@playcraft/cli 0.0.39 → 0.0.41

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.
Files changed (121) hide show
  1. package/README.md +66 -3
  2. package/dist/atom-plan/validate-atom-plan.js +298 -0
  3. package/dist/cli-root-help.js +1 -1
  4. package/dist/commands/3d.js +363 -0
  5. package/dist/commands/create.js +337 -0
  6. package/dist/commands/fix-ids.js +17 -3
  7. package/dist/commands/fix-ids.test.js +264 -0
  8. package/dist/commands/image.js +1337 -43
  9. package/dist/commands/login.js +60 -2
  10. package/dist/commands/recommend.js +1 -1
  11. package/dist/commands/remix.js +213 -0
  12. package/dist/commands/skills.js +1379 -0
  13. package/dist/commands/tools-3d.js +473 -0
  14. package/dist/commands/tools-generation.js +454 -0
  15. package/dist/commands/tools-project.js +400 -0
  16. package/dist/commands/tools-research.js +37 -0
  17. package/dist/commands/tools-research.test.js +216 -0
  18. package/dist/commands/tools-utils.js +164 -0
  19. package/dist/commands/tools.js +7 -616
  20. package/dist/config.js +2 -0
  21. package/dist/index.js +20 -2
  22. package/dist/utils/agent-api-client.js +52 -16
  23. package/package.json +9 -3
  24. package/project-template/.claude/agents/designer.md +116 -0
  25. package/project-template/.claude/agents/developer.md +133 -0
  26. package/project-template/.claude/agents/pm.md +164 -0
  27. package/project-template/.claude/agents/refs/README.md +67 -0
  28. package/project-template/.claude/agents/refs/designer-art-style-catalog.md +533 -0
  29. package/project-template/.claude/agents/refs/designer-color-audio-recipes.md +153 -0
  30. package/project-template/.claude/agents/refs/designer-deliverable-spec.md +167 -0
  31. package/project-template/.claude/agents/refs/designer-dimension-axis.md +27 -0
  32. package/project-template/.claude/agents/refs/designer-handoff-v2-checklist.md +68 -0
  33. package/project-template/.claude/agents/refs/designer-master-composite-recipes.md +216 -0
  34. package/project-template/.claude/agents/refs/designer-style-exploration-flow.md +37 -0
  35. package/project-template/.claude/agents/refs/developer-dev-handoff.md +109 -0
  36. package/project-template/.claude/agents/refs/developer-impl-cookbook.md +134 -0
  37. package/project-template/.claude/agents/refs/developer-phase1-flow.md +211 -0
  38. package/project-template/.claude/agents/refs/pm-workflow-detail.md +545 -0
  39. package/project-template/.claude/agents/refs/reviewer-six-dimension-eval.md +286 -0
  40. package/project-template/.claude/agents/refs/ta-3d-flip-recipe.md +85 -0
  41. package/project-template/.claude/agents/refs/ta-atlas-deliverable-standard.md +46 -0
  42. package/project-template/.claude/agents/refs/ta-batch-pipeline-recipes.md +120 -0
  43. package/project-template/.claude/agents/refs/ta-image-generation-detail.md +356 -0
  44. package/project-template/.claude/agents/refs/ta-image-ops-reference.md +495 -0
  45. package/project-template/.claude/agents/refs/ta-pipeline-cookbook.md +699 -0
  46. package/project-template/.claude/agents/refs/ta-tools-reference.md +111 -0
  47. package/project-template/.claude/agents/refs/ta-vfx-preset-catalog.md +365 -0
  48. package/project-template/.claude/agents/reviewer.md +103 -0
  49. package/project-template/.claude/agents/technical-artist.md +111 -0
  50. package/project-template/.claude/hooks/README.md +36 -0
  51. package/project-template/.claude/hooks/validate-atom-plan.mjs +224 -0
  52. package/project-template/.claude/hooks/validate-workflow-stop.mjs +258 -0
  53. package/project-template/.claude/settings.json +32 -0
  54. package/project-template/.claude/settings.local.json +4 -0
  55. package/project-template/.claude/skills/playcraft-ad-psychology/SKILL.md +182 -0
  56. package/project-template/.claude/skills/playcraft-art-style-guide/SKILL.md +123 -0
  57. package/project-template/.claude/skills/playcraft-asset-state-sheet/SKILL.md +141 -0
  58. package/project-template/.claude/skills/playcraft-audio-generation/SKILL.md +280 -0
  59. package/project-template/.claude/skills/playcraft-batch-pipeline/SKILL.md +184 -0
  60. package/project-template/.claude/skills/playcraft-build-optimizer/SKILL.md +306 -0
  61. package/project-template/.claude/skills/playcraft-image-generation/SKILL.md +229 -0
  62. package/project-template/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +123 -0
  63. package/project-template/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +254 -0
  64. package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +235 -0
  65. package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +97 -0
  66. package/project-template/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +118 -0
  67. package/project-template/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +137 -0
  68. package/project-template/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +397 -0
  69. package/project-template/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +296 -0
  70. package/project-template/.claude/skills/playcraft-image-ops/SKILL.md +122 -0
  71. package/project-template/.claude/skills/playcraft-masking/SKILL.md +373 -0
  72. package/project-template/.claude/skills/playcraft-research/SKILL.md +212 -0
  73. package/project-template/.claude/skills/playcraft-sprite-generation/SKILL.md +423 -0
  74. package/project-template/.claude/skills/playcraft-storyboard/SKILL.md +148 -0
  75. package/project-template/.claude/skills/playcraft-style-qa/SKILL.md +270 -0
  76. package/project-template/.claude/skills/playcraft-text-rendering/SKILL.md +236 -0
  77. package/project-template/.claude/skills/playcraft-vfx-animation/SKILL.md +130 -0
  78. package/project-template/.claude/skills/playcraft-workflow/SKILL.md +396 -0
  79. package/project-template/.cursor/hooks.json +17 -0
  80. package/project-template/.cursor/rules/playcraft-orchestrator.mdc +87 -0
  81. package/project-template/.cursor/rules/playcraft-subagent-boundary.mdc +18 -0
  82. package/project-template/CLAUDE.md +240 -0
  83. package/project-template/assets/audio/bgm/.gitkeep +0 -0
  84. package/project-template/assets/audio/sfx/.gitkeep +0 -0
  85. package/project-template/assets/bundles/.gitkeep +0 -0
  86. package/project-template/assets/images/bg/.gitkeep +0 -0
  87. package/project-template/assets/images/reference/.gitkeep +0 -0
  88. package/project-template/assets/images/storyboard/.gitkeep +0 -0
  89. package/project-template/assets/images/tiles/.gitkeep +0 -0
  90. package/project-template/assets/images/ui/.gitkeep +0 -0
  91. package/project-template/assets/images/vfx/.gitkeep +0 -0
  92. package/project-template/assets/models/.gitkeep +0 -0
  93. package/project-template/docs/team/agent-conduct.md +105 -0
  94. package/project-template/docs/team/agent-runtime-matrix.md +62 -0
  95. package/project-template/docs/team/atom-plan-format.md +74 -0
  96. package/project-template/docs/team/collaboration.md +288 -0
  97. package/project-template/docs/team/core-model.md +50 -0
  98. package/project-template/docs/team/platform-capabilities.md +15 -0
  99. package/project-template/docs/team/workflow-changelog.md +51 -0
  100. package/project-template/docs/team/workflow-consistency-checklist.md +128 -0
  101. package/project-template/game/config/.gitkeep +0 -0
  102. package/project-template/game/gameplay/.gitkeep +0 -0
  103. package/project-template/game/scenes/.gitkeep +0 -0
  104. package/project-template/logs/.gitkeep +0 -0
  105. package/project-template/ta-workspace/logs/.gitkeep +0 -0
  106. package/project-template/ta-workspace/scripts/.gitkeep +0 -0
  107. package/project-template/ta-workspace/tmp/.gitkeep +0 -0
  108. package/project-template/templates/atom-plan.template.json +26 -0
  109. package/project-template/templates/atom-plan.template.md +76 -0
  110. package/project-template/templates/design-brief.template.md +195 -0
  111. package/project-template/templates/design-lens-checklist.reference.md +117 -0
  112. package/project-template/templates/design-methodology.md +99 -0
  113. package/project-template/templates/designer-log.template.md +98 -0
  114. package/project-template/templates/developer-log.template.md +140 -0
  115. package/project-template/templates/five-axis-framework.md +186 -0
  116. package/project-template/templates/intent-clarifications.template.md +58 -0
  117. package/project-template/templates/layout-spec.template.md +132 -0
  118. package/project-template/templates/project-state.template.md +219 -0
  119. package/project-template/templates/review-report.template.md +166 -0
  120. package/project-template/templates/style-exploration.template.md +93 -0
  121. package/project-template/templates/ta-log.template.md +205 -0
@@ -0,0 +1,356 @@
1
+ # TA 图片生成进阶参考
2
+
3
+ > 本文件供 TA/Designer 在需要精灵图直出、Edit 模型变体、错误恢复等进阶场景时按需查阅。核心决策逻辑见 `playcraft-image-generation` skill。
4
+
5
+ ---
6
+
7
+ ## 1. gpt-image-2 精灵图直出 + 批量出图策略
8
+
9
+ ### 策略一:直接生成整张精灵图(最高效)
10
+
11
+ **gpt-image-2 可以一次 API 调用就生成一张包含多个元素的网格图**,后续用 `sprite-split` 切分。避免逐个生成的低效循环。
12
+
13
+ > gpt-image-2 本身就慢(单图 7-8 分钟正常,精灵图 90-150 秒正常)。**调用 gpt-image-2 时不要设 `--timeout`**,让它自然完成。"慢"不是卡死,不要中途 Ctrl+C 换模型。真正的失败是 `API 500` 或 `fetch failed`,那才需要切换 provider。
14
+
15
+ #### 先判断:元素需要透明背景吗?
16
+
17
+ ```
18
+ 需要透明背景(独立元素:角色、车、道具、图标)?
19
+ ├─ YES → 绿幕策略:prompt 所有格子加 "solid bright green #00FF00 background"
20
+ │ 切分后对每帧跑 remove-background --tolerance 25
21
+ └─ NO → 白底策略:prompt 加 "white background"(卡牌/棋盘/UI 面板适用)
22
+ ```
23
+
24
+ #### 白底示例(卡牌,不需要去背景)
25
+
26
+ ```bash
27
+ playcraft tools generate-image \
28
+ --prompt "Sprite sheet grid, 4 columns × 2 rows. Each cell: one playing card face, flat 2D, white card face, uniform size. Row 1: Ace of Spades, 2 of Spades, 3 of Spades, 4 of Spades. Row 2: 5 of Spades, 6 of Spades, 7 of Spades, 8 of Spades. Grid layout, equal cell size, no border between cells." \
29
+ --output assets/gen/cards_sheet.png \
30
+ --aspect-ratio 3:2 \
31
+ --image-model iegg-litellm/gpt-image-2
32
+ # gpt-image-2 不设 --timeout,精灵图 90-150s 正常,等待即可
33
+
34
+ # 查尺寸再切分(frame-width=总宽/列数, frame-height=总高/行数)
35
+ playcraft image info --input assets/gen/cards_sheet.png
36
+ playcraft image sprite-split \
37
+ --input assets/gen/cards_sheet.png \
38
+ --output-dir assets/images/cards/ \
39
+ --rows 2 --columns 4 \
40
+ --frame-width <总宽/4> --frame-height <总高/2>
41
+ ```
42
+
43
+ #### 绿幕示例(独立元素,需要透明背景)
44
+
45
+ ```bash
46
+ # Step 1:生成绿幕精灵图
47
+ playcraft tools generate-image \
48
+ --prompt "Sprite sheet grid, 3 columns × 1 row. Each cell: one car, flat 2D vector, bold outline, centered, isolated on solid bright green #00FF00 background. [Row1,Col1]: red sports car front view; [Row1,Col2]: blue SUV front view; [Row1,Col3]: yellow taxi front view. Grid layout, equal cell size, no border between cells." \
49
+ --output assets/gen/cars_sheet.png \
50
+ --aspect-ratio 3:2 \
51
+ --image-model iegg-litellm/gpt-image-2
52
+ # gpt-image-2 不设 --timeout,精灵图 90-150s 正常,等待即可
53
+
54
+ # Step 2:切分
55
+ playcraft image info --input assets/gen/cars_sheet.png
56
+ playcraft image sprite-split \
57
+ --input assets/gen/cars_sheet.png \
58
+ --output-dir assets/gen/cars-split/ \
59
+ --rows 1 --columns 3 \
60
+ --frame-width <总宽/3> --frame-height <总高>
61
+
62
+ # Step 3:逐帧去背景(绿幕用 tolerance 25)
63
+ for f in assets/gen/cars-split/frame_*.png; do
64
+ name=$(basename "$f")
65
+ playcraft image remove-background \
66
+ --input "$f" \
67
+ --output "assets/images/cars/$name" \
68
+ --tolerance 25
69
+ done
70
+ ```
71
+
72
+ **Provider 选择**:iegg-litellm/gpt-image-2 质量最高;google/gemini-3.1-flash-image-preview 最稳定且参考图正常工作。
73
+
74
+ **Prompt 关键词**:`sprite sheet grid, N columns × M rows, grid layout, equal cell size, uniform size`
75
+
76
+ **每批推荐最多 16 个元素(4x4)**,元素太多时会出现混乱。
77
+
78
+ ### 策略二:批量出图(n>1,一次 API 调用返回多张候选)
79
+
80
+ `--count N` 让同一个 prompt 一次返回 N 张候选图,适合 Phase 1 挑图。**谨慎使用,容易触发 provider 并发限制。**
81
+
82
+ ```bash
83
+ # 一次 API 调用生成 4 张候选,选最好的
84
+ playcraft tools generate-image \
85
+ --prompt "A single playing card, Ace of Hearts, flat 2D..." \
86
+ --output assets/gen/card \
87
+ --count 4 \
88
+ --image-model iegg-litellm/gpt-image-2
89
+ # → 保存为 card_1.png card_2.png card_3.png card_4.png
90
+ ```
91
+
92
+ > `--count N` 是"同一 prompt 出 N 张变体",而不是"N 个不同元素"。生成 N 个不同元素请用策略一(精灵图直出)。
93
+
94
+ **两种策略对比**:
95
+
96
+ | 场景 | 推荐策略 | 说明 |
97
+ | -------------------------- | --------------------------- | --------------------------------- |
98
+ | <=16 个同类元素 | 精灵图直出(策略一) | 一张网格图 + sprite-split,最高效 |
99
+ | 17-52 个元素 | 精灵图直出分批(每批 <=16) | 生成多张精灵图再切分 |
100
+ | 风格变体(同构造不同内容) | 批量出图 `--count 4-6` | 同 prompt 出多张挑最好的 |
101
+ | 禁止 | 逐个生成每个元素 | 效率极低,应全面避免 |
102
+
103
+ ### 策略三:分批生成精灵图(元素数量 > 16)
104
+
105
+ ```javascript
106
+ // ta-workspace/scripts/gen-cards-batch-sheets.mjs
107
+ // 52 张牌 → 4 批 × 13 = 4 张精灵图,再统一切分
108
+ const BATCHES = [
109
+ {
110
+ name: "sheet_spades",
111
+ cards: [
112
+ "A♠",
113
+ "2♠",
114
+ "3♠",
115
+ "4♠",
116
+ "5♠",
117
+ "6♠",
118
+ "7♠",
119
+ "8♠",
120
+ "9♠",
121
+ "10♠",
122
+ "J♠",
123
+ "Q♠",
124
+ "K♠",
125
+ ],
126
+ },
127
+ {
128
+ name: "sheet_hearts",
129
+ cards: [
130
+ "A♥",
131
+ "2♥",
132
+ "3♥",
133
+ "4♥",
134
+ "5♥",
135
+ "6♥",
136
+ "7♥",
137
+ "8♥",
138
+ "9♥",
139
+ "10♥",
140
+ "J♥",
141
+ "Q♥",
142
+ "K♥",
143
+ ],
144
+ },
145
+ {
146
+ name: "sheet_diamonds",
147
+ cards: [
148
+ "A♦",
149
+ "2♦",
150
+ "3♦",
151
+ "4♦",
152
+ "5♦",
153
+ "6♦",
154
+ "7♦",
155
+ "8♦",
156
+ "9♦",
157
+ "10♦",
158
+ "J♦",
159
+ "Q♦",
160
+ "K♦",
161
+ ],
162
+ },
163
+ {
164
+ name: "sheet_clubs",
165
+ cards: [
166
+ "A♣",
167
+ "2♣",
168
+ "3♣",
169
+ "4♣",
170
+ "5♣",
171
+ "6♣",
172
+ "7♣",
173
+ "8♣",
174
+ "9♣",
175
+ "10♣",
176
+ "J♣",
177
+ "Q♣",
178
+ "K♣",
179
+ ],
180
+ },
181
+ ];
182
+ // 每批生成一张 13×1 精灵图,再用 sprite-split 切分
183
+ ```
184
+
185
+ 参考脚本模板:[gen-batch-sprite.template.mjs](../../skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs)
186
+
187
+ ---
188
+
189
+ ## 2. Edit 模型工作流(基图 → 编辑变体)
190
+
191
+ ### 适用场景
192
+
193
+ 结构相同、只改局部的变体集合:扑克牌(换花色/换数字)、棋子(换颜色)、图标集(换内容符号)。
194
+
195
+ ### 工作流
196
+
197
+ ```
198
+ Phase 1:高质量模型生成 1 张完美基图
199
+ → gpt-image-2 / gemini-flash(最佳质量)
200
+ → 反复生成直到满意,存为 base_xxx.png
201
+
202
+ Phase 2:用参考图 + prompt 批量生成变体
203
+ → 任何 text+image 或 image→image 模型均可
204
+ → 将基图作为 --reference-image,prompt 中描述变体差异
205
+ → 纯 edit 场景可用 mulerouter/qwen-image-edit-max
206
+ ```
207
+
208
+ ### Edit Prompt 写法
209
+
210
+ ```
211
+ 好的写法(修改指令):
212
+ "Change the rank symbol from A to 2, show two spade symbols in the center"
213
+
214
+ 差的写法(完整重描述):
215
+ "A playing card with two spade symbols, white background..."
216
+ (这会让模型重新生图,而不是编辑)
217
+ ```
218
+
219
+ ### 使用脚本模板
220
+
221
+ ```bash
222
+ cp .claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs \
223
+ ta-workspace/scripts/gen-<name>-variants.mjs
224
+ # 修改 CONFIG.baseImage / CONFIG.editModel / VARIANTS[] 后运行
225
+ node ta-workspace/scripts/gen-<name>-variants.mjs
226
+ ```
227
+
228
+ ---
229
+
230
+ ## 3. 错误恢复策略
231
+
232
+ > **gpt-image-2 超时规则(最重要)**:gpt-image-2 慢是设计如此,不是故障。单图 7-8 分钟、精灵图 90-150 秒均属正常范围。**调用 gpt-image-2 时永远不要设 `--timeout`**,也不要因为"等了很久"就 Ctrl+C 中断。只有收到 `API 500` 或 `fetch failed` 才切换 provider。
233
+
234
+ | 错误现象 | 模型 | 原因 | 立即行动 |
235
+ | ---------------------- | ------------------------------------------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
236
+ | `API 500` | 任意 | 该 provider 节点不可用 | **立即换同模型的另一个 provider**(如 `iegg-litellm/gpt-image-2` → `mulerouter/gpt-image-2` → `302/gpt-image-2`) |
237
+ | `fetch failed` | 任意 | provider 网络不通 | 换另一个 provider |
238
+ | 等待 7-8 分钟还未返回 | **gpt-image-2** | 正常现象,模型本身就慢 | **继续等待,不要中断**;若超过 15 分钟仍无响应则换同模型另一 provider |
239
+ | 等待 >120s 无响应 | **非 gpt-image-2**(gemini/nano-banana 等) | 请求卡死 | Ctrl+C 中止,换另一个 provider 或换模型;可加 `--timeout 60` 防止下次卡住 |
240
+ | 精灵图等待 90-150s | **gpt-image-2** | 正常现象 | 继续等待;**不要设 `--timeout`** |
241
+ | `--count N` 触发限流 | 任意 | 并发提交多任务超过 provider 限制 | 降低 count 或改用精灵图直出策略 |
242
+ | `reference-image` 报错 | 任意 | 模型 CAPABILITY 为 `text→image`,不支持参考图 | 换 CAPABILITY 为 `text+image` 或 `image→image` 的模型 |
243
+ | 风格偏差大 | 任意 | Prompt 不够具体 | 参考 prompt-cookbook.md 对应素材类型模板 |
244
+ | 质量不达标 | 非 gpt-image-2 | 模型能力不够 | 换 gpt-image-2(最高质量)+ 参考 prompt-cookbook 质量修饰词 |
245
+
246
+ ### 模型回退顺序
247
+
248
+ ```
249
+ gpt-image-2(最高质量,三个 provider 互为回退):
250
+ 1. iegg-litellm/gpt-image-2
251
+ 2. mulerouter/gpt-image-2
252
+ 3. 302/gpt-image-2
253
+
254
+ 稳定回退(非 gpt-image-2):
255
+ 4. google/gemini-3.1-flash-image-preview
256
+ 5. mulerouter/nano-banana-2
257
+ ```
258
+
259
+ **同一个 provider 最多重试 1 次**,失败立即切换到同模型的另一个 provider,不要等待。
260
+
261
+ ---
262
+
263
+ ## 4. 批量生成最佳实践
264
+
265
+ ### 首选策略:精灵图直出(见第 1 节)
266
+
267
+ **优先让 gpt-image-2 直接生成包含多个元素的网格图**,然后用 `sprite-split` 切分。这是最高效的做法,避免逐个 API 调用。只有在以下情况才退化为逐个调用:
268
+
269
+ - 需要 reference-image 一致性(网格 prompt 不稳定)
270
+ - 每个元素差异太大,一张图放不下
271
+
272
+ ### 单张验证后再批量
273
+
274
+ 先生成 1 张验证效果,满意后再运行批量脚本。
275
+
276
+ ### 使用 Node.js 脚本(推荐)
277
+
278
+ 参见 [gen-batch.template.mjs](../../skills/playcraft-image-generation/reference/gen-batch.template.mjs),复制到 `ta-workspace/scripts/` 后修改 CONFIG 区域。
279
+
280
+ ```bash
281
+ cp .claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs \
282
+ ta-workspace/scripts/gen-<name>.mjs
283
+ # 修改 CONFIG / ITEMS[] 后运行
284
+ node ta-workspace/scripts/gen-<name>.mjs
285
+ ```
286
+
287
+ ### 批量处理
288
+
289
+ 参见 [process-batch.template.mjs](../../skills/playcraft-image-generation/reference/process-batch.template.mjs)。
290
+
291
+ ```bash
292
+ cp .claude/skills/playcraft-image-generation/reference/process-batch.template.mjs \
293
+ ta-workspace/scripts/process-<name>.mjs
294
+ # 修改 CONFIG(特别是 skipRemoveBg)后运行
295
+ node ta-workspace/scripts/process-<name>.mjs
296
+ ```
297
+
298
+ ### 合并精灵图
299
+
300
+ 参见 [build-sprite-sheet.template.mjs](../../skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs)。
301
+
302
+ ```bash
303
+ cp .claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs \
304
+ ta-workspace/scripts/build-<name>-atlas.mjs
305
+ # 修改 CONFIG / ORDERED_NAMES[] 后运行
306
+ node ta-workspace/scripts/build-<name>-atlas.mjs
307
+ ```
308
+
309
+ ---
310
+
311
+ ## 5. TA Workspace:Node.js 脚本驱动
312
+
313
+ ### 为什么用 Node.js 而不是 bash?
314
+
315
+ | 维度 | bash | Node.js |
316
+ | -------- | ----------------- | -------------------------- |
317
+ | 语法错误 | 引号/转义陷阱多 | 标准 ES 语法,错误立即可读 |
318
+ | 条件逻辑 | 繁琐 | if/else/switch 简洁 |
319
+ | 错误处理 | `set -e` 容易遗漏 | try/catch 完整覆盖 |
320
+ | 数据驱动 | 字符串拼接 | 对象数组,结构清晰 |
321
+ | 调试 | `bash -x` 噪声大 | `console.log` 精确定位 |
322
+
323
+ **结论**:超过 5 步或超过 10 个文件,始终写 Node.js 脚本。
324
+
325
+ ### ta-workspace 目录约定
326
+
327
+ ```
328
+ ta-workspace/
329
+ ├── scripts/ ← Node.js 脚本(.mjs)
330
+ ├── logs/ ← 脚本运行日志(自动追加)
331
+ └── tmp/ ← 临时文件(脚本完成后自动清理)
332
+ ```
333
+
334
+ ### 脚本模板目录
335
+
336
+ | 模板 | 用途 | 关键 CONFIG |
337
+ | -------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | --------------------------------------------- |
338
+ | [gen-batch-sprite.template.mjs](../../skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs) | 精灵图直出(gpt-image-2 网格图 → sprite-split) | `columns`, `rows`, `BATCHES[]` |
339
+ | [gen-batch.template.mjs](../../skills/playcraft-image-generation/reference/gen-batch.template.mjs) | 批量从零 AI 生图(reference-image 模式) | `model`, `referenceImage`, `style`, `ITEMS[]` |
340
+ | [gen-edit-variants.template.mjs](../../skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs) | 基图 + edit 模型生成变体 | `baseImage`, `editModel`, `VARIANTS[]` |
341
+ | [process-batch.template.mjs](../../skills/playcraft-image-generation/reference/process-batch.template.mjs) | 批量去背景 / trim + resize | `inputDir`, `outputDir`, `skipRemoveBg` |
342
+ | [build-sprite-sheet.template.mjs](../../skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs) | 精灵图合并 + JSON 验证 | `processedDir`, `columns`, `ORDERED_NAMES[]` |
343
+
344
+ 每个模板均包含:CONFIG/DATA/LOGIC 三段式结构、`existsSync` 幂等跳过、`appendFileSync` 日志、try/catch 错误统计。
345
+
346
+ ### 什么时候用命令行,什么时候写脚本?
347
+
348
+ | 场景 | 命令行 | 脚本 |
349
+ | -------------------------------- | ------ | ---- |
350
+ | 单张图片处理 / 查看信息 | 是 | — |
351
+ | 3-5 个文件,步骤简单 | 是 | — |
352
+ | 10+ 个文件,相同步骤 | — | 是 |
353
+ | 需要条件逻辑(不同素材不同参数) | — | 是 |
354
+ | 需要验证中间结果 | — | 是 |
355
+ | 需要幂等重跑(跳过已存在) | — | 是 |
356
+ | 完整管线(生成 → 处理 → 打包) | — | 是 |