@moretea-labs/forge 1.5.0-rc.1 → 1.5.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.md +9 -11
- package/CHANGELOG.md +19 -0
- package/CLAUDE.md +8 -10
- package/DESIGN.md +278 -0
- package/README.md +70 -90
- package/README.zh-CN.md +50 -55
- package/SKILL.md +8 -11
- package/THIRD_PARTY_NOTICES.md +9 -3
- package/assets/branding/README.md +4 -2
- package/assets/hooks/lib/workflow-state.sh +19 -18
- package/assets/hooks/post-edit-guard.sh +6 -75
- package/assets/hooks/prompt-guard.sh +24 -12
- package/assets/hooks/session-start-context.sh +17 -17
- package/assets/hooks/stop-orchestrator.sh +2 -2
- package/assets/partials/04-project-structure.partial.md +6 -6
- package/assets/partials/05-workflow.partial.md +6 -6
- package/assets/partials/07-footer.partial.md +1 -1
- package/assets/partials/08-orchestration.partial.md +2 -2
- package/assets/partials-agents/02-operating-mode.partial.md +5 -5
- package/assets/partials-agents/03-orchestration.partial.md +3 -3
- package/assets/partials-agents/04-task-protocol.partial.md +3 -3
- package/assets/partials-agents/08-deep-docs.partial.md +1 -1
- package/assets/reference-configs/agentic-development-flow.md +49 -86
- package/assets/reference-configs/external-tooling.md +21 -61
- package/assets/reference-configs/handoff-protocol.md +25 -20
- package/assets/reference-configs/harness-overview.md +8 -8
- package/assets/templates/helpers/archive-workflow.sh +0 -1
- package/assets/templates/helpers/capture-plan.sh +3 -3
- package/assets/templates/helpers/check-task-workflow.sh +2 -2
- package/assets/templates/helpers/codex-handoff-resume.sh +5 -5
- package/assets/templates/helpers/ensure-task-workflow.sh +37 -35
- package/assets/templates/helpers/new-plan.sh +1 -1
- package/assets/templates/helpers/plan-to-todo.sh +2 -2
- package/assets/templates/helpers/prepare-codex-handoff.sh +2 -2
- package/assets/templates/helpers/prepare-handoff.sh +9 -9
- package/assets/templates/helpers/refresh-current-status.sh +2 -2
- package/assets/templates/helpers/ship-worktrees.sh +1 -1
- package/assets/templates/helpers/sprint-backlog.sh +1 -1
- package/assets/templates/helpers/verify-sprint.sh +7 -7
- package/assets/templates/helpers/workstream-sync.sh +1 -1
- package/assets/templates/plan.template.md +1 -1
- package/assets/workflow-contract.v1.json +6 -3
- package/docs/architecture/current/README.md +10 -9
- package/docs/architecture/current/approved-target-architecture.zh-CN.md +2 -2
- package/docs/architecture/current/architecture-invariants.md +2 -2
- package/docs/architecture/current/automation-and-schedule-engine.md +15 -15
- package/docs/architecture/current/codegraph-context-provider.md +2 -2
- package/docs/architecture/current/control-plane-authority-inventory.md +12 -0
- package/docs/architecture/current/dispatch-and-agent-strategy.md +11 -11
- package/docs/architecture/current/entity-model.md +0 -27
- package/docs/architecture/current/failure-recovery.md +0 -24
- package/docs/architecture/current/governance.md +1 -1
- package/docs/architecture/current/implementation-status.md +1 -1
- package/docs/architecture/current/legacy-governance.md +58 -0
- package/docs/architecture/current/multi-repository-execution.md +1 -1
- package/docs/architecture/current/peer-supercontroller-runtime.md +1 -1
- package/docs/architecture/current/personal-assistant-plugin-baseline.md +4 -5
- package/docs/architecture/current/scheduler-and-resource-claims.md +0 -10
- package/docs/architecture/current/target-requirements-traceability.md +2 -2
- package/docs/architecture/current/thin-harness-governance-policy.md +1 -1
- package/docs/architecture/current/thin-harness-v1.md +9 -11
- package/docs/architecture/domains/runtime-harness.md +1 -1
- package/docs/forge-autonomous-goal-loop.md +3 -1
- package/docs/forge-chatgpt-mcp-setup.md +51 -184
- package/docs/images/forge-banner-cn.svg +26 -1
- package/docs/images/forge-banner.svg +26 -1
- package/docs/operations/features.md +1 -1
- package/docs/operations/homebrew.md +3 -3
- package/docs/operations/mcp-tool-exposure.md +5 -5
- package/docs/operations/platform-support.md +45 -37
- package/docs/operations/platform-support.zh-CN.md +40 -38
- package/docs/operations/releasing.md +3 -3
- package/docs/operations/releasing.zh-CN.md +3 -3
- package/docs/operations/troubleshooting.md +11 -6
- package/docs/operations/troubleshooting.zh-CN.md +11 -6
- package/docs/public-usage-guide.md +28 -21
- package/docs/public-usage-guide.zh-CN.md +28 -21
- package/docs/tutorials/01-install-and-start.md +56 -35
- package/docs/tutorials/01-install-and-start.zh-CN.md +56 -35
- package/docs/tutorials/02-connect-chatgpt.md +112 -46
- package/docs/tutorials/02-connect-chatgpt.zh-CN.md +113 -45
- package/docs/wiki/Architecture.md +1 -1
- package/docs/wiki/Installation.md +2 -2
- package/docs/wiki/Quick-Start.md +1 -1
- package/docs/wiki/Work-Lifecycle.md +1 -1
- package/install.ps1 +4 -5
- package/install.sh +4 -6
- package/package.json +15 -5
- package/scripts/archive-workflow.sh +0 -1
- package/scripts/benchmark-thin-harness-mcp-e2e.ts +27 -14
- package/scripts/build-controller-ui.ts +28 -0
- package/scripts/capture-plan.sh +4 -4
- package/scripts/check-agent-tooling.sh +12 -1
- package/scripts/check-platform-support.mjs +2 -2
- package/scripts/check-public-docs.sh +16 -5
- package/scripts/check-release-readiness.sh +5 -11
- package/scripts/check-runtime-architecture.mjs +14 -22
- package/scripts/check-tarball-install-smoke.sh +3 -2
- package/scripts/check-task-workflow.sh +2 -2
- package/scripts/codex-handoff-resume.sh +5 -5
- package/scripts/create-project-dirs.sh +3 -3
- package/scripts/ensure-task-workflow.sh +45 -35
- package/scripts/init-project.sh +4 -4
- package/scripts/install-desktop-operator-registration.ts +2 -2
- package/scripts/lib/project-init-lib.sh +46 -44
- package/scripts/migrate-project-template.sh +7 -4
- package/scripts/new-plan.sh +1 -1
- package/scripts/plan-to-todo.sh +2 -2
- package/scripts/prepare-codex-handoff.sh +2 -2
- package/scripts/prepare-handoff.sh +9 -9
- package/scripts/refresh-current-status.sh +2 -2
- package/scripts/setup-plugins.sh +3 -3
- package/scripts/ship-worktrees.sh +1 -1
- package/scripts/sprint-backlog.sh +5 -5
- package/scripts/sync-codex-installed-copies.sh +2 -3
- package/scripts/verify-sprint.sh +7 -7
- package/scripts/workstream-sync.sh +1 -1
- package/src/cli/chatgpt-browser/bridge-extension.ts +1 -1
- package/src/cli/chatgpt-browser/bridge-provider.ts +29 -0
- package/src/cli/chatgpt-browser/file-policy.ts +3 -1
- package/src/cli/commands/chatgpt.ts +51 -0
- package/src/cli/commands/doctor.ts +1 -1
- package/src/cli/commands/init-hook.ts +211 -70
- package/src/cli/commands/init.ts +5 -6
- package/src/cli/commands/mcp.ts +29 -5
- package/src/cli/commands/runtime.ts +60 -8
- package/src/cli/commands/setup-profile.ts +441 -0
- package/src/cli/controller/check-runner.ts +20 -3
- package/src/cli/controller/codex-continuation.ts +4 -7
- package/src/cli/controller/context-pack.ts +118 -14
- package/src/cli/controller/operational-plan.ts +4 -4
- package/src/cli/controller/task-ledger.ts +10 -10
- package/src/cli/controller/work-mode.ts +6 -13
- package/src/cli/index.ts +14 -35
- package/src/cli/local-bridge/connector-freshness.ts +1 -1
- package/src/cli/local-bridge/console-automations.ts +160 -0
- package/src/cli/local-bridge/dashboard.ts +8 -1303
- package/src/cli/local-bridge/facade-api.ts +16 -7
- package/src/cli/local-bridge/frontend/src/App.tsx +10 -0
- package/src/cli/local-bridge/frontend/src/components/Button.tsx +1 -0
- package/src/cli/local-bridge/frontend/src/components/DetailPane.tsx +3 -0
- package/src/cli/local-bridge/frontend/src/components/SearchField.tsx +1 -0
- package/src/cli/local-bridge/frontend/src/components/SectionHeader.tsx +1 -0
- package/src/cli/local-bridge/frontend/src/components/Segmented.tsx +1 -0
- package/src/cli/local-bridge/frontend/src/components/StatusText.tsx +3 -0
- package/src/cli/local-bridge/frontend/src/design/icons.tsx +11 -0
- package/src/cli/local-bridge/frontend/src/design/tokens.css +8 -0
- package/src/cli/local-bridge/frontend/src/features/automations/AutomationsView.tsx +3 -0
- package/src/cli/local-bridge/frontend/src/features/capabilities/CapabilitiesView.tsx +4 -0
- package/src/cli/local-bridge/frontend/src/features/overview/OverviewView.tsx +3 -0
- package/src/cli/local-bridge/frontend/src/features/repositories/RepositoriesView.tsx +2 -0
- package/src/cli/local-bridge/frontend/src/features/settings/SettingsView.tsx +2 -0
- package/src/cli/local-bridge/frontend/src/features/system/SystemView.tsx +2 -0
- package/src/cli/local-bridge/frontend/src/features/work/WorkView.tsx +3 -0
- package/src/cli/local-bridge/frontend/src/lib/api.ts +23 -0
- package/src/cli/local-bridge/frontend/src/lib/format.ts +4 -0
- package/src/cli/local-bridge/frontend/src/lib/routes.ts +7 -0
- package/src/cli/local-bridge/frontend/src/main.tsx +1 -0
- package/src/cli/local-bridge/frontend/src/shell/AppShell.tsx +1 -0
- package/src/cli/local-bridge/frontend/src/shell/CommandBar.tsx +2 -0
- package/src/cli/local-bridge/frontend/src/shell/Sidebar.tsx +3 -0
- package/src/cli/local-bridge/frontend/src/styles.css +12 -0
- package/src/cli/local-bridge/frontend/src/types.ts +14 -0
- package/src/cli/local-bridge/frontend/src/vite-env.d.ts +1 -0
- package/src/cli/local-bridge/frontend/vite.config.ts +27 -0
- package/src/cli/local-bridge/server.ts +44 -0
- package/src/cli/local-bridge/ui-dist/app.css +1 -0
- package/src/cli/local-bridge/ui-dist/app.js +11094 -0
- package/src/cli/mcp/instructions.ts +3 -3
- package/src/cli/mcp/legacy-tool-service.ts +27 -23
- package/src/cli/mcp/multi-repository.ts +2 -0
- package/src/cli/mcp/policy.ts +7 -5
- package/src/cli/mcp/repository-tools.ts +53 -14
- package/src/cli/mcp/server.ts +5 -10
- package/src/cli/mcp/setup.ts +211 -275
- package/src/cli/mcp/tool-capability-cache.ts +1 -1
- package/src/cli/mcp/toolset-names.ts +1 -1
- package/src/cli/mcp/toolset.ts +0 -1
- package/src/cli/mcp/transports/http.ts +24 -4
- package/src/cli/repositories/branch-name-policy.ts +0 -7
- package/src/cli/repositories/controller-home.ts +110 -3
- package/src/cli/repositories/safe-patch.ts +1 -1
- package/src/cli/repositories/selected-path-actions.ts +26 -24
- package/src/core/adoption/gitignore-plan.ts +2 -3
- package/src/core/adoption/plan.ts +4 -1
- package/src/runtime/control-plane/execution/edit-validation-coordinator.ts +556 -0
- package/src/runtime/control-plane/execution/work-handle-store.ts +128 -1
- package/src/runtime/control-plane/execution/work-validation-reconciler.ts +277 -0
- package/src/runtime/control-plane/execution/work-verification-snapshot.ts +169 -0
- package/src/runtime/control-plane/facade/capability-registry.ts +0 -10
- package/src/runtime/control-plane/facade/handoff-inbox-store.ts +44 -25
- package/src/runtime/control-plane/facade/suggested-actions.ts +7 -1
- package/src/runtime/control-plane/facade/types.ts +0 -1
- package/src/runtime/control-plane/global-scheduler/scheduler.ts +30 -8
- package/src/runtime/control-plane/launcher/chatgpt-work-binding-store.ts +114 -0
- package/src/runtime/control-plane/launcher/chatgpt-work-continuation.ts +175 -0
- package/src/runtime/control-plane/launcher/launch-reservation-store.ts +161 -0
- package/src/runtime/control-plane/launcher/provider-mcp-bootstrap.ts +64 -0
- package/src/runtime/control-plane/launcher/thin-launcher.ts +117 -24
- package/src/runtime/control-plane/routing/route-policy.ts +14 -14
- package/src/runtime/control-plane/runtime-cleanup.ts +0 -1
- package/src/runtime/evidence/event-ledger.ts +1 -1
- package/src/runtime/{workflow/campaigns/workspace.ts → execution/managed-workspace.ts} +41 -43
- package/src/runtime/execution/process-runtime/check-facade.ts +6 -0
- package/src/runtime/execution/process-runtime/check-result.ts +45 -0
- package/src/runtime/execution/process-runtime/check-runner-sidecar.ts +42 -16
- package/src/runtime/execution/process-runtime/command-facade.ts +4 -2
- package/src/runtime/execution/process-runtime/gc.ts +1 -1
- package/src/runtime/execution/process-runtime/index.ts +3 -0
- package/src/runtime/execution/process-runtime/interactive-admission.ts +14 -5
- package/src/runtime/execution/process-runtime/persisted-check.ts +285 -0
- package/src/runtime/execution/process-runtime/resource-claims.ts +30 -0
- package/src/runtime/execution/process-runtime/runtime.ts +18 -1
- package/src/runtime/execution/process-runtime/store.ts +1 -19
- package/src/runtime/execution/process-runtime/types.ts +4 -0
- package/src/runtime/execution/thin-harness/execution-router.ts +0 -1
- package/src/runtime/execution/thin-harness/fast-executor.ts +1 -1
- package/src/runtime/execution/thin-harness/lightweight-lanes.ts +1 -2
- package/src/runtime/execution/thin-harness/types.ts +0 -1
- package/src/runtime/execution/workers/executor.ts +1 -1
- package/src/runtime/gateway/mcp/execution-tools.ts +1 -1
- package/src/runtime/gateway/mcp/persisted-check-process.ts +3 -255
- package/src/runtime/gateway/mcp/process-tools.ts +16 -3
- package/src/runtime/gateway/mcp/resource-policy.ts +0 -9
- package/src/runtime/gateway/mcp/router.ts +117 -182
- package/src/runtime/gateway/mcp/runtime-tools.ts +331 -409
- package/src/runtime/gateway/mcp/work-validation-reconciler.ts +1 -219
- package/src/runtime/plugins/browser-adapter.ts +5 -0
- package/src/runtime/plugins/desktop-operator-registration.ts +1 -1
- package/src/runtime/plugins/store.ts +14 -6
- package/src/runtime/plugins/types.ts +1 -1
- package/src/runtime/projections/materialized-view.ts +1 -23
- package/src/runtime/recovery/maintenance-executor.ts +9 -0
- package/src/runtime/resources/ownership.ts +0 -1
- package/src/runtime/root/gateway-adapter.ts +2 -0
- package/src/runtime/root/mcp-transport.ts +10 -2
- package/src/runtime/root/package-runtime-release.ts +161 -0
- package/src/runtime/root/package-runtime-service.ts +172 -0
- package/src/runtime/root/runtime.ts +2 -1
- package/src/runtime/root/scheduler.ts +5 -0
- package/src/runtime/root/service.ts +18 -5
- package/src/runtime/standalone-recovery/core.ts +65 -16
- package/src/runtime/workflow/findings/store.ts +145 -106
- package/src/runtime/workflow/findings/types.ts +22 -0
- package/src/runtime/workflow/schedules/engine.ts +132 -2
- package/src/runtime/workflow/schedules/pending-activation.ts +139 -0
- package/src/runtime/workflow/schedules/work-continuation.ts +218 -0
- package/docs/CHANGELOG.md +0 -978
- package/docs/README.zh-CN.md +0 -58
- package/scripts/smoke-chatgpt-supervised-automation.ts +0 -208
- package/src/cli/commands/controller.ts +0 -680
- package/src/runtime/workflow/campaigns/cleanup.ts +0 -263
- package/src/runtime/workflow/campaigns/engine.ts +0 -112
- package/src/runtime/workflow/campaigns/normalize.ts +0 -100
- package/src/runtime/workflow/campaigns/review.ts +0 -315
- package/src/runtime/workflow/campaigns/store.ts +0 -526
- package/src/runtime/workflow/campaigns/supervisor.ts +0 -112
- package/src/runtime/workflow/campaigns/types.ts +0 -290
- /package/src/runtime/{workflow/campaigns → execution}/workspace-agent.ts +0 -0
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'crypto';
|
|
2
|
-
import type {
|
|
3
|
-
Campaign,
|
|
4
|
-
CampaignCheckpoint,
|
|
5
|
-
CampaignCheckpointKind,
|
|
6
|
-
CampaignReviewPacket,
|
|
7
|
-
CampaignReviewPacketTask,
|
|
8
|
-
CampaignSupervisorDecision,
|
|
9
|
-
} from './types';
|
|
10
|
-
import { computeCampaignGoalHash, updateCampaign } from './store';
|
|
11
|
-
import { campaignSupervisorAdapter } from './supervisor';
|
|
12
|
-
|
|
13
|
-
function now(): string { return new Date().toISOString(); }
|
|
14
|
-
|
|
15
|
-
export function currentCampaignGoal(campaign: Campaign) {
|
|
16
|
-
const goal = campaign.goals.at(-1);
|
|
17
|
-
if (!goal) throw new Error('CAMPAIGN_GOAL_MISSING');
|
|
18
|
-
return goal;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function truncate(value: string, maximum: number): string {
|
|
22
|
-
return value.length <= maximum ? value : `${value.slice(0, Math.max(0, maximum - 3))}...`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function taskPacket(task: Campaign['tasks'][number] | undefined): CampaignReviewPacketTask | undefined {
|
|
26
|
-
if (!task) return undefined;
|
|
27
|
-
return {
|
|
28
|
-
taskId: task.taskId,
|
|
29
|
-
title: truncate(task.title, 512),
|
|
30
|
-
objective: truncate(task.objective, 4_000),
|
|
31
|
-
status: task.status,
|
|
32
|
-
attempt: task.attempt,
|
|
33
|
-
operation: task.operation,
|
|
34
|
-
jobId: task.jobId,
|
|
35
|
-
runId: task.runId,
|
|
36
|
-
error: task.error ? { ...task.error, message: truncate(task.error.message, 4_000) } : undefined,
|
|
37
|
-
evidenceIds: task.evidenceIds.slice(-50),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function campaignProgress(campaign: Campaign): CampaignReviewPacket['progress'] {
|
|
42
|
-
return {
|
|
43
|
-
total: campaign.tasks.length,
|
|
44
|
-
succeeded: campaign.tasks.filter((task) => ['succeeded', 'succeeded_no_change', 'skipped'].includes(task.status)).length,
|
|
45
|
-
running: campaign.tasks.filter((task) => ['queued', 'running'].includes(task.status)).length,
|
|
46
|
-
waitingReview: campaign.tasks.filter((task) => task.status === 'waiting_review').length,
|
|
47
|
-
failed: campaign.tasks.filter((task) => ['failed', 'failed_no_effect'].includes(task.status)).length,
|
|
48
|
-
blocked: campaign.tasks.filter((task) => task.status === 'blocked').length,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function packetBytes(packet: CampaignReviewPacket): number {
|
|
53
|
-
return Buffer.byteLength(JSON.stringify(packet));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function boundedReviewPacket(packet: CampaignReviewPacket, maximumBytes: number): CampaignReviewPacket {
|
|
57
|
-
if (packetBytes(packet) <= maximumBytes) return packet;
|
|
58
|
-
const reduced: CampaignReviewPacket = {
|
|
59
|
-
...packet,
|
|
60
|
-
acceptanceCriteria: packet.acceptanceCriteria.slice(0, 30).map((value) => truncate(value, 1_000)),
|
|
61
|
-
nonGoals: packet.nonGoals.slice(0, 20).map((value) => truncate(value, 1_000)),
|
|
62
|
-
recentEvidenceIds: packet.recentEvidenceIds.slice(-20),
|
|
63
|
-
task: packet.task ? {
|
|
64
|
-
...packet.task,
|
|
65
|
-
title: truncate(packet.task.title, 256),
|
|
66
|
-
objective: truncate(packet.task.objective, 1_500),
|
|
67
|
-
evidenceIds: packet.task.evidenceIds.slice(-20),
|
|
68
|
-
error: packet.task.error ? { ...packet.task.error, message: truncate(packet.task.error.message, 1_500) } : undefined,
|
|
69
|
-
} : undefined,
|
|
70
|
-
goal: truncate(packet.goal, 4_000),
|
|
71
|
-
title: truncate(packet.title, 256),
|
|
72
|
-
};
|
|
73
|
-
if (packetBytes(reduced) <= maximumBytes) return reduced;
|
|
74
|
-
return {
|
|
75
|
-
...reduced,
|
|
76
|
-
acceptanceCriteria: reduced.acceptanceCriteria.slice(0, 10),
|
|
77
|
-
nonGoals: reduced.nonGoals.slice(0, 5),
|
|
78
|
-
recentEvidenceIds: reduced.recentEvidenceIds.slice(-5),
|
|
79
|
-
task: reduced.task ? { ...reduced.task, objective: truncate(reduced.task.objective, 500), evidenceIds: reduced.task.evidenceIds.slice(-5) } : undefined,
|
|
80
|
-
goal: truncate(reduced.goal, 1_500),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function buildCampaignReviewPacket(
|
|
85
|
-
campaign: Campaign,
|
|
86
|
-
checkpointId: string,
|
|
87
|
-
kind: CampaignCheckpointKind,
|
|
88
|
-
nonce: string,
|
|
89
|
-
taskId?: string,
|
|
90
|
-
): CampaignReviewPacket {
|
|
91
|
-
const goal = currentCampaignGoal(campaign);
|
|
92
|
-
const task = taskId ? campaign.tasks.find((entry) => entry.taskId === taskId) : undefined;
|
|
93
|
-
const evidence = campaign.tasks.flatMap((entry) => entry.evidenceIds).slice(-100);
|
|
94
|
-
const packet: CampaignReviewPacket = {
|
|
95
|
-
schemaVersion: 1,
|
|
96
|
-
campaignId: campaign.campaignId,
|
|
97
|
-
checkpointId,
|
|
98
|
-
checkpointKind: kind,
|
|
99
|
-
nonce,
|
|
100
|
-
goalRevision: goal.revision,
|
|
101
|
-
goalHash: goal.goalHash,
|
|
102
|
-
title: campaign.title,
|
|
103
|
-
goal: goal.statement,
|
|
104
|
-
acceptanceCriteria: goal.acceptanceCriteria,
|
|
105
|
-
nonGoals: goal.nonGoals,
|
|
106
|
-
task: taskPacket(task),
|
|
107
|
-
progress: campaignProgress(campaign),
|
|
108
|
-
recentEvidenceIds: evidence,
|
|
109
|
-
createdAt: now(),
|
|
110
|
-
maxResponseBytes: campaign.budget.reviewPacketMaxBytes,
|
|
111
|
-
workspace: {
|
|
112
|
-
mode: campaign.workspace.mode,
|
|
113
|
-
checkoutId: campaign.workspace.checkoutId,
|
|
114
|
-
branch: campaign.workspace.branch,
|
|
115
|
-
baseRevision: campaign.workspace.baseRevision,
|
|
116
|
-
managed: campaign.workspace.managed,
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
return boundedReviewPacket(packet, campaign.budget.reviewPacketMaxBytes);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function openCampaignCheckpoint(
|
|
123
|
-
campaign: Campaign,
|
|
124
|
-
kind: CampaignCheckpointKind,
|
|
125
|
-
taskId?: string,
|
|
126
|
-
): { campaign: Campaign; checkpoint: CampaignCheckpoint; created: boolean } {
|
|
127
|
-
const existing = campaign.checkpoints.find((entry) => entry.status === 'open' && entry.kind === kind && entry.taskId === taskId);
|
|
128
|
-
if (existing) return { campaign, checkpoint: existing, created: false };
|
|
129
|
-
if (campaign.counters.supervisorReviewsOpened >= campaign.budget.maxSupervisorReviews) {
|
|
130
|
-
campaign.status = 'paused';
|
|
131
|
-
campaign.pauseReason = 'Supervisor review budget exhausted.';
|
|
132
|
-
throw new Error('CAMPAIGN_SUPERVISOR_BUDGET_EXHAUSTED');
|
|
133
|
-
}
|
|
134
|
-
const checkpointId = `CP-${Date.now()}-${randomUUID().slice(0, 8)}`;
|
|
135
|
-
const nonce = randomUUID();
|
|
136
|
-
const goal = currentCampaignGoal(campaign);
|
|
137
|
-
const checkpoint: CampaignCheckpoint = {
|
|
138
|
-
checkpointId,
|
|
139
|
-
kind,
|
|
140
|
-
status: 'open',
|
|
141
|
-
nonce,
|
|
142
|
-
goalRevision: goal.revision,
|
|
143
|
-
taskId,
|
|
144
|
-
packet: buildCampaignReviewPacket(campaign, checkpointId, kind, nonce, taskId),
|
|
145
|
-
triggerAttempts: 0,
|
|
146
|
-
createdAt: now(),
|
|
147
|
-
};
|
|
148
|
-
campaign.checkpoints.push(checkpoint);
|
|
149
|
-
campaign.counters.supervisorReviewsOpened += 1;
|
|
150
|
-
if (taskId) {
|
|
151
|
-
const task = campaign.tasks.find((entry) => entry.taskId === taskId);
|
|
152
|
-
if (task) {
|
|
153
|
-
task.checkpointId = checkpointId;
|
|
154
|
-
task.status = 'waiting_review';
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return { campaign, checkpoint, created: true };
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function taskForCheckpoint(campaign: Campaign, checkpoint: CampaignCheckpoint) {
|
|
161
|
-
if (!checkpoint.taskId) return undefined;
|
|
162
|
-
const task = campaign.tasks.find((entry) => entry.taskId === checkpoint.taskId);
|
|
163
|
-
if (!task) throw new Error(`CAMPAIGN_CHECKPOINT_TASK_MISSING: ${checkpoint.taskId}`);
|
|
164
|
-
return task;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export interface SubmitCampaignReviewInput {
|
|
168
|
-
repoId: string;
|
|
169
|
-
campaignId: string;
|
|
170
|
-
checkpointId: string;
|
|
171
|
-
nonce: string;
|
|
172
|
-
goalRevision: number;
|
|
173
|
-
expectedCampaignRevision?: number;
|
|
174
|
-
requestId: string;
|
|
175
|
-
decision: Omit<CampaignSupervisorDecision, 'submittedAt'> & { submittedAt?: string };
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function submitCampaignReview(controllerHome: string, input: SubmitCampaignReviewInput): Campaign {
|
|
179
|
-
return updateCampaign(controllerHome, input.repoId, input.campaignId, input.requestId, (campaign) => {
|
|
180
|
-
const checkpoint = campaign.checkpoints.find((entry) => entry.checkpointId === input.checkpointId);
|
|
181
|
-
if (!checkpoint) throw new Error(`CAMPAIGN_CHECKPOINT_NOT_FOUND: ${input.checkpointId}`);
|
|
182
|
-
if (checkpoint.status !== 'open') throw new Error(`CAMPAIGN_CHECKPOINT_ALREADY_SUBMITTED: ${input.checkpointId}`);
|
|
183
|
-
if (checkpoint.nonce !== input.nonce) throw new Error('CAMPAIGN_CHECKPOINT_NONCE_MISMATCH');
|
|
184
|
-
if (checkpoint.goalRevision !== input.goalRevision || currentCampaignGoal(campaign).revision !== input.goalRevision) {
|
|
185
|
-
throw new Error('CAMPAIGN_GOAL_REVISION_STALE');
|
|
186
|
-
}
|
|
187
|
-
const allowedActions = new Set(['accept', 'request_changes', 'retry', 'skip', 'pause', 'resume', 'approve_final', 'revise_goal', 'escalate']);
|
|
188
|
-
if (!allowedActions.has(input.decision.action)) throw new Error(`CAMPAIGN_REVIEW_ACTION_INVALID: ${input.decision.action}`);
|
|
189
|
-
const decision: CampaignSupervisorDecision = {
|
|
190
|
-
...input.decision,
|
|
191
|
-
summary: input.decision.summary.trim(),
|
|
192
|
-
submittedBy: input.decision.submittedBy.trim() || 'chatgpt',
|
|
193
|
-
submittedAt: input.decision.submittedAt ?? now(),
|
|
194
|
-
};
|
|
195
|
-
if (!decision.summary) throw new Error('CAMPAIGN_REVIEW_SUMMARY_REQUIRED');
|
|
196
|
-
campaignSupervisorAdapter(campaign).validateDecision(campaign, checkpoint, decision);
|
|
197
|
-
checkpoint.status = 'submitted';
|
|
198
|
-
checkpoint.decision = decision;
|
|
199
|
-
checkpoint.submittedAt = decision.submittedAt;
|
|
200
|
-
campaign.counters.supervisorDecisionsAccepted += 1;
|
|
201
|
-
|
|
202
|
-
const task = taskForCheckpoint(campaign, checkpoint);
|
|
203
|
-
const action = decision.action;
|
|
204
|
-
if (action === 'revise_goal') {
|
|
205
|
-
if (!decision.revisedGoal?.statement.trim()) throw new Error('CAMPAIGN_REVISED_GOAL_REQUIRED');
|
|
206
|
-
const currentGoal = currentCampaignGoal(campaign);
|
|
207
|
-
const statement = decision.revisedGoal.statement.trim();
|
|
208
|
-
const acceptanceCriteria = decision.revisedGoal.acceptanceCriteria ?? currentGoal.acceptanceCriteria;
|
|
209
|
-
const nonGoals = decision.revisedGoal.nonGoals ?? currentGoal.nonGoals;
|
|
210
|
-
const nextGoalRevision = currentGoal.revision + 1;
|
|
211
|
-
campaign.goals.push({
|
|
212
|
-
revision: nextGoalRevision,
|
|
213
|
-
goalHash: computeCampaignGoalHash(statement, acceptanceCriteria, nonGoals),
|
|
214
|
-
statement,
|
|
215
|
-
acceptanceCriteria,
|
|
216
|
-
nonGoals,
|
|
217
|
-
changedBy: decision.submittedBy,
|
|
218
|
-
changedAt: decision.submittedAt,
|
|
219
|
-
reason: decision.revisedGoal.reason ?? decision.summary,
|
|
220
|
-
});
|
|
221
|
-
const checkpointsToReopen = campaign.checkpoints.filter((entry) =>
|
|
222
|
-
entry.goalRevision === currentGoal.revision
|
|
223
|
-
&& (entry.status === 'open' || entry.checkpointId === checkpoint.checkpointId),
|
|
224
|
-
);
|
|
225
|
-
for (const stale of checkpointsToReopen) {
|
|
226
|
-
if (stale.checkpointId !== checkpoint.checkpointId) stale.status = 'superseded';
|
|
227
|
-
const staleTask = taskForCheckpoint(campaign, stale);
|
|
228
|
-
if (staleTask) {
|
|
229
|
-
staleTask.checkpointId = undefined;
|
|
230
|
-
staleTask.status = 'waiting_review';
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
for (const stale of checkpointsToReopen) openCampaignCheckpoint(campaign, stale.kind, stale.taskId);
|
|
234
|
-
campaign.status = 'waiting_for_supervisor';
|
|
235
|
-
campaign.pauseReason = undefined;
|
|
236
|
-
campaign.nextReconcileAt = undefined;
|
|
237
|
-
return campaign;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (checkpoint.kind === 'task_review' && task) {
|
|
241
|
-
if (action === 'accept') {
|
|
242
|
-
task.status = 'succeeded';
|
|
243
|
-
task.completedAt = decision.submittedAt;
|
|
244
|
-
task.error = undefined;
|
|
245
|
-
task.supervisorInstructions = undefined;
|
|
246
|
-
campaign.status = 'active';
|
|
247
|
-
} else if (action === 'request_changes' || action === 'retry') {
|
|
248
|
-
task.status = 'changes_requested';
|
|
249
|
-
task.jobId = undefined;
|
|
250
|
-
task.maxAttempts = Math.min(10, Math.max(task.maxAttempts, task.attempt + 1));
|
|
251
|
-
task.checkpointId = undefined;
|
|
252
|
-
task.nextAttemptAt = undefined;
|
|
253
|
-
task.error = undefined;
|
|
254
|
-
task.supervisorInstructions = decision.instructions ?? decision.summary;
|
|
255
|
-
campaign.status = 'active';
|
|
256
|
-
} else if (action === 'skip') {
|
|
257
|
-
task.status = 'skipped';
|
|
258
|
-
task.completedAt = decision.submittedAt;
|
|
259
|
-
campaign.status = 'active';
|
|
260
|
-
} else if (action === 'pause' || action === 'escalate') {
|
|
261
|
-
campaign.status = 'paused';
|
|
262
|
-
campaign.pauseReason = decision.summary;
|
|
263
|
-
} else {
|
|
264
|
-
throw new Error(`CAMPAIGN_REVIEW_ACTION_INVALID: ${action} for task_review`);
|
|
265
|
-
}
|
|
266
|
-
} else if (checkpoint.kind === 'failure' && task) {
|
|
267
|
-
if (action === 'retry' || action === 'request_changes') {
|
|
268
|
-
task.status = 'changes_requested';
|
|
269
|
-
task.jobId = undefined;
|
|
270
|
-
task.maxAttempts = Math.min(10, Math.max(task.maxAttempts, task.attempt + 1));
|
|
271
|
-
task.checkpointId = undefined;
|
|
272
|
-
task.nextAttemptAt = undefined;
|
|
273
|
-
task.error = undefined;
|
|
274
|
-
task.supervisorInstructions = decision.instructions ?? decision.summary;
|
|
275
|
-
campaign.status = 'active';
|
|
276
|
-
} else if (action === 'skip') {
|
|
277
|
-
task.status = 'skipped';
|
|
278
|
-
task.completedAt = decision.submittedAt;
|
|
279
|
-
campaign.status = 'active';
|
|
280
|
-
} else if (action === 'pause' || action === 'escalate') {
|
|
281
|
-
campaign.status = 'paused';
|
|
282
|
-
campaign.pauseReason = decision.summary;
|
|
283
|
-
} else {
|
|
284
|
-
throw new Error(`CAMPAIGN_REVIEW_ACTION_INVALID: ${action} for failure`);
|
|
285
|
-
}
|
|
286
|
-
} else if (checkpoint.kind === 'final') {
|
|
287
|
-
if (action === 'approve_final' || action === 'accept') {
|
|
288
|
-
campaign.status = 'ready_for_human_acceptance';
|
|
289
|
-
campaign.pauseReason = undefined;
|
|
290
|
-
} else if (action === 'request_changes' || action === 'pause' || action === 'escalate') {
|
|
291
|
-
campaign.status = 'paused';
|
|
292
|
-
campaign.pauseReason = decision.instructions ?? decision.summary;
|
|
293
|
-
} else {
|
|
294
|
-
throw new Error(`CAMPAIGN_REVIEW_ACTION_INVALID: ${action} for final`);
|
|
295
|
-
}
|
|
296
|
-
} else {
|
|
297
|
-
if (action === 'accept' || action === 'resume') {
|
|
298
|
-
campaign.status = 'active';
|
|
299
|
-
campaign.pauseReason = undefined;
|
|
300
|
-
} else if (action === 'pause' || action === 'escalate') {
|
|
301
|
-
campaign.status = 'paused';
|
|
302
|
-
campaign.pauseReason = decision.summary;
|
|
303
|
-
} else {
|
|
304
|
-
throw new Error(`CAMPAIGN_REVIEW_ACTION_INVALID: ${action} for ${checkpoint.kind}`);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
campaign.nextReconcileAt = undefined;
|
|
308
|
-
return campaign;
|
|
309
|
-
}, {
|
|
310
|
-
expectedRevision: input.expectedCampaignRevision,
|
|
311
|
-
eventType: 'campaign_review_submitted',
|
|
312
|
-
eventData: { checkpointId: input.checkpointId, action: input.decision.action, goalRevision: input.goalRevision },
|
|
313
|
-
requestFingerprint: JSON.stringify({ checkpointId: input.checkpointId, nonce: input.nonce, goalRevision: input.goalRevision, decision: input.decision }),
|
|
314
|
-
});
|
|
315
|
-
}
|