dsh-rule-engine 0.5.3 → 0.5.4
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/lib/core/guard-core.js +12 -0
- package/lib/core/understander.js +1 -1
- package/package.json +1 -1
package/lib/core/guard-core.js
CHANGED
|
@@ -44,6 +44,7 @@ const RULE_HINTS = {
|
|
|
44
44
|
"13A": "先对目标路径执行备份(复制到 .bak/.backups/trash-)",
|
|
45
45
|
"18": "先读取 ~/.dsh/skills/dsh-usage-manual/SKILL.md",
|
|
46
46
|
"21": "按规则 21 分级确认后再落盘",
|
|
47
|
+
"22": "先回答/展示方案,待用户明确授权(非疑问句+动作词,或 ask 授权答复)后再执行",
|
|
47
48
|
"24": "确认插件 dsh.bundle 类型或改用正确挂载",
|
|
48
49
|
"27": "先运行 node scripts/audit-mount-consistency.mjs --profile web"
|
|
49
50
|
};
|
|
@@ -280,6 +281,17 @@ function matchRule(cfg, ctx) {
|
|
|
280
281
|
const { name, args, p, cmd, session, unlock, state, now } = ctx;
|
|
281
282
|
const id = String(cfg.ruleId);
|
|
282
283
|
|
|
284
|
+
// 规则 22⑦ 机器化:用户消息是疑问句 → 本回合禁止变更类工具调用
|
|
285
|
+
//("你的执行方案难道没问题吗?"虽含"执行"仍是疑问句——同形词不构成指令,不豁免)
|
|
286
|
+
if (cfg.handler === "rule22-7-direct") {
|
|
287
|
+
if (session.turn.questionOnly) {
|
|
288
|
+
if (isReadOnlyTool(name, args)) return null; // 只读 → 豁免③
|
|
289
|
+
if (SAFE_UNCOVERED_TOOLS.has(name)) return null; // 展示/授权/查询类(含 ask_user_question)→ 豁免③
|
|
290
|
+
return makeHit(cfg, `【硬拦截】用户消息是疑问句而非授权(规则 22⑦):请先回答/展示方案,待用户明确授权后再执行(放行:非疑问句+动作词,或 ask_user_question 授权答复)`);
|
|
291
|
+
}
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
|
|
283
295
|
// 规则 1:同工具同参数连续失败 ≥2 次后拦第 3 次(失败计数由 tool/result 更新)
|
|
284
296
|
if (cfg.handler === "rule1-retry") {
|
|
285
297
|
const key = `${name}:${JSON.stringify(args || {})}`;
|
package/lib/core/understander.js
CHANGED