@zergai/ztc 0.21.0-beta.1 → 0.22.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +144 -33
  2. package/bin/zmux-darwin-arm64 +0 -0
  3. package/bin/ztc-audio-darwin-arm64 +0 -0
  4. package/bin/ztc-capture-darwin-arm64 +0 -0
  5. package/bin/ztc-tui-darwin-arm64 +0 -0
  6. package/bin/zterm-darwin-arm64 +2 -2
  7. package/dist/App.js +2 -2
  8. package/dist/agent/agent.d.ts +13 -3
  9. package/dist/agent/agent.js +179 -91
  10. package/dist/agent/backends/codex_app_server.d.ts +1 -0
  11. package/dist/agent/backends/codex_app_server.js +3 -1
  12. package/dist/agent/backends/host_effort_policy.d.ts +12 -0
  13. package/dist/agent/backends/host_effort_policy.js +132 -0
  14. package/dist/agent/backends/index.d.ts +3 -2
  15. package/dist/agent/backends/index.js +4 -0
  16. package/dist/agent/backends/router_gate.d.ts +11 -0
  17. package/dist/agent/backends/router_gate.js +27 -2
  18. package/dist/agent/backends/router_keys.d.ts +63 -0
  19. package/dist/agent/backends/router_keys.js +94 -0
  20. package/dist/agent/backends/router_refusal.d.ts +12 -15
  21. package/dist/agent/backends/router_refusal.js +29 -5
  22. package/dist/agent/backends/types.d.ts +10 -0
  23. package/dist/agent/backends/zrouter_stream.d.ts +48 -1
  24. package/dist/agent/backends/zrouter_stream.js +215 -24
  25. package/dist/agent/commands/agent_cli.js +11 -3
  26. package/dist/agent/commands/config.js +12 -0
  27. package/dist/agent/commands/index.js +2 -1
  28. package/dist/agent/commands/mirror.js +15 -5
  29. package/dist/agent/commands/provider.js +4 -2
  30. package/dist/agent/commands/provider_selection.js +16 -2
  31. package/dist/agent/commands/router_availability.d.ts +15 -0
  32. package/dist/agent/commands/router_availability.js +45 -0
  33. package/dist/agent/commands/settings.js +38 -5
  34. package/dist/agent/commands/subs.d.ts +4 -1
  35. package/dist/agent/commands/subs.js +15 -5
  36. package/dist/agent/commands/types.d.ts +10 -0
  37. package/dist/agent/commands/ztc_pane.d.ts +20 -0
  38. package/dist/agent/commands/ztc_pane.js +239 -0
  39. package/dist/agent/factory.js +10 -2
  40. package/dist/agent/host_model_context.d.ts +9 -0
  41. package/dist/agent/host_model_context.js +40 -0
  42. package/dist/agent/request_encoder.d.ts +3 -0
  43. package/dist/agent/request_encoder.js +11 -4
  44. package/dist/agent/runtime/tool_runtime.js +8 -2
  45. package/dist/agent/subagent.d.ts +9 -0
  46. package/dist/agent/subagent.js +65 -46
  47. package/dist/agent/tools/file.js +10 -6
  48. package/dist/agent/tools/pane.d.ts +7 -0
  49. package/dist/agent/tools/pane.js +31 -6
  50. package/dist/agent/tools/ztc_command.d.ts +12 -0
  51. package/dist/agent/tools/ztc_command.js +21 -6
  52. package/dist/app/agent_runner.js +5 -2
  53. package/dist/app/command_context.js +10 -4
  54. package/dist/app/mirror_startup.d.ts +16 -0
  55. package/dist/app/mirror_startup.js +10 -0
  56. package/dist/app/runtime_choices.d.ts +2 -0
  57. package/dist/app/runtime_choices.js +1 -1
  58. package/dist/app/runtime_choices_source.js +2 -1
  59. package/dist/app/tool_callbacks.js +1 -0
  60. package/dist/cli_args.d.ts +2 -0
  61. package/dist/cli_args.js +5 -0
  62. package/dist/cli_ratatui.d.ts +14 -0
  63. package/dist/cli_ratatui.js +113 -27
  64. package/dist/config/permissions.d.ts +13 -0
  65. package/dist/config/permissions.js +63 -1
  66. package/dist/config/retired_routes.d.ts +23 -3
  67. package/dist/config/retired_routes.js +62 -11
  68. package/dist/config/types.d.ts +18 -1
  69. package/dist/config.d.ts +42 -0
  70. package/dist/config.js +102 -3
  71. package/dist/desktop/daily/desktop_wiring.js +9 -0
  72. package/dist/desktop/daily/recipes.js +7 -1
  73. package/dist/headless.js +2 -2
  74. package/dist/library.js +2 -2
  75. package/dist/mcp/client.js +6 -3
  76. package/dist/mcp/workspace_server.d.ts +6 -1
  77. package/dist/mcp/workspace_server.js +58 -9
  78. package/dist/onboarding/first_run.d.ts +3 -1
  79. package/dist/onboarding/first_run.js +21 -6
  80. package/dist/onboarding/router_tips.js +10 -7
  81. package/dist/panes/agent_cli.d.ts +48 -0
  82. package/dist/panes/agent_cli.js +145 -0
  83. package/dist/panes/agent_panes.d.ts +11 -0
  84. package/dist/panes/agent_panes.js +25 -4
  85. package/dist/panes/initial_input.d.ts +6 -0
  86. package/dist/panes/initial_input.js +6 -0
  87. package/dist/panes/motsi.d.ts +22 -7
  88. package/dist/panes/motsi.js +36 -9
  89. package/dist/panes/worker_route.d.ts +123 -0
  90. package/dist/panes/worker_route.js +464 -0
  91. package/dist/panes/ztc_launch.d.ts +9 -0
  92. package/dist/panes/ztc_launch.js +58 -2
  93. package/dist/router_auth.d.ts +18 -0
  94. package/dist/router_auth.js +78 -2
  95. package/dist/types.d.ts +5 -0
  96. package/dist/ui/ratatui/headless_pane_manager.d.ts +2 -0
  97. package/dist/ui/ratatui/headless_pane_manager.js +6 -3
  98. package/dist/ui/ratatui/pane_relay.d.ts +11 -1
  99. package/dist/ui/ratatui/pane_relay.js +14 -2
  100. package/dist/ui/ratatui/protocol.d.ts +9 -1
  101. package/dist/utils/atomic_write.js +26 -1
  102. package/dist/utils/docker_target.js +4 -1
  103. package/dist/utils/subprocess_env.d.ts +18 -0
  104. package/dist/utils/subprocess_env.js +45 -0
  105. package/dist/web/mirror_authenticator.d.ts +6 -0
  106. package/dist/web/mirror_authenticator.js +15 -12
  107. package/dist/web/mirror_stream.d.ts +50 -0
  108. package/dist/web/mirror_stream.js +121 -30
  109. package/dist/worker/worker_models.d.ts +11 -0
  110. package/dist/worker/worker_models.js +19 -7
  111. package/dist/zlm-embed.mjs +1349 -429
  112. package/dist/zlm.js +1 -1
  113. package/package.json +32 -16
@@ -79,6 +79,25 @@ async function executeWithTimeout(command, args, timeoutMs) {
79
79
  }
80
80
  }
81
81
  }
82
+ /** The catalog entry a command name runs: the current mode's override, else the global command. */
83
+ function catalogEntry(command) {
84
+ if (!catalogProvider)
85
+ return undefined;
86
+ const matches = catalogProvider.getEntries().filter((e) => e.name === command);
87
+ if (matches.length === 0)
88
+ return undefined;
89
+ const currentMode = catalogProvider.getCurrentMode();
90
+ return matches.find((e) => e.scope === currentMode) ?? matches.find((e) => e.scope === 'global') ?? matches[0];
91
+ }
92
+ /**
93
+ * What a ztc_command call's command does that the agent's permission profile governs, which the tool runtime checks as
94
+ * the call's own capabilities: /claude and /codex start a program that runs commands (shell_exec), so a profile refuses
95
+ * them, or asks before them, as it does a shell. None for a command the agent can't run, which execute refuses.
96
+ */
97
+ export function ztcCommandCapabilities(args) {
98
+ const entry = typeof args.command === 'string' ? catalogEntry(args.command) : undefined;
99
+ return entry?.agentRunnable ? [...(entry.capabilities ?? [])] : [];
100
+ }
82
101
  /** Group entries by scope (global first, modes alphabetical) then by category. */
83
102
  export function buildZtcCommandDescription(provider) {
84
103
  const entries = provider.getEntries().filter((e) => e.agentRunnable);
@@ -189,16 +208,12 @@ export const ztcCommandTool = {
189
208
  if (!catalogProvider) {
190
209
  return 'Error: ZTC command catalog not initialized. This tool is only available when running inside ZTC.';
191
210
  }
192
- const entries = catalogProvider.getEntries();
193
211
  // A command name may exist as a global AND a mode override. Prefer current-mode override.
194
212
  const currentMode = catalogProvider.getCurrentMode();
195
- const matches = entries.filter((e) => e.name === command);
196
- if (matches.length === 0) {
213
+ const entry = catalogEntry(command);
214
+ if (!entry) {
197
215
  return `Error: Unknown ZTC command "${command}".`;
198
216
  }
199
- const entry = matches.find((e) => e.scope === currentMode) ??
200
- matches.find((e) => e.scope === 'global') ??
201
- matches[0];
202
217
  if (!entry.agentRunnable) {
203
218
  return `Error: Command /${command} is not exposed to the agent. Ask the user to run it manually.`;
204
219
  }
@@ -102,8 +102,11 @@ export function createAgentWithConfig(overrides = {}) {
102
102
  // A profile waiting for a route choice has no route but the one this
103
103
  // run's own --provider chose (see ConfigStore.routeAwaitingChoice), so its
104
104
  // workers run on that one, never on the pool's routes.
105
- const workerModels = config.workers?.models.length && configStore.retiredRouteAwaitingChoice() === undefined ? createWorkerModels(config.workers, { connection: configStore.getRouterCatalogConnection(), conversationId: overrides.sessionId,
106
- openRouterPreferences: () => configStore.get().openRouter }) : null;
105
+ // Router workers on the person's own Router sign-in send each request with it as the profile holds it then.
106
+ const routerConnection = configStore.getRouterCatalogConnection();
107
+ const ownSignIn = routerConnection !== undefined && routerConnection.token === configStore.getPersonalRouterCredential()?.token;
108
+ const workerModels = config.workers?.models.length && configStore.retiredRouteAwaitingChoice() === undefined ? createWorkerModels(config.workers, { connection: routerConnection, conversationId: overrides.sessionId, openRouterPreferences: () => configStore.get().openRouter,
109
+ ...(ownSignIn ? { routerSignIn: (origin) => configStore.getRouterSignIn(origin) } : {}) }) : null;
107
110
  const executor = new InProcessWorkerExecutor({
108
111
  provider: workerModels ? 'openai_compatible' : resolvedBackend.provider,
109
112
  apiKey: workerModels ? 'worker-model-pool' : resolvedBackend.apiKey,
@@ -4,6 +4,7 @@ import { getSkills } from '../skills/registry.js';
4
4
  import { runShellCommand } from '../utils/shell.js';
5
5
  import { configStore } from '../config.js';
6
6
  import { ToolCapability } from '../agent/runtime/capabilities.js';
7
+ import { routerAccount, routerRefusalGate } from '../agent/backends/router_gate.js';
7
8
  // ─── Input Routing ───────────────────────────────────────────────────
8
9
  /** Well-known system path prefixes that should NOT be treated as slash commands. */
9
10
  const FILE_PATH_PREFIXES = ['/Users/', '/home/', '/tmp/', '/var/', '/etc/', '/opt/'];
@@ -76,11 +77,11 @@ export function routeUserInput(text) {
76
77
  tokens.push(token);
77
78
  return { type: 'command', cmd, args: tokens.slice(1) };
78
79
  }
79
- if (['fork', 'side', 'claude', 'codex'].includes(cmd.toLowerCase())) {
80
+ if (['fork', 'side', 'claude', 'codex', 'ztc'].includes(cmd.toLowerCase())) {
80
81
  // A fork's body is authored task data, not tokenized command options,
81
- // and /claude and /codex read theirs as a prompt or a shell-quoted
82
- // argument list. Remove exactly the command separator and retain the
83
- // remaining bytes.
82
+ // /claude and /codex read theirs as a prompt or a shell-quoted
83
+ // argument list, and /ztc's text after its flags is a task. Remove
84
+ // exactly the command separator and retain the remaining bytes.
84
85
  const task = line.slice(cmd.length + 2);
85
86
  return { type: 'command', cmd, args: task.length ? [task] : [] };
86
87
  }
@@ -128,6 +129,11 @@ export function buildModelsController(config) {
128
129
  if (!active || routerCatalogScope(active) !== scope)
129
130
  throw new Error('Router discovery context changed. Retry model discovery.');
130
131
  await config.adoptRouterCatalog?.(catalog);
132
+ // A list Router has just sent (a cached one may predate a key added since) ends this account's holds for want
133
+ // of a key it now has: /provider refresh after adding one lets a pane's relayed messages through again.
134
+ if (!catalog.cached && !catalog.authRequired) {
135
+ routerRefusalGate.keysListed({ route: connection.origin, account: routerAccount(connection.token) }, catalog);
136
+ }
131
137
  return catalog;
132
138
  }
133
139
  catch (error) {
@@ -15,3 +15,19 @@ export declare function shouldMarkMirrorServerAsColonyChild(options: MirrorChild
15
15
  * it made. A pane opened or resumed is handed one (see consumePaneCredentialHandoff).
16
16
  */
17
17
  export declare function shouldAttachParentMirrorClient(options: ParentMirrorClientOptions, env: Record<string, string | undefined>): boolean;
18
+ export interface PaneControlCredentialOptions {
19
+ /** The desktop app's owner. */
20
+ desktopMode: boolean;
21
+ /** ZTC under zmux or the desktop app, which runs panes. */
22
+ muxMode: boolean;
23
+ /** ZTC started the mirror itself, without --mirror or /mirror start. */
24
+ autoStarted: boolean;
25
+ }
26
+ /**
27
+ * Whether a mirror, while sign-in is off, opens panes and takes typing only from a caller with a credential
28
+ * (MirrorStreamServer.setPaneControlCredentialRequired): the desktop owner's, and a zmux owner's own silent one. Every
29
+ * caller those serve holds a credential or is given one: the owner's panes, the Status pane, the browser ZTC opens with
30
+ * its link. An explicit `ztc --mirror` (and so every colony cell) is opened by hand, by people and colony's dashboard,
31
+ * so it keeps taking them from anyone on this computer, until outside access has an approval model of its own.
32
+ */
33
+ export declare function mirrorPaneControlNeedsCredential(options: PaneControlCredentialOptions): boolean;
@@ -18,3 +18,13 @@ export function shouldAttachParentMirrorClient(options, env) {
18
18
  return false;
19
19
  return options.colonyChild || options.paneMode;
20
20
  }
21
+ /**
22
+ * Whether a mirror, while sign-in is off, opens panes and takes typing only from a caller with a credential
23
+ * (MirrorStreamServer.setPaneControlCredentialRequired): the desktop owner's, and a zmux owner's own silent one. Every
24
+ * caller those serve holds a credential or is given one: the owner's panes, the Status pane, the browser ZTC opens with
25
+ * its link. An explicit `ztc --mirror` (and so every colony cell) is opened by hand, by people and colony's dashboard,
26
+ * so it keeps taking them from anyone on this computer, until outside access has an approval model of its own.
27
+ */
28
+ export function mirrorPaneControlNeedsCredential(options) {
29
+ return options.desktopMode || (options.muxMode && options.autoStarted);
30
+ }
@@ -70,6 +70,8 @@ export interface RuntimeChoicesInput {
70
70
  /** Zerg Router's Credentials page, for the person's own Router sign-in. */
71
71
  credentialsUrl?: string;
72
72
  }
73
+ /** How a route reads after a model: through Zerg Router, or on what bills it here. */
74
+ export declare function routeWord(provider: string, routed: boolean): string;
73
75
  /**
74
76
  * The lists a pane header's provider and model menus show (desktop_runtime_choices_v1), from what the pane's ZTC has
75
77
  * cached; the revision is the caller's (RuntimeChoicesPublication). Providers: Zerg Router's in Router's order, then
@@ -179,7 +179,7 @@ function modelRow(entry, group) {
179
179
  detail: fit(entry.detail, DESKTOP_RUNTIME_MAX_CHOICE_DETAIL_BYTES) || null, available: entry.available, group };
180
180
  }
181
181
  /** How a route reads after a model: through Zerg Router, or on what bills it here. */
182
- function routeWord(provider, routed) {
182
+ export function routeWord(provider, routed) {
183
183
  if (routed)
184
184
  return 'Zerg Router';
185
185
  if (isLocalSubscriptionProvider(provider))
@@ -6,6 +6,7 @@
6
6
  * the models discovery last found. It never lists models or fetches: listing Codex CLI's models starts codex
7
7
  * app-server, and a Router list older than 30 s starts a fetch. Discovery runs only when the menus ask (refresh_choices).
8
8
  */
9
+ import { routerCredentialsUrl } from '../agent/backends/router_keys.js';
9
10
  import { modelRouteStatus } from '../agent/commands/provider_choices.js';
10
11
  import { MODEL_CATALOG } from '../panes/model_catalog.js';
11
12
  import { RouterCatalogAuthenticationError } from '../utils/router_catalog.js';
@@ -47,7 +48,7 @@ export class RuntimeChoicesSource {
47
48
  ...(selected.routed ? {} : { directModels: this.directModels(selected.provider) }),
48
49
  modelsLoading: selected.routed ? this.routerLoading : this.listing.has(selected.provider),
49
50
  recentModels: pane.recentModels, newPane: pane.newPane,
50
- ...(origin ? { credentialsUrl: `${origin.replace(/\/+$/, '')}/dashboard?tab=credentials` } : {}),
51
+ ...(origin ? { credentialsUrl: routerCredentialsUrl(origin) } : {}),
51
52
  };
52
53
  }
53
54
  /**
@@ -23,6 +23,7 @@ function buildCommandCatalogEntries() {
23
23
  category: c.category,
24
24
  scope: 'global',
25
25
  agentRunnable: c.agentRunnable === true,
26
+ ...(c.agentCapabilities ? { capabilities: c.agentCapabilities } : {}),
26
27
  }));
27
28
  const registry = getModeRegistry();
28
29
  for (const mode of registry.listModes()) {
@@ -7,6 +7,8 @@ export type CliArgsValidationResult = {
7
7
  flag?: string;
8
8
  value?: string;
9
9
  };
10
+ /** Whether this process was launched with FLAG: one of its options, before any `--`, after which comes its prompt. */
11
+ export declare function hasLaunchFlag(flag: string, argv?: readonly string[]): boolean;
10
12
  /** Separate prompt text from options before the legacy flag consumers see it. */
11
13
  export declare function parsePromptInvocation(input: readonly string[]): {
12
14
  args: string[];
package/dist/cli_args.js CHANGED
@@ -8,6 +8,11 @@ const REQUIRED_VALUE_FLAGS = new Set([
8
8
  '--cwd', '--name', '--session-id', '--session-file', '--mode', '--agent-domain', '--domain-paths', '--embedded', '--embedded-rom', '--embedded-workflow', '--embedded-runtime-tick-ms', '--embedded-runtime-frame-budget', '--bench', '--bench-workflow', '--num-zergs', '--provider', '--model', '--auth-mode', '--router-url', '--profile', '--effort', '--thinking', '--emulation', '--prompt', '--max-iterations', '--timeout', '--output', '--output-schema', '--trajectory-jsonl', '--voyager-task', '--voyager-max-rounds', '--mirror-port', '--navigator-group', '--connect-zerg',
9
9
  ]);
10
10
  const OPTIONAL_VALUE_FLAGS = new Set(['--resume', '--continue', '-c', '--sfx']);
11
+ /** Whether this process was launched with FLAG: one of its options, before any `--`, after which comes its prompt. */
12
+ export function hasLaunchFlag(flag, argv = process.argv) {
13
+ const end = argv.indexOf('--');
14
+ return (end < 0 ? argv : argv.slice(0, end)).includes(flag);
15
+ }
11
16
  /** Separate prompt text from options before the legacy flag consumers see it. */
12
17
  export function parsePromptInvocation(input) {
13
18
  const args = [];
@@ -133,6 +133,8 @@ export declare class RatatuiApp {
133
133
  private agentBuiltForRoute;
134
134
  private readonly maxIterations?;
135
135
  private readonly initialPrompt?;
136
+ /** A pane's launch task is an agent's (PANE_TASK_AS_MESSAGE_ENV): its agent gets it as a message, never as a command. */
137
+ private readonly initialPromptAsMessage;
136
138
  private initialPaneInput;
137
139
  private readonly instanceTitleProvider;
138
140
  private readonly instanceRegistry;
@@ -822,6 +824,18 @@ export declare class RatatuiApp {
822
824
  private notePaneCreated;
823
825
  private shouldIgnorePaneClosed;
824
826
  private publishPaneSystemMessage;
827
+ /**
828
+ * Why a ZTC pane opened now on PROVIDER's MODEL, or on the route new panes start on when it names neither, would
829
+ * fail on its first message: Zerg Router, its route, has no key for its provider (asked once more first). Undefined
830
+ * when it can run, or Router is not its route. The agent's create_ztc_pane checks its panes the same way.
831
+ */
832
+ private keylessZtcPaneRoute;
833
+ /**
834
+ * A ZTC pane a child ZTC opens through the pane relay (its /ztc, or create_ztc_pane there) starts on the route its
835
+ * launch flags name, which only its create_pane tells this process: the pane's launch spec is read back from them and
836
+ * recorded as for a pane this process opens itself, so a split or a restore of it starts there (see splitRouteFor).
837
+ */
838
+ private noteChildPaneLaunch;
825
839
  private trackPendingPaneLaunch;
826
840
  private dailySelect;
827
841
  private observeRestoredPaneState;
@@ -13,7 +13,7 @@ import { isPaneRefusalFor, waitForPaneCreatedOrError } from './agent/tools/pane.
13
13
  import { findAgentCli } from './panes/agent_cli.js';
14
14
  import { agentCliFromRequestId, formatAgentPaneMessage, openAgentPane, typeLineIntoPane } from './panes/agent_panes.js';
15
15
  import { agentCliFromChoice, newPaneChoices } from './panes/new_pane_choices.js';
16
- import { MOTSI_PANE_ENV, remoteViewMotsi, throughMotsi } from './panes/motsi.js';
16
+ import { MOTSI_PANE_ENV, remoteViewMotsi, runsMotsi, throughMotsi } from './panes/motsi.js';
17
17
  import { IntakeNotifications } from './intake/notifications.js';
18
18
  import { projectGoal } from './goal_contract.js';
19
19
  import { isToolResultMessage } from './utils/tool_result_message.js';
@@ -42,7 +42,7 @@ import { normalizeProviderId } from './agent/backends/provider_ids.js';
42
42
  import { collectUsageViews, buildUsageViews, nativeUsageView } from './usage_projection.js';
43
43
  import { createUsageSnapshot, recordUsageReceipt } from './usage_snapshot.js';
44
44
  import { withActiveProfileArg } from './config/profiles.js';
45
- import { DEFAULT_ROUTER_ORIGIN, RouterConfigurationError } from './router_auth.js';
45
+ import { DEFAULT_ROUTER_ORIGIN, RouterConfigurationError, routerSignInRefusal } from './router_auth.js';
46
46
  import { CODEX_REASONING_EFFORTS } from './config/types.js';
47
47
  import { getSupportedCodexReasoningEfforts, unsupportedEffortMessage, } from './utils/models.js';
48
48
  import { getVersion } from './utils/version.js';
@@ -140,7 +140,9 @@ import { clearWorkerExecutor } from './worker/index.js';
140
140
  import { isPhantomCompletion } from './app/phantom_completion.js';
141
141
  import { SelectionCompletion } from './app/selection_completion.js';
142
142
  import { routerCatalogScope } from './utils/router_catalog.js';
143
- import { shouldAttachParentMirrorClient, shouldMarkMirrorServerAsColonyChild } from './app/mirror_startup.js';
143
+ import { mirrorPaneControlNeedsCredential, shouldAttachParentMirrorClient, shouldMarkMirrorServerAsColonyChild } from './app/mirror_startup.js';
144
+ import { keylessRouterModelRefusal } from './agent/commands/router_availability.js';
145
+ import { keylessZtcPaneRoute } from './panes/worker_route.js';
144
146
  import { buildDesktopUpdateRelaunchContext, buildHotRestartLaunch, prepareDesktopUpdateAuthorization, reduceDesktopUpdateOwnerHandshake, requestColonyCellRestart, } from './app/restart.js';
145
147
  import { PANE_CREDENTIAL_ENV, WORKSPACE_MONITOR_CREDENTIAL_REQUEST, paneCredentialRelaunchArgs, withoutMirrorCredentials } from './web/pane_credentials.js';
146
148
  export { buildDesktopUpdateRelaunchContext, buildHotRestartArgs, requestColonyCellRestart, } from './app/restart.js';
@@ -155,8 +157,8 @@ import { linkWorkspaceAgentSessions, resolveWorkspaceAgentSession } from './work
155
157
  import { hostedSessionSettingsEqual, hostedSettingsConfigPatch, isHostedMuxCommandAllowed, parseHostedSessionSettings, } from './hosted/session_settings.js';
156
158
  import { registerHostedAgentToolBridge } from './hosted/tool_bridge.js';
157
159
  import { PaneRegistry, isNativeZtcPane, mergeSessionPaneSpecs, nativeLaunchRouterOrigin } from './panes/pane_registry.js';
158
- import { buildZtcPaneLaunchCommand, createZtcLaunchSpec } from './panes/ztc_launch.js';
159
- import { preparePaneInitialInput, loadPaneInitialInput, readSavedPaneInitialInput, acknowledgePaneInitialInput, waitForPaneInitialInput, cleanupPaneInitialInput } from './panes/initial_input.js';
160
+ import { buildZtcPaneLaunchCommand, createZtcLaunchSpec, ztcLaunchSpecFromArgs } from './panes/ztc_launch.js';
161
+ import { preparePaneInitialInput, loadPaneInitialInput, readSavedPaneInitialInput, acknowledgePaneInitialInput, waitForPaneInitialInput, cleanupPaneInitialInput, PANE_TASK_AS_MESSAGE_ENV } from './panes/initial_input.js';
160
162
  import { getProviderForModel, isCatalogModelForProvider, isPaneProvider, resolveModelAndProvider } from './panes/model_catalog.js';
161
163
  import { registerToolCallbacks, clearToolCallbacks } from './app/tool_callbacks.js';
162
164
  import { applyAgentEventToState, buildActivityDisplayState, formatApiRetryNotice } from './app/activity.js';
@@ -166,6 +168,7 @@ import { openUrlInBrowser } from './utils/open_url.js';
166
168
  import { canAskAtLaunch } from './utils/session_interactivity.js';
167
169
  import { buildCredentialSetupMessage, buildNoCredentialsWelcome, buildReadyWelcome, buildResumedWelcome, createFirstRunLaunchMessage, excludePrintedFirstRunWelcome, shouldDeferFirstRunScrollback, } from './onboarding/first_run.js';
168
170
  import { routerLoginTip, routerTipForError } from './onboarding/router_tips.js';
171
+ import { hasLaunchFlag } from './cli_args.js';
169
172
  import { askHowToConnectAtLaunch } from './onboarding/zergai_login.js';
170
173
  /** A Zerg Router login tip stays in the status line long enough to read. */
171
174
  const ROUTER_TIP_TOAST_MS = 12_000;
@@ -177,7 +180,7 @@ export { childPaneEventDisposition } from './app/child_pane_events.js';
177
180
  import { createRecapController } from './app/recap.js';
178
181
  import { clearStaleTodosOnBoot, normalizeTodoItems } from './app/todo_state.js';
179
182
  import { writePaneResponseSync } from './utils/pane_response.js';
180
- import { launchedByAnotherZtc } from './utils/subprocess_env.js';
183
+ import { hostEffortPolicyBlanks, launchedByAnotherZtc } from './utils/subprocess_env.js';
181
184
  import { registerInstance, deregisterInstance, loadInstances, updateInstance, heartbeatInstance, reapStoppedInstances, INSTANCE_HEARTBEAT_MS, } from './instance_registry.js';
182
185
  import { loadPreviewsForInstances } from './navigator_preview.js';
183
186
  import { FormWidget, SelectWidget, selectOptionSummary, TextInputWidget, QuestionnaireWidget, PromptViewerWidget, LogViewWidget } from './ui/widgets/index.js';
@@ -216,7 +219,7 @@ function playSfxLazy(event) {
216
219
  // existing public surface of this module.
217
220
  const DEBUG_ENABLED = process.env.ZTC_DEBUG === '1';
218
221
  const TRANSCRIPT_DEBUG_ENABLED = process.env.ZTC_TRANSCRIPT_DEBUG === '1'
219
- || process.argv.includes('--transcript-debug');
222
+ || hasLaunchFlag('--transcript-debug');
220
223
  const STATUS_KEY_SEPARATOR = '\u0000';
221
224
  const TRANSCRIPT_DEBUG_LOG_FILE = join(tmpdir(), `ztc-transcript-${process.pid}.log`);
222
225
  if (TRANSCRIPT_DEBUG_ENABLED) {
@@ -466,6 +469,8 @@ export class RatatuiApp {
466
469
  agentBuiltForRoute = null;
467
470
  maxIterations;
468
471
  initialPrompt;
472
+ /** A pane's launch task is an agent's (PANE_TASK_AS_MESSAGE_ENV): its agent gets it as a message, never as a command. */
473
+ initialPromptAsMessage;
469
474
  initialPaneInput = null;
470
475
  instanceTitleProvider;
471
476
  instanceRegistry;
@@ -1292,6 +1297,9 @@ export class RatatuiApp {
1292
1297
  this.startupZergEndpoint = options?.startupZergEndpoint;
1293
1298
  this.maxIterations = options?.maxIterations;
1294
1299
  this.initialPrompt = options?.initialPrompt;
1300
+ // Read once, and kept from everything this pane starts.
1301
+ this.initialPromptAsMessage = options?.pane === true && process.env[PANE_TASK_AS_MESSAGE_ENV] === '1';
1302
+ delete process.env[PANE_TASK_AS_MESSAGE_ENV];
1295
1303
  this.sessionFile = options?.sessionFile;
1296
1304
  this.instanceTitleProvider = options?.instanceTitleProvider ?? resolveNavigatorInstanceTitle;
1297
1305
  this.instanceRegistry = options?.instanceRegistry ?? DEFAULT_INSTANCE_REGISTRY;
@@ -1511,13 +1519,18 @@ export class RatatuiApp {
1511
1519
  process.env.ZTC_API_URL = configStore.getApiBaseUrl();
1512
1520
  }
1513
1521
  // Auto-started mirrors bind to loopback only (127.0.0.1). Explicit
1514
- // --mirror keeps the historical 0.0.0.0 behavior via the env/default
1515
- // resolution in createMirrorStreamServer. This prevents silently
1516
- // exposing sessions to other machines on the LAN — and on macOS it
1517
- // avoids triggering the "accept incoming connections?" firewall
1518
- // prompt for every background ZTC.
1522
+ // --mirror resolves its bind in createMirrorStreamServer: ZTC_MIRROR_HOST,
1523
+ // else loopback while sign-in is off and every interface once it is on
1524
+ // (defaultMirrorHost). This prevents silently exposing sessions to other
1525
+ // machines on the LAN — and on macOS it avoids triggering the "accept
1526
+ // incoming connections?" firewall prompt for every background ZTC.
1519
1527
  const autoHost = autoMirror ? '127.0.0.1' : undefined;
1520
1528
  this.mirrorServer = createMirrorStreamServer(this.pendingMirrorPort, this.shouldPersistSession(), this.sessionId, autoHost, this.sessionId);
1529
+ // The desktop owner's mirror and a zmux owner's own silent one open panes and take typing only from a caller with
1530
+ // a credential while sign-in is off; the link ZTC opens the browser with carries one.
1531
+ this.mirrorServer.setPaneControlCredentialRequired(mirrorPaneControlNeedsCredential({
1532
+ desktopMode: this.desktopMode, muxMode: this.muxMode, autoStarted: this.mirrorAutoStarted
1533
+ }));
1521
1534
  const hostedRuntime = this.isHostedRuntime();
1522
1535
  this.mirrorServer.setHostedMode(hostedRuntime);
1523
1536
  if (hostedRuntime) {
@@ -3402,6 +3415,7 @@ export class RatatuiApp {
3402
3415
  hasViewers: () => this.mirrorServer ? this.mirrorServer.getViewerCount() > 0 : !!this.mirrorClient,
3403
3416
  getPort: () => this.mirrorServer?.getPort() ?? 0,
3404
3417
  getUrl: (params) => this.mirrorServer?.getLaunchUrl(params) ?? '',
3418
+ accessNotice: () => this.mirrorServer?.remoteAccessNotice(),
3405
3419
  start: async (port) => {
3406
3420
  await this.startMirrorFromCommand(port);
3407
3421
  },
@@ -3680,6 +3694,9 @@ export class RatatuiApp {
3680
3694
  process.env.ZTC_API_URL = configStore.getApiBaseUrl();
3681
3695
  }
3682
3696
  this.mirrorServer = await startMirrorStreamServer(requestedPort, this.sessionId, this.sessionId);
3697
+ this.mirrorServer.setPaneControlCredentialRequired(mirrorPaneControlNeedsCredential({
3698
+ desktopMode: this.desktopMode, muxMode: this.muxMode, autoStarted: false
3699
+ }));
3683
3700
  this.mirrorServer.setRuntimeStatsProvider(() => this.getRuntimeStats());
3684
3701
  this.mirrorServer.setPromptTurnsProvider(() => projectCorrelatedTurns(this.committedTurnMessages, this.sessionId, this.committedPromptTurns));
3685
3702
  this.mirrorServer.onCorrelatedInput(async (input) => (await this.handleMirrorInput(input)) ?? { ok: false, reason: 'input_unavailable' }, () => goalManager.get()?.status !== 'active');
@@ -4733,9 +4750,14 @@ export class RatatuiApp {
4733
4750
  if (this.muxMode && process.env.ZTC_PANE_RELAY) {
4734
4751
  // Both interactive (TuiProcess) and headless (HeadlessPaneManager) serve the relay.
4735
4752
  // This allows sub-panes spawned within colony cells to connect and use pane tools.
4736
- this.paneRelay = new PaneRelayServer(this.tui, process.env.ZTC_PANE_RELAY);
4737
- // A child's report of its own pane tells this process the route it runs on (see noteChildPaneReport).
4738
- this.paneRelay.onChildCommand((command, announced) => this.noteChildPaneReport(command, announced));
4753
+ // Children's pane lists say which panes run Claude Code or Codex, which only this ZTC knows.
4754
+ this.paneRelay = new PaneRelayServer(this.tui, process.env.ZTC_PANE_RELAY, { agentCliOf: paneId => this.agentCliPanes.get(paneId) });
4755
+ // A child's report of its own pane tells this process the route it runs on (see noteChildPaneReport), and a ZTC
4756
+ // pane it opens, the route that pane starts on (see noteChildPaneLaunch).
4757
+ this.paneRelay.onChildCommand((command, announced) => {
4758
+ this.noteChildPaneLaunch(command);
4759
+ this.noteChildPaneReport(command, announced);
4760
+ });
4739
4761
  await this.paneRelay.start();
4740
4762
  this.assertStartupActive();
4741
4763
  debugLog(`[start] Pane relay server started: ${process.env.ZTC_PANE_RELAY}`);
@@ -4909,6 +4931,7 @@ export class RatatuiApp {
4909
4931
  authEmail: configStore.isAuthenticated() ? auth?.email : undefined,
4910
4932
  workspaceName: configStore.isAuthenticated() ? workspace?.name : undefined,
4911
4933
  routerSession: configStore.getRouterSessionStatus(),
4934
+ routerDevice: configStore.getRouterDeviceName(),
4912
4935
  };
4913
4936
  };
4914
4937
  if (this.resumedSession && this.resumedSession.messages.length > 0) {
@@ -5079,16 +5102,19 @@ export class RatatuiApp {
5079
5102
  // still pass --mirror.
5080
5103
  if (this.mirrorServer && !this.mirrorAutoStarted && !this.muxOnlyMirror) {
5081
5104
  const mirrorUrl = this.mirrorServer.getLaunchUrl();
5105
+ // Said once, as it starts: who can open it (an open mirror: this computer alone).
5106
+ const accessNotice = this.mirrorServer.remoteAccessNotice();
5082
5107
  this.controller.addMessage({
5083
5108
  role: 'system',
5084
- content: `🪞 Mirror mode enabled at ${mirrorUrl}`,
5109
+ content: `🪞 Mirror mode enabled at ${mirrorUrl}${accessNotice ? `\n${accessNotice}` : ''}`,
5085
5110
  metadata: { ephemeral: true },
5086
5111
  });
5087
5112
  // Auto-open browser:
5088
5113
  // - always for normal interactive runs (unless --no-browser-open suppresses it)
5089
5114
  // - for headless mirror only when explicitly enabled by --open-mirror
5090
5115
  if ((!this.headlessMirror || this.openMirrorOnStart) && !this.noBrowserOpen) {
5091
- debugLog(`[Mirror] Calling openUrlInBrowser(${mirrorUrl})`);
5116
+ // Logs name the port: the link can carry the mirror's credential, and the mirror serves its debug log.
5117
+ debugLog(`[Mirror] Calling openUrlInBrowser for port ${this.mirrorServer.getPort()}`);
5092
5118
  openUrlInBrowser(mirrorUrl).then(() => {
5093
5119
  debugLog(`[Mirror] Browser launch reported success`);
5094
5120
  }).catch((err) => {
@@ -5104,7 +5130,7 @@ export class RatatuiApp {
5104
5130
  const reason = this.headlessMirror && !this.openMirrorOnStart
5105
5131
  ? 'headless mirror without --open-mirror'
5106
5132
  : this.noBrowserOpen ? '--no-browser-open' : 'unknown';
5107
- debugLog(`[Mirror] Skipping browser auto-open (reason: ${reason}) — server at ${mirrorUrl}`);
5133
+ debugLog(`[Mirror] Skipping browser auto-open (reason: ${reason}) — server on port ${this.mirrorServer.getPort()}`);
5108
5134
  }
5109
5135
  // Wire bus for multi-pane mode (register parent as member 0 if not already)
5110
5136
  if (this.muxMode) {
@@ -5116,7 +5142,7 @@ export class RatatuiApp {
5116
5142
  else if (this.mirrorServer && this.mirrorAutoStarted) {
5117
5143
  // Auto-started: silent — but we still need the bus wiring in mux
5118
5144
  // mode so that navigator-originated browser visits can send messages.
5119
- debugLog(`[Mirror] Auto-started silent mirror at ${this.mirrorServer.getLaunchUrl()}`);
5145
+ debugLog(`[Mirror] Auto-started silent mirror on port ${this.mirrorServer.getPort()}`);
5120
5146
  if (this.muxMode) {
5121
5147
  this.mirrorServer.onBusMessage(0, 'Overseer', (msg) => {
5122
5148
  this.handleBusMessage(msg);
@@ -5457,6 +5483,10 @@ export class RatatuiApp {
5457
5483
  if (this.initialPromptStep) {
5458
5484
  this.holdInitialPrompt(prompt);
5459
5485
  }
5486
+ else if (this.initialPromptAsMessage) {
5487
+ // An agent's task: a message to this pane's agent, word for word, which no one entered here.
5488
+ setTimeout(() => void this.handleSubmit(prompt, undefined, undefined, true), 0);
5489
+ }
5460
5490
  else {
5461
5491
  setTimeout(() => {
5462
5492
  void this.submitPersonInput(prompt);
@@ -5729,6 +5759,26 @@ export class RatatuiApp {
5729
5759
  publishPaneSystemMessage(paneId, content) {
5730
5760
  this.mirrorServer?.publishPaneSystemMessage(paneId, content);
5731
5761
  }
5762
+ /**
5763
+ * Why a ZTC pane opened now on PROVIDER's MODEL, or on the route new panes start on when it names neither, would
5764
+ * fail on its first message: Zerg Router, its route, has no key for its provider (asked once more first). Undefined
5765
+ * when it can run, or Router is not its route. The agent's create_ztc_pane checks its panes the same way.
5766
+ */
5767
+ async keylessZtcPaneRoute(provider, model) {
5768
+ return keylessZtcPaneRoute(provider, model);
5769
+ }
5770
+ /**
5771
+ * A ZTC pane a child ZTC opens through the pane relay (its /ztc, or create_ztc_pane there) starts on the route its
5772
+ * launch flags name, which only its create_pane tells this process: the pane's launch spec is read back from them and
5773
+ * recorded as for a pane this process opens itself, so a split or a restore of it starts there (see splitRouteFor).
5774
+ */
5775
+ noteChildPaneLaunch(command) {
5776
+ if (command.type !== 'create_pane' || command.pane_type !== 'ztc' || !command.request_id || !command.args)
5777
+ return;
5778
+ const spec = ztcLaunchSpecFromArgs(command.args, { cwd: command.cwd, title: command.title });
5779
+ if (spec)
5780
+ this.trackPendingPaneLaunch(command.request_id, spec);
5781
+ }
5732
5782
  trackPendingPaneLaunch(requestId, launchSpec) {
5733
5783
  this.paneRegistry.trackPendingCreate(requestId, launchSpec);
5734
5784
  }
@@ -6279,6 +6329,14 @@ export class RatatuiApp {
6279
6329
  if (this.isHostedRuntime()) {
6280
6330
  return { ok: false, error: 'Hosted workbenches allow one agent pane per thread.' };
6281
6331
  }
6332
+ // The browser keeps its own default model and sends it here, unchecked: a pane on a model Router has no key for
6333
+ // would fail on its first message, so it is refused with where the key goes, and Main says so.
6334
+ const keyless = await this.keylessZtcPaneRoute(command.provider, command.model);
6335
+ if (keyless) {
6336
+ const error = `No ZTC pane was opened: ${keyless}`;
6337
+ this.publishPaneSystemMessage(0, error);
6338
+ return { ok: false, error };
6339
+ }
6282
6340
  const title = command.title || `ZTC ${this.childPaneIds.size + 1}`;
6283
6341
  try {
6284
6342
  const launchSpec = this.createZtcPaneSpec({
@@ -6372,6 +6430,14 @@ export class RatatuiApp {
6372
6430
  this.publishPaneSystemMessage(command.pane_id, error);
6373
6431
  return { ok: false, error };
6374
6432
  }
6433
+ // A model Router has no key for is refused with where the key goes, once Router has been asked again.
6434
+ const origin = configStore.getPersonalRouterCredential()?.origin;
6435
+ const keyless = route === 'zrouter' ? await keylessRouterModelRefusal(resolved.provider, resolved.model, { catalog,
6436
+ refresh: () => buildModelsController(configStore).catalog(undefined, { refresh: true }), ...(origin ? { origin } : {}) }) : undefined;
6437
+ if (keyless) {
6438
+ this.publishPaneSystemMessage(command.pane_id, keyless);
6439
+ return { ok: false, error: keyless };
6440
+ }
6375
6441
  nextOverride = { provider: resolved.provider, model: resolved.model };
6376
6442
  }
6377
6443
  if (this.mirrorServer?.isPaneBusy(command.pane_id)) {
@@ -9744,6 +9810,13 @@ export class RatatuiApp {
9744
9810
  this.addSystemMessage(`Message not sent. ${ROUTE_AWAITS_A_CHOICE} Then press Enter to send it.`);
9745
9811
  return;
9746
9812
  }
9813
+ if (sendRoute.signIn !== undefined) {
9814
+ // Kept in the conversation, so the first message after a sign-in carries it (a launch's sign-in recovery does): the
9815
+ // refusal says so, since nothing was sent now.
9816
+ this.controller.addMessage({ role: 'user', content: text });
9817
+ this.addErrorMessage(`${sendRoute.signIn} What you typed stays here and goes with your next message.`);
9818
+ return;
9819
+ }
9747
9820
  if (!sendRoute.ready) {
9748
9821
  if (!credentialPrompted && sendRoute.route
9749
9822
  && this.askForSendCredential(sendRoute.route, input, queuedEntryId, literalInput, person, via))
@@ -9855,6 +9928,11 @@ export class RatatuiApp {
9855
9928
  // login elsewhere could reach (see ConfigStore.routeAwaitingChoice).
9856
9929
  if (error instanceof RouteAwaitingChoiceError)
9857
9930
  return { ready: false, awaitingChoice: error.notice };
9931
+ // A Zerg Router route with no current Router sign-in (signed out, or expired) reaches no model, whatever key or
9932
+ // ZergAI platform login is here: nothing is sent, and the pane says how to sign in.
9933
+ if (error instanceof RouterConfigurationError && error.needsSignIn) {
9934
+ return { ready: false, signIn: routerSignInRefusal(error.kind === 'expired' ? 'expired' : 'signed_out') };
9935
+ }
9858
9936
  return { ready: configStore.hasApiKey() || configStore.isAuthenticated() };
9859
9937
  }
9860
9938
  // A provider only Zerg Router serves (Modal among them) has no platform fallback: the factory refuses it off Router.
@@ -9925,7 +10003,7 @@ export class RatatuiApp {
9925
10003
  showLaunchConnectPrompt() {
9926
10004
  const ctx = this.buildCommandContext(message => {
9927
10005
  this.controller.addMessage(message);
9928
- if (message.role === 'system')
10006
+ if (message.role === 'system' && message.metadata?.localOnly !== true)
9929
10007
  this.mirror?.publishMessage('system', message.content);
9930
10008
  });
9931
10009
  showConnectPrompt(ctx, { launch: true, onFinished: () => {
@@ -11445,7 +11523,7 @@ export class RatatuiApp {
11445
11523
  finalMessage: result.content.trim() || result.reasoning?.trim() ? {
11446
11524
  id: generateId(), role: 'assistant', content: result.content, timestamp: new Date(),
11447
11525
  turn: this.streamingPromptTurn?.snapshot(),
11448
- metadata: { ...this.getAssistantStreamMetadata(), ...(result.reasoning ? { reasoningContent: result.reasoning } : {}) },
11526
+ metadata: { ...this.getAssistantStreamMetadata(), ...(result.reasoning ? { reasoningContent: result.reasoning, reasoningModel: result.reasoningModel } : {}) },
11449
11527
  ...(result.nativeContent ? { nativeContent: result.nativeContent, nativeModel: result.nativeModel, nativeContextId: result.nativeContextId } : {}),
11450
11528
  } : undefined,
11451
11529
  }));
@@ -11477,7 +11555,7 @@ export class RatatuiApp {
11477
11555
  toolCalls: lightToolCalls.length > 0 ? lightToolCalls : undefined,
11478
11556
  // Carry the provider's reasoning trace so the next turn replays this
11479
11557
  // assistant message intact; reasoning models expect it back as-is.
11480
- metadata: result.reasoning ? { ...finalMeta, reasoningContent: result.reasoning } : finalMeta,
11558
+ metadata: result.reasoning ? { ...finalMeta, reasoningContent: result.reasoning, reasoningModel: result.reasoningModel } : finalMeta,
11481
11559
  });
11482
11560
  if (result.content)
11483
11561
  this.maybeSpeakText(result.content);
@@ -11494,7 +11572,7 @@ export class RatatuiApp {
11494
11572
  ...(result.nativeContent ? { nativeContent: result.nativeContent, nativeModel: result.nativeModel, nativeContextId: result.nativeContextId } : {}),
11495
11573
  ...(lightToolCalls.length > 0 ? { toolCalls: lightToolCalls } : {}),
11496
11574
  metadata: { ...m.metadata, ...finalMeta,
11497
- ...(result.reasoning ? { reasoningContent: result.reasoning } : {}),
11575
+ ...(result.reasoning ? { reasoningContent: result.reasoning, reasoningModel: result.reasoningModel } : {}),
11498
11576
  },
11499
11577
  }
11500
11578
  : m);
@@ -12601,7 +12679,8 @@ export class RatatuiApp {
12601
12679
  }
12602
12680
  const context = this.buildCommandContext((msg) => {
12603
12681
  this.controller.addMessage(msg);
12604
- if (msg.role === 'system') {
12682
+ // A message for this terminal only (the mirror's own link) never reaches the mirror's transcript.
12683
+ if (msg.role === 'system' && msg.metadata?.localOnly !== true) {
12605
12684
  this.mirror?.publishMessage('system', msg.content);
12606
12685
  }
12607
12686
  }, origin);
@@ -14422,6 +14501,8 @@ export class RatatuiApp {
14422
14501
  cwd: options.cwd || this.shellCwd || process.cwd(),
14423
14502
  findBinary: id => this.installedAgentClis()[id] ?? null,
14424
14503
  motsi: this.paneMotsi(),
14504
+ // The chooser, the desktop menus and splits, and the browser's + menu are the person's.
14505
+ openedBy: 'person',
14425
14506
  });
14426
14507
  if (result.notice)
14427
14508
  this.addSystemMessage(result.notice);
@@ -14717,6 +14798,8 @@ export class RatatuiApp {
14717
14798
  title,
14718
14799
  paneType: 'process',
14719
14800
  });
14801
+ // The renderer started with this process's environment; a host's effort policy in it is ZTC's own (hostEffortPolicyBlanks).
14802
+ const env = { ...hostEffortPolicyBlanks(), ...(motsi ? MOTSI_PANE_ENV : {}) };
14720
14803
  return this.tui.send({
14721
14804
  type: 'create_pane',
14722
14805
  request_id: requestId,
@@ -14725,7 +14808,7 @@ export class RatatuiApp {
14725
14808
  cwd,
14726
14809
  title,
14727
14810
  pane_type: 'process',
14728
- ...(motsi ? { env: { ...MOTSI_PANE_ENV } } : {}),
14811
+ ...(Object.keys(env).length > 0 ? { env } : {}),
14729
14812
  ...(options?.direction ? { direction: options.direction } : {}),
14730
14813
  ...(options?.ratio !== undefined ? { ratio: options.ratio } : {}),
14731
14814
  ...(options?.target !== undefined ? { target: options.target } : {}),
@@ -14750,7 +14833,8 @@ export class RatatuiApp {
14750
14833
  const requestId = `create-command-${generateSessionId()}`;
14751
14834
  const cwd = options?.cwd || this.shellCwd || process.cwd();
14752
14835
  const title = options?.title || fallbackTitle;
14753
- const motsi = this.paneMotsi();
14836
+ // MotSi itself (its dashboard, which shows every sign-in's emails and usage) never runs through motsi run.
14837
+ const motsi = runsMotsi(command) ? null : this.paneMotsi();
14754
14838
  const launched = motsi ? throughMotsi(motsi, title, { command: shellCommand, args: shellArgs }) : { command: shellCommand, args: shellArgs };
14755
14839
  this.trackPendingPaneLaunch(requestId, {
14756
14840
  kind: 'process',
@@ -14760,6 +14844,8 @@ export class RatatuiApp {
14760
14844
  title,
14761
14845
  paneType: 'command',
14762
14846
  });
14847
+ // As for a shell: a host's effort policy in the renderer's environment is ZTC's own (hostEffortPolicyBlanks).
14848
+ const env = { ...hostEffortPolicyBlanks(), ...(motsi ? MOTSI_PANE_ENV : {}) };
14763
14849
  return this.tui.send({
14764
14850
  type: 'create_pane',
14765
14851
  request_id: requestId,
@@ -14768,7 +14854,7 @@ export class RatatuiApp {
14768
14854
  cwd,
14769
14855
  title,
14770
14856
  pane_type: 'command',
14771
- ...(motsi ? { env: { ...MOTSI_PANE_ENV } } : {}),
14857
+ ...(Object.keys(env).length > 0 ? { env } : {}),
14772
14858
  ...(options?.target !== undefined ? { target: options.target } : {}),
14773
14859
  })
14774
14860
  ? null