conductor-remote 1.117.0 → 1.118.1
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/README.md +10 -8
- package/dist/assets/{PierrePatch-D3_YBIAr.js → PierrePatch-Dh-08CLI.js} +1 -1
- package/dist/assets/index-BRzsSW8g.css +1 -0
- package/dist/assets/index-BpY3Jhxk.js +65 -0
- package/dist/index.html +2 -2
- package/dist/push-sw.js +2 -2
- package/dist/sw.js +1 -1
- package/dist-node/scripts/nosleep-setup.js +2 -2
- package/dist-node/scripts/nosleep.js +3 -3
- package/dist-node/scripts/service/commands.js +32 -0
- package/dist-node/scripts/service/configuration.js +205 -0
- package/dist-node/scripts/service/environment.js +59 -0
- package/dist-node/scripts/service/flags.js +45 -0
- package/dist-node/scripts/service/installation.js +91 -0
- package/dist-node/scripts/service/launch-agent.js +134 -0
- package/dist-node/scripts/service/network.js +244 -0
- package/dist-node/scripts/service/presentation.js +101 -0
- package/dist-node/scripts/service/voice.js +113 -0
- package/dist-node/scripts/service.js +5 -980
- package/dist-node/src/{agent-config.js → agents/agent-config.js} +1 -1
- package/dist-node/src/{model-cache.js → agents/model-cache.js} +1 -1
- package/dist-node/src/{roles.js → agents/roles.js} +3 -3
- package/dist-node/src/db.js +1 -1
- package/dist-node/src/{parked.js → delivery/parked.js} +1 -1
- package/dist-node/src/{dev-server.js → dev-server/controller.js} +8 -291
- package/dist-node/src/dev-server/ports.js +63 -0
- package/dist-node/src/dev-server/processes.js +73 -0
- package/dist-node/src/dev-server/proxy.js +158 -0
- package/dist-node/src/{run-activity.js → dev-server/run-activity.js} +2 -2
- package/dist-node/src/dev-server/types.js +1 -0
- package/dist-node/src/{file-preview.js → files/file-preview.js} +1 -1
- package/dist-node/src/{change-stats.js → git/change-stats.js} +1 -1
- package/dist-node/src/{git.js → git/diff.js} +43 -18
- package/dist-node/src/{autoupdate.js → host/autoupdate.js} +1 -1
- package/dist-node/src/{funnel-watchdog.js → host/funnel-watchdog.js} +4 -4
- package/dist-node/src/{logbuf.js → host/logbuf.js} +1 -1
- package/dist-node/src/{nosleep-helper.js → host/nosleep-helper.js} +1 -1
- package/dist-node/src/{tailscale.js → host/tailscale.js} +1 -1
- package/dist-node/src/http/router-types.js +2 -0
- package/dist-node/src/http/router.js +78 -0
- package/dist-node/src/http/routes/create-workspace.js +90 -0
- package/dist-node/src/http/routes/files.js +53 -0
- package/dist-node/src/http/routes/prompts.js +363 -0
- package/dist-node/src/http/routes/sessions.js +279 -0
- package/dist-node/src/http/routes/state.js +186 -0
- package/dist-node/src/http/routes/system.js +220 -0
- package/dist-node/src/http/routes/voice.js +117 -0
- package/dist-node/src/http/routes/workflows.js +248 -0
- package/dist-node/src/http/routes/workspaces.js +267 -0
- package/dist-node/src/http/services/base.js +252 -0
- package/dist-node/src/http/services/delegations.js +301 -0
- package/dist-node/src/http/services/delivery.js +433 -0
- package/dist-node/src/http/services/files.js +199 -0
- package/dist-node/src/http/services/mcp.js +94 -0
- package/dist-node/src/http/services/responses.js +120 -0
- package/dist-node/src/http/services/voice.js +147 -0
- package/dist-node/src/http/services/workflow-probes.js +215 -0
- package/dist-node/src/http/services/workflow-state.js +195 -0
- package/dist-node/src/http/services/workflow.js +366 -0
- package/dist-node/src/http/services.js +35 -0
- package/dist-node/src/mcp/arguments.js +14 -0
- package/dist-node/src/mcp/dispatcher.js +56 -0
- package/dist-node/src/mcp/formatters.js +110 -0
- package/dist-node/src/mcp/protocol.js +7 -0
- package/dist-node/src/mcp/registry.js +66 -0
- package/dist-node/src/mcp/tools/agent-options.js +122 -0
- package/dist-node/src/mcp/tools/chat-actions.js +194 -0
- package/dist-node/src/mcp/tools/chats.js +194 -0
- package/dist-node/src/mcp/tools/delegation.js +135 -0
- package/dist-node/src/mcp/tools/system.js +135 -0
- package/dist-node/src/mcp/tools/voice.js +136 -0
- package/dist-node/src/mcp/tools/workspaces.js +259 -0
- package/dist-node/src/mcp/types.js +1 -0
- package/dist-node/src/mcp.js +6 -4
- package/dist-node/src/{notify.js → notifications/notify.js} +5 -5
- package/dist-node/src/{webpush.js → notifications/webpush.js} +1 -1
- package/dist-node/src/orchestration/delegation/codec.js +201 -0
- package/dist-node/src/{delegation-intake.js → orchestration/delegation/intake.js} +2 -2
- package/dist-node/src/{delegation-prompt.js → orchestration/delegation/prompt.js} +1 -1
- package/dist-node/src/orchestration/delegation/queue.js +255 -0
- package/dist-node/src/orchestration/delegation/store.js +111 -0
- package/dist-node/src/orchestration/delegation/types.js +2 -0
- package/dist-node/src/orchestration/persistence/capabilities.js +109 -0
- package/dist-node/src/orchestration/persistence/codecs.js +148 -0
- package/dist-node/src/orchestration/persistence/connection.js +205 -0
- package/dist-node/src/orchestration/persistence/db.js +101 -0
- package/dist-node/src/orchestration/persistence/effect-recovery.js +227 -0
- package/dist-node/src/orchestration/persistence/effect-transitions.js +157 -0
- package/dist-node/src/orchestration/persistence/effects.js +109 -0
- package/dist-node/src/orchestration/persistence/errors.js +39 -0
- package/dist-node/src/orchestration/persistence/events.js +29 -0
- package/dist-node/src/orchestration/persistence/idempotency.js +82 -0
- package/dist-node/src/orchestration/persistence/job-attempts.js +114 -0
- package/dist-node/src/orchestration/persistence/jobs.js +159 -0
- package/dist-node/src/orchestration/persistence/projections.js +190 -0
- package/dist-node/src/orchestration/persistence/quarantine.js +46 -0
- package/dist-node/src/orchestration/persistence/records.js +115 -0
- package/dist-node/src/orchestration/persistence/relays.js +78 -0
- package/dist-node/src/orchestration/persistence/runs.js +156 -0
- package/dist-node/src/{orchestration-schema.js → orchestration/persistence/schema.js} +1 -1
- package/dist-node/src/orchestration/persistence/types.js +1 -0
- package/dist-node/src/orchestration/persistence/ui-lease.js +197 -0
- package/dist-node/src/orchestration/persistence/values.js +114 -0
- package/dist-node/src/orchestration/workflow/commands.js +309 -0
- package/dist-node/src/orchestration/workflow/coordinator.js +28 -0
- package/dist-node/src/orchestration/workflow/effect-recovery.js +125 -0
- package/dist-node/src/orchestration/workflow/effects.js +307 -0
- package/dist-node/src/orchestration/workflow/errors.js +13 -0
- package/dist-node/src/orchestration/workflow/helpers.js +154 -0
- package/dist-node/src/orchestration/workflow/job-dispatch.js +312 -0
- package/dist-node/src/orchestration/workflow/job-results.js +280 -0
- package/dist-node/src/{workflow.js → orchestration/workflow/prompts.js} +2 -2
- package/dist-node/src/orchestration/workflow/root.js +293 -0
- package/dist-node/src/orchestration/workflow/start.js +99 -0
- package/dist-node/src/orchestration/workflow/state.js +105 -0
- package/dist-node/src/orchestration/workflow/types.js +1 -0
- package/dist-node/src/orchestration/workflow/wake.js +164 -0
- package/dist-node/src/prefs.js +1 -1
- package/dist-node/src/{background-tasks.js → reads/background-tasks.js} +1 -1
- package/dist-node/src/reads/messages.js +362 -0
- package/dist-node/src/reads/repository.js +87 -0
- package/dist-node/src/reads/sessions.js +165 -0
- package/dist-node/src/reads/types.js +1 -0
- package/dist-node/src/reads/workspaces.js +230 -0
- package/dist-node/src/reads/worktrees.js +45 -0
- package/dist-node/src/routes.js +5 -5
- package/dist-node/src/{search.js → search/coordinator.js} +4 -4
- package/dist-node/src/{search-worker.js → search/worker.js} +3 -3
- package/dist-node/src/server.js +14 -3930
- package/dist-node/src/settings.js +1 -1
- package/dist-node/src/shared.js +10 -10
- package/dist-node/src/{transcript.js → transcript/parser.js} +4 -4
- package/dist-node/src/{tool-usage-worker.js → usage/tool-usage-worker.js} +1 -1
- package/dist-node/src/{tool-usage.js → usage/tool-usage.js} +1 -1
- package/dist-node/src/voice/brief.js +22 -50
- package/dist-node/src/voice/context.js +1 -1
- package/dist-node/src/voice/dates.js +38 -0
- package/dist-node/src/voice/history.js +14 -5
- package/dist-node/src/voice/prompt.js +10 -9
- package/dist-node/src/voice/recall.js +115 -0
- package/dist-node/src/{speech.js → voice/speech.js} +1 -1
- package/dist-node/src/voice/tools.js +92 -3
- package/dist-node/src/voice/webrtc.js +1 -1
- package/dist-node/src/wire.js +2 -2
- package/dist-node/src/writes/actuator.js +124 -0
- package/dist-node/src/writes/agent-options.js +151 -0
- package/dist-node/src/writes/applescript/agent-options.applescript +334 -0
- package/dist-node/src/writes/applescript/chat-targeting.applescript +149 -0
- package/dist-node/src/writes/applescript/composer.applescript +195 -0
- package/dist-node/src/writes/applescript/hotspot.applescript +155 -0
- package/dist-node/src/writes/applescript/lifecycle.applescript +266 -0
- package/dist-node/src/writes/applescript/run-tasks.applescript +208 -0
- package/dist-node/src/writes/applescript/source.js +52 -0
- package/dist-node/src/writes/applescript/window.applescript +436 -0
- package/dist-node/src/writes/applescript/workspace-status.applescript +177 -0
- package/dist-node/src/writes/applescript/workspace-targeting.applescript +359 -0
- package/dist-node/src/writes/chats.js +160 -0
- package/dist-node/src/writes/guards.js +77 -0
- package/dist-node/src/writes/runner.js +67 -0
- package/dist-node/src/{sidecar.js → writes/sidecar.js} +1 -1
- package/dist-node/src/writes/system.js +81 -0
- package/dist-node/src/writes/targeting.js +121 -0
- package/dist-node/src/writes/types.js +1 -0
- package/dist-node/src/writes/ui-lock.js +229 -0
- package/dist-node/src/writes/workspaces.js +233 -0
- package/docs/voice-setup.md +34 -12
- package/package.json +2 -2
- package/dist/assets/index-ByTwVInL.css +0 -1
- package/dist/assets/index-LAm9X7wv.js +0 -65
- package/dist-node/src/conductor.applescript +0 -2279
- package/dist-node/src/delegations.js +0 -557
- package/dist-node/src/mcp-tools.js +0 -1319
- package/dist-node/src/orchestration-db.js +0 -2186
- package/dist-node/src/reads.js +0 -787
- package/dist-node/src/workflow-coordinator.js +0 -2119
- package/dist-node/src/writes.js +0 -1223
- /package/dist-node/src/{conductor-settings.js → agents/conductor-settings.js} +0 -0
- /package/dist-node/src/{firstprompt.js → delivery/firstprompt.js} +0 -0
- /package/dist-node/src/{sendonce.js → delivery/sendonce.js} +0 -0
- /package/dist-node/src/{preview-urls.js → dev-server/preview-urls.js} +0 -0
- /package/dist-node/src/{run-configs.js → dev-server/run-configs.js} +0 -0
- /package/dist-node/src/{attachments.js → files/attachments.js} +0 -0
- /package/dist-node/src/{icons.js → files/icons.js} +0 -0
- /package/dist-node/src/{staged-attachments.js → files/staged-attachments.js} +0 -0
- /package/dist-node/src/{fork-workspace.js → git/fork-workspace.js} +0 -0
- /package/dist-node/src/{merge.js → git/merge.js} +0 -0
- /package/dist-node/src/{pr.js → git/pr.js} +0 -0
- /package/dist-node/src/{nosleep.js → host/nosleep.js} +0 -0
- /package/dist-node/src/{relay-processes.js → host/relay-processes.js} +0 -0
- /package/dist-node/src/{ui-lease-watchdog.js → host/ui-lease-watchdog.js} +0 -0
- /package/dist-node/src/{wifi.js → host/wifi.js} +0 -0
- /package/dist-node/src/{orchestration-schema.generated.js → orchestration/persistence/schema.generated.js} +0 -0
- /package/dist-node/src/{workflow-effect-runner.js → orchestration/workflow/effect-runner.js} +0 -0
- /package/dist-node/src/{workflow-http.js → orchestration/workflow/http.js} +0 -0
- /package/dist-node/src/{workflow-machine.js → orchestration/workflow/machine.js} +0 -0
- /package/dist-node/src/{session-poller.js → reads/session-poller.js} +0 -0
- /package/dist-node/src/{context-breakdown.js → transcript/context-breakdown.js} +0 -0
- /package/dist-node/src/{chat-cursor.js → transcript/cursor.js} +0 -0
- /package/dist-node/src/{plan-usage.js → usage/plan-usage.js} +0 -0
- /package/dist-node/src/{tool-usage-service.js → usage/tool-usage-service.js} +0 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { workflowCapabilityToken } from "../../shared.js";
|
|
3
|
+
import { withUiDispatchHook, withUiPriority } from "../../writes/ui-lock.js";
|
|
4
|
+
import { hashCapabilityToken, WorkflowTransitionError } from "../persistence/db.js";
|
|
5
|
+
import { quarantineAndBlock } from "./effect-recovery.js";
|
|
6
|
+
import { WorkflowCoordinatorError } from "./errors.js";
|
|
7
|
+
import { cleanUnknown, errorCode, errorMessage, preExecutionRetryClass, sameRelay } from "./helpers.js";
|
|
8
|
+
import { isTerminalWorkflowPhase } from "./machine.js";
|
|
9
|
+
import { assertCompatible, blockRun, effectReadCall, requireEffect, requireRun } from "./state.js";
|
|
10
|
+
export async function runDurableEffect(context, options) {
|
|
11
|
+
let effect = requireEffect(context, options.run.id, options.effect.actionId);
|
|
12
|
+
if (effect.state === 'committed' ||
|
|
13
|
+
effect.state === 'failed' ||
|
|
14
|
+
effect.state === 'ambiguous' ||
|
|
15
|
+
effect.state === 'cancelled') {
|
|
16
|
+
return { effect, changed: false };
|
|
17
|
+
}
|
|
18
|
+
if (!effect.owner &&
|
|
19
|
+
effect.state === 'prepared' &&
|
|
20
|
+
(effect.kind === 'configure_root' || effect.kind === 'configure_child')) {
|
|
21
|
+
const satisfaction = await context.deps.reconcileEffect?.(effectReadCall(options.run, effect, options.job));
|
|
22
|
+
if (satisfaction?.status === 'committed') {
|
|
23
|
+
const latest = requireEffect(context, options.run.id, effect.actionId);
|
|
24
|
+
const latestRun = requireRun(context, options.run.id);
|
|
25
|
+
if (!latest.owner &&
|
|
26
|
+
latest.state === 'prepared' &&
|
|
27
|
+
latestRun.phase !== 'blocked' &&
|
|
28
|
+
!isTerminalWorkflowPhase(latestRun.phase)) {
|
|
29
|
+
effect = context.db.markWorkflowEffectSatisfiedWithoutDispatch({
|
|
30
|
+
runId: latestRun.id,
|
|
31
|
+
actionId: latest.actionId,
|
|
32
|
+
expectedCancellationGeneration: latestRun.cancellationGeneration,
|
|
33
|
+
receipt: cleanUnknown(satisfaction.receipt),
|
|
34
|
+
eventKey: `effect-satisfied:${latest.actionId}`
|
|
35
|
+
});
|
|
36
|
+
return { effect, changed: true };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (effect.owner) {
|
|
41
|
+
const reconciled = await reconcileClaimedEffect(context, options.run, effect, options.job);
|
|
42
|
+
effect = reconciled.effect;
|
|
43
|
+
if (reconciled.changed || effect.owner || effect.state !== 'prepared')
|
|
44
|
+
return reconciled;
|
|
45
|
+
}
|
|
46
|
+
const currentRun = requireRun(context, options.run.id);
|
|
47
|
+
if (currentRun.phase === 'blocked' || isTerminalWorkflowPhase(currentRun.phase))
|
|
48
|
+
return { effect, changed: false };
|
|
49
|
+
const claim = context.db.claimPreparedWorkflowEffect({
|
|
50
|
+
runId: options.run.id,
|
|
51
|
+
actionId: effect.actionId,
|
|
52
|
+
owner: context.relay,
|
|
53
|
+
expectedCancellationGeneration: currentRun.cancellationGeneration
|
|
54
|
+
});
|
|
55
|
+
if (!claim)
|
|
56
|
+
return { effect: requireEffect(context, options.run.id, effect.actionId), changed: false };
|
|
57
|
+
const capabilityToken = options.capabilityGrant
|
|
58
|
+
? workflowCapabilityToken(randomBytes(32).toString('base64url'))
|
|
59
|
+
: undefined;
|
|
60
|
+
const launchNonce = capabilityToken ? hashCapabilityToken(capabilityToken) : randomBytes(32).toString('hex');
|
|
61
|
+
const dispatchMode = context.deps.dispatchMode?.(claim.effect) ?? 'in_process';
|
|
62
|
+
const dispatch = {
|
|
63
|
+
mode: dispatchMode,
|
|
64
|
+
gatedProcessReady: async (externalProcess) => {
|
|
65
|
+
if (dispatchMode !== 'gated_child') {
|
|
66
|
+
throw new WorkflowCoordinatorError('workflow_adapter_invalid', `Workflow adapter for ${effect.actionId} registered a gated process in in-process mode.`);
|
|
67
|
+
}
|
|
68
|
+
const latestRun = requireRun(context, options.run.id);
|
|
69
|
+
if (latestRun.cancellationGeneration !== currentRun.cancellationGeneration ||
|
|
70
|
+
latestRun.phase === 'blocked' ||
|
|
71
|
+
isTerminalWorkflowPhase(latestRun.phase)) {
|
|
72
|
+
throw new WorkflowTransitionError(`Workflow ${latestRun.id} changed before gated process release`);
|
|
73
|
+
}
|
|
74
|
+
await assertCompatible(context);
|
|
75
|
+
context.db.markWorkflowEffectMayExecute({
|
|
76
|
+
runId: latestRun.id,
|
|
77
|
+
actionId: effect.actionId,
|
|
78
|
+
owner: context.relay,
|
|
79
|
+
attemptNumber: claim.attempt.attemptNumber,
|
|
80
|
+
launchNonce,
|
|
81
|
+
externalProcess
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
try {
|
|
86
|
+
return await withUiPriority('background', () => withUiDispatchHook(async () => {
|
|
87
|
+
const latestRun = requireRun(context, options.run.id);
|
|
88
|
+
if (latestRun.cancellationGeneration !== currentRun.cancellationGeneration ||
|
|
89
|
+
latestRun.phase === 'blocked' ||
|
|
90
|
+
isTerminalWorkflowPhase(latestRun.phase)) {
|
|
91
|
+
throw new WorkflowTransitionError(`Workflow ${latestRun.id} changed before UI dispatch`);
|
|
92
|
+
}
|
|
93
|
+
await context.deps.validateBeforeDispatch?.(effectReadCall(latestRun, requireEffect(context, latestRun.id, effect.actionId), options.job));
|
|
94
|
+
await assertCompatible(context);
|
|
95
|
+
context.db.markWorkflowEffectDispatched({
|
|
96
|
+
runId: latestRun.id,
|
|
97
|
+
actionId: effect.actionId,
|
|
98
|
+
owner: context.relay,
|
|
99
|
+
attemptNumber: claim.attempt.attemptNumber,
|
|
100
|
+
launchNonce,
|
|
101
|
+
mayExecute: dispatchMode === 'in_process'
|
|
102
|
+
});
|
|
103
|
+
}, async () => {
|
|
104
|
+
try {
|
|
105
|
+
const result = await options.execute(capabilityToken, dispatch);
|
|
106
|
+
effect = requireEffect(context, options.run.id, effect.actionId);
|
|
107
|
+
if (effect.state !== 'dispatched') {
|
|
108
|
+
throw new WorkflowCoordinatorError('workflow_adapter_invalid', `Workflow adapter for ${effect.actionId} returned without entering uiTurn.`);
|
|
109
|
+
}
|
|
110
|
+
if (!effect.mayExecute) {
|
|
111
|
+
throw new WorkflowCoordinatorError('workflow_adapter_invalid', `Workflow adapter for ${effect.actionId} returned before releasing its gated process.`);
|
|
112
|
+
}
|
|
113
|
+
const receipt = cleanUnknown(options.validate(result));
|
|
114
|
+
const completedRun = requireRun(context, options.run.id);
|
|
115
|
+
if (completedRun.phase === 'cancelled') {
|
|
116
|
+
effect = context.db.recordLateWorkflowEffect({
|
|
117
|
+
runId: completedRun.id,
|
|
118
|
+
actionId: effect.actionId,
|
|
119
|
+
receipt,
|
|
120
|
+
eventKey: `late-effect:${effect.actionId}:${claim.attempt.attemptNumber}`
|
|
121
|
+
});
|
|
122
|
+
return { effect, changed: true };
|
|
123
|
+
}
|
|
124
|
+
if (completedRun.phase === 'completed')
|
|
125
|
+
return { effect, changed: false };
|
|
126
|
+
effect = context.db.markWorkflowEffectCommitted({
|
|
127
|
+
runId: options.run.id,
|
|
128
|
+
actionId: effect.actionId,
|
|
129
|
+
owner: context.relay,
|
|
130
|
+
attemptNumber: claim.attempt.attemptNumber,
|
|
131
|
+
receipt
|
|
132
|
+
});
|
|
133
|
+
if (requireRun(context, options.run.id).phase === 'cancelled') {
|
|
134
|
+
effect = context.db.recordLateWorkflowEffect({
|
|
135
|
+
runId: options.run.id,
|
|
136
|
+
actionId: effect.actionId,
|
|
137
|
+
receipt,
|
|
138
|
+
eventKey: `late-effect:${effect.actionId}:${claim.attempt.attemptNumber}`
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return { effect, changed: true };
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
return failEffect(context, options.run, effect.actionId, claim.attempt.attemptNumber, error, options.job);
|
|
145
|
+
}
|
|
146
|
+
}, claim.effect.id));
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
return failEffect(context, options.run, effect.actionId, claim.attempt.attemptNumber, error, options.job);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
export async function reconcileClaimedEffect(context, run, effect, job) {
|
|
153
|
+
const positive = await context.deps.reconcileEffect?.(effectReadCall(run, effect, job));
|
|
154
|
+
if (positive?.status === 'committed') {
|
|
155
|
+
const committed = context.db.markWorkflowEffectCommitted({
|
|
156
|
+
runId: run.id,
|
|
157
|
+
actionId: effect.actionId,
|
|
158
|
+
receipt: cleanUnknown(positive.receipt),
|
|
159
|
+
eventKey: `effect-reconciled:${effect.actionId}:${effect.attemptCount}`
|
|
160
|
+
});
|
|
161
|
+
return { effect: committed, changed: true };
|
|
162
|
+
}
|
|
163
|
+
const recovery = context.db.reconcileAbandonedWorkflowEffect({
|
|
164
|
+
runId: run.id,
|
|
165
|
+
actionId: effect.actionId,
|
|
166
|
+
eventKey: `recover-effect:${effect.actionId}:${effect.attemptCount}`
|
|
167
|
+
});
|
|
168
|
+
if (recovery.status === 'safely_prepared')
|
|
169
|
+
return { effect: recovery.effect, changed: true };
|
|
170
|
+
if (recovery.status === 'ambiguous') {
|
|
171
|
+
quarantineAndBlock(context, run, recovery.effect, positive?.status === 'ambiguous' ? positive.candidates : undefined);
|
|
172
|
+
return { effect: recovery.effect, changed: true };
|
|
173
|
+
}
|
|
174
|
+
return { effect: recovery.effect, changed: false };
|
|
175
|
+
}
|
|
176
|
+
export async function failEffect(context, run, actionId, attemptNumber, error, job) {
|
|
177
|
+
let effect = requireEffect(context, run.id, actionId);
|
|
178
|
+
const currentRun = requireRun(context, run.id);
|
|
179
|
+
if (currentRun.phase === 'cancelled' || currentRun.phase === 'completed') {
|
|
180
|
+
if (effect.state === 'dispatched') {
|
|
181
|
+
if (!effect.mayExecute) {
|
|
182
|
+
effect = context.db.markWorkflowEffectFailedBeforeMayExecute({
|
|
183
|
+
runId: run.id,
|
|
184
|
+
actionId,
|
|
185
|
+
owner: context.relay,
|
|
186
|
+
attemptNumber,
|
|
187
|
+
errorCode: errorCode(error, 'workflow_effect_failed'),
|
|
188
|
+
errorMessage: errorMessage(error),
|
|
189
|
+
evidence: cleanUnknown(error)
|
|
190
|
+
});
|
|
191
|
+
return { effect, changed: true };
|
|
192
|
+
}
|
|
193
|
+
let positive;
|
|
194
|
+
try {
|
|
195
|
+
positive = await context.deps.reconcileEffect?.(effectReadCall(currentRun, effect, job));
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
// Failure to read a receipt is not negative evidence. Preserve ambiguity below.
|
|
199
|
+
}
|
|
200
|
+
if (positive?.status === 'committed') {
|
|
201
|
+
const receipt = cleanUnknown(positive.receipt);
|
|
202
|
+
effect =
|
|
203
|
+
currentRun.phase === 'cancelled'
|
|
204
|
+
? context.db.recordLateWorkflowEffect({
|
|
205
|
+
runId: run.id,
|
|
206
|
+
actionId,
|
|
207
|
+
receipt,
|
|
208
|
+
eventKey: `late-effect-error:${actionId}:${attemptNumber}`
|
|
209
|
+
})
|
|
210
|
+
: context.db.markWorkflowEffectCommitted({
|
|
211
|
+
runId: run.id,
|
|
212
|
+
actionId,
|
|
213
|
+
owner: context.relay,
|
|
214
|
+
attemptNumber,
|
|
215
|
+
receipt
|
|
216
|
+
});
|
|
217
|
+
return { effect, changed: true };
|
|
218
|
+
}
|
|
219
|
+
effect = context.db.markWorkflowEffectAmbiguous({
|
|
220
|
+
runId: run.id,
|
|
221
|
+
actionId,
|
|
222
|
+
owner: context.relay,
|
|
223
|
+
attemptNumber,
|
|
224
|
+
errorCode: errorCode(error, 'ambiguous_effect'),
|
|
225
|
+
errorMessage: errorMessage(error),
|
|
226
|
+
evidence: cleanUnknown(error)
|
|
227
|
+
});
|
|
228
|
+
context.db.activateUiQuarantine({
|
|
229
|
+
actionId: effect.actionId,
|
|
230
|
+
effectId: effect.id,
|
|
231
|
+
reason: effect.errorMessage ?? 'A terminal Workflow has an unresolved UI effect.',
|
|
232
|
+
owner: effect.owner,
|
|
233
|
+
externalProcess: effect.externalProcess
|
|
234
|
+
});
|
|
235
|
+
return { effect, changed: true };
|
|
236
|
+
}
|
|
237
|
+
return { effect, changed: false };
|
|
238
|
+
}
|
|
239
|
+
if (effect.state === 'prepared' && sameRelay(effect.owner, context.relay)) {
|
|
240
|
+
effect = context.db.markWorkflowEffectFailed({
|
|
241
|
+
runId: run.id,
|
|
242
|
+
actionId,
|
|
243
|
+
owner: context.relay,
|
|
244
|
+
attemptNumber,
|
|
245
|
+
errorCode: errorCode(error, 'workflow_effect_failed'),
|
|
246
|
+
errorMessage: errorMessage(error),
|
|
247
|
+
evidence: cleanUnknown(error)
|
|
248
|
+
});
|
|
249
|
+
blockRun(context, currentRun, {
|
|
250
|
+
actionId,
|
|
251
|
+
errorCode: effect.errorCode ?? 'workflow_effect_failed',
|
|
252
|
+
message: effect.errorMessage ?? 'Workflow UI action failed before dispatch.',
|
|
253
|
+
retryClass: preExecutionRetryClass(error)
|
|
254
|
+
});
|
|
255
|
+
return { effect, changed: true };
|
|
256
|
+
}
|
|
257
|
+
if (effect.state === 'dispatched') {
|
|
258
|
+
if (!effect.mayExecute) {
|
|
259
|
+
effect = context.db.markWorkflowEffectFailedBeforeMayExecute({
|
|
260
|
+
runId: run.id,
|
|
261
|
+
actionId,
|
|
262
|
+
owner: context.relay,
|
|
263
|
+
attemptNumber,
|
|
264
|
+
errorCode: errorCode(error, 'workflow_effect_failed'),
|
|
265
|
+
errorMessage: errorMessage(error),
|
|
266
|
+
evidence: cleanUnknown(error)
|
|
267
|
+
});
|
|
268
|
+
blockRun(context, currentRun, {
|
|
269
|
+
actionId,
|
|
270
|
+
errorCode: effect.errorCode ?? 'workflow_effect_failed',
|
|
271
|
+
message: effect.errorMessage ?? 'Workflow external command failed before its private gate opened.',
|
|
272
|
+
retryClass: preExecutionRetryClass(error)
|
|
273
|
+
});
|
|
274
|
+
return { effect, changed: true };
|
|
275
|
+
}
|
|
276
|
+
let positive;
|
|
277
|
+
try {
|
|
278
|
+
positive = await context.deps.reconcileEffect?.(effectReadCall(currentRun, effect, job));
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
// A failed receipt read cannot make an already-authorized external action safe to replay.
|
|
282
|
+
}
|
|
283
|
+
if (positive?.status === 'committed') {
|
|
284
|
+
effect = context.db.markWorkflowEffectCommitted({
|
|
285
|
+
runId: run.id,
|
|
286
|
+
actionId,
|
|
287
|
+
owner: context.relay,
|
|
288
|
+
attemptNumber,
|
|
289
|
+
receipt: cleanUnknown(positive.receipt),
|
|
290
|
+
eventKey: `effect-positive-after-error:${actionId}:${attemptNumber}`
|
|
291
|
+
});
|
|
292
|
+
return { effect, changed: true };
|
|
293
|
+
}
|
|
294
|
+
effect = context.db.markWorkflowEffectAmbiguous({
|
|
295
|
+
runId: run.id,
|
|
296
|
+
actionId,
|
|
297
|
+
owner: context.relay,
|
|
298
|
+
attemptNumber,
|
|
299
|
+
errorCode: errorCode(error, 'ambiguous_effect'),
|
|
300
|
+
errorMessage: errorMessage(error),
|
|
301
|
+
evidence: cleanUnknown(error)
|
|
302
|
+
});
|
|
303
|
+
quarantineAndBlock(context, currentRun, effect, positive?.status === 'ambiguous' ? positive.candidates : undefined);
|
|
304
|
+
return { effect, changed: true };
|
|
305
|
+
}
|
|
306
|
+
return { effect, changed: false };
|
|
307
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { scrubWorkflowSecrets } from "../../shared.js";
|
|
2
|
+
export class WorkflowCoordinatorError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
status;
|
|
5
|
+
retryable;
|
|
6
|
+
constructor(code, message, options = {}) {
|
|
7
|
+
super(scrubWorkflowSecrets(message));
|
|
8
|
+
this.name = 'WorkflowCoordinatorError';
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.status = options.status ?? 409;
|
|
11
|
+
this.retryable = options.retryable ?? false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { scrubWorkflowSecrets, WORKFLOW_PRIVATE_ENVELOPE_CLOSE, WORKFLOW_PRIVATE_ENVELOPE_OPEN } from "../../shared.js";
|
|
2
|
+
import { WorkflowTransitionError } from "../persistence/db.js";
|
|
3
|
+
import { WorkflowCoordinatorError } from "./errors.js";
|
|
4
|
+
import { isTerminalWorkflowPhase } from "./machine.js";
|
|
5
|
+
export function cleanUnknown(value, depth = 0) {
|
|
6
|
+
if (depth > 12)
|
|
7
|
+
return '[truncated]';
|
|
8
|
+
if (typeof value === 'string')
|
|
9
|
+
return scrubWorkflowSecrets(value);
|
|
10
|
+
if (Array.isArray(value))
|
|
11
|
+
return value.map(entry => cleanUnknown(entry, depth + 1));
|
|
12
|
+
if (value && typeof value === 'object') {
|
|
13
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, cleanUnknown(entry, depth + 1)]));
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export function errorMessage(error) {
|
|
18
|
+
return scrubWorkflowSecrets(error instanceof Error ? error.message : String(error)).slice(0, 500);
|
|
19
|
+
}
|
|
20
|
+
export function errorCode(error, fallback) {
|
|
21
|
+
if (error && typeof error === 'object' && 'code' in error && typeof error.code === 'string') {
|
|
22
|
+
return scrubWorkflowSecrets(error.code).slice(0, 100);
|
|
23
|
+
}
|
|
24
|
+
return fallback;
|
|
25
|
+
}
|
|
26
|
+
export function preExecutionRetryClass(error) {
|
|
27
|
+
return errorCode(error, 'workflow_effect_failed') === 'workflow_root_not_pristine' ? 'terminal' : 'deterministic';
|
|
28
|
+
}
|
|
29
|
+
export function sanitizeChildOutcome(outcome) {
|
|
30
|
+
return outcome.kind === 'success'
|
|
31
|
+
? {
|
|
32
|
+
kind: 'success',
|
|
33
|
+
baton: scrubWorkflowSecrets(outcome.baton),
|
|
34
|
+
...(outcome.evidence === undefined ? {} : { evidence: cleanUnknown(outcome.evidence) })
|
|
35
|
+
}
|
|
36
|
+
: {
|
|
37
|
+
kind: 'failure',
|
|
38
|
+
code: scrubWorkflowSecrets(outcome.code),
|
|
39
|
+
message: scrubWorkflowSecrets(outcome.message),
|
|
40
|
+
retryClass: outcome.retryClass ?? 'deterministic',
|
|
41
|
+
...(outcome.evidence === undefined ? {} : { evidence: cleanUnknown(outcome.evidence) })
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function isDeliveryReceipt(value) {
|
|
45
|
+
if (!value || typeof value !== 'object')
|
|
46
|
+
return false;
|
|
47
|
+
const receipt = value;
|
|
48
|
+
if (receipt.kind === 'outbox')
|
|
49
|
+
return typeof receipt.id === 'string' && receipt.id.length > 0;
|
|
50
|
+
return (receipt.kind === 'message' &&
|
|
51
|
+
typeof receipt.id === 'string' &&
|
|
52
|
+
typeof receipt.rowid === 'number' &&
|
|
53
|
+
Number.isSafeInteger(receipt.rowid) &&
|
|
54
|
+
(receipt.turnId === null || typeof receipt.turnId === 'string'));
|
|
55
|
+
}
|
|
56
|
+
export function messageReceipt(resolution, expectedId) {
|
|
57
|
+
if (resolution.status !== 'delivered' || resolution.receipt.id !== expectedId)
|
|
58
|
+
return null;
|
|
59
|
+
return resolution.receipt;
|
|
60
|
+
}
|
|
61
|
+
export function effectSessionId(effect) {
|
|
62
|
+
if (!effect.target || typeof effect.target !== 'object')
|
|
63
|
+
return undefined;
|
|
64
|
+
const sessionId = effect.target.sessionId;
|
|
65
|
+
return typeof sessionId === 'string' && sessionId ? sessionId : undefined;
|
|
66
|
+
}
|
|
67
|
+
export function receiptEventSuffix(receipt, fallback) {
|
|
68
|
+
return isDeliveryReceipt(receipt) ? `${receipt.kind}:${receipt.id}` : fallback;
|
|
69
|
+
}
|
|
70
|
+
/** Stable, non-secret evidence used to match an orphaned external effect. */
|
|
71
|
+
export function workflowEffectCorrelationMarker(runId, actionId) {
|
|
72
|
+
return `[conductor-remote workflow:${runId} action:${actionId}]`;
|
|
73
|
+
}
|
|
74
|
+
/** Raw Conductor sees the marker; every scrubbed transcript surface removes it. */
|
|
75
|
+
export function privateCorrelationBlock(runId, actionId) {
|
|
76
|
+
return [
|
|
77
|
+
WORKFLOW_PRIVATE_ENVELOPE_OPEN,
|
|
78
|
+
workflowEffectCorrelationMarker(runId, actionId),
|
|
79
|
+
WORKFLOW_PRIVATE_ENVELOPE_CLOSE
|
|
80
|
+
].join('\n');
|
|
81
|
+
}
|
|
82
|
+
export function sameRelay(left, right) {
|
|
83
|
+
return Boolean(left &&
|
|
84
|
+
left.instanceId === right.instanceId &&
|
|
85
|
+
left.pid === right.pid &&
|
|
86
|
+
left.processStartedAt === right.processStartedAt &&
|
|
87
|
+
left.protocolVersion === right.protocolVersion);
|
|
88
|
+
}
|
|
89
|
+
export function activeResumePhase(run) {
|
|
90
|
+
if (run.phase === 'blocked')
|
|
91
|
+
return run.blocked?.resumePhase ?? 'pending_root';
|
|
92
|
+
if (isTerminalWorkflowPhase(run.phase)) {
|
|
93
|
+
throw new WorkflowTransitionError(`Workflow ${run.id} is ${run.phase}`);
|
|
94
|
+
}
|
|
95
|
+
return run.phase;
|
|
96
|
+
}
|
|
97
|
+
export function guardJobs(jobs) {
|
|
98
|
+
return jobs.map(job => ({
|
|
99
|
+
role: job.role,
|
|
100
|
+
cycle: job.cycle,
|
|
101
|
+
status: job.state,
|
|
102
|
+
...(isDeliveryReceipt(job.batonReceipt) ? { batonReceiptKind: job.batonReceipt.kind } : {})
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
export function actionOrdinal(jobs, role, cycle) {
|
|
106
|
+
const prefix = role === 'exploration' ? 'explore' : 'implement';
|
|
107
|
+
let max = -1;
|
|
108
|
+
for (const job of jobs) {
|
|
109
|
+
if (job.role !== role || job.cycle !== cycle)
|
|
110
|
+
continue;
|
|
111
|
+
if (job.logicalKey === 'explore:0' && cycle === 0)
|
|
112
|
+
max = Math.max(max, 0);
|
|
113
|
+
const match = job.logicalKey.match(new RegExp(`^${prefix}:${cycle}:(\\d+)$`));
|
|
114
|
+
if (match)
|
|
115
|
+
max = Math.max(max, Number(match[1]));
|
|
116
|
+
}
|
|
117
|
+
return max + 1;
|
|
118
|
+
}
|
|
119
|
+
export function effectGrant(effect) {
|
|
120
|
+
if (!effect.inputs || typeof effect.inputs !== 'object')
|
|
121
|
+
return null;
|
|
122
|
+
const grant = effect.inputs.grant;
|
|
123
|
+
if (!grant ||
|
|
124
|
+
(grant.phase !== 'exploring' && grant.phase !== 'planning' && grant.phase !== 'reviewing') ||
|
|
125
|
+
!Number.isSafeInteger(grant.cycle) ||
|
|
126
|
+
!Number.isSafeInteger(grant.revision) ||
|
|
127
|
+
!Array.isArray(grant.allowedRoles) ||
|
|
128
|
+
grant.allowedRoles.some(role => role !== 'exploration' && role !== 'implementation')) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
return grant;
|
|
132
|
+
}
|
|
133
|
+
export function assertWorkspaceReceipt(value) {
|
|
134
|
+
if (!value || typeof value !== 'object' || typeof value.workspaceId !== 'string') {
|
|
135
|
+
throw new WorkflowCoordinatorError('workflow_adapter_invalid', 'Workspace creation returned no exact workspace ID.');
|
|
136
|
+
}
|
|
137
|
+
return { workspaceId: value.workspaceId };
|
|
138
|
+
}
|
|
139
|
+
export function assertSessionReceipt(value) {
|
|
140
|
+
if (!value || typeof value !== 'object' || typeof value.sessionId !== 'string') {
|
|
141
|
+
throw new WorkflowCoordinatorError('workflow_adapter_invalid', 'Child creation returned no exact session ID.');
|
|
142
|
+
}
|
|
143
|
+
return { sessionId: value.sessionId };
|
|
144
|
+
}
|
|
145
|
+
export function assertDeliveryReceipt(value) {
|
|
146
|
+
if (!isDeliveryReceipt(value)) {
|
|
147
|
+
throw new WorkflowCoordinatorError('workflow_adapter_invalid', 'Prompt delivery returned no tagged receipt.');
|
|
148
|
+
}
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
/** DB roles originate exclusively in prepareWorkflowRun, whose effort union is narrower. */
|
|
152
|
+
export function promptRole(role) {
|
|
153
|
+
return role;
|
|
154
|
+
}
|