@mmerterden/multi-agent-pipeline 23.3.0 → 23.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +27 -8
  3. package/README.tr.md +28 -9
  4. package/SECURITY.md +16 -0
  5. package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
  6. package/docs/adr/0010-own-code-graph.md +299 -8
  7. package/docs/architecture.md +3 -3
  8. package/docs/ecosystem.md +10 -10
  9. package/docs/engineering.md +4 -4
  10. package/docs/facts.json +8 -8
  11. package/docs/features.md +5 -5
  12. package/docs/performance.md +17 -17
  13. package/install/_dev-only-files.mjs +9 -0
  14. package/install/_platform-filter.mjs +2 -55
  15. package/install/claude.mjs +28 -2
  16. package/install/codex.mjs +1 -3
  17. package/install/copilot.mjs +4 -8
  18. package/install/templates/claude-hooks.json +32 -1
  19. package/manifest.json +236 -167
  20. package/package.json +11 -3
  21. package/pipeline/commands/multi-agent/SKILL.md +1 -1
  22. package/pipeline/commands/multi-agent/design-check/SKILL.md +3 -2
  23. package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
  24. package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
  25. package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
  26. package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
  27. package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
  28. package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
  29. package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
  30. package/pipeline/contract/CHANGELOG.md +63 -0
  31. package/pipeline/contract/README.md +1 -0
  32. package/pipeline/contract/build.mjs +13 -1
  33. package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
  34. package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
  35. package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
  36. package/pipeline/contract/fixtures/runs-empty.json +1 -1
  37. package/pipeline/contract/fixtures/runs-failed.json +4 -1
  38. package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
  39. package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
  40. package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
  41. package/pipeline/contract/fixtures/runs-running.json +4 -1
  42. package/pipeline/contract/manifest.json +41 -15
  43. package/pipeline/contract/types/index.d.ts +81 -3
  44. package/pipeline/lib/detach-self.mjs +95 -0
  45. package/pipeline/lib/public-mcp-servers.mjs +33 -0
  46. package/pipeline/lib/rotated-log.mjs +93 -0
  47. package/pipeline/lib/stack-detect.sh +1 -1
  48. package/pipeline/lib/tls-trust.mjs +29 -0
  49. package/pipeline/lib/usage-lifecycle.mjs +9 -11
  50. package/pipeline/lib/usage-names.generated.mjs +613 -0
  51. package/pipeline/lib/usage-run-key.mjs +235 -0
  52. package/pipeline/lib/usage-vocab.mjs +210 -0
  53. package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
  54. package/pipeline/multi-agent-refs/analysis/render.md +1 -1
  55. package/pipeline/multi-agent-refs/channels/generator.md +4 -5
  56. package/pipeline/multi-agent-refs/cross-cli-contract.md +3 -3
  57. package/pipeline/multi-agent-refs/design-check/init-inventory.md +11 -1
  58. package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
  59. package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
  60. package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
  61. package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
  62. package/pipeline/multi-agent-refs/features/model-fallback.md +6 -4
  63. package/pipeline/multi-agent-refs/features/remote-control.md +253 -0
  64. package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
  65. package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
  66. package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
  67. package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
  68. package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
  69. package/pipeline/multi-agent-refs/features/usage-reporting.md +255 -27
  70. package/pipeline/multi-agent-refs/help/en.md +3 -2
  71. package/pipeline/multi-agent-refs/help/tr.md +3 -2
  72. package/pipeline/multi-agent-refs/knowledge.md +1 -1
  73. package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -2
  74. package/pipeline/multi-agent-refs/phases/operations.md +2 -2
  75. package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
  76. package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
  77. package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -0
  78. package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
  79. package/pipeline/multi-agent-refs/platform-parity.md +2 -2
  80. package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
  81. package/pipeline/office/index.html +1309 -236
  82. package/pipeline/office/toolkit.json +1 -1
  83. package/pipeline/rules/outside-the-pipeline.md +1 -1
  84. package/pipeline/schemas/activity.schema.json +23 -0
  85. package/pipeline/schemas/agent-state.schema.json +6 -1
  86. package/pipeline/schemas/code-graph-calls.schema.json +254 -0
  87. package/pipeline/schemas/code-graph-docs.schema.json +223 -0
  88. package/pipeline/schemas/code-graph-infra.schema.json +227 -0
  89. package/pipeline/schemas/code-graph.schema.json +2 -2
  90. package/pipeline/schemas/examples/design-check-config.json +27 -0
  91. package/pipeline/schemas/learning-curve.schema.json +67 -0
  92. package/pipeline/schemas/mcp-health.schema.json +96 -0
  93. package/pipeline/schemas/office-jobs.json +69 -2
  94. package/pipeline/schemas/office-jobs.schema.json +8 -1
  95. package/pipeline/schemas/phases.json +5 -0
  96. package/pipeline/schemas/phases.schema.json +8 -0
  97. package/pipeline/schemas/prefs.schema.json +46 -12
  98. package/pipeline/schemas/runs-index.schema.json +17 -0
  99. package/pipeline/schemas/toolkit-path-params.json +78 -8
  100. package/pipeline/scripts/README.md +1 -0
  101. package/pipeline/scripts/_code-graph.mjs +184 -103
  102. package/pipeline/scripts/_contract-core.mjs +1 -1
  103. package/pipeline/scripts/_contract-routes-office.mjs +33 -0
  104. package/pipeline/scripts/_diff-impact.mjs +21 -2
  105. package/pipeline/scripts/_graph-sidecars.mjs +372 -0
  106. package/pipeline/scripts/_http-post.mjs +103 -115
  107. package/pipeline/scripts/_safe-read.mjs +57 -0
  108. package/pipeline/scripts/_skill-practices.mjs +26 -0
  109. package/pipeline/scripts/_strip-code.mjs +380 -0
  110. package/pipeline/scripts/activity-snapshot.mjs +13 -1
  111. package/pipeline/scripts/aggregate-metrics.mjs +3 -5
  112. package/pipeline/scripts/build-stack-plugins.mjs +1 -47
  113. package/pipeline/scripts/call-graph/index.mjs +78 -0
  114. package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
  115. package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
  116. package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
  117. package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
  118. package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
  119. package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
  120. package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
  121. package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
  122. package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
  123. package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
  124. package/pipeline/scripts/call-graph/lex.mjs +396 -0
  125. package/pipeline/scripts/call-graph/platform.mjs +86 -0
  126. package/pipeline/scripts/call-graph/profiles.mjs +89 -0
  127. package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
  128. package/pipeline/scripts/call-graph/scan.mjs +267 -0
  129. package/pipeline/scripts/code-graph-rules/android.json +7 -2
  130. package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
  131. package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
  132. package/pipeline/scripts/code-graph-rules/go.json +2 -1
  133. package/pipeline/scripts/code-graph-rules/ios.json +3 -1
  134. package/pipeline/scripts/code-graph-rules/java.json +76 -0
  135. package/pipeline/scripts/code-graph-rules/node.json +7 -2
  136. package/pipeline/scripts/code-graph-rules/python.json +6 -2
  137. package/pipeline/scripts/code-graph-rules/rust.json +105 -0
  138. package/pipeline/scripts/contract-server.mjs +3 -0
  139. package/pipeline/scripts/design-check-config.mjs +205 -0
  140. package/pipeline/scripts/feedback-send.mjs +26 -26
  141. package/pipeline/scripts/gate-ledger.mjs +2 -1
  142. package/pipeline/scripts/gen-facts.mjs +1 -2
  143. package/pipeline/scripts/gen-usage-names.mjs +124 -0
  144. package/pipeline/scripts/graph-affected.mjs +109 -20
  145. package/pipeline/scripts/graph-build.mjs +95 -15
  146. package/pipeline/scripts/graph-export.mjs +272 -0
  147. package/pipeline/scripts/graph-hint.mjs +15 -2
  148. package/pipeline/scripts/graph-query.mjs +305 -26
  149. package/pipeline/scripts/graph-report.mjs +187 -1
  150. package/pipeline/scripts/health-report.mjs +3 -4
  151. package/pipeline/scripts/infra/docs.mjs +317 -0
  152. package/pipeline/scripts/infra/extract.mjs +998 -0
  153. package/pipeline/scripts/infra/graph.mjs +245 -0
  154. package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
  155. package/pipeline/scripts/job-launch.mjs +67 -2
  156. package/pipeline/scripts/learning-curve.mjs +288 -178
  157. package/pipeline/scripts/log-metric.sh +10 -1
  158. package/pipeline/scripts/mcp-health.mjs +309 -0
  159. package/pipeline/scripts/note-agent-event.mjs +3 -4
  160. package/pipeline/scripts/note-command-use.mjs +333 -0
  161. package/pipeline/scripts/note-command-use.sh +126 -0
  162. package/pipeline/scripts/note-mcp-call.sh +89 -0
  163. package/pipeline/scripts/note-mcp-failure.mjs +272 -1
  164. package/pipeline/scripts/note-session.sh +62 -3
  165. package/pipeline/scripts/note-skill-use.mjs +58 -2
  166. package/pipeline/scripts/office-build.mjs +115 -1
  167. package/pipeline/scripts/office-memory.mjs +14 -5
  168. package/pipeline/scripts/pair.mjs +333 -0
  169. package/pipeline/scripts/pre-push-check.sh +1 -1
  170. package/pipeline/scripts/remote/cbor.mjs +128 -0
  171. package/pipeline/scripts/remote/contract.mjs +98 -0
  172. package/pipeline/scripts/remote/handler.mjs +330 -0
  173. package/pipeline/scripts/remote/handles.mjs +57 -0
  174. package/pipeline/scripts/remote/lifecycle.mjs +186 -0
  175. package/pipeline/scripts/remote/listener.mjs +204 -0
  176. package/pipeline/scripts/remote/lockout.mjs +103 -0
  177. package/pipeline/scripts/remote/nonces.mjs +61 -0
  178. package/pipeline/scripts/remote/pairing.mjs +519 -0
  179. package/pipeline/scripts/remote/qr-encode.mjs +459 -0
  180. package/pipeline/scripts/remote/store.mjs +191 -0
  181. package/pipeline/scripts/remote/transport.mjs +211 -0
  182. package/pipeline/scripts/remote/verbs.json +70 -0
  183. package/pipeline/scripts/remote/verbs.mjs +217 -0
  184. package/pipeline/scripts/remote/webauthn.mjs +169 -0
  185. package/pipeline/scripts/remote/wire.mjs +364 -0
  186. package/pipeline/scripts/remote-listener.mjs +83 -0
  187. package/pipeline/scripts/route-learn.mjs +4 -4
  188. package/pipeline/scripts/run-kill.mjs +1 -1
  189. package/pipeline/scripts/run-write.mjs +13 -2
  190. package/pipeline/scripts/runs-index.mjs +30 -3
  191. package/pipeline/scripts/search-logs.sh +9 -0
  192. package/pipeline/scripts/session-brief.mjs +458 -0
  193. package/pipeline/scripts/session-brief.sh +130 -0
  194. package/pipeline/scripts/skill-usage.mjs +16 -5
  195. package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
  196. package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
  197. package/pipeline/scripts/test-gap-rules/java.json +20 -0
  198. package/pipeline/scripts/test-gap-rules/rust.json +14 -0
  199. package/pipeline/scripts/token-budget-report.mjs +3 -2
  200. package/pipeline/scripts/uninstall.mjs +29 -0
  201. package/pipeline/scripts/usage-access.mjs +16 -31
  202. package/pipeline/scripts/usage-health.mjs +31 -62
  203. package/pipeline/scripts/usage-register-beacon.mjs +11 -22
  204. package/pipeline/scripts/usage-register.mjs +39 -29
  205. package/pipeline/scripts/usage-report.mjs +579 -178
  206. package/pipeline/scripts/validate-code-graph.mjs +361 -111
  207. package/pipeline/scripts/write-state.mjs +39 -0
  208. package/pipeline/skills/.skill-manifest.json +21 -17
  209. package/pipeline/skills/.skills-index.json +13 -2
  210. package/pipeline/skills/shared/README.md +5 -4
  211. package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
  212. package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
  213. package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
  214. package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
  215. package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
  216. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
  217. package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
  218. package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
  219. package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
  220. package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
  221. package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
  222. package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
  223. package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
  224. package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
  225. package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
  226. package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
  227. package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
  228. package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
  229. package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
  230. package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
  231. package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
  232. package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
  233. package/pipeline/skills/skills-index.md +3 -2
  234. package/docs/FIGMA_PIPELINE.md +0 -137
  235. package/pipeline/lib/identifier-scan.mjs +0 -156
  236. package/pipeline/scripts/_renamed-skills.mjs +0 -164
  237. package/pipeline/scripts/publish-staged.mjs +0 -324
  238. package/pipeline/skills/renamed.json +0 -30
  239. package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
@@ -24,12 +24,14 @@
24
24
  */
25
25
 
26
26
  import { createHash } from "node:crypto";
27
- import { readFileSync, readdirSync, writeFileSync } from "node:fs";
27
+ import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
28
28
  import { deflateSync, inflateSync } from "node:zlib";
29
29
  import { basename, join } from "node:path";
30
30
  import { pathToFileURL } from "node:url";
31
+ import vm from "node:vm";
31
32
 
32
33
  import { APP_ICON_SIZES, THEME_COLOR } from "./office-webapp.mjs";
34
+ import { catalog, commandsDir } from "./commands.mjs";
33
35
 
34
36
  const ROOT = join(import.meta.dirname, "..");
35
37
  const SRC = join(ROOT, "office-src");
@@ -886,6 +888,7 @@ export const APP_MODULES = [
886
888
  "panel-server.js",
887
889
  "panel-archive.js",
888
890
  "demo.js",
891
+ "progress-draft.js",
889
892
  "start.js",
890
893
  ];
891
894
  // The /* global */ and /* exported */ lines that tell the linter what a module
@@ -901,7 +904,117 @@ export function appSource() {
901
904
  ).join("\n\n");
902
905
  }
903
906
 
907
+ // --- how the office handles each command ---------------------------------------
908
+ // office-src/command-routes.json names every command: "start" (a job in
909
+ // schemas/office-jobs.json runs it), "window:<id>" or "terminal:<reason>".
910
+ // Nothing is defaulted: a command without an entry, or an entry without a
911
+ // command, fails the build, so a new command is a decision and not a silent
912
+ // terminal-only.
913
+
914
+ export const TERMINAL_REASONS = ["approval", "device", "freeform", "machine", "self"];
915
+ const ROOT_COMMAND = "multi-agent";
916
+
917
+ /** The page's own first-listed-wins job lookup, run from core.js so there is one definition. */
918
+ export function pageJobByCommand(jobs) {
919
+ const core = readFileSync(join(SRC, "app", "core.js"), "utf8");
920
+ const start = core.indexOf("function jobByCommand(");
921
+ const end = core.indexOf("\n}\n", start);
922
+ if (start < 0 || end < 0) throw new Error("core.js has no jobByCommand function");
923
+ const ctx = vm.createContext({});
924
+ vm.runInContext(`${core.slice(start, end + 3)}\nthis.fn = jobByCommand;`, ctx);
925
+ return ctx.fn(jobs);
926
+ }
927
+
928
+ /** Every command the office can be asked about: the catalog plus the root command. */
929
+ export function commandIds(dir) {
930
+ const cat = catalog(dir);
931
+ if (!cat) return [];
932
+ const ids = cat.commands.map((c) => c.id);
933
+ if (existsSync(join(commandsDir(dir), "SKILL.md")) && !ids.includes(ROOT_COMMAND))
934
+ ids.unshift(ROOT_COMMAND);
935
+ return ids;
936
+ }
937
+
938
+ /** The windows the page can open: every `loaders.<id> =` its modules assign. */
939
+ export function windowIds() {
940
+ const ids = new Set();
941
+ for (const m of appSource().matchAll(/\bloaders\.([A-Za-z]\w*)\s*=/g)) ids.add(m[1]);
942
+ return ids;
943
+ }
944
+
945
+ /** Keys that appear more than once in a JSON object text; JSON.parse keeps the last silently. */
946
+ export function duplicateKeys(text) {
947
+ const seen = new Set();
948
+ const twice = [];
949
+ for (const m of text.matchAll(/"((?:[^"\\]|\\.)*)"\s*:/g)) {
950
+ if (seen.has(m[1]) && !twice.includes(m[1])) twice.push(m[1]);
951
+ seen.add(m[1]);
952
+ }
953
+ return twice;
954
+ }
955
+
956
+ /** The routes table and what is wrong with its text. */
957
+ export function readRoutes(file) {
958
+ const text = readFileSync(file, "utf8");
959
+ return {
960
+ routes: JSON.parse(text).commands,
961
+ problems: duplicateKeys(text).map(
962
+ (id) => `command-routes.json names "${id}" more than once; only the last would count`,
963
+ ),
964
+ };
965
+ }
966
+
967
+ const has = (table, key) => Object.hasOwn(table, key);
968
+
969
+ /** What is wrong with a routes table next to the command list, the jobs and the windows. */
970
+ export function routeProblems({ ids, routes, jobs, windows = windowIds() }) {
971
+ const problems = [];
972
+ const known = new Set(ids);
973
+ const byCommand = pageJobByCommand(jobs);
974
+ for (const id of ids) {
975
+ if (!has(routes, id)) {
976
+ problems.push(`command-routes.json has no entry for the command "${id}"`);
977
+ continue;
978
+ }
979
+ const r = routes[id];
980
+ const window = /^window:(\w+)$/.exec(r);
981
+ const terminal = /^terminal:(\w+)$/.exec(r);
982
+ if (r === "start") {
983
+ if (!byCommand.has(id))
984
+ problems.push(`"${id}" is routed "start" but no job in office-jobs.json runs it`);
985
+ } else if (window || terminal) {
986
+ if (byCommand.has(id))
987
+ problems.push(
988
+ `"${id}" has a job in office-jobs.json, so its route must be "start", not "${r}"`,
989
+ );
990
+ if (terminal && !TERMINAL_REASONS.includes(terminal[1]))
991
+ problems.push(`"${id}" has the unknown terminal reason "${terminal[1]}"`);
992
+ if (window && !windows.has(window[1]))
993
+ problems.push(`"${id}" opens the window "${window[1]}", which the page does not have`);
994
+ } else
995
+ problems.push(`"${id}" has the route "${r}"; use start, window:<id> or terminal:<reason>`);
996
+ }
997
+ for (const id of Object.keys(routes))
998
+ if (!known.has(id))
999
+ problems.push(`command-routes.json has an entry for "${id}", which is not a command`);
1000
+ for (const id of byCommand.keys())
1001
+ if (!known.has(id)) problems.push(`office-jobs.json runs "${id}", which is not a command`);
1002
+ return problems;
1003
+ }
1004
+
1005
+ /** The routes problems for the repository's own command tree; empty when it has none. */
1006
+ export function repoRouteProblems() {
1007
+ const tree = join(ROOT, "commands", "multi-agent");
1008
+ if (!existsSync(tree)) return [];
1009
+ const ids = commandIds(tree);
1010
+ const { routes, problems } = readRoutes(join(SRC, "command-routes.json"));
1011
+ const jobs = JSON.parse(readFileSync(join(ROOT, "schemas", "office-jobs.json"), "utf8")).jobs;
1012
+ return [...problems, ...routeProblems({ ids, routes, jobs })];
1013
+ }
1014
+
904
1015
  export function build() {
1016
+ const problems = repoRouteProblems();
1017
+ if (problems.length) throw new Error(`command-routes.json: ${problems.join("; ")}`);
905
1018
  const read = (f) => readFileSync(join(SRC, f), "utf8");
906
1019
  const strings = JSON.parse(read("strings.json"));
907
1020
  const sprites = atlas();
@@ -913,6 +1026,7 @@ export function build() {
913
1026
  `const ATLAS = ${JSON.stringify(sprites)};`,
914
1027
  `const STRINGS = ${JSON.stringify(strings)};`,
915
1028
  `const EMPLOYEES = ${JSON.stringify(staff.people)};`,
1029
+ `const COMMAND_ROUTES = ${JSON.stringify(JSON.parse(read("command-routes.json")))};`,
916
1030
  'const spriteUrl = (name) => "/office/assets/" + name + ".png";',
917
1031
  read("world.js").trim(),
918
1032
  appSource(),
@@ -122,6 +122,15 @@ export async function store(path, maxBytes) {
122
122
  }
123
123
  }
124
124
 
125
+ /**
126
+ * A store that rotates to `<path>.1`: both generations as one store, the
127
+ * previous one first, so the count and the tail run across a rotation.
128
+ */
129
+ export async function rotatedStore(path, maxBytes) {
130
+ const [older, current] = await Promise.all([store(`${path}.1`, maxBytes), store(path, maxBytes)]);
131
+ return { count: older.count + current.count, tail: [...older.tail, ...current.tail] };
132
+ }
133
+
125
134
  const ms = (v) => {
126
135
  const t = Date.parse(v ?? "");
127
136
  return Number.isFinite(t) ? t : null;
@@ -140,11 +149,11 @@ async function shelf(name, r, now, R, maxBytes) {
140
149
  sizeKb: Math.round(st.size / 1024),
141
150
  };
142
151
  }
143
- const [learnings, findings, notes] = await Promise.all(
144
- ["learnings-ledger.jsonl", "triage-corpus.jsonl", "session-notes.jsonl"].map((f) =>
145
- store(join(dir, f), maxBytes),
146
- ),
147
- );
152
+ const [learnings, findings, notes] = await Promise.all([
153
+ store(join(dir, "learnings-ledger.jsonl"), maxBytes),
154
+ store(join(dir, "triage-corpus.jsonl"), maxBytes),
155
+ rotatedStore(join(dir, "session-notes.jsonl"), maxBytes),
156
+ ]);
148
157
  const times = [...learnings.tail, ...findings.tail, ...notes.tail]
149
158
  .map((x) => ms(x.ts))
150
159
  .filter((t) => t !== null);
@@ -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
+ }