@zergai/ztc 0.26.2-dev.202611210149 → 0.26.4-dev.202611231953

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 (275) hide show
  1. package/README.md +590 -28
  2. package/bin/zmux-darwin-arm64 +0 -0
  3. package/bin/zmux-linux-x64 +0 -0
  4. package/bin/ztc-audio-darwin-arm64 +0 -0
  5. package/bin/ztc-capture-darwin-arm64 +0 -0
  6. package/bin/ztc-tui-darwin-arm64 +0 -0
  7. package/bin/ztc-tui-linux-x64 +0 -0
  8. package/bin/zterm-darwin-arm64 +2 -2
  9. package/dist/App.js +18 -1
  10. package/dist/agent/agent.d.ts +25 -1
  11. package/dist/agent/agent.js +26 -1
  12. package/dist/agent/attached_images.d.ts +58 -0
  13. package/dist/agent/attached_images.js +145 -0
  14. package/dist/agent/backends/anthropic.d.ts +14 -0
  15. package/dist/agent/backends/anthropic.js +49 -2
  16. package/dist/agent/backends/codex_app_server.d.ts +3 -1
  17. package/dist/agent/backends/codex_app_server.js +9 -6
  18. package/dist/agent/backends/codex_auth.js +3 -0
  19. package/dist/agent/backends/gemini.js +3 -0
  20. package/dist/agent/backends/host_effort_policy.js +14 -2
  21. package/dist/agent/backends/http_error.d.ts +17 -0
  22. package/dist/agent/backends/http_error.js +50 -1
  23. package/dist/agent/backends/index.js +2 -1
  24. package/dist/agent/backends/model_redirect.d.ts +47 -0
  25. package/dist/agent/backends/model_redirect.js +97 -0
  26. package/dist/agent/backends/openai_compatible.js +5 -0
  27. package/dist/agent/backends/openai_responses.d.ts +9 -1
  28. package/dist/agent/backends/openai_responses.js +21 -12
  29. package/dist/agent/backends/prompt_cache.d.ts +8 -0
  30. package/dist/agent/backends/prompt_cache.js +10 -0
  31. package/dist/agent/backends/provider_ids.d.ts +1 -1
  32. package/dist/agent/backends/provider_ids.js +1 -1
  33. package/dist/agent/backends/types.d.ts +8 -0
  34. package/dist/agent/backends/zerg-api.js +5 -1
  35. package/dist/agent/backends/zrouter_stream.d.ts +75 -9
  36. package/dist/agent/backends/zrouter_stream.js +250 -49
  37. package/dist/agent/commands/config.js +51 -4
  38. package/dist/agent/commands/connect.js +20 -0
  39. package/dist/agent/commands/credential_status.js +5 -3
  40. package/dist/agent/commands/debug.js +3 -0
  41. package/dist/agent/commands/diff.js +9 -5
  42. package/dist/agent/commands/emulation.js +7 -1
  43. package/dist/agent/commands/inbox.js +4 -3
  44. package/dist/agent/commands/mcp.js +3 -0
  45. package/dist/agent/commands/models.js +20 -3
  46. package/dist/agent/commands/permissions.js +16 -2
  47. package/dist/agent/commands/provider_selection.js +13 -6
  48. package/dist/agent/commands/settings.js +15 -4
  49. package/dist/agent/commands/status.js +23 -1
  50. package/dist/agent/commands/types.d.ts +34 -3
  51. package/dist/agent/commands/update.d.ts +2 -1
  52. package/dist/agent/commands/update.js +8 -3
  53. package/dist/agent/commands/zerg.d.ts +6 -0
  54. package/dist/agent/commands/zerg.js +152 -28
  55. package/dist/agent/commands/ztc_pane.js +8 -5
  56. package/dist/agent/factory.js +22 -4
  57. package/dist/agent/request_encoder.js +11 -2
  58. package/dist/agent/runtime/command_jobs.js +16 -1
  59. package/dist/agent/runtime/command_panes.js +4 -1
  60. package/dist/agent/runtime/execution_context.d.ts +8 -1
  61. package/dist/agent/runtime/execution_context.js +8 -2
  62. package/dist/agent/runtime/policy.d.ts +66 -5
  63. package/dist/agent/runtime/policy.js +161 -33
  64. package/dist/agent/runtime/remote_broker_transport.d.ts +7 -0
  65. package/dist/agent/runtime/remote_broker_transport.js +33 -3
  66. package/dist/agent/runtime/remote_resource_errors.d.ts +7 -0
  67. package/dist/agent/runtime/remote_resource_errors.js +10 -0
  68. package/dist/agent/runtime/remote_resources.d.ts +1 -1
  69. package/dist/agent/runtime/remote_resources.js +7 -3
  70. package/dist/agent/runtime/source_verification.js +15 -12
  71. package/dist/agent/runtime/tool_runtime.js +165 -58
  72. package/dist/agent/runtime/verifier_capture.d.ts +1 -1
  73. package/dist/agent/runtime/verifier_capture.js +6 -0
  74. package/dist/agent/runtime/work_base.js +46 -14
  75. package/dist/agent/tools/adaptation.js +29 -12
  76. package/dist/agent/tools/apply_patch.js +62 -5
  77. package/dist/agent/tools/background.js +2 -0
  78. package/dist/agent/tools/benchmark_cpu.js +2 -0
  79. package/dist/agent/tools/bus_message.d.ts +4 -2
  80. package/dist/agent/tools/bus_message.js +21 -3
  81. package/dist/agent/tools/delegate.js +2 -0
  82. package/dist/agent/tools/file.d.ts +12 -1
  83. package/dist/agent/tools/file.js +92 -11
  84. package/dist/agent/tools/lsp.d.ts +12 -0
  85. package/dist/agent/tools/lsp.js +61 -5
  86. package/dist/agent/tools/pane.js +20 -45
  87. package/dist/agent/tools/project_context.js +5 -2
  88. package/dist/agent/tools/routine.js +20 -4
  89. package/dist/agent/tools/screenshot.d.ts +8 -0
  90. package/dist/agent/tools/screenshot.js +39 -25
  91. package/dist/agent/tools/search.js +31 -3
  92. package/dist/agent/tools/shell.js +7 -1
  93. package/dist/agent/tools/supervision.js +6 -0
  94. package/dist/agent/tools/types.d.ts +18 -0
  95. package/dist/agent/tools/zerg.js +15 -19
  96. package/dist/agent/tools/ztc_command.d.ts +15 -4
  97. package/dist/agent/tools/ztc_command.js +48 -34
  98. package/dist/app/agent_runner.js +8 -6
  99. package/dist/app/conversation_compaction.d.ts +6 -3
  100. package/dist/app/conversation_compaction.js +6 -3
  101. package/dist/app/tool_callbacks.js +1 -0
  102. package/dist/audio/sfx.js +6 -0
  103. package/dist/batch/worktree.js +22 -10
  104. package/dist/board/client.js +2 -1
  105. package/dist/cli_main.d.ts +1 -0
  106. package/dist/cli_main.js +141 -45
  107. package/dist/cli_ratatui.d.ts +49 -4
  108. package/dist/cli_ratatui.js +355 -79
  109. package/dist/conductor_branch.js +4 -1
  110. package/dist/config/host_credentials.d.ts +157 -0
  111. package/dist/config/host_credentials.js +589 -0
  112. package/dist/config/model_pin.d.ts +111 -0
  113. package/dist/config/model_pin.js +182 -0
  114. package/dist/config/own_state_files.d.ts +35 -0
  115. package/dist/config/own_state_files.js +161 -0
  116. package/dist/config/permission_pin.d.ts +148 -0
  117. package/dist/config/permission_pin.js +203 -0
  118. package/dist/config/permissions.d.ts +9 -2
  119. package/dist/config/permissions.js +14 -3
  120. package/dist/config/platform_login.d.ts +72 -0
  121. package/dist/config/platform_login.js +111 -0
  122. package/dist/config/profile_limits.d.ts +34 -0
  123. package/dist/config/profile_limits.js +66 -0
  124. package/dist/config/provider_api_key_env.js +3 -2
  125. package/dist/config/provider_models.d.ts +6 -1
  126. package/dist/config/provider_models.js +38 -11
  127. package/dist/config/repo_config.d.ts +22 -0
  128. package/dist/config/repo_config.js +77 -3
  129. package/dist/config/router_runtime_grant.d.ts +53 -0
  130. package/dist/config/router_runtime_grant.js +131 -0
  131. package/dist/config/settings_merge.d.ts +22 -0
  132. package/dist/config/settings_merge.js +75 -0
  133. package/dist/config/types.d.ts +8 -0
  134. package/dist/config.d.ts +334 -4
  135. package/dist/config.js +1024 -41
  136. package/dist/context/project_intelligence.d.ts +11 -2
  137. package/dist/context/project_intelligence.js +38 -15
  138. package/dist/desktop/daily/desktop_wiring.js +8 -6
  139. package/dist/desktop/daily/native_pane_launcher.js +2 -1
  140. package/dist/desktop/daily/native_tool.d.ts +1 -1
  141. package/dist/desktop/daily/native_tool.js +4 -3
  142. package/dist/desktop/daily/process_identity.js +10 -2
  143. package/dist/desktop/daily/source_baseline.js +4 -3
  144. package/dist/diagnostics/native_terminal_benchmark.js +3 -2
  145. package/dist/diagnostics/session_export.js +27 -14
  146. package/dist/embedded/anempa_runtime.js +3 -3
  147. package/dist/embedded/gameboy_runtime.js +5 -4
  148. package/dist/embedded/zergpod_runtime.js +5 -4
  149. package/dist/emulation/catalog.js +6 -1
  150. package/dist/emulation/tool_adapters.js +13 -3
  151. package/dist/environment/store.js +5 -4
  152. package/dist/extension_discovery.d.ts +12 -2
  153. package/dist/extension_discovery.js +52 -7
  154. package/dist/headless.d.ts +8 -0
  155. package/dist/headless.js +52 -13
  156. package/dist/headless_cli.js +16 -1
  157. package/dist/headless_workflow_trigger.js +1 -1
  158. package/dist/hooks/dispatcher.d.ts +8 -0
  159. package/dist/hooks/dispatcher.js +22 -2
  160. package/dist/hooks/lifecycle.d.ts +6 -0
  161. package/dist/hooks/lifecycle.js +1 -0
  162. package/dist/hooks/program_files.d.ts +10 -0
  163. package/dist/hooks/program_files.js +175 -0
  164. package/dist/hooks/runner.d.ts +11 -1
  165. package/dist/hooks/runner.js +112 -11
  166. package/dist/hooks/types.d.ts +2 -0
  167. package/dist/host_credentials_startup.d.ts +6 -0
  168. package/dist/host_credentials_startup.js +17 -0
  169. package/dist/instance_registry.d.ts +6 -2
  170. package/dist/instance_registry.js +9 -15
  171. package/dist/intake/format.d.ts +6 -0
  172. package/dist/intake/format.js +9 -0
  173. package/dist/intake/notifications.js +2 -1
  174. package/dist/lsp/manager.d.ts +1 -1
  175. package/dist/lsp/manager.js +4 -5
  176. package/dist/mcp/client.d.ts +2 -0
  177. package/dist/mcp/client.js +116 -18
  178. package/dist/mcp/registry.d.ts +12 -0
  179. package/dist/mcp/registry.js +15 -1
  180. package/dist/modes/handlers.js +14 -5
  181. package/dist/panes/agent_cli.d.ts +23 -1
  182. package/dist/panes/agent_cli.js +96 -1
  183. package/dist/panes/agent_panes.d.ts +27 -4
  184. package/dist/panes/agent_panes.js +73 -11
  185. package/dist/panes/editor_program.d.ts +8 -0
  186. package/dist/panes/editor_program.js +25 -0
  187. package/dist/panes/motsi.d.ts +11 -1
  188. package/dist/panes/motsi.js +14 -1
  189. package/dist/panes/pane_registry.d.ts +28 -1
  190. package/dist/panes/pane_registry.js +25 -0
  191. package/dist/panes/worker_route.js +5 -3
  192. package/dist/panes/ztc_launch.d.ts +8 -0
  193. package/dist/panes/ztc_launch.js +26 -1
  194. package/dist/profile_baseline.js +2 -0
  195. package/dist/router_auth.d.ts +8 -3
  196. package/dist/router_auth.js +34 -2
  197. package/dist/runtime_info.js +56 -38
  198. package/dist/session.js +12 -2
  199. package/dist/shannon/runtime.js +13 -1
  200. package/dist/simulation/domains/loader.d.ts +2 -1
  201. package/dist/simulation/domains/loader.js +19 -2
  202. package/dist/simulation/living/context.d.ts +8 -8
  203. package/dist/simulation/living/types.d.ts +2 -2
  204. package/dist/simulation/memory/embedding.d.ts +2 -1
  205. package/dist/simulation/memory/embedding.js +25 -6
  206. package/dist/terminal_attach.js +2 -1
  207. package/dist/types.d.ts +21 -0
  208. package/dist/ui/ratatui/headless_pane_manager.d.ts +12 -6
  209. package/dist/ui/ratatui/headless_pane_manager.js +65 -21
  210. package/dist/ui/ratatui/ipc_path.d.ts +41 -2
  211. package/dist/ui/ratatui/ipc_path.js +164 -5
  212. package/dist/ui/ratatui/pane_credential_broker.d.ts +17 -4
  213. package/dist/ui/ratatui/pane_credential_broker.js +23 -5
  214. package/dist/ui/ratatui/pane_relay.d.ts +74 -0
  215. package/dist/ui/ratatui/pane_relay.js +188 -13
  216. package/dist/ui/ratatui/process.d.ts +15 -1
  217. package/dist/ui/ratatui/process.js +129 -163
  218. package/dist/ui/ratatui/protocol.d.ts +11 -1
  219. package/dist/ui/ratatui/protocol.js +6 -0
  220. package/dist/ui/ratatui/ztc_launch_trust.d.ts +87 -0
  221. package/dist/ui/ratatui/ztc_launch_trust.js +249 -0
  222. package/dist/utils/admitted_open.d.ts +40 -0
  223. package/dist/utils/admitted_open.js +111 -0
  224. package/dist/utils/clipboard.js +2 -1
  225. package/dist/utils/computer_native.js +12 -56
  226. package/dist/utils/dictation.js +15 -12
  227. package/dist/utils/dictation_native.js +17 -60
  228. package/dist/utils/git_probe_options.d.ts +28 -0
  229. package/dist/utils/git_probe_options.js +30 -0
  230. package/dist/utils/git_program_files.d.ts +145 -0
  231. package/dist/utils/git_program_files.js +1282 -0
  232. package/dist/utils/git_repository_programs.d.ts +13 -0
  233. package/dist/utils/git_repository_programs.js +38 -0
  234. package/dist/utils/host_shell.js +2 -1
  235. package/dist/utils/idle_compaction.js +8 -1
  236. package/dist/utils/image_fit.d.ts +4 -1
  237. package/dist/utils/image_fit.js +6 -2
  238. package/dist/utils/image_preview.js +3 -2
  239. package/dist/utils/mirror_media.d.ts +22 -4
  240. package/dist/utils/mirror_media.js +87 -86
  241. package/dist/utils/ml_native.js +11 -56
  242. package/dist/utils/native_install.d.ts +55 -0
  243. package/dist/utils/native_install.js +107 -0
  244. package/dist/utils/open_url.js +2 -0
  245. package/dist/utils/process_end.d.ts +16 -0
  246. package/dist/utils/process_end.js +73 -0
  247. package/dist/utils/router_catalog.js +9 -2
  248. package/dist/utils/sandbox.d.ts +64 -1
  249. package/dist/utils/sandbox.js +397 -89
  250. package/dist/utils/shell.js +31 -12
  251. package/dist/utils/subprocess_env.d.ts +218 -2
  252. package/dist/utils/subprocess_env.js +429 -11
  253. package/dist/utils/system_ps.d.ts +5 -0
  254. package/dist/utils/system_ps.js +30 -0
  255. package/dist/utils/tts.js +5 -0
  256. package/dist/utils/tts_native.js +13 -60
  257. package/dist/utils/zlicky_overlay.js +17 -50
  258. package/dist/utils/ztc_own_state.d.ts +58 -0
  259. package/dist/utils/ztc_own_state.js +236 -0
  260. package/dist/web/mirror_authenticator.d.ts +67 -6
  261. package/dist/web/mirror_authenticator.js +131 -22
  262. package/dist/web/mirror_stream.d.ts +54 -10
  263. package/dist/web/mirror_stream.js +379 -92
  264. package/dist/web/observer_query_redaction.js +53 -13
  265. package/dist/web/observer_secret_redaction.d.ts +59 -0
  266. package/dist/web/observer_secret_redaction.js +714 -0
  267. package/dist/web/pane_credentials.d.ts +20 -2
  268. package/dist/web/pane_credentials.js +58 -5
  269. package/dist/worker/executor.js +3 -1
  270. package/dist/workspace_collision.js +19 -15
  271. package/dist/zerg/local_zerg_launches.d.ts +27 -0
  272. package/dist/zerg/local_zerg_launches.js +198 -0
  273. package/dist/zlm-embed.mjs +6257 -2791
  274. package/npm-shrinkwrap.json +1 -1
  275. package/package.json +42 -15
@@ -12,17 +12,60 @@ import { spawn } from 'child_process';
12
12
  import { randomUUID } from 'node:crypto';
13
13
  import { existsSync, unlinkSync } from 'fs';
14
14
  import { createInterface } from 'readline';
15
- import { join, dirname, resolve } from 'path';
16
- import { homedir, platform, arch } from 'os';
17
- import { fileURLToPath } from 'url';
15
+ import { join } from 'path';
16
+ import { homedir, platform } from 'os';
18
17
  import { createConnection } from 'net';
19
18
  import { serializeCommand, parseEvent, CAPABILITY_CLIPBOARD_IMAGE, CAPABILITY_CLIPBOARD_TEXT } from './protocol.js';
20
19
  import { generateIpcPath, removeOwnedIpcPath } from './ipc_path.js';
21
20
  import { loadDesktopRuntime, validateDesktopRendererReady } from '../../desktop/runtime.js';
22
21
  import { debugFileLog as debugLog, describeInputForLog } from '../../utils/debug_log.js';
23
22
  import { rendererOpensInBackground } from '../../utils/session_interactivity.js';
23
+ import { HOST_HANDOFF_FLAG, removeHostHandoff, writeHostHandoff } from '../../config/host_credentials.js';
24
+ import { buildRendererEnv, ztcChildCredentialEnv } from '../../utils/subprocess_env.js';
24
25
  import { withoutMirrorCredentials } from '../../web/pane_credentials.js';
25
- import { PaneCredentialBroker } from './pane_credential_broker.js';
26
+ import { findNativeProgram, isPackedZtcInstall, nativeProgramBuildCommand, packagedName } from '../../utils/native_install.js';
27
+ import { isOwnersCommand, isZtcLaunchTrusted, PaneCredentialBroker } from './pane_credential_broker.js';
28
+ /**
29
+ * CMD, a create_pane for this renderer, with what a ZTC pane or colony cell it starts is given of ZTC's credentials
30
+ * (ztcChildCredentialEnv) in its environment: the renderer starts it with its own environment, which holds none of them.
31
+ * A pane a pane asks the relay to open is given them only on a launch nonce the relay issued (isZtcLaunchTrusted), as
32
+ * the headless pane manager checks too, whatever type it names. The command's marks (a pane relay's, see markRelayed)
33
+ * stay on it.
34
+ */
35
+ function withZtcChildCredentials(cmd) {
36
+ if (!isZtcLaunchTrusted(cmd))
37
+ return cmd;
38
+ const credentials = ztcChildCredentialEnv(cmd.pane_type);
39
+ if (Object.keys(credentials).length === 0)
40
+ return cmd;
41
+ const given = { ...cmd, env: { ...(cmd.env ?? {}), ...credentials } };
42
+ for (const symbol of Object.getOwnPropertySymbols(cmd))
43
+ Object.defineProperty(given, symbol, Object.getOwnPropertyDescriptor(cmd, symbol));
44
+ return given;
45
+ }
46
+ /**
47
+ * CMD, a replace_pane for this renderer, with what a ZTC pane or colony cell is given of ZTC's credentials
48
+ * (ztcChildCredentialEnv) as a create_pane gives it (withZtcChildCredentials), and the handoff they went in. A
49
+ * replace_pane carries no environment, and the renderer starts the pane's program again with its own environment
50
+ * alone, which holds none of them: so they go in a one-time owner-only handoff named among the program's options
51
+ * (HOST_HANDOFF_FLAG), never on its command line. A ZTC pane opened with a task ends its command line with an end of
52
+ * options ('--') and the task, literal text, so the flag goes before the two. Only the owner's own replacement of a
53
+ * ZTC pane is given them: one a pane sends through the relay, a pane of any other type, and a replacement with no
54
+ * program get none.
55
+ */
56
+ function withZtcChildHandoff(cmd) {
57
+ if (!cmd.command || (cmd.pane_type !== 'ztc' && cmd.pane_type !== 'colony_ztc') || !isOwnersCommand(cmd))
58
+ return { command: cmd };
59
+ const handoff = writeHostHandoff(ztcChildCredentialEnv(cmd.pane_type));
60
+ if (!handoff)
61
+ return { command: cmd };
62
+ const args = cmd.args ?? [];
63
+ const option = [HOST_HANDOFF_FLAG, handoff];
64
+ const given = { ...cmd, args: args.at(-2) === '--' ? [...args.slice(0, -2), ...option, ...args.slice(-2)] : [...args, ...option] };
65
+ for (const symbol of Object.getOwnPropertySymbols(cmd))
66
+ Object.defineProperty(given, symbol, Object.getOwnPropertyDescriptor(cmd, symbol));
67
+ return { command: given, handoff };
68
+ }
26
69
  /** Renderer events that carry no user text, logged whole. */
27
70
  const PLAIN_RENDERER_EVENTS = new Set(['ready', 'resize', 'resize_ack', 'quit_requested']);
28
71
  /**
@@ -37,161 +80,20 @@ function describeRendererLine(line, event) {
37
80
  return `input ${describeInputForLog(event.input, event.paste)}`;
38
81
  return PLAIN_RENDERER_EVENTS.has(event.type) ? line : `${event.type} ${line.length} bytes`;
39
82
  }
40
- const __filename = fileURLToPath(import.meta.url);
41
- const __dirname = dirname(__filename);
42
- /**
43
- * Get the platform-specific binary name
44
- */
45
- function getBinaryName() {
46
- const p = platform();
47
- const a = arch();
48
- let os;
49
- switch (p) {
50
- case 'darwin':
51
- os = 'darwin';
52
- break;
53
- case 'linux':
54
- os = 'linux';
55
- break;
56
- case 'win32':
57
- os = 'win';
58
- break;
59
- default:
60
- os = p;
61
- }
62
- let cpu;
63
- switch (a) {
64
- case 'x64':
65
- cpu = 'x64';
66
- break;
67
- case 'arm64':
68
- cpu = 'arm64';
69
- break;
70
- default:
71
- cpu = a;
72
- }
73
- const ext = p === 'win32' ? '.exe' : '';
74
- return `ztc-tui-${os}-${cpu}${ext}`;
75
- }
76
- function candidateProjectRoots() {
77
- const anchors = [
78
- __dirname,
79
- process.argv[1] ? dirname(resolve(process.argv[1])) : null,
80
- ].filter((anchor) => !!anchor);
81
- const roots = [];
82
- const seen = new Set();
83
- for (const anchor of anchors) {
84
- let current = resolve(anchor);
85
- while (!seen.has(current)) {
86
- seen.add(current);
87
- roots.push(current);
88
- const parent = dirname(current);
89
- if (parent === current)
90
- break;
91
- current = parent;
92
- }
93
- }
94
- return roots;
95
- }
96
- function findRustBinaryPath(roots, packageName, executableName, packagedBinaryName) {
97
- const possiblePaths = [
98
- join(__dirname, '..', '..', '..', 'bin', packagedBinaryName),
99
- ];
100
- for (const root of roots) {
101
- possiblePaths.push(join(root, 'packages', packageName, 'target', 'release', executableName), join(root, 'packages', packageName, 'target', 'debug', executableName), join(root, 'bin', packagedBinaryName));
102
- }
103
- possiblePaths.push(join(homedir(), '.ztc', 'bin', packagedBinaryName));
104
- const seen = new Set();
105
- for (const path of possiblePaths) {
106
- if (seen.has(path))
107
- continue;
108
- seen.add(path);
109
- if (existsSync(path)) {
110
- return path;
111
- }
112
- }
113
- return null;
114
- }
115
83
  /**
116
- * Get the path to the ztc-tui binary. Binary discovery must not depend on
117
- * process.cwd(): child-pane launch code may intentionally strip or override
118
- * cwd, and tests simulate parent cwd changes. Walk upward from stable module /
119
- * entrypoint anchors instead.
84
+ * Get the path to the ztc-tui binary, from ZTC's own install only (utils/native_install.ts findNativeProgram): the
85
+ * package's bin/ (an npm install, the npm launcher's copy, the desktop app's bundle), then, in a source checkout, the
86
+ * package's cargo build. Binary discovery never depends on process.cwd(): child-pane launch code may intentionally strip
87
+ * or override cwd, and an agent writes there, as it does ~/.ztc/bin and the folders above the install.
120
88
  */
121
89
  function getBinaryPath() {
122
- const binaryName = getBinaryName();
123
- return findRustBinaryPath(candidateProjectRoots(), 'ztc-tui', 'ztc-tui', binaryName);
124
- }
125
- /**
126
- * Get the platform-specific zmux binary name
127
- */
128
- function getZmuxBinaryName() {
129
- const p = platform();
130
- const a = arch();
131
- let os;
132
- switch (p) {
133
- case 'darwin':
134
- os = 'darwin';
135
- break;
136
- case 'linux':
137
- os = 'linux';
138
- break;
139
- case 'win32':
140
- os = 'win';
141
- break;
142
- default: os = p;
143
- }
144
- let cpu;
145
- switch (a) {
146
- case 'x64':
147
- cpu = 'x64';
148
- break;
149
- case 'arm64':
150
- cpu = 'arm64';
151
- break;
152
- default: cpu = a;
153
- }
154
- const ext = p === 'win32' ? '.exe' : '';
155
- return `zmux-${os}-${cpu}${ext}`;
90
+ return findNativeProgram('ztc-tui');
156
91
  }
157
92
  /**
158
- * Get the path to the zmux binary
93
+ * Get the path to the zmux binary, from ZTC's own install only (findNativeProgram), as ztc-tui's.
159
94
  */
160
95
  export function getZmuxBinaryPath() {
161
- const binaryName = getZmuxBinaryName();
162
- return findRustBinaryPath(candidateProjectRoots(), 'zmux', 'zmux', binaryName);
163
- }
164
- /**
165
- * Get the platform-specific zterm binary name
166
- */
167
- function getZtermBinaryName() {
168
- const p = platform();
169
- const a = arch();
170
- let os;
171
- switch (p) {
172
- case 'darwin':
173
- os = 'darwin';
174
- break;
175
- case 'linux':
176
- os = 'linux';
177
- break;
178
- case 'win32':
179
- os = 'win';
180
- break;
181
- default: os = p;
182
- }
183
- let cpu;
184
- switch (a) {
185
- case 'x64':
186
- cpu = 'x64';
187
- break;
188
- case 'arm64':
189
- cpu = 'arm64';
190
- break;
191
- default: cpu = a;
192
- }
193
- const ext = p === 'win32' ? '.exe' : '';
194
- return `zterm-${os}-${cpu}${ext}`;
96
+ return findNativeProgram('zmux');
195
97
  }
196
98
  /** Resolve the executable inside a standard installed ZTerm.app bundle. */
197
99
  export function resolveInstalledZtermExecutable(userHome = homedir(), pathExists = existsSync) {
@@ -219,12 +121,12 @@ function getZtermBinaryPath(admission) {
219
121
  const runtime = admission === undefined ? loadDesktopRuntime() : admission;
220
122
  if (runtime)
221
123
  return runtime.rendererPath;
222
- const binaryName = getZtermBinaryName();
223
124
  return resolveZtermBinaryPath({
224
125
  operatingSystem: platform(),
225
126
  userHome: homedir(),
226
127
  pathExists: existsSync,
227
- resolveFallback: () => findRustBinaryPath(candidateProjectRoots(), 'zterm', 'zterm', binaryName),
128
+ // Else ZTC's own install's (findNativeProgram), as ztc-tui's.
129
+ resolveFallback: () => findNativeProgram('zterm'),
228
130
  });
229
131
  }
230
132
  /**
@@ -246,7 +148,7 @@ export function isZtermAvailable(admission) {
246
148
  export async function launchZtermDesktop(options) {
247
149
  const binaryPath = getZtermBinaryPath();
248
150
  if (!binaryPath) {
249
- throw new Error('zterm binary not found. Build with: cd packages/zterm && cargo build --release');
151
+ throw new Error(`zterm binary not found. Build with: ${nativeProgramBuildCommand('zterm')}`);
250
152
  }
251
153
  const spawnArgs = options?.args ?? [];
252
154
  const child = spawn(binaryPath, spawnArgs, {
@@ -294,6 +196,25 @@ export function isTTY() {
294
196
  export function isRatatuiBinaryAvailable() {
295
197
  return getBinaryPath() !== null;
296
198
  }
199
+ /**
200
+ * Why no ZTC pane opens where this install has no ztc-tui (isRatatuiBinaryAvailable): create_ztc_pane's refusal, and the
201
+ * pane relay's to a launch nonce asked for one. A source checkout is told to build it; a packed install, which would never
202
+ * run that build (utils/native_install.ts), that it ships none.
203
+ */
204
+ export function ztcPaneRendererMissing() {
205
+ return isPackedZtcInstall()
206
+ ? `ZTC child panes require the Rust ztc-tui binary, which this ZTC install does not ship (bin/${packagedName('ztc-tui')}).`
207
+ : `ZTC child panes require the Rust ztc-tui binary. Build it with \`${nativeProgramBuildCommand('ztc-tui')}\`.`;
208
+ }
209
+ /**
210
+ * Why RENDERER can't start: in a source checkout, the cargo build to make; in a packed install, which would never run
211
+ * that build, that it ships none (bin/<name>-<os>-<cpu>).
212
+ */
213
+ function rendererMissing(renderer) {
214
+ return isPackedZtcInstall()
215
+ ? `${renderer} binary not found: this ZTC install does not ship bin/${packagedName(renderer)}.`
216
+ : `${renderer} binary not found. Build with: ${nativeProgramBuildCommand(renderer)}`;
217
+ }
297
218
  /**
298
219
  * Check if the Ratatui TUI renderer is available
299
220
  * Requires both the binary to exist and a TTY to be present
@@ -399,6 +320,12 @@ export class TuiProcess {
399
320
  * (see PaneCredentialBroker).
400
321
  */
401
322
  paneCredentials = new PaneCredentialBroker(() => this.rendererMirrorPort);
323
+ /**
324
+ * The one-time handoff of ZTC's credentials each ZTC pane the renderer started again in place was given, by pane id
325
+ * (withZtcChildHandoff): its program takes it as it starts, and one it never took goes when the pane closes, or
326
+ * when the renderer is gone.
327
+ */
328
+ hostHandoffs = new Map();
402
329
  /**
403
330
  * In-flight `read_clipboard_image` requests, keyed by request id. The
404
331
  * renderer answers asynchronously (it reads and PNG-encodes the clipboard
@@ -485,6 +412,17 @@ export class TuiProcess {
485
412
  }
486
413
  if (completed?.timer)
487
414
  clearTimeout(completed.timer);
415
+ // A handoff is used once: one the pane's program never took goes with its pane, or with a replacement that failed.
416
+ if (event.type === 'pane_closed')
417
+ this.releaseHostHandoff(event.pane_id);
418
+ if (completed?.hostHandoff) {
419
+ if (event.type === 'pane_created') {
420
+ this.releaseHostHandoff(event.pane_id);
421
+ this.hostHandoffs.set(event.pane_id, completed.hostHandoff);
422
+ }
423
+ else
424
+ removeHostHandoff(completed.hostHandoff);
425
+ }
488
426
  for (const handler of this.eventHandlers) {
489
427
  try {
490
428
  handler(event);
@@ -511,8 +449,14 @@ export class TuiProcess {
511
449
  pending.wireRequestId = pending.requestId;
512
450
  if (!this.socket || !this.ready)
513
451
  throw new Error('Native pane renderer unavailable');
514
- let command = pending.command.type === 'create_pane' ? this.paneCredentials.prepare(pending.command)
515
- : this.paneCredentials.prepareReplace(pending.command);
452
+ let replacement;
453
+ if (pending.command.type === 'replace_pane') {
454
+ const given = withZtcChildHandoff(pending.command);
455
+ replacement = given.command;
456
+ pending.hostHandoff = given.handoff;
457
+ }
458
+ let command = pending.command.type === 'create_pane' ? this.paneCredentials.prepare(withZtcChildCredentials(pending.command))
459
+ : this.paneCredentials.prepareReplace(replacement);
516
460
  if (command.request_id !== undefined && this.timedOutPaneRequestIds.has(command.request_id))
517
461
  command = { ...command, request_id: randomUUID() };
518
462
  pending.wireRequestId = command.request_id;
@@ -520,6 +464,14 @@ export class TuiProcess {
520
464
  pending.timer.unref();
521
465
  this.socket.write(serializeCommand(command) + '\n');
522
466
  }
467
+ /** Remove the handoff pane PANE_ID was given when it was started again in place, if its program never took it. */
468
+ releaseHostHandoff(paneId) {
469
+ const handoff = this.hostHandoffs.get(paneId);
470
+ if (handoff === undefined)
471
+ return;
472
+ this.hostHandoffs.delete(paneId);
473
+ removeHostHandoff(handoff);
474
+ }
523
475
  timeoutPaneMutation(pending) {
524
476
  if (!this.pendingPaneCreations.has(pending) || !pending.dispatched)
525
477
  return;
@@ -613,7 +565,7 @@ export class TuiProcess {
613
565
  const runtime = options?.desktopRuntime === undefined ? loadDesktopRuntime() : options.desktopRuntime;
614
566
  binaryPath = runtime?.rendererPath ?? this.options.desktopBinaryPath ?? getZtermBinaryPath(runtime);
615
567
  if (!binaryPath) {
616
- throw new Error('zterm binary not found. Build with: cd packages/zterm && cargo build --release');
568
+ throw new Error(`zterm binary not found. Build with: ${nativeProgramBuildCommand('zterm')}`);
617
569
  }
618
570
  if (runtime)
619
571
  this.desktopCompatibility = { version: runtime.rendererVersion, requiredCapabilities: runtime.requiredCapabilities };
@@ -623,13 +575,13 @@ export class TuiProcess {
623
575
  else if (this._muxMode) {
624
576
  binaryPath = getZmuxBinaryPath();
625
577
  if (!binaryPath) {
626
- throw new Error('zmux binary not found. Build with: cd packages/zmux && cargo build --release');
578
+ throw new Error(rendererMissing('zmux'));
627
579
  }
628
580
  }
629
581
  else {
630
582
  binaryPath = getBinaryPath();
631
583
  if (!binaryPath) {
632
- throw new Error('ztc-tui binary not found. Build with: cd packages/ztc-tui && cargo build --release');
584
+ throw new Error(rendererMissing('ztc-tui'));
633
585
  }
634
586
  }
635
587
  // Generate socket path
@@ -654,8 +606,14 @@ export class TuiProcess {
654
606
  if (isHeadless && !this._desktopMode)
655
607
  spawnArgs.push('--headless');
656
608
  // The renderer starts every pane it opens with its own environment plus the pane's: it is spawned without this
657
- // process's mirror credentials, so no pane can inherit them (each pane gets its own; see PaneCredentialBroker).
658
- const childEnv = withoutMirrorCredentials(process.env);
609
+ // process's mirror credentials, so no pane can inherit them (each pane gets its own; see PaneCredentialBroker),
610
+ // and without the other credentials no pane needs (buildRendererEnv). It holds no credential a ZTC pane routes
611
+ // with either: the host-credential store took the grant, the platform login and the effort policy out of
612
+ // process.env, so a ZTC pane or colony cell is given them in its create_pane environment
613
+ // (withZtcChildCredentials), or in a one-time handoff when the owner starts it again in place (withZtcChildHandoff).
614
+ // zmux's restart_pane starts a pane's program again with what its create_pane gave it over this environment,
615
+ // its pane credential blank (revoked as it starts again), and refuses a ZTC pane.
616
+ const childEnv = withoutMirrorCredentials(buildRendererEnv(process.env));
659
617
  Object.assign(childEnv, options?.env ?? {});
660
618
  // The renderer hands this port to every pane it starts, whatever this process's environment names later.
661
619
  this.rendererMirrorPort = childEnv.ZTC_MIRROR_PORT || undefined;
@@ -974,6 +932,8 @@ export class TuiProcess {
974
932
  if (pending.timer)
975
933
  clearTimeout(pending.timer);
976
934
  this.paneCredentials.failed(pending.wireRequestId);
935
+ if (pending.hostHandoff)
936
+ removeHostHandoff(pending.hostHandoff);
977
937
  this.pendingPaneCreations.delete(pending);
978
938
  }
979
939
  return false;
@@ -989,13 +949,19 @@ export class TuiProcess {
989
949
  * Clean up resources
990
950
  */
991
951
  cleanup() {
992
- for (const pending of this.pendingPaneCreations)
952
+ for (const pending of this.pendingPaneCreations) {
993
953
  if (pending.timer)
994
954
  clearTimeout(pending.timer);
955
+ if (pending.hostHandoff)
956
+ removeHostHandoff(pending.hostHandoff);
957
+ }
995
958
  this.pendingPaneCreations.clear();
996
959
  this.ready = false;
997
960
  // The renderer is gone, and with it every pane it opened.
998
961
  this.paneCredentials.revokeAll();
962
+ for (const handoff of this.hostHandoffs.values())
963
+ removeHostHandoff(handoff);
964
+ this.hostHandoffs.clear();
999
965
  // A torn-down socket can never deliver answers; release waiters.
1000
966
  for (const pending of this.clipboardRequests.values()) {
1001
967
  clearTimeout(pending.timer);
@@ -55,6 +55,12 @@ export declare const CAPABILITY_DESKTOP_RUNTIME_CHOICES = "desktop_runtime_choic
55
55
  * anything else, so the main ZTC knows which pane each child connection speaks for (see PaneRelayServer).
56
56
  */
57
57
  export declare const CAPABILITY_PANE_RELAY_IDENTITY = "pane_relay_identity_v1";
58
+ /**
59
+ * The pane relay's own (never a renderer's): it starts a ZTC pane a child asks for only on a launch nonce it issued for
60
+ * that exact launch (a `ztc_launch_nonce` line, answered with one), and any other a child asks for as a process pane
61
+ * (ztc_launch_trust.ts).
62
+ */
63
+ export declare const CAPABILITY_ZTC_LAUNCH_NONCE = "ztc_launch_nonce_v1";
58
64
  export declare const CAPABILITY_DESKTOP_SESSION_SHARE = "desktop_session_share_v1";
59
65
  export declare const CAPABILITY_TERMINAL_FRAME_METRICS = "terminal_frame_metrics_v1";
60
66
  export declare const CAPABILITY_TERMINAL_INTERACTION = "terminal_interaction_v1";
@@ -553,7 +559,9 @@ export type RustCommand = {
553
559
  } | {
554
560
  type: 'cancel_update_restart';
555
561
  message: string;
556
- } | {
562
+ }
563
+ /** `launch_nonce`: a child's, through the pane relay, which takes it off before the command goes on (ztc_launch_trust.ts). */
564
+ | {
557
565
  type: 'create_pane';
558
566
  command: string;
559
567
  args?: string[];
@@ -568,6 +576,7 @@ export type RustCommand = {
568
576
  env?: Record<string, string>;
569
577
  request_id?: string;
570
578
  persona?: string;
579
+ launch_nonce?: string;
571
580
  } | {
572
581
  type: 'create_feed_pane';
573
582
  title?: string;
@@ -623,6 +632,7 @@ export type RustCommand = {
623
632
  desktop_status?: boolean;
624
633
  content?: string;
625
634
  request_id?: string;
635
+ launch_nonce?: string;
626
636
  } | {
627
637
  type: 'list_panes';
628
638
  } | {
@@ -26,6 +26,12 @@ export const CAPABILITY_DESKTOP_RUNTIME_CHOICES = 'desktop_runtime_choices_v1';
26
26
  * anything else, so the main ZTC knows which pane each child connection speaks for (see PaneRelayServer).
27
27
  */
28
28
  export const CAPABILITY_PANE_RELAY_IDENTITY = 'pane_relay_identity_v1';
29
+ /**
30
+ * The pane relay's own (never a renderer's): it starts a ZTC pane a child asks for only on a launch nonce it issued for
31
+ * that exact launch (a `ztc_launch_nonce` line, answered with one), and any other a child asks for as a process pane
32
+ * (ztc_launch_trust.ts).
33
+ */
34
+ export const CAPABILITY_ZTC_LAUNCH_NONCE = 'ztc_launch_nonce_v1';
29
35
  export const CAPABILITY_DESKTOP_SESSION_SHARE = 'desktop_session_share_v1';
30
36
  export const CAPABILITY_TERMINAL_FRAME_METRICS = 'terminal_frame_metrics_v1';
31
37
  export const CAPABILITY_TERMINAL_INTERACTION = 'terminal_interaction_v1';
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Which launches a pane relay's owner starts as ZTC panes, which are given its Router runtime grant
3
+ * (hostRouterGrantForZtcChild): those it decides are ZTC's own, never because a child of the relay says so.
4
+ *
5
+ * Every program in a pane the main ZTC runs can reach the relay's socket (relay_policy.ts), and a pane's type is only
6
+ * what its sender wrote. A create_pane or replace_pane that arrives through the relay as a ZTC pane (pane_type ztc or
7
+ * colony_ztc) therefore starts as a plain process pane, with a user subprocess's environment, unless it carries a launch
8
+ * nonce: one the relay issued, to that connection, a moment before, for that exact command and those exact arguments,
9
+ * and only for a launch that runs ZTC from the install this process runs from (ownZtcLaunch). A nonce is good once, and
10
+ * what it starts is the install's own program as this process found it, never the paths the client named, which it
11
+ * can point elsewhere once the nonce is issued, nor a motsi the client named.
12
+ * A ZTC pane's own pane tools ask for one as they open a ZTC pane through the relay (PaneRelayClient), as do the
13
+ * workspace tools of a Claude Code or Codex pane; ZTC's own launches that reach the renderer through its own transport
14
+ * (its agent's create_ztc_pane, the person's splits and the colony's cells) never pass through the relay.
15
+ */
16
+ /** A ZTC entry point by its name, as a ZTC pane's command line names it. */
17
+ export declare const CHILD_ZTC_SCRIPT_RE: RegExp;
18
+ /**
19
+ * The entry point a ZTC pane this process opens runs: the host's ZTC_CHILD_ENTRYPOINT (a colony cell's worktree ZTC),
20
+ * else this process's own, else a checkout's in the working directory, for a process not started from one.
21
+ */
22
+ export declare function resolveChildZtcEntrypoint(): string | null;
23
+ /** A program that is ZTC: a command and the arguments it starts with (its entry point, or the desktop app's CLI flag). */
24
+ export interface ZtcProgram {
25
+ readonly command: string;
26
+ readonly lead: readonly string[];
27
+ }
28
+ /**
29
+ * The ZTC this process launches its own ZTC panes with (panes/ztc_launch.ts buildZtcPaneLaunchCommand): the entry point
30
+ * its panes run (resolveChildZtcEntrypoint) and the one it runs itself, each under the Node it runs on, or a checkout's
31
+ * sources under the tsx beside them (npx's where there is none), and the desktop app's renderer in its CLI mode when it
32
+ * runs from the app.
33
+ */
34
+ export declare function ownZtcPrograms(): ZtcProgram[];
35
+ /**
36
+ * ZTC's own launch, as a pane relay starts it on a launch nonce (ownZtcLaunch): the command and leading arguments of the
37
+ * program this process runs ZTC with (ownZtcPrograms), then the rest of the arguments the client gave; and the title of
38
+ * the MotSi terminal the client asked to run it in, when it asked for one.
39
+ */
40
+ export interface OwnZtcLaunch {
41
+ readonly command: string;
42
+ readonly args: readonly string[];
43
+ readonly motsiTitle?: string;
44
+ }
45
+ /**
46
+ * The launch of ZTC from this process's install that COMMAND with ARGS asks for, or null when it asks for none: one of
47
+ * PROGRAMS (ownZtcPrograms) with its leading arguments, each named by the same path once links are resolved, directly
48
+ * or as MotSi runs it (`motsi run --title=… -- <program>`, panes/motsi.ts). What it returns names the program as this
49
+ * process found it, never the paths the client named, which the client could point at a program of its own once its
50
+ * nonce was issued; and it names no motsi, since the client's could be any program: whether a relayed ZTC pane runs
51
+ * inside MotSi is for the relay's owner to decide, with its own motsi (PaneRelayServer).
52
+ */
53
+ export declare function ownZtcLaunch(command: string, args: readonly string[], programs?: readonly ZtcProgram[]): OwnZtcLaunch | null;
54
+ /**
55
+ * The launch nonces a pane relay issued: each for one connection (OWNER), one command and its arguments, good once and
56
+ * for LAUNCH_NONCE_MS, with the LAUNCH the relay starts on it. A nonce presented is spent whatever it is presented with.
57
+ */
58
+ export declare class ZtcLaunchNonces<Launch> {
59
+ private readonly now;
60
+ private readonly issued;
61
+ constructor(now?: () => number);
62
+ /** A nonce for OWNER to start COMMAND with ARGS as a ZTC pane, which starts LAUNCH. */
63
+ issue(owner: object, command: string, args: readonly string[], launch: Launch): string;
64
+ /**
65
+ * The launch NONCE was issued for, when it was issued to OWNER for COMMAND with exactly ARGS and has not expired; null
66
+ * otherwise. It is spent either way.
67
+ */
68
+ redeem(nonce: string, owner: object, command: string | undefined, args: readonly string[] | undefined): Launch | null;
69
+ /** Forget every nonce OWNER holds (its connection closed). */
70
+ forget(owner: object): void;
71
+ private sweep;
72
+ }
73
+ /**
74
+ * What a ZTC pane a child opens through the relay keeps of the environment its command sends: the names ZTC's own pane
75
+ * tools send a ZTC pane (agent/tools/pane.ts childZtcPaneEnv and agentZtcPaneEnv), and only the values they send, and a
76
+ * request for the pane's own mirror credential, which the pane transport answers (pane_credential_broker.ts). Nothing
77
+ * else of it reaches the pane: not a program to preload (NODE_OPTIONS), not a PATH or another grant or Router of the
78
+ * child's choosing; the host's pin of the permission settings only as 1, which pins. The pane joins this relay
79
+ * (RELAY_PATH) when its command asks to join one. One the relay starts
80
+ * inside MotSi (THROUGH_MOTSI) has MotSi's terminal id blank (panes/motsi.ts MOTSI_PANE_ENV), as ZTC's own do. What this
81
+ * process gives one of its own ZTC panes of its grant goes in whatever the client sent: a blank for a grant that takes
82
+ * no effect, and explicit discovery with one that does (hostRouterGrantBlank, hostRouterGrantDiscovery), so a pane a
83
+ * renderer starts with this process's environment imports no plugin from where an agent writes.
84
+ */
85
+ export declare function relayedZtcPaneEnv(env: Readonly<Record<string, string>> | undefined, relayPath: string, { throughMotsi }?: {
86
+ throughMotsi?: boolean;
87
+ }): Record<string, string>;