@zergai/ztc 0.26.6-dev.202611240947 → 0.27.0-beta.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 (268) hide show
  1. package/README.md +629 -167
  2. package/RUST_THIRD_PARTY_LICENSES.txt +5 -5
  3. package/bin/zmux-darwin-arm64 +0 -0
  4. package/bin/zmux-linux-x64 +0 -0
  5. package/bin/ztc-audio-darwin-arm64 +0 -0
  6. package/bin/ztc-capture-darwin-arm64 +0 -0
  7. package/bin/ztc-computer-darwin-arm64 +0 -0
  8. package/bin/ztc-llm-darwin-arm64 +0 -0
  9. package/bin/ztc-tts-darwin-arm64 +0 -0
  10. package/bin/ztc-tui-darwin-arm64 +0 -0
  11. package/bin/ztc-tui-linux-x64 +0 -0
  12. package/bin/zterm-darwin-arm64 +2 -2
  13. package/dist/App.js +6 -1
  14. package/dist/agent/agent.d.ts +21 -15
  15. package/dist/agent/agent.js +389 -163
  16. package/dist/agent/backends/codex_app_server.d.ts +7 -1
  17. package/dist/agent/backends/codex_app_server.js +11 -1
  18. package/dist/agent/backends/gemini.js +22 -8
  19. package/dist/agent/commands/batch.js +8 -0
  20. package/dist/agent/commands/config.js +10 -0
  21. package/dist/agent/commands/environment.js +5 -5
  22. package/dist/agent/commands/goal.d.ts +1 -0
  23. package/dist/agent/commands/goal.js +2 -1
  24. package/dist/agent/commands/index.js +2 -1
  25. package/dist/agent/commands/manifest.js +4 -0
  26. package/dist/agent/commands/optimize.js +5 -2
  27. package/dist/agent/commands/pane_cli.d.ts +29 -0
  28. package/dist/agent/commands/pane_cli.js +303 -0
  29. package/dist/agent/commands/settings.js +13 -3
  30. package/dist/agent/commands/shannon.js +8 -0
  31. package/dist/agent/commands/update.js +15 -3
  32. package/dist/agent/commands/zerg.js +31 -1
  33. package/dist/agent/commands/ztc_pane.js +3 -1
  34. package/dist/agent/factory.d.ts +4 -0
  35. package/dist/agent/factory.js +11 -1
  36. package/dist/agent/loop_policy.d.ts +42 -5
  37. package/dist/agent/loop_policy.js +206 -3
  38. package/dist/agent/runtime/command_jobs.d.ts +5 -0
  39. package/dist/agent/runtime/command_jobs.js +241 -31
  40. package/dist/agent/runtime/command_wait.d.ts +2 -0
  41. package/dist/agent/runtime/command_wait.js +1 -0
  42. package/dist/agent/runtime/done_report.d.ts +18 -0
  43. package/dist/agent/runtime/done_report.js +130 -0
  44. package/dist/agent/runtime/execution_context.js +4 -1
  45. package/dist/agent/runtime/failure_cause.d.ts +2 -0
  46. package/dist/agent/runtime/failure_cause.js +35 -0
  47. package/dist/agent/runtime/policy.d.ts +14 -2
  48. package/dist/agent/runtime/policy.js +104 -12
  49. package/dist/agent/runtime/quiet_job.d.ts +18 -0
  50. package/dist/agent/runtime/quiet_job.js +48 -0
  51. package/dist/agent/runtime/recovery.d.ts +1 -5
  52. package/dist/agent/runtime/recovery.js +2 -44
  53. package/dist/agent/runtime/tool_runtime.d.ts +1 -0
  54. package/dist/agent/runtime/tool_runtime.js +2 -0
  55. package/dist/agent/subagent.js +6 -1
  56. package/dist/agent/tools/deferred.js +1 -0
  57. package/dist/agent/tools/index.d.ts +2 -0
  58. package/dist/agent/tools/index.js +1 -0
  59. package/dist/agent/tools/outcome.d.ts +15 -0
  60. package/dist/agent/tools/outcome.js +107 -0
  61. package/dist/agent/tools/pane.d.ts +2 -1
  62. package/dist/agent/tools/pane.js +21 -3
  63. package/dist/agent/tools/registry.js +2 -0
  64. package/dist/agent/tools/shell.d.ts +1 -0
  65. package/dist/agent/tools/shell.js +128 -17
  66. package/dist/agent/tools/sim_domain_tools.js +4 -2
  67. package/dist/agent/tools/supervision.js +4 -2
  68. package/dist/agent/tools/types.d.ts +3 -0
  69. package/dist/app/command_context.js +5 -9
  70. package/dist/app/conversation_compaction.d.ts +4 -2
  71. package/dist/app/conversation_compaction.js +16 -5
  72. package/dist/app/headless_shell_mode.d.ts +14 -0
  73. package/dist/app/headless_shell_mode.js +7 -0
  74. package/dist/app/hosted_resident.d.ts +356 -0
  75. package/dist/app/hosted_resident.js +677 -0
  76. package/dist/app/restart.js +11 -2
  77. package/dist/app/session_manager.d.ts +5 -0
  78. package/dist/app/session_manager.js +21 -6
  79. package/dist/app/session_messages.js +6 -6
  80. package/dist/app/workspace_layout_controller.js +7 -0
  81. package/dist/batch/worktree.d.ts +10 -0
  82. package/dist/batch/worktree.js +15 -0
  83. package/dist/bench/registry.js +4 -2
  84. package/dist/cli_args.js +1 -1
  85. package/dist/cli_main.js +80 -10
  86. package/dist/cli_ratatui.d.ts +75 -0
  87. package/dist/cli_ratatui.js +485 -84
  88. package/dist/components/InputArea.js +4 -4
  89. package/dist/config/execution.d.ts +10 -0
  90. package/dist/config/execution.js +10 -0
  91. package/dist/config/hosted_runtime.d.ts +4 -1
  92. package/dist/config/hosted_runtime.js +4 -1
  93. package/dist/config/permission_pin.d.ts +34 -2
  94. package/dist/config/permission_pin.js +52 -2
  95. package/dist/config/person_command_policy.d.ts +38 -0
  96. package/dist/config/person_command_policy.js +11 -0
  97. package/dist/config/profiles.d.ts +21 -0
  98. package/dist/config/profiles.js +56 -2
  99. package/dist/config/types.d.ts +4 -1
  100. package/dist/config.js +34 -19
  101. package/dist/desktop/daily/codex_exec_adapter.js +7 -2
  102. package/dist/desktop/daily/desktop_wiring.d.ts +7 -1
  103. package/dist/desktop/daily/desktop_wiring.js +11 -3
  104. package/dist/desktop/daily/recipes.js +20 -4
  105. package/dist/desktop/health.d.ts +24 -0
  106. package/dist/desktop/health.js +151 -0
  107. package/dist/desktop/native_dialogs.d.ts +37 -0
  108. package/dist/desktop/native_dialogs.js +105 -0
  109. package/dist/diagnostics/session_export.d.ts +1 -0
  110. package/dist/diagnostics/session_export.js +28 -0
  111. package/dist/embedded/registry.js +4 -2
  112. package/dist/emulation/tool_adapters.js +9 -4
  113. package/dist/emulation/ztc_addendum.js +3 -0
  114. package/dist/headless.d.ts +11 -4
  115. package/dist/headless.js +99 -34
  116. package/dist/headless_approval.d.ts +6 -0
  117. package/dist/headless_cli.js +1 -1
  118. package/dist/hooks/runner.js +7 -6
  119. package/dist/library.d.ts +4 -0
  120. package/dist/library.js +3 -0
  121. package/dist/mcp/client.js +3 -3
  122. package/dist/modes/registry.js +13 -4
  123. package/dist/onboarding/setup_environment.js +13 -1
  124. package/dist/optimize/adapters/kernelbench.js +88 -10
  125. package/dist/optimize/adapters/types.d.ts +5 -0
  126. package/dist/optimize/executor.js +21 -0
  127. package/dist/panes/cli_install.d.ts +54 -0
  128. package/dist/panes/cli_install.js +157 -0
  129. package/dist/panes/model_catalog.js +3 -0
  130. package/dist/panes/new_pane_choices.d.ts +6 -2
  131. package/dist/panes/new_pane_choices.js +24 -12
  132. package/dist/panes/pane_cli_launch.d.ts +50 -0
  133. package/dist/panes/pane_cli_launch.js +124 -0
  134. package/dist/panes/pane_clis.d.ts +171 -0
  135. package/dist/panes/pane_clis.js +325 -0
  136. package/dist/panes/person_only_panes.d.ts +45 -0
  137. package/dist/panes/person_only_panes.js +117 -0
  138. package/dist/plugin/simulation_living.js +0 -2
  139. package/dist/plugin/simulation_living_engine.d.ts +1 -0
  140. package/dist/plugin/simulation_living_engine.js +1 -0
  141. package/dist/plugin/simulation_living_labels.d.ts +3 -0
  142. package/dist/plugin/simulation_living_labels.js +2 -0
  143. package/dist/router_auth.js +12 -1
  144. package/dist/session.js +26 -1
  145. package/dist/simulation/art/gemini_image.js +11 -5
  146. package/dist/simulation/domains/loader.js +25 -3
  147. package/dist/simulation/living/cold.d.ts +23 -0
  148. package/dist/simulation/living/cold.js +41 -0
  149. package/dist/simulation/living/context.d.ts +591 -1283
  150. package/dist/simulation/living/context.js +378 -244
  151. package/dist/simulation/living/contradictions.d.ts +14 -0
  152. package/dist/simulation/living/contradictions.js +282 -0
  153. package/dist/simulation/living/core/ids.d.ts +53 -0
  154. package/dist/simulation/living/core/ids.js +39 -0
  155. package/dist/simulation/living/core/kind.d.ts +20 -0
  156. package/dist/simulation/living/core/kind.js +15 -0
  157. package/dist/simulation/living/core/laws.d.ts +179 -0
  158. package/dist/simulation/living/core/laws.js +184 -0
  159. package/dist/simulation/living/core/ops.d.ts +257 -0
  160. package/dist/simulation/living/core/ops.js +34 -0
  161. package/dist/simulation/living/definer.d.ts +17 -1
  162. package/dist/simulation/living/definer.js +130 -51
  163. package/dist/simulation/living/definition.d.ts +174 -65
  164. package/dist/simulation/living/definition.js +287 -180
  165. package/dist/simulation/living/director.d.ts +80 -0
  166. package/dist/simulation/living/director.js +363 -0
  167. package/dist/simulation/living/frame.d.ts +108 -21
  168. package/dist/simulation/living/frame.js +111 -66
  169. package/dist/simulation/living/identifiers.d.ts +0 -1
  170. package/dist/simulation/living/identifiers.js +0 -3
  171. package/dist/simulation/living/index.d.ts +18 -9
  172. package/dist/simulation/living/index.js +18 -9
  173. package/dist/simulation/living/inference.d.ts +92 -50
  174. package/dist/simulation/living/inference.js +319 -175
  175. package/dist/simulation/living/knowledge.d.ts +28 -0
  176. package/dist/simulation/living/knowledge.js +73 -0
  177. package/dist/simulation/living/library.json +1177 -0
  178. package/dist/simulation/living/mechanics.d.ts +31 -34
  179. package/dist/simulation/living/mechanics.js +222 -138
  180. package/dist/simulation/living/model-input.d.ts +6 -3
  181. package/dist/simulation/living/model-input.js +18 -26
  182. package/dist/simulation/living/open-world.d.ts +74 -94
  183. package/dist/simulation/living/open-world.js +151 -30
  184. package/dist/simulation/living/phrases.d.ts +3 -0
  185. package/dist/simulation/living/phrases.js +37 -0
  186. package/dist/simulation/living/phrases.json +560 -0
  187. package/dist/simulation/living/projection.d.ts +316 -2
  188. package/dist/simulation/living/projection.js +50 -2
  189. package/dist/simulation/living/prompts/example-spec.json +11 -0
  190. package/dist/simulation/living/prompts/role-text.json +14 -0
  191. package/dist/simulation/living/prompts.d.ts +5 -0
  192. package/dist/simulation/living/prompts.js +275 -0
  193. package/dist/simulation/living/recall.d.ts +2 -2
  194. package/dist/simulation/living/reduce.d.ts +51 -14
  195. package/dist/simulation/living/reduce.js +941 -579
  196. package/dist/simulation/living/replay.d.ts +5 -4
  197. package/dist/simulation/living/replay.js +10 -9
  198. package/dist/simulation/living/runtime.d.ts +135 -25
  199. package/dist/simulation/living/runtime.js +1641 -583
  200. package/dist/simulation/living/scale.d.ts +96 -0
  201. package/dist/simulation/living/scale.js +124 -0
  202. package/dist/simulation/living/script.d.ts +5 -0
  203. package/dist/simulation/living/script.js +115 -0
  204. package/dist/simulation/living/shared-kinds.d.ts +4 -11
  205. package/dist/simulation/living/shared-kinds.js +11 -81
  206. package/dist/simulation/living/space.d.ts +14 -0
  207. package/dist/simulation/living/space.js +132 -0
  208. package/dist/simulation/living/state.d.ts +100 -0
  209. package/dist/simulation/living/state.js +393 -0
  210. package/dist/simulation/living/types.d.ts +829 -512
  211. package/dist/simulation/living/types.js +162 -187
  212. package/dist/simulation/living/world-rules.d.ts +100 -0
  213. package/dist/simulation/living/world-rules.js +267 -0
  214. package/dist/simulation/plugins/loader.js +11 -0
  215. package/dist/skills/loader.js +4 -0
  216. package/dist/tools.d.ts +1 -0
  217. package/dist/tools.js +1 -0
  218. package/dist/ui/ratatui/headless_pane_manager.d.ts +4 -1
  219. package/dist/ui/ratatui/headless_pane_manager.js +13 -9
  220. package/dist/ui/ratatui/pane_relay.js +29 -0
  221. package/dist/ui/ratatui/pane_type.d.ts +10 -0
  222. package/dist/ui/ratatui/pane_type.js +11 -0
  223. package/dist/ui/ratatui/process.d.ts +30 -0
  224. package/dist/ui/ratatui/process.js +133 -19
  225. package/dist/ui/ratatui/protocol.d.ts +124 -2
  226. package/dist/ui/ratatui/protocol.js +35 -0
  227. package/dist/ui/ratatui/relay_policy.js +3 -0
  228. package/dist/ui/ratatui/ztc_launch_trust.d.ts +2 -1
  229. package/dist/ui/ratatui/ztc_launch_trust.js +8 -1
  230. package/dist/ui/terminal_image.d.ts +12 -0
  231. package/dist/ui/terminal_image.js +21 -1
  232. package/dist/utils/codex_project_trust.d.ts +19 -0
  233. package/dist/utils/codex_project_trust.js +37 -0
  234. package/dist/utils/compaction.js +103 -20
  235. package/dist/utils/git_program_files.d.ts +19 -12
  236. package/dist/utils/git_program_files.js +411 -83
  237. package/dist/utils/host_shell.d.ts +10 -1
  238. package/dist/utils/host_shell.js +14 -1
  239. package/dist/utils/mid_turn_compaction.d.ts +2 -0
  240. package/dist/utils/mid_turn_compaction.js +2 -0
  241. package/dist/utils/models.js +6 -1
  242. package/dist/utils/sandbox.d.ts +109 -8
  243. package/dist/utils/sandbox.js +981 -187
  244. package/dist/utils/shell.d.ts +2 -0
  245. package/dist/utils/shell.js +10 -4
  246. package/dist/utils/subprocess_env.d.ts +47 -11
  247. package/dist/utils/subprocess_env.js +107 -15
  248. package/dist/utils/system_ps.d.ts +8 -0
  249. package/dist/utils/system_ps.js +39 -7
  250. package/dist/utils/unattended_compaction.d.ts +9 -0
  251. package/dist/utils/unattended_compaction.js +13 -0
  252. package/dist/utils/ztc_own_state.d.ts +8 -5
  253. package/dist/utils/ztc_own_state.js +17 -11
  254. package/dist/web/mirror_client.js +1 -0
  255. package/dist/web/mirror_stream.d.ts +50 -6
  256. package/dist/web/mirror_stream.js +160 -15
  257. package/dist/workflows/registry.js +3 -1
  258. package/dist/workspace/controller.js +12 -0
  259. package/dist/workspace_collision.d.ts +3 -0
  260. package/dist/workspace_collision.js +14 -1
  261. package/dist/workspace_session_context.js +2 -1
  262. package/dist/zlm-embed.mjs +3823 -1970
  263. package/node_modules/@zerg/model-contracts/README.md +16 -4
  264. package/node_modules/@zerg/model-contracts/index.js +6 -1
  265. package/npm-shrinkwrap.json +1 -1
  266. package/package.json +42 -24
  267. package/packages/model-contracts/README.md +16 -4
  268. package/packages/model-contracts/index.js +6 -1
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Opening a coding-agent CLI other than Claude Code and Codex in a pane (pane_clis.ts: Antigravity, Pi, OpenCode, Gemini
3
+ * CLI, GitHub Copilot CLI, Cursor CLI), as a terminal would: the person's own executable, unmodified, from their login
4
+ * shell, in the folder given, signed in with their own account through its own flow. ZTC adds only what the CLI takes
5
+ * for one run without ZTC editing the person's configuration: Copilot's --additional-mcp-config for ZTC's workspace
6
+ * server. No permission flag of ZTC's is passed: each CLI asks, or doesn't, as its own settings say.
7
+ *
8
+ * A person-only CLI's pane (Antigravity) is noted as it opens (person_only_panes.ts), so that no agent types into it,
9
+ * messages it or restarts it, and it never runs through MotSi, whose remote view another program reads.
10
+ */
11
+ import { randomUUID } from 'node:crypto';
12
+ import { listWorkspacePanes, waitForPaneCreatedOrError } from '../agent/tools/pane.js';
13
+ import { buildUserSubprocessEnvOverrides } from '../utils/subprocess_env.js';
14
+ import { configStore } from '../config.js';
15
+ import { PINNED_PANE_INSTEAD, personProgramRefusal } from '../config/permission_pin.js';
16
+ import { WORKSPACE_MCP_ENV, agentPaneEnv, formatCliArguments, loginShellExec, nextPaneTitle, workspaceMcpProgram } from './agent_cli.js';
17
+ import { parentSessionMarkers } from './agent_panes.js';
18
+ import { sessionNamePaneTitle } from './labels.js';
19
+ import { MOTSI_PANE_ENV, remoteViewMotsi, throughMotsi } from './motsi.js';
20
+ import { PANE_CLIS, agentPaneCliRefusal, findPaneCli, isPaneCliId, isPersonOnlyCli, paneCliArgs, refusedPaneCliWord, } from './pane_clis.js';
21
+ import { notePersonOnlyPane, personOnlyLaunchRefusal } from './person_only_panes.js';
22
+ /** Request ids of these launches start with this; Claude Code's and Codex's start with agent_panes.ts's own. */
23
+ export const CLI_PANE_REQUEST_PREFIX = 'cli-pane:';
24
+ /** Which CLI a create_pane request id launched, if one of these did. */
25
+ export function paneCliFromRequestId(requestId) {
26
+ if (!requestId?.startsWith(CLI_PANE_REQUEST_PREFIX))
27
+ return null;
28
+ const id = requestId.slice(CLI_PANE_REQUEST_PREFIX.length).split(':')[0] ?? '';
29
+ return isPaneCliId(id) ? id : null;
30
+ }
31
+ const NEEDS_PANES = 'needs ZTC\'s panes: start ZTC with zmux (plain `ztc`) or use the desktop app';
32
+ async function existingTitles(transport) {
33
+ const panes = await listWorkspacePanes(transport, 3000);
34
+ return panes instanceof Error ? [] : panes.map(pane => pane.labels?.manual_title || pane.title);
35
+ }
36
+ /** Open the person's own CLI in a new pane. */
37
+ export async function openPaneCli(transport, options) {
38
+ const spec = PANE_CLIS[options.cli];
39
+ if (spec.opens !== 'terminal')
40
+ return { error: `/${spec.command} opens ${spec.label}.` };
41
+ const pinRefusal = personProgramRefusal(`No ${spec.label} pane was opened`, `${spec.label} (${spec.binaries[0]})`, PINNED_PANE_INSTEAD);
42
+ if (pinRefusal)
43
+ return { error: pinRefusal };
44
+ const request = options.request ?? { words: [] };
45
+ const byPerson = options.openedBy === 'person';
46
+ if (!byPerson) {
47
+ const refused = personOnlyLaunchRefusal(options.cli) ?? agentPaneCliRefusal(options.cli, request);
48
+ if (refused)
49
+ return { error: refused };
50
+ }
51
+ const refusedWord = refusedPaneCliWord(options.cli, request.words);
52
+ if (refusedWord)
53
+ return { error: `ZTC doesn't start ${spec.label} with ${refusedWord}: ${spec.refused.why}.` };
54
+ if (!transport || !transport.isMuxMode)
55
+ return { error: `${spec.label} opens in a pane, which ${NEEDS_PANES}.` };
56
+ const env = options.env ?? process.env;
57
+ const binary = (options.findBinary ?? (id => findPaneCli(id, { env, ...(options.cwd ? { cwd: options.cwd } : {}) })))(options.cli);
58
+ if (!binary)
59
+ return { error: `${spec.label} is not installed. Install it from ${spec.setupUrl}, then try again.` };
60
+ const personOnly = isPersonOnlyCli(options.cli);
61
+ // Only a CLI that takes ZTC's workspace server for one run gets it, and the workspace's coordinates with it.
62
+ const server = spec.workspaceMcp === 'copilot' ? (options.server === undefined ? workspaceMcpProgram() : options.server) : null;
63
+ const attached = server && !(server instanceof Error) ? server : null;
64
+ const workspaceEnv = attached ? agentPaneEnv(env) : {};
65
+ // The variables the server reads that the pane will hold: the renderer sets the pane's id; ZTC the rest it has.
66
+ const envNames = attached ? WORKSPACE_MCP_ENV.filter(name => name === 'ZTC_PANE_ID' || Boolean(workspaceEnv[name])) : [];
67
+ const { args, notices } = paneCliArgs(options.cli, request, attached ? { server: attached, envNames } : null);
68
+ const title = options.title?.trim() || nextPaneTitle(spec.label, await existingTitles(transport));
69
+ const motsi = personOnly ? null : options.motsi === undefined ? remoteViewMotsi(configStore.get().panes, { env }) : options.motsi;
70
+ const cleared = parentSessionMarkers(env);
71
+ const program = motsi
72
+ ? loginShellExec(motsi, throughMotsi(motsi, title, { command: binary, args }).args, env.SHELL, process.platform, cleared)
73
+ : loginShellExec(binary, args, env.SHELL, process.platform, cleared);
74
+ const requestId = `${CLI_PANE_REQUEST_PREFIX}${options.cli}:${randomUUID()}`;
75
+ const created = waitForPaneCreatedOrError(transport, { requestId }, 15000);
76
+ const sent = transport.send({
77
+ type: 'create_pane',
78
+ request_id: requestId,
79
+ command: program.command,
80
+ args: program.args,
81
+ ...(options.cwd ? { cwd: options.cwd } : {}),
82
+ title,
83
+ pane_type: 'command',
84
+ ...(options.direction ? { direction: options.direction } : {}),
85
+ ...(options.ratio !== undefined ? { ratio: options.ratio } : {}),
86
+ ...(options.target !== undefined ? { target: options.target } : {}),
87
+ ...(options.newWindow ? { new_window: true } : {}),
88
+ // ZTC's own variables blanked, as for any program of the person's; the workspace's only for a pane with its server.
89
+ env: { ...buildUserSubprocessEnvOverrides(env), ...Object.fromEntries(cleared.map(name => [name, ''])), ...workspaceEnv,
90
+ ...(motsi ? MOTSI_PANE_ENV : {}) },
91
+ });
92
+ if (!sent) {
93
+ created.catch(() => { });
94
+ return { error: `Could not open ${spec.label}: the renderer is not connected.` };
95
+ }
96
+ let event;
97
+ try {
98
+ event = await created;
99
+ }
100
+ catch (error) {
101
+ return { error: `Could not open ${spec.label}: no pane appeared (${error.message}).` };
102
+ }
103
+ if (event.type === 'error')
104
+ return { error: `Could not open ${spec.label}: the renderer refused the pane (${event.message}).` };
105
+ if (event.type !== 'pane_created')
106
+ return { error: `Could not open ${spec.label}: unexpected response from the renderer.` };
107
+ // Before anything else can address the pane: no agent drives a person-only CLI's.
108
+ if (personOnly)
109
+ notePersonOnlyPane(event.pane_id, options.cli);
110
+ transport.send(sessionNamePaneTitle(event.pane_id, title));
111
+ if (spec.workspaceMcp !== null && !attached) {
112
+ const why = server instanceof Error ? server.message : 'none was given';
113
+ notices.push(`${title} opened without ZTC's workspace tools (${why}), so it cannot open or message other panes.`);
114
+ }
115
+ const shownArgs = request.words.length > 0 || request.prompt?.trim()
116
+ ? paneCliArgs(options.cli, request).args : [];
117
+ return {
118
+ paneId: event.pane_id,
119
+ title,
120
+ ...(options.cwd ? { cwd: options.cwd } : {}),
121
+ shown: formatCliArguments([spec.binaries[0], ...shownArgs]),
122
+ ...(notices.length > 0 ? { notice: notices.join(' ') } : {}),
123
+ };
124
+ }
@@ -0,0 +1,171 @@
1
+ /**
2
+ * The coding-agent CLIs ZTC opens in a pane, as data.
3
+ *
4
+ * Claude Code and Codex are opened by `/claude` and `/codex` with ZTC's full integration (agent_cli.ts: resume and
5
+ * sessions, sign-in profiles, the workspace MCP server). The others open as a terminal would open them
6
+ * (pane_cli_launch.ts): the person's own, unmodified CLI, signed in through its own flow, in a new pane in this pane's
7
+ * folder. ZTC never reads, stores or forwards any CLI's sign-in.
8
+ *
9
+ * Each row says how to find the CLI (its executable's names, where its installer puts it), how to install it (the
10
+ * vendor's own commands, verbatim, for each platform, with the page each is from), how an opening prompt reaches it,
11
+ * which of its own words ZTC never passes it, whether ZTC's workspace MCP server is attached for the run (only where the
12
+ * CLI takes one for that run alone, so that ZTC edits none of the person's configuration), and who may drive its pane:
13
+ * the person and, as their permission profile lets, ZTC's agents; or the person alone, where the CLI's terms say that
14
+ * another program driving it isn't covered (Antigravity: Google's FAQ says wrapping agy inside third-party coding
15
+ * agents or applications isn't supported on consumer plans).
16
+ *
17
+ * Looking for a CLI never takes one from the project: a PATH entry that is relative, lies in a node_modules folder, or
18
+ * lies inside the folder ZTC works in is skipped (isProjectLocalDir), so a repository can't put a program of its own in
19
+ * the CLI's place.
20
+ */
21
+ export type PaneCliId = 'claude' | 'codex' | 'antigravity' | 'pi' | 'opencode' | 'gemini' | 'copilot' | 'cursor';
22
+ /** The platforms an install command is for. */
23
+ export type InstallPlatform = 'darwin' | 'linux' | 'win32';
24
+ /** One of a vendor's own install commands. */
25
+ export interface InstallMethod {
26
+ /** What it installs with, as the chooser names it: npm, Homebrew, the install script, PowerShell, WinGet. */
27
+ via: string;
28
+ /** The program it runs first, which must be found for ZTC to offer it: npm, brew, curl, powershell, winget. */
29
+ needs: string;
30
+ /** The command, exactly as the vendor's page gives it. */
31
+ command: string;
32
+ platforms: readonly InstallPlatform[];
33
+ /** The page it is from. */
34
+ source: string;
35
+ }
36
+ /**
37
+ * How an opening prompt reaches the CLI: joined to a flag (`--prompt-interactive=<prompt>`), as one word after `--`,
38
+ * as one word after the rest, or not at all (the CLI takes none on its command line).
39
+ */
40
+ export type PromptPassing = {
41
+ kind: 'flag';
42
+ flag: string;
43
+ } | {
44
+ kind: 'after-separator';
45
+ } | {
46
+ kind: 'last-word';
47
+ } | {
48
+ kind: 'none';
49
+ };
50
+ /** How ZTC's workspace MCP server is attached for one run: Claude Code's and Codex's own ways, Copilot's, or none. */
51
+ export type WorkspaceMcpAttach = 'claude' | 'codex' | 'copilot' | null;
52
+ export interface PaneCliSpec {
53
+ id: PaneCliId;
54
+ /** The slash command that opens it, without the slash. */
55
+ command: string;
56
+ label: string;
57
+ /** Who opens it: `/claude` and `/codex` (agent_cli.ts), or the launcher the other CLIs share (pane_cli_launch.ts). */
58
+ opens: 'agent-cli' | 'terminal';
59
+ /** The executable's names, looked for in this order. */
60
+ binaries: readonly string[];
61
+ /** Folders under the home folder its installer puts the executable in, looked in after PATH. */
62
+ homeDirs: readonly string[];
63
+ /** The vendor's install page. */
64
+ setupUrl: string;
65
+ /** How the person signs in, in the CLI's own flow. */
66
+ signIn: string;
67
+ install: readonly InstallMethod[];
68
+ prompt: PromptPassing;
69
+ /**
70
+ * Its own flags and commands ZTC never passes it, whoever asks, and why: the modes in which another program drives
71
+ * the CLI, where its terms don't cover that.
72
+ */
73
+ refused?: {
74
+ flags: readonly string[];
75
+ commands: readonly string[];
76
+ why: string;
77
+ };
78
+ workspaceMcp: WorkspaceMcpAttach;
79
+ /** Who drives the pane: the person and, as their permission profile lets, ZTC's agents; or the person alone. */
80
+ drivenBy: 'anyone' | 'person';
81
+ /** Why only the person drives it, said in each refusal. */
82
+ personOnlyWhy?: string;
83
+ }
84
+ export declare const PANE_CLIS: Readonly<Record<PaneCliId, PaneCliSpec>>;
85
+ /** Every CLI, Claude Code and Codex first, as /agents and the new-pane chooser list them. */
86
+ export declare const PANE_CLI_IDS: readonly PaneCliId[];
87
+ /** The CLIs the shared launcher opens (all but Claude Code and Codex). */
88
+ export declare const TERMINAL_CLI_IDS: readonly PaneCliId[];
89
+ export declare function isPaneCliId(value: string): value is PaneCliId;
90
+ /** Whether only the person drives CLI's pane. */
91
+ export declare function isPersonOnlyCli(id: PaneCliId): boolean;
92
+ /** The CLI whose executable is named NAME (its file name, without a Windows extension), if any. */
93
+ export declare function paneCliByBinary(name: string): PaneCliId | null;
94
+ /** The vendor's install commands for PLATFORM, in the registry's order. */
95
+ export declare function installMethodsFor(id: PaneCliId, platform?: NodeJS.Platform): InstallMethod[];
96
+ export interface PaneCliLookup {
97
+ env?: NodeJS.ProcessEnv;
98
+ /** The home folder (default: the env's HOME, else the user's). */
99
+ home?: string;
100
+ platform?: NodeJS.Platform;
101
+ /** The folder ZTC works in: a PATH entry inside it is the project's, never looked in. */
102
+ cwd?: string;
103
+ /** Shared bin folders looked in after PATH and the home folders. */
104
+ systemDirs?: readonly string[];
105
+ }
106
+ /**
107
+ * Whether DIR, a PATH entry, is the project's rather than the person's: relative (read against whatever folder ZTC
108
+ * runs in), in a node_modules folder, or inside CWD, the folder ZTC works in, unless that folder is the home folder, the
109
+ * filesystem's root or one above the home folder (where everything would be inside it).
110
+ */
111
+ export declare function isProjectLocalDir(dir: string, options: {
112
+ cwd?: string;
113
+ home: string;
114
+ }): boolean;
115
+ /**
116
+ * The absolute path of the person's own CLI, or null when it is not installed: on PATH (its project-local entries
117
+ * skipped), then in the folders under the home folder its installer uses, then in the shared bin folders, where a
118
+ * desktop app started from the Finder, whose PATH is bare, still finds it.
119
+ */
120
+ export declare function findPaneCli(id: PaneCliId, lookup?: PaneCliLookup): string | null;
121
+ /**
122
+ * Where a program an install command runs (npm, brew, curl, and the bash it pipes to) is looked for, in order: PATH's
123
+ * own entries (isProjectLocalDir's skipped), ~/.local/bin, then the shared bin folders. An install pane runs with these
124
+ * as its PATH (cli_install.ts), so its command runs the program ZTC found, never one a project put ahead of it.
125
+ */
126
+ export declare function installSearchDirs(lookup?: PaneCliLookup): string[];
127
+ /** A program an install command runs first (npm, brew, curl…), looked for in installSearchDirs, or null. */
128
+ export declare function findInstallProgram(name: string, lookup?: PaneCliLookup): string | null;
129
+ /** What to start a CLI with: its own words, an opening prompt, or both. */
130
+ export interface PaneCliRequest {
131
+ words: string[];
132
+ prompt?: string;
133
+ }
134
+ /**
135
+ * Read the text after the CLI's command. Text that starts with a flag is the CLI's own arguments, split like a shell
136
+ * command line (`/pi --model sonnet`); a leading standalone `--` starts an opening prompt (`/pi -- --help me`); anything
137
+ * else is the opening prompt, kept exactly as typed, apostrophes and all. Throws CliArgumentsError for an unclosed quote.
138
+ */
139
+ export declare function parsePaneCliBody(body: string): PaneCliRequest;
140
+ /** The word a refused flag or command is, among WORDS (before any `--`), or null. */
141
+ export declare function refusedPaneCliWord(id: PaneCliId, words: readonly string[]): string | null;
142
+ /**
143
+ * Why an agent can't open the CLI with REQUEST, or null. An agent passes a prompt and nothing else: no flag of the
144
+ * CLI's own, which is the person's to choose (ZTC reads no CLI's flags but Claude Code's and Codex's, agent_cli.ts), and
145
+ * no task of one word a CLI that takes its prompt as a word could read as one of its commands.
146
+ */
147
+ export declare function agentPaneCliRefusal(id: PaneCliId, request: PaneCliRequest): string | null;
148
+ /** How to start ZTC's workspace server: a program and its arguments. */
149
+ export interface WorkspaceServer {
150
+ command: string;
151
+ args: readonly string[];
152
+ }
153
+ /** ZTC's name for its workspace server, the CLI's tools' prefix. */
154
+ export declare const PANE_CLI_MCP_SERVER_NAME = "ztc";
155
+ /**
156
+ * Copilot's own flag for an MCP server for this session alone, which adds to ~/.copilot/mcp-config.json without
157
+ * changing it: the workspace server, every tool of it, and each variable it reads named, never its value, which
158
+ * Copilot takes from its own environment (`${NAME}`), so no credential is on the command line.
159
+ */
160
+ export declare function copilotMcpArgs(server: WorkspaceServer, envNames: readonly string[]): string[];
161
+ /**
162
+ * The CLI's arguments for REQUEST: the workspace server first where it takes one (ATTACH), then the person's own words,
163
+ * then the opening prompt, as the CLI takes it, as one word. NOTICES says what of the request didn't reach it.
164
+ */
165
+ export declare function paneCliArgs(id: PaneCliId, request: PaneCliRequest, attach?: {
166
+ server: WorkspaceServer;
167
+ envNames: readonly string[];
168
+ } | null): {
169
+ args: string[];
170
+ notices: string[];
171
+ };
@@ -0,0 +1,325 @@
1
+ /**
2
+ * The coding-agent CLIs ZTC opens in a pane, as data.
3
+ *
4
+ * Claude Code and Codex are opened by `/claude` and `/codex` with ZTC's full integration (agent_cli.ts: resume and
5
+ * sessions, sign-in profiles, the workspace MCP server). The others open as a terminal would open them
6
+ * (pane_cli_launch.ts): the person's own, unmodified CLI, signed in through its own flow, in a new pane in this pane's
7
+ * folder. ZTC never reads, stores or forwards any CLI's sign-in.
8
+ *
9
+ * Each row says how to find the CLI (its executable's names, where its installer puts it), how to install it (the
10
+ * vendor's own commands, verbatim, for each platform, with the page each is from), how an opening prompt reaches it,
11
+ * which of its own words ZTC never passes it, whether ZTC's workspace MCP server is attached for the run (only where the
12
+ * CLI takes one for that run alone, so that ZTC edits none of the person's configuration), and who may drive its pane:
13
+ * the person and, as their permission profile lets, ZTC's agents; or the person alone, where the CLI's terms say that
14
+ * another program driving it isn't covered (Antigravity: Google's FAQ says wrapping agy inside third-party coding
15
+ * agents or applications isn't supported on consumer plans).
16
+ *
17
+ * Looking for a CLI never takes one from the project: a PATH entry that is relative, lies in a node_modules folder, or
18
+ * lies inside the folder ZTC works in is skipped (isProjectLocalDir), so a repository can't put a program of its own in
19
+ * the CLI's place.
20
+ */
21
+ import { accessSync, constants, statSync } from 'node:fs';
22
+ import { homedir } from 'node:os';
23
+ import { isAbsolute, join, relative, resolve, sep } from 'node:path';
24
+ import { splitCliArguments } from './agent_cli.js';
25
+ const ALL = ['darwin', 'linux', 'win32'];
26
+ const POSIX = ['darwin', 'linux'];
27
+ const CLAUDE_SETUP = 'https://code.claude.com/docs/en/setup';
28
+ const CODEX_README = 'https://github.com/openai/codex';
29
+ const AGY_SETUP = 'https://antigravity.google/docs/getting-started/';
30
+ const PI_SITE = 'https://pi.dev/';
31
+ const OPENCODE_DOCS = 'https://opencode.ai/docs/';
32
+ const GEMINI_README = 'https://github.com/google-gemini/gemini-cli';
33
+ const COPILOT_INSTALL = 'https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli';
34
+ const CURSOR_INSTALL = 'https://cursor.com/docs/cli/installation';
35
+ /** Why Antigravity's pane is the person's alone, in Google's words where they have them. */
36
+ const ANTIGRAVITY_PERSON_ONLY = 'Google\'s Antigravity FAQ says wrapping agy inside third-party coding agents or applications isn\'t '
37
+ + 'supported on consumer plans (https://antigravity.google/docs/faq/)';
38
+ export const PANE_CLIS = Object.freeze({
39
+ claude: {
40
+ id: 'claude', command: 'claude', label: 'Claude Code', opens: 'agent-cli', binaries: ['claude'],
41
+ homeDirs: ['.local/bin', '.claude/local'], setupUrl: CLAUDE_SETUP,
42
+ signIn: 'its own browser sign-in (a Claude plan or a Console account)',
43
+ install: [
44
+ { via: 'the install script', needs: 'curl', command: 'curl -fsSL https://claude.ai/install.sh | bash', platforms: POSIX, source: CLAUDE_SETUP },
45
+ { via: 'Homebrew', needs: 'brew', command: 'brew install --cask claude-code', platforms: ['darwin'], source: CLAUDE_SETUP },
46
+ { via: 'npm', needs: 'npm', command: 'npm install -g @anthropic-ai/claude-code@latest', platforms: ALL, source: CLAUDE_SETUP },
47
+ { via: 'PowerShell', needs: 'powershell', command: 'irm https://claude.ai/install.ps1 | iex', platforms: ['win32'], source: CLAUDE_SETUP },
48
+ { via: 'WinGet', needs: 'winget', command: 'winget install Anthropic.ClaudeCode', platforms: ['win32'], source: CLAUDE_SETUP },
49
+ ],
50
+ prompt: { kind: 'after-separator' }, workspaceMcp: 'claude', drivenBy: 'anyone',
51
+ },
52
+ codex: {
53
+ id: 'codex', command: 'codex', label: 'Codex', opens: 'agent-cli', binaries: ['codex'],
54
+ homeDirs: ['.local/bin'], setupUrl: 'https://developers.openai.com/codex/cli',
55
+ signIn: 'its own Sign in with ChatGPT, or an API key',
56
+ install: [
57
+ { via: 'npm', needs: 'npm', command: 'npm install -g @openai/codex', platforms: ALL, source: CODEX_README },
58
+ { via: 'Homebrew', needs: 'brew', command: 'brew install --cask codex', platforms: ['darwin'], source: CODEX_README },
59
+ { via: 'the install script', needs: 'curl', command: 'curl -fsSL https://chatgpt.com/codex/install.sh | sh', platforms: POSIX, source: CODEX_README },
60
+ { via: 'PowerShell', needs: 'powershell', command: 'powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"',
61
+ platforms: ['win32'], source: CODEX_README },
62
+ ],
63
+ prompt: { kind: 'after-separator' }, workspaceMcp: 'codex', drivenBy: 'anyone',
64
+ },
65
+ antigravity: {
66
+ id: 'antigravity', command: 'antigravity', label: 'Antigravity', opens: 'terminal', binaries: ['agy'], homeDirs: ['.local/bin'],
67
+ setupUrl: AGY_SETUP, signIn: 'its own Google sign-in, in the browser, the first time it starts',
68
+ install: [
69
+ { via: 'the install script', needs: 'curl', command: 'curl -fsSL https://antigravity.google/cli/install.sh | bash', platforms: POSIX, source: AGY_SETUP },
70
+ { via: 'PowerShell', needs: 'powershell', command: 'irm https://antigravity.google/cli/install.ps1 | iex', platforms: ['win32'], source: AGY_SETUP },
71
+ ],
72
+ prompt: { kind: 'flag', flag: '--prompt-interactive' },
73
+ refused: {
74
+ flags: ['-p', '--print', '--prompt', '--output-format', '--input-format', '--json-schema', '--print-timeout', '--disable-slash-commands'],
75
+ commands: ['acp'],
76
+ why: 'its headless mode and its Agent Client Protocol are how another program drives agy, which Google\'s terms don\'t cover on a '
77
+ + 'consumer plan; run agy yourself in a terminal for those',
78
+ },
79
+ workspaceMcp: null, drivenBy: 'person', personOnlyWhy: ANTIGRAVITY_PERSON_ONLY,
80
+ },
81
+ pi: {
82
+ // Its install script puts pi in the first of ~/.local/bin, ~/bin and the like that is on PATH, else in ~/.pi/agent/bin.
83
+ id: 'pi', command: 'pi', label: 'Pi', opens: 'terminal', binaries: ['pi'], homeDirs: ['.local/bin', '.pi/agent/bin'], setupUrl: PI_SITE,
84
+ signIn: 'its own /login, for a subscription or an API key',
85
+ install: [
86
+ { via: 'the install script', needs: 'curl', command: 'curl -fsSL https://pi.dev/install.sh | sh', platforms: POSIX, source: PI_SITE },
87
+ { via: 'npm', needs: 'npm', command: 'npm install -g --ignore-scripts @earendil-works/pi-coding-agent', platforms: ALL, source: PI_SITE },
88
+ { via: 'PowerShell', needs: 'powershell', command: 'powershell -c "irm https://pi.dev/install.ps1 | iex"', platforms: ['win32'], source: PI_SITE },
89
+ ],
90
+ prompt: { kind: 'after-separator' }, workspaceMcp: null, drivenBy: 'anyone',
91
+ },
92
+ opencode: {
93
+ // Its install script puts opencode in ~/.opencode/bin, which it adds to PATH in the shell's startup file only.
94
+ id: 'opencode', command: 'opencode', label: 'OpenCode', opens: 'terminal', binaries: ['opencode'], homeDirs: ['.opencode/bin'],
95
+ setupUrl: OPENCODE_DOCS, signIn: 'its own /connect, for each provider',
96
+ install: [
97
+ { via: 'the install script', needs: 'curl', command: 'curl -fsSL https://opencode.ai/v2/install | bash', platforms: POSIX, source: OPENCODE_DOCS },
98
+ { via: 'npm', needs: 'npm', command: 'npm install -g @opencode/cli', platforms: ALL, source: OPENCODE_DOCS },
99
+ { via: 'Homebrew', needs: 'brew', command: 'brew install anomalyco/tap/opencode-v2', platforms: POSIX, source: OPENCODE_DOCS },
100
+ ],
101
+ prompt: { kind: 'none' }, workspaceMcp: null, drivenBy: 'anyone',
102
+ },
103
+ gemini: {
104
+ id: 'gemini', command: 'gemini', label: 'Gemini CLI', opens: 'terminal', binaries: ['gemini'], homeDirs: ['.local/bin'],
105
+ // Gemini CLI's unpaid tier and Google One users moved to Antigravity CLI on June 18, 2026
106
+ // (https://www.geminicli.com/docs/resources/tos-privacy).
107
+ setupUrl: GEMINI_README, signIn: 'its own Sign in with Google (a Gemini Code Assist license), a Gemini API key, or Vertex AI',
108
+ install: [
109
+ { via: 'npm', needs: 'npm', command: 'npm install -g @google/gemini-cli', platforms: ALL, source: GEMINI_README },
110
+ { via: 'Homebrew', needs: 'brew', command: 'brew install gemini-cli', platforms: POSIX, source: GEMINI_README },
111
+ ],
112
+ prompt: { kind: 'flag', flag: '--prompt-interactive' }, workspaceMcp: null, drivenBy: 'anyone',
113
+ },
114
+ copilot: {
115
+ id: 'copilot', command: 'copilot', label: 'GitHub Copilot CLI', opens: 'terminal', binaries: ['copilot'], homeDirs: ['.local/bin'],
116
+ setupUrl: COPILOT_INSTALL, signIn: 'its own /login with your GitHub account (a Copilot plan)',
117
+ install: [
118
+ { via: 'npm', needs: 'npm', command: 'npm install -g @github/copilot', platforms: ALL, source: COPILOT_INSTALL },
119
+ { via: 'Homebrew', needs: 'brew', command: 'brew install --cask copilot-cli', platforms: POSIX, source: COPILOT_INSTALL },
120
+ { via: 'the install script', needs: 'curl', command: 'curl -fsSL https://gh.io/copilot-install | bash', platforms: POSIX, source: COPILOT_INSTALL },
121
+ { via: 'WinGet', needs: 'winget', command: 'winget install GitHub.Copilot', platforms: ['win32'], source: COPILOT_INSTALL },
122
+ ],
123
+ prompt: { kind: 'flag', flag: '--interactive' }, workspaceMcp: 'copilot', drivenBy: 'anyone',
124
+ },
125
+ cursor: {
126
+ // Its install script links ~/.local/bin/agent, the name Cursor's docs now use, and cursor-agent, the unambiguous one.
127
+ id: 'cursor', command: 'cursor', label: 'Cursor CLI', opens: 'terminal', binaries: ['cursor-agent'], homeDirs: ['.local/bin'],
128
+ setupUrl: CURSOR_INSTALL, signIn: 'its own agent login, in the browser, or a Cursor API key',
129
+ install: [
130
+ { via: 'the install script', needs: 'curl', command: 'curl https://cursor.com/install -fsS | bash', platforms: POSIX, source: CURSOR_INSTALL },
131
+ { via: 'PowerShell', needs: 'powershell', command: 'irm \'https://cursor.com/install?win32=true\' | iex', platforms: ['win32'], source: CURSOR_INSTALL },
132
+ ],
133
+ prompt: { kind: 'last-word' }, workspaceMcp: null, drivenBy: 'anyone',
134
+ },
135
+ });
136
+ /** Every CLI, Claude Code and Codex first, as /agents and the new-pane chooser list them. */
137
+ export const PANE_CLI_IDS = Object.freeze(['claude', 'codex', 'antigravity', 'pi', 'opencode', 'gemini', 'copilot', 'cursor']);
138
+ /** The CLIs the shared launcher opens (all but Claude Code and Codex). */
139
+ export const TERMINAL_CLI_IDS = Object.freeze(PANE_CLI_IDS.filter(id => PANE_CLIS[id].opens === 'terminal'));
140
+ export function isPaneCliId(value) {
141
+ return PANE_CLI_IDS.includes(value);
142
+ }
143
+ /** Whether only the person drives CLI's pane. */
144
+ export function isPersonOnlyCli(id) {
145
+ return PANE_CLIS[id].drivenBy === 'person';
146
+ }
147
+ /** The CLI whose executable is named NAME (its file name, without a Windows extension), if any. */
148
+ export function paneCliByBinary(name) {
149
+ const bare = name.replace(/\.(exe|cmd)$/i, '');
150
+ return PANE_CLI_IDS.find(id => PANE_CLIS[id].binaries.includes(bare)) ?? null;
151
+ }
152
+ /** The vendor's install commands for PLATFORM, in the registry's order. */
153
+ export function installMethodsFor(id, platform = process.platform) {
154
+ return PANE_CLIS[id].install.filter(method => method.platforms.includes(platform));
155
+ }
156
+ const SYSTEM_BIN_DIRS = ['/opt/homebrew/bin', '/usr/local/bin', '/usr/bin'];
157
+ function isExecutableFile(path) {
158
+ try {
159
+ if (!statSync(path).isFile())
160
+ return false;
161
+ accessSync(path, constants.X_OK);
162
+ return true;
163
+ }
164
+ catch {
165
+ return false;
166
+ }
167
+ }
168
+ function inside(folder, path) {
169
+ const rel = relative(folder, path);
170
+ return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
171
+ }
172
+ /**
173
+ * Whether DIR, a PATH entry, is the project's rather than the person's: relative (read against whatever folder ZTC
174
+ * runs in), in a node_modules folder, or inside CWD, the folder ZTC works in, unless that folder is the home folder, the
175
+ * filesystem's root or one above the home folder (where everything would be inside it).
176
+ */
177
+ export function isProjectLocalDir(dir, options) {
178
+ if (!dir || !isAbsolute(dir))
179
+ return true;
180
+ if (dir.split(/[\\/]+/).includes('node_modules'))
181
+ return true;
182
+ if (!options.cwd || !isAbsolute(options.cwd))
183
+ return false;
184
+ const cwd = resolve(options.cwd);
185
+ const home = resolve(options.home);
186
+ if (cwd === resolve(sep) || inside(cwd, home))
187
+ return false;
188
+ return inside(cwd, resolve(dir));
189
+ }
190
+ /** The first of NAMES that is an executable file in DIRS, by its absolute path, or null. */
191
+ function firstExecutable(names, dirs, platform) {
192
+ const files = platform === 'win32' ? names.flatMap(name => [`${name}.exe`, `${name}.cmd`]) : names;
193
+ for (const dir of dirs) {
194
+ for (const file of files) {
195
+ const candidate = join(dir, file);
196
+ if (isExecutableFile(candidate))
197
+ return candidate;
198
+ }
199
+ }
200
+ return null;
201
+ }
202
+ /** PATH's entries that are the person's (isProjectLocalDir), in order. */
203
+ function personPathDirs(lookup, home) {
204
+ const env = lookup.env ?? process.env;
205
+ const platform = lookup.platform ?? process.platform;
206
+ return (env.PATH ?? '').split(platform === 'win32' ? ';' : ':')
207
+ .filter(dir => !isProjectLocalDir(dir, { ...(lookup.cwd ? { cwd: lookup.cwd } : {}), home }));
208
+ }
209
+ function lookupHome(lookup) {
210
+ return lookup.home ?? (lookup.env ?? process.env).HOME ?? homedir();
211
+ }
212
+ /**
213
+ * The absolute path of the person's own CLI, or null when it is not installed: on PATH (its project-local entries
214
+ * skipped), then in the folders under the home folder its installer uses, then in the shared bin folders, where a
215
+ * desktop app started from the Finder, whose PATH is bare, still finds it.
216
+ */
217
+ export function findPaneCli(id, lookup = {}) {
218
+ const home = lookupHome(lookup);
219
+ const platform = lookup.platform ?? process.platform;
220
+ const spec = PANE_CLIS[id];
221
+ const dirs = [...personPathDirs(lookup, home), ...spec.homeDirs.map(dir => join(home, dir)), ...(lookup.systemDirs ?? SYSTEM_BIN_DIRS)];
222
+ return firstExecutable(spec.binaries, dirs, platform);
223
+ }
224
+ /**
225
+ * Where a program an install command runs (npm, brew, curl, and the bash it pipes to) is looked for, in order: PATH's
226
+ * own entries (isProjectLocalDir's skipped), ~/.local/bin, then the shared bin folders. An install pane runs with these
227
+ * as its PATH (cli_install.ts), so its command runs the program ZTC found, never one a project put ahead of it.
228
+ */
229
+ export function installSearchDirs(lookup = {}) {
230
+ const home = lookupHome(lookup);
231
+ return [...new Set([...personPathDirs(lookup, home), join(home, '.local', 'bin'), ...(lookup.systemDirs ?? SYSTEM_BIN_DIRS)])];
232
+ }
233
+ /** A program an install command runs first (npm, brew, curl…), looked for in installSearchDirs, or null. */
234
+ export function findInstallProgram(name, lookup = {}) {
235
+ return firstExecutable([name], installSearchDirs(lookup), lookup.platform ?? process.platform);
236
+ }
237
+ /**
238
+ * Read the text after the CLI's command. Text that starts with a flag is the CLI's own arguments, split like a shell
239
+ * command line (`/pi --model sonnet`); a leading standalone `--` starts an opening prompt (`/pi -- --help me`); anything
240
+ * else is the opening prompt, kept exactly as typed, apostrophes and all. Throws CliArgumentsError for an unclosed quote.
241
+ */
242
+ export function parsePaneCliBody(body) {
243
+ const text = body.trim();
244
+ if (!text)
245
+ return { words: [] };
246
+ if (text === '--' || /^--\s/.test(text)) {
247
+ const prompt = text.slice(2).trim();
248
+ return prompt ? { words: [], prompt } : { words: [] };
249
+ }
250
+ if (text.startsWith('-'))
251
+ return { words: splitCliArguments(text) };
252
+ return { words: [], prompt: text };
253
+ }
254
+ /** The word a refused flag or command is, among WORDS (before any `--`), or null. */
255
+ export function refusedPaneCliWord(id, words) {
256
+ const refused = PANE_CLIS[id].refused;
257
+ if (!refused)
258
+ return null;
259
+ for (const word of words) {
260
+ if (word === '--')
261
+ return null;
262
+ const flag = word.startsWith('--') ? word.split('=', 1)[0] : word.startsWith('-') && word.length > 2 ? word.slice(0, 2) : word;
263
+ if (word.startsWith('-') ? refused.flags.includes(flag) : refused.commands.includes(word))
264
+ return word;
265
+ }
266
+ return null;
267
+ }
268
+ /**
269
+ * A word of lowercase letters, digits and hyphens, starting with a letter: how every CLI here names its own commands
270
+ * (`pi install`, `cursor-agent update`, `gemini mcp`), so a task of one such word could run one.
271
+ */
272
+ const COMMAND_WORD = /^[a-z][a-z0-9-]*$/;
273
+ /**
274
+ * Why an agent can't open the CLI with REQUEST, or null. An agent passes a prompt and nothing else: no flag of the
275
+ * CLI's own, which is the person's to choose (ZTC reads no CLI's flags but Claude Code's and Codex's, agent_cli.ts), and
276
+ * no task of one word a CLI that takes its prompt as a word could read as one of its commands.
277
+ */
278
+ export function agentPaneCliRefusal(id, request) {
279
+ const spec = PANE_CLIS[id];
280
+ if (request.words.length > 0) {
281
+ return `An agent can open ${spec.label} only with a prompt: its own flags (${request.words[0]}) are the person's to pass.`;
282
+ }
283
+ const passing = spec.prompt.kind;
284
+ if ((passing === 'after-separator' || passing === 'last-word') && COMMAND_WORD.test(request.prompt?.trim() ?? '')) {
285
+ return `An agent can't open ${spec.label} with the task "${request.prompt.trim()}": ${spec.label} reads its prompt as words, where one `
286
+ + 'word of lowercase letters, digits and hyphens may be one of its own commands; write the task in more than one word.';
287
+ }
288
+ return null;
289
+ }
290
+ /** ZTC's name for its workspace server, the CLI's tools' prefix. */
291
+ export const PANE_CLI_MCP_SERVER_NAME = 'ztc';
292
+ /**
293
+ * Copilot's own flag for an MCP server for this session alone, which adds to ~/.copilot/mcp-config.json without
294
+ * changing it: the workspace server, every tool of it, and each variable it reads named, never its value, which
295
+ * Copilot takes from its own environment (`${NAME}`), so no credential is on the command line.
296
+ */
297
+ export function copilotMcpArgs(server, envNames) {
298
+ const env = Object.fromEntries(envNames.map(name => [name, `\${${name}}`]));
299
+ return ['--additional-mcp-config', JSON.stringify({
300
+ mcpServers: { [PANE_CLI_MCP_SERVER_NAME]: { type: 'local', command: server.command, args: [...server.args], tools: ['*'], env } },
301
+ })];
302
+ }
303
+ /**
304
+ * The CLI's arguments for REQUEST: the workspace server first where it takes one (ATTACH), then the person's own words,
305
+ * then the opening prompt, as the CLI takes it, as one word. NOTICES says what of the request didn't reach it.
306
+ */
307
+ export function paneCliArgs(id, request, attach = null) {
308
+ const spec = PANE_CLIS[id];
309
+ const notices = [];
310
+ const mcp = attach && spec.workspaceMcp === 'copilot' ? copilotMcpArgs(attach.server, attach.envNames) : [];
311
+ const prompt = request.prompt?.trim() ? request.prompt : undefined;
312
+ const passing = spec.prompt;
313
+ let promptArgs = [];
314
+ if (prompt !== undefined) {
315
+ if (passing.kind === 'flag')
316
+ promptArgs = [`${passing.flag}=${prompt}`];
317
+ else if (passing.kind === 'after-separator')
318
+ promptArgs = ['--', prompt];
319
+ else if (passing.kind === 'last-word')
320
+ promptArgs = [prompt];
321
+ else
322
+ notices.push(`${spec.label} takes no opening prompt on its command line, so it opened without one: type it in its pane.`);
323
+ }
324
+ return { args: [...mcp, ...request.words, ...promptArgs], notices };
325
+ }