akbo-cli 0.0.0-stage → 1.9.4

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 (66) hide show
  1. package/README.md +706 -2
  2. package/dist/catalog_store.d.ts +78 -0
  3. package/dist/catalog_store.js +375 -0
  4. package/dist/cleaner.d.ts +11 -0
  5. package/dist/cleaner.js +92 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +1596 -0
  8. package/dist/extractors/base.d.ts +35 -0
  9. package/dist/extractors/base.js +17 -0
  10. package/dist/extractors/custom_extractor.d.ts +55 -0
  11. package/dist/extractors/custom_extractor.js +198 -0
  12. package/dist/extractors/dotnet_extractor.d.ts +11 -0
  13. package/dist/extractors/dotnet_extractor.js +579 -0
  14. package/dist/extractors/golang_extractor.d.ts +11 -0
  15. package/dist/extractors/golang_extractor.js +73 -0
  16. package/dist/extractors/index.d.ts +14 -0
  17. package/dist/extractors/index.js +30 -0
  18. package/dist/extractors/jvm_extractor.d.ts +11 -0
  19. package/dist/extractors/jvm_extractor.js +319 -0
  20. package/dist/extractors/node_extractor.d.ts +11 -0
  21. package/dist/extractors/node_extractor.js +306 -0
  22. package/dist/extractors/proto_graphql_extractor.d.ts +11 -0
  23. package/dist/extractors/proto_graphql_extractor.js +125 -0
  24. package/dist/extractors/python_extractor.d.ts +11 -0
  25. package/dist/extractors/python_extractor.js +298 -0
  26. package/dist/extractors/rust_extractor.d.ts +11 -0
  27. package/dist/extractors/rust_extractor.js +66 -0
  28. package/dist/graph_builder.d.ts +87 -0
  29. package/dist/graph_builder.js +1498 -0
  30. package/dist/harvester.d.ts +38 -0
  31. package/dist/harvester.js +461 -0
  32. package/dist/hook_generator.d.ts +26 -0
  33. package/dist/hook_generator.js +203 -0
  34. package/dist/importers/skill_importer.d.ts +43 -0
  35. package/dist/importers/skill_importer.js +470 -0
  36. package/dist/index.d.ts +17 -0
  37. package/dist/index.js +17 -0
  38. package/dist/indexer.d.ts +19 -0
  39. package/dist/indexer.js +108 -0
  40. package/dist/init_service.d.ts +37 -0
  41. package/dist/init_service.js +246 -0
  42. package/dist/mcp_server.d.ts +10 -0
  43. package/dist/mcp_server.js +632 -0
  44. package/dist/pool_resolver.d.ts +40 -0
  45. package/dist/pool_resolver.js +84 -0
  46. package/dist/provider.d.ts +135 -0
  47. package/dist/provider.js +880 -0
  48. package/dist/query_service.d.ts +33 -0
  49. package/dist/query_service.js +161 -0
  50. package/dist/schema_generator.d.ts +236 -0
  51. package/dist/schema_generator.js +264 -0
  52. package/dist/standards_loader.d.ts +7 -0
  53. package/dist/standards_loader.js +33 -0
  54. package/dist/types.d.ts +265 -0
  55. package/dist/types.js +105 -0
  56. package/dist/unit_synthesizer.d.ts +22 -0
  57. package/dist/unit_synthesizer.js +196 -0
  58. package/dist/validator.d.ts +13 -0
  59. package/dist/validator.js +152 -0
  60. package/dist/version.d.ts +6 -0
  61. package/dist/version.js +16 -0
  62. package/dist/watcher.d.ts +38 -0
  63. package/dist/watcher.js +132 -0
  64. package/package.json +56 -6
  65. package/schemas/index-schema.json +98 -0
  66. package/schemas/knowledge-unit.json +154 -0
@@ -0,0 +1,33 @@
1
+ import { type LLMProvider } from './provider.js';
2
+ import type { GraphNeighborhood } from './types.js';
3
+ export interface QueryServiceOptions {
4
+ dir?: string;
5
+ poolDir?: string;
6
+ model?: string;
7
+ forceCli?: boolean;
8
+ provider?: LLMProvider;
9
+ providerName?: string;
10
+ apiKey?: string;
11
+ baseUrl?: string;
12
+ useCache?: boolean;
13
+ cachePath?: string;
14
+ onProgress?: (message: string) => void;
15
+ }
16
+ export interface QueryResult {
17
+ answer: string;
18
+ keyEntities: string[];
19
+ activeRules: string[];
20
+ groundedEntitiesCount: number;
21
+ neighborhood: GraphNeighborhood | null;
22
+ contextSlice: string;
23
+ }
24
+ /**
25
+ * Shared service orchestrating GraphRAG queries, cross-lingual semantic seed grounding,
26
+ * and grounded architectural answer synthesis across both CLI and MCP server interfaces.
27
+ */
28
+ export declare class QueryService {
29
+ private repoRoot;
30
+ private poolDir?;
31
+ constructor(repoRoot?: string, poolDir?: string);
32
+ query(prompt: string, options?: QueryServiceOptions): Promise<QueryResult>;
33
+ }
@@ -0,0 +1,161 @@
1
+ import path from 'node:path';
2
+ import { Harvester } from './harvester.js';
3
+ import { GraphBuilder } from './graph_builder.js';
4
+ import { createLLMProvider } from './provider.js';
5
+ const COMMON_STOPWORDS = new Set([
6
+ 'how', 'what', 'where', 'when', 'which', 'why', 'who',
7
+ 'explain', 'the', 'and', 'for', 'with', 'from', 'that',
8
+ 'this', 'are', 'used', 'does', 'did', 'show', 'tell',
9
+ 'about', 'into', 'have', 'has', 'been', 'will', 'would',
10
+ 'could', 'should', 'can', 'may', 'work', 'works', 'working'
11
+ ]);
12
+ function mergeNeighborhoods(neighborhoods) {
13
+ if (neighborhoods.length === 0)
14
+ return null;
15
+ if (neighborhoods.length === 1)
16
+ return neighborhoods[0];
17
+ const primary = neighborhoods[0];
18
+ const nodeMap = new Map();
19
+ const edgeMap = new Map();
20
+ const invariantMap = new Map();
21
+ const deprecationWarningsSet = new Set();
22
+ const formattedSections = [];
23
+ for (const n of neighborhoods) {
24
+ for (const node of n.nodes) {
25
+ nodeMap.set(node.id, node);
26
+ }
27
+ for (const edge of n.edges) {
28
+ const edgeKey = `${edge.source}->${edge.type}->${edge.target}`;
29
+ edgeMap.set(edgeKey, edge);
30
+ }
31
+ for (const inv of n.activeInvariants || []) {
32
+ invariantMap.set(inv.id, inv);
33
+ }
34
+ for (const warn of n.deprecationWarnings || []) {
35
+ deprecationWarningsSet.add(warn);
36
+ }
37
+ formattedSections.push(n.formattedContext);
38
+ }
39
+ return {
40
+ centerNode: primary.centerNode,
41
+ nodes: Array.from(nodeMap.values()),
42
+ edges: Array.from(edgeMap.values()),
43
+ formattedContext: formattedSections.join('\n\n---\n\n'),
44
+ activeInvariants: invariantMap.size > 0 ? Array.from(invariantMap.values()) : undefined,
45
+ deprecationWarnings: deprecationWarningsSet.size > 0 ? Array.from(deprecationWarningsSet) : undefined
46
+ };
47
+ }
48
+ /**
49
+ * Shared service orchestrating GraphRAG queries, cross-lingual semantic seed grounding,
50
+ * and grounded architectural answer synthesis across both CLI and MCP server interfaces.
51
+ */
52
+ export class QueryService {
53
+ repoRoot;
54
+ poolDir;
55
+ constructor(repoRoot = process.cwd(), poolDir) {
56
+ this.repoRoot = path.resolve(repoRoot);
57
+ this.poolDir = poolDir;
58
+ }
59
+ async query(prompt, options = {}) {
60
+ const targetDir = path.resolve(options.dir || this.repoRoot);
61
+ const poolDir = options.poolDir || this.poolDir;
62
+ const harvester = new Harvester(targetDir, undefined, poolDir);
63
+ const skeleton = await harvester.harvest({
64
+ useCache: options.useCache ?? true,
65
+ cachePath: options.cachePath
66
+ });
67
+ const graphBuilder = new GraphBuilder(targetDir, poolDir);
68
+ const graph = await graphBuilder.buildGraph(skeleton, undefined, {
69
+ useCache: options.useCache ?? true,
70
+ cachePath: options.cachePath
71
+ });
72
+ // 1. Direct lexical match attempt with punctuation-stripped tokens and stopword filtering
73
+ const words = prompt
74
+ .toLowerCase()
75
+ .split(/[^\p{L}\p{N}_.\-/]+/iu)
76
+ .map(w => w.replace(/^[\s./\\_\-]+|[\s./\\_\-]+$/g, '').trim())
77
+ .filter(w => w.length > 2 && !COMMON_STOPWORDS.has(w));
78
+ const matchedNeighborhoods = [];
79
+ const seenCenterIds = new Set();
80
+ for (const word of words) {
81
+ const match = graphBuilder.extractNeighborhood(graph, word, 2);
82
+ if (match && !seenCenterIds.has(match.centerNode.id)) {
83
+ seenCenterIds.add(match.centerNode.id);
84
+ matchedNeighborhoods.push(match);
85
+ }
86
+ }
87
+ // Sort matched neighborhoods by richness and merge top 2-3
88
+ matchedNeighborhoods.sort((a, b) => (b.nodes.length + b.edges.length) - (a.nodes.length + a.edges.length));
89
+ let bestNeighborhood = mergeNeighborhoods(matchedNeighborhoods.slice(0, 3));
90
+ const provider = options.provider || createLLMProvider({
91
+ model: options.model || process.env.GEMINI_MODEL || 'gemini-3.5-flash',
92
+ forceCli: Boolean(options.forceCli),
93
+ provider: options.providerName,
94
+ apiKey: options.apiKey,
95
+ baseUrl: options.baseUrl
96
+ });
97
+ // 2. Cross-Lingual & Semantic Seed Grounding if direct match failed
98
+ if (!bestNeighborhood && graph.nodes.length > 0) {
99
+ const candidateEntities = graph.nodes
100
+ .filter(n => n.type !== 'invariant')
101
+ .slice(0, 150)
102
+ .map(n => ({ id: n.id, label: n.label, type: n.type }));
103
+ try {
104
+ if (options.onProgress) {
105
+ options.onProgress('Resolving cross-lingual / semantic entity seeds via LLM...');
106
+ }
107
+ const resolution = await provider.generateJson(`You are an expert multilingual software architect and code graph resolver.
108
+ The user asked a question in English: "${prompt}"
109
+ The codebase entities may be named in local languages (e.g. Spanish, German, French, Chinese, etc.) or domain-specific terminology.
110
+ Available codebase entities:
111
+ ${JSON.stringify(candidateEntities)}
112
+
113
+ Map the user's conceptual intent to 1 to 3 candidate entity IDs from the list (e.g., mapping "invoice" to Spanish "Factura", German "Rechnung", or Chinese "发票", "customer" or "client" to "Cliente" or "Kunde", "order" to "Pedido" or "Bestellung", "billing" to "Facturacion/Finanzas", etc.).
114
+ Return valid JSON: {"resolvedEntityIds": ["id1", "id2"]}`);
115
+ if (resolution.resolvedEntityIds && resolution.resolvedEntityIds.length > 0) {
116
+ const crossLingualMatches = [];
117
+ for (const entId of resolution.resolvedEntityIds) {
118
+ const match = graphBuilder.extractNeighborhood(graph, entId, 2);
119
+ if (match && !seenCenterIds.has(match.centerNode.id)) {
120
+ seenCenterIds.add(match.centerNode.id);
121
+ crossLingualMatches.push(match);
122
+ }
123
+ }
124
+ if (crossLingualMatches.length > 0) {
125
+ crossLingualMatches.sort((a, b) => (b.nodes.length + b.edges.length) - (a.nodes.length + a.edges.length));
126
+ bestNeighborhood = mergeNeighborhoods(crossLingualMatches.slice(0, 3));
127
+ }
128
+ }
129
+ }
130
+ catch {
131
+ // Fallback gracefully if seed resolution call fails
132
+ }
133
+ }
134
+ const contextSlice = bestNeighborhood
135
+ ? bestNeighborhood.formattedContext
136
+ : `Entities summary:\n` + graph.nodes.slice(0, 30).map(n => `- [${n.type}] ${n.label} (${n.file || ''})`).join('\n');
137
+ const groundedEntitiesCount = bestNeighborhood ? bestNeighborhood.nodes.length : Math.min(30, graph.nodes.length);
138
+ if (options.onProgress) {
139
+ options.onProgress(`Grounded in ${groundedEntitiesCount} graph entities. Synthesizing answer...\n`);
140
+ }
141
+ const fullPrompt = `You are a Principal Software Architect.
142
+ Answer the following question about the codebase.
143
+ The user asked in English, so your explanation MUST be written in English.
144
+ Your answer MUST be strictly grounded in the provided Codebase Knowledge Graph (CKG) topological context and architectural invariants. Accurately cite the actual code symbols (even if named in Spanish, German, French, Chinese, etc.) and explain their roles clearly. Do not hallucinate classes, endpoints, or conventions not present in the graph.
145
+
146
+ ${contextSlice}
147
+
148
+ User Question: ${prompt}
149
+
150
+ Provide a concise, highly structured architectural explanation.`;
151
+ const response = await provider.generateJson(fullPrompt + `\n\nReturn your response as a valid JSON object matching: {"answer": "...", "keyEntities": ["..."], "activeRules": ["..."]}`);
152
+ return {
153
+ answer: response.answer || '',
154
+ keyEntities: response.keyEntities || [],
155
+ activeRules: response.activeRules || [],
156
+ groundedEntitiesCount,
157
+ neighborhood: bestNeighborhood,
158
+ contextSlice
159
+ };
160
+ }
161
+ }
@@ -0,0 +1,236 @@
1
+ export declare const KNOWLEDGE_UNIT_JSON_SCHEMA: {
2
+ $schema: string;
3
+ title: string;
4
+ description: string;
5
+ type: string;
6
+ required: string[];
7
+ properties: {
8
+ id: {
9
+ type: string;
10
+ description: string;
11
+ pattern: string;
12
+ };
13
+ type: {
14
+ type: string;
15
+ description: string;
16
+ enum: string[];
17
+ };
18
+ title: {
19
+ type: string;
20
+ description: string;
21
+ };
22
+ domain: {
23
+ type: string;
24
+ description: string;
25
+ };
26
+ status: {
27
+ type: string;
28
+ description: string;
29
+ enum: string[];
30
+ default: string;
31
+ };
32
+ version: {
33
+ type: string;
34
+ description: string;
35
+ default: string;
36
+ };
37
+ authority: {
38
+ type: string;
39
+ description: string;
40
+ properties: {
41
+ level: {
42
+ type: string;
43
+ enum: string[];
44
+ default: string;
45
+ };
46
+ confidence: {
47
+ type: string;
48
+ enum: string[];
49
+ default: string;
50
+ };
51
+ };
52
+ };
53
+ owner: {
54
+ type: string;
55
+ description: string;
56
+ properties: {
57
+ team: {
58
+ type: string;
59
+ description: string;
60
+ };
61
+ };
62
+ };
63
+ applies_to: {
64
+ type: string;
65
+ description: string;
66
+ items: {
67
+ type: string;
68
+ };
69
+ };
70
+ rule: {
71
+ type: string;
72
+ description: string;
73
+ };
74
+ decision: {
75
+ type: string;
76
+ description: string;
77
+ };
78
+ context: {
79
+ type: string;
80
+ description: string;
81
+ };
82
+ do: {
83
+ type: string;
84
+ description: string;
85
+ items: {
86
+ type: string;
87
+ };
88
+ };
89
+ dont: {
90
+ type: string;
91
+ description: string;
92
+ items: {
93
+ type: string;
94
+ };
95
+ };
96
+ reason: {
97
+ type: string;
98
+ description: string;
99
+ };
100
+ related_items: {
101
+ type: string;
102
+ description: string;
103
+ items: {
104
+ type: string;
105
+ };
106
+ };
107
+ skill_file: {
108
+ type: string;
109
+ description: string;
110
+ };
111
+ reference_files: {
112
+ type: string;
113
+ description: string;
114
+ items: {
115
+ type: string;
116
+ };
117
+ };
118
+ workflow_gates: {
119
+ type: string;
120
+ description: string;
121
+ items: {
122
+ type: string;
123
+ };
124
+ };
125
+ };
126
+ };
127
+ export declare const MASTER_INDEX_JSON_SCHEMA: {
128
+ $schema: string;
129
+ title: string;
130
+ description: string;
131
+ type: string;
132
+ required: string[];
133
+ properties: {
134
+ system_name: {
135
+ type: string;
136
+ description: string;
137
+ };
138
+ repository_root: {
139
+ type: string;
140
+ description: string;
141
+ };
142
+ description: {
143
+ type: string;
144
+ description: string;
145
+ };
146
+ knowledge_units_count: {
147
+ type: string;
148
+ description: string;
149
+ };
150
+ last_updated: {
151
+ type: string;
152
+ description: string;
153
+ };
154
+ knowledge_units: {
155
+ type: string;
156
+ description: string;
157
+ additionalProperties: {
158
+ type: string;
159
+ items: {
160
+ type: string;
161
+ required: string[];
162
+ properties: {
163
+ id: {
164
+ type: string;
165
+ };
166
+ file: {
167
+ type: string;
168
+ };
169
+ title: {
170
+ type: string;
171
+ };
172
+ purpose: {
173
+ type: string;
174
+ };
175
+ };
176
+ };
177
+ };
178
+ };
179
+ domains: {
180
+ type: string;
181
+ description: string;
182
+ items: {
183
+ type: string;
184
+ required: string[];
185
+ properties: {
186
+ id: {
187
+ type: string;
188
+ };
189
+ name: {
190
+ type: string;
191
+ };
192
+ description: {
193
+ type: string;
194
+ };
195
+ catalog: {
196
+ type: string;
197
+ };
198
+ applies_to: {
199
+ oneOf: ({
200
+ type: string;
201
+ items: {
202
+ type: string;
203
+ };
204
+ } | {
205
+ type: string;
206
+ items?: undefined;
207
+ })[];
208
+ };
209
+ };
210
+ };
211
+ };
212
+ };
213
+ };
214
+ export declare class SchemaGenerator {
215
+ private repoRoot;
216
+ constructor(repoRoot?: string);
217
+ /**
218
+ * Writes the standard JSON Schemas to schemas/ directory.
219
+ */
220
+ writeSchemas(): {
221
+ unitSchemaPath: string;
222
+ indexSchemaPath: string;
223
+ };
224
+ /**
225
+ * Configures VS Code / Cursor IDE yaml.schemas settings in .vscode/settings.json
226
+ * to automatically enable hover help, autocomplete, and validation for knowledge units.
227
+ */
228
+ configureIdeSettings(): string;
229
+ /**
230
+ * Convenience runner writing both schemas and configuring IDE settings.
231
+ */
232
+ writeAll(): {
233
+ writtenSchemas: string[];
234
+ settingsPath: string;
235
+ };
236
+ }
@@ -0,0 +1,264 @@
1
+ import path from 'node:path';
2
+ import fs from 'node:fs';
3
+ export const KNOWLEDGE_UNIT_JSON_SCHEMA = {
4
+ $schema: 'http://json-schema.org/draft-07/schema#',
5
+ title: 'AKB Knowledge Unit Specification',
6
+ description: 'Schema defining atomic YAML knowledge units (standards, rules, and architecture decisions) for AI coding assistants.',
7
+ type: 'object',
8
+ required: ['id', 'type', 'title', 'domain'],
9
+ properties: {
10
+ id: {
11
+ type: 'string',
12
+ description: 'Unique immutable identifier for this knowledge unit (e.g. ARCH-SYS-001, DEV-TS-001, ADR-001).',
13
+ pattern: '^[A-Za-z0-9]+([_-][A-Za-z0-9]+)*$'
14
+ },
15
+ type: {
16
+ type: 'string',
17
+ description: 'Category type of the knowledge unit.',
18
+ enum: [
19
+ 'architecture_standard',
20
+ 'development_standard',
21
+ 'product_rule',
22
+ 'security_standard',
23
+ 'architecture_decision'
24
+ ]
25
+ },
26
+ title: {
27
+ type: 'string',
28
+ description: 'Human-readable title summarizing the unit directive.'
29
+ },
30
+ domain: {
31
+ type: 'string',
32
+ description: 'Bounded context or architectural domain (e.g. architecture, development, product, decisions, billing, core).'
33
+ },
34
+ status: {
35
+ type: 'string',
36
+ description: 'Current lifecycle status.',
37
+ enum: ['approved', 'draft', 'deprecated', 'accepted', 'proposed', 'locked'],
38
+ default: 'approved'
39
+ },
40
+ version: {
41
+ type: 'string',
42
+ description: 'Semantic version of this knowledge unit specification.',
43
+ default: '1.0.0'
44
+ },
45
+ authority: {
46
+ type: 'object',
47
+ description: 'Organizational authority and confidence level.',
48
+ properties: {
49
+ level: {
50
+ type: 'string',
51
+ enum: ['official', 'guideline', 'experimental', 'human_curated'],
52
+ default: 'official'
53
+ },
54
+ confidence: {
55
+ type: 'string',
56
+ enum: ['high', 'medium', 'low', 'verified'],
57
+ default: 'high'
58
+ }
59
+ }
60
+ },
61
+ owner: {
62
+ type: 'object',
63
+ description: 'Ownership team or persona.',
64
+ properties: {
65
+ team: {
66
+ type: 'string',
67
+ description: 'Team name responsible for enforcing this rule.'
68
+ }
69
+ }
70
+ },
71
+ applies_to: {
72
+ type: 'array',
73
+ description: 'List of file globs, directory paths, or component tags to which this invariant strictly applies.',
74
+ items: {
75
+ type: 'string'
76
+ }
77
+ },
78
+ rule: {
79
+ type: 'string',
80
+ description: 'Primary normative architectural rule or directive enforced by this unit.'
81
+ },
82
+ decision: {
83
+ type: 'string',
84
+ description: 'Architectural decision statement (for type: architecture_decision).'
85
+ },
86
+ context: {
87
+ type: 'string',
88
+ description: 'Problem context and historical motivation.'
89
+ },
90
+ do: {
91
+ type: 'array',
92
+ description: 'Prescriptive action items and best practices that developers and AI agents must follow.',
93
+ items: {
94
+ type: 'string'
95
+ }
96
+ },
97
+ dont: {
98
+ type: 'array',
99
+ description: 'Strict prohibitions and anti-patterns that must not be introduced.',
100
+ items: {
101
+ type: 'string'
102
+ }
103
+ },
104
+ reason: {
105
+ type: 'string',
106
+ description: 'Architectural rationale explaining why this invariant is necessary.'
107
+ },
108
+ related_items: {
109
+ type: 'array',
110
+ description: 'Cross-reference IDs to related Knowledge Units (e.g. ARCH-SYS-001).',
111
+ items: {
112
+ type: 'string'
113
+ }
114
+ },
115
+ skill_file: {
116
+ type: 'string',
117
+ description: 'Relative path to the original human-curated SKILL.md file if imported from an agent skill.'
118
+ },
119
+ reference_files: {
120
+ type: 'array',
121
+ description: 'Discovered companion reference documentation files (e.g. references/*.md) supporting this skill.',
122
+ items: {
123
+ type: 'string'
124
+ }
125
+ },
126
+ workflow_gates: {
127
+ type: 'array',
128
+ description: 'Ordered procedural implementation gates or verification steps extracted from the skill.',
129
+ items: {
130
+ type: 'string'
131
+ }
132
+ }
133
+ }
134
+ };
135
+ export const MASTER_INDEX_JSON_SCHEMA = {
136
+ $schema: 'http://json-schema.org/draft-07/schema#',
137
+ title: 'AKB Master Index & Catalog Router Specification',
138
+ description: 'Schema defining the root knowledge/index.yaml and domain sub-catalogs.',
139
+ type: 'object',
140
+ required: ['system_name'],
141
+ properties: {
142
+ system_name: {
143
+ type: 'string',
144
+ description: 'System name or platform identifier.'
145
+ },
146
+ repository_root: {
147
+ type: 'string',
148
+ description: 'Normalized repository root directory path.'
149
+ },
150
+ description: {
151
+ type: 'string',
152
+ description: 'Overview description of the system or bounded context.'
153
+ },
154
+ knowledge_units_count: {
155
+ type: 'integer',
156
+ description: 'Total number of active knowledge units indexed.'
157
+ },
158
+ last_updated: {
159
+ type: 'string',
160
+ description: 'Date string when the catalog was last updated (YYYY-MM-DD).'
161
+ },
162
+ knowledge_units: {
163
+ type: 'object',
164
+ description: 'Inventory of knowledge units grouped by domain.',
165
+ additionalProperties: {
166
+ type: 'array',
167
+ items: {
168
+ type: 'object',
169
+ required: ['id', 'file', 'title'],
170
+ properties: {
171
+ id: { type: 'string' },
172
+ file: { type: 'string' },
173
+ title: { type: 'string' },
174
+ purpose: { type: 'string' }
175
+ }
176
+ }
177
+ }
178
+ },
179
+ domains: {
180
+ type: 'array',
181
+ description: 'Federated domain catalog references (Namespaced Central Hub).',
182
+ items: {
183
+ type: 'object',
184
+ required: ['id', 'catalog'],
185
+ properties: {
186
+ id: { type: 'string' },
187
+ name: { type: 'string' },
188
+ description: { type: 'string' },
189
+ catalog: { type: 'string' },
190
+ applies_to: {
191
+ oneOf: [
192
+ { type: 'array', items: { type: 'string' } },
193
+ { type: 'string' }
194
+ ]
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }
200
+ };
201
+ export class SchemaGenerator {
202
+ repoRoot;
203
+ constructor(repoRoot = process.cwd()) {
204
+ this.repoRoot = path.resolve(repoRoot).replace(/\\/g, '/');
205
+ }
206
+ /**
207
+ * Writes the standard JSON Schemas to schemas/ directory.
208
+ */
209
+ writeSchemas() {
210
+ const schemasDir = path.join(this.repoRoot, 'schemas');
211
+ fs.mkdirSync(schemasDir, { recursive: true });
212
+ const unitSchemaPath = path.join(schemasDir, 'knowledge-unit.json');
213
+ const indexSchemaPath = path.join(schemasDir, 'index-schema.json');
214
+ fs.writeFileSync(unitSchemaPath, JSON.stringify(KNOWLEDGE_UNIT_JSON_SCHEMA, null, 2), 'utf-8');
215
+ fs.writeFileSync(indexSchemaPath, JSON.stringify(MASTER_INDEX_JSON_SCHEMA, null, 2), 'utf-8');
216
+ return { unitSchemaPath, indexSchemaPath };
217
+ }
218
+ /**
219
+ * Configures VS Code / Cursor IDE yaml.schemas settings in .vscode/settings.json
220
+ * to automatically enable hover help, autocomplete, and validation for knowledge units.
221
+ */
222
+ configureIdeSettings() {
223
+ const vscodeDir = path.join(this.repoRoot, '.vscode');
224
+ fs.mkdirSync(vscodeDir, { recursive: true });
225
+ const settingsPath = path.join(vscodeDir, 'settings.json');
226
+ let settings = {};
227
+ if (fs.existsSync(settingsPath)) {
228
+ try {
229
+ settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
230
+ }
231
+ catch {
232
+ settings = {};
233
+ }
234
+ }
235
+ if (!settings['yaml.schemas']) {
236
+ settings['yaml.schemas'] = {};
237
+ }
238
+ // Configure relative schema mappings
239
+ const relativeUnitSchema = './schemas/knowledge-unit.json';
240
+ const relativeIndexSchema = './schemas/index-schema.json';
241
+ settings['yaml.schemas'][relativeUnitSchema] = [
242
+ 'knowledge/**/*.yaml',
243
+ '!knowledge/index.yaml',
244
+ '!knowledge/**/index.yaml'
245
+ ];
246
+ settings['yaml.schemas'][relativeIndexSchema] = [
247
+ 'knowledge/index.yaml',
248
+ 'knowledge/**/index.yaml'
249
+ ];
250
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf-8');
251
+ return settingsPath;
252
+ }
253
+ /**
254
+ * Convenience runner writing both schemas and configuring IDE settings.
255
+ */
256
+ writeAll() {
257
+ const { unitSchemaPath, indexSchemaPath } = this.writeSchemas();
258
+ const settingsPath = this.configureIdeSettings();
259
+ return {
260
+ writtenSchemas: [unitSchemaPath, indexSchemaPath],
261
+ settingsPath
262
+ };
263
+ }
264
+ }