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,94 @@
|
|
|
1
|
+
import { handleRpc } from "../../mcp/dispatcher.js";
|
|
2
|
+
import { READ_TIMEOUT_MS } from "../../mcp/protocol.js";
|
|
3
|
+
import { createTools } from "../../mcp/registry.js";
|
|
4
|
+
import { responseErrorMessage } from "../../shared.js";
|
|
5
|
+
import { withUiPriority } from "../../writes/ui-lock.js";
|
|
6
|
+
export function createMcpServices(services) {
|
|
7
|
+
const { cfg, json, authed, readBody, forTheClient } = services;
|
|
8
|
+
/**
|
|
9
|
+
* The MCP tools, bound to this relay over loopback.
|
|
10
|
+
*
|
|
11
|
+
* A self-request looks odd and is deliberate: the alternative is carving every route
|
|
12
|
+
* handler out of the router below so the tools could call them directly, which buys
|
|
13
|
+
* a sub-millisecond hop and costs the guarantee that matters — that a tool behaves
|
|
14
|
+
* identically over `POST /mcp` and over `conductor-remote mcp`'s stdio. One code
|
|
15
|
+
* path, one set of budgets, one place a route's semantics live.
|
|
16
|
+
*/
|
|
17
|
+
const mcpTools = createTools(async (route, opts = {}) => {
|
|
18
|
+
// 0.0.0.0 binds every interface, so loopback still reaches us; a pinned RELAY_HOST
|
|
19
|
+
// is the address we actually answer on.
|
|
20
|
+
const host = !cfg.host || cfg.host === '0.0.0.0' || cfg.host === '::' ? '127.0.0.1' : cfg.host;
|
|
21
|
+
const timeoutMs = opts.timeoutMs ?? READ_TIMEOUT_MS;
|
|
22
|
+
const res = await fetch(`http://${host}:${cfg.port}${route}`, {
|
|
23
|
+
method: opts.method ?? 'GET',
|
|
24
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
25
|
+
headers: {
|
|
26
|
+
authorization: `Bearer ${cfg.token}`,
|
|
27
|
+
'content-type': 'application/json',
|
|
28
|
+
'x-relay-client': 'mcp',
|
|
29
|
+
'x-client-timeout-ms': String(timeoutMs)
|
|
30
|
+
},
|
|
31
|
+
body: opts.body === undefined ? undefined : JSON.stringify(opts.body)
|
|
32
|
+
});
|
|
33
|
+
const payload = (await res.json().catch(() => ({})));
|
|
34
|
+
if (!res.ok) {
|
|
35
|
+
const busy = res.status === 503 ? ' (Conductor’s UI is busy — retry shortly)' : '';
|
|
36
|
+
throw new Error(`${responseErrorMessage(payload.error, `HTTP ${res.status}`)}${busy}`);
|
|
37
|
+
}
|
|
38
|
+
return payload;
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* MCP over HTTP.
|
|
42
|
+
*
|
|
43
|
+
* Two guards beyond the token. **Origin is rejected when present and foreign**: a real
|
|
44
|
+
* MCP client sends none, and a browser cannot omit it — so this closes the DNS-rebinding
|
|
45
|
+
* hole the spec warns about without needing to know our own hostname behind Tailscale's
|
|
46
|
+
* TLS. And **the body is capped**, because this endpoint is reachable from the internet
|
|
47
|
+
* whenever EXPOSE=public and an unbounded JSON parse is the cheapest thing to abuse.
|
|
48
|
+
*/
|
|
49
|
+
async function handleMcpHttp(req, res) {
|
|
50
|
+
if (req.method === 'GET' || req.method === 'DELETE') {
|
|
51
|
+
// No server-initiated messages and no session to end. 405 is the spec's own answer
|
|
52
|
+
// for a server that doesn't offer the stream.
|
|
53
|
+
res.writeHead(405, { allow: 'POST' }).end();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (req.method !== 'POST')
|
|
57
|
+
return void res.writeHead(405, { allow: 'POST' }).end();
|
|
58
|
+
const origin = req.headers.origin;
|
|
59
|
+
if (origin)
|
|
60
|
+
return void json(req, res, 403, { error: 'cross-origin requests are not accepted here' });
|
|
61
|
+
if (!authed(req))
|
|
62
|
+
return void json(req, res, 401, { error: 'unauthorized' });
|
|
63
|
+
let body;
|
|
64
|
+
try {
|
|
65
|
+
body = await readBody(req);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return void json(req, res, 400, { error: 'could not read request body' });
|
|
69
|
+
}
|
|
70
|
+
if (body.length > 1_000_000)
|
|
71
|
+
return void json(req, res, 413, { error: 'request too large' });
|
|
72
|
+
let parsed;
|
|
73
|
+
try {
|
|
74
|
+
parsed = JSON.parse(body || 'null');
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
res.writeHead(400, { 'content-type': 'application/json' });
|
|
78
|
+
return void res.end(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'parse error' } }));
|
|
79
|
+
}
|
|
80
|
+
// Agents yield the UI lock to whoever is holding the phone, exactly as the stdio
|
|
81
|
+
// transport does via its `x-relay-client` header.
|
|
82
|
+
const answers = await withUiPriority('background', async () => {
|
|
83
|
+
const batch = Array.isArray(parsed) ? parsed : [parsed];
|
|
84
|
+
const settled = await Promise.all(batch.map(m => handleRpc(mcpTools, m)));
|
|
85
|
+
return settled.filter(m => m !== null);
|
|
86
|
+
});
|
|
87
|
+
// A payload of nothing but notifications takes no reply at all.
|
|
88
|
+
if (!answers.length)
|
|
89
|
+
return void res.writeHead(202).end();
|
|
90
|
+
res.writeHead(200, { 'content-type': 'application/json', 'cache-control': 'no-store' });
|
|
91
|
+
res.end(JSON.stringify(forTheClient(Array.isArray(parsed) ? answers : answers[0])));
|
|
92
|
+
}
|
|
93
|
+
return { handleMcpHttp };
|
|
94
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import zlib from 'node:zlib';
|
|
3
|
+
import { scrubWorkflowSecrets, withoutClientWindowEvidence } from "../../shared.js";
|
|
4
|
+
export function createResponsesServices(services) {
|
|
5
|
+
const { cfg } = services;
|
|
6
|
+
/** Per-file ceiling for a relay exposed through Tailscale Funnel. Large media belongs in a link. */
|
|
7
|
+
const MAX_ATTACHMENT_BYTES = 25 * 1024 * 1024;
|
|
8
|
+
class PayloadTooLargeError extends Error {
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The last thing that happens to an error before it leaves the relay: the diagnostic
|
|
12
|
+
* tail `windowEvidence()` appends comes off, and the full text goes to the log instead.
|
|
13
|
+
*
|
|
14
|
+
* One place rather than the dozen routes that hand back a UI-write failure, for the
|
|
15
|
+
* same reason `redactSecrets` sits in front of every served log line: a rule applied at
|
|
16
|
+
* the boundary cannot be forgotten by the next route someone adds. What it prevents is
|
|
17
|
+
* what a tap on Fork against a locked Mac used to answer with — the sentence, then
|
|
18
|
+
* "[window server: 6; screen: locked] [processes: conductor=0] [menus: Apple, Conductor,
|
|
19
|
+
* File, ...]", in 11px red, on a phone that can do nothing with any of it. The evidence
|
|
20
|
+
* is still the fastest way to tell a wedged Conductor from a hidden window, so it lands
|
|
21
|
+
* in relay.log, which `/api/logs` serves to the same phone on request.
|
|
22
|
+
*/
|
|
23
|
+
function forTheClient(body) {
|
|
24
|
+
const scrub = (value, key) => {
|
|
25
|
+
if (typeof value === 'string') {
|
|
26
|
+
const withoutEvidence = withoutClientWindowEvidence(value, key);
|
|
27
|
+
if (withoutEvidence !== value)
|
|
28
|
+
console.warn(`[relay] ${scrubWorkflowSecrets(value)}`);
|
|
29
|
+
return scrubWorkflowSecrets(withoutEvidence);
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(value))
|
|
32
|
+
return value.map(item => scrub(item));
|
|
33
|
+
if (!value || typeof value !== 'object')
|
|
34
|
+
return value;
|
|
35
|
+
return Object.fromEntries(Object.entries(value).map(([childKey, child]) => [childKey, scrub(child, childKey)]));
|
|
36
|
+
};
|
|
37
|
+
return scrub(body);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Successful GETs are conditional + compressed to keep the phone's polling cheap.
|
|
41
|
+
* `no-cache` (not `no-store`) means the browser must revalidate on every tick —
|
|
42
|
+
* the relay still runs the handler and auth each time, so data is never stale;
|
|
43
|
+
* a matching ETag just elides the redundant body (304), and changed bodies over
|
|
44
|
+
* ~1 KB go out gzipped. Errors and non-GETs stay unconditional `no-store`.
|
|
45
|
+
*/
|
|
46
|
+
function json(req, res, status, body) {
|
|
47
|
+
const payload = Buffer.from(JSON.stringify(forTheClient(body)));
|
|
48
|
+
if (status !== 200 || req.method !== 'GET') {
|
|
49
|
+
res.writeHead(status, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
|
|
50
|
+
return void res.end(payload);
|
|
51
|
+
}
|
|
52
|
+
// Weak: the same entity may be delivered gzipped or plain.
|
|
53
|
+
const etag = `W/"${crypto.createHash('sha1').update(payload).digest('base64url')}"`;
|
|
54
|
+
const headers = {
|
|
55
|
+
'content-type': 'application/json; charset=utf-8',
|
|
56
|
+
'cache-control': 'no-cache',
|
|
57
|
+
etag,
|
|
58
|
+
vary: 'accept-encoding'
|
|
59
|
+
};
|
|
60
|
+
if (req.headers['if-none-match'] === etag)
|
|
61
|
+
return void res.writeHead(304, headers).end();
|
|
62
|
+
if (payload.length > 1024 && /\bgzip\b/.test(String(req.headers['accept-encoding'] ?? ''))) {
|
|
63
|
+
headers['content-encoding'] = 'gzip';
|
|
64
|
+
return void res.writeHead(200, headers).end(zlib.gzipSync(payload));
|
|
65
|
+
}
|
|
66
|
+
res.writeHead(200, headers).end(payload);
|
|
67
|
+
}
|
|
68
|
+
/** Constant-time string compare — the token is the sole internet-facing gate when exposed via Funnel. */
|
|
69
|
+
function tokenEq(candidate) {
|
|
70
|
+
if (candidate == null)
|
|
71
|
+
return false;
|
|
72
|
+
const a = Buffer.from(candidate);
|
|
73
|
+
const b = Buffer.from(cfg.token);
|
|
74
|
+
return a.length === b.length && crypto.timingSafeEqual(a, b);
|
|
75
|
+
}
|
|
76
|
+
function authed(req) {
|
|
77
|
+
const auth = req.headers.authorization;
|
|
78
|
+
if (auth?.startsWith('Bearer '))
|
|
79
|
+
return tokenEq(auth.slice('Bearer '.length));
|
|
80
|
+
const url = new URL(req.url ?? '/', 'http://x');
|
|
81
|
+
return tokenEq(url.searchParams.get('token'));
|
|
82
|
+
}
|
|
83
|
+
async function readBody(req) {
|
|
84
|
+
const chunks = [];
|
|
85
|
+
for await (const c of req)
|
|
86
|
+
chunks.push(c);
|
|
87
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
88
|
+
}
|
|
89
|
+
/** Read one uploaded file without allowing a token holder to fill the relay's memory. */
|
|
90
|
+
async function readAttachmentBody(req) {
|
|
91
|
+
const declared = Number(req.headers['content-length']);
|
|
92
|
+
if (Number.isFinite(declared) && declared > MAX_ATTACHMENT_BYTES) {
|
|
93
|
+
throw new PayloadTooLargeError(`attachments are limited to ${MAX_ATTACHMENT_BYTES / 1024 / 1024} MB`);
|
|
94
|
+
}
|
|
95
|
+
const chunks = [];
|
|
96
|
+
let bytes = 0;
|
|
97
|
+
for await (const chunk of req) {
|
|
98
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
99
|
+
bytes += buffer.length;
|
|
100
|
+
if (bytes > MAX_ATTACHMENT_BYTES) {
|
|
101
|
+
req.destroy();
|
|
102
|
+
throw new PayloadTooLargeError(`attachments are limited to ${MAX_ATTACHMENT_BYTES / 1024 / 1024} MB`);
|
|
103
|
+
}
|
|
104
|
+
chunks.push(buffer);
|
|
105
|
+
}
|
|
106
|
+
return Buffer.concat(chunks, bytes);
|
|
107
|
+
}
|
|
108
|
+
function attachmentHeaderName(req) {
|
|
109
|
+
const encoded = req.headers['x-attachment-name'];
|
|
110
|
+
if (typeof encoded !== 'string' || !encoded)
|
|
111
|
+
return null;
|
|
112
|
+
try {
|
|
113
|
+
return decodeURIComponent(encoded);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return { json, authed, readBody, forTheClient, attachmentHeaderName, readAttachmentBody, PayloadTooLargeError };
|
|
120
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { stateDir } from "../../config.js";
|
|
4
|
+
import { attachPrStatus } from "../../git/pr.js";
|
|
5
|
+
import { handleRpc } from "../../mcp/dispatcher.js";
|
|
6
|
+
import { readPrefs, writePrefs } from "../../prefs.js";
|
|
7
|
+
import { routes } from "../../routes.js";
|
|
8
|
+
import { VoiceBriefBoard } from "../../voice/brief.js";
|
|
9
|
+
import { VoiceBroker } from "../../voice/broker.js";
|
|
10
|
+
import { openAIOriginForSipHost, readVoiceConfig } from "../../voice/config.js";
|
|
11
|
+
import { readVoiceChatContext } from "../../voice/context.js";
|
|
12
|
+
import { createVoiceGateway } from "../../voice/gateway.js";
|
|
13
|
+
import { VoiceHistory } from "../../voice/history.js";
|
|
14
|
+
import { PreviewStore } from "../../voice/preview.js";
|
|
15
|
+
import { VoiceRecall } from "../../voice/recall.js";
|
|
16
|
+
import { createVoiceServer } from "../../voice/server.js";
|
|
17
|
+
import { createVoiceTools } from "../../voice/tools.js";
|
|
18
|
+
import { screenLocked } from "../../writes/guards.js";
|
|
19
|
+
export function createVoiceServices(services) {
|
|
20
|
+
const { cfg, reads } = services;
|
|
21
|
+
// The voice process surface shares this process (and therefore the one UI lock) but not
|
|
22
|
+
// this server's port. Only its three scoped routes are mounted through Funnel.
|
|
23
|
+
const voiceConfig = readVoiceConfig();
|
|
24
|
+
// Stable but useless outside this OpenAI abuse-control header. Hashing the relay
|
|
25
|
+
// bearer means neither that bearer nor a device identifier leaves the Mac.
|
|
26
|
+
const voiceSafetyIdentifier = crypto.createHash('sha256').update(`conductor-remote:${cfg.token}`).digest('hex');
|
|
27
|
+
const voiceBoards = new Map();
|
|
28
|
+
const voicePreviews = new PreviewStore(path.join(stateDir(), 'voice-previews.json'));
|
|
29
|
+
const voiceHistory = new VoiceHistory(path.join(stateDir(), 'voice-history.db'));
|
|
30
|
+
process.on('exit', () => voiceHistory.close());
|
|
31
|
+
const voiceBroker = voiceConfig.openaiKey
|
|
32
|
+
? new VoiceBroker({
|
|
33
|
+
apiKey: voiceConfig.openaiKey,
|
|
34
|
+
apiOrigin: openAIOriginForSipHost(voiceConfig.sipHost),
|
|
35
|
+
model: voiceConfig.model,
|
|
36
|
+
voice: voiceConfig.voice,
|
|
37
|
+
mcpUrl: voiceConfig.publicBaseUrl ? `${voiceConfig.publicBaseUrl}/mcp` : null,
|
|
38
|
+
mcpToken: voiceConfig.mcpToken,
|
|
39
|
+
stateFile: path.join(stateDir(), 'voice-calls.json'),
|
|
40
|
+
history: voiceHistory,
|
|
41
|
+
tools: callId => voiceToolsForCall(callId),
|
|
42
|
+
onClose: callId => voiceBoards.delete(callId)
|
|
43
|
+
})
|
|
44
|
+
: null;
|
|
45
|
+
function voiceBoard(callId) {
|
|
46
|
+
let board = voiceBoards.get(callId);
|
|
47
|
+
if (board)
|
|
48
|
+
return board;
|
|
49
|
+
board = new VoiceBriefBoard({
|
|
50
|
+
reads: {
|
|
51
|
+
listWorkspaces: () => {
|
|
52
|
+
const workspaces = reads.listWorkspaces();
|
|
53
|
+
attachPrStatus(workspaces);
|
|
54
|
+
return workspaces;
|
|
55
|
+
},
|
|
56
|
+
listSessionStates: () => reads.listSessionStates(),
|
|
57
|
+
lastAssistantText: sessionId => reads.lastAssistantText(sessionId),
|
|
58
|
+
lastQuestionInput: sessionId => reads.lastQuestionInput(sessionId)
|
|
59
|
+
},
|
|
60
|
+
locked: async () => (await screenLocked()) === true,
|
|
61
|
+
readPrefs,
|
|
62
|
+
writePrefs
|
|
63
|
+
});
|
|
64
|
+
voiceBoards.set(callId, board);
|
|
65
|
+
return board;
|
|
66
|
+
}
|
|
67
|
+
function voiceRelayOrigin() {
|
|
68
|
+
const host = !cfg.host || cfg.host === '0.0.0.0' || cfg.host === '::' ? '127.0.0.1' : cfg.host;
|
|
69
|
+
return `http://${host}:${cfg.port}`;
|
|
70
|
+
}
|
|
71
|
+
async function dispatchVoicePreview(preview) {
|
|
72
|
+
const timeoutMs = 75_000;
|
|
73
|
+
const res = await fetch(`${voiceRelayOrigin()}${routes.sendPrompt.path(preview.sessionId)}`, {
|
|
74
|
+
method: routes.sendPrompt.method,
|
|
75
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
76
|
+
headers: {
|
|
77
|
+
authorization: `Bearer ${cfg.token}`,
|
|
78
|
+
'content-type': 'application/json',
|
|
79
|
+
'x-relay-client': 'voice',
|
|
80
|
+
'x-client-timeout-ms': String(timeoutMs)
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
workspaceId: preview.workspaceId,
|
|
84
|
+
text: preview.text,
|
|
85
|
+
clientId: preview.token
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
const payload = (await res.json().catch(() => ({})));
|
|
89
|
+
return {
|
|
90
|
+
ok: payload.ok === true,
|
|
91
|
+
parked: payload.parked === true,
|
|
92
|
+
error: payload.error ?? (!res.ok ? `HTTP ${res.status}` : undefined)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async function createVoiceWorkspace(preview) {
|
|
96
|
+
// Creation runs behind the shared Conductor UI lease. The call already returned
|
|
97
|
+
// "queued", so keep enough room for one in-flight interactive action to finish
|
|
98
|
+
// before the deep link and its workspace-row receipt run.
|
|
99
|
+
const timeoutMs = 75_000;
|
|
100
|
+
const res = await fetch(`${voiceRelayOrigin()}${routes.createWorkspace.path()}`, {
|
|
101
|
+
method: routes.createWorkspace.method,
|
|
102
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
103
|
+
headers: {
|
|
104
|
+
authorization: `Bearer ${cfg.token}`,
|
|
105
|
+
'content-type': 'application/json',
|
|
106
|
+
'x-relay-client': 'voice',
|
|
107
|
+
'x-client-timeout-ms': String(timeoutMs)
|
|
108
|
+
},
|
|
109
|
+
body: JSON.stringify({ repo: preview.repo, prompt: preview.prompt, sendImmediately: true })
|
|
110
|
+
});
|
|
111
|
+
const payload = (await res.json().catch(() => ({})));
|
|
112
|
+
return {
|
|
113
|
+
ok: res.ok && payload.ok === true,
|
|
114
|
+
workspaceId: payload.workspaceId,
|
|
115
|
+
warning: payload.warning,
|
|
116
|
+
error: payload.error ?? (!res.ok ? `HTTP ${res.status}` : undefined)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function voiceToolsForCall(callId) {
|
|
120
|
+
return createVoiceTools({
|
|
121
|
+
callId,
|
|
122
|
+
board: voiceBoard(callId),
|
|
123
|
+
recall: new VoiceRecall({ history: voiceHistory, callId }),
|
|
124
|
+
previews: voicePreviews,
|
|
125
|
+
findSession: sessionId => reads.listSessionStates().find(state => state.sessionId === sessionId) ?? null,
|
|
126
|
+
listRepos: () => reads.listRepos().map(repo => ({ name: repo.name, defaultBranch: repo.default_branch })),
|
|
127
|
+
createWorkspace: createVoiceWorkspace,
|
|
128
|
+
readChatContext: target => readVoiceChatContext(reads, target),
|
|
129
|
+
dispatch: dispatchVoicePreview,
|
|
130
|
+
announce: spoken => {
|
|
131
|
+
if (!voiceBroker?.inject(callId, spoken))
|
|
132
|
+
console.warn(`[voice] ${callId} could not receive a delivery nudge`);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const voiceGateway = createVoiceGateway({
|
|
137
|
+
config: () => voiceConfig,
|
|
138
|
+
broker: () => voiceBroker,
|
|
139
|
+
rpc: (callId, request) => handleRpc(voiceToolsForCall(callId), request)
|
|
140
|
+
});
|
|
141
|
+
const voiceServer = createVoiceServer({
|
|
142
|
+
routes: voiceGateway,
|
|
143
|
+
mcpToken: () => voiceConfig.mcpToken,
|
|
144
|
+
log: line => console.warn(line)
|
|
145
|
+
});
|
|
146
|
+
return { voiceHistory, voiceConfig, voiceBroker, voiceSafetyIdentifier, voiceServer };
|
|
147
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { ATTACHMENT_DIR, attachmentName, attachmentToken } from "../../files/attachments.js";
|
|
5
|
+
import { WorkflowCoordinatorError } from "../../orchestration/workflow/errors.js";
|
|
6
|
+
import { modelLabel, timestampMs, workspaceTitle } from "../../shared.js";
|
|
7
|
+
import { retryWontHelp } from "../../writes/guards.js";
|
|
8
|
+
import { uiTurn, withGatedUiCommand } from "../../writes/ui-lock.js";
|
|
9
|
+
export function createWorkflowProbesServices(services) {
|
|
10
|
+
const { reads, actuator, firstPrompts, parkedPrompts, deliverPrompt, SEND_BUDGET_MS, locateChat, confirmDelivery, CONFIRM_WINDOW_MS } = services;
|
|
11
|
+
function workflowDeliveryCursor(sessionId) {
|
|
12
|
+
const cursor = reads.deliveryCursor(sessionId);
|
|
13
|
+
return { rowid: cursor.rowid, outboxIds: [...cursor.outboxIds].sort() };
|
|
14
|
+
}
|
|
15
|
+
function readsDeliveryCursor(value) {
|
|
16
|
+
if (!value || typeof value !== 'object')
|
|
17
|
+
return null;
|
|
18
|
+
const cursor = value;
|
|
19
|
+
if (!Number.isSafeInteger(cursor.rowid) || !Array.isArray(cursor.outboxIds))
|
|
20
|
+
return null;
|
|
21
|
+
if (cursor.outboxIds.some(id => typeof id !== 'string'))
|
|
22
|
+
return null;
|
|
23
|
+
return { rowid: cursor.rowid, outboxIds: new Set(cursor.outboxIds) };
|
|
24
|
+
}
|
|
25
|
+
function workspaceBaseline(value) {
|
|
26
|
+
if (!value || typeof value !== 'object')
|
|
27
|
+
return null;
|
|
28
|
+
const baseline = value;
|
|
29
|
+
return baseline.kind === 'workspace_ids' &&
|
|
30
|
+
typeof baseline.repo === 'string' &&
|
|
31
|
+
Array.isArray(baseline.workspaceIds) &&
|
|
32
|
+
baseline.workspaceIds.every(id => typeof id === 'string')
|
|
33
|
+
? baseline
|
|
34
|
+
: null;
|
|
35
|
+
}
|
|
36
|
+
function sessionBaseline(value) {
|
|
37
|
+
if (!value || typeof value !== 'object')
|
|
38
|
+
return null;
|
|
39
|
+
const baseline = value;
|
|
40
|
+
return baseline.kind === 'session_ids' &&
|
|
41
|
+
typeof baseline.workspaceId === 'string' &&
|
|
42
|
+
Array.isArray(baseline.sessionIds) &&
|
|
43
|
+
baseline.sessionIds.every(id => typeof id === 'string')
|
|
44
|
+
? baseline
|
|
45
|
+
: null;
|
|
46
|
+
}
|
|
47
|
+
function workflowRootInspection(ws, session) {
|
|
48
|
+
const cursor = workflowDeliveryCursor(session.id);
|
|
49
|
+
const userRows = reads.getMessages(session.id).entries.filter(entry => entry.role === 'user');
|
|
50
|
+
const firstPrompt = firstPrompts.list().some(entry => entry.workspaceId === ws.id);
|
|
51
|
+
const parked = parkedPrompts.list().some(entry => entry.sessionId === session.id);
|
|
52
|
+
const reasons = [
|
|
53
|
+
session.status !== 'idle' ? `the chat status is ${session.status ?? 'unknown'}, not idle` : '',
|
|
54
|
+
session.background_tasks.length ? 'the chat is waiting on a background task' : '',
|
|
55
|
+
session.last_user_message_at ? 'the chat already has a user message timestamp' : '',
|
|
56
|
+
userRows.length ? 'the chat already has a user message' : '',
|
|
57
|
+
cursor.outboxIds.length ? 'the chat already has a queued prompt' : '',
|
|
58
|
+
firstPrompt ? 'the workspace already has a pending first prompt' : '',
|
|
59
|
+
parked ? 'the chat already has a parked prompt' : ''
|
|
60
|
+
].filter(Boolean);
|
|
61
|
+
return {
|
|
62
|
+
workspaceId: ws.id,
|
|
63
|
+
rootSessionId: session.id,
|
|
64
|
+
pristine: reasons.length === 0,
|
|
65
|
+
pristineEvidence: {
|
|
66
|
+
status: session.status,
|
|
67
|
+
backgroundTasks: session.background_tasks.length,
|
|
68
|
+
lastUserMessageAt: session.last_user_message_at,
|
|
69
|
+
userRows: userRows.length,
|
|
70
|
+
outboxRows: cursor.outboxIds.length,
|
|
71
|
+
firstPrompt,
|
|
72
|
+
parked
|
|
73
|
+
},
|
|
74
|
+
deliveryCursor: cursor,
|
|
75
|
+
...(reasons.length ? { reason: `Workflow requires a pristine root: ${reasons.join('; ')}.` } : {})
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function assertWorkflowRootStillPristine(run, expectedSessionId) {
|
|
79
|
+
const ws = run.workspaceId ? reads.getWorkspace(run.workspaceId) : null;
|
|
80
|
+
const session = reads.getSession(expectedSessionId);
|
|
81
|
+
if (!ws ||
|
|
82
|
+
!run.rootSessionId ||
|
|
83
|
+
run.rootSessionId !== expectedSessionId ||
|
|
84
|
+
!session ||
|
|
85
|
+
reads.sessionWorkspaceId(expectedSessionId) !== ws.id) {
|
|
86
|
+
throw new WorkflowCoordinatorError('workflow_root_not_pristine', 'The exact Workflow root binding changed before its first prompt could be dispatched.');
|
|
87
|
+
}
|
|
88
|
+
const inspection = workflowRootInspection(ws, session);
|
|
89
|
+
if (!inspection.pristine) {
|
|
90
|
+
throw new WorkflowCoordinatorError('workflow_root_not_pristine', inspection.reason ?? 'Workflow requires a pristine root chat.');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function sessionMatchesWorkflowRole(session, role) {
|
|
94
|
+
const selected = modelLabel(session.model, [role.model]).toLowerCase();
|
|
95
|
+
const wanted = role.model.toLowerCase();
|
|
96
|
+
return (session.agent_type === role.agentType &&
|
|
97
|
+
(selected === wanted || selected.startsWith(wanted)) &&
|
|
98
|
+
(role.effort === undefined || session.claude_effort_level === role.effort) &&
|
|
99
|
+
(role.fast === undefined || Boolean(session.fast_mode) === role.fast));
|
|
100
|
+
}
|
|
101
|
+
function stableWorkflowAttachment(worktree, jobId, name, body) {
|
|
102
|
+
// Conductor requires six alphanumerics. Preserve all six characters' entropy
|
|
103
|
+
// instead of truncating a hex digest to only 24 bits for a long-lived stable path.
|
|
104
|
+
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
105
|
+
const digest = crypto.createHash('sha256').update(`workflow-handoff:${jobId}`).digest();
|
|
106
|
+
const id = Array.from(digest.subarray(0, 6), byte => alphabet[byte % alphabet.length]).join('');
|
|
107
|
+
const safeName = attachmentName(name);
|
|
108
|
+
const directory = path.join(worktree, ATTACHMENT_DIR, id);
|
|
109
|
+
const destination = path.join(directory, safeName);
|
|
110
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
111
|
+
try {
|
|
112
|
+
fs.writeFileSync(destination, body, { flag: 'wx' });
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error.code !== 'EEXIST')
|
|
116
|
+
throw error;
|
|
117
|
+
if (fs.readFileSync(destination, 'utf8') !== body) {
|
|
118
|
+
throw new Error(`the stable Workflow handoff path ${path.join(ATTACHMENT_DIR, id, safeName)} is occupied`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return attachmentToken(safeName, path.join(ATTACHMENT_DIR, id, safeName));
|
|
122
|
+
}
|
|
123
|
+
function workflowWorkspaceCandidate(ws) {
|
|
124
|
+
return {
|
|
125
|
+
id: ws.id,
|
|
126
|
+
title: workspaceTitle(ws),
|
|
127
|
+
repo: ws.repo_name ?? '',
|
|
128
|
+
createdAt: timestampMs(ws.created_at),
|
|
129
|
+
kind: 'workspace'
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function workflowSessionCandidate(ws, session) {
|
|
133
|
+
return {
|
|
134
|
+
id: session.id,
|
|
135
|
+
title: session.title?.trim() || '(untitled chat)',
|
|
136
|
+
repo: ws.repo_name ?? '',
|
|
137
|
+
createdAt: timestampMs(session.created_at),
|
|
138
|
+
kind: 'session'
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function workflowSessionId(effect) {
|
|
142
|
+
if (!effect.target || typeof effect.target !== 'object')
|
|
143
|
+
return null;
|
|
144
|
+
const id = effect.target.sessionId;
|
|
145
|
+
return typeof id === 'string' ? id : null;
|
|
146
|
+
}
|
|
147
|
+
function workflowEffectPrompt(effect) {
|
|
148
|
+
if (!effect.inputs || typeof effect.inputs !== 'object')
|
|
149
|
+
return null;
|
|
150
|
+
const prompt = effect.inputs.prompt;
|
|
151
|
+
return typeof prompt === 'string' ? prompt : null;
|
|
152
|
+
}
|
|
153
|
+
function workflowEffectMarker(effect) {
|
|
154
|
+
if (!effect.inputs || typeof effect.inputs !== 'object')
|
|
155
|
+
return null;
|
|
156
|
+
const marker = effect.inputs.correlationMarker;
|
|
157
|
+
return typeof marker === 'string' ? marker : null;
|
|
158
|
+
}
|
|
159
|
+
function withWorkflowEffectGate(call, operation) {
|
|
160
|
+
return call.dispatch.mode === 'gated_child'
|
|
161
|
+
? withGatedUiCommand(call.dispatch.gatedProcessReady, () => uiTurn(operation))
|
|
162
|
+
: uiTurn(operation);
|
|
163
|
+
}
|
|
164
|
+
async function sendWorkflowPrompt(call, queue) {
|
|
165
|
+
const ws = call.run.workspaceId ? reads.getWorkspace(call.run.workspaceId) : null;
|
|
166
|
+
if (!ws || reads.sessionWorkspaceId(call.sessionId) !== ws.id) {
|
|
167
|
+
throw new WorkflowCoordinatorError('workflow_not_found', 'The Workflow destination chat is unavailable.', {
|
|
168
|
+
status: 404
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
const before = readsDeliveryCursor(call.effect.cursor) ?? reads.deliveryCursor(call.sessionId);
|
|
172
|
+
const result = await withWorkflowEffectGate(call, async () => {
|
|
173
|
+
if (actuator.name !== 'sidecar')
|
|
174
|
+
return deliverPrompt(ws, call.sessionId, call.text, SEND_BUDGET_MS, queue);
|
|
175
|
+
const located = locateChat(ws, call.sessionId);
|
|
176
|
+
if ('error' in located)
|
|
177
|
+
return { ok: false, strategy: actuator.name, attempts: 0, error: located.error };
|
|
178
|
+
const sent = await actuator.send({ workspace: ws, sessionId: call.sessionId, tab: located.tab }, call.text, {
|
|
179
|
+
queue
|
|
180
|
+
});
|
|
181
|
+
if (!sent.ok)
|
|
182
|
+
return { ...sent, attempts: 1 };
|
|
183
|
+
const landed = await confirmDelivery(call.sessionId, call.text, before, Date.now() + CONFIRM_WINDOW_MS);
|
|
184
|
+
return landed
|
|
185
|
+
? { ...sent, attempts: 1 }
|
|
186
|
+
: {
|
|
187
|
+
ok: false,
|
|
188
|
+
strategy: sent.strategy,
|
|
189
|
+
attempts: 1,
|
|
190
|
+
error: 'Conductor did not record the sidecar Workflow prompt; automatic replay is disabled.'
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
const receipt = reads.deliveryReceiptSince(call.sessionId, call.text, before);
|
|
194
|
+
if (receipt)
|
|
195
|
+
return receipt;
|
|
196
|
+
throw new WorkflowCoordinatorError('workflow_effect_failed', result.error ?? 'Conductor did not record an accepted Workflow prompt.', { retryable: !retryWontHelp(result.error) });
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
workflowRootInspection,
|
|
200
|
+
withWorkflowEffectGate,
|
|
201
|
+
sessionMatchesWorkflowRole,
|
|
202
|
+
workflowDeliveryCursor,
|
|
203
|
+
stableWorkflowAttachment,
|
|
204
|
+
sendWorkflowPrompt,
|
|
205
|
+
workflowSessionId,
|
|
206
|
+
assertWorkflowRootStillPristine,
|
|
207
|
+
workspaceBaseline,
|
|
208
|
+
workflowWorkspaceCandidate,
|
|
209
|
+
sessionBaseline,
|
|
210
|
+
workflowSessionCandidate,
|
|
211
|
+
workflowEffectPrompt,
|
|
212
|
+
readsDeliveryCursor,
|
|
213
|
+
workflowEffectMarker
|
|
214
|
+
};
|
|
215
|
+
}
|