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,248 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { stagedAttachments } from "../../files/staged-attachments.js";
|
|
3
|
+
import { WorkflowCoordinatorError } from "../../orchestration/workflow/errors.js";
|
|
4
|
+
import { parseConfirmUiStableRequest, parseStartWorkflowRequest, parseWorkflowAdoptRequest, parseWorkflowCompleteRequest, parseWorkflowDelegateRequest, parseWorkflowReplayRequest, parseWorkflowRetryRequest, WorkflowRequestError, workflowClientIsMcp } from "../../orchestration/workflow/http.js";
|
|
5
|
+
import { isRoute, routeParam, routes } from "../../routes.js";
|
|
6
|
+
import { NOT_HANDLED } from "../router-types.js";
|
|
7
|
+
export function createWorkflowsRoutes(services) {
|
|
8
|
+
const { orchestration, orchestrationUnavailableReason, workflowRequestBody, json, workflowCoordinator, stagedAttachmentIdsInObjective, STAGED_ATTACHMENTS_DIR, roleStore, modelCache, requirePhoneWorkflowCoordinator, WORKFLOW_RECOVERY_PHONE_ONLY, reads, delegationStore, projectDelegation, projectWorkflowDelegation } = services;
|
|
9
|
+
return async (req, res, url) => {
|
|
10
|
+
const { pathname } = url;
|
|
11
|
+
// This is deliberately independent of a Workflow run: cancellation cannot
|
|
12
|
+
// make an ambiguous shared-window effect safe. Only a phone acknowledgement
|
|
13
|
+
// after inspecting Conductor clears the relay-wide hold.
|
|
14
|
+
if (isRoute(routes.confirmUiStable, req.method, pathname)) {
|
|
15
|
+
if (workflowClientIsMcp(req.headers)) {
|
|
16
|
+
throw new WorkflowRequestError('Only the phone UI can confirm that Conductor is stable.', 403);
|
|
17
|
+
}
|
|
18
|
+
if (!orchestration.writable) {
|
|
19
|
+
throw new WorkflowCoordinatorError('workflow_incompatible_relay', `UI stability confirmation is disabled because ${orchestrationUnavailableReason()}.`, { status: 409 });
|
|
20
|
+
}
|
|
21
|
+
const request = parseConfirmUiStableRequest(await workflowRequestBody(req));
|
|
22
|
+
const confirmed = orchestration.idempotentMutation('confirm_ui_stable', request.clientId, {
|
|
23
|
+
confirmStable: true,
|
|
24
|
+
createdAt: request.createdAt,
|
|
25
|
+
...(request.actionId ? { actionId: request.actionId } : {}),
|
|
26
|
+
...(request.effectId ? { effectId: request.effectId } : {})
|
|
27
|
+
}, () => {
|
|
28
|
+
const current = orchestration.getUiQuarantine();
|
|
29
|
+
if (current.active &&
|
|
30
|
+
(current.createdAt !== request.createdAt ||
|
|
31
|
+
current.actionId !== request.actionId ||
|
|
32
|
+
current.effectId !== request.effectId)) {
|
|
33
|
+
throw new WorkflowCoordinatorError('workflow_recovery_invalid', 'The Conductor UI safety hold changed; inspect the current hold before confirming it.', { status: 409 });
|
|
34
|
+
}
|
|
35
|
+
orchestration.clearUiQuarantine(`phone:${request.clientId}`);
|
|
36
|
+
return { ok: true };
|
|
37
|
+
});
|
|
38
|
+
return json(req, res, 200, confirmed.result);
|
|
39
|
+
}
|
|
40
|
+
// POST /api/workflows — the only operation that authorizes a managed
|
|
41
|
+
// Workflow. Acceptance is durable and intentionally precedes every UI effect.
|
|
42
|
+
if (isRoute(routes.workflows, req.method, pathname)) {
|
|
43
|
+
if (workflowClientIsMcp(req.headers)) {
|
|
44
|
+
throw new WorkflowRequestError('MCP cannot start a Workflow; start it from the Conductor Remote UI.', 403);
|
|
45
|
+
}
|
|
46
|
+
if (!workflowCoordinator) {
|
|
47
|
+
throw new WorkflowCoordinatorError('workflow_incompatible_relay', `Workflow is disabled because ${orchestrationUnavailableReason()}.`, { status: 409 });
|
|
48
|
+
}
|
|
49
|
+
const request = parseStartWorkflowRequest(await workflowRequestBody(req));
|
|
50
|
+
const replay = orchestration.getIdempotentMutation('start_workflow', request.clientId, {
|
|
51
|
+
objective: request.objective,
|
|
52
|
+
target: request.target
|
|
53
|
+
});
|
|
54
|
+
if (!replay && request.target.kind === 'new_workspace') {
|
|
55
|
+
const stageIds = stagedAttachmentIdsInObjective(request.objective);
|
|
56
|
+
if (stageIds.length && !stagedAttachments(STAGED_ATTACHMENTS_DIR, stageIds)) {
|
|
57
|
+
throw new WorkflowCoordinatorError('invalid_request', 'One or more Workflow attachments are no longer staged; add them again.', { status: 409 });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const accepted = await workflowCoordinator.start({
|
|
61
|
+
clientId: request.clientId,
|
|
62
|
+
objective: request.objective,
|
|
63
|
+
target: request.target,
|
|
64
|
+
roles: roleStore.read(),
|
|
65
|
+
modelGroups: modelCache.list()
|
|
66
|
+
});
|
|
67
|
+
queueMicrotask(() => {
|
|
68
|
+
void workflowCoordinator.wake(accepted.workflow.id).catch(error => {
|
|
69
|
+
console.error(`[workflow ${accepted.workflow.id}] initial wake failed:`, error);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
return json(req, res, 202, { workflow: accepted.workflow });
|
|
73
|
+
}
|
|
74
|
+
// POST /api/workflows/:id/delegations — managed delegation. The
|
|
75
|
+
// capability, exact root, frozen role, and phase barrier are checked together.
|
|
76
|
+
const workflowDelegation = routeParam(routes.workflowDelegation, req.method, pathname);
|
|
77
|
+
if (workflowDelegation) {
|
|
78
|
+
if (!workflowCoordinator) {
|
|
79
|
+
throw new WorkflowCoordinatorError('workflow_incompatible_relay', 'Workflow is unavailable.', {
|
|
80
|
+
status: 409
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const request = parseWorkflowDelegateRequest(await workflowRequestBody(req), workflowDelegation);
|
|
84
|
+
// The capability rotates after every accepted choice. Its hash therefore
|
|
85
|
+
// doubles as a stable retry identity without adding a field to the exact tool schema.
|
|
86
|
+
const clientId = crypto
|
|
87
|
+
.createHash('sha256')
|
|
88
|
+
.update(JSON.stringify([
|
|
89
|
+
request.workflow_id,
|
|
90
|
+
request.phase_capability,
|
|
91
|
+
request.session_id,
|
|
92
|
+
request.role,
|
|
93
|
+
request.prompt
|
|
94
|
+
]))
|
|
95
|
+
.digest('hex');
|
|
96
|
+
const accepted = await workflowCoordinator.delegate({
|
|
97
|
+
clientId,
|
|
98
|
+
workflowId: request.workflow_id,
|
|
99
|
+
sessionId: request.session_id,
|
|
100
|
+
phaseCapability: request.phase_capability,
|
|
101
|
+
role: request.role,
|
|
102
|
+
task: request.prompt,
|
|
103
|
+
...(request.role === 'implementation' ? { planningInterpretation: request.prompt } : {})
|
|
104
|
+
});
|
|
105
|
+
queueMicrotask(() => {
|
|
106
|
+
void workflowCoordinator.wake(accepted.workflow.id).catch(error => {
|
|
107
|
+
console.error(`[workflow ${accepted.workflow.id}] delegated wake failed:`, error);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
return json(req, res, 202, {
|
|
111
|
+
ok: true,
|
|
112
|
+
workflowId: accepted.workflow.id,
|
|
113
|
+
delegationId: accepted.job.id,
|
|
114
|
+
role: accepted.job.role,
|
|
115
|
+
model: accepted.job.resolvedRole.model
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
const retryWorkflow = routeParam(routes.workflowRetry, req.method, pathname);
|
|
119
|
+
if (retryWorkflow) {
|
|
120
|
+
const coordinator = requirePhoneWorkflowCoordinator(req, WORKFLOW_RECOVERY_PHONE_ONLY);
|
|
121
|
+
const request = parseWorkflowRetryRequest(await workflowRequestBody(req));
|
|
122
|
+
const result = await coordinator.retry({
|
|
123
|
+
clientId: request.clientId,
|
|
124
|
+
workflowId: retryWorkflow
|
|
125
|
+
});
|
|
126
|
+
queueMicrotask(() => void coordinator.wake(result.workflow.id).catch(console.error));
|
|
127
|
+
return json(req, res, 200, { workflow: result.workflow });
|
|
128
|
+
}
|
|
129
|
+
const adoptWorkflow = routeParam(routes.workflowAdopt, req.method, pathname);
|
|
130
|
+
if (adoptWorkflow) {
|
|
131
|
+
const coordinator = requirePhoneWorkflowCoordinator(req, WORKFLOW_RECOVERY_PHONE_ONLY);
|
|
132
|
+
const request = parseWorkflowAdoptRequest(await workflowRequestBody(req));
|
|
133
|
+
const result = await coordinator.adopt({
|
|
134
|
+
clientId: request.clientId,
|
|
135
|
+
workflowId: adoptWorkflow,
|
|
136
|
+
actionId: request.actionId,
|
|
137
|
+
candidateId: request.workspaceId ?? request.sessionId
|
|
138
|
+
});
|
|
139
|
+
queueMicrotask(() => void coordinator.wake(result.workflow.id).catch(console.error));
|
|
140
|
+
return json(req, res, 200, { workflow: result.workflow });
|
|
141
|
+
}
|
|
142
|
+
const replayWorkflow = routeParam(routes.workflowReplay, req.method, pathname);
|
|
143
|
+
if (replayWorkflow) {
|
|
144
|
+
const coordinator = requirePhoneWorkflowCoordinator(req, WORKFLOW_RECOVERY_PHONE_ONLY);
|
|
145
|
+
const request = parseWorkflowReplayRequest(await workflowRequestBody(req));
|
|
146
|
+
const result = await coordinator.replay({
|
|
147
|
+
clientId: request.clientId,
|
|
148
|
+
workflowId: replayWorkflow,
|
|
149
|
+
actionId: request.actionId,
|
|
150
|
+
confirmDuplicateRisk: request.confirmDuplicateRisk
|
|
151
|
+
});
|
|
152
|
+
queueMicrotask(() => void coordinator.wake(result.workflow.id).catch(console.error));
|
|
153
|
+
return json(req, res, 200, { workflow: result.workflow });
|
|
154
|
+
}
|
|
155
|
+
const completeWorkflow = routeParam(routes.workflowComplete, req.method, pathname);
|
|
156
|
+
if (completeWorkflow) {
|
|
157
|
+
const coordinator = requirePhoneWorkflowCoordinator(req, 'Only the phone UI can mark a Workflow complete.');
|
|
158
|
+
const request = parseWorkflowCompleteRequest(await workflowRequestBody(req));
|
|
159
|
+
const result = await coordinator.complete({
|
|
160
|
+
clientId: request.clientId,
|
|
161
|
+
workflowId: completeWorkflow
|
|
162
|
+
});
|
|
163
|
+
return json(req, res, 200, { workflow: result.workflow });
|
|
164
|
+
}
|
|
165
|
+
const cancelWorkflow = routeParam(routes.workflow, req.method, pathname);
|
|
166
|
+
if (cancelWorkflow) {
|
|
167
|
+
const coordinator = requirePhoneWorkflowCoordinator(req, 'Only the phone UI can cancel a Workflow.');
|
|
168
|
+
const clientId = url.searchParams.get('clientId');
|
|
169
|
+
if (!clientId?.trim())
|
|
170
|
+
throw new WorkflowRequestError('clientId is required.');
|
|
171
|
+
const result = await coordinator.cancel({ clientId: clientId.trim(), workflowId: cancelWorkflow });
|
|
172
|
+
return json(req, res, 200, { workflow: result.workflow });
|
|
173
|
+
}
|
|
174
|
+
if (isRoute(routes.delegations, req.method, pathname)) {
|
|
175
|
+
const workspaceId = url.searchParams.get('workspaceId');
|
|
176
|
+
const workspaces = reads.listWorkspaces().filter(ws => !workspaceId || ws.id === workspaceId);
|
|
177
|
+
if (workspaceId && !workspaces.length)
|
|
178
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
179
|
+
const legacy = workspaces.flatMap(ws => {
|
|
180
|
+
const store = delegationStore(ws);
|
|
181
|
+
return store
|
|
182
|
+
? store
|
|
183
|
+
.list()
|
|
184
|
+
.jobs.filter(job => job.status !== 'returned')
|
|
185
|
+
.map(projectDelegation)
|
|
186
|
+
: [];
|
|
187
|
+
});
|
|
188
|
+
const allowedWorkspaces = new Set(workspaces.map(workspace => workspace.id));
|
|
189
|
+
const workflows = orchestration.writable
|
|
190
|
+
? orchestration.listWorkflowProjections().flatMap(workflow => {
|
|
191
|
+
if (!workflow.workspaceId || !allowedWorkspaces.has(workflow.workspaceId))
|
|
192
|
+
return [];
|
|
193
|
+
return orchestration
|
|
194
|
+
.listWorkflowJobs(workflow.id)
|
|
195
|
+
.filter(job => job.state !== 'returned')
|
|
196
|
+
.flatMap(job => projectWorkflowDelegation(workflow, job) ?? []);
|
|
197
|
+
})
|
|
198
|
+
: [];
|
|
199
|
+
return json(req, res, 200, { delegations: [...legacy, ...workflows] });
|
|
200
|
+
}
|
|
201
|
+
const dismissDelegation = routeParam(routes.dismissDelegation, req.method, pathname);
|
|
202
|
+
if (dismissDelegation) {
|
|
203
|
+
for (const ws of reads.listWorkspaces()) {
|
|
204
|
+
const store = delegationStore(ws);
|
|
205
|
+
if (!store)
|
|
206
|
+
continue;
|
|
207
|
+
let job;
|
|
208
|
+
try {
|
|
209
|
+
job = store.get(dismissDelegation);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
const error = {
|
|
213
|
+
code: 'state_invalid',
|
|
214
|
+
message: `Cannot dismiss unreadable delegation: ${err instanceof Error ? err.message : err}`,
|
|
215
|
+
retryable: false
|
|
216
|
+
};
|
|
217
|
+
return json(req, res, 409, {
|
|
218
|
+
ok: false,
|
|
219
|
+
error
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (!job)
|
|
223
|
+
continue;
|
|
224
|
+
if (job.status !== 'failed') {
|
|
225
|
+
return json(req, res, 409, {
|
|
226
|
+
ok: false,
|
|
227
|
+
error: {
|
|
228
|
+
code: 'invalid_request',
|
|
229
|
+
message: 'Only a failed delegation can be dismissed.',
|
|
230
|
+
retryable: false
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
store.remove(job.id);
|
|
235
|
+
return json(req, res, 200, { ok: true, delegationId: job.id });
|
|
236
|
+
}
|
|
237
|
+
return json(req, res, 404, {
|
|
238
|
+
ok: false,
|
|
239
|
+
error: {
|
|
240
|
+
code: 'delegation_not_found',
|
|
241
|
+
message: 'Delegation not found.',
|
|
242
|
+
retryable: false
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return NOT_HANDLED;
|
|
247
|
+
};
|
|
248
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { listSourceFiles, workspaceDiff, workspaceFileDiff } from "../../git/diff.js";
|
|
2
|
+
import { mergePr } from "../../git/merge.js";
|
|
3
|
+
import { routeParam, routes } from "../../routes.js";
|
|
4
|
+
import { archiveWorkspace, continueWorkspace, setWorkspaceStatus, WORKSPACE_STATUS_LABELS } from "../../writes/workspaces.js";
|
|
5
|
+
import { NOT_HANDLED } from "../router-types.js";
|
|
6
|
+
export function createWorkspacesRoutes(services) {
|
|
7
|
+
const { reads, json, delegationStore, attachWorkflowState, openChat, readBody, locateChat, sleep, devServers } = services;
|
|
8
|
+
return async (req, res, url) => {
|
|
9
|
+
const { pathname } = url;
|
|
10
|
+
// GET /api/workspaces/:id — one workspace by id, archived included. `/api/state` lists
|
|
11
|
+
// only the live ones, so this is what lets the phone open a chat search found in work
|
|
12
|
+
// that has been put away: the worktree is gone, the transcript is not.
|
|
13
|
+
const workspaceById = routeParam(routes.workspace, req.method, pathname);
|
|
14
|
+
if (workspaceById) {
|
|
15
|
+
const found = reads.getAnyWorkspace(workspaceById);
|
|
16
|
+
if (!found)
|
|
17
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
18
|
+
return json(req, res, 200, { workspace: found });
|
|
19
|
+
}
|
|
20
|
+
// GET /api/workspaces/:id/sessions
|
|
21
|
+
const listSessionsIn = routeParam(routes.sessions, req.method, pathname);
|
|
22
|
+
if (listSessionsIn) {
|
|
23
|
+
const ws = reads.getWorkspace(listSessionsIn);
|
|
24
|
+
const store = ws ? delegationStore(ws) : null;
|
|
25
|
+
const roles = store?.sessionRoles();
|
|
26
|
+
const enriched = ws;
|
|
27
|
+
if (enriched)
|
|
28
|
+
attachWorkflowState([enriched]);
|
|
29
|
+
const sessionRoles = { ...(roles?.sessions ?? {}), ...(enriched?.session_roles ?? {}) };
|
|
30
|
+
return json(req, res, 200, {
|
|
31
|
+
sessions: reads.listSessions(listSessionsIn),
|
|
32
|
+
...(Object.keys(sessionRoles).length ? { session_roles: sessionRoles } : {})
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const closedSessionsIn = routeParam(routes.closedSessions, req.method, pathname);
|
|
36
|
+
if (closedSessionsIn) {
|
|
37
|
+
if (!reads.getAnyWorkspace(closedSessionsIn))
|
|
38
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
39
|
+
return json(req, res, 200, { sessions: reads.listClosedSessions(closedSessionsIn) });
|
|
40
|
+
}
|
|
41
|
+
// POST /api/workspaces/:id/sessions — open a new chat (Cmd+T) in the workspace
|
|
42
|
+
const newChatIn = routeParam(routes.newChat, req.method, pathname);
|
|
43
|
+
if (newChatIn) {
|
|
44
|
+
const workspaceId = newChatIn;
|
|
45
|
+
const ws = reads.getWorkspace(workspaceId);
|
|
46
|
+
if (!ws)
|
|
47
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
48
|
+
const opened = await openChat(ws);
|
|
49
|
+
if ('error' in opened)
|
|
50
|
+
return json(req, res, 502, opened.result);
|
|
51
|
+
return json(req, res, 200, { ok: true, sessionId: opened.sessionId });
|
|
52
|
+
}
|
|
53
|
+
// GET /api/workspaces/:id/diff
|
|
54
|
+
const diffOf = routeParam(routes.diff, req.method, pathname);
|
|
55
|
+
if (diffOf) {
|
|
56
|
+
const ws = reads.getWorkspace(diffOf);
|
|
57
|
+
if (!ws)
|
|
58
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
59
|
+
if (!ws.worktree)
|
|
60
|
+
return json(req, res, 409, { error: 'worktree path unresolved' });
|
|
61
|
+
const diff = await workspaceDiff(ws.worktree, ws.baseBranch);
|
|
62
|
+
return json(req, res, 200, diff);
|
|
63
|
+
}
|
|
64
|
+
// GET /api/workspaces/:id/diff/file?path=… — the complete patch for the file
|
|
65
|
+
// currently on screen. The aggregate endpoint stays bounded for phone-sized
|
|
66
|
+
// responses, while a late file no longer disappears behind that bound.
|
|
67
|
+
const fileDiffOf = routeParam(routes.fileDiff, req.method, pathname);
|
|
68
|
+
if (fileDiffOf) {
|
|
69
|
+
const ws = reads.getWorkspace(fileDiffOf);
|
|
70
|
+
if (!ws)
|
|
71
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
72
|
+
if (!ws.worktree)
|
|
73
|
+
return json(req, res, 409, { error: 'worktree path unresolved' });
|
|
74
|
+
const file = url.searchParams.get('path');
|
|
75
|
+
if (!file)
|
|
76
|
+
return json(req, res, 400, { error: 'file path is required' });
|
|
77
|
+
const diff = await workspaceFileDiff(ws.worktree, ws.baseBranch, file);
|
|
78
|
+
if (!diff)
|
|
79
|
+
return json(req, res, 404, { error: 'changed file not found' });
|
|
80
|
+
return json(req, res, 200, diff);
|
|
81
|
+
}
|
|
82
|
+
// GET /api/workspaces/:id/files — previewable worktree files for the diff window's
|
|
83
|
+
// All-files rail and for linking `tests/foo.ts` in a message only when it really exists.
|
|
84
|
+
// A workspace with no worktree has no list for either caller.
|
|
85
|
+
const filesOf = routeParam(routes.workspaceFiles, req.method, pathname);
|
|
86
|
+
if (filesOf) {
|
|
87
|
+
const ws = reads.getWorkspace(filesOf);
|
|
88
|
+
if (!ws)
|
|
89
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
90
|
+
if (!ws.worktree)
|
|
91
|
+
return json(req, res, 200, { files: [], truncated: false });
|
|
92
|
+
return json(req, res, 200, await listSourceFiles(ws.worktree));
|
|
93
|
+
}
|
|
94
|
+
// POST /api/workspaces/:id/merge — merge the workspace's open PR (mirrors Conductor's merge button)
|
|
95
|
+
const mergeOf = routeParam(routes.merge, req.method, pathname);
|
|
96
|
+
if (mergeOf) {
|
|
97
|
+
const ws = reads.getWorkspace(mergeOf);
|
|
98
|
+
if (!ws)
|
|
99
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
100
|
+
const result = await mergePr(ws);
|
|
101
|
+
return json(req, res, result.ok ? 200 : 409, result);
|
|
102
|
+
}
|
|
103
|
+
// POST /api/workspaces/:id/continue { sessionId? } — press the Continue action
|
|
104
|
+
// Conductor draws for a merged PR. The native handler checks out a fresh branch,
|
|
105
|
+
// updates its own workspace record and stages Branch continued.md in the selected
|
|
106
|
+
// chat. Only it can do all three consistently; this relay keeps its DB read-only.
|
|
107
|
+
const continueOf = routeParam(routes.continueWorkspace, req.method, pathname);
|
|
108
|
+
if (continueOf) {
|
|
109
|
+
const workspaceId = continueOf;
|
|
110
|
+
const ws = reads.getWorkspace(workspaceId);
|
|
111
|
+
if (!ws) {
|
|
112
|
+
const known = reads.getAnyWorkspace(workspaceId);
|
|
113
|
+
if (known?.archived) {
|
|
114
|
+
return json(req, res, 409, { ok: false, error: 'Archived workspaces cannot be continued.' });
|
|
115
|
+
}
|
|
116
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
117
|
+
}
|
|
118
|
+
const body = JSON.parse((await readBody(req)) || '{}');
|
|
119
|
+
const requestedSession = body.sessionId || ws.active_session_id;
|
|
120
|
+
let tab;
|
|
121
|
+
if (requestedSession) {
|
|
122
|
+
const located = locateChat(ws, requestedSession);
|
|
123
|
+
if ('error' in located)
|
|
124
|
+
return json(req, res, 409, { ok: false, error: located.error });
|
|
125
|
+
if (body.sessionId && !located.session) {
|
|
126
|
+
return json(req, res, 409, { ok: false, error: 'chat is no longer one of the workspace’s tabs' });
|
|
127
|
+
}
|
|
128
|
+
tab = located.tab;
|
|
129
|
+
}
|
|
130
|
+
const previousBranch = ws.branch;
|
|
131
|
+
if (!previousBranch)
|
|
132
|
+
return json(req, res, 409, { ok: false, error: 'workspace has no branch to continue' });
|
|
133
|
+
const result = await continueWorkspace({ workspace: ws, sessionId: requestedSession, tab });
|
|
134
|
+
if (!result.ok)
|
|
135
|
+
return json(req, res, 502, result);
|
|
136
|
+
// AXPress only proves the button accepted a click. Conductor then fetches the
|
|
137
|
+
// target and changes the worktree asynchronously, so the branch column is the
|
|
138
|
+
// receipt. A generous wait covers the fetch without ever writing that column.
|
|
139
|
+
let continued = reads.getWorkspace(workspaceId);
|
|
140
|
+
for (let i = 0; i < 60 && (!continued?.branch || continued.branch === previousBranch); i++) {
|
|
141
|
+
await sleep(500);
|
|
142
|
+
continued = reads.getWorkspace(workspaceId);
|
|
143
|
+
}
|
|
144
|
+
if (!continued?.branch || continued.branch === previousBranch) {
|
|
145
|
+
return json(req, res, 502, {
|
|
146
|
+
ok: false,
|
|
147
|
+
strategy: result.strategy,
|
|
148
|
+
error: 'Conductor did not record a new branch within 30 seconds. Check it on your Mac before retrying.'
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return json(req, res, 200, { ok: true, previousBranch, workspace: continued });
|
|
152
|
+
}
|
|
153
|
+
// POST /api/workspaces/:id/status { status } — move it between the sidebar's status groups.
|
|
154
|
+
// Conductor derives that status from a PR it sometimes never links (a PR merged inside its
|
|
155
|
+
// poll window is invisible to it afterwards), which strands finished work in "In progress"
|
|
156
|
+
// with no way to correct it from a phone. This is that way.
|
|
157
|
+
const statusOf = routeParam(routes.workspaceStatus, req.method, pathname);
|
|
158
|
+
if (statusOf) {
|
|
159
|
+
const workspaceId = statusOf;
|
|
160
|
+
const body = JSON.parse((await readBody(req)) || '{}');
|
|
161
|
+
const status = body.status ?? '';
|
|
162
|
+
if (!WORKSPACE_STATUS_LABELS[status]) {
|
|
163
|
+
const allowed = Object.keys(WORKSPACE_STATUS_LABELS).join(', ');
|
|
164
|
+
return json(req, res, 400, { error: `status must be one of ${allowed}` });
|
|
165
|
+
}
|
|
166
|
+
const ws = reads.getWorkspace(workspaceId);
|
|
167
|
+
if (!ws)
|
|
168
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
169
|
+
const result = await setWorkspaceStatus(ws, status);
|
|
170
|
+
if (!result.ok)
|
|
171
|
+
return json(req, res, 502, result);
|
|
172
|
+
// The menu press lands in the DB a beat later. Confirm rather than assume —
|
|
173
|
+
// and if Conductor wrote something else, say what, instead of "didn't work".
|
|
174
|
+
let observed = ws.manual_status ?? '';
|
|
175
|
+
for (let i = 0; i < 10 && observed !== status; i++) {
|
|
176
|
+
await new Promise(r => setTimeout(r, 300));
|
|
177
|
+
observed = reads.getWorkspace(workspaceId)?.manual_status ?? '';
|
|
178
|
+
}
|
|
179
|
+
if (observed !== status) {
|
|
180
|
+
return json(req, res, 502, {
|
|
181
|
+
ok: false,
|
|
182
|
+
strategy: result.strategy,
|
|
183
|
+
error: observed
|
|
184
|
+
? `Conductor recorded the status as “${observed}”, not “${status}”.`
|
|
185
|
+
: 'Conductor didn’t record the change — it may have been asleep. Try again.'
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return json(req, res, 200, { ok: true, workspace: reads.getWorkspace(workspaceId) });
|
|
189
|
+
}
|
|
190
|
+
// POST /api/workspaces/:id/archive { stopAgents? } — put the workspace away, the way
|
|
191
|
+
// Conductor's own ⌘⇧A does. The one write here that destroys something: the worktree
|
|
192
|
+
// goes, and any agent still working goes with it. So the running agents are counted
|
|
193
|
+
// from the DB *before* the UI is touched and refused unless the caller has said it
|
|
194
|
+
// meant that — the phone's own dialog then says so in the same words Conductor's does.
|
|
195
|
+
const archiveOf = routeParam(routes.archiveWorkspace, req.method, pathname);
|
|
196
|
+
if (archiveOf) {
|
|
197
|
+
const workspaceId = archiveOf;
|
|
198
|
+
const body = JSON.parse((await readBody(req)) || '{}');
|
|
199
|
+
const ws = reads.getWorkspace(workspaceId);
|
|
200
|
+
if (!ws) {
|
|
201
|
+
// Already archived is the answer the caller asked for, not a 404. A phone whose
|
|
202
|
+
// answer went missing retries, and `getWorkspace` only sees the live sidebar.
|
|
203
|
+
const known = reads.getAnyWorkspace(workspaceId);
|
|
204
|
+
if (known?.archived)
|
|
205
|
+
return json(req, res, 200, { ok: true, alreadyArchived: true, workspace: known });
|
|
206
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
207
|
+
}
|
|
208
|
+
const working = reads.listSessions(ws.id).filter(s => s.status === 'working').length;
|
|
209
|
+
if (working > 0 && body.stopAgents !== true) {
|
|
210
|
+
return json(req, res, 409, {
|
|
211
|
+
ok: false,
|
|
212
|
+
agentsRunning: true,
|
|
213
|
+
error: `${working} agent${working === 1 ? ' is' : 's are'} still working here. Archiving stops them.`
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
const result = await archiveWorkspace(ws, body.stopAgents === true);
|
|
217
|
+
if (!result.ok)
|
|
218
|
+
return json(req, res, 502, result);
|
|
219
|
+
// `state` becoming 'archived' is the receipt, like the status change above: the
|
|
220
|
+
// keystroke is fire-and-forget and Conductor writes the row a beat later.
|
|
221
|
+
let archived = reads.getAnyWorkspace(workspaceId);
|
|
222
|
+
for (let i = 0; i < 20 && !archived?.archived; i++) {
|
|
223
|
+
await sleep(300);
|
|
224
|
+
archived = reads.getAnyWorkspace(workspaceId);
|
|
225
|
+
}
|
|
226
|
+
if (!archived?.archived) {
|
|
227
|
+
return json(req, res, 502, {
|
|
228
|
+
ok: false,
|
|
229
|
+
strategy: result.strategy,
|
|
230
|
+
error: 'Conductor took the archive but the workspace is still in the sidebar. Try again, or archive it on your Mac.'
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return json(req, res, 200, { ok: true, strategy: result.strategy, workspace: archived });
|
|
234
|
+
}
|
|
235
|
+
// Conductor's Run configs plus tailnet-only HTTPS forwards for the active
|
|
236
|
+
// one's ports. Reads never touch Conductor's UI; start/stop use the same
|
|
237
|
+
// Accessibility lock and target assertion as every other UI write.
|
|
238
|
+
const devServerOf = routeParam(routes.devServer, req.method, pathname);
|
|
239
|
+
if (devServerOf) {
|
|
240
|
+
const ws = reads.getWorkspace(devServerOf);
|
|
241
|
+
if (!ws)
|
|
242
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
243
|
+
return json(req, res, 200, await devServers.state(ws));
|
|
244
|
+
}
|
|
245
|
+
const startDevServerIn = routeParam(routes.startDevServer, req.method, pathname);
|
|
246
|
+
if (startDevServerIn) {
|
|
247
|
+
const ws = reads.getWorkspace(startDevServerIn);
|
|
248
|
+
if (!ws)
|
|
249
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
250
|
+
const body = JSON.parse((await readBody(req)) || '{}');
|
|
251
|
+
if (body.runConfigId !== undefined && (typeof body.runConfigId !== 'string' || !body.runConfigId.trim())) {
|
|
252
|
+
return json(req, res, 400, { error: 'runConfigId must be a non-empty string' });
|
|
253
|
+
}
|
|
254
|
+
const result = await devServers.start(ws, body.runConfigId);
|
|
255
|
+
return json(req, res, result.ok ? 200 : result.available ? 502 : 409, result);
|
|
256
|
+
}
|
|
257
|
+
const stopDevServerIn = routeParam(routes.stopDevServer, req.method, pathname);
|
|
258
|
+
if (stopDevServerIn) {
|
|
259
|
+
const ws = reads.getWorkspace(stopDevServerIn);
|
|
260
|
+
if (!ws)
|
|
261
|
+
return json(req, res, 404, { error: 'workspace not found' });
|
|
262
|
+
const result = await devServers.stop(ws);
|
|
263
|
+
return json(req, res, result.ok ? 200 : 502, result);
|
|
264
|
+
}
|
|
265
|
+
return NOT_HANDLED;
|
|
266
|
+
};
|
|
267
|
+
}
|