@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
@@ -0,0 +1,542 @@
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 { displayWidth, padEndDisplay } from '../core/text_width.js';
11
+ import { TERMINAL_THEME } from '../views/theme.js';
12
+ import { rankFuzzy } from '../../utils/fuzzy_match.js';
13
+ import { isControlKey } from '../core/input.js';
14
+ import { AGENT_CLIS } from '../../panes/agent_cli.js';
15
+ import { ROWS_PER_VIEW } from '../../panes/agent_sessions/limits.js';
16
+ import { bodyBand, bottomBorder, buildWidgetFrameView, clipText, dropLastGrapheme, formatRelativeTime, framedLine, isInsideBand, joinColumns, lineText, topBorder, widgetFrameGeometry, } from './panel_frame.js';
17
+ import { formatCwdTail } from './resume_panel.js';
18
+ /** Text in lines of at most `width` columns, broken between words (a word wider than a line is cut). */
19
+ function wrapWords(text, width) {
20
+ const lines = [];
21
+ let line = '';
22
+ for (const word of text.split(' ')) {
23
+ const next = line ? `${line} ${word}` : word;
24
+ if (displayWidth(next) <= width || !line) {
25
+ line = next;
26
+ }
27
+ else {
28
+ lines.push(line);
29
+ line = word;
30
+ }
31
+ }
32
+ if (line)
33
+ lines.push(line);
34
+ return lines.map(part => clipText(part, Math.max(1, width)));
35
+ }
36
+ /** A row's session in its store: one session can be listed once in each sign-in's store. */
37
+ function rowKey(entry) {
38
+ return entry ? `${entry.session.profile ?? ''}:${entry.session.id}` : null;
39
+ }
40
+ /** `~/…` for a folder under the home. */
41
+ function homeRelative(path, home) {
42
+ if (!home)
43
+ return path;
44
+ return path === home ? '~' : path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
45
+ }
46
+ /** Where each CLI's own list of sessions is, for when the picker can't list them. */
47
+ const OWN_LIST = Object.freeze({
48
+ claude: "/claude --resume opens Claude Code's own list.",
49
+ codex: "Codex's own /resume, in a /codex pane, lists them all.",
50
+ });
51
+ /** What a session the picker leaves out is, for each CLI: what its own picker leaves out too. */
52
+ const LEFT_OUT = Object.freeze({
53
+ claude: 'Agent SDK, desktop app or subagent sessions',
54
+ codex: 'exec, MCP or subagent sessions',
55
+ });
56
+ /** `45s`, `1m`: how long ago a session was active, to the second under a minute. */
57
+ function recentAge(mtimeMs, nowMs) {
58
+ const seconds = Math.max(0, Math.floor((nowMs - mtimeMs) / 1000));
59
+ return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m`;
60
+ }
61
+ /** `2h`, `30m`, `3d`, `now`: formatRelativeTime without "ago". */
62
+ function shortAge(mtimeMs, nowMs) {
63
+ const relative = formatRelativeTime(new Date(mtimeMs).toISOString(), nowMs);
64
+ if (relative === 'just now')
65
+ return 'now';
66
+ if (relative === 'unknown')
67
+ return '?';
68
+ return relative.replace(/ ago$/, '');
69
+ }
70
+ export class AgentSessionsPanelWidget {
71
+ host;
72
+ active = null;
73
+ view = 'here';
74
+ viewChosen = false;
75
+ filterText = '';
76
+ filterMode = false;
77
+ selectedIndex = 0;
78
+ listScrollOffset = 0;
79
+ lastBodyRows = 1;
80
+ /** The row waiting on a second ↵, what that ↵ confirms, and what the person confirmed of it before. */
81
+ armed = null;
82
+ choosing = false;
83
+ /** Whether the person moved the highlight; until then it stays on the newest session as rows come in. */
84
+ moved = false;
85
+ listBand = null;
86
+ frameInset = 0;
87
+ constructor(host) {
88
+ this.host = host;
89
+ }
90
+ show(data) {
91
+ this.active = data;
92
+ this.view = data.initialView ?? 'here';
93
+ this.viewChosen = data.initialView !== undefined;
94
+ this.filterText = '';
95
+ this.filterMode = false;
96
+ this.selectedIndex = 0;
97
+ this.listScrollOffset = 0;
98
+ this.armed = null;
99
+ this.choosing = false;
100
+ this.moved = false;
101
+ this.settleView();
102
+ this.host.render();
103
+ }
104
+ isActive() {
105
+ return this.active !== null;
106
+ }
107
+ /** New rows from the scan, and how it went: rows fill in as files are read. */
108
+ updateRows(rows, status) {
109
+ if (!this.active)
110
+ return;
111
+ const selected = rowKey(this.selectedRow());
112
+ this.active = {
113
+ ...this.active, rows, loading: status.loading, unreadable: status.unreadable ?? 0, partial: status.partial ?? false,
114
+ read: status.read ?? 0, skipped: status.skipped ?? 0, older: status.older ?? 0, links: status.links ?? 0,
115
+ };
116
+ this.settleView();
117
+ const visible = this.visibleRows();
118
+ // Heads arrive in any order: the highlight stays on the newest until the person moves it, then with their row.
119
+ const kept = this.moved && selected ? visible.findIndex(entry => rowKey(entry) === selected) : -1;
120
+ this.selectedIndex = kept >= 0 ? kept : this.moved ? Math.min(this.selectedIndex, Math.max(0, visible.length - 1)) : 0;
121
+ this.host.render();
122
+ }
123
+ /** Close without choosing; runs the host's onClose. */
124
+ cancel() {
125
+ if (!this.active)
126
+ return;
127
+ const onClose = this.active.onClose;
128
+ this.active = null;
129
+ this.armed = null;
130
+ this.host.render();
131
+ onClose?.();
132
+ }
133
+ /** The highlighted row, after filtering. */
134
+ selectedRow() {
135
+ return this.visibleRows()[this.selectedIndex];
136
+ }
137
+ // ── Rows ──────────────────────────────────────────────────────────────────
138
+ /**
139
+ * Whether This folder may miss this folder's sessions: Codex's are found only among the newest files read, where
140
+ * Claude Code's are read by their project folder's name however old (claude_store.ts).
141
+ */
142
+ thisFolderLimited() {
143
+ return this.active?.cli === 'codex' && (this.active.older ?? 0) > 0;
144
+ }
145
+ /**
146
+ * This folder opens the picker, unless it has none once the scan is done and the person chose no view; and unless
147
+ * it may be missing older sessions, which its empty view then says.
148
+ */
149
+ settleView() {
150
+ if (!this.active || this.viewChosen || this.active.loading || this.thisFolderLimited())
151
+ return;
152
+ if (this.view === 'here' && this.viewRows('here').length === 0 && this.viewRows('all').length > 0)
153
+ this.view = 'all';
154
+ }
155
+ /** Every session of a view, however many: the tabs count them and a search looks through them all. */
156
+ viewRows(view) {
157
+ const rows = this.active?.rows ?? [];
158
+ return view === 'here' ? rows.filter(entry => entry.inHere !== null) : rows;
159
+ }
160
+ searchText(entry) {
161
+ const { session } = entry;
162
+ return [session.title ?? '', session.cwd ?? '', session.profile ? `@${session.profile}` : '', session.id.slice(0, 8)].join(' ');
163
+ }
164
+ /** This view's sessions the search matches, best first, or all of them newest first. */
165
+ matchingRows() {
166
+ const rows = this.viewRows(this.view);
167
+ const query = this.filterText.trim();
168
+ if (!query)
169
+ return rows;
170
+ return rankFuzzy(query, rows, entry => this.searchText(entry)).map(ranked => ranked.item);
171
+ }
172
+ /** The rows drawn: the first ROWS_PER_VIEW that match. */
173
+ visibleRows() {
174
+ return this.matchingRows().slice(0, ROWS_PER_VIEW);
175
+ }
176
+ move(delta) {
177
+ const count = this.visibleRows().length;
178
+ if (count === 0)
179
+ return;
180
+ this.selectedIndex = Math.max(0, Math.min(this.selectedIndex + delta, count - 1));
181
+ this.armed = null;
182
+ this.moved = true;
183
+ }
184
+ moveTo(end) {
185
+ const count = this.visibleRows().length;
186
+ this.selectedIndex = end ? Math.max(0, count - 1) : 0;
187
+ this.armed = null;
188
+ this.moved = true;
189
+ }
190
+ switchView(view) {
191
+ this.viewChosen = true;
192
+ if (this.view === view)
193
+ return;
194
+ this.view = view;
195
+ this.selectedIndex = 0;
196
+ this.listScrollOffset = 0;
197
+ this.armed = null;
198
+ }
199
+ applyFilter() {
200
+ this.selectedIndex = 0;
201
+ this.listScrollOffset = 0;
202
+ this.armed = null;
203
+ }
204
+ // ── Input ─────────────────────────────────────────────────────────────────
205
+ handleInput(input, key) {
206
+ if (!this.active)
207
+ return;
208
+ if (key.paste) {
209
+ if (!input)
210
+ return;
211
+ this.filterMode = true;
212
+ this.filterText += input.replace(/[\r\n\t]+/g, ' ');
213
+ this.applyFilter();
214
+ this.host.render();
215
+ return;
216
+ }
217
+ if (isControlKey(input, key, 'c')) {
218
+ this.cancel();
219
+ return;
220
+ }
221
+ if (this.filterMode) {
222
+ if (key.escape) {
223
+ this.filterMode = false;
224
+ this.host.render();
225
+ return;
226
+ }
227
+ if (key.backspace || key.delete) {
228
+ this.filterText = dropLastGrapheme(this.filterText);
229
+ this.applyFilter();
230
+ this.host.render();
231
+ return;
232
+ }
233
+ if (isControlKey(input, key, 'u')) {
234
+ this.filterText = '';
235
+ this.applyFilter();
236
+ this.host.render();
237
+ return;
238
+ }
239
+ if (!key.ctrl && !key.meta && !key.super && !key.return && this.isPrintable(input)) {
240
+ this.filterText += input;
241
+ this.applyFilter();
242
+ this.host.render();
243
+ return;
244
+ }
245
+ }
246
+ if (key.escape) {
247
+ if (this.armed !== null) {
248
+ this.armed = null;
249
+ this.host.render();
250
+ return;
251
+ }
252
+ this.cancel();
253
+ return;
254
+ }
255
+ if (isControlKey(input, key, 'u')) {
256
+ this.filterText = '';
257
+ this.applyFilter();
258
+ this.host.render();
259
+ return;
260
+ }
261
+ if (key.tab || key.leftArrow || key.rightArrow) {
262
+ this.switchView(key.tab ? (this.view === 'here' ? 'all' : 'here') : key.rightArrow ? 'all' : 'here');
263
+ this.host.render();
264
+ return;
265
+ }
266
+ const plain = !key.ctrl && !key.meta && !key.super;
267
+ const typing = this.filterMode;
268
+ if (key.upArrow || (plain && !typing && input === 'k'))
269
+ this.move(-1);
270
+ else if (key.downArrow || (plain && !typing && input === 'j'))
271
+ this.move(1);
272
+ else if (key.pageUp)
273
+ this.move(-Math.max(1, this.lastBodyRows - 2));
274
+ else if (key.pageDown)
275
+ this.move(Math.max(1, this.lastBodyRows - 2));
276
+ else if (key.home || (plain && !typing && input === 'g'))
277
+ this.moveTo(false);
278
+ else if (key.end || (plain && !typing && input === 'G'))
279
+ this.moveTo(true);
280
+ else if (key.return) {
281
+ void this.choose();
282
+ return;
283
+ }
284
+ else if (plain && !typing && input === 'r' && this.active.onRefresh) {
285
+ this.active.onRefresh();
286
+ return;
287
+ }
288
+ else if (plain && !typing && input === '/') {
289
+ // The search line's own key: a search can then start with a letter that moves or refreshes.
290
+ this.filterMode = true;
291
+ }
292
+ else if (plain && this.isPrintable(input)) {
293
+ this.filterMode = true;
294
+ this.filterText += input;
295
+ this.applyFilter();
296
+ }
297
+ else {
298
+ return;
299
+ }
300
+ this.host.render();
301
+ }
302
+ handleMouse(event) {
303
+ if (!this.active || !isInsideBand(this.listBand, event.x, event.y))
304
+ return false;
305
+ this.move(event.wheel === 'up' ? -1 : 1);
306
+ this.host.render();
307
+ return true;
308
+ }
309
+ isPrintable(input) {
310
+ if (!input || input.startsWith('\x1b') || input === '\x7f')
311
+ return false;
312
+ if (input.length === 1) {
313
+ const code = input.charCodeAt(0);
314
+ return code >= 0x20 && code !== 0x7f;
315
+ }
316
+ return !/[\r\n\t]/.test(input);
317
+ }
318
+ async choose() {
319
+ const active = this.active;
320
+ const entry = this.selectedRow();
321
+ if (!active || !entry || this.choosing) {
322
+ if (active && !entry)
323
+ this.host.setToast('No session selected');
324
+ return;
325
+ }
326
+ const key = rowKey(entry);
327
+ const armed = this.armed?.key === key ? this.armed : null;
328
+ const here = armed !== null && (armed.here || armed.asks === 'here');
329
+ const recent = armed !== null && (armed.recent || armed.asks === 'recent');
330
+ this.choosing = true;
331
+ let choice;
332
+ try {
333
+ choice = await active.onChoose(entry, here, recent);
334
+ }
335
+ catch {
336
+ choice = 'stay';
337
+ }
338
+ finally {
339
+ this.choosing = false;
340
+ }
341
+ if (this.active !== active)
342
+ return;
343
+ this.armed = choice === 'confirm-here' || choice === 'confirm-recent'
344
+ ? { key, asks: choice === 'confirm-here' ? 'here' : 'recent', here, recent }
345
+ : null;
346
+ this.host.render();
347
+ }
348
+ // ── Drawing ───────────────────────────────────────────────────────────────
349
+ label() {
350
+ return AGENT_CLIS[this.active.cli].label;
351
+ }
352
+ rowSegments(entry, selected, width, nowMs) {
353
+ const { session } = entry;
354
+ const open = entry.openInPane !== null;
355
+ const prefix = `${selected ? '▌' : ' '}${open ? '●' : ' '} ${padEndDisplay(clipText(shortAge(session.mtimeMs, nowMs), 5), 5)} `;
356
+ const prefixWidth = displayWidth(prefix);
357
+ const place = this.view === 'all' ? (session.cwd ? formatCwdTail(session.cwd) : '') : entry.inHere ?? '';
358
+ const meta = [];
359
+ const parts = [place, this.active.hasProfiles && session.profile ? `@${session.profile}` : ''].filter(Boolean);
360
+ if (parts.length > 0)
361
+ meta.push({ text: parts.join(' · '), style: { color: TERMINAL_THEME.subtle, dimColor: true } });
362
+ if (entry.folderMissing)
363
+ meta.push({ text: `${parts.length > 0 ? ' · ' : ''}folder gone`, style: { color: TERMINAL_THEME.attention } });
364
+ // The label wins the fight for space; the folder and sign-in go before it starves.
365
+ let metaWidth = displayWidth(meta.map(segment => segment.text).join(''));
366
+ const metaBudget = Math.max(0, Math.floor(width * 0.4) - 1);
367
+ const minimumLabel = Math.min(12, Math.max(4, Math.floor(width * 0.5)));
368
+ if (metaWidth > metaBudget || width - prefixWidth - metaWidth - 1 < minimumLabel) {
369
+ meta.length = 0;
370
+ metaWidth = 0;
371
+ }
372
+ const labelBudget = Math.max(1, width - prefixWidth - metaWidth - (metaWidth > 0 ? 1 : 0));
373
+ const title = clipText(session.title ?? '(no title)', labelBudget);
374
+ const segments = [
375
+ { text: prefix, style: { color: open ? TERMINAL_THEME.success : TERMINAL_THEME.borderSubtle } },
376
+ { text: title, style: { color: selected ? TERMINAL_THEME.text : TERMINAL_THEME.muted, bold: selected } },
377
+ ];
378
+ const used = prefixWidth + displayWidth(title);
379
+ segments.push({ text: ' '.repeat(Math.max(1, width - used - metaWidth)) });
380
+ return [...segments, ...meta];
381
+ }
382
+ /** What an empty view says: why there is nothing to list, and where else to look. */
383
+ emptyMessage() {
384
+ const active = this.active;
385
+ const label = this.label();
386
+ if (active.loading)
387
+ return `Reading ${label} sessions…`;
388
+ if (this.filterText.trim())
389
+ return 'No sessions match this search.';
390
+ if (this.view === 'here') {
391
+ return this.thisFolderLimited()
392
+ ? `None of the ${active.read ?? 0} newest ${label} sessions works in this folder. Codex's own /resume, in a /codex pane here, lists older ones. `
393
+ + '←→ shows all folders.'
394
+ : `No ${label} sessions in this folder. ←→ shows all folders.`;
395
+ }
396
+ const links = active.links ?? 0;
397
+ if (links > 0) {
398
+ return `ZTC found no ${label} sessions it can read: ${links === 1 ? 'a session folder is a symbolic link' : `${links} session folders are symbolic links`}, `
399
+ + `which ZTC doesn't follow. ${OWN_LIST[active.cli]}`;
400
+ }
401
+ const skipped = active.skipped ?? 0;
402
+ if (skipped > 0) {
403
+ return `None of the ${Math.max(active.read ?? 0, skipped)} newest ${label} session files is one to resume: ${skipped} ${skipped === 1 ? 'is' : 'are'} `
404
+ + `${LEFT_OUT[active.cli]}. ${OWN_LIST[active.cli]}`;
405
+ }
406
+ return `No ${label} sessions on this computer.`;
407
+ }
408
+ /** The list, or what an empty view says, wrapped to the width so none of it is cut. */
409
+ listRows(width, nowMs) {
410
+ const rows = this.visibleRows();
411
+ if (rows.length === 0) {
412
+ return wrapWords(this.emptyMessage(), width).map(line => [{ text: line, style: { color: TERMINAL_THEME.muted, dimColor: true } }]);
413
+ }
414
+ return rows.map((entry, index) => this.rowSegments(entry, index === this.selectedIndex, width, nowMs));
415
+ }
416
+ tabsLine(width) {
417
+ const segments = [];
418
+ for (const view of ['here', 'all']) {
419
+ const count = this.viewRows(view).length;
420
+ segments.push({
421
+ text: ` ${view === 'here' ? 'This folder' : 'All folders'} (${count}) `,
422
+ style: this.view === view ? { color: TERMINAL_THEME.info, bold: true, inverse: true } : { color: TERMINAL_THEME.muted },
423
+ });
424
+ segments.push({ text: ' ' });
425
+ }
426
+ const used = displayWidth(segments.map(segment => segment.text).join(''));
427
+ const hint = '←→ switch';
428
+ if (used + displayWidth(hint) + 2 <= width) {
429
+ segments.push({ text: ' '.repeat(width - used - displayWidth(hint)) });
430
+ segments.push({ text: hint, style: { color: TERMINAL_THEME.subtle, dimColor: true } });
431
+ }
432
+ return segments;
433
+ }
434
+ /** How many sessions were read, how many of this view are drawn when not all, and whether any reading fell short. */
435
+ statusText() {
436
+ const active = this.active;
437
+ if (active.loading)
438
+ return 'reading…';
439
+ const count = this.viewRows('all').length;
440
+ const parts = [`${count} session${count === 1 ? '' : 's'}`];
441
+ if (this.matchingRows().length > ROWS_PER_VIEW)
442
+ parts.push(`${ROWS_PER_VIEW} shown`);
443
+ if (active.partial)
444
+ parts.push('partial');
445
+ if (active.unreadable)
446
+ parts.push(`${active.unreadable} couldn't be read`);
447
+ if (active.links)
448
+ parts.push(`${active.links} linked folder${active.links === 1 ? '' : 's'} not read`);
449
+ return parts.join(' · ');
450
+ }
451
+ /** The highlighted session's facts (or the second ↵ it waits for), then the keys. */
452
+ footerLines() {
453
+ const active = this.active;
454
+ const entry = this.selectedRow();
455
+ const verb = active.mode === 'fork' ? 'fork' : 'resume';
456
+ const here = homeRelative(active.cwd, active.home);
457
+ const facts = () => {
458
+ if (!entry)
459
+ return '';
460
+ const { session } = entry;
461
+ const folder = session.cwd ? homeRelative(session.cwd, active.home) : 'folder unknown';
462
+ const signIn = session.profile ? `ZTC profile @${session.profile}` : `this computer's ${this.label()} sign-in`;
463
+ return `${folder} · ${signIn} · ${session.id.slice(0, 8)}${entry.openInPane !== null ? ` · open in pane ${entry.openInPane}` : ''}`;
464
+ };
465
+ if (entry && this.armed?.key === rowKey(entry)) {
466
+ if (this.armed.asks === 'recent') {
467
+ const age = recentAge(entry.session.mtimeMs, active.now ? active.now() : Date.now());
468
+ return [`Active ${age} ago: it may still be open in another pane or terminal · ↵ again ${verb}s it anyway`,
469
+ `↵ ${verb} anyway · Esc cancel`];
470
+ }
471
+ const gone = entry.session.cwd ? `${homeRelative(entry.session.cwd, active.home)} is gone` : 'Its folder is unknown';
472
+ return [`${gone} · ↵ again ${verb}s in ${here} · Esc cancel`, `↵ ${verb} in ${here} · Esc cancel`];
473
+ }
474
+ if (this.filterMode)
475
+ return [facts(), `Type to filter · ↵ ${verb} · Esc keep search · Ctrl+U clear`];
476
+ if (!entry)
477
+ return ['', '←→ view · / search · r refresh · Esc close'];
478
+ if (entry.openInPane !== null)
479
+ return [facts(), '↵ go to pane · ↑↓ move · ←→ view · / search · Esc close'];
480
+ return [facts(), `↑↓ move · ←→ view · / search · ↵ ${verb} · r refresh · Esc close`];
481
+ }
482
+ buildSurface(cols, maxRows) {
483
+ const lines = this.buildLines(cols, maxRows);
484
+ return { content: lines.map(lineText).join('\n'), view: buildWidgetFrameView(lines, this.frameInset), lineCount: lines.length };
485
+ }
486
+ buildContent(cols, maxRows) {
487
+ return this.buildSurface(cols, maxRows).content;
488
+ }
489
+ buildLines(cols, maxRows) {
490
+ const active = this.active;
491
+ if (!active || (maxRows !== undefined && maxRows <= 0))
492
+ return [];
493
+ const { width, inset } = widgetFrameGeometry(Math.max(1, Math.floor(cols || process.stdout.columns || 80)));
494
+ this.frameInset = inset;
495
+ const height = Math.max(1, Math.floor(maxRows ?? 20));
496
+ const innerWidth = Math.max(0, width - 4);
497
+ const nowMs = active.now ? active.now() : Date.now();
498
+ const rows = this.visibleRows();
499
+ this.selectedIndex = rows.length === 0 ? 0 : Math.min(this.selectedIndex, rows.length - 1);
500
+ const title = `${active.mode === 'fork' ? 'Fork' : 'Resume'} a ${this.label()} session${active.profile ? ` · @${active.profile}` : ''}`;
501
+ const lines = [topBorder(width, title, rows.length > 0 ? `${this.selectedIndex + 1}/${rows.length}` : '0/0')];
502
+ if (height <= 1)
503
+ return lines;
504
+ if (height === 2)
505
+ return [...lines, bottomBorder(width)];
506
+ const chrome = height >= 8;
507
+ const bodyRows = Math.max(1, height - (chrome ? 6 : 3));
508
+ this.lastBodyRows = bodyRows;
509
+ if (chrome) {
510
+ lines.push(framedLine(this.tabsLine(innerWidth), width, TERMINAL_THEME.bgElevated));
511
+ lines.push(framedLine([{
512
+ text: joinColumns(`/ Search: ${this.filterText || 'all'}${this.filterMode ? '█' : ''}`, this.statusText(), innerWidth),
513
+ style: this.filterMode ? { color: TERMINAL_THEME.info, bold: true } : { color: TERMINAL_THEME.muted },
514
+ }], width, TERMINAL_THEME.bgElevated));
515
+ }
516
+ const list = this.listRows(innerWidth, nowMs);
517
+ const capacity = Math.max(1, bodyRows - 1);
518
+ // Keep the highlighted row in view.
519
+ if (this.selectedIndex < this.listScrollOffset)
520
+ this.listScrollOffset = this.selectedIndex;
521
+ if (this.selectedIndex >= this.listScrollOffset + capacity)
522
+ this.listScrollOffset = this.selectedIndex - capacity + 1;
523
+ this.listScrollOffset = Math.max(0, Math.min(this.listScrollOffset, Math.max(0, list.length - capacity)));
524
+ const above = this.listScrollOffset;
525
+ const below = Math.max(0, list.length - above - capacity);
526
+ lines.push(framedLine([{
527
+ text: joinColumns(this.view === 'here' ? 'THIS FOLDER' : 'ALL FOLDERS', `${above > 0 ? `↑${above} ` : ''}${below > 0 ? `↓${below}` : ''}`, innerWidth),
528
+ style: { color: TERMINAL_THEME.subtle, bold: true },
529
+ }], width, TERMINAL_THEME.bgPanel));
530
+ const listTop = lines.length;
531
+ for (let index = 0; index < capacity; index += 1) {
532
+ lines.push(framedLine(list[above + index] ?? [], width));
533
+ }
534
+ this.listBand = bodyBand(listTop, lines.length - 1, innerWidth, this.frameInset);
535
+ const [details, hints] = this.footerLines();
536
+ if (chrome)
537
+ lines.push(framedLine([{ text: details, style: { color: TERMINAL_THEME.text } }], width, TERMINAL_THEME.bgElevated));
538
+ lines.push(framedLine([{ text: hints, style: { color: TERMINAL_THEME.muted, dimColor: true } }], width, TERMINAL_THEME.bgElevated));
539
+ lines.push(bottomBorder(width));
540
+ return lines.slice(0, height);
541
+ }
542
+ }
@@ -11,11 +11,13 @@ export interface LogViewSource {
11
11
  title: string;
12
12
  /**
13
13
  * Called with the number of lines already fetched.
14
- * Returns new lines since that offset and the new total.
14
+ * Returns new lines since that offset and the new total, or, with `notice`, why the source gives none: the view shows
15
+ * it in place of the log and asks no more until the person refreshes.
15
16
  */
16
17
  fetch: (since: number) => Promise<{
17
18
  lines: string[];
18
19
  total: number;
20
+ notice?: string;
19
21
  }>;
20
22
  }
21
23
  export declare class LogViewWidget {
@@ -37,6 +39,8 @@ export declare class LogViewWidget {
37
39
  private source;
38
40
  private pollTimer;
39
41
  private fetching;
42
+ /** Why the source gives no lines, when it said (see LogViewSource.fetch). */
43
+ private notice;
40
44
  private onCancel;
41
45
  constructor(host: WidgetHost);
42
46
  isActive(): boolean;
@@ -28,6 +28,8 @@ export class LogViewWidget {
28
28
  source = null;
29
29
  pollTimer = null;
30
30
  fetching = false;
31
+ /** Why the source gives no lines, when it said (see LogViewSource.fetch). */
32
+ notice = null;
31
33
  onCancel = null;
32
34
  constructor(host) {
33
35
  this.host = host;
@@ -37,6 +39,7 @@ export class LogViewWidget {
37
39
  }
38
40
  show(source, onCancel) {
39
41
  this.active = true;
42
+ this.notice = null;
40
43
  this.allLines = [];
41
44
  this.lineOffset = 0;
42
45
  this.scrollOffset = 0;
@@ -50,6 +53,7 @@ export class LogViewWidget {
50
53
  }
51
54
  cancel() {
52
55
  this.active = false;
56
+ this.notice = null;
53
57
  this.source = null;
54
58
  this.allLines = [];
55
59
  this.lineOffset = 0;
@@ -70,10 +74,21 @@ export class LogViewWidget {
70
74
  return;
71
75
  this.fetching = true;
72
76
  const since = this.lineOffset;
73
- this.source.fetch(since).then(({ lines, total }) => {
77
+ this.source.fetch(since).then(({ lines, total, notice }) => {
74
78
  this.fetching = false;
75
79
  if (!this.active)
76
80
  return;
81
+ if (notice !== undefined) {
82
+ // The source said why it gives no lines: show that, and stop asking it on a timer.
83
+ this.notice = notice;
84
+ if (this.pollTimer) {
85
+ clearInterval(this.pollTimer);
86
+ this.pollTimer = null;
87
+ }
88
+ this.host.render();
89
+ return;
90
+ }
91
+ this.notice = null;
77
92
  if (lines.length > 0) {
78
93
  this.allLines.push(...lines);
79
94
  // Ring: drop from front when over max
@@ -217,9 +232,12 @@ export class LogViewWidget {
217
232
  if (totalFiltered === 0) {
218
233
  const msg = this.filterText
219
234
  ? `No lines match filter: "${this.filterText}"`
220
- : (this.fetching ? 'Fetching logs…' : 'No log lines yet. Press r to refresh.');
221
- lines.push('│ ' + pad(msg) + ' │');
222
- for (let i = 1; i < availRows; i++) {
235
+ : (this.notice ?? (this.fetching ? 'Fetching logs…' : 'No log lines yet. Press r to refresh.'));
236
+ // A source's notice is read whole, so it wraps; the view's own messages fit a line.
237
+ const shown = this.notice !== null && !this.filterText ? wrapWords(msg, innerW).slice(0, availRows) : [msg];
238
+ for (const line of shown)
239
+ lines.push('│ ' + pad(line) + ' │');
240
+ for (let i = shown.length; i < availRows; i++) {
223
241
  lines.push('│ ' + ' '.repeat(innerW) + ' │');
224
242
  }
225
243
  }
@@ -290,6 +308,24 @@ export class LogViewWidget {
290
308
  return true;
291
309
  }
292
310
  }
311
+ /** TEXT broken at spaces into lines of at most WIDTH characters (a longer word is cut). */
312
+ function wrapWords(text, width) {
313
+ const lines = [];
314
+ let line = '';
315
+ for (const word of text.split(/\s+/).filter(Boolean)) {
316
+ const next = line ? `${line} ${word}` : word;
317
+ if (next.length <= width) {
318
+ line = next;
319
+ continue;
320
+ }
321
+ if (line)
322
+ lines.push(line);
323
+ line = word.length <= width ? word : word.slice(0, width);
324
+ }
325
+ if (line)
326
+ lines.push(line);
327
+ return lines.length > 0 ? lines : [''];
328
+ }
293
329
  /** Strip/classify log line — return plain text for terminal rendering. */
294
330
  function colorTag(line, maxW) {
295
331
  // Just truncate — terminal has no color codes here, host renders raw.