@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.
- package/README.md +1 -1
- package/changelog.json +6 -2
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/desk.lock.json +8 -0
- package/dist/heart/identity.js +27 -1
- package/dist/mind/desk-section.js +33 -43
- package/dist/repertoire/desk-mcp.js +140 -0
- package/dist/repertoire/mcp-manager.js +22 -0
- package/dist/repertoire/mcp-tools.js +11 -7
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -1
- package/vendor/desk/.claude-plugin/plugin.json +35 -0
- package/vendor/desk/.mcp.claude-codex.json +28 -0
- package/vendor/desk/.mcp.copilot.json +16 -0
- package/vendor/desk/.ouro-desk.json +6 -0
- package/vendor/desk/CHANGELOG.md +7004 -0
- package/vendor/desk/README.md +195 -0
- package/vendor/desk/activation/README.md +98 -0
- package/vendor/desk/activation/copilot-root.flattened-bundle.json +38 -0
- package/vendor/desk/activation/desk.activation.json +251 -0
- package/vendor/desk/activation/host-capability-evidence.md +46 -0
- package/vendor/desk/activation/support-matrix.json +84 -0
- package/vendor/desk/agency.json +20 -0
- package/vendor/desk/agents/observer.agent.md +26 -0
- package/vendor/desk/agents/observer.md +29 -0
- package/vendor/desk/agents/worker.agent.md +32 -0
- package/vendor/desk/agents/worker.md +40 -0
- package/vendor/desk/artifacts/tombstones/tombstone.schema.json +53 -0
- package/vendor/desk/artifacts/tombstones/tombstones.jsonl +1 -0
- package/vendor/desk/changelog.d/README.md +12 -0
- package/vendor/desk/docs/agent-files.md +104 -0
- package/vendor/desk/docs/agentic-engineering-v2-rfc.md +206 -0
- package/vendor/desk/docs/agentic-engineering-v3-rfc.md +109 -0
- package/vendor/desk/docs/browser-remote-desktops.md +69 -0
- package/vendor/desk/docs/dependency-activation-stories-and-criteria.md +500 -0
- package/vendor/desk/docs/evaluation-packet.md +363 -0
- package/vendor/desk/docs/factory-local-capture.md +651 -0
- package/vendor/desk/docs/factory-store-playbook.md +927 -0
- package/vendor/desk/docs/images/factory-site.png +0 -0
- package/vendor/desk/docs/issue-drains.md +79 -0
- package/vendor/desk/docs/lfs-inspection.md +55 -0
- package/vendor/desk/docs/preview-diagnostics.md +11 -0
- package/vendor/desk/docs/relays.md +88 -0
- package/vendor/desk/docs/schedules.md +69 -0
- package/vendor/desk/docs/search-recovery.md +22 -0
- package/vendor/desk/docs/session-labels.md +157 -0
- package/vendor/desk/docs/session-retention.md +125 -0
- package/vendor/desk/docs/sessions.md +17 -0
- package/vendor/desk/docs/stalled-nudges.md +54 -0
- package/vendor/desk/docs/webhooks.md +80 -0
- package/vendor/desk/docs/workspace-tidy.md +74 -0
- package/vendor/desk/hooks/boot-checks.cjs +7 -0
- package/vendor/desk/hooks/claude-session-start.cjs +123 -0
- package/vendor/desk/hooks/compatible-node.cjs +97 -0
- package/vendor/desk/hooks/copilot-boot-prompt.cjs +69 -0
- package/vendor/desk/hooks/copilot-durable-files.cjs +8 -0
- package/vendor/desk/hooks/copilot-hooks.json +61 -0
- package/vendor/desk/hooks/copilot-intake-context.cjs +5 -0
- package/vendor/desk/hooks/copilot-lane-model.cjs +8 -0
- package/vendor/desk/hooks/copilot-session-start.cjs +264 -0
- package/vendor/desk/hooks/copilot-skill-current.cjs +28 -0
- package/vendor/desk/hooks/factory-end.cjs +5 -0
- package/vendor/desk/hooks/factory-start.cjs +27 -0
- package/vendor/desk/hooks/hooks.json +40 -0
- package/vendor/desk/hooks/lib/boot-checks.cjs +643 -0
- package/vendor/desk/hooks/lib/child-agent.cjs +14 -0
- package/vendor/desk/hooks/lib/copilot-intake-context.cjs +73 -0
- package/vendor/desk/hooks/lib/current-release.cjs +162 -0
- package/vendor/desk/hooks/lib/delivery-stop.cjs +326 -0
- package/vendor/desk/hooks/lib/detach-worker.cjs +43 -0
- package/vendor/desk/hooks/lib/durable-files.cjs +102 -0
- package/vendor/desk/hooks/lib/factory-end.cjs +327 -0
- package/vendor/desk/hooks/lib/lane-model.cjs +82 -0
- package/vendor/desk/hooks/lib/node-required.cjs +56 -0
- package/vendor/desk/hooks/lib/orca-session-title.cjs +60 -0
- package/vendor/desk/hooks/lib/session-end.cjs +30 -0
- package/vendor/desk/hooks/lib/sync-end.cjs +89 -0
- package/vendor/desk/hooks/loop-start.cjs +105 -0
- package/vendor/desk/hooks/node-missing.sh +78 -0
- package/vendor/desk/hooks/orca-session-title.cjs +8 -0
- package/vendor/desk/hooks/session-end.cjs +8 -0
- package/vendor/desk/mcp/README.md +269 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/support-matrix.json +72 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/README.md +25 -0
- package/vendor/desk/mcp/bootstrap.cjs +761 -0
- package/vendor/desk/mcp/docs/private-feedback.md +13 -0
- package/vendor/desk/mcp/idle-proxy.cjs +423 -0
- package/vendor/desk/mcp/index.js +813 -0
- package/vendor/desk/mcp/package-lock.json +3717 -0
- package/vendor/desk/mcp/package.json +44 -0
- package/vendor/desk/mcp/scripts/agency-desk-channel.js +7 -0
- package/vendor/desk/mcp/scripts/build-runtime-deps-pack.js +5 -0
- package/vendor/desk/mcp/scripts/crew.js +89 -0
- package/vendor/desk/mcp/scripts/drains-launcher.mjs +329 -0
- package/vendor/desk/mcp/scripts/drains.js +5 -0
- package/vendor/desk/mcp/scripts/factory.js +657 -0
- package/vendor/desk/mcp/scripts/file-desk-problem.js +9 -0
- package/vendor/desk/mcp/scripts/finish-commit.js +7 -0
- package/vendor/desk/mcp/scripts/lfs.js +37 -0
- package/vendor/desk/mcp/scripts/local-recovery.js +363 -0
- package/vendor/desk/mcp/scripts/migrations.js +11 -0
- package/vendor/desk/mcp/scripts/private-view.js +177 -0
- package/vendor/desk/mcp/scripts/resolve-desk-root.js +106 -0
- package/vendor/desk/mcp/scripts/session-boot.js +22 -0
- package/vendor/desk/mcp/scripts/session-retention.js +5 -0
- package/vendor/desk/mcp/scripts/session-sync.js +10 -0
- package/vendor/desk/mcp/scripts/sessions.js +5 -0
- package/vendor/desk/mcp/scripts/sync-push.js +13 -0
- package/vendor/desk/mcp/scripts/tidy-status.js +8 -0
- package/vendor/desk/mcp/scripts/verify-runtime-deps-pack.js +5 -0
- package/vendor/desk/mcp/src/actions/desk-read.actions.mts +73 -0
- package/vendor/desk/mcp/src/actions/desk-session.actions.mts +42 -0
- package/vendor/desk/mcp/src/actions/desk-web.actions.mts +52 -0
- package/vendor/desk/mcp/src/actions/desk.actions.mts +5 -0
- package/vendor/desk/mcp/src/actions/generated/desk/OuroActions.swift +649 -0
- package/vendor/desk/mcp/src/actions/generated/desk/OuroActionsReins.swift +61 -0
- package/vendor/desk/mcp/src/actions/generated/desk/actions.json +280 -0
- package/vendor/desk/mcp/src/actions/generated/desk/commands.json +145 -0
- package/vendor/desk/mcp/src/actions/generated/desk/mcp.json +256 -0
- package/vendor/desk/mcp/src/actions/generated/desk/web.ts +59 -0
- package/vendor/desk/mcp/src/actions/generated/desk/webmcp.json +250 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/OuroActions.swift +241 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/OuroActionsReins.swift +25 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/actions.json +73 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/commands.json +53 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/mcp.json +83 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/web.ts +47 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/webmcp.json +81 -0
- package/vendor/desk/mcp/src/actions/served.js +5 -0
- package/vendor/desk/mcp/src/activation/admit.js +77 -0
- package/vendor/desk/mcp/src/activation/failures.js +65 -0
- package/vendor/desk/mcp/src/activation/readiness-policy.js +102 -0
- package/vendor/desk/mcp/src/activation/schema.js +17 -0
- package/vendor/desk/mcp/src/activation/superpowers-context.js +265 -0
- package/vendor/desk/mcp/src/activation/validate.js +540 -0
- package/vendor/desk/mcp/src/artifacts/tombstones.js +61 -0
- package/vendor/desk/mcp/src/crew/initiative.js +287 -0
- package/vendor/desk/mcp/src/crew/workspace.js +1259 -0
- package/vendor/desk/mcp/src/db/init.js +75 -0
- package/vendor/desk/mcp/src/db/schema.sql +83 -0
- package/vendor/desk/mcp/src/desk/active-tasks.js +408 -0
- package/vendor/desk/mcp/src/desk/card-commit-guard.js +281 -0
- package/vendor/desk/mcp/src/desk/cleanup-index.js +53 -0
- package/vendor/desk/mcp/src/desk/content-home.js +246 -0
- package/vendor/desk/mcp/src/desk/crew-config.js +102 -0
- package/vendor/desk/mcp/src/desk/crew-member.js +196 -0
- package/vendor/desk/mcp/src/desk/crew-roster.js +151 -0
- package/vendor/desk/mcp/src/desk/frontmatter-lite.js +228 -0
- package/vendor/desk/mcp/src/desk/gh-logins.js +109 -0
- package/vendor/desk/mcp/src/desk/handles.js +123 -0
- package/vendor/desk/mcp/src/desk/handoff-reference.js +35 -0
- package/vendor/desk/mcp/src/desk/improvement-authority.js +3 -0
- package/vendor/desk/mcp/src/desk/improvement-cards.js +704 -0
- package/vendor/desk/mcp/src/desk/improvement-person.js +51 -0
- package/vendor/desk/mcp/src/desk/lifecycle.js +16 -0
- package/vendor/desk/mcp/src/desk/machine-desks.js +119 -0
- package/vendor/desk/mcp/src/desk/naming.js +333 -0
- package/vendor/desk/mcp/src/desk/organization.js +592 -0
- package/vendor/desk/mcp/src/desk/resources.js +274 -0
- package/vendor/desk/mcp/src/desk/runtime-resolver.js +30 -0
- package/vendor/desk/mcp/src/desk/scratch-paths.js +44 -0
- package/vendor/desk/mcp/src/desk/step-delivery.js +140 -0
- package/vendor/desk/mcp/src/desk/steps.js +263 -0
- package/vendor/desk/mcp/src/desk/tidy.js +930 -0
- package/vendor/desk/mcp/src/desk/unsigned-deliveries.js +359 -0
- package/vendor/desk/mcp/src/factory/agent-types.js +45 -0
- package/vendor/desk/mcp/src/factory/andon-watch.js +109 -0
- package/vendor/desk/mcp/src/factory/binding.js +612 -0
- package/vendor/desk/mcp/src/factory/boot-check.js +645 -0
- package/vendor/desk/mcp/src/factory/capture-classify.js +158 -0
- package/vendor/desk/mcp/src/factory/capture-count.js +183 -0
- package/vendor/desk/mcp/src/factory/capture-flush.js +268 -0
- package/vendor/desk/mcp/src/factory/capture-publish.js +141 -0
- package/vendor/desk/mcp/src/factory/capture-schema.js +193 -0
- package/vendor/desk/mcp/src/factory/capture-sweep.js +239 -0
- package/vendor/desk/mcp/src/factory/catch-point.js +60 -0
- package/vendor/desk/mcp/src/factory/commit-resolve.js +94 -0
- package/vendor/desk/mcp/src/factory/consent-answer.js +37 -0
- package/vendor/desk/mcp/src/factory/context-capability.js +15 -0
- package/vendor/desk/mcp/src/factory/context-outbox.js +885 -0
- package/vendor/desk/mcp/src/factory/context-run.js +386 -0
- package/vendor/desk/mcp/src/factory/context-schema.js +249 -0
- package/vendor/desk/mcp/src/factory/copilot-turn-index.js +93 -0
- package/vendor/desk/mcp/src/factory/copilot-usage.js +148 -0
- package/vendor/desk/mcp/src/factory/credential.js +45 -0
- package/vendor/desk/mcp/src/factory/derive-claude.js +960 -0
- package/vendor/desk/mcp/src/factory/derive-codex.js +734 -0
- package/vendor/desk/mcp/src/factory/derive-common.js +279 -0
- package/vendor/desk/mcp/src/factory/derive-copilot.js +1057 -0
- package/vendor/desk/mcp/src/factory/derive-run.js +807 -0
- package/vendor/desk/mcp/src/factory/desk-problem-file.js +310 -0
- package/vendor/desk/mcp/src/factory/desk-problem-fingerprint.js +70 -0
- package/vendor/desk/mcp/src/factory/desk-problem-known.js +246 -0
- package/vendor/desk/mcp/src/factory/desk-problem-template.js +107 -0
- package/vendor/desk/mcp/src/factory/desk-repo.js +1223 -0
- package/vendor/desk/mcp/src/factory/desk-task-line.js +28 -0
- package/vendor/desk/mcp/src/factory/desk-visibility.js +48 -0
- package/vendor/desk/mcp/src/factory/end-hook.js +14 -0
- package/vendor/desk/mcp/src/factory/evaluate-kick.js +164 -0
- package/vendor/desk/mcp/src/factory/evaluate-run.js +678 -0
- package/vendor/desk/mcp/src/factory/evaluator-step.js +484 -0
- package/vendor/desk/mcp/src/factory/filer-launch.js +79 -0
- package/vendor/desk/mcp/src/factory/flush-health.js +26 -0
- package/vendor/desk/mcp/src/factory/flush.js +1758 -0
- package/vendor/desk/mcp/src/factory/focus.js +326 -0
- package/vendor/desk/mcp/src/factory/headless-flag.cjs +32 -0
- package/vendor/desk/mcp/src/factory/headless-flag.js +25 -0
- package/vendor/desk/mcp/src/factory/headless-ledger.js +743 -0
- package/vendor/desk/mcp/src/factory/headless.js +567 -0
- package/vendor/desk/mcp/src/factory/held-route.js +93 -0
- package/vendor/desk/mcp/src/factory/host-flags.js +36 -0
- package/vendor/desk/mcp/src/factory/improvement-verify.js +429 -0
- package/vendor/desk/mcp/src/factory/kaizen-file.js +231 -0
- package/vendor/desk/mcp/src/factory/label-binding.js +90 -0
- package/vendor/desk/mcp/src/factory/label-schema.js +426 -0
- package/vendor/desk/mcp/src/factory/local-status.js +368 -0
- package/vendor/desk/mcp/src/factory/loop-conditions.js +121 -0
- package/vendor/desk/mcp/src/factory/loop-health.js +500 -0
- package/vendor/desk/mcp/src/factory/loop-slot.js +90 -0
- package/vendor/desk/mcp/src/factory/loop-status.js +100 -0
- package/vendor/desk/mcp/src/factory/loop-switch.cjs +14 -0
- package/vendor/desk/mcp/src/factory/loop-worker-state.js +96 -0
- package/vendor/desk/mcp/src/factory/loop-worker.js +290 -0
- package/vendor/desk/mcp/src/factory/marker.js +61 -0
- package/vendor/desk/mcp/src/factory/mirror-step.js +145 -0
- package/vendor/desk/mcp/src/factory/os-protect.js +243 -0
- package/vendor/desk/mcp/src/factory/outbox.js +2231 -0
- package/vendor/desk/mcp/src/factory/outcome.js +431 -0
- package/vendor/desk/mcp/src/factory/pipeline/andon.js +319 -0
- package/vendor/desk/mcp/src/factory/pipeline/attention-rollup.js +158 -0
- package/vendor/desk/mcp/src/factory/pipeline/attention.js +146 -0
- package/vendor/desk/mcp/src/factory/pipeline/build.js +299 -0
- package/vendor/desk/mcp/src/factory/pipeline/compare.js +148 -0
- package/vendor/desk/mcp/src/factory/pipeline/formulas.js +652 -0
- package/vendor/desk/mcp/src/factory/pipeline/kaizen.js +387 -0
- package/vendor/desk/mcp/src/factory/pipeline/lifecycle-clocks.js +345 -0
- package/vendor/desk/mcp/src/factory/pipeline/normalize.js +73 -0
- package/vendor/desk/mcp/src/factory/pipeline/number-states.js +154 -0
- package/vendor/desk/mcp/src/factory/pipeline/outcomes.js +268 -0
- package/vendor/desk/mcp/src/factory/pipeline/report.js +737 -0
- package/vendor/desk/mcp/src/factory/pipeline/rollups.js +883 -0
- package/vendor/desk/mcp/src/factory/pipeline/stretches.js +523 -0
- package/vendor/desk/mcp/src/factory/pipeline/timeline.js +199 -0
- package/vendor/desk/mcp/src/factory/pipeline/validate-pr.js +238 -0
- package/vendor/desk/mcp/src/factory/pipeline/versions.js +42 -0
- package/vendor/desk/mcp/src/factory/pipeline/walk.js +1177 -0
- package/vendor/desk/mcp/src/factory/plugin-registry.js +72 -0
- package/vendor/desk/mcp/src/factory/plugin-sources.cjs +249 -0
- package/vendor/desk/mcp/src/factory/pr-green.js +77 -0
- package/vendor/desk/mcp/src/factory/process-lock.js +142 -0
- package/vendor/desk/mcp/src/factory/proof-session.js +75 -0
- package/vendor/desk/mcp/src/factory/publish.js +637 -0
- package/vendor/desk/mcp/src/factory/published-schema.js +648 -0
- package/vendor/desk/mcp/src/factory/reconcile-reasons.js +22 -0
- package/vendor/desk/mcp/src/factory/reconcile-step.js +251 -0
- package/vendor/desk/mcp/src/factory/reconcile.js +808 -0
- package/vendor/desk/mcp/src/factory/release-version.js +134 -0
- package/vendor/desk/mcp/src/factory/repo-name.js +13 -0
- package/vendor/desk/mcp/src/factory/retention.js +60 -0
- package/vendor/desk/mcp/src/factory/route-desk.js +40 -0
- package/vendor/desk/mcp/src/factory/route-issues.js +251 -0
- package/vendor/desk/mcp/src/factory/route-local.js +264 -0
- package/vendor/desk/mcp/src/factory/schema.js +957 -0
- package/vendor/desk/mcp/src/factory/session-kind.js +16 -0
- package/vendor/desk/mcp/src/factory/session-lifetime.js +56 -0
- package/vendor/desk/mcp/src/factory/session-route.js +183 -0
- package/vendor/desk/mcp/src/factory/shell-git.js +500 -0
- package/vendor/desk/mcp/src/factory/store-issues.js +143 -0
- package/vendor/desk/mcp/src/factory/store-route.js +208 -0
- package/vendor/desk/mcp/src/factory/test-state-guard.js +103 -0
- package/vendor/desk/mcp/src/factory/time.js +36 -0
- package/vendor/desk/mcp/src/factory/tool-issue-file.js +84 -0
- package/vendor/desk/mcp/src/factory/tool-kinds.js +87 -0
- package/vendor/desk/mcp/src/factory/triage-schema.js +233 -0
- package/vendor/desk/mcp/src/factory/windows-acl.js +679 -0
- package/vendor/desk/mcp/src/indexer/chunk.js +232 -0
- package/vendor/desk/mcp/src/indexer/discover.js +434 -0
- package/vendor/desk/mcp/src/indexer/exclusions.js +247 -0
- package/vendor/desk/mcp/src/indexer/index.js +167 -0
- package/vendor/desk/mcp/src/indexer/refs.js +0 -0
- package/vendor/desk/mcp/src/indexer/text-hash.js +18 -0
- package/vendor/desk/mcp/src/lib/ouro-actions/actions.claims.json +75 -0
- package/vendor/desk/mcp/src/lib/ouro-actions/dist-manifest.json +70 -0
- package/vendor/desk/mcp/src/lib/ouro-actions/ouro-actions.mts +1416 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/LICENSE +21 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/ax-claims.ts +190 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/ax-command.ts +1020 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/checks.ts +343 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/cli.ts +240 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/component.ts +430 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/dev-commands.ts +204 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/doctor.ts +126 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/effects.ts +68 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/exit-codes.ts +75 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/help.ts +220 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/mcp.ts +268 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/outcome.ts +265 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/output.ts +67 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/precise-copy.ts +235 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/problem.ts +124 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/surfaces.kit.mts +8 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/surfaces.ts +568 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/terminal.ts +245 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/voice.ts +136 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/wait.ts +226 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/work-event.ts +181 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/xray.kit.mts +18 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/xray.ts +2072 -0
- package/vendor/desk/mcp/src/package-metadata.js +20 -0
- package/vendor/desk/mcp/src/protected/legacy-ledger.js +55 -0
- package/vendor/desk/mcp/src/readiness/leftovers.js +75 -0
- package/vendor/desk/mcp/src/readiness/process-start.js +149 -0
- package/vendor/desk/mcp/src/runtime/admission-worker.js +194 -0
- package/vendor/desk/mcp/src/runtime/admission.js +177 -0
- package/vendor/desk/mcp/src/runtime/agency-desk-channel.js +342 -0
- package/vendor/desk/mcp/src/runtime/agents-md.js +62 -0
- package/vendor/desk/mcp/src/runtime/append-lane.js +68 -0
- package/vendor/desk/mcp/src/runtime/argv-safe-reason.js +55 -0
- package/vendor/desk/mcp/src/runtime/boot-dependencies.js +75 -0
- package/vendor/desk/mcp/src/runtime/boot-text.js +504 -0
- package/vendor/desk/mcp/src/runtime/boot.js +1677 -0
- package/vendor/desk/mcp/src/runtime/bootstrap.js +1455 -0
- package/vendor/desk/mcp/src/runtime/chunked-import.js +102 -0
- package/vendor/desk/mcp/src/runtime/copilot-commit-trailer.js +133 -0
- package/vendor/desk/mcp/src/runtime/copilot-session.js +155 -0
- package/vendor/desk/mcp/src/runtime/deliver.js +469 -0
- package/vendor/desk/mcp/src/runtime/desk-channel.js +86 -0
- package/vendor/desk/mcp/src/runtime/desk-failure.js +26 -0
- package/vendor/desk/mcp/src/runtime/desk-health.js +168 -0
- package/vendor/desk/mcp/src/runtime/desk-session.js +1451 -0
- package/vendor/desk/mcp/src/runtime/diagnostic-server.js +72 -0
- package/vendor/desk/mcp/src/runtime/diagnostics.js +241 -0
- package/vendor/desk/mcp/src/runtime/drains-cli.js +187 -0
- package/vendor/desk/mcp/src/runtime/drains.js +781 -0
- package/vendor/desk/mcp/src/runtime/elsewhere-note.js +9 -0
- package/vendor/desk/mcp/src/runtime/failure-evidence.js +21 -0
- package/vendor/desk/mcp/src/runtime/fast-refs.js +209 -0
- package/vendor/desk/mcp/src/runtime/filer-throttle.js +66 -0
- package/vendor/desk/mcp/src/runtime/focused-card.js +147 -0
- package/vendor/desk/mcp/src/runtime/front-door.js +204 -0
- package/vendor/desk/mcp/src/runtime/gate-wait.js +2 -0
- package/vendor/desk/mcp/src/runtime/git-inspection.js +201 -0
- package/vendor/desk/mcp/src/runtime/git-read-worker.js +157 -0
- package/vendor/desk/mcp/src/runtime/health.js +50 -0
- package/vendor/desk/mcp/src/runtime/hooks.js +353 -0
- package/vendor/desk/mcp/src/runtime/hosted.js +163 -0
- package/vendor/desk/mcp/src/runtime/inbox.js +102 -0
- package/vendor/desk/mcp/src/runtime/index-drift.js +118 -0
- package/vendor/desk/mcp/src/runtime/last-start.js +133 -0
- package/vendor/desk/mcp/src/runtime/lesson-section.js +92 -0
- package/vendor/desk/mcp/src/runtime/lessons-shelf.js +100 -0
- package/vendor/desk/mcp/src/runtime/lfs.js +319 -0
- package/vendor/desk/mcp/src/runtime/native-path.js +12 -0
- package/vendor/desk/mcp/src/runtime/newest-release.js +197 -0
- package/vendor/desk/mcp/src/runtime/node-selection.js +233 -0
- package/vendor/desk/mcp/src/runtime/orca-session-title.js +225 -0
- package/vendor/desk/mcp/src/runtime/other-sessions.js +183 -0
- package/vendor/desk/mcp/src/runtime/pending-migrations.js +653 -0
- package/vendor/desk/mcp/src/runtime/plugin-update.js +215 -0
- package/vendor/desk/mcp/src/runtime/pluginless-runtimes.js +34 -0
- package/vendor/desk/mcp/src/runtime/pr-publication.js +226 -0
- package/vendor/desk/mcp/src/runtime/preview-snapshot.js +23 -0
- package/vendor/desk/mcp/src/runtime/publication-mode.js +19 -0
- package/vendor/desk/mcp/src/runtime/relays.js +974 -0
- package/vendor/desk/mcp/src/runtime/release-alert.js +148 -0
- package/vendor/desk/mcp/src/runtime/remote-identity.js +140 -0
- package/vendor/desk/mcp/src/runtime/resolve-here.js +4 -0
- package/vendor/desk/mcp/src/runtime/runtime-deps-cli.js +65 -0
- package/vendor/desk/mcp/src/runtime/runtime-deps.js +1109 -0
- package/vendor/desk/mcp/src/runtime/runtime-identity.js +22 -0
- package/vendor/desk/mcp/src/runtime/runtime-swap.js +101 -0
- package/vendor/desk/mcp/src/runtime/schedules.js +235 -0
- package/vendor/desk/mcp/src/runtime/session-activity.js +190 -0
- package/vendor/desk/mcp/src/runtime/session-label.js +30 -0
- package/vendor/desk/mcp/src/runtime/session-retention.js +662 -0
- package/vendor/desk/mcp/src/runtime/session-sync.js +333 -0
- package/vendor/desk/mcp/src/runtime/session-trailer.js +126 -0
- package/vendor/desk/mcp/src/runtime/sessions-cli.js +301 -0
- package/vendor/desk/mcp/src/runtime/signoff-listed.js +81 -0
- package/vendor/desk/mcp/src/runtime/skills.js +76 -0
- package/vendor/desk/mcp/src/runtime/stale-card-lead.js +52 -0
- package/vendor/desk/mcp/src/runtime/stale-desk-refresh.js +198 -0
- package/vendor/desk/mcp/src/runtime/stale-desk.js +219 -0
- package/vendor/desk/mcp/src/runtime/stalled.js +255 -0
- package/vendor/desk/mcp/src/runtime/standing-authority.js +79 -0
- package/vendor/desk/mcp/src/runtime/startup-boot.js +341 -0
- package/vendor/desk/mcp/src/runtime/startup-resolve.js +140 -0
- package/vendor/desk/mcp/src/runtime/state-branch.js +203 -0
- package/vendor/desk/mcp/src/runtime/status-compact.js +165 -0
- package/vendor/desk/mcp/src/runtime/status-inspection-child.js +26 -0
- package/vendor/desk/mcp/src/runtime/status-inspection.js +147 -0
- package/vendor/desk/mcp/src/runtime/status-root.js +39 -0
- package/vendor/desk/mcp/src/runtime/sync-worker.js +911 -0
- package/vendor/desk/mcp/src/runtime/test-state-guard.js +107 -0
- package/vendor/desk/mcp/src/runtime/unmerged-saves.js +247 -0
- package/vendor/desk/mcp/src/runtime/workspace-claim.js +53 -0
- package/vendor/desk/mcp/src/runtime/workspace-evidence.js +96 -0
- package/vendor/desk/mcp/src/runtime/workspace-tidy.js +509 -0
- package/vendor/desk/mcp/src/search/direct-lexical.js +54 -0
- package/vendor/desk/mcp/src/search/embedder.js +108 -0
- package/vendor/desk/mcp/src/search/engine.js +406 -0
- package/vendor/desk/mcp/src/search/files-router.js +22 -0
- package/vendor/desk/mcp/src/search/old-index.js +46 -0
- package/vendor/desk/mcp/src/search/vectors.js +60 -0
- package/vendor/desk/mcp/src/server.js +389 -0
- package/vendor/desk/mcp/src/tool-names.js +73 -0
- package/vendor/desk/mcp/src/tool-refusal.cjs +35 -0
- package/vendor/desk/mcp/src/tool-schema-parts.js +12 -0
- package/vendor/desk/mcp/src/tool-schemas.js +325 -0
- package/vendor/desk/mcp/src/tools/_card-commit.js +148 -0
- package/vendor/desk/mcp/src/tools/archive-links.js +185 -0
- package/vendor/desk/mcp/src/tools/archive-move.js +18 -0
- package/vendor/desk/mcp/src/tools/archive-native-session.js +728 -0
- package/vendor/desk/mcp/src/tools/archive-state.js +513 -0
- package/vendor/desk/mcp/src/tools/delivery-gate.js +251 -0
- package/vendor/desk/mcp/src/tools/desk-save.js +444 -0
- package/vendor/desk/mcp/src/tools/doctor.js +122 -0
- package/vendor/desk/mcp/src/tools/done-evidence.js +260 -0
- package/vendor/desk/mcp/src/tools/factory-context.js +204 -0
- package/vendor/desk/mcp/src/tools/friction.js +332 -0
- package/vendor/desk/mcp/src/tools/improvement.js +156 -0
- package/vendor/desk/mcp/src/tools/lesson-lines.js +22 -0
- package/vendor/desk/mcp/src/tools/lesson-owners.js +137 -0
- package/vendor/desk/mcp/src/tools/lesson-team.js +169 -0
- package/vendor/desk/mcp/src/tools/lesson.js +254 -0
- package/vendor/desk/mcp/src/tools/local-only.js +151 -0
- package/vendor/desk/mcp/src/tools/move.js +794 -0
- package/vendor/desk/mcp/src/tools/native-stage-context.js +32 -0
- package/vendor/desk/mcp/src/tools/note.js +267 -0
- package/vendor/desk/mcp/src/tools/search.js +634 -0
- package/vendor/desk/mcp/src/tools/shared-write.js +196 -0
- package/vendor/desk/mcp/src/tools/sibling-desk.js +37 -0
- package/vendor/desk/mcp/src/tools/status.js +233 -0
- package/vendor/desk/mcp/src/tools/task-archive-due.js +9 -0
- package/vendor/desk/mcp/src/tools/task-archived-resource.js +53 -0
- package/vendor/desk/mcp/src/tools/task-body.js +141 -0
- package/vendor/desk/mcp/src/tools/task-focus.js +164 -0
- package/vendor/desk/mcp/src/tools/task-log.js +76 -0
- package/vendor/desk/mcp/src/tools/task-signoff.js +155 -0
- package/vendor/desk/mcp/src/tools/task.js +1768 -0
- package/vendor/desk/mcp/src/tools/track-row.js +89 -0
- package/vendor/desk/mcp/src/tools/track.js +240 -0
- package/vendor/desk/mcp/src/util/agency-session.cjs +29 -0
- package/vendor/desk/mcp/src/util/archive-links.js +105 -0
- package/vendor/desk/mcp/src/util/bash.js +36 -0
- package/vendor/desk/mcp/src/util/capture-record.js +73 -0
- package/vendor/desk/mcp/src/util/cas-commit.js +252 -0
- package/vendor/desk/mcp/src/util/created-dirs.js +71 -0
- package/vendor/desk/mcp/src/util/deferred-tools.js +51 -0
- package/vendor/desk/mcp/src/util/desk-owner.js +99 -0
- package/vendor/desk/mcp/src/util/env-value.js +13 -0
- package/vendor/desk/mcp/src/util/file-identity.js +40 -0
- package/vendor/desk/mcp/src/util/finish-commit.js +145 -0
- package/vendor/desk/mcp/src/util/fm.js +410 -0
- package/vendor/desk/mcp/src/util/git-config-file.js +85 -0
- package/vendor/desk/mcp/src/util/git-stage.js +440 -0
- package/vendor/desk/mcp/src/util/main-publish.js +240 -0
- package/vendor/desk/mcp/src/util/markdown-links.cjs +555 -0
- package/vendor/desk/mcp/src/util/object-input.js +59 -0
- package/vendor/desk/mcp/src/util/paths.js +647 -0
- package/vendor/desk/mcp/src/util/rank.js +189 -0
- package/vendor/desk/mcp/src/util/redact.js +92 -0
- package/vendor/desk/mcp/src/util/remove-retry.js +35 -0
- package/vendor/desk/mcp/src/util/rename-retry.js +73 -0
- package/vendor/desk/mcp/src/util/route-around.js +265 -0
- package/vendor/desk/mcp/src/util/shell-quote.js +18 -0
- package/vendor/desk/mcp/src/util/startup-direction.js +124 -0
- package/vendor/desk/mcp/src/util/state-ignore.js +33 -0
- package/vendor/desk/mcp/src/util/tool-commits.js +64 -0
- package/vendor/desk/mcp/src/util/unicode-16/LICENSE-MIT.txt +7 -0
- package/vendor/desk/mcp/src/util/unicode-16/README.md +9 -0
- package/vendor/desk/mcp/src/util/unicode-16/letter.cjs +1 -0
- package/vendor/desk/mcp/src/util/unicode-16/mark.cjs +1 -0
- package/vendor/desk/mcp/src/util/unicode-16/number.cjs +1 -0
- package/vendor/desk/mcp/web-auth.cjs +1897 -0
- package/vendor/desk/mcp/web-browser-discovery.cjs +53 -0
- package/vendor/desk/mcp/web-catalog.json +34 -0
- package/vendor/desk/mcp/web-launch.cjs +101 -0
- package/vendor/desk/mcp/web.cjs +1239 -0
- package/vendor/desk/migrations/01-move-to-ourostack-desk.md +188 -0
- package/vendor/desk/migrations/02-tidy-desk.md +87 -0
- package/vendor/desk/migrations/03-desk-release-channel.md +38 -0
- package/vendor/desk/optional/session-label/consumer.mjs +237 -0
- package/vendor/desk/optional/session-label/extension.mjs +32 -0
- package/vendor/desk/plugin.json +54 -0
- package/vendor/desk/settings.json +3 -0
- package/vendor/desk/skills/add-workspace-mcp/SKILL.md +180 -0
- package/vendor/desk/skills/adopt-inflight-work/SKILL.md +212 -0
- package/vendor/desk/skills/archive-workflow/SKILL.md +132 -0
- package/vendor/desk/skills/content-routing/SKILL.md +95 -0
- package/vendor/desk/skills/core-meeting-capture/SKILL.md +47 -0
- package/vendor/desk/skills/core-meeting-capture/references/capture-contract.md +175 -0
- package/vendor/desk/skills/curator/SKILL.md +103 -0
- package/vendor/desk/skills/delightful-decks/SKILL.md +67 -0
- package/vendor/desk/skills/desk-problem/SKILL.md +87 -0
- package/vendor/desk/skills/directory-structure/SKILL.md +169 -0
- package/vendor/desk/skills/doc-review-rigor/SKILL.md +63 -0
- package/vendor/desk/skills/draining-issues/SKILL.md +62 -0
- package/vendor/desk/skills/evaluate-release/SKILL.md +96 -0
- package/vendor/desk/skills/evidence-discipline/SKILL.md +150 -0
- package/vendor/desk/skills/factory-evaluator/SKILL.md +122 -0
- package/vendor/desk/skills/factory-task-context/SKILL.md +116 -0
- package/vendor/desk/skills/factory-work/SKILL.md +16 -0
- package/vendor/desk/skills/fast-honest-ci/SKILL.md +70 -0
- package/vendor/desk/skills/fast-honest-ci/examples.md +49 -0
- package/vendor/desk/skills/first-run-bootstrap/SKILL.md +95 -0
- package/vendor/desk/skills/friction-management/SKILL.md +98 -0
- package/vendor/desk/skills/git-hygiene/SKILL.md +253 -0
- package/vendor/desk/skills/independent-review/SKILL.md +34 -0
- package/vendor/desk/skills/interaction-style/SKILL.md +239 -0
- package/vendor/desk/skills/lesson-capture/SKILL.md +85 -0
- package/vendor/desk/skills/lesson-capture/agents-md-budget.mjs +61 -0
- package/vendor/desk/skills/online-evaluation/SKILL.md +81 -0
- package/vendor/desk/skills/operator-voice-comments/LICENSE-humanize +21 -0
- package/vendor/desk/skills/operator-voice-comments/SKILL.md +90 -0
- package/vendor/desk/skills/operator-voice-comments/human-voice.md +43 -0
- package/vendor/desk/skills/peer-pr-review/SKILL.md +104 -0
- package/vendor/desk/skills/pr-feedback-on-own-pr/SKILL.md +145 -0
- package/vendor/desk/skills/pr-review-interrogation/SKILL.md +121 -0
- package/vendor/desk/skills/pr-reviewer-audit/SKILL.md +68 -0
- package/vendor/desk/skills/pr-reviewer-audit/helpers/audit.py +335 -0
- package/vendor/desk/skills/pr-reviewer-audit/helpers/test_audit.py +486 -0
- package/vendor/desk/skills/pr-self-review/SKILL.md +86 -0
- package/vendor/desk/skills/pr-surface-hygiene/SKILL.md +105 -0
- package/vendor/desk/skills/pr-surface-hygiene/check-visual-proof.cjs +99 -0
- package/vendor/desk/skills/pr-surface-hygiene/repository-setup.md +19 -0
- package/vendor/desk/skills/pr-surface-hygiene/resources/pr-visual-proof.yml +29 -0
- package/vendor/desk/skills/pr-surface-hygiene/resources/pull-request-template.md +5 -0
- package/vendor/desk/skills/preflight-actions/SKILL.md +60 -0
- package/vendor/desk/skills/preview-feedback/SKILL.md +70 -0
- package/vendor/desk/skills/repo-handling/SKILL.md +67 -0
- package/vendor/desk/skills/rnd-lab/SKILL.md +52 -0
- package/vendor/desk/skills/runtime-symptom-investigation/SKILL.md +106 -0
- package/vendor/desk/skills/session-resumption/SKILL.md +126 -0
- package/vendor/desk/skills/session-start/SKILL.md +54 -0
- package/vendor/desk/skills/session-start/details.md +150 -0
- package/vendor/desk/skills/session-start-migrations/README.md +71 -0
- package/vendor/desk/skills/session-start-migrations/SKILL.md +108 -0
- package/vendor/desk/skills/start-task/SKILL.md +88 -0
- package/vendor/desk/skills/task-card-format/SKILL.md +198 -0
- package/vendor/desk/skills/task-lifecycle/SKILL.md +217 -0
- package/vendor/desk/skills/track-card-format/SKILL.md +90 -0
- package/vendor/desk/skills/using-desk/SKILL.md +58 -0
- package/vendor/desk/skills/using-superpowers-with-desk/SKILL.md +156 -0
- 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
|
+
}
|