oh-my-super-agent 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/.agents/agents/advisor.md +15 -0
- package/.agents/agents/conductor.md +32 -0
- package/.agents/agents/dreamer.md +13 -0
- package/.agents/agents/executor.md +17 -0
- package/.agents/agents/grader.md +15 -0
- package/.agents/config/endurance-policy.json +8 -0
- package/.agents/config/oms-config.json +119 -0
- package/.agents/config/release-policy.json +12 -0
- package/.agents/config/secret-scan-policy.json +7 -0
- package/.agents/config/verification-plan.json +33 -0
- package/.agents/registry.json +11 -0
- package/.agents/rules/constitution.md +7 -0
- package/.agents/skills/conductor/SKILL.md +23 -0
- package/.agents/skills/dream/SKILL.md +14 -0
- package/.agents/skills/executor/SKILL.md +13 -0
- package/.agents/skills/oms/SKILL.md +52 -0
- package/.agents/skills/quota-aware/SKILL.md +12 -0
- package/.agents/skills/schedule/SKILL.md +13 -0
- package/.agents/skills/team-protocol/SKILL.md +20 -0
- package/LICENSE +21 -0
- package/README.md +146 -0
- package/dist/src/audit/run-ledger.d.ts +183 -0
- package/dist/src/audit/run-ledger.js +1655 -0
- package/dist/src/audit/run-ledger.js.map +1 -0
- package/dist/src/cli.d.ts +61 -0
- package/dist/src/cli.js +2096 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/commands/github-queue-probe.d.ts +26 -0
- package/dist/src/commands/github-queue-probe.js +51 -0
- package/dist/src/commands/github-queue-probe.js.map +1 -0
- package/dist/src/commands/trace-fixture.d.ts +20 -0
- package/dist/src/commands/trace-fixture.js +72 -0
- package/dist/src/commands/trace-fixture.js.map +1 -0
- package/dist/src/conductor/activity.d.ts +46 -0
- package/dist/src/conductor/activity.js +224 -0
- package/dist/src/conductor/activity.js.map +1 -0
- package/dist/src/conductor/bridge.d.ts +53 -0
- package/dist/src/conductor/bridge.js +652 -0
- package/dist/src/conductor/bridge.js.map +1 -0
- package/dist/src/conductor/notifications.d.ts +59 -0
- package/dist/src/conductor/notifications.js +381 -0
- package/dist/src/conductor/notifications.js.map +1 -0
- package/dist/src/conductor/recovery.d.ts +29 -0
- package/dist/src/conductor/recovery.js +198 -0
- package/dist/src/conductor/recovery.js.map +1 -0
- package/dist/src/conductor/start.d.ts +73 -0
- package/dist/src/conductor/start.js +519 -0
- package/dist/src/conductor/start.js.map +1 -0
- package/dist/src/conductor/waiter.d.ts +88 -0
- package/dist/src/conductor/waiter.js +427 -0
- package/dist/src/conductor/waiter.js.map +1 -0
- package/dist/src/config.d.ts +9 -0
- package/dist/src/config.js +40 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/dispatch/advice-source.d.ts +61 -0
- package/dist/src/dispatch/advice-source.js +198 -0
- package/dist/src/dispatch/advice-source.js.map +1 -0
- package/dist/src/dispatch/advice-store.d.ts +41 -0
- package/dist/src/dispatch/advice-store.js +201 -0
- package/dist/src/dispatch/advice-store.js.map +1 -0
- package/dist/src/dispatch/advice.d.ts +34 -0
- package/dist/src/dispatch/advice.js +371 -0
- package/dist/src/dispatch/advice.js.map +1 -0
- package/dist/src/dispatch/authority.d.ts +124 -0
- package/dist/src/dispatch/authority.js +1202 -0
- package/dist/src/dispatch/authority.js.map +1 -0
- package/dist/src/dispatch/intent.d.ts +66 -0
- package/dist/src/dispatch/intent.js +71 -0
- package/dist/src/dispatch/intent.js.map +1 -0
- package/dist/src/dispatch/runtime-authority.d.ts +42 -0
- package/dist/src/dispatch/runtime-authority.js +52 -0
- package/dist/src/dispatch/runtime-authority.js.map +1 -0
- package/dist/src/doctor.d.ts +20 -0
- package/dist/src/doctor.js +85 -0
- package/dist/src/doctor.js.map +1 -0
- package/dist/src/domain/records.d.ts +44 -0
- package/dist/src/domain/records.js +138 -0
- package/dist/src/domain/records.js.map +1 -0
- package/dist/src/domain/role-policy.d.ts +67 -0
- package/dist/src/domain/role-policy.js +547 -0
- package/dist/src/domain/role-policy.js.map +1 -0
- package/dist/src/events/bus.d.ts +32 -0
- package/dist/src/events/bus.js +115 -0
- package/dist/src/events/bus.js.map +1 -0
- package/dist/src/events/kinds.d.ts +126 -0
- package/dist/src/events/kinds.js +14 -0
- package/dist/src/events/kinds.js.map +1 -0
- package/dist/src/evidence/immutable-file.d.ts +12 -0
- package/dist/src/evidence/immutable-file.js +141 -0
- package/dist/src/evidence/immutable-file.js.map +1 -0
- package/dist/src/evidence/store.d.ts +125 -0
- package/dist/src/evidence/store.js +1189 -0
- package/dist/src/evidence/store.js.map +1 -0
- package/dist/src/evidence/verdict.d.ts +17 -0
- package/dist/src/evidence/verdict.js +23 -0
- package/dist/src/evidence/verdict.js.map +1 -0
- package/dist/src/generation/agent.d.ts +5 -0
- package/dist/src/generation/agent.js +34 -0
- package/dist/src/generation/agent.js.map +1 -0
- package/dist/src/generation/frontmatter.d.ts +7 -0
- package/dist/src/generation/frontmatter.js +33 -0
- package/dist/src/generation/frontmatter.js.map +1 -0
- package/dist/src/github/adapter.d.ts +44 -0
- package/dist/src/github/adapter.js +592 -0
- package/dist/src/github/adapter.js.map +1 -0
- package/dist/src/github/dispatch-eligibility.d.ts +9 -0
- package/dist/src/github/dispatch-eligibility.js +94 -0
- package/dist/src/github/dispatch-eligibility.js.map +1 -0
- package/dist/src/github/projector.d.ts +23 -0
- package/dist/src/github/projector.js +181 -0
- package/dist/src/github/projector.js.map +1 -0
- package/dist/src/github/review.d.ts +39 -0
- package/dist/src/github/review.js +1450 -0
- package/dist/src/github/review.js.map +1 -0
- package/dist/src/github/sync.d.ts +21 -0
- package/dist/src/github/sync.js +518 -0
- package/dist/src/github/sync.js.map +1 -0
- package/dist/src/github/types.d.ts +134 -0
- package/dist/src/github/types.js +11 -0
- package/dist/src/github/types.js.map +1 -0
- package/dist/src/goals/artifact-store.d.ts +31 -0
- package/dist/src/goals/artifact-store.js +241 -0
- package/dist/src/goals/artifact-store.js.map +1 -0
- package/dist/src/goals/authority.d.ts +112 -0
- package/dist/src/goals/authority.js +621 -0
- package/dist/src/goals/authority.js.map +1 -0
- package/dist/src/goals/native-snapshot.d.ts +12 -0
- package/dist/src/goals/native-snapshot.js +53 -0
- package/dist/src/goals/native-snapshot.js.map +1 -0
- package/dist/src/goals/runtime-authority.d.ts +7 -0
- package/dist/src/goals/runtime-authority.js +20 -0
- package/dist/src/goals/runtime-authority.js.map +1 -0
- package/dist/src/health/release-assessment.d.ts +11 -0
- package/dist/src/health/release-assessment.js +83 -0
- package/dist/src/health/release-assessment.js.map +1 -0
- package/dist/src/health/release-policy.d.ts +16 -0
- package/dist/src/health/release-policy.js +40 -0
- package/dist/src/health/release-policy.js.map +1 -0
- package/dist/src/hooks/native.d.ts +30 -0
- package/dist/src/hooks/native.js +495 -0
- package/dist/src/hooks/native.js.map +1 -0
- package/dist/src/hooks/provider-runtime.d.ts +55 -0
- package/dist/src/hooks/provider-runtime.js +479 -0
- package/dist/src/hooks/provider-runtime.js.map +1 -0
- package/dist/src/hooks/provider.d.ts +102 -0
- package/dist/src/hooks/provider.js +358 -0
- package/dist/src/hooks/provider.js.map +1 -0
- package/dist/src/live/contact-journal.d.ts +73 -0
- package/dist/src/live/contact-journal.js +439 -0
- package/dist/src/live/contact-journal.js.map +1 -0
- package/dist/src/live-probes/gh-adapter.d.ts +28 -0
- package/dist/src/live-probes/gh-adapter.js +188 -0
- package/dist/src/live-probes/gh-adapter.js.map +1 -0
- package/dist/src/live-probes/github-queue.d.ts +1 -0
- package/dist/src/live-probes/github-queue.js +2 -0
- package/dist/src/live-probes/github-queue.js.map +1 -0
- package/dist/src/notifications/slack-request.d.ts +13 -0
- package/dist/src/notifications/slack-request.js +40 -0
- package/dist/src/notifications/slack-request.js.map +1 -0
- package/dist/src/outbox/processor.d.ts +27 -0
- package/dist/src/outbox/processor.js +63 -0
- package/dist/src/outbox/processor.js.map +1 -0
- package/dist/src/outbox/store.d.ts +158 -0
- package/dist/src/outbox/store.js +834 -0
- package/dist/src/outbox/store.js.map +1 -0
- package/dist/src/package-root.d.ts +1 -0
- package/dist/src/package-root.js +26 -0
- package/dist/src/package-root.js.map +1 -0
- package/dist/src/project.d.ts +12 -0
- package/dist/src/project.js +60 -0
- package/dist/src/project.js.map +1 -0
- package/dist/src/projection/generated-file.d.ts +15 -0
- package/dist/src/projection/generated-file.js +72 -0
- package/dist/src/projection/generated-file.js.map +1 -0
- package/dist/src/projection/project-workspace.d.ts +11 -0
- package/dist/src/projection/project-workspace.js +94 -0
- package/dist/src/projection/project-workspace.js.map +1 -0
- package/dist/src/projection/registry.d.ts +15 -0
- package/dist/src/projection/registry.js +59 -0
- package/dist/src/projection/registry.js.map +1 -0
- package/dist/src/projection/safe-path.d.ts +4 -0
- package/dist/src/projection/safe-path.js +106 -0
- package/dist/src/projection/safe-path.js.map +1 -0
- package/dist/src/providers/claude-interactive.d.ts +38 -0
- package/dist/src/providers/claude-interactive.js +287 -0
- package/dist/src/providers/claude-interactive.js.map +1 -0
- package/dist/src/providers/claude-structured-bridge.d.ts +32 -0
- package/dist/src/providers/claude-structured-bridge.js +215 -0
- package/dist/src/providers/claude-structured-bridge.js.map +1 -0
- package/dist/src/providers/claude-structured-completion.d.ts +23 -0
- package/dist/src/providers/claude-structured-completion.js +229 -0
- package/dist/src/providers/claude-structured-completion.js.map +1 -0
- package/dist/src/providers/claude-structured-pane.d.ts +23 -0
- package/dist/src/providers/claude-structured-pane.js +156 -0
- package/dist/src/providers/claude-structured-pane.js.map +1 -0
- package/dist/src/providers/claude-structured-store.d.ts +48 -0
- package/dist/src/providers/claude-structured-store.js +212 -0
- package/dist/src/providers/claude-structured-store.js.map +1 -0
- package/dist/src/providers/claude-structured.d.ts +56 -0
- package/dist/src/providers/claude-structured.js +250 -0
- package/dist/src/providers/claude-structured.js.map +1 -0
- package/dist/src/providers/codex-exec.d.ts +29 -0
- package/dist/src/providers/codex-exec.js +127 -0
- package/dist/src/providers/codex-exec.js.map +1 -0
- package/dist/src/providers/grading.d.ts +2 -0
- package/dist/src/providers/grading.js +20 -0
- package/dist/src/providers/grading.js.map +1 -0
- package/dist/src/providers/native-dispatch.d.ts +24 -0
- package/dist/src/providers/native-dispatch.js +34 -0
- package/dist/src/providers/native-dispatch.js.map +1 -0
- package/dist/src/providers/preflight.d.ts +65 -0
- package/dist/src/providers/preflight.js +256 -0
- package/dist/src/providers/preflight.js.map +1 -0
- package/dist/src/providers/process.d.ts +18 -0
- package/dist/src/providers/process.js +21 -0
- package/dist/src/providers/process.js.map +1 -0
- package/dist/src/queue/model.d.ts +37 -0
- package/dist/src/queue/model.js +51 -0
- package/dist/src/queue/model.js.map +1 -0
- package/dist/src/queue/service.d.ts +1 -0
- package/dist/src/queue/service.js +2 -0
- package/dist/src/queue/service.js.map +1 -0
- package/dist/src/reflections/store.d.ts +21 -0
- package/dist/src/reflections/store.js +60 -0
- package/dist/src/reflections/store.js.map +1 -0
- package/dist/src/reports/daily-trust.d.ts +11 -0
- package/dist/src/reports/daily-trust.js +98 -0
- package/dist/src/reports/daily-trust.js.map +1 -0
- package/dist/src/runs/controller.d.ts +187 -0
- package/dist/src/runs/controller.js +1182 -0
- package/dist/src/runs/controller.js.map +1 -0
- package/dist/src/runtime/composition.d.ts +9 -0
- package/dist/src/runtime/composition.js +35 -0
- package/dist/src/runtime/composition.js.map +1 -0
- package/dist/src/runtime/endurance-authorities.d.ts +44 -0
- package/dist/src/runtime/endurance-authorities.js +101 -0
- package/dist/src/runtime/endurance-authorities.js.map +1 -0
- package/dist/src/runtime/endurance-policy.d.ts +12 -0
- package/dist/src/runtime/endurance-policy.js +13 -0
- package/dist/src/runtime/endurance-policy.js.map +1 -0
- package/dist/src/runtime/lock.d.ts +63 -0
- package/dist/src/runtime/lock.js +577 -0
- package/dist/src/runtime/lock.js.map +1 -0
- package/dist/src/runtime/process-identity.d.ts +10 -0
- package/dist/src/runtime/process-identity.js +43 -0
- package/dist/src/runtime/process-identity.js.map +1 -0
- package/dist/src/runtime/quota.d.ts +130 -0
- package/dist/src/runtime/quota.js +590 -0
- package/dist/src/runtime/quota.js.map +1 -0
- package/dist/src/runtime/record-store.d.ts +45 -0
- package/dist/src/runtime/record-store.js +272 -0
- package/dist/src/runtime/record-store.js.map +1 -0
- package/dist/src/runtime/schema.d.ts +28 -0
- package/dist/src/runtime/schema.js +194 -0
- package/dist/src/runtime/schema.js.map +1 -0
- package/dist/src/runtime/stable-id.d.ts +3 -0
- package/dist/src/runtime/stable-id.js +27 -0
- package/dist/src/runtime/stable-id.js.map +1 -0
- package/dist/src/runtime/system-clock.d.ts +8 -0
- package/dist/src/runtime/system-clock.js +35 -0
- package/dist/src/runtime/system-clock.js.map +1 -0
- package/dist/src/schedule/service-plan.d.ts +58 -0
- package/dist/src/schedule/service-plan.js +327 -0
- package/dist/src/schedule/service-plan.js.map +1 -0
- package/dist/src/schedule/user-installation.d.ts +62 -0
- package/dist/src/schedule/user-installation.js +701 -0
- package/dist/src/schedule/user-installation.js.map +1 -0
- package/dist/src/schedule/user-plan.d.ts +47 -0
- package/dist/src/schedule/user-plan.js +286 -0
- package/dist/src/schedule/user-plan.js.map +1 -0
- package/dist/src/scheduler/minute.d.ts +31 -0
- package/dist/src/scheduler/minute.js +441 -0
- package/dist/src/scheduler/minute.js.map +1 -0
- package/dist/src/schemas/registry.d.ts +10 -0
- package/dist/src/schemas/registry.js +36 -0
- package/dist/src/schemas/registry.js.map +1 -0
- package/dist/src/security/secret-scan.d.ts +50 -0
- package/dist/src/security/secret-scan.js +384 -0
- package/dist/src/security/secret-scan.js.map +1 -0
- package/dist/src/sessions/registry.d.ts +89 -0
- package/dist/src/sessions/registry.js +443 -0
- package/dist/src/sessions/registry.js.map +1 -0
- package/dist/src/state.d.ts +27 -0
- package/dist/src/state.js +235 -0
- package/dist/src/state.js.map +1 -0
- package/dist/src/status/hud.d.ts +37 -0
- package/dist/src/status/hud.js +88 -0
- package/dist/src/status/hud.js.map +1 -0
- package/dist/src/team/plan.d.ts +31 -0
- package/dist/src/team/plan.js +184 -0
- package/dist/src/team/plan.js.map +1 -0
- package/dist/src/team/projection.d.ts +24 -0
- package/dist/src/team/projection.js +79 -0
- package/dist/src/team/projection.js.map +1 -0
- package/dist/src/tickets/admission.d.ts +34 -0
- package/dist/src/tickets/admission.js +169 -0
- package/dist/src/tickets/admission.js.map +1 -0
- package/dist/src/tickets/materializer.d.ts +1 -0
- package/dist/src/tickets/materializer.js +2 -0
- package/dist/src/tickets/materializer.js.map +1 -0
- package/dist/src/tickets/runtime-authority.d.ts +32 -0
- package/dist/src/tickets/runtime-authority.js +46 -0
- package/dist/src/tickets/runtime-authority.js.map +1 -0
- package/dist/src/tickets/store.d.ts +221 -0
- package/dist/src/tickets/store.js +2025 -0
- package/dist/src/tickets/store.js.map +1 -0
- package/dist/src/tracer/one-ticket.d.ts +58 -0
- package/dist/src/tracer/one-ticket.js +578 -0
- package/dist/src/tracer/one-ticket.js.map +1 -0
- package/dist/src/trust/assessment.d.ts +24 -0
- package/dist/src/trust/assessment.js +124 -0
- package/dist/src/trust/assessment.js.map +1 -0
- package/dist/src/trust/runs.d.ts +13 -0
- package/dist/src/trust/runs.js +46 -0
- package/dist/src/trust/runs.js.map +1 -0
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/fs.d.ts +13 -0
- package/dist/src/utils/fs.js +188 -0
- package/dist/src/utils/fs.js.map +1 -0
- package/dist/src/verification/authority.d.ts +28 -0
- package/dist/src/verification/authority.js +153 -0
- package/dist/src/verification/authority.js.map +1 -0
- package/dist/src/verification/grade-source.d.ts +17 -0
- package/dist/src/verification/grade-source.js +30 -0
- package/dist/src/verification/grade-source.js.map +1 -0
- package/dist/src/verification/plan.d.ts +20 -0
- package/dist/src/verification/plan.js +128 -0
- package/dist/src/verification/plan.js.map +1 -0
- package/dist/src/verification/protected-runner.d.ts +50 -0
- package/dist/src/verification/protected-runner.js +171 -0
- package/dist/src/verification/protected-runner.js.map +1 -0
- package/dist/src/verification/result-gate-store.d.ts +72 -0
- package/dist/src/verification/result-gate-store.js +193 -0
- package/dist/src/verification/result-gate-store.js.map +1 -0
- package/dist/src/verification/result-gate.d.ts +41 -0
- package/dist/src/verification/result-gate.js +731 -0
- package/dist/src/verification/result-gate.js.map +1 -0
- package/dist/src/verification/runner.d.ts +38 -0
- package/dist/src/verification/runner.js +143 -0
- package/dist/src/verification/runner.js.map +1 -0
- package/dist/src/verification/sandbox.d.ts +16 -0
- package/dist/src/verification/sandbox.js +199 -0
- package/dist/src/verification/sandbox.js.map +1 -0
- package/dist/src/verify.d.ts +8 -0
- package/dist/src/verify.js +35 -0
- package/dist/src/verify.js.map +1 -0
- package/dist/src/watchdog/reconcile.d.ts +42 -0
- package/dist/src/watchdog/reconcile.js +440 -0
- package/dist/src/watchdog/reconcile.js.map +1 -0
- package/dist/src/workers/bridge.d.ts +35 -0
- package/dist/src/workers/bridge.js +426 -0
- package/dist/src/workers/bridge.js.map +1 -0
- package/dist/src/workers/delivery.d.ts +31 -0
- package/dist/src/workers/delivery.js +876 -0
- package/dist/src/workers/delivery.js.map +1 -0
- package/dist/src/workers/panes.d.ts +32 -0
- package/dist/src/workers/panes.js +212 -0
- package/dist/src/workers/panes.js.map +1 -0
- package/dist/src/workers/registry.d.ts +80 -0
- package/dist/src/workers/registry.js +351 -0
- package/dist/src/workers/registry.js.map +1 -0
- package/dist/src/workers/runtime.d.ts +44 -0
- package/dist/src/workers/runtime.js +21 -0
- package/dist/src/workers/runtime.js.map +1 -0
- package/dist/src/worktrees/manager.d.ts +35 -0
- package/dist/src/worktrees/manager.js +315 -0
- package/dist/src/worktrees/manager.js.map +1 -0
- package/docs/ARCHITECTURE.md +323 -0
- package/docs/PLAN.md +216 -0
- package/docs/REFERENCES.md +42 -0
- package/docs/ROADMAP.md +327 -0
- package/docs/SECURITY.md +242 -0
- package/docs/adr/0001-tracer-first-file-backed-certification.md +41 -0
- package/docs/adr/0002-conductor-first-typed-dispatch.md +102 -0
- package/docs/adr/0003-mandatory-pre-dispatch-advice.md +59 -0
- package/docs/compatibility/claude-code-2.1.207.md +25 -0
- package/loop/contract.md +102 -0
- package/package.json +54 -0
- package/schemas/advisor-evidence.schema.json +54 -0
- package/schemas/advisor-output.schema.json +31 -0
- package/schemas/conductor-activity-payload.schema.json +38 -0
- package/schemas/conductor-decision.schema.json +29 -0
- package/schemas/conductor-dispatch-intent.schema.json +71 -0
- package/schemas/conductor-dispatch-preparation.schema.json +46 -0
- package/schemas/conductor-dispatch-proposal.schema.json +82 -0
- package/schemas/conductor-goal-proposal.schema.json +30 -0
- package/schemas/conductor-manage-worker.schema.json +17 -0
- package/schemas/conductor-notification-payload.schema.json +39 -0
- package/schemas/conductor-process-result.schema.json +14 -0
- package/schemas/conductor-route.schema.json +51 -0
- package/schemas/conductor-start-team.schema.json +16 -0
- package/schemas/conductor-waiter-payload.schema.json +68 -0
- package/schemas/deterministic-check.schema.json +107 -0
- package/schemas/dispatch-acknowledgement.schema.json +15 -0
- package/schemas/dispatch-advice-payload.schema.json +64 -0
- package/schemas/dispatch-payload.schema.json +131 -0
- package/schemas/dispatch-result.schema.json +28 -0
- package/schemas/endurance-policy.schema.json +16 -0
- package/schemas/events/dispatch-delivery-requested.schema.json +17 -0
- package/schemas/events/github-observed.schema.json +28 -0
- package/schemas/events/native-hook-observed.schema.json +35 -0
- package/schemas/events/provider-observed.schema.json +64 -0
- package/schemas/events/run-heartbeat-due.schema.json +10 -0
- package/schemas/events/slack-notification-requested.schema.json +14 -0
- package/schemas/events/structured-role-completed.schema.json +54 -0
- package/schemas/events/ticket-resume-due.schema.json +28 -0
- package/schemas/events/watchdog-lease-expired.schema.json +14 -0
- package/schemas/events/watchdog-outbox-stalled.schema.json +12 -0
- package/schemas/events/watchdog-session-stalled.schema.json +11 -0
- package/schemas/evidence-record.schema.json +37 -0
- package/schemas/executor-result.schema.json +17 -0
- package/schemas/github-observation.schema.json +33 -0
- package/schemas/github-watermark.schema.json +66 -0
- package/schemas/goal-artifact.schema.json +19 -0
- package/schemas/goal-create-input.schema.json +14 -0
- package/schemas/goal-executor-result.schema.json +18 -0
- package/schemas/goal-payload.schema.json +95 -0
- package/schemas/grader-output.schema.json +33 -0
- package/schemas/lease-expiry.schema.json +19 -0
- package/schemas/live-disclosure.schema.json +16 -0
- package/schemas/live-outcome.schema.json +52 -0
- package/schemas/native-goal-snapshot.schema.json +27 -0
- package/schemas/provider-observed.schema.json +64 -0
- package/schemas/quota-observation.schema.json +72 -0
- package/schemas/reflection-evidence.schema.json +61 -0
- package/schemas/reflection.schema.json +13 -0
- package/schemas/regression-request.schema.json +54 -0
- package/schemas/release-assessment.schema.json +34 -0
- package/schemas/release-policy.schema.json +30 -0
- package/schemas/result-gate-payload.schema.json +244 -0
- package/schemas/review-delivery-payload.schema.json +42 -0
- package/schemas/role-policy.schema.json +111 -0
- package/schemas/run-abort-input.schema.json +11 -0
- package/schemas/run-completion-proof.schema.json +62 -0
- package/schemas/run-ledger-entry.schema.json +78 -0
- package/schemas/run-manifest.schema.json +74 -0
- package/schemas/run-start-intent.schema.json +74 -0
- package/schemas/runtime-record.schema.json +111 -0
- package/schemas/service-plan.schema.json +35 -0
- package/schemas/session-payload.schema.json +80 -0
- package/schemas/structured-role-read-request.schema.json +14 -0
- package/schemas/structured-role-request.schema.json +44 -0
- package/schemas/structured-role-result.schema.json +38 -0
- package/schemas/structured-role-submit-result.schema.json +15 -0
- package/schemas/team-checkpoint.schema.json +42 -0
- package/schemas/team-plan.schema.json +30 -0
- package/schemas/ticket-content.schema.json +38 -0
- package/schemas/ticket-queue-payload.schema.json +191 -0
- package/schemas/trust-report.schema.json +68 -0
- package/schemas/trust-run.schema.json +47 -0
- package/schemas/ultragoal-checkpoint.schema.json +49 -0
- package/schemas/user-schedule-installation-v1.schema.json +32 -0
- package/schemas/user-schedule-installation.schema.json +38 -0
- package/schemas/user-schedule-plan.schema.json +39 -0
- package/schemas/verification-plan-evidence.schema.json +37 -0
- package/schemas/worker-acknowledge-dispatch.schema.json +12 -0
- package/schemas/worker-payload.schema.json +47 -0
- package/schemas/worker-read-dispatch.schema.json +11 -0
- package/schemas/worker-record-dispatch-result.schema.json +14 -0
|
@@ -0,0 +1,876 @@
|
|
|
1
|
+
import { existsSync, lstatSync, mkdirSync, realpathSync, symlinkSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, join } from "node:path";
|
|
3
|
+
import { readOmsConfig } from "../config.js";
|
|
4
|
+
import { captureStoredDispatchIntent, deriveWorktreeId, dispatchWorktreeStartCommit, } from "../dispatch/authority.js";
|
|
5
|
+
import { assertStoredAdvisorEvidenceProvenance } from "../dispatch/advice-source.js";
|
|
6
|
+
import { loadTrackedRolePolicyGate } from "../domain/role-policy.js";
|
|
7
|
+
import { assertOpaqueId } from "../domain/records.js";
|
|
8
|
+
import { deriveOperationNonce } from "../outbox/store.js";
|
|
9
|
+
import { SUPPORTED_PROVIDER_HOOK_VERSIONS } from "../hooks/provider.js";
|
|
10
|
+
import { discloseLiveContact, readLiveDeliveryAuthorization } from "../live/contact-journal.js";
|
|
11
|
+
import { prepareClaudeInteractiveLaunch } from "../providers/claude-interactive.js";
|
|
12
|
+
import { prepareCodexGoalLaunch } from "../providers/native-dispatch.js";
|
|
13
|
+
import { probeClaudeCodeCompatibility, resolveConfiguredRole } from "../providers/preflight.js";
|
|
14
|
+
import { runProcess } from "../providers/process.js";
|
|
15
|
+
import { createStableId } from "../runtime/stable-id.js";
|
|
16
|
+
import { errorMessage, lstatIfExists, readJsonFileNoFollow, validateExistingDirectory, writeJsonAtomicNoReplace, } from "../utils/fs.js";
|
|
17
|
+
import { parseTicketWorktreeRecord } from "../worktrees/manager.js";
|
|
18
|
+
import { createWorkerPaneAdapter } from "./panes.js";
|
|
19
|
+
import { createRuntimeWorkerAuthorities } from "./runtime.js";
|
|
20
|
+
const DELIVERY_CONSUMER = "oms-worker-delivery";
|
|
21
|
+
const HEARTBEAT_MS = 15 * 60 * 1_000;
|
|
22
|
+
export function createWorkerDeliveryService(options) {
|
|
23
|
+
const packageRoot = validateExistingDirectory(options.packageRoot, "package root");
|
|
24
|
+
const configRoot = validateExistingDirectory(options.configRoot ?? packageRoot, "configuration root");
|
|
25
|
+
const workspaceRoot = validateExistingDirectory(options.workspaceRoot, "worker workspace root");
|
|
26
|
+
const stateRoot = validateExistingDirectory(options.stateRoot, "worker state root");
|
|
27
|
+
const executablePath = validateExecutable(options.executablePath);
|
|
28
|
+
const env = options.env ?? process.env;
|
|
29
|
+
const runner = options.runner ?? runProcess;
|
|
30
|
+
const panes = options.panes ?? createWorkerPaneAdapter({ env, runner });
|
|
31
|
+
const clock = options.clock ?? (() => new Date().toISOString());
|
|
32
|
+
const runtime = createRuntimeWorkerAuthorities({
|
|
33
|
+
packageRoot,
|
|
34
|
+
configRoot,
|
|
35
|
+
workspaceRoot,
|
|
36
|
+
stateRoot,
|
|
37
|
+
actorId: "oms-conductor",
|
|
38
|
+
clock,
|
|
39
|
+
});
|
|
40
|
+
function launch(dispatch, sourceEventId) {
|
|
41
|
+
if (dispatch.state !== "accepted")
|
|
42
|
+
throw new Error(`worker delivery requires an accepted dispatch, got ${dispatch.state}`);
|
|
43
|
+
try {
|
|
44
|
+
assertApprovedDispatchAdvice(dispatch, runtime.tickets.evidenceStore, stateRoot);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
parkWorker(dispatch, sourceEventId, "wkr-adv-park");
|
|
48
|
+
return Object.freeze({
|
|
49
|
+
status: "parked",
|
|
50
|
+
dispatch_id: dispatch.record_id,
|
|
51
|
+
reason: boundedReason(errorMessage(error)),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const worker = runtime.workers.read(dispatch.record_id);
|
|
55
|
+
if (worker.state !== "idle" || (worker.payload.health !== "healthy" && worker.payload.health !== "parked")) {
|
|
56
|
+
throw new Error("worker delivery requires one idle healthy or parked reservation");
|
|
57
|
+
}
|
|
58
|
+
if (dispatch.payload.capabilities.length !== 2
|
|
59
|
+
|| dispatch.payload.capabilities[0] !== "repository-read"
|
|
60
|
+
|| dispatch.payload.capabilities[1] !== "ticket-worktree-write")
|
|
61
|
+
throw new Error("worker delivery received expanded capabilities");
|
|
62
|
+
let providerLaunch;
|
|
63
|
+
let liveDeliveryRepository = null;
|
|
64
|
+
try {
|
|
65
|
+
const config = readOmsConfig(configRoot);
|
|
66
|
+
const currentPolicy = loadTrackedRolePolicyGate(configRoot);
|
|
67
|
+
const configured = resolveConfiguredRole(config, dispatch.payload.role_id);
|
|
68
|
+
const ticket = runtime.tickets.lifecycle.read(dispatch.payload.ticket_id);
|
|
69
|
+
if (ticket.payload.source === "github") {
|
|
70
|
+
const content = runtime.tickets.materializer.readContent({
|
|
71
|
+
ticket_id: ticket.record_id,
|
|
72
|
+
sha256: ticket.payload.content_sha256,
|
|
73
|
+
file_name: ticket.payload.content_file,
|
|
74
|
+
});
|
|
75
|
+
if (content.repository === null)
|
|
76
|
+
throw new Error("GitHub worker ticket lacks its repository");
|
|
77
|
+
liveDeliveryRepository = content.repository.toLowerCase();
|
|
78
|
+
}
|
|
79
|
+
const worktree = parseTicketWorktreeRecord(readJsonFileNoFollow(join(stateRoot, "worktree-records", `${dispatch.payload.ticket_id}.json`), 64 * 1024), "worker delivery worktree record");
|
|
80
|
+
if (currentPolicy.digest !== dispatch.payload.policy_digest
|
|
81
|
+
|| configured.modelId !== dispatch.payload.model_id
|
|
82
|
+
|| configured.role.transport !== dispatch.payload.provider_mode
|
|
83
|
+
|| configured.role.sandbox !== "ticket-worktree-write"
|
|
84
|
+
|| runtime.tickets.lifecycle.authorityStatus(dispatch.payload.ticket_id) !== "current"
|
|
85
|
+
|| ticket.state !== "leased"
|
|
86
|
+
|| ticket.version !== dispatch.payload.ticket_version
|
|
87
|
+
|| ticket.attempt !== dispatch.payload.attempt
|
|
88
|
+
|| ticket.actor !== dispatch.payload.worker_id
|
|
89
|
+
|| ticket.lease_token === null
|
|
90
|
+
|| ticket.lease_token !== dispatch.payload.lease_token
|
|
91
|
+
|| ticket.payload.session_id !== dispatch.payload.session_id
|
|
92
|
+
|| ticket.payload.lease_expires_at === null
|
|
93
|
+
|| Date.parse(ticket.payload.lease_expires_at) <= Date.parse(clock())
|
|
94
|
+
|| worktree.ticket_id !== dispatch.payload.ticket_id
|
|
95
|
+
|| worktree.repository_root !== workspaceRoot
|
|
96
|
+
|| worktree.worktree_root !== dispatch.payload.worktree_path
|
|
97
|
+
|| worktree.branch !== dispatch.payload.worktree_branch
|
|
98
|
+
|| worktree.base_commit !== dispatch.payload.worktree_base_commit
|
|
99
|
+
|| deriveWorktreeId(worktree) !== dispatch.payload.worktree_id) {
|
|
100
|
+
throw new Error("worker delivery authority changed after dispatch acceptance");
|
|
101
|
+
}
|
|
102
|
+
restoreLeaseExpiredCheckout({
|
|
103
|
+
dispatch,
|
|
104
|
+
evidenceStore: runtime.tickets.evidenceStore,
|
|
105
|
+
hasBoundSession: runtime.sessions.readIfExists(dispatch.payload.session_id) !== undefined,
|
|
106
|
+
hasBoundPane: panes.observe(dispatch.record_id) !== undefined,
|
|
107
|
+
env,
|
|
108
|
+
runner,
|
|
109
|
+
});
|
|
110
|
+
verifyWorkerCheckout(dispatch, env, runner);
|
|
111
|
+
const workerBridge = {
|
|
112
|
+
command: executablePath,
|
|
113
|
+
args: [
|
|
114
|
+
"worker",
|
|
115
|
+
"bridge",
|
|
116
|
+
"--dispatch-id",
|
|
117
|
+
dispatch.record_id,
|
|
118
|
+
"--session-id",
|
|
119
|
+
dispatch.payload.session_id,
|
|
120
|
+
"--state-root",
|
|
121
|
+
stateRoot,
|
|
122
|
+
"--workspace-root",
|
|
123
|
+
workspaceRoot,
|
|
124
|
+
"--config-root",
|
|
125
|
+
configRoot,
|
|
126
|
+
],
|
|
127
|
+
};
|
|
128
|
+
if (dispatch.payload.role_id === "oms.ticket-executor") {
|
|
129
|
+
probeClaudeCodeCompatibility({ cwd: dispatch.payload.worktree_path, env, runner });
|
|
130
|
+
const prepared = prepareClaudeInteractiveLaunch({
|
|
131
|
+
config,
|
|
132
|
+
roleId: "oms.ticket-executor",
|
|
133
|
+
cwd: dispatch.payload.worktree_path,
|
|
134
|
+
sessionName: dispatch.payload.session_id,
|
|
135
|
+
env,
|
|
136
|
+
runner,
|
|
137
|
+
workerBridge,
|
|
138
|
+
workerInstructionsPath: join(configRoot, ".agents", "agents", "executor.md"),
|
|
139
|
+
dispatchId: dispatch.record_id,
|
|
140
|
+
});
|
|
141
|
+
providerLaunch = {
|
|
142
|
+
dispatchId: dispatch.record_id,
|
|
143
|
+
command: prepared.command,
|
|
144
|
+
args: prepared.args,
|
|
145
|
+
cwd: prepared.cwd,
|
|
146
|
+
env: prepared.env,
|
|
147
|
+
nativeAction: "claude",
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const prepared = prepareCodexGoalLaunch({
|
|
152
|
+
config,
|
|
153
|
+
roleId: "oms.goal-long-executor",
|
|
154
|
+
cwd: dispatch.payload.worktree_path,
|
|
155
|
+
env,
|
|
156
|
+
runner,
|
|
157
|
+
});
|
|
158
|
+
providerLaunch = {
|
|
159
|
+
dispatchId: dispatch.record_id,
|
|
160
|
+
command: prepared.command,
|
|
161
|
+
args: [
|
|
162
|
+
...prepared.args,
|
|
163
|
+
"--enable",
|
|
164
|
+
"goals",
|
|
165
|
+
"--enable",
|
|
166
|
+
"hooks",
|
|
167
|
+
"--disable",
|
|
168
|
+
"apps",
|
|
169
|
+
"--disable",
|
|
170
|
+
"browser_use",
|
|
171
|
+
"--disable",
|
|
172
|
+
"computer_use",
|
|
173
|
+
"--disable",
|
|
174
|
+
"image_generation",
|
|
175
|
+
"--disable",
|
|
176
|
+
"plugins",
|
|
177
|
+
"--strict-config",
|
|
178
|
+
"--ask-for-approval",
|
|
179
|
+
"never",
|
|
180
|
+
"--dangerously-bypass-hook-trust",
|
|
181
|
+
"--config",
|
|
182
|
+
`mcp_servers={oms_worker={command=${tomlString(workerBridge.command)},args=${tomlArray(workerBridge.args)},enabled_tools=${tomlArray(["read_dispatch", "acknowledge_dispatch", "record_dispatch_result"])},default_tools_approval_mode="approve",required=true}}`,
|
|
183
|
+
"--config",
|
|
184
|
+
"sandbox_workspace_write.exclude_slash_tmp=true",
|
|
185
|
+
"--config",
|
|
186
|
+
"sandbox_workspace_write.exclude_tmpdir_env_var=true",
|
|
187
|
+
],
|
|
188
|
+
cwd: prepared.cwd,
|
|
189
|
+
env: {
|
|
190
|
+
...prepared.env,
|
|
191
|
+
CODEX_HOME: prepareIsolatedCodexHome({
|
|
192
|
+
stateRoot,
|
|
193
|
+
sessionId: dispatch.payload.session_id,
|
|
194
|
+
dispatchId: dispatch.record_id,
|
|
195
|
+
executablePath,
|
|
196
|
+
workspaceRoot,
|
|
197
|
+
configRoot,
|
|
198
|
+
env: prepared.env,
|
|
199
|
+
}),
|
|
200
|
+
},
|
|
201
|
+
nativeAction: "goal",
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
parkWorker(dispatch, sourceEventId, "wkr-pre-park");
|
|
207
|
+
return Object.freeze({
|
|
208
|
+
status: "parked",
|
|
209
|
+
dispatch_id: dispatch.record_id,
|
|
210
|
+
reason: boundedReason(errorMessage(error)),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
if (liveDeliveryRepository !== null) {
|
|
214
|
+
const authorization = readLiveDeliveryAuthorization(stateRoot);
|
|
215
|
+
if (!authorization || authorization.repository !== liveDeliveryRepository) {
|
|
216
|
+
parkWorker(dispatch, sourceEventId, "wkr-auth-park");
|
|
217
|
+
return Object.freeze({
|
|
218
|
+
status: "parked",
|
|
219
|
+
dispatch_id: dispatch.record_id,
|
|
220
|
+
reason: "worker delivery lacks matching human-started live authorization",
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
discloseLiveContact({
|
|
225
|
+
stateRoot,
|
|
226
|
+
authorization,
|
|
227
|
+
operation: "worker-session",
|
|
228
|
+
contactSurface: providerLaunch.nativeAction === "goal" ? "codex-goal" : "claude-interactive",
|
|
229
|
+
subjectId: dispatch.payload.session_id,
|
|
230
|
+
request: {
|
|
231
|
+
dispatch_id: dispatch.record_id,
|
|
232
|
+
ticket_id: dispatch.payload.ticket_id,
|
|
233
|
+
role_id: dispatch.payload.role_id,
|
|
234
|
+
model_id: dispatch.payload.model_id,
|
|
235
|
+
provider_mode: dispatch.payload.provider_mode,
|
|
236
|
+
worktree_id: dispatch.payload.worktree_id,
|
|
237
|
+
},
|
|
238
|
+
disclosedAt: clock(),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
parkWorker(dispatch, sourceEventId, "wkr-disc-park");
|
|
243
|
+
return Object.freeze({
|
|
244
|
+
status: "parked",
|
|
245
|
+
dispatch_id: dispatch.record_id,
|
|
246
|
+
reason: boundedReason(errorMessage(error)),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
let ensured;
|
|
251
|
+
try {
|
|
252
|
+
ensured = panes.ensure(providerLaunch);
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
parkWorker(dispatch, sourceEventId, "wkr-lch-park");
|
|
256
|
+
return Object.freeze({ status: "parked", dispatch_id: dispatch.record_id, reason: boundedReason(errorMessage(error)) });
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
const observedAt = dispatch.payload.created_at;
|
|
260
|
+
runtime.sessions.register({
|
|
261
|
+
sessionId: dispatch.payload.session_id,
|
|
262
|
+
roleId: dispatch.payload.role_id,
|
|
263
|
+
engine: dispatch.payload.engine,
|
|
264
|
+
mode: dispatch.payload.provider_mode === "codex_goal" ? "goal" : "pane",
|
|
265
|
+
runId: null,
|
|
266
|
+
ticketId: dispatch.payload.ticket_id,
|
|
267
|
+
nativeSessionRef: dispatch.payload.session_id,
|
|
268
|
+
tmuxPaneId: ensured.observation.pane_id,
|
|
269
|
+
actorId: "oms-system",
|
|
270
|
+
sourceEventId,
|
|
271
|
+
observedAt,
|
|
272
|
+
heartbeatDeadlineAt: addMilliseconds(observedAt, HEARTBEAT_MS),
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
if (ensured.status === "created") {
|
|
277
|
+
try {
|
|
278
|
+
panes.stop(dispatch.record_id);
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
// A later recovery pass will observe the unregistered pane.
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
parkWorker(dispatch, sourceEventId, "wkr-reg-park");
|
|
285
|
+
return Object.freeze({ status: "parked", dispatch_id: dispatch.record_id, reason: boundedReason(errorMessage(error)) });
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
panes.activate(dispatch.record_id, providerLaunch.nativeAction);
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
let pane;
|
|
292
|
+
try {
|
|
293
|
+
pane = panes.observe(dispatch.record_id);
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
pane = undefined;
|
|
297
|
+
}
|
|
298
|
+
if (pane && !pane.dead) {
|
|
299
|
+
parkWorker(dispatch, sourceEventId, "wkr-act-park");
|
|
300
|
+
return Object.freeze({
|
|
301
|
+
status: "parked",
|
|
302
|
+
dispatch_id: dispatch.record_id,
|
|
303
|
+
activation_pending: true,
|
|
304
|
+
reason: boundedReason(errorMessage(error)),
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
const session = runtime.sessions.readIfExists(dispatch.payload.session_id);
|
|
308
|
+
const at = clock();
|
|
309
|
+
if (session && session.state !== "stopped") {
|
|
310
|
+
runtime.sessions.stop({
|
|
311
|
+
sessionId: session.record_id,
|
|
312
|
+
expectedVersion: session.version,
|
|
313
|
+
operationId: createStableId("wkr-act-stop", dispatch.record_id, sourceEventId),
|
|
314
|
+
actorId: "oms-system",
|
|
315
|
+
eventId: createStableId("wkr-act-evt", dispatch.record_id, sourceEventId),
|
|
316
|
+
observedAt: nextTimestamp(session.payload.last_observed_at, at),
|
|
317
|
+
reason: boundedReason(errorMessage(error)),
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
const current = runtime.workers.read(dispatch.record_id);
|
|
321
|
+
if (current.payload.health !== "stopped") {
|
|
322
|
+
runtime.workers.setHealth({
|
|
323
|
+
dispatchId: dispatch.record_id,
|
|
324
|
+
expectedVersion: current.version,
|
|
325
|
+
operationId: createStableId("wkr-act-hstop", dispatch.record_id, sourceEventId),
|
|
326
|
+
actorId: "oms-system",
|
|
327
|
+
observedAt: nextTimestamp(current.payload.updated_at, at),
|
|
328
|
+
health: "stopped",
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return Object.freeze({ status: "stopped", dispatch_id: dispatch.record_id, reason: boundedReason(errorMessage(error)) });
|
|
332
|
+
}
|
|
333
|
+
let currentWorker = runtime.workers.read(dispatch.record_id);
|
|
334
|
+
if (currentWorker.payload.health === "parked") {
|
|
335
|
+
currentWorker = runtime.workers.setHealth({
|
|
336
|
+
dispatchId: dispatch.record_id,
|
|
337
|
+
expectedVersion: currentWorker.version,
|
|
338
|
+
operationId: createStableId("wkr-pre-res", dispatch.record_id, sourceEventId),
|
|
339
|
+
actorId: "oms-system",
|
|
340
|
+
observedAt: nextTimestamp(currentWorker.payload.updated_at, clock()),
|
|
341
|
+
health: "healthy",
|
|
342
|
+
}).record;
|
|
343
|
+
}
|
|
344
|
+
if (currentWorker.state === "idle") {
|
|
345
|
+
runtime.workers.setActivity({
|
|
346
|
+
dispatchId: dispatch.record_id,
|
|
347
|
+
expectedVersion: currentWorker.version,
|
|
348
|
+
operationId: createStableId("wkr-act-work", dispatch.record_id, sourceEventId),
|
|
349
|
+
actorId: "oms-system",
|
|
350
|
+
observedAt: nextTimestamp(currentWorker.payload.updated_at, clock()),
|
|
351
|
+
activity: "working",
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
return Object.freeze({
|
|
355
|
+
status: ensured.status,
|
|
356
|
+
dispatch_id: dispatch.record_id,
|
|
357
|
+
session_id: dispatch.payload.session_id,
|
|
358
|
+
pane_id: ensured.observation.pane_id,
|
|
359
|
+
provider_mode: dispatch.payload.provider_mode,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
function observe(dispatchId) {
|
|
363
|
+
const dispatch = runtime.dispatch.read(assertOpaqueId(dispatchId, "dispatch id"));
|
|
364
|
+
const worker = runtime.workers.read(dispatch.record_id);
|
|
365
|
+
const session = runtime.sessions.readIfExists(dispatch.payload.session_id);
|
|
366
|
+
const pane = panes.observe(dispatch.record_id);
|
|
367
|
+
return Object.freeze({
|
|
368
|
+
dispatch_id: dispatch.record_id,
|
|
369
|
+
worker_activity: worker.state,
|
|
370
|
+
worker_health: worker.payload.health,
|
|
371
|
+
session_state: session?.state ?? null,
|
|
372
|
+
pane_id: pane?.pane_id ?? session?.payload.tmux_pane_id ?? null,
|
|
373
|
+
pane_live: pane !== undefined && !pane.dead,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
const service = Object.freeze({
|
|
377
|
+
deliver(eventId) {
|
|
378
|
+
const id = assertOpaqueId(eventId, "delivery event id");
|
|
379
|
+
const lock = runtime.outbox.acquireProcessingLock(id, DELIVERY_CONSUMER);
|
|
380
|
+
try {
|
|
381
|
+
const event = runtime.events.read(id, "dispatch-delivery-requested");
|
|
382
|
+
const existing = runtime.outbox.readReceipt(id, DELIVERY_CONSUMER);
|
|
383
|
+
if (existing)
|
|
384
|
+
return Object.freeze({ status: "replayed", outcome: existing.result });
|
|
385
|
+
const dispatch = runtime.dispatch.read(event.payload.dispatch_id);
|
|
386
|
+
if (dispatch.version < event.payload.dispatch_version
|
|
387
|
+
|| !dispatch.transition_outcomes.some((transition) => (transition.version === event.payload.dispatch_version && transition.state === "accepted"))
|
|
388
|
+
|| dispatch.payload.delivery_event_id !== event.event_id
|
|
389
|
+
|| dispatch.payload.accepted_at === null
|
|
390
|
+
|| dispatch.payload.worker_record_id !== event.payload.worker_record_id
|
|
391
|
+
|| dispatch.payload.ticket_id !== event.payload.ticket_id
|
|
392
|
+
|| dispatch.payload.attempt !== event.payload.attempt
|
|
393
|
+
|| dispatch.payload.lease_token !== event.payload.lease_token)
|
|
394
|
+
throw new Error("delivery event changed its accepted dispatch binding");
|
|
395
|
+
const outcome = dispatch.state === "accepted"
|
|
396
|
+
? launch(dispatch, event.event_id)
|
|
397
|
+
: recoverDeliveredDispatch(dispatch, event.event_id);
|
|
398
|
+
const receipt = runtime.outbox.commitReceipt({
|
|
399
|
+
eventId: event.event_id,
|
|
400
|
+
consumerId: DELIVERY_CONSUMER,
|
|
401
|
+
processedAt: clock(),
|
|
402
|
+
result: { ...outcome, operation_nonce: deriveOperationNonce(event.event_id, DELIVERY_CONSUMER) },
|
|
403
|
+
}).receipt;
|
|
404
|
+
return Object.freeze({ status: "processed", outcome: receipt.result });
|
|
405
|
+
}
|
|
406
|
+
finally {
|
|
407
|
+
lock.release();
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
park(dispatchId, reason, parkedUntil) {
|
|
411
|
+
const dispatch = runtime.dispatch.read(assertOpaqueId(dispatchId, "dispatch id"));
|
|
412
|
+
const at = clock();
|
|
413
|
+
let session = runtime.sessions.read(dispatch.payload.session_id);
|
|
414
|
+
let worker = runtime.workers.read(dispatch.record_id);
|
|
415
|
+
if (session.state !== "running" && session.state !== "stalled" && session.state !== "parked") {
|
|
416
|
+
throw new Error(`worker cannot park from session ${session.state}`);
|
|
417
|
+
}
|
|
418
|
+
if (worker.payload.health !== "healthy" && worker.payload.health !== "stalled" && worker.payload.health !== "parked") {
|
|
419
|
+
throw new Error(`worker cannot park from health ${worker.payload.health}`);
|
|
420
|
+
}
|
|
421
|
+
const parkedUntilMs = Date.parse(parkedUntil);
|
|
422
|
+
if (!Number.isFinite(parkedUntilMs) || parkedUntilMs <= Date.parse(at)) {
|
|
423
|
+
throw new Error("worker parked-until must be a future timestamp");
|
|
424
|
+
}
|
|
425
|
+
if (session.state === "parked" && session.payload.parked_until !== parkedUntil) {
|
|
426
|
+
throw new Error("worker is already parked until a different timestamp");
|
|
427
|
+
}
|
|
428
|
+
panes.park(dispatch.record_id, nativeAction(dispatch));
|
|
429
|
+
if (session.state !== "parked") {
|
|
430
|
+
session = runtime.sessions.park({
|
|
431
|
+
sessionId: session.record_id,
|
|
432
|
+
expectedVersion: session.version,
|
|
433
|
+
operationId: createStableId("wkr-park", dispatch.record_id, boundedReason(reason), parkedUntil),
|
|
434
|
+
actorId: "oms-system",
|
|
435
|
+
eventId: createStableId("wkr-park-evt", dispatch.record_id, parkedUntil),
|
|
436
|
+
observedAt: nextTimestamp(session.payload.last_observed_at, at),
|
|
437
|
+
parkedUntil,
|
|
438
|
+
}).record;
|
|
439
|
+
}
|
|
440
|
+
if (worker.payload.health !== "parked") {
|
|
441
|
+
worker = runtime.workers.setHealth({
|
|
442
|
+
dispatchId: dispatch.record_id,
|
|
443
|
+
expectedVersion: worker.version,
|
|
444
|
+
operationId: createStableId("wkr-hlth-park", dispatch.record_id, boundedReason(reason), parkedUntil),
|
|
445
|
+
actorId: "oms-system",
|
|
446
|
+
observedAt: nextTimestamp(worker.payload.updated_at, at),
|
|
447
|
+
health: "parked",
|
|
448
|
+
}).record;
|
|
449
|
+
}
|
|
450
|
+
return observe(dispatch.record_id);
|
|
451
|
+
},
|
|
452
|
+
resume(dispatchId) {
|
|
453
|
+
const dispatch = runtime.dispatch.read(assertOpaqueId(dispatchId, "dispatch id"));
|
|
454
|
+
let session = runtime.sessions.readIfExists(dispatch.payload.session_id);
|
|
455
|
+
if (!session) {
|
|
456
|
+
const eventId = dispatch.payload.delivery_event_id;
|
|
457
|
+
if (!eventId)
|
|
458
|
+
throw new Error("dispatch has no delivery event");
|
|
459
|
+
launch(dispatch, eventId);
|
|
460
|
+
return observe(dispatch.record_id);
|
|
461
|
+
}
|
|
462
|
+
const at = clock();
|
|
463
|
+
let worker = runtime.workers.read(dispatch.record_id);
|
|
464
|
+
if ((session.state !== "parked" && session.state !== "running") || (worker.payload.health !== "parked" && worker.payload.health !== "healthy")) {
|
|
465
|
+
throw new Error(`worker cannot resume from session ${session.state} and health ${worker.payload.health}`);
|
|
466
|
+
}
|
|
467
|
+
const pane = panes.observe(dispatch.record_id);
|
|
468
|
+
if (!pane || pane.dead)
|
|
469
|
+
throw new Error("worker cannot resume without its live bound pane");
|
|
470
|
+
const deliveryEventId = dispatch.payload.delivery_event_id;
|
|
471
|
+
const deliveryReceipt = deliveryEventId
|
|
472
|
+
? runtime.outbox.readReceipt(deliveryEventId, DELIVERY_CONSUMER)
|
|
473
|
+
: undefined;
|
|
474
|
+
const parkedUntil = session.payload.parked_until;
|
|
475
|
+
if (session.state === "parked" && (parkedUntil === null || Date.parse(at) < Date.parse(parkedUntil))) {
|
|
476
|
+
throw new Error("worker resume is not due");
|
|
477
|
+
}
|
|
478
|
+
if (session.state === "running"
|
|
479
|
+
&& session.version === 0
|
|
480
|
+
&& worker.payload.health === "parked"
|
|
481
|
+
&& deliveryReceipt?.result.activation_pending === true) {
|
|
482
|
+
panes.activate(dispatch.record_id, nativeAction(dispatch));
|
|
483
|
+
}
|
|
484
|
+
else if (session.state === "parked" || worker.payload.health === "parked") {
|
|
485
|
+
panes.resume(dispatch.record_id, nativeAction(dispatch));
|
|
486
|
+
}
|
|
487
|
+
if (session.state === "parked") {
|
|
488
|
+
if (parkedUntil === null)
|
|
489
|
+
throw new Error("parked worker lost its resume timestamp");
|
|
490
|
+
session = runtime.sessions.resume({
|
|
491
|
+
sessionId: session.record_id,
|
|
492
|
+
expectedVersion: session.version,
|
|
493
|
+
operationId: createStableId("wkr-resume", dispatch.record_id, parkedUntil),
|
|
494
|
+
actorId: "oms-system",
|
|
495
|
+
eventId: createStableId("wkr-res-evt", dispatch.record_id, parkedUntil),
|
|
496
|
+
observedAt: nextTimestamp(session.payload.last_observed_at, at),
|
|
497
|
+
heartbeatDeadlineAt: addMilliseconds(nextTimestamp(session.payload.last_observed_at, at), HEARTBEAT_MS),
|
|
498
|
+
}).record;
|
|
499
|
+
}
|
|
500
|
+
if (worker.payload.health === "parked") {
|
|
501
|
+
worker = runtime.workers.setHealth({
|
|
502
|
+
dispatchId: dispatch.record_id,
|
|
503
|
+
expectedVersion: worker.version,
|
|
504
|
+
operationId: createStableId("wkr-hlth-res", dispatch.record_id, String(session.version)),
|
|
505
|
+
actorId: "oms-system",
|
|
506
|
+
observedAt: nextTimestamp(worker.payload.updated_at, at),
|
|
507
|
+
health: "healthy",
|
|
508
|
+
}).record;
|
|
509
|
+
}
|
|
510
|
+
if (worker.state === "idle") {
|
|
511
|
+
worker = runtime.workers.setActivity({
|
|
512
|
+
dispatchId: dispatch.record_id,
|
|
513
|
+
expectedVersion: worker.version,
|
|
514
|
+
operationId: createStableId("wkr-act-res", dispatch.record_id, String(session.version)),
|
|
515
|
+
actorId: "oms-system",
|
|
516
|
+
observedAt: nextTimestamp(worker.payload.updated_at, at),
|
|
517
|
+
activity: "working",
|
|
518
|
+
}).record;
|
|
519
|
+
}
|
|
520
|
+
return observe(dispatch.record_id);
|
|
521
|
+
},
|
|
522
|
+
stop(dispatchId, reason) {
|
|
523
|
+
const dispatch = runtime.dispatch.read(assertOpaqueId(dispatchId, "dispatch id"));
|
|
524
|
+
const session = runtime.sessions.readIfExists(dispatch.payload.session_id);
|
|
525
|
+
let worker = runtime.workers.read(dispatch.record_id);
|
|
526
|
+
if (panes.observe(dispatch.record_id))
|
|
527
|
+
panes.stop(dispatch.record_id);
|
|
528
|
+
const at = clock();
|
|
529
|
+
if (session && session.state !== "stopped") {
|
|
530
|
+
runtime.sessions.stop({
|
|
531
|
+
sessionId: session.record_id,
|
|
532
|
+
expectedVersion: session.version,
|
|
533
|
+
operationId: createStableId("wkr-stop", dispatch.record_id, boundedReason(reason)),
|
|
534
|
+
actorId: "oms-system",
|
|
535
|
+
eventId: createStableId("wkr-stop-evt", dispatch.record_id, at),
|
|
536
|
+
observedAt: at,
|
|
537
|
+
reason: boundedReason(reason),
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
if (worker.payload.health !== "stopped") {
|
|
541
|
+
worker = runtime.workers.setHealth({
|
|
542
|
+
dispatchId: dispatch.record_id,
|
|
543
|
+
expectedVersion: worker.version,
|
|
544
|
+
operationId: createStableId("wkr-hlth-stop", dispatch.record_id, boundedReason(reason)),
|
|
545
|
+
actorId: "oms-system",
|
|
546
|
+
observedAt: nextTimestamp(worker.payload.updated_at, at),
|
|
547
|
+
health: "stopped",
|
|
548
|
+
}).record;
|
|
549
|
+
}
|
|
550
|
+
if (worker.state !== "done" && worker.state !== "blocked") {
|
|
551
|
+
runtime.workers.setActivity({
|
|
552
|
+
dispatchId: dispatch.record_id,
|
|
553
|
+
expectedVersion: worker.version,
|
|
554
|
+
operationId: createStableId("wkr-stop-block", dispatch.record_id, boundedReason(reason)),
|
|
555
|
+
actorId: "oms-system",
|
|
556
|
+
observedAt: nextTimestamp(worker.payload.updated_at, at),
|
|
557
|
+
activity: "blocked",
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
return observe(dispatch.record_id);
|
|
561
|
+
},
|
|
562
|
+
observe,
|
|
563
|
+
});
|
|
564
|
+
function parkWorker(dispatch, sourceEventId, prefix) {
|
|
565
|
+
const current = runtime.workers.read(dispatch.record_id);
|
|
566
|
+
if (current.payload.health === "parked")
|
|
567
|
+
return;
|
|
568
|
+
runtime.workers.setHealth({
|
|
569
|
+
dispatchId: dispatch.record_id,
|
|
570
|
+
expectedVersion: current.version,
|
|
571
|
+
operationId: createStableId(prefix, dispatch.record_id, sourceEventId),
|
|
572
|
+
actorId: "oms-system",
|
|
573
|
+
observedAt: nextTimestamp(current.payload.updated_at, clock()),
|
|
574
|
+
health: "parked",
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
function recoverDeliveredDispatch(dispatch, sourceEventId) {
|
|
578
|
+
if (dispatch.state !== "acknowledged" && dispatch.state !== "result-received" && dispatch.state !== "resolved") {
|
|
579
|
+
throw new Error(`delivery cannot recover dispatch state ${dispatch.state}`);
|
|
580
|
+
}
|
|
581
|
+
const session = runtime.sessions.readIfExists(dispatch.payload.session_id);
|
|
582
|
+
const worker = runtime.workers.read(dispatch.record_id);
|
|
583
|
+
if (!session
|
|
584
|
+
|| session.payload.source_event_id !== sourceEventId
|
|
585
|
+
|| session.payload.ticket_id !== dispatch.payload.ticket_id
|
|
586
|
+
|| session.payload.role_id !== dispatch.payload.role_id
|
|
587
|
+
|| session.payload.engine !== dispatch.payload.engine
|
|
588
|
+
|| session.payload.native_session_ref !== dispatch.payload.session_id
|
|
589
|
+
|| session.payload.tmux_pane_id === null
|
|
590
|
+
|| worker.record_id !== dispatch.payload.worker_record_id
|
|
591
|
+
|| worker.payload.dispatch_id !== dispatch.record_id
|
|
592
|
+
|| worker.payload.ticket_id !== dispatch.payload.ticket_id
|
|
593
|
+
|| worker.payload.session_id !== dispatch.payload.session_id
|
|
594
|
+
|| worker.payload.role_id !== dispatch.payload.role_id
|
|
595
|
+
|| worker.payload.provider_mode !== dispatch.payload.provider_mode
|
|
596
|
+
|| worker.payload.worktree_id !== dispatch.payload.worktree_id)
|
|
597
|
+
throw new Error("advanced dispatch has no exact canonical worker delivery binding");
|
|
598
|
+
return Object.freeze({
|
|
599
|
+
status: "recovered",
|
|
600
|
+
dispatch_id: dispatch.record_id,
|
|
601
|
+
dispatch_state: dispatch.state,
|
|
602
|
+
session_id: session.record_id,
|
|
603
|
+
session_state: session.state,
|
|
604
|
+
pane_id: session.payload.tmux_pane_id,
|
|
605
|
+
provider_mode: dispatch.payload.provider_mode,
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
return service;
|
|
609
|
+
}
|
|
610
|
+
function assertApprovedDispatchAdvice(dispatch, evidenceStore, stateRoot) {
|
|
611
|
+
const digest = dispatch.payload.dispatch_intent_sha256;
|
|
612
|
+
const reference = dispatch.payload.advisor_evidence;
|
|
613
|
+
if (typeof digest !== "string" || !reference) {
|
|
614
|
+
throw new Error("worker delivery requires approved advisor evidence");
|
|
615
|
+
}
|
|
616
|
+
const evidence = evidenceStore.read(reference);
|
|
617
|
+
const intent = captureStoredDispatchIntent(dispatch.payload);
|
|
618
|
+
try {
|
|
619
|
+
if (digest !== intent.dispatch_intent_sha256) {
|
|
620
|
+
throw new Error("worker delivery dispatch intent digest changed");
|
|
621
|
+
}
|
|
622
|
+
assertStoredAdvisorEvidenceProvenance({ stateRoot, evidence, intent });
|
|
623
|
+
if (evidence.evidence_kind !== "advisor-output"
|
|
624
|
+
|| evidence.producer_role !== "oms.exec-advisor"
|
|
625
|
+
|| evidence.ticket_id !== dispatch.payload.ticket_id
|
|
626
|
+
|| evidence.payload.dispatch_intent_sha256 !== digest
|
|
627
|
+
|| evidence.payload.verdict !== "approve")
|
|
628
|
+
throw new Error("advisor verdict is not approve");
|
|
629
|
+
}
|
|
630
|
+
catch (error) {
|
|
631
|
+
throw new Error("worker delivery advisor evidence does not approve this dispatch intent", { cause: error });
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function validateExecutable(path) {
|
|
635
|
+
if (!isAbsolute(path) || !existsSync(path))
|
|
636
|
+
throw new Error("OMS executable path must be an existing absolute file");
|
|
637
|
+
const entry = lstatSync(path);
|
|
638
|
+
if (entry.isSymbolicLink() || !entry.isFile() || (entry.mode & 0o111) === 0) {
|
|
639
|
+
throw new Error("OMS executable path must be a non-symbolic executable file");
|
|
640
|
+
}
|
|
641
|
+
return realpathSync.native(path);
|
|
642
|
+
}
|
|
643
|
+
function boundedReason(value) {
|
|
644
|
+
const normalized = value.trim().replace(/[\0\r\n]+/gu, " ");
|
|
645
|
+
return (normalized || "worker lifecycle request").slice(0, 512);
|
|
646
|
+
}
|
|
647
|
+
function addMilliseconds(timestamp, milliseconds) {
|
|
648
|
+
const value = Date.parse(timestamp);
|
|
649
|
+
if (!Number.isFinite(value))
|
|
650
|
+
throw new Error("invalid worker lifecycle timestamp");
|
|
651
|
+
return new Date(value + milliseconds).toISOString();
|
|
652
|
+
}
|
|
653
|
+
function nextTimestamp(previous, candidate) {
|
|
654
|
+
const previousMs = Date.parse(previous);
|
|
655
|
+
const candidateMs = Date.parse(candidate);
|
|
656
|
+
if (!Number.isFinite(previousMs) || !Number.isFinite(candidateMs))
|
|
657
|
+
throw new Error("invalid worker transition timestamp");
|
|
658
|
+
return new Date(Math.max(previousMs + 1, candidateMs)).toISOString();
|
|
659
|
+
}
|
|
660
|
+
function tomlString(value) {
|
|
661
|
+
if (/[\0\r\n]/u.test(value))
|
|
662
|
+
throw new Error("worker MCP argument contains control characters");
|
|
663
|
+
return JSON.stringify(value);
|
|
664
|
+
}
|
|
665
|
+
function tomlArray(values) {
|
|
666
|
+
return `[${values.map(tomlString).join(",")}]`;
|
|
667
|
+
}
|
|
668
|
+
function prepareIsolatedCodexHome(options) {
|
|
669
|
+
const { stateRoot, sessionId, dispatchId, executablePath, workspaceRoot, configRoot, env } = options;
|
|
670
|
+
const sourceHomePath = env.CODEX_HOME ?? (env.HOME ? join(env.HOME, ".codex") : undefined);
|
|
671
|
+
if (!sourceHomePath)
|
|
672
|
+
throw new Error("Codex subscription home is unavailable");
|
|
673
|
+
const sourceHome = validateExistingDirectory(sourceHomePath, "Codex subscription home");
|
|
674
|
+
const sourceAuth = join(sourceHome, "auth.json");
|
|
675
|
+
const sourceAuthEntry = lstatSync(sourceAuth);
|
|
676
|
+
if (sourceAuthEntry.isSymbolicLink() || !sourceAuthEntry.isFile()) {
|
|
677
|
+
throw new Error("Codex subscription auth must be one regular file");
|
|
678
|
+
}
|
|
679
|
+
const sourceAuthTarget = realpathSync.native(sourceAuth);
|
|
680
|
+
const runtimeHomePath = join(stateRoot, "tmp", `codex-${assertOpaqueId(sessionId, "Codex session id")}`);
|
|
681
|
+
const runtimeHomeEntry = lstatIfExists(runtimeHomePath);
|
|
682
|
+
if (!runtimeHomeEntry)
|
|
683
|
+
mkdirSync(runtimeHomePath, { mode: 0o700 });
|
|
684
|
+
const runtimeHome = validateExistingDirectory(runtimeHomePath, "isolated Codex home");
|
|
685
|
+
if ((lstatSync(runtimeHome).mode & 0o077) !== 0)
|
|
686
|
+
throw new Error("isolated Codex home is not private");
|
|
687
|
+
const runtimeAuth = join(runtimeHome, "auth.json");
|
|
688
|
+
const runtimeAuthEntry = lstatIfExists(runtimeAuth);
|
|
689
|
+
if (!runtimeAuthEntry) {
|
|
690
|
+
symlinkSync(sourceAuthTarget, runtimeAuth, "file");
|
|
691
|
+
}
|
|
692
|
+
else if (!runtimeAuthEntry.isSymbolicLink() || realpathSync.native(runtimeAuth) !== sourceAuthTarget) {
|
|
693
|
+
throw new Error("isolated Codex auth binding changed");
|
|
694
|
+
}
|
|
695
|
+
const hookArgs = [
|
|
696
|
+
executablePath,
|
|
697
|
+
"hook",
|
|
698
|
+
"provider",
|
|
699
|
+
"--provider",
|
|
700
|
+
"codex",
|
|
701
|
+
"--provider-version",
|
|
702
|
+
SUPPORTED_PROVIDER_HOOK_VERSIONS.codex,
|
|
703
|
+
"--dispatch-id",
|
|
704
|
+
dispatchId,
|
|
705
|
+
"--session-id",
|
|
706
|
+
sessionId,
|
|
707
|
+
"--state-root",
|
|
708
|
+
stateRoot,
|
|
709
|
+
"--workspace-root",
|
|
710
|
+
workspaceRoot,
|
|
711
|
+
"--config-root",
|
|
712
|
+
configRoot,
|
|
713
|
+
];
|
|
714
|
+
const command = hookArgs.map(shellQuote).join(" ");
|
|
715
|
+
const hooks = {
|
|
716
|
+
hooks: {
|
|
717
|
+
SessionStart: [{ matcher: "startup|resume", hooks: [{ type: "command", command, timeout: 10 }] }],
|
|
718
|
+
UserPromptSubmit: [{ hooks: [{ type: "command", command, timeout: 10 }] }],
|
|
719
|
+
Stop: [{ hooks: [{ type: "command", command, timeout: 10 }] }],
|
|
720
|
+
},
|
|
721
|
+
};
|
|
722
|
+
const hooksPath = join(runtimeHome, "hooks.json");
|
|
723
|
+
const hooksEntry = lstatIfExists(hooksPath);
|
|
724
|
+
if (!hooksEntry) {
|
|
725
|
+
writeJsonAtomicNoReplace(hooksPath, hooks);
|
|
726
|
+
}
|
|
727
|
+
else {
|
|
728
|
+
if (hooksEntry.isSymbolicLink() || !hooksEntry.isFile())
|
|
729
|
+
throw new Error("isolated Codex hooks binding changed");
|
|
730
|
+
if (JSON.stringify(readJsonFileNoFollow(hooksPath, 64 * 1024)) !== JSON.stringify(hooks)) {
|
|
731
|
+
throw new Error("isolated Codex hooks binding changed");
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return runtimeHome;
|
|
735
|
+
}
|
|
736
|
+
function shellQuote(value) {
|
|
737
|
+
if (/[^\x20-\x7e]/u.test(value))
|
|
738
|
+
throw new Error("Codex hook argument contains control characters");
|
|
739
|
+
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
740
|
+
}
|
|
741
|
+
function verifyWorkerCheckout(dispatch, env, runner) {
|
|
742
|
+
const result = runner({
|
|
743
|
+
command: "git",
|
|
744
|
+
args: ["rev-parse", "--show-toplevel", "HEAD"],
|
|
745
|
+
cwd: dispatch.payload.worktree_path,
|
|
746
|
+
env,
|
|
747
|
+
timeoutMs: 10_000,
|
|
748
|
+
maxBufferBytes: 64 * 1024,
|
|
749
|
+
});
|
|
750
|
+
if (result.error || result.status !== 0)
|
|
751
|
+
throw new Error("worker checkout probe failed");
|
|
752
|
+
const [root, head, ...extra] = result.stdout.trim().split(/\r?\n/u);
|
|
753
|
+
const branchResult = runner({
|
|
754
|
+
command: "git",
|
|
755
|
+
args: ["symbolic-ref", "--short", "HEAD"],
|
|
756
|
+
cwd: dispatch.payload.worktree_path,
|
|
757
|
+
env,
|
|
758
|
+
timeoutMs: 10_000,
|
|
759
|
+
maxBufferBytes: 64 * 1024,
|
|
760
|
+
});
|
|
761
|
+
const branch = branchResult.stdout.trim();
|
|
762
|
+
if (!root
|
|
763
|
+
|| branchResult.error
|
|
764
|
+
|| branchResult.status !== 0
|
|
765
|
+
|| realpathSync.native(root) !== realpathSync.native(dispatch.payload.worktree_path)
|
|
766
|
+
|| branch !== dispatch.payload.worktree_branch
|
|
767
|
+
|| head !== dispatchWorktreeStartCommit(dispatch.payload)
|
|
768
|
+
|| extra.length > 0)
|
|
769
|
+
throw new Error("worker checkout changed after dispatch acceptance");
|
|
770
|
+
const lineage = runner({
|
|
771
|
+
command: "git",
|
|
772
|
+
args: [
|
|
773
|
+
"merge-base",
|
|
774
|
+
"--is-ancestor",
|
|
775
|
+
dispatch.payload.worktree_base_commit,
|
|
776
|
+
dispatchWorktreeStartCommit(dispatch.payload),
|
|
777
|
+
],
|
|
778
|
+
cwd: dispatch.payload.worktree_path,
|
|
779
|
+
env,
|
|
780
|
+
timeoutMs: 10_000,
|
|
781
|
+
maxBufferBytes: 64 * 1024,
|
|
782
|
+
});
|
|
783
|
+
if (lineage.error || lineage.status !== 0)
|
|
784
|
+
throw new Error("worker checkout start is outside the trusted base lineage");
|
|
785
|
+
const statusResult = runner({
|
|
786
|
+
command: "git",
|
|
787
|
+
args: ["status", "--porcelain=v1", "--untracked-files=all"],
|
|
788
|
+
cwd: dispatch.payload.worktree_path,
|
|
789
|
+
env,
|
|
790
|
+
timeoutMs: 10_000,
|
|
791
|
+
maxBufferBytes: 64 * 1024,
|
|
792
|
+
});
|
|
793
|
+
if (statusResult.error || statusResult.status !== 0)
|
|
794
|
+
throw new Error("worker checkout cleanliness probe failed");
|
|
795
|
+
if (statusResult.stdout.trim() !== "")
|
|
796
|
+
throw new Error("worker checkout is not clean before provider launch");
|
|
797
|
+
}
|
|
798
|
+
function restoreLeaseExpiredCheckout(options) {
|
|
799
|
+
const reference = options.dispatch.payload.prior_failure_evidence;
|
|
800
|
+
if (reference === null)
|
|
801
|
+
return;
|
|
802
|
+
const evidence = options.evidenceStore.read(reference);
|
|
803
|
+
if (evidence.evidence_kind !== "lease-expiry")
|
|
804
|
+
return;
|
|
805
|
+
const startCommit = dispatchWorktreeStartCommit(options.dispatch.payload);
|
|
806
|
+
if (evidence.ticket_id !== options.dispatch.payload.ticket_id
|
|
807
|
+
|| evidence.payload.attempt !== options.dispatch.payload.attempt - 1
|
|
808
|
+
|| evidence.payload.worktree_start_commit !== startCommit)
|
|
809
|
+
throw new Error("expired lease restart evidence changed after dispatch acceptance");
|
|
810
|
+
const binding = options.runner({
|
|
811
|
+
command: "git",
|
|
812
|
+
args: ["rev-parse", "--show-toplevel", "HEAD"],
|
|
813
|
+
cwd: options.dispatch.payload.worktree_path,
|
|
814
|
+
env: options.env,
|
|
815
|
+
timeoutMs: 10_000,
|
|
816
|
+
maxBufferBytes: 64 * 1024,
|
|
817
|
+
});
|
|
818
|
+
const branchResult = options.runner({
|
|
819
|
+
command: "git",
|
|
820
|
+
args: ["symbolic-ref", "--short", "HEAD"],
|
|
821
|
+
cwd: options.dispatch.payload.worktree_path,
|
|
822
|
+
env: options.env,
|
|
823
|
+
timeoutMs: 10_000,
|
|
824
|
+
maxBufferBytes: 64 * 1024,
|
|
825
|
+
});
|
|
826
|
+
const [root, head, ...extra] = binding.stdout.trim().split(/\r?\n/u);
|
|
827
|
+
if (binding.error
|
|
828
|
+
|| binding.status !== 0
|
|
829
|
+
|| branchResult.error
|
|
830
|
+
|| branchResult.status !== 0
|
|
831
|
+
|| branchResult.stdout.trim() !== options.dispatch.payload.worktree_branch
|
|
832
|
+
|| !root
|
|
833
|
+
|| !head
|
|
834
|
+
|| extra.length > 0
|
|
835
|
+
|| realpathSync.native(root) !== realpathSync.native(options.dispatch.payload.worktree_path))
|
|
836
|
+
throw new Error("expired lease checkout binding changed");
|
|
837
|
+
if (head === startCommit)
|
|
838
|
+
return;
|
|
839
|
+
if (options.hasBoundSession || options.hasBoundPane) {
|
|
840
|
+
throw new Error("expired lease checkout cannot reset while a worker binding is live");
|
|
841
|
+
}
|
|
842
|
+
const lineage = options.runner({
|
|
843
|
+
command: "git",
|
|
844
|
+
args: ["merge-base", "--is-ancestor", options.dispatch.payload.worktree_base_commit, startCommit],
|
|
845
|
+
cwd: options.dispatch.payload.worktree_path,
|
|
846
|
+
env: options.env,
|
|
847
|
+
timeoutMs: 10_000,
|
|
848
|
+
maxBufferBytes: 64 * 1024,
|
|
849
|
+
});
|
|
850
|
+
if (lineage.error || lineage.status !== 0)
|
|
851
|
+
throw new Error("expired lease restart is outside the trusted base lineage");
|
|
852
|
+
const reset = options.runner({
|
|
853
|
+
command: "git",
|
|
854
|
+
args: ["reset", "--hard", startCommit],
|
|
855
|
+
cwd: options.dispatch.payload.worktree_path,
|
|
856
|
+
env: options.env,
|
|
857
|
+
timeoutMs: 30_000,
|
|
858
|
+
maxBufferBytes: 256 * 1024,
|
|
859
|
+
});
|
|
860
|
+
if (reset.error || reset.status !== 0)
|
|
861
|
+
throw new Error("expired lease checkout reset failed");
|
|
862
|
+
const clean = options.runner({
|
|
863
|
+
command: "git",
|
|
864
|
+
args: ["clean", "-fd", "--", "."],
|
|
865
|
+
cwd: options.dispatch.payload.worktree_path,
|
|
866
|
+
env: options.env,
|
|
867
|
+
timeoutMs: 30_000,
|
|
868
|
+
maxBufferBytes: 256 * 1024,
|
|
869
|
+
});
|
|
870
|
+
if (clean.error || clean.status !== 0)
|
|
871
|
+
throw new Error("expired lease checkout clean failed");
|
|
872
|
+
}
|
|
873
|
+
function nativeAction(dispatch) {
|
|
874
|
+
return dispatch.payload.provider_mode === "codex_goal" ? "goal" : "claude";
|
|
875
|
+
}
|
|
876
|
+
//# sourceMappingURL=delivery.js.map
|