@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,333 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @file pair.mjs - pair a phone with this computer and manage the pairing.
4
+ * The script behind /multi-agent:pair. Remote control is off until the site
5
+ * enables it for this user AND a device is paired here.
6
+ *
7
+ * Pairing (always needs the person; refused when MULTI_AGENT_UNATTENDED=1):
8
+ * pair.mjs all steps in one run; needs a terminal
9
+ * pair.mjs begin step 1: show the QR code and the fallback code
10
+ * pair.mjs wait [--timeout S] step 2: wait for the phone (default 90 s)
11
+ * pair.mjs confirm <NNNNNN> step 3: the six-digit number the phone shows
12
+ * pair.mjs cancel abandon a pairing in progress
13
+ *
14
+ * Managing:
15
+ * pair.mjs --list the devices pinned on this computer
16
+ * pair.mjs --revoke <device> forget one device here (id or unique prefix)
17
+ * pair.mjs --off stop the listener and forget every device;
18
+ * works offline
19
+ * pair.mjs --start start the listener again for pinned devices
20
+ * pair.mjs --status listener and device summary
21
+ *
22
+ * Add --json for one JSON object on stdout. The number the phone shows is
23
+ * compared here and never printed or sent to the site.
24
+ *
25
+ * Exit: 0 done, 1 failed, 2 usage, 3 remote control is not enabled on the
26
+ * site or the account lacks the permission, 4 the site did not accept this
27
+ * machine's usage token.
28
+ */
29
+
30
+ import { closeSync, openSync, writeSync } from "node:fs";
31
+ import { createInterface } from "node:readline";
32
+ import { loadPrefs, prefsPath } from "../lib/prefs-value.mjs";
33
+ import { resolveUsageToken } from "../lib/usage-token.mjs";
34
+ import { isUnattended } from "../lib/unattended.mjs";
35
+ import { exitOnHelp } from "../lib/cli-help.mjs";
36
+ import { invokedDirectly } from "../lib/invoked-directly.mjs";
37
+ import { runMain } from "../lib/fatal.mjs";
38
+ import {
39
+ PAIRING_NOTICE,
40
+ PairError,
41
+ beginPairing,
42
+ cancelPairing,
43
+ confirmPairing,
44
+ forgetEverything,
45
+ listPinned,
46
+ revokeDevice,
47
+ waitPairing,
48
+ } from "./remote/pairing.mjs";
49
+ import { listenerStatus, startListener, stopListener } from "./remote/lifecycle.mjs";
50
+ import { readDevices } from "./remote/store.mjs";
51
+ import { SiteError, createSiteClient, siteFromPrefs } from "./remote/transport.mjs";
52
+ import { encodeQr, renderHalfBlocks } from "./remote/qr-encode.mjs";
53
+
54
+ exitOnHelp(import.meta.url);
55
+
56
+ const MANAGE_FLAGS = new Set(["--list", "--revoke", "--off", "--start", "--status"]);
57
+ const STEPS = new Set(["begin", "wait", "confirm", "cancel"]);
58
+
59
+ function parse(argv) {
60
+ const json = argv.includes("--json");
61
+ const rest = argv.filter((a) => a !== "--json");
62
+ let timeout = 90;
63
+ const ti = rest.indexOf("--timeout");
64
+ if (ti !== -1) {
65
+ timeout = Number(rest[ti + 1]);
66
+ rest.splice(ti, 2);
67
+ if (!Number.isInteger(timeout) || timeout < 1 || timeout > 600) return null;
68
+ }
69
+ const [cmd, arg, ...extra] = rest;
70
+ if (extra.length) return null;
71
+ if (cmd === undefined) return { json, mode: "interactive", timeout };
72
+ if (STEPS.has(cmd)) {
73
+ if (cmd === "confirm" ? arg === undefined : arg !== undefined) return null;
74
+ return { json, mode: cmd, arg, timeout };
75
+ }
76
+ if (MANAGE_FLAGS.has(cmd)) {
77
+ if (cmd === "--revoke" ? arg === undefined : arg !== undefined) return null;
78
+ return { json, mode: cmd, arg, timeout };
79
+ }
80
+ return null;
81
+ }
82
+
83
+ function clientFor(env, deps) {
84
+ if (deps.client) return { client: deps.client, site: deps.site };
85
+ const prefs = loadPrefs(prefsPath(env));
86
+ let site;
87
+ try {
88
+ site = siteFromPrefs(prefs);
89
+ } catch (err) {
90
+ if (err instanceof SiteError) throw new PairError("untrusted-site", err.message);
91
+ throw err;
92
+ }
93
+ const token = () => resolveUsageToken(prefs.global, { env });
94
+ if (!token()) {
95
+ throw new PairError(
96
+ "no-token",
97
+ "this machine has no usage token; run /multi-agent:setup first",
98
+ );
99
+ }
100
+ return { client: createSiteClient({ site, token }), site };
101
+ }
102
+
103
+ /** Tells the site (machine/revoke) when it is reachable; never throws, and says why it could not. */
104
+ async function revokeOnSite(env, deps, body) {
105
+ try {
106
+ const { client } = clientFor(env, deps);
107
+ const r = await client.post("machine/revoke", body);
108
+ if (r.status === 200) return { done: true, reason: "" };
109
+ if (r.status === 404 && r.json?.error === "unknown_device") return { done: true, reason: "" };
110
+ return { done: false, reason: r.status === 404 ? "token not accepted" : `status ${r.status}` };
111
+ } catch (err) {
112
+ return {
113
+ done: false,
114
+ reason: err instanceof PairError ? err.code : (err.code ?? "unreachable"),
115
+ };
116
+ }
117
+ }
118
+
119
+ function say(out, json, object, lines) {
120
+ out.write(json ? `${JSON.stringify(object)}\n` : `${lines.join("\n")}\n`);
121
+ }
122
+
123
+ async function afterPaired(env, deps) {
124
+ if (env.MA_REMOTE_NO_LISTENER === "1") return { running: false, started: false };
125
+ return (deps.startListener ?? startListener)(env);
126
+ }
127
+
128
+ async function interactive(env, deps, out, json) {
129
+ if (isUnattended(env))
130
+ throw new PairError("unattended", "pairing needs a person; it is refused in an unattended run");
131
+ if (!deps.input && !(process.stdin.isTTY && process.stdout.isTTY)) {
132
+ throw new PairError(
133
+ "no-terminal",
134
+ "this needs a terminal; use the begin, wait and confirm steps instead",
135
+ );
136
+ }
137
+ const { client, site } = clientFor(env, deps);
138
+ const shown = await beginPairing({ env, client, site });
139
+ showCode(out, shown, false);
140
+ for (;;) {
141
+ const w = await waitPairing({ env, client, timeoutMs: 30_000 });
142
+ if (w.state === "registered") break;
143
+ }
144
+ const rl = createInterface({ input: deps.input ?? process.stdin, output: process.stderr });
145
+ let typed;
146
+ try {
147
+ typed = await new Promise((resolve) =>
148
+ rl.question("Type the number shown on your phone: ", resolve),
149
+ );
150
+ } finally {
151
+ rl.close();
152
+ }
153
+ const done = await confirmPairing({ env, client, typed });
154
+ const listener = await afterPaired(env, deps);
155
+ say(out, json, { paired: true, deviceId: done.deviceId, label: done.label, listener }, [
156
+ `Paired "${done.label}".`,
157
+ listener.running
158
+ ? "The listener is running."
159
+ : "The listener did not start; run: pair.mjs --start",
160
+ ]);
161
+ }
162
+
163
+ /** A writer for the controlling terminal, or null when there is none (a host that runs this without one). */
164
+ function openTty() {
165
+ try {
166
+ const fd = openSync("/dev/tty", "w");
167
+ return {
168
+ write: (text) => writeSync(fd, text),
169
+ close: () => closeSync(fd),
170
+ };
171
+ } catch {
172
+ return null;
173
+ }
174
+ }
175
+
176
+ /**
177
+ * With a terminal, the QR code and the code go straight to it and the session
178
+ * (the model's context) learns only that they were shown and how long they
179
+ * last. Without one they go to the session output, which the ref says plainly.
180
+ */
181
+ function presentCode(out, tty, shown, json) {
182
+ if (!tty) return showCode(out, shown, json);
183
+ showCode(tty, shown, false);
184
+ tty.close?.();
185
+ const minutes = Math.max(1, Math.round((Date.parse(shown.expiresAt) - Date.now()) / 60_000));
186
+ say(out, json, { shown: true, machineName: shown.machineName, expiresInMinutes: minutes }, [
187
+ `Shown on your terminal. The code expires in ${minutes} minute${minutes === 1 ? "" : "s"}.`,
188
+ ]);
189
+ }
190
+
191
+ function showCode(out, shown, json) {
192
+ const qr = renderHalfBlocks(encodeQr(shown.url).modules);
193
+ if (json) {
194
+ out.write(`${JSON.stringify({ ...shown, qr, notice: PAIRING_NOTICE })}\n`);
195
+ return;
196
+ }
197
+ out.write(
198
+ `${PAIRING_NOTICE}\n\n${qr}\n\nOr open ${shown.url.split("#")[0]} on the phone and enter this code:\n ${shown.code}\n`,
199
+ );
200
+ out.write(`Computer: ${shown.machineName}. Valid until ${shown.expiresAt}.\n`);
201
+ }
202
+
203
+ /**
204
+ * @param {string[]} argv
205
+ * @param {{env?: object, out?: {write: Function}, err?: {write: Function}, client?: object, site?: object,
206
+ * input?: NodeJS.ReadableStream, startListener?: Function}} [deps]
207
+ */
208
+ export async function main(argv, deps = {}) {
209
+ const env = deps.env ?? process.env;
210
+ const out = deps.out ?? process.stdout;
211
+ const err = deps.err ?? process.stderr;
212
+ const args = parse(argv);
213
+ if (!args) {
214
+ err.write(
215
+ "usage: pair.mjs [begin | wait [--timeout S] | confirm <NNNNNN> | cancel | --list | --revoke <device> | --off | --start | --status] [--json]\n",
216
+ );
217
+ return 2;
218
+ }
219
+ const { json } = args;
220
+ try {
221
+ switch (args.mode) {
222
+ case "--list": {
223
+ const devices = listPinned(env);
224
+ say(
225
+ out,
226
+ json,
227
+ { devices },
228
+ devices.length
229
+ ? devices.map((d) => `${d.id} ${d.label} paired ${d.pairedAt}`)
230
+ : ["No device is paired."],
231
+ );
232
+ return 0;
233
+ }
234
+ case "--revoke": {
235
+ const id = revokeDevice(env, args.arg);
236
+ if (Object.keys(readDevices(env).devices).length === 0) await stopListener(env);
237
+ const site = await revokeOnSite(env, deps, { deviceId: id });
238
+ say(out, json, { revoked: id, site: site.done, siteReason: site.reason }, [
239
+ site.done
240
+ ? `Forgot ${id} on this computer and removed it on the site.`
241
+ : `Forgot ${id} on this computer only: the site could not be told (${site.reason}). Remove it on the site too (the phone page or the panel).`,
242
+ ]);
243
+ return 0;
244
+ }
245
+ case "--off": {
246
+ const stopped = await stopListener(env);
247
+ forgetEverything(env);
248
+ const site = await revokeOnSite(env, deps, { all: true });
249
+ say(
250
+ out,
251
+ json,
252
+ { off: true, listenerStopped: stopped.stopped, site: site.done, siteReason: site.reason },
253
+ [
254
+ "Remote control is off here: the listener is stopped and every device is forgotten.",
255
+ site.done
256
+ ? "The devices were removed on the site as well."
257
+ : `Only this computer was acted on: the site could not be told (${site.reason}). Remove the devices on the site (the phone page or the panel).`,
258
+ ],
259
+ );
260
+ return 0;
261
+ }
262
+ case "--status": {
263
+ const listener = listenerStatus(env);
264
+ const devices = listPinned(env);
265
+ say(out, json, { listener, devices: devices.length }, [
266
+ `Listener: ${listener.running ? `running (pid ${listener.pid})` : "not running"}`,
267
+ `Devices: ${devices.length}`,
268
+ ]);
269
+ return 0;
270
+ }
271
+ case "--start": {
272
+ if (!Object.keys(readDevices(env).devices).length) {
273
+ throw new PairError("no-devices", "no device is paired; pair one first");
274
+ }
275
+ const listener = await (deps.startListener ?? startListener)(env);
276
+ say(out, json, { listener }, [
277
+ listener.running ? "The listener is running." : "The listener did not start.",
278
+ ]);
279
+ return listener.running ? 0 : 1;
280
+ }
281
+ case "interactive":
282
+ await interactive(env, deps, out, json);
283
+ return 0;
284
+ case "begin": {
285
+ const { client, site } = clientFor(env, deps);
286
+ presentCode(out, deps.tty ?? null, await beginPairing({ env, client, site }), json);
287
+ return 0;
288
+ }
289
+ case "wait": {
290
+ const { client } = clientFor(env, deps);
291
+ const w = await waitPairing({ env, client, timeoutMs: args.timeout * 1000 });
292
+ say(out, json, w, [
293
+ w.state === "registered"
294
+ ? `The phone registered ("${w.label}"). Ask the person for the six-digit number on the phone, then run: confirm <NNNNNN>`
295
+ : "Still waiting for the phone.",
296
+ ]);
297
+ return 0;
298
+ }
299
+ case "confirm": {
300
+ const { client } = clientFor(env, deps);
301
+ const done = await confirmPairing({ env, client, typed: args.arg });
302
+ const listener = await afterPaired(env, deps);
303
+ say(out, json, { paired: true, deviceId: done.deviceId, label: done.label, listener }, [
304
+ `Paired "${done.label}".`,
305
+ listener.running
306
+ ? "The listener is running."
307
+ : "The listener did not start; run: pair.mjs --start",
308
+ ]);
309
+ return 0;
310
+ }
311
+ case "cancel": {
312
+ const { client } = clientFor(env, deps);
313
+ const c = await cancelPairing({ env, client });
314
+ say(out, json, c, [c.cancelled ? "Pairing cancelled." : "No pairing was in progress."]);
315
+ return 0;
316
+ }
317
+ default:
318
+ return 2;
319
+ }
320
+ } catch (e) {
321
+ if (!(e instanceof PairError)) throw e;
322
+ if (json) out.write(`${JSON.stringify({ error: e.code, message: e.message })}\n`);
323
+ else err.write(`pair: ${e.message}\n`);
324
+ if (e.code === "not-enabled" || e.code === "no-permission") return 3;
325
+ return e.code === "token-not-accepted" ? 4 : 1;
326
+ }
327
+ }
328
+
329
+ if (invokedDirectly(import.meta.url)) {
330
+ runMain("pair", async () => {
331
+ process.exitCode = await main(process.argv.slice(2), { tty: openTty() });
332
+ });
333
+ }
@@ -151,7 +151,7 @@ export MULTI_AGENT_CROSS_REPO_REQUIRED=1
151
151
  export SMOKE_REQUIRE_BROWSER=1
152
152
  run_step "npm test (full gate chain)" npm test --silent
153
153
  run_step "lint" npx --no-install eslint . --max-warnings 0
154
- run_step "personal-data leak" bash pipeline/scripts/smoke-personal-data.sh
154
+ run_step "personal-data leak" env MA_LEAK_STRICT=1 bash pipeline/scripts/smoke-personal-data.sh
155
155
  # Skills ship without attribution files, so none may repeat a known upstream.
156
156
  # The corpus is local (prefs.global.upstreamCorpus); without one the step passes.
157
157
  run_step "upstream overlap" node pipeline/scripts/upstream-overlap-gate.mjs
@@ -0,0 +1,128 @@
1
+ /**
2
+ * cbor.mjs - a deliberately small CBOR reader for the COSE public key of a
3
+ * passkey. It accepts only what that structure needs:
4
+ *
5
+ * - unsigned and negative integers up to 32 bits, byte strings, text
6
+ * strings, arrays, maps and the simple values false, true and null;
7
+ * - definite lengths in their shortest form (no indefinite lengths, no
8
+ * padded length fields);
9
+ * - map keys that are integers or text, never duplicated;
10
+ * - no tags, no floats, no 64-bit integers;
11
+ * - nesting depth at most 6 and at most 32 items per container.
12
+ *
13
+ * Every limit is checked before anything is allocated, so a hostile length
14
+ * field cannot reserve memory.
15
+ *
16
+ * @module pipeline/scripts/remote/cbor
17
+ */
18
+
19
+ export class CborError extends Error {
20
+ constructor(message) {
21
+ super(message);
22
+ this.name = "CborError";
23
+ }
24
+ }
25
+
26
+ export const CBOR_MAX_DEPTH = 6;
27
+ export const CBOR_MAX_ITEMS = 32;
28
+ export const CBOR_MAX_BYTES = 16 * 1024;
29
+
30
+ const utf8 = new TextDecoder("utf-8", { fatal: true });
31
+
32
+ function take(buf, s, n) {
33
+ if (n < 0 || s.pos + n > buf.length) throw new CborError("truncated");
34
+ const out = buf.subarray(s.pos, s.pos + n);
35
+ s.pos += n;
36
+ return out;
37
+ }
38
+
39
+ function argument(buf, s, info) {
40
+ if (info < 24) return info;
41
+ if (info === 24) {
42
+ const v = take(buf, s, 1)[0];
43
+ if (v < 24) throw new CborError("non-minimal length");
44
+ return v;
45
+ }
46
+ if (info === 25) {
47
+ const b = take(buf, s, 2);
48
+ const v = (b[0] << 8) | b[1];
49
+ if (v < 256) throw new CborError("non-minimal length");
50
+ return v;
51
+ }
52
+ if (info === 26) {
53
+ const b = take(buf, s, 4);
54
+ const v = ((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]) >>> 0;
55
+ if (v < 65536) throw new CborError("non-minimal length");
56
+ return v;
57
+ }
58
+ if (info === 27) throw new CborError("64-bit integers are not accepted");
59
+ if (info === 31) throw new CborError("indefinite length is not accepted");
60
+ throw new CborError("reserved additional information");
61
+ }
62
+
63
+ function item(buf, s, depth) {
64
+ if (depth > CBOR_MAX_DEPTH) throw new CborError("nesting too deep");
65
+ const head = take(buf, s, 1)[0];
66
+ const major = head >> 5;
67
+ const info = head & 0x1f;
68
+ switch (major) {
69
+ case 0:
70
+ return argument(buf, s, info);
71
+ case 1:
72
+ return -1 - argument(buf, s, info);
73
+ case 2:
74
+ return take(buf, s, argument(buf, s, info));
75
+ case 3:
76
+ try {
77
+ return utf8.decode(take(buf, s, argument(buf, s, info)));
78
+ } catch (err) {
79
+ if (err instanceof CborError) throw err;
80
+ throw new CborError("invalid utf-8");
81
+ }
82
+ case 4: {
83
+ const count = argument(buf, s, info);
84
+ if (count > CBOR_MAX_ITEMS) throw new CborError("too many items");
85
+ if (count > buf.length - s.pos) throw new CborError("truncated");
86
+ const out = [];
87
+ for (let i = 0; i < count; i++) out.push(item(buf, s, depth + 1));
88
+ return out;
89
+ }
90
+ case 5: {
91
+ const count = argument(buf, s, info);
92
+ if (count > CBOR_MAX_ITEMS) throw new CborError("too many items");
93
+ if (count * 2 > buf.length - s.pos) throw new CborError("truncated");
94
+ const out = new Map();
95
+ for (let i = 0; i < count; i++) {
96
+ const key = item(buf, s, depth + 1);
97
+ if (typeof key !== "number" && typeof key !== "string") {
98
+ throw new CborError("unsupported map key");
99
+ }
100
+ if (out.has(key)) throw new CborError("duplicate map key");
101
+ out.set(key, item(buf, s, depth + 1));
102
+ }
103
+ return out;
104
+ }
105
+ case 6:
106
+ throw new CborError("tags are not accepted");
107
+ default:
108
+ if (info === 20) return false;
109
+ if (info === 21) return true;
110
+ if (info === 22) return null;
111
+ throw new CborError("unsupported simple value or float");
112
+ }
113
+ }
114
+
115
+ /** Reads one item starting at `offset`; returns the value and the offset after it. */
116
+ export function readCbor(input, offset = 0) {
117
+ if (input.length > CBOR_MAX_BYTES) throw new CborError("input too large");
118
+ const state = { pos: offset };
119
+ const value = item(input, state, 0);
120
+ return { value, end: state.pos };
121
+ }
122
+
123
+ /** Reads exactly one item and nothing after it. */
124
+ export function decodeCborExact(input) {
125
+ const { value, end } = readCbor(input);
126
+ if (end !== input.length) throw new CborError("trailing bytes");
127
+ return value;
128
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * contract.mjs - the fixed verb contract shared with the phone, and the
3
+ * argument validation every verb passes before anything runs.
4
+ *
5
+ * verbs.json is the shared contract: it holds the contract version, the
6
+ * active phase and, per verb, its phase, whether it mutates, whether it
7
+ * targets a run and an argument schema. A verb exists only if it is in the
8
+ * file and its phase is at or below the phase this computer implements
9
+ * (IMPLEMENTED_PHASE), whatever the file says is active: the site cannot
10
+ * raise it.
11
+ *
12
+ * @module pipeline/scripts/remote/contract
13
+ */
14
+
15
+ import { readFileSync } from "node:fs";
16
+
17
+ export const CONTRACT = JSON.parse(readFileSync(new URL("./verbs.json", import.meta.url), "utf8"));
18
+
19
+ /** The highest verb phase this implementation executes. */
20
+ export const IMPLEMENTED_PHASE = 1;
21
+
22
+ const VERB_NAME = /^[a-z][a-z0-9_]{0,31}$/;
23
+
24
+ /**
25
+ * The verb's spec when it is a contract verb whose phase is at or below both
26
+ * the contract's active phase and the implemented phase, else null.
27
+ */
28
+ export function verbSpec(name, contract = CONTRACT) {
29
+ if (typeof name !== "string" || !VERB_NAME.test(name)) return null;
30
+ if (!Object.prototype.hasOwnProperty.call(contract.verbs, name)) return null;
31
+ const spec = contract.verbs[name];
32
+ if (spec.phase > contract.activePhase || spec.phase > IMPLEMENTED_PHASE) return null;
33
+ return spec;
34
+ }
35
+
36
+ /**
37
+ * Checks an argument object against a verb's schema. Unknown keys, wrong
38
+ * types and out-of-range values are refused; defaults are filled in.
39
+ *
40
+ * @returns {{ok: true, args: Record<string, string|number>} | {ok: false, error: string}}
41
+ */
42
+ export function validateArgs(spec, input) {
43
+ if (!input || typeof input !== "object" || Array.isArray(input)) {
44
+ return { ok: false, error: "args" };
45
+ }
46
+ for (const key of Object.keys(input)) {
47
+ if (!Object.prototype.hasOwnProperty.call(spec.args, key)) {
48
+ return { ok: false, error: `unknown:${key}` };
49
+ }
50
+ }
51
+ const out = {};
52
+ for (const [key, arg] of Object.entries(spec.args)) {
53
+ const value = input[key];
54
+ if (value === undefined) {
55
+ if (arg.required) return { ok: false, error: `missing:${key}` };
56
+ if (arg.default !== undefined) out[key] = arg.default;
57
+ continue;
58
+ }
59
+ if (arg.type === "string") {
60
+ if (typeof value !== "string" || value.length === 0)
61
+ return { ok: false, error: `type:${key}` };
62
+ if (arg.maxLength !== undefined && value.length > arg.maxLength) {
63
+ return { ok: false, error: `length:${key}` };
64
+ }
65
+ if (arg.pattern && !new RegExp(arg.pattern).test(value)) {
66
+ return { ok: false, error: `pattern:${key}` };
67
+ }
68
+ } else if (arg.type === "idlist") {
69
+ if (!Array.isArray(value) || value.length < arg.minItems || value.length > arg.maxItems) {
70
+ return { ok: false, error: `length:${key}` };
71
+ }
72
+ const pattern = new RegExp(arg.pattern);
73
+ if (!value.every((item) => typeof item === "string" && pattern.test(item))) {
74
+ return { ok: false, error: `pattern:${key}` };
75
+ }
76
+ if (new Set(value).size !== value.length) return { ok: false, error: `duplicate:${key}` };
77
+ out[key] = [...value];
78
+ continue;
79
+ } else if (arg.type === "integer") {
80
+ if (
81
+ typeof value !== "number" ||
82
+ !Number.isInteger(value) ||
83
+ value < arg.min ||
84
+ value > arg.max
85
+ ) {
86
+ return { ok: false, error: `range:${key}` };
87
+ }
88
+ } else if (arg.type === "enum") {
89
+ if (typeof value !== "string" || !arg.values.includes(value)) {
90
+ return { ok: false, error: `enum:${key}` };
91
+ }
92
+ } else {
93
+ return { ok: false, error: `schema:${key}` };
94
+ }
95
+ out[key] = value;
96
+ }
97
+ return { ok: true, args: out };
98
+ }