@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
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { resolveControllerHome } from '../../../cli/repositories/controller-home';
|
|
5
|
+
import { getSchedule, saveSchedule } from './store';
|
|
6
|
+
|
|
7
|
+
const EXTERNAL_CONTROLLER_WAKE_OPERATION = 'external_controller_wake';
|
|
8
|
+
|
|
9
|
+
export interface PendingContinuationActivationMarker {
|
|
10
|
+
schemaVersion: 1;
|
|
11
|
+
repoId: string;
|
|
12
|
+
scheduleId: string;
|
|
13
|
+
workId: string;
|
|
14
|
+
queuedAt: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface PendingContinuationActivationResult {
|
|
18
|
+
repoId: string;
|
|
19
|
+
scheduleId: string;
|
|
20
|
+
workId: string;
|
|
21
|
+
status: 'activated' | 'already_active' | 'cancelled' | 'failed';
|
|
22
|
+
reason?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function pendingContinuationActivationRoot(controllerHome: string): string {
|
|
26
|
+
return join(resolveControllerHome(controllerHome), 'runtime', 'pending-continuation-activations');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function markerPath(controllerHome: string, repoId: string, scheduleId: string): string {
|
|
30
|
+
const digest = createHash('sha256').update(`${repoId}:${scheduleId}`).digest('hex').slice(0, 32);
|
|
31
|
+
return join(pendingContinuationActivationRoot(controllerHome), `${digest}.json`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function validMarker(value: unknown): value is PendingContinuationActivationMarker {
|
|
35
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
36
|
+
const marker = value as PendingContinuationActivationMarker;
|
|
37
|
+
return marker.schemaVersion === 1
|
|
38
|
+
&& typeof marker.repoId === 'string' && marker.repoId.length > 0
|
|
39
|
+
&& typeof marker.scheduleId === 'string' && marker.scheduleId.length > 0
|
|
40
|
+
&& typeof marker.workId === 'string' && marker.workId.length > 0
|
|
41
|
+
&& typeof marker.queuedAt === 'string' && Number.isFinite(Date.parse(marker.queuedAt));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function readMarker(path: string): PendingContinuationActivationMarker {
|
|
45
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8')) as unknown;
|
|
46
|
+
if (!validMarker(parsed)) throw new Error('PENDING_CONTINUATION_ACTIVATION_MARKER_INVALID');
|
|
47
|
+
return parsed;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function queuePendingContinuationActivation(
|
|
51
|
+
controllerHome: string,
|
|
52
|
+
repoId: string,
|
|
53
|
+
scheduleId: string,
|
|
54
|
+
): PendingContinuationActivationMarker {
|
|
55
|
+
const schedule = getSchedule(controllerHome, repoId, scheduleId);
|
|
56
|
+
if (schedule.action.operation !== EXTERNAL_CONTROLLER_WAKE_OPERATION) {
|
|
57
|
+
throw new Error('PENDING_CONTINUATION_ACTIVATION_REQUIRES_EXTERNAL_CONTROLLER_WAKE');
|
|
58
|
+
}
|
|
59
|
+
const workId = schedule.action.arguments?.work_id;
|
|
60
|
+
if (typeof workId !== 'string' || !workId.trim()) {
|
|
61
|
+
throw new Error('PENDING_CONTINUATION_ACTIVATION_WORK_ID_REQUIRED');
|
|
62
|
+
}
|
|
63
|
+
if (!schedule.enabled) throw new Error('PENDING_CONTINUATION_ACTIVATION_REQUIRES_ENABLED_SCHEDULE');
|
|
64
|
+
if (!schedule.policy.shadowMode) throw new Error('PENDING_CONTINUATION_ACTIVATION_REQUIRES_SHADOW_SCHEDULE');
|
|
65
|
+
|
|
66
|
+
const path = markerPath(controllerHome, repoId, scheduleId);
|
|
67
|
+
if (existsSync(path)) {
|
|
68
|
+
const existing = readMarker(path);
|
|
69
|
+
if (existing.repoId !== repoId || existing.scheduleId !== scheduleId || existing.workId !== workId) {
|
|
70
|
+
throw new Error('PENDING_CONTINUATION_ACTIVATION_MARKER_CONFLICT');
|
|
71
|
+
}
|
|
72
|
+
return existing;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const marker: PendingContinuationActivationMarker = {
|
|
76
|
+
schemaVersion: 1,
|
|
77
|
+
repoId,
|
|
78
|
+
scheduleId,
|
|
79
|
+
workId: workId.trim(),
|
|
80
|
+
queuedAt: new Date().toISOString(),
|
|
81
|
+
};
|
|
82
|
+
const root = pendingContinuationActivationRoot(controllerHome);
|
|
83
|
+
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
84
|
+
const temp = `${path}.${process.pid}.${randomUUID().slice(0, 8)}.tmp`;
|
|
85
|
+
writeFileSync(temp, `${JSON.stringify(marker, null, 2)}\n`, { encoding: 'utf8', mode: 0o600, flag: 'wx' });
|
|
86
|
+
renameSync(temp, path);
|
|
87
|
+
return marker;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function listPendingContinuationActivations(controllerHome: string): PendingContinuationActivationMarker[] {
|
|
91
|
+
const root = pendingContinuationActivationRoot(controllerHome);
|
|
92
|
+
if (!existsSync(root)) return [];
|
|
93
|
+
return readdirSync(root)
|
|
94
|
+
.filter((name) => name.endsWith('.json'))
|
|
95
|
+
.flatMap((name) => {
|
|
96
|
+
try { return [readMarker(join(root, name))]; } catch { return []; }
|
|
97
|
+
})
|
|
98
|
+
.sort((a, b) => a.queuedAt.localeCompare(b.queuedAt));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function applyPendingContinuationActivations(controllerHome: string): PendingContinuationActivationResult[] {
|
|
102
|
+
const root = pendingContinuationActivationRoot(controllerHome);
|
|
103
|
+
if (!existsSync(root)) return [];
|
|
104
|
+
const results: PendingContinuationActivationResult[] = [];
|
|
105
|
+
for (const name of readdirSync(root).filter((entry) => entry.endsWith('.json')).sort()) {
|
|
106
|
+
const path = join(root, name);
|
|
107
|
+
try {
|
|
108
|
+
const marker = readMarker(path);
|
|
109
|
+
const schedule = getSchedule(controllerHome, marker.repoId, marker.scheduleId);
|
|
110
|
+
const workId = schedule.action.arguments?.work_id;
|
|
111
|
+
if (schedule.action.operation !== EXTERNAL_CONTROLLER_WAKE_OPERATION || workId !== marker.workId) {
|
|
112
|
+
results.push({ ...marker, status: 'failed', reason: 'Schedule no longer targets the queued Work continuation.' });
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (!schedule.enabled) {
|
|
116
|
+
rmSync(path, { force: true });
|
|
117
|
+
results.push({ ...marker, status: 'cancelled', reason: 'Schedule was disabled before Runtime activation.' });
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (!schedule.policy.shadowMode) {
|
|
121
|
+
rmSync(path, { force: true });
|
|
122
|
+
results.push({ ...marker, status: 'already_active' });
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
saveSchedule(controllerHome, { ...schedule, policy: { ...schedule.policy, shadowMode: false } });
|
|
126
|
+
rmSync(path, { force: true });
|
|
127
|
+
results.push({ ...marker, status: 'activated' });
|
|
128
|
+
} catch (error) {
|
|
129
|
+
results.push({
|
|
130
|
+
repoId: 'unknown',
|
|
131
|
+
scheduleId: name,
|
|
132
|
+
workId: 'unknown',
|
|
133
|
+
status: 'failed',
|
|
134
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return results;
|
|
139
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { getWorkContract, isTerminalWorkContractStatus, type WorkContract } from '../../control-plane/facade';
|
|
3
|
+
import { assertAutomatedOperationAllowed } from '../../control-plane/governance/external-effects';
|
|
4
|
+
import { evaluateSchedule } from './engine';
|
|
5
|
+
import {
|
|
6
|
+
createSchedule,
|
|
7
|
+
getSchedule,
|
|
8
|
+
listOccurrences,
|
|
9
|
+
listSchedules,
|
|
10
|
+
saveSchedule,
|
|
11
|
+
} from './store';
|
|
12
|
+
import type {
|
|
13
|
+
RepositorySchedule,
|
|
14
|
+
ScheduleCondition,
|
|
15
|
+
ScheduleOccurrence,
|
|
16
|
+
ScheduleTrigger,
|
|
17
|
+
ScheduleTriggerContext,
|
|
18
|
+
ScheduleTriggerType,
|
|
19
|
+
} from './types';
|
|
20
|
+
|
|
21
|
+
export type ContinuationControllerType = 'chatgpt' | 'codex' | 'claude' | 'grok';
|
|
22
|
+
|
|
23
|
+
export interface WorkContinuationScheduleInput {
|
|
24
|
+
workId: string;
|
|
25
|
+
controllerType?: ContinuationControllerType;
|
|
26
|
+
executable?: string;
|
|
27
|
+
launchArgs?: string[];
|
|
28
|
+
launchReservationMs?: number;
|
|
29
|
+
handoffId?: string;
|
|
30
|
+
browserSessionId?: string;
|
|
31
|
+
conversationUrl?: string;
|
|
32
|
+
continuationPrompt?: string;
|
|
33
|
+
scheduleName?: string;
|
|
34
|
+
requestId?: string;
|
|
35
|
+
triggerType?: ScheduleTriggerType;
|
|
36
|
+
everyMinutes?: number;
|
|
37
|
+
cronExpression?: string;
|
|
38
|
+
timezone?: string;
|
|
39
|
+
catchUpMinutes?: number;
|
|
40
|
+
calendarAt?: string;
|
|
41
|
+
condition?: ScheduleCondition;
|
|
42
|
+
eventName?: string;
|
|
43
|
+
dependencyJobIds?: string[];
|
|
44
|
+
maxFailures?: number;
|
|
45
|
+
cooldownMinutes?: number;
|
|
46
|
+
dailyBudgetMinutes?: number;
|
|
47
|
+
shadowMode?: boolean;
|
|
48
|
+
backoffBaseMinutes?: number;
|
|
49
|
+
backoffMaxMinutes?: number;
|
|
50
|
+
stopConditions?: string[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface WorkContinuationScheduleListOptions {
|
|
54
|
+
workId?: string;
|
|
55
|
+
includeOccurrences?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function requiredWork(controllerHome: string, repoId: string, workId: string): WorkContract {
|
|
59
|
+
const normalized = workId.trim();
|
|
60
|
+
if (!normalized) throw new Error('WORK_ID_REQUIRED');
|
|
61
|
+
const work = getWorkContract({ controllerHome, repoId }, normalized);
|
|
62
|
+
if (!work) throw new Error(`WORK_NOT_FOUND: ${normalized}`);
|
|
63
|
+
return work;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function activeWork(controllerHome: string, repoId: string, workId: string): WorkContract {
|
|
67
|
+
const work = requiredWork(controllerHome, repoId, workId);
|
|
68
|
+
if (isTerminalWorkContractStatus(work.status)) throw new Error(`WORK_ALREADY_TERMINAL: ${work.workId}:${work.status}`);
|
|
69
|
+
return work;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function continuationSchedule(schedule: RepositorySchedule): RepositorySchedule {
|
|
73
|
+
if (schedule.action.operation !== 'external_controller_wake') {
|
|
74
|
+
throw new Error(`SCHEDULE_NOT_WORK_CONTINUATION: ${schedule.scheduleId}`);
|
|
75
|
+
}
|
|
76
|
+
return schedule;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function normalizedTrigger(input: WorkContinuationScheduleInput): ScheduleTrigger {
|
|
80
|
+
const type = input.triggerType ?? (input.everyMinutes !== undefined ? 'interval' : 'manual');
|
|
81
|
+
return {
|
|
82
|
+
type,
|
|
83
|
+
everyMinutes: input.everyMinutes !== undefined ? Math.max(1, Math.trunc(input.everyMinutes)) : undefined,
|
|
84
|
+
cronExpression: input.cronExpression,
|
|
85
|
+
timezone: input.timezone,
|
|
86
|
+
catchUpMinutes: input.catchUpMinutes !== undefined ? Math.max(0, Math.trunc(input.catchUpMinutes)) : undefined,
|
|
87
|
+
calendarAt: input.calendarAt,
|
|
88
|
+
condition: input.condition,
|
|
89
|
+
eventName: input.eventName,
|
|
90
|
+
dependencyJobIds: input.dependencyJobIds,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function wakeArguments(input: WorkContinuationScheduleInput, controllerType: ContinuationControllerType): Record<string, unknown> {
|
|
95
|
+
return {
|
|
96
|
+
work_id: input.workId.trim(),
|
|
97
|
+
controller_type: controllerType,
|
|
98
|
+
...(input.executable?.trim() ? { executable: input.executable.trim() } : {}),
|
|
99
|
+
...(input.launchArgs ? { launch_args: input.launchArgs.map(String) } : {}),
|
|
100
|
+
...(input.launchReservationMs !== undefined ? { launch_reservation_ms: input.launchReservationMs } : {}),
|
|
101
|
+
...(input.handoffId?.trim() ? { handoff_id: input.handoffId.trim() } : {}),
|
|
102
|
+
...(input.browserSessionId?.trim() ? { browser_session_id: input.browserSessionId.trim() } : {}),
|
|
103
|
+
...(input.conversationUrl?.trim() ? { conversation_url: input.conversationUrl.trim() } : {}),
|
|
104
|
+
...(input.continuationPrompt?.trim() ? { continuation_prompt: input.continuationPrompt.trim() } : {}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function createWorkContinuationSchedule(
|
|
109
|
+
controllerHome: string,
|
|
110
|
+
repoId: string,
|
|
111
|
+
input: WorkContinuationScheduleInput,
|
|
112
|
+
): { schedule: RepositorySchedule; work: WorkContract } {
|
|
113
|
+
const work = activeWork(controllerHome, repoId, input.workId);
|
|
114
|
+
const controllerType = input.controllerType ?? 'chatgpt';
|
|
115
|
+
const trigger = normalizedTrigger(input);
|
|
116
|
+
const actionArguments = wakeArguments(input, controllerType);
|
|
117
|
+
assertAutomatedOperationAllowed('external_controller_wake', actionArguments);
|
|
118
|
+
const name = input.scheduleName?.trim() || `Continue Work ${work.workId}`;
|
|
119
|
+
const semantic = JSON.stringify({
|
|
120
|
+
repoId,
|
|
121
|
+
workId: work.workId,
|
|
122
|
+
controllerType,
|
|
123
|
+
trigger,
|
|
124
|
+
name,
|
|
125
|
+
actionArguments,
|
|
126
|
+
policy: {
|
|
127
|
+
maxFailures: input.maxFailures,
|
|
128
|
+
cooldownMinutes: input.cooldownMinutes,
|
|
129
|
+
dailyBudgetMinutes: input.dailyBudgetMinutes,
|
|
130
|
+
shadowMode: input.shadowMode,
|
|
131
|
+
backoffBaseMinutes: input.backoffBaseMinutes,
|
|
132
|
+
backoffMaxMinutes: input.backoffMaxMinutes,
|
|
133
|
+
},
|
|
134
|
+
stopConditions: input.stopConditions,
|
|
135
|
+
});
|
|
136
|
+
const requestId = input.requestId?.trim()
|
|
137
|
+
|| `work-continuation:${repoId}:${work.workId}:${createHash('sha256').update(semantic).digest('hex').slice(0, 16)}`;
|
|
138
|
+
const schedule = createSchedule(controllerHome, {
|
|
139
|
+
requestId,
|
|
140
|
+
repoId,
|
|
141
|
+
name,
|
|
142
|
+
enabled: true,
|
|
143
|
+
trigger,
|
|
144
|
+
policy: {
|
|
145
|
+
maxActiveOccurrences: 1,
|
|
146
|
+
maxFailures: input.maxFailures !== undefined ? Math.max(1, Math.trunc(input.maxFailures)) : 3,
|
|
147
|
+
cooldownMinutes: input.cooldownMinutes !== undefined ? Math.max(0, Math.trunc(input.cooldownMinutes)) : 120,
|
|
148
|
+
dailyBudgetMinutes: input.dailyBudgetMinutes !== undefined ? Math.max(1, Math.trunc(input.dailyBudgetMinutes)) : 180,
|
|
149
|
+
shadowMode: input.shadowMode !== false,
|
|
150
|
+
backoffBaseMinutes: input.backoffBaseMinutes !== undefined ? Math.max(1, Math.trunc(input.backoffBaseMinutes)) : 5,
|
|
151
|
+
backoffMaxMinutes: input.backoffMaxMinutes !== undefined ? Math.max(1, Math.trunc(input.backoffMaxMinutes)) : 24 * 60,
|
|
152
|
+
},
|
|
153
|
+
// The schedule only wakes a Controller. The Controller acquires Work/resource
|
|
154
|
+
// ownership separately, so the wake itself must not claim repository writes.
|
|
155
|
+
action: { operation: 'external_controller_wake', target: 'runtime', arguments: actionArguments, resourceClaims: [] },
|
|
156
|
+
stopConditions: input.stopConditions ?? ['work_terminal', 'human_review_required', 'external_blocker'],
|
|
157
|
+
});
|
|
158
|
+
return { schedule, work };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function listWorkContinuationSchedules(
|
|
162
|
+
controllerHome: string,
|
|
163
|
+
repoId: string,
|
|
164
|
+
options: WorkContinuationScheduleListOptions = {},
|
|
165
|
+
): { schedules: RepositorySchedule[]; occurrences?: ScheduleOccurrence[] } {
|
|
166
|
+
const schedules = listSchedules(controllerHome, repoId)
|
|
167
|
+
.filter((entry) => entry.action.operation === 'external_controller_wake')
|
|
168
|
+
.filter((entry) => !options.workId || entry.action.arguments?.work_id === options.workId);
|
|
169
|
+
if (!options.includeOccurrences) return { schedules };
|
|
170
|
+
const scheduleIds = new Set(schedules.map((entry) => entry.scheduleId));
|
|
171
|
+
const occurrences = listOccurrences(controllerHome, repoId, undefined, 100)
|
|
172
|
+
.filter((entry) => scheduleIds.has(entry.scheduleId));
|
|
173
|
+
return { schedules, occurrences };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function getWorkContinuationSchedule(
|
|
177
|
+
controllerHome: string,
|
|
178
|
+
repoId: string,
|
|
179
|
+
scheduleId: string,
|
|
180
|
+
includeOccurrences = false,
|
|
181
|
+
): { schedule: RepositorySchedule; occurrences?: ScheduleOccurrence[] } {
|
|
182
|
+
const schedule = continuationSchedule(getSchedule(controllerHome, repoId, scheduleId));
|
|
183
|
+
return {
|
|
184
|
+
schedule,
|
|
185
|
+
...(includeOccurrences ? { occurrences: listOccurrences(controllerHome, repoId, schedule.scheduleId, 50) } : {}),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function pauseWorkContinuationSchedule(
|
|
190
|
+
controllerHome: string,
|
|
191
|
+
repoId: string,
|
|
192
|
+
scheduleId: string,
|
|
193
|
+
reason?: string,
|
|
194
|
+
): RepositorySchedule {
|
|
195
|
+
const schedule = continuationSchedule(getSchedule(controllerHome, repoId, scheduleId));
|
|
196
|
+
return saveSchedule(controllerHome, {
|
|
197
|
+
...schedule,
|
|
198
|
+
enabled: false,
|
|
199
|
+
pausedReason: reason?.trim() || 'Paused through rh_work.',
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function resumeWorkContinuationSchedule(controllerHome: string, repoId: string, scheduleId: string): RepositorySchedule {
|
|
204
|
+
const schedule = continuationSchedule(getSchedule(controllerHome, repoId, scheduleId));
|
|
205
|
+
const workId = typeof schedule.action.arguments?.work_id === 'string' ? schedule.action.arguments.work_id : '';
|
|
206
|
+
activeWork(controllerHome, repoId, workId);
|
|
207
|
+
return saveSchedule(controllerHome, { ...schedule, enabled: true, pausedReason: undefined });
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export async function triggerWorkContinuationSchedule(
|
|
211
|
+
controllerHome: string,
|
|
212
|
+
repoId: string,
|
|
213
|
+
scheduleId: string,
|
|
214
|
+
context: ScheduleTriggerContext = { source: 'manual' },
|
|
215
|
+
): Promise<ScheduleOccurrence | undefined> {
|
|
216
|
+
const schedule = continuationSchedule(getSchedule(controllerHome, repoId, scheduleId));
|
|
217
|
+
return evaluateSchedule(controllerHome, schedule, true, context);
|
|
218
|
+
}
|