@ouro.bot/cli 0.1.0-alpha.1469 → 0.1.0-alpha.1470

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 (567) hide show
  1. package/README.md +1 -1
  2. package/changelog.json +6 -2
  3. package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
  4. package/deploy/unraid/sanctuary.xml +1 -1
  5. package/desk.lock.json +8 -0
  6. package/dist/heart/identity.js +27 -1
  7. package/dist/mind/desk-section.js +33 -43
  8. package/dist/repertoire/desk-mcp.js +140 -0
  9. package/dist/repertoire/mcp-manager.js +22 -0
  10. package/dist/repertoire/mcp-tools.js +11 -7
  11. package/npm-shrinkwrap.json +2 -2
  12. package/package.json +4 -1
  13. package/vendor/desk/.claude-plugin/plugin.json +35 -0
  14. package/vendor/desk/.mcp.claude-codex.json +28 -0
  15. package/vendor/desk/.mcp.copilot.json +16 -0
  16. package/vendor/desk/.ouro-desk.json +6 -0
  17. package/vendor/desk/CHANGELOG.md +7004 -0
  18. package/vendor/desk/README.md +195 -0
  19. package/vendor/desk/activation/README.md +98 -0
  20. package/vendor/desk/activation/copilot-root.flattened-bundle.json +38 -0
  21. package/vendor/desk/activation/desk.activation.json +251 -0
  22. package/vendor/desk/activation/host-capability-evidence.md +46 -0
  23. package/vendor/desk/activation/support-matrix.json +84 -0
  24. package/vendor/desk/agency.json +20 -0
  25. package/vendor/desk/agents/observer.agent.md +26 -0
  26. package/vendor/desk/agents/observer.md +29 -0
  27. package/vendor/desk/agents/worker.agent.md +32 -0
  28. package/vendor/desk/agents/worker.md +40 -0
  29. package/vendor/desk/artifacts/tombstones/tombstone.schema.json +53 -0
  30. package/vendor/desk/artifacts/tombstones/tombstones.jsonl +1 -0
  31. package/vendor/desk/changelog.d/README.md +12 -0
  32. package/vendor/desk/docs/agent-files.md +104 -0
  33. package/vendor/desk/docs/agentic-engineering-v2-rfc.md +206 -0
  34. package/vendor/desk/docs/agentic-engineering-v3-rfc.md +109 -0
  35. package/vendor/desk/docs/browser-remote-desktops.md +69 -0
  36. package/vendor/desk/docs/dependency-activation-stories-and-criteria.md +500 -0
  37. package/vendor/desk/docs/evaluation-packet.md +363 -0
  38. package/vendor/desk/docs/factory-local-capture.md +651 -0
  39. package/vendor/desk/docs/factory-store-playbook.md +927 -0
  40. package/vendor/desk/docs/images/factory-site.png +0 -0
  41. package/vendor/desk/docs/issue-drains.md +79 -0
  42. package/vendor/desk/docs/lfs-inspection.md +55 -0
  43. package/vendor/desk/docs/preview-diagnostics.md +11 -0
  44. package/vendor/desk/docs/relays.md +88 -0
  45. package/vendor/desk/docs/schedules.md +69 -0
  46. package/vendor/desk/docs/search-recovery.md +22 -0
  47. package/vendor/desk/docs/session-labels.md +157 -0
  48. package/vendor/desk/docs/session-retention.md +125 -0
  49. package/vendor/desk/docs/sessions.md +17 -0
  50. package/vendor/desk/docs/stalled-nudges.md +54 -0
  51. package/vendor/desk/docs/webhooks.md +80 -0
  52. package/vendor/desk/docs/workspace-tidy.md +74 -0
  53. package/vendor/desk/hooks/boot-checks.cjs +7 -0
  54. package/vendor/desk/hooks/claude-session-start.cjs +123 -0
  55. package/vendor/desk/hooks/compatible-node.cjs +97 -0
  56. package/vendor/desk/hooks/copilot-boot-prompt.cjs +69 -0
  57. package/vendor/desk/hooks/copilot-durable-files.cjs +8 -0
  58. package/vendor/desk/hooks/copilot-hooks.json +61 -0
  59. package/vendor/desk/hooks/copilot-intake-context.cjs +5 -0
  60. package/vendor/desk/hooks/copilot-lane-model.cjs +8 -0
  61. package/vendor/desk/hooks/copilot-session-start.cjs +264 -0
  62. package/vendor/desk/hooks/copilot-skill-current.cjs +28 -0
  63. package/vendor/desk/hooks/factory-end.cjs +5 -0
  64. package/vendor/desk/hooks/factory-start.cjs +27 -0
  65. package/vendor/desk/hooks/hooks.json +40 -0
  66. package/vendor/desk/hooks/lib/boot-checks.cjs +643 -0
  67. package/vendor/desk/hooks/lib/child-agent.cjs +14 -0
  68. package/vendor/desk/hooks/lib/copilot-intake-context.cjs +73 -0
  69. package/vendor/desk/hooks/lib/current-release.cjs +162 -0
  70. package/vendor/desk/hooks/lib/delivery-stop.cjs +326 -0
  71. package/vendor/desk/hooks/lib/detach-worker.cjs +43 -0
  72. package/vendor/desk/hooks/lib/durable-files.cjs +102 -0
  73. package/vendor/desk/hooks/lib/factory-end.cjs +327 -0
  74. package/vendor/desk/hooks/lib/lane-model.cjs +82 -0
  75. package/vendor/desk/hooks/lib/node-required.cjs +56 -0
  76. package/vendor/desk/hooks/lib/orca-session-title.cjs +60 -0
  77. package/vendor/desk/hooks/lib/session-end.cjs +30 -0
  78. package/vendor/desk/hooks/lib/sync-end.cjs +89 -0
  79. package/vendor/desk/hooks/loop-start.cjs +105 -0
  80. package/vendor/desk/hooks/node-missing.sh +78 -0
  81. package/vendor/desk/hooks/orca-session-title.cjs +8 -0
  82. package/vendor/desk/hooks/session-end.cjs +8 -0
  83. package/vendor/desk/mcp/README.md +269 -0
  84. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
  85. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
  86. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
  87. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
  88. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
  89. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
  90. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
  91. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
  92. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
  93. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
  94. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
  95. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
  96. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
  97. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
  98. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
  99. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/support-matrix.json +72 -0
  100. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
  101. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
  102. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
  103. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
  104. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
  105. package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
  106. package/vendor/desk/mcp/artifacts/runtime-deps/README.md +25 -0
  107. package/vendor/desk/mcp/bootstrap.cjs +761 -0
  108. package/vendor/desk/mcp/docs/private-feedback.md +13 -0
  109. package/vendor/desk/mcp/idle-proxy.cjs +423 -0
  110. package/vendor/desk/mcp/index.js +813 -0
  111. package/vendor/desk/mcp/package-lock.json +3717 -0
  112. package/vendor/desk/mcp/package.json +44 -0
  113. package/vendor/desk/mcp/scripts/agency-desk-channel.js +7 -0
  114. package/vendor/desk/mcp/scripts/build-runtime-deps-pack.js +5 -0
  115. package/vendor/desk/mcp/scripts/crew.js +89 -0
  116. package/vendor/desk/mcp/scripts/drains-launcher.mjs +329 -0
  117. package/vendor/desk/mcp/scripts/drains.js +5 -0
  118. package/vendor/desk/mcp/scripts/factory.js +657 -0
  119. package/vendor/desk/mcp/scripts/file-desk-problem.js +9 -0
  120. package/vendor/desk/mcp/scripts/finish-commit.js +7 -0
  121. package/vendor/desk/mcp/scripts/lfs.js +37 -0
  122. package/vendor/desk/mcp/scripts/local-recovery.js +363 -0
  123. package/vendor/desk/mcp/scripts/migrations.js +11 -0
  124. package/vendor/desk/mcp/scripts/private-view.js +177 -0
  125. package/vendor/desk/mcp/scripts/resolve-desk-root.js +106 -0
  126. package/vendor/desk/mcp/scripts/session-boot.js +22 -0
  127. package/vendor/desk/mcp/scripts/session-retention.js +5 -0
  128. package/vendor/desk/mcp/scripts/session-sync.js +10 -0
  129. package/vendor/desk/mcp/scripts/sessions.js +5 -0
  130. package/vendor/desk/mcp/scripts/sync-push.js +13 -0
  131. package/vendor/desk/mcp/scripts/tidy-status.js +8 -0
  132. package/vendor/desk/mcp/scripts/verify-runtime-deps-pack.js +5 -0
  133. package/vendor/desk/mcp/src/actions/desk-read.actions.mts +73 -0
  134. package/vendor/desk/mcp/src/actions/desk-session.actions.mts +42 -0
  135. package/vendor/desk/mcp/src/actions/desk-web.actions.mts +52 -0
  136. package/vendor/desk/mcp/src/actions/desk.actions.mts +5 -0
  137. package/vendor/desk/mcp/src/actions/generated/desk/OuroActions.swift +649 -0
  138. package/vendor/desk/mcp/src/actions/generated/desk/OuroActionsReins.swift +61 -0
  139. package/vendor/desk/mcp/src/actions/generated/desk/actions.json +280 -0
  140. package/vendor/desk/mcp/src/actions/generated/desk/commands.json +145 -0
  141. package/vendor/desk/mcp/src/actions/generated/desk/mcp.json +256 -0
  142. package/vendor/desk/mcp/src/actions/generated/desk/web.ts +59 -0
  143. package/vendor/desk/mcp/src/actions/generated/desk/webmcp.json +250 -0
  144. package/vendor/desk/mcp/src/actions/generated/desk-web/OuroActions.swift +241 -0
  145. package/vendor/desk/mcp/src/actions/generated/desk-web/OuroActionsReins.swift +25 -0
  146. package/vendor/desk/mcp/src/actions/generated/desk-web/actions.json +73 -0
  147. package/vendor/desk/mcp/src/actions/generated/desk-web/commands.json +53 -0
  148. package/vendor/desk/mcp/src/actions/generated/desk-web/mcp.json +83 -0
  149. package/vendor/desk/mcp/src/actions/generated/desk-web/web.ts +47 -0
  150. package/vendor/desk/mcp/src/actions/generated/desk-web/webmcp.json +81 -0
  151. package/vendor/desk/mcp/src/actions/served.js +5 -0
  152. package/vendor/desk/mcp/src/activation/admit.js +77 -0
  153. package/vendor/desk/mcp/src/activation/failures.js +65 -0
  154. package/vendor/desk/mcp/src/activation/readiness-policy.js +102 -0
  155. package/vendor/desk/mcp/src/activation/schema.js +17 -0
  156. package/vendor/desk/mcp/src/activation/superpowers-context.js +265 -0
  157. package/vendor/desk/mcp/src/activation/validate.js +540 -0
  158. package/vendor/desk/mcp/src/artifacts/tombstones.js +61 -0
  159. package/vendor/desk/mcp/src/crew/initiative.js +287 -0
  160. package/vendor/desk/mcp/src/crew/workspace.js +1259 -0
  161. package/vendor/desk/mcp/src/db/init.js +75 -0
  162. package/vendor/desk/mcp/src/db/schema.sql +83 -0
  163. package/vendor/desk/mcp/src/desk/active-tasks.js +408 -0
  164. package/vendor/desk/mcp/src/desk/card-commit-guard.js +281 -0
  165. package/vendor/desk/mcp/src/desk/cleanup-index.js +53 -0
  166. package/vendor/desk/mcp/src/desk/content-home.js +246 -0
  167. package/vendor/desk/mcp/src/desk/crew-config.js +102 -0
  168. package/vendor/desk/mcp/src/desk/crew-member.js +196 -0
  169. package/vendor/desk/mcp/src/desk/crew-roster.js +151 -0
  170. package/vendor/desk/mcp/src/desk/frontmatter-lite.js +228 -0
  171. package/vendor/desk/mcp/src/desk/gh-logins.js +109 -0
  172. package/vendor/desk/mcp/src/desk/handles.js +123 -0
  173. package/vendor/desk/mcp/src/desk/handoff-reference.js +35 -0
  174. package/vendor/desk/mcp/src/desk/improvement-authority.js +3 -0
  175. package/vendor/desk/mcp/src/desk/improvement-cards.js +704 -0
  176. package/vendor/desk/mcp/src/desk/improvement-person.js +51 -0
  177. package/vendor/desk/mcp/src/desk/lifecycle.js +16 -0
  178. package/vendor/desk/mcp/src/desk/machine-desks.js +119 -0
  179. package/vendor/desk/mcp/src/desk/naming.js +333 -0
  180. package/vendor/desk/mcp/src/desk/organization.js +592 -0
  181. package/vendor/desk/mcp/src/desk/resources.js +274 -0
  182. package/vendor/desk/mcp/src/desk/runtime-resolver.js +30 -0
  183. package/vendor/desk/mcp/src/desk/scratch-paths.js +44 -0
  184. package/vendor/desk/mcp/src/desk/step-delivery.js +140 -0
  185. package/vendor/desk/mcp/src/desk/steps.js +263 -0
  186. package/vendor/desk/mcp/src/desk/tidy.js +930 -0
  187. package/vendor/desk/mcp/src/desk/unsigned-deliveries.js +359 -0
  188. package/vendor/desk/mcp/src/factory/agent-types.js +45 -0
  189. package/vendor/desk/mcp/src/factory/andon-watch.js +109 -0
  190. package/vendor/desk/mcp/src/factory/binding.js +612 -0
  191. package/vendor/desk/mcp/src/factory/boot-check.js +645 -0
  192. package/vendor/desk/mcp/src/factory/capture-classify.js +158 -0
  193. package/vendor/desk/mcp/src/factory/capture-count.js +183 -0
  194. package/vendor/desk/mcp/src/factory/capture-flush.js +268 -0
  195. package/vendor/desk/mcp/src/factory/capture-publish.js +141 -0
  196. package/vendor/desk/mcp/src/factory/capture-schema.js +193 -0
  197. package/vendor/desk/mcp/src/factory/capture-sweep.js +239 -0
  198. package/vendor/desk/mcp/src/factory/catch-point.js +60 -0
  199. package/vendor/desk/mcp/src/factory/commit-resolve.js +94 -0
  200. package/vendor/desk/mcp/src/factory/consent-answer.js +37 -0
  201. package/vendor/desk/mcp/src/factory/context-capability.js +15 -0
  202. package/vendor/desk/mcp/src/factory/context-outbox.js +885 -0
  203. package/vendor/desk/mcp/src/factory/context-run.js +386 -0
  204. package/vendor/desk/mcp/src/factory/context-schema.js +249 -0
  205. package/vendor/desk/mcp/src/factory/copilot-turn-index.js +93 -0
  206. package/vendor/desk/mcp/src/factory/copilot-usage.js +148 -0
  207. package/vendor/desk/mcp/src/factory/credential.js +45 -0
  208. package/vendor/desk/mcp/src/factory/derive-claude.js +960 -0
  209. package/vendor/desk/mcp/src/factory/derive-codex.js +734 -0
  210. package/vendor/desk/mcp/src/factory/derive-common.js +279 -0
  211. package/vendor/desk/mcp/src/factory/derive-copilot.js +1057 -0
  212. package/vendor/desk/mcp/src/factory/derive-run.js +807 -0
  213. package/vendor/desk/mcp/src/factory/desk-problem-file.js +310 -0
  214. package/vendor/desk/mcp/src/factory/desk-problem-fingerprint.js +70 -0
  215. package/vendor/desk/mcp/src/factory/desk-problem-known.js +246 -0
  216. package/vendor/desk/mcp/src/factory/desk-problem-template.js +107 -0
  217. package/vendor/desk/mcp/src/factory/desk-repo.js +1223 -0
  218. package/vendor/desk/mcp/src/factory/desk-task-line.js +28 -0
  219. package/vendor/desk/mcp/src/factory/desk-visibility.js +48 -0
  220. package/vendor/desk/mcp/src/factory/end-hook.js +14 -0
  221. package/vendor/desk/mcp/src/factory/evaluate-kick.js +164 -0
  222. package/vendor/desk/mcp/src/factory/evaluate-run.js +678 -0
  223. package/vendor/desk/mcp/src/factory/evaluator-step.js +484 -0
  224. package/vendor/desk/mcp/src/factory/filer-launch.js +79 -0
  225. package/vendor/desk/mcp/src/factory/flush-health.js +26 -0
  226. package/vendor/desk/mcp/src/factory/flush.js +1758 -0
  227. package/vendor/desk/mcp/src/factory/focus.js +326 -0
  228. package/vendor/desk/mcp/src/factory/headless-flag.cjs +32 -0
  229. package/vendor/desk/mcp/src/factory/headless-flag.js +25 -0
  230. package/vendor/desk/mcp/src/factory/headless-ledger.js +743 -0
  231. package/vendor/desk/mcp/src/factory/headless.js +567 -0
  232. package/vendor/desk/mcp/src/factory/held-route.js +93 -0
  233. package/vendor/desk/mcp/src/factory/host-flags.js +36 -0
  234. package/vendor/desk/mcp/src/factory/improvement-verify.js +429 -0
  235. package/vendor/desk/mcp/src/factory/kaizen-file.js +231 -0
  236. package/vendor/desk/mcp/src/factory/label-binding.js +90 -0
  237. package/vendor/desk/mcp/src/factory/label-schema.js +426 -0
  238. package/vendor/desk/mcp/src/factory/local-status.js +368 -0
  239. package/vendor/desk/mcp/src/factory/loop-conditions.js +121 -0
  240. package/vendor/desk/mcp/src/factory/loop-health.js +500 -0
  241. package/vendor/desk/mcp/src/factory/loop-slot.js +90 -0
  242. package/vendor/desk/mcp/src/factory/loop-status.js +100 -0
  243. package/vendor/desk/mcp/src/factory/loop-switch.cjs +14 -0
  244. package/vendor/desk/mcp/src/factory/loop-worker-state.js +96 -0
  245. package/vendor/desk/mcp/src/factory/loop-worker.js +290 -0
  246. package/vendor/desk/mcp/src/factory/marker.js +61 -0
  247. package/vendor/desk/mcp/src/factory/mirror-step.js +145 -0
  248. package/vendor/desk/mcp/src/factory/os-protect.js +243 -0
  249. package/vendor/desk/mcp/src/factory/outbox.js +2231 -0
  250. package/vendor/desk/mcp/src/factory/outcome.js +431 -0
  251. package/vendor/desk/mcp/src/factory/pipeline/andon.js +319 -0
  252. package/vendor/desk/mcp/src/factory/pipeline/attention-rollup.js +158 -0
  253. package/vendor/desk/mcp/src/factory/pipeline/attention.js +146 -0
  254. package/vendor/desk/mcp/src/factory/pipeline/build.js +299 -0
  255. package/vendor/desk/mcp/src/factory/pipeline/compare.js +148 -0
  256. package/vendor/desk/mcp/src/factory/pipeline/formulas.js +652 -0
  257. package/vendor/desk/mcp/src/factory/pipeline/kaizen.js +387 -0
  258. package/vendor/desk/mcp/src/factory/pipeline/lifecycle-clocks.js +345 -0
  259. package/vendor/desk/mcp/src/factory/pipeline/normalize.js +73 -0
  260. package/vendor/desk/mcp/src/factory/pipeline/number-states.js +154 -0
  261. package/vendor/desk/mcp/src/factory/pipeline/outcomes.js +268 -0
  262. package/vendor/desk/mcp/src/factory/pipeline/report.js +737 -0
  263. package/vendor/desk/mcp/src/factory/pipeline/rollups.js +883 -0
  264. package/vendor/desk/mcp/src/factory/pipeline/stretches.js +523 -0
  265. package/vendor/desk/mcp/src/factory/pipeline/timeline.js +199 -0
  266. package/vendor/desk/mcp/src/factory/pipeline/validate-pr.js +238 -0
  267. package/vendor/desk/mcp/src/factory/pipeline/versions.js +42 -0
  268. package/vendor/desk/mcp/src/factory/pipeline/walk.js +1177 -0
  269. package/vendor/desk/mcp/src/factory/plugin-registry.js +72 -0
  270. package/vendor/desk/mcp/src/factory/plugin-sources.cjs +249 -0
  271. package/vendor/desk/mcp/src/factory/pr-green.js +77 -0
  272. package/vendor/desk/mcp/src/factory/process-lock.js +142 -0
  273. package/vendor/desk/mcp/src/factory/proof-session.js +75 -0
  274. package/vendor/desk/mcp/src/factory/publish.js +637 -0
  275. package/vendor/desk/mcp/src/factory/published-schema.js +648 -0
  276. package/vendor/desk/mcp/src/factory/reconcile-reasons.js +22 -0
  277. package/vendor/desk/mcp/src/factory/reconcile-step.js +251 -0
  278. package/vendor/desk/mcp/src/factory/reconcile.js +808 -0
  279. package/vendor/desk/mcp/src/factory/release-version.js +134 -0
  280. package/vendor/desk/mcp/src/factory/repo-name.js +13 -0
  281. package/vendor/desk/mcp/src/factory/retention.js +60 -0
  282. package/vendor/desk/mcp/src/factory/route-desk.js +40 -0
  283. package/vendor/desk/mcp/src/factory/route-issues.js +251 -0
  284. package/vendor/desk/mcp/src/factory/route-local.js +264 -0
  285. package/vendor/desk/mcp/src/factory/schema.js +957 -0
  286. package/vendor/desk/mcp/src/factory/session-kind.js +16 -0
  287. package/vendor/desk/mcp/src/factory/session-lifetime.js +56 -0
  288. package/vendor/desk/mcp/src/factory/session-route.js +183 -0
  289. package/vendor/desk/mcp/src/factory/shell-git.js +500 -0
  290. package/vendor/desk/mcp/src/factory/store-issues.js +143 -0
  291. package/vendor/desk/mcp/src/factory/store-route.js +208 -0
  292. package/vendor/desk/mcp/src/factory/test-state-guard.js +103 -0
  293. package/vendor/desk/mcp/src/factory/time.js +36 -0
  294. package/vendor/desk/mcp/src/factory/tool-issue-file.js +84 -0
  295. package/vendor/desk/mcp/src/factory/tool-kinds.js +87 -0
  296. package/vendor/desk/mcp/src/factory/triage-schema.js +233 -0
  297. package/vendor/desk/mcp/src/factory/windows-acl.js +679 -0
  298. package/vendor/desk/mcp/src/indexer/chunk.js +232 -0
  299. package/vendor/desk/mcp/src/indexer/discover.js +434 -0
  300. package/vendor/desk/mcp/src/indexer/exclusions.js +247 -0
  301. package/vendor/desk/mcp/src/indexer/index.js +167 -0
  302. package/vendor/desk/mcp/src/indexer/refs.js +0 -0
  303. package/vendor/desk/mcp/src/indexer/text-hash.js +18 -0
  304. package/vendor/desk/mcp/src/lib/ouro-actions/actions.claims.json +75 -0
  305. package/vendor/desk/mcp/src/lib/ouro-actions/dist-manifest.json +70 -0
  306. package/vendor/desk/mcp/src/lib/ouro-actions/ouro-actions.mts +1416 -0
  307. package/vendor/desk/mcp/src/lib/ouro-ui/LICENSE +21 -0
  308. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/ax-claims.ts +190 -0
  309. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/ax-command.ts +1020 -0
  310. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/checks.ts +343 -0
  311. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/cli.ts +240 -0
  312. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/component.ts +430 -0
  313. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/dev-commands.ts +204 -0
  314. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/doctor.ts +126 -0
  315. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/effects.ts +68 -0
  316. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/exit-codes.ts +75 -0
  317. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/help.ts +220 -0
  318. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/mcp.ts +268 -0
  319. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/outcome.ts +265 -0
  320. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/output.ts +67 -0
  321. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/precise-copy.ts +235 -0
  322. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/problem.ts +124 -0
  323. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/surfaces.kit.mts +8 -0
  324. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/surfaces.ts +568 -0
  325. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/terminal.ts +245 -0
  326. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/voice.ts +136 -0
  327. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/wait.ts +226 -0
  328. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/work-event.ts +181 -0
  329. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/xray.kit.mts +18 -0
  330. package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/xray.ts +2072 -0
  331. package/vendor/desk/mcp/src/package-metadata.js +20 -0
  332. package/vendor/desk/mcp/src/protected/legacy-ledger.js +55 -0
  333. package/vendor/desk/mcp/src/readiness/leftovers.js +75 -0
  334. package/vendor/desk/mcp/src/readiness/process-start.js +149 -0
  335. package/vendor/desk/mcp/src/runtime/admission-worker.js +194 -0
  336. package/vendor/desk/mcp/src/runtime/admission.js +177 -0
  337. package/vendor/desk/mcp/src/runtime/agency-desk-channel.js +342 -0
  338. package/vendor/desk/mcp/src/runtime/agents-md.js +62 -0
  339. package/vendor/desk/mcp/src/runtime/append-lane.js +68 -0
  340. package/vendor/desk/mcp/src/runtime/argv-safe-reason.js +55 -0
  341. package/vendor/desk/mcp/src/runtime/boot-dependencies.js +75 -0
  342. package/vendor/desk/mcp/src/runtime/boot-text.js +504 -0
  343. package/vendor/desk/mcp/src/runtime/boot.js +1677 -0
  344. package/vendor/desk/mcp/src/runtime/bootstrap.js +1455 -0
  345. package/vendor/desk/mcp/src/runtime/chunked-import.js +102 -0
  346. package/vendor/desk/mcp/src/runtime/copilot-commit-trailer.js +133 -0
  347. package/vendor/desk/mcp/src/runtime/copilot-session.js +155 -0
  348. package/vendor/desk/mcp/src/runtime/deliver.js +469 -0
  349. package/vendor/desk/mcp/src/runtime/desk-channel.js +86 -0
  350. package/vendor/desk/mcp/src/runtime/desk-failure.js +26 -0
  351. package/vendor/desk/mcp/src/runtime/desk-health.js +168 -0
  352. package/vendor/desk/mcp/src/runtime/desk-session.js +1451 -0
  353. package/vendor/desk/mcp/src/runtime/diagnostic-server.js +72 -0
  354. package/vendor/desk/mcp/src/runtime/diagnostics.js +241 -0
  355. package/vendor/desk/mcp/src/runtime/drains-cli.js +187 -0
  356. package/vendor/desk/mcp/src/runtime/drains.js +781 -0
  357. package/vendor/desk/mcp/src/runtime/elsewhere-note.js +9 -0
  358. package/vendor/desk/mcp/src/runtime/failure-evidence.js +21 -0
  359. package/vendor/desk/mcp/src/runtime/fast-refs.js +209 -0
  360. package/vendor/desk/mcp/src/runtime/filer-throttle.js +66 -0
  361. package/vendor/desk/mcp/src/runtime/focused-card.js +147 -0
  362. package/vendor/desk/mcp/src/runtime/front-door.js +204 -0
  363. package/vendor/desk/mcp/src/runtime/gate-wait.js +2 -0
  364. package/vendor/desk/mcp/src/runtime/git-inspection.js +201 -0
  365. package/vendor/desk/mcp/src/runtime/git-read-worker.js +157 -0
  366. package/vendor/desk/mcp/src/runtime/health.js +50 -0
  367. package/vendor/desk/mcp/src/runtime/hooks.js +353 -0
  368. package/vendor/desk/mcp/src/runtime/hosted.js +163 -0
  369. package/vendor/desk/mcp/src/runtime/inbox.js +102 -0
  370. package/vendor/desk/mcp/src/runtime/index-drift.js +118 -0
  371. package/vendor/desk/mcp/src/runtime/last-start.js +133 -0
  372. package/vendor/desk/mcp/src/runtime/lesson-section.js +92 -0
  373. package/vendor/desk/mcp/src/runtime/lessons-shelf.js +100 -0
  374. package/vendor/desk/mcp/src/runtime/lfs.js +319 -0
  375. package/vendor/desk/mcp/src/runtime/native-path.js +12 -0
  376. package/vendor/desk/mcp/src/runtime/newest-release.js +197 -0
  377. package/vendor/desk/mcp/src/runtime/node-selection.js +233 -0
  378. package/vendor/desk/mcp/src/runtime/orca-session-title.js +225 -0
  379. package/vendor/desk/mcp/src/runtime/other-sessions.js +183 -0
  380. package/vendor/desk/mcp/src/runtime/pending-migrations.js +653 -0
  381. package/vendor/desk/mcp/src/runtime/plugin-update.js +215 -0
  382. package/vendor/desk/mcp/src/runtime/pluginless-runtimes.js +34 -0
  383. package/vendor/desk/mcp/src/runtime/pr-publication.js +226 -0
  384. package/vendor/desk/mcp/src/runtime/preview-snapshot.js +23 -0
  385. package/vendor/desk/mcp/src/runtime/publication-mode.js +19 -0
  386. package/vendor/desk/mcp/src/runtime/relays.js +974 -0
  387. package/vendor/desk/mcp/src/runtime/release-alert.js +148 -0
  388. package/vendor/desk/mcp/src/runtime/remote-identity.js +140 -0
  389. package/vendor/desk/mcp/src/runtime/resolve-here.js +4 -0
  390. package/vendor/desk/mcp/src/runtime/runtime-deps-cli.js +65 -0
  391. package/vendor/desk/mcp/src/runtime/runtime-deps.js +1109 -0
  392. package/vendor/desk/mcp/src/runtime/runtime-identity.js +22 -0
  393. package/vendor/desk/mcp/src/runtime/runtime-swap.js +101 -0
  394. package/vendor/desk/mcp/src/runtime/schedules.js +235 -0
  395. package/vendor/desk/mcp/src/runtime/session-activity.js +190 -0
  396. package/vendor/desk/mcp/src/runtime/session-label.js +30 -0
  397. package/vendor/desk/mcp/src/runtime/session-retention.js +662 -0
  398. package/vendor/desk/mcp/src/runtime/session-sync.js +333 -0
  399. package/vendor/desk/mcp/src/runtime/session-trailer.js +126 -0
  400. package/vendor/desk/mcp/src/runtime/sessions-cli.js +301 -0
  401. package/vendor/desk/mcp/src/runtime/signoff-listed.js +81 -0
  402. package/vendor/desk/mcp/src/runtime/skills.js +76 -0
  403. package/vendor/desk/mcp/src/runtime/stale-card-lead.js +52 -0
  404. package/vendor/desk/mcp/src/runtime/stale-desk-refresh.js +198 -0
  405. package/vendor/desk/mcp/src/runtime/stale-desk.js +219 -0
  406. package/vendor/desk/mcp/src/runtime/stalled.js +255 -0
  407. package/vendor/desk/mcp/src/runtime/standing-authority.js +79 -0
  408. package/vendor/desk/mcp/src/runtime/startup-boot.js +341 -0
  409. package/vendor/desk/mcp/src/runtime/startup-resolve.js +140 -0
  410. package/vendor/desk/mcp/src/runtime/state-branch.js +203 -0
  411. package/vendor/desk/mcp/src/runtime/status-compact.js +165 -0
  412. package/vendor/desk/mcp/src/runtime/status-inspection-child.js +26 -0
  413. package/vendor/desk/mcp/src/runtime/status-inspection.js +147 -0
  414. package/vendor/desk/mcp/src/runtime/status-root.js +39 -0
  415. package/vendor/desk/mcp/src/runtime/sync-worker.js +911 -0
  416. package/vendor/desk/mcp/src/runtime/test-state-guard.js +107 -0
  417. package/vendor/desk/mcp/src/runtime/unmerged-saves.js +247 -0
  418. package/vendor/desk/mcp/src/runtime/workspace-claim.js +53 -0
  419. package/vendor/desk/mcp/src/runtime/workspace-evidence.js +96 -0
  420. package/vendor/desk/mcp/src/runtime/workspace-tidy.js +509 -0
  421. package/vendor/desk/mcp/src/search/direct-lexical.js +54 -0
  422. package/vendor/desk/mcp/src/search/embedder.js +108 -0
  423. package/vendor/desk/mcp/src/search/engine.js +406 -0
  424. package/vendor/desk/mcp/src/search/files-router.js +22 -0
  425. package/vendor/desk/mcp/src/search/old-index.js +46 -0
  426. package/vendor/desk/mcp/src/search/vectors.js +60 -0
  427. package/vendor/desk/mcp/src/server.js +389 -0
  428. package/vendor/desk/mcp/src/tool-names.js +73 -0
  429. package/vendor/desk/mcp/src/tool-refusal.cjs +35 -0
  430. package/vendor/desk/mcp/src/tool-schema-parts.js +12 -0
  431. package/vendor/desk/mcp/src/tool-schemas.js +325 -0
  432. package/vendor/desk/mcp/src/tools/_card-commit.js +148 -0
  433. package/vendor/desk/mcp/src/tools/archive-links.js +185 -0
  434. package/vendor/desk/mcp/src/tools/archive-move.js +18 -0
  435. package/vendor/desk/mcp/src/tools/archive-native-session.js +728 -0
  436. package/vendor/desk/mcp/src/tools/archive-state.js +513 -0
  437. package/vendor/desk/mcp/src/tools/delivery-gate.js +251 -0
  438. package/vendor/desk/mcp/src/tools/desk-save.js +444 -0
  439. package/vendor/desk/mcp/src/tools/doctor.js +122 -0
  440. package/vendor/desk/mcp/src/tools/done-evidence.js +260 -0
  441. package/vendor/desk/mcp/src/tools/factory-context.js +204 -0
  442. package/vendor/desk/mcp/src/tools/friction.js +332 -0
  443. package/vendor/desk/mcp/src/tools/improvement.js +156 -0
  444. package/vendor/desk/mcp/src/tools/lesson-lines.js +22 -0
  445. package/vendor/desk/mcp/src/tools/lesson-owners.js +137 -0
  446. package/vendor/desk/mcp/src/tools/lesson-team.js +169 -0
  447. package/vendor/desk/mcp/src/tools/lesson.js +254 -0
  448. package/vendor/desk/mcp/src/tools/local-only.js +151 -0
  449. package/vendor/desk/mcp/src/tools/move.js +794 -0
  450. package/vendor/desk/mcp/src/tools/native-stage-context.js +32 -0
  451. package/vendor/desk/mcp/src/tools/note.js +267 -0
  452. package/vendor/desk/mcp/src/tools/search.js +634 -0
  453. package/vendor/desk/mcp/src/tools/shared-write.js +196 -0
  454. package/vendor/desk/mcp/src/tools/sibling-desk.js +37 -0
  455. package/vendor/desk/mcp/src/tools/status.js +233 -0
  456. package/vendor/desk/mcp/src/tools/task-archive-due.js +9 -0
  457. package/vendor/desk/mcp/src/tools/task-archived-resource.js +53 -0
  458. package/vendor/desk/mcp/src/tools/task-body.js +141 -0
  459. package/vendor/desk/mcp/src/tools/task-focus.js +164 -0
  460. package/vendor/desk/mcp/src/tools/task-log.js +76 -0
  461. package/vendor/desk/mcp/src/tools/task-signoff.js +155 -0
  462. package/vendor/desk/mcp/src/tools/task.js +1768 -0
  463. package/vendor/desk/mcp/src/tools/track-row.js +89 -0
  464. package/vendor/desk/mcp/src/tools/track.js +240 -0
  465. package/vendor/desk/mcp/src/util/agency-session.cjs +29 -0
  466. package/vendor/desk/mcp/src/util/archive-links.js +105 -0
  467. package/vendor/desk/mcp/src/util/bash.js +36 -0
  468. package/vendor/desk/mcp/src/util/capture-record.js +73 -0
  469. package/vendor/desk/mcp/src/util/cas-commit.js +252 -0
  470. package/vendor/desk/mcp/src/util/created-dirs.js +71 -0
  471. package/vendor/desk/mcp/src/util/deferred-tools.js +51 -0
  472. package/vendor/desk/mcp/src/util/desk-owner.js +99 -0
  473. package/vendor/desk/mcp/src/util/env-value.js +13 -0
  474. package/vendor/desk/mcp/src/util/file-identity.js +40 -0
  475. package/vendor/desk/mcp/src/util/finish-commit.js +145 -0
  476. package/vendor/desk/mcp/src/util/fm.js +410 -0
  477. package/vendor/desk/mcp/src/util/git-config-file.js +85 -0
  478. package/vendor/desk/mcp/src/util/git-stage.js +440 -0
  479. package/vendor/desk/mcp/src/util/main-publish.js +240 -0
  480. package/vendor/desk/mcp/src/util/markdown-links.cjs +555 -0
  481. package/vendor/desk/mcp/src/util/object-input.js +59 -0
  482. package/vendor/desk/mcp/src/util/paths.js +647 -0
  483. package/vendor/desk/mcp/src/util/rank.js +189 -0
  484. package/vendor/desk/mcp/src/util/redact.js +92 -0
  485. package/vendor/desk/mcp/src/util/remove-retry.js +35 -0
  486. package/vendor/desk/mcp/src/util/rename-retry.js +73 -0
  487. package/vendor/desk/mcp/src/util/route-around.js +265 -0
  488. package/vendor/desk/mcp/src/util/shell-quote.js +18 -0
  489. package/vendor/desk/mcp/src/util/startup-direction.js +124 -0
  490. package/vendor/desk/mcp/src/util/state-ignore.js +33 -0
  491. package/vendor/desk/mcp/src/util/tool-commits.js +64 -0
  492. package/vendor/desk/mcp/src/util/unicode-16/LICENSE-MIT.txt +7 -0
  493. package/vendor/desk/mcp/src/util/unicode-16/README.md +9 -0
  494. package/vendor/desk/mcp/src/util/unicode-16/letter.cjs +1 -0
  495. package/vendor/desk/mcp/src/util/unicode-16/mark.cjs +1 -0
  496. package/vendor/desk/mcp/src/util/unicode-16/number.cjs +1 -0
  497. package/vendor/desk/mcp/web-auth.cjs +1897 -0
  498. package/vendor/desk/mcp/web-browser-discovery.cjs +53 -0
  499. package/vendor/desk/mcp/web-catalog.json +34 -0
  500. package/vendor/desk/mcp/web-launch.cjs +101 -0
  501. package/vendor/desk/mcp/web.cjs +1239 -0
  502. package/vendor/desk/migrations/01-move-to-ourostack-desk.md +188 -0
  503. package/vendor/desk/migrations/02-tidy-desk.md +87 -0
  504. package/vendor/desk/migrations/03-desk-release-channel.md +38 -0
  505. package/vendor/desk/optional/session-label/consumer.mjs +237 -0
  506. package/vendor/desk/optional/session-label/extension.mjs +32 -0
  507. package/vendor/desk/plugin.json +54 -0
  508. package/vendor/desk/settings.json +3 -0
  509. package/vendor/desk/skills/add-workspace-mcp/SKILL.md +180 -0
  510. package/vendor/desk/skills/adopt-inflight-work/SKILL.md +212 -0
  511. package/vendor/desk/skills/archive-workflow/SKILL.md +132 -0
  512. package/vendor/desk/skills/content-routing/SKILL.md +95 -0
  513. package/vendor/desk/skills/core-meeting-capture/SKILL.md +47 -0
  514. package/vendor/desk/skills/core-meeting-capture/references/capture-contract.md +175 -0
  515. package/vendor/desk/skills/curator/SKILL.md +103 -0
  516. package/vendor/desk/skills/delightful-decks/SKILL.md +67 -0
  517. package/vendor/desk/skills/desk-problem/SKILL.md +87 -0
  518. package/vendor/desk/skills/directory-structure/SKILL.md +169 -0
  519. package/vendor/desk/skills/doc-review-rigor/SKILL.md +63 -0
  520. package/vendor/desk/skills/draining-issues/SKILL.md +62 -0
  521. package/vendor/desk/skills/evaluate-release/SKILL.md +96 -0
  522. package/vendor/desk/skills/evidence-discipline/SKILL.md +150 -0
  523. package/vendor/desk/skills/factory-evaluator/SKILL.md +122 -0
  524. package/vendor/desk/skills/factory-task-context/SKILL.md +116 -0
  525. package/vendor/desk/skills/factory-work/SKILL.md +16 -0
  526. package/vendor/desk/skills/fast-honest-ci/SKILL.md +70 -0
  527. package/vendor/desk/skills/fast-honest-ci/examples.md +49 -0
  528. package/vendor/desk/skills/first-run-bootstrap/SKILL.md +95 -0
  529. package/vendor/desk/skills/friction-management/SKILL.md +98 -0
  530. package/vendor/desk/skills/git-hygiene/SKILL.md +253 -0
  531. package/vendor/desk/skills/independent-review/SKILL.md +34 -0
  532. package/vendor/desk/skills/interaction-style/SKILL.md +239 -0
  533. package/vendor/desk/skills/lesson-capture/SKILL.md +85 -0
  534. package/vendor/desk/skills/lesson-capture/agents-md-budget.mjs +61 -0
  535. package/vendor/desk/skills/online-evaluation/SKILL.md +81 -0
  536. package/vendor/desk/skills/operator-voice-comments/LICENSE-humanize +21 -0
  537. package/vendor/desk/skills/operator-voice-comments/SKILL.md +90 -0
  538. package/vendor/desk/skills/operator-voice-comments/human-voice.md +43 -0
  539. package/vendor/desk/skills/peer-pr-review/SKILL.md +104 -0
  540. package/vendor/desk/skills/pr-feedback-on-own-pr/SKILL.md +145 -0
  541. package/vendor/desk/skills/pr-review-interrogation/SKILL.md +121 -0
  542. package/vendor/desk/skills/pr-reviewer-audit/SKILL.md +68 -0
  543. package/vendor/desk/skills/pr-reviewer-audit/helpers/audit.py +335 -0
  544. package/vendor/desk/skills/pr-reviewer-audit/helpers/test_audit.py +486 -0
  545. package/vendor/desk/skills/pr-self-review/SKILL.md +86 -0
  546. package/vendor/desk/skills/pr-surface-hygiene/SKILL.md +105 -0
  547. package/vendor/desk/skills/pr-surface-hygiene/check-visual-proof.cjs +99 -0
  548. package/vendor/desk/skills/pr-surface-hygiene/repository-setup.md +19 -0
  549. package/vendor/desk/skills/pr-surface-hygiene/resources/pr-visual-proof.yml +29 -0
  550. package/vendor/desk/skills/pr-surface-hygiene/resources/pull-request-template.md +5 -0
  551. package/vendor/desk/skills/preflight-actions/SKILL.md +60 -0
  552. package/vendor/desk/skills/preview-feedback/SKILL.md +70 -0
  553. package/vendor/desk/skills/repo-handling/SKILL.md +67 -0
  554. package/vendor/desk/skills/rnd-lab/SKILL.md +52 -0
  555. package/vendor/desk/skills/runtime-symptom-investigation/SKILL.md +106 -0
  556. package/vendor/desk/skills/session-resumption/SKILL.md +126 -0
  557. package/vendor/desk/skills/session-start/SKILL.md +54 -0
  558. package/vendor/desk/skills/session-start/details.md +150 -0
  559. package/vendor/desk/skills/session-start-migrations/README.md +71 -0
  560. package/vendor/desk/skills/session-start-migrations/SKILL.md +108 -0
  561. package/vendor/desk/skills/start-task/SKILL.md +88 -0
  562. package/vendor/desk/skills/task-card-format/SKILL.md +198 -0
  563. package/vendor/desk/skills/task-lifecycle/SKILL.md +217 -0
  564. package/vendor/desk/skills/track-card-format/SKILL.md +90 -0
  565. package/vendor/desk/skills/using-desk/SKILL.md +58 -0
  566. package/vendor/desk/skills/using-superpowers-with-desk/SKILL.md +156 -0
  567. package/vendor/desk/skills/work-orchestration/SKILL.md +162 -0
@@ -0,0 +1,704 @@
1
+ // Improvement cards: one file per card, a stable key, a claim and legal moves.
2
+ //
3
+ // A card lives on the desk at `<desk>/<person prefix>/_meta/improvement/<source>--<12 hex of
4
+ // sha256(key)>.md`. `personPrefix` is "" for a solo desk and `desks/<alias>` in a crew desk.
5
+ // A card holds pointers, counts and a title the library builds: never prompt text, command text, file content or an
6
+ // absolute path. The only free text is a lesson's topic in its card's title, checked whole before it is written
7
+ // (`lessonTitle`). The only URLs are `countermeasure` (a GitHub pull request) and `kaizen_url`
8
+ // (a GitHub issue), each checked by shape. This module does not commit to Git: every function
9
+ // that writes returns the card file's absolute path so the caller can commit exactly that file.
10
+ //
11
+ // Reading checks shape only; writing enforces the frozen tables and lists. Machines on different Desk
12
+ // versions share a desk through Git, so a card whose title, id, close reason or check result is well
13
+ // formed but not in this version's tables is a valid card on read, and only what this version writes
14
+ // (`openImprovement`, `updateCard`) must be in the tables.
15
+ //
16
+ // Wrong states are impossible, not discouraged. A file that does not parse, breaks the shape, is
17
+ // oversized, or is a link or directory is never read as a card and never guessed at: `readCards` counts
18
+ // it, and the three writers (`claimNext`, `openImprovement`, `updateCard`) move it aside by rename into
19
+ // `improvement/invalid/` under the lock before they act, so the loop heals itself and a set-aside
20
+ // card's claim no longer counts (a bounded, visible gap). A file that cannot be read at all (a
21
+ // permission fault) is left in place and counted, never moved, and does not block a claim. Files that
22
+ // may appear beside the cards, and that a commit step must never stage: the directory
23
+ // `_meta/.improvement.lock/` and `_meta/.improvement-<pid>-<hex>.tmp`.
24
+ //
25
+ // The file is YAML front matter in which every value is JSON (valid YAML) plus a fixed body.
26
+ // Every write takes a lock file created with `wx` beside the card folder (a lock older than two
27
+ // minutes is taken over) and writes a temp file that is renamed over the card.
28
+
29
+ import { promises as fs, constants as fsConstants } from "node:fs"
30
+ import * as path from "node:path"
31
+ import { createHash, randomBytes, randomUUID } from "node:crypto"
32
+ import { PUBLIC_PLUGINS, isGeneric } from "../factory/kaizen-file.js"
33
+ import { SLUG_SOURCE } from "../factory/repo-name.js"
34
+ import { PATTERNS } from "../factory/schema.js"
35
+ import { readMachineSecret } from "../factory/outbox.js"
36
+ import { RECONCILE_REASONS } from "../factory/reconcile-reasons.js"
37
+ import { MEASURE_IDS } from "../factory/pipeline/rollups.js"
38
+
39
+ export const SOURCES = Object.freeze(["andon", "friction_candidate", "reconcile_class", "desk_problem", "store_build", "evaluator", "loop_alarm", "flush_health"])
40
+ export const STATES = Object.freeze(["open", "claimed", "shipped", "verifying", "closed_confirmed", "closed_unverified"])
41
+ export const MOVES = Object.freeze({
42
+ open: Object.freeze(["claimed", "closed_unverified"]),
43
+ claimed: Object.freeze(["open", "shipped", "closed_unverified"]),
44
+ shipped: Object.freeze(["verifying", "closed_confirmed", "closed_unverified", "open"]),
45
+ verifying: Object.freeze(["closed_confirmed", "closed_unverified", "open"]),
46
+ closed_confirmed: Object.freeze(["open"]),
47
+ closed_unverified: Object.freeze(["open"]),
48
+ })
49
+ export const CLAIM_TTL_HOURS = 4
50
+ export const MAX_LIVE_CLAIMS = 1
51
+ // The loop steps whose `step_stale:<step>` alarm this version may write; `triage` came with the loop's triage step (no field, lifecycle or claim change), so an earlier Desk reads its card and never writes it.
52
+ const STEP_NAMES = ["evaluate", "route", "mirror", "reconcile", "verify", "measure", "deliver", "triage"]
53
+ export const LOOP_ALARMS = Object.freeze(["improvement_age", "improvement_stuck", "unsigned_age", "headless_blocked", "labels_quarantined", "label_lag", "facts_quarantine_not_settling", "held_sessions", "cards_invalid", "capture_loop_slot", "triage_engine_unpinned", ...STEP_NAMES.map((step) => `step_stale:${step}`)])
54
+ export const EVALUATOR_NAMES = Object.freeze(["expired_requests", "gave_up"])
55
+ export const FLUSH_HEALTH_CODES = Object.freeze(["no_account", "auth_failed", "gh_missing", "account_cannot_deliver", "route_unknown", "held_markers", "frozen"])
56
+ // The reconcile reasons come from the one list the reconcile code keeps; the measure IDs from the one list the kaizen filer accepts.
57
+ export { RECONCILE_REASONS, MEASURE_IDS }
58
+ // Why a card closed (the close-rules ruling and the verify step), and what a daily check found.
59
+ export const CLOSE_REASONS = Object.freeze([
60
+ "confirmed", "thin_data_after_14_checks", "merged_without_signal", "version_unavailable", "andon_closed", "desk_problem_quiet",
61
+ "reconcile_zero_twice", "store_build_closed", "condition_cleared", "wont_fix", "duplicate", "not_reproducible",
62
+ "source_recovered",
63
+ ])
64
+ export const CHECK_RESULTS = Object.freeze([
65
+ "version_set", "confirmed", "not_confirmed", "thin_data", "version_unavailable", "countermeasure_not_merged", "recovered", "still_recurring", "waiting", "checks_not_green",
66
+ ])
67
+ export const MAX_CARD_FILES = 2000
68
+ export const SET_ASIDE_FOLDER = "invalid"
69
+
70
+ const SCHEMA = "desk.improvement/1"
71
+ const MAX_TITLE = 120
72
+ const MAX_EVIDENCE = 10
73
+ const MAX_CLAIM_LOG = 10
74
+ const MAX_FILE_BYTES = 16 * 1024
75
+ const MAX_FILES = 200
76
+ const LOCK_NAME = ".improvement.lock"
77
+ const MACHINE = /^[0-9a-f]{8,64}$/u
78
+ const CODE = /^[a-z][a-z0-9_]{0,63}$/u
79
+ const MEASURE_SHAPE = /^[a-z][a-z0-9_.]{0,63}$/u
80
+ const LOCK_STALE_MS = 2 * 60 * 1000
81
+ const LOCK_WAIT_MS = 5000
82
+ const LOCK_POLL_MS = 10
83
+ const HOUR_MS = 60 * 60 * 1000
84
+
85
+ const FIELDS = [
86
+ "schema", "key", "source", "title", "evidence", "opened_at", "last_opened_at", "state", "claim", "claim_log", "countermeasure", "plugin", "signal",
87
+ "kaizen_url", "shipped_version", "checks_run", "last_check_at", "last_check_result", "recurrences", "reopened", "closed_at", "close_reason", "verifying_since",
88
+ ]
89
+ const IMMUTABLE = ["key", "source", "opened_at"]
90
+ const REPO_ISSUE = /^(.+)#(\d{1,9})$/u
91
+ const URL_SHAPE = new RegExp(`^https://github\\.com/(${SLUG_SOURCE})/(pull|issues)/\\d{1,9}$`, "u")
92
+ const FILE_NAME = /^([a-z_]+)--([0-9a-f]{12})\.md$/u
93
+ const CONTROL = /[\u0000-\u001f\u007f]/u
94
+ const ABSOLUTE_PATH = /(^|[\s("'`=])(\/[A-Za-z0-9._-]+|[A-Za-z]:[\\/])/u
95
+ const PREFIX_SEGMENT = /^[A-Za-z0-9._-]+$/u
96
+
97
+ const isRepoIssue = (id) => {
98
+ const match = REPO_ISSUE.exec(id)
99
+ return match !== null && PATTERNS.prRepo.test(match[1])
100
+ }
101
+ const ID_CHECKS = {
102
+ andon: isRepoIssue,
103
+ store_build: isRepoIssue,
104
+ desk_problem: (id) => isRepoIssue(id) && id.startsWith("ourostack/desk#"),
105
+ friction_candidate: (id) => /^[0-9a-f]{32}$/u.test(id),
106
+ reconcile_class: (id) => RECONCILE_REASONS.includes(id),
107
+ evaluator: (id) => EVALUATOR_NAMES.includes(id),
108
+ flush_health: (id) => FLUSH_HEALTH_CODES.includes(id),
109
+ loop_alarm: (id) => LOOP_ALARMS.includes(id),
110
+ }
111
+
112
+ // Reading and updating accept any well-formed id (`ID_SHAPES`); writing a new key needs the frozen lists (`ID_CHECKS`).
113
+ const ID_SHAPES = {
114
+ ...ID_CHECKS,
115
+ desk_problem: isRepoIssue,
116
+ reconcile_class: (id) => CODE.test(id),
117
+ evaluator: (id) => CODE.test(id),
118
+ flush_health: (id) => CODE.test(id),
119
+ loop_alarm: (id) => /^[a-z][a-z0-9_]{0,63}(:[a-z][a-z0-9_]{0,63})?$/u.test(id),
120
+ }
121
+
122
+ function keyParts(key, strict = false) {
123
+ if (typeof key !== "string") return null
124
+ const colon = key.indexOf(":")
125
+ const source = key.slice(0, colon)
126
+ if (colon < 0 || !SOURCES.includes(source) || !(strict ? ID_CHECKS : ID_SHAPES)[source](key.slice(colon + 1))) return null
127
+ return { source, id: key.slice(colon + 1) }
128
+ }
129
+
130
+ const FLUSH_TITLES = {
131
+ no_account: "Factory delivery has no account signed in",
132
+ auth_failed: "Factory delivery account sign in failed",
133
+ gh_missing: "Factory delivery cannot find the GitHub command",
134
+ account_cannot_deliver: "No account that is signed in can deliver to the store",
135
+ route_unknown: "Factory store route is unknown",
136
+ held_markers: "Factory markers are held back",
137
+ frozen: "Factory delivery is frozen",
138
+ }
139
+ const LOOP_TITLES = {
140
+ improvement_age: "An improvement card has waited past the age threshold",
141
+ improvement_stuck: "An improvement card has waited in verification past the stuck threshold",
142
+ unsigned_age: "A delivery has waited unsigned past the age threshold",
143
+ headless_blocked: "The headless evaluator is blocked",
144
+ triage_engine_unpinned: "The triage runner engine pin is behind the installed Claude Code",
145
+ labels_quarantined: "Evaluation labels were quarantined",
146
+ label_lag: "A finished job has waited over an hour for labels",
147
+ facts_quarantine_not_settling: "Session facts have sat in a quarantine that does not settle",
148
+ held_sessions: "Ended sessions have been held for over a day without being derived",
149
+ cards_invalid: "Improvement card files were set aside as invalid",
150
+ capture_loop_slot: "The loop health record could not be sent to the store",
151
+ }
152
+
153
+ /**
154
+ * `cardTitle(source, id, { plugin, signal }?) -> string | null`: the title the library builds for every source, from frozen
155
+ * tables, so no free text enters a card through it. A friction candidate's title is fixed words plus the plugin name when it is a
156
+ * public plugin and the signal when it is a known measure (null only for an unknown source).
157
+ */
158
+ export function cardTitle(source, id, { plugin, signal } = {}) {
159
+ switch (source) {
160
+ case "andon": return "Store build andon is open"
161
+ case "store_build": return "Store build is failing"
162
+ case "desk_problem": return "Desk problem filed as a GitHub issue"
163
+ case "reconcile_class": return `Reconcile mismatch: ${id}`
164
+ case "friction_candidate": return `System friction${PUBLIC_PLUGINS.includes(plugin) ? ` in the ${plugin} plugin` : ""}${MEASURE_IDS.includes(signal) ? ` moving ${signal}` : ""}`
165
+ case "evaluator": return id === "gave_up" ? "Evaluation requests were given up after repeated attempts" : "Evaluation requests expired without a label"
166
+ case "flush_health": return FLUSH_TITLES[id]
167
+ case "loop_alarm": return id.startsWith("step_stale:") ? `Loop step ${id.slice("step_stale:".length)} is stale` : LOOP_TITLES[id]
168
+ default: return null
169
+ }
170
+ }
171
+
172
+ // A lesson's owner as lesson_add names it: a plugin's skill, a Desk tool, the child brief or the always-on foundation.
173
+ const LESSON_OWNER = /^(?:skill:[a-z0-9][a-z0-9-]{0,63}:[a-z0-9][a-z0-9-]{0,63}|tool:[a-z][a-z0-9_]{0,63}|brief|foundation)$/u
174
+
175
+ // Any character that would break the card's one-line front matter: controls, U+2028 and U+2029.
176
+ const NOT_ONE_LINE = /[\p{Cc}\p{Zl}\p{Zp}]/u
177
+
178
+ /**
179
+ * `lessonTitle({ owner, topic }) -> string | null`: the title of a lesson's friction card, "Lesson for <owner>: <topic>",
180
+ * cut to the title limit, so the card says which lesson it carries. Null when the owner is not an owner's shape or the whole
181
+ * topic is not one line or holds private text (a credential, email, private path or absolute path); the card then takes the
182
+ * fixed words. The topic is judged whole, before the cut, so no part of a secret survives it, and the cut never splits a
183
+ * character. A cut title can still fail a check the whole one passed (a run of numbers cut into an IPv4 address), so
184
+ * `openImprovement` writes it only when the card reads back.
185
+ */
186
+ function lessonTitle(lesson) {
187
+ const { owner, topic } = lesson !== null && typeof lesson === "object" ? lesson : {}
188
+ if (typeof owner !== "string" || !LESSON_OWNER.test(owner) || typeof topic !== "string" || topic.trim() === "") return null
189
+ const full = `Lesson for ${owner}: ${topic.trim()}`
190
+ if (NOT_ONE_LINE.test(full) || !isCleanTitle(full)) return null
191
+ const title = full.length <= MAX_TITLE ? full : `${full.slice(0, MAX_TITLE - 1).replace(/[\uD800-\uDBFF]$/u, "")}…`
192
+ return title
193
+ }
194
+
195
+ /** `cardKey(source, id) -> string`: the stable key `<source>:<id>`; throws `invalid_source` for an id the source does not allow. */
196
+ export function cardKey(source, id) {
197
+ const key = `${source}:${id}`
198
+ if (!SOURCES.includes(source) || keyParts(key, true) === null) throw new TypeError("invalid_source")
199
+ return key
200
+ }
201
+
202
+ function locationFolder(deskRoot, personPrefix) {
203
+ const segments = personPrefix === "" ? [] : String(personPrefix).split("/")
204
+ const clean = typeof personPrefix === "string" && segments.every((segment) => PREFIX_SEGMENT.test(segment) && segment !== "." && segment !== "..")
205
+ if (typeof deskRoot !== "string" || !path.isAbsolute(deskRoot) || !clean) return null
206
+ return path.join(deskRoot, ...segments, "_meta")
207
+ }
208
+
209
+ const cardFileName = (key) => `${keyParts(key).source}--${createHash("sha256").update(key).digest("hex").slice(0, 12)}.md`
210
+
211
+ /** `cardFile(deskRoot, personPrefix, key) -> string`: the card's absolute path; throws `invalid_location` or `invalid_source`. */
212
+ export function cardFile(deskRoot, personPrefix, key) {
213
+ const meta = locationFolder(deskRoot, personPrefix)
214
+ if (meta === null) throw new TypeError("invalid_location")
215
+ if (keyParts(key) === null) throw new TypeError("invalid_source")
216
+ return path.join(meta, "improvement", cardFileName(key))
217
+ }
218
+
219
+ function toDate(now) {
220
+ const date = now === undefined ? new Date() : new Date(now)
221
+ if (Number.isNaN(date.getTime())) throw Object.assign(new TypeError("Pass `now` as a Date or a millisecond number"), { code: "improvement_cards_pass_now_as_a_date" })
222
+ return date
223
+ }
224
+
225
+ /** `isClaimLive(card, now) -> boolean`: the card carries a claim whose expiry is still ahead of `now` (a Date or milliseconds). */
226
+ export function isClaimLive(card, now) {
227
+ return card.claim !== null && card.claim.expires_at !== null && Date.parse(card.claim.expires_at) > new Date(now).getTime()
228
+ }
229
+
230
+ // ---------------------------------------------------------------------------
231
+ // Field rules
232
+
233
+ const isTimestamp = (value) => typeof value === "string" && PATTERNS.timestamp.test(value) && !Number.isNaN(Date.parse(value))
234
+ const nullable = (check) => (value) => value === null || check(value)
235
+ const isCount = (value) => Number.isInteger(value) && value >= 0 && value <= 1000000
236
+ const isMachine = (value) => typeof value === "string" && MACHINE.test(value)
237
+ const oneOf = (list) => (value) => list.includes(value)
238
+
239
+ function isPointer(value, strict) {
240
+ if (typeof value !== "string") return false
241
+ const colon = value.indexOf(":")
242
+ const rest = value.slice(colon + 1)
243
+ switch (value.slice(0, colon)) {
244
+ case "job": return PATTERNS.jobId.test(rest)
245
+ case "fingerprint": return /^[0-9a-f]{8,64}$/u.test(rest)
246
+ case "reconcile": return /^[a-z_]+@\d{1,6}$/u.test(rest) && (!strict || RECONCILE_REASONS.includes(rest.slice(0, rest.indexOf("@"))))
247
+ case "issue":
248
+ case "pr": return isRepoIssue(rest)
249
+ default: return false
250
+ }
251
+ }
252
+
253
+ const isEvidence = (value) => Array.isArray(value) && value.length <= MAX_EVIDENCE && value.every((pointer) => isPointer(pointer, true))
254
+ const isEvidenceShape = (value) => Array.isArray(value) && value.length <= MAX_EVIDENCE && value.every((pointer) => isPointer(pointer, false))
255
+
256
+ function isGithubUrl(kind) {
257
+ return (value) => {
258
+ const match = typeof value === "string" ? URL_SHAPE.exec(value) : null
259
+ return match !== null && match[2] === kind && PATTERNS.prRepo.test(match[1])
260
+ }
261
+ }
262
+
263
+ function isFrictionTitle(value) {
264
+ return typeof value === "string" && value.trim() !== "" && value.length <= MAX_TITLE && !CONTROL.test(value)
265
+ }
266
+ const isCleanTitle = (value) => isGeneric(value) && !ABSOLUTE_PATH.test(value)
267
+
268
+ function isClaim(value) {
269
+ if (value === null) return true
270
+ const keys = typeof value === "object" && !Array.isArray(value) ? Object.keys(value).sort().join() : ""
271
+ return keys === "claim_id,claimed_at,expires_at,machine,session" && PATTERNS.sessionId.test(String(value.claim_id)) && isTimestamp(value.claimed_at) &&
272
+ nullable(isTimestamp)(value.expires_at) && isMachine(value.machine) && nullable((id) => PATTERNS.sessionId.test(String(id)))(value.session)
273
+ }
274
+
275
+ function isClaimLogEntry(entry) {
276
+ return entry !== null && typeof entry === "object" && Object.keys(entry).sort().join() === "at,machine" && isTimestamp(entry.at) && isMachine(entry.machine)
277
+ }
278
+
279
+ // The fields a later step may patch, each with its check and the code a refused value gets. `reopened` and
280
+ // `recurrences` are not patchable: only a counted move or `openImprovement` raises them.
281
+ const PATCHABLE = {
282
+ state: [oneOf(STATES)],
283
+ evidence: [isEvidence, "invalid_patch", isEvidenceShape],
284
+ countermeasure: [nullable(isGithubUrl("pull")), "invalid_countermeasure"],
285
+ kaizen_url: [nullable(isGithubUrl("issues")), "invalid_kaizen_url"],
286
+ plugin: [(value) => typeof value === "string" && PATTERNS.pluginName.test(value)],
287
+ signal: [nullable(oneOf(MEASURE_IDS)), "invalid_patch", nullable((value) => typeof value === "string" && MEASURE_SHAPE.test(value))],
288
+ shipped_version: [nullable((value) => typeof value === "string" && PATTERNS.semver.test(value))],
289
+ checks_run: [isCount],
290
+ last_check_at: [nullable(isTimestamp)],
291
+ last_check_result: [nullable(oneOf(CHECK_RESULTS)), "invalid_patch", nullable((value) => typeof value === "string" && CODE.test(value))],
292
+ close_reason: [nullable(oneOf(CLOSE_REASONS)), "invalid_patch", nullable((value) => typeof value === "string" && CODE.test(value))],
293
+ }
294
+
295
+ // `card` is always the plain object `parse` returns.
296
+ function isCard(card) {
297
+ if (Object.keys(card).sort().join() !== [...FIELDS].sort().join()) return false
298
+ const parts = keyParts(card.key)
299
+ const checks = [
300
+ card.schema === SCHEMA,
301
+ parts !== null && parts.source === card.source,
302
+ isFrictionTitle(card.title) && isCleanTitle(card.title),
303
+ isTimestamp(card.opened_at),
304
+ isTimestamp(card.last_opened_at),
305
+ isClaim(card.claim),
306
+ Array.isArray(card.claim_log) && card.claim_log.length <= MAX_CLAIM_LOG && card.claim_log.every(isClaimLogEntry),
307
+ nullable(isTimestamp)(card.closed_at),
308
+ nullable(isTimestamp)(card.verifying_since),
309
+ isCount(card.recurrences),
310
+ isCount(card.reopened),
311
+ ...Object.entries(PATCHABLE).map(([field, [strict, , shape = strict]]) => shape(card[field])),
312
+ ]
313
+ if (!checks.every(Boolean)) return false
314
+ const closed = card.state.startsWith("closed_")
315
+ return (card.state !== "claimed" || (card.claim !== null && card.claim.expires_at !== null)) &&
316
+ (card.state !== "shipped" && card.state !== "verifying" ? true : card.countermeasure !== null) &&
317
+ (card.state !== "verifying" || card.shipped_version !== null) &&
318
+ closed === (card.closed_at !== null) && closed === (card.close_reason !== null)
319
+ }
320
+
321
+ // ---------------------------------------------------------------------------
322
+ // Files
323
+
324
+ function serialize(card) {
325
+ const front = FIELDS.map((field) => `${field}: ${JSON.stringify(card[field])}`).join("\n")
326
+ return `---\n${front}\n---\n# ${card.title}\n\nStanding improvement card. Desk builds its title; the rest is pointers and counts. Read the front matter.\n`
327
+ }
328
+
329
+ // Whether the text `serialize` writes for `card` parses back to a valid card.
330
+ function readsBack(card) {
331
+ const back = parse(serialize(card))
332
+ return back !== null && isCard(back)
333
+ }
334
+
335
+ function parse(text) {
336
+ const lines = text.split("\n")
337
+ const end = lines[0] === "---" ? lines.indexOf("---", 1) : -1
338
+ if (end < 0) return null
339
+ const data = {}
340
+ for (const line of lines.slice(1, end)) {
341
+ const match = /^([a-z_]+): (.*)$/u.exec(line)
342
+ if (match === null || Object.hasOwn(data, match[1])) return null
343
+ try {
344
+ data[match[1]] = JSON.parse(match[2])
345
+ } catch {
346
+ return null
347
+ }
348
+ }
349
+ // A card written before the field existed reads as never having entered verification.
350
+ if (!Object.hasOwn(data, "verifying_since")) data.verifying_since = null
351
+ return data
352
+ }
353
+
354
+ // `{ card }` or `{ kind }`, kind being how the file failed. Reads no-follow and under the size cap.
355
+ async function inspect(file) {
356
+ let stat
357
+ try {
358
+ stat = await fs.lstat(file)
359
+ } catch {
360
+ return { kind: "missing" }
361
+ }
362
+ if (stat.isSymbolicLink()) return { kind: "symlink" }
363
+ if (!stat.isFile()) return { kind: "not_regular" }
364
+ if (stat.size > MAX_FILE_BYTES) return { kind: "too_large" }
365
+ let text
366
+ try {
367
+ text = await fs.readFile(file, { encoding: "utf8", flag: fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW })
368
+ } catch {
369
+ return { kind: "unreadable" }
370
+ }
371
+ const data = parse(text)
372
+ if (data === null) return { kind: "unparseable" }
373
+ return isCard(data) ? { card: data } : { kind: "invalid" }
374
+ }
375
+
376
+ // The card folder is missing (fine), a folder, or something else (unreadable).
377
+ async function folderState(folder) {
378
+ try {
379
+ const stat = await fs.lstat(folder)
380
+ return stat.isDirectory() ? "directory" : "unreadable"
381
+ } catch (error) {
382
+ return error.code === "ENOENT" ? "missing" : "unreadable"
383
+ }
384
+ }
385
+
386
+ // Reads the folder: the valid cards, how many of each kind were skipped, and the names of the files to set aside.
387
+ async function scan(deskRoot, personPrefix, limit) {
388
+ const empty = { cards: [], unreadable: false, truncated: false, skipped: {}, bad: [], set_aside_total: 0, unreadable_files: 0 }
389
+ const meta = locationFolder(deskRoot, personPrefix)
390
+ if (meta === null) return { ...empty, unreadable: true }
391
+ const folder = path.join(meta, "improvement")
392
+ const state = await folderState(folder)
393
+ if (state === "missing") return empty
394
+ let names
395
+ try {
396
+ names = state === "directory" ? (await fs.readdir(folder)).filter((name) => name !== SET_ASIDE_FOLDER).sort() : null
397
+ } catch {
398
+ names = null
399
+ }
400
+ const aside = names === null ? null : await setAsideCount(folder)
401
+ if (aside === null) return { ...empty, unreadable: true }
402
+ const result = { ...empty, truncated: names.length > limit, set_aside_total: aside }
403
+ const skip = (kind, name) => {
404
+ result.skipped[kind] = (result.skipped[kind] ?? 0) + 1
405
+ if (kind !== "foreign" && kind !== "unreadable") result.bad.push(name)
406
+ }
407
+ for (const name of names.slice(0, limit)) {
408
+ if (!FILE_NAME.test(name)) {
409
+ skip("foreign", name)
410
+ continue
411
+ }
412
+ const found = await inspect(path.join(folder, name))
413
+ if (found.card === undefined) skip(found.kind, name)
414
+ else if (cardFileName(found.card.key) !== name) skip("misnamed", name)
415
+ else result.cards.push(found.card)
416
+ }
417
+ result.unreadable_files = result.skipped.unreadable ?? 0
418
+ return result
419
+ }
420
+
421
+ // How many files sit in `invalid/`; null when `invalid` is not a folder (or cannot be listed).
422
+ async function setAsideCount(folder) {
423
+ const aside = path.join(folder, SET_ASIDE_FOLDER)
424
+ const state = await folderState(aside)
425
+ if (state === "missing") return 0
426
+ try {
427
+ return state === "directory" ? (await fs.readdir(aside)).length : null
428
+ } catch {
429
+ return null
430
+ }
431
+ }
432
+
433
+ /**
434
+ * `readCards({ deskRoot, personPrefix, limit = 200 }) -> { cards, unreadable, truncated, skipped, set_aside_total, unreadable_files }`. Read-only.
435
+ * Bounded: regular files only, no-follow, at most 16 KiB each, at most `limit` files in name order
436
+ * (`truncated` says more existed). A file that fails is counted in `skipped` by kind (`symlink`,
437
+ * `not_regular`, `too_large`, `unreadable`, `unparseable`, `invalid`, `misnamed`, `foreign`) and never
438
+ * returned. `set_aside_total` is how many files sit in `invalid/` (never read), and `unreadable_files` how many
439
+ * card files could not be read and were left in place: durable state from which the measure step opens
440
+ * `loop_alarm:cards_invalid`. An `invalid` entry that is not a folder makes the whole read `unreadable`.
441
+ */
442
+ export async function readCards({ deskRoot, personPrefix, limit = MAX_FILES }) {
443
+ const { cards, unreadable, truncated, skipped, set_aside_total: setAsideTotal, unreadable_files: unreadableFiles } = await scan(deskRoot, personPrefix, limit)
444
+ return { cards, unreadable, truncated, skipped, set_aside_total: setAsideTotal, unreadable_files: unreadableFiles }
445
+ }
446
+
447
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
448
+ // Takes the lock, a directory made with `mkdir` (atomic) that holds one empty directory named by the caller's unique token;
449
+ // `false` when it is not free within `wait` ms. Every step touches only the caller's own token path or the lock directory
450
+ // when empty, so no interleaving can remove a lock another caller holds: a caller owns the lock only if it made its token
451
+ // directory, and the creator retries when its lock directory was removed between the two `mkdir` calls. A lock whose token
452
+ // directory is older than two minutes is taken over by removing exactly that token directory (a second taker, or a
453
+ // holder releasing at the same time, finds it gone and starts again).
454
+ // Windows refuses to create a folder whose deletion is still pending (EPERM, sometimes EACCES), and a lock another caller has just released is such a folder for a moment, so it is contention for about this long, not a fault.
455
+ const LOCK_PENDING_DELETE_MS = 5000
456
+ async function acquire(lock, token, wait, hooks) {
457
+ const deadline = Date.now() + wait
458
+ const pendingDeadline = Date.now() + LOCK_PENDING_DELETE_MS
459
+ for (;;) {
460
+ try {
461
+ await fs.mkdir(lock)
462
+ await hooks.afterLockDir?.(lock)
463
+ await fs.mkdir(path.join(lock, token))
464
+ return true
465
+ } catch (error) {
466
+ if (error.code === "ENOENT") continue
467
+ if ((error.code === "EPERM" || error.code === "EACCES") && (hooks.platform ?? process.platform) === "win32" && Date.now() < pendingDeadline) {
468
+ await sleep(LOCK_POLL_MS)
469
+ continue
470
+ }
471
+ if (error.code !== "EEXIST") throw error
472
+ }
473
+ const children = await fs.readdir(lock).catch(() => null)
474
+ await hooks.afterList?.(lock)
475
+ const stat = children === null ? null : await fs.stat(children.length === 0 ? lock : path.join(lock, children[0])).catch(() => null)
476
+ if (stat !== null && Date.now() - stat.mtimeMs > LOCK_STALE_MS) {
477
+ await hooks.afterStale?.(lock)
478
+ for (const child of children) await fs.rm(path.join(lock, child), { recursive: true, force: true })
479
+ await fs.rmdir(lock).catch(() => {})
480
+ } else if (Date.now() >= deadline) {
481
+ return false
482
+ } else {
483
+ await sleep(LOCK_POLL_MS)
484
+ }
485
+ }
486
+ }
487
+
488
+ // Runs `work({ folder, meta, cards, truncated })` under the lock, after moving every bad card file aside. The result of
489
+ // `work` gains `set_aside` (a count) and `set_aside_files` (absolute paths, each moved file's old and new path, for the
490
+ // caller to commit) only when something was moved. Other results: `invalid_location`, `unreadable_folder`, `lock_busy`.
491
+ async function withLock({ deskRoot, personPrefix, lockWaitMs = LOCK_WAIT_MS, lockHooks = {} }, work) {
492
+ const meta = locationFolder(deskRoot, personPrefix)
493
+ if (meta === null) return { result: "invalid_location" }
494
+ const folder = path.join(meta, "improvement")
495
+ if ((await folderState(folder)) === "unreadable") return { result: "unreadable_folder" }
496
+ await fs.mkdir(meta, { recursive: true })
497
+ return holdLock(path.join(meta, LOCK_NAME), { lockWaitMs, lockHooks }, async () => {
498
+ const scanned = await scan(deskRoot, personPrefix, MAX_CARD_FILES)
499
+ if (scanned.unreadable) return { result: "unreadable_folder" }
500
+ const files = []
501
+ for (const name of scanned.bad) {
502
+ const target = path.join(folder, SET_ASIDE_FOLDER, `${name}.${randomBytes(3).toString("hex")}`)
503
+ await fs.mkdir(path.dirname(target), { recursive: true })
504
+ await fs.rename(path.join(folder, name), target)
505
+ files.push(path.join(folder, name), target)
506
+ }
507
+ const result = await work({ folder, meta, cards: scanned.cards, truncated: scanned.truncated })
508
+ return files.length === 0 ? result : { ...result, set_aside: files.length / 2, set_aside_files: files }
509
+ })
510
+ }
511
+
512
+ /**
513
+ * `holdLock(lock, { lockWaitMs, lockHooks }, work)`: runs `work()` while holding the directory lock at `lock` (see
514
+ * `acquire`) and releases it after; `{ result: "lock_busy" }` when the lock is not free in time. The lock directory and
515
+ * its token directory are empty, so Git never sees them. The card store and `lesson_add`'s AGENTS.md writes use it.
516
+ */
517
+ export async function holdLock(lock, { lockWaitMs = LOCK_WAIT_MS, lockHooks = {} }, work) {
518
+ const token = randomBytes(8).toString("hex")
519
+ if (!(await acquire(lock, token, lockWaitMs, lockHooks))) return { result: "lock_busy" }
520
+ try {
521
+ return await work()
522
+ } finally {
523
+ await lockHooks.beforeRelease?.(lock)
524
+ await fs.rmdir(path.join(lock, token)).catch(() => {})
525
+ await fs.rmdir(lock).catch(() => {})
526
+ }
527
+ }
528
+
529
+ async function writeCard(card, folder, meta) {
530
+ const file = path.join(folder, cardFileName(card.key))
531
+ const temp = path.join(meta, `.improvement-${process.pid}-${randomBytes(4).toString("hex")}.tmp`)
532
+ try {
533
+ await fs.mkdir(folder, { recursive: true })
534
+ await fs.writeFile(temp, serialize(card), { flag: "wx", mode: 0o600 })
535
+ await fs.rename(temp, file)
536
+ } catch (error) {
537
+ await fs.rm(temp, { force: true })
538
+ throw error
539
+ }
540
+ return file
541
+ }
542
+
543
+ const mergeEvidence = (old, added) => [...old, ...added.filter((pointer) => !old.includes(pointer))].slice(-MAX_EVIDENCE)
544
+ const unique = (list) => [...new Set(list)]
545
+
546
+ /**
547
+ * `openImprovement({ deskRoot, personPrefix, key, source, title?, lesson?, evidence, plugin, signal, now, lockWaitMs? })
548
+ * -> { result: "opened" | "duplicate" | "reopened", file } | { result: <refusal code> }`.
549
+ * The library builds the title for every source (`cardTitle`) and a caller-supplied `title` is refused. A friction
550
+ * candidate opened for a lesson (`lesson: { owner, topic }`) is titled from it (`lessonTitle`), or with the fixed words
551
+ * when that title would not pass; `lesson` on any other source is refused as a title. An open card with the key is a `duplicate` (no byte
552
+ * changes); a closed card is `reopened` (recurrences + 1, `last_opened_at` moves, evidence merged, countermeasure, version,
553
+ * `kaizen_url` and check fields cleared). Refusals: `invalid_location`, `invalid_source`, `title_not_allowed`,
554
+ * `invalid_evidence`, `invalid_plugin`, `invalid_signal`, `unreadable_folder`, `too_many_cards` (the card's own file
555
+ * is bad and the folder is too large to have been repaired), `lock_busy`.
556
+ */
557
+ export async function openImprovement({ deskRoot, personPrefix, key, source, title, lesson, evidence, plugin, signal, now, lockWaitMs, lockHooks }) {
558
+ const at = toDate(now).toISOString()
559
+ const refuse = (result) => ({ result })
560
+ if (locationFolder(deskRoot, personPrefix) === null) return refuse("invalid_location")
561
+ const parts = keyParts(key, true)
562
+ if (parts === null || parts.source !== source) return refuse("invalid_source")
563
+ if (title !== undefined || (lesson !== undefined && source !== "friction_candidate")) return refuse("title_not_allowed")
564
+ const named = lesson === undefined ? null : lessonTitle(lesson)
565
+ const fixed = cardTitle(source, parts.id, { plugin, signal })
566
+ const pointers = Array.isArray(evidence) ? unique(evidence) : null
567
+ if (pointers === null || !isEvidence(pointers)) return refuse("invalid_evidence")
568
+ if (!PATCHABLE.plugin[0](plugin)) return refuse("invalid_plugin")
569
+ if (!PATCHABLE.signal[0](signal)) return refuse("invalid_signal")
570
+ return withLock({ deskRoot, personPrefix, lockWaitMs, lockHooks }, async ({ folder, meta }) => {
571
+ const file = path.join(folder, cardFileName(key))
572
+ const found = await inspect(file)
573
+ if (found.kind === "missing") {
574
+ const build = (cardTitleText) => ({
575
+ schema: SCHEMA, key, source, title: cardTitleText, evidence: pointers, opened_at: at, last_opened_at: at, state: "open", claim: null, claim_log: [],
576
+ countermeasure: null, plugin, signal, kaizen_url: null, shipped_version: null, checks_run: 0, last_check_at: null, last_check_result: null, verifying_since: null,
577
+ recurrences: 0, reopened: 0, closed_at: null, close_reason: null,
578
+ })
579
+ // A lesson's card is written only when its exact text reads back as a card; otherwise it takes the fixed words.
580
+ const lessonCard = named === null ? null : build(named)
581
+ const card = lessonCard !== null && readsBack(lessonCard) ? lessonCard : build(fixed)
582
+ return { result: "opened", file: await writeCard(card, folder, meta) }
583
+ }
584
+ if (found.card === undefined) return refuse("too_many_cards")
585
+ if (!found.card.state.startsWith("closed_")) return { result: "duplicate", file }
586
+ const card = {
587
+ ...found.card, state: "open", recurrences: found.card.recurrences + 1, last_opened_at: at, evidence: mergeEvidence(found.card.evidence, pointers),
588
+ countermeasure: null, shipped_version: null, kaizen_url: null, checks_run: 0, last_check_at: null, last_check_result: null, verifying_since: null, closed_at: null, close_reason: null,
589
+ }
590
+ return { result: "reopened", file: await writeCard(card, folder, meta) }
591
+ })
592
+ }
593
+
594
+ /**
595
+ * `machineKey(env) -> Promise<string | null>`: this machine's stable, content-free key: 32 hex characters, a fixed hash
596
+ * of the factory's own machine secret (the one behind the friction fingerprint, kept in the protected factory state).
597
+ * Null when the factory state cannot be read; callers never invent a key. Tests get two machines with two state folders.
598
+ */
599
+ export async function machineKey(env) {
600
+ try {
601
+ return createHash("sha256").update("desk.improvement.machine\n").update(await readMachineSecret(env)).digest("hex").slice(0, 32)
602
+ } catch {
603
+ return null
604
+ }
605
+ }
606
+
607
+
608
+ /**
609
+ * `claimNext({ env, deskRoot, personPrefix, now, session?, lockWaitMs? })
610
+ * -> { result: "claimed", card, claim_id, file } | { result: "claim_held", key } | { result: "none_open" | "too_many_cards" }
611
+ * | { result: "invalid_location" | "machine_key_unavailable" | "invalid_session" | "unreadable_folder" | "lock_busy" }`.
612
+ * The machine key is derived here from `env` by `machineKey(env)` (no caller supplies one); when the factory state cannot give it
613
+ * the answer is `machine_key_unavailable`. Takes the
614
+ * open card with the oldest `last_opened_at` (a claimed card whose claim expired counts as open; a card with another machine's
615
+ * live claim is not offered). One live claim per machine (`MAX_LIVE_CLAIMS`) and a `CLAIM_TTL_HOURS` expiry; there is no daily cap. It reads up to `MAX_CARD_FILES` card files
616
+ * and answers `too_many_cards`, never `none_open` or a claim, when the folder holds more.
617
+ */
618
+ export async function claimNext({ env, deskRoot, personPrefix, now, session, lockWaitMs, lockHooks }) {
619
+ const date = toDate(now)
620
+ const machine = await machineKey(env)
621
+ if (machine === null) return { result: "machine_key_unavailable" }
622
+ if (session !== undefined && session !== null && !PATTERNS.sessionId.test(String(session))) return { result: "invalid_session" }
623
+ return withLock({ deskRoot, personPrefix, lockWaitMs, lockHooks }, async ({ folder, meta, cards, truncated }) => {
624
+ if (truncated) return { result: "too_many_cards" }
625
+ const live = cards.filter((card) => isClaimLive(card, date) && card.claim.machine === machine)
626
+ if (live.length >= MAX_LIVE_CLAIMS) return { result: "claim_held", key: live[0].key }
627
+ const candidates = cards.filter((card) => card.state === "open" || (card.state === "claimed" && !isClaimLive(card, date)))
628
+ .sort((a, b) => a.last_opened_at.localeCompare(b.last_opened_at) || a.key.localeCompare(b.key))
629
+ if (candidates.length === 0) return { result: "none_open" }
630
+ const claim = {
631
+ claim_id: randomUUID(), claimed_at: date.toISOString(), expires_at: new Date(date.getTime() + CLAIM_TTL_HOURS * HOUR_MS).toISOString(), machine, session: session ?? null,
632
+ }
633
+ const card = { ...candidates[0], state: "claimed", claim, claim_log: [...candidates[0].claim_log, { at: claim.claimed_at, machine }].slice(-MAX_CLAIM_LOG) }
634
+ return { result: "claimed", card, claim_id: claim.claim_id, file: await writeCard(card, folder, meta) }
635
+ })
636
+ }
637
+
638
+ // What `updateCard` may do. `claimed` is made only by `claimNext` (it enforces the caps) and a closed
639
+ // card reopens only through `openImprovement` (it counts the recurrence).
640
+ const updateMoves = (from) => MOVES[from].filter((to) => to !== "claimed" && !from.startsWith("closed_"))
641
+
642
+ function checkPatch(patch, old) {
643
+ if (patch === null || typeof patch !== "object" || Array.isArray(patch) || Object.keys(patch).length === 0) return { result: "invalid_patch", field: "patch" }
644
+ for (const field of Object.keys(patch)) {
645
+ if (IMMUTABLE.includes(field)) return { result: "immutable_field", field }
646
+ if (!Object.hasOwn(PATCHABLE, field)) return { result: "unknown_field", field }
647
+ const [check, code = "invalid_patch"] = PATCHABLE[field]
648
+ if (!check(patch[field])) return code === "invalid_patch" ? { result: code, field } : { result: code }
649
+ }
650
+ const state = patch.state ?? old.state
651
+ if (patch.checks_run !== undefined && (patch.checks_run !== old.checks_run + 1 || (state !== "shipped" && state !== "verifying"))) return { result: "invalid_patch", field: "checks_run" }
652
+ return null
653
+ }
654
+
655
+ /**
656
+ * `updateCard({ deskRoot, personPrefix, key, claim_id, patch, now, lockWaitMs? })
657
+ * -> { result: "updated", file, card } | { result: <refusal code>, ... }`.
658
+ * `patch` (not empty) may set `state`, `evidence` (replaces; de-duplicated; at most 10), `countermeasure`, `kaizen_url`, `plugin`,
659
+ * `signal`, `shipped_version`, `checks_run` (only to the old value + 1, and only on a `shipped` or `verifying` card), `last_check_at`, `last_check_result` (from `CHECK_RESULTS`)
660
+ * and `close_reason` (from `CLOSE_REASONS`, only on a closed card). `reopened` and `recurrences` cannot be patched. A card with no live
661
+ * claim accepts system patches without a `claim_id`; a claimed card needs its own `claim_id` while the claim is live and refuses a wrong
662
+ * one always. A move out of `claimed` ends the claim (`expires_at` null); a move to a closed state stamps `closed_at`; a move from
663
+ * `shipped` or `verifying` to `open` adds 1 to `reopened` and clears `countermeasure`, `shipped_version`, `checks_run`, `last_check_at`
664
+ * and `last_check_result`. Refusals: `invalid_location`, `invalid_source`, `unreadable_folder`, `lock_busy`, `not_found`, `too_many_cards`
665
+ * (the card's own file is bad and the folder is too large to have been repaired), `not_your_claim`, `immutable_field` (+ `field`),
666
+ * `unknown_field` (+ `field`), `invalid_countermeasure`, `invalid_kaizen_url`, `invalid_patch` (+ `field`), `invalid_move` (+ `allowed`),
667
+ * `missing_countermeasure`, `missing_version`, `missing_close_reason`.
668
+ */
669
+ export async function updateCard({ deskRoot, personPrefix, key, claim_id: claimId, patch, now, lockWaitMs, lockHooks }) {
670
+ const date = toDate(now)
671
+ if (locationFolder(deskRoot, personPrefix) === null) return { result: "invalid_location" }
672
+ if (keyParts(key) === null) return { result: "invalid_source" }
673
+ return withLock({ deskRoot, personPrefix, lockWaitMs, lockHooks }, async ({ folder, meta }) => {
674
+ const found = await inspect(path.join(folder, cardFileName(key)))
675
+ if (found.kind === "missing") return { result: "not_found" }
676
+ if (found.card === undefined || found.card.key !== key) return { result: "too_many_cards" }
677
+ const old = found.card
678
+ if (claimId !== undefined && (old.state !== "claimed" || claimId !== old.claim.claim_id)) return { result: "not_your_claim" }
679
+ if (old.state === "claimed" && claimId === undefined && isClaimLive(old, date)) return { result: "not_your_claim" }
680
+ const refused = checkPatch(patch, old)
681
+ if (refused !== null) return refused
682
+ const card = { ...old, ...patch }
683
+ if (patch.evidence !== undefined) card.evidence = unique(patch.evidence)
684
+ if (card.state !== old.state) {
685
+ const allowed = updateMoves(old.state)
686
+ if (!allowed.includes(card.state)) return { result: "invalid_move", allowed }
687
+ if (old.state === "claimed") card.claim = { ...old.claim, expires_at: null }
688
+ // A card let go of goes behind every other open card, so the next claim serves another one instead of the same card again.
689
+ if (old.state === "claimed" && card.state === "open") card.last_opened_at = date.toISOString()
690
+ if (card.state.startsWith("closed_")) card.closed_at = date.toISOString()
691
+ if (card.state === "open" && old.state !== "claimed") {
692
+ Object.assign(card, { reopened: old.reopened + 1, countermeasure: null, shipped_version: null, checks_run: 0, last_check_at: null, last_check_result: null, verifying_since: null })
693
+ }
694
+ // The time a card entered verification is the library's to stamp, and its checks start again from zero.
695
+ if (card.state === "verifying" && old.state !== "verifying") Object.assign(card, { verifying_since: date.toISOString(), checks_run: 0 })
696
+ }
697
+ if ((card.state === "shipped" || card.state === "verifying") && card.countermeasure === null) return { result: "missing_countermeasure" }
698
+ if (card.state === "verifying" && card.shipped_version === null) return { result: "missing_version" }
699
+ const closed = card.state.startsWith("closed_")
700
+ if (closed && card.close_reason === null) return { result: "missing_close_reason" }
701
+ if (!closed && card.close_reason !== null) return { result: "invalid_patch", field: "close_reason" }
702
+ return { result: "updated", file: await writeCard(card, folder, meta), card }
703
+ })
704
+ }