@mmerterden/multi-agent-pipeline 23.3.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 (224) hide show
  1. package/CHANGELOG.md +44 -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 +5 -5
  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 +223 -155
  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/graph/SKILL.md +57 -24
  21. package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
  22. package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
  23. package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
  24. package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
  25. package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
  26. package/pipeline/contract/CHANGELOG.md +49 -0
  27. package/pipeline/contract/build.mjs +13 -1
  28. package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
  29. package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
  30. package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
  31. package/pipeline/contract/fixtures/runs-empty.json +1 -1
  32. package/pipeline/contract/fixtures/runs-failed.json +4 -1
  33. package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
  34. package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
  35. package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
  36. package/pipeline/contract/fixtures/runs-running.json +4 -1
  37. package/pipeline/contract/manifest.json +28 -15
  38. package/pipeline/contract/types/index.d.ts +55 -3
  39. package/pipeline/lib/detach-self.mjs +95 -0
  40. package/pipeline/lib/public-mcp-servers.mjs +33 -0
  41. package/pipeline/lib/rotated-log.mjs +93 -0
  42. package/pipeline/lib/tls-trust.mjs +29 -0
  43. package/pipeline/lib/usage-lifecycle.mjs +9 -11
  44. package/pipeline/lib/usage-names.generated.mjs +614 -0
  45. package/pipeline/lib/usage-run-key.mjs +235 -0
  46. package/pipeline/lib/usage-vocab.mjs +210 -0
  47. package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
  48. package/pipeline/multi-agent-refs/analysis/render.md +1 -1
  49. package/pipeline/multi-agent-refs/channels/generator.md +4 -5
  50. package/pipeline/multi-agent-refs/cross-cli-contract.md +3 -3
  51. package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
  52. package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
  53. package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
  54. package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
  55. package/pipeline/multi-agent-refs/features/model-fallback.md +6 -4
  56. package/pipeline/multi-agent-refs/features/remote-control.md +252 -0
  57. package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
  58. package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
  59. package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
  60. package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
  61. package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
  62. package/pipeline/multi-agent-refs/features/usage-reporting.md +252 -24
  63. package/pipeline/multi-agent-refs/help/en.md +3 -2
  64. package/pipeline/multi-agent-refs/help/tr.md +3 -2
  65. package/pipeline/multi-agent-refs/knowledge.md +1 -1
  66. package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +1 -1
  67. package/pipeline/multi-agent-refs/phases/operations.md +2 -2
  68. package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
  69. package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
  70. package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -0
  71. package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
  72. package/pipeline/multi-agent-refs/platform-parity.md +2 -2
  73. package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
  74. package/pipeline/office/index.html +1207 -233
  75. package/pipeline/office/toolkit.json +1 -1
  76. package/pipeline/rules/outside-the-pipeline.md +1 -1
  77. package/pipeline/schemas/activity.schema.json +23 -0
  78. package/pipeline/schemas/agent-state.schema.json +6 -1
  79. package/pipeline/schemas/code-graph-calls.schema.json +254 -0
  80. package/pipeline/schemas/code-graph-docs.schema.json +223 -0
  81. package/pipeline/schemas/code-graph-infra.schema.json +227 -0
  82. package/pipeline/schemas/code-graph.schema.json +2 -2
  83. package/pipeline/schemas/examples/design-check-config.json +27 -0
  84. package/pipeline/schemas/learning-curve.schema.json +67 -0
  85. package/pipeline/schemas/office-jobs.json +69 -2
  86. package/pipeline/schemas/office-jobs.schema.json +8 -1
  87. package/pipeline/schemas/phases.json +5 -0
  88. package/pipeline/schemas/phases.schema.json +8 -0
  89. package/pipeline/schemas/prefs.schema.json +46 -12
  90. package/pipeline/schemas/runs-index.schema.json +17 -0
  91. package/pipeline/schemas/toolkit-path-params.json +84 -8
  92. package/pipeline/scripts/README.md +1 -0
  93. package/pipeline/scripts/_code-graph.mjs +184 -103
  94. package/pipeline/scripts/_contract-core.mjs +1 -1
  95. package/pipeline/scripts/_contract-routes-office.mjs +21 -0
  96. package/pipeline/scripts/_diff-impact.mjs +21 -2
  97. package/pipeline/scripts/_graph-sidecars.mjs +372 -0
  98. package/pipeline/scripts/_http-post.mjs +103 -115
  99. package/pipeline/scripts/_safe-read.mjs +57 -0
  100. package/pipeline/scripts/_skill-practices.mjs +26 -0
  101. package/pipeline/scripts/_strip-code.mjs +380 -0
  102. package/pipeline/scripts/activity-snapshot.mjs +13 -1
  103. package/pipeline/scripts/aggregate-metrics.mjs +3 -5
  104. package/pipeline/scripts/call-graph/index.mjs +78 -0
  105. package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
  106. package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
  107. package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
  108. package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
  109. package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
  110. package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
  111. package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
  112. package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
  113. package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
  114. package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
  115. package/pipeline/scripts/call-graph/lex.mjs +396 -0
  116. package/pipeline/scripts/call-graph/platform.mjs +86 -0
  117. package/pipeline/scripts/call-graph/profiles.mjs +89 -0
  118. package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
  119. package/pipeline/scripts/call-graph/scan.mjs +267 -0
  120. package/pipeline/scripts/code-graph-rules/android.json +7 -2
  121. package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
  122. package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
  123. package/pipeline/scripts/code-graph-rules/go.json +2 -1
  124. package/pipeline/scripts/code-graph-rules/ios.json +3 -1
  125. package/pipeline/scripts/code-graph-rules/java.json +76 -0
  126. package/pipeline/scripts/code-graph-rules/node.json +7 -2
  127. package/pipeline/scripts/code-graph-rules/python.json +6 -2
  128. package/pipeline/scripts/code-graph-rules/rust.json +105 -0
  129. package/pipeline/scripts/contract-server.mjs +1 -0
  130. package/pipeline/scripts/feedback-send.mjs +26 -26
  131. package/pipeline/scripts/gate-ledger.mjs +2 -1
  132. package/pipeline/scripts/gen-usage-names.mjs +124 -0
  133. package/pipeline/scripts/graph-affected.mjs +109 -20
  134. package/pipeline/scripts/graph-build.mjs +95 -15
  135. package/pipeline/scripts/graph-export.mjs +272 -0
  136. package/pipeline/scripts/graph-hint.mjs +15 -2
  137. package/pipeline/scripts/graph-query.mjs +305 -26
  138. package/pipeline/scripts/graph-report.mjs +187 -1
  139. package/pipeline/scripts/health-report.mjs +3 -4
  140. package/pipeline/scripts/infra/docs.mjs +317 -0
  141. package/pipeline/scripts/infra/extract.mjs +998 -0
  142. package/pipeline/scripts/infra/graph.mjs +245 -0
  143. package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
  144. package/pipeline/scripts/job-launch.mjs +67 -2
  145. package/pipeline/scripts/learning-curve.mjs +288 -178
  146. package/pipeline/scripts/log-metric.sh +10 -1
  147. package/pipeline/scripts/note-agent-event.mjs +3 -4
  148. package/pipeline/scripts/note-command-use.mjs +333 -0
  149. package/pipeline/scripts/note-command-use.sh +126 -0
  150. package/pipeline/scripts/note-mcp-call.sh +89 -0
  151. package/pipeline/scripts/note-mcp-failure.mjs +272 -1
  152. package/pipeline/scripts/note-session.sh +62 -3
  153. package/pipeline/scripts/note-skill-use.mjs +58 -2
  154. package/pipeline/scripts/office-build.mjs +115 -1
  155. package/pipeline/scripts/office-memory.mjs +14 -5
  156. package/pipeline/scripts/pair.mjs +333 -0
  157. package/pipeline/scripts/pre-push-check.sh +1 -1
  158. package/pipeline/scripts/remote/cbor.mjs +128 -0
  159. package/pipeline/scripts/remote/contract.mjs +98 -0
  160. package/pipeline/scripts/remote/handler.mjs +317 -0
  161. package/pipeline/scripts/remote/handles.mjs +57 -0
  162. package/pipeline/scripts/remote/lifecycle.mjs +186 -0
  163. package/pipeline/scripts/remote/listener.mjs +204 -0
  164. package/pipeline/scripts/remote/lockout.mjs +103 -0
  165. package/pipeline/scripts/remote/nonces.mjs +61 -0
  166. package/pipeline/scripts/remote/pairing.mjs +519 -0
  167. package/pipeline/scripts/remote/qr-encode.mjs +459 -0
  168. package/pipeline/scripts/remote/store.mjs +188 -0
  169. package/pipeline/scripts/remote/transport.mjs +211 -0
  170. package/pipeline/scripts/remote/verbs.json +70 -0
  171. package/pipeline/scripts/remote/verbs.mjs +217 -0
  172. package/pipeline/scripts/remote/webauthn.mjs +169 -0
  173. package/pipeline/scripts/remote/wire.mjs +364 -0
  174. package/pipeline/scripts/remote-listener.mjs +83 -0
  175. package/pipeline/scripts/route-learn.mjs +4 -4
  176. package/pipeline/scripts/run-kill.mjs +1 -1
  177. package/pipeline/scripts/run-write.mjs +13 -2
  178. package/pipeline/scripts/runs-index.mjs +30 -3
  179. package/pipeline/scripts/search-logs.sh +9 -0
  180. package/pipeline/scripts/session-brief.mjs +458 -0
  181. package/pipeline/scripts/session-brief.sh +130 -0
  182. package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
  183. package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
  184. package/pipeline/scripts/test-gap-rules/java.json +20 -0
  185. package/pipeline/scripts/test-gap-rules/rust.json +14 -0
  186. package/pipeline/scripts/token-budget-report.mjs +3 -2
  187. package/pipeline/scripts/uninstall.mjs +29 -0
  188. package/pipeline/scripts/usage-access.mjs +16 -31
  189. package/pipeline/scripts/usage-health.mjs +31 -62
  190. package/pipeline/scripts/usage-register-beacon.mjs +11 -22
  191. package/pipeline/scripts/usage-register.mjs +39 -29
  192. package/pipeline/scripts/usage-report.mjs +579 -178
  193. package/pipeline/scripts/validate-code-graph.mjs +361 -111
  194. package/pipeline/scripts/write-state.mjs +39 -0
  195. package/pipeline/skills/.skill-manifest.json +21 -17
  196. package/pipeline/skills/.skills-index.json +13 -2
  197. package/pipeline/skills/shared/README.md +5 -4
  198. package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
  199. package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
  200. package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
  201. package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
  202. package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
  203. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
  204. package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
  205. package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
  206. package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
  207. package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
  208. package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
  209. package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
  210. package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
  211. package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
  212. package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
  213. package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
  214. package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
  215. package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
  216. package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
  217. package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
  218. package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
  219. package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
  220. package/pipeline/skills/skills-index.md +3 -2
  221. package/docs/FIGMA_PIPELINE.md +0 -137
  222. package/pipeline/lib/identifier-scan.mjs +0 -156
  223. package/pipeline/scripts/publish-staged.mjs +0 -324
  224. package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
@@ -92,6 +92,32 @@ function targets(text, fromRel) {
92
92
  return out;
93
93
  }
94
94
 
95
+ const ESCAPES = (path) => path === ".." || path.startsWith("../");
96
+
97
+ /**
98
+ * Markdown links (and backticked `../` paths) in SKILL.md or a companion that
99
+ * resolve outside the skill folder. A skill ships and is copied as its folder,
100
+ * so a path that leaves it points at nothing on the machine that installs it.
101
+ *
102
+ * @returns {{from: string, to: string}[]}
103
+ */
104
+ export function escapingLinks(skillDirPath) {
105
+ const out = [];
106
+ for (const rel of ["SKILL.md", ...companionMarkdown(skillDirPath)]) {
107
+ const text = readFileSync(join(skillDirPath, rel), "utf8");
108
+ const base = dirname(rel);
109
+ const raw = [
110
+ ...String(text).matchAll(LINK),
111
+ ...[...String(text).matchAll(TICKED)].filter((m) => m[1].startsWith("../")),
112
+ ];
113
+ for (const m of raw) {
114
+ const resolved = normalize(join(base, m[1])).split(sep).join("/");
115
+ if (ESCAPES(resolved)) out.push({ from: rel, to: m[1] });
116
+ }
117
+ }
118
+ return out;
119
+ }
120
+
95
121
  export function nestedReferences(skillDirPath) {
96
122
  const companions = companionMarkdown(skillDirPath);
97
123
  const known = new Set(companions);
@@ -0,0 +1,380 @@
1
+ /**
2
+ * @file _strip-code.mjs - blank comments and string literals, keep interpolated code.
3
+ *
4
+ * The code graph reads definitions, identifiers and calls from source with the
5
+ * text that is not code removed. A character scan does it, not a regex pass: a
6
+ * regex cannot tell a `//` inside a string from a comment, which is what makes
7
+ * reference edges noisy. Removed spans become spaces, so offsets and line
8
+ * numbers are preserved.
9
+ *
10
+ * What counts as a comment or a string comes from the stack's rule file
11
+ * (`comments`): line and block markers, quote tokens, and a `dialect` that turns
12
+ * on the literal forms of that language:
13
+ *
14
+ * js template literals, regular-expression literals
15
+ * swift nested block comments, `#"..."#` extended delimiters, `\(expr)`
16
+ * kotlin nested block comments, `"""` raw strings, `${expr}` templates
17
+ * rust nested block comments, `r#"..."#` raw strings, char literals
18
+ * cpp `R"x(...)x"` raw strings, char literals
19
+ * csharp `@"..."` verbatim and `$"..."` interpolated strings
20
+ * python `f"..."` strings with `{expr}` holes
21
+ * go backtick raw strings
22
+ *
23
+ * The code inside an interpolation hole is kept (comments, strings and regular
24
+ * expressions inside it are blanked in turn), because a call written there is a
25
+ * call. Work is linear: every character is visited once, holes nest to a fixed
26
+ * depth, and an unterminated literal ends at the end of the text.
27
+ *
28
+ * @module pipeline/scripts/_strip-code
29
+ */
30
+
31
+ const HOLE_DEPTH_MAX = 12;
32
+ const REGEX_LOOKAHEAD = 600;
33
+ // "<" is absent: a "/" after it closes a JSX tag (`</strong>`), and `a < /re/` is not written.
34
+ const REGEX_AFTER_CHARS = new Set([..."=(,:;!&|?{[+-*%>~^"]);
35
+ const REGEX_AFTER_WORDS = new Set([
36
+ "return",
37
+ "typeof",
38
+ "case",
39
+ "in",
40
+ "of",
41
+ "delete",
42
+ "void",
43
+ "yield",
44
+ "await",
45
+ "else",
46
+ "throw",
47
+ ]);
48
+
49
+ const isIdentChar = (c) => c !== undefined && /[A-Za-z0-9_$]/.test(c);
50
+
51
+ /** Can a `/` at index i start a regular-expression literal, judging by what precedes it? */
52
+ function regexMayStart(text, i) {
53
+ let k = i - 1;
54
+ while (k >= 0 && (text[k] === " " || text[k] === "\t" || text[k] === "\n" || text[k] === "\r"))
55
+ k--;
56
+ if (k < 0) return true;
57
+ if (REGEX_AFTER_CHARS.has(text[k])) return true;
58
+ if (!/[A-Za-z_$]/.test(text[k])) return false;
59
+ let w = k;
60
+ while (w > 0 && isIdentChar(text[w - 1])) w--;
61
+ return REGEX_AFTER_WORDS.has(text.slice(w, k + 1));
62
+ }
63
+
64
+ /** End (exclusive, flags included) of the regular-expression literal starting at i, or -1. */
65
+ function regexEnd(text, i) {
66
+ const limit = Math.min(text.length, i + REGEX_LOOKAHEAD);
67
+ let j = i + 1;
68
+ let inClass = false;
69
+ while (j < limit) {
70
+ const c = text[j];
71
+ if (c === "\n") return -1;
72
+ if (c === "\\") {
73
+ j += 2;
74
+ continue;
75
+ }
76
+ if (inClass) {
77
+ if (c === "]") inClass = false;
78
+ } else if (c === "[") inClass = true;
79
+ else if (c === "/") {
80
+ j++;
81
+ while (j < limit && /[dgimsuyv]/.test(text[j])) j++;
82
+ return j > i + 1 ? j : -1;
83
+ }
84
+ j++;
85
+ }
86
+ return -1;
87
+ }
88
+
89
+ /** Number of consecutive `ch` immediately before index i. */
90
+ function runBefore(text, i, ch) {
91
+ let k = 0;
92
+ while (i - k - 1 >= 0 && text[i - k - 1] === ch) k++;
93
+ return k;
94
+ }
95
+
96
+ /**
97
+ * How the literal that opens with `tok` at index i is written in this dialect.
98
+ *
99
+ * @returns {{from: number, body: number, close: (j: number) => number, esc: string|null,
100
+ * multiline: boolean, hole: ((j: number) => {len: number, closer: string}|null)|null,
101
+ * verbatim: boolean, pair?: string}}
102
+ */
103
+ function literalSpec(text, i, tok, dialect, depth) {
104
+ const single = (close, esc, multiline) => ({
105
+ from: i,
106
+ body: i + tok.length,
107
+ close: (j) => (text.startsWith(close, j) ? close.length : 0),
108
+ esc,
109
+ multiline,
110
+ hole: null,
111
+ verbatim: false,
112
+ });
113
+ const holeAt = (open, closer) => (j) =>
114
+ depth < HOLE_DEPTH_MAX && text.startsWith(open, j) ? { len: open.length, closer } : null;
115
+
116
+ if (dialect === "js") {
117
+ const s = single(tok, "\\", tok === "`");
118
+ if (tok === "`") s.hole = holeAt("${", "}");
119
+ return s;
120
+ }
121
+ if (dialect === "swift") {
122
+ const hashes = runBefore(text, i, "#");
123
+ const tail = "#".repeat(hashes);
124
+ const s = single(tok + tail, null, tok.length === 3);
125
+ s.from = i - hashes;
126
+ s.esc = `\\${tail}`;
127
+ s.hole = holeAt(`\\${tail}(`, ")");
128
+ return s;
129
+ }
130
+ if (dialect === "kotlin") {
131
+ const s = single(tok, tok.length === 3 ? null : "\\", tok.length === 3);
132
+ s.hole = holeAt("${", "}");
133
+ return s;
134
+ }
135
+ if (dialect === "rust" && tok === '"') {
136
+ const hashes = runBefore(text, i, "#");
137
+ const r = text[i - hashes - 1];
138
+ const before = text[i - hashes - 2];
139
+ if (r === "r" && !(isIdentChar(before) && before !== "b" && before !== "c")) {
140
+ const s = single(`"${"#".repeat(hashes)}`, null, true);
141
+ s.from = i - hashes - 1;
142
+ return s;
143
+ }
144
+ return single(tok, "\\", true);
145
+ }
146
+ if (dialect === "cpp" && tok === '"') {
147
+ let before = i - 2;
148
+ while (before >= 0 && before > i - 5 && "Lu8U".includes(text[before])) before--;
149
+ if (text[i - 1] === "R" && !isIdentChar(text[before])) {
150
+ const open = text.indexOf("(", i + 1);
151
+ if (open > 0 && open - i <= 17) {
152
+ const delim = text.slice(i + 1, open);
153
+ if (!/[\s)\\]/.test(delim)) {
154
+ const s = single(`)${delim}"`, null, true);
155
+ s.from = i - 1;
156
+ s.body = open + 1;
157
+ return s;
158
+ }
159
+ }
160
+ }
161
+ return single(tok, "\\", false);
162
+ }
163
+ if (dialect === "csharp" && tok === '"') {
164
+ const verbatim = text[i - 1] === "@" || (text[i - 1] === "$" && text[i - 2] === "@");
165
+ const interpolated = text[i - 1] === "$" || (text[i - 1] === "@" && text[i - 2] === "$");
166
+ const s = single(tok, verbatim ? null : "\\", verbatim);
167
+ s.from = i - (verbatim && interpolated ? 2 : verbatim || interpolated ? 1 : 0);
168
+ s.verbatim = verbatim;
169
+ if (verbatim) s.close = (j) => (text[j] === '"' && text[j + 1] !== '"' ? 1 : 0);
170
+ if (interpolated) {
171
+ s.pair = "{{";
172
+ s.hole = (j) => (depth < HOLE_DEPTH_MAX && text[j] === "{" ? { len: 1, closer: "}" } : null);
173
+ }
174
+ return s;
175
+ }
176
+ if (dialect === "python") {
177
+ let p = 0;
178
+ let f = false;
179
+ while (p < 3 && /[A-Za-z]/.test(text[i - p - 1] || "")) {
180
+ if (/[fF]/.test(text[i - p - 1])) f = true;
181
+ p++;
182
+ }
183
+ if (p && isIdentChar(text[i - p - 1])) {
184
+ p = 0;
185
+ f = false;
186
+ }
187
+ const s = single(tok, "\\", tok.length === 3);
188
+ s.from = i - p;
189
+ if (f) {
190
+ s.pair = "{{";
191
+ s.hole = (j) => (depth < HOLE_DEPTH_MAX && text[j] === "{" ? { len: 1, closer: "}" } : null);
192
+ }
193
+ return s;
194
+ }
195
+ if (dialect === "go" && tok === "`") return single(tok, null, true);
196
+ return single(tok, "\\", tok.length > 1);
197
+ }
198
+
199
+ /** A character literal such as `'"'` or `'\n'` at i in a dialect whose quotes list omits `'`. */
200
+ function charLiteralEnd(text, i) {
201
+ if (text[i + 1] === "\\") {
202
+ const end = text.indexOf("'", i + 3);
203
+ return end > 0 && end - i <= 12 ? end + 1 : -1;
204
+ }
205
+ const cp = text.codePointAt(i + 1);
206
+ const width = cp > 0xffff ? 2 : 1;
207
+ return text[i + 1 + width] === "'" ? i + width + 2 : -1;
208
+ }
209
+
210
+ /**
211
+ * Remove comments and string literals so they cannot produce phantom edges.
212
+ *
213
+ * @param {string} text - source text
214
+ * @param {object} comments - rules.comments: line, block, string, regex, dialect, nested
215
+ * @param {{stringFill?: string}} [options] - stringFill replaces the first character of each
216
+ * string literal, so a scanner that reads call arguments still sees that one was written.
217
+ * @returns {string} same length, comments and literal text blanked, interpolated code kept
218
+ */
219
+ export function stripCode(text, comments = {}, options = {}) {
220
+ const line = comments.line || [];
221
+ const block = comments.block || [];
222
+ const quotes = comments.string || [];
223
+ const fill = options.stringFill || null;
224
+ const dialect = comments.dialect || (comments.regex === true ? "js" : "");
225
+ const nested = comments.nested === true;
226
+ const regexOn = dialect === "js";
227
+ const charLiterals = dialect === "rust" || dialect === "cpp";
228
+ const out = text.split("");
229
+ const n = text.length;
230
+
231
+ const starts = new Set([
232
+ ...line.map((t) => t[0]),
233
+ ...block.map(([open]) => open[0]),
234
+ ...quotes.map((q) => q[0]),
235
+ ...(regexOn ? ["/"] : []),
236
+ ...(charLiterals ? ["'"] : []),
237
+ ]);
238
+
239
+ const blank = (from, to) => {
240
+ for (let k = Math.max(from, 0); k < to && k < n; k++) {
241
+ if (out[k] !== "\n") out[k] = " ";
242
+ }
243
+ };
244
+
245
+ const blockEnd = (i, open, close) => {
246
+ if (!nested) {
247
+ const end = text.indexOf(close, i + open.length);
248
+ return end === -1 ? n : end + close.length;
249
+ }
250
+ let depth = 1;
251
+ let j = i + open.length;
252
+ while (j < n && depth > 0) {
253
+ if (text.startsWith(open, j)) {
254
+ depth++;
255
+ j += open.length;
256
+ } else if (text.startsWith(close, j)) {
257
+ depth--;
258
+ j += close.length;
259
+ } else j++;
260
+ }
261
+ return j;
262
+ };
263
+
264
+ /** Read one literal; blank its text and keep what is inside its holes. */
265
+ const literal = (i, tok, depth) => {
266
+ const spec = literalSpec(text, i, tok, dialect, depth);
267
+ let j = spec.body;
268
+ let segment = spec.from;
269
+ while (j < n) {
270
+ if (spec.pair && text.startsWith(spec.pair, j)) {
271
+ j += spec.pair.length;
272
+ continue;
273
+ }
274
+ const hole = spec.hole ? spec.hole(j) : null;
275
+ if (hole) {
276
+ blank(segment, j + hole.len);
277
+ const end = scan(j + hole.len, hole.closer, depth + 1);
278
+ segment = end;
279
+ j = end < n ? end + 1 : n;
280
+ continue;
281
+ }
282
+ if (spec.esc && text.startsWith(spec.esc, j)) {
283
+ j += spec.esc.length + 1;
284
+ continue;
285
+ }
286
+ if (spec.verbatim && text[j] === '"' && text[j + 1] === '"') {
287
+ j += 2;
288
+ continue;
289
+ }
290
+ const closing = spec.close(j);
291
+ if (closing) {
292
+ j += closing;
293
+ break;
294
+ }
295
+ if (text[j] === "\n" && !spec.multiline) break;
296
+ j++;
297
+ }
298
+ j = Math.min(j, n);
299
+ blank(segment, j);
300
+ if (fill) out[spec.from] = fill;
301
+ return j;
302
+ };
303
+
304
+ /**
305
+ * Scan code from i. At a hole (`closer` set) stop at the bracket that closes it
306
+ * and return its index; at the top level run to the end of the text.
307
+ */
308
+ const scan = (start, closer, depth) => {
309
+ const opener = closer === "}" ? "{" : closer === ")" ? "(" : null;
310
+ let level = 0;
311
+ let i = start;
312
+ while (i < n) {
313
+ const c = text[i];
314
+ if (closer !== null) {
315
+ if (c === opener) level++;
316
+ else if (c === closer) {
317
+ if (level === 0) {
318
+ blank(i, i + 1);
319
+ return i;
320
+ }
321
+ level--;
322
+ }
323
+ }
324
+ if (!starts.has(c)) {
325
+ i++;
326
+ continue;
327
+ }
328
+ const rest = text.slice(i, i + 8);
329
+
330
+ const lineTok = line.find((t) => rest.startsWith(t));
331
+ if (lineTok) {
332
+ let end = text.indexOf("\n", i);
333
+ if (end === -1) end = n;
334
+ blank(i, end);
335
+ i = end;
336
+ continue;
337
+ }
338
+
339
+ const blockTok = block.find(([open]) => rest.startsWith(open));
340
+ if (blockTok) {
341
+ const end = blockEnd(i, blockTok[0], blockTok[1]);
342
+ blank(i, end);
343
+ i = end;
344
+ continue;
345
+ }
346
+
347
+ const quoteTok = quotes.find((q) => rest.startsWith(q));
348
+ if (quoteTok) {
349
+ i = literal(i, quoteTok, depth);
350
+ continue;
351
+ }
352
+
353
+ if (regexOn && c === "/" && regexMayStart(text, i)) {
354
+ const end = regexEnd(text, i);
355
+ if (end > 0) {
356
+ blank(i, end);
357
+ if (fill) out[i] = "0";
358
+ i = end;
359
+ continue;
360
+ }
361
+ }
362
+
363
+ if (charLiterals && c === "'") {
364
+ const end = charLiteralEnd(text, i);
365
+ if (end > 0) {
366
+ blank(i, end);
367
+ if (fill) out[i] = "0";
368
+ i = end;
369
+ continue;
370
+ }
371
+ }
372
+
373
+ i++;
374
+ }
375
+ return n;
376
+ };
377
+
378
+ scan(0, null, 0);
379
+ return out.join("");
380
+ }
@@ -78,11 +78,13 @@ import { buildIndex } from "./runs-index.mjs";
78
78
  import { startedJobs } from "./job-launch.mjs";
79
79
  import { createUsageCache, priceModels, sessionTranscripts } from "../lib/session-usage.mjs";
80
80
  import { exitOnHelp } from "../lib/cli-help.mjs";
81
+ import { globalPref } from "../lib/prefs-value.mjs";
82
+ import { budgetConfig } from "./_cost-budget.mjs";
81
83
  import { ArgsError, parseArgs as parseArgv } from "../lib/args.mjs";
82
84
 
83
85
  exitOnHelp(import.meta.url);
84
86
 
85
- export const CONTRACT_VERSION = "1.2.0";
87
+ export const CONTRACT_VERSION = "1.4.0";
86
88
  export const RECENT_MS = 10 * 60_000;
87
89
 
88
90
  export const ROLES = JSON.parse(
@@ -741,6 +743,11 @@ export async function activitySnapshot(opts = {}) {
741
743
  corridors,
742
744
  counts: { rooms: 0, tables: 0, seats: 0, live: 0, waiting: 0 },
743
745
  };
746
+ const budget = budgetConfig(
747
+ opts.costBudget !== undefined ? opts.costBudget : globalPref("costBudget", null),
748
+ );
749
+ if (budget.enabled)
750
+ doc.costBudget = { maxUsd: budget.maxUsd, warnPct: budget.warnPct, onExceed: budget.onExceed };
744
751
  for (const room of doc.rooms) {
745
752
  doc.counts.rooms++;
746
753
  for (const t of room.tables) {
@@ -943,6 +950,8 @@ function renderTable(team, clean, now) {
943
950
  channels: [],
944
951
  waitingFor: asking(seats) ? "terminal" : null,
945
952
  waitingForYou: asking(seats),
953
+ waitingSince: null,
954
+ waitingSinceSource: null,
946
955
  pendingQuestion: null,
947
956
  tokens: team.usage?.tokens ?? null,
948
957
  estUsd: team.usage?.estUsd ?? null,
@@ -998,6 +1007,9 @@ function renderTable(team, clean, now) {
998
1007
  pr: Number.isInteger(run.prNumber) && run.prNumber > 0 ? { number: run.prNumber } : null,
999
1008
  channels: Array.isArray(run.channels) ? run.channels.slice(0, 5) : [],
1000
1009
  waitingFor,
1010
+ waitingSince: waitingFor && typeof run.waitingSince === "string" ? run.waitingSince : null,
1011
+ waitingSinceSource:
1012
+ waitingFor && typeof run.waitingSince === "string" ? (run.waitingSinceSource ?? null) : null,
1001
1013
  host,
1002
1014
  limited: host !== "claude",
1003
1015
  sessionId: run.sessionId ?? first?.sessionId ?? null,
@@ -22,7 +22,7 @@
22
22
  // node aggregate-metrics.mjs --since=2026-04-01 --json
23
23
  // METRICS_FILE=/tmp/test.jsonl node aggregate-metrics.mjs
24
24
 
25
- import { existsSync, readFileSync } from "node:fs";
25
+ import { readRotatedLines, rotatedExists } from "../lib/rotated-log.mjs";
26
26
  import { homedir } from "node:os";
27
27
  import { join } from "node:path";
28
28
 
@@ -51,7 +51,7 @@ for (const a of args) {
51
51
  const METRICS_FILE =
52
52
  process.env.METRICS_FILE || join(homedir(), ".claude", "logs", "multi-agent", "metrics.jsonl");
53
53
 
54
- if (!existsSync(METRICS_FILE)) {
54
+ if (!rotatedExists(METRICS_FILE)) {
55
55
  if (opts.json) {
56
56
  console.log(
57
57
  JSON.stringify({ ok: false, reason: "metrics file not found", path: METRICS_FILE }),
@@ -63,9 +63,7 @@ if (!existsSync(METRICS_FILE)) {
63
63
  process.exit(0);
64
64
  }
65
65
 
66
- const lines = readFileSync(METRICS_FILE, "utf-8")
67
- .split("\n")
68
- .filter((l) => l.trim());
66
+ const lines = readRotatedLines(METRICS_FILE);
69
67
  const events = [];
70
68
  let parseErrors = 0;
71
69
  for (const line of lines) {
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @file index.mjs - per-file call facts and graph-wide call edges.
3
+ *
4
+ * `analyzeFile` runs once per file during extraction and returns JSON-safe
5
+ * facts: declared types and functions, imports, and for every function the
6
+ * call chains in its body. `addCallEdges` (resolve.mjs) joins those facts across
7
+ * files after every file has been read.
8
+ *
9
+ * @module pipeline/scripts/call-graph
10
+ */
11
+
12
+ import { BudgetError, refusal, tokenize } from "./lex.mjs";
13
+ import { scanBody } from "./scan.mjs";
14
+ import { profileForPath } from "./profiles.mjs";
15
+
16
+ export { addCallEdges } from "./resolve.mjs";
17
+ export { profileForPath, supportedExtensions } from "./profiles.mjs";
18
+
19
+ /**
20
+ * Call facts for one file, or null when the language is not covered or the file
21
+ * must not be analysed (too large, binary, minified, unbalanced, too many tokens).
22
+ *
23
+ * @param {string} raw - source text as read
24
+ * @param {(options: object) => string} strip - strips comments and string bodies; called only for a covered language
25
+ * @param {string} path - repo-relative path
26
+ * @param {{budgetMs?: number}} [options] - budgetMs overrides the per-file time budget
27
+ * @returns {{facts: object|null, skipped: string|null}}
28
+ */
29
+ export function analyzeFile(raw, strip, path, { budgetMs } = {}) {
30
+ const profile = profileForPath(path);
31
+ if (!profile) return { facts: null, skipped: null };
32
+ const why = refusal(raw);
33
+ if (why) return { facts: null, skipped: why };
34
+ let text = strip({ stringFill: "\u0001" });
35
+ if (profile.prepare) text = profile.prepare(text);
36
+ const tk = tokenize(text, budgetMs);
37
+ if (tk.skipped) return { facts: null, skipped: tk.skipped };
38
+ let parsed;
39
+ let fns;
40
+ let binds;
41
+ let rx;
42
+ const top = [];
43
+ try {
44
+ parsed = profile.parse(tk, path);
45
+ fns = parsed.fns.map((f) => {
46
+ const { body, pr, ...rest } = f;
47
+ const ev = [
48
+ ...(pr ? scanBody(tk, pr[0], pr[1], profile) : []),
49
+ ...(body ? scanBody(tk, body[0], body[1], profile) : []),
50
+ ];
51
+ return { ...rest, ...(ev.length ? { ev } : {}) };
52
+ });
53
+ binds = profile.binds
54
+ ? profile.binds(profile.keepStrings ? strip({ keepStrings: true }) : text, path)
55
+ : parsed.binds || [];
56
+ for (const [from, to] of parsed.top || []) top.push(...scanBody(tk, from, to, profile));
57
+ rx = profile.reexports
58
+ ? profile.reexports(profile.keepStrings ? strip({ keepStrings: true }) : text)
59
+ : [];
60
+ } catch (e) {
61
+ return { facts: null, skipped: e instanceof BudgetError ? "time-budget" : "parse-error" };
62
+ }
63
+ return {
64
+ facts: {
65
+ lang: profile.id,
66
+ types: parsed.types,
67
+ fns,
68
+ binds,
69
+ ...(parsed.gl && Object.keys(parsed.gl).length ? { gl: parsed.gl } : {}),
70
+ ...(parsed.mods?.length ? { mods: parsed.mods } : {}),
71
+ ...(parsed.vars?.length ? { vars: parsed.vars } : {}),
72
+ ...(parsed.def ? { def: parsed.def } : {}),
73
+ ...(rx.length ? { rx } : {}),
74
+ ...(top.length ? { top } : {}),
75
+ },
76
+ skipped: null,
77
+ };
78
+ }