@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.
Files changed (239) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +27 -8
  3. package/README.tr.md +28 -9
  4. package/SECURITY.md +16 -0
  5. package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
  6. package/docs/adr/0010-own-code-graph.md +299 -8
  7. package/docs/architecture.md +3 -3
  8. package/docs/ecosystem.md +10 -10
  9. package/docs/engineering.md +4 -4
  10. package/docs/facts.json +8 -8
  11. package/docs/features.md +5 -5
  12. package/docs/performance.md +17 -17
  13. package/install/_dev-only-files.mjs +9 -0
  14. package/install/_platform-filter.mjs +2 -55
  15. package/install/claude.mjs +28 -2
  16. package/install/codex.mjs +1 -3
  17. package/install/copilot.mjs +4 -8
  18. package/install/templates/claude-hooks.json +32 -1
  19. package/manifest.json +236 -167
  20. package/package.json +11 -3
  21. package/pipeline/commands/multi-agent/SKILL.md +1 -1
  22. package/pipeline/commands/multi-agent/design-check/SKILL.md +3 -2
  23. package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
  24. package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
  25. package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
  26. package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
  27. package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
  28. package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
  29. package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
  30. package/pipeline/contract/CHANGELOG.md +63 -0
  31. package/pipeline/contract/README.md +1 -0
  32. package/pipeline/contract/build.mjs +13 -1
  33. package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
  34. package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
  35. package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
  36. package/pipeline/contract/fixtures/runs-empty.json +1 -1
  37. package/pipeline/contract/fixtures/runs-failed.json +4 -1
  38. package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
  39. package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
  40. package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
  41. package/pipeline/contract/fixtures/runs-running.json +4 -1
  42. package/pipeline/contract/manifest.json +41 -15
  43. package/pipeline/contract/types/index.d.ts +81 -3
  44. package/pipeline/lib/detach-self.mjs +95 -0
  45. package/pipeline/lib/public-mcp-servers.mjs +33 -0
  46. package/pipeline/lib/rotated-log.mjs +93 -0
  47. package/pipeline/lib/stack-detect.sh +1 -1
  48. package/pipeline/lib/tls-trust.mjs +29 -0
  49. package/pipeline/lib/usage-lifecycle.mjs +9 -11
  50. package/pipeline/lib/usage-names.generated.mjs +613 -0
  51. package/pipeline/lib/usage-run-key.mjs +235 -0
  52. package/pipeline/lib/usage-vocab.mjs +210 -0
  53. package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
  54. package/pipeline/multi-agent-refs/analysis/render.md +1 -1
  55. package/pipeline/multi-agent-refs/channels/generator.md +4 -5
  56. package/pipeline/multi-agent-refs/cross-cli-contract.md +3 -3
  57. package/pipeline/multi-agent-refs/design-check/init-inventory.md +11 -1
  58. package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
  59. package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
  60. package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
  61. package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
  62. package/pipeline/multi-agent-refs/features/model-fallback.md +6 -4
  63. package/pipeline/multi-agent-refs/features/remote-control.md +253 -0
  64. package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
  65. package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
  66. package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
  67. package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
  68. package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
  69. package/pipeline/multi-agent-refs/features/usage-reporting.md +255 -27
  70. package/pipeline/multi-agent-refs/help/en.md +3 -2
  71. package/pipeline/multi-agent-refs/help/tr.md +3 -2
  72. package/pipeline/multi-agent-refs/knowledge.md +1 -1
  73. package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -2
  74. package/pipeline/multi-agent-refs/phases/operations.md +2 -2
  75. package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
  76. package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
  77. package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -0
  78. package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
  79. package/pipeline/multi-agent-refs/platform-parity.md +2 -2
  80. package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
  81. package/pipeline/office/index.html +1309 -236
  82. package/pipeline/office/toolkit.json +1 -1
  83. package/pipeline/rules/outside-the-pipeline.md +1 -1
  84. package/pipeline/schemas/activity.schema.json +23 -0
  85. package/pipeline/schemas/agent-state.schema.json +6 -1
  86. package/pipeline/schemas/code-graph-calls.schema.json +254 -0
  87. package/pipeline/schemas/code-graph-docs.schema.json +223 -0
  88. package/pipeline/schemas/code-graph-infra.schema.json +227 -0
  89. package/pipeline/schemas/code-graph.schema.json +2 -2
  90. package/pipeline/schemas/examples/design-check-config.json +27 -0
  91. package/pipeline/schemas/learning-curve.schema.json +67 -0
  92. package/pipeline/schemas/mcp-health.schema.json +96 -0
  93. package/pipeline/schemas/office-jobs.json +69 -2
  94. package/pipeline/schemas/office-jobs.schema.json +8 -1
  95. package/pipeline/schemas/phases.json +5 -0
  96. package/pipeline/schemas/phases.schema.json +8 -0
  97. package/pipeline/schemas/prefs.schema.json +46 -12
  98. package/pipeline/schemas/runs-index.schema.json +17 -0
  99. package/pipeline/schemas/toolkit-path-params.json +78 -8
  100. package/pipeline/scripts/README.md +1 -0
  101. package/pipeline/scripts/_code-graph.mjs +184 -103
  102. package/pipeline/scripts/_contract-core.mjs +1 -1
  103. package/pipeline/scripts/_contract-routes-office.mjs +33 -0
  104. package/pipeline/scripts/_diff-impact.mjs +21 -2
  105. package/pipeline/scripts/_graph-sidecars.mjs +372 -0
  106. package/pipeline/scripts/_http-post.mjs +103 -115
  107. package/pipeline/scripts/_safe-read.mjs +57 -0
  108. package/pipeline/scripts/_skill-practices.mjs +26 -0
  109. package/pipeline/scripts/_strip-code.mjs +380 -0
  110. package/pipeline/scripts/activity-snapshot.mjs +13 -1
  111. package/pipeline/scripts/aggregate-metrics.mjs +3 -5
  112. package/pipeline/scripts/build-stack-plugins.mjs +1 -47
  113. package/pipeline/scripts/call-graph/index.mjs +78 -0
  114. package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
  115. package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
  116. package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
  117. package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
  118. package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
  119. package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
  120. package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
  121. package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
  122. package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
  123. package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
  124. package/pipeline/scripts/call-graph/lex.mjs +396 -0
  125. package/pipeline/scripts/call-graph/platform.mjs +86 -0
  126. package/pipeline/scripts/call-graph/profiles.mjs +89 -0
  127. package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
  128. package/pipeline/scripts/call-graph/scan.mjs +267 -0
  129. package/pipeline/scripts/code-graph-rules/android.json +7 -2
  130. package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
  131. package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
  132. package/pipeline/scripts/code-graph-rules/go.json +2 -1
  133. package/pipeline/scripts/code-graph-rules/ios.json +3 -1
  134. package/pipeline/scripts/code-graph-rules/java.json +76 -0
  135. package/pipeline/scripts/code-graph-rules/node.json +7 -2
  136. package/pipeline/scripts/code-graph-rules/python.json +6 -2
  137. package/pipeline/scripts/code-graph-rules/rust.json +105 -0
  138. package/pipeline/scripts/contract-server.mjs +3 -0
  139. package/pipeline/scripts/design-check-config.mjs +205 -0
  140. package/pipeline/scripts/feedback-send.mjs +26 -26
  141. package/pipeline/scripts/gate-ledger.mjs +2 -1
  142. package/pipeline/scripts/gen-facts.mjs +1 -2
  143. package/pipeline/scripts/gen-usage-names.mjs +124 -0
  144. package/pipeline/scripts/graph-affected.mjs +109 -20
  145. package/pipeline/scripts/graph-build.mjs +95 -15
  146. package/pipeline/scripts/graph-export.mjs +272 -0
  147. package/pipeline/scripts/graph-hint.mjs +15 -2
  148. package/pipeline/scripts/graph-query.mjs +305 -26
  149. package/pipeline/scripts/graph-report.mjs +187 -1
  150. package/pipeline/scripts/health-report.mjs +3 -4
  151. package/pipeline/scripts/infra/docs.mjs +317 -0
  152. package/pipeline/scripts/infra/extract.mjs +998 -0
  153. package/pipeline/scripts/infra/graph.mjs +245 -0
  154. package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
  155. package/pipeline/scripts/job-launch.mjs +67 -2
  156. package/pipeline/scripts/learning-curve.mjs +288 -178
  157. package/pipeline/scripts/log-metric.sh +10 -1
  158. package/pipeline/scripts/mcp-health.mjs +309 -0
  159. package/pipeline/scripts/note-agent-event.mjs +3 -4
  160. package/pipeline/scripts/note-command-use.mjs +333 -0
  161. package/pipeline/scripts/note-command-use.sh +126 -0
  162. package/pipeline/scripts/note-mcp-call.sh +89 -0
  163. package/pipeline/scripts/note-mcp-failure.mjs +272 -1
  164. package/pipeline/scripts/note-session.sh +62 -3
  165. package/pipeline/scripts/note-skill-use.mjs +58 -2
  166. package/pipeline/scripts/office-build.mjs +115 -1
  167. package/pipeline/scripts/office-memory.mjs +14 -5
  168. package/pipeline/scripts/pair.mjs +333 -0
  169. package/pipeline/scripts/pre-push-check.sh +1 -1
  170. package/pipeline/scripts/remote/cbor.mjs +128 -0
  171. package/pipeline/scripts/remote/contract.mjs +98 -0
  172. package/pipeline/scripts/remote/handler.mjs +330 -0
  173. package/pipeline/scripts/remote/handles.mjs +57 -0
  174. package/pipeline/scripts/remote/lifecycle.mjs +186 -0
  175. package/pipeline/scripts/remote/listener.mjs +204 -0
  176. package/pipeline/scripts/remote/lockout.mjs +103 -0
  177. package/pipeline/scripts/remote/nonces.mjs +61 -0
  178. package/pipeline/scripts/remote/pairing.mjs +519 -0
  179. package/pipeline/scripts/remote/qr-encode.mjs +459 -0
  180. package/pipeline/scripts/remote/store.mjs +191 -0
  181. package/pipeline/scripts/remote/transport.mjs +211 -0
  182. package/pipeline/scripts/remote/verbs.json +70 -0
  183. package/pipeline/scripts/remote/verbs.mjs +217 -0
  184. package/pipeline/scripts/remote/webauthn.mjs +169 -0
  185. package/pipeline/scripts/remote/wire.mjs +364 -0
  186. package/pipeline/scripts/remote-listener.mjs +83 -0
  187. package/pipeline/scripts/route-learn.mjs +4 -4
  188. package/pipeline/scripts/run-kill.mjs +1 -1
  189. package/pipeline/scripts/run-write.mjs +13 -2
  190. package/pipeline/scripts/runs-index.mjs +30 -3
  191. package/pipeline/scripts/search-logs.sh +9 -0
  192. package/pipeline/scripts/session-brief.mjs +458 -0
  193. package/pipeline/scripts/session-brief.sh +130 -0
  194. package/pipeline/scripts/skill-usage.mjs +16 -5
  195. package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
  196. package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
  197. package/pipeline/scripts/test-gap-rules/java.json +20 -0
  198. package/pipeline/scripts/test-gap-rules/rust.json +14 -0
  199. package/pipeline/scripts/token-budget-report.mjs +3 -2
  200. package/pipeline/scripts/uninstall.mjs +29 -0
  201. package/pipeline/scripts/usage-access.mjs +16 -31
  202. package/pipeline/scripts/usage-health.mjs +31 -62
  203. package/pipeline/scripts/usage-register-beacon.mjs +11 -22
  204. package/pipeline/scripts/usage-register.mjs +39 -29
  205. package/pipeline/scripts/usage-report.mjs +579 -178
  206. package/pipeline/scripts/validate-code-graph.mjs +361 -111
  207. package/pipeline/scripts/write-state.mjs +39 -0
  208. package/pipeline/skills/.skill-manifest.json +21 -17
  209. package/pipeline/skills/.skills-index.json +13 -2
  210. package/pipeline/skills/shared/README.md +5 -4
  211. package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
  212. package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
  213. package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
  214. package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
  215. package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
  216. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
  217. package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
  218. package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
  219. package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
  220. package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
  221. package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
  222. package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
  223. package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
  224. package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
  225. package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
  226. package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
  227. package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
  228. package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
  229. package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
  230. package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
  231. package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
  232. package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
  233. package/pipeline/skills/skills-index.md +3 -2
  234. package/docs/FIGMA_PIPELINE.md +0 -137
  235. package/pipeline/lib/identifier-scan.mjs +0 -156
  236. package/pipeline/scripts/_renamed-skills.mjs +0 -164
  237. package/pipeline/scripts/publish-staged.mjs +0 -324
  238. package/pipeline/skills/renamed.json +0 -30
  239. 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
- * @returns {Map<string, Array<{id: string, kind: string}>>}
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 Set();
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
- for (const dep of adj.get(target) || []) {
130
- if (dep.kind === "defines" || seedFiles.has(dep.id) || reported.has(dep.id)) continue;
131
- const node = byId.get(dep.id);
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
- reported.add(dep.id);
134
- out.push({ id: dep.id, dist, kind: dep.kind, node });
135
- for (const id of expand(node)) if (!walked.has(id)) walked.add(id) && next.push(id);
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 the
7
- * corporate iOS app (4,311 Swift sources, 14.3 MB) the whole pass takes under
8
- * three seconds, so an incremental extraction path would add a cache file, a
9
- * staleness bug surface and a second code path to test in exchange for nothing.
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. Required.
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, prints a one-line summary.
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, writeFileSync, mkdirSync, existsSync } from "node:fs";
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
- buildGraph,
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("graph-build: --stack <ios|android|node|python|go> required\n");
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 files = listSourceFiles(root, rules);
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
- extracted.set(path, extractFile(readFileSync(join(root, path), "utf8"), rules));
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 graph = buildGraph({
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
- writeFileSync(out, JSON.stringify(graph), "utf8");
198
+ writeGraphFiles(out, built);
132
199
 
133
200
  const elapsedMs = Date.now() - startedAt;
134
- const summary = { out, elapsedMs, ...graph.stats };
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 in ${elapsedMs}ms -> ${out}\n`,
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
  }