akbo-cli 0.0.0-stage → 2.0.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.
- package/README.md +786 -2
- package/dist/catalog_store.d.ts +131 -0
- package/dist/catalog_store.js +506 -0
- package/dist/cleaner.d.ts +11 -0
- package/dist/cleaner.js +92 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1961 -0
- package/dist/dream_engine.d.ts +61 -0
- package/dist/dream_engine.js +330 -0
- package/dist/extractors/base.d.ts +35 -0
- package/dist/extractors/base.js +17 -0
- package/dist/extractors/custom_extractor.d.ts +55 -0
- package/dist/extractors/custom_extractor.js +198 -0
- package/dist/extractors/dotnet_extractor.d.ts +11 -0
- package/dist/extractors/dotnet_extractor.js +579 -0
- package/dist/extractors/golang_extractor.d.ts +11 -0
- package/dist/extractors/golang_extractor.js +73 -0
- package/dist/extractors/index.d.ts +14 -0
- package/dist/extractors/index.js +30 -0
- package/dist/extractors/jvm_extractor.d.ts +11 -0
- package/dist/extractors/jvm_extractor.js +319 -0
- package/dist/extractors/node_extractor.d.ts +11 -0
- package/dist/extractors/node_extractor.js +306 -0
- package/dist/extractors/proto_graphql_extractor.d.ts +11 -0
- package/dist/extractors/proto_graphql_extractor.js +125 -0
- package/dist/extractors/python_extractor.d.ts +11 -0
- package/dist/extractors/python_extractor.js +298 -0
- package/dist/extractors/rust_extractor.d.ts +11 -0
- package/dist/extractors/rust_extractor.js +66 -0
- package/dist/graph_builder.d.ts +87 -0
- package/dist/graph_builder.js +1516 -0
- package/dist/guard_service.d.ts +33 -0
- package/dist/guard_service.js +167 -0
- package/dist/harvester.d.ts +38 -0
- package/dist/harvester.js +461 -0
- package/dist/hook_generator.d.ts +34 -0
- package/dist/hook_generator.js +269 -0
- package/dist/importers/skill_importer.d.ts +43 -0
- package/dist/importers/skill_importer.js +470 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +20 -0
- package/dist/indexer.d.ts +19 -0
- package/dist/indexer.js +108 -0
- package/dist/init_service.d.ts +37 -0
- package/dist/init_service.js +246 -0
- package/dist/mcp_server.d.ts +10 -0
- package/dist/mcp_server.js +846 -0
- package/dist/pool_resolver.d.ts +40 -0
- package/dist/pool_resolver.js +84 -0
- package/dist/provider.d.ts +135 -0
- package/dist/provider.js +880 -0
- package/dist/query_service.d.ts +33 -0
- package/dist/query_service.js +161 -0
- package/dist/schema_generator.d.ts +236 -0
- package/dist/schema_generator.js +264 -0
- package/dist/standards_loader.d.ts +7 -0
- package/dist/standards_loader.js +33 -0
- package/dist/types.d.ts +323 -0
- package/dist/types.js +123 -0
- package/dist/unit_synthesizer.d.ts +22 -0
- package/dist/unit_synthesizer.js +196 -0
- package/dist/validator.d.ts +13 -0
- package/dist/validator.js +152 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.js +16 -0
- package/dist/watcher.d.ts +38 -0
- package/dist/watcher.js +132 -0
- package/package.json +56 -6
- package/schemas/index-schema.json +98 -0
- package/schemas/knowledge-unit.json +154 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import child_process from 'node:child_process';
|
|
4
|
+
import { globby } from 'globby';
|
|
5
|
+
import { createLLMProvider, GeminiApiProvider } from './provider.js';
|
|
6
|
+
import { StandardsLoader } from './standards_loader.js';
|
|
7
|
+
export class UnitSynthesizer {
|
|
8
|
+
provider;
|
|
9
|
+
client;
|
|
10
|
+
modelName;
|
|
11
|
+
repoRoot;
|
|
12
|
+
poolDir;
|
|
13
|
+
initialRetryDelay;
|
|
14
|
+
constructor(repoRoot, apiKeyOrProvider, modelName = process.env.GEMINI_MODEL || 'gemini-3.5-flash', initialRetryDelay = 2000, options) {
|
|
15
|
+
this.repoRoot = path.resolve(repoRoot);
|
|
16
|
+
this.poolDir = options?.poolDir;
|
|
17
|
+
this.modelName = modelName;
|
|
18
|
+
this.initialRetryDelay = initialRetryDelay;
|
|
19
|
+
if (apiKeyOrProvider && typeof apiKeyOrProvider === 'object' && 'generateJson' in apiKeyOrProvider) {
|
|
20
|
+
this.provider = apiKeyOrProvider;
|
|
21
|
+
if ('client' in apiKeyOrProvider) {
|
|
22
|
+
this.client = apiKeyOrProvider.client;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const explicitKey = typeof apiKeyOrProvider === 'string' ? apiKeyOrProvider : options?.apiKey;
|
|
27
|
+
const provider = createLLMProvider({
|
|
28
|
+
apiKey: explicitKey,
|
|
29
|
+
model: modelName,
|
|
30
|
+
forceCli: options?.forceCli,
|
|
31
|
+
provider: options?.provider,
|
|
32
|
+
baseUrl: options?.baseUrl,
|
|
33
|
+
initialRetryDelay
|
|
34
|
+
});
|
|
35
|
+
this.provider = provider;
|
|
36
|
+
if (provider instanceof GeminiApiProvider) {
|
|
37
|
+
this.client = provider.client;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
get providerName() {
|
|
42
|
+
return this.provider.name;
|
|
43
|
+
}
|
|
44
|
+
async synthesizeUnit(unit) {
|
|
45
|
+
const fileSnippets = await this.readTargetFiles(unit.targetFilesOrPatterns);
|
|
46
|
+
const prompt = this.buildPrompt(unit, fileSnippets);
|
|
47
|
+
try {
|
|
48
|
+
const parsed = await this.provider.generateJson(prompt);
|
|
49
|
+
// Sanitize fields
|
|
50
|
+
parsed.id = unit.id;
|
|
51
|
+
parsed.domain = unit.domain;
|
|
52
|
+
parsed.status = parsed.status || 'approved';
|
|
53
|
+
parsed.version = parsed.version || '1.0.0';
|
|
54
|
+
return parsed;
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
throw new Error(`Failed to parse unit ${unit.id} JSON: ${err.message}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
getFileRecencyScore(relPath) {
|
|
61
|
+
const fullPath = path.join(this.repoRoot, relPath);
|
|
62
|
+
try {
|
|
63
|
+
const out = child_process.execSync(`git log -1 --format=%ct -- "${relPath}"`, {
|
|
64
|
+
cwd: this.repoRoot,
|
|
65
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
66
|
+
encoding: 'utf-8',
|
|
67
|
+
timeout: 2000
|
|
68
|
+
}).trim();
|
|
69
|
+
if (out && /^\d+$/.test(out)) {
|
|
70
|
+
return parseInt(out, 10) * 1000;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch { }
|
|
74
|
+
try {
|
|
75
|
+
return fs.statSync(fullPath).mtimeMs;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async readTargetFiles(patterns) {
|
|
82
|
+
const snippets = {};
|
|
83
|
+
for (const pattern of patterns) {
|
|
84
|
+
const matched = await globby(pattern, {
|
|
85
|
+
cwd: this.repoRoot,
|
|
86
|
+
onlyFiles: true,
|
|
87
|
+
dot: true
|
|
88
|
+
});
|
|
89
|
+
// Tier 1 (Fast in-memory sort): Score all files by mtimeMs (0 child processes)
|
|
90
|
+
const fastScored = matched
|
|
91
|
+
.map(relPath => {
|
|
92
|
+
const fullPath = path.join(this.repoRoot, relPath);
|
|
93
|
+
let mtime = 0;
|
|
94
|
+
try {
|
|
95
|
+
mtime = fs.statSync(fullPath).mtimeMs;
|
|
96
|
+
}
|
|
97
|
+
catch { }
|
|
98
|
+
return { relPath, mtime };
|
|
99
|
+
})
|
|
100
|
+
.sort((a, b) => b.mtime - a.mtime);
|
|
101
|
+
// Tier 2 (Targeted Git refinement): Check git commit timestamps only on top candidates (max 10)
|
|
102
|
+
const topCandidates = fastScored.slice(0, 10);
|
|
103
|
+
const sortedMatched = topCandidates
|
|
104
|
+
.map(item => ({ relPath: item.relPath, score: this.getFileRecencyScore(item.relPath) }))
|
|
105
|
+
.sort((a, b) => b.score - a.score)
|
|
106
|
+
.map(item => item.relPath);
|
|
107
|
+
for (const relPath of sortedMatched.slice(0, 3)) { // Read top 3 most recent files per pattern to reflect target conventions
|
|
108
|
+
const fullPath = path.join(this.repoRoot, relPath);
|
|
109
|
+
try {
|
|
110
|
+
const stats = fs.statSync(fullPath);
|
|
111
|
+
if (stats.size > 100 * 1024) {
|
|
112
|
+
// If file is > 100KB, read only first 300 lines
|
|
113
|
+
const content = fs.readFileSync(fullPath, 'utf-8').split('\n').slice(0, 300).join('\n');
|
|
114
|
+
snippets[relPath] = `${content}\n\n... [Truncated for brevity - ${stats.size} bytes total]`;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
snippets[relPath] = fs.readFileSync(fullPath, 'utf-8');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Skip unreadable files
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return snippets;
|
|
126
|
+
}
|
|
127
|
+
buildPrompt(unit, snippets) {
|
|
128
|
+
const filesContext = Object.entries(snippets)
|
|
129
|
+
.map(([filepath, content]) => `### FILE: ${filepath}\n\`\`\`\n${content}\n\`\`\``)
|
|
130
|
+
.join('\n\n');
|
|
131
|
+
const standards = StandardsLoader.load(this.repoRoot, this.poolDir);
|
|
132
|
+
let standardsContext = '';
|
|
133
|
+
if (standards) {
|
|
134
|
+
const targets = standards.standards.target_patterns;
|
|
135
|
+
const deprecated = standards.standards.deprecated_patterns;
|
|
136
|
+
if (targets.length > 0 || deprecated.length > 0) {
|
|
137
|
+
standardsContext = `
|
|
138
|
+
IMPORTANT ARCHITECTURAL STANDARDS GUIDELINES:
|
|
139
|
+
The repository author has defined explicit target modern standards and forbidden legacy anti-patterns:
|
|
140
|
+
${targets.length > 0 ? `Target Patterns (MUST enforce in "do" array if relevant to this unit):\n${targets.map(t => `- Pattern "${t.pattern}": ${t.description || ''}`).join('\n')}` : ''}
|
|
141
|
+
${deprecated.length > 0 ? `Deprecated / Legacy Anti-Patterns (MUST strictly prohibit in "dont" array if relevant to this unit):\n${deprecated.map(d => `- Pattern "${d.pattern}": ${d.reason || ''}`).join('\n')}` : ''}
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return `
|
|
146
|
+
You are the Chief Software Architect creating an Atomic Knowledge Base Unit for AI coding agents (Antigravity, Cursor, Claude Code).
|
|
147
|
+
AI agents will load and strictly follow this Knowledge Unit whenever working in this domain.
|
|
148
|
+
|
|
149
|
+
Knowledge Unit ID: ${unit.id}
|
|
150
|
+
Domain: ${unit.domain}
|
|
151
|
+
Title: ${unit.title}
|
|
152
|
+
Purpose: ${unit.purpose}
|
|
153
|
+
|
|
154
|
+
Here are the specific targeted code/config snippets extracted from the repository:
|
|
155
|
+
${filesContext || 'No specific files found matching pattern. Rely on architectural conventions for this technology stack.'}
|
|
156
|
+
${standardsContext}
|
|
157
|
+
TASK:
|
|
158
|
+
Extract non-negotiable architectural invariants, code conventions, do's, dont's, and reasoning.
|
|
159
|
+
Avoid trivial advice like "write clean code" or "add comments".
|
|
160
|
+
Focus on SPECIFIC technology constraints, library choices, safety rules, directory layouts, and error prevention invariants evident in the code.
|
|
161
|
+
If target patterns or deprecated patterns were specified above, strictly honor them by enforcing target patterns in "do" and prohibiting deprecated patterns in "dont".
|
|
162
|
+
|
|
163
|
+
Output STRICT JSON conforming to this schema:
|
|
164
|
+
{
|
|
165
|
+
"id": "${unit.id}",
|
|
166
|
+
"type": "architecture_standard" | "development_standard" | "product_rule" | "architecture_decision" | "security_standard",
|
|
167
|
+
"title": "${unit.title}",
|
|
168
|
+
"domain": "${unit.domain}",
|
|
169
|
+
"status": "approved",
|
|
170
|
+
"version": "1.0.0",
|
|
171
|
+
"authority": {
|
|
172
|
+
"level": "official",
|
|
173
|
+
"confidence": "high"
|
|
174
|
+
},
|
|
175
|
+
"owner": {
|
|
176
|
+
"team": "core_architecture"
|
|
177
|
+
},
|
|
178
|
+
"applies_to": [
|
|
179
|
+
"e.g. backend", "frontend", "api", "database", etc.
|
|
180
|
+
],
|
|
181
|
+
"rule": "Single concise paragraph stating the non-negotiable overarching architectural rule.",
|
|
182
|
+
"do": [
|
|
183
|
+
"Concrete, highly actionable requirement 1",
|
|
184
|
+
"Concrete requirement 2",
|
|
185
|
+
"Concrete requirement 3"
|
|
186
|
+
],
|
|
187
|
+
"dont": [
|
|
188
|
+
"Specific anti-pattern or prohibited behavior 1",
|
|
189
|
+
"Specific anti-pattern 2"
|
|
190
|
+
],
|
|
191
|
+
"reason": "Clear explanation of WHY this rule is mandatory (e.g. performance, zero zombie processes, consistency, security).",
|
|
192
|
+
"related_items": []
|
|
193
|
+
}
|
|
194
|
+
`;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type PoolConfig } from './pool_resolver.js';
|
|
2
|
+
export interface ValidationResult {
|
|
3
|
+
valid: boolean;
|
|
4
|
+
errors: string[];
|
|
5
|
+
warnings: string[];
|
|
6
|
+
unitCount: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class KnowledgeValidator {
|
|
9
|
+
private repoRoot;
|
|
10
|
+
poolConfig: PoolConfig;
|
|
11
|
+
constructor(repoRoot: string, poolDir?: string);
|
|
12
|
+
validate(): Promise<ValidationResult>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import YAML from 'yaml';
|
|
4
|
+
import { globby } from 'globby';
|
|
5
|
+
import { MasterIndexSchema, StandardKnowledgeUnitSchema, DecisionKnowledgeUnitSchema } from './types.js';
|
|
6
|
+
import { KnowledgePoolResolver } from './pool_resolver.js';
|
|
7
|
+
export class KnowledgeValidator {
|
|
8
|
+
repoRoot;
|
|
9
|
+
poolConfig;
|
|
10
|
+
constructor(repoRoot, poolDir) {
|
|
11
|
+
this.repoRoot = path.resolve(repoRoot);
|
|
12
|
+
this.poolConfig = KnowledgePoolResolver.resolve(this.repoRoot, { explicitPoolDir: poolDir });
|
|
13
|
+
}
|
|
14
|
+
async validate() {
|
|
15
|
+
const errors = [];
|
|
16
|
+
const warnings = [];
|
|
17
|
+
const indexPath = path.join(this.poolConfig.knowledgeDir, 'index.yaml');
|
|
18
|
+
if (!fs.existsSync(indexPath)) {
|
|
19
|
+
return {
|
|
20
|
+
valid: false,
|
|
21
|
+
errors: [`Missing master index at ${indexPath}`],
|
|
22
|
+
warnings: [],
|
|
23
|
+
unitCount: 0
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
let indexData;
|
|
27
|
+
try {
|
|
28
|
+
indexData = YAML.parse(fs.readFileSync(indexPath, 'utf-8'));
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
return {
|
|
32
|
+
valid: false,
|
|
33
|
+
errors: [`Syntax error in knowledge/index.yaml: ${err}`],
|
|
34
|
+
warnings: [],
|
|
35
|
+
unitCount: 0
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Runtime Zod schema validation for master index
|
|
39
|
+
const parsedIndex = MasterIndexSchema.safeParse(indexData);
|
|
40
|
+
if (!parsedIndex.success) {
|
|
41
|
+
for (const issue of parsedIndex.error.issues) {
|
|
42
|
+
const pathStr = issue.path.length > 0 ? ` [${issue.path.join('.')}]` : '';
|
|
43
|
+
errors.push(`knowledge/index.yaml:${pathStr} ${issue.message}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Scan all unit files, excluding index.yaml and domain catalog index.yaml files
|
|
47
|
+
const unitFiles = await globby(['knowledge/**/*.yaml', '!knowledge/index.yaml', '!knowledge/**/index.yaml'], {
|
|
48
|
+
cwd: this.poolConfig.poolDir,
|
|
49
|
+
onlyFiles: true
|
|
50
|
+
});
|
|
51
|
+
const definedIds = new Set();
|
|
52
|
+
for (const relFile of unitFiles) {
|
|
53
|
+
const fullPath = path.join(this.poolConfig.poolDir, relFile);
|
|
54
|
+
let content;
|
|
55
|
+
try {
|
|
56
|
+
content = YAML.parse(fs.readFileSync(fullPath, 'utf-8'));
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
errors.push(`${relFile}: Invalid YAML syntax (${err})`);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (typeof content !== 'object' || content === null) {
|
|
63
|
+
errors.push(`${relFile}: Knowledge unit content must be a valid YAML mapping object`);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const rawUnit = content;
|
|
67
|
+
const isDecision = rawUnit.type === 'architecture_decision' || relFile.includes('decisions/');
|
|
68
|
+
if (isDecision) {
|
|
69
|
+
const parsedDecision = DecisionKnowledgeUnitSchema.safeParse(rawUnit);
|
|
70
|
+
if (!parsedDecision.success) {
|
|
71
|
+
for (const issue of parsedDecision.error.issues) {
|
|
72
|
+
const pathStr = issue.path.length > 0 ? ` [${issue.path.join('.')}]` : '';
|
|
73
|
+
errors.push(`${relFile}:${pathStr} ${issue.message}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
definedIds.add(parsedDecision.data.id);
|
|
78
|
+
if (!parsedDecision.data.context) {
|
|
79
|
+
warnings.push(`${relFile}: Decision missing recommended field 'context'`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const parsedUnit = StandardKnowledgeUnitSchema.safeParse(rawUnit);
|
|
85
|
+
if (!parsedUnit.success) {
|
|
86
|
+
for (const issue of parsedUnit.error.issues) {
|
|
87
|
+
const pathStr = issue.path.length > 0 ? ` [${issue.path.join('.')}]` : '';
|
|
88
|
+
errors.push(`${relFile}:${pathStr} ${issue.message}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
definedIds.add(parsedUnit.data.id);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Verify index references against physical files
|
|
97
|
+
if (parsedIndex.success) {
|
|
98
|
+
// 1. Check flat knowledge_units
|
|
99
|
+
const knowledgeUnits = parsedIndex.data.knowledge_units || {};
|
|
100
|
+
for (const [, list] of Object.entries(knowledgeUnits)) {
|
|
101
|
+
if (Array.isArray(list)) {
|
|
102
|
+
for (const item of list) {
|
|
103
|
+
if (item.file && !fs.existsSync(path.join(this.poolConfig.poolDir, item.file))) {
|
|
104
|
+
errors.push(`index.yaml references non-existent file: ${item.file}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// 2. Check Namespaced Central Hub domain sub-catalogs
|
|
110
|
+
if (parsedIndex.data.domains && Array.isArray(parsedIndex.data.domains)) {
|
|
111
|
+
for (const domainRef of parsedIndex.data.domains) {
|
|
112
|
+
const catalogPath = path.join(this.poolConfig.poolDir, domainRef.catalog);
|
|
113
|
+
if (!fs.existsSync(catalogPath)) {
|
|
114
|
+
errors.push(`index.yaml references non-existent domain catalog: ${domainRef.catalog}`);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
try {
|
|
118
|
+
const subData = YAML.parse(fs.readFileSync(catalogPath, 'utf-8'));
|
|
119
|
+
const parsedSub = MasterIndexSchema.safeParse(subData);
|
|
120
|
+
if (!parsedSub.success) {
|
|
121
|
+
for (const issue of parsedSub.error.issues) {
|
|
122
|
+
const pathStr = issue.path.length > 0 ? ` [${issue.path.join('.')}]` : '';
|
|
123
|
+
errors.push(`${domainRef.catalog}:${pathStr} ${issue.message}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
for (const [, list] of Object.entries(parsedSub.data.knowledge_units || {})) {
|
|
128
|
+
if (Array.isArray(list)) {
|
|
129
|
+
for (const item of list) {
|
|
130
|
+
if (item.file && !fs.existsSync(path.join(this.poolConfig.poolDir, item.file))) {
|
|
131
|
+
errors.push(`${domainRef.catalog} references non-existent file: ${item.file}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
errors.push(`Syntax error in domain catalog ${domainRef.catalog}: ${err}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
valid: errors.length === 0,
|
|
147
|
+
errors,
|
|
148
|
+
warnings,
|
|
149
|
+
unitCount: unitFiles.length
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the current semantic version of akbo-cli.
|
|
4
|
+
* Dynamically resolves from package.json with a fallback to the build-time constant.
|
|
5
|
+
*/
|
|
6
|
+
export function getVersion() {
|
|
7
|
+
try {
|
|
8
|
+
const pkgPath = new URL('../package.json', import.meta.url);
|
|
9
|
+
const content = fs.readFileSync(pkgPath, 'utf-8');
|
|
10
|
+
return JSON.parse(content).version || '2.0.0';
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return '2.0.0';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export const VERSION = getVersion();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { CodebaseKnowledgeGraph } from './types.js';
|
|
2
|
+
export interface WatchOptions {
|
|
3
|
+
dir?: string;
|
|
4
|
+
out?: string;
|
|
5
|
+
format?: 'json' | 'mermaid' | 'markdown';
|
|
6
|
+
clustered?: boolean;
|
|
7
|
+
maxNodes?: number;
|
|
8
|
+
nodeTypes?: string[] | string;
|
|
9
|
+
debounceMs?: number;
|
|
10
|
+
onUpdate?: (event: {
|
|
11
|
+
timestamp: string;
|
|
12
|
+
nodesCount: number;
|
|
13
|
+
edgesCount: number;
|
|
14
|
+
outPath?: string;
|
|
15
|
+
durationMs: number;
|
|
16
|
+
}) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare class CodebaseWatcher {
|
|
19
|
+
private repoRoot;
|
|
20
|
+
private poolDir?;
|
|
21
|
+
private isWatching;
|
|
22
|
+
private watcher;
|
|
23
|
+
private debounceTimer;
|
|
24
|
+
constructor(repoRoot?: string, poolDir?: string);
|
|
25
|
+
/**
|
|
26
|
+
* Re-builds and writes the graph snapshot once.
|
|
27
|
+
*/
|
|
28
|
+
rebuildGraph(options?: WatchOptions): Promise<{
|
|
29
|
+
graph: CodebaseKnowledgeGraph;
|
|
30
|
+
outPath?: string;
|
|
31
|
+
durationMs: number;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Starts watching the target directory for file updates and automatically re-renders the CKG.
|
|
35
|
+
*/
|
|
36
|
+
start(options?: WatchOptions): Promise<void>;
|
|
37
|
+
stop(): void;
|
|
38
|
+
}
|
package/dist/watcher.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { Harvester } from './harvester.js';
|
|
4
|
+
import { GraphBuilder } from './graph_builder.js';
|
|
5
|
+
export class CodebaseWatcher {
|
|
6
|
+
repoRoot;
|
|
7
|
+
poolDir;
|
|
8
|
+
isWatching = false;
|
|
9
|
+
watcher = null;
|
|
10
|
+
debounceTimer = null;
|
|
11
|
+
constructor(repoRoot = process.cwd(), poolDir) {
|
|
12
|
+
this.repoRoot = path.resolve(repoRoot).replace(/\\/g, '/');
|
|
13
|
+
this.poolDir = poolDir;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Re-builds and writes the graph snapshot once.
|
|
17
|
+
*/
|
|
18
|
+
async rebuildGraph(options = {}) {
|
|
19
|
+
const startTime = Date.now();
|
|
20
|
+
const targetDir = path.resolve(options.dir || this.repoRoot);
|
|
21
|
+
const harvester = new Harvester(targetDir, undefined, this.poolDir);
|
|
22
|
+
const skeleton = await harvester.harvest({ useCache: true });
|
|
23
|
+
const graphBuilder = new GraphBuilder(targetDir, this.poolDir);
|
|
24
|
+
const graph = await graphBuilder.buildGraph(skeleton, undefined, { useCache: true });
|
|
25
|
+
const clustered = options.clustered !== false;
|
|
26
|
+
const format = options.format || 'json';
|
|
27
|
+
let outPath;
|
|
28
|
+
if (options.out) {
|
|
29
|
+
outPath = path.isAbsolute(options.out)
|
|
30
|
+
? options.out
|
|
31
|
+
: path.resolve(targetDir, options.out);
|
|
32
|
+
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
33
|
+
if (format === 'mermaid') {
|
|
34
|
+
const mermaid = graphBuilder.exportMermaid(graph, {
|
|
35
|
+
clustered,
|
|
36
|
+
maxNodes: options.maxNodes,
|
|
37
|
+
nodeTypes: options.nodeTypes
|
|
38
|
+
});
|
|
39
|
+
fs.writeFileSync(outPath, mermaid, 'utf-8');
|
|
40
|
+
}
|
|
41
|
+
else if (format === 'markdown') {
|
|
42
|
+
let md = `# Codebase Knowledge Graph\n\n`;
|
|
43
|
+
md += `Total Entities: ${graph.nodes.length} | Relationships: ${graph.edges.length}\n\n`;
|
|
44
|
+
md += `\`\`\`mermaid\n${graphBuilder.exportMermaid(graph, {
|
|
45
|
+
clustered,
|
|
46
|
+
maxNodes: options.maxNodes,
|
|
47
|
+
nodeTypes: options.nodeTypes
|
|
48
|
+
})}\n\`\`\`\n\n`;
|
|
49
|
+
md += `## Entities\n| ID | Type | Label | File |\n| :--- | :--- | :--- | :--- |\n`;
|
|
50
|
+
for (const n of graph.nodes) {
|
|
51
|
+
md += `| \`${n.id}\` | ${n.type} | ${n.label} | ${n.file || '-'} |\n`;
|
|
52
|
+
}
|
|
53
|
+
fs.writeFileSync(outPath, md, 'utf-8');
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
fs.writeFileSync(outPath, JSON.stringify(graph, null, 2), 'utf-8');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const durationMs = Date.now() - startTime;
|
|
60
|
+
return { graph, outPath, durationMs };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Starts watching the target directory for file updates and automatically re-renders the CKG.
|
|
64
|
+
*/
|
|
65
|
+
async start(options = {}) {
|
|
66
|
+
const targetDir = path.resolve(options.dir || this.repoRoot);
|
|
67
|
+
const debounceMs = options.debounceMs || 500;
|
|
68
|
+
// Initial build
|
|
69
|
+
const initial = await this.rebuildGraph(options);
|
|
70
|
+
if (options.onUpdate) {
|
|
71
|
+
options.onUpdate({
|
|
72
|
+
timestamp: new Date().toISOString(),
|
|
73
|
+
nodesCount: initial.graph.nodes.length,
|
|
74
|
+
edgesCount: initial.graph.edges.length,
|
|
75
|
+
outPath: initial.outPath,
|
|
76
|
+
durationMs: initial.durationMs
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
this.isWatching = true;
|
|
80
|
+
try {
|
|
81
|
+
this.watcher = fs.watch(targetDir, { recursive: true }, (_eventType, filename) => {
|
|
82
|
+
if (!this.isWatching)
|
|
83
|
+
return;
|
|
84
|
+
if (!filename)
|
|
85
|
+
return;
|
|
86
|
+
// Skip ignored directories & dotfiles
|
|
87
|
+
const norm = filename.replace(/\\/g, '/');
|
|
88
|
+
if (norm.startsWith('.git') ||
|
|
89
|
+
norm.startsWith('node_modules') ||
|
|
90
|
+
norm.startsWith('dist') ||
|
|
91
|
+
norm.startsWith('.akb') ||
|
|
92
|
+
norm.endsWith('.tmp')) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (this.debounceTimer) {
|
|
96
|
+
clearTimeout(this.debounceTimer);
|
|
97
|
+
}
|
|
98
|
+
this.debounceTimer = setTimeout(async () => {
|
|
99
|
+
try {
|
|
100
|
+
const update = await this.rebuildGraph(options);
|
|
101
|
+
if (options.onUpdate) {
|
|
102
|
+
options.onUpdate({
|
|
103
|
+
timestamp: new Date().toISOString(),
|
|
104
|
+
nodesCount: update.graph.nodes.length,
|
|
105
|
+
edgesCount: update.graph.edges.length,
|
|
106
|
+
outPath: update.outPath,
|
|
107
|
+
durationMs: update.durationMs
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Silently continue watching on transient file-lock errors
|
|
113
|
+
}
|
|
114
|
+
}, debounceMs);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// Fallback gracefully if recursive watch is unavailable on host filesystem
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
stop() {
|
|
122
|
+
this.isWatching = false;
|
|
123
|
+
if (this.debounceTimer) {
|
|
124
|
+
clearTimeout(this.debounceTimer);
|
|
125
|
+
this.debounceTimer = null;
|
|
126
|
+
}
|
|
127
|
+
if (this.watcher) {
|
|
128
|
+
this.watcher.close();
|
|
129
|
+
this.watcher = null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "akbo-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "akbo-cli",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "AI-Native Knowledge Base Oracle & Operator (AKBO) - Deterministic AST Harvester, Agent Memory Consolidation (Dreaming), CKG Engine & Runtime Guardrails",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"akbo": "dist/cli.js",
|
|
10
|
+
"akbo-cli": "dist/cli.js",
|
|
11
|
+
"akb": "dist/cli.js",
|
|
12
|
+
"akbo-mcp": "dist/cli.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"schemas",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"dev": "tsx src/cli.ts",
|
|
22
|
+
"start": "node dist/cli.js",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"release": "node scripts/publish-release.mjs",
|
|
25
|
+
"prepublishOnly": "npm run test && npm run build"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"ai",
|
|
29
|
+
"knowledge-base",
|
|
30
|
+
"oracle",
|
|
31
|
+
"operator",
|
|
32
|
+
"agents",
|
|
33
|
+
"cursor",
|
|
34
|
+
"antigravity",
|
|
35
|
+
"claude-code",
|
|
36
|
+
"architecture-invariants"
|
|
37
|
+
],
|
|
38
|
+
"author": "",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
42
|
+
"chalk": "^5.4.1",
|
|
43
|
+
"commander": "^12.1.0",
|
|
44
|
+
"dotenv": "^16.4.7",
|
|
45
|
+
"globby": "^14.0.2",
|
|
46
|
+
"ignore": "^7.0.3",
|
|
47
|
+
"yaml": "^2.7.0",
|
|
48
|
+
"zod": "^4.6.7"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^22.13.5",
|
|
52
|
+
"tsx": "^4.19.3",
|
|
53
|
+
"typescript": "^5.7.3",
|
|
54
|
+
"vitest": "^3.0.6"
|
|
55
|
+
}
|
|
56
|
+
}
|