@shgroup/dsh-serenity-hooks 1.137.11 → 1.137.13

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/lib/index.js CHANGED
@@ -4,16 +4,15 @@ import { a as findSerenityRoot$1, d as readCccName, g as resolveInside, l as pat
4
4
  import { A as useSession, C as resolveSessionByTitle, D as showSession, E as setActiveSessionInfo, F as isoLocal, I as localFileStamp, M as TRAJECTORY_LEGACY_FILENAMES, O as summarize, S as readTrajectoryUid, T as sessionsRoot, _ as listSessions, b as parseTrajectoryCode, c as UID_FILENAME, d as createSession, j as TRAJECTORY_FILENAME, k as trajectoryDescOf, l as archiveSession, m as getActiveSessionInfo, o as COGNITIVE_TRAJECTORY_ACTIONS, p as findSession, u as clearActiveSessionInfo, v as namingTitleFor, w as sessionEvents, y as parseSessionContextFromEvents } from "./bind-file-Dy6Qmm7z.js";
5
5
  import { n as checkLocalstoreGitCompliance, o as readStore, s as runLocalStore, t as LOCALSTORE_SCOPES } from "./service-BRUHmVFn.js";
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
- import { a as loadMsmEntries, c as docsPointer, i as findEntry, l as setWeixinSendEndpoint, n as CCC_CONFIG_REFERENCE, o as runMsm, s as runMsmAsync, t as ACC_CATALOG } from "./service-DF23HvHY.js";
7
+ import { C as docsPointer, S as runMsmAsync, _ as CCC_CONFIG_REFERENCE, a as setSafeMode, b as loadMsmEntries, d as forgetNonCccToolVisibility, g as ACC_CATALOG, h as forgetToolVisibility, i as readDshVersion, m as syncToolVisibility, n as summarizeHostContract, o as listOpencodeSkillDirs, p as registerGuards, r as getStatus, s as loadOpencodeSkill, t as hostContractReport, w as setWeixinSendEndpoint, x as runMsm, y as findEntry } from "./contract-B0uRA4S2.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-CRcW3ifg.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-CA4rNuiV.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-BMaTNjK1.js";
10
10
  import { 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-ME-aoZVl.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-pOtONqPy.js";
12
12
  import { i as hostAliveProbe, n as readSimpleSettings, r as registerSettingsSection } from "./settings-YC-csZus.js";
13
13
  import { a as readFeishuCredential, c as readWeixinSettings, d as weixinInboundDir, f as weixinSessionIdForTrajectory, i as matchWeixinRoute, n as extractWeixinText, r as hasVoiceItem, s as readWeixinCredential, t as extractWeixinMedia, u as sanitizeFileName$1 } from "./route-DcUo9alz.js";
14
14
  import { i as runImBridge, n as isImWiredTrajectory, r as registerImChannel, t as imChannelIds } from "./channels-Covd8vLQ.js";
15
- import { a as loadOpencodeSkill, 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 } from "./status-BwfDsakn.js";
16
- import { a as ACK_PREFIX, c as eventToken, i as resolveSessionMdPath, l as DEFAULT_FAKE_INITIAL_MESSAGES, o as ASSISTANT_PREFIX, r as registerRebuildTurnHook, s as LOG_FILE_REL, t as buildRebuildAnchor, u as registerBootstrap } from "./rebuild-Di1ITL-N.js";
15
+ import { a as ACK_PREFIX, c as eventToken, i as resolveSessionMdPath, l as DEFAULT_FAKE_INITIAL_MESSAGES, o as ASSISTANT_PREFIX, r as registerRebuildTurnHook, s as LOG_FILE_REL, t as buildRebuildAnchor, u as registerBootstrap } from "./rebuild-CNFvXPby.js";
17
16
  import { i as subscriptionStats, n as registerTrajectorySubscriptions, r as subscriptionEval, t as defaultSubscriptionDeps } from "./subscriptions-DBoO0GSO.js";
18
17
  import { c as sendTextMessage, i as getUpdates, l as sendTyping, n as downloadMedia, o as markdownToPlainText, r as getConfig, s as sendFileMessage, t as TypingStatus, u as sniffImageExt } from "./ilink-CsZ-f64q.js";
19
18
  import { a as registerImAccountImpl, i as normalizeAccountChannel, n as getImAccountImpl, r as imAccountChannels } from "./accounts-BHQbakUh.js";
@@ -425,7 +424,7 @@ function runCcFs(root, args) {
425
424
  * 进程内注册(取代 v0.1 的 bash spawn runner):zod/schemastery 参数校验、
426
425
  * 规范 JSON 输出、纯 render 投影。逻辑在 tools/fs/service.ts(可单测)。
427
426
  */
428
- function renderText$12(value) {
427
+ function renderText$11(value) {
429
428
  return [{
430
429
  type: "text",
431
430
  text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
@@ -497,7 +496,7 @@ const ccFsTool = defineTool({
497
496
  },
498
497
  output: {
499
498
  schema: { type: "json" },
500
- render: (args, value) => renderText$12(value)
499
+ render: (args, value) => renderText$11(value)
501
500
  },
502
501
  async execute(args, exec) {
503
502
  const root = cccRootForExec(exec);
@@ -515,7 +514,7 @@ const KIT_ACTIONS = [
515
514
  async function runKit(root, args, hostCtx) {
516
515
  switch (args.action) {
517
516
  case "health": {
518
- const { containerStatus } = await import("./observation-DiD_yJjS.js");
517
+ const { containerStatus } = await import("./observation-L-KQr5RL.js");
519
518
  const s = containerStatus({
520
519
  root,
521
520
  hostCtx
@@ -561,7 +560,7 @@ async function runKit(root, args, hostCtx) {
561
560
  }
562
561
  case "diag": {
563
562
  if (hostCtx === void 0) throw new Error("diag requires the plugin context (live session data unavailable without it)");
564
- const { runDiag, renderDiag } = await import("./service-mYmQXFFT.js");
563
+ const { runDiag, renderDiag } = await import("./service-BZwjW8JL.js");
565
564
  return renderDiag(await runDiag(hostCtx, root ?? ""));
566
565
  }
567
566
  default: throw new Error(`Unknown action: ${args.action}`);
@@ -572,7 +571,7 @@ async function runKit(root, args, hostCtx) {
572
571
  /**
573
572
  * tools/kit/index.ts — dashboard 真实 DSH 工具定义(defineTool)(v1.30:acc_kit → dashboard)
574
573
  */
575
- function renderText$11(value) {
574
+ function renderText$10(value) {
576
575
  return [{
577
576
  type: "text",
578
577
  text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
@@ -594,7 +593,7 @@ function createKitTool(ctx) {
594
593
  } },
595
594
  output: {
596
595
  schema: { type: "json" },
597
- render: (args, value) => renderText$11(value)
596
+ render: (args, value) => renderText$10(value)
598
597
  },
599
598
  async execute(args, exec) {
600
599
  return await runKit(cccRootForExec(exec), args, ctx);
@@ -910,7 +909,7 @@ function runGit(root, args) {
910
909
  /**
911
910
  * tools/git/index.ts — container_git 真实 DSH 工具定义(defineTool)(v1.30:cc_git → container_git)
912
911
  */
913
- function renderText$10(value) {
912
+ function renderText$9(value) {
914
913
  return [{
915
914
  type: "text",
916
915
  text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
@@ -958,7 +957,7 @@ const gitTool = defineTool({
958
957
  },
959
958
  output: {
960
959
  schema: { type: "json" },
961
- render: (args, value) => renderText$10(value)
960
+ render: (args, value) => renderText$9(value)
962
961
  },
963
962
  async execute(args, exec) {
964
963
  const root = cccRootForExec(exec);
@@ -988,7 +987,7 @@ const gitTool = defineTool({
988
987
  function agentSessionId$1(exec) {
989
988
  return exec.agent?.session?.id ?? "";
990
989
  }
991
- function renderText$9(value) {
990
+ function renderText$8(value) {
992
991
  return [{
993
992
  type: "text",
994
993
  text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
@@ -1086,7 +1085,7 @@ const msmTool = defineTool({
1086
1085
  },
1087
1086
  output: {
1088
1087
  schema: { type: "json" },
1089
- render: (args, value) => renderText$9(value)
1088
+ render: (args, value) => renderText$8(value)
1090
1089
  },
1091
1090
  async execute(args, exec) {
1092
1091
  const root = cccRootForExec(exec);
@@ -1095,12 +1094,19 @@ const msmTool = defineTool({
1095
1094
  const name = args.name;
1096
1095
  const gate = trajectoryConstraintMsmGate(root, sessionId, name ? "exec" : "list", name);
1097
1096
  if (gate.reject) throw new Error(gate.reject);
1098
- if (!name || name.trim() === "") return gate.whitelist ? "MSMs allowed in this role:\n" + [...gate.whitelist].join("\n") : buildMsmIndex(root);
1097
+ if (!name || name.trim() === "") {
1098
+ if (gate.whitelist) {
1099
+ const allowed = [...gate.whitelist];
1100
+ if (allowed.length === 0) return "This trajectory declares an EMPTY `msms` whitelist — no MSM is callable here.\n ⇒ That is a deliberate declaration (an explicit `\"msms\": []`), not a missing field.\n ⇒ To lift it, remove the `msms` key from this trajectory's trajectory file (omitting it means \"unrestricted\").";
1101
+ return `MSMs allowed for this trajectory (declared \`msms\` whitelist, ${allowed.length} entr${allowed.length === 1 ? "y" : "ies"}):\n` + allowed.join("\n") + "\n ⇒ This is a NARROWED view, not the full registry. Run `msm()` without a whitelist declared to see everything.";
1102
+ }
1103
+ return buildMsmIndex(root);
1104
+ }
1099
1105
  const clean = name.trim();
1100
- if (gate.whitelist && !gate.whitelist.has(clean)) return `MSM "${clean}" is not in this role's whitelist. Allowed: ${[...gate.whitelist].join(", ")}`;
1106
+ if (gate.whitelist && !gate.whitelist.has(clean)) return `MSM "${clean}" is not in this trajectory's declared \`msms\` whitelist.\n Allowed here: ${[...gate.whitelist].join(", ") || "(none — the whitelist is explicitly empty)"}`;
1101
1107
  if (!findEntry(root, clean)) {
1102
1108
  const suggest = suggestMsm(root, clean);
1103
- return gate.whitelist ? `(whitelisted role — candidates filtered)\n${suggest}` : suggest;
1109
+ return gate.whitelist ? `(whitelisted trajectory — candidates filtered)\n${suggest}` : suggest;
1104
1110
  }
1105
1111
  if (args.inspect === true) return runMsmAsync(root, {
1106
1112
  action: "exec",
@@ -1610,7 +1616,7 @@ const PRAXIS_INDEX = `praxis — 可实践理论注入(认知框架,按需
1610
1616
  praxis ontology(本体论工程方法群——触发/编码/四组判据 M·L·D·V/OEPE 循环/公理/反模式)
1611
1617
  无参返回本目录;详情以对应框架原文为准(单一真相源)。
1612
1618
  `;
1613
- function renderText$8(value) {
1619
+ function renderText$7(value) {
1614
1620
  return [{
1615
1621
  type: "text",
1616
1622
  text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
@@ -1631,7 +1637,7 @@ const praxisTool = defineTool({
1631
1637
  } },
1632
1638
  output: {
1633
1639
  schema: { type: "string" },
1634
- render: (_args, value) => renderText$8(value)
1640
+ render: (_args, value) => renderText$7(value)
1635
1641
  },
1636
1642
  async execute(args) {
1637
1643
  if (args.section === "eap") return eapPaper();
@@ -5224,7 +5230,7 @@ const LEVELS_BY_COMMAND = {
5224
5230
  "full"
5225
5231
  ]
5226
5232
  };
5227
- function renderText$7(value) {
5233
+ function renderText$6(value) {
5228
5234
  return [{
5229
5235
  type: "text",
5230
5236
  text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
@@ -5289,7 +5295,7 @@ function createOntologyTool() {
5289
5295
  },
5290
5296
  output: {
5291
5297
  schema: { type: "string" },
5292
- render: (_args, value) => renderText$7(value)
5298
+ render: (_args, value) => renderText$6(value)
5293
5299
  },
5294
5300
  async execute(args, exec) {
5295
5301
  const root = cccRootForExec(exec);
@@ -5749,7 +5755,7 @@ serenity-skill-creator review <skill> ← C 档:文字与 ttl 逐条的合
5749
5755
  **判据**:改完**必须重跑** \`check\` —— 本仓的教训是"检查没跑"和"检查通过"在输出上必须分得开;
5750
5756
  \`review\` 出的是**问题清单**(半机械、要人回答),**不是**通过/不通过。
5751
5757
  `;
5752
- function renderText$6(value) {
5758
+ function renderText$5(value) {
5753
5759
  return [{
5754
5760
  type: "text",
5755
5761
  text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
@@ -5877,7 +5883,7 @@ function createSkillCreatorTool() {
5877
5883
  },
5878
5884
  output: {
5879
5885
  schema: { type: "string" },
5880
- render: (_args, value) => renderText$6(value)
5886
+ render: (_args, value) => renderText$5(value)
5881
5887
  },
5882
5888
  async execute(args, exec) {
5883
5889
  const root = cccRootForExec(exec);
@@ -6447,7 +6453,7 @@ function renameDshSessionForActive(ctx, exec, info, summary) {
6447
6453
  console.warn(`[serenity-hooks] dsh 会话重命名异常: ${String(err?.message ?? err)}`);
6448
6454
  }
6449
6455
  }
6450
- function renderText$5(value) {
6456
+ function renderText$4(value) {
6451
6457
  return [{
6452
6458
  type: "text",
6453
6459
  text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
@@ -6549,7 +6555,7 @@ function createCognitiveTrajectoryTool(ctx) {
6549
6555
  },
6550
6556
  output: {
6551
6557
  schema: { type: "json" },
6552
- render: (args, value) => renderText$5(value)
6558
+ render: (args, value) => renderText$4(value)
6553
6559
  },
6554
6560
  async execute(args, exec) {
6555
6561
  const root = cccRootForExec(exec);
@@ -6643,32 +6649,58 @@ function createCognitiveTrajectoryTool(ctx) {
6643
6649
  if (!args.summary || args.summary.trim() === "") throw new Error("rebuild requires --summary <content summary ≤20 chars> (the dsh session title is renamed to S###-YYYY-MM-DD-<summary> after rebuild)");
6644
6650
  const dshSessionId = exec.agent?.session?.id ?? "";
6645
6651
  if (!dshSessionId) throw new Error("Unable to determine the current dsh session id");
6646
- try {
6647
- const { readTokenTotals, cumulativeTokens, RECONSTRUCT_TOKEN_THRESHOLD } = await Promise.resolve().then(() => reconstruct_exports);
6648
- const session = exec.agent?.session;
6649
- const totals = session ? readTokenTotals(ctx, session) : null;
6650
- const cumulative = totals ? cumulativeTokens(totals) : null;
6651
- if (cumulative !== null && cumulative >= RECONSTRUCT_TOKEN_THRESHOLD) {
6652
- const { queueReconstruct } = await Promise.resolve().then(() => reconstruct_exports);
6653
- const rerouted = queueReconstruct(ctx, {
6654
- root,
6655
- note: args.note,
6656
- summary: args.summary,
6657
- dshSessionId
6658
- });
6659
- return {
6660
- ok: true,
6661
- queued: rerouted.queued,
6662
- rerouted: "reconstruct",
6663
- cumulativeTokens: rerouted.cumulative,
6664
- threshold: RECONSTRUCT_TOKEN_THRESHOLD,
6665
- anchor: rerouted.anchor,
6666
- sessionMdPath: rerouted.sessionMdPath,
6667
- instruction: `Rebuild was rerouted to reconstruct: this session's cumulative usage is ${rerouted.cumulative} ≥ threshold ${RECONSTRUCT_TOKEN_THRESHOLD}, and clearing in place would NOT bring it down. When this turn ends: a NEW dsh session is created, this cognitive trajectory is bound to it, the continue anchor is injected there, and the current session is archived. Resume from SESSION.md in the new conversation — do not keep working in this one.`
6668
- };
6652
+ {
6653
+ let totals = null;
6654
+ let mod = null;
6655
+ try {
6656
+ mod = await Promise.resolve().then(() => reconstruct_exports);
6657
+ const session = exec.agent?.session;
6658
+ const read = session ? mod.readTokenTotals(ctx, session) : null;
6659
+ totals = read ? mod.cumulativeTokens(read) : null;
6660
+ if (totals !== null && totals >= mod.RECONSTRUCT_TOKEN_THRESHOLD) {
6661
+ const rerouted = mod.queueReconstruct(ctx, {
6662
+ root,
6663
+ note: args.note,
6664
+ summary: args.summary,
6665
+ dshSessionId
6666
+ });
6667
+ return {
6668
+ ok: true,
6669
+ queued: rerouted.queued,
6670
+ rerouted: "reconstruct",
6671
+ cumulativeTokens: rerouted.cumulative,
6672
+ threshold: mod.RECONSTRUCT_TOKEN_THRESHOLD,
6673
+ anchor: rerouted.anchor,
6674
+ sessionMdPath: rerouted.sessionMdPath,
6675
+ instruction: `Rebuild was rerouted to reconstruct: this session's cumulative usage is ${rerouted.cumulative} ≥ threshold ${mod.RECONSTRUCT_TOKEN_THRESHOLD}, and clearing in place would NOT bring it down. When this turn ends: a NEW dsh session is created, this cognitive trajectory is bound to it, the continue anchor is injected there, and the current session is archived. Resume from SESSION.md in the new conversation — do not keep working in this one.`
6676
+ };
6677
+ }
6678
+ } catch {} finally {
6679
+ /**
6680
+ * 🔴🔴 **观测面(2026-11-20 从已删的 `makeReconstructWhen` 搬到这里)**。
6681
+ *
6682
+ * 原处是那个条件可见工具的 `when` 回调:宿主**每步**问一次"要不要放出工具",
6683
+ * 它顺带按会话节流 60s 落一条诊断。工具面删除后那个回调没了 ⇒ 观测会整条消失。
6684
+ *
6685
+ * **搬到这里的理由(不是"随手放一处")**:
6686
+ * ① 这里**本来就要读四桶、本来就要判阈值** ⇒ 多写一行诊断是**零额外成本**;
6687
+ * ② 那个读数要回答的问题是「**机制到底读到了多少**」,
6688
+ * 而**只有当它真的要改道时,这个答案才有用** —— 平时读数再密也没人去看。
6689
+ * ⚠️ **如实登记的代价**:取样密度从"每步(节流 60s)"降到"每次调 rebuild 一次"。
6690
+ * ⇒ 若将来要看"这条会话当前累计多少",改用 `readTokenTotals` 现读,⛔ 别指望这个文件是仪表盘。
6691
+ * ⚠️ `isOk()` 判空是**必须**的:`finally` 在 import 失败时同样会跑,而那时 `mod` 仍是 null。
6692
+ */
6693
+ if (mod !== null && typeof mod.writeReconstructDiagForRoute === "function") try {
6694
+ mod.writeReconstructDiagForRoute(root, {
6695
+ sessionId: dshSessionId,
6696
+ cumulative: totals,
6697
+ threshold: mod.RECONSTRUCT_TOKEN_THRESHOLD,
6698
+ rerouted: totals !== null && totals >= mod.RECONSTRUCT_TOKEN_THRESHOLD
6699
+ });
6700
+ } catch {}
6669
6701
  }
6670
- } catch {}
6671
- const { queueRebuild } = await import("./rebuild-Di1ITL-N.js").then((n) => n.n);
6702
+ }
6703
+ const { queueRebuild } = await import("./rebuild-CNFvXPby.js").then((n) => n.n);
6672
6704
  const result = await queueRebuild(ctx, {
6673
6705
  root,
6674
6706
  note: args.note,
@@ -6833,7 +6865,7 @@ const ACTIONS$1 = [
6833
6865
  "show",
6834
6866
  "doc"
6835
6867
  ];
6836
- function renderText$4(value) {
6868
+ function renderText$3(value) {
6837
6869
  return [{
6838
6870
  type: "text",
6839
6871
  text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
@@ -6865,7 +6897,7 @@ const localstoreTool = defineTool({
6865
6897
  },
6866
6898
  output: {
6867
6899
  schema: { type: "json" },
6868
- render: (args, value) => renderText$4(value)
6900
+ render: (args, value) => renderText$3(value)
6869
6901
  },
6870
6902
  async execute(args, exec) {
6871
6903
  const root = cccRootForExec(exec);
@@ -7633,7 +7665,7 @@ function viewConfigSummary(root) {
7633
7665
  note: "This is a **current-value summary** (only keys with values are shown; long values truncated). How to fill each section, and what a wrong value does ⇒ container_admin config docs config"
7634
7666
  };
7635
7667
  }
7636
- function renderText$3(value) {
7668
+ function renderText$2(value) {
7637
7669
  return [{
7638
7670
  type: "text",
7639
7671
  text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
@@ -7732,7 +7764,7 @@ function createContainerAdminTool(ctx) {
7732
7764
  },
7733
7765
  output: {
7734
7766
  schema: { type: "json" },
7735
- render: (args, value) => renderText$3(value)
7767
+ render: (args, value) => renderText$2(value)
7736
7768
  },
7737
7769
  async execute(args, exec) {
7738
7770
  const root = cccRootForExec(exec);
@@ -7800,16 +7832,19 @@ function createContainerAdminTool(ctx) {
7800
7832
  //#region src/trajectory/reconstruct.ts
7801
7833
  var reconstruct_exports = /* @__PURE__ */ __exportAll({
7802
7834
  RECONSTRUCT_TOKEN_THRESHOLD: () => RECONSTRUCT_TOKEN_THRESHOLD,
7835
+ __resetPendingReconstructForTest: () => __resetPendingReconstructForTest,
7836
+ __resetReconstructDiagForTest: () => __resetReconstructDiagForTest,
7803
7837
  cumulativeTokens: () => cumulativeTokens,
7804
- makeReconstructWhen: () => makeReconstructWhen,
7838
+ pendingReconstructSnapshot: () => pendingReconstructSnapshot,
7805
7839
  performReconstruct: () => performReconstruct,
7806
7840
  queueReconstruct: () => queueReconstruct,
7807
7841
  readTokenTotals: () => readTokenTotals,
7842
+ reconstructDiagSnapshot: () => reconstructDiagSnapshot,
7808
7843
  registerReconstructTurnHook: () => registerReconstructTurnHook,
7809
7844
  scheduleArchiveOldSession: () => scheduleArchiveOldSession,
7810
7845
  selectHandoverPath: () => selectHandoverPath,
7811
7846
  shouldOfferReconstruct: () => shouldOfferReconstruct,
7812
- supportsActivation: () => supportsActivation
7847
+ writeReconstructDiagForRoute: () => writeReconstructDiagForRoute
7813
7848
  });
7814
7849
  /**
7815
7850
  * 触发阈值:**10 亿**累计 token(owner 2026-11-06 裁「我这有好几个十亿的」+ 截图 1372M)。
@@ -7860,18 +7895,11 @@ function cumulativeTokens(totals) {
7860
7895
  return totals.uncachedInputTokens + totals.outputTokens + totals.cacheReadTokens + totals.cacheWriteTokens;
7861
7896
  }
7862
7897
  /**
7863
- * 当前宿主是否支持 `register()` 的第二参数(工具准入条件)。
7898
+ * 该会话此刻是否已达阈值(keeper 提醒侧用它**记录**分流路径,不参与注入正文)。
7864
7899
  *
7865
- * 判据 = 宿主版本 ≥ `0.2.2-rc.1`(`ToolRegistrationOptions` 首次出现的档)。
7866
- * 读不到版本 ⇒ `false`(保守:不传第二参数 ⇒ 退化成"常驻可见",而不是赌它支持)。
7900
+ * 🔴 **2026-11-20**:原注释写「`when` 与 keeper 提醒共用」—— `when` 已随工具面删除,
7901
+ * 现在**只剩 keeper 这一处**调用(`seams/cognitive-trajectory-lifecycle.ts`)。
7867
7902
  */
7868
- function supportsActivation() {
7869
- const v = readDshVersion();
7870
- if (v === null) return false;
7871
- const cmp = compareSemver(v, "0.2.2-rc.1");
7872
- return cmp !== null && cmp >= 0;
7873
- }
7874
- /** 该会话此刻是否已达阈值(`when` 与 keeper 提醒**共用**这一条判据) */
7875
7903
  function shouldOfferReconstruct(ctx, session) {
7876
7904
  const totals = readTokenTotals(ctx, session);
7877
7905
  if (totals === null) return false;
@@ -7907,9 +7935,10 @@ let diagState = {
7907
7935
  /**
7908
7936
  * 落一份诊断快照。
7909
7937
  *
7910
- * 🔴 **本函数在 `when` 回调里也会被调到** ⇒ 必须**永不抛**(宿主契约逐字:
7911
- * *"rejection fails step preparation"* ⇒ `when` 里任何一个异常都会让**这一步的准备失败**)。
7912
- * 故整段 try/catch 兜底、失败静默。
7938
+ * 🔴 **必须永不抛**:本函数曾被 `when` 回调调用(宿主契约逐字 *"rejection fails step preparation"*
7939
+ * ⇒ `when` 里任何一个异常都会让**这一步的准备失败**)。**2026-11-20 起 `when` 已删**,
7940
+ * 但"永不抛"这条**保留** —— 它现在被 `case 'rebuild'` 的 `finally` 调,那里抛错会炸掉一次
7941
+ * **本来要成功的 rebuild**。故整段 try/catch 兜底、失败静默。
7913
7942
  */
7914
7943
  function writeReconstructDiag(root, entry) {
7915
7944
  try {
@@ -7928,54 +7957,49 @@ function writeReconstructDiag(root, entry) {
7928
7957
  writeFileSync(file, JSON.stringify(s, null, 2) + "\n", "utf-8");
7929
7958
  } catch {}
7930
7959
  }
7931
- /** 观测落盘的节流窗(`when` 每步都跑 ⇒ 写盘必须有界) */
7932
- const OBSERVE_THROTTLE_MS = 6e4;
7960
+ /** 测试/调试:读诊断状态 */
7961
+ function reconstructDiagSnapshot() {
7962
+ return { ...diagState };
7963
+ }
7933
7964
  /**
7934
- * 造 `when` 回调:**答"这一步要不要把这个工具放出来"**,并顺带落一次节流的观测。
7965
+ * **改道观测**(2026-11-20 从已删的 `makeReconstructWhen` 搬来)——见 `tools/cognitive-trajectory.ts` 的调用处。
7935
7966
  *
7936
- * 为什么观测不能省:owner 要的第一件事是"达阈值才出现",而**"它到底读到了多少"只有真机答得上**
7937
- * (宿主的投影在本会话能否读出 1391 M 级 —— 这是方案阶段明确未验的那一格)。
7938
- * 观测落盘让**第一次真机运行**同时完成"验投影"与"验功能",不必再另写一次性探针
7939
- * (探针验的是"我这样调能读懂",诊断文件验的是**真实现每步真的算出什么** —— 后者才是上生产的那个数)。
7967
+ * 判据:`case 'rebuild'` 那里**已经**读完了四桶并判过阈值,多写一条诊断是零成本;
7968
+ * 而那条读数要回答的「机制到底读到了多少」,**只在真要改道时才需要**。
7940
7969
  *
7941
- * 🔴 三条硬约束(都来自宿主契约,逐字):
7942
- * ① **绝不抛**(rejection fails step preparation);
7943
- * ② **不改变任何注册、不启动任何工具工作**(契约:*"Conditions must not mutate registrations
7944
- * or start tool work"*);
7945
- * ③ **便宜** —— 每步都会跑 ⇒ 落盘按会话**节流 60s**。
7970
+ * @param cumulative `null` = 读不到投影(⛔ 不写 0 —— 那会让"读不到"与"真的是 0"同形)
7946
7971
  */
7947
- function makeReconstructWhen(ctx) {
7948
- const lastObserve = /* @__PURE__ */ new Map();
7949
- return (context) => {
7950
- try {
7951
- const session = (context?.agent)?.session;
7952
- if (!session) return false;
7953
- const totals = readTokenTotals(ctx, session);
7954
- if (totals === null) return false;
7955
- const total = cumulativeTokens(totals);
7956
- const id = String(session.id ?? "");
7957
- const root = cccRootForCwd(agentCwdFor({ session }));
7958
- if (root !== null) {
7959
- const now = Date.now();
7960
- if (now - (lastObserve.get(id) ?? 0) >= OBSERVE_THROTTLE_MS) {
7961
- lastObserve.set(id, now);
7962
- writeReconstructDiag(root, {
7963
- sessionId: id,
7964
- event: "observe",
7965
- observe: true,
7966
- detail: `cumulative=${total} threshold=${RECONSTRUCT_TOKEN_THRESHOLD} visible=${total >= RECONSTRUCT_TOKEN_THRESHOLD} buckets=${JSON.stringify(totals)} activation=${supportsActivation()}`
7967
- });
7968
- }
7969
- }
7970
- return total >= RECONSTRUCT_TOKEN_THRESHOLD;
7971
- } catch {
7972
- return false;
7973
- }
7972
+ function writeReconstructDiagForRoute(root, input) {
7973
+ writeReconstructDiag(root, {
7974
+ sessionId: input.sessionId,
7975
+ event: input.rerouted ? "rerouted" : "route-skipped",
7976
+ detail: `cumulative=${input.cumulative === null ? "unreadable" : input.cumulative} threshold=${input.threshold} rerouted=${input.rerouted}`
7977
+ });
7978
+ }
7979
+ /** 测试/调试:清空诊断状态(跨用例隔离) */
7980
+ function __resetReconstructDiagForTest() {
7981
+ diagState = {
7982
+ lastTs: "",
7983
+ lastSessionId: "",
7984
+ lastEvent: "",
7985
+ observeCount: 0,
7986
+ queuedCount: 0,
7987
+ rebuiltCount: 0,
7988
+ archivedCount: 0,
7989
+ failedCount: 0
7974
7990
  };
7975
7991
  }
7976
7992
  const pendingReconstructs = /* @__PURE__ */ new Map();
7977
7993
  /** 陈旧队列存活时长:超过则丢弃(turn 异常结束 / agent 崩溃时防残留误换代 —— 同 rebuild) */
7978
7994
  const PENDING_TTL_MS = 6e5;
7995
+ /** 测试/调试:查看待换代的队列 */
7996
+ function pendingReconstructSnapshot() {
7997
+ return new Map(pendingReconstructs);
7998
+ }
7999
+ /** 测试/调试:清空待换代队列 */
8000
+ function __resetPendingReconstructForTest() {
8001
+ pendingReconstructs.clear();
8002
+ }
7979
8003
  /**
7980
8004
  * 排队一次换代(**不立即建新会话**)。
7981
8005
  *
@@ -8513,6 +8537,208 @@ function registerKeeper(ctx, opts = {}) {
8513
8537
  });
8514
8538
  }
8515
8539
  //#endregion
8540
+ //#region src/seams/session-md-full-read.ts
8541
+ /**
8542
+ * seams/session-md-full-read.ts — **读 SESSION.md 一次给全文**(owner 2026-11-20 令)
8543
+ *
8544
+ * ## owner 要的是什么(原话)
8545
+ *
8546
+ * > 「由于 SESSION.md 的本质,所以无论多大都需要一次全读,故节约的是调用次数」
8547
+ * > 「请你照顾你自己的习惯,习惯的东西不应当改变,只是机械层面我们让它直接出全文就好,
8548
+ * > 也就是说只要读的是 SESSION.md;无视参数;直接全文;这就照顾到了每一个轨迹的成本」
8549
+ *
8550
+ * 拆成三条可判定的约束:
8551
+ * | # | 约束 | 落地 |
8552
+ * |---|---|---|
8553
+ * | 1 | **只认 SESSION.md** | 文件名精确 `SESSION.md`(⛔ 不是"含 SESSION 的路径") |
8554
+ * | 2 | **无视参数** | 传 `limit`/`offset` 一律不管,恒从第 1 行给到末行 |
8555
+ * | 3 | **模型看到的是全文** | 替换**模型读的那一面**(content),⛔ 不动结构化 value |
8556
+ *
8557
+ * ## 🔴 为什么不能"放大 limit"就完事(本模块存在的真正理由)
8558
+ *
8559
+ * 宿主 `read` 有三道上限,**行数不是卡住我们的那道**:
8560
+ * | 配置 | 默认 | 实测后果 |
8561
+ * |---|---|---|
8562
+ * | 一次最多行数 | 2000 | 我们这份 500 余行 ⇒ **没撞到它** |
8563
+ * | **一次最多字节数** | **51200 B** | **实测截断点就在这**:66,881 B 的文件停在第 360 行 |
8564
+ * | 单行最长 | 2000 字符 | 与本模块无关 |
8565
+ * ⇒ 传多大的 `limit` 都过不了字节这道闸;而且 `limit` 一旦超过上限,宿主**直接抛错**。
8566
+ * ⇒ 唯一可行的机械手段 = **在结果返回后重写模型看到的那一面**。
8567
+ *
8568
+ * ## 🔴 为什么不自己拼整份文本(本模块最容易写错的一处)
8569
+ *
8570
+ * 第一版我打算「读文件 → 自己编号 → 整份塞进去」。**那是复刻宿主的渲染语义**,
8571
+ * 而本仓已为这件事付过代价(自写探针复刻 `foldSurface`,复刻错就得到相反结论)。
8572
+ * ⇒ 改为**就地接续**:取宿主**真实产出**的前缀(含它自己的编号样式与信封),
8573
+ * 只把**剩余行**按同样样式接上,再接回宿主自己的结尾。格式的定义权仍归宿主。
8574
+ *
8575
+ * ## 🔴 失败一律原样放行
8576
+ *
8577
+ * 识别不出格式 / 读不到文件 / 拼接后不合法 ⇒ **一个字节都不改**,退回分次读。
8578
+ * **残缺的长文档比短的完整文档危险得多** —— 它不报错。
8579
+ *
8580
+ * ## ⚠️ 已知边界(如实登记)
8581
+ *
8582
+ * · 只在本进程能读到该文件时生效;读不到就放行。
8583
+ * · 只接管 `read` 这一个工具名,其余工具零干预(见测试的对照验证)。
8584
+ * · ⛔ **不设体量上限**:owner 明确「阈值 100 KB,实际最大就在这附近」⇒
8585
+ * 在 100 KB 量级设上限属于伪需求。但这条依赖「SESSION.md 有体积告示」这个既有机制,
8586
+ * 若那个机制被拆掉,本模块会让一次读取无界 ⇒ 登记为耦合项。
8587
+ */
8588
+ /** 只接管这**一个**文件名(精确匹配,⛔ 不是后缀/包含匹配) */
8589
+ const SESSION_MD_BASENAME = "SESSION.md";
8590
+ /** 宿主 read 产出的信封形态(逐字对读过宿主 `formatReadOutput`) */
8591
+ const ENVELOPE_RE = /^<path>([^\n]*)<\/path>\n<type>file<\/type>\n<content>\n([\s\S]*)\n<\/content>$/;
8592
+ /** 行号前缀 `NNN: ` —— 编号样式由宿主决定,这里只**识别**,不发明 */
8593
+ const LINE_RE = /^(\d+): ([\s\S]*)$/;
8594
+ /** 宿主三种结尾(capped / 还有更多 / 读到末尾) */
8595
+ const FOOTER_CAPPED_RE = /^\(Output capped\. Showing lines (\d+)-(\d+)\. Use offset=(\d+) to continue\.\)$/;
8596
+ const FOOTER_MORE_RE = /^\(Showing lines (\d+)-(\d+) of (\d+)\. Use offset=(\d+) to continue\.\)$/;
8597
+ const FOOTER_END_RE = /^\(End of file - total (\d+) lines\)$/;
8598
+ /**
8599
+ * 判「这次 read 是不是在读 SESSION.md」。
8600
+ *
8601
+ * ⚠️ 用 `basename` 精确比,⛔ 不用 `includes('SESSION')`:
8602
+ * 后者会把 `SESSION-archive-2026-11-20.md`(几百 KB 的归档)也一起接管,
8603
+ * 那是**本模块最危险的一种误判** —— 归档本来就该分次读。
8604
+ */
8605
+ function isSessionMdRead(filePath) {
8606
+ if (typeof filePath !== "string" || filePath.length === 0) return false;
8607
+ return basename(filePath) === SESSION_MD_BASENAME;
8608
+ }
8609
+ /**
8610
+ * 把宿主产出的「前 N 行」接续成全文。
8611
+ *
8612
+ * @param content 宿主给模型看的文本(单个 text 块的内容)
8613
+ * @param absolutePath 真实文件路径(用于读全文;读不到就放行)
8614
+ * @returns `text=null` 表示不接管
8615
+ */
8616
+ function extendToWholeFile(content, absolutePath) {
8617
+ const m = ENVELOPE_RE.exec(content);
8618
+ if (!m) return {
8619
+ text: null,
8620
+ reason: "envelope-unrecognized"
8621
+ };
8622
+ const body = m[2];
8623
+ const split = body.lastIndexOf("\n\n");
8624
+ if (split < 0) return {
8625
+ text: null,
8626
+ reason: "no-footer-separator"
8627
+ };
8628
+ const bodyLinesText = body.slice(0, split);
8629
+ const footer = body.slice(split + 2);
8630
+ const isCapped = FOOTER_CAPPED_RE.test(footer);
8631
+ const isMore = FOOTER_MORE_RE.test(footer);
8632
+ const isEnd = FOOTER_END_RE.test(footer);
8633
+ if (!isCapped && !isMore && !isEnd) return {
8634
+ text: null,
8635
+ reason: "footer-unrecognized"
8636
+ };
8637
+ if (isEnd) return {
8638
+ text: null,
8639
+ reason: "already-complete"
8640
+ };
8641
+ const given = [];
8642
+ for (const line of bodyLinesText.split("\n")) {
8643
+ const lm = LINE_RE.exec(line);
8644
+ if (!lm) return {
8645
+ text: null,
8646
+ reason: "body-line-unrecognized"
8647
+ };
8648
+ given.push({
8649
+ number: Number(lm[1]),
8650
+ text: lm[2]
8651
+ });
8652
+ }
8653
+ if (given.length === 0) return {
8654
+ text: null,
8655
+ reason: "body-empty"
8656
+ };
8657
+ let all;
8658
+ try {
8659
+ all = readFileSync(absolutePath, "utf-8").split("\n");
8660
+ } catch {
8661
+ return {
8662
+ text: null,
8663
+ reason: "file-unreadable"
8664
+ };
8665
+ }
8666
+ if (all.length > 0 && all[all.length - 1] === "") all.pop();
8667
+ const lastGiven = given[given.length - 1];
8668
+ if (all.length <= lastGiven.number) return {
8669
+ text: null,
8670
+ reason: "nothing-left-to-extend"
8671
+ };
8672
+ if (all[lastGiven.number - 1] !== lastGiven.text) return {
8673
+ text: null,
8674
+ reason: "file-changed-since-read"
8675
+ };
8676
+ const rest = all.slice(lastGiven.number).map((t, i) => `${lastGiven.number + 1 + i}: ${t}`);
8677
+ const extendedBody = [...bodyLinesText.split("\n"), ...rest].join("\n");
8678
+ const newFooter = `(End of file - total ${all.length} lines)`;
8679
+ return {
8680
+ text: `<path>${m[1]}</path>\n<type>file</type>\n<content>\n${extendedBody}\n\n${newFooter}\n</content>`,
8681
+ reason: null
8682
+ };
8683
+ }
8684
+ /**
8685
+ * 从一次成功 read 的 content 里取**单个 text 块**的正文。
8686
+ * 非单块 / 非 text ⇒ `null`(放行)。
8687
+ */
8688
+ function singleTextOf(content) {
8689
+ if (!Array.isArray(content) || content.length !== 1) return null;
8690
+ const only = content[0];
8691
+ if (!only || only.type !== "text" || typeof only.text !== "string") return null;
8692
+ return only.text;
8693
+ }
8694
+ /**
8695
+ * 注册读全文接管(`index.ts` 的 apply 调用)。
8696
+ *
8697
+ * ## 🔴 三处必须守住的边界
8698
+ *
8699
+ * ① **只改 `content`,⛔ 绝不动 `value`** —— 宿主源码对此有硬断言:
8700
+ * 同时给两者会 `throw TypeError("cannot replace both value and content")`。
8701
+ * 落到实处:`surface/usage.ts` 读的是 `value`,动它就会**打断用量统计**。
8702
+ * ② **`isError` 一律放行** —— 失败的读取没有正文可接续。
8703
+ * ③ **本钩子永不抛** —— 它挂在每轮都跑的返回路径上;抛一次等于用一次优化打断会话。
8704
+ * `try/catch` 兜底后返回 `next()`(下游其他人的决策照旧)。
8705
+ *
8706
+ * ## 与既有 `tools/post-execute` 消费者的关系
8707
+ *
8708
+ * 本仓另有一处同钩子(keeper 计分/提醒/体积告示)。两者在**不同文件里各注册一次**,
8709
+ * 宿主按 waterfall 串联 ⇒ 谁先谁后不影响正确性:本钩子只碰 `content`,
8710
+ * 那一处只碰 `additionalContexts`。**这里刻意不合并**,因为合并会让
8711
+ * 「一次读文件」和「每轮计分」产生编译期耦合。
8712
+ */
8713
+ function registerSessionMdFullRead(ctx) {
8714
+ const on = ctx.on;
8715
+ if (typeof on !== "function") return;
8716
+ on.call(ctx, "tools/post-execute", async (exec, result, next) => {
8717
+ const downstream = await next();
8718
+ try {
8719
+ if (exec?.name !== "read") return downstream;
8720
+ const argPath = exec.arguments?.file_path;
8721
+ if (!isSessionMdRead(argPath)) return downstream;
8722
+ if (result?.isError === true) return downstream;
8723
+ const ds = downstream;
8724
+ if (ds?.kind === "block") return downstream;
8725
+ const text = singleTextOf(result.content);
8726
+ if (text === null) return downstream;
8727
+ const outcome = extendToWholeFile(singleTextOf(ds.content) ?? text, String(argPath));
8728
+ if (outcome.text === null) return downstream;
8729
+ return {
8730
+ ...ds,
8731
+ content: [{
8732
+ type: "text",
8733
+ text: outcome.text
8734
+ }]
8735
+ };
8736
+ } catch {
8737
+ return downstream;
8738
+ }
8739
+ });
8740
+ }
8741
+ //#endregion
8516
8742
  //#region src/trajectory/model-runtime.ts
8517
8743
  /**
8518
8744
  * trajectory/model-runtime.ts — **`trajectory.json` 的 `model` 字段:每轮求值 + 运行时热切换**
@@ -11437,93 +11663,6 @@ function registerGateway(ctx) {
11437
11663
  });
11438
11664
  }
11439
11665
  //#endregion
11440
- //#region src/tools/reconstruct.ts
11441
- /**
11442
- * tools/reconstruct.ts — `reconstruct` 工具面(owner 2026-11-06 令)
11443
- *
11444
- * 只有一个动作、两个参数(与 `rebuild` 同形),因为它的语义就是"rebuild 的换代版":
11445
- *
11446
- * | 参数 | 必需 | 说明 |
11447
- * |---|---|---|
11448
- * | `summary` | ✅ | 内容概括 ≤20 字(新载体的会话标题用它,与 rebuild 同一个服务端清洗/截断) |
11449
- * | `note` | — | 任务焦点 ≤200 字(注入新载体锚点的 `- Task focus:` 行) |
11450
- *
11451
- * ## 🔴 本工具**平时不可见**,由 `register(def, { when })` 控制
11452
- *
11453
- * 判据在 `trajectory/reconstruct.ts` 的 {@link makeReconstructWhen}:累计 token ≥ 阈值才放出。
11454
- * ⇒ **工具面的注册点在 `index.ts`**,本文件只给 `def`(不为可见性负责)。
11455
- *
11456
- * ## 为什么文案要写"它和 rebuild 有什么不同"
11457
- *
11458
- * 模型同时看到 `rebuild` / `reconstruct` 时会**默认选更熟的那个**(rebuild),
11459
- * 而两者治的**不是同一个病**(rebuild 治上下文、reconstruct 治日志体积)。
11460
- * ⇒ 描述里必须一句话说清"什么时候该用我",否则这个工具等于不存在
11461
- * (它只在阈值后才出现,那时模型更没机会摸索)。
11462
- */
11463
- function renderText$2(value) {
11464
- return [{
11465
- type: "text",
11466
- text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
11467
- }];
11468
- }
11469
- /**
11470
- * 造 `reconstruct` 工具定义(**不带任何可见性判定**)。
11471
- *
11472
- * @param ctx 插件上下文(排队时需要 `ctx.sessions.get` 定位会话;闭包捕获)
11473
- */
11474
- function createReconstructTool(ctx) {
11475
- return defineTool({
11476
- name: "reconstruct",
11477
- description: [
11478
- "Replace this conversation as the carrier of this cognitive trajectory — the successor of rebuild, not a variant of it.",
11479
- "rebuild clears THIS conversation in place, so the same session keeps growing its log. reconstruct creates a NEW dsh session, binds the same 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.",
11480
- "Use it when the carrier session itself has become too large to keep (its cumulative token usage passed the configured ceiling). Use rebuild instead when only the model context is too big — that one is cheap and keeps the same session.",
11481
- `This tool appears only after that ceiling is passed (threshold ${RECONSTRUCT_TOKEN_THRESHOLD} cumulative '
11482
- + 'tokens, counting every usage bucket: uncached input + cache read + cache write + output). Its absence means the carrier is still within budget.`,
11483
- "It queues: the swap runs when this turn ends, so finish the step you are in first. It takes the same parameters as rebuild — summary (required, ≤20 chars, becomes part of the new carrier's title) and note (optional, ≤200 chars, becomes the task focus line in the new carrier's anchor)."
11484
- ].join(" "),
11485
- parameters: {
11486
- summary: {
11487
- type: "string",
11488
- required: true,
11489
- description: "Content summary ≤20 chars — names the next work phase. Appended to the NEW carrier's session title as S###-YYYY-MM-DD-<summary>; the S### id and date stay server-derived. Same parameter as rebuild."
11490
- },
11491
- note: {
11492
- type: "string",
11493
- description: "Task focus ≤200 chars for the new carrier — what to work on next (short, no history; SESSION.md holds the full history). Injected as \"- Task focus: …\" into the continue anchor. Same parameter as rebuild."
11494
- }
11495
- },
11496
- output: {
11497
- schema: { type: "json" },
11498
- render: (_args, value) => renderText$2(value)
11499
- },
11500
- async execute(args, exec) {
11501
- const root = cccRootForExec(exec);
11502
- if (!root) throw new Error(NO_CCC_FROM_AGENT_CWD);
11503
- if (!args.summary || args.summary.trim() === "") throw new Error("reconstruct requires summary <content summary ≤20 chars> (the new carrier's dsh session title is renamed to S###-YYYY-MM-DD-<summary>)");
11504
- const dshSessionId = exec.agent?.session?.id ?? "";
11505
- if (!dshSessionId) throw new Error("Unable to determine the current dsh session id");
11506
- const result = queueReconstruct(ctx, {
11507
- root,
11508
- note: args.note,
11509
- summary: args.summary,
11510
- dshSessionId
11511
- });
11512
- const totals = readTokenTotals(ctx, exec.agent?.session);
11513
- return {
11514
- ok: true,
11515
- queued: result.queued,
11516
- carrierSessionId: dshSessionId,
11517
- cumulativeTokens: totals ? cumulativeTokens(totals) : null,
11518
- threshold: RECONSTRUCT_TOKEN_THRESHOLD,
11519
- anchor: result.anchor,
11520
- sessionMdPath: result.sessionMdPath,
11521
- instruction: "Queued carrier replacement: when this turn ends, a NEW dsh session is created, this cognitive trajectory is bound to it, the continue anchor is injected there, and the current session is archived. Resume from SESSION.md in the new conversation — do not keep working in this one."
11522
- };
11523
- }
11524
- });
11525
- }
11526
- //#endregion
11527
11666
  //#region node_modules/.pnpm/marked@18.0.11/node_modules/marked/lib/marked.esm.js
11528
11667
  /**
11529
11668
  * marked v18.0.11 - a markdown parser
@@ -23015,11 +23154,11 @@ function apply(ctx, config) {
23015
23154
  }
23016
23155
  registerSettingsSection(ctx, config);
23017
23156
  if (config.tools) registerDiagramTool(ctx);
23018
- if (config.tools) registerReconstructTool(ctx);
23019
23157
  registerGateway(ctx);
23020
23158
  registerRebuildTurnHook(ctx);
23021
23159
  registerReconstructTurnHook(ctx);
23022
23160
  registerOutputGuardHook(ctx);
23161
+ registerSessionMdFullRead(ctx);
23023
23162
  if (config.env) registerEnv(ctx);
23024
23163
  if (config.opencodeSkills) registerOpencodeSkills(ctx);
23025
23164
  registerBootstrap(ctx);
@@ -23054,36 +23193,6 @@ function apply(ctx, config) {
23054
23193
  * 🔴 **关的时候要注销**(不是"留着但不响应"):与"关时不注册"同一口径 —— 工具不出现在模型清单里。
23055
23194
  * @param ctx - 插件上下文
23056
23195
  */
23057
- /**
23058
- * 注册 `reconstruct` 工具(v1.121.0,owner 2026-11-06 令)。
23059
- *
23060
- * ## 与其它条件工具的区别(这一格是本仓唯一)
23061
- *
23062
- * `im-bridge` / `diagram` 的条件都靠 `seams/guards.ts` 的 `restrict({ deny })` 施加。
23063
- * 而宿主 `restrict` **只能 deny,不能 allow** ⇒ 那套机制只能"平时藏起来",
23064
- * 做不到"达阈值再放出来"。`reconstruct` 要的正是后者 ⇒ 走 `register(def, { when })`:
23065
- * 宿主每步 `resolve()` 时问一次,`false` 时**既不进模型声明,也不进派发**。
23066
- *
23067
- * ⚠️ **档位降级(如实登记)**:第二参数只在宿主 `≥0.2.2-rc.1` 存在。
23068
- * 低档下多传的实参被 JS 静默忽略 ⇒ 那个档位上 `reconstruct` **常驻可见**。
23069
- * 这是"宿主没这个能力"的降级,不是缺陷;`supportsActivation()` 把它落进
23070
- * `AGENT_SESSIONS/.reconstruct-diag.json`,让读数面能区分"没出现"与"出现了但藏不住"。
23071
- *
23072
- * @param ctx - 插件上下文(`when` 要读 `sessionProjections`)
23073
- */
23074
- function registerReconstructTool(ctx) {
23075
- try {
23076
- const when = makeReconstructWhen(ctx);
23077
- const tools = ctx.tools;
23078
- if (supportsActivation()) tools.register(createReconstructTool(ctx), { when });
23079
- else {
23080
- tools.register(createReconstructTool(ctx));
23081
- console.log("[serenity-hooks] reconstruct:当前宿主不支持工具准入条件 ⇒ 该工具常驻可见(降级,非缺陷)");
23082
- }
23083
- } catch (err) {
23084
- console.error(`[serenity-hooks] ✗ reconstruct 工具注册失败: ${String(err?.message ?? err)}`);
23085
- }
23086
- }
23087
23196
  function registerDiagramTool(ctx) {
23088
23197
  /** 当前注册的 disposer(`null` = 未注册)。宿主 `ctx.tools.register` **返回注销器**。 */
23089
23198
  let dispose = null;