Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/CHECKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ requires Bun 1.4 or later. See [Live review](LIVE-REVIEW.md).
| `JOB_BINDING_INVALID` | The private sibling/outbox is tracked or not effectively ignored, the binding is malformed, unavailable or mismatched, or a job command has invalid arguments. Restore effective private ignores. Restore the matching writer-owned binding through `job open`, then retry publication into the existing job. |
| `JOB_PRIVATE_STORAGE_INVALID` | Private publication storage has unsafe permissions, type or symlinks. Restore owner-only real directories and regular files. |
| `JOB_OUTBOX_INVALID` | A private publication receipt is absent, malformed or unreadable. Restore its writer-owned bytes before reconciling. The check reports this as a HOLE. |
| `JOB_ASK_PENDING` | A bound writer would publish a different target while the job has an owner ask with no ingested act. The message names the job and pending asks. Have the owner finish those asks, run `job acts` and ingest the acts with the printed commands, then retry the writer to publish into the existing job. Refusal preserves `project.json` and the job state byte-identically. |
| `JOB_ASK_PENDING` | A bound writer, or `job open --question`/`--plan`, would publish a different target while the job has an owner ask with no ingested act. Publishing supersedes the open ask, so a second interview question waits for the first. The message names the job and pending asks. Have the owner finish those asks, run `job acts <dir> --wait` and ingest the acts with the printed commands, then retry the command to publish into the existing job. Refusal preserves `project.json` and the job state byte-identically. |
| `JOB_PUBLICATION_ASK_REQUIRED` | A bound version writer would replace an open publication with no owner ask. Keep the open page and use `job open` when the next review is ready. The refusal leaves the record and outbox unchanged. |
| `JOB_ASK_REFUSED` | A publication is acknowledged, but Review refused the ask for one of its declared subjects. The message names each subject and Review's code. The publication is not pending. Restore the published record bytes and run `job open` to ask again. |
| `JOB_DRAFT_UNKNOWN` | `job open --draft <id>` names a draft the record does not hold. Record the draft with `draft-rig` or name a recorded draft. |
Expand Down
16 changes: 10 additions & 6 deletions docs/LIVE-REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ and leaves the open page and outbox unchanged. Its text output identifies the
missing evidence. Run the preparation moves shown by `next` and then
`job open --draft <id>` to show the prepared draft in the same job.

A bound writer that reports `JOB_ASK_PENDING` needs the owner to finish the
current asks. Run `job acts`, ingest with the printed commands, then retry
the writer to publish into the existing job.
A bound writer or `job open --question`/`--plan` that reports
`JOB_ASK_PENDING` needs the owner to finish the current asks. Run
`job acts --wait`, ingest with the printed commands, then retry the command
to publish into the existing job.

A bound version writer refuses with `JOB_PUBLICATION_ASK_REQUIRED` before
committing if its candidate would replace an open page without an owner ask.
Expand Down Expand Up @@ -421,9 +422,12 @@ Review's code. Run `job open` to retry the ask.
| `plan-approved`, `rigging-interview`, `post-interview` | record plan | `job open --plan` in the approval stage |
| `interview` | record plan, using release-pinned Review 4.9.1 with the interview carrier ([Review #803](https://github.com/rig-c/review/pull/803), issue #800) | `job open --plan` after `interview --check` passes and the displayed plan has steps; ingest `signoff interview --from-review <actId>`, then `advance plan-approved` |

Interview picks use `job open --question <id>`. After ingesting every pick,
run `interview --check`, then `job open --plan` for the interview signature.
This record route is supported by release-pinned
Interview picks use `job open --question <id>`, one question at a time: a
new publication supersedes the open ask, so publish one question, run
`job acts <dir> --json --wait`, ingest its act, then publish the next. A
second `--question` while an ask is open refuses `JOB_ASK_PENDING`. After
ingesting every pick, run `interview --check`, then `job open --plan` for
the interview signature. This record route is supported by release-pinned
[Review 4.9.1](https://github.com/rig-c/review/tree/v4.9.1), including the
[Review #803](https://github.com/rig-c/review/pull/803) carrier (issue #800).
The record subject is `plan`, with non-empty
Expand Down
42 changes: 37 additions & 5 deletions src/job-acts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/** Writer routing for finalized acts. No event transport or automatic ingestion. */
import type { ActV3, JobEventV3, JobOwnerHost, JobSelector, PendingAskV3, SourceV3 } from '@rig-c/review/job-host';
import type { ActV3, JobEventV3, JobOwnerHost, JobSelector, PendingAskV3, RecordResult, SourceV3 } from '@rig-c/review/job-host';
import { isDeepStrictEqual } from 'node:util';
import { asArray, collectItems, collectSignoffs, isObject, loadCollection, type Finding } from './check.ts';
import { optionFile } from './choices.ts';
import { existsSync, readFileSync } from './check-reads.ts';
import { join } from 'node:path';
import { recordedPartsVerdict } from './parts-verdict-record.ts';
Expand Down Expand Up @@ -278,6 +279,15 @@ function actMatchesAsk(act: ActV3, ask: PendingAskV3): boolean {
}
}

/** A publication target: a package selector, or a record result (`--question` option set or `--plan`). */
export type JobAskTarget = JobSelector | RecordResult;

function sameTarget(source: SourceV3, target: JobAskTarget): boolean {
if ('selector' in source && source.selector) return isDeepStrictEqual(source.selector, target);
if ('selection' in source && source.selection) return isDeepStrictEqual(source.selection, target);
return false;
}

function sourceTargetInfo(source: SourceV3): { label: string; selector: JobSelector | null; version: number | null } {
if ('selector' in source && source.selector) {
const selector = source.selector;
Expand Down Expand Up @@ -328,12 +338,34 @@ function signoffSettlesAsk(project: JsonObject, ask: PendingAskV3): boolean {
});
}

/**
* An owner-chat interview answer (`interview-answer --owner-chat`) creates no Review act.
* It settles the interview-picks ask when the question's current answer is bound to the
* same option set the ask published: path and sha256, and the set id they resolve to.
*/
function ownerChatAnswerSettlesAsk(project: JsonObject, root: string, ask: PendingAskV3): boolean {
if (ask.status !== 'pending' || ask.subject.kind !== 'interview-picks') return false;
const source = ask.source;
if (!('selection' in source) || source.selection?.kind !== 'option-set' || !source.optionSet || !source.optionSetFile) return false;
const { questionId, setId } = source.selection;
if (ask.subject.questionId !== questionId || ask.subject.setId !== setId || source.optionSet.id !== setId) return false;
let item: ReturnType<typeof collectItems>[number] | undefined;
try { item = collectItems(project, { collection: loadCollection(root, project) }).find(candidate => candidate.id === questionId); }
catch { return false; }
if (!item || (item.state.state !== 'user' && item.state.state !== 'delegated') || item.state.answer !== item.raw) return false;
const answer = item.state.answer;
if (answer.source !== OWNER_CHAT_SOURCE || !isObject(answer.choice)) return false;
const binding = answer.choice.set;
if (!isObject(binding) || binding.path !== source.optionSetFile.path || binding.sha256 !== source.optionSet.sha256) return false;
try { return optionFile(root, binding).set.id === setId; } catch { return false; }
}

export function pendingJobAsksForTarget(
project: JsonObject,
asks: readonly PendingAskV3[],
acts: readonly ActV3[],
root: string,
target: JobSelector,
target: JobAskTarget,
): PendingTargetAsk[] {
// Retired reopens stay visible in job acts and job close, but cannot gate a new target.
const actionableAsks = asks.filter(ask => ask.subject.kind !== 'reopen');
Expand All @@ -345,16 +377,16 @@ export function pendingJobAsksForTarget(
for (const ask of actionableAsks) {
if (ingestedActs.some(act => actMatchesAsk(act, ask))) continue;
const info = sourceTargetInfo(ask.source);
if (info.selector && isDeepStrictEqual(info.selector, target)) continue;
if (sameTarget(ask.source, target)) continue;
const hasUnIngestedAct = actionableActs.some(act => unIngestedIds.has(act.actId) && actMatchesAsk(act, ask));
if (!hasUnIngestedAct && signoffSettlesAsk(project, ask)) continue;
if (!hasUnIngestedAct && (signoffSettlesAsk(project, ask) || ownerChatAnswerSettlesAsk(project, root, ask))) continue;
if (!hasUnIngestedAct && info.selector?.kind === 'draft' && target.kind === 'draft') continue;
pending.push({ label: `${askSubjectText(ask.subject)} on ${info.label}`, version: info.version });
}
for (const act of actionableActs) {
if (!unIngestedIds.has(act.actId) || actionableAsks.some(ask => actMatchesAsk(act, ask))) continue;
const info = sourceTargetInfo(act.source);
if (info.selector && isDeepStrictEqual(info.selector, target)) continue;
if (sameTarget(act.source, target)) continue;
pending.push({ label: `${act.kind} (${act.actId}) on ${info.label}`, version: info.version });
}
return pending;
Expand Down
44 changes: 27 additions & 17 deletions src/job-close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type JobSelector,
} from '@rig-c/review/job-host';
import { asArray, checkProject } from './check.ts';
import { pendingJobActs, pendingJobAsksForTarget, readHostActs, readHostActsAndAsks } from './job-acts.ts';
import { pendingJobActs, pendingJobAsksForTarget, readHostActs, readHostActsAndAsks, shellWord, type JobAskTarget } from './job-acts.ts';
import {
acquireJobLock,
JOB_BINDING_FILE,
Expand Down Expand Up @@ -188,7 +188,7 @@ export async function attachCreateJobForClose(

export async function assertNoPendingJobAsk(
root: string,
target: JobSelector,
target: JobAskTarget,
startHost: (options: JobHostOptions) => Promise<JobOwnerHost> = startJobHost,
): Promise<string | null> {
root = realpathSync(root);
Expand All @@ -204,26 +204,36 @@ export async function assertNoPendingJobAsk(
throw error;
}
try {
const project = JSON.parse(readFileSync(join(root, 'project.json'), 'utf8')) as JsonObject;
const { head, asks, acts } = await readHostActsAndAsks(host);
const pending = pendingJobAsksForTarget(project, asks, acts, root, target);
if (pending.length > 0) {
const listed = pending.map(item => item.label).join('; ');
const version = pending.find(item => item.version !== null)?.version ?? null;
const ingest = version === null || pending.some(item => item.version === null)
? 'have the owner respond in Review, run rig-create job acts, and run the printed ingest commands'
: `have the owner give the verdict in Review, run rig-create job acts, and ingest with rig-create review ${version} --from-review <actId> (review <n> --from-review <actId>)`;
refuse(
'JOB_ASK_PENDING',
`project.json: bound job ${binding.jobId} holds pending owner ask(s) ${listed} with no ingested act; ${ingest}; re-run this command to publish into the existing job`,
);
}
return head;
return await refusePendingJobAsks(root, binding.jobId, host, target);
} finally {
host.stop();
}
}

/**
* Publishing supersedes every pending ask on the job, and an answer to a superseded ask
* never becomes an act. Refuse JOB_ASK_PENDING while an ask for another target is still
* open, or answered but not ingested. Returns the job's head publication.
*/
export async function refusePendingJobAsks(root: string, jobId: string, host: JobOwnerHost, target: JobAskTarget): Promise<string | null> {
const project = JSON.parse(readFileSync(join(root, 'project.json'), 'utf8')) as JsonObject;
const { head, asks, acts } = await readHostActsAndAsks(host);
const pending = pendingJobAsksForTarget(project, asks, acts, root, target);
if (pending.length > 0) {
const listed = pending.map(item => item.label).join('; ');
const version = pending.find(item => item.version !== null)?.version ?? null;
const wait = `rig-create job acts ${shellWord(root)} --wait`;
const ingest = version === null || pending.some(item => item.version === null)
? `have the owner respond in Review, run ${wait}, and run the printed ingest commands`
: `have the owner give the verdict in Review, run ${wait}, and ingest with rig-create review ${version} --from-review <actId> (review <n> --from-review <actId>)`;
refuse(
'JOB_ASK_PENDING',
`project.json: bound job ${jobId} holds pending owner ask(s) ${listed} with no ingested act; ${ingest}; re-run this command to publish into the existing job`,
);
}
return head;
}

export async function closeCreateJob(
root: string,
startHost: (options: JobHostOptions) => Promise<JobOwnerHost> = startJobHost,
Expand Down
6 changes: 4 additions & 2 deletions src/job-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Refusal, refuse } from './refusal.ts';
import { liveManifestPath, draftPackageIdentity, inspectDraftPublication, currentJobIdentity, partsEnumerator, prepareDraftManifest, prepareLiveManifest, publicationFile, publicationSelector, publishedDraft, readPublished, readRecordPublished, riggingDraftPartsChange } from './job-publication.ts';
import { acknowledgePublication, acquireJobLock, assertJobIdentity, enqueuePublication, ensureJobPrivateIgnores, failPublication, JOB_BINDING_FILE, jobHash, jobHostStateRoot, pendingPublications, privateDirectory, publicationVersionHash, readAcknowledgedPublication, readWriterBinding, reconcilePublication, refuseJobIdentityMismatch, writePrivateJson, isRecordResult, type PublicationResult, type JobIdentity, type PendingPublication, type WriterBinding, type PublicationSubject } from './job-outbox.ts';
import { draftPublicationResult } from './job-writer.ts';
import { attachCreateJobForClose } from './job-close.ts';
import { attachCreateJobForClose, refusePendingJobAsks } from './job-close.ts';
import { agentCall, ingestedJobActs, ingestedSummary, jobEvents, pendingJobActs, readHostActsAndAsks, shellWord, type AgentReply, type IngestedJobAct, type PendingJobAct } from './job-acts.ts';
import { checkReviewPackages } from './review-package.ts';
import { reviewVerdictSignable } from './signable.ts';
Expand Down Expand Up @@ -503,7 +503,7 @@ function selectorLabel(selector: JobSelector): string {
}

/** Resolve only an explicitly requested current record subject, before opening a host. */
export function requestedRecordResult(root: string, question?: string, plan = false, now = Date.now()): PublicationResult | undefined {
export function requestedRecordResult(root: string, question?: string, plan = false, now = Date.now()): RecordPublicationRequestResult | undefined {
return requestedRecordPublication(root, question, plan, now)?.result;
}

Expand Down Expand Up @@ -550,6 +550,8 @@ export async function openRecordPublication(root: string, host: JobOwnerHost, qu
} else {
const binding = readWriterBinding(root);
if (!binding || binding.jobId !== host.session.jobId) refuse('JOB_BINDING_INVALID', 'project.json: open the writer-owned job before publishing');
// A new publication supersedes the job's pending asks: one question at a time (#737).
await refusePendingJobAsks(root, binding.jobId, host, result);
enqueuePublication(root, binding, result);
({ outcomes } = await reconcileLocked(root, publishPending));
}
Expand Down
4 changes: 3 additions & 1 deletion src/job-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ async function run(): Promise<void> {
case 'close': await closeCreateJob(root, undefined, input.retireRefused, input.discardActs, input.now); console.log('job: closed'); break;
case 'open': {
if (!input.reviewer || !input.role) refuse('JOB_BINDING_INVALID', 'project.json: job open needs --reviewer and --role owner|delegate');
requestedRecordResult(root, input.question, input.plan, input.now);
const record = requestedRecordResult(root, input.question, input.plan, input.now);
// Refuse before attaching or writing; openRecordPublication repeats it under the job lock (#737).
if (record) await assertNoPendingJobAsk(root, record);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Recognize relayed interview answers before refusing the next ask

If the owner answers a published question through the supported interview-answer --owner-chat route, opening the next question now refuses JOB_ASK_PENDING even though the first answer is recorded. interviewAnswerCommand removes pending_options but creates no Review act for a chat answer, while pendingJobAsksForTarget recognizes separately recorded answers only for signoffs (signoffSettlesAsk), not interview picks. Consequently, the previous interview ask remains a blocker, and the printed instruction to ingest it cannot work: the recorded answer has already changed the project hash and removed the pending set required for ingestion. Recognize a valid owner-chat answer bound to the published option set before blocking subsequent question or plan publication.

AGENTS.md reference: AGENTS.md:L23-L29

Useful? React with 👍 / 👎.

const rig = assertRequestedRig(root, input.rig, input.draft);
const { bytes, draftId } = assertRequestedDraft(root, input.draft, input.now);
if (rig || draftId !== undefined) requireOwnerLanguage(JSON.parse(bytes.toString('utf8')) as JsonObject);
Expand Down
18 changes: 14 additions & 4 deletions src/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,9 @@ function ownerChatSignoffCommand(dir: string, project: JsonObject, act: NextRevi
return `rig-create ${writer} ${shellWord(dir)}${version} ${OWNER_CHAT_COMMAND_FLAGS}`;
}

/** The person acts in Review; the agent only hosts and ingests its exported act. */
function reviewCommands(dir: string, project: JsonObject, move: NextMove): NextMove[] {
/** The person acts in Review; the agent only hosts and ingests its exported act.
* A job holds one open interview question: `asked` names the earlier question in this report. */
function reviewCommands(dir: string, project: JsonObject, move: NextMove, asked: { question?: string } = {}): NextMove[] {
const act = move.review_act;
if (move.role !== 'human' || move.unanswered_by_record || move.field === 'pauses' || !act) return [move];
let selector: string;
Expand Down Expand Up @@ -500,9 +501,17 @@ function reviewCommands(dir: string, project: JsonObject, move: NextMove): NextM
} catch { /* The check's named option-file refusal supplies the repair route. */ }
}
}
let publish = 'publish this Review page; run the first open in the background and share its URL once; later opens publish into the running host and exit';
if (act.kind === 'interview-picks' && act.question_id) {
const earlier = asked.question;
asked.question ??= act.question_id;
publish = earlier === undefined
? `${publish}; one question at a time: publish it, wait with job acts --json --wait, ingest, then publish the next question`
: `only after the ${earlier} act is ingested: one question at a time, so publish this one next, wait with job acts --json --wait and ingest (an open earlier question refuses JOB_ASK_PENDING)`;
}
return [
...chatMoves,
agent(`rig-create job open ${root} ${selector} --reviewer '<reviewer>' --role owner`, 'publish this Review page; run the first open in the background and share its URL once; later opens publish into the running host and exit'),
agent(`rig-create job open ${root} ${selector} --reviewer '<reviewer>' --role owner`, publish),
move,
agent(`rig-create job acts ${root} --json --wait`, `wait in the background for the person to submit in Review, then use the matching actId below${act.kind === 'parts-verdict' ? '; approval also records the prepared parts-review signature' : act.stage === 'parts-review' ? '; run its reported legacy signoff preconditions before ingestion' : ''}`),
agent(`rig-create ${writer} ${root} --from-review '<actId>'`, 'ingest the matching exported Review act; never supply the human answer or words'),
Expand Down Expand Up @@ -2231,11 +2240,12 @@ export function nextProject(projectDirArg: string, now: number = Date.now()): Ne
});
}

const asked: { question?: string } = {};
const runnableMoves = moves.flatMap(move => {
if (move.review_act && move.review_act.stage !== effectiveStage) return [move];
if (move.review_act?.stage === 'direction-review' && move.review_act.kind === 'signoff'
&& moves.some(other => other.review_act?.stage === 'direction-review' && other.review_act.kind === 'review-verdict')) return [move];
return reviewCommands(dir, project, move);
return reviewCommands(dir, project, move, asked);
});

return {
Expand Down
Loading
Loading