@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
package/README.md CHANGED
@@ -115,13 +115,17 @@ in the browser mirror. Run `/help` for the full command list.
115
115
 
116
116
  Zerg Router enforces the spending, token and access limits on your account and your
117
117
  monthly token quota. When it refuses a request before calling any provider, ZTC ends the
118
- turn at once with Router's own words, when the limit resets in your local time, and the
119
- link to your limits. It doesn't retry: the refusal holds that route, account and model for
120
- the whole ZTC process, so subagents, workers, heartbeats, `/loop` routines, goal loops and
121
- messages from other panes get the same message without contacting Router. One real request
122
- every five minutes still goes through, so a raised limit works within minutes, and a
123
- successful answer for that model lifts the hold. When Router had no key for the model's
124
- provider, `/provider refresh` lifts it too once Router's list shows the key you added.
118
+ turn at once with the refusal's class and HTTP status (`Plan limit (HTTP 429): `,
119
+ `Router refused (HTTP 403): `), Router's own words, when the limit resets in your local
120
+ time, and the link to your limits. It doesn't retry: the refusal holds that route, account
121
+ and model for the whole ZTC process, so subagents, workers, heartbeats, `/loop` routines,
122
+ goal loops and messages from other panes get the same message without contacting Router.
123
+ One real request every five minutes still goes through, so a raised limit works within
124
+ minutes, and a successful answer for that model lifts the hold. When Router has no key for
125
+ the model's provider, or holds one it can't use (saved with a defect, such as a masked
126
+ copy, or refused by the provider), the refusal says so in its own words and where the key
127
+ goes, with no class before them, and `/provider refresh` lifts the hold too once Router's
128
+ list shows the key you added or replaced.
125
129
  Some providers' keys are personal in Router: Router uses such a key only for the logins of
126
130
  the Router account that holds it, so it has to be in the account ZTC is signed in to,
127
131
  which the refusal says. `/auth status` names that account and this device ("Zerg Router:
@@ -265,6 +269,55 @@ update installs, the next launch shows what's new in it. See
265
269
  [desktop release details](packages/zterm/RELEASES.md) for the trust, packaging
266
270
  and publication contract.
267
271
 
272
+ #### Closing tabs
273
+
274
+ A tab closes with the panes in it:
275
+
276
+ - **Its ×**, which shows on the tab under the pointer and always on the active
277
+ tab, or a **middle-click** on the tab. A press that slides off the × closes
278
+ nothing.
279
+ - **Close Tab** in the tab's menu, and **Close Other Tabs**, which closes every
280
+ tab but this one and Main's. Close Other Tabs is off, and says why, when no
281
+ other tab would close.
282
+ - **The close-tab key**, which closes the active tab: ⌥⌘W on macOS. It is
283
+ `close_tab` among ZTerm's key bindings (`~/.ztc/zterm/settings.json`), so
284
+ `"close_tab": "cmd+shift+x"` makes it ⇧⌘X. On Linux and Windows it has no
285
+ default key yet.
286
+
287
+ Main's tab, the one that holds ZTC's own pane, and the only tab stay open while
288
+ ZTC runs: neither shows a ×, their menu rows are disabled and say why, and the
289
+ key or a middle-click there says so in the status bar. Pinned panes stay open,
290
+ and so does their tab; a tab whose panes are all pinned says how to unpin each
291
+ (`/label pane <id> unpin`).
292
+
293
+ When closing would stop something, a sheet lists what stops and what stays
294
+ before anything closes: a Claude Code, Codex or custom command pane, a ZTC pane
295
+ at work, a shell running a command, a program running in a pane of its own, a
296
+ delegated worker. Return closes and Esc cancels. **Don't ask again** turns the
297
+ sheet off; **Ask before closing a tab that's running something**, a row in any
298
+ tab's menu, turns it back on. A tab of shells at their prompts closes at once,
299
+ even with a job one of them suspended (Ctrl-Z) or runs in the background (`&`):
300
+ ZTerm doesn't see those, and they end with the tab. A Shell pane opened while
301
+ MotSi's remote view is on runs inside `motsi run`, which hides the shell's
302
+ prompt, so closing its tab always asks. Claude Code and Codex sessions end with
303
+ their tab: resume them later with `/claude resume` or `/codex resume` in Main,
304
+ which list your sessions and open the one you pick in its own folder (see
305
+ [Resuming your sessions](#resuming-your-sessions)). A message one of them sent
306
+ Main that still waited for a turn of its own goes with the tab: Main never takes
307
+ it up.
308
+
309
+ When the tabs don't fit, the strip keeps the active tab in view and lists the
310
+ others under », before + and ▾. Every tab's number hint is the ⌘ key that
311
+ reaches it (⌘1 to ⌘9), in the strip and under ».
312
+
313
+ The ZTC that runs the window can close a tab as well: it sends ZTerm
314
+ `close_window` (only to a ZTerm that advertises `desktop_close_window_v1`) and
315
+ hears what closed and what stayed. A program in a pane can't send
316
+ `close_window`: the pane relay refuses it. The relay still forwards
317
+ `close_pane`, so an agent in a pane can close another tab's unpinned panes one
318
+ by one, and the tab with the last of them, without the sheet. The saved
319
+ workspace drops a closed tab at once.
320
+
268
321
  #### Native tool panes
269
322
 
270
323
  In `ztc --desktop`, open the new-pane menu (Ctrl+Cmd+N at the focused pane, or
@@ -673,9 +726,55 @@ listens on `127.0.0.1` and answers only this computer, whatever a request's
673
726
  `Host` or `X-Forwarded-For` says. To open it from another machine, start ZTC
674
727
  with `ZTC_MIRROR_REQUIRE_AUTH=1` and open the link it prints; `ZTC_MIRROR_HOST`
675
728
  sets the address it listens on. The desktop app's mirror, and the one a zmux
676
- session starts by itself, open panes and take typing only from a caller with a
677
- credential: its own panes, and the browser opened with the link from
678
- `/mirror open`.
729
+ session starts by itself, answer only callers that hold a credential ZTC gave
730
+ them: its own panes, each with one of its own, and the browser opened with the
731
+ link from `/mirror open`. A program on this computer with no credential gets
732
+ `401` from the mirror, and "Open it from ZTC with /mirror open.", on every
733
+ route but the page's scripts and icons and `/health`, which says only that the
734
+ mirror is up: through the mirror it reads no pane's output and changes
735
+ nothing. A browser that opens the bare address, or whose link has expired
736
+ (links last 12 hours), is told to open the mirror from ZTC with
737
+ `/mirror open`. Another ZTC's pane picker (`Ctrl+B w`) says that such a ZTC's
738
+ logs and page open only from that ZTC. An explicit `ztc --mirror` (and so every
739
+ colony cell) still answers anyone on this computer.
740
+
741
+ A pane's own credential reaches only that pane's messages and publications,
742
+ and the supervision of panes its pane opened. It never types as you: `/input`,
743
+ `/submit` and `/pane-input` refuse it. Its messages go only to agents (Main,
744
+ ZTC panes, Claude Code and Codex panes), never to a shell or a command pane
745
+ (`409 not_an_agent`); a message for a Claude Code or Codex pane is typed into
746
+ its prompt as one line that says who sent it. A message for a ZTC pane that
747
+ hasn't joined the bus yet (one just opened, a native ZTC pane, a colony cell)
748
+ waits for it, from whoever sends it, and reaches it as a message when it joins,
749
+ never typed in: the mirror answers `202` with `held: true`. The pane takes it
750
+ after the session it resumes and the task it was opened with. Each pane holds
751
+ at most 32 messages and 512 KB (`429 hold_full` past that); a held message is
752
+ dropped if its pane closes, hasn't joined within 2 minutes or the mirror stops,
753
+ or, as the next message for it arrives, once its pane can no longer join (it
754
+ started again in place without its credential), and a ZTC pane or Main that
755
+ sent it is told. A ZTC pane that holds no credential that joins the bus, such
756
+ as a worker a pane relaunched through the pane relay, still gets a pane's
757
+ message typed into its terminal, as before, and a native ZTC pane the desktop
758
+ app restarted in place gets `409 not_an_agent`. A desktop ZTC pane whose
759
+ program has exited stays open, but nothing will join for it: once the desktop
760
+ app reports the exit, what waited for it is dropped (its senders told), and a
761
+ message for it is refused at once with `409 pane_exited` ("Pane 9's program
762
+ has exited, so it can't take messages until it's started again."), until a ZTC
763
+ starts in it again with a fresh credential, as a ZTC pane's Resume starts one,
764
+ when messages wait for it again; started again without one, it is answered as
765
+ above. `create_supervised_ztc_pane` says whether its child's task waits for the
766
+ pane to join, or wasn't sent and why. The browser mirror's own ZTC
767
+ chat panes join no bus and read their input, and get a message there as
768
+ before. A Claude Code or Codex pane's credential sits in its environment. ZTC
769
+ keeps its own panes and agents within these rules, but it can't stop other
770
+ programs running as you: one that reads that environment can act as that
771
+ pane, within what the pane's credential reaches.
772
+
773
+ The pane relay, the socket every pane's programs reach through
774
+ `$ZTC_PANE_RELAY`, forwards only a pane's reports on itself and its pane tools
775
+ to the renderer, and asks for no credential yet. Until a later release, any
776
+ program running as you that reaches it can read any pane, type into one and
777
+ close one, and receives every pane's output.
679
778
 
680
779
  In `zmux` mode the browser mirror can now focus panes, switch layout presets, toggle zoom, create ZTC or shell panes, close panes, and drive pane scroll position through the same mux state machine as the terminal client.
681
780
 
@@ -1379,6 +1478,12 @@ keeps it. A `--headless` run reports such a turn as `status: interrupted` with
1379
1478
  `resumable: true` and its known usage, sends the same answer as its message and to
1380
1479
  `--output`, and ends with error code `ROUTER_STREAM_LOST` and a non-zero exit, with the
1381
1480
  session saved without that answer, so another message has the model answer again.
1481
+ When every try of a request was cut off before any answer text, tool call or other effect,
1482
+ ZTC first sends it once more directly, not as a stream to resume, so Router answers with
1483
+ the error that cut it off; that request is never sent again, and without an answer from
1484
+ Router the turn ends as above. The error a turn ends with starts with its class and HTTP
1485
+ status (`Rate limit (HTTP 429): `, `Router refused (HTTP 403): `, `Context window
1486
+ exceeded (HTTP 400)`), naming the provider only when the provider wrote the error.
1382
1487
  The activity line shows when ZTC is waiting for the endpoint; request diagnostics
1383
1488
  include HTTP status and bounded, redacted response details.
1384
1489
 
@@ -1661,7 +1766,10 @@ credentials. Panes need zmux (plain `ztc`) or the desktop app.
1661
1766
  - `/claude [prompt | flags]` and `/codex [prompt | flags]` open one in this
1662
1767
  pane's directory. Plain text is the opening prompt (`/claude fix the failing
1663
1768
  test`); text that starts with a flag goes to the CLI as its arguments
1664
- (`/claude --continue`, `/codex -m gpt-5 "review the diff"`).
1769
+ (`/claude --continue`, `/codex -m gpt-5 "review the diff"`). A leading `--`
1770
+ makes the rest the prompt, word for word (`/claude -- resume work`). The
1771
+ words `resume`, `continue`, `fork`, `sessions` and `show-resumable` resume
1772
+ your own sessions (see [Resuming your sessions](#resuming-your-sessions)).
1665
1773
  - `/ztc [--provider <id>] [--model <id>] [--effort <level>] [task]` opens ZTC
1666
1774
  itself the same way, next to this pane and in its directory, on the route
1667
1775
  this pane runs on now: its provider, model, auth mode and reasoning effort,
@@ -1741,7 +1849,90 @@ is never edited. Its tools give the agent the workspace:
1741
1849
  A ZTC agent reaches these panes by name as well: a message for a Claude Code or
1742
1850
  Codex pane is typed into it as `[Message from ben (pane 2)] …` (a question also
1743
1851
  says how to answer), and the answer comes back as a message from that pane.
1744
- Broadcasts to `all` reach ZTC agents only.
1852
+ Broadcasts to `all` reach ZTC agents only. `send_message` reaches agents alone:
1853
+ a message for a shell or a command pane is refused, and `type_into_pane` types
1854
+ into those. A ZTC agent's own `send_message` and `ask_ztc_pane` say so too
1855
+ (`write_terminal_pane` types into those panes there). A ZTC pane still starting,
1856
+ such as one just opened with `open_pane`, gets a message when it joins ZTC's
1857
+ bus: `send_message` (and a ZTC agent's `ask_ztc_pane`) says "Pane 7 is still
1858
+ starting; it gets your message when it joins.", and an answer comes back later
1859
+ as a message from that pane. A worker opened with a task answers the task
1860
+ first, and the message once that turn has ended.
1861
+
1862
+ Main answers a message one of these panes sends it once it has finished the
1863
+ work on it: the turn that read it, and any turn that goes on with that work by
1864
+ itself, such as the plan turn after Main's agent enters plan mode, or the next
1865
+ turns of a `/goal` it set (a `/goal` you were already running is yours, and the
1866
+ pane hears the answer of the turn that read its message). Its answer is typed
1867
+ into that pane as `[Answer from Main (pane 0)] …`, all Main wrote on the
1868
+ message, and by then `read_pane 0` shows all of it. An answer longer than 8000
1869
+ characters is cut there, saying how many characters were left out and the
1870
+ `read_pane` of pane 0, with enough `lines`, that shows the whole answer, or,
1871
+ while pane 0 is still showing it at your **Prose reading rate** (`/settings
1872
+ display`), about how long that takes. A turn that was interrupted or
1873
+ failed says so instead; one that stopped at the iteration limit says the task
1874
+ is unfinished and that a message makes Main continue; and an answer ZTC flags as
1875
+ a claim its tools don't show carries that warning. A message Main's agent sends
1876
+ that pane meanwhile comes right after the answer.
1877
+
1878
+ A turn that stops for your answer to a question, or your approval of a plan,
1879
+ says so at once, and the turn that goes on from your reply answers, whether you
1880
+ answer in the terminal or the browser mirror, approve the plan or send it back
1881
+ with feedback. If you go on with a prompt of your own instead, the pane hears
1882
+ that Main's turn was interrupted, never your answer. If you close the question
1883
+ without answering it, cancel the plan or take it to edit, clear or rewind the
1884
+ conversation past the message, or switch Main to another session, the pane hears
1885
+ that Main stopped and why, and can send its message again. A message that comes
1886
+ while Main is busy, or waits on you, waits for a turn of its own, and pane 0
1887
+ shows it when Main takes it up. A message to `all` gets no such answer. Pane 0
1888
+ shows the message as the pane sent it, under the pane's name. Main's messages
1889
+ name it as `list_panes` does: "Main", or the name `/rename` gave it. A colony
1890
+ cell answers the Claude Code and Codex panes in its own workspace the same way.
1891
+
1892
+ How long Main answers a pane by itself is the reply mode of their exchange,
1893
+ the run of answers back and forth between them, and the pane that starts the
1894
+ exchange chooses it with its message: `reply_mode` on workspace-mcp's
1895
+ `send_message` to pane 0, or on Main's agent's `send_message` or `ask_ztc_pane`
1896
+ to the pane, which take it as text (`"capped:5"`, `"arbitrator:judge"`).
1897
+
1898
+ | Reply mode | Main's automatic answers |
1899
+ | --- | --- |
1900
+ | `"uncapped"` | Every message. |
1901
+ | `{"capped": N}` | N (1 to 100) with no message of yours in Main; the last ends "no more automatic answers in this exchange; …". |
1902
+ | `{"arbitrator": NAME}` | Before each one after the first, the arbitrator decides whether the exchange goes on. |
1903
+
1904
+ A message that names no mode takes your **Agent reply mode** (`/settings` →
1905
+ Panes), which starts at capped 5. When an exchange stops, pane 0 says why and
1906
+ the pane's later messages wait for you; your next message in Main starts the
1907
+ count again, and they get a turn of their own after yours. Lowering your default
1908
+ below the answers an exchange has had stops it at its next answer, and pane 0
1909
+ and the pane say so. A different mode from the pane that started the exchange
1910
+ starts it over (the same one again changes nothing); a mode from the other side
1911
+ is not applied, and its tool says so.
1912
+
1913
+ An arbitrator is `"model"`, a model on Main's own route asked a fixed short
1914
+ prompt, or one you add under **Reply arbitrators** (`/settings` → Panes): a
1915
+ model with its provider, or an HTTP(S) endpoint (plain http for localhost only)
1916
+ that answers a POST of the exchange's summary with `{"continue": true or false,
1917
+ "reason": "…"}`. Agents can name only these; any other name is refused, so no
1918
+ agent can send the conversation somewhere you didn't choose. A model arbitrator
1919
+ on a subscription login (Codex CLI, Codex Legacy, Kimi Code), `"model"` while
1920
+ Main runs on one included, is never asked and gives no decision, since Codex
1921
+ CLI's agent would run tools of its own with no one to approve them; set one up
1922
+ on another provider. The summary holds the two panes' names, how many automatic
1923
+ answers Main has sent, and the last six messages, each cut to 600 characters
1924
+ with the keys and tokens ZTC holds taken out (saved keys, MCP servers'
1925
+ environment and headers, your Zerg Router sign-in), and nothing else. An HTTP
1926
+ arbitrator is sent no credential; a model one is reached as Main reaches its own
1927
+ model. Pane 0 shows each decision; one that comes after your next message in
1928
+ Main, which starts the count again, doesn't apply, and pane 0 says so. A stop, a
1929
+ timeout (20 seconds unless you set one), an error or an answer that isn't a
1930
+ decision stops the exchange, and the pane hears why.
1931
+
1932
+ A ZTC pane's message to Main gets no such answer: Main's agent answers it with
1933
+ `send_message` when it does. A ZTC agent's `ask_ztc_pane` waits for the response
1934
+ a child pane writes for itself, and Main writes none, so from a ZTC pane ask
1935
+ Main with `send_message`.
1745
1936
 
1746
1937
  A pane the agent opens with `open_pane` starts as one you open yourself, by
1747
1938
  ZTC's settings as saved at that moment: the profile new Claude Code and Codex
@@ -1798,6 +1989,100 @@ false` in ZTC's config): ZTC then passes nothing. ZTC decides from its own
1798
1989
  setting alone and never opens Claude Code's files; Claude Code reads its own
1799
1990
  when it runs.
1800
1991
 
1992
+ #### Resuming your sessions
1993
+
1994
+ `/claude resume` and `/codex resume` (or `sessions`, or `show-resumable`) open
1995
+ a picker in Main listing your Claude Code or Codex sessions: **This folder**
1996
+ (sessions working here or under it) and **All folders**, newest first, each
1997
+ with when it was last active, its title, its folder and, when you have ZTC
1998
+ sign-in profiles, which one it belongs to. A Claude Code session's title is a
1999
+ name given when it started (`claude -n`) or a summary, else its opening prompt
2000
+ (a pasted screenshot's text, or "[Image]"); Claude Code's own titles and a
2001
+ name given later with `/rename` are further into the file than ZTC reads, so
2002
+ those sessions show their opening prompt. A Codex session's title is the name
2003
+ Codex keeps for it, else its opening request. Type to search title, folder,
2004
+ `@profile` and id, among every session read; ←→ switches views; ↵ opens the
2005
+ highlighted session; r reads them again; Esc closes. The status line says how
2006
+ many sessions were read, how many are shown, and whether the list is partial
2007
+ or some files couldn't be read. `--all` opens it on All folders, and
2008
+ `/claude @work resume` lists only that profile's.
2009
+
2010
+ Every resumed session opens in its own folder, on the sign-in whose store
2011
+ holds it (this computer's own or a ZTC profile, regardless of the profile new
2012
+ panes start on), exactly as any `/claude` or `/codex` pane you open: the same
2013
+ permission defaults, workspace server and MotSi wrapping, named "Claude Code"
2014
+ or "Codex @work", never after the session. Claude Code gets `--resume <id>`,
2015
+ Codex `resume <id>`. A session in two sign-ins' stores is listed once in each.
2016
+
2017
+ - `/claude resume <id>` and `/codex resume <id>` open that session, as does
2018
+ the start of its id as the picker's footer shows it (`/claude resume
2019
+ b2222222`); `-- <prompt>` after it is the session's next prompt, passed as
2020
+ the CLI's own argument.
2021
+ - `--here` resumes it in this folder instead (Codex also gets `-C` for it).
2022
+ - `continue` (or `resume --last`) opens this folder's latest session on the
2023
+ sign-in that holds it, or, with none, the CLI's own `claude --continue` or
2024
+ `codex resume --last`; `fork` copies a session into a new one
2025
+ (`--fork-session`, `codex fork`), from the picker or by id.
2026
+ - `resume <name>` passes a name to the CLI, which looks for it itself.
2027
+ - Your own `/claude --resume <id>` opens in that session's folder too.
2028
+
2029
+ A session already open in a pane is marked ● and gone to, not opened twice:
2030
+ every Claude Code pane ZTC starts gets its own `--session-id`, so ZTC knows
2031
+ which session it holds. A pane whose program isn't running holds none: one
2032
+ restored "Not started" with the workspace, or one whose CLI exited. ZTC can't
2033
+ tell which session a Codex pane, a pane started with `--continue` or `--last`,
2034
+ or another terminal holds, so the picker asks for a second ↵ before resuming a
2035
+ session that was active in the last two minutes. Run saved command (or `/layout
2036
+ run <pane>`) on a Claude Code or Codex pane restored "Not started" whose launch
2037
+ holds a session ZTC knows resumes that session the same way, in a pane Main
2038
+ answers, next to the placeholder, which then closes; one whose session isn't in
2039
+ a store runs its saved command as saved.
2040
+
2041
+ A session whose folder is gone, or whose file doesn't say, isn't opened in
2042
+ this folder silently: the command says so and how to resume it here (`--here`),
2043
+ and the picker asks for a second ↵. A folder that doesn't answer within a
2044
+ second, as one on a sleeping NAS doesn't, counts as gone, and one under `/net`
2045
+ is looked at only when you choose its session. A session whose first prompt
2046
+ runs past what ZTC reads, such as a pasted screenshot, is still placed in its
2047
+ folder. An id ZTC can't find, the wrong `@profile` and an id in two sign-ins'
2048
+ stores each open nothing and say why. When the picker lists none, it says
2049
+ what ZTC read and left out (Agent SDK, desktop app, `codex exec` and subagent
2050
+ sessions, as the CLIs' own pickers leave out), that a session folder that is a
2051
+ symbolic link isn't followed, and where the CLI's own list is; Codex's This
2052
+ folder says when only the newest 300 sessions were read. In a plain terminal
2053
+ (`--no-mux`), ZTC prints the command to run elsewhere (`cd <folder> &&
2054
+ claude --resume <id>`) instead, signed in as the pane would be: on a profile,
2055
+ `env -u` clears Claude Code's sign-in overrides, and Codex keeps its sign-in in
2056
+ the profile's files.
2057
+
2058
+ The resume words are yours alone: an agent's `/claude resume` (through
2059
+ `ztc_command`) and input relayed to Main (a message from another pane) are
2060
+ refused before anything is read, and a ZTC pane is told they work only in Main.
2061
+ Agents can still pass the CLI's own `--resume <id>` or `--continue`, which
2062
+ open in their folder. Inside `motsi run`, ZTC lists no sessions.
2063
+
2064
+ To list them, ZTC reads session metadata only (each session's id, folder,
2065
+ last-active time and title) from Claude Code's and Codex's own session stores
2066
+ (`~/.claude/projects`, `~/.codex/sessions` and Codex's
2067
+ `session_index.jsonl` of names, and the same under each ZTC profile's
2068
+ folder), only when you open the picker or resume, and only the head of each
2069
+ file: a Claude Code session's first 64 KiB (a line cut there is read as far
2070
+ as it is whole), a Codex session's first megabyte at most (its first line
2071
+ alone when that rules it out), the index's last 256 KiB. Each time it reads
2072
+ the newest 300 sessions and, for Claude Code, up to 300 more whose project
2073
+ folders are named after this folder, so This folder lists an old project's
2074
+ sessions too. It never opens their sign-in files or tokens
2075
+ (`.credentials.json`, `.claude.json`, `auth.json`, the Keychain), nor a
2076
+ session file that is a symbolic or hard link, and never writes to their
2077
+ stores. While the picker is open, and for a second after, no other pane, agent
2078
+ or web mirror viewer can read Main's screen: a `read_pane` of pane 0 is
2079
+ refused. In a terminal with panes, ZTC's lines about a resumed session name no
2080
+ session, folder or prompt, since other panes may read Main as they may any pane
2081
+ (the resumed session's own pane included), and the web mirror records a typed
2082
+ resume command without its session or prompt, one ZTC can't read included.
2083
+ Nothing ZTC reads is saved with ZTC's session, sent to a model or to Zerg
2084
+ Router, or logged.
2085
+
1801
2086
  #### Sign-in profiles of ZTC's own
1802
2087
 
1803
2088
  `/claude @work …` and `/codex @work …` open the pane on a ZTC profile named
@@ -1810,7 +2095,8 @@ files (`cli_auth_credentials_store="file"`). `/subs` lists your profiles, and
1810
2095
  `/subs use claude|codex [profile]` sets the one new panes start on (no profile:
1811
2096
  this computer's normal sign-in, the one the CLI uses in any other terminal). A
1812
2097
  pane on a profile is named after it (`Claude Code @work`). ZTC never reads what
1813
- a CLI stores in a profile and never moves a pane to another profile on its own.
2098
+ a CLI stores in a profile, beyond the session metadata `/claude resume` lists
2099
+ (above), and never moves a pane to another profile on its own.
1814
2100
  A profile starts without your usual CLI settings, MCP servers or plugins, since
1815
2101
  those live in the CLI's default config directory.
1816
2102
 
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/bin/zterm-darwin-arm64
3
- size: 33976912 bytes
4
- sha256: 1b627439925cc82e5b468d13335f1055f9bd3a4c5e15e09a572f4b83ae4cf123
3
+ size: 34042768 bytes
4
+ sha256: cc53d486f2ba34e6582cebc3c3a63892408bb24e76e148b1b51f1c054e94b05e
@@ -10,7 +10,7 @@ import { mergeTokenUsage } from './backends/token_usage.js';
10
10
  import { createUsageSnapshot, mergeUsageSnapshots, parseUsageSnapshot, recordUsageReceipt } from '../usage_snapshot.js';
11
11
  import { IncompleteStreamError, isIncompleteStreamError, isTransportCodeError, isTransportMessageError } from './backends/transport_errors.js';
12
12
  import { BackendHttpError, redactErrorText, retryAfterDelayMs } from './backends/http_error.js';
13
- import { formatRouterRefusal, readRouterRefusal, ROUTER_USAGE_REFUSED, RouterRefusalError } from './backends/router_refusal.js';
13
+ import { formatRouterRefusal, readRouterRefusal, ROUTER_USAGE_REFUSED, RouterRefusalError, withHttpStatus } from './backends/router_refusal.js';
14
14
  import { inferDefaultProvider, getDefaultApiKeyForProvider, getDefaultModelForProvider } from '../config/defaults.js';
15
15
  import { apiRetryDelayMs, resolveApiRetrySettings } from '../config/api_retry.js';
16
16
  import { resolveExecutionSettings } from '../config/execution.js';
@@ -104,6 +104,7 @@ export class ContextOverflowError extends AgentError {
104
104
  // truth so the agent and host runners (TUI, headless) match the same patterns.
105
105
  const CONTEXT_OVERFLOW_SUBSTRINGS = [
106
106
  'context window',
107
+ 'context length',
107
108
  'prompt is too long',
108
109
  'too many tokens',
109
110
  'exceeds the context',
@@ -1289,7 +1290,7 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
1289
1290
  * visible text, so an empty or whitespace-only response emits no stream
1290
1291
  * events (EPO-622), matching emitStreamText.
1291
1292
  */
1292
- async streamAndAssemble(backend, request, signal, onAnswerOutput, onUsage, onAnswerText) {
1293
+ async streamAndAssemble(backend, request, signal, onAnswerOutput, onUsage, onAnswerText, onToolOutput) {
1293
1294
  let text = '';
1294
1295
  let reasoning = '';
1295
1296
  const toolUses = [];
@@ -1363,6 +1364,7 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
1363
1364
  }
1364
1365
  break;
1365
1366
  case 'tool_use_start': {
1367
+ onToolOutput?.();
1366
1368
  // Order-independent: a delta may have created the entry already.
1367
1369
  const existing = toolUses.find((t) => t.id === ev.id);
1368
1370
  if (existing)
@@ -1372,6 +1374,7 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
1372
1374
  break;
1373
1375
  }
1374
1376
  case 'tool_use_delta': {
1377
+ onToolOutput?.();
1375
1378
  let tu = toolUses.find((t) => t.id === ev.id);
1376
1379
  if (!tu) {
1377
1380
  tu = { id: ev.id, name: '', inputJson: '' };
@@ -1381,6 +1384,7 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
1381
1384
  break;
1382
1385
  }
1383
1386
  case 'tool_use_end':
1387
+ onToolOutput?.();
1384
1388
  closedToolUses.add(ev.id);
1385
1389
  break;
1386
1390
  case 'usage': {
@@ -3046,7 +3050,11 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
3046
3050
  // model like deepseek can regenerate the turn instead of killing the run.
3047
3051
  const useStream = process.env.ZTC_NO_STREAM !== '1' && !backend.streamsSyntheticallyFor?.(request);
3048
3052
  let answerOutputEmitted = false;
3053
+ let answerOutputSeen = false;
3054
+ let toolOutputEmitted = false;
3049
3055
  let effectObserved = false;
3056
+ let directProbeUsed = false;
3057
+ let lostStreamReason = '';
3050
3058
  let partialAnswer = '';
3051
3059
  let recoveryStartedAt;
3052
3060
  let rateLimitedAttempts = 0;
@@ -3153,7 +3161,7 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
3153
3161
  this._lastResponseStreamed = true;
3154
3162
  try {
3155
3163
  return await Promise.race([
3156
- this.streamAndAssemble(backend, guardedRequest, signal, () => { answerOutputEmitted = true; }, onUsage, text => { partialAnswer = text; }).then(returned),
3164
+ this.streamAndAssemble(backend, guardedRequest, signal, () => { answerOutputEmitted = true; answerOutputSeen = true; }, onUsage, text => { partialAnswer = text; }, () => { toolOutputEmitted = true; }).then(returned),
3157
3165
  guardPromise,
3158
3166
  ]);
3159
3167
  }
@@ -3229,18 +3237,39 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
3229
3237
  throw new AgentError('LLM request timed out. Try again, reduce tool output, or raise ZTC_LLM_REQUEST_TIMEOUT_MS if this model needs longer.', 'API_TIMEOUT');
3230
3238
  }
3231
3239
  const failure = this.parseAPIError(error);
3232
- throw new AgentError(failure.reason, failure.kind === 'router_refusal' ? ROUTER_USAGE_REFUSED : 'API_ERROR');
3240
+ throw new AgentError(failure.failure ?? failure.reason, failure.kind === 'router_refusal' ? ROUTER_USAGE_REFUSED : 'API_ERROR');
3233
3241
  }
3234
3242
  if (useStream && answerOutputEmitted) {
3235
3243
  this.emit({ type: 'stream_reset' });
3236
3244
  answerOutputEmitted = false;
3237
3245
  }
3246
+ // The direct attempt is one request that asks Router for the error a lost stream hid. Router cannot
3247
+ // deduplicate a request without a turn id, so nothing sends it again: without Router's answer it learned
3248
+ // nothing and the turn ends as the lost stream it was. After Router's answer, any further attempt is a
3249
+ // resumable turn again.
3250
+ if (request.transportTurnId === null) {
3251
+ if (!(error instanceof BackendHttpError))
3252
+ throw new StreamLostError(lostStreamReason, partialAnswer, { cause: error });
3253
+ request = { ...request, transportTurnId: randomUUID() };
3254
+ }
3238
3255
  const stalled = timedOut;
3239
- const { retryable, reason, kind } = stalled
3256
+ const parsed = stalled
3240
3257
  ? { retryable: true, reason: 'LLM request stalled without activity', kind: undefined }
3241
3258
  : this.parseAPIError(error);
3259
+ const { retryable, reason, kind } = parsed;
3260
+ const failureReason = parsed.failure ?? reason;
3242
3261
  if (kind === 'stream_lost' && !isIncompleteStreamError(error) && request.transportTurnId !== undefined) {
3243
3262
  if (attempt >= maxAttempts) {
3263
+ if (!directProbeUsed && !effectObserved && !answerOutputSeen && !toolOutputEmitted) {
3264
+ directProbeUsed = true;
3265
+ lostStreamReason = reason;
3266
+ request = { ...request, transportTurnId: null };
3267
+ this.emit({ type: 'api_retry', attempt, maxAttempts, delay: 0, reason: 'The Router stream was interrupted',
3268
+ phase: 'retry', elapsedMs: 0 });
3269
+ removeAbortListener?.();
3270
+ removeAbortListener = undefined;
3271
+ continue;
3272
+ }
3244
3273
  throw new StreamLostError(reason, partialAnswer, { cause: error });
3245
3274
  }
3246
3275
  request = { ...request, transportTurnId: randomUUID() };
@@ -3262,7 +3291,7 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
3262
3291
  if (!retryable || maxAttempts === 1
3263
3292
  || attempt >= maxAttempts && (recoveryWindowMs === 0 || stalled || isIncompleteStreamError(error))) {
3264
3293
  if (kind === 'context_overflow') {
3265
- throw new ContextOverflowError(reason, request, error.message);
3294
+ throw new ContextOverflowError(failureReason, request, error.message);
3266
3295
  }
3267
3296
  if (stalled) {
3268
3297
  throw new AgentError('LLM request timed out. Try again, reduce tool output, or raise ZTC_LLM_REQUEST_TIMEOUT_MS if this model needs longer.', 'API_TIMEOUT');
@@ -3270,7 +3299,7 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
3270
3299
  if (isIncompleteStreamError(error)) {
3271
3300
  throw new AgentError(INCOMPLETE_MODEL_RESPONSE_MESSAGE, INCOMPLETE_MODEL_RESPONSE_CODE);
3272
3301
  }
3273
- throw new AgentError(reason, kind === 'router_refusal' ? ROUTER_USAGE_REFUSED : 'API_ERROR');
3302
+ throw new AgentError(failureReason, kind === 'router_refusal' ? ROUTER_USAGE_REFUSED : 'API_ERROR');
3274
3303
  }
3275
3304
  // Router ended the turn with this error (a router_error frame), so resuming its turn id would replay it.
3276
3305
  if ((isIncompleteStreamError(error) || (error instanceof BackendHttpError && error.turnEnded)) && request.transportTurnId !== undefined) {
@@ -3278,16 +3307,16 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
3278
3307
  }
3279
3308
  rateLimitedAttempts = kind === 'rate_limit' ? rateLimitedAttempts + 1 : 0;
3280
3309
  if (rateLimitedAttempts >= RATE_LIMITED_ATTEMPTS) {
3281
- throw new AgentError(`${reason.replace(/\.?\s*$/, '.')} Still rate-limited after ${rateLimitedAttempts} attempts, so ZTC `
3310
+ throw new AgentError(`${failureReason.replace(/\.?\s*$/, '.')} Still rate-limited after ${rateLimitedAttempts} attempts, so ZTC `
3282
3311
  + 'stopped retrying. Send a message to try again, or choose another model with /model.', 'API_ERROR');
3283
3312
  }
3284
- lastReason = reason;
3313
+ lastReason = failureReason;
3285
3314
  const recovering = attempt >= maxAttempts;
3286
3315
  if (recovering)
3287
3316
  recoveryStartedAt ??= Date.now();
3288
3317
  const elapsedMs = recoveryStartedAt === undefined ? 0 : Math.max(0, Date.now() - recoveryStartedAt);
3289
3318
  if (recovering && recoveryWindowMs !== null && elapsedMs >= recoveryWindowMs) {
3290
- throw new AgentError(reason, stalled ? 'API_TIMEOUT' : 'API_ERROR');
3319
+ throw new AgentError(failureReason, stalled ? 'API_TIMEOUT' : 'API_ERROR');
3291
3320
  }
3292
3321
  // Keep the exact pending inference alive. Never resubmit the user turn
3293
3322
  // or revisit already checkpointed tool results to recover an endpoint.
@@ -3365,6 +3394,7 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
3365
3394
  let errorMessage = '';
3366
3395
  let admissionMessage = '';
3367
3396
  let admissionCode = '';
3397
+ let routerEnvelope = false;
3368
3398
  // OpenRouter answers "Provider returned error" and nests the upstream provider's own error, as a JSON string, in
3369
3399
  // error.metadata.raw. That nested message is the one a person can act on.
3370
3400
  let providerName = '';
@@ -3407,6 +3437,7 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
3407
3437
  // Provider error objects/strings and diagnostic detail stay private,
3408
3438
  // even when a provider also includes a top-level statusCode/message.
3409
3439
  if (errorPayload === true || (errorPayload === undefined && typeof parsed.statusCode === 'number')) {
3440
+ routerEnvelope = true;
3410
3441
  if (typeof parsed.message === 'string')
3411
3442
  admissionMessage = parsed.message;
3412
3443
  else if (typeof parsed.statusMessage === 'string')
@@ -3422,6 +3453,10 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
3422
3453
  // The provider's own words, shown so a person can act on them. The HTTP layer already redacted credentials from
3423
3454
  // its body; an error raised outside it is redacted here.
3424
3455
  const httpError = error instanceof BackendHttpError;
3456
+ const status = httpError ? error.status : statusCode;
3457
+ // The route's provider is named only for a body the provider wrote: Router's own envelope holds Router's words,
3458
+ // such as a limit on the Router key.
3459
+ const failureProvider = providerName || (httpError && !routerEnvelope ? error.provider ?? '' : '');
3425
3460
  // An error with no HTTP status (a broken stream, a backend's own failure) is its message.
3426
3461
  const body = httpError ? error.body : /API error \(\d+\): ([\s\S]*)$/.exec(message)?.[1] ?? (statusCode === 0 ? message : '');
3427
3462
  const providerSource = upstreamMessage || (typeof errorMessage === 'string' ? errorMessage : '') || (body.trimStart().startsWith('{') ? '' : body);
@@ -3437,7 +3472,9 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
3437
3472
  }
3438
3473
  // Detected before the generic 400 bucket so the host can dump the request.
3439
3474
  if (errorCode === 'context_length_exceeded' || isContextOverflowMessage(`${errorMessage} ${message}`)) {
3440
- return { retryable: false, reason: 'Context window exceeded', kind: 'context_overflow' };
3475
+ return { retryable: false, reason: 'Context window exceeded', kind: 'context_overflow',
3476
+ failure: `${withHttpStatus('Context window exceeded', status, failureProvider)}. `
3477
+ + 'Compact the conversation with /compact, or start a new session.' };
3441
3478
  }
3442
3479
  // Retryable errors
3443
3480
  if (statusCode === 529 || errorType === 'overloaded_error') {
@@ -3450,17 +3487,23 @@ INVESTIGATION STRATEGY — before making tool calls to explore or debug, follow
3450
3487
  ? readRouterRefusal(error.status, error.body) : null;
3451
3488
  if (routerRefusal) {
3452
3489
  const reason = formatRouterRefusal(routerRefusal);
3453
- return routerRefusal.kind === 'lasting' ? { retryable: false, reason, kind: 'router_refusal' } : { retryable: true, reason, kind: 'rate_limit' };
3490
+ return routerRefusal.kind === 'lasting'
3491
+ ? { retryable: false, reason, kind: 'router_refusal' }
3492
+ : { retryable: true, reason, kind: 'rate_limit' };
3454
3493
  }
3455
3494
  // Router words every OpenRouter rate limit itself, so its message is public. A used-up daily
3456
3495
  // free-model quota lasts until the day resets; retrying only spends what is left of it.
3457
3496
  const routerRateLimit = statusCode === 429 && message.startsWith('ZRouter API error (')
3458
3497
  && ROUTER_RATE_LIMIT_CODES.has(errorCode) && /^OpenRouter(?:'s)? /.test(errorMessage) ? errorMessage.trim() : '';
3459
3498
  if (routerRateLimit && errorCode === 'free_model_daily_limit') {
3460
- return { retryable: false, reason: `${routerRateLimit.replace(/\.?\s*$/, '.')} Choose another model with /model, or wait for the limit to reset.` };
3499
+ const reason = `${routerRateLimit.replace(/\.?\s*$/, '.')} Choose another model with /model, or wait for the limit to reset.`;
3500
+ return { retryable: false, reason, failure: `${withHttpStatus('Plan limit', status, failureProvider)}: ${reason}` };
3461
3501
  }
3462
3502
  if (statusCode === 429 || errorType === 'rate_limit_error' || errorType === 'RESOURCE_EXHAUSTED') {
3463
- return { retryable: true, reason: routerRateLimit || 'Rate limit exceeded', kind: 'rate_limit' };
3503
+ const detail = routerRateLimit || admissionMessage
3504
+ || (providerDetail.toLowerCase() === 'rate limit exceeded' ? '' : providerDetail);
3505
+ return { retryable: true, reason: routerRateLimit || admissionMessage || 'Rate limit exceeded', kind: 'rate_limit',
3506
+ failure: `${withHttpStatus('Rate limit', status, failureProvider)}${detail ? `: ${detail}` : ''}` };
3464
3507
  }
3465
3508
  if (statusCode === 504 || statusCode === 503 || statusCode === 502 || statusCode === 500 || errorType === 'UNAVAILABLE' || errorType === 'INTERNAL') {
3466
3509
  // A bounded response-header ID supplies support correlation beside the provider's message.
@@ -7,6 +7,7 @@ export declare class BackendHttpError extends Error {
7
7
  readonly httpError: HttpErrorDiagnostic;
8
8
  /** Transport control only; never copied into the public body diagnostic. */
9
9
  readonly retryAtMs?: number;
10
+ readonly provider?: string;
10
11
  /**
11
12
  * Router ended the turn with this error (a router_error frame): resuming the same turn id replays it, so another
12
13
  * attempt must start a new turn.
@@ -20,6 +21,7 @@ export declare class BackendHttpError extends Error {
20
21
  /** Router defines x-ratelimit-reset as relative seconds, not an epoch. */
21
22
  rateLimitReset?: string | null;
22
23
  turnEnded?: boolean;
24
+ provider?: string;
23
25
  });
24
26
  }
25
27
  /** Respect a server's minimum wait, then spread concurrent callers by up to one second. */