@zergai/ztc 0.23.1-dev.202611152321 → 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 (149) 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-computer-darwin-arm64 +0 -0
  6. package/bin/ztc-llm-darwin-arm64 +0 -0
  7. package/bin/ztc-tts-darwin-arm64 +0 -0
  8. package/bin/ztc-tui-darwin-arm64 +0 -0
  9. package/bin/zterm-darwin-arm64 +2 -2
  10. package/dist/agent/agent.js +57 -14
  11. package/dist/agent/backends/http_error.d.ts +2 -0
  12. package/dist/agent/backends/http_error.js +2 -0
  13. package/dist/agent/backends/router_gate.d.ts +3 -2
  14. package/dist/agent/backends/router_gate.js +5 -4
  15. package/dist/agent/backends/router_keys.d.ts +14 -0
  16. package/dist/agent/backends/router_keys.js +19 -0
  17. package/dist/agent/backends/router_refusal.d.ts +5 -3
  18. package/dist/agent/backends/router_refusal.js +28 -6
  19. package/dist/agent/backends/types.d.ts +1 -1
  20. package/dist/agent/backends/zrouter_stream.js +10 -6
  21. package/dist/agent/commands/agent_cli.d.ts +11 -1
  22. package/dist/agent/commands/agent_cli.js +295 -38
  23. package/dist/agent/commands/diff.js +4 -1
  24. package/dist/agent/commands/help.js +4 -1
  25. package/dist/agent/commands/plan.js +3 -1
  26. package/dist/agent/commands/session_redaction.d.ts +16 -0
  27. package/dist/agent/commands/session_redaction.js +77 -0
  28. package/dist/agent/commands/settings.js +144 -0
  29. package/dist/agent/commands/types.d.ts +5 -0
  30. package/dist/agent/commands/usage_spec.d.ts +4 -0
  31. package/dist/agent/commands/usage_spec.js +10 -4
  32. package/dist/agent/runtime/policy.d.ts +25 -0
  33. package/dist/agent/runtime/policy.js +154 -26
  34. package/dist/agent/runtime/source_verification.js +6 -2
  35. package/dist/agent/runtime/tool_runtime.js +81 -3
  36. package/dist/agent/tools/apply_patch.js +678 -131
  37. package/dist/agent/tools/bus_message.d.ts +26 -1
  38. package/dist/agent/tools/bus_message.js +126 -10
  39. package/dist/agent/tools/file.d.ts +16 -1
  40. package/dist/agent/tools/file.js +43 -5
  41. package/dist/agent/tools/index.d.ts +1 -1
  42. package/dist/agent/tools/index.js +1 -1
  43. package/dist/agent/tools/pane.js +5 -0
  44. package/dist/agent/tools/search.js +5 -1
  45. package/dist/agent/tools/supervision.js +16 -2
  46. package/dist/agent/tools/types.d.ts +22 -0
  47. package/dist/app/mirror_startup.d.ts +7 -5
  48. package/dist/app/mirror_startup.js +7 -5
  49. package/dist/app/navigator_mirrors.d.ts +20 -0
  50. package/dist/app/navigator_mirrors.js +36 -0
  51. package/dist/app/workspace_layout_controller.d.ts +11 -2
  52. package/dist/app/workspace_layout_controller.js +13 -2
  53. package/dist/batch/worktree.js +9 -1
  54. package/dist/cli_ratatui.d.ts +264 -12
  55. package/dist/cli_ratatui.js +1198 -103
  56. package/dist/config/types.d.ts +29 -0
  57. package/dist/desktop/daily/source_baseline.js +3 -1
  58. package/dist/diagnostics/session_export.d.ts +1 -0
  59. package/dist/diagnostics/session_export.js +229 -26
  60. package/dist/emulation/tool_adapters.js +42 -5
  61. package/dist/headless.js +24 -5
  62. package/dist/instance_registry.d.ts +7 -0
  63. package/dist/mcp/workspace_server.d.ts +12 -1
  64. package/dist/mcp/workspace_server.js +75 -8
  65. package/dist/panes/agent_cli.d.ts +60 -3
  66. package/dist/panes/agent_cli.js +169 -16
  67. package/dist/panes/agent_pane_sessions.d.ts +22 -0
  68. package/dist/panes/agent_pane_sessions.js +111 -0
  69. package/dist/panes/agent_panes.d.ts +77 -3
  70. package/dist/panes/agent_panes.js +199 -10
  71. package/dist/panes/agent_profiles.d.ts +5 -0
  72. package/dist/panes/agent_profiles.js +7 -0
  73. package/dist/panes/agent_resume.d.ts +134 -0
  74. package/dist/panes/agent_resume.js +155 -0
  75. package/dist/panes/agent_sessions/claude_head.d.ts +32 -0
  76. package/dist/panes/agent_sessions/claude_head.js +122 -0
  77. package/dist/panes/agent_sessions/claude_store.d.ts +59 -0
  78. package/dist/panes/agent_sessions/claude_store.js +223 -0
  79. package/dist/panes/agent_sessions/codex_head.d.ts +55 -0
  80. package/dist/panes/agent_sessions/codex_head.js +161 -0
  81. package/dist/panes/agent_sessions/codex_store.d.ts +43 -0
  82. package/dist/panes/agent_sessions/codex_store.js +187 -0
  83. package/dist/panes/agent_sessions/controller.d.ts +74 -0
  84. package/dist/panes/agent_sessions/controller.js +110 -0
  85. package/dist/panes/agent_sessions/cut_json.d.ts +14 -0
  86. package/dist/panes/agent_sessions/cut_json.js +109 -0
  87. package/dist/panes/agent_sessions/limits.d.ts +48 -0
  88. package/dist/panes/agent_sessions/limits.js +48 -0
  89. package/dist/panes/agent_sessions/scan.d.ts +49 -0
  90. package/dist/panes/agent_sessions/scan.js +86 -0
  91. package/dist/panes/agent_sessions/store_fs.d.ts +51 -0
  92. package/dist/panes/agent_sessions/store_fs.js +128 -0
  93. package/dist/panes/agent_sessions/stores.d.ts +36 -0
  94. package/dist/panes/agent_sessions/stores.js +89 -0
  95. package/dist/panes/agent_sessions/title.d.ts +9 -0
  96. package/dist/panes/agent_sessions/title.js +51 -0
  97. package/dist/panes/agent_sessions/types.d.ts +48 -0
  98. package/dist/panes/agent_sessions/types.js +2 -0
  99. package/dist/panes/reply_arbitrator.d.ts +39 -0
  100. package/dist/panes/reply_arbitrator.js +185 -0
  101. package/dist/panes/reply_modes.d.ts +291 -0
  102. package/dist/panes/reply_modes.js +598 -0
  103. package/dist/runtime_info.js +11 -2
  104. package/dist/session.js +4 -2
  105. package/dist/simulation/living/context.d.ts +8 -8
  106. package/dist/simulation/living/types.d.ts +5 -5
  107. package/dist/simulation/toolkit/dynamic_state.d.ts +1 -1
  108. package/dist/ui/ratatui/ipc_path.d.ts +5 -0
  109. package/dist/ui/ratatui/ipc_path.js +23 -3
  110. package/dist/ui/ratatui/pane_credential_broker.d.ts +23 -8
  111. package/dist/ui/ratatui/pane_credential_broker.js +49 -14
  112. package/dist/ui/ratatui/pane_relay.d.ts +5 -2
  113. package/dist/ui/ratatui/pane_relay.js +86 -19
  114. package/dist/ui/ratatui/process.js +3 -0
  115. package/dist/ui/ratatui/protocol.d.ts +50 -1
  116. package/dist/ui/ratatui/protocol.js +56 -0
  117. package/dist/ui/ratatui/relay_policy.d.ts +39 -0
  118. package/dist/ui/ratatui/relay_policy.js +94 -0
  119. package/dist/ui/ratatui/screen_privacy.d.ts +15 -0
  120. package/dist/ui/ratatui/screen_privacy.js +24 -0
  121. package/dist/ui/scrollback.js +8 -0
  122. package/dist/ui/widgets/agent_sessions_panel.d.ts +139 -0
  123. package/dist/ui/widgets/agent_sessions_panel.js +542 -0
  124. package/dist/ui/widgets/log_view.d.ts +5 -1
  125. package/dist/ui/widgets/log_view.js +40 -4
  126. package/dist/utils/atomic_write.js +9 -11
  127. package/dist/utils/canonical_path.d.ts +19 -0
  128. package/dist/utils/canonical_path.js +44 -0
  129. package/dist/utils/compaction.d.ts +2 -1
  130. package/dist/utils/compaction.js +3 -1
  131. package/dist/utils/git_directory_names.d.ts +51 -0
  132. package/dist/utils/git_directory_names.js +429 -0
  133. package/dist/utils/temporary_write_root.d.ts +6 -1
  134. package/dist/utils/temporary_write_root.js +32 -2
  135. package/dist/utils/tool_result_message.d.ts +4 -1
  136. package/dist/utils/tool_result_message.js +6 -2
  137. package/dist/web/bus_hold.d.ts +70 -0
  138. package/dist/web/bus_hold.js +118 -0
  139. package/dist/web/mirror_client.d.ts +7 -3
  140. package/dist/web/mirror_client.js +61 -23
  141. package/dist/web/mirror_route_gate.d.ts +40 -0
  142. package/dist/web/mirror_route_gate.js +71 -0
  143. package/dist/web/mirror_stream.d.ts +147 -22
  144. package/dist/web/mirror_stream.js +350 -83
  145. package/dist/web/pane_credentials.d.ts +32 -1
  146. package/dist/web/pane_credentials.js +62 -2
  147. package/dist/workspace_collision.js +11 -2
  148. package/dist/zlm-embed.mjs +940 -273
  149. package/package.json +39 -7
@@ -5,11 +5,36 @@
5
5
  * from cli_ratatui.ts at startup.
6
6
  */
7
7
  import { Tool } from './types.js';
8
+ import type { BusSendResult } from '../../web/mirror_client.js';
9
+ import type { BusMessage, MirrorStreamServer } from '../../web/mirror_stream.js';
10
+ import { type ReplyModeHost } from '../../panes/reply_modes.js';
8
11
  export interface BusTransport {
9
- sendBusMessage(to: number | 'all', text: string, type?: 'user_input' | 'ztc_message'): void;
12
+ /**
13
+ * Send TEXT to pane TO (or every agent on the bus), and say what became of it: a ZTC pane's mirror client resolves with
14
+ * the mirror's answer, and the ZTC that runs the bus returns its mirror's (overseerBusTransport). The mirror holds a
15
+ * message for a ZTC pane that hasn't joined the bus yet, and refuses one for a pane that runs no agent, or one that
16
+ * doesn't fit in what a pane holds. A transport with no mirror to ask returns nothing.
17
+ */
18
+ sendBusMessage(to: number | 'all', text: string, type?: 'user_input' | 'ztc_message'): void | BusSendResult | Promise<BusSendResult>;
10
19
  getPaneId(): number;
11
20
  getPaneName(): string;
21
+ /**
22
+ * Main's only: it answers the Claude Code and Codex panes in its workspace by itself, so a message its model sends one
23
+ * sets or joins their exchange and its reply mode (panes/reply_modes.ts). A ZTC that answers no pane has none.
24
+ */
25
+ replyModes?: ReplyModeHost;
12
26
  }
27
+ /**
28
+ * The bus transport of the ZTC that runs the bus (Main, bus member 0). It sends as Main through the mirror it runs at
29
+ * the time (MIRROR): the one it started with, or the one /mirror start started, whose bus its panes' mirror clients
30
+ * rejoin; never one /mirror stop stopped, whose bus is gone. It says what the mirror did with the message, as /bus/send
31
+ * answers a pane. While it runs none, OFF_BUS gets the message, which the owner types into the panes it is for, and it
32
+ * says nothing.
33
+ *
34
+ * NAME is what Main is called as each message leaves: the name its pane goes by, which list_panes and the pane's header
35
+ * give it, "Main" or the one /rename gave it, so an agent that reads the message can answer Main by it.
36
+ */
37
+ export declare function overseerBusTransport(mirror: () => MirrorStreamServer | null, offBus: (message: BusMessage) => void, name?: () => string): BusTransport;
13
38
  export declare function setBusTransport(transport: BusTransport): void;
14
39
  export declare function clearBusTransport(): void;
15
40
  export declare function getBusTransport(): BusTransport | null;
@@ -4,8 +4,47 @@
4
4
  * Uses a setter pattern (like pane tools) so the transport can be wired
5
5
  * from cli_ratatui.ts at startup.
6
6
  */
7
+ import { randomUUID } from 'node:crypto';
7
8
  import { readPaneResponseSnapshot } from '../../utils/pane_response.js';
8
9
  import { listWorkspacePanes, resolvePaneIdByName } from './pane.js';
10
+ import { MAX_REPLY_CAP, parseReplyMode, ReplyModeError } from '../../panes/reply_modes.js';
11
+ /** The tool's answer when the mirror refused a message for RECIPIENT, in the mirror's words; null when it took it. */
12
+ function refusal(sent, recipient) {
13
+ return sent && !sent.ok ? `Error: the message to ${recipient} wasn't sent. ${sent.error}` : null;
14
+ }
15
+ /**
16
+ * The tool's answer when the mirror holds the message for pane TO, still starting, until it joins the bus, in the
17
+ * mirror's words; null when it delivered it. With ANSWERS (a question or a request), the answer comes later, as a message
18
+ * from that pane once it has joined and answered: nothing waits for it here.
19
+ */
20
+ function heldAnswer(sent, to, answers) {
21
+ if (!sent || !sent.ok || !sent.held)
22
+ return null;
23
+ return answers ? `${sent.notice} Its answer comes back to you as a message from pane ${to}.` : sent.notice;
24
+ }
25
+ /**
26
+ * The bus transport of the ZTC that runs the bus (Main, bus member 0). It sends as Main through the mirror it runs at
27
+ * the time (MIRROR): the one it started with, or the one /mirror start started, whose bus its panes' mirror clients
28
+ * rejoin; never one /mirror stop stopped, whose bus is gone. It says what the mirror did with the message, as /bus/send
29
+ * answers a pane. While it runs none, OFF_BUS gets the message, which the owner types into the panes it is for, and it
30
+ * says nothing.
31
+ *
32
+ * NAME is what Main is called as each message leaves: the name its pane goes by, which list_panes and the pane's header
33
+ * give it, "Main" or the one /rename gave it, so an agent that reads the message can answer Main by it.
34
+ */
35
+ export function overseerBusTransport(mirror, offBus, name = () => 'Main') {
36
+ return {
37
+ sendBusMessage: (to, text, type = 'ztc_message') => {
38
+ const message = { id: randomUUID(), from: { id: 0, name: name() }, to, type, text };
39
+ const server = mirror();
40
+ if (server)
41
+ return server.busSendResult(server.deliverBusMessage(message), to);
42
+ offBus(message);
43
+ },
44
+ getPaneId() { return 0; },
45
+ getPaneName() { return name(); },
46
+ };
47
+ }
9
48
  // --- Setter-based transport access ---
10
49
  let busTransportRef = null;
11
50
  export function setBusTransport(transport) {
@@ -71,6 +110,58 @@ function buildZtcRequestPayload(text, kind) {
71
110
  replyToName: busTransportRef.getPaneName(),
72
111
  });
73
112
  }
113
+ /**
114
+ * The reply_mode a ZTC tool was given (ARGS.reply_mode: "uncapped", "capped:N", "arbitrator:NAME", or the same as JSON),
115
+ * or none; an Error, said as the tool's answer, when it isn't one, or names an arbitrator the person didn't set up (HOST
116
+ * knows which they did).
117
+ */
118
+ function toolReplyMode(args, host) {
119
+ const raw = args.reply_mode;
120
+ if (raw === undefined || raw === null || (typeof raw === 'string' && raw.trim() === ''))
121
+ return undefined;
122
+ let mode;
123
+ try {
124
+ mode = parseReplyMode(raw);
125
+ }
126
+ catch (error) {
127
+ if (error instanceof ReplyModeError)
128
+ return new Error(`Error: the message wasn't sent. ${error.message}`);
129
+ throw error;
130
+ }
131
+ const refused = host?.refusal(mode);
132
+ return refused ? new Error(`Error: the message wasn't sent. ${refused}`) : mode;
133
+ }
134
+ /**
135
+ * What a sent message did to the exchange with pane TO, for the tool's answer: Main (HOST) records a message for a
136
+ * Claude Code or Codex pane it answers, with MODE or none, and says what became of a mode it was given; anywhere else a
137
+ * mode has no effect, which the answer says.
138
+ */
139
+ function replyModeNote(host, to, text, mode) {
140
+ if (host && typeof to === 'number' && host.answers(to)) {
141
+ const said = host.sent(to, text, mode);
142
+ return said ? ` ${said}` : '';
143
+ }
144
+ if (mode === undefined)
145
+ return '';
146
+ return host
147
+ ? ' Its reply_mode had no effect: a reply mode is for a message to a Claude Code or Codex pane, which Main answers by itself.'
148
+ : ' Its reply_mode had no effect: only Main, the ZTC that runs this workspace (pane 0), answers Claude Code and Codex panes by itself.';
149
+ }
150
+ /** reply_mode, as ZTC's send_message and ask_ztc_pane take it. */
151
+ const REPLY_MODE_PARAMETER = {
152
+ type: 'string',
153
+ description: 'For a message to a Claude Code or Codex pane: how ZTC answers that pane by itself in the exchange this message '
154
+ + 'starts, the run of messages back and forth between you and it. Each time a turn on a message from that pane ends, ZTC types '
155
+ + 'your answer into the pane, and the agent there may answer that. "uncapped": every message. "capped:N" (N from 1 to '
156
+ + `${MAX_REPLY_CAP}): N automatic answers with no message from the person, the last saying "no more automatic answers in this `
157
+ + 'exchange"; then the pane\'s messages wait for the person until their next message here, or until you send a different '
158
+ + 'reply_mode. "arbitrator:NAME": before each automatic answer after the first, the arbitrator decides whether the exchange '
159
+ + 'goes on, and each decision shows in pane 0; NAME is "model" (your own model) or an arbitrator the person set up in /settings, '
160
+ + 'and any other name is refused; its timeout, error or unreadable answer stops the exchange. Omitted: the person\'s default '
161
+ + '(capped:5 unless they changed it). Only the pane that starts an exchange sets its mode, so in one the other pane started, '
162
+ + 'yours is not applied, and the answer says so; the same mode again changes nothing. Only Main answers these panes by itself, '
163
+ + 'so from a ZTC pane it has no effect.',
164
+ };
74
165
  // --- Tool ---
75
166
  // Tool descriptions are mode-sensitive: sim free-mode runs LLMs in-character as
76
167
  // fictional people, where dev-flavored phrasing ("ZTC instances", "zmux", "panes")
@@ -128,6 +219,7 @@ export const sendMessageTool = {
128
219
  type: 'string',
129
220
  description: 'When kind="reply", the id of the question/request you are answering (see [QUESTIONS AWAITING YOUR REPLY] in your prompt).',
130
221
  },
222
+ ...(process.env.ZTC_SIM_FREE_MODE ? {} : { reply_mode: REPLY_MODE_PARAMETER }),
131
223
  },
132
224
  required: ['to', 'text'],
133
225
  },
@@ -140,6 +232,10 @@ export const sendMessageTool = {
140
232
  if (!text) {
141
233
  return 'Error: text is required.';
142
234
  }
235
+ const replyHost = busTransportRef.replyModes;
236
+ const replyMode = process.env.ZTC_SIM_FREE_MODE ? undefined : toolReplyMode(args, replyHost);
237
+ if (replyMode instanceof Error)
238
+ return replyMode.message;
143
239
  const recipientKindRaw = String(args.recipient_kind || '').trim().toLowerCase();
144
240
  if (process.env.ZTC_SIM_FREE_MODE && recipientKindRaw === 'external') {
145
241
  const externalIdRaw = String(args.to || '').trim();
@@ -199,25 +295,33 @@ export const sendMessageTool = {
199
295
  // reply written right after delivery is never mistaken for the baseline.
200
296
  const baseline = asks ? readPaneResponseSnapshot(to) : null;
201
297
  const outgoingText = asks ? buildZtcRequestPayload(text, kind) : text;
202
- busTransportRef.sendBusMessage(to, outgoingText, 'ztc_message');
298
+ const sent = await busTransportRef.sendBusMessage(to, outgoingText, 'ztc_message');
299
+ const refused = refusal(sent, recipient);
300
+ if (refused)
301
+ return refused;
302
+ // A message that reached the pane sets or joins its exchange with Main, and the answer says what that did.
303
+ const replyNote = replyModeNote(replyHost, to, text, replyMode);
304
+ const held = heldAnswer(sent, to, asks);
305
+ if (held)
306
+ return `${held}${replyNote}`;
203
307
  const external = asks ? await nonZtcPaneName(to) : null;
204
308
  if (external !== null) {
205
- return `${kind === 'question' ? 'Question' : 'Request'} sent to ${external} (pane ${to}). It is not a ZTC agent, so its answer arrives later as a message from that pane.`;
309
+ return `${kind === 'question' ? 'Question' : 'Request'} sent to ${external} (pane ${to}). It is not a ZTC agent, so its answer arrives later as a message from that pane.${replyNote}`;
206
310
  }
207
311
  const waitForResponse = asks;
208
312
  if (waitForResponse && baseline) {
209
313
  try {
210
314
  const response = await waitForNewPaneResponse(to, baseline, 90_000);
211
- return `Response from ${recipient}:\n${response}`;
315
+ return `Response from ${recipient}:\n${response}${replyNote}`;
212
316
  }
213
317
  catch (err) {
214
- return `Message sent to ${recipient}, but no completed response arrived within 90s: ${err.message}`;
318
+ return `Message sent to ${recipient}, but no completed response arrived within 90s: ${err.message}${replyNote}`;
215
319
  }
216
320
  }
217
321
  if (to === 'all') {
218
- return `Message broadcast to all ZTCs: "${text.slice(0, 100)}${text.length > 100 ? '...' : ''}"`;
322
+ return `Message broadcast to all ZTCs: "${text.slice(0, 100)}${text.length > 100 ? '...' : ''}"${replyNote}`;
219
323
  }
220
- return `Message sent to ${recipient}: "${text.slice(0, 100)}${text.length > 100 ? '...' : ''}"`;
324
+ return `Message sent to ${recipient}: "${text.slice(0, 100)}${text.length > 100 ? '...' : ''}"${replyNote}`;
221
325
  },
222
326
  };
223
327
  export const contactExternalTool = {
@@ -299,6 +403,7 @@ export const askZtcPaneTool = {
299
403
  type: 'number',
300
404
  description: 'How long to wait for a new child response. Defaults to 90, max 300.',
301
405
  },
406
+ reply_mode: REPLY_MODE_PARAMETER,
302
407
  },
303
408
  required: ['pane_id', 'text'],
304
409
  },
@@ -324,22 +429,33 @@ export const askZtcPaneTool = {
324
429
  if (!text) {
325
430
  return 'Error: text is required.';
326
431
  }
432
+ const replyHost = busTransportRef.replyModes;
433
+ const replyMode = toolReplyMode(args, replyHost);
434
+ if (replyMode instanceof Error)
435
+ return replyMode.message;
327
436
  const timeoutRaw = Number(args.timeout_seconds ?? 90);
328
437
  const timeoutSeconds = Number.isFinite(timeoutRaw)
329
438
  ? Math.min(Math.max(Math.round(timeoutRaw), 5), 300)
330
439
  : 90;
331
440
  const baseline = readPaneResponseSnapshot(paneId);
332
- busTransportRef.sendBusMessage(paneId, buildZtcRequestPayload(text, 'request'), 'ztc_message');
441
+ const sent = await busTransportRef.sendBusMessage(paneId, buildZtcRequestPayload(text, 'request'), 'ztc_message');
442
+ const refused = refusal(sent, `ZTC ${paneId}`);
443
+ if (refused)
444
+ return refused;
445
+ const replyNote = replyModeNote(replyHost, paneId, text, replyMode);
446
+ const held = heldAnswer(sent, paneId, true);
447
+ if (held)
448
+ return `${held}${replyNote}`;
333
449
  const external = await nonZtcPaneName(paneId);
334
450
  if (external !== null) {
335
- return `Sent to ${external} (pane ${paneId}). It is not a ZTC agent, so its answer arrives later as a message from that pane.`;
451
+ return `Sent to ${external} (pane ${paneId}). It is not a ZTC agent, so its answer arrives later as a message from that pane.${replyNote}`;
336
452
  }
337
453
  try {
338
454
  const response = await waitForNewPaneResponse(paneId, baseline, timeoutSeconds * 1000);
339
- return `Response from ZTC ${paneId}:\n${response}`;
455
+ return `Response from ZTC ${paneId}:\n${response}${replyNote}`;
340
456
  }
341
457
  catch (err) {
342
- return `Error: ${err.message}`;
458
+ return `Error: ${err.message}${replyNote}`;
343
459
  }
344
460
  },
345
461
  };
@@ -1,5 +1,18 @@
1
1
  import { Tool, ToolContext } from './types.js';
2
2
  export declare function resolvePath(path: string, context?: ToolContext): string;
3
+ /**
4
+ * A tool's `path` argument as the policy judged it: a string. Another value is refused, never turned into a path:
5
+ * String(['../x']) is '../x', which the policy, reading only strings, never saw.
6
+ */
7
+ export declare function stringPathArgument(args: Record<string, unknown>, tool: string): string;
8
+ /** The path the runtime's write admission checks for a resolved tool path: in Docker mode, relative to the
9
+ * container's working directory, as the host policy sees a relative `path` there. */
10
+ export declare function writeAdmissionPath(path: string): string;
11
+ /**
12
+ * Admit a write of `path` once more, inside its path lock and just before the write: the filesystem may have changed
13
+ * since dispatch (a directory swapped for a symlink that leads out).
14
+ */
15
+ export declare function admitLockedWrite(path: string, label: string, context?: ToolContext): Promise<void>;
3
16
  export declare const readFileTool: Tool;
4
17
  export declare const writeFileTool: Tool;
5
18
  /**
@@ -19,7 +32,9 @@ export declare function readRawFile(path: string): Promise<string>;
19
32
  * Shared by edit_file and the Edit/MultiEdit emulation fallbacks so the three
20
33
  * cannot drift.
21
34
  */
22
- export declare function updateFileAtomic(path: string, mutate: (content: string) => string): Promise<{
35
+ export declare function updateFileAtomic(path: string, mutate: (content: string) => string,
36
+ /** Runs inside the lock before the read: the caller's last admission of the write. */
37
+ admit?: () => Promise<void>): Promise<{
23
38
  before: string;
24
39
  after: string;
25
40
  sha256: string;
@@ -111,10 +111,41 @@ export function resolvePath(path, context) {
111
111
  const base = context?.cwd || process.cwd();
112
112
  return resolve(base, expanded);
113
113
  }
114
+ /**
115
+ * A tool's `path` argument as the policy judged it: a string. Another value is refused, never turned into a path:
116
+ * String(['../x']) is '../x', which the policy, reading only strings, never saw.
117
+ */
118
+ export function stringPathArgument(args, tool) {
119
+ const value = args.path;
120
+ if (value === undefined || value === null)
121
+ throw new Error(`${tool}: path argument is required but was not provided`);
122
+ if (typeof value !== 'string')
123
+ throw new Error(`${tool}: path argument must be a string`);
124
+ return value;
125
+ }
114
126
  async function assertTemporaryWriteAllowed(path, context) {
115
127
  if (context?.temporaryWriteRoot === undefined)
116
128
  return;
117
- await assertTemporaryWritePathAllowed(path, context.temporaryWriteRoot, 'write_file');
129
+ await assertTemporaryWritePathAllowed(path, context.temporaryWriteRoot, 'write_file', context.cwd);
130
+ }
131
+ /** The path the runtime's write admission checks for a resolved tool path: in Docker mode, relative to the
132
+ * container's working directory, as the host policy sees a relative `path` there. */
133
+ export function writeAdmissionPath(path) {
134
+ return DOCKER_CONTAINER ? posix.relative(DOCKER_WORKDIR, path) || '.' : path;
135
+ }
136
+ /** The file a write_file or edit_file call writes, for the runtime's admission before dispatch. */
137
+ async function filePathTarget(args, context) {
138
+ if (args.path === undefined || args.path === null)
139
+ return [];
140
+ return [{ path: writeAdmissionPath(resolvePath(String(args.path), context)), label: String(args.path) }];
141
+ }
142
+ /**
143
+ * Admit a write of `path` once more, inside its path lock and just before the write: the filesystem may have changed
144
+ * since dispatch (a directory swapped for a symlink that leads out).
145
+ */
146
+ export async function admitLockedWrite(path, label, context) {
147
+ await assertTemporaryWriteAllowed(path, context);
148
+ context?.admitWrites?.([{ path: writeAdmissionPath(path), label }]);
118
149
  }
119
150
  // --- File Tools ---
120
151
  export const readFileTool = {
@@ -149,7 +180,7 @@ export const readFileTool = {
149
180
  }
150
181
  },
151
182
  execute: async (args, context) => {
152
- const path = resolvePath(String(args.path), context);
183
+ const path = resolvePath(stringPathArgument(args, 'read_file'), context);
153
184
  for (const name of ['offset', 'limit']) {
154
185
  const value = args[name];
155
186
  if (value !== undefined && (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 1)) {
@@ -308,6 +339,7 @@ export const writeFileTool = {
308
339
  required: ['path', 'content']
309
340
  }
310
341
  },
342
+ writePaths: filePathTarget,
311
343
  execute: async (args, context) => {
312
344
  if (args.path === undefined || args.path === null) {
313
345
  throw new Error('write_file: path argument is required but was not provided');
@@ -332,6 +364,7 @@ export const writeFileTool = {
332
364
  // response would otherwise both read the pre-write content and the
333
365
  // second write would silently discard the first.
334
366
  const written = await withPathLock(path, async () => {
367
+ await admitLockedWrite(path, String(args.path), context);
335
368
  const dir = posix.dirname(path);
336
369
  await dockerExec(`mkdir -p ${shellEscape(dir)}`);
337
370
  let before = '';
@@ -363,6 +396,7 @@ export const writeFileTool = {
363
396
  // atomically, then verify against disk.
364
397
  const { mkdir } = await import('fs/promises');
365
398
  const written = await withPathLock(path, async () => {
399
+ await admitLockedWrite(path, String(args.path), context);
366
400
  await mkdir(dirname(path), { recursive: true });
367
401
  let before = '';
368
402
  try {
@@ -465,8 +499,11 @@ function parseBooleanFlag(value) {
465
499
  * Shared by edit_file and the Edit/MultiEdit emulation fallbacks so the three
466
500
  * cannot drift.
467
501
  */
468
- export async function updateFileAtomic(path, mutate) {
502
+ export async function updateFileAtomic(path, mutate,
503
+ /** Runs inside the lock before the read: the caller's last admission of the write. */
504
+ admit) {
469
505
  return withPathLock(path, async () => {
506
+ await admit?.();
470
507
  const before = await readRawFile(path);
471
508
  const after = mutate(before);
472
509
  await writeRawFile(path, after);
@@ -500,6 +537,7 @@ export const editFileTool = {
500
537
  required: ['path', 'old_string', 'new_string'],
501
538
  },
502
539
  },
540
+ writePaths: filePathTarget,
503
541
  execute: async (args, context) => {
504
542
  if (args.path === undefined || args.path === null) {
505
543
  throw new Error('edit_file: path argument is required but was not provided');
@@ -517,7 +555,7 @@ export const editFileTool = {
517
555
  let after;
518
556
  let digest;
519
557
  try {
520
- const updated = await updateFileAtomic(path, content => applyExactReplace(content, args.old_string, args.new_string, replaceAll));
558
+ const updated = await updateFileAtomic(path, content => applyExactReplace(content, args.old_string, args.new_string, replaceAll), () => admitLockedWrite(path, String(args.path), context));
521
559
  before = updated.before;
522
560
  after = updated.after;
523
561
  digest = updated.sha256;
@@ -568,7 +606,7 @@ export const listDirectoryTool = {
568
606
  }
569
607
  },
570
608
  execute: async (args, context) => {
571
- const path = resolvePath(String(args.path), context);
609
+ const path = resolvePath(stringPathArgument(args, 'list_directory'), context);
572
610
  const recursive = parseBooleanFlag(args.recursive);
573
611
  if (DOCKER_CONTAINER) {
574
612
  // Docker mode: use docker exec to list directory
@@ -25,7 +25,7 @@ export { applyPatchTool } from './apply_patch.js';
25
25
  export type { AskUserData, AskUserOption, AskUserQuestion } from './ask_user.js';
26
26
  export { paneTools, setPaneToolsTuiProcess, clearPaneToolsTuiProcess, setPaneToolsOwnId, setPaneToolsExitCallback, setPaneToolsMirrorCallback, setPaneToolsZdeLiteCallback, setPaneToolsPendingLaunchCallback, clearPaneToolsPendingLaunchCallback } from './pane.js';
27
27
  export { supervisionTools, setSupervisionManager, clearSupervisionManager, getSupervisionManager } from './supervision.js';
28
- export { sendMessageTool, askZtcPaneTool, contactExternalTool, setBusTransport, clearBusTransport, getBusTransport } from './bus_message.js';
28
+ export { sendMessageTool, askZtcPaneTool, contactExternalTool, setBusTransport, clearBusTransport, getBusTransport, overseerBusTransport } from './bus_message.js';
29
29
  export type { BusTransport } from './bus_message.js';
30
30
  export declare const busTools: Tool[];
31
31
  export { proposeWorldMutationTool } from './world_mutation.js';
@@ -45,7 +45,7 @@ export { askUserTool, setAskUserCallback, clearAskUserCallback, resetAskUserTurn
45
45
  export { applyPatchTool } from './apply_patch.js';
46
46
  export { paneTools, setPaneToolsTuiProcess, clearPaneToolsTuiProcess, setPaneToolsOwnId, setPaneToolsExitCallback, setPaneToolsMirrorCallback, setPaneToolsZdeLiteCallback, setPaneToolsPendingLaunchCallback, clearPaneToolsPendingLaunchCallback } from './pane.js';
47
47
  export { supervisionTools, setSupervisionManager, clearSupervisionManager, getSupervisionManager } from './supervision.js';
48
- export { sendMessageTool, askZtcPaneTool, contactExternalTool, setBusTransport, clearBusTransport, getBusTransport } from './bus_message.js';
48
+ export { sendMessageTool, askZtcPaneTool, contactExternalTool, setBusTransport, clearBusTransport, getBusTransport, overseerBusTransport } from './bus_message.js';
49
49
  export const busTools = [sendMessageTool, askZtcPaneTool, contactExternalTool];
50
50
  export { proposeWorldMutationTool } from './world_mutation.js';
51
51
  export const worldMutationTools = [proposeWorldMutationTool];
@@ -13,6 +13,7 @@ import { existsSync } from 'fs';
13
13
  import { basename, isAbsolute, resolve } from 'path';
14
14
  import { isRatatuiBinaryAvailable } from '../../ui/ratatui/process.js';
15
15
  import { CAPABILITY_PANE_DELIVERY_ACK } from '../../ui/ratatui/protocol.js';
16
+ import { paneReadRefusal } from '../../ui/ratatui/screen_privacy.js';
16
17
  import { generateSessionId } from '../../session.js';
17
18
  import { isPaneProvider, resolveModelAndProvider } from '../../panes/model_catalog.js';
18
19
  import { buildZtcPaneLaunchCommand, createZtcLaunchSpec } from '../../panes/ztc_launch.js';
@@ -963,6 +964,10 @@ export const readTerminalPaneTool = {
963
964
  if (!Number.isSafeInteger(paneId) || paneId < 0) {
964
965
  throw new Error('pane_id must be a non-negative integer.');
965
966
  }
967
+ // The main ZTC's own screen while it shows the person's sessions picker, which no agent reads (screen_privacy.ts).
968
+ const refused = paneReadRefusal(paneId);
969
+ if (refused !== null)
970
+ throw new Error(refused);
966
971
  const lines = args.lines == null ? 200 : Number(args.lines);
967
972
  if (!Number.isSafeInteger(lines) || lines < 1 || lines > 2000)
968
973
  throw new Error('lines must be between 1 and 2000');
@@ -133,7 +133,11 @@ export const searchTool = {
133
133
  const baseCwd = context?.cwd || process.cwd();
134
134
  const pattern = String(args.pattern || '');
135
135
  const docker = dockerTarget();
136
- const searchPath = docker ? containerPath(docker, String(args.path || '.')) : resolve(baseCwd, String(args.path || '.'));
136
+ // A path the policy judged: a string. Another value is refused, never turned into one (String(['..']) is '..').
137
+ const pathArgument = args.path === undefined || args.path === null || args.path === '' ? '.' : args.path;
138
+ if (typeof pathArgument !== 'string')
139
+ throw new Error('search: path argument must be a string');
140
+ const searchPath = docker ? containerPath(docker, pathArgument) : resolve(baseCwd, pathArgument);
137
141
  // `docker exec` reports a missing executable as exit 126/127, which takes the grep fallback below.
138
142
  const search = (command, commandArgs, opts) => docker
139
143
  ? runCommand('docker', ['exec', '-w', docker.workdir, docker.container, command, ...commandArgs], baseCwd, { ...opts, env: context?.subprocessEnv })
@@ -3,6 +3,7 @@ import { configStore } from '../../config.js';
3
3
  import { ROUTE_AWAITS_A_CHOICE } from '../../config/retired_routes.js';
4
4
  import { PANE_TASK_AS_MESSAGE_ENV } from '../../panes/initial_input.js';
5
5
  import { generateSessionId } from '../../session.js';
6
+ import { paneMirrorCredentialHeaders } from '../../web/pane_credentials.js';
6
7
  import { getBusTransport } from './bus_message.js';
7
8
  import { buildChildZtcPaneLaunch, getMuxTransport, paneLimitReached, resolveModelAndProvider, withChildZtcFlags, } from './pane.js';
8
9
  let supervisionManagerRef = null;
@@ -26,6 +27,11 @@ function getCurrentPaneId() {
26
27
  function hasRemoteSupervisionApi() {
27
28
  return !supervisionManagerRef && Boolean(process.env.ZTC_MIRROR_PORT);
28
29
  }
30
+ /**
31
+ * Ask the mirror of the ZTC that opened this pane (ZTC_MIRROR_PORT) to run COMMAND on its supervision manager. The
32
+ * request presents this pane's own mirror credential, with which the mirror runs it for this pane's own sessions only;
33
+ * the desktop app's mirror, and a zmux session's own, answer nothing without a credential.
34
+ */
29
35
  function callRemoteSupervisionApi(command) {
30
36
  return new Promise((resolve, reject) => {
31
37
  const port = process.env.ZTC_MIRROR_PORT;
@@ -42,6 +48,7 @@ function callRemoteSupervisionApi(command) {
42
48
  headers: {
43
49
  'Content-Type': 'application/json',
44
50
  'Content-Length': Buffer.byteLength(payload),
51
+ ...paneMirrorCredentialHeaders(),
45
52
  },
46
53
  }, (res) => {
47
54
  let body = '';
@@ -311,10 +318,17 @@ export const createSupervisedZtcPaneTool = {
311
318
  }
312
319
  sessionId = remote.session.id;
313
320
  }
321
+ // What became of the task, when the mirror said: the child hasn't joined the bus yet, so the mirror holds its task
322
+ // until it does, or refuses it (what the pane holds is full, or its program has exited).
323
+ let taskOutcome = '';
314
324
  if (task) {
315
325
  const busTransport = getBusTransport();
316
326
  if (busTransport) {
317
- busTransport.sendBusMessage(childPane.pane_id, task, 'ztc_message');
327
+ const sent = await busTransport.sendBusMessage(childPane.pane_id, task, 'ztc_message');
328
+ if (sent && !sent.ok)
329
+ taskOutcome = ` Its task wasn't sent: ${sent.error}`;
330
+ else if (sent && sent.held)
331
+ taskOutcome = ` Its task waits for the pane to join: ${sent.notice}`;
318
332
  }
319
333
  else {
320
334
  const sent = transport.send({
@@ -328,7 +342,7 @@ export const createSupervisedZtcPaneTool = {
328
342
  }
329
343
  }
330
344
  }
331
- return `Created supervised ZTC pane "${childPane.title}" (pane ${childPane.pane_id}) with feed pane ${feedPane.pane_id}. Session ID: ${sessionId}.`;
345
+ return `Created supervised ZTC pane "${childPane.title}" (pane ${childPane.pane_id}) with feed pane ${feedPane.pane_id}. Session ID: ${sessionId}.${taskOutcome}`;
332
346
  }
333
347
  catch (error) {
334
348
  return `Error creating supervised pane: ${error.message}`;
@@ -48,6 +48,17 @@ export interface ToolContext {
48
48
  onHostVerifier?: (receipt: CommandVerificationReceipt, decision: HostVerifierDecision) => void;
49
49
  /** Trusted registered comparison; original measurements remain in the canonical evidence store. */
50
50
  onHostBenchmarkComparison?: (decision: BenchmarkComparisonDecision) => void;
51
+ /** Runtime-owned write admission under the host's permission policy: throws, naming the path and the rule, when any
52
+ * of these paths is refused now. A tool that writes files calls it inside its path locks, just before its first
53
+ * write, so the check sees the filesystem that write will see. */
54
+ admitWrites?: (targets: readonly ToolWritePath[]) => void;
55
+ }
56
+ /** One path a call will create, change, move or delete. */
57
+ export interface ToolWritePath {
58
+ /** The path the policy checks, as the tool will resolve it (absolute on this host). */
59
+ path: string;
60
+ /** How the call names it, for a refusal: "Add File ../notes.txt". */
61
+ label: string;
51
62
  }
52
63
  export interface Tool {
53
64
  definition: ToolDefinition;
@@ -56,6 +67,17 @@ export interface Tool {
56
67
  /** Host-created structured directory mapping, shared with execution. This
57
68
  * describes invocation arguments, not directories inferred from shell text. */
58
69
  resolveExecutionCwd?: (args: Record<string, unknown>, context?: ToolContext) => string;
70
+ /** Host-created mapping to the shell text this call runs, shared with
71
+ * execution (exec_command runs `cmd` before `command`). The shell policy
72
+ * checks it instead of a `command` argument. */
73
+ resolveExecutionCommand?: (args: Record<string, unknown>) => string;
74
+ /** Every file this call will create, change, move or delete: paths inside an
75
+ * argument the policy cannot read (apply_patch's patch text), and the files
76
+ * a file tool writes. The runtime gives each the check write_file's `path`
77
+ * gets plus the rules for written files, before dispatch and again at
78
+ * dispatch, and one refusal refuses the whole call. Throws when the
79
+ * arguments are malformed, as execution would. */
80
+ writePaths?: (args: Record<string, unknown>, context?: ToolContext) => Promise<readonly ToolWritePath[]>;
59
81
  /** Explicit scheduling opt-in; only read effects may run concurrently. */
60
82
  parallelSafe?: boolean;
61
83
  /** Per-call opt-in for a tool whose effect depends on its arguments: true
@@ -24,10 +24,12 @@ export interface PaneControlCredentialOptions {
24
24
  autoStarted: boolean;
25
25
  }
26
26
  /**
27
- * Whether a mirror, while sign-in is off, opens panes and takes typing only from a caller with a credential
28
- * (MirrorStreamServer.setPaneControlCredentialRequired): the desktop owner's, and a zmux owner's own silent one. Every
29
- * caller those serve holds a credential or is given one: the owner's panes, the Status pane, the browser ZTC opens with
30
- * its link. An explicit `ztc --mirror` (and so every colony cell) is opened by hand, by people and colony's dashboard,
31
- * so it keeps taking them from anyone on this computer, until outside access has an approval model of its own.
27
+ * Whether a mirror, while sign-in is off, answers only a caller with a credential, on every route but its page's scripts
28
+ * and icons and /health (MirrorStreamServer.setPaneControlCredentialRequired): the desktop owner's, and a zmux owner's
29
+ * own silent one.
30
+ * Every caller those serve holds a credential or is given one: the owner's panes and their supervision tool, the Status
31
+ * pane, the browser ZTC opens with its link. An explicit `ztc --mirror` (and so every colony cell) is opened by hand, by
32
+ * people and colony's dashboard, so it keeps answering anyone on this computer, until outside access has an approval
33
+ * model of its own.
32
34
  */
33
35
  export declare function mirrorPaneControlNeedsCredential(options: PaneControlCredentialOptions): boolean;
@@ -19,11 +19,13 @@ export function shouldAttachParentMirrorClient(options, env) {
19
19
  return options.colonyChild || options.paneMode;
20
20
  }
21
21
  /**
22
- * Whether a mirror, while sign-in is off, opens panes and takes typing only from a caller with a credential
23
- * (MirrorStreamServer.setPaneControlCredentialRequired): the desktop owner's, and a zmux owner's own silent one. Every
24
- * caller those serve holds a credential or is given one: the owner's panes, the Status pane, the browser ZTC opens with
25
- * its link. An explicit `ztc --mirror` (and so every colony cell) is opened by hand, by people and colony's dashboard,
26
- * so it keeps taking them from anyone on this computer, until outside access has an approval model of its own.
22
+ * Whether a mirror, while sign-in is off, answers only a caller with a credential, on every route but its page's scripts
23
+ * and icons and /health (MirrorStreamServer.setPaneControlCredentialRequired): the desktop owner's, and a zmux owner's
24
+ * own silent one.
25
+ * Every caller those serve holds a credential or is given one: the owner's panes and their supervision tool, the Status
26
+ * pane, the browser ZTC opens with its link. An explicit `ztc --mirror` (and so every colony cell) is opened by hand, by
27
+ * people and colony's dashboard, so it keeps answering anyone on this computer, until outside access has an approval
28
+ * model of its own.
27
29
  */
28
30
  export function mirrorPaneControlNeedsCredential(options) {
29
31
  return options.desktopMode || (options.muxMode && options.autoStarted);
@@ -0,0 +1,20 @@
1
+ /**
2
+ * What another ZTC's navigator (Ctrl+B W) opens of an instance's mirror, and what it says instead.
3
+ *
4
+ * The desktop app's mirror, and the one a zmux session starts by itself, answer only the link their own ZTC gives
5
+ * (MirrorStreamServer.setPaneControlCredentialRequired); each such instance records it in the instance registry
6
+ * (ZtcInstance.mirrorNeedsLink). Another ZTC holds no credential for them, so its navigator opens neither their logs
7
+ * nor their page there: it says where those open instead of showing an empty log, or opening a bare address that loads
8
+ * nothing. A mirror that refuses the logs although its instance recorded nothing (one started after the record) is
9
+ * named the same way in the log view.
10
+ */
11
+ import type { LogViewSource } from '../ui/widgets/log_view.js';
12
+ /** What the navigator says of TITLE's logs when that instance's mirror answers only its own ZTC's link. */
13
+ export declare function linkOnlyLogsNotice(title: string): string;
14
+ /** What the navigator says, instead of opening TITLE's mirror page, when that mirror answers only its own ZTC's link. */
15
+ export declare function linkOnlyPageNotice(title: string): string;
16
+ /**
17
+ * The navigator's log source for the instance TITLE, whose mirror listens on PORT: its /debug/logs, from the line the
18
+ * view has. A mirror that answers only its own ZTC's link refuses it (401), and the view then says where the logs open.
19
+ */
20
+ export declare function remoteMirrorLogSource(title: string, port: number, fetchImpl?: typeof fetch): LogViewSource;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * What another ZTC's navigator (Ctrl+B W) opens of an instance's mirror, and what it says instead.
3
+ *
4
+ * The desktop app's mirror, and the one a zmux session starts by itself, answer only the link their own ZTC gives
5
+ * (MirrorStreamServer.setPaneControlCredentialRequired); each such instance records it in the instance registry
6
+ * (ZtcInstance.mirrorNeedsLink). Another ZTC holds no credential for them, so its navigator opens neither their logs
7
+ * nor their page there: it says where those open instead of showing an empty log, or opening a bare address that loads
8
+ * nothing. A mirror that refuses the logs although its instance recorded nothing (one started after the record) is
9
+ * named the same way in the log view.
10
+ */
11
+ /** What the navigator says of TITLE's logs when that instance's mirror answers only its own ZTC's link. */
12
+ export function linkOnlyLogsNotice(title) {
13
+ return `${title}'s logs open only in that ZTC: its mirror answers only the link that ZTC gives.`;
14
+ }
15
+ /** What the navigator says, instead of opening TITLE's mirror page, when that mirror answers only its own ZTC's link. */
16
+ export function linkOnlyPageNotice(title) {
17
+ return `${title}'s mirror opens only from that ZTC: run /mirror open there.`;
18
+ }
19
+ /**
20
+ * The navigator's log source for the instance TITLE, whose mirror listens on PORT: its /debug/logs, from the line the
21
+ * view has. A mirror that answers only its own ZTC's link refuses it (401), and the view then says where the logs open.
22
+ */
23
+ export function remoteMirrorLogSource(title, port, fetchImpl = fetch) {
24
+ return {
25
+ title,
26
+ fetch: async (since) => {
27
+ const resp = await fetchImpl(`http://localhost:${port}/debug/logs?since=${since}`);
28
+ if (resp.status === 401)
29
+ return { lines: [], total: since, notice: linkOnlyLogsNotice(title) };
30
+ if (!resp.ok)
31
+ return { lines: [], total: since };
32
+ const data = await resp.json();
33
+ return { lines: data.lines, total: data.total };
34
+ },
35
+ };
36
+ }