@shgroup/dsh-serenity-hooks 1.117.0 → 1.118.0

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.117.0",
3
+ "version": "1.118.0",
4
4
  "main": "lib/index.js",
5
5
  "description": "宁静号 ACC harness(Native Cordis 插件):给 DSH 装一个「AI 工作区」——12 个工具(container_fs/cognitive_trajectory/dashboard/container_git/msm/praxis/ontology/serenity-skill-creator/localstore/container_admin;另两个 im-bridge/diagram 按配置条件出现)+ 机械约束(安全模式/工作区围墙/密钥守卫)+ 认知轨迹日志与原地重建 + 网页登录入口/IM 桥/认知轨迹唤醒注册表。轨迹声明 = 轨迹目录下的 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/client.js CHANGED
@@ -4054,6 +4054,163 @@ Instruction-following style:
4054
4054
  });
4055
4055
  }
4056
4056
  //#endregion
4057
+ //#region src/client/HumorEditor.tsx
4058
+ /**
4059
+ * client/HumorEditor.tsx — 脱口秀片段面板编辑器(D287,2026-11-04 owner 想法)
4060
+ *
4061
+ * ## owner 原话
4062
+ *
4063
+ * > 「在 Serenity 的配置页填写好了,这样比较方便」
4064
+ * > 「收集 30 段,每次随机注入一段;在提示词中要诚恳:先来看看这段脱口秀片段再继续阅读吧」
4065
+ *
4066
+ * ## 交互设计(三个刻意的选择)
4067
+ *
4068
+ * ### ① 一个多行框 + `---` 分隔,⛔ 不是 30 个输入框
4069
+ *
4070
+ * 30 个独立的 input 会让面板变成一堵墙,而且粘贴 30 段要点 30 次。
4071
+ * ⇒ **一个 textarea,`---` 独行分隔**:一次粘贴全部、随时增删、肉眼可见边界。
4072
+ *
4073
+ * ### ② 实时显示段数
4074
+ *
4075
+ * 判据:owner 说"收集 30 段",那**填的时候就要能看见现在有几段** ——
4076
+ * 否则填到第 28 段无从确认。这里显示「当前 N 段」,并提示空段会被忽略。
4077
+ *
4078
+ * ### ③ 原文住用户配置,⛔ 不进仓
4079
+ *
4080
+ * 本仓是 GitHub 公开仓。段子是有版权的创作文本 ⇒
4081
+ * 存在 `~/.dsh/serenity-hooks.json`(仓外),本组件只负责编辑它。
4082
+ * ⛔ 不要往仓库里的任何文件贴段子原文。
4083
+ */
4084
+ /** 段分隔符(**独占一行**的 `---`);选中它是因为它不会出现在正常段子里 */
4085
+ const SEP = "---";
4086
+ /** 把 textarea 原文按分隔符拆成段(去空段、trim) */
4087
+ function splitBits(raw) {
4088
+ return raw.split(/^---\s*$/m).map((s) => s.trim()).filter((s) => s !== "");
4089
+ }
4090
+ /** 把段数组写回 textarea 形态(与 splitBits 互逆) */
4091
+ function joinBits(bits) {
4092
+ return bits.join(`\n${SEP}\n`);
4093
+ }
4094
+ function HumorEditor() {
4095
+ const [enabled, setEnabled] = (0, react.useState)(false);
4096
+ const [raw, setRaw] = (0, react.useState)("");
4097
+ const [loaded, setLoaded] = (0, react.useState)(false);
4098
+ const [busy, setBusy] = (0, react.useState)(false);
4099
+ const [error, setError] = (0, react.useState)(null);
4100
+ const [saved, setSaved] = (0, react.useState)(false);
4101
+ const bits = splitBits(raw);
4102
+ (0, react.useEffect)(() => {
4103
+ let alive = true;
4104
+ fetchConfig().then((cfg) => {
4105
+ if (!alive || !cfg) return;
4106
+ setEnabled(cfg.config?.humor?.enabled === true);
4107
+ setRaw(joinBits(cfg.config?.humor?.bits ?? []));
4108
+ setLoaded(true);
4109
+ });
4110
+ return () => {
4111
+ alive = false;
4112
+ };
4113
+ }, []);
4114
+ const save = () => {
4115
+ setBusy(true);
4116
+ setError(null);
4117
+ setSaved(false);
4118
+ saveConfig({ humor: {
4119
+ enabled,
4120
+ bits
4121
+ } }).then((cfg) => {
4122
+ if (cfg) {
4123
+ setEnabled(cfg.humor?.enabled === true);
4124
+ setRaw(joinBits(cfg.humor?.bits ?? []));
4125
+ setSaved(true);
4126
+ setTimeout(() => setSaved(false), 2e3);
4127
+ }
4128
+ }).catch((e) => setError(e instanceof Error ? e.message : String(e))).finally(() => setBusy(false));
4129
+ };
4130
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4131
+ className: "pe-wrap",
4132
+ children: [
4133
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4134
+ className: "pe-row",
4135
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
4136
+ className: "pe-label",
4137
+ htmlFor: "hu-enabled",
4138
+ children: [
4139
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
4140
+ id: "hu-enabled",
4141
+ type: "checkbox",
4142
+ checked: enabled,
4143
+ onChange: (e) => setEnabled(e.target.checked)
4144
+ }),
4145
+ " ",
4146
+ "启用(缺省关;纯装饰,不影响任何判断)"
4147
+ ]
4148
+ })
4149
+ }),
4150
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4151
+ className: "pe-row",
4152
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
4153
+ className: "pe-label",
4154
+ htmlFor: "hu-bits",
4155
+ children: [
4156
+ "片段池 —— 用独占一行的 ",
4157
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: SEP }),
4158
+ " 分隔各段;当前 ",
4159
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: bits.length }),
4160
+ " 段"
4161
+ ]
4162
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
4163
+ id: "hu-bits",
4164
+ className: "pe-textarea",
4165
+ rows: 14,
4166
+ value: raw,
4167
+ placeholder: `第一段完整文本\n${SEP}\n第二段完整文本\n${SEP}\n第三段……\n\n每段会被完整注入,不会截断;空段自动忽略。
4168
+ 每开启一条新会话随机选一段,会话进行中保持不变。`,
4169
+ onChange: (e) => setRaw(e.target.value)
4170
+ })]
4171
+ }),
4172
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4173
+ className: "pe-actions",
4174
+ children: [
4175
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4176
+ className: "pe-btn pe-btnGhost",
4177
+ type: "button",
4178
+ onClick: () => setRaw(joinBits([...bits, ""])),
4179
+ disabled: !loaded,
4180
+ children: "追加一段"
4181
+ }),
4182
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4183
+ className: "pe-btn pe-btnGhost",
4184
+ type: "button",
4185
+ onClick: () => setRaw(""),
4186
+ disabled: !loaded,
4187
+ children: "清空"
4188
+ }),
4189
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4190
+ className: "pe-btn pe-btnPrimary",
4191
+ type: "button",
4192
+ onClick: save,
4193
+ disabled: busy || !loaded,
4194
+ children: busy ? "保存中…" : "保存"
4195
+ })
4196
+ ]
4197
+ }),
4198
+ enabled && bits.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4199
+ className: "pe-hint pe-hintErr",
4200
+ children: "已启用但池是空的 ⇒ 实际不注入任何内容(等于关闭)。"
4201
+ }),
4202
+ saved && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4203
+ className: "pe-hint pe-hintOk",
4204
+ children: "已保存,新会话即时生效"
4205
+ }),
4206
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4207
+ className: "pe-hint pe-hintErr",
4208
+ children: error
4209
+ })
4210
+ ]
4211
+ });
4212
+ }
4213
+ //#endregion
4057
4214
  //#region src/client/ImBridgeEditor.tsx
4058
4215
  /**
4059
4216
  * ImBridgeEditor.tsx — 「IM 桥」配置区块(原 `WeixinBridgeEditor`,2026-10-19 泛化)
@@ -4997,6 +5154,11 @@ Instruction-following style:
4997
5154
  desc: "替换输出风格提示词(默认关闭)",
4998
5155
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PersonaEditor, {})
4999
5156
  }),
5157
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Collapse, {
5158
+ title: "脱口秀片段",
5159
+ desc: "会话开始时随机注入一段到系统提示词(纯装饰,默认关闭)",
5160
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HumorEditor, {})
5161
+ }),
5000
5162
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Collapse, {
5001
5163
  title: "IM 桥",
5002
5164
  desc: "绑定即时通讯账号 · 路由到认知轨迹(CCC 级配置)",
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-DKlpuFN_.js";
7
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-qqnsi8tc.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-Djqz4Noy.js";
9
- import { A as truncateContent, C as verifyTotpCode, D as buildResourceIndex, E as SKILL_ONTOLOGY_FILE, M as hasTrajectoryPrompt, O as buildResourceNameSuffix, S as MECHANISM_PORTS, T as REFERENCE_DIR, _ as projectKnownWorkspaces, a as trajectoryConstraintFor, b as verifyPassword, c as trajectoryWorkspaceMdPath, d as splitModel, f as registerCognitiveTrajectorySkillSection, g as migrateLegacyLocalstore, h as applyWirePatch, i as getTrajectoryAgent, j as TRAJECTORY_PROMPT_FILENAME, k as isSafeSkillName, 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 recordToolUsage, x as FACE_PORTS, y as toWire } from "./session-BVBI5jch.js";
9
+ import { A as truncateContent, C as verifyTotpCode, D as buildResourceIndex, E as SKILL_ONTOLOGY_FILE, M as hasTrajectoryPrompt, O as buildResourceNameSuffix, S as MECHANISM_PORTS, T as REFERENCE_DIR, _ as projectKnownWorkspaces, a as trajectoryConstraintFor, b as verifyPassword, c as trajectoryWorkspaceMdPath, d as splitModel, f as registerCognitiveTrajectorySkillSection, g as migrateLegacyLocalstore, h as applyWirePatch, i as getTrajectoryAgent, j as TRAJECTORY_PROMPT_FILENAME, k as isSafeSkillName, 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 recordToolUsage, x as FACE_PORTS, y as toWire } from "./session-D3Zsxoip.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 } from "./injection-B5jZxemg.js";
11
11
  import { _ as addWake, a as DEFAULT_LOOKBACK_MS, c as projectDirNameForCwd, d as registerCroTurnTracking, f as registerDisposer, g as WAKE_CATCH_UP_MS, h as CARRIER_OPENING_MARK, l as scanInterruptedSessions, o as createResumeOne, p as buildCroSnapshot, r as sendToCognitiveTrajectory, s as formatPendingTools, t as registerWakeScheduler, u as listRunningSessionIds } from "./scheduler-CUPz7geH.js";
12
12
  import { i as sessionsRootDir } from "./cleanup-CPl1SSaK.js";
@@ -51,6 +51,23 @@ interface PersonaSettings {
51
51
  /** 用户替换文本(替代 EAP 块 + MSM 原则段的原文) */
52
52
  overrideText: string;
53
53
  }
54
+ /**
55
+ * 脱口秀片段(2026-11-04 owner 想法):
56
+ * 「收集一版各类脱口秀的片段内容,随机在会话开始 / rebuild 时注入一段到系统提示词,
57
+ * 这个不会改变什么行为,但是会让过程变得有趣」+「要有个开关」。
58
+ *
59
+ * 🔴 **原文住在用户配置里,⛔ 不进仓**:本仓是 GitHub 公开仓,段子是有版权的创作文本。
60
+ * 机制在 ACC(怎么选、怎么注入),措辞在用户配置(填什么)—— 与 D23 同款分工。
61
+ */
62
+ interface HumorSettings {
63
+ /** 总开关(缺省 **关**:纯装饰不该是默认状态) */
64
+ enabled: boolean;
65
+ /**
66
+ * 片段池(每项 = 一段完整文本)。
67
+ * ⚠️ 面板里用 `---` 分隔多段;这里存拆好的数组。
68
+ */
69
+ bits: string[];
70
+ }
54
71
  /** F4d 建议问答页(v1.26.1)**已于 2026-10-15 整面退役**(owner 裁「砍掉外部问答」)
55
72
  * ⇒ 原 `PublicAskSettings`(key + 容器白名单)连同 `AdvancedSettings.publicAsk` 一并删除。
56
73
  * 旧配置文件残留 `publicAsk` 节 ⇒ **静默忽略**(`mergeWithDefaults` 不再读它,幂等安全)。 */
@@ -64,6 +81,8 @@ interface PersonaSettings {
64
81
  interface AdvancedSettings {
65
82
  gateway: GatewaySettings;
66
83
  persona: PersonaSettings;
84
+ /** 脱口秀片段注入(2026-11-04):纯装饰,缺省关 */
85
+ humor: HumorSettings;
67
86
  /** 主动发送入口(v1.30.9):**只绑 127.0.0.1** 的独立监听器——CCC 的 MSM 用它发消息给指定用户 */
68
87
  weixinApi: WeixinApiSettings;
69
88
  }
@@ -120,6 +139,7 @@ interface AdvancedSettingsWire {
120
139
  totpEnabled: boolean;
121
140
  };
122
141
  persona: PersonaSettings;
142
+ humor: HumorSettings;
123
143
  }
124
144
  /** 持久化 → wire(剥离 passHash/totpSecret;只留布尔) */
125
145
  export declare function toWire(settings: AdvancedSettings): AdvancedSettingsWire;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * seams/humor.ts — **脱口秀片段注入**(2026-11-04,owner 想法)
3
+ *
4
+ * ## owner 原话(本文件存在的全部理由)
5
+ *
6
+ * > 「我们 Serenity 收集一版各类脱口秀的片段内容,随机性在会话和 rebuild 的时候
7
+ * > 去进行一段注入到系统提示词(一段完整的),这个不会改变什么行为,
8
+ * > 但是会让过程变得有趣」
9
+ * > 「要做到随机,例如我们收集 30 段,每次随机注入一段;在提示词中要诚恳:
10
+ * > 先来看看这段脱口秀片段再继续阅读吧」
11
+ * > 「这个功能要做个开关」
12
+ *
13
+ * ## 🔴 三条硬约束(每条都对应一个会出问题的位置)
14
+ *
15
+ * ### ① 随机的时机 = **会话开始**,会话进行中**绝不变**
16
+ *
17
+ * owner 原话:「随机是指会话开始的时候随机,rebuild 的时候换一个;会话进行中不变动」
18
+ * (2026-11-04 二次确认:**rebuild 用同一个 session.id**,故 `sessionId` 单种子即满足
19
+ * —— rebuild 属实不换段,这正是期望行为。⛔ 不要为了"rebuild 也换"而引入代次。)
20
+ *
21
+ * ⚠️ **为什么不用 `Math.random()` 现抽**:`serenitySystemPrompt()` **每次请求都重新求值**
22
+ * ⇒ 现抽会让系统提示词每轮都变(刷新页面都可能换段),而我们**无法解释为什么变了**。
23
+ * ⇒ 选哪段可以随机,但**选定后必须可重放**:种子 = sessionId,纯函数。
24
+ *
25
+ * ### ② 原文住**用户配置**,⛔ 不进仓
26
+ *
27
+ * 本仓是 **GitHub 公开仓**。脱口秀段子是有版权的创作文本,
28
+ * ⇒ 机制在 ACC(怎么选、怎么注入),**措辞在用户配置**(`~/.dsh/serenity-hooks.json`
29
+ * 的 `humor.bits`,仓外)—— 与 D23「ACC 管机制、CCC 管措辞」同款分工。
30
+ * ⛔ 不要往本文件里贴任何段子原文。
31
+ *
32
+ * ### ③ 关闭时必须与现状**逐字节相同**
33
+ *
34
+ * 它是纯装饰,进的是每次请求的系统提示词。
35
+ * ⇒ `enabled=false`(或池为空)时 `humorBlock()` 返回 `''`,装配层不 push。
36
+ * 判据由测试钉住。
37
+ */
38
+ /**
39
+ * 按种子稳定地选一段(**纯函数**:同种子必得同一段)。
40
+ *
41
+ * @param seed 会话 id
42
+ * @param bits 片段池(来自用户配置)
43
+ * @returns 选中的文本;池空 ⇒ `null`
44
+ */
45
+ export declare function pickHumor(seed: string, bits: readonly string[]): string | null;
46
+ /**
47
+ * 装配进系统提示词的块(owner 指定的诚恳开场:**先来看看这段脱口秀片段再继续阅读吧**)。
48
+ *
49
+ * 🔴 **分段边界必须说清**:本块自带 `=== Serenity Humor ===` 标记头,
50
+ * 与 persona/EAP 等块同构,便于从装配结果里一眼确认它在不在。
51
+ * 结尾补一句「不影响任何判断」—— 它是装饰,**不能被读成行为约束**。
52
+ *
53
+ * @param seed 会话稳定种子(sessionId)
54
+ * @param bits 片段池
55
+ * @param enabled 总开关;`false` ⇒ 返回 `''`(逐字节等于没有本功能)
56
+ */
57
+ export declare function humorBlock(seed: string, bits: readonly string[], enabled: boolean): string;
@@ -111,7 +111,16 @@ export declare function sessionBlock(root: string, scope?: string): string;
111
111
  */
112
112
  export declare function serenitySystemPrompt(root: string, scope?: string,
113
113
  /** 活跃轨迹目录名(给了才有第 ⑧ 段;未绑定轨迹 ⇒ undefined,不注入) */
114
- dirName?: string): string;
114
+ dirName?: string,
115
+ /**
116
+ * 会话 id —— **脱口秀块(D287)的随机种子**。
117
+ *
118
+ * 🔴 为什么必须是会话 id 而不是每次现抽:本函数**每次请求都重新求值**,
119
+ * 现抽会让系统提示词每轮都变(刷新页面都可能换段),且**无法解释为什么变了**。
120
+ * ⇒ 同一条会话永远是同一段(owner 要的"会话进行中不变动"),换会话才换。
121
+ * 未传(如某些冷路径)⇒ 不注入该块(`''`),行为等于该功能没开。
122
+ */
123
+ sessionId?: string): string;
115
124
  /**
116
125
  * Code Mode 适配行:当前 scope 以 Code Mode 呈现工具时(run_code 可见),
117
126
  * ACC 块按 native 语义指引"直接调用工具"会与"只有 run_code 可直接调用"的执行
@@ -1121,6 +1121,10 @@ function defaultAdvancedSettings() {
1121
1121
  mode: "",
1122
1122
  overrideText: ""
1123
1123
  },
1124
+ humor: {
1125
+ enabled: false,
1126
+ bits: []
1127
+ },
1124
1128
  weixinApi: {
1125
1129
  enabled: true,
1126
1130
  port: WEIXIN_SEND_PORT
@@ -1173,6 +1177,7 @@ function mergeWithDefaults(raw) {
1173
1177
  const o = raw;
1174
1178
  const gateway = o.gateway ?? {};
1175
1179
  const persona = o.persona ?? {};
1180
+ const humor = o.humor ?? {};
1176
1181
  const weixinApi = o.weixinApi ?? {};
1177
1182
  return {
1178
1183
  gateway: {
@@ -1189,6 +1194,10 @@ function mergeWithDefaults(raw) {
1189
1194
  mode: typeof persona.mode === "string" ? persona.mode : def.persona.mode,
1190
1195
  overrideText: typeof persona.overrideText === "string" ? persona.overrideText : def.persona.overrideText
1191
1196
  },
1197
+ humor: {
1198
+ enabled: typeof humor.enabled === "boolean" ? humor.enabled : def.humor.enabled,
1199
+ bits: Array.isArray(humor.bits) ? humor.bits.filter((b) => typeof b === "string" && b.trim() !== "") : def.humor.bits
1200
+ },
1192
1201
  weixinApi: {
1193
1202
  enabled: typeof weixinApi.enabled === "boolean" ? weixinApi.enabled : def.weixinApi.enabled,
1194
1203
  port: typeof weixinApi.port === "number" && Number.isInteger(weixinApi.port) && weixinApi.port >= 0 ? weixinApi.port : def.weixinApi.port
@@ -1226,6 +1235,10 @@ function updateAdvancedSettings(patch) {
1226
1235
  mode: typeof ps.mode === "string" ? ps.mode : current.persona.mode,
1227
1236
  overrideText: typeof ps.overrideText === "string" ? ps.overrideText : current.persona.overrideText
1228
1237
  } : current.persona,
1238
+ humor: patch.humor !== void 0 ? {
1239
+ enabled: typeof patch.humor.enabled === "boolean" ? patch.humor.enabled : current.humor.enabled,
1240
+ bits: Array.isArray(patch.humor.bits) ? patch.humor.bits.filter((b) => typeof b === "string" && b.trim() !== "") : current.humor.bits
1241
+ } : current.humor,
1229
1242
  weixinApi: patch.weixinApi !== void 0 ? {
1230
1243
  enabled: typeof patch.weixinApi.enabled === "boolean" ? patch.weixinApi.enabled : current.weixinApi.enabled,
1231
1244
  port: typeof patch.weixinApi.port === "number" && Number.isInteger(patch.weixinApi.port) && patch.weixinApi.port >= 0 ? patch.weixinApi.port : current.weixinApi.port
@@ -1267,7 +1280,8 @@ function toWire(settings) {
1267
1280
  allowWorkspaceCreate: settings.gateway.allowWorkspaceCreate,
1268
1281
  totpEnabled: settings.gateway.totpEnabled
1269
1282
  },
1270
- persona: settings.persona
1283
+ persona: settings.persona,
1284
+ humor: settings.humor
1271
1285
  };
1272
1286
  }
1273
1287
  /**
@@ -1336,9 +1350,100 @@ function applyWirePatch(wire) {
1336
1350
  if (typeof wire.persona.overrideText === "string") psPatch.overrideText = wire.persona.overrideText;
1337
1351
  patch.persona = psPatch;
1338
1352
  }
1353
+ if (wire.humor !== void 0) {
1354
+ const hPatch = { ...current.humor };
1355
+ if (typeof wire.humor.enabled === "boolean") hPatch.enabled = wire.humor.enabled;
1356
+ if (Array.isArray(wire.humor.bits)) hPatch.bits = wire.humor.bits.filter((b) => typeof b === "string" && b.trim() !== "");
1357
+ patch.humor = hPatch;
1358
+ }
1339
1359
  return updateAdvancedSettings(patch);
1340
1360
  }
1341
1361
  //#endregion
1362
+ //#region src/seams/humor.ts
1363
+ /**
1364
+ * seams/humor.ts — **脱口秀片段注入**(2026-11-04,owner 想法)
1365
+ *
1366
+ * ## owner 原话(本文件存在的全部理由)
1367
+ *
1368
+ * > 「我们 Serenity 收集一版各类脱口秀的片段内容,随机性在会话和 rebuild 的时候
1369
+ * > 去进行一段注入到系统提示词(一段完整的),这个不会改变什么行为,
1370
+ * > 但是会让过程变得有趣」
1371
+ * > 「要做到随机,例如我们收集 30 段,每次随机注入一段;在提示词中要诚恳:
1372
+ * > 先来看看这段脱口秀片段再继续阅读吧」
1373
+ * > 「这个功能要做个开关」
1374
+ *
1375
+ * ## 🔴 三条硬约束(每条都对应一个会出问题的位置)
1376
+ *
1377
+ * ### ① 随机的时机 = **会话开始**,会话进行中**绝不变**
1378
+ *
1379
+ * owner 原话:「随机是指会话开始的时候随机,rebuild 的时候换一个;会话进行中不变动」
1380
+ * (2026-11-04 二次确认:**rebuild 用同一个 session.id**,故 `sessionId` 单种子即满足
1381
+ * —— rebuild 属实不换段,这正是期望行为。⛔ 不要为了"rebuild 也换"而引入代次。)
1382
+ *
1383
+ * ⚠️ **为什么不用 `Math.random()` 现抽**:`serenitySystemPrompt()` **每次请求都重新求值**
1384
+ * ⇒ 现抽会让系统提示词每轮都变(刷新页面都可能换段),而我们**无法解释为什么变了**。
1385
+ * ⇒ 选哪段可以随机,但**选定后必须可重放**:种子 = sessionId,纯函数。
1386
+ *
1387
+ * ### ② 原文住**用户配置**,⛔ 不进仓
1388
+ *
1389
+ * 本仓是 **GitHub 公开仓**。脱口秀段子是有版权的创作文本,
1390
+ * ⇒ 机制在 ACC(怎么选、怎么注入),**措辞在用户配置**(`~/.dsh/serenity-hooks.json`
1391
+ * 的 `humor.bits`,仓外)—— 与 D23「ACC 管机制、CCC 管措辞」同款分工。
1392
+ * ⛔ 不要往本文件里贴任何段子原文。
1393
+ *
1394
+ * ### ③ 关闭时必须与现状**逐字节相同**
1395
+ *
1396
+ * 它是纯装饰,进的是每次请求的系统提示词。
1397
+ * ⇒ `enabled=false`(或池为空)时 `humorBlock()` 返回 `''`,装配层不 push。
1398
+ * 判据由测试钉住。
1399
+ */
1400
+ /** 会话(或任意字符串)→ 稳定索引。FNV-1a 32 位:无依赖、纯函数、够均匀。 */
1401
+ function stableIndex(seed, mod) {
1402
+ let h = 2166136261;
1403
+ for (let i = 0; i < seed.length; i++) {
1404
+ h ^= seed.charCodeAt(i);
1405
+ h = Math.imul(h, 16777619) >>> 0;
1406
+ }
1407
+ return h % mod;
1408
+ }
1409
+ /**
1410
+ * 按种子稳定地选一段(**纯函数**:同种子必得同一段)。
1411
+ *
1412
+ * @param seed 会话 id
1413
+ * @param bits 片段池(来自用户配置)
1414
+ * @returns 选中的文本;池空 ⇒ `null`
1415
+ */
1416
+ function pickHumor(seed, bits) {
1417
+ if (bits.length === 0) return null;
1418
+ return bits[stableIndex(seed, bits.length)] ?? null;
1419
+ }
1420
+ /**
1421
+ * 装配进系统提示词的块(owner 指定的诚恳开场:**先来看看这段脱口秀片段再继续阅读吧**)。
1422
+ *
1423
+ * 🔴 **分段边界必须说清**:本块自带 `=== Serenity Humor ===` 标记头,
1424
+ * 与 persona/EAP 等块同构,便于从装配结果里一眼确认它在不在。
1425
+ * 结尾补一句「不影响任何判断」—— 它是装饰,**不能被读成行为约束**。
1426
+ *
1427
+ * @param seed 会话稳定种子(sessionId)
1428
+ * @param bits 片段池
1429
+ * @param enabled 总开关;`false` ⇒ 返回 `''`(逐字节等于没有本功能)
1430
+ */
1431
+ function humorBlock(seed, bits, enabled) {
1432
+ if (!enabled) return "";
1433
+ const bit = pickHumor(seed, bits);
1434
+ if (bit === null) return "";
1435
+ return [
1436
+ "",
1437
+ "=== Serenity Humor ===",
1438
+ "先来看看这段脱口秀片段再继续阅读吧:",
1439
+ "",
1440
+ bit.trimEnd(),
1441
+ "",
1442
+ "(读完就继续正事。它只是路过,不影响任何判断。)",
1443
+ ""
1444
+ ].join("\n");
1445
+ }
1446
+ //#endregion
1342
1447
  //#region src/trajectory/prompt-injection.ts
1343
1448
  /**
1344
1449
  * trajectory/prompt-injection.ts — **轨迹提示词的注入模式**(owner 2026-10-20 令)
@@ -1459,6 +1564,21 @@ function readPersonaSettings() {
1459
1564
  };
1460
1565
  }
1461
1566
  }
1567
+ /** 读取脱口秀片段配置(D287;读取失败 ⇒ 视为关闭,不阻断装配) */
1568
+ function readHumorSettings() {
1569
+ try {
1570
+ const s = readAdvancedSettings();
1571
+ return {
1572
+ enabled: s.humor.enabled === true,
1573
+ bits: s.humor.bits ?? []
1574
+ };
1575
+ } catch {
1576
+ return {
1577
+ enabled: false,
1578
+ bits: []
1579
+ };
1580
+ }
1581
+ }
1462
1582
  /** 过滤掉对 agent 隐藏的内容(safe-mode 是用户能力,不对 agent 提及)。无 g flag:`.test()` 须逐行独立无状态,避免 lastIndex 游移漏滤(问题A) */
1463
1583
  const HIDDEN_LINES = /安全模式|safe-mode|\.serenity-safe-on/;
1464
1584
  function sanitizeSkillContent(content) {
@@ -1865,7 +1985,7 @@ function sessionBlock(root, scope = DEFAULT_SESSION_SCOPE) {
1865
1985
  * Principles 剥离 MSM 原则段(指令遵循约束)——用户文本承接两处风格;本体论/关系段/
1866
1986
  * 操作边界(安全硬约束)永远保留。未配置 → 与 v1.23.0 逐字节一致(零影响)。
1867
1987
  */
1868
- function serenitySystemPrompt(root, scope = DEFAULT_SESSION_SCOPE, dirName) {
1988
+ function serenitySystemPrompt(root, scope = DEFAULT_SESSION_SCOPE, dirName, sessionId) {
1869
1989
  const persona = readPersonaSettings();
1870
1990
  const personaOn = persona.mode !== "" && persona.overrideText.trim() !== "";
1871
1991
  const trajReader = dirName === void 0 ? null : createTrajectoryPromptReader(root, dirName);
@@ -1877,6 +1997,20 @@ function serenitySystemPrompt(root, scope = DEFAULT_SESSION_SCOPE, dirName) {
1877
1997
  if (!plan.replaces.has("principles")) parts.push(principlesBlock(root, personaOn));
1878
1998
  if (!plan.replaces.has("cce")) parts.push(cceBlock());
1879
1999
  if (!plan.replaces.has("eap")) parts.push(eapBlock());
2000
+ /**
2001
+ * 🔴 **D287 脱口秀块(2026-11-04 owner 想法)** —— 纯装饰,不进任何判据路径。
2002
+ *
2003
+ * 位置:**质量层(EAP)之后、表达层(persona)之前** —— 先立标准,再路过一段闲笔,
2004
+ * 最后才谈表达风格(persona 才是真正改风格的那一层)。
2005
+ *
2006
+ * ⚠️ **关闭 / 池空 / 无 sessionId ⇒ `humorBlock` 返回 `''`,不 push**
2007
+ * ⇒ 装配结果**逐字节等于没有本功能**。这条由测试钉住(装饰品不许偷偷改变提示词)。
2008
+ */
2009
+ if (sessionId !== void 0 && sessionId !== "") {
2010
+ const hum = readHumorSettings();
2011
+ const bit = humorBlock(sessionId, hum.bits, hum.enabled);
2012
+ if (bit !== "") parts.push(bit);
2013
+ }
1880
2014
  if (personaOn) {
1881
2015
  const expr = personaBlock(persona.mode, persona.overrideText);
1882
2016
  if (expr !== "") parts.push(expr);
@@ -1995,7 +2129,7 @@ function registerEntrySkillSectionGlobal(ctx) {
1995
2129
  if (!cwd) return "";
1996
2130
  const root = cccRootForCwd(cwd);
1997
2131
  if (!root) return "";
1998
- const base = serenitySystemPrompt(root, agentScope(context), boundDirNameFor(context.agent?.session));
2132
+ const base = serenitySystemPrompt(root, agentScope(context), boundDirNameFor(context.agent?.session), (context.agent?.session)?.id);
1999
2133
  const codeLine = codeModeAdaptationLine(ctx, context.scope);
2000
2134
  return codeLine ? `${base}\n${codeLine}` : base;
2001
2135
  }
@@ -2027,7 +2161,7 @@ function registerEntrySkillSection(agent, root) {
2027
2161
  name: "serenity-entry",
2028
2162
  order: -50,
2029
2163
  text: (context) => {
2030
- const base = serenitySystemPrompt(root, scope, boundDirNameFor(agent.session));
2164
+ const base = serenitySystemPrompt(root, scope, boundDirNameFor(agent.session), agent.session.id);
2031
2165
  const codeLine = codeModeAdaptationLine(agent.ctx, context.scope);
2032
2166
  return codeLine ? `${base}\n${codeLine}` : base;
2033
2167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgroup/dsh-serenity-hooks",
3
- "version": "1.117.0",
3
+ "version": "1.118.0",
4
4
  "description": "宁静号 ACC harness(Native Cordis 插件)——给 DeepSeek Harness 装一个「AI 工作区」:12 个工具(container_fs/cognitive_trajectory/dashboard/container_git/msm/praxis/ontology/serenity-skill-creator/localstore/container_admin;另两个 im-bridge/diagram 按配置条件出现)+ 机械约束(安全模式/工作区围墙/密钥守卫/对外输出守卫)+ 认知轨迹日志与原地重建 + 网页登录入口/IM 桥/认知轨迹唤醒注册表。轨迹声明 = 轨迹目录下的 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": {