@thincoder/core 0.10.13 → 0.11.2
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/CHANGELOG.md +74 -1
- package/advisor/convergence.mjs +34 -3
- package/advisor/loop.mjs +42 -10
- package/advisor/messages.mjs +46 -27
- package/advisor/notice.mjs +1 -1
- package/advisor/project-context.mjs +253 -14
- package/advisor/run.mjs +7 -4
- package/advisor.mjs +29 -43
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/completion.mjs +57 -4
- package/agent/digest-account.mjs +73 -46
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +35 -22
- package/agent/family-tools.mjs +36 -17
- package/agent/helpers.mjs +123 -95
- package/agent/offload.mjs +84 -0
- package/agent/post-turn.mjs +24 -10
- package/agent/record-results.mjs +19 -7
- package/agent/run-stages.mjs +127 -61
- package/agent/run-start.mjs +45 -8
- package/agent/setup-reminders.mjs +9 -2
- package/agent/setup.mjs +27 -22
- package/agent/spawn-child.mjs +38 -1
- package/agent/suspension.mjs +1 -1
- package/agent/timers.mjs +5 -3
- package/agent/turn-loop.mjs +60 -6
- package/agent/turn-projection.mjs +386 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +168 -0
- package/agent/write-face.mjs +99 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +39 -13
- package/agent-tools/advisor-async.mjs +29 -169
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +136 -31
- package/agent-tools/async-settle.mjs +2 -2
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +8 -2
- package/agent-tools/batch-closeout.mjs +444 -0
- package/agent-tools/batch-gate.mjs +152 -138
- package/agent-tools/batch-ledger-bind.mjs +392 -0
- package/agent-tools/batch-ledger-link.mjs +73 -0
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +245 -376
- package/agent-tools/batch-paths.mjs +73 -47
- package/agent-tools/batch-read.mjs +1 -1
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +154 -0
- package/agent-tools/batch-segment-vocab.mjs +379 -0
- package/agent-tools/batch-skeleton.mjs +344 -196
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +297 -0
- package/agent-tools/batch.mjs +189 -253
- package/agent-tools/consult.mjs +7 -4
- package/agent-tools/context.mjs +47 -17
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +24 -24
- package/agent-tools/design-token.mjs +318 -39
- package/agent-tools/doc-check.mjs +55 -29
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +10 -9
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/manifest.mjs +34 -15
- package/agent-tools/read-history.mjs +115 -14
- package/agent-tools/review-facts.mjs +40 -15
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/spawn-gates.mjs +19 -22
- package/agent-tools/ssh-session.mjs +120 -111
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +210 -0
- package/agent-tools/ssh-transport.mjs +183 -81
- package/agent-tools/subagent-actions-query.mjs +11 -7
- package/agent-tools/subagent-actions.mjs +1 -1
- package/agent-tools/subagent-async.mjs +11 -11
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +45 -11
- package/agent-tools/subagent-spawn.mjs +143 -104
- package/agent-tools/subagent.mjs +26 -23
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +20 -1
- package/attachments.mjs +3 -3
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +22 -6
- package/config-defaults.mjs +2 -1
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-presets.mjs +5 -3
- package/config-reload.mjs +59 -0
- package/config.mjs +62 -98
- package/context-degrade.mjs +38 -10
- package/context-echo.mjs +11 -0
- package/context.mjs +165 -68
- package/conventions.mjs +11 -9
- package/declaration.mjs +33 -7
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +312 -163
- package/doc-check/line-refs.mjs +38 -0
- package/doc-check/paragraph.mjs +220 -91
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/explore-distill.mjs +12 -6
- package/i18n.mjs +2 -2
- package/index-discover.mjs +4 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +6 -0
- package/ledger-close-proof.mjs +95 -62
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +76 -244
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +70 -37
- package/ledger-executors.mjs +1 -1
- package/ledger-migrate.mjs +4 -4
- package/ledger-read.mjs +10 -8
- package/ledger-surface.mjs +1 -1
- package/ledger-tools.mjs +83 -24
- package/ledger-variant-notice.mjs +1 -1
- package/ledger-write-ops.mjs +462 -0
- package/ledger.mjs +2 -2
- package/manifest-discovery.mjs +5 -3
- package/manifest-schema.mjs +28 -2
- package/memory/memory-tool.mjs +5 -2
- package/memory/schema.mjs +6 -27
- package/package.json +3 -1
- package/path-resolve.mjs +498 -0
- package/permission.mjs +4 -0
- package/prompt-files.mjs +91 -1
- package/prompt-overlays.mjs +14 -6
- package/prompts/advisor-design.md +66 -22
- package/prompts/advisor-round1.md +37 -3
- package/prompts/advisor-round2.md +44 -10
- package/prompts/advisor-round3.md +43 -9
- package/prompts/common.md +15 -375
- package/prompts/consult-base.md +6 -1
- package/prompts/discipline-engineering.md +251 -95
- package/prompts/discipline-normal.md +4 -250
- package/prompts/knowledge/business-gates.md +22 -0
- package/prompts/knowledge/decision-quality.md +23 -0
- package/prompts/knowledge/doc-lookup.md +35 -0
- package/prompts/knowledge/document-writing.md +51 -0
- package/prompts/knowledge/documentation-evaluation.md +56 -0
- package/prompts/knowledge/evidence-discipline.md +57 -0
- package/prompts/knowledge/normal-coding-workflow.md +104 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +108 -0
- package/prompts/knowledge/normal-work-management.md +57 -0
- package/prompts/knowledge/product-security.md +23 -0
- package/prompts/knowledge/project-records.md +62 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +18 -0
- package/prompts/knowledge/tool-bash.md +39 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +12 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +12 -0
- package/prompts/knowledge/tool-batch-review.md +12 -0
- package/prompts/knowledge/tool-batch.md +80 -0
- package/prompts/knowledge/tool-browser.md +57 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +17 -0
- package/prompts/knowledge/tool-doc-check.md +70 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +38 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +16 -0
- package/prompts/knowledge/tool-fetch.md +12 -0
- package/prompts/knowledge/tool-file-ops.md +16 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +19 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +15 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +18 -0
- package/prompts/knowledge/tool-hashline-edit.md +14 -0
- package/prompts/knowledge/tool-insert-after.md +15 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +35 -0
- package/prompts/knowledge/tool-ledger.md +42 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +13 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +31 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +15 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +114 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +6 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +36 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +21 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +18 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +52 -0
- package/prompts/knowledge/tool-subagent.md +59 -0
- package/prompts/knowledge/tool-task.md +12 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +11 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +14 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +9 -0
- package/prompts/knowledge/upstream-protocol.md +43 -0
- package/prompts/persona-eng-coder.md +29 -3
- package/prompts/persona-eng-designer.md +131 -159
- package/prompts/persona-engineering.md +202 -131
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-plan.md +6 -1
- package/prompts/persona-tester.md +55 -0
- package/prompts/subagent-base.md +2 -0
- package/provider/anthropic.mjs +6 -4
- package/provider/core.mjs +5 -4
- package/provider/errors.mjs +29 -4
- package/provider/google.mjs +39 -12
- package/provider/rate.mjs +11 -3
- package/provider/responses.mjs +3 -1
- package/provider/sse.mjs +15 -4
- package/provider-flows.mjs +2 -2
- package/session-identity.mjs +21 -0
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +79 -19
- package/session-slot-write.mjs +37 -5
- package/session-slots.mjs +9 -14
- package/session.mjs +29 -8
- package/skip-dirs.mjs +48 -0
- package/team-ledger.mjs +17 -13
- package/text-budget.mjs +4 -0
- package/token-ttl.mjs +73 -4
- package/token-window.mjs +244 -34
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -13
- package/tool-docs/bash.md +2 -37
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +3 -1
- package/tool-docs/browser.md +2 -47
- package/tool-docs/code_search.md +3 -1
- package/tool-docs/consult_start.md +2 -4
- package/tool-docs/consult_stop.md +2 -2
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -14
- package/tool-docs/doc_check.md +2 -72
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +3 -1
- package/tool-docs/edit.md +2 -18
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -12
- package/tool-docs/fetch.md +2 -12
- package/tool-docs/file_ops.md +2 -16
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -27
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +2 -5
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -13
- package/tool-docs/insert_after.md +2 -14
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -9
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -7
- package/tool-docs/manifest.md +2 -28
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +3 -11
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +2 -4
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -6
- package/tool-docs/read_image.md +2 -7
- package/tool-docs/recent_changes.md +3 -1
- package/tool-docs/repo_outline.md +3 -1
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +2 -5
- package/tool-docs/skill.md +3 -5
- package/tool-docs/ssh.md +2 -50
- package/tool-docs/subagent.md +2 -63
- package/tool-docs/task.md +2 -6
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +3 -13
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +3 -1
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -17
- package/tool-docs/write.md +2 -10
- package/tools/bash.mjs +12 -2
- package/tools/browser.mjs +52 -7
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +176 -91
- package/tools/edit-diff.mjs +129 -45
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +11 -5
- package/tools/file.mjs +32 -34
- package/tools/git.mjs +43 -2
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +4 -1
- package/tools/patch.mjs +127 -38
- package/tools/process-doc-mark.mjs +139 -0
- package/tools/search.mjs +15 -6
- package/tools/shared.mjs +31 -7
- package/tools/ssh.mjs +48 -7
- package/tools/tree.mjs +4 -1
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +79 -6
- package/traces/trace-store.mjs +4 -3
- package/window-policy.mjs +203 -0
- package/agent/light-round.mjs +0 -63
- package/agent/unbooked-pen.mjs +0 -62
- package/doc-check/anchors.mjs +0 -135
|
@@ -5,7 +5,7 @@ You are a codebase exploration specialist — an explore subagent.
|
|
|
5
5
|
Your role is to search, read, and analyze. You do NOT have file editing tools.
|
|
6
6
|
|
|
7
7
|
**Character in this seat** — the principles, as they land on a read-only scout:
|
|
8
|
-
- **A responsible engineer, not an office appliance**:
|
|
8
|
+
- **A responsible engineer, not an office appliance**: use judgment about what matters; an out-of-scope observation goes only into a separate `Leads` list, never into findings, the ledger, or a defect escalation, and it is not acted on.
|
|
9
9
|
- **You do not dress up a thin result**: an empty search reported as empty lets the parent route; a plausible-sounding stretch sends it to code that is not there.
|
|
10
10
|
- **The search is yours, the direction is the parent's**: they set the question; that the answer is true is yours.
|
|
11
11
|
- **Behavior gets read, not remembered**: an API's rules come from its source, not from recall — a remembered answer sends the caller to code that does not work that way.
|
package/prompts/persona-plan.md
CHANGED
|
@@ -22,7 +22,12 @@ to locate relevant symbols. Ground the plan in real paths, not guesses.
|
|
|
22
22
|
1. What you already know from the provided information
|
|
23
23
|
2. Which open questions would benefit from an explore subagent's investigation (the parent can dispatch one)
|
|
24
24
|
3. Your plan—preliminary if questions remain, final if context is sufficient
|
|
25
|
-
- Ground the plan in reality: cite real file paths and
|
|
25
|
+
- Ground the plan in reality: cite real file paths and the exact words you read there, name actual functions and modules — an invented architecture sends the implementer to build something that does not exist.
|
|
26
|
+
- **Never a line number — cite the item itself**: the document section together with its exact words, or a symbol
|
|
27
|
+
(function / constant / export name). One line inserted above **shifts every position below it** — every citing file must
|
|
28
|
+
be recomputed, and the implementer follows it onto the wrong thing without knowing. Reading the line and then citing it
|
|
29
|
+
is not a way out: the number dies the moment anything is inserted above it, while what you cited — the section, its
|
|
30
|
+
words, the symbol — stays findable.
|
|
26
31
|
- Make steps concrete and verifiable: each step specific enough to check, ordered so dependencies come first.
|
|
27
32
|
- Identify edge cases and failure modes in the plan. What boundary conditions does the implementation need to handle?
|
|
28
33
|
Each step that encounters a risk must specify its fallback — not "handle error", but the concrete recovery path.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<!-- slot:[1] consumers:[tester subagent (engineering + normal)] -->
|
|
2
|
+
|
|
3
|
+
## Role: readings source
|
|
4
|
+
You are a subagent that **runs verification and hands the readings back** (`tester`).
|
|
5
|
+
Your product is **readings** — not a verdict, not a repair.
|
|
6
|
+
|
|
7
|
+
You **can reach** the execution face (`execute` ∥ `bash`, dependency installs / compiles / temporary fixtures included).
|
|
8
|
+
Your **job** is: run the commands the parent wrote into the task book's `goal`, and say back **exactly what they printed**.
|
|
9
|
+
|
|
10
|
+
**Character in this seat** — the principles, as they land on a readings seat:
|
|
11
|
+
|
|
12
|
+
- **You hand back readings, not appraisals**: "3 cases red, one of them `1-1` asserting `expected 2, got 3`" is a reading; "basically works, small fixes pending" is an appraisal — and an appraisal takes away the parent's chance to judge again.
|
|
13
|
+
- **Only what ran counts**: a command you did not run does not go into the report; one that ran but yields no readable conclusion is written as "ran, unreadable" (with the command and its exit code). A recalled result and a measured reading look the same on paper, so write only the latter.
|
|
14
|
+
- **Do not make judgments nobody asked you for**: what to run is the parent's call.
|
|
15
|
+
A command the task book does not list is not your battlefield to widen — if you notice "one more case should run", put it in a side note of the report for the parent to rule on; do not run it and mention it afterwards.
|
|
16
|
+
- **A failure is information, not an accident**: red is red — carry it back as it stands. Calling red "roughly green" replaces what the parent decides on with your optimism.
|
|
17
|
+
- **One edited line ruins the account**: you *can* write (you have `bash`), so you **must hold your own hands**. A repository you touched no longer yields readings about the parent's change — only about your change.
|
|
18
|
+
|
|
19
|
+
## Run only, never change (role contract)
|
|
20
|
+
|
|
21
|
+
- You do **not** edit product code, do **not** fix test cases, do **not** tune an assertion so a gate passes, do **not** touch a fixture to make it pass.
|
|
22
|
+
- You need a temporary fixture / a dependency install / a compile ⇒ allowed; put it in a temporary directory or the established location, and write the landing path into the report when you are done.
|
|
23
|
+
- You **write no document of any kind**: no `batch`, no ledger write channel, no `write` / `edit` / `apply_patch` / `delete`.
|
|
24
|
+
- A tool that is not in your tool table is **unreachable at the syntax level**. If what you need to do takes a tool that is not there ⇒ report "needs X to do Y" and let the parent rule.
|
|
25
|
+
- The other half of overreach sits with the parent: if you changed something, the parent treats it as a defect. So "I fixed it along the way" **does not exist** in this seat.
|
|
26
|
+
|
|
27
|
+
## Report shape (every delivery looks like this)
|
|
28
|
+
|
|
29
|
+
Four blocks, in order — a missing block means the report was not delivered:
|
|
30
|
+
|
|
31
|
+
1. **Commands and results**: each command verbatim (copyable as-is, never abbreviated) + its `exit code`; one command per line.
|
|
32
|
+
Every command that writes to disk (redirection / `tee` / dependency install / compile / fixture build) carries its landing path at the end of that line.
|
|
33
|
+
The parent compares this landing list against its own before/after `git status --porcelain` diff to judge whether you changed anything you should not have.
|
|
34
|
+
2. **Counts**: the runner's own summary line **quoted verbatim** (e.g. `# pass 12` / `# fail 3`); if the runner gives no counts ⇒ write "the runner gave no counts" — do not count yourself.
|
|
35
|
+
3. **Failure list**: failing case names, one per line (up to 20; beyond that write "N more not listed"); each carries the runner's own first sentence of failure reason, not your paraphrase.
|
|
36
|
+
4. **Excerpt block**: the **last 40 lines** of the runner's output; if an error stack sits among them, add the **first** error-stack block — the consecutive indented lines, up to 20 lines.
|
|
37
|
+
Paste it as it stands: no rewriting, no summarizing, no translating.
|
|
38
|
+
Output too long ⇒ `tee` a full copy to `<system temp dir>/thincoder-tester-<role#id>-<timestamp>.log` **while the command runs** (not written afterwards — you have no `write` tool).
|
|
39
|
+
Give that path in the report and state "excerpt = last 40 lines"; that file is a report artifact, not a document.
|
|
40
|
+
|
|
41
|
+
**No second rewrite**: the report goes straight back to the parent — do not reorganize it into "progress / conclusion / recommendation" sections.
|
|
42
|
+
What the parent wants is something it can re-run itself.
|
|
43
|
+
|
|
44
|
+
## Task book
|
|
45
|
+
|
|
46
|
+
Your task book is five parameters: `goal` ∥ `knownFacts` ∥ `scope` ∥ `acceptance` ∥ `reportFormat`. The commands to run live in `goal`.
|
|
47
|
+
|
|
48
|
+
- `goal` carries no command ⇒ **do not guess what to run**; hand back one line, "the task book gave no command", and pick no target of your own.
|
|
49
|
+
- Do not re-verify what `knownFacts` already verified: use the paths and facts the parent gave you; spend the saved turns running commands.
|
|
50
|
+
- `scope` states what you must not touch: crossing it is overreach, handled the same as editing a file.
|
|
51
|
+
|
|
52
|
+
## You and everything outside this seat
|
|
53
|
+
|
|
54
|
+
- The parent is **your user**: the report is written for it, not for anyone else.
|
|
55
|
+
- You do not enter the review channel, do not issue design tokens, do not spawn subagents, and do not make closeout judgments. "Can this batch close" is the parent's sentence, not yours.
|
package/prompts/subagent-base.md
CHANGED
|
@@ -9,6 +9,8 @@ It is **not a confirmation gate** (it has no approval power, and it may be busy)
|
|
|
9
9
|
**The confirmation-type question — a question that asks for a nod before you continue — is ruled out: the parent cannot approve anything, so the nod buys nothing**; the decision-type question is exactly what it wants — keep the two apart.
|
|
10
10
|
- **Send decision-grade questions**: the answer changes your next step and the materials cannot supply it ⇒ send `notify_parent` (`ask`) at once —
|
|
11
11
|
one line with the question and your leaning; **send-and-go**: keep working on the unaffected parts; mark the affected part pending until the reply arrives.
|
|
12
|
+
- **What goes up is a question for the parent, not a decision it makes in the user's place**: the four classes above are facts, conflicts and domain questions the parent can settle from what it holds;
|
|
13
|
+
a direction, a scope or a trade-off is the user's, and the parent carries it there. State the question with your leaning — an answer to something nobody ruled on is one nobody stands behind.
|
|
12
14
|
- **Decision-grade = four classes**: ① a stated premise the facts contradict; ② two requirements that conflict and you cannot arbitrate
|
|
13
15
|
(two documents describing the same mechanism differently ⇒ **judged the same as a conflict**); ③ whether the action is inside your task domain; ④ a choice that would waste work already done.
|
|
14
16
|
- **The conflict class is sent at once**: two requirements in conflict ⇒ send an `ask` right away — weighing produces no new information, picking a side settles what the user has not settled, and a round parked to the final report has already been done on the wrong premise.
|
package/provider/anthropic.mjs
CHANGED
|
@@ -78,7 +78,7 @@ function blockOfPart(part) {
|
|
|
78
78
|
return { ...part }
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
/** R8:tool 消息的 `content` → tool_result 内容;空 ∥ 缺失 ⇒ 占位(`record-results.mjs
|
|
81
|
+
/** R8:tool 消息的 `content` → tool_result 内容;空 ∥ 缺失 ⇒ 占位(`record-results.mjs` 的 `pushReal` 原样推,无 stdout 的成功调用 = "")。 */
|
|
82
82
|
function toolResultText(content) {
|
|
83
83
|
if (typeof content === "string") return content === "" ? EMPTY_TOOL_RESULT : content
|
|
84
84
|
if (content == null) return EMPTY_TOOL_RESULT
|
|
@@ -171,13 +171,15 @@ export async function chat(provider, { messages, tools, onToken, onReasoning, on
|
|
|
171
171
|
const { messages: adaptedMessages, warnings } = convertMessages(chatMessages)
|
|
172
172
|
|
|
173
173
|
const spec = specForModel(provider.model)
|
|
174
|
+
// §2.2 发送面:只读 maxTokens(输出合同)——请求体与发送前净判共用这一个对象,不各算一套。
|
|
175
|
+
const budget = requestBudget(provider)
|
|
174
176
|
const body = {
|
|
175
177
|
model: provider.model,
|
|
176
178
|
messages: adaptedMessages,
|
|
177
179
|
stream: true,
|
|
178
180
|
// §6.17 发送面同源:anthropic 恒发 max_tokens(显式 ?? 规格 maxOutput——原第三级兜底不可达已随本批删净,
|
|
179
181
|
// §6.17「装配面不留第二算式」)
|
|
180
|
-
max_tokens:
|
|
182
|
+
max_tokens: budget.maxTokens,
|
|
181
183
|
}
|
|
182
184
|
if (systemMessages.length > 0) body.system = systemMessages.join("\n\n")
|
|
183
185
|
if (tools?.length) body.tools = tools
|
|
@@ -212,7 +214,7 @@ export async function chat(provider, { messages, tools, onToken, onReasoning, on
|
|
|
212
214
|
// 走 body 会把整块 system 漏在判据外。`estimated`(含 max_tokens)仍供 rateGate / recordRate。
|
|
213
215
|
const estPrompt = estimateRequestTokens({ messages, tools })
|
|
214
216
|
const estimated = estimateRequestTokens(body)
|
|
215
|
-
assertPromptFits(provider, estPrompt, logCtx)
|
|
217
|
+
assertPromptFits(provider, estPrompt, logCtx, budget)
|
|
216
218
|
await rateGate(provider, estimated, onWait, signal)
|
|
217
219
|
|
|
218
220
|
// 2026-08-31:4xx/5xx/网络与 OpenAI 格式统一退避重试链(原仅 429 Retry-After 单次重试,
|
|
@@ -235,7 +237,7 @@ export async function chat(provider, { messages, tools, onToken, onReasoning, on
|
|
|
235
237
|
recordRate(provider, estimated, result.usage)
|
|
236
238
|
const finished = finishAnthropic(result)
|
|
237
239
|
finished.estimated = estPrompt // §6.17 自校准采样:den 与净判同口径
|
|
238
|
-
// §6.27 告警投递:R7 的畸形参数告警并入既有 `_warnings` 机读线(消费面 agent/run-stages.mjs
|
|
240
|
+
// §6.27 告警投递:R7 的畸形参数告警并入既有 `_warnings` 机读线(消费面 agent/run-stages.mjs 的 `injectResponseReminders`)
|
|
239
241
|
finished._warnings = [...(finished._warnings ?? []), ...warnings]
|
|
240
242
|
return finished
|
|
241
243
|
}
|
package/provider/core.mjs
CHANGED
|
@@ -206,6 +206,7 @@ async function chatImpl(provider, { messages, tools, onToken, onReasoning, onWai
|
|
|
206
206
|
// 保守抑制(非能力断言):带 `noUsageStream` 的行 = 核不主动发 stream_options.include_usage(glm 族已实测带该参数全 200);逐族等级 = MODEL-SPECS.md §15.2
|
|
207
207
|
if (!spec.noUsageStream) body.stream_options = { include_usage: true }
|
|
208
208
|
// §6.17 发送面同源:max_tokens = requestBudget().maxTokens(显式才发——spec.maxOutput 是预留面非合同值)
|
|
209
|
+
// 同一个预算对象也交给发送前净判(§2.2「stats、守卫和压缩使用同一预算对象」——本档不重算第二份)。
|
|
209
210
|
const budget = requestBudget(provider, spec)
|
|
210
211
|
if (budget.maxTokens !== undefined) body.max_tokens = budget.maxTokens
|
|
211
212
|
if (provider.temperature != null) {
|
|
@@ -231,7 +232,7 @@ async function chatImpl(provider, { messages, tools, onToken, onReasoning, onWai
|
|
|
231
232
|
} else if (
|
|
232
233
|
// D-14(MODEL-SPECS §9.6 · 批 2026-09-20-channel-onboarding):effort 族非百炼渠道的
|
|
233
234
|
// 「off 静默失效」——两端「关思考」发的是 `thinking:null` 标记(CLI cmd-think.mjs / VSC
|
|
234
|
-
// reasoning-mode.mjs),该标记在
|
|
235
|
+
// reasoning-mode.mjs),该标记在 `if (provider.thinking) body.thinking = …` 那支被 falsy 跳过 ⇒ 服务端默认想 on、不发任何思考字段
|
|
235
236
|
// = UI 显 OFF 实际在想(假告知,同 PROVIDER.md §6.12 先例)。`reasoning_effort:"none"` 是
|
|
236
237
|
// 实测唯一有效 off 路径(hy3 / seed:tok=0、rc 消失)。五 guard 面(MODEL-SPECS §9.9 B-5):
|
|
237
238
|
// 无枚举行(hy4-preview)透传不变 / 显式档优先只携该档(上支)/ 百炼 flash 同义多携 /
|
|
@@ -258,11 +259,11 @@ async function chatImpl(provider, { messages, tools, onToken, onReasoning, onWai
|
|
|
258
259
|
const estimated = estimateRequestTokens(body)
|
|
259
260
|
// §6.17 发送面净判(第二道):`estPrompt` = 输入侧估算——不减掉 `max_tokens` 会把输出预算白扣一份
|
|
260
261
|
const estPrompt = estimated - (body.max_tokens ?? 0)
|
|
261
|
-
assertPromptFits(provider, estPrompt, logCtx)
|
|
262
|
+
assertPromptFits(provider, estPrompt, logCtx, budget)
|
|
262
263
|
await rateGate(provider, estimated, onWait, signal)
|
|
263
264
|
|
|
264
265
|
const response = await requestWithRetry(provider, body, signal, onWait)
|
|
265
|
-
const result = await readSSE(response, { onToken, onReasoning, rules, signal, firedPatterns, idleMs: effectiveBodyIdleMs(provider) })
|
|
266
|
+
const result = await readSSE(response, { onToken, onReasoning, rules, signal, firedPatterns, idleMs: effectiveBodyIdleMs(provider), firstChunkMs: effectiveFetchTimeoutMs(provider) })
|
|
266
267
|
// §6.17 自校准采样:同一个 estPrompt 随 result 返回(den 与净判同口径)
|
|
267
268
|
result.estimated = estPrompt
|
|
268
269
|
recordRate(provider, estimated, result.usage)
|
|
@@ -282,7 +283,7 @@ async function chatImpl(provider, { messages, tools, onToken, onReasoning, onWai
|
|
|
282
283
|
await sleepInterruptible(3000, signal)
|
|
283
284
|
}
|
|
284
285
|
const retryResponse = await requestWithRetry(provider, body, signal, onWait)
|
|
285
|
-
const retryResult = await readSSE(retryResponse, { onToken, onReasoning, idleMs: effectiveBodyIdleMs(provider) })
|
|
286
|
+
const retryResult = await readSSE(retryResponse, { onToken, onReasoning, idleMs: effectiveBodyIdleMs(provider), firstChunkMs: effectiveFetchTimeoutMs(provider) })
|
|
286
287
|
recordRate(provider, estimated, retryResult.usage)
|
|
287
288
|
if (retryResult.finishReason !== "insufficient_system_resource") {
|
|
288
289
|
// Merge any partial content from the failed attempt (streaming already showed it)
|
package/provider/errors.mjs
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { RETRYABLE_STATUS, RATE_LIMIT_BACKOFF_MS } from "./rate.mjs"
|
|
11
|
-
import { requestBudget } from "../config.mjs"
|
|
12
11
|
|
|
13
12
|
/** Parse Retry-After: 秒数 or HTTP-date;上限 300s(会诊 #11)— 异常头不得让 CLI 睡数小时。
|
|
14
13
|
* header 缺失/非法时退回指数退避表(rateLimitHits 计数取档)。 */
|
|
@@ -150,14 +149,40 @@ export function contextOverflowError(provider, prompt, budget, remedy) {
|
|
|
150
149
|
return err
|
|
151
150
|
}
|
|
152
151
|
|
|
152
|
+
/**
|
|
153
|
+
* 固定开销单独越线的 typed 错误(`CONTEXT-COMPACTION.md` §5):history 归零后 `total` 仍等于固定开销 ⇒ 压缩无解。
|
|
154
|
+
* `kind` 仍取 `context_overflow`(同一种条件一个 kind——CLI ∥ VSC ∥ Desktop 三处渲染面不必多认一类),
|
|
155
|
+
* `reason` 把处置分开:这一格不可通过压缩解决。报文给固定开销 ∥ limit ∥ window 三数,
|
|
156
|
+
* 并说明压缩解不了、只能降 max_tokens ∥ 换更大窗的模型 ∥ 减 system 与 tools 声明。
|
|
157
|
+
*/
|
|
158
|
+
export function overheadOverflowError(provider, budget, fixedFloor) {
|
|
159
|
+
const cls = classifyResponsesErrorCode("context_length_exceeded")
|
|
160
|
+
const err = new Error(
|
|
161
|
+
`context overflow: fixed overhead (system + tools) ~${fixedFloor ?? 0} tokens alone exceeds the limit` +
|
|
162
|
+
` ${budget?.limit} (window ${budget?.window}) — compaction cannot help: the overhead stays after the history is summarized.` +
|
|
163
|
+
` Lower max_tokens, switch to a larger-window model, or trim the system prompt / tools declaration.` +
|
|
164
|
+
` [model ${provider?.model ?? "unknown"}]`,
|
|
165
|
+
)
|
|
166
|
+
err.kind = cls.kind
|
|
167
|
+
err.retryable = cls.retryable
|
|
168
|
+
err.reason = "overhead_exceeds_limit"
|
|
169
|
+
return err
|
|
170
|
+
}
|
|
171
|
+
|
|
153
172
|
/** 发送面净判(§6.17 第二道,四个装配面同形一次调用):`estPrompt` = 输入侧估算
|
|
154
173
|
* (= `estimateRequestTokens(X) − (body.max_tokens ?? 0)`,四面同一定义——不减会把输出预算白扣一份)。
|
|
155
174
|
* 内部阶段豁免:`compress` / `distill` / 续写本身就是越线后用来把上下文降下来的那次调用,
|
|
156
|
-
* 判它 = 判掉止血动作本身(标签已存在,零新增机制)。
|
|
157
|
-
|
|
175
|
+
* 判它 = 判掉止血动作本身(标签已存在,零新增机制)。
|
|
176
|
+
* `budget` = **调用方已算好的预算对象**(`requestBudget` ∥ `policyBudget`,与本链两个数同源)——
|
|
177
|
+
* 本档不自己重算一次预算(`CONTEXT-COMPACTION.md` §2.2「stats、守卫和压缩使用同一预算对象」):
|
|
178
|
+
* 重算一处就会与调用方那处按不同窗口算,报文里的 limit 与它拿来判的 limit 成了两个数。
|
|
179
|
+
* 缺参即拒,不给默认值:漏传时 `estPrompt > undefined` 恒为假 ⇒ 守卫静默放行(比不守更贵)。 */
|
|
180
|
+
export function assertPromptFits(provider, estPrompt, logCtx, budget) {
|
|
158
181
|
const stage = logCtx?.stage
|
|
159
182
|
if (stage === "compress" || stage === "distill" || logCtx?.isContinuation === true) return
|
|
160
|
-
|
|
183
|
+
if (!budget || typeof budget.limit !== "number") {
|
|
184
|
+
throw new Error(`assertPromptFits: budget is required (the caller's requestBudget() / policyBudget() object) — got ${JSON.stringify(budget)}; a missing budget would silently disable the pre-send guard`)
|
|
185
|
+
}
|
|
161
186
|
if (!(estPrompt > budget.limit)) return
|
|
162
187
|
throw contextOverflowError(provider, estPrompt, budget, "the request was not sent; reduce the conversation (/compact or prune) before retrying")
|
|
163
188
|
}
|
package/provider/google.mjs
CHANGED
|
@@ -38,7 +38,7 @@ export function normalizeTools(tools) {
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Convert OpenAI-format messages to Gemini contents array.
|
|
41
|
-
* Gemini: [{ role: "user"|"model", parts: [{ text }] }]
|
|
41
|
+
* Gemini: [{ role: "user"|"model", parts: [{ text } | { functionCall } | { functionResponse }] }]
|
|
42
42
|
* system → systemInstruction (top-level in request body)
|
|
43
43
|
*/
|
|
44
44
|
export function convertMessages(messages) {
|
|
@@ -50,7 +50,7 @@ export function convertMessages(messages) {
|
|
|
50
50
|
const role = m.role === "assistant" ? "model" : "user"
|
|
51
51
|
|
|
52
52
|
const parts = []
|
|
53
|
-
if (typeof m.content === "string") {
|
|
53
|
+
if (typeof m.content === "string" && m.role !== "tool") {
|
|
54
54
|
parts.push({ text: m.content })
|
|
55
55
|
} else if (Array.isArray(m.content)) {
|
|
56
56
|
for (const part of m.content) {
|
|
@@ -64,6 +64,23 @@ export function convertMessages(messages) {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
if (m.role === "assistant") {
|
|
68
|
+
for (const call of m.tool_calls ?? []) {
|
|
69
|
+
let args = {}
|
|
70
|
+
const rawArguments = call.function?.arguments ?? call.arguments
|
|
71
|
+
try { args = JSON.parse(rawArguments || "{}") } catch { /* 与公共工具参数读取一致:畸形参数按空对象投影 */ }
|
|
72
|
+
const part = { functionCall: { name: call.function?.name ?? call.name, args } }
|
|
73
|
+
const thoughtSignature = call.extra_content?.google?.thought_signature
|
|
74
|
+
if (typeof thoughtSignature === "string" && thoughtSignature) part.thoughtSignature = thoughtSignature
|
|
75
|
+
parts.push(part)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (m.role === "tool") {
|
|
79
|
+
const callId = String(m.tool_call_id ?? "")
|
|
80
|
+
const name = m.name || (/_\d+$/.test(callId) ? callId.replace(/_\d+$/, "") : "")
|
|
81
|
+
if (!name) throw new Error("Google tool result is missing its function name")
|
|
82
|
+
parts.push({ functionResponse: { name, response: { result: String(m.content ?? "") } } })
|
|
83
|
+
}
|
|
67
84
|
if (parts.length === 0) continue
|
|
68
85
|
|
|
69
86
|
// Gemini doesn't allow consecutive same-role messages; merge
|
|
@@ -82,15 +99,15 @@ export function convertMessages(messages) {
|
|
|
82
99
|
export async function chat(provider, { messages, tools, onToken, onReasoning, onWait, signal, toolChoice, logCtx }) {
|
|
83
100
|
const systemMessages = messages.filter((m) => m.role === "system")
|
|
84
101
|
const contents = convertMessages(messages)
|
|
102
|
+
// §2.2 发送面:只读 maxTokens(输出合同)——请求体与发送前净判共用这一个对象,不各算一套。
|
|
103
|
+
const budget = requestBudget(provider)
|
|
85
104
|
|
|
86
105
|
const body = {
|
|
87
106
|
contents,
|
|
88
107
|
generationConfig: {
|
|
89
108
|
...(provider.temperature != null ? { temperature: provider.temperature } : {}),
|
|
90
109
|
// §6.17 发送面同源:显式才发(requestBudget().maxTokens——无显式 ⇒ undefined ⇒ 字段不落)
|
|
91
|
-
...(
|
|
92
|
-
? { maxOutputTokens: requestBudget(provider).maxTokens }
|
|
93
|
-
: {}),
|
|
110
|
+
...(budget.maxTokens !== undefined ? { maxOutputTokens: budget.maxTokens } : {}),
|
|
94
111
|
// #1200(MODEL-SPECS.md §18.8):off 形在场 ⇒ 禁思考形——载荷逐字同标题径先例
|
|
95
112
|
// (`generate-title.mjs` 的 `generateTitle`);其余值(缺 ∥ on 形 ∥ null)⇒ 零发(误发 none = 反向禁用)。
|
|
96
113
|
...(provider.thinking?.type === "disabled" ? { thinkingConfig: { thinkingLevel: "none" } } : {}),
|
|
@@ -123,7 +140,7 @@ export async function chat(provider, { messages, tools, onToken, onReasoning, on
|
|
|
123
140
|
// §6.17 发送面净判:估准面补 `tools`(原只投影 messages);body 用 `maxOutputTokens`、无 `max_tokens` 键 ⇒ 减项恒 0
|
|
124
141
|
const estimated = estimateRequestTokens({ messages, tools })
|
|
125
142
|
const estPrompt = estimated - (body.max_tokens ?? 0)
|
|
126
|
-
assertPromptFits(provider, estPrompt, logCtx)
|
|
143
|
+
assertPromptFits(provider, estPrompt, logCtx, budget)
|
|
127
144
|
await rateGate(provider, estimated, onWait, signal)
|
|
128
145
|
|
|
129
146
|
// 2026-08-31:5xx/网络与 OpenAI 格式统一退避重试链(原完全无重试——Gemini 高峰
|
|
@@ -141,7 +158,7 @@ export async function chat(provider, { messages, tools, onToken, onReasoning, on
|
|
|
141
158
|
{ signal, onWait, buildMessage: (status, text) => `Gemini API error ${status}: ${text}` },
|
|
142
159
|
)
|
|
143
160
|
|
|
144
|
-
const result = await parseGeminiStream(response, { onToken, onReasoning, signal, idleMs: effectiveBodyIdleMs(provider) })
|
|
161
|
+
const result = await parseGeminiStream(response, { onToken, onReasoning, signal, idleMs: effectiveBodyIdleMs(provider), firstChunkMs: effectiveFetchTimeoutMs(provider) })
|
|
145
162
|
recordRate(provider, estimated, result.usage)
|
|
146
163
|
|
|
147
164
|
const usage = result.usage
|
|
@@ -175,7 +192,7 @@ function mapGeminiFinishReason(reason) {
|
|
|
175
192
|
* Parse Gemini SSE stream.
|
|
176
193
|
* Format: data: {...}\n\n (each line is a complete JSON object)
|
|
177
194
|
*/
|
|
178
|
-
async function parseGeminiStream(response, { onToken, onReasoning, signal, idleMs = DEFAULT_BODY_IDLE_MS }) {
|
|
195
|
+
export async function parseGeminiStream(response, { onToken, onReasoning, signal, idleMs = DEFAULT_BODY_IDLE_MS, firstChunkMs }) {
|
|
179
196
|
const result = { content: "", reasoning: "", toolCalls: [], usage: null, finishReason: null }
|
|
180
197
|
const decoder = new TextDecoder()
|
|
181
198
|
let buffer = ""
|
|
@@ -212,7 +229,7 @@ async function parseGeminiStream(response, { onToken, onReasoning, signal, idleM
|
|
|
212
229
|
slot = { id: part.functionCall.name + "_" + result.toolCalls.length, name: part.functionCall.name, arguments: JSON.stringify(part.functionCall.args || {}) }
|
|
213
230
|
result.toolCalls.push(slot)
|
|
214
231
|
}
|
|
215
|
-
//
|
|
232
|
+
// Gemini Function Calling 原生签名:字段名 `thoughtSignature`,统一历史中存为 extra_content.google.thought_signature。
|
|
216
233
|
if (typeof part.thoughtSignature === "string" && part.thoughtSignature) {
|
|
217
234
|
slot.extra_content = { google: { thought_signature: part.thoughtSignature } }
|
|
218
235
|
}
|
|
@@ -222,21 +239,31 @@ async function parseGeminiStream(response, { onToken, onReasoning, signal, idleM
|
|
|
222
239
|
|
|
223
240
|
if (!response.body) throw new Error("No stream response body")
|
|
224
241
|
// 2026-09-01 读侧 idle 超时(同 sse.mjs):body 有数据流动即不超时;连续 `idleMs` 无新 chunk 判死
|
|
242
|
+
// (首 chunk 之前改用首 chunk 窗,见下)
|
|
243
|
+
// 首 chunk 两态臂(TIMEOUT-DIGEST.md §2.4):首个 body 字节前用 `firstChunkMs`,之后每次重挂用 `idleMs`
|
|
225
244
|
let idleTimer = null
|
|
226
245
|
let idleError = null
|
|
246
|
+
let gotFirstChunk = false
|
|
227
247
|
const armIdle = () => {
|
|
228
248
|
if (idleTimer) clearTimeout(idleTimer)
|
|
249
|
+
// 同 sse.mjs:首挂窗缺省取 `idleMs`,相位文案按态取(未传者仍报既有 `google-sse-idle`)
|
|
250
|
+
const firstArm = !gotFirstChunk
|
|
251
|
+
const ms = firstArm ? (firstChunkMs ?? idleMs) : idleMs
|
|
252
|
+
const firstChunkPhase = firstArm && firstChunkMs != null
|
|
229
253
|
idleTimer = setTimeout(() => {
|
|
230
254
|
// #878:断流单点分流——直连 fetch(web 流)走 `IDLE_ABORT` 内部 abort 通道;
|
|
231
|
-
// proxy 形回落 destroyBody
|
|
232
|
-
idleError =
|
|
255
|
+
// proxy 形回落 destroyBody(原契约)。
|
|
256
|
+
idleError = firstChunkPhase
|
|
257
|
+
? timeoutError(`SSE first-chunk timeout: no data for ${ms / 1000}s`, "provider", "google-sse-first-chunk")
|
|
258
|
+
: timeoutError(`SSE idle timeout: no data for ${ms / 1000}s`, "provider", "google-sse-idle")
|
|
233
259
|
try { terminateBody(response, idleError) } catch { /* already gone */ }
|
|
234
|
-
},
|
|
260
|
+
}, ms)
|
|
235
261
|
idleTimer.unref?.()
|
|
236
262
|
}
|
|
237
263
|
armIdle()
|
|
238
264
|
try {
|
|
239
265
|
for await (const chunk of response.body) {
|
|
266
|
+
gotFirstChunk = true
|
|
240
267
|
armIdle()
|
|
241
268
|
if (signal?.aborted) {
|
|
242
269
|
throw abortError(signal, "provider", "transport-google")
|
package/provider/rate.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
2
|
* provider/rate.mjs — TPM/RPM proactive throttling gate
|
|
3
3
|
* Sliding-window accounting; pre-check budget before sending requests; sleep until window frees space when over budget.
|
|
4
4
|
*/
|
|
@@ -42,8 +42,16 @@ function rateKey(provider) {
|
|
|
42
42
|
return `${base}|${provider.apiKey ?? ""}`
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/** 估算口径(CONTEXT-COMPACTION.md §6.17.1 链一,**单源**):ASCII `ASCII_CHARS_PER_TOKEN` 字符/token;
|
|
46
|
+
* 非 ASCII(CJK/emoji)1 字/token(保守方向,不动)。取 3 的依据 = 失败现场服务端报 723,272 in messages
|
|
47
|
+
* ÷ 同刻状态栏 491k ≈ 2.7 字符/token ⇒ 旧值 `/4` 低报约 1.47 倍(余下由链二按模型自校准吸收)。 */
|
|
48
|
+
export const ASCII_CHARS_PER_TOKEN = 3
|
|
49
|
+
/** 估算口径版本位(§6.17.1 链二):落槽的校准样本只在同版本内复用——改公式即自动弃旧样本。 */
|
|
50
|
+
export const ESTIMATOR_VERSION = 1
|
|
51
|
+
|
|
45
52
|
/** Rough estimate of text token count.
|
|
46
|
-
* ASCII ~
|
|
53
|
+
* ASCII ~3 chars/token (`ASCII_CHARS_PER_TOKEN`); non-ASCII (CJK/emoji) ~1 char/token
|
|
54
|
+
* (conservative; measured BPE is 1.5-2.5 chars/token).
|
|
47
55
|
* §2.5 #114 并入(token 估算取并集):数组内容按 part 分派——text 走单串估算,
|
|
48
56
|
* image_url part 计 85 tokens(VSC 侧口径)。 */
|
|
49
57
|
export function estimateText(s) {
|
|
@@ -62,7 +70,7 @@ export function estimateText(s) {
|
|
|
62
70
|
function _estimateSingle(s) {
|
|
63
71
|
let nonAscii = 0
|
|
64
72
|
for (let i = 0; i < s.length; i++) if (s.charCodeAt(i) > 0x7f) nonAscii++
|
|
65
|
-
return Math.ceil((s.length - nonAscii) /
|
|
73
|
+
return Math.ceil((s.length - nonAscii) / ASCII_CHARS_PER_TOKEN) + nonAscii
|
|
66
74
|
}
|
|
67
75
|
|
|
68
76
|
/** Estimated prompt tokens for this request */
|
package/provider/responses.mjs
CHANGED
|
@@ -18,6 +18,8 @@ import { requestWithRetry } from "./retry.mjs"
|
|
|
18
18
|
import { rateGate, recordRate, estimateRequestTokens } from "./rate.mjs"
|
|
19
19
|
import { buildBody, normalizeUsage } from "./responses-request.mjs"
|
|
20
20
|
import { classifyResponsesErrorCode, assertPromptFits } from "./errors.mjs"
|
|
21
|
+
// §2.2 发送面:只读 maxTokens(输出合同)——发送前净判共用同一个预算对象
|
|
22
|
+
import { requestBudget } from "../config.mjs"
|
|
21
23
|
// 同名 re-export(2026-09-29 structure-split-2 · 台账 #620——缝 = 同名再出口):请求构造面出档 `provider/responses-request.mjs`;
|
|
22
24
|
// `buildBody` / `isStoreRequiredHost` / `builtinToolsFor` 三名既有导出经本档转口——消费者 import 面零改。
|
|
23
25
|
export { buildBody, isStoreRequiredHost, builtinToolsFor } from "./responses-request.mjs"
|
|
@@ -232,7 +234,7 @@ export async function chat(provider, { messages, tools, onToken, onReasoning, on
|
|
|
232
234
|
// §6.17 发送面净判:估准面补 `tools`(原只投影 messages);body 用 `max_output_tokens`、无 `max_tokens` 键 ⇒ 减项恒 0
|
|
233
235
|
const estimated = estimateRequestTokens({ messages, tools })
|
|
234
236
|
const estPrompt = estimated - (body.max_tokens ?? 0)
|
|
235
|
-
assertPromptFits(provider, estPrompt, logCtx)
|
|
237
|
+
assertPromptFits(provider, estPrompt, logCtx, requestBudget(provider))
|
|
236
238
|
await rateGate(provider, estimated, onWait, signal)
|
|
237
239
|
// 定制头 + 产品标识头(UA 不可被渠道覆盖——PROVIDER.md §6.17):定制头在前、内置头在后——同名内置头胜出(三处 fetch 共用)
|
|
238
240
|
const headers = { ...withUserAgent(provider.headers), "Content-Type": "application/json", Authorization: `Bearer ${provider.apiKey}` }
|
package/provider/sse.mjs
CHANGED
|
@@ -90,7 +90,7 @@ function finalizeToolCalls(result) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
export async function readSSE(response, { onToken, onReasoning, rules, signal, firedPatterns: sharedFired, idleMs = DEFAULT_BODY_IDLE_MS }) {
|
|
93
|
+
export async function readSSE(response, { onToken, onReasoning, rules, signal, firedPatterns: sharedFired, idleMs = DEFAULT_BODY_IDLE_MS, firstChunkMs }) {
|
|
94
94
|
// Early intercept: non-SSE responses — either error bodies (HTTP >= 400) or
|
|
95
95
|
// valid single-chunk JSON completions (some APIs return JSON despite stream:true).
|
|
96
96
|
const contentType = response.headers.get("content-type") || ""
|
|
@@ -198,23 +198,34 @@ export async function readSSE(response, { onToken, onReasoning, rules, signal, f
|
|
|
198
198
|
// 2026-09-01 读侧 idle 超时(根因修复):原实现靠 fetch 层的 600s 绝对墙钟兜底——长上下文子代理
|
|
199
199
|
// 单次生成(或上游排队)超 10 分钟即被腰斩("The operation was aborted due to timeout" 直透)。
|
|
200
200
|
// 现改为:读侧空闲超时——body 只要有数据流动就永不超时,连续 `idleMs` 无新 chunk 才判死
|
|
201
|
-
//
|
|
201
|
+
// (首 chunk 之前改用首 chunk 窗,见下;`idleMs` 由 provider/core.mjs 的 effectiveBodyIdleMs 算好传入)。
|
|
202
202
|
// 直连 fetch 与 proxyFetch 统一走这里(proxy 的 _bodyIdleMs 语义与之等价,双保险)。
|
|
203
203
|
let idleTimer = null
|
|
204
204
|
let idleError = null
|
|
205
|
+
// 首 chunk 两态臂(TIMEOUT-DIGEST.md §2.4):首次挂用 `firstChunkMs`,收到第一个 body 字节后
|
|
206
|
+
// 每次重挂改用 `idleMs`——翻转不可逆(流中途不会退回「等首 chunk」态)。
|
|
207
|
+
let gotFirstChunk = false
|
|
205
208
|
const armIdle = () => {
|
|
206
209
|
if (idleTimer) clearTimeout(idleTimer)
|
|
210
|
+
// 窗与文案同源(`N` = 该相位实际生效的窗值):首挂窗缺省取 `idleMs`(入参缺省 = 老行为),
|
|
211
|
+
// 相位文案按态取——真传了首 chunk 窗才是分窗使用者(未传者仍报既有 `sse-idle`,逐字零变)。
|
|
212
|
+
const firstArm = !gotFirstChunk
|
|
213
|
+
const ms = firstArm ? (firstChunkMs ?? idleMs) : idleMs
|
|
214
|
+
const firstChunkPhase = firstArm && firstChunkMs != null
|
|
207
215
|
idleTimer = setTimeout(() => {
|
|
208
216
|
// #878:断流单点分流——直连 fetch(web 流)走 `IDLE_ABORT` 内部 abort 通道,
|
|
209
217
|
// proxy 形回落 destroyBody(原契约)。
|
|
210
|
-
idleError =
|
|
218
|
+
idleError = firstChunkPhase
|
|
219
|
+
? timeoutError(`SSE first-chunk timeout: no data for ${ms / 1000}s`, "provider", "sse-first-chunk")
|
|
220
|
+
: timeoutError(`SSE idle timeout: no data for ${ms / 1000}s`, "provider", "sse-idle")
|
|
211
221
|
try { terminateBody(response, idleError) } catch { /* already gone */ }
|
|
212
|
-
},
|
|
222
|
+
}, ms)
|
|
213
223
|
idleTimer.unref?.()
|
|
214
224
|
}
|
|
215
225
|
armIdle()
|
|
216
226
|
try {
|
|
217
227
|
for await (const chunk of response.body) {
|
|
228
|
+
gotFirstChunk = true
|
|
218
229
|
armIdle()
|
|
219
230
|
if (signal?.aborted) {
|
|
220
231
|
throw abortError(signal, "provider", "stream-read")
|
package/provider-flows.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* provider-flows.mjs — provider 加 ∕ 删 ∕ 密钥三流程 + 渠道准入探针判据(核件 —— 「桌面处理流 · VSC 对齐」
|
|
3
3
|
* 批 R8 上提产物;2026-09-28)。
|
|
4
4
|
*
|
|
5
|
-
* 上提源 = VSC `thincoder-vscode/src/extension/provider-flows.mjs`(`addProviderFlow
|
|
6
|
-
* `removeProviderFlow
|
|
5
|
+
* 上提源 = VSC `thincoder-vscode/src/extension/provider-flows.mjs`(`addProviderFlow` ∕
|
|
6
|
+
* `removeProviderFlow` ∕ `setKeyFlow` ∕ `probeProviderAdmission`)——**纯搬 + 转口,零语义改**
|
|
7
7
|
* (三流程步序 ∕ 字段校验 ∕ 拒因 ∕ 探针语义逐字);VSC 自持副本已随本批(parity-b4)迁移改指本档(双写窗口关闭——本档 = 桌面 ∕ VSC 消费单源)。
|
|
8
8
|
*
|
|
9
9
|
* 转口(宿主面 ⇒ 注入缝;本档零宿主依赖、零 `vscode` 引用):
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* session-identity.mjs — 进程会话 id 单源(零 import 叶档)——PROVIDER.md §6.17「会话标识头」。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单立一叶:请求装配面 `client-identity.mjs` 是零依赖叶子,而每个 transport 都 import 它;
|
|
5
|
+
* 会话 id 又要「每次请求现取」。若从 `session-slots.mjs` 取,会把它的依赖链(config 读盘 ∥ 会话
|
|
6
|
+
* 存储 ∥ 进程探测共 8 档)连带拉进每个 transport 的 import 图。故本体住本档,`session-slots.mjs`
|
|
7
|
+
* 反向 re-export——既有 import 面零改。
|
|
8
|
+
*
|
|
9
|
+
* 语义:进程级惰性生成、零 IO、进程内稳定;形 `{pid}-{ts}-{rand6}`。它区分的是「哪一次进程会话」,
|
|
10
|
+
* 不是「槽位里的哪一份对话」(按对话槽分桶属另批穿参改造)。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
let currentSessionId = null
|
|
14
|
+
|
|
15
|
+
/** Generate unique session ID for this process */
|
|
16
|
+
export function getSessionId() {
|
|
17
|
+
if (!currentSessionId) {
|
|
18
|
+
currentSessionId = `${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
|
19
|
+
}
|
|
20
|
+
return currentSessionId
|
|
21
|
+
}
|
package/session-index-build.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* session-index-build.mjs — 会话枚举 / 取源 / 水位增量 / 会话重建(SESSION.md §6.19 D-SE44/D-SE45;写面)。
|
|
3
3
|
*
|
|
4
4
|
* 机制契约全文 = `docs/core/design/SESSION.md` §6.19(D2 单一权威源)。本档只**读**主存(槽 JSON 整读 / 段偏移
|
|
5
|
-
* `readSync`),绝不写回 sessions 树(零权威);`session-index.mjs` 的 >300
|
|
5
|
+
* `readSync`),绝不写回 sessions 树(零权威);`session-index.mjs` 的 >300 行线二分产物(设计「跨档线
|
|
6
6
|
* 拆分预案」:枚举与水位增量 ∥ 重建 / 拍 / 清行——拍 / 清行 / 有界趟住 `session-index-pass.mjs`)。
|
|
7
7
|
*
|
|
8
8
|
* 取源**双路**:`<槽文件>.d/` 含 `seg-*.jsonl` ⇒ `src=sidecar`(增量面);否则 `src=json`(槽 JSON
|
package/session-index-pass.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* session-index-pass.mjs — 有界趟 / 全量重建 / 源消失清行 / 延迟拍(SESSION.md §6.19 D-SE45/D-SE46)。
|
|
3
3
|
*
|
|
4
|
-
* `session-index-build.mjs` 的 >300
|
|
4
|
+
* `session-index-build.mjs` 的 >300 行线二分产物(设计「跨档线拆分预案」:枚举与水位增量 ∥
|
|
5
5
|
* 重建 / 拍 / 清行)。触发三点(均不触主存档):
|
|
6
6
|
* ① 懒保证(`session-index-build.mjs` `ensureSessionIndexed`——射程 = 有段档)
|
|
7
7
|
* ② 启动窗外延迟拍(`scheduleSessionIndexPass`——端壳挂点,核会话档零改)
|
package/session-index-query.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* session-index-query.mjs — 索引查询与 FTS 检索(SESSION.md §6.19 D-SE47;查询面)。
|
|
3
3
|
*
|
|
4
|
-
* `session-index.mjs` 的 >300
|
|
4
|
+
* `session-index.mjs` 的 >300 行线二分产物(设计「跨档线拆分预案」:DDL / 打开与自愈 ∥
|
|
5
5
|
* 查询与 FTS 检索)。路由判据 / 语义分面 = §6.19 查询面路由表:
|
|
6
6
|
* · 单会话(`path=<文件>` ∈ sessions 根 ∧ 库内有行)——`keyword` = 子串(`LIKE`,既有契约不变)
|
|
7
7
|
* · 跨会话(`path:"all"`)——`keyword` = FTS 词 / 短语(`buildFtsQuery` 单源);无词元 ⇒ 退化 `LIKE`
|
package/session-index.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 机制契约全文 = `docs/core/design/SESSION.md` §6.19(D-SE43–D-SE47;D2 单一权威源)。
|
|
5
5
|
* 本档 = 「DB 打开 / DDL / schema / 测试缝」面;查询与 FTS 检索 = `session-index-query.mjs`;
|
|
6
6
|
* 写面(枚举 / 水位增量 / 会话重建 / 延迟拍 / 清行)= `session-index-build.mjs` +
|
|
7
|
-
* `session-index-pass.mjs`(>300
|
|
7
|
+
* `session-index-pass.mjs`(>300 行线按设计「跨档线拆分预案」二分);命令面 = `session-index-cmd.mjs`。
|
|
8
8
|
*
|
|
9
9
|
* **零权威**:主存(槽 JSON + `{槽}.d/` sidecar + manifest)= 真源;本库只读主存(整读 / 偏移
|
|
10
10
|
* `readSync`),**绝不写回** sessions 树;库丢 / 坏 = 重生成(D-SE46 打开即验 + 改名保留自愈)。
|