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
@@ -1,5 +1,5 @@
1
- import { oneLine } from "../speech.js";
2
1
  import { VOICE_INSTRUCTIONS, workspaceVoiceInstructions } from "./prompt.js";
2
+ import { oneLine } from "./speech.js";
3
3
  import { voiceFunctionTools } from "./tools.js";
4
4
  import { voiceTranscription } from "./transcription.js";
5
5
  export { TRANSCRIPTION_MODEL } from "./transcription.js";
@@ -5,9 +5,9 @@
5
5
  * under the names the wire uses, and declares the response envelopes the route
6
6
  * handlers assemble. Three callers read it and none of them may disagree:
7
7
  *
8
- * - `src/server.ts` builds these payloads,
8
+ * - `src/http/routes/` builds these payloads,
9
9
  * - `web/src/lib/types.ts` re-exports the lot for the PWA,
10
- * - `src/mcp-tools.ts` annotates its relay calls with them.
10
+ * - `src/mcp/tools/` annotates its relay calls with them.
11
11
  *
12
12
  * Before this, the phone kept a hand-written mirror of all of it and `mcp-tools.ts`
13
13
  * kept a third copy inline. Nothing enforced the copies — a field renamed in
@@ -0,0 +1,124 @@
1
+ import { CONDUCTOR_HANDLERS, osaError, runCeiling, SEND_ATTEMPT_MS } from "./runner.js";
2
+ import { sidecarAvailable, sidecarSendUserMessage } from "./sidecar.js";
3
+ import { withTargetEnvironment } from "./targeting.js";
4
+ import { exec, uiTurn } from "./ui-lock.js";
5
+ /**
6
+ * The sidecar IPC path — the precise, per-session write. Delivers straight to
7
+ * `sessionId` over Conductor's own dispatch socket (see src/writes/sidecar.ts), so it needs
8
+ * no window focus and the app UI reflects the turn correctly.
9
+ *
10
+ * Opt-in (WRITE_STRATEGY=sidecar) because it speaks a private, versioned IPC and
11
+ * hasn't been validated by an automated live send (that would inject a prompt
12
+ * into a running agent). It is the intended default once you've confirmed it on
13
+ * your setup.
14
+ */
15
+ export class SidecarActuator {
16
+ name = 'sidecar';
17
+ caveat = 'Delivered straight to the target session over Conductor’s dispatch socket — precise per-workspace targeting.';
18
+ precise = true;
19
+ available() {
20
+ return sidecarAvailable();
21
+ }
22
+ /** `deadline` is ignored — the sidecar is one socket write, with no UI to wait on. */
23
+ async send(target, text, options = {}) {
24
+ const sessionId = target.sessionId ?? target.workspace.active_session_id;
25
+ if (!sessionId)
26
+ return { ok: false, strategy: this.name, error: 'no session id to target' };
27
+ try {
28
+ await sidecarSendUserMessage(sessionId, text, options.queue ? 'queue' : 'default');
29
+ return { ok: true, strategy: this.name };
30
+ }
31
+ catch (err) {
32
+ return { ok: false, strategy: this.name, error: err instanceof Error ? err.message : String(err) };
33
+ }
34
+ }
35
+ }
36
+ /**
37
+ * Drives Conductor's real send path via macOS Accessibility (AppleScript): focus
38
+ * the target workspace, paste the prompt, press Enter. Uses whatever model /
39
+ * permission mode the session already has (zero risk of altering the agent),
40
+ * which is why it's the default.
41
+ *
42
+ * Precise targeting comes from opening Conductor's own workspace link first
43
+ * (`conductor://workspace?id=…&session=…`, see `workspaceLink`) and then
44
+ * confirming the pane and the chat tab through Accessibility (see
45
+ * src/writes/applescript/), so the prompt lands in the right session regardless
46
+ * of what was focused. The link is public and id-addressed; the AX reads only
47
+ * check it, and pressing the sidebar row or the command palette remains the
48
+ * fallback for a Conductor that doesn't answer it.
49
+ */
50
+ export class AppleScriptActuator {
51
+ name = 'applescript';
52
+ caveat = "Opens the target workspace's own Conductor link, then confirms the chat tab before sending.";
53
+ precise = true;
54
+ async send(target, text, options = {}) {
55
+ const deadline = options.deadline ?? Date.now() + SEND_ATTEMPT_MS;
56
+ // Open the target workspace's own link, confirm its chat tab, fill the composer, send.
57
+ // Filling is an Accessibility write (no keystrokes, no clipboard); the
58
+ // clipboard paste is kept only as a fallback, and stashes/restores around it.
59
+ //
60
+ // The send is then read back rather than assumed (`submitComposer`): Conductor
61
+ // consumes the draft when it takes a prompt, so a composer that still holds the
62
+ // text is an Enter that went nowhere, and pressing again inside this run costs
63
+ // under a second. Left to `deliverPrompt` the same failure costs the 6s confirm
64
+ // window plus a whole second run, which is the ~10s of prompt-sitting-on-screen
65
+ // this Mac's logs recorded. A composer that survives three presses is stuck on
66
+ // something the script can't see, so it errors and lets that retry take over.
67
+ const script = `
68
+ ${CONDUCTOR_HANDLERS}
69
+
70
+ my activateConductor()
71
+ my focusWorkspace()
72
+ my selectChatTab()
73
+ set promptText to my normalizeNewlines(do shell script "cat" & " " & quoted form of (system attribute "RELAY_PROMPT_FILE"))
74
+ set textBox to my composerField()
75
+ if not (my fillComposer(textBox, promptText)) then
76
+ set savedClipboard to the clipboard
77
+ my pasteComposer()
78
+ delay 0.1
79
+ set the clipboard to savedClipboard
80
+ end if
81
+ set presses to my submitComposer(textBox, promptText, (system attribute "RELAY_QUEUE_PROMPT") is "1")
82
+ if presses is 0 then error "Conductor ignored Enter - the prompt is still sitting in its composer"
83
+ return "presses:" & presses
84
+ `.trim();
85
+ // Pass the prompt via a temp file + env to avoid AppleScript string escaping.
86
+ const os = await import('node:os');
87
+ const fs = await import('node:fs/promises');
88
+ const path = await import('node:path');
89
+ const tmp = path.join(os.tmpdir(), `relay-prompt-${process.pid}-${Date.now()}.txt`);
90
+ await fs.writeFile(tmp, text, 'utf8');
91
+ try {
92
+ const { stdout } = await withTargetEnvironment(target, targetEnvironment => uiTurn(() => exec('osascript', ['-e', script], {
93
+ env: {
94
+ ...process.env,
95
+ RELAY_PROMPT_FILE: tmp,
96
+ RELAY_QUEUE_PROMPT: options.queue ? '1' : '',
97
+ ...targetEnvironment
98
+ },
99
+ timeout: runCeiling(deadline)
100
+ })));
101
+ // A rescued send is otherwise indistinguishable from one that worked first
102
+ // time, so the failure would leave the log whether it was fixed or hidden.
103
+ const presses = Number(stdout.match(/presses:(\d+)/)?.[1] ?? 1);
104
+ if (presses > 1) {
105
+ console.warn(`[relay] Conductor ignored Enter — the composer cleared on press ${presses}`);
106
+ }
107
+ return { ok: true, strategy: this.name };
108
+ }
109
+ catch (err) {
110
+ return { ok: false, strategy: this.name, error: osaError(err) };
111
+ }
112
+ finally {
113
+ await fs.rm(tmp, { force: true }).catch(() => undefined);
114
+ }
115
+ }
116
+ }
117
+ export function pickActuator(strategy) {
118
+ return strategy === 'sidecar' ? new SidecarActuator() : new AppleScriptActuator();
119
+ }
120
+ /** Effective actuator description for the UI, factoring in runtime availability. */
121
+ export async function describeActuator(actuator) {
122
+ const available = actuator.available ? await actuator.available().catch(() => false) : true;
123
+ return { name: actuator.name, caveat: actuator.caveat, precise: actuator.precise, available };
124
+ }
@@ -0,0 +1,151 @@
1
+ import { modelPickerLabel } from "../shared.js";
2
+ import { CONDUCTOR_HANDLERS, osaError, SEND_ATTEMPT_MS } from "./runner.js";
3
+ import { withTargetEnvironment } from "./targeting.js";
4
+ import { exec, uiTurn } from "./ui-lock.js";
5
+ /**
6
+ * Conductor stores the effort level in a provider-specific session column
7
+ * (`codex_thinking_level` or `claude_effort_level`), normalized by Reads onto the
8
+ * relay's stable wire field. The composer button is labelled with the human name
9
+ * and *cycles* through these values, so both directions are needed: the label to
10
+ * press toward, and the normalized DB value to confirm against.
11
+ */
12
+ export const EFFORT_LABELS = {
13
+ none: 'None',
14
+ low: 'Low',
15
+ medium: 'Medium',
16
+ high: 'High',
17
+ xhigh: 'Extra high',
18
+ max: 'Max',
19
+ ultracode: 'Ultracode'
20
+ };
21
+ const CODEX_EFFORT_LABELS = {
22
+ none: '__UNNAMED_EFFORT__',
23
+ low: 'Light',
24
+ medium: 'Medium',
25
+ high: 'High',
26
+ xhigh: 'Extra high',
27
+ max: 'Max',
28
+ ultracode: 'Ultra'
29
+ };
30
+ /** Translate the stable wire value to the provider's measured composer label. */
31
+ export function effortUiLabel(effort, agentType) {
32
+ if (agentType === 'codex')
33
+ return CODEX_EFFORT_LABELS[effort];
34
+ if (agentType === 'claude' && effort !== 'none')
35
+ return EFFORT_LABELS[effort];
36
+ return undefined;
37
+ }
38
+ /**
39
+ * A boolean patch says what state the caller wants, not that the matching UI
40
+ * control must be pressed. Avoid looking for Plan when Conductor already records
41
+ * the requested mode — some models do not render that control at all when it is
42
+ * off. Unknown state remains fail-closed and is sent through to the actuator.
43
+ */
44
+ export function planSettingForUi(wanted, currentPermissionMode) {
45
+ if (wanted === undefined)
46
+ return undefined;
47
+ return currentPermissionMode === (wanted ? 'plan' : 'default') ? undefined : wanted;
48
+ }
49
+ /**
50
+ * Apply agent settings to a specific chat: focus its workspace and tab (same
51
+ * verified path as a send), then drive the composer's own controls. Every step
52
+ * confirms the control landed on the requested value and errors out otherwise,
53
+ * so a half-applied change is reported rather than assumed.
54
+ */
55
+ export async function setAgentOptions(target, opts) {
56
+ if (opts.effort && !effortUiLabel(opts.effort, opts.agentType)) {
57
+ return { ok: false, strategy: 'applescript', error: `unknown effort level ${opts.effort}` };
58
+ }
59
+ const script = `
60
+ ${CONDUCTOR_HANDLERS}
61
+
62
+ my activateConductor()
63
+ my focusWorkspace()
64
+ my selectChatTab()
65
+ my applyAgentOptions()
66
+ return "ok"`.trim();
67
+ try {
68
+ await withTargetEnvironment(target, targetEnvironment => uiTurn(() => exec('osascript', ['-e', script], {
69
+ env: {
70
+ ...process.env,
71
+ ...targetEnvironment,
72
+ RELAY_SET_EFFORT: opts.effort ? effortUiLabel(opts.effort, opts.agentType) : '',
73
+ RELAY_SET_PLAN: opts.plan === undefined ? '' : opts.plan ? '1' : '0',
74
+ RELAY_SET_FAST: opts.toggleFast ? '1' : '',
75
+ RELAY_SET_MODEL: opts.model ?? ''
76
+ },
77
+ timeout: SEND_ATTEMPT_MS
78
+ })));
79
+ return { ok: true, strategy: 'applescript' };
80
+ }
81
+ catch (err) {
82
+ return { ok: false, strategy: 'applescript', error: osaError(err) };
83
+ }
84
+ }
85
+ /**
86
+ * Star one picker row as Conductor's user-wide default model.
87
+ *
88
+ * The desktop exposes this as a child button named "Set … as default and select",
89
+ * so this deliberately has both effects: it changes the global default and selects
90
+ * that model for `target`. The AppleScript reopens the picker and reads the unique
91
+ * starred row back before this reports success.
92
+ */
93
+ export async function setDefaultModel(target, model) {
94
+ const script = `
95
+ ${CONDUCTOR_HANDLERS}
96
+
97
+ my activateConductor()
98
+ my focusWorkspace()
99
+ my selectChatTab()
100
+ return my setDefaultModel(system attribute "RELAY_DEFAULT_MODEL")`.trim();
101
+ try {
102
+ const { stdout } = await withTargetEnvironment(target, targetEnvironment => uiTurn(() => exec('osascript', ['-e', script], {
103
+ env: { ...process.env, ...targetEnvironment, RELAY_DEFAULT_MODEL: model },
104
+ timeout: SEND_ATTEMPT_MS
105
+ })));
106
+ const selected = modelPickerLabel(stdout.trim());
107
+ if (!selected)
108
+ return { ok: false, strategy: 'applescript', error: 'Conductor returned no default model' };
109
+ return { ok: true, strategy: 'applescript', model: selected };
110
+ }
111
+ catch (err) {
112
+ return { ok: false, strategy: 'applescript', error: osaError(err) };
113
+ }
114
+ }
115
+ const DEFAULT_MODEL_LINE = '__CONDUCTOR_DEFAULT_MODEL__\t';
116
+ /** Turn listModels' tagged line protocol into the live picker state. Exported for its parser tests. */
117
+ export function parseModelMenuOutput(stdout) {
118
+ let defaultModel;
119
+ const models = [];
120
+ for (const raw of stdout.split('\n')) {
121
+ const line = raw.trim();
122
+ if (!line)
123
+ continue;
124
+ if (line.startsWith(DEFAULT_MODEL_LINE)) {
125
+ defaultModel = modelPickerLabel(line.slice(DEFAULT_MODEL_LINE.length).trim()) || undefined;
126
+ continue;
127
+ }
128
+ models.push(modelPickerLabel(line));
129
+ }
130
+ return { models: [...new Set(models.filter(Boolean))], defaultModel };
131
+ }
132
+ /** The model labels Conductor is currently offering, plus its starred default. */
133
+ export async function listAgentModels(target) {
134
+ const script = `
135
+ ${CONDUCTOR_HANDLERS}
136
+
137
+ my activateConductor()
138
+ my focusWorkspace()
139
+ my selectChatTab()
140
+ return my listModels()`.trim();
141
+ try {
142
+ const { stdout } = await withTargetEnvironment(target, targetEnvironment => uiTurn(() => exec('osascript', ['-e', script], {
143
+ env: { ...process.env, ...targetEnvironment },
144
+ timeout: SEND_ATTEMPT_MS
145
+ })));
146
+ return { ok: true, ...parseModelMenuOutput(stdout) };
147
+ }
148
+ catch (err) {
149
+ return { ok: false, error: osaError(err) };
150
+ }
151
+ }
@@ -0,0 +1,334 @@
1
+
2
+ on composerControls()
3
+ set strips to my tabGroups()
4
+ if (count of strips) is 0 then error "couldn't find the composer"
5
+ tell application "System Events" to tell process "Conductor"
6
+ set pane to value of attribute "AXParent" of (item 1 of strips)
7
+ set composerBox to item 1 of (UI elements of pane whose name is "composer")
8
+ set out to {}
9
+ repeat with e in (UI elements of composerBox)
10
+ set end of out to contents of e
11
+ repeat with e2 in (UI elements of e)
12
+ set end of out to contents of e2
13
+ end repeat
14
+ end repeat
15
+ return out
16
+ end tell
17
+ end composerControls
18
+
19
+ on controlNamed(wanted)
20
+ repeat with entry in my composerControls()
21
+ set c to contents of entry
22
+ if my tabLabel(c) is wanted then return c
23
+ end repeat
24
+ return missing value
25
+ end controlNamed
26
+
27
+ on effortButton()
28
+ -- The effort control is a button whose *label is its current value*, so it is
29
+ -- identified by that label rather than a stable name. Claude calls its top
30
+ -- level Ultracode while Codex calls the corresponding level Ultra. Codex's
31
+ -- None state is the exception: its button has no accessible name at all, so
32
+ -- accept one (and only one) unnamed button *after* the proven model picker.
33
+ -- The main composer also contains unnamed attachment/stop buttons before that
34
+ -- picker, and pressing one of those would be worse than failing.
35
+ set levels to {"Light", "Low", "Medium", "High", "Extra high", "Max", "Ultracode", "Ultra"}
36
+ set sawModel to false
37
+ set unnamed to {}
38
+ repeat with entry in my composerControls()
39
+ set c to contents of entry
40
+ if (my axRole(c)) is "AXPopUpButton" and (my axName(c)) contains "Change agent" then
41
+ set sawModel to true
42
+ else if sawModel and (my axRole(c)) is "AXButton" then
43
+ set label to my axName(c)
44
+ if label is in levels then return c
45
+ if label is "" then set end of unnamed to c
46
+ end if
47
+ end repeat
48
+ if (count of unnamed) is 1 then return item 1 of unnamed
49
+ return missing value
50
+ end effortButton
51
+
52
+ on setEffort(wanted)
53
+ -- Claude owns a six-value ring ending in Ultracode; Codex adds None and ends
54
+ -- in Ultra. Step around either ring once and confirm the label landed.
55
+ set btn to my effortButton()
56
+ if btn is missing value then error "couldn't find the effort control"
57
+ repeat 8 times
58
+ set currentLabel to my axName(btn)
59
+ if currentLabel is wanted or (wanted is "__UNNAMED_EFFORT__" and currentLabel is "") then return
60
+ tell application "System Events" to tell process "Conductor"
61
+ perform action "AXPress" of btn
62
+ end tell
63
+ delay 0.35
64
+ set btn to my effortButton()
65
+ if btn is missing value then error "the effort control vanished mid-cycle"
66
+ end repeat
67
+ error "couldn't set effort to " & wanted
68
+ end setEffort
69
+
70
+ on setPlan(wanted)
71
+ set box to my controlNamed("Plan")
72
+ if box is missing value then error "couldn't find the Plan toggle"
73
+ tell application "System Events" to tell process "Conductor"
74
+ set current to ((value of box) as text)
75
+ if (wanted is "1" and current is "0") or (wanted is "0" and current is not "0") then
76
+ perform action "AXPress" of box
77
+ delay 0.4
78
+ if ((value of box) as text) is current then error "the Plan toggle didn't change"
79
+ end if
80
+ end tell
81
+ end setPlan
82
+
83
+ on pressFast()
84
+ -- Fast has no AX state to read (its label is always "Fast"), so the caller
85
+ -- decides whether a press is needed and re-checks the DB afterwards.
86
+ set btn to my controlNamed("Fast")
87
+ if btn is missing value then error "this model has no Fast toggle"
88
+ tell application "System Events" to tell process "Conductor"
89
+ perform action "AXPress" of btn
90
+ end tell
91
+ delay 0.4
92
+ end pressFast
93
+
94
+ on firstLine(s)
95
+ set saved to AppleScript's text item delimiters
96
+ set AppleScript's text item delimiters to linefeed
97
+ set parts to text items of s
98
+ set AppleScript's text item delimiters to saved
99
+ return item 1 of parts
100
+ end firstLine
101
+
102
+ on pickerShowsModel(popup, wanted)
103
+ set pickerLabel to my tabLabel(popup)
104
+ if pickerLabel contains ("(" & wanted & ")") then return true
105
+ -- The menu can label a newly released model "Opus 5 NEW", while the
106
+ -- composer deliberately drops that temporary badge and says "Opus 5".
107
+ -- Treat that exact display form as the same choice; the surrounding
108
+ -- parentheses keep "Opus 5" distinct from a longer model name.
109
+ if wanted ends with " NEW" then
110
+ set baseName to text 1 thru -5 of wanted
111
+ if pickerLabel contains ("(" & baseName & ")") then return true
112
+ end if
113
+ return false
114
+ end pickerShowsModel
115
+
116
+ on modelMenuItem(wanted)
117
+ -- Resolve one model from the picker that is already open. The menu can append
118
+ -- `NEW` to a freshly released model while the relay deliberately exposes the
119
+ -- stable name without it, so the same unique-prefix rule as setModel applies.
120
+ set chosen to missing value
121
+ set loose to {}
122
+ set wa to my webArea()
123
+ tell application "System Events" to tell process "Conductor"
124
+ repeat with m in (get UI elements of wa whose role is "AXMenu")
125
+ repeat with mi in (get UI elements of m whose role is "AXMenuItem")
126
+ set label to my firstLine(my tabLabel(mi))
127
+ if label is wanted then
128
+ set chosen to contents of mi
129
+ else if label starts with wanted then
130
+ set end of loose to contents of mi
131
+ end if
132
+ end repeat
133
+ end repeat
134
+ end tell
135
+ if chosen is missing value and (count of loose) is 1 then set chosen to item 1 of loose
136
+ if chosen is missing value then
137
+ if (count of loose) > 1 then error "several models match " & wanted
138
+ error "no model named " & wanted
139
+ end if
140
+ return chosen
141
+ end modelMenuItem
142
+
143
+ on modelDefaultButton(menuItem)
144
+ -- Every non-default row has a child star button named "Set <model> as
145
+ -- default and select". The starred row has no button at all. Read the role and
146
+ -- label together so an unrelated control a future picker grows cannot be
147
+ -- mistaken for a global preference write.
148
+ repeat with childNode in my axKids(menuItem)
149
+ set childEl to contents of childNode
150
+ if (my axRole(childEl)) is "AXButton" and (my axName(childEl)) contains " as default" then return childEl
151
+ end repeat
152
+ return missing value
153
+ end modelDefaultButton
154
+
155
+ on modelMenuItems()
156
+ set found to {}
157
+ set wa to my webArea()
158
+ tell application "System Events" to tell process "Conductor"
159
+ repeat with m in (get UI elements of wa whose role is "AXMenu")
160
+ set found to found & (get UI elements of m whose role is "AXMenuItem")
161
+ end repeat
162
+ end tell
163
+ return found
164
+ end modelMenuItems
165
+
166
+ on defaultModelInOpenPicker()
167
+ -- The selected star is exposed by *removing* the star button from that row.
168
+ -- Require exactly one such row. If managed settings disable every star, or a
169
+ -- Conductor release changes this tree, failing closed is safer than reporting
170
+ -- that whichever model was requested became the user's global default.
171
+ set defaults to {}
172
+ repeat with mi in my modelMenuItems()
173
+ set menuItem to contents of mi
174
+ if (my modelDefaultButton(menuItem)) is missing value then set end of defaults to my firstLine(my tabLabel(menuItem))
175
+ end repeat
176
+ if (count of defaults) is not 1 then error "couldn't identify Conductor's default model"
177
+ return item 1 of defaults
178
+ end defaultModelInOpenPicker
179
+
180
+ on modelPickerButton()
181
+ set popup to missing value
182
+ repeat with entry in my composerControls()
183
+ set c to contents of entry
184
+ if my tabLabel(c) contains "Change agent" then set popup to c
185
+ end repeat
186
+ if popup is missing value then error "couldn't find the model picker"
187
+ return popup
188
+ end modelPickerButton
189
+
190
+ on openModelPicker()
191
+ set popup to my modelPickerButton()
192
+ tell application "System Events" to tell process "Conductor"
193
+ perform action "AXPress" of popup
194
+ end tell
195
+ delay 1.0
196
+ end openModelPicker
197
+
198
+ on setDefaultModel(wanted)
199
+ -- Conductor's star is one combined action: its accessible name is "Set … as
200
+ -- default and select". Mirror that rather than pretending this only changes a
201
+ -- preference — the target chat switches model too, and the picker label is
202
+ -- read back below as the receipt for that half.
203
+ set initialPopup to my modelPickerButton()
204
+ set alreadySelected to my pickerShowsModel(initialPopup, wanted)
205
+ tell application "System Events" to tell process "Conductor"
206
+ perform action "AXPress" of initialPopup
207
+ end tell
208
+ delay 1.0
209
+ try
210
+ set chosen to my modelMenuItem(wanted)
211
+ set chosenLabel to my firstLine(my tabLabel(chosen))
212
+ set currentDefault to my defaultModelInOpenPicker()
213
+ if currentDefault is chosenLabel then
214
+ if alreadySelected then
215
+ tell application "System Events" to key code 53
216
+ return chosenLabel
217
+ end if
218
+ -- The star is already selected, but this chat is not. Its row is now
219
+ -- the remaining half of Conductor's combined action.
220
+ tell application "System Events" to tell process "Conductor"
221
+ perform action "AXPress" of chosen
222
+ end tell
223
+ delay 0.8
224
+ set selectedPopup to my modelPickerButton()
225
+ if not my pickerShowsModel(selectedPopup, chosenLabel) then error "the model didn't switch to " & chosenLabel
226
+ return chosenLabel
227
+ end if
228
+ set starButton to my modelDefaultButton(chosen)
229
+ if starButton is missing value then error "the default-model star is missing for " & chosenLabel
230
+ tell application "System Events" to tell process "Conductor"
231
+ perform action "AXPress" of starButton
232
+ end tell
233
+ delay 0.8
234
+ set selectedPopup to my modelPickerButton()
235
+ if not my pickerShowsModel(selectedPopup, chosenLabel) then error "the model didn't switch to " & chosenLabel
236
+ -- Re-open and read the star back. Pressing is fire-and-forget; the only safe
237
+ -- success is the requested row becoming the unique one with no star button.
238
+ my openModelPicker()
239
+ set verified to my modelMenuItem(wanted)
240
+ set verifiedLabel to my firstLine(my tabLabel(verified))
241
+ set currentDefault to my defaultModelInOpenPicker()
242
+ tell application "System Events" to key code 53
243
+ if currentDefault is not verifiedLabel then error "Conductor didn't mark " & verifiedLabel & " as the default model"
244
+ return verifiedLabel
245
+ on error errText number errNum
246
+ tell application "System Events" to key code 53
247
+ error errText number errNum
248
+ end try
249
+ end setDefaultModel
250
+
251
+ on setModel(wanted)
252
+ set popup to missing value
253
+ repeat with entry in my composerControls()
254
+ set c to contents of entry
255
+ if my tabLabel(c) contains "Change agent" then set popup to c
256
+ end repeat
257
+ if popup is missing value then error "couldn't find the model picker"
258
+ if my pickerShowsModel(popup, wanted) then return
259
+ tell application "System Events" to tell process "Conductor"
260
+ perform action "AXPress" of popup
261
+ end tell
262
+ delay 1.0
263
+ -- The relay removes a temporary `NEW` badge before it sends this label back,
264
+ -- so a prefix match resolves that menu item. It is accepted only when unique:
265
+ -- "Sonnet 4.6" would
266
+ -- otherwise also match "Sonnet 4.6 1M"), which must fail rather than guess.
267
+ set chosen to missing value
268
+ set loose to {}
269
+ set wa to my webArea()
270
+ tell application "System Events" to tell process "Conductor"
271
+ repeat with m in (get UI elements of wa whose role is "AXMenu")
272
+ repeat with mi in (get UI elements of m whose role is "AXMenuItem")
273
+ set label to my firstLine(my tabLabel(mi))
274
+ if label is wanted then
275
+ set chosen to contents of mi
276
+ else if label starts with wanted then
277
+ set end of loose to contents of mi
278
+ end if
279
+ end repeat
280
+ end repeat
281
+ end tell
282
+ if chosen is missing value and (count of loose) is 1 then set chosen to item 1 of loose
283
+ if chosen is missing value then
284
+ tell application "System Events" to key code 53
285
+ if (count of loose) > 1 then error "several models match " & wanted
286
+ error "no model named " & wanted
287
+ end if
288
+ set chosenLabel to my firstLine(my tabLabel(chosen))
289
+ tell application "System Events" to tell process "Conductor"
290
+ perform action "AXPress" of chosen
291
+ end tell
292
+ delay 0.8
293
+ set popup to missing value
294
+ repeat with entry in my composerControls()
295
+ set c to contents of entry
296
+ if my tabLabel(c) contains "Change agent" then set popup to c
297
+ end repeat
298
+ if popup is missing value then error "the model picker vanished"
299
+ if not my pickerShowsModel(popup, chosenLabel) then error "the model didn't switch to " & chosenLabel
300
+ end setModel
301
+
302
+ on listModels()
303
+ -- Enumerate the picker rather than hard-coding a model list that would rot on
304
+ -- every Conductor release. The first tagged line carries the unique starred
305
+ -- row, followed by the ordinary labels. Opens the menu, reads, closes it again.
306
+ my openModelPicker()
307
+ try
308
+ set labels to {}
309
+ repeat with mi in my modelMenuItems()
310
+ set end of labels to my firstLine(my tabLabel(mi))
311
+ end repeat
312
+ set defaultLabel to my defaultModelInOpenPicker()
313
+ tell application "System Events" to key code 53
314
+ set saved to AppleScript's text item delimiters
315
+ set AppleScript's text item delimiters to linefeed
316
+ set joined to labels as text
317
+ set AppleScript's text item delimiters to saved
318
+ return "__CONDUCTOR_DEFAULT_MODEL__" & tab & defaultLabel & linefeed & joined
319
+ on error errText number errNum
320
+ tell application "System Events" to key code 53
321
+ error errText number errNum
322
+ end try
323
+ end listModels
324
+
325
+ on applyAgentOptions()
326
+ set wantEffort to system attribute "RELAY_SET_EFFORT"
327
+ set wantPlan to system attribute "RELAY_SET_PLAN"
328
+ set wantFast to system attribute "RELAY_SET_FAST"
329
+ set wantModel to system attribute "RELAY_SET_MODEL"
330
+ if wantModel is not "" then my setModel(wantModel)
331
+ if wantEffort is not "" then my setEffort(wantEffort)
332
+ if wantPlan is not "" then my setPlan(wantPlan)
333
+ if wantFast is "1" then my pressFast()
334
+ end applyAgentOptions