@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
package/config-normalize.mjs
CHANGED
|
@@ -7,10 +7,36 @@
|
|
|
7
7
|
*
|
|
8
8
|
* config.mjs re-exports the four load-bearing ones (`sanitizeSubagentModel` ·
|
|
9
9
|
* `sanitizeSubagentModels` · `normalizeProxy` · `normalizeTeamSection`) — importers keep their
|
|
10
|
-
* path. `sanitizeProviderHeaders` / `sanitizeConsultModels` /
|
|
11
|
-
*
|
|
10
|
+
* path. `sanitizeProviderHeaders` / `sanitizeConsultModels` / `providerDropReason` (+ its admission
|
|
11
|
+
* face `isUsableProviderEntry`) / the two warn helpers are consumed by `loadConfig` only and are not
|
|
12
|
+
* part of the public config.mjs surface — `reloadProviders` shares that one judgement by going through
|
|
13
|
+
* `loadConfig`, it does not import them itself.
|
|
12
14
|
*/
|
|
13
15
|
|
|
16
|
+
/** 渠道条目丢弃原因(`docs/core/design/PROVIDER.md` §6.29「丢弃要看得见」):返回闭集四种之一,
|
|
17
|
+
* 可进使用面 ⇒ `null`。**判据单源**——准入谓词 `isUsableProviderEntry` 就是本函数的 `null` 判定,
|
|
18
|
+
* 所以「收不收」与「记什么原因」永远对着同一处代码判,不会给同一条目判出两种说法。
|
|
19
|
+
* 为什么只出原因、不出条目内容:载体会进日志 ∥ 报错 ∥ 别人的调试输出,而一条「有 apiKey 却缺 name」
|
|
20
|
+
* 的条目若取 JSON,`sk-…` 就原样写进数据层;判据只需要知道「第几条坏了、坏在哪」,条目内容对它零价值。
|
|
21
|
+
* 为什么按 name 认:`name` 是渠道唯一句柄(`findProvider` ∥ `parseModelRef` ∥ 会话槽 ∥ 选择器
|
|
22
|
+
* 全按 name 匹配),无名条目既不可寻址也不可被发送,留着只能让读它的地方失真——而失真点就是
|
|
23
|
+
* `/model` 的 `${p.name.padEnd(12)}` 抛 `Cannot read properties of undefined (reading 'padEnd')`。
|
|
24
|
+
* 数组不是条目(`typeof [] === "object"`);空串 name 同样不可寻址 ⇒ 一并拒绝。
|
|
25
|
+
* 「不给无名条目编名字」:编名等于把坏配置伪装成好配置,所以这里只判真伪,不修补。 */
|
|
26
|
+
export function providerDropReason(p) {
|
|
27
|
+
if (p === null) return "null"
|
|
28
|
+
if (typeof p !== "object" || Array.isArray(p)) return "not an object"
|
|
29
|
+
if (typeof p.name !== "string") return "no name"
|
|
30
|
+
if (p.name === "") return "empty name"
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 渠道条目准入判据——本谓词只是 `providerDropReason` 的准入面(`=== null` ⇒ 可引用)。
|
|
35
|
+
* 装载(`thincoder-core/config.mjs` 的 `providers:` 分支)∥ 运行中重读(`reloadProviders`)共用。 */
|
|
36
|
+
export function isUsableProviderEntry(p) {
|
|
37
|
+
return providerDropReason(p) === null
|
|
38
|
+
}
|
|
39
|
+
|
|
14
40
|
/** F-4 (IKCDMR) 软失败清洗(D-S1 范式——loadConfig 是 CLI 启动砖点):consultModels 非法
|
|
15
41
|
* 条目过滤不 throw——非数组 → []、形状非法/未知渠道丢弃、超 5 截断(keep 前 5)。
|
|
16
42
|
* 返回 { keep, dropped }——dropped 供一次性警告;merged.agent.consultModelsFiltered 挂载
|
package/config-presets.mjs
CHANGED
|
@@ -51,9 +51,11 @@ export const PROVIDER_PRESETS = {
|
|
|
51
51
|
// `/messages` 侧(同 key——模型按侧选)。字段集 = 最小面:`thinking` / `reasoningEffort` 不设 = 不发
|
|
52
52
|
// (D-13 同口径);`maxTokens` 仅 anthropic 侧设 `65536`(该 transport `max_tokens` 必发——不设即落规格
|
|
53
53
|
// 行值 131072,超渠道口径)。**待验(无 key——未实拉 `/models` ∕ 载荷未实测;接入后按实拉复核)**;
|
|
54
|
-
// `x-opencode-session` 头 =
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
// `x-opencode-session` 头 = **必需**(不带 ⇒ 上游回 `HTTP 400 {"type":"MissingSessionID"}`——实测见
|
|
55
|
+
// PROVIDER.md §6.17);值形 = 模板 `${sessionId}`,每次请求现取本进程会话 id(解析单源 = `withUserAgent`)。
|
|
56
|
+
// 两条预设都携缺省值:新装即带上,用户无需手改配置;不声明该头的其它渠道出站头零变化。
|
|
57
|
+
"opencode-go": { baseURL: "https://opencode.ai/zen/go/v1", headers: { "x-opencode-session": "thincoder-${sessionId}" }, desc: "OpenCode Go subscription (sk- key from opencode.ai/zen; OpenAI-compatible models — MiniMax/Qwen via opencode-go-anthropic)" },
|
|
58
|
+
"opencode-go-anthropic": { baseURL: "https://opencode.ai/zen/go/v1", format: "anthropic", maxTokens: 65536, headers: { "x-opencode-session": "thincoder-${sessionId}" }, desc: "OpenCode Go — Anthropic Messages side (same sk- key as opencode-go; MiniMax/Qwen models)" },
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
/** Build the stored provider entry from a preset — strip the display field, keep the rest
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config-reload.mjs — 运行中重读盘上渠道表(`docs/core/design/PROVIDER.md` §6.30)。
|
|
3
|
+
*
|
|
4
|
+
* 从 `thincoder-core/config.mjs` 抽出:该档落盘后越过 `docs/core/design/DOC-DISCIPLINE.md` §3.10 所定的 500 行,
|
|
5
|
+
* 抽法沿 §6.30 指的候选线——`reloadProviders` 整段移出,`config.mjs` 以
|
|
6
|
+
* re-export 保持导入面(形态同 `config-migrate.mjs` ∥ `config-io.mjs` 两次既有拆分)。
|
|
7
|
+
*
|
|
8
|
+
* 环:本档 import `config.mjs` 的 `loadConfig` ∥ `proxy.mjs` 的 `injectProxy`,而两者都反向指向
|
|
9
|
+
* `config.mjs`——两处都只在调用期取活绑定,模块求值期不触碰,故环安全(同 `proxy.mjs` 既有形态)。
|
|
10
|
+
*/
|
|
11
|
+
import { loadConfig } from "./config.mjs"
|
|
12
|
+
import { injectProxy } from "./proxy.mjs"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 运行中重读盘上渠道表——`/model` 打开边界调用:「切的时候读」,不必重启。四步:
|
|
16
|
+
* ① 读盘(`loadConfig`,含它自带的老字段迁移写回——既有行为,本批不新增写盘);
|
|
17
|
+
* ② 准入判据由装载路径本身施加(`isUsableProviderEntry`,见 `thincoder-core/config-normalize.mjs`);
|
|
18
|
+
* 本档不重复应用谓词、也不造第二份丢弃记录——判据单源、丢弃载体单源都在装载那一步;
|
|
19
|
+
* ③ `injectProxy` 按当前 `config.proxy` 重算派生值 `proxyUri`;
|
|
20
|
+
* ④ 按 name 把会话态的 `_unavailable` 从旧表带到新表,再把**同一数组**赋给三个读点。
|
|
21
|
+
*
|
|
22
|
+
* **同一数组同赋值**:启动时 `agent.config.providersList` 与 `agent.config.providers` 本就是
|
|
23
|
+
* `loadConfig` 里那个数组(整表别名);只换一边就分叉——`thincoder-core/advisor/run.mjs` ∥
|
|
24
|
+
* `thincoder-core/agent-tools/subagent-async.mjs` 读的是 `providersList` 那一侧。
|
|
25
|
+
*
|
|
26
|
+
* **读失败 ⇒ `{ ok:false, error }`,绝不 throw、绝不退回旧表**:拿旧表当现况正是本缺陷的形状
|
|
27
|
+
* (盘上改了不生效,就是因为读的不是盘),所以调用方必须拒开列表并报错,内存态保持原样。
|
|
28
|
+
*
|
|
29
|
+
* 不动面(半量新鲜度,§6.30「前置」):`defaultModel` ∥ `agent.provider` ∥ `providerState` 仍是
|
|
30
|
+
* 启动时 `resolveProviderPlan` 解析的那份——替换运行态属运行面变更,不在本批暗改。
|
|
31
|
+
*
|
|
32
|
+
* @param agent 会话 agent(读 `agent.providers` 取会话态,写 `agent.providers` ∥ `agent.config.*`)
|
|
33
|
+
* @returns {{ ok: boolean, dropped: string[], error?: string }} dropped = 本次丢弃记录(一句一条)
|
|
34
|
+
*/
|
|
35
|
+
export function reloadProviders(agent) {
|
|
36
|
+
let fresh
|
|
37
|
+
try {
|
|
38
|
+
fresh = loadConfig()
|
|
39
|
+
} catch (error) {
|
|
40
|
+
return { ok: false, error: error?.message ?? String(error), dropped: [] }
|
|
41
|
+
}
|
|
42
|
+
const dropped = Array.isArray(fresh.providersDropped) ? fresh.providersDropped : []
|
|
43
|
+
const providers = fresh.providersList
|
|
44
|
+
// 会话态按 name 合并且只带 truthy 标记:`_unavailable` 是探针写在内存里的
|
|
45
|
+
// (`thincoder-cli/src/tui/provider-admin.mjs`),盘上没有它,整表替换会把它冲掉——用户会看到
|
|
46
|
+
// 刚标过不可用的渠道又变回可用。
|
|
47
|
+
const previous = new Map((Array.isArray(agent.providers) ? agent.providers : []).filter((p) => p?.name).map((p) => [p.name, p]))
|
|
48
|
+
for (const provider of providers) {
|
|
49
|
+
if (previous.get(provider.name)?._unavailable) provider._unavailable = true
|
|
50
|
+
}
|
|
51
|
+
injectProxy(providers, fresh)
|
|
52
|
+
agent.providers = providers
|
|
53
|
+
agent.config ??= {}
|
|
54
|
+
agent.config.providersList = providers
|
|
55
|
+
agent.config.providers = providers
|
|
56
|
+
// 载体跟新:盘上改好了就没有丢弃 ⇒ 清掉(`/model` 表头据此消失);同一键、同形(string[])。
|
|
57
|
+
agent.config.providersDropped = dropped.length ? dropped : undefined
|
|
58
|
+
return { ok: true, dropped }
|
|
59
|
+
}
|
package/config.mjs
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import { existsSync, readFileSync } from "node:fs"
|
|
15
15
|
import { parseModelRef, resolveChannelModel, resolveProviderPlan, resolveRuntimeProvider, defaultModelReason } from "./model-ref.mjs"
|
|
16
16
|
// 老形态迁移核(M7 v2——纯函数零依赖——本文件超 500 行硬限拆分,VSC 同构文件)
|
|
17
|
-
import { migrateLegacyModelFields } from "./config-migrate.mjs"
|
|
17
|
+
import { migrateLegacyModelFields, resolveWorkMode } from "./config-migrate.mjs"
|
|
18
18
|
import { expandHome } from "./expand-home.mjs"
|
|
19
19
|
// 核内单一读写面 + 预设表(§2.5 #129 / #131——拆档以容纳 500 行硬限)
|
|
20
20
|
import {
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
} from "./config-io.mjs"
|
|
24
24
|
|
|
25
25
|
export { parseModelRef, resolveChannelModel, resolveProviderPlan, resolveRuntimeProvider, defaultModelReason, migrateLegacyModelFields }
|
|
26
|
+
export { WORK_MODES, resolveWorkMode, resolveSessionWorkMode, setConfigWorkMode } from "./config-migrate.mjs"
|
|
26
27
|
export { PROVIDER_PRESETS, presetToEntry, configDir, configPath, _setConfigPathForTest, _resetConfigPathForTest }
|
|
27
28
|
// 核内单一写盘执行体(已迁 `config-io.mjs`)——本档 re-export 保持既有导入面(§2.5 #131)。
|
|
28
29
|
export { writeConfigAtomic }
|
|
@@ -43,94 +44,15 @@ export { specForModel, providerSpec, providerSpecResolution, specMatch, formatCo
|
|
|
43
44
|
import { positiveInt, warnContextOnce } from "./model-context.mjs"
|
|
44
45
|
|
|
45
46
|
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/** Output reservation counted against the window: the value ACTUALLY sent as max_tokens —
|
|
56
|
-
* explicit `provider.maxTokens` when set (the transport faces send it verbatim), else the spec
|
|
57
|
-
* `maxOutput`, else 0. NOT capped: the old 25% cap reopened a residual band between the counted
|
|
58
|
-
* reservation and the real output budget — messages could cross the true window while still below
|
|
59
|
-
* the compaction line (2026-10-18 overflow 400: budget counted 250_000, 393_216 actually sent).
|
|
60
|
-
* Single source = §6.17 requestBudget; this is its reserve face (advisor budget reuses it). */
|
|
61
|
-
export function outputReserve(provider, spec) {
|
|
62
|
-
const explicit = provider?.maxTokens
|
|
63
|
-
return Number.isFinite(explicit) && explicit > 0 ? explicit : spec?.maxOutput ?? 0
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Usable input window = window − output reservation. Degenerate guard: a reservation
|
|
67
|
-
* ≥ the window is non-physical (no input could ever fit — e.g. `doubao-seed-2-1-turbo-260628`:
|
|
68
|
-
* 256_000 window / 256_000 `maxOutput` (官方口径) ∥ the test harness's 1K window vs the
|
|
69
|
-
* default spec); collapsing the budget to 0 would be instant `context_limit` death — the very
|
|
70
|
-
* failure the reservation fold exists to prevent. Fall back to half the window.
|
|
71
|
-
* (2026-10-06——收口核验捕获:advisor-loop-split B5a 红。) */
|
|
72
|
-
export function usableWindow(context, reserve) {
|
|
73
|
-
const ctx = context ?? 0
|
|
74
|
-
const usable = ctx - reserve
|
|
75
|
-
return usable > 0 ? usable : Math.floor(ctx / 2)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Request budget — single source for window ∥ actually-sent max_tokens ∥ compaction threshold ∥
|
|
79
|
-
* overflow guard (CONTEXT-COMPACTION.md §6.17 / D-CC32). One formula, four consumer faces:
|
|
80
|
-
* threshold (resolveCompactThreshold / per-run setup), the four transport faces (read ONLY
|
|
81
|
-
* maxTokens), the stats budget line (agent-tools/context.mjs), the pre-send guard
|
|
82
|
-
* (agent/run-stages.mjs). transport derives from provider.format ("anthropic" | "google" |
|
|
83
|
-
* "responses" | default = OpenAI-compatible). Fields:
|
|
84
|
-
* - window / windowSource: spec.context (the §6.15 chain — modelContext / legacy context /
|
|
85
|
-
* /models self-report / static table / default — already resolved by providerSpec);
|
|
86
|
-
* source = providerSpecResolution(provider).source — closed set { modelContext |
|
|
87
|
-
* provider-override | list | spec | default }, passed through verbatim (no class merging).
|
|
88
|
-
* - maxTokens / maxTokensSource: the value THIS transport writes into the request body —
|
|
89
|
-
* anthropic always sends it (explicit ?? spec.maxOutput); the other three faces send only an
|
|
90
|
-
* explicit provider.maxTokens, absent ⇒ undefined / "absent". Never a guard criterion
|
|
91
|
-
* (undefined ⇒ NaN — §6.17 guard); the guard reads limit instead.
|
|
92
|
-
* - reserve: maxTokens ?? spec.maxOutput — uncapped, always a number.
|
|
93
|
-
* - usable: usableWindow(window, reserve) (degenerate half-window guard).
|
|
94
|
-
* - threshold: min(usable, ⌊window × COMPACT_RATIO⌋) — the compaction trigger line.
|
|
95
|
-
* - limit: window − reserve — hard prompt ceiling; the guard's ONLY numeric criterion field
|
|
96
|
-
* (always a number; negative = any prompt overflows). `absent` rows (the transport sends no
|
|
97
|
-
* max_tokens) take the floor max(window − reserve, threshold): only the degenerate
|
|
98
|
-
* reserve ≥ window rows move (bare value 0 ⇒ every prompt would be rejected), and for
|
|
99
|
-
* reserve < window threshold ≤ usable = window − reserve makes the floor a no-op. */
|
|
100
|
-
export function requestBudget(provider, spec) {
|
|
101
|
-
// windowSource = 五级链的同一次遍历出口(§6.15)——L1 / L3 命中也会如实报来源,不再二值猜。
|
|
102
|
-
// 调用方传 spec(core.mjs 已算过 providerSpec)时窗口值用它,来源仍读 resolution(恒等映射,不并类)。
|
|
103
|
-
const resolution = providerSpecResolution(provider)
|
|
104
|
-
const resolved = spec ?? resolution.spec
|
|
105
|
-
const window = resolved?.context ?? 0
|
|
106
|
-
const windowSource = resolution.source
|
|
107
|
-
const explicitRaw = Number(provider?.maxTokens)
|
|
108
|
-
const explicit = Number.isFinite(explicitRaw) && explicitRaw > 0 ? explicitRaw : undefined
|
|
109
|
-
const anthropicAlwaysSends = provider?.format === "anthropic"
|
|
110
|
-
const maxTokens = explicit ?? (anthropicAlwaysSends ? resolved?.maxOutput ?? 0 : undefined)
|
|
111
|
-
const maxTokensSource = explicit != null ? "explicit" : anthropicAlwaysSends ? "spec" : "absent"
|
|
112
|
-
const reserve = maxTokens ?? resolved?.maxOutput ?? 0
|
|
113
|
-
const usable = usableWindow(window, reserve)
|
|
114
|
-
const threshold = Math.min(usable, Math.floor(window * COMPACT_RATIO))
|
|
115
|
-
const bare = window - reserve
|
|
116
|
-
return {
|
|
117
|
-
window, windowSource, maxTokens, maxTokensSource, reserve, usable, threshold,
|
|
118
|
-
// §6.17 地板:absent 档 reserve 可能 ≥ window(退化行,bare ≤ 0)——裸式下任何 prompt 都判真、
|
|
119
|
-
// 该档永久发不出去;地板把它抬到 ≤ ⌊w/2⌋。非 absent 档逐位不变(仍是 bare)。
|
|
120
|
-
limit: maxTokensSource === "absent" ? Math.max(bare, threshold) : bare,
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** Derive compaction threshold; explicit is the value explicitly set in config file (takes priority),
|
|
125
|
-
* otherwise auto = requestBudget().threshold (§6.17 single source — min(usable, ⌊window × 0.6⌋),
|
|
126
|
-
* reserve uncapped). Second param accepts EITHER a model name string (pure spec lookup — compat shape,
|
|
127
|
-
* no caller passes a string today) OR a provider object (providerSpec — the providers[].context
|
|
128
|
-
* override in K units is honored, PROVIDER.md §15 T-C2). */
|
|
129
|
-
export function resolveCompactThreshold(explicit, modelOrProvider) {
|
|
130
|
-
if (explicit != null) return { value: explicit, auto: false }
|
|
131
|
-
const provider = typeof modelOrProvider === "string" ? { model: modelOrProvider } : (modelOrProvider ?? {})
|
|
132
|
-
return { value: requestBudget(provider).threshold, auto: true }
|
|
133
|
-
}
|
|
47
|
+
// 预算族(`outputReserve` ∥ `usableWindow` ∥ `requestBudget` ∥ `policyBudget` ∥ `effectiveWindow` ∥
|
|
48
|
+
// `resolveCompactThreshold` ∥ `INJECT_HEADROOM_TOKENS` ∥ `RETAIN_CAP_TOKENS`)居 `window-policy.mjs`——`CONTEXT-COMPACTION.md` §2.1 ∥
|
|
49
|
+
// §2.2 把「窗口事实」与「窗口策略」两件事分开,本档越 500 行硬限按设计给的候选线抽出;以下 re-export
|
|
50
|
+
// 保既有导入面(同 `model-specs.mjs` 拆分形态)。`resolveCompactThreshold` 在本档装载期自用
|
|
51
|
+
// (auto 档派生 `compactThresholdResolved`——按本会话档位现算,tiny 档随之落在有效窗口上),故先 import 再转口。
|
|
52
|
+
import { resolveCompactThreshold } from "./window-policy.mjs"
|
|
53
|
+
export {
|
|
54
|
+
TINY_WINDOW_CAP, INJECT_HEADROOM_TOKENS, RETAIN_CAP_TOKENS, effectiveWindow, outputReserve, usableWindow, requestBudget, policyBudget, resolveCompactThreshold,
|
|
55
|
+
} from "./window-policy.mjs"
|
|
134
56
|
|
|
135
57
|
/**
|
|
136
58
|
* Bailian (阿里云百炼) host check — enable_thinking is a Bailian-only extension parameter;
|
|
@@ -142,7 +64,7 @@ export function isBailianHost(baseURL) {
|
|
|
142
64
|
}
|
|
143
65
|
|
|
144
66
|
/**
|
|
145
|
-
* Resolve the Bailian `enable_thinking` switch for qwen hybrid-thinking models (PROVIDER.md §12).
|
|
67
|
+
* Resolve the Bailian `enable_thinking` switch for qwen hybrid-thinking models (`docs/core/design/PROVIDER.md` §6.12).
|
|
146
68
|
* qwen3.x on Bailian defaults to thinking ON, so an explicit off must send enable_thinking:false
|
|
147
69
|
* or the server silently keeps thinking. Whitelist: model name starts with "qwen" (excluding the
|
|
148
70
|
* non-thinking qwen3-coder line) AND the provider points at a Bailian host.
|
|
@@ -160,7 +82,7 @@ export function resolveEnableThinking(provider, spec) {
|
|
|
160
82
|
if (!isBailianHost(provider?.baseURL)) return undefined
|
|
161
83
|
// 一致性分支(#1659):effort 档位有值且非 "none" ⇒ effort 赢(thinking on)。
|
|
162
84
|
// 百炼约束:enable_thinking:false 时 reasoning_effort 必须为 "none",互斥即 400。
|
|
163
|
-
// 压缩下行(context.mjs
|
|
85
|
+
// 压缩下行(context.mjs 的 compressIfNeeded)显式 thinking:null 但继承 effort(v3 同源裁定)——
|
|
164
86
|
// 无此分支则发出 {enable_thinking:false, reasoning_effort:"medium"} ⇒ 400 ⇒ 压缩三连败。
|
|
165
87
|
if (provider.reasoningEffort && provider.reasoningEffort !== "none") return true
|
|
166
88
|
if (provider.thinking === null) return false
|
|
@@ -169,11 +91,12 @@ export function resolveEnableThinking(provider, spec) {
|
|
|
169
91
|
}
|
|
170
92
|
|
|
171
93
|
// 加载期归一 / 清洗纯函数族已迁 `config-normalize.mjs`(§6.16.9 —— C1)——四个公共函数经本档
|
|
172
|
-
// re-export
|
|
173
|
-
//
|
|
94
|
+
// re-export 保持既有导入面;其余六个(sanitizeProviderHeaders ∥ sanitizeConsultModels ∥
|
|
95
|
+
// isUsableProviderEntry ∥ providerDropReason ∥ 两枚一次性警告旗)只由 loadConfig 消费
|
|
96
|
+
// (`reloadProviders` 经 loadConfig 共用同一次判定,本档只转交,不另调)。
|
|
174
97
|
import {
|
|
175
98
|
sanitizeConsultModels, warnConsultModelsFiltered, sanitizeSubagentModel, sanitizeSubagentModels,
|
|
176
|
-
warnSubagentModelsFiltered, sanitizeProviderHeaders, normalizeProxy, normalizeTeamSection,
|
|
99
|
+
warnSubagentModelsFiltered, sanitizeProviderHeaders, normalizeProxy, normalizeTeamSection, isUsableProviderEntry, providerDropReason,
|
|
177
100
|
} from "./config-normalize.mjs"
|
|
178
101
|
export { sanitizeSubagentModel, sanitizeSubagentModels, normalizeProxy, normalizeTeamSection }
|
|
179
102
|
|
|
@@ -209,6 +132,17 @@ export function promoteAgentViews(config) {
|
|
|
209
132
|
return config
|
|
210
133
|
}
|
|
211
134
|
|
|
135
|
+
/**
|
|
136
|
+
* 丢弃记录一句一条(`docs/core/design/PROVIDER.md` §6.29「丢弃要看得见」):`providers[18]: null`。
|
|
137
|
+
* 只有盘上下标 + 原因闭集四值之一——**绝不带条目内容**:载体是数据层,会进日志 ∥ 报错 ∥ 调试输出,
|
|
138
|
+
* 一条「有 apiKey 却缺 name」的条目若取 JSON,`sk-…` 就原样写进不需要它的地方。原因由
|
|
139
|
+
* `providerDropReason`(`thincoder-core/config-normalize.mjs`)给出——与准入判据同源,同一条目不会
|
|
140
|
+
* 在这里和装载分支各判出一种说法;下标让用户能找到要改的那一条。
|
|
141
|
+
*/
|
|
142
|
+
function providerDropLine(index, reason) {
|
|
143
|
+
return `providers[${index}]: ${reason}`
|
|
144
|
+
}
|
|
145
|
+
|
|
212
146
|
/**
|
|
213
147
|
* Load configuration.
|
|
214
148
|
* No env-var overrides — config.json is the single source of truth
|
|
@@ -237,13 +171,28 @@ export function loadConfig() {
|
|
|
237
171
|
}
|
|
238
172
|
}
|
|
239
173
|
|
|
174
|
+
// 渠道条目准入过滤(`docs/core/design/PROVIDER.md` §6.29):无名条目不进使用面——`name` 是渠道
|
|
175
|
+
// 唯一句柄(findProvider ∥ parseModelRef ∥ 会话槽 ∥ 选择器全按 name 匹配),无名条目既不可寻址
|
|
176
|
+
// 也不可被发送,留着只会让读它的地方失真:`/model` 的 `${p.name.padEnd(12)}` 直接抛
|
|
177
|
+
// `Cannot read properties of undefined (reading 'padEnd')`,19 个正常渠道被 1 条空条目连累。
|
|
178
|
+
// 过滤在整表别名 `merged.providersList = merged.providers` **之前**:别名之后没有第二个汇聚点,
|
|
179
|
+
// 漏一处就留一条不可寻址的条目在运行面。判据单源 = `isUsableProviderEntry`(装载 ∥ 重读共用)。
|
|
180
|
+
// 盘面处置 = 不重写被丢弃的那条(同节「零写盘」:它可能携用户已填的 apiKey ∥ baseURL)。
|
|
181
|
+
// 丢弃记录只写盘上下标 + 原因闭集(条目内容不进载体——载体是数据层,会进日志与调试输出)。
|
|
182
|
+
const droppedProviders = []
|
|
183
|
+
const providers = Array.isArray(config.providers)
|
|
184
|
+
? config.providers.flatMap((p, index) => {
|
|
185
|
+
if (isUsableProviderEntry(p)) return [sanitizeProviderHeaders({ ...p })]
|
|
186
|
+
droppedProviders.push(providerDropLine(index, providerDropReason(p)))
|
|
187
|
+
return []
|
|
188
|
+
})
|
|
189
|
+
: []
|
|
190
|
+
|
|
240
191
|
const merged = {
|
|
241
192
|
...DEFAULTS,
|
|
242
193
|
...config,
|
|
243
194
|
defaultModel: typeof config.defaultModel === "string" && config.defaultModel.trim() ? config.defaultModel : null,
|
|
244
|
-
providers
|
|
245
|
-
? config.providers.map((p) => sanitizeProviderHeaders({ ...p }))
|
|
246
|
-
: [],
|
|
195
|
+
providers,
|
|
247
196
|
agent: { ...DEFAULTS.agent, ...config.agent },
|
|
248
197
|
memory: { ...DEFAULTS.memory, ...config.memory },
|
|
249
198
|
embedding: { ...DEFAULTS.embedding, ...config.embedding },
|
|
@@ -252,6 +201,17 @@ export function loadConfig() {
|
|
|
252
201
|
diagnostics: { ...DEFAULTS.diagnostics },
|
|
253
202
|
}
|
|
254
203
|
|
|
204
|
+
// Work mode is normalized from the raw input: a valid mode wins; legacy engineering is read
|
|
205
|
+
// only when mode is absent. The old boolean remains a derived runtime view, never a second authority.
|
|
206
|
+
merged.agent.mode = resolveWorkMode(config.agent)
|
|
207
|
+
merged.agent.engineering = merged.agent.mode === "engineering"
|
|
208
|
+
|
|
209
|
+
// 丢弃要看得见(同节「丢弃要看得见 · 数据面载体」):载体只在有丢弃时有值(无丢弃 ⇒ undefined,
|
|
210
|
+
// 与 `[]` 同义)。一条一句挂数据层;出词归消费面——本批唯一消费方 = `/model` L1 列表首行
|
|
211
|
+
// (`thincoder-cli/src/tui/provider-entries.mjs`),故不走 console。无条件写一次:载体是派生值,
|
|
212
|
+
// 而 `merged` 先摊平了盘上原文(`...config`),条件赋值会把盘上手写的同名键原样放进数据层。
|
|
213
|
+
merged.providersDropped = droppedProviders.length ? droppedProviders : undefined
|
|
214
|
+
|
|
255
215
|
// 家目录展开(第 29 批):config 路径字段单一规范化点——只读归一(磁盘原文保留)
|
|
256
216
|
merged.memory.dbPath = expandHome(merged.memory.dbPath)
|
|
257
217
|
merged.memory.projectDir = expandHome(merged.memory.projectDir)
|
|
@@ -362,7 +322,7 @@ export function loadConfig() {
|
|
|
362
322
|
merged.agent.compactThresholdAuto = false
|
|
363
323
|
} else {
|
|
364
324
|
merged.agent.compactThreshold = undefined
|
|
365
|
-
merged.agent.compactThresholdResolved = resolveCompactThreshold(null, merged.provider).value
|
|
325
|
+
merged.agent.compactThresholdResolved = resolveCompactThreshold(null, merged.provider, merged.agent.mode).value
|
|
366
326
|
merged.agent.compactThresholdAuto = true
|
|
367
327
|
}
|
|
368
328
|
|
|
@@ -380,6 +340,10 @@ export function loadConfig() {
|
|
|
380
340
|
return merged
|
|
381
341
|
}
|
|
382
342
|
|
|
343
|
+
// 运行中重读盘上渠道表本体居 `config-reload.mjs`(`docs/core/design/PROVIDER.md` §6.30)——本档已过
|
|
344
|
+
// 500 行后按设计指的候选线抽出,以下 re-export 保持既有导入面(同 config-io.mjs 拆分形态)。
|
|
345
|
+
export { reloadProviders } from "./config-reload.mjs"
|
|
346
|
+
|
|
383
347
|
/**
|
|
384
348
|
* MCP.md §5 D-3 (2026-09-01): re-read config.json and replace ONLY the agent's mcp section
|
|
385
349
|
* — the agent 代配 closed loop (agent edits config.json with its edit tool, /mcp picks it
|
package/context-degrade.mjs
CHANGED
|
@@ -5,20 +5,34 @@
|
|
|
5
5
|
* 原档 `context.mjs` 经 `export { … } from` 转口保名(消费面 / 单元测试档 import 面零改);
|
|
6
6
|
* 跨档被引的原私有面(`shrinkOversized`)补 `export` 关键字。
|
|
7
7
|
*/
|
|
8
|
-
import { collectStaleToolOutputs } from "./token-window.mjs"
|
|
8
|
+
import { collectStaleToolOutputs, contextUsage, estimateTokens, rebaseMeasured, tokenRatioOf } from "./token-window.mjs"
|
|
9
|
+
// 保护尾跟着**有效窗口**走(`CONTEXT-COMPACTION.md` §2.1 / §4):档位自 agent 现取,不靠参数透传。
|
|
10
|
+
import { resolveWorkMode } from "./config.mjs"
|
|
11
|
+
// 保留窗起点(#2431):prune 的合格集与压缩同一个切点——保留窗内那几轮的工具输出不被选中(§1.2)。
|
|
12
|
+
import { retentionWindowStart } from "./agent/turn-projection.mjs"
|
|
9
13
|
|
|
10
14
|
/** prune stub 逐字(§6.16.3):只给「已清理 + 原长度 + 重跑路径」——prune 是**删**不是摘要,不声称可复原。 */
|
|
11
15
|
const pruneStub = (chars) => `[pruned: stale tool output dropped (${chars} chars) — re-run the tool if you need it again.]`
|
|
12
16
|
|
|
17
|
+
/** 本档两处编辑都量到「旧前缀里被改动的那一段」为止:`_usageAtLen` 之后的消息从没被量过,减它们就是减错账。 */
|
|
18
|
+
function measuredEndOf(agent, history) {
|
|
19
|
+
return Number.isInteger(agent?._usageAtLen) ? agent._usageAtLen : history.length
|
|
20
|
+
}
|
|
21
|
+
|
|
13
22
|
/**
|
|
14
23
|
* 陈旧工具输出清理(F-CC3 · §6.16.3):合格集 = `token-window.mjs` 单源(保护尾外 ∧ `role:"tool"` ∧ ≥ 门槛);
|
|
15
24
|
* 命中项**原位换「内容」**(`history[i] = { ...m, content: stub }`——数组引用 / 长度 / 索引 / `tool_call_id` 全不变
|
|
16
|
-
* ⇒ 配对**结构上不可能被拆**)。记录面零改(copy-on-write
|
|
25
|
+
* ⇒ 配对**结构上不可能被拆**)。记录面零改(copy-on-write:消息对象与人读线共享)。
|
|
26
|
+
* 基线按 §3.1 **重定,不归零**:原位替换 ⇒ `_usageAtLen` 原样,`_lastPromptTokens` 只扣那一截的估算差。
|
|
27
|
+
* `fixedOverhead` ∥ `ratio` 的来处 = §2.3 表(`contextUsage(agent).overhead` · `tokenRatioOf(agent)`)。
|
|
17
28
|
* @returns {{pruned:number, freed:number, candidates:number, tailKept:number, belowMin:number}}
|
|
18
29
|
*/
|
|
19
30
|
export function pruneStaleToolOutputs(agent) {
|
|
20
31
|
const history = agent.history
|
|
21
|
-
const stale = collectStaleToolOutputs(
|
|
32
|
+
const stale = collectStaleToolOutputs(
|
|
33
|
+
history, agent.provider, resolveWorkMode(agent.config?.agent), retentionWindowStart(agent),
|
|
34
|
+
contextUsage(agent).overhead, tokenRatioOf(agent),
|
|
35
|
+
)
|
|
22
36
|
const counts = {
|
|
23
37
|
pruned: stale.indexes.length,
|
|
24
38
|
freed: stale.tokens,
|
|
@@ -27,14 +41,21 @@ export function pruneStaleToolOutputs(agent) {
|
|
|
27
41
|
belowMin: stale.belowMin,
|
|
28
42
|
}
|
|
29
43
|
if (counts.pruned === 0) return counts
|
|
44
|
+
const measuredEnd = measuredEndOf(agent, history)
|
|
45
|
+
let estBefore = 0
|
|
46
|
+
let estAfter = 0
|
|
30
47
|
for (const i of stale.indexes) {
|
|
31
48
|
const m = history[i]
|
|
49
|
+
const before = i < measuredEnd ? estimateTokens([m]) : 0
|
|
32
50
|
// 多模态 tool 结果(content 数组)整体替换为 stub ⇒ 图像 part 丢弃(不可再取——prune 是删;回执只给重跑路径)
|
|
33
51
|
const chars = typeof m.content === "string" ? m.content.length : JSON.stringify(m.content ?? "").length
|
|
34
52
|
history[i] = { ...m, content: pruneStub(chars) }
|
|
53
|
+
if (i < measuredEnd) {
|
|
54
|
+
estBefore += before
|
|
55
|
+
estAfter += estimateTokens([history[i]])
|
|
56
|
+
}
|
|
35
57
|
}
|
|
36
|
-
agent
|
|
37
|
-
agent._usageAtLen = null
|
|
58
|
+
rebaseMeasured(agent, estBefore, estAfter, { inPlace: true })
|
|
38
59
|
return counts
|
|
39
60
|
}
|
|
40
61
|
|
|
@@ -51,31 +72,38 @@ const OVERSIZE_CONTENT_LIMIT = 8_000
|
|
|
51
72
|
*/
|
|
52
73
|
export function shrinkOversized(agent, limit = OVERSIZE_CONTENT_LIMIT) {
|
|
53
74
|
let shrunk = false
|
|
75
|
+
const measuredEnd = measuredEndOf(agent, agent.history)
|
|
76
|
+
let estBefore = 0
|
|
77
|
+
let estAfter = 0
|
|
54
78
|
// Copy-on-write: build a NEW array and replace only truncated entries. pushReal stores the SAME
|
|
55
79
|
// message object in both `agent.history` (machine line) and `agent._fullHistory` (human/persistence
|
|
56
80
|
// line), so in-place `m.content = ...` would ALSO truncate the never-compacted human line and lose
|
|
57
81
|
// the original pasted content on session persist (session.mjs persists _fullHistory). VS Code port
|
|
58
82
|
// already copies (`history.map(m => ({ ...m }))`); this brings CLI to parity.
|
|
59
|
-
const next = agent.history.map((m) => {
|
|
83
|
+
const next = agent.history.map((m, i) => {
|
|
60
84
|
if ((m.role !== "user" && m.role !== "tool") || typeof m.content !== "string") return m
|
|
61
85
|
if (m.content.length <= limit) return m
|
|
62
86
|
// Truncate keeping head + tail, insert stub in between; keepHead/keepTail proportional but not exceeding 50%/25% of limit
|
|
63
87
|
const keepHead = Math.min(Math.floor(limit * 0.5), 4000)
|
|
64
88
|
const keepTail = Math.min(Math.floor(limit * 0.25), 2000)
|
|
65
89
|
shrunk = true
|
|
66
|
-
|
|
90
|
+
const truncated = {
|
|
67
91
|
...m,
|
|
68
92
|
content:
|
|
69
93
|
m.content.slice(0, keepHead) +
|
|
70
94
|
`\n[... ${m.content.length - keepHead - keepTail} chars truncated — single message too large for context window ...]\n` +
|
|
71
95
|
m.content.slice(-keepTail),
|
|
72
96
|
}
|
|
97
|
+
if (i < measuredEnd) {
|
|
98
|
+
estBefore += estimateTokens([m])
|
|
99
|
+
estAfter += estimateTokens([truncated])
|
|
100
|
+
}
|
|
101
|
+
return truncated
|
|
73
102
|
})
|
|
74
103
|
if (shrunk) {
|
|
75
104
|
agent.history = next
|
|
76
|
-
//
|
|
77
|
-
agent
|
|
78
|
-
agent._usageAtLen = null
|
|
105
|
+
// 基线按 §3.1 **重定,不归零**:截断是原位替换(数组长度与下标不变)⇒ `_usageAtLen` 原样。
|
|
106
|
+
rebaseMeasured(agent, estBefore, estAfter, { inPlace: true })
|
|
79
107
|
}
|
|
80
108
|
return shrunk
|
|
81
109
|
}
|
package/context-echo.mjs
CHANGED
|
@@ -9,6 +9,17 @@
|
|
|
9
9
|
/** Placeholder assistant reply committed right after compaction (D9); D-CC18 merges it into an adjacent tail assistant instead of emitting it as a separate message */
|
|
10
10
|
export const COMPACTION_PLACEHOLDER = "Understood. I'll continue from these notes, re-verifying anything transient."
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* 压缩注记的前缀(`context.mjs` 的 `applyCompression` 拼在摘要正文之前)。
|
|
14
|
+
* 住在本档的理由:它是压缩产物那对固定文本之一,另一条就是上面的占位句;两条一起被
|
|
15
|
+
* `token-window.mjs` 的 `NOTE_ESTIMATE` 量一次(§4 的减法链要扣注记与占位),分住两档就得让
|
|
16
|
+
* `token-window.mjs` 反向 import `context.mjs`(成环)。
|
|
17
|
+
*/
|
|
18
|
+
export const COMPACTION_PREFIX =
|
|
19
|
+
"[Context was automatically compacted. Below is a summary of earlier work. " +
|
|
20
|
+
"Treat it as notes, not proof — trust its conclusions (don't redo what it reports as done) " +
|
|
21
|
+
"but re-verify transient state with tools. Check memory search for any missing decisions.]\n\n"
|
|
22
|
+
|
|
12
23
|
/**
|
|
13
24
|
* Content-shape-safe prefixing (D-CC18, generalized for D-CC19 merge reuse):
|
|
14
25
|
* string → text + blank line + original; multimodal array → text part prepended;
|