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:
+68
-5
@@ -21,6 +21,10 @@
|
||||
// save-package "display name" save a DRAFT's craft as a new user
|
||||
// package (state/packages/, published to
|
||||
// all; pc never rides; --owner stamps)
|
||||
// fork-package <pkg> "display" copy any package into state/packages
|
||||
// as a user package (owner stamped, pc
|
||||
// never rides, scaffold flag preserved
|
||||
// -- the copy-to-author act)
|
||||
// init build session one of a fresh run
|
||||
// (the low-level primitive under create)
|
||||
// render write canon/ring-a.md, ring-b.md
|
||||
@@ -74,7 +78,7 @@
|
||||
/** @typedef {{ phase?: string, ready?: boolean, [k: string]: unknown }} SessionMeta */
|
||||
|
||||
/** One package as `packages` lists it. */
|
||||
/** @typedef {{ name: string, origin: 'system'|'user', owner?: ?string, display: string, pc: ?string, records: boolean, carryover: boolean, memory: boolean, complete: boolean }} PackageListed */
|
||||
/** @typedef {{ name: string, origin: 'system'|'user', owner?: ?string, display: string, pc: ?string, records: boolean, scaffold: boolean, carryover: boolean, memory: boolean, complete: boolean }} PackageListed */
|
||||
|
||||
/** One run as `runs` lists it (fill is present exactly when initialized). */
|
||||
/** @typedef {{ id: string, package: string, models: ?{ player?: ?{ provider: string, model: string, effort: string }, housekeeper?: ?{ provider: string, model: string, effort: string } }, owner: ?string, created: ?string, forked: ?number, pc: ?string, display: string, sessions: number, phase: ?string, ready: ?boolean, initialized: boolean, fill?: { a: number, b: number, cold: number } }} RunListed */
|
||||
@@ -159,7 +163,7 @@ const [cmd, ...args] = argv;
|
||||
|
||||
// a run is an instance under runs/, created from a package by `create`;
|
||||
// state is per-deployment -- a fresh clone has zero runs
|
||||
const NO_RUN_NEEDED = new Set(['runs', 'packages', 'create', 'pick']);
|
||||
const NO_RUN_NEEDED = new Set(['runs', 'packages', 'create', 'pick', 'fork-package']);
|
||||
const RUN = NO_RUN_NEEDED.has(cmd ?? '') ? null : runOverride;
|
||||
if (!NO_RUN_NEEDED.has(cmd ?? '') && (!RUN || !/^[a-z0-9-]+$/.test(RUN))) {
|
||||
fail('no run specified -- use --run <id> (see: runs); runs are created with: create <package> <pc-name>');
|
||||
@@ -837,6 +841,11 @@ function packageEntry(name, dir, origin) {
|
||||
display: settings.name ?? name,
|
||||
pc: settings.pc ?? null,
|
||||
records: settings.records === true,
|
||||
// the ready-to-run flag (developer, 2026-11-19): a scaffold is
|
||||
// authoring material, not a story -- create refuses it, fork
|
||||
// copies it, the editor's settings flip it off when the package
|
||||
// is ready
|
||||
scaffold: settings.scaffold === true,
|
||||
carryover: has('carryover.jsonl'), memory: has('memory.json'),
|
||||
complete: has('backdrop.md') && has('character.md'),
|
||||
};
|
||||
@@ -858,7 +867,7 @@ function cmdPackages() {
|
||||
if (AS_JSON) { console.log(JSON.stringify(list)); return; }
|
||||
if (!list.length) { console.log('(no packages)'); return; }
|
||||
for (const x of list) {
|
||||
console.log(`${x.name}: ${x.display} [${x.origin}] -- records ${x.records ? 'on' : 'off'} \u00b7 carryover ${x.carryover ? 'yes' : 'no'} \u00b7 memory ${x.memory ? 'yes' : 'no'} \u00b7 backdrop+card ${x.complete ? 'ok' : 'MISSING'}`);
|
||||
console.log(`${x.name}: ${x.display} [${x.origin}] -- records ${x.records ? 'on' : 'off'}${x.scaffold ? ' \u00b7 SCAFFOLD (fork to author)' : ''} \u00b7 carryover ${x.carryover ? 'yes' : 'no'} \u00b7 memory ${x.memory ? 'yes' : 'no'} \u00b7 backdrop+card ${x.complete ? 'ok' : 'MISSING'}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -889,6 +898,12 @@ function cmdCreate(pkgName, pc, displayName) {
|
||||
}
|
||||
const pkgDir = packageDir(pkgName);
|
||||
if (!pkgDir) fail(`no such package: ${pkgName} -- see: packages`);
|
||||
// a scaffold is authoring material, never a story (developer,
|
||||
// 2026-11-19): the fork copies it, the editor's settings flip it
|
||||
// off when the package is ready to run
|
||||
if (readRunSettings(pkgDir).scaffold === true) {
|
||||
fail(`'${pkgName}' is a scaffold -- fork it to author, then flip "scaffold" off in the editor`);
|
||||
}
|
||||
pc = String(pc).trim();
|
||||
// different runs of the same package require different pc names
|
||||
if (fs.existsSync(RUNS_DIR)) {
|
||||
@@ -919,7 +934,13 @@ function cmdCreate(pkgName, pc, displayName) {
|
||||
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
||||
fs.copyFileSync(src, dst);
|
||||
}
|
||||
const hb = path.join(ROOT, 'handbook.md');
|
||||
// the handbook: the package's own when it carries one (the
|
||||
// save-package round-trip -- an authored or edited handbook is
|
||||
// craft, and losing it on re-create was a bug), else the repo's
|
||||
// shared copy
|
||||
const hb = fs.existsSync(path.join(pkgDir, 'handbook.md'))
|
||||
? path.join(pkgDir, 'handbook.md')
|
||||
: path.join(ROOT, 'handbook.md');
|
||||
if (fs.existsSync(hb)) {
|
||||
fs.mkdirSync(path.join(s1, 'bundle'), { recursive: true });
|
||||
fs.copyFileSync(hb, path.join(s1, 'bundle', 'handbook.md'));
|
||||
@@ -1051,6 +1072,47 @@ function cmdSavePackage(displayName) {
|
||||
console.log(`saved package '${id}' -- ${name}: ${rel(dst)}`);
|
||||
}
|
||||
|
||||
// fork a package: the copy-to-author act (developer, 2026-11-19).
|
||||
// Everything rides -- gm.md included, the save-package publishing
|
||||
// precedent -- into state/packages as a user package owned by the
|
||||
// forker. The display name is the fork's one decision; the pc never
|
||||
// rides (the next create asks for one); the scaffold flag rides
|
||||
// untouched (a scaffold fork stays a scaffold until the author flips
|
||||
// it off -- the flag is the package's doneness state, and publishing
|
||||
// your own scaffold for others to fork is free).
|
||||
/** @param {?string} fromName @param {?string} displayName */
|
||||
function cmdForkPackage(fromName, displayName) {
|
||||
const name = String(displayName ?? '').trim();
|
||||
if (!fromName || !name) fail('usage: fork-package <package> "display name"');
|
||||
const src = packageDir(fromName);
|
||||
if (!src) fail(`no such package: ${fromName} -- see: packages`);
|
||||
/** @type {string} */ let id;
|
||||
for (;;) {
|
||||
id = randomBytes(4).toString('hex');
|
||||
if (!fs.existsSync(path.join(STATE_PACKAGES_DIR, id)) && !fs.existsSync(path.join(PACKAGES_DIR, id))) break;
|
||||
}
|
||||
const dst = path.join(STATE_PACKAGES_DIR, id);
|
||||
fs.mkdirSync(dst, { recursive: true });
|
||||
for (const f of fs.readdirSync(src)) {
|
||||
const p = path.join(src, f);
|
||||
if (fs.statSync(p).isFile()) fs.copyFileSync(p, path.join(dst, f));
|
||||
}
|
||||
const settingsPath = path.join(dst, 'settings.json');
|
||||
/** @type {RunSettings} */ let settings = {};
|
||||
try { settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); } catch {}
|
||||
settings.name = name;
|
||||
delete settings.pc; // per-run identity never rides a package
|
||||
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
|
||||
fs.writeFileSync(path.join(dst, 'package.json'), JSON.stringify({
|
||||
owner: ownerOverride, created: today(), forked: fromName,
|
||||
}, null, 2) + '\n');
|
||||
if (AS_JSON) {
|
||||
console.log(JSON.stringify({ id, name, origin: 'user', owner: ownerOverride, forked: fromName }));
|
||||
return;
|
||||
}
|
||||
console.log(`forked package '${id}' -- ${name} (from ${fromName}): ${rel(dst)}`);
|
||||
}
|
||||
|
||||
/** @param {string} ring @param {string} type @param {string} label @param {?string} [detail] */
|
||||
function gmOp(ring, type, label, detail) {
|
||||
const db = openDb();
|
||||
@@ -1271,6 +1333,7 @@ switch (cmd) {
|
||||
case 'runs': cmdRuns(); break;
|
||||
case 'create': cmdCreate(args[0], args[1], args[2]); break;
|
||||
case 'save-package': cmdSavePackage(args[0]); break;
|
||||
case 'fork-package': cmdForkPackage(args[0], args[1]); break;
|
||||
case 'init': cmdInit(); break;
|
||||
case 'render': renderAll(openDb()); break;
|
||||
case 'apply': args[0] ? cmdApply(args[0]) : fail('usage: apply <manifest.json>'); break;
|
||||
@@ -1288,6 +1351,6 @@ switch (cmd) {
|
||||
case 'dump': cmdDump(); break;
|
||||
case 'restore': cmdRestore(FORCE); break;
|
||||
default:
|
||||
console.error('usage: node tool/memory.mjs <packages|runs|create|save-package|init|render|apply|reapply|insert|delete|revive|file|amend|discard|search|unarchive|pick|dump|restore|report>');
|
||||
console.error('usage: node tool/memory.mjs <packages|runs|create|save-package|fork-package|init|render|apply|reapply|insert|delete|revive|file|amend|discard|search|unarchive|pick|dump|restore|report>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user