multiuser: token identity, invites + bootstrap, owner-gated runs, fork, user packages; spectator spa; utc house rule

This commit is contained in:
2026-11-14 20:01:15 +00:00
parent 9f85adc3c6
commit 711634cc38
15 changed files with 1134 additions and 105 deletions
+9 -5
View File
@@ -96,7 +96,7 @@ export function parseManifest(text) {
// --- the job -----------------------------------------------------------------
export function trigger(ctx, runId) {
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`);
@@ -104,16 +104,18 @@ export function trigger(ctx, runId) {
ctx.sessions.delete(runId); // the window is closed from here on
const job = { state: 'running', session: s.stamp, started: new Date().toISOString() };
ctx.jobs.set(runId, job);
runJob(ctx, runId, s.stamp, s.lines); // async; catches its own errors
// the whole async chain holds the run's activity lock — a fork
// enqueued behind it copies the post-wrap state, never a half-apply
ctx.enqueue(runId, () => runJob(ctx, runId, s.stamp, s.lines, user));
return job;
}
async function runJob(ctx, runId, stamp, lines) {
async function runJob(ctx, runId, stamp, lines, user) {
const job = ctx.jobs.get(runId);
try {
const text = ctx.mock
? mockManifest(stamp)
: await callHousekeeper(ctx, runId, buildMessages(runId, lines, stamp));
: await callHousekeeper(ctx, runId, buildMessages(runId, lines, stamp), user);
const dir = path.join(runDir(runId), 'manifests');
fs.mkdirSync(dir, { recursive: true });
let mf;
@@ -136,9 +138,11 @@ async function runJob(ctx, runId, stamp, lines) {
}
}
async function callHousekeeper(ctx, runId, messages) {
async function callHousekeeper(ctx, runId, messages, user) {
const model = ctx.cfg.models?.housekeeper ?? ctx.cfg.models?.player ?? null;
if (!model) throw new Error('no housekeeper model configured (server.json models.housekeeper)');
// attribution (#22): every LLM call names the acting user
console.log(`${new Date().toISOString().slice(11, 19)} llm ${model} u:${user?.id ?? '?'}`);
const data = await ctx.provider.chat(model, messages, undefined, ctx.cfg.params ?? {});
return data.choices[0].message.content ?? '';
}