Repository navigation
Update the WeChat article studio: build the publish arguments from the detected interface - #171
Conversation
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.
|
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 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 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 ( 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, Tests. 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
left a comment
There was a problem hiding this comment.
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.
|
All three points are fixed in
A body that already carries a path cannot contribute one. A list item is treated like a top-level body. On Tests and probes. 93 checks, up from 76: 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 |
MyPrototypeWhat
left a comment
There was a problem hiding this comment.
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.
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
buildPublishArgumentspicked 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 declaresmaxLength: 20000. The call was rejected as invalid parameters before it left the app. The same interface also needed akind, acover, anactionand aconfirm; 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_imageis served exactly like one that calls itthumb_media_id, one that calls its bodyarticle_contentlike one that calls itcontent, one that calls its kindmessage_typelike one that calls itkind.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 (
), the form an interface that uploads images expects. Nothing outside the plugin's owndataDiris 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/.collectAssetPathsused to buildjoin(assetsDir, assetId + ext)from whatever the record said. It now goes throughassetFilePath()inminiapp/node/paths.mjs: the id must be a plain name the renderer writes (randomUUID(), no separator), the extension must be.jpg,.jpeg,.pngor.webp, and the resolved file must lie insideassetsDir.../secret,../../outside,..\..\outside,/etc/passwdandC:\Windows\winall yield no path; a sibling directory whose name merely starts withassetsdoes not count as inside either. A record that fails is reported rather than dropped silently, and the publish route refuses with409 asset_path_outside_assetsnaming the slot instead of sending the call.2. A body that already carries a path cannot add one.
toPlainBodynow 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/articlesis built item by item from the item's own schema (title,article_content,thumb_media_id…), and its body goes through the samechooseBody()as a top-level body: the item's ownmaxLength, and plain text when the interface takes the images separately. An interface that declares bothcontentandarticlesgets 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 —missingRequiredArgumentsnow checks item-levelrequiredtoo.On the two behaviours that were flagged as possibly intentional: a declared
confirmis set totrueand anactionenum holding bothpublishanddraftis filled aspublish, because this call happens only after the page's confirmation dialog named the interface. An interface whose enum has nopublishgets its owndraftword, and a flag the interface does not declare is never sent; a test pins both.Tested environment
toolAccess, which older clients reject.agentAccess,agentConcurrencyandsurface.windowneed 3.1.2.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.../../outsideand whose illustration reads../secretreports both as rejected, the plain body keeps nowin.iniline, 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 fourlines point insidedataDir\assets./api/exportread from the Browser tab for both drafts in the data directory:200, and every image marker in the plain body lies insidedataDir\assets.npm run checkreportsplugins/xiaobinger/wechat-mp-article-studio: OK— no errors and no warnings for this package — andrepository: OK.Not verified
Remaining
npm run checkfindingsnpm run checkruns 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 withEPERMbefore 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 ofmain.Access and data
Unchanged from the merged version:
toolAccess: ["call"],agentAccess: ["session.run"],agentConcurrency: 2, nodeviceAccess, nohostAccess, nosession.read. No process is spawned and no shell is used. State is written only insidecontext.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, byassetFilePath()for the records and bytoPlainBody'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
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.