@zergai/ztc 0.23.0-beta.1 → 0.24.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 (146) hide show
  1. package/README.md +299 -13
  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/agent/agent.js +57 -14
  8. package/dist/agent/backends/http_error.d.ts +2 -0
  9. package/dist/agent/backends/http_error.js +2 -0
  10. package/dist/agent/backends/router_gate.d.ts +3 -2
  11. package/dist/agent/backends/router_gate.js +5 -4
  12. package/dist/agent/backends/router_keys.d.ts +14 -0
  13. package/dist/agent/backends/router_keys.js +19 -0
  14. package/dist/agent/backends/router_refusal.d.ts +5 -3
  15. package/dist/agent/backends/router_refusal.js +28 -6
  16. package/dist/agent/backends/types.d.ts +1 -1
  17. package/dist/agent/backends/zrouter_stream.js +10 -6
  18. package/dist/agent/commands/agent_cli.d.ts +11 -1
  19. package/dist/agent/commands/agent_cli.js +295 -38
  20. package/dist/agent/commands/diff.js +4 -1
  21. package/dist/agent/commands/help.js +4 -1
  22. package/dist/agent/commands/plan.js +3 -1
  23. package/dist/agent/commands/session_redaction.d.ts +16 -0
  24. package/dist/agent/commands/session_redaction.js +77 -0
  25. package/dist/agent/commands/settings.js +144 -0
  26. package/dist/agent/commands/types.d.ts +5 -0
  27. package/dist/agent/commands/usage_spec.d.ts +4 -0
  28. package/dist/agent/commands/usage_spec.js +10 -4
  29. package/dist/agent/runtime/policy.d.ts +25 -0
  30. package/dist/agent/runtime/policy.js +154 -26
  31. package/dist/agent/runtime/source_verification.js +6 -2
  32. package/dist/agent/runtime/tool_runtime.js +81 -3
  33. package/dist/agent/tools/apply_patch.js +678 -131
  34. package/dist/agent/tools/bus_message.d.ts +26 -1
  35. package/dist/agent/tools/bus_message.js +126 -10
  36. package/dist/agent/tools/file.d.ts +16 -1
  37. package/dist/agent/tools/file.js +43 -5
  38. package/dist/agent/tools/index.d.ts +1 -1
  39. package/dist/agent/tools/index.js +1 -1
  40. package/dist/agent/tools/pane.js +5 -0
  41. package/dist/agent/tools/search.js +5 -1
  42. package/dist/agent/tools/supervision.js +16 -2
  43. package/dist/agent/tools/types.d.ts +22 -0
  44. package/dist/app/mirror_startup.d.ts +7 -5
  45. package/dist/app/mirror_startup.js +7 -5
  46. package/dist/app/navigator_mirrors.d.ts +20 -0
  47. package/dist/app/navigator_mirrors.js +36 -0
  48. package/dist/app/workspace_layout_controller.d.ts +11 -2
  49. package/dist/app/workspace_layout_controller.js +13 -2
  50. package/dist/batch/worktree.js +9 -1
  51. package/dist/cli_ratatui.d.ts +264 -12
  52. package/dist/cli_ratatui.js +1198 -103
  53. package/dist/config/types.d.ts +29 -0
  54. package/dist/desktop/daily/source_baseline.js +3 -1
  55. package/dist/diagnostics/session_export.d.ts +1 -0
  56. package/dist/diagnostics/session_export.js +229 -26
  57. package/dist/emulation/tool_adapters.js +42 -5
  58. package/dist/headless.js +24 -5
  59. package/dist/instance_registry.d.ts +7 -0
  60. package/dist/mcp/workspace_server.d.ts +12 -1
  61. package/dist/mcp/workspace_server.js +75 -8
  62. package/dist/panes/agent_cli.d.ts +60 -3
  63. package/dist/panes/agent_cli.js +169 -16
  64. package/dist/panes/agent_pane_sessions.d.ts +22 -0
  65. package/dist/panes/agent_pane_sessions.js +111 -0
  66. package/dist/panes/agent_panes.d.ts +77 -3
  67. package/dist/panes/agent_panes.js +199 -10
  68. package/dist/panes/agent_profiles.d.ts +5 -0
  69. package/dist/panes/agent_profiles.js +7 -0
  70. package/dist/panes/agent_resume.d.ts +134 -0
  71. package/dist/panes/agent_resume.js +155 -0
  72. package/dist/panes/agent_sessions/claude_head.d.ts +32 -0
  73. package/dist/panes/agent_sessions/claude_head.js +122 -0
  74. package/dist/panes/agent_sessions/claude_store.d.ts +59 -0
  75. package/dist/panes/agent_sessions/claude_store.js +223 -0
  76. package/dist/panes/agent_sessions/codex_head.d.ts +55 -0
  77. package/dist/panes/agent_sessions/codex_head.js +161 -0
  78. package/dist/panes/agent_sessions/codex_store.d.ts +43 -0
  79. package/dist/panes/agent_sessions/codex_store.js +187 -0
  80. package/dist/panes/agent_sessions/controller.d.ts +74 -0
  81. package/dist/panes/agent_sessions/controller.js +110 -0
  82. package/dist/panes/agent_sessions/cut_json.d.ts +14 -0
  83. package/dist/panes/agent_sessions/cut_json.js +109 -0
  84. package/dist/panes/agent_sessions/limits.d.ts +48 -0
  85. package/dist/panes/agent_sessions/limits.js +48 -0
  86. package/dist/panes/agent_sessions/scan.d.ts +49 -0
  87. package/dist/panes/agent_sessions/scan.js +86 -0
  88. package/dist/panes/agent_sessions/store_fs.d.ts +51 -0
  89. package/dist/panes/agent_sessions/store_fs.js +128 -0
  90. package/dist/panes/agent_sessions/stores.d.ts +36 -0
  91. package/dist/panes/agent_sessions/stores.js +89 -0
  92. package/dist/panes/agent_sessions/title.d.ts +9 -0
  93. package/dist/panes/agent_sessions/title.js +51 -0
  94. package/dist/panes/agent_sessions/types.d.ts +48 -0
  95. package/dist/panes/agent_sessions/types.js +2 -0
  96. package/dist/panes/reply_arbitrator.d.ts +39 -0
  97. package/dist/panes/reply_arbitrator.js +185 -0
  98. package/dist/panes/reply_modes.d.ts +291 -0
  99. package/dist/panes/reply_modes.js +598 -0
  100. package/dist/runtime_info.js +11 -2
  101. package/dist/session.js +4 -2
  102. package/dist/simulation/living/context.d.ts +8 -8
  103. package/dist/simulation/living/types.d.ts +5 -5
  104. package/dist/simulation/toolkit/dynamic_state.d.ts +1 -1
  105. package/dist/ui/ratatui/ipc_path.d.ts +5 -0
  106. package/dist/ui/ratatui/ipc_path.js +23 -3
  107. package/dist/ui/ratatui/pane_credential_broker.d.ts +23 -8
  108. package/dist/ui/ratatui/pane_credential_broker.js +49 -14
  109. package/dist/ui/ratatui/pane_relay.d.ts +5 -2
  110. package/dist/ui/ratatui/pane_relay.js +86 -19
  111. package/dist/ui/ratatui/process.js +3 -0
  112. package/dist/ui/ratatui/protocol.d.ts +50 -1
  113. package/dist/ui/ratatui/protocol.js +56 -0
  114. package/dist/ui/ratatui/relay_policy.d.ts +39 -0
  115. package/dist/ui/ratatui/relay_policy.js +94 -0
  116. package/dist/ui/ratatui/screen_privacy.d.ts +15 -0
  117. package/dist/ui/ratatui/screen_privacy.js +24 -0
  118. package/dist/ui/scrollback.js +8 -0
  119. package/dist/ui/widgets/agent_sessions_panel.d.ts +139 -0
  120. package/dist/ui/widgets/agent_sessions_panel.js +542 -0
  121. package/dist/ui/widgets/log_view.d.ts +5 -1
  122. package/dist/ui/widgets/log_view.js +40 -4
  123. package/dist/utils/atomic_write.js +9 -11
  124. package/dist/utils/canonical_path.d.ts +19 -0
  125. package/dist/utils/canonical_path.js +44 -0
  126. package/dist/utils/compaction.d.ts +2 -1
  127. package/dist/utils/compaction.js +3 -1
  128. package/dist/utils/git_directory_names.d.ts +51 -0
  129. package/dist/utils/git_directory_names.js +429 -0
  130. package/dist/utils/temporary_write_root.d.ts +6 -1
  131. package/dist/utils/temporary_write_root.js +32 -2
  132. package/dist/utils/tool_result_message.d.ts +4 -1
  133. package/dist/utils/tool_result_message.js +6 -2
  134. package/dist/web/bus_hold.d.ts +70 -0
  135. package/dist/web/bus_hold.js +118 -0
  136. package/dist/web/mirror_client.d.ts +7 -3
  137. package/dist/web/mirror_client.js +61 -23
  138. package/dist/web/mirror_route_gate.d.ts +40 -0
  139. package/dist/web/mirror_route_gate.js +71 -0
  140. package/dist/web/mirror_stream.d.ts +147 -22
  141. package/dist/web/mirror_stream.js +350 -83
  142. package/dist/web/pane_credentials.d.ts +32 -1
  143. package/dist/web/pane_credentials.js +62 -2
  144. package/dist/workspace_collision.js +11 -2
  145. package/dist/zlm-embed.mjs +940 -273
  146. package/package.json +34 -12
@@ -62,6 +62,12 @@ export declare const CAPABILITY_SYNCHRONIZED_OUTPUT = "synchronized_output_v1";
62
62
  * looking at it, and lists the badge as the pane's `attention`.
63
63
  */
64
64
  export declare const CAPABILITY_ATTENTION_BADGES = "attention_badges_v1";
65
+ /**
66
+ * The renderer closes a tab and the panes in it when the ZTC that runs the window asks (close_window), as it does for the
67
+ * person's ×, middle-click, Close Tab and close-tab key, and reports every close with window_closed. ZTC sends
68
+ * close_window only to a renderer that advertises it.
69
+ */
70
+ export declare const CAPABILITY_DESKTOP_CLOSE_WINDOW = "desktop_close_window_v1";
65
71
  /** Render work the native renderer counted, rather than timed, over `frames` frames
66
72
  * (packages/zterm/src/terminal/stats.rs). Lock and repaint times are nanoseconds. */
67
73
  export interface TerminalRenderCounters {
@@ -407,6 +413,31 @@ export interface DesktopTaskAction {
407
413
  text?: string | null;
408
414
  before_id?: string | null;
409
415
  }
416
+ /**
417
+ * What became of a tab the renderer was asked to close (window_closed): every pane in it closed and the tab with them;
418
+ * some closed and the tab stayed for the rest (pinned panes, and Main's); the person cancelled the close sheet, which the
419
+ * renderer reports only for the owner's request; or it refused (Main's tab, the only tab, or no such tab).
420
+ */
421
+ export type WindowCloseOutcome = 'closed' | 'partly_closed' | 'cancelled' | 'refused';
422
+ export declare const WINDOW_CLOSE_OUTCOMES: readonly WindowCloseOutcome[];
423
+ /** The ids each of window_closed's lists holds at most. */
424
+ export declare const WINDOW_CLOSED_MAX_PANE_IDS = 1024;
425
+ /** The bytes window_closed's message holds at most; its request id holds as many. */
426
+ export declare const WINDOW_CLOSED_MAX_TEXT_BYTES = 256;
427
+ /**
428
+ * The renderer's report of a tab it closed, or didn't, for the person's own close (no request id) or the owner's
429
+ * close_window (its request id). kept_pane_ids are the panes it left open: pinned panes and Main's.
430
+ */
431
+ export interface WindowClosedEvent {
432
+ type: 'window_closed';
433
+ window_id: number;
434
+ request_id?: string;
435
+ outcome: WindowCloseOutcome;
436
+ closed_pane_ids: number[];
437
+ kept_pane_ids: number[];
438
+ /** Why it refused, in the renderer's words. */
439
+ message?: string;
440
+ }
410
441
  export type RustCommand = {
411
442
  type: 'render';
412
443
  frame: LayoutFrame;
@@ -580,6 +611,17 @@ export type RustCommand = {
580
611
  } | {
581
612
  type: 'switch_window';
582
613
  window_id: number;
614
+ }
615
+ /**
616
+ * Close tab WINDOW_ID and the panes in it, as the person's ×, middle-click, Close Tab and close-tab key do; the renderer
617
+ * answers with window_closed under REQUEST_ID. With CONFIRMED the owner has already asked the person, so no close sheet
618
+ * shows. Capability gate: `desktop_close_window_v1`.
619
+ */
620
+ | {
621
+ type: 'close_window';
622
+ window_id: number;
623
+ request_id?: string;
624
+ confirmed?: boolean;
583
625
  } | {
584
626
  type: 'set_pane_window';
585
627
  pane_id: number;
@@ -784,7 +826,7 @@ export type RustEvent = DesktopTaskAction | DesktopRuntimeAction | DesktopSessio
784
826
  } | {
785
827
  type: 'window_switched';
786
828
  window_id: number;
787
- } | {
829
+ } | WindowClosedEvent | {
788
830
  type: 'show_pane_picker';
789
831
  } | {
790
832
  type: 'show_new_pane_picker';
@@ -812,6 +854,13 @@ export declare function serializeCommand(cmd: RustCommand): string;
812
854
  * Parse an event from Rust
813
855
  */
814
856
  export declare function parseEvent(json: string): RustEvent | null;
857
+ /**
858
+ * Whether VALUE is a well-formed window_closed: integer ids a u32 holds; at most 1024 ids in each list; one of the four
859
+ * outcomes; a request id of 1 to 256 bytes and a message of at most 256, neither with a control character. Only the keys
860
+ * it knows are checked: a newer renderer's own are ignored (workspace spec §13). An absent request id or message may come
861
+ * as null.
862
+ */
863
+ export declare function isWindowClosed(value: unknown): value is WindowClosedEvent;
815
864
  /** Sharing intents carry only bounded identities and an explicit save destination. */
816
865
  export declare function isDesktopSessionShareAction(value: unknown): value is DesktopSessionShareAction;
817
866
  /**
@@ -39,6 +39,12 @@ export const CAPABILITY_SYNCHRONIZED_OUTPUT = 'synchronized_output_v1';
39
39
  * looking at it, and lists the badge as the pane's `attention`.
40
40
  */
41
41
  export const CAPABILITY_ATTENTION_BADGES = 'attention_badges_v1';
42
+ /**
43
+ * The renderer closes a tab and the panes in it when the ZTC that runs the window asks (close_window), as it does for the
44
+ * person's ×, middle-click, Close Tab and close-tab key, and reports every close with window_closed. ZTC sends
45
+ * close_window only to a renderer that advertises it.
46
+ */
47
+ export const CAPABILITY_DESKTOP_CLOSE_WINDOW = 'desktop_close_window_v1';
42
48
  /** Limits on `runtime_choices`, the same as ztc-core's (protocol.rs). Byte limits are UTF-8 bytes. */
43
49
  export const DESKTOP_RUNTIME_MAX_PROVIDER_CHOICES = 48;
44
50
  export const DESKTOP_RUNTIME_MAX_MODEL_CHOICES = 128;
@@ -46,6 +52,11 @@ export const DESKTOP_RUNTIME_MAX_CHOICE_LABEL_BYTES = 96;
46
52
  export const DESKTOP_RUNTIME_MAX_CHOICE_SHORT_LABEL_BYTES = 48;
47
53
  export const DESKTOP_RUNTIME_MAX_CHOICE_DETAIL_BYTES = 160;
48
54
  export const DESKTOP_RUNTIME_MAX_URL_BYTES = 512;
55
+ export const WINDOW_CLOSE_OUTCOMES = Object.freeze(['closed', 'partly_closed', 'cancelled', 'refused']);
56
+ /** The ids each of window_closed's lists holds at most. */
57
+ export const WINDOW_CLOSED_MAX_PANE_IDS = 1024;
58
+ /** The bytes window_closed's message holds at most; its request id holds as many. */
59
+ export const WINDOW_CLOSED_MAX_TEXT_BYTES = 256;
49
60
  // ============================================================================
50
61
  // Serialization helpers
51
62
  // ============================================================================
@@ -70,12 +81,57 @@ export function parseEvent(json) {
70
81
  return null;
71
82
  if (parsed.type === 'desktop_session_share_action' && !isDesktopSessionShareAction(parsed))
72
83
  return null;
84
+ if (parsed.type === 'window_closed')
85
+ return isWindowClosed(parsed) ? windowClosedFields(parsed) : null;
73
86
  return parsed;
74
87
  }
75
88
  catch {
76
89
  return null;
77
90
  }
78
91
  }
92
+ /** A tab's or a pane's id, as the renderer's u32 holds it. */
93
+ function isU32(value) {
94
+ return Number.isInteger(value) && value >= 0 && value <= 0xffff_ffff;
95
+ }
96
+ /** Text of at most WINDOW_CLOSED_MAX_TEXT_BYTES, with no C0 or C1 control. */
97
+ function isWindowClosedText(value) {
98
+ return typeof value === 'string' && Buffer.byteLength(value, 'utf8') <= WINDOW_CLOSED_MAX_TEXT_BYTES
99
+ && !/[\u0000-\u001f\u007f-\u009f]/.test(value);
100
+ }
101
+ /** A list of at most WINDOW_CLOSED_MAX_PANE_IDS pane ids. */
102
+ function isPaneIdList(value) {
103
+ return Array.isArray(value) && value.length <= WINDOW_CLOSED_MAX_PANE_IDS && value.every(isU32);
104
+ }
105
+ /**
106
+ * Whether VALUE is a well-formed window_closed: integer ids a u32 holds; at most 1024 ids in each list; one of the four
107
+ * outcomes; a request id of 1 to 256 bytes and a message of at most 256, neither with a control character. Only the keys
108
+ * it knows are checked: a newer renderer's own are ignored (workspace spec §13). An absent request id or message may come
109
+ * as null.
110
+ */
111
+ export function isWindowClosed(value) {
112
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
113
+ return false;
114
+ const event = value;
115
+ return event.type === 'window_closed' && isU32(event.window_id)
116
+ && (event.request_id === undefined || event.request_id === null
117
+ || (isWindowClosedText(event.request_id) && event.request_id.length > 0))
118
+ && WINDOW_CLOSE_OUTCOMES.includes(event.outcome)
119
+ && isPaneIdList(event.closed_pane_ids) && isPaneIdList(event.kept_pane_ids)
120
+ && (event.message === undefined || event.message === null || isWindowClosedText(event.message));
121
+ }
122
+ /** EVENT's known fields alone, leaving out a request id or message that came as null. */
123
+ function windowClosedFields(event) {
124
+ const { window_id: windowId, request_id: requestId, outcome, closed_pane_ids: closed, kept_pane_ids: kept, message } = event;
125
+ return {
126
+ type: 'window_closed',
127
+ window_id: windowId,
128
+ ...(typeof requestId === 'string' ? { request_id: requestId } : {}),
129
+ outcome,
130
+ closed_pane_ids: [...closed],
131
+ kept_pane_ids: [...kept],
132
+ ...(typeof message === 'string' ? { message } : {}),
133
+ };
134
+ }
79
135
  /** Sharing intents carry only bounded identities and an explicit save destination. */
80
136
  export function isDesktopSessionShareAction(value) {
81
137
  if (value === null || typeof value !== 'object' || Array.isArray(value))
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The pane relay's command table (workspace spec §4A, T0.3): what a child of the pane relay may send the renderer.
3
+ *
4
+ * Every program in a pane the main ZTC runs can reach the relay's socket ($ZTC_PANE_RELAY): a ZTC pane, the workspace
5
+ * tools of a Claude Code or Codex pane, a shell and whatever runs in it. The relay forwards a child's line to the
6
+ * renderer only when this table lets it (PaneRelayServer asks relayVerdict for every line):
7
+ *
8
+ * - own_report: what a ZTC pane reports about itself (its activity, task controls, labels and title);
9
+ * - pane_tool: what ZTC's own pane tools send (agent/tools/pane.ts, the supervision tool, workspace-mcp): opening,
10
+ * reading, writing, laying out and closing panes;
11
+ * - owner_only: the main ZTC's own commands (its frames, configuration and shutdown, clipboard reads, the workspace's
12
+ * saved state and windows, the mirror socket, key bindings and input capture), which no child sends.
13
+ *
14
+ * A write_pane never carries control: a control line reaches a pane bare, as only the ZTC that opened it sends one.
15
+ * Anything else a child sends, a line that isn't one JSON command and a command type this table doesn't know included,
16
+ * is answered with an error and never forwarded. The table is exhaustive at compile time, so a command added to
17
+ * RustCommand is classified here as it is added.
18
+ */
19
+ import type { RustCommand } from './protocol.js';
20
+ /** What a child may do with a command: report on its own pane, use a pane tool, or nothing (the owner's alone). */
21
+ export type RelayCommandClass = 'own_report' | 'pane_tool' | 'owner_only';
22
+ /** Each command type's class. */
23
+ export declare const RELAY_COMMAND_CLASSES: Readonly<Record<RustCommand['type'], RelayCommandClass>>;
24
+ /** The error a child gets for a line the relay doesn't forward: for its request, when the line named one. */
25
+ export interface RelayRefusal {
26
+ type: 'error';
27
+ message: string;
28
+ request_id?: string;
29
+ }
30
+ /** What the relay does with a line a child sent: forward its command, or answer it with an error. */
31
+ export type RelayVerdict = {
32
+ forward: true;
33
+ command: RustCommand;
34
+ } | {
35
+ forward: false;
36
+ error: RelayRefusal;
37
+ };
38
+ /** The verdict on VALUE, one line a child sent, parsed as JSON (undefined when it isn't JSON). */
39
+ export declare function relayVerdict(value: unknown): RelayVerdict;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The pane relay's command table (workspace spec §4A, T0.3): what a child of the pane relay may send the renderer.
3
+ *
4
+ * Every program in a pane the main ZTC runs can reach the relay's socket ($ZTC_PANE_RELAY): a ZTC pane, the workspace
5
+ * tools of a Claude Code or Codex pane, a shell and whatever runs in it. The relay forwards a child's line to the
6
+ * renderer only when this table lets it (PaneRelayServer asks relayVerdict for every line):
7
+ *
8
+ * - own_report: what a ZTC pane reports about itself (its activity, task controls, labels and title);
9
+ * - pane_tool: what ZTC's own pane tools send (agent/tools/pane.ts, the supervision tool, workspace-mcp): opening,
10
+ * reading, writing, laying out and closing panes;
11
+ * - owner_only: the main ZTC's own commands (its frames, configuration and shutdown, clipboard reads, the workspace's
12
+ * saved state and windows, the mirror socket, key bindings and input capture), which no child sends.
13
+ *
14
+ * A write_pane never carries control: a control line reaches a pane bare, as only the ZTC that opened it sends one.
15
+ * Anything else a child sends, a line that isn't one JSON command and a command type this table doesn't know included,
16
+ * is answered with an error and never forwarded. The table is exhaustive at compile time, so a command added to
17
+ * RustCommand is classified here as it is added.
18
+ */
19
+ const CLASSES = {
20
+ set_pane_activity: 'own_report',
21
+ set_pane_task_controls: 'own_report',
22
+ set_pane_labels: 'own_report',
23
+ set_pane_title: 'own_report',
24
+ create_pane: 'pane_tool',
25
+ create_feed_pane: 'pane_tool',
26
+ create_doc_pane: 'pane_tool',
27
+ read_pane: 'pane_tool',
28
+ write_pane: 'pane_tool',
29
+ append_pane_lines: 'pane_tool',
30
+ set_pane_content: 'pane_tool',
31
+ close_pane: 'pane_tool',
32
+ replace_pane: 'pane_tool',
33
+ restart_pane: 'pane_tool',
34
+ list_panes: 'pane_tool',
35
+ focus_pane: 'pane_tool',
36
+ set_layout: 'pane_tool',
37
+ toggle_zoom: 'pane_tool',
38
+ scroll_pane: 'pane_tool',
39
+ swap_pane: 'pane_tool',
40
+ cycle_overflow: 'pane_tool',
41
+ set_pane_window: 'pane_tool',
42
+ open_file_picker: 'pane_tool',
43
+ open_file_tree: 'pane_tool',
44
+ set_zlicky_cursors: 'pane_tool',
45
+ render: 'owner_only',
46
+ print_scrollback: 'owner_only',
47
+ clear_scrollback: 'owner_only',
48
+ replace_scrollback: 'owner_only',
49
+ replace_scrollback_with_anchor: 'owner_only',
50
+ resize_fence: 'owner_only',
51
+ read_clipboard_image: 'owner_only',
52
+ read_clipboard_text: 'owner_only',
53
+ transmit_image: 'owner_only',
54
+ config: 'owner_only',
55
+ shutdown: 'owner_only',
56
+ authorize_update_restart: 'owner_only',
57
+ cancel_update_restart: 'owner_only',
58
+ resize_pane: 'owner_only',
59
+ get_session_state: 'owner_only',
60
+ get_terminal_metrics: 'owner_only',
61
+ restore_session_state: 'owner_only',
62
+ workspace_layout: 'owner_only',
63
+ switch_window: 'owner_only',
64
+ // Closing a tab closes every pane in it, the person's own among them (phase W1), so only the owner asks for it.
65
+ close_window: 'owner_only',
66
+ zoom_pane: 'owner_only',
67
+ attach_mirror: 'owner_only',
68
+ detach_mirror: 'owner_only',
69
+ set_keybindings: 'owner_only',
70
+ set_input_capture: 'owner_only',
71
+ set_wheel_capture: 'owner_only',
72
+ };
73
+ /** Each command type's class. */
74
+ export const RELAY_COMMAND_CLASSES = CLASSES;
75
+ function refusal(message, requestId) {
76
+ return { forward: false, error: { type: 'error', message, ...(typeof requestId === 'string' ? { request_id: requestId } : {}) } };
77
+ }
78
+ /** The verdict on VALUE, one line a child sent, parsed as JSON (undefined when it isn't JSON). */
79
+ export function relayVerdict(value) {
80
+ if (!value || typeof value !== 'object' || Array.isArray(value) || typeof value.type !== 'string') {
81
+ return refusal('The pane relay takes one JSON command per line, with its type.', undefined);
82
+ }
83
+ const command = value;
84
+ if (!Object.hasOwn(RELAY_COMMAND_CLASSES, command.type)) {
85
+ return refusal(`The pane relay doesn't know the command ${JSON.stringify(command.type)}.`, command.request_id);
86
+ }
87
+ if (RELAY_COMMAND_CLASSES[command.type] === 'owner_only') {
88
+ return refusal(`A pane can't send ${command.type}: only the ZTC that runs this workspace does.`, command.request_id);
89
+ }
90
+ if (command.type === 'write_pane' && (command.control ?? false) !== false) {
91
+ return refusal('A pane\'s write_pane can\'t carry control: only the ZTC that runs this workspace sends a pane its control lines.', command.request_id);
92
+ }
93
+ return { forward: true, command: value };
94
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Whether a pane's screen may be read now. The main ZTC refuses reads of its own screen (pane 0) while it shows the
3
+ * person's Claude Code and Codex sessions picker, whose titles are their opening prompts, from every folder (workspace
4
+ * spec §14). Each path that reads a pane in the main ZTC's process asks here first: the pane relay, for every child's
5
+ * read_pane (a ZTC pane's read_terminal_pane, a Claude Code or Codex pane's workspace-mcp read_pane) and every
6
+ * pane_read it passes on; read_terminal_pane, for Main's own agent; and the web mirror's viewport read.
7
+ *
8
+ * A child ZTC never sets this: its reads reach the renderer only through the main ZTC's relay, which asks.
9
+ */
10
+ /** Why the main ZTC refuses reads of a pane now, or null. */
11
+ export type PaneReadRefusal = (paneId: number) => string | null;
12
+ /** Set by the main ZTC as it starts; null takes it away. */
13
+ export declare function setPaneReadRefusal(next: PaneReadRefusal | null): void;
14
+ /** Why `paneId` can't be read now, or null when it can. */
15
+ export declare function paneReadRefusal(paneId: number): string | null;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Whether a pane's screen may be read now. The main ZTC refuses reads of its own screen (pane 0) while it shows the
3
+ * person's Claude Code and Codex sessions picker, whose titles are their opening prompts, from every folder (workspace
4
+ * spec §14). Each path that reads a pane in the main ZTC's process asks here first: the pane relay, for every child's
5
+ * read_pane (a ZTC pane's read_terminal_pane, a Claude Code or Codex pane's workspace-mcp read_pane) and every
6
+ * pane_read it passes on; read_terminal_pane, for Main's own agent; and the web mirror's viewport read.
7
+ *
8
+ * A child ZTC never sets this: its reads reach the renderer only through the main ZTC's relay, which asks.
9
+ */
10
+ let refusal = null;
11
+ /** Set by the main ZTC as it starts; null takes it away. */
12
+ export function setPaneReadRefusal(next) {
13
+ refusal = next;
14
+ }
15
+ /** Why `paneId` can't be read now, or null when it can. */
16
+ export function paneReadRefusal(paneId) {
17
+ try {
18
+ return refusal?.(paneId) ?? null;
19
+ }
20
+ catch {
21
+ // A refusal that fails refuses: the screen may hold what it guards.
22
+ return 'This pane can\'t be read right now.';
23
+ }
24
+ }
@@ -277,6 +277,14 @@ function roleConfig(message) {
277
277
  // One-column icon like every other header, so labels stay on the grid.
278
278
  return { label: 'Thinking', icon: '✻', color: 'yellow' };
279
279
  }
280
+ // A message another pane sent on the bus is headed by its sender, as the live frame and the browser mirror head it,
281
+ // never as the person's own. The name is the sender's to give, so it is drawn on one line, with no control character.
282
+ const sender = message.role === 'user' ? meta?.busFrom?.name : undefined;
283
+ if (typeof sender === 'string') {
284
+ const name = sender.replace(/\s*[\r\n]+\s*/g, ' ').replace(/[\u0000-\u001f\u007f-\u009f]/g, '').trim();
285
+ if (name)
286
+ return { label: name, icon: '◆', color: 'cyan' };
287
+ }
280
288
  switch (message.role) {
281
289
  case 'user':
282
290
  return { label: 'You', icon: '❯', color: 'blue' };
@@ -0,0 +1,139 @@
1
+ /**
2
+ * The Claude Code and Codex sessions picker: a full-page list of the person's sessions in Main, to resume or fork one.
3
+ *
4
+ * Modelled on the /resume page (resume_panel.ts): the same frame, keys and fuzzy filter. Two views: This folder, the
5
+ * sessions working in this folder or under it, and All folders. It only receives rows (panes/agent_sessions/), each
6
+ * with what the host found out about it: it reads nothing itself, holds no file, and previews no transcript. ↵ hands
7
+ * the highlighted row back; the host re-checks it and opens it, focuses the pane it is already open in, or, for a
8
+ * session whose folder is gone or unknown, asks for a second ↵, which resumes it in this folder.
9
+ */
10
+ import { type LayoutNode } from '../core/index.js';
11
+ import { type AgentCliId } from '../../panes/agent_cli.js';
12
+ import type { AgentSessionRow } from '../../panes/agent_sessions/types.js';
13
+ import type { KeyEvent, WidgetHost, WidgetMouseEvent } from './types.js';
14
+ export type AgentSessionsView = 'here' | 'all';
15
+ /** A session as the picker shows it, with what the host found out about it. */
16
+ export interface AgentSessionsPanelRow {
17
+ session: AgentSessionRow;
18
+ /** Where in this folder the session works: '' for this folder itself, a subfolder's path, or null for elsewhere. */
19
+ inHere: string | null;
20
+ /** The session's folder is gone, or its file names none. */
21
+ folderMissing: boolean;
22
+ /** The ZTC pane the session is open in, if it is. */
23
+ openInPane: number | null;
24
+ }
25
+ /**
26
+ * What the host did with a chosen row: closed the picker, or asks for a second ↵, which confirms resuming the session
27
+ * in this folder ('confirm-here': its own is gone or unknown) or resuming it though it may still be open elsewhere
28
+ * ('confirm-recent'), or stays.
29
+ */
30
+ export type AgentSessionsChoice = 'closed' | 'confirm-here' | 'confirm-recent' | 'stay';
31
+ export interface AgentSessionsPanelData {
32
+ cli: AgentCliId;
33
+ mode: 'resume' | 'fork';
34
+ /** The ZTC profile the picker is scoped to, if any. */
35
+ profile?: string;
36
+ /** Whether the person has ZTC profiles for this CLI, so rows name theirs. */
37
+ hasProfiles: boolean;
38
+ /** This folder, and the home folders are shown under. */
39
+ cwd: string;
40
+ home: string;
41
+ rows: AgentSessionsPanelRow[];
42
+ loading: boolean;
43
+ unreadable?: number;
44
+ partial?: boolean;
45
+ /** Session files read, those of them left out (the Agent SDK's, codex exec's, a subagent's…), and older ones not read. */
46
+ read?: number;
47
+ skipped?: number;
48
+ older?: number;
49
+ /** Session folders not read because they are symbolic links. */
50
+ links?: number;
51
+ initialView?: AgentSessionsView;
52
+ /**
53
+ * Resume or fork the row's session; `here` once the person confirmed this folder for it, `recent` once they confirmed
54
+ * resuming it though it may still be open elsewhere.
55
+ */
56
+ onChoose: (row: AgentSessionsPanelRow, here: boolean, recent: boolean) => AgentSessionsChoice | Promise<AgentSessionsChoice>;
57
+ onRefresh?: () => void;
58
+ onClose?: () => void;
59
+ now?: () => number;
60
+ }
61
+ export interface AgentSessionsPanelSurface {
62
+ content: string;
63
+ view: LayoutNode;
64
+ lineCount: number;
65
+ }
66
+ export declare class AgentSessionsPanelWidget {
67
+ private host;
68
+ private active;
69
+ private view;
70
+ private viewChosen;
71
+ private filterText;
72
+ private filterMode;
73
+ private selectedIndex;
74
+ private listScrollOffset;
75
+ private lastBodyRows;
76
+ /** The row waiting on a second ↵, what that ↵ confirms, and what the person confirmed of it before. */
77
+ private armed;
78
+ private choosing;
79
+ /** Whether the person moved the highlight; until then it stays on the newest session as rows come in. */
80
+ private moved;
81
+ private listBand;
82
+ private frameInset;
83
+ constructor(host: WidgetHost);
84
+ show(data: AgentSessionsPanelData): void;
85
+ isActive(): boolean;
86
+ /** New rows from the scan, and how it went: rows fill in as files are read. */
87
+ updateRows(rows: AgentSessionsPanelRow[], status: {
88
+ loading: boolean;
89
+ unreadable?: number;
90
+ partial?: boolean;
91
+ read?: number;
92
+ skipped?: number;
93
+ older?: number;
94
+ links?: number;
95
+ }): void;
96
+ /** Close without choosing; runs the host's onClose. */
97
+ cancel(): void;
98
+ /** The highlighted row, after filtering. */
99
+ selectedRow(): AgentSessionsPanelRow | undefined;
100
+ /**
101
+ * Whether This folder may miss this folder's sessions: Codex's are found only among the newest files read, where
102
+ * Claude Code's are read by their project folder's name however old (claude_store.ts).
103
+ */
104
+ private thisFolderLimited;
105
+ /**
106
+ * This folder opens the picker, unless it has none once the scan is done and the person chose no view; and unless
107
+ * it may be missing older sessions, which its empty view then says.
108
+ */
109
+ private settleView;
110
+ /** Every session of a view, however many: the tabs count them and a search looks through them all. */
111
+ private viewRows;
112
+ private searchText;
113
+ /** This view's sessions the search matches, best first, or all of them newest first. */
114
+ private matchingRows;
115
+ /** The rows drawn: the first ROWS_PER_VIEW that match. */
116
+ private visibleRows;
117
+ private move;
118
+ private moveTo;
119
+ private switchView;
120
+ private applyFilter;
121
+ handleInput(input: string, key: KeyEvent): void;
122
+ handleMouse(event: WidgetMouseEvent): boolean;
123
+ private isPrintable;
124
+ private choose;
125
+ private label;
126
+ private rowSegments;
127
+ /** What an empty view says: why there is nothing to list, and where else to look. */
128
+ private emptyMessage;
129
+ /** The list, or what an empty view says, wrapped to the width so none of it is cut. */
130
+ private listRows;
131
+ private tabsLine;
132
+ /** How many sessions were read, how many of this view are drawn when not all, and whether any reading fell short. */
133
+ private statusText;
134
+ /** The highlighted session's facts (or the second ↵ it waits for), then the keys. */
135
+ private footerLines;
136
+ buildSurface(cols?: number, maxRows?: number): AgentSessionsPanelSurface;
137
+ buildContent(cols?: number, maxRows?: number): string;
138
+ private buildLines;
139
+ }