@mmerterden/multi-agent-pipeline 23.3.0 → 23.5.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/CHANGELOG.md +73 -0
- package/README.md +27 -8
- package/README.tr.md +28 -9
- package/SECURITY.md +16 -0
- package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
- package/docs/adr/0010-own-code-graph.md +299 -8
- package/docs/architecture.md +3 -3
- package/docs/ecosystem.md +10 -10
- package/docs/engineering.md +4 -4
- package/docs/facts.json +8 -8
- package/docs/features.md +5 -5
- package/docs/performance.md +17 -17
- package/install/_dev-only-files.mjs +9 -0
- package/install/_platform-filter.mjs +2 -55
- package/install/claude.mjs +28 -2
- package/install/codex.mjs +1 -3
- package/install/copilot.mjs +4 -8
- package/install/templates/claude-hooks.json +32 -1
- package/manifest.json +236 -167
- package/package.json +11 -3
- package/pipeline/commands/multi-agent/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/design-check/SKILL.md +3 -2
- package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
- package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
- package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
- package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
- package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
- package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
- package/pipeline/contract/CHANGELOG.md +63 -0
- package/pipeline/contract/README.md +1 -0
- package/pipeline/contract/build.mjs +13 -1
- package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
- package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
- package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
- package/pipeline/contract/fixtures/runs-empty.json +1 -1
- package/pipeline/contract/fixtures/runs-failed.json +4 -1
- package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
- package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
- package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
- package/pipeline/contract/fixtures/runs-running.json +4 -1
- package/pipeline/contract/manifest.json +41 -15
- package/pipeline/contract/types/index.d.ts +81 -3
- package/pipeline/lib/detach-self.mjs +95 -0
- package/pipeline/lib/public-mcp-servers.mjs +33 -0
- package/pipeline/lib/rotated-log.mjs +93 -0
- package/pipeline/lib/stack-detect.sh +1 -1
- package/pipeline/lib/tls-trust.mjs +29 -0
- package/pipeline/lib/usage-lifecycle.mjs +9 -11
- package/pipeline/lib/usage-names.generated.mjs +613 -0
- package/pipeline/lib/usage-run-key.mjs +235 -0
- package/pipeline/lib/usage-vocab.mjs +210 -0
- package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
- package/pipeline/multi-agent-refs/analysis/render.md +1 -1
- package/pipeline/multi-agent-refs/channels/generator.md +4 -5
- package/pipeline/multi-agent-refs/cross-cli-contract.md +3 -3
- package/pipeline/multi-agent-refs/design-check/init-inventory.md +11 -1
- package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
- package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
- package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
- package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
- package/pipeline/multi-agent-refs/features/model-fallback.md +6 -4
- package/pipeline/multi-agent-refs/features/remote-control.md +253 -0
- package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
- package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
- package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
- package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
- package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
- package/pipeline/multi-agent-refs/features/usage-reporting.md +255 -27
- package/pipeline/multi-agent-refs/help/en.md +3 -2
- package/pipeline/multi-agent-refs/help/tr.md +3 -2
- package/pipeline/multi-agent-refs/knowledge.md +1 -1
- package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -2
- package/pipeline/multi-agent-refs/phases/operations.md +2 -2
- package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
- package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
- package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -0
- package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
- package/pipeline/multi-agent-refs/platform-parity.md +2 -2
- package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
- package/pipeline/office/index.html +1309 -236
- package/pipeline/office/toolkit.json +1 -1
- package/pipeline/rules/outside-the-pipeline.md +1 -1
- package/pipeline/schemas/activity.schema.json +23 -0
- package/pipeline/schemas/agent-state.schema.json +6 -1
- package/pipeline/schemas/code-graph-calls.schema.json +254 -0
- package/pipeline/schemas/code-graph-docs.schema.json +223 -0
- package/pipeline/schemas/code-graph-infra.schema.json +227 -0
- package/pipeline/schemas/code-graph.schema.json +2 -2
- package/pipeline/schemas/examples/design-check-config.json +27 -0
- package/pipeline/schemas/learning-curve.schema.json +67 -0
- package/pipeline/schemas/mcp-health.schema.json +96 -0
- package/pipeline/schemas/office-jobs.json +69 -2
- package/pipeline/schemas/office-jobs.schema.json +8 -1
- package/pipeline/schemas/phases.json +5 -0
- package/pipeline/schemas/phases.schema.json +8 -0
- package/pipeline/schemas/prefs.schema.json +46 -12
- package/pipeline/schemas/runs-index.schema.json +17 -0
- package/pipeline/schemas/toolkit-path-params.json +78 -8
- package/pipeline/scripts/README.md +1 -0
- package/pipeline/scripts/_code-graph.mjs +184 -103
- package/pipeline/scripts/_contract-core.mjs +1 -1
- package/pipeline/scripts/_contract-routes-office.mjs +33 -0
- package/pipeline/scripts/_diff-impact.mjs +21 -2
- package/pipeline/scripts/_graph-sidecars.mjs +372 -0
- package/pipeline/scripts/_http-post.mjs +103 -115
- package/pipeline/scripts/_safe-read.mjs +57 -0
- package/pipeline/scripts/_skill-practices.mjs +26 -0
- package/pipeline/scripts/_strip-code.mjs +380 -0
- package/pipeline/scripts/activity-snapshot.mjs +13 -1
- package/pipeline/scripts/aggregate-metrics.mjs +3 -5
- package/pipeline/scripts/build-stack-plugins.mjs +1 -47
- package/pipeline/scripts/call-graph/index.mjs +78 -0
- package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
- package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
- package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
- package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
- package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
- package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
- package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
- package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
- package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
- package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
- package/pipeline/scripts/call-graph/lex.mjs +396 -0
- package/pipeline/scripts/call-graph/platform.mjs +86 -0
- package/pipeline/scripts/call-graph/profiles.mjs +89 -0
- package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
- package/pipeline/scripts/call-graph/scan.mjs +267 -0
- package/pipeline/scripts/code-graph-rules/android.json +7 -2
- package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
- package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
- package/pipeline/scripts/code-graph-rules/go.json +2 -1
- package/pipeline/scripts/code-graph-rules/ios.json +3 -1
- package/pipeline/scripts/code-graph-rules/java.json +76 -0
- package/pipeline/scripts/code-graph-rules/node.json +7 -2
- package/pipeline/scripts/code-graph-rules/python.json +6 -2
- package/pipeline/scripts/code-graph-rules/rust.json +105 -0
- package/pipeline/scripts/contract-server.mjs +3 -0
- package/pipeline/scripts/design-check-config.mjs +205 -0
- package/pipeline/scripts/feedback-send.mjs +26 -26
- package/pipeline/scripts/gate-ledger.mjs +2 -1
- package/pipeline/scripts/gen-facts.mjs +1 -2
- package/pipeline/scripts/gen-usage-names.mjs +124 -0
- package/pipeline/scripts/graph-affected.mjs +109 -20
- package/pipeline/scripts/graph-build.mjs +95 -15
- package/pipeline/scripts/graph-export.mjs +272 -0
- package/pipeline/scripts/graph-hint.mjs +15 -2
- package/pipeline/scripts/graph-query.mjs +305 -26
- package/pipeline/scripts/graph-report.mjs +187 -1
- package/pipeline/scripts/health-report.mjs +3 -4
- package/pipeline/scripts/infra/docs.mjs +317 -0
- package/pipeline/scripts/infra/extract.mjs +998 -0
- package/pipeline/scripts/infra/graph.mjs +245 -0
- package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
- package/pipeline/scripts/job-launch.mjs +67 -2
- package/pipeline/scripts/learning-curve.mjs +288 -178
- package/pipeline/scripts/log-metric.sh +10 -1
- package/pipeline/scripts/mcp-health.mjs +309 -0
- package/pipeline/scripts/note-agent-event.mjs +3 -4
- package/pipeline/scripts/note-command-use.mjs +333 -0
- package/pipeline/scripts/note-command-use.sh +126 -0
- package/pipeline/scripts/note-mcp-call.sh +89 -0
- package/pipeline/scripts/note-mcp-failure.mjs +272 -1
- package/pipeline/scripts/note-session.sh +62 -3
- package/pipeline/scripts/note-skill-use.mjs +58 -2
- package/pipeline/scripts/office-build.mjs +115 -1
- package/pipeline/scripts/office-memory.mjs +14 -5
- package/pipeline/scripts/pair.mjs +333 -0
- package/pipeline/scripts/pre-push-check.sh +1 -1
- package/pipeline/scripts/remote/cbor.mjs +128 -0
- package/pipeline/scripts/remote/contract.mjs +98 -0
- package/pipeline/scripts/remote/handler.mjs +330 -0
- package/pipeline/scripts/remote/handles.mjs +57 -0
- package/pipeline/scripts/remote/lifecycle.mjs +186 -0
- package/pipeline/scripts/remote/listener.mjs +204 -0
- package/pipeline/scripts/remote/lockout.mjs +103 -0
- package/pipeline/scripts/remote/nonces.mjs +61 -0
- package/pipeline/scripts/remote/pairing.mjs +519 -0
- package/pipeline/scripts/remote/qr-encode.mjs +459 -0
- package/pipeline/scripts/remote/store.mjs +191 -0
- package/pipeline/scripts/remote/transport.mjs +211 -0
- package/pipeline/scripts/remote/verbs.json +70 -0
- package/pipeline/scripts/remote/verbs.mjs +217 -0
- package/pipeline/scripts/remote/webauthn.mjs +169 -0
- package/pipeline/scripts/remote/wire.mjs +364 -0
- package/pipeline/scripts/remote-listener.mjs +83 -0
- package/pipeline/scripts/route-learn.mjs +4 -4
- package/pipeline/scripts/run-kill.mjs +1 -1
- package/pipeline/scripts/run-write.mjs +13 -2
- package/pipeline/scripts/runs-index.mjs +30 -3
- package/pipeline/scripts/search-logs.sh +9 -0
- package/pipeline/scripts/session-brief.mjs +458 -0
- package/pipeline/scripts/session-brief.sh +130 -0
- package/pipeline/scripts/skill-usage.mjs +16 -5
- package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
- package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
- package/pipeline/scripts/test-gap-rules/java.json +20 -0
- package/pipeline/scripts/test-gap-rules/rust.json +14 -0
- package/pipeline/scripts/token-budget-report.mjs +3 -2
- package/pipeline/scripts/uninstall.mjs +29 -0
- package/pipeline/scripts/usage-access.mjs +16 -31
- package/pipeline/scripts/usage-health.mjs +31 -62
- package/pipeline/scripts/usage-register-beacon.mjs +11 -22
- package/pipeline/scripts/usage-register.mjs +39 -29
- package/pipeline/scripts/usage-report.mjs +579 -178
- package/pipeline/scripts/validate-code-graph.mjs +361 -111
- package/pipeline/scripts/write-state.mjs +39 -0
- package/pipeline/skills/.skill-manifest.json +21 -17
- package/pipeline/skills/.skills-index.json +13 -2
- package/pipeline/skills/shared/README.md +5 -4
- package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
- package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
- package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
- package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
- package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
- package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
- package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
- package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
- package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
- package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
- package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
- package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
- package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
- package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
- package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
- package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
- package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
- package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
- package/pipeline/skills/skills-index.md +3 -2
- package/docs/FIGMA_PIPELINE.md +0 -137
- package/pipeline/lib/identifier-scan.mjs +0 -156
- package/pipeline/scripts/_renamed-skills.mjs +0 -164
- package/pipeline/scripts/publish-staged.mjs +0 -324
- package/pipeline/skills/renamed.json +0 -30
- package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
|
@@ -34,6 +34,7 @@ import { resolve } from "node:path";
|
|
|
34
34
|
import { readFileSync } from "node:fs";
|
|
35
35
|
import { parseFlags } from "./graph-build.mjs";
|
|
36
36
|
import { loadGraph, defaultGraphPath } from "./graph-query.mjs";
|
|
37
|
+
import { layerNotes } from "./_graph-sidecars.mjs";
|
|
37
38
|
import {
|
|
38
39
|
parseHunkRanges,
|
|
39
40
|
changedSymbols,
|
|
@@ -62,19 +63,45 @@ export function findByName(graph, name) {
|
|
|
62
63
|
return graph.nodes.filter((n) => (n.name || "").toLowerCase() === lower);
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
const RANK = { low: 1, medium: 2, high: 3, certain: 4 };
|
|
67
|
+
const RANK_NAME = ["", "low", "medium", "high", "certain"];
|
|
68
|
+
|
|
69
|
+
const CALLABLE_KINDS = new Set(["method", "function", "func", "fun", "def"]);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The edge kinds a symbol's dependents are found through by default. `calls`
|
|
73
|
+
* is followed only into a function or method that is itself a seed, and then
|
|
74
|
+
* into each caller in turn: the dependents of a type are the files that name
|
|
75
|
+
* it, and following every method's callers as well would list most of the
|
|
76
|
+
* repository.
|
|
77
|
+
*/
|
|
78
|
+
const STRUCTURAL_KINDS = new Set([
|
|
79
|
+
"imports",
|
|
80
|
+
"references",
|
|
81
|
+
"inherits",
|
|
82
|
+
"reads",
|
|
83
|
+
"sets",
|
|
84
|
+
"uses",
|
|
85
|
+
"builds",
|
|
86
|
+
"runs",
|
|
87
|
+
]);
|
|
88
|
+
|
|
65
89
|
/**
|
|
66
90
|
* Incoming adjacency only.
|
|
67
91
|
*
|
|
68
92
|
* @param {object} graph
|
|
69
93
|
* @param {Set<string>|null} kinds
|
|
70
|
-
* @
|
|
94
|
+
* @param {number} [minRank] - drop edges whose confidence ranks below this (low 1, medium 2, high 3)
|
|
95
|
+
* @returns {Map<string, Array<{id: string, kind: string, rank: number, via: string|null}>>}
|
|
71
96
|
*/
|
|
72
|
-
export function incoming(graph, kinds = null) {
|
|
97
|
+
export function incoming(graph, kinds = null, minRank = 0) {
|
|
73
98
|
const adj = new Map();
|
|
74
99
|
for (const e of graph.edges) {
|
|
75
100
|
if (kinds && !kinds.has(e.kind)) continue;
|
|
101
|
+
const rank = RANK[e.confidence] ?? RANK.certain;
|
|
102
|
+
if (rank < minRank) continue;
|
|
76
103
|
if (!adj.has(e.to)) adj.set(e.to, []);
|
|
77
|
-
adj.get(e.to).push({ id: e.from, kind: e.kind });
|
|
104
|
+
adj.get(e.to).push({ id: e.from, kind: e.kind, rank, via: e.via || null });
|
|
78
105
|
}
|
|
79
106
|
return adj;
|
|
80
107
|
}
|
|
@@ -95,11 +122,17 @@ export function incoming(graph, kinds = null) {
|
|
|
95
122
|
* @param {object[]} params.seeds - symbol or file nodes
|
|
96
123
|
* @param {number} params.depth
|
|
97
124
|
* @param {Set<string>|null} [params.kinds] - dependency edge kinds to follow
|
|
98
|
-
* @returns {Array<{id: string, dist: number, kind: string, node: object}>}
|
|
125
|
+
* @returns {Array<{id: string, dist: number, kind: string, node: object, confidence: string, via: string|null}>}
|
|
126
|
+
* `confidence` is the weakest call edge on the route to the dependent ("certain" when none was used).
|
|
127
|
+
* A `low` call edge is never followed: it is a lead, not a dependency.
|
|
99
128
|
*/
|
|
100
129
|
export function affected({ graph, seeds, depth, kinds = null }) {
|
|
101
130
|
const byId = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
102
|
-
const adj = incoming(graph, kinds);
|
|
131
|
+
const adj = incoming(graph, kinds || STRUCTURAL_KINDS);
|
|
132
|
+
const callIn = kinds ? new Map() : incoming(graph, new Set(["calls"]), RANK.medium);
|
|
133
|
+
const callTargets = new Set(
|
|
134
|
+
seeds.filter((n) => CALLABLE_KINDS.has(n.symbolKind)).map((n) => n.id),
|
|
135
|
+
);
|
|
103
136
|
const declares = new Map();
|
|
104
137
|
const definer = new Map();
|
|
105
138
|
for (const e of graph.edges) {
|
|
@@ -121,18 +154,54 @@ export function affected({ graph, seeds, depth, kinds = null }) {
|
|
|
121
154
|
for (const seed of seeds)
|
|
122
155
|
for (const id of expand(seed)) if (!walked.has(id)) walked.add(id) && frontier.push(id);
|
|
123
156
|
|
|
124
|
-
const reported = new
|
|
157
|
+
const reported = new Map();
|
|
158
|
+
const routeOf = new Map([...walked].map((id) => [id, RANK.certain]));
|
|
125
159
|
const out = [];
|
|
126
160
|
for (let dist = 1; dist <= depth && frontier.length; dist++) {
|
|
127
161
|
const next = [];
|
|
128
162
|
for (const target of frontier) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
163
|
+
const deps = [...(adj.get(target) || [])];
|
|
164
|
+
if (callTargets.has(target)) deps.push(...(callIn.get(target) || []));
|
|
165
|
+
for (const dep of deps) {
|
|
166
|
+
if (dep.kind === "defines") continue;
|
|
167
|
+
const route = Math.min(
|
|
168
|
+
routeOf.get(target) ?? RANK.certain,
|
|
169
|
+
dep.kind === "calls" ? dep.rank : RANK.certain,
|
|
170
|
+
);
|
|
171
|
+
if (dep.kind === "calls" && !walked.has(dep.id)) {
|
|
172
|
+
walked.add(dep.id);
|
|
173
|
+
routeOf.set(dep.id, route);
|
|
174
|
+
callTargets.add(dep.id);
|
|
175
|
+
next.push(dep.id);
|
|
176
|
+
}
|
|
177
|
+
const depId = dep.kind === "calls" ? definer.get(dep.id) || dep.id : dep.id;
|
|
178
|
+
if (seedFiles.has(depId)) continue;
|
|
179
|
+
if (reported.has(depId)) {
|
|
180
|
+
const have = reported.get(depId);
|
|
181
|
+
if (have.dist === dist && route > have.rank) {
|
|
182
|
+
have.rank = route;
|
|
183
|
+
have.hit.confidence = RANK_NAME[route];
|
|
184
|
+
}
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const node = byId.get(depId);
|
|
132
188
|
if (!node) continue;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
189
|
+
const hit = {
|
|
190
|
+
id: depId,
|
|
191
|
+
dist,
|
|
192
|
+
kind: dep.kind,
|
|
193
|
+
node,
|
|
194
|
+
confidence: RANK_NAME[route],
|
|
195
|
+
via: dep.via || null,
|
|
196
|
+
};
|
|
197
|
+
reported.set(depId, { dist, rank: route, hit });
|
|
198
|
+
out.push(hit);
|
|
199
|
+
for (const id of expand(node)) {
|
|
200
|
+
if (walked.has(id)) continue;
|
|
201
|
+
walked.add(id);
|
|
202
|
+
routeOf.set(id, route);
|
|
203
|
+
next.push(id);
|
|
204
|
+
}
|
|
136
205
|
}
|
|
137
206
|
}
|
|
138
207
|
frontier = next;
|
|
@@ -144,16 +213,37 @@ function printJson(obj) {
|
|
|
144
213
|
process.stdout.write(JSON.stringify(obj, null, 2) + "\n");
|
|
145
214
|
}
|
|
146
215
|
|
|
216
|
+
function hitLine(hit) {
|
|
217
|
+
const edge = hit.kind === "calls" ? `calls ${hit.via || "-"} ${hit.confidence}` : hit.kind;
|
|
218
|
+
const weak =
|
|
219
|
+
hit.confidence === "medium" ? " (reached only through medium-confidence call edges)" : "";
|
|
220
|
+
return `${" ".repeat(hit.dist)}- ${hit.node?.name || hit.id} [${edge}] ${hit.node?.path || "-"}${weak}`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function mediumNote(hits) {
|
|
224
|
+
const weak = hits.filter((h) => h.confidence === "medium").length;
|
|
225
|
+
const base =
|
|
226
|
+
"call edges of low confidence are not followed; a caller that exists only through one is not listed\n";
|
|
227
|
+
return weak ? `${weak} marked medium: confirm them before relying on them; ${base}` : base;
|
|
228
|
+
}
|
|
229
|
+
|
|
147
230
|
function hitRows(hits) {
|
|
148
231
|
return hits.map((h) => ({
|
|
149
232
|
id: h.id,
|
|
150
233
|
dist: h.dist,
|
|
151
234
|
edgeKind: h.kind,
|
|
235
|
+
...(h.kind === "calls" ? { via: h.via } : {}),
|
|
236
|
+
confidence: h.confidence,
|
|
152
237
|
path: h.node?.path || null,
|
|
153
238
|
}));
|
|
154
239
|
}
|
|
155
240
|
|
|
156
241
|
function freshnessLine(f) {
|
|
242
|
+
const layers = (f.layers || []).map((n) => `\ngraph layer: ${n}`).join("");
|
|
243
|
+
return graphLine(f) + layers;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function graphLine(f) {
|
|
157
247
|
if (!f.stale) return "graph: current";
|
|
158
248
|
const parts = [];
|
|
159
249
|
if (f.commitMoved)
|
|
@@ -162,6 +252,7 @@ function freshnessLine(f) {
|
|
|
162
252
|
);
|
|
163
253
|
if (f.changedFiles.length) parts.push(`${f.changedFiles.length} file(s) edited since the build`);
|
|
164
254
|
if (f.removedFiles.length) parts.push(`${f.removedFiles.length} file(s) removed`);
|
|
255
|
+
if (f.addedFiles?.length) parts.push(`${f.addedFiles.length} file(s) added`);
|
|
165
256
|
return `graph: STALE (${parts.join("; ")}) - rebuild with graph-build.mjs for a current answer`;
|
|
166
257
|
}
|
|
167
258
|
|
|
@@ -173,7 +264,7 @@ function runDiff(flags, graph, depth, kinds) {
|
|
|
173
264
|
} else {
|
|
174
265
|
text = diffFor(root, flags.diff);
|
|
175
266
|
}
|
|
176
|
-
const freshness = graphFreshness(graph, { root });
|
|
267
|
+
const freshness = { ...graphFreshness(graph, { root }), layers: layerNotes(graph) };
|
|
177
268
|
const range = flags["diff-file"] && flags["diff-file"] !== true ? undefined : flags.diff;
|
|
178
269
|
const side = graphSide(graph, { root, range });
|
|
179
270
|
const mapped = changedSymbols(graph, parseHunkRanges(text, side));
|
|
@@ -205,11 +296,10 @@ function runDiff(flags, graph, depth, kinds) {
|
|
|
205
296
|
process.stdout.write("\n");
|
|
206
297
|
for (const hit of hits) {
|
|
207
298
|
if (hit.node?.path) files.add(hit.node.path);
|
|
208
|
-
process.stdout.write(
|
|
209
|
-
`${" ".repeat(hit.dist)}- ${hit.node?.name || hit.id} [${hit.kind}] ${hit.node?.path || "-"}\n`,
|
|
210
|
-
);
|
|
299
|
+
process.stdout.write(`${hitLine(hit)}\n`);
|
|
211
300
|
}
|
|
212
301
|
process.stdout.write(`\n${hits.length} dependents across ${files.size} files\n`);
|
|
302
|
+
process.stdout.write(`${mediumNote(hits)}`);
|
|
213
303
|
if (result.notIndexed.length)
|
|
214
304
|
process.stdout.write(`not in the graph: ${result.notIndexed.join(", ")}\n`);
|
|
215
305
|
process.stdout.write(`${freshnessLine(freshness)}\n`);
|
|
@@ -256,7 +346,7 @@ function main() {
|
|
|
256
346
|
}
|
|
257
347
|
|
|
258
348
|
const seeds = findByName(graph, name);
|
|
259
|
-
const freshness = graphFreshness(graph);
|
|
349
|
+
const freshness = { ...graphFreshness(graph), layers: layerNotes(graph) };
|
|
260
350
|
if (seeds.length === 0) {
|
|
261
351
|
if (flags.json === true) {
|
|
262
352
|
printJson({ symbol: name, seeds: [], affected: [], freshness });
|
|
@@ -285,11 +375,10 @@ function main() {
|
|
|
285
375
|
const files = new Set();
|
|
286
376
|
for (const hit of hits) {
|
|
287
377
|
if (hit.node?.path) files.add(hit.node.path);
|
|
288
|
-
process.stdout.write(
|
|
289
|
-
`${" ".repeat(hit.dist)}- ${hit.node?.name || hit.id} [${hit.kind}] ${hit.node?.path || "-"}\n`,
|
|
290
|
-
);
|
|
378
|
+
process.stdout.write(`${hitLine(hit)}\n`);
|
|
291
379
|
}
|
|
292
380
|
process.stdout.write(`\n${hits.length} dependents across ${files.size} files\n`);
|
|
381
|
+
process.stdout.write(`${mediumNote(hits)}`);
|
|
293
382
|
process.stdout.write(`${freshnessLine(freshness)}\n`);
|
|
294
383
|
}
|
|
295
384
|
|
|
@@ -3,26 +3,39 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @file graph-build.mjs - build the code graph for one repo.
|
|
5
5
|
*
|
|
6
|
-
* Full rebuild every time, by measurement rather than by principle: on
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* staleness bug surface and a second code path to test in exchange for
|
|
6
|
+
* Full rebuild every time, by measurement rather than by principle: on a large
|
|
7
|
+
* iOS app (4,400 Swift sources, 14 MB) the whole pass takes about four seconds
|
|
8
|
+
* with call edges, so an incremental extraction path would add a cache
|
|
9
|
+
* file, a staleness bug surface and a second code path to test in exchange for
|
|
10
|
+
* little.
|
|
10
11
|
* The manifest is still written - Phase 1 uses it to report how far behind a
|
|
11
12
|
* graph is, not to rebuild a subset.
|
|
12
13
|
*
|
|
13
14
|
* Inputs:
|
|
14
15
|
* --root <path> Repo root. Default: cwd
|
|
15
|
-
* --stack <id> ios | android | node | python | go
|
|
16
|
+
* --stack <id> ios | android | node | python | go | rust | java | csharp | cpp.
|
|
17
|
+
* Required.
|
|
16
18
|
* --out <path> Graph output. Default: ~/.claude/knowledge/<project>/code-graph.json
|
|
17
19
|
* --max-nodes N Refuse to write a graph larger than this. Default: 200000.
|
|
18
20
|
* Callers pass prefs.global.codeGraph.maxNodes. A tree that
|
|
19
21
|
* blows past it is vendored or generated source, and writing
|
|
20
22
|
* a several-hundred-megabyte file for it helps nobody, so
|
|
21
23
|
* the build fails loudly instead of succeeding quietly.
|
|
24
|
+
* --no-calls Skip the calls sidecar (function nodes and call edges)
|
|
25
|
+
* --docs Also write the docs sidecar (documentation sections, rationale)
|
|
26
|
+
* --infra Also write the infra sidecar (Dockerfile, Compose, Kubernetes,
|
|
27
|
+
* Helm, Terraform, CI workflows, .env files, application config)
|
|
28
|
+
* The settings file code-graph.config.json beside the graph
|
|
29
|
+
* ({"docs": true, "infra": true, "calls": false}) sets the same
|
|
30
|
+
* per repo; a flag beats it.
|
|
22
31
|
* --json Emit the summary as JSON instead of a line
|
|
23
32
|
*
|
|
24
33
|
* Output:
|
|
25
|
-
* Writes the graph,
|
|
34
|
+
* Writes the main graph (schema 1.2.0: files, symbols, modules and the
|
|
35
|
+
* defines / imports / references / inherits edges) and one sidecar file per
|
|
36
|
+
* layer next to it: code-graph.calls.json, code-graph.docs.json,
|
|
37
|
+
* code-graph.infra.json. A sidecar this run did not build is removed, so no
|
|
38
|
+
* sidecar outlives the graph it was made against. Prints a one-line summary.
|
|
26
39
|
*
|
|
27
40
|
* Exit codes:
|
|
28
41
|
* 0 - built
|
|
@@ -32,18 +45,22 @@
|
|
|
32
45
|
* @module pipeline/scripts/graph-build
|
|
33
46
|
*/
|
|
34
47
|
|
|
35
|
-
import { readFileSync,
|
|
48
|
+
import { readFileSync, mkdirSync, existsSync } from "node:fs";
|
|
36
49
|
import { execFileSync } from "node:child_process";
|
|
37
50
|
import { join, dirname, resolve, basename } from "node:path";
|
|
38
51
|
import { homedir } from "node:os";
|
|
39
52
|
import { fileURLToPath } from "node:url";
|
|
40
53
|
import {
|
|
41
54
|
loadRules,
|
|
55
|
+
listCandidateFiles,
|
|
42
56
|
listSourceFiles,
|
|
43
57
|
extractFile,
|
|
44
|
-
|
|
58
|
+
buildGraphSet,
|
|
45
59
|
diffManifest,
|
|
46
60
|
} from "./_code-graph.mjs";
|
|
61
|
+
import { writeGraphFiles } from "./_graph-sidecars.mjs";
|
|
62
|
+
import { makeSafeReader } from "./_safe-read.mjs";
|
|
63
|
+
import { collectDocs, collectInfra } from "./infra/graph.mjs";
|
|
47
64
|
import { parseArgs } from "../lib/args.mjs";
|
|
48
65
|
import { exitOnHelp } from "../lib/cli-help.mjs";
|
|
49
66
|
|
|
@@ -51,6 +68,7 @@ exitOnHelp(import.meta.url);
|
|
|
51
68
|
|
|
52
69
|
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
|
|
53
70
|
const DEFAULT_MAX_NODES = 200000;
|
|
71
|
+
const MAX_ANALYSIS_MS = 240_000;
|
|
54
72
|
|
|
55
73
|
export function parseFlags(argv) {
|
|
56
74
|
const { flags, positionals } = parseArgs(argv, { equals: false, terminator: false });
|
|
@@ -72,11 +90,42 @@ function headCommit(root) {
|
|
|
72
90
|
}
|
|
73
91
|
}
|
|
74
92
|
|
|
93
|
+
export const SETTINGS_FILE = "code-graph.config.json";
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Which layers to build. Calls are on unless switched off; documentation and
|
|
97
|
+
* infrastructure are off unless a flag or the per-repo settings file next to
|
|
98
|
+
* the graph (`code-graph.config.json`: {"docs": true, "infra": true, "calls": false})
|
|
99
|
+
* switches them on. A flag beats the file.
|
|
100
|
+
*/
|
|
101
|
+
export function resolveLayers(flags, settings = {}) {
|
|
102
|
+
const pick = (name, fallback) =>
|
|
103
|
+
flags[`no-${name}`] === true
|
|
104
|
+
? false
|
|
105
|
+
: flags[name] === true
|
|
106
|
+
? true
|
|
107
|
+
: typeof settings[name] === "boolean"
|
|
108
|
+
? settings[name]
|
|
109
|
+
: fallback;
|
|
110
|
+
return { calls: pick("calls", true), docs: pick("docs", false), infra: pick("infra", false) };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function readSettings(out) {
|
|
114
|
+
try {
|
|
115
|
+
const parsed = JSON.parse(readFileSync(join(dirname(out), SETTINGS_FILE), "utf8"));
|
|
116
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
117
|
+
} catch {
|
|
118
|
+
return {};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
75
122
|
function main() {
|
|
76
123
|
const { flags } = parseFlags(process.argv.slice(2));
|
|
77
124
|
const stack = flags.stack;
|
|
78
125
|
if (!stack || stack === true) {
|
|
79
|
-
process.stderr.write(
|
|
126
|
+
process.stderr.write(
|
|
127
|
+
"graph-build: --stack <ios|android|node|python|go|rust|java|csharp|cpp> required\n",
|
|
128
|
+
);
|
|
80
129
|
process.exit(64);
|
|
81
130
|
}
|
|
82
131
|
|
|
@@ -94,20 +143,37 @@ function main() {
|
|
|
94
143
|
process.stderr.write(`graph-build: ${e.message}\n`);
|
|
95
144
|
process.exit(1);
|
|
96
145
|
}
|
|
146
|
+
const layers = resolveLayers(flags, readSettings(out));
|
|
97
147
|
|
|
98
148
|
const startedAt = Date.now();
|
|
99
|
-
const
|
|
149
|
+
const candidates = listCandidateFiles(root);
|
|
150
|
+
const files = listSourceFiles(root, rules, candidates);
|
|
151
|
+
const readSafe = makeSafeReader(root);
|
|
100
152
|
const extracted = new Map();
|
|
153
|
+
let analysisMs = 0;
|
|
101
154
|
for (const path of files) {
|
|
155
|
+
const text = readSafe(path);
|
|
156
|
+
if (text === null) continue;
|
|
102
157
|
try {
|
|
103
|
-
|
|
158
|
+
const began = performance.now();
|
|
159
|
+
extracted.set(
|
|
160
|
+
path,
|
|
161
|
+
extractFile(text, rules, layers.calls ? path : undefined, {
|
|
162
|
+
skipCalls: analysisMs > MAX_ANALYSIS_MS ? "total-time-budget" : null,
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
analysisMs += performance.now() - began;
|
|
104
166
|
} catch {
|
|
105
167
|
/* unreadable file: skip, it simply does not reach the graph */
|
|
106
168
|
}
|
|
107
169
|
}
|
|
108
170
|
|
|
109
171
|
const { manifest } = diffManifest(root, [...extracted.keys()], {});
|
|
110
|
-
const
|
|
172
|
+
const built = buildGraphSet({
|
|
173
|
+
infra: layers.infra ? collectInfra(root, candidates, readSafe) : null,
|
|
174
|
+
docs: layers.docs ? collectDocs(root, candidates, readSafe) : null,
|
|
175
|
+
calls: layers.calls,
|
|
176
|
+
known: new Set(candidates),
|
|
111
177
|
root,
|
|
112
178
|
stack,
|
|
113
179
|
extracted,
|
|
@@ -116,6 +182,7 @@ function main() {
|
|
|
116
182
|
baseCommit: headCommit(root),
|
|
117
183
|
generatedAt: new Date().toISOString(),
|
|
118
184
|
});
|
|
185
|
+
const graph = built.graph;
|
|
119
186
|
|
|
120
187
|
const maxNodes = Number(flags["max-nodes"]) > 0 ? Number(flags["max-nodes"]) : DEFAULT_MAX_NODES;
|
|
121
188
|
if (graph.stats.nodes > maxNodes) {
|
|
@@ -128,16 +195,29 @@ function main() {
|
|
|
128
195
|
}
|
|
129
196
|
|
|
130
197
|
mkdirSync(dirname(out), { recursive: true });
|
|
131
|
-
|
|
198
|
+
writeGraphFiles(out, built);
|
|
132
199
|
|
|
133
200
|
const elapsedMs = Date.now() - startedAt;
|
|
134
|
-
const
|
|
201
|
+
const layerStats = Object.fromEntries(
|
|
202
|
+
Object.entries(built.sidecars).map(([name, side]) => [
|
|
203
|
+
name,
|
|
204
|
+
{ nodes: side.stats.nodes, edges: side.stats.edges, truncated: side.truncated },
|
|
205
|
+
]),
|
|
206
|
+
);
|
|
207
|
+
const summary = { out, elapsedMs, ...graph.stats, layers: layerStats };
|
|
135
208
|
if (flags.json === true) {
|
|
136
209
|
process.stdout.write(JSON.stringify(summary, null, 2) + "\n");
|
|
137
210
|
} else {
|
|
211
|
+
const calls = built.sidecars.calls;
|
|
212
|
+
const parts = Object.entries(built.sidecars).map(
|
|
213
|
+
([name, side]) => `${name} ${side.stats.edges} edges${side.truncated ? " (TRUNCATED)" : ""}`,
|
|
214
|
+
);
|
|
138
215
|
process.stdout.write(
|
|
139
216
|
`graph-build: ${graph.stats.files} files, ${graph.stats.nodes} nodes, ` +
|
|
140
|
-
`${graph.stats.edges} edges
|
|
217
|
+
`${graph.stats.edges} edges` +
|
|
218
|
+
(parts.length ? `; sidecars: ${parts.join(", ")}` : "; no sidecars") +
|
|
219
|
+
(calls ? ` (${calls.stats.callFilesSkipped} files not call-analysed)` : "") +
|
|
220
|
+
` in ${elapsedMs}ms -> ${out}\n`,
|
|
141
221
|
);
|
|
142
222
|
}
|
|
143
223
|
}
|