spa modules and terminology: app.mjs split into flat es modules (router lifecycle, shared widgets, views own their state), mock smoke in test/; DICTIONARY.md rules the terms, four renames swept clean through the machinery - paper->status (run summary command is report now), window->session, wrap->housekeeping, context window->contwin; no dual-accepts by ruling, old data migrates once in the clerk (restore self-heals old dumps)
This commit is contained in:
+19
-19
@@ -1,11 +1,11 @@
|
||||
// server/housekeeping.mjs — the window-close ritual, as an async job.
|
||||
// server/housekeeping.mjs — the session-close ritual, as an async job.
|
||||
//
|
||||
// The chain, unattended: render the transcript -> invoke the
|
||||
// housekeeper on a fresh context (its prompt, run state, the card, the
|
||||
// backdrop, both ring views, the transcript with labeled thinking) ->
|
||||
// save the manifest -> apply via the clerk (which validates, writes
|
||||
// the window log, snapshots the dump) -> mark the session housekept ->
|
||||
// autorestart: a fresh window opens with fresh views. A rejection at
|
||||
// the session log, snapshots the dump) -> mark the session housekept ->
|
||||
// autorestart: a fresh session opens with fresh views. A rejection at
|
||||
// any step holds the restart and surfaces why; the manifest (or the
|
||||
// raw output, if unparseable) stays on disk for a hand edit and
|
||||
// POST .../housekeeping/apply.
|
||||
@@ -14,7 +14,7 @@ import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { clerk } from './clerk.mjs';
|
||||
import { runDir, requireRun, readSettings, expandVars } from './bundle.mjs';
|
||||
import { openWindow, markHousekept, latestSession, lastHousekept } from './session.mjs';
|
||||
import { openSession, markHousekept, latestSession, lastHousekept } from './session.mjs';
|
||||
import { HttpError } from './loop.mjs';
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
@@ -51,14 +51,14 @@ export function renderTranscript(lines) {
|
||||
continue;
|
||||
}
|
||||
if (e.t === 'note') {
|
||||
if (e.kind === 'paper') {
|
||||
L.push(`[paper] lost: ${JSON.stringify(e.applied?.lost ?? [])}, gained: ${JSON.stringify(e.applied?.gained ?? [])}${e.conflicts?.length ? ` — conflicts: ${e.conflicts.join('; ')}` : ''}`, '');
|
||||
if (e.kind === 'status') {
|
||||
L.push(`[status] lost: ${JSON.stringify(e.applied?.lost ?? [])}, gained: ${JSON.stringify(e.applied?.gained ?? [])}${e.conflicts?.length ? ` — conflicts: ${e.conflicts.join('; ')}` : ''}`, '');
|
||||
} else if (e.kind === 'agenda') {
|
||||
L.push(`[agenda] added: ${JSON.stringify(e.applied?.added ?? [])}, dropped: ${JSON.stringify(e.applied?.dropped ?? [])}, evicted: ${JSON.stringify(e.applied?.evicted ?? [])}${e.conflicts?.length ? ` — conflicts: ${e.conflicts.join('; ')}` : ''}`, '');
|
||||
} else if (e.kind === 'ask') {
|
||||
L.push(`[ask_gm pending] ${e.question}`, '');
|
||||
} else if (e.kind === 'window') {
|
||||
L.push(`[window opened ${e.at}${e.fresh ? ' — fresh' : ''}]`, '');
|
||||
} else if (e.kind === 'session') {
|
||||
L.push(`[session opened ${e.at}${e.fresh ? ' — fresh' : ''}]`, '');
|
||||
} else if (e.kind === 'seed' || e.kind === 'ingest') {
|
||||
L.push(`[${e.kind}] ${e.ok ? 'ok' : 'failed'}: ${e.detail}`, '');
|
||||
}
|
||||
@@ -106,13 +106,13 @@ export function parseManifest(text) {
|
||||
export function trigger(ctx, runId, user) {
|
||||
requireRun(runId);
|
||||
const s = ctx.sessions.get(runId);
|
||||
if (!s) throw new HttpError(409, `no open window for '${runId}' — housekeeping is the window-close ritual`);
|
||||
if (s.pendingAsk) throw new HttpError(409, 'a question is pending — answer it before closing the window');
|
||||
ctx.sessions.delete(runId); // the window is closed from here on
|
||||
if (!s) throw new HttpError(409, `no open session for '${runId}' — housekeeping is the session-close ritual`);
|
||||
if (s.pendingAsk) throw new HttpError(409, 'a question is pending — answer it before closing the session');
|
||||
ctx.sessions.delete(runId); // the session is closed from here on
|
||||
const job = { state: 'running', session: s.stamp, started: new Date().toISOString() };
|
||||
ctx.jobs.set(runId, job);
|
||||
// the whole async chain holds the run's activity lock — a fork
|
||||
// enqueued behind it copies the post-wrap state, never a half-apply
|
||||
// enqueued behind it copies the post-apply state, never a half-apply
|
||||
ctx.enqueue(runId, () => runJob(ctx, runId, s.stamp, s.lines, user));
|
||||
return job;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ async function runJob(ctx, runId, stamp, lines, user) {
|
||||
fs.writeFileSync(manifestPath, JSON.stringify(mf, null, 2) + '\n');
|
||||
job.manifest = `manifests/${stamp}.json`;
|
||||
const next = applyAndRestart(ctx, runId, manifestPath, stamp);
|
||||
job.window = mf.window;
|
||||
job.session = mf.session;
|
||||
job.next = next.stamp;
|
||||
job.state = 'applied';
|
||||
} catch (e) {
|
||||
@@ -165,7 +165,7 @@ export function applyAndRestart(ctx, runId, manifestPath, sessionStamp) {
|
||||
const r = clerk(runId, 'apply', manifestPath);
|
||||
if (r.code !== 0) throw new Error(`apply rejected:\n${r.err || r.out}`);
|
||||
markHousekept(runId, sessionStamp);
|
||||
const s = openWindow(runId); // the #21 guard passes now
|
||||
const s = openSession(runId); // the #21 guard passes now
|
||||
ctx.sessions.set(runId, s);
|
||||
return s;
|
||||
}
|
||||
@@ -184,11 +184,11 @@ export function jobState(ctx, runId) {
|
||||
|
||||
export function latestLog(runId) {
|
||||
const dir = path.join(runDir(runId), 'log');
|
||||
if (!fs.existsSync(dir)) throw new HttpError(404, 'no window logs yet');
|
||||
if (!fs.existsSync(dir)) throw new HttpError(404, 'no session logs yet');
|
||||
const files = fs.readdirSync(dir).filter((f) => f.endsWith('.md')).sort();
|
||||
if (!files.length) throw new HttpError(404, 'no window logs yet');
|
||||
if (!files.length) throw new HttpError(404, 'no session logs yet');
|
||||
const f = files[files.length - 1];
|
||||
return { window: f.replace(/\.md$/, '', ''), content: fs.readFileSync(path.join(dir, f), 'utf8') };
|
||||
return { session: f.replace(/\.md$/, '', ''), content: fs.readFileSync(path.join(dir, f), 'utf8') };
|
||||
}
|
||||
|
||||
// --- the mock housekeeper ----------------------------------------------------
|
||||
@@ -198,8 +198,8 @@ export function latestLog(runId) {
|
||||
// ring-B memory. Exercises the whole chain without a key.
|
||||
function mockManifest(stamp) {
|
||||
return JSON.stringify({
|
||||
window: stamp.toLowerCase(),
|
||||
summary: 'Mock wrap: she left the container, crossed the hot sand and entered the dark hold.',
|
||||
session: stamp.toLowerCase(),
|
||||
summary: 'Mock housekeeping: she left the container, crossed the hot sand and entered the dark hold.',
|
||||
touch: [{ id: 'e1', reason: 'the cuffs shaped every move she made' }],
|
||||
insert: [{
|
||||
ring: 'b', type: 'place', label: 'The dark hold',
|
||||
|
||||
Reference in New Issue
Block a user