Jason's owner report 2026-11-06: no way to archive or delete projects.
Archive is the reversible half; delete stays out of scope because project
and run records are write-once evidence.
- project.archive / project.unarchive: human-only (project.create's gate
minus the tester carve-out; tester, user and agent refused). State is the
latest row of a new append-only project_archives journal (3s->3t, additive;
the rows are the audit trail), so projects itself never changes and nothing
is deleted. Repeats refuse project-already-archived / project-not-archived.
- project.list hides archived projects until {includeArchived:true}, which
flags each with archived:true; a user still lists granted projects only.
- While archived, thread.create, thread.send, room.open and room.send refuse
project-archived; every existing record stays readable and unarchive
restores everything.
- Console: new public/project-archive.js (+css) and project-archive-http.mjs
routes (chatHTTP's write fence); chat.js gains two one-line hooks,
index.html one script and one link tag; styling only through the shell's
.project-archive-control / .project-archived-filter hooks.
- CLI: mosaic project archive|unarchive <name-or-id> and list --archived.
- stack-release COUNTED/LISTED gain project_archives (schema order); schema
step-count pins and migration fixtures updated for 3t.
bus 1601/1601 (Node 24; Node 26 has the pre-existing project-file socket
stall), webui 582/582, plugins 132/132, cli 1191/1194 (two pre-existing
load flakes of the row253 C4 and land_work families; both pass isolated and
the base commit's full suite fails four of the same family).
98 lines
5.6 KiB
JavaScript
98 lines
5.6 KiB
JavaScript
import { configDir, loadBusiness } from '../../business/src/index.mjs';
|
|
import { checkProject, initProject, ProjectError, testerProjectArea } from '../../project/src/index.mjs';
|
|
import { loadSystem, rolesDir } from './config.mjs';
|
|
import { CliError } from './errors.mjs';
|
|
import { shortId } from './format.mjs';
|
|
import { parseArgs } from './thread.mjs';
|
|
import { refuseInsideAgent } from './transport.mjs';
|
|
|
|
export const PROJECT_USAGE = 'mosaic project init <business> <project> [--tester] | check <business> <project>';
|
|
// Row 128 (#1622): create and list work on the bus record (project.create, project.list); init
|
|
// and check above work on the repository on disk and never contact the bus, except that
|
|
// init --tester (row 175, #1673) binds the tester once before it writes.
|
|
export const PROJECT_BUS_USAGE = [
|
|
'mosaic project create <name> [--repo <repo>] [--business <id>] [--tester]',
|
|
'mosaic project list [--archived] [--business <id>] [--json] [--tester]',
|
|
'mosaic project archive <name-or-id> [--business <id>]',
|
|
'mosaic project unarchive <name-or-id> [--business <id>]',
|
|
'A thread project named for a business repository must carry that repo: --repo <name>.',
|
|
'list --archived includes archived projects, each marked; archive is reversible and deletes nothing.',
|
|
].join('\n ');
|
|
|
|
export async function projectBusCommand(args, io, callFor) {
|
|
const [sub, ...rest] = args;
|
|
const parsed = parseArgs(rest, PROJECT_BUS_USAGE, sub === 'create'
|
|
? { flags: ['--tester'], values: ['--repo', '--business'] }
|
|
: sub === 'list'
|
|
? { flags: ['--json', '--tester', '--archived'], values: ['--business'] }
|
|
: { flags: [], values: ['--business'] });
|
|
const one = sub === 'create' || sub === 'archive' || sub === 'unarchive';
|
|
if (parsed.positional.length !== (one ? 1 : 0))
|
|
throw new CliError(`project ${sub} takes ${one ? (sub === 'create' ? 'one name' : 'one name or id') : 'no arguments'}\n${PROJECT_BUS_USAGE}`, 4);
|
|
const call = callFor(parsed);
|
|
if (sub === 'create') {
|
|
const [name] = parsed.positional;
|
|
let made;
|
|
try {
|
|
made = await call('project.create', { name, ...(parsed.values['--repo'] === undefined ? {} : { repo: parsed.values['--repo'] }) });
|
|
} catch (error) {
|
|
if (error.code === 'project-name-is-repo')
|
|
throw new CliError(`${JSON.stringify(name)} is a repository in the business file; add --repo ${name} to make its thread project, or pick another name`, 2);
|
|
throw error;
|
|
}
|
|
return io.stdout.write(`created project ${name} id ${made.id}\n`);
|
|
}
|
|
// #797 MVP3: the owner's reversible archive. Resolution reads the full list, archived included,
|
|
// so an archived project can be named for unarchive.
|
|
if (sub === 'archive' || sub === 'unarchive') {
|
|
const [ref] = parsed.positional;
|
|
const projects = await call('project.list', { includeArchived: true });
|
|
const hit = projects.find(p => p.id === ref) ?? projects.find(p => p.name === ref);
|
|
if (!hit) throw new CliError(`no project is named or numbered ${JSON.stringify(ref)}; see mosaic project list`, 2);
|
|
try {
|
|
await call(`project.${sub}`, { project: hit.id });
|
|
} catch (error) {
|
|
if (error.code === 'project-already-archived') throw new CliError(`project ${hit.name} is already archived`, 2);
|
|
if (error.code === 'project-not-archived') throw new CliError(`project ${hit.name} is not archived`, 2);
|
|
throw error;
|
|
}
|
|
return io.stdout.write(`${sub === 'archive' ? 'archived' : 'unarchived'} project ${hit.name} id ${shortId(hit.id)}\n`);
|
|
}
|
|
const projects = await call('project.list', parsed.flags.has('--archived') ? { includeArchived: true } : {});
|
|
if (parsed.flags.has('--json')) return io.stdout.write(`${JSON.stringify(projects, null, 2)}\n`);
|
|
io.stdout.write(projects.length === 0 ? 'no projects\n' : projects.map(p => `${p.name}${p.archived ? ' archived' : ''} ${p.repo ?? '-'} ${shortId(p.id)}\n`).join(''));
|
|
}
|
|
|
|
// Row 175 (#1673, Q173, mos-0872 Q2): `init --tester` may run inside an agent. Before anything
|
|
// touches the disk it refuses a repository outside <dataRoot>/projects/<business>/
|
|
// (tester-project-area, exit 2), then binds the tester with one agents read, so tester-off and
|
|
// tester-required refuse (exit 3), then commits the layout as `tester`.
|
|
export async function projectCommand(args, io, deps = {}, callFor) {
|
|
const tester = args[0] === 'init' && args.filter(arg => arg === '--tester').length === 1;
|
|
const words = tester ? args.filter(arg => arg !== '--tester') : args;
|
|
if (words.length !== 3 || !['init', 'check'].includes(words[0]) || words.some(arg => arg.startsWith('--')))
|
|
throw new CliError(PROJECT_USAGE, 4);
|
|
const [verb, id, project] = words;
|
|
if (verb === 'init' && !tester) refuseInsideAgent(io.env);
|
|
try {
|
|
const system = deps.system ?? loadSystem({ env: io.env });
|
|
const business = loadBusiness(id, { dir: configDir(io.env), rolesDir: rolesDir(io.env) });
|
|
const context = { business, project, dataRoot: system.dataRoot };
|
|
if (tester) {
|
|
testerProjectArea(context);
|
|
await callFor({ positional: [], flags: new Set(['--tester']), values: { '--business': id } })('agents', {});
|
|
}
|
|
if (verb === 'init') {
|
|
const result = await initProject(context, tester ? { author: 'tester' } : {});
|
|
io.stdout.write(`initialized ${result.repo}\ncommit ${result.commit}\n`);
|
|
} else {
|
|
const result = await checkProject(context);
|
|
if (!result.ok) throw new CliError(result.problems.join('\n'), 2);
|
|
io.stdout.write(`checked ${result.repo}: valid\n`);
|
|
}
|
|
} catch (error) {
|
|
if (error instanceof CliError) throw error;
|
|
throw new CliError(error.message, error instanceof ProjectError ? 2 : 3);
|
|
}
|
|
}
|