agent-control-plane 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +589 -0
- package/SKILL.md +149 -0
- package/assets/workflow-catalog.json +57 -0
- package/bin/audit-issue-routing.sh +74 -0
- package/bin/issue-resource-class.sh +58 -0
- package/bin/label-follow-up-issues.sh +114 -0
- package/bin/pr-risk.sh +532 -0
- package/bin/sync-pr-labels.sh +112 -0
- package/hooks/heartbeat-hooks.sh +573 -0
- package/hooks/issue-reconcile-hooks.sh +217 -0
- package/hooks/pr-reconcile-hooks.sh +225 -0
- package/npm/bin/agent-control-plane.js +1984 -0
- package/npm/public-bin/agent-control-plane +3 -0
- package/package.json +61 -0
- package/tools/bin/agent-cleanup-worktree +247 -0
- package/tools/bin/agent-github-update-labels +66 -0
- package/tools/bin/agent-init-worktree +216 -0
- package/tools/bin/agent-project-archive-run +52 -0
- package/tools/bin/agent-project-capture-worker +46 -0
- package/tools/bin/agent-project-catch-up-merged-prs +137 -0
- package/tools/bin/agent-project-cleanup-session +244 -0
- package/tools/bin/agent-project-detached-launch +107 -0
- package/tools/bin/agent-project-heartbeat-loop +2347 -0
- package/tools/bin/agent-project-open-issue-worktree +89 -0
- package/tools/bin/agent-project-open-pr-worktree +80 -0
- package/tools/bin/agent-project-publish-issue-pr +349 -0
- package/tools/bin/agent-project-reconcile-issue-session +1128 -0
- package/tools/bin/agent-project-reconcile-pr-session +1005 -0
- package/tools/bin/agent-project-retry-state +147 -0
- package/tools/bin/agent-project-run-claude-session +657 -0
- package/tools/bin/agent-project-run-codex-resilient +718 -0
- package/tools/bin/agent-project-run-codex-session +316 -0
- package/tools/bin/agent-project-run-kilo-session +27 -0
- package/tools/bin/agent-project-run-openclaw-session +984 -0
- package/tools/bin/agent-project-run-opencode-session +27 -0
- package/tools/bin/agent-project-sync-anchor-repo +128 -0
- package/tools/bin/agent-project-worker-status +143 -0
- package/tools/bin/audit-agent-worktrees.sh +310 -0
- package/tools/bin/audit-issue-routing.sh +11 -0
- package/tools/bin/audit-retained-layout.sh +58 -0
- package/tools/bin/audit-retained-overlap.sh +135 -0
- package/tools/bin/audit-retained-worktrees.sh +228 -0
- package/tools/bin/branch-verification-guard.sh +351 -0
- package/tools/bin/capture-worker.sh +18 -0
- package/tools/bin/check-skill-contracts.sh +324 -0
- package/tools/bin/cleanup-worktree.sh +44 -0
- package/tools/bin/codex-quota +31 -0
- package/tools/bin/create-follow-up-issue.sh +114 -0
- package/tools/bin/dashboard-launchd-bootstrap.sh +38 -0
- package/tools/bin/flow-config-lib.sh +2127 -0
- package/tools/bin/flow-resident-worker-lib.sh +683 -0
- package/tools/bin/flow-runtime-doctor.sh +97 -0
- package/tools/bin/flow-shell-lib.sh +266 -0
- package/tools/bin/heartbeat-recovery-preflight.sh +106 -0
- package/tools/bin/heartbeat-safe-auto.sh +551 -0
- package/tools/bin/install-dashboard-launchd.sh +152 -0
- package/tools/bin/install-project-launchd.sh +219 -0
- package/tools/bin/issue-publish-scope-guard.sh +242 -0
- package/tools/bin/issue-requires-local-workspace-install.sh +31 -0
- package/tools/bin/issue-resource-class.sh +12 -0
- package/tools/bin/kick-scheduler.sh +75 -0
- package/tools/bin/label-follow-up-issues.sh +14 -0
- package/tools/bin/new-pr-worktree.sh +50 -0
- package/tools/bin/new-worktree.sh +49 -0
- package/tools/bin/pr-risk.sh +12 -0
- package/tools/bin/prepare-worktree.sh +140 -0
- package/tools/bin/profile-activate.sh +109 -0
- package/tools/bin/profile-adopt.sh +219 -0
- package/tools/bin/profile-smoke.sh +461 -0
- package/tools/bin/project-init.sh +189 -0
- package/tools/bin/project-launchd-bootstrap.sh +54 -0
- package/tools/bin/project-remove.sh +155 -0
- package/tools/bin/project-runtime-supervisor.sh +56 -0
- package/tools/bin/project-runtimectl.sh +586 -0
- package/tools/bin/provider-cooldown-state.sh +166 -0
- package/tools/bin/publish-issue-worker.sh +31 -0
- package/tools/bin/reconcile-issue-worker.sh +34 -0
- package/tools/bin/reconcile-pr-worker.sh +34 -0
- package/tools/bin/record-verification.sh +71 -0
- package/tools/bin/render-architecture-infographics.sh +110 -0
- package/tools/bin/render-dashboard-demo-media.sh +333 -0
- package/tools/bin/render-dashboard-snapshot.py +16 -0
- package/tools/bin/render-flow-config.sh +86 -0
- package/tools/bin/retry-state.sh +31 -0
- package/tools/bin/reuse-issue-worktree.sh +75 -0
- package/tools/bin/run-codex-bypass.sh +3 -0
- package/tools/bin/run-codex-safe.sh +3 -0
- package/tools/bin/run-codex-task.sh +231 -0
- package/tools/bin/scaffold-profile.sh +374 -0
- package/tools/bin/serve-dashboard.sh +5 -0
- package/tools/bin/split-retained-slice.sh +124 -0
- package/tools/bin/start-issue-worker.sh +796 -0
- package/tools/bin/start-pr-fix-worker.sh +458 -0
- package/tools/bin/start-pr-merge-repair-worker.sh +8 -0
- package/tools/bin/start-pr-review-worker.sh +227 -0
- package/tools/bin/start-resident-issue-loop.sh +908 -0
- package/tools/bin/sync-agent-repo.sh +52 -0
- package/tools/bin/sync-dependency-baseline.sh +247 -0
- package/tools/bin/sync-pr-labels.sh +12 -0
- package/tools/bin/sync-recurring-issue-checklist.sh +274 -0
- package/tools/bin/sync-shared-agent-home.sh +214 -0
- package/tools/bin/sync-vscode-workspace.sh +157 -0
- package/tools/bin/test-smoke.sh +63 -0
- package/tools/bin/uninstall-project-launchd.sh +55 -0
- package/tools/bin/update-github-labels.sh +14 -0
- package/tools/bin/worker-status.sh +19 -0
- package/tools/bin/workflow-catalog.sh +77 -0
- package/tools/dashboard/app.js +286 -0
- package/tools/dashboard/dashboard_snapshot.py +466 -0
- package/tools/dashboard/index.html +41 -0
- package/tools/dashboard/server.py +64 -0
- package/tools/dashboard/styles.css +351 -0
- package/tools/templates/issue-prompt-template.md +109 -0
- package/tools/templates/pr-fix-template.md +120 -0
- package/tools/templates/pr-merge-repair-template.md +91 -0
- package/tools/templates/pr-review-template.md +62 -0
- package/tools/templates/scheduled-issue-prompt-template.md +62 -0
- package/tools/tests/test-agent-control-plane-npm-cli.sh +279 -0
- package/tools/tests/test-agent-github-update-labels-falls-back-to-repository-id.sh +56 -0
- package/tools/tests/test-agent-project-claude-session-wrapper-clears-stale-sandbox-artifacts.sh +89 -0
- package/tools/tests/test-agent-project-claude-session-wrapper-does-not-retry-provider-quota.sh +82 -0
- package/tools/tests/test-agent-project-claude-session-wrapper-retries-transient-failures.sh +90 -0
- package/tools/tests/test-agent-project-claude-session-wrapper-times-out.sh +73 -0
- package/tools/tests/test-agent-project-claude-session-wrapper.sh +103 -0
- package/tools/tests/test-agent-project-cleanup-session-orphan-fallback.sh +90 -0
- package/tools/tests/test-agent-project-cleanup-session-skip-worktree-cleanup.sh +90 -0
- package/tools/tests/test-agent-project-codex-live-thread-persist.sh +76 -0
- package/tools/tests/test-agent-project-codex-recovery.sh +731 -0
- package/tools/tests/test-agent-project-codex-session-wrapper-clears-stale-sandbox-artifacts.sh +105 -0
- package/tools/tests/test-agent-project-codex-session-wrapper.sh +97 -0
- package/tools/tests/test-agent-project-open-pr-worktree-config-prefix.sh +81 -0
- package/tools/tests/test-agent-project-openclaw-session-wrapper-clears-stale-sandbox-artifacts.sh +109 -0
- package/tools/tests/test-agent-project-openclaw-session-wrapper-infers-blocked-result-contract.sh +89 -0
- package/tools/tests/test-agent-project-openclaw-session-wrapper-recovers-literal-env-artifacts.sh +113 -0
- package/tools/tests/test-agent-project-openclaw-session-wrapper-recovers-version-mismatch.sh +135 -0
- package/tools/tests/test-agent-project-openclaw-session-wrapper-resident.sh +179 -0
- package/tools/tests/test-agent-project-openclaw-session-wrapper-reuses-existing-agent-after-add-race.sh +119 -0
- package/tools/tests/test-agent-project-openclaw-session-wrapper-terminates-rate-limit-hang.sh +91 -0
- package/tools/tests/test-agent-project-openclaw-session-wrapper.sh +117 -0
- package/tools/tests/test-agent-project-publish-issue-pr-prunes-stale-worktree-entry.sh +148 -0
- package/tools/tests/test-agent-project-publish-issue-pr-reads-archived-session.sh +146 -0
- package/tools/tests/test-agent-project-publish-issue-pr-recovers-final-head.sh +145 -0
- package/tools/tests/test-agent-project-publish-issue-pr-reuses-existing-worktree.sh +147 -0
- package/tools/tests/test-agent-project-reconcile-failure-reason.sh +456 -0
- package/tools/tests/test-agent-project-reconcile-issue-archived-session-fallback.sh +96 -0
- package/tools/tests/test-agent-project-reconcile-issue-before-blocked.sh +90 -0
- package/tools/tests/test-agent-project-reconcile-issue-host-verification-recovery-uses-recovered-worktree.sh +212 -0
- package/tools/tests/test-agent-project-reconcile-issue-host-verification-recovery.sh +207 -0
- package/tools/tests/test-agent-project-reconcile-issue-provider-quota-schedules-provider-cooldown.sh +101 -0
- package/tools/tests/test-agent-project-reconcile-issue-session-backfills-lane-metadata-from-worker-key.sh +113 -0
- package/tools/tests/test-agent-project-reconcile-issue-session-clears-stale-failed-summary.sh +117 -0
- package/tools/tests/test-agent-project-reconcile-issue-session-initializes-shared-agent-home.sh +55 -0
- package/tools/tests/test-agent-project-reconcile-issue-session-normalizes-runner-state.sh +125 -0
- package/tools/tests/test-agent-project-reconcile-issue-session-records-invalid-contract-summary.sh +118 -0
- package/tools/tests/test-agent-project-reconcile-issue-session-skips-duplicate-blocked-comment.sh +144 -0
- package/tools/tests/test-agent-project-reconcile-issue-session-standardizes-no-commits-blocker.sh +145 -0
- package/tools/tests/test-agent-project-reconcile-issue-session-synthesizes-blocked-comment.sh +139 -0
- package/tools/tests/test-agent-project-reconcile-pr-blocked-host-recovery.sh +242 -0
- package/tools/tests/test-agent-project-reconcile-pr-guard-blocked-no-commit.sh +142 -0
- package/tools/tests/test-agent-project-reconcile-pr-provider-quota-schedules-provider-cooldown.sh +106 -0
- package/tools/tests/test-agent-project-reconcile-pr-session-initializes-shared-agent-home.sh +66 -0
- package/tools/tests/test-agent-project-reconcile-pr-updated-branch-noop.sh +129 -0
- package/tools/tests/test-audit-agent-worktrees-active-launch-skips-git-inspection.sh +69 -0
- package/tools/tests/test-audit-agent-worktrees-broken-worktree.sh +43 -0
- package/tools/tests/test-audit-agent-worktrees-pending-launch-owner.sh +46 -0
- package/tools/tests/test-audit-agent-worktrees-unreconciled-owner.sh +79 -0
- package/tools/tests/test-audit-issue-routing-managed-branch-globs.sh +56 -0
- package/tools/tests/test-branch-verification-guard-generated-artifacts.sh +72 -0
- package/tools/tests/test-branch-verification-guard-targeted-coverage.sh +125 -0
- package/tools/tests/test-codex-quota-manager-failure-driven-rotation.sh +178 -0
- package/tools/tests/test-codex-quota-wrapper.sh +37 -0
- package/tools/tests/test-contribution-docs.sh +18 -0
- package/tools/tests/test-control-plane-dashboard-runtime-smoke.sh +343 -0
- package/tools/tests/test-create-follow-up-issue.sh +73 -0
- package/tools/tests/test-dashboard-launchd-bootstrap.sh +55 -0
- package/tools/tests/test-flow-export-execution-env-exports-repo-id.sh +30 -0
- package/tools/tests/test-flow-export-github-cli-auth-env-prefers-git-credential.sh +48 -0
- package/tools/tests/test-flow-github-api-repo-fallback-preserves-input.sh +85 -0
- package/tools/tests/test-flow-github-api-repo-prefers-explicit-repository-id.sh +60 -0
- package/tools/tests/test-flow-github-issue-list-falls-back-to-repository-id.sh +64 -0
- package/tools/tests/test-flow-github-pr-list-falls-back-to-repository-id.sh +77 -0
- package/tools/tests/test-flow-resident-can-reuse-does-not-leak-metadata.sh +52 -0
- package/tools/tests/test-flow-resident-reap-stale-controllers.sh +63 -0
- package/tools/tests/test-flow-resolve-codex-quota-tools.sh +104 -0
- package/tools/tests/test-flow-runtime-doctor-profile-selection.sh +27 -0
- package/tools/tests/test-heartbeat-codex-pr-linked-issue-exclusion.sh +79 -0
- package/tools/tests/test-heartbeat-hooks-enqueue-resident-issue-for-idle-controller.sh +115 -0
- package/tools/tests/test-heartbeat-hooks-enqueue-resident-issue-for-live-lane-controller.sh +117 -0
- package/tools/tests/test-heartbeat-hooks-start-resident-issue-loop-claude.sh +96 -0
- package/tools/tests/test-heartbeat-hooks-start-resident-issue-loop-codex.sh +96 -0
- package/tools/tests/test-heartbeat-hooks-start-resident-issue-loop.sh +96 -0
- package/tools/tests/test-heartbeat-loop-auth-wait-does-not-consume-capacity.sh +170 -0
- package/tools/tests/test-heartbeat-loop-blocked-recovery-lane.sh +201 -0
- package/tools/tests/test-heartbeat-loop-blocked-recovery-vs-pr-reservation.sh +201 -0
- package/tools/tests/test-heartbeat-loop-idle-resident-controller-does-not-block-launches.sh +160 -0
- package/tools/tests/test-heartbeat-loop-pr-launch-dedup.sh +133 -0
- package/tools/tests/test-heartbeat-loop-provider-cooldown-suppresses-launches.sh +157 -0
- package/tools/tests/test-heartbeat-loop-reaps-stale-resident-controller.sh +181 -0
- package/tools/tests/test-heartbeat-loop-waiting-provider-resident-controller-does-not-block-launches.sh +160 -0
- package/tools/tests/test-heartbeat-ready-issues-blocked-recovery.sh +134 -0
- package/tools/tests/test-heartbeat-safe-auto-dynamic-concurrency.sh +162 -0
- package/tools/tests/test-heartbeat-safe-auto-no-tmux-sessions.sh +136 -0
- package/tools/tests/test-heartbeat-safe-auto-openclaw-skips-codex-quota.sh +139 -0
- package/tools/tests/test-heartbeat-safe-auto-quota-health-signal.sh +119 -0
- package/tools/tests/test-heartbeat-safe-auto-stale-shared-loop-pid-does-not-skip.sh +140 -0
- package/tools/tests/test-heartbeat-safe-auto-static-capacity-without-quota-cache.sh +142 -0
- package/tools/tests/test-heartbeat-safe-auto-zero-healthy-pools.sh +141 -0
- package/tools/tests/test-heartbeat-sync-issue-labels-empty-schedule.sh +65 -0
- package/tools/tests/test-heartbeat-sync-open-agent-prs-terminal-clears-running.sh +179 -0
- package/tools/tests/test-install-dashboard-launchd.sh +78 -0
- package/tools/tests/test-install-project-launchd-adds-tool-paths.sh +87 -0
- package/tools/tests/test-install-project-launchd.sh +110 -0
- package/tools/tests/test-issue-local-workspace-install-policy.sh +81 -0
- package/tools/tests/test-issue-publish-scope-guard-docs-signal.sh +70 -0
- package/tools/tests/test-issue-reconcile-hooks-success-clears-blocked.sh +36 -0
- package/tools/tests/test-kick-scheduler-requires-explicit-profile.sh +47 -0
- package/tools/tests/test-label-follow-up-issues-falls-back-to-repository-id.sh +132 -0
- package/tools/tests/test-manual-operator-entrypoints-require-explicit-profile.sh +64 -0
- package/tools/tests/test-package-funding-metadata.sh +21 -0
- package/tools/tests/test-package-public-metadata.sh +62 -0
- package/tools/tests/test-placeholder-worker-adapters.sh +38 -0
- package/tools/tests/test-pr-reconcile-hooks-refreshes-recurring-issue-checklist.sh +110 -0
- package/tools/tests/test-pr-risk-cohesive-mobile-locale-scope.sh +70 -0
- package/tools/tests/test-pr-risk-fix-label-semantics.sh +114 -0
- package/tools/tests/test-pr-risk-local-first-no-checks.sh +70 -0
- package/tools/tests/test-prepare-worktree-simple-repo-baseline.sh +67 -0
- package/tools/tests/test-profile-activate.sh +33 -0
- package/tools/tests/test-profile-adopt-allow-missing-repo.sh +68 -0
- package/tools/tests/test-profile-adopt-skip-workspace-sync-missing-file.sh +61 -0
- package/tools/tests/test-profile-adopt-syncs-anchor-and-workspace.sh +90 -0
- package/tools/tests/test-profile-smoke-collision.sh +44 -0
- package/tools/tests/test-profile-smoke-invalid-claude-config.sh +31 -0
- package/tools/tests/test-profile-smoke-invalid-provider-pool.sh +68 -0
- package/tools/tests/test-profile-smoke-repo-slug-mismatch.sh +36 -0
- package/tools/tests/test-profile-smoke.sh +45 -0
- package/tools/tests/test-project-init-force-and-skip-sync.sh +61 -0
- package/tools/tests/test-project-init-repo-slug-mismatch.sh +29 -0
- package/tools/tests/test-project-init.sh +66 -0
- package/tools/tests/test-project-launchd-bootstrap.sh +66 -0
- package/tools/tests/test-project-remove.sh +150 -0
- package/tools/tests/test-project-runtime-supervisor.sh +47 -0
- package/tools/tests/test-project-runtimectl-launchd.sh +115 -0
- package/tools/tests/test-project-runtimectl-missing-profile.sh +54 -0
- package/tools/tests/test-project-runtimectl-start-falls-back-to-bootstrap.sh +108 -0
- package/tools/tests/test-project-runtimectl-status-reports-supervisor-as-heartbeat-parent.sh +95 -0
- package/tools/tests/test-project-runtimectl-status-supervisor-running.sh +59 -0
- package/tools/tests/test-project-runtimectl-stop-cancels-pending-kick.sh +85 -0
- package/tools/tests/test-project-runtimectl-stop-clears-running-labels.sh +78 -0
- package/tools/tests/test-project-runtimectl.sh +212 -0
- package/tools/tests/test-provider-cooldown-state-prefers-runtime-worker-context.sh +39 -0
- package/tools/tests/test-provider-cooldown-state.sh +59 -0
- package/tools/tests/test-public-repo-docs.sh +159 -0
- package/tools/tests/test-reconcile-pr-worker-acp-config-routing.sh +75 -0
- package/tools/tests/test-render-dashboard-snapshot.sh +149 -0
- package/tools/tests/test-render-flow-config-demo-profile.sh +36 -0
- package/tools/tests/test-render-flow-config-provider-pool-fallback.sh +81 -0
- package/tools/tests/test-render-flow-config.sh +52 -0
- package/tools/tests/test-run-codex-task-claude-routing.sh +125 -0
- package/tools/tests/test-run-codex-task-codex-resident-routing.sh +108 -0
- package/tools/tests/test-run-codex-task-kilo-routing.sh +98 -0
- package/tools/tests/test-run-codex-task-openclaw-resident-routing.sh +117 -0
- package/tools/tests/test-run-codex-task-openclaw-routing.sh +113 -0
- package/tools/tests/test-run-codex-task-opencode-routing.sh +98 -0
- package/tools/tests/test-run-codex-task-provider-pool-fallback-routing.sh +146 -0
- package/tools/tests/test-scaffold-profile.sh +108 -0
- package/tools/tests/test-serve-dashboard.sh +93 -0
- package/tools/tests/test-start-issue-worker-blocked-context.sh +129 -0
- package/tools/tests/test-start-issue-worker-blocks-complete-recurring-checklist.sh +189 -0
- package/tools/tests/test-start-issue-worker-local-install-routing.sh +157 -0
- package/tools/tests/test-start-issue-worker-profile-template-routing.sh +149 -0
- package/tools/tests/test-start-issue-worker-recurring-resident-reuse-codex.sh +212 -0
- package/tools/tests/test-start-issue-worker-recurring-resident-reuse.sh +219 -0
- package/tools/tests/test-start-issue-worker-renders-verification-snippet.sh +155 -0
- package/tools/tests/test-start-issue-worker-resident-reuse-falls-back-to-new-worktree.sh +199 -0
- package/tools/tests/test-start-pr-fix-worker-host-blocker-context.sh +275 -0
- package/tools/tests/test-start-resident-issue-loop-adopts-next-recurring-issue.sh +185 -0
- package/tools/tests/test-start-resident-issue-loop-clears-pending-while-waiting-due.sh +152 -0
- package/tools/tests/test-start-resident-issue-loop-consumes-queued-lease.sh +186 -0
- package/tools/tests/test-start-resident-issue-loop-fails-over-provider-pool.sh +212 -0
- package/tools/tests/test-start-resident-issue-loop-immediate-cycles.sh +148 -0
- package/tools/tests/test-start-resident-issue-loop-waits-for-provider.sh +194 -0
- package/tools/tests/test-start-resident-issue-loop-waits-for-terminal-reconcile-status.sh +198 -0
- package/tools/tests/test-start-resident-issue-loop-yields-to-live-lane-controller.sh +145 -0
- package/tools/tests/test-sync-pr-labels-fix-lane-uses-repair-queued.sh +67 -0
- package/tools/tests/test-sync-recurring-issue-checklist-backfills-workflow-complete-blocker.sh +70 -0
- package/tools/tests/test-sync-recurring-issue-checklist.sh +95 -0
- package/tools/tests/test-sync-shared-agent-home-local-source-root.sh +66 -0
- package/tools/tests/test-sync-shared-agent-home-preserves-unrelated-workflow-catalog-skill.sh +47 -0
- package/tools/tests/test-test-smoke.sh +86 -0
- package/tools/tests/test-uninstall-project-launchd.sh +37 -0
- package/tools/tests/test-update-github-labels-prefers-sibling-helper.sh +49 -0
- package/tools/tests/test-workflow-catalog.sh +43 -0
- package/tools/vendor/codex-quota/LICENSE +21 -0
- package/tools/vendor/codex-quota/README.md +459 -0
- package/tools/vendor/codex-quota/codex-quota.js +261 -0
- package/tools/vendor/codex-quota/lib/claude-accounts.js +226 -0
- package/tools/vendor/codex-quota/lib/claude-oauth.js +174 -0
- package/tools/vendor/codex-quota/lib/claude-tokens.js +471 -0
- package/tools/vendor/codex-quota/lib/claude-usage.js +929 -0
- package/tools/vendor/codex-quota/lib/codex-accounts.js +205 -0
- package/tools/vendor/codex-quota/lib/codex-tokens.js +326 -0
- package/tools/vendor/codex-quota/lib/codex-usage.js +32 -0
- package/tools/vendor/codex-quota/lib/color.js +72 -0
- package/tools/vendor/codex-quota/lib/constants.js +57 -0
- package/tools/vendor/codex-quota/lib/container.js +143 -0
- package/tools/vendor/codex-quota/lib/display.js +1111 -0
- package/tools/vendor/codex-quota/lib/fs.js +63 -0
- package/tools/vendor/codex-quota/lib/handlers.js +2060 -0
- package/tools/vendor/codex-quota/lib/jwt.js +33 -0
- package/tools/vendor/codex-quota/lib/oauth.js +486 -0
- package/tools/vendor/codex-quota/lib/paths.js +34 -0
- package/tools/vendor/codex-quota/lib/prompts.js +44 -0
- package/tools/vendor/codex-quota/lib/sync.js +1438 -0
- package/tools/vendor/codex-quota/lib/token-match.js +96 -0
- package/tools/vendor/codex-quota-manager/scripts/auto-switch.sh +500 -0
- package/tools/vendor/codex-quota-manager/scripts/batch-add.sh +123 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
usage() {
|
|
5
|
+
cat <<'EOF'
|
|
6
|
+
Usage:
|
|
7
|
+
agent-project-catch-up-merged-prs --repo-slug <owner/repo> --state-root <path> --hook-file <path> [--limit <n>]
|
|
8
|
+
|
|
9
|
+
Catch up merge-cleanup for managed PRs that were merged manually after their
|
|
10
|
+
worker session had already been reconciled and cleaned up.
|
|
11
|
+
EOF
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
repo_slug=""
|
|
15
|
+
state_root=""
|
|
16
|
+
hook_file=""
|
|
17
|
+
limit="100"
|
|
18
|
+
|
|
19
|
+
while [[ $# -gt 0 ]]; do
|
|
20
|
+
case "$1" in
|
|
21
|
+
--repo-slug) repo_slug="${2:-}"; shift 2 ;;
|
|
22
|
+
--state-root) state_root="${2:-}"; shift 2 ;;
|
|
23
|
+
--hook-file) hook_file="${2:-}"; shift 2 ;;
|
|
24
|
+
--limit) limit="${2:-}"; shift 2 ;;
|
|
25
|
+
--help|-h) usage; exit 0 ;;
|
|
26
|
+
*) echo "Unknown argument: $1" >&2; usage >&2; exit 1 ;;
|
|
27
|
+
esac
|
|
28
|
+
done
|
|
29
|
+
|
|
30
|
+
if [[ -z "$repo_slug" || -z "$state_root" || -z "$hook_file" ]]; then
|
|
31
|
+
usage >&2
|
|
32
|
+
exit 1
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
if [[ ! -f "$hook_file" ]]; then
|
|
36
|
+
echo "missing hook file: $hook_file" >&2
|
|
37
|
+
exit 1
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# shellcheck source=/dev/null
|
|
41
|
+
source "$hook_file"
|
|
42
|
+
|
|
43
|
+
optional_hooks=(
|
|
44
|
+
pr_clear_retry
|
|
45
|
+
pr_cleanup_linked_issue_session
|
|
46
|
+
pr_cleanup_merged_residue
|
|
47
|
+
pr_linked_issue_should_close
|
|
48
|
+
pr_after_merged
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
for hook_name in "${optional_hooks[@]}"; do
|
|
52
|
+
if ! declare -F "$hook_name" >/dev/null 2>&1; then
|
|
53
|
+
eval "${hook_name}() { :; }"
|
|
54
|
+
fi
|
|
55
|
+
done
|
|
56
|
+
|
|
57
|
+
ledger_dir="${state_root}/merged-pr-catchup"
|
|
58
|
+
mkdir -p "$ledger_dir"
|
|
59
|
+
|
|
60
|
+
get_pr_risk_json() {
|
|
61
|
+
local pr_number="${1:?pr number required}"
|
|
62
|
+
if declare -F heartbeat_pr_risk_json >/dev/null 2>&1; then
|
|
63
|
+
heartbeat_pr_risk_json "$pr_number"
|
|
64
|
+
return 0
|
|
65
|
+
fi
|
|
66
|
+
if [[ -n "${ADAPTER_BIN_DIR:-}" && -x "${ADAPTER_BIN_DIR}/pr-risk.sh" ]]; then
|
|
67
|
+
"${ADAPTER_BIN_DIR}/pr-risk.sh" "$pr_number"
|
|
68
|
+
return 0
|
|
69
|
+
fi
|
|
70
|
+
echo "missing PR risk provider for catch-up" >&2
|
|
71
|
+
return 1
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
close_issue_if_needed() {
|
|
75
|
+
local pr_number="${1:?pr number required}"
|
|
76
|
+
local issue_id="${2:-}"
|
|
77
|
+
[[ -n "$issue_id" ]] || return 0
|
|
78
|
+
|
|
79
|
+
local should_close="yes"
|
|
80
|
+
should_close="$(pr_linked_issue_should_close "$issue_id" || printf 'yes\n')"
|
|
81
|
+
if [[ "$should_close" != "yes" ]]; then
|
|
82
|
+
return 0
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
pr_cleanup_linked_issue_session "$issue_id" || true
|
|
86
|
+
|
|
87
|
+
local issue_state=""
|
|
88
|
+
issue_state="$(flow_github_issue_view_json "$repo_slug" "$issue_id" 2>/dev/null | jq -r '.state // empty' || true)"
|
|
89
|
+
if [[ "$issue_state" == "OPEN" ]]; then
|
|
90
|
+
flow_github_issue_close "$repo_slug" "$issue_id" "Closed automatically after PR #${pr_number} merged." >/dev/null 2>&1 || true
|
|
91
|
+
printf 'CATCHUP_CLOSED_ISSUE=%s\n' "$issue_id"
|
|
92
|
+
fi
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
merged_prs_json="$(flow_github_pr_list_json "$repo_slug" merged "$limit")"
|
|
96
|
+
|
|
97
|
+
while IFS= read -r pr_number; do
|
|
98
|
+
[[ -n "$pr_number" ]] || continue
|
|
99
|
+
|
|
100
|
+
ledger_file="${ledger_dir}/${pr_number}.env"
|
|
101
|
+
if [[ -f "$ledger_file" ]]; then
|
|
102
|
+
continue
|
|
103
|
+
fi
|
|
104
|
+
|
|
105
|
+
risk_json="$(get_pr_risk_json "$pr_number" 2>/dev/null || true)"
|
|
106
|
+
if [[ -z "$risk_json" ]]; then
|
|
107
|
+
continue
|
|
108
|
+
fi
|
|
109
|
+
|
|
110
|
+
is_managed="$(jq -r '.isManagedByAgent // .isAgentBranch // false' <<<"$risk_json" 2>/dev/null || printf 'false\n')"
|
|
111
|
+
if [[ "$is_managed" != "true" ]]; then
|
|
112
|
+
continue
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
linked_issue_id="$(jq -r '.linkedIssueId // empty' <<<"$risk_json" 2>/dev/null || true)"
|
|
116
|
+
merged_at="$(jq -r --arg pr "$pr_number" 'map(select((.number | tostring) == $pr)) | .[0].mergedAt // ""' <<<"$merged_prs_json")"
|
|
117
|
+
|
|
118
|
+
PR_NUMBER="$pr_number" pr_clear_retry || true
|
|
119
|
+
close_issue_if_needed "$pr_number" "$linked_issue_id"
|
|
120
|
+
if ! PR_NUMBER="$pr_number" pr_after_merged "$pr_number"; then
|
|
121
|
+
printf 'CATCHUP_FAILED_PR=%s\n' "$pr_number" >&2
|
|
122
|
+
continue
|
|
123
|
+
fi
|
|
124
|
+
if ! PR_NUMBER="$pr_number" pr_cleanup_merged_residue "$pr_number"; then
|
|
125
|
+
printf 'CATCHUP_FAILED_RESIDUE=%s\n' "$pr_number" >&2
|
|
126
|
+
continue
|
|
127
|
+
fi
|
|
128
|
+
|
|
129
|
+
{
|
|
130
|
+
printf 'PR_NUMBER=%s\n' "$pr_number"
|
|
131
|
+
printf 'ISSUE_ID=%s\n' "$linked_issue_id"
|
|
132
|
+
printf 'MERGED_AT=%s\n' "$merged_at"
|
|
133
|
+
printf 'PROCESSED_AT=%s\n' "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
|
|
134
|
+
} >"$ledger_file"
|
|
135
|
+
|
|
136
|
+
printf 'CATCHUP_MERGED_PR=%s\n' "$pr_number"
|
|
137
|
+
done < <(jq -r 'sort_by(.mergedAt) | reverse | .[].number' <<<"$merged_prs_json")
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
usage() {
|
|
5
|
+
cat <<'EOF'
|
|
6
|
+
Usage:
|
|
7
|
+
agent-project-cleanup-session --repo-root <path> [--runs-root <path> --history-root <path> --session <id>] [--worktree <path>] [--mode generic|issue|pr] [--remote <name>] [--remove-file <path>] [--keep-remote] [--allow-unmerged] [--skip-worktree-cleanup]
|
|
8
|
+
|
|
9
|
+
Cleanup a project-lane worktree/branch using shared agent helpers, then archive
|
|
10
|
+
the session run directory when one is provided.
|
|
11
|
+
EOF
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
shared_agent_home="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
15
|
+
repo_root="${AGENT_PROJECT_REPO_ROOT:-}"
|
|
16
|
+
runs_root="${AGENT_PROJECT_RUNS_ROOT:-}"
|
|
17
|
+
history_root="${AGENT_PROJECT_HISTORY_ROOT:-}"
|
|
18
|
+
session=""
|
|
19
|
+
worktree_path=""
|
|
20
|
+
mode="generic"
|
|
21
|
+
remote_name="origin"
|
|
22
|
+
remove_file=""
|
|
23
|
+
keep_remote="auto"
|
|
24
|
+
allow_unmerged="auto"
|
|
25
|
+
merged_base=""
|
|
26
|
+
skip_worktree_cleanup="false"
|
|
27
|
+
|
|
28
|
+
while [[ $# -gt 0 ]]; do
|
|
29
|
+
case "$1" in
|
|
30
|
+
--repo-root) repo_root="${2:-}"; shift 2 ;;
|
|
31
|
+
--runs-root) runs_root="${2:-}"; shift 2 ;;
|
|
32
|
+
--history-root) history_root="${2:-}"; shift 2 ;;
|
|
33
|
+
--session) session="${2:-}"; shift 2 ;;
|
|
34
|
+
--worktree) worktree_path="${2:-}"; shift 2 ;;
|
|
35
|
+
--mode) mode="${2:-}"; shift 2 ;;
|
|
36
|
+
--remote) remote_name="${2:-}"; shift 2 ;;
|
|
37
|
+
--remove-file) remove_file="${2:-}"; shift 2 ;;
|
|
38
|
+
--merged-base) merged_base="${2:-}"; shift 2 ;;
|
|
39
|
+
--keep-remote) keep_remote="true"; shift ;;
|
|
40
|
+
--allow-unmerged) allow_unmerged="true"; shift ;;
|
|
41
|
+
--skip-worktree-cleanup) skip_worktree_cleanup="true"; shift ;;
|
|
42
|
+
--help|-h) usage; exit 0 ;;
|
|
43
|
+
*) echo "Unknown argument: $1" >&2; usage >&2; exit 1 ;;
|
|
44
|
+
esac
|
|
45
|
+
done
|
|
46
|
+
|
|
47
|
+
if [[ -z "$repo_root" ]]; then
|
|
48
|
+
echo "--repo-root is required" >&2
|
|
49
|
+
usage >&2
|
|
50
|
+
exit 1
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
case "$mode" in
|
|
54
|
+
generic|issue|pr) ;;
|
|
55
|
+
*)
|
|
56
|
+
echo "--mode must be generic, issue, or pr" >&2
|
|
57
|
+
exit 1
|
|
58
|
+
;;
|
|
59
|
+
esac
|
|
60
|
+
|
|
61
|
+
if [[ -z "$worktree_path" && -z "$session" ]]; then
|
|
62
|
+
echo "Provide at least one of --worktree or --session" >&2
|
|
63
|
+
usage >&2
|
|
64
|
+
exit 1
|
|
65
|
+
fi
|
|
66
|
+
|
|
67
|
+
if [[ -n "$session" && ( -z "$runs_root" || -z "$history_root" ) ]]; then
|
|
68
|
+
echo "--runs-root and --history-root are required when --session is set" >&2
|
|
69
|
+
usage >&2
|
|
70
|
+
exit 1
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
if [[ "$keep_remote" == "auto" ]]; then
|
|
74
|
+
case "$mode" in
|
|
75
|
+
issue) keep_remote="true" ;;
|
|
76
|
+
*) keep_remote="false" ;;
|
|
77
|
+
esac
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
if [[ "$allow_unmerged" == "auto" ]]; then
|
|
81
|
+
case "$mode" in
|
|
82
|
+
issue|pr) allow_unmerged="true" ;;
|
|
83
|
+
*) allow_unmerged="false" ;;
|
|
84
|
+
esac
|
|
85
|
+
fi
|
|
86
|
+
|
|
87
|
+
meta_file=""
|
|
88
|
+
branch_name=""
|
|
89
|
+
result_file=""
|
|
90
|
+
cleanup_warning=""
|
|
91
|
+
cleanup_status="0"
|
|
92
|
+
cleanup_error=""
|
|
93
|
+
cleanup_mode="noop"
|
|
94
|
+
orphan_fallback_used="false"
|
|
95
|
+
|
|
96
|
+
if [[ -n "$session" ]]; then
|
|
97
|
+
meta_file="${runs_root}/${session}/run.env"
|
|
98
|
+
if [[ -f "$meta_file" ]]; then
|
|
99
|
+
set -a
|
|
100
|
+
# shellcheck source=/dev/null
|
|
101
|
+
source "$meta_file"
|
|
102
|
+
set +a
|
|
103
|
+
branch_name="${BRANCH:-}"
|
|
104
|
+
result_file="${RESULT_FILE:-}"
|
|
105
|
+
if [[ -z "$worktree_path" ]]; then
|
|
106
|
+
worktree_path="${WORKTREE:-}"
|
|
107
|
+
fi
|
|
108
|
+
fi
|
|
109
|
+
fi
|
|
110
|
+
|
|
111
|
+
if [[ -z "$remove_file" ]]; then
|
|
112
|
+
remove_file="$result_file"
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
cleanup_tool="${shared_agent_home}/tools/bin/agent-cleanup-worktree"
|
|
116
|
+
archive_tool="${shared_agent_home}/tools/bin/agent-project-archive-run"
|
|
117
|
+
|
|
118
|
+
canonicalize_existing_dir() {
|
|
119
|
+
local target="${1:-}"
|
|
120
|
+
[[ -n "$target" && -d "$target" ]] || return 1
|
|
121
|
+
(
|
|
122
|
+
cd "$target"
|
|
123
|
+
pwd -P
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
path_is_within_root() {
|
|
128
|
+
local target="${1:-}"
|
|
129
|
+
local root="${2:-}"
|
|
130
|
+
local target_canonical=""
|
|
131
|
+
local root_canonical=""
|
|
132
|
+
|
|
133
|
+
target_canonical="$(canonicalize_existing_dir "$target" || true)"
|
|
134
|
+
root_canonical="$(canonicalize_existing_dir "$root" || true)"
|
|
135
|
+
[[ -n "$target_canonical" && -n "$root_canonical" ]] || return 1
|
|
136
|
+
[[ "$target_canonical" == "$root_canonical" || "$target_canonical" == "$root_canonical"/* ]]
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
cleanup_with_branch_tool() {
|
|
140
|
+
local include_path="${1:-yes}"
|
|
141
|
+
local -a cleanup_args
|
|
142
|
+
|
|
143
|
+
cleanup_args=(--branch "$branch_name")
|
|
144
|
+
if [[ -n "$remote_name" ]]; then
|
|
145
|
+
cleanup_args+=(--remote "$remote_name")
|
|
146
|
+
fi
|
|
147
|
+
if [[ -n "$merged_base" ]]; then
|
|
148
|
+
cleanup_args+=(--merged-base "$merged_base")
|
|
149
|
+
fi
|
|
150
|
+
if [[ "$include_path" == "yes" && -n "$worktree_path" && -d "$worktree_path" ]]; then
|
|
151
|
+
cleanup_args+=(--path "$worktree_path")
|
|
152
|
+
fi
|
|
153
|
+
if [[ "$keep_remote" == "true" ]]; then
|
|
154
|
+
cleanup_args+=(--keep-remote)
|
|
155
|
+
fi
|
|
156
|
+
if [[ "$allow_unmerged" == "true" ]]; then
|
|
157
|
+
cleanup_args+=(--allow-unmerged)
|
|
158
|
+
fi
|
|
159
|
+
|
|
160
|
+
(
|
|
161
|
+
cd "$repo_root"
|
|
162
|
+
"$cleanup_tool" "${cleanup_args[@]}"
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
cleanup_orphan_worktree_dir() {
|
|
167
|
+
local worktree_root="${AGENT_PROJECT_WORKTREE_ROOT:-${F_LOSNING_WORKTREE_ROOT:-}}"
|
|
168
|
+
local worktree_canonical=""
|
|
169
|
+
|
|
170
|
+
[[ -n "$worktree_path" && -d "$worktree_path" ]] || return 1
|
|
171
|
+
[[ ! -e "$worktree_path/.git" ]] || return 1
|
|
172
|
+
[[ -n "$worktree_root" ]] || return 1
|
|
173
|
+
path_is_within_root "$worktree_path" "$worktree_root" || return 1
|
|
174
|
+
|
|
175
|
+
worktree_canonical="$(canonicalize_existing_dir "$worktree_path" || true)"
|
|
176
|
+
[[ -n "$worktree_canonical" ]] || return 1
|
|
177
|
+
rm -rf "$worktree_canonical"
|
|
178
|
+
git -C "$repo_root" worktree prune >/dev/null 2>&1 || true
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if [[ "$skip_worktree_cleanup" != "true" && -n "$branch_name" ]]; then
|
|
182
|
+
if cleanup_output="$(cleanup_with_branch_tool yes 2>&1)"; then
|
|
183
|
+
cleanup_mode="branch"
|
|
184
|
+
else
|
|
185
|
+
cleanup_status="$?"
|
|
186
|
+
cleanup_error="${cleanup_output}"
|
|
187
|
+
if cleanup_orphan_worktree_dir; then
|
|
188
|
+
orphan_fallback_used="true"
|
|
189
|
+
if cleanup_retry_output="$(cleanup_with_branch_tool no 2>&1)"; then
|
|
190
|
+
cleanup_mode="orphan-worktree"
|
|
191
|
+
cleanup_status="0"
|
|
192
|
+
cleanup_warning="${cleanup_error}"
|
|
193
|
+
else
|
|
194
|
+
cleanup_status="$?"
|
|
195
|
+
cleanup_error="${cleanup_error}"$'\n'"${cleanup_retry_output}"
|
|
196
|
+
fi
|
|
197
|
+
fi
|
|
198
|
+
fi
|
|
199
|
+
elif [[ "$skip_worktree_cleanup" != "true" && -n "$worktree_path" ]] && git -C "$repo_root" worktree list --porcelain | rg -F -q "worktree $worktree_path"; then
|
|
200
|
+
git -C "$repo_root" worktree remove "$worktree_path" --force || true
|
|
201
|
+
git -C "$repo_root" worktree prune
|
|
202
|
+
cleanup_mode="worktree"
|
|
203
|
+
elif [[ "$skip_worktree_cleanup" == "true" ]]; then
|
|
204
|
+
cleanup_mode="archived-only"
|
|
205
|
+
fi
|
|
206
|
+
|
|
207
|
+
archive_output=""
|
|
208
|
+
if [[ -n "$session" ]]; then
|
|
209
|
+
archive_output="$(
|
|
210
|
+
"$archive_tool" \
|
|
211
|
+
--runs-root "$runs_root" \
|
|
212
|
+
--history-root "$history_root" \
|
|
213
|
+
--session "$session" \
|
|
214
|
+
--remove-file "${remove_file:-}"
|
|
215
|
+
)"
|
|
216
|
+
fi
|
|
217
|
+
|
|
218
|
+
if [[ "$cleanup_status" != "0" && -z "$session" ]]; then
|
|
219
|
+
[[ -n "$cleanup_error" ]] && printf '%s\n' "$cleanup_error" >&2
|
|
220
|
+
exit "$cleanup_status"
|
|
221
|
+
fi
|
|
222
|
+
|
|
223
|
+
printf 'SESSION=%s\n' "$session"
|
|
224
|
+
printf 'MODE=%s\n' "$mode"
|
|
225
|
+
printf 'WORKTREE=%s\n' "$worktree_path"
|
|
226
|
+
printf 'BRANCH=%s\n' "$branch_name"
|
|
227
|
+
printf 'KEEP_REMOTE=%s\n' "$keep_remote"
|
|
228
|
+
printf 'ALLOW_UNMERGED=%s\n' "$allow_unmerged"
|
|
229
|
+
printf 'SKIP_WORKTREE_CLEANUP=%s\n' "$skip_worktree_cleanup"
|
|
230
|
+
printf 'CLEANUP_MODE=%s\n' "$cleanup_mode"
|
|
231
|
+
printf 'ORPHAN_FALLBACK_USED=%s\n' "$orphan_fallback_used"
|
|
232
|
+
printf 'CLEANUP_STATUS=%s\n' "$cleanup_status"
|
|
233
|
+
if [[ -n "$meta_file" ]]; then
|
|
234
|
+
printf 'META_FILE=%s\n' "$meta_file"
|
|
235
|
+
fi
|
|
236
|
+
if [[ -n "$archive_output" ]]; then
|
|
237
|
+
printf '%s\n' "$archive_output"
|
|
238
|
+
fi
|
|
239
|
+
if [[ -n "$cleanup_warning" ]]; then
|
|
240
|
+
printf 'CLEANUP_WARNING=%s\n' "$(printf '%s' "$cleanup_warning" | tr '\n' ' ' | sed 's/ */ /g')"
|
|
241
|
+
fi
|
|
242
|
+
if [[ "$cleanup_status" != "0" && -n "$cleanup_error" ]]; then
|
|
243
|
+
printf 'CLEANUP_ERROR=%s\n' "$(printf '%s' "$cleanup_error" | tr '\n' ' ' | sed 's/ */ /g')"
|
|
244
|
+
fi
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
5
|
+
# shellcheck source=/dev/null
|
|
6
|
+
source "${SCRIPT_DIR}/flow-config-lib.sh"
|
|
7
|
+
CONFIG_YAML="$(resolve_flow_config_yaml "${BASH_SOURCE[0]}")"
|
|
8
|
+
STATE_ROOT="$(flow_resolve_state_root "${CONFIG_YAML}")"
|
|
9
|
+
|
|
10
|
+
usage() {
|
|
11
|
+
cat <<'EOF'
|
|
12
|
+
Usage:
|
|
13
|
+
agent-project-detached-launch [--pending-key <kind-id>] <name> <command> [args...]
|
|
14
|
+
|
|
15
|
+
Detach a worker bootstrap command from the current heartbeat process so the
|
|
16
|
+
heartbeat can keep launching additional workers without waiting for expensive
|
|
17
|
+
worktree/bootstrap/setup steps to finish.
|
|
18
|
+
EOF
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
pending_key=""
|
|
22
|
+
|
|
23
|
+
while [[ $# -gt 0 ]]; do
|
|
24
|
+
case "$1" in
|
|
25
|
+
--pending-key)
|
|
26
|
+
pending_key="${2:-}"
|
|
27
|
+
shift 2
|
|
28
|
+
;;
|
|
29
|
+
--help|-h)
|
|
30
|
+
usage
|
|
31
|
+
exit 0
|
|
32
|
+
;;
|
|
33
|
+
*)
|
|
34
|
+
break
|
|
35
|
+
;;
|
|
36
|
+
esac
|
|
37
|
+
done
|
|
38
|
+
|
|
39
|
+
if [[ $# -lt 2 ]]; then
|
|
40
|
+
usage >&2
|
|
41
|
+
exit 1
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
launch_name="${1:-}"
|
|
45
|
+
shift
|
|
46
|
+
|
|
47
|
+
if [[ -z "${launch_name}" ]]; then
|
|
48
|
+
usage >&2
|
|
49
|
+
exit 1
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
log_root="${ACP_LAUNCHER_LOG_ROOT:-${F_LOSNING_LAUNCHER_LOG_ROOT:-${STATE_ROOT}/launcher-logs}}"
|
|
53
|
+
mkdir -p "${log_root}"
|
|
54
|
+
|
|
55
|
+
safe_name="$(printf '%s' "${launch_name}" | tr '/[:space:]' '__' | tr -cd '[:alnum:]_.-')"
|
|
56
|
+
if [[ -z "${safe_name}" ]]; then
|
|
57
|
+
safe_name="launch"
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
timestamp="$(date -u +%Y%m%dT%H%M%SZ)"
|
|
61
|
+
log_file="${log_root}/${timestamp}-${safe_name}.log"
|
|
62
|
+
pending_file=""
|
|
63
|
+
pending_dir="${ACP_PENDING_LAUNCH_DIR:-${F_LOSNING_PENDING_LAUNCH_DIR:-${STATE_ROOT}/pending-launches}}"
|
|
64
|
+
if [[ -n "${pending_key}" ]]; then
|
|
65
|
+
mkdir -p "${pending_dir}"
|
|
66
|
+
pending_file="${pending_dir}/${pending_key}.pid"
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
python_bin="${PYTHON_BIN:-$(command -v python3 || true)}"
|
|
70
|
+
if [[ -z "${python_bin}" ]]; then
|
|
71
|
+
echo "python3 is required for detached launch" >&2
|
|
72
|
+
exit 1
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
launch_pid="$(
|
|
76
|
+
"${python_bin}" - "${log_file}" "${pending_file}" "$@" <<'PY'
|
|
77
|
+
import subprocess
|
|
78
|
+
import sys
|
|
79
|
+
from pathlib import Path
|
|
80
|
+
|
|
81
|
+
log_file = Path(sys.argv[1])
|
|
82
|
+
pending_file = sys.argv[2]
|
|
83
|
+
argv = sys.argv[3:]
|
|
84
|
+
|
|
85
|
+
with log_file.open("ab", buffering=0) as log_handle:
|
|
86
|
+
proc = subprocess.Popen(
|
|
87
|
+
argv,
|
|
88
|
+
stdin=subprocess.DEVNULL,
|
|
89
|
+
stdout=log_handle,
|
|
90
|
+
stderr=subprocess.STDOUT,
|
|
91
|
+
start_new_session=True,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
if pending_file:
|
|
95
|
+
Path(pending_file).write_text(f"{proc.pid}\n", encoding="utf-8")
|
|
96
|
+
|
|
97
|
+
print(proc.pid)
|
|
98
|
+
PY
|
|
99
|
+
)"
|
|
100
|
+
|
|
101
|
+
printf 'LAUNCH_MODE=detached\n'
|
|
102
|
+
printf 'LAUNCH_NAME=%s\n' "${launch_name}"
|
|
103
|
+
printf 'LAUNCH_PID=%s\n' "${launch_pid}"
|
|
104
|
+
printf 'LAUNCH_LOG=%s\n' "${log_file}"
|
|
105
|
+
if [[ -n "${pending_file}" ]]; then
|
|
106
|
+
printf 'LAUNCH_PENDING_FILE=%s\n' "${pending_file}"
|
|
107
|
+
fi
|