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,586 @@
|
|
|
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
|
+
|
|
8
|
+
usage() {
|
|
9
|
+
cat <<'EOF'
|
|
10
|
+
Usage:
|
|
11
|
+
project-runtimectl.sh <status|start|stop|restart> --profile-id <id> [options]
|
|
12
|
+
|
|
13
|
+
Manage runtime processes for one installed profile.
|
|
14
|
+
|
|
15
|
+
Options:
|
|
16
|
+
--profile-id <id> Profile id to manage
|
|
17
|
+
--delay-seconds <n> Delay for start via kick-scheduler (default: 0)
|
|
18
|
+
--wait-seconds <n> Wait for stop to settle before SIGKILL (default: 10)
|
|
19
|
+
--help Show this help
|
|
20
|
+
EOF
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
subcommand="${1:-}"
|
|
24
|
+
if [[ -z "${subcommand}" ]]; then
|
|
25
|
+
usage >&2
|
|
26
|
+
exit 64
|
|
27
|
+
fi
|
|
28
|
+
shift || true
|
|
29
|
+
|
|
30
|
+
profile_id_override=""
|
|
31
|
+
delay_seconds="0"
|
|
32
|
+
wait_seconds="10"
|
|
33
|
+
|
|
34
|
+
while [[ $# -gt 0 ]]; do
|
|
35
|
+
case "$1" in
|
|
36
|
+
--profile-id) profile_id_override="${2:-}"; shift 2 ;;
|
|
37
|
+
--delay-seconds) delay_seconds="${2:-}"; shift 2 ;;
|
|
38
|
+
--wait-seconds) wait_seconds="${2:-}"; shift 2 ;;
|
|
39
|
+
--help|-h) usage; exit 0 ;;
|
|
40
|
+
*) echo "Unknown argument: $1" >&2; usage >&2; exit 64 ;;
|
|
41
|
+
esac
|
|
42
|
+
done
|
|
43
|
+
|
|
44
|
+
case "${subcommand}" in
|
|
45
|
+
status|start|stop|restart) ;;
|
|
46
|
+
*)
|
|
47
|
+
echo "Unknown subcommand: ${subcommand}" >&2
|
|
48
|
+
usage >&2
|
|
49
|
+
exit 64
|
|
50
|
+
;;
|
|
51
|
+
esac
|
|
52
|
+
|
|
53
|
+
if [[ -n "${profile_id_override}" ]]; then
|
|
54
|
+
export ACP_PROJECT_ID="${profile_id_override}"
|
|
55
|
+
export AGENT_PROJECT_ID="${profile_id_override}"
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
FLOW_SKILL_DIR="$(resolve_flow_skill_dir "${BASH_SOURCE[0]}")"
|
|
59
|
+
if ! flow_require_explicit_profile_selection "${FLOW_SKILL_DIR}" "project-runtimectl.sh"; then
|
|
60
|
+
exit 64
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
CONFIG_YAML="$(resolve_flow_config_yaml "${BASH_SOURCE[0]}")"
|
|
64
|
+
if [[ ! -f "${CONFIG_YAML}" ]]; then
|
|
65
|
+
requested_profile_id="${profile_id_override:-${ACP_PROJECT_ID:-${AGENT_PROJECT_ID:-unknown}}}"
|
|
66
|
+
if [[ "${subcommand}" == "stop" ]]; then
|
|
67
|
+
printf 'ACTION=stop\n'
|
|
68
|
+
printf 'PROFILE_ID=%s\n' "${requested_profile_id}"
|
|
69
|
+
printf 'CONFIG_YAML=%s\n' "${CONFIG_YAML}"
|
|
70
|
+
printf 'REPO_SLUG=\n'
|
|
71
|
+
printf 'RUNS_ROOT=\n'
|
|
72
|
+
printf 'STATE_ROOT=\n'
|
|
73
|
+
printf 'RUNTIME_STATUS=not-installed\n'
|
|
74
|
+
printf 'LAUNCHD_STATE=n/a\n'
|
|
75
|
+
printf 'HEARTBEAT_PID=\n'
|
|
76
|
+
printf 'HEARTBEAT_PARENT_PID=\n'
|
|
77
|
+
printf 'SHARED_LOOP_PID=\n'
|
|
78
|
+
printf 'SUPERVISOR_PID=\n'
|
|
79
|
+
printf 'CONTROLLER_COUNT=0\n'
|
|
80
|
+
printf 'ACTIVE_TMUX_SESSION_COUNT=0\n'
|
|
81
|
+
printf 'PENDING_LAUNCH_COUNT=0\n'
|
|
82
|
+
printf 'CONTROLLER_PIDS=\n'
|
|
83
|
+
printf 'ACTIVE_TMUX_SESSIONS=\n'
|
|
84
|
+
printf 'PENDING_LAUNCH_PIDS=\n'
|
|
85
|
+
exit 0
|
|
86
|
+
fi
|
|
87
|
+
printf 'profile not installed: %s\n' "${requested_profile_id}" >&2
|
|
88
|
+
exit 66
|
|
89
|
+
fi
|
|
90
|
+
PROFILE_ID="$(flow_resolve_adapter_id "${CONFIG_YAML}")"
|
|
91
|
+
REPO_SLUG="$(flow_resolve_repo_slug "${CONFIG_YAML}")"
|
|
92
|
+
RUNS_ROOT="$(flow_resolve_runs_root "${CONFIG_YAML}")"
|
|
93
|
+
STATE_ROOT="$(flow_resolve_state_root "${CONFIG_YAML}")"
|
|
94
|
+
SUPERVISOR_PID_FILE="${STATE_ROOT}/runtime-supervisor.pid"
|
|
95
|
+
PROFILE_ID_SLUG="$(printf '%s' "${PROFILE_ID}" | tr -c 'A-Za-z0-9._-' '-')"
|
|
96
|
+
BOOTSTRAP_SCRIPT="${ACP_PROJECT_RUNTIME_BOOTSTRAP_SCRIPT:-${FLOW_SKILL_DIR}/tools/bin/project-launchd-bootstrap.sh}"
|
|
97
|
+
KICK_SCRIPT="${ACP_PROJECT_RUNTIME_KICK_SCRIPT:-${FLOW_SKILL_DIR}/tools/bin/kick-scheduler.sh}"
|
|
98
|
+
SUPERVISOR_SCRIPT="${ACP_PROJECT_RUNTIME_SUPERVISOR_SCRIPT:-${FLOW_SKILL_DIR}/tools/bin/project-runtime-supervisor.sh}"
|
|
99
|
+
UPDATE_LABELS_SCRIPT="${ACP_PROJECT_RUNTIME_UPDATE_LABELS_SCRIPT:-${FLOW_SKILL_DIR}/tools/bin/agent-github-update-labels}"
|
|
100
|
+
TMUX_BIN="${ACP_PROJECT_RUNTIME_TMUX_BIN:-$(command -v tmux || true)}"
|
|
101
|
+
LAUNCHCTL_BIN="${ACP_PROJECT_RUNTIME_LAUNCHCTL_BIN:-$(command -v launchctl || true)}"
|
|
102
|
+
LAUNCH_AGENTS_DIR="${ACP_PROJECT_RUNTIME_LAUNCH_AGENTS_DIR:-${HOME}/Library/LaunchAgents}"
|
|
103
|
+
LAUNCHD_LABEL="${ACP_PROJECT_RUNTIME_LAUNCHD_LABEL:-ai.agent.project.${PROFILE_ID_SLUG}}"
|
|
104
|
+
LAUNCHD_PLIST="${ACP_PROJECT_RUNTIME_LAUNCHD_PLIST:-${LAUNCH_AGENTS_DIR}/${LAUNCHD_LABEL}.plist}"
|
|
105
|
+
|
|
106
|
+
case "${delay_seconds}" in
|
|
107
|
+
''|*[!0-9]*) echo "--delay-seconds must be numeric" >&2; exit 64 ;;
|
|
108
|
+
esac
|
|
109
|
+
|
|
110
|
+
case "${wait_seconds}" in
|
|
111
|
+
''|*[!0-9]*) echo "--wait-seconds must be numeric" >&2; exit 64 ;;
|
|
112
|
+
esac
|
|
113
|
+
|
|
114
|
+
pid_alive() {
|
|
115
|
+
local pid="${1:-}"
|
|
116
|
+
[[ -n "${pid}" ]] || return 1
|
|
117
|
+
kill -0 "${pid}" 2>/dev/null
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
pid_from_file() {
|
|
121
|
+
local file_path="${1:-}"
|
|
122
|
+
local pid=""
|
|
123
|
+
[[ -f "${file_path}" ]] || return 1
|
|
124
|
+
pid="$(tr -d '[:space:]' <"${file_path}" 2>/dev/null || true)"
|
|
125
|
+
[[ -n "${pid}" ]] || return 1
|
|
126
|
+
if pid_alive "${pid}"; then
|
|
127
|
+
printf '%s\n' "${pid}"
|
|
128
|
+
return 0
|
|
129
|
+
fi
|
|
130
|
+
return 1
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
command_of_pid() {
|
|
134
|
+
local pid="${1:-}"
|
|
135
|
+
[[ -n "${pid}" ]] || return 1
|
|
136
|
+
ps -p "${pid}" -o command= 2>/dev/null | sed 's/^ *//'
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
ppid_of_pid() {
|
|
140
|
+
local pid="${1:-}"
|
|
141
|
+
[[ -n "${pid}" ]] || return 1
|
|
142
|
+
ps -p "${pid}" -o ppid= 2>/dev/null | tr -d '[:space:]'
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
join_by_comma() {
|
|
146
|
+
local first="1"
|
|
147
|
+
local item=""
|
|
148
|
+
while IFS= read -r item; do
|
|
149
|
+
[[ -n "${item}" ]] || continue
|
|
150
|
+
if [[ "${first}" == "1" ]]; then
|
|
151
|
+
printf '%s' "${item}"
|
|
152
|
+
first="0"
|
|
153
|
+
else
|
|
154
|
+
printf ',%s' "${item}"
|
|
155
|
+
fi
|
|
156
|
+
done
|
|
157
|
+
printf '\n'
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
runtime_started() {
|
|
161
|
+
local heartbeat=""
|
|
162
|
+
local shared_loop=""
|
|
163
|
+
local controller_pid=""
|
|
164
|
+
local active_session=""
|
|
165
|
+
local supervisor=""
|
|
166
|
+
|
|
167
|
+
heartbeat="$(heartbeat_pid)"
|
|
168
|
+
shared_loop="$(shared_loop_pid)"
|
|
169
|
+
controller_pid="$(collect_controller_pids | head -n 1 || true)"
|
|
170
|
+
active_session="$(collect_active_tmux_sessions | head -n 1 || true)"
|
|
171
|
+
supervisor="$(supervisor_pid)"
|
|
172
|
+
|
|
173
|
+
[[ -n "${heartbeat}" || -n "${shared_loop}" || -n "${controller_pid}" || -n "${active_session}" || -n "${supervisor}" ]]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
wait_for_runtime_start() {
|
|
177
|
+
local timeout="${1:?timeout required}"
|
|
178
|
+
local deadline=$(( $(date +%s) + timeout ))
|
|
179
|
+
|
|
180
|
+
while (( $(date +%s) <= deadline )); do
|
|
181
|
+
if runtime_started; then
|
|
182
|
+
return 0
|
|
183
|
+
fi
|
|
184
|
+
sleep 1
|
|
185
|
+
done
|
|
186
|
+
return 1
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
tmux_session_exists() {
|
|
190
|
+
local session="${1:-}"
|
|
191
|
+
[[ -n "${TMUX_BIN}" && -n "${session}" ]] || return 1
|
|
192
|
+
"${TMUX_BIN}" has-session -t "${session}" 2>/dev/null
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
collect_run_sessions() {
|
|
196
|
+
local run_env=""
|
|
197
|
+
local session=""
|
|
198
|
+
[[ -d "${RUNS_ROOT}" ]] || return 0
|
|
199
|
+
while IFS= read -r run_env; do
|
|
200
|
+
[[ -n "${run_env}" ]] || continue
|
|
201
|
+
session="$(awk -F= '/^SESSION=/{print $2}' "${run_env}" 2>/dev/null | tail -n 1 | tr -d '\r' || true)"
|
|
202
|
+
if [[ -z "${session}" ]]; then
|
|
203
|
+
session="$(basename "$(dirname "${run_env}")")"
|
|
204
|
+
fi
|
|
205
|
+
[[ -n "${session}" ]] || continue
|
|
206
|
+
printf '%s\n' "${session}"
|
|
207
|
+
done < <(find "${RUNS_ROOT}" -mindepth 2 -maxdepth 2 -type f -name run.env 2>/dev/null | sort -u)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
collect_active_tmux_sessions() {
|
|
211
|
+
local session=""
|
|
212
|
+
while IFS= read -r session; do
|
|
213
|
+
[[ -n "${session}" ]] || continue
|
|
214
|
+
if tmux_session_exists "${session}"; then
|
|
215
|
+
printf '%s\n' "${session}"
|
|
216
|
+
fi
|
|
217
|
+
done < <(collect_run_sessions)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
collect_repo_shared_loop_pids() {
|
|
221
|
+
ps -ax -o pid=,command= 2>/dev/null \
|
|
222
|
+
| while read -r pid command; do
|
|
223
|
+
[[ -n "${pid:-}" ]] || continue
|
|
224
|
+
case "${command}" in
|
|
225
|
+
*"agent-project-heartbeat-loop --repo-slug ${REPO_SLUG}"*)
|
|
226
|
+
if pid_alive "${pid}"; then
|
|
227
|
+
printf '%s\n' "${pid}"
|
|
228
|
+
fi
|
|
229
|
+
;;
|
|
230
|
+
esac
|
|
231
|
+
done
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
collect_controller_pids() {
|
|
235
|
+
local controller_file=""
|
|
236
|
+
local pid=""
|
|
237
|
+
[[ -d "${STATE_ROOT}/resident-workers/issues" ]] || return 0
|
|
238
|
+
while IFS= read -r controller_file; do
|
|
239
|
+
[[ -n "${controller_file}" ]] || continue
|
|
240
|
+
pid="$(awk -F= '/^CONTROLLER_PID=/{print $2}' "${controller_file}" 2>/dev/null | tail -n 1 | tr -d '[:space:]\r' || true)"
|
|
241
|
+
if pid_alive "${pid}"; then
|
|
242
|
+
printf '%s\n' "${pid}"
|
|
243
|
+
fi
|
|
244
|
+
done < <(find "${STATE_ROOT}/resident-workers/issues" -mindepth 2 -maxdepth 2 -type f -name controller.env 2>/dev/null | sort -u)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
collect_pending_launch_pids() {
|
|
248
|
+
local pid_file=""
|
|
249
|
+
local pid=""
|
|
250
|
+
[[ -d "${STATE_ROOT}/pending-launches" ]] || return 0
|
|
251
|
+
while IFS= read -r pid_file; do
|
|
252
|
+
[[ -n "${pid_file}" ]] || continue
|
|
253
|
+
pid="$(pid_from_file "${pid_file}" || true)"
|
|
254
|
+
if [[ -n "${pid}" ]]; then
|
|
255
|
+
printf '%s\n' "${pid}"
|
|
256
|
+
fi
|
|
257
|
+
done < <(find "${STATE_ROOT}/pending-launches" -mindepth 1 -maxdepth 1 -type f -name '*.pid' 2>/dev/null | sort -u)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
heartbeat_pid() {
|
|
261
|
+
pid_from_file "${STATE_ROOT}/heartbeat-loop.lock/pid" || true
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
shared_loop_pid() {
|
|
265
|
+
local pid=""
|
|
266
|
+
pid="$(pid_from_file "${STATE_ROOT}/shared-heartbeat-loop.pid" || true)"
|
|
267
|
+
if [[ -n "${pid}" ]]; then
|
|
268
|
+
if command_of_pid "${pid}" | grep -F -- "agent-project-heartbeat-loop --repo-slug ${REPO_SLUG}" >/dev/null 2>&1; then
|
|
269
|
+
printf '%s\n' "${pid}"
|
|
270
|
+
return 0
|
|
271
|
+
fi
|
|
272
|
+
rm -f "${STATE_ROOT}/shared-heartbeat-loop.pid"
|
|
273
|
+
fi
|
|
274
|
+
collect_repo_shared_loop_pids | head -n 1 || true
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
kick_scheduler_pid() {
|
|
278
|
+
pid_from_file "${STATE_ROOT}/kick-scheduler/pid" || true
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
supervisor_pid() {
|
|
282
|
+
pid_from_file "${SUPERVISOR_PID_FILE}" || true
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
heartbeat_parent_pid() {
|
|
286
|
+
local pid=""
|
|
287
|
+
local parent_pid=""
|
|
288
|
+
local parent_command=""
|
|
289
|
+
pid="$(heartbeat_pid)"
|
|
290
|
+
[[ -n "${pid}" ]] || return 0
|
|
291
|
+
parent_pid="$(ppid_of_pid "${pid}" || true)"
|
|
292
|
+
[[ -n "${parent_pid}" ]] || return 0
|
|
293
|
+
parent_command="$(command_of_pid "${parent_pid}" || true)"
|
|
294
|
+
case "${parent_command}" in
|
|
295
|
+
*project-runtime-supervisor.sh*|*agent-scheduler-launchd.sh*|*"agent-project-${PROFILE_ID_SLUG}-launchd.sh"*)
|
|
296
|
+
if pid_alive "${parent_pid}"; then
|
|
297
|
+
printf '%s\n' "${parent_pid}"
|
|
298
|
+
fi
|
|
299
|
+
;;
|
|
300
|
+
esac
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
launchd_service_enabled_for_profile() {
|
|
304
|
+
[[ -n "${LAUNCHCTL_BIN}" && -x "${LAUNCHCTL_BIN}" ]] || return 1
|
|
305
|
+
[[ -f "${LAUNCHD_PLIST}" ]] || return 1
|
|
306
|
+
return 0
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
launchd_service_state() {
|
|
310
|
+
if ! launchd_service_enabled_for_profile; then
|
|
311
|
+
printf 'n/a\n'
|
|
312
|
+
return 0
|
|
313
|
+
fi
|
|
314
|
+
if "${LAUNCHCTL_BIN}" print "gui/$(id -u)/${LAUNCHD_LABEL}" >/dev/null 2>&1; then
|
|
315
|
+
printf 'running\n'
|
|
316
|
+
else
|
|
317
|
+
printf 'stopped\n'
|
|
318
|
+
fi
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
print_status() {
|
|
322
|
+
local heartbeat=""
|
|
323
|
+
local shared_loop=""
|
|
324
|
+
local heartbeat_parent=""
|
|
325
|
+
local supervisor=""
|
|
326
|
+
local controller_pids=""
|
|
327
|
+
local active_sessions=""
|
|
328
|
+
local pending_pids=""
|
|
329
|
+
local runtime_status="stopped"
|
|
330
|
+
local controller_count="0"
|
|
331
|
+
local active_session_count="0"
|
|
332
|
+
local pending_count="0"
|
|
333
|
+
local launchd_state=""
|
|
334
|
+
|
|
335
|
+
heartbeat="$(heartbeat_pid)"
|
|
336
|
+
shared_loop="$(shared_loop_pid)"
|
|
337
|
+
supervisor="$(supervisor_pid)"
|
|
338
|
+
heartbeat_parent="$(heartbeat_parent_pid)"
|
|
339
|
+
controller_pids="$(collect_controller_pids | sort -u)"
|
|
340
|
+
active_sessions="$(collect_active_tmux_sessions | sort -u)"
|
|
341
|
+
pending_pids="$(collect_pending_launch_pids | sort -u)"
|
|
342
|
+
|
|
343
|
+
[[ -n "${controller_pids}" ]] && controller_count="$(printf '%s\n' "${controller_pids}" | awk 'NF {c+=1} END {print c+0}')"
|
|
344
|
+
[[ -n "${active_sessions}" ]] && active_session_count="$(printf '%s\n' "${active_sessions}" | awk 'NF {c+=1} END {print c+0}')"
|
|
345
|
+
[[ -n "${pending_pids}" ]] && pending_count="$(printf '%s\n' "${pending_pids}" | awk 'NF {c+=1} END {print c+0}')"
|
|
346
|
+
|
|
347
|
+
if [[ -n "${heartbeat}" || -n "${shared_loop}" || -n "${supervisor}" || "${controller_count}" != "0" || "${active_session_count}" != "0" ]]; then
|
|
348
|
+
runtime_status="running"
|
|
349
|
+
fi
|
|
350
|
+
if [[ -z "${heartbeat}" && -z "${supervisor}" && ( -n "${shared_loop}" || "${controller_count}" != "0" || "${active_session_count}" != "0" ) ]]; then
|
|
351
|
+
runtime_status="partial"
|
|
352
|
+
fi
|
|
353
|
+
|
|
354
|
+
launchd_state="$(launchd_service_state)"
|
|
355
|
+
|
|
356
|
+
printf 'PROFILE_ID=%s\n' "${PROFILE_ID}"
|
|
357
|
+
printf 'CONFIG_YAML=%s\n' "${CONFIG_YAML}"
|
|
358
|
+
printf 'REPO_SLUG=%s\n' "${REPO_SLUG}"
|
|
359
|
+
printf 'RUNS_ROOT=%s\n' "${RUNS_ROOT}"
|
|
360
|
+
printf 'STATE_ROOT=%s\n' "${STATE_ROOT}"
|
|
361
|
+
printf 'RUNTIME_STATUS=%s\n' "${runtime_status}"
|
|
362
|
+
printf 'LAUNCHD_STATE=%s\n' "${launchd_state}"
|
|
363
|
+
printf 'LAUNCHD_LABEL=%s\n' "${LAUNCHD_LABEL}"
|
|
364
|
+
printf 'LAUNCHD_PLIST=%s\n' "${LAUNCHD_PLIST}"
|
|
365
|
+
printf 'HEARTBEAT_PID=%s\n' "${heartbeat}"
|
|
366
|
+
printf 'HEARTBEAT_PARENT_PID=%s\n' "${heartbeat_parent}"
|
|
367
|
+
printf 'SHARED_LOOP_PID=%s\n' "${shared_loop}"
|
|
368
|
+
printf 'SUPERVISOR_PID=%s\n' "${supervisor}"
|
|
369
|
+
printf 'CONTROLLER_COUNT=%s\n' "${controller_count}"
|
|
370
|
+
printf 'ACTIVE_TMUX_SESSION_COUNT=%s\n' "${active_session_count}"
|
|
371
|
+
printf 'PENDING_LAUNCH_COUNT=%s\n' "${pending_count}"
|
|
372
|
+
printf 'CONTROLLER_PIDS=%s\n' "$(printf '%s\n' "${controller_pids}" | join_by_comma)"
|
|
373
|
+
printf 'ACTIVE_TMUX_SESSIONS=%s\n' "$(printf '%s\n' "${active_sessions}" | join_by_comma)"
|
|
374
|
+
printf 'PENDING_LAUNCH_PIDS=%s\n' "$(printf '%s\n' "${pending_pids}" | join_by_comma)"
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
terminate_pid_list() {
|
|
378
|
+
local signal_name="${1:?signal required}"
|
|
379
|
+
shift
|
|
380
|
+
local pid=""
|
|
381
|
+
for pid in "$@"; do
|
|
382
|
+
[[ -n "${pid}" ]] || continue
|
|
383
|
+
kill "-${signal_name}" "${pid}" 2>/dev/null || true
|
|
384
|
+
done
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
wait_for_pids_to_exit() {
|
|
388
|
+
local timeout="${1:?timeout required}"
|
|
389
|
+
shift
|
|
390
|
+
if [[ "$#" -eq 0 ]]; then
|
|
391
|
+
return 0
|
|
392
|
+
fi
|
|
393
|
+
local -a pids=("$@")
|
|
394
|
+
local deadline=$(( $(date +%s) + timeout ))
|
|
395
|
+
local pid=""
|
|
396
|
+
local alive="1"
|
|
397
|
+
|
|
398
|
+
while (( $(date +%s) <= deadline )); do
|
|
399
|
+
alive="0"
|
|
400
|
+
for pid in "${pids[@]}"; do
|
|
401
|
+
if pid_alive "${pid}"; then
|
|
402
|
+
alive="1"
|
|
403
|
+
break
|
|
404
|
+
fi
|
|
405
|
+
done
|
|
406
|
+
if [[ "${alive}" == "0" ]]; then
|
|
407
|
+
return 0
|
|
408
|
+
fi
|
|
409
|
+
sleep 1
|
|
410
|
+
done
|
|
411
|
+
return 1
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
remove_runtime_pid_files() {
|
|
415
|
+
rm -f "${STATE_ROOT}/shared-heartbeat-loop.pid"
|
|
416
|
+
rm -f "${STATE_ROOT}/kick-scheduler/pid"
|
|
417
|
+
rmdir "${STATE_ROOT}/kick-scheduler" 2>/dev/null || true
|
|
418
|
+
rm -f "${SUPERVISOR_PID_FILE}"
|
|
419
|
+
rm -f "${STATE_ROOT}/heartbeat-loop.lock/pid"
|
|
420
|
+
rmdir "${STATE_ROOT}/heartbeat-loop.lock" 2>/dev/null || true
|
|
421
|
+
find "${STATE_ROOT}/pending-launches" -mindepth 1 -maxdepth 1 -type f -name '*.pid' -delete 2>/dev/null || true
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
clear_running_labels_after_stop() {
|
|
425
|
+
local issue_json=""
|
|
426
|
+
local pr_json=""
|
|
427
|
+
local number=""
|
|
428
|
+
|
|
429
|
+
if ! command -v gh >/dev/null 2>&1 || [[ ! -x "${UPDATE_LABELS_SCRIPT}" ]]; then
|
|
430
|
+
return 0
|
|
431
|
+
fi
|
|
432
|
+
|
|
433
|
+
issue_json="$(flow_github_issue_list_json "${REPO_SLUG}" open 100 2>/dev/null || printf '[]\n')"
|
|
434
|
+
while IFS= read -r number; do
|
|
435
|
+
[[ -n "${number}" ]] || continue
|
|
436
|
+
bash "${UPDATE_LABELS_SCRIPT}" --repo-slug "${REPO_SLUG}" --number "${number}" --remove agent-running >/dev/null 2>&1 || true
|
|
437
|
+
done < <(jq -r '.[] | select(any(.labels[]?; .name == "agent-running")) | .number' <<<"${issue_json}" 2>/dev/null || true)
|
|
438
|
+
|
|
439
|
+
pr_json="$(flow_github_pr_list_json "${REPO_SLUG}" open 100 2>/dev/null || printf '[]\n')"
|
|
440
|
+
while IFS= read -r number; do
|
|
441
|
+
[[ -n "${number}" ]] || continue
|
|
442
|
+
bash "${UPDATE_LABELS_SCRIPT}" --repo-slug "${REPO_SLUG}" --number "${number}" --remove agent-running >/dev/null 2>&1 || true
|
|
443
|
+
done < <(jq -r '.[] | select(any(.labels[]?; .name == "agent-running")) | .number' <<<"${pr_json}" 2>/dev/null || true)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
stop_runtime() {
|
|
447
|
+
local -a tmux_sessions=()
|
|
448
|
+
local -a pid_targets=()
|
|
449
|
+
local session=""
|
|
450
|
+
local pid=""
|
|
451
|
+
local launchd_stopped="no"
|
|
452
|
+
|
|
453
|
+
while IFS= read -r session; do
|
|
454
|
+
[[ -n "${session}" ]] || continue
|
|
455
|
+
tmux_sessions+=("${session}")
|
|
456
|
+
done < <(collect_active_tmux_sessions | sort -u)
|
|
457
|
+
|
|
458
|
+
while IFS= read -r pid; do
|
|
459
|
+
[[ -n "${pid}" ]] || continue
|
|
460
|
+
pid_targets+=("${pid}")
|
|
461
|
+
done < <(
|
|
462
|
+
{
|
|
463
|
+
heartbeat_pid
|
|
464
|
+
heartbeat_parent_pid
|
|
465
|
+
shared_loop_pid
|
|
466
|
+
collect_repo_shared_loop_pids
|
|
467
|
+
kick_scheduler_pid
|
|
468
|
+
supervisor_pid
|
|
469
|
+
collect_controller_pids
|
|
470
|
+
collect_pending_launch_pids
|
|
471
|
+
} | awk 'NF {print}' | sort -u
|
|
472
|
+
)
|
|
473
|
+
|
|
474
|
+
if launchd_service_enabled_for_profile; then
|
|
475
|
+
"${LAUNCHCTL_BIN}" bootout "gui/$(id -u)/${LAUNCHD_LABEL}" >/dev/null 2>&1 || true
|
|
476
|
+
launchd_stopped="yes"
|
|
477
|
+
fi
|
|
478
|
+
|
|
479
|
+
if [[ -n "${TMUX_BIN}" ]]; then
|
|
480
|
+
for session in "${tmux_sessions[@]+"${tmux_sessions[@]}"}"; do
|
|
481
|
+
"${TMUX_BIN}" kill-session -t "${session}" >/dev/null 2>&1 || true
|
|
482
|
+
done
|
|
483
|
+
fi
|
|
484
|
+
|
|
485
|
+
terminate_pid_list TERM "${pid_targets[@]+"${pid_targets[@]}"}"
|
|
486
|
+
wait_for_pids_to_exit "${wait_seconds}" "${pid_targets[@]+"${pid_targets[@]}"}" || terminate_pid_list KILL "${pid_targets[@]+"${pid_targets[@]}"}"
|
|
487
|
+
remove_runtime_pid_files
|
|
488
|
+
clear_running_labels_after_stop
|
|
489
|
+
|
|
490
|
+
printf 'ACTION=stop\n'
|
|
491
|
+
printf 'PROFILE_ID=%s\n' "${PROFILE_ID}"
|
|
492
|
+
printf 'LAUNCHD_STOPPED=%s\n' "${launchd_stopped}"
|
|
493
|
+
printf 'STOPPED_PID_COUNT=%s\n' "$(printf '%s\n' "${pid_targets[@]+"${pid_targets[@]}"}" | awk 'NF {c+=1} END {print c+0}')"
|
|
494
|
+
printf 'STOPPED_TMUX_SESSION_COUNT=%s\n' "$(printf '%s\n' "${tmux_sessions[@]+"${tmux_sessions[@]}"}" | awk 'NF {c+=1} END {print c+0}')"
|
|
495
|
+
printf 'STOPPED_PIDS=%s\n' "$(printf '%s\n' "${pid_targets[@]+"${pid_targets[@]}"}" | join_by_comma)"
|
|
496
|
+
printf 'STOPPED_TMUX_SESSIONS=%s\n' "$(printf '%s\n' "${tmux_sessions[@]+"${tmux_sessions[@]}"}" | join_by_comma)"
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
start_runtime() {
|
|
500
|
+
local kick_output=""
|
|
501
|
+
local fallback_pid=""
|
|
502
|
+
local start_timeout="${ACP_PROJECT_RUNTIME_START_WAIT_SECONDS:-${wait_seconds}}"
|
|
503
|
+
local runtime_started_after_kick="0"
|
|
504
|
+
local supervisor_spawned="0"
|
|
505
|
+
local start_mode="kick-scheduler"
|
|
506
|
+
|
|
507
|
+
if runtime_started; then
|
|
508
|
+
printf 'ACTION=start\n'
|
|
509
|
+
printf 'PROFILE_ID=%s\n' "${PROFILE_ID}"
|
|
510
|
+
printf 'START_MODE=already-running\n'
|
|
511
|
+
printf 'NOOP=yes\n'
|
|
512
|
+
return 0
|
|
513
|
+
fi
|
|
514
|
+
|
|
515
|
+
if launchd_service_enabled_for_profile; then
|
|
516
|
+
local launchd_domain="gui/$(id -u)"
|
|
517
|
+
"${LAUNCHCTL_BIN}" bootout "${launchd_domain}/${LAUNCHD_LABEL}" >/dev/null 2>&1 || true
|
|
518
|
+
"${LAUNCHCTL_BIN}" bootstrap "${launchd_domain}" "${LAUNCHD_PLIST}"
|
|
519
|
+
for _ in 1 2 3 4 5 6 7 8 9 10; do
|
|
520
|
+
if "${LAUNCHCTL_BIN}" print "${launchd_domain}/${LAUNCHD_LABEL}" >/dev/null 2>&1; then
|
|
521
|
+
break
|
|
522
|
+
fi
|
|
523
|
+
sleep 1
|
|
524
|
+
done
|
|
525
|
+
"${LAUNCHCTL_BIN}" kickstart -k "${launchd_domain}/${LAUNCHD_LABEL}" >/dev/null 2>&1 || true
|
|
526
|
+
printf 'ACTION=start\n'
|
|
527
|
+
printf 'PROFILE_ID=%s\n' "${PROFILE_ID}"
|
|
528
|
+
printf 'START_MODE=launchd\n'
|
|
529
|
+
printf 'LAUNCHD_LABEL=%s\n' "${LAUNCHD_LABEL}"
|
|
530
|
+
return 0
|
|
531
|
+
fi
|
|
532
|
+
|
|
533
|
+
kick_output="$(ACP_PROJECT_ID="${PROFILE_ID}" AGENT_PROJECT_ID="${PROFILE_ID}" bash "${KICK_SCRIPT}" "${delay_seconds}")"
|
|
534
|
+
if wait_for_runtime_start "${start_timeout}"; then
|
|
535
|
+
runtime_started_after_kick="1"
|
|
536
|
+
fi
|
|
537
|
+
|
|
538
|
+
if [[ "${runtime_started_after_kick}" != "1" && -z "$(supervisor_pid)" ]]; then
|
|
539
|
+
mkdir -p "${STATE_ROOT}"
|
|
540
|
+
nohup env ACP_PROJECT_ID="${PROFILE_ID}" AGENT_PROJECT_ID="${PROFILE_ID}" \
|
|
541
|
+
bash "${SUPERVISOR_SCRIPT}" \
|
|
542
|
+
--bootstrap-script "${BOOTSTRAP_SCRIPT}" \
|
|
543
|
+
--pid-file "${SUPERVISOR_PID_FILE}" \
|
|
544
|
+
--delay-seconds "${delay_seconds}" \
|
|
545
|
+
--interval-seconds "${ACP_PROJECT_RUNTIME_SUPERVISOR_INTERVAL_SECONDS:-15}" \
|
|
546
|
+
</dev/null >/dev/null 2>&1 &
|
|
547
|
+
fallback_pid="$!"
|
|
548
|
+
supervisor_spawned="1"
|
|
549
|
+
wait_for_runtime_start "${start_timeout}" || true
|
|
550
|
+
fi
|
|
551
|
+
|
|
552
|
+
if [[ "${supervisor_spawned}" == "1" ]]; then
|
|
553
|
+
if [[ "${runtime_started_after_kick}" == "1" ]]; then
|
|
554
|
+
start_mode="kick-scheduler-plus-supervisor"
|
|
555
|
+
else
|
|
556
|
+
start_mode="kick-scheduler-fallback-supervisor"
|
|
557
|
+
fi
|
|
558
|
+
fi
|
|
559
|
+
|
|
560
|
+
printf 'ACTION=start\n'
|
|
561
|
+
printf 'PROFILE_ID=%s\n' "${PROFILE_ID}"
|
|
562
|
+
printf 'START_MODE=%s\n' "${start_mode}"
|
|
563
|
+
printf '%s\n' "${kick_output}"
|
|
564
|
+
if [[ -n "${fallback_pid}" ]]; then
|
|
565
|
+
printf 'FALLBACK_SUPERVISOR_PID=%s\n' "${fallback_pid}"
|
|
566
|
+
fi
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
case "${subcommand}" in
|
|
570
|
+
status)
|
|
571
|
+
print_status
|
|
572
|
+
;;
|
|
573
|
+
stop)
|
|
574
|
+
stop_runtime
|
|
575
|
+
print_status
|
|
576
|
+
;;
|
|
577
|
+
start)
|
|
578
|
+
start_runtime
|
|
579
|
+
print_status
|
|
580
|
+
;;
|
|
581
|
+
restart)
|
|
582
|
+
stop_runtime >/dev/null
|
|
583
|
+
start_runtime
|
|
584
|
+
print_status
|
|
585
|
+
;;
|
|
586
|
+
esac
|