diff --git a/BUILD-LOG.md b/BUILD-LOG.md index c5c3738b7..c49c519ff 100644 --- a/BUILD-LOG.md +++ b/BUILD-LOG.md @@ -6118,3 +6118,6 @@ Local commit only; no push or live instance/credential-file access. 2026-11-04 | Codex implementation sub-agent | #803 Console Model proxy in Settings | Before: the owner's native Model proxy page was linked above the Console tree at /proxy. After: Settings links to /settings/model-proxy, whose page links back to Settings; /proxy redirects there only after the existing sign-in, granted-user and named-host fences. The proxy script, fixed API routes, human bus verbs, read and write authority, origin, Fetch Metadata, transport and bounded body checks are unchanged. No secret values are displayed. Tests first: expected red 3 failures (new Settings link, redirect and tester fence), 18 passes, zero skips; final targeted proxy HTTP 13/13, proxy browser 5/5, Settings browser 3/3, whole webui 558/558, zero failures, cancellations or skips. Each test command used a fresh TMPDIR under /mnt/storage/scratch/tmp/XXXXXX; logs /mnt/storage/scratch/tmp/console803-logs/{red,proxy-page,proxy-browser,views,webui}.log. Root dependencies were symlinked and webui dependencies linked per entry without installation. Queue next in this worktree refused the linked checkout; canonical queue next t3 returned nothing, with no queue movement. Local commit only; no push, live configuration or secrets access. 2026-11-04T18:34:22Z | Codex implementation sub-agent, t3/lifecycle-intake-question | #797 / Gitea #1839 PM intake question before/after | Before: base 647626bdd exposes request.question on the bus but no PM harness tool. After: PM with message.send gets intake_question in both harnesses, forwarding only request, revision, op, text and optional bounded choices; the existing broker enforces exact shape, distinct choice keys, authority and replay. A stable caller-supplied op and exact retry use the broker journal, while bus refusals remain errors and lost/unknown outcomes are reported as unknown with no automatic retry. PM duty prose describes status reconciliation and that answers do not approve a PRD. Red evidence: request-tools red-real.log 19/25, with missing tool and unknown-outcome failures; earlier fixture corrections are retained in the logs. Final gates: harness 234/234, bus 1556/1556, business 307/307, all zero failures/skips/cancellations; tests include both harness manifests, unauthorized roles, invalid input, refusal propagation, unknown outcome, stable-op replay and owner Console answer through the real bus. Logs: /mnt/storage/scratch/tmp/W6Jjos/; each invocation used a fresh TMPDIR from /mnt/storage/scratch/tmp/XXXXXX and pipefail. No bus, role JSON, contract or migration change; local commit only, no push. Canonical queue next t3 returned nothing; coordination stays with the controller. +2026-11-04 | GPT-6.1 Terra implementation sub-agent | #797 / Gitea #1839 lifecycle Task 7b WIP | Implemented reviewed-delivery draft, 6b completion transition, owner attachment and legacy completion handling on t3/lifecycle-task-7b; no migration. Red-first logs and focused evidence under /mnt/storage/scratch/tmp/vWMFoL/. Brief trio 22/22, harness 228/228, business 307/307, seat 239/239, webui 558/558, zero skips on those runs. Whole bus 1566/1569: channel-proof freezes the changed webui transport bytes and two Console whitelist pins omit the mandated artifact verb. Each failing file reproduced alone and passed on 647626bdd. Stopped for lead ruling on the security proof baseline; tests and changes remain uncommitted, no push. + +2026-11-04 | GPT-6.1 Terra implementation sub-agent | #797 / Gitea #1839 lifecycle Task 7b | Lead authorized the Console transport proof re-pin after the earlier stop: webui bus.mjs changes only the artifact response cap to 2 MiB, all other Console responses retain 1 MiB, and the focused transport test checks both boundaries and refusal above them. Added owner-only artifact read, reviewed blob and reviewer record.write receipt binding, atomic completion and chief intent, same-artifact duplicate handling, historical complete preservation, safe attachment and evidence panel. Real task.close through the tasks adapter and fake tracker now feeds an end-to-end delivery fixture; coder push_working and reviewer fetch_review use distinct local clones. The downloaded HTML was opened in offline Chromium and matched the reviewed blob and hash. No migration; schema remains 3s. GREEN zero skips: brief 24, bus 1570, harness 228, business 307, seat 239, webui 559; logs /mnt/storage/scratch/tmp/vWMFoL/final-*. Previous bus failure and stop remain recorded above; no push or deployment. diff --git a/docs/SESSIONS.md b/docs/SESSIONS.md index 1925d3b41..17a34c81b 100644 --- a/docs/SESSIONS.md +++ b/docs/SESSIONS.md @@ -2015,3 +2015,7 @@ are never rewritten or removed; corrections are new entries. 2026-11-04 | Codex implementation sub-agent, t3/lifecycle-task-6b-r3 | #797 / Gitea #1839 Task 6b rebase onto 68bef84fa | Kept both append-only log sides, the Task 4 snapshot-counter behavior and the full 6b continuation changes; 3r-3s migration remains byte-identical to 65588327d. Gates, zero skips: bus 1556/1556, harness 228/228, business 307/307, webui 554/554; logs /mnt/storage/scratch/tmp/nj4n7n/gate-*.log. Local commit only, no push. 2026-11-04 | Codex implementation sub-agent, t3/console-803-proxy-settings | #803 Model proxy in Settings | Protected /settings/model-proxy and checked /proxy redirect; unchanged proxy API and authority. Red first; proxy HTTP 13/13, proxy browser 5/5, Settings browser 3/3, whole webui 558/558, zero skips; logs /mnt/storage/scratch/tmp/console803-logs/. Linked-worktree queue refusal; canonical queue next t3 returned nothing. Local commit only, no push or live/secret access. 2026-11-04 | Codex implementation sub-agent, t3/lifecycle-intake-question | #797 / Gitea #1839 PM intake question tool | PM-only typed request.question, strict bounded broker arguments, stable-op replay, refusal and unknown-outcome propagation, owner-answer integration and PM duty prose; red-first; harness 234/234, bus 1556/1556, business 307/307, zero skips; logs /mnt/storage/scratch/tmp/W6Jjos/. Local commit only; no push, bus, role JSON, contract or migration changes. Canonical queue next t3 returned nothing. +2026-11-04 | GPT-6.1 Terra implementation sub-agent, t3/lifecycle-task-7b | #797 / Gitea #1839 lifecycle Task 7b preflight | Stopped before implementation: landed Task 6b advances delivery to complete on task closure and creates a chief send_message continuation before artifact evidence, conflicting with Task 7 delivery and atomic notification requirements; owner direction needed. No migration, tests, commit, push, or product changes. +2026-11-04 | GPT-6.1 Terra implementation sub-agent, t3/lifecycle-task-7b | #797 / Gitea #1839 lifecycle Task 7b WIP | After lead ruling implemented and tested a delivery draft; stopped at frozen Console proof/transport hash conflict, with bus 1566/1569 and other recorded gates green; no migration, no commit, no push. Logs /mnt/storage/scratch/tmp/vWMFoL/. +2026-11-04 | GPT-6.1 Terra implementation sub-agent, t3/lifecycle-task-7b | #797 / Gitea #1839 lifecycle Task 7b | Lead-approved proof re-pin, artifact-only cap, real adapter task.close fixture and completed delivery draft. Brief 24/24, bus 1570/1570, harness 228/228, business 307/307, seat 239/239, webui 559/559; zero skips, no migration; logs /mnt/storage/scratch/tmp/vWMFoL/final-*. Local commit only, no push. +2026-11-04 | GPT-6 Luna implementation sub-agent, t3/lifecycle-task-7b-r2 | #797 / Gitea #1839 lifecycle Task 7b rebase onto 34e9af616 | Cherry-picked 1904c9775 as one local commit; unioned BUILD-LOG and SESSIONS stages 1/2/3 and retained both intake_question and deliver_request in harness tool/bundle expectations. Post-pick checks: webui bus.mjs 593d12b1582a4a3a285e0b89b32d9ee6e3ab726d, channel-proof pin 34fa64ffa17886d86243d7712fdb6f632c22b96412b642d785ddbc05fbd79692. Bus 1570/1570, harness 234/234, business 307/307, seat 239/239, zero skips. WebUI exact full runs: 562/563 with decide-browser timeout, isolated decide-browser 9/9; second run 562 passed/1 cancelled on tester-cli timeout, isolated tester-cli 2/2; final concurrency-4 run 563/563, zero skips. Logs: /mnt/storage/scratch/tmp/FcQIVV/bus.log, /mnt/storage/scratch/tmp/b3p9Ff/harness.log, /mnt/storage/scratch/tmp/YSkAka/business.log, /mnt/storage/scratch/tmp/4Qkhl5/seat.log, /mnt/storage/scratch/tmp/Zcgo8v/webui.log, /mnt/storage/scratch/tmp/n0o7aV/decide-browser.log, /mnt/storage/scratch/tmp/HIdzOF/webui.log, /mnt/storage/scratch/tmp/gBCdZz/tester-cli.log, /mnt/storage/scratch/tmp/GyMQoN/webui.log. No push. diff --git a/packages/bus/src/broker.mjs b/packages/bus/src/broker.mjs index 77f82fce3..6f008f382 100644 --- a/packages/bus/src/broker.mjs +++ b/packages/bus/src/broker.mjs @@ -160,15 +160,15 @@ export const USER_VERBS = Object.freeze(['project.list', 'thread.create', 'threa 'thread.share', 'thread.unshare', 'thread.shares']); // Row 252 (#1753, design sections 2-3): the only verbs a Console owner cap reaches. Every other verb // refuses it human-required before its own checks, and these refuse every other cap. -export const CONSOLE_VERBS = Object.freeze(['decision.preview.console', 'decision.resolve.console', 'prd.revoke.console', 'request.mode.console', 'request.draft.console', +export const CONSOLE_VERBS = Object.freeze(['request.artifact.console', 'decision.preview.console', 'decision.resolve.console', 'prd.revoke.console', 'request.mode.console', 'request.draft.console', // Task 3 (#1839): and the owner's intake controls. The reads and writes are the same lifecycle methods the PM's // unsuffixed verbs reach, with the owner's verified (provider, iss, sub) as the only caller; the PM-only // request.question and the PM's own reads keep their unsuffixed names and refuse a console cap. 'request.get.console', 'request.projects.console', 'request.answer.console', 'request.attach.console', 'request.cancel.console']); // What an owner's console cap may ask of the request lifecycle (a read, the intake controls, and Task 4's mode and draft). -const INTAKE_CONSOLE = Object.freeze(['get', 'answer', 'attach', 'cancel', 'mode', 'draft']); +const INTAKE_CONSOLE = Object.freeze(['artifactConsole', 'get', 'answer', 'attach', 'cancel', 'mode', 'draft']); const REQUEST_VERBS = Object.freeze({ 'request.open': 'open', 'request.get': 'get', 'request.projects': 'projects', 'request.propose': 'propose', - 'prd.submit': 'submit', 'request.advance': 'advance', 'request.question': 'question', 'request.get.console': 'get', 'request.projects.console': 'projects', + 'prd.submit': 'submit', 'request.advance': 'advance', 'request.deliver': 'deliver', 'request.artifact.console': 'artifactConsole', 'request.question': 'question', 'request.get.console': 'get', 'request.projects.console': 'projects', 'request.answer.console': 'answer', 'request.attach.console': 'attach', 'request.cancel.console': 'cancel' }); // Row 275 (193b1b, #1780, row 193 design 4.3 and 9): the user verbs a viewer grant reaches. They // read, so a live grant at any level covers them. thread.create, thread.open and thread.send need a @@ -612,6 +612,7 @@ export class Broker { dataRoot, builtinBinding: builtinFor, progress: state => this.#requestProgress(state), + deliveryEvidence: (state, args) => this.#deliveryEvidence(state, args), continuationContext: (state, target) => this.#continuationContext(state, target), continuationEffect: (state, intent, message) => { if (intent.step !== 'send_message' || state.phase !== 'complete' || !state.thread) return null; @@ -767,6 +768,25 @@ export class Broker { if (!phase) fail('request-evidence-required'); return { phase, tasks, evidence: [...new Set(evidence)] }; } + #deliveryEvidence(state, args) { + const progress = this.#requestProgress(state); + if (state.phase !== 'delivery' || !state.tasks.includes(args.task_ref)) fail('request-evidence-required'); + const rows = this.#store.all('SELECT * FROM events WHERE business=? AND subject=? ORDER BY seq', state.business, args.task_ref) + .map(e => ({ ...e, body: JSON.parse(e.body) })); + const push = rows.findLast(e => e.kind === 'action.allowed' && e.body.action === 'git.push.working'); + const review = rows.findLast(e => e.kind === 'review.requested' && e.seq > push.seq && e.body.commit === push.body.commit && e.body.project === state.project); + const verdict = review && rows.findLast(e => e.kind === 'review.verdict' && e.body.request === review.id && e.body.commit === push.body.commit); + if (!review || !verdict || verdict.id !== args.verdict || verdict.body.verdict !== 'approve' || verdict.actor_role !== review.body.to || verdict.actor_role === push.actor_role) fail('request-evidence-required'); + const receipt = this.#store.all("SELECT * FROM events WHERE business=? AND kind='action.allowed' AND actor_role=? AND seq AND json_extract(body,'$.action')='record.write' ORDER BY seq", state.business, verdict.actor_role, verdict.seq) + .find(e => { const b = JSON.parse(e.body); return e.seq > review.seq && b.project === state.project && b.path === args.verification_record.path && b.commit === args.verification_record.commit; }); + if (!receipt) fail('request-verification-refused'); + const message = this.#store.get('SELECT body FROM messages WHERE business=? AND id=?', state.business, verdict.body.message); + const marker = `Review verdict ${verdict.id} on ${args.task_ref}, commit ${push.body.commit}: approve. A task_close cites this verdict id.\n\n`; + if (!message?.body.startsWith(marker)) fail('request-verification-refused'); + let report; try { report = JSON.parse(message.body.slice(marker.length)); } catch { fail('request-verification-refused'); } + if (!object(report) || Object.keys(report).sort().join(',') !== 'results,verification_record' || !object(report.verification_record) || Object.keys(report.verification_record).sort().join(',') !== 'commit,path' || report.verification_record.path !== args.verification_record.path || report.verification_record.commit !== args.verification_record.commit || typeof report.results !== 'string' || !report.results.trim()) fail('request-verification-refused'); + return { commit: push.body.commit, review_request: review.id, verdict: verdict.id, results: report.results, evidence: progress.evidence, receipt: receipt.id }; + } #requestAuthorize(s, state, operation) { if (!s || s.business !== state.business) fail('request-access-refused'); if (s.reader) fail('read-only'); @@ -779,7 +799,7 @@ export class Broker { if (s.human !== state.owner || s.human !== this.#business(s.business).human) fail('request-access-refused'); return; } - if (['mode', 'draft'].includes(operation)) fail('human-required'); + if (['mode', 'draft', 'artifactConsole'].includes(operation)) fail('human-required'); if (s.human) { this.#human(s); if (s.human !== state.owner || s.human !== this.#business(s.business).human) fail('request-access-refused'); diff --git a/packages/bus/src/request-continuation.mjs b/packages/bus/src/request-continuation.mjs index c0a05d25c..15499da91 100644 --- a/packages/bus/src/request-continuation.mjs +++ b/packages/bus/src/request-continuation.mjs @@ -36,7 +36,7 @@ export function createContinuations({ journal, services }) { return []; } const evidence = state => ({ source_message: state.source_message, decision: state.wait?.kind === 'decision' ? state.wait.subject : null, - question: state.question?.id ?? null, answer: state.question?.answer ?? null, plan: state.plan_digest, spec_commit: state.spec_commit, candidate: state.candidate ? { prd_version: state.candidate.prd_version, records_commit: state.candidate.records_commit, prd_path: state.candidate.prd_path } : null, snapshot: state.snapshot, tasks: state.tasks, events: state.evidence ?? [] }); + question: state.question?.id ?? null, answer: state.question?.answer ?? null, plan: state.plan_digest, spec_commit: state.spec_commit, candidate: state.candidate ? { prd_version: state.candidate.prd_version, records_commit: state.candidate.records_commit, prd_path: state.candidate.prd_path } : null, snapshot: state.snapshot, tasks: state.tasks, delivery: state.delivery_evidence ?? null, events: state.evidence ?? [] }); const intentFor = (state, target, step) => ({ key: digest([state.request, state.revision, target, step]), request: state.request, revision: state.revision, target, step, phase: state.phase, project: state.project, evidence: evidence(state) }); function send(state, intent, context) { @@ -58,9 +58,9 @@ export function createContinuations({ journal, services }) { resolve_decision: 'Read the exact PRD candidate and requirements with intake_status(path), one selected path at a time. Resolve only the cited PRD decision through resolve_decision; ask for changes if evidence is incomplete.', task_create: 'Read list_requirements for this project and snapshot. Check existing task/create receipts before creating or retrying. Create and assign the scoped tasks, request_staff for coder/reviewer sessions, then advance_request.', push_working: 'Check the assigned tasks and existing receipts. Implement the approved requirements, push_working, and request_review for each latest commit.', - review_verdict: 'Fetch each current review request with fetch_review, review the artifacts and return review_verdict against that exact request and commit.', + review_verdict: 'Fetch each current review request with fetch_review, run acceptance checks, write a verification Markdown record containing a JSON object with version 1, task_ref, review_request, commit and results (a nonempty string), then return review_verdict with a JSON body containing exactly verification_record: {path, commit} from write_record and results, matching the record.', advance_request: 'Check the existing task, push and review evidence, then call advance_request at the current intake_status revision. Never claim a success phase.', - task_close: 'Close each task with task_close citing the latest approve verdict. Verify the completed artifacts, then advance_request.', + task_close: 'Close each task with task_close citing the latest approve verdict. Read the review verdict JSON for verification_record and results, then call deliver_request for the reviewed HTML and that reviewer-authored verification record; closing alone does not complete delivery.', send_message: 'Deliver the artifact and task/review evidence through the existing chief → assistant → user path, with send_message in_reply_to the original source_message so it returns to the originating session. Never coordinate the assistant directly with PM or reviewer.' }[intent.step]); return services.continuationMessage(state, intent.target, body, context); } diff --git a/packages/bus/src/request-lifecycle.mjs b/packages/bus/src/request-lifecycle.mjs index c342e27a1..c862d522e 100644 --- a/packages/bus/src/request-lifecycle.mjs +++ b/packages/bus/src/request-lifecycle.mjs @@ -4,6 +4,8 @@ // Later executors must consume these exact immutable bindings, never approvalChoice. import { createContinuations } from './request-continuation.mjs'; import { lstatSync } from 'node:fs'; +import { randomUUID } from 'node:crypto'; +import { basename } from 'node:path'; import { join, dirname } from 'node:path'; import { exact, object, id, key, text, digest, validatePlan, refuse, positive, optionList, QUESTION_PHASES, PICKER_CODES } from './request-store.mjs'; @@ -271,13 +273,14 @@ export function createRequestLifecycle({ journal, services }) { const proposal_digest = digest(args), old = journal.proposal(state.business, state.request, args.op); if (old) { if (old.proposal_digest !== proposal_digest) refuse('request-operation-conflict'); return state; } if (state.revision !== args.revision) refuse('request-revision-conflict'); + if (['cancelled','delivered','complete'].includes(state.phase)) refuse('request-phase-refused'); if (!state.project || args.mode_revision !== state.mode_revision) refuse('request-mode-revision-conflict'); const mode_revision = journal.changeMode({ business: state.business, project: state.project, revision: args.mode_revision, mode: args.mode, op: args.op, request: args.request }); services.catalog.invalidate(state.business, state.project, 'request-mode-changed'); for (const row of journal.listRequests()) { if (row.business !== state.business) continue; const attached = stateOf(row.business, row.request); - if (attached.project === state.project && attached.phase !== 'cancelled') append(attached, 'mode.changed', { mode: args.mode, mode_revision, op: args.op, proposal_digest }); + if (attached.project === state.project && !['cancelled','delivered','complete'].includes(attached.phase)) append(attached, 'mode.changed', { mode: args.mode, mode_revision, op: args.op, proposal_digest }); } return stateOf(state.business, state.request); })); @@ -333,7 +336,7 @@ export function createRequestLifecycle({ journal, services }) { if (old && old.proposal_digest !== proposal_digest) refuse('request-operation-conflict'); return old !== null; }; - const ended = state => { if (['cancelled', 'delivered'].includes(state.phase)) refuse('request-phase-refused'); }; + const ended = state => { if (['cancelled', 'delivered', 'complete'].includes(state.phase)) refuse('request-phase-refused'); }; // The PM's one outstanding question. It is a journal event, not a decision: an answer is text and approves nothing. async function question(identity, args) { exact(args, ['request','revision','op','text'], ['options']); @@ -420,6 +423,7 @@ export function createRequestLifecycle({ journal, services }) { const proposal_digest = digest(args), old = journal.proposal(state.business, state.request, args.op); if (old) { if (old.proposal_digest !== proposal_digest) refuse('request-operation-conflict'); return state; } if (state.revision !== args.revision) refuse('request-revision-conflict'); + if (state.phase === 'delivery') { services.progress(state); refuse('request-delivery-required'); } if (!state.snapshot || !services.progress) refuse('request-evidence-required'); await services.catalog.resolve({ business: state.business, project: state.project, snapshot: state.snapshot }); return journal.transaction(tx => { @@ -433,7 +437,66 @@ export function createRequestLifecycle({ journal, services }) { }); }); } - return Object.freeze({ open, get, projects, propose, submit, question, answer, attach, cancel, advance, modeConsole, + async function deliver(identity, args) { + exact(args, ['request','revision','op','task_ref','verdict','path','verification_record']); + exact(args.verification_record, ['path','commit']); + if (!id(args.request) || !id(args.op) || !id(args.verdict) || !text(args.task_ref, 160) || !text(args.path, 4096) || + !text(args.verification_record.path, 256) || !/^[a-f0-9]{40}$/.test(args.verification_record.commit) || !Number.isSafeInteger(args.revision) || args.revision < 1) refuse('invalid-request'); + return serial(identity.business, args.request, async () => { + let state = stateOf(identity.business, args.request); authorize(identity, state, 'deliver'); + const proposal = digest(args), old = journal.effects(state.business, state.request).filter(e => e.kind === 'delivery'); + const committed = old.find(e => e.stage === 'committed'); + if (committed) { + if (committed.op === args.op && committed.digest !== proposal) refuse('request-operation-conflict'); + const d = committed.result; + if (d.task_ref !== args.task_ref || d.verdict !== args.verdict || d.artifact.path !== args.path || d.verification.record_path !== args.verification_record.path || d.verification.record_commit !== args.verification_record.commit) refuse('request-operation-conflict'); + return d; + } + if (state.revision !== args.revision) refuse('request-revision-conflict'); + if (state.phase !== 'delivery') refuse('request-phase-refused'); + const header = { version: 1, business: state.business, request: state.request, op: args.op, kind: 'delivery', digest: proposal }; + journal.prepareEffect({ ...header, stage: 'prepared', result: null, code: null }); + const evidence = services.deliveryEvidence(state, args); + const [verification, artifact] = await Promise.all([services.readVerification(state, args.verification_record), services.readReviewedArtifact(state, evidence.commit, args.path)]); + let record; try { record = JSON.parse(verification.content); } catch { refuse('request-verification-refused'); } + exact(record, ['version','task_ref','review_request','commit','results'], [], 'request-verification-refused'); + if (verification.commit !== args.verification_record.commit || record.version !== 1 || record.task_ref !== args.task_ref || record.review_request !== evidence.review_request || record.commit !== evidence.commit || record.results !== evidence.results || !text(record.results)) refuse('request-verification-refused'); + if (artifact.mime !== 'text/html') refuse('artifact-type-refused'); + await services.catalog.resolve({ business: state.business, project: state.project, snapshot: state.snapshot }); + const filename = basename(args.path); + if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(filename)) refuse('artifact-path-invalid'); + return journal.transaction(tx => { + state = stateOf(state.business, state.request); authorize(identity, state, 'deliver'); + if (state.revision !== args.revision || state.phase !== 'delivery') refuse('request-revision-conflict'); + const again = services.deliveryEvidence(state, args); + if (digest(again) !== digest(evidence)) refuse('request-evidence-required'); + const value = { version: 1, id: randomUUID(), business: state.business, request: state.request, project: state.project, snapshot: state.snapshot, + task_ref: args.task_ref, commit: evidence.commit, review_request: evidence.review_request, verdict: evidence.verdict, + artifact: { path: args.path, blob: artifact.blob, sha256: artifact.sha256, bytes: artifact.bytes.length, mime: artifact.mime }, + verification: { record_path: args.verification_record.path, record_commit: args.verification_record.commit }, message: null }; + const result = append(state, 'advanced', { op: args.op, proposal_digest: proposal, from: 'delivery', phase: 'complete', tasks: state.tasks, evidence: evidence.evidence }, identity, tx.appendRequest); + continuations.resume({ ...result, delivery: value.id, delivery_evidence: value }); + const notice = journal.effects(state.business, state.request).find(e => e.kind === 'continuation' && e.stage === 'uncertain' && e.result?.intent?.phase === 'complete' && e.result.intent.revision === result.revision && e.result.intent.step === 'send_message'); + if (!notice?.result?.message) refuse('request-notification-unavailable'); + value.message = notice.result.message; + services.record?.(identity, 'request.deliver', result); + journal.finishEffect({ ...header, stage: 'committed', result: value, code: null }); + return value; + }); + }); + } + async function artifactConsole(identity, args) { + exact(args, ['request','delivery']); + if (!id(args.request) || !id(args.delivery)) refuse('invalid-request'); + const state = stateOf(identity.business, args.request); authorize(identity, state, 'artifactConsole'); + const d = state.delivery_evidence; + if (!d || d.id !== args.delivery) refuse('request-not-found'); + const artifact = await services.readReviewedArtifact(state, d.commit, d.artifact.path); + const current = stateOf(identity.business, args.request); authorize(identity, current, 'artifactConsole'); + if (current.delivery !== d.id || artifact.sha256 !== d.artifact.sha256 || artifact.blob !== d.artifact.blob || artifact.bytes.length !== d.artifact.bytes) refuse('request-evidence-required'); + return { mime: d.artifact.mime, filename: basename(d.artifact.path), base64: artifact.bytes.toString('base64'), sha256: artifact.sha256 }; + } + return Object.freeze({ open, get, projects, propose, submit, question, answer, attach, cancel, advance, deliver, artifactConsole, modeConsole, hasWork: () => journal.listRequests().length > 0, launches: continuations.launches, launchResult: continuations.launchResult, manifestNeeded: continuations.manifestNeeded, draftConsole: async (identity, args) => { exact(args, ['request']); if (!id(args.request)) refuse('invalid-request'); diff --git a/packages/bus/src/request-store.mjs b/packages/bus/src/request-store.mjs index bf4b5ac13..c89e1b05a 100644 --- a/packages/bus/src/request-store.mjs +++ b/packages/bus/src/request-store.mjs @@ -214,6 +214,8 @@ export function createRequestStore(store) { const latest = new Map(); for (const launch of launches) if (active.has(launch.key)) latest.set(launch.instance, launch); const last = launches.findLast(launch => launch.code && latest.get(launch.instance) === launch); + const delivery = store.get("SELECT result FROM request_effects WHERE business=? AND request=? AND kind='delivery' AND stage='committed' ORDER BY seq LIMIT 1", business, request); + if (delivery && state.phase === 'complete') { const value = JSON.parse(delivery.result); state.delivery = value.id; state.delivery_evidence = value; } state.launch_refusal = last ? { instance: last.instance, code: last.code, key: last.key } : null; return state; }; diff --git a/packages/bus/src/requirement-catalog.mjs b/packages/bus/src/requirement-catalog.mjs index 3ddf9f0b7..b7821ef36 100644 --- a/packages/bus/src/requirement-catalog.mjs +++ b/packages/bus/src/requirement-catalog.mjs @@ -11,7 +11,7 @@ export function createRequirementCatalog({ journal, readSpec, builtinBinding }) for (const row of journal.listRequests()) { if (row.business !== business) continue; const state = journal.readRequest(business, row.request); - if (state.project === project && (state.candidate || state.snapshot)) append(state, 'prd.invalidated', { code }); + if (state.project === project && !['complete','delivered','cancelled'].includes(state.phase) && (state.candidate || state.snapshot)) append(state, 'prd.invalidated', { code }); } }); } @@ -91,7 +91,7 @@ export function createRequirementCatalog({ journal, readSpec, builtinBinding }) const result = journal.snapshotEvent({ business: identity.business, project: args.project, snapshot: snap.id, kind: 'revoked', cause }); for (const row of journal.listRequests()) { const state = journal.readRequest(row.business, row.request); - if (row.business === identity.business && state.project === args.project && state.snapshot === snap.id) append(state, 'prd.invalidated', { code: 'requirement-snapshot-revoked' }); + if (row.business === identity.business && state.project === args.project && !['complete','delivered','cancelled'].includes(state.phase) && state.snapshot === snap.id) append(state, 'prd.invalidated', { code: 'requirement-snapshot-revoked' }); } return result; }); diff --git a/packages/bus/src/runtime.mjs b/packages/bus/src/runtime.mjs index 409591206..434a50006 100644 --- a/packages/bus/src/runtime.mjs +++ b/packages/bus/src/runtime.mjs @@ -7,6 +7,7 @@ import { fileURLToPath } from 'node:url'; import { Store } from './store.mjs'; import { createRequestStore } from './request-store.mjs'; import { createRequestLifecycle } from './request-lifecycle.mjs'; +import { readReviewedArtifact } from '../../seat/src/artifact.mjs'; import { executeBootstrap } from './request-bootstrap.mjs'; import { hostPreparation } from './request-host.mjs'; import { managedPaths, managedState } from '../../business/src/project-bootstrap.mjs'; @@ -594,7 +595,7 @@ export async function startBroker({ const catalog = createRequirementCatalog({ journal: { ...requestJournal, readCandidate, authority: services.prdAuthority, approval: services.prdApproval }, readSpec: ({ business, project }) => projectModule.readSpec({ business: services.prdBusiness(business), project, dataRoot }), builtinBinding: services.builtinBinding }); - return (requestLifecycle = createRequestLifecycle({ journal: requestJournal, services: { catalog, readCandidate, requestAdmission: state => admission({ business: state.business, project: state.project }), ...(writer ? hostPreparation({ dataRoot, organization: writer, trackers }) : {}), ...requestServices, ...services, + return (requestLifecycle = createRequestLifecycle({ journal: requestJournal, services: { catalog, readCandidate, readReviewedArtifact: (state, commit, path) => readReviewedArtifact({ repo: workingRepo(dataRoot, state.business, state.project), commit, path }), readVerification: (state, record) => projectModule.readProjectFile({ business: services.prdBusiness(state.business), project: state.project, dataRoot, path: record.path, commit: record.commit }), requestAdmission: state => admission({ business: state.business, project: state.project }), ...(writer ? hostPreparation({ dataRoot, organization: writer, trackers }) : {}), ...requestServices, ...services, // The new-project executor needs the organization writer; without one a confirmed selection stays at its setup wait. ...(writer ? { bootstrap: ({ binding, state }) => processing.work(() => executeBootstrap({ binding, owner: state.owner, journal: requestJournal, services: { dataRoot, organization: writer, activate: activateManagedProject, barrier: requestServices.barrier, diff --git a/packages/bus/tests/channel-proof.test.mjs b/packages/bus/tests/channel-proof.test.mjs index 63207b57c..02098242e 100644 --- a/packages/bus/tests/channel-proof.test.mjs +++ b/packages/bus/tests/channel-proof.test.mjs @@ -34,7 +34,8 @@ const baselines = { // Row 301 (#1808, mos-1449): the user transport moved from user-bus.mjs into bus.mjs; humanCall unchanged. // Row 239 (#1745): outcome-unknown-revoked joins OPEN (duckworth-0165 C1), and STATUS gets // revision-conflict-revoked 409 and outcome-unknown-revoked 503; no proof or transport change. - "packages/webui/src/bus.mjs": "4ebf6c2b5d71c23d85cbde83f69aa671058dc2195c9ae4bdda624f6940729d1b", + // #1839: artifact Console replies alone may use 2 MiB; the proof and other limits are unchanged. + "packages/webui/src/bus.mjs": "34fa64ffa17886d86243d7712fdb6f632c22b96412b642d785ddbc05fbd79692", }; const repoFile = path => new URL("../../../" + path, import.meta.url); diff --git a/packages/bus/tests/console-decide.test.mjs b/packages/bus/tests/console-decide.test.mjs index 53ed21516..183fc3758 100644 --- a/packages/bus/tests/console-decide.test.mjs +++ b/packages/bus/tests/console-decide.test.mjs @@ -86,10 +86,10 @@ function setup(t) { return { store, broker, make, caps, call, raise, events, grantEvents, settle, closes, enrolls, grant }; } -// #797 / #1839 Task 3 appends the five request-intake console verbs to Task 4's five and only those: the decision -// pair stays first and unchanged, and no unsuffixed verb is ever a console verb. +// #797 / #1839 adds the owner-only artifact read to the existing decision and request controls; +// no unsuffixed verb is ever a console verb. test('N4: owner Console verbs have an explicit immutable whitelist and exclude decision.resolve', () => { - assert.deepEqual([...CONSOLE_VERBS], ['decision.preview.console', 'decision.resolve.console', 'prd.revoke.console', 'request.mode.console', 'request.draft.console', + assert.deepEqual([...CONSOLE_VERBS], ['request.artifact.console', 'decision.preview.console', 'decision.resolve.console', 'prd.revoke.console', 'request.mode.console', 'request.draft.console', 'request.get.console', 'request.projects.console', 'request.answer.console', 'request.attach.console', 'request.cancel.console']); assert.ok(CONSOLE_VERBS.every(verb => verb.endsWith('.console'))); assert.equal(CONSOLE_VERBS.includes('decision.resolve'), false); diff --git a/packages/bus/tests/delivery-fixture.mjs b/packages/bus/tests/delivery-fixture.mjs new file mode 100644 index 000000000..d2fa6b454 --- /dev/null +++ b/packages/bus/tests/delivery-fixture.mjs @@ -0,0 +1,91 @@ +import { createGitSocket } from '../../cli/src/git-socket.mjs'; +import { pushWorking, fetchReview } from '../../harness/src/git-tools.mjs'; +import { mkdirSync, symlinkSync, writeFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { git } from '../../project/tests/prd-fixture.mjs'; +import assert from 'node:assert/strict'; +import { requestFixture } from './request-fixture.mjs'; +import { scopedFixture } from '../../tasks/tests/scoped-fixture.mjs'; +import { DatabaseSync } from 'node:sqlite'; +import { createRequestStore } from '../src/request-store.mjs'; +const advance = async (f, op = 'next') => { const s = f.journal.readRequest('demo', f.request); return f.call('pm', 'request.advance', { request: f.request, revision: s.revision, op }); }; + +export async function planned(t, threaded = false) { + const f = await requestFixture(t, 'autonomous', null, threaded), sub = await f.submit(); f.approve(sub); await f.activate(sub); + const { createDigest, createMarker } = await import('../src/broker.mjs'); + const s = f.journal.readRequest('demo', f.request), task_ref = 'vikunja:2/41'; + const prepared = { op: 'timer-task', request: f.request, requirement: 'REQ-POMO-1', project_key: 'timer', requirement_snapshot: s.snapshot, + project: 2, creator: 3, decision: null, view: { ids: { todo: 1, review: 2, done: 3 } }, labels: [], relations: [] }; + prepared.body = { title: 'Timer', description: createMarker(prepared) }; + prepared.body_digest = createDigest(prepared.body); + const { receipt } = f.bus.broker.prepareTaskCreate(f.caps.pm, prepared); + let fields = { ...prepared.body, project_id: 2, bucket: 1, done: false, assignees: [], due_date: null, priority: 0 }; + const snapshot = () => ({ task_ref, fields, digest: createDigest(fields), updated: new Date().toISOString() }); + f.bus.broker.recordRecoveredCreate({ receipt, task_ref, snapshot: { ...snapshot(), creator: 3 } }); + f.bus.broker.recordTask({ cap: f.caps.pm, business: 'demo', snapshots: [snapshot()], events: [] }); + await assert.rejects(advance(f), /request-evidence-required/); + fields = { ...fields, assignees: [5] }; + f.bus.broker.recordTask({ cap: f.caps.pm, business: 'demo', snapshots: [snapshot()], events: [{ kind: 'task.assigned', subject: task_ref, body: { role: 'coder', previous: [] } }] }); + const push = commit => f.bus.broker.recordPush(f.caps.coder, { task_ref, project: 'timer', branch: 'timer', ref: 'work/vikunja-2-41', commit, previous: null }); + const review = commit => f.call('coder', 'review.request', { task_ref, commit, to: 'reviewer' }); + // Lightweight continuation tests simulate the tracker receipt; plannedWithRealClose uses the actual adapter. + return { ...f, task_ref, push, review, closeTask: verdict => { + fields = { ...fields, done: true, bucket: 3 }; + f.bus.broker.recordTask({ cap: f.caps.pm, business: 'demo', snapshots: [snapshot()], events: [{ kind: 'task.closed', subject: task_ref, body: { verdict } }] }); + } }; +} + + +async function plannedWithRealClose(t) { + const f = await scopedFixture(t), product = await f.product('timer'); + const task = await f.create(product.args), task_ref = task.task_ref; + await f.bus.broker.requestTask(f.caps.pm, { verb: 'task.assign', args: { task_ref, role: 'coder' } }, f.adapter.handle); + const db = new DatabaseSync(join(f.f.dataRoot, 'bus/bus.sqlite'), { readOnly: true }); t.after(() => db.close()); + const store = { get: (sql, ...a) => db.prepare(sql).get(...a), all: (sql, ...a) => db.prepare(sql).all(...a) }; + return { ...f, request: product.request, task_ref, store, journal: createRequestStore(store), + push: commit => f.bus.broker.recordPush(f.caps.coder, { task_ref, project: 'timer', branch: 'timer', ref: 'work/vikunja-2-41', commit, previous: null }), + review: commit => f.call('coder', 'review.request', { task_ref, commit, to: 'reviewer' }), + closeTask: verdict => f.bus.broker.requestTask(f.caps.pm, { verb: 'task.close', args: { task_ref, verdict } }, f.adapter.handle) }; +} + +export async function ready(t, options = {}) { + const f = options.realClose ? await plannedWithRealClose(t) : await planned(t, true); + const advance = async op => { const s = f.journal.readRequest('demo', f.request); return f.call('pm', 'request.advance', { request: f.request, revision: s.revision, op }); }; + await advance('start'); + const code = join(f.f.dataRoot, 'products/demo/timer/code'); + const sandbox = join(f.f.dataRoot, 'test-workspaces'); + const coder = join(sandbox, 'coder'), reviewer = join(sandbox, 'reviewer'), temp = join(sandbox, 'tmp'); + for (const dir of [coder, reviewer, temp, join(f.f.dataRoot, 'bus-host')]) mkdirSync(dir, { recursive: true }); + git(coder, 'clone', '-q', code, 'timer'); git(reviewer, 'clone', '-q', code, 'timer'); + const clone = join(coder, 'timer'); git(clone, 'checkout', '-qb', 'feat'); + const bytes = Buffer.from(`
No current PRD candidate or approved snapshot. Waiting for a PRD submission.
'; const c = m.candidate; let h = `Product PRD ${txt(c.prd_version)}
-Records commit: ${txt(c.records_commit)}
PRD: ${txt(c.prd_path)}
PRD blob: ${txt(c.prd_blob)}
Confirmed intent commit: ${txt(c.spec_commit)}
Mode revision: ${txt(c.mode_revision)}
Records commit: ${txt(c.records_commit)}
PRD: ${txt(c.prd_path)}
PRD blob: ${txt(c.prd_blob)}
Confirmed intent commit: ${txt(c.spec_commit)}
Mode revision: ${txt(c.mode_revision)}
${txt(m.prd)}${txt(r.id)} — ${txt(r.title)}
${txt(c.requirements[i].path)}
Blob: ${txt(c.requirements[i].blob)}
${txt(r.text)}Request Phase: ${txt(s.phase)}${s.mode ? ` Mode: ${txt(s.mode)}` : ''}
`; if (s.project) body += `Project: ${txt(s.project)}${s.phase === 'cancelled' ? ' (kept)' : ''}
Completed before delivery evidence.
'; + const d = s.delivery_evidence; + if (s.phase === 'complete' && d && d.id === s.delivery && d.request === s.request && d.artifact && d.verification) { + body += `Reviewed delivery — not landed or deployed.
+ +Approved snapshot: ${txt(d.snapshot)}
Task: ${txt(d.task_ref)}
+ Code commit: ${txt(d.commit)}
Review request: ${txt(d.review_request)}
Verdict: ${txt(d.verdict)}
+ Verification record: ${txt(d.verification.record_path)} at ${txt(d.verification.record_commit)}
+ Blob: ${txt(d.artifact.blob)}
SHA-256: ${txt(d.artifact.sha256)}