@shgroup/dsh-serenity-hooks 1.137.13 → 1.137.15

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.137.13",
3
+ "version": "1.137.15",
4
4
  "main": "lib/index.js",
5
5
  "description": "宁静号 ACC harness(Native Cordis 插件):给 DSH 装一个「AI 工作区」——13 个工具(container_fs/cognitive_trajectory/dashboard/container_git/msm/praxis/ontology/serenity-skill-creator/localstore/container_admin/browser_slot;另两个 im-bridge/diagram 按条件出现)+ 机械约束(安全模式/工作区围墙/密钥守卫)+ 认知轨迹日志与原地重建 + 网页登录入口/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
@@ -12,14 +12,14 @@ import { c as buildCroSnapshot, d as WAKE_CATCH_UP_MS, f as addWake, i as sendTo
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 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";
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-DVVb82zf.js";
16
16
  import { i as subscriptionStats, n as registerTrajectorySubscriptions, r as subscriptionEval, t as defaultSubscriptionDeps } from "./subscriptions-DBoO0GSO.js";
17
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";
18
18
  import { a as registerImAccountImpl, i as normalizeAccountChannel, n as getImAccountImpl, r as imAccountChannels } from "./accounts-BHQbakUh.js";
19
19
  import { createRequire } from "node:module";
20
20
  import z from "@deepseek-ai/schemastery";
21
21
  import { defineTool } from "@deepseek-ai/dsh-tools";
22
- import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
22
+ import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
23
23
  import { appendFileSync, chmodSync, closeSync, cpSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, rmdirSync, statSync, unlinkSync, utimesSync, writeFileSync } from "node:fs";
24
24
  import { execFileSync, spawn } from "node:child_process";
25
25
  import { homedir, platform } from "node:os";
@@ -6700,7 +6700,7 @@ function createCognitiveTrajectoryTool(ctx) {
6700
6700
  } catch {}
6701
6701
  }
6702
6702
  }
6703
- const { queueRebuild } = await import("./rebuild-CNFvXPby.js").then((n) => n.n);
6703
+ const { queueRebuild } = await import("./rebuild-DVVb82zf.js").then((n) => n.n);
6704
6704
  const result = await queueRebuild(ctx, {
6705
6705
  root,
6706
6706
  note: args.note,
@@ -8609,16 +8609,25 @@ function isSessionMdRead(filePath) {
8609
8609
  /**
8610
8610
  * 把宿主产出的「前 N 行」接续成全文。
8611
8611
  *
8612
- * @param content 宿主给模型看的文本(单个 text 块的内容)
8613
- * @param absolutePath 真实文件路径(用于读全文;读不到就放行)
8612
+ * 🔴 **路径来源(真机踩过,v1.137.13 发布后当场发现)**:调用方传进来的 `file_path`
8613
+ * 往往是**相对路径**(如 `AGENT_SESSIONS/<轨迹>/SESSION.md`),而 `readFileSync` 按
8614
+ * **进程 cwd** 解析 —— 宿主进程的 cwd 不是 CCC 根 ⇒ 读到 ENOENT ⇒ 本模块静默放行,
8615
+ * **功能看起来"没生效"而实际是路径取错了**。
8616
+ * ⇒ 权威路径 = 宿主信封里的 `<path>`(`displayPath`,实测是绝对路径)。
8617
+ * ⚠️ 两者都试:**先信封、后参数**,并都要求绝对(相对路径无法可靠解析,⛔ 不猜)。
8618
+ * 安全性由**接缝核验**兜底:读错了文件 ⇒ 最后一行对不上 ⇒ 放行。
8619
+ *
8620
+ * @param content 宿主给模型看的文本(单个 text 块的内容)
8621
+ * @param hintPath 调用参数里的路径(兜底用;通常是相对路径)
8614
8622
  * @returns `text=null` 表示不接管
8615
8623
  */
8616
- function extendToWholeFile(content, absolutePath) {
8624
+ function extendToWholeFile(content, hintPath) {
8617
8625
  const m = ENVELOPE_RE.exec(content);
8618
8626
  if (!m) return {
8619
8627
  text: null,
8620
8628
  reason: "envelope-unrecognized"
8621
8629
  };
8630
+ const candidates = [m[1], hintPath ?? ""].filter((p) => p.length > 0 && isAbsolute(p));
8622
8631
  const body = m[2];
8623
8632
  const split = body.lastIndexOf("\n\n");
8624
8633
  if (split < 0) return {
@@ -8654,25 +8663,42 @@ function extendToWholeFile(content, absolutePath) {
8654
8663
  text: null,
8655
8664
  reason: "body-empty"
8656
8665
  };
8657
- let all;
8658
- try {
8659
- all = readFileSync(absolutePath, "utf-8").split("\n");
8660
- } catch {
8666
+ const lastGiven = given[given.length - 1];
8667
+ const readLines = (p) => {
8668
+ try {
8669
+ const lines = readFileSync(p, "utf-8").split("\n");
8670
+ if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
8671
+ return lines;
8672
+ } catch {
8673
+ return null;
8674
+ }
8675
+ };
8676
+ let all = null;
8677
+ let seamMismatch = false;
8678
+ for (const p of candidates) {
8679
+ const lines = readLines(p);
8680
+ if (lines === null) continue;
8681
+ if (lines.length <= lastGiven.number) {
8682
+ seamMismatch = true;
8683
+ break;
8684
+ }
8685
+ if (lines[lastGiven.number - 1] !== lastGiven.text) {
8686
+ seamMismatch = true;
8687
+ break;
8688
+ }
8689
+ all = lines;
8690
+ break;
8691
+ }
8692
+ if (all === null) {
8693
+ if (seamMismatch) return {
8694
+ text: null,
8695
+ reason: "seam-mismatch"
8696
+ };
8661
8697
  return {
8662
8698
  text: null,
8663
- reason: "file-unreadable"
8699
+ reason: candidates.length === 0 ? "no-absolute-path" : "file-unreadable"
8664
8700
  };
8665
8701
  }
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
8702
  const rest = all.slice(lastGiven.number).map((t, i) => `${lastGiven.number + 1 + i}: ${t}`);
8677
8703
  const extendedBody = [...bodyLinesText.split("\n"), ...rest].join("\n");
8678
8704
  const newFooter = `(End of file - total ${all.length} lines)`;
@@ -8724,7 +8750,7 @@ function registerSessionMdFullRead(ctx) {
8724
8750
  if (ds?.kind === "block") return downstream;
8725
8751
  const text = singleTextOf(result.content);
8726
8752
  if (text === null) return downstream;
8727
- const outcome = extendToWholeFile(singleTextOf(ds.content) ?? text, String(argPath));
8753
+ const outcome = extendToWholeFile(singleTextOf(ds.content) ?? text, typeof argPath === "string" ? argPath : void 0);
8728
8754
  if (outcome.text === null) return downstream;
8729
8755
  return {
8730
8756
  ...ds,
@@ -617,9 +617,11 @@ function extractAllHandoverNotes(text) {
617
617
  continue;
618
618
  }
619
619
  const head = i;
620
+ const inFence = fencedLineMask(lines, head);
620
621
  let end = lines.length;
621
622
  for (let j = head + 1; j < lines.length; j++) {
622
623
  const t = lines[j].trim();
624
+ if (inFence[j] === true) continue;
623
625
  if (t.startsWith("## ") || t.startsWith("# ")) {
624
626
  end = j;
625
627
  break;
@@ -627,12 +629,74 @@ function extractAllHandoverNotes(text) {
627
629
  }
628
630
  const section = lines.slice(head, end);
629
631
  while (section.length > 0 && section[section.length - 1].trim() === "") section.pop();
630
- out.push(section.join("\n"));
632
+ out.push(capNoteSection(section).join("\n"));
631
633
  i = end;
632
634
  }
633
635
  return out;
634
636
  }
635
637
  /**
638
+ * 代码围栏标记识别:``` 或 ```` (含前后空白、含 info string 如 ```ts)。
639
+ *
640
+ * @returns 围栏"种类"(反引号个数),非围栏行 ⇒ `null`。
641
+ * ⚠️ 用**长度**当种类:``` 与 ```` 是两种不同围栏,混用时不互相闭合(CommonMark 语义)。
642
+ */
643
+ function fenceMarkerOf(trimmedLine) {
644
+ const m = /^(`{3,})/.exec(trimmedLine);
645
+ return m ? m[1] : null;
646
+ }
647
+ /**
648
+ * 标出「哪些行在代码围栏内」(`mask[行号] === true` 表示该行属于围栏内容)。
649
+ *
650
+ * ## 🔴 未闭合围栏的处置(这条是判据,⛔ 不是实现细节)
651
+ *
652
+ * 围栏开着却一直没闭合(写到一半被中断、或围栏标记只是长得像),**怎么办**:
653
+ *
654
+ * | 选法 | 后果 |
655
+ * |---|---|
656
+ * | 认为"后面全在围栏内" | **整个文件剩余部分都会被吞进便签节** ⇒ 新代 = 旧代,轮转被架空 |
657
+ * | ✅ **只有真正闭合的围栏才算围栏** | 未闭合处标题照常当边界 ⇒ **宁可少搬,不可错搬大段** |
658
+ *
659
+ * ⇒ 取后者。判据与本仓反复出现的那条同向:**残缺的长文档比短的完整文档危险得多**;
660
+ * 而这里更严重 —— 吞掉的是别人的正文,且没有任何读数会说出来。
661
+ *
662
+ * ⚠️ 实现要点:**两遍**。第一遍只认**已闭合**的围栏(配对成功才标记);
663
+ * 到文件尾仍未闭合的开围栏,**整段不标记** ⇒ 其中的标题照常当边界。
664
+ */
665
+ function fencedLineMask(lines, scanFrom) {
666
+ const mask = new Array(lines.length).fill(false);
667
+ let fence = null;
668
+ let fenceStart = -1;
669
+ for (let j = scanFrom + 1; j < lines.length; j++) {
670
+ const mark = fenceMarkerOf(lines[j].trim());
671
+ if (mark === null) continue;
672
+ if (fence === null) {
673
+ fence = mark;
674
+ fenceStart = j;
675
+ } else if (mark === fence) {
676
+ for (let k = fenceStart; k <= j; k++) mask[k] = true;
677
+ fence = null;
678
+ fenceStart = -1;
679
+ }
680
+ }
681
+ return mask;
682
+ }
683
+ /**
684
+ * 超上限时截断,并**留下可见记号** —— ⛔ 绝不静默截断。
685
+ *
686
+ * 判据:**残缺的长文档比短的完整文档危险得多,它不报错**(v1.137.13 立的同一条)。
687
+ * ⇒ 记号必须写清:被截了多少行、全文在哪一代冻结件里。
688
+ */
689
+ function capNoteSection(section) {
690
+ if (section.length <= 300) return section;
691
+ const kept = section.slice(0, 300);
692
+ const omitted = section.length - 300;
693
+ return [
694
+ ...kept,
695
+ "",
696
+ `> ⚠️ **交接节已截断(truncated)**:本代便签原有 ${section.length} 行,超过 ACC 上限 300 行 ⇒ 只搬前 300 行,省略 ${omitted} 行。**完整内容在上一代冻结件里**(\`LOG/LOG-*.md\`),要找回请读那里。⛔ 不要把超长内容写进便签 —— 它每轮都会被整节搬运。`
697
+ ];
698
+ }
699
+ /**
636
700
  * 生成新一代 `LOG.md` 的出生头。
637
701
  *
638
702
  * ⚠️ **措辞归 CCC**:这里只给一个**可替换的默认模板**,各轨迹可以在自己的 PROMPT.md 里
@@ -15,11 +15,19 @@ export declare function isSessionMdRead(filePath: unknown): boolean;
15
15
  /**
16
16
  * 把宿主产出的「前 N 行」接续成全文。
17
17
  *
18
- * @param content 宿主给模型看的文本(单个 text 块的内容)
19
- * @param absolutePath 真实文件路径(用于读全文;读不到就放行)
18
+ * 🔴 **路径来源(真机踩过,v1.137.13 发布后当场发现)**:调用方传进来的 `file_path`
19
+ * 往往是**相对路径**(如 `AGENT_SESSIONS/<轨迹>/SESSION.md`),而 `readFileSync` 按
20
+ * **进程 cwd** 解析 —— 宿主进程的 cwd 不是 CCC 根 ⇒ 读到 ENOENT ⇒ 本模块静默放行,
21
+ * **功能看起来"没生效"而实际是路径取错了**。
22
+ * ⇒ 权威路径 = 宿主信封里的 `<path>`(`displayPath`,实测是绝对路径)。
23
+ * ⚠️ 两者都试:**先信封、后参数**,并都要求绝对(相对路径无法可靠解析,⛔ 不猜)。
24
+ * 安全性由**接缝核验**兜底:读错了文件 ⇒ 最后一行对不上 ⇒ 放行。
25
+ *
26
+ * @param content 宿主给模型看的文本(单个 text 块的内容)
27
+ * @param hintPath 调用参数里的路径(兜底用;通常是相对路径)
20
28
  * @returns `text=null` 表示不接管
21
29
  */
22
- export declare function extendToWholeFile(content: string, absolutePath: string): FullReadOutcome;
30
+ export declare function extendToWholeFile(content: string, hintPath?: string): FullReadOutcome;
23
31
  /**
24
32
  * 从一次成功 read 的 content 里取**单个 text 块**的正文。
25
33
  * 非单块 / 非 text ⇒ `null`(放行)。
@@ -103,6 +103,14 @@ export declare function extractHandoverNote(text: string): string | null;
103
103
  * (人可能续写、模板可能先占位),所以正确做法是**全搬**,不是"规定只能有一个"。
104
104
  */
105
105
  export declare function extractAllHandoverNotes(text: string): string[];
106
+ /**
107
+ * 便签节的**体量上限**(行数,`AC` 兜底,⛔ 不指望每条轨迹都把便签写短)。
108
+ *
109
+ * 🔴 **为什么需要**:真机上出现过 `1,488` 行的便签节 ⇒ 新代 = 5 行出生头 + 1,488 行 = **1,494 行**,
110
+ * 而冻结件是 `1,805` 行 ⇒ **轮转等于没轮转**("新代"几乎和旧代一样大)。
111
+ * 上限是**兜底**,不是常态:正常便签只有几十行。
112
+ */
113
+ export declare const MAX_HANDOVER_NOTE_LINES = 300;
106
114
  /** 读一个轨迹目录的日志状态(只读,不改任何东西)。 */
107
115
  export declare function readCarrierLogState(trajectoryDir: string): CarrierLogState;
108
116
  /** 轮转结果(**回执只说明"我做了什么",不说明"效果达成了"**)。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgroup/dsh-serenity-hooks",
3
- "version": "1.137.13",
3
+ "version": "1.137.15",
4
4
  "description": "宁静号 ACC harness(Native Cordis 插件)——给 DeepSeek Harness 装一个「AI 工作区」:13 个工具(container_fs/cognitive_trajectory/dashboard/container_git/msm/praxis/ontology/serenity-skill-creator/localstore/container_admin/browser_slot;另两个 im-bridge/diagram 按条件出现)+ 机械约束(安全模式/工作区围墙/密钥守卫/对外输出守卫)+ 认知轨迹日志与原地重建 + 网页登录入口/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": {