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.
- package/README.md +706 -2
- package/dist/catalog_store.d.ts +78 -0
- package/dist/catalog_store.js +375 -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 +1596 -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 +1498 -0
- package/dist/harvester.d.ts +38 -0
- package/dist/harvester.js +461 -0
- package/dist/hook_generator.d.ts +26 -0
- package/dist/hook_generator.js +203 -0
- package/dist/importers/skill_importer.d.ts +43 -0
- package/dist/importers/skill_importer.js +470 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +17 -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 +632 -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 +265 -0
- package/dist/types.js +105 -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,246 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import YAML from 'yaml';
|
|
4
|
+
import { Harvester } from './harvester.js';
|
|
5
|
+
import { IndexSynthesizer } from './indexer.js';
|
|
6
|
+
import { UnitSynthesizer } from './unit_synthesizer.js';
|
|
7
|
+
import { HookGenerator } from './hook_generator.js';
|
|
8
|
+
import { KnowledgeValidator } from './validator.js';
|
|
9
|
+
import { cleanArtifacts } from './cleaner.js';
|
|
10
|
+
import { KnowledgePoolResolver } from './pool_resolver.js';
|
|
11
|
+
function findRepoRoot(startDir) {
|
|
12
|
+
let current = path.resolve(startDir);
|
|
13
|
+
while (current !== path.dirname(current)) {
|
|
14
|
+
if (fs.existsSync(path.join(current, '.git')) || fs.existsSync(path.join(current, 'knowledge', 'index.yaml'))) {
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
current = path.dirname(current);
|
|
18
|
+
}
|
|
19
|
+
return path.resolve(startDir);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* All-in-one orchestrator coordinating the complete 5-stage initialization pipeline:
|
|
23
|
+
* Stage 1 (Harvest) -> Stage 2 (Plan) -> Stage 3 (Generate) -> Stage 4 (Hooks & Schemas) -> Stage 5 (Validate).
|
|
24
|
+
*/
|
|
25
|
+
export class InitService {
|
|
26
|
+
repoRoot;
|
|
27
|
+
constructor(repoRoot = process.cwd()) {
|
|
28
|
+
this.repoRoot = findRepoRoot(repoRoot);
|
|
29
|
+
}
|
|
30
|
+
async init(options = {}) {
|
|
31
|
+
const startTime = Date.now();
|
|
32
|
+
const rawTargetDir = path.resolve(options.dir || this.repoRoot);
|
|
33
|
+
const poolConfig = options.poolDir || process.env.AKBO_POOL_DIR
|
|
34
|
+
? KnowledgePoolResolver.resolve(rawTargetDir, { explicitPoolDir: options.poolDir })
|
|
35
|
+
: {
|
|
36
|
+
targetDir: rawTargetDir,
|
|
37
|
+
poolDir: rawTargetDir,
|
|
38
|
+
isExternalPool: false,
|
|
39
|
+
knowledgeDir: path.join(rawTargetDir, 'knowledge'),
|
|
40
|
+
standardsFile: path.join(rawTargetDir, '.akb', 'standards.yaml'),
|
|
41
|
+
customExtractorsFile: path.join(rawTargetDir, '.akb', 'custom-extractors.yaml'),
|
|
42
|
+
cacheDir: path.join(rawTargetDir, '.akb', 'caches'),
|
|
43
|
+
cacheFile: path.join(rawTargetDir, '.akb', 'caches', `${path.basename(rawTargetDir)}-cache.json`)
|
|
44
|
+
};
|
|
45
|
+
const targetDir = poolConfig.targetDir;
|
|
46
|
+
const codeRepoRoot = options.local ? targetDir : findRepoRoot(targetDir);
|
|
47
|
+
const repoRoot = poolConfig.isExternalPool
|
|
48
|
+
? poolConfig.poolDir
|
|
49
|
+
: (options.local ? targetDir : (options.domain ? codeRepoRoot : targetDir));
|
|
50
|
+
const forceCli = Boolean(options.forceCli);
|
|
51
|
+
const model = options.model || process.env.GEMINI_MODEL || 'gemini-3.5-flash';
|
|
52
|
+
const log = options.onProgress || (() => { });
|
|
53
|
+
const skipHooks = Boolean(options.noHooks || (poolConfig.isExternalPool && !options.forceHooks));
|
|
54
|
+
// Stage 1: Deterministic Codebase Harvester (0 tokens)
|
|
55
|
+
log('Stage 1/5: Deterministically scanning codebase topology & schemas (0 tokens)...');
|
|
56
|
+
const harvester = new Harvester(targetDir, undefined, poolConfig.poolDir);
|
|
57
|
+
const skeleton = await harvester.harvest({ useCache: false });
|
|
58
|
+
// Stage 2: Master Index Synthesizer
|
|
59
|
+
log(`Stage 2/5: Synthesizing master index plan using ${model}...`);
|
|
60
|
+
const indexSynthesizer = new IndexSynthesizer(undefined, model, {
|
|
61
|
+
forceCli,
|
|
62
|
+
provider: options.provider,
|
|
63
|
+
apiKey: options.apiKey,
|
|
64
|
+
baseUrl: options.baseUrl
|
|
65
|
+
});
|
|
66
|
+
const plan = await indexSynthesizer.synthesize(skeleton);
|
|
67
|
+
// Stage 3: Atomic Unit Synthesis
|
|
68
|
+
log('Stage 3/5: Synthesizing atomic knowledge units with rule directives...');
|
|
69
|
+
const unitSynthesizer = new UnitSynthesizer(targetDir, undefined, model, 2000, {
|
|
70
|
+
forceCli,
|
|
71
|
+
provider: options.provider,
|
|
72
|
+
apiKey: options.apiKey,
|
|
73
|
+
baseUrl: options.baseUrl,
|
|
74
|
+
poolDir: poolConfig.poolDir
|
|
75
|
+
});
|
|
76
|
+
const flatUnits = [];
|
|
77
|
+
const domains = plan.domains;
|
|
78
|
+
for (const [dom, list] of Object.entries(domains)) {
|
|
79
|
+
for (const u of list) {
|
|
80
|
+
u.domain = options.domain || u.domain || dom;
|
|
81
|
+
if (options.domain) {
|
|
82
|
+
u.file = options.domain === 'core'
|
|
83
|
+
? `knowledge/core/${u.id}.yaml`
|
|
84
|
+
: `knowledge/domains/${options.domain}/${u.id}.yaml`;
|
|
85
|
+
}
|
|
86
|
+
else if (!u.file) {
|
|
87
|
+
u.file = `knowledge/${u.domain}/${u.id}.yaml`;
|
|
88
|
+
}
|
|
89
|
+
flatUnits.push(u);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const generatedUnits = [];
|
|
93
|
+
for (const unit of flatUnits) {
|
|
94
|
+
const outFilePath = unit.file.startsWith('knowledge/')
|
|
95
|
+
? path.resolve(repoRoot, unit.file)
|
|
96
|
+
: (poolConfig.isExternalPool
|
|
97
|
+
? path.resolve(poolConfig.knowledgeDir, path.basename(unit.file))
|
|
98
|
+
: path.resolve(targetDir, unit.file));
|
|
99
|
+
// Protect human_curated or locked knowledge units from overwrite
|
|
100
|
+
if (fs.existsSync(outFilePath) && !options.force) {
|
|
101
|
+
try {
|
|
102
|
+
const existing = YAML.parse(fs.readFileSync(outFilePath, 'utf-8'));
|
|
103
|
+
if (existing?.authority?.level === 'human_curated' || existing?.status === 'locked') {
|
|
104
|
+
log(` • Skipping unit ${unit.id}: protected (${existing?.authority?.level || existing?.status})`);
|
|
105
|
+
generatedUnits.push(existing);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch { }
|
|
110
|
+
}
|
|
111
|
+
log(` • Synthesizing unit ${unit.id}: ${unit.title}...`);
|
|
112
|
+
try {
|
|
113
|
+
const unitContent = await unitSynthesizer.synthesizeUnit(unit);
|
|
114
|
+
generatedUnits.push(unitContent);
|
|
115
|
+
fs.mkdirSync(path.dirname(outFilePath), { recursive: true });
|
|
116
|
+
fs.writeFileSync(outFilePath, YAML.stringify(unitContent), 'utf-8');
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
log(` ✖ Failed to synthesize ${unit.id}: ${err.message}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Write Master Index or Domain Sub-Catalog
|
|
123
|
+
let catalogPath = '';
|
|
124
|
+
if (options.domain) {
|
|
125
|
+
const isCore = options.domain === 'core';
|
|
126
|
+
const catalogRelPath = isCore
|
|
127
|
+
? 'knowledge/core/index.yaml'
|
|
128
|
+
: `knowledge/domains/${options.domain}/index.yaml`;
|
|
129
|
+
const catalogFullPath = path.resolve(repoRoot, catalogRelPath);
|
|
130
|
+
fs.mkdirSync(path.dirname(catalogFullPath), { recursive: true });
|
|
131
|
+
const domainCatalogYaml = {
|
|
132
|
+
system_name: `${plan.system_name || options.domain}`,
|
|
133
|
+
description: plan.description || `Domain catalog for ${options.domain}`,
|
|
134
|
+
knowledge_units_count: generatedUnits.length,
|
|
135
|
+
last_updated: new Date().toISOString().split('T')[0],
|
|
136
|
+
knowledge_units: {}
|
|
137
|
+
};
|
|
138
|
+
for (const u of generatedUnits) {
|
|
139
|
+
if (!domainCatalogYaml.knowledge_units[u.domain]) {
|
|
140
|
+
domainCatalogYaml.knowledge_units[u.domain] = [];
|
|
141
|
+
}
|
|
142
|
+
domainCatalogYaml.knowledge_units[u.domain].push({
|
|
143
|
+
id: u.id,
|
|
144
|
+
file: options.domain === 'core'
|
|
145
|
+
? `knowledge/core/${u.id}.yaml`
|
|
146
|
+
: `knowledge/domains/${options.domain}/${u.id}.yaml`,
|
|
147
|
+
title: u.title
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
fs.writeFileSync(catalogFullPath, YAML.stringify(domainCatalogYaml), 'utf-8');
|
|
151
|
+
catalogPath = catalogFullPath;
|
|
152
|
+
// Register in root index router
|
|
153
|
+
const rootIndexPath = path.resolve(repoRoot, 'knowledge', 'index.yaml');
|
|
154
|
+
let rootIndexData = { system_name: 'EnterprisePlatform', domains: [] };
|
|
155
|
+
if (fs.existsSync(rootIndexPath)) {
|
|
156
|
+
try {
|
|
157
|
+
rootIndexData = YAML.parse(fs.readFileSync(rootIndexPath, 'utf-8')) || rootIndexData;
|
|
158
|
+
}
|
|
159
|
+
catch { }
|
|
160
|
+
}
|
|
161
|
+
if (!Array.isArray(rootIndexData.domains)) {
|
|
162
|
+
rootIndexData.domains = [];
|
|
163
|
+
}
|
|
164
|
+
const relScope = path.relative(codeRepoRoot, targetDir).replace(/\\/g, '/');
|
|
165
|
+
const appliesTo = !relScope || relScope === '.' || isCore ? ['**/*'] : [`${relScope}/**`];
|
|
166
|
+
const domainEntry = {
|
|
167
|
+
id: options.domain,
|
|
168
|
+
name: plan.system_name || options.domain,
|
|
169
|
+
catalog: catalogRelPath,
|
|
170
|
+
applies_to: appliesTo
|
|
171
|
+
};
|
|
172
|
+
const existingIdx = rootIndexData.domains.findIndex((d) => d.id === options.domain);
|
|
173
|
+
if (existingIdx >= 0) {
|
|
174
|
+
rootIndexData.domains[existingIdx] = domainEntry;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
rootIndexData.domains.push(domainEntry);
|
|
178
|
+
}
|
|
179
|
+
if (!rootIndexData.repository_root) {
|
|
180
|
+
rootIndexData.repository_root = codeRepoRoot.replace(/\\/g, '/');
|
|
181
|
+
}
|
|
182
|
+
rootIndexData.last_updated = new Date().toISOString().split('T')[0];
|
|
183
|
+
fs.writeFileSync(rootIndexPath, YAML.stringify(rootIndexData), 'utf-8');
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
const finalIndexPath = path.resolve(poolConfig.knowledgeDir, 'index.yaml');
|
|
187
|
+
fs.mkdirSync(path.dirname(finalIndexPath), { recursive: true });
|
|
188
|
+
const finalIndexYaml = {
|
|
189
|
+
system_name: plan.system_name,
|
|
190
|
+
repository_root: codeRepoRoot.replace(/\\/g, '/'),
|
|
191
|
+
knowledge_units_count: generatedUnits.length,
|
|
192
|
+
last_updated: new Date().toISOString().split('T')[0],
|
|
193
|
+
knowledge_units: {}
|
|
194
|
+
};
|
|
195
|
+
for (const u of generatedUnits) {
|
|
196
|
+
if (!finalIndexYaml.knowledge_units[u.domain]) {
|
|
197
|
+
finalIndexYaml.knowledge_units[u.domain] = [];
|
|
198
|
+
}
|
|
199
|
+
finalIndexYaml.knowledge_units[u.domain].push({
|
|
200
|
+
id: u.id,
|
|
201
|
+
file: `knowledge/${u.domain}/${u.id}.yaml`,
|
|
202
|
+
title: u.title
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
fs.writeFileSync(finalIndexPath, YAML.stringify(finalIndexYaml), 'utf-8');
|
|
206
|
+
catalogPath = finalIndexPath;
|
|
207
|
+
}
|
|
208
|
+
// Stage 4: Bootstrap Hooks & JSON Schemas
|
|
209
|
+
let writtenHooks = [];
|
|
210
|
+
if (!skipHooks) {
|
|
211
|
+
log('Stage 4/5: Bootstrapping multi-agent hooks & JSON schemas...');
|
|
212
|
+
const hookGen = new HookGenerator(repoRoot);
|
|
213
|
+
const proposedIndexForHooks = {
|
|
214
|
+
system_name: plan.system_name,
|
|
215
|
+
description: plan.description,
|
|
216
|
+
domains: domains
|
|
217
|
+
};
|
|
218
|
+
writtenHooks = hookGen.writeAllHooks(proposedIndexForHooks, generatedUnits, { forceHooks: options.forceHooks });
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
log(`Stage 4/5: Skipping hook generation (${poolConfig.isExternalPool ? 'external pool active' : '--no-hooks enabled'})...`);
|
|
222
|
+
}
|
|
223
|
+
// Stage 5: Schema Validation
|
|
224
|
+
log('Stage 5/5: Validating knowledge base structural integrity...');
|
|
225
|
+
const validator = new KnowledgeValidator(targetDir, poolConfig.poolDir);
|
|
226
|
+
const valResult = await validator.validate();
|
|
227
|
+
// Auto-clean temporary artifacts if requested (clean default: true)
|
|
228
|
+
if (options.clean !== false && !poolConfig.isExternalPool) {
|
|
229
|
+
cleanArtifacts(targetDir);
|
|
230
|
+
}
|
|
231
|
+
const elapsedSeconds = parseFloat(((Date.now() - startTime) / 1000).toFixed(2));
|
|
232
|
+
return {
|
|
233
|
+
success: valResult.valid,
|
|
234
|
+
systemName: plan.system_name,
|
|
235
|
+
unitsCount: generatedUnits.length,
|
|
236
|
+
catalogPath,
|
|
237
|
+
generatedHooks: writtenHooks,
|
|
238
|
+
validation: {
|
|
239
|
+
valid: valResult.valid,
|
|
240
|
+
errors: valResult.errors,
|
|
241
|
+
warnings: valResult.warnings
|
|
242
|
+
},
|
|
243
|
+
elapsedSeconds
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
export interface McpServerConfig {
|
|
3
|
+
poolDir?: string;
|
|
4
|
+
disableTools?: string[];
|
|
5
|
+
zeroTokenOnly?: boolean;
|
|
6
|
+
disallowRootScan?: boolean;
|
|
7
|
+
disallowedDirs?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function createMcpServer(repoRoot?: string, poolDirOrConfig?: string | McpServerConfig): McpServer;
|
|
10
|
+
export declare function runMcpServer(repoRoot?: string, poolDirOrConfig?: string | McpServerConfig, config?: McpServerConfig): Promise<void>;
|