@zergai/ztc 0.17.0-beta.1 → 0.18.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 +3 -2
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/zterm-darwin-arm64 +1 -1
- package/dist/App.js +21 -7
- package/dist/agent/backends/router_gate.js +3 -2
- package/dist/agent/backends/router_refusal_record.d.ts +12 -2
- package/dist/agent/backends/router_refusal_record.js +19 -4
- package/dist/agent/tools/pane.d.ts +6 -1
- package/dist/agent/tools/pane.js +6 -4
- package/dist/app/mirror_startup.d.ts +7 -0
- package/dist/app/mirror_startup.js +10 -0
- package/dist/app/restart.d.ts +6 -0
- package/dist/app/restart.js +13 -3
- package/dist/app/workspace_monitor.js +17 -3
- package/dist/app/workspace_presets.js +8 -1
- package/dist/cli_main.js +5 -0
- package/dist/cli_ratatui.d.ts +87 -18
- package/dist/cli_ratatui.js +234 -129
- package/dist/embedded/anempa_runtime.js +3 -0
- package/dist/embedded/gameboy_runtime.js +4 -2
- package/dist/embedded/zergpod_runtime.js +4 -2
- package/dist/environment/store.js +4 -1
- package/dist/mcp/client.js +6 -2
- package/dist/mcp/workspace_server.d.ts +7 -3
- package/dist/mcp/workspace_server.js +15 -8
- package/dist/panes/agent_cli.d.ts +10 -3
- package/dist/panes/agent_cli.js +16 -4
- package/dist/runtime_info.js +10 -1
- package/dist/simulation/engines/swarm/pane_manager.d.ts +16 -3
- package/dist/simulation/engines/swarm/pane_manager.js +39 -17
- package/dist/types.d.ts +5 -2
- package/dist/ui/ratatui/headless_pane_manager.d.ts +13 -1
- package/dist/ui/ratatui/headless_pane_manager.js +37 -8
- package/dist/ui/ratatui/pane_credential_broker.d.ts +107 -0
- package/dist/ui/ratatui/pane_credential_broker.js +239 -0
- package/dist/ui/ratatui/pane_relay.js +4 -2
- package/dist/ui/ratatui/process.d.ts +13 -0
- package/dist/ui/ratatui/process.js +38 -3
- package/dist/utils/subprocess_env.js +1 -0
- package/dist/web/mirror_authenticator.d.ts +27 -11
- package/dist/web/mirror_authenticator.js +36 -12
- package/dist/web/mirror_client.d.ts +2 -1
- package/dist/web/mirror_client.js +7 -5
- package/dist/web/mirror_stream.d.ts +39 -8
- package/dist/web/mirror_stream.js +164 -29
- package/dist/web/pane_credentials.d.ts +131 -0
- package/dist/web/pane_credentials.js +302 -0
- package/dist/zlm-embed.mjs +2 -1
- package/package.json +11 -46
package/dist/cli_ratatui.js
CHANGED
|
@@ -111,7 +111,7 @@ import { generateSessionId, bindToolResponseStoreToSession, findRecentSessionSum
|
|
|
111
111
|
import { awaitStartupGitSnapshot, getRuntimeInfo, getStartupGitSnapshot } from './runtime_info.js';
|
|
112
112
|
import { ContextOverflowError, isContextOverflowMessage } from './agent/agent.js';
|
|
113
113
|
import { dumpContextOverflow } from './agent/contextDump.js';
|
|
114
|
-
import { BROWSER_BUS_MEMBER_ID, createMirrorStreamServer, startMirrorStreamServer, stopMirrorStreamServer, } from './web/mirror_stream.js';
|
|
114
|
+
import { BROWSER_BUS_MEMBER_ID, OVERSEER_BUS_MEMBER_ID, createMirrorStreamServer, startMirrorStreamServer, stopMirrorStreamServer, } from './web/mirror_stream.js';
|
|
115
115
|
import { initMirrorClient } from './web/mirror_client.js';
|
|
116
116
|
import { PaneRelayServer, PaneRelayClient, generateRelaySocketPath } from './ui/ratatui/pane_relay.js';
|
|
117
117
|
import { perfBeginKeystroke, perfStage, perfEndKeystroke } from './debug/perf_trace.js';
|
|
@@ -129,6 +129,7 @@ import { SelectionCompletion } from './app/selection_completion.js';
|
|
|
129
129
|
import { routerCatalogScope } from './utils/router_catalog.js';
|
|
130
130
|
import { shouldAttachParentMirrorClient, shouldMarkMirrorServerAsColonyChild } from './app/mirror_startup.js';
|
|
131
131
|
import { buildDesktopUpdateRelaunchContext, buildHotRestartLaunch, prepareDesktopUpdateAuthorization, reduceDesktopUpdateOwnerHandshake, requestColonyCellRestart, } from './app/restart.js';
|
|
132
|
+
import { paneCredentialRelaunchArgs, withoutMirrorCredentials } from './web/pane_credentials.js';
|
|
132
133
|
export { buildDesktopUpdateRelaunchContext, buildHotRestartArgs, requestColonyCellRestart, } from './app/restart.js';
|
|
133
134
|
import { formatWorkflowEventDisplay } from './app/workflow_event_display.js';
|
|
134
135
|
import { getBackgroundRegistry, clearBackgroundRegistry } from './agent/tools/index.js';
|
|
@@ -564,14 +565,16 @@ export class RatatuiApp {
|
|
|
564
565
|
/** Busy Enter prompts waiting for the next completed tool batch. */
|
|
565
566
|
pendingSteering = [];
|
|
566
567
|
/**
|
|
567
|
-
* Steering the person
|
|
568
|
-
* carries one is theirs: it gets
|
|
568
|
+
* Steering that takes the person's one attempt past a Zerg Router refusal (see takesRouterAttempt) and that no
|
|
569
|
+
* request has carried yet. The first request that carries one is theirs: it gets that attempt, as their message would
|
|
570
|
+
* when idle.
|
|
569
571
|
*/
|
|
570
572
|
personSteeringIds = new Set();
|
|
571
573
|
/**
|
|
572
|
-
* The person entered a message
|
|
573
|
-
*
|
|
574
|
-
*
|
|
574
|
+
* The person entered a message that takes their one attempt past a Zerg Router refusal (see takesRouterAttempt), and
|
|
575
|
+
* the next turn to start carries it. That turn takes it as it starts and, once started, admits it on the agent that
|
|
576
|
+
* runs it (rebuilt meanwhile when the mode changed), so the request carrying the message gets the attempt. A turn
|
|
577
|
+
* that fails to start drops it. Typing that reaches a ZTC pane's or a colony cell's terminal never sets it.
|
|
575
578
|
*/
|
|
576
579
|
personMessagePending = false;
|
|
577
580
|
nativeSteeringInFlight = [];
|
|
@@ -602,7 +605,7 @@ export class RatatuiApp {
|
|
|
602
605
|
workspacePausedSnapshot = null;
|
|
603
606
|
workspacePausedEffectCwd = null;
|
|
604
607
|
workspacePausedQueueId = null;
|
|
605
|
-
/** Input held over a workspace pause, and
|
|
608
|
+
/** Input held over a workspace pause, and who entered it and where (see queueOrigin). */
|
|
606
609
|
workspacePendingInputs = [];
|
|
607
610
|
workspaceDeferredRun = false;
|
|
608
611
|
workspaceAdmissionTail = Promise.resolve();
|
|
@@ -1495,40 +1498,13 @@ export class RatatuiApp {
|
|
|
1495
1498
|
this.mirrorServer.onBusMessage(0, 'Overseer', (msg) => {
|
|
1496
1499
|
this.handleBusMessage(msg);
|
|
1497
1500
|
});
|
|
1498
|
-
|
|
1499
|
-
// Input that carries attachments is encoded as a structured submit envelope so the child
|
|
1500
|
-
// pane can reconstruct them; plain text falls back to a flattened `[image ...]` form.
|
|
1501
|
-
this.mirrorServer.onPaneInput((paneId, input) => {
|
|
1502
|
-
debugLog(`[Mirror] Pane input fallback via stdin: pane=${paneId} length=${input.text.length}`);
|
|
1503
|
-
if (input.attachments.length > 0) {
|
|
1504
|
-
// Attachments can't ride the plain-text prompt envelope, so encode them
|
|
1505
|
-
// as a submit_input control command — delivered BARE (control:true) so
|
|
1506
|
-
// the child classifies it as submit_input, not a literal prompt.
|
|
1507
|
-
this.tui.send({ type: 'write_pane', pane_id: paneId, input: JSON.stringify({ __ztc_cmd: 'submit_input', input }), control: true });
|
|
1508
|
-
}
|
|
1509
|
-
else {
|
|
1510
|
-
// Plain user text: prompt-wrapped (submit) — verbatim to the LLM.
|
|
1511
|
-
this.tui.send({ type: 'write_pane', pane_id: paneId, input: formatMirrorPaneInput(input), submit: true });
|
|
1512
|
-
}
|
|
1513
|
-
});
|
|
1514
|
-
// Internal control commands (model hot-swap, effort) reach a headless child
|
|
1515
|
-
// BARE so its classifier can never confuse them with a user prompt.
|
|
1516
|
-
this.mirrorServer.onPaneControl((paneId, controlLine) => {
|
|
1517
|
-
debugLog(`[Mirror] Pane control via stdin (bare): pane=${paneId} cmd=${controlLine.slice(0, 60)}`);
|
|
1518
|
-
this.tui.send({ type: 'write_pane', pane_id: paneId, input: controlLine, control: true });
|
|
1519
|
-
});
|
|
1520
|
-
// An agent's message for a Claude Code or Codex pane is typed in, one
|
|
1521
|
-
// line saying who sent it, with Enter as its own keystroke.
|
|
1522
|
-
this.mirrorServer.onAgentPaneMessage((paneId, msg) => {
|
|
1523
|
-
if (!this.agentCliPanes.has(paneId))
|
|
1524
|
-
return false;
|
|
1525
|
-
return typeLineIntoPane(this.tui, paneId, formatAgentPaneMessage(msg));
|
|
1526
|
-
});
|
|
1501
|
+
this.registerMirrorPaneFallbacks(this.mirrorServer);
|
|
1527
1502
|
}
|
|
1528
|
-
// Handle input from browser mirror (single-pane mode fallback), and what
|
|
1503
|
+
// Handle input from browser mirror (single-pane mode fallback), what a ZTC process or pane relays, and what
|
|
1504
|
+
// /broadcast delivers (see submitMirrorInput)
|
|
1529
1505
|
this.mirrorServer.onInput((input, via) => {
|
|
1530
1506
|
debugLog(`[Mirror] Received input from ${via}: length=${input.text.length}`);
|
|
1531
|
-
this.
|
|
1507
|
+
void this.submitMirrorInput(input, via);
|
|
1532
1508
|
});
|
|
1533
1509
|
this.mirrorServer.onCancel((paneId) => {
|
|
1534
1510
|
debugLog(`[Mirror] Cancel requested from browser: pane=${paneId}`);
|
|
@@ -1547,9 +1523,10 @@ export class RatatuiApp {
|
|
|
1547
1523
|
if (paneId !== 0 && this.muxMode) {
|
|
1548
1524
|
debugLog(`[Mirror] Routing widget answer to child pane ${paneId} via bus`);
|
|
1549
1525
|
const payload = JSON.stringify({ __ztc_cmd: 'widget_answer', widget_id: widgetId, answer });
|
|
1526
|
+
// A child takes control commands only from its parent (handleBusMessage), so this one speaks as the overseer.
|
|
1550
1527
|
this.mirrorServer.deliverBusMessage({
|
|
1551
1528
|
id: randomUUID(),
|
|
1552
|
-
from: { id:
|
|
1529
|
+
from: { id: OVERSEER_BUS_MEMBER_ID, name: 'Overseer' },
|
|
1553
1530
|
to: paneId,
|
|
1554
1531
|
type: 'ztc_message',
|
|
1555
1532
|
text: payload,
|
|
@@ -1594,38 +1571,17 @@ export class RatatuiApp {
|
|
|
1594
1571
|
setBusTransport(this.mirrorClient);
|
|
1595
1572
|
}
|
|
1596
1573
|
}
|
|
1597
|
-
// Wire bus transport for send_message tool
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
sendBusMessage(to, text, type = 'ztc_message') {
|
|
1602
|
-
server.deliverBusMessage({
|
|
1603
|
-
id: randomUUID(),
|
|
1604
|
-
from: { id: 0, name: 'Overseer' },
|
|
1605
|
-
to,
|
|
1606
|
-
type,
|
|
1607
|
-
text,
|
|
1608
|
-
});
|
|
1609
|
-
},
|
|
1610
|
-
getPaneId() { return 0; },
|
|
1611
|
-
getPaneName() { return 'Overseer'; },
|
|
1612
|
-
});
|
|
1613
|
-
}
|
|
1614
|
-
else if (this.muxMode && !this.mirrorClient) {
|
|
1615
|
-
// Fallback: deliver messages by writing to panes via IPC (no mirror needed)
|
|
1616
|
-
const tui = this.tui;
|
|
1617
|
-
const self = this;
|
|
1574
|
+
// Wire bus transport for send_message tool. The parent sends as the overseer through the mirror it runs at the time:
|
|
1575
|
+
// the one it started with, or the one /mirror start started, whose bus its panes' mirror clients rejoin; never one
|
|
1576
|
+
// /mirror stop stopped, whose bus is gone. While it runs none, the message is typed into the panes.
|
|
1577
|
+
if (this.muxMode && !this.mirrorClient) {
|
|
1618
1578
|
setBusTransport({
|
|
1619
|
-
sendBusMessage(to, text) {
|
|
1620
|
-
const
|
|
1621
|
-
if (
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
}
|
|
1626
|
-
else {
|
|
1627
|
-
tui.send({ type: 'write_pane', pane_id: to, input: formatted, submit: true });
|
|
1628
|
-
}
|
|
1579
|
+
sendBusMessage: (to, text, type = 'ztc_message') => {
|
|
1580
|
+
const message = { id: randomUUID(), from: { id: 0, name: 'Overseer' }, to, type, text };
|
|
1581
|
+
if (this.mirrorServer)
|
|
1582
|
+
this.mirrorServer.deliverBusMessage(message);
|
|
1583
|
+
else
|
|
1584
|
+
this.typeOverseerMessage(message);
|
|
1629
1585
|
},
|
|
1630
1586
|
getPaneId() { return 0; },
|
|
1631
1587
|
getPaneName() { return 'Overseer'; },
|
|
@@ -1681,19 +1637,19 @@ export class RatatuiApp {
|
|
|
1681
1637
|
setEvolutionTuiProcess(this.tui);
|
|
1682
1638
|
// Colony Agent Bridge is initialized in start() AFTER tui.start() so the
|
|
1683
1639
|
// transport is ready to accept create_pane commands. See _initColonyBridge().
|
|
1684
|
-
// Wire mirror callback so doc pane content reaches the browser
|
|
1640
|
+
// Wire mirror callback so doc pane content reaches the browser, through the
|
|
1641
|
+
// mirror this ZTC runs at the time (a /mirror start's after /mirror stop).
|
|
1685
1642
|
// Only for Rust zmux mode — HeadlessPaneManager already emits pane_output
|
|
1686
1643
|
// via its own event handler, so skip to avoid double-publishing.
|
|
1687
1644
|
if (this.mirrorServer && !this.headlessMirror) {
|
|
1688
|
-
const mirror = this.mirrorServer;
|
|
1689
1645
|
setPaneToolsMirrorCallback((paneId, content) => {
|
|
1690
|
-
|
|
1646
|
+
this.mirrorServer?.publish({
|
|
1691
1647
|
type: 'pane_output',
|
|
1692
1648
|
data: { pane_id: paneId, content },
|
|
1693
1649
|
});
|
|
1694
1650
|
});
|
|
1695
1651
|
setPaneToolsZdeLiteCallback((paneId, state) => {
|
|
1696
|
-
|
|
1652
|
+
this.mirrorServer?.publishZdeLiteState(paneId, state);
|
|
1697
1653
|
});
|
|
1698
1654
|
}
|
|
1699
1655
|
setPaneToolsPendingLaunchCallback((requestId, launchSpec) => {
|
|
@@ -2310,7 +2266,8 @@ export class RatatuiApp {
|
|
|
2310
2266
|
}
|
|
2311
2267
|
this.handoffQueueSaveInFlight = true;
|
|
2312
2268
|
try {
|
|
2313
|
-
|
|
2269
|
+
// As whoever queued it, from where: a line relayed here takes no attempt past a Zerg Router refusal.
|
|
2270
|
+
const accepted = await this.admitBusySteering({ text: queued.text, attachments: queued.attachments ?? [] }, this.busyInputEpoch, { entry: queued, correction, source }, this.takesRouterAttempt(queued.person === true, queued.via ?? 'terminal'));
|
|
2314
2271
|
reply(accepted ? 'applied' : 'persistence_failed', accepted
|
|
2315
2272
|
? 'Queued task will steer the current run at its next admission boundary.'
|
|
2316
2273
|
: 'Queued task was not sent; its original source is retained.');
|
|
@@ -3435,12 +3392,14 @@ export class RatatuiApp {
|
|
|
3435
3392
|
.catch(() => { });
|
|
3436
3393
|
const actualPort = this.mirrorServer.getPort();
|
|
3437
3394
|
process.env.ZTC_MIRROR_PORT = String(actualPort);
|
|
3395
|
+
this.setPaneTransportMirrorPort(actualPort);
|
|
3438
3396
|
debugLog(`[Mirror] Server started on port ${actualPort}`);
|
|
3439
3397
|
if (this.muxMode) {
|
|
3440
3398
|
this.mirrorServer.setMultiPaneMode(true, configStore.getModel(), configStore.getProvider());
|
|
3441
3399
|
this.mirrorServer.onBusMessage(0, 'Overseer', (msg) => {
|
|
3442
3400
|
this.handleBusMessage(msg);
|
|
3443
3401
|
});
|
|
3402
|
+
this.registerMirrorPaneFallbacks(this.mirrorServer);
|
|
3444
3403
|
}
|
|
3445
3404
|
if (this.muxMode && !this.paneMode) {
|
|
3446
3405
|
this.mirrorServer.onMuxCommand((command) => this.handleMirrorMuxCommand(command));
|
|
@@ -3448,7 +3407,7 @@ export class RatatuiApp {
|
|
|
3448
3407
|
}
|
|
3449
3408
|
this.mirrorServer.onInput((input, via) => {
|
|
3450
3409
|
debugLog(`[Mirror] Received input from ${via}: length=${input.text.length}`);
|
|
3451
|
-
this.
|
|
3410
|
+
void this.submitMirrorInput(input, via);
|
|
3452
3411
|
});
|
|
3453
3412
|
this.mirrorServer.onCancel((paneId) => {
|
|
3454
3413
|
debugLog(`[Mirror] Cancel requested from browser: pane=${paneId}`);
|
|
@@ -3457,6 +3416,66 @@ export class RatatuiApp {
|
|
|
3457
3416
|
this.mirrorServer.onAskUserAnswer((answer, paneId, questionId) => this.handleQuestionAnswer(answer, paneId, questionId));
|
|
3458
3417
|
this.mirrorServer.onHookApproval((id, decision, reason, paneId) => this.handleApprovalAnswer(id, decision, reason, paneId));
|
|
3459
3418
|
}
|
|
3419
|
+
/**
|
|
3420
|
+
* In zmux, what SERVER delivers to a child pane with no bus connection of its own reaches the pane through this ZTC's
|
|
3421
|
+
* renderer, typed into its terminal: browser input and another member's message as input, the overseer's control
|
|
3422
|
+
* commands bare, and an agent's message for a Claude Code or Codex pane with its sender. The mirror ZTC starts with and
|
|
3423
|
+
* each one /mirror start starts take them; without them a mirror queues the message for a bus connection the pane
|
|
3424
|
+
* never makes.
|
|
3425
|
+
*/
|
|
3426
|
+
registerMirrorPaneFallbacks(server) {
|
|
3427
|
+
// Fallback: deliver browser input to child panes via stdin when bus SSE is unavailable.
|
|
3428
|
+
// Input that carries attachments is encoded as a structured submit envelope so the child
|
|
3429
|
+
// pane can reconstruct them; plain text falls back to a flattened `[image ...]` form.
|
|
3430
|
+
server.onPaneInput((paneId, input) => {
|
|
3431
|
+
debugLog(`[Mirror] Pane input fallback via stdin: pane=${paneId} length=${input.text.length}`);
|
|
3432
|
+
if (input.attachments.length > 0) {
|
|
3433
|
+
// Attachments can't ride the plain-text prompt envelope, so encode them
|
|
3434
|
+
// as a submit_input control command — delivered BARE (control:true) so
|
|
3435
|
+
// the child classifies it as submit_input, not a literal prompt.
|
|
3436
|
+
this.tui.send({ type: 'write_pane', pane_id: paneId, input: JSON.stringify({ __ztc_cmd: 'submit_input', input }), control: true });
|
|
3437
|
+
}
|
|
3438
|
+
else {
|
|
3439
|
+
// Plain user text: prompt-wrapped (submit) — verbatim to the LLM.
|
|
3440
|
+
this.tui.send({ type: 'write_pane', pane_id: paneId, input: formatMirrorPaneInput(input), submit: true });
|
|
3441
|
+
}
|
|
3442
|
+
});
|
|
3443
|
+
// Internal control commands (model hot-swap, effort) reach a headless child
|
|
3444
|
+
// BARE so its classifier can never confuse them with a user prompt.
|
|
3445
|
+
server.onPaneControl((paneId, controlLine) => {
|
|
3446
|
+
debugLog(`[Mirror] Pane control via stdin (bare): pane=${paneId} cmd=${controlLine.slice(0, 60)}`);
|
|
3447
|
+
this.tui.send({ type: 'write_pane', pane_id: paneId, input: controlLine, control: true });
|
|
3448
|
+
});
|
|
3449
|
+
// An agent's message for a Claude Code or Codex pane is typed in, one
|
|
3450
|
+
// line saying who sent it, with Enter as its own keystroke.
|
|
3451
|
+
server.onAgentPaneMessage((paneId, msg) => {
|
|
3452
|
+
if (!this.agentCliPanes.has(paneId))
|
|
3453
|
+
return false;
|
|
3454
|
+
return typeLineIntoPane(this.tui, paneId, formatAgentPaneMessage(msg));
|
|
3455
|
+
});
|
|
3456
|
+
}
|
|
3457
|
+
/**
|
|
3458
|
+
* The overseer's MESSAGE while this ZTC runs no mirror (it started without one, or /mirror stop stopped it): there is
|
|
3459
|
+
* no bus, so it is typed into the panes it is for. One for this ZTC itself reaches its own agent, as a mirror's member
|
|
3460
|
+
* 0 hands it over. A Claude Code or Codex pane gets it as a mirror types it in (registerMirrorPaneFallbacks); any other
|
|
3461
|
+
* pane, as the prompt "[Message from Overseer]: …". A broadcast reaches the ZTC panes, the members a bus would have,
|
|
3462
|
+
* and no shell, which would run it as a command.
|
|
3463
|
+
*/
|
|
3464
|
+
typeOverseerMessage(message) {
|
|
3465
|
+
if (message.to === OVERSEER_BUS_MEMBER_ID) {
|
|
3466
|
+
void this.handleBusMessage(message);
|
|
3467
|
+
return;
|
|
3468
|
+
}
|
|
3469
|
+
const paneIds = message.to === 'all'
|
|
3470
|
+
? this.paneRegistry.all().filter(pane => pane.paneType === 'ztc' && pane.paneId !== OVERSEER_BUS_MEMBER_ID).map(pane => pane.paneId)
|
|
3471
|
+
: [message.to];
|
|
3472
|
+
for (const paneId of paneIds) {
|
|
3473
|
+
if (this.agentCliPanes.has(paneId))
|
|
3474
|
+
typeLineIntoPane(this.tui, paneId, formatAgentPaneMessage(message));
|
|
3475
|
+
else
|
|
3476
|
+
this.tui.send({ type: 'write_pane', pane_id: paneId, input: `[Message from Overseer]: ${message.text}`, submit: true });
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3460
3479
|
resolveOwnQuestion(questionId) {
|
|
3461
3480
|
if (this.activeQuestionId !== questionId)
|
|
3462
3481
|
return false;
|
|
@@ -3467,7 +3486,8 @@ export class RatatuiApp {
|
|
|
3467
3486
|
}
|
|
3468
3487
|
handleQuestionAnswer(answer, paneId, questionId) {
|
|
3469
3488
|
if (paneId !== 0 && this.muxMode) {
|
|
3470
|
-
|
|
3489
|
+
// Relayed as the overseer: a child takes control commands only from its parent (handleBusMessage).
|
|
3490
|
+
this.mirrorServer?.deliverBusMessage({ id: randomUUID(), from: { id: OVERSEER_BUS_MEMBER_ID, name: 'Overseer' }, to: paneId,
|
|
3471
3491
|
type: 'ztc_message', text: JSON.stringify({ __ztc_cmd: 'ask_user_answer', question_id: questionId, answer }) });
|
|
3472
3492
|
return;
|
|
3473
3493
|
}
|
|
@@ -3541,7 +3561,8 @@ export class RatatuiApp {
|
|
|
3541
3561
|
}
|
|
3542
3562
|
handleApprovalAnswer(id, decision, reason, paneId = 0) {
|
|
3543
3563
|
if (paneId !== 0 && this.muxMode) {
|
|
3544
|
-
|
|
3564
|
+
// Relayed as the overseer: a child takes control commands only from its parent (handleBusMessage).
|
|
3565
|
+
this.mirrorServer?.deliverBusMessage({ id: randomUUID(), from: { id: OVERSEER_BUS_MEMBER_ID, name: 'Overseer' }, to: paneId,
|
|
3545
3566
|
type: 'ztc_message', text: JSON.stringify({ __ztc_cmd: 'hook_approval', id, decision, reason }) });
|
|
3546
3567
|
return;
|
|
3547
3568
|
}
|
|
@@ -3554,6 +3575,17 @@ export class RatatuiApp {
|
|
|
3554
3575
|
await stopMirrorStreamServer();
|
|
3555
3576
|
this.mirrorServer = null;
|
|
3556
3577
|
delete process.env.ZTC_MIRROR_PORT;
|
|
3578
|
+
this.setPaneTransportMirrorPort(undefined);
|
|
3579
|
+
}
|
|
3580
|
+
/**
|
|
3581
|
+
* Tell the pane transport which mirror this ZTC runs now, or that it runs none: a pane a pane opens through the relay
|
|
3582
|
+
* is pointed at that mirror and gets its credential there, rather than at the one the renderer was started with, which
|
|
3583
|
+
* /mirror stop and a /mirror start on another port leave behind (PaneCredentialBroker.setOwnerMirrorPort). Only a
|
|
3584
|
+
* transport that opens panes takes it; NullTuiProcess opens none.
|
|
3585
|
+
*/
|
|
3586
|
+
setPaneTransportMirrorPort(port) {
|
|
3587
|
+
if (this.tui instanceof TuiProcess || this.tui instanceof HeadlessPaneManager)
|
|
3588
|
+
this.tui.setOwnerMirrorPort(port);
|
|
3557
3589
|
}
|
|
3558
3590
|
handleDictationEvent(event) {
|
|
3559
3591
|
if (event.source === 'replay') {
|
|
@@ -4124,6 +4156,7 @@ export class RatatuiApp {
|
|
|
4124
4156
|
this.assertStartupActive();
|
|
4125
4157
|
const actualPort = this.mirrorServer.getPort();
|
|
4126
4158
|
process.env.ZTC_MIRROR_PORT = String(actualPort);
|
|
4159
|
+
this.setPaneTransportMirrorPort(actualPort);
|
|
4127
4160
|
debugLog(`[Mirror] Server listening on port ${actualPort}`);
|
|
4128
4161
|
if (this.muxMode) {
|
|
4129
4162
|
this.mirrorServer.setMultiPaneMode(true, configStore.getModel(), configStore.getProvider());
|
|
@@ -4656,9 +4689,13 @@ export class RatatuiApp {
|
|
|
4656
4689
|
this.assertStartupActive();
|
|
4657
4690
|
if (this.launchConnectPromptWanted() && !this.composerHasDraft())
|
|
4658
4691
|
this.heldLaunchNotices = [];
|
|
4659
|
-
// A refusal an unattended run recorded holds this session's background work
|
|
4692
|
+
// A refusal an unattended run recorded holds this session's background work. The person's messages still try,
|
|
4693
|
+
// except what is relayed here (see takesRouterAttempt): in a ZTC pane all it reads, in a colony cell what its
|
|
4694
|
+
// terminal reads but not its browser mirror. The notice says which.
|
|
4695
|
+
const attempts = this.takesRouterAttempt(true, 'terminal') ? 'all'
|
|
4696
|
+
: this.mirror && this.takesRouterAttempt(true, 'browser') ? 'mirror' : 'none';
|
|
4660
4697
|
for (const hold of adoptRouterRefusalRecord('interactive'))
|
|
4661
|
-
this.showLaunchNotice(formatRecordedRouterRefusal(hold));
|
|
4698
|
+
this.showLaunchNotice(formatRecordedRouterRefusal(hold, attempts));
|
|
4662
4699
|
if (this.taskHandoff) {
|
|
4663
4700
|
this.showLaunchNotice(formatTaskHandoffNotice(this.taskHandoff.snapshot));
|
|
4664
4701
|
this.publishTaskHandoff(this.taskHandoff);
|
|
@@ -5186,7 +5223,9 @@ export class RatatuiApp {
|
|
|
5186
5223
|
const proc = spawn('npm', ['install', '-g', info.packageSpec], {
|
|
5187
5224
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
5188
5225
|
shell: true,
|
|
5189
|
-
|
|
5226
|
+
// Inherit the environment for PATH, without the mirror credentials this process holds: any program running as
|
|
5227
|
+
// this user can read the environment a process (npm, and the install scripts it runs) starts with.
|
|
5228
|
+
env: withoutMirrorCredentials(process.env),
|
|
5190
5229
|
});
|
|
5191
5230
|
let stdout = '';
|
|
5192
5231
|
let stderr = '';
|
|
@@ -6044,6 +6083,7 @@ export class RatatuiApp {
|
|
|
6044
6083
|
const created = this.waitForTuiEvent(event => event.type === 'error' || (event.type === 'pane_created' && event.request_id === requestId), 15000);
|
|
6045
6084
|
this.trackPendingPaneLaunch(requestId, spec);
|
|
6046
6085
|
this.trackPendingPaneReplacement(paneId, requestId);
|
|
6086
|
+
// The pane transport gives the resumed ZTC a mirror credential of its own, as for a new pane (PaneCredentialBroker).
|
|
6047
6087
|
const sent = this.tui.send({ type: 'replace_pane', pane_id: paneId, request_id: requestId,
|
|
6048
6088
|
command: child.command, args: this.headlessMirror ? child.args.filter(arg => arg !== '--pane') : child.args,
|
|
6049
6089
|
cwd: child.cwd, title: pane.title, pane_type: 'ztc' });
|
|
@@ -8582,8 +8622,14 @@ export class RatatuiApp {
|
|
|
8582
8622
|
*/
|
|
8583
8623
|
async handleBusMessage(msg) {
|
|
8584
8624
|
debugLog(`[Bus] Received: from=${msg.from.name} type=${msg.type} text=${msg.text.slice(0, 50)} paneMode=${this.paneMode} muxMode=${this.muxMode}`);
|
|
8625
|
+
// Question replies and structured control commands (a widget, ask_user or hook answer, a model or effort change)
|
|
8626
|
+
// come only from this pane's parent: the ZTC that runs the mirror, bus member 0, which relays the browser's answers
|
|
8627
|
+
// as its own. The mirror lets a pane send only as itself and a browser session only as the browser member, so
|
|
8628
|
+
// neither can forge one.
|
|
8629
|
+
const fromParent = msg.from.id === OVERSEER_BUS_MEMBER_ID;
|
|
8585
8630
|
if (msg.questionAnswer === true) {
|
|
8586
|
-
|
|
8631
|
+
if (fromParent)
|
|
8632
|
+
this.acceptChildAskUserAnswer(msg.text);
|
|
8587
8633
|
return;
|
|
8588
8634
|
}
|
|
8589
8635
|
const humanSimPane = process.env.ZTC_HUMAN_SIM_PANE === '1';
|
|
@@ -8604,15 +8650,22 @@ export class RatatuiApp {
|
|
|
8604
8650
|
approxTokens,
|
|
8605
8651
|
}));
|
|
8606
8652
|
}
|
|
8607
|
-
// Normal input. Only the person in the browser mirror speaks as "User"
|
|
8608
|
-
// the person, so its message never takes their attempt
|
|
8609
|
-
//
|
|
8653
|
+
// Normal input. Only the person in the browser mirror speaks as "User" (the mirror refuses that member to a ZTC
|
|
8654
|
+
// process or a pane); another pane or the coordinator is not the person, so its message never takes their attempt
|
|
8655
|
+
// past a Zerg Router refusal, and in a --pane child, which relays all it reads, neither does the browser's. What
|
|
8656
|
+
// /broadcast delivers on the bus speaks as User too, and keeps that attempt as before, but it is /broadcast's (see
|
|
8657
|
+
// handleSubmit's via and takesRouterAttempt).
|
|
8610
8658
|
const fromBrowser = msg.from.id === BROWSER_BUS_MEMBER_ID;
|
|
8611
8659
|
this.handleSubmit({ text: msg.text, attachments: msg.attachments || [] }, undefined, undefined, false, false, fromBrowser, msg.via === 'broadcast' ? 'broadcast' : fromBrowser ? 'browser' : 'terminal');
|
|
8612
8660
|
}
|
|
8613
8661
|
else if (msg.type === 'ztc_message') {
|
|
8614
8662
|
// Intercept structured control commands from parent (model hot-swap, widget answers).
|
|
8615
8663
|
if (msg.text.startsWith('{"__ztc_cmd":')) {
|
|
8664
|
+
if (!fromParent) {
|
|
8665
|
+
const sender = msg.from.id === BROWSER_BUS_MEMBER_ID ? 'the browser member' : `pane ${msg.from.id}`;
|
|
8666
|
+
this.addSystemMessage(`Ignored a pane control command from ${sender}: those come only from the ZTC that runs this workspace. No prompt was submitted.`);
|
|
8667
|
+
return;
|
|
8668
|
+
}
|
|
8616
8669
|
try {
|
|
8617
8670
|
const cmd = JSON.parse(msg.text);
|
|
8618
8671
|
if (cmd.__ztc_cmd === 'ask_user_answer') {
|
|
@@ -8754,29 +8807,65 @@ export class RatatuiApp {
|
|
|
8754
8807
|
/**
|
|
8755
8808
|
* Submit what the person entered themselves (typed, dictated, sent from the browser mirror, or given on the command
|
|
8756
8809
|
* line). It gets one real attempt even while a Zerg Router refusal holds the route, since they may have just raised
|
|
8757
|
-
* the limit
|
|
8758
|
-
*
|
|
8759
|
-
*
|
|
8810
|
+
* the limit, unless it is relayed here: what a ZTC pane or a colony cell reads from its terminal, which the
|
|
8811
|
+
* overseer's write_terminal_pane types into too, never gets it (see takesRouterAttempt). What the mirror's /broadcast
|
|
8812
|
+
* delivers comes here too and keeps that attempt, as it always has. `via`: where it was entered, this ZTC's terminal
|
|
8813
|
+
* (its keys, dictation, the command line), the browser mirror or /broadcast (see handleSubmit's `via`).
|
|
8760
8814
|
*/
|
|
8761
8815
|
submitPersonInput(rawInput, via = 'terminal') {
|
|
8762
8816
|
return this.handleSubmit(rawInput, undefined, undefined, false, false, true, via);
|
|
8763
8817
|
}
|
|
8818
|
+
/**
|
|
8819
|
+
* Submit what the mirror's input callback delivers. The browser's is the person's, and what /broadcast delivers keeps
|
|
8820
|
+
* the attempt it always had (submitPersonInput). What a ZTC process or a pane posts ('relayed': the mirror's
|
|
8821
|
+
* process-wide token or a pane's own credential) is never the person's: it runs as relayed input, so choices only the
|
|
8822
|
+
* person makes refuse it and it takes no attempt past a Zerg Router refusal.
|
|
8823
|
+
*/
|
|
8824
|
+
submitMirrorInput(input, via) {
|
|
8825
|
+
if (via === 'relayed')
|
|
8826
|
+
return this.handleSubmit(input, undefined, undefined, false, false, false, via);
|
|
8827
|
+
return this.submitPersonInput(input, via);
|
|
8828
|
+
}
|
|
8764
8829
|
/**
|
|
8765
8830
|
* Who entered input the queue holds for later, kept with its entry: handleSubmit's `person` and `via`. Each place
|
|
8766
8831
|
* that sends a queued entry passes them back (`entry.person === true`, `entry.via ?? 'terminal'`), so the person's
|
|
8767
|
-
* line runs as theirs and relayed input stays relayed.
|
|
8832
|
+
* line runs as theirs and relayed input stays relayed. A workspace pause keeps them the same way.
|
|
8768
8833
|
*/
|
|
8769
8834
|
queueOrigin(person, via) {
|
|
8770
8835
|
return person ? { person: true, ...(via === 'terminal' ? {} : { via }) } : {};
|
|
8771
8836
|
}
|
|
8837
|
+
/**
|
|
8838
|
+
* Whether what is entered from `via` is relayed here, whoever entered it, so a command in it makes none of the
|
|
8839
|
+
* person's choices. What a ZTC that another ZTC launched into one of its panes reads from its terminal is, whatever
|
|
8840
|
+
* its flags: a ZTC pane's ztc-tui, or a colony cell's own zmux, reads a PTY that the overseer's write_terminal_pane
|
|
8841
|
+
* and other panes type into too, so the person's typing there can't be told from theirs. A colony cell's own browser
|
|
8842
|
+
* mirror is still the person; everything a --pane child reads is relayed, its browser messages included. What a
|
|
8843
|
+
* mirror's /broadcast delivers is relayed in every ZTC, cell or not: only colony's send_to_worktree tool and its
|
|
8844
|
+
* dashboard post there.
|
|
8845
|
+
*/
|
|
8846
|
+
relayedHere(via) {
|
|
8847
|
+
return this.paneMode || via === 'broadcast' || (this.inAnotherZtcPane && via !== 'browser');
|
|
8848
|
+
}
|
|
8849
|
+
/**
|
|
8850
|
+
* Whether input takes the person's one real attempt past a Zerg Router refusal: they entered it (handleSubmit's
|
|
8851
|
+
* `person`) where it isn't relayed (see relayedHere), so nothing the overseer types into a ZTC pane or a colony cell
|
|
8852
|
+
* sends Router a request the refusal holds. What the mirror's /broadcast delivers keeps the attempt it always had,
|
|
8853
|
+
* relayed or not: the colony dashboard's send, which is the person, posts there.
|
|
8854
|
+
*/
|
|
8855
|
+
takesRouterAttempt(person, via) {
|
|
8856
|
+
return person && (via === 'broadcast' || !this.relayedHere(via));
|
|
8857
|
+
}
|
|
8772
8858
|
/**
|
|
8773
8859
|
* `person`: the person entered this input themselves (see submitPersonInput). A /loop tick, a goal continuation,
|
|
8774
8860
|
* another pane's or the coordinator's message and a pane's initial task never are, so none of them passes a Zerg
|
|
8775
8861
|
* Router refusal the process holds; a queued entry is whoever queued it (QueueEntry.person and QueueEntry.via, which
|
|
8776
8862
|
* the queue passes back here). `via`: where the person entered it, this ZTC's terminal or the
|
|
8777
8863
|
* browser mirror, or else the mirror's /broadcast, which only colony's AgentBridge posts to (the overseer's
|
|
8778
|
-
* send_to_worktree tool and the colony dashboard's send)
|
|
8779
|
-
*
|
|
8864
|
+
* send_to_worktree tool and the colony dashboard's send), or 'relayed', the mirror's routes posted by a ZTC process or
|
|
8865
|
+
* a pane, which is never the person's (submitMirrorInput). In a ZTC another ZTC launched into one of its panes, what
|
|
8866
|
+
* the terminal gives it isn't only the person's, and what /broadcast gives any ZTC never is (see relayedHere). What
|
|
8867
|
+
* is relayed here makes none of the person's choices and, unless /broadcast delivered it, passes no refusal either
|
|
8868
|
+
* (see takesRouterAttempt).
|
|
8780
8869
|
*/
|
|
8781
8870
|
async handleSubmit(rawInput, queuedEntryId, queuedAdmission, literalInput = false, credentialPrompted = false, person = false, via = 'terminal') {
|
|
8782
8871
|
if (this.exiting)
|
|
@@ -8882,14 +8971,12 @@ export class RatatuiApp {
|
|
|
8882
8971
|
this.reconcileQueueEdit();
|
|
8883
8972
|
}
|
|
8884
8973
|
// A command the person didn't enter themselves (another pane's or the coordinator's message, a pane's stdin,
|
|
8885
|
-
// a /loop tick) runs as relayed input, queued or not: choices only the person makes refuse it. So does
|
|
8886
|
-
//
|
|
8887
|
-
|
|
8888
|
-
//
|
|
8889
|
-
//
|
|
8890
|
-
|
|
8891
|
-
const relayedHere = this.paneMode || via === 'broadcast' || (this.inAnotherZtcPane && via !== 'browser');
|
|
8892
|
-
const origin = person && !relayedHere ? undefined : 'relayed';
|
|
8974
|
+
// a /loop tick) runs as relayed input, queued or not: choices only the person makes refuse it. So does one they
|
|
8975
|
+
// entered where input is relayed here, such as a ZTC pane's or a colony cell's terminal (see relayedHere).
|
|
8976
|
+
const origin = person && !this.relayedHere(via) ? undefined : 'relayed';
|
|
8977
|
+
// Such input passes no Zerg Router refusal either, unless /broadcast delivered it. A held entry keeps who entered
|
|
8978
|
+
// it and where, not this answer, which is worked out again when it is sent.
|
|
8979
|
+
const routerAttempt = this.takesRouterAttempt(person, via);
|
|
8893
8980
|
if (route.type === 'shell') {
|
|
8894
8981
|
this.mirror?.publishMessage('user', text);
|
|
8895
8982
|
await this.handleCommand('shell', [route.command], false, origin);
|
|
@@ -8909,7 +8996,7 @@ export class RatatuiApp {
|
|
|
8909
8996
|
}
|
|
8910
8997
|
if (!sendRoute.ready) {
|
|
8911
8998
|
if (!credentialPrompted && sendRoute.route
|
|
8912
|
-
&& this.askForSendCredential(sendRoute.route, input, queuedEntryId, literalInput, person))
|
|
8999
|
+
&& this.askForSendCredential(sendRoute.route, input, queuedEntryId, literalInput, person, via))
|
|
8913
9000
|
return;
|
|
8914
9001
|
this.controller.addMessage({
|
|
8915
9002
|
role: 'user',
|
|
@@ -8920,7 +9007,7 @@ export class RatatuiApp {
|
|
|
8920
9007
|
}
|
|
8921
9008
|
// Resolve local overlap while the full input is still unadmitted, before
|
|
8922
9009
|
// a busy classifier or any provider can receive the candidate source.
|
|
8923
|
-
if (!queuedEntryId && !await this.guardWorkspaceAdmission(input, undefined, undefined, undefined, person))
|
|
9010
|
+
if (!queuedEntryId && !await this.guardWorkspaceAdmission(input, undefined, undefined, undefined, this.queueOrigin(person, via)))
|
|
8924
9011
|
return;
|
|
8925
9012
|
// Enter during a run steers the current turn at its next tool boundary.
|
|
8926
9013
|
// Tab remains the explicit after-turn queue.
|
|
@@ -8929,7 +9016,7 @@ export class RatatuiApp {
|
|
|
8929
9016
|
const inputMode = state.inputMode;
|
|
8930
9017
|
if (busy) {
|
|
8931
9018
|
if (inputMode === 'steer') {
|
|
8932
|
-
await this.routeBusyInput(input,
|
|
9019
|
+
await this.routeBusyInput(input, routerAttempt);
|
|
8933
9020
|
return;
|
|
8934
9021
|
}
|
|
8935
9022
|
// Opt-in interruption retires the old owner before the replacement can
|
|
@@ -8986,8 +9073,9 @@ export class RatatuiApp {
|
|
|
8986
9073
|
// Publish user message to observer (with attachments so thumbnails survive a refresh).
|
|
8987
9074
|
this.mirror?.publishMessage('user', text, attachments.length > 0 ? { attachments } : undefined);
|
|
8988
9075
|
queuedAdmission?.onQueuedAdmission();
|
|
8989
|
-
// A message the person just entered gets one real attempt even while Zerg Router's refusal holds the route
|
|
8990
|
-
|
|
9076
|
+
// A message the person just entered gets one real attempt even while Zerg Router's refusal holds the route, unless
|
|
9077
|
+
// it was relayed here (see takesRouterAttempt).
|
|
9078
|
+
if (routerAttempt)
|
|
8991
9079
|
this.personMessagePending = true;
|
|
8992
9080
|
// Run the agent on current messages
|
|
8993
9081
|
await this.runAgent();
|
|
@@ -9191,16 +9279,17 @@ export class RatatuiApp {
|
|
|
9191
9279
|
* Ask for the API key a direct route is missing, then send `input` as typed.
|
|
9192
9280
|
* On cancel the text goes back to the composer. Only input typed in this
|
|
9193
9281
|
* terminal or its mirror asks: queued input and pane children keep the setup
|
|
9194
|
-
* message, and an open widget is never replaced.
|
|
9282
|
+
* message, and an open widget is never replaced. The send goes as whoever
|
|
9283
|
+
* entered it, from where (handleSubmit's `person` and `via`).
|
|
9195
9284
|
*/
|
|
9196
|
-
askForSendCredential(route, input, queuedEntryId, literalInput, person) {
|
|
9285
|
+
askForSendCredential(route, input, queuedEntryId, literalInput, person, via) {
|
|
9197
9286
|
if (queuedEntryId || this.paneMode || this.routingInteractionOccupied())
|
|
9198
9287
|
return false;
|
|
9199
9288
|
const ctx = this.buildCommandContext(message => this.controller.addMessage(message));
|
|
9200
9289
|
return promptForMissingDirectKey(route, ctx, async () => {
|
|
9201
9290
|
// A live agent was built without this key; the send builds a fresh one.
|
|
9202
9291
|
this.reloadAgentInPlace(true);
|
|
9203
|
-
await this.handleSubmit(input, undefined, undefined, literalInput, true, person);
|
|
9292
|
+
await this.handleSubmit(input, undefined, undefined, literalInput, true, person, via);
|
|
9204
9293
|
}, {
|
|
9205
9294
|
onCancel: () => {
|
|
9206
9295
|
this.restoreBusyDraft(input);
|
|
@@ -9233,13 +9322,14 @@ export class RatatuiApp {
|
|
|
9233
9322
|
return pending;
|
|
9234
9323
|
}
|
|
9235
9324
|
/**
|
|
9236
|
-
* Only accepted-but-unadmitted sources belong to this local pause. `
|
|
9237
|
-
* continue sends it
|
|
9325
|
+
* Only accepted-but-unadmitted sources belong to this local pause. `origin`: who entered it and where (see
|
|
9326
|
+
* queueOrigin), which /sessions continue sends it with, so the person's message keeps its one real attempt past a
|
|
9327
|
+
* Zerg Router refusal where it had one (see takesRouterAttempt).
|
|
9238
9328
|
*/
|
|
9239
|
-
retainWorkspaceInput(input,
|
|
9329
|
+
retainWorkspaceInput(input, origin) {
|
|
9240
9330
|
this.workspacePendingInputs.push({
|
|
9241
9331
|
input: { ...input, attachments: input.attachments.map(attachment => ({ ...attachment })) },
|
|
9242
|
-
|
|
9332
|
+
origin,
|
|
9243
9333
|
});
|
|
9244
9334
|
this.restoreBusyDraft(input);
|
|
9245
9335
|
}
|
|
@@ -9290,21 +9380,24 @@ export class RatatuiApp {
|
|
|
9290
9380
|
ownedIds.push(id);
|
|
9291
9381
|
});
|
|
9292
9382
|
}
|
|
9293
|
-
async pauseWorkspace(snapshot, input, cancelled = false, queuedEntryId, effectCwd,
|
|
9383
|
+
async pauseWorkspace(snapshot, input, cancelled = false, queuedEntryId, effectCwd, origin = {}) {
|
|
9294
9384
|
this.workspacePaused = true;
|
|
9295
9385
|
this.workspacePausedSnapshot = snapshot;
|
|
9296
9386
|
this.workspacePausedEffectCwd = effectCwd ?? null;
|
|
9297
9387
|
this.workspacePausedQueueId = queuedEntryId ?? null;
|
|
9298
9388
|
await this.localWorkspace().setActivity('paused');
|
|
9299
9389
|
if (input && !queuedEntryId && !this.exiting)
|
|
9300
|
-
this.retainWorkspaceInput(input,
|
|
9390
|
+
this.retainWorkspaceInput(input, origin);
|
|
9301
9391
|
if (!this.exiting)
|
|
9302
9392
|
this.addSystemMessage(cancelled
|
|
9303
9393
|
? 'Workspace decision cancelled. Input retained. Use /sessions continue when ready.'
|
|
9304
9394
|
: 'This session is paused. Prompt, attachments and queued work are retained. Use /sessions continue when ready.');
|
|
9305
9395
|
}
|
|
9306
|
-
/**
|
|
9307
|
-
|
|
9396
|
+
/**
|
|
9397
|
+
* `origin`: who entered `input` and where (see queueOrigin), which a pause keeps with it (see
|
|
9398
|
+
* retainWorkspaceInput).
|
|
9399
|
+
*/
|
|
9400
|
+
async guardWorkspaceAdmission(input, signal, cwd, queuedEntryId, origin = {}) {
|
|
9308
9401
|
if (this.isHostedRuntime())
|
|
9309
9402
|
return !this.exiting && !signal?.aborted;
|
|
9310
9403
|
const epoch = this.workspaceEpoch;
|
|
@@ -9321,7 +9414,7 @@ export class RatatuiApp {
|
|
|
9321
9414
|
}
|
|
9322
9415
|
if (this.workspacePaused) {
|
|
9323
9416
|
if (input && !queuedEntryId) {
|
|
9324
|
-
this.retainWorkspaceInput(input,
|
|
9417
|
+
this.retainWorkspaceInput(input, origin);
|
|
9325
9418
|
// Enter once did nothing visible here: the prompt went back into the composer silently (2026-10-27).
|
|
9326
9419
|
if (!this.exiting)
|
|
9327
9420
|
this.addSystemMessage('This session is paused for a workspace overlap. Your message is kept; run /sessions continue to send it.');
|
|
@@ -9366,7 +9459,7 @@ export class RatatuiApp {
|
|
|
9366
9459
|
coordinator.acknowledge(latest);
|
|
9367
9460
|
return true;
|
|
9368
9461
|
}
|
|
9369
|
-
await this.pauseWorkspace(snapshot, input, choice === null, queuedEntryId, cwd,
|
|
9462
|
+
await this.pauseWorkspace(snapshot, input, choice === null, queuedEntryId, cwd, origin);
|
|
9370
9463
|
if (choice === 'isolate')
|
|
9371
9464
|
await this.isolateWorkspace();
|
|
9372
9465
|
return false;
|
|
@@ -9378,7 +9471,7 @@ export class RatatuiApp {
|
|
|
9378
9471
|
if (queuedEntryId)
|
|
9379
9472
|
this.workspacePausedQueueId = queuedEntryId;
|
|
9380
9473
|
if (input && !queuedEntryId)
|
|
9381
|
-
this.retainWorkspaceInput(input,
|
|
9474
|
+
this.retainWorkspaceInput(input, origin);
|
|
9382
9475
|
this.addErrorMessage(`Workspace admission failed. Input retained: ${String(error)}`);
|
|
9383
9476
|
}
|
|
9384
9477
|
return false;
|
|
@@ -9467,8 +9560,9 @@ export class RatatuiApp {
|
|
|
9467
9560
|
}
|
|
9468
9561
|
if (getPlainText(this.inputState.segments) === entry.input.text)
|
|
9469
9562
|
this.setInputToText('', 0);
|
|
9470
|
-
//
|
|
9471
|
-
|
|
9563
|
+
// Sent as whoever entered it, from where: what the person typed is still theirs, with its one real attempt past
|
|
9564
|
+
// a Zerg Router refusal where it had one (see takesRouterAttempt).
|
|
9565
|
+
await this.handleSubmit(entry.input, undefined, undefined, false, false, entry.origin.person === true, entry.origin.via ?? 'terminal');
|
|
9472
9566
|
}
|
|
9473
9567
|
if (deferred && retained.length === 0 && !this.exiting) {
|
|
9474
9568
|
this.pendingAgentTurn = true;
|
|
@@ -9542,8 +9636,11 @@ export class RatatuiApp {
|
|
|
9542
9636
|
this.addErrorMessage(`Isolation did not launch. Original workspace and pending input are retained: ${String(error)}${retainedTarget ? `\nRetained target: ${retainedTarget}` : ''}`);
|
|
9543
9637
|
}
|
|
9544
9638
|
}
|
|
9545
|
-
/**
|
|
9546
|
-
|
|
9639
|
+
/**
|
|
9640
|
+
* Classify independently; admission decisions retain submission FIFO. `routerAttempt`: the input takes the person's
|
|
9641
|
+
* one real attempt past a Zerg Router refusal (see takesRouterAttempt), which it carries as steering.
|
|
9642
|
+
*/
|
|
9643
|
+
async routeBusyInput(rawInput, routerAttempt = false) {
|
|
9547
9644
|
const input = { ...rawInput, attachments: rawInput.attachments.map(attachment => ({ ...attachment })) };
|
|
9548
9645
|
if (this.busyInputControllers.size >= MAX_QUEUE) {
|
|
9549
9646
|
this.restoreBusyDraft(input);
|
|
@@ -9652,7 +9749,7 @@ export class RatatuiApp {
|
|
|
9652
9749
|
this.restoreBusyDraft(input);
|
|
9653
9750
|
return;
|
|
9654
9751
|
}
|
|
9655
|
-
await this.admitBusySteering(input, epoch, undefined,
|
|
9752
|
+
await this.admitBusySteering(input, epoch, undefined, routerAttempt);
|
|
9656
9753
|
}).catch(error => {
|
|
9657
9754
|
if (!this.exiting) {
|
|
9658
9755
|
this.restoreBusyDraft(input);
|
|
@@ -9730,7 +9827,11 @@ export class RatatuiApp {
|
|
|
9730
9827
|
}
|
|
9731
9828
|
this.render();
|
|
9732
9829
|
}
|
|
9733
|
-
|
|
9830
|
+
/**
|
|
9831
|
+
* `routerAttempt`: the steering takes the person's one real attempt past a Zerg Router refusal (see
|
|
9832
|
+
* takesRouterAttempt).
|
|
9833
|
+
*/
|
|
9834
|
+
async admitBusySteering(input, epoch, queuedSource, routerAttempt = false) {
|
|
9734
9835
|
const { text, attachments } = input;
|
|
9735
9836
|
if (queuedSource) {
|
|
9736
9837
|
const stillQueued = this.controller.getQueue().find(entry => entry.id === queuedSource.entry.id);
|
|
@@ -9793,7 +9894,7 @@ export class RatatuiApp {
|
|
|
9793
9894
|
if (queuedSource)
|
|
9794
9895
|
this.controller.removeQueueEntry(queuedSource.entry.id);
|
|
9795
9896
|
this.pendingSteering.push(message);
|
|
9796
|
-
if (
|
|
9897
|
+
if (routerAttempt)
|
|
9797
9898
|
this.personSteeringIds.add(message.id);
|
|
9798
9899
|
if (this.agent) {
|
|
9799
9900
|
const activeAgent = this.agent;
|
|
@@ -11084,7 +11185,10 @@ export class RatatuiApp {
|
|
|
11084
11185
|
this.mirror?.publishMessage('user', message.content, message.attachments?.length ? { attachments: message.attachments } : undefined);
|
|
11085
11186
|
}
|
|
11086
11187
|
}
|
|
11087
|
-
/**
|
|
11188
|
+
/**
|
|
11189
|
+
* MESSAGES now go to the agent: when one is steering that takes the person's attempt (see personSteeringIds), the
|
|
11190
|
+
* request that carries it is theirs.
|
|
11191
|
+
*/
|
|
11088
11192
|
admitPersonSteering(messages) {
|
|
11089
11193
|
let person = false;
|
|
11090
11194
|
for (const message of messages)
|
|
@@ -13365,6 +13469,7 @@ export class RatatuiApp {
|
|
|
13365
13469
|
}
|
|
13366
13470
|
}
|
|
13367
13471
|
}
|
|
13472
|
+
/** What a ZTC pane needs to join this workspace; its mirror credential is its own (see pane.ts childZtcPaneEnv). */
|
|
13368
13473
|
childZtcPaneEnv() {
|
|
13369
13474
|
const env = {
|
|
13370
13475
|
ZTC_PARENT_PID: String(process.pid),
|
|
@@ -13372,9 +13477,6 @@ export class RatatuiApp {
|
|
|
13372
13477
|
if (process.env.ZTC_MIRROR_PORT) {
|
|
13373
13478
|
env.ZTC_MIRROR_PORT = process.env.ZTC_MIRROR_PORT;
|
|
13374
13479
|
}
|
|
13375
|
-
if (process.env.ZTC_MIRROR_INTERNAL_TOKEN) {
|
|
13376
|
-
env.ZTC_MIRROR_INTERNAL_TOKEN = process.env.ZTC_MIRROR_INTERNAL_TOKEN;
|
|
13377
|
-
}
|
|
13378
13480
|
if (process.env.ZTC_PANE_RELAY) {
|
|
13379
13481
|
env.ZTC_PANE_RELAY = process.env.ZTC_PANE_RELAY;
|
|
13380
13482
|
}
|
|
@@ -14064,6 +14166,9 @@ export class RatatuiApp {
|
|
|
14064
14166
|
// as the only resume target.
|
|
14065
14167
|
const spawnCwd = existsSync(options.cwd) ? options.cwd : process.cwd();
|
|
14066
14168
|
const { command, args, shell } = buildHotRestartLaunch(withActiveProfileArg(process.argv.slice(1)), options.sessionId, process.execPath, spawnCwd);
|
|
14169
|
+
// A pane's ZTC hands its mirror credential to the ZTC that takes its place in a fresh one-time file, never in the
|
|
14170
|
+
// environment that ZTC starts with (see pane_credentials.ts).
|
|
14171
|
+
args.push(...paneCredentialRelaunchArgs());
|
|
14067
14172
|
debugLog(`[${options.label}] Spawning new process: ${command} ${args.join(' ')} (cwd=${spawnCwd})`);
|
|
14068
14173
|
// Keep the foreground job alive. Spawning and exiting lets the shell
|
|
14069
14174
|
// reclaim the terminal, so the orphaned renderer fails with raw-mode EIO.
|