@zergai/ztc 0.25.0-beta.1 → 0.26.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +70 -0
  2. package/bin/zmux-darwin-arm64 +0 -0
  3. package/bin/ztc-audio-darwin-arm64 +0 -0
  4. package/bin/ztc-capture-darwin-arm64 +0 -0
  5. package/bin/ztc-tui-darwin-arm64 +0 -0
  6. package/bin/zterm-darwin-arm64 +2 -2
  7. package/dist/app/emergency_exit.d.ts +14 -0
  8. package/dist/app/emergency_exit.js +36 -0
  9. package/dist/app/layout_change.d.ts +20 -0
  10. package/dist/app/layout_change.js +14 -0
  11. package/dist/app/workspace_topology.d.ts +8 -0
  12. package/dist/app/workspace_topology.js +8 -0
  13. package/dist/cli_main.js +2 -24
  14. package/dist/cli_ratatui.d.ts +70 -1
  15. package/dist/cli_ratatui.js +259 -53
  16. package/dist/desktop/daily/status_restore.js +6 -2
  17. package/dist/mcp/workspace_server.js +9 -2
  18. package/dist/ui/core/input_segments.d.ts +15 -0
  19. package/dist/ui/core/input_segments.js +22 -0
  20. package/dist/ui/core/layout_yoga.d.ts +7 -0
  21. package/dist/ui/core/layout_yoga.js +16 -0
  22. package/dist/ui/ratatui/owner_ping.d.ts +24 -0
  23. package/dist/ui/ratatui/owner_ping.js +18 -0
  24. package/dist/ui/ratatui/process.d.ts +2 -2
  25. package/dist/ui/ratatui/protocol.d.ts +80 -3
  26. package/dist/ui/ratatui/protocol.js +58 -0
  27. package/dist/ui/scrollback.d.ts +24 -0
  28. package/dist/ui/scrollback.js +53 -18
  29. package/dist/ui/terminal_image.js +17 -1
  30. package/dist/ui/transcript_bound.d.ts +41 -0
  31. package/dist/ui/transcript_bound.js +100 -0
  32. package/dist/ui/transcript_render_cache.d.ts +15 -4
  33. package/dist/ui/transcript_render_cache.js +39 -16
  34. package/dist/ui/views/app.js +3 -2
  35. package/dist/ui/views/input_area.d.ts +1 -0
  36. package/dist/ui/views/input_area.js +34 -8
  37. package/dist/zlm-embed.mjs +1 -1
  38. package/package.json +17 -9
package/README.md CHANGED
@@ -318,6 +318,76 @@ hears what closed and what stayed. A program in a pane can't send
318
318
  by one, and the tab with the last of them, without the sheet. The saved
319
319
  workspace drops a closed tab at once.
320
320
 
321
+ #### Arranging panes and tabs
322
+
323
+ When panes move, from ZTC's workspace presets, a delegated worker or the
324
+ browser mirror, the desktop app tells ZTC what moved (`layout_changed`) and
325
+ ZTC saves the workspace a quarter of a second later, the order of the tabs
326
+ with it, so resuming the session (`ztc resume`, `/resume` in Main, or the
327
+ restart an update does) brings back the tabs as they were arranged. Quitting
328
+ and reopening the desktop app starts a new session, with the default layout.
329
+ A move that empties a tab closes it, a move that can't be finished changes
330
+ nothing, and Main always stays in a tab.
331
+
332
+ Arrange the tabs yourself: drag a tab along the strip, past 10 points, and let
333
+ go where the bar marks the gap (Esc cancels); on macOS press ⌥⇧⌘[ or ⌥⇧⌘] to
334
+ move the tab in front one place left or right, wrapping at the ends; or use
335
+ **Move Tab Left**, **Move Tab Right**, **Move Tab to Start** and **Move Tab to
336
+ End** in a tab's menu, which is the way on Linux and Windows until those keys
337
+ get their chords there. ⌘1 to ⌘9 and every tab's number follow the new order,
338
+ ZTC saves it a quarter of a second later, and Claude Code and Codex panes
339
+ asking for the workspace's panes hear each tab numbered as the strip numbers
340
+ it. A screen reader names each tab by its place ("Tab 2 of 5: Claude Code ·
341
+ workers"), says where each pane sits in its tab, and hears what each move did.
342
+
343
+ Arrange the panes the same way: drag a pane by its title row (or, on macOS,
344
+ with ⌘⌥⇧ from anywhere in it) onto a half of another pane to put it there,
345
+ rest in a pane's middle to swap them, let go between two tabs, in the strip's
346
+ empty space past the last tab or on `+` for a new tab, or rest on a tab to drop
347
+ into it; Esc cancels. On macOS ⌥⇧⌘←, →, ↑
348
+ and ↓ trade the focused pane with its neighbour that way. A click on the dot at
349
+ the left of a pane's title row (six dots while the pointer is on the row), a
350
+ right-click or ⌃-click on the row, or ⌥⇧⌘M on macOS opens the pane's menu,
351
+ which does the same from the keyboard: **Move Pane to Split Pane…** (the pane
352
+ turns green and your next click places it), **Put Beside…** any side of any
353
+ pane, **Swap With Pane…**, **Move Left** / **Right** / **Up** / **Down**,
354
+ another tab or a **New Tab**. On Linux and Windows the swap keys and the menu's
355
+ key start unbound for now; the menu, from the grip or a right-click on the
356
+ title row, does what they do. To keep title rows from dragging, untick **Drag
357
+ panes by their title** in any tab's menu; ⌘⌥⇧ and the menus still move panes.
358
+ A plain ⌘-click on a link still opens it. A screen reader finds each pane's
359
+ "Pane menu" button and hears every move.
360
+
361
+ #### Links in ZTC panes
362
+
363
+ ⌘-click a URL in Main, or in any ZTC pane, to open it in your browser, as in a
364
+ terminal pane: with ⌘ held the URL under the pointer is underlined and the
365
+ pointer is a hand. The punctuation of the sentence around it is left off (the
366
+ comma after the Router key error's Credentials link, say), and a URL too long
367
+ for its row in ZTC's own text opens whole from any row it was broken over.
368
+ Inside a code block or a table, a URL that runs into the frame's border or fills
369
+ its cell may go on past it, so it opens nothing; one short of the border opens.
370
+ A plain click still focuses the pane and selects.
371
+
372
+ #### When ZTC stops or hangs
373
+
374
+ The desktop app is every pane's parent, so its panes keep running without ZTC.
375
+ When ZTC leaves without quitting (an uncaught exception or an unhandled
376
+ rejection, after which ZTC saves the session and leaves the window running, a
377
+ SIGKILL, running out of memory or a native crash), the window and every pane
378
+ stay under a banner, "ZTC (the agent runtime) stopped. Your panes keep
379
+ running.", with **Wait** (hides it), **Copy diagnostics** and **Quit (ends
380
+ panes)**. ZTC pings the desktop app every 2 seconds from its own event loop, so
381
+ when it hangs, the app notices within about 10 seconds (or once it has read
382
+ nothing the app wrote for 30 seconds) and shows "ZTC (the agent runtime) isn't
383
+ responding. Your panes keep running." with **End ZTC (keeps panes)** as well:
384
+ ZTerm closes its side of the connection, sends ZTC SIGTERM and, 3 seconds
385
+ later, SIGKILL, and keeps the panes. **Wait** hides that banner for 10 seconds.
386
+ A quit still closes the window and every pane: Ctrl+C on an empty composer,
387
+ `/exit`, closing the window or a SIGTERM to ZTC. Nothing reconnects a new ZTC
388
+ to panes left running this way yet; they keep running until you quit the
389
+ window.
390
+
321
391
  #### Native tool panes
322
392
 
323
393
  In `ztc --desktop`, open the new-pane menu (Ctrl+Cmd+N at the focused pane, or
Binary file
Binary file
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/bin/zterm-darwin-arm64
3
- size: 34075648 bytes
4
- sha256: f990a9b9cec71f37ec9f69e3b2a5eb325678a209aace10490775a799d4fce81f
3
+ size: 35030144 bytes
4
+ sha256: fd669957a62c8525667a6cc80ff91730c6568eb6b16e6489e109b6c1adb1bd95
@@ -0,0 +1,14 @@
1
+ /** What the emergency handlers need of the app they end: RatatuiApp's emergency exit and its exit after a crash. */
2
+ export interface EmergencyExitApp {
3
+ emergencyExit(): Promise<void>;
4
+ crashExit(): Promise<void>;
5
+ }
6
+ /**
7
+ * The handlers that end ZTC when something other than its own quit does. cli_main.ts installs them on the RatatuiApp it
8
+ * runs, before starting it, and the first to run is the only one. SIGTERM, SIGHUP and SIGQUIT take the app's emergency
9
+ * exit, which saves the session and stops the renderer, giving the terminal back (mouse capture, raw mode) or, in the
10
+ * desktop app, telling ZTerm it is a quit. An uncaught exception or an unhandled rejection takes its exit after a crash,
11
+ * which saves the session too but leaves a desktop renderer running, so ZTerm keeps its panes (RatatuiApp.crashExit).
12
+ * Either way the process then exits 1. SIGINT is already handled inside RatatuiApp; SIGKILL cannot be caught.
13
+ */
14
+ export declare function installEmergencyHandlers(app: EmergencyExitApp): void;
@@ -0,0 +1,36 @@
1
+ import { debugLog } from '../utils/debug_log.js';
2
+ /**
3
+ * The handlers that end ZTC when something other than its own quit does. cli_main.ts installs them on the RatatuiApp it
4
+ * runs, before starting it, and the first to run is the only one. SIGTERM, SIGHUP and SIGQUIT take the app's emergency
5
+ * exit, which saves the session and stops the renderer, giving the terminal back (mouse capture, raw mode) or, in the
6
+ * desktop app, telling ZTerm it is a quit. An uncaught exception or an unhandled rejection takes its exit after a crash,
7
+ * which saves the session too but leaves a desktop renderer running, so ZTerm keeps its panes (RatatuiApp.crashExit).
8
+ * Either way the process then exits 1. SIGINT is already handled inside RatatuiApp; SIGKILL cannot be caught.
9
+ */
10
+ export function installEmergencyHandlers(app) {
11
+ let cleanupRan = false;
12
+ const leave = async (how) => {
13
+ if (cleanupRan)
14
+ return;
15
+ cleanupRan = true;
16
+ try {
17
+ await (how === 'crash' ? app.crashExit() : app.emergencyExit());
18
+ }
19
+ catch { /* best effort */ }
20
+ process.exit(1);
21
+ };
22
+ const emergencyCleanup = () => leave('signal');
23
+ process.on('SIGTERM', emergencyCleanup);
24
+ // SIGHUP = controlling terminal closed / parent died — the classic "killed from
25
+ // outside" that left the host shell stranded with raw mode + mouse capture on.
26
+ process.on('SIGHUP', emergencyCleanup);
27
+ process.on('SIGQUIT', emergencyCleanup);
28
+ process.on('uncaughtException', (err) => {
29
+ debugLog(`[main] uncaughtException: ${err}`);
30
+ void leave('crash');
31
+ });
32
+ process.on('unhandledRejection', (reason) => {
33
+ debugLog(`[main] unhandledRejection: ${reason}`);
34
+ void leave('crash');
35
+ });
36
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * What ZTC does when the desktop app reports a move with layout_changed (pane-drag-drop spec §7.4): the person or the
3
+ * owner arranged the live workspace, so ZTC saves it soon, and a startup layout it kept after a refused restore no longer
4
+ * stands for it. Pure: the TUI applies the effects.
5
+ */
6
+ import type { LayoutChangedEvent } from '../ui/ratatui/protocol.js';
7
+ /** How long after a move ZTC saves the workspace: a burst of moves, as the presets send, makes one save. */
8
+ export declare const LAYOUT_SAVE_DELAY_MS = 250;
9
+ export interface LayoutChangeEffects {
10
+ /** Drop the startup layout ZTC kept after a refused restore: the live workspace is the one to save now. */
11
+ dropRetainedStartupLayout: boolean;
12
+ /** Save the workspace this many milliseconds from now, debounced with every other save; null: no save. */
13
+ saveAfterMs: number | null;
14
+ /** A line for the debug log, for a move that changed nothing. */
15
+ debug: string | null;
16
+ }
17
+ /** The effects of EVENT, given whether a native restore is under way. */
18
+ export declare function layoutChangeEffects(event: LayoutChangedEvent, context: {
19
+ nativeRestorePending: boolean;
20
+ }): LayoutChangeEffects;
@@ -0,0 +1,14 @@
1
+ /** How long after a move ZTC saves the workspace: a burst of moves, as the presets send, makes one save. */
2
+ export const LAYOUT_SAVE_DELAY_MS = 250;
3
+ /** The effects of EVENT, given whether a native restore is under way. */
4
+ export function layoutChangeEffects(event, context) {
5
+ if (event.outcome === 'changed') {
6
+ // A restore under way keeps what it retained; the save waits on it as every save does.
7
+ return { dropRetainedStartupLayout: !context.nativeRestorePending, saveAfterMs: LAYOUT_SAVE_DELAY_MS, debug: null };
8
+ }
9
+ return {
10
+ dropRetainedStartupLayout: false,
11
+ saveAfterMs: null,
12
+ debug: `[layout] ${event.outcome}${event.message === undefined ? '' : `: ${event.message}`}`,
13
+ };
14
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * What a saved workspace is made of, as one comparable key (pane-drag-drop spec §7.4): its tabs with each one's layout
3
+ * shape, and each pane's tab. ZTC keeps a startup layout it couldn't restore only while the live workspace still has the
4
+ * topology it had then; once the person or the owner arranges it, the live layout is the one to save.
5
+ */
6
+ import type { MuxSessionState } from '../ui/ratatui/protocol.js';
7
+ /** STATE's topology, as a string two states share exactly when their topologies are equal. */
8
+ export declare function workspacePaneTopology(state: MuxSessionState): string;
@@ -0,0 +1,8 @@
1
+ /** STATE's topology, as a string two states share exactly when their topologies are equal. */
2
+ export function workspacePaneTopology(state) {
3
+ const layout = (node) => node.type === 'leaf' ? node.pane_id : [node.direction, layout(node.first), layout(node.second)];
4
+ // The tabs as the strip runs, which is the order of the saved windows; the panes by id.
5
+ return JSON.stringify({ windows: state.windows
6
+ ? state.windows.map(window => [window.id, layout(window.layout)])
7
+ : [[0, layout(state.layout)]], panes: state.panes.map(pane => [pane.id, pane.window_id ?? 0]).sort((a, b) => a[0] - b[0]) });
8
+ }
package/dist/cli_main.js CHANGED
@@ -29,6 +29,7 @@ import { getProviderForModel, isModelAvailableForProvider, resolveModelAndProvid
29
29
  import { computeHeadlessMirror } from './panes/headless_mode.js';
30
30
  import { parsePromptInvocation, requiresPlanSafeRenderer, validateCliArgs, } from './cli_args.js';
31
31
  import { parseHeadlessInteractionMode } from './app/headless_interaction.js';
32
+ import { installEmergencyHandlers } from './app/emergency_exit.js';
32
33
  import { buildCliCommonStarts } from './onboarding/first_run.js';
33
34
  import { validateProfileName } from './config/profiles.js';
34
35
  import { loadDesktopRuntime } from './desktop/runtime.js';
@@ -1726,30 +1727,7 @@ async function main() {
1726
1727
  });
1727
1728
  // Ensure terminal cleanup (mouse capture, raw mode) on abnormal exit.
1728
1729
  // SIGINT is already handled inside RatatuiApp; SIGKILL cannot be caught.
1729
- let cleanupRan = false;
1730
- const emergencyCleanup = async () => {
1731
- if (cleanupRan)
1732
- return;
1733
- cleanupRan = true;
1734
- try {
1735
- await app.emergencyExit();
1736
- }
1737
- catch { /* best effort */ }
1738
- process.exit(1);
1739
- };
1740
- process.on('SIGTERM', emergencyCleanup);
1741
- // SIGHUP = controlling terminal closed / parent died — the classic "killed from
1742
- // outside" that left the host shell stranded with raw mode + mouse capture on.
1743
- process.on('SIGHUP', emergencyCleanup);
1744
- process.on('SIGQUIT', emergencyCleanup);
1745
- process.on('uncaughtException', (err) => {
1746
- debugLog(`[main] uncaughtException: ${err}`);
1747
- void emergencyCleanup();
1748
- });
1749
- process.on('unhandledRejection', (reason) => {
1750
- debugLog(`[main] unhandledRejection: ${reason}`);
1751
- void emergencyCleanup();
1752
- });
1730
+ installEmergencyHandlers(app);
1753
1731
  // A stopped TUI is the freeze users cannot escape: the process still holds the
1754
1732
  // terminal, ignores further keys, and — because a stopped process defers
1755
1733
  // SIGTERM until it is continued — cannot even be killed by closing the shell.
@@ -469,9 +469,39 @@ export declare class RatatuiApp {
469
469
  /** Fingerprint of the last transcript actually shipped, so an idle rebuild
470
470
  * (identical content) skips re-serialising and re-sending the whole buffer. */
471
471
  private transcriptShipped;
472
- /** Rows of the transcript last built for zmux: a compact select sits right under them (see render). */
472
+ /** Rows of the transcript last shipped to zmux: a compact select sits right under them (see render). */
473
473
  private transcriptRows;
474
+ /**
475
+ * The most bytes of transcript one command line carries (ui/transcript_bound.ts). A renderer that refuses a
476
+ * transcript as too long halves it, down to MIN_TRANSCRIPT_LINE_BUDGET; a new renderer starts it again.
477
+ */
478
+ private transcriptLineBudget;
479
+ /** The last transcript command shipped, to tell a too_long refusal of it by its size. */
480
+ private transcriptCommand;
481
+ /** The renderer's too_long refusals of a transcript, and whether one came at the smallest budget. */
482
+ private transcriptRefusals;
483
+ private transcriptRefusedAtFloor;
484
+ /** Whether the person was told of a too_long refusal of a command other than the transcript. */
485
+ private commandRefusalTold;
486
+ /** The render frames sent last, newest last, to tell a too_long refusal of one by its size. */
487
+ private readonly recentRenders;
488
+ /** Whether the person was told this renderer refused a render frame. */
489
+ private renderRefusalTold;
490
+ /** How many render frames are kept to tell a refusal of one: as many as reach the renderer before its answer. */
491
+ private static RECENT_RENDERS;
492
+ /** A draft at least this large is named, with how to clear it, when a render frame is refused. */
493
+ private static COMPOSER_DRAFT_NOTICE_BYTES;
474
494
  private static TRANSCRIPT_REBUILD_THROTTLE_MS;
495
+ /**
496
+ * How long a width that keeps changing must hold still before the transcript is rebuilt for it (LS3). ZTerm sends a
497
+ * resize each frame a window edge or a split is dragged, and every width renders the shipped rows again.
498
+ */
499
+ private static TRANSCRIPT_WIDTH_SETTLE_MS;
500
+ /** When the width last changed, and when the last rebuild ended. */
501
+ private transcriptWidthChangedAt;
502
+ private transcriptRebuiltAt;
503
+ /** Until when a rebuild for a width still changing waits (0 when none does). */
504
+ private transcriptWidthSettlesAt;
475
505
  private desktopMode;
476
506
  private desktopRuntime;
477
507
  private childPaneIds;
@@ -548,6 +578,8 @@ export declare class RatatuiApp {
548
578
  private stopFollowingConfig;
549
579
  /** Stops refreshConnectedState from following a ZergAI login's wait. */
550
580
  private stopFollowingLogin;
581
+ /** Stops the pings that tell a desktop renderer this process's event loop still runs (owner_ping.ts). */
582
+ private stopOwnerPing;
551
583
  /** The connection snapshot last given to which mirror server, as JSON. */
552
584
  private publishedConnection;
553
585
  private intakeNotifications;
@@ -1160,6 +1192,14 @@ export declare class RatatuiApp {
1160
1192
  * (controller.addMessage, stream_delta, batch update, recap insert).
1161
1193
  */
1162
1194
  private markTranscriptDirty;
1195
+ private runTranscriptRebuildTimer;
1196
+ /**
1197
+ * The transcript's width changed (LS3). The first change after a quiet spell is rebuilt at once, as a single resize
1198
+ * should be. One that comes while the change before it, or the rebuild that ended last, is more recent than
1199
+ * TRANSCRIPT_WIDTH_SETTLE_MS waits until the width has held still that long, so a drag through 20 widths rebuilds the
1200
+ * transcript twice rather than 20 times, and resizes queued behind a slow rebuild are not each rebuilt in turn.
1201
+ */
1202
+ private noteTranscriptWidthChange;
1163
1203
  /**
1164
1204
  * Flush a pending rebuild synchronously when the throttle window has
1165
1205
  * elapsed (i.e. the rebuild WOULD fire on the next tick anyway). Used
@@ -1197,6 +1237,17 @@ export declare class RatatuiApp {
1197
1237
  * survives resize re-emit.
1198
1238
  */
1199
1239
  private rebuildTranscript;
1240
+ /**
1241
+ * The renderer dropped a command line over its cap (RZ1, RX1: `too_long`, naming the line's bytes). ZTC bounds what
1242
+ * it ships so this never comes; if it does, it is never let go silently, nor answered by shipping the same line
1243
+ * forever. A refused transcript ships again at half the size, at most every time a refusal halves the budget down to
1244
+ * MIN_TRANSCRIPT_LINE_BUDGET, and after that only as it changes; the transcript says so once each way.
1245
+ */
1246
+ private handleCommandRefusedTooLong;
1247
+ /** Whether one of the render frames sent last was `bytes` long as the renderer read it, newest first. */
1248
+ private isRecentRender;
1249
+ /** The bytes of the composer's draft: its text and pastes. */
1250
+ private composerDraftBytes;
1200
1251
  /**
1201
1252
  * Get a human-readable verb for a tool name (for spinner/status display)
1202
1253
  */
@@ -1905,8 +1956,26 @@ export declare class RatatuiApp {
1905
1956
  private stopBackgroundPoll;
1906
1957
  private prepareDesktopUpdateRestart;
1907
1958
  private applyDesktopUpdateOwnerInput;
1959
+ /**
1960
+ * A Ctrl+C in the terminal that started ZTC while a quit already runs: leave now, as before, but tell the renderer
1961
+ * first that this is a quit (Q1). The quit sends `shutdown` only once it has the window's layout, up to 300 ms on, and
1962
+ * a desktop renderer that loses its owner without `shutdown` keeps the window and every pane under its "ZTC stopped"
1963
+ * banner, as after a crash (RZ8a). The line reaches the socket at once when nothing waits ahead of it; the exit waits
1964
+ * one turn of the event loop for what does.
1965
+ */
1966
+ private leaveMidQuit;
1908
1967
  private emergencyExitPromise;
1968
+ /** Leave at once, saving the session and stopping the renderer: for a signal (SIGTERM, SIGHUP, SIGQUIT, a Ctrl+C). */
1909
1969
  emergencyExit(): Promise<void>;
1970
+ /**
1971
+ * Leave after ZTC itself failed: an uncaught exception or an unhandled rejection reached cli_main.ts's handlers. The
1972
+ * session is saved as for a signal. In a terminal the renderer is stopped too, as only that gives the terminal back.
1973
+ * A desktop renderer that has admitted this owner is left running: ZTerm reads `shutdown` as a quit and ends every
1974
+ * pane with its window, while an owner that leaves without it is a crash, and ZTerm keeps the window and its panes
1975
+ * under "ZTC (the agent runtime) stopped" (P3a-0, RZ8a), as after a SIGKILL.
1976
+ */
1977
+ crashExit(): Promise<void>;
1978
+ private leaveInEmergency;
1910
1979
  exit(forceSessionPersistence?: boolean, options?: {
1911
1980
  announce?: boolean;
1912
1981
  exitCode?: number;