diff --git a/packages/bus/schema.sql b/packages/bus/schema.sql index 0c636369d..b06bb372d 100644 --- a/packages/bus/schema.sql +++ b/packages/bus/schema.sql @@ -319,3 +319,52 @@ CREATE TRIGGER message_threads_no_replace BEFORE INSERT ON message_threads WHEN CREATE TRIGGER thread_opens_no_update BEFORE UPDATE ON thread_opens BEGIN SELECT RAISE(ABORT, 'thread_opens is append-only'); END; CREATE TRIGGER thread_opens_no_delete BEFORE DELETE ON thread_opens BEGIN SELECT RAISE(ABORT, 'thread_opens is append-only'); END; CREATE TRIGGER thread_opens_no_replace BEFORE INSERT ON thread_opens WHEN EXISTS (SELECT 1 FROM thread_opens WHERE seq = NEW.seq) BEGIN SELECT RAISE(ABORT, 'thread_opens is append-only'); END; +-- Row 138 (#1632): immutable proposals and human confirmations, with exact decision citations. +CREATE TABLE specs ( + seq INTEGER PRIMARY KEY AUTOINCREMENT, + at TEXT NOT NULL, + business TEXT NOT NULL, + spec_id TEXT NOT NULL, + need TEXT NOT NULL, + version INTEGER NOT NULL CHECK (version > 0), + text TEXT NOT NULL CHECK (length(text) BETWEEN 1 AND 32768), + proposed_by_role TEXT NOT NULL, + proposed_by_run TEXT NOT NULL, + UNIQUE (business, spec_id, version) +) STRICT; +CREATE TABLE spec_confirmations ( + seq INTEGER PRIMARY KEY AUTOINCREMENT, + at TEXT NOT NULL, + business TEXT NOT NULL, + spec_id TEXT NOT NULL, + spec_version INTEGER NOT NULL, + confirmed_by TEXT NOT NULL, + UNIQUE (business, spec_id, spec_version), + FOREIGN KEY (business, spec_id, spec_version) REFERENCES specs(business, spec_id, version) +) STRICT; +ALTER TABLE decisions ADD COLUMN spec_id TEXT; +ALTER TABLE decisions ADD COLUMN spec_version INTEGER; +CREATE TRIGGER specs_identity BEFORE INSERT ON specs + WHEN EXISTS (SELECT 1 FROM specs s WHERE s.business = NEW.business + AND ((s.spec_id = NEW.spec_id AND s.need <> NEW.need) OR (s.need = NEW.need AND s.spec_id <> NEW.spec_id))) + BEGIN SELECT RAISE(ABORT, 'spec need and id are immutable'); END; +CREATE TRIGGER specs_version BEFORE INSERT ON specs + WHEN NEW.version <> COALESCE((SELECT max(version) FROM specs WHERE business = NEW.business AND spec_id = NEW.spec_id), 0) + 1 + BEGIN SELECT RAISE(ABORT, 'spec versions advance by one'); END; +CREATE TRIGGER spec_confirmations_forward BEFORE INSERT ON spec_confirmations + WHEN NEW.spec_version <= COALESCE((SELECT max(spec_version) FROM spec_confirmations + WHERE business = NEW.business AND spec_id = NEW.spec_id), 0) + BEGIN SELECT RAISE(ABORT, 'spec confirmation must advance'); END; +CREATE TRIGGER decisions_spec BEFORE INSERT ON decisions + WHEN (NEW.spec_id IS NULL) <> (NEW.spec_version IS NULL) + OR (NEW.spec_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM spec_confirmations c + WHERE c.business = NEW.business AND c.spec_id = NEW.spec_id AND c.spec_version = NEW.spec_version + AND c.spec_version = (SELECT max(spec_version) FROM spec_confirmations + WHERE business = NEW.business AND spec_id = NEW.spec_id))) + BEGIN SELECT RAISE(ABORT, 'decision needs current confirmed spec'); END; +CREATE TRIGGER specs_no_update BEFORE UPDATE ON specs BEGIN SELECT RAISE(ABORT, 'specs is append-only'); END; +CREATE TRIGGER specs_no_delete BEFORE DELETE ON specs BEGIN SELECT RAISE(ABORT, 'specs is append-only'); END; +CREATE TRIGGER specs_no_replace BEFORE INSERT ON specs WHEN EXISTS (SELECT 1 FROM specs WHERE seq = NEW.seq OR (business = NEW.business AND spec_id = NEW.spec_id AND version = NEW.version)) BEGIN SELECT RAISE(ABORT, 'specs is append-only'); END; +CREATE TRIGGER spec_confirmations_no_update BEFORE UPDATE ON spec_confirmations BEGIN SELECT RAISE(ABORT, 'spec_confirmations is append-only'); END; +CREATE TRIGGER spec_confirmations_no_delete BEFORE DELETE ON spec_confirmations BEGIN SELECT RAISE(ABORT, 'spec_confirmations is append-only'); END; +CREATE TRIGGER spec_confirmations_no_replace BEFORE INSERT ON spec_confirmations WHEN EXISTS (SELECT 1 FROM spec_confirmations WHERE seq = NEW.seq OR (business = NEW.business AND spec_id = NEW.spec_id AND spec_version = NEW.spec_version)) BEGIN SELECT RAISE(ABORT, 'spec_confirmations is append-only'); END; diff --git a/packages/bus/src/broker.mjs b/packages/bus/src/broker.mjs index 49c51cd8e..ecb94b749 100644 --- a/packages/bus/src/broker.mjs +++ b/packages/bus/src/broker.mjs @@ -22,6 +22,7 @@ export const ACTIONS = Object.freeze([ 'role.revoke', 'role.end', 'organization.change', + 'spec.propose', 'credential.mint', 'spend', 'deploy', @@ -475,6 +476,24 @@ export class Broker { #sender(s) { return s.human ? 'human' : s.tester ? 'tester' : s.role; } + // Row 138: exact proposal versions are immutable; confirmation is separate human evidence. + #spec(s, specId, version = null) { + const exists = this.#store.get('SELECT 1 FROM specs WHERE business=? AND spec_id=?', s.business, specId); + if (!exists) fail('spec-not-found'); + const row = version === null + ? this.#store.get( + `SELECT p.*, c.at AS confirmed_at, c.confirmed_by FROM specs p + JOIN spec_confirmations c ON c.business=p.business AND c.spec_id=p.spec_id AND c.spec_version=p.version + WHERE p.business=? AND p.spec_id=? ORDER BY p.version DESC LIMIT 1`, s.business, specId, + ) + : this.#store.get( + `SELECT p.*, c.at AS confirmed_at, c.confirmed_by FROM specs p + LEFT JOIN spec_confirmations c ON c.business=p.business AND c.spec_id=p.spec_id AND c.spec_version=p.version + WHERE p.business=? AND p.spec_id=? AND p.version=?`, s.business, specId, version, + ); + if (!row) fail(version === null ? 'spec-unconfirmed' : 'spec-version-not-found'); + return row; + } #decision(s, id) { const d = this.#store.get('SELECT * FROM decisions WHERE id=? AND business=?', id, s.business); if (!d) fail('decision-not-found'); @@ -991,6 +1010,58 @@ export class Broker { this.#claimEnd(s, h, 'revoke', a.decision ?? null, a.reason ?? null); return { revoked: true }; } + case 'spec': { + keys(a, ['spec_id', 'version'], ['spec_id']); + identifier(a.spec_id); + if (a.version !== undefined) { + this.#human(s); + if (!Number.isSafeInteger(a.version) || a.version < 1) fail('invalid-request'); + } else if (s.human) this.#human(s); + else this.#agent(s); + return this.#spec(s, a.spec_id, a.version ?? null); + } + case 'spec.propose': { + keys(a, ['spec_id', 'need', 'text'], ['spec_id', 'need', 'text']); + this.#agent(s); + if (b.roles[s.role]?.definition !== 'assistant') fail('assistant-required'); + if (this.#classification(s, 'spec.propose') !== 'within-role') fail('spec-proposal-refused'); + identifier(a.spec_id); + string(a.need, 1024); + string(a.text, 32768); + if (this.#store.get( + `SELECT 1 FROM specs WHERE business=? AND + ((spec_id=? AND need<>?) OR (need=? AND spec_id<>?))`, + s.business, a.spec_id, a.need, a.need, a.spec_id, + )) fail('spec-need-conflict'); + const version = this.#store.get( + 'SELECT COALESCE(max(version),0)+1 AS version FROM specs WHERE business=? AND spec_id=?', + s.business, a.spec_id, + ).version; + this.#consumeAuthority(s, 'spec.propose', {}, { operation: 'spec.propose', spec_id: a.spec_id, version }); + this.#store.run( + `INSERT INTO specs(at,business,spec_id,need,version,text,proposed_by_role,proposed_by_run) + VALUES(?,?,?,?,?,?,?,?)`, this.#now(), s.business, a.spec_id, a.need, version, a.text, s.role, s.run, + ); + return this.#spec(s, a.spec_id, version); + } + case 'spec.confirm': { + keys(a, ['spec_id', 'version'], ['spec_id', 'version']); + this.#human(s); + identifier(a.spec_id); + if (!Number.isSafeInteger(a.version) || a.version < 1) fail('invalid-request'); + this.#spec(s, a.spec_id, a.version); + const current = this.#store.get( + 'SELECT max(spec_version) AS version FROM spec_confirmations WHERE business=? AND spec_id=?', + s.business, a.spec_id, + ).version; + if (current !== null && a.version <= current) fail('spec-confirmation-stale'); + this.#store.run( + 'INSERT INTO spec_confirmations(at,business,spec_id,spec_version,confirmed_by) VALUES(?,?,?,?,?)', + this.#now(), s.business, a.spec_id, a.version, s.human, + ); + this.#event(s, 'action.allowed', { operation: 'spec.confirm', spec_id: a.spec_id, version: a.version }); + return this.#spec(s, a.spec_id); + } case 'decision.raise': { keys( a, @@ -1008,11 +1079,20 @@ export class Broker { 'supersedes', 'choice', 'approvalChoice', + 'spec_id', + 'spec_version', ], ['action', 'question', 'options', 'recommendation', 'blocking'], ); this.#agent(s); const cls = this.#classification(s, a.action); + if ((a.spec_id !== undefined) !== (a.spec_version !== undefined)) fail('invalid-request'); + if (a.spec_id !== undefined) { + identifier(a.spec_id); + if (!Number.isSafeInteger(a.spec_version) || a.spec_version < 1) fail('invalid-request'); + const spec = this.#spec(s, a.spec_id); + if (spec.version !== a.spec_version) fail('spec-version-stale'); + } string(a.question); if (typeof a.blocking !== 'boolean') fail('invalid-request'); if (a.blocking && !a.task_ref) fail('task-required'); @@ -1052,7 +1132,7 @@ export class Broker { } const did = randomUUID(); this.#store.run( - 'INSERT INTO decisions(id,at,business,project,raised_by_role,raised_by_run,class,action,route_to,question,options,recommendation,task_ref,requirement_ref,blocking,supersedes) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', + 'INSERT INTO decisions(id,at,business,project,raised_by_role,raised_by_run,class,action,route_to,question,options,recommendation,task_ref,requirement_ref,blocking,supersedes,spec_id,spec_version) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', did, this.#now(), s.business, @@ -1069,6 +1149,8 @@ export class Broker { a.requirement_ref ?? null, Number(a.blocking), a.supersedes ?? null, + a.spec_id ?? null, + a.spec_version ?? null, ); this.#event( s, diff --git a/packages/bus/src/store.mjs b/packages/bus/src/store.mjs index 81e01cca7..761f93101 100644 --- a/packages/bus/src/store.mjs +++ b/packages/bus/src/store.mjs @@ -13,8 +13,8 @@ import { join, isAbsolute } from 'node:path'; import { createHash } from 'node:crypto'; const ddl = readFileSync(new URL('../schema.sql', import.meta.url), 'utf8'); -export const SCHEMA_SHA256 = '21e6c091f14f818396f4d7836f381cc1389d45b2680ecaa1a00646b652c45050'; -export const SCHEMA_VERSION = '3e'; +export const SCHEMA_SHA256 = '348304fd160dba7227531b7ce22fbb44afd0fe68f1985476ba74b29940951c87'; +export const SCHEMA_VERSION = '3f'; // Ordered, named offline steps. New schema changes append a step and keep prior DDL pinned. const legacyDDL = readFileSync(new URL('./migrations/3b.sql', import.meta.url), 'utf8'); const LEGACY_SHA256 = '179ffe356d4ff19a49b5ebad39b6c6bfd7771deb8e1b7c55b5e746f039d69e65'; @@ -38,6 +38,10 @@ const migrations = [{ report: (store) => store.all( "SELECT business, to_role, count(*) AS n FROM messages m WHERE NOT EXISTS(SELECT 1 FROM deliveries d WHERE d.message=m.id AND d.op IN ('delivered','read')) GROUP BY business, to_role ORDER BY business, to_role", ).map((r) => `kept ${r.n} undelivered message(s) for ${r.business}/${r.to_role} without a thread; if that role is a thread instance, its thread runs never receive them, so the human re-sends them with thread.send`), +}, { + from: '3e', + to: '3f', + sql: readFileSync(new URL('./migrations/3e-3f.sql', import.meta.url), 'utf8'), }]; const timedTables = [ 'events', @@ -51,6 +55,8 @@ const timedTables = [ 'threads', 'thread_claims', 'thread_opens', + 'specs', + 'spec_confirmations', ]; const hex = (value) => createHash('sha256').update(value).digest('hex'); if (hex(ddl) !== SCHEMA_SHA256) throw Error('schema-source-mismatch'); diff --git a/packages/bus/tests/chief-of-staff.test.mjs b/packages/bus/tests/chief-of-staff.test.mjs index 67b962f89..e20bfb7e2 100644 --- a/packages/bus/tests/chief-of-staff.test.mjs +++ b/packages/bus/tests/chief-of-staff.test.mjs @@ -6,7 +6,7 @@ import { join } from 'node:path'; import { createHash } from 'node:crypto'; import { DatabaseSync } from 'node:sqlite'; import { fileURLToPath, pathToFileURL } from 'node:url'; -import { Store, schemaDigest } from '../src/store.mjs'; +import { Store, schemaDigest, SCHEMA_VERSION } from '../src/store.mjs'; import { Broker } from '../src/broker.mjs'; import { startBroker } from '../src/runtime.mjs'; import { businessDoc, rolesCopy, systemFor, writeJson } from '../../business/tests/helpers.mjs'; @@ -367,7 +367,7 @@ async function database3c(t) { let source = readFileSync(here('../src/store.mjs'), 'utf8'); const pinned = source .replace(/export const SCHEMA_SHA256 = '[a-f0-9]+';/, `export const SCHEMA_SHA256 = '${createHash('sha256').update(ddl3c).digest('hex')}';`) - .replace("export const SCHEMA_VERSION = '3e';", "export const SCHEMA_VERSION = '3c';") + .replace(/export const SCHEMA_VERSION = '[^']+';/, "export const SCHEMA_VERSION = '3c';") .replace(/\}, \{\n {2}from: '3c',[\s\S]*?\}\];\nconst timedTables/, '}];\nconst timedTables'); assert.notEqual(pinned, source); assert.ok(!pinned.includes('3c-3d'), 'the 3c engine has no 3c→3d step'); @@ -391,7 +391,7 @@ test('REQ-ROLE-2, REQ-COS-1: the 3c→3d migration lets the chief of staff end a assert.throws(() => new Store(root), /schema-mismatch/); const store = new Store(root, { migrateSchema: true }); t.after(() => store.close()); - assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3e'); + assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, SCHEMA_VERSION); assert.equal(store.get("SELECT body FROM events WHERE id='preserved'").body, '{"fixture":true}'); assert.equal(store.get("SELECT holder_run FROM role_claims WHERE role='coder'").holder_run, 'coder-run'); const b = new Broker({ store, businesses: demo(), organization: null }); diff --git a/packages/bus/tests/comment-migration.test.mjs b/packages/bus/tests/comment-migration.test.mjs index 555da864c..2ae3f75c0 100644 --- a/packages/bus/tests/comment-migration.test.mjs +++ b/packages/bus/tests/comment-migration.test.mjs @@ -5,7 +5,7 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { DatabaseSync } from 'node:sqlite'; import { createHash } from 'node:crypto'; -import { Store, schemaDigest } from '../src/store.mjs'; +import { Store, schemaDigest, SCHEMA_VERSION } from '../src/store.mjs'; function legacy(t) { const root = mkdtempSync(join(tmpdir(), 'comment-migration-')); @@ -33,7 +33,7 @@ test('explicit 3b copy migration preserves evidence and opens as 3e; normal star const original = readFileSync(source); assert.throws(() => new Store(root), /schema-mismatch/); const store = new Store(root, { migrateSchema: true }); - assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3e'); + assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, SCHEMA_VERSION); assert.equal(store.get("SELECT body FROM events WHERE id='preserved'").body, '{"fixture":true}'); assert.equal(store.get('SELECT count(*) n FROM task_comment_cursors').n, 0); const epoch = store.get("SELECT value FROM meta WHERE key='comment_cursor_epoch'").value; @@ -62,7 +62,7 @@ test('migration refuses active writers and drifted legacy schemas, with no parti assert.throws(() => new Store(other.root, { migrateSchema: true }), /writer-locked/); }); -test('named migration registry chains 3b through 3e to a fixture-only future version in order', async t => { +test('named migration registry chains 3b through 3f to a fixture-only future version in order', async t => { const { root } = legacy(t); const { writeFileSync } = await import('node:fs'); const { pathToFileURL } = await import('node:url'); @@ -75,15 +75,15 @@ test('named migration registry chains 3b through 3e to a fixture-only future ver const sha = createHash('sha256').update(futureDDL).digest('hex'); let source = readFileSync(new URL('../src/store.mjs', import.meta.url), 'utf8'); source = source.replace(/export const SCHEMA_SHA256 = '[a-f0-9]+';/, `export const SCHEMA_SHA256 = '${sha}';`) - .replace("export const SCHEMA_VERSION = '3e';", "export const SCHEMA_VERSION = '3f';") - .replace('}];\nconst timedTables', `}, { from: '3e', to: '3f', sql: ${JSON.stringify(futureSQL)} }];\nconst timedTables`); + .replace("export const SCHEMA_VERSION = '3f';", "export const SCHEMA_VERSION = '3g';") + .replace('}];\nconst timedTables', `}, { from: '3f', to: '3g', sql: ${JSON.stringify(futureSQL)} }];\nconst timedTables`); writeFileSync(join(moduleRoot, 'src/store.mjs'), source); writeFileSync(join(moduleRoot, 'schema.sql'), futureDDL); - for (const name of ['3b.sql', '3b-3c.sql', '3c-3d.sql', '3d-3e.sql']) + for (const name of ['3b.sql', '3b-3c.sql', '3c-3d.sql', '3d-3e.sql', '3e-3f.sql']) copyFileSync(new URL('../src/migrations/' + name, import.meta.url), join(moduleRoot, 'src/migrations', name)); const { Store: FutureStore } = await import(pathToFileURL(join(moduleRoot, 'src/store.mjs'))); const future = new FutureStore(root, { migrateSchema: true }); - assert.equal(future.get("SELECT value FROM meta WHERE key='schema_version'").value, '3f'); + assert.equal(future.get("SELECT value FROM meta WHERE key='schema_version'").value, '3g'); assert.equal(future.get("SELECT name FROM sqlite_master WHERE name='future_fixture'").name, 'future_fixture'); assert.equal(future.get("SELECT count(*) n FROM task_comment_cursors").n, 0); assert.equal(future.get("SELECT id FROM events").id, 'preserved'); @@ -109,7 +109,7 @@ test('offline command migrates only the supplied fixture root and reports usage const command = new URL('../src/migrate-schema.mjs', import.meta.url).pathname; const migrated = spawnSync(process.execPath, [command, root], { encoding: 'utf8' }); assert.equal(migrated.status, 0, migrated.stderr); - assert.match(migrated.stdout, /bus schema 3e ready/); + assert.match(migrated.stdout, new RegExp(`bus schema ${SCHEMA_VERSION} ready`)); new Store(root).close(); const usage = spawnSync(process.execPath, [command], { encoding: 'utf8' }); assert.equal(usage.status, 2); diff --git a/packages/bus/tests/schema.test.mjs b/packages/bus/tests/schema.test.mjs index ef940a297..52d77fcb9 100644 --- a/packages/bus/tests/schema.test.mjs +++ b/packages/bus/tests/schema.test.mjs @@ -517,7 +517,7 @@ test('v3b prototype refusals, views and append-only mutations', (t) => { const count = (type) => db.prepare('SELECT count(*) n FROM sqlite_master WHERE type = ?').get(type).n; for (const label of refused) assert.ok(tested.has(label), label); // Row 121 (#1615) adds 5 tables and 24 triggers for projects and threads; threads.test.mjs tests them. - assert.equal(count('table') - 1, 14); - assert.equal(count('trigger'), 63); + assert.equal(count('table') - 1, 16); + assert.equal(count('trigger'), 73); assert.equal(count('view'), 5); }); diff --git a/packages/bus/tests/thread-migration.test.mjs b/packages/bus/tests/thread-migration.test.mjs index 47ebfb262..79839c90a 100644 --- a/packages/bus/tests/thread-migration.test.mjs +++ b/packages/bus/tests/thread-migration.test.mjs @@ -7,7 +7,7 @@ import { createHash } from 'node:crypto'; import { spawnSync } from 'node:child_process'; import { DatabaseSync } from 'node:sqlite'; import { pathToFileURL } from 'node:url'; -import { Store, schemaDigest } from '../src/store.mjs'; +import { Store, schemaDigest, SCHEMA_VERSION } from '../src/store.mjs'; import { Broker } from '../src/broker.mjs'; const here = (path) => new URL(path, import.meta.url); @@ -49,7 +49,7 @@ async function database3d(t) { const source = readFileSync(here('../src/store.mjs'), 'utf8'); const pinned = source .replace(/export const SCHEMA_SHA256 = '[a-f0-9]+';/, `export const SCHEMA_SHA256 = '${createHash('sha256').update(ddl3d).digest('hex')}';`) - .replace("export const SCHEMA_VERSION = '3e';", "export const SCHEMA_VERSION = '3d';") + .replace(/export const SCHEMA_VERSION = '[^']+';/, "export const SCHEMA_VERSION = '3d';") .replace(/\}, \{\n {2}from: '3d',[\s\S]*?\}\];\nconst timedTables/, '}];\nconst timedTables'); assert.ok(!pinned.includes('3d-3e'), 'the 3d engine has no 3d→3e step'); writeFileSync(join(moduleRoot, 'src/store.mjs'), pinned); @@ -95,7 +95,7 @@ test('REQ-THREAD-1 REQ-ORG-2: the 3d→3e migration adds the thread tables and l assert.throws(() => new Store(root), /schema-mismatch/); const store = new Store(root, { migrateSchema: true }); t.after(() => store.close()); - assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3e'); + assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, SCHEMA_VERSION); for (const table of ['projects', 'threads', 'thread_claims', 'message_threads', 'thread_opens']) assert.equal(store.get(`SELECT count(*) n FROM ${table}`).n, 0, table); // Parked: the undelivered ones are counted per business and role, and none is changed or given a thread. @@ -155,5 +155,5 @@ test('REQ-THREAD-1: the offline command prints the kept-message counts before th const command = new URL('../src/migrate-schema.mjs', import.meta.url).pathname; const migrated = spawnSync(process.execPath, [command, root], { encoding: 'utf8' }); assert.equal(migrated.status, 0, migrated.stderr); - assert.equal(migrated.stdout, [...REPORT, 'bus schema 3e ready', ''].join('\n')); + assert.equal(migrated.stdout, [...REPORT, `bus schema ${SCHEMA_VERSION} ready`, ''].join('\n')); }); diff --git a/packages/business/src/vocabulary.mjs b/packages/business/src/vocabulary.mjs index c24993250..6b2a987a8 100644 --- a/packages/business/src/vocabulary.mjs +++ b/packages/business/src/vocabulary.mjs @@ -31,6 +31,7 @@ export const ACTIONS = Object.freeze([ // so the grant lives in a role file; role.revoke itself stays gated for every role. "role.end", "organization.change", + "spec.propose", "credential.mint", "spend", "deploy", diff --git a/packages/business/tests/assistant.test.mjs b/packages/business/tests/assistant.test.mjs index 3b9759e96..17f90a684 100644 --- a/packages/business/tests/assistant.test.mjs +++ b/packages/business/tests/assistant.test.mjs @@ -12,7 +12,7 @@ import { businessDoc, REPO_ROLES, systemFor, tmp, writeJson } from "./helpers.mj const APPROVED = Object.freeze({ tools: ["read", "grep", "find", "ls"], network: "api-only", - authority: Object.freeze({ withinRole: Object.freeze(["message.send"]), crossRole: Object.freeze([]) }), + authority: Object.freeze({ withinRole: Object.freeze(["message.send", "spec.propose"]), crossRole: Object.freeze([]) }), credentials: Object.freeze([]), // REQ-ASSIST-2: the user and the chief of staff, both ways. The broker enforces these lists (row 120). messaging: Object.freeze({ @@ -67,15 +67,15 @@ test("the shipped file is exactly the approved list", () => { assert.deepEqual(rest, { roleVersion: 2, name: "assistant", contract: "assistant.md", ...APPROVED }); }); -test("the assistant's authority is message.send within role and nothing else", () => { +test("the assistant holds only message.send and spec.propose within role", () => { const role = loadRole(REPO_ROLES, "assistant"); - assert.deepEqual(role.authority, { withinRole: ["message.send"], crossRole: [] }); + assert.deepEqual(role.authority, { withinRole: ["message.send", "spec.propose"], crossRole: [] }); assert.deepEqual(role.credentials, []); const record = resolved(loadFixture()); - assert.deepEqual(record.limits.authority, { withinRole: ["message.send"], crossRole: [] }); + assert.deepEqual(record.limits.authority, { withinRole: ["message.send", "spec.propose"], crossRole: [] }); assert.deepEqual(record.credentials, {}); for (const action of ACTIONS) { - assert.equal(classify(record, action), action === "message.send" ? "within" : "gated", action); + assert.equal(classify(record, action), ["message.send", "spec.propose"].includes(action) ? "within" : "gated", action); } for (const action of ["task.create", "task.assign", "role.launch"]) assert.equal(classify(record, action), "gated", action); }); diff --git a/packages/cli/src/cli.mjs b/packages/cli/src/cli.mjs index 0a96dcd50..43b280194 100644 --- a/packages/cli/src/cli.mjs +++ b/packages/cli/src/cli.mjs @@ -26,6 +26,8 @@ import { SeatError } from "../../seat/src/seat.mjs"; export const USAGE = `usage: ${LIMITS_USAGE} + mosaic spec [--json] [--business ] + mosaic spec confirm [--yes] [--business ] mosaic inbox [--business ] [--json] [--tester] mosaic decide