@rig-c/create 1.2.0 → 1.2.1
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/docs/CHECKS.md +1 -1
- package/package.json +1 -1
- package/src/restart.ts +29 -6
package/docs/CHECKS.md
CHANGED
|
@@ -1541,7 +1541,7 @@ and known regressions under `ledger`.
|
|
|
1541
1541
|
| `RESTART_NOT_A_PROJECT` | the folder has no readable `rig-create/project@0` `project.json` | run restart on a create project folder |
|
|
1542
1542
|
| `RESTART_NOT_IN_GIT` | the project folder is not inside a git work tree, so git history cannot hold the record restart replaces | put the project under git, commit `project.json`, then restart |
|
|
1543
1543
|
| `RESTART_RECORD_UNCOMMITTED` | `project.json` is untracked, staged but never committed, or differs from its version at HEAD | commit `project.json`, then restart |
|
|
1544
|
-
| `RESTART_INPUT_INVALID` | a kept input fails the input writer's checks,
|
|
1544
|
+
| `RESTART_INPUT_INVALID` | a kept input fails the input writer's checks, or a left-out legacy entry is the declared `painting` without a writer-valid twin for the same bytes | restore the file, or register it again with `input add` (`input add --painting` for the painting) |
|
|
1545
1545
|
| `RESTART_PART_SET_INCOMPLETE` | a kept part set (inputs under `<set>/parts/*.png` or `<set>/parts.json`) lacks `<set>/parts.json`, a part PNG, or its rig: `rig.json` and `mesh_report.json` at `<set>/rig/` or `<set>/` | register the missing files with `input add`, or stop keeping the set |
|
|
1546
1546
|
| `RESTART_MALFORMED` | `restarts` is not a list, or an entry lacks `{ at, by, reason, previous_record_sha256 }` | restore the entry `restart` wrote |
|
|
1547
1547
|
| `RESTART_SOURCE_CHANGED` | `project.json` changed while `restart` was validating | retry against the current record |
|
package/package.json
CHANGED
package/src/restart.ts
CHANGED
|
@@ -110,16 +110,36 @@ export function restartCommand(args: string[], now: number): { stdout: string; e
|
|
|
110
110
|
} catch { return notProject(`is not a ${PROJECT_SCHEMA} record`); }
|
|
111
111
|
const inputs = { dir, project, refusals: [] as Finding[], warnings: [] as Finding[] };
|
|
112
112
|
checkInputs(inputs);
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
const invalidInput = (finding: Finding): never => refuse('RESTART_INPUT_INVALID', `${finding.path}: ${finding.code}: ${finding.message}; a restart keeps only inputs the input writer would record, so restore the file or register it again with input add`);
|
|
114
|
+
const firstRefusal = inputs.refusals[0] ?? inputs.warnings.find(finding => finding.code !== 'INPUT_WRITER_MISSING');
|
|
115
|
+
if (firstRefusal !== undefined) invalidInput(firstRefusal);
|
|
116
|
+
const legacyPaths = new Set(inputs.warnings.filter(finding => finding.code === 'INPUT_WRITER_MISSING').map(finding => finding.path));
|
|
117
|
+
const keptInputs: Json[] = [];
|
|
118
|
+
const leftOut: { index: number; entry: JsonObject }[] = [];
|
|
119
|
+
asArray(project.inputs).forEach((raw, index) => {
|
|
120
|
+
if (legacyPaths.has(`inputs[${index}]`)) leftOut.push({ index, entry: isObject(raw) ? raw : {} });
|
|
121
|
+
else keptInputs.push(raw);
|
|
122
|
+
});
|
|
123
|
+
let painting = project.painting;
|
|
124
|
+
if (typeof painting === 'string' && !keptInputs.some(entry => isObject(entry) && entry.path === painting)) {
|
|
125
|
+
const legacyPainting = leftOut.find(({ entry }) => entry.path === painting)?.entry;
|
|
126
|
+
const twin = legacyPainting !== undefined && typeof legacyPainting.sha256 === 'string' && typeof legacyPainting.bytes === 'number'
|
|
127
|
+
? keptInputs.filter(isObject).find(entry => entry.sha256 === legacyPainting.sha256 && entry.bytes === legacyPainting.bytes && typeof entry.path === 'string')
|
|
128
|
+
: undefined;
|
|
129
|
+
if (twin !== undefined) painting = twin.path;
|
|
130
|
+
}
|
|
131
|
+
const keptCheck = { dir, project: { ...project, ...(painting !== undefined ? { painting } : {}), inputs: keptInputs }, refusals: [] as Finding[], warnings: [] as Finding[] };
|
|
132
|
+
checkInputs(keptCheck);
|
|
133
|
+
const keptFinding = keptCheck.refusals[0] ?? keptCheck.warnings[0];
|
|
134
|
+
if (keptFinding !== undefined) invalidInput(keptFinding);
|
|
135
|
+
const gaps = partSetGaps(keptInputs);
|
|
116
136
|
if (gaps.length) refuse('RESTART_PART_SET_INCOMPLETE', `inputs: a kept part set needs its parts.json and its rig with its PNGs, missing ${gaps.join('; ')}; register the missing files with input add, or stop keeping the set`);
|
|
117
137
|
const candidate = freshProjectRecord(typeof project.name === 'string' ? project.name : '', now);
|
|
118
138
|
if (project.name !== undefined) candidate.name = project.name;
|
|
119
139
|
if (project.title !== undefined) candidate.title = project.title;
|
|
120
|
-
if (
|
|
140
|
+
if (painting !== undefined) candidate.painting = painting;
|
|
121
141
|
if (project.same_artwork !== undefined) candidate.same_artwork = project.same_artwork;
|
|
122
|
-
candidate.inputs =
|
|
142
|
+
candidate.inputs = keptInputs;
|
|
123
143
|
candidate.fix_ledger = project.fix_ledger ?? [];
|
|
124
144
|
const entry: JsonObject = { at: new Date(now).toISOString(), by: opts['--by'], reason, previous_record_sha256: createHash('sha256').update(original).digest('hex') };
|
|
125
145
|
candidate.restarts = [...asArray(project.restarts), entry];
|
|
@@ -132,9 +152,12 @@ export function restartCommand(args: string[], now: number): { stdout: string; e
|
|
|
132
152
|
if (rejected !== undefined) refuse(rejected.code, rejected.message);
|
|
133
153
|
writeRecord(file, original, candidate, 'restart');
|
|
134
154
|
const rows = asArray(candidate.fix_ledger).length;
|
|
155
|
+
const leftOutText = leftOut.length
|
|
156
|
+
? `; left out legacy input(s) ${leftOut.map(({ index, entry: item }) => typeof item.path === 'string' && item.path.trim() !== '' ? `inputs[${index}] (${item.path})` : `inputs[${index}]`).join(', ')}`
|
|
157
|
+
: '';
|
|
135
158
|
return {
|
|
136
159
|
stdout: json ? JSON.stringify(entry, null, 2)
|
|
137
|
-
: `restart: project record restarted at stage ${String(candidate.stage)}; kept ${asArray(candidate.inputs).length} input(s) and ${rows} ledger row(s); the earlier record (sha256 ${String(entry.previous_record_sha256)}) is in git history`,
|
|
160
|
+
: `restart: project record restarted at stage ${String(candidate.stage)}; kept ${asArray(candidate.inputs).length} input(s) and ${rows} ledger row(s)${leftOutText}; the earlier record (sha256 ${String(entry.previous_record_sha256)}) is in git history`,
|
|
138
161
|
exit: 0,
|
|
139
162
|
};
|
|
140
163
|
} finally { release(); }
|