@zergai/ztc 0.26.6-dev.202611240947 → 0.27.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.
- package/README.md +629 -167
- package/RUST_THIRD_PARTY_LICENSES.txt +5 -5
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/zmux-linux-x64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-computer-darwin-arm64 +0 -0
- package/bin/ztc-llm-darwin-arm64 +0 -0
- package/bin/ztc-tts-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/ztc-tui-linux-x64 +0 -0
- package/bin/zterm-darwin-arm64 +2 -2
- package/dist/App.js +6 -1
- package/dist/agent/agent.d.ts +21 -15
- package/dist/agent/agent.js +389 -163
- package/dist/agent/backends/codex_app_server.d.ts +7 -1
- package/dist/agent/backends/codex_app_server.js +11 -1
- package/dist/agent/backends/gemini.js +22 -8
- package/dist/agent/commands/batch.js +8 -0
- package/dist/agent/commands/config.js +10 -0
- package/dist/agent/commands/environment.js +5 -5
- package/dist/agent/commands/goal.d.ts +1 -0
- package/dist/agent/commands/goal.js +2 -1
- package/dist/agent/commands/index.js +2 -1
- package/dist/agent/commands/manifest.js +4 -0
- package/dist/agent/commands/optimize.js +5 -2
- package/dist/agent/commands/pane_cli.d.ts +29 -0
- package/dist/agent/commands/pane_cli.js +303 -0
- package/dist/agent/commands/settings.js +13 -3
- package/dist/agent/commands/shannon.js +8 -0
- package/dist/agent/commands/update.js +15 -3
- package/dist/agent/commands/zerg.js +31 -1
- package/dist/agent/commands/ztc_pane.js +3 -1
- package/dist/agent/factory.d.ts +4 -0
- package/dist/agent/factory.js +11 -1
- package/dist/agent/loop_policy.d.ts +42 -5
- package/dist/agent/loop_policy.js +206 -3
- package/dist/agent/runtime/command_jobs.d.ts +5 -0
- package/dist/agent/runtime/command_jobs.js +241 -31
- package/dist/agent/runtime/command_wait.d.ts +2 -0
- package/dist/agent/runtime/command_wait.js +1 -0
- package/dist/agent/runtime/done_report.d.ts +18 -0
- package/dist/agent/runtime/done_report.js +130 -0
- package/dist/agent/runtime/execution_context.js +4 -1
- package/dist/agent/runtime/failure_cause.d.ts +2 -0
- package/dist/agent/runtime/failure_cause.js +35 -0
- package/dist/agent/runtime/policy.d.ts +14 -2
- package/dist/agent/runtime/policy.js +104 -12
- package/dist/agent/runtime/quiet_job.d.ts +18 -0
- package/dist/agent/runtime/quiet_job.js +48 -0
- package/dist/agent/runtime/recovery.d.ts +1 -5
- package/dist/agent/runtime/recovery.js +2 -44
- package/dist/agent/runtime/tool_runtime.d.ts +1 -0
- package/dist/agent/runtime/tool_runtime.js +2 -0
- package/dist/agent/subagent.js +6 -1
- package/dist/agent/tools/deferred.js +1 -0
- package/dist/agent/tools/index.d.ts +2 -0
- package/dist/agent/tools/index.js +1 -0
- package/dist/agent/tools/outcome.d.ts +15 -0
- package/dist/agent/tools/outcome.js +107 -0
- package/dist/agent/tools/pane.d.ts +2 -1
- package/dist/agent/tools/pane.js +21 -3
- package/dist/agent/tools/registry.js +2 -0
- package/dist/agent/tools/shell.d.ts +1 -0
- package/dist/agent/tools/shell.js +128 -17
- package/dist/agent/tools/sim_domain_tools.js +4 -2
- package/dist/agent/tools/supervision.js +4 -2
- package/dist/agent/tools/types.d.ts +3 -0
- package/dist/app/command_context.js +5 -9
- package/dist/app/conversation_compaction.d.ts +4 -2
- package/dist/app/conversation_compaction.js +16 -5
- package/dist/app/headless_shell_mode.d.ts +14 -0
- package/dist/app/headless_shell_mode.js +7 -0
- package/dist/app/hosted_resident.d.ts +356 -0
- package/dist/app/hosted_resident.js +677 -0
- package/dist/app/restart.js +11 -2
- package/dist/app/session_manager.d.ts +5 -0
- package/dist/app/session_manager.js +21 -6
- package/dist/app/session_messages.js +6 -6
- package/dist/app/workspace_layout_controller.js +7 -0
- package/dist/batch/worktree.d.ts +10 -0
- package/dist/batch/worktree.js +15 -0
- package/dist/bench/registry.js +4 -2
- package/dist/cli_args.js +1 -1
- package/dist/cli_main.js +80 -10
- package/dist/cli_ratatui.d.ts +75 -0
- package/dist/cli_ratatui.js +485 -84
- package/dist/components/InputArea.js +4 -4
- package/dist/config/execution.d.ts +10 -0
- package/dist/config/execution.js +10 -0
- package/dist/config/hosted_runtime.d.ts +4 -1
- package/dist/config/hosted_runtime.js +4 -1
- package/dist/config/permission_pin.d.ts +34 -2
- package/dist/config/permission_pin.js +52 -2
- package/dist/config/person_command_policy.d.ts +38 -0
- package/dist/config/person_command_policy.js +11 -0
- package/dist/config/profiles.d.ts +21 -0
- package/dist/config/profiles.js +56 -2
- package/dist/config/types.d.ts +4 -1
- package/dist/config.js +34 -19
- package/dist/desktop/daily/codex_exec_adapter.js +7 -2
- package/dist/desktop/daily/desktop_wiring.d.ts +7 -1
- package/dist/desktop/daily/desktop_wiring.js +11 -3
- package/dist/desktop/daily/recipes.js +20 -4
- package/dist/desktop/health.d.ts +24 -0
- package/dist/desktop/health.js +151 -0
- package/dist/desktop/native_dialogs.d.ts +37 -0
- package/dist/desktop/native_dialogs.js +105 -0
- package/dist/diagnostics/session_export.d.ts +1 -0
- package/dist/diagnostics/session_export.js +28 -0
- package/dist/embedded/registry.js +4 -2
- package/dist/emulation/tool_adapters.js +9 -4
- package/dist/emulation/ztc_addendum.js +3 -0
- package/dist/headless.d.ts +11 -4
- package/dist/headless.js +99 -34
- package/dist/headless_approval.d.ts +6 -0
- package/dist/headless_cli.js +1 -1
- package/dist/hooks/runner.js +7 -6
- package/dist/library.d.ts +4 -0
- package/dist/library.js +3 -0
- package/dist/mcp/client.js +3 -3
- package/dist/modes/registry.js +13 -4
- package/dist/onboarding/setup_environment.js +13 -1
- package/dist/optimize/adapters/kernelbench.js +88 -10
- package/dist/optimize/adapters/types.d.ts +5 -0
- package/dist/optimize/executor.js +21 -0
- package/dist/panes/cli_install.d.ts +54 -0
- package/dist/panes/cli_install.js +157 -0
- package/dist/panes/model_catalog.js +3 -0
- package/dist/panes/new_pane_choices.d.ts +6 -2
- package/dist/panes/new_pane_choices.js +24 -12
- package/dist/panes/pane_cli_launch.d.ts +50 -0
- package/dist/panes/pane_cli_launch.js +124 -0
- package/dist/panes/pane_clis.d.ts +171 -0
- package/dist/panes/pane_clis.js +325 -0
- package/dist/panes/person_only_panes.d.ts +45 -0
- package/dist/panes/person_only_panes.js +117 -0
- package/dist/plugin/simulation_living.js +0 -2
- package/dist/plugin/simulation_living_engine.d.ts +1 -0
- package/dist/plugin/simulation_living_engine.js +1 -0
- package/dist/plugin/simulation_living_labels.d.ts +3 -0
- package/dist/plugin/simulation_living_labels.js +2 -0
- package/dist/router_auth.js +12 -1
- package/dist/session.js +26 -1
- package/dist/simulation/art/gemini_image.js +11 -5
- package/dist/simulation/domains/loader.js +25 -3
- package/dist/simulation/living/cold.d.ts +23 -0
- package/dist/simulation/living/cold.js +41 -0
- package/dist/simulation/living/context.d.ts +591 -1283
- package/dist/simulation/living/context.js +378 -244
- package/dist/simulation/living/contradictions.d.ts +14 -0
- package/dist/simulation/living/contradictions.js +282 -0
- package/dist/simulation/living/core/ids.d.ts +53 -0
- package/dist/simulation/living/core/ids.js +39 -0
- package/dist/simulation/living/core/kind.d.ts +20 -0
- package/dist/simulation/living/core/kind.js +15 -0
- package/dist/simulation/living/core/laws.d.ts +179 -0
- package/dist/simulation/living/core/laws.js +184 -0
- package/dist/simulation/living/core/ops.d.ts +257 -0
- package/dist/simulation/living/core/ops.js +34 -0
- package/dist/simulation/living/definer.d.ts +17 -1
- package/dist/simulation/living/definer.js +130 -51
- package/dist/simulation/living/definition.d.ts +174 -65
- package/dist/simulation/living/definition.js +287 -180
- package/dist/simulation/living/director.d.ts +80 -0
- package/dist/simulation/living/director.js +363 -0
- package/dist/simulation/living/frame.d.ts +108 -21
- package/dist/simulation/living/frame.js +111 -66
- package/dist/simulation/living/identifiers.d.ts +0 -1
- package/dist/simulation/living/identifiers.js +0 -3
- package/dist/simulation/living/index.d.ts +18 -9
- package/dist/simulation/living/index.js +18 -9
- package/dist/simulation/living/inference.d.ts +92 -50
- package/dist/simulation/living/inference.js +319 -175
- package/dist/simulation/living/knowledge.d.ts +28 -0
- package/dist/simulation/living/knowledge.js +73 -0
- package/dist/simulation/living/library.json +1177 -0
- package/dist/simulation/living/mechanics.d.ts +31 -34
- package/dist/simulation/living/mechanics.js +222 -138
- package/dist/simulation/living/model-input.d.ts +6 -3
- package/dist/simulation/living/model-input.js +18 -26
- package/dist/simulation/living/open-world.d.ts +74 -94
- package/dist/simulation/living/open-world.js +151 -30
- package/dist/simulation/living/phrases.d.ts +3 -0
- package/dist/simulation/living/phrases.js +37 -0
- package/dist/simulation/living/phrases.json +560 -0
- package/dist/simulation/living/projection.d.ts +316 -2
- package/dist/simulation/living/projection.js +50 -2
- package/dist/simulation/living/prompts/example-spec.json +11 -0
- package/dist/simulation/living/prompts/role-text.json +14 -0
- package/dist/simulation/living/prompts.d.ts +5 -0
- package/dist/simulation/living/prompts.js +275 -0
- package/dist/simulation/living/recall.d.ts +2 -2
- package/dist/simulation/living/reduce.d.ts +51 -14
- package/dist/simulation/living/reduce.js +941 -579
- package/dist/simulation/living/replay.d.ts +5 -4
- package/dist/simulation/living/replay.js +10 -9
- package/dist/simulation/living/runtime.d.ts +135 -25
- package/dist/simulation/living/runtime.js +1641 -583
- package/dist/simulation/living/scale.d.ts +96 -0
- package/dist/simulation/living/scale.js +124 -0
- package/dist/simulation/living/script.d.ts +5 -0
- package/dist/simulation/living/script.js +115 -0
- package/dist/simulation/living/shared-kinds.d.ts +4 -11
- package/dist/simulation/living/shared-kinds.js +11 -81
- package/dist/simulation/living/space.d.ts +14 -0
- package/dist/simulation/living/space.js +132 -0
- package/dist/simulation/living/state.d.ts +100 -0
- package/dist/simulation/living/state.js +393 -0
- package/dist/simulation/living/types.d.ts +829 -512
- package/dist/simulation/living/types.js +162 -187
- package/dist/simulation/living/world-rules.d.ts +100 -0
- package/dist/simulation/living/world-rules.js +267 -0
- package/dist/simulation/plugins/loader.js +11 -0
- package/dist/skills/loader.js +4 -0
- package/dist/tools.d.ts +1 -0
- package/dist/tools.js +1 -0
- package/dist/ui/ratatui/headless_pane_manager.d.ts +4 -1
- package/dist/ui/ratatui/headless_pane_manager.js +13 -9
- package/dist/ui/ratatui/pane_relay.js +29 -0
- package/dist/ui/ratatui/pane_type.d.ts +10 -0
- package/dist/ui/ratatui/pane_type.js +11 -0
- package/dist/ui/ratatui/process.d.ts +30 -0
- package/dist/ui/ratatui/process.js +133 -19
- package/dist/ui/ratatui/protocol.d.ts +124 -2
- package/dist/ui/ratatui/protocol.js +35 -0
- package/dist/ui/ratatui/relay_policy.js +3 -0
- package/dist/ui/ratatui/ztc_launch_trust.d.ts +2 -1
- package/dist/ui/ratatui/ztc_launch_trust.js +8 -1
- package/dist/ui/terminal_image.d.ts +12 -0
- package/dist/ui/terminal_image.js +21 -1
- package/dist/utils/codex_project_trust.d.ts +19 -0
- package/dist/utils/codex_project_trust.js +37 -0
- package/dist/utils/compaction.js +103 -20
- package/dist/utils/git_program_files.d.ts +19 -12
- package/dist/utils/git_program_files.js +411 -83
- package/dist/utils/host_shell.d.ts +10 -1
- package/dist/utils/host_shell.js +14 -1
- package/dist/utils/mid_turn_compaction.d.ts +2 -0
- package/dist/utils/mid_turn_compaction.js +2 -0
- package/dist/utils/models.js +6 -1
- package/dist/utils/sandbox.d.ts +109 -8
- package/dist/utils/sandbox.js +981 -187
- package/dist/utils/shell.d.ts +2 -0
- package/dist/utils/shell.js +10 -4
- package/dist/utils/subprocess_env.d.ts +47 -11
- package/dist/utils/subprocess_env.js +107 -15
- package/dist/utils/system_ps.d.ts +8 -0
- package/dist/utils/system_ps.js +39 -7
- package/dist/utils/unattended_compaction.d.ts +9 -0
- package/dist/utils/unattended_compaction.js +13 -0
- package/dist/utils/ztc_own_state.d.ts +8 -5
- package/dist/utils/ztc_own_state.js +17 -11
- package/dist/web/mirror_client.js +1 -0
- package/dist/web/mirror_stream.d.ts +50 -6
- package/dist/web/mirror_stream.js +160 -15
- package/dist/workflows/registry.js +3 -1
- package/dist/workspace/controller.js +12 -0
- package/dist/workspace_collision.d.ts +3 -0
- package/dist/workspace_collision.js +14 -1
- package/dist/workspace_session_context.js +2 -1
- package/dist/zlm-embed.mjs +3823 -1970
- package/node_modules/@zerg/model-contracts/README.md +16 -4
- package/node_modules/@zerg/model-contracts/index.js +6 -1
- package/npm-shrinkwrap.json +1 -1
- package/package.json +42 -24
- package/packages/model-contracts/README.md +16 -4
- package/packages/model-contracts/index.js +6 -1
package/dist/cli_ratatui.js
CHANGED
|
@@ -2,19 +2,23 @@ import { statusPlacement, statusRestoreState, remapWorkspacePaneIds } from './de
|
|
|
2
2
|
import { routerChromeState } from './desktop/daily/native_status.js';
|
|
3
3
|
import { buildWorkspaceMonitorLaunch, loadWorkspacePreset } from './app/workspace_presets.js';
|
|
4
4
|
import { DesktopDaily, nativeChoices, canResumeNative, safeDailyMessage } from './desktop/daily/desktop_wiring.js';
|
|
5
|
+
import { NativeDialogClient } from './desktop/native_dialogs.js';
|
|
6
|
+
import { DesktopHealthController } from './desktop/health.js';
|
|
5
7
|
import { parseNativeRecords } from './desktop/daily/native_records.js';
|
|
6
8
|
import { environmentOperationInProgress } from './agent/commands/environment.js';
|
|
7
9
|
import { withheldAttachedImages } from './agent/attached_images.js';
|
|
8
10
|
import { pinnedRoute, pinnedRouteCommandRefusal, pinnedRouteMessage, pinnedRoutingRefusal, routingEnvOverride } from './config/model_pin.js';
|
|
9
|
-
import { isPinFolder, permissionPinChildEnv, pinnedRestartFolderMessage, pinnedRestartMessage, pinnedSettingsARestartWouldTake } from './config/permission_pin.js';
|
|
11
|
+
import { isPinFolder, permissionPinChildEnv, personProgramRefusal, PINNED_PANE_INSTEAD, pinnedPaneTypingRefusal, pinnedRestartFolderMessage, pinnedRestartMessage, pinnedSettingsARestartWouldTake } from './config/permission_pin.js';
|
|
10
12
|
import { terminateActiveShellChildren } from './utils/shell.js';
|
|
11
13
|
import { getEnvironment, openEnvironment, releaseEnvironment, describeEnvironmentForAgent, isEnvironmentWorkspacePath } from './environment/store.js';
|
|
12
14
|
import { readPaneLabels, sessionNamePaneTitle } from './panes/labels.js';
|
|
15
|
+
import { personOnlyPanesRelaunchEnv } from './panes/person_only_panes.js';
|
|
13
16
|
import { reconcileOrderedTranscript } from './app/ordered_transcript.js';
|
|
14
17
|
import { layoutChangeEffects } from './app/layout_change.js';
|
|
15
18
|
import { workspacePaneTopology } from './app/workspace_topology.js';
|
|
16
|
-
import { listCommandJobs, shutdownCommandJobs, subscribeCommandJobs } from './agent/runtime/command_jobs.js';
|
|
19
|
+
import { listCommandJobs, shutdownCommandJobs, startedHere, subscribeCommandJobs } from './agent/runtime/command_jobs.js';
|
|
17
20
|
import { CommandPaneManager, commandPaneText } from './agent/runtime/command_panes.js';
|
|
21
|
+
import { personCommandPolicy } from './config/person_command_policy.js';
|
|
18
22
|
import { getMuxTransport, isPaneRefusalFor, waitForPaneCreatedOrError } from './agent/tools/pane.js';
|
|
19
23
|
import { AGENT_CLIS, findAgentCli } from './panes/agent_cli.js';
|
|
20
24
|
import { openResumedAgentPane, openedSessionLine, resumeLaunchPlan, resumeSavedAgentPane, elsewhereCommandLine } from './panes/agent_resume.js';
|
|
@@ -26,7 +30,9 @@ import { AgentSessionsPanelWidget } from './ui/widgets/agent_sessions_panel.js';
|
|
|
26
30
|
import { agentCliFromRequestId, agentPaneAnswerText, agentPaneNoteForModel, formatAgentPaneMessage, formatTypedPaneMessage, openAgentPane, typeLineIntoPane, typingSettled } from './panes/agent_panes.js';
|
|
27
31
|
import { ReplyExchanges, arbitrationNotice, arbitrationStopForPane, arbitrationSummary, arrivalNote, capLoweredNotice, capLoweredStopForPane, capNoteForPane, capStopNotice, heldNotice, heldNoticeForPane, knownSecrets, replyModeRefusal, replyModeSettings, resumedNotice, staleArbitrationNotice, withheldNotice } from './panes/reply_modes.js';
|
|
28
32
|
import { askArbitrator } from './panes/reply_arbitrator.js';
|
|
29
|
-
import { agentCliFromChoice, newPaneChoices } from './panes/new_pane_choices.js';
|
|
33
|
+
import { agentCliFromChoice, newPaneChoices, paneCliFromChoice } from './panes/new_pane_choices.js';
|
|
34
|
+
import { TERMINAL_CLI_IDS, findPaneCli } from './panes/pane_clis.js';
|
|
35
|
+
import { openPaneCli } from './panes/pane_cli_launch.js';
|
|
30
36
|
import { MOTSI_PANE_ENV, remoteViewMotsi, runsMotsi, throughMotsi } from './panes/motsi.js';
|
|
31
37
|
import { editorProgram } from './panes/editor_program.js';
|
|
32
38
|
import { IntakeNotifications } from './intake/notifications.js';
|
|
@@ -45,7 +51,7 @@ import { formatTaskHandoffNotice, projectTaskHandoff } from './session_handoff_c
|
|
|
45
51
|
import { resolve } from 'path';
|
|
46
52
|
import { beginSimTurn } from './agent/tools/sim_turn_budget.js';
|
|
47
53
|
import { randomUUID } from 'crypto';
|
|
48
|
-
import { appendFileSync, existsSync, promises as fsPromises, writeFileSync } from 'fs';
|
|
54
|
+
import { appendFileSync, existsSync, promises as fsPromises, realpathSync, statSync, writeFileSync } from 'fs';
|
|
49
55
|
import { tmpdir, homedir } from 'os';
|
|
50
56
|
import { dirname, join } from 'path';
|
|
51
57
|
import { execFile, spawnSync } from 'child_process';
|
|
@@ -57,7 +63,7 @@ import { canonicalAccountProvider } from './agent/backends/account_pool.js';
|
|
|
57
63
|
import { normalizeProviderId } from './agent/backends/provider_ids.js';
|
|
58
64
|
import { collectUsageViews, buildUsageViews, nativeUsageView } from './usage_projection.js';
|
|
59
65
|
import { createUsageSnapshot, recordUsageReceipt } from './usage_snapshot.js';
|
|
60
|
-
import { withActiveProfileArg } from './config/profiles.js';
|
|
66
|
+
import { nestedRunEnv, withActiveProfileArg } from './config/profiles.js';
|
|
61
67
|
import { DEFAULT_ROUTER_ORIGIN, RouterConfigurationError, readRouterCredentialsSync, routerSignInRefusal } from './router_auth.js';
|
|
62
68
|
import { CODEX_REASONING_EFFORTS } from './config/types.js';
|
|
63
69
|
import { getSupportedCodexReasoningEfforts, unsupportedEffortMessage, } from './utils/models.js';
|
|
@@ -112,7 +118,7 @@ import { RuntimeChoicesSource } from './app/runtime_choices_source.js';
|
|
|
112
118
|
import { PaneModelMemory } from './config/provider_models.js';
|
|
113
119
|
import { zmuxKeymapPayload, zmuxShortcutHint } from './config/keybindings.js';
|
|
114
120
|
import { customPaneOptions } from './config/panes.js';
|
|
115
|
-
import { CAPABILITY_DESKTOP_CLOSE_WINDOW, CAPABILITY_DESKTOP_UPDATE_RESTART, CAPABILITY_DESKTOP_TASK_CONTROLS, CAPABILITY_DESKTOP_ROUTER_CHROME, CAPABILITY_DESKTOP_RUNTIME_CONTROLS, CAPABILITY_DESKTOP_RUNTIME_CHOICES, CAPABILITY_DESKTOP_SESSION_SHARE, CAPABILITY_KITTY_GRAPHICS, isDesktopSessionShareAction, CAPABILITY_SCROLLBACK_ANCHOR, CAPABILITY_TERMINAL_INTERACTION, CAPABILITY_TRANSCRIPT_CLICK, } from './ui/ratatui/protocol.js';
|
|
121
|
+
import { CAPABILITY_DESKTOP_CLOSE_WINDOW, CAPABILITY_DESKTOP_NATIVE_DIALOGS, CAPABILITY_DESKTOP_UPDATE_RESTART, CAPABILITY_DESKTOP_TASK_CONTROLS, CAPABILITY_DESKTOP_ROUTER_CHROME, CAPABILITY_DESKTOP_RUNTIME_CONTROLS, CAPABILITY_DESKTOP_RUNTIME_CHOICES, CAPABILITY_DESKTOP_SESSION_SHARE, CAPABILITY_KITTY_GRAPHICS, isDesktopSessionShareAction, CAPABILITY_SCROLLBACK_ANCHOR, CAPABILITY_TERMINAL_INTERACTION, CAPABILITY_TRANSCRIPT_CLICK, } from './ui/ratatui/protocol.js';
|
|
116
122
|
import { writeClipboard } from './utils/clipboard.js';
|
|
117
123
|
import { saveClipboardImagePng } from './utils/clipboard_image.js';
|
|
118
124
|
import { loadEmulationProfiles, getEmulationProfile } from './emulation/catalog.js';
|
|
@@ -120,7 +126,7 @@ import { buildToolGroupOutput } from './utils/tool_trace.js';
|
|
|
120
126
|
import { modelHandoffSummarizer } from './utils/compaction.js';
|
|
121
127
|
import { resolvePromptPrefixId } from './utils/compaction.js';
|
|
122
128
|
import { IDLE_COMPACT_DEFAULT_LEAD_MS, IDLE_COMPACT_MIN_CONTEXT_TOKENS, IdleCompactionScheduler, resolveCacheLifetimeMs, } from './utils/idle_compaction.js';
|
|
123
|
-
import { KittyImageUploads,
|
|
129
|
+
import { KittyImageUploads, resolveTerminalImageMode, setTerminalImageMode, transcriptImagesForToolOutput } from './ui/terminal_image.js';
|
|
124
130
|
import { MIN_TRANSCRIPT_LINE_BUDGET, RENDERER_TRANSCRIPT_ROWS, TRANSCRIPT_LINE_BUDGET, boundTranscript, sizeName } from './ui/transcript_bound.js';
|
|
125
131
|
import { insertText, insertBadge, expandPasteBadge, backspace, deleteForward, moveLeft, moveRight, moveWordLeft, moveWordRight, moveToStart, moveToEnd, moveToLineStart, moveToLineEnd, killToLineStart, killToLineEnd, moveVertical, wordBeforeCaret, wordAfterCaret, deleteWordBackward, deleteWordForward, getPlainText, serializeSegments, serializeMessageInput, textCursorIndex, killInputDraft, yankInputKill, historyUp, historyDown, PASTE_BADGE_THRESHOLD, pasteBecomesBadge, } from './ui/core/input_segments.js';
|
|
126
132
|
import { findAtMention, completeAtMention, applyAtMention } from './utils/at_mention.js';
|
|
@@ -149,7 +155,9 @@ import { PaneRelayServer, PaneRelayClient, generateRelaySocketPath, startStaleRe
|
|
|
149
155
|
import { paneReadRefusal, setPaneReadRefusal } from './ui/ratatui/screen_privacy.js';
|
|
150
156
|
import { perfBeginKeystroke, perfStage, perfEndKeystroke } from './debug/perf_trace.js';
|
|
151
157
|
import { resolveMuxPersistenceOptions, sanitizeMuxSessionState, validateWorkspaceState } from './ui/ratatui/mux_persistence.js';
|
|
152
|
-
import { buildModelsController, buildSkillsController, buildShellController, routeUserInput, getPlanModeCommandDenial } from './app/command_context.js';
|
|
158
|
+
import { buildModelsController, buildSkillsController, buildShellController, buildStubShellController, routeUserInput, getPlanModeCommandDenial } from './app/command_context.js';
|
|
159
|
+
import { stubsMirrorShell } from './app/headless_shell_mode.js';
|
|
160
|
+
import { HOSTED_RESIDENT_NO_MODEL_ROUTE, hostedResidentAgentCommandRefusal, hostedResidentAgentPaneTransport, hostedResidentAgentZtcPaneDecision, hostedResidentRelayTransport, hostedResidentCommandContext, hostedResidentCommandRefusal, hostedResidentExtensionRoots, hostedResidentMuxDecision, hostedResidentPaneArgs, hostedResidentPaneEnv, hostedResidentPaneInputRefusal } from './app/hosted_resident.js';
|
|
153
161
|
import { advanceEscapeStop, isEscapeStopArmed, ESCAPE_STOP_WINDOW_MS } from './app/escape_stop.js';
|
|
154
162
|
import { createAgentWithConfig, AgentRunLifecycle } from './app/agent_runner.js';
|
|
155
163
|
import { classifyBusyInput } from './app/task_scope_router.js';
|
|
@@ -503,9 +511,38 @@ export function shouldProcessPostCommandBackgroundEvents(batch, workflows) {
|
|
|
503
511
|
function sameRoute(a, b) {
|
|
504
512
|
return normalizeProviderId(a.provider) === normalizeProviderId(b.provider) && a.model === b.model && a.authMode === b.authMode;
|
|
505
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* A directory's real path as the kernel resolves the path given, or null when it is no directory (a hosted resident's
|
|
516
|
+
* pane cwd check). realpathSync.native, not realpathSync: the JS one folds 'link/..' away as text first, and the kernel
|
|
517
|
+
* reads it as the parent of link's target.
|
|
518
|
+
*/
|
|
519
|
+
function realDirectory(path) {
|
|
520
|
+
try {
|
|
521
|
+
const real = realpathSync.native(path);
|
|
522
|
+
return statSync(real).isDirectory() ? real : null;
|
|
523
|
+
}
|
|
524
|
+
catch {
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
506
528
|
export class RatatuiApp {
|
|
507
529
|
tui;
|
|
508
530
|
headlessMirror = false;
|
|
531
|
+
/**
|
|
532
|
+
* A hosted resident (app/hosted_resident.ts): a headless mirror whose host stubbed its shell, as ZergCloud launches a
|
|
533
|
+
* ZeP service zerg. Read once at construction; what its mirror controllers send is held to its allowlists.
|
|
534
|
+
*/
|
|
535
|
+
hostedResident;
|
|
536
|
+
/** A hosted resident's workspace: the working directory it was launched in. */
|
|
537
|
+
residentWorkspace;
|
|
538
|
+
/** The extension roots a hosted resident's ZTC panes load from, resolved as it starts (hostedResidentExtensionRoots). */
|
|
539
|
+
residentExtensionRoots;
|
|
540
|
+
/**
|
|
541
|
+
* The ZTC panes a hosted resident opened itself (a controller's create_ztc_pane, spawnZtcPane's callers), by pane id,
|
|
542
|
+
* and the request ids of those it is opening: only such a pane takes a controller's typing, never one its agent opened.
|
|
543
|
+
*/
|
|
544
|
+
residentOpenedPanes = new Set();
|
|
545
|
+
residentPaneRequests = new Set();
|
|
509
546
|
interactiveHeadless;
|
|
510
547
|
startupZergEndpoint;
|
|
511
548
|
/** Colony children run real zmux --headless for PTY-backed sub-panes. */
|
|
@@ -994,6 +1031,8 @@ export class RatatuiApp {
|
|
|
994
1031
|
transcriptWidthSettlesAt = 0;
|
|
995
1032
|
desktopMode = false;
|
|
996
1033
|
desktopRuntime;
|
|
1034
|
+
reattachSocket;
|
|
1035
|
+
reattachTokenFile;
|
|
997
1036
|
childPaneIds = new Set();
|
|
998
1037
|
/** Panes running the user's own Claude Code or Codex, by pane id. */
|
|
999
1038
|
agentCliPanes = new Map();
|
|
@@ -1089,6 +1128,8 @@ export class RatatuiApp {
|
|
|
1089
1128
|
retainedStartupTopology = null;
|
|
1090
1129
|
dailyStatusCancel = null;
|
|
1091
1130
|
dailyDialogs = Promise.resolve();
|
|
1131
|
+
nativeDialogs = new NativeDialogClient((command) => this.tui.send(command));
|
|
1132
|
+
desktopHealth = new DesktopHealthController();
|
|
1092
1133
|
// Per-turn snapshots feed the post-turn recap trigger. They live on `this`
|
|
1093
1134
|
// because the idle-transition hook runs outside runAgent's scope. Tool calls
|
|
1094
1135
|
// are counted here (not read from Message.toolCalls) because streaming only
|
|
@@ -1482,12 +1523,15 @@ export class RatatuiApp {
|
|
|
1482
1523
|
return new Promise((resolve) => {
|
|
1483
1524
|
const id = generateId();
|
|
1484
1525
|
this.pendingHookApprovals.set(id, { request, resolver: resolve });
|
|
1526
|
+
// A resident's approver is its mirror's controller: it is told whether the call starts a program outside the OS
|
|
1527
|
+
// sandbox (a language server, run_and_capture's command), as a headless run's --approval-url approver is.
|
|
1485
1528
|
this.mirror?.publishHookApprovalRequest({
|
|
1486
1529
|
id,
|
|
1487
1530
|
toolName: request.toolName,
|
|
1488
1531
|
reason: request.reason,
|
|
1489
1532
|
capabilities: request.capabilities,
|
|
1490
1533
|
args: request.args,
|
|
1534
|
+
...(request.startsProgramsOutsideSandbox === true ? { startsProgramsOutsideSandbox: true } : {}),
|
|
1491
1535
|
...(request.kind ? { kind: request.kind } : {}),
|
|
1492
1536
|
...(request.firstRun ? { firstRun: request.firstRun } : {}),
|
|
1493
1537
|
});
|
|
@@ -1514,6 +1558,11 @@ export class RatatuiApp {
|
|
|
1514
1558
|
this.resolveStartupReady = resolve;
|
|
1515
1559
|
});
|
|
1516
1560
|
this.headlessMirror = options?.headlessMirror ?? false;
|
|
1561
|
+
this.hostedResident = stubsMirrorShell({ headlessMirror: this.headlessMirror });
|
|
1562
|
+
this.residentWorkspace = process.cwd();
|
|
1563
|
+
this.residentExtensionRoots = this.hostedResident
|
|
1564
|
+
? hostedResidentExtensionRoots(process.env, realDirectory(this.residentWorkspace) ?? this.residentWorkspace, realDirectory)
|
|
1565
|
+
: {};
|
|
1517
1566
|
this.interactiveHeadless = options?.interactiveHeadless ?? false;
|
|
1518
1567
|
this.startupZergEndpoint = options?.startupZergEndpoint;
|
|
1519
1568
|
this.maxIterations = options?.maxIterations;
|
|
@@ -1535,6 +1584,8 @@ export class RatatuiApp {
|
|
|
1535
1584
|
this.muxMode = options?.mux ?? false;
|
|
1536
1585
|
this.desktopMode = options?.desktop ?? false;
|
|
1537
1586
|
this.desktopRuntime = options?.desktopRuntime;
|
|
1587
|
+
this.reattachSocket = options?.reattachSocket;
|
|
1588
|
+
this.reattachTokenFile = options?.reattachTokenFile;
|
|
1538
1589
|
this.paneMode = options?.pane ?? false;
|
|
1539
1590
|
// A pane another ZTC launched runs its launch route flags for itself alone (ConfigStore.markLaunchedByParent).
|
|
1540
1591
|
configStore.markLaunchedByParent(this.paneMode);
|
|
@@ -1763,6 +1814,7 @@ export class RatatuiApp {
|
|
|
1763
1814
|
}));
|
|
1764
1815
|
const hostedRuntime = this.isHostedRuntime();
|
|
1765
1816
|
this.mirrorServer.setHostedMode(hostedRuntime);
|
|
1817
|
+
this.mirrorServer.setHostedResident(this.hostedResident);
|
|
1766
1818
|
if (hostedRuntime) {
|
|
1767
1819
|
registerHostedAgentToolBridge(this.mirrorServer, () => this.agent);
|
|
1768
1820
|
}
|
|
@@ -1923,9 +1975,10 @@ export class RatatuiApp {
|
|
|
1923
1975
|
},
|
|
1924
1976
|
planApprovalGuard: () => this.planApprovedRecently,
|
|
1925
1977
|
});
|
|
1926
|
-
// Set up pane tools TUI process reference (for zmux mode)
|
|
1978
|
+
// Set up pane tools TUI process reference (for zmux mode). A hosted resident's agent opens its ZTC panes as the
|
|
1979
|
+
// resident opens a controller's (agentZtcPane), whichever tool asks.
|
|
1927
1980
|
if (this.muxMode) {
|
|
1928
|
-
setPaneToolsTuiProcess(this.tui);
|
|
1981
|
+
setPaneToolsTuiProcess(this.hostedResident ? hostedResidentAgentPaneTransport(this.tui, command => this.agentZtcPane(command)) : this.tui);
|
|
1929
1982
|
// The primary ZTC (mux owner) is always pane 0 in zmux — see App::new in
|
|
1930
1983
|
// ztc/packages/zmux/src/app.rs:241 where `ztc_id = next_pane_id()` is the
|
|
1931
1984
|
// first call to `next_pane_id()` which returns 0. Without this call,
|
|
@@ -3654,7 +3707,7 @@ export class RatatuiApp {
|
|
|
3654
3707
|
// own live SSE clients; an auto-started mirror with no browser is 0.
|
|
3655
3708
|
hasViewers: () => this.mirrorServer ? this.mirrorServer.getViewerCount() > 0 : !!this.mirrorClient,
|
|
3656
3709
|
getPort: () => this.mirrorServer?.getPort() ?? 0,
|
|
3657
|
-
getUrl: (params) => this.
|
|
3710
|
+
getUrl: (params) => this.mirrorLaunchUrl(params),
|
|
3658
3711
|
accessNotice: () => this.mirrorServer?.remoteAccessNotice(),
|
|
3659
3712
|
start: async (port) => {
|
|
3660
3713
|
await this.startMirrorFromCommand(port);
|
|
@@ -3664,7 +3717,7 @@ export class RatatuiApp {
|
|
|
3664
3717
|
},
|
|
3665
3718
|
open: async (params) => {
|
|
3666
3719
|
if (this.mirrorServer) {
|
|
3667
|
-
await openUrlInBrowser(this.
|
|
3720
|
+
await openUrlInBrowser(this.mirrorLaunchUrl(params));
|
|
3668
3721
|
}
|
|
3669
3722
|
},
|
|
3670
3723
|
publish: (event) => {
|
|
@@ -3842,7 +3895,9 @@ export class RatatuiApp {
|
|
|
3842
3895
|
this.legacyCommandPrompt = owner;
|
|
3843
3896
|
this.legacyCommandPromptWidgetId = this.lastPromptWidgetId === previousWidgetId ? null : this.lastPromptWidgetId;
|
|
3844
3897
|
};
|
|
3845
|
-
|
|
3898
|
+
// A hosted resident's commands (ZTC_HEADLESS_SHELL_MODE=stub, app/hosted_resident.ts) pin no command pane, open no
|
|
3899
|
+
// environment and run the stub shell for /shell, ! and /cd, whoever sends them.
|
|
3900
|
+
return this.hostedResident ? hostedResidentCommandContext(context, buildStubShellController()) : context;
|
|
3846
3901
|
}
|
|
3847
3902
|
/**
|
|
3848
3903
|
* Panels that replace the transcript while open.
|
|
@@ -3907,6 +3962,12 @@ export class RatatuiApp {
|
|
|
3907
3962
|
* Used by the ztc_command tool to let the agent run ZTC commands.
|
|
3908
3963
|
*/
|
|
3909
3964
|
async executeCommandForTool(cmd, cmdArgs, origin = 'agent') {
|
|
3965
|
+
// A hosted resident's agent runs none of the platform's zerg commands, which reach the ZergAI platform API with ZTC's
|
|
3966
|
+
// platform login, nor /debug headlines, which launches a local zerg service (app/hosted_resident.ts): refused before
|
|
3967
|
+
// anything of the command runs.
|
|
3968
|
+
const residentRefusal = this.hostedResident ? hostedResidentAgentCommandRefusal(cmd, cmdArgs) : null;
|
|
3969
|
+
if (residentRefusal !== null)
|
|
3970
|
+
return residentRefusal;
|
|
3910
3971
|
// Capture messages added during command execution
|
|
3911
3972
|
const capturedMessages = [];
|
|
3912
3973
|
await this.ensureOptionalControllersForCommand(cmd);
|
|
@@ -3960,6 +4021,10 @@ export class RatatuiApp {
|
|
|
3960
4021
|
this.mirrorServer.setPaneControlCredentialRequired(mirrorPaneControlNeedsCredential({
|
|
3961
4022
|
desktopMode: this.desktopMode, muxMode: this.muxMode, autoStarted: false
|
|
3962
4023
|
}));
|
|
4024
|
+
// No hosted resident reaches here: one is always a --headless --mirror launch, whose server the constructor made
|
|
4025
|
+
// (and marked), so this returns above; /mirror is neither its controllers' nor its agent's to run. Marked all the
|
|
4026
|
+
// same, so a mirror started here would hold a hosted resident's controllers to its routes as well.
|
|
4027
|
+
this.mirrorServer.setHostedResident(this.hostedResident);
|
|
3963
4028
|
this.mirrorServer.setRuntimeStatsProvider(() => this.getRuntimeStats());
|
|
3964
4029
|
this.mirrorServer.setPromptTurnsProvider(() => projectCorrelatedTurns(this.committedTurnMessages, this.sessionId, this.committedPromptTurns));
|
|
3965
4030
|
this.mirrorServer.onCorrelatedInput(async (input) => (await this.handleMirrorInput(input)) ?? { ok: false, reason: 'input_unavailable' }, () => goalManager.get()?.status !== 'active');
|
|
@@ -4019,8 +4084,24 @@ export class RatatuiApp {
|
|
|
4019
4084
|
// Fallback: deliver browser input to child panes via stdin when bus SSE is unavailable.
|
|
4020
4085
|
// Input that carries attachments is encoded as a structured submit envelope so the child
|
|
4021
4086
|
// pane can reconstruct them; plain text falls back to a flattened `[image ...]` form.
|
|
4022
|
-
server.onPaneInput((paneId, input) => {
|
|
4087
|
+
server.onPaneInput((paneId, input, agent) => {
|
|
4088
|
+
// A hosted resident's mirror types only into its ZTC panes, and a controller's input (/pane-input, the bus fallback,
|
|
4089
|
+
// /broadcast) only into the ones it opened itself, never one its agent opened. An agent's message (AGENT, its sender:
|
|
4090
|
+
// Main's agent's and its answers, or a ZTC pane's own credential's, which the mirror types in as one line that says
|
|
4091
|
+
// who sent it) goes into any of its ZTC panes, the ones its agent opened among them, which get their work so.
|
|
4092
|
+
const refused = this.hostedResident ? hostedResidentPaneInputRefusal(paneId, server.getPaneInfo(paneId)?.paneType,
|
|
4093
|
+
// Whether the pane counts as one the resident opened itself: every ZTC pane does for an agent's message.
|
|
4094
|
+
agent !== undefined || this.residentOpenedPanes.has(paneId)) : null;
|
|
4095
|
+
if (refused !== null)
|
|
4096
|
+
return refused;
|
|
4023
4097
|
debugLog(`[Mirror] Pane input fallback via stdin: pane=${paneId} length=${input.text.length}`);
|
|
4098
|
+
// Under the pin, what a pane that runs no ZTC would run outside the OS sandbox isn't typed: said in pane 0's
|
|
4099
|
+
// transcript, and returned, so /pane-input answers it as refused and a bus message's sender is told so.
|
|
4100
|
+
const typing = this.pinnedTypingRefusal(paneId);
|
|
4101
|
+
if (typing) {
|
|
4102
|
+
this.publishPaneSystemMessage(0, typing);
|
|
4103
|
+
return typing;
|
|
4104
|
+
}
|
|
4024
4105
|
if (input.attachments.length > 0) {
|
|
4025
4106
|
// Attachments can't ride the plain-text prompt envelope, so encode them
|
|
4026
4107
|
// as a submit_input control command — delivered BARE (control:true) so
|
|
@@ -4039,7 +4120,8 @@ export class RatatuiApp {
|
|
|
4039
4120
|
this.tui.send({ type: 'write_pane', pane_id: paneId, input: controlLine, control: true });
|
|
4040
4121
|
});
|
|
4041
4122
|
// An agent's message for a Claude Code or Codex pane is typed in, one
|
|
4042
|
-
// line saying who sent it, with Enter as its own keystroke.
|
|
4123
|
+
// line saying who sent it, with Enter as its own keystroke. A hosted
|
|
4124
|
+
// resident's mirror hands over only its own agent's (deliverBusMessage).
|
|
4043
4125
|
server.onAgentPaneMessage((paneId, msg) => {
|
|
4044
4126
|
if (!this.agentCliPanes.has(paneId))
|
|
4045
4127
|
return false;
|
|
@@ -4316,6 +4398,29 @@ export class RatatuiApp {
|
|
|
4316
4398
|
if (this.agentPaneAsksWaiting.length === 0 && !this.busMessageInConversation)
|
|
4317
4399
|
this.pendingBusTrigger = false;
|
|
4318
4400
|
}
|
|
4401
|
+
/**
|
|
4402
|
+
* Pane PANE_ID, which a renderer reported created for REQUEST_ID, runs the person's own Claude Code or Codex when that
|
|
4403
|
+
* request is one openAgentPane sent (agentCliFromRequestId). zmux's report and the headless pane manager's both say so:
|
|
4404
|
+
* an agent's message is typed into such a pane with its sender, and under the pin a controller still types into it
|
|
4405
|
+
* (pinnedPaneTypingRefusal), as it asks before each of its commands there. The resident's pane manager said so of none,
|
|
4406
|
+
* so the pin refused typing into the Claude Code pane /claude had just opened (PIN-HEADLESS-AGENT-PANE-TYPING).
|
|
4407
|
+
*/
|
|
4408
|
+
noteAgentCliPane(paneId, requestId) {
|
|
4409
|
+
const agentCli = agentCliFromRequestId(requestId);
|
|
4410
|
+
if (agentCli)
|
|
4411
|
+
this.agentCliPanes.set(paneId, agentCli);
|
|
4412
|
+
}
|
|
4413
|
+
/**
|
|
4414
|
+
* Pane PANE_ID closed, in zmux or the headless pane manager: it runs no Claude Code or Codex any more, its exchange with
|
|
4415
|
+
* Main ends, and what Main held of it, or kept for a turn of its own, goes with it: no turn runs for a pane that is gone.
|
|
4416
|
+
* A pane that takes its number starts its own exchange.
|
|
4417
|
+
*/
|
|
4418
|
+
agentCliPaneClosed(paneId) {
|
|
4419
|
+
this.agentCliPanes.delete(paneId);
|
|
4420
|
+
this.replyExchanges.closed(paneId);
|
|
4421
|
+
this.agentPaneMessagesHeld.delete(paneId);
|
|
4422
|
+
this.dropWaitingAgentPaneMessages(paneId);
|
|
4423
|
+
}
|
|
4319
4424
|
/**
|
|
4320
4425
|
* Pane PANE_ID closed: its messages still waiting for a turn of their own (agentPaneAsksWaiting) go, and nothing waits
|
|
4321
4426
|
* to start a turn for them alone.
|
|
@@ -5313,8 +5418,13 @@ export class RatatuiApp {
|
|
|
5313
5418
|
this.observeRestoredPaneState(event);
|
|
5314
5419
|
if (event.type === 'pane_created') {
|
|
5315
5420
|
this.childPaneIds.add(event.pane_id);
|
|
5421
|
+
// A pane a hosted resident opened itself (residentPaneRequests): only such a pane takes a controller's typing.
|
|
5422
|
+
if (event.request_id !== undefined && this.residentPaneRequests.delete(event.request_id))
|
|
5423
|
+
this.residentOpenedPanes.add(event.pane_id);
|
|
5316
5424
|
// Track which child requested this pane (for replace flow / origin paneRegistry).
|
|
5317
5425
|
this.notePaneCreated(event.pane_id, event.request_id);
|
|
5426
|
+
// A Claude Code or Codex pane /claude or /codex opened is one here as in zmux (handleTuiEvent).
|
|
5427
|
+
this.noteAgentCliPane(event.pane_id, event.request_id);
|
|
5318
5428
|
const restoredSpec = this.paneRegistry.get(event.pane_id)?.launchSpec
|
|
5319
5429
|
|| this.paneRegistry.consumePendingCreate(event.request_id)
|
|
5320
5430
|
|| this.resumedPaneSpecs.find((pane) => pane.paneId === event.pane_id)?.launchSpec;
|
|
@@ -5360,7 +5470,9 @@ export class RatatuiApp {
|
|
|
5360
5470
|
if (!this.shouldIgnorePaneClosed(event.pane_id)) {
|
|
5361
5471
|
this.observeDailyStatusClosed(event.pane_id);
|
|
5362
5472
|
this.childPaneIds.delete(event.pane_id);
|
|
5473
|
+
this.residentOpenedPanes.delete(event.pane_id);
|
|
5363
5474
|
this.colonyPaneIds.delete(event.pane_id);
|
|
5475
|
+
this.agentCliPaneClosed(event.pane_id);
|
|
5364
5476
|
if (this.mirrorServer) {
|
|
5365
5477
|
this.mirrorServer.unregisterPane(event.pane_id);
|
|
5366
5478
|
}
|
|
@@ -5517,9 +5629,17 @@ export class RatatuiApp {
|
|
|
5517
5629
|
desktop: this.desktopMode,
|
|
5518
5630
|
desktopRuntime: this.desktopRuntime,
|
|
5519
5631
|
desktopUpdateRelaunch,
|
|
5632
|
+
reattachSocket: this.reattachSocket,
|
|
5633
|
+
reattachTokenFile: this.reattachTokenFile,
|
|
5520
5634
|
env: this.zmuxKeymapEnv(),
|
|
5521
5635
|
});
|
|
5522
5636
|
this.assertStartupActive();
|
|
5637
|
+
if (this.tui instanceof TuiProcess && this.tui.isReattached) {
|
|
5638
|
+
// ZTerm already holds every live pane & window; adopt them from the
|
|
5639
|
+
// live pane_state instead of restoring stale startup layout descriptors.
|
|
5640
|
+
this.retainedStartupLayout = null;
|
|
5641
|
+
this.resumedPaneSpecs = [];
|
|
5642
|
+
}
|
|
5523
5643
|
debugLog(`[start] tui.start() returned: ${size.cols}x${size.rows}`);
|
|
5524
5644
|
// ZTerm hears from this event loop every 2 s, and takes an owner that goes 10 s without a ping for one that hangs.
|
|
5525
5645
|
if (this.tui instanceof TuiProcess)
|
|
@@ -5554,7 +5674,9 @@ export class RatatuiApp {
|
|
|
5554
5674
|
// Children's pane lists say which panes run Claude Code or Codex, which only this ZTC knows.
|
|
5555
5675
|
// A ZTC pane a child asks for through MotSi runs inside the motsi this ZTC starts its own panes through, never the
|
|
5556
5676
|
// child's (ztc_launch_trust.ts).
|
|
5557
|
-
|
|
5677
|
+
// A hosted resident's ZTC panes open and relaunch no pane through its relay (hostedResidentRelayTransport): a
|
|
5678
|
+
// relayed create_pane or replace_pane would skip the transport its agent's panes are held to (ztc (2)'s F4).
|
|
5679
|
+
this.paneRelay = new PaneRelayServer(this.hostedResident ? hostedResidentRelayTransport(this.tui) : this.tui, process.env.ZTC_PANE_RELAY, { agentCliOf: paneId => this.agentCliPanes.get(paneId),
|
|
5558
5680
|
ztcPanesThroughMotsi: () => this.paneMotsi() });
|
|
5559
5681
|
// A child's report of its own pane tells this process the route it runs on (see noteChildPaneReport), and a ZTC
|
|
5560
5682
|
// pane it opens, the route that pane starts on (see noteChildPaneLaunch).
|
|
@@ -5701,7 +5823,7 @@ export class RatatuiApp {
|
|
|
5701
5823
|
this.mirrorServer.clearChildPanes();
|
|
5702
5824
|
}
|
|
5703
5825
|
const restoredMuxSession = await this.restoreMuxSessionIfNeeded();
|
|
5704
|
-
if (this.muxMode && !this.isHostedRuntime()) {
|
|
5826
|
+
if (this.muxMode && !this.isHostedRuntime() && !this.hostedResident) {
|
|
5705
5827
|
try {
|
|
5706
5828
|
await this.ensureCommandPanes();
|
|
5707
5829
|
}
|
|
@@ -5927,7 +6049,7 @@ export class RatatuiApp {
|
|
|
5927
6049
|
// not as a user-visible feature. Users who want the browser mirror must
|
|
5928
6050
|
// still pass --mirror.
|
|
5929
6051
|
if (this.mirrorServer && !this.mirrorAutoStarted && !this.muxOnlyMirror) {
|
|
5930
|
-
const mirrorUrl = this.
|
|
6052
|
+
const mirrorUrl = this.mirrorLaunchUrl();
|
|
5931
6053
|
// Said once, as it starts: who can open it (an open mirror: this computer alone).
|
|
5932
6054
|
const accessNotice = this.mirrorServer.remoteAccessNotice();
|
|
5933
6055
|
this.controller.addMessage({
|
|
@@ -6468,9 +6590,62 @@ export class RatatuiApp {
|
|
|
6468
6590
|
modelOverride: resolved.model,
|
|
6469
6591
|
...(options?.authMode ? { authMode: options.authMode } : {}),
|
|
6470
6592
|
...(options?.routerOrigin ? { routerOrigin: options.routerOrigin } : {}),
|
|
6471
|
-
extraArgs: [],
|
|
6593
|
+
extraArgs: options?.extraArgs ?? [],
|
|
6472
6594
|
});
|
|
6473
6595
|
}
|
|
6596
|
+
/** What a hosted resident's decisions read of its launch: its workspace's real path, and its provider and model. */
|
|
6597
|
+
residentLaunch() {
|
|
6598
|
+
return {
|
|
6599
|
+
workspace: realDirectory(this.residentWorkspace) ?? this.residentWorkspace,
|
|
6600
|
+
provider: configStore.getProvider(),
|
|
6601
|
+
model: configStore.getModel(),
|
|
6602
|
+
};
|
|
6603
|
+
}
|
|
6604
|
+
/**
|
|
6605
|
+
* What a hosted resident's decisions read of its panes, as its mirror registered them (HeadlessPaneManager registers a
|
|
6606
|
+
* pane while create_pane is still being sent, so a burst of creates counts each one).
|
|
6607
|
+
*/
|
|
6608
|
+
residentPanes() {
|
|
6609
|
+
return {
|
|
6610
|
+
paneType: paneId => this.mirrorServer?.getPaneInfo(paneId)?.paneType,
|
|
6611
|
+
realDirectory,
|
|
6612
|
+
ztcPaneCount: () => this.mirrorServer?.countChildPanes('ztc') ?? 0,
|
|
6613
|
+
openedByResident: paneId => this.residentOpenedPanes.has(paneId),
|
|
6614
|
+
};
|
|
6615
|
+
}
|
|
6616
|
+
/**
|
|
6617
|
+
* A ZTC pane a hosted resident's agent opens with its own tools (create_ztc_pane, create_terminal_pane's ZTC launch,
|
|
6618
|
+
* a supervision or simulation pane; hostedResidentAgentPaneTransport hands each here): held to the decision a
|
|
6619
|
+
* controller's create_ztc_pane gets (hostedResidentAgentZtcPaneDecision) and launched as handleMirrorMuxCommand
|
|
6620
|
+
* launches a controller's, on the resident's own flags and pane environment (childZtcPaneEnv), in the real directory
|
|
6621
|
+
* the check approved, under its own new session; only the tool's request id, title and placement are kept. It is not a
|
|
6622
|
+
* pane the resident opened itself: no controller types into it (residentOpenedPanes). It is a nested run of the
|
|
6623
|
+
* resident (config/profiles.ts nestedRunEnv), as the pane the agent's tool would have opened is (agent/tools/pane.ts
|
|
6624
|
+
* agentZtcPaneEnv): it saves none of the resident's settings and signs it neither in nor out. A controller's carries no
|
|
6625
|
+
* such marker.
|
|
6626
|
+
*/
|
|
6627
|
+
agentZtcPane(command) {
|
|
6628
|
+
const decision = hostedResidentAgentZtcPaneDecision(command, this.residentLaunch(), this.residentPanes());
|
|
6629
|
+
if (!decision.ok)
|
|
6630
|
+
return decision;
|
|
6631
|
+
const pane = decision.ztcPane;
|
|
6632
|
+
const title = command.title || `ZTC ${this.childPaneIds.size + 1}`;
|
|
6633
|
+
try {
|
|
6634
|
+
const launchSpec = this.createZtcPaneSpec({ sessionMode: 'new', title, cwd: pane.cwd, extraArgs: pane.args });
|
|
6635
|
+
const child = this.buildZtcCommand(launchSpec);
|
|
6636
|
+
// A headless mirror's ZTC pane runs as a headless pane child, as a controller's does (handleMirrorMuxCommand).
|
|
6637
|
+
const childArgs = this.headlessMirror ? child.args.filter(arg => arg !== '--pane') : child.args;
|
|
6638
|
+
if (command.request_id)
|
|
6639
|
+
this.trackPendingPaneLaunch(command.request_id, launchSpec);
|
|
6640
|
+
return { ok: true, command: { type: 'create_pane', request_id: command.request_id, command: child.command,
|
|
6641
|
+
args: hostedResidentPaneArgs(childArgs), cwd: pane.cwd, title, direction: command.direction, ratio: command.ratio,
|
|
6642
|
+
target: command.target, new_window: command.new_window, pane_type: 'ztc',
|
|
6643
|
+
env: { ...this.childZtcPaneEnv(), ...nestedRunEnv() } } };
|
|
6644
|
+
}
|
|
6645
|
+
catch (error) {
|
|
6646
|
+
return { ok: false, error: `failed to create ZTC pane: ${error.message}` };
|
|
6647
|
+
}
|
|
6648
|
+
}
|
|
6474
6649
|
registerPaneSpec(paneId, paneType, title, launchSpec) {
|
|
6475
6650
|
const isZtc = launchSpec?.kind === 'ztc' || paneType === 'ztc';
|
|
6476
6651
|
// A ZTC pane that names no route of its own starts on the route new panes start on, never this pane's.
|
|
@@ -6598,6 +6773,10 @@ export class RatatuiApp {
|
|
|
6598
6773
|
pending.sawClose = true;
|
|
6599
6774
|
return true;
|
|
6600
6775
|
}
|
|
6776
|
+
/** Why what a mirror's controller types isn't typed into pane PANE_ID, under its host's pin (pinnedPaneTypingRefusal). */
|
|
6777
|
+
pinnedTypingRefusal(paneId) {
|
|
6778
|
+
return pinnedPaneTypingRefusal(this.paneRegistry.get(paneId)?.paneType, this.agentCliPanes.has(paneId));
|
|
6779
|
+
}
|
|
6601
6780
|
publishPaneSystemMessage(paneId, content) {
|
|
6602
6781
|
this.mirrorServer?.publishPaneSystemMessage(paneId, content);
|
|
6603
6782
|
}
|
|
@@ -6624,7 +6803,15 @@ export class RatatuiApp {
|
|
|
6624
6803
|
trackPendingPaneLaunch(requestId, launchSpec) {
|
|
6625
6804
|
this.paneRegistry.trackPendingCreate(requestId, launchSpec);
|
|
6626
6805
|
}
|
|
6806
|
+
usesNativeDesktopDialogs() {
|
|
6807
|
+
return this.desktopMode && this.tui.hasCapability(CAPABILITY_DESKTOP_NATIVE_DIALOGS);
|
|
6808
|
+
}
|
|
6627
6809
|
async dailySelect(title, options) {
|
|
6810
|
+
if (this.usesNativeDesktopDialogs()) {
|
|
6811
|
+
if (this.exiting || !options.length)
|
|
6812
|
+
return null;
|
|
6813
|
+
return this.nativeDialogs.select({ title, options, filterable: options.length > 6 });
|
|
6814
|
+
}
|
|
6628
6815
|
let finish;
|
|
6629
6816
|
const previous = this.dailyDialogs;
|
|
6630
6817
|
this.dailyDialogs = new Promise(resolve => { finish = resolve; });
|
|
@@ -6788,7 +6975,13 @@ export class RatatuiApp {
|
|
|
6788
6975
|
transport: this.tui, cwd: () => this.shellCwd || process.cwd(), isRestoring: () => this.nativeRestorePending,
|
|
6789
6976
|
delegatedSkillRoots: () => configStore.get().desktopDelegatedSkillRoots ?? [],
|
|
6790
6977
|
select: (title, options) => this.dailySelect(title, options),
|
|
6791
|
-
input: (title, defaultValue) =>
|
|
6978
|
+
input: (title, defaultValue) => this.usesNativeDesktopDialogs()
|
|
6979
|
+
? this.nativeDialogs.input({ title, defaultValue })
|
|
6980
|
+
: new Promise(resolve => this.textInputWidget.show({ title, question: title, defaultValue, callback: resolve })),
|
|
6981
|
+
approve: (request) => this.usesNativeDesktopDialogs()
|
|
6982
|
+
? this.nativeDialogs.approve(request)
|
|
6983
|
+
: this.dailySelect(request.title, [{ value: 'denied', label: 'Deny' }, ...(request.approvable ? [{ value: 'approved', label: 'Approve' }] : [])])
|
|
6984
|
+
.then(answer => answer === 'approved' && request.approvable ? 'approved' : 'denied'),
|
|
6792
6985
|
track: record => {
|
|
6793
6986
|
const clean = parseNativeRecords({ [record.paneId]: record })[String(record.paneId)];
|
|
6794
6987
|
this.registerPaneSpec(clean.paneId, clean.launch.mode === 'interactive' ? 'process' : 'feed', `${clean.launch.tool} ${clean.launch.mode}`, { kind: 'native_tool', title: clean.launch.tool, record: clean });
|
|
@@ -7167,6 +7360,14 @@ export class RatatuiApp {
|
|
|
7167
7360
|
if (this.isHostedRuntime() && !isHostedMuxCommandAllowed(command.type)) {
|
|
7168
7361
|
return { ok: false, error: `The ${command.type} command is unavailable in hosted mode.` };
|
|
7169
7362
|
}
|
|
7363
|
+
// A hosted resident's decision; for a ZTC pane, the real directory and launch flags it approved.
|
|
7364
|
+
let residentPane;
|
|
7365
|
+
if (this.hostedResident) {
|
|
7366
|
+
const decision = hostedResidentMuxDecision(command, this.residentLaunch(), this.residentPanes());
|
|
7367
|
+
if (!decision.ok)
|
|
7368
|
+
return decision;
|
|
7369
|
+
residentPane = decision.ztcPane;
|
|
7370
|
+
}
|
|
7170
7371
|
if (command.type === 'set_session_settings') {
|
|
7171
7372
|
return this.applyHostedSessionSettingsCommand(command.expected_revision, command.settings);
|
|
7172
7373
|
}
|
|
@@ -7206,13 +7407,20 @@ export class RatatuiApp {
|
|
|
7206
7407
|
})
|
|
7207
7408
|
? { ok: true }
|
|
7208
7409
|
: { ok: false, error: 'failed to scroll pane' };
|
|
7209
|
-
case 'restart_pane':
|
|
7410
|
+
case 'restart_pane': {
|
|
7210
7411
|
if (command.pane_id === 0) {
|
|
7211
7412
|
return { ok: false, error: 'cannot restart overseer pane' };
|
|
7212
7413
|
}
|
|
7414
|
+
// A pane restarted runs its program again outside any sandbox (zmux and the headless pane manager restart a shell's
|
|
7415
|
+
// or a command's pane): under its host's pin, where the person's commands run only inside the OS sandbox, none is
|
|
7416
|
+
// (config/permission_pin.ts personProgramRefusal).
|
|
7417
|
+
const pinned = personProgramRefusal('No pane was restarted', 'its program', PINNED_PANE_INSTEAD);
|
|
7418
|
+
if (pinned)
|
|
7419
|
+
return { ok: false, error: pinned };
|
|
7213
7420
|
return this.tui.send({ type: 'restart_pane', pane_id: command.pane_id })
|
|
7214
7421
|
? { ok: true }
|
|
7215
7422
|
: { ok: false, error: 'failed to restart pane' };
|
|
7423
|
+
}
|
|
7216
7424
|
case 'close_pane':
|
|
7217
7425
|
if (command.pane_id === 0) {
|
|
7218
7426
|
return { ok: false, error: 'cannot close overseer pane' };
|
|
@@ -7247,14 +7455,22 @@ export class RatatuiApp {
|
|
|
7247
7455
|
this.publishPaneSystemMessage(0, error);
|
|
7248
7456
|
return { ok: false, error };
|
|
7249
7457
|
}
|
|
7458
|
+
// That check may ask Router (it awaits), and another create_ztc_pane, a controller's or the agent's, may have opened
|
|
7459
|
+
// a pane meanwhile: a hosted resident decides again here, with nothing awaited before the send, so no launch takes
|
|
7460
|
+
// a place past its cap (as spawnZtcPane does).
|
|
7461
|
+
if (this.hostedResident) {
|
|
7462
|
+
const decision = hostedResidentMuxDecision(command, this.residentLaunch(), this.residentPanes());
|
|
7463
|
+
if (!decision.ok)
|
|
7464
|
+
return decision;
|
|
7465
|
+
residentPane = decision.ztcPane;
|
|
7466
|
+
}
|
|
7250
7467
|
const title = command.title || `ZTC ${this.childPaneIds.size + 1}`;
|
|
7251
7468
|
try {
|
|
7252
|
-
|
|
7253
|
-
|
|
7254
|
-
|
|
7255
|
-
|
|
7256
|
-
title
|
|
7257
|
-
});
|
|
7469
|
+
// A hosted resident's pane starts on the flags its decision gave, never a provider or model inferred from
|
|
7470
|
+
// what the controller sent.
|
|
7471
|
+
const launchSpec = residentPane
|
|
7472
|
+
? this.createZtcPaneSpec({ sessionMode: 'new', title, cwd: residentPane.cwd, extraArgs: residentPane.args })
|
|
7473
|
+
: this.createZtcPaneSpec({ sessionMode: 'new', provider: command.provider, model: command.model, title });
|
|
7258
7474
|
const child = this.buildZtcCommand(launchSpec);
|
|
7259
7475
|
// A ZTC pane is a WEB CHAT pane (Dockview pane rendering the child agent's
|
|
7260
7476
|
// message stream), NOT a CLI terminal. In the headless mirror there's no
|
|
@@ -7265,17 +7481,24 @@ export class RatatuiApp {
|
|
|
7265
7481
|
// emits the JSON pane protocol on stdout, which the manager forwards to the
|
|
7266
7482
|
// mirror tagged by pane id — the web renders it as a 'ztc' chat pane.
|
|
7267
7483
|
// (In zmux mode --pane is correct; zmux supplies the PTY.)
|
|
7268
|
-
const
|
|
7484
|
+
const childArgs = this.headlessMirror
|
|
7269
7485
|
? child.args.filter((a) => a !== '--pane')
|
|
7270
7486
|
: child.args;
|
|
7487
|
+
// A hosted resident's pane takes its extension roots from its environment, as the launch resolved them.
|
|
7488
|
+
const paneArgs = residentPane ? hostedResidentPaneArgs(childArgs) : childArgs;
|
|
7271
7489
|
const requestId = `create-ztc-${generateSessionId()}`;
|
|
7272
7490
|
this.trackPendingPaneLaunch(requestId, launchSpec);
|
|
7491
|
+
// A hosted resident opens this pane itself, for its controller: it takes a controller's typing.
|
|
7492
|
+
if (residentPane)
|
|
7493
|
+
this.residentPaneRequests.add(requestId);
|
|
7273
7494
|
const sent = this.tui.send({
|
|
7274
7495
|
type: 'create_pane',
|
|
7275
7496
|
request_id: requestId,
|
|
7276
7497
|
command: child.command,
|
|
7277
7498
|
args: paneArgs,
|
|
7278
|
-
|
|
7499
|
+
// A hosted resident's pane is spawned in exactly the real directory its check approved. The chdir resolves
|
|
7500
|
+
// it again, so the pane checks where it landed as it starts (hostedResidentPaneStartRefusal).
|
|
7501
|
+
cwd: residentPane ? residentPane.cwd : command.cwd || child.cwd,
|
|
7279
7502
|
title,
|
|
7280
7503
|
pane_type: 'ztc',
|
|
7281
7504
|
env: this.childZtcPaneEnv(),
|
|
@@ -7302,6 +7525,9 @@ export class RatatuiApp {
|
|
|
7302
7525
|
return error ? { ok: false, error } : { ok: true };
|
|
7303
7526
|
}
|
|
7304
7527
|
case 'write_pane': {
|
|
7528
|
+
const typing = this.pinnedTypingRefusal(command.pane_id);
|
|
7529
|
+
if (typing)
|
|
7530
|
+
return { ok: false, error: typing };
|
|
7305
7531
|
// A shell's or a command's pane (an agent CLI's too) gets what the browser writes as written: its keys. Any other
|
|
7306
7532
|
// pane's program, a ZTC pane's agent above all, runs it as its prompt, so there it is mirror text, as what
|
|
7307
7533
|
// /pane-input sends a pane is: a forged `[image PATH]` in it would read PATH.
|
|
@@ -8800,13 +9026,18 @@ export class RatatuiApp {
|
|
|
8800
9026
|
rendererHostMode: this.desktopMode ? 'desktop' : 'terminal', rendererIdentitySource: 'host_launch_mode',
|
|
8801
9027
|
columns: event.cols, rows: event.rows, source: 'renderer_ready',
|
|
8802
9028
|
});
|
|
8803
|
-
// Real images need a renderer that
|
|
8804
|
-
//
|
|
8805
|
-
//
|
|
8806
|
-
// half blocks.
|
|
8807
|
-
setTerminalImageMode(
|
|
8808
|
-
|
|
9029
|
+
// Real images need a renderer that handles `transmit_image` uploads:
|
|
9030
|
+
// ZTC Desktop draws them natively as GPU textures, and ztc-tui/zmux
|
|
9031
|
+
// forward them to Ghostty/Kitty. Child panes and other terminals keep
|
|
9032
|
+
// half blocks, and ZTC_IMAGE_PROTOCOL=blocks overrides everywhere.
|
|
9033
|
+
setTerminalImageMode(resolveTerminalImageMode(process.env, {
|
|
9034
|
+
desktopMode: this.desktopMode,
|
|
9035
|
+
paneMode: this.paneMode,
|
|
9036
|
+
headlessMirror: this.headlessMirror,
|
|
9037
|
+
rendererSupportsImages: this.tui.hasCapability(CAPABILITY_KITTY_GRAPHICS),
|
|
9038
|
+
}), event.cell_pixels ?? null);
|
|
8809
9039
|
this.kittyImageUploads.reset();
|
|
9040
|
+
this.nativeDialogs.cancelAll();
|
|
8810
9041
|
// A new renderer: its cap is its own, so the transcript goes out under the full budget again.
|
|
8811
9042
|
this.transcriptLineBudget = TRANSCRIPT_LINE_BUDGET;
|
|
8812
9043
|
this.transcriptCommand = null;
|
|
@@ -8824,6 +9055,44 @@ export class RatatuiApp {
|
|
|
8824
9055
|
case 'desktop_session_share_action':
|
|
8825
9056
|
void this.handleDesktopSessionShareAction(event);
|
|
8826
9057
|
break;
|
|
9058
|
+
case 'desktop_dialog_result':
|
|
9059
|
+
this.nativeDialogs.handleEvent(event);
|
|
9060
|
+
break;
|
|
9061
|
+
case 'health': {
|
|
9062
|
+
const chip = this.desktopHealth.observe(event.health);
|
|
9063
|
+
if (chip && this.tui.hasCapability('desktop_health_v1')) {
|
|
9064
|
+
this.tui.send({
|
|
9065
|
+
type: 'set_health_chip',
|
|
9066
|
+
level: chip.level,
|
|
9067
|
+
text: chip.text,
|
|
9068
|
+
detail: chip.detail,
|
|
9069
|
+
actions: chip.actions,
|
|
9070
|
+
});
|
|
9071
|
+
}
|
|
9072
|
+
break;
|
|
9073
|
+
}
|
|
9074
|
+
case 'health_action_chosen': {
|
|
9075
|
+
if (event.action === 'restart_owner') {
|
|
9076
|
+
void this.restartZtc(true);
|
|
9077
|
+
}
|
|
9078
|
+
else if (event.action === 'open_doctor') {
|
|
9079
|
+
this.addSystemMessage('Running `ztc doctor` diagnostics from desktop health chip…');
|
|
9080
|
+
if (this.muxMode && this.tui.isReady()) {
|
|
9081
|
+
this.tui.send({
|
|
9082
|
+
type: 'create_pane',
|
|
9083
|
+
command: process.execPath,
|
|
9084
|
+
args: [process.argv[1] || 'ztc', 'doctor'],
|
|
9085
|
+
cwd: this.shellCwd || process.cwd(),
|
|
9086
|
+
title: 'ztc doctor',
|
|
9087
|
+
pane_type: 'process',
|
|
9088
|
+
});
|
|
9089
|
+
}
|
|
9090
|
+
}
|
|
9091
|
+
else if (event.action === 'copy_diagnostics') {
|
|
9092
|
+
this.addSystemMessage(this.desktopHealth.latestSummary());
|
|
9093
|
+
}
|
|
9094
|
+
break;
|
|
9095
|
+
}
|
|
8827
9096
|
case 'input':
|
|
8828
9097
|
this.handleInput(event.input, event.key, event.paste === true);
|
|
8829
9098
|
break;
|
|
@@ -8890,9 +9159,7 @@ export class RatatuiApp {
|
|
|
8890
9159
|
this.dailyDesktop.paneClosed(event.pane_id);
|
|
8891
9160
|
this.childPaneIds.add(event.pane_id);
|
|
8892
9161
|
this.notePaneCreated(event.pane_id, event.request_id);
|
|
8893
|
-
|
|
8894
|
-
if (agentCli)
|
|
8895
|
-
this.agentCliPanes.set(event.pane_id, agentCli);
|
|
9162
|
+
this.noteAgentCliPane(event.pane_id, event.request_id);
|
|
8896
9163
|
const launchSpec = this.paneRegistry.get(event.pane_id)?.launchSpec
|
|
8897
9164
|
|| this.paneRegistry.consumePendingCreate(event.request_id)
|
|
8898
9165
|
|| this.resumedPaneSpecs.find((pane) => pane.paneId === event.pane_id)?.launchSpec;
|
|
@@ -9040,12 +9307,7 @@ export class RatatuiApp {
|
|
|
9040
9307
|
this.childPaneModels.delete(event.pane_id);
|
|
9041
9308
|
this.childPaneSessionIds.delete(event.pane_id);
|
|
9042
9309
|
this.colonyPaneIds.delete(event.pane_id);
|
|
9043
|
-
this.
|
|
9044
|
-
// Its exchange with Main ends, and what Main held of it, or kept for a turn of its own, goes with it: no turn
|
|
9045
|
-
// runs for a pane that is gone. A pane that takes its number starts its own exchange.
|
|
9046
|
-
this.replyExchanges.closed(event.pane_id);
|
|
9047
|
-
this.agentPaneMessagesHeld.delete(event.pane_id);
|
|
9048
|
-
this.dropWaitingAgentPaneMessages(event.pane_id);
|
|
9310
|
+
this.agentCliPaneClosed(event.pane_id);
|
|
9049
9311
|
this.paneRegistry.remove(event.pane_id);
|
|
9050
9312
|
if (this.mirrorServer) {
|
|
9051
9313
|
this.mirrorServer.unregisterPane(event.pane_id);
|
|
@@ -11118,6 +11380,13 @@ export class RatatuiApp {
|
|
|
11118
11380
|
if (route.type === 'command') {
|
|
11119
11381
|
// The mirror records it without a key or a session of the person's (redactMirroredCommand); it runs as typed.
|
|
11120
11382
|
this.mirror?.publishMessage('user', redactMirroredCommand(text));
|
|
11383
|
+
// Every input reaches a hosted resident from its controllers (its mirror, or what they set going: a queued
|
|
11384
|
+
// line, a /loop tick, a goal), so it runs only its allowlisted slash commands; ! stays on the stub shell.
|
|
11385
|
+
const refusal = this.hostedResident ? hostedResidentCommandRefusal(route.cmd) : null;
|
|
11386
|
+
if (refusal) {
|
|
11387
|
+
this.addSystemMessage(refusal);
|
|
11388
|
+
return;
|
|
11389
|
+
}
|
|
11121
11390
|
await this.handleCommand(route.cmd, route.args, false, origin, atTerminal);
|
|
11122
11391
|
return;
|
|
11123
11392
|
}
|
|
@@ -11149,7 +11418,7 @@ export class RatatuiApp {
|
|
|
11149
11418
|
});
|
|
11150
11419
|
// A model only Zerg Router serves names itself and the step that reaches it, with or without a key here.
|
|
11151
11420
|
const routerOnly = sendRoute.route ? currentRouterOnlyModelError(configStore, sendRoute.route) : undefined;
|
|
11152
|
-
this.addErrorMessage(routerOnly ? routerOnly.message : buildCredentialSetupMessage());
|
|
11421
|
+
this.addErrorMessage(this.hostedResident ? HOSTED_RESIDENT_NO_MODEL_ROUTE : (routerOnly ? routerOnly.message : buildCredentialSetupMessage()));
|
|
11153
11422
|
return;
|
|
11154
11423
|
}
|
|
11155
11424
|
// Resolve local overlap while the full input is still unadmitted, before
|
|
@@ -11445,7 +11714,8 @@ export class RatatuiApp {
|
|
|
11445
11714
|
* entered it, from where (handleSubmit's `person` and `via`).
|
|
11446
11715
|
*/
|
|
11447
11716
|
askForSendCredential(route, input, queuedEntryId, literalInput, person, via) {
|
|
11448
|
-
|
|
11717
|
+
// A hosted resident never asks: its controllers would answer, and their answer is saved to config.json.
|
|
11718
|
+
if (this.hostedResident || queuedEntryId || this.paneMode || this.routingInteractionOccupied())
|
|
11449
11719
|
return false;
|
|
11450
11720
|
const ctx = this.buildCommandContext(message => this.controller.addMessage(message));
|
|
11451
11721
|
return promptForMissingDirectKey(route, ctx, async () => {
|
|
@@ -11560,7 +11830,9 @@ export class RatatuiApp {
|
|
|
11560
11830
|
* retainWorkspaceInput).
|
|
11561
11831
|
*/
|
|
11562
11832
|
async guardWorkspaceAdmission(input, signal, cwd, queuedEntryId, origin = {}) {
|
|
11563
|
-
|
|
11833
|
+
// Nor does a hosted resident ask: its controllers would answer, and isolate runs git and opens a ZTC pane outside
|
|
11834
|
+
// its workspace, while pause holds pane 0 behind /sessions continue, which they may not run.
|
|
11835
|
+
if (this.isHostedRuntime() || this.hostedResident)
|
|
11564
11836
|
return !this.exiting && !signal?.aborted;
|
|
11565
11837
|
const epoch = this.workspaceEpoch;
|
|
11566
11838
|
const attempt = this.workspaceAdmissionTail.then(async () => {
|
|
@@ -11736,6 +12008,13 @@ export class RatatuiApp {
|
|
|
11736
12008
|
}
|
|
11737
12009
|
}
|
|
11738
12010
|
async isolateWorkspace() {
|
|
12011
|
+
if (this.hostedResident) {
|
|
12012
|
+
// Its two ways here are closed already: it never puts up the workspace-overlap chooser, and /sessions isolate is
|
|
12013
|
+
// neither its controllers' nor its agent's to run. Refused all the same, as isolating runs git and opens a ZTC
|
|
12014
|
+
// pane outside the workspace.
|
|
12015
|
+
this.addSystemMessage('A hosted resident does not isolate its session into a new worktree. Your prompt and workspace are retained.');
|
|
12016
|
+
return;
|
|
12017
|
+
}
|
|
11739
12018
|
if (this.isHostedRuntime() || !this.muxMode || this.paneMode) {
|
|
11740
12019
|
this.addSystemMessage('Isolating this session requires a local zmux session (--mux). Your prompt and workspace are retained.');
|
|
11741
12020
|
return;
|
|
@@ -14022,8 +14301,8 @@ export class RatatuiApp {
|
|
|
14022
14301
|
return;
|
|
14023
14302
|
}
|
|
14024
14303
|
// Handle paste-image command
|
|
14025
|
-
// Useful when Cmd+V doesn't work for images (terminal intercepts it)
|
|
14026
|
-
if (cmd === 'paste-image'
|
|
14304
|
+
// Useful when Cmd+V doesn't work for images (terminal intercepts it). /pi is Pi's (pane_cli.ts).
|
|
14305
|
+
if (cmd === 'paste-image') {
|
|
14027
14306
|
const success = await this.handleClipboardImagePaste();
|
|
14028
14307
|
if (success) {
|
|
14029
14308
|
this.addSystemMessage('Image pasted from clipboard.');
|
|
@@ -14033,25 +14312,20 @@ export class RatatuiApp {
|
|
|
14033
14312
|
}
|
|
14034
14313
|
return;
|
|
14035
14314
|
}
|
|
14036
|
-
// Handle background agent commands
|
|
14037
|
-
|
|
14038
|
-
|
|
14039
|
-
|
|
14040
|
-
|
|
14041
|
-
|
|
14042
|
-
|
|
14043
|
-
|
|
14044
|
-
|
|
14315
|
+
// Handle background agent commands. /agents shows them, then (from the command registry) the coding-agent CLIs
|
|
14316
|
+
// ZTC opens in a pane; `/agents install <cli>` is the CLIs' alone.
|
|
14317
|
+
if (cmd === 'agents' && cmdArgs.length === 0) {
|
|
14318
|
+
const tasks = getBackgroundRegistry()?.listTasks() ?? [];
|
|
14319
|
+
if (tasks.length > 0) {
|
|
14320
|
+
const lines = tasks.map(t => {
|
|
14321
|
+
const elapsed = Date.now() - t.startedAt.getTime();
|
|
14322
|
+
const dur = formatDuration(elapsed);
|
|
14323
|
+
// A task cut short says so: the mirror withholds from an observer what may start a credential at the mark.
|
|
14324
|
+
const description = t.description.length > 60 ? `${t.description.slice(0, 60)}…` : t.description;
|
|
14325
|
+
return ` ${t.id} ${t.status.padEnd(10)} ${dur.padEnd(8)} ${description}`;
|
|
14326
|
+
});
|
|
14327
|
+
this.addSystemMessage(`Background agents:\n\n ID Status Duration Description\n${lines.join('\n')}`);
|
|
14045
14328
|
}
|
|
14046
|
-
const lines = tasks.map(t => {
|
|
14047
|
-
const elapsed = Date.now() - t.startedAt.getTime();
|
|
14048
|
-
const dur = formatDuration(elapsed);
|
|
14049
|
-
// A task cut short says so: the mirror withholds from an observer what may start a credential at the mark.
|
|
14050
|
-
const description = t.description.length > 60 ? `${t.description.slice(0, 60)}…` : t.description;
|
|
14051
|
-
return ` ${t.id} ${t.status.padEnd(10)} ${dur.padEnd(8)} ${description}`;
|
|
14052
|
-
});
|
|
14053
|
-
this.addSystemMessage(`Background agents:\n\n ID Status Duration Description\n${lines.join('\n')}`);
|
|
14054
|
-
return;
|
|
14055
14329
|
}
|
|
14056
14330
|
if (cmd === 'agent-cancel') {
|
|
14057
14331
|
const registry = this.requireBackgroundRegistry();
|
|
@@ -14394,9 +14668,8 @@ export class RatatuiApp {
|
|
|
14394
14668
|
const manager = new CommandPaneManager(this.sessionId, this.environmentSessionCwd ?? this.shellCwd, () => {
|
|
14395
14669
|
if (this.controller.getMode() === 'plan')
|
|
14396
14670
|
throw new Error('Command execution is disabled in Plan mode.');
|
|
14397
|
-
|
|
14398
|
-
|
|
14399
|
-
return { profileId, profile: configStore.getEffectivePermissionProfile(profileId), sandbox: config.sandbox };
|
|
14671
|
+
// A /job command is the person's: under its host's pin, with the OS sandbox required (config/person_command_policy.ts).
|
|
14672
|
+
return personCommandPolicy(configStore);
|
|
14400
14673
|
});
|
|
14401
14674
|
await manager.refresh();
|
|
14402
14675
|
this.commandPaneManagers.set(this.sessionId, manager);
|
|
@@ -14476,7 +14749,8 @@ export class RatatuiApp {
|
|
|
14476
14749
|
this.mirrorClient?.publish(snapshot);
|
|
14477
14750
|
for (const job of jobs) {
|
|
14478
14751
|
this.ensureSessionManager().recordCommandJob(job);
|
|
14479
|
-
|
|
14752
|
+
// Said of the jobs this ZTC starts: a session opened again is not told again of all an earlier process ran.
|
|
14753
|
+
if (startedHere(job) && this.commandJobStates.get(job.job_id) !== job.status) {
|
|
14480
14754
|
this.commandJobStates.set(job.job_id, job.status);
|
|
14481
14755
|
// A command cut short says so: the mirror withholds from an observer what may start a credential at the mark.
|
|
14482
14756
|
const command = job.command.length > 120 ? `${job.command.slice(0, 120)}…` : job.command;
|
|
@@ -14514,6 +14788,8 @@ export class RatatuiApp {
|
|
|
14514
14788
|
hookDispatcher,
|
|
14515
14789
|
hookApprovalRequester: (request) => this.requestHookApproval(request),
|
|
14516
14790
|
toolEffectObserver: (event) => this.admitWorkspaceTool(event),
|
|
14791
|
+
// A hosted resident's agent goes without the platform's zerg_* tools (app/hosted_resident.ts).
|
|
14792
|
+
hostedResident: this.hostedResident,
|
|
14517
14793
|
onLocalFileChange: async (paths, cwd) => {
|
|
14518
14794
|
if (!this.isHostedRuntime() && !this.exiting)
|
|
14519
14795
|
await this.localWorkspace().recordObservedPaths(paths, cwd);
|
|
@@ -14522,7 +14798,7 @@ export class RatatuiApp {
|
|
|
14522
14798
|
if (checkpoint.sessionId !== this.sessionId)
|
|
14523
14799
|
throw new Error('Tool checkpoint belongs to a different session');
|
|
14524
14800
|
this.controller.setMessages(mergeToolCheckpointMessages(this.controller.getState().messages, checkpoint.messages));
|
|
14525
|
-
await this.saveCurrentSession(true);
|
|
14801
|
+
await this.saveCurrentSession(true, undefined, true);
|
|
14526
14802
|
},
|
|
14527
14803
|
onMidTurnCompact: ({ signal, messages }) => this.ensureSessionManager().compactHistory(30, 5, signal, messages),
|
|
14528
14804
|
});
|
|
@@ -14644,11 +14920,12 @@ export class RatatuiApp {
|
|
|
14644
14920
|
/**
|
|
14645
14921
|
* Save the current session to disk
|
|
14646
14922
|
*/
|
|
14647
|
-
async saveCurrentSession(force = false, signal) {
|
|
14923
|
+
async saveCurrentSession(force = false, signal, toolCheckpoint = false) {
|
|
14648
14924
|
this.publishCurrentGoal();
|
|
14649
14925
|
if (!force && !this.shouldPersistSession())
|
|
14650
14926
|
return;
|
|
14651
|
-
await this.ensureSessionManager().save({ persistEmpty: force, required: force, signal, ...(
|
|
14927
|
+
await this.ensureSessionManager().save({ persistEmpty: force, required: force, signal, ...(toolCheckpoint ? { toolCheckpoint } : {}),
|
|
14928
|
+
...(this.exiting ? { captureLayout: true } : {}) });
|
|
14652
14929
|
}
|
|
14653
14930
|
workspacePaneTopology(state) {
|
|
14654
14931
|
return workspacePaneTopology(state);
|
|
@@ -15911,6 +16188,13 @@ export class RatatuiApp {
|
|
|
15911
16188
|
}
|
|
15912
16189
|
}
|
|
15913
16190
|
}
|
|
16191
|
+
/**
|
|
16192
|
+
* The mirror's URL for this ZTC's own messages and logs. A hosted resident's carries no token: its controllers come
|
|
16193
|
+
* with the one their host minted them, and a fresh 12-hour controller token would outlive that grant.
|
|
16194
|
+
*/
|
|
16195
|
+
mirrorLaunchUrl(params) {
|
|
16196
|
+
return this.mirrorServer?.getLaunchUrl(params, { token: !this.hostedResident }) ?? '';
|
|
16197
|
+
}
|
|
15914
16198
|
/**
|
|
15915
16199
|
* What a ZTC pane needs to join this workspace; its mirror credential is its own (see pane.ts childZtcPaneEnv). The
|
|
15916
16200
|
* renderer that starts it holds this process's environment: the pane keeps a host's grant that takes effect, and gets
|
|
@@ -15924,6 +16208,10 @@ export class RatatuiApp {
|
|
|
15924
16208
|
...hostRouterGrantDiscovery(),
|
|
15925
16209
|
// Under the host's pin of the permission settings the pane pins its own (config/permission_pin.ts).
|
|
15926
16210
|
...permissionPinChildEnv(configStore.permissionsPinned()),
|
|
16211
|
+
// What a hosted resident's controllers type into its ZTC panes runs no slash command there either; each pane starts
|
|
16212
|
+
// only inside the resident's workspace, which it checks for itself as it starts, and loads only the extension
|
|
16213
|
+
// roots the launch named, as the resident resolved them.
|
|
16214
|
+
...(this.hostedResident ? hostedResidentPaneEnv(this.residentLaunch().workspace, this.residentExtensionRoots) : {}),
|
|
15927
16215
|
};
|
|
15928
16216
|
if (process.env.ZTC_MIRROR_PORT) {
|
|
15929
16217
|
env.ZTC_MIRROR_PORT = process.env.ZTC_MIRROR_PORT;
|
|
@@ -16013,6 +16301,29 @@ export class RatatuiApp {
|
|
|
16013
16301
|
installedAgentClis() {
|
|
16014
16302
|
return { claude: findAgentCli('claude'), codex: findAgentCli('codex') };
|
|
16015
16303
|
}
|
|
16304
|
+
/** Where the person's own other coding-agent CLIs are installed (pane_clis.ts), none of them the project's in CWD. */
|
|
16305
|
+
installedTerminalClis(cwd) {
|
|
16306
|
+
const folder = cwd || this.shellCwd || process.cwd();
|
|
16307
|
+
return Object.fromEntries(TERMINAL_CLI_IDS.map(id => [id, findPaneCli(id, { cwd: folder })]));
|
|
16308
|
+
}
|
|
16309
|
+
/**
|
|
16310
|
+
* Open the person's own Antigravity, Pi, OpenCode, Gemini CLI, Copilot CLI or Cursor CLI in a pane: the chooser's
|
|
16311
|
+
* entry point. Returns what to tell the user (an error), or null.
|
|
16312
|
+
*/
|
|
16313
|
+
async spawnTerminalCliPane(cli, options) {
|
|
16314
|
+
if (!this.muxMode || this.paneMode)
|
|
16315
|
+
return 'Opening a coding-agent CLI needs a zmux session or the desktop app.';
|
|
16316
|
+
const cwd = options.cwd || this.shellCwd || process.cwd();
|
|
16317
|
+
const result = await openPaneCli(this.tui, {
|
|
16318
|
+
cli, cwd, ...(options.target !== undefined ? { target: options.target } : {}),
|
|
16319
|
+
findBinary: id => findPaneCli(id, { cwd }), motsi: this.paneMotsi(),
|
|
16320
|
+
// The chooser is the person's.
|
|
16321
|
+
openedBy: 'person',
|
|
16322
|
+
});
|
|
16323
|
+
if (result.notice)
|
|
16324
|
+
this.addSystemMessage(result.notice);
|
|
16325
|
+
return result.error ?? null;
|
|
16326
|
+
}
|
|
16016
16327
|
/**
|
|
16017
16328
|
* The `motsi` that panes start through so Zerg Router's Command Central can
|
|
16018
16329
|
* show them, or null: MotSi installed, its remote view on, and
|
|
@@ -16037,16 +16348,30 @@ export class RatatuiApp {
|
|
|
16037
16348
|
}
|
|
16038
16349
|
// The caller's directory when it has one (zmux reports the focused pane's),
|
|
16039
16350
|
// else this pane's own cwd — which is where the user's `/cd` landed.
|
|
16040
|
-
|
|
16351
|
+
let cwd = options?.cwd || this.shellCwd || process.cwd();
|
|
16352
|
+
// A hosted resident holds a ZTC pane its own callers open (the busy-input chooser's separate task, say) to the
|
|
16353
|
+
// decisions a controller's create_ztc_pane gets: inside its workspace, in the real directory approved, on its launch.
|
|
16354
|
+
let residentArgs;
|
|
16355
|
+
if (this.hostedResident) {
|
|
16356
|
+
const decision = hostedResidentMuxDecision({ type: 'create_ztc_pane', cwd }, this.residentLaunch(), this.residentPanes());
|
|
16357
|
+
if (!decision.ok)
|
|
16358
|
+
return { error: decision.error };
|
|
16359
|
+
cwd = decision.ztcPane.cwd;
|
|
16360
|
+
residentArgs = decision.ztcPane.args;
|
|
16361
|
+
}
|
|
16041
16362
|
const title = options?.title?.trim() || `ZTC ${this.childPaneIds.size + 1}`;
|
|
16042
16363
|
const requestId = `ztc-pane-${generateSessionId()}`;
|
|
16043
16364
|
const route = options?.route;
|
|
16044
16365
|
const launchSpec = this.createZtcPaneSpec({ sessionMode: 'new', cwd, title, ...(route ? { provider: route.provider,
|
|
16045
|
-
model: route.model, authMode: route.authMode, ...(route.routerOrigin ? { routerOrigin: route.routerOrigin } : {}) } : {})
|
|
16366
|
+
model: route.model, authMode: route.authMode, ...(route.routerOrigin ? { routerOrigin: route.routerOrigin } : {}) } : {}),
|
|
16367
|
+
extraArgs: residentArgs });
|
|
16046
16368
|
let child;
|
|
16047
16369
|
let captured = null;
|
|
16048
16370
|
try {
|
|
16049
16371
|
child = this.buildZtcCommand(launchSpec);
|
|
16372
|
+
// A hosted resident's pane takes its extension roots from its environment, as the launch resolved them.
|
|
16373
|
+
if (residentArgs)
|
|
16374
|
+
child = { ...child, args: hostedResidentPaneArgs(child.args) };
|
|
16050
16375
|
if (options?.initialInput) {
|
|
16051
16376
|
captured = await preparePaneInitialInput(options.initialInput, launchSpec.session.id, cwd);
|
|
16052
16377
|
if (this.exiting || options.initialInputSignal?.aborted) {
|
|
@@ -16066,6 +16391,18 @@ export class RatatuiApp {
|
|
|
16066
16391
|
await cleanupPaneInitialInput(captured);
|
|
16067
16392
|
return { error: `Failed to build the ZTC pane command: ${err.message}` };
|
|
16068
16393
|
}
|
|
16394
|
+
// Capturing the input awaited, and a controller's create_ztc_pane may have opened a pane meanwhile: a hosted
|
|
16395
|
+
// resident decides again here, with nothing awaited before the send, so no launch takes a place past its cap.
|
|
16396
|
+
if (this.hostedResident) {
|
|
16397
|
+
const decision = hostedResidentMuxDecision({ type: 'create_ztc_pane', cwd }, this.residentLaunch(), this.residentPanes());
|
|
16398
|
+
if (!decision.ok) {
|
|
16399
|
+
if (captured)
|
|
16400
|
+
await cleanupPaneInitialInput(captured);
|
|
16401
|
+
return { error: decision.error };
|
|
16402
|
+
}
|
|
16403
|
+
// A hosted resident opens this pane itself (its separate-task chooser, say): it takes a controller's typing.
|
|
16404
|
+
this.residentPaneRequests.add(requestId);
|
|
16405
|
+
}
|
|
16069
16406
|
this.trackPendingPaneLaunch(requestId, launchSpec);
|
|
16070
16407
|
const created = this.waitForTuiEvent(
|
|
16071
16408
|
// A refusal named for another request is another pane's; one that names
|
|
@@ -16140,6 +16477,26 @@ export class RatatuiApp {
|
|
|
16140
16477
|
return;
|
|
16141
16478
|
}
|
|
16142
16479
|
const origin = this.desktopMode ? await this.rendererFocusedPane() : null;
|
|
16480
|
+
const choices = newPaneChoices(customPaneOptions(configStore.get()), { ...this.installedAgentClis(), ...this.installedTerminalClis(cwd) });
|
|
16481
|
+
const options = [
|
|
16482
|
+
...choices,
|
|
16483
|
+
...(this.dailyDesktop ? [...nativeChoices, { value: 'native:stop', label: 'Stop native pane' }, { value: 'native:resume', label: 'Resume native pane by exact id' }, { value: 'native:adopt', label: 'Adopt orphaned native pane' }, { value: 'native:router-refresh', label: 'Refresh delegated Router login' }, { value: 'native:router-signout', label: 'Sign out delegated Router login (local only)' }] : []),
|
|
16484
|
+
];
|
|
16485
|
+
if (this.usesNativeDesktopDialogs()) {
|
|
16486
|
+
const value = await this.nativeDialogs.select({
|
|
16487
|
+
title: 'New pane',
|
|
16488
|
+
question: 'What should the new pane be?',
|
|
16489
|
+
options,
|
|
16490
|
+
filterable: true,
|
|
16491
|
+
hint: 'Type to filter · Enter open · Esc cancel',
|
|
16492
|
+
});
|
|
16493
|
+
if (value === null)
|
|
16494
|
+
return;
|
|
16495
|
+
const error = await this.createPickedPane(value, cwd, origin ?? undefined);
|
|
16496
|
+
if (error)
|
|
16497
|
+
this.addSystemMessage(error);
|
|
16498
|
+
return;
|
|
16499
|
+
}
|
|
16143
16500
|
if (this.desktopMode)
|
|
16144
16501
|
this.tui.send({ type: 'focus_pane', pane_id: 0 });
|
|
16145
16502
|
// An open prompt in Main, a native pane's dialog among them, waits for its answer: the chooser would replace it
|
|
@@ -16149,16 +16506,12 @@ export class RatatuiApp {
|
|
|
16149
16506
|
return;
|
|
16150
16507
|
}
|
|
16151
16508
|
const ctx = this.buildCommandContext((msg) => this.controller.addMessage(msg));
|
|
16152
|
-
const choices = newPaneChoices(customPaneOptions(configStore.get()), this.installedAgentClis());
|
|
16153
16509
|
ctx.select.showSelect({
|
|
16154
16510
|
title: 'New pane',
|
|
16155
16511
|
// The browser mirror asks it; the panel's heading says it here.
|
|
16156
16512
|
question: 'What should the new pane be?',
|
|
16157
16513
|
type: 'select',
|
|
16158
|
-
options
|
|
16159
|
-
...choices,
|
|
16160
|
-
...(this.dailyDesktop ? [...nativeChoices, { value: 'native:stop', label: 'Stop native pane' }, { value: 'native:resume', label: 'Resume native pane by exact id' }, { value: 'native:adopt', label: 'Adopt orphaned native pane' }, { value: 'native:router-refresh', label: 'Refresh delegated Router login' }, { value: 'native:router-signout', label: 'Sign out delegated Router login (local only)' }] : []),
|
|
16161
|
-
],
|
|
16514
|
+
options,
|
|
16162
16515
|
// A short choice, like the connect prompt: a panel on the composer, as every small panel is (user 2026-11-12).
|
|
16163
16516
|
appearance: 'panel',
|
|
16164
16517
|
statusHint: 'Enter open · Esc cancel',
|
|
@@ -16253,6 +16606,9 @@ export class RatatuiApp {
|
|
|
16253
16606
|
const agentCli = agentCliFromChoice(choice);
|
|
16254
16607
|
if (agentCli)
|
|
16255
16608
|
return this.spawnAgentCliPane(agentCli, { cwd, target });
|
|
16609
|
+
const paneCli = paneCliFromChoice(choice);
|
|
16610
|
+
if (paneCli)
|
|
16611
|
+
return this.spawnTerminalCliPane(paneCli, { cwd, target });
|
|
16256
16612
|
if (choice.startsWith('custom:')) {
|
|
16257
16613
|
const option = customPaneOptions(configStore.get())[Number(choice.slice('custom:'.length))];
|
|
16258
16614
|
if (!option)
|
|
@@ -16289,6 +16645,11 @@ export class RatatuiApp {
|
|
|
16289
16645
|
* zmux accepted the pane.
|
|
16290
16646
|
*/
|
|
16291
16647
|
spawnShellPane(options) {
|
|
16648
|
+
// A shell pane's shell runs outside any sandbox: under its host's pin, where the person's commands run only inside the
|
|
16649
|
+
// OS sandbox, none is opened, from the chooser, the desktop app or a controller (config/permission_pin.ts).
|
|
16650
|
+
const pinned = personProgramRefusal('No shell pane was opened', 'its shell', PINNED_PANE_INSTEAD);
|
|
16651
|
+
if (pinned)
|
|
16652
|
+
return pinned;
|
|
16292
16653
|
const shellCommand = process.env.SHELL || (process.platform === 'win32' ? 'powershell.exe' : '/bin/bash');
|
|
16293
16654
|
const requestId = options?.requestId ?? `create-shell-${generateSessionId()}`;
|
|
16294
16655
|
const cwd = options?.cwd || this.shellCwd || process.cwd();
|
|
@@ -16330,6 +16691,12 @@ export class RatatuiApp {
|
|
|
16330
16691
|
* it and ZTC the rest, so there ZTC starts none and says where the plan is.
|
|
16331
16692
|
*/
|
|
16332
16693
|
async openPlanInEditor(planFile) {
|
|
16694
|
+
// The editor runs outside any sandbox, and can run commands of its own: under its host's pin, it isn't started.
|
|
16695
|
+
const pinned = personProgramRefusal('The plan was not opened in your editor', 'the editor', `The plan is ${planFile}.`);
|
|
16696
|
+
if (pinned) {
|
|
16697
|
+
this.controller.addMessage({ role: 'system', content: pinned });
|
|
16698
|
+
return;
|
|
16699
|
+
}
|
|
16333
16700
|
const panes = getMuxTransport();
|
|
16334
16701
|
if (!panes) {
|
|
16335
16702
|
this.controller.addMessage({ role: 'system', content: 'Ctrl+G opens the plan in your editor in a pane of its own, '
|
|
@@ -16377,6 +16744,10 @@ export class RatatuiApp {
|
|
|
16377
16744
|
* an error to report, or null when zmux accepted the pane.
|
|
16378
16745
|
*/
|
|
16379
16746
|
spawnCommandPane(commandLine, options) {
|
|
16747
|
+
// A command pane's command runs outside any sandbox: under its host's pin, not at all, as for a shell pane.
|
|
16748
|
+
const pinned = personProgramRefusal('No command pane was opened', 'its command', PINNED_PANE_INSTEAD);
|
|
16749
|
+
if (pinned)
|
|
16750
|
+
return pinned;
|
|
16380
16751
|
const command = commandLine.trim();
|
|
16381
16752
|
if (!command)
|
|
16382
16753
|
return 'command is required';
|
|
@@ -16557,6 +16928,7 @@ export class RatatuiApp {
|
|
|
16557
16928
|
if (this.exiting)
|
|
16558
16929
|
return this.exitComplete;
|
|
16559
16930
|
this.exiting = true;
|
|
16931
|
+
this.nativeDialogs.cancelAll(true);
|
|
16560
16932
|
this.idleCompaction.cancel();
|
|
16561
16933
|
this.startupCatalogController.abort(new Error('Runtime stopped'));
|
|
16562
16934
|
this.stopFollowingConfig?.();
|
|
@@ -16643,7 +17015,12 @@ export class RatatuiApp {
|
|
|
16643
17015
|
// screen). From here the user sees a normal shell again. Guarded so a stuck
|
|
16644
17016
|
// renderer can't strand the process before it reaches process.exit().
|
|
16645
17017
|
try {
|
|
16646
|
-
|
|
17018
|
+
if (options.preserveRendererForReattach && this.tui instanceof TuiProcess) {
|
|
17019
|
+
this.tui.disconnectForReattach();
|
|
17020
|
+
}
|
|
17021
|
+
else {
|
|
17022
|
+
await this.tui.stop();
|
|
17023
|
+
}
|
|
16647
17024
|
}
|
|
16648
17025
|
catch (err) {
|
|
16649
17026
|
debugLog(`[exit] tui.stop failed: ${err.message}`);
|
|
@@ -16916,14 +17293,36 @@ export class RatatuiApp {
|
|
|
16916
17293
|
await stopMirrorStreamServer();
|
|
16917
17294
|
this.mirrorServer = null;
|
|
16918
17295
|
}
|
|
17296
|
+
// If running inside a desktop ZTerm that supports live owner reattach
|
|
17297
|
+
// (`owner_reattach_v1`), detach cleanly WITHOUT sending `shutdown` so ZTerm
|
|
17298
|
+
// and every live shell/agent pane + detached OS window keep running while
|
|
17299
|
+
// the new ZTC takes over in-situ!
|
|
17300
|
+
const reattachTarget = (this.desktopMode
|
|
17301
|
+
&& this.tui instanceof TuiProcess
|
|
17302
|
+
&& this.tui.hasCapability('owner_reattach_v1')
|
|
17303
|
+
&& this.tui.activeSocketPath
|
|
17304
|
+
&& this.tui.reattachTokenPath
|
|
17305
|
+
&& existsSync(this.tui.reattachTokenPath))
|
|
17306
|
+
? { socketPath: this.tui.activeSocketPath, tokenFilePath: this.tui.reattachTokenPath }
|
|
17307
|
+
: null;
|
|
16919
17308
|
// execve skips exit handlers. Release the old session's registry entry,
|
|
16920
17309
|
// timers, backends and renderer before replacing the process. Persistence
|
|
16921
17310
|
// already happened above, while the renderer could still snapshot panes.
|
|
16922
|
-
await this.exit(false, {
|
|
17311
|
+
await this.exit(false, {
|
|
17312
|
+
announce: false,
|
|
17313
|
+
persistSession: false,
|
|
17314
|
+
terminateProcess: false,
|
|
17315
|
+
preserveRendererForReattach: reattachTarget !== null,
|
|
17316
|
+
});
|
|
16923
17317
|
// Build relaunch args: preserve runtime flags but force the target session
|
|
16924
17318
|
// as the only resume target.
|
|
16925
17319
|
const spawnCwd = existsSync(options.cwd) ? options.cwd : process.cwd();
|
|
16926
17320
|
const { command, args, shell } = buildHotRestartLaunch(withActiveProfileArg(process.argv.slice(1)), options.sessionId, process.execPath, spawnCwd);
|
|
17321
|
+
if (reattachTarget) {
|
|
17322
|
+
if (!args.includes('--desktop'))
|
|
17323
|
+
args.push('--desktop');
|
|
17324
|
+
args.push('--reattach-socket', reattachTarget.socketPath, '--reattach-token-file', reattachTarget.tokenFilePath);
|
|
17325
|
+
}
|
|
16927
17326
|
// A pane's ZTC hands its mirror credential to the ZTC that takes its place in a fresh one-time file, never in the
|
|
16928
17327
|
// environment that ZTC starts with (see pane_credentials.ts).
|
|
16929
17328
|
args.push(...paneCredentialRelaunchArgs());
|
|
@@ -16938,7 +17337,9 @@ export class RatatuiApp {
|
|
|
16938
17337
|
// Under the host's pin of the permission settings, it is handed the variable, whatever this process's environment says
|
|
16939
17338
|
// of it now, and what this ZTC's pin was taken from, and doesn't start where config.json, or the host's thread, says
|
|
16940
17339
|
// otherwise by the time it reads them (config/permission_pin.ts).
|
|
16941
|
-
|
|
17340
|
+
// It is handed which live panes are the person's alone (person_only_panes.ts), as it adopts them.
|
|
17341
|
+
const relaunchEnv = { ...process.env, ...hostCredentialRelaunchEnv(), ...configStore.permissionPinRestartEnv(),
|
|
17342
|
+
...personOnlyPanesRelaunchEnv() };
|
|
16942
17343
|
if (runtime.execve) {
|
|
16943
17344
|
process.chdir(spawnCwd);
|
|
16944
17345
|
runtime.execve(command, [command, ...args], relaunchEnv);
|