@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
@@ -9,7 +9,7 @@
9
9
  import { randomUUID } from 'node:crypto';
10
10
  import { listWorkspacePanes, waitForPaneCreatedOrError } from '../agent/tools/pane.js';
11
11
  import { CAPABILITY_ATTENTION_BADGES, CAPABILITY_SYNCHRONIZED_OUTPUT } from '../ui/ratatui/protocol.js';
12
- import { AGENT_CLIS, agentCliArgs, agentPaneEnv, agentPermissionsSetting, bypassRefusal, bypassWord, choosesClaudeSession, choosesPermissions, findAgentCli, isAgentCliId, loginShellExec, nextPaneTitle, permissionDefaultArgs, workspaceMcpProgram, } from './agent_cli.js';
12
+ import { AGENT_CLIS, agentCliArgs, agentLaunchRefusal, agentLaunchRefusalMessage, agentPaneEnv, agentPermissionsSetting, bypassRefusal, bypassWord, choosesClaudeSession, choosesPermissions, findAgentCli, isAgentCliId, loginShellExec, nextPaneTitle, permissionDefaultArgs, workspaceMcpProgram, } from './agent_cli.js';
13
13
  import { sessionNamePaneTitle } from './labels.js';
14
14
  import { MOTSI_PANE_ENV, remoteViewMotsi, throughMotsi } from './motsi.js';
15
15
  import { agentProfileArgs, agentProfileClearedEnv, agentProfileEnv, ensureAgentProfile } from './agent_profiles.js';
@@ -40,6 +40,23 @@ function newSessionArgs(options) {
40
40
  return [];
41
41
  return ['--session-id', (options.newSessionId ?? randomUUID)()];
42
42
  }
43
+ /**
44
+ * panes.agentPermissions for a Claude Code or Codex pane the person opens, here or as the desktop app's native pane
45
+ * (desktop_wiring.ts): 'ask' when this process's settings say so, or config.json does as it is saved now
46
+ * (agentPermissionsSetting reads each). Every ZTC pane is its own process and reads the profile again only every few
47
+ * seconds, so another pane's 'ask' may not have reached this one yet; neither setting can turn the other's ask into
48
+ * bypass. A config.json that can't be read leaves this process's setting to decide. Where the host pinned the
49
+ * session's permission profile and sandbox (ZTC_PERMISSION_PROFILE_PINNED), no saved setting gives a pane bypass: 'ask'.
50
+ */
51
+ export async function personPanePermissions() {
52
+ if (configStore.permissionsPinned())
53
+ return 'ask';
54
+ if (agentPermissionsSetting(configStore.get().panes) === 'ask')
55
+ return 'ask';
56
+ // Whatever config.json holds: a file that holds no settings, or no panes settings, says nothing.
57
+ const saved = await configStore.readSavedSettings();
58
+ return agentPermissionsSetting(saved?.panes);
59
+ }
43
60
  /** Open the user's own `claude` or `codex` in a new pane, attached to this workspace. */
44
61
  /**
45
62
  * What a Claude Code or Codex session sets for the commands it runs, present in `env`. A ZTC started from inside one
@@ -62,6 +79,10 @@ export async function openAgentPane(transport, options) {
62
79
  return { error: `An agent can't open ${spec.label} with ${bypass}, which skips every permission check: only the person can. `
63
80
  + `Without it, ${spec.label} asks before it runs commands, as its own settings say.` };
64
81
  }
82
+ // Of the CLI's own words an agent passes only those that leave how it asks to its own settings (agentLaunchRefusal).
83
+ const refused = byPerson ? null : agentLaunchRefusal(options.cli, options.request ?? { words: [] });
84
+ if (refused)
85
+ return { error: agentLaunchRefusalMessage(options.cli, refused) };
65
86
  if (!transport || !transport.isMuxMode)
66
87
  return { error: `${spec.label} opens in a pane, which ${NEEDS_PANES}.` };
67
88
  const binary = (options.findBinary ?? findAgentCli)(options.cli);
@@ -98,7 +119,7 @@ export async function openAgentPane(transport, options) {
98
119
  ? badgedNotificationArgs(options.request?.words ?? [], configStore.get().panes)
99
120
  : [];
100
121
  // A pane an agent opens never gets ZTC's bypass: panes.agentPermissions is the person's default for their own.
101
- const permissions = byPerson ? agentPermissionsSetting(configStore.get().panes) : 'ask';
122
+ const permissions = byPerson ? await personPanePermissions() : 'ask';
102
123
  const notices = [];
103
124
  // A CLI that would refuse its bypass flag here (Claude Code as root) starts with its prompts, and the pane says why.
104
125
  const refusal = permissions === 'bypass' && !choosesPermissions(options.cli, words) ? bypassRefusal(options.cli, { env }) : null;
@@ -225,11 +246,37 @@ function parseAgentPaneAnswer(from, text) {
225
246
  return null;
226
247
  }
227
248
  /**
228
- * TEXT as one typed line: its line ends, and the spaces around them, one space, a tab a space, and no other control
229
- * character (C0, DEL or C1), which the CLI typed into would read as a key: an ESC sequence or Ctrl+C an answer quoted.
249
+ * TEXT as one typed line: its line ends (CR, LF, U+2028 and U+2029), and the spaces around them, one space, a tab a
250
+ * space, and no other control character (C0, DEL or C1), which the CLI typed into would read as a key: an ESC sequence
251
+ * or Ctrl+C an answer quoted.
230
252
  */
231
253
  function asOneLine(text) {
232
- return text.replace(/\s*[\r\n]+\s*/g, ' ').replace(/\t/g, ' ').replace(/[\u0000-\u001f\u007f-\u009f]/g, '').trim();
254
+ return text.replace(/\s*[\r\n\p{Zl}\p{Zp}]+\s*/gu, ' ').replace(/\t/g, ' ').replace(/[\u0000-\u001f\u007f-\u009f]/g, '').trim();
255
+ }
256
+ /** The longest sender name, or pane id, typed into an agent pane, in characters; a longer one is cut there and ends "…". */
257
+ export const AGENT_PANE_SENDER_MAX_CHARS = 64;
258
+ /**
259
+ * An ESC sequence (ECMA-48): a control sequence (ESC [ or C1 CSI, its parameter and intermediate bytes, its final byte),
260
+ * a control string (ESC ], P, X, ^ or _, or the C1 control that stands for one, up to BEL or ST), or another escape
261
+ * (ESC, its intermediate bytes, its final byte). One cut off before its end runs to the end of the text.
262
+ */
263
+ const ESC_SEQUENCE = /(?:\u001b\[|\u009b)[0-?]*[ -/]*[@-~]?|(?:\u001b[\]PX^_]|[\u0090\u0098\u009d-\u009f])[^\u0007\u001b\u009c]*(?:\u0007|\u001b\\|\u009c)?|\u001b[ -/]*[0-~]?/g;
264
+ /**
265
+ * FIELD, a sender's name or pane id, as one inert run of words in a line typed into a pane (an agent pane's, or the one
266
+ * formatTypedPaneMessage types into any other): no ESC sequence, whole,
267
+ * nor any other control character (C0, DEL or C1); its whitespace, line ends among it, one space; a square bracket a
268
+ * parenthesis, so it can't end the line's "[Message from …]" early nor start an "[Answer from …]" of its own; cut to
269
+ * AGENT_PANE_SENDER_MAX_CHARS characters, never inside one.
270
+ */
271
+ function asOneField(field) {
272
+ const words = field.replace(ESC_SEQUENCE, '').replace(/[\s\u0000-\u001f\u007f-\u009f]+/g, ' ').trim().replace(/\[/g, '(').replace(/\]/g, ')');
273
+ const characters = Array.from(words);
274
+ return characters.length > AGENT_PANE_SENDER_MAX_CHARS ? `${characters.slice(0, AGENT_PANE_SENDER_MAX_CHARS).join('')}…` : words;
275
+ }
276
+ /** FROM as a TypedSender; a name that is nothing once its controls go is its pane's ("pane 3"). */
277
+ function typedSender(from) {
278
+ const id = asOneField(String(from.id));
279
+ return { id, name: asOneField(from.name) || `pane ${id}` };
233
280
  }
234
281
  /** What Main's answer says, cut to AGENT_PANE_ANSWER_MAX_CHARS characters, never inside one, saying what was left out. */
235
282
  function answerLine(from, answer) {
@@ -297,10 +344,12 @@ function cutAnswer(line, paneId, read) {
297
344
  * What Main's model reads right after a message an agent pane (Claude Code, Codex) sent it, which the transcript leaves
298
345
  * out: who sent it, that Main's answer, the text the model writes in the turn, goes back to that pane when the turn
299
346
  * ends, and, when the model's send_message reaches that pane at all (HELD_SENDS: not a colony cell's, which reaches the
300
- * colony), that a message the model sends the pane during the turn follows the answer.
347
+ * colony), that a message the model sends the pane during the turn follows the answer. The sender is named as what is
348
+ * typed into a pane names it (typedSender), in one line.
301
349
  */
302
350
  export function agentPaneNoteForModel(from, heldSends = true) {
303
- const who = `${from.name} (pane ${from.id})`;
351
+ const sender = typedSender(from);
352
+ const who = `${sender.name} (pane ${sender.id})`;
304
353
  return `The message above is from ${who}, an agent in another pane. When this turn ends, ZTC sends ${who} your answer: `
305
354
  + 'the text you write in this turn. You don\'t need send_message for it.'
306
355
  + (heldSends ? ` A message you send ${who} during this turn reaches it right after your answer.` : '');
@@ -308,16 +357,19 @@ export function agentPaneNoteForModel(from, heldSends = true) {
308
357
  /**
309
358
  * A bus message as it is typed into an agent pane: one line, saying who sent
310
359
  * it and, for a question or request, how to answer; Main's answer at the end
311
- * of a turn (agentPaneAnswerText) says it is one.
360
+ * of a turn (agentPaneAnswerText) says it is one. Who sent it is named by
361
+ * typedSender: a pane's name is its own to choose, and nothing in it ends
362
+ * the line or ZTC's header.
312
363
  */
313
364
  export function formatAgentPaneMessage(message) {
314
- const who = `${message.from.name} (pane ${message.from.id})`;
365
+ const sender = typedSender(message.from);
366
+ const who = `${sender.name} (pane ${sender.id})`;
315
367
  const answer = parseAgentPaneAnswer(message.from, message.text);
316
368
  if (answer?.outcome === 'stopped')
317
369
  return `[Answer from ${who}] ${asOneLine(answer.note)}`;
318
370
  if (answer) {
319
371
  const note = 'exchangeNote' in answer && answer.exchangeNote ? ` [${asOneLine(answer.exchangeNote)}]` : '';
320
- return `[Answer from ${who}] ${answerLine(message.from, answer)}${note}`;
372
+ return `[Answer from ${who}] ${answerLine(sender, answer)}${note}`;
321
373
  }
322
374
  let text = message.text;
323
375
  let kind = 'Message';
@@ -334,7 +386,17 @@ export function formatAgentPaneMessage(message) {
334
386
  const line = asOneLine(text);
335
387
  return kind === 'Message'
336
388
  ? `[Message from ${who}] ${line}`
337
- : `[${kind} from ${who} — answer with the ztc send_message tool, to: ${message.from.id}] ${line}`;
389
+ : `[${kind} from ${who} — answer with the ztc send_message tool, to: ${sender.id}] ${line}`;
390
+ }
391
+ /**
392
+ * A bus message as it is typed into a pane that is not a Claude Code or Codex pane, a ZTC pane above all, while no
393
+ * mirror runs to carry it on a bus: "[Message from <name>]: <text>", one line, which the pane submits as its own typing.
394
+ * Who sent it is named by typedSender, and its text is made one line by asOneLine, as formatAgentPaneMessage's is: a
395
+ * line break submits what came before it, so a line of it would reach the pane on its own, as the person's (a slash
396
+ * command among them), and an ESC sequence or Ctrl+C would reach a program that isn't reading a paste as a key.
397
+ */
398
+ export function formatTypedPaneMessage(message) {
399
+ return `[Message from ${typedSender(message.from).name}]: ${asOneLine(message.text)}`;
338
400
  }
339
401
  /** Delay between typed text and its Enter for programs that read a burst of input as a paste. */
340
402
  export const TYPED_ENTER_DELAY_MS = 120;
@@ -0,0 +1,8 @@
1
+ import type { PaneProgram } from './agent_cli.js';
2
+ /**
3
+ * The program a pane runs to open FILE in EDITOR, the person's $EDITOR. ZTC runs $EDITOR as git does: a value with no
4
+ * blank or shell character is the program, and any other value is a shell command that sh runs with FILE after it as
5
+ * "$@", so `code --wait`, `subl -w` and `emacsclient -t` work, and so does a program path in quotes. A value that is
6
+ * the absolute path of an executable file is that program all the same, spaces and all.
7
+ */
8
+ export declare function editorProgram(editor: string, file: string): PaneProgram;
@@ -0,0 +1,25 @@
1
+ import { accessSync, constants, statSync } from 'fs';
2
+ import { isAbsolute } from 'path';
3
+ /** The characters that make git run an $EDITOR value through the shell (run-command.c, prepare_shell_cmd). */
4
+ const SHELL_CHARACTERS = /[|&;<>()$`\\"' \t\n*?[#~=%]/;
5
+ function isExecutableFile(path) {
6
+ try {
7
+ accessSync(path, constants.X_OK);
8
+ return statSync(path).isFile();
9
+ }
10
+ catch {
11
+ return false;
12
+ }
13
+ }
14
+ /**
15
+ * The program a pane runs to open FILE in EDITOR, the person's $EDITOR. ZTC runs $EDITOR as git does: a value with no
16
+ * blank or shell character is the program, and any other value is a shell command that sh runs with FILE after it as
17
+ * "$@", so `code --wait`, `subl -w` and `emacsclient -t` work, and so does a program path in quotes. A value that is
18
+ * the absolute path of an executable file is that program all the same, spaces and all.
19
+ */
20
+ export function editorProgram(editor, file) {
21
+ if (!SHELL_CHARACTERS.test(editor) || (isAbsolute(editor) && isExecutableFile(editor))) {
22
+ return { command: editor, args: [file] };
23
+ }
24
+ return { command: '/bin/sh', args: ['-c', `${editor} "$@"`, editor, file] };
25
+ }
@@ -16,6 +16,13 @@
16
16
  * sessions start without it, and so does a custom pane running MotSi itself
17
17
  * (runsMotsi). ZTC reads only that switch from MotSi's settings, nothing else
18
18
  * of MotSi's.
19
+ *
20
+ * A ZTC that holds its host's Router runtime grant (a resident) starts no pane
21
+ * through MotSi: motsi is a program of its own, found where an agent writes
22
+ * (PATH, ~/go/bin, ~/.local/bin), its switch is a file there too, and a ZTC
23
+ * pane wrapped in it would hand it the grant the pane is given. Such a ZTC
24
+ * starts each pane directly, a ZTC pane with the grant handed over explicitly,
25
+ * as its own launches are. A ZTC with no grant finds MotSi as it always has.
19
26
  */
20
27
  import type { PaneProgram } from './agent_cli.js';
21
28
  export interface MotsiLookup {
@@ -30,7 +37,10 @@ export declare function findMotsi(lookup?: MotsiLookup): string | null;
30
37
  * `$XDG_CONFIG_HOME/motsi`, else `~/.config/motsi`, the first of those that is set. Anything but a true is off.
31
38
  */
32
39
  export declare function motsiRemoteViewOn(lookup?: MotsiLookup): boolean;
33
- /** The `motsi` to start panes through, or null when panes start as they always have. */
40
+ /**
41
+ * The `motsi` to start panes through, or null when panes start as they always have; always null while this ZTC holds
42
+ * its host's Router runtime grant (the host-credential store's, config/host_credentials.ts), whatever MotSi says.
43
+ */
34
44
  export declare function remoteViewMotsi(panes: {
35
45
  remoteView?: boolean;
36
46
  } | undefined, lookup?: MotsiLookup): string | null;
@@ -16,10 +16,18 @@
16
16
  * sessions start without it, and so does a custom pane running MotSi itself
17
17
  * (runsMotsi). ZTC reads only that switch from MotSi's settings, nothing else
18
18
  * of MotSi's.
19
+ *
20
+ * A ZTC that holds its host's Router runtime grant (a resident) starts no pane
21
+ * through MotSi: motsi is a program of its own, found where an agent writes
22
+ * (PATH, ~/go/bin, ~/.local/bin), its switch is a file there too, and a ZTC
23
+ * pane wrapped in it would hand it the grant the pane is given. Such a ZTC
24
+ * starts each pane directly, a ZTC pane with the grant handed over explicitly,
25
+ * as its own launches are. A ZTC with no grant finds MotSi as it always has.
19
26
  */
20
27
  import { accessSync, constants, readFileSync, statSync } from 'node:fs';
21
28
  import { homedir } from 'node:os';
22
29
  import { basename, join } from 'node:path';
30
+ import { hostCredential, ROUTER_RUNTIME_GRANT_ENV } from '../config/host_credentials.js';
23
31
  const SYSTEM_BIN_DIRS = ['/opt/homebrew/bin', '/usr/local/bin', '/usr/bin'];
24
32
  function isExecutableFile(path) {
25
33
  try {
@@ -64,10 +72,15 @@ export function motsiRemoteViewOn(lookup = {}) {
64
72
  return false;
65
73
  }
66
74
  }
67
- /** The `motsi` to start panes through, or null when panes start as they always have. */
75
+ /**
76
+ * The `motsi` to start panes through, or null when panes start as they always have; always null while this ZTC holds
77
+ * its host's Router runtime grant (the host-credential store's, config/host_credentials.ts), whatever MotSi says.
78
+ */
68
79
  export function remoteViewMotsi(panes, lookup = {}) {
69
80
  if (panes?.remoteView === false)
70
81
  return null;
82
+ if (hostCredential(ROUTER_RUNTIME_GRANT_ENV)?.trim())
83
+ return null;
71
84
  if (!motsiRemoteViewOn(lookup))
72
85
  return null;
73
86
  return findMotsi(lookup);
@@ -1,4 +1,4 @@
1
- import type { NativeToolPaneRecord } from '../desktop/daily/native_tool.js';
1
+ import type { NativeTool, NativeToolPaneRecord } from '../desktop/daily/native_tool.js';
2
2
  import type { MuxPaneState, MuxSessionState } from '../ui/ratatui/protocol.js';
3
3
  import type { NativePaneLaunchSpec, PaneLaunchSpec, PaneRunStatus, PaneRuntimeRecord, PaneSessionSpec, PaneType } from './types.js';
4
4
  /**
@@ -9,6 +9,33 @@ import type { NativePaneLaunchSpec, PaneLaunchSpec, PaneRunStatus, PaneRuntimeRe
9
9
  export declare function isNativeZtcPane(pane: PaneRuntimeRecord | undefined): pane is PaneRuntimeRecord & {
10
10
  launchSpec: NativePaneLaunchSpec;
11
11
  };
12
+ /**
13
+ * What a native pane that takes no agent's message runs (nativeNonAgentPane): Claude Code, Codex or a shell, interactive,
14
+ * or any tool, delegated.
15
+ */
16
+ export type NativeNonAgentPane = {
17
+ tool: Exclude<NativeTool, 'ztc'>;
18
+ mode: 'interactive';
19
+ } | {
20
+ tool: NativeTool;
21
+ mode: 'delegated';
22
+ };
23
+ /**
24
+ * The tool and mode of `pane` when it is one of the desktop app's native panes that takes no agent's message (the bus's
25
+ * not_an_agent): an interactive Claude Code, Codex or shell pane, which is for the person's typing (the desktop labels
26
+ * it "human input only", and starts Claude Code and Codex there without workspace-mcp) and takes typing, not messages:
27
+ * type_into_pane and write_terminal_pane type into it as into any pane; or any delegated pane,
28
+ * which shows a worker's untrusted feed and takes no input. Undefined for a native ZTC pane, an agent that joins the
29
+ * mirror as itself (isNativeZtcPane), and for any pane ZTC registered itself.
30
+ */
31
+ export declare function nativeNonAgentPane(pane: PaneRuntimeRecord | undefined): NativeNonAgentPane | undefined;
32
+ /**
33
+ * Whether `pane` runs a ZTC agent, by ZTC's own record of it: a ZTC pane or a colony cell, by its type, or a native ZTC
34
+ * pane (isNativeZtcPane), a process pane by its type. While ZTC runs no mirror, these are the panes besides Claude Code
35
+ * and Codex panes that Main's message is typed into (typeOverseerMessage), as the bus would deliver it to them; a shell,
36
+ * a command or another program's pane, which would take it as its own input, is not one, nor is a pane with no record.
37
+ */
38
+ export declare function runsZtcAgent(pane: PaneRuntimeRecord | undefined): boolean;
12
39
  /**
13
40
  * The Zerg Router origin a native pane's record was launched with (its --router-url), if it names one: read from the
14
41
  * record the desktop's native owner launched, since a record kept or saved is rebuilt from its recipe, without its
@@ -22,6 +22,31 @@ export function isNativeZtcPane(pane) {
22
22
  const launch = pane?.launchSpec?.kind === 'native_tool' ? pane.launchSpec.record.launch : undefined;
23
23
  return launch?.tool === 'ztc' && launch.mode === 'interactive';
24
24
  }
25
+ /**
26
+ * The tool and mode of `pane` when it is one of the desktop app's native panes that takes no agent's message (the bus's
27
+ * not_an_agent): an interactive Claude Code, Codex or shell pane, which is for the person's typing (the desktop labels
28
+ * it "human input only", and starts Claude Code and Codex there without workspace-mcp) and takes typing, not messages:
29
+ * type_into_pane and write_terminal_pane type into it as into any pane; or any delegated pane,
30
+ * which shows a worker's untrusted feed and takes no input. Undefined for a native ZTC pane, an agent that joins the
31
+ * mirror as itself (isNativeZtcPane), and for any pane ZTC registered itself.
32
+ */
33
+ export function nativeNonAgentPane(pane) {
34
+ if (pane?.launchSpec?.kind !== 'native_tool')
35
+ return undefined;
36
+ const { tool, mode } = pane.launchSpec.record.launch;
37
+ if (mode === 'delegated')
38
+ return { tool, mode };
39
+ return tool === 'ztc' ? undefined : { tool, mode };
40
+ }
41
+ /**
42
+ * Whether `pane` runs a ZTC agent, by ZTC's own record of it: a ZTC pane or a colony cell, by its type, or a native ZTC
43
+ * pane (isNativeZtcPane), a process pane by its type. While ZTC runs no mirror, these are the panes besides Claude Code
44
+ * and Codex panes that Main's message is typed into (typeOverseerMessage), as the bus would deliver it to them; a shell,
45
+ * a command or another program's pane, which would take it as its own input, is not one, nor is a pane with no record.
46
+ */
47
+ export function runsZtcAgent(pane) {
48
+ return pane?.paneType === 'ztc' || pane?.paneType === 'colony_ztc' || isNativeZtcPane(pane);
49
+ }
25
50
  /**
26
51
  * The Zerg Router origin a native pane's record was launched with (its --router-url), if it names one: read from the
27
52
  * record the desktop's native owner launched, since a record kept or saved is rebuilt from its recipe, without its
@@ -448,11 +448,13 @@ function directRouteRuns(llm) {
448
448
  || (llm.authMode !== 'direct' && Boolean(llm.authToken));
449
449
  }
450
450
  /**
451
- * Whether a route through Zerg Router here has a credential to go with now: this profile's Router sign-in, or the ZergAI
452
- * platform's login on its own proxy; else why not, an expired sign-in or none.
451
+ * Whether a route through Zerg Router here has a credential to go with now: this profile's Router sign-in, the ZergAI
452
+ * platform's login on its own proxy, or the host's Router runtime grant, which a ZTC pane is given as well
453
+ * (hostRouterGrantForZtcChild); else why not, an expired sign-in or none.
453
454
  */
454
455
  function routerCredential() {
455
- if (configStore.getPersonalRouterCredential() || configStore.getPlatformProxyLogin(configStore.get().zergProxyUrl))
456
+ if (configStore.getPersonalRouterCredential() || configStore.getPlatformProxyLogin(configStore.get().zergProxyUrl)
457
+ || configStore.getHostRouterGrant())
456
458
  return 'current';
457
459
  return configStore.getRouterSessionStatus() === 'expired' ? 'expired' : 'signed_out';
458
460
  }
@@ -6,6 +6,14 @@ export interface BuiltZtcCommand {
6
6
  cwd?: string;
7
7
  childSessionId: string;
8
8
  }
9
+ /**
10
+ * Why a new ZTC pane on PROVIDER is refused, or undefined when it may open: a pane runs on its provider's routing, and
11
+ * one off the routing ZTC_LLM_AUTH_MODE pins (config/model_pin.ts), a local login under zrouter, opens none, as the
12
+ * mirror's model picker refuses that provider for a pane already open. The refusal names the mode and that a pane can
13
+ * still open on any model on that routing; where the host pins the route too (ZTC_MODEL_PINNED), its message is the one
14
+ * given. A pane that names no provider starts on the route new panes start on, as it always has.
15
+ */
16
+ export declare function ztcPaneRoutingRefusal(provider: string | undefined): string | undefined;
9
17
  export declare function buildZtcPaneLaunchCommand(spec: ZtcPaneLaunchSpec, argv?: string[]): BuiltZtcCommand | Error;
10
18
  /**
11
19
  * The launch spec of a ZTC pane, read back from ARGS, the arguments of the create_pane another ZTC process sent for it (a
@@ -1,4 +1,5 @@
1
1
  import { isLocalSubscriptionProvider } from '../agent/backends/provider_ids.js';
2
+ import { pinnedRoute, pinnedRouteMessage, pinnedRouting, pinnedRoutingMessage } from '../config/model_pin.js';
2
3
  import { isRetiredModel, isRetiredProvider } from '../config/retired_ids.js';
3
4
  import { ROUTE_AWAITS_A_CHOICE } from '../config/retired_routes.js';
4
5
  import { configStore } from '../config.js';
@@ -7,6 +8,9 @@ import { dirname, join } from 'path';
7
8
  import { generateSessionId } from '../session.js';
8
9
  import { activeProfile } from '../config/profiles.js';
9
10
  import { resolveOwnedCliLaunch } from '../desktop/cli_launch.js';
11
+ import { withoutHostHandoff } from '../config/host_credentials.js';
12
+ import { withoutExtensionRootFlags } from '../extension_discovery.js';
13
+ import { ztcChildDiscoversExplicitly } from '../utils/subprocess_env.js';
10
14
  const CHILD_ZTC_SCRIPT_RE = /(?:^|[\\/])cli_(?:main|ratatui)\.(?:js|ts)$/;
11
15
  function filterChildZtcArgs(args) {
12
16
  const skipFlags = new Set([
@@ -94,6 +98,18 @@ function withoutDefaultEffort(extra) {
94
98
  const at = extra.findIndex((arg, index) => arg === '--effort' && extra[index + 1]?.toLowerCase() === 'default');
95
99
  return at < 0 ? [...extra] : [...extra.slice(0, at), ...extra.slice(at + 2)];
96
100
  }
101
+ /**
102
+ * Why a new ZTC pane on PROVIDER is refused, or undefined when it may open: a pane runs on its provider's routing, and
103
+ * one off the routing ZTC_LLM_AUTH_MODE pins (config/model_pin.ts), a local login under zrouter, opens none, as the
104
+ * mirror's model picker refuses that provider for a pane already open. The refusal names the mode and that a pane can
105
+ * still open on any model on that routing; where the host pins the route too (ZTC_MODEL_PINNED), its message is the one
106
+ * given. A pane that names no provider starts on the route new panes start on, as it always has.
107
+ */
108
+ export function ztcPaneRoutingRefusal(provider) {
109
+ if (!provider || !configStore.routingRefusal(provider))
110
+ return undefined;
111
+ return pinnedRoute() ? pinnedRouteMessage() : pinnedRoutingMessage(pinnedRouting(), 'pane');
112
+ }
97
113
  export function buildZtcPaneLaunchCommand(spec, argv = process.argv) {
98
114
  const scriptPath = argv[1] || '';
99
115
  if (!scriptPath) {
@@ -106,7 +122,12 @@ export function buildZtcPaneLaunchCommand(spec, argv = process.argv) {
106
122
  // clear.
107
123
  const ownEffort = extra.some(isReasoningFlag);
108
124
  const parentArgs = ownEffort ? withoutReasoningFlags(launchArgs) : launchArgs;
109
- const childArgs = [...parentArgs, ...(ownEffort && !launchArgs.some(isReasoningFlag) ? withoutDefaultEffort(extra) : extra)];
125
+ const launchFlags = [...parentArgs, ...(ownEffort && !launchArgs.some(isReasoningFlag) ? withoutDefaultEffort(extra) : extra)];
126
+ // A pane that discovers extensions explicitly (one given the host's grant, or this process's own explicit discovery)
127
+ // takes its extension roots only from the ZTC_*_PATHS it inherits, which its host set: no flag of this launch, the
128
+ // extra_args an agent gave create_ztc_pane among them, adds a folder an agent wrote as one. And no flag of it names a
129
+ // handoff of variables the pane takes as it starts (withoutHostHandoff): only ZTC writes one, for a launch of its own.
130
+ const childArgs = withoutHostHandoff(ztcChildDiscoversExplicitly() ? withoutExtensionRootFlags(launchFlags) : launchFlags);
110
131
  if (!childArgs.includes('--profile'))
111
132
  childArgs.push('--profile', activeProfile());
112
133
  if (spec.session.mode === 'resume') {
@@ -128,6 +149,10 @@ export function buildZtcPaneLaunchCommand(spec, argv = process.argv) {
128
149
  const named = providerOverride ?? (flagged >= 0 ? childArgs[flagged + 1] : undefined);
129
150
  if (named && configStore.routeAwaitingChoice(named) !== undefined)
130
151
  return new Error(`Error: ${ROUTE_AWAITS_A_CHOICE}`);
152
+ // Whoever opens it (the mirror, an agent's tool, /ztc, a split, a preset): a provider off the pinned routing opens none.
153
+ const offRouting = ztcPaneRoutingRefusal(named);
154
+ if (offRouting)
155
+ return new Error(`Error: ${offRouting}`);
131
156
  // A pane this run opens is part of the run: while the profile waits for a
132
157
  // route choice, one that names no route of its own takes the route the run's
133
158
  // own launch flags chose, and applies those flags as this run did.
@@ -2,6 +2,7 @@ import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync, writ
2
2
  import { homedir } from 'os';
3
3
  import { join, resolve } from 'path';
4
4
  import { spawn, spawnSync } from 'child_process';
5
+ import { buildUserSubprocessEnv } from './utils/subprocess_env.js';
5
6
  import { buildProfileOptimizationCommand, getProfileGateCommand, getProfileManifest, listProfileManifests, } from './emulation/profile_gates.js';
6
7
  import { compile_optimization_spec, execute_optimization_spec, render_optimization_plan, } from './optimize/index.js';
7
8
  const DEFAULT_GENERATION_MODEL = 'openai/gpt-5.5';
@@ -276,6 +277,7 @@ function normalizePythonCommand(command) {
276
277
  function commandExists(command) {
277
278
  const result = spawnSync('/usr/bin/env', ['sh', '-c', `command -v '${command.replace(/'/g, "'\\''")}' >/dev/null 2>&1`], {
278
279
  stdio: 'ignore',
280
+ env: buildUserSubprocessEnv(),
279
281
  });
280
282
  return result.status === 0;
281
283
  }
@@ -15,10 +15,13 @@ export declare const ROUTER_SIGN_IN_REJECTED: string;
15
15
  * anything is sent: signed out (or never signed in), or signed in with a login that has expired.
16
16
  */
17
17
  export declare function routerSignInRefusal(status: Exclude<RouterSessionStatus, 'signed_in'>): string;
18
- /** Local, actionable routing failures whose messages contain no remote payload. */
18
+ /**
19
+ * Local, actionable routing failures whose messages contain no remote payload. `host_grant`: the host claimed this
20
+ * Router for a Router runtime grant that is no usable bearer, which no sign-in can stand in for.
21
+ */
19
22
  export declare class RouterConfigurationError extends Error {
20
- readonly kind: 'configuration' | 'expired' | 'authentication_required';
21
- constructor(message: string, kind?: 'configuration' | 'expired' | 'authentication_required');
23
+ readonly kind: 'configuration' | 'expired' | 'authentication_required' | 'host_grant';
24
+ constructor(message: string, kind?: 'configuration' | 'expired' | 'authentication_required' | 'host_grant');
22
25
  get needsSignIn(): boolean;
23
26
  }
24
27
  type RouterAuthOutput = (message: string, stream: 'stdout' | 'stderr') => void;
@@ -88,6 +91,8 @@ export interface RouterAccountReadiness {
88
91
  }
89
92
  export declare function readRouterAccountReadiness(credentials: RouterCredentials, surface?: RouterAuthSurface): Promise<RouterAccountReadiness>;
90
93
  export declare function formatRouterAccountReadiness(account: RouterAccountReadiness, surface?: RouterAuthSurface): string;
94
+ /** What /auth status calls the host's Router runtime grant (config/router_runtime_grant.ts). It never shows the grant. */
95
+ export declare const HOST_ROUTER_GRANT_STATUS = "Router runtime grant from the host";
91
96
  export interface RouterAuthCommandOptions {
92
97
  /** The configured Router origin, when the caller knows overrides a fresh load would miss. */
93
98
  origin?: string;
@@ -4,6 +4,7 @@ import { chmod, mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promi
4
4
  import { hostname } from 'node:os';
5
5
  import { dirname, join } from 'node:path';
6
6
  import { spawn } from 'node:child_process';
7
+ import { buildUserSubprocessEnv } from './utils/subprocess_env.js';
7
8
  import { setTimeout as delay } from 'node:timers/promises';
8
9
  import { getVersion } from './utils/version.js';
9
10
  import { browserLaunchAllowed } from './utils/session_interactivity.js';
@@ -32,7 +33,10 @@ export function routerSignInRefusal(status) {
32
33
  ? 'This ZTC\'s Zerg Router sign-in expired, so nothing was sent. Run /auth login to sign in again.'
33
34
  : 'This ZTC isn\'t signed in to Zerg Router, so nothing was sent. Run /auth login to sign in.';
34
35
  }
35
- /** Local, actionable routing failures whose messages contain no remote payload. */
36
+ /**
37
+ * Local, actionable routing failures whose messages contain no remote payload. `host_grant`: the host claimed this
38
+ * Router for a Router runtime grant that is no usable bearer, which no sign-in can stand in for.
39
+ */
36
40
  export class RouterConfigurationError extends Error {
37
41
  kind;
38
42
  constructor(message, kind = 'configuration') {
@@ -322,7 +326,7 @@ function openBrowser(url, output) {
322
326
  }
323
327
  const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'rundll32' : 'xdg-open';
324
328
  const args = process.platform === 'win32' ? ['url.dll,FileProtocolHandler', url] : [url];
325
- const child = spawn(command, args, { stdio: 'ignore' });
329
+ const child = spawn(command, args, { stdio: 'ignore', env: buildUserSubprocessEnv() });
326
330
  child.on('error', () => { output('Open the login URL above in your browser.\n', 'stderr'); });
327
331
  child.unref();
328
332
  }
@@ -539,6 +543,22 @@ async function profileRouterOrigin() {
539
543
  return undefined;
540
544
  }
541
545
  }
546
+ /** What /auth status calls the host's Router runtime grant (config/router_runtime_grant.ts). It never shows the grant. */
547
+ export const HOST_ROUTER_GRANT_STATUS = 'Router runtime grant from the host';
548
+ /**
549
+ * The origin of the Router the host claimed for its Router runtime grant, when that is the configured Router
550
+ * (CONFIGURED, a session's own, else the profile's), and whether the grant is a usable bearer there; never the grant.
551
+ * Only the grant goes there: nothing goes with one that is no usable bearer, and no saved sign-in in its place.
552
+ */
553
+ async function hostGrantRouter(configured) {
554
+ const { ConfigStore } = await import('./config.js');
555
+ const config = new ConfigStore();
556
+ await config.load();
557
+ const destination = configured ?? config.get().zergProxyUrl;
558
+ if (!destination || !config.hostClaimsRouter(destination))
559
+ return undefined;
560
+ return { origin: new URL(destination.trim()).origin, usable: config.getHostRouterGrant(destination) !== undefined };
561
+ }
542
562
  /** The Router origin this profile is configured to log in to. */
543
563
  async function configuredRouterOrigin() {
544
564
  // Shell and slash commands share the active profile and URL overrides.
@@ -619,6 +639,18 @@ export async function runRouterAuthCommand(args, output = terminalOutput, { orig
619
639
  if (flags.some(option => option !== (action === 'status' ? '--json' : '--local-only'))) {
620
640
  throw new Error(`Usage: ztc auth ${action} ${action === 'status' ? '[--json] [--url <router-origin>]' : '[--local-only]'}`);
621
641
  }
642
+ // On the host's Router runtime grant, that is what this ZTC's Router requests use (a saved sign-in to the same Router
643
+ // is not); the status names it, and nothing about it is read out or sent to Router.
644
+ const granted = action === 'status' ? await hostGrantRouter(configuredOrigin) : undefined;
645
+ if (granted) {
646
+ const { origin: router, usable } = granted;
647
+ const saved = await loadRouterCredentials().catch(() => null);
648
+ output(options.includes('--json') ? JSON.stringify({ authenticated: usable, origin: router, credential: 'host_runtime_grant' }) + '\n'
649
+ : `${HOST_ROUTER_GRANT_STATUS} for ${router}${usable ? '.' : ' is set but is not a usable Router bearer (only visible ASCII '
650
+ + 'characters, with no spaces or line breaks), so nothing is sent there.'}\n`
651
+ + (saved?.origin === router ? `A saved sign-in to ${router} is not used while the host provides one.\n` : ''), 'stdout');
652
+ return;
653
+ }
622
654
  // Local removal must remain usable even if the stored JSON is corrupt.
623
655
  const credentials = action === 'logout' && options.includes('--local-only')
624
656
  ? await loadRouterCredentials().catch(() => null) : await loadRouterCredentials();