@mmerterden/multi-agent-pipeline 23.2.0 → 23.4.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 (230) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +25 -6
  3. package/README.tr.md +26 -7
  4. package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
  5. package/docs/adr/0010-own-code-graph.md +299 -8
  6. package/docs/architecture.md +3 -3
  7. package/docs/ecosystem.md +10 -10
  8. package/docs/engineering.md +4 -4
  9. package/docs/facts.json +8 -8
  10. package/docs/features.md +6 -6
  11. package/docs/performance.md +17 -17
  12. package/install/_dev-only-files.mjs +9 -0
  13. package/install/claude.mjs +28 -2
  14. package/install/templates/claude-hooks.json +32 -1
  15. package/manifest.json +229 -161
  16. package/package.json +11 -3
  17. package/pipeline/commands/multi-agent/SKILL.md +1 -1
  18. package/pipeline/commands/multi-agent/design-check/SKILL.md +2 -2
  19. package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
  20. package/pipeline/commands/multi-agent/fable-status/SKILL.md +1 -1
  21. package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
  22. package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
  23. package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
  24. package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
  25. package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
  26. package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
  27. package/pipeline/contract/CHANGELOG.md +49 -0
  28. package/pipeline/contract/build.mjs +13 -1
  29. package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
  30. package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
  31. package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
  32. package/pipeline/contract/fixtures/runs-empty.json +1 -1
  33. package/pipeline/contract/fixtures/runs-failed.json +4 -1
  34. package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
  35. package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
  36. package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
  37. package/pipeline/contract/fixtures/runs-running.json +4 -1
  38. package/pipeline/contract/manifest.json +28 -15
  39. package/pipeline/contract/types/index.d.ts +55 -3
  40. package/pipeline/lib/detach-self.mjs +95 -0
  41. package/pipeline/lib/model-rung.sh +1 -1
  42. package/pipeline/lib/public-mcp-servers.mjs +33 -0
  43. package/pipeline/lib/rotated-log.mjs +93 -0
  44. package/pipeline/lib/tls-trust.mjs +29 -0
  45. package/pipeline/lib/usage-lifecycle.mjs +9 -11
  46. package/pipeline/lib/usage-names.generated.mjs +614 -0
  47. package/pipeline/lib/usage-run-key.mjs +235 -0
  48. package/pipeline/lib/usage-vocab.mjs +210 -0
  49. package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
  50. package/pipeline/multi-agent-refs/analysis/render.md +1 -1
  51. package/pipeline/multi-agent-refs/channels/generator.md +4 -5
  52. package/pipeline/multi-agent-refs/cross-cli-contract.md +4 -4
  53. package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
  54. package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
  55. package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
  56. package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
  57. package/pipeline/multi-agent-refs/features/model-fallback.md +9 -7
  58. package/pipeline/multi-agent-refs/features/remote-control.md +252 -0
  59. package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
  60. package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
  61. package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
  62. package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
  63. package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
  64. package/pipeline/multi-agent-refs/features/usage-reporting.md +252 -24
  65. package/pipeline/multi-agent-refs/help/en.md +3 -2
  66. package/pipeline/multi-agent-refs/help/tr.md +3 -2
  67. package/pipeline/multi-agent-refs/knowledge.md +1 -1
  68. package/pipeline/multi-agent-refs/orchestrator/copilot-pipeline.md +1 -1
  69. package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +1 -1
  70. package/pipeline/multi-agent-refs/phases/operations.md +2 -2
  71. package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
  72. package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
  73. package/pipeline/multi-agent-refs/phases/phase-3-review.md +5 -3
  74. package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
  75. package/pipeline/multi-agent-refs/platform-parity.md +2 -2
  76. package/pipeline/multi-agent-refs/review/panel.md +1 -1
  77. package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
  78. package/pipeline/office/index.html +1207 -233
  79. package/pipeline/office/toolkit.json +1 -1
  80. package/pipeline/rules/outside-the-pipeline.md +1 -1
  81. package/pipeline/schemas/activity.schema.json +23 -0
  82. package/pipeline/schemas/agent-state.schema.json +6 -1
  83. package/pipeline/schemas/code-graph-calls.schema.json +254 -0
  84. package/pipeline/schemas/code-graph-docs.schema.json +223 -0
  85. package/pipeline/schemas/code-graph-infra.schema.json +227 -0
  86. package/pipeline/schemas/code-graph.schema.json +2 -2
  87. package/pipeline/schemas/examples/design-check-config.json +27 -0
  88. package/pipeline/schemas/learning-curve.schema.json +67 -0
  89. package/pipeline/schemas/office-jobs.json +69 -2
  90. package/pipeline/schemas/office-jobs.schema.json +8 -1
  91. package/pipeline/schemas/phases.json +5 -0
  92. package/pipeline/schemas/phases.schema.json +8 -0
  93. package/pipeline/schemas/prefs.schema.json +46 -12
  94. package/pipeline/schemas/runs-index.schema.json +17 -0
  95. package/pipeline/schemas/toolkit-path-params.json +84 -8
  96. package/pipeline/scripts/README.md +1 -0
  97. package/pipeline/scripts/_code-graph.mjs +184 -103
  98. package/pipeline/scripts/_contract-core.mjs +1 -1
  99. package/pipeline/scripts/_contract-routes-office.mjs +21 -0
  100. package/pipeline/scripts/_diff-impact.mjs +21 -2
  101. package/pipeline/scripts/_graph-sidecars.mjs +372 -0
  102. package/pipeline/scripts/_http-post.mjs +103 -115
  103. package/pipeline/scripts/_safe-read.mjs +57 -0
  104. package/pipeline/scripts/_skill-practices.mjs +26 -0
  105. package/pipeline/scripts/_strip-code.mjs +380 -0
  106. package/pipeline/scripts/activity-snapshot.mjs +13 -1
  107. package/pipeline/scripts/aggregate-metrics.mjs +3 -5
  108. package/pipeline/scripts/call-graph/index.mjs +78 -0
  109. package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
  110. package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
  111. package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
  112. package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
  113. package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
  114. package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
  115. package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
  116. package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
  117. package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
  118. package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
  119. package/pipeline/scripts/call-graph/lex.mjs +396 -0
  120. package/pipeline/scripts/call-graph/platform.mjs +86 -0
  121. package/pipeline/scripts/call-graph/profiles.mjs +89 -0
  122. package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
  123. package/pipeline/scripts/call-graph/scan.mjs +267 -0
  124. package/pipeline/scripts/code-graph-rules/android.json +7 -2
  125. package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
  126. package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
  127. package/pipeline/scripts/code-graph-rules/go.json +2 -1
  128. package/pipeline/scripts/code-graph-rules/ios.json +3 -1
  129. package/pipeline/scripts/code-graph-rules/java.json +76 -0
  130. package/pipeline/scripts/code-graph-rules/node.json +7 -2
  131. package/pipeline/scripts/code-graph-rules/python.json +6 -2
  132. package/pipeline/scripts/code-graph-rules/rust.json +105 -0
  133. package/pipeline/scripts/contract-server.mjs +1 -0
  134. package/pipeline/scripts/cost-table.json +6 -5
  135. package/pipeline/scripts/feedback-send.mjs +26 -26
  136. package/pipeline/scripts/gate-ledger.mjs +2 -1
  137. package/pipeline/scripts/gen-usage-names.mjs +124 -0
  138. package/pipeline/scripts/graph-affected.mjs +109 -20
  139. package/pipeline/scripts/graph-build.mjs +95 -15
  140. package/pipeline/scripts/graph-export.mjs +272 -0
  141. package/pipeline/scripts/graph-hint.mjs +15 -2
  142. package/pipeline/scripts/graph-query.mjs +305 -26
  143. package/pipeline/scripts/graph-report.mjs +187 -1
  144. package/pipeline/scripts/health-report.mjs +3 -4
  145. package/pipeline/scripts/infra/docs.mjs +317 -0
  146. package/pipeline/scripts/infra/extract.mjs +998 -0
  147. package/pipeline/scripts/infra/graph.mjs +245 -0
  148. package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
  149. package/pipeline/scripts/job-launch.mjs +67 -2
  150. package/pipeline/scripts/learning-curve.mjs +288 -178
  151. package/pipeline/scripts/log-metric.sh +10 -1
  152. package/pipeline/scripts/note-agent-event.mjs +3 -4
  153. package/pipeline/scripts/note-command-use.mjs +333 -0
  154. package/pipeline/scripts/note-command-use.sh +126 -0
  155. package/pipeline/scripts/note-mcp-call.sh +89 -0
  156. package/pipeline/scripts/note-mcp-failure.mjs +272 -1
  157. package/pipeline/scripts/note-session.sh +62 -3
  158. package/pipeline/scripts/note-skill-use.mjs +58 -2
  159. package/pipeline/scripts/office-build.mjs +115 -1
  160. package/pipeline/scripts/office-memory.mjs +14 -5
  161. package/pipeline/scripts/pair.mjs +333 -0
  162. package/pipeline/scripts/pre-push-check.sh +1 -1
  163. package/pipeline/scripts/remote/cbor.mjs +128 -0
  164. package/pipeline/scripts/remote/contract.mjs +98 -0
  165. package/pipeline/scripts/remote/handler.mjs +317 -0
  166. package/pipeline/scripts/remote/handles.mjs +57 -0
  167. package/pipeline/scripts/remote/lifecycle.mjs +186 -0
  168. package/pipeline/scripts/remote/listener.mjs +204 -0
  169. package/pipeline/scripts/remote/lockout.mjs +103 -0
  170. package/pipeline/scripts/remote/nonces.mjs +61 -0
  171. package/pipeline/scripts/remote/pairing.mjs +519 -0
  172. package/pipeline/scripts/remote/qr-encode.mjs +459 -0
  173. package/pipeline/scripts/remote/store.mjs +188 -0
  174. package/pipeline/scripts/remote/transport.mjs +211 -0
  175. package/pipeline/scripts/remote/verbs.json +70 -0
  176. package/pipeline/scripts/remote/verbs.mjs +217 -0
  177. package/pipeline/scripts/remote/webauthn.mjs +169 -0
  178. package/pipeline/scripts/remote/wire.mjs +364 -0
  179. package/pipeline/scripts/remote-listener.mjs +83 -0
  180. package/pipeline/scripts/route-learn.mjs +4 -4
  181. package/pipeline/scripts/run-kill.mjs +1 -1
  182. package/pipeline/scripts/run-write.mjs +13 -2
  183. package/pipeline/scripts/runs-index.mjs +30 -3
  184. package/pipeline/scripts/search-logs.sh +9 -0
  185. package/pipeline/scripts/session-brief.mjs +458 -0
  186. package/pipeline/scripts/session-brief.sh +130 -0
  187. package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
  188. package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
  189. package/pipeline/scripts/test-gap-rules/java.json +20 -0
  190. package/pipeline/scripts/test-gap-rules/rust.json +14 -0
  191. package/pipeline/scripts/token-budget-report.mjs +3 -2
  192. package/pipeline/scripts/uninstall.mjs +29 -0
  193. package/pipeline/scripts/usage-access.mjs +16 -31
  194. package/pipeline/scripts/usage-health.mjs +31 -62
  195. package/pipeline/scripts/usage-register-beacon.mjs +11 -22
  196. package/pipeline/scripts/usage-register.mjs +39 -29
  197. package/pipeline/scripts/usage-report.mjs +579 -178
  198. package/pipeline/scripts/validate-code-graph.mjs +361 -111
  199. package/pipeline/scripts/write-state.mjs +39 -0
  200. package/pipeline/skills/.skill-manifest.json +22 -18
  201. package/pipeline/skills/.skills-index.json +13 -2
  202. package/pipeline/skills/shared/README.md +5 -4
  203. package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
  204. package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
  205. package/pipeline/skills/shared/core/multi-agent-fable-status/SKILL.md +1 -1
  206. package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
  207. package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
  208. package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
  209. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
  210. package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
  211. package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
  212. package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
  213. package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
  214. package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
  215. package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
  216. package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
  217. package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
  218. package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
  219. package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
  220. package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
  221. package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
  222. package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
  223. package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
  224. package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
  225. package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
  226. package/pipeline/skills/skills-index.md +3 -2
  227. package/docs/FIGMA_PIPELINE.md +0 -137
  228. package/pipeline/lib/identifier-scan.mjs +0 -156
  229. package/pipeline/scripts/publish-staged.mjs +0 -324
  230. package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
@@ -108,6 +108,8 @@ export function summarize(graph, top) {
108
108
  referenceKinds = null;
109
109
  }
110
110
  const unreferenced = referenceKinds ? unreferencedSymbols(graph, referenceKinds) : null;
111
+ const callHubs = callSummary(graph, top);
112
+ const config = configSummary(graph, top);
111
113
 
112
114
  return {
113
115
  hubs,
@@ -118,6 +120,111 @@ export function summarize(graph, top) {
118
120
  fileCount: files.length,
119
121
  referenceKinds,
120
122
  unreferenced,
123
+ callHubs,
124
+ config,
125
+ };
126
+ }
127
+
128
+ const CALLABLE_ANY = new Set(["method", "function", "func", "fun", "def", "fn"]);
129
+ const ENTRY_NAMES = new Set(["main", "init", "constructor", "body", "deinit", "setUp", "tearDown"]);
130
+
131
+ /**
132
+ * Functions ranked by how many other functions call them, and functions nothing
133
+ * calls.
134
+ *
135
+ * The first list is the call-graph hotspot view: fan-in beside the span of the
136
+ * function in lines, which stands in for how much code a change to it touches.
137
+ * The second is a list of candidates, not verdicts: a name shared with another
138
+ * declaration is left out, because an override, an interface implementation and
139
+ * a callback look exactly like an unused function from here, and so does an
140
+ * entry point.
141
+ *
142
+ * @param {object} graph
143
+ * @param {number} top
144
+ * @returns {{hubs: object[], uncalled: object[], edges: number, lowShare: number}|null}
145
+ * null when the graph has no call edges
146
+ */
147
+ export function callSummary(graph, top) {
148
+ const calls = graph.edges.filter((e) => e.kind === "calls");
149
+ if (calls.length === 0) return null;
150
+ const byId = new Map(graph.nodes.map((n) => [n.id, n]));
151
+ const callers = new Map();
152
+ const highCallers = new Map();
153
+ for (const e of calls) {
154
+ const from = byId.get(e.from);
155
+ if (!from || from.kind !== "symbol") continue;
156
+ if (e.confidence === "low") continue;
157
+ if (!callers.has(e.to)) callers.set(e.to, new Set());
158
+ callers.get(e.to).add(e.from);
159
+ if (e.confidence === "high") {
160
+ if (!highCallers.has(e.to)) highCallers.set(e.to, new Set());
161
+ highCallers.get(e.to).add(e.from);
162
+ }
163
+ }
164
+ const rows = [];
165
+ for (const [id, from] of callers) {
166
+ const n = byId.get(id);
167
+ if (!n || n.kind !== "symbol" || n.isTest || !CALLABLE_ANY.has(n.symbolKind)) continue;
168
+ const lines = n.endLine && n.line ? n.endLine - n.line + 1 : 1;
169
+ rows.push({ node: n, callers: from.size, high: highCallers.get(id)?.size || 0, lines });
170
+ }
171
+ rows.sort((a, b) => b.callers - a.callers || b.lines - a.lines);
172
+ const nameCount = new Map();
173
+ for (const n of graph.nodes) {
174
+ if (n.kind === "symbol" && CALLABLE_ANY.has(n.symbolKind)) {
175
+ nameCount.set(n.name, (nameCount.get(n.name) || 0) + 1);
176
+ }
177
+ }
178
+ const called = new Set(calls.map((e) => e.to));
179
+ const uncalled = graph.nodes.filter(
180
+ (n) =>
181
+ n.kind === "symbol" &&
182
+ CALLABLE_ANY.has(n.symbolKind) &&
183
+ !n.isTest &&
184
+ !called.has(n.id) &&
185
+ !ENTRY_NAMES.has(n.name) &&
186
+ nameCount.get(n.name) === 1,
187
+ );
188
+ const low = calls.filter((e) => e.confidence === "low").length;
189
+ return {
190
+ lowEdges: low,
191
+ hubs: rows.slice(0, top),
192
+ uncalled: uncalled.slice(0, top * 4),
193
+ uncalledTotal: uncalled.length,
194
+ edges: calls.length,
195
+ lowShare: low / calls.length,
196
+ };
197
+ }
198
+
199
+ /**
200
+ * Environment variables and configuration keys read by code or set by
201
+ * infrastructure.
202
+ *
203
+ * @param {object} graph
204
+ * @param {number} top
205
+ * @returns {{infra: number, env: number, config: number, readNotSet: string[], setNotRead: string[]}|null}
206
+ * null when the graph has no infrastructure facts
207
+ */
208
+ export function configSummary(graph, top) {
209
+ const env = graph.nodes.filter((n) => n.kind === "env");
210
+ const infra = graph.nodes.filter((n) => n.kind === "infra");
211
+ const config = graph.nodes.filter((n) => n.kind === "config");
212
+ if (!env.length && !infra.length && !config.length) return null;
213
+ const readBy = new Set();
214
+ const setBy = new Set();
215
+ for (const e of graph.edges) {
216
+ if (e.kind === "reads") readBy.add(e.to);
217
+ if (e.kind === "sets" || (e.kind === "defines" && e.to.startsWith("env:"))) setBy.add(e.to);
218
+ }
219
+ const sorted = (list) => list.map((n) => n.name).sort();
220
+ return {
221
+ infra: infra.length,
222
+ env: env.length,
223
+ config: config.length,
224
+ readNotSet: sorted(env.filter((n) => readBy.has(n.id) && !setBy.has(n.id))).slice(0, top * 4),
225
+ readNotSetTotal: env.filter((n) => readBy.has(n.id) && !setBy.has(n.id)).length,
226
+ setNotRead: sorted(env.filter((n) => setBy.has(n.id) && !readBy.has(n.id))).slice(0, top * 4),
227
+ setNotReadTotal: env.filter((n) => setBy.has(n.id) && !readBy.has(n.id)).length,
121
228
  };
122
229
  }
123
230
 
@@ -219,6 +326,9 @@ export function render(graph, top) {
219
326
  L.push(
220
327
  `- Scale: ${graph.stats.files} files, ${graph.stats.nodes} nodes, ${graph.stats.edges} edges`,
221
328
  );
329
+ for (const [name, st] of Object.entries(graph.sidecars || {})) {
330
+ L.push(`- Layer ${name}: ${st.state}${st.reason ? ` (${st.reason})` : ""}`);
331
+ }
222
332
  L.push("");
223
333
 
224
334
  L.push(`## Architectural hubs`);
@@ -297,6 +407,78 @@ export function render(graph, top) {
297
407
  L.push("");
298
408
  }
299
409
 
410
+ if (s.callHubs) {
411
+ const c = s.callHubs;
412
+ L.push(`## Most-called functions`);
413
+ L.push("");
414
+ L.push(
415
+ `${c.edges} call edges, ${(c.lowShare * 100).toFixed(0)}% of them low confidence (an ` +
416
+ `unresolved binding: often right in script-style code, a lead anywhere else). Fan-in ` +
417
+ `counts the distinct functions that call the target through edges of medium confidence ` +
418
+ `or better; the ${c.lowEdges} low edges are not counted. Lines is the target's span.`,
419
+ );
420
+ L.push("");
421
+ L.push(`| Function | Callers | of them high | Lines | Path |`);
422
+ L.push(`|---|---|---|---|---|`);
423
+ for (const r of c.hubs) {
424
+ const owner = r.node.owner ? `${r.node.owner}.` : "";
425
+ L.push(
426
+ `| \`${owner}${r.node.name}\` | ${r.callers} | ${r.high} | ${r.lines} | \`${r.node.path}:${r.node.line || 1}\` |`,
427
+ );
428
+ }
429
+ L.push("");
430
+ L.push(`## Functions nothing calls`);
431
+ L.push("");
432
+ L.push(
433
+ `Candidates, not verdicts: ${c.uncalledTotal} functions with no incoming call edge, ` +
434
+ `leaving out entry points and any name declared more than once (overrides, interface ` +
435
+ `implementations and callbacks look unused from here). The call resolver misses calls ` +
436
+ `through function values, callbacks stored in collections, registries and dynamic ` +
437
+ `lookup, and a function it cannot match by argument count, so a function listed here ` +
438
+ `may well be called.`,
439
+ );
440
+ L.push("");
441
+ for (const n of c.uncalled.slice(0, top)) {
442
+ const owner = n.owner ? `${n.owner}.` : "";
443
+ L.push(`- \`${owner}${n.name}\` - \`${n.path}:${n.line || 1}\``);
444
+ }
445
+ if (c.uncalledTotal > top) L.push(`- ... ${c.uncalledTotal - top} more`);
446
+ L.push("");
447
+ }
448
+
449
+ if (s.config) {
450
+ const k = s.config;
451
+ L.push(`## Configuration`);
452
+ L.push("");
453
+ L.push(
454
+ `${k.infra} infrastructure nodes, ${k.env} environment variables, ${k.config} configuration keys. ` +
455
+ `Names only; no value is stored.`,
456
+ );
457
+ L.push("");
458
+ if (k.readNotSetTotal) {
459
+ L.push(
460
+ `Read by code and set by no file in this repo (${k.readNotSetTotal}): ` +
461
+ k.readNotSet
462
+ .slice(0, top)
463
+ .map((n) => `\`${n}\``)
464
+ .join(", ") +
465
+ (k.readNotSetTotal > top ? ", ..." : ""),
466
+ );
467
+ L.push("");
468
+ }
469
+ if (k.setNotReadTotal) {
470
+ L.push(
471
+ `Set by infrastructure and read by no code here (${k.setNotReadTotal}): ` +
472
+ k.setNotRead
473
+ .slice(0, top)
474
+ .map((n) => `\`${n}\``)
475
+ .join(", ") +
476
+ (k.setNotReadTotal > top ? ", ..." : ""),
477
+ );
478
+ L.push("");
479
+ }
480
+ }
481
+
300
482
  L.push(`## Modules`);
301
483
  L.push("");
302
484
  L.push(`| Module | Files | Symbols | Test files |`);
@@ -426,9 +608,13 @@ export function statusLine(graph, path) {
426
608
  } else if (!graph.baseCommit) {
427
609
  freshness = "freshness unknown (graph carries no baseCommit)";
428
610
  }
611
+ const layers = Object.entries(graph.sidecars || {})
612
+ .map(([name, st]) => `${name} ${st.state}${st.truncated ? " truncated" : ""}`)
613
+ .join(", ");
429
614
  return (
430
615
  `graph-status: ${graph.stack} | ${graph.stats.files} files, ${graph.stats.nodes} nodes, ` +
431
- `${graph.stats.edges} edges | built ${graph.generatedAt} | ${freshness} | ${path}`
616
+ `${graph.stats.edges} edges | built ${graph.generatedAt} | ${freshness} | ${path}` +
617
+ (layers ? ` | layers: ${layers}` : "")
432
618
  );
433
619
  }
434
620
 
@@ -58,6 +58,7 @@ import { invokedDirectly } from "../lib/invoked-directly.mjs";
58
58
  import { startOfLocalDay, usageSince } from "../lib/session-usage.mjs";
59
59
  import { outputLanguage } from "../lib/user-facing.mjs";
60
60
  import { spawnAsync } from "./_spawn-async.mjs";
61
+ import { readRotatedText, rotatedExists } from "../lib/rotated-log.mjs";
61
62
  import { prefsPath as sharedPrefsPath } from "../lib/prefs-value.mjs";
62
63
  import { exitOnHelp } from "../lib/cli-help.mjs";
63
64
  import { parseArgs as parseArgv } from "../lib/args.mjs";
@@ -622,12 +623,10 @@ export function gateSection(stamp) {
622
623
  * counts once; a row without an id is a run of its own.
623
624
  */
624
625
  export function errorsSection(path, now = Date.now()) {
625
- let text;
626
- try {
627
- text = readFileSync(path, "utf8");
628
- } catch {
626
+ if (!rotatedExists(path)) {
629
627
  return result("green", msg("errors.noLedger"), { ledger: false, runs: 0, recurring: [] });
630
628
  }
629
+ const text = readRotatedText(path);
631
630
  const since = now - ERROR_WINDOW_MS;
632
631
  const runsByTag = new Map();
633
632
  const runIds = new Set();
@@ -0,0 +1,317 @@
1
+ /**
2
+ * @file docs.mjs - documentation sections and rationale comments as graph nodes.
3
+ *
4
+ * Two kinds of text explain code without being code:
5
+ *
6
+ * doc a section of a Markdown or AsciiDoc file (an Architecture
7
+ * Decision Record is a document whose first heading names the
8
+ * decision). Its `mentions` edges point at the files and
9
+ * symbols it names in backticks, and at the decision records it
10
+ * cites by number.
11
+ * rationale a code comment that states why: one that opens with NOTE, WHY,
12
+ * HACK, FIXME, XXX, RATIONALE or IMPORTANT, or cites ADR-12 or
13
+ * RFC 9110. Its `explains` edge points at the innermost
14
+ * declaration around it, or at the file.
15
+ *
16
+ * Only a bounded amount is kept, and only text a reader would put in a heading
17
+ * or a one-line comment: nothing is stored past MAX_NAME characters.
18
+ *
19
+ * @module pipeline/scripts/infra/docs
20
+ */
21
+
22
+ export const MAX_DOC_BYTES = 300 * 1024;
23
+ export const MAX_SECTIONS_PER_DOC = 200;
24
+ export const MAX_RATIONALE_PER_FILE = 30;
25
+ export const MAX_RATIONALE_TOTAL = 5000;
26
+ const MAX_NAME = 90;
27
+ const MAX_COMMENT_LINE = 400;
28
+ const MAX_MENTIONS_PER_SECTION = 40;
29
+
30
+ const DOC_EXT = /\.(md|mdx|markdown|adoc|asciidoc)$/i;
31
+
32
+ /** Is this a documentation file the graph reads? */
33
+ export const isDocPath = (path) => DOC_EXT.test(path);
34
+
35
+ const slug = (text) =>
36
+ text
37
+ .toLowerCase()
38
+ .replace(/[^a-z0-9]+/g, "-")
39
+ .replace(/^-|-$/g, "")
40
+ .slice(0, 60);
41
+
42
+ const clip = (text) => text.replace(/\s+/g, " ").trim().slice(0, MAX_NAME);
43
+
44
+ const MAX_LINE = 2000;
45
+
46
+ /**
47
+ * The title of a Markdown (`## Title ##`) or AsciiDoc (`== Title`) heading line,
48
+ * or null. Read by hand, one pass over a line cut to MAX_LINE characters: a
49
+ * pattern with two open-ended parts around optional whitespace is cubic on a
50
+ * line of spaces.
51
+ */
52
+ function headingOf(line) {
53
+ const text = line.length > MAX_LINE ? line.slice(0, MAX_LINE) : line;
54
+ const mark = text[0];
55
+ if (mark !== "#" && mark !== "=") return null;
56
+ let i = 0;
57
+ while (i < text.length && text[i] === mark) i++;
58
+ if (i > 4 || (text[i] !== " " && text[i] !== "\t")) return null;
59
+ let end = text.length;
60
+ while (end > i && /\s/.test(text[end - 1])) end--;
61
+ if (mark === "#") {
62
+ let k = end;
63
+ while (k > i && text[k - 1] === "#") k--;
64
+ if (k < end && k > i && /\s/.test(text[k - 1])) {
65
+ end = k;
66
+ while (end > i && /\s/.test(text[end - 1])) end--;
67
+ }
68
+ }
69
+ const title = text.slice(i, end).trim();
70
+ return title.length ? title : null;
71
+ }
72
+
73
+ /** The ADR number in a decision-record path such as docs/adr/0010-title.md, or null. */
74
+ export function adrNumber(path) {
75
+ const m = path.match(/(?:^|\/)(?:adr|adrs|decisions?)\/(?:adr-?)?0*(\d{1,5})[-_.]/i);
76
+ return m ? m[1] : null;
77
+ }
78
+
79
+ /**
80
+ * Sections of a documentation file and what each one mentions.
81
+ *
82
+ * @param {string} path
83
+ * @param {string} text
84
+ * @returns {{nodes: Array, edges: Array}}
85
+ */
86
+ export function docFacts(path, text) {
87
+ const out = { nodes: [], edges: [] };
88
+ if (text.length > MAX_DOC_BYTES || text.includes("\0")) return out;
89
+ const lines = text.split(/\r?\n/);
90
+ const adr = adrNumber(path);
91
+ let current = null;
92
+ let fence = false;
93
+ let mentions = new Set();
94
+ const close = () => {
95
+ if (!current) return;
96
+ for (const m of mentions)
97
+ out.edges.push({
98
+ from: current,
99
+ to: m,
100
+ kind: "mentions",
101
+ via: "backtick",
102
+ confidence: "medium",
103
+ });
104
+ mentions = new Set();
105
+ };
106
+ for (let i = 0; i < lines.length && out.nodes.length < MAX_SECTIONS_PER_DOC; i++) {
107
+ const line = lines[i];
108
+ if (/^\s*(```|~~~)/.test(line)) {
109
+ fence = !fence;
110
+ continue;
111
+ }
112
+ const heading = fence ? null : headingOf(line);
113
+ if (heading) {
114
+ close();
115
+ const name = clip(heading.replace(/[`*_]/g, ""));
116
+ const id = `doc:${path}#${slug(name) || i + 1}-${i + 1}`;
117
+ out.nodes.push({
118
+ id,
119
+ kind: "doc",
120
+ name,
121
+ sk: adr && out.nodes.length === 0 ? "adr" : "section",
122
+ line: i + 1,
123
+ });
124
+ current = id;
125
+ if (out.nodes.length === 1)
126
+ out.edges.push({
127
+ from: `file:${path}`,
128
+ to: id,
129
+ kind: "defines",
130
+ via: "declaration",
131
+ confidence: "certain",
132
+ });
133
+ else
134
+ out.edges.push({
135
+ from: out.nodes[0].id,
136
+ to: id,
137
+ kind: "defines",
138
+ via: "declaration",
139
+ confidence: "certain",
140
+ });
141
+ continue;
142
+ }
143
+ if (!current || fence || line.length > MAX_LINE) continue;
144
+ for (const m of line.matchAll(/`([^`\n]{2,120})`/g)) {
145
+ if (mentions.size >= MAX_MENTIONS_PER_SECTION) break;
146
+ const token = m[1].trim();
147
+ if (/^[\w./-]+\.[A-Za-z0-9]{1,6}$/.test(token) && token.includes("/"))
148
+ mentions.add(`path:${token.replace(/^\.\//, "")}`);
149
+ else if (/^[A-Za-z_][\w]*(?:\.[A-Za-z_]\w*)?(?:\(\))?$/.test(token))
150
+ mentions.add(`name:${token.replace(/\(\)$/, "")}`);
151
+ }
152
+ for (const m of line.matchAll(
153
+ /\b(?:ADR|ADR-|decision record)\s{0,3}[-#]?\s{0,3}0{0,8}(\d{1,5})\b/gi,
154
+ )) {
155
+ if (mentions.size < MAX_MENTIONS_PER_SECTION) mentions.add(`adr:${m[1]}`);
156
+ }
157
+ }
158
+ close();
159
+ return out;
160
+ }
161
+
162
+ const MARKERS =
163
+ /(?:\/\/{1,4}|#{1,4}|--|\/\*{1,4}|\*|;;)\s{0,8}(NOTE|WHY|HACK|FIXME|XXX|RATIONALE|IMPORTANT)\b[:\s-]{0,12}(.{0,200})/;
164
+ const CITATION = /\b(?:ADR|RFC)[-\s]?0{0,8}(\d{1,5})\b/g;
165
+
166
+ /**
167
+ * Rationale comments in a source file.
168
+ *
169
+ * @param {string} text - raw source, comments included
170
+ * @returns {Array<{line: number, name: string, adrs: string[]}>}
171
+ */
172
+ export function rationaleComments(text) {
173
+ const found = [];
174
+ if (!/NOTE|WHY|HACK|FIXME|XXX|RATIONALE|IMPORTANT|ADR|RFC/.test(text)) return found;
175
+ const lines = text.split("\n");
176
+ for (let i = 0; i < lines.length && found.length < MAX_RATIONALE_PER_FILE; i++) {
177
+ const line = lines[i];
178
+ if (line.length > MAX_COMMENT_LINE) continue;
179
+ const m = line.match(MARKERS);
180
+ const cited = /(?:\/\/|#|--|\/\*|\*)/.test(line)
181
+ ? [...line.matchAll(CITATION)].map((x) => x[1])
182
+ : [];
183
+ if (!m && cited.length === 0) continue;
184
+ found.push({
185
+ line: i + 1,
186
+ name: clip(m ? `${m[1]}: ${m[2]}` : line.replace(/^[\s/*#-]+/, "")),
187
+ adrs: cited,
188
+ });
189
+ }
190
+ return found;
191
+ }
192
+
193
+ /**
194
+ * Put documentation and rationale into the graph.
195
+ *
196
+ * @param {object} params
197
+ * @param {Map<string, object>} params.nodes - graph nodes, mutated
198
+ * @param {Array} params.edges - graph edges, mutated
199
+ * @param {Map<string, {nodes: Array, edges: Array}>} params.docs - docFacts per file
200
+ * @param {Map<string, Array>} params.rationale - rationaleComments per source file
201
+ * @returns {{docs: number, rationale: number}}
202
+ */
203
+ export function addDocs({ nodes, edges, docs, rationale }) {
204
+ const stats = { docs: 0, rationale: 0 };
205
+ const byName = new Map();
206
+ const spans = new Map();
207
+ for (const n of nodes.values()) {
208
+ if (n.kind !== "symbol") continue;
209
+ if (n.nested !== true) {
210
+ if (!byName.has(n.name)) byName.set(n.name, []);
211
+ byName.get(n.name).push(n.id);
212
+ }
213
+ if (n.path && n.line) addSpan(spans, n);
214
+ }
215
+ const adrDocs = new Map();
216
+ for (const [path, f] of docs) {
217
+ const num = adrNumber(path);
218
+ if (num && f.nodes[0]) adrDocs.set(num, f.nodes[0].id);
219
+ }
220
+ const seen = new Set();
221
+ const push = (from, to, kind, via, confidence) => {
222
+ const key = `${from}\0${to}\0${kind}`;
223
+ if (seen.has(key) || from === to) return;
224
+ seen.add(key);
225
+ edges.push({ from, to, kind, ...(via ? { via, confidence } : {}) });
226
+ };
227
+ const resolve = (ref) => {
228
+ if (ref.startsWith("path:")) {
229
+ const id = `file:${ref.slice(5)}`;
230
+ return nodes.has(id) ? id : null;
231
+ }
232
+ if (ref.startsWith("adr:")) return adrDocs.get(String(Number(ref.slice(4)))) || null;
233
+ if (ref.startsWith("name:")) {
234
+ const name = ref.slice(5);
235
+ const cands = byName.get(name.includes(".") ? name.split(".").pop() : name);
236
+ return cands && cands.length === 1 ? cands[0] : null;
237
+ }
238
+ return ref;
239
+ };
240
+
241
+ for (const [path, f] of docs) {
242
+ if (!nodes.has(`file:${path}`)) {
243
+ nodes.set(`file:${path}`, {
244
+ id: `file:${path}`,
245
+ kind: "file",
246
+ name: path.split("/").pop(),
247
+ path,
248
+ isTest: false,
249
+ degree: 0,
250
+ });
251
+ }
252
+ for (const n of f.nodes) {
253
+ nodes.set(n.id, {
254
+ id: n.id,
255
+ kind: "doc",
256
+ name: n.name,
257
+ path,
258
+ line: n.line,
259
+ symbolKind: n.sk,
260
+ degree: 0,
261
+ });
262
+ stats.docs++;
263
+ }
264
+ for (const e of f.edges) {
265
+ const to = resolve(e.to);
266
+ if (to && nodes.has(e.from) && nodes.has(to))
267
+ push(e.from, to, e.kind, e.kind === "defines" ? null : e.via, e.confidence);
268
+ }
269
+ }
270
+
271
+ let total = 0;
272
+ for (const [path, list] of rationale) {
273
+ const fid = `file:${path}`;
274
+ if (!nodes.has(fid)) continue;
275
+ for (const r of list) {
276
+ if (total++ >= MAX_RATIONALE_TOTAL) return stats;
277
+ const id = `rationale:${path}#${r.line}`;
278
+ nodes.set(id, {
279
+ id,
280
+ kind: "rationale",
281
+ name: r.name,
282
+ path,
283
+ line: r.line,
284
+ symbolKind: "rationale",
285
+ degree: 0,
286
+ });
287
+ stats.rationale++;
288
+ const around = innermost(spans.get(path) || [], r.line);
289
+ push(
290
+ id,
291
+ around ? around.id : fid,
292
+ "explains",
293
+ around ? "enclosing-declaration" : "file",
294
+ "high",
295
+ );
296
+ for (const num of r.adrs) {
297
+ const doc = adrDocs.get(String(Number(num)));
298
+ if (doc) push(id, doc, "mentions", "adr-citation", "high");
299
+ }
300
+ }
301
+ }
302
+ return stats;
303
+ }
304
+
305
+ function addSpan(spans, n) {
306
+ if (!spans.has(n.path)) spans.set(n.path, []);
307
+ spans.get(n.path).push({ id: n.id, from: n.startLine || n.line, to: n.endLine || n.line });
308
+ }
309
+
310
+ function innermost(list, line) {
311
+ let best = null;
312
+ for (const s of list) {
313
+ if (line < s.from || line > s.to) continue;
314
+ if (!best || s.to - s.from < best.to - best.from) best = s;
315
+ }
316
+ return best;
317
+ }