@mmerterden/multi-agent-pipeline 20.44.0 → 21.0.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 (419) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/README.md +31 -35
  3. package/README.tr.md +30 -34
  4. package/SECURITY.md +4 -4
  5. package/docs/architecture.md +6 -6
  6. package/docs/ecosystem.md +35 -30
  7. package/docs/facts.json +10 -8
  8. package/docs/features.md +6 -5
  9. package/index.js +1 -1
  10. package/install/_common.mjs +5 -1
  11. package/install/_mcp-register.mjs +80 -5
  12. package/install/_plugin-skills.mjs +1 -1
  13. package/install/_unattended-profile.mjs +12 -3
  14. package/install/claude.mjs +45 -4
  15. package/install/codex.mjs +2 -2
  16. package/install/index.mjs +49 -9
  17. package/install/templates/claude-hooks.json +2 -2
  18. package/install/templates/codex-instructions.md +1 -1
  19. package/install/templates/copilot-instructions.md +7 -7
  20. package/manifest.json +404 -404
  21. package/package.json +4 -4
  22. package/pipeline/agents/security-auditor.md +2 -2
  23. package/pipeline/agents/test-gen-analyst.md +1 -1
  24. package/pipeline/commands/archive-guard.md +6 -6
  25. package/pipeline/commands/multi-agent/SKILL.md +23 -2
  26. package/pipeline/commands/multi-agent/analysis/SKILL.md +8 -0
  27. package/pipeline/commands/multi-agent/analysis-jira/SKILL.md +8 -0
  28. package/pipeline/commands/multi-agent/autopilot-off/SKILL.md +10 -6
  29. package/pipeline/commands/multi-agent/bug-bash/SKILL.md +1 -1
  30. package/pipeline/commands/multi-agent/channels/SKILL.md +8 -0
  31. package/pipeline/commands/multi-agent/complaint-analysis/SKILL.md +8 -0
  32. package/pipeline/commands/multi-agent/create-jira/SKILL.md +8 -0
  33. package/pipeline/commands/multi-agent/design-check/SKILL.md +9 -1
  34. package/pipeline/commands/multi-agent/issue/SKILL.md +8 -0
  35. package/pipeline/commands/multi-agent/jira/SKILL.md +8 -0
  36. package/pipeline/commands/multi-agent/kill/SKILL.md +8 -0
  37. package/pipeline/commands/multi-agent/office-off/SKILL.md +3 -4
  38. package/pipeline/commands/multi-agent/office-on/SKILL.md +2 -6
  39. package/pipeline/commands/multi-agent/office-status/SKILL.md +1 -6
  40. package/pipeline/commands/multi-agent/prune-logs/SKILL.md +2 -2
  41. package/pipeline/commands/multi-agent/purge/SKILL.md +8 -0
  42. package/pipeline/commands/multi-agent/refactor/SKILL.md +16 -8
  43. package/pipeline/commands/multi-agent/research/SKILL.md +1 -1
  44. package/pipeline/commands/multi-agent/resume/SKILL.md +8 -0
  45. package/pipeline/commands/multi-agent/review/SKILL.md +8 -0
  46. package/pipeline/commands/multi-agent/review-analysis/SKILL.md +8 -0
  47. package/pipeline/commands/multi-agent/review-issue/SKILL.md +8 -0
  48. package/pipeline/commands/multi-agent/review-jira/SKILL.md +8 -0
  49. package/pipeline/commands/multi-agent/review-priority/SKILL.md +8 -0
  50. package/pipeline/commands/multi-agent/route-on/SKILL.md +1 -1
  51. package/pipeline/commands/multi-agent/routines/SKILL.md +36 -14
  52. package/pipeline/commands/multi-agent/save/SKILL.md +1 -1
  53. package/pipeline/commands/multi-agent/scaffold/SKILL.md +8 -0
  54. package/pipeline/commands/multi-agent/search/SKILL.md +4 -4
  55. package/pipeline/commands/multi-agent/security-review/SKILL.md +9 -4
  56. package/pipeline/commands/multi-agent/setup/SKILL.md +7 -2
  57. package/pipeline/commands/multi-agent/store-ready/SKILL.md +5 -3
  58. package/pipeline/commands/multi-agent/sync/SKILL.md +20 -12
  59. package/pipeline/commands/multi-agent/test/SKILL.md +1 -1
  60. package/pipeline/commands/multi-agent/test-accessibility/SKILL.md +1 -1
  61. package/pipeline/commands/multi-agent/test-dark-mode/SKILL.md +1 -1
  62. package/pipeline/commands/multi-agent/test-dynamic-type/SKILL.md +1 -1
  63. package/pipeline/commands/multi-agent/test-gen/SKILL.md +1 -1
  64. package/pipeline/commands/multi-agent/test-screenshots/SKILL.md +1 -1
  65. package/pipeline/commands/multi-agent/testflight-validation/SKILL.md +1 -1
  66. package/pipeline/commands/multi-agent/uninstall/SKILL.md +3 -3
  67. package/pipeline/commands/multi-agent/update/SKILL.md +9 -2
  68. package/pipeline/commands/sim-test.md +5 -5
  69. package/pipeline/contract/CHANGELOG.md +49 -0
  70. package/pipeline/contract/README.md +34 -29
  71. package/pipeline/contract/build.mjs +0 -5
  72. package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
  73. package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
  74. package/pipeline/contract/manifest.json +62 -122
  75. package/pipeline/contract/types/index.d.ts +97 -49
  76. package/pipeline/lib/credential-inventory.sh +3 -2
  77. package/pipeline/lib/cross-repo.mjs +11 -6
  78. package/pipeline/lib/fetch-crashlytics.sh +5 -2
  79. package/pipeline/lib/mcp-rename.mjs +508 -0
  80. package/pipeline/lib/model-dispatch.sh +1 -1
  81. package/pipeline/lib/office-legacy.mjs +207 -0
  82. package/pipeline/lib/outbound-gate.mjs +8 -2
  83. package/pipeline/lib/route-state.sh +2 -2
  84. package/pipeline/lib/routine-secret-scan.mjs +166 -0
  85. package/pipeline/lib/toolkit-llm.sh +12 -10
  86. package/pipeline/lib/unattended.mjs +1 -1
  87. package/pipeline/lib/unattended.sh +1 -1
  88. package/pipeline/lib/untrusted-fence.mjs +1 -1
  89. package/pipeline/lib/usage-endpoint.mjs +32 -0
  90. package/pipeline/lib/usage-token.mjs +76 -0
  91. package/pipeline/multi-agent-refs/_input-parser.md +22 -0
  92. package/pipeline/multi-agent-refs/analysis/locked.md +1 -1
  93. package/pipeline/multi-agent-refs/android-guide.md +2 -2
  94. package/pipeline/multi-agent-refs/audit-guide.md +1 -1
  95. package/pipeline/multi-agent-refs/complaint-analysis/phases.md +1 -1
  96. package/pipeline/multi-agent-refs/cross-cli-contract.md +20 -18
  97. package/pipeline/multi-agent-refs/design-check/build-launch.md +2 -2
  98. package/pipeline/multi-agent-refs/design-check/compare.md +2 -2
  99. package/pipeline/multi-agent-refs/design-check/drive-capture.md +1 -1
  100. package/pipeline/multi-agent-refs/design-check/export.md +1 -1
  101. package/pipeline/multi-agent-refs/design-check/init-inventory.md +2 -2
  102. package/pipeline/multi-agent-refs/design-check/mcp-currency-gate.md +4 -4
  103. package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
  104. package/pipeline/multi-agent-refs/features/build-facts.md +115 -0
  105. package/pipeline/multi-agent-refs/features/code-graph.md +8 -8
  106. package/pipeline/multi-agent-refs/features/code-intelligence.md +5 -5
  107. package/pipeline/multi-agent-refs/features/design-conformance.md +4 -4
  108. package/pipeline/multi-agent-refs/features/doctor.md +43 -4
  109. package/pipeline/multi-agent-refs/features/exploratory-testing.md +1 -1
  110. package/pipeline/multi-agent-refs/features/external-context-injection.md +1 -1
  111. package/pipeline/multi-agent-refs/features/free-models.md +5 -5
  112. package/pipeline/multi-agent-refs/features/office-threat-model.md +9 -32
  113. package/pipeline/multi-agent-refs/features/plan-attachment.md +55 -0
  114. package/pipeline/multi-agent-refs/features/product-context.md +1 -1
  115. package/pipeline/multi-agent-refs/features/routine-sharing.md +196 -0
  116. package/pipeline/multi-agent-refs/features/security-audit.md +3 -3
  117. package/pipeline/multi-agent-refs/features/test-classification.md +2 -2
  118. package/pipeline/multi-agent-refs/features/unattended-gates.md +1 -1
  119. package/pipeline/multi-agent-refs/features/unattended-security.md +8 -23
  120. package/pipeline/multi-agent-refs/features/usage-reporting.md +172 -4
  121. package/pipeline/multi-agent-refs/features/visual-evidence.md +1 -1
  122. package/pipeline/multi-agent-refs/help/en.md +138 -274
  123. package/pipeline/multi-agent-refs/help/tr.md +140 -274
  124. package/pipeline/multi-agent-refs/keychain.md +2 -2
  125. package/pipeline/multi-agent-refs/knowledge.md +4 -4
  126. package/pipeline/multi-agent-refs/orchestrator/copilot-pipeline.md +3 -3
  127. package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -0
  128. package/pipeline/multi-agent-refs/outside-the-pipeline.md +2 -2
  129. package/pipeline/multi-agent-refs/phases/modes.md +17 -0
  130. package/pipeline/multi-agent-refs/phases/phase-0-init.md +21 -2
  131. package/pipeline/multi-agent-refs/phases/phase-1-plan.md +8 -5
  132. package/pipeline/multi-agent-refs/phases/phase-2-dev.md +2 -2
  133. package/pipeline/multi-agent-refs/phases/phase-3-review.md +4 -4
  134. package/pipeline/multi-agent-refs/phases/phase-5-report.md +10 -0
  135. package/pipeline/multi-agent-refs/refactor/sweep.md +4 -4
  136. package/pipeline/multi-agent-refs/refactor/toolkit-research.md +1 -1
  137. package/pipeline/multi-agent-refs/research/engine.md +1 -1
  138. package/pipeline/multi-agent-refs/rules.md +2 -2
  139. package/pipeline/multi-agent-refs/setup/app-store-connect.md +2 -2
  140. package/pipeline/multi-agent-refs/setup/firebase.md +3 -2
  141. package/pipeline/multi-agent-refs/setup/google-play.md +1 -1
  142. package/pipeline/multi-agent-refs/setup/token-save-flow.md +3 -2
  143. package/pipeline/multi-agent-refs/store-ready/gate-1-static.md +12 -2
  144. package/pipeline/multi-agent-refs/store-ready/gate-3-policy.md +3 -3
  145. package/pipeline/multi-agent-refs/store-ready/gates.md +2 -1
  146. package/pipeline/multi-agent-refs/store-ready/report.md +10 -1
  147. package/pipeline/multi-agent-refs/swiftui-guide.md +2 -2
  148. package/pipeline/multi-agent-refs/sync/codex.md +1 -1
  149. package/pipeline/multi-agent-refs/sync/dev-toolkit.md +5 -5
  150. package/pipeline/multi-agent-refs/sync/overview.md +2 -2
  151. package/pipeline/multi-agent-refs/sync/stack-plugins.md +2 -2
  152. package/pipeline/multi-agent-refs/tracker-contract.md +1 -1
  153. package/pipeline/multi-agent-refs/unattended-contract.md +1 -2
  154. package/pipeline/multi-agent-refs/web-guide.md +2 -2
  155. package/pipeline/office/index.html +645 -144
  156. package/pipeline/office/toolkit.json +1 -1
  157. package/pipeline/preferences-template.json +6 -6
  158. package/pipeline/rules/figma-pipeline.md +2 -2
  159. package/pipeline/rules/outside-the-pipeline.md +1 -1
  160. package/pipeline/schemas/activity-chat.schema.json +1 -1
  161. package/pipeline/schemas/activity-roles.schema.json +1 -1
  162. package/pipeline/schemas/activity.schema.json +1 -1
  163. package/pipeline/schemas/agent-state.schema.json +36 -2
  164. package/pipeline/schemas/analysis-output.schema.json +1 -1
  165. package/pipeline/schemas/answer-request.schema.json +1 -1
  166. package/pipeline/schemas/answer-result.schema.json +1 -1
  167. package/pipeline/schemas/autopilot-config.schema.json +1 -1
  168. package/pipeline/schemas/autopilot-off-request.schema.json +1 -1
  169. package/pipeline/schemas/autopilot-off.schema.json +1 -1
  170. package/pipeline/schemas/autopilot-on-request.schema.json +1 -1
  171. package/pipeline/schemas/autopilot-on.schema.json +1 -1
  172. package/pipeline/schemas/autopilot-status.schema.json +1 -1
  173. package/pipeline/schemas/bug-bash-verification.schema.json +1 -1
  174. package/pipeline/schemas/code-graph.schema.json +1 -1
  175. package/pipeline/schemas/command-parameters.schema.json +1 -1
  176. package/pipeline/schemas/constitution.schema.json +1 -1
  177. package/pipeline/schemas/contract-error.schema.json +6 -13
  178. package/pipeline/schemas/criteria-manifest.schema.json +1 -1
  179. package/pipeline/schemas/design-check-config.schema.json +1 -1
  180. package/pipeline/schemas/diff-risk.schema.json +1 -1
  181. package/pipeline/schemas/disk-clean-request.schema.json +1 -1
  182. package/pipeline/schemas/disk-clean.schema.json +1 -1
  183. package/pipeline/schemas/doctor-report.schema.json +1 -1
  184. package/pipeline/schemas/explore-run.schema.json +1 -1
  185. package/pipeline/schemas/figma-project-config.schema.json +1 -1
  186. package/pipeline/schemas/gc-request.schema.json +1 -1
  187. package/pipeline/schemas/gc.schema.json +1 -1
  188. package/pipeline/schemas/issue-maturity.schema.json +1 -1
  189. package/pipeline/schemas/issues.schema.json +1 -1
  190. package/pipeline/schemas/job-change.schema.json +1 -1
  191. package/pipeline/schemas/job-request.schema.json +1 -1
  192. package/pipeline/schemas/kill-request.schema.json +1 -1
  193. package/pipeline/schemas/kill.schema.json +1 -1
  194. package/pipeline/schemas/launch-plan.schema.json +1 -1
  195. package/pipeline/schemas/launch-request.schema.json +2 -2
  196. package/pipeline/schemas/launch.schema.json +1 -1
  197. package/pipeline/schemas/learnings-ledger.schema.json +1 -1
  198. package/pipeline/schemas/ledger.schema.json +1 -1
  199. package/pipeline/schemas/office-archive.schema.json +2 -2
  200. package/pipeline/schemas/office-credentials.schema.json +1 -1
  201. package/pipeline/schemas/office-jobs.schema.json +1 -1
  202. package/pipeline/schemas/office-memory.schema.json +1 -1
  203. package/pipeline/schemas/office-server-room.schema.json +1 -1
  204. package/pipeline/schemas/office-settings-request.schema.json +1 -1
  205. package/pipeline/schemas/office-settings.schema.json +1 -1
  206. package/pipeline/schemas/permissions.schema.json +1 -1
  207. package/pipeline/schemas/phases.json +4 -4
  208. package/pipeline/schemas/phases.schema.json +1 -1
  209. package/pipeline/schemas/plan-critique.schema.json +1 -1
  210. package/pipeline/schemas/planning-output.schema.json +1 -1
  211. package/pipeline/schemas/pr-reach.schema.json +1 -1
  212. package/pipeline/schemas/pr-request.schema.json +1 -1
  213. package/pipeline/schemas/prefs.schema.json +40 -18
  214. package/pipeline/schemas/product-tree-overlay.schema.json +1 -1
  215. package/pipeline/schemas/product-tree.schema.json +1 -1
  216. package/pipeline/schemas/prs.schema.json +1 -1
  217. package/pipeline/schemas/prune-logs-request.schema.json +1 -1
  218. package/pipeline/schemas/prune-logs.schema.json +1 -1
  219. package/pipeline/schemas/repo-change.schema.json +1 -1
  220. package/pipeline/schemas/repo-profile.schema.json +1 -1
  221. package/pipeline/schemas/repo-request.schema.json +1 -1
  222. package/pipeline/schemas/repos.schema.json +1 -1
  223. package/pipeline/schemas/research-output.schema.json +1 -1
  224. package/pipeline/schemas/resume-request.schema.json +1 -1
  225. package/pipeline/schemas/review-file-exclusions.schema.json +1 -1
  226. package/pipeline/schemas/review-verdict-request.schema.json +1 -1
  227. package/pipeline/schemas/review-verdict.schema.json +1 -1
  228. package/pipeline/schemas/reviewer-output.schema.json +1 -1
  229. package/pipeline/schemas/route-config.schema.json +2 -2
  230. package/pipeline/schemas/routine-delete.schema.json +1 -1
  231. package/pipeline/schemas/routines.schema.json +1 -1
  232. package/pipeline/schemas/run-evidence.schema.json +1 -1
  233. package/pipeline/schemas/run-log.schema.json +1 -1
  234. package/pipeline/schemas/run-questions.schema.json +1 -1
  235. package/pipeline/schemas/run-results.schema.json +1 -1
  236. package/pipeline/schemas/runs-index.schema.json +1 -1
  237. package/pipeline/schemas/scaffold-manifest.schema.json +1 -1
  238. package/pipeline/schemas/scope-check.schema.json +1 -1
  239. package/pipeline/schemas/secret-patterns.schema.json +1 -1
  240. package/pipeline/schemas/security-finding.schema.json +1 -1
  241. package/pipeline/schemas/service-read.schema.json +1 -1
  242. package/pipeline/schemas/shared-routine-import-request.schema.json +43 -0
  243. package/pipeline/schemas/shared-routine-import.schema.json +118 -0
  244. package/pipeline/schemas/shared-routine.schema.json +79 -0
  245. package/pipeline/schemas/shared-routines.schema.json +83 -0
  246. package/pipeline/schemas/skill-catalog.schema.json +1 -1
  247. package/pipeline/schemas/stack-adapters.schema.json +1 -1
  248. package/pipeline/schemas/stack-change.schema.json +1 -1
  249. package/pipeline/schemas/stack-request.schema.json +1 -1
  250. package/pipeline/schemas/stack.schema.json +1 -1
  251. package/pipeline/schemas/steer-request.schema.json +1 -1
  252. package/pipeline/schemas/steer.schema.json +1 -1
  253. package/pipeline/schemas/system-status.schema.json +2 -2
  254. package/pipeline/schemas/test-gap.schema.json +1 -1
  255. package/pipeline/schemas/test-gen-discovery.schema.json +1 -1
  256. package/pipeline/schemas/test-gen-gaps.schema.json +1 -1
  257. package/pipeline/schemas/test-gen-inventory.schema.json +1 -1
  258. package/pipeline/schemas/test-gen-results.schema.json +1 -1
  259. package/pipeline/schemas/token-budget.json +4 -4
  260. package/pipeline/schemas/token-budget.schema.json +1 -1
  261. package/pipeline/schemas/tool-call-request.schema.json +1 -1
  262. package/pipeline/schemas/tool-call.schema.json +1 -1
  263. package/pipeline/schemas/toolkit-path-params.json +34 -2
  264. package/pipeline/schemas/toolkit-path-params.schema.json +2 -2
  265. package/pipeline/schemas/tools.schema.json +2 -2
  266. package/pipeline/schemas/triage-corpus.schema.json +1 -1
  267. package/pipeline/schemas/triage-output.schema.json +1 -1
  268. package/pipeline/schemas/unattended-policy.json +8 -4
  269. package/pipeline/schemas/unattended-policy.schema.json +1 -1
  270. package/pipeline/schemas/unattended-profile.json +8 -6
  271. package/pipeline/schemas/unattended-profile.schema.json +1 -1
  272. package/pipeline/schemas/worktrees.schema.json +1 -1
  273. package/pipeline/scripts/_contract-core.mjs +1 -1
  274. package/pipeline/scripts/_contract-routes-ops.mjs +14 -1
  275. package/pipeline/scripts/_contract-routes-routines.mjs +327 -0
  276. package/pipeline/scripts/_contract-routes-runs.mjs +4 -47
  277. package/pipeline/scripts/_guard-probe.mjs +1 -1
  278. package/pipeline/scripts/_renamed-skills.mjs +20 -8
  279. package/pipeline/scripts/_sibling-root.mjs +1 -1
  280. package/pipeline/scripts/_stack-routing.mjs +1 -0
  281. package/pipeline/scripts/_user_guard_rules.py +22 -7
  282. package/pipeline/scripts/autopilot-control.mjs +14 -2
  283. package/pipeline/scripts/autopilot-loop.mjs +16 -1
  284. package/pipeline/scripts/autopilot-runner.mjs +37 -12
  285. package/pipeline/scripts/bulk-read.sh +1 -1
  286. package/pipeline/scripts/contract-server.mjs +68 -147
  287. package/pipeline/scripts/cost-table.json +2 -2
  288. package/pipeline/scripts/doctor.mjs +171 -10
  289. package/pipeline/scripts/feedback-send.mjs +2 -36
  290. package/pipeline/scripts/gen-facts.mjs +21 -1
  291. package/pipeline/scripts/gen-free-hosts.mjs +2 -2
  292. package/pipeline/scripts/gen-mode-dispatch.mjs +11 -7
  293. package/pipeline/scripts/graph-hint.mjs +1 -1
  294. package/pipeline/scripts/health-report.mjs +4 -3
  295. package/pipeline/scripts/job-launch.mjs +1 -1
  296. package/pipeline/scripts/launch-request.mjs +12 -25
  297. package/pipeline/scripts/migrate-prefs.mjs +21 -1
  298. package/pipeline/scripts/office-archive.mjs +1 -2
  299. package/pipeline/scripts/office-control.mjs +17 -92
  300. package/pipeline/scripts/office-server-room.mjs +1 -1
  301. package/pipeline/scripts/phase0-exit-gate.mjs +1 -1
  302. package/pipeline/scripts/plan-attachment.mjs +1082 -0
  303. package/pipeline/scripts/pre-commit-check.sh +4 -0
  304. package/pipeline/scripts/pre-push-check.sh +1 -1
  305. package/pipeline/scripts/probe-evidence-capability.sh +1 -1
  306. package/pipeline/scripts/repo-recommend.mjs +2 -2
  307. package/pipeline/scripts/routine-registry.mjs +537 -53
  308. package/pipeline/scripts/routine-share.mjs +442 -0
  309. package/pipeline/scripts/runs-index.mjs +1 -1
  310. package/pipeline/scripts/system-status.mjs +8 -2
  311. package/pipeline/scripts/test-classify.mjs +1 -1
  312. package/pipeline/scripts/toolkit-tools.mjs +4 -3
  313. package/pipeline/scripts/unattended_policy.py +18 -5
  314. package/pipeline/scripts/uninstall.mjs +71 -28
  315. package/pipeline/scripts/usage-access.mjs +384 -0
  316. package/pipeline/scripts/usage-identity.mjs +81 -14
  317. package/pipeline/scripts/usage-register.mjs +389 -72
  318. package/pipeline/scripts/usage-report.mjs +124 -11
  319. package/pipeline/scripts/work-items.mjs +1 -1
  320. package/pipeline/scripts/write-store-config.mjs +3 -3
  321. package/pipeline/skills/.skill-manifest.json +66 -70
  322. package/pipeline/skills/.skills-index.json +18 -29
  323. package/pipeline/skills/renamed.json +2 -1
  324. package/pipeline/skills/shared/README.md +11 -12
  325. package/pipeline/skills/shared/core/apple-archive-compliance/SKILL.md +14 -14
  326. package/pipeline/skills/shared/core/apple-archive-compliance/references/examples.md +1 -1
  327. package/pipeline/skills/shared/core/apple-archive-compliance/references/version-history.md +3 -3
  328. package/pipeline/skills/shared/core/google-play-compliance/SKILL.md +1 -1
  329. package/pipeline/skills/shared/core/google-play-compliance/references/notes.md +1 -1
  330. package/pipeline/skills/shared/core/multi-agent/SKILL.md +14 -4
  331. package/pipeline/skills/shared/core/multi-agent-analysis/SKILL.md +8 -0
  332. package/pipeline/skills/shared/core/multi-agent-analysis-jira/SKILL.md +8 -0
  333. package/pipeline/skills/shared/core/multi-agent-autopilot-off/SKILL.md +6 -3
  334. package/pipeline/skills/shared/core/multi-agent-bug-bash/SKILL.md +1 -1
  335. package/pipeline/skills/shared/core/multi-agent-channels/SKILL.md +8 -0
  336. package/pipeline/skills/shared/core/multi-agent-complaint-analysis/SKILL.md +9 -1
  337. package/pipeline/skills/shared/core/multi-agent-create-jira/SKILL.md +8 -0
  338. package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +13 -5
  339. package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +6 -6
  340. package/pipeline/skills/shared/core/multi-agent-help/SKILL.md +1 -1
  341. package/pipeline/skills/shared/core/multi-agent-issue/SKILL.md +8 -0
  342. package/pipeline/skills/shared/core/multi-agent-jira/SKILL.md +8 -0
  343. package/pipeline/skills/shared/core/multi-agent-kill/SKILL.md +8 -0
  344. package/pipeline/skills/shared/core/multi-agent-office-off/SKILL.md +2 -2
  345. package/pipeline/skills/shared/core/multi-agent-office-on/SKILL.md +1 -1
  346. package/pipeline/skills/shared/core/multi-agent-office-status/SKILL.md +2 -4
  347. package/pipeline/skills/shared/core/multi-agent-purge/SKILL.md +8 -0
  348. package/pipeline/skills/shared/core/multi-agent-refactor/SKILL.md +16 -8
  349. package/pipeline/skills/shared/core/multi-agent-research/SKILL.md +2 -2
  350. package/pipeline/skills/shared/core/multi-agent-resume/SKILL.md +8 -0
  351. package/pipeline/skills/shared/core/multi-agent-review/SKILL.md +8 -0
  352. package/pipeline/skills/shared/core/multi-agent-review-analysis/SKILL.md +8 -0
  353. package/pipeline/skills/shared/core/multi-agent-review-issue/SKILL.md +8 -0
  354. package/pipeline/skills/shared/core/multi-agent-review-jira/SKILL.md +8 -0
  355. package/pipeline/skills/shared/core/multi-agent-review-priority/SKILL.md +8 -0
  356. package/pipeline/skills/shared/core/multi-agent-route-on/SKILL.md +1 -1
  357. package/pipeline/skills/shared/core/multi-agent-routines/SKILL.md +17 -6
  358. package/pipeline/skills/shared/core/multi-agent-save/SKILL.md +3 -3
  359. package/pipeline/skills/shared/core/multi-agent-scaffold/SKILL.md +8 -0
  360. package/pipeline/skills/shared/core/multi-agent-search/SKILL.md +3 -3
  361. package/pipeline/skills/shared/core/multi-agent-security-review/SKILL.md +6 -5
  362. package/pipeline/skills/shared/core/multi-agent-setup/SKILL.md +7 -2
  363. package/pipeline/skills/shared/core/multi-agent-store-ready/SKILL.md +20 -8
  364. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +18 -10
  365. package/pipeline/skills/shared/core/multi-agent-test/SKILL.md +5 -3
  366. package/pipeline/skills/shared/core/multi-agent-test-accessibility/SKILL.md +5 -3
  367. package/pipeline/skills/shared/core/multi-agent-test-dark-mode/SKILL.md +5 -3
  368. package/pipeline/skills/shared/core/multi-agent-test-dynamic-type/SKILL.md +5 -3
  369. package/pipeline/skills/shared/core/multi-agent-test-gen/SKILL.md +2 -2
  370. package/pipeline/skills/shared/core/multi-agent-test-screenshots/SKILL.md +5 -3
  371. package/pipeline/skills/shared/core/multi-agent-testflight-validation/SKILL.md +7 -4
  372. package/pipeline/skills/shared/core/multi-agent-update/SKILL.md +70 -17
  373. package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -2
  374. package/pipeline/skills/shared/external/app-store-review/SKILL.md +1 -1
  375. package/pipeline/skills/shared/external/e2e-testing/SKILL.md +23 -23
  376. package/pipeline/skills/shared/external/e2e-testing/evals/evals.json +1 -1
  377. package/pipeline/skills/shared/external/e2e-testing/references/document-fixtures.md +6 -6
  378. package/pipeline/skills/shared/external/free-llm-apis/SKILL.md +2 -2
  379. package/pipeline/skills/shared/external/handle-request/SKILL.md +1 -1
  380. package/pipeline/skills/shared/external/hig-app-icons/SKILL.md +2 -2
  381. package/pipeline/skills/shared/external/hig-app-icons/references/icon-workflow.md +1 -1
  382. package/pipeline/skills/shared/external/ios-design-review/SKILL.md +12 -12
  383. package/pipeline/skills/shared/external/ios-design-review/evals/evals.json +1 -1
  384. package/pipeline/skills/shared/external/ios-design-review/references/appearance-matrix.md +17 -17
  385. package/pipeline/skills/shared/external/ios-design-review/references/checklist.md +1 -1
  386. package/pipeline/skills/shared/external/ios-simulator-debugging/SKILL.md +5 -5
  387. package/pipeline/skills/shared/external/passkit-wallet/SKILL.md +4 -4
  388. package/pipeline/skills/shared/external/release-video/SKILL.md +10 -10
  389. package/pipeline/skills/shared/external/release-video/evals/evals.json +8 -8
  390. package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +231 -0
  391. package/pipeline/skills/shared/external/reverse-engineer-own-app/evals/evals.json +43 -0
  392. package/pipeline/skills/shared/external/security-review/SKILL.md +2 -2
  393. package/pipeline/skills/shared/external/security-review/references/owasp-mobile-top10-2024.md +1 -1
  394. package/pipeline/skills/shared/external/security-review/references/owasp-web-api-top10-2021.md +1 -1
  395. package/pipeline/skills/shared/external/short-video-craft/SKILL.md +20 -20
  396. package/pipeline/skills/shared/external/short-video-craft/evals/evals.json +3 -3
  397. package/pipeline/skills/shared/external/short-video-craft/references/generated-defaults.md +2 -2
  398. package/pipeline/skills/shared/external/signal-community/SKILL.md +6 -6
  399. package/pipeline/skills/shared/external/test-result-triage/SKILL.md +4 -4
  400. package/pipeline/skills/shared/external/web-testing/SKILL.md +3 -3
  401. package/pipeline/skills/shared/external/web-testing/references/testing-examples.md +13 -13
  402. package/pipeline/skills/skills-index.md +7 -8
  403. package/pipeline/commands/multi-agent/autopilot/SKILL.md +0 -123
  404. package/pipeline/commands/multi-agent/office-pair/SKILL.md +0 -89
  405. package/pipeline/contract/fixtures/error-unsigned.json +0 -5
  406. package/pipeline/lib/office-remote.mjs +0 -228
  407. package/pipeline/lib/qr-code.mjs +0 -386
  408. package/pipeline/lib/web-push.mjs +0 -198
  409. package/pipeline/multi-agent-refs/features/office-remote-protocol.md +0 -319
  410. package/pipeline/multi-agent-refs/features/phone-api.md +0 -306
  411. package/pipeline/schemas/phone-devices.schema.json +0 -61
  412. package/pipeline/schemas/phone-signed-request.schema.json +0 -67
  413. package/pipeline/scripts/_phone-auth.mjs +0 -485
  414. package/pipeline/scripts/office-pair.mjs +0 -459
  415. package/pipeline/scripts/office-push.mjs +0 -613
  416. package/pipeline/scripts/office-remote-client.mjs +0 -490
  417. package/pipeline/scripts/phone-devices.mjs +0 -248
  418. package/pipeline/skills/shared/core/multi-agent-autopilot/SKILL.md +0 -62
  419. package/pipeline/skills/shared/core/multi-agent-office-pair/SKILL.md +0 -19
@@ -22,28 +22,74 @@
22
22
  // node routine-registry.mjs add --name <n> --description <d>
23
23
  // [--description-tr <t>] [--argument-hint <h>] --source <s> --body-file <f> [--home <dir>]
24
24
  // node routine-registry.mjs remove --name <n> [--home <dir>]
25
+ // node routine-registry.mjs export --name <n> [--home <dir>]
26
+ // node routine-registry.mjs import --payload-file <f> --owner <login> --version <n>
27
+ // [--id <shared id>] [--as <local name>] [--replace] [--home <dir>]
28
+ // node routine-registry.mjs scan (--name <n> | --payload-file <f>) [--home <dir>]
25
29
  //
26
- // Exit: 0 ok, 1 error (validation / collision / not-found), 64 usage.
30
+ // export prints the shareable payload of a saved routine: name, description,
31
+ // descriptionTr, argumentHint, body (the procedure text only, never the
32
+ // frontmatter) and sha256 (hex SHA-256 of the body's UTF-8 bytes).
33
+ // payloadDigest() hashes the whole installed payload (every field above but
34
+ // sha256); routine-share.mjs binds an import's confirmation to it.
35
+ // import adds a payload as a routine after checking its sha256; the
36
+ // frontmatter is rebuilt here, so a shared routine cannot bring its own
37
+ // allowed-tools or drop local-only. Its registry entry records
38
+ // source "shared:<owner>/<name>@<version>", sha256 and the shared id.
39
+ // --replace swaps the body of a routine imported from the same shared id
40
+ // (an update); anything else with that name is a collision, including a
41
+ // command directory the registry does not track (a shipped command or a
42
+ // preserved local-only wrapper). add refuses the same directories.
43
+ // scan runs the pre-share secret scan (lib/routine-secret-scan.mjs) and
44
+ // prints {findings}; exit 1 when it found anything.
45
+ //
46
+ // add, import and remove refuse under MULTI_AGENT_UNATTENDED=1, and the guard
47
+ // blocks the same subcommands by name (unattended-policy.json): saving,
48
+ // installing or deleting a command is for a person to confirm.
49
+ //
50
+ // Exit: 0 ok, 1 error (validation / collision / not-found), 3 unattended,
51
+ // 64 usage.
27
52
  //
28
53
  // listRoutines() and removeRoutine() are exported for contract-server.mjs
29
54
  // (GET /v1/routines, DELETE /v1/routines/{name}), so the panel and the
30
55
  // terminal commands run the same code; they throw RoutineError where the CLI
31
- // prints and exits 1.
56
+ // prints and exits 1. localNameTaken() answers the office's import preview
57
+ // before anything is written.
32
58
 
33
- import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync, renameSync } from "node:fs";
59
+ import {
60
+ copyFileSync,
61
+ existsSync,
62
+ lstatSync,
63
+ readFileSync,
64
+ readdirSync,
65
+ rmdirSync,
66
+ writeFileSync,
67
+ mkdirSync,
68
+ rmSync,
69
+ } from "node:fs";
34
70
  import { join, dirname } from "node:path";
35
71
  import { runMain } from "../lib/fatal.mjs";
36
- import { hostCommand } from "../lib/user-facing.mjs";
37
72
  import { invokedDirectly } from "../lib/invoked-directly.mjs";
38
73
  import { prefsFileIn } from "../lib/prefs-value.mjs";
39
74
  import { parseArgs as parseArgv } from "../lib/args.mjs";
40
75
  import { exitOnHelp } from "../lib/cli-help.mjs";
76
+ import { createHash } from "node:crypto";
77
+ import { denyHostsFrom, scanSecrets } from "../lib/routine-secret-scan.mjs";
78
+ import { isUnattended } from "../lib/unattended.mjs";
79
+ import { lockTimeoutFrom, updateJsonFileSync } from "../lib/json-file-lock.mjs";
41
80
 
42
81
  exitOnHelp(import.meta.url);
43
82
 
44
83
  const NAME_RE = /^[a-z0-9][a-z0-9-]*$/;
45
84
  const MAX_NAME = 40;
46
85
  const MAX_ROUTINES = 100;
86
+ export const MAX_BODY_BYTES = 65536;
87
+ const FIELD_LIMITS = { description: 300, descriptionTr: 300, argumentHint: 120 };
88
+ const SHA_RE = /^[0-9a-f]{64}$/;
89
+ // The body keeps tab, line feed and carriage return; every other C0 is refused, as on the server.
90
+ // eslint-disable-next-line no-control-regex
91
+ const BODY_CONTROL_RE = /[\u0000-\u0008\u000b\u000c\u000e-\u001f]/;
92
+ const INPUT_MARKER = "**Input**: $ARGUMENTS\n\n";
47
93
 
48
94
  function parseArgs(argv) {
49
95
  // Values are separate tokens only; --flag=value is named back in the
@@ -94,12 +140,27 @@ function readPrefs(home) {
94
140
  }
95
141
  }
96
142
 
97
- function writePrefs(home, prefs) {
143
+ /**
144
+ * Lock the preferences file, read it, let `mutate` change it, and replace it
145
+ * atomically at 0600, writing through a symlink so a dotfiles link survives.
146
+ * `mutate` runs under the lock, so its checks see the current registry and
147
+ * two writers never drop each other's entry. Returning undefined writes
148
+ * nothing; a file that exists but does not parse is refused, never replaced.
149
+ */
150
+ function updatePrefs(home, mutate) {
98
151
  const p = prefsPath(home);
99
152
  mkdirSync(dirname(p), { recursive: true });
100
- const tmp = `${p}.tmp.${process.pid}`;
101
- writeFileSync(tmp, `${JSON.stringify(prefs, null, 2)}\n`);
102
- renameSync(tmp, p);
153
+ return updateJsonFileSync(
154
+ p,
155
+ (current) => {
156
+ if (current === null && existsSync(p)) fail(`could not parse ${p}`);
157
+ const prefs = current ?? {};
158
+ if (typeof prefs !== "object" || Array.isArray(prefs)) fail(`could not parse ${p}`);
159
+ if (!prefs.global || typeof prefs.global !== "object") prefs.global = {};
160
+ return mutate(prefs);
161
+ },
162
+ { mode: 0o600, followSymlink: true, timeoutMs: lockTimeoutFrom(process.env) },
163
+ );
103
164
  }
104
165
 
105
166
  function getRoutines(prefs) {
@@ -114,6 +175,58 @@ function isLocalOnlyDir(dir) {
114
175
  return /^local-only:\s*true\s*$/m.test(readFileSync(skill, "utf-8"));
115
176
  }
116
177
 
178
+ // Files this tool writes into a routine's command directory.
179
+ const OWN_FILES = ["SKILL.md", "SKILL.md.bak"];
180
+
181
+ /**
182
+ * What sits at a routine's command path, read without following a link:
183
+ * absent nothing there
184
+ * stale a real directory that is empty or holds only SKILL.md.bak
185
+ * routine a real directory whose SKILL.md is local-only
186
+ * shipped a real directory whose SKILL.md is not local-only
187
+ * foreign anything else: a symlink, a file, or a directory holding a
188
+ * nested <sub>.md command, another file or a subdirectory.
189
+ * Claude Code reads <name>/<sub>.md as /multi-agent:<name>:<sub>, so a
190
+ * foreign path is a local command the registry does not track: it is
191
+ * refused and never deleted.
192
+ */
193
+ function dirState(dir) {
194
+ let st;
195
+ try {
196
+ st = lstatSync(dir);
197
+ } catch {
198
+ return "absent";
199
+ }
200
+ if (st.isSymbolicLink() || !st.isDirectory()) return "foreign";
201
+ const names = readdirSync(dir);
202
+ if (names.includes("SKILL.md")) return isLocalOnlyDir(dir) ? "routine" : "shipped";
203
+ const ownOnly = names.every((n) => n === "SKILL.md.bak" && lstatSync(join(dir, n)).isFile());
204
+ return ownOnly ? "stale" : "foreign";
205
+ }
206
+
207
+ /** Clear a stale command directory; true when one was removed. */
208
+ function clearStaleDir(dir) {
209
+ if (dirState(dir) !== "stale") return false;
210
+ rmSync(dir, { recursive: true, force: true });
211
+ return true;
212
+ }
213
+
214
+ /**
215
+ * Remove what this tool wrote in a routine directory, then the directory
216
+ * when nothing else is left. Returns true when the directory is gone.
217
+ */
218
+ function removeOwnFiles(dir) {
219
+ for (const f of OWN_FILES) rmSync(join(dir, f), { force: true });
220
+ if (readdirSync(dir).length > 0) return false;
221
+ rmdirSync(dir);
222
+ return true;
223
+ }
224
+
225
+ const untracked = (name, state) =>
226
+ state === "foreign"
227
+ ? `"${name}" is a local command the registry does not track and holds files this tool did not write`
228
+ : `"${name}" is a local command the registry does not track`;
229
+
117
230
  function cmdList(home, json) {
118
231
  const routines = getRoutines(readPrefs(home));
119
232
  if (json) {
@@ -141,25 +254,278 @@ function cmdGet(home, name) {
141
254
  export const ROUTINE_ALLOWED_TOOLS = "Skill, Bash, Read, Edit, Write, AskUserQuestion";
142
255
 
143
256
  function buildSkill(args) {
144
- const desc = args.description;
145
- const descTr = args["description-tr"];
146
- const hint = args["argument-hint"] || "[optional args]";
147
- const body = readFileSync(args["body-file"], "utf-8").trimEnd();
257
+ return skillText({
258
+ name: args.name,
259
+ description: args.description,
260
+ descriptionTr: args["description-tr"],
261
+ argumentHint: args["argument-hint"],
262
+ body: readFileSync(args["body-file"], "utf-8"),
263
+ });
264
+ }
265
+
266
+ const isForbiddenCode = (c) =>
267
+ c <= 0x1f || (c >= 0x7f && c <= 0x9f) || c === 0x2028 || c === 0x2029;
268
+
269
+ /**
270
+ * Whether a frontmatter value holds a character that could end its line or
271
+ * hide in it: every C0 control (tab included), DEL, every C1 control (NEL
272
+ * included) and the Unicode line and paragraph separators.
273
+ */
274
+ export function hasForbiddenFieldChar(value) {
275
+ for (const ch of String(value)) {
276
+ if (isForbiddenCode(ch.codePointAt(0))) return true;
277
+ }
278
+ return false;
279
+ }
280
+
281
+ function skillText({ name, description, descriptionTr, argumentHint, body }) {
282
+ for (const [field, v] of Object.entries({ description, descriptionTr, argumentHint })) {
283
+ if (v !== undefined && v !== null && hasForbiddenFieldChar(v))
284
+ fail(`${field} holds a control or line-break character`);
285
+ }
286
+ const hint = argumentHint || "[optional args]";
148
287
  const fm = [
149
288
  "---",
150
- `description: ${JSON.stringify(desc)}`,
151
- descTr ? `description-tr: ${JSON.stringify(descTr)}` : null,
289
+ `description: ${JSON.stringify(description)}`,
290
+ descriptionTr ? `description-tr: ${JSON.stringify(descriptionTr)}` : null,
152
291
  `argument-hint: ${JSON.stringify(hint)}`,
153
292
  `allowed-tools: ${ROUTINE_ALLOWED_TOOLS}`,
154
293
  "local-only: true",
155
294
  "---",
156
295
  ].filter(Boolean);
157
- return `${fm.join("\n")}\n\n# multi-agent ${args.name} - saved routine\n\n**Input**: $ARGUMENTS\n\n${body}\n`;
296
+ return `${fm.join("\n")}\n\n# multi-agent ${name} - saved routine\n\n${INPUT_MARKER}${body.trimEnd()}\n`;
297
+ }
298
+
299
+ /** Lowercase hex SHA-256 of a string's UTF-8 bytes. */
300
+ export function bodySha256(body) {
301
+ return createHash("sha256").update(String(body), "utf8").digest("hex");
302
+ }
303
+
304
+ /**
305
+ * Lowercase hex SHA-256 of everything an import installs: the canonical JSON
306
+ * of {argumentHint, body, description, descriptionTr, name}, keys sorted,
307
+ * no whitespace, an absent optional field as "". This is the sharing
308
+ * server's content digest byte for byte, so the digest a fetch shows can be
309
+ * checked against the one the server sends. A confirmation carries it, so a
310
+ * description or argument hint changed after the user saw it is refused the
311
+ * same way a changed body is.
312
+ */
313
+ export function payloadDigest(p) {
314
+ const canonical = JSON.stringify({
315
+ argumentHint: p?.argumentHint ?? "",
316
+ body: p?.body,
317
+ description: p?.description,
318
+ descriptionTr: p?.descriptionTr ?? "",
319
+ name: p?.name,
320
+ });
321
+ return createHash("sha256").update(canonical, "utf8").digest("hex");
322
+ }
323
+
324
+ function frontValue(front, key) {
325
+ const m = new RegExp(`^${key}:\\s*(.*)$`, "m").exec(front);
326
+ if (!m) return undefined;
327
+ const raw = m[1].trim();
328
+ try {
329
+ return raw.startsWith('"') ? JSON.parse(raw) : raw;
330
+ } catch {
331
+ return raw;
332
+ }
333
+ }
334
+
335
+ /**
336
+ * Split a routine SKILL.md into its frontmatter values and its procedure
337
+ * body. The body is the text after the generated input line; a hand-edited
338
+ * file without that line yields everything after the frontmatter.
339
+ */
340
+ export function parseRoutineSkill(text) {
341
+ const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(text);
342
+ const front = m ? m[1] : "";
343
+ const rest = m ? text.slice(m[0].length) : text;
344
+ const at = rest.indexOf(INPUT_MARKER);
345
+ const body = (at >= 0 ? rest.slice(at + INPUT_MARKER.length) : rest)
346
+ .replace(/^\s*\n/, "")
347
+ .trimEnd();
348
+ const hint = frontValue(front, "argument-hint");
349
+ return {
350
+ description: frontValue(front, "description"),
351
+ descriptionTr: frontValue(front, "description-tr"),
352
+ argumentHint: hint === "[optional args]" ? undefined : hint,
353
+ body,
354
+ };
355
+ }
356
+
357
+ const RESERVED_NAMES = new Set(["shared"]);
358
+
359
+ function validName(name) {
360
+ return (
361
+ typeof name === "string" &&
362
+ NAME_RE.test(name) &&
363
+ name.length <= MAX_NAME &&
364
+ !RESERVED_NAMES.has(name)
365
+ );
366
+ }
367
+
368
+ /**
369
+ * Whether a name can be a routine's local name: the command directory and
370
+ * the registry key. It is a single path segment and never the reserved
371
+ * `shared`, so every caller that builds a path from it can check here first.
372
+ */
373
+ export function isValidLocalName(name) {
374
+ return validName(name);
375
+ }
376
+
377
+ /**
378
+ * The problems that make a payload unshareable or unimportable, each with
379
+ * the field it is about: {code, field}. Codes and rules match the sharing
380
+ * server's: a single-line field is refused for any control or line-break
381
+ * character, then its length is checked after trimming (the server stores
382
+ * it trimmed); the body is refused for a C0 control other than tab, line
383
+ * feed and carriage return.
384
+ */
385
+ export function payloadIssues(p) {
386
+ if (!p || typeof p !== "object") return [{ code: "invalid-field", field: "payload" }];
387
+ const out = [];
388
+ if (!validName(p.name)) out.push({ code: "invalid-name", field: "name" });
389
+ if (typeof p.description !== "string" || p.description.trim() === "")
390
+ out.push({ code: "invalid-field", field: "description" });
391
+ for (const [key, max] of Object.entries(FIELD_LIMITS)) {
392
+ const v = p[key];
393
+ if (v === undefined || v === null) continue;
394
+ if (typeof v !== "string" || hasForbiddenFieldChar(v) || v.trim().length > max)
395
+ out.push({ code: "invalid-field", field: key });
396
+ }
397
+ if (typeof p.body !== "string" || p.body.trim() === "" || BODY_CONTROL_RE.test(p.body))
398
+ out.push({ code: "invalid-field", field: "body" });
399
+ else if (Buffer.byteLength(p.body, "utf8") > MAX_BODY_BYTES)
400
+ out.push({ code: "too-large", field: "body" });
401
+ if (
402
+ typeof p.body === "string" &&
403
+ (!SHA_RE.test(String(p.sha256)) || p.sha256 !== bodySha256(p.body))
404
+ ) {
405
+ out.push({ code: "sha-mismatch", field: "sha256" });
406
+ }
407
+ const seen = new Set();
408
+ return out.filter((i) => {
409
+ const key = `${i.code}:${i.field}`;
410
+ if (seen.has(key)) return false;
411
+ seen.add(key);
412
+ return true;
413
+ });
414
+ }
415
+
416
+ /**
417
+ * The problems that make a payload unshareable or unimportable, as short
418
+ * codes matching the sharing server's: invalid-name, invalid-field,
419
+ * too-large, sha-mismatch.
420
+ */
421
+ export function payloadProblems(p) {
422
+ return [...new Set(payloadIssues(p).map((i) => i.code))];
423
+ }
424
+
425
+ /** The shareable payload of a saved routine. */
426
+ export function exportRoutine(home, name) {
427
+ if (!validName(name)) fail(`invalid routine name: ${name}`);
428
+ const entry = getRoutines(readPrefs(home)).find((r) => r.name === name);
429
+ if (!entry) fail(`no routine named "${name}"`);
430
+ const dir = routineDir(home, name);
431
+ if (!isLocalOnlyDir(dir)) fail(`"${name}" has no local-only command file; re-save it first`);
432
+ const parsed = parseRoutineSkill(readFileSync(join(dir, "SKILL.md"), "utf-8"));
433
+ const payload = { name, description: parsed.description || entry.description, body: parsed.body };
434
+ if (parsed.descriptionTr) payload.descriptionTr = parsed.descriptionTr;
435
+ if (parsed.argumentHint) payload.argumentHint = parsed.argumentHint;
436
+ payload.sha256 = bodySha256(parsed.body);
437
+ return payload;
438
+ }
439
+
440
+ /** Secret findings for a payload, with this machine's deny list. */
441
+ export function scanPayload(home, payload, env = process.env) {
442
+ return scanSecrets(payload, { denyHosts: denyHostsFrom(readPrefs(home).global, env) });
443
+ }
444
+
445
+ /**
446
+ * Add a shared payload as a local routine. The sha256 is checked before
447
+ * anything is written; the local name is `as` when given, else the payload's.
448
+ *
449
+ * @param {string} home
450
+ * @param {object} payload {name, description, descriptionTr?, argumentHint?, body, sha256}
451
+ * @param {{owner: string, version: number, id?: string, as?: string, replace?: boolean}} meta
452
+ */
453
+ export function importRoutine(home, payload, meta) {
454
+ const problems = payloadProblems(payload);
455
+ if (problems.includes("sha-mismatch")) fail("sha256 does not match the body; refusing to import");
456
+ if (problems.length) fail(`payload rejected: ${problems.join(", ")}`);
457
+ if (typeof meta?.owner !== "string" || !/^[a-z0-9][a-z0-9-]{0,38}$/i.test(meta.owner))
458
+ fail("invalid --owner");
459
+ const version = Number(meta.version);
460
+ if (!Number.isInteger(version) || version < 1) fail("invalid --version");
461
+ if (
462
+ meta.id !== undefined &&
463
+ (typeof meta.id !== "string" || !/^[A-Za-z0-9][A-Za-z0-9-]{0,63}$/.test(meta.id))
464
+ ) {
465
+ fail("invalid --id");
466
+ }
467
+ const name = meta.as || payload.name;
468
+ if (!validName(name))
469
+ fail(`invalid local name (need ${NAME_RE} , <= ${MAX_NAME} chars): ${name}`);
470
+ const dir = routineDir(home, name);
471
+ if (dirState(dir) === "shipped") {
472
+ fail(`collision: "${name}" is a shipped command; pick another local name`);
473
+ }
474
+ let written;
475
+ updatePrefs(home, (prefs) => {
476
+ const routines = getRoutines(prefs);
477
+ const idx = routines.findIndex((r) => r.name === name);
478
+ const state = dirState(dir);
479
+ if (state === "foreign" || (idx < 0 && state === "routine")) {
480
+ fail(`collision: ${untracked(name, state)}; pick another local name`);
481
+ }
482
+ if (idx >= 0) {
483
+ const same = meta.replace && meta.id && routines[idx].sharedId === meta.id;
484
+ if (!same)
485
+ fail(`collision: a routine named "${name}" already exists; pick another local name`);
486
+ } else if (meta.replace) {
487
+ fail(`no imported routine named "${name}" to update`);
488
+ } else if (routines.length >= MAX_ROUTINES) {
489
+ fail(`routine cap (${MAX_ROUTINES}) reached`);
490
+ }
491
+ const skill = skillText({ ...payload, name });
492
+ if (!/^local-only:\s*true\s*$/m.test(skill))
493
+ fail("internal: generated SKILL missing local-only");
494
+ clearStaleDir(dir);
495
+ mkdirSync(dir, { recursive: true });
496
+ const file = join(dir, "SKILL.md");
497
+ if (meta.backup && idx >= 0 && existsSync(file)) copyFileSync(file, `${file}.bak`);
498
+ writeFileSync(file, skill);
499
+ const entry = {
500
+ name,
501
+ description: payload.description,
502
+ createdAt: idx >= 0 ? routines[idx].createdAt : new Date().toISOString(),
503
+ source: `shared:${meta.owner.toLowerCase()}/${payload.name}@${version}`,
504
+ sha256: payload.sha256,
505
+ skillSha256: bodySha256(skill),
506
+ };
507
+ if (meta.id) entry.sharedId = meta.id;
508
+ if (idx >= 0) routines[idx] = entry;
509
+ else routines.push(entry);
510
+ prefs.global.routines = routines;
511
+ written = entry;
512
+ return prefs;
513
+ });
514
+ return written;
515
+ }
516
+
517
+ function readPayloadFile(file) {
518
+ if (!file || !existsSync(file)) fail("--payload-file is required and must exist");
519
+ try {
520
+ return JSON.parse(readFileSync(file, "utf-8"));
521
+ } catch {
522
+ fail("--payload-file is not valid JSON");
523
+ }
158
524
  }
159
525
 
160
526
  function cmdAdd(home, args) {
161
527
  const name = requireName(args.name);
162
- if (!NAME_RE.test(name) || name.length > MAX_NAME) {
528
+ if (!validName(name)) {
163
529
  fail(`invalid --name (need ${NAME_RE} , <= ${MAX_NAME} chars): ${name}`);
164
530
  }
165
531
  if (!args.description) fail("--description is required");
@@ -168,34 +534,89 @@ function cmdAdd(home, args) {
168
534
  }
169
535
  const dir = routineDir(home, name);
170
536
  // Collision: an existing non-local-only dir is a shipped command - never touch.
171
- if (existsSync(dir) && !isLocalOnlyDir(dir)) {
537
+ if (dirState(dir) === "shipped") {
172
538
  fail(`"${name}" collides with a shipped command; pick another name`);
173
539
  }
174
- const prefs = readPrefs(home);
175
- const routines = getRoutines(prefs);
176
- if (routines.some((r) => r.name === name)) {
177
- fail(`a routine named "${name}" already exists; forget it first or pick another name`);
178
- }
179
- if (routines.length >= MAX_ROUTINES) fail(`routine cap (${MAX_ROUTINES}) reached`);
180
-
181
- mkdirSync(dir, { recursive: true });
540
+ let cleared = false;
182
541
  const skill = buildSkill(args);
183
542
  // Safety: the generated file MUST be local-only so it never syncs to the repo.
184
543
  if (!/^local-only:\s*true\s*$/m.test(skill)) fail("internal: generated SKILL missing local-only");
185
- writeFileSync(join(dir, "SKILL.md"), skill);
186
-
187
- routines.push({
188
- name,
189
- description: args.description,
190
- createdAt: new Date().toISOString(),
191
- source: args.source || "user",
544
+ updatePrefs(home, (prefs) => {
545
+ const routines = getRoutines(prefs);
546
+ if (routines.some((r) => r.name === name)) {
547
+ fail(`a routine named "${name}" already exists; forget it first or pick another name`);
548
+ }
549
+ const state = dirState(dir);
550
+ if (state === "foreign" || state === "routine" || state === "shipped") {
551
+ fail(`${untracked(name, state)}; pick another name`);
552
+ }
553
+ if (routines.length >= MAX_ROUTINES) fail(`routine cap (${MAX_ROUTINES}) reached`);
554
+ cleared = clearStaleDir(dir);
555
+ mkdirSync(dir, { recursive: true });
556
+ writeFileSync(join(dir, "SKILL.md"), skill);
557
+ routines.push({
558
+ name,
559
+ description: args.description,
560
+ createdAt: new Date().toISOString(),
561
+ source: args.source || "user",
562
+ });
563
+ prefs.global.routines = routines;
564
+ return prefs;
192
565
  });
193
- prefs.global.routines = routines;
194
- writePrefs(home, prefs);
566
+ if (cleared) {
567
+ console.log(
568
+ `routine-registry: replaced a stale command directory (empty, or only SKILL.md.bak) at ${dir}`,
569
+ );
570
+ }
195
571
  console.log(`routine-registry: saved "${name}" -> ${join(dir, "SKILL.md")}`);
196
- console.log(
197
- `routine-registry: available as ${hostCommand(name, import.meta.dirname)} after a session reload`,
198
- );
572
+ console.log(availableLine(name));
573
+ }
574
+
575
+ /**
576
+ * Whether an imported routine's SKILL.md differs from the file the import
577
+ * wrote: true, false, or "unknown". An update replaces SKILL.md, so it
578
+ * refuses anything but false unless forced.
579
+ *
580
+ * With a recorded skillSha256 the file's sha256 decides. An entry written
581
+ * before that field existed is judged by rebuilding the file with the same
582
+ * writer from the entry's name and description and the file's own
583
+ * body. Such an entry records no descriptionTr or argument hint, so a file
584
+ * carrying either cannot be checked and is "unknown". When the rebuild is
585
+ * byte-identical and the body still hashes to the entry's sha256 (the writer
586
+ * drops trailing whitespace, so with or without one final line feed), the
587
+ * file is unedited and skillSha256 is backfilled under the preferences lock;
588
+ * when the rebuild is identical but the body hash is not, the body was
589
+ * edited; when the writer cannot reproduce the file at all, the answer is
590
+ * "unknown".
591
+ */
592
+ export function skillEdited(home, entry) {
593
+ if (!entry || !validName(entry.name)) return true;
594
+ const file = join(routineDir(home, entry.name), "SKILL.md");
595
+ if (!existsSync(file)) return true;
596
+ const text = readFileSync(file, "utf8");
597
+ if (typeof entry.skillSha256 === "string") return bodySha256(text) !== entry.skillSha256;
598
+ let rebuilt;
599
+ let body;
600
+ try {
601
+ const parsed = parseRoutineSkill(text);
602
+ if (parsed.descriptionTr !== undefined || parsed.argumentHint !== undefined) return "unknown";
603
+ body = parsed.body;
604
+ rebuilt = skillText({ ...parsed, name: entry.name, description: entry.description });
605
+ } catch {
606
+ return "unknown";
607
+ }
608
+ if (rebuilt !== text) return "unknown";
609
+ if (![body, `${body}\n`].some((b) => bodySha256(b) === entry.sha256)) return true;
610
+ const sha = bodySha256(text);
611
+ updatePrefs(home, (prefs) => {
612
+ const hit = getRoutines(prefs).find(
613
+ (r) => r.name === entry.name && r.skillSha256 === undefined && r.sha256 === entry.sha256,
614
+ );
615
+ if (!hit) return undefined;
616
+ hit.skillSha256 = sha;
617
+ return prefs;
618
+ });
619
+ return false;
199
620
  }
200
621
 
201
622
  /** The registered routines, as `list --json` prints them. */
@@ -203,6 +624,21 @@ export function listRoutines(home) {
203
624
  return getRoutines(readPrefs(home));
204
625
  }
205
626
 
627
+ /**
628
+ * Would importRoutine refuse this local name as a collision: a registered
629
+ * routine has it, or anything but an absent or stale path sits under its
630
+ * command directory (dirState). That covers shipped
631
+ * commands and local-only wrappers the installer preserves but the registry
632
+ * does not track. An invalid name is refused (RoutineError) before any path
633
+ * is built from it.
634
+ */
635
+ export function localNameTaken(home, name) {
636
+ if (!validName(name)) fail(`invalid local name: ${String(name).slice(0, 80)}`);
637
+ if (getRoutines(readPrefs(home)).some((r) => r.name === name)) return true;
638
+ const state = dirState(routineDir(home, name));
639
+ return state !== "absent" && state !== "stale";
640
+ }
641
+
206
642
  /**
207
643
  * Remove a routine: its local-only command directory and its registry entry.
208
644
  * A shipped command directory is refused, and so is a name that is neither
@@ -211,24 +647,35 @@ export function listRoutines(home) {
211
647
  * @returns {{name: string, removedDir: boolean, removedEntry: boolean}}
212
648
  */
213
649
  export function removeRoutine(home, name) {
214
- if (!name || !NAME_RE.test(name) || name.length > MAX_NAME) fail(`invalid routine name: ${name}`);
215
- const prefs = readPrefs(home);
216
- const routines = getRoutines(prefs);
217
- const idx = routines.findIndex((r) => r.name === name);
650
+ if (!name || !validName(name)) fail(`invalid routine name: ${name}`);
218
651
  const dir = routineDir(home, name);
219
- // Guard: only remove a dir that is BOTH registered AND local-only.
220
- if (existsSync(dir) && !isLocalOnlyDir(dir)) {
221
- fail(`"${name}" is a shipped command, not a routine; refusing to remove`);
222
- }
223
- if (idx < 0 && !existsSync(dir)) fail(`no routine named "${name}"`);
224
- const removedDir = existsSync(dir) && isLocalOnlyDir(dir);
225
- if (removedDir) rmSync(dir, { recursive: true, force: true });
226
- if (idx >= 0) {
652
+ let result;
653
+ updatePrefs(home, (prefs) => {
654
+ const routines = getRoutines(prefs);
655
+ const idx = routines.findIndex((r) => r.name === name);
656
+ // Guard: only touch a dir that is a local-only routine or stale; never
657
+ // delete a file this tool did not write.
658
+ const state = dirState(dir);
659
+ if (state === "shipped") {
660
+ fail(`"${name}" is a shipped command, not a routine; refusing to remove`);
661
+ }
662
+ if (state === "foreign") fail(`${untracked(name, state)}; refusing to remove it`);
663
+ if (idx < 0 && state === "absent") fail(`no routine named "${name}"`);
664
+ let removedDir = false;
665
+ if (state === "stale") removedDir = clearStaleDir(dir);
666
+ else if (state === "routine") removedDir = removeOwnFiles(dir);
667
+ result = { name, removedDir, removedEntry: idx >= 0 };
668
+ if (idx < 0) return undefined;
227
669
  routines.splice(idx, 1);
228
670
  prefs.global.routines = routines;
229
- writePrefs(home, prefs);
230
- }
231
- return { name, removedDir, removedEntry: idx >= 0 };
671
+ return prefs;
672
+ });
673
+ return result;
674
+ }
675
+
676
+ /** Routines are Claude Code commands only: whatever host runs this, name that one. */
677
+ function availableLine(name) {
678
+ return `routine-registry: available in Claude Code as /multi-agent:${name} after a session reload (routines are Claude Code only)`;
232
679
  }
233
680
 
234
681
  function cmdRemove(home, name) {
@@ -239,9 +686,15 @@ function cmdRemove(home, name) {
239
686
  );
240
687
  }
241
688
 
689
+ const UNATTENDED_REFUSED = new Set(["add", "import", "remove"]);
690
+
242
691
  function main() {
243
692
  const [, , sub, ...rest] = process.argv;
244
693
  const args = parseArgs(rest);
694
+ if (UNATTENDED_REFUSED.has(sub) && isUnattended(process.env)) {
695
+ console.error("routine-registry: an unattended run may not save, import or remove routines");
696
+ process.exit(3);
697
+ }
245
698
  const home = homeDir(args);
246
699
  if (!home) fail("cannot resolve home dir");
247
700
  switch (sub) {
@@ -253,8 +706,39 @@ function main() {
253
706
  return cmdAdd(home, args);
254
707
  case "remove":
255
708
  return cmdRemove(home, args.name);
709
+ case "export":
710
+ process.stdout.write(
711
+ `${JSON.stringify(exportRoutine(home, requireName(args.name)), null, 2)}\n`,
712
+ );
713
+ return;
714
+ case "import": {
715
+ const entry = importRoutine(home, readPayloadFile(args["payload-file"]), {
716
+ owner: args.owner,
717
+ version: args.version,
718
+ id: args.id,
719
+ as: args.as,
720
+ replace: Boolean(args.replace),
721
+ });
722
+ process.stdout.write(`${JSON.stringify(entry, null, 2)}\n`);
723
+ console.error(
724
+ `routine-registry: installed "${entry.name}" -> ${join(routineDir(home, entry.name), "SKILL.md")}`,
725
+ );
726
+ console.error(availableLine(entry.name));
727
+ return;
728
+ }
729
+ case "scan": {
730
+ const payload = args.name
731
+ ? exportRoutine(home, requireName(args.name))
732
+ : readPayloadFile(args["payload-file"]);
733
+ const findings = scanPayload(home, payload);
734
+ process.stdout.write(`${JSON.stringify({ findings }, null, 2)}\n`);
735
+ if (findings.length) process.exitCode = 1;
736
+ return;
737
+ }
256
738
  default:
257
- console.error("usage: routine-registry.mjs <list|get|add|remove> [flags] (see header)");
739
+ console.error(
740
+ "usage: routine-registry.mjs <list|get|add|remove|export|import|scan> [flags] (see header)",
741
+ );
258
742
  process.exit(64);
259
743
  }
260
744
  }