@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
@@ -13,6 +13,7 @@ export class BackendHttpError extends Error {
13
13
  httpError;
14
14
  /** Transport control only; never copied into the public body diagnostic. */
15
15
  retryAtMs;
16
+ provider;
16
17
  /**
17
18
  * Router ended the turn with this error (a router_error frame): resuming the same turn id replays it, so another
18
19
  * attempt must start a new turn.
@@ -27,6 +28,7 @@ export class BackendHttpError extends Error {
27
28
  this.status = status;
28
29
  this.body = safe.text;
29
30
  this.turnEnded = options.turnEnded === true;
31
+ this.provider = options.provider;
30
32
  if (status === 429) {
31
33
  const now = Date.now();
32
34
  this.retryAtMs = parseRetryDeadline(options.retryAfter, now, true)
@@ -54,8 +54,9 @@ export declare class RouterRefusalGate {
54
54
  /** Router answered: whatever held this route and model is over. */
55
55
  succeed(target: RouterGateTarget): void;
56
56
  /**
57
- * Router's catalog, just sent for this route and account, lists as one it can run a model a hold for want of its
58
- * provider's key (provider_key_unavailable) waited on: the key has been added, so that hold is over and the next
57
+ * Router's catalog, just sent for this route and account, lists as one it can run a model a hold for want of a usable
58
+ * key of its provider waited on (provider_key_unavailable, or a key stored broken or refused: provider_key_malformed,
59
+ * provider_key_rejected): the key has been added or replaced, so that hold is over and the next
59
60
  * request for it reaches Router, a relayed one included. A model the catalog doesn't describe counts once any model
60
61
  * of its provider can run. Every other hold stays. Only a catalog Router has just sent says so, never a cached one.
61
62
  */
@@ -21,7 +21,7 @@
21
21
  */
22
22
  import { createHash } from 'node:crypto';
23
23
  import { resolveRouterModel } from '../../utils/router_catalog.js';
24
- import { PROVIDER_KEY_UNAVAILABLE } from './router_keys.js';
24
+ import { PROVIDER_KEY_REFUSALS } from './router_keys.js';
25
25
  import { RouterRefusalError } from './router_refusal.js';
26
26
  /** At most one real attempt per held route and model in this long. */
27
27
  export const ROUTER_REFUSAL_RETRY_MS = 5 * 60_000;
@@ -100,8 +100,9 @@ export class RouterRefusalGate {
100
100
  this.store?.released(hold);
101
101
  }
102
102
  /**
103
- * Router's catalog, just sent for this route and account, lists as one it can run a model a hold for want of its
104
- * provider's key (provider_key_unavailable) waited on: the key has been added, so that hold is over and the next
103
+ * Router's catalog, just sent for this route and account, lists as one it can run a model a hold for want of a usable
104
+ * key of its provider waited on (provider_key_unavailable, or a key stored broken or refused: provider_key_malformed,
105
+ * provider_key_rejected): the key has been added or replaced, so that hold is over and the next
105
106
  * request for it reaches Router, a relayed one included. A model the catalog doesn't describe counts once any model
106
107
  * of its provider can run. Every other hold stays. Only a catalog Router has just sent says so, never a cached one.
107
108
  */
@@ -109,7 +110,7 @@ export class RouterRefusalGate {
109
110
  if (catalog.version !== 1)
110
111
  return;
111
112
  for (const [key, hold] of this.holds) {
112
- if (hold.refusal.code !== PROVIDER_KEY_UNAVAILABLE || hold.route !== routerRoute(filter.route) || hold.account !== filter.account)
113
+ if (!PROVIDER_KEY_REFUSALS.has(hold.refusal.code) || hold.route !== routerRoute(filter.route) || hold.account !== filter.account)
113
114
  continue;
114
115
  const row = resolveRouterModel(catalog, hold.provider, hold.model);
115
116
  const runs = row ? row.available !== false
@@ -13,6 +13,14 @@
13
13
  import type { RouterCatalog } from '../../utils/router_catalog.js';
14
14
  /** Router's code for a provider it has no usable key for, so nothing was sent to it. */
15
15
  export declare const PROVIDER_KEY_UNAVAILABLE = "provider_key_unavailable";
16
+ /**
17
+ * Router's codes for an account key it holds but can't use, so nothing was sent: one stored with a defect (an export
18
+ * line, a masked copy), or one its provider refused and that is cooling (zapps/zergrouter server/lib/missing-provider-key.ts).
19
+ */
20
+ export declare const PROVIDER_KEY_MALFORMED = "provider_key_malformed";
21
+ export declare const PROVIDER_KEY_REJECTED = "provider_key_rejected";
22
+ /** Refusals the person ends by adding or replacing the provider's key: a list Router sends that runs it again ends them. */
23
+ export declare const PROVIDER_KEY_REFUSALS: ReadonlySet<string>;
16
24
  /** Router's Credentials page on ORIGIN, where a person adds a provider's API key. */
17
25
  export declare function routerCredentialsUrl(origin: string): string;
18
26
  /** The name Router's catalog gives PROVIDER ("Morph"), if it lists one. */
@@ -40,6 +48,12 @@ export declare function routerKeyAdvice(target: RouterKeyTarget, addIt: string,
40
48
  }): string;
41
49
  /** What ZTC says when Router refused a request because it has no key for the provider: nothing reached it. */
42
50
  export declare function missingRouterKeyMessage(target: RouterKeyTarget): string;
51
+ /**
52
+ * What ZTC says when Router holds the account's key for the provider but can't use it (PROVIDER_KEY_MALFORMED,
53
+ * PROVIDER_KEY_REJECTED): Router's own sentence, which says what is wrong and to replace the key, then where the new
54
+ * key goes. Router's words alone when ZTC can't tell the provider is the request's, or it runs only on Zerg's key.
55
+ */
56
+ export declare function unusableRouterKeyMessage(said: string, target: RouterKeyTarget): string;
43
57
  /**
44
58
  * What ZTC says when the provider turned away the key Zerg Router holds for it: its 401, which Router passes on from
45
59
  * inside a turn it started, so Router took this ZTC's sign-in. The key to check is the provider's, on Router.
@@ -1,5 +1,13 @@
1
1
  /** Router's code for a provider it has no usable key for, so nothing was sent to it. */
2
2
  export const PROVIDER_KEY_UNAVAILABLE = 'provider_key_unavailable';
3
+ /**
4
+ * Router's codes for an account key it holds but can't use, so nothing was sent: one stored with a defect (an export
5
+ * line, a masked copy), or one its provider refused and that is cooling (zapps/zergrouter server/lib/missing-provider-key.ts).
6
+ */
7
+ export const PROVIDER_KEY_MALFORMED = 'provider_key_malformed';
8
+ export const PROVIDER_KEY_REJECTED = 'provider_key_rejected';
9
+ /** Refusals the person ends by adding or replacing the provider's key: a list Router sends that runs it again ends them. */
10
+ export const PROVIDER_KEY_REFUSALS = new Set([PROVIDER_KEY_UNAVAILABLE, PROVIDER_KEY_MALFORMED, PROVIDER_KEY_REJECTED]);
3
11
  /** Router's Credentials page on ORIGIN, where a person adds a provider's API key. */
4
12
  export function routerCredentialsUrl(origin) {
5
13
  return `${origin.replace(/\/+$/, '')}/dashboard?tab=credentials`;
@@ -62,6 +70,17 @@ export function missingRouterKeyMessage(target) {
62
70
  return `Zerg Router has no key for ${name}, so it cannot run this model. Choose another model with /model.`;
63
71
  return `Zerg Router has no ${name} key for your account, so nothing was sent to ${name}. ${routerKeyAdvice(target, `your ${name} API key`)}`;
64
72
  }
73
+ /**
74
+ * What ZTC says when Router holds the account's key for the provider but can't use it (PROVIDER_KEY_MALFORMED,
75
+ * PROVIDER_KEY_REJECTED): Router's own sentence, which says what is wrong and to replace the key, then where the new
76
+ * key goes. Router's words alone when ZTC can't tell the provider is the request's, or it runs only on Zerg's key.
77
+ */
78
+ export function unusableRouterKeyMessage(said, target) {
79
+ const name = nameOf(target);
80
+ if (!name || zergKeyOnly(target.provider))
81
+ return said;
82
+ return `${said} ${routerKeyAdvice(target, `your new ${name} API key`)}`;
83
+ }
65
84
  /**
66
85
  * What ZTC says when the provider turned away the key Zerg Router holds for it: its 401, which Router passes on from
67
86
  * inside a turn it started, so Router took this ZTC's sign-in. The key to check is the provider's, on Router.
@@ -92,9 +92,11 @@ export declare function cleanRouterText(text: string, max?: number): string;
92
92
  export declare function routerHelpUrl(value: unknown): string | undefined;
93
93
  /** A moment in the person's own time zone, named: "Sun, Nov 8, 4:00 PM PST". */
94
94
  export declare function localRouterTime(at: number): string;
95
+ export declare function withHttpStatus(label: string, status: number, provider?: string): string;
95
96
  /**
96
- * What ZTC shows for a refusal: Router's words, then the reset in the person's local time when Router gives one (and
97
- * nothing about waiting when waiting will not help), then the help link unless Router's words already hold it.
98
- * `retryAt` is when a cooldown that ended the turn clears.
97
+ * What ZTC shows for a refusal: its class and HTTP status, then Router's words, then the reset in the person's local
98
+ * time when Router gives one (and nothing about waiting when waiting will not help), then the help link unless Router's
99
+ * words already hold it. A refusal for want of a usable provider key (PROVIDER_KEY_REFUSALS) is worded whole, what is
100
+ * wrong and where the key goes, so it has no class before it. `retryAt` is when a cooldown that ended the turn clears.
99
101
  */
100
102
  export declare function formatRouterRefusal(refusal: RouterRefusal, now?: number, retryAt?: number): string;
@@ -11,9 +11,11 @@
11
11
  * and body through but drops its headers, so retry timing is read from the body; its own workspace quota and request
12
12
  * throttles answer in their own shapes. A provider Router has no usable key for is `provider_key_unavailable`, read by
13
13
  * its code whatever the provider (or, from an older Router that sent no code, by its exact sentence) and worded by ZTC
14
- * (router_keys.ts), since Router's sentence names no way on.
14
+ * (router_keys.ts), since Router's sentence names no way on. An account key Router holds but can't use, stored with a
15
+ * defect (`provider_key_malformed`) or refused by its provider and cooling (`provider_key_rejected`), keeps Router's
16
+ * sentence, which says to replace it, and ZTC adds where the new key goes.
15
17
  */
16
- import { missingRouterKeyMessage, PROVIDER_KEY_UNAVAILABLE } from './router_keys.js';
18
+ import { missingRouterKeyMessage, PROVIDER_KEY_MALFORMED, PROVIDER_KEY_REFUSALS, PROVIDER_KEY_REJECTED, PROVIDER_KEY_UNAVAILABLE, unusableRouterKeyMessage, } from './router_keys.js';
17
19
  import { RequestRefusedError } from './types.js';
18
20
  /**
19
21
  * The longest provider cooldown a turn waits out. Router cools a rate-limited key for 60 seconds unless the provider
@@ -167,6 +169,18 @@ export function readRouterRefusal(status, body, request) {
167
169
  fallback = missingRouterKeyMessage({ provider: named?.provider, label: named?.providerLabel, credentialsUrl: request?.credentialsUrl });
168
170
  ownWords = true;
169
171
  }
172
+ else if ((code === PROVIDER_KEY_MALFORMED || code === PROVIDER_KEY_REJECTED) && dispatched === false) {
173
+ // Lasts until the key is replaced: the person's own next message still gets a real attempt (router_gate.ts).
174
+ kind = 'lasting';
175
+ const words = sentence(said || (code === PROVIDER_KEY_MALFORMED
176
+ ? 'The key Zerg Router holds for this provider was saved with a defect, so nothing was sent to it'
177
+ : 'The provider refused the key Zerg Router holds for it, so nothing was sent to it'));
178
+ const named = request && providerNamed(fields, said) === request.provider ? request : undefined;
179
+ fallback = named
180
+ ? unusableRouterKeyMessage(words, { provider: named.provider, label: named.providerLabel, credentialsUrl: named.credentialsUrl })
181
+ : words;
182
+ ownWords = true;
183
+ }
170
184
  else if (code && Object.hasOwn(ROUTER_USAGE_DENIALS, code) && dispatched !== true) {
171
185
  kind = code === CONCURRENCY ? 'concurrency' : 'lasting';
172
186
  fallback = ROUTER_USAGE_DENIALS[code];
@@ -266,10 +280,15 @@ export function localRouterTime(at) {
266
280
  function sentence(text) {
267
281
  return /[.!?…]$/.test(text) ? text : `${text}.`;
268
282
  }
283
+ export function withHttpStatus(label, status, provider = '') {
284
+ const at = Number.isInteger(status) && status >= 400 && status <= 599 ? ` (HTTP ${status})` : '';
285
+ return `${label}${at}${provider ? ` from ${provider}` : ''}`;
286
+ }
269
287
  /**
270
- * What ZTC shows for a refusal: Router's words, then the reset in the person's local time when Router gives one (and
271
- * nothing about waiting when waiting will not help), then the help link unless Router's words already hold it.
272
- * `retryAt` is when a cooldown that ended the turn clears.
288
+ * What ZTC shows for a refusal: its class and HTTP status, then Router's words, then the reset in the person's local
289
+ * time when Router gives one (and nothing about waiting when waiting will not help), then the help link unless Router's
290
+ * words already hold it. A refusal for want of a usable provider key (PROVIDER_KEY_REFUSALS) is worded whole, what is
291
+ * wrong and where the key goes, so it has no class before it. `retryAt` is when a cooldown that ended the turn clears.
273
292
  */
274
293
  export function formatRouterRefusal(refusal, now = Date.now(), retryAt) {
275
294
  let text = sentence(refusal.message);
@@ -282,5 +301,8 @@ export function formatRouterRefusal(refusal, now = Date.now(), retryAt) {
282
301
  text += ` ${WAIT_GUIDANCE}`;
283
302
  if (refusal.helpUrl && !text.includes(refusal.helpUrl))
284
303
  text += ` See ${refusal.helpUrl}.`;
285
- return text;
304
+ if (PROVIDER_KEY_REFUSALS.has(refusal.code))
305
+ return text;
306
+ const label = refusal.kind !== 'lasting' ? 'Rate limit' : refusal.status === 429 ? 'Plan limit' : 'Router refused';
307
+ return `${withHttpStatus(label, refusal.status)}: ${text}`;
286
308
  }
@@ -193,7 +193,7 @@ export interface BackendRequest {
193
193
  allow_fallbacks: boolean;
194
194
  };
195
195
  /** Stable id for one logical LLM turn across transport reconnects. */
196
- transportTurnId?: string;
196
+ transportTurnId?: string | null;
197
197
  /**
198
198
  * The first request of a turn the person's own new message started. It gets one real attempt even while Zerg
199
199
  * Router's refusal holds the route: they may have just raised the limit.
@@ -529,7 +529,7 @@ export class ZRouterStreamBackend {
529
529
  if (!response.ok) {
530
530
  const failure = await readHttpErrorBody(response, request.signal);
531
531
  throw routerFailure(response.status, failure.body, { headers, response, bodyReadState: failure.bodyReadState, request: this.refusalRequest(),
532
- ownSignIn: this.signInTarget() });
532
+ ownSignIn: this.signInTarget(), provider: this.provider });
533
533
  }
534
534
  const data = await response.json();
535
535
  const parsed = this.parseOpenAIResponse(data);
@@ -636,16 +636,18 @@ export class ZRouterStreamBackend {
636
636
  const headers = await this.buildHeaders(request);
637
637
  if (resumeAfter)
638
638
  headers['X-Zerg-Resume-After'] = resumeAfter;
639
+ // Router answers a request without a turn id only once the provider's first bytes arrive, and that request
640
+ // is never sent again, so it has no reconnect budget to share.
639
641
  const response = await fetchWithHeadersTimeout(fetcher, this.endpointFor(), {
640
642
  method: 'POST',
641
643
  headers,
642
644
  body,
643
645
  signal: request.signal,
644
- }, Math.min(ZROUTER_HEADERS_TIMEOUT_MS, Math.max(1, remaining())));
646
+ }, request.transportTurnId ? Math.min(ZROUTER_HEADERS_TIMEOUT_MS, Math.max(1, remaining())) : ZROUTER_HEADERS_TIMEOUT_MS);
645
647
  if (!response.ok) {
646
648
  const failure = await readHttpErrorBody(response, request.signal);
647
649
  throw routerFailure(response.status, routerErrorFrameBody(failure.body), { headers, response, bodyReadState: failure.bodyReadState,
648
- request: this.refusalRequest(), ownSignIn: this.signInTarget() });
650
+ request: this.refusalRequest(), ownSignIn: this.signInTarget(), provider: this.provider });
649
651
  }
650
652
  if (!response.body) {
651
653
  throw new Error('ZRouter API error: no response body for streaming request');
@@ -675,7 +677,7 @@ export class ZRouterStreamBackend {
675
677
  : 502;
676
678
  routerTurnEnded = true;
677
679
  throw routerFailure(status, JSON.stringify(ev.body ?? {}), { headers, turnEnded: true, request: this.refusalRequest(),
678
- ownSignIn: this.signInTarget() });
680
+ ownSignIn: this.signInTarget(), provider: this.provider });
679
681
  }
680
682
  const mapped = mapEvent(ev);
681
683
  if (this.getModelCapabilities(request.model)?.tools === false && mapped.some(event => event.type.startsWith('tool_use'))) {
@@ -711,6 +713,8 @@ export class ZRouterStreamBackend {
711
713
  : isTransportError(error));
712
714
  if (request.signal?.aborted
713
715
  || !retryable
716
+ // Router tells a reconnect from a new request by its turn id: without one, sending again dispatches again.
717
+ || !request.transportTurnId
714
718
  || (emittedMappedEvent && (!resumeSupported || !resumeAfter))) {
715
719
  // The last clause keeps the no-duplicate guarantee: once visible output
716
720
  // has been delivered, a retry is only safe when the Router can replay
@@ -740,7 +744,7 @@ export class ZRouterStreamBackend {
740
744
  }
741
745
  }
742
746
  function withTransportTurn(request) {
743
- return request.transportTurnId ? request : { ...request, transportTurnId: randomUUID() };
747
+ return request.transportTurnId === undefined ? { ...request, transportTurnId: randomUUID() } : request;
744
748
  }
745
749
  async function fetchWithHeadersTimeout(fetcher, input, init, timeoutMs) {
746
750
  const timeoutController = new AbortController();
@@ -868,7 +872,7 @@ function routerFailure(status, body, options) {
868
872
  const header = options.response?.headers.get('retry-after') ?? null;
869
873
  const httpError = (retryAfter) => {
870
874
  const error = new BackendHttpError(status, body, { prefix: 'ZRouter API', headers: options.headers, bodyReadState: options.bodyReadState,
871
- retryAfter, rateLimitReset: options.response?.headers.get('x-ratelimit-reset'), turnEnded: options.turnEnded });
875
+ retryAfter, rateLimitReset: options.response?.headers.get('x-ratelimit-reset'), turnEnded: options.turnEnded, provider: options.provider });
872
876
  if (options.response)
873
877
  error.message += failureHeaderSuffix(options.response);
874
878
  return error;
@@ -1,11 +1,21 @@
1
1
  /**
2
2
  * `/claude` and `/codex` — open the user's own Claude Code or Codex in a new
3
- * pane, in this pane's directory.
3
+ * pane, in this pane's directory, or resume one of their own sessions.
4
4
  *
5
5
  * The CLI signs in with the user's own account through its own flow; ZTC only
6
6
  * runs it, unmodified, and attaches its workspace MCP server so the agent can
7
7
  * open, read, type into and message other panes. Plain text after the command
8
8
  * is the opening prompt; text starting with a flag is the CLI's arguments.
9
+ *
10
+ * `resume`, `continue`, `fork`, `sessions` and `show-resumable` resume the
11
+ * person's sessions (panes/agent_cli.ts's parseAgentCommand): one by id opens
12
+ * in its own folder, on the sign-in whose store holds it (panes/agent_resume.ts).
13
+ * They are the person's alone: an agent's or relayed input's are refused before
14
+ * anything is read, and only Main, which has the sessions controller, reads the
15
+ * stores. What is said about a session is shown in this terminal only
16
+ * (localOnly) and never saved (ephemeral); with panes, which may read Main's
17
+ * screen, it names no session, folder or prompt (openedSessionLine), and only
18
+ * the command printed to run elsewhere, where there are none, names them.
9
19
  */
10
20
  import { type AgentCliId, type PaneProgram } from '../../panes/agent_cli.js';
11
21
  import type { PaneCommandTransport } from '../../ui/ratatui/pane_relay.js';