@shgroup/dsh-serenity-hooks 1.136.5 → 1.137.1

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/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-serenity-hooks",
3
- "version": "1.136.5",
3
+ "version": "1.137.1",
4
4
  "main": "lib/index.js",
5
5
  "description": "宁静号 ACC harness(Native Cordis 插件):给 DSH 装一个「AI 工作区」——14 个工具(container_fs/cognitive_trajectory/dashboard/container_git/msm/praxis/ontology/serenity-skill-creator/localstore/container_admin/browser_slot;另三个 im-bridge/diagram/reconstruct 按条件出现)+ 机械约束(安全模式/工作区围墙/密钥守卫)+ 认知轨迹日志与原地重建 + 网页登录入口/IM 桥/认知轨迹唤醒注册表 + 浏览器槽位管理(≤20 个独立 profile 的 Chrome 槽位,带占用归属与异常时向所属会话反向注入提醒)。轨迹声明 = 轨迹目录下的 trajectory.json(约束面 + 旧标识 uid + CRO 机器绑定 cro.host;旧名 trajectory-constraint.json / skiff.json 仍在读取族里);轨迹提示词 = 轨迹目录下的 PROMPT.md(一条轨迹「是谁、按什么章程工作」,所有轨迹通用,追加在容器层与质量层之后,不替换它们)。适配 DSH 0.1.7-rc.1 / 0.2.0-rc.1 / 0.2.1-rc.1(三档,deepseek-ai/deepseek-harness)。",
6
6
  "engines": {
package/lib/index.js CHANGED
@@ -6,7 +6,7 @@ import { n as checkLocalstoreGitCompliance, o as readStore, s as runLocalStore,
6
6
  import { d as findPackageRoot, i as constraintSystemPromptSource, l as resolveConstraintSystemPrompt, r as constraintCognitiveTrajectory, t as TRAJECTORY_CONSTRAINT_HINT, u as ACC_VERSION } from "./rules-BYeykzys.js";
7
7
  import { C as runMsmAsync, S as runMsm, T as setWeixinSendEndpoint, _ as ACC_CATALOG, a as loadOpencodeSkill, b as findEntry, c as summarizeHostContract, f as forgetNonCccToolVisibility, g as forgetToolVisibility, h as syncToolVisibility, i as listOpencodeSkillDirs, m as registerGuards, n as readDshVersion, o as compareSemver, r as setSafeMode, s as hostContractReport, t as getStatus, v as CCC_CONFIG_REFERENCE, w as docsPointer, x as loadMsmEntries } from "./status-BjebXb2G.js";
8
8
  import { c as replacesDefaultIdentity, i as listTrajectoryConstraints, l as trajectoryCodeForSession, n as findDirNameByCode, o as readTrajectoryConstraintAt, r as isTrajectoryConstrained, s as readTrajectoryConstraintByCode, t as TRAJECTORY_CONSTRAINT_FILENAME } from "./profile-RuvXAGBX.js";
9
- import { A as TRAJECTORY_PROMPT_FILENAME, C as recordToolUsage, D as buildResourceNameSuffix, E as buildResourceIndex, O as isSafeSkillName, S as verifyTotpCode, T as SKILL_ONTOLOGY_FILE, _ as projectKnownWorkspaces, a as trajectoryConstraintFor, b as FACE_PORTS, c as trajectoryWorkspaceMdPath, d as splitModel, f as registerCognitiveTrajectorySkillSection, g as migrateLegacyLocalstore, h as applyWirePatch, i as getTrajectoryAgent, j as hasTrajectoryPrompt, k as truncateContent, l as unregisterTrajectorySession, m as registerEntrySkillSectionGlobal, n as deliverToTrajectory, o as trajectoryConstraintMsmGate, p as registerEntrySkillSection, r as ensureWorkspacePromptSection, s as trajectoryConstraintParticipates, t as createTrajectoryAgent, u as workspaceCognitiveTrajectoryLine, v as readAdvancedSettings, w as REFERENCE_DIR, x as MECHANISM_PORTS, y as toWire } from "./session-y44CGve_.js";
9
+ import { A as TRAJECTORY_PROMPT_FILENAME, C as recordToolUsage, D as buildResourceNameSuffix, E as buildResourceIndex, O as isSafeSkillName, S as verifyTotpCode, T as SKILL_ONTOLOGY_FILE, _ as projectKnownWorkspaces, a as trajectoryConstraintFor, b as FACE_PORTS, c as trajectoryWorkspaceMdPath, d as splitModel, f as registerCognitiveTrajectorySkillSection, g as migrateLegacyLocalstore, h as applyWirePatch, i as getTrajectoryAgent, j as hasTrajectoryPrompt, k as truncateContent, l as unregisterTrajectorySession, m as registerEntrySkillSectionGlobal, n as deliverToTrajectory, o as trajectoryConstraintMsmGate, p as registerEntrySkillSection, r as ensureWorkspacePromptSection, s as trajectoryConstraintParticipates, t as createTrajectoryAgent, u as workspaceCognitiveTrajectoryLine, v as readAdvancedSettings, w as REFERENCE_DIR, x as MECHANISM_PORTS, y as toWire } from "./session-BUyOHV12.js";
10
10
  import { a as ACC_MESSAGE_KIND, d as readLastBound, f as resolveSessionCognitiveTrajectoryLabel, i as toMessage, l as findTrajectoryOfSession, n as deliver, o as PLUGIN_SOURCE, r as makeInjection, s as appendBound, u as listBoundSessionIds } from "./injection-BVKPD4Yf.js";
11
11
  import { c as buildCroSnapshot, d as WAKE_CATCH_UP_MS, f as addWake, i as sendToCognitiveTrajectory, n as registerWakeScheduler, o as registerCroTurnTracking, s as registerDisposer, t as createAndBindTarget, u as CARRIER_OPENING_MARK } from "./scheduler-DMF2hKeT.js";
12
12
  import { i as hostAliveProbe, n as readSimpleSettings, r as registerSettingsSection } from "./settings-zIGSzPPG.js";
@@ -7764,12 +7764,28 @@ const DEFAULT_COMPACTION_TOOLS = [
7764
7764
  ];
7765
7765
  /**
7766
7766
  * 协议级「假首轮」话语序列(用户确认固化,2026-08-24 S142):任何 CCC 在抽象层都是
7767
- * 宁静号/ACC——假首轮话语统一,无 CCC 配置面。两轮递进:
7768
- * ① ACC 身份 + EAP 原则 + we/us 人称 + 先锚定后行动
7769
- * ② 协作协议 5 条 + acknowledge 要求(只回确认,不做事)
7770
- * 文本 = 原 home-serenity CCC 配置,随零配置化固化进代码。
7767
+ * 宁静号/ACC——假首轮话语统一,无 CCC 配置面。
7768
+ *
7769
+ * 🔵 **2026-11-16 合并:两条 → 一条**(owner 令「合并吧」)。
7770
+ *
7771
+ * 判据(为什么合并安全 · 逐条对读过系统提示词**才**动的手):
7772
+ * · 本文件这两条**只出现一次**(`hasUserMessageHistory` 守卫:有真人说话就不再插),
7773
+ * 而系统提示词里的 EAP 块**每轮注入** ⇒ 两者不构成第二真相源,但确实**功能重叠**。
7774
+ * · 重叠的那一块 = EAP 是什么。系统提示词的 `eapBlock()` 给的是**更详细的操作定义**
7775
+ * (E↑/R↓/S↑ 各自查什么)⇒ 这里**不必复述**,压成一句指认即可。
7776
+ * · ⛔ **不可省的四处,条条只在 bootstrap 有**:
7777
+ * ① `personal pronoun is us/we` —— 系统提示词零处(grep 过)
7778
+ * ② `We anchor first, then act` —— 同上
7779
+ * ③ 协作五条 —— 系统提示词零处
7780
+ * ④ 身份句 `operator agent of Serenity…ACC protocol` —— 开场语境
7781
+ * · `Please simply reply "acknowledge"` 原本**两条各写一遍**(重复两次),合并后一处。
7782
+ *
7783
+ * 🔴 **为什么"合并"而不是"删第一条"**:删掉第一条会连同 ①②③④ 一起消失;
7784
+ * 合并只是去掉 EAP 的**展开复述**与重复的 acknowledge 指令,语义面零损失。
7785
+ * ⚠️ 轮数因此 2 → 1:`requiredSignals` 与 `pendingFakeTurns.remaining` 都由
7786
+ * `DEFAULT_FAKE_INITIAL_MESSAGES.length` 派生,**跟着自动变**,无需另改。
7771
7787
  */
7772
- const DEFAULT_FAKE_INITIAL_MESSAGES = ["You are the operator agent of Serenity — a cognitive container governed by the Abstract Cognitive Container (ACC) protocol.\nWe operate under the Explicit Abstraction Principle (EAP): the functional value of a thought equals its external reconstructability — every output we produce must be explicit (E↑), reconstructable (R↓), and stable (S↑).\nThe personal pronoun is us/we.\nWe anchor first, then act: the abstract layer precedes the concrete.\nPlease simply reply \"acknowledge\" — no action needed.", "Before we proceed, align on how we work:\n1. We read before we write — every decision grounds in what already exists in the container.\n2. Every output records its reasoning (R↓): decisions carry reasons and alternatives.\n3. We never jump levels — abstract layer first, then specifics.\n4. Every artifact we create is a durable cognitive anchor for the work that follows.\n5. We keep the container's state coherent (SESSION.md) as we advance.\nPlease simply reply \"acknowledge\" — no action needed."];
7788
+ const DEFAULT_FAKE_INITIAL_MESSAGES = ["You are the operator agent of Serenity — a cognitive container governed by the Abstract Cognitive Container (ACC) protocol.\nWe operate under the Explicit Abstraction Principle (EAP), whose operational self-check (E↑ explicit / R↓ reconstructable / S↑ stable) is given in full in the system prompt — apply it there, do not restate it here.\nThe personal pronoun is us/we.\nWe anchor first, then act: the abstract layer precedes the concrete.\nHow we work:\n1. We read before we write — every decision grounds in what already exists in the container.\n2. Every output records its reasoning (R↓): decisions carry reasons and alternatives.\n3. We never jump levels — abstract layer first, then specifics.\n4. Every artifact we create is a durable cognitive anchor for the work that follows.\n5. We keep the container's state coherent (SESSION.md) as we advance.\nPlease simply reply \"acknowledge\" — no action needed."];
7773
7789
  /**
7774
7790
  * 根会话重入判定(v1.28.1 提取导出以便单测):会话是否已有真实用户消息。
7775
7791
  * resume/续跑的会话已有对话历史 → **不重插假首轮**(只注入一次)。
@@ -7898,8 +7914,10 @@ async function* fakeTurnAckStream() {
7898
7914
  /**
7899
7915
  * 构建一个 epoch 感知晋升跟踪器(纯逻辑,可单测)。
7900
7916
  * requiredSignals:晋升所需信号数(boundary 后累计;默认 1)。
7901
- * 多轮锚定(v4):两轮递进锚定时 requiredSignals = 锚定轮数——
7902
- * 每条锚定回复(assistant/message)计一次,最后一条回复后晋升。
7917
+ * 多轮锚定(v4):N 轮递进锚定时 requiredSignals = N——每条锚定回复
7918
+ * (assistant/message)计一次,最后一条回复后晋升。
7919
+ * 🔵 2026-11-16:`DEFAULT_FAKE_INITIAL_MESSAGES` 由两条合并为一条 ⇒ 缺省 N = **1**
7920
+ * (仍由 `.length` 派生,不写死;本函数对 N 的语义未变)。
7903
7921
  *
7904
7922
  * maxRoundsFallback:**轮次兜底**(v1.19.3 修复 responses API 兼容)。
7905
7923
  * 某些模型/协议(如 opencode-go-responses)的会话可能不产生标准
@@ -8238,21 +8256,14 @@ function registerBootstrap(ctx) {
8238
8256
  const EVENT_LABEL = {
8239
8257
  /** 计分同步提醒(原 TRAJECTORY-STEWARD) */
8240
8258
  checkpoint: "CHECKPOINT",
8241
- /** 上下文极限重建提醒(原 TRAJECTORY;LIMIT 替代被否的 BOSS——自然词) */
8242
- limit: "LIMIT",
8243
- /** 极限强制升级(原 TRAJECTORY-ESCALATED) */
8244
- limitMandatory: "LIMIT · MANDATORY",
8259
+ /** 交接提醒(rebuild ≡ reconstruct 共用;2026-11-16 由 `limit`/`limitMandatory` 合并而来) */
8260
+ handover: "HANDOVER",
8245
8261
  /** 重建锚点头部(原 TRAJECTORY-REBUILD) */
8246
8262
  rebuild: "REBUILD",
8247
8263
  /** 敏感输出边界守卫(原 SERENITY OUTPUT GUARD) */
8248
8264
  guard: "BOUNDARY GUARD",
8249
8265
  /** SESSION.md 体积超限重写提醒(v1.31.1,S142 用户需求) */
8250
- compaction: "LOGBOOK COMPACTION",
8251
- /** **交界便签(REBUILD-TODO.md)体积超限清理提醒**(v1.49.0,owner 2026-09-26 需求)。
8252
- *
8253
- * 🔴 **刻意与 `compaction` 分开**:那条要求"**重写 SESSION.md 并保留 EAP 骨架**",
8254
- * 本条只要求"**清理便签**"——共用一个 token 会让模型误以为要动 SESSION.md。 */
8255
- scratchPrune: "SCRATCH PRUNE"
8266
+ compaction: "LOGBOOK COMPACTION"
8256
8267
  };
8257
8268
  /** 家族标识(所有动态注入统一前缀) */
8258
8269
  const ASSISTANT_PREFIX = "COGNITIVE-TRAJECTORY-ASSISTANT";
@@ -8263,24 +8274,23 @@ function eventToken(event) {
8263
8274
  /** ACK 确认码前缀(recorded/skipped 语义不变,仅家族名更新) */
8264
8275
  const ACK_PREFIX = `${ASSISTANT_PREFIX}-recorded`;
8265
8276
  /**
8266
- * rebuild 交界便签的**文件名**(v1.49.0;owner 2026-09-26 需求)。
8277
+ * 交接便签的**落点**:`LOG/LOG.md` 里的节名(2026-11-16 owner 裁定)。
8267
8278
  *
8268
- * ## 它取代了什么(owner 原话:*"砍掉 in-flight,这正是目的"*)
8269
- * v1.31.1 的交界协议要求把手头事项写进 **SESSION.md 末尾**的 `## In-flight (rebuild handover)` 段。
8270
- * 实测的代价(S142 自身取证):In-flight 段曾积 **12 块**(含多份**已被取代**的交接),
8271
- * 而 SESSION.md 是**有格式义务**的持久文件(7 段固定 + 粒度受 EAP 约束)⇒
8272
- * ① 持久文件被临时物污染 ② 每次整理都要付"压缩+归档+保真"三件套(该文件曾达 292 KB)。
8273
- *
8274
- * ⇒ 分家:**只用一次的交界材料**写进这份**临时便签**(无格式义务、无留档义务、可随时丢弃)。
8279
+ * ## 它取代了什么
8280
+ * v1.49.0 曾把交界材料分家到**独立文件** `REBUILD-TODO.md`。v1.136.0 起 LOG 有了
8281
+ * **机械轮转**(`carrier-log.ts`),于是那个独立文件成了第三种住处——而它要装的东西
8282
+ * ("我卡在哪一步")本质是**过程留痕**,与 LOG 同性质、同寿命、同策展度。
8283
+ * ⇒ 2026-11-16 owner 裁定:**整体删掉独立文件**,便签住进 LOG 的一节,
8284
+ * 轮转时**整节搬运**进新代出生头(否则旧代冻结、新代空白 ⇒ 交接断开)。
8275
8285
  *
8276
8286
  * ## 🔴 三处引用同一常量(单一真相源)
8277
- * **写侧** = `seams/keeper.ts` 的 `rebuildReminderText()`|**读侧** = `trajectory/rebuild.ts` 的重建锚点|
8278
- * **体积提醒** = `seams/keeper.ts` 的 `rebuildTodoReminderText()`。
8279
- * 文件名一旦漂移,写侧写的东西读侧就找不到 —— **且没有任何机械信号会报警**。
8280
- *
8281
- * 🔴 **不得改名**(owner 已具名)。形态 = **固定文件名**(人读友好;比照旧 IN_FLIGHT_HEADING 的取舍)。
8287
+ * **写侧** = `seams/cognitive-trajectory-lifecycle.ts` 的 `handoverReminderText()`|**读侧** = `trajectory/rebuild.ts` 的重建锚点|
8288
+ * **搬运** = `trajectory/carrier-log.ts` 的 `rotateCarrierLog()`。
8289
+ * 节名一旦漂移,写侧写的东西读侧就找不到,**且没有任何机械信号会报警**。
8282
8290
  */
8283
- const REBUILD_TODO_FILENAME = "REBUILD-TODO.md";
8291
+ const HANDOVER_NOTE_HEADING = "## Handover note";
8292
+ /** 交接便签在 LOG 里的相对路径(给人读的提示用) */
8293
+ const LOG_FILE_REL = "LOG/LOG.md";
8284
8294
  /** 当前代的固定文件名。**名字即指针** —— 改成 A/B 双槽会引入"谁是当前"这个外部事实。 */
8285
8295
  const LOG_FILE = "LOG.md";
8286
8296
  /** 冻结日志的命名:`LOG-<YYYY-MM-DDTHHmm>.md`(**本地时区,分钟级**)。 */
@@ -8317,6 +8327,31 @@ function listFrozen(dir) {
8317
8327
  return names.filter((n) => n.startsWith("LOG-") && n.endsWith(".md")).sort();
8318
8328
  }
8319
8329
  /**
8330
+ * 从一份 LOG 正文里抽出 `## Handover note` 整节(含标题,到下一个同级或更高级标题为止)。
8331
+ *
8332
+ * 🔴 **为什么不抽就轮转 = 交接断开**:轮转把整份 `LOG.md` `mv` 成冻结代,新代是空白的。
8333
+ * 若在办状态写在旧代里,新会话读新代 ⇒ **读不到** ⇒ 交接失败,且**没有任何报错**。
8334
+ * 这与"便签必须被交接后的会话完整读到"是同一条判据(2026-11-16 owner 裁定)。
8335
+ *
8336
+ * @returns 该节全文(含标题、去掉尾部空行);没有该节 ⇒ `null`
8337
+ */
8338
+ function extractHandoverNote(text) {
8339
+ const lines = text.split("\n");
8340
+ const head = lines.findIndex((l) => l.trim() === HANDOVER_NOTE_HEADING);
8341
+ if (head < 0) return null;
8342
+ let end = lines.length;
8343
+ for (let i = head + 1; i < lines.length; i++) {
8344
+ const t = lines[i].trim();
8345
+ if (t.startsWith("## ") || t.startsWith("# ")) {
8346
+ end = i;
8347
+ break;
8348
+ }
8349
+ }
8350
+ const section = lines.slice(head, end);
8351
+ while (section.length > 0 && section[section.length - 1].trim() === "") section.pop();
8352
+ return section.join("\n");
8353
+ }
8354
+ /**
8320
8355
  * 生成新一代 `LOG.md` 的出生头。
8321
8356
  *
8322
8357
  * ⚠️ **措辞归 CCC**:这里只给一个**可替换的默认模板**,各轨迹可以在自己的 PROMPT.md 里
@@ -8381,8 +8416,10 @@ function rotateCarrierLog(trajectoryDir, now = /* @__PURE__ */ new Date()) {
8381
8416
  renameSync(live, dst);
8382
8417
  const verified = existsSync(dst) && statSync(dst).size === bytesBefore;
8383
8418
  if (!existsSync(live)) {
8384
- const frozen = listFrozen(dir);
8385
- writeFileSync(live, birthHeader(frozen.length + 1, now, target), "utf-8");
8419
+ let header = birthHeader(listFrozen(dir).length + 1, now, target);
8420
+ const note = extractHandoverNote(readFileSync(dst, "utf-8"));
8421
+ if (note !== null) header += `${note}\n\n`;
8422
+ writeFileSync(live, header, "utf-8");
8386
8423
  }
8387
8424
  return {
8388
8425
  rotated: true,
@@ -8424,8 +8461,9 @@ function stripAckSuffix(text) {
8424
8461
  */
8425
8462
  function buildRebuildAnchor(root, sessionName, activeMdPath, protocolMessages = DEFAULT_FAKE_INITIAL_MESSAGES, focus) {
8426
8463
  const rel = activeMdPath.startsWith(root) ? activeMdPath.slice(root.length + 1) : activeMdPath;
8427
- const todoAbs = join(dirname(activeMdPath), REBUILD_TODO_FILENAME);
8428
- const todoRel = todoAbs.startsWith(root) ? todoAbs.slice(root.length + 1) : todoAbs;
8464
+ const logDirAbs = join(dirname(activeMdPath), "LOG");
8465
+ const logLiveAbs = join(logDirAbs, "LOG.md");
8466
+ const logRel = logLiveAbs.startsWith(root) ? logLiveAbs.slice(root.length + 1) : logLiveAbs;
8429
8467
  const sessionDir = basename(dirname(activeMdPath));
8430
8468
  const sessionLine = sessionDir !== "AGENT_SESSIONS" ? `- Serenity session: ${sessionName !== "" ? `${sessionName} (${sessionDir})` : sessionDir}` : null;
8431
8469
  const focusLine = sanitizeFocusLine(focus);
@@ -8438,7 +8476,7 @@ function buildRebuildAnchor(root, sessionName, activeMdPath, protocolMessages =
8438
8476
  `- Persistent cognitive trajectory — SESSION.md path: ${rel}`,
8439
8477
  ` (the cognitive trajectory's persistent body — stays in place through rebuilds)`,
8440
8478
  `- Read that SESSION.md first (goal/decisions/progress/unresolved), then continue from the last checkpoint.`,
8441
- `- Then read the handover scratch note: ${todoRel} (path: ${todoAbs}) — the previous self paused mid-task and left its in-flight items there. That file carries no format obligation and may be discarded at any time; it is NOT the authoritative state. If it is missing, infer the in-flight items from SESSION.md's latest progress entries.`,
8479
+ `- Handover note: read ${logRel} first — "${HANDOVER_NOTE_HEADING}" in the current generation, and the previous generation's \`LOG-<stamp>.md\` if this handover froze it. The previous carrier wrote its in-flight step there before it was retired.`,
8442
8480
  ...focusLine ? [`- Task focus: ${focusLine}`] : []
8443
8481
  ].join("\n");
8444
8482
  }
@@ -8781,7 +8819,7 @@ const RECONSTRUCT_TOKEN_THRESHOLD = 1e9;
8781
8819
  *
8782
8820
  * ⚠️ **必须显式给 keys**(`snapshot(session, ['tokenUsage'])`):`tokenUsage` 的 `wire`
8783
8821
  * **没有** `summary: false`(而 `contextPressure` 有)⇒ 走"摘要集"读法拿不到它。
8784
- * 这里直接点名要它,与 `keeper.ts` 的 `readContextPressure`(不传 keys)**走法不同**,不是笔误。
8822
+ * 这里直接点名要它,与 `cognitive-trajectory-lifecycle.ts` 的 `readContextPressure`(不传 keys)**走法不同**,不是笔误。
8785
8823
  *
8786
8824
  * @returns 读不到(投影未装配 / 会话无该格)⇒ `null`,**不回报 0**
8787
8825
  */
@@ -8830,18 +8868,21 @@ function shouldOfferReconstruct(ctx, session) {
8830
8868
  return cumulativeTokens(totals) >= RECONSTRUCT_TOKEN_THRESHOLD;
8831
8869
  }
8832
8870
  /**
8833
- * 达到阈值时注入的那句话(owner 给的语义,逐要素保留:**会话 id + "过于庞大" + 动作名**)。
8871
+ * **机械选路**(2026-11-16 owner 裁定):会话不参与、也不感知这个决定。
8834
8872
  *
8835
- * 🔴 与 `rebuildReminderText` 同一门禁口径(D64):**不给 token 数值**——
8836
- * "当前有多大"是模型无法据以行动的信息,"该调用 reconstruct"才是。
8837
- * ⚠️ 会话 id **必须给**:owner 原话里就有它,且它是唯一能让模型分辨"说的是哪条"的锚。
8873
+ * 判据只有两个量,且**顺序不可换**:
8874
+ * 1. **累计用量超限** ⇒ 必须 `new-log`。
8875
+ * 因为原地清空**不会让累计量回落** —— 同一条日志换个讲者还是那么大。
8876
+ * 2. 仅**上下文超限** ⇒ `in-place`(更便宜:不新建会话、不归档、id 不变)。
8877
+ *
8878
+ * 🔴 **同时触发时选 `new-log`**(裁定 1):反正累计量迟早要超,一次做到位,
8879
+ * 比"先原地清空、下一轮再另开"少一次中断。
8880
+ * ⛔ **LOG 大小不参与**:LOG 有机械轮转,永远不是交接触发器。
8838
8881
  */
8839
- function reconstructReminderText(dshSessionId) {
8840
- return [
8841
- `[RECONSTRUCT] The carrier session of this cognitive trajectory — ${dshSessionId} — has grown too large: its cumulative token usage passed the configured ceiling, so keeping it as the carrier costs every future turn.`,
8842
- "Call the reconstruct tool. It behaves exactly like rebuild with one difference: it creates a NEW conversation, binds this cognitive trajectory to it, injects the continue anchor there, and then archives the current session. Nothing is lost — SESSION.md stays where it is and the new carrier resumes from it.",
8843
- "Call it with --summary \"<content summary ≤20 chars>\" naming the next phase (same parameter as rebuild), optionally with --note \"<task focus ≤200 chars>\". It queues and runs when this turn ends, so finish the step you are in first."
8844
- ].join(" ");
8882
+ function selectHandoverPath(input) {
8883
+ if (input.totalOver) return "new-log";
8884
+ if (input.contextOver) return "in-place";
8885
+ return null;
8845
8886
  }
8846
8887
  let diagState = {
8847
8888
  lastTs: "",
@@ -9134,7 +9175,7 @@ function registerReconstructTurnHook(ctx) {
9134
9175
  });
9135
9176
  }
9136
9177
  //#endregion
9137
- //#region src/seams/keeper.ts
9178
+ //#region src/seams/cognitive-trajectory-lifecycle.ts
9138
9179
  const SCORES = {
9139
9180
  write: 3,
9140
9181
  edit: 3,
@@ -9212,10 +9253,23 @@ function reminderText(code) {
9212
9253
  * SESSION.md 末尾的段,改指**独立便签文件** `REBUILD-TODO_FILENAME`(轨迹目录下)——
9213
9254
  * 理由见该常量的头注(持久文件 vs 只用一次的交界材料必须分家)。
9214
9255
  */
9215
- function rebuildReminderText(escalated = false) {
9216
- const handover = ` Before rebuilding, write your current in-flight items (the exact step you are in the middle of, what is not finished yet, and what the next action is) into "${REBUILD_TODO_FILENAME}" in this cognitive trajectory's directory — create it if it does not exist. That file is a scratch note for the handover only: no format obligation, no archival duty, safe to discard at any time. The rebuilt conversation reads it first and continues from it.`;
9217
- if (escalated) return `${eventToken("limitMandatory")} Context usage has reached the configured rebuild threshold — you have been reminded repeatedly and have NOT called the cognitive_trajectory rebuild action. This is now mandatory: STOP at the current task step, preserve valuable cognition into the CCC skills (or write a new-skill proposal into SESSION.md), then call cognitive_trajectory rebuild immediately, passing --summary "<content summary ≤20 chars>" (required; the dsh session title is renamed to S###-YYYY-MM-DD-<summary> after rebuild).${handover} The conversation will be cleared and rebuilt in place; SESSION.md is the persistent cognitive trajectory and stays in place — identity continues from it. Do not continue working without rebuilding; this reminder persists until you call cognitive_trajectory rebuild.`;
9218
- return `${eventToken("limit")} Context usage has reached the configured rebuild threshold. This session is the rebuildable carrier of the cognitive trajectory: SESSION.md is the persistent body, this conversation is only a temporary work copy. Before rebuilding: if this conversation produced valuable cognition, revise the relevant existing skill of this CCC (structure it with eap); if a new skill is warranted, write a short proposal into SESSION.md for the user to review — do not create it yourself.${handover} ACT NOW: at the next natural pause (end of the current task step), call the cognitive_trajectory rebuild action — passing --summary "<content summary ≤20 chars>" describing the next work phase (required; the dsh session title is renamed to S###-YYYY-MM-DD-<summary> after rebuild) — to clear and rebuild this conversation: the current copy is discarded, identity continues from SESSION.md. If you are in the middle of an unbreakable step, continue it, then rebuild at its end. Do not ignore this; rebuild is the expected action, not an option.`;
9256
+ /**
9257
+ * 交接提醒(**rebuild 与 reconstruct 共用同一条文案**,2026-11-16 owner 裁定)。
9258
+ *
9259
+ * 🔴 为什么必须无差别:`rebuild`(原地清空、会话 id 不变)与 `reconstruct`
9260
+ * (另开日志、旧会话归档)对**会话本身**做的是同一件事——**把它换掉**。
9261
+ * 旧日志封不封存、id 变不变,是**机械层的账**,会话不需要知道,也不该据此改变行为。
9262
+ * 让模型看见两条不同文案 ⇒ 它要判断"我该调哪个" ⇒ 把一个机械决定变成一次思考,
9263
+ * 既浪费注意力,又可能选错。
9264
+ *
9265
+ * 选路由本文件的 `registerKeeper` 一侧机械完成(`selectHandoverPath` 只是纯函数),规则见那里的注释。
9266
+ *
9267
+ * ⚠️ 便签落点 = `LOG/LOG.md` 的 `## Handover note` 节(2026-11-16 裁定):
9268
+ * 它是**小步落盘的同一块地**,不另立文件;轮转时该节整节搬进新代出生头。
9269
+ */
9270
+ function handoverReminderText(escalated = false) {
9271
+ if (escalated) return `${eventToken("handover")} Repeatedly unacknowledged. STOP: write "## Handover note" into ${LOG_FILE_REL} (the exact step you are in, what comes next, what is unfinished), then call cognitive_trajectory rebuild --summary "<next phase ≤20 chars>" immediately.`;
9272
+ return `${eventToken("handover")} This carrier is being retired; the cognitive trajectory continues. Write your in-flight state into ${LOG_FILE_REL} under "## Handover note", then call cognitive_trajectory rebuild --summary "<next phase ≤20 chars>".`;
9219
9273
  }
9220
9274
  /** 读取会话 contextPressure 投影(sessionProjections 可选服务;未装配返回 null) */
9221
9275
  function readContextPressure(ctx, session) {
@@ -9322,42 +9376,11 @@ function readSessionMdMaxKB(root, configPaths, now = Date.now) {
9322
9376
  function cognitiveTrajectoryCompactionReminderText(input) {
9323
9377
  const { sizeKB, limitKB, mdPath, escalated = false } = input;
9324
9378
  const facts = `SESSION.md is ${sizeKB} KB (limit ${limitKB} KB): ${mdPath}`;
9325
- const principles = "Load eap (praxis eap) first, then refactor SESSION.md end to end under EAP: (1) E↑ — make every variable, boundary and directed relationship explicit; (2) R↓ — carry rationale and rejected alternatives, so the next self can rebuild the reasoning rather than only the conclusion, and move long evidence chains, logs and reference material out into separate files (e.g. AGENT_SESSIONS/<session>/references/*.md) linked from SESSION.md; (3) S↑ — a structure that regenerates the same way each time instead of a chronological transcript. The fixed sections are a contract with the harness: keep their order and headings, and rewrite everything inside them.";
9379
+ const principles = "Load eap (praxis eap) first, then restructure it as a layered abstraction tree — do not merely shorten it. Sort its contents BY NATURE (this is the whole point of the load): (1) process — attempts, dead ends, raw readings — belongs in LOG/LOG.md; (2) evidence and designs — long evidence chains, research, reference material — belongs in AGENT_SESSIONS/<session>/references/ and is reached by a pointer from SESSION.md; (3) judgement stays in the body — identity and boundaries, decisions with rationale and rejected options, milestones with evidence pointers, current state, pending rulings. Keep the fixed sections in this order — 身份与边界 / 权威锚点 / 工作纪律 / 决策 / 日志 / 当前状态 / 待 owner 裁决 — and rewrite everything inside them.";
9326
9380
  const frontmatterGuard = "Keep the YAML frontmatter at the top of the file exactly as it is — it carries this cognitive trajectory's skill declarations.";
9327
9381
  if (escalated) return `${eventToken("compaction")} ${facts} — you have been reminded repeatedly and have NOT compacted SESSION.md. This is now mandatory: STOP the current task step, load eap (praxis eap), refactor SESSION.md end to end, then resume. ${principles} ${frontmatterGuard} This reminder persists until the file is under the limit.`;
9328
9382
  return `${eventToken("compaction")} ${facts}. Pause the current work and compact this cognitive trajectory's log (SESSION.md) before continuing — that log is the persistent body of this cognitive trajectory, and its size is operational entropy (H_op) the container pays on every read. ${principles} ${frontmatterGuard} After rewriting, resume the paused work; this reminder stops once the file is under the limit.`;
9329
9383
  }
9330
- /** 连续超限轮数达此值 → 语气升级(对齐 COMPACTION_ESCALATE_AFTER / REBUILD_ESCALATE_AFTER) */
9331
- const REBUILD_TODO_ESCALATE_AFTER = 3;
9332
- const rebuildTodoStates = /* @__PURE__ */ new Map();
9333
- /**
9334
- * 交界便签超限提醒文案(v1.49.0)。
9335
- *
9336
- * ## 与 SESSION.md 档的**语义差别**(刻意,不是疏漏)
9337
- *
9338
- * | | SESSION.md 超限(`cognitiveTrajectoryCompactionReminderText`) | 便签超限(本条) |
9339
- * |---|---|---|
9340
- * | 动作 | **重写**(compaction) | **清理/丢弃**(prune) |
9341
- * | 结构义务 | 保 EAP 骨架 + 4 条重写原则 + frontmatter 护栏 | **无** |
9342
- * | 强度 | 升级后**强制**("STOP…必须先重写") | 升级后**语气加重,但动作仍只是"清理"** |
9343
- * | 授权 | — | 🔴 **明确授权整份删除** |
9344
- *
9345
- * ## 归属(D23)
9346
- * 机制(文件名 / 上限 / 注入时机)归 **ACC**;**写什么、怎么组织、何时丢**归 **CCC**。
9347
- * 🔴 owner 裁决(逐字):*"rebuild 提示 Agent 去写,清空我们就不干涉了,只管最大量"* ⇒
9348
- * **ACC 只提醒,不做任何写/删/归档操作**(自动删 = 数据丢失风险:rebuild 时序上新我还没读就被删)。
9349
- *
9350
- * ## 为什么要求"参照 eap"
9351
- * owner 裁决(逐字):*"不规定,但要求参照 eap 来编写(这样质量会好点)"* ⇒
9352
- * **不规定内部结构**(不给骨架),但**要求按 EAP 写**(显式 / 可重建 / 稳定)。
9353
- */
9354
- function rebuildTodoReminderText(input) {
9355
- const { sizeKB, limitKB, mdPath, escalated = false } = input;
9356
- const facts = `${REBUILD_TODO_FILENAME} is ${sizeKB} KB (limit ${limitKB} KB): ${mdPath}`;
9357
- const action = "This file is a scratch note for the rebuild handover — it carries no archival duty and you may discard it wholesale at any time. Prune it now, writing in the spirit of eap (praxis eap): (1) delete what is already done; (2) delete what has been superseded; (3) delete what is already recorded in SESSION.md — that file is the cognitive trajectory's persistent body, this one only carries what the next self needs once. Do not restructure it into a formal document: the only mechanical constraint on this file is its size.";
9358
- if (escalated) return `${eventToken("scratchPrune")} ${facts} — you have been reminded repeatedly and have NOT pruned it. Prune it now. ${action} This reminder persists until the file is under the limit.`;
9359
- return `${eventToken("scratchPrune")} ${facts}. ${action} This reminder stops once the file is under the limit.`;
9360
- }
9361
9384
  /** 每 agent 一个跟踪器(进程内存态,agent token 维度) */
9362
9385
  const trackers = /* @__PURE__ */ new Map();
9363
9386
  /** 连续超阈值轮数达此值 → 升级为 [TRAJECTORY-ESCALATED] 强制语气(此后持续升级催,直到 rebuild) */
@@ -9400,20 +9423,29 @@ function registerKeeper(ctx, opts = {}) {
9400
9423
  if (participatesRebuild) {
9401
9424
  const session = exec.agent?.session;
9402
9425
  if (session) {
9426
+ const thresholdK = readSimpleSettings().rebuildThresholdK;
9403
9427
  const pressure = readContextPressure(ctx, session);
9404
- if (pressure && pressure.projectedTokens > 0) {
9405
- const thresholdK = readSimpleSettings().rebuildThresholdK;
9406
- if (pressure.projectedTokens >= thresholdK * 1e3) {
9407
- const key = exec.agent?.session?.id ?? "global";
9408
- const st = rebuildReminderStates.get(key) ?? { consecutive: 0 };
9409
- st.consecutive += 1;
9410
- const escalated = st.consecutive >= REBUILD_ESCALATE_AFTER;
9411
- blocks.push({
9412
- type: "text",
9413
- text: rebuildReminderText(escalated)
9414
- });
9415
- rebuildReminderStates.set(key, st);
9416
- }
9428
+ const contextOver = pressure !== null && pressure.projectedTokens > 0 && pressure.projectedTokens >= thresholdK * 1e3;
9429
+ let totalOver = false;
9430
+ try {
9431
+ totalOver = shouldOfferReconstruct(ctx, session);
9432
+ } catch {}
9433
+ if (contextOver || totalOver) {
9434
+ const key = exec.agent?.session?.id ?? "global";
9435
+ const st = rebuildReminderStates.get(key) ?? { consecutive: 0 };
9436
+ st.consecutive += 1;
9437
+ rebuildReminderStates.set(key, st);
9438
+ st.path = selectHandoverPath({
9439
+ contextOver,
9440
+ totalOver
9441
+ }) ?? void 0;
9442
+ blocks.push({
9443
+ type: "text",
9444
+ text: handoverReminderText(st.consecutive >= REBUILD_ESCALATE_AFTER)
9445
+ });
9446
+ } else {
9447
+ const key = exec.agent?.session?.id ?? "global";
9448
+ rebuildReminderStates.delete(key);
9417
9449
  }
9418
9450
  }
9419
9451
  }
@@ -9440,39 +9472,6 @@ function registerKeeper(ctx, opts = {}) {
9440
9472
  } else compactionStates.delete(scope);
9441
9473
  }
9442
9474
  }
9443
- if (trajectoryConstraintParticipates(root, sessionId, "session")) {
9444
- const scope = sessionId ?? "global";
9445
- const session = exec.agent?.session;
9446
- const mdPath = resolveActiveSessionMdPath(root, scope, session);
9447
- const todoPath = mdPath ? join(dirname(mdPath), REBUILD_TODO_FILENAME) : null;
9448
- const size = todoPath ? readFileSize(todoPath) : null;
9449
- if (todoPath && size !== null && size > 10240) {
9450
- const st = rebuildTodoStates.get(scope) ?? { consecutive: 0 };
9451
- st.consecutive += 1;
9452
- blocks.push({
9453
- type: "text",
9454
- text: rebuildTodoReminderText({
9455
- sizeKB: Math.round(size / 1024),
9456
- limitKB: 10,
9457
- mdPath: todoPath,
9458
- escalated: st.consecutive >= REBUILD_TODO_ESCALATE_AFTER
9459
- })
9460
- });
9461
- rebuildTodoStates.set(scope, st);
9462
- } else rebuildTodoStates.delete(scope);
9463
- }
9464
- if (participatesRebuild) {
9465
- const session = exec.agent?.session;
9466
- if (session) try {
9467
- if (shouldOfferReconstruct(ctx, session)) {
9468
- const id = exec.agent?.session?.id ?? "";
9469
- blocks.push({
9470
- type: "text",
9471
- text: reconstructReminderText(id)
9472
- });
9473
- }
9474
- } catch {}
9475
- }
9476
9475
  if (blocks.length === 0) return downstream;
9477
9476
  const blockTexts = blocks.map((b) => b.text ?? "");
9478
9477
  const reminderAll = toMessage(makeInjection({
@@ -45,10 +45,26 @@ export declare const DEFAULT_SUPPRESSED_SOURCES: string[];
45
45
  export declare const DEFAULT_COMPACTION_TOOLS: string[];
46
46
  /**
47
47
  * 协议级「假首轮」话语序列(用户确认固化,2026-08-24 S142):任何 CCC 在抽象层都是
48
- * 宁静号/ACC——假首轮话语统一,无 CCC 配置面。两轮递进:
49
- * ① ACC 身份 + EAP 原则 + we/us 人称 + 先锚定后行动
50
- * ② 协作协议 5 条 + acknowledge 要求(只回确认,不做事)
51
- * 文本 = 原 home-serenity CCC 配置,随零配置化固化进代码。
48
+ * 宁静号/ACC——假首轮话语统一,无 CCC 配置面。
49
+ *
50
+ * 🔵 **2026-11-16 合并:两条 → 一条**(owner 令「合并吧」)。
51
+ *
52
+ * 判据(为什么合并安全 · 逐条对读过系统提示词**才**动的手):
53
+ * · 本文件这两条**只出现一次**(`hasUserMessageHistory` 守卫:有真人说话就不再插),
54
+ * 而系统提示词里的 EAP 块**每轮注入** ⇒ 两者不构成第二真相源,但确实**功能重叠**。
55
+ * · 重叠的那一块 = EAP 是什么。系统提示词的 `eapBlock()` 给的是**更详细的操作定义**
56
+ * (E↑/R↓/S↑ 各自查什么)⇒ 这里**不必复述**,压成一句指认即可。
57
+ * · ⛔ **不可省的四处,条条只在 bootstrap 有**:
58
+ * ① `personal pronoun is us/we` —— 系统提示词零处(grep 过)
59
+ * ② `We anchor first, then act` —— 同上
60
+ * ③ 协作五条 —— 系统提示词零处
61
+ * ④ 身份句 `operator agent of Serenity…ACC protocol` —— 开场语境
62
+ * · `Please simply reply "acknowledge"` 原本**两条各写一遍**(重复两次),合并后一处。
63
+ *
64
+ * 🔴 **为什么"合并"而不是"删第一条"**:删掉第一条会连同 ①②③④ 一起消失;
65
+ * 合并只是去掉 EAP 的**展开复述**与重复的 acknowledge 指令,语义面零损失。
66
+ * ⚠️ 轮数因此 2 → 1:`requiredSignals` 与 `pendingFakeTurns.remaining` 都由
67
+ * `DEFAULT_FAKE_INITIAL_MESSAGES.length` 派生,**跟着自动变**,无需另改。
52
68
  */
53
69
  export declare const DEFAULT_FAKE_INITIAL_MESSAGES: string[];
54
70
  /**
@@ -139,8 +155,10 @@ interface PromotionTracker {
139
155
  /**
140
156
  * 构建一个 epoch 感知晋升跟踪器(纯逻辑,可单测)。
141
157
  * requiredSignals:晋升所需信号数(boundary 后累计;默认 1)。
142
- * 多轮锚定(v4):两轮递进锚定时 requiredSignals = 锚定轮数——
143
- * 每条锚定回复(assistant/message)计一次,最后一条回复后晋升。
158
+ * 多轮锚定(v4):N 轮递进锚定时 requiredSignals = N——每条锚定回复
159
+ * (assistant/message)计一次,最后一条回复后晋升。
160
+ * 🔵 2026-11-16:`DEFAULT_FAKE_INITIAL_MESSAGES` 由两条合并为一条 ⇒ 缺省 N = **1**
161
+ * (仍由 `.length` 派生,不写死;本函数对 N 的语义未变)。
144
162
  *
145
163
  * maxRoundsFallback:**轮次兜底**(v1.19.3 修复 responses API 兼容)。
146
164
  * 某些模型/协议(如 opencode-go-responses)的会话可能不产生标准
@@ -1,5 +1,13 @@
1
1
  /**
2
- * keeper.ts — 拦截缝:session-keeper(DCP 提醒,post-execute observe-and-enrich)
2
+ * cognitive-trajectory-lifecycle.ts — 拦截缝:**认知轨迹生命周期**提醒(post-execute observe-and-enrich)
3
+ *
4
+ * 🔵 **2026-11-16 改名(原 `seams/keeper.ts`)**:本文件的职责在 v1.13x 后已经**只剩轨迹生命周期**——
5
+ * 计分 / 交接 / 上下文压缩 / rebuild 提醒,全部围绕"这条认知轨迹该怎么续下去"。
6
+ * `keeper` 是沿袭 opencode-serenity-plugin 的旧名(session-keeper),**名不副实** ⇒ 改成本名。
7
+ *
8
+ * 🔴 **改名边界(重要,别顺手改)**:只改**文件路径与模块 id**。
9
+ * ⛔ **不改** `cognitiveTrajectory.keeper`(配置键)与 `'keeper'`(轨迹约束子集维度)——
10
+ * 那两个是**外部契约**:用户 `trajectory-constraint.json` 里写着它们,改一名会让所有存量配置静默失效。
3
11
  *
4
12
  * 照 dsh-external/tool-failure-guard 模式:先检测计分,`next()` 委托,
5
13
  * 再把提醒折叠到返回决策的 additionalContexts(绝不 veto)。
@@ -10,6 +18,7 @@
10
18
  * 提醒要求模型回应 [COGNITIVE-TRAJECTORY-ASSISTANT-recorded-{code}] 确认(DCP 模式)。
11
19
  */
12
20
  import type { Context } from 'cordis';
21
+ import { type HandoverPath } from '../trajectory/reconstruct.js';
13
22
  export declare function scoreTool(toolName: string): number;
14
23
  export declare class KeeperTracker {
15
24
  private threshold;
@@ -55,7 +64,21 @@ export declare function reminderText(code: string): string;
55
64
  * SESSION.md 末尾的段,改指**独立便签文件** `REBUILD-TODO_FILENAME`(轨迹目录下)——
56
65
  * 理由见该常量的头注(持久文件 vs 只用一次的交界材料必须分家)。
57
66
  */
58
- export declare function rebuildReminderText(escalated?: boolean): string;
67
+ /**
68
+ * 交接提醒(**rebuild 与 reconstruct 共用同一条文案**,2026-11-16 owner 裁定)。
69
+ *
70
+ * 🔴 为什么必须无差别:`rebuild`(原地清空、会话 id 不变)与 `reconstruct`
71
+ * (另开日志、旧会话归档)对**会话本身**做的是同一件事——**把它换掉**。
72
+ * 旧日志封不封存、id 变不变,是**机械层的账**,会话不需要知道,也不该据此改变行为。
73
+ * 让模型看见两条不同文案 ⇒ 它要判断"我该调哪个" ⇒ 把一个机械决定变成一次思考,
74
+ * 既浪费注意力,又可能选错。
75
+ *
76
+ * 选路由本文件的 `registerKeeper` 一侧机械完成(`selectHandoverPath` 只是纯函数),规则见那里的注释。
77
+ *
78
+ * ⚠️ 便签落点 = `LOG/LOG.md` 的 `## Handover note` 节(2026-11-16 裁定):
79
+ * 它是**小步落盘的同一块地**,不另立文件;轮转时该节整节搬进新代出生头。
80
+ */
81
+ export declare function handoverReminderText(escalated?: boolean): string;
59
82
  /** 读取会话 contextPressure 投影(sessionProjections 可选服务;未装配返回 null) */
60
83
  export declare function readContextPressure(ctx: Context, session: unknown): {
61
84
  projectedTokens: number;
@@ -120,51 +143,6 @@ export declare function cognitiveTrajectoryCompactionReminderText(input: {
120
143
  mdPath: string;
121
144
  escalated?: boolean;
122
145
  }): string;
123
- /**
124
- * 交界便签体积上限(KB)—— **硬编码,刻意不设配置键**。
125
- *
126
- * 🔴 owner 2026-09-26 裁决(逐字):*"不需要设定,很多设定项我想砍掉了,好的功能用久了就发现
127
- * 离不开,就不需要了"* ⇒ **不提供 `sessionKeeper.rebuildTodoMaxKB`**(设计件 Q4 的原倾向被否)。
128
- * 对照:SESSION.md 的上限**保留可配置**(既有面,本版不动)。
129
- */
130
- export declare const DEFAULT_REBUILD_TODO_MAX_KB = 10;
131
- interface RebuildTodoState {
132
- /** 连续超限轮数(文件降回限内即清零 → 清理完成后提醒自动停止) */
133
- consecutive: number;
134
- }
135
- /** 测试/调试:查看交界便签超限提醒状态 */
136
- export declare function rebuildTodoStateSnapshot(): ReadonlyMap<string, RebuildTodoState>;
137
- /** 会话销毁/测试重置:清理超限计数(防 per-会话 Map 无界增长) */
138
- export declare function forgetRebuildTodoState(scope: string): void;
139
- /** 测试辅助:清空交界便签提醒状态 */
140
- export declare function __resetRebuildTodoForTest(): void;
141
- /**
142
- * 交界便签超限提醒文案(v1.49.0)。
143
- *
144
- * ## 与 SESSION.md 档的**语义差别**(刻意,不是疏漏)
145
- *
146
- * | | SESSION.md 超限(`cognitiveTrajectoryCompactionReminderText`) | 便签超限(本条) |
147
- * |---|---|---|
148
- * | 动作 | **重写**(compaction) | **清理/丢弃**(prune) |
149
- * | 结构义务 | 保 EAP 骨架 + 4 条重写原则 + frontmatter 护栏 | **无** |
150
- * | 强度 | 升级后**强制**("STOP…必须先重写") | 升级后**语气加重,但动作仍只是"清理"** |
151
- * | 授权 | — | 🔴 **明确授权整份删除** |
152
- *
153
- * ## 归属(D23)
154
- * 机制(文件名 / 上限 / 注入时机)归 **ACC**;**写什么、怎么组织、何时丢**归 **CCC**。
155
- * 🔴 owner 裁决(逐字):*"rebuild 提示 Agent 去写,清空我们就不干涉了,只管最大量"* ⇒
156
- * **ACC 只提醒,不做任何写/删/归档操作**(自动删 = 数据丢失风险:rebuild 时序上新我还没读就被删)。
157
- *
158
- * ## 为什么要求"参照 eap"
159
- * owner 裁决(逐字):*"不规定,但要求参照 eap 来编写(这样质量会好点)"* ⇒
160
- * **不规定内部结构**(不给骨架),但**要求按 EAP 写**(显式 / 可重建 / 稳定)。
161
- */
162
- export declare function rebuildTodoReminderText(input: {
163
- sizeKB: number;
164
- limitKB: number;
165
- mdPath: string;
166
- escalated?: boolean;
167
- }): string;
168
146
  interface KeeperRegistration {
169
147
  /** 缺省阈值(serenity.json sessionKeeper.threshold 优先,其次此值) */
170
148
  defaultThreshold?: number;
@@ -173,8 +151,10 @@ interface KeeperRegistration {
173
151
  }
174
152
  /** v1.23.3 重建提醒状态:agentId → 连续超阈值累计轮数(进程内存态) */
175
153
  interface RebuildReminderState {
176
- /** 连续超阈值未 rebuild 的累计轮数(达阈值 → 升级强制提醒) */
154
+ /** 连续超阈值未交接的累计轮数(达阈值 → 升级强制提醒) */
177
155
  consecutive: number;
156
+ /** 本呆机械选定的交接路径(⛔ 不进注入正文,只供诊断与测试观测) */
157
+ path?: HandoverPath;
178
158
  }
179
159
  /** 测试/调试:查看重建提醒状态 */
180
160
  export declare function rebuildReminderStateSnapshot(): ReadonlyMap<string, RebuildReminderState>;
@@ -2176,13 +2176,13 @@ function sessionBlock(root, scope = DEFAULT_SESSION_SCOPE) {
2176
2176
  `Active session: ${active.sessionId} — ${active.dirName} (this session is the rebuildable carrier of the cognitive trajectory)`,
2177
2177
  `SESSION.md path: ${active.mdPath} (the cognitive trajectory's persistent body — stays in place through rebuilds)`,
2178
2178
  "",
2179
- "Rules (SESSION.md is the cognitive trajectory log — keep its format & granularity fixed):",
2179
+ "Rules (SESSION.md is the cognitive trajectory BODY — judgement only; keep its format & granularity fixed):",
2180
2180
  " • Write only when a MILESTONE landed or a DECISION was made — not every round",
2181
2181
  " • One entry = one abstraction level, at the highest one that can express it:",
2182
2182
  " identity/anchors (rare) › decision (one line + rationale/rejected) › milestone",
2183
- " (one line + an evidence pointer, e.g. a commit id). Execution detail — test",
2184
- " counts, coverage decimals, per-file readings, step narration — belongs in the",
2185
- " COMMIT MESSAGE, not here",
2183
+ " (one line + an evidence pointer, e.g. a commit id). Process detail — attempts,",
2184
+ " dead ends, raw readings, step narration — belongs in LOG/LOG.md, written as it",
2185
+ " happens. Only the diff-level nitty-gritty goes in the COMMIT MESSAGE. Not here.",
2186
2186
  " • Never write a value that changes by the act of writing it (file size; the hash",
2187
2187
  " of the commit containing this edit)",
2188
2188
  " • Fixed sections, in this order: 身份与边界 / 权威锚点 / 工作纪律 / 决策 / 日志 /",
@@ -2204,7 +2204,7 @@ function sessionBlock(root, scope = DEFAULT_SESSION_SCOPE) {
2204
2204
  "task=10, read/grep/glob/msm=1, +1 per minute) and reminds you with a",
2205
2205
  "[COGNITIVE-TRAJECTORY-ASSISTANT · CHECKPOINT] message when the threshold is reached. On every such",
2206
2206
  "reminder you MUST reply with the exact ACK code:",
2207
- " [COGNITIVE-TRAJECTORY-ASSISTANT-recorded-{code}] — if you recorded progress to SESSION.md",
2207
+ " [COGNITIVE-TRAJECTORY-ASSISTANT-recorded-{code}] — if you recorded progress: SESSION.md for judgement, LOG/LOG.md for process",
2208
2208
  " [COGNITIVE-TRAJECTORY-ASSISTANT-skipped-{code}] — if nothing to record this round",
2209
2209
  "Do not ignore the reminder; do not stop ongoing work. Codes are single-use;",
2210
2210
  "never reuse a prior code.",
@@ -23,21 +23,14 @@
23
23
  export declare const EVENT_LABEL: {
24
24
  /** 计分同步提醒(原 TRAJECTORY-STEWARD) */
25
25
  readonly checkpoint: "CHECKPOINT";
26
- /** 上下文极限重建提醒(原 TRAJECTORY;LIMIT 替代被否的 BOSS——自然词) */
27
- readonly limit: "LIMIT";
28
- /** 极限强制升级(原 TRAJECTORY-ESCALATED) */
29
- readonly limitMandatory: "LIMIT · MANDATORY";
26
+ /** 交接提醒(rebuild ≡ reconstruct 共用;2026-11-16 由 `limit`/`limitMandatory` 合并而来) */
27
+ readonly handover: "HANDOVER";
30
28
  /** 重建锚点头部(原 TRAJECTORY-REBUILD) */
31
29
  readonly rebuild: "REBUILD";
32
30
  /** 敏感输出边界守卫(原 SERENITY OUTPUT GUARD) */
33
31
  readonly guard: "BOUNDARY GUARD";
34
32
  /** SESSION.md 体积超限重写提醒(v1.31.1,S142 用户需求) */
35
33
  readonly compaction: "LOGBOOK COMPACTION";
36
- /** **交界便签(REBUILD-TODO.md)体积超限清理提醒**(v1.49.0,owner 2026-09-26 需求)。
37
- *
38
- * 🔴 **刻意与 `compaction` 分开**:那条要求"**重写 SESSION.md 并保留 EAP 骨架**",
39
- * 本条只要求"**清理便签**"——共用一个 token 会让模型误以为要动 SESSION.md。 */
40
- readonly scratchPrune: "SCRATCH PRUNE";
41
34
  };
42
35
  /** 家族标识(所有动态注入统一前缀) */
43
36
  export declare const ASSISTANT_PREFIX = "COGNITIVE-TRAJECTORY-ASSISTANT";
@@ -47,24 +40,23 @@ export declare function eventToken(event: keyof typeof EVENT_LABEL): string;
47
40
  export declare const ACK_PREFIX = "COGNITIVE-TRAJECTORY-ASSISTANT-recorded";
48
41
  export declare const ACK_SKIP_PREFIX = "COGNITIVE-TRAJECTORY-ASSISTANT-skipped";
49
42
  /**
50
- * rebuild 交界便签的**文件名**(v1.49.0;owner 2026-09-26 需求)。
43
+ * 交接便签的**落点**:`LOG/LOG.md` 里的节名(2026-11-16 owner 裁定)。
51
44
  *
52
- * ## 它取代了什么(owner 原话:*"砍掉 in-flight,这正是目的"*)
53
- * v1.31.1 的交界协议要求把手头事项写进 **SESSION.md 末尾**的 `## In-flight (rebuild handover)` 段。
54
- * 实测的代价(S142 自身取证):In-flight 段曾积 **12 块**(含多份**已被取代**的交接),
55
- * 而 SESSION.md 是**有格式义务**的持久文件(7 段固定 + 粒度受 EAP 约束)⇒
56
- * ① 持久文件被临时物污染 ② 每次整理都要付"压缩+归档+保真"三件套(该文件曾达 292 KB)。
57
- *
58
- * ⇒ 分家:**只用一次的交界材料**写进这份**临时便签**(无格式义务、无留档义务、可随时丢弃)。
45
+ * ## 它取代了什么
46
+ * v1.49.0 曾把交界材料分家到**独立文件** `REBUILD-TODO.md`。v1.136.0 起 LOG 有了
47
+ * **机械轮转**(`carrier-log.ts`),于是那个独立文件成了第三种住处——而它要装的东西
48
+ * ("我卡在哪一步")本质是**过程留痕**,与 LOG 同性质、同寿命、同策展度。
49
+ * ⇒ 2026-11-16 owner 裁定:**整体删掉独立文件**,便签住进 LOG 的一节,
50
+ * 轮转时**整节搬运**进新代出生头(否则旧代冻结、新代空白 ⇒ 交接断开)。
59
51
  *
60
52
  * ## 🔴 三处引用同一常量(单一真相源)
61
- * **写侧** = `seams/keeper.ts` 的 `rebuildReminderText()`|**读侧** = `trajectory/rebuild.ts` 的重建锚点|
62
- * **体积提醒** = `seams/keeper.ts` 的 `rebuildTodoReminderText()`。
63
- * 文件名一旦漂移,写侧写的东西读侧就找不到 —— **且没有任何机械信号会报警**。
64
- *
65
- * 🔴 **不得改名**(owner 已具名)。形态 = **固定文件名**(人读友好;比照旧 IN_FLIGHT_HEADING 的取舍)。
53
+ * **写侧** = `seams/cognitive-trajectory-lifecycle.ts` 的 `handoverReminderText()`|**读侧** = `trajectory/rebuild.ts` 的重建锚点|
54
+ * **搬运** = `trajectory/carrier-log.ts` 的 `rotateCarrierLog()`。
55
+ * 节名一旦漂移,写侧写的东西读侧就找不到,**且没有任何机械信号会报警**。
66
56
  */
67
- export declare const REBUILD_TODO_FILENAME = "REBUILD-TODO.md";
57
+ export declare const HANDOVER_NOTE_HEADING = "## Handover note";
58
+ /** 交接便签在 LOG 里的相对路径(给人读的提示用) */
59
+ export declare const LOG_FILE_REL = "LOG/LOG.md";
68
60
  /** 风格档位:plain(默认,精确文本)/ metaphor(借星舰词——产品隐喻非游戏词) */
69
61
  type CognitiveTrajectoryStyle = 'plain' | 'metaphor';
70
62
  /**
@@ -76,6 +76,16 @@ export declare function frozenLogName(now: Date): string;
76
76
  * 若按裸字节判非空,**刚开的新代立刻会被判为"有内容可冻结"** ⇒ 产生一堆只有出生头的垃圾归档。
77
77
  */
78
78
  export declare function isEffectivelyEmpty(text: string): boolean;
79
+ /**
80
+ * 从一份 LOG 正文里抽出 `## Handover note` 整节(含标题,到下一个同级或更高级标题为止)。
81
+ *
82
+ * 🔴 **为什么不抽就轮转 = 交接断开**:轮转把整份 `LOG.md` `mv` 成冻结代,新代是空白的。
83
+ * 若在办状态写在旧代里,新会话读新代 ⇒ **读不到** ⇒ 交接失败,且**没有任何报错**。
84
+ * 这与"便签必须被交接后的会话完整读到"是同一条判据(2026-11-16 owner 裁定)。
85
+ *
86
+ * @returns 该节全文(含标题、去掉尾部空行);没有该节 ⇒ `null`
87
+ */
88
+ export declare function extractHandoverNote(text: string): string | null;
79
89
  /** 读一个轨迹目录的日志状态(只读,不改任何东西)。 */
80
90
  export declare function readCarrierLogState(trajectoryDir: string): CarrierLogState;
81
91
  /** 轮转结果(**回执只说明"我做了什么",不说明"效果达成了"**)。 */
@@ -12,7 +12,7 @@
12
12
  * |---|---|---|
13
13
  * | 1 | 累计输入 token > 1000m | 阈值 = **1e9**(owner 裁「我这有好几个十亿的」) |
14
14
  * | 2 | 隐藏 tool 自动出现 | **`ctx.tools.register(def, { when })`** —— 不是 restrict,见下 |
15
- * | 3 | 提示词注入 | `seams/keeper.ts` 每轮超阈值注入一句,指明会话 id 与动作 |
15
+ * | 3 | 提示词注入 | `seams/cognitive-trajectory-lifecycle.ts` 每轮超阈值注入一句,指明会话 id 与动作 |
16
16
  * | 4 | 与 rebuild 同语义、区别 = 先建新会话 → 绑轨迹 → 注入继续 → 归档旧的 | 本文件 |
17
17
  *
18
18
  * ## 🔴 「累计输入 token」到底是哪个量(**判错会让功能在最需要的会话上永不触发**)
@@ -98,7 +98,7 @@ export interface TokenTotals {
98
98
  *
99
99
  * ⚠️ **必须显式给 keys**(`snapshot(session, ['tokenUsage'])`):`tokenUsage` 的 `wire`
100
100
  * **没有** `summary: false`(而 `contextPressure` 有)⇒ 走"摘要集"读法拿不到它。
101
- * 这里直接点名要它,与 `keeper.ts` 的 `readContextPressure`(不传 keys)**走法不同**,不是笔误。
101
+ * 这里直接点名要它,与 `cognitive-trajectory-lifecycle.ts` 的 `readContextPressure`(不传 keys)**走法不同**,不是笔误。
102
102
  *
103
103
  * @returns 读不到(投影未装配 / 会话无该格)⇒ `null`,**不回报 0**
104
104
  */
@@ -119,6 +119,24 @@ export declare function cumulativeTokens(totals: TokenTotals): number;
119
119
  export declare function supportsActivation(): boolean;
120
120
  /** 该会话此刻是否已达阈值(`when` 与 keeper 提醒**共用**这一条判据) */
121
121
  export declare function shouldOfferReconstruct(ctx: unknown, session: unknown): boolean;
122
+ /** 交接走哪条路(`in-place` = 原地清空;`new-log` = 另开日志并归档旧的) */
123
+ export type HandoverPath = 'in-place' | 'new-log';
124
+ /**
125
+ * **机械选路**(2026-11-16 owner 裁定):会话不参与、也不感知这个决定。
126
+ *
127
+ * 判据只有两个量,且**顺序不可换**:
128
+ * 1. **累计用量超限** ⇒ 必须 `new-log`。
129
+ * 因为原地清空**不会让累计量回落** —— 同一条日志换个讲者还是那么大。
130
+ * 2. 仅**上下文超限** ⇒ `in-place`(更便宜:不新建会话、不归档、id 不变)。
131
+ *
132
+ * 🔴 **同时触发时选 `new-log`**(裁定 1):反正累计量迟早要超,一次做到位,
133
+ * 比"先原地清空、下一轮再另开"少一次中断。
134
+ * ⛔ **LOG 大小不参与**:LOG 有机械轮转,永远不是交接触发器。
135
+ */
136
+ export declare function selectHandoverPath(input: {
137
+ contextOver: boolean;
138
+ totalOver: boolean;
139
+ }): HandoverPath | null;
122
140
  /**
123
141
  * 达到阈值时注入的那句话(owner 给的语义,逐要素保留:**会话 id + "过于庞大" + 动作名**)。
124
142
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgroup/dsh-serenity-hooks",
3
- "version": "1.136.5",
3
+ "version": "1.137.1",
4
4
  "description": "宁静号 ACC harness(Native Cordis 插件)——给 DeepSeek Harness 装一个「AI 工作区」:14 个工具(container_fs/cognitive_trajectory/dashboard/container_git/msm/praxis/ontology/serenity-skill-creator/localstore/container_admin/browser_slot;另三个 im-bridge/diagram/reconstruct 按条件出现)+ 机械约束(安全模式/工作区围墙/密钥守卫/对外输出守卫)+ 认知轨迹日志与原地重建 + 网页登录入口/IM 桥/认知轨迹唤醒注册表 + 浏览器槽位管理(≤20 个独立 profile 的 Chrome 槽位,带占用归属与异常时向所属会话反向注入提醒)。轨迹声明 = 轨迹目录下的 trajectory.json(约束面 + 旧标识 uid + CRO 机器绑定 cro.host;旧名 trajectory-constraint.json / skiff.json 仍在读取族里);轨迹提示词 = 轨迹目录下的 PROMPT.md(一条轨迹「是谁、按什么章程工作」,所有轨迹通用,追加在容器层与质量层之后,不替换它们)。适配 DSH 0.1.7-rc.1 / 0.2.0-rc.1 / 0.2.1-rc.1(三档)。",
5
5
  "license": "MIT",
6
6
  "repository": {