dsh-mo-image 0.0.0-stage → 0.4.1
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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +375 -3
- package/cordis.patch.yml +3 -0
- package/lib/adapters.js +1421 -0
- package/lib/client.js +3162 -0
- package/lib/config-guard.js +38 -0
- package/lib/index.js +1393 -0
- package/lib/localized-error.js +66 -0
- package/lib/net.js +158 -0
- package/lib/png-scale.js +231 -0
- package/lib/prompt-profiles.js +310 -0
- package/lib/proxy-dispatcher.js +212 -0
- package/lib/proxy.js +232 -0
- package/lib/update-service.js +298 -0
- package/lib/update.js +250 -0
- package/locale/messages.csv +159 -0
- package/package.json +70 -4
- package/scripts/build-locales.mjs +274 -0
- package/scripts/release.mjs +532 -0
- package/skills/mo-image-editing/SKILL.md +151 -0
- package/skills/mo-image-generation/SKILL.md +237 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具守卫:把「生图配置只能由用户改」从提示词约束升级成执行层拦截。
|
|
3
|
+
*
|
|
4
|
+
* 通过 ctx.tools.guard() 注册到宿主,任何工具调用只要“目标”指向插件配置文件
|
|
5
|
+
* 或配置接口,就在调度阶段被拒(不是提示词劝告)。
|
|
6
|
+
*
|
|
7
|
+
* 只看目标字段(路径 / URL / 命令行),不在正文里误伤:例如修改插件源码时,
|
|
8
|
+
* 新代码里出现 '/api/mo-image/config' 不应该被拦。
|
|
9
|
+
*
|
|
10
|
+
* 注意:这是参数级匹配,刻意混淆的 shell 命令(base64、字符串拼接)拦不住;
|
|
11
|
+
* 真正的硬边界仍然是宿主给不给这个 Agent 开 shell。
|
|
12
|
+
*/
|
|
13
|
+
const CONFIG_TARGET = /(?:^|[^a-z0-9_-])mo-image[\\/]+config\.json(?![a-z0-9_-])|\/api\/mo-image\/config(?![a-z0-9_-])/i;
|
|
14
|
+
|
|
15
|
+
const TARGET_FIELDS = ['path', 'file_path', 'filePath', 'files', 'url', 'command', 'cmd', 'script', 'target', 'cwd'];
|
|
16
|
+
|
|
17
|
+
export const CONFIG_GUARD_REASON = '生图配置只能由用户在该插件的设置页修改(dsh-mo-image 已拦截对配置的写入)。';
|
|
18
|
+
|
|
19
|
+
function normalize(text) {
|
|
20
|
+
return String(text || '').replace(/\\\\/g, '\\').replace(/\\/g, '/');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function hits(value) {
|
|
24
|
+
if (value === null || value === undefined) return false;
|
|
25
|
+
if (typeof value === 'string') return CONFIG_TARGET.test(normalize(value));
|
|
26
|
+
if (Array.isArray(value)) return value.some((item) => hits(item));
|
|
27
|
+
if (typeof value === 'object') return Object.keys(value).some((key) => hits(value[key]));
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** @returns {string|undefined} 返回字符串即拒绝该工具调用。 */
|
|
32
|
+
export function configWriteReason(args) {
|
|
33
|
+
if (!args || typeof args !== 'object') return undefined;
|
|
34
|
+
for (const field of TARGET_FIELDS) {
|
|
35
|
+
if (Object.prototype.hasOwnProperty.call(args, field) && hits(args[field])) return CONFIG_GUARD_REASON;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|