neuroplex 0.0.1 → 0.1.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/LICENSE +21 -21
- package/README.md +11 -11
- package/dist/brain/build.d.ts +21 -0
- package/dist/brain/build.js +172 -0
- package/dist/brain/build.js.map +1 -0
- package/dist/brain/local.d.ts +12 -0
- package/dist/brain/local.js +23 -0
- package/dist/brain/local.js.map +1 -0
- package/dist/brain/stats.d.ts +23 -0
- package/dist/brain/stats.js +37 -0
- package/dist/brain/stats.js.map +1 -0
- package/dist/brain/status.d.ts +21 -0
- package/dist/brain/status.js +28 -0
- package/dist/brain/status.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +208 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/config/config.d.ts +62 -0
- package/dist/config/config.js +141 -0
- package/dist/config/config.js.map +1 -0
- package/dist/enrich/index.d.ts +8 -0
- package/dist/enrich/index.js +13 -0
- package/dist/enrich/index.js.map +1 -0
- package/dist/enrich/tasks.d.ts +52 -0
- package/dist/enrich/tasks.js +339 -0
- package/dist/enrich/tasks.js.map +1 -0
- package/dist/enrich/write.d.ts +45 -0
- package/dist/enrich/write.js +228 -0
- package/dist/enrich/write.js.map +1 -0
- package/dist/graph/graph.d.ts +42 -0
- package/dist/graph/graph.js +174 -0
- package/dist/graph/graph.js.map +1 -0
- package/dist/graph/ids.d.ts +42 -0
- package/dist/graph/ids.js +104 -0
- package/dist/graph/ids.js.map +1 -0
- package/dist/graph/jsonl.d.ts +31 -0
- package/dist/graph/jsonl.js +121 -0
- package/dist/graph/jsonl.js.map +1 -0
- package/dist/graph/schema.d.ts +89 -0
- package/dist/graph/schema.js +73 -0
- package/dist/graph/schema.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/install/claude.d.ts +37 -0
- package/dist/install/claude.js +104 -0
- package/dist/install/claude.js.map +1 -0
- package/dist/mcp/config.d.ts +20 -0
- package/dist/mcp/config.js +51 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/serve.d.ts +5 -0
- package/dist/mcp/serve.js +12 -0
- package/dist/mcp/serve.js.map +1 -0
- package/dist/mcp/server.d.ts +9 -0
- package/dist/mcp/server.js +248 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/query/brain.d.ts +21 -0
- package/dist/query/brain.js +51 -0
- package/dist/query/brain.js.map +1 -0
- package/dist/query/queries.d.ts +116 -0
- package/dist/query/queries.js +224 -0
- package/dist/query/queries.js.map +1 -0
- package/dist/query/search.d.ts +43 -0
- package/dist/query/search.js +329 -0
- package/dist/query/search.js.map +1 -0
- package/dist/scan/assemble.d.ts +20 -0
- package/dist/scan/assemble.js +255 -0
- package/dist/scan/assemble.js.map +1 -0
- package/dist/scan/discover.d.ts +21 -0
- package/dist/scan/discover.js +119 -0
- package/dist/scan/discover.js.map +1 -0
- package/dist/scan/extract.d.ts +3 -0
- package/dist/scan/extract.js +11 -0
- package/dist/scan/extract.js.map +1 -0
- package/dist/scan/extractors/python.d.ts +4 -0
- package/dist/scan/extractors/python.js +303 -0
- package/dist/scan/extractors/python.js.map +1 -0
- package/dist/scan/extractors/typescript.d.ts +6 -0
- package/dist/scan/extractors/typescript.js +509 -0
- package/dist/scan/extractors/typescript.js.map +1 -0
- package/dist/scan/git.d.ts +15 -0
- package/dist/scan/git.js +42 -0
- package/dist/scan/git.js.map +1 -0
- package/dist/scan/merge.d.ts +14 -0
- package/dist/scan/merge.js +57 -0
- package/dist/scan/merge.js.map +1 -0
- package/dist/scan/parser.d.ts +23 -0
- package/dist/scan/parser.js +57 -0
- package/dist/scan/parser.js.map +1 -0
- package/dist/scan/resolve.d.ts +23 -0
- package/dist/scan/resolve.js +131 -0
- package/dist/scan/resolve.js.map +1 -0
- package/dist/scan/scan.d.ts +36 -0
- package/dist/scan/scan.js +74 -0
- package/dist/scan/scan.js.map +1 -0
- package/dist/scan/types.d.ts +86 -0
- package/dist/scan/types.js +20 -0
- package/dist/scan/types.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +40 -6
- package/skills/neuroplex/SKILL.md +94 -0
- package/skills/neuroplex-update/SKILL.md +37 -0
- package/bin/neuroplex.js +0 -8
- package/index.js +0 -7
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { PROJECT_ID } from '../graph/ids.js';
|
|
2
|
+
/**
|
|
3
|
+
* Enrichment tasks (docs/ARCHITECTURE.md §4.3).
|
|
4
|
+
*
|
|
5
|
+
* Tasks are derived from the graph on every call: anything without an AI
|
|
6
|
+
* summary, or whose summary is `stale`, needs work. There is no task state to
|
|
7
|
+
* keep in sync, so enrichment can stop and resume at any time.
|
|
8
|
+
*
|
|
9
|
+
* Phases run in order, and `listTasks` only returns tasks from the earliest
|
|
10
|
+
* phase that still has work:
|
|
11
|
+
* 1. modules - summarize modules, their files and important symbols
|
|
12
|
+
* 2. project - summarize the whole project from the module summaries
|
|
13
|
+
* 3. concepts - identify business/domain concepts and their members
|
|
14
|
+
* 4. flows - describe end-to-end flows as ordered steps
|
|
15
|
+
*/
|
|
16
|
+
export const PHASES = ['modules', 'project', 'concepts', 'flows'];
|
|
17
|
+
/** Files and symbols per module task, so each task fits comfortably in an AI context window. */
|
|
18
|
+
export const MAX_FILES_PER_TASK = 12;
|
|
19
|
+
export const MAX_SYMBOLS_PER_TASK = 60;
|
|
20
|
+
const needsSummary = (n) => !!n && (!n.summary || n.stale);
|
|
21
|
+
export const RESULT_FORMAT = `JSON object, every key optional:
|
|
22
|
+
{
|
|
23
|
+
"summaries": { "<node id>": "what it does and why it exists: symbols/files 1-2 sentences, modules 2-4, project 3-6" },
|
|
24
|
+
"notes": { "<node id>": "optional longer markdown for modules or key files" },
|
|
25
|
+
"tags": { "<node id>": ["short", "lowercase", "tags"] },
|
|
26
|
+
"concepts": [{ "name": "Authentication", "summary": "...", "members": ["<node id, path or unique name>", ...] }],
|
|
27
|
+
"flows": [{ "name": "Sign in", "summary": "...", "steps": ["<symbol id or unique name>", ...] }]
|
|
28
|
+
}
|
|
29
|
+
Use node IDs exactly as given in the task. Submit with \`neuroplex write <task-id> --file result.json\` (or stdin), or the \`submit_task\` MCP tool.`;
|
|
30
|
+
export function listTasks(graph, options = {}) {
|
|
31
|
+
const all = {
|
|
32
|
+
modules: moduleTasks(graph),
|
|
33
|
+
project: projectTasks(graph),
|
|
34
|
+
concepts: conceptTasks(graph, options.phase === 'concepts'),
|
|
35
|
+
flows: flowTasks(graph, options.phase === 'flows'),
|
|
36
|
+
};
|
|
37
|
+
const pending = Object.fromEntries(PHASES.map((p) => [p, all[p].length]));
|
|
38
|
+
const phase = options.phase ?? PHASES.find((p) => all[p].length > 0) ?? null;
|
|
39
|
+
const tasks = phase ? all[phase].slice(0, options.limit ?? 5) : [];
|
|
40
|
+
const list = { phase, tasks, pending, resultFormat: RESULT_FORMAT };
|
|
41
|
+
if (options.sourcePath)
|
|
42
|
+
list.sourcePath = options.sourcePath;
|
|
43
|
+
return list;
|
|
44
|
+
}
|
|
45
|
+
/** Finds a task by ID across all phases (used by `write` to validate and scope results). */
|
|
46
|
+
export function findTask(graph, id) {
|
|
47
|
+
for (const phase of PHASES) {
|
|
48
|
+
const found = listTasks(graph, { phase, limit: Number.MAX_SAFE_INTEGER }).tasks.find((t) => t.id === id);
|
|
49
|
+
if (found)
|
|
50
|
+
return found;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
// ── Phase 1: modules ──────────────────────────────────────────────────
|
|
55
|
+
function moduleTasks(graph) {
|
|
56
|
+
const containers = [graph.getNode(PROJECT_ID), ...[...graph.nodes()].filter((n) => n.type === 'module')].filter((n) => !!n);
|
|
57
|
+
const withFiles = [];
|
|
58
|
+
const parentsOnly = [];
|
|
59
|
+
for (const node of containers) {
|
|
60
|
+
const files = children(graph, node, 'file');
|
|
61
|
+
if (files.length) {
|
|
62
|
+
const centrality = graph.incoming(node.id, ['depends_on']).length * 10 + importers(graph, files);
|
|
63
|
+
withFiles.push({ node, files, centrality });
|
|
64
|
+
}
|
|
65
|
+
else if (node.type === 'module') {
|
|
66
|
+
parentsOnly.push(node);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Most depended-on modules first: their summaries help everything else.
|
|
70
|
+
withFiles.sort((a, b) => b.centrality - a.centrality || compare(a.node.id, b.node.id));
|
|
71
|
+
const tasks = [];
|
|
72
|
+
for (const { node, files } of withFiles)
|
|
73
|
+
tasks.push(...moduleFileTasks(graph, node, files));
|
|
74
|
+
// Modules that only contain other modules come after their children, and only
|
|
75
|
+
// once no task below them is pending, so their submodule summaries exist.
|
|
76
|
+
const pendingPaths = tasks.map((t) => t.targets.map((id) => graph.getNode(id)?.path ?? '')).flat();
|
|
77
|
+
const hasPendingBelow = (mod) => pendingPaths.some((p) => p.startsWith(`${mod.path}/`)) ||
|
|
78
|
+
parentsOnly.some((o) => o !== mod && o.path?.startsWith(`${mod.path}/`) && needsSummary(o));
|
|
79
|
+
parentsOnly.sort((a, b) => depth(b) - depth(a) || compare(a.id, b.id));
|
|
80
|
+
for (const node of parentsOnly) {
|
|
81
|
+
if (!needsSummary(node) || hasPendingBelow(node))
|
|
82
|
+
continue;
|
|
83
|
+
const subs = children(graph, node, 'module');
|
|
84
|
+
tasks.push({
|
|
85
|
+
id: node.id,
|
|
86
|
+
phase: 'modules',
|
|
87
|
+
title: `Summarize module ${node.path}`,
|
|
88
|
+
instructions: `Summarize the module \`${node.path}\` from its submodules (their summaries are below; read the code if they are missing). ` +
|
|
89
|
+
'Say what this part of the codebase is responsible for and how the submodules fit together.',
|
|
90
|
+
targets: [node.id],
|
|
91
|
+
context: { module: brief(node), submodules: subs.map(brief) },
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return tasks;
|
|
95
|
+
}
|
|
96
|
+
function moduleFileTasks(graph, mod, files) {
|
|
97
|
+
const isRoot = mod.type === 'project';
|
|
98
|
+
const label = isRoot ? 'project root' : `module ${mod.path}`;
|
|
99
|
+
const subs = isRoot ? [] : children(graph, mod, 'module');
|
|
100
|
+
const batches = [];
|
|
101
|
+
let batch = [];
|
|
102
|
+
let symbols = 0;
|
|
103
|
+
for (const file of [...files].sort((a, b) => compare(a.id, b.id))) {
|
|
104
|
+
const count = keySymbols(graph, file).length;
|
|
105
|
+
if (batch.length && (batch.length >= MAX_FILES_PER_TASK || symbols + count > MAX_SYMBOLS_PER_TASK)) {
|
|
106
|
+
batches.push(batch);
|
|
107
|
+
batch = [];
|
|
108
|
+
symbols = 0;
|
|
109
|
+
}
|
|
110
|
+
batch.push(file);
|
|
111
|
+
symbols += count;
|
|
112
|
+
}
|
|
113
|
+
if (batch.length)
|
|
114
|
+
batches.push(batch);
|
|
115
|
+
const tasks = [];
|
|
116
|
+
batches.forEach((group, i) => {
|
|
117
|
+
const fileTargets = group.filter(needsSummary).map((f) => f.id);
|
|
118
|
+
const symbolNodes = group.flatMap((f) => keySymbols(graph, f));
|
|
119
|
+
const symbolTargets = symbolNodes.filter(needsSummary).map((s) => s.id);
|
|
120
|
+
// The module itself is summarized in its last batch, once its files are understood.
|
|
121
|
+
const moduleTarget = !isRoot && i === batches.length - 1 && needsSummary(mod) ? [mod.id] : [];
|
|
122
|
+
const targets = [...moduleTarget, ...fileTargets, ...symbolTargets];
|
|
123
|
+
if (!targets.length)
|
|
124
|
+
return;
|
|
125
|
+
const base = isRoot ? 'files:.' : mod.id;
|
|
126
|
+
tasks.push({
|
|
127
|
+
id: batches.length > 1 ? `${base}@${i + 1}` : base,
|
|
128
|
+
phase: 'modules',
|
|
129
|
+
title: `Summarize ${label}` + (batches.length > 1 ? ` (part ${i + 1}/${batches.length})` : ''),
|
|
130
|
+
instructions: `Read the files listed below (paths are relative to the source project) and write a summary for every node in \`targets\`. ` +
|
|
131
|
+
'Files: what the file is for and its main responsibilities. Symbols: what it does, important inputs/outputs or side effects, and anything surprising. ' +
|
|
132
|
+
(moduleTarget.length
|
|
133
|
+
? `Module: the role of \`${mod.path}\` in the project and how its files${subs.length ? ' and submodules' : ''} work together; add a short markdown note for it under "notes". `
|
|
134
|
+
: '') +
|
|
135
|
+
(batches.length > 1 ? 'This module is split into parts; the module itself is summarized in the last part. ' : '') +
|
|
136
|
+
'Nodes marked stale already have an old summary: check it against the current code and rewrite it.',
|
|
137
|
+
targets,
|
|
138
|
+
context: {
|
|
139
|
+
...(isRoot ? {} : { module: brief(mod), dependsOn: related(graph, mod, 'out'), usedBy: related(graph, mod, 'in') }),
|
|
140
|
+
...(moduleTarget.length && subs.length ? { submodules: subs.map(brief) } : {}),
|
|
141
|
+
files: group.map((f) => ({
|
|
142
|
+
...brief(f),
|
|
143
|
+
symbols: keySymbols(graph, f).map((s) => ({
|
|
144
|
+
id: s.id,
|
|
145
|
+
...(s.kind && { kind: s.kind }),
|
|
146
|
+
...(s.range && { lines: `${s.range.start}-${s.range.end}` }),
|
|
147
|
+
...(s.summary && { summary: s.summary }),
|
|
148
|
+
...(s.stale && { stale: true }),
|
|
149
|
+
})),
|
|
150
|
+
otherSymbols: otherSymbols(graph, f),
|
|
151
|
+
})),
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
return tasks;
|
|
156
|
+
}
|
|
157
|
+
/** Symbols this short are self-explanatory (a constant, a type alias, a getter). */
|
|
158
|
+
const TRIVIAL_LINES = 3;
|
|
159
|
+
/** Functions this long deserve a summary even when private. */
|
|
160
|
+
const SUBSTANTIAL_LINES = 15;
|
|
161
|
+
/**
|
|
162
|
+
* Symbols worth a summary: classes, interfaces, routes and components; and
|
|
163
|
+
* functions/methods/types that are exported, called from several places,
|
|
164
|
+
* orchestrate other calls, or are long. Tiny symbols are left to the file summary.
|
|
165
|
+
*/
|
|
166
|
+
function keySymbols(graph, file) {
|
|
167
|
+
return symbolsIn(graph, file).filter((s) => {
|
|
168
|
+
if (['class', 'interface', 'route', 'component'].includes(s.kind ?? ''))
|
|
169
|
+
return true;
|
|
170
|
+
const lines = s.range ? s.range.end - s.range.start + 1 : 0;
|
|
171
|
+
if (lines <= TRIVIAL_LINES)
|
|
172
|
+
return false;
|
|
173
|
+
return (s.tags?.includes('exported') ||
|
|
174
|
+
graph.incoming(s.id, ['calls']).length >= 2 ||
|
|
175
|
+
graph.outgoing(s.id, ['calls']).length >= 3 ||
|
|
176
|
+
lines >= SUBSTANTIAL_LINES);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function otherSymbols(graph, file) {
|
|
180
|
+
const key = new Set(keySymbols(graph, file).map((s) => s.id));
|
|
181
|
+
return symbolsIn(graph, file)
|
|
182
|
+
.filter((s) => !key.has(s.id))
|
|
183
|
+
.map((s) => s.name);
|
|
184
|
+
}
|
|
185
|
+
function symbolsIn(graph, file) {
|
|
186
|
+
const out = [];
|
|
187
|
+
const visit = (id) => {
|
|
188
|
+
for (const e of graph.outgoing(id, ['contains'])) {
|
|
189
|
+
const n = graph.getNode(e.to);
|
|
190
|
+
if (n?.type !== 'symbol')
|
|
191
|
+
continue;
|
|
192
|
+
out.push(n);
|
|
193
|
+
visit(n.id);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
visit(file.id);
|
|
197
|
+
return out.sort((a, b) => (a.range?.start ?? 0) - (b.range?.start ?? 0));
|
|
198
|
+
}
|
|
199
|
+
// ── Phase 2: project ──────────────────────────────────────────────────
|
|
200
|
+
function projectTasks(graph) {
|
|
201
|
+
const project = graph.getNode(PROJECT_ID);
|
|
202
|
+
if (!project || !needsSummary(project))
|
|
203
|
+
return [];
|
|
204
|
+
const modules = [...graph.nodes()].filter((n) => n.type === 'module');
|
|
205
|
+
const top = modules.filter((m) => graph.incoming(m.id, ['contains'])[0]?.from === PROJECT_ID);
|
|
206
|
+
const packages = [...graph.nodes()]
|
|
207
|
+
.filter((n) => n.type === 'package')
|
|
208
|
+
.map((p) => ({ name: p.name, importers: graph.incoming(p.id, ['imports']).length }))
|
|
209
|
+
.sort((a, b) => b.importers - a.importers)
|
|
210
|
+
.slice(0, 15);
|
|
211
|
+
return [
|
|
212
|
+
{
|
|
213
|
+
id: 'project',
|
|
214
|
+
phase: 'project',
|
|
215
|
+
title: 'Summarize the project',
|
|
216
|
+
instructions: 'Write a summary of the whole project (3-6 sentences): what it is, who uses it, its main parts and how they fit together. ' +
|
|
217
|
+
'Base it on the module summaries below; read the README or entry points if needed. Also add a markdown note for "project" with a short architecture overview.',
|
|
218
|
+
targets: [PROJECT_ID],
|
|
219
|
+
context: { topModules: top.map(brief), allModules: modules.map(brief), externalPackages: packages },
|
|
220
|
+
},
|
|
221
|
+
];
|
|
222
|
+
}
|
|
223
|
+
// ── Phase 3: concepts ─────────────────────────────────────────────────
|
|
224
|
+
function conceptTasks(graph, force) {
|
|
225
|
+
const existing = [...graph.nodes()].filter((n) => n.type === 'concept');
|
|
226
|
+
if (existing.length && !force)
|
|
227
|
+
return [];
|
|
228
|
+
return [
|
|
229
|
+
{
|
|
230
|
+
id: 'concepts',
|
|
231
|
+
phase: 'concepts',
|
|
232
|
+
title: 'Identify domain concepts',
|
|
233
|
+
instructions: 'Identify the 5-15 most important business or domain concepts in this project (e.g. "Authentication", "Billing", "Knowledge graph"), not technical layers. ' +
|
|
234
|
+
'For each, write a 1-3 sentence summary and list its members (most important first, at most 15): module or file IDs from the context below, or symbols by ID, path or unique name. ' +
|
|
235
|
+
'Submitting "concepts" for this task replaces all existing concepts.',
|
|
236
|
+
targets: [],
|
|
237
|
+
context: {
|
|
238
|
+
project: brief(graph.getNode(PROJECT_ID)),
|
|
239
|
+
modules: [...graph.nodes()].filter((n) => n.type === 'module' || (n.type === 'file' && n.summary)).map(brief),
|
|
240
|
+
keySymbols: [...graph.nodes()]
|
|
241
|
+
.filter((n) => n.type === 'symbol' && n.summary && (n.tags?.includes('exported') || n.kind === 'class'))
|
|
242
|
+
.slice(0, 150)
|
|
243
|
+
.map((n) => ({ id: n.id, summary: n.summary })),
|
|
244
|
+
existingConcepts: existing.map(brief),
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
];
|
|
248
|
+
}
|
|
249
|
+
// ── Phase 4: flows ────────────────────────────────────────────────────
|
|
250
|
+
/**
|
|
251
|
+
* Likely entry points: routes, and exported top-level functions that nothing in
|
|
252
|
+
* the project calls but that call several things. Methods are left out: calls on
|
|
253
|
+
* local variables (`obj.method()`) are not resolved, so methods often look uncalled.
|
|
254
|
+
*/
|
|
255
|
+
function entryPoints(graph) {
|
|
256
|
+
const isTest = (path) => !!path && /(^|\/)(tests?|__tests__|spec)\/|\.(test|spec)\.|(^|\/)test_/.test(path);
|
|
257
|
+
return [...graph.nodes()]
|
|
258
|
+
.filter((n) => n.type === 'symbol' && !isTest(n.path))
|
|
259
|
+
.filter((n) => n.kind === 'route' ||
|
|
260
|
+
(n.kind === 'function' &&
|
|
261
|
+
n.tags?.includes('exported') &&
|
|
262
|
+
graph.incoming(n.id, ['calls']).length === 0 &&
|
|
263
|
+
graph.outgoing(n.id, ['calls']).length >= 2))
|
|
264
|
+
.sort((a, b) => graph.outgoing(b.id, ['calls']).length - graph.outgoing(a.id, ['calls']).length || compare(a.id, b.id))
|
|
265
|
+
.slice(0, 25);
|
|
266
|
+
}
|
|
267
|
+
function callTree(graph, node, depth, seen = new Set()) {
|
|
268
|
+
seen.add(node.id);
|
|
269
|
+
const calls = depth > 0
|
|
270
|
+
? graph
|
|
271
|
+
.outgoing(node.id, ['calls'])
|
|
272
|
+
// Order of first call in the source, which is close to execution order.
|
|
273
|
+
.sort((a, b) => Number(a.props?.line ?? Infinity) - Number(b.props?.line ?? Infinity))
|
|
274
|
+
.map((e) => graph.getNode(e.to))
|
|
275
|
+
.filter((c) => !seen.has(c.id))
|
|
276
|
+
.slice(0, 8)
|
|
277
|
+
.map((c) => callTree(graph, c, depth - 1, seen))
|
|
278
|
+
: [];
|
|
279
|
+
return calls.length ? { id: node.id, calls } : { id: node.id };
|
|
280
|
+
}
|
|
281
|
+
function flowTasks(graph, force) {
|
|
282
|
+
const existing = [...graph.nodes()].filter((n) => n.type === 'flow');
|
|
283
|
+
if (existing.length && !force)
|
|
284
|
+
return [];
|
|
285
|
+
return [
|
|
286
|
+
{
|
|
287
|
+
id: 'flows',
|
|
288
|
+
phase: 'flows',
|
|
289
|
+
title: 'Describe end-to-end flows',
|
|
290
|
+
instructions: 'Describe the 3-10 most important end-to-end flows (e.g. "Sign in", "Checkout", "Scan a project"): what triggers them and what happens. ' +
|
|
291
|
+
'For each, write a 1-3 sentence summary and list its steps as symbol IDs in execution order (3-12 steps). ' +
|
|
292
|
+
'The entry points below (CLI commands `command:*`, HTTP routes, MCP tools `tool:*`, and exported functions nothing calls) are a heuristic starting point. ' +
|
|
293
|
+
'Their call trees list callees in source order, which is close to but not always execution order, and they miss calls made on local variables (`obj.method()`). ' +
|
|
294
|
+
'Read the code to confirm the steps and their order. Submitting "flows" for this task replaces all existing flows.',
|
|
295
|
+
targets: [],
|
|
296
|
+
context: {
|
|
297
|
+
project: brief(graph.getNode(PROJECT_ID)),
|
|
298
|
+
entryPoints: entryPoints(graph).map((n) => ({ ...brief(n), callTree: callTree(graph, n, 3) })),
|
|
299
|
+
existingFlows: existing.map(brief),
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
];
|
|
303
|
+
}
|
|
304
|
+
// ── helpers ───────────────────────────────────────────────────────────
|
|
305
|
+
/** Compact node description for task context. */
|
|
306
|
+
function brief(node) {
|
|
307
|
+
if (!node)
|
|
308
|
+
return {};
|
|
309
|
+
const b = { id: node.id, name: node.name };
|
|
310
|
+
if (node.kind)
|
|
311
|
+
b.kind = node.kind;
|
|
312
|
+
if (node.path && node.type !== 'symbol')
|
|
313
|
+
b.path = node.path;
|
|
314
|
+
if (node.range)
|
|
315
|
+
b.lines = `${node.range.start}-${node.range.end}`;
|
|
316
|
+
if (node.tags?.includes('exported'))
|
|
317
|
+
b.exported = true;
|
|
318
|
+
if (node.summary)
|
|
319
|
+
b.summary = node.summary;
|
|
320
|
+
if (node.stale)
|
|
321
|
+
b.stale = true;
|
|
322
|
+
return b;
|
|
323
|
+
}
|
|
324
|
+
function children(graph, node, type) {
|
|
325
|
+
return graph
|
|
326
|
+
.outgoing(node.id, ['contains'])
|
|
327
|
+
.map((e) => graph.getNode(e.to))
|
|
328
|
+
.filter((n) => n.type === type);
|
|
329
|
+
}
|
|
330
|
+
function related(graph, mod, dir) {
|
|
331
|
+
const edges = dir === 'out' ? graph.outgoing(mod.id, ['depends_on']) : graph.incoming(mod.id, ['depends_on']);
|
|
332
|
+
return edges.map((e) => (dir === 'out' ? e.to : e.from)).sort();
|
|
333
|
+
}
|
|
334
|
+
function importers(graph, files) {
|
|
335
|
+
return files.reduce((n, f) => n + graph.incoming(f.id, ['imports']).length, 0);
|
|
336
|
+
}
|
|
337
|
+
const depth = (n) => (n.path ? n.path.split('/').length : 0);
|
|
338
|
+
const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
339
|
+
//# sourceMappingURL=tasks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/enrich/tasks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C;;;;;;;;;;;;;GAaG;AAEH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAU,CAAC;AAkC3E,gGAAgG;AAChG,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AACrC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEvC,MAAM,YAAY,GAAG,CAAC,CAAwB,EAAW,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;AAE3F,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;qJAQwH,CAAC;AAEt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CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,MAAM,KAAK,GAAG,CAAC,CAAY,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChF,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { GraphNode } from '../graph/schema.js';
|
|
3
|
+
/** What the AI submits for a task (see `RESULT_FORMAT` in tasks.ts). */
|
|
4
|
+
export declare const EnrichmentResultSchema: z.ZodObject<{
|
|
5
|
+
summaries: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
6
|
+
notes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
7
|
+
tags: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
8
|
+
concepts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
summary: z.ZodString;
|
|
11
|
+
members: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
12
|
+
}, z.core.$strip>>>;
|
|
13
|
+
flows: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
14
|
+
name: z.ZodString;
|
|
15
|
+
summary: z.ZodString;
|
|
16
|
+
steps: z.ZodArray<z.ZodString>;
|
|
17
|
+
}, z.core.$strip>>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export type EnrichmentResult = z.output<typeof EnrichmentResultSchema>;
|
|
20
|
+
export type EnrichmentResultInput = z.input<typeof EnrichmentResultSchema>;
|
|
21
|
+
export interface WriteReport {
|
|
22
|
+
task?: string;
|
|
23
|
+
summaries: number;
|
|
24
|
+
notes: number;
|
|
25
|
+
tags: number;
|
|
26
|
+
concepts: number;
|
|
27
|
+
flows: number;
|
|
28
|
+
/** Targets of the task that still have no summary. */
|
|
29
|
+
missing: string[];
|
|
30
|
+
/** Problems that were skipped instead of failing the whole write. */
|
|
31
|
+
warnings: string[];
|
|
32
|
+
}
|
|
33
|
+
export declare class EnrichmentError extends Error {
|
|
34
|
+
name: string;
|
|
35
|
+
}
|
|
36
|
+
/** Parses raw input (string or object) into a validated result. */
|
|
37
|
+
export declare function parseResult(raw: unknown): EnrichmentResult;
|
|
38
|
+
/**
|
|
39
|
+
* Applies an AI result to the brain: summaries, notes and tags on existing
|
|
40
|
+
* nodes, plus concepts and flows. Unknown node IDs become warnings rather than
|
|
41
|
+
* errors, so one typo does not throw away a whole batch of work.
|
|
42
|
+
*/
|
|
43
|
+
export declare function writeResult(brainDir: string, raw: unknown, taskId?: string): Promise<WriteReport>;
|
|
44
|
+
/** Where a node's note lives, e.g. `notes/modules/src/auth.md`. */
|
|
45
|
+
export declare function notePath(node: GraphNode): string;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { loadConfig } from '../config/config.js';
|
|
5
|
+
import { conceptId, flowId, parseId, PROJECT_ID } from '../graph/ids.js';
|
|
6
|
+
import { readGraph, writeGraph } from '../graph/jsonl.js';
|
|
7
|
+
import { resolveRef } from '../query/queries.js';
|
|
8
|
+
import { SearchIndex } from '../query/search.js';
|
|
9
|
+
import { findTask } from './tasks.js';
|
|
10
|
+
/** What the AI submits for a task (see `RESULT_FORMAT` in tasks.ts). */
|
|
11
|
+
export const EnrichmentResultSchema = z.object({
|
|
12
|
+
summaries: z.record(z.string(), z.string().trim().min(1).max(2000)).default({}),
|
|
13
|
+
notes: z.record(z.string(), z.string().trim().min(1)).default({}),
|
|
14
|
+
tags: z.record(z.string(), z.array(z.string().trim().min(1).max(40)).max(10)).default({}),
|
|
15
|
+
concepts: z
|
|
16
|
+
.array(z.object({
|
|
17
|
+
name: z.string().trim().min(1).max(80),
|
|
18
|
+
summary: z.string().trim().min(1).max(2000),
|
|
19
|
+
members: z.array(z.string().min(1)).max(50).default([]),
|
|
20
|
+
}))
|
|
21
|
+
.optional(),
|
|
22
|
+
flows: z
|
|
23
|
+
.array(z.object({
|
|
24
|
+
name: z.string().trim().min(1).max(80),
|
|
25
|
+
summary: z.string().trim().min(1).max(2000),
|
|
26
|
+
steps: z.array(z.string().min(1)).min(1).max(30),
|
|
27
|
+
}))
|
|
28
|
+
.optional(),
|
|
29
|
+
});
|
|
30
|
+
export class EnrichmentError extends Error {
|
|
31
|
+
name = 'EnrichmentError';
|
|
32
|
+
}
|
|
33
|
+
/** Parses raw input (string or object) into a validated result. */
|
|
34
|
+
export function parseResult(raw) {
|
|
35
|
+
let value = raw;
|
|
36
|
+
if (typeof raw === 'string') {
|
|
37
|
+
try {
|
|
38
|
+
value = JSON.parse(raw);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
throw new EnrichmentError(`Result is not valid JSON: ${err.message}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const parsed = EnrichmentResultSchema.safeParse(value);
|
|
45
|
+
if (!parsed.success)
|
|
46
|
+
throw new EnrichmentError(`Invalid result:\n${z.prettifyError(parsed.error)}`);
|
|
47
|
+
return parsed.data;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Applies an AI result to the brain: summaries, notes and tags on existing
|
|
51
|
+
* nodes, plus concepts and flows. Unknown node IDs become warnings rather than
|
|
52
|
+
* errors, so one typo does not throw away a whole batch of work.
|
|
53
|
+
*/
|
|
54
|
+
export async function writeResult(brainDir, raw, taskId) {
|
|
55
|
+
const dir = resolve(brainDir);
|
|
56
|
+
const result = parseResult(raw);
|
|
57
|
+
const [config, graph] = await Promise.all([loadConfig(dir), readGraph(dir)]);
|
|
58
|
+
// A task that is already complete no longer appears in the list; the write is still accepted.
|
|
59
|
+
const task = taskId ? findTask(graph, taskId) : undefined;
|
|
60
|
+
const provenance = `ai@${config.source.indexedCommit?.slice(0, 7) ?? 'worktree'}`;
|
|
61
|
+
const report = { summaries: 0, notes: 0, tags: 0, concepts: 0, flows: 0, missing: [], warnings: [] };
|
|
62
|
+
if (taskId)
|
|
63
|
+
report.task = taskId;
|
|
64
|
+
const search = new SearchIndex(graph.nodes());
|
|
65
|
+
const lookup = (ref) => {
|
|
66
|
+
const found = resolveRef(graph, search, ref);
|
|
67
|
+
return 'node' in found ? found.node : undefined;
|
|
68
|
+
};
|
|
69
|
+
const markWritten = (node, patch) => {
|
|
70
|
+
graph.updateNode(node.id, {
|
|
71
|
+
...patch,
|
|
72
|
+
stale: false,
|
|
73
|
+
provenance: { ...node.provenance, semantic: provenance },
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
for (const [id, summary] of Object.entries(result.summaries)) {
|
|
77
|
+
const node = graph.getNode(id);
|
|
78
|
+
if (!node) {
|
|
79
|
+
report.warnings.push(`summaries: unknown node "${id}" (use IDs exactly as given in the task)`);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
markWritten(node, { summary });
|
|
83
|
+
report.summaries++;
|
|
84
|
+
}
|
|
85
|
+
for (const [id, tags] of Object.entries(result.tags)) {
|
|
86
|
+
const node = graph.getNode(id);
|
|
87
|
+
if (!node) {
|
|
88
|
+
report.warnings.push(`tags: unknown node "${id}"`);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const merged = [...new Set([...(node.tags ?? []), ...tags.map((t) => t.toLowerCase())])];
|
|
92
|
+
graph.updateNode(id, { tags: merged });
|
|
93
|
+
report.tags++;
|
|
94
|
+
}
|
|
95
|
+
const notes = [];
|
|
96
|
+
for (const [id, markdown] of Object.entries(result.notes)) {
|
|
97
|
+
const node = graph.getNode(id);
|
|
98
|
+
if (!node) {
|
|
99
|
+
report.warnings.push(`notes: unknown node "${id}"`);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const path = notePath(node);
|
|
103
|
+
graph.updateNode(id, { note: path });
|
|
104
|
+
notes.push([path, markdown.endsWith('\n') ? markdown : `${markdown}\n`]);
|
|
105
|
+
report.notes++;
|
|
106
|
+
}
|
|
107
|
+
const removedNotes = [];
|
|
108
|
+
if (result.concepts) {
|
|
109
|
+
if (taskId === 'concepts')
|
|
110
|
+
removedNotes.push(...removeAll(graph, 'concept'));
|
|
111
|
+
for (const c of result.concepts) {
|
|
112
|
+
const id = conceptId(c.name);
|
|
113
|
+
const members = resolveAll(c.members, lookup, `concept "${c.name}"`, report.warnings);
|
|
114
|
+
graph.upsertNode({
|
|
115
|
+
id,
|
|
116
|
+
type: 'concept',
|
|
117
|
+
name: c.name,
|
|
118
|
+
summary: c.summary,
|
|
119
|
+
note: notePathFor('concept', id),
|
|
120
|
+
provenance: { semantic: provenance },
|
|
121
|
+
});
|
|
122
|
+
for (const m of members)
|
|
123
|
+
graph.addEdge({ from: m.id, to: id, type: 'implements_concept' });
|
|
124
|
+
notes.push([notePathFor('concept', id), conceptNote(c.name, c.summary, members)]);
|
|
125
|
+
report.concepts++;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (result.flows) {
|
|
129
|
+
if (taskId === 'flows')
|
|
130
|
+
removedNotes.push(...removeAll(graph, 'flow'));
|
|
131
|
+
for (const f of result.flows) {
|
|
132
|
+
const id = flowId(f.name);
|
|
133
|
+
const steps = resolveAll(f.steps, lookup, `flow "${f.name}"`, report.warnings);
|
|
134
|
+
if (!steps.length) {
|
|
135
|
+
report.warnings.push(`flow "${f.name}": no valid steps, skipped`);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
graph.upsertNode({
|
|
139
|
+
id,
|
|
140
|
+
type: 'flow',
|
|
141
|
+
name: f.name,
|
|
142
|
+
summary: f.summary,
|
|
143
|
+
note: notePathFor('flow', id),
|
|
144
|
+
provenance: { semantic: provenance },
|
|
145
|
+
});
|
|
146
|
+
for (const e of graph.incoming(id, ['step_of']))
|
|
147
|
+
graph.removeEdge(e.from, 'step_of', id);
|
|
148
|
+
steps.forEach((s, i) => graph.addEdge({ from: s.id, to: id, type: 'step_of', props: { order: i + 1 } }));
|
|
149
|
+
notes.push([notePathFor('flow', id), flowNote(f.name, f.summary, steps)]);
|
|
150
|
+
report.flows++;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (task)
|
|
154
|
+
report.missing = task.targets.filter((id) => !graph.getNode(id)?.summary);
|
|
155
|
+
await writeGraph(dir, graph);
|
|
156
|
+
for (const path of removedNotes) {
|
|
157
|
+
if (!notes.some(([p]) => p === path))
|
|
158
|
+
await rm(join(dir, path), { force: true });
|
|
159
|
+
}
|
|
160
|
+
for (const [path, content] of notes) {
|
|
161
|
+
await mkdir(dirname(join(dir, path)), { recursive: true });
|
|
162
|
+
await writeFile(join(dir, path), content, 'utf8');
|
|
163
|
+
}
|
|
164
|
+
return report;
|
|
165
|
+
}
|
|
166
|
+
function resolveAll(refs, lookup, where, warnings) {
|
|
167
|
+
const out = [];
|
|
168
|
+
for (const r of refs) {
|
|
169
|
+
const node = lookup(r);
|
|
170
|
+
if (!node)
|
|
171
|
+
warnings.push(`${where}: could not resolve "${r}"`);
|
|
172
|
+
else if (!out.some((n) => n.id === node.id))
|
|
173
|
+
out.push(node);
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
}
|
|
177
|
+
/** Removes every node of a semantic type and returns their note paths. */
|
|
178
|
+
function removeAll(graph, type) {
|
|
179
|
+
const doomed = [...graph.nodes()].filter((n) => n.type === type);
|
|
180
|
+
for (const n of doomed)
|
|
181
|
+
graph.removeNode(n.id);
|
|
182
|
+
return doomed.map((n) => n.note).filter((p) => !!p);
|
|
183
|
+
}
|
|
184
|
+
// ── Notes ─────────────────────────────────────────────────────────────
|
|
185
|
+
/** Where a node's note lives, e.g. `notes/modules/src/auth.md`. */
|
|
186
|
+
export function notePath(node) {
|
|
187
|
+
if (node.id === PROJECT_ID)
|
|
188
|
+
return 'notes/project.md';
|
|
189
|
+
return notePathFor(node.type, node.id);
|
|
190
|
+
}
|
|
191
|
+
function notePathFor(type, id) {
|
|
192
|
+
const parsed = parseId(id);
|
|
193
|
+
const safe = (s) => s.replace(/[<>:"|?*#]/g, '_');
|
|
194
|
+
switch (type) {
|
|
195
|
+
case 'module':
|
|
196
|
+
return `notes/modules/${safe(parsed.key)}.md`;
|
|
197
|
+
case 'file':
|
|
198
|
+
return `notes/files/${safe(parsed.key)}.md`;
|
|
199
|
+
case 'symbol':
|
|
200
|
+
return `notes/symbols/${safe(parsed.key)}/${safe(parsed.symbol ?? 'symbol')}.md`;
|
|
201
|
+
case 'package':
|
|
202
|
+
return `notes/packages/${safe(parsed.key)}.md`;
|
|
203
|
+
case 'concept':
|
|
204
|
+
return `notes/concepts/${parsed.key}.md`;
|
|
205
|
+
case 'flow':
|
|
206
|
+
return `notes/flows/${parsed.key}.md`;
|
|
207
|
+
default:
|
|
208
|
+
return 'notes/project.md';
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const label = (n) => (n.type === 'symbol' ? `\`${n.name}\` (${n.path})` : `\`${n.path ?? n.name}\``);
|
|
212
|
+
function conceptNote(name, summary, members) {
|
|
213
|
+
const lines = [`# ${name}`, '', summary, ''];
|
|
214
|
+
if (members.length) {
|
|
215
|
+
lines.push('## Where it lives', '');
|
|
216
|
+
for (const m of members)
|
|
217
|
+
lines.push(`- ${label(m)}${m.summary ? `: ${m.summary}` : ''}`);
|
|
218
|
+
lines.push('');
|
|
219
|
+
}
|
|
220
|
+
return lines.join('\n');
|
|
221
|
+
}
|
|
222
|
+
function flowNote(name, summary, steps) {
|
|
223
|
+
const lines = [`# ${name}`, '', summary, '', '## Steps', ''];
|
|
224
|
+
steps.forEach((s, i) => lines.push(`${i + 1}. ${label(s)}${s.summary ? `: ${s.summary}` : ''}`));
|
|
225
|
+
lines.push('');
|
|
226
|
+
return lines.join('\n');
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=write.js.map
|