diff --git a/packages/cli/src/agent-levels.mjs b/packages/cli/src/agent-levels.mjs
index 3a81f42ea..8778367ad 100644
--- a/packages/cli/src/agent-levels.mjs
+++ b/packages/cli/src/agent-levels.mjs
@@ -19,9 +19,10 @@
// A write prints its receipt; refusals name keys, never values.
import { configDir } from '../../organization/src/organization-config.mjs';
-import { organizationWriter } from '../../organization/src/organization.mjs';
+import { OrgError } from '../../organization/src/org-registry.mjs';
+import { OrganizationError, organizationWriter } from '../../organization/src/organization.mjs';
import { changeRootAgent, patchRootEntry, projectAgentSummary, readRootAgentsFile, rootAgentSummary } from '../../organization/src/agent-levels-write.mjs';
-import { rolesDir } from './config.mjs';
+import { loadSystem, rolesDir } from './config.mjs';
import { DEV_OWNER, devOwnerInstance } from './dev-local-owner.mjs';
import { CliError } from './errors.mjs';
import { refuseInsideAgent } from './transport.mjs';
@@ -82,15 +83,26 @@ function vars(parsed, line) {
const revisionOf = (parsed, read) => parsed.single['--revision'] ?? read();
function owner(io) {
refuseInsideAgent(io.env);
- devOwnerInstance(io.env);
+ // Its refusal is one fixed line naming no path.
+ let instance;
+ try { instance = devOwnerInstance(io.env); } catch (error) { throw error instanceof CliError ? error : new CliError(String(error?.message), 2); }
+ // The instance's system config must exist and validate, marker included, as `mosaic org` checks:
+ // a missing or broken config refuses (exit 3) before anything is read or written.
+ loadSystem({ env: io.env, instance });
return { dir: configDir(io.env), roles: rolesDir(io.env) };
}
+// Only the writers' own coded refusals print their text (it names keys and ids, never a value).
+// Anything else, a filesystem error above all, prints its code and a fixed line: its message can
+// hold a host path. So does a coded refusal whose text happens to hold an absolute path.
+const ABSOLUTE_PATH = /(?:^|[\s('"=:])\/[^\s/]/;
function refusal(error) {
if (error instanceof CliError) return error;
- const code = typeof error?.code === 'string' ? error.code : null;
+ const code = typeof error?.code === 'string' && /^[A-Za-z0-9_-]{1,64}$/.test(error.code) ? error.code : null;
+ const ours = (error instanceof OrgError || error instanceof OrganizationError || error?.name === 'BusinessError') && code !== null;
+ const text = ours && typeof error.message === 'string' && !ABSOLUTE_PATH.test(error.message) ? error.message : 'the operation failed; the error text is not shown';
// A refusal after the replace says the change landed; the receipt may be missing.
const landed = error?.committed ? ' (the change was written; its receipt may be missing)' : '';
- return new CliError(`${code ? `${code}: ` : ''}${error?.message ?? String(error)}${landed}`, 2);
+ return new CliError(`${code ? `${code}: ` : ''}${text}${landed}`, 2);
}
export async function agentsRootCommand(args, io) {
@@ -145,7 +157,7 @@ export async function projectAgentsCommand(args, io) {
if (name !== undefined) throw usage('list takes no name', line);
only(parsed, ['--org', '--json'], line);
const { document, revision } = writer.read(org);
- if (!Object.hasOwn(document.projects ?? {}, project)) throw Object.assign(new Error(`project ${project} is not in organization ${org}`), { code: 'project-not-found' });
+ if (!Object.hasOwn(document.projects ?? {}, project)) throw new OrgError('project-not-found', `project ${project} is not in organization ${org}`);
const listing = { organization: org, project, revision, agents: projectAgentSummary(document.projects[project].agents ?? {}) };
io.stdout.write(parsed.flags.has('--json') ? `${JSON.stringify(listing, null, 2)}\n` : formatProject(listing));
return;
diff --git a/packages/cli/tests/agent-levels-cli.test.mjs b/packages/cli/tests/agent-levels-cli.test.mjs
index cf4c9a956..2b76bd697 100644
--- a/packages/cli/tests/agent-levels-cli.test.mjs
+++ b/packages/cli/tests/agent-levels-cli.test.mjs
@@ -3,7 +3,7 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { existsSync, mkdtempSync, readFileSync } from 'node:fs';
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { tmpdir } from 'node:os';
import { spawnSync } from 'node:child_process';
@@ -69,6 +69,42 @@ test('agents root list, set, remove: each write prints its receipt, values stay
assert.equal(unknown.status, 4); assert.ok(!unknown.stderr.includes(SECRET));
});
+test('a filesystem failure prints its code and a fixed line, never a host path', () => {
+ const { run, configDir, home } = instance();
+ // A directory where the receipt file goes: opening it fails EISDIR, whose message holds the path.
+ mkdirSync(join(configDir, 'agents-receipts.jsonl'));
+ const r = run(['agents', 'root', 'set', 'researcher', '--definition', 'research']);
+ assert.equal(r.status, 2, r.stderr);
+ assert.match(r.stderr, /EISDIR: the operation failed; the error text is not shown/);
+ assert.ok(!r.stderr.includes(home), r.stderr);
+ assert.equal(existsSync(join(configDir, 'agents.json')), false);
+});
+
+test('a missing, malformed or unclaimed instance config refuses before anything is read or written', () => {
+ const verbs = [['agents', 'root', 'set', 'researcher', '--definition', 'research'], ['agents', 'root', 'list'], ['project', 'agents', 'work', '--org', 'alpha', 'exclude', 'coder']];
+ const check = (env, dir, why) => {
+ for (const args of verbs) {
+ const r = spawnSync(join(repo, 'scripts/mosaic'), args, { cwd: repo, env, encoding: 'utf8' });
+ assert.equal(r.status, 3, `${why} ${args.join(' ')}: ${r.stderr}`); assert.match(r.stderr, /system config problem/);
+ }
+ assert.equal(existsSync(join(dir, 'agents.json')), false, why);
+ assert.equal(existsSync(join(dir, 'agents-receipts.jsonl')), false, why);
+ };
+ // Missing: the instance's config directory exists, its config.json does not.
+ const home = mkdtempSync(join(tmpdir(), 'a2cfg-'));
+ const dir = join(home, '.config/mosaic-atwo');
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
+ const env = { PATH: process.env.PATH, LANG: 'C.UTF-8', TMPDIR: process.env.TMPDIR ?? tmpdir(), HOME: home, MOSAIC_CONFIG: join(dir, 'config.json') };
+ check(env, dir, 'missing');
+ writeFileSync(join(dir, 'config.json'), '{', { mode: 0o600 });
+ check(env, dir, 'malformed');
+ // Unclaimed: a bootstrapped instance whose data root marker names another instance.
+ const booted = instance();
+ const { dataRoot } = JSON.parse(readFileSync(booted.env.MOSAIC_CONFIG, 'utf8'));
+ writeFileSync(join(dataRoot, 'instance.json'), JSON.stringify({ instanceVersion: 1, name: 'other' }));
+ check(booted.env, booted.configDir, 'marker');
+});
+
test('the default instance refuses the agent level verbs', () => {
const home = mkdtempSync(join(tmpdir(), 'a2def-'));
const env = { PATH: process.env.PATH, LANG: 'C.UTF-8', TMPDIR: process.env.TMPDIR ?? tmpdir(), HOME: home };
diff --git a/packages/organization/src/agent-levels-write.mjs b/packages/organization/src/agent-levels-write.mjs
index 30579fcb8..7badc3589 100644
--- a/packages/organization/src/agent-levels-write.mjs
+++ b/packages/organization/src/agent-levels-write.mjs
@@ -38,15 +38,22 @@ export function requireRootOwner(actor, owner) {
fail('human-required', 'only the signed-in owner writes the root agent file');
}
-// Every ancestor a real directory, configDir this uid's and not group or other writable.
+// Every ancestor a real directory that only root or this uid can change: owned by one of them, and
+// group or other writable only with the sticky bit (as /tmp is), so no other user can rename or
+// replace configDir between these checks and the path-based lock, temp file and rename. configDir
+// itself is this uid's and not group or other writable.
function assertConfigDir(configDir, uid) {
if (typeof configDir !== 'string' || resolve(configDir) !== configDir) fail('agents-unsafe', 'config directory must be an absolute normalized path');
let current = parse(configDir).root;
+ const trusted = st => (st.uid === 0 || st.uid === uid) && (!(st.mode & 0o022) || (st.mode & 0o1000));
+ try { if (!trusted(lstatSync(current))) fail('agents-unsafe', `a config directory ancestor must belong to root or uid ${uid} and not be writable by others without the sticky bit`); }
+ catch (error) { if (error instanceof OrgError) throw error; fail('agents-unsafe', 'config directory is missing'); }
for (const part of configDir.slice(current.length).split('/').filter(Boolean)) {
current = join(current, part);
let st;
try { st = lstatSync(current); } catch { fail('agents-unsafe', 'config directory is missing'); }
if (!st.isDirectory() || st.isSymbolicLink()) fail('agents-unsafe', 'config path contains a symbolic link or non-directory');
+ if (current !== configDir && !trusted(st)) fail('agents-unsafe', `a config directory ancestor must belong to root or uid ${uid} and not be writable by others without the sticky bit`);
}
const st = lstatSync(configDir);
if (st.uid !== uid) fail('agents-unsafe', `config directory must belong to uid ${uid}`);
@@ -55,7 +62,7 @@ function assertConfigDir(configDir, uid) {
// The reader's descriptor checks (loadRootAgents), plus one link: a regular file, no symbolic link,
// this uid, no group or other write. Missing is an empty root level at ABSENT_REVISION.
-async function readCurrent(configDir, uid) {
+async function readCurrent(configDir, uid, statFile = fd => fd.stat()) {
const file = rootAgentsPath(configDir);
let fd;
try { fd = await fs.open(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK); }
@@ -65,7 +72,7 @@ async function readCurrent(configDir, uid) {
}
let bytes;
try {
- const st = await fd.stat();
+ const st = await statFile(fd);
if (!st.isFile()) fail('agents-unsafe', `root agent file must be a regular file, not a symbolic link (${ROOT_FILE})`);
if (st.uid !== uid) fail('agents-unsafe', `root agent file must belong to uid ${uid} (${ROOT_FILE})`);
if (st.mode & 0o022) fail('agents-unsafe', `root agent file must not be writable by group or other (${ROOT_FILE})`);
@@ -80,9 +87,10 @@ async function readCurrent(configDir, uid) {
// The file's document and revision, for a form or a CLI list. A file that is not a root agent
// document at all refuses; one with a bad entry reads, so the owner can fix or remove that entry.
-export async function readRootAgentsFile(configDir, { uid = process.geteuid() } = {}) {
+// statFile is a test seam for the descriptor stat; it grants nothing a caller's uid does not.
+export async function readRootAgentsFile(configDir, { uid = process.geteuid(), statFile } = {}) {
assertConfigDir(configDir, uid);
- const current = await readCurrent(configDir, uid);
+ const current = await readCurrent(configDir, uid, statFile);
shape(current.document);
return current;
}
@@ -172,7 +180,7 @@ async function syncDirectory(dir) {
// Change one root agent. `entry` is the new entry, null to remove it, or a function of the old
// entry (undefined when there is none) returning either. Returns the receipt. An error after the
// rename carries committed: true, so a caller never retries a write that landed.
-export async function changeRootAgent(configDir, { revision, name, entry }, { actor, owner, rolesDir, uid = process.geteuid(), beforeReplace, syncDirectory: syncDir = syncDirectory } = {}) {
+export async function changeRootAgent(configDir, { revision, name, entry }, { actor, owner, rolesDir, uid = process.geteuid(), beforeReplace, statFile, syncDirectory: syncDir = syncDirectory } = {}) {
requireRootOwner(actor, owner);
if (typeof name !== 'string' || !ID_PATTERN.test(name)) fail('agents-invalid', 'agent name must be an id: lowercase letters, digits, dot, dash or underscore, at most 64');
if (typeof revision !== 'string' || !REVISION.test(revision)) fail('revision-conflict', 'a root agent change needs the revision it was read at');
@@ -188,7 +196,7 @@ export async function changeRootAgent(configDir, { revision, name, entry }, { ac
let temp, receiptFd, committed = false;
try {
assertConfigDir(configDir, uid);
- const before = await readCurrent(configDir, uid);
+ const before = await readCurrent(configDir, uid, statFile);
if (before.revision !== revision) fail('revision-conflict', 'the root agent file changed since it was read; read it again');
shape(before.document);
const old = Object.hasOwn(before.document.agents, name) ? before.document.agents[name] : undefined;
@@ -219,7 +227,7 @@ export async function changeRootAgent(configDir, { revision, name, entry }, { ac
try { await fd.writeFile(bytes); await fd.sync(); } finally { await fd.close(); }
await beforeReplace?.();
// A writer that ignores the lock still loses: the bytes must be the ones read.
- const again = await readCurrent(configDir, uid);
+ const again = await readCurrent(configDir, uid, statFile);
if (again.exists !== before.exists || again.revision !== before.revision) fail('revision-conflict', 'the root agent file changed before the write; read it again');
// A new file is published with link, which fails rather than replace a file made meanwhile.
if (before.exists) await fs.rename(temp, file);
diff --git a/packages/organization/tests/agent-levels-write.test.mjs b/packages/organization/tests/agent-levels-write.test.mjs
index 4134a771c..bb996fafb 100644
--- a/packages/organization/tests/agent-levels-write.test.mjs
+++ b/packages/organization/tests/agent-levels-write.test.mjs
@@ -4,10 +4,10 @@
import test from "node:test";
import assert from "node:assert/strict";
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, symlinkSync, writeFileSync } from "node:fs";
-import { join } from "node:path";
+import { dirname, join } from "node:path";
import { loadRootAgents } from "../src/agent-levels.mjs";
import {
- ABSENT_REVISION, ROOT_RECEIPTS, changeRootAgent, patchRootEntry, projectAgentProblem, readRootAgentsFile, rootAgentSummary,
+ ABSENT_REVISION, ROOT_LOCK, ROOT_RECEIPTS, changeRootAgent, patchRootEntry, projectAgentProblem, readRootAgentsFile, rootAgentSummary,
} from "../src/agent-levels-write.mjs";
import * as oldPath from "../../business/src/agent-levels-write.mjs";
import { organizationWriter } from "../src/organization.mjs";
@@ -138,14 +138,35 @@ test("root writer: a symbolic link, a group-writable file and a foreign uid refu
linkSync(file(dir), join(dir, "alias.json"));
await assert.rejects(changeRootAgent(dir, { revision, name: "pm", entry: { definition: "pm" } }, as()), refuses("agents-unsafe", e => /one link/.test(e.message)));
unlinkSync(join(dir, "alias.json"));
- // Not this process's uid: the config directory's owner check refuses first, the file's after it.
- await assert.rejects(changeRootAgent(dir, { revision, name: "pm", entry: { definition: "pm" } }, { ...as(), uid: process.geteuid() + 1 }), refuses("agents-unsafe", e => /uid/.test(e.message)));
- await assert.rejects(readRootAgentsFile(dir, { uid: process.geteuid() + 1 }), refuses("agents-unsafe", e => /uid/.test(e.message)));
+ // Not this process's uid: the directory checks refuse first (an ancestor this uid owns is foreign).
+ await assert.rejects(changeRootAgent(dir, { revision, name: "pm", entry: { definition: "pm" } }, { ...as(), uid: process.geteuid() + 1 }), refuses("agents-unsafe", e => /config directory/.test(e.message) && !/root agent file/.test(e.message)));
+ await assert.rejects(readRootAgentsFile(dir, { uid: process.geteuid() + 1 }), refuses("agents-unsafe", e => /config directory/.test(e.message) && !/root agent file/.test(e.message)));
assert.equal(bytes(dir), original);
+ // A file another uid owns, in a directory that is this uid's: the file's own owner check refuses.
+ // Changing a file's owner needs root, so the descriptor stat reports a foreign uid through the seam.
+ const foreign = async fd => { const st = await fd.stat(); return Object.assign(Object.create(Object.getPrototypeOf(st)), st, { uid: st.uid + 1 }); };
+ const receiptsBefore = existsSync(join(dir, ROOT_RECEIPTS)) ? readFileSync(join(dir, ROOT_RECEIPTS), "utf8") : null;
+ await assert.rejects(changeRootAgent(dir, { revision, name: "pm", entry: { definition: "pm" } }, { ...as(), statFile: foreign }), refuses("agents-unsafe", e => /root agent file must belong to uid/.test(e.message)));
+ await assert.rejects(readRootAgentsFile(dir, { statFile: foreign }), refuses("agents-unsafe", e => /root agent file must belong to uid/.test(e.message)));
+ assert.equal(bytes(dir), original);
+ assert.equal(lstatSync(file(dir)).mode & 0o777, 0o600);
+ assert.equal(existsSync(join(dir, ROOT_RECEIPTS)) ? readFileSync(join(dir, ROOT_RECEIPTS), "utf8") : null, receiptsBefore);
+ assert.equal(existsSync(join(dir, ROOT_LOCK)), false, "the lock is released");
// A group-writable config directory refuses before any lock or read.
chmodSync(dir, 0o770);
await assert.rejects(changeRootAgent(dir, { revision, name: "pm", entry: { definition: "pm" } }, as()), refuses("agents-unsafe", e => /config directory/.test(e.message)));
chmodSync(dir, 0o700);
+ // An ancestor another user can write without the sticky bit refuses: that user could rename the
+ // config directory between the checks and the write. With the sticky bit, as /tmp has, it can't.
+ const parent = dirname(dir);
+ const mode = lstatSync(parent).mode & 0o7777;
+ chmodSync(parent, 0o777);
+ try {
+ await assert.rejects(changeRootAgent(dir, { revision, name: "pm", entry: { definition: "pm" } }, as()), refuses("agents-unsafe", e => /ancestor/.test(e.message) && !e.message.includes(dir)));
+ await assert.rejects(readRootAgentsFile(dir), refuses("agents-unsafe", e => /ancestor/.test(e.message)));
+ chmodSync(parent, 0o1777);
+ assert.equal((await readRootAgentsFile(dir)).revision, revision);
+ } finally { chmodSync(parent, mode); }
assert.equal(bytes(dir), original);
assert.equal(receipts(dir).length, 1);
assert.equal(existsSync(join(dir, "agents.lock")), false);
@@ -206,11 +227,9 @@ test("root writer: a held lock refuses agents-locked", async () => {
});
// The project-agent verb: the organization file's projects.
.agents, one entry per call.
-function org(t, mutate = () => {}) {
+function org(mutate = () => {}) {
const root = tmp();
const doc = businessDoc(root);
- doc.projects.notes = { kind: "library", root: join(root, "notes"), mapping: undefined };
- delete doc.projects.notes;
mutate(doc);
const dir = join(root, "config");
const orgFile = writeJson(join(dir, "businesses/acme.json"), doc);
@@ -266,13 +285,18 @@ test("project verb: a narrow that widens refuses, and refusals never quote a val
test("project verb: the chief and the assistant refuse", () => {
const { writer, orgFile } = org(doc => { doc.roles.assistant = { definition: "assistant" }; });
- const { revision } = writer.read("acme");
+ const { document, revision } = writer.read("acme");
+ assert.equal(document.roles.assistant.definition, "assistant", "the fixture has an organization assistant");
+ assert.equal(document.roles.chief.definition, "chief-of-staff", "the fixture has a chief");
const before = readFileSync(orgFile, "utf8");
- for (const [name, entry] of [
- ["chief", { exclude: true }], ["chief", { vars: { "limits.network": "none" } }], ["chief", { definition: "reviewer" }],
- ["assistant", { exclude: true }], ["helper", { definition: "chief-of-staff" }], ["helper", { definition: "assistant" }],
+ const protectedAgent = /a project can't change the organization's (chief-of-staff|assistant)/;
+ const notProjectAgent = /can't be a project agent/;
+ for (const [name, entry, reason] of [
+ ["chief", { exclude: true }, protectedAgent], ["chief", { vars: { "limits.network": "none" } }, protectedAgent], ["chief", { definition: "reviewer" }, protectedAgent],
+ ["assistant", { exclude: true }, protectedAgent], ["assistant", { vars: { "limits.network": "none" } }, protectedAgent], ["assistant", { definition: "reviewer" }, protectedAgent],
+ ["helper", { definition: "chief-of-staff" }, notProjectAgent], ["helper", { definition: "assistant" }, notProjectAgent],
]) {
- assert.throws(() => writer.setProjectAgent("acme", { revision, project: "stack", name, entry }, "jason"), e => e.code === "project-agents-invalid", `${name} ${JSON.stringify(entry)}`);
+ assert.throws(() => writer.setProjectAgent("acme", { revision, project: "stack", name, entry }, "jason"), e => e.code === "project-agents-invalid" && reason.test(e.message), `${name} ${JSON.stringify(entry)}`);
}
assert.equal(readFileSync(orgFile, "utf8"), before);
});
diff --git a/packages/webui/src/agent-levels-write.mjs b/packages/webui/src/agent-levels-write.mjs
index ebfbeab57..6bac109e8 100644
--- a/packages/webui/src/agent-levels-write.mjs
+++ b/packages/webui/src/agent-levels-write.mjs
@@ -21,6 +21,7 @@
// A response or trail entry names agents, keys and revisions, never a var value or a host path.
import { organizationWriter } from '../../organization/src/organization.mjs';
import { changeRootAgent, patchRootEntry, projectAgentSummary, readRootAgentsFile, rootAgentSummary } from '../../organization/src/agent-levels-write.mjs';
+import { ID_PATTERN } from '../../organization/src/vocabulary.mjs';
import { actor } from './action-trail.mjs';
export const ROOT_ROUTE = '/api/agents/root';
@@ -28,7 +29,10 @@ export const PROJECT_ROUTE = /^\/api\/orgs\/([^/]+)\/agent-levels\/projects\/([^
// routeTable takes GET and POST only; any other method never reaches these hooks (serve.mjs answers it).
const METHODS = ['GET', 'POST'];
const REVISION = /^[a-f0-9]{64}$/;
-const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,159}$/;
+// Agent and project names are the writers' ids (requireId): checked here so a bad one is a 400
+// naming the field, not a writer error the Console can't classify.
+const NAME = ID_PATTERN;
+const NAME_RULE = 'lowercase letters, digits, dot, dash or underscore, at most 64';
const LIMIT = 4096;
const ROOT_PATCH = ['definition', 'vars', 'excludeOrgs'];
const PROJECT_ENTRY = ['definition', 'vars', 'exclude'];
@@ -86,7 +90,8 @@ async function body(req) {
try { value = JSON.parse(Buffer.concat(chunks).toString('utf8')); } catch { return null; }
const keys = ['revision', 'name', 'entry'];
if (!plain(value) || Object.keys(value).length !== keys.length || !keys.every(k => Object.hasOwn(value, k))) return null;
- if (typeof value.revision !== 'string' || !REVISION.test(value.revision) || typeof value.name !== 'string' || !NAME.test(value.name)) return null;
+ if (typeof value.revision !== 'string' || !REVISION.test(value.revision) || typeof value.name !== 'string') return null;
+ if (!NAME.test(value.name)) return 'bad-name';
return value;
}
const only = (entry, keys) => plain(entry) && Object.keys(entry).length > 0 && Object.keys(entry).every(k => keys.includes(k));
@@ -107,6 +112,7 @@ export function agentLevelsWriteRoutes({ configDir, rolesDir, trail = null, log
if (!send) { json(res, 403, { error: 'read-only', message: 'this Console was started without writes' }); return null; }
const value = await body(req);
if (value === 'too-large') { json(res, 413, { error: 'invalid-request', message: `a change is at most ${LIMIT} bytes` }); return null; }
+ if (value === 'bad-name') { json(res, 400, { error: 'invalid-request', message: `name must be an id: ${NAME_RULE}` }); return null; }
if (!value) { json(res, 400, { error: 'invalid-request', message: 'this takes revision, name and entry, nothing else' }); return null; }
return value;
}
diff --git a/packages/webui/src/public/agents.js b/packages/webui/src/public/agents.js
index e05a7bd9e..32ebdc554 100644
--- a/packages/webui/src/public/agents.js
+++ b/packages/webui/src/public/agents.js
@@ -247,6 +247,11 @@
const UNKNOWN = 'Outcome unknown. Nothing was retried. The grid below was read again.';
let root = null, levels = null, project = null, selected = { org: '', project: '' };
let receipts = { root: '', project: '' }, busy = false, confirming = null;
+ // What each form holds, kept here so a polling render, a picker change or the other form's save
+ // repaints it as typed. A draft keeps the revision it began at, so a save sends that and a file
+ // changed meanwhile refuses rather than being overwritten unseen. The project draft belongs to its
+ // organization and project. Only the submitted form's own success clears it.
+ const drafts = { root: null, project: null };
const read = url => fetch(url, { cache: 'no-store', redirect: 'manual' }).then(async r => {
if (r.type === 'opaqueredirect') return { signedOut: true };
@@ -308,14 +313,22 @@
return `