@thincoder/core 0.11.1 → 0.11.3
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 +64 -2
- package/advisor/compaction.mjs +7 -5
- package/advisor/convergence.mjs +34 -3
- package/advisor/history.mjs +24 -11
- package/advisor/loop.mjs +49 -12
- package/advisor/messages.mjs +114 -33
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +24 -10
- package/advisor.mjs +36 -46
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/chat-call.mjs +14 -9
- package/agent/completion.mjs +70 -41
- package/agent/continue-decision.mjs +14 -8
- package/agent/digest-account.mjs +133 -59
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +10 -4
- package/agent/family-tools.mjs +37 -23
- package/agent/helpers.mjs +139 -73
- package/agent/image-heal.mjs +18 -4
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +36 -35
- package/agent/record-results.mjs +39 -7
- package/agent/run-stages.mjs +132 -52
- package/agent/run-start.mjs +150 -78
- package/agent/setup-reminders.mjs +194 -91
- package/agent/setup.mjs +219 -140
- package/agent/spawn-child.mjs +40 -3
- package/agent/suspension.mjs +43 -15
- package/agent/timers.mjs +9 -4
- package/agent/turn-domain-text.mjs +105 -0
- package/agent/turn-loop.mjs +84 -27
- package/agent/turn-projection.mjs +286 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +163 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +35 -172
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +37 -48
- package/agent-tools/async-discard.mjs +7 -2
- package/agent-tools/async-settle.mjs +18 -12
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +5 -2
- package/agent-tools/batch-closeout.mjs +223 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +240 -20
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +197 -48
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-read.mjs +151 -4
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +23 -11
- package/agent-tools/batch-segment-vocab.mjs +459 -0
- package/agent-tools/batch-skeleton.mjs +196 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +214 -0
- package/agent-tools/batch.mjs +192 -439
- package/agent-tools/browser-async.mjs +5 -2
- package/agent-tools/consult.mjs +17 -11
- package/agent-tools/context.mjs +76 -33
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +1 -1
- package/agent-tools/design-token.mjs +279 -81
- package/agent-tools/digest-budget.mjs +10 -9
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +12 -12
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/goal.mjs +5 -2
- package/agent-tools/judge-domain.mjs +347 -0
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/parent-channel.mjs +6 -3
- package/agent-tools/plan.mjs +11 -10
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +19 -6
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/skill.mjs +7 -8
- package/agent-tools/spawn-gates.mjs +14 -24
- package/agent-tools/ssh-session.mjs +8 -5
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +1 -1
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-actions.mjs +2 -2
- package/agent-tools/subagent-async.mjs +19 -17
- 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 +13 -13
- package/agent-tools/subagent-spawn.mjs +92 -112
- package/agent-tools/subagent.mjs +16 -28
- package/agent-tools/task.mjs +0 -8
- 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 +26 -7
- package/attachments.mjs +3 -3
- package/auto-think.mjs +5 -2
- 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 +1 -1
- package/compaction-work-state.mjs +230 -0
- package/compress-form.mjs +41 -6
- package/config-defaults.mjs +7 -3
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +110 -110
- package/context-degrade.mjs +93 -34
- package/context-echo.mjs +6 -15
- package/context-push.mjs +328 -31
- package/context.mjs +298 -170
- package/conventions.mjs +11 -9
- package/declaration.mjs +126 -22
- 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 +309 -213
- package/doc-check/line-refs.mjs +27 -101
- package/doc-check/paragraph.mjs +218 -102
- 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/escape.mjs +6 -5
- package/explore-distill.mjs +41 -8
- package/generate-title.mjs +10 -1
- package/i18n.mjs +1 -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 +10 -0
- package/ledger-close-proof.mjs +100 -49
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +47 -91
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +47 -15
- package/ledger-executors.mjs +1 -1
- package/ledger-tools.mjs +121 -62
- package/ledger-write-ops.mjs +162 -46
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/docs.mjs +51 -15
- package/memory/file-list.mjs +6 -0
- package/memory/schema.mjs +2 -2
- package/model-specs.mjs +87 -21
- package/origin-guard.mjs +190 -0
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +114 -2
- package/prompt-overlays.mjs +21 -11
- package/prompts/advisor-design.md +96 -36
- package/prompts/advisor-round1.md +48 -4
- package/prompts/advisor-round2.md +54 -10
- package/prompts/advisor-round3.md +53 -9
- package/prompts/common.md +99 -434
- package/prompts/consult-base.md +7 -4
- package/prompts/discipline-engineering.md +504 -295
- package/prompts/discipline-normal.md +106 -281
- package/prompts/knowledge/business-gates.md +30 -0
- package/prompts/knowledge/decision-quality.md +21 -0
- package/prompts/knowledge/doc-lookup.md +30 -0
- package/prompts/knowledge/document-writing.md +33 -0
- package/prompts/knowledge/documentation-evaluation.md +48 -0
- package/prompts/knowledge/evidence-discipline.md +38 -0
- package/prompts/knowledge/normal-coding-workflow.md +110 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +124 -0
- package/prompts/knowledge/normal-work-management.md +60 -0
- package/prompts/knowledge/product-security.md +28 -0
- package/prompts/knowledge/project-records.md +73 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +17 -0
- package/prompts/knowledge/tool-bash.md +48 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +19 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +20 -0
- package/prompts/knowledge/tool-batch-review.md +18 -0
- package/prompts/knowledge/tool-batch.md +94 -0
- package/prompts/knowledge/tool-browser.md +68 -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 +21 -0
- package/prompts/knowledge/tool-doc-check.md +71 -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 +41 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +21 -0
- package/prompts/knowledge/tool-fetch.md +18 -0
- package/prompts/knowledge/tool-file-ops.md +21 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +21 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +17 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +21 -0
- package/prompts/knowledge/tool-hashline-edit.md +16 -0
- package/prompts/knowledge/tool-insert-after.md +17 -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 +28 -0
- package/prompts/knowledge/tool-ledger.md +46 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +15 -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 +34 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +19 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +102 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +5 -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 +35 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +22 -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 +17 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +74 -0
- package/prompts/knowledge/tool-subagent.md +57 -0
- package/prompts/knowledge/tool-task.md +14 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +15 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +16 -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 +12 -0
- package/prompts/knowledge/upstream-protocol.md +45 -0
- package/prompts/persona-coder.md +1 -3
- package/prompts/persona-eng-coder.md +24 -6
- package/prompts/persona-eng-designer.md +150 -171
- package/prompts/persona-engineering.md +531 -442
- package/prompts/persona-explore.md +1 -3
- package/prompts/persona-normal.md +17 -9
- package/prompts/persona-plan.md +5 -3
- package/prompts/persona-tester.md +0 -2
- package/prompts/subagent-base.md +2 -2
- package/provider/anthropic.mjs +10 -6
- package/provider/core.mjs +8 -5
- package/provider/errors.mjs +63 -4
- package/provider/google.mjs +29 -10
- package/provider/reasoning-echo.mjs +16 -0
- package/provider/responses.mjs +7 -3
- package/provider/sse.mjs +11 -6
- package/provider-flows.mjs +2 -2
- package/rules.mjs +11 -10
- 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 +131 -42
- package/session-slot-write.mjs +38 -6
- package/session.mjs +30 -11
- package/shell-identity.mjs +129 -22
- package/skip-dirs.mjs +26 -2
- package/team-ledger.mjs +34 -30
- package/text-budget.mjs +1 -1
- package/think-off.mjs +27 -0
- package/token-ttl.mjs +74 -5
- package/token-window.mjs +371 -47
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -43
- 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 +2 -84
- package/tool-docs/browser.md +2 -49
- package/tool-docs/code_search.md +2 -2
- package/tool-docs/consult_start.md +2 -8
- package/tool-docs/consult_stop.md +2 -4
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -17
- package/tool-docs/doc_check.md +2 -107
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +2 -4
- package/tool-docs/edit.md +1 -38
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -18
- package/tool-docs/fetch.md +2 -14
- package/tool-docs/file_ops.md +2 -18
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -35
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +1 -6
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -15
- package/tool-docs/insert_after.md +2 -16
- 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 -10
- 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 -8
- package/tool-docs/manifest.md +2 -35
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +2 -20
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +1 -5
- 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 -18
- package/tool-docs/read_image.md +2 -9
- package/tool-docs/recent_changes.md +2 -2
- package/tool-docs/repo_outline.md +2 -2
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +1 -12
- package/tool-docs/skill.md +2 -6
- package/tool-docs/ssh.md +1 -62
- package/tool-docs/subagent.md +2 -100
- package/tool-docs/task.md +1 -7
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +2 -19
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +2 -12
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -19
- package/tool-docs/write.md +2 -12
- package/tools/browser.mjs +54 -9
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +170 -92
- package/tools/edit-diff.mjs +78 -62
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +3 -3
- package/tools/file.mjs +28 -14
- package/tools/git.mjs +36 -21
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +5 -3
- package/tools/patch.mjs +124 -44
- package/tools/process-doc-mark.mjs +33 -4
- package/tools/repomap.mjs +25 -3
- package/tools/search.mjs +74 -26
- package/tools/shared.mjs +29 -27
- package/tools/ssh.mjs +5 -5
- package/tools/tree.mjs +32 -10
- package/tools/web-deepseek.mjs +1 -1
- package/tools/web.mjs +2 -2
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +243 -0
- package/doc-check/anchors.mjs +0 -235
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 打开即验 + 改名保留自愈)。
|
package/session-lifecycle.mjs
CHANGED
|
@@ -19,9 +19,12 @@
|
|
|
19
19
|
|
|
20
20
|
import { existsSync } from "node:fs"
|
|
21
21
|
// §6.17:auto 派生值只进显示面(compactThresholdResolved)——显式键 agent.compactThreshold 永不被改写
|
|
22
|
-
import { resolveCompactThreshold } from "./config.mjs"
|
|
22
|
+
import { resolveCompactThreshold, resolveSessionWorkMode, setConfigWorkMode } from "./config.mjs"
|
|
23
23
|
// 槽面判据单源(#841 KD-841-2:槽渠道 key 门 + 模型面序——PROVIDER.md §6.22)。
|
|
24
24
|
import { hasKey, resolveChannelModel, resolveProviderPlan } from "./model-ref.mjs"
|
|
25
|
+
// 旧线补来源(AGENT-LOOP.md §5.5.4 补行):槽 `activeProvider` 是非空字符串且与运行态不同时,给无标记的 assistant 消息补会话级来源。
|
|
26
|
+
import { fillOriginFromSlot } from "./origin-guard.mjs"
|
|
27
|
+
|
|
25
28
|
import {
|
|
26
29
|
slotPath, loadManifest, saveManifest, slotDigest, writeSessionFile, getSessionId,
|
|
27
30
|
writeEndMarker, sessionEnd, ownerPid, ownerPids,
|
|
@@ -35,7 +38,12 @@ import { loadSlotFile } from "./session.mjs"
|
|
|
35
38
|
// 全新槽首物化构造器单源(SLOT-END-PARAM 批 §6.20 判据句 4 写面:「`newSession` 并入」——
|
|
36
39
|
// 与 VSC `newSlot` / `loadSlotForWrite` 全新分支同一构造器;环 import 同上,函数体内运行时使用)。
|
|
37
40
|
import { newSlotData } from "./session-slot-write.mjs"
|
|
38
|
-
import { mergeAdjacentAssistantEchoes } from "./context.mjs"
|
|
41
|
+
import { mergeAdjacentAssistantEchoes, setInject } from "./context.mjs"
|
|
42
|
+
// 拍平投影(读数在拍平视图上算,位置在结构上取):机读线按轮嵌套后,外层条数是轮数。
|
|
43
|
+
import { flattenHistory, normalizeMachineLine, setSessionHead } from "./context-push.mjs"
|
|
44
|
+
// 机读线装回(SESSION.md §2):槽里的 `contextHistory` 就是那条线,逐条原样装回——不从 `turns` 重拼、
|
|
45
|
+
// 不从 `history` 补;本档只用归一面回填 `agent._turns`,并把压缩检查点播种回 agent。
|
|
46
|
+
import { normalizeCheckpoint, normalizeSlotTurns } from "./agent/turn-projection.mjs"
|
|
39
47
|
// 打开态读数公式(§6.24 判据句 2——与 CLI 状态行 / VSC 同一实现点的投影;零新公式,只组合)。
|
|
40
48
|
import { historyPercent, restoreTokenSample, sampleRatio } from "./token-window.mjs"
|
|
41
49
|
import { scheduleSessionGC } from "./session-gc.mjs"
|
|
@@ -75,6 +83,50 @@ function stripTruncatedToolArgs(m) {
|
|
|
75
83
|
return changed ? { ...m, tool_calls } : m
|
|
76
84
|
}
|
|
77
85
|
|
|
86
|
+
/**
|
|
87
|
+
* 压缩状态恢复播种(SESSION.md §2「恢复也把压缩状态播种回 agent」):机读线整条装回之后,压缩检查点仍随槽
|
|
88
|
+
* 回来——它决定下一回合压缩的起点与降级报告里的 `discardedTurns` 读数。
|
|
89
|
+
* - `agent._compactCheckpoint` = 槽里的 `compactCheckpoint`;键缺 ∥ 形态坏 ⇒ 不设(与「本会话还没压过」同义);
|
|
90
|
+
* - 保留窗起点与覆盖条数不播种:两者都按外层轮元素结构现读(`SESSION.md` §2),
|
|
91
|
+
* 线与字段一起装回就够——盘上只有消息的文本,没有身份;不重建任何运行期账。
|
|
92
|
+
* 播种的键缺失等同没有:不报错,也不回写槽。
|
|
93
|
+
* @param {object} agent
|
|
94
|
+
* @param {object} data — 槽数据
|
|
95
|
+
*/
|
|
96
|
+
function seedCompressionState(agent, data) {
|
|
97
|
+
// 轮记录只解析一次:`agent._turns` 已在 `applySession` 里归一过,夹取与读同一个数组。
|
|
98
|
+
const turns = Array.isArray(agent?._turns) ? agent._turns : normalizeSlotTurns(data?.turns)
|
|
99
|
+
// 压缩摘要跟压缩成果一起回来(§1「压缩摘要的位置」:写 `_compactCheckpoint.compactionSummary` 的同时
|
|
100
|
+
// 写进 `_inject` 的 `compaction-summary` 格)。只播检查点而不播种压缩摘要,重开后的首条请求就少了那条
|
|
101
|
+
// 「前面已被摘要」的框定:压缩成果能活过重启(槽里装的是线)而它在请求里的位置丢了。
|
|
102
|
+
// 落 A 段 `compaction-summary` 格,装配时排在对话之前(唯一一格提前),不落槽、不进机读线。
|
|
103
|
+
agent._compactCheckpoint = normalizeCheckpoint(data?.compactCheckpoint, turns.length)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 槽里的机读线两形态归一(设计档 §1.1「槽与迁移」):
|
|
108
|
+
* - 已是嵌套轮(某个元素带 `messages` 数组)⇒ 逐元素归一,白名单只有 `messages`——**按原样装回,不筛不丢**;
|
|
109
|
+
* - 扁平消息数组(本批之前的槽)⇒ 按消息上的 `turn` 分组重建轮元素,随后删掉该字段;
|
|
110
|
+
* 没有 `turn` 的那批旧注入跟前面那一轮同轮、原样留下(不筛、不丢弃、不重建)。
|
|
111
|
+
* 空 ∥ 非数组 ⇒ 空数组(「槽里没有机读线」与「空机读线」在调用方同形)。
|
|
112
|
+
*/
|
|
113
|
+
function normalizeContextHistory(raw) {
|
|
114
|
+
// 单源 = `context-push.mjs` 的 `normalizeMachineLine`(端侧 `thincoder-vscode/src/agent/setup.mjs` 同一实现)。
|
|
115
|
+
return normalizeMachineLine(raw)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 待发队(B 段)随槽回填:新键 `pendingInject`;旧键 `pendingReminders` 认一次——旧槽里那是纯字符串条目,
|
|
120
|
+
* 这里升级为消息 `{ role: "user", content }`(条目形只有一个:待发队里装的都是消息)。
|
|
121
|
+
* 非对象、非法形状的元素丢弃(队列是发送面的载体,坏条目送上去就是一个 provider 400)。
|
|
122
|
+
*/
|
|
123
|
+
function normalizePendingInject(raw) {
|
|
124
|
+
const list = Array.isArray(raw) ? raw : []
|
|
125
|
+
return list
|
|
126
|
+
.map((m) => (typeof m === "string" ? { role: "user", content: m } : m))
|
|
127
|
+
.filter((m) => m && typeof m === "object" && !Array.isArray(m))
|
|
128
|
+
}
|
|
129
|
+
|
|
78
130
|
/** Apply loaded session data onto an agent object; returns `{ switched, droppedDesignTokens }`
|
|
79
131
|
* (`switched` = 运行态渠道是否被切——原布尔值;`droppedDesignTokens` = 离开本会话的未过期
|
|
80
132
|
* 设计凭证数,设计档 §3.2)。2026-08-31 会诊 F1:清空 _slot/_slotMtime 缓存——切换后下次保存重新认领。
|
|
@@ -90,49 +142,60 @@ function stripTruncatedToolArgs(m) {
|
|
|
90
142
|
* 删旧支:"activeModel==null 清 stale override 回渠道默认"——前提 = 渠道默认字段——已随
|
|
91
143
|
* 三旧层删除消失——双字段恒非空故不可能触发(评审 #7)。 */
|
|
92
144
|
export function applySession(agent, data, opts = {}) {
|
|
93
|
-
// 机读线语义(历史注释保留):data.history = FULL 未压缩记录(人读线);data.contextHistory =
|
|
94
|
-
//
|
|
95
|
-
//
|
|
145
|
+
// 机读线语义(历史注释保留):data.history = FULL 未压缩记录(人读线);data.contextHistory = 机读线本身
|
|
146
|
+
// ——装回的只有它(保留压缩收益——从完整 history 重建会塞回中间过程——实测 prompt 膨胀 283%)。
|
|
147
|
+
// v1 老文件(无 contextHistory ∥ 空数组)回退播种,剥离被 slimForDisplay 截断的
|
|
96
148
|
// tool_calls.arguments(… 结尾 → 置 {}——截断可劈断 \\uXXXX 产生 400 毒载荷)。length > 0 才
|
|
97
149
|
// 当机读线(contextHistory: [] 是"无机读线"而非空机器线——空机器线静默丢全部上下文)。
|
|
98
150
|
agent.config ??= {} // ACP test mocks may omit config; be defensive like the ??= below
|
|
99
151
|
const full = Array.isArray(data.history) ? data.history : []
|
|
100
|
-
// SESSION.md §6.11(2026-09-08——F2/F3
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
// 一次性闸(src/agent/setup-reminders.mjs——process restarted 句的进程级信号)。
|
|
110
|
-
agent._envResumed = full.length > 0
|
|
111
|
-
const ch = data.contextHistory
|
|
112
|
-
const machine = (Array.isArray(ch) && ch.length > 0) ? ch : full.map(stripTruncatedToolArgs)
|
|
152
|
+
// SESSION.md §6.11(2026-09-08——F2/F3):`_processRestartPending` 不在这里清——由启动路径
|
|
153
|
+
// (bin/thincoder.mjs)设、`prepareRun` 发句清(N6——信号独立:切槽不报进程重启)。
|
|
154
|
+
// 机读线两形态归一(设计档 §1.1「槽与迁移」):已是嵌套轮 ⇒ 逐元素归一(白名单 `messages`,按原样装回、
|
|
155
|
+
// 不筛不丢);扁平旧槽 ⇒ 按消息上的 `turn` 重组轮,随后删字段(无 `turn` 的旧注入跟前面那一轮同轮)。
|
|
156
|
+
const ch = normalizeContextHistory(data.contextHistory)
|
|
157
|
+
// 恢复权威顺序(SESSION.md §2 单点定义,两步):`contextHistory` 非空 ⇒ 机读线 = 它,逐条原样装回
|
|
158
|
+
// (不从 `turns` 重拼、不从 `history` 补);否则由 `history` 播种(包成一个轮元素,旧语义逐条不动)。
|
|
159
|
+
// `sessionReading` 走同一顺序(同档末)。
|
|
160
|
+
const fallbackLine = ch.length > 0 ? ch : [{ messages: full.map(stripTruncatedToolArgs) }]
|
|
113
161
|
// D-CC19 恢复面回声归并(CONTEXT-COMPACTION §6.10 #8):已落盘机读线原样装回会复活
|
|
114
162
|
// D-CC18 病态形态(无 reasoning_content 的 assistant 紧邻 assistant ⇒ 首请求 400)——
|
|
115
|
-
//
|
|
116
|
-
|
|
163
|
+
// 线定下后、装线前逐轮归并(调用与结果同轮,配对不跳轮界;干净输入返回同一引用——零拷贝零回归)。
|
|
164
|
+
// 空串 `reasoning_content` 是合法的「没有原文」编码(#2647):装回线原样保留,不清账。
|
|
165
|
+
const machineMerged = fallbackLine.map((turn) => ({ messages: mergeAdjacentAssistantEchoes(turn.messages) }))
|
|
117
166
|
// 绑定态(opts.slot 在场):人读线 = 记录存储尾窗(下方绑定块填充)——不复制全量 JSON 数组
|
|
118
167
|
agent._fullHistory = opts.slot != null ? [] : [...full]
|
|
119
|
-
agent.history =
|
|
168
|
+
agent.history = machineMerged
|
|
169
|
+
// 轮记录随槽回填(SESSION §2):跨轮清理按「第 k 个轮元素」与这份数组的下标对应,重启前后同一套判据;
|
|
170
|
+
// 归零活动轮的两件临时载体——上一进程的中止 ∥ 未完成轮不得跟过来。旧槽无 `turns` ⇒ 空数组,
|
|
171
|
+
// 机读线仍按上面的回退线走(旧槽零回归)。
|
|
172
|
+
agent._turns = normalizeSlotTurns(data.turns)
|
|
173
|
+
// 压缩状态随槽播种(`compactCheckpoint` 播回;保留窗起点与覆盖条数不播种——按外层结构现读)。
|
|
174
|
+
seedCompressionState(agent, data)
|
|
175
|
+
agent._turnLedger = null
|
|
120
176
|
agent.title = data.title ?? ""
|
|
121
177
|
agent.tasks = data.tasks ?? []
|
|
122
178
|
agent.planMode = data.planMode ?? false
|
|
123
179
|
agent.autoApprove = data.autoApprove ?? false
|
|
124
180
|
agent.goal = data.goal ?? null
|
|
125
|
-
agent.
|
|
181
|
+
agent._pendingInject = normalizePendingInject(data.pendingInject ?? data.pendingReminders)
|
|
182
|
+
// 注入三段里**不随槽走**的两段:B 段整段来自槽(上面一行),A 段格位与 C 段累积是「当前状态」,
|
|
183
|
+
// 由本会话的写入方按格写——切槽(`/session N` ∥ ACP 换槽)时上一个会话的压缩摘要 ∥ 任务表 ∥
|
|
184
|
+
// 工作状态块 ∥ 技能块 ∥ 会话头块不得跟着进新会话的请求。新会话(`resetSessionState`)同一处置。
|
|
185
|
+
agent._inject = []
|
|
186
|
+
agent._retained = []
|
|
187
|
+
setSessionHead(agent, "")
|
|
188
|
+
// 清场之后只播种**这个槽自己**的压缩摘要(不是上一个会话遗留的那份——上面已清):重开一个压过的会话,
|
|
189
|
+
// 首条请求仍带着「前面已被摘要」的框定,否则模型看到的是从中间开始的对话。
|
|
190
|
+
if (agent._compactCheckpoint?.compactionSummary) {
|
|
191
|
+
setInject(agent, "compaction-summary", agent._compactCheckpoint.compactionSummary)
|
|
192
|
+
}
|
|
126
193
|
agent._sessionStart = data.sessionStart ?? null
|
|
127
194
|
// R16 token 字段恢复(过期过滤——见 token-ttl.mjs restoreEngTokens);返回值 = 离开集计数(§3.2)
|
|
128
195
|
const restored = restoreEngTokens(agent, data)
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
if (data.engineering !== undefined) {
|
|
133
|
-
agent.config.agent ??= {}
|
|
134
|
-
agent.config.agent.engineering = data.engineering === true
|
|
135
|
-
}
|
|
196
|
+
// The slot's valid mode is authoritative. Legacy slots migrate their engineering boolean on
|
|
197
|
+
// read; slots with neither field keep the new-session default seeded from config.json.
|
|
198
|
+
setConfigWorkMode(agent.config, resolveSessionWorkMode(data, agent.config.agent))
|
|
136
199
|
// ENG-PLAN-EXCLUSION(FR31 ③ / KD10——恢复点①·CLI `applySession`):工程模式 ⇒ planMode 恒
|
|
137
200
|
// false(内存位 + 未注入的 plan 提示语)——防「工程纪律 × plan 只读」半状态随槽恢复复活。
|
|
138
201
|
// **槽不就地回写**:内存值在下一次 `saveSession` 随 `planMode` 字段自然收正(`session.mjs`)。
|
|
@@ -213,12 +276,25 @@ export function applySession(agent, data, opts = {}) {
|
|
|
213
276
|
// §6.17.1 链二读面:估算校准样本随槽恢复——上行刚把 `provider` 按槽值落定,key 同源校验才有意义
|
|
214
277
|
// (四条校验在 `restoreTokenSample`:形状 / est 版本 / key 同源 / 下界 1;不合格 ⇒ 未校准档)。
|
|
215
278
|
restoreTokenSample(agent, data.estimateSample, agent.provider)
|
|
279
|
+
// 旧线补来源(AGENT-LOOP.md §5.5.4 补行 · 槽渠道解析之后、机读线装回之后):槽 `activeProvider` 是非空字符串且与运行态
|
|
280
|
+
// `agent.provider.name` 不同时,给无标记的 assistant 消息补会话级来源;空串与缺键(无会话级证据)一律不补。补来源是尽力而为,
|
|
281
|
+
// 不承诺逐条正确;这只限制跨来源字段隔离,缺回声退轮不读来源,旧会话完整历史仍由 §5.5.5 承接。
|
|
282
|
+
agent.history = fillOriginFromSlot(agent.history, {
|
|
283
|
+
slotProvider: data.activeProvider ?? null,
|
|
284
|
+
runtimeProviderName: agent.provider?.name,
|
|
285
|
+
})
|
|
216
286
|
return { switched, droppedDesignTokens: restored.droppedDesignTokens }
|
|
217
287
|
}
|
|
218
288
|
// ② 槽无 key ∥ 不在册 → D-S3 保留——静默保持现状(落 config 链:config 统一解析产物已是
|
|
219
289
|
// `agent.provider`;不报错不纠正——两方都无效由调用侧复验 validateProvider 弹重选)
|
|
220
290
|
// §6.17.1 链二读面(B 支出口同 A 支):样本照旧随槽恢复(provider = config 链产物,key 同源校验照做)
|
|
221
291
|
restoreTokenSample(agent, data.estimateSample, agent.provider)
|
|
292
|
+
// 旧线补来源(B 支,判据同 A 支 · AGENT-LOOP.md §5.5.4 补行):槽渠道没被采用(无 key / 不在册)时,槽 `activeProvider` 仍可能是写下这段历史的那个 provider;
|
|
293
|
+
// 只有它是非空字符串且与运行态 `agent.provider.name` 不同时才补,空串与缺键一律不补。
|
|
294
|
+
agent.history = fillOriginFromSlot(agent.history, {
|
|
295
|
+
slotProvider: data.activeProvider ?? null,
|
|
296
|
+
runtimeProviderName: agent.provider?.name,
|
|
297
|
+
})
|
|
222
298
|
return { switched: false, droppedDesignTokens: restored.droppedDesignTokens }
|
|
223
299
|
}
|
|
224
300
|
|
|
@@ -270,7 +346,7 @@ export async function newSession(cwd, opts = {}) {
|
|
|
270
346
|
// VS Code newSlot 对齐(SESSION.md §6.3 v2 格式双端一致;两端读侧均有兜底,功能等价)。
|
|
271
347
|
// SLOT-END-PARAM 批(§6.20 判据句 4 写面):改用首物化构造器单源 `newSlotData(cwd)`
|
|
272
348
|
// (原字面逐字同形——并入后随其带创建端 = 本端名)。
|
|
273
|
-
const data = newSlotData(cwd)
|
|
349
|
+
const data = newSlotData(cwd, opts.mode)
|
|
274
350
|
writeSessionFile(slotPath(cwd, slot), data)
|
|
275
351
|
// 摘要 `ts` 地板入参(#503 同族随动——保存面写后取 mtime;`slotMtime` 读失败 ⇒ null ⇒ 裸墙钟)
|
|
276
352
|
m.slots[slot] = slotDigest(data, slotMtime(cwd, slot))
|
|
@@ -324,22 +400,30 @@ export function resetSessionState(agent) {
|
|
|
324
400
|
agent._compressFailures = 0
|
|
325
401
|
agent._verifyRetries = 0
|
|
326
402
|
agent._verifyPassed = undefined
|
|
327
|
-
|
|
403
|
+
// 轮记录面(SESSION §2):新会话无轮记录、无活动账本、无跨轮清理的坐标——旧会话的
|
|
404
|
+
// 轮记录不得跟新槽走(否则首回合的覆盖账会把上一会话的轮算进来);压缩状态同理:新会话没压过,
|
|
405
|
+
// 旧检查点跟过去会让首回合的机读线被当成「已被摘要覆盖」。
|
|
406
|
+
agent._turns = []
|
|
407
|
+
agent._compactCheckpoint = null
|
|
408
|
+
agent._turnLedger = null
|
|
328
409
|
agent._lastPromptTokens = null
|
|
329
|
-
agent.
|
|
410
|
+
agent._usageAt = null
|
|
411
|
+
agent._usageFixedBase = null
|
|
330
412
|
// §6.17 估算自校准:新会话无样本(比 = 1)——跨会话不继承旧模型的估算偏差
|
|
331
413
|
agent._tok = null
|
|
332
414
|
agent._tokRatio = 1
|
|
333
415
|
agent.planMode = false
|
|
334
416
|
agent.goal = null
|
|
335
|
-
agent.
|
|
417
|
+
agent._pendingInject = []
|
|
418
|
+
agent._inject = []
|
|
419
|
+
agent._retained = []
|
|
336
420
|
agent._slot = null
|
|
337
421
|
agent._slotMtime = null
|
|
338
422
|
agent._slotEffort = null // 新会话无档位(§6.21 判据句 5:全新槽规范形 = `effort: null`)
|
|
339
|
-
|
|
340
|
-
// §
|
|
341
|
-
|
|
342
|
-
|
|
423
|
+
// 会话头块随新会话清空(与 `_inject` ∥ `_retained` 同组:旧会话的环境文本不带进新会话;
|
|
424
|
+
// run 起点会重建一份)——写入口仍只有 `setSessionHead` 一个(设计 §1.1「写入面」),不就地写字段。
|
|
425
|
+
setSessionHead(agent, "")
|
|
426
|
+
// §6.11(2026-09-08):/new 或切槽清零启动句标志——它不跨会话复活
|
|
343
427
|
agent._processRestartPending = false
|
|
344
428
|
agent._lastEngState = false
|
|
345
429
|
// /new 或切换:记录存储解绑(新槽由 cmd-new / 首保存补绑重新挂载——§6.14 绑定与对账)
|
|
@@ -400,21 +484,26 @@ export function slotOccupancy(cwd, slot) {
|
|
|
400
484
|
|
|
401
485
|
/** 打开态读数(SESSION.md §6.24 · 桌面残余批——恢复态播种的读数**单源**):槽数据 ⇒ 状态行上下文
|
|
402
486
|
* 读数百分数(整数)。与 `applySession` 后读数**同源同式**(四事同判——组合既有件,零新公式):
|
|
403
|
-
* ① 线选 = `contextHistory`
|
|
487
|
+
* ① 线选 = `contextHistory` 非空取之(同 applySession 恢复权威顺序;两形态归一后逐条就是装回的那条线),
|
|
488
|
+
* 否则 `history` 经 `stripTruncatedToolArgs` 回退(同 applySession);
|
|
404
489
|
* ② 回声归并 = `mergeAdjacentAssistantEchoes`(同 applySession 装线前一步);
|
|
405
490
|
* ③ 渠道合并 = `providers` 命中 `data.activeProvider` ⇒ 槽模型(串值 `activeModel`;非串 ∕ 空串 = 未登记
|
|
406
491
|
* ⇒ 落链)∥ 无槽模型 ⇒ 现行模型链回落(`defaultModel` 属本渠道 ⇒ 其模型段;两档皆无 ⇒ `null`——
|
|
407
492
|
* `resolveChannelModel`,2026-10-09 清除批:渠道单值模型退场,零静默回落);未命中 ⇒ `fallback`
|
|
408
493
|
* (支 ②「静默保持现状」的装配口径 = `loadConfig().provider`);
|
|
409
|
-
* ④ 公式 = 核 `historyReading
|
|
494
|
+
* ④ 公式 = 核 `historyPercent`(= `historyReading` 的 `pct` 薄转口;与 CLI ∥ VSC 同一实现点的投影);
|
|
495
|
+
* 第三参 = 槽样本经 `sampleRatio` 取的校准比。档位不是入参(§2.1 ∥ §2.3):有效窗口恒等于模型窗口,
|
|
496
|
+
* 打开态分母因此只由渠道那一行决定,槽里的 `mode` 不参与读数。
|
|
410
497
|
* **零副作用**:`data` / `providers` / `fallback` / `defaultModel` 皆入参(不读盘、不写盘、不改任何进程态);
|
|
411
498
|
* `data` 非对象 ⇒ `0`(与空历史同值——「非正 ⇒ 零节点」显示门归端侧,沿 `historyPercent` 空历史口径)。 */
|
|
412
499
|
export function sessionReading(data, { providers, fallback, defaultModel } = {}) {
|
|
413
500
|
if (data === null || typeof data !== "object") return 0
|
|
414
501
|
const full = Array.isArray(data.history) ? data.history : []
|
|
415
|
-
const ch = data.contextHistory
|
|
416
|
-
const
|
|
417
|
-
|
|
502
|
+
const ch = normalizeContextHistory(data.contextHistory)
|
|
503
|
+
const fallbackLine = ch.length > 0 ? ch : [{ messages: full.map(stripTruncatedToolArgs) }]
|
|
504
|
+
// 与 `applySession` 同尺(SESSION §2 恢复权威顺序):打开态读的就是装回的那条线;
|
|
505
|
+
// 读数在拍平视图上算(外层条数是轮数,不是消息数);归并与空串清账同 `applySession` 一趟。
|
|
506
|
+
const line = flattenHistory(fallbackLine.map((turn) => ({ messages: mergeAdjacentAssistantEchoes(turn.messages) })))
|
|
418
507
|
const entry = data.activeProvider ? providers?.find((pr) => pr.name === data.activeProvider && hasKey(pr)) : null
|
|
419
508
|
// #638:非串 ∕ 空串 `activeModel` 归一(与 applySession 模型合并支 ① 同判)——脏值不达 `historyPercent`;
|
|
420
509
|
// 未登记 ⇒ 落现行模型链(`defaultModel` 属本渠段 ∥ `null`——渠道单值退场,2026-10-09 清除批)。
|
package/session-slot-write.mjs
CHANGED
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
* (settle 落盘 / 门禁回读 / 链终清理三面齐备);本档只承载其**保存面合并规则**
|
|
21
21
|
* (`mergeEngTokensForSave`——空态保留 + 并集 + 新铸者胜,纯函数)。批次归属旁列
|
|
22
22
|
* (`engDesignTokenBatches`)同款分层:槽 I/O 在 `token-ttl.mjs`,本档只持其保存面合并规则
|
|
23
|
-
* (`mergeEngTokenBatchesForSave
|
|
23
|
+
* (`mergeEngTokenBatchesForSave`)。评审封印旁列(`engDesignTokenSeals`,§10.2)同一分层,
|
|
24
|
+
* 合并规则 = `mergeEngTokenSealsForSave`。槽标题写面同样不在
|
|
24
25
|
* 本档——单源 = `session-rename.mjs` 的 `renameSlot`(同 `{ok, reason}` 契约 + mtime 门控)。
|
|
25
26
|
*/
|
|
26
27
|
|
|
@@ -36,6 +37,7 @@ import { tokenExpiryMs } from "./token-ttl.mjs"
|
|
|
36
37
|
// 与 off 可达性(`thinkOffPath`);两叶档(零 import)⇒ 不涉环,核内零第二份族别 / 枚举表。
|
|
37
38
|
import { specForModel } from "./model-specs.mjs"
|
|
38
39
|
import { thinkOffPath } from "./think-off.mjs"
|
|
40
|
+
import { WORK_MODES } from "./config-migrate.mjs"
|
|
39
41
|
|
|
40
42
|
/** mtime 缓存(键 = 槽文件路径 → 上次所见 mtimeMs):同一槽连写时跳过重复解析。
|
|
41
43
|
* 测试复位缝(与 `_setSessionsDirForTest` 同款):缓存为进程级单例,用例间需可复位
|
|
@@ -47,12 +49,14 @@ export function _resetSlotMtimeCacheForTest() { slotMtimeCache.clear() }
|
|
|
47
49
|
* 批起 `newSession` 与本构造器单源;`effort: null` = 会话级档位未设态——§6.21 判据句 5 规范
|
|
48
50
|
* 结构同源;老槽无该键由读侧按 `null` 容忍)。首物化即记创建端(§6.20 判据句 4 写面:本端
|
|
49
51
|
* 物化者 = 进程端名;「禁回填」不适用——本构造器只产全新槽)。 */
|
|
50
|
-
export function newSlotData(cwd) {
|
|
52
|
+
export function newSlotData(cwd, mode) {
|
|
53
|
+
if (mode !== undefined && !WORK_MODES.includes(mode)) throw new Error(`invalid session work mode: ${JSON.stringify(mode)}`)
|
|
51
54
|
return {
|
|
52
55
|
version: 2, cwd, title: "", updatedAt: Date.now(),
|
|
53
|
-
history: [], contextHistory: [], tasks: [],
|
|
56
|
+
history: [], contextHistory: [], tasks: [], turns: [],
|
|
57
|
+
...(mode !== undefined ? { mode } : {}),
|
|
54
58
|
planMode: false, goal: null, autoApprove: false, advisor: null, effort: null,
|
|
55
|
-
|
|
59
|
+
pendingInject: [], sessionStart: null,
|
|
56
60
|
createdBy: sessionEnd(),
|
|
57
61
|
}
|
|
58
62
|
}
|
|
@@ -160,9 +164,19 @@ export function setSlotPlanMode(cwd, slot, value) {
|
|
|
160
164
|
return writeFlag(cwd, slot, (d) => { d.planMode = value })
|
|
161
165
|
}
|
|
162
166
|
|
|
163
|
-
/**
|
|
167
|
+
/** 会话级互斥工作模式——槽是会话真值来源;旧 engineering 字段在写入时退役。 */
|
|
168
|
+
export function setSlotMode(cwd, slot, value) {
|
|
169
|
+
if (!["tiny", "normal", "engineering"].includes(value)) return false
|
|
170
|
+
return writeFlag(cwd, slot, (d) => {
|
|
171
|
+
d.mode = value
|
|
172
|
+
if (value === "engineering") d.planMode = false
|
|
173
|
+
delete d.engineering
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** 旧调用面保留,但写入同样只落到唯一 mode。 */
|
|
164
178
|
export function setSlotEngineering(cwd, slot, value) {
|
|
165
|
-
return
|
|
179
|
+
return setSlotMode(cwd, slot, value === true ? "engineering" : "normal")
|
|
166
180
|
}
|
|
167
181
|
|
|
168
182
|
/** advisor 守卫开关(`advisor: { guard }`——空值升格为对象)。 */
|
|
@@ -213,6 +227,24 @@ export function mergeEngTokenBatchesForSave(incoming, existing) {
|
|
|
213
227
|
return { ...existing, ...incoming }
|
|
214
228
|
}
|
|
215
229
|
|
|
230
|
+
/**
|
|
231
|
+
* 保存面「评审封印旁列」合并规则(DESIGN-TOKEN-SETTLEMENT §10.2——纯函数):与
|
|
232
|
+
* `mergeEngTokenBatchesForSave` **同形**(槽独有项保留;同 key 冲突以新写者胜——封印值是
|
|
233
|
+
* `{ hash, docs, docHashes }`,同一 designId 的新值来自更晚的一次评审,不比时刻、就是新写者)。
|
|
234
|
+
* - `incoming === undefined`(调用方未携带该字段)⇒ 保留槽值;
|
|
235
|
+
* - incoming 空值 ⇒ 槽有值则保留槽、槽也空 ⇒ null(写 null = 清字段);
|
|
236
|
+
* - 两端都有 ⇒ 并集:槽独有项保留、incoming 覆盖同 key。
|
|
237
|
+
* 理由同批归属:忙时保存把封印写丢 ⇒ 闸面落进「无封印值 ⇒ 不拦」,正是 §10.2 要消的窗口。
|
|
238
|
+
*/
|
|
239
|
+
export function mergeEngTokenSealsForSave(incoming, existing) {
|
|
240
|
+
if (incoming === undefined) return existing ?? null
|
|
241
|
+
const hasNew = incoming && typeof incoming === "object" && !Array.isArray(incoming) && Object.keys(incoming).length > 0
|
|
242
|
+
const slotHas = existing && typeof existing === "object" && !Array.isArray(existing) && Object.keys(existing).length > 0
|
|
243
|
+
if (!hasNew) return slotHas ? existing : null
|
|
244
|
+
if (!slotHas) return incoming
|
|
245
|
+
return { ...existing, ...incoming }
|
|
246
|
+
}
|
|
247
|
+
|
|
216
248
|
/** 会话级偏好(§6.21)键闭集——表外键 = 整 patch 拒(写未发生)。 */
|
|
217
249
|
const SLOT_PREF_KEYS = new Set(["provider", "model", "effort"])
|
|
218
250
|
|
package/session.mjs
CHANGED
|
@@ -29,6 +29,10 @@ import { guardForeignSlotFile } from "./session-guard.mjs"
|
|
|
29
29
|
import { engTokenSlotFields } from "./token-ttl.mjs"
|
|
30
30
|
// §6.17.1 链二写面(估算校准样本随会话槽走):本档只取写出值,读面在 `session-lifecycle.mjs`(applySession)。
|
|
31
31
|
import { tokenSampleOf } from "./token-window.mjs"
|
|
32
|
+
// 槽键归一(轮记录 ∥ 压缩检查点):机读线整条落槽之后,投影面只剩折叠一处(`SESSION.md` §2)。
|
|
33
|
+
import { normalizeCheckpoint, slotTurns } from "./agent/turn-projection.mjs"
|
|
34
|
+
// 机读线按轮嵌套:`legacyHistory` 的回退支(无 `_fullHistory`)读的是拍平视图——外层条数是轮数,不是消息数。
|
|
35
|
+
import { flattenHistory } from "./context-push.mjs"
|
|
32
36
|
// TUI-OOM-ROOTCAUSE 批(SESSION.md §6.14):人读线记录存储(磁盘为准 + 内存窗口)。
|
|
33
37
|
// slimForDisplay/isLegacyTransient 迁入 store 模块(§6.14 记录存储)——本文件 re-export 保持
|
|
34
38
|
// 既有 import 面(session-slots.mjs 引 isLegacyTransient)。依赖方向单向:store 零项目内依赖。
|
|
@@ -63,9 +67,12 @@ import { resumeSlot as lifecycleResumeSlot } from "./session-lifecycle.mjs"
|
|
|
63
67
|
// (legacy transient 判定 + slimForDisplay 自本区迁至 session-store.mjs——§6.14;
|
|
64
68
|
// 上方 re-export 保持既有 import 面。)
|
|
65
69
|
|
|
66
|
-
/** 未绑定路径的人读线全量物化(模式 F——既有语义逐字保留)。
|
|
70
|
+
/** 未绑定路径的人读线全量物化(模式 F——既有语义逐字保留)。
|
|
71
|
+
* 人读线在(`_fullHistory`)⇒ 原样;回退那一支的机读线已按轮嵌套 ⇒ 先拍平再逐条读
|
|
72
|
+
* (拿嵌套外层当消息数组数,数到的是轮数)。 */
|
|
67
73
|
function legacyHistory(agent) {
|
|
68
|
-
|
|
74
|
+
const line = Array.isArray(agent._fullHistory) ? agent._fullHistory : flattenHistory(agent.history)
|
|
75
|
+
return line
|
|
69
76
|
.filter((m) => !m.transient && !isLegacyTransient(m))
|
|
70
77
|
.map(slimForDisplay)
|
|
71
78
|
}
|
|
@@ -115,17 +122,25 @@ function digestFromStore(fields, counters, mtimeMs) {
|
|
|
115
122
|
export function saveSession(agent, opts = {}) {
|
|
116
123
|
// _fullHistory is written at the source via pushReal — no flush needed here.
|
|
117
124
|
// history = FULL, never-compacted (human-readable; VS Code panel & CLI resume read this)
|
|
118
|
-
// contextHistory = machine context (possibly compacted) so CLI resume keeps the token savings
|
|
119
125
|
// Human line: transient machine injections never enter the readable record.
|
|
120
126
|
// TUI-OOM-ROOTCAUSE 批(SESSION.md §6.14 追加时点):绑定记录存储后 `history` 字段由
|
|
121
127
|
// saveProjectedSlot 流式拼接段原文生成(磁盘为准——不物化全量数组);未绑定
|
|
122
128
|
// (模式 F:thincoder chat/测试/未覆盖路径)→ 既有全量物化路径逐字保留(D-SE26 模式 F 零回归)。
|
|
123
|
-
// Machine line (contextHistory)
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
// Machine line (contextHistory):机读线本身(SESSION.md §2)——保存当刻 `agent.history` 的嵌套形态,
|
|
130
|
+
// 逐元素归一(白名单只有 `messages`):外层每个元素是一轮,内层是该轮自己的消息。
|
|
131
|
+
// 注入不在线上(机读线上只有真实对话)⇒ 不再按 `transient` 滤一遍——有标记的就是旧槽带回来的注入,
|
|
132
|
+
// 按原样装回(设计档 §1.1「槽与迁移」)。恢复面逐条装回这条线,不按 `turns` 重投影。
|
|
133
|
+
const turns = Array.isArray(agent._turns) ? agent._turns : []
|
|
134
|
+
// 压缩检查点(SESSION §2 表行):内存载体 = `agent._compactCheckpoint`(`applyCompression` 产出);
|
|
135
|
+
// 归一不过(无压缩 ∥ 形态坏)⇒ `null` ⇒ **键缺**(不写 `null`、不写空对象)。
|
|
136
|
+
const compactCheckpoint = normalizeCheckpoint(agent._compactCheckpoint, turns.length)
|
|
137
|
+
// 在途 ∥ 异常段不再单列键:它就是机读线的尾段,随 `contextHistory` 一起落槽、一起装回(SESSION.md §2)。
|
|
138
|
+
const contextHistory = (Array.isArray(agent.history) ? agent.history : []).map((turn, i) => {
|
|
139
|
+
if (!turn || typeof turn !== "object" || !Array.isArray(turn.messages)) {
|
|
140
|
+
throw new TypeError(`agent.history element ${i} is not a turn ({ messages: [...] })`)
|
|
141
|
+
}
|
|
142
|
+
return { messages: turn.messages }
|
|
143
|
+
})
|
|
129
144
|
// fields = 槽 JSON 数据面(history 由投影插入——键序与既有 data 形态同序,history/contextHistory 居后)
|
|
130
145
|
const fields = {
|
|
131
146
|
version: 2,
|
|
@@ -139,15 +154,19 @@ export function saveSession(agent, opts = {}) {
|
|
|
139
154
|
tasks: agent.tasks ?? [],
|
|
140
155
|
planMode: agent.planMode ?? false,
|
|
141
156
|
autoApprove: agent.autoApprove ?? false,
|
|
142
|
-
|
|
157
|
+
mode: agent.config?.agent?.mode ?? (agent.config?.agent?.engineering === true ? "engineering" : "normal"),
|
|
143
158
|
...engTokenSlotFields(agent),
|
|
144
159
|
goal: agent.goal ?? null,
|
|
145
160
|
advisor: agent.config?.advisor ?? null,
|
|
146
|
-
|
|
161
|
+
pendingInject: agent._pendingInject ?? [],
|
|
147
162
|
sessionStart: agent._sessionStart ?? null,
|
|
148
163
|
// §6.17.1 链二写面:估算校准样本 `{key,num,den,est}`——空样本落 null(不造空对象);
|
|
149
164
|
// 只随回合尾保存走,不新增写路径、不逐样本落盘。
|
|
150
165
|
estimateSample: tokenSampleOf(agent),
|
|
166
|
+
// 轮记录(SESSION §2:每项形如 `{ userRequest, finalResponse, taskState }`)——人读回查、VSC 端恢复
|
|
167
|
+
// `_turns` 与折叠续记读它;不作机读线的恢复依据。
|
|
168
|
+
...(compactCheckpoint ? { compactCheckpoint } : {}),
|
|
169
|
+
turns: slotTurns(turns),
|
|
151
170
|
}
|
|
152
171
|
// 2026-09-05 §6.10 D-4:首认领(_slot 为 null——如 /session 切换后首保存、“查看对方活槽 →
|
|
153
172
|
// 保存 fork 新槽”的落盘槽跟随)写本端记录——marker = 端内最后认领者;粘性 _slot 期间
|