mixdog 0.9.18 → 0.9.20

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 (214) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +93 -29
  3. package/package.json +5 -3
  4. package/scripts/build-runtime-windows.ps1 +242 -242
  5. package/scripts/build-tui.mjs +6 -0
  6. package/scripts/hook-bus-test.mjs +8 -0
  7. package/scripts/log-writer-guard-smoke.mjs +131 -0
  8. package/scripts/output-style-smoke.mjs +2 -2
  9. package/scripts/reactive-compact-persist-smoke.mjs +22 -6
  10. package/scripts/recall-bench-cases.json +10 -0
  11. package/scripts/recall-bench.mjs +91 -2
  12. package/scripts/recall-quality-cases.json +1 -2
  13. package/scripts/recall-usecase-cases.json +1 -1
  14. package/scripts/session-ingest-compaction-smoke.mjs +241 -0
  15. package/scripts/smoke-runtime-negative.ps1 +106 -106
  16. package/scripts/tool-efficiency-diag.mjs +5 -2
  17. package/scripts/tool-smoke.mjs +251 -72
  18. package/src/agents/debugger/AGENT.md +3 -3
  19. package/src/agents/heavy-worker/AGENT.md +7 -10
  20. package/src/agents/maintainer/AGENT.md +1 -2
  21. package/src/agents/reviewer/AGENT.md +1 -2
  22. package/src/agents/worker/AGENT.md +5 -8
  23. package/src/defaults/agents.json +3 -0
  24. package/src/help.mjs +2 -5
  25. package/src/lib/mixdog-debug.cjs +13 -0
  26. package/src/mixdog-session-runtime.mjs +7 -3311
  27. package/src/rules/agent/00-core.md +4 -3
  28. package/src/rules/agent/30-explorer.md +53 -22
  29. package/src/rules/lead/02-channels.md +3 -3
  30. package/src/rules/lead/lead-tool.md +3 -2
  31. package/src/rules/shared/01-tool.md +24 -29
  32. package/src/runtime/agent/orchestrator/context/collect.mjs +33 -9
  33. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +1 -1
  34. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +1 -1
  35. package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +24 -3
  36. package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +3 -3
  37. package/src/runtime/agent/orchestrator/session/agent-loop.mjs +663 -0
  38. package/src/runtime/agent/orchestrator/session/compact/engine.mjs +6 -0
  39. package/src/runtime/agent/orchestrator/session/context-utils.mjs +2 -2
  40. package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +153 -0
  41. package/src/runtime/agent/orchestrator/session/loop/recall-fasttrack.mjs +49 -0
  42. package/src/runtime/agent/orchestrator/session/loop/steering-ladder.mjs +250 -35
  43. package/src/runtime/agent/orchestrator/session/loop/stored-tool-args.mjs +9 -1
  44. package/src/runtime/agent/orchestrator/session/loop.mjs +8 -1860
  45. package/src/runtime/agent/orchestrator/session/manager/agent-runtime-singleton.mjs +29 -0
  46. package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +686 -0
  47. package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +60 -12
  48. package/src/runtime/agent/orchestrator/session/manager/env-utils.mjs +8 -0
  49. package/src/runtime/agent/orchestrator/session/manager/idle-cleanup.mjs +159 -0
  50. package/src/runtime/agent/orchestrator/session/manager/message-sanitize.mjs +143 -0
  51. package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge.mjs +268 -0
  52. package/src/runtime/agent/orchestrator/session/manager/provider-cache-key.mjs +22 -0
  53. package/src/runtime/agent/orchestrator/session/manager/runtime-loaders.mjs +26 -0
  54. package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +124 -0
  55. package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +258 -0
  56. package/src/runtime/agent/orchestrator/session/manager/session-errors.mjs +20 -0
  57. package/src/runtime/agent/orchestrator/session/manager/session-id.mjs +9 -0
  58. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +475 -0
  59. package/src/runtime/agent/orchestrator/session/manager/session-lock.mjs +23 -0
  60. package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +6 -4
  61. package/src/runtime/agent/orchestrator/session/manager.mjs +88 -2285
  62. package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +440 -0
  63. package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +153 -0
  64. package/src/runtime/agent/orchestrator/session/store.mjs +4 -1
  65. package/src/runtime/agent/orchestrator/session/tool-batch.mjs +642 -0
  66. package/src/runtime/agent/orchestrator/tools/bash-session.mjs +23 -3
  67. package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +198 -6
  68. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +10 -2
  69. package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +13 -15
  70. package/src/runtime/agent/orchestrator/tools/builtin/read-batch.mjs +6 -1
  71. package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +45 -3
  72. package/src/runtime/agent/orchestrator/tools/builtin/search-path-diagnostics.mjs +5 -2
  73. package/src/runtime/agent/orchestrator/tools/builtin/search-tool.mjs +195 -3
  74. package/src/runtime/agent/orchestrator/tools/builtin/shell-job-paths.mjs +108 -2
  75. package/src/runtime/agent/orchestrator/tools/builtin/shell-job-process.mjs +15 -3
  76. package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +7 -0
  77. package/src/runtime/agent/orchestrator/tools/builtin/shell-runtime.mjs +24 -2
  78. package/src/runtime/agent/orchestrator/tools/builtin.mjs +17 -1
  79. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +38 -0
  80. package/src/runtime/agent/orchestrator/tools/code-graph-tool-defs.mjs +4 -4
  81. package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +2 -2
  82. package/src/runtime/agent/orchestrator/tools/patch/parsing.mjs +72 -8
  83. package/src/runtime/agent/orchestrator/tools/shell-policy-danger-target.mjs +5 -1
  84. package/src/runtime/agent/orchestrator/tools/shell-state.mjs +1 -1
  85. package/src/runtime/channels/backends/discord-gateway.mjs +14 -1
  86. package/src/runtime/channels/backends/discord.mjs +43 -1
  87. package/src/runtime/channels/index.mjs +6 -2096
  88. package/src/runtime/channels/lib/inbound-handler.mjs +328 -0
  89. package/src/runtime/channels/lib/inbound-routing.mjs +19 -12
  90. package/src/runtime/channels/lib/interaction-handlers.mjs +260 -0
  91. package/src/runtime/channels/lib/memory-client.mjs +32 -14
  92. package/src/runtime/channels/lib/network-retry.mjs +23 -0
  93. package/src/runtime/channels/lib/output-forwarder.mjs +38 -7
  94. package/src/runtime/channels/lib/owned-runtime.mjs +547 -0
  95. package/src/runtime/channels/lib/owner-heartbeat.mjs +13 -4
  96. package/src/runtime/channels/lib/runtime-paths.mjs +35 -1
  97. package/src/runtime/channels/lib/tool-dispatch.mjs +17 -7
  98. package/src/runtime/channels/lib/transcript-binding.mjs +336 -0
  99. package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +39 -2
  100. package/src/runtime/channels/lib/worker-bootstrap.mjs +97 -0
  101. package/src/runtime/channels/lib/worker-ipc.mjs +201 -0
  102. package/src/runtime/channels/lib/worker-main.mjs +771 -0
  103. package/src/runtime/memory/index.mjs +73 -1725
  104. package/src/runtime/memory/lib/embedding-provider.mjs +4 -2
  105. package/src/runtime/memory/lib/embedding-worker.mjs +47 -6
  106. package/src/runtime/memory/lib/http-router.mjs +772 -0
  107. package/src/runtime/memory/lib/memory-action-handlers.mjs +901 -0
  108. package/src/runtime/memory/lib/memory-embed.mjs +28 -7
  109. package/src/runtime/memory/lib/memory-recall-scope-filter.mjs +8 -2
  110. package/src/runtime/memory/lib/memory-recall-store.mjs +182 -9
  111. package/src/runtime/memory/lib/query-handlers.mjs +38 -6
  112. package/src/runtime/memory/lib/recall-format.mjs +106 -6
  113. package/src/runtime/memory/lib/session-ingest-runtime.mjs +401 -0
  114. package/src/runtime/memory/lib/session-ingest.mjs +1 -1
  115. package/src/runtime/shared/atomic-file.mjs +10 -4
  116. package/src/runtime/shared/background-tasks.mjs +4 -2
  117. package/src/runtime/shared/tool-execution-contract.mjs +1 -1
  118. package/src/runtime/shared/tool-result-summary.mjs +1 -1
  119. package/src/runtime/shared/tool-surface.mjs +30 -1
  120. package/src/session-runtime/boot-profile.mjs +36 -0
  121. package/src/session-runtime/channel-config-api.mjs +70 -0
  122. package/src/session-runtime/config-lifecycle.mjs +1 -1
  123. package/src/session-runtime/context-status.mjs +181 -0
  124. package/src/session-runtime/cwd-plugins.mjs +46 -3
  125. package/src/session-runtime/env.mjs +17 -0
  126. package/src/session-runtime/lifecycle-api.mjs +242 -0
  127. package/src/session-runtime/mcp-glue.mjs +24 -3
  128. package/src/session-runtime/model-route-api.mjs +198 -0
  129. package/src/session-runtime/output-styles.mjs +44 -10
  130. package/src/session-runtime/provider-auth-api.mjs +135 -0
  131. package/src/session-runtime/resource-api.mjs +282 -0
  132. package/src/session-runtime/runtime-core.mjs +2046 -0
  133. package/src/session-runtime/session-turn-api.mjs +274 -0
  134. package/src/session-runtime/tool-catalog.mjs +18 -264
  135. package/src/session-runtime/tool-defs.mjs +2 -2
  136. package/src/session-runtime/workflow-agents-api.mjs +238 -0
  137. package/src/session-runtime/workflow.mjs +16 -1
  138. package/src/standalone/agent-tool.mjs +2 -2
  139. package/src/standalone/channel-worker.mjs +78 -5
  140. package/src/standalone/explore-tool.mjs +1 -1
  141. package/src/standalone/memory-runtime-proxy.mjs +56 -6
  142. package/src/tui/App.jsx +88 -97
  143. package/src/tui/app/channel-pickers.mjs +45 -0
  144. package/src/tui/app/core-memory-picker.mjs +1 -1
  145. package/src/tui/app/slash-commands.mjs +0 -1
  146. package/src/tui/app/slash-dispatch.mjs +0 -16
  147. package/src/tui/app/transcript-window.mjs +44 -1
  148. package/src/tui/app/use-mouse-input.mjs +15 -2
  149. package/src/tui/app/use-prompt-handlers.mjs +7 -94
  150. package/src/tui/app/use-transcript-scroll.mjs +82 -4
  151. package/src/tui/app/use-transcript-window.mjs +65 -5
  152. package/src/tui/components/PromptInput.jsx +33 -64
  153. package/src/tui/components/ToolExecution.jsx +2 -2
  154. package/src/tui/dist/index.mjs +7908 -7558
  155. package/src/tui/engine/context-state.mjs +145 -0
  156. package/src/tui/engine/prompt-history.mjs +27 -0
  157. package/src/tui/engine/session-api-ext.mjs +478 -0
  158. package/src/tui/engine/session-api.mjs +545 -0
  159. package/src/tui/engine/session-flow.mjs +485 -0
  160. package/src/tui/engine/turn.mjs +1078 -0
  161. package/src/tui/engine.mjs +69 -2582
  162. package/src/tui/index.jsx +7 -0
  163. package/src/tui/lib/voice-setup.mjs +166 -0
  164. package/src/tui/paste-attachments.mjs +12 -5
  165. package/src/tui/prompt-history-store.mjs +125 -12
  166. package/vendor/ink/build/ink.js +16 -1
  167. package/vendor/ink/build/output.js +30 -4
  168. package/vendor/ink/build/render.js +5 -0
  169. package/scripts/bench/cache-probe-tasks.json +0 -8
  170. package/scripts/bench/lead-review-tasks-r3.json +0 -20
  171. package/scripts/bench/lead-review-tasks.json +0 -20
  172. package/scripts/bench/r4-mixed-tasks.json +0 -20
  173. package/scripts/bench/r5-orchestrated-task.json +0 -7
  174. package/scripts/bench/review-tasks.json +0 -20
  175. package/scripts/bench/round-codex.json +0 -114
  176. package/scripts/bench/round-mixdog-lead-r3.json +0 -269
  177. package/scripts/bench/round-mixdog-lead.json +0 -269
  178. package/scripts/bench/round-mixdog.json +0 -126
  179. package/scripts/bench/round-r10-bigsample.json +0 -679
  180. package/scripts/bench/round-r11-codexalign.json +0 -257
  181. package/scripts/bench/round-r13-clientmeta.json +0 -464
  182. package/scripts/bench/round-r14-betafeatures.json +0 -466
  183. package/scripts/bench/round-r15-fulldefault.json +0 -462
  184. package/scripts/bench/round-r16-sessionid.json +0 -466
  185. package/scripts/bench/round-r17-wirebytes.json +0 -456
  186. package/scripts/bench/round-r18-prewarm.json +0 -468
  187. package/scripts/bench/round-r19-clean.json +0 -472
  188. package/scripts/bench/round-r20-prewarm-clean.json +0 -475
  189. package/scripts/bench/round-r21-delta-retry.json +0 -473
  190. package/scripts/bench/round-r22-full-probe.json +0 -693
  191. package/scripts/bench/round-r23-itemprobe.json +0 -701
  192. package/scripts/bench/round-r24-shapefix.json +0 -677
  193. package/scripts/bench/round-r25-serial.json +0 -464
  194. package/scripts/bench/round-r26-parallel3.json +0 -671
  195. package/scripts/bench/round-r27-parallel10.json +0 -894
  196. package/scripts/bench/round-r28-parallel10-stagger.json +0 -882
  197. package/scripts/bench/round-r29-parallel10-stagger166.json +0 -886
  198. package/scripts/bench/round-r30-instid.json +0 -253
  199. package/scripts/bench/round-r31-upgradeprobe.json +0 -256
  200. package/scripts/bench/round-r32-vs-codex-lead.json +0 -254
  201. package/scripts/bench/round-r33-vs-codex-codex.json +0 -115
  202. package/scripts/bench/round-r34-orchestrated.json +0 -120
  203. package/scripts/bench/round-r35-orchestrated-codex.json +0 -61
  204. package/scripts/bench/round-r36-orchestrated-capped.json +0 -128
  205. package/scripts/bench/round-r4-codex.json +0 -114
  206. package/scripts/bench/round-r4-mixed.json +0 -225
  207. package/scripts/bench/round-r5-gpt-lead.json +0 -259
  208. package/scripts/bench/round-r6-codex.json +0 -114
  209. package/scripts/bench/round-r6-solo.json +0 -257
  210. package/scripts/bench/round-r7-full.json +0 -254
  211. package/scripts/bench/round-r8-fulldefault.json +0 -255
  212. package/src/tui/components/prompt-input/voice-indicator.mjs +0 -39
  213. package/src/tui/lib/voice-recorder.mjs +0 -469
  214. package/src/workflows/sequential/WORKFLOW.md +0 -51
@@ -1,9 +1,8 @@
1
1
  # Agent Constraints
2
2
 
3
3
  - Use English for agent task communication.
4
- - ONE TURN = ONE BATCH: emit all independent tool calls of a step in the same
5
- turn; a lone read-only call that could have ridden the previous turn is a
6
- wasted round-trip.
4
+ - ONE TURN = ONE BATCH: a read-only call that could have ridden the prior
5
+ turn is a wasted round-trip.
7
6
  - NEVER PREAMBLE: no status/progress narration, "I will..." setup, or any text
8
7
  before tool calls — call needed tools immediately; emit text only for the
9
8
  final handoff after tool work is done.
@@ -15,6 +14,8 @@
15
14
  searched); state only what changed and where to look. Verification =
16
15
  command + result in one line. Same fact twice = delete one.
17
16
  - Handoff cap ~30 lines unless `Deliver:` raises it — a ceiling, not a target.
17
+ - A blocked or partial report is a valid completion: state done/missing/
18
+ blocker in fragments — never keep retrieving to avoid reporting.
18
19
  - Banned as pure cost: report headings, markdown tables (unless requested),
19
20
  prose narration, raw logs/tool traces, speculative next-checks, restated
20
21
  brief, articles/politeness.
@@ -8,27 +8,58 @@ kind: retrieval
8
8
 
9
9
  Coordinate locator. Deliverable = WHERE as `path:line`, never WHY — no
10
10
  explaining or tracing. You ARE the `explore` tool: never call it; shared
11
- rules pointing at `explore` don't apply — use grep/code_graph/find/glob
12
- directly.
11
+ rules pointing at `explore` don't apply.
12
+
13
+ Tools: grep/find/glob/code_graph ONLY. `read` and `list` are FORBIDDEN —
14
+ grep match lines already carry every `path:line` you may output; opening a
15
+ file to "confirm" or "understand" a hit is the WHY you must not answer.
16
+ This ban has NO exception: not after a hit, not for the reason field, not
17
+ "just one read" — a `read`/`list` call anywhere in the session is a defect.
18
+
19
+ Turn 1 is the whole search, ONE message: one grep whose `pattern[]` packs
20
+ 3-6 token variants (camelCase/kebab-case/snake_case/SCREAMING_SNAKE casings,
21
+ synonyms, library/domain names), plus `find` with name fragments, plus `code_graph`
22
+ symbol_search when the query names an identifier. A single-pattern,
23
+ single-tool first turn is a defect.
24
+
25
+ Search tokens are CODE tokens: first translate natural-language or
26
+ non-English queries into probable English identifiers (e.g. "최대 루프 반복
27
+ 횟수" → maxLoop, loop-policy, iterations). Grep non-ASCII text only when
28
+ the query quotes a literal string.
29
+
30
+ Search scope is ALWAYS the session working directory: omit `path` (default
31
+ scope) or pass ONLY a path that appeared in an earlier result this session.
32
+ Inventing a directory (`/workspace/...`, guessed `src/lib`, another repo's
33
+ layout) is a defect — those results are always empty; on zero hits change
34
+ TOKENS, never guess paths.
13
35
 
14
36
  Credibility is mechanical: hit = line/path contains ANY query token or
15
- obvious synonym. No other standard "is this the real implementation" is
16
- the caller's question. Sole exception: a generic-word-only match (schema,
17
- handler, config, resolver…) with no SPECIFIC query token (product/library/
18
- domain name) = zero, not a hit.
19
-
20
- Rule zero — after EVERY tool result: ≥1 `path:line` matching a query
21
- token answer NOW with those coordinates; no verify, no re-grep, no
22
- ranking; mark weak anchors `?`. Zero → one more batch if budget remains.
23
- No third branch: "hits exist but I want better ones" IS branch one.
24
-
25
- Turns: 3 tool turns HARD max; start each tool message with `turn N/3`.
26
- Turn 1 → answer; turns 2-3 are miss-recovery only, and must change tokens
27
- OR scope never reword. One turn = ONE batch of AT MOST 5 calls: a single
28
- grep packing ALL variants in pattern[] plus code_graph/find/glob; a 6th
29
- call = packing failure. Flow/how questions: return first matching entry
30
- anchors (≤5); the caller traces the chain.
31
-
32
- Answer, nothing else: up to 5 lines `path:line symbol short reason`
33
- (`?` if weak), or `EXPLORATION_FAILED`only after 3 turns of zero
34
- anchors, or when every anchor matches only generic words.
37
+ obvious synonym never judge "is this the real implementation". Sole
38
+ exception: a generic-word-only match (schema, handler, config, resolver…)
39
+ with no SPECIFIC query token (product/library/domain name) = zero, not a hit.
40
+ A `code_graph` symbol hit (find_symbol/symbol_search returning `path:line`)
41
+ IS an anchor — emit it directly; never re-locate it with grep.
42
+
43
+ Rule zero after EVERY tool result: ≥1 `path:line` matching a query token
44
+ answer NOW with those coordinates, mark weak anchors `?`; zero → one more
45
+ batch if budget remains. No third branch: "hits exist but I want better
46
+ ones" IS branch one. Once ANY turn yields a matching line, the only legal
47
+ next output is the final answer text every further tool call is a defect.
48
+
49
+ Turns: hard max 3, expected 1; start each tool message with `turn N/3`.
50
+ Turns 2-3 are miss-recovery only (prior turn had ZERO matching lines) and
51
+ must change tokens OR scope, never reword.
52
+ Flow/how questions: first matching entry/definition anchors ARE the answer,
53
+ one anchor per concept — never trace the chain.
54
+ Compound queries ("where is X and what value/default does it use"): the
55
+ definition anchor answers BOTH partsnever launch extra searches for the
56
+ value, threshold, or content; one anchor per concept, all from the same batch.
57
+
58
+ Answer, nothing else: anchor lines `path:line — symbol — short reason`
59
+ (`?` if weak), max 3 lines — extra anchors are cost, not quality; pick the
60
+ 3 with the most specific token match. Or `EXPLORATION_FAILED` — only after
61
+ the turn budget is
62
+ spent with zero anchors, or when every anchor matches only generic words.
63
+ Before emitting `EXPLORATION_FAILED`, re-scan ALL earlier tool results: if
64
+ any line anywhere matched a specific query token, answer with that anchor
65
+ (`?` if weak) instead — a weak anchor beats a false miss.
@@ -1,3 +1,3 @@
1
- # Channels
2
-
3
- - Channel features are handled by the runtime.
1
+ # Channels
2
+
3
+ - Channel features are handled by the runtime.
@@ -1,7 +1,8 @@
1
1
  # Lead Tool Use
2
2
 
3
- - Lead owns repo-local shell work: run git/build/test/verification via `shell`
4
- directly; do not delegate to agents.
3
+ - Write-role agents run their own build/test verification via `shell`; Lead
4
+ runs cross-scope verification, benches, and everything git via `shell`
5
+ directly.
5
6
  - Use the session's current project/workspace. Change the work project only
6
7
  when the user asks for another project or a tool call needs another root.
7
8
  - Use `agent` for scoped implementation, research, review, and debugging — not
@@ -1,32 +1,27 @@
1
1
  # Tool Use
2
2
 
3
- - Batch independent lookups in one turn; serialize only when a call needs a
4
- prior result including edit loops: batch the post-edit verification read
5
- with the next target's lookup.
6
- - Pick by target: symbols/callers/deps → `code_graph`; exact text in a verified
7
- scope `grep`; dirs → `list`; verified file `read`.
8
- Locating files: concept-level or cross-file questions ("where is X handled",
9
- "how does Y flow") → `explore`, even when you could guess a keyword — its
10
- fan-out spends explorer context, not yours, and guess-and-retry keywords
11
- belong to it, not grep. Confident name fragment `find`; exact name
12
- pattern → `glob`; exact content literal `grep`. Flow/trace with a known
13
- symbol `code_graph`, never `explore` it returns entry-point anchors
14
- only; follow the chain yourself. Never `grep`/`read` guessed paths.
15
- - One concept ONE search call: all synonyms/variants in one
16
- `grep pattern:[...]` (or `code_graph symbols[]`), scopes as `path[]`;
17
- single-pattern bursts = packing failure. A second call on the same concept
18
- is a defect unless the first returned zero then change tokens or scope,
19
- never reword.
20
- - Content-mode `grep` always carries `-C 5`+ ; re-reading the same file after
21
- a content grep is a wasted round-trip. Bare match lines = existence checks
22
- only.
23
- - Any path not returned by a tool this session is a guess: find first, then
24
- grep/read the returned path. On ENOENT the next call is find on the
25
- basename never a second guess or the same path with changed args.
26
- - Retrieval serves the NEXT action (edit, answer, handoff), not certainty:
27
- the FIRST anchor ends the search — no verifying, ranking, or re-checking a
28
- hit already on screen. When acting and looking are both possible, act.
29
- - `read` uses `offset`/`limit` only; 2+ spans from known file(s) = ONE batched
30
- `read` with `{path,offset,limit}` regions. Adjacent spans in one file
31
- (within a few hundred lines) are ONE window, not repeated reads.
3
+ - Batch independent calls in one turn; serialize only when a call needs a
4
+ prior result. Merge equivalent variants/scopes into ONE call wherever the
5
+ schema accepts arrays (`pattern[]`, `path[]`, `symbols[]`, `query[]`).
6
+ - Route by what is already known: known symbol/relation → `code_graph`;
7
+ exact text in a known scope → `grep`; unknown location or concept-level
8
+ question `explore`; name fragment `find`; exact name pattern → `glob`;
9
+ known directory → `list`; known file/region `read`.
10
+ - Valid anchors come from user input or tool output in this session; locate
11
+ anything else with `find` before `grep`/`read`. On ENOENT the next call is
12
+ `find` on the basename never a retried guess.
13
+ - Retrieval stops when evidence covers the deliverable: single-answer tasks
14
+ end at the first sufficient anchor; enumeration tasks (review, audit) end
15
+ when the stated scope is covered. Never re-verify a hit already on screen;
16
+ a plausible anchor means the next call is the action itself
17
+ (patch/answer/handoff) never "one more confirming read".
18
+ - Content-mode `grep` requests enough context (`-C`) to act without
19
+ re-reading the same file; bare match lines are existence checks only.
20
+ - Repeat a search concept only after a zero-result call, changing tokens or
21
+ scope never wording alone.
22
+ - `read` windows use `offset`/`limit`; multiple spans or files = ONE call
23
+ with `{path,offset,limit}[]` regions. Size the window to the whole logical
24
+ unit (function/section) — over-read once instead of paging the same file
25
+ in small windows across turns; a 3rd window into one file means the first
26
+ should have been wider.
32
27
  - Don't mix `apply_patch` with shell or other state-changing calls in one turn.
@@ -319,16 +319,34 @@ export function bp1HasDeferredToolManifestBlock(text) {
319
319
  }
320
320
 
321
321
  /**
322
- * Names-only manifest for tools in the deferred pool (catalog minus active wire tools).
322
+ * Skill-style manifest for tools in the deferred pool (catalog minus active
323
+ * wire tools). Each entry is either a bare name string or `{ name, description }`;
324
+ * output lines are `- name: description` (description omitted when absent),
325
+ * mirroring the available-skills manifest so the model calls deferred tools
326
+ * directly. Descriptions are compacted and stripped of `<`/`>`.
323
327
  * Empty pool → '' (caller omits the block).
324
328
  */
325
- export function buildDeferredToolManifest(names) {
326
- const list = [...new Set((Array.isArray(names) ? names : [])
327
- .map((name) => sanitizeDeferredToolManifestName(name))
328
- .filter(Boolean))]
329
- .sort((a, b) => a.localeCompare(b));
329
+ export function buildDeferredToolManifest(entries) {
330
+ const list = [];
331
+ const seen = new Set();
332
+ for (const entry of Array.isArray(entries) ? entries : []) {
333
+ const rawName = typeof entry === 'string' ? entry : entry?.name;
334
+ const name = sanitizeDeferredToolManifestName(rawName);
335
+ if (!name || seen.has(name)) continue;
336
+ seen.add(name);
337
+ const description = typeof entry === 'string'
338
+ ? ''
339
+ : compactSkillManifestText(String(entry?.description || '').replace(/[<>]/g, ''));
340
+ list.push({ name, description });
341
+ }
330
342
  if (!list.length) return '';
331
- return ['<available-deferred-tools>', ...list, '</available-deferred-tools>'].join('\n');
343
+ list.sort((a, b) => a.name.localeCompare(b.name));
344
+ return [
345
+ '<available-deferred-tools>',
346
+ 'You may call any tool listed below directly by name with its arguments; it auto-loads on first call.',
347
+ ...list.map((entry) => (entry.description ? `- ${entry.name}: ${entry.description}` : `- ${entry.name}`)),
348
+ '</available-deferred-tools>',
349
+ ].join('\n');
332
350
  }
333
351
 
334
352
  function sanitizeMcpManifestServerName(name) {
@@ -389,12 +407,18 @@ export function stripDeferredToolManifestBlock(text) {
389
407
  .trimEnd();
390
408
  }
391
409
 
392
- /** Inject names-only deferred pool into BP1 once at session start; never rewrite BP1 after. */
410
+ /** Inject the skill-style deferred pool (name + description) into BP1 once at session start; never rewrite BP1 after. */
393
411
  export function applyInitialDeferredToolManifestToBp1(session, poolNames) {
394
412
  if (!session || !Array.isArray(session.messages) || session.deferredToolBp1Applied) return false;
395
413
  const pool = Array.isArray(poolNames) ? poolNames : [];
414
+ const descByName = new Map();
415
+ for (const tool of Array.isArray(session?.deferredToolCatalog) ? session.deferredToolCatalog : []) {
416
+ const name = String(tool?.name || '').trim();
417
+ if (name && !descByName.has(name)) descByName.set(name, String(tool?.description || ''));
418
+ }
419
+ const entries = pool.map((name) => ({ name, description: descByName.get(String(name).trim()) || '' }));
396
420
  const parts = [];
397
- const deferredManifest = buildDeferredToolManifest(pool);
421
+ const deferredManifest = buildDeferredToolManifest(entries);
398
422
  if (deferredManifest) parts.push(deferredManifest);
399
423
  const mcpManifest = buildMcpInstructionsManifest(session.mcpServerInstructions, pool);
400
424
  if (mcpManifest) parts.push(mcpManifest);
@@ -376,7 +376,7 @@ function toAnthropicMessages(messages) {
376
376
  continue;
377
377
  }
378
378
 
379
- // Claude Code parity: fold a user text turn that directly follows a
379
+ // First-party client parity: fold a user text turn that directly follows a
380
380
  // tool_result turn into that tool_result's content. A sibling text
381
381
  // turn after tool_result renders as `</function_results>\n\nHuman:`
382
382
  // on the wire and trains the model toward 3-token empty end_turn
@@ -378,7 +378,7 @@ function toAnthropicMessages(messages) {
378
378
  }
379
379
  continue;
380
380
  }
381
- // Claude Code parity: fold a user text turn that directly follows a
381
+ // First-party client parity: fold a user text turn that directly follows a
382
382
  // tool_result turn into that tool_result's content (empty end_turn
383
383
  // livelock prevention; see foldUserTextIntoToolResultTail).
384
384
  if (m.role === 'user' && foldUserTextIntoToolResultTail(result, normalizeContentForAnthropic(m.content))) {
@@ -241,14 +241,35 @@ function windowFromPercent(label, value, source) {
241
241
  return Object.keys(out).length > 2 ? out : null;
242
242
  }
243
243
 
244
+ // Grok Build billing periods are migrating from monthly to a shared weekly
245
+ // pool (xAI rollout is per-account). Derive the window cadence from the
246
+ // actual billing period length instead of hardcoding monthly: <=10 days
247
+ // means a weekly cycle, anything longer (or unknown) stays monthly.
248
+ function grokBillingCadence(config) {
249
+ if (config?.weeklyLimit !== undefined || config?.weekly_limit !== undefined) {
250
+ return { label: 'W', period: 'weekly' };
251
+ }
252
+ const start = resetAtMs(config?.billingPeriodStart ?? config?.billing_period_start);
253
+ const end = resetAtMs(config?.billingPeriodEnd ?? config?.billing_period_end);
254
+ if (start && end && end > start && (end - start) <= 10 * 24 * 60 * 60_000) {
255
+ return { label: 'W', period: 'weekly' };
256
+ }
257
+ return { label: 'M', period: 'monthly' };
258
+ }
259
+
244
260
  function creditWindowFromBilling(config) {
245
261
  if (!config || typeof config !== 'object') return null;
246
- const limit = num(config.monthlyLimit?.val ?? config.monthlyLimit ?? config.includedLimit?.val, null);
262
+ const limit = num(
263
+ config.weeklyLimit?.val ?? config.weeklyLimit
264
+ ?? config.monthlyLimit?.val ?? config.monthlyLimit
265
+ ?? config.includedLimit?.val,
266
+ null,
267
+ );
247
268
  const used = num(config.used?.val ?? config.includedUsed?.val ?? config.used, null);
248
269
  if (limit === null || used === null || !(limit > 0)) return null;
249
270
  const resetAt = resetAtMs(config.billingPeriodEnd ?? config.billing_period_end);
250
271
  return {
251
- label: 'M',
272
+ label: grokBillingCadence(config).label,
252
273
  source: 'grok-build-billing',
253
274
  usedPct: round(Math.min(100, used * 100 / limit), 2),
254
275
  usedCredits: round(used, 2),
@@ -265,7 +286,7 @@ function balanceFromGrokBilling(config) {
265
286
  if (cap === null || !(cap > 0)) return null;
266
287
  return {
267
288
  source: 'grok-build-on-demand',
268
- period: 'monthly',
289
+ period: grokBillingCadence(config).period,
269
290
  budgetCredits: round(cap, 2),
270
291
  spentCredits: round(used, 2),
271
292
  remainingCredits: round(Math.max(0, cap - used), 2),
@@ -29,15 +29,15 @@ import {
29
29
  // 408 — request timeout
30
30
  // 500/502/503/504 — server errors (overload / bad gateway / timeout)
31
31
  // 429 is excluded from blanket transient retry, but withRetry() honors a
32
- // SHORT Retry-After header (< SHORT_RETRY_AFTER_MAX_MS) the way Claude Code
33
- // does (refs/claude-code withRetry.ts SHORT_RETRY_THRESHOLD_MS = 20s):
32
+ // SHORT Retry-After header (< SHORT_RETRY_AFTER_MAX_MS): a short-retry
33
+ // threshold of 20s matches first-party client behavior:
34
34
  // brief throttle windows retry once the server-stated wait elapses; long or
35
35
  // headerless 429s still surface immediately (quota windows are
36
36
  // deterministic — sleeping into an outer watchdog just relabels the error).
37
37
  const TRANSIENT_STATUSES = new Set([408, 500, 502, 503, 504])
38
38
 
39
39
  // Max server-stated Retry-After we are willing to sleep on a 429 before
40
- // surfacing it. Mirrors Claude Code's 20s short-retry threshold.
40
+ // surfacing it. Mirrors the first-party client's 20s short-retry threshold.
41
41
  const SHORT_RETRY_AFTER_MAX_MS = 20_000
42
42
 
43
43
  // HTTP statuses that mean "permanent: stop retrying, surface to caller".