@shgroup/dsh-serenity-hooks 1.16.11 → 1.16.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/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-serenity-hooks",
3
- "version": "1.16.11",
3
+ "version": "1.16.13",
4
4
  "main": "lib/index.js",
5
5
  "description": "宁静号 ACC harness(Native Cordis 插件):真实 DSH 工具 cc_fs/session/acc_msm/eap/neat/cce/loop + 拦截缝机械约束(safe-mode/路径守卫/会话落盘)。适配 DSH 公开版(0.1.0-rc,deepseek-ai/deepseek-harness)。私有(dsh-external 组织)。",
6
6
  "engines": {
package/lib/index.js CHANGED
@@ -2827,6 +2827,51 @@ function eapBlock() {
2827
2827
  ""
2828
2828
  ].join("\n");
2829
2829
  }
2830
+ /**
2831
+ * 运行时状态块 1) safe-mode(S134 v1.16.12):ON 时告知 agent(行为约束;机制仍由 guards 强制)。
2832
+ * 文案与实现逐项对应(guards.ts):bash 禁用(restrict deny + decideGuard)、
2833
+ * 黑名单路径拦截、CCC 治理文件保护;write/edit 等其余工具保留(受路径逃逸/黑名单约束)。
2834
+ */
2835
+ function safeModeBlock(root) {
2836
+ if (!isSafeModeOn(root)) return "";
2837
+ const blacklist = readBlacklist(root);
2838
+ return [
2839
+ "",
2840
+ "=== Serenity Safe Mode ===",
2841
+ "Safe mode is ON (enabled by the user): bash is disabled (hidden and blocked);",
2842
+ "blacklist rules apply to file paths; CCC governance files (.serenity,",
2843
+ ".serenity-safe-on) are protected from agent writes. Other read/write tools",
2844
+ "remain available, subject to path-escape and blacklist guards.",
2845
+ "Behavior constraints: do not attempt to bypass restrictions; do not write to",
2846
+ "blacklisted paths or governance files.",
2847
+ blacklist.length > 0 ? `\nActive blacklist rules: ${blacklist.join(", ")}` : "",
2848
+ ""
2849
+ ].join("\n");
2850
+ }
2851
+ /**
2852
+ * 运行时状态块 2) localstore git 策略(S134 v1.16.12):localstore.json 存在时按 gitTrack
2853
+ * 提示敏感行为约束。deny(缺省)= 本地私有不提交;allow = 进 git(个人私有仓)但敏感数据
2854
+ * 只限于该文件内(不外泄到其他文件/对话/日志)。
2855
+ */
2856
+ function localstoreBlock(root) {
2857
+ if (!existsSync(localstorePath(root))) return "";
2858
+ return (readGitTrack(root) === "allow" ? [
2859
+ "",
2860
+ "=== Serenity Localstore ===",
2861
+ "localstore.json is committed to git (gitTrack=allow — personal private repository).",
2862
+ "Sensitive data may live in this file, but ONLY in this file: keep credentials and",
2863
+ "secret values confined to localstore.json — never leak them into other files,",
2864
+ "conversation, or logs.",
2865
+ ""
2866
+ ] : [
2867
+ "",
2868
+ "=== Serenity Localstore ===",
2869
+ "localstore.json is a local private file (gitTrack=deny — not committed to git,",
2870
+ ".gitignore enforced). Credentials/config live only on this machine: do not write",
2871
+ "them into conversation or logs; do not attempt to commit this file (cc_git will refuse).",
2872
+ ""
2873
+ ]).join("\n");
2874
+ }
2830
2875
  /** 4) SKILL.md 全文:该 CCC 顶层入口 skill 原文(对齐 osp:原文直推,无包裹头;仅过滤治理内容) */
2831
2876
  function entrySkillSectionText(root) {
2832
2877
  const skills = findEntrySkills(root);
@@ -2882,9 +2927,11 @@ function serenitySystemPrompt(root, scope = DEFAULT_SESSION_SCOPE) {
2882
2927
  const parts = [
2883
2928
  accBlock(root),
2884
2929
  cceBlock(),
2885
- constraintsBlock(root),
2886
- eapBlock()
2930
+ constraintsBlock(root)
2887
2931
  ];
2932
+ const state = [safeModeBlock(root), localstoreBlock(root)].filter((b) => b !== "").join("\n");
2933
+ if (state) parts.push(state);
2934
+ parts.push(eapBlock());
2888
2935
  const skill = entrySkillSectionText(root);
2889
2936
  if (skill) parts.push(skill);
2890
2937
  const session = sessionBlock(root, scope);
@@ -3048,6 +3095,16 @@ function shouldAutoRestore(agent) {
3048
3095
  if (session.id?.startsWith("loop-")) return false;
3049
3096
  return true;
3050
3097
  }
3098
+ /**
3099
+ * 恢复触发判定(S134 泄漏修复 v1.16.13):根会话 **且已有对话历史**(续跑/恢复的会话)
3100
+ * 才自动恢复上次激活的宁静号会话——全新会话(新任务,如 apaas-26116)无历史 → 不恢复,
3101
+ * 避免把过去的 SESSION 上下文注入新任务(跨任务污染)。
3102
+ */
3103
+ function shouldRestoreActive(agent) {
3104
+ if (!shouldAutoRestore(agent)) return false;
3105
+ const events = agent.session?.events;
3106
+ return Array.isArray(events) && events.length > 0;
3107
+ }
3051
3108
  function registerContext(ctx, opts = {}) {
3052
3109
  const configPaths = opts.configPaths ?? DEFAULT_SERENITY_CONFIG_PATHS;
3053
3110
  const entrySkillMaxChars = opts.entrySkillMaxChars ?? 3e4;
@@ -3056,7 +3113,7 @@ function registerContext(ctx, opts = {}) {
3056
3113
  if (!root) return;
3057
3114
  const key = agentKey(agent);
3058
3115
  registerEntrySkillSection(agent, root);
3059
- if (shouldAutoRestore(agent)) try {
3116
+ if (shouldRestoreActive(agent)) try {
3060
3117
  if (loadSerenityConfig(root, configPaths).hooks?.autoRestoreSession ?? true) {
3061
3118
  const restored = restoreActiveSession(root, agentScope(agent));
3062
3119
  if (restored) console.log(`[serenity-hooks] ↻ 自动恢复激活会话: ${restored.dir}(from scope ${restored.from})`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgroup/dsh-serenity-hooks",
3
- "version": "1.16.11",
3
+ "version": "1.16.13",
4
4
  "description": "宁静号 ACC harness — Native Cordis 插件(DeepSeek Harness 运行时)。真实 DSH 工具注册(cc_fs/session/acc_msm 等 9 工具)+ 拦截缝机械约束(safe-mode/路径守卫/会话落盘)+ 系统提示词注入(ACC/CCE/Constraints/SKILL/Session 五块)。适配 DSH 公开版(deepseek-ai/deepseek-harness 0.1.0-rc)。",
5
5
  "license": "MIT",
6
6
  "repository": {