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,61 @@
|
|
|
1
|
+
export interface DreamOptions {
|
|
2
|
+
targetDir: string;
|
|
3
|
+
poolDir?: string;
|
|
4
|
+
sinceHours?: number;
|
|
5
|
+
stageOnly?: boolean;
|
|
6
|
+
autoApprove?: boolean;
|
|
7
|
+
provider?: string;
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
model?: string;
|
|
10
|
+
cli?: boolean;
|
|
11
|
+
agy?: boolean;
|
|
12
|
+
transcriptFiles?: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface DreamResult {
|
|
15
|
+
observationsProcessed: number;
|
|
16
|
+
unitsCreated: string[];
|
|
17
|
+
unitsUpdated: string[];
|
|
18
|
+
proposalsStaged: string[];
|
|
19
|
+
errors: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface SynthesizedDreamPayload {
|
|
22
|
+
newUnits?: Array<{
|
|
23
|
+
id: string;
|
|
24
|
+
domain: string;
|
|
25
|
+
type?: string;
|
|
26
|
+
title: string;
|
|
27
|
+
rule?: string;
|
|
28
|
+
decision?: string;
|
|
29
|
+
do?: string[];
|
|
30
|
+
dont?: string[];
|
|
31
|
+
reason?: string;
|
|
32
|
+
applies_to?: string[];
|
|
33
|
+
}>;
|
|
34
|
+
unitUpdates?: Array<{
|
|
35
|
+
targetUnitId: string;
|
|
36
|
+
appendDo?: string[];
|
|
37
|
+
appendDont?: string[];
|
|
38
|
+
reason?: string;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
export declare class DreamEngine {
|
|
42
|
+
private targetDir;
|
|
43
|
+
private poolDir?;
|
|
44
|
+
constructor(targetDir?: string, poolDir?: string);
|
|
45
|
+
/**
|
|
46
|
+
* Consolidates recorded observations and error traces out-of-band into durable knowledge units or staged proposals.
|
|
47
|
+
*/
|
|
48
|
+
dream(options: DreamOptions): Promise<DreamResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Distills observations using an LLM provider.
|
|
51
|
+
*/
|
|
52
|
+
private distillWithLLM;
|
|
53
|
+
/**
|
|
54
|
+
* Deterministically distills observations without LLM tokens.
|
|
55
|
+
*/
|
|
56
|
+
private distillDeterministic;
|
|
57
|
+
/**
|
|
58
|
+
* Updates observation files in .akb/sessions/ marking processed observation IDs as consolidated.
|
|
59
|
+
*/
|
|
60
|
+
private markObservationsConsolidated;
|
|
61
|
+
}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { CatalogStore } from './catalog_store.js';
|
|
4
|
+
import { KnowledgePoolResolver } from './pool_resolver.js';
|
|
5
|
+
import { GraphBuilder } from './graph_builder.js';
|
|
6
|
+
import { createLLMProvider } from './provider.js';
|
|
7
|
+
export class DreamEngine {
|
|
8
|
+
targetDir;
|
|
9
|
+
poolDir;
|
|
10
|
+
constructor(targetDir = process.cwd(), poolDir) {
|
|
11
|
+
this.targetDir = path.resolve(targetDir);
|
|
12
|
+
this.poolDir = poolDir;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Consolidates recorded observations and error traces out-of-band into durable knowledge units or staged proposals.
|
|
16
|
+
*/
|
|
17
|
+
async dream(options) {
|
|
18
|
+
const targetDir = path.resolve(options.targetDir || this.targetDir);
|
|
19
|
+
const poolConfig = KnowledgePoolResolver.resolve(targetDir, { explicitPoolDir: options.poolDir || this.poolDir });
|
|
20
|
+
const poolDir = poolConfig.poolDir;
|
|
21
|
+
const result = {
|
|
22
|
+
observationsProcessed: 0,
|
|
23
|
+
unitsCreated: [],
|
|
24
|
+
unitsUpdated: [],
|
|
25
|
+
proposalsStaged: [],
|
|
26
|
+
errors: []
|
|
27
|
+
};
|
|
28
|
+
// 1. Gather recorded observations
|
|
29
|
+
const allObservations = CatalogStore.listObservations({ targetDir, poolDir });
|
|
30
|
+
const cutoffTime = options.sinceHours ? Date.now() - options.sinceHours * 60 * 60 * 1000 : 0;
|
|
31
|
+
const eligibleObservations = allObservations.filter(obs => {
|
|
32
|
+
const isRecorded = !obs.status || obs.status === 'recorded';
|
|
33
|
+
const obsTime = obs.timestamp ? new Date(obs.timestamp).getTime() : 0;
|
|
34
|
+
return isRecorded && (cutoffTime === 0 || obsTime >= cutoffTime);
|
|
35
|
+
});
|
|
36
|
+
// 2. Gather transcript errors if available
|
|
37
|
+
const transcriptErrors = [];
|
|
38
|
+
const candidateTranscriptFiles = [
|
|
39
|
+
...(options.transcriptFiles || []),
|
|
40
|
+
path.join(targetDir, '.system_generated', 'logs', 'transcript.jsonl')
|
|
41
|
+
];
|
|
42
|
+
for (const tf of candidateTranscriptFiles) {
|
|
43
|
+
if (fs.existsSync(tf)) {
|
|
44
|
+
try {
|
|
45
|
+
const content = fs.readFileSync(tf, 'utf-8');
|
|
46
|
+
const lines = content.split('\n').filter(l => l.trim().length > 0);
|
|
47
|
+
for (const line of lines) {
|
|
48
|
+
try {
|
|
49
|
+
const entry = JSON.parse(line);
|
|
50
|
+
if (entry.status === 'ERROR' || (entry.content && typeof entry.content === 'string' && entry.content.includes('Error:'))) {
|
|
51
|
+
const snippet = entry.content ? entry.content.slice(0, 300) : entry.status;
|
|
52
|
+
transcriptErrors.push(`[${entry.type || 'STEP'}] ${snippet}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch { }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
result.errors.push(`Failed reading transcript ${tf}: ${e.message}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (eligibleObservations.length === 0 && transcriptErrors.length === 0) {
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
result.observationsProcessed = eligibleObservations.length;
|
|
67
|
+
// 3. Attempt LLM-based distillation if provider is explicitly requested
|
|
68
|
+
let synthesized = null;
|
|
69
|
+
const hasExplicitProvider = Boolean(options.provider || options.cli || options.agy || options.apiKey);
|
|
70
|
+
if (hasExplicitProvider) {
|
|
71
|
+
try {
|
|
72
|
+
const provider = await createLLMProvider({
|
|
73
|
+
provider: options.provider,
|
|
74
|
+
apiKey: options.apiKey,
|
|
75
|
+
model: options.model,
|
|
76
|
+
forceCli: options.cli,
|
|
77
|
+
forceAgy: options.agy
|
|
78
|
+
});
|
|
79
|
+
synthesized = await this.distillWithLLM(provider, eligibleObservations, transcriptErrors);
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
result.errors.push(`LLM distillation failed, falling back to deterministic consolidation: ${err.message}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// 4. Fallback: Deterministic consolidation if LLM was unavailable or returned empty
|
|
86
|
+
if (!synthesized || (!synthesized.newUnits?.length && !synthesized.unitUpdates?.length)) {
|
|
87
|
+
synthesized = this.distillDeterministic(eligibleObservations, targetDir, poolDir);
|
|
88
|
+
}
|
|
89
|
+
// 5. Apply consolidation (either staged proposals or direct atomic upsert)
|
|
90
|
+
const stageOnly = options.stageOnly && !options.autoApprove;
|
|
91
|
+
if (stageOnly) {
|
|
92
|
+
// Stage new units
|
|
93
|
+
if (synthesized.newUnits) {
|
|
94
|
+
for (const u of synthesized.newUnits) {
|
|
95
|
+
const proposal = {
|
|
96
|
+
id: `staged-${u.id}-${Date.now().toString(36)}`,
|
|
97
|
+
targetUnitId: u.id,
|
|
98
|
+
domain: u.domain,
|
|
99
|
+
action: u.type === 'architecture_decision' ? 'record_decision' : 'create',
|
|
100
|
+
title: u.title,
|
|
101
|
+
proposed_rule: u.rule,
|
|
102
|
+
proposed_do: u.do,
|
|
103
|
+
proposed_dont: u.dont,
|
|
104
|
+
proposed_decision: u.decision,
|
|
105
|
+
reason: u.reason || 'Synthesized from runtime agent observations',
|
|
106
|
+
timestamp: new Date().toISOString(),
|
|
107
|
+
status: 'staged'
|
|
108
|
+
};
|
|
109
|
+
CatalogStore.stageProposal(proposal, { targetDir, poolDir });
|
|
110
|
+
result.proposalsStaged.push(proposal.id);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Stage unit updates
|
|
114
|
+
if (synthesized.unitUpdates) {
|
|
115
|
+
for (const up of synthesized.unitUpdates) {
|
|
116
|
+
const proposal = {
|
|
117
|
+
id: `staged-update-${up.targetUnitId}-${Date.now().toString(36)}`,
|
|
118
|
+
targetUnitId: up.targetUnitId,
|
|
119
|
+
domain: 'development',
|
|
120
|
+
action: 'append_rules',
|
|
121
|
+
proposed_do: up.appendDo,
|
|
122
|
+
proposed_dont: up.appendDont,
|
|
123
|
+
reason: up.reason || 'Appended directives from consolidated session observations',
|
|
124
|
+
timestamp: new Date().toISOString(),
|
|
125
|
+
status: 'staged'
|
|
126
|
+
};
|
|
127
|
+
CatalogStore.stageProposal(proposal, { targetDir, poolDir });
|
|
128
|
+
result.proposalsStaged.push(proposal.id);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
// Direct upsert new units
|
|
134
|
+
if (synthesized.newUnits && synthesized.newUnits.length > 0) {
|
|
135
|
+
const unitsToUpsert = synthesized.newUnits.map(u => ({
|
|
136
|
+
id: u.id,
|
|
137
|
+
domain: u.domain || 'decisions',
|
|
138
|
+
type: u.type || (u.decision ? 'architecture_decision' : 'development_standard'),
|
|
139
|
+
title: u.title,
|
|
140
|
+
rule: u.rule,
|
|
141
|
+
decision: u.decision,
|
|
142
|
+
do: u.do || ['Adhere to synthesized pattern.'],
|
|
143
|
+
dont: u.dont || ['Do not repeat recorded trial-and-error trap.'],
|
|
144
|
+
reason: u.reason || 'Consolidated out-of-band via akbo dream.',
|
|
145
|
+
applies_to: u.applies_to || [],
|
|
146
|
+
status: 'approved',
|
|
147
|
+
version: '1.0.0',
|
|
148
|
+
authority: { level: 'synthesized_dream', confidence: 'verified' }
|
|
149
|
+
}));
|
|
150
|
+
const upsertRes = await CatalogStore.upsertUnits(unitsToUpsert, { targetDir, poolDir, validate: false });
|
|
151
|
+
if (upsertRes.success) {
|
|
152
|
+
result.unitsCreated.push(...upsertRes.units);
|
|
153
|
+
}
|
|
154
|
+
else if (upsertRes.error) {
|
|
155
|
+
result.errors.push(`Failed to upsert new units: ${upsertRes.error}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Direct update existing units
|
|
159
|
+
if (synthesized.unitUpdates && synthesized.unitUpdates.length > 0) {
|
|
160
|
+
for (const up of synthesized.unitUpdates) {
|
|
161
|
+
const existing = CatalogStore.getUnit(up.targetUnitId, { targetDir, poolDir });
|
|
162
|
+
if (existing && existing.unit) {
|
|
163
|
+
const unit = existing.unit;
|
|
164
|
+
let modified = false;
|
|
165
|
+
if (up.appendDo && up.appendDo.length > 0) {
|
|
166
|
+
unit.do = Array.from(new Set([...(unit.do || []), ...up.appendDo]));
|
|
167
|
+
modified = true;
|
|
168
|
+
}
|
|
169
|
+
if (up.appendDont && up.appendDont.length > 0) {
|
|
170
|
+
unit.dont = Array.from(new Set([...(unit.dont || []), ...up.appendDont]));
|
|
171
|
+
modified = true;
|
|
172
|
+
}
|
|
173
|
+
if (modified) {
|
|
174
|
+
// Bump version patch
|
|
175
|
+
const vParts = (unit.version || '1.0.0').split('.');
|
|
176
|
+
if (vParts.length === 3) {
|
|
177
|
+
vParts[2] = String(parseInt(vParts[2], 10) + 1);
|
|
178
|
+
unit.version = vParts.join('.');
|
|
179
|
+
}
|
|
180
|
+
unit.authority = { level: 'synthesized_dream', confidence: 'verified' };
|
|
181
|
+
const updateRes = await CatalogStore.upsertUnits([unit], { targetDir, poolDir, validate: false });
|
|
182
|
+
if (updateRes.success) {
|
|
183
|
+
result.unitsUpdated.push(up.targetUnitId);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// 6. Mark processed observations as consolidated
|
|
191
|
+
this.markObservationsConsolidated(poolDir, eligibleObservations.map(o => o.id));
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Distills observations using an LLM provider.
|
|
196
|
+
*/
|
|
197
|
+
async distillWithLLM(provider, observations, transcriptErrors) {
|
|
198
|
+
const prompt = `You are an AI Memory Consolidation Engine ("Dreaming") for a software codebase.
|
|
199
|
+
Your goal is to review runtime session observations and execution errors from past agent tasks and synthesize them into durable, compounding architectural rules or decision records.
|
|
200
|
+
|
|
201
|
+
Observations:
|
|
202
|
+
${JSON.stringify(observations, null, 2)}
|
|
203
|
+
|
|
204
|
+
Execution Errors / Stack Traces:
|
|
205
|
+
${transcriptErrors.slice(0, 10).join('\n---\n')}
|
|
206
|
+
|
|
207
|
+
Instructions:
|
|
208
|
+
1. Discard transient one-off noise (e.g. typos, temporary connection dropouts).
|
|
209
|
+
2. For recurring traps or newly discovered patterns:
|
|
210
|
+
- Propose a new Knowledge Unit (type: 'development_standard' or 'architecture_decision') with clean ID (e.g. DEV-TRAP-001 or ADR-002), clear title, rule or decision, do list, dont list, and reason.
|
|
211
|
+
- OR propose an update to an existing standard if known.
|
|
212
|
+
3. Emit strictly valid JSON conforming to:
|
|
213
|
+
{
|
|
214
|
+
"newUnits": [
|
|
215
|
+
{
|
|
216
|
+
"id": "DEV-TRAP-001",
|
|
217
|
+
"domain": "development",
|
|
218
|
+
"type": "development_standard",
|
|
219
|
+
"title": "Clear descriptive title",
|
|
220
|
+
"rule": "Exact standard rule",
|
|
221
|
+
"do": ["Required action"],
|
|
222
|
+
"dont": ["Forbidden action"],
|
|
223
|
+
"reason": "Why this prevents errors",
|
|
224
|
+
"applies_to": ["src/**"]
|
|
225
|
+
}
|
|
226
|
+
],
|
|
227
|
+
"unitUpdates": [
|
|
228
|
+
{
|
|
229
|
+
"targetUnitId": "ARCH-SYS-001",
|
|
230
|
+
"appendDo": ["Additional positive instruction"],
|
|
231
|
+
"appendDont": ["Additional forbidden practice"],
|
|
232
|
+
"reason": "Reason for update"
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
}`;
|
|
236
|
+
return await provider.generateJson(prompt);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Deterministically distills observations without LLM tokens.
|
|
240
|
+
*/
|
|
241
|
+
distillDeterministic(observations, targetDir, poolDir) {
|
|
242
|
+
const newUnits = [];
|
|
243
|
+
const unitUpdates = [];
|
|
244
|
+
const graphBuilder = new GraphBuilder(targetDir, poolDir);
|
|
245
|
+
const existingInvariants = graphBuilder.loadKnowledgeUnits();
|
|
246
|
+
for (const obs of observations) {
|
|
247
|
+
if (!obs.finding)
|
|
248
|
+
continue;
|
|
249
|
+
// Check if observation matches an existing invariant by topic or file
|
|
250
|
+
let matchedUnit;
|
|
251
|
+
if (obs.associated_files && obs.associated_files.length > 0) {
|
|
252
|
+
for (const file of obs.associated_files) {
|
|
253
|
+
matchedUnit = existingInvariants.find(inv => graphBuilder.matchesAppliesTo(inv, file));
|
|
254
|
+
if (matchedUnit)
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (!matchedUnit && obs.topic) {
|
|
259
|
+
const topicNorm = obs.topic.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
260
|
+
matchedUnit = existingInvariants.find(inv => {
|
|
261
|
+
const invIdNorm = inv.id.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
262
|
+
const invTitleNorm = inv.title.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
263
|
+
return invIdNorm.includes(topicNorm) || invTitleNorm.includes(topicNorm);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
if (matchedUnit && obs.reproducible_fix) {
|
|
267
|
+
unitUpdates.push({
|
|
268
|
+
targetUnitId: matchedUnit.id,
|
|
269
|
+
appendDo: [obs.reproducible_fix],
|
|
270
|
+
appendDont: [`Do not repeat: ${obs.finding}`],
|
|
271
|
+
reason: `Consolidated observation: ${obs.finding}`
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
const topicSlug = (obs.topic || 'convention')
|
|
276
|
+
.toUpperCase()
|
|
277
|
+
.replace(/[^A-Z0-9]/g, '-')
|
|
278
|
+
.slice(0, 12);
|
|
279
|
+
const hash = Math.random().toString(36).substring(2, 6).toUpperCase();
|
|
280
|
+
const id = `ADR-${topicSlug}-${hash}`;
|
|
281
|
+
newUnits.push({
|
|
282
|
+
id,
|
|
283
|
+
domain: 'decisions',
|
|
284
|
+
type: 'architecture_decision',
|
|
285
|
+
title: `${obs.topic || 'Runtime'}: Fix for ${obs.finding.slice(0, 40)}`,
|
|
286
|
+
decision: obs.reproducible_fix || obs.finding,
|
|
287
|
+
reason: obs.finding,
|
|
288
|
+
applies_to: obs.associated_files || []
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return { newUnits, unitUpdates };
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Updates observation files in .akb/sessions/ marking processed observation IDs as consolidated.
|
|
296
|
+
*/
|
|
297
|
+
markObservationsConsolidated(poolDir, processedIds) {
|
|
298
|
+
if (processedIds.length === 0)
|
|
299
|
+
return;
|
|
300
|
+
const idSet = new Set(processedIds);
|
|
301
|
+
const sessionsBase = path.join(poolDir, '.akb', 'sessions');
|
|
302
|
+
if (!fs.existsSync(sessionsBase))
|
|
303
|
+
return;
|
|
304
|
+
const dirs = fs.readdirSync(sessionsBase).map(d => path.join(sessionsBase, d));
|
|
305
|
+
for (const d of dirs) {
|
|
306
|
+
const obsFile = path.join(d, 'observations.jsonl');
|
|
307
|
+
if (fs.existsSync(obsFile)) {
|
|
308
|
+
try {
|
|
309
|
+
const content = fs.readFileSync(obsFile, 'utf-8');
|
|
310
|
+
const lines = content.split('\n').filter(l => l.trim().length > 0);
|
|
311
|
+
const updatedLines = [];
|
|
312
|
+
for (const line of lines) {
|
|
313
|
+
try {
|
|
314
|
+
const obs = JSON.parse(line);
|
|
315
|
+
if (idSet.has(obs.id)) {
|
|
316
|
+
obs.status = 'consolidated';
|
|
317
|
+
}
|
|
318
|
+
updatedLines.push(JSON.stringify(obs));
|
|
319
|
+
}
|
|
320
|
+
catch {
|
|
321
|
+
updatedLines.push(line);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
fs.writeFileSync(obsFile, updatedLines.join('\n') + '\n', 'utf-8');
|
|
325
|
+
}
|
|
326
|
+
catch { }
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ManifestSummary, SchemaSummary, RouteOrSignature } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Universal interface for language and framework AST extractors.
|
|
4
|
+
*/
|
|
5
|
+
export interface CodebaseExtractor {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
/**
|
|
8
|
+
* Returns true if this extractor can handle manifests for the given file.
|
|
9
|
+
*/
|
|
10
|
+
canExtractManifest?(filePath: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Extracts manifest summaries from the given file and content.
|
|
13
|
+
*/
|
|
14
|
+
extractManifest?(filePath: string, content: string): ManifestSummary | ManifestSummary[] | null;
|
|
15
|
+
/**
|
|
16
|
+
* Returns true if this extractor can handle schemas for the given file.
|
|
17
|
+
*/
|
|
18
|
+
canExtractSchema?(filePath: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Extracts schema models, tables, or entities from the given file and content.
|
|
21
|
+
*/
|
|
22
|
+
extractSchemas?(filePath: string, content: string): SchemaSummary[];
|
|
23
|
+
/**
|
|
24
|
+
* Returns true if this extractor can handle routes/commands/handlers for the given file.
|
|
25
|
+
*/
|
|
26
|
+
canExtractRoutes?(filePath: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Extracts routes, commands, handlers, and RPCs from the given file and content.
|
|
29
|
+
*/
|
|
30
|
+
extractRoutesAndCommands?(filePath: string, content: string): RouteOrSignature[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Cleans and normalizes HTTP client target paths across all extractors.
|
|
34
|
+
*/
|
|
35
|
+
export declare function cleanClientUrl(rawUrl: string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cleans and normalizes HTTP client target paths across all extractors.
|
|
3
|
+
*/
|
|
4
|
+
export function cleanClientUrl(rawUrl) {
|
|
5
|
+
if (!rawUrl)
|
|
6
|
+
return '';
|
|
7
|
+
let p = rawUrl.trim();
|
|
8
|
+
p = p.replace(/^['"`]|['"`]$/g, '');
|
|
9
|
+
p = p.replace(/^https?:\/\/[^\/]+/, '');
|
|
10
|
+
p = p.split('?')[0];
|
|
11
|
+
p = p.replace(/\$\{[^}]+\}/g, '{param}');
|
|
12
|
+
if (!p.startsWith('/') && !p.startsWith('http'))
|
|
13
|
+
p = `/${p}`;
|
|
14
|
+
if (p.length > 1 && p.endsWith('/'))
|
|
15
|
+
p = p.slice(0, -1);
|
|
16
|
+
return p;
|
|
17
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { CodebaseExtractor } from './base.js';
|
|
2
|
+
import type { SchemaSummary, RouteOrSignature, SchemaType } from '../types.js';
|
|
3
|
+
export interface CustomRuleEndpoint {
|
|
4
|
+
pattern: string;
|
|
5
|
+
filePattern?: string;
|
|
6
|
+
identifierGroup?: number;
|
|
7
|
+
signatureGroup?: number;
|
|
8
|
+
signatureTemplate?: string;
|
|
9
|
+
framework?: string;
|
|
10
|
+
method?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CustomRuleHandler {
|
|
13
|
+
pattern: string;
|
|
14
|
+
filePattern?: string;
|
|
15
|
+
identifierGroup?: number;
|
|
16
|
+
signatureTemplate?: string;
|
|
17
|
+
framework?: string;
|
|
18
|
+
implementsGroup?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface CustomRuleSchema {
|
|
21
|
+
pattern: string;
|
|
22
|
+
filePattern?: string;
|
|
23
|
+
modelGroup?: number;
|
|
24
|
+
type?: SchemaType;
|
|
25
|
+
}
|
|
26
|
+
export interface CustomRuleCall {
|
|
27
|
+
pattern: string;
|
|
28
|
+
filePattern?: string;
|
|
29
|
+
targetGroup?: number;
|
|
30
|
+
type?: 'CALLS_RPC' | 'CALLS_HTTP' | 'CALLS_GRPC';
|
|
31
|
+
framework?: string;
|
|
32
|
+
method?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface CustomExtractorConfig {
|
|
35
|
+
name?: string;
|
|
36
|
+
filePattern?: string;
|
|
37
|
+
endpoints?: CustomRuleEndpoint[];
|
|
38
|
+
handlers?: CustomRuleHandler[];
|
|
39
|
+
schemas?: CustomRuleSchema[];
|
|
40
|
+
calls?: CustomRuleCall[];
|
|
41
|
+
}
|
|
42
|
+
export declare class CustomRegexExtractor implements CodebaseExtractor {
|
|
43
|
+
readonly name: string;
|
|
44
|
+
private configs;
|
|
45
|
+
constructor(configs: CustomExtractorConfig[] | CustomExtractorConfig, name?: string);
|
|
46
|
+
/**
|
|
47
|
+
* Helper to load custom extractor configuration from a YAML or JSON file.
|
|
48
|
+
*/
|
|
49
|
+
static fromFile(configPath: string): CustomRegexExtractor | null;
|
|
50
|
+
private matchesFile;
|
|
51
|
+
canExtractSchema(filePath: string): boolean;
|
|
52
|
+
extractSchemas(filePath: string, content: string): SchemaSummary[];
|
|
53
|
+
canExtractRoutes(filePath: string): boolean;
|
|
54
|
+
extractRoutesAndCommands(filePath: string, content: string): RouteOrSignature[];
|
|
55
|
+
}
|