dsh-mo-image 0.0.0-stage → 0.5.0
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 +31 -0
- package/LICENSE +21 -0
- package/README.md +392 -3
- package/THIRD-PARTY-NOTICES.md +32 -0
- package/cordis.patch.yml +3 -0
- package/lib/adapters.js +1824 -0
- package/lib/client.js +4693 -0
- package/lib/config-guard.js +51 -0
- package/lib/index.js +1465 -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 +311 -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 +178 -0
- package/package.json +71 -4
- package/scripts/build-locales.mjs +274 -0
- package/scripts/release.mjs +532 -0
- package/skills/mo-image-editing/SKILL.md +152 -0
- package/skills/mo-image-generation/SKILL.md +239 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具守卫:把「生图配置只能由用户改」从提示词约束升级成执行层拦截。
|
|
3
|
+
*
|
|
4
|
+
* 通过 ctx.tools.guard() 注册到宿主,任何工具调用只要“目标”指向插件配置文件
|
|
5
|
+
* 或配置接口,就在调度阶段被拒(不是提示词劝告)。
|
|
6
|
+
*
|
|
7
|
+
* 只拦写入:只读工具(read / grep / glob / read_image)可以照常读配置,
|
|
8
|
+
* 想看有哪些模型时读得到;写入和 shell 仍然被拒。shell 里区分「读」和「写」
|
|
9
|
+
* 不可靠(重定向、管道、编码都绕得过去),所以命令一律按写入处理。
|
|
10
|
+
*
|
|
11
|
+
* 只看目标字段(路径 / URL / 命令行),不在正文里误伤:例如修改插件源码时,
|
|
12
|
+
* 新代码里出现 '/api/mo-image/config' 不应该被拦。
|
|
13
|
+
*
|
|
14
|
+
* 注意:这是参数级匹配,刻意混淆的 shell 命令(base64、字符串拼接)拦不住;
|
|
15
|
+
* 真正的硬边界仍然是宿主给不给这个 Agent 开 shell。
|
|
16
|
+
*/
|
|
17
|
+
const CONFIG_TARGET = /(?:^|[^a-z0-9_-])mo-image[\\/]+config\.json(?![a-z0-9_-])|\/api\/mo-image\/config(?![a-z0-9_-])/i;
|
|
18
|
+
|
|
19
|
+
const TARGET_FIELDS = ['path', 'file_path', 'filePath', 'files', 'url', 'command', 'cmd', 'script', 'target', 'cwd'];
|
|
20
|
+
|
|
21
|
+
/** 只读工具:读配置不算修改,放行。 */
|
|
22
|
+
const READ_ONLY_TOOLS = new Set(['read', 'read_image', 'grep', 'glob']);
|
|
23
|
+
|
|
24
|
+
export const CONFIG_GUARD_REASON = '生图配置只能由用户在该插件的设置页修改(dsh-mo-image 已拦截对配置的写入)。';
|
|
25
|
+
|
|
26
|
+
function normalize(text) {
|
|
27
|
+
return String(text || '').replace(/\\\\/g, '\\').replace(/\\/g, '/');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function hits(value) {
|
|
31
|
+
if (value === null || value === undefined) return false;
|
|
32
|
+
if (typeof value === 'string') return CONFIG_TARGET.test(normalize(value));
|
|
33
|
+
if (Array.isArray(value)) return value.some((item) => hits(item));
|
|
34
|
+
if (typeof value === 'object') return Object.keys(value).some((key) => hits(value[key]));
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {unknown} args 工具参数
|
|
40
|
+
* @param {string} [toolName] 工具名;只读工具放行,缺省按写入处理
|
|
41
|
+
* @returns {string|undefined} 返回字符串即拒绝该工具调用。
|
|
42
|
+
*/
|
|
43
|
+
export function configWriteReason(args, toolName) {
|
|
44
|
+
const name = String(toolName || '').trim().toLowerCase();
|
|
45
|
+
if (name && READ_ONLY_TOOLS.has(name)) return undefined;
|
|
46
|
+
if (!args || typeof args !== 'object') return undefined;
|
|
47
|
+
for (const field of TARGET_FIELDS) {
|
|
48
|
+
if (Object.prototype.hasOwnProperty.call(args, field) && hits(args[field])) return CONFIG_GUARD_REASON;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|