@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,662 @@
|
|
|
1
|
+
// Session retention keeps the disk used by agent sessions, their worktrees and logs bounded. It is opt-in: nothing in Desk runs it;
|
|
2
|
+
// an operator schedules the CLI (scripts/session-retention.js). A dry run is the default and `--apply` deletes. See docs/session-retention.md.
|
|
3
|
+
//
|
|
4
|
+
// It reads directory entries and stats only removal candidates, never walks inside a regenerable tree, measures what it freed from
|
|
5
|
+
// free-space readings, and deletes by moving a folder aside and removing it in rate-limited pieces: a per-file walk of a busy machine's
|
|
6
|
+
// agent storage can saturate its disk for hours.
|
|
7
|
+
import { execFile } from "node:child_process"
|
|
8
|
+
import { promises as fsp } from "node:fs"
|
|
9
|
+
import os from "node:os"
|
|
10
|
+
import path from "node:path"
|
|
11
|
+
import { resolveStateHome } from "../util/paths.js"
|
|
12
|
+
import { AxError } from "../lib/ouro-ui/registry/ouro/ax/problem.ts"
|
|
13
|
+
import { defineCli, defineCommand } from "../lib/ouro-ui/registry/ouro/ax/ax-command.ts"
|
|
14
|
+
import { runCli } from "../lib/ouro-ui/registry/ouro/ax/cli.ts"
|
|
15
|
+
|
|
16
|
+
const DAY = 86_400_000
|
|
17
|
+
const GB = 1_073_741_824
|
|
18
|
+
const MB = 1_048_576
|
|
19
|
+
const BUILD_DIRS = new Set(["node_modules", "dist", "target", ".vite", ".next", ".turbo", ".parcel-cache", ".svelte-kit", "DerivedData", ".build"])
|
|
20
|
+
const MEDIA = new Set([".mp4", ".webm", ".mov", ".mkv", ".avi", ".m4v"])
|
|
21
|
+
const TRACE = new Set([".trace", ".cpuprofile", ".heapsnapshot", ".heapprofile", ".har"])
|
|
22
|
+
const IMAGE = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif", ".bmp", ".tiff"])
|
|
23
|
+
// A session's history and plan stay, whatever its state.
|
|
24
|
+
const SESSION_KEEP_TOP = new Set(["events.jsonl", "checkpoints", "workspace.yaml", "session.db", "plan.md", "research", ".workspace-fork.lock"])
|
|
25
|
+
const SMALL_TEXT = /\.(?:md|txt|json|ya?ml|jsonl|csv|log)$/iu
|
|
26
|
+
const GIT_BUSY = ["MERGE_HEAD", "rebase-merge", "rebase-apply", "CHERRY_PICK_HEAD", "REVERT_HEAD", "BISECT_LOG"]
|
|
27
|
+
const SKIPPABLE = new Set(["logs", "sessions", "worktrees", "state"])
|
|
28
|
+
// A workspace session's archive state lives on its workspace; sessions.archived_at covers only sessions without one.
|
|
29
|
+
const QUERIES = {
|
|
30
|
+
protectedIds: `select session_id as v from workspaces where archived_at is null and session_id is not null
|
|
31
|
+
union select a.session_id from workspace_session_aliases a join workspaces w on w.id = a.workspace_id where w.archived_at is null
|
|
32
|
+
union select s.id from sessions s where s.is_running = 1 or (s.archived_at is null
|
|
33
|
+
and not exists (select 1 from workspaces w where w.session_id = s.id)
|
|
34
|
+
and not exists (select 1 from workspace_session_aliases a where a.session_id = s.id))`,
|
|
35
|
+
protectedPaths: `select t.path as v from workspaces w join worktrees t on t.id = w.worktree_id where w.archived_at is null
|
|
36
|
+
union select source_path from workspaces where archived_at is null and source_path is not null`,
|
|
37
|
+
openPr: `select session_id as v from workspaces where created_pr_state = 'open' and session_id is not null
|
|
38
|
+
union select a.session_id from workspace_session_aliases a join workspaces w on w.id = a.workspace_id where w.created_pr_state = 'open'`,
|
|
39
|
+
archivedIds: `select id as v from sessions where archived_at is not null
|
|
40
|
+
union select session_id from workspaces where archived_at is not null and session_id is not null
|
|
41
|
+
union select a.session_id from workspace_session_aliases a join workspaces w on w.id = a.workspace_id where w.archived_at is not null`,
|
|
42
|
+
knownWorktrees: "select path as v from worktrees",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const NUMBER = (description) => ({ type: "number", min: 0, description })
|
|
46
|
+
const LIST = (description) => ({ type: "string", placeholder: "<dirs>", description: `${description} Separated by "${path.delimiter}".` })
|
|
47
|
+
const FLAGS = {
|
|
48
|
+
apply: { type: "boolean", description: "Delete what the dry run lists." },
|
|
49
|
+
ceiling: { type: "boolean", description: "After the main pass, prune the oldest inactive sessions until agent storage is under --ceiling-gb." },
|
|
50
|
+
"ceiling-gb": NUMBER("Storage ceiling in GB (60)."),
|
|
51
|
+
"session-state": { type: "string", placeholder: "<dir>", description: "Copilot session folders (<COPILOT_HOME>/session-state)." },
|
|
52
|
+
"app-db": { type: "string", placeholder: "<file>", description: "Copilot app database, read only (<COPILOT_HOME>/data.db)." },
|
|
53
|
+
"code-roots": LIST("Folders holding session worktrees (default: the parents of the worktrees the app database knows)."),
|
|
54
|
+
"log-dirs": LIST("Log folders pruned by age (<COPILOT_HOME>/logs)."),
|
|
55
|
+
"state-roots": LIST("Other agent state folders: only old node_modules and unused browser profiles go (none)."),
|
|
56
|
+
"log-days": NUMBER("Log age to remove (7)."),
|
|
57
|
+
"artifact-days": NUMBER("Age of screenshots, build folders and browser profiles to remove (3)."),
|
|
58
|
+
"recent-hours": NUMBER("A session written within this many hours counts as active (24)."),
|
|
59
|
+
"worktree-depth": NUMBER("How deep to look for worktrees under each code root (3)."),
|
|
60
|
+
"scan-depth": NUMBER("How deep to look inside a session folder (7)."),
|
|
61
|
+
"load-limit": NUMBER("Load average above which the scan and deletion slow down (12)."),
|
|
62
|
+
"gb-per-min": NUMBER("Most GB deleted per minute (3)."),
|
|
63
|
+
"git-pause-ms": NUMBER("Pause before checking each worktree with Git (1000)."),
|
|
64
|
+
skip: { type: "string", placeholder: "<list>", description: `Comma-separated parts to skip: ${[...SKIPPABLE].join(", ")}.` },
|
|
65
|
+
trash: { type: "string", placeholder: "<dir>", description: "Where folders wait to be deleted, on the same volume (<state>/desk/session-retention/trash)." },
|
|
66
|
+
"report-dir": { type: "string", placeholder: "<dir>", description: "Where the JSON report goes (<state>/desk/session-retention)." },
|
|
67
|
+
sizes: { type: "boolean", description: "Measure each listed folder with du (slower)." },
|
|
68
|
+
verbose: { type: "boolean", description: "List every checkout left in place and why." },
|
|
69
|
+
}
|
|
70
|
+
const PATH_FLAGS = { "app-db": "appDb", "report-dir": "reportDir", "session-state": "sessionState", trash: "trash" }
|
|
71
|
+
const LIST_FLAGS = { "code-roots": "codeRoots", "log-dirs": "logDirs", "state-roots": "stateRoots" }
|
|
72
|
+
const NUMBER_FLAGS = {
|
|
73
|
+
"artifact-days": "artifactDays", "ceiling-gb": "ceilingGB", "gb-per-min": "gbPerMin", "git-pause-ms": "gitPauseMs",
|
|
74
|
+
"load-limit": "loadLimit", "log-days": "logDays", "recent-hours": "recentHours", "scan-depth": "scanDepth", "worktree-depth": "worktreeDepth",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The options with their defaults, then the flags the command was given applied. */
|
|
78
|
+
export function retentionOptions(input = {}, { env = process.env, homeDir = os.homedir() } = {}) {
|
|
79
|
+
const home = env.HOME || homeDir
|
|
80
|
+
const copilot = env.COPILOT_HOME || path.join(home, ".copilot")
|
|
81
|
+
const state = path.join(resolveStateHome({ ...env, HOME: home }), "desk", "session-retention")
|
|
82
|
+
const options = {
|
|
83
|
+
apply: input.apply === true, ceiling: input.ceiling === true, sizes: input.sizes === true, verbose: input.verbose === true,
|
|
84
|
+
sessionState: path.join(copilot, "session-state"),
|
|
85
|
+
appDb: path.join(copilot, "data.db"),
|
|
86
|
+
codeRoots: null,
|
|
87
|
+
logDirs: [path.join(copilot, "logs")],
|
|
88
|
+
stateRoots: [],
|
|
89
|
+
logDays: 7, artifactDays: 3, recentHours: 24, ceilingGB: 60, loadLimit: 12,
|
|
90
|
+
worktreeDepth: 3, scanDepth: 7, gbPerMin: 3, gitPauseMs: 1000,
|
|
91
|
+
trash: path.join(state, "trash"),
|
|
92
|
+
reportDir: state,
|
|
93
|
+
skip: new Set(),
|
|
94
|
+
home,
|
|
95
|
+
}
|
|
96
|
+
for (const [flag, key] of Object.entries(PATH_FLAGS)) if (input[flag] !== undefined) options[key] = path.resolve(input[flag])
|
|
97
|
+
for (const [flag, key] of Object.entries(LIST_FLAGS)) if (input[flag] !== undefined) options[key] = input[flag].split(path.delimiter).filter(Boolean).map((p) => path.resolve(p))
|
|
98
|
+
for (const [flag, key] of Object.entries(NUMBER_FLAGS)) if (input[flag] !== undefined) options[key] = input[flag]
|
|
99
|
+
if (input.skip !== undefined) {
|
|
100
|
+
const parts = input.skip.split(",").filter(Boolean)
|
|
101
|
+
const unknown = parts.filter((p) => !SKIPPABLE.has(p))
|
|
102
|
+
if (unknown.length) throw new AxError({ code: "skip-unknown-name", exit: 2, thing: "--skip", problem: `it takes ${[...SKIPPABLE].join(", ")}, not ${unknown.join(", ")}`, fix: `session-retention --skip ${[...SKIPPABLE][0]}` })
|
|
103
|
+
options.skip = new Set(parts)
|
|
104
|
+
}
|
|
105
|
+
return options
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const DEFAULT_DEPS = {
|
|
109
|
+
now: () => Date.now(),
|
|
110
|
+
loadavg: () => os.loadavg(),
|
|
111
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
112
|
+
kill: (pid, signal) => process.kill(pid, signal),
|
|
113
|
+
freeBytes: async (dir) => {
|
|
114
|
+
const s = await fsp.statfs(dir)
|
|
115
|
+
return s.bavail * s.bsize
|
|
116
|
+
},
|
|
117
|
+
// null when the size cannot be measured (no du, as on Windows); the ceiling then reports itself unmeasured.
|
|
118
|
+
diskUsage: async (target) => {
|
|
119
|
+
const r = await runCommand("du", ["-sk", target], { timeout: 1_800_000 })
|
|
120
|
+
return r.ok ? Number(r.stdout.split("\t")[0]) * 1024 : null
|
|
121
|
+
},
|
|
122
|
+
openAppDb: async (file) => {
|
|
123
|
+
const { default: Database } = await import("better-sqlite3")
|
|
124
|
+
const db = new Database(file, { readonly: true, fileMustExist: true })
|
|
125
|
+
return { all: (sql) => db.prepare(sql).all(), close: () => db.close() }
|
|
126
|
+
},
|
|
127
|
+
run: (cmd, argv, options) => runCommand(cmd, argv, options),
|
|
128
|
+
rm: (target) => fsp.rm(target, { recursive: true, force: true }),
|
|
129
|
+
rename: (from, to) => fsp.rename(from, to),
|
|
130
|
+
// Load from other processes can stay high for hours, so pacing slows the job down but never stalls it.
|
|
131
|
+
paceEvery: 200,
|
|
132
|
+
deleteBatch: 1024,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function runCommand(cmd, argv, { cwd, timeout = 120_000 } = {}) {
|
|
136
|
+
const env = { ...process.env, GIT_OPTIONAL_LOCKS: "0", GIT_TERMINAL_PROMPT: "0", GCM_INTERACTIVE: "never" }
|
|
137
|
+
return new Promise((resolve) => {
|
|
138
|
+
execFile(cmd, argv, { cwd, timeout, env, windowsHide: true, maxBuffer: 64 * MB }, (error, stdout, stderr) =>
|
|
139
|
+
resolve({ ok: !error, stdout: String(stdout), stderr: String(stderr) }))
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function lstat(p) {
|
|
144
|
+
try {
|
|
145
|
+
return await fsp.lstat(p)
|
|
146
|
+
} catch {
|
|
147
|
+
return null
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function readdir(p) {
|
|
152
|
+
try {
|
|
153
|
+
return await fsp.readdir(p, { withFileTypes: true })
|
|
154
|
+
} catch {
|
|
155
|
+
return []
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function isInside(child, parent) {
|
|
160
|
+
const rel = path.relative(parent, child)
|
|
161
|
+
return rel === "" || (rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel))
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Allocated size; a file system that reports no blocks (or a sparse file) falls back to the length.
|
|
165
|
+
const diskBytes = (st) => st.blocks * 512 || st.size
|
|
166
|
+
const gb = (bytes) => `${(bytes / GB).toFixed(2)} GB`
|
|
167
|
+
const keepTop = (name) => SESSION_KEEP_TOP.has(name) || name.startsWith("inuse.")
|
|
168
|
+
|
|
169
|
+
/** Runs one retention pass with `options` from parseRetentionArgs; `overrides` replace its clock, processes and file operations in tests. */
|
|
170
|
+
export async function runRetention(options, overrides = {}) {
|
|
171
|
+
const o = options
|
|
172
|
+
const d = { ...DEFAULT_DEPS, ...overrides }
|
|
173
|
+
const t0 = d.now()
|
|
174
|
+
const plan = []
|
|
175
|
+
const planned = new Set()
|
|
176
|
+
const skipped = []
|
|
177
|
+
const undeletable = []
|
|
178
|
+
const stats = { sessions: { active: 0, inactive: 0 }, worktrees: { protected: 0, candidates: 0 } }
|
|
179
|
+
const remoteShaCache = new Map()
|
|
180
|
+
let paceBudget = 0
|
|
181
|
+
let batch = 0
|
|
182
|
+
let windowStart = 0
|
|
183
|
+
let windowFree = 0
|
|
184
|
+
|
|
185
|
+
const git = (dir, argv, opts) => d.run("git", ["-c", "core.fsmonitor=false", "-C", dir, ...argv], opts)
|
|
186
|
+
// A file that vanished since its folder was read (st is null) never counts as old.
|
|
187
|
+
const old = (st, days) => t0 - st?.mtimeMs > days * DAY
|
|
188
|
+
|
|
189
|
+
async function pace() {
|
|
190
|
+
if (++paceBudget < d.paceEvery) return
|
|
191
|
+
paceBudget = 0
|
|
192
|
+
if (d.loadavg()[0] > o.loadLimit) await d.sleep(1500)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function underPlanned(p) {
|
|
196
|
+
for (let q = p; q !== path.dirname(q); q = path.dirname(q)) if (planned.has(q)) return true
|
|
197
|
+
return false
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function add(category, p, extra = {}) {
|
|
201
|
+
if (underPlanned(p)) return
|
|
202
|
+
planned.add(p)
|
|
203
|
+
const bytes = extra.bytes ?? (o.sizes ? (await d.diskUsage(p)) || 0 : 0)
|
|
204
|
+
plan.push({ category, path: p, ...extra, bytes })
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// ---------- what is active ----------
|
|
208
|
+
async function loadActive() {
|
|
209
|
+
let db
|
|
210
|
+
try {
|
|
211
|
+
db = await d.openAppDb(o.appDb)
|
|
212
|
+
const read = (sql) => new Set(db.all(sql).map((row) => row.v))
|
|
213
|
+
return Object.fromEntries(Object.entries(QUERIES).map(([key, sql]) => [key, read(sql)]))
|
|
214
|
+
} catch (error) {
|
|
215
|
+
throw Object.assign(new Error(`Check the app database path: cannot read the app database at ${o.appDb} (${error.message}); sessions and worktrees left untouched`), { code: "session_retention_check_the_app_database_path" })
|
|
216
|
+
} finally {
|
|
217
|
+
db?.close()
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function pidAlive(pid) {
|
|
222
|
+
try {
|
|
223
|
+
d.kill(pid, 0)
|
|
224
|
+
return true
|
|
225
|
+
} catch (error) {
|
|
226
|
+
return error.code === "EPERM"
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async function workspacePaths(dir) {
|
|
231
|
+
let text = ""
|
|
232
|
+
try {
|
|
233
|
+
text = await fsp.readFile(path.join(dir, "workspace.yaml"), "utf8")
|
|
234
|
+
} catch {
|
|
235
|
+
return []
|
|
236
|
+
}
|
|
237
|
+
return ["cwd", "git_root"]
|
|
238
|
+
.map((key) => text.match(new RegExp(`^${key}:[ \\t]*(.+)$`, "mu")))
|
|
239
|
+
.filter(Boolean)
|
|
240
|
+
.map((m) => m[1].trim().replace(/^["']|["']$/gu, ""))
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async function sessionActivity(dir) {
|
|
244
|
+
let newest = 0
|
|
245
|
+
let live = false
|
|
246
|
+
for (const e of await readdir(dir)) {
|
|
247
|
+
const lock = e.name.match(/^inuse\.(\d+)\.lock$/u)
|
|
248
|
+
if (lock && pidAlive(Number(lock[1]))) live = true
|
|
249
|
+
const st = e.isFile() && await lstat(path.join(dir, e.name))
|
|
250
|
+
if (st) newest = Math.max(newest, st.mtimeMs)
|
|
251
|
+
}
|
|
252
|
+
return { live, newest }
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// ---------- git safety ----------
|
|
256
|
+
async function remoteShas(dir, commonDir) {
|
|
257
|
+
if (remoteShaCache.has(commonDir)) return remoteShaCache.get(commonDir)
|
|
258
|
+
const shas = new Set()
|
|
259
|
+
for (const remote of (await git(dir, ["remote"])).stdout.split("\n").filter(Boolean)) {
|
|
260
|
+
const res = await git(dir, ["ls-remote", remote], { timeout: 60_000 })
|
|
261
|
+
for (const line of (res.ok ? res.stdout : "").split("\n").filter(Boolean)) shas.add(line.split("\t")[0])
|
|
262
|
+
}
|
|
263
|
+
remoteShaCache.set(commonDir, shas)
|
|
264
|
+
return shas
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Safe means nothing is lost by removing the checkout: clean, idle, and every tip is on a remote (or is a SHA a remote advertises,
|
|
268
|
+
// which covers a squash-merged pull request's head).
|
|
269
|
+
async function gitSafety(dir, linked) {
|
|
270
|
+
const top = await git(dir, ["rev-parse", "--absolute-git-dir", "--git-common-dir"])
|
|
271
|
+
if (!top.ok) return { reason: "git metadata unreadable (broken or orphaned checkout)" }
|
|
272
|
+
const [gitDir, commonRaw] = top.stdout.trim().split("\n")
|
|
273
|
+
const commonDir = path.resolve(dir, commonRaw)
|
|
274
|
+
for (const marker of GIT_BUSY) if (await lstat(path.join(gitDir, marker))) return { reason: `git operation in progress (${marker})` }
|
|
275
|
+
if (linked && await lstat(path.join(gitDir, "locked"))) return { reason: "worktree is locked" }
|
|
276
|
+
const st = await git(dir, ["status", "--porcelain=v1", "--untracked-files=normal", "--ignore-submodules=none"], { timeout: 300_000 })
|
|
277
|
+
if (!st.ok) return { reason: "git status failed" }
|
|
278
|
+
if (st.stdout.trim()) return { reason: `uncommitted changes (${st.stdout.trim().split("\n").length} paths)` }
|
|
279
|
+
if (!(await git(dir, ["remote"])).stdout.trim()) return { reason: "no git remote" }
|
|
280
|
+
const tips = [["HEAD", (await git(dir, ["rev-parse", "HEAD"])).stdout.trim()]]
|
|
281
|
+
if (!linked) {
|
|
282
|
+
const branches = await git(dir, ["for-each-ref", "--format=%(refname:short)\t%(objectname)", "refs/heads"])
|
|
283
|
+
tips.push(...branches.stdout.split("\n").filter(Boolean).map((line) => line.split("\t")))
|
|
284
|
+
if ((await git(dir, ["stash", "list"])).stdout.trim()) return { reason: "has git stash entries" }
|
|
285
|
+
}
|
|
286
|
+
for (const [name, sha] of tips) {
|
|
287
|
+
const unpushed = await git(dir, ["rev-list", "--max-count=1", sha, "--not", "--remotes"])
|
|
288
|
+
if (!unpushed.ok) return { reason: `cannot compare ${name} with remotes` }
|
|
289
|
+
if (!unpushed.stdout.trim() || (await remoteShas(dir, commonDir)).has(sha)) continue
|
|
290
|
+
const count = (await git(dir, ["rev-list", "--count", sha, "--not", "--remotes"])).stdout.trim()
|
|
291
|
+
return { reason: `unpushed commits on ${name} (${count} not on any remote)` }
|
|
292
|
+
}
|
|
293
|
+
return { safe: true, commonDir }
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ---------- scanners ----------
|
|
297
|
+
const isChromiumProfile = (entries) => entries.some((e) => e.name === "Local State" && e.isFile())
|
|
298
|
+
|
|
299
|
+
async function scanTree(dir, ctx, depth = 0) {
|
|
300
|
+
await pace()
|
|
301
|
+
const entries = await readdir(dir)
|
|
302
|
+
if (depth > 0 && ctx.mode !== "state" && entries.some((e) => e.name === ".git") && dir !== ctx.gitRoot) return handleCheckout(dir, entries, ctx, depth)
|
|
303
|
+
if (depth > 0 && ctx.mode === "inactive" && isChromiumProfile(entries)) return add("browser-profiles", dir)
|
|
304
|
+
if (depth > 0 && ctx.mode === "state" && isChromiumProfile(entries)) {
|
|
305
|
+
// A running browser keeps a SingletonLock symlink in its profile.
|
|
306
|
+
const st = await lstat(dir)
|
|
307
|
+
if (!entries.some((e) => e.name === "SingletonLock") && old(st, o.artifactDays)) await add("state-browser-profiles", dir)
|
|
308
|
+
return
|
|
309
|
+
}
|
|
310
|
+
if (depth >= ctx.maxDepth) return
|
|
311
|
+
for (const e of entries) {
|
|
312
|
+
const fp = path.join(dir, e.name)
|
|
313
|
+
if (e.isSymbolicLink() || (depth === 0 && ctx.session && keepTop(e.name))) continue
|
|
314
|
+
if (e.isDirectory()) await scanDir(fp, e.name, ctx, depth)
|
|
315
|
+
else if (e.isFile() && ctx.mode === "inactive") await scanFile(fp, e.name, ctx)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
async function scanDir(fp, name, ctx, depth) {
|
|
320
|
+
if (name === ".git") return
|
|
321
|
+
if (!BUILD_DIRS.has(name) || (ctx.mode === "state" && name !== "node_modules")) return scanTree(fp, ctx, depth + 1)
|
|
322
|
+
if (ctx.mode !== "inactive" && !old(await lstat(fp), o.artifactDays)) return
|
|
323
|
+
// Only ignored build output goes from a checkout: a tracked dist/ is source.
|
|
324
|
+
if (ctx.gitRoot && name !== "node_modules" && !(await git(ctx.gitRoot, ["check-ignore", "-q", fp])).ok) return
|
|
325
|
+
await add("build-output", fp)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async function scanFile(fp, name, ctx) {
|
|
329
|
+
const ext = path.extname(name).toLowerCase()
|
|
330
|
+
if (MEDIA.has(ext)) return add("videos", fp)
|
|
331
|
+
if (TRACE.has(ext) || (ext === ".zip" && /trace/iu.test(name))) return add("traces", fp)
|
|
332
|
+
if (ext === ".json" && /trace|profile/iu.test(name)) {
|
|
333
|
+
const st = await lstat(fp)
|
|
334
|
+
if (st?.size > 10 * MB) await add("traces", fp, { bytes: diskBytes(st) })
|
|
335
|
+
return
|
|
336
|
+
}
|
|
337
|
+
if (!IMAGE.has(ext) || ctx.keepImages) return
|
|
338
|
+
const st = await lstat(fp)
|
|
339
|
+
if (old(st, o.artifactDays)) await add("screenshots", fp, { bytes: diskBytes(st) })
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async function handleCheckout(dir, entries, ctx, depth) {
|
|
343
|
+
const linked = entries.find((e) => e.name === ".git").isFile()
|
|
344
|
+
if (ctx.mode === "inactive") {
|
|
345
|
+
const s = await gitSafety(dir, linked)
|
|
346
|
+
if (s.safe) return add("session-clones", dir, linked ? { commonDir: s.commonDir } : {})
|
|
347
|
+
skipped.push({ path: dir, reason: s.reason })
|
|
348
|
+
}
|
|
349
|
+
return scanTree(dir, { ...ctx, mode: ctx.mode === "inactive" ? "buildOnly" : ctx.mode, gitRoot: dir }, depth)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
async function scanSessions(active, scanContents) {
|
|
353
|
+
const sessions = []
|
|
354
|
+
for (const e of await readdir(o.sessionState)) {
|
|
355
|
+
if (!e.isDirectory()) continue
|
|
356
|
+
const dir = path.join(o.sessionState, e.name)
|
|
357
|
+
const { live, newest } = await sessionActivity(dir)
|
|
358
|
+
const isActive = active.protectedIds.has(e.name) || live || t0 - newest < o.recentHours * 3_600_000
|
|
359
|
+
if (isActive) for (const p of await workspacePaths(dir)) active.protectedPaths.add(p)
|
|
360
|
+
sessions.push({ id: e.name, dir, isActive, newest, archived: active.archivedIds.has(e.name) })
|
|
361
|
+
}
|
|
362
|
+
for (const s of sessions) {
|
|
363
|
+
stats.sessions[s.isActive ? "active" : "inactive"]++
|
|
364
|
+
if (scanContents) await scanTree(s.dir, { mode: s.isActive ? "active" : "inactive", session: true, keepImages: active.openPr.has(s.id), maxDepth: o.scanDepth })
|
|
365
|
+
}
|
|
366
|
+
return sessions
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async function findCheckouts(root, depth, found) {
|
|
370
|
+
if (depth > o.worktreeDepth) return found
|
|
371
|
+
for (const e of await readdir(root)) {
|
|
372
|
+
if (!e.isDirectory() || e.name === "node_modules" || e.name === ".git") continue
|
|
373
|
+
const fp = path.join(root, e.name)
|
|
374
|
+
const dotGit = await lstat(path.join(fp, ".git"))
|
|
375
|
+
if (dotGit) found.push({ path: fp, linked: dotGit.isFile() })
|
|
376
|
+
else await findCheckouts(fp, depth + 1, found)
|
|
377
|
+
}
|
|
378
|
+
return found
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Without --code-roots, the folders that hold the worktrees the app made. The home folder itself is never a code root.
|
|
382
|
+
function codeRoots(active) {
|
|
383
|
+
if (o.codeRoots) return o.codeRoots
|
|
384
|
+
const parents = [...new Set([...active.knownWorktrees].map((p) => path.dirname(p)))]
|
|
385
|
+
.filter((p) => p !== path.dirname(p) && p !== o.home)
|
|
386
|
+
return parents.filter((p) => !parents.some((q) => q !== p && isInside(p, q)))
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function scanWorktrees(active, roots) {
|
|
390
|
+
const prot = [...active.protectedPaths]
|
|
391
|
+
// The app keeps a pool of pre-created copilot-prewarm-* worktrees for future sessions, outside its database.
|
|
392
|
+
const isProtected = (p) => path.basename(p).startsWith("copilot-prewarm-") || prot.some((q) => isInside(p, q) || isInside(q, p))
|
|
393
|
+
for (const root of roots) {
|
|
394
|
+
for (const c of await findCheckouts(root, 1, [])) {
|
|
395
|
+
await pace()
|
|
396
|
+
if (c.linked && !isProtected(c.path)) {
|
|
397
|
+
await d.sleep(o.gitPauseMs)
|
|
398
|
+
const s = await gitSafety(c.path, true)
|
|
399
|
+
if (s.safe) {
|
|
400
|
+
stats.worktrees.candidates++
|
|
401
|
+
await add("worktrees", c.path, { commonDir: s.commonDir })
|
|
402
|
+
continue
|
|
403
|
+
}
|
|
404
|
+
skipped.push({ path: c.path, reason: s.reason })
|
|
405
|
+
} else if (c.linked) stats.worktrees.protected++
|
|
406
|
+
await scanTree(c.path, { mode: "active", gitRoot: c.path, maxDepth: o.scanDepth })
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async function scanLogs() {
|
|
412
|
+
const stack = [...o.logDirs]
|
|
413
|
+
while (stack.length) {
|
|
414
|
+
const dir = stack.pop()
|
|
415
|
+
for (const e of await readdir(dir)) {
|
|
416
|
+
const fp = path.join(dir, e.name)
|
|
417
|
+
if (e.isDirectory()) stack.push(fp)
|
|
418
|
+
if (!e.isFile()) continue
|
|
419
|
+
const st = await lstat(fp)
|
|
420
|
+
if (old(st, o.logDays)) await add("logs", fp, { bytes: diskBytes(st) })
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// ---------- ceiling ----------
|
|
426
|
+
async function agentStorageBytes(roots) {
|
|
427
|
+
const tops = [o.sessionState, ...o.logDirs]
|
|
428
|
+
for (const root of roots) for (const c of await findCheckouts(root, 1, [])) if (c.linked) tops.push(c.path)
|
|
429
|
+
let total = 0
|
|
430
|
+
for (const top of tops) {
|
|
431
|
+
if (!(await lstat(top))) continue
|
|
432
|
+
const bytes = await d.diskUsage(top)
|
|
433
|
+
if (bytes === null) return null
|
|
434
|
+
total += bytes
|
|
435
|
+
}
|
|
436
|
+
return total
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
async function ceilingPass(sessions, roots) {
|
|
440
|
+
const current = await agentStorageBytes(roots)
|
|
441
|
+
const ceilingBytes = o.ceilingGB * GB
|
|
442
|
+
if (current === null) return { unmeasured: true, ceilingBytes }
|
|
443
|
+
// After --apply the main deletions already happened, so `current` is measured; a dry run projects from the listed sizes (known only with --sizes).
|
|
444
|
+
const projected = current - (o.apply ? 0 : plan.reduce((sum, item) => sum + item.bytes, 0))
|
|
445
|
+
const result = { currentBytes: current, projectedBytes: projected, ceilingBytes, extraBytes: 0, sessionsPruned: 0 }
|
|
446
|
+
let over = projected - ceilingBytes
|
|
447
|
+
const oldestFirst = sessions.filter((s) => !s.isActive).sort((a, b) => (b.archived - a.archived) || (a.newest - b.newest))
|
|
448
|
+
for (const s of oldestFirst) {
|
|
449
|
+
if (over <= 0) break
|
|
450
|
+
let freed = 0
|
|
451
|
+
const stack = [s.dir]
|
|
452
|
+
while (stack.length) {
|
|
453
|
+
const dir = stack.pop()
|
|
454
|
+
for (const e of await readdir(dir)) {
|
|
455
|
+
const fp = path.join(dir, e.name)
|
|
456
|
+
if (e.isSymbolicLink() || underPlanned(fp) || (dir === s.dir && keepTop(e.name))) continue
|
|
457
|
+
if (e.isDirectory()) {
|
|
458
|
+
// Never enter a checkout the main pass did not verify as safe.
|
|
459
|
+
if (e.name !== ".git" && !(await lstat(path.join(fp, ".git")))) stack.push(fp)
|
|
460
|
+
continue
|
|
461
|
+
}
|
|
462
|
+
const st = await lstat(fp)
|
|
463
|
+
if (!st || (SMALL_TEXT.test(e.name) && st.size < MB)) continue
|
|
464
|
+
await add("ceiling", fp, { bytes: diskBytes(st) })
|
|
465
|
+
freed += diskBytes(st)
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
over -= freed
|
|
469
|
+
result.extraBytes += freed
|
|
470
|
+
result.sessionsPruned++
|
|
471
|
+
}
|
|
472
|
+
return result
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// ---------- apply ----------
|
|
476
|
+
async function resetWindow() {
|
|
477
|
+
windowStart = d.now()
|
|
478
|
+
windowFree = await d.freeBytes(o.trash)
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
async function rateLimit() {
|
|
482
|
+
const elapsed = d.now() - windowStart
|
|
483
|
+
if (elapsed >= 60_000) return resetWindow()
|
|
484
|
+
if ((await d.freeBytes(o.trash)) - windowFree >= o.gbPerMin * GB) {
|
|
485
|
+
await d.sleep(60_000 - elapsed)
|
|
486
|
+
return resetWindow()
|
|
487
|
+
}
|
|
488
|
+
// Deletions wake endpoint scanners, so after each batch the job yields briefly while the 5-minute load is high.
|
|
489
|
+
if (++batch < d.deleteBatch) return
|
|
490
|
+
batch = 0
|
|
491
|
+
if (d.loadavg()[1] >= o.loadLimit) await d.sleep(2000)
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
async function rmForce(p) {
|
|
495
|
+
try {
|
|
496
|
+
return await d.rm(p)
|
|
497
|
+
} catch (error) {
|
|
498
|
+
if (error.code !== "EACCES" && error.code !== "EPERM") throw error
|
|
499
|
+
}
|
|
500
|
+
// Some packages ship read-only folders: restore owner write permission and retry once.
|
|
501
|
+
await d.run("chmod", ["-R", "u+w", p], { timeout: 600_000 })
|
|
502
|
+
try {
|
|
503
|
+
await d.rm(p)
|
|
504
|
+
} catch (error) {
|
|
505
|
+
if (undeletable.some((u) => isInside(p, u.path) || isInside(u.path, p))) return
|
|
506
|
+
undeletable.push({ path: p, reason: error.code === "EACCES" || error.code === "EPERM" ? "not removable by this user (left in the trash)" : error.message })
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// Deletes a tree in pieces so no single step frees more than a little at once.
|
|
511
|
+
async function rmChunked(p, depth = 3) {
|
|
512
|
+
if ((await lstat(p))?.isDirectory() && depth > 0) for (const e of await readdir(p)) await rmChunked(path.join(p, e.name), depth - 1)
|
|
513
|
+
await rmForce(p)
|
|
514
|
+
await rateLimit()
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
async function apply(items) {
|
|
518
|
+
const result = { removedBytes: 0, byCategory: {}, failed: [] }
|
|
519
|
+
await fsp.mkdir(o.trash, { recursive: true })
|
|
520
|
+
await resetWindow()
|
|
521
|
+
// Whatever an interrupted run left in the trash goes first.
|
|
522
|
+
for (const e of await readdir(o.trash)) await rmChunked(path.join(o.trash, e.name))
|
|
523
|
+
const runDir = path.join(o.trash, String(t0))
|
|
524
|
+
await fsp.mkdir(runDir, { recursive: true })
|
|
525
|
+
const prune = new Set()
|
|
526
|
+
let i = 0
|
|
527
|
+
for (const category of new Set(items.map((item) => item.category))) {
|
|
528
|
+
const before = await d.freeBytes(o.trash)
|
|
529
|
+
for (const item of items.filter((x) => x.category === category)) {
|
|
530
|
+
try {
|
|
531
|
+
if ((await fsp.lstat(item.path)).isDirectory()) {
|
|
532
|
+
// A same-volume rename takes the folder out of place at once; the slow delete happens afterwards.
|
|
533
|
+
let target = path.join(runDir, `${i++}-${path.basename(item.path)}`)
|
|
534
|
+
try {
|
|
535
|
+
await d.rename(item.path, target)
|
|
536
|
+
} catch (error) {
|
|
537
|
+
if (error.code !== "EXDEV") throw error
|
|
538
|
+
target = item.path
|
|
539
|
+
}
|
|
540
|
+
if (item.commonDir) prune.add(item.commonDir)
|
|
541
|
+
await rmChunked(target)
|
|
542
|
+
} else {
|
|
543
|
+
await rmForce(item.path)
|
|
544
|
+
if (i++ % 200 === 0) await rateLimit()
|
|
545
|
+
}
|
|
546
|
+
} catch (error) {
|
|
547
|
+
result.failed.push({ path: item.path, reason: error.message })
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
result.byCategory[category] = Math.max(0, (await d.freeBytes(o.trash)) - before)
|
|
551
|
+
result.removedBytes += result.byCategory[category]
|
|
552
|
+
}
|
|
553
|
+
for (const commonDir of prune) await d.run("git", ["--git-dir", commonDir, "worktree", "prune"])
|
|
554
|
+
await rmForce(runDir)
|
|
555
|
+
return result
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// ---------- main ----------
|
|
559
|
+
await fsp.mkdir(o.reportDir, { recursive: true })
|
|
560
|
+
const freeBefore = await d.freeBytes(o.reportDir)
|
|
561
|
+
let active = null
|
|
562
|
+
let classificationError = null
|
|
563
|
+
try {
|
|
564
|
+
active = await loadActive()
|
|
565
|
+
} catch (error) {
|
|
566
|
+
classificationError = error.message
|
|
567
|
+
}
|
|
568
|
+
if (!o.skip.has("logs")) await scanLogs()
|
|
569
|
+
let sessions = []
|
|
570
|
+
let roots = []
|
|
571
|
+
if (active) {
|
|
572
|
+
// Sessions are always classified: an active session's workspace paths protect its worktrees.
|
|
573
|
+
sessions = await scanSessions(active, !o.skip.has("sessions"))
|
|
574
|
+
roots = codeRoots(active)
|
|
575
|
+
if (!o.skip.has("worktrees")) await scanWorktrees(active, roots)
|
|
576
|
+
if (!o.skip.has("state")) for (const r of o.stateRoots) await scanTree(r, { mode: "state", maxDepth: 12 })
|
|
577
|
+
}
|
|
578
|
+
const applied = o.apply ? await apply(plan) : null
|
|
579
|
+
let ceiling = null
|
|
580
|
+
if (active && o.ceiling) {
|
|
581
|
+
const before = plan.length
|
|
582
|
+
ceiling = await ceilingPass(sessions, roots)
|
|
583
|
+
if (applied) {
|
|
584
|
+
const more = await apply(plan.slice(before))
|
|
585
|
+
applied.removedBytes += more.removedBytes
|
|
586
|
+
applied.failed.push(...more.failed)
|
|
587
|
+
for (const [k, v] of Object.entries(more.byCategory)) applied.byCategory[k] = (applied.byCategory[k] || 0) + v
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
const categories = {}
|
|
591
|
+
for (const item of plan) {
|
|
592
|
+
categories[item.category] ??= { items: 0, bytes: 0 }
|
|
593
|
+
categories[item.category].items++
|
|
594
|
+
categories[item.category].bytes += item.bytes
|
|
595
|
+
}
|
|
596
|
+
const report = {
|
|
597
|
+
mode: o.apply ? "apply" : "dry-run",
|
|
598
|
+
at: new Date(t0).toISOString(),
|
|
599
|
+
seconds: Math.round((d.now() - t0) / 1000),
|
|
600
|
+
classificationError,
|
|
601
|
+
codeRoots: roots,
|
|
602
|
+
sessions: stats.sessions,
|
|
603
|
+
worktrees: stats.worktrees,
|
|
604
|
+
categories,
|
|
605
|
+
plannedBytes: plan.reduce((sum, item) => sum + item.bytes, 0),
|
|
606
|
+
ceiling,
|
|
607
|
+
freeBefore,
|
|
608
|
+
freeAfter: await d.freeBytes(o.reportDir),
|
|
609
|
+
applied: applied && { ...applied, failed: [...applied.failed, ...undeletable] },
|
|
610
|
+
skipped,
|
|
611
|
+
plan: plan.map(({ category, path: p, bytes }) => ({ category, path: p, bytes })),
|
|
612
|
+
}
|
|
613
|
+
report.file = path.join(o.reportDir, `${report.at.slice(0, 10)}-${report.mode}.json`)
|
|
614
|
+
await fsp.writeFile(report.file, `${JSON.stringify(report, null, 1)}\n`)
|
|
615
|
+
return report
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function summary(report, o) {
|
|
619
|
+
const lines = [`session-retention ${report.mode} (${report.seconds}s): ${report.plan.length} items ${report.applied ? `removed, ${gb(report.applied.removedBytes)} freed` : "would be removed"}`]
|
|
620
|
+
if (report.classificationError) lines.push(` ${report.classificationError}`)
|
|
621
|
+
lines.push(` sessions: ${report.sessions.active} active, ${report.sessions.inactive} inactive; worktrees: ${report.worktrees.candidates} removable, ${report.worktrees.protected} protected`)
|
|
622
|
+
for (const [name, c] of Object.entries(report.categories).sort((a, b) => b[1].items - a[1].items)) {
|
|
623
|
+
const freed = report.applied ? ` freed ${gb(report.applied.byCategory[name] || 0)}` : ""
|
|
624
|
+
lines.push(` ${name.padEnd(22)} ${String(c.items).padStart(6)} items ${gb(c.bytes)}${freed}`)
|
|
625
|
+
}
|
|
626
|
+
const c = report.ceiling
|
|
627
|
+
if (c?.unmeasured) lines.push(" ceiling not checked: agent storage could not be measured (du unavailable)")
|
|
628
|
+
else if (c) lines.push(` agent storage ${gb(c.currentBytes)}, ceiling ${gb(c.ceilingBytes)}; the ceiling pass pruned ${c.sessionsPruned} sessions`)
|
|
629
|
+
lines.push(` left in place (unsafe to remove): ${report.skipped.length}`)
|
|
630
|
+
if (o.verbose) for (const s of report.skipped) lines.push(` ${s.path}: ${s.reason}`)
|
|
631
|
+
const failed = report.applied?.failed ?? []
|
|
632
|
+
if (failed.length) lines.push(` failed: ${failed.length}`, ...failed.slice(0, 20).map((f) => ` ${f.path}: ${f.reason}`))
|
|
633
|
+
lines.push(` free space: ${gb(report.freeBefore)} -> ${gb(report.freeAfter)}`, ` report: ${report.file}`)
|
|
634
|
+
return `${lines.join("\n")}\n`
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** The CLI: parses `argv` with Ouro AX, runs one pass and prints a summary (or JSON). Returns the exit code. */
|
|
638
|
+
export async function runSessionRetentionCli({ argv, env = process.env, io = process, deps }) {
|
|
639
|
+
const cli = defineCli({
|
|
640
|
+
name: "session-retention",
|
|
641
|
+
about: [
|
|
642
|
+
"Keeps agent session storage bounded. A dry run by default: it lists what it would remove and writes a report. --apply deletes.",
|
|
643
|
+
"Run it at low priority, for example: nice -n 19 node session-retention.js --apply --ceiling",
|
|
644
|
+
],
|
|
645
|
+
command: defineCommand({
|
|
646
|
+
name: "session-retention",
|
|
647
|
+
effect: "private",
|
|
648
|
+
summary: "List what is safe to remove from agent session storage and write a report; with --apply, remove it.",
|
|
649
|
+
output: "the report without its plan",
|
|
650
|
+
flags: FLAGS,
|
|
651
|
+
examples: ["--apply --ceiling"],
|
|
652
|
+
text: (result) => result.text,
|
|
653
|
+
run: async (input) => {
|
|
654
|
+
const options = retentionOptions(input, { env })
|
|
655
|
+
const report = await runRetention(options, deps)
|
|
656
|
+
const { plan: _plan, ...brief } = report
|
|
657
|
+
return Object.defineProperty(brief, "text", { value: summary(report, options) })
|
|
658
|
+
},
|
|
659
|
+
}),
|
|
660
|
+
})
|
|
661
|
+
return runCli(cli, argv, { stdout: io.stdout, stderr: io.stderr })
|
|
662
|
+
}
|