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.
- package/LICENSE +21 -0
- package/README.md +93 -29
- package/package.json +5 -3
- package/scripts/build-runtime-windows.ps1 +242 -242
- package/scripts/build-tui.mjs +6 -0
- package/scripts/hook-bus-test.mjs +8 -0
- package/scripts/log-writer-guard-smoke.mjs +131 -0
- package/scripts/output-style-smoke.mjs +2 -2
- package/scripts/reactive-compact-persist-smoke.mjs +22 -6
- package/scripts/recall-bench-cases.json +10 -0
- package/scripts/recall-bench.mjs +91 -2
- package/scripts/recall-quality-cases.json +1 -2
- package/scripts/recall-usecase-cases.json +1 -1
- package/scripts/session-ingest-compaction-smoke.mjs +241 -0
- package/scripts/smoke-runtime-negative.ps1 +106 -106
- package/scripts/tool-efficiency-diag.mjs +5 -2
- package/scripts/tool-smoke.mjs +251 -72
- package/src/agents/debugger/AGENT.md +3 -3
- package/src/agents/heavy-worker/AGENT.md +7 -10
- package/src/agents/maintainer/AGENT.md +1 -2
- package/src/agents/reviewer/AGENT.md +1 -2
- package/src/agents/worker/AGENT.md +5 -8
- package/src/defaults/agents.json +3 -0
- package/src/help.mjs +2 -5
- package/src/lib/mixdog-debug.cjs +13 -0
- package/src/mixdog-session-runtime.mjs +7 -3311
- package/src/rules/agent/00-core.md +4 -3
- package/src/rules/agent/30-explorer.md +53 -22
- package/src/rules/lead/02-channels.md +3 -3
- package/src/rules/lead/lead-tool.md +3 -2
- package/src/rules/shared/01-tool.md +24 -29
- package/src/runtime/agent/orchestrator/context/collect.mjs +33 -9
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +24 -3
- package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +3 -3
- package/src/runtime/agent/orchestrator/session/agent-loop.mjs +663 -0
- package/src/runtime/agent/orchestrator/session/compact/engine.mjs +6 -0
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +153 -0
- package/src/runtime/agent/orchestrator/session/loop/recall-fasttrack.mjs +49 -0
- package/src/runtime/agent/orchestrator/session/loop/steering-ladder.mjs +250 -35
- package/src/runtime/agent/orchestrator/session/loop/stored-tool-args.mjs +9 -1
- package/src/runtime/agent/orchestrator/session/loop.mjs +8 -1860
- package/src/runtime/agent/orchestrator/session/manager/agent-runtime-singleton.mjs +29 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +686 -0
- package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +60 -12
- package/src/runtime/agent/orchestrator/session/manager/env-utils.mjs +8 -0
- package/src/runtime/agent/orchestrator/session/manager/idle-cleanup.mjs +159 -0
- package/src/runtime/agent/orchestrator/session/manager/message-sanitize.mjs +143 -0
- package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge.mjs +268 -0
- package/src/runtime/agent/orchestrator/session/manager/provider-cache-key.mjs +22 -0
- package/src/runtime/agent/orchestrator/session/manager/runtime-loaders.mjs +26 -0
- package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +124 -0
- package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +258 -0
- package/src/runtime/agent/orchestrator/session/manager/session-errors.mjs +20 -0
- package/src/runtime/agent/orchestrator/session/manager/session-id.mjs +9 -0
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +475 -0
- package/src/runtime/agent/orchestrator/session/manager/session-lock.mjs +23 -0
- package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +6 -4
- package/src/runtime/agent/orchestrator/session/manager.mjs +88 -2285
- package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +440 -0
- package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +153 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +4 -1
- package/src/runtime/agent/orchestrator/session/tool-batch.mjs +642 -0
- package/src/runtime/agent/orchestrator/tools/bash-session.mjs +23 -3
- package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +198 -6
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +10 -2
- package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +13 -15
- package/src/runtime/agent/orchestrator/tools/builtin/read-batch.mjs +6 -1
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +45 -3
- package/src/runtime/agent/orchestrator/tools/builtin/search-path-diagnostics.mjs +5 -2
- package/src/runtime/agent/orchestrator/tools/builtin/search-tool.mjs +195 -3
- package/src/runtime/agent/orchestrator/tools/builtin/shell-job-paths.mjs +108 -2
- package/src/runtime/agent/orchestrator/tools/builtin/shell-job-process.mjs +15 -3
- package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +7 -0
- package/src/runtime/agent/orchestrator/tools/builtin/shell-runtime.mjs +24 -2
- package/src/runtime/agent/orchestrator/tools/builtin.mjs +17 -1
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +38 -0
- package/src/runtime/agent/orchestrator/tools/code-graph-tool-defs.mjs +4 -4
- package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/patch/parsing.mjs +72 -8
- package/src/runtime/agent/orchestrator/tools/shell-policy-danger-target.mjs +5 -1
- package/src/runtime/agent/orchestrator/tools/shell-state.mjs +1 -1
- package/src/runtime/channels/backends/discord-gateway.mjs +14 -1
- package/src/runtime/channels/backends/discord.mjs +43 -1
- package/src/runtime/channels/index.mjs +6 -2096
- package/src/runtime/channels/lib/inbound-handler.mjs +328 -0
- package/src/runtime/channels/lib/inbound-routing.mjs +19 -12
- package/src/runtime/channels/lib/interaction-handlers.mjs +260 -0
- package/src/runtime/channels/lib/memory-client.mjs +32 -14
- package/src/runtime/channels/lib/network-retry.mjs +23 -0
- package/src/runtime/channels/lib/output-forwarder.mjs +38 -7
- package/src/runtime/channels/lib/owned-runtime.mjs +547 -0
- package/src/runtime/channels/lib/owner-heartbeat.mjs +13 -4
- package/src/runtime/channels/lib/runtime-paths.mjs +35 -1
- package/src/runtime/channels/lib/tool-dispatch.mjs +17 -7
- package/src/runtime/channels/lib/transcript-binding.mjs +336 -0
- package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +39 -2
- package/src/runtime/channels/lib/worker-bootstrap.mjs +97 -0
- package/src/runtime/channels/lib/worker-ipc.mjs +201 -0
- package/src/runtime/channels/lib/worker-main.mjs +771 -0
- package/src/runtime/memory/index.mjs +73 -1725
- package/src/runtime/memory/lib/embedding-provider.mjs +4 -2
- package/src/runtime/memory/lib/embedding-worker.mjs +47 -6
- package/src/runtime/memory/lib/http-router.mjs +772 -0
- package/src/runtime/memory/lib/memory-action-handlers.mjs +901 -0
- package/src/runtime/memory/lib/memory-embed.mjs +28 -7
- package/src/runtime/memory/lib/memory-recall-scope-filter.mjs +8 -2
- package/src/runtime/memory/lib/memory-recall-store.mjs +182 -9
- package/src/runtime/memory/lib/query-handlers.mjs +38 -6
- package/src/runtime/memory/lib/recall-format.mjs +106 -6
- package/src/runtime/memory/lib/session-ingest-runtime.mjs +401 -0
- package/src/runtime/memory/lib/session-ingest.mjs +1 -1
- package/src/runtime/shared/atomic-file.mjs +10 -4
- package/src/runtime/shared/background-tasks.mjs +4 -2
- package/src/runtime/shared/tool-execution-contract.mjs +1 -1
- package/src/runtime/shared/tool-result-summary.mjs +1 -1
- package/src/runtime/shared/tool-surface.mjs +30 -1
- package/src/session-runtime/boot-profile.mjs +36 -0
- package/src/session-runtime/channel-config-api.mjs +70 -0
- package/src/session-runtime/config-lifecycle.mjs +1 -1
- package/src/session-runtime/context-status.mjs +181 -0
- package/src/session-runtime/cwd-plugins.mjs +46 -3
- package/src/session-runtime/env.mjs +17 -0
- package/src/session-runtime/lifecycle-api.mjs +242 -0
- package/src/session-runtime/mcp-glue.mjs +24 -3
- package/src/session-runtime/model-route-api.mjs +198 -0
- package/src/session-runtime/output-styles.mjs +44 -10
- package/src/session-runtime/provider-auth-api.mjs +135 -0
- package/src/session-runtime/resource-api.mjs +282 -0
- package/src/session-runtime/runtime-core.mjs +2046 -0
- package/src/session-runtime/session-turn-api.mjs +274 -0
- package/src/session-runtime/tool-catalog.mjs +18 -264
- package/src/session-runtime/tool-defs.mjs +2 -2
- package/src/session-runtime/workflow-agents-api.mjs +238 -0
- package/src/session-runtime/workflow.mjs +16 -1
- package/src/standalone/agent-tool.mjs +2 -2
- package/src/standalone/channel-worker.mjs +78 -5
- package/src/standalone/explore-tool.mjs +1 -1
- package/src/standalone/memory-runtime-proxy.mjs +56 -6
- package/src/tui/App.jsx +88 -97
- package/src/tui/app/channel-pickers.mjs +45 -0
- package/src/tui/app/core-memory-picker.mjs +1 -1
- package/src/tui/app/slash-commands.mjs +0 -1
- package/src/tui/app/slash-dispatch.mjs +0 -16
- package/src/tui/app/transcript-window.mjs +44 -1
- package/src/tui/app/use-mouse-input.mjs +15 -2
- package/src/tui/app/use-prompt-handlers.mjs +7 -94
- package/src/tui/app/use-transcript-scroll.mjs +82 -4
- package/src/tui/app/use-transcript-window.mjs +65 -5
- package/src/tui/components/PromptInput.jsx +33 -64
- package/src/tui/components/ToolExecution.jsx +2 -2
- package/src/tui/dist/index.mjs +7908 -7558
- package/src/tui/engine/context-state.mjs +145 -0
- package/src/tui/engine/prompt-history.mjs +27 -0
- package/src/tui/engine/session-api-ext.mjs +478 -0
- package/src/tui/engine/session-api.mjs +545 -0
- package/src/tui/engine/session-flow.mjs +485 -0
- package/src/tui/engine/turn.mjs +1078 -0
- package/src/tui/engine.mjs +69 -2582
- package/src/tui/index.jsx +7 -0
- package/src/tui/lib/voice-setup.mjs +166 -0
- package/src/tui/paste-attachments.mjs +12 -5
- package/src/tui/prompt-history-store.mjs +125 -12
- package/vendor/ink/build/ink.js +16 -1
- package/vendor/ink/build/output.js +30 -4
- package/vendor/ink/build/render.js +5 -0
- package/scripts/bench/cache-probe-tasks.json +0 -8
- package/scripts/bench/lead-review-tasks-r3.json +0 -20
- package/scripts/bench/lead-review-tasks.json +0 -20
- package/scripts/bench/r4-mixed-tasks.json +0 -20
- package/scripts/bench/r5-orchestrated-task.json +0 -7
- package/scripts/bench/review-tasks.json +0 -20
- package/scripts/bench/round-codex.json +0 -114
- package/scripts/bench/round-mixdog-lead-r3.json +0 -269
- package/scripts/bench/round-mixdog-lead.json +0 -269
- package/scripts/bench/round-mixdog.json +0 -126
- package/scripts/bench/round-r10-bigsample.json +0 -679
- package/scripts/bench/round-r11-codexalign.json +0 -257
- package/scripts/bench/round-r13-clientmeta.json +0 -464
- package/scripts/bench/round-r14-betafeatures.json +0 -466
- package/scripts/bench/round-r15-fulldefault.json +0 -462
- package/scripts/bench/round-r16-sessionid.json +0 -466
- package/scripts/bench/round-r17-wirebytes.json +0 -456
- package/scripts/bench/round-r18-prewarm.json +0 -468
- package/scripts/bench/round-r19-clean.json +0 -472
- package/scripts/bench/round-r20-prewarm-clean.json +0 -475
- package/scripts/bench/round-r21-delta-retry.json +0 -473
- package/scripts/bench/round-r22-full-probe.json +0 -693
- package/scripts/bench/round-r23-itemprobe.json +0 -701
- package/scripts/bench/round-r24-shapefix.json +0 -677
- package/scripts/bench/round-r25-serial.json +0 -464
- package/scripts/bench/round-r26-parallel3.json +0 -671
- package/scripts/bench/round-r27-parallel10.json +0 -894
- package/scripts/bench/round-r28-parallel10-stagger.json +0 -882
- package/scripts/bench/round-r29-parallel10-stagger166.json +0 -886
- package/scripts/bench/round-r30-instid.json +0 -253
- package/scripts/bench/round-r31-upgradeprobe.json +0 -256
- package/scripts/bench/round-r32-vs-codex-lead.json +0 -254
- package/scripts/bench/round-r33-vs-codex-codex.json +0 -115
- package/scripts/bench/round-r34-orchestrated.json +0 -120
- package/scripts/bench/round-r35-orchestrated-codex.json +0 -61
- package/scripts/bench/round-r36-orchestrated-capped.json +0 -128
- package/scripts/bench/round-r4-codex.json +0 -114
- package/scripts/bench/round-r4-mixed.json +0 -225
- package/scripts/bench/round-r5-gpt-lead.json +0 -259
- package/scripts/bench/round-r6-codex.json +0 -114
- package/scripts/bench/round-r6-solo.json +0 -257
- package/scripts/bench/round-r7-full.json +0 -254
- package/scripts/bench/round-r8-fulldefault.json +0 -255
- package/src/tui/components/prompt-input/voice-indicator.mjs +0 -39
- package/src/tui/lib/voice-recorder.mjs +0 -469
- 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:
|
|
5
|
-
turn
|
|
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
|
|
12
|
-
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
No third branch: "hits exist but I want better
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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 parts — never 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
|
-
-
|
|
4
|
-
|
|
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
|
|
4
|
-
prior result
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
*
|
|
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(
|
|
326
|
-
const list = [
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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(
|
|
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:
|
|
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:
|
|
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)
|
|
33
|
-
//
|
|
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
|
|
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".
|