@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
@@ -19,9 +19,9 @@ import { accessSync, chmodSync, constants, existsSync, statSync } from 'fs';
19
19
  import { delimiter, dirname, isAbsolute, join, resolve } from 'path';
20
20
  import { createRequire } from 'module';
21
21
  import { isMuxPaneRestorable, resolveMuxPersistenceOptions, sanitizeMuxSessionState, validateWorkspaceState } from './mux_persistence.js';
22
- import { buildUserSubprocessEnv, removeUserSubprocessCredentials, restoreHostEffortPolicy, restoreModelRouteCredentials } from '../../utils/subprocess_env.js';
23
- import { withoutMirrorCredentials } from '../../web/pane_credentials.js';
24
- import { PaneCredentialBroker } from './pane_credential_broker.js';
22
+ import { buildUserSubprocessEnv, hostRouterGrantForZtcChild, removeUserSubprocessCredentials, restoreHostEffortPolicy, restoreModelRouteCredentials, withoutZtcCredentials } from '../../utils/subprocess_env.js';
23
+ import { hostLaunchEnvironment } from '../../config/host_credentials.js';
24
+ import { isZtcLaunchTrusted, PaneCredentialBroker } from './pane_credential_broker.js';
25
25
  import { handleWorkspaceLayout } from '../../workspace_layout.js';
26
26
  let _ptyMod;
27
27
  function loadPty() {
@@ -102,10 +102,13 @@ export function encodeZtcPaneInput(input) {
102
102
  * Compute the env a managed pane child is spawned with.
103
103
  *
104
104
  * colony_ztc panes are framework children and inherit the full parent env,
105
- * except the parent's mirror credentials (withoutMirrorCredentials): each pane
106
- * is given a credential of its own by PaneCredentialBroker: a ZTC pane or a
107
- * workspace monitor in a one-time file its arguments name, any other pane in
108
- * `commandEnv`.
105
+ * except the credentials of ZTC's that a cell never needs
106
+ * (withoutZtcCredentials ztcChild): the parent's mirror credentials, since each
107
+ * pane is given a credential of its own by PaneCredentialBroker (a ZTC pane or
108
+ * a workspace monitor in a one-time file its arguments name, any other pane in
109
+ * `commandEnv`), the host's approval token and a runtime session secret. A
110
+ * cell is a ZTC: it keeps the Router grant it infers with (ZTC_AUTH_TOKEN) and
111
+ * its host's RPC transport.
109
112
  * Every other pane type runs as a user subprocess: ZTC infra vars
110
113
  * (ZTC_MIRROR_PORT, ZTC_PANE_RELAY, ...) are stripped via
111
114
  * buildUserSubprocessEnv so nested user processes don't inherit the parent's
@@ -116,11 +119,17 @@ export function encodeZtcPaneInput(input) {
116
119
  * inference credentials are removed from every pane except `ztc` panes, which
117
120
  * infer for themselves and reserve them again for their own tool children.
118
121
  * A host's effort policy (ZTC_EFFORT_POLICY_URL and its token) reaches `ztc`
119
- * panes and colony cells as a pair, both or neither, and no other pane.
122
+ * panes and colony cells as a pair, both or neither, and no other pane. So
123
+ * does the host's Router runtime grant, with the Router it names
124
+ * (hostRouterGrantForZtcChild), when it takes effect: merged last, so no
125
+ * `commandEnv` sends it elsewhere.
120
126
  */
121
- export function computePaneSpawnEnv(paneType, paneId, options = {}, source = process.env) {
127
+ export function computePaneSpawnEnv(paneType, paneId, options = {}, ownEnvironment = process.env) {
128
+ // This process's environment as ZTC was started with it: the host-credential store holds ZTC's credentials, and a
129
+ // ZTC child is given those it needs from there (config/host_credentials.ts).
130
+ const source = hostLaunchEnvironment(ownEnvironment);
122
131
  const env = {
123
- ...(paneType === 'colony_ztc' ? withoutMirrorCredentials(source) : buildUserSubprocessEnv(source)),
132
+ ...(paneType === 'colony_ztc' ? withoutZtcCredentials(source, { ztcChild: true }) : buildUserSubprocessEnv(source)),
124
133
  ...(paneType === 'colony_ztc' ? {} : { ZTC_HEADLESS_MUX: '1' }),
125
134
  ZTC_PANE_ID: String(paneId),
126
135
  ...(options.persona ? { ZTC_SIM_PERSONA: options.persona } : {}),
@@ -128,9 +137,11 @@ export function computePaneSpawnEnv(paneType, paneId, options = {}, source = pro
128
137
  };
129
138
  const parent = { ...source, ...(options.commandEnv ?? {}) };
130
139
  if (paneType === 'colony_ztc')
131
- return restoreHostEffortPolicy(env, parent);
140
+ return { ...restoreHostEffortPolicy(env, parent), ...hostRouterGrantForZtcChild(source) };
132
141
  const childEnv = removeUserSubprocessCredentials(env);
133
- return paneType === 'ztc' ? restoreHostEffortPolicy(restoreModelRouteCredentials(childEnv, parent), parent) : childEnv;
142
+ return paneType === 'ztc'
143
+ ? { ...restoreHostEffortPolicy(restoreModelRouteCredentials(childEnv, parent), parent), ...hostRouterGrantForZtcChild(source) }
144
+ : childEnv;
134
145
  }
135
146
  /**
136
147
  * Inverse of encodeZtcPaneInput: recover the original input from a stdin line a
@@ -195,6 +206,17 @@ function findFirstLeafId(node) {
195
206
  return node.pane_id;
196
207
  return findFirstLeafId(node.first);
197
208
  }
209
+ function layoutLeafIds(node) {
210
+ return node.type === 'leaf' ? [node.pane_id] : [...layoutLeafIds(node.first), ...layoutLeafIds(node.second)];
211
+ }
212
+ /** A copy of NODE holding only KEEP's panes: a split that loses one side is the other side. Null when none is kept. */
213
+ function keepLayoutPanes(node, keep) {
214
+ if (node.type === 'leaf')
215
+ return keep.has(node.pane_id) ? { ...node } : null;
216
+ const first = keepLayoutPanes(node.first, keep);
217
+ const second = keepLayoutPanes(node.second, keep);
218
+ return first && second ? { ...node, first, second } : first ?? second;
219
+ }
198
220
  export class HeadlessPaneManager {
199
221
  panes = new Map();
200
222
  // Keep recently closed panes so read_pane can return startup/crash tails.
@@ -452,9 +474,12 @@ export class HeadlessPaneManager {
452
474
  const title = cmd.title || cmd.command;
453
475
  const args = cmd.args || [];
454
476
  const cwd = cmd.cwd || process.cwd();
455
- // Detect whether this is a ZTC child or a generic process
456
- const isZtc = (args[0] === '--ztc-cli' || args.some(a => /cli_(main|ratatui)\.(js|ts)$/.test(a))) && args.includes('--pane');
457
- const paneType = cmd.pane_type || (isZtc ? 'ztc' : 'process');
477
+ // Detect whether this is a ZTC child or a generic process. A pane a child asks for through the relay is a ZTC pane
478
+ // only on a launch nonce the relay issued it (ztc_launch_trust.ts), whatever its type or arguments say.
479
+ const trusted = isZtcLaunchTrusted(cmd);
480
+ const isZtc = trusted && (args[0] === '--ztc-cli' || args.some(a => /cli_(main|ratatui)\.(js|ts)$/.test(a))) && args.includes('--pane');
481
+ const declaredType = cmd.pane_type || (isZtc ? 'ztc' : 'process');
482
+ const paneType = !trusted && isZtcPaneType(declaredType) ? 'process' : declaredType;
458
483
  const groupId = cmd.env?.ZTC_MIRROR_GROUP || '';
459
484
  // Reuse the shared env builder (dev's computePaneSpawnEnv) — behaviourally
460
485
  // identical to the old inline childEnv. The actual spawn (PTY-aware) lives
@@ -671,7 +696,10 @@ export class HeadlessPaneManager {
671
696
  const args = cmd.args || [];
672
697
  const cwd = cmd.cwd || process.cwd();
673
698
  const title = cmd.title || pane.title;
674
- const paneType = cmd.pane_type || pane.paneType;
699
+ // A ZTC pane a child relaunches through the relay with another program is a process pane, unless the relay issued
700
+ // that launch a nonce (ztc_launch_trust.ts).
701
+ const declaredType = cmd.pane_type || pane.paneType;
702
+ const paneType = !isZtcLaunchTrusted(cmd) && isZtcPaneType(declaredType) ? 'process' : declaredType;
675
703
  // A relaunched ZTC pane's credential is a fresh one, in a one-time file its arguments name; the program it replaced
676
704
  // never had it.
677
705
  const relaunch = this.paneCredentials.prepareRelaunch(cmd, paneType, cmd.pane_id);
@@ -1015,11 +1043,27 @@ export class HeadlessPaneManager {
1015
1043
  : undefined,
1016
1044
  });
1017
1045
  }
1018
- return sanitizeMuxSessionState({
1019
- ...structuredClone(this.workspaceMetadata),
1020
- layout: structuredClone(this.layout),
1021
- panes,
1022
- }, persistenceOptions);
1046
+ // The workspace without the panes left out above (a ZTC pane with no session link is never restored): the layout,
1047
+ // each window's, and the focus and zoom of each name only panes it describes, as a saved workspace must.
1048
+ const kept = new Set([0, ...panes.map(pane => pane.id)]);
1049
+ const metadata = structuredClone(this.workspaceMetadata);
1050
+ const layout = keepLayoutPanes(this.layout, kept) ?? { type: 'leaf', pane_id: 0 };
1051
+ if (!kept.has(metadata.focused_pane_id))
1052
+ metadata.focused_pane_id = findFirstLeafId(layout);
1053
+ if (metadata.zoomed_pane_id !== undefined && !kept.has(metadata.zoomed_pane_id))
1054
+ delete metadata.zoomed_pane_id;
1055
+ if (metadata.windows) {
1056
+ metadata.windows = metadata.windows.map(window => {
1057
+ const windowLayout = keepLayoutPanes(window.layout, kept) ?? { type: 'leaf', pane_id: 0 };
1058
+ const shown = new Set(layoutLeafIds(windowLayout));
1059
+ const described = { ...window, layout: windowLayout,
1060
+ focused_pane_id: shown.has(window.focused_pane_id) ? window.focused_pane_id : findFirstLeafId(windowLayout) };
1061
+ if (described.zoomed_pane_id !== undefined && !shown.has(described.zoomed_pane_id))
1062
+ delete described.zoomed_pane_id;
1063
+ return described;
1064
+ });
1065
+ }
1066
+ return sanitizeMuxSessionState({ ...metadata, layout, panes }, persistenceOptions);
1023
1067
  }
1024
1068
  handleGetSessionState() {
1025
1069
  this.emit({
@@ -7,18 +7,31 @@
7
7
  * `\\.\pipe\<name>` form: libuv maps a bare path into the pipe namespace itself,
8
8
  * so a filesystem-style path can never reach an AF_UNIX socket there.
9
9
  */
10
+ import { type Stats } from 'fs';
11
+ /** Where an endpoint that can't go in the temporary directory gets a private directory of its own. */
12
+ export declare const SHARED_IPC_ROOT = "/tmp";
10
13
  /**
11
14
  * Build a unique IPC endpoint name for the current process.
12
15
  *
13
16
  * A Unix socket goes in the temporary directory only while that directory is this user's alone and the address fits.
14
17
  * Anywhere else (Linux's shared /tmp, a directory others can open, an address past the limit) it gets a fresh
15
- * directory of its own in /tmp that only this user can open, which removeOwnedIpcPath retires: in a shared directory
16
- * every user sees the socket, can try it, and can take its predictable name first.
18
+ * directory of its own in /tmp that only this user can open, which removeOwnedIpcPath retires, as does this process's
19
+ * end if it is still empty then: in a shared directory every user sees the socket, can try it, and can take its
20
+ * predictable name first.
17
21
  *
18
22
  * `platformName` is injectable so both branches are directly testable rather
19
23
  * than only whichever one the host happens to run.
20
24
  */
21
25
  export declare function generateIpcPath(prefix: string, platformName?: string): string;
26
+ /** Whether ENDPOINT is in a private directory this process allocated in /tmp (generateIpcPath) and still holds. */
27
+ export declare function hasOwnIpcDirectory(endpoint: string): boolean;
28
+ /**
29
+ * Before a listener binds ENDPOINT, make its private directory again if it is gone: another process's sweep
30
+ * (sweepStaleIpcDirectories) takes an empty one untouched for ten minutes, which a start that slow had yet to listen in.
31
+ * It is made exclusively, as only this user can open it, so a directory or a link something else put in its place is
32
+ * refused, never used. An endpoint without a directory of its own is left alone.
33
+ */
34
+ export declare function restoreOwnedIpcDirectory(endpoint: string): void;
22
35
  /** Retire only directories allocated by this host, without recursive removal. */
23
36
  export declare function removeOwnedIpcPath(endpoint: string): void;
24
37
  /**
@@ -28,3 +41,29 @@ export declare function removeOwnedIpcPath(endpoint: string): void;
28
41
  * filesystem cleanup for them.
29
42
  */
30
43
  export declare function isNamedPipePath(path: string): boolean;
44
+ export interface StaleIpcSweepOptions {
45
+ /** The directory the private directories are in: /tmp, where generateIpcPath makes them. */
46
+ root?: string;
47
+ /** At most this many directories named as PREFIX's are examined, so a start stays quick however many there are. */
48
+ limit?: number;
49
+ /** One touched more recently than this is kept: its process may not have bound its socket yet. */
50
+ minAgeMs?: number;
51
+ /** How long a connection to a socket may take. One that hasn't failed by then keeps its directory. */
52
+ connectTimeoutMs?: number;
53
+ /** The filesystem's lstat (a test stands in another user's directory). */
54
+ lstat?: (path: string) => Promise<Stats>;
55
+ }
56
+ export interface StaleIpcSweepResult {
57
+ /** How many directories named as PREFIX's were examined. */
58
+ examined: number;
59
+ /** The directories removed. */
60
+ removed: string[];
61
+ }
62
+ /**
63
+ * Remove the private directories PREFIX's endpoints had in /tmp (generateIpcPath) whose processes are gone: a SIGKILL,
64
+ * a crash or a lost machine runs no cleanup, and nothing else ever removes them. Only a directory named exactly as
65
+ * generateIpcPath names one is examined, at most LIMIT of them, never a link; it is removed with its socket only when it
66
+ * certainly is a dead one (see removeIfDead), so a live process's endpoint, one still starting, and anything another
67
+ * user or program made are never touched. Each directory is tried in turn; one that can't be read is kept.
68
+ */
69
+ export declare function sweepStaleIpcDirectories(prefix: string, options?: StaleIpcSweepOptions): Promise<StaleIpcSweepResult>;
@@ -7,10 +7,20 @@
7
7
  * `\\.\pipe\<name>` form: libuv maps a bare path into the pipe namespace itself,
8
8
  * so a filesystem-style path can never reach an AF_UNIX socket there.
9
9
  */
10
- import { chmodSync, mkdtempSync, rmdirSync, statSync } from 'fs';
10
+ import { chmodSync, lstatSync, mkdirSync, mkdtempSync, rmdirSync, statSync } from 'fs';
11
+ import { lstat as lstatPath, opendir, readdir, rmdir, unlink } from 'fs/promises';
12
+ import { createConnection } from 'net';
11
13
  import { tmpdir } from 'os';
12
14
  import { join } from 'path';
15
+ import { onProcessEnd } from '../../utils/process_end.js';
16
+ /** Where an endpoint that can't go in the temporary directory gets a private directory of its own. */
17
+ export const SHARED_IPC_ROOT = '/tmp';
13
18
  const ownedEndpoints = new Map();
19
+ let retiresAtProcessEnd = false;
20
+ /** The name an endpoint's private directory starts with for PREFIX: `<channel>-` and six characters (mkdtemp's). */
21
+ function ipcChannel(prefix) {
22
+ return prefix.replace(/[^a-zA-Z0-9_-]/g, '').slice(0, 16) || 'ztc-ipc';
23
+ }
14
24
  /**
15
25
  * Whether DIRECTORY is this user's alone: a directory this user owns that no one else may open (mode 0700), as macOS's
16
26
  * per-user $TMPDIR is. Linux's shared /tmp isn't, nor is a directory that is gone.
@@ -25,13 +35,31 @@ function isPrivateDirectory(directory) {
25
35
  return false;
26
36
  }
27
37
  }
38
+ /**
39
+ * Remove each private directory this process allocated that is empty: an address it never listened on (a mux ZTC names
40
+ * its relay's before its renderer starts, and may end before the relay listens), or one whose listener has stopped. A
41
+ * directory that holds anything stays: its socket is another process's, or a listener's that retires it itself.
42
+ */
43
+ function retireOwnedIpcDirectories() {
44
+ for (const [endpoint, directory] of [...ownedEndpoints]) {
45
+ try {
46
+ rmdirSync(directory);
47
+ ownedEndpoints.delete(endpoint);
48
+ }
49
+ catch (error) {
50
+ if (error.code === 'ENOENT')
51
+ ownedEndpoints.delete(endpoint);
52
+ }
53
+ }
54
+ }
28
55
  /**
29
56
  * Build a unique IPC endpoint name for the current process.
30
57
  *
31
58
  * A Unix socket goes in the temporary directory only while that directory is this user's alone and the address fits.
32
59
  * Anywhere else (Linux's shared /tmp, a directory others can open, an address past the limit) it gets a fresh
33
- * directory of its own in /tmp that only this user can open, which removeOwnedIpcPath retires: in a shared directory
34
- * every user sees the socket, can try it, and can take its predictable name first.
60
+ * directory of its own in /tmp that only this user can open, which removeOwnedIpcPath retires, as does this process's
61
+ * end if it is still empty then: in a shared directory every user sees the socket, can try it, and can take its
62
+ * predictable name first.
35
63
  *
36
64
  * `platformName` is injectable so both branches are directly testable rather
37
65
  * than only whichever one the host happens to run.
@@ -47,13 +75,44 @@ export function generateIpcPath(prefix, platformName = process.platform) {
47
75
  // must not truncate distinct endpoints onto the same kernel address.
48
76
  if (Buffer.byteLength(requested, 'utf8') <= 103 && isPrivateDirectory(temporary))
49
77
  return requested;
50
- const channel = prefix.replace(/[^a-zA-Z0-9_-]/g, '').slice(0, 16) || 'ztc-ipc';
51
- const directory = mkdtempSync(join('/tmp', `${channel}-`));
78
+ const directory = mkdtempSync(join(SHARED_IPC_ROOT, `${ipcChannel(prefix)}-`));
52
79
  chmodSync(directory, 0o700);
53
80
  const endpoint = join(directory, 'socket');
54
81
  ownedEndpoints.set(endpoint, directory);
82
+ if (!retiresAtProcessEnd) {
83
+ retiresAtProcessEnd = true;
84
+ onProcessEnd(retireOwnedIpcDirectories);
85
+ }
55
86
  return endpoint;
56
87
  }
88
+ /** Whether ENDPOINT is in a private directory this process allocated in /tmp (generateIpcPath) and still holds. */
89
+ export function hasOwnIpcDirectory(endpoint) {
90
+ return ownedEndpoints.has(endpoint);
91
+ }
92
+ /**
93
+ * Before a listener binds ENDPOINT, make its private directory again if it is gone: another process's sweep
94
+ * (sweepStaleIpcDirectories) takes an empty one untouched for ten minutes, which a start that slow had yet to listen in.
95
+ * It is made exclusively, as only this user can open it, so a directory or a link something else put in its place is
96
+ * refused, never used. An endpoint without a directory of its own is left alone.
97
+ */
98
+ export function restoreOwnedIpcDirectory(endpoint) {
99
+ const directory = ownedEndpoints.get(endpoint);
100
+ if (!directory)
101
+ return;
102
+ try {
103
+ mkdirSync(directory, { mode: 0o700 });
104
+ chmodSync(directory, 0o700);
105
+ return;
106
+ }
107
+ catch (error) {
108
+ if (error.code !== 'EEXIST')
109
+ throw error;
110
+ }
111
+ const found = lstatSync(directory);
112
+ if (!found.isDirectory() || found.uid !== process.getuid?.() || (found.mode & 0o077) !== 0) {
113
+ throw new Error(`${directory} is no longer a directory only this user can open`);
114
+ }
115
+ }
57
116
  /** Retire only directories allocated by this host, without recursive removal. */
58
117
  export function removeOwnedIpcPath(endpoint) {
59
118
  const directory = ownedEndpoints.get(endpoint);
@@ -79,3 +138,103 @@ export function removeOwnedIpcPath(endpoint) {
79
138
  export function isNamedPipePath(path) {
80
139
  return path.startsWith('\\\\');
81
140
  }
141
+ /** Whether a connection to the socket at PATH is refused as a dead socket's is, or the socket isn't there. */
142
+ function refusesConnection(path, timeoutMs) {
143
+ return new Promise(resolve => {
144
+ const socket = createConnection(path);
145
+ const settle = (refused) => {
146
+ clearTimeout(timer);
147
+ socket.destroy();
148
+ resolve(refused);
149
+ };
150
+ // A connection that neither opens nor fails in time proves nothing: its directory stays.
151
+ const timer = setTimeout(() => settle(false), timeoutMs);
152
+ timer.unref();
153
+ socket.once('connect', () => settle(false));
154
+ socket.once('error', (error) => settle(error.code === 'ECONNREFUSED' || error.code === 'ENOENT'));
155
+ });
156
+ }
157
+ /**
158
+ * Remove DIRECTORY, a dead endpoint's private directory, and its socket, when it certainly is one: a directory (never a
159
+ * link) this user owns and only this user can open, holding nothing but a socket of this user's named `socket`, or
160
+ * nothing, untouched for MINAGEMS, whose socket refuses a connection, and that is unchanged once it has. True when it
161
+ * was removed.
162
+ */
163
+ async function removeIfDead(directory, uid, options) {
164
+ const { lstat } = options;
165
+ const found = await lstat(directory);
166
+ if (!found.isDirectory() || found.uid !== uid || (found.mode & 0o777) !== 0o700)
167
+ return false;
168
+ const entries = await readdir(directory);
169
+ if (entries.length > 1 || (entries.length === 1 && entries[0] !== 'socket'))
170
+ return false;
171
+ const socketPath = join(directory, 'socket');
172
+ const socket = entries.length === 1 ? await lstat(socketPath) : null;
173
+ if (socket && (!socket.isSocket() || socket.uid !== uid))
174
+ return false;
175
+ if (Date.now() - Math.max(found.mtimeMs, socket?.mtimeMs ?? 0) < options.minAgeMs)
176
+ return false;
177
+ if (!await refusesConnection(socketPath, options.connectTimeoutMs))
178
+ return false;
179
+ // As it was when its socket was tried: the same directory, holding the same socket or still nothing.
180
+ const now = await lstat(directory);
181
+ if (!now.isDirectory() || now.ino !== found.ino || now.dev !== found.dev)
182
+ return false;
183
+ const entriesNow = await readdir(directory);
184
+ if (entriesNow.length !== entries.length || entriesNow[0] !== entries[0])
185
+ return false;
186
+ if (socket) {
187
+ const socketNow = await lstat(socketPath);
188
+ if (!socketNow.isSocket() || socketNow.ino !== socket.ino)
189
+ return false;
190
+ await unlink(socketPath);
191
+ }
192
+ // Never recursive: anything that appeared in it since keeps it.
193
+ await rmdir(directory);
194
+ return true;
195
+ }
196
+ /**
197
+ * Remove the private directories PREFIX's endpoints had in /tmp (generateIpcPath) whose processes are gone: a SIGKILL,
198
+ * a crash or a lost machine runs no cleanup, and nothing else ever removes them. Only a directory named exactly as
199
+ * generateIpcPath names one is examined, at most LIMIT of them, never a link; it is removed with its socket only when it
200
+ * certainly is a dead one (see removeIfDead), so a live process's endpoint, one still starting, and anything another
201
+ * user or program made are never touched. Each directory is tried in turn; one that can't be read is kept.
202
+ */
203
+ export async function sweepStaleIpcDirectories(prefix, options = {}) {
204
+ const result = { examined: 0, removed: [] };
205
+ const uid = process.getuid?.();
206
+ if (uid === undefined)
207
+ return result;
208
+ const root = options.root ?? SHARED_IPC_ROOT;
209
+ const limit = options.limit ?? 500;
210
+ // A channel is letters, digits, `_` and `-` alone, none of which a pattern reads as anything but itself.
211
+ const pattern = new RegExp(`^${ipcChannel(prefix)}-[A-Za-z0-9]{6}$`);
212
+ const names = [];
213
+ try {
214
+ for await (const entry of await opendir(root)) {
215
+ if (!pattern.test(entry.name))
216
+ continue;
217
+ names.push(entry.name);
218
+ if (names.length >= limit)
219
+ break;
220
+ }
221
+ }
222
+ catch {
223
+ return result;
224
+ }
225
+ const checks = {
226
+ minAgeMs: options.minAgeMs ?? 10 * 60_000,
227
+ connectTimeoutMs: options.connectTimeoutMs ?? 1000,
228
+ lstat: options.lstat ?? ((path) => lstatPath(path)),
229
+ };
230
+ for (const name of names) {
231
+ result.examined += 1;
232
+ const directory = join(root, name);
233
+ try {
234
+ if (await removeIfDead(directory, uid, checks))
235
+ result.removed.push(directory);
236
+ }
237
+ catch { /* kept */ }
238
+ }
239
+ return result;
240
+ }
@@ -19,8 +19,9 @@
19
19
  * transport reports the pane under its sender's own (created). A ZTC pane its owner has the renderer start again in
20
20
  * place (replace_pane, through prepareReplace) gets a fresh credential the same way, in a one-time file, since
21
21
  * replace_pane carries no environment either. A closed pane's credential is revoked, and so is the credential of a pane
22
- * the renderer relaunches in place without one: zmux's restart_pane, which starts the program with the renderer's
23
- * environment alone, or a replace a pane asked for through the relay. The desktop app's restart keeps the pane's own
22
+ * the renderer relaunches in place without one: zmux's restart_pane, which starts the program again with the
23
+ * environment its create_pane gave it but the credential there blank and no credential file on its command line, or a
24
+ * replace a pane asked for through the relay. The desktop app's restart keeps the pane's own
24
25
  * environment and command line and reports no new pane: a credential the program took from a file, which it deleted,
25
26
  * is revoked as the restart is sent (restarted), since the program that starts again can't take it, and one in the
26
27
  * pane's environment stays bound, as the program starts again with it. The credential of a pane a pane opens through the
@@ -41,9 +42,16 @@ type ReplacePane = Extract<RustCommand, {
41
42
  * shape; it tells the transport the command is a pane's, which may ask for a plain credential for a pane it opens,
42
43
  * never a workspace monitor's, and only from the mirror its transport's owner runs, and gets none for a pane it
43
44
  * relaunches in place. The credential of a pane it opens records the announced pane as the pane that opened it
44
- * (PaneCredentialStore.openerOf).
45
+ * (PaneCredentialStore.openerOf). ZTC_LAUNCH says the relay issued the command a launch nonce: it starts a ZTC pane. A
46
+ * relayed command without one never does (isZtcLaunchTrusted).
45
47
  */
46
- export declare function markRelayed<T extends object>(command: T, announcedPaneId?: number | null): T;
48
+ export declare function markRelayed<T extends object>(command: T, announcedPaneId?: number | null, ztcLaunch?: boolean): T;
49
+ /**
50
+ * Whether a transport may start COMMAND as a ZTC pane (pane_type ztc or colony_ztc, or one its arguments make one):
51
+ * its owner's own command, or a relayed one the relay issued a launch nonce for. Any other relayed command starts a
52
+ * process pane, whatever its type or arguments say (ztc_launch_trust.ts).
53
+ */
54
+ export declare function isZtcLaunchTrusted(command: object): boolean;
47
55
  export declare class PaneCredentialBroker {
48
56
  private readonly inheritedMirrorPort;
49
57
  /** Credentials waiting for pane_created, by the request id the broker sent their create_pane or replace_pane under. */
@@ -123,4 +131,9 @@ export declare class PaneCredentialBroker {
123
131
  private await;
124
132
  private hold;
125
133
  }
134
+ /**
135
+ * Whether COMMAND is its transport's owner's own, not one a pane sent through the pane relay (markRelayed): only the
136
+ * owner's own replacement of a ZTC pane is handed ZTC's credentials (TuiProcess).
137
+ */
138
+ export declare function isOwnersCommand(command: object): boolean;
126
139
  export {};
@@ -19,8 +19,9 @@
19
19
  * transport reports the pane under its sender's own (created). A ZTC pane its owner has the renderer start again in
20
20
  * place (replace_pane, through prepareReplace) gets a fresh credential the same way, in a one-time file, since
21
21
  * replace_pane carries no environment either. A closed pane's credential is revoked, and so is the credential of a pane
22
- * the renderer relaunches in place without one: zmux's restart_pane, which starts the program with the renderer's
23
- * environment alone, or a replace a pane asked for through the relay. The desktop app's restart keeps the pane's own
22
+ * the renderer relaunches in place without one: zmux's restart_pane, which starts the program again with the
23
+ * environment its create_pane gave it but the credential there blank and no credential file on its command line, or a
24
+ * replace a pane asked for through the relay. The desktop app's restart keeps the pane's own
24
25
  * environment and command line and reports no new pane: a credential the program took from a file, which it deleted,
25
26
  * is revoked as the restart is sent (restarted), since the program that starts again can't take it, and one in the
26
27
  * pane's environment stays bound, as the program starts again with it. The credential of a pane a pane opens through the
@@ -39,10 +40,11 @@ const RELAYED = Symbol('ztc.paneRelayed');
39
40
  * shape; it tells the transport the command is a pane's, which may ask for a plain credential for a pane it opens,
40
41
  * never a workspace monitor's, and only from the mirror its transport's owner runs, and gets none for a pane it
41
42
  * relaunches in place. The credential of a pane it opens records the announced pane as the pane that opened it
42
- * (PaneCredentialStore.openerOf).
43
+ * (PaneCredentialStore.openerOf). ZTC_LAUNCH says the relay issued the command a launch nonce: it starts a ZTC pane. A
44
+ * relayed command without one never does (isZtcLaunchTrusted).
43
45
  */
44
- export function markRelayed(command, announcedPaneId = null) {
45
- const mark = { announcedPaneId };
46
+ export function markRelayed(command, announcedPaneId = null, ztcLaunch = false) {
47
+ const mark = { announcedPaneId, ztcLaunch };
46
48
  Object.defineProperty(command, RELAYED, { value: mark });
47
49
  return command;
48
50
  }
@@ -52,6 +54,15 @@ function relayedMark(command) {
52
54
  function isRelayed(command) {
53
55
  return relayedMark(command) !== undefined;
54
56
  }
57
+ /**
58
+ * Whether a transport may start COMMAND as a ZTC pane (pane_type ztc or colony_ztc, or one its arguments make one):
59
+ * its owner's own command, or a relayed one the relay issued a launch nonce for. Any other relayed command starts a
60
+ * process pane, whatever its type or arguments say (ztc_launch_trust.ts).
61
+ */
62
+ export function isZtcLaunchTrusted(command) {
63
+ const mark = relayedMark(command);
64
+ return mark === undefined || mark.ztcLaunch;
65
+ }
55
66
  function isZtcPane(paneType) {
56
67
  return paneType === 'ztc' || paneType === 'colony_ztc';
57
68
  }
@@ -287,3 +298,10 @@ function release(held) {
287
298
  if (held.handoff)
288
299
  removePaneCredentialHandoff(held.handoff);
289
300
  }
301
+ /**
302
+ * Whether COMMAND is its transport's owner's own, not one a pane sent through the pane relay (markRelayed): only the
303
+ * owner's own replacement of a ZTC pane is handed ZTC's credentials (TuiProcess).
304
+ */
305
+ export function isOwnersCommand(command) {
306
+ return !isRelayed(command);
307
+ }
@@ -10,6 +10,7 @@
10
10
  * so pane.ts tools work identically regardless of which is wired up.
11
11
  */
12
12
  import type { RustCommand, RustEvent } from './protocol.js';
13
+ import { type OwnZtcLaunch } from './ztc_launch_trust.js';
13
14
  export type PaneEventHandler = (event: RustEvent) => void;
14
15
  export interface PaneCommandTransport {
15
16
  isOnlyPendingPaneCreate?(requestId: string): boolean;
@@ -27,6 +28,23 @@ export interface PaneRelayHello {
27
28
  type: 'relay_hello';
28
29
  pane_id: number;
29
30
  }
31
+ /**
32
+ * A child's request for a launch nonce, on a relay that advertises CAPABILITY_ZTC_LAUNCH_NONCE: for COMMAND with ARGS,
33
+ * which the child then sends as a ZTC pane's create_pane or replace_pane, with the nonce as its launch_nonce. The relay
34
+ * answers this child alone, with `{ type: 'ztc_launch_nonce', request_id, nonce }` or an error, and forwards nothing.
35
+ */
36
+ export interface ZtcLaunchNonceRequest {
37
+ type: 'ztc_launch_nonce';
38
+ request_id?: string;
39
+ command: string;
40
+ args?: string[];
41
+ }
42
+ /** The relay's answer to a ZtcLaunchNonceRequest it issued a nonce for. */
43
+ export interface ZtcLaunchNonceAnswer {
44
+ type: 'ztc_launch_nonce';
45
+ request_id?: string;
46
+ nonce: string;
47
+ }
30
48
  /** A command a child sent, with the pane its connection announced (null when it announced none). */
31
49
  export type ChildCommandListener = (command: RustCommand, announcedPaneId: number | null) => void;
32
50
  export interface PaneRelayServerOptions {
@@ -35,7 +53,26 @@ export interface PaneRelayServerOptions {
35
53
  * Codex panes. Pane lists passed to children carry it (PaneInfo.agent_cli), so a workspace server lists them as such.
36
54
  */
37
55
  agentCliOf?: (paneId: number) => 'claude' | 'codex' | undefined;
56
+ /**
57
+ * The launch of ZTC from this process's install that COMMAND with ARGS asks for, which a launch nonce is issued for, or
58
+ * null (ownZtcLaunch).
59
+ */
60
+ ownZtcLaunch?: (command: string, args: readonly string[]) => OwnZtcLaunch | null;
61
+ /**
62
+ * The motsi this relay's owner starts the ZTC panes it opens itself through, as its MotSi remote view says
63
+ * (panes/motsi.ts remoteViewMotsi), or null. A ZTC launch a child asks for through MotSi runs inside it; with none,
64
+ * and in a process that holds a host's Router runtime grant, directly. None unless the owner names one.
65
+ */
66
+ ztcPanesThroughMotsi?: () => string | null;
38
67
  }
68
+ /**
69
+ * Once per process, as its relay starts in a private directory of its own in /tmp (generateIpcPath: Linux's shared
70
+ * /tmp, or a temporary directory others can open), remove in the background the directories there whose relays are
71
+ * gone, which a SIGKILL or a crash leaves and nothing else removes (sweepStaleIpcDirectories): a live relay's, one still
72
+ * starting and anything else are kept. A relay whose socket is in a temporary directory of this user's alone leaves
73
+ * nothing in /tmp, and sweeps nothing.
74
+ */
75
+ export declare function startStaleRelaySweep(endpoint: string): void;
39
76
  export declare class PaneRelayServer {
40
77
  private transport;
41
78
  private server;
@@ -44,7 +81,36 @@ export declare class PaneRelayServer {
44
81
  private tuiUnsubscribe;
45
82
  private readonly childCommandListeners;
46
83
  private readonly agentCliOf?;
84
+ private readonly ownZtcLaunch;
85
+ private readonly ztcPanesThroughMotsi;
86
+ /** The launch nonces this relay issued its children, each for one connection and one launch (ztc_launch_trust.ts). */
87
+ private readonly launchNonces;
47
88
  constructor(transport: PaneCommandTransport, socketPath: string, options?: PaneRelayServerOptions);
89
+ /**
90
+ * What a launch nonce for OWN starts: OWN's program, ZTC's own as this process found it, inside the motsi its owner
91
+ * starts its own ZTC panes through when the child asked for MotSi, else directly. Never inside MotSi in a process
92
+ * that holds a host's Router runtime grant, which goes to the ZTC panes it opens and no program around one: held, that
93
+ * is, in the host-credential store, which took it out of process.env as ZTC started (hostCredential). A pane that
94
+ * discovers extensions explicitly (ztcChildDiscoversExplicitly) starts without the launch flags that add an extension
95
+ * root (withoutExtensionRootFlags), as ZTC's own launches of one do: its roots are the ones its host set. And none
96
+ * starts with a handoff of variables the client's arguments name (withoutHostHandoff), which could set the Router its
97
+ * grant goes to: only ZTC writes one, for a launch of its own.
98
+ */
99
+ private relayedLaunch;
100
+ /**
101
+ * Answer CLIENT's request for a launch nonce: one for its exact command and arguments when they launch ZTC from this
102
+ * process's install (ownZtcLaunch) and this install opens ZTC panes at all, as create_ztc_pane does only with a
103
+ * ztc-tui renderer in it (isRatatuiBinaryAvailable); else an error. Either way, to this child alone.
104
+ */
105
+ private answerLaunchNonce;
106
+ /**
107
+ * What COMMAND, a create_pane or replace_pane CLIENT sent, starts: on a launch nonce this relay issued CLIENT for its
108
+ * exact command and arguments, a ZTC pane running the launch the nonce was issued for (relayedLaunch), not the
109
+ * command the client sent, with only the environment ZTC's pane tools send one (relayedZtcPaneEnv); on any other
110
+ * nonce, nothing (null: CLIENT is told why); without one, a process pane, whatever type it names (a replace that names
111
+ * none would keep the type of the pane it replaces). Any other command goes on as it is.
112
+ */
113
+ private launchTrust;
48
114
  /**
49
115
  * EVENT as children get it: a pane list says which panes run an agent CLI (see agentCliOf), and a pane's text the
50
116
  * main ZTC refuses to have read now (screen_privacy.ts), a read already on its way, comes without its content.
@@ -71,6 +137,8 @@ export declare class PaneRelayClient implements PaneCommandTransport {
71
137
  private capabilities;
72
138
  private socketPath;
73
139
  private readonly paneId;
140
+ /** ZTC pane launches waiting for the launch nonce asked for them, by the request id it was asked under. */
141
+ private readonly pendingLaunches;
74
142
  /** `paneId` is this child's pane (ZTC_PANE_ID): it names it to a relay that asks, before anything else it sends. */
75
143
  constructor(socketPath: string, options?: {
76
144
  paneId?: number;
@@ -78,6 +146,12 @@ export declare class PaneRelayClient implements PaneCommandTransport {
78
146
  /** Connect to the parent's relay socket */
79
147
  connect(): Promise<void>;
80
148
  private setupHandlers;
149
+ /**
150
+ * LINE from the relay, when it answers a launch nonce asked for: the launch waiting for it goes, with the nonce, and the
151
+ * line is this transport's own (true). A refusal goes on to the handlers as the launch's own refusal, and the launch
152
+ * is dropped.
153
+ */
154
+ private answeredLaunch;
81
155
  /** Send a pane command to the parent via relay */
82
156
  send(cmd: RustCommand): boolean;
83
157
  /** Subscribe to pane events from the parent */