@hiveforge/hivemind-mcp 2.2.0 → 2.4.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 (77) hide show
  1. package/README.md +114 -25
  2. package/dist/cli.js +193 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/graph/builder.d.ts +7 -3
  5. package/dist/graph/builder.d.ts.map +1 -1
  6. package/dist/graph/builder.js +51 -21
  7. package/dist/graph/builder.js.map +1 -1
  8. package/dist/mcp/index.d.ts +8 -0
  9. package/dist/mcp/index.d.ts.map +1 -0
  10. package/dist/mcp/index.js +8 -0
  11. package/dist/mcp/index.js.map +1 -0
  12. package/dist/mcp/tool-generator.d.ts +110 -0
  13. package/dist/mcp/tool-generator.d.ts.map +1 -0
  14. package/dist/mcp/tool-generator.js +281 -0
  15. package/dist/mcp/tool-generator.js.map +1 -0
  16. package/dist/parser/markdown.d.ts +9 -0
  17. package/dist/parser/markdown.d.ts.map +1 -1
  18. package/dist/parser/markdown.js +13 -2
  19. package/dist/parser/markdown.js.map +1 -1
  20. package/dist/search/engine.d.ts +9 -1
  21. package/dist/search/engine.d.ts.map +1 -1
  22. package/dist/search/engine.js +16 -4
  23. package/dist/search/engine.js.map +1 -1
  24. package/dist/server.d.ts +8 -4
  25. package/dist/server.d.ts.map +1 -1
  26. package/dist/server.js +66 -199
  27. package/dist/server.js.map +1 -1
  28. package/dist/templates/builtin/people-management.d.ts +18 -0
  29. package/dist/templates/builtin/people-management.d.ts.map +1 -0
  30. package/dist/templates/builtin/people-management.js +523 -0
  31. package/dist/templates/builtin/people-management.js.map +1 -0
  32. package/dist/templates/builtin/research.d.ts +18 -0
  33. package/dist/templates/builtin/research.d.ts.map +1 -0
  34. package/dist/templates/builtin/research.js +349 -0
  35. package/dist/templates/builtin/research.js.map +1 -0
  36. package/dist/templates/builtin/worldbuilding.d.ts +20 -0
  37. package/dist/templates/builtin/worldbuilding.d.ts.map +1 -0
  38. package/dist/templates/builtin/worldbuilding.js +602 -0
  39. package/dist/templates/builtin/worldbuilding.js.map +1 -0
  40. package/dist/templates/detector.d.ts +51 -0
  41. package/dist/templates/detector.d.ts.map +1 -0
  42. package/dist/templates/detector.js +71 -0
  43. package/dist/templates/detector.js.map +1 -0
  44. package/dist/templates/folder-mapper.d.ts +66 -0
  45. package/dist/templates/folder-mapper.d.ts.map +1 -0
  46. package/dist/templates/folder-mapper.js +148 -0
  47. package/dist/templates/folder-mapper.js.map +1 -0
  48. package/dist/templates/index.d.ts +15 -0
  49. package/dist/templates/index.d.ts.map +1 -0
  50. package/dist/templates/index.js +15 -0
  51. package/dist/templates/index.js.map +1 -0
  52. package/dist/templates/loader.d.ts +117 -0
  53. package/dist/templates/loader.d.ts.map +1 -0
  54. package/dist/templates/loader.js +208 -0
  55. package/dist/templates/loader.js.map +1 -0
  56. package/dist/templates/registry.d.ts +127 -0
  57. package/dist/templates/registry.d.ts.map +1 -0
  58. package/dist/templates/registry.js +205 -0
  59. package/dist/templates/registry.js.map +1 -0
  60. package/dist/templates/schema-factory.d.ts +76 -0
  61. package/dist/templates/schema-factory.d.ts.map +1 -0
  62. package/dist/templates/schema-factory.js +171 -0
  63. package/dist/templates/schema-factory.js.map +1 -0
  64. package/dist/templates/types.d.ts +40 -0
  65. package/dist/templates/types.d.ts.map +1 -1
  66. package/dist/templates/validator.d.ts +310 -0
  67. package/dist/templates/validator.d.ts.map +1 -0
  68. package/dist/templates/validator.js +169 -0
  69. package/dist/templates/validator.js.map +1 -0
  70. package/dist/types/index.d.ts +57 -21
  71. package/dist/types/index.d.ts.map +1 -1
  72. package/dist/types/index.js +39 -15
  73. package/dist/types/index.js.map +1 -1
  74. package/dist/vault/reader.d.ts.map +1 -1
  75. package/dist/vault/reader.js +15 -1
  76. package/dist/vault/reader.js.map +1 -1
  77. package/package.json +7 -4
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Template auto-detection from vault folder structure.
3
+ *
4
+ * This module enables backwards compatibility by automatically identifying
5
+ * templates based on vault organization patterns.
6
+ */
7
+ import { promises as fs } from 'fs';
8
+ /**
9
+ * Detects template type from vault folder structure.
10
+ *
11
+ * Provides automatic template identification for backwards compatibility
12
+ * with existing vaults.
13
+ */
14
+ export class TemplateDetector {
15
+ /**
16
+ * Worldbuilding folder patterns (case-insensitive).
17
+ *
18
+ * Vaults with 2+ matching folders are detected as worldbuilding templates.
19
+ */
20
+ static WORLDBUILDING_PATTERNS = [
21
+ 'characters',
22
+ 'character',
23
+ 'locations',
24
+ 'location',
25
+ 'events',
26
+ 'event',
27
+ 'factions',
28
+ 'faction',
29
+ 'lore',
30
+ 'assets',
31
+ 'asset',
32
+ ];
33
+ /**
34
+ * Detect template from vault folder structure.
35
+ *
36
+ * Scans top-level folders and matches against known template patterns.
37
+ * Returns null if no template can be confidently detected.
38
+ *
39
+ * @param vaultPath - Absolute path to vault directory
40
+ * @returns Detection result with confidence level, or null if no match
41
+ */
42
+ async detectTemplate(vaultPath) {
43
+ const folders = await this.listTopLevelFolders(vaultPath);
44
+ // Check for worldbuilding patterns
45
+ const matched = folders.filter((f) => TemplateDetector.WORLDBUILDING_PATTERNS.some((p) => f.toLowerCase().includes(p.toLowerCase())));
46
+ if (matched.length >= 2) {
47
+ const confidence = matched.length >= 4 ? 'high' : matched.length >= 3 ? 'medium' : 'low';
48
+ return {
49
+ templateId: 'worldbuilding',
50
+ confidence,
51
+ matchedPatterns: matched,
52
+ message: `Detected worldbuilding vault (${confidence} confidence). Matched folders: ${matched.join(', ')}`,
53
+ };
54
+ }
55
+ return null;
56
+ }
57
+ /**
58
+ * List top-level folders in vault, excluding hidden directories.
59
+ *
60
+ * @param vaultPath - Absolute path to vault directory
61
+ * @returns Array of folder names
62
+ */
63
+ async listTopLevelFolders(vaultPath) {
64
+ const entries = await fs.readdir(vaultPath, { withFileTypes: true });
65
+ return entries
66
+ .filter((e) => e.isDirectory())
67
+ .filter((e) => !e.name.startsWith('.'))
68
+ .map((e) => e.name);
69
+ }
70
+ }
71
+ //# sourceMappingURL=detector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detector.js","sourceRoot":"","sources":["../../src/templates/detector.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AAmBpC;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAC3B;;;;OAIG;IACK,MAAM,CAAU,sBAAsB,GAAG;QAC/C,YAAY;QACZ,WAAW;QACX,WAAW;QACX,UAAU;QACV,QAAQ;QACR,OAAO;QACP,UAAU;QACV,SAAS;QACT,MAAM;QACN,QAAQ;QACR,OAAO;KACR,CAAC;IAEF;;;;;;;;OAQG;IACH,KAAK,CAAC,cAAc,CAAC,SAAiB;QACpC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAE1D,mCAAmC;QACnC,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CACnC,gBAAgB,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACjD,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAC1C,CACF,CAAC;QAEF,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,UAAU,GACd,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;YAExE,OAAO;gBACL,UAAU,EAAE,eAAe;gBAC3B,UAAU;gBACV,eAAe,EAAE,OAAO;gBACxB,OAAO,EAAE,iCAAiC,UAAU,kCAAkC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;aAC3G,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,mBAAmB,CAAC,SAAiB;QACjD,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QACrE,OAAO,OAAO;aACX,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;aAC9B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;aACtC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC"}
@@ -0,0 +1,66 @@
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
+ import type { FolderMapping } from './types.js';
9
+ /**
10
+ * Default folder-to-type mappings for common worldbuilding folder structures.
11
+ *
12
+ * Supports multiple naming conventions (e.g., 'characters', 'people', 'npcs')
13
+ * mapping to the same entity type.
14
+ */
15
+ export declare const DEFAULT_FOLDER_MAPPINGS: FolderMapping[];
16
+ /**
17
+ * FolderMapper infers entity types from file paths.
18
+ *
19
+ * Checks each path segment against folder mappings to determine
20
+ * the most likely entity type for a file.
21
+ */
22
+ export declare class FolderMapper {
23
+ private mappings;
24
+ /**
25
+ * Create a FolderMapper with optional custom mappings.
26
+ *
27
+ * @param customMappings - Additional or override mappings.
28
+ * Custom mappings take precedence over defaults.
29
+ */
30
+ constructor(customMappings?: FolderMapping[]);
31
+ /**
32
+ * Infer entity type from a file path.
33
+ *
34
+ * Checks each folder in the path against mappings.
35
+ * Returns the first match found, or null if no match.
36
+ *
37
+ * @param filePath - Relative or absolute file path
38
+ * @returns Inferred entity type name, or null if no match
39
+ */
40
+ inferType(filePath: string): string | null;
41
+ /**
42
+ * Infer types for multiple file paths.
43
+ *
44
+ * @param filePaths - Array of file paths
45
+ * @returns Map of file path to inferred type (or null)
46
+ */
47
+ inferTypes(filePaths: string[]): Map<string, string | null>;
48
+ /**
49
+ * Get all registered mappings.
50
+ *
51
+ * @returns Array of folder mappings
52
+ */
53
+ getMappings(): FolderMapping[];
54
+ /**
55
+ * Add a new mapping.
56
+ *
57
+ * @param pattern - Folder name pattern
58
+ * @param entityType - Entity type to assign
59
+ */
60
+ addMapping(pattern: string, entityType: string): void;
61
+ }
62
+ /**
63
+ * Singleton instance for convenience.
64
+ */
65
+ export declare const folderMapper: FolderMapper;
66
+ //# sourceMappingURL=folder-mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"folder-mapper.d.ts","sourceRoot":"","sources":["../../src/templates/folder-mapper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,EAAE,aAAa,EAgDlD,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAsB;IAEtC;;;;;OAKG;gBACS,cAAc,GAAE,aAAa,EAAO;IAchD;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAuB1C;;;;;OAKG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAQ3D;;;;OAIG;IACH,WAAW,IAAI,aAAa,EAAE;IAO9B;;;;;OAKG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;CAGtD;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,cAAqB,CAAC"}
@@ -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 @@
1
+ {"version":3,"file":"folder-mapper.js","sourceRoot":"","sources":["../../src/templates/folder-mapper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAoB;IACtD,qBAAqB;IACrB,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE;IAClD,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE;IAC9C,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE;IAC5C,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE;IAC3C,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE;IAE5C,oBAAoB;IACpB,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE;IAChD,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE;IAC7C,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE;IAChD,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAA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IAAI,CAAC,CAAC;YAC3C,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,UAAU,CAAC;YACpB,CAAC;YAED,8DAA8D;YAC9D,KAAK,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAClD,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC7B,OAAO,UAAU,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,SAAmB;QAC5B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;QACjD,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,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,117 @@
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
+ * Includes:
39
+ * - worldbuilding: Characters, locations, events, factions, lore, assets
40
+ * - research: Papers, citations, concepts, notes
41
+ * - people-management: People, goals, teams, 1:1 meetings
42
+ *
43
+ * This function should be called before loading user templates to ensure
44
+ * built-in templates can be referenced by ID.
45
+ */
46
+ export declare function registerBuiltinTemplates(): void;
47
+ /**
48
+ * Register user-defined templates from config.
49
+ *
50
+ * Validates each template and registers it in the registry.
51
+ *
52
+ * @param config - Template configuration from config.json
53
+ * @throws {Error} If any user template fails validation or has duplicate ID
54
+ */
55
+ export declare function registerUserTemplates(config: TemplateConfig): void;
56
+ /**
57
+ * Activate the selected template.
58
+ *
59
+ * Sets the active template in the registry based on the activeTemplate field
60
+ * in the config.
61
+ *
62
+ * @param config - Template configuration from config.json
63
+ * @throws {Error} If the specified template is not registered
64
+ */
65
+ export declare function activateTemplate(config: TemplateConfig): void;
66
+ /**
67
+ * Pre-generate schemas for all entity types in the active template.
68
+ *
69
+ * Caches schemas in the schema factory for fast runtime access.
70
+ * This improves performance for note parsing and validation.
71
+ *
72
+ * @throws {Error} If no template is active
73
+ */
74
+ export declare function pregenerateSchemas(): void;
75
+ /**
76
+ * Full initialization sequence for template system.
77
+ *
78
+ * Performs complete setup:
79
+ * 1. Register built-in templates
80
+ * 2. Load config from file
81
+ * 3. Register user-defined templates
82
+ * 4. Activate selected template
83
+ * 5. Pre-generate schemas
84
+ *
85
+ * This is the main entry point for template system initialization.
86
+ * Call this at application startup before using any template features.
87
+ *
88
+ * @param configPath - Optional explicit path to config file
89
+ * @returns The loaded template configuration
90
+ * @throws {Error} If initialization fails at any step
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * // At application startup
95
+ * const config = initializeTemplates();
96
+ * console.log(`Loaded template: ${config.activeTemplate}`);
97
+ * ```
98
+ */
99
+ export declare function initializeTemplates(configPath?: string): TemplateConfig;
100
+ /**
101
+ * Convenience function to get an entity schema by name.
102
+ *
103
+ * Retrieves the entity type config from the active template and returns
104
+ * the corresponding Zod schema.
105
+ *
106
+ * @param entityTypeName - Name of the entity type (e.g., "character", "location")
107
+ * @returns Zod schema for the entity type
108
+ * @throws {Error} If no template is active or entity type not found
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * const characterSchema = getEntitySchema('character');
113
+ * const validated = characterSchema.parse(frontmatter);
114
+ * ```
115
+ */
116
+ export declare function getEntitySchema(entityTypeName: string): import("zod").ZodObject<any, import("zod/v4/core").$strip>;
117
+ //# 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;AAQjD;;;;;;;;;;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;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAI/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,208 @@
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
+ import { researchTemplate } from './builtin/research.js';
19
+ import { peopleManagementTemplate } from './builtin/people-management.js';
20
+ /**
21
+ * Find the config.json file.
22
+ *
23
+ * Searches in:
24
+ * 1. Provided path (if given)
25
+ * 2. Current working directory
26
+ * 3. Module directory (for development)
27
+ *
28
+ * @param configPath - Optional explicit path to config file
29
+ * @returns Path to config.json if found, null otherwise
30
+ */
31
+ export function findConfigFile(configPath) {
32
+ // If explicit path provided, use it
33
+ if (configPath) {
34
+ return existsSync(configPath) ? resolve(configPath) : null;
35
+ }
36
+ // Try current working directory
37
+ const cwdConfig = resolve(process.cwd(), 'config.json');
38
+ if (existsSync(cwdConfig)) {
39
+ return cwdConfig;
40
+ }
41
+ // Try module directory (for development/testing)
42
+ const moduleDir = dirname(fileURLToPath(import.meta.url));
43
+ const moduleConfig = resolve(moduleDir, '../../config.json');
44
+ if (existsSync(moduleConfig)) {
45
+ return moduleConfig;
46
+ }
47
+ return null;
48
+ }
49
+ /**
50
+ * Load template configuration from config.json.
51
+ *
52
+ * Searches for config.json in multiple locations and extracts the template
53
+ * section. Returns defaults if config file not found or template section missing.
54
+ *
55
+ * @param configPath - Optional explicit path to config file
56
+ * @returns Template configuration object
57
+ * @throws {Error} If config file is found but contains invalid template config
58
+ */
59
+ export function loadTemplateConfig(configPath) {
60
+ const configFilePath = findConfigFile(configPath);
61
+ // If no config file found, return defaults
62
+ if (!configFilePath) {
63
+ return {
64
+ activeTemplate: 'worldbuilding',
65
+ templates: [],
66
+ };
67
+ }
68
+ // Read and parse config file
69
+ let configContent;
70
+ try {
71
+ const fileContent = readFileSync(configFilePath, 'utf-8');
72
+ configContent = JSON.parse(fileContent);
73
+ }
74
+ catch (err) {
75
+ throw new Error(`Failed to read or parse config file at ${configFilePath}: ${err instanceof Error ? err.message : String(err)}`);
76
+ }
77
+ // Extract template section (use defaults if missing)
78
+ const templateConfig = configContent.template || {
79
+ activeTemplate: 'worldbuilding',
80
+ templates: [],
81
+ };
82
+ // Validate the template config
83
+ return validateTemplateConfig(templateConfig);
84
+ }
85
+ /**
86
+ * Register all built-in templates.
87
+ *
88
+ * Includes:
89
+ * - worldbuilding: Characters, locations, events, factions, lore, assets
90
+ * - research: Papers, citations, concepts, notes
91
+ * - people-management: People, goals, teams, 1:1 meetings
92
+ *
93
+ * This function should be called before loading user templates to ensure
94
+ * built-in templates can be referenced by ID.
95
+ */
96
+ export function registerBuiltinTemplates() {
97
+ templateRegistry.register(worldbuildingTemplate, 'builtin');
98
+ templateRegistry.register(researchTemplate, 'builtin');
99
+ templateRegistry.register(peopleManagementTemplate, 'builtin');
100
+ }
101
+ /**
102
+ * Register user-defined templates from config.
103
+ *
104
+ * Validates each template and registers it in the registry.
105
+ *
106
+ * @param config - Template configuration from config.json
107
+ * @throws {Error} If any user template fails validation or has duplicate ID
108
+ */
109
+ export function registerUserTemplates(config) {
110
+ if (!config.templates || config.templates.length === 0) {
111
+ return;
112
+ }
113
+ for (const template of config.templates) {
114
+ // Template already validated by loadTemplateConfig
115
+ templateRegistry.register(template, 'config');
116
+ }
117
+ }
118
+ /**
119
+ * Activate the selected template.
120
+ *
121
+ * Sets the active template in the registry based on the activeTemplate field
122
+ * in the config.
123
+ *
124
+ * @param config - Template configuration from config.json
125
+ * @throws {Error} If the specified template is not registered
126
+ */
127
+ export function activateTemplate(config) {
128
+ templateRegistry.activate(config.activeTemplate);
129
+ }
130
+ /**
131
+ * Pre-generate schemas for all entity types in the active template.
132
+ *
133
+ * Caches schemas in the schema factory for fast runtime access.
134
+ * This improves performance for note parsing and validation.
135
+ *
136
+ * @throws {Error} If no template is active
137
+ */
138
+ export function pregenerateSchemas() {
139
+ const activeTemplate = templateRegistry.getActive();
140
+ if (!activeTemplate) {
141
+ throw new Error('Cannot pregenerate schemas: no active template');
142
+ }
143
+ // Generate schemas for all entity types
144
+ schemaFactory.generateSchemas(activeTemplate.entityTypes);
145
+ }
146
+ /**
147
+ * Full initialization sequence for template system.
148
+ *
149
+ * Performs complete setup:
150
+ * 1. Register built-in templates
151
+ * 2. Load config from file
152
+ * 3. Register user-defined templates
153
+ * 4. Activate selected template
154
+ * 5. Pre-generate schemas
155
+ *
156
+ * This is the main entry point for template system initialization.
157
+ * Call this at application startup before using any template features.
158
+ *
159
+ * @param configPath - Optional explicit path to config file
160
+ * @returns The loaded template configuration
161
+ * @throws {Error} If initialization fails at any step
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * // At application startup
166
+ * const config = initializeTemplates();
167
+ * console.log(`Loaded template: ${config.activeTemplate}`);
168
+ * ```
169
+ */
170
+ export function initializeTemplates(configPath) {
171
+ // 1. Register built-in templates
172
+ registerBuiltinTemplates();
173
+ // 2. Load config
174
+ const config = loadTemplateConfig(configPath);
175
+ // 3. Register user templates
176
+ registerUserTemplates(config);
177
+ // 4. Activate selected template
178
+ activateTemplate(config);
179
+ // 5. Pre-generate schemas
180
+ pregenerateSchemas();
181
+ return config;
182
+ }
183
+ /**
184
+ * Convenience function to get an entity schema by name.
185
+ *
186
+ * Retrieves the entity type config from the active template and returns
187
+ * the corresponding Zod schema.
188
+ *
189
+ * @param entityTypeName - Name of the entity type (e.g., "character", "location")
190
+ * @returns Zod schema for the entity type
191
+ * @throws {Error} If no template is active or entity type not found
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * const characterSchema = getEntitySchema('character');
196
+ * const validated = characterSchema.parse(frontmatter);
197
+ * ```
198
+ */
199
+ export function getEntitySchema(entityTypeName) {
200
+ const entityType = templateRegistry.getEntityType(entityTypeName);
201
+ if (!entityType) {
202
+ const activeTemplate = templateRegistry.getActive();
203
+ const availableTypes = activeTemplate?.entityTypes.map((t) => t.name).join(', ') || 'none';
204
+ throw new Error(`Entity type "${entityTypeName}" not found in active template. Available types: ${availableTypes}`);
205
+ }
206
+ return schemaFactory.getSchema(entityType);
207
+ }
208
+ //# sourceMappingURL=loader.js.map