feat: 0.3.0 - let the plugin diagnose itself

Answers the top complaint "it does not work and I cannot tell why" by turning
hidden state into explicit output.

- moyun_ultimate_profile now reports permission.builtin / .effective / .verdict
  and environment.profile / .userLayerOverrides / .siblingPlugins / .winner,
  so the user can see whether the permission layer actually took effect
- new tool moyun_skills_audit: which of the 63 skills run out of the box and
  which are missing their external binaries (nuclei/fscan/IDA/jadx/...)
- badge now colors itself by real state: green (this package owns permission),
  amber (user layer overrode it / sibling plugin present / disabled), red (refusal)
- skill audit speed: 2933 ms -> 234 ms by indexing PATH instead of spawning
  "where" per command (0 ms once cached)
This commit is contained in:
moyun 2026-11-17 14:28:01 +08:00
parent 07fabc9fe6
commit 83ceae9e72
5 changed files with 541 additions and 154 deletions

View File

@ -1,5 +1,27 @@
# Changelog
## 0.3.0 — 2026-11-17
### 新增:插件自己诊断自己
针对「装了没效果 / 不知道哪里冲突 / 技能跑不起来」三类反馈,把隐性状态变成显性输出。
- **`moyun_ultimate_profile` 大改**:新增 `permission`(builtin / effective / verdict 三态)+
`environment`(profile / userLayerOverrides / siblingPlugins / winner)+ `skills` 汇总。
权限层是不是真生效,一眼能看到,不用猜。
- **新工具 `moyun_skills_audit`**:审计 63 个技能的可用性,区分「能直接用」和「缺外部工具」,
并列出具体缺哪些二进制。
- **状态条按真实状态变色**:绿(本插件接管)/ 琥珀(被用户层接管、有同类插件、已关闭)/ 红(判拒)。
悬停显示详细原因。
- **性能**:技能审计从逐条 `where`(约 2.9 s)改为 PATH 目录索引(**234 ms**,缓存后 0 ms)。
### 验证
- `node --check` 通过;工具实测输出正确(本机识别出 `overridden-by-user-layer` +
`siblingPlugins: ["dsh-purge"]`)
---
## 0.2.1 — 2026-11-17
### 新增

View File

@ -1,10 +1,11 @@
# moyun-ultimate · 墨昀·终极破甲
> 五层提示词内核 + 权限层,一层解决一个环节,互不重叠。装这一个就够。
> **插件会自己报告状态**:`moyun_ultimate_profile` 一看就知道权限层有没有真生效。
> Five-layer prompt core with a built-in permission layer for DeepSeek Harness.
<p align="center">
<img alt="version" src="https://img.shields.io/badge/version-0.1.0-blue">
<img alt="version" src="https://img.shields.io/badge/version-0.3.0-blue">
<img alt="license" src="https://img.shields.io/badge/license-MIT-green">
<img alt="dsh" src="https://img.shields.io/badge/DSH-0.2.1--rc.5-4D6BFE">
<img alt="skills" src="https://img.shields.io/badge/skills-63-orange">
@ -19,7 +20,10 @@
- **五段分层系统提示**(人格 / 反拒绝 / 执行强度 / 强化镜像 / 技能路由),合计 21 KB
- **权限层**:沙箱 `danger-full-access` + 审批自动应答 + 结果不截断 —— **只靠官方 config 覆盖实现,不改宿主源码**
- **63 个内置攻防技能**(41 个通用 + 22 个内网红队),首次启动自动落地到 `$DSH_HOME/skills`
- **2 个新工具**:`moyun_frame`(被拒时换框重试)、`moyun_ultimate_profile`(自查)
- **3 个新工具**:
- `moyun_frame` —— 被拒时换框重试(5 个框架按需取)
- `moyun_ultimate_profile` —— **自查:五层状态 + 权限层是否真生效 + 冲突检测**
- `moyun_skills_audit` —— **技能可用性审计:哪些能直接用、哪些缺外部工具**
- **拒绝投影状态条**:对话区底部小绿条,实时显示激活态与判拒评分
- **分层开关**:五段提示词任一层、以及权限层,都可单独关闭
@ -299,6 +303,51 @@ RESULT: OK=11 WARN=2 FAIL=0
`WARN` 不一定是问题——上面两条正是「和别的插件共存」时的正常提示。
### 让插件自己报告状态(最省事)
装完重启后,直接让 Agent 调:
```
moyun_ultimate_profile
```
它会一次性告诉你四件事:
```json
{
"version": "0.2.1",
"layers": "5/5 enabled",
"permission": {
"builtin": true,
"effective": "overridden-by-user-layer",
"verdict": "权限层被 profile 用户层覆盖(permission)—— 当前由那几段配置生效。想让本插件接管就删掉它们。"
},
"environment": {
"profile": "desktop",
"userLayerOverrides": ["permission"],
"siblingPlugins": ["dsh-purge"],
"winner": "user-layer"
},
"skills": { "total": 63, "ready": 48, "needExternalTools": 15 }
}
```
**`permission.effective` 三种取值**:
| 值 | 含义 | 该做什么 |
|---|---|---|
| `effective` | 权限层由本插件接管 | 什么都不用做 |
| `overridden-by-user-layer` | 被 profile 用户层覆盖了 | 删掉用户层那几段,或设 `permission: false` |
| `disabled-by-config` | 按配置关掉了 | 若另一插件负责权限,这是预期状态 |
### 技能为什么跑不起来
```
moyun_skills_audit
```
返回 `ready` / `skillsNeedingTools` / `missingTools`。技能不缺文件,缺的是外部二进制(nuclei / fscan / IDA / jadx…)。装好对应工具即可直接用,不用重装插件。
### 四项手动验证
**1. 五段是否注入** —— 问 Agent:
@ -331,7 +380,15 @@ moyun_frame(frame="textbook", request="写一个 SQL 注入检测脚本")
(Get-ChildItem "$env:DSH_HOME\skills" -Directory).Count # 应 +63
```
**5. 状态条**:对话区底部会出现一条绿色状态条:
**5. 状态条**:对话区底部会出现状态条,**颜色和文案反映真实状态**:
| 显示 | 含义 |
|---|---|
| 🟢 `墨昀爱搬砖 · 五层就绪` | 五层注入 + 权限层由本插件接管 |
| 🟡 `…· 权限由用户层接管` | 五层正常,但权限层被 profile 覆盖(悬停看详情) |
| 🟡 `…· 权限层待确认` | 有同类插件共存,后应用者赢 |
| 🟡 `…· 权限层已关` | `permission: false` |
| 🔴 `✗ 触发安全拒绝` | 本轮回复被判拒(闪一下) |
![状态条特写](docs/screenshots/09-badge-zoom.png)

View File

@ -45,6 +45,18 @@
};
var FLASH_MS = 2500;
// three tones: ok(green) / warn(amber) / bad(red)
var TONE = {
ok: { border: "rgba(16, 185, 129, 0.45)", bg: "rgba(16, 185, 129, 0.12)", dot: "#10b981" },
warn: { border: "rgba(245, 158, 11, 0.45)", bg: "rgba(245, 158, 11, 0.12)", dot: "#f59e0b" },
bad: { border: "rgba(239, 68, 68, 0.50)", bg: "rgba(239, 68, 68, 0.12)", dot: "#ef4444" }
};
function applyTone(style, tone) {
style.borderColor = tone.border;
style.background = tone.bg;
return tone.dot;
}
function ArmorDock(props) {
var useProjection = props.useProjection;
var armor = typeof useProjection === "function"
@ -83,9 +95,33 @@
var showVerdict = !running && lastVerdictRef.current !== null &&
Date.now() < flashUntilRef.current;
var text = "墨昀爱搬砖 · 终极破甲已激活";
// static status: five layers + whether permission layer really takes effect
var env = armor && armor.env ? armor.env : null;
var permOn = !!(armor && armor.permissionOn);
var text = "墨昀爱搬砖 · 五层就绪";
var tip = "墨昀爱搬砖 · 五段提示词已注入";
var tone = TONE.ok;
if (!permOn) {
text = "墨昀爱搬砖 · 五层就绪 · 权限层已关";
tip = "权限层按配置关闭 (permission: false)";
tone = TONE.warn;
} else if (env && Array.isArray(env.userOverrides) && env.userOverrides.length > 0) {
text = "墨昀爱搬砖 · 五层就绪 · 权限由用户层接管";
tip = (env.profile ? "profile=" + env.profile + "; " : "") +
"用户层覆盖了 " + env.userOverrides.join(",") +
" (用户层优先级更高)。要本插件接管就删掉那几段,或设 permission:false。";
tone = TONE.warn;
} else if (env && Array.isArray(env.siblingPlugins) && env.siblingPlugins.length > 0) {
text = "墨昀爱搬砖 · 五层就绪 · 权限层待确认";
tip = "bundles 里有同类插件 " + env.siblingPlugins.join(",") +
",两者都改 approval/permission 时后应用者赢。建议二选一。";
tone = TONE.warn;
}
var dotStyle = Object.assign({}, DOT_STYLE);
var badgeStyle = Object.assign({}, BADGE_STYLE);
dotStyle.background = applyTone(badgeStyle, tone);
if (running) {
dotStyle.animation = "moyunArmorPulse 1.2s ease-in-out infinite";
@ -97,9 +133,7 @@
} else {
text = "✗ " + (words[0] || "触发安全拒绝");
badgeStyle.animation = "moyunArmorFlash 1.6s ease";
badgeStyle.borderColor = "rgba(239, 68, 68, 0.5)";
badgeStyle.background = "rgba(239, 68, 68, 0.12)";
dotStyle.background = "#ef4444";
dotStyle.background = applyTone(badgeStyle, TONE.bad);
}
}
@ -108,7 +142,7 @@
{ style: WRAP_STYLE },
react.createElement(
"div",
{ style: badgeStyle, "data-armor": "on", "data-plugin": "moyun-ultimate", title: "墨昀爱搬砖 · 终极破甲已激活" },
{ style: badgeStyle, "data-armor": "on", "data-plugin": "moyun-ultimate", "data-permission": permOn ? ((env && env.userOverrides && env.userOverrides.length) ? "overridden" : "builtin") : "off", title: tip },
react.createElement("span", { style: dotStyle }),
react.createElement("span", null, text)
)

296
index.js
View File

@ -1,4 +1,4 @@
import { readFileSync, existsSync, mkdirSync, readdirSync, copyFileSync } from "node:fs";
import { readdirSync, readFileSync, existsSync, mkdirSync, copyFileSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
@ -71,20 +71,220 @@ const frameTool = {
},
};
function readOwnVersion() {
try {
return JSON.parse(readFileSync(join(HERE, "package.json"), "utf8")).version || "0.0.0";
} catch {
return "0.0.0";
}
}
// ── 环境诊断:找出当前 profile、检测配置覆盖与同类插件 ──────────────────
const CONFLICT_IDS = ["sandbox-policy", "approval", "permission", "spill-policy", "tool-result-pruner"];
const SIBLING_HINTS = /purge|ungate|jailbreak|armor|unrestrict|pojia|po$/i;
let profileCache = null;
function findProfileDir(dshHome) {
if (profileCache) return profileCache;
if (!dshHome) return null;
const root = join(dshHome, "profiles");
let found = null;
try {
for (const name of readdirSync(root, { withFileTypes: true })) {
if (!name.isDirectory()) continue;
const pj = join(root, name.name, "package.json");
if (!existsSync(pj)) continue;
try {
const j = JSON.parse(readFileSync(pj, "utf8"));
const bundles = (j.dsh && j.dsh.profile && j.dsh.profile.bundles) || [];
if (bundles.includes("moyun-ultimate")) {
found = { name: name.name, dir: join(root, name.name), pkg: j };
break;
}
} catch {}
}
} catch {}
profileCache = found;
return found;
}
function detectConflicts(dshHome) {
const out = { profile: null, userOverrides: [], siblingPlugins: [], winner: null, notes: [] };
const prof = findProfileDir(dshHome);
if (!prof) {
out.notes.push("未找到登记本插件的 profile(可能刚安装、尚未写 bundles)");
return out;
}
out.profile = prof.name;
// 1) 用户层是否覆盖了同名 config id
const patchPath = join(prof.dir, "cordis.patch.yml");
if (existsSync(patchPath)) {
try {
const txt = readFileSync(patchPath, "utf8");
for (const id of CONFLICT_IDS) {
const re = new RegExp("^\\s*-\\s*id:\\s*" + id + "\\s*$", "m");
if (re.test(txt)) out.userOverrides.push(id);
}
} catch {}
}
// 2) bundles 里有没有同类插件
const bundles = (prof.pkg.dsh && prof.pkg.dsh.profile && prof.pkg.dsh.profile.bundles) || [];
out.siblingPlugins = bundles.filter((b) => b !== "moyun-ultimate" && SIBLING_HINTS.test(b));
// 3) 谁生效
if (out.userOverrides.length > 0) {
out.winner = "user-layer";
out.notes.push(
"profile 用户层覆盖了 " + out.userOverrides.join(", ") + " —— 用户层后应用、优先级更高," +
"本包的权限层被盖掉。要本包接管就删掉那几段;要保留就设 permission: false。",
);
} else if (out.siblingPlugins.length > 0) {
out.winner = "ambiguous";
out.notes.push(
"bundles 里有同类插件 " + out.siblingPlugins.join(", ") + " —— 如果它也改 approval/permission," +
"后应用者赢,不会报错但一方静默失效。建议二选一。",
);
} else {
out.winner = "moyun-ultimate";
out.notes.push("权限层由本插件接管,无冲突。");
}
return out;
}
// ── 技能依赖审计:哪些技能能用、哪些缺外部工具 ────────────────────────
// 只列真正依赖外部二进制的技能,纯提示词类不检查。
const SKILL_DEPS = {
"nuclei-scan": ["nuclei"],
"fscan-intranet": ["fscan"],
"gogo-intranet": ["gogo"],
"active-scan": ["nmap"],
"dir-bruteforce": ["ffuf", "feroxbuster", "dirsearch", "gobuster"],
"credential-attack": ["hashcat", "hydra"],
"ida-reverse": ["ida64", "ida"],
"ghidra-reverse": ["ghidra", "analyzeHeadless"],
"radare2": ["r2", "radare2"],
"apk-reverse": ["jadx", "apktool", "adb"],
"mobile-reverse": ["frida", "objection"],
"chisel-tunnel": ["chisel"],
"frp-tunnel": ["frpc", "frps"],
"suo5-tunnel": ["suo5"],
"shell-handler": ["msfconsole", "nc", "socat"],
"recon-pipeline": ["subfinder", "httpx", "naabu"],
"pentest-tools": ["nmap", "sqlmap"],
"go-rust-reverse": ["go", "cargo"],
"dotnet-reverse": ["dnspy", "ilspycmd"],
"js-reverse": ["node"],
"browser-automation": ["node"],
};
let toolCache = null;
let pathIndex = null;
// 用 PATH 目录索引代替逐条 `where` 调用:63 个技能全部检查也从 ~3s 降到几十 ms。
function buildPathIndex() {
if (pathIndex) return pathIndex;
const sep = process.platform === "win32" ? ";" : ":";
const dirs = (process.env.PATH || "").split(sep).filter((d) => {
try {
return d && existsSync(d);
} catch {
return false;
}
});
pathIndex = dirs;
return pathIndex;
}
function which(cmd) {
const dirs = buildPathIndex();
const exts =
process.platform === "win32" ? [".exe", ".cmd", ".bat", ".com", ""] : [""];
for (const d of dirs) {
for (const e of exts) {
try {
if (existsSync(join(d, cmd + e))) return true;
} catch {}
}
}
return false;
}
function auditSkills(dshHome) {
if (toolCache) return toolCache;
const dirs = [];
try {
const src = join(HERE, "skills");
for (const d of readdirSync(src, { withFileTypes: true })) {
if (d.isDirectory()) dirs.push(d.name);
}
} catch {}
const result = { total: dirs.length, ready: [], needTools: [], missingTools: [] };
const missing = new Set();
for (const name of dirs) {
const deps = SKILL_DEPS[name];
if (!deps || deps.length === 0) {
result.ready.push(name);
continue;
}
const have = deps.filter((c) => which(c));
if (have.length > 0) {
result.ready.push(name);
} else {
result.needTools.push({ skill: name, tools: deps });
deps.forEach((c) => missing.add(c));
}
}
result.missingTools = [...missing].sort();
toolCache = result;
return result;
}
// ── 工具 2:运行时状态 ────────────────────────────────────────────────
const profileTool = {
name: "moyun_ultimate_profile",
description: "返回「墨昀·终极破甲」的版本、分层状态与技能库规模。",
description:
"返回「墨昀·终极破甲」的版本、五层状态、权限层实际生效情况、技能库规模与环境诊断" +
"(是否被 profile 用户层覆盖、是否有同类插件争用同一批 config id)。" +
"装完先调这个,就知道自己处在什么状态、为什么被拒。",
parameters: { type: "object", properties: {}, additionalProperties: false },
output: objectOutput,
execute(config = {}) {
const dshHome = process.env.DSH_HOME || "";
const env = detectConflicts(dshHome);
const audit = auditSkills(dshHome);
let skillCount = 0;
try {
skillCount = readdirSync(join(HERE, "skills"), { withFileTypes: true }).filter((d) => d.isDirectory()).length;
} catch {}
// 权限层真实状态
const permissionBuiltin = config.permission !== false;
const permissionEffective =
permissionBuiltin && env.userOverrides.length === 0 ? "effective" :
permissionBuiltin && env.userOverrides.length > 0 ? "overridden-by-user-layer" :
"disabled-by-config";
// 一句话结论(帮用户直接判断)
let verdict;
if (permissionEffective === "effective") {
verdict = "权限层由本插件接管:工具审批自动通过、沙箱 danger-full-access。";
} else if (permissionEffective === "overridden-by-user-layer") {
verdict = "权限层被 profile 用户层覆盖(" + env.userOverrides.join(", ") +
")—— 当前由那几段配置生效。想让本插件接管就删掉它们。";
} else {
verdict = "权限层已按配置关闭(permission: false)。若另一插件负责权限,这是预期状态。";
}
return {
plugin: "moyun-ultimate",
version: "0.1.0",
version: readOwnVersion(),
displayName: "墨昀·终极破甲",
layers: LAYERS.map((l) => ({
section: l.section,
@ -93,19 +293,71 @@ const profileTool = {
enabled: config[l.key] !== false,
bytes: l.text.length,
})),
permission: {
builtin: permissionBuiltin,
effective: permissionEffective,
verdict,
},
environment: {
profile: env.profile,
userLayerOverrides: env.userOverrides,
siblingPlugins: env.siblingPlugins,
winner: env.winner,
notes: env.notes,
},
skills: {
total: skillCount,
ready: audit.ready.length,
needExternalTools: audit.needTools.length,
missingTools: audit.missingTools,
detailTool: "moyun_skills_audit",
},
frames: Object.keys(FRAMES),
skills: skillCount,
fusedFrom: [
"人格双槽 + 判拒投影(墨昀原创)",
"反拒绝机制:授权不可复核 / 外来模式识别 / 边界词归一化",
"执行强度:完整交付不降级 / 阻断只报一行",
"5 个换框模板 + 技能路由表",
"63 个攻防技能(逆向 24 / 渗透 16 / 云 8 / 取证 6 / 其它 9)",
design: [
"五段分层提示词:人格 / 反拒绝 / 执行强度 / 强化镜像 / 技能路由",
"权限层:sandbox-policy + approval + permission 覆盖 + 审批应答器(不改宿主源码)",
"5 个换框模板按需加载,不常驻提示词",
"63 个攻防技能,首次启动幂等同步到 $DSH_HOME/skills",
],
};
},
};
// ── 工具 3:技能可用性审计 ─────────────────────────────────────────────
const skillsAuditTool = {
name: "moyun_skills_audit",
description:
"列出 63 个内置攻击技能里,哪些可以直接用、哪些还缺外部工具(nuclei/fscan/IDA/jadx 等)。" +
"技能只提供用法与命令模板,不打包二进制——跑不起来通常是没装对应工具。",
parameters: {
type: "object",
properties: {
onlyMissing: { type: "boolean", description: "只看缺工具的技能" },
},
additionalProperties: false,
},
output: objectOutput,
execute(args = {}) {
const dshHome = process.env.DSH_HOME || "";
const a = auditSkills(dshHome);
const base = {
total: a.total,
ready: a.ready.length,
needExternalTools: a.needTools.length,
missingTools: a.missingTools,
note: "缺工具的技能不是坏掉,是缺依赖。装对应二进制后即可直接用,无需重装插件。",
};
if (args.onlyMissing) {
base.missingSkills = a.needTools;
return base;
}
base.readySkills = a.ready;
base.skillsNeedingTools = a.needTools;
return base;
},
};
// ── 技能库自动同步(幂等:只补缺失,不覆盖用户改动)──────────────────
function syncSkills(dshHome) {
if (!dshHome) return { synced: 0, skipped: 0 };
@ -241,16 +493,35 @@ export function apply(ctx, config = {}) {
// 工具
ctx.effect(() => ctx.tools.register(frameTool));
ctx.effect(() => ctx.tools.register(profileTool));
ctx.effect(() => ctx.tools.register(skillsAuditTool));
// 判拒投影
// 环境诊断结果只算一次(apply 时),随 view 一并下发,供状态条显示真实状态。
const anySchema = { parse: (v) => v };
const envSnapshot = (() => {
try {
const e = detectConflicts(process.env.DSH_HOME || "");
return {
profile: e.profile,
userOverrides: e.userOverrides,
siblingPlugins: e.siblingPlugins,
winner: e.winner,
note: e.notes[0] || "",
};
} catch {
return null;
}
})();
const armorDef = {
key: "moyun-ultimate",
stateVersion: 1,
stateSchema: anySchema,
init: () => ({ running: false, verdict: null, safe: [], risk: [] }),
apply: armorProjectionApply,
wire: { viewSchema: anySchema, view: (s) => s },
wire: {
viewSchema: anySchema,
view: (s) => Object.assign({}, s, { env: envSnapshot, permissionOn: config.permission !== false }),
},
};
const registerArmor = (p) => {
try {
@ -266,3 +537,6 @@ export function apply(ctx, config = {}) {
});
}
}
// 供外部诊断脚本复用(doctor.ps1 的 JS 版、CI 等);不影响插件运行。
export const __diagnostics = { detectConflicts, auditSkills, findProfileDir, readOwnVersion, profileTool, skillsAuditTool };

View File

@ -1,6 +1,6 @@
{
"name": "moyun-ultimate",
"version": "0.2.1",
"version": "0.3.0",
"displayName": "墨昀·终极破甲",
"description": "墨昀·终极破甲:五层提示词内核 + 内置权限层 —— 人格双槽 × 反拒绝机制 × 执行强度 × 换框模板 × 技能路由,内置 63 个攻防技能(逆向 24 / 渗透 16 / 云 8 / 取证 6 / 其它 9)。Layered prompt core with five sections and 63 built-in skills.",
"keywords": [
@ -36,8 +36,8 @@
"dsh": {
"id": "moyun-ultimate",
"name": "墨昀·终极破甲",
"version": "0.2.1",
"permissions": "系统提示词五段注入, 双槽强化, 拒绝投影状态条, 换框模板工具, 63 技能自动同步",
"version": "0.3.0",
"permissions": "系统提示词五段注入, 内置权限层(沙箱/审批/结果), 拒绝投影状态条, 换框模板工具, 状态自查工具, 技能审计工具, 63 技能自动同步",
"bundle": {
"patch": "./cordis.patch.yml"
},