the packager, reshaped on calibration evidence: the character to lift, no chunks, markdown extraction, one call per job -- plus the roles inventory, staged earlier and verified in its own sitting
The who: a source usually holds several characters, so the request names the character to lift, in the caller's own words (required in character mode, optional in full mode where the seat rules stand unnamed). A named character who is not a woman, or one who never appears in the material, refuses loud: the model answers REFUSED with one line naming who and why, nothing lands (the route cannot gender a name or know who appears; the model can). The mode-split rule lands in the prompt the same round: her voice may run in thought, speech, and writing, the modes may sound different, they are never blended into one averaged voice, and when her thoughts never reach the page nothing is invented -- how her thinking shows, as observable behavior, is the record. The lift-her-not-the-narrator rules ride with it: her voice is only what she herself says or writes, and names are not identity. The calibration program (the developer's design, run on a real book): planted-invariant passages for the voice extraction first, then a full multi-character calibration -- a named side character lifted from a narrator-voiced source, the alias tracking deliberately in-test with no hints on the request. The verdicts, each total. The chunked pipeline silently distilled the wrong woman with every gate green: the chunks where she never appears each filled the her-slot with the narrator, and the blind merge had no way to know, so no chunks, ever -- the full source in one read, and a source that does not fit the spec's contwin refuses before the job starts with the arithmetic and both fixes (compact it, or pick a wider contwin; compaction is the caller's editorial act). Five malformed distillates across the runs were all one disease -- the dropped closing brace of the her-object, one character repairs it every time -- so the distillate is markdown now: formal syntax lives exactly where machinery consumes it (the draft's file sections, the carryover, the memory manifest) and nowhere else. And the pass-count A/B (character mode and full mode, same book, same who, same cut) ruled one call per job: extraction sections then the files in a single output, split at the first file marker, the extraction retained as the audit artifact -- composing with the source in view is what kept the narrator's devices out of her portrait, a property of the shape, not a prompt line. Machinery: the fit check (source chars/4 plus a named 32K-token overhead against the registry's input ceiling; a 413 over it naming the arithmetic, a 400 when the ceiling is unknown, never a guess), the REFUSED prefix checked on every output, distill.md and draft.txt retained per job, the receipt naming the extraction and draft sizes, the mock serving the canned pair concatenated, steps total two. The chunker, the whole knob, the assemble pass, and the JSON refusal shape are all deleted (no-legacy). Huge-source distillation goes to ROADMAP's distant shelf with the folded-sweep design recorded so a future round starts from it; the flake doctrine stands as practiced -- hand-repair, the evidence in the calibration material. The roles inventory rides along as staged: every human and inferencer seat named (the developer, the assistant, the op, a run's GM, the package author, the reader; the player, the housekeeper, the curator, the clerk, the packager), the vocabulary swept, the retired class words lint-banned, "model" kept as the machinery's noun. Verified: typecheck green on both programs, smoke ALL PASS through every reshape (who required, the refusal case, the oversized-source arithmetic, the one-call receipt with its split), check-repo clean, the debug server on the new code over the real state. The developer's red pen on packager.md is the next act: it is the assistant's draft, the exact text every calibration output was produced from, and one edit lands on the survivor.
This commit is contained in:
+65
-4
@@ -37,6 +37,7 @@ import { gmTurn, answerAsk, openingCall, HttpError, specFromMeta, gateSpec } fro
|
||||
import * as users from './users.mjs';
|
||||
import { forkRun } from './fork.mjs';
|
||||
import * as discovery from './discovery.mjs';
|
||||
import * as packager from './packager.mjs';
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const MOCK = process.argv.includes('--mock');
|
||||
@@ -149,14 +150,14 @@ const send = (res, status, body) => {
|
||||
res.end(data);
|
||||
};
|
||||
|
||||
/** @param {import('node:http').IncomingMessage} req @returns {Promise<any>} */
|
||||
const readBody = (req) => new Promise((resolve, reject) => {
|
||||
/** @param {import('node:http').IncomingMessage} req @param {number} [limit] @returns {Promise<any>} */
|
||||
const readBody = (req, limit = 1024 * 1024) => new Promise((resolve, reject) => {
|
||||
/** @type {Buffer[]} */
|
||||
const chunks = [];
|
||||
let size = 0;
|
||||
req.on('data', (c) => {
|
||||
size += c.length;
|
||||
if (size > 1024 * 1024) { reject(new HttpError(413, 'body too large')); req.destroy(); return; }
|
||||
if (size > limit) { reject(new HttpError(413, 'body too large')); req.destroy(); return; }
|
||||
chunks.push(c);
|
||||
});
|
||||
req.on('end', () => {
|
||||
@@ -681,6 +682,63 @@ route('POST', '/api/packages/fork', async ({ body, user }) => {
|
||||
return { package: JSON.parse(r.out) };
|
||||
});
|
||||
|
||||
// --- the packager ----------------------------------------------------------------
|
||||
//
|
||||
// Literature into scaffold packages (developer, 2026-11-19). Any
|
||||
// signed-in user -- packages are user-authored already; one job at a
|
||||
// time (the singleton slot -- this is tens of minutes of deployment
|
||||
// inference). The request carries the mode, the settings (name, pc,
|
||||
// records -- user input, never a model output), the source as one
|
||||
// text/plain in a JSON string field, the cut in the caller's own
|
||||
// words (full mode), and an optional full spec defaulting to the
|
||||
// provider default. The landing is a scaffold: review in the
|
||||
// package editor, flip ready.
|
||||
|
||||
/** @param {unknown} raw @returns {{ slug: string, model: string, effort: string }} */
|
||||
function resolvePackSpec(raw) {
|
||||
if (raw === undefined || raw === null) {
|
||||
const d = ctx.providerCfg.providers.find((p) => p.default);
|
||||
if (!d || !d.default) throw new HttpError(409, 'no provider default is set -- the op selects one, or send a spec');
|
||||
return { slug: d.slug, model: d.default.model, effort: d.default.effort };
|
||||
}
|
||||
if (typeof raw !== 'object' || Array.isArray(raw)) throw new HttpError(400, 'spec must be { provider, model, effort }');
|
||||
const o = /** @type {{ provider?: unknown, model?: unknown, effort?: unknown }} */ (raw);
|
||||
if (typeof o.provider !== 'string' || typeof o.model !== 'string' || typeof o.effort !== 'string') {
|
||||
throw new HttpError(400, 'spec must be { provider, model, effort } -- see GET /api/models');
|
||||
}
|
||||
if (!discovery.EFFORT_LEVELS.includes(o.effort)) {
|
||||
throw new HttpError(400, `spec.effort must be one of ${discovery.EFFORT_LEVELS.join(', ')}`);
|
||||
}
|
||||
if (!discovery.usable(o.provider, o.model)) {
|
||||
throw new HttpError(400, `spec model '${o.model}' is not usable on '${o.provider}' (not discovered, or failed the battery)`);
|
||||
}
|
||||
return { slug: o.provider, model: o.model, effort: o.effort };
|
||||
}
|
||||
|
||||
route('POST', '/api/packager', async ({ body, user }) => {
|
||||
requireUser(user);
|
||||
const mode = body.mode;
|
||||
if (mode !== 'character' && mode !== 'full') throw new HttpError(400, "mode must be 'character' or 'full'");
|
||||
const name = String(body.name ?? '').trim();
|
||||
const pc = String(body.pc ?? '').trim();
|
||||
if (!name) throw new HttpError(400, 'name (the new package\'s display name) is required');
|
||||
if (!pc) throw new HttpError(400, 'pc (her default name) is required');
|
||||
// the character to lift, in the caller's own words -- required in
|
||||
// character mode (no named woman, no voice to distill); optional
|
||||
// in full mode, where the seat rules stand when she is unnamed
|
||||
const who = String(body.who ?? '').trim();
|
||||
if (mode === 'character' && !who) throw new HttpError(400, 'who (the character to lift, in your own words) is required for a character packaging');
|
||||
const records = body.records === true;
|
||||
if (typeof body.source !== 'string' || !body.source.trim()) throw new HttpError(400, 'source (one text/plain file) is required');
|
||||
if (body.source.length > packager.SOURCE_MAX) throw new HttpError(413, `the source is too large (over ${Math.round(packager.SOURCE_MAX / 1024 / 1024)}MB)`);
|
||||
const cut = String(body.cut ?? '').trim();
|
||||
if (mode === 'full' && !cut) throw new HttpError(400, 'cut (where her import stops, in your own words) is required for a full packaging');
|
||||
const spec = resolvePackSpec(body.spec);
|
||||
return packager.start(ctx, { mode, name, pc, who, records, source: body.source, cut }, spec, user);
|
||||
});
|
||||
|
||||
route('GET', '/api/packager', async () => packager.state());
|
||||
|
||||
// --- the package editor ---------------------------------------------------------
|
||||
//
|
||||
// The owner's authoring surface over a user package: the same fixed
|
||||
@@ -1562,7 +1620,10 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
const m = match(String(req.method), url.pathname);
|
||||
if (!m) throw new HttpError(404, `no such route: ${req.method} ${url.pathname}`);
|
||||
const body = (req.method === 'POST' || req.method === 'PUT') ? await readBody(req) : {};
|
||||
// the packager's body carries a whole book as one JSON string --
|
||||
// every other route keeps the 1MB cap
|
||||
const bodyLimit = url.pathname === '/api/packager' ? 6 * 1024 * 1024 : 1024 * 1024;
|
||||
const body = (req.method === 'POST' || req.method === 'PUT') ? await readBody(req, bodyLimit) : {};
|
||||
user = authenticate(req);
|
||||
if (!m.publicRoute && !user) throw new HttpError(401, 'not signed in -- claim an invite first (POST /api/claim)');
|
||||
send(res, 200, await m.handler({ params: m.params, body, req, user }));
|
||||
|
||||
Reference in New Issue
Block a user