@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
@@ -0,0 +1,105 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "stack": "rust",
4
+ "description": "Rust code-graph rules. Adds what the graph needs on top of test-gap-rules/rust.json, which owns sourceExtensions, excludePathGlobs and the test-path predicates. Types and traits are the symbols; functions and methods come from the call analysis, which reads impl blocks.",
5
+ "comments": {
6
+ "line": ["//"],
7
+ "block": [["/*", "*/"]],
8
+ "string": ["\""],
9
+ "dialect": "rust",
10
+ "nested": true
11
+ },
12
+ "definitionPatterns": [
13
+ {
14
+ "id": "struct",
15
+ "kind": "struct",
16
+ "regex": "\\bstruct\\s+([A-Z][A-Za-z0-9_]*)"
17
+ },
18
+ {
19
+ "id": "enum",
20
+ "kind": "enum",
21
+ "regex": "\\benum\\s+([A-Z][A-Za-z0-9_]*)"
22
+ },
23
+ {
24
+ "id": "trait",
25
+ "kind": "trait",
26
+ "regex": "\\btrait\\s+([A-Z][A-Za-z0-9_]*)"
27
+ },
28
+ {
29
+ "id": "type",
30
+ "kind": "type",
31
+ "regex": "\\btype\\s+([A-Z][A-Za-z0-9_]*)\\s*(?:<[^>]*>)?\\s*="
32
+ },
33
+ {
34
+ "id": "fn",
35
+ "kind": "fn",
36
+ "regex": "^[ \\t]*(?:pub(?:\\([^)]*\\))?\\s+)?(?:async\\s+|const\\s+|unsafe\\s+)*fn\\s+([a-z_][A-Za-z0-9_]*)"
37
+ }
38
+ ],
39
+ "importPatterns": [
40
+ {
41
+ "id": "use",
42
+ "regex": "^\\s*(?:pub(?:\\([^)]*\\))?\\s+)?use\\s+(?:[A-Za-z_][A-Za-z0-9_]*::)*([A-Za-z_][A-Za-z0-9_]*)"
43
+ }
44
+ ],
45
+ "referenceKinds": ["struct", "enum", "trait", "type"],
46
+ "supertypes": {
47
+ "syntax": "colon",
48
+ "kinds": ["trait"]
49
+ },
50
+ "referenceKindsNote": "fn is absent for the reason the other stacks record: a bare lowercase name matched across files is rarely a call to that exact declaration. Call edges come from the call analysis instead.",
51
+ "ignoredIdentifiers": [
52
+ "self",
53
+ "Self",
54
+ "super",
55
+ "crate",
56
+ "fn",
57
+ "let",
58
+ "mut",
59
+ "pub",
60
+ "use",
61
+ "mod",
62
+ "impl",
63
+ "trait",
64
+ "struct",
65
+ "enum",
66
+ "type",
67
+ "where",
68
+ "match",
69
+ "if",
70
+ "else",
71
+ "for",
72
+ "while",
73
+ "loop",
74
+ "in",
75
+ "return",
76
+ "break",
77
+ "continue",
78
+ "as",
79
+ "ref",
80
+ "move",
81
+ "static",
82
+ "const",
83
+ "unsafe",
84
+ "async",
85
+ "await",
86
+ "dyn",
87
+ "true",
88
+ "false",
89
+ "Some",
90
+ "None",
91
+ "Ok",
92
+ "Err",
93
+ "Option",
94
+ "Result",
95
+ "Vec",
96
+ "String",
97
+ "Box",
98
+ "Rc",
99
+ "Arc",
100
+ "Default",
101
+ "Debug",
102
+ "Clone",
103
+ "Copy"
104
+ ]
105
+ }
@@ -361,6 +361,7 @@ export const ROUTES = [
361
361
  office.activityStream,
362
362
  office.chat,
363
363
  office.ledger,
364
+ office.learning,
364
365
  office.system,
365
366
  office.credentials,
366
367
  office.memory,
@@ -32,7 +32,10 @@ import { join } from "node:path";
32
32
  import { hostCommand } from "../lib/user-facing.mjs";
33
33
  import { loadGlobalPrefs, prefsFileIn } from "../lib/prefs-value.mjs";
34
34
  import { exitOnHelp } from "../lib/cli-help.mjs";
35
- import { endpointAllowed, resolveUsageToken } from "../lib/usage-token.mjs";
35
+ import { nowMinute, releaseVersion } from "../lib/usage-vocab.mjs";
36
+ import { postJson } from "./_http-post.mjs";
37
+ import { registerUrlAllowed } from "../lib/usage-endpoint.mjs";
38
+ import { resolveUsageToken } from "../lib/usage-token.mjs";
36
39
 
37
40
  exitOnHelp(import.meta.url);
38
41
 
@@ -57,7 +60,7 @@ function packageVersion() {
57
60
  join(homedir(), ".codex", ".pipeline-version"),
58
61
  ]) {
59
62
  try {
60
- const v = readFileSync(p, "utf-8").trim();
63
+ const v = releaseVersion(readFileSync(p, "utf-8"));
61
64
  if (v) return v;
62
65
  } catch {
63
66
  /* try the next host */
@@ -101,7 +104,7 @@ async function main() {
101
104
  kind,
102
105
  v: packageVersion(),
103
106
  host: host(),
104
- at: new Date().toISOString(),
107
+ at: nowMinute(),
105
108
  };
106
109
 
107
110
  if (process.argv.includes("--dry-run")) {
@@ -111,8 +114,10 @@ async function main() {
111
114
  return;
112
115
  }
113
116
 
114
- if (!endpointAllowed(endpoint)) {
115
- process.stderr.write(`ERROR: refusing to send over a non-TLS endpoint: ${endpoint}\n`);
117
+ if (!registerUrlAllowed(endpoint, readPrefs().usageLog?.trustedHosts)) {
118
+ process.stderr.write(
119
+ `ERROR: refusing to send: the endpoint is not https on a trusted host (usageLog.trustedHosts): ${endpoint}\n`,
120
+ );
116
121
  process.exit(1);
117
122
  }
118
123
 
@@ -124,29 +129,24 @@ async function main() {
124
129
  process.exit(1);
125
130
  }
126
131
 
127
- const ctrl = new AbortController();
128
- const timer = setTimeout(() => ctrl.abort(), TIMEOUT_MS);
129
- try {
130
- const res = await fetch(endpoint, {
131
- method: "POST",
132
- headers: { "Content-Type": "application/json", "X-Usage-Token": token },
133
- body: JSON.stringify(payload),
134
- signal: ctrl.signal,
135
- });
136
- if (!res.ok) {
137
- // Unlike telemetry, this failure is reported: the person is standing there
138
- // waiting to hear whether their message went. Swallowing it would leave
139
- // them believing they had been heard.
140
- process.stderr.write(`ERROR: the endpoint answered ${res.status}\n`);
141
- process.exit(1);
142
- }
143
- process.stdout.write("feedback sent\n");
144
- } catch (err) {
145
- process.stderr.write(`ERROR: could not reach the endpoint (${err.name})\n`);
132
+ const res = await postJson({
133
+ url: endpoint,
134
+ headers: { "X-Usage-Token": token },
135
+ body: JSON.stringify(payload),
136
+ timeoutMs: TIMEOUT_MS,
137
+ });
138
+ if (res.failure) {
139
+ process.stderr.write(`ERROR: could not reach the endpoint (${res.failure})\n`);
140
+ process.exit(1);
141
+ }
142
+ if (res.status < 200 || res.status >= 300) {
143
+ // Unlike telemetry, this failure is reported: the person is standing there
144
+ // waiting to hear whether their message went. Swallowing it would leave
145
+ // them believing they had been heard.
146
+ process.stderr.write(`ERROR: the endpoint answered ${res.status}\n`);
146
147
  process.exit(1);
147
- } finally {
148
- clearTimeout(timer);
149
148
  }
149
+ process.stdout.write("feedback sent\n");
150
150
  }
151
151
 
152
152
  // `main()` is async, and calling it bare leaves any rejection it does not
@@ -83,7 +83,7 @@ import { globalPref } from "../lib/prefs-value.mjs";
83
83
  import { modeEntry } from "../lib/run-completion.mjs";
84
84
  import { attendedVerdict, gatesActive } from "../lib/unattended.mjs";
85
85
  import { listRuns, resolveRunFile } from "./_run-paths.mjs";
86
- import { acquireLock, releaseLock, stillOurs } from "./write-state.mjs";
86
+ import { acquireLock, releaseLock, stampWaitingSince, stillOurs } from "./write-state.mjs";
87
87
  import { ArgsError, parseArgs } from "../lib/args.mjs";
88
88
  import { exitOnHelp } from "../lib/cli-help.mjs";
89
89
 
@@ -501,6 +501,7 @@ export async function updateState(path, mutate) {
501
501
  }
502
502
  const next = mutate(current);
503
503
  if (next === current) return current;
504
+ stampWaitingSince(next, current);
504
505
  next.rev = (Number.isInteger(current.rev) ? current.rev : 0) + 1;
505
506
  if (!stillOurs(path, ino)) {
506
507
  throw new LedgerError("io", `the lock on ${path} was taken mid-write; nothing written`);
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * gen-usage-names.mjs - write lib/usage-names.generated.mjs, the names a usage
4
+ * record may carry.
5
+ *
6
+ * A record names a command, a skill or an MCP tool only when the package
7
+ * itself ships it. The lists are built here, when the package is packed, from
8
+ * the package's own trees, and travel inside it; nothing found on the machine
9
+ * that runs the pipeline (saved routines, local wrappers, a marketplace cache,
10
+ * a registered server) can extend them.
11
+ *
12
+ * SHIPPED_COMMANDS the tracked directories of pipeline/commands/multi-agent
13
+ * SHIPPED_SKILLS the tracked directories of pipeline/skills/shared/{core,external}
14
+ * TOOLKIT_TOOLS the tools of this product's MCP server, from
15
+ * pipeline/schemas/toolkit-path-params.json (itself
16
+ * generated from the server's tool manifest)
17
+ *
18
+ * The trees are read from the tracked file set (git ls-files), not from the
19
+ * disk, so a directory that is only present locally never enters a list.
20
+ * `prepack` runs the generator, so a published package carries the lists of the
21
+ * tree it was packed from; `npm test` runs it with --check.
22
+ *
23
+ * Usage: gen-usage-names.mjs [--check]
24
+ * Exit: 0 written / current, 1 --check found the file stale.
25
+ *
26
+ * @module pipeline/scripts/gen-usage-names
27
+ */
28
+
29
+ import { execFileSync } from "node:child_process";
30
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
31
+ import { dirname, join, resolve } from "node:path";
32
+ import { fileURLToPath } from "node:url";
33
+ import { invokedDirectly } from "../lib/invoked-directly.mjs";
34
+ import { exitOnHelp } from "../lib/cli-help.mjs";
35
+
36
+ exitOnHelp(import.meta.url);
37
+
38
+ const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..");
39
+ const OUT = join(ROOT, "pipeline", "lib", "usage-names.generated.mjs");
40
+
41
+ /**
42
+ * The directories directly under `prefix` that hold at least one tracked file.
43
+ * The tracked file set is the package's; a directory that exists on this disk
44
+ * but is not in git (a routine, a scratch copy) is not.
45
+ */
46
+ function trackedDirsUnder(root, prefix) {
47
+ const out = execFileSync("git", ["ls-files", "-z", "--", prefix], {
48
+ cwd: root,
49
+ encoding: "utf8",
50
+ maxBuffer: 64 * 1024 * 1024,
51
+ });
52
+ const names = new Set();
53
+ for (const file of out.split("\0")) {
54
+ if (!file.startsWith(`${prefix}/`)) continue;
55
+ const [name, ...rest] = file.slice(prefix.length + 1).split("/");
56
+ if (rest.length && name && !name.startsWith(".")) names.add(name);
57
+ }
58
+ return [...names].sort();
59
+ }
60
+
61
+ /** The three lists, read from the package's trees. */
62
+ export function collect(root = ROOT) {
63
+ const commands = trackedDirsUnder(root, "pipeline/commands/multi-agent");
64
+ const skills = [
65
+ ...new Set(
66
+ ["core", "external"].flatMap((g) => trackedDirsUnder(root, `pipeline/skills/shared/${g}`)),
67
+ ),
68
+ ].sort();
69
+ const params = JSON.parse(
70
+ readFileSync(join(root, "pipeline", "schemas", "toolkit-path-params.json"), "utf8"),
71
+ );
72
+ const tools = Object.keys(params.tools ?? {}).sort();
73
+ return { commands, skills, tools };
74
+ }
75
+
76
+ export function render({ commands, skills, tools }) {
77
+ const list = (name, doc, names) => [
78
+ `/** ${doc} */`,
79
+ `export const ${name} = Object.freeze([`,
80
+ ...names.map((n) => ` ${JSON.stringify(n)},`),
81
+ "]);",
82
+ "",
83
+ ];
84
+ return [
85
+ "/**",
86
+ " * Generated by pipeline/scripts/gen-usage-names.mjs from the package's own",
87
+ " * command, skill and tool trees. Regenerate after any of them changes; npm",
88
+ " * test runs it with --check.",
89
+ " *",
90
+ " * @module pipeline/lib/usage-names.generated",
91
+ " */",
92
+ "",
93
+ ...list(
94
+ "SHIPPED_COMMANDS",
95
+ "The commands under commands/multi-agent that the package ships.",
96
+ commands,
97
+ ),
98
+ ...list("SHIPPED_SKILLS", "The skills the package ships (core and external).", skills),
99
+ ...list("TOOLKIT_TOOLS", "The tools this product's MCP server serves.", tools),
100
+ ].join("\n");
101
+ }
102
+
103
+ function main() {
104
+ const check = process.argv.includes("--check");
105
+ const want = render(collect());
106
+ const have = existsSync(OUT) ? readFileSync(OUT, "utf8") : null;
107
+ if (check) {
108
+ if (want !== have) {
109
+ process.stderr.write(
110
+ "gen-usage-names: pipeline/lib/usage-names.generated.mjs is stale\n" +
111
+ " run: node pipeline/scripts/gen-usage-names.mjs\n",
112
+ );
113
+ process.exitCode = 1;
114
+ return;
115
+ }
116
+ process.stdout.write("gen-usage-names: current\n");
117
+ return;
118
+ }
119
+ if (want !== have) writeFileSync(OUT, want);
120
+ // stderr: this runs as `prepack`, whose stdout lands inside `npm pack --json`.
121
+ process.stderr.write(`gen-usage-names: ${want === have ? "current" : "written"}\n`);
122
+ }
123
+
124
+ if (invokedDirectly(import.meta.url)) main();
@@ -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