@hiveforge/hivemind-mcp 2.1.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +18 -9
  2. package/dist/cli.js +193 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/mcp/index.d.ts +8 -0
  5. package/dist/mcp/index.d.ts.map +1 -0
  6. package/dist/mcp/index.js +8 -0
  7. package/dist/mcp/index.js.map +1 -0
  8. package/dist/mcp/tool-generator.d.ts +108 -0
  9. package/dist/mcp/tool-generator.d.ts.map +1 -0
  10. package/dist/mcp/tool-generator.js +245 -0
  11. package/dist/mcp/tool-generator.js.map +1 -0
  12. package/dist/parser/markdown.d.ts +9 -0
  13. package/dist/parser/markdown.d.ts.map +1 -1
  14. package/dist/parser/markdown.js +13 -2
  15. package/dist/parser/markdown.js.map +1 -1
  16. package/dist/server.d.ts +8 -4
  17. package/dist/server.d.ts.map +1 -1
  18. package/dist/server.js +66 -199
  19. package/dist/server.js.map +1 -1
  20. package/dist/templates/builtin/worldbuilding.d.ts +20 -0
  21. package/dist/templates/builtin/worldbuilding.d.ts.map +1 -0
  22. package/dist/templates/builtin/worldbuilding.js +464 -0
  23. package/dist/templates/builtin/worldbuilding.js.map +1 -0
  24. package/dist/templates/detector.d.ts +51 -0
  25. package/dist/templates/detector.d.ts.map +1 -0
  26. package/dist/templates/detector.js +71 -0
  27. package/dist/templates/detector.js.map +1 -0
  28. package/dist/templates/folder-mapper.d.ts +66 -0
  29. package/dist/templates/folder-mapper.d.ts.map +1 -0
  30. package/dist/templates/folder-mapper.js +148 -0
  31. package/dist/templates/folder-mapper.js.map +1 -0
  32. package/dist/templates/index.d.ts +15 -0
  33. package/dist/templates/index.d.ts.map +1 -0
  34. package/dist/templates/index.js +15 -0
  35. package/dist/templates/index.js.map +1 -0
  36. package/dist/templates/loader.d.ts +115 -0
  37. package/dist/templates/loader.d.ts.map +1 -0
  38. package/dist/templates/loader.js +202 -0
  39. package/dist/templates/loader.js.map +1 -0
  40. package/dist/templates/registry.d.ts +97 -0
  41. package/dist/templates/registry.d.ts.map +1 -0
  42. package/dist/templates/registry.js +141 -0
  43. package/dist/templates/registry.js.map +1 -0
  44. package/dist/templates/schema-factory.d.ts +76 -0
  45. package/dist/templates/schema-factory.d.ts.map +1 -0
  46. package/dist/templates/schema-factory.js +171 -0
  47. package/dist/templates/schema-factory.js.map +1 -0
  48. package/dist/templates/types.d.ts +114 -0
  49. package/dist/templates/types.d.ts.map +1 -0
  50. package/dist/templates/types.js +9 -0
  51. package/dist/templates/types.js.map +1 -0
  52. package/dist/templates/validator.d.ts +200 -0
  53. package/dist/templates/validator.d.ts.map +1 -0
  54. package/dist/templates/validator.js +136 -0
  55. package/dist/templates/validator.js.map +1 -0
  56. package/dist/types/index.d.ts +57 -21
  57. package/dist/types/index.d.ts.map +1 -1
  58. package/dist/types/index.js +39 -15
  59. package/dist/types/index.js.map +1 -1
  60. package/dist/vault/reader.d.ts.map +1 -1
  61. package/dist/vault/reader.js +15 -1
  62. package/dist/vault/reader.js.map +1 -1
  63. package/package.json +7 -4
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Folder-to-type mapping utility.
3
+ *
4
+ * Infers entity types from file paths based on folder names.
5
+ * Used by the CLI 'fix' command and Obsidian plugin to auto-suggest
6
+ * entity types for files without frontmatter.
7
+ */
8
+ /**
9
+ * Default folder-to-type mappings for common worldbuilding folder structures.
10
+ *
11
+ * Supports multiple naming conventions (e.g., 'characters', 'people', 'npcs')
12
+ * mapping to the same entity type.
13
+ */
14
+ export const DEFAULT_FOLDER_MAPPINGS = [
15
+ // Character mappings
16
+ { pattern: 'characters', entityType: 'character' },
17
+ { pattern: 'people', entityType: 'character' },
18
+ { pattern: 'npcs', entityType: 'character' },
19
+ { pattern: 'pcs', entityType: 'character' },
20
+ { pattern: 'cast', entityType: 'character' },
21
+ // Location mappings
22
+ { pattern: 'locations', entityType: 'location' },
23
+ { pattern: 'places', entityType: 'location' },
24
+ { pattern: 'geography', entityType: 'location' },
25
+ { pattern: 'world', entityType: 'location' },
26
+ { pattern: 'regions', entityType: 'location' },
27
+ { pattern: 'cities', entityType: 'location' },
28
+ { pattern: 'towns', entityType: 'location' },
29
+ // Event mappings
30
+ { pattern: 'events', entityType: 'event' },
31
+ { pattern: 'timeline', entityType: 'event' },
32
+ { pattern: 'history', entityType: 'event' },
33
+ { pattern: 'sessions', entityType: 'event' },
34
+ // Faction mappings
35
+ { pattern: 'factions', entityType: 'faction' },
36
+ { pattern: 'organizations', entityType: 'faction' },
37
+ { pattern: 'groups', entityType: 'faction' },
38
+ { pattern: 'guilds', entityType: 'faction' },
39
+ { pattern: 'houses', entityType: 'faction' },
40
+ // Lore mappings
41
+ { pattern: 'lore', entityType: 'lore' },
42
+ { pattern: 'mythology', entityType: 'lore' },
43
+ { pattern: 'magic', entityType: 'lore' },
44
+ { pattern: 'culture', entityType: 'lore' },
45
+ { pattern: 'religion', entityType: 'lore' },
46
+ // Asset mappings
47
+ { pattern: 'assets', entityType: 'asset' },
48
+ { pattern: 'images', entityType: 'asset' },
49
+ { pattern: 'media', entityType: 'asset' },
50
+ // Reference mappings
51
+ { pattern: 'references', entityType: 'reference' },
52
+ { pattern: 'sources', entityType: 'reference' },
53
+ { pattern: 'inspiration', entityType: 'reference' },
54
+ { pattern: 'notes', entityType: 'reference' },
55
+ { pattern: 'meta', entityType: 'reference' },
56
+ ];
57
+ /**
58
+ * FolderMapper infers entity types from file paths.
59
+ *
60
+ * Checks each path segment against folder mappings to determine
61
+ * the most likely entity type for a file.
62
+ */
63
+ export class FolderMapper {
64
+ mappings;
65
+ /**
66
+ * Create a FolderMapper with optional custom mappings.
67
+ *
68
+ * @param customMappings - Additional or override mappings.
69
+ * Custom mappings take precedence over defaults.
70
+ */
71
+ constructor(customMappings = []) {
72
+ this.mappings = new Map();
73
+ // Add default mappings first
74
+ for (const mapping of DEFAULT_FOLDER_MAPPINGS) {
75
+ this.mappings.set(mapping.pattern.toLowerCase(), mapping.entityType);
76
+ }
77
+ // Override with custom mappings
78
+ for (const mapping of customMappings) {
79
+ this.mappings.set(mapping.pattern.toLowerCase(), mapping.entityType);
80
+ }
81
+ }
82
+ /**
83
+ * Infer entity type from a file path.
84
+ *
85
+ * Checks each folder in the path against mappings.
86
+ * Returns the first match found, or null if no match.
87
+ *
88
+ * @param filePath - Relative or absolute file path
89
+ * @returns Inferred entity type name, or null if no match
90
+ */
91
+ inferType(filePath) {
92
+ // Split on both forward and back slashes
93
+ const parts = filePath.toLowerCase().split(/[/\\]/);
94
+ // Check each path part against mappings
95
+ for (const part of parts) {
96
+ // Exact match
97
+ const exactMatch = this.mappings.get(part);
98
+ if (exactMatch) {
99
+ return exactMatch;
100
+ }
101
+ // Prefix match (e.g., 'characters-main' matches 'characters')
102
+ for (const [pattern, entityType] of this.mappings) {
103
+ if (part.startsWith(pattern)) {
104
+ return entityType;
105
+ }
106
+ }
107
+ }
108
+ return null;
109
+ }
110
+ /**
111
+ * Infer types for multiple file paths.
112
+ *
113
+ * @param filePaths - Array of file paths
114
+ * @returns Map of file path to inferred type (or null)
115
+ */
116
+ inferTypes(filePaths) {
117
+ const results = new Map();
118
+ for (const path of filePaths) {
119
+ results.set(path, this.inferType(path));
120
+ }
121
+ return results;
122
+ }
123
+ /**
124
+ * Get all registered mappings.
125
+ *
126
+ * @returns Array of folder mappings
127
+ */
128
+ getMappings() {
129
+ return Array.from(this.mappings.entries()).map(([pattern, entityType]) => ({
130
+ pattern,
131
+ entityType,
132
+ }));
133
+ }
134
+ /**
135
+ * Add a new mapping.
136
+ *
137
+ * @param pattern - Folder name pattern
138
+ * @param entityType - Entity type to assign
139
+ */
140
+ addMapping(pattern, entityType) {
141
+ this.mappings.set(pattern.toLowerCase(), entityType);
142
+ }
143
+ }
144
+ /**
145
+ * Singleton instance for convenience.
146
+ */
147
+ export const folderMapper = new FolderMapper();
148
+ //# sourceMappingURL=folder-mapper.js.map
@@ -0,0 +1 @@
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,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACH,WAAW;QACT,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;YACzE,OAAO;YACP,UAAU;SACX,CAAC,CAAC,CAAC;IACN,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,OAAe,EAAE,UAAkB;QAC5C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,UAAU,CAAC,CAAC;IACvD,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Template system for pluggable entity type definitions.
3
+ *
4
+ * This module enables users to define custom entity types via config
5
+ * without writing code.
6
+ */
7
+ export * from './types.js';
8
+ export * from './schema-factory.js';
9
+ export * from './validator.js';
10
+ export * from './registry.js';
11
+ export * from './loader.js';
12
+ export * from './detector.js';
13
+ export * from './folder-mapper.js';
14
+ export * from './builtin/worldbuilding.js';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Template system for pluggable entity type definitions.
3
+ *
4
+ * This module enables users to define custom entity types via config
5
+ * without writing code.
6
+ */
7
+ export * from './types.js';
8
+ export * from './schema-factory.js';
9
+ export * from './validator.js';
10
+ export * from './registry.js';
11
+ export * from './loader.js';
12
+ export * from './detector.js';
13
+ export * from './folder-mapper.js';
14
+ export * from './builtin/worldbuilding.js';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Template configuration loader.
3
+ *
4
+ * Provides functions to:
5
+ * 1. Load template configuration from config.json
6
+ * 2. Register built-in templates
7
+ * 3. Validate and register user-defined templates
8
+ * 4. Activate the selected template
9
+ * 5. Pre-generate schemas for performance
10
+ */
11
+ import type { TemplateConfig } from './types.js';
12
+ /**
13
+ * Find the config.json file.
14
+ *
15
+ * Searches in:
16
+ * 1. Provided path (if given)
17
+ * 2. Current working directory
18
+ * 3. Module directory (for development)
19
+ *
20
+ * @param configPath - Optional explicit path to config file
21
+ * @returns Path to config.json if found, null otherwise
22
+ */
23
+ export declare function findConfigFile(configPath?: string): string | null;
24
+ /**
25
+ * Load template configuration from config.json.
26
+ *
27
+ * Searches for config.json in multiple locations and extracts the template
28
+ * section. Returns defaults if config file not found or template section missing.
29
+ *
30
+ * @param configPath - Optional explicit path to config file
31
+ * @returns Template configuration object
32
+ * @throws {Error} If config file is found but contains invalid template config
33
+ */
34
+ export declare function loadTemplateConfig(configPath?: string): TemplateConfig;
35
+ /**
36
+ * Register all built-in templates.
37
+ *
38
+ * Currently includes:
39
+ * - worldbuilding: Characters, locations, events, factions, lore, assets
40
+ *
41
+ * This function should be called before loading user templates to ensure
42
+ * built-in templates can be referenced by ID.
43
+ */
44
+ export declare function registerBuiltinTemplates(): void;
45
+ /**
46
+ * Register user-defined templates from config.
47
+ *
48
+ * Validates each template and registers it in the registry.
49
+ *
50
+ * @param config - Template configuration from config.json
51
+ * @throws {Error} If any user template fails validation or has duplicate ID
52
+ */
53
+ export declare function registerUserTemplates(config: TemplateConfig): void;
54
+ /**
55
+ * Activate the selected template.
56
+ *
57
+ * Sets the active template in the registry based on the activeTemplate field
58
+ * in the config.
59
+ *
60
+ * @param config - Template configuration from config.json
61
+ * @throws {Error} If the specified template is not registered
62
+ */
63
+ export declare function activateTemplate(config: TemplateConfig): void;
64
+ /**
65
+ * Pre-generate schemas for all entity types in the active template.
66
+ *
67
+ * Caches schemas in the schema factory for fast runtime access.
68
+ * This improves performance for note parsing and validation.
69
+ *
70
+ * @throws {Error} If no template is active
71
+ */
72
+ export declare function pregenerateSchemas(): void;
73
+ /**
74
+ * Full initialization sequence for template system.
75
+ *
76
+ * Performs complete setup:
77
+ * 1. Register built-in templates
78
+ * 2. Load config from file
79
+ * 3. Register user-defined templates
80
+ * 4. Activate selected template
81
+ * 5. Pre-generate schemas
82
+ *
83
+ * This is the main entry point for template system initialization.
84
+ * Call this at application startup before using any template features.
85
+ *
86
+ * @param configPath - Optional explicit path to config file
87
+ * @returns The loaded template configuration
88
+ * @throws {Error} If initialization fails at any step
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * // At application startup
93
+ * const config = initializeTemplates();
94
+ * console.log(`Loaded template: ${config.activeTemplate}`);
95
+ * ```
96
+ */
97
+ export declare function initializeTemplates(configPath?: string): TemplateConfig;
98
+ /**
99
+ * Convenience function to get an entity schema by name.
100
+ *
101
+ * Retrieves the entity type config from the active template and returns
102
+ * the corresponding Zod schema.
103
+ *
104
+ * @param entityTypeName - Name of the entity type (e.g., "character", "location")
105
+ * @returns Zod schema for the entity type
106
+ * @throws {Error} If no template is active or entity type not found
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const characterSchema = getEntitySchema('character');
111
+ * const validated = characterSchema.parse(frontmatter);
112
+ * ```
113
+ */
114
+ export declare function getEntitySchema(entityTypeName: string): import("zod").ZodObject<any, import("zod/v4/core").$strip>;
115
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/templates/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAMjD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoBjE;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CA8BtE;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CASlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAE7D;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAQzC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAiBvE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,cAAc,EAAE,MAAM,8DAWrD"}
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Template configuration loader.
3
+ *
4
+ * Provides functions to:
5
+ * 1. Load template configuration from config.json
6
+ * 2. Register built-in templates
7
+ * 3. Validate and register user-defined templates
8
+ * 4. Activate the selected template
9
+ * 5. Pre-generate schemas for performance
10
+ */
11
+ import { readFileSync, existsSync } from 'fs';
12
+ import { resolve, dirname } from 'path';
13
+ import { fileURLToPath } from 'url';
14
+ import { validateTemplateConfig } from './validator.js';
15
+ import { templateRegistry } from './registry.js';
16
+ import { schemaFactory } from './schema-factory.js';
17
+ import { worldbuildingTemplate } from './builtin/worldbuilding.js';
18
+ /**
19
+ * Find the config.json file.
20
+ *
21
+ * Searches in:
22
+ * 1. Provided path (if given)
23
+ * 2. Current working directory
24
+ * 3. Module directory (for development)
25
+ *
26
+ * @param configPath - Optional explicit path to config file
27
+ * @returns Path to config.json if found, null otherwise
28
+ */
29
+ export function findConfigFile(configPath) {
30
+ // If explicit path provided, use it
31
+ if (configPath) {
32
+ return existsSync(configPath) ? resolve(configPath) : null;
33
+ }
34
+ // Try current working directory
35
+ const cwdConfig = resolve(process.cwd(), 'config.json');
36
+ if (existsSync(cwdConfig)) {
37
+ return cwdConfig;
38
+ }
39
+ // Try module directory (for development/testing)
40
+ const moduleDir = dirname(fileURLToPath(import.meta.url));
41
+ const moduleConfig = resolve(moduleDir, '../../config.json');
42
+ if (existsSync(moduleConfig)) {
43
+ return moduleConfig;
44
+ }
45
+ return null;
46
+ }
47
+ /**
48
+ * Load template configuration from config.json.
49
+ *
50
+ * Searches for config.json in multiple locations and extracts the template
51
+ * section. Returns defaults if config file not found or template section missing.
52
+ *
53
+ * @param configPath - Optional explicit path to config file
54
+ * @returns Template configuration object
55
+ * @throws {Error} If config file is found but contains invalid template config
56
+ */
57
+ export function loadTemplateConfig(configPath) {
58
+ const configFilePath = findConfigFile(configPath);
59
+ // If no config file found, return defaults
60
+ if (!configFilePath) {
61
+ return {
62
+ activeTemplate: 'worldbuilding',
63
+ templates: [],
64
+ };
65
+ }
66
+ // Read and parse config file
67
+ let configContent;
68
+ try {
69
+ const fileContent = readFileSync(configFilePath, 'utf-8');
70
+ configContent = JSON.parse(fileContent);
71
+ }
72
+ catch (err) {
73
+ throw new Error(`Failed to read or parse config file at ${configFilePath}: ${err instanceof Error ? err.message : String(err)}`);
74
+ }
75
+ // Extract template section (use defaults if missing)
76
+ const templateConfig = configContent.template || {
77
+ activeTemplate: 'worldbuilding',
78
+ templates: [],
79
+ };
80
+ // Validate the template config
81
+ return validateTemplateConfig(templateConfig);
82
+ }
83
+ /**
84
+ * Register all built-in templates.
85
+ *
86
+ * Currently includes:
87
+ * - worldbuilding: Characters, locations, events, factions, lore, assets
88
+ *
89
+ * This function should be called before loading user templates to ensure
90
+ * built-in templates can be referenced by ID.
91
+ */
92
+ export function registerBuiltinTemplates() {
93
+ templateRegistry.register(worldbuildingTemplate, 'builtin');
94
+ }
95
+ /**
96
+ * Register user-defined templates from config.
97
+ *
98
+ * Validates each template and registers it in the registry.
99
+ *
100
+ * @param config - Template configuration from config.json
101
+ * @throws {Error} If any user template fails validation or has duplicate ID
102
+ */
103
+ export function registerUserTemplates(config) {
104
+ if (!config.templates || config.templates.length === 0) {
105
+ return;
106
+ }
107
+ for (const template of config.templates) {
108
+ // Template already validated by loadTemplateConfig
109
+ templateRegistry.register(template, 'config');
110
+ }
111
+ }
112
+ /**
113
+ * Activate the selected template.
114
+ *
115
+ * Sets the active template in the registry based on the activeTemplate field
116
+ * in the config.
117
+ *
118
+ * @param config - Template configuration from config.json
119
+ * @throws {Error} If the specified template is not registered
120
+ */
121
+ export function activateTemplate(config) {
122
+ templateRegistry.activate(config.activeTemplate);
123
+ }
124
+ /**
125
+ * Pre-generate schemas for all entity types in the active template.
126
+ *
127
+ * Caches schemas in the schema factory for fast runtime access.
128
+ * This improves performance for note parsing and validation.
129
+ *
130
+ * @throws {Error} If no template is active
131
+ */
132
+ export function pregenerateSchemas() {
133
+ const activeTemplate = templateRegistry.getActive();
134
+ if (!activeTemplate) {
135
+ throw new Error('Cannot pregenerate schemas: no active template');
136
+ }
137
+ // Generate schemas for all entity types
138
+ schemaFactory.generateSchemas(activeTemplate.entityTypes);
139
+ }
140
+ /**
141
+ * Full initialization sequence for template system.
142
+ *
143
+ * Performs complete setup:
144
+ * 1. Register built-in templates
145
+ * 2. Load config from file
146
+ * 3. Register user-defined templates
147
+ * 4. Activate selected template
148
+ * 5. Pre-generate schemas
149
+ *
150
+ * This is the main entry point for template system initialization.
151
+ * Call this at application startup before using any template features.
152
+ *
153
+ * @param configPath - Optional explicit path to config file
154
+ * @returns The loaded template configuration
155
+ * @throws {Error} If initialization fails at any step
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * // At application startup
160
+ * const config = initializeTemplates();
161
+ * console.log(`Loaded template: ${config.activeTemplate}`);
162
+ * ```
163
+ */
164
+ export function initializeTemplates(configPath) {
165
+ // 1. Register built-in templates
166
+ registerBuiltinTemplates();
167
+ // 2. Load config
168
+ const config = loadTemplateConfig(configPath);
169
+ // 3. Register user templates
170
+ registerUserTemplates(config);
171
+ // 4. Activate selected template
172
+ activateTemplate(config);
173
+ // 5. Pre-generate schemas
174
+ pregenerateSchemas();
175
+ return config;
176
+ }
177
+ /**
178
+ * Convenience function to get an entity schema by name.
179
+ *
180
+ * Retrieves the entity type config from the active template and returns
181
+ * the corresponding Zod schema.
182
+ *
183
+ * @param entityTypeName - Name of the entity type (e.g., "character", "location")
184
+ * @returns Zod schema for the entity type
185
+ * @throws {Error} If no template is active or entity type not found
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const characterSchema = getEntitySchema('character');
190
+ * const validated = characterSchema.parse(frontmatter);
191
+ * ```
192
+ */
193
+ export function getEntitySchema(entityTypeName) {
194
+ const entityType = templateRegistry.getEntityType(entityTypeName);
195
+ if (!entityType) {
196
+ const activeTemplate = templateRegistry.getActive();
197
+ const availableTypes = activeTemplate?.entityTypes.map((t) => t.name).join(', ') || 'none';
198
+ throw new Error(`Entity type "${entityTypeName}" not found in active template. Available types: ${availableTypes}`);
199
+ }
200
+ return schemaFactory.getSchema(entityType);
201
+ }
202
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src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,CAAC;IACJ,CAAC;IAED,OAAO,aAAa,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Template registry for managing template lifecycle.
3
+ *
4
+ * Provides centralized template management with O(1) lookups
5
+ * and validation on registration.
6
+ */
7
+ import type { TemplateDefinition, TemplateRegistryEntry, EntityTypeConfig } from './types.js';
8
+ /**
9
+ * Source of a template registration.
10
+ */
11
+ type TemplateSource = 'builtin' | 'config';
12
+ /**
13
+ * Manages registered templates with fast lookups.
14
+ *
15
+ * Singleton pattern ensures consistent state across the application.
16
+ * Validates templates on registration and provides O(1) entity type lookups.
17
+ */
18
+ export declare class TemplateRegistry {
19
+ /** Map from template ID to registry entry */
20
+ private templates;
21
+ /** ID of the currently active template */
22
+ private activeTemplateId;
23
+ /**
24
+ * Registers a template in the registry.
25
+ *
26
+ * Validates the template definition and creates optimized lookup maps.
27
+ *
28
+ * @param template - Template definition to register
29
+ * @param source - Source of the template (builtin or config)
30
+ * @throws {Error} If template with this ID is already registered
31
+ */
32
+ register(template: TemplateDefinition, source: TemplateSource): void;
33
+ /**
34
+ * Sets the active template by ID.
35
+ *
36
+ * @param templateId - ID of template to activate
37
+ * @throws {Error} If template ID is not registered
38
+ */
39
+ activate(templateId: string): void;
40
+ /**
41
+ * Gets the currently active template.
42
+ *
43
+ * @returns Active template entry, or null if no template is active
44
+ */
45
+ getActive(): TemplateRegistryEntry | null;
46
+ /**
47
+ * Gets a template by ID.
48
+ *
49
+ * @param templateId - Template ID to retrieve
50
+ * @returns Template entry if found, undefined otherwise
51
+ */
52
+ get(templateId: string): TemplateRegistryEntry | undefined;
53
+ /**
54
+ * Checks if a template is registered.
55
+ *
56
+ * @param templateId - Template ID to check
57
+ * @returns True if template exists in registry
58
+ */
59
+ has(templateId: string): boolean;
60
+ /**
61
+ * Lists all registered template IDs.
62
+ *
63
+ * @returns Array of template IDs
64
+ */
65
+ listTemplates(): string[];
66
+ /**
67
+ * Gets an entity type config from the active template.
68
+ *
69
+ * O(1) lookup using the entity type map.
70
+ *
71
+ * @param name - Entity type name to retrieve
72
+ * @returns Entity type config if found, undefined otherwise
73
+ * @throws {Error} If no template is active
74
+ */
75
+ getEntityType(name: string): EntityTypeConfig | undefined;
76
+ /**
77
+ * Gets all entity type configs from the active template.
78
+ *
79
+ * @returns Array of entity type configs
80
+ * @throws {Error} If no template is active
81
+ */
82
+ getEntityTypes(): EntityTypeConfig[];
83
+ /**
84
+ * Clears all registered templates and resets active template.
85
+ *
86
+ * Primarily for testing purposes.
87
+ */
88
+ clear(): void;
89
+ }
90
+ /**
91
+ * Singleton instance of the template registry.
92
+ *
93
+ * Use this throughout the application for consistent template state.
94
+ */
95
+ export declare const templateRegistry: TemplateRegistry;
96
+ export {};
97
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/templates/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,KAAK,cAAc,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE3C;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,6CAA6C;IAC7C,OAAO,CAAC,SAAS,CAA4C;IAE7D,0CAA0C;IAC1C,OAAO,CAAC,gBAAgB,CAAuB;IAE/C;;;;;;;;OAQG;IACH,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI;IAyBpE;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAUlC;;;;OAIG;IACH,SAAS,IAAI,qBAAqB,GAAG,IAAI;IAOzC;;;;;OAKG;IACH,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS;IAI1D;;;;;OAKG;IACH,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAIhC;;;;OAIG;IACH,aAAa,IAAI,MAAM,EAAE;IAIzB;;;;;;;;OAQG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAQzD;;;;;OAKG;IACH,cAAc,IAAI,gBAAgB,EAAE;IAQpC;;;;OAIG;IACH,KAAK,IAAI,IAAI;CAId;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,kBAAyB,CAAC"}