the package-authoring round: fork is the verb, the scaffold flag is the ready-to-run gate, the package editor is the owner's surface, and /packages is the launchpad

The design conversation settled the verb question (developer, 2026-11-19): a "create new package" with a base selector is fork under another name, so the SPA gains one list at /packages with three acts per card -- start (the run-create flow, unchanged), fork (any package, system or user, by anyone: the copy lands in state/packages owned by the forker, pc stripped, display name asked inline, the fork landing straight in the editor -- nobody forks to immediately start), and edit (the owner's own user packages only). /new retires to a redirect onto /packages; the source link (code.fleshless.org/hackmaster/tiny-worlds) rides the header.

The template's unplayability became machinery instead of a naming special-case: settings.json carries the "scaffold" flag (the records-bool precedent -- authored content carries the marker, machinery reads it). Create refuses a scaffold loudly on both ends ("fork it to author, then flip scaffold off in the editor"), the listing marks it, the SPA disables its start. The developer's ruling over my clear-the-flag draft: the flag RIDES FORKS UNTOUCHED -- a scaffold fork stays a scaffold until its author flips it off, so the flag is the package's doneness state, and publishing your own scaffold for others to fork is free. The settings editor is raw JSON for now (native UI later, the developer's "ready to run" toggle its eventual shape), with a hint teaching the keys.

The package editor (/packages/:name): every file of a user package is authoring material -- settings included -- with the cheap save lints (memory.json and settings.json must parse as JSON objects; the carryover passes the authored lint, the run surface's exact gate), the deep checks staying at the start gate where they already lived. The gates mirror the run precedent: system packages are repo-side and refuse ("fork to edit"); an ownerless user package is readable, forkable, never editable -- and an ownerless package IS forkable, the copy is yours.

The refactor the editor forced: the setup view's file-editor machinery (nav, textarea + the sigil/var highlight overlay, drafts, dirty marks, the save flow) extracted into widgets.mjs's fileEditor factory, parameterized over DOM ids and a PUT call -- setup keeps its run-side couplings (the phase-gated rw, the addressed session), the package editor is the simpler parameterization, and the editor CSS generalized from id selectors to classes so both surfaces share it.

En-route bug found and fixed: cmdCreate always copied the REPO's handbook.md into the run, so a user package's handbook -- which save-package faithfully copies out -- was silently ignored on re-create; the author's craft edit died in the round-trip. Create now prefers the package's own handbook when it carries one, else the repo's shared copy. The smoke proves the round-trip: a handbook marker authored through the package editor surfaces in the created run's files.

Browser-pass find: the pkgedit header state span and the editor's save-state span shared the id pkgedit-state, so the widget's select() wiped the header line -- the editor's span renamed (pkgedit-edit-state), verified rendering.

Verified: typecheck green both programs; smoke ALL PASS (+20 -- the fork battery: the template fork owner-stamped scaffold-preserved pc-stripped, create refusing the scaffold on both ends, the playable fork carrying no scaffold, fork validation, the editor gates owner-200/non-owner-403/system-repo-side-403/unknown-404, the raw-JSON and carryover save lints, the ready-to-run flip, create from the flipped fork, the handbook round-trip; and the ownerless pair: the editor refuses, the fork succeeds); restart + reminder checks green (6 runs); a browser pass on --mock --debug end to end -- the paste token re-landing after the state wipe, /new redirecting with the URL honest, the template card disabled with the scaffold note, boutique disabled as incomplete, the fork form prefill and submit landing in the editor, the scaffold state line, the settings flip and save making the card startable, the start-form flow intact, zero console errors; check-repo clean; the debug server back on the real state. Docs: README's packages passage (fork, scaffold, the editor, the gates), the booting flow, the layout tree (the clerk's fork-package verb, the view list, widgets.mjs); DICTIONARY's package, scaffold, and fork entries. The developer's queue line ('"create new package" in SPA') is struck by them in the same round. packages/detention stays untracked WIP, untouched.
This commit is contained in:
2026-11-19 11:11:23 +00:00
parent 4b8fbd7471
commit 0ddb9a218d
19 changed files with 782 additions and 245 deletions
+67 -1
View File
@@ -637,6 +637,68 @@ r = await call('/runs', { method: 'POST', token: op, body: { package: pkgId, pc:
ok('create from user package', r.status === 200 && !!r.data.run?.id, r.data.error ?? r.data.run?.id);
const secondId = r.data.run?.id;
// 14b. the package fork battery (developer, 2026-11-19): fork is the
// copy-to-author act -- any package, the scaffold flag preserved
// (the flag is the package's doneness state: a scaffold fork stays a
// scaffold until the editor flips it off), the editor is the owner's
// alone, and create refuses a scaffold on both ends
r = await call('/packages/fork', { method: 'POST', token: op, body: { from: 'template', name: 'My Scaffold' } });
ok('fork the template', r.status === 200 && r.data.package?.forked === 'template' && !!r.data.package?.id, JSON.stringify(r.data.package ?? r.data.error));
const tplFork = r.data.package?.id;
r = await call('/packages', { token: op });
const tplForkEntry = r.data.find((p) => p.name === tplFork);
ok('the fork is a user package, owner-stamped, scaffold preserved, pc stripped',
!!tplForkEntry && tplForkEntry.origin === 'user' && tplForkEntry.ownerName === 'Op' && tplForkEntry.scaffold === true
&& tplForkEntry.display === 'My Scaffold' && tplForkEntry.pc === null,
JSON.stringify(tplForkEntry ?? null));
r = await call('/runs', { method: 'POST', token: op, body: { package: 'template', pc: 'Nobody', name: 'x' } });
ok('create from a scaffold refuses', r.status === 400 && /scaffold/.test(r.data.error), r.data.error ?? '');
r = await call('/runs', { method: 'POST', token: op, body: { package: tplFork, pc: 'Nobody', name: 'x' } });
ok('create from the scaffold fork refuses too (the flag rides)', r.status === 400 && /scaffold/.test(r.data.error), r.data.error ?? '');
r = await call('/packages/fork', { method: 'POST', token: op, body: { from: 'la-caramba', name: 'Caramba Variant' } });
ok('fork a playable package', r.status === 200 && r.data.package?.forked === 'la-caramba', JSON.stringify(r.data.package ?? r.data.error));
const carambaFork = r.data.package?.id;
r = await call('/packages', { token: op });
ok('a fork of a playable package carries no scaffold', r.data.find((p) => p.name === carambaFork)?.scaffold === false,
JSON.stringify(r.data.find((p) => p.name === carambaFork) ?? null));
r = await call('/packages/fork', { method: 'POST', token: op, body: { from: 'template' } });
ok('fork needs a display name', r.status === 400, r.data.error ?? '');
r = await call('/packages/fork', { method: 'POST', token: op, body: { from: 'nope', name: 'x' } });
ok('fork of an unknown package refuses', r.status === 400 && /no such package/.test(r.data.error), r.data.error ?? '');
// 14c. the package editor: the owner's authoring surface, every file
// rw (settings included -- raw JSON for now), the cheap save lints,
// and the ready-to-run flip
r = await call(`/packages/${tplFork}/files`, { token: op });
ok('the owner reads the editor surface',
r.status === 200 && r.data.files['settings.json']?.exists === true && r.data.scaffold === true && r.data.display === 'My Scaffold',
JSON.stringify(r.data.files ? { display: r.data.display, scaffold: r.data.scaffold } : r.data));
r = await call(`/packages/${tplFork}/files`, { token: ash });
ok("the editor is the owner's", r.status === 403, r.data.error ?? '');
r = await call('/packages/la-caramba/files', { token: op });
ok('system packages refuse the editor (repo-side)', r.status === 403 && /repo-side/.test(r.data.error), r.data.error ?? '');
r = await call('/packages/nope/files', { token: op });
ok('an unknown package 404s', r.status === 404, r.data.error ?? '');
r = await call(`/packages/${tplFork}/files/settings.json`, { method: 'PUT', token: op, body: { content: '{ not json' } });
ok('settings must parse (the raw JSON editor)', r.status === 400 && /JSON object/.test(r.data.error), r.data.error ?? '');
r = await call(`/packages/${tplFork}/files/carryover.jsonl`, { method: 'PUT', token: op, body: { content: 'nope' } });
ok('the carryover save lint holds on the package editor', r.status === 400, r.data.error ?? '');
r = await call(`/packages/${tplFork}/files/backdrop.md`, { method: 'PUT', token: op, body: { content: '# My forked backdrop\n\nA new island.\n' } });
ok('the owner writes a file', r.status === 200, r.data.error ?? '');
r = await call(`/packages/${tplFork}/files/handbook.md`, { method: 'PUT', token: op, body: { content: "# The fork's own handbook\n\nCraft marker: unique-to-the-fork.\n" } });
ok('the handbook is authorable on the package', r.status === 200, r.data.error ?? '');
r = await call(`/packages/${tplFork}/files/settings.json`, { method: 'PUT', token: op, body: { content: JSON.stringify({ records: false, scaffold: false, name: 'My Scaffold' }, null, 2) + '\n' } });
ok('the ready-to-run flip (scaffold off)', r.status === 200, r.data.error ?? '');
r = await call('/packages', { token: op });
ok('the listing reflects the flip', r.data.find((p) => p.name === tplFork)?.scaffold === false, '');
r = await call('/runs', { method: 'POST', token: op, body: { package: tplFork, pc: 'Forkina', name: 'Fork Story' } });
ok('create from the flipped fork', r.status === 200 && !!r.data.run?.id, r.data.error ?? r.data.run?.id);
const forkRunId = r.data.run?.id;
r = await call(`/runs/${forkRunId}/files`, { token: op });
ok("the handbook round-trips (the package's own beats the repo default)",
r.data.files['handbook.md']?.content?.includes('unique-to-the-fork') === true,
JSON.stringify((r.data.files['handbook.md']?.content ?? '').slice(0, 60)));
// 15. op revokes ash -- identity destroyed, data stays
r = await call(`/users/${ashId}/revoke`, { method: 'POST', token: op, body: {} });
ok('revoke ash', r.status === 200, r.data.error ?? '');
@@ -652,6 +714,10 @@ r = await call('/packages', { token: op });
const saved2 = r.data.find((p) => p.name === pkgId);
ok('user package survives, ownerless', !!saved2 && saved2.owner === null && saved2.ownerName === null && saved2.display === 'Ash Pack',
JSON.stringify(saved2));
r = await call(`/packages/${pkgId}/files`, { token: op });
ok('an ownerless package refuses the editor (readable, forkable, never editable)', r.status === 403 && /not yours/.test(r.data.error), r.data.error ?? '');
r = await call('/packages/fork', { method: 'POST', token: op, body: { from: pkgId, name: 'Ash Pack Continued' } });
ok('an ownerless package is forkable (the copy is yours)', r.status === 200 && r.data.package?.forked === pkgId, JSON.stringify(r.data.package ?? r.data.error));
r = await call(`/runs/${forkId}/fork`, { method: 'POST', token: op, body: {} });
ok('op forks the ownerless run', r.status === 200 && !!r.data.run, r.data.error ?? r.data.run);
const reforkId = r.data.run;
@@ -1087,7 +1153,7 @@ ok('the sheet crossed the boundary (the note feeds the new session\'s scan)', JS
}
ok('the restored world refined', jobR?.state === 'applied', JSON.stringify(jobR ?? null));
}
console.log(`\nrun ids: source=${runId} draft=${draftId} fork=${forkId} second=${secondId} refork=${reforkId}`);
console.log(`\nrun ids: source=${runId} draft=${draftId} fork=${forkId} second=${secondId} refork=${reforkId} fork-story=${forkRunId}`);
writeFileSync(TOKEN_FILE, `${op} ${reforkId} ${secondId}`);
console.log(failures ? `\n${failures} FAILURES` : '\nALL PASS');
process.exit(failures ? 1 : 0);