You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support content type inference from folder structure #73
Spaces often organise documents into folders that could tell us what the node type is. Add a config option to the markdown plugin that allows type inference during parsing.
Eg
goals/winning.md doesn't have to have a type: goal frontmatter item because the read phase inferred it from the directory (goals) matching a type name, type alias, or matcher.
Consider the config option allowing specification of which of those elements to match on, though all is probably fine. Also consider what the default should be. On feels like a good and safe convention.
Assumption: specifying type in a doc overrides any inferred type
Out of scope: if/how this generalises for parse plugins (plug-in level config for now); extending for other kinds of type inference (eg type from hierarchy by directory depth)
Cross-referencing #44 (parsing hints) and #78 (metadata layout refactor).
Agreed that folder-to-type inference should default to on. Concrete use case from setting up knowledge wiki spaces: two spaces using the same knowledge_wiki schema, each with different folder structures. The type inference avoids needing to add every folder name as a schema alias.
However, there's a design tension worth surfacing: should the folder mapping live in the schema (as aliases/matchers) or in the space config (as parsing hints)?
Schema-level: portable across spaces, but schema becomes overloaded with conventions from specific spaces.
Space-level: each space defines its own conventions, but you lose the benefit of a shared schema doing the work.
Proposal: default to schema-level aliases for common names (sources, concepts, notes), and support space-level overrides/additions via the parsing hints from #44. Space config hints take precedence over schema aliases when both match. This way a general-purpose knowledge schema stays clean, and spaces with non-standard structures self-configure.
Implements automatic node type inference from folder structure in the markdown plugin.
Closes issues #73 (type inference from folder structure), #44 (parsing hints in space config), #78 (metadata layout).
Design decisions
$metadata is unchanged — no new fields added to the schema dialect
Known types source of truth: canonical type names are extracted from oneOf branches in the schema (properties.type.const / .enum), not from metadata hierarchy/relationships. Flat schemas with no hierarchy work correctly.
Default mode (folder-name): match the leaf directory name case-insensitively against canonical type names and alias keys. Sources matches alias "sources": "source" but not the type source directly.
folderMap mode: replaces auto-matching entirely. Keys are full paths from the space root (trailing slashes normalised). Longest-prefix match wins. Values may be aliases (resolved to canonical type).
Precedence: explicit type: in frontmatter always wins over inferred type.
Config errors are hard errors: unresolvable folderMap values (not a known type or alias) throw at parse time.
mode is an enum ('folder-name' | 'off') rather than boolean to support future modes (e.g. 'folder-level').
Step 1 — Relocate extractEntityInfo and add extractSchemaTypeNames in src/schema/schema.ts
Move extractEntityInfo from src/commands/schemas.ts to src/schema/schema.ts — it is schema inspection logic that only ended up in the command layer by accident. Update imports in src/commands/schemas.ts and src/commands/validate.ts.
Add extractSchemaTypeNames(schema: SchemaWithMetadata, schemaRefRegistry: Map<string, AnySchemaObject>): Set<string> as a thin wrapper: new Set(extractEntityInfo(...).map(e => e.type))
EntityInfo type moves to src/schema/schema.ts alongside the function (or src/types.ts if broadly useful)
Simplify signature: extractEntityInfo currently takes oneOf as a separate parameter; after the move, update it to take SchemaWithMetadata directly (accessing schema.oneOf internally). Update both call sites accordingly.
Step 2 — Update MarkdownPluginConfig in src/plugins/markdown/index.ts
Activity
mindsocket commentedon Apr 6, 2026
Cross-referencing #44 (parsing hints) and #78 (metadata layout refactor).
Agreed that folder-to-type inference should default to on. Concrete use case from setting up knowledge wiki spaces: two spaces using the same knowledge_wiki schema, each with different folder structures. The type inference avoids needing to add every folder name as a schema alias.
However, there's a design tension worth surfacing: should the folder mapping live in the schema (as aliases/matchers) or in the space config (as parsing hints)?
Schema-level: portable across spaces, but schema becomes overloaded with conventions from specific spaces.
Space-level: each space defines its own conventions, but you lose the benefit of a shared schema doing the work.
Proposal: default to schema-level aliases for common names (sources, concepts, notes), and support space-level overrides/additions via the parsing hints from #44. Space config hints take precedence over schema aliases when both match. This way a general-purpose knowledge schema stays clean, and spaces with non-standard structures self-configure.
feat: folder-based type inference for markdown plugin
mindsocket commentedon Apr 7, 2026
Plan: Folder-based type inference (#73, #44, #78)
Implements automatic node type inference from folder structure in the markdown plugin.
Closes issues #73 (type inference from folder structure), #44 (parsing hints in space config), #78 (metadata layout).
Design decisions
$metadatais unchanged — no new fields added to the schema dialectoneOfbranches in the schema (properties.type.const/.enum), not from metadata hierarchy/relationships. Flat schemas with no hierarchy work correctly.folder-name): match the leaf directory name case-insensitively against canonical type names and alias keys.Sourcesmatches alias"sources": "source"but not the typesourcedirectly.folderMapmode: replaces auto-matching entirely. Keys are full paths from the space root (trailing slashes normalised). Longest-prefix match wins. Values may be aliases (resolved to canonical type).type:in frontmatter always wins over inferred type.folderMapvalues (not a known type or alias) throw at parse time.modeis an enum ('folder-name' | 'off') rather than boolean to support future modes (e.g.'folder-level').Config shape
{ "name": "my-wiki", "path": "...", "schema": "knowledge_wiki.json", "plugins": { "markdown": { "typeInference": { "mode": "folder-name" } } } }With explicit folder map (replaces auto-matching):
{ "plugins": { "markdown": { "typeInference": { "folderMap": { "Research": "source", "Personal": "note", "topics/concepts": "concept" } } } } }Tasks
Step 1 — Relocate
extractEntityInfoand addextractSchemaTypeNamesinsrc/schema/schema.tsextractEntityInfofromsrc/commands/schemas.tstosrc/schema/schema.ts— it is schema inspection logic that only ended up in the command layer by accident. Update imports insrc/commands/schemas.tsandsrc/commands/validate.ts.extractSchemaTypeNames(schema: SchemaWithMetadata, schemaRefRegistry: Map<string, AnySchemaObject>): Set<string>as a thin wrapper:new Set(extractEntityInfo(...).map(e => e.type))EntityInfotype moves tosrc/schema/schema.tsalongside the function (orsrc/types.tsif broadly useful)extractEntityInfocurrently takesoneOfas a separate parameter; after the move, update it to takeSchemaWithMetadatadirectly (accessingschema.oneOfinternally). Update both call sites accordingly.Step 2 — Update
MarkdownPluginConfiginsrc/plugins/markdown/index.tsTypeInferenceConfigtype:{ mode?: 'folder-name' | 'off', folderMap?: Record<string, string> }typeInference?: TypeInferenceConfigtoMarkdownPluginConfigMARKDOWN_CONFIG_SCHEMAStep 3 —
inferTypeFromPathinsrc/plugins/markdown/util.tsinferTypeFromPath(filePath: string, config: TypeInferenceConfig, knownTypes: Set<string>, typeAliases: Record<string, string> | undefined): string | undefinedmode: 'off'→ returnundefinedfolderMapis provided):filePathrelative to space roottypeAliasesfirst, thenknownTypesfolderMap):filePathknownTypescase-insensitively → return matched type name (preserving original case from schema)typeAliaseskeys case-insensitively → resolve and return canonical typeundefinedif no matchundefinedStep 4 — Wire into
readSpaceDirectoryinsrc/plugins/markdown/read-space.tsknownTypes = extractSchemaTypeNames(context.schema)once before the file loopapplyFieldMap/coerceDates, if!data.type: callinferTypeFromPathand assign result todata.typeStep 5 — Tests in
tests/plugins/markdown/read-space-directory-type-inference.test.tstests/fixtures/(knowledge-wiki schema)concept/page.md→concept)study/page.md→source), case-insensitive (Study/page.md)sources/page.md→ not inferred)type:in frontmatter overrides inferred typemode: 'off'→ no inferencefolderMap: mapped folder infers correctlyfolderMap: unmapped folder does not inferfolderMap: nested path (topics/concepts) matches correctlyfolderMap: longest-prefix wins when keys overlap (a/bvsa/b/c)folderMap: trailing slash in key is normalisedfolderMap: value can be an alias (resolves to canonical type)folderMap: unresolvable value throws a hard errorStep 6 — Docs
README.md: addtypeInferenceto plugin config reference sectiondocs/concepts.md: add Type inference entry to the Space directory sectionStep 7 — Close issues