Files
stack/packages/webui/src/organizations.mjs
T
jason.woltje 0c35eeed9d fix(webui): E2E6 round, live edits survive refresh, org page layout, decision refusals (#1873)
P1-1 an open workflow editor, a dirty autonomy form and a pack's picked project keep their
node, draft and focus across the 10-second poll and an org-changed repaint.
P1-2 decision-http names the refused field and keeps the bus code and detail.
P1-3 long editors span the full width below the org page split.
P2-1 workflow roles resolve as definitions, templates and human; P2-2 a pack apply re-reads
workflows, autonomy and board and keeps its receipt; P2-3 pack preview fits its column;
P2-4 unknown project, agent or harness say so instead of outcome-unknown; P2-6 a stopped bus
reads "bus stopped"; P2-8 Queue says why it is unavailable; P2-9 pane settings values are not
clipped; P2-10 spend wording; P2-11 project header stays in its column; P2-12 project tabs
fade at the edge until scrolled to the end; P2-13 Restart bus and Stop bus line up in panes;
P2-15 backticks in chat text render as code.
Minor: Same-as commands wrap between words; harness checkboxes share a row.
Tests: org-live-edit-browser, e2e6-layout-browser, chat-replies and decision-http additions.
2026-11-13 19:24:48 -06:00

82 lines
4.6 KiB
JavaScript

import { plainMessage } from './org-admin.mjs';
// The registry and service are injected here so their single, shared implementations remain
// the authority. The browser supplies only an id; roots and sockets come from verified metadata.
// Only the service's own coded messages are shown, never parser text, which can quote file bytes.
function publicReason(ctx, error) {
if (typeof error?.code !== 'string' || typeof error.message !== 'string') return 'organization could not be read';
return plainMessage(ctx, error.message.replace(/^(invalid registry):[\s\S]*$/, '$1'));
}
export function organizationConsole({ ctx, listOrgs, showOrg, resolveOrg, orgPaths, busStatus, options }) {
async function admitted(id, session) {
const principal = { provider: session?.provider, iss: session?.iss, sub: session?.sub };
if (Object.values(principal).some(value => typeof value !== 'string' || !value)) throw new Error('org-unavailable');
const context = { ...ctx, principal };
const shown = await showOrg(context, id);
const org = await resolveOrg(ctx, id);
if (org.state !== 'active') throw new Error('org-unavailable');
return { org, shown, context };
}
async function list(session) {
const entries = await listOrgs(ctx), result = [];
for (const entry of entries) {
if (entry.state !== 'active') continue;
let verified;
try { verified = await admitted(entry.id, session); }
catch (error) {
// Show a broken org only to its verified owner (the service marks failures after the
// owner check). Anything else, including a broken root or owner file, stays hidden.
if (error?.ownerVerified !== true) continue;
result.push({ id: entry.id, label: entry.id, invalid: true, reason: publicReason(ctx, error) });
continue;
}
// E2E6 P2-8: a bus with no host recorded (stopped by its owner, or never started) is "stopped",
// not a failure. A host that is recorded but does not answer stays plain unavailable.
let busHealthy = false, busStopped = false;
try { const s = await busStatus(ctx, entry.id); busHealthy = s?.healthy === true; busStopped = !busHealthy && s?.pid == null; } catch { /* offline metadata remains visible */ }
result.push({ id: entry.id, label: entry.id, theme: verified.shown.doc?.appearance?.theme ?? null, busHealthy, ...(busStopped ? { busStopped: true } : {}) });
}
return result;
}
// U1 (#1873): the orgs a session belongs to, for the cross-organization read (workspace-read.mjs).
// The same admission as `list` and `resolve`: an org the session does not own is skipped, and a
// broken org shows only to its verified owner, as invalid. Bus status and options are lazy, so a
// stopped bus never gets a transport; `timeoutMs` bounds each bus read the options make.
async function members(session, { timeoutMs } = {}) {
const entries = await listOrgs(ctx), result = [];
for (const entry of entries) {
if (entry.state !== 'active') continue;
let verified;
try { verified = await admitted(entry.id, session); }
catch (error) {
if (error?.ownerVerified !== true) continue;
result.push({ id: entry.id, invalid: true, reason: publicReason(ctx, error) });
continue;
}
const { org, shown, context } = verified, id = entry.id;
result.push({
id, doc: shown.doc,
// Host paths in a refusal or boot reason become relative to the instance before they leave.
async status(bound) {
let s;
try { s = await busStatus(ctx, id, bound); }
catch (error) { throw new Error(plainMessage(ctx, typeof error?.message === 'string' ? error.message : 'bus state could not be read')); }
const boot = s?.boot && typeof s.boot === 'object' ? { ok: s.boot.ok, at: s.boot.at, lastGood: s.boot.lastGood ?? null, reason: s.boot.reason == null ? null : plainMessage(ctx, s.boot.reason) } : null;
return { healthy: s?.healthy === true, pid: Number.isSafeInteger(s?.pid) ? s.pid : null, boot };
},
options: bound => options({ id, root: org.root, paths: orgPaths(org.root), session, context, doc: shown.doc, ...(timeoutMs === undefined ? {} : { timeoutMs }), ...bound }),
});
}
return result;
}
return Object.freeze({
list,
members,
async resolve(id, session) {
const { org, shown, context } = await admitted(id, session);
let busHealthy = false;
try { busHealthy = (await busStatus(ctx, id)).healthy === true; } catch { /* unavailable */ }
return { ...options({ id, root: org.root, paths: orgPaths(org.root), session, context, doc: shown.doc }), busHealthy };
},
});
}