@shgroup/dsh-serenity-hooks 1.138.0 → 1.138.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.138.0",
3
+ "version": "1.138.1",
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": {
@@ -0,0 +1,98 @@
1
+ /**
2
+ * browser/domain-skill.ts —— 浏览器扩展 skill(域名强相关):加载 + 注入 + 访问台账
3
+ *
4
+ * 设计稿:`AGENT_SESSIONS/…S142…/proposals/browser-domain-skill-design.md`
5
+ * owner 原话(2026-11-23):「在宁静号根目录设定 BROWSER 目录,内部按域名建立文件夹,
6
+ * 每个文件夹下设 SKILL.md … 我们浏览器工具在打开某个域名的时候自动按目录找到 SKILL.md
7
+ * 并全文注入。」
8
+ *
9
+ * ## 三条设计判据(都是裁过的,⛔ 别在这里重新发明)
10
+ *
11
+ * 1. **注入附着在 `open`/`goto` 的**回执**上**(owner 裁「同意」)——
12
+ * ⛔ 不新增注入点、⛔ 不唤醒会话。理由:模型刚打开这个站、正要操作它,
13
+ * 时机比任何注入点都准;而新开注入点要回答"它唤醒吗"这一轴。
14
+ *
15
+ * 2. **未命中 ⇒ 回执一字不变**。绝大多数站不会有说明书,给它们留一句
16
+ * "本站无说明书"是纯噪声(每天几十次那种噪声会把真信号埋掉)。
17
+ *
18
+ * 3. **截断必须可见**。超限时给前 8 KB + 记号 + 完整路径。
19
+ * 静默截断比不注入更坏 —— 读者会以为那就是全部(1.137.15 的教训)。
20
+ *
21
+ * ## 与既有体系的关系(⛔ 不造第二真相源)
22
+ *
23
+ * - `.opencode/skills/` 是**能力**(怎么做一类事);这里是**单个站点的经验**。平行、不重叠。
24
+ * - `browser/ledger.ts` 是**槽位租约**台账;这里是**域名访问**台账。两个文件、互不引用,
25
+ * 只借它的锁实现(`O_EXCL` + temp→rename),⛔ 不借语义。
26
+ */
27
+ /** 单个 SKILL.md 进注入的体量上限(设计 §4.3)。超出则截断 + 可见记号。 */
28
+ export declare const DOMAIN_SKILL_MAX_BYTES: number;
29
+ /** 台账文件名(在 `BROWSER/` 下) */
30
+ export declare const VISIT_LEDGER_FILENAME = "_index.json";
31
+ /** BROWSER 根目录 */
32
+ export declare function browserRoot(cccRoot: string): string;
33
+ /** 某个域名的目录(不可用时返回 null) */
34
+ export declare function domainDir(cccRoot: string, urlOrHost: string): string | null;
35
+ /** SKILL.md 的绝对路径(**不判存在**,只要路径) */
36
+ export declare function domainSkillPath(cccRoot: string, urlOrHost: string): string | null;
37
+ /** 该域名是否已有说明书(**永远现算**,⛔ 不缓存进台账 —— 设计 §5.3) */
38
+ export declare function hasDomainSkill(cccRoot: string, urlOrHost: string): boolean;
39
+ export interface DomainSkillHit {
40
+ /** 要追加到回执里的整段文本(含抬头与可能的截断记号) */
41
+ text: string;
42
+ /** SKILL.md 的绝对路径(给用户看"完整内容在哪") */
43
+ path: string;
44
+ truncated: boolean;
45
+ }
46
+ /**
47
+ * 读该域名的说明书;未命中 ⇒ `null`(调用方**原样返回**回执,⛔ 不加任何噪声)。
48
+ *
49
+ * 读失败(权限、半写状态)也返回 `null` —— 打开页面的主流程**不因说明书而失败**。
50
+ */
51
+ export declare function loadDomainSkill(cccRoot: string, urlOrHost: string): DomainSkillHit | null;
52
+ export interface DomainVisit {
53
+ /** 累计打开次数 */
54
+ opens: number;
55
+ /** 最后一次打开时刻(ms) */
56
+ lastAt: number;
57
+ /** 最后一次来自哪条会话(回答"谁在用这个站") */
58
+ lastSession: string;
59
+ /** 最后一次用的哪个槽位 */
60
+ lastSlot: number;
61
+ }
62
+ export interface VisitLedger {
63
+ version: number;
64
+ domains: Record<string, DomainVisit>;
65
+ updatedAt: number;
66
+ }
67
+ export declare function visitLedgerPath(cccRoot: string): string;
68
+ /**
69
+ * 记一次访问(`open`/`goto` 当场调用)。
70
+ *
71
+ * 🔴 **必须在打开页面时就记,⛔ 不能等 release**:
72
+ * 释放会销毁进程、删 identity、清采样缓存 —— "用过哪些站"那一刻就没了。
73
+ *
74
+ * 任何异常都吞掉:记账是**旁路**,⛔ 不许让打开页面失败。
75
+ */
76
+ export declare function recordVisit(cccRoot: string, url: string, sessionId: string, slot: number): void;
77
+ /** 读整份访问台账(给 `diag`/`list` 与释放提示用) */
78
+ export declare function readVisits(cccRoot: string): VisitLedger;
79
+ /**
80
+ * 释放成功后的「写说明书」提示(设计 §5.4,owner 裁「跨会话累计」)。
81
+ *
82
+ * ## 为什么只有这一条通道
83
+ *
84
+ * owner 的触发点裁决是**浏览器主动释放**(⛔ 不是 ACC 发版、⛔ 不是定时器):
85
+ * 释放本来就是工作的自然终点,且 `releaseSlot()` 天然拿得到"谁用了哪个槽"。
86
+ *
87
+ * ## 降噪硬判据(照本仓既有教训,⛔ 每条都有代价)
88
+ *
89
+ * - **只在真的释放成功时**调用本函数(`released === true`);"本就无人占用"不提示 ——
90
+ * 什么都没发生,提示它等于凭空催人写文档。
91
+ * - **单次最多列 3 个**(按 opens 降序),其余折叠成一句"另有 N 个"。
92
+ * ⛔ 不列全:一次列出 10 个站,模型只会看一眼就跳过,等于没提示。
93
+ * - **必须带确切路径** —— ⛔ "你可以写一份"这种无法执行的话。
94
+ * - **每个站必须写清"用过几次"** —— 那是它值不值得写的唯一依据。
95
+ *
96
+ * @returns 追加到 release 回执后的文本;无值得提示的站 ⇒ 空串(回执保持原样)
97
+ */
98
+ export declare function domainSkillPrompt(cccRoot: string): string;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * browser/domain.ts —— 域名归一化(**唯一实现**)
3
+ *
4
+ * 设计稿:`AGENT_SESSIONS/…S142…/proposals/browser-domain-skill-design.md` §4.1 / §5.1
5
+ *
6
+ * 🔴 **为什么归一化只许写一次**:槽位动作(open/goto)、访问台账、SKILL 注入三处都要用它。
7
+ * 各写一份 ⇒ 三者会分叉,而分叉的表现是"目录名对不上" —— 那**没有报错**,
8
+ * 只会让说明书**静默失效**(打开 a.com 却读不到 `www.a.com` 目录里的经验)。
9
+ * 本仓为"两套判据必然分叉"付过多次代价 ⇒ 这里只出一个函数。
10
+ *
11
+ * 🔴 **纯函数、零依赖、不抛错**:一个坏 URL 不该炸掉 `open` 动作。
12
+ * 解析不了就返回 `null`,调用方按"没有域名"处理(⛔ 不是"报错")。
13
+ */
14
+ export interface DomainRef {
15
+ /** 归一化主机名(小写、剥 `www.`、保留端口)—— 用于台账键与展示 */
16
+ host: string;
17
+ /** 目录名(在 `host` 基础上把非法文件名字符换成 `_`)—— 用于 `<CCC>/BROWSER/<目录名>/` */
18
+ dirName: string;
19
+ }
20
+ /**
21
+ * 归一化一个 URL 到"站点身份"。
22
+ *
23
+ * @param url 任何字符串;非 http(s) 或无法解析 ⇒ `null`
24
+ */
25
+ export declare function normalizeDomain(url: string): DomainRef | null;
26
+ /** 只要目录名时的手感包装(`null` 原样返回)。 */
27
+ export declare function domainDirName(url: string): string | null;
@@ -86,6 +86,7 @@ export declare function waitSlotReady(root: string, n: number): Promise<{
86
86
  export declare function releaseSlot(root: string, sessionId: string, target: number): {
87
87
  ok: boolean;
88
88
  detail: string;
89
+ released: boolean;
89
90
  };
90
91
  /** list:全部槽位一览(含空槽) */
91
92
  export declare function listSlots(root: string, policy?: SlotPolicy): {
package/lib/index.js CHANGED
@@ -21810,11 +21810,13 @@ function releaseSlot(root, sessionId, target) {
21810
21810
  const lease = readLedger().leases[String(target)];
21811
21811
  if (!lease) return {
21812
21812
  ok: true,
21813
- detail: `槽位 ${slotLabel(target)} 本就无人占用(无需释放)。`
21813
+ detail: `槽位 ${slotLabel(target)} 本就无人占用(无需释放)。`,
21814
+ released: false
21814
21815
  };
21815
21816
  if (sessionId && lease.sessionId && lease.sessionId !== sessionId) return {
21816
21817
  ok: false,
21817
- detail: `槽位 ${slotLabel(target)} 不属于你(占用者:${lease.trajectory || lease.sessionId || "未知"})。\n ⛔ 不代别人释放 —— 它可能正在用。若确信它已废弃,用 \`browser_slot reap <槽>\`(看守动作,会记录原因)。`
21818
+ detail: `槽位 ${slotLabel(target)} 不属于你(占用者:${lease.trajectory || lease.sessionId || "未知"})。\n ⛔ 不代别人释放 —— 它可能正在用。若确信它已废弃,用 \`browser_slot reap <槽>\`(看守动作,会记录原因)。`,
21819
+ released: false
21818
21820
  };
21819
21821
  const destroyed = destroySlot(target, lease.pid);
21820
21822
  withLedger((lg) => {
@@ -21828,7 +21830,8 @@ function releaseSlot(root, sessionId, target) {
21828
21830
  sampleCache.delete(target);
21829
21831
  return {
21830
21832
  ok: true,
21831
- detail: `已释放槽位 ${slotLabel(target)}。${destroyed.detail}`
21833
+ detail: `已释放槽位 ${slotLabel(target)}。${destroyed.detail}`,
21834
+ released: true
21832
21835
  };
21833
21836
  }
21834
21837
  /** list:全部槽位一览(含空槽) */
@@ -22505,6 +22508,256 @@ function xyFormHint(param = "xy") {
22505
22508
  ].join("\n");
22506
22509
  }
22507
22510
  //#endregion
22511
+ //#region src/browser/domain.ts
22512
+ /**
22513
+ * 文件系统目录名里不能出现的字符 → `_`。
22514
+ *
22515
+ * 实测唯一会出现的非法字符是冒号(`a.com:8080`),但 Windows 上还有 `< > : " | ? *`
22516
+ * 与反斜杠。全域替换(而不是只处理冒号)是因为**同一个 CCC 可能被不同平台打开**。
22517
+ */
22518
+ const ILLEGAL_DIR_CHARS = /[<>:"|?*\\/]/g;
22519
+ /**
22520
+ * 归一化一个 URL 到"站点身份"。
22521
+ *
22522
+ * @param url 任何字符串;非 http(s) 或无法解析 ⇒ `null`
22523
+ */
22524
+ function normalizeDomain(url) {
22525
+ if (typeof url !== "string" || !url) return null;
22526
+ let parsed;
22527
+ try {
22528
+ parsed = new URL(url);
22529
+ } catch {
22530
+ return null;
22531
+ }
22532
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
22533
+ let host = parsed.hostname.toLowerCase();
22534
+ if (!host) return null;
22535
+ if (host.startsWith("www.") && host.length > 4) host = host.slice(4);
22536
+ if (parsed.port) host = `${host}:${parsed.port}`;
22537
+ return {
22538
+ host,
22539
+ dirName: host.replace(ILLEGAL_DIR_CHARS, "_")
22540
+ };
22541
+ }
22542
+ //#endregion
22543
+ //#region src/browser/domain-skill.ts
22544
+ /**
22545
+ * browser/domain-skill.ts —— 浏览器扩展 skill(域名强相关):加载 + 注入 + 访问台账
22546
+ *
22547
+ * 设计稿:`AGENT_SESSIONS/…S142…/proposals/browser-domain-skill-design.md`
22548
+ * owner 原话(2026-11-23):「在宁静号根目录设定 BROWSER 目录,内部按域名建立文件夹,
22549
+ * 每个文件夹下设 SKILL.md … 我们浏览器工具在打开某个域名的时候自动按目录找到 SKILL.md
22550
+ * 并全文注入。」
22551
+ *
22552
+ * ## 三条设计判据(都是裁过的,⛔ 别在这里重新发明)
22553
+ *
22554
+ * 1. **注入附着在 `open`/`goto` 的**回执**上**(owner 裁「同意」)——
22555
+ * ⛔ 不新增注入点、⛔ 不唤醒会话。理由:模型刚打开这个站、正要操作它,
22556
+ * 时机比任何注入点都准;而新开注入点要回答"它唤醒吗"这一轴。
22557
+ *
22558
+ * 2. **未命中 ⇒ 回执一字不变**。绝大多数站不会有说明书,给它们留一句
22559
+ * "本站无说明书"是纯噪声(每天几十次那种噪声会把真信号埋掉)。
22560
+ *
22561
+ * 3. **截断必须可见**。超限时给前 8 KB + 记号 + 完整路径。
22562
+ * 静默截断比不注入更坏 —— 读者会以为那就是全部(1.137.15 的教训)。
22563
+ *
22564
+ * ## 与既有体系的关系(⛔ 不造第二真相源)
22565
+ *
22566
+ * - `.opencode/skills/` 是**能力**(怎么做一类事);这里是**单个站点的经验**。平行、不重叠。
22567
+ * - `browser/ledger.ts` 是**槽位租约**台账;这里是**域名访问**台账。两个文件、互不引用,
22568
+ * 只借它的锁实现(`O_EXCL` + temp→rename),⛔ 不借语义。
22569
+ */
22570
+ /** 单个 SKILL.md 进注入的体量上限(设计 §4.3)。超出则截断 + 可见记号。 */
22571
+ const DOMAIN_SKILL_MAX_BYTES = 8192;
22572
+ /** 台账文件名(在 `BROWSER/` 下) */
22573
+ const VISIT_LEDGER_FILENAME = "_index.json";
22574
+ /** BROWSER 根目录 */
22575
+ function browserRoot(cccRoot) {
22576
+ return join(cccRoot, "BROWSER");
22577
+ }
22578
+ /** 某个域名的目录(不可用时返回 null) */
22579
+ function domainDir(cccRoot, urlOrHost) {
22580
+ const dirName = normalizeDomain(urlOrHost)?.dirName ?? normalizeDomain(`https://${urlOrHost}`)?.dirName ?? null;
22581
+ return dirName ? join(browserRoot(cccRoot), dirName) : null;
22582
+ }
22583
+ /** SKILL.md 的绝对路径(**不判存在**,只要路径) */
22584
+ function domainSkillPath(cccRoot, urlOrHost) {
22585
+ const d = domainDir(cccRoot, urlOrHost);
22586
+ return d ? join(d, "SKILL.md") : null;
22587
+ }
22588
+ /** 该域名是否已有说明书(**永远现算**,⛔ 不缓存进台账 —— 设计 §5.3) */
22589
+ function hasDomainSkill(cccRoot, urlOrHost) {
22590
+ const p = domainSkillPath(cccRoot, urlOrHost);
22591
+ return !!p && existsSync(p);
22592
+ }
22593
+ /**
22594
+ * 读该域名的说明书;未命中 ⇒ `null`(调用方**原样返回**回执,⛔ 不加任何噪声)。
22595
+ *
22596
+ * 读失败(权限、半写状态)也返回 `null` —— 打开页面的主流程**不因说明书而失败**。
22597
+ */
22598
+ function loadDomainSkill(cccRoot, urlOrHost) {
22599
+ const p = domainSkillPath(cccRoot, urlOrHost);
22600
+ if (!p) return null;
22601
+ let raw;
22602
+ try {
22603
+ if (!existsSync(p)) return null;
22604
+ raw = readFileSync(p, "utf8");
22605
+ } catch {
22606
+ return null;
22607
+ }
22608
+ const truncated = Buffer.byteLength(raw, "utf8") > DOMAIN_SKILL_MAX_BYTES;
22609
+ let body = raw;
22610
+ if (truncated) {
22611
+ body = raw.slice(0, DOMAIN_SKILL_MAX_BYTES);
22612
+ body += `\n\n──── ⚠️ 说明书已截断(只显示前 ${DOMAIN_SKILL_MAX_BYTES} 字节)────\n完整内容:${p}\n⛔ 不要以为上面就是全部 —— 缺的那部分可能正是你要找的坑。\n`;
22613
+ }
22614
+ return {
22615
+ text: `\n\n──── 本站说明书(BROWSER/${normalizeDomain(urlOrHost)?.dirName ?? urlOrHost}/SKILL.md)────\n` + body,
22616
+ path: p,
22617
+ truncated
22618
+ };
22619
+ }
22620
+ function visitLedgerPath(cccRoot) {
22621
+ return join(browserRoot(cccRoot), VISIT_LEDGER_FILENAME);
22622
+ }
22623
+ function readVisitLedger(cccRoot) {
22624
+ const empty = {
22625
+ version: 1,
22626
+ domains: {},
22627
+ updatedAt: 0
22628
+ };
22629
+ try {
22630
+ const raw = JSON.parse(readFileSync(visitLedgerPath(cccRoot), "utf8"));
22631
+ const domains = {};
22632
+ for (const [k, v] of Object.entries(raw?.domains ?? {})) {
22633
+ const d = v;
22634
+ if (typeof k !== "string" || !k) continue;
22635
+ domains[k] = {
22636
+ opens: Number(d?.opens) || 0,
22637
+ lastAt: Number(d?.lastAt) || 0,
22638
+ lastSession: typeof d?.lastSession === "string" ? d.lastSession : "",
22639
+ lastSlot: Number(d?.lastSlot) || 0
22640
+ };
22641
+ }
22642
+ return {
22643
+ version: Number(raw?.version) || 1,
22644
+ domains,
22645
+ updatedAt: Number(raw?.updatedAt) || 0
22646
+ };
22647
+ } catch {
22648
+ return empty;
22649
+ }
22650
+ }
22651
+ function writeVisitLedger(cccRoot, ledger) {
22652
+ const p = visitLedgerPath(cccRoot);
22653
+ mkdirSync(dirname(p), { recursive: true });
22654
+ const tmp = `${p}.tmp-${process.pid}-${Date.now()}`;
22655
+ writeFileSync(tmp, JSON.stringify({
22656
+ ...ledger,
22657
+ updatedAt: Date.now()
22658
+ }, null, 2), "utf8");
22659
+ renameSync(tmp, p);
22660
+ }
22661
+ /**
22662
+ * 在锁内做「读 → 改 → 写」。
22663
+ *
22664
+ * 🔴 为什么连锁的实现也要抄 `ledger.ts` 那套而不另造:本机 13+ 个 live 会话会**并发**打开页面,
22665
+ * 整文件读改写会**静默丢键**(`localstore.json` 已为这个病付过代价)。
22666
+ * ⚠️ 但这是**另一个文件、另一把锁**(`_index.json.lock`)——⛔ 不与槽位台账共用锁,
22667
+ * 否则一次域名记账会阻塞整个槽位系统。
22668
+ */
22669
+ function withVisitLedger(cccRoot, update) {
22670
+ const p = visitLedgerPath(cccRoot);
22671
+ mkdirSync(dirname(p), { recursive: true });
22672
+ const lock = p + ".lock";
22673
+ const deadline = Date.now() + 3e3;
22674
+ let acquired = false;
22675
+ while (Date.now() < deadline) try {
22676
+ writeFileSync(lock, String(process.pid), { flag: "wx" });
22677
+ acquired = true;
22678
+ break;
22679
+ } catch {
22680
+ try {
22681
+ if (Date.now() - statSync(lock).mtimeMs > 1e4) rmSync(lock, { force: true });
22682
+ } catch {}
22683
+ const until = Date.now() + 20;
22684
+ while (Date.now() < until);
22685
+ }
22686
+ if (!acquired) return void 0;
22687
+ try {
22688
+ const cur = readVisitLedger(cccRoot);
22689
+ const result = update(cur);
22690
+ writeVisitLedger(cccRoot, cur);
22691
+ return result;
22692
+ } finally {
22693
+ rmSync(lock, { force: true });
22694
+ }
22695
+ }
22696
+ /**
22697
+ * 记一次访问(`open`/`goto` 当场调用)。
22698
+ *
22699
+ * 🔴 **必须在打开页面时就记,⛔ 不能等 release**:
22700
+ * 释放会销毁进程、删 identity、清采样缓存 —— "用过哪些站"那一刻就没了。
22701
+ *
22702
+ * 任何异常都吞掉:记账是**旁路**,⛔ 不许让打开页面失败。
22703
+ */
22704
+ function recordVisit(cccRoot, url, sessionId, slot) {
22705
+ const ref = normalizeDomain(url);
22706
+ if (!ref) return;
22707
+ try {
22708
+ withVisitLedger(cccRoot, (lg) => {
22709
+ const prev = lg.domains[ref.host];
22710
+ lg.domains[ref.host] = {
22711
+ opens: (prev?.opens ?? 0) + 1,
22712
+ lastAt: Date.now(),
22713
+ lastSession: sessionId || prev?.lastSession || "",
22714
+ lastSlot: slot || prev?.lastSlot || 0
22715
+ };
22716
+ });
22717
+ } catch {}
22718
+ }
22719
+ /** 读整份访问台账(给 `diag`/`list` 与释放提示用) */
22720
+ function readVisits(cccRoot) {
22721
+ return readVisitLedger(cccRoot);
22722
+ }
22723
+ /**
22724
+ * 释放成功后的「写说明书」提示(设计 §5.4,owner 裁「跨会话累计」)。
22725
+ *
22726
+ * ## 为什么只有这一条通道
22727
+ *
22728
+ * owner 的触发点裁决是**浏览器主动释放**(⛔ 不是 ACC 发版、⛔ 不是定时器):
22729
+ * 释放本来就是工作的自然终点,且 `releaseSlot()` 天然拿得到"谁用了哪个槽"。
22730
+ *
22731
+ * ## 降噪硬判据(照本仓既有教训,⛔ 每条都有代价)
22732
+ *
22733
+ * - **只在真的释放成功时**调用本函数(`released === true`);"本就无人占用"不提示 ——
22734
+ * 什么都没发生,提示它等于凭空催人写文档。
22735
+ * - **单次最多列 3 个**(按 opens 降序),其余折叠成一句"另有 N 个"。
22736
+ * ⛔ 不列全:一次列出 10 个站,模型只会看一眼就跳过,等于没提示。
22737
+ * - **必须带确切路径** —— ⛔ "你可以写一份"这种无法执行的话。
22738
+ * - **每个站必须写清"用过几次"** —— 那是它值不值得写的唯一依据。
22739
+ *
22740
+ * @returns 追加到 release 回执后的文本;无值得提示的站 ⇒ 空串(回执保持原样)
22741
+ */
22742
+ function domainSkillPrompt(cccRoot) {
22743
+ try {
22744
+ const ledger = readVisitLedger(cccRoot);
22745
+ const missing = Object.entries(ledger.domains).filter(([host]) => !hasDomainSkill(cccRoot, host));
22746
+ if (missing.length === 0) return "";
22747
+ missing.sort((a, b) => b[1].opens - a[1].opens || b[1].lastAt - a[1].lastAt);
22748
+ const shown = missing.slice(0, 3);
22749
+ const rest = missing.length - shown.length;
22750
+ const lines = shown.map(([host, v]) => {
22751
+ const p = domainSkillPath(cccRoot, host);
22752
+ return ` · ${host} 累计 ${v.opens} 次 ⛔ 还没有说明书\n → ${p}`;
22753
+ });
22754
+ if (rest > 0) lines.push(` · 另有 ${rest} 个站用过但没有说明书(这张表在 BROWSER/_index.json)`);
22755
+ return `\n──── BROWSER 域名台账(有站还没写说明书)────\n` + lines.join("\n") + "\n\n想让下次省一轮摸索,就把这次的经验按四段写进去:\n 这站的特殊之处 / 已知坑 / 有效操作序列 / 失效记录\n⚠️ 每条坑都要写「怎么发现的」—— 只有\"有效操作\"不成,后人重建不出来。\n";
22756
+ } catch {
22757
+ return "";
22758
+ }
22759
+ }
22760
+ //#endregion
22508
22761
  //#region src/tools/browser-slot/index.ts
22509
22762
  /**
22510
22763
  * tools/browser-slot/index.ts — browser_slot 工具(ACC 级浏览器槽位管理器)
@@ -22615,6 +22868,27 @@ function extArgs(args) {
22615
22868
  }
22616
22869
  return out;
22617
22870
  }
22871
+ /**
22872
+ * `open`/`goto` 回执的**域名说明书尾巴**(owner 2026-11-23 令:浏览器扩展 skill 域名强相关)。
22873
+ *
22874
+ * 🔴 为什么是"回执尾巴"而⛔ 不是新注入点:模型刚打开这个站、正要操作它 ——
22875
+ * 此刻把说明书写进**这次调用的结果**里,时机最准,且**零唤醒风险**
22876
+ * (`kernel/injection-sites.ts` 那张表的 `wakes` 一轴一行都不用改)。
22877
+ *
22878
+ * 🔴 未命中 ⇒ **返回空串**,回执与今天**逐字相同**:绝大多数站没有说明书,
22879
+ * 给它们加一句"本站无说明书"是每天几十次的纯噪声,会把真信号埋掉。
22880
+ *
22881
+ * ⚠️ 任何异常都吞掉 —— 说明书是旁路,⛔ 不许让"打开网页"因它失败。
22882
+ */
22883
+ function domainSkillTail(root, url, sessionId, slot) {
22884
+ try {
22885
+ recordVisit(root, url, sessionId, slot);
22886
+ const hit = loadDomainSkill(root, url);
22887
+ return hit ? hit.text : "";
22888
+ } catch {
22889
+ return "";
22890
+ }
22891
+ }
22618
22892
  /** 动作实现 */
22619
22893
  async function run(ctx, root, sessionId, trajectory, action, args) {
22620
22894
  switch (action) {
@@ -22635,7 +22909,8 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
22635
22909
  case "release": {
22636
22910
  const n = normalizeSlotId(String(args.slot ?? ""));
22637
22911
  if (n === 0) return "⛔ 需要槽位号:release 需要 --slot <b1..b20>";
22638
- return releaseSlot(root, sessionId, n).detail;
22912
+ const r = releaseSlot(root, sessionId, n);
22913
+ return r.detail + (r.released && r.ok ? domainSkillPrompt(root) : "");
22639
22914
  }
22640
22915
  case "reap": {
22641
22916
  const n = normalizeSlotId(String(args.slot ?? ""));
@@ -22673,6 +22948,14 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
22673
22948
  }
22674
22949
  lines.push("");
22675
22950
  lines.push("用法:acquire(自动挑空槽,可 --slot 指定)· release(用完必须交还)· status --slot b1");
22951
+ const visits = Object.entries(readVisits(root).domains).sort((a, b) => b[1].opens - a[1].opens || b[1].lastAt - a[1].lastAt);
22952
+ if (visits.length > 0) {
22953
+ const missing = visits.filter(([h]) => !hasDomainSkill(root, h)).length;
22954
+ lines.push("");
22955
+ lines.push(`域名台账 ${visits.length} 个站${missing > 0 ? `(${missing} 个还没有说明书)` : "(都有说明书)"}:`);
22956
+ for (const [h, v] of visits.slice(0, 5)) lines.push(` ${hasDomainSkill(root, h) ? "✓" : "·"} ${h.padEnd(28)} ${v.opens} 次`);
22957
+ if (visits.length > 5) lines.push(` ……另有 ${visits.length - 5} 个(BROWSER/_index.json)`);
22958
+ }
22676
22959
  return lines.join("\n");
22677
22960
  }
22678
22961
  case "doctor": return JSON.stringify(doctorSlots(root), null, 2);
@@ -22686,7 +22969,7 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
22686
22969
  const n = needSlot(args);
22687
22970
  const url = str(args.url);
22688
22971
  if (!url) return "⛔ 需要 --url=<地址>";
22689
- return `[browser_slot] targetId=${await slotOpen(root, n, sessionId, url)}`;
22972
+ return `[browser_slot] targetId=${await slotOpen(root, n, sessionId, url)}` + domainSkillTail(root, url, sessionId, n);
22690
22973
  }
22691
22974
  case "goto": {
22692
22975
  const n = needSlot(args);
@@ -22694,7 +22977,7 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
22694
22977
  if (!url) return "⛔ 需要 --url=<地址>";
22695
22978
  const target = await needTarget(root, n, sessionId, args);
22696
22979
  await slotGoto(root, n, sessionId, target, url);
22697
- return `[browser_slot] navigate ${target} → ${url}`;
22980
+ return `[browser_slot] navigate ${target} → ${url}` + domainSkillTail(root, url, sessionId, n);
22698
22981
  }
22699
22982
  case "eval": {
22700
22983
  const n = needSlot(args);
@@ -22853,7 +23136,7 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
22853
23136
  function createBrowserSlotTool(ctx) {
22854
23137
  return defineTool({
22855
23138
  name: "browser_slot",
22856
- description: "Browser slot manager (ACC-level, max 20 Chrome slots). Each slot = one isolated Chrome process with its own profile dir, fixed resolution, and a CDP port (9301+). Slots carry state: free / leased / stale (idle too long, CPU or memory over threshold, lease expired) / orphaned (process died). Actions: acquire (lease a slot; reuses your existing lease instead of leasing a second one) / release (REQUIRED when done — a background watchman nudges you if you forget, and **force-reclaims after ~30 min of silence**) / list (all slots + occupancy) / status --slot <bN> / hold --slot <bN> --holdFor <minutes> [--reason] (keep-alive: the idle reclaim skips a held slot; use it before long downloads or slow queries — no permanent hold) / reap --slot <bN> (force-reclaim an abandoned slot, records a reason) / doctor (self-check, read-only). PAGE: targets / open / goto / eval / text / html / shot / reload / close / click (text or xy, real mouse events). HIGH-LEVEL (v1.130.0): ax (accessibility-tree snapshot -> stable `ref` like e12345; the only honest answer to \"is this control clickable\") / press (semantic keys & chords: Enter, Escape, Control+A; non-ASCII text must use `type`) / type (browser text input at the focused element) / fill --ref --value (native setter + input/change so React/Vue actually see it; receipt reports the READ-BACK value) / scroll (real wheel events, so lazy-loading and virtual lists fire) / wait --for <selector:|text:|url:|gone:|js:> (in-page polling; timeout says WHAT it waited for and what it last read) / drag --from --to (multi-step mouseMoved; one-jump drags are ignored by sortablejs & friends) / upload --ref --file (paths must stay inside the CCC root) / downloads (pins the capture dir to _tmp/browser-downloads/<slot>) / dialog (default DISMISS — OK often means delete/pay/publish). 🔴 Lease before you drive a browser for evidence, and ALWAYS release when finished — an unreleased slot keeps a Chrome process alive and burns power.",
23139
+ description: "Browser slot manager (ACC-level, max 20 Chrome slots). Each slot = one isolated Chrome process with its own profile dir, fixed resolution, and a CDP port (9301+). Slots carry state: free / leased / stale (idle too long, CPU or memory over threshold, lease expired) / orphaned (process died). Actions: acquire (lease a slot; reuses your existing lease instead of leasing a second one) / release (REQUIRED when done — a background watchman nudges you if you forget, and **force-reclaims after ~30 min of silence**) / list (all slots + occupancy) / status --slot <bN> / hold --slot <bN> --holdFor <minutes> [--reason] (keep-alive: the idle reclaim skips a held slot; use it before long downloads or slow queries — no permanent hold) / reap --slot <bN> (force-reclaim an abandoned slot, records a reason) / doctor (self-check, read-only). PAGE: targets / open / goto / eval / text / html / shot / reload / close / click (text or xy, real mouse events). HIGH-LEVEL (v1.130.0): ax (accessibility-tree snapshot -> stable `ref` like e12345; the only honest answer to \"is this control clickable\") / press (semantic keys & chords: Enter, Escape, Control+A; non-ASCII text must use `type`) / type (browser text input at the focused element) / fill --ref --value (native setter + input/change so React/Vue actually see it; receipt reports the READ-BACK value) / scroll (real wheel events, so lazy-loading and virtual lists fire) / wait --for <selector:|text:|url:|gone:|js:> (in-page polling; timeout says WHAT it waited for and what it last read) / drag --from --to (multi-step mouseMoved; one-jump drags are ignored by sortablejs & friends) / upload --ref --file (paths must stay inside the CCC root) / downloads (pins the capture dir to _tmp/browser-downloads/<slot>) / dialog (default DISMISS — OK often means delete/pay/publish). 🔴 Lease before you drive a browser for evidence, and ALWAYS release when finished — an unreleased slot keeps a Chrome process alive and burns power. DOMAIN SKILL (browser extension skill — per-site know-how): `open`/`goto` automatically append `BROWSER/<domain>/SKILL.md` to their receipt when that site has one (nothing is added when it does not — silence means \"no notes for this site yet\"). On a successful `release` the receipt lists sites you have used that still have no SKILL.md, with the exact path to write. When a site gives you trouble twice, record what you learned there (four sections: quirks / known traps with how you found them / working sequence / what failed).",
22857
23140
  parameters: {
22858
23141
  action: {
22859
23142
  type: "string",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgroup/dsh-serenity-hooks",
3
- "version": "1.138.0",
3
+ "version": "1.138.1",
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": {