@thincoder/core 0.11.2 → 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 +18 -0
- package/advisor/compaction.mjs +7 -5
- package/advisor/history.mjs +24 -11
- package/advisor/loop.mjs +13 -8
- package/advisor/messages.mjs +72 -8
- package/advisor/run.mjs +24 -13
- package/advisor.mjs +7 -3
- package/agent/chat-call.mjs +14 -9
- package/agent/completion.mjs +28 -40
- package/agent/continue-decision.mjs +14 -8
- package/agent/digest-account.mjs +133 -59
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +2 -1
- package/agent/family-tools.mjs +12 -13
- package/agent/helpers.mjs +17 -72
- package/agent/image-heal.mjs +18 -4
- package/agent/post-turn.mjs +13 -26
- package/agent/record-results.mjs +21 -6
- package/agent/run-stages.mjs +72 -37
- package/agent/run-start.mjs +148 -113
- package/agent/setup-reminders.mjs +187 -91
- package/agent/setup.mjs +204 -138
- package/agent/spawn-child.mjs +2 -2
- package/agent/suspension.mjs +43 -15
- package/agent/timers.mjs +4 -1
- package/agent/turn-domain-text.mjs +105 -0
- package/agent/turn-loop.mjs +54 -22
- package/agent/turn-projection.mjs +127 -227
- package/agent/turn-tool-process.mjs +32 -37
- package/agent-tools/advisor-async.mjs +6 -3
- package/agent-tools/advisor-launch.mjs +5 -5
- package/agent-tools/advisor.mjs +1 -1
- package/agent-tools/async-discard.mjs +7 -2
- package/agent-tools/async-settle.mjs +18 -12
- package/agent-tools/bash-async.mjs +5 -2
- package/agent-tools/batch-closeout.mjs +12 -62
- package/agent-tools/batch-ledger-bind.mjs +19 -8
- package/agent-tools/batch-lifecycle.mjs +37 -11
- package/agent-tools/batch-read.mjs +151 -4
- package/agent-tools/batch-record-write.mjs +5 -5
- package/agent-tools/batch-segment-vocab.mjs +84 -4
- package/agent-tools/batch-skeleton.mjs +18 -14
- package/agent-tools/batch-supersede.mjs +1 -1
- package/agent-tools/batch-tier-gate.mjs +36 -119
- package/agent-tools/batch.mjs +30 -20
- package/agent-tools/browser-async.mjs +5 -2
- package/agent-tools/consult.mjs +10 -7
- package/agent-tools/context.mjs +47 -31
- package/agent-tools/digest-budget.mjs +10 -9
- package/agent-tools/eng.mjs +3 -4
- package/agent-tools/escalate-async.mjs +3 -3
- package/agent-tools/goal.mjs +5 -2
- package/agent-tools/judge-domain.mjs +347 -0
- package/agent-tools/manifest.mjs +2 -2
- package/agent-tools/parent-channel.mjs +6 -3
- package/agent-tools/plan.mjs +11 -10
- package/agent-tools/review-facts.mjs +9 -3
- package/agent-tools/skill.mjs +7 -8
- package/agent-tools/spawn-gates.mjs +5 -16
- package/agent-tools/ssh-session.mjs +6 -3
- package/agent-tools/ssh-transfer.mjs +1 -1
- package/agent-tools/subagent-actions.mjs +2 -2
- package/agent-tools/subagent-async.mjs +11 -8
- package/agent-tools/subagent-scheduler.mjs +9 -9
- package/agent-tools/subagent-spawn.mjs +2 -2
- package/agent-tools/subagent.mjs +5 -18
- package/agent-tools/task.mjs +0 -8
- package/agent.mjs +15 -15
- package/auto-think.mjs +5 -2
- package/compaction-work-state.mjs +230 -0
- package/compress-form.mjs +41 -6
- package/config-defaults.mjs +5 -2
- package/config.mjs +53 -17
- package/context-degrade.mjs +79 -48
- package/context-echo.mjs +6 -26
- package/context-push.mjs +328 -31
- package/context.mjs +203 -141
- package/conventions.mjs +1 -1
- package/declaration.mjs +95 -17
- package/escape.mjs +6 -5
- package/explore-distill.mjs +35 -8
- package/generate-title.mjs +10 -1
- package/knowledge/prompt-resources.md +5 -1
- package/ledger-tools.mjs +50 -50
- package/ledger-write-ops.mjs +43 -16
- package/memory/docs.mjs +51 -15
- package/memory/file-list.mjs +6 -0
- package/model-specs.mjs +87 -21
- package/origin-guard.mjs +190 -0
- package/package.json +1 -1
- package/prompt-files.mjs +33 -11
- package/prompt-overlays.mjs +12 -5
- package/prompts/advisor-design.md +55 -36
- package/prompts/advisor-round1.md +18 -7
- package/prompts/advisor-round2.md +18 -7
- package/prompts/advisor-round3.md +18 -7
- package/prompts/common.md +89 -51
- package/prompts/consult-base.md +2 -3
- package/prompts/discipline-engineering.md +474 -440
- package/prompts/discipline-normal.md +107 -31
- package/prompts/knowledge/business-gates.md +23 -15
- package/prompts/knowledge/decision-quality.md +16 -18
- package/prompts/knowledge/doc-lookup.md +22 -27
- package/prompts/knowledge/document-writing.md +31 -49
- package/prompts/knowledge/documentation-evaluation.md +37 -45
- package/prompts/knowledge/evidence-discipline.md +36 -55
- package/prompts/knowledge/normal-coding-workflow.md +27 -21
- package/prompts/knowledge/normal-delivery-collaboration.md +33 -17
- package/prompts/knowledge/normal-work-management.md +10 -7
- package/prompts/knowledge/product-security.md +22 -17
- package/prompts/knowledge/project-records.md +63 -52
- package/prompts/knowledge/tool-apply-patch.md +12 -13
- package/prompts/knowledge/tool-bash.md +13 -4
- package/prompts/knowledge/tool-batch-eng-coder.md +13 -6
- package/prompts/knowledge/tool-batch-eng-designer.md +14 -6
- package/prompts/knowledge/tool-batch-review.md +12 -6
- package/prompts/knowledge/tool-batch.md +76 -62
- package/prompts/knowledge/tool-browser.md +45 -34
- package/prompts/knowledge/tool-context.md +2 -2
- package/prompts/knowledge/tool-delete.md +5 -1
- package/prompts/knowledge/tool-doc-check.md +25 -24
- package/prompts/knowledge/tool-doc-graph-read.md +3 -3
- package/prompts/knowledge/tool-doc-graph.md +15 -15
- package/prompts/knowledge/tool-edit.md +26 -23
- package/prompts/knowledge/tool-execute.md +9 -4
- package/prompts/knowledge/tool-fetch.md +7 -1
- package/prompts/knowledge/tool-file-ops.md +6 -1
- package/prompts/knowledge/tool-git-read.md +3 -1
- package/prompts/knowledge/tool-git.md +1 -1
- package/prompts/knowledge/tool-glob.md +3 -1
- package/prompts/knowledge/tool-grep.md +5 -2
- package/prompts/knowledge/tool-hashline-edit.md +4 -2
- package/prompts/knowledge/tool-insert-after.md +3 -1
- package/prompts/knowledge/tool-ledger-read.md +6 -13
- package/prompts/knowledge/tool-ledger.md +14 -10
- package/prompts/knowledge/tool-ls.md +2 -0
- package/prompts/knowledge/tool-manifest.md +10 -7
- package/prompts/knowledge/tool-memory.md +15 -11
- package/prompts/knowledge/tool-operations.md +59 -71
- package/prompts/knowledge/tool-plan.md +1 -2
- package/prompts/knowledge/tool-process.md +1 -1
- package/prompts/knowledge/tool-read-history.md +6 -7
- package/prompts/knowledge/tool-read.md +1 -0
- package/prompts/knowledge/tool-settings.md +6 -7
- package/prompts/knowledge/tool-ssh.md +37 -15
- package/prompts/knowledge/tool-subagent.md +37 -39
- package/prompts/knowledge/tool-task.md +3 -1
- package/prompts/knowledge/tool-team-ledger.md +5 -1
- package/prompts/knowledge/tool-tree.md +2 -0
- package/prompts/knowledge/tool-wait-for.md +16 -16
- package/prompts/knowledge/tool-write.md +4 -1
- package/prompts/knowledge/upstream-protocol.md +39 -37
- package/prompts/persona-coder.md +1 -3
- package/prompts/persona-eng-coder.md +5 -5
- package/prompts/persona-eng-designer.md +34 -17
- package/prompts/persona-engineering.md +532 -501
- package/prompts/persona-explore.md +0 -2
- package/prompts/persona-normal.md +17 -9
- package/prompts/persona-plan.md +0 -2
- package/prompts/persona-tester.md +0 -2
- package/prompts/subagent-base.md +0 -2
- package/provider/anthropic.mjs +4 -2
- package/provider/core.mjs +5 -3
- package/provider/errors.mjs +41 -7
- package/provider/google.mjs +5 -3
- package/provider/reasoning-echo.mjs +16 -0
- package/provider/responses.mjs +4 -2
- package/provider/sse.mjs +11 -6
- package/rules.mjs +11 -10
- package/session-lifecycle.mjs +115 -81
- package/session-slot-write.mjs +1 -1
- package/session.mjs +23 -20
- package/shell-identity.mjs +129 -22
- package/skip-dirs.mjs +24 -0
- package/team-ledger.mjs +22 -22
- package/text-budget.mjs +1 -1
- package/think-off.mjs +27 -0
- package/token-ttl.mjs +1 -1
- package/token-window.mjs +278 -88
- package/tool-docs/bash.md +0 -2
- package/tool-docs/consult_start.md +2 -2
- package/tool-docs/consult_stop.md +2 -2
- package/tools/browser.mjs +8 -8
- package/tools/execute.mjs +2 -2
- package/tools/file.mjs +17 -11
- package/tools/git.mjs +12 -12
- package/tools/ops.mjs +2 -2
- package/tools/patch.mjs +1 -1
- package/tools/process-doc-mark.mjs +33 -4
- package/tools/repomap.mjs +25 -3
- package/tools/search.mjs +74 -26
- package/tools/shared.mjs +4 -3
- 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 +3 -3
- package/window-policy.mjs +118 -78
|
@@ -2,63 +2,64 @@
|
|
|
2
2
|
* agent/setup-reminders.mjs — per-turn transient reminders
|
|
3
3
|
* (SESSION.md §6.11 — 2026-09-06 需求池 R5/R8/R9/R11 合并设计; R10 L1 peer 注入同文件).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* CURRENT state, so a mode/
|
|
5
|
+
* 本档写两类东西:
|
|
6
|
+
* - A 段格位:`time`(`pushTimeReminder`)· `peer`(`pushPeerReminder`)· `editor`(`pushInjections`)。
|
|
7
|
+
* - 会话头块:`pushSessionHeadBlock`——现读八项(端名 · 工作模式 · 槽 · OS 与工作目录 · 执行器身份 ·
|
|
8
|
+
* 网页搜索面 · 项目相位 ∥ 报明行 · 依赖大纲)拼成一段文本,写进 `agent._sessionHead`(机制 = `CONTEXT-COMPACTION.md`「会话头块」)。
|
|
9
|
+
* 会话内恒定的东西住这里,不再每请求重拼。大纲正文由调用方构好传入(`sessionOutlineOf` 是那一处)。
|
|
10
|
+
* 每轮只留真正每轮会变的三格(`time` ∥ `peer` ∥ `mode`);`model` 与 `resumed` 不是每轮变化的事实,已随
|
|
11
|
+
* env 身份行一并退场——`agent._sessionStart` 字段本身仍在(会话文件身份键、轨迹关联等直接读它)。
|
|
12
|
+
* Change awareness needs no dedicated injection — every turn carries the CURRENT state, so a mode/slot flip
|
|
13
|
+
* shows up at the next run's head block.
|
|
13
14
|
* git is NOT a field here (§6.11: CLI 不重复注入 clean|dirty 摘要) — the rich
|
|
14
15
|
* git-context injection (branch/commits/uncommitted — helpers.mjs
|
|
15
|
-
* collectGitContext
|
|
16
|
-
* Peer awareness (R10 L1) rides the
|
|
16
|
+
* collectGitContext) 本批已暂停注入(设计档 §7.1「暂停注入」)。
|
|
17
|
+
* Peer awareness (R10 L1) rides the per-turn transient channel:
|
|
17
18
|
* pushPeerReminder injects the live co-cwd instance list when present.
|
|
18
|
-
* Manifest state rides it too (#28 — `docs/core/design/MANIFEST.md` §2.6):
|
|
19
|
-
* pushManifestStateReminder carries the project phase as a self-healing single live line.
|
|
20
19
|
* #34 adds the per-turn value refresh (mtime-gated re-read — §2.6 ③b / KD-M1-17..M1-19):
|
|
21
|
-
*
|
|
20
|
+
* 会话头块里的项目相位总是盘上当前那个,不是装配时的快照。
|
|
22
21
|
* 2026-09-21(#188):**状态选行**(③' `projectView(agent.cwd)` —— KD-M1-26)——`ok` ⇒ 相位行
|
|
23
22
|
* (逐字零改);`no-project` / `workspace` ⇒ 报明行;`missing` / `invalid` ⇒ 有既往好值保守沿用、
|
|
24
23
|
* 无 ⇒ 报明行;无锚 ⇒ **零 I/O / 零报明**(KD-M1-27)。报明行构造 = `manifestReportLine` 四态。
|
|
25
24
|
*
|
|
26
25
|
* #113(S1 续轮第二批——VSC 侧并入 ④ 段):`pushInjections`(机器行专用注入——编辑器上下文
|
|
27
|
-
*
|
|
26
|
+
* 等端侧采集内容;N 条并成一条、写入 `editor` 格)与 `appendImagePointer`(粘贴图指引——非多模态模型可见报错)
|
|
28
27
|
* 两档并入——内容由端采集 / 传入(核内零端名),核供注入纪律单点。
|
|
29
28
|
*/
|
|
30
29
|
import { statSync } from "node:fs"
|
|
31
30
|
import { resolve } from "node:path"
|
|
32
31
|
import { sessionEnd } from "../session-slots.mjs"
|
|
33
32
|
import { peerInstances } from "../peer-instances.mjs"
|
|
34
|
-
import { specForModel } from "../config.mjs"
|
|
33
|
+
import { resolveWorkMode, specForModel } from "../config.mjs"
|
|
35
34
|
import { docRootPaths, manifestFilePath, readManifest, projectView } from "../manifest.mjs"
|
|
35
|
+
import { normalizeOrigin } from "../memory/origin.mjs"
|
|
36
|
+
import { OUTLINE_INJECT_PREFIX } from "./helpers.mjs"
|
|
37
|
+
// 执行器身份那一行(件 ⑤):身份与版本的单源 = `shell-identity.mjs`,本档只取一行文案。
|
|
38
|
+
import { resolveShellIdentity, shellVersionLine } from "../shell-identity.mjs"
|
|
39
|
+
// 降级留痕(`sessionOutlineOf` 的 skip 行)——核日志单一通道,与 `compaction-work-state.mjs` 同一条。
|
|
40
|
+
import { logEvent } from "../log.mjs"
|
|
41
|
+
// 网页搜索面那一行的工具侧判据:后端档位与 DeepSeek 资格都只认工具侧单点(`backendMode` ∥ `deepseekChannel`),
|
|
42
|
+
// 键的解引用沿用 `tools/web.mjs` 的同一个读法(`resolveEnvRefs`)——判据只有一处,复制一份就会与真实行为漂移。
|
|
43
|
+
import { backendMode, deepseekChannel } from "../tools/web-deepseek.mjs"
|
|
44
|
+
import { resolveEnvRefs } from "../env-ref.mjs"
|
|
45
|
+
// A 段当前状态的唯一写入口与会话头块的唯一写入口都住 `context-push.mjs`(`CONTEXT-COMPACTION.md`「注入的三段:按存活期分」∥「会话头块」):本档写 `time` ∥ `peer`
|
|
46
|
+
// ∥ `editor` 三格与 `_sessionHead` 一段,写即覆盖——不再扫 `agent.history` 摘旧行 / 按内容比同文。
|
|
47
|
+
import { setInject, setSessionHead } from "../context-push.mjs"
|
|
36
48
|
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export function envStateLine({ mode, model, slot, resumed }) {
|
|
41
|
-
return `[System reminder: env: ${sessionEnd()}, mode: ${mode}, model: ${model}, slot: ${slot}, resumed: ${resumed ? "yes" : "no"}.]`
|
|
49
|
+
/** Local time, second precision, for the per-turn transient reminder. */
|
|
50
|
+
function timeNowLocal() {
|
|
51
|
+
return new Date().toLocaleString("sv-SE")
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* agent.
|
|
49
|
-
*
|
|
50
|
-
* F3 伪触发消除)。slot = 粘性 agent._slot(§6.11 N2/N3——无绑定显式 null)。
|
|
51
|
-
* Degrades safely: activeModel null → provider.model → "unknown" (T-E12);
|
|
52
|
-
* a missing config/history never throws (T-E13).
|
|
55
|
+
* `time` 格的写入方(一格一个写入方;写入节拍单源 = `docs/core/design/CONTEXT-COMPACTION.md` §1.1 格位表
|
|
56
|
+
* 「每回合一次:每请求读到的是这一请求的时间」)。两个调用点都走本函数:
|
|
57
|
+
* `agent/setup.mjs` 的 `prepareRun`(run 起点——只调 `prepareRun` 的路径仍有时间行)∥
|
|
58
|
+
* `agent/run-stages.mjs` 的 `injectTurnReminders`(回合头——覆盖为这一回合的时间)。
|
|
59
|
+
* 成本:`assembleRequestMessages` 每请求按格现取,本格并进请求尾部那一块 ⇒ 每回合换值不破前缀缓存。
|
|
53
60
|
*/
|
|
54
|
-
export function
|
|
55
|
-
|
|
56
|
-
const mode = workMode === "engineering" ? "eng" : workMode
|
|
57
|
-
const model = agent.activeModel ?? agent.provider?.model ?? "unknown"
|
|
58
|
-
const slot = agent._slot ?? null
|
|
59
|
-
const resumed = agent._envResumed === true
|
|
60
|
-
agent._envResumed = false
|
|
61
|
-
agent.history.push({ role: "user", content: envStateLine({ mode, model, slot, resumed }), transient: true })
|
|
61
|
+
export function pushTimeReminder(agent) {
|
|
62
|
+
setInject(agent, "time", `[System reminder: current time is ${timeNowLocal()} (local; timezone ${Intl.DateTimeFormat().resolvedOptions().timeZone || "local"})].`)
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
/** 情境行前缀——本行族识别符(摘旧行 / 会话重建认领同用;行形逐字见 manifestStateLine)。 */
|
|
@@ -67,8 +68,7 @@ const MANIFEST_LINE_PREFIX = "[System reminder: project state: "
|
|
|
67
68
|
/** phase → rigor 标签映射(判据单源 = 需求 v2);未知值不在表内 → 无标签。 */
|
|
68
69
|
const MANIFEST_RIGOR = Object.freeze({ "initial-dev": "light", production: "strict" })
|
|
69
70
|
|
|
70
|
-
/** 情境行构造 — pure, unit-testable(模块契约 `docs/core/design/MANIFEST.md` §2.6
|
|
71
|
-
* envStateLine 同族)。行形逐字(**单字段**——2026-09-17 裁撤批后):
|
|
71
|
+
/** 情境行构造 — pure, unit-testable(模块契约 `docs/core/design/MANIFEST.md` §2.6)。行形逐字(**单字段**——2026-09-17 裁撤批后):
|
|
72
72
|
* `[System reminder: project state: phase: <值> (rigor: <light|strict>).]`
|
|
73
73
|
* 未知 phase → 只出值、不编判据(无标签)。 */
|
|
74
74
|
export function manifestStateLine({ phase }) {
|
|
@@ -147,67 +147,165 @@ function refreshManifest(agent) {
|
|
|
147
147
|
agent._manifestMtime = mtimeMs
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
/** 会话头块首行的识别前缀(用例按它数块:一次请求恰一处)。 */
|
|
151
|
+
export const SESSION_HEAD_PREFIX = "[System reminder: session head —"
|
|
152
|
+
|
|
150
153
|
/**
|
|
151
|
-
*
|
|
152
|
-
* `
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* 槽——架构 E5.1 #5,`context.mjs` 压缩面零触碰)。`transient:true` ⇒ 不进人读线(`_fullHistory`)。
|
|
156
|
-
* @param {object} agent 主 agent(`agent.manifest` / `agent.history` / `agent.cwd`——③'/③b)
|
|
157
|
-
* @param {{depth?: number}} [opts] 注入深度(仅 depth-0)
|
|
158
|
-
* @returns {boolean} 是否落新行(测试断言用)
|
|
154
|
+
* 项目相位 ∥ 报明行那一行(③' 状态选行 + ③b 取值前置步;判据见 `docs/core/design/MANIFEST.md` §2.6):
|
|
155
|
+
* - 无锚(`agent.cwd` 缺)⇒ 有既往好值就沿用、无则 null(零 I/O / 零报明——KD-M1-27);
|
|
156
|
+
* - 有锚 ⇒ `projectView` 五态选行,mtime 门控重读后取当前相位(KD-M1-26)。
|
|
157
|
+
* @returns {string|null} 整行(含 `[System reminder: project state: ` 前缀)或 null(无内容可报)
|
|
159
158
|
*/
|
|
160
|
-
|
|
161
|
-
if (depth !== 0) return false // ① 仅 depth-0(子代理读任务书——架构 §2.4 M5 零 manifest 读面)
|
|
162
|
-
if (agent.config?.agent?.engineering !== true) return false // ② 模式门:仅工程模式
|
|
159
|
+
function projectStateLine(agent) {
|
|
163
160
|
let line
|
|
164
161
|
if (!agent.cwd) {
|
|
165
|
-
|
|
166
|
-
// 无既往好值 ⇒ 零注入)。既有无 cwd 夹具用例零改(§2.6 条 3 边界同源)。
|
|
167
|
-
if (!agent.manifest) return false
|
|
162
|
+
if (!agent.manifest) return null
|
|
168
163
|
line = manifestStateLine({ phase: agent.manifest.phase })
|
|
169
164
|
} else {
|
|
170
|
-
// ③' 状态选行(KD-M1-26——**每回合实读**,成本两轴见 §2.6 条 3):projectView 五态 ⇒ 选行。
|
|
171
165
|
const view = projectView(agent.cwd)
|
|
172
166
|
refreshManifest(agent) // ③b 取值前置步(#34):mtime 门控重读——相位行须取刷新后的值
|
|
173
167
|
if (view.state === "ok") {
|
|
174
168
|
const phase = (agent.manifest ?? view.manifest)?.phase
|
|
175
169
|
line = phase === undefined ? null : manifestStateLine({ phase })
|
|
176
170
|
} else if (view.state === "no-project" || view.state === "workspace") {
|
|
177
|
-
line = manifestReportLine({ ...view, cwd: resolve(agent.cwd) })
|
|
171
|
+
line = manifestReportLine({ ...view, cwd: resolve(agent.cwd) })
|
|
178
172
|
} else if (agent.manifest) {
|
|
179
173
|
line = manifestStateLine({ phase: agent.manifest.phase }) // missing / invalid:有既往好值 ⇒ 保守沿用
|
|
180
174
|
} else {
|
|
181
175
|
line = manifestReportLine({ ...view, cwd: resolve(agent.cwd) }) // 首观即失败 ⇒ 至少可见一次(KD-M1-26)
|
|
182
176
|
}
|
|
183
177
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
178
|
+
return line ?? null
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 依赖大纲正文(会话头块里最贵的一项)——调用方拿它构好 `outline` 传进 `pushSessionHeadBlock`。
|
|
183
|
+
* 空串 = 这一趟没有大纲:`tiny` 档不构、无记忆句柄不构、索引未就绪不构、空摘要(`(no indexed` 开头)
|
|
184
|
+
* 不装——四种情况在块上是同一件事:大纲那两行不写。
|
|
185
|
+
* 它要读索引与源文件,所以只在两个刷新点调(run 起点与压缩后),不每请求重算。
|
|
186
|
+
* `none found:` 查过 `thincoder-core/tools/repomap.mjs` 的 `buildSummary`(只收 db ∥ cwd ∥ origin,不认
|
|
187
|
+
* agent 也不装 tiny ∥ 空摘要两条门)与 `agent/setup.mjs` 的 `prepareRun`(同一段三行内联在意,无导出面)。
|
|
188
|
+
*/
|
|
189
|
+
export async function sessionOutlineOf(agent) {
|
|
190
|
+
if (!agent?.memory) return ""
|
|
191
|
+
if (resolveWorkMode(agent?.config?.agent) === "tiny") return ""
|
|
192
|
+
try {
|
|
193
|
+
const { buildSummary } = await import("../tools/repomap.mjs")
|
|
194
|
+
// §6.14 B4:origin 限定 + 文件数上界(越界 ⇒ 提示行 + 跳过大纲构建——见 repomap.mjs)。
|
|
195
|
+
const summary = await buildSummary(agent.memory.db, agent.cwd, { origin: normalizeOrigin(agent.memory.codeOrigin) })
|
|
196
|
+
return summary && !summary.startsWith("(no indexed") ? summary : ""
|
|
197
|
+
} catch (err) {
|
|
198
|
+
// 降级留痕(与 `compaction-work-state.mjs` 的 `skip(reason)` 同一条纪律:缺失不是无痕,
|
|
199
|
+
// 否则「索引坏了」「本来就没索引」两种回事在上下文里同形)。注入结不打断 run。
|
|
200
|
+
logEvent("session-head:outline-skip", { reason: err?.message ?? String(err) })
|
|
201
|
+
return ""
|
|
196
202
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 网页搜索面(`docs/core/design/CONTEXT-COMPACTION.md`「网页搜索面那一行」):判据全取这一趟的活工具表与配置,
|
|
206
|
+
// 不读盘、不探网、不改任何工具的可用性。名称判据是启发式,行文因此是提示、不是门。
|
|
207
|
+
const MCP_SEARCH_NAME_RE = /search|web|reader|crawl/i
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* `websearch` 后端的第二档(Tavily):键的读法与 `tools/web.mjs` 的 `fetchTavily` 同一个(`resolveEnvRefs(config?.websearch?.apiKey)`,
|
|
211
|
+
* 「未设 ∕ 空串 ⇒ 抛错」),而那里把这次读放在 `try` 之外、调用处也没有包 try——引用坏了,`websearch` 在走到
|
|
212
|
+
* Tavily ∥ Bing 之前就抛。此时写 `tavily` ∥ `bing scrape` 是与运行期相反的断言,这一档因此单独成 `config-error`;
|
|
213
|
+
* 缺失不是无痕,故留一条与 `session-head:outline-skip` 同形的日志。行本身照写、不向调用方抛错——注入失败不打断 run。
|
|
214
|
+
* @param {object} config `agent.config`(读 `websearch.apiKey`)
|
|
215
|
+
* @returns {string} `tavily` ∥ `bing scrape` ∥ `config-error`
|
|
216
|
+
*/
|
|
217
|
+
function websearchKeyFace(config) {
|
|
218
|
+
let apiKey
|
|
219
|
+
try {
|
|
220
|
+
apiKey = resolveEnvRefs(config?.websearch?.apiKey)
|
|
221
|
+
} catch (err) {
|
|
222
|
+
logEvent("session-head:web-search-skip", { reason: err?.message ?? String(err) })
|
|
223
|
+
return "config-error"
|
|
201
224
|
}
|
|
202
|
-
|
|
203
|
-
|
|
225
|
+
// 与 `fetchTavily` 的 `if (!apiKey) return null` 同一谓词:解析不出非空值 ⇒ 落到 Bing 抓取。
|
|
226
|
+
return apiKey ? "tavily" : "bing scrape"
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 网页搜索面那一行(行构造器、单测入口;唯一副作用 = 坏键引用时经 `websearchKeyFace` 留一条
|
|
231
|
+
* `session-head:web-search-skip` 痕;行形与判据 = `docs/core/design/CONTEXT-COMPACTION.md`「网页搜索面那一行」):
|
|
232
|
+
* `· Web search: MCP: <服务器名列表 | none matched by name (servers: …) | none> · websearch(<后端>) fetch(<后端>)`。
|
|
233
|
+
* 三段都取这一趟的事实:MCP 段数活工具表里带 `_mcpName` 的搜索类工具(内置 `websearch` 名字命中 `/web/` 却不带
|
|
234
|
+
* 该字段,只按名字判就把它报成一个 MCP 服务器;没有名字可写的条目不报);两条内置腿先判在场(装配期按 `name`
|
|
235
|
+
* 剔除之后仍报它就是与运行期相反的断言),再按各自的 `backend` 与 DeepSeek 资格取后端词。
|
|
236
|
+
* MCP 段三态都写:工具名命中就问名字;挂着 MCP 工具而一条工具名都没命中,写
|
|
237
|
+
* `none matched by name (servers: …)` 并列出服务器名(名字判据是启发式,这一态不能写成事实);一个 MCP 工具都没有
|
|
238
|
+
* 才写 `none`;工具不在写 `absent`。整行从不省略——省略只会被读成「不知道」。
|
|
239
|
+
* @param {{tools?: object[], config?: object}} p `tools` = 本趟活工具表(`agent.tools`);`config` = `agent.config`
|
|
240
|
+
* @returns {string} 整行(以 `· Web search: ` 起首,不含换行)
|
|
241
|
+
*/
|
|
242
|
+
export function searchFaceLine({ tools, config } = {}) {
|
|
243
|
+
const list = Array.isArray(tools) ? tools : []
|
|
244
|
+
const seenServers = [] // 表里所有带名字的 MCP 服务器,按出现序
|
|
245
|
+
const matchedServers = [] // 其中至少一条工具名命中名字判据的
|
|
246
|
+
for (const tool of list) {
|
|
247
|
+
const server = tool?._mcpName
|
|
248
|
+
if (typeof server !== "string" || server.trim() === "") continue // 没有名字可写(内置工具不带这个字段)
|
|
249
|
+
if (!seenServers.includes(server)) seenServers.push(server)
|
|
250
|
+
if (typeof tool?.name !== "string" || !MCP_SEARCH_NAME_RE.test(tool.name)) continue
|
|
251
|
+
if (!matchedServers.includes(server)) matchedServers.push(server)
|
|
252
|
+
}
|
|
253
|
+
// DeepSeek 资格一次求出、两条腿共用(判据本体 = `tools/web-deepseek.mjs` 的 `deepseekChannel`,逐条已 try ⇒ 永不抛)。
|
|
254
|
+
const deepseek = deepseekChannel(config) !== null
|
|
255
|
+
const legFace = (name, fallback) => {
|
|
256
|
+
if (!list.some((tool) => tool?.name === name)) return "absent"
|
|
257
|
+
if (backendMode(config, name) !== "local" && deepseek) return "deepseek"
|
|
258
|
+
return fallback()
|
|
259
|
+
}
|
|
260
|
+
const mcp = matchedServers.length > 0
|
|
261
|
+
? matchedServers.join(", ")
|
|
262
|
+
: seenServers.length > 0
|
|
263
|
+
? `none matched by name (servers: ${seenServers.join(", ")})`
|
|
264
|
+
: "none"
|
|
265
|
+
const websearch = legFace("websearch", () => websearchKeyFace(config))
|
|
266
|
+
const fetch = legFace("fetch", () => "local")
|
|
267
|
+
return `· Web search: MCP: ${mcp} · websearch(${websearch}) fetch(${fetch})`
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* 会话头块的写入方单点(`CONTEXT-COMPACTION.md`「会话头块」):现读八项拼成一段文本,
|
|
272
|
+
* 交 `setSessionHead` 整段替换 `agent._sessionHead`(不进人读线、不进记录存储、不进会话存储)。
|
|
273
|
+
* 项序固定,缺项整行不写、不补占位:
|
|
274
|
+
* ① 端名(`sessionEnd()`)· 工作模式(`resolveWorkMode`)· 槽(`agent._slot`;无绑定不写这一项)
|
|
275
|
+
* ② OS 与工作目录
|
|
276
|
+
* ③ 执行器身份(`shellVersionLine`——名字,探到版本时带版本;探测在本函数之外结算)
|
|
277
|
+
* ④ 网页搜索面(`searchFaceLine`——MCP 服务器名与两条内置腿的后端词;这一行从不缺)
|
|
278
|
+
* ⑤ 项目相位 ∥ 报明行(`projectStateLine`)
|
|
279
|
+
* ⑥ 项目依赖大纲(`outline`;空串 ⇒ 整段不写)
|
|
280
|
+
* `outline` 必填、无默认:这一趟没有大纲就明确传空串,函数不替调用方补一个猜的值。
|
|
281
|
+
* 每个 agent 各得一份(`prepareRun` 那一行不判 depth):子代理的块没有大纲那两段,`outline` 传空串。
|
|
282
|
+
* @param {object} agent 目标 agent(`agent.cwd` ∥ `agent._slot` ∥ `agent.manifest`)
|
|
283
|
+
* @param {{outline: string}} opts `outline` = 本趟大纲正文(必填、无默认)
|
|
284
|
+
* @returns {boolean} 恒为真(每次调用都整段重写;返回面留作调用方断言)
|
|
285
|
+
*/
|
|
286
|
+
export function pushSessionHeadBlock(agent, { outline } = {}) {
|
|
287
|
+
if (typeof outline !== "string") {
|
|
288
|
+
throw new Error(`pushSessionHeadBlock: \`outline\` is required (a string, no default) — pass "" when this run has no outline; got ${JSON.stringify(outline)}`)
|
|
289
|
+
}
|
|
290
|
+
const mode = resolveWorkMode(agent?.config?.agent)
|
|
291
|
+
const slot = agent?._slot ?? null
|
|
292
|
+
const platform = { win32: "Windows", darwin: "macOS", linux: "Linux" }[process.platform] ?? process.platform
|
|
293
|
+
const lines = [`${SESSION_HEAD_PREFIX} ${sessionEnd()} · mode: ${mode}${slot === null ? "" : ` · slot: ${slot}`}`]
|
|
294
|
+
lines.push(agent?.cwd ? `· OS: ${platform} · Working directory: ${agent.cwd}` : `· OS: ${platform}`)
|
|
295
|
+
// 执行器身份:同步只读版本缓存(探测在 `prepareRun` 里、本函数之前已结算)。没探到就只有名字。
|
|
296
|
+
lines.push(`· Shell: ${shellVersionLine(resolveShellIdentity(agent?.config?.shell ?? null))}`)
|
|
297
|
+
// 网页搜索面:与 OS ∥ Shell 同属环境事实,紧接执行器身份——模型据此决定要不要去联网核实。
|
|
298
|
+
lines.push(searchFaceLine({ tools: agent?.tools, config: agent?.config }))
|
|
299
|
+
const projectState = projectStateLine(agent)
|
|
300
|
+
if (projectState) lines.push(`· project state: ${projectState.slice(MANIFEST_LINE_PREFIX.length).replace(/\.?\]$/, "")}`)
|
|
301
|
+
if (outline) lines.push("· project dependency outline:", `${OUTLINE_INJECT_PREFIX}\n${outline}`)
|
|
302
|
+
setSessionHead(agent, `${lines.join("\n")}]`)
|
|
204
303
|
return true
|
|
205
304
|
}
|
|
206
305
|
|
|
207
306
|
/**
|
|
208
|
-
* R10 L1 peer reminder(MULTI-INSTANCE-COLLAB §2a.4 D-L1a
|
|
209
|
-
*
|
|
210
|
-
* ——无同伴零开销(peerInstances 惰性 mtime/TTL 缓存保证:命中零 exec)。任何
|
|
307
|
+
* R10 L1 peer reminder(MULTI-INSTANCE-COLLAB §2a.4 D-L1a):depth-0、transient:true——与 `editor` 格同一注入纪律。
|
|
308
|
+
* 有同伴(非 self > 0)才注入——无同伴零开销(peerInstances 惰性 mtime/TTL 缓存保证:命中零 exec)。任何
|
|
211
309
|
* 感知失败静默跳过(注入绝不打断回合)。文案(设计逐字):"本目录另有 N 个活跃
|
|
212
310
|
* thincoder({end} pid={pid}…)——文件操作注意避让"。
|
|
213
311
|
*
|
|
@@ -222,29 +320,27 @@ export async function pushPeerReminder(agent) {
|
|
|
222
320
|
} catch {
|
|
223
321
|
return // 感知失败降级——不注入
|
|
224
322
|
}
|
|
225
|
-
if (peers.length === 0)
|
|
323
|
+
if (peers.length === 0) {
|
|
324
|
+
// A 段:无同伴 ⇒ 清空 `peer` 格(旧值必须消失——上一次的同伴列表不是当前状态)。
|
|
325
|
+
setInject(agent, "peer", null)
|
|
326
|
+
return
|
|
327
|
+
}
|
|
226
328
|
const who = peers.map((p) => (p.end ? `${p.end} pid=${p.pid}` : `pid=${p.pid}`)).join("、")
|
|
227
|
-
agent.
|
|
228
|
-
role: "user",
|
|
229
|
-
content: `[System reminder: 本目录另有 ${peers.length} 个活跃 thincoder(${who})——文件操作注意避让]`,
|
|
230
|
-
transient: true,
|
|
231
|
-
})
|
|
329
|
+
setInject(agent, "peer", `[System reminder: 本目录另有 ${peers.length} 个活跃 thincoder(${who})——文件操作注意避让]`)
|
|
232
330
|
}
|
|
233
331
|
|
|
234
332
|
/**
|
|
235
333
|
* 机器行专用注入单点(#113 VSC 侧并入——编辑器上下文等端侧采集内容):`injections` =
|
|
236
|
-
* 单条或数组,每条 `{ content }`。纪律与 CLI parity
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
334
|
+
* 单条或数组,每条 `{ content }`。纪律与 CLI parity:只进 A 段 `editor` 格(进机器请求,
|
|
335
|
+
* 不进人读记录);**N 条并成一条**(条间换行)——写即覆盖,同文去重退场。
|
|
336
|
+
* 本次一批零条 ⇒ **不调 `setInject`**(它对空 `content` 写 `null`,逐字照它实现就把这份上下文抹掉了)。
|
|
337
|
+
* 非法条目静默跳过(注入绝不打断回合)。内容由**端装配**采集并传入(核内零端名——④ 段)。
|
|
240
338
|
*/
|
|
241
|
-
export function pushInjections(
|
|
339
|
+
export function pushInjections(agent, injections) {
|
|
242
340
|
const list = Array.isArray(injections) ? injections : (injections ? [injections] : [])
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
history.push({ role: "user", content: inj.content, transient: true })
|
|
247
|
-
}
|
|
341
|
+
const lines = list.filter((inj) => inj && typeof inj.content === "string").map((inj) => inj.content)
|
|
342
|
+
if (lines.length === 0) return
|
|
343
|
+
setInject(agent, "editor", lines.join("\n"))
|
|
248
344
|
}
|
|
249
345
|
|
|
250
346
|
/**
|