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.
Files changed (200) hide show
  1. package/README.md +10 -8
  2. package/dist/assets/{PierrePatch-D3_YBIAr.js → PierrePatch-Dh-08CLI.js} +1 -1
  3. package/dist/assets/index-BRzsSW8g.css +1 -0
  4. package/dist/assets/index-BpY3Jhxk.js +65 -0
  5. package/dist/index.html +2 -2
  6. package/dist/push-sw.js +2 -2
  7. package/dist/sw.js +1 -1
  8. package/dist-node/scripts/nosleep-setup.js +2 -2
  9. package/dist-node/scripts/nosleep.js +3 -3
  10. package/dist-node/scripts/service/commands.js +32 -0
  11. package/dist-node/scripts/service/configuration.js +205 -0
  12. package/dist-node/scripts/service/environment.js +59 -0
  13. package/dist-node/scripts/service/flags.js +45 -0
  14. package/dist-node/scripts/service/installation.js +91 -0
  15. package/dist-node/scripts/service/launch-agent.js +134 -0
  16. package/dist-node/scripts/service/network.js +244 -0
  17. package/dist-node/scripts/service/presentation.js +101 -0
  18. package/dist-node/scripts/service/voice.js +113 -0
  19. package/dist-node/scripts/service.js +5 -980
  20. package/dist-node/src/{agent-config.js → agents/agent-config.js} +1 -1
  21. package/dist-node/src/{model-cache.js → agents/model-cache.js} +1 -1
  22. package/dist-node/src/{roles.js → agents/roles.js} +3 -3
  23. package/dist-node/src/db.js +1 -1
  24. package/dist-node/src/{parked.js → delivery/parked.js} +1 -1
  25. package/dist-node/src/{dev-server.js → dev-server/controller.js} +8 -291
  26. package/dist-node/src/dev-server/ports.js +63 -0
  27. package/dist-node/src/dev-server/processes.js +73 -0
  28. package/dist-node/src/dev-server/proxy.js +158 -0
  29. package/dist-node/src/{run-activity.js → dev-server/run-activity.js} +2 -2
  30. package/dist-node/src/dev-server/types.js +1 -0
  31. package/dist-node/src/{file-preview.js → files/file-preview.js} +1 -1
  32. package/dist-node/src/{change-stats.js → git/change-stats.js} +1 -1
  33. package/dist-node/src/{git.js → git/diff.js} +43 -18
  34. package/dist-node/src/{autoupdate.js → host/autoupdate.js} +1 -1
  35. package/dist-node/src/{funnel-watchdog.js → host/funnel-watchdog.js} +4 -4
  36. package/dist-node/src/{logbuf.js → host/logbuf.js} +1 -1
  37. package/dist-node/src/{nosleep-helper.js → host/nosleep-helper.js} +1 -1
  38. package/dist-node/src/{tailscale.js → host/tailscale.js} +1 -1
  39. package/dist-node/src/http/router-types.js +2 -0
  40. package/dist-node/src/http/router.js +78 -0
  41. package/dist-node/src/http/routes/create-workspace.js +90 -0
  42. package/dist-node/src/http/routes/files.js +53 -0
  43. package/dist-node/src/http/routes/prompts.js +363 -0
  44. package/dist-node/src/http/routes/sessions.js +279 -0
  45. package/dist-node/src/http/routes/state.js +186 -0
  46. package/dist-node/src/http/routes/system.js +220 -0
  47. package/dist-node/src/http/routes/voice.js +117 -0
  48. package/dist-node/src/http/routes/workflows.js +248 -0
  49. package/dist-node/src/http/routes/workspaces.js +267 -0
  50. package/dist-node/src/http/services/base.js +252 -0
  51. package/dist-node/src/http/services/delegations.js +301 -0
  52. package/dist-node/src/http/services/delivery.js +433 -0
  53. package/dist-node/src/http/services/files.js +199 -0
  54. package/dist-node/src/http/services/mcp.js +94 -0
  55. package/dist-node/src/http/services/responses.js +120 -0
  56. package/dist-node/src/http/services/voice.js +147 -0
  57. package/dist-node/src/http/services/workflow-probes.js +215 -0
  58. package/dist-node/src/http/services/workflow-state.js +195 -0
  59. package/dist-node/src/http/services/workflow.js +366 -0
  60. package/dist-node/src/http/services.js +35 -0
  61. package/dist-node/src/mcp/arguments.js +14 -0
  62. package/dist-node/src/mcp/dispatcher.js +56 -0
  63. package/dist-node/src/mcp/formatters.js +110 -0
  64. package/dist-node/src/mcp/protocol.js +7 -0
  65. package/dist-node/src/mcp/registry.js +66 -0
  66. package/dist-node/src/mcp/tools/agent-options.js +122 -0
  67. package/dist-node/src/mcp/tools/chat-actions.js +194 -0
  68. package/dist-node/src/mcp/tools/chats.js +194 -0
  69. package/dist-node/src/mcp/tools/delegation.js +135 -0
  70. package/dist-node/src/mcp/tools/system.js +135 -0
  71. package/dist-node/src/mcp/tools/voice.js +136 -0
  72. package/dist-node/src/mcp/tools/workspaces.js +259 -0
  73. package/dist-node/src/mcp/types.js +1 -0
  74. package/dist-node/src/mcp.js +6 -4
  75. package/dist-node/src/{notify.js → notifications/notify.js} +5 -5
  76. package/dist-node/src/{webpush.js → notifications/webpush.js} +1 -1
  77. package/dist-node/src/orchestration/delegation/codec.js +201 -0
  78. package/dist-node/src/{delegation-intake.js → orchestration/delegation/intake.js} +2 -2
  79. package/dist-node/src/{delegation-prompt.js → orchestration/delegation/prompt.js} +1 -1
  80. package/dist-node/src/orchestration/delegation/queue.js +255 -0
  81. package/dist-node/src/orchestration/delegation/store.js +111 -0
  82. package/dist-node/src/orchestration/delegation/types.js +2 -0
  83. package/dist-node/src/orchestration/persistence/capabilities.js +109 -0
  84. package/dist-node/src/orchestration/persistence/codecs.js +148 -0
  85. package/dist-node/src/orchestration/persistence/connection.js +205 -0
  86. package/dist-node/src/orchestration/persistence/db.js +101 -0
  87. package/dist-node/src/orchestration/persistence/effect-recovery.js +227 -0
  88. package/dist-node/src/orchestration/persistence/effect-transitions.js +157 -0
  89. package/dist-node/src/orchestration/persistence/effects.js +109 -0
  90. package/dist-node/src/orchestration/persistence/errors.js +39 -0
  91. package/dist-node/src/orchestration/persistence/events.js +29 -0
  92. package/dist-node/src/orchestration/persistence/idempotency.js +82 -0
  93. package/dist-node/src/orchestration/persistence/job-attempts.js +114 -0
  94. package/dist-node/src/orchestration/persistence/jobs.js +159 -0
  95. package/dist-node/src/orchestration/persistence/projections.js +190 -0
  96. package/dist-node/src/orchestration/persistence/quarantine.js +46 -0
  97. package/dist-node/src/orchestration/persistence/records.js +115 -0
  98. package/dist-node/src/orchestration/persistence/relays.js +78 -0
  99. package/dist-node/src/orchestration/persistence/runs.js +156 -0
  100. package/dist-node/src/{orchestration-schema.js → orchestration/persistence/schema.js} +1 -1
  101. package/dist-node/src/orchestration/persistence/types.js +1 -0
  102. package/dist-node/src/orchestration/persistence/ui-lease.js +197 -0
  103. package/dist-node/src/orchestration/persistence/values.js +114 -0
  104. package/dist-node/src/orchestration/workflow/commands.js +309 -0
  105. package/dist-node/src/orchestration/workflow/coordinator.js +28 -0
  106. package/dist-node/src/orchestration/workflow/effect-recovery.js +125 -0
  107. package/dist-node/src/orchestration/workflow/effects.js +307 -0
  108. package/dist-node/src/orchestration/workflow/errors.js +13 -0
  109. package/dist-node/src/orchestration/workflow/helpers.js +154 -0
  110. package/dist-node/src/orchestration/workflow/job-dispatch.js +312 -0
  111. package/dist-node/src/orchestration/workflow/job-results.js +280 -0
  112. package/dist-node/src/{workflow.js → orchestration/workflow/prompts.js} +2 -2
  113. package/dist-node/src/orchestration/workflow/root.js +293 -0
  114. package/dist-node/src/orchestration/workflow/start.js +99 -0
  115. package/dist-node/src/orchestration/workflow/state.js +105 -0
  116. package/dist-node/src/orchestration/workflow/types.js +1 -0
  117. package/dist-node/src/orchestration/workflow/wake.js +164 -0
  118. package/dist-node/src/prefs.js +1 -1
  119. package/dist-node/src/{background-tasks.js → reads/background-tasks.js} +1 -1
  120. package/dist-node/src/reads/messages.js +362 -0
  121. package/dist-node/src/reads/repository.js +87 -0
  122. package/dist-node/src/reads/sessions.js +165 -0
  123. package/dist-node/src/reads/types.js +1 -0
  124. package/dist-node/src/reads/workspaces.js +230 -0
  125. package/dist-node/src/reads/worktrees.js +45 -0
  126. package/dist-node/src/routes.js +5 -5
  127. package/dist-node/src/{search.js → search/coordinator.js} +4 -4
  128. package/dist-node/src/{search-worker.js → search/worker.js} +3 -3
  129. package/dist-node/src/server.js +14 -3930
  130. package/dist-node/src/settings.js +1 -1
  131. package/dist-node/src/shared.js +10 -10
  132. package/dist-node/src/{transcript.js → transcript/parser.js} +4 -4
  133. package/dist-node/src/{tool-usage-worker.js → usage/tool-usage-worker.js} +1 -1
  134. package/dist-node/src/{tool-usage.js → usage/tool-usage.js} +1 -1
  135. package/dist-node/src/voice/brief.js +22 -50
  136. package/dist-node/src/voice/context.js +1 -1
  137. package/dist-node/src/voice/dates.js +38 -0
  138. package/dist-node/src/voice/history.js +14 -5
  139. package/dist-node/src/voice/prompt.js +10 -9
  140. package/dist-node/src/voice/recall.js +115 -0
  141. package/dist-node/src/{speech.js → voice/speech.js} +1 -1
  142. package/dist-node/src/voice/tools.js +92 -3
  143. package/dist-node/src/voice/webrtc.js +1 -1
  144. package/dist-node/src/wire.js +2 -2
  145. package/dist-node/src/writes/actuator.js +124 -0
  146. package/dist-node/src/writes/agent-options.js +151 -0
  147. package/dist-node/src/writes/applescript/agent-options.applescript +334 -0
  148. package/dist-node/src/writes/applescript/chat-targeting.applescript +149 -0
  149. package/dist-node/src/writes/applescript/composer.applescript +195 -0
  150. package/dist-node/src/writes/applescript/hotspot.applescript +155 -0
  151. package/dist-node/src/writes/applescript/lifecycle.applescript +266 -0
  152. package/dist-node/src/writes/applescript/run-tasks.applescript +208 -0
  153. package/dist-node/src/writes/applescript/source.js +52 -0
  154. package/dist-node/src/writes/applescript/window.applescript +436 -0
  155. package/dist-node/src/writes/applescript/workspace-status.applescript +177 -0
  156. package/dist-node/src/writes/applescript/workspace-targeting.applescript +359 -0
  157. package/dist-node/src/writes/chats.js +160 -0
  158. package/dist-node/src/writes/guards.js +77 -0
  159. package/dist-node/src/writes/runner.js +67 -0
  160. package/dist-node/src/{sidecar.js → writes/sidecar.js} +1 -1
  161. package/dist-node/src/writes/system.js +81 -0
  162. package/dist-node/src/writes/targeting.js +121 -0
  163. package/dist-node/src/writes/types.js +1 -0
  164. package/dist-node/src/writes/ui-lock.js +229 -0
  165. package/dist-node/src/writes/workspaces.js +233 -0
  166. package/docs/voice-setup.md +34 -12
  167. package/package.json +2 -2
  168. package/dist/assets/index-ByTwVInL.css +0 -1
  169. package/dist/assets/index-LAm9X7wv.js +0 -65
  170. package/dist-node/src/conductor.applescript +0 -2279
  171. package/dist-node/src/delegations.js +0 -557
  172. package/dist-node/src/mcp-tools.js +0 -1319
  173. package/dist-node/src/orchestration-db.js +0 -2186
  174. package/dist-node/src/reads.js +0 -787
  175. package/dist-node/src/workflow-coordinator.js +0 -2119
  176. package/dist-node/src/writes.js +0 -1223
  177. /package/dist-node/src/{conductor-settings.js → agents/conductor-settings.js} +0 -0
  178. /package/dist-node/src/{firstprompt.js → delivery/firstprompt.js} +0 -0
  179. /package/dist-node/src/{sendonce.js → delivery/sendonce.js} +0 -0
  180. /package/dist-node/src/{preview-urls.js → dev-server/preview-urls.js} +0 -0
  181. /package/dist-node/src/{run-configs.js → dev-server/run-configs.js} +0 -0
  182. /package/dist-node/src/{attachments.js → files/attachments.js} +0 -0
  183. /package/dist-node/src/{icons.js → files/icons.js} +0 -0
  184. /package/dist-node/src/{staged-attachments.js → files/staged-attachments.js} +0 -0
  185. /package/dist-node/src/{fork-workspace.js → git/fork-workspace.js} +0 -0
  186. /package/dist-node/src/{merge.js → git/merge.js} +0 -0
  187. /package/dist-node/src/{pr.js → git/pr.js} +0 -0
  188. /package/dist-node/src/{nosleep.js → host/nosleep.js} +0 -0
  189. /package/dist-node/src/{relay-processes.js → host/relay-processes.js} +0 -0
  190. /package/dist-node/src/{ui-lease-watchdog.js → host/ui-lease-watchdog.js} +0 -0
  191. /package/dist-node/src/{wifi.js → host/wifi.js} +0 -0
  192. /package/dist-node/src/{orchestration-schema.generated.js → orchestration/persistence/schema.generated.js} +0 -0
  193. /package/dist-node/src/{workflow-effect-runner.js → orchestration/workflow/effect-runner.js} +0 -0
  194. /package/dist-node/src/{workflow-http.js → orchestration/workflow/http.js} +0 -0
  195. /package/dist-node/src/{workflow-machine.js → orchestration/workflow/machine.js} +0 -0
  196. /package/dist-node/src/{session-poller.js → reads/session-poller.js} +0 -0
  197. /package/dist-node/src/{context-breakdown.js → transcript/context-breakdown.js} +0 -0
  198. /package/dist-node/src/{chat-cursor.js → transcript/cursor.js} +0 -0
  199. /package/dist-node/src/{plan-usage.js → usage/plan-usage.js} +0 -0
  200. /package/dist-node/src/{tool-usage-service.js → usage/tool-usage-service.js} +0 -0
@@ -0,0 +1,259 @@
1
+ import { routes } from "../../routes.js";
2
+ import { workspaceTitle } from "../../shared.js";
3
+ import { need, rejectUnknown, str } from "../arguments.js";
4
+ import { clip, formatDevServer, unmark } from "../formatters.js";
5
+ import { WRITE_TIMEOUT_MS } from "../protocol.js";
6
+ export function createListWorkspacesTool(call) {
7
+ return {
8
+ name: 'list_workspaces',
9
+ description: 'List the live (non-archived) Conductor workspaces with what each one is doing right now: agent status, model, branch, PR state, and any prompt the relay is still holding for it. Use this to see what is running before starting or steering anything.',
10
+ inputSchema: {
11
+ type: 'object',
12
+ properties: {
13
+ status: {
14
+ type: 'string',
15
+ description: 'Filter by live agent status: working | idle | error. Omit for all.'
16
+ }
17
+ }
18
+ },
19
+ run: async (args) => {
20
+ const status = str(args.status);
21
+ const data = await call(routes.state.path());
22
+ const shown = status ? data.workspaces.filter(w => w.session_status === status) : data.workspaces;
23
+ if (!shown.length)
24
+ return status ? `no workspace is ${status}` : 'no live workspaces';
25
+ return shown
26
+ .map(w => {
27
+ const assigned = w.active_session_id ? w.session_roles?.[w.active_session_id] : undefined;
28
+ const lines = [
29
+ `${w.session_status === 'working' ? '▶' : '·'} ${workspaceTitle(w)}`,
30
+ ` ${[w.repo_name, w.branch, w.model, assigned ? `role ${assigned.role}` : null, w.pr_number ? `PR #${w.pr_number} ${w.pr_status ?? ''}`.trim() : null].filter(Boolean).join(' · ')}`,
31
+ ` workspace_id: ${w.id}${w.active_session_id ? ` session_id: ${w.active_session_id}` : ''}`
32
+ ];
33
+ // An undelivered prompt is invisible from the DB — it lives in the relay's own
34
+ // queues — so an agent reading only status would call a stalled workspace idle
35
+ // and send a second copy of the prompt already waiting on it (dismiss_prompt).
36
+ if (w.pending_prompt) {
37
+ const p = w.pending_prompt;
38
+ lines.push(` ! first prompt ${p.status}: ${clip(unmark(p.text), 120)}${p.error ? ` — ${p.error}` : ''}`);
39
+ }
40
+ for (const p of w.parked_prompts ?? []) {
41
+ lines.push(` ! prompt ${p.status} for session ${p.sessionId} (${p.reason}): ${clip(unmark(p.text), 120)}`);
42
+ }
43
+ for (const job of w.delegations ?? []) {
44
+ lines.push(` ${job.status === 'failed' ? '!' : '→'} delegation ${job.role}: ${job.status} (${job.id})${job.failure ? ` — ${job.failure.message}` : ''}`);
45
+ }
46
+ if (w.delegation_warning)
47
+ lines.push(` ! delegation state: ${w.delegation_warning}`);
48
+ return lines.join('\n');
49
+ })
50
+ .join('\n');
51
+ }
52
+ };
53
+ }
54
+ export function createWorkspaceDiffTool(call) {
55
+ return {
56
+ name: 'workspace_diff',
57
+ description: 'The git diff of a live workspace against its target branch, untracked files included.',
58
+ inputSchema: {
59
+ type: 'object',
60
+ properties: { workspace_id: { type: 'string' } },
61
+ required: ['workspace_id']
62
+ },
63
+ run: async (args) => {
64
+ const id = need(args, 'workspace_id');
65
+ const data = await call(routes.diff.path(id), {
66
+ timeoutMs: 30_000
67
+ });
68
+ if (!data.files.length)
69
+ return 'no changes against the target branch';
70
+ return data.files.map(f => `${f.path} +${f.added} -${f.removed}`).join('\n');
71
+ }
72
+ };
73
+ }
74
+ export function createListReposTool(call) {
75
+ return {
76
+ name: 'list_repos',
77
+ description: 'The repos Conductor can create a workspace in. Use before create_workspace to get an exact repo name.',
78
+ inputSchema: { type: 'object', properties: {} },
79
+ run: async () => {
80
+ const data = await call(routes.repos.path());
81
+ return data.repos.map(r => `${r.name} (${r.default_branch ?? '?'}) ${r.root_path ?? ''}`).join('\n');
82
+ }
83
+ };
84
+ }
85
+ export function createCreateWorkspaceTool(call) {
86
+ return {
87
+ name: 'create_workspace',
88
+ description: 'Start an ordinary new Conductor workspace in a repo, optionally with a first prompt and agent settings. The workspace starts from a Conductor deep link, so creation itself needs no Accessibility. The relay applies requested model, effort, plan, and fast settings through Conductor’s UI after it creates the first chat and before it delivers the prompt. This utility cannot start or join a Workflow. Returns as soon as the workspace row exists (~2s), before the worktree is built.',
89
+ inputSchema: {
90
+ type: 'object',
91
+ properties: {
92
+ repo: { type: 'string', description: 'Exact name from list_repos.' },
93
+ prompt: { type: 'string', description: 'First prompt for the new agent. Omit to open an empty workspace.' },
94
+ model: {
95
+ type: 'string',
96
+ description: 'Picker label from list_models with no session_id. The relay applies it before the first prompt, or configures an empty workspace once its chat exists.'
97
+ },
98
+ effort: {
99
+ type: 'string',
100
+ enum: ['none', 'low', 'medium', 'high', 'xhigh', 'max', 'ultracode'],
101
+ description: 'Reasoning effort applied before the first prompt.'
102
+ },
103
+ plan: { type: 'boolean', description: 'Start the first chat in Conductor’s Plan mode.' },
104
+ fast: { type: 'boolean', description: 'Set Fast mode before the first prompt.' },
105
+ wait_for_send: {
106
+ type: 'boolean',
107
+ description: 'Block until the first prompt is actually delivered (tens of seconds, and longer behind other queued sends). Default false.'
108
+ },
109
+ send_immediately: {
110
+ type: 'boolean',
111
+ description: "Send the first prompt without waiting for the worktree to finish building, which is how Conductor's own New workspace box behaves. Default true. Pass false only when the agent's first move needs what the repo's setup script installs."
112
+ }
113
+ },
114
+ required: ['repo'],
115
+ additionalProperties: false
116
+ },
117
+ run: async (args) => {
118
+ rejectUnknown(args, ['repo', 'prompt', 'model', 'effort', 'plan', 'fast', 'wait_for_send', 'send_immediately']);
119
+ const repo = need(args, 'repo');
120
+ const prompt = str(args.prompt);
121
+ const model = str(args.model);
122
+ const effort = str(args.effort);
123
+ const plan = typeof args.plan === 'boolean' ? args.plan : undefined;
124
+ const fast = typeof args.fast === 'boolean' ? args.fast : undefined;
125
+ const explicitAgent = model !== undefined || effort !== undefined || plan !== undefined || fast !== undefined;
126
+ const configured = explicitAgent;
127
+ const send = args.wait_for_send === true;
128
+ // Default on, matching the relay: an omitted flag must never mean "wait".
129
+ const sendImmediately = args.send_immediately !== false;
130
+ const data = await call(routes.createWorkspace.path(), {
131
+ method: routes.createWorkspace.method,
132
+ body: { repo, prompt, model, effort, plan, fast, send, sendImmediately },
133
+ timeoutMs: send ? WRITE_TIMEOUT_MS : 30_000
134
+ });
135
+ const lines = [
136
+ `created ${data.workspace ? workspaceTitle(data.workspace) : data.workspaceId}`,
137
+ `workspace_id: ${data.workspaceId}`
138
+ ];
139
+ if (data.warning)
140
+ lines.push(`! ${data.warning}`);
141
+ else if (data.pendingPrompt && !data.sent)
142
+ lines.push('the first prompt is queued — the relay delivers it, so do not send it again');
143
+ else if (data.sent)
144
+ lines.push('the first prompt was delivered');
145
+ if (configured)
146
+ lines.push(data.configured ? 'agent settings applied' : 'agent settings queued');
147
+ return lines.join('\n');
148
+ }
149
+ };
150
+ }
151
+ export function createSetWorkspaceStatusTool(call) {
152
+ return {
153
+ name: 'set_workspace_status',
154
+ description: 'Set a workspace’s status in Conductor’s sidebar (backlog, in-progress, in-review, done, canceled). Drives the real UI through the sidebar row menu, but changes nothing on screen. A collapsed section hides its rows from Accessibility, so folded sections are opened, used, and folded back — which makes this run a few seconds longer.',
155
+ inputSchema: {
156
+ type: 'object',
157
+ properties: {
158
+ workspace_id: { type: 'string' },
159
+ status: { type: 'string', enum: ['backlog', 'in-progress', 'in-review', 'done', 'canceled'] }
160
+ },
161
+ required: ['workspace_id', 'status']
162
+ },
163
+ run: async (args) => {
164
+ const id = need(args, 'workspace_id');
165
+ const status = need(args, 'status');
166
+ const data = await call(routes.workspaceStatus.path(id), {
167
+ method: routes.workspaceStatus.method,
168
+ body: { status },
169
+ timeoutMs: WRITE_TIMEOUT_MS
170
+ });
171
+ if (!data.ok)
172
+ throw new Error(data.error ?? 'the status change did not land');
173
+ return `status set to ${status}`;
174
+ }
175
+ };
176
+ }
177
+ export function createDevServerTool(call) {
178
+ return {
179
+ name: 'dev_server',
180
+ description: 'Inspect, start or stop a workspace’s configured Conductor Run task and tailnet preview. Use this instead of launching a long-lived development server from a shell: Conductor supplies the workspace ports, enforces run-mode rules and owns process cleanup, while the relay avoids duplicate starts. Status is the default and touches no UI. Start and stop DRIVE THE REAL UI and can steal focus for a few seconds; confirm before controlling a workspace the user did not name. Starting requires Tailscale and, when status lists multiple Run configs, an exact run_config_id.',
181
+ inputSchema: {
182
+ type: 'object',
183
+ properties: {
184
+ workspace_id: { type: 'string', description: 'The live local workspace to control.' },
185
+ action: {
186
+ type: 'string',
187
+ enum: ['status', 'start', 'stop'],
188
+ description: 'Default status. Start and stop use Conductor’s managed Run task.'
189
+ },
190
+ run_config_id: {
191
+ type: 'string',
192
+ description: 'Exact ID printed by status. Only valid for start; required when more than one is listed.'
193
+ }
194
+ },
195
+ required: ['workspace_id']
196
+ },
197
+ run: async (args) => {
198
+ const id = need(args, 'workspace_id');
199
+ const action = str(args.action) ?? 'status';
200
+ if (action !== 'status' && action !== 'start' && action !== 'stop')
201
+ throw new Error('action is invalid');
202
+ const runConfigId = str(args.run_config_id);
203
+ if (args.run_config_id !== undefined && !runConfigId)
204
+ throw new Error('run_config_id must be a non-empty string');
205
+ if (runConfigId && action !== 'start')
206
+ throw new Error('run_config_id is only valid with action start');
207
+ if (action === 'status') {
208
+ const state = await call(routes.devServer.path(id));
209
+ return formatDevServer(state);
210
+ }
211
+ const route = action === 'start' ? routes.startDevServer : routes.stopDevServer;
212
+ const result = await call(route.path(id), {
213
+ method: route.method,
214
+ ...(action === 'start' && runConfigId ? { body: { runConfigId } } : {}),
215
+ timeoutMs: WRITE_TIMEOUT_MS
216
+ });
217
+ if (!result.ok)
218
+ throw new Error(result.error ?? `could not ${action} the dev server`);
219
+ const headline = action === 'start'
220
+ ? result.changed === false
221
+ ? 'already running'
222
+ : 'started'
223
+ : result.changed === false
224
+ ? 'already stopped'
225
+ : 'stopped';
226
+ return formatDevServer(result, headline);
227
+ }
228
+ };
229
+ }
230
+ export function createArchiveWorkspaceTool(call) {
231
+ return {
232
+ name: 'archive_workspace',
233
+ description: 'Archive a workspace — Conductor’s own ⌘⇧A, which deletes its worktree and takes any agent still working in it down with it. The chat survives archiving and stays readable through search_chats and read_chat. Drives the real UI: it focuses the workspace on the Mac first, so confirm with the user before archiving one they did not name. A workspace with an agent working is refused unless stop_agents is true.',
234
+ inputSchema: {
235
+ type: 'object',
236
+ properties: {
237
+ workspace_id: { type: 'string' },
238
+ stop_agents: {
239
+ type: 'boolean',
240
+ description: 'Archive even though agents are still working here, ending their turns.'
241
+ }
242
+ },
243
+ required: ['workspace_id']
244
+ },
245
+ run: async (args) => {
246
+ const id = need(args, 'workspace_id');
247
+ const data = await call(routes.archiveWorkspace.path(id), {
248
+ method: routes.archiveWorkspace.method,
249
+ body: { stopAgents: args.stop_agents === true },
250
+ timeoutMs: WRITE_TIMEOUT_MS
251
+ });
252
+ if (!data.ok)
253
+ throw new Error(data.error ?? 'the archive did not land');
254
+ if (data.alreadyArchived)
255
+ return 'already archived';
256
+ return `archived ${data.workspace ? workspaceTitle(data.workspace) : id}`;
257
+ }
258
+ };
259
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,13 +2,15 @@ import { readFileSync } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { createInterface } from 'node:readline';
4
4
  import { stateDir } from "./config.js";
5
- import { createTools, handleRpc, READ_TIMEOUT_MS } from "./mcp-tools.js";
5
+ import { handleRpc } from "./mcp/dispatcher.js";
6
+ import { READ_TIMEOUT_MS } from "./mcp/protocol.js";
7
+ import { createTools } from "./mcp/registry.js";
6
8
  /**
7
9
  * MCP over stdio: `conductor-remote mcp`.
8
10
  *
9
11
  * The transport a local agent gets — the client spawns this as a child process and
10
12
  * talks newline-delimited JSON-RPC 2.0 over its stdin and stdout. The tools
11
- * themselves live in `mcp-tools.ts`, shared with the relay's own `POST /mcp` so the
13
+ * themselves live in `src/mcp/tools/`, shared with the relay's own `POST /mcp` so the
12
14
  * two transports cannot drift.
13
15
  *
14
16
  * Nothing here authenticates the *stdio* channel, and nothing needs to: whatever can
@@ -55,10 +57,10 @@ async function call(route, opts = {}) {
55
57
  authorization: `Bearer ${relayToken()}`,
56
58
  'content-type': 'application/json',
57
59
  // Marks this caller as an agent: the relay drops it to background priority on
58
- // the UI lock, behind anyone using the phone (server.ts ▸ withUiPriority).
60
+ // the UI lock, behind anyone using the phone (src/http/router.ts ▸ withUiPriority).
59
61
  'x-relay-client': 'mcp',
60
62
  // The relay retries a failed send inside this budget and never past it, so
61
- // stating it here is what stops it outliving us — see server.ts ▸ sendBudget.
63
+ // stating it here is what stops it outliving us — see src/http/services/delivery.ts ▸ sendBudget.
62
64
  'x-client-timeout-ms': String(timeoutMs)
63
65
  },
64
66
  body: opts.body === undefined ? undefined : JSON.stringify(opts.body)
@@ -28,8 +28,8 @@
28
28
  import crypto from 'node:crypto';
29
29
  import fs from 'node:fs';
30
30
  import path from 'node:path';
31
- import { stateDir } from "./config.js";
32
- import { clipExact, oneLine } from "./speech.js";
31
+ import { stateDir } from "../config.js";
32
+ import { clipExact, oneLine } from "../voice/speech.js";
33
33
  import { generateVapidKeys, MAX_PAYLOAD_BYTES, sendPush } from "./webpush.js";
34
34
  const STORE_VERSION = 1;
35
35
  /**
@@ -227,7 +227,7 @@ async function deliver(device, message) {
227
227
  }
228
228
  device.failures++;
229
229
  device.lastError = result.error ?? `HTTP ${result.status}`;
230
- // Never log the endpoint: it's a capability URL, and the log is a wire surface (src/logbuf.ts).
230
+ // Never log the endpoint: it's a capability URL, and the log is a wire surface (src/host/logbuf.ts).
231
231
  console.warn(`[push] delivery failed (${device.lastError}) — ${device.failures} in a row`);
232
232
  if (device.failures >= MAX_FAILURES)
233
233
  drop(device.endpoint, `${device.failures} consecutive failures`);
@@ -286,7 +286,7 @@ export function chatRoute(workspaceId, sessionId) {
286
286
  * Everything this chat records about a person having asked for something, as one
287
287
  * comparable string — the turn head *and* the last user message, because steering a
288
288
  * running turn moves only the second (`turn_started_at` stays at the first message in
289
- * that `turn_id`; see reads.ts). Empty when the chat records neither, which is what
289
+ * that `turn_id`; see src/reads/sessions.ts). Empty when the chat records neither, which is what
290
290
  * `selfScheduled` reads as "no evidence" rather than as "nobody asked".
291
291
  */
292
292
  function askedBy(state) {
@@ -300,7 +300,7 @@ function turnEnded(status) {
300
300
  }
301
301
  /**
302
302
  * The status state machine, kept apart from the store and the network so it can be
303
- * driven a tick at a time by `tests/notify.test.ts`. Every rule in it is a rule
303
+ * driven a tick at a time by `tests/notifications/notify.test.ts`. Every rule in it is a rule
304
304
  * about *not* notifying, and each one is a nuisance or a silence that nothing in the
305
305
  * type system can catch.
306
306
  */
@@ -13,7 +13,7 @@
13
13
  * - **The keypair must be stable.** `applicationServerKey` is baked into the
14
14
  * browser's subscription at subscribe time, and a push signed by a *different*
15
15
  * VAPID key is rejected (403) forever after. So the keys are persisted
16
- * (src/notify.ts) and never regenerated behind a live subscription.
16
+ * (src/notifications/notify.ts) and never regenerated behind a live subscription.
17
17
  * - **A push must carry a notification the SW actually shows.** Silent pushes
18
18
  * get a subscription dropped on iOS, so the caller always sends a payload and
19
19
  * `public/push-sw.js` always calls `showNotification`.
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Validate the exact persisted delegation envelope and stage-specific evidence.
3
+ * Decoder failures remain public warnings; callers keep the original bytes intact.
4
+ */
5
+ import { decodeRoles } from "../../agents/roles.js";
6
+ export const SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
7
+ const MAX_TEXT = 1_000_000;
8
+ const STATUSES = new Set([
9
+ 'queued',
10
+ 'opening',
11
+ 'configuring',
12
+ 'sending',
13
+ 'running',
14
+ 'returning',
15
+ 'returned',
16
+ 'failed'
17
+ ]);
18
+ const ERROR_CODES = new Set([
19
+ 'invalid_request',
20
+ 'role_not_found',
21
+ 'model_missing',
22
+ 'provider_unknown',
23
+ 'same_provider',
24
+ 'workspace_not_found',
25
+ 'session_not_found',
26
+ 'delegation_not_found',
27
+ 'worktree_unavailable',
28
+ 'state_invalid',
29
+ 'opening_failed',
30
+ 'configuration_failed',
31
+ 'send_failed',
32
+ 'completion_failed',
33
+ 'return_failed'
34
+ ]);
35
+ function object(raw) {
36
+ return raw !== null && typeof raw === 'object' && !Array.isArray(raw) ? raw : null;
37
+ }
38
+ export function text(value, field, maximum = 256) {
39
+ if (typeof value !== 'string' || !value.trim() || value.length > maximum)
40
+ throw new Error(`${field} is invalid`);
41
+ return value;
42
+ }
43
+ function integer(value, field, minimum = 0) {
44
+ if (!Number.isSafeInteger(value) || value < minimum)
45
+ throw new Error(`${field} is invalid`);
46
+ return value;
47
+ }
48
+ function decodeError(raw, field) {
49
+ const value = object(raw);
50
+ if (!value || !ERROR_CODES.has(value.code))
51
+ throw new Error(`${field}.code is invalid`);
52
+ return {
53
+ code: value.code,
54
+ message: text(value.message, `${field}.message`, 10_000),
55
+ retryable: value.retryable === true
56
+ };
57
+ }
58
+ function decodeOutcome(raw) {
59
+ const value = object(raw);
60
+ if (!value)
61
+ throw new Error('outcome is invalid');
62
+ if (value.kind === 'success') {
63
+ return {
64
+ kind: 'success',
65
+ assistantRowid: integer(value.assistantRowid, 'outcome.assistantRowid', 1),
66
+ text: text(value.text, 'outcome.text', MAX_TEXT)
67
+ };
68
+ }
69
+ if (value.kind === 'error') {
70
+ return {
71
+ kind: 'error',
72
+ ...(value.assistantRowid === undefined
73
+ ? {}
74
+ : { assistantRowid: integer(value.assistantRowid, 'outcome.assistantRowid', 1) }),
75
+ ...(value.text === undefined ? {} : { text: text(value.text, 'outcome.text', MAX_TEXT) }),
76
+ error: text(value.error, 'outcome.error', 10_000)
77
+ };
78
+ }
79
+ throw new Error('outcome.kind is invalid');
80
+ }
81
+ function decodeAttachment(raw) {
82
+ const value = object(raw);
83
+ if (!value)
84
+ throw new Error('handoff is invalid');
85
+ return {
86
+ name: text(value.name, 'handoff.name', 256),
87
+ path: text(value.path, 'handoff.path', 1_024),
88
+ bytes: integer(value.bytes, 'handoff.bytes'),
89
+ token: text(value.token, 'handoff.token', 2_048)
90
+ };
91
+ }
92
+ function decodeResolvedRole(raw) {
93
+ const value = object(raw);
94
+ if (!value)
95
+ throw new Error('resolvedRole is invalid');
96
+ const agentType = text(value.agentType, 'resolvedRole.agentType', 64);
97
+ const role = decodeRoles({
98
+ version: 1,
99
+ roles: { resolved: Object.fromEntries(Object.entries(value).filter(([field]) => field !== 'agentType')) }
100
+ }).roles.resolved;
101
+ return { ...role, agentType };
102
+ }
103
+ function requireStageFields(job) {
104
+ if (['configuring', 'sending', 'running', 'returning', 'returned'].includes(job.status) && !job.childSessionId) {
105
+ throw new Error(`${job.status} requires childSessionId`);
106
+ }
107
+ if (job.status === 'sending' && !job.handoff)
108
+ throw new Error('sending requires handoff');
109
+ if (['running', 'returning', 'returned'].includes(job.status) && job.sentRowid === undefined) {
110
+ throw new Error(`${job.status} requires sentRowid`);
111
+ }
112
+ if (['returning', 'returned'].includes(job.status) && !job.outcome) {
113
+ throw new Error(`${job.status} requires outcome`);
114
+ }
115
+ if (job.returnCursor !== undefined && (!job.returnAttachment || !job.returnText)) {
116
+ throw new Error('a dispatched return requires returnAttachment and returnText');
117
+ }
118
+ if (job.status === 'returned' && job.returnRowid === undefined)
119
+ throw new Error('returned requires returnRowid');
120
+ if (job.status === 'failed' && !job.failure)
121
+ throw new Error('failed requires failure');
122
+ }
123
+ export function decodeDelegation(raw) {
124
+ const value = object(raw);
125
+ if (!value)
126
+ throw new Error('delegation must be an object');
127
+ if (value.version !== 1)
128
+ throw new Error(`unsupported delegation version ${String(value.version)}`);
129
+ const id = text(value.id, 'id', 128);
130
+ if (!SAFE_ID.test(id))
131
+ throw new Error('id is invalid');
132
+ const status = value.status;
133
+ if (!STATUSES.has(status))
134
+ throw new Error('status is invalid');
135
+ const returnMode = value.returnMode;
136
+ if (returnMode !== 'queue' && returnMode !== 'steer')
137
+ throw new Error('returnMode is invalid');
138
+ if (typeof value.includeThinking !== 'boolean')
139
+ throw new Error('includeThinking is invalid');
140
+ const job = {
141
+ version: 1,
142
+ id,
143
+ workspaceId: text(value.workspaceId, 'workspaceId'),
144
+ parentSessionId: text(value.parentSessionId, 'parentSessionId'),
145
+ ...(value.childSessionId === undefined ? {} : { childSessionId: text(value.childSessionId, 'childSessionId') }),
146
+ role: text(value.role, 'role', 64),
147
+ resolvedRole: decodeResolvedRole(value.resolvedRole),
148
+ prompt: text(value.prompt, 'prompt', MAX_TEXT),
149
+ returnMode,
150
+ includeThinking: value.includeThinking,
151
+ ...(value.throughRowid === undefined ? {} : { throughRowid: integer(value.throughRowid, 'throughRowid', 1) }),
152
+ status,
153
+ attempts: integer(value.attempts, 'attempts'),
154
+ createdAt: integer(value.createdAt, 'createdAt'),
155
+ updatedAt: integer(value.updatedAt, 'updatedAt'),
156
+ ...(value.handoff === undefined ? {} : { handoff: decodeAttachment(value.handoff) }),
157
+ ...(value.sentRowid === undefined ? {} : { sentRowid: integer(value.sentRowid, 'sentRowid', 1) }),
158
+ ...(value.completionRowid === undefined
159
+ ? {}
160
+ : { completionRowid: integer(value.completionRowid, 'completionRowid', 1) }),
161
+ ...(value.returnCursor === undefined ? {} : { returnCursor: integer(value.returnCursor, 'returnCursor') }),
162
+ ...(value.returnAttachment === undefined ? {} : { returnAttachment: decodeAttachment(value.returnAttachment) }),
163
+ ...(value.returnText === undefined ? {} : { returnText: text(value.returnText, 'returnText', MAX_TEXT) }),
164
+ ...(value.returnRowid === undefined ? {} : { returnRowid: integer(value.returnRowid, 'returnRowid', 1) }),
165
+ ...(value.outcome === undefined ? {} : { outcome: decodeOutcome(value.outcome) }),
166
+ ...(value.failure === undefined ? {} : { failure: decodeError(value.failure, 'failure') }),
167
+ ...(value.lastAttemptAt === undefined ? {} : { lastAttemptAt: integer(value.lastAttemptAt, 'lastAttemptAt') })
168
+ };
169
+ requireStageFields(job);
170
+ return job;
171
+ }
172
+ export function decodeSessionRoles(raw) {
173
+ const value = object(raw);
174
+ if (!value)
175
+ throw new Error('session roles must be an object');
176
+ if (value.version !== 1)
177
+ throw new Error(`unsupported session roles version ${String(value.version)}`);
178
+ const sessions = object(value.sessions);
179
+ if (!sessions)
180
+ throw new Error('sessions must be an object');
181
+ const decoded = {};
182
+ for (const [sessionId, rawAssignment] of Object.entries(sessions)) {
183
+ text(sessionId, 'session id');
184
+ const assignment = object(rawAssignment);
185
+ if (!assignment)
186
+ throw new Error(`session ${sessionId} role is invalid`);
187
+ const delegationId = assignment.delegationId;
188
+ if (delegationId !== undefined && (typeof delegationId !== 'string' || !SAFE_ID.test(delegationId))) {
189
+ throw new Error(`session ${sessionId} delegationId is invalid`);
190
+ }
191
+ decoded[sessionId] = {
192
+ role: text(assignment.role, `session ${sessionId} role`, 64),
193
+ ...(delegationId === undefined ? {} : { delegationId }),
194
+ ...(assignment.parentSessionId === undefined
195
+ ? {}
196
+ : { parentSessionId: text(assignment.parentSessionId, `session ${sessionId} parentSessionId`) }),
197
+ assignedAt: integer(assignment.assignedAt, `session ${sessionId} assignedAt`)
198
+ };
199
+ }
200
+ return decoded;
201
+ }
@@ -1,7 +1,7 @@
1
1
  /** Ordinary-chat delegation intake. All validation precedes persistence or UI work. */
2
2
  import { randomUUID } from 'node:crypto';
3
- import { resolveRole } from "./roles.js";
4
- import { transcriptThrough } from "./transcript.js";
3
+ import { resolveRole } from "../../agents/roles.js";
4
+ import { transcriptThrough } from "../../transcript/parser.js";
5
5
  function refused(code, message) {
6
6
  return { ok: false, error: { code, message, retryable: false } };
7
7
  }
@@ -1,4 +1,4 @@
1
- import { attachmentPrompt } from "./attachments.js";
1
+ import { attachmentPrompt } from "../../files/attachments.js";
2
2
  /** Ordinary delegation supplies transport context; the saved role and assignment supply the task. */
3
3
  export function delegatedPrompt(job) {
4
4
  if (!job.handoff)