@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
@@ -5,6 +5,7 @@ import { runOpenAICompatibleWizard } from './openai_compat_wizard.js';
5
5
  import { openFactoryResetConfirmation, settingsCommand } from './settings.js';
6
6
  import { contextProgressBarConfig, normalizeBarColor, publishContextProgressBar, withBarColor, } from './context_progress_bar.js';
7
7
  import { compatEndpoint, DEFAULT_CONTEXT_PROGRESS_BAR, maskApiKey } from '../../config.js';
8
+ import { profileLimitsAgent } from '../../config/profile_limits.js';
8
9
  import { parseGoalTurnCap } from './goal.js';
9
10
  import { getSupportedCodexReasoningEfforts, unsupportedEffortMessage, } from '../../utils/models.js';
10
11
  import { modelForProviderSwitch } from './provider_model_defaults.js';
@@ -17,6 +18,7 @@ import { canAskForCredential, manageApiKey, promptForMissingDirectKey, removeApi
17
18
  import { looksLikeApiKeyEnvName } from '../../config/provider_api_key_env.js';
18
19
  import { offerKeyedProviderSwitch, ownRouteModelSelection, selectProviderModel } from './provider_selection.js';
19
20
  import { keylessRouterModelRefusal } from './router_availability.js';
21
+ import { pinnedRoute, pinnedRouterAddressMessage, routeChangeRefusal, RouteChangeRefusedError, routingEnvOverride } from '../../config/model_pin.js';
20
22
  import { connectionStatusLines } from './credential_status.js';
21
23
  import { normalizeProviderId } from '../backends/provider_ids.js';
22
24
  import { unsupportedCodexEffort } from '../../config/defaults.js';
@@ -224,8 +226,18 @@ async function setConfigProvider(value, ctx, credentialPrompted = false) {
224
226
  const currentModel = getEffectiveModel(ctx);
225
227
  const model = modelForProviderSwitch(provider, previousProvider, currentModel);
226
228
  if (provider !== 'openai_compatible') {
227
- // Checked as it will be once chosen: saving it ends any wait for a route choice.
228
- const llm = ctx.config.resolveLLMBackendConfig({ provider, model, asChosen: true });
229
+ // Checked as it will be once chosen: saving it ends any wait for a route choice. A route one of the host's pins
230
+ // refuses says so, and nothing is saved (config/model_pin.ts).
231
+ let llm;
232
+ try {
233
+ llm = ctx.config.resolveLLMBackendConfig({ provider, model, asChosen: true });
234
+ }
235
+ catch (error) {
236
+ if (!(error instanceof RouteChangeRefusedError))
237
+ throw error;
238
+ ctx.addMessage({ role: 'system', content: `✗ ${error.message} Keeping the current selection.` });
239
+ return;
240
+ }
229
241
  if (!isBuildableResolvedConfig(llm)) {
230
242
  if (!credentialPrompted && promptForMissingDirectKey(llm, ctx, () => setConfigProvider(provider, ctx, true)))
231
243
  return;
@@ -267,7 +279,17 @@ async function setConfigModel(value, ctx, credentialPrompted = false) {
267
279
  // Verify the selection builds a backend BEFORE persisting so an
268
280
  // unbuildable choice never lands in config.json nor earns a false "✓".
269
281
  const activeProvider = ctx.config.getProvider();
270
- const llm = ctx.config.resolveLLMBackendConfig({ provider: activeProvider, model: value, asChosen: true });
282
+ let llm;
283
+ try {
284
+ llm = ctx.config.resolveLLMBackendConfig({ provider: activeProvider, model: value, asChosen: true });
285
+ }
286
+ catch (error) {
287
+ // A route one of the host's pins refuses says so, and nothing is saved (config/model_pin.ts).
288
+ if (!(error instanceof RouteChangeRefusedError))
289
+ throw error;
290
+ ctx.addMessage({ role: 'system', content: `✗ ${error.message} Keeping the current selection.` });
291
+ return;
292
+ }
271
293
  if (!isBuildableResolvedConfig(llm)) {
272
294
  if (!credentialPrompted && promptForMissingDirectKey(llm, ctx, () => setConfigModel(value, ctx, true)))
273
295
  return;
@@ -313,6 +335,10 @@ const CONFIG_HELP = [
313
335
  ' /config reset Factory reset (asks first)',
314
336
  'Any other word searches the settings, for example /config compaction.',
315
337
  ].join('\n');
338
+ /** Whether the permission profile CONFIG runs under now limits the agent (config/profile_limits.ts). */
339
+ function agentLimited(config) {
340
+ return profileLimitsAgent(config.getEffectivePermissionProfile?.(), config.get().sandbox);
341
+ }
316
342
  export const configCommand = {
317
343
  name: 'config',
318
344
  description: 'Manage configuration',
@@ -381,6 +407,14 @@ Usage:
381
407
  return;
382
408
  }
383
409
  if (requested === 'clear') {
410
+ // Under a permission profile that limits the agent, the session's settings may be what limits it: only the
411
+ // person clears them. Where its host pinned them (ZTC_PERMISSION_PROFILE_PINNED), the refusal says so too.
412
+ if (ctx.commandOrigin === 'agent' && agentLimited(ctx.config)) {
413
+ const pinned = ctx.config.permissionPinRefusal?.();
414
+ ctx.addMessage({ role: 'system', content: 'Clearing this session\'s settings requires the person\'s own command: '
415
+ + `under a permission profile that limits the agent, they may hold its limits.${pinned ? ` ${pinned}` : ''} Nothing was cleared.` });
416
+ return;
417
+ }
384
418
  ctx.config.clearSessionOverrides?.();
385
419
  ctx.reloadAgent();
386
420
  ctx.addMessage({ role: 'system', content: '✓ Session-local config overrides cleared.' });
@@ -606,6 +640,12 @@ Usage:
606
640
  Usage: /config zrouter-url <url|clear>` });
607
641
  return;
608
642
  }
643
+ // A session its host pinned is reached through the Zerg Router it started on: no other address is saved
644
+ // (config/model_pin.ts).
645
+ if (pinnedRoute()) {
646
+ ctx.addMessage({ role: 'system', content: `✗ ${pinnedRouterAddressMessage()}` });
647
+ return;
648
+ }
609
649
  ctx.config.set('zergProxyUrl', value === 'clear' ? undefined : value);
610
650
  await ctx.config.save();
611
651
  ctx.reloadAgent();
@@ -658,6 +698,12 @@ Usage: /config zrouter-url <url|clear>` });
658
698
  });
659
699
  return;
660
700
  }
701
+ // The routing ZTC_LLM_AUTH_MODE pins is the only one this session takes; nothing else is saved (config/model_pin.ts).
702
+ const offRouting = routeChangeRefusal({ routing: mode });
703
+ if (offRouting) {
704
+ ctx.addMessage({ role: 'system', content: `✗ ${offRouting}` });
705
+ return;
706
+ }
661
707
  if (ctx.config.setAuthMode) {
662
708
  ctx.config.setAuthMode(mode);
663
709
  }
@@ -666,7 +712,8 @@ Usage: /config zrouter-url <url|clear>` });
666
712
  }
667
713
  await ctx.config.save();
668
714
  ctx.reloadAgent();
669
- const envOverride = process.env.ZTC_LLM_AUTH_MODE || process.env.ZERG_LLM_AUTH_MODE;
715
+ // The variable outranks the saved value only when it names another routing: the one it pins is all it lets be set.
716
+ const envOverride = routingEnvOverride(mode);
670
717
  const detail = mode === 'direct'
671
718
  ? 'local API keys'
672
719
  : mode === 'zrouter'
@@ -5,6 +5,7 @@ import { currentRouteReady, formatDirectProviders, selectProviderModel } from '.
5
5
  import { LOCAL_API_KEYS_LABEL, ZERGAI_LOGIN_BENEFITS, ZERGAI_LOGIN_LABEL, } from '../../onboarding/zergai_login.js';
6
6
  import { readProviderApiKeyEnv } from '../../config/provider_api_key_env.js';
7
7
  import { isClaudeCodeToken } from '../../config/retired_routes.js';
8
+ import { routeChangeRefusal } from '../../config/model_pin.js';
8
9
  const ROUTE_OPTIONS = [
9
10
  {
10
11
  value: 'zergrouter',
@@ -56,8 +57,23 @@ function keptKeyChoice(ctx) {
56
57
  description: 'Kept from your settings before the move, for Claude models · billed per token',
57
58
  };
58
59
  }
60
+ /**
61
+ * Whether ROUTE runs off the routing ZTC_LLM_AUTH_MODE pins (config/model_pin.ts): then it says so, nothing is saved,
62
+ * and the launch flow steps back to its choice.
63
+ */
64
+ async function routeRefused(route, ctx, flow) {
65
+ const refused = routeChangeRefusal({ routing: route === 'zergrouter' ? 'zrouter' : 'direct' });
66
+ if (!refused)
67
+ return false;
68
+ ctx.addMessage({ role: 'system', content: `✗ ${refused}` });
69
+ if (flow)
70
+ await flow.back();
71
+ return true;
72
+ }
59
73
  /** Use a provider's API key: the direct route, chosen as local keys are. */
60
74
  async function connectKey(provider, ctx, flow) {
75
+ if (await routeRefused('direct', ctx, flow))
76
+ return;
61
77
  const previous = ctx.config.get().onboarding;
62
78
  ctx.config.set('onboarding', { ...previous, connectChoice: 'direct' });
63
79
  await ctx.config.save();
@@ -66,6 +82,8 @@ async function connectKey(provider, ctx, flow) {
66
82
  }
67
83
  /** The kept key, chosen: it becomes the Anthropic key (and is no longer offered apart), then runs as any key does. */
68
84
  async function connectKeptKey(ctx, flow) {
85
+ if (await routeRefused('direct', ctx, flow))
86
+ return;
69
87
  const kept = ctx.config.get().keptAnthropicKey;
70
88
  if (kept?.key)
71
89
  ctx.config.setApiKey(kept.key, 'anthropic');
@@ -101,6 +119,8 @@ async function connectProvider(provider, ready, ctx, flow) {
101
119
  flow?.finish();
102
120
  }
103
121
  async function connectRoute(route, ctx, noBrowser, flow) {
122
+ if (await routeRefused(route, ctx, flow))
123
+ return;
104
124
  // Saved before the route runs: choosing local keys counts even when the
105
125
  // provider list is then cancelled, and it keeps the launch prompt away.
106
126
  const previous = ctx.config.get().onboarding;
@@ -1,7 +1,7 @@
1
1
  import { API_KEY_PROVIDER_CHOICES, DIRECT_PROVIDER_CHOICES, isLocalSubscription, isRouterOnlyProvider, modelRouteStatus, } from './provider_choices.js';
2
2
  import { isBuildableResolvedConfig } from './config.js';
3
3
  import { maskApiKey } from '../../config.js';
4
- import { RouterConfigurationError } from '../../router_auth.js';
4
+ import { HOST_ROUTER_GRANT_STATUS, RouterConfigurationError } from '../../router_auth.js';
5
5
  import { RouteAwaitingChoiceError } from '../../config/retired_routes.js';
6
6
  /** The route as /status and /config show name it. */
7
7
  const ROUTE_NAMES = {
@@ -118,8 +118,10 @@ export function credentialStatusLines(config) {
118
118
  const proxy = config.get().zergProxyUrl;
119
119
  const session = config.getRouterSessionStatus?.() ?? 'signed_out';
120
120
  const router = proxy ? ` (Zerg Router at ${proxy})` : '';
121
- const login = session === 'signed_in' ? `signed in${router}`
122
- : `${session === 'expired' ? 'session expired' : 'not signed in'}${router} · /auth login`;
121
+ // On the host's Router runtime grant no login is used there, or needed: the line names the grant, never its value.
122
+ const login = config.getHostRouterGrantOrigin?.() ? `${HOST_ROUTER_GRANT_STATUS}${router}`
123
+ : session === 'signed_in' ? `signed in${router}`
124
+ : `${session === 'expired' ? 'session expired' : 'not signed in'}${router} · /auth login`;
123
125
  const keys = [];
124
126
  const logins = [];
125
127
  for (const { id } of DIRECT_PROVIDER_CHOICES) {
@@ -1,6 +1,7 @@
1
1
  import { existsSync, readFileSync } from 'fs';
2
2
  import { dirname, join, resolve } from 'path';
3
3
  import { zergLaunchLocal } from './zerg.js';
4
+ import { ToolCapability } from '../runtime/capabilities.js';
4
5
  import { configStore } from '../../config.js';
5
6
  import { getZergSocketClient } from '../../zerg/socket_client.js';
6
7
  import { collectCompanionFiles, setActiveManifest, } from '../../zerg/manifest_state.js';
@@ -185,6 +186,8 @@ export const debugCommand = {
185
186
  description: 'Toggle debug mode or run a scripted debug flow',
186
187
  usage: '/debug <on|off|headlines>',
187
188
  agentRunnable: true,
189
+ // /debug headlines launches a local Zerg as /zerg launch does: Poetry, outside any sandbox.
190
+ agentCapabilities: args => (args[0] || '').toLowerCase() === 'headlines' ? [ToolCapability.SHELL_EXEC] : [],
188
191
  category: 'debug',
189
192
  handler: async (args, ctx) => {
190
193
  const sub = (args[0] || '').toLowerCase();
@@ -1,16 +1,20 @@
1
+ import { GIT_DIFF_OPTIONS, GIT_PROBE_OPTIONS } from '../../utils/git_probe_options.js';
1
2
  const MAX_DIFF_CHARS = 60_000;
2
3
  export const diffCommand = {
3
4
  name: 'diff',
4
5
  description: 'Show git status and diff for the current working directory',
5
6
  usage: '',
6
7
  handler: async (_args, ctx) => {
7
- // The agent writes this work tree: git runs no core.fsmonitor command from its config, and
8
- // safe.bareRepository=explicit stops it reading a planted implicit bare repository's config.
9
- const git = 'git -c core.fsmonitor=false -c safe.bareRepository=explicit';
10
- const result = await ctx.shell.run(`${git} status --short && printf "\\n--- diff --stat ---\\n" && ${git} diff --stat && printf "\\n--- diff ---\\n" && ${git} diff -- .`);
8
+ // The agent writes this work tree: git runs no fsmonitor, external diff, textconv driver or signature program from
9
+ // its config, and reads no planted implicit bare repository's config (utils/git_probe_options.ts). The options are
10
+ // ZTC's own constants: plain words, no quoting needed.
11
+ const git = ['git', ...GIT_PROBE_OPTIONS].join(' ');
12
+ const diff = ['diff', ...GIT_DIFF_OPTIONS].join(' ');
13
+ const result = await ctx.shell.run(`${git} status --short && printf "\\n--- diff --stat ---\\n" && ${git} ${diff} --stat && printf "\\n--- diff ---\\n" && ${git} ${diff} -- .`);
11
14
  const output = [result.stdout, result.stderr].filter(Boolean).join('\n');
15
+ // The cut is marked where it falls: the mirror withholds from an observer what may start a credential there.
12
16
  const content = output.length > MAX_DIFF_CHARS
13
- ? `${output.slice(0, MAX_DIFF_CHARS)}\n\n[diff truncated at ${MAX_DIFF_CHARS} chars]`
17
+ ? `${output.slice(0, MAX_DIFF_CHARS)}…\n\n[diff truncated at ${MAX_DIFF_CHARS} chars]`
14
18
  : output || '(no git diff output)';
15
19
  ctx.addMessage({
16
20
  role: 'system',
@@ -5,13 +5,19 @@ import { spawn } from 'child_process';
5
5
  import { get as httpsGet } from 'https';
6
6
  import { get as httpGet } from 'http';
7
7
  import { CUSTOM_EMULATION_DIR, SHANNON_DIR, SHANNON_REPO, init_shannon_profile, } from '../../emulation/shannon_profile.js';
8
+ import { buildGitSubprocessEnv } from '../../utils/subprocess_env.js';
8
9
  const EMULATION_REPO = 'https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools.git';
9
10
  const EMULATION_DIR = join(homedir(), '.ztc', 'emulations', 'x1xhlol');
10
11
  const MAX_FETCH_BYTES = 10 * 1024 * 1024;
11
12
  const MAX_FETCH_REDIRECTS = 5;
13
+ /**
14
+ * Run git for a catalog clone, with a user subprocess's environment: git runs the clone's hooks and the programs its
15
+ * config names with it, so they get the person's environment and none of ZTC's credentials. No GIT_DIR or other
16
+ * repository variable of ZTC's environment reaches it, so a pull acts on the clone in CWD.
17
+ */
12
18
  async function runGitCommand(cmd, args, cwd) {
13
19
  return new Promise((resolve) => {
14
- const proc = spawn(cmd, args, { cwd, shell: true });
20
+ const proc = spawn(cmd, args, { cwd, shell: true, env: buildGitSubprocessEnv() });
15
21
  let stdout = '';
16
22
  let stderr = '';
17
23
  proc.stdout?.on('data', (data) => { stdout += data.toString(); });
@@ -1,10 +1,11 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { spawn } from 'node:child_process';
3
+ import { buildUserSubprocessEnv } from '../../utils/subprocess_env.js';
3
4
  import { open, realpath, stat } from 'node:fs/promises';
4
5
  import { extname, isAbsolute, relative, sep } from 'node:path';
5
6
  import { profileConfigDir } from '../../config/profiles.js';
6
7
  import { changeIntakeReceipt, getIntakeReceipt, listIntakeReceipts, receiveIntakeRequest } from '../../intake/store.js';
7
- import { formatIntakeReceipt } from '../../intake/format.js';
8
+ import { actionPreview, formatIntakeReceipt } from '../../intake/format.js';
8
9
  import { redactDiagnosticValue } from '../../diagnostics/session_export.js';
9
10
  import { browserLaunchAllowed } from '../../utils/session_interactivity.js';
10
11
  const USAGE = '/inbox [list|add <request>|show|ack|run|complete|fail|dismiss <req-ID> [note]|link <req-ID> source|card|artifact <target>|open <req-ID> session|source|card|artifact]';
@@ -23,7 +24,7 @@ export const inboxCommand = {
23
24
  const warning = result.unavailable ? `\n${result.unavailable} receipt${result.unavailable === 1 ? '' : 's'} unavailable. Inspect the inbox storage before retrying; the original records were preserved.` : '';
24
25
  say((result.total === 0 ? result.unavailable ? 'No readable inbox requests.' : 'Inbox is empty. Add a request with /inbox add <request>, or deliver an envelope with ztc inbox receive --file request.json.'
25
26
  : [`Inbox · ${result.total} requests${result.total > result.receipts.length ? ` · showing newest ${result.receipts.length}` : ''}`,
26
- ...result.receipts.map(receipt => `${receipt.intakeId}\n ${receipt.state} · ${receipt.source.channel} · ${receipt.owner?.sessionId ?? 'unassigned'} · ${receipt.action.replace(/\s+/g, ' ').slice(0, 120)}`),
27
+ ...result.receipts.map(receipt => `${receipt.intakeId}\n ${receipt.state} · ${receipt.source.channel} · ${receipt.owner?.sessionId ?? 'unassigned'} · ${actionPreview(receipt.action, 120)}`),
27
28
  'Inspect: /inbox show <req-ID>. Nothing runs until you use /inbox run <req-ID>.'].join('\n')) + warning);
28
29
  return;
29
30
  }
@@ -132,7 +133,7 @@ export const inboxCommand = {
132
133
  throw new Error(`Browser launch is off in this session. Open directly: ${target}`);
133
134
  await new Promise((resolve, reject) => {
134
135
  const executable = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'rundll32.exe' : 'xdg-open';
135
- const child = spawn(executable, process.platform === 'win32' ? ['url.dll,FileProtocolHandler', target] : [target], { stdio: 'ignore' });
136
+ const child = spawn(executable, process.platform === 'win32' ? ['url.dll,FileProtocolHandler', target] : [target], { stdio: 'ignore', env: buildUserSubprocessEnv() });
136
137
  child.once('error', reject);
137
138
  child.once('exit', code => code === 0 ? resolve() : reject(new Error(`Browser launcher exited with code ${code}. Open directly: ${target}`)));
138
139
  });
@@ -10,6 +10,9 @@ function formatServer(s) {
10
10
  if (s.connected && s.tools.length > 0) {
11
11
  lines.push(` ${s.tools.join(', ')}`);
12
12
  }
13
+ // How it was started: the variables it started without, and the passEnv that gives one (never their values).
14
+ for (const notice of s.notices ?? [])
15
+ lines.push(` ${notice}`);
13
16
  return lines.join('\n');
14
17
  }
15
18
  /**
@@ -4,6 +4,7 @@ import { isBuildableResolvedConfig, unbuildableSelectionMessage } from './config
4
4
  import { promptForMissingDirectKey } from './direct_credential_prompt.js';
5
5
  import { canonicalProvider } from './provider_choices.js';
6
6
  import { selectProviderModel } from './provider_selection.js';
7
+ import { RouteChangeRefusedError } from '../../config/model_pin.js';
7
8
  const LATEST_TAGS = ['latest', 'current', 'default'];
8
9
  function filterModelsForProvider(models, provider) {
9
10
  const normalizedProvider = provider.toLowerCase();
@@ -123,8 +124,18 @@ async function setModelOnly(value, ctx, credentialPrompted = false) {
123
124
  const provider = ctx.config.getProvider();
124
125
  // Verify the selection builds a backend BEFORE persisting so an unbuildable
125
126
  // choice never lands in config.json nor earns a false "✓".
126
- // Checked as it will be once chosen: saving it ends any wait for a route choice.
127
- const llm = ctx.config.resolveLLMBackendConfig({ provider, model: value, asChosen: true });
127
+ // Checked as it will be once chosen: saving it ends any wait for a route choice. A route one of the host's pins
128
+ // refuses says so, and nothing is saved (config/model_pin.ts).
129
+ let llm;
130
+ try {
131
+ llm = ctx.config.resolveLLMBackendConfig({ provider, model: value, asChosen: true });
132
+ }
133
+ catch (error) {
134
+ if (!(error instanceof RouteChangeRefusedError))
135
+ throw error;
136
+ ctx.addMessage({ role: 'system', content: `✗ ${error.message} Keeping the current selection.` });
137
+ return;
138
+ }
128
139
  if (!isBuildableResolvedConfig(llm)) {
129
140
  if (!credentialPrompted && promptForMissingDirectKey(llm, ctx, () => setModelOnly(value, ctx, true)))
130
141
  return;
@@ -138,6 +149,12 @@ async function setModelOnly(value, ctx, credentialPrompted = false) {
138
149
  }
139
150
  /** `/models list|latest [provider]`. Latest asks for a missing direct key before listing. */
140
151
  async function listModels(subCmd, provider, ctx, credentialPrompted = false) {
152
+ // A provider one of the host's pins keeps this session off is refused before its models are listed (config/model_pin.ts).
153
+ const refused = subCmd === 'latest' ? ctx.config.routeChangeRefusal?.(provider) : undefined;
154
+ if (refused) {
155
+ ctx.addMessage({ role: 'system', content: `✗ ${refused} Keeping the current selection.` });
156
+ return;
157
+ }
141
158
  try {
142
159
  // A Router route lists through its login; only a direct route can lack a key.
143
160
  if (subCmd === 'latest' && !credentialPrompted && ctx.config.getAuthMode?.() !== 'zrouter') {
@@ -199,7 +216,7 @@ async function listModels(subCmd, provider, ctx, credentialPrompted = false) {
199
216
  const message = err instanceof Error ? err.message : 'Unable to list models';
200
217
  ctx.addMessage({
201
218
  role: 'system',
202
- content: `Models error: ${message}`
219
+ content: err instanceof RouteChangeRefusedError ? `✗ ${message} Keeping the current selection.` : `Models error: ${message}`
203
220
  });
204
221
  }
205
222
  }
@@ -3,6 +3,10 @@ import { PERMISSION_CAPABILITIES, describePermissionChanges, describePermissionP
3
3
  const usage = '/permissions show | profiles [--repo] | use <profile|repo:name> | set <capability> <on|off>';
4
4
  const normalize = (value) => value.trim().toLowerCase();
5
5
  export async function activatePermissionConfig(next, ctx) {
6
+ // A session whose host pinned its permission settings (ZTC_PERMISSION_PROFILE_PINNED) changes none, whoever asks.
7
+ const pinned = ctx.config.permissionPinRefusal?.();
8
+ if (pinned)
9
+ throw new Error(pinned);
6
10
  if (ctx.commandOrigin === 'agent')
7
11
  throw new Error('Permission changes require an explicit user command.');
8
12
  const previous = ctx.config.get(), after = projectPermissionPolicy(next);
@@ -36,10 +40,20 @@ export async function activatePermissionConfig(next, ctx) {
36
40
  }
37
41
  async function run(args, ctx) {
38
42
  const action = normalize(args[0] ?? 'show'), config = ctx.config.get();
43
+ // Where the host pinned the permission settings (ZTC_PERMISSION_PROFILE_PINNED), use and set change nothing, whoever
44
+ // asks; the refusal names the variable and nothing of the profile.
45
+ const pinned = ctx.config.permissionPinRefusal?.();
46
+ if (['use', 'set'].includes(action) && pinned)
47
+ return `${pinned} Nothing was changed.`;
39
48
  if (['use', 'set'].includes(action) && ctx.commandOrigin === 'agent')
40
49
  return 'Permission changes require an explicit user command.';
41
- if (action === 'show')
42
- return args.length > 1 ? usage : describePermissionPolicy(projectPermissionPolicy(config));
50
+ if (action === 'show') {
51
+ if (args.length > 1)
52
+ return usage;
53
+ // The show still works under the pin, and says it.
54
+ const policy = describePermissionPolicy(projectPermissionPolicy(config));
55
+ return pinned ? `${policy}\n${pinned}` : policy;
56
+ }
43
57
  if (action === 'profiles') {
44
58
  if (args.length > 2 || (args.length === 2 && args[1] !== '--repo'))
45
59
  return usage;
@@ -14,6 +14,7 @@ import { ROUTER_SIGN_IN_REJECTED } from '../../router_auth.js';
14
14
  import { offerReasoningPicker } from './reasoning_picker.js';
15
15
  import { isRetiredModel, isRetiredProvider, retiredModelMessage, retiredProviderMessage } from '../../config/retired_routes.js';
16
16
  import { keylessRouterModelRefusal } from './router_availability.js';
17
+ import { routeChangeRefusal, routingOverrideMessage } from '../../config/model_pin.js';
17
18
  /**
18
19
  * Where this configuration keeps its profile: the models remembered per provider live beside its config.json. A
19
20
  * configuration without a file (a renderer's stand-in) remembers nothing.
@@ -156,15 +157,21 @@ export async function selectProviderModel(args, ctx, options = {}) {
156
157
  if (values.length > (choice === 'zergrouter' ? 3 : 2)) {
157
158
  return ended(ctx, 'refused', 'Usage: /model [direct] <provider> [model] or /model zergrouter <upstream-provider> [model]');
158
159
  }
160
+ const authMode = routed ? 'zrouter' : 'direct';
161
+ const explicitModel = values[choice === 'zergrouter' ? 2 : 1];
162
+ // A route one of the host's pins refuses (config/model_pin.ts) is refused before a login or key is asked for, or
163
+ // anything saved: another than the pinned route, or one off the pinned routing; a provider whose own routing differs
164
+ // (a local login, Morph's own key) is refused as it resolves.
165
+ const refused = routeChangeRefusal({ provider, model: explicitModel, routing: authMode });
166
+ if (refused)
167
+ return ended(ctx, 'refused', `✗ ${refused} Keeping the current selection.`);
159
168
  const routerSession = ctx.config.getRouterSessionStatus?.();
160
169
  if (routed && routerSession !== undefined && routerSession !== 'signed_in') {
161
170
  return credentialPrompted ? ended(ctx, 'refused', `✗ ${ROUTER_MODELS_NEED_LOGIN} with ZergAI. Keeping the current selection.`)
162
171
  : askForRouterLogin(args, ctx, options);
163
172
  }
164
- const authMode = routed ? 'zrouter' : 'direct';
165
173
  const choiceId = providerChoiceId(provider, routed ? 'zergrouter' : 'direct');
166
174
  const defaultModel = provider === 'inception' ? getDefaultModel(provider) : getDefaultModelForProvider(provider);
167
- const explicitModel = values[choice === 'zergrouter' ? 2 : 1];
168
175
  // Another provider lands on the model last used with it; the one in use keeps its model, and a custom endpoint
169
176
  // names its own. It must still be offered, through Zerg Router (below) or on your own key; a retired id is never
170
177
  // used again.
@@ -207,12 +214,12 @@ export async function selectProviderModel(args, ctx, options = {}) {
207
214
  model = selected.id;
208
215
  }
209
216
  }
210
- // Checked as it will be once chosen: saving it ends any wait for a route choice.
217
+ // Checked as it will be once chosen: saving it ends any wait for a route choice. A route off the routing
218
+ // ZTC_LLM_AUTH_MODE pins is refused there; one asking for another routing than it gives, here.
211
219
  const llm = ctx.config.resolveLLMBackendConfig({ provider, model, asChosen: true,
212
220
  config: { ...ctx.config.get(), provider, model, authMode } });
213
- if (llm.authMode !== authMode) {
214
- throw new Error('Routing is pinned by ZTC_LLM_AUTH_MODE/ZERG_LLM_AUTH_MODE. Unset it before switching routes.');
215
- }
221
+ if (llm.authMode !== authMode)
222
+ throw new Error(routingOverrideMessage());
216
223
  // A pane header's choice that isn't ready yet asks in this pane for what it needs, and the pane switches only once
217
224
  // it is there. A local login builds a backend without one, so the login itself is its readiness, as /settings
218
225
  // checks it: the pane says how to sign in. A custom endpoint opens its setup form, and switches once it is saved.
@@ -28,6 +28,7 @@ import { isBuildableResolvedConfig, unbuildableSelectionMessage } from './config
28
28
  import { hasRemovableKey, manageApiKey, promptForMissingDirectKey, removeApiKey, } from './direct_credential_prompt.js';
29
29
  import { offerKeyedProviderSwitch, ownRouteModelSelection, profileDirectory, stillListed } from './provider_selection.js';
30
30
  import { keylessRouterModelRefusal } from './router_availability.js';
31
+ import { pinnedRoute, pinnedRouterAddressMessage, routeChangeRefusal, routingOverrideMessage } from '../../config/model_pin.js';
31
32
  import { API_KEY_PROVIDER_CHOICES, DIRECT_PROVIDER_CHOICES, PROVIDER_CHOICES, ROUTER_CHOICE_PREFIX, canonicalProvider, describeKeySource, isLocalSubscription, isRouterOnlyProvider, modelRouteStatus, providerChoiceId, } from './provider_choices.js';
32
33
  import { rememberedModel, rememberProviderModel } from '../../config/provider_models.js';
33
34
  import { describeActiveRoute, describeConnection, describeKeyRow } from './credential_status.js';
@@ -1519,6 +1520,9 @@ function applySettingChange(ctx, setting, value, selection) {
1519
1520
  ctx.config.set('authMode', value);
1520
1521
  break;
1521
1522
  case 'zergProxyUrl':
1523
+ // A session its host pinned is reached through the Zerg Router it started on (config/model_pin.ts).
1524
+ if (pinnedRoute())
1525
+ throw new Error(pinnedRouterAddressMessage());
1522
1526
  ctx.config.set('zergProxyUrl', value || undefined);
1523
1527
  break;
1524
1528
  case 'zergEndpoint':
@@ -2217,6 +2221,11 @@ function holdUnbuildableSelection(ctx, categories, setting, { provider, model, a
2217
2221
  const current = ctx.config.getProvider();
2218
2222
  const loginFirst = 'Log in with ZergAI first (Connection → Log in with ZergAI). Keeping the current selection.';
2219
2223
  const signedIn = ctx.config.getRouterSessionStatus?.() === 'signed_in';
2224
+ // A route one of the host's pins refuses (config/model_pin.ts) is refused before its login or key is asked for: the
2225
+ // route itself, the routing its provider runs on, or the routing the choice names.
2226
+ const refused = ctx.config.routeChangeRefusal?.(provider, model) ?? routeChangeRefusal({ routing: authMode });
2227
+ if (refused)
2228
+ throw new Error(`${refused} Keeping the current selection.`);
2220
2229
  // A local login builds a backend without a key, so readiness is the login itself.
2221
2230
  if (isLocalSubscription(provider) && ctx.config.hasDirectCredential?.(provider) === false) {
2222
2231
  throw new Error(unbuildableSelectionMessage(provider));
@@ -2232,9 +2241,8 @@ function holdUnbuildableSelection(ctx, categories, setting, { provider, model, a
2232
2241
  throw new Error(loginFirst);
2233
2242
  throw new Error(`${error instanceof Error ? error.message : String(error)} Keeping the current selection.`);
2234
2243
  }
2235
- if (authMode && llm.authMode !== authMode) {
2236
- throw new Error('Routing is pinned by ZTC_LLM_AUTH_MODE/ZERG_LLM_AUTH_MODE. Unset it before switching routes. Keeping the current selection.');
2237
- }
2244
+ if (authMode && llm.authMode !== authMode)
2245
+ throw new Error(`${routingOverrideMessage()} Keeping the current selection.`);
2238
2246
  if (authMode === 'zrouter' && !llm.useProxy)
2239
2247
  throw new Error(loginFirst);
2240
2248
  if (isBuildableResolvedConfig(llm))
@@ -2796,7 +2804,10 @@ export function openFactoryResetConfirmation(ctx, onDone) {
2796
2804
  return (async () => {
2797
2805
  await ctx.config.factoryReset?.();
2798
2806
  ctx.reloadAgent();
2799
- ctx.addMessage({ role: 'system', content: `Factory reset complete: ${path}` });
2807
+ // The permission profile the launch named stays (ConfigStore.factoryReset), which the person should know.
2808
+ const kept = ctx.config.getLaunchPermissionProfile?.();
2809
+ ctx.addMessage({ role: 'system', content: `Factory reset complete: ${path}`
2810
+ + (kept ? `. This ZTC keeps the permission profile it was started with (--permission-profile ${kept}).` : '') });
2800
2811
  if (onDone)
2801
2812
  await onDone();
2802
2813
  else
@@ -1,8 +1,29 @@
1
1
  import { describeExecutionContext } from '../runtime/execution_context.js';
2
+ import { PERMISSION_PIN_ENV } from '../../config/permission_pin.js';
3
+ import { projectPermissionPolicy } from '../../config/permissions.js';
2
4
  import { formatRuntimeSummary, getRuntimeInfo } from '../../runtime_info.js';
3
5
  import { getWorkflowRegistry } from '../../workflows/registry_handle.js';
4
6
  import { workflowsEnabled, workflowNaturalLanguageTriggerEnabled } from '../../workflows/config.js';
5
7
  import { connectionStatusLines, describeActiveRoute, readinessLine } from './credential_status.js';
8
+ /**
9
+ * What the agent runs under, for /status: the permission profile's id, said pinned where its host pinned the permission
10
+ * settings (ZTC_PERMISSION_PROFILE_PINNED), and whether its commands must run in the OS sandbox and whether one enforces
11
+ * them here, with which backend. Never the profile's definition (its file roots, its capabilities): /permissions shows that,
12
+ * and /status --verbose leaves it out of the agent's execution facts, which held it (describeExecutionContext).
13
+ */
14
+ function permissionStatusLines(config, ctx) {
15
+ const policy = projectPermissionPolicy(config);
16
+ const sandbox = policy.commandSandbox;
17
+ const pinned = ctx.config.permissionPinRefusal?.() ? `, pinned by its host (${PERMISSION_PIN_ENV})` : '';
18
+ const enforced = !sandbox.requested ? 'none is used'
19
+ : sandbox.available && sandbox.enforcement === 'os' ? `enforced by ${sandbox.backend}`
20
+ : sandbox.available && sandbox.enforcement === 'partial' ? `partly enforced by ${sandbox.backend}`
21
+ : `not enforced: no OS sandbox on this host${sandbox.required ? ', so commands don\'t run' : ''}`;
22
+ return [
23
+ ` Permission profile: ${policy.id}${pinned}`,
24
+ ` OS command sandbox: ${sandbox.required ? 'required' : 'not required'}${sandbox.requested ? '; ' : ', and '}${enforced}`,
25
+ ];
26
+ }
6
27
  export const statusCommand = {
7
28
  name: 'status',
8
29
  description: 'Show current status',
@@ -19,7 +40,7 @@ export const statusCommand = {
19
40
  const execution = ctx.getExecutionContext?.();
20
41
  const environment = ctx.getEnvironment?.();
21
42
  const executionLines = !execution ? [] : args.includes('--verbose')
22
- ? [describeExecutionContext(execution)]
43
+ ? [describeExecutionContext(execution, { permissions: false })]
23
44
  : [
24
45
  ` Mode: ${execution.mode}`,
25
46
  ` Working directory: ${execution.cwd}`,
@@ -35,6 +56,7 @@ export const statusCommand = {
35
56
  ...executionLines,
36
57
  ` Runtime: ${runtimeSummary}`,
37
58
  ` Workflows: ${workflowState} (${workflowRegistry}, ${workflowTrigger})`,
59
+ ...permissionStatusLines(config, ctx),
38
60
  // The platform API only serves a legacy ZergAI token.
39
61
  ...(ctx.config.isAuthenticated?.() ? [
40
62
  ` API Env: ${ctx.config.getApiEnvironment?.() || '(unknown)'}`,
@@ -21,6 +21,11 @@ import type { TaskHandoffProjection } from '../../session_handoff_contract.js';
21
21
  export interface ConfigController {
22
22
  getRouterCatalogConnection?: () => import('../../utils/router_catalog.js').RouterCatalogConnection | undefined;
23
23
  getRouterSessionStatus?: () => import('../../router_auth.js').RouterSessionStatus;
24
+ /**
25
+ * The configured Zerg Router's origin, when the host claimed it for its Router runtime grant (no sign-in of the
26
+ * profile's is used there, and only a usable grant goes); never the grant.
27
+ */
28
+ getHostRouterGrantOrigin?: () => string | undefined;
24
29
  getRoutedModelCatalog?: () => import('../../utils/router_catalog.js').RouterCatalog | undefined;
25
30
  adoptRouterCatalog?(catalog: import('../../utils/router_catalog.js').RouterCatalog): Promise<void>;
26
31
  getRouterCatalog?: () => import('../../utils/router_catalog.js').RouterCatalog | undefined;
@@ -57,6 +62,13 @@ export interface ConfigController {
57
62
  withConfigScope?: <T>(scope: ZTCConfigScope, fn: () => T | Promise<T>) => Promise<T>;
58
63
  refresh?: () => Promise<void>;
59
64
  factoryReset?: () => Promise<void>;
65
+ /** The permission profile this process's launch named (`--permission-profile`), which a factory reset keeps. */
66
+ getLaunchPermissionProfile?: () => string | undefined;
67
+ /**
68
+ * Why a change of the permission profile, sandbox or tool permissions is refused, or undefined when it may go: the
69
+ * host pinned them (ZTC_PERMISSION_PROFILE_PINNED; ConfigStore.permissionPinRefusal).
70
+ */
71
+ permissionPinRefusal?: () => string | undefined;
60
72
  switchProfile?: (name: string, activate: () => void | Promise<void>) => Promise<void>;
61
73
  hasApiKey: () => boolean;
62
74
  getApiKey: (provider?: string) => string | undefined;
@@ -79,6 +91,11 @@ export interface ConfigController {
79
91
  setOpenAICompatibleSettings?: (next: Partial<OpenAICompatibleSettings>) => void;
80
92
  getAuthMode?: () => ZTCAuthMode;
81
93
  setAuthMode?: (mode: ZTCAuthMode) => void;
94
+ /**
95
+ * Why moving this session to PROVIDER/MODEL is refused, or undefined when it may move: the host's pin of its route
96
+ * (ZTC_MODEL_PINNED), or the routing ZTC_LLM_AUTH_MODE pins (ConfigStore.routeChangeRefusal).
97
+ */
98
+ routeChangeRefusal?: (provider?: string, model?: string) => string | undefined;
82
99
  getEmulationId: () => string | undefined;
83
100
  setEmulationId: (id: string | undefined) => void;
84
101
  save: () => void | Promise<void>;
@@ -157,6 +174,12 @@ export interface ShellResult {
157
174
  outputHeldOpen?: boolean;
158
175
  /** The JSON record of the sandbox the command ran under, beside its output rather than in it. */
159
176
  sandboxAudit?: string;
177
+ /**
178
+ * What ZTC did or says about the command's sandbox beyond its output: a notice of the plan's, once per ZTC process (a
179
+ * core.hooksPath folder the repository tracks, whose hooks stay the command's to write), and what the step after a
180
+ * bwrap command undid where a repository names the programs git starts (utils/git_program_files.ts).
181
+ */
182
+ sandboxNotes?: string[];
160
183
  }
161
184
  export interface ShellController {
162
185
  run: (command: string) => Promise<ShellResult>;
@@ -823,10 +846,18 @@ export interface Command {
823
846
  /**
824
847
  * What the command does, run by the agent through ztc_command, that the agent's permission profile governs: the tool
825
848
  * runtime checks them as that call's own capabilities, so a profile refuses the command, or asks first, as it does
826
- * a tool with them. /claude and /codex start a program that runs commands (shell_exec). Absent: nothing beyond
827
- * ztc_command's own.
849
+ * a tool with them. /claude and /codex start a program that runs commands (shell_exec), and so does /zerg launch,
850
+ * which a function of the arguments says. Absent: nothing beyond ztc_command's own.
851
+ */
852
+ agentCapabilities?: readonly ToolCapability[] | ((args: readonly string[]) => readonly ToolCapability[]);
853
+ /**
854
+ * What the command starts, run by the agent, runs no program of the agent's outside run_command's OS sandbox, though
855
+ * it declares shell_exec: the ZTC pane /ztc opens runs under permissions no wider than this pane's, so its commands
856
+ * are held where this pane's are. Absent: a command that declares shell_exec starts a program outside that sandbox
857
+ * (/claude and /codex open a CLI that runs its own commands), which a profile whose commands run only inside an OS
858
+ * sandbox refuses unless it asks the person first (see Tool.confinedCommands).
828
859
  */
829
- agentCapabilities?: readonly ToolCapability[];
860
+ agentConfined?: boolean;
830
861
  /** Grouping label for the agent-facing description (e.g. "zerg", "manifest", "config"). */
831
862
  category?: string;
832
863
  /**
@@ -3,7 +3,8 @@ export interface UpdateCommandDependencies {
3
3
  desktopBundle: () => boolean;
4
4
  packageRoot: () => string;
5
5
  exists: (path: string) => boolean;
6
- run: (command: string, args: string[]) => Promise<{
6
+ /** Runs the launcher's update; by default in a process of its own (runProcess). */
7
+ run?: (command: string, args: string[]) => Promise<{
7
8
  exitCode: number;
8
9
  stdout: string;
9
10
  stderr: string;