A local-first multi-agent app development platform, built on PenguinHarness
fix(plugins): 图片插件真跑之后,中文图层名和 png 后缀都对得上了
lmlihengfb2ab5ad01c0
diff --git a/changelog/unreleased/2026-10-28-use-seedream.md b/changelog/unreleased/2026-10-28-use-seedream.mdindex 33cba367..519dab60 100644--- a/changelog/unreleased/2026-10-28-use-seedream.md+++ b/changelog/unreleased/2026-10-28-use-seedream.md@@ -28,8 +28,12 @@ layer's `z_index`, name and bounding box reported back — and transparent backg`0` saved, `2` bad command line, `3` no `ARK_API_KEY`, `4` the API refused (its own text in `upstream`,`ModelNotOpen` included), `7` an image did not download.- A multi-image answer makes `--out` a directory and names files `<NNN>-z<z_index>-<name>.<ext>` — a- running number for order, the stacking index when the service gives one, the cleaned-up name it- reported (`base` / `layer` when it reported none). Layers are always PNG.+ running number for order, the stacking index when the service gives one, and the name it reported,+ kept as it is: only what a path cannot hold is turned into a dash, so `002-z1-背景.png` keeps its+ name (`base` / `layer` stands in when the service named nothing). Layers are always PNG.+- The output format follows the name: `--format` when given, otherwise `--out`'s extension, otherwise+ PNG. A file called `cat.png` holding JPEG bytes is a broken file in half of the image viewers out+ there, so `--out cat.png` now asks the service for PNG (`--out cat.jpg` for JPEG).- `plugins/use-seedream/skills/seedream/SKILL.md` (new): when to use it, the cost warning (a group or alayer split is several billed images), the credential check, and the note that Markdown image syntaxdoes not resolve in the chat — results are handed over as workspace paths.@@ -48,5 +52,10 @@ layer's `z_index`, name and bounding box reported back — and transparent backg- Nothing existing changed shape: a new plugin, one more name in the plugin lists.- The default model is `doubao-seedream-5-0-pro-260628`; another Seedream id goes in with `--model`.-- The live API has not been called yet: the Ark account in this vault has that model **not activated**- (`ModelNotOpen`), so everything above is verified against the stub, not against the service.+- Verified against the live API on 2026-10-28 with `doubao-seedream-5-0-pro-260628`: one 1280×720+ image, and a layer split of it into a base plus `背景 / 窗户 / 木桌 / 橘猫` — every layer a+ transparent PNG with its `z_index` and `bounding_box` reported. Two defects only the real service+ exposed were fixed in the same change: layer names in Chinese were being cleaned away, and a+ `--out x.png` was getting JPEG bytes.+- Ark's image models are **not** on by default: an account that has never opened them answers+ `ModelNotOpen` until Seedream is activated in the console's 开通管理.diff --git a/changelog/unreleased/2026-10-28-use-seedream.zh.md b/changelog/unreleased/2026-10-28-use-seedream.zh.mdindex 112ea05e..b2a5298c 100644--- a/changelog/unreleased/2026-10-28-use-seedream.zh.md+++ b/changelog/unreleased/2026-10-28-use-seedream.zh.md@@ -25,7 +25,11 @@一个 400。退出码沿用视频插件:`0` 成功、`2` 命令行不对、`3` 缺 `ARK_API_KEY`、`4` 接口拒绝(服务原话在 `upstream` 里,含 `ModelNotOpen`)、`7` 图没下下来。- 多图时 `--out` 当目录,文件名是 `<NNN>-z<z_index>-<名称>.<扩展名>`:序号管顺序,有层序就带上,名称用- 服务给的那个(没有就用 `base` / `layer`)。图层恒为 PNG。+ 服务给的那个并**原样保留** —— 只把路径里放不下的字符换成 `-`,所以 `002-z1-背景.png` 还是它自己的名字+ (服务没给名字时用 `base` / `layer`)。图层恒为 PNG。+- 输出格式跟着文件名走:给了 `--format` 用它,否则看 `--out` 的扩展名,都没有就是 PNG。叫 `cat.png` 的+ 文件里装着 JPEG 字节,在一半看图工具里就是坏文件,所以现在 `--out cat.png` 会直接向服务要 PNG+ (`cat.jpg` 要 JPEG)。- `plugins/use-seedream/skills/seedream/SKILL.md`(新增):什么时候用、先说清计费(组图或图层拆分就是好几张在计费)、先确认凭据,以及一条要紧的:聊天里的 Markdown 图片语法解析不到工作区文件 —— 结果按路径交给用户,别写 `![]()`。@@ -43,5 +47,9 @@- 原有接口一个都没动:多了一个插件、插件清单里多一个名字。- 默认模型是 `doubao-seedream-5-0-pro-260628`,换别的 Seedream 用 `--model`。-- **真实接口还没跑过**:密钥库里这把方舟 key 对应账号没有开通该模型(`ModelNotOpen`),所以以上全部是- 对桩服务验的,不是对服务验的。+- 2026-10-28 对着真接口验过一遍(`doubao-seedream-5-0-pro-260628`):一张 1280×720 的图,以及把这张图+ 拆成「底图 + 背景 / 窗户 / 木桌 / 橘猫」的图层拆分 —— 每个图层都是带透明通道的 PNG,`z_index` 与+ `bounding_box` 都在。真跑时暴露、并在同一笔改动里修掉的问题有两个:中文层名被清掉、`--out x.png`+ 拿到 JPEG 字节。+- 方舟的图像模型**不是默认开通**的:没开通过程的账号会一直回 `ModelNotOpen`,要在控制台「开通管理」里+ 单独开通 Seedream。diff --git a/docs/FORK-PROGRESS.md b/docs/FORK-PROGRESS.mdindex d6ea672f..911c0bf1 100644--- a/docs/FORK-PROGRESS.md+++ b/docs/FORK-PROGRESS.md@@ -18209,7 +18209,8 @@ key)、**4.1–4.3**(明令不动)、**5.6** / **5.10**(拍板 / 新依模型);`doubao-seedream-5-0-260128`、`4-0-250828`、`3-0-t2i`、`seededit-3-0-i2i` 全是`InvalidEndpointOrModel.NotFound`。**密钥本身是好的**(鉴权通过、拿到账号 id 与 request id),缺的是在方舟控制台「开通模型」这一步。-- 所以真实接口一张图都没出过 —— 这一轮所有结论都是对本地桩服务验的,这点在 changelog 里也写明了。+- 用户随后在方舟控制台开通了模型(「Doubao-Seedream-5.0-pro」),重试即 **HTTP 200**:`1280x720` 的图+ 17–21 秒出,`usage.output_tokens` 3600。**图像模型确实不是默认开通的**,这一点也写进了插件 SKILL。### 干了什么:新增 `plugins/use-seedream`@@ -18230,15 +18231,28 @@ key)、**4.1–4.3**(明令不动)、**5.6** / **5.10**(拍板 / 新依- 顺手改掉 SKILL 里一句不实的话:原先写「聊天能显示图片」,实际 `Prose` 只覆盖 `pre` 与 `a`,Markdown图片语法在聊天里解析到的是 Web 自己的源,工作区文件打不开,改成「按路径交给用户」。+### 真跑暴露、当场修掉的两个缺陷++- **中文层名被清空**:第一版 `cleanName` 只留 `[A-Za-z0-9._-]`,真接口回来的是「橘猫 / 木桌 / 窗户 /+ 背景」,于是五个文件全叫 `00N-zM-layer.png`。改成只替换路径里放不下的字符(`/ \ : * ? " < > |`、+ 空白、控制符),中文原样保留,现在文件名是 `005-z4-橘猫.png`。+- **`--out x.png` 拿到 JPEG 字节**:服务默认 `output_format` 是 jpeg,加上 `--out` 只决定路径,于是+ 扩展名骗人。改成输出格式跟着名字走:`--format` 优先,其次 `--out` 的扩展名,都没有就默认 **png**+ (图层本来就是 png,底图跟着一致);扩展名服务写不出来(如 `.webp`)直接算命令行错,不让它伪装。+- 这两条都补了用例(桩里放中文层名、四种格式来源、`.webp` 报错),插件自检从 10 条到 12 条。+### 验证-- `node --test plugins/use-seedream/test/*.test.mjs`:**10/10 通过**(缺密钥、单图下载、组图请求体、图层- 拆分命名与 `layers[]`、本机参考图内联、`b64_json`、坏参数、被拒带原话)。+- 真接口(2026-10-28 开通后):单图 1280×720 出图并落盘为真 PNG;`--layers` 对一张本机图拆出 5 项+ (1 张底图 + 背景 / 窗户 / 木桌 / 橘猫),图层全是带 alpha 的 PNG,`bounding_box.absolute` 与+ `.normalized` 都在;底图在修复后也是 PNG。+- `node --test plugins/use-seedream/test/*.test.mjs`:**12/12 通过**(缺密钥、单图下载、组图请求体、图层+ 拆分命名与 `layers[]`、本机参考图内联、`b64_json`、坏参数、格式来源、中文名、被拒带原话)。- `packages/core` 全量:**69 文件 / 1438 通过 / 6 跳过**(`EXIT=0`),含插件名单与计数。- `packages/docs/test/skills-sync.test.ts`:3/3 通过。- 全仓 `prettier --check .` 干净、`oxlint .` 0 警告 0 错误。-- 没做的:真实接口冒烟(模型未开通,等用户点「开通」);`--count 1` 会发 `max_images: 1`,真实服务是否接受- 没验过。+- 没做的:组图(`--count`)的真实张数没验;`--count 1` 会发 `max_images: 1`,真实服务是否接受没验过;+ Windows 上的路径与 base64 参考图没验(本机是 Linux)。### 没做 / 还差什么diff --git a/plugins/use-seedream/README.md b/plugins/use-seedream/README.mdindex 52984127..88605a5f 100644--- a/plugins/use-seedream/README.md+++ b/plugins/use-seedream/README.md@@ -30,12 +30,14 @@ stderr 是给人看的进度行,**stdout 只有一行 JSON**,路径、耗时`--model`(默认 `doubao-seedream-5-0-pro-260628`)、`--image`(参考图,可重复,最多 14 张,本机文件会内联成 `data:<mime>;base64,…`)、`--size`(`1K`/`2K`/`4K` 或 `2048x2048`,总像素须在 1280×720 与 4096×4096 之间)、`--count`(一次出组图,1–15 张)、`--layers`(图层拆分)、-`--transparent`、`--format`(`png`/`jpeg`)、`--seed`、`--watermark`。**没传的参数不发给服务**,-所以模型自己的默认值说了算;未知参数直接报错,不会悄悄忽略。+`--transparent`、`--format`(`png`/`jpeg`;不传时按 `--out` 的扩展名定,两者都没有就是 `png` ——+一个叫 `cat.png` 的文件里装着 JPEG 字节,在很多看图工具里就是「坏文件」)、`--seed`、`--watermark`。+**没传的参数不发给服务**,所以模型自己的默认值说了算;未知参数直接报错,不会悄悄忽略。出多图(`--count` 或 `--layers`)时 `--out` 当目录用,文件名是三位序号加内容:-`001-base.png`、`002-z0-cat-outline.png`……序号后面带 `-z<z_index>`(有的话)和清洗过的层名-(中文层名清洗后为空,就用 `base` / `layer`)。图层一律是 PNG。+`001-base.png`、`002-z1-背景.png`……序号后面带 `-z<z_index>`(有的话)和层名 —— 层名原样保留,+只把路径里放不下的字符(`/ \ : * ? " < > |`、空白、控制字符)换成 `-`,中文不会被打掉;服务没给名字时+用 `base` / `layer`。图层一律是 PNG。退出码把结果分了类:`0` 成功;`2` 命令行不对;`3` 缺 `ARK_API_KEY`;`4` 接口拒了请求(`upstream`里是服务原话);`7` 图片没下下来(临时文件已删,最终路径上不会留半张图)。@@ -57,17 +59,24 @@ node --test "plugins/use-seedream/test/*.test.mjs" # 或在包目录里 pnpm t桩(`test/` 里那个 `http.createServer`)冒充方舟:生成接口按用例返回 URL 或 base64,图片地址由同一个桩提供,于是整条路——请求 → 下载 → 改名——都在本机跑完,并断言密钥只发往接口、-不发给图片 URL(真实的返回是签名链接)。**它验的是脚本自己的行为,不是真实响应的形状**:-真实方舟的成功响应长什么样只能靠文档,想真跑一次需要账号已开通 Seedream 并且愿意付费。+不发给图片 URL(真实的返回是签名链接)。它验的是脚本自己的行为;真实响应形状另外对着方舟真接口核过一次+(2026-10-28,`doubao-seedream-5-0-pro-260628`:出图、组图与图层拆分都跑通了)。关键接口改动时以官网为准:[图片生成](https://docs.volcengine.com/docs/ark/image-generation-api?lang=zh)、[模型列表](https://docs.volcengine.com/docs/ark/model-list?lang=zh)。+## 真接口核过什么(2026-10-28)++- 单图:`--size 1280x720` 出图,落盘 1280×720 PNG;`--out X.png` 现在会让服务直接给 PNG。+- 图层拆分:`--image` 给一张本机图,回来 5 项(1 张底图 + 4 个图层),层名是中文+ `背景 / 窗户 / 木桌 / 橘猫`,图层都是带 alpha 的 PNG,`bounding_box.absolute` / `.normalized` 都在。+- 这一轮真跑时发现并修掉两个只有真接口才暴露的问题:中文层名被清成 `layer`(现在原样保留),以及+ `--out X.png` 拿到 JPEG 字节(现在扩展名决定 `output_format`,都没说时默认 png)。+- 当时的账号还回 `ModelNotOpen`:方舟的图像模型要在控制台「开通管理」里单独开通,不是默认可用。+## 还没验的-- 真实方舟的一次完整成功(需要已开通的账号与付费额度)。-- 图层拆分的真实响应:文档说 `data` 里是 1 张底图加最多 16 个图层、每项带- `name`/`z_index`/`description`/`bounding_box`,脚本按这个形状解析,但没对着真响应跑过。+- 组图(`--count`)的真实张数与上限。- `sequential_image_generation` 与 `layer_decomposition` 在真实模型上的组合约束(脚本只按文档传参)。- Windows 上的路径与 base64 参考图(本机是 Linux,只验了 Linux)。diff --git a/plugins/use-seedream/skills/seedream/SKILL.md b/plugins/use-seedream/skills/seedream/SKILL.mdindex 4c10db09..7854c549 100644--- a/plugins/use-seedream/skills/seedream/SKILL.md+++ b/plugins/use-seedream/skills/seedream/SKILL.md@@ -59,8 +59,10 @@ rebuilding the names yourself.When the answer carries several images — `--count`, `--layers`, or simply more images than one —`--out` is a **directory**, and the files are named `<NNN>-z<z_index>-<name>.<ext>`: a running-number, the layer's stacking index when it has one, and the cleaned-up name the service gave-(non-ASCII names clean to nothing, so `base` / `layer` stands in). Layers are always PNG.+number, the layer's stacking index when it has one, and the name the service gave — kept as it is,+with only what a path cannot hold (`/ \ : * ? " < > |`, whitespace, control characters) turned into+a dash, so a Chinese layer name survives as `002-z1-背景.png`. `base` / `layer` stands in when the+service named nothing. Layers are always PNG.Options:@@ -74,7 +76,7 @@ Options:| `--count <n>` | a group of n images (1–15) in one request || `--layers` | split the result into a base image plus up to **16** transparent PNG layers || `--transparent` | transparent background instead of opaque |-| `--format <png\|jpeg>` | output file format |+| `--format <png\|jpeg>` | output file format; when it is not given, `--out`'s extension decides, and with neither the answer is PNG (a `cat.png` holding JPEG bytes reads as a broken file) || `--seed <integer>` | fix the take, for a result you can reproduce || `--watermark` | keep the service watermark (otherwise it is the service default) |@@ -94,7 +96,9 @@ node <skill dir>/kit/seedream.mjs \## Layers and groups- **Layers** (`--layers`) come back as one base image plus at most **16** layers, each with- `name`, `z_index`, `description` and a `bounding_box` (absolute and normalized). The base image+ `name`, `z_index`, `description` and a `bounding_box` (absolute and normalized). Verified against the+ live API on 2026-10-28: a prompt naming four subjects returned the base plus `背景 / 窗户 / 木桌 /+ 橘猫`, every layer a transparent PNG. The base imageis saved first, then the layers in ascending `z_index`; the JSON's `layers[]` repeats eachlayer's `path`, `z_index`, `name`, `size` and `bounding_box` so a caller can reassemble them.Layers are always **transparent PNG**, whatever `--format` says. If the service fails todiff --git a/plugins/use-seedream/skills/seedream/kit/seedream.mjs b/plugins/use-seedream/skills/seedream/kit/seedream.mjsindex dd1c7ff9..be3f4db3 100644--- a/plugins/use-seedream/skills/seedream/kit/seedream.mjs+++ b/plugins/use-seedream/skills/seedream/kit/seedream.mjs@@ -184,8 +184,32 @@ function formatArg(raw) {return value;}+/** The extensions `--out` can imply; anything else leaves the service's own default in place. */+const FORMAT_BY_EXT = { ".png": "png", ".jpg": "jpeg", ".jpeg": "jpeg" };++/**+ * The format to ask for. A file called `cat.png` that holds JPEG bytes is a trap every image viewer+ * reports as a broken file, so `--out`'s extension decides when `--format` did not; with neither the+ * answer is PNG — the layers are PNG whatever is asked, and a base image under the same name had+ * better be one too. An extension the service cannot produce is a bad command line, not a JPEG+ * wearing a `.webp` name.+ */+function formatFor(args) {+ const explicit = formatArg(args.format);+ if (explicit !== undefined) return explicit;+ if (args.out === undefined) return "png";+ const ext = path.extname(args.out).toLowerCase();+ if (ext === "") return "png";+ const mapped = FORMAT_BY_EXT[ext];+ if (mapped === undefined)+ throw new UsageError(+ `"--out" ends in "${ext}"; the service writes png or jpeg — name the file .png / .jpg / .jpeg, or say the format with "--format"`,+ );+ return mapped;+}+/** The request body: only the options actually given, so the service's own defaults stand. */-function buildBody(args, model) {+function buildBody(args, model, format) {const images = (args.image ?? []).map((spec) => imageFor(spec, "image"));if (images.length > MAX_IMAGES)throw new UsageError(@@ -209,7 +233,6 @@ function buildBody(args, model) {}if (args.layers) body.layer_decomposition = true;if (args.transparent) body.background = "transparent";- const format = formatArg(args.format);if (format !== undefined) body.output_format = format;const seed = integerArg(args, "seed");if (seed !== undefined) body.seed = seed;@@ -249,13 +272,19 @@ async function apiJson(url, init, what) {}}-/** `[A-Za-z0-9._-]` survives, everything else becomes a dash; empty names fall back. */+/**+ * A service-given layer name as a file name: characters a path cannot hold (and whitespace) become+ * a dash, everything else survives — a Chinese layer name is the name the user will look for, so it+ * is not ASCII-folded away. Leading dots go too: `/`-free is not the only thing a name must be.+ */function cleanName(raw, fallback) {- const cleaned = String(raw ?? "")- .replace(/[^A-Za-z0-9._-]/g, "-")- .replace(/^-+|-+$/g, "")+ const cleaned = Array.from(String(raw ?? ""))+ .map((ch) => (/[\s\\/:*?"<>|\u0000-\u001f]/.test(ch) ? "-" : ch))+ .join("")+ .replace(/-{2,}/g, "-")+ .replace(/^[-.]+|[-.]+$/g, "").slice(0, 40)- .replace(/-+$/g, "");+ .replace(/[-.]+$/, "");return cleaned || fallback;}@@ -336,8 +365,8 @@ async function main() {// asked for: a typo should not look like a credential problem.const model = args.model ?? DEFAULT_MODEL;const count = integerArg(args, "count", { min: 1, max: MAX_COUNT });- const format = formatArg(args.format);- const body = buildBody(args, model);+ const format = formatFor(args);+ const body = buildBody(args, model, format);const baseUrl = (process.env.ARK_BASE_URL?.trim() || DEFAULT_BASE_URL).replace(/\/+$/, "");if (!/^https?:\/\//i.test(baseUrl))throw new UsageError(`ARK_BASE_URL must be an http(s) URL, got "${baseUrl}"`);diff --git a/plugins/use-seedream/test/seedream.test.mjs b/plugins/use-seedream/test/seedream.test.mjsindex 521f30a8..d69c4c36 100644--- a/plugins/use-seedream/test/seedream.test.mjs+++ b/plugins/use-seedream/test/seedream.test.mjs@@ -213,6 +213,7 @@ describe("the seedream kit", () => {model: MODEL,prompt: "一只猫晒太阳",size: "2K",+ output_format: "png",watermark: true,response_format: "url",});@@ -238,6 +239,53 @@ describe("the seedream kit", () => {assert.deepEqual(result.paths, [path.join(dir, "inline.png")]);});+ it("lets the extension of --out pick the format, and a plain --format still wins", async () => {+ const s = await stub({ answer: (_seen, root) => urlItems(root, ["fmt"]) });+ const env = { ARK_API_KEY: "stub-key", ARK_BASE_URL: s.origin };+ await run(["--prompt", "a cat", "--out", "cat.jpg"], { env });+ await run(["--prompt", "a cat", "--out", "cat.PNG"], { env });+ await run(["--prompt", "a cat", "--out", "cat.jpg", "--format", "png"], { env });+ // No extension (a directory for several images) and no `--out` at all both mean PNG.+ await run(["--prompt", "a cat", "--out", "group"], { env });+ await run(["--prompt", "a cat"], { env });+ assert.deepEqual(+ s.seen.bodies.map((body) => body.output_format),+ ["jpeg", "png", "png", "png", "png"],+ );+ // A format the service cannot write is a bad command line, not a mislabelled file.+ const webp = await run(["--prompt", "a cat", "--out", "cat.webp"], { env });+ assert.equal(webp.status, 2);+ assert.match(webp.stderr, /"--out" ends in ".webp"/);+ });++ it("keeps a name the service gave, minus what a path cannot hold", async () => {+ const s = await stub({+ answer: (_seen, root) => ({+ model: MODEL,+ data: [+ { url: `${root}/img/base.png`, output_format: "png" },+ {+ url: `${root}/img/layer.png`,+ z_index: 1,+ name: " 猫/主体: 01 ? ",+ output_format: "png",+ },+ ],+ }),+ });+ const { status, stdout, dir, stderr } = await run(+ ["--prompt", "a cat", "--layers", "--out", "layers"],+ { env: { ARK_API_KEY: "stub-key", ARK_BASE_URL: s.origin } },+ );+ assert.equal(status, 0, stderr);+ assert.deepEqual(+ jsonLines(stdout)+ .at(-1)+ .paths.map((p) => path.relative(dir, p)),+ ["layers/001-base.png", "layers/002-z1-猫-主体-01.png"],+ );+ });+it("asks for a group of three with sequential generation, and names them in a directory", async () => {const s = await stub({ answer: (_seen, root) => urlItems(root, ["g1", "g2", "g3"]) });const { status, stdout, dir } = await run(@@ -304,13 +352,13 @@ describe("the seedream kit", () => {// Base first, then z0, then z1 — the running number follows the stacking order…assert.deepEqual(result.paths.map((p) => path.relative(dir, p)),- ["layers/001-base.png", "layers/002-z0-cat-outline.png", "layers/003-z1-layer.png"],+ ["layers/001-base.png", "layers/002-z0-cat-outline.png", "layers/003-z1-背景.png"],);- // …and the Chinese layer name cleans to nothing, so the fallback stands in for it.+ // The Chinese layer name is kept as is — it is the name the user will look for.assert.deepEqual(fs.readdirSync(path.join(dir, "layers")).sort(), ["001-base.png","002-z0-cat-outline.png",- "003-z1-layer.png",+ "003-z1-背景.png",]);assert.deepEqual(fs.readFileSync(path.join(dir, "layers", "002-z0-cat-outline.png")),