@shgroup/dsh-serenity-hooks 1.18.0 → 1.18.2

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.18.0",
3
+ "version": "1.18.2",
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
@@ -3621,10 +3621,11 @@ function resolveBootstrapSettings(opts) {
3621
3621
  if (promoteOn !== "either" && promoteOn !== "tool-call" && promoteOn !== "assistant-message") throw new TypeError(`bootstrap: promoteOn must be one of "tool-call", "assistant-message", "either"; got ${JSON.stringify(promoteOn)}`);
3622
3622
  return {
3623
3623
  bootstrapTools: stringList(opts.bootstrapTools, "bootstrapTools", DEFAULT_BOOTSTRAP_TOOLS),
3624
- promoteEvents: PROMOTE_EVENTS[promoteOn],
3624
+ promoteEvents: opts.zeroTools ? PROMOTE_EVENTS["assistant-message"] : PROMOTE_EVENTS[promoteOn],
3625
3625
  suppressedSources: sourceList(opts.suppressedContextSources, "suppressedContextSources", DEFAULT_SUPPRESSED_SOURCES),
3626
3626
  compactionTools: stringList(opts.compactionTools, "compactionTools", DEFAULT_COMPACTION_TOOLS),
3627
- anchorMessage: typeof opts.anchorMessage === "string" && opts.anchorMessage.length > 0 ? opts.anchorMessage : DEFAULT_ANCHOR_MESSAGE
3627
+ anchorMessage: typeof opts.anchorMessage === "string" && opts.anchorMessage.length > 0 ? opts.anchorMessage : DEFAULT_ANCHOR_MESSAGE,
3628
+ zeroTools: opts.zeroTools === true
3628
3629
  };
3629
3630
  }
3630
3631
  /**
@@ -3642,26 +3643,41 @@ function agentRoot(agent) {
3642
3643
  if (typeof cwd !== "string") return null;
3643
3644
  return findSerenityRoot(cwd);
3644
3645
  }
3645
- /** 按 agent cwd 解析 bootstrap 配置;未开启返回 null */
3646
+ /** 按 agent cwd 解析 bootstrap 配置(总是生效——无 enabled 开关,用户明确"直接开启不能关";
3647
+ * CCC 的 serenity.json bootstrap 段仅用于调参数,缺省用默认设置) */
3646
3648
  function readBootstrapConfig(agent) {
3647
3649
  const root = agentRoot(agent);
3648
- if (!root) return null;
3650
+ if (!root) return resolveBootstrapSettings({});
3649
3651
  const b = loadSerenityConfig(root).bootstrap;
3650
- if (!b?.enabled) return null;
3651
3652
  return resolveBootstrapSettings({
3652
- bootstrapTools: b.bootstrapTools,
3653
- promoteOn: b.promoteOn,
3654
- suppressedContextSources: b.suppressedContextSources,
3655
- compactionTools: b.compactionTools,
3656
- anchorMessage: b.anchorMessage
3653
+ bootstrapTools: b?.bootstrapTools,
3654
+ promoteOn: b?.promoteOn,
3655
+ suppressedContextSources: b?.suppressedContextSources,
3656
+ compactionTools: b?.compactionTools,
3657
+ anchorMessage: b?.anchorMessage,
3658
+ zeroTools: b?.zeroTools
3657
3659
  });
3658
3660
  }
3659
3661
  function registerBootstrap(ctx) {
3660
3662
  const settingsByRoot = /* @__PURE__ */ new Map();
3661
- const tracker = createEpochPromotion(/* @__PURE__ */ new Set(["tool/call", "assistant/message"]));
3663
+ const trackers = /* @__PURE__ */ new Map();
3664
+ const trackerFor = (root, settings) => {
3665
+ let t = trackers.get(root);
3666
+ if (!t) {
3667
+ t = createEpochPromotion(settings.promoteEvents);
3668
+ trackers.set(root, t);
3669
+ }
3670
+ return t;
3671
+ };
3662
3672
  ctx.on("session/event", (session, event) => {
3663
3673
  try {
3664
- tracker.observe(session, event);
3674
+ const cwd = session?.header?.cwd;
3675
+ if (typeof cwd !== "string") return;
3676
+ const root = findSerenityRoot(cwd);
3677
+ if (!root) return;
3678
+ const settings = settingsByRoot.get(root) ?? readBootstrapConfig({ session });
3679
+ settingsByRoot.set(root, settings);
3680
+ trackerFor(root, settings).observe(session, event);
3665
3681
  } catch {}
3666
3682
  });
3667
3683
  ctx.on("agent/inbox/inserted", ({ agent, message }) => {
@@ -3669,7 +3685,6 @@ function registerBootstrap(ctx) {
3669
3685
  const root = agentRoot(agent);
3670
3686
  if (!root) return;
3671
3687
  const settings = settingsByRoot.get(root) ?? readBootstrapConfig(agent);
3672
- if (!settings) return;
3673
3688
  const session = agent.session;
3674
3689
  if ((session?.header?.delegationDepth ?? 0) > 0) return;
3675
3690
  if (session?.events?.some((event) => event.type === "user/message")) return;
@@ -3708,15 +3723,30 @@ function registerBootstrap(ctx) {
3708
3723
  const root = agentRoot(agent);
3709
3724
  if (!root) return assembled;
3710
3725
  const settings = settingsByRoot.get(root) ?? readBootstrapConfig(agent);
3711
- if (!settings) return assembled;
3712
3726
  settingsByRoot.set(root, settings);
3713
- const status = tracker.status(agent);
3727
+ const status = trackerFor(root, settings).status(agent);
3714
3728
  if (status.promoted) return assembled;
3715
- const keep = new Set(settings.bootstrapTools);
3716
- if (status.boundary >= 0) for (const toolName of settings.compactionTools) keep.add(toolName);
3717
3729
  const tools = assembled.tools;
3718
3730
  if (!Array.isArray(tools)) return assembled;
3719
3731
  const available = new Set(tools.map((tool) => tool.name).filter((n) => typeof n === "string"));
3732
+ if (settings.zeroTools) {
3733
+ if (status.boundary < 0) return {
3734
+ ...assembled,
3735
+ tools: []
3736
+ };
3737
+ const keep = new Set(settings.compactionTools);
3738
+ const missing = [...keep].filter((name) => !available.has(name));
3739
+ if (missing.length > 0) {
3740
+ warnOnce(`expected compaction tools missing=${JSON.stringify(missing)} — bootstrap disabled, full catalog exposed`);
3741
+ return assembled;
3742
+ }
3743
+ return {
3744
+ ...assembled,
3745
+ tools: tools.filter((tool) => typeof tool.name === "string" && keep.has(tool.name))
3746
+ };
3747
+ }
3748
+ const keep = new Set(settings.bootstrapTools);
3749
+ if (status.boundary >= 0) for (const toolName of settings.compactionTools) keep.add(toolName);
3720
3750
  const missing = [...keep].filter((name) => !available.has(name));
3721
3751
  if (missing.length > 0) {
3722
3752
  warnOnce(`expected bootstrap tools missing=${JSON.stringify(missing)} — bootstrap disabled, full catalog exposed`);
@@ -3735,9 +3765,11 @@ function registerBootstrap(ctx) {
3735
3765
  const decision = await next();
3736
3766
  if (decision.kind === "reject") return decision;
3737
3767
  try {
3738
- const settings = readBootstrapConfig(agent);
3739
- if (!settings) return decision;
3740
- if (tracker.status(agent).promoted || settings.suppressedSources.size === 0) return decision;
3768
+ const root = agentRoot(agent);
3769
+ if (!root) return decision;
3770
+ const settings = settingsByRoot.get(root) ?? readBootstrapConfig(agent);
3771
+ settingsByRoot.set(root, settings);
3772
+ if (trackerFor(root, settings).status(agent).promoted || settings.suppressedSources.size === 0) return decision;
3741
3773
  const messages = decision.messages;
3742
3774
  if (!Array.isArray(messages)) return decision;
3743
3775
  const kept = messages.filter((message) => {
@@ -4686,8 +4718,7 @@ const Config = z.object({
4686
4718
  api: z.boolean().default(true),
4687
4719
  entrySkillMaxChars: z.number().default(3e4),
4688
4720
  env: z.boolean().default(true),
4689
- opencodeSkills: z.boolean().default(true),
4690
- bootstrap: z.boolean().default(false)
4721
+ opencodeSkills: z.boolean().default(true)
4691
4722
  });
4692
4723
  function apply(ctx, config) {
4693
4724
  if (config.tools) {
@@ -4720,7 +4751,7 @@ function apply(ctx, config) {
4720
4751
  if (config.api) registerStatusApi(ctx, { configPaths: config.serenityConfigPaths });
4721
4752
  if (config.env) registerEnv(ctx);
4722
4753
  if (config.opencodeSkills) registerOpencodeSkills(ctx);
4723
- if (config.bootstrap) registerBootstrap(ctx);
4754
+ registerBootstrap(ctx);
4724
4755
  }
4725
4756
  //#endregion
4726
4757
  export { Config, apply, inject, name };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgroup/dsh-serenity-hooks",
3
- "version": "1.18.0",
3
+ "version": "1.18.2",
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": {