@rig-c/parts 2.44.0 → 2.45.0

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.
package/README.md CHANGED
@@ -329,7 +329,9 @@ Command details and config saving are in the [command reference](docs/AUTHORING.
329
329
  | `layers` | [Inspect wrapper layers or a PSD](docs/AUTHORING.md#command-reference) |
330
330
  | `sheet` | [Make a contact sheet](docs/AUTHORING.md#command-reference) |
331
331
  | `assemble` | [Merge layers into measured parts](docs/AUTHORING.md#command-reference) |
332
+ | `diff-drafts` | [Compare two assemble outputs](docs/AUTHORING.md#command-reference) |
332
333
  | `edited-part` | [Record an edited part receipt](docs/AUTHORING.md#edited-rig-space-parts-assembleedited_parts-issue-1278) |
334
+ | `external-receipt` | [Record or verify an external mask](docs/AUTHORING.md#external-mask-receipt) |
333
335
  | `propose` | [Draft or inspect a character config](docs/AUTHORING.md#command-reference) |
334
336
  | `compare` | [Compare two skeletons by name](docs/AUTHORING.md#command-reference) |
335
337
  | `rig` | [Author gated rig and motion specs](docs/AUTHORING.md#command-reference) |
package/cli.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env bun
2
2
  import { diffComponentsCommand } from './src/diffcomponents.ts';
3
+ import { DIFF_DRAFTS_SPEC, diffDraftsCommand } from './src/diffdrafts.ts';
3
4
  import { applyTakenLayers } from './src/takelayers.ts';
4
5
  import { applyDepth, bindDepthMap, prepareDepth } from './src/depthworkflow.ts';
6
+ import { externalReceipt } from './src/externalreceipt.ts';
5
7
  import { writeEditedPart } from './tools/edited-part-cli.ts';
6
8
  /**
7
9
  * rig-parts — one painting and its See-through layers in, Spine-ready parts
@@ -74,7 +76,9 @@ const LATER: ReadonlyArray<[string, string]> = [];
74
76
  const HELP = `rig-parts ${version()} — Spine-ready parts from one painting and its See-through layers
75
77
 
76
78
  usage:
77
- rig-parts edited-part --config <config.json> --part <name> --file <edited.png> --from <assembled.png> --editor <text> [--rig-config <config.json>]
79
+ rig-parts edited-part --config <config.json> --part <name> --file <edited.png> --from <assembled.png> (--producer <json> | --editor <text>) [--rig-config <config.json>]
80
+ rig-parts external-receipt --kind mask --file <png> --painting <png> --producer <json> --out <receipt.json>
81
+ rig-parts external-receipt --verify <receipt.json>
78
82
  Record both file hashes and the declared editor in one edited_parts receipt.
79
83
  Update only explicitly named configs; build verifies the assembled baseline.
80
84
 
@@ -82,6 +86,12 @@ usage:
82
86
  [--threshold <channel>] [--figure <binary-png>] [--owners] (--out <json> | --verify <json>)
83
87
  Exhaustive native difference inventory; default max RGB channel > 40.
84
88
 
89
+ rig-parts diff-drafts --left <dir> --right <dir> --out <json>
90
+ Compare two assemble or build outputs and write ${DIFF_DRAFTS_SPEC} JSON:
91
+ per-part status (same, changed, added, removed), file sha256, rig-pixel
92
+ box and draw-order index per present side, pixels_equal and rig-space
93
+ pixel diff counts/bounds on changed parts, and the composite pixel diff.
94
+
85
95
 
86
96
  rig-parts depth-prepare --parts <assembled-dir> --config <depth-recipe.json> --out <empty-dir>
87
97
  Write per-part inference PNGs on neutral gray, upscaled and padded as
@@ -1102,6 +1112,14 @@ function cmdDiffComponents(args: string[]): number {
1102
1112
  try { diffComponentsCommand(args); return EXIT_OK; } catch (err) { return printRefusal(err); }
1103
1113
  }
1104
1114
 
1115
+ function cmdDiffDrafts(args: string[]): number {
1116
+ for (let i = 0; i < args.length; i += 2) {
1117
+ if (!takesValued('diff-drafts', args[i])) return usage(notTaken('diff-drafts', args[i]));
1118
+ if (args[i + 1] === undefined || args[i + 1].startsWith('--')) return usage(`diff-drafts ${args[i]} requires a value`);
1119
+ }
1120
+ try { diffDraftsCommand(args); return EXIT_OK; } catch (err) { return printRefusal(err); }
1121
+ }
1122
+
1105
1123
  /** `guide`: one argument, a rule name or a section; the slice printed, or the refusal. */
1106
1124
  function cmdGuide(args: string[]): number {
1107
1125
  if (args.length !== 1) return usage(`guide takes one rule name or one §<n> / §<n>.<m> / §<n>.<m>.<k>; got ${args.length} argument(s)`);
@@ -1190,33 +1208,35 @@ function printLayerTable(set: LayerSet): void {
1190
1208
  * no row; `layers` takes one positional path beside its flags (issue #359).
1191
1209
  */
1192
1210
  const TAKES = {
1193
- 'edited-part': { valued: ['--config', '--part', '--file', '--from', '--editor', '--rig-config'], switches: [] },
1194
- 'check-parts': { valued: ['--parts', '--out'], switches: ['--json'] },
1195
- 'diff-components': { valued: ['--stack', '--painting', '--parts', '--figure', '--floor', '--threshold', '--out', '--verify'], switches: ['--owners'] },
1196
- 'depth-bind': { valued: ['--map', '--input', '--part'], switches: [] },
1197
- 'depth-prepare': { valued: ['--parts', '--config', '--out'], switches: [] },
1198
- 'depth-apply': { valued: ['--parts', '--manifest', '--config', '--rig-config', '--out'], switches: [] },
1199
- layers: { valued: ['--export', '--template', '--canvas', '--full', '--source', '--config'], switches: [] },
1200
- sheet: { valued: ['--source', '--layers', '--out', '--cell', '--cols'], switches: [] },
1201
- rig: { valued: ['--config', '--parts', '--out', '--idle-keys', '--page-edges', '--pack-shape', '--page-size'], switches: [] },
1202
- propose: { valued: ['--parts', '--source', '--out', '--from-config', '--compare', '--full', '--head', '--canvas', '--keypoints', '--person', '--wrist-snap', '--grid-rule', '--cloth', '--write-config', '--from', '--bust-landmarks', '--no-bust'], switches: ['--head-box', '--no-back-hair', '--only-missing'] },
1203
- compare: { valued: ['--left', '--right', '--map'], switches: [] },
1204
- check: { valued: ['--rig', '--out', '--parts', '--source', '--page-edges', '--pack-shape', '--page-size', '--requirements', '--set', '--environment', '--wind-band'], switches: ['--seam-pairs', '--keep-stills', '--all-sets', '--no-extremes', '--json'] },
1205
- loop: { valued: ['--frames', '--out'], switches: ['--palette'] },
1206
- assemble: { valued: ['--source', '--full', '--head', '--config', '--out', '--emit-fill-masks', '--seam', '--project', '--alt', '--write-config', '--requirements'], switches: ['--propose-plan'] },
1207
- 'comfy seethrough': { valued: ['--image', '--out', '--resolution', '--steps', '--seed', '--prefix', '--host', '--wait', '--timeout', '--poll', '--config', '--depth-run'], switches: ['--offload', '--no-offload', '--lama', '--nf4'] },
1208
- 'comfy paint': { valued: ['--config', '--out', '--seeds', '--seed0', '--host', '--wait', '--timeout', '--poll'], switches: [] },
1209
- 'comfy matte': { valued: ['--painting', '--out', '--node', '--model', '--checkpoint-sha256', '--resolution', '--threshold', '--host', '--wait', '--timeout', '--poll'], switches: [] },
1210
- 'comfy plate': { valued: ['--mode', '--painting', '--mask-from', '--occluder', '--out', '--graph', '--model', '--checkpoint-sha256', '--seed', '--grow', '--steps', '--cfg', '--prompt', '--negative', '--host', '--wait', '--timeout', '--poll'], switches: ['--holes'] },
1211
- inputs: { valued: ['--source', '--config', '--out'], switches: [] },
1212
- build: { valued: ['--config', '--source', '--full', '--head', '--out', '--seam', '--project', '--page-edges', '--pack-shape', '--page-size', '--requirements', '--idle-keys', '--lead-in', '--alt', '--set', '--environment', '--wind-band'], switches: ['--loop', '--seam-pairs', '--keep-stills', '--all-sets', '--no-extremes'] },
1213
- compose: { valued: ['--scene', '--out', '--requirements', '--accept', '--page-size'], switches: [] },
1214
- 'mesh-draft': { valued: ['--config', '--parts', '--out', '--requirements', '--idle-keys', '--page-edges', '--pack-shape', '--page-size'], switches: ['--more-triangles'] },
1215
- 'mesh-stats': { valued: ['--config', '--parts'], switches: [] },
1216
- remesh: { valued: ['--rig', '--config', '--parts', '--part', '--mesh', '--delta', '--out', '--requirements', '--idle-keys', '--page-edges', '--pack-shape', '--page-size', '--input-check'], switches: ['--record-input-check'] },
1217
- retune: { valued: ['--rig', '--config', '--parts', '--out', '--requirements', '--idle-keys', '--page-edges', '--pack-shape', '--page-size', '--input-check'], switches: ['--record-input-check'] },
1218
- 'head-crop-preflight': { valued: ['--full', '--canvas', '--head-box'], switches: [] },
1219
- painting: { valued: ['--keypoints', '--person', '--form'], switches: [] },
1211
+ 'edited-part': { valued: ['--config', '--part', '--file', '--from', '--editor', '--producer', '--rig-config'], switches: ['--help'] },
1212
+ 'external-receipt': { valued: ['--kind', '--file', '--painting', '--producer', '--out', '--verify'], switches: ['--help'] },
1213
+ 'check-parts': { valued: ['--parts', '--out'], switches: ['--json', '--help'] },
1214
+ 'diff-components': { valued: ['--stack', '--painting', '--parts', '--figure', '--floor', '--threshold', '--out', '--verify'], switches: ['--owners', '--help'] },
1215
+ 'diff-drafts': { valued: ['--left', '--right', '--out'], switches: ['--help'] },
1216
+ 'depth-bind': { valued: ['--map', '--input', '--part'], switches: ['--help'] },
1217
+ 'depth-prepare': { valued: ['--parts', '--config', '--out'], switches: ['--help'] },
1218
+ 'depth-apply': { valued: ['--parts', '--manifest', '--config', '--rig-config', '--out'], switches: ['--help'] },
1219
+ layers: { valued: ['--export', '--template', '--canvas', '--full', '--source', '--config'], switches: ['--help'] },
1220
+ sheet: { valued: ['--source', '--layers', '--out', '--cell', '--cols'], switches: ['--help'] },
1221
+ rig: { valued: ['--config', '--parts', '--out', '--idle-keys', '--page-edges', '--pack-shape', '--page-size'], switches: ['--help'] },
1222
+ propose: { valued: ['--parts', '--source', '--out', '--from-config', '--compare', '--full', '--head', '--canvas', '--keypoints', '--person', '--wrist-snap', '--grid-rule', '--cloth', '--write-config', '--from', '--bust-landmarks', '--no-bust'], switches: ['--head-box', '--no-back-hair', '--only-missing', '--help'] },
1223
+ compare: { valued: ['--left', '--right', '--map'], switches: ['--help'] },
1224
+ check: { valued: ['--rig', '--out', '--parts', '--source', '--page-edges', '--pack-shape', '--page-size', '--requirements', '--set', '--environment', '--wind-band'], switches: ['--seam-pairs', '--keep-stills', '--all-sets', '--no-extremes', '--json', '--help'] },
1225
+ loop: { valued: ['--frames', '--out'], switches: ['--palette', '--help'] },
1226
+ assemble: { valued: ['--source', '--full', '--head', '--config', '--out', '--emit-fill-masks', '--seam', '--project', '--alt', '--write-config', '--requirements'], switches: ['--propose-plan', '--help'] },
1227
+ 'comfy seethrough': { valued: ['--image', '--out', '--resolution', '--steps', '--seed', '--prefix', '--host', '--wait', '--timeout', '--poll', '--config', '--depth-run'], switches: ['--offload', '--no-offload', '--lama', '--nf4', '--help'] },
1228
+ 'comfy paint': { valued: ['--config', '--out', '--seeds', '--seed0', '--host', '--wait', '--timeout', '--poll'], switches: ['--help'] },
1229
+ 'comfy matte': { valued: ['--painting', '--out', '--node', '--model', '--checkpoint-sha256', '--resolution', '--threshold', '--host', '--wait', '--timeout', '--poll'], switches: ['--help'] },
1230
+ 'comfy plate': { valued: ['--mode', '--painting', '--mask-from', '--occluder', '--out', '--graph', '--model', '--checkpoint-sha256', '--seed', '--grow', '--steps', '--cfg', '--prompt', '--negative', '--host', '--wait', '--timeout', '--poll'], switches: ['--holes', '--help'] },
1231
+ inputs: { valued: ['--source', '--config', '--out'], switches: ['--help'] },
1232
+ build: { valued: ['--config', '--source', '--full', '--head', '--out', '--seam', '--project', '--page-edges', '--pack-shape', '--page-size', '--requirements', '--idle-keys', '--lead-in', '--alt', '--set', '--environment', '--wind-band'], switches: ['--loop', '--seam-pairs', '--keep-stills', '--all-sets', '--no-extremes', '--help'] },
1233
+ compose: { valued: ['--scene', '--out', '--requirements', '--accept', '--page-size'], switches: ['--help'] },
1234
+ 'mesh-draft': { valued: ['--config', '--parts', '--out', '--requirements', '--idle-keys', '--page-edges', '--pack-shape', '--page-size'], switches: ['--more-triangles', '--help'] },
1235
+ 'mesh-stats': { valued: ['--config', '--parts'], switches: ['--help'] },
1236
+ remesh: { valued: ['--rig', '--config', '--parts', '--part', '--mesh', '--delta', '--out', '--requirements', '--idle-keys', '--page-edges', '--pack-shape', '--page-size', '--input-check'], switches: ['--record-input-check', '--help'] },
1237
+ retune: { valued: ['--rig', '--config', '--parts', '--out', '--requirements', '--idle-keys', '--page-edges', '--pack-shape', '--page-size', '--input-check'], switches: ['--record-input-check', '--help'] },
1238
+ 'head-crop-preflight': { valued: ['--full', '--canvas', '--head-box'], switches: ['--help'] },
1239
+ painting: { valued: ['--keypoints', '--person', '--form'], switches: ['--help'] },
1220
1240
  } as const satisfies Record<string, { valued: readonly string[]; switches: readonly string[] }>;
1221
1241
 
1222
1242
  type Command = keyof typeof TAKES;
@@ -1226,10 +1246,73 @@ function takesValued(command: Command, flag: string): boolean {
1226
1246
  return (TAKES[command].valued as readonly string[]).includes(flag);
1227
1247
  }
1228
1248
 
1229
- /** The unknown-flag refusal: the flag, and every flag the command's {@link TAKES} row holds, valued then bare. */
1249
+ /** The unknown-flag refusal: the flag, and every flag the command's {@link TAKES} row holds, valued then bare (keeping `--help` out of non-compose refusals so no non-help output byte changes, issue #1360). */
1230
1250
  function notTaken(command: Command, flag: string): string {
1231
1251
  const row = TAKES[command];
1232
- return `${command} does not take "${flag}"; it takes ${[...row.valued, ...row.switches].join(', ')}`;
1252
+ const switches = command === 'compose' ? row.switches : row.switches.filter((f) => f !== '--help');
1253
+ return `${command} does not take "${flag}"; it takes ${[...row.valued, ...switches].join(', ')}`;
1254
+ }
1255
+
1256
+ /** One command's (or comfy subcommand's) own usage section from {@link HELP}. */
1257
+ function commandUsage(target: string): string | null {
1258
+ const end = HELP.indexOf('\n rig-parts --version');
1259
+ const lines = (end < 0 ? HELP : HELP.slice(0, end)).split('\n');
1260
+ const head = ` rig-parts ${target} `;
1261
+ const from = lines.findIndex((l) => l.startsWith(head));
1262
+ if (from < 0) return null;
1263
+ let to = lines.length;
1264
+ for (let i = from + 1; i < lines.length; i++) {
1265
+ if (lines[i].startsWith(' rig-parts ') && !lines[i].startsWith(head)) {
1266
+ to = i;
1267
+ break;
1268
+ }
1269
+ }
1270
+ while (to > from && lines[to - 1] === '') to--;
1271
+ return lines.slice(from, to).join('\n');
1272
+ }
1273
+
1274
+ /** Shared `--help` / `-h` path taken before any command's own flag parsing (issue #1360). */
1275
+ function maybeCommandHelp(command: string, args: readonly string[]): number | null {
1276
+ if (!args.includes('--help') && !args.includes('-h')) return null;
1277
+ if (command === 'guide') {
1278
+ if (args.length === 1 && (args[0] === '--help' || args[0] === '-h')) {
1279
+ console.log(commandUsage('guide'));
1280
+ return EXIT_OK;
1281
+ }
1282
+ return null;
1283
+ }
1284
+ if (command === 'comfy' && (args[0] === '--help' || args[0] === '-h')) {
1285
+ if (args.filter((a) => a === '--help' || a === '-h').length > 1) return usage('--help is given twice');
1286
+ const extra = args.find((a) => a !== '--help' && a !== '-h');
1287
+ if (extra !== undefined) return usage(`comfy takes seethrough, paint, plate or matte; got "${extra}"`);
1288
+ console.log(commandUsage('comfy'));
1289
+ return EXIT_OK;
1290
+ }
1291
+ const target: Command | null =
1292
+ command === 'comfy'
1293
+ ? args[0] === 'seethrough' || args[0] === 'paint' || args[0] === 'plate' || args[0] === 'matte'
1294
+ ? `comfy ${args[0]}`
1295
+ : null
1296
+ : Object.hasOwn(TAKES, command)
1297
+ ? (command as Command)
1298
+ : null;
1299
+ if (target === null) return null;
1300
+ const cmdArgs = command === 'comfy' ? args.slice(1) : args;
1301
+ const help = cmdArgs.filter((a) => a === '--help' || a === '-h').length;
1302
+ if (help === 0) return null;
1303
+ if (help > 1) return usage('--help is given twice');
1304
+ const rest = cmdArgs.filter((a) => a !== '--help' && a !== '-h');
1305
+ const switches = (TAKES[target].switches as readonly string[]).filter((f) => f !== '--help');
1306
+ for (let i = 0; i < rest.length; i++) {
1307
+ const flag = rest[i];
1308
+ if (switches.includes(flag)) continue;
1309
+ if ((target === 'layers' || target === 'painting') && !flag.startsWith('--')) continue;
1310
+ if (!takesValued(target, flag)) return usage(notTaken(target, flag));
1311
+ if (rest[i + 1] === undefined) return usage(`${flag} needs a value`);
1312
+ i++;
1313
+ }
1314
+ console.log(commandUsage(target));
1315
+ return EXIT_OK;
1233
1316
  }
1234
1317
 
1235
1318
 
@@ -2545,12 +2628,22 @@ function cmdDepthPrepare(args: string[]): number {
2545
2628
  }
2546
2629
 
2547
2630
  function cmdEditedPart(args: string[]): number {
2548
- const f = flags(args, 'edited-part', ['--config', '--part', '--file', '--from', '--editor']);
2631
+ const f = flags(args, 'edited-part', ['--config', '--part', '--file', '--from']);
2549
2632
  if (typeof f === 'string') return usage(f);
2633
+ if (!f.has('--editor') && !f.has('--producer')) return usage('edited-part needs --producer <json> or --editor <text>');
2550
2634
  try {
2551
- const { receipt, writes } = writeEditedPart({ config: f.get('--config')!, part: f.get('--part')!, file: f.get('--file')!, from: f.get('--from')!, editor: f.get('--editor')!, rigConfig: f.get('--rig-config') });
2635
+ const { receipt, writes } = writeEditedPart({ config: f.get('--config')!, part: f.get('--part')!, file: f.get('--file')!, from: f.get('--from')!, editor: f.get('--editor'), producer: f.get('--producer'), rigConfig: f.get('--rig-config') });
2552
2636
  for (const { target, changes } of writes) for (const line of configWriteLines(target, changes)) console.error(line);
2553
- console.log(`edited-part: part ${JSON.stringify(receipt.part)} sha256=${receipt.sha256} from_sha256=${receipt.from_sha256} editor=${JSON.stringify(receipt.editor)}`);
2637
+ console.log(`edited-part: part ${JSON.stringify(receipt.part)} sha256=${receipt.sha256} from_sha256=${receipt.from_sha256} ${receipt.editor === undefined ? 'producer' : 'editor'}=${JSON.stringify(receipt.editor ?? receipt.producer)}`);
2638
+ return EXIT_OK;
2639
+ } catch (error) { return printRefusal(error); }
2640
+ }
2641
+
2642
+ function cmdExternalReceipt(args: string[]): number {
2643
+ const f = flags(args, 'external-receipt', []);
2644
+ if (typeof f === 'string') return usage(f);
2645
+ try {
2646
+ externalReceipt(f);
2554
2647
  return EXIT_OK;
2555
2648
  } catch (error) { return printRefusal(error); }
2556
2649
  }
@@ -2587,10 +2680,14 @@ function main(argv: string[]): number | Promise<number> {
2587
2680
  console.log(version());
2588
2681
  return EXIT_OK;
2589
2682
  }
2683
+ const helped = maybeCommandHelp(command, rest);
2684
+ if (helped !== null) return helped;
2590
2685
  if (command === 'diff-components') return cmdDiffComponents(rest);
2686
+ if (command === 'diff-drafts') return cmdDiffDrafts(rest);
2591
2687
  if (command === 'layers') return cmdLayers(rest);
2592
2688
  if (command === 'depth-prepare') return cmdDepthPrepare(rest);
2593
2689
  if (command === 'edited-part') return cmdEditedPart(rest);
2690
+ if (command === 'external-receipt') return cmdExternalReceipt(rest);
2594
2691
  if (command === 'depth-bind') return cmdDepthBind(rest);
2595
2692
  if (command === 'depth-apply') return cmdDepthApply(rest);
2596
2693
  if (command === 'sheet') return cmdSheet(rest);