moyun-ultimate/client.js
moyun 83ceae9e72 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)
2026-11-17 14:28:01 +08:00

172 lines
7.0 KiB
JavaScript

(() => {
try {
/* 墨昀爱搬砖 (moyun-ultimate) client half — realtime badge.
__ModuleLoader__ 格式,与 fujiang-armor desktop 适配同构。 */
window.__ModuleLoader__.load({
id: "moyun-ultimate",
factory: (require) => {
var module = { exports: {} };
var exports = module.exports;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
var react = require("react");
var inject = ["slots"];
var ANIM_CSS = "@keyframes moyunArmorPulse{0%,100%{box-shadow:0 0 2px rgba(16,185,129,.5);opacity:1}50%{box-shadow:0 0 14px rgba(16,185,129,1);opacity:.6}}@keyframes moyunArmorFlash{0%{transform:scale(1)}30%{transform:scale(1.1)}100%{transform:scale(1)}}";
var WRAP_STYLE = {
display: "flex",
justifyContent: "center",
width: "100%"
};
var BADGE_STYLE = {
display: "inline-flex",
alignItems: "center",
gap: "6px",
width: "fit-content",
padding: "3px 10px",
borderRadius: "6px",
border: "1px solid rgba(16, 185, 129, 0.45)",
background: "rgba(16, 185, 129, 0.12)",
color: "inherit",
fontSize: "11px",
lineHeight: "16px",
fontFamily: "inherit",
userSelect: "none",
whiteSpace: "nowrap"
};
var DOT_STYLE = {
width: "6px",
height: "6px",
borderRadius: "50%",
background: "#10b981",
flex: "none"
};
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"
? useProjection("moyun-ultimate")
: undefined;
var lastVerdictRef = react.useRef(null);
var flashUntilRef = react.useRef(0);
var tickPair = react.useState(0);
var setTick = tickPair[1];
react.useEffect(function () {
var styleEl = null;
if (!document.getElementById("moyun-ultimate-css")) {
styleEl = document.createElement("style");
styleEl.id = "moyun-ultimate-css";
styleEl.textContent = ANIM_CSS;
document.head.appendChild(styleEl);
}
return function () { if (styleEl) styleEl.remove(); };
}, []);
react.useEffect(function () {
var v = armor && armor.verdict ? armor.verdict : null;
if (v !== lastVerdictRef.current) {
lastVerdictRef.current = v;
if (v) flashUntilRef.current = Date.now() + FLASH_MS;
setTick(Date.now());
}
}, [armor]);
var running = !!(armor && armor.running);
var words = armor && Array.isArray(armor.words) ? armor.words : [];
var risk = armor && Array.isArray(armor.risk) ? armor.risk : [];
var domain = armor && armor.domain ? armor.domain : null;
var showVerdict = !running && lastVerdictRef.current !== null &&
Date.now() < flashUntilRef.current;
// 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";
text = "执行中…";
} else if (showVerdict) {
if (lastVerdictRef.current === "pass") {
text = "✓ 通过" + (domain ? " · " + domain : "") + (risk.length ? " · 载荷x" + risk.length : "");
badgeStyle.animation = "moyunArmorFlash 1.2s ease";
} else {
text = "✗ " + (words[0] || "触发安全拒绝");
badgeStyle.animation = "moyunArmorFlash 1.6s ease";
dotStyle.background = applyTone(badgeStyle, TONE.bad);
}
}
return react.createElement(
"div",
{ style: WRAP_STYLE },
react.createElement(
"div",
{ 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)
)
);
}
function apply(ctx) {
ctx.slots.inject("conversation.input.dock", () =>
ctx.slots.register({
name: "conversation.input.dock",
id: "moyun-ultimate:badge",
order: 30
}, ArmorDock)
);
}
exports.name = "moyun-ultimate";
exports.inject = inject;
exports.apply = apply;
return module.exports;
}
});
} catch (err) {
console.warn('[AI Client Sandbox] moyun-ultimate runtime error:', err);
}
})();