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,573 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
HOOK_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
5
|
+
# shellcheck source=/dev/null
|
|
6
|
+
source "${HOOK_SCRIPT_DIR}/../tools/bin/flow-config-lib.sh"
|
|
7
|
+
# shellcheck source=/dev/null
|
|
8
|
+
source "${HOOK_SCRIPT_DIR}/../tools/bin/flow-resident-worker-lib.sh"
|
|
9
|
+
|
|
10
|
+
FLOW_SKILL_DIR="$(cd "${HOOK_SCRIPT_DIR}/.." && pwd)"
|
|
11
|
+
CONFIG_YAML="$(resolve_flow_config_yaml "${BASH_SOURCE[0]}")"
|
|
12
|
+
flow_export_execution_env "${CONFIG_YAML}"
|
|
13
|
+
ADAPTER_BIN_DIR="${FLOW_SKILL_DIR}/bin"
|
|
14
|
+
FLOW_TOOLS_DIR="${FLOW_SKILL_DIR}/tools/bin"
|
|
15
|
+
DETACHED_LAUNCH_BIN="${FLOW_TOOLS_DIR}/agent-project-detached-launch"
|
|
16
|
+
RESIDENT_ISSUE_LOOP_BIN="${FLOW_TOOLS_DIR}/start-resident-issue-loop.sh"
|
|
17
|
+
REPO_SLUG="$(flow_resolve_repo_slug "${CONFIG_YAML}")"
|
|
18
|
+
AGENT_PR_PREFIXES_JSON="$(flow_managed_pr_prefixes_json "${CONFIG_YAML}")"
|
|
19
|
+
AGENT_PR_ISSUE_CAPTURE_REGEX="$(flow_managed_issue_branch_regex "${CONFIG_YAML}")"
|
|
20
|
+
AGENT_PR_HANDOFF_LABEL="${AGENT_PR_HANDOFF_LABEL:-agent-handoff}"
|
|
21
|
+
AGENT_EXCLUSIVE_LABEL="${AGENT_EXCLUSIVE_LABEL:-agent-exclusive}"
|
|
22
|
+
CODING_WORKER="${ACP_CODING_WORKER:-${F_LOSNING_CODING_WORKER:-codex}}"
|
|
23
|
+
|
|
24
|
+
heartbeat_open_agent_pr_issue_ids() {
|
|
25
|
+
flow_github_pr_list_json "$REPO_SLUG" open 100 \
|
|
26
|
+
| jq --argjson agentPrPrefixes "${AGENT_PR_PREFIXES_JSON}" --arg handoffLabel "${AGENT_PR_HANDOFF_LABEL}" --arg branchIssueRegex "${AGENT_PR_ISSUE_CAPTURE_REGEX}" '
|
|
27
|
+
map(
|
|
28
|
+
. as $pr
|
|
29
|
+
| select(
|
|
30
|
+
any($agentPrPrefixes[]; (($pr.headRefName // "") | startswith(.)))
|
|
31
|
+
or any(($pr.labels // [])[]?; .name == $handoffLabel)
|
|
32
|
+
or any(($pr.comments // [])[]?; ((.body // "") | test("^## PR (final review blocker|repair worker summary|repair summary|repair update)"; "i")))
|
|
33
|
+
)
|
|
34
|
+
| [
|
|
35
|
+
(
|
|
36
|
+
$pr.headRefName
|
|
37
|
+
| capture($branchIssueRegex)?
|
|
38
|
+
| .id
|
|
39
|
+
),
|
|
40
|
+
(
|
|
41
|
+
($pr.body // "")
|
|
42
|
+
| capture("(?i)\\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\\s+#(?<id>[0-9]+)\\b")?
|
|
43
|
+
| .id
|
|
44
|
+
)
|
|
45
|
+
]
|
|
46
|
+
| .[]
|
|
47
|
+
| select(. != null and . != "")
|
|
48
|
+
)
|
|
49
|
+
| unique
|
|
50
|
+
'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
heartbeat_list_ready_issue_ids() {
|
|
54
|
+
local open_agent_pr_issue_ids
|
|
55
|
+
local ready_issue_rows issue_id is_blocked retry_out retry_reason
|
|
56
|
+
open_agent_pr_issue_ids="$(heartbeat_open_agent_pr_issue_ids)"
|
|
57
|
+
|
|
58
|
+
ready_issue_rows="$(
|
|
59
|
+
flow_github_issue_list_json "$REPO_SLUG" open 100 \
|
|
60
|
+
| jq -r --argjson openAgentPrIssueIds "${open_agent_pr_issue_ids}" '
|
|
61
|
+
map(select(
|
|
62
|
+
(any(.labels[]?; .name == "agent-running") | not)
|
|
63
|
+
and ((.number | tostring) as $issueId | ($openAgentPrIssueIds | index($issueId) | not))
|
|
64
|
+
))
|
|
65
|
+
| sort_by(.createdAt, .number)
|
|
66
|
+
| .[]
|
|
67
|
+
| [.number, (any(.labels[]?; .name == "agent-blocked"))]
|
|
68
|
+
| @tsv
|
|
69
|
+
'
|
|
70
|
+
)"
|
|
71
|
+
|
|
72
|
+
while IFS=$'\t' read -r issue_id is_blocked; do
|
|
73
|
+
[[ -n "${issue_id:-}" ]] || continue
|
|
74
|
+
|
|
75
|
+
if [[ "${is_blocked:-false}" == "true" ]]; then
|
|
76
|
+
retry_out="$("${FLOW_TOOLS_DIR}/retry-state.sh" issue "$issue_id" get 2>/dev/null || true)"
|
|
77
|
+
retry_reason="$(awk -F= '/^LAST_REASON=/{print $2}' <<<"${retry_out:-}")"
|
|
78
|
+
if [[ -z "${retry_reason:-}" ]]; then
|
|
79
|
+
continue
|
|
80
|
+
fi
|
|
81
|
+
continue
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
printf '%s\n' "$issue_id"
|
|
85
|
+
done <<<"$ready_issue_rows"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
heartbeat_list_blocked_recovery_issue_ids() {
|
|
89
|
+
local open_agent_pr_issue_ids
|
|
90
|
+
local blocked_issue_rows issue_id retry_out retry_reason
|
|
91
|
+
open_agent_pr_issue_ids="$(heartbeat_open_agent_pr_issue_ids)"
|
|
92
|
+
|
|
93
|
+
blocked_issue_rows="$(
|
|
94
|
+
flow_github_issue_list_json "$REPO_SLUG" open 100 \
|
|
95
|
+
| jq -r --argjson openAgentPrIssueIds "${open_agent_pr_issue_ids}" '
|
|
96
|
+
map(select(
|
|
97
|
+
any(.labels[]?; .name == "agent-blocked")
|
|
98
|
+
and (any(.labels[]?; .name == "agent-running") | not)
|
|
99
|
+
and ((.number | tostring) as $issueId | ($openAgentPrIssueIds | index($issueId) | not))
|
|
100
|
+
))
|
|
101
|
+
| sort_by(.createdAt, .number)
|
|
102
|
+
| .[].number
|
|
103
|
+
'
|
|
104
|
+
)"
|
|
105
|
+
|
|
106
|
+
while IFS= read -r issue_id; do
|
|
107
|
+
[[ -n "${issue_id:-}" ]] || continue
|
|
108
|
+
retry_out="$("${FLOW_TOOLS_DIR}/retry-state.sh" issue "$issue_id" get 2>/dev/null || true)"
|
|
109
|
+
retry_reason="$(awk -F= '/^LAST_REASON=/{print $2}' <<<"${retry_out:-}")"
|
|
110
|
+
if [[ -z "${retry_reason:-}" ]]; then
|
|
111
|
+
continue
|
|
112
|
+
fi
|
|
113
|
+
|
|
114
|
+
printf '%s\n' "$issue_id"
|
|
115
|
+
done <<<"$blocked_issue_rows"
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
heartbeat_list_exclusive_issue_ids() {
|
|
119
|
+
local open_agent_pr_issue_ids
|
|
120
|
+
open_agent_pr_issue_ids="$(heartbeat_open_agent_pr_issue_ids)"
|
|
121
|
+
|
|
122
|
+
flow_github_issue_list_json "$REPO_SLUG" open 100 \
|
|
123
|
+
| jq -r --arg exclusiveLabel "${AGENT_EXCLUSIVE_LABEL}" --argjson openAgentPrIssueIds "${open_agent_pr_issue_ids}" '
|
|
124
|
+
map(select(
|
|
125
|
+
any(.labels[]?; .name == $exclusiveLabel)
|
|
126
|
+
and (any(.labels[]?; .name == "agent-running") | not)
|
|
127
|
+
and (any(.labels[]?; .name == "agent-blocked") | not)
|
|
128
|
+
and ((.number | tostring) as $issueId | ($openAgentPrIssueIds | index($issueId) | not))
|
|
129
|
+
))
|
|
130
|
+
| sort_by(.createdAt, .number)
|
|
131
|
+
| .[].number
|
|
132
|
+
'
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
heartbeat_list_running_issue_ids() {
|
|
136
|
+
flow_github_issue_list_json "$REPO_SLUG" open 100 \
|
|
137
|
+
| jq -r '
|
|
138
|
+
map(select(any(.labels[]?; .name == "agent-running")))
|
|
139
|
+
| sort_by(.createdAt, .number)
|
|
140
|
+
| .[].number
|
|
141
|
+
'
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
heartbeat_list_open_agent_pr_ids() {
|
|
145
|
+
flow_github_pr_list_json "$REPO_SLUG" open 100 \
|
|
146
|
+
| jq -r --argjson agentPrPrefixes "${AGENT_PR_PREFIXES_JSON}" --arg handoffLabel "${AGENT_PR_HANDOFF_LABEL}" '
|
|
147
|
+
map(select(
|
|
148
|
+
. as $pr
|
|
149
|
+
| (
|
|
150
|
+
any($agentPrPrefixes[]; (($pr.headRefName // "") | startswith(.)))
|
|
151
|
+
or any(($pr.labels // [])[]?; .name == $handoffLabel)
|
|
152
|
+
or any(($pr.comments // [])[]?; ((.body // "") | test("^## PR (final review blocker|repair worker summary|repair summary|repair update)"; "i")))
|
|
153
|
+
)
|
|
154
|
+
))
|
|
155
|
+
| sort_by(.createdAt)
|
|
156
|
+
| .[].number
|
|
157
|
+
'
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
heartbeat_list_exclusive_pr_ids() {
|
|
161
|
+
flow_github_pr_list_json "$REPO_SLUG" open 100 \
|
|
162
|
+
| jq -r --argjson agentPrPrefixes "${AGENT_PR_PREFIXES_JSON}" --arg handoffLabel "${AGENT_PR_HANDOFF_LABEL}" --arg exclusiveLabel "${AGENT_EXCLUSIVE_LABEL}" '
|
|
163
|
+
map(select(
|
|
164
|
+
. as $pr
|
|
165
|
+
| (
|
|
166
|
+
any($agentPrPrefixes[]; (($pr.headRefName // "") | startswith(.)))
|
|
167
|
+
or any(($pr.labels // [])[]?; .name == $handoffLabel)
|
|
168
|
+
or any(($pr.comments // [])[]?; ((.body // "") | test("^## PR (final review blocker|repair worker summary|repair summary|repair update)"; "i")))
|
|
169
|
+
)
|
|
170
|
+
and any(($pr.labels // [])[]?; .name == $exclusiveLabel)
|
|
171
|
+
))
|
|
172
|
+
| sort_by(.createdAt)
|
|
173
|
+
| .[].number
|
|
174
|
+
'
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
heartbeat_issue_is_heavy() {
|
|
178
|
+
local issue_id="${1:?issue id required}"
|
|
179
|
+
local class_out
|
|
180
|
+
class_out="$("${ADAPTER_BIN_DIR}/issue-resource-class.sh" "$issue_id")"
|
|
181
|
+
awk -F= '/^IS_E2E=/{print $2}' <<<"$class_out"
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
heartbeat_issue_is_recurring() {
|
|
185
|
+
local issue_id="${1:?issue id required}"
|
|
186
|
+
local issue_json
|
|
187
|
+
issue_json="$(flow_github_issue_view_json "$REPO_SLUG" "$issue_id" 2>/dev/null || true)"
|
|
188
|
+
if [[ -n "$issue_json" ]] && jq -e 'any(.labels[]?; .name == "agent-keep-open")' >/dev/null <<<"$issue_json"; then
|
|
189
|
+
printf 'yes\n'
|
|
190
|
+
else
|
|
191
|
+
printf 'no\n'
|
|
192
|
+
fi
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
heartbeat_issue_schedule_interval_seconds() {
|
|
196
|
+
local issue_id="${1:?issue id required}"
|
|
197
|
+
local issue_json issue_body
|
|
198
|
+
issue_json="$(flow_github_issue_view_json "$REPO_SLUG" "$issue_id" 2>/dev/null || true)"
|
|
199
|
+
if [[ -z "$issue_json" ]]; then
|
|
200
|
+
issue_json='{}'
|
|
201
|
+
fi
|
|
202
|
+
issue_body="$(jq -r '.body // ""' <<<"$issue_json")"
|
|
203
|
+
ISSUE_BODY="$issue_body" node <<'EOF'
|
|
204
|
+
const body = process.env.ISSUE_BODY || '';
|
|
205
|
+
const match = body.match(/^\s*(?:Agent schedule|Schedule|Cadence)\s*:\s*(?:every\s+)?(\d+)\s*([mhd])\s*$/im);
|
|
206
|
+
if (!match) {
|
|
207
|
+
process.stdout.write('0\n');
|
|
208
|
+
process.exit(0);
|
|
209
|
+
}
|
|
210
|
+
const value = Number(match[1]);
|
|
211
|
+
const unit = String(match[2] || '').toLowerCase();
|
|
212
|
+
const multiplier = { m: 60, h: 3600, d: 86400 }[unit] || 0;
|
|
213
|
+
const seconds = Number.isFinite(value) && value > 0 ? value * multiplier : 0;
|
|
214
|
+
process.stdout.write(`${seconds}\n`);
|
|
215
|
+
EOF
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
heartbeat_issue_schedule_token() {
|
|
219
|
+
local issue_id="${1:?issue id required}"
|
|
220
|
+
local issue_json issue_body
|
|
221
|
+
issue_json="$(flow_github_issue_view_json "$REPO_SLUG" "$issue_id" 2>/dev/null || true)"
|
|
222
|
+
if [[ -z "$issue_json" ]]; then
|
|
223
|
+
issue_json='{}'
|
|
224
|
+
fi
|
|
225
|
+
issue_body="$(jq -r '.body // ""' <<<"$issue_json")"
|
|
226
|
+
ISSUE_BODY="$issue_body" node <<'EOF'
|
|
227
|
+
const body = process.env.ISSUE_BODY || '';
|
|
228
|
+
const match = body.match(/^\s*(?:Agent schedule|Schedule|Cadence)\s*:\s*(?:every\s+)?(\d+)\s*([mhd])\s*$/im);
|
|
229
|
+
if (!match) {
|
|
230
|
+
process.stdout.write('\n');
|
|
231
|
+
process.exit(0);
|
|
232
|
+
}
|
|
233
|
+
process.stdout.write(`${match[1]}${String(match[2] || '').toLowerCase()}\n`);
|
|
234
|
+
EOF
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
heartbeat_issue_schedule_label() {
|
|
238
|
+
local issue_id="${1:?issue id required}"
|
|
239
|
+
local token
|
|
240
|
+
token="$(heartbeat_issue_schedule_token "$issue_id")"
|
|
241
|
+
if [[ -n "$token" ]]; then
|
|
242
|
+
printf 'agent-schedule-%s\n' "$token"
|
|
243
|
+
fi
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
heartbeat_issue_is_scheduled() {
|
|
247
|
+
local issue_id="${1:?issue id required}"
|
|
248
|
+
local interval_seconds
|
|
249
|
+
interval_seconds="$(heartbeat_issue_schedule_interval_seconds "$issue_id")"
|
|
250
|
+
if [[ "${interval_seconds}" =~ ^[1-9][0-9]*$ ]]; then
|
|
251
|
+
printf 'yes\n'
|
|
252
|
+
else
|
|
253
|
+
printf 'no\n'
|
|
254
|
+
fi
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
heartbeat_issue_is_exclusive() {
|
|
258
|
+
local issue_id="${1:?issue id required}"
|
|
259
|
+
local issue_json
|
|
260
|
+
issue_json="$(flow_github_issue_view_json "$REPO_SLUG" "$issue_id" 2>/dev/null || true)"
|
|
261
|
+
if [[ -n "$issue_json" ]] && jq -e --arg exclusiveLabel "${AGENT_EXCLUSIVE_LABEL}" 'any(.labels[]?; .name == $exclusiveLabel)' >/dev/null <<<"$issue_json"; then
|
|
262
|
+
printf 'yes\n'
|
|
263
|
+
else
|
|
264
|
+
printf 'no\n'
|
|
265
|
+
fi
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
heartbeat_pr_is_exclusive() {
|
|
269
|
+
local pr_number="${1:?pr number required}"
|
|
270
|
+
local pr_json
|
|
271
|
+
pr_json="$(flow_github_pr_view_json "$REPO_SLUG" "$pr_number" 2>/dev/null || true)"
|
|
272
|
+
if [[ -n "$pr_json" ]] && jq -e --arg exclusiveLabel "${AGENT_EXCLUSIVE_LABEL}" 'any(.labels[]?; .name == $exclusiveLabel)' >/dev/null <<<"$pr_json"; then
|
|
273
|
+
printf 'yes\n'
|
|
274
|
+
else
|
|
275
|
+
printf 'no\n'
|
|
276
|
+
fi
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
heartbeat_sync_pr_labels() {
|
|
280
|
+
local pr_number="${1:?pr number required}"
|
|
281
|
+
"${ADAPTER_BIN_DIR}/sync-pr-labels.sh" "$pr_number"
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
heartbeat_pr_risk_json() {
|
|
285
|
+
local pr_number="${1:?pr number required}"
|
|
286
|
+
"${ADAPTER_BIN_DIR}/pr-risk.sh" "$pr_number"
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
heartbeat_mark_issue_running() {
|
|
290
|
+
local issue_id="${1:?issue id required}"
|
|
291
|
+
local is_heavy="${2:-no}"
|
|
292
|
+
if [[ "$is_heavy" == "yes" ]]; then
|
|
293
|
+
bash "${FLOW_TOOLS_DIR}/agent-github-update-labels" --repo-slug "$REPO_SLUG" --number "$issue_id" --remove agent-ready --remove agent-blocked --add agent-running --add agent-e2e-heavy >/dev/null
|
|
294
|
+
else
|
|
295
|
+
bash "${FLOW_TOOLS_DIR}/agent-github-update-labels" --repo-slug "$REPO_SLUG" --number "$issue_id" --remove agent-ready --remove agent-blocked --add agent-running >/dev/null
|
|
296
|
+
fi
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
heartbeat_issue_launch_failed() {
|
|
300
|
+
local issue_id="${1:?issue id required}"
|
|
301
|
+
bash "${FLOW_TOOLS_DIR}/agent-github-update-labels" --repo-slug "$REPO_SLUG" --number "$issue_id" --remove agent-running >/dev/null || true
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
heartbeat_ensure_issue_label_exists() {
|
|
305
|
+
local label_name="${1:?label required}"
|
|
306
|
+
local label_description="${2:-}"
|
|
307
|
+
local label_color="${3:-1D76DB}"
|
|
308
|
+
flow_github_label_create "$REPO_SLUG" "$label_name" "$label_description" "$label_color" >/dev/null 2>&1 || true
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
heartbeat_sync_issue_labels() {
|
|
312
|
+
local issue_id="${1:?issue id required}"
|
|
313
|
+
local issue_json issue_body schedule_token schedule_label label_name
|
|
314
|
+
local -a remove_args=()
|
|
315
|
+
local -a add_args=()
|
|
316
|
+
local -a update_args=()
|
|
317
|
+
|
|
318
|
+
issue_json="$(flow_github_issue_view_json "$REPO_SLUG" "$issue_id" 2>/dev/null || true)"
|
|
319
|
+
if [[ -z "$issue_json" ]]; then
|
|
320
|
+
return 0
|
|
321
|
+
fi
|
|
322
|
+
|
|
323
|
+
issue_body="$(jq -r '.body // ""' <<<"$issue_json")"
|
|
324
|
+
while IFS= read -r label_name; do
|
|
325
|
+
[[ -n "$label_name" ]] || continue
|
|
326
|
+
if [[ "$label_name" == agent-schedule-* ]]; then
|
|
327
|
+
remove_args+=(--remove "$label_name")
|
|
328
|
+
fi
|
|
329
|
+
done < <(jq -r '.labels[]?.name // empty' <<<"$issue_json")
|
|
330
|
+
remove_args+=(--remove agent-running --remove agent-blocked --remove agent-scheduled)
|
|
331
|
+
|
|
332
|
+
schedule_token="$(
|
|
333
|
+
ISSUE_BODY="$issue_body" node <<'EOF'
|
|
334
|
+
const body = process.env.ISSUE_BODY || '';
|
|
335
|
+
const match = body.match(/^\s*(?:Agent schedule|Schedule|Cadence)\s*:\s*(?:every\s+)?(\d+)\s*([mhd])\s*$/im);
|
|
336
|
+
if (!match) {
|
|
337
|
+
process.stdout.write('\n');
|
|
338
|
+
process.exit(0);
|
|
339
|
+
}
|
|
340
|
+
process.stdout.write(`${match[1]}${String(match[2] || '').toLowerCase()}\n`);
|
|
341
|
+
EOF
|
|
342
|
+
)"
|
|
343
|
+
|
|
344
|
+
if [[ -n "$schedule_token" ]]; then
|
|
345
|
+
heartbeat_ensure_issue_label_exists "agent-scheduled" "Recurring scheduled check issue" "5319E7"
|
|
346
|
+
add_args+=(--add agent-scheduled)
|
|
347
|
+
schedule_label="agent-schedule-${schedule_token}"
|
|
348
|
+
if [[ -n "$schedule_label" ]]; then
|
|
349
|
+
heartbeat_ensure_issue_label_exists "$schedule_label" "Scheduled recurring cadence for agent checks" "0E8A16"
|
|
350
|
+
add_args+=(--add "$schedule_label")
|
|
351
|
+
fi
|
|
352
|
+
fi
|
|
353
|
+
|
|
354
|
+
update_args=(
|
|
355
|
+
--repo-slug "$REPO_SLUG"
|
|
356
|
+
--number "$issue_id"
|
|
357
|
+
)
|
|
358
|
+
if ((${#remove_args[@]} > 0)); then
|
|
359
|
+
update_args+=("${remove_args[@]}")
|
|
360
|
+
fi
|
|
361
|
+
if ((${#add_args[@]} > 0)); then
|
|
362
|
+
update_args+=("${add_args[@]}")
|
|
363
|
+
fi
|
|
364
|
+
|
|
365
|
+
bash "${FLOW_TOOLS_DIR}/agent-github-update-labels" "${update_args[@]}" >/dev/null || true
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
heartbeat_issue_uses_resident_loop() {
|
|
369
|
+
local issue_id="${1:?issue id required}"
|
|
370
|
+
|
|
371
|
+
if ! flow_resident_issue_backend_supported "${CODING_WORKER}"; then
|
|
372
|
+
printf 'no\n'
|
|
373
|
+
return 0
|
|
374
|
+
fi
|
|
375
|
+
|
|
376
|
+
if ! flow_is_truthy "$(flow_resident_issue_workers_enabled "${CONFIG_YAML}")"; then
|
|
377
|
+
printf 'no\n'
|
|
378
|
+
return 0
|
|
379
|
+
fi
|
|
380
|
+
|
|
381
|
+
if [[ "$(heartbeat_issue_is_recurring "${issue_id}")" == "yes" || "$(heartbeat_issue_is_scheduled "${issue_id}")" == "yes" ]]; then
|
|
382
|
+
printf 'yes\n'
|
|
383
|
+
else
|
|
384
|
+
printf 'no\n'
|
|
385
|
+
fi
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
heartbeat_resident_idle_issue_controller_count() {
|
|
389
|
+
local resident_root controller_file controller_pid controller_state count=0
|
|
390
|
+
|
|
391
|
+
resident_root="$(flow_resident_workers_root "${CONFIG_YAML}")"
|
|
392
|
+
for controller_file in "${resident_root}"/issues/*/controller.env; do
|
|
393
|
+
[[ -f "${controller_file}" ]] || continue
|
|
394
|
+
controller_state="$(awk -F= '/^CONTROLLER_STATE=/{print $2; exit}' "${controller_file}" 2>/dev/null | tr -d '"' || true)"
|
|
395
|
+
[[ "${controller_state}" == "idle" ]] || continue
|
|
396
|
+
controller_pid="$(awk -F= '/^CONTROLLER_PID=/{print $2; exit}' "${controller_file}" 2>/dev/null | tr -d '"' || true)"
|
|
397
|
+
[[ "${controller_pid}" =~ ^[0-9]+$ ]] || continue
|
|
398
|
+
if kill -0 "${controller_pid}" 2>/dev/null; then
|
|
399
|
+
count=$((count + 1))
|
|
400
|
+
fi
|
|
401
|
+
done
|
|
402
|
+
|
|
403
|
+
printf '%s\n' "${count}"
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
heartbeat_issue_resident_lane_kind() {
|
|
407
|
+
local issue_id="${1:?issue id required}"
|
|
408
|
+
local interval_seconds=""
|
|
409
|
+
|
|
410
|
+
interval_seconds="$(heartbeat_issue_schedule_interval_seconds "${issue_id}")"
|
|
411
|
+
if [[ "${interval_seconds}" =~ ^[1-9][0-9]*$ ]]; then
|
|
412
|
+
printf 'scheduled\n'
|
|
413
|
+
else
|
|
414
|
+
printf 'recurring\n'
|
|
415
|
+
fi
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
heartbeat_issue_resident_lane_value() {
|
|
419
|
+
local issue_id="${1:?issue id required}"
|
|
420
|
+
local interval_seconds=""
|
|
421
|
+
|
|
422
|
+
interval_seconds="$(heartbeat_issue_schedule_interval_seconds "${issue_id}")"
|
|
423
|
+
if [[ "${interval_seconds}" =~ ^[1-9][0-9]*$ ]]; then
|
|
424
|
+
printf '%s\n' "${interval_seconds}"
|
|
425
|
+
else
|
|
426
|
+
printf 'general\n'
|
|
427
|
+
fi
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
heartbeat_issue_resident_worker_key() {
|
|
431
|
+
local issue_id="${1:?issue id required}"
|
|
432
|
+
local lane_kind=""
|
|
433
|
+
local lane_value=""
|
|
434
|
+
|
|
435
|
+
lane_kind="$(heartbeat_issue_resident_lane_kind "${issue_id}")"
|
|
436
|
+
lane_value="$(heartbeat_issue_resident_lane_value "${issue_id}")"
|
|
437
|
+
flow_resident_issue_lane_key "${CODING_WORKER}" "safe" "${lane_kind}" "${lane_value}"
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
heartbeat_live_issue_controller_for_lane() {
|
|
441
|
+
local issue_id="${1:?issue id required}"
|
|
442
|
+
local worker_key=""
|
|
443
|
+
|
|
444
|
+
worker_key="$(heartbeat_issue_resident_worker_key "${issue_id}")"
|
|
445
|
+
flow_resident_live_issue_controller_for_key "${CONFIG_YAML}" "${worker_key}" || return 1
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
heartbeat_enqueue_issue_for_live_resident_lane() {
|
|
449
|
+
local issue_id="${1:?issue id required}"
|
|
450
|
+
local live_controller=""
|
|
451
|
+
local controller_issue_id=""
|
|
452
|
+
|
|
453
|
+
live_controller="$(heartbeat_live_issue_controller_for_lane "${issue_id}" || true)"
|
|
454
|
+
[[ -n "${live_controller}" ]] || return 1
|
|
455
|
+
|
|
456
|
+
controller_issue_id="$(awk -F= '/^ISSUE_ID=/{print $2; exit}' <<<"${live_controller}")"
|
|
457
|
+
if [[ -n "${controller_issue_id}" && "${controller_issue_id}" == "${issue_id}" ]]; then
|
|
458
|
+
printf 'QUEUE_STATUS=controller-already-active\n'
|
|
459
|
+
printf 'ISSUE_ID=%s\n' "${issue_id}"
|
|
460
|
+
return 0
|
|
461
|
+
fi
|
|
462
|
+
|
|
463
|
+
flow_resident_issue_enqueue "${CONFIG_YAML}" "${issue_id}" "heartbeat-live-lane" >/dev/null
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
heartbeat_enqueue_issue_for_resident_controller() {
|
|
467
|
+
local issue_id="${1:?issue id required}"
|
|
468
|
+
local idle_controller_count queue_depth
|
|
469
|
+
|
|
470
|
+
idle_controller_count="$(heartbeat_resident_idle_issue_controller_count)"
|
|
471
|
+
[[ "${idle_controller_count}" =~ ^[0-9]+$ ]] || idle_controller_count="0"
|
|
472
|
+
if (( idle_controller_count <= 0 )); then
|
|
473
|
+
return 1
|
|
474
|
+
fi
|
|
475
|
+
|
|
476
|
+
queue_depth="$(flow_resident_issue_queue_count "${CONFIG_YAML}")"
|
|
477
|
+
[[ "${queue_depth}" =~ ^[0-9]+$ ]] || queue_depth="0"
|
|
478
|
+
if (( queue_depth >= idle_controller_count )); then
|
|
479
|
+
return 1
|
|
480
|
+
fi
|
|
481
|
+
|
|
482
|
+
flow_resident_issue_enqueue "${CONFIG_YAML}" "${issue_id}" "heartbeat" >/dev/null
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
heartbeat_start_issue_worker() {
|
|
486
|
+
local issue_id="${1:?issue id required}"
|
|
487
|
+
if [[ "$(heartbeat_issue_uses_resident_loop "${issue_id}")" == "yes" ]]; then
|
|
488
|
+
if heartbeat_enqueue_issue_for_live_resident_lane "${issue_id}"; then
|
|
489
|
+
printf 'LAUNCH_MODE=resident-lease\n'
|
|
490
|
+
return 0
|
|
491
|
+
fi
|
|
492
|
+
if heartbeat_enqueue_issue_for_resident_controller "${issue_id}"; then
|
|
493
|
+
printf 'LAUNCH_MODE=resident-lease\n'
|
|
494
|
+
return 0
|
|
495
|
+
fi
|
|
496
|
+
"${DETACHED_LAUNCH_BIN}" --pending-key "issue-${issue_id}" "issue-${issue_id}" "${RESIDENT_ISSUE_LOOP_BIN}" "$issue_id"
|
|
497
|
+
else
|
|
498
|
+
"${DETACHED_LAUNCH_BIN}" --pending-key "issue-${issue_id}" "issue-${issue_id}" "${FLOW_TOOLS_DIR}/start-issue-worker.sh" "$issue_id"
|
|
499
|
+
fi
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
heartbeat_mark_pr_running() {
|
|
503
|
+
local pr_number="${1:?pr number required}"
|
|
504
|
+
bash "${FLOW_TOOLS_DIR}/agent-github-update-labels" --repo-slug "$REPO_SLUG" --number "$pr_number" --add agent-running --remove agent-blocked >/dev/null || true
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
heartbeat_clear_pr_running() {
|
|
508
|
+
local pr_number="${1:?pr number required}"
|
|
509
|
+
bash "${FLOW_TOOLS_DIR}/agent-github-update-labels" --repo-slug "$REPO_SLUG" --number "$pr_number" --remove agent-running >/dev/null || true
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
heartbeat_start_pr_review_worker() {
|
|
513
|
+
local pr_number="${1:?pr number required}"
|
|
514
|
+
"${DETACHED_LAUNCH_BIN}" --pending-key "pr-${pr_number}" "pr-review-${pr_number}" "${FLOW_TOOLS_DIR}/start-pr-review-worker.sh" "$pr_number"
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
heartbeat_start_pr_merge_repair_worker() {
|
|
518
|
+
local pr_number="${1:?pr number required}"
|
|
519
|
+
"${DETACHED_LAUNCH_BIN}" --pending-key "pr-${pr_number}" "pr-merge-repair-${pr_number}" "${FLOW_TOOLS_DIR}/start-pr-merge-repair-worker.sh" "$pr_number"
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
heartbeat_start_pr_fix_worker() {
|
|
523
|
+
local pr_number="${1:?pr number required}"
|
|
524
|
+
"${DETACHED_LAUNCH_BIN}" --pending-key "pr-${pr_number}" "pr-fix-${pr_number}" "${FLOW_TOOLS_DIR}/start-pr-fix-worker.sh" "$pr_number"
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
heartbeat_start_pr_ci_refresh() {
|
|
528
|
+
local pr_number="${1:?pr number required}"
|
|
529
|
+
local state_root
|
|
530
|
+
state_root="$(flow_resolve_state_root "${CONFIG_YAML}")"
|
|
531
|
+
local head_sha run_ids run_id rerun_count=0
|
|
532
|
+
|
|
533
|
+
head_sha="$(flow_github_api_repo "${REPO_SLUG}" "pulls/${pr_number}" --jq .head.sha)"
|
|
534
|
+
run_ids="$(
|
|
535
|
+
flow_github_api_repo "${REPO_SLUG}" "commits/${head_sha}/check-runs" \
|
|
536
|
+
| jq -r '.check_runs[]
|
|
537
|
+
| select((.conclusion // "") == "failure")
|
|
538
|
+
| (.details_url // "")
|
|
539
|
+
| capture("/actions/runs/(?<id>[0-9]+)")?
|
|
540
|
+
| .id // empty' \
|
|
541
|
+
| sort -u
|
|
542
|
+
)"
|
|
543
|
+
|
|
544
|
+
if [[ -z "$run_ids" ]]; then
|
|
545
|
+
printf 'CI_REFRESH_STATUS=no-failed-runs\n'
|
|
546
|
+
return 0
|
|
547
|
+
fi
|
|
548
|
+
|
|
549
|
+
while IFS= read -r run_id; do
|
|
550
|
+
[[ -n "$run_id" ]] || continue
|
|
551
|
+
if flow_github_api_repo "${REPO_SLUG}" "actions/runs/${run_id}/rerun-failed-jobs" --method POST >/dev/null 2>&1 \
|
|
552
|
+
|| flow_github_api_repo "${REPO_SLUG}" "actions/runs/${run_id}/rerun" --method POST >/dev/null 2>&1; then
|
|
553
|
+
rerun_count=$((rerun_count + 1))
|
|
554
|
+
fi
|
|
555
|
+
done <<<"$run_ids"
|
|
556
|
+
|
|
557
|
+
"${FLOW_TOOLS_DIR}/retry-state.sh" pr "$pr_number" schedule "ci-refresh-rerun" >/dev/null || true
|
|
558
|
+
|
|
559
|
+
printf 'CI_REFRESH_STATUS=rerun-requested\n'
|
|
560
|
+
printf 'PR_NUMBER=%s\n' "$pr_number"
|
|
561
|
+
printf 'HEAD_SHA=%s\n' "$head_sha"
|
|
562
|
+
printf 'RERUN_COUNT=%s\n' "$rerun_count"
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
heartbeat_reconcile_issue() {
|
|
566
|
+
local session="${1:?session required}"
|
|
567
|
+
"${FLOW_TOOLS_DIR}/reconcile-issue-worker.sh" "$session"
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
heartbeat_reconcile_pr() {
|
|
571
|
+
local session="${1:?session required}"
|
|
572
|
+
"${FLOW_TOOLS_DIR}/reconcile-pr-worker.sh" "$session"
|
|
573
|
+
}
|