Skip to content

Update the WeChat article studio: build the publish arguments from the detected interface - #171

Merged
MyPrototypeWhat merged 3 commits into
MiniMax-AI:mainfrom
xiaobinger:fix/wechat-mp-publish-arguments
Nov 27, 2026
Merged

MyPrototypeWhat merged 3 commits into
MiniMax-AI:mainfrom
xiaobinger:fix/wechat-mp-publish-arguments

Conversation

@xiaobinger

@xiaobinger xiaobinger commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Updates the WeChat Official Account article studio that was merged in #168 — same plugin ID, version 1.0.0 → 1.1.0 — because the publish call filled three arguments and left the rest of the detected interface's schema alone.

What was wrong

buildPublishArguments picked the first name it knew for each part of the article and sent that. For an interface that publishes a 公众号 article from a title, a cover file and a body, the app sent the styled export as the body — 2,317,213 characters of inline-styled HTML with every image embedded as a base64 data URI, against a field that declares maxLength: 20000. The call was rejected as invalid parameters before it left the app. The same interface also needed a kind, a cover, an action and a confirm; none of them were sent, and the images were never named.

How the arguments are built now

Each part of the article has a role — title, digest, body, cover, images, kind of message, what to do with it, the confirmation flag, the wait — and each role is known by a list of names. The first name the detected interface itself declares is the one that gets filled, so this is not written against one interface: an interface that calls its cover cover_image is served exactly like one that calls it thumb_media_id, one that calls its body article_content like one that calls it content, one that calls its kind message_type like one that calls it kind.

The value follows the schema too. The kind is the enum value that means an article, the action is the enum value that means publish, the confirmation flag is set only when the interface declares one, and the body is the styled HTML — unless the interface takes the images separately, or the HTML does not fit the limit the interface declares, in which case it is the plain body with every image named inside it on a line of its own (![](C:\...\assets\<id>.jpg)), the form an interface that uploads images expects. Nothing outside the plugin's own dataDir is ever named.

An interface that asks for something this draft cannot provide — a draft id that only the console knows, for instance — is not called at all, and the page says which argument was missing. An interface with no field for the body is still refused, and still never swapped for another one.

Two smaller changes

「复制正文」 now copies the plain body instead of the styled HTML, so what lands in the clipboard is the text with the images named by their local paths; 「预览」 and 「下载 HTML」 keep the styled export, so nothing is lost for a paste into the console. And the cover and every illustration can now be re-rendered on their own, with the requirements that are current for that version — the prompt of each slot is shown in its card.

Review follow-up (91012ec)

1. An asset path cannot leave assets/. collectAssetPaths used to build join(assetsDir, assetId + ext) from whatever the record said. It now goes through assetFilePath() in miniapp/node/paths.mjs: the id must be a plain name the renderer writes (randomUUID(), no separator), the extension must be .jpg, .jpeg, .png or .webp, and the resolved file must lie inside assetsDir. ../secret, ../../outside, ..\..\outside, /etc/passwd and C:\Windows\win all yield no path; a sibling directory whose name merely starts with assets does not count as inside either. A record that fails is reported rather than dropped silently, and the publish route refuses with 409 asset_path_outside_assets naming the slot instead of sending the call.

2. A body that already carries a path cannot add one. toPlainBody now takes the assets directory as its root and keeps an image reference found in the body — markdown ![](...), [[img:...]] or <img src=...> — only when it resolves inside that root. file:///C:/Windows/win.ini, https://…, data:… and relative references are removed with the line that held them; the illustrations the app names itself are checked against the same root. So "no file outside the plugin's own directory is ever named" now holds for a hand-edited state file and for a pasted line, not only for the happy path.

3. A list item gets the same body rule. article_list / articles is built item by item from the item's own schema (title, article_content, thumb_media_id …), and its body goes through the same chooseBody() as a top-level body: the item's own maxLength, and plain text when the interface takes the images separately. An interface that declares both content and articles gets the same chosen body in both. A list whose items name no body field is left unsent rather than filled with a guessed name, and an item that must carry a field this draft cannot name stops the publish — missingRequiredArguments now checks item-level required too.

On the two behaviours that were flagged as possibly intentional: a declared confirm is set to true and an action enum holding both publish and draft is filled as publish, because this call happens only after the page's confirmation dialog named the interface. An interface whose enum has no publish gets its own draft word, and a flag the interface does not declare is never sent; a test pins both.

Tested environment

  • MiniMax Code 3.1.19 on Windows 11 (x64).
  • Minimum client version: MiniMax Code 3.1.6 — unchanged; the manifest declares toolAccess, which older clients reject. agentAccess, agentConcurrency and surface.window need 3.1.2.
  • The publish gate was re-run against the live inventory of this machine twice: with no 公众号 interface connected (203 tools) all three checks report 「未接入」 and both publish buttons stay disabled, with no console error; with a 公众号 interface connected, all three are confirmed by detection, the page lists the two publish interfaces it found and lets you pick one, and the publish button stays disabled until you do.
  • The publish arguments were built against the live schema of a connected 公众号 interface that publishes an article from a title, a cover file and a body: the payload carries the title, the digest, the cover as a local path, the plain body (1,137 characters, inside the 20,000 the interface declares), the kind, the action and the confirmation — no required argument missing, nothing over a declared limit. The interface that can only publish an existing draft id is refused instead of called.
  • The interface picker, the disabled publish button until an interface is picked, the confirmation that names the picked interface, the plain body in the clipboard and the per-slot re-render button were exercised in the app's own Browser tab. The console showed no errors.
  • The package's own regression tests: node --test "tests/**/*.test.mjs" — 93 checks, up from 76, covering the publish gate's matching, the interface answer, the durable state, the questionnaire flow, the download allowlist, the plain body, the asset-path containment, the list arguments and the page.
  • The containment was also probed outside the tests, on a throwaway data directory in the app's own runtime shape: a draft whose cover record reads ../../outside and whose illustration reads ../secret reports both as rejected, the plain body keeps no win.ini line, and no cover path is sent. On the real data directory the same route reports no rejected records, the plain body is 1,137 characters, and all four ![](...) lines point inside dataDir\assets.
  • The running app was re-published and its /api/export read from the Browser tab for both drafts in the data directory: 200, and every image marker in the plain body lies inside dataDir\assets.
  • npm run check reports plugins/xiaobinger/wechat-mp-article-studio: OK — no errors and no warnings for this package — and repository: OK.

Not verified

  • The interface publish path was exercised up to the call: the arguments were built against the live schema of a connected interface and checked there, but the call itself was not made, so no 公众号 publish was performed and no result code was read back from a real publish.
  • The Agent polish turn was triggered once in the app's own Browser tab: the turn ran and the result was saved as a new version. The branch of that path where the Agent asks a question was not exercised, because the turn did not ask one.
  • The duplication check is a deterministic text-overlap heuristic, not a semantic comparison. It was checked against hand-made near-duplicates and unrelated articles, not against a large corpus.

Remaining npm run check findings

npm run check runs 92 repository tests; 90 pass. The two failures are the repository's own symlink tests (test/files.test.mjs): creating a symlink on this Windows machine needs Developer Mode or an elevated shell, and the test aborts with EPERM before it reaches any assertion. Both tests build their own fixture under a temporary directory and never touch this package — they fail identically on a clean checkout of main.

Access and data

Unchanged from the merged version: toolAccess: ["call"], agentAccess: ["session.run"], agentConcurrency: 2, no deviceAccess, no hostAccess, no session.read. No process is spawned and no shell is used. State is written only inside context.dataDir; the publish call names the rendered cover and illustrations as file paths inside that same directory and the body as text — now enforced rather than assumed, by assetFilePath() for the records and by toPlainBody's root for references already in the body. The plugin ID, the access declarations and the root README entries stay as they are.

Written by MiniMax M3.1 Flash

Notes for the reviewer

  • This updates the package merged in Add WeChat Official Account Article Studio Mini App #168 in place, under the same plugins/xiaobinger/wechat-mp-article-studio/ directory and the same plugin ID, with the version bumped to 1.1.0. The root README entries do not change, because the app it lists is the same app.
  • The package is self-contained and depends on no other directory in this repository.

熊兵 added 2 commits November 27, 2026 14:13
The publish call filled three arguments and left the rest of the interface's
schema alone, so an interface that publishes a article from a title, a cover
file and a body was handed the styled export: 2.3 million characters of
inline-styled HTML with every image embedded as a base64 data URI, against a
field that declares 20,000. The call was rejected as invalid before it left
the app.

Each part of the article now has a role, and every role is known by a list of
names; the first name the detected interface itself declares is the one that
is filled. The value follows the schema too: the kind is the enum value that
means an article, the action the one that means publish, and the body is the
styled HTML unless the interface takes the images separately or the HTML does
not fit its declared limit — then it is the plain body with every image named
inside it. An interface that asks for something this draft cannot provide is
not called, and the page says which argument was missing.

「复制正文」 copies that plain body, so the clipboard holds the text with the
images named by their local paths; the preview and the HTML download keep the
styled export. The cover and every illustration can now be re-rendered on
their own, with the requirements that are current for this version.

Tests: node --test "tests/**/*.test.mjs" (76 checks, up from 62).
The publish arguments now follow the interface that was detected, 「复制正文」
copies the plain body, and every image can be re-rendered on its own.
@xiaobinger

Copy link
Copy Markdown
Contributor Author

This is the follow-up to #168, which was merged — the same package, same plugin ID, version 1.1.0.

The publish call filled three arguments and left the rest of the detected interface's schema alone, so an interface that publishes a 公众号 article from a title, a cover file and a body was handed the styled export: 2,317,213 characters of inline-styled HTML with every image embedded as a base64 data URI, against a field that declares maxLength: 20000. The call was rejected as invalid parameters before it left the app. The same interface also needed a kind, a cover, an action and a confirm; none of them were sent, and the images were never named.

How the arguments are built now. Each part of the article has a role — title, digest, body, cover, images, kind of message, what to do with it, the confirmation flag, the wait — and each role is known by a list of names. The first name the detected interface itself declares is the one that gets filled, so this is not written against one interface: an interface that calls its cover cover_image is served exactly like one that calls it thumb_media_id, one that calls its body article_content like one that calls it content, one that calls its kind message_type like one that calls it kind.

The value follows the schema too. The kind is the enum value that means an article; the action is the enum value that means publish; the confirmation flag is set only when the interface declares one. The body is the styled HTML — unless the interface takes the images separately, or the HTML does not fit the limit the interface declares, in which case it is the plain body with every image named inside it on a line of its own (![](C:\...\assets\<id>.jpg)), which is the form an interface that uploads images expects. Nothing outside the plugin's own dataDir is ever named.

A missing argument stops the publish. An interface that asks for something this draft cannot provide — a draft id that only the console knows, for instance — is not called at all, and the page says which argument was missing. An interface with no field for the body is still refused, and still never swapped for another one.

Two smaller changes. 「复制正文」 now copies the plain body instead of the styled HTML, so what lands in the clipboard is the text with the images named by their local paths; 「预览」 and 「下载 HTML」 keep the styled export, so nothing is lost for a paste into the console. And the cover and every illustration can now be re-rendered on their own, with the requirements that are current for that version.

What is unchanged. Everything the last round asked for still holds: the result code decides over the status string next to it, submit is not a publish role, several matching interfaces are never resolved silently, the confirmation names the interface, the download allowlist is pinned to the bucket and a redirect may not leave the host, a damaged state file is never overwritten, and the arguments are still built only from the target tool's own inputSchema — never from its description.

Tests. node --test "tests/**/*.test.mjs" — 76/76, up from 62. New: the plain body keeps the section order, names every illustration by its local path and carries no markdown emphasis; an interface that builds the article itself gets the plain body, the cover path, the kind, the action and the confirmation; the body never exceeds the limit the interface declares; a second vocabulary (art_title, article_content, cover_image, image_list, message_type, mode, confirmed, wait_seconds) is filled with its own names; an interface that only takes a body still gets the styled HTML; and an interface that requires an argument this draft cannot provide is not called.

Verified against a live interface, not only in mocks. A 公众号 interface was connected to this machine and the app detected it. The publish arguments were built against its live schema: the title, the digest, the cover as a local path, the plain body of 1,137 characters, the kind, the action and the confirmation — no required argument missing, nothing over a declared limit. The interface that can only publish an existing draft id is refused instead of called. The picker, the disabled publish button until an interface is picked, the confirmation that names the picked interface, the plain body in the clipboard and the per-slot re-render button were all exercised in the app's own Browser tab.

What is still not verified: the publish call itself was never made, so no article was published from this app and no result code was read back from a real publish. The Agent polish turn was triggered once in the app's own Browser tab and its result was saved as a new version; the branch where the Agent asks a question was not exercised, because that turn did not ask one.

@MyPrototypeWhat MyPrototypeWhat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the 1.1.0 follow-up. We re-checked on 28c9c107. This isn't ready to merge yet.

collectAssetPaths builds paths with join(assetsDir, assetId + ext) and does not check that the result stays inside dataDir. In our probes, an assetId of ../secret landed inside dataDir but outside assets, and ../../outside landed outside dataDir. Existing file:/// paths in the draft body are also copied as-is into the plain-text ![](...) lines. The Chinese README says 「永远不会提到插件自己目录以外的任何文件」; that isn't true for modified state or for addresses already in the body. Normal rendering writes assets with randomUUID() under dataDir/assets/, so the happy path is fine — the missing check still matters.

Separately, when the interface only has article_list, or has both content and articles, each list item's content still gets the full styled HTML and does not go through chooseBody. The tests don't cover that shape, so the old over-long HTML problem could still show up there.

「复制正文」 does go through /api/export as plain text from toPlainBody, and a single-image re-render only runs when the slot matches. A declared confirm field is always set to true, and an action enum with both publish and draft is filled as publish; the page already has a confirmation dialog, so that may be intentional.

Package tests were 76/76 on this head. We have not run this on Host or Electron, and we have not made a real publish call.

The review on 28c9c10 found two holes and one untested shape.

Asset paths were built as join(assetsDir, assetId + ext) without asking
whether the result stays inside assets. A record of ../secret in a
hand-edited state file landed inside dataDir but outside assets, and
../../outside landed outside dataDir. An image reference already present
in the draft body was also copied into the plain body as it was, so the
README's "no file outside the plugin's own directory is ever named" was
not true for a modified state or a pasted file:/// line.

- paths.mjs: assetFilePath() accepts only an id the renderer writes (a
  plain name, no separator) and an extension among .jpg/.jpeg/.png/.webp,
  then checks the resolved file is inside assetsDir. collectAssetPaths()
  reports every record it had to leave out instead of dropping it
  silently.
- server.mjs: a publish with such a record is refused with 409
  asset_path_outside_assets rather than sent, and both the publish and
  the export hand toPlainBody the assets directory as its root.
- content.mjs: toPlainBody() keeps a markdown, [[img:...]] or <img src>
  reference from the body only when it resolves inside that root; https,
  data and relative references never become a path. The illustrations it
  is given are checked against the same root.
- publishing.mjs: a list item is built from its own item schema, and its
  body goes through the same chooseBody() as a top-level one — its own
  maxLength, and plain text when the interface takes the images
  separately. A list whose items name no body field is left unsent
  instead of guessed at, and an item that must carry a field this draft
  cannot name stops the publish. missingRequiredArguments() checks item
  required fields too.
- tests: 93, up from 76. New paths.test.mjs probes ../secret,
  ../../outside, a sibling prefix and a file:/// reference; content tests
  cover a body that carries outside references; publishing tests cover a
  list-only interface, both content and article_list, a renamed item
  vocabulary, an item schema with no body field, and a required item
  field.
- README (en + zh): the containment rule, the list-item rule, the test
  count, and a Not-verified line that no longer contradicts the rest of
  the section.
@xiaobinger

Copy link
Copy Markdown
Contributor Author

All three points are fixed in 91012ec, pushed to the same branch; CI is green on that head. Version stays 1.1.0 — this is the same unreleased version, not a second bump.

collectAssetPaths no longer trusts a record. Path building moved to miniapp/node/paths.mjs / assetFilePath(), which accepts only an id the renderer itself writes (a plain name — randomUUID() — with no separator), only the extensions the renderer writes (.jpg, .jpeg, .png, .webp), and only a result that resolves inside assetsDir. A sibling whose name merely starts with assets is not "inside" either: containment is checked on path segments, after . and .. are collapsed, not on a string prefix. Your two probes now yield nothing — ../secret and ../../outside both fail, as do ..\..\outside, /etc/passwd and C:\Windows\win. collectAssetPaths reports what it dropped in a rejected list instead of dropping it silently, and the publish route refuses with 409 asset_path_outside_assets, naming the slot, before any call is made.

A body that already carries a path cannot contribute one. toPlainBody now takes the assets directory as its root and keeps an image reference found in the draft body only when it resolves inside it. All three forms are covered — markdown ![](...), [[img:...]], <img src=...> — and https:, data:, file://host/… and relative references never become a path at all. The illustrations the app names itself are checked against the same root, so the root is the only way a path reaches the payload. The Chinese README's sentence is now true for a modified state file and for a body that already contains a file:/// line, not only for the normal rendering path; both READMEs say how, and the English one gained a Asset paths are contained paragraph.

A list item is treated like a top-level body. article_list / articles is built item by item from the item's own schema — title, article_content, desc, thumb_media_id … — and its body goes through the same chooseBody() as content: the item's own maxLength, and plain text when the interface takes the images separately (top-level or inside the item). Both of your shapes are tested: a list-only interface, and an interface declaring both content and articles (both receive the same chosen body). Two more behaviours while I was there: a list whose items name no body field is left unsent rather than filled with a name the tool never declared, and missingRequiredArguments now checks item-level required too, so an item that must carry something this draft cannot name stops the publish and the page names it (article_list[].thumb_media_id).

On confirm and action. Both are intentional, and now pinned by a test. The call only happens after the page's confirmation dialog has named the interface, so the user asked for a publish, not for another draft; an enum with no publish gets its own draft word instead, and a flag the interface does not declare is never sent.

Tests and probes. 93 checks, up from 76: tests/paths.test.mjs probes ../secret, ../../outside, the sibling prefix and file:///C:/Windows/win.ini; the content tests feed a body that carries outside references; the publishing tests cover the list shapes above. Outside the tests I ran the same route on a throwaway data directory in the app's own state shape, with a cover record of ../../outside and an illustration of ../secret: both are reported rejected, the plain body keeps no win.ini line, no cover path is sent. On the real data directory nothing is rejected, the plain body is 1,137 characters, all four markers point inside dataDir\assets, and /api/export read from the running app answers 200 for both drafts with zero markers outside.

Still not verified, as before: the publish call itself was never made, so no article was published from this app and no result code was read back from a real publish. Also unchanged: no Host or Electron run, and the two test/files.test.mjs symlink tests still fail on this machine for want of Developer Mode.

@MyPrototypeWhat MyPrototypeWhat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up on 91012ec7. We re-checked the two points from the earlier review.

collectAssetPaths now goes through assetFilePath(), which only accepts a plain filename and an extension, and checks that the resolved file stays inside assetsDir. Our probes of ../secret and ../../outside no longer produce a path. A publish with those records is refused with 409 asset_path_outside_assets before any tool is called. toPlainBody also keeps an existing image reference only when it resolves inside that root, so a file:/// line in the draft body is no longer copied into the plain-text ![](...) lines. List items now go through the same chooseBody() rule as a top-level body, using each item's own schema.

The confirm / action behavior is unchanged and is pinned by tests; that still looks intentional, given the page's confirmation dialog.

Package tests were 93/93 on this head, and repo CI is green. We have not run this on Host or Electron, and we have not made a real publish call. One leftover that is not a merge blocker: ordinary sentence text can still mention a path, even though image references are filtered. The check also does not follow symlinks.

This is ready to merge from our side.

@MyPrototypeWhat
MyPrototypeWhat merged commit b4fbdfd into MiniMax-AI:main Nov 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants