@akagilnc/pi-workflow-roles 0.1.4526 → 0.1.4586

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17694,7 +17694,7 @@ async function listPullRequestNumbersByCommit(runner, input) {
17694
17694
  function createGhApiRunner(options = {}) {
17695
17695
  const spawnImpl = options.spawnImpl ?? spawn2;
17696
17696
  return async (args, runOptions = {}) => {
17697
- return await new Promise((resolve10, reject) => {
17697
+ return await new Promise((resolve11, reject) => {
17698
17698
  const signal = runOptions.signal;
17699
17699
  if (signal?.aborted) {
17700
17700
  reject(signal.reason ?? new Error("aborted"));
@@ -17767,11 +17767,11 @@ function createGhApiRunner(options = {}) {
17767
17767
  const value = line2.slice(idx + 1).trim();
17768
17768
  headers[name] = value;
17769
17769
  }
17770
- resolve10({ status, headers, bodyText });
17770
+ resolve11({ status, headers, bodyText });
17771
17771
  return;
17772
17772
  }
17773
17773
  if (code === 0) {
17774
- resolve10({ status: 200, headers: {}, bodyText: stdout });
17774
+ resolve11({ status: 200, headers: {}, bodyText: stdout });
17775
17775
  return;
17776
17776
  }
17777
17777
  const failure = new Error(
@@ -20096,12 +20096,12 @@ var init_option_definitions = __esm({
20096
20096
  canonical: "--lens",
20097
20097
  aliases: [],
20098
20098
  valueMetavar: "completeness|correctness",
20099
- required: true,
20099
+ required: false,
20100
20100
  repeatable: false,
20101
20101
  form: "option",
20102
20102
  description: {
20103
- en: "Required single review lens: completeness or correctness (no default).",
20104
- zh: "\u5FC5\u586B\u5355 lens\uFF1Acompleteness \u6216 correctness\uFF08\u65E0\u9ED8\u8BA4\u503C\uFF09\u3002"
20103
+ en: "Optional single-lens override: completeness or correctness; omitted runs both in parallel.",
20104
+ zh: "\u53EF\u9009\u5355 lens \u8986\u76D6\uFF1Acompleteness \u6216 correctness\uFF1B\u7701\u7565\u65F6\u5E76\u884C\u8FD0\u884C\u4E24\u8F74\u3002"
20105
20105
  }
20106
20106
  },
20107
20107
  {
@@ -20459,9 +20459,9 @@ var init_option_definitions = __esm({
20459
20459
  },
20460
20460
  reviewer: {
20461
20461
  command: "reviewer",
20462
- summary: "Fixed-target single-lens review (completeness or correctness).",
20462
+ summary: "Fixed-target parallel two-lens review, with an optional single-lens override.",
20463
20463
  usage: [
20464
- "ak-role reviewer --base <revision> --lens completeness|correctness --authority-ref <ref> [options] <instruction>"
20464
+ "ak-role reviewer --base <revision> [--lens completeness|correctness] --authority-ref <ref> [options] <instruction>"
20465
20465
  ],
20466
20466
  examples: [
20467
20467
  'ak-role reviewer --base main --lens completeness --authority-ref docs/adr/0001.md "Review the branch."',
@@ -22594,7 +22594,7 @@ function parseReviewerArgv(args) {
22594
22594
  instruction: positional.join(" "),
22595
22595
  attachmentPaths,
22596
22596
  baseRevision,
22597
- lens,
22597
+ ...lens === void 0 ? {} : { lens },
22598
22598
  authorityRefs,
22599
22599
  ...project === void 0 ? {} : { project }
22600
22600
  };
@@ -22643,6 +22643,7 @@ async function admitReviewerInvocation(options) {
22643
22643
  baseRevision,
22644
22644
  lens,
22645
22645
  authorityRefs: [...authorityRefs],
22646
+ ...options.correlationId === void 0 ? {} : { correlationId: options.correlationId },
22646
22647
  attachments: attachments.map((a) => ({
22647
22648
  provenancePath: a.provenancePath,
22648
22649
  frozenPath: a.frozenPath,
@@ -22670,7 +22671,8 @@ async function admitReviewerInvocation(options) {
22670
22671
  admittedRequestPath,
22671
22672
  baseRevision,
22672
22673
  lens,
22673
- authorityRefs
22674
+ authorityRefs,
22675
+ ...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
22674
22676
  };
22675
22677
  }
22676
22678
  function buildReviewerSkillArgProjection(admitted) {
@@ -22887,11 +22889,11 @@ function parseAnalystCohortIssueToken(raw, flag) {
22887
22889
  `${flag} requires a comma-separated list of N or book:N`
22888
22890
  );
22889
22891
  }
22890
- const sep5 = trimmed.lastIndexOf(":");
22891
- if (sep5 > 0) {
22892
- const rhs = trimmed.slice(sep5 + 1);
22892
+ const sep6 = trimmed.lastIndexOf(":");
22893
+ if (sep6 > 0) {
22894
+ const rhs = trimmed.slice(sep6 + 1);
22893
22895
  if (ANALYST_TICKET_NUMBER_PATTERN.test(rhs)) {
22894
- const bookKey = trimmed.slice(0, sep5);
22896
+ const bookKey = trimmed.slice(0, sep6);
22895
22897
  if (bookKey.trim() === "") {
22896
22898
  throw new CliUsageError(
22897
22899
  `${flag} book:N requires a non-empty book key, got ${raw}`
@@ -24108,8 +24110,8 @@ async function readRunTerminalArtifact(runDirectory) {
24108
24110
  const read = await readTerminalArtifactAtPath(path, file);
24109
24111
  if (read !== void 0) return read;
24110
24112
  }
24111
- for (const relative3 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
24112
- const path = join20(runDirectory, relative3);
24113
+ for (const relative4 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
24114
+ const path = join20(runDirectory, relative4);
24113
24115
  const read = await readTerminalArtifactAtPath(path, "error.json");
24114
24116
  if (read !== void 0) return read;
24115
24117
  }
@@ -24990,6 +24992,15 @@ function formatTerminalResult(result2) {
24990
24992
  );
24991
24993
  }
24992
24994
  }
24995
+ if (result2.reviewerChildOutcomes !== void 0) {
24996
+ for (const axis of ["completeness", "correctness"]) {
24997
+ const child = result2.reviewerChildOutcomes[axis];
24998
+ lines.push(`reviewer-child ${axis} ${child.exitCode}`);
24999
+ if (child.stderr !== void 0 && child.stderr !== "") {
25000
+ lines.push(`reviewer-child-diagnostic ${axis} ${encodeTerminalField(child.stderr)}`);
25001
+ }
25002
+ }
25003
+ }
24993
25004
  if (result2.resume !== void 0) {
24994
25005
  lines.push(`resume ${encodeTerminalField(result2.resume.command)}`);
24995
25006
  } else if (result2.runId !== void 0) {
@@ -27450,10 +27461,10 @@ function presentFailureTerminal(terminal, io) {
27450
27461
  }
27451
27462
  function defaultNavigatorGraceSleep() {
27452
27463
  let timer;
27453
- const sleep2 = ((ms) => new Promise((resolve10) => {
27464
+ const sleep2 = ((ms) => new Promise((resolve11) => {
27454
27465
  timer = setTimeout(() => {
27455
27466
  timer = void 0;
27456
- resolve10();
27467
+ resolve11();
27457
27468
  }, ms);
27458
27469
  }));
27459
27470
  sleep2.cancel = () => {
@@ -27465,7 +27476,7 @@ function defaultNavigatorGraceSleep() {
27465
27476
  return sleep2;
27466
27477
  }
27467
27478
  function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep2 = defaultNavigatorGraceSleep()) {
27468
- return new Promise((resolve10, reject) => {
27479
+ return new Promise((resolve11, reject) => {
27469
27480
  let settled = false;
27470
27481
  const finish = (action) => {
27471
27482
  if (settled) return;
@@ -27474,11 +27485,11 @@ function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep2
27474
27485
  action();
27475
27486
  };
27476
27487
  void work.then(
27477
- (value) => finish(() => resolve10({ status: "done", value })),
27488
+ (value) => finish(() => resolve11({ status: "done", value })),
27478
27489
  (error) => finish(() => reject(error))
27479
27490
  );
27480
27491
  void sleep2(graceMs).then(() => {
27481
- finish(() => resolve10({ status: "timeout" }));
27492
+ finish(() => resolve11({ status: "timeout" }));
27482
27493
  });
27483
27494
  });
27484
27495
  }
@@ -27547,7 +27558,7 @@ var init_settlement = __esm({
27547
27558
 
27548
27559
  // src/public-cli/turn-request.ts
27549
27560
  function projectRoleTurnRequest(admitted, roleDetails, options) {
27550
- const cwd = admitted.projectRoot ?? admitted.repoRoot ?? admitted.cwd;
27561
+ const cwd = options.cwd ?? admitted.projectRoot ?? admitted.repoRoot ?? admitted.cwd;
27551
27562
  if (cwd === void 0) throw new Error("admitted invocation missing working directory");
27552
27563
  if (admitted.principal === void 0) throw new Error("admitted invocation missing principal");
27553
27564
  return {
@@ -28838,6 +28849,8 @@ async function runPostAdmissionSeatResume(input) {
28838
28849
  }
28839
28850
  adapters = prepared.adapters;
28840
28851
  }
28852
+ let env = input.env;
28853
+ let preparedCleanup;
28841
28854
  const buildRequestAfterLease = async () => {
28842
28855
  let openCourtAttemptId;
28843
28856
  let admittedForBuild = loaded.admitted;
@@ -28888,7 +28901,12 @@ async function runPostAdmissionSeatResume(input) {
28888
28901
  return turnRequest;
28889
28902
  };
28890
28903
  try {
28891
- if (input.env.stationChild === true) {
28904
+ if (input.afterAdmittedPrepare !== void 0) {
28905
+ const prepared = await input.afterAdmittedPrepare(loaded.admitted);
28906
+ if (prepared.env !== void 0) env = prepared.env;
28907
+ preparedCleanup = prepared.cleanup;
28908
+ }
28909
+ if (env.stationChild === true) {
28892
28910
  let firstTurn;
28893
28911
  const stationAdapters = withOnceSuccessfulBeforeDispatch(adapters);
28894
28912
  const invocationScopeId = mintEngineDetourInvocationScope({
@@ -28896,14 +28914,14 @@ async function runPostAdmissionSeatResume(input) {
28896
28914
  });
28897
28915
  return await runWithAutoResumeLoop({
28898
28916
  admitted: loaded.admitted,
28899
- principalAuthority: input.env.principalAuthority,
28917
+ principalAuthority: env.principalAuthority,
28900
28918
  isPrincipalAvailable: resolveHostAwareSessionAvailability(
28901
- input.env.host,
28902
- input.env.principalAuthority
28919
+ env.host,
28920
+ env.principalAuthority
28903
28921
  ),
28904
28922
  io: input.io,
28905
- sessionAppender: input.env.sessionAppender,
28906
- autoResumeLimit: input.env.autoResumeLimit,
28923
+ sessionAppender: env.sessionAppender,
28924
+ autoResumeLimit: env.autoResumeLimit,
28907
28925
  buildInitialPayload: () => ({ resumeTurn: false }),
28908
28926
  buildResumePayload: () => ({ resumeTurn: true }),
28909
28927
  // Same as public manual resume: prior-court sealed acceptance is not a
@@ -28930,7 +28948,7 @@ async function runPostAdmissionSeatResume(input) {
28930
28948
  dispatch: async (turnRequest) => {
28931
28949
  const result2 = await dispatchPostAdmissionTurn({
28932
28950
  admitted: loaded.admitted,
28933
- env: input.env,
28951
+ env,
28934
28952
  io: attemptIo,
28935
28953
  request: turnRequest,
28936
28954
  lease,
@@ -28940,7 +28958,7 @@ async function runPostAdmissionSeatResume(input) {
28940
28958
  });
28941
28959
  return settleDeferredPersist(
28942
28960
  loaded.admitted,
28943
- input.env.principalAuthority,
28961
+ env.principalAuthority,
28944
28962
  stationAdapters,
28945
28963
  attemptIo,
28946
28964
  result2
@@ -28951,7 +28969,7 @@ async function runPostAdmissionSeatResume(input) {
28951
28969
  }
28952
28970
  return await runPostAdmissionManualResume({
28953
28971
  admitted: loaded.admitted,
28954
- env: input.env,
28972
+ env,
28955
28973
  io: input.io,
28956
28974
  adapters,
28957
28975
  ...input.effectiveEngine === void 0 ? {} : { effectiveEngine: input.effectiveEngine },
@@ -28963,6 +28981,10 @@ async function runPostAdmissionSeatResume(input) {
28963
28981
  return { exitCode: 2 };
28964
28982
  }
28965
28983
  throw error;
28984
+ } finally {
28985
+ if (preparedCleanup !== void 0) {
28986
+ await preparedCleanup();
28987
+ }
28966
28988
  }
28967
28989
  }
28968
28990
  async function runPostAdmissionOneShot(input) {
@@ -30423,16 +30445,346 @@ var init_diarist_run = __esm({
30423
30445
  }
30424
30446
  });
30425
30447
 
30448
+ // src/public-cli/reviewer-run.ts
30449
+ var reviewer_run_exports = {};
30450
+ __export(reviewer_run_exports, {
30451
+ buildReviewerTurnRequest: () => buildReviewerTurnRequest,
30452
+ runPublicReviewer: () => runPublicReviewer,
30453
+ runPublicReviewerResume: () => runPublicReviewerResume
30454
+ });
30455
+ import { resolve as resolve9 } from "node:path";
30456
+ function reviewerMethods(packageRoot2) {
30457
+ return [{ kind: "skill", path: resolvePackagedMethodSkillPath(packageRoot2, "ak-cross-m-review") }];
30458
+ }
30459
+ async function runReviewerTurnInFreshCopy(env, projectRoot, io, body) {
30460
+ if (env.executionCwd !== void 0) {
30461
+ return body(env);
30462
+ }
30463
+ const { withEphemeralReviewerWorktree: withEphemeralReviewerWorktree2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
30464
+ return await withEphemeralReviewerWorktree2({
30465
+ projectRoot,
30466
+ onCleanupDiagnostic: (diagnostic) => {
30467
+ io.stderr(`${diagnostic}
30468
+ `);
30469
+ },
30470
+ run: (executionCwd) => body({ ...env, executionCwd })
30471
+ });
30472
+ }
30473
+ function buildReviewerTurnRequest(admitted, options) {
30474
+ return projectRoleTurnRequest(
30475
+ admitted,
30476
+ {
30477
+ activation: {
30478
+ role: "reviewer",
30479
+ baseRevision: admitted.baseRevision,
30480
+ lens: admitted.lens,
30481
+ authorityRefs: admitted.authorityRefs,
30482
+ ...admitted.ticketNumber === void 0 ? {} : { ticketNumber: admitted.ticketNumber }
30483
+ },
30484
+ methods: reviewerMethods(options.packageRoot)
30485
+ },
30486
+ options
30487
+ );
30488
+ }
30489
+ function reviewerAdapters(packageRoot2, methodMaterial) {
30490
+ return {
30491
+ trySettle: (admitted, authority, scope) => methodMaterial === void 0 ? Promise.resolve(void 0) : trySettleReviewerTerminalResult(
30492
+ admitted,
30493
+ authority,
30494
+ {
30495
+ methodProvenance: methodMaterial.provenance,
30496
+ methodSkillPath: methodMaterial.skillPath,
30497
+ methodSkillConfiguredPath: resolvePackagedMethodSkillPath(
30498
+ packageRoot2,
30499
+ "ak-cross-m-review"
30500
+ )
30501
+ },
30502
+ scope
30503
+ ),
30504
+ resolveRunnerKnownFailure: async ({ result: result2, sessionFile }) => {
30505
+ const infrastructureFailure = await readEngineDetourInfrastructureFailure(sessionFile);
30506
+ return infrastructureFailure === void 0 ? result2.knownFailure : {
30507
+ ...infrastructureFailure.cause === void 0 ? {} : { cause: infrastructureFailure.cause },
30508
+ diagnostic: infrastructureFailure.diagnostic,
30509
+ ...infrastructureFailure.identity === void 0 ? {} : { identity: infrastructureFailure.identity }
30510
+ };
30511
+ }
30512
+ };
30513
+ }
30514
+ async function loadReviewerMethodMaterial(packageRoot2) {
30515
+ return await loadPackagedMethodSkillMaterial(packageRoot2, "ak-cross-m-review");
30516
+ }
30517
+ function reviewerResumePrompt(env, message) {
30518
+ const lines = [RESUME_TRANSPORT_ENVELOPE];
30519
+ if (message !== void 0) lines.push("", message);
30520
+ return appendEngineSessionMaterial(
30521
+ lines,
30522
+ engineSessionMaterialFromOptions({
30523
+ ...pickEngineAxis(env),
30524
+ packageRoot: env.packageRoot
30525
+ })
30526
+ ).join("\n");
30527
+ }
30528
+ async function runPublicReviewer(argv, env, io, parseReviewerArgv2) {
30529
+ let parsed;
30530
+ try {
30531
+ parsed = parseReviewerArgv2(argv);
30532
+ } catch (error) {
30533
+ if (error instanceof CliUsageError) {
30534
+ presentStructuralRejection(error, io);
30535
+ return { exitCode: 2 };
30536
+ }
30537
+ throw error;
30538
+ }
30539
+ if (parsed.lens === void 0) {
30540
+ const { summonParallelReviewerLenses: summonParallelReviewerLenses2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
30541
+ const children = await summonParallelReviewerLenses2({
30542
+ argv,
30543
+ // Replay argv under the same cwd the single-axis entry would see (10a).
30544
+ // Do not substitute the resolved project path — relative --project must
30545
+ // not be re-resolved against a shifted cwd.
30546
+ cwd: env.cwd,
30547
+ projectRoot: resolve9(parsed.project ?? env.cwd),
30548
+ // Typed base from the public parse — precheck only; child argv stays verbatim.
30549
+ baseRevision: parsed.baseRevision,
30550
+ home: env.home,
30551
+ agentDir: env.agentDir,
30552
+ ...env.credentials === void 0 ? {} : { credentials: env.credentials },
30553
+ ...env.model === void 0 ? {} : { model: env.model },
30554
+ ...env.host === void 0 ? {} : { host: env.host },
30555
+ ...env.engine === void 0 ? {} : { engine: env.engine },
30556
+ ...env.engineModel === void 0 ? {} : { engineModel: env.engineModel },
30557
+ packageRoot: env.packageRoot,
30558
+ ...env.signal === void 0 ? {} : { signal: env.signal },
30559
+ ...env.correlationId === void 0 ? {} : { correlationId: env.correlationId },
30560
+ roleTurnHost: env.roleTurnHost,
30561
+ ...env.hostAdapters === void 0 ? {} : { hostAdapters: env.hostAdapters },
30562
+ principalAuthority: env.principalAuthority,
30563
+ ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs }
30564
+ });
30565
+ const childResults = [children.completeness, children.correctness];
30566
+ const terminals = childResults.map((child) => child.terminal).filter((terminal2) => terminal2 !== void 0);
30567
+ const failedChildren = childResults.filter((child) => child.terminal === void 0 || !isLawfulTypedTerminalOutcome(child.terminal.roleOutcome)).length;
30568
+ const overlayExit = childResults.some((child) => child.exitCode !== 0);
30569
+ const failed = failedChildren > 0 || overlayExit;
30570
+ const overlayDiagnostics = [...new Set(
30571
+ childResults.map((child) => child.stderr).filter((text) => typeof text === "string" && text !== "")
30572
+ )];
30573
+ const terminal = {
30574
+ batch: "reviewer",
30575
+ roleOutcome: failed ? {
30576
+ kind: "failure",
30577
+ role: "reviewer",
30578
+ diagnostic: failedChildren > 0 ? "Reviewer batch child failure" : overlayDiagnostics[0] ?? "Reviewer batch infrastructure failure",
30579
+ decisiveFacts: { failedChildren },
30580
+ payloads: terminals
30581
+ } : { kind: "accepted", role: "reviewer", payloads: terminals },
30582
+ reviewerChildren: {
30583
+ ...children.completeness.terminal === void 0 ? {} : { completeness: children.completeness.terminal },
30584
+ ...children.correctness.terminal === void 0 ? {} : { correctness: children.correctness.terminal }
30585
+ },
30586
+ reviewerChildOutcomes: {
30587
+ completeness: { exitCode: children.completeness.exitCode, ...children.completeness.stderr === void 0 ? {} : { stderr: children.completeness.stderr } },
30588
+ correctness: { exitCode: children.correctness.exitCode, ...children.correctness.stderr === void 0 ? {} : { stderr: children.correctness.stderr } }
30589
+ },
30590
+ // Batch has no parent run and no own attendance; no-advice is affirmative
30591
+ // only (navigator-attendance.ts). Children carry their own navigator facts.
30592
+ navigator: {
30593
+ disposition: "unavailable",
30594
+ source: "unknown",
30595
+ reason: "Reviewer batch has no parent-run Navigator attendance"
30596
+ },
30597
+ artifacts: terminals.flatMap((item) => item.artifacts)
30598
+ };
30599
+ io.stdout(formatTerminalResult(terminal));
30600
+ return { exitCode: failed ? 1 : 0, terminal };
30601
+ }
30602
+ let admitted;
30603
+ try {
30604
+ admitted = await admitReviewerInvocation({
30605
+ home: env.home,
30606
+ principalAuthority: env.principalAuthority,
30607
+ cwd: env.cwd,
30608
+ instruction: parsed.instruction,
30609
+ attachmentPaths: parsed.attachmentPaths,
30610
+ baseRevision: parsed.baseRevision,
30611
+ lens: parsed.lens,
30612
+ authorityRefs: parsed.authorityRefs,
30613
+ ...parsed.project === void 0 ? {} : { project: parsed.project },
30614
+ ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId },
30615
+ ...env.correlationId === void 0 ? {} : { correlationId: env.correlationId },
30616
+ ...env.model === void 0 ? {} : { model: env.model }
30617
+ });
30618
+ } catch (error) {
30619
+ if (error instanceof CliUsageError) {
30620
+ presentStructuralRejection(error, io);
30621
+ return { exitCode: 2 };
30622
+ }
30623
+ throw error;
30624
+ }
30625
+ await markRunAdmitted(admitted, env.principalAuthority);
30626
+ let methodMaterial;
30627
+ try {
30628
+ methodMaterial = await loadReviewerMethodMaterial(env.packageRoot);
30629
+ } catch (error) {
30630
+ return await presentControlledFailure2(
30631
+ admitted,
30632
+ {
30633
+ timedOut: false,
30634
+ code: null,
30635
+ stderr: "",
30636
+ thrown: error
30637
+ },
30638
+ reviewerAdapters(env.packageRoot),
30639
+ env.principalAuthority,
30640
+ io
30641
+ );
30642
+ }
30643
+ try {
30644
+ return await runReviewerTurnInFreshCopy(env, admitted.projectRoot, io, async (sandboxedEnv) => await runPostAdmissionResumable({
30645
+ admitted,
30646
+ env: sandboxedEnv,
30647
+ io,
30648
+ buildInitialRequest: () => buildReviewerTurnRequest(admitted, {
30649
+ packageRoot: sandboxedEnv.packageRoot,
30650
+ home: sandboxedEnv.home,
30651
+ agentDir: sandboxedEnv.agentDir,
30652
+ ...sandboxedEnv.model === void 0 ? {} : { model: sandboxedEnv.model },
30653
+ ...pickEngineAxis(sandboxedEnv),
30654
+ ...sandboxedEnv.timeoutMs === void 0 ? {} : { timeoutMs: sandboxedEnv.timeoutMs },
30655
+ ...admitted.correlationId === void 0 && sandboxedEnv.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? sandboxedEnv.correlationId },
30656
+ // Ephemeral worktree cwd; durable projectRoot stays on admitted caller project.
30657
+ ...sandboxedEnv.executionCwd === void 0 ? {} : { cwd: sandboxedEnv.executionCwd },
30658
+ continuation: {
30659
+ kind: "initial",
30660
+ prompt: buildReviewerTransportPrompt(
30661
+ admitted,
30662
+ engineSessionMaterialFromOptions({
30663
+ ...pickEngineAxis(sandboxedEnv),
30664
+ packageRoot: sandboxedEnv.packageRoot
30665
+ })
30666
+ )
30667
+ }
30668
+ }),
30669
+ buildResumeRequest: () => buildReviewerTurnRequest(admitted, {
30670
+ packageRoot: sandboxedEnv.packageRoot,
30671
+ home: sandboxedEnv.home,
30672
+ agentDir: sandboxedEnv.agentDir,
30673
+ ...sandboxedEnv.model === void 0 ? {} : { model: sandboxedEnv.model },
30674
+ ...pickEngineAxis(sandboxedEnv),
30675
+ ...sandboxedEnv.timeoutMs === void 0 ? {} : { timeoutMs: sandboxedEnv.timeoutMs },
30676
+ ...admitted.correlationId === void 0 && sandboxedEnv.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? sandboxedEnv.correlationId },
30677
+ // In-batch auto-resume keeps the same call's sandbox (dual-lens or single).
30678
+ ...sandboxedEnv.executionCwd === void 0 ? {} : { cwd: sandboxedEnv.executionCwd },
30679
+ continuation: {
30680
+ kind: "resume",
30681
+ prompt: reviewerResumePrompt(sandboxedEnv)
30682
+ }
30683
+ }),
30684
+ adapters: reviewerAdapters(sandboxedEnv.packageRoot, methodMaterial),
30685
+ ...sandboxedEnv.engine === void 0 ? {} : { effectiveEngine: sandboxedEnv.engine }
30686
+ }));
30687
+ } catch (error) {
30688
+ return await presentControlledFailure2(
30689
+ admitted,
30690
+ {
30691
+ timedOut: false,
30692
+ code: null,
30693
+ stderr: "",
30694
+ thrown: error
30695
+ },
30696
+ reviewerAdapters(env.packageRoot, methodMaterial),
30697
+ env.principalAuthority,
30698
+ io
30699
+ );
30700
+ }
30701
+ }
30702
+ async function runPublicReviewerResume(request, env, io) {
30703
+ const sandbox = {
30704
+ ...env.executionCwd === void 0 ? {} : { executionCwd: env.executionCwd }
30705
+ };
30706
+ return await runPostAdmissionSeatResume({
30707
+ request,
30708
+ env,
30709
+ io,
30710
+ load: (effective) => loadResumableReviewerRun(env.home, effective.runId, env.principalAuthority),
30711
+ buildTurnRequest: (admitted, effective) => {
30712
+ const activeEnv = sandbox.executionCwd === void 0 ? env : { ...env, executionCwd: sandbox.executionCwd };
30713
+ const base = resumeTurnRequestProjectionOptions(admitted, effective, activeEnv);
30714
+ return buildReviewerTurnRequest(admitted, {
30715
+ ...base,
30716
+ // Fresh copy at resume time; durable projectRoot unchanged.
30717
+ ...sandbox.executionCwd === void 0 ? {} : { cwd: sandbox.executionCwd },
30718
+ continuation: {
30719
+ kind: "resume",
30720
+ prompt: reviewerResumePrompt(activeEnv, effective.message)
30721
+ }
30722
+ });
30723
+ },
30724
+ adapters: reviewerAdapters(env.packageRoot),
30725
+ afterAdmittedLoad: async (admitted) => {
30726
+ return resolveResumeMethodMaterialAdapters({
30727
+ admitted,
30728
+ authority: env.principalAuthority,
30729
+ io,
30730
+ loadMaterial: () => loadReviewerMethodMaterial(env.packageRoot),
30731
+ adaptersWith: (material) => reviewerAdapters(env.packageRoot, material),
30732
+ emptyAdapters: reviewerAdapters(env.packageRoot)
30733
+ });
30734
+ },
30735
+ afterAdmittedPrepare: async (admitted) => {
30736
+ if (sandbox.executionCwd !== void 0) {
30737
+ return { env: { ...env, executionCwd: sandbox.executionCwd } };
30738
+ }
30739
+ const { openEphemeralReviewerWorktree: openEphemeralReviewerWorktree2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
30740
+ const opened = await openEphemeralReviewerWorktree2({
30741
+ projectRoot: admitted.projectRoot,
30742
+ onCleanupDiagnostic: (diagnostic) => {
30743
+ io.stderr(`${diagnostic}
30744
+ `);
30745
+ }
30746
+ });
30747
+ sandbox.executionCwd = opened.executionCwd;
30748
+ return {
30749
+ env: { ...env, executionCwd: opened.executionCwd },
30750
+ cleanup: opened.close
30751
+ };
30752
+ },
30753
+ ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
30754
+ });
30755
+ }
30756
+ var init_reviewer_run = __esm({
30757
+ "src/public-cli/reviewer-run.ts"() {
30758
+ "use strict";
30759
+ init_engine_material();
30760
+ init_method_skill();
30761
+ init_cli_errors();
30762
+ init_invocation();
30763
+ init_run_lifecycle();
30764
+ init_settlement();
30765
+ init_terminal();
30766
+ init_turn_request();
30767
+ init_post_admission();
30768
+ }
30769
+ });
30770
+
30426
30771
  // src/public-role-summons.ts
30427
30772
  var public_role_summons_exports = {};
30428
30773
  __export(public_role_summons_exports, {
30429
30774
  AK_ROLE_PACKAGE_ROOT_ENV: () => AK_ROLE_PACKAGE_ROOT_ENV,
30775
+ openEphemeralReviewerWorktree: () => openEphemeralReviewerWorktree,
30430
30776
  resolveSummonsPackageRoot: () => resolveSummonsPackageRoot,
30431
30777
  summonGateOfficer: () => summonGateOfficer,
30432
- summonPublicRole: () => summonPublicRole
30778
+ summonParallelReviewerLenses: () => summonParallelReviewerLenses,
30779
+ summonPublicRole: () => summonPublicRole,
30780
+ withEphemeralReviewerWorktree: () => withEphemeralReviewerWorktree
30433
30781
  });
30782
+ import { execFile as execFile3 } from "node:child_process";
30434
30783
  import { existsSync as existsSync10 } from "node:fs";
30435
- import { join as join30 } from "node:path";
30784
+ import { mkdir as mkdir5, mkdtemp as mkdtemp3, realpath as realpath6, rm as rm3 } from "node:fs/promises";
30785
+ import { tmpdir as tmpdir3 } from "node:os";
30786
+ import { join as join30, relative as relative3, sep as sep5 } from "node:path";
30787
+ import { promisify as promisify3 } from "node:util";
30436
30788
  function createCapturingIo() {
30437
30789
  const chunks = [];
30438
30790
  return {
@@ -30520,13 +30872,14 @@ async function createSummonEnv(options, afterHost) {
30520
30872
  Promise.resolve().then(() => (init_role_turn_host_resolution(), role_turn_host_resolution_exports)),
30521
30873
  Promise.resolve().then(() => (init_config2(), config_exports))
30522
30874
  ]);
30523
- const principalAuthority = piDurablePrincipalAuthority2;
30875
+ const principalAuthority = options.principalAuthority ?? piDurablePrincipalAuthority2;
30524
30876
  const roleTurnHost = resolveRoleTurnHost2(
30525
30877
  {
30526
30878
  packageRoot: options.packageRoot,
30527
30879
  ...options.roleTurnHost === void 0 ? {} : { roleTurnHost: options.roleTurnHost },
30528
30880
  ...options.hostAdapters === void 0 ? {} : { hostAdapters: options.hostAdapters },
30529
- ...options.extraPiArgs === void 0 || options.extraPiArgs.length === 0 ? {} : { extraPiArgs: options.extraPiArgs }
30881
+ ...options.extraPiArgs === void 0 || options.extraPiArgs.length === 0 ? {} : { extraPiArgs: options.extraPiArgs },
30882
+ ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
30530
30883
  },
30531
30884
  { role: options.role, seat: options.seat, principalAuthority }
30532
30885
  );
@@ -30539,13 +30892,16 @@ async function createSummonEnv(options, afterHost) {
30539
30892
  };
30540
30893
  }
30541
30894
  const hostName = seatWithModel.host ?? "pi";
30542
- const { loadHostProvidersTable: loadHostProvidersTable2, projectHostFacingProvider: projectHostFacingProvider2 } = await Promise.resolve().then(() => (init_host_providers(), host_providers_exports));
30543
- const hostFacingSelection = projectHostFacingProvider2(
30544
- seatWithModel.selection,
30545
- hostName,
30546
- loadHostProvidersTable2(options.home),
30547
- options.home
30548
- );
30895
+ let hostFacingSelection = options.hostFacingModel;
30896
+ if (hostFacingSelection === void 0) {
30897
+ const { loadHostProvidersTable: loadHostProvidersTable2, projectHostFacingProvider: projectHostFacingProvider2 } = await Promise.resolve().then(() => (init_host_providers(), host_providers_exports));
30898
+ hostFacingSelection = projectHostFacingProvider2(
30899
+ seatWithModel.selection,
30900
+ hostName,
30901
+ loadHostProvidersTable2(options.home),
30902
+ options.home
30903
+ );
30904
+ }
30549
30905
  return {
30550
30906
  ok: true,
30551
30907
  env: {
@@ -30559,7 +30915,8 @@ async function createSummonEnv(options, afterHost) {
30559
30915
  credentials: options.credentials,
30560
30916
  ...hostFacingSelection === void 0 ? {} : { model: hostFacingSelection },
30561
30917
  ...projectSeatEngine(seatWithModel),
30562
- ...projectSeatHost(seatWithModel)
30918
+ ...projectSeatHost(seatWithModel),
30919
+ ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
30563
30920
  }
30564
30921
  };
30565
30922
  }
@@ -30574,7 +30931,19 @@ async function summonPublicRole(options) {
30574
30931
  } = await Promise.resolve().then(() => (init_config2(), config_exports));
30575
30932
  const credentials = options.credentials ?? await loadCredentialProviders2(agentDir);
30576
30933
  const config = await loadPublicCliConfig2(home);
30577
- const seat = resolveEffectiveSeat2(config, options.role, credentials);
30934
+ const resolvedSeat = resolveEffectiveSeat2(config, options.role, credentials);
30935
+ const inheritedSelection = options.model === void 0 ? void 0 : {
30936
+ provider: options.model.provider,
30937
+ model: options.model.model,
30938
+ ...options.model.thinking === void 0 ? {} : { thinking: options.model.thinking }
30939
+ };
30940
+ const seat = {
30941
+ ...resolvedSeat,
30942
+ ...inheritedSelection === void 0 ? {} : { selection: inheritedSelection, source: "invocation" },
30943
+ ...options.host === void 0 ? {} : { host: options.host, hostSource: "invocation" },
30944
+ ...options.engine === void 0 ? {} : { engine: options.engine, engineSource: "invocation" },
30945
+ ...options.engineModel === void 0 ? {} : { engineModel: options.engineModel }
30946
+ };
30578
30947
  const captured = options.io === void 0 ? createCapturingIo() : void 0;
30579
30948
  const io = options.io ?? captured.io;
30580
30949
  const summonEnvInput = {
@@ -30587,7 +30956,11 @@ async function summonPublicRole(options) {
30587
30956
  seat,
30588
30957
  ...options.extraPiArgs === void 0 ? {} : { extraPiArgs: options.extraPiArgs },
30589
30958
  ...options.roleTurnHost === void 0 ? {} : { roleTurnHost: options.roleTurnHost },
30590
- ...options.hostAdapters === void 0 ? {} : { hostAdapters: options.hostAdapters }
30959
+ ...options.hostAdapters === void 0 ? {} : { hostAdapters: options.hostAdapters },
30960
+ ...options.principalAuthority === void 0 ? {} : { principalAuthority: options.principalAuthority },
30961
+ ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs },
30962
+ // Parent model is already host-facing; child must not project again.
30963
+ ...options.model === void 0 ? {} : { hostFacingModel: options.model }
30591
30964
  };
30592
30965
  async function prepareSummonEnv(afterHost) {
30593
30966
  try {
@@ -30599,7 +30972,9 @@ async function summonPublicRole(options) {
30599
30972
  ok: true,
30600
30973
  env: {
30601
30974
  ...built.env,
30602
- stationChild: true,
30975
+ // Nested court stations keep station-child semantics; dual-lens
30976
+ // ordinary Reviewer axes opt out (#946 / ADR 0082).
30977
+ ...options.stationChild === false ? {} : { stationChild: true },
30603
30978
  // Forward composition-root adapters so nested court stations (e.g.
30604
30979
  // countersign → diarist) select the same faux/production table (#924).
30605
30980
  ...options.hostAdapters === void 0 ? {} : { hostAdapters: options.hostAdapters },
@@ -30609,7 +30984,8 @@ async function summonPublicRole(options) {
30609
30984
  ...options.gateReviewInstruction === void 0 ? {} : { gateReviewInstruction: options.gateReviewInstruction },
30610
30985
  ...options.boundTicketNumber === void 0 ? {} : { boundTicketNumber: options.boundTicketNumber },
30611
30986
  ...options.correlationId === void 0 || options.correlationId.trim() === "" ? {} : { correlationId: options.correlationId },
30612
- ...options.createRunId === void 0 ? {} : { createRunId: options.createRunId }
30987
+ ...options.createRunId === void 0 ? {} : { createRunId: options.createRunId },
30988
+ ...options.executionCwd === void 0 ? {} : { executionCwd: options.executionCwd }
30613
30989
  }
30614
30990
  };
30615
30991
  } catch (error) {
@@ -30721,6 +31097,16 @@ async function summonPublicRole(options) {
30721
31097
  result2 = stepped.ok;
30722
31098
  break;
30723
31099
  }
31100
+ case "reviewer": {
31101
+ const [{ runPublicReviewer: runPublicReviewer2 }, { parseReviewerArgv: parseReviewerArgv2 }] = await Promise.all([
31102
+ Promise.resolve().then(() => (init_reviewer_run(), reviewer_run_exports)),
31103
+ Promise.resolve().then(() => (init_invocation(), invocation_exports))
31104
+ ]);
31105
+ const stepped = await runPrepared(parseReviewerArgv2, (env, once) => runPublicReviewer2(options.argv, env, io, once));
31106
+ if ("fail" in stepped) return stepped.fail;
31107
+ result2 = stepped.ok;
31108
+ break;
31109
+ }
30724
31110
  }
30725
31111
  const stderr = captured?.stderrText();
30726
31112
  const runDirectory = result2.admitted?.runDirectory;
@@ -30732,6 +31118,296 @@ async function summonPublicRole(options) {
30732
31118
  ...stderr === void 0 || stderr === "" ? {} : { stderr }
30733
31119
  };
30734
31120
  }
31121
+ function withReviewerLens(argv, lens) {
31122
+ const separator = argv.indexOf("--");
31123
+ if (separator === -1) return [...argv, "--lens", lens];
31124
+ return [...argv.slice(0, separator), "--lens", lens, ...argv.slice(separator)];
31125
+ }
31126
+ async function resolveReviewerWorktreeRoots(projectRoot) {
31127
+ const callerProjectRoot = await realpath6(projectRoot);
31128
+ const sourceProjectRoot = await realpath6((await execFileAsync3(
31129
+ "git",
31130
+ ["rev-parse", "--show-toplevel"],
31131
+ { cwd: callerProjectRoot }
31132
+ )).stdout.trim());
31133
+ const callerRelative = relative3(sourceProjectRoot, callerProjectRoot);
31134
+ const projectRelative = callerRelative === "" || callerRelative === "." || callerRelative.startsWith(`..${sep5}`) || callerRelative === ".." ? "" : callerRelative;
31135
+ return { callerProjectRoot, sourceProjectRoot, projectRelative };
31136
+ }
31137
+ function reviewerSandboxPath(worktreeAxis, projectRelative) {
31138
+ return projectRelative === "" ? worktreeAxis : join30(worktreeAxis, projectRelative);
31139
+ }
31140
+ async function openEphemeralReviewerWorktree(options) {
31141
+ const { sourceProjectRoot, projectRelative } = await resolveReviewerWorktreeRoots(
31142
+ options.projectRoot
31143
+ );
31144
+ const { stdout: headStdout } = await execFileAsync3(
31145
+ "git",
31146
+ ["rev-parse", "--verify", "HEAD^{commit}"],
31147
+ { cwd: sourceProjectRoot }
31148
+ );
31149
+ const targetCommit = headStdout.trim();
31150
+ const root = await mkdtemp3(join30(tmpdir3(), "ak-reviewer-sandbox-"));
31151
+ const worktreeRoot = join30(root, "work");
31152
+ let registered = false;
31153
+ const rollback = async (cause) => {
31154
+ const cleanupErrors = [];
31155
+ if (registered) {
31156
+ try {
31157
+ await execFileAsync3("git", ["worktree", "remove", "--force", worktreeRoot], {
31158
+ cwd: sourceProjectRoot
31159
+ });
31160
+ } catch (error) {
31161
+ cleanupErrors.push(error);
31162
+ }
31163
+ }
31164
+ try {
31165
+ await rm3(root, { recursive: true, force: true });
31166
+ } catch (error) {
31167
+ cleanupErrors.push(error);
31168
+ }
31169
+ if (cleanupErrors.length > 0) {
31170
+ options.onCleanupDiagnostic?.([
31171
+ "reviewer worktree cleanup failed",
31172
+ ...cleanupErrors.map((error) => error instanceof Error ? error.message : String(error))
31173
+ ].join("\n"));
31174
+ }
31175
+ throw cause;
31176
+ };
31177
+ try {
31178
+ await execFileAsync3("git", ["worktree", "add", "--detach", worktreeRoot, targetCommit], {
31179
+ cwd: sourceProjectRoot
31180
+ });
31181
+ registered = true;
31182
+ if (projectRelative !== "") {
31183
+ await mkdir5(reviewerSandboxPath(worktreeRoot, projectRelative), { recursive: true });
31184
+ }
31185
+ } catch (error) {
31186
+ await rollback(error);
31187
+ }
31188
+ let closed = false;
31189
+ return {
31190
+ executionCwd: reviewerSandboxPath(worktreeRoot, projectRelative),
31191
+ close: async () => {
31192
+ if (closed) return;
31193
+ closed = true;
31194
+ const cleanupErrors = [];
31195
+ try {
31196
+ await execFileAsync3("git", ["worktree", "remove", worktreeRoot], {
31197
+ cwd: sourceProjectRoot
31198
+ });
31199
+ } catch (error) {
31200
+ cleanupErrors.push(error);
31201
+ }
31202
+ try {
31203
+ await rm3(root, { recursive: true, force: true });
31204
+ } catch (error) {
31205
+ cleanupErrors.push(error);
31206
+ }
31207
+ if (cleanupErrors.length > 0) {
31208
+ options.onCleanupDiagnostic?.([
31209
+ "reviewer worktree cleanup failed",
31210
+ ...cleanupErrors.map((error) => error instanceof Error ? error.message : String(error))
31211
+ ].join("\n"));
31212
+ }
31213
+ }
31214
+ };
31215
+ }
31216
+ async function withEphemeralReviewerWorktree(options) {
31217
+ const sandbox = await openEphemeralReviewerWorktree({
31218
+ projectRoot: options.projectRoot,
31219
+ ...options.onCleanupDiagnostic === void 0 ? {} : { onCleanupDiagnostic: options.onCleanupDiagnostic }
31220
+ });
31221
+ try {
31222
+ return await options.run(sandbox.executionCwd);
31223
+ } finally {
31224
+ await sandbox.close();
31225
+ }
31226
+ }
31227
+ async function summonParallelReviewerLenses(options) {
31228
+ const describeFailure = (error) => {
31229
+ if (error instanceof AggregateError) {
31230
+ return [error.message, ...error.errors.map(describeFailure)].join("\n");
31231
+ }
31232
+ return error instanceof Error ? error.message : String(error);
31233
+ };
31234
+ const failedResult = (error) => ({
31235
+ exitCode: 1,
31236
+ stderr: describeFailure(error)
31237
+ });
31238
+ const dualFailure = (error) => {
31239
+ const failure = failedResult(error);
31240
+ return { completeness: failure, correctness: failure };
31241
+ };
31242
+ let sourceProjectRoot;
31243
+ let projectRelative;
31244
+ let targetCommit;
31245
+ const statusArgs = [
31246
+ "status",
31247
+ "--porcelain=v1",
31248
+ "--untracked-files=all",
31249
+ "--",
31250
+ ":/",
31251
+ ":(top,exclude).claude/worktrees/**"
31252
+ ];
31253
+ try {
31254
+ const roots = await resolveReviewerWorktreeRoots(options.projectRoot);
31255
+ sourceProjectRoot = roots.sourceProjectRoot;
31256
+ projectRelative = roots.projectRelative;
31257
+ const { stdout: statusStdout } = await execFileAsync3("git", statusArgs, {
31258
+ cwd: sourceProjectRoot
31259
+ });
31260
+ if (statusStdout !== "") {
31261
+ const diagnostic = [
31262
+ "Reviewer target status gate failed:",
31263
+ "git status --porcelain=v1 --untracked-files=all -- :/ ':(top,exclude).claude/worktrees/**'",
31264
+ statusStdout
31265
+ ].join("\n");
31266
+ return dualFailure(new Error(diagnostic));
31267
+ }
31268
+ const { stdout: targetStdout } = await execFileAsync3(
31269
+ "git",
31270
+ ["rev-parse", "--verify", "HEAD^{commit}"],
31271
+ { cwd: sourceProjectRoot }
31272
+ );
31273
+ targetCommit = targetStdout.trim();
31274
+ await execFileAsync3(
31275
+ "git",
31276
+ ["rev-parse", "--verify", `${options.baseRevision}^{commit}`],
31277
+ { cwd: sourceProjectRoot }
31278
+ );
31279
+ } catch (error) {
31280
+ return dualFailure(error);
31281
+ }
31282
+ const root = await mkdtemp3(join30(tmpdir3(), "ak-reviewer-lenses-"));
31283
+ const completenessRoot = join30(root, "completeness");
31284
+ const correctnessRoot = join30(root, "correctness");
31285
+ const worktrees = [completenessRoot, correctnessRoot];
31286
+ const created = /* @__PURE__ */ new Set();
31287
+ let results;
31288
+ const creation = await Promise.allSettled(
31289
+ worktrees.map(async (path) => {
31290
+ await execFileAsync3("git", ["worktree", "add", "--detach", path, targetCommit], {
31291
+ cwd: sourceProjectRoot
31292
+ });
31293
+ created.add(path);
31294
+ if (projectRelative !== "") {
31295
+ await mkdir5(reviewerSandboxPath(path, projectRelative), { recursive: true });
31296
+ }
31297
+ })
31298
+ );
31299
+ const creationFailures = creation.flatMap((result2) => result2.status === "rejected" ? [result2.reason] : []);
31300
+ if (creationFailures.length > 0) {
31301
+ const failure = failedResult(new AggregateError(
31302
+ creationFailures,
31303
+ "parallel reviewer worktree creation failed"
31304
+ ));
31305
+ results = { completeness: failure, correctness: failure };
31306
+ } else {
31307
+ const summon = (lens, worktreeAxis) => {
31308
+ const sandbox = reviewerSandboxPath(worktreeAxis, projectRelative);
31309
+ return summonPublicRole({
31310
+ role: "reviewer",
31311
+ argv: withReviewerLens(options.argv, lens),
31312
+ cwd: options.cwd,
31313
+ executionCwd: sandbox,
31314
+ // Ordinary single-axis public semantics — not a nested court station.
31315
+ stationChild: false,
31316
+ home: options.home,
31317
+ ...options.agentDir === void 0 ? {} : { agentDir: options.agentDir },
31318
+ ...options.credentials === void 0 ? {} : { credentials: options.credentials },
31319
+ ...options.model === void 0 ? {} : { model: options.model },
31320
+ ...options.host === void 0 ? {} : { host: options.host },
31321
+ ...options.engine === void 0 ? {} : { engine: options.engine },
31322
+ ...options.engineModel === void 0 ? {} : { engineModel: options.engineModel },
31323
+ ...options.signal === void 0 ? {} : { signal: options.signal },
31324
+ ...options.correlationId === void 0 ? {} : { correlationId: options.correlationId },
31325
+ ...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
31326
+ ...options.roleTurnHost === void 0 ? {} : { roleTurnHost: options.roleTurnHost },
31327
+ ...options.hostAdapters === void 0 ? {} : { hostAdapters: options.hostAdapters },
31328
+ ...options.principalAuthority === void 0 ? {} : { principalAuthority: options.principalAuthority },
31329
+ ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
31330
+ });
31331
+ };
31332
+ const settled = await Promise.allSettled([
31333
+ summon("completeness", completenessRoot),
31334
+ summon("correctness", correctnessRoot)
31335
+ ]);
31336
+ results = {
31337
+ completeness: settled[0].status === "fulfilled" ? settled[0].value : failedResult(settled[0].reason),
31338
+ correctness: settled[1].status === "fulfilled" ? settled[1].value : failedResult(settled[1].reason)
31339
+ };
31340
+ }
31341
+ let sealDiagnostic;
31342
+ try {
31343
+ const { stdout: headBeforeStdout } = await execFileAsync3(
31344
+ "git",
31345
+ ["rev-parse", "--verify", "HEAD^{commit}"],
31346
+ { cwd: sourceProjectRoot }
31347
+ );
31348
+ const { stdout: sealedStatusStdout } = await execFileAsync3("git", statusArgs, {
31349
+ cwd: sourceProjectRoot
31350
+ });
31351
+ const { stdout: headAfterStdout } = await execFileAsync3(
31352
+ "git",
31353
+ ["rev-parse", "--verify", "HEAD^{commit}"],
31354
+ { cwd: sourceProjectRoot }
31355
+ );
31356
+ const headBefore = headBeforeStdout.trim();
31357
+ const headAfter = headAfterStdout.trim();
31358
+ if (headBefore !== targetCommit || headAfter !== targetCommit || sealedStatusStdout !== "") {
31359
+ sealDiagnostic = [
31360
+ "Reviewer target final seal failed:",
31361
+ `HEAD before status => ${headBefore}`,
31362
+ `HEAD after status => ${headAfter}`,
31363
+ `expected PRE_HEAD ${targetCommit}`,
31364
+ "git status --porcelain=v1 --untracked-files=all -- :/ ':(top,exclude).claude/worktrees/**'",
31365
+ sealedStatusStdout
31366
+ ].join("\n");
31367
+ }
31368
+ } catch (error) {
31369
+ sealDiagnostic = `Reviewer target final seal failed:
31370
+ ${describeFailure(error)}`;
31371
+ }
31372
+ if (sealDiagnostic !== void 0) {
31373
+ const withSealFailure = (result2) => ({
31374
+ ...result2,
31375
+ exitCode: 1,
31376
+ stderr: [result2.stderr, sealDiagnostic].filter(
31377
+ (text) => typeof text === "string" && text !== ""
31378
+ ).join("\n")
31379
+ });
31380
+ results = {
31381
+ completeness: withSealFailure(results.completeness),
31382
+ correctness: withSealFailure(results.correctness)
31383
+ };
31384
+ }
31385
+ const cleanup = await Promise.allSettled(
31386
+ [...created].map((path) => execFileAsync3("git", ["worktree", "remove", path], { cwd: sourceProjectRoot }))
31387
+ );
31388
+ const cleanupFailures = cleanup.flatMap((result2) => result2.status === "rejected" ? [result2.reason] : []);
31389
+ if (cleanupFailures.length === 0) {
31390
+ const rootCleanup = await Promise.allSettled([rm3(root, { recursive: true, force: true })]);
31391
+ cleanupFailures.push(...rootCleanup.flatMap((result2) => result2.status === "rejected" ? [result2.reason] : []));
31392
+ }
31393
+ if (cleanupFailures.length > 0) {
31394
+ const diagnostic = [
31395
+ "parallel reviewer worktree cleanup failed",
31396
+ ...cleanupFailures.map((failure) => failure instanceof Error ? failure.message : String(failure))
31397
+ ].join("\n");
31398
+ const withCleanupDiagnostic = (result2) => ({
31399
+ ...result2,
31400
+ stderr: [result2.stderr, diagnostic].filter(
31401
+ (text) => typeof text === "string" && text !== ""
31402
+ ).join("\n")
31403
+ });
31404
+ results = {
31405
+ completeness: withCleanupDiagnostic(results.completeness),
31406
+ correctness: withCleanupDiagnostic(results.correctness)
31407
+ };
31408
+ }
31409
+ return results;
31410
+ }
30735
31411
  async function summonGateOfficer(options) {
30736
31412
  let home = options.home;
30737
31413
  if (home === void 0) {
@@ -30781,12 +31457,13 @@ async function summonGateOfficer(options) {
30781
31457
  ...common
30782
31458
  });
30783
31459
  }
30784
- var AK_ROLE_PACKAGE_ROOT_ENV;
31460
+ var AK_ROLE_PACKAGE_ROOT_ENV, execFileAsync3;
30785
31461
  var init_public_role_summons = __esm({
30786
31462
  "src/public-role-summons.ts"() {
30787
31463
  "use strict";
30788
31464
  init_engine_material();
30789
31465
  AK_ROLE_PACKAGE_ROOT_ENV = "AK_ROLE_PACKAGE_ROOT";
31466
+ execFileAsync3 = promisify3(execFile3);
30790
31467
  }
30791
31468
  });
30792
31469
 
@@ -31889,189 +32566,6 @@ var init_merger_run = __esm({
31889
32566
  }
31890
32567
  });
31891
32568
 
31892
- // src/public-cli/reviewer-run.ts
31893
- function reviewerMethods(packageRoot2) {
31894
- return [{ kind: "skill", path: resolvePackagedMethodSkillPath(packageRoot2, "ak-cross-m-review") }];
31895
- }
31896
- function buildReviewerTurnRequest(admitted, options) {
31897
- return projectRoleTurnRequest(
31898
- admitted,
31899
- {
31900
- activation: {
31901
- role: "reviewer",
31902
- baseRevision: admitted.baseRevision,
31903
- lens: admitted.lens,
31904
- authorityRefs: admitted.authorityRefs,
31905
- ...admitted.ticketNumber === void 0 ? {} : { ticketNumber: admitted.ticketNumber }
31906
- },
31907
- methods: reviewerMethods(options.packageRoot)
31908
- },
31909
- options
31910
- );
31911
- }
31912
- function reviewerAdapters(packageRoot2, methodMaterial) {
31913
- return {
31914
- trySettle: (admitted, authority, scope) => methodMaterial === void 0 ? Promise.resolve(void 0) : trySettleReviewerTerminalResult(
31915
- admitted,
31916
- authority,
31917
- {
31918
- methodProvenance: methodMaterial.provenance,
31919
- methodSkillPath: methodMaterial.skillPath,
31920
- methodSkillConfiguredPath: resolvePackagedMethodSkillPath(
31921
- packageRoot2,
31922
- "ak-cross-m-review"
31923
- )
31924
- },
31925
- scope
31926
- ),
31927
- resolveRunnerKnownFailure: async ({ result: result2, sessionFile }) => {
31928
- const infrastructureFailure = await readEngineDetourInfrastructureFailure(sessionFile);
31929
- return infrastructureFailure === void 0 ? result2.knownFailure : {
31930
- ...infrastructureFailure.cause === void 0 ? {} : { cause: infrastructureFailure.cause },
31931
- diagnostic: infrastructureFailure.diagnostic,
31932
- ...infrastructureFailure.identity === void 0 ? {} : { identity: infrastructureFailure.identity }
31933
- };
31934
- }
31935
- };
31936
- }
31937
- async function loadReviewerMethodMaterial(packageRoot2) {
31938
- return await loadPackagedMethodSkillMaterial(packageRoot2, "ak-cross-m-review");
31939
- }
31940
- function reviewerResumePrompt(env, message) {
31941
- const lines = [RESUME_TRANSPORT_ENVELOPE];
31942
- if (message !== void 0) lines.push("", message);
31943
- return appendEngineSessionMaterial(
31944
- lines,
31945
- engineSessionMaterialFromOptions({
31946
- ...pickEngineAxis(env),
31947
- packageRoot: env.packageRoot
31948
- })
31949
- ).join("\n");
31950
- }
31951
- async function runPublicReviewer(argv, env, io, parseReviewerArgv2) {
31952
- let admitted;
31953
- try {
31954
- const parsed = parseReviewerArgv2(argv);
31955
- admitted = await admitReviewerInvocation({
31956
- home: env.home,
31957
- principalAuthority: env.principalAuthority,
31958
- cwd: env.cwd,
31959
- instruction: parsed.instruction,
31960
- attachmentPaths: parsed.attachmentPaths,
31961
- baseRevision: parsed.baseRevision,
31962
- lens: parsed.lens,
31963
- authorityRefs: parsed.authorityRefs,
31964
- ...parsed.project === void 0 ? {} : { project: parsed.project },
31965
- ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId },
31966
- ...env.model === void 0 ? {} : { model: env.model }
31967
- });
31968
- } catch (error) {
31969
- if (error instanceof CliUsageError) {
31970
- presentStructuralRejection(error, io);
31971
- return { exitCode: 2 };
31972
- }
31973
- throw error;
31974
- }
31975
- await markRunAdmitted(admitted, env.principalAuthority);
31976
- let methodMaterial;
31977
- try {
31978
- methodMaterial = await loadReviewerMethodMaterial(env.packageRoot);
31979
- } catch (error) {
31980
- return await presentControlledFailure2(
31981
- admitted,
31982
- {
31983
- timedOut: false,
31984
- code: null,
31985
- stderr: "",
31986
- thrown: error
31987
- },
31988
- reviewerAdapters(env.packageRoot),
31989
- env.principalAuthority,
31990
- io
31991
- );
31992
- }
31993
- return await runPostAdmissionResumable({
31994
- admitted,
31995
- env,
31996
- io,
31997
- buildInitialRequest: () => buildReviewerTurnRequest(admitted, {
31998
- packageRoot: env.packageRoot,
31999
- home: env.home,
32000
- agentDir: env.agentDir,
32001
- ...env.model === void 0 ? {} : { model: env.model },
32002
- ...pickEngineAxis(env),
32003
- ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
32004
- ...admitted.correlationId === void 0 && env.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? env.correlationId },
32005
- continuation: {
32006
- kind: "initial",
32007
- prompt: buildReviewerTransportPrompt(
32008
- admitted,
32009
- engineSessionMaterialFromOptions({
32010
- ...pickEngineAxis(env),
32011
- packageRoot: env.packageRoot
32012
- })
32013
- )
32014
- }
32015
- }),
32016
- buildResumeRequest: () => buildReviewerTurnRequest(admitted, {
32017
- packageRoot: env.packageRoot,
32018
- home: env.home,
32019
- agentDir: env.agentDir,
32020
- ...env.model === void 0 ? {} : { model: env.model },
32021
- ...pickEngineAxis(env),
32022
- ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
32023
- ...admitted.correlationId === void 0 && env.correlationId === void 0 ? {} : { correlationId: admitted.correlationId ?? env.correlationId },
32024
- continuation: {
32025
- kind: "resume",
32026
- prompt: reviewerResumePrompt(env)
32027
- }
32028
- }),
32029
- adapters: reviewerAdapters(env.packageRoot, methodMaterial),
32030
- ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
32031
- });
32032
- }
32033
- async function runPublicReviewerResume(request, env, io) {
32034
- return await runPostAdmissionSeatResume({
32035
- request,
32036
- env,
32037
- io,
32038
- load: (effective) => loadResumableReviewerRun(env.home, effective.runId, env.principalAuthority),
32039
- buildTurnRequest: (admitted, effective) => {
32040
- const base = resumeTurnRequestProjectionOptions(admitted, effective, env);
32041
- return buildReviewerTurnRequest(admitted, {
32042
- ...base,
32043
- continuation: {
32044
- kind: "resume",
32045
- prompt: reviewerResumePrompt(env, effective.message)
32046
- }
32047
- });
32048
- },
32049
- adapters: reviewerAdapters(env.packageRoot),
32050
- afterAdmittedLoad: (admitted) => resolveResumeMethodMaterialAdapters({
32051
- admitted,
32052
- authority: env.principalAuthority,
32053
- io,
32054
- loadMaterial: () => loadReviewerMethodMaterial(env.packageRoot),
32055
- adaptersWith: (material) => reviewerAdapters(env.packageRoot, material),
32056
- emptyAdapters: reviewerAdapters(env.packageRoot)
32057
- }),
32058
- ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
32059
- });
32060
- }
32061
- var init_reviewer_run = __esm({
32062
- "src/public-cli/reviewer-run.ts"() {
32063
- "use strict";
32064
- init_engine_material();
32065
- init_method_skill();
32066
- init_cli_errors();
32067
- init_invocation();
32068
- init_run_lifecycle();
32069
- init_settlement();
32070
- init_turn_request();
32071
- init_post_admission();
32072
- }
32073
- });
32074
-
32075
32569
  // src/analyst-book-key.ts
32076
32570
  import { statSync as statSync2 } from "node:fs";
32077
32571
  import { isAbsolute as isAbsolute9 } from "node:path";
@@ -32108,7 +32602,7 @@ var init_analyst_book_key = __esm({
32108
32602
 
32109
32603
  // src/atomic-write.ts
32110
32604
  import { randomUUID as randomUUID7 } from "node:crypto";
32111
- import { rename as rename3, rm as rm3, writeFile as writeFile10 } from "node:fs/promises";
32605
+ import { rename as rename3, rm as rm4, writeFile as writeFile10 } from "node:fs/promises";
32112
32606
  import { dirname as dirname16, join as join31 } from "node:path";
32113
32607
  async function writeFileAtomically(destination, contents) {
32114
32608
  const parent = dirname16(destination);
@@ -32117,7 +32611,7 @@ async function writeFileAtomically(destination, contents) {
32117
32611
  await writeFile10(temporary, contents);
32118
32612
  await rename3(temporary, destination);
32119
32613
  } catch (error) {
32120
- await rm3(temporary, { force: true }).catch(() => void 0);
32614
+ await rm4(temporary, { force: true }).catch(() => void 0);
32121
32615
  throw error;
32122
32616
  }
32123
32617
  }
@@ -32131,8 +32625,8 @@ var init_atomic_write = __esm({
32131
32625
  import { open as open3, readFile as readFile19, unlink as unlink3 } from "node:fs/promises";
32132
32626
  import { dirname as dirname17, join as join32 } from "node:path";
32133
32627
  function sleep(ms) {
32134
- return new Promise((resolve10) => {
32135
- setTimeout(resolve10, ms);
32628
+ return new Promise((resolve11) => {
32629
+ setTimeout(resolve11, ms);
32136
32630
  });
32137
32631
  }
32138
32632
  async function withAnalystLibraryIndexLock(ledgerHome, fn) {
@@ -34025,7 +34519,7 @@ var init_analyst_entry = __esm({
34025
34519
 
34026
34520
  // src/public-cli/analyst-run.ts
34027
34521
  import { readFile as readFile22 } from "node:fs/promises";
34028
- import { isAbsolute as isAbsolute10, resolve as resolve9 } from "node:path";
34522
+ import { isAbsolute as isAbsolute10, resolve as resolve10 } from "node:path";
34029
34523
  function resolveAnalystIssueBookKeyFromCwd(cwd = process.cwd()) {
34030
34524
  try {
34031
34525
  return resolveBookKeyFromGit(cwd);
@@ -34074,7 +34568,7 @@ async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
34074
34568
  );
34075
34569
  }
34076
34570
  const sourcePath = attachmentPaths[0];
34077
- const absolute = isAbsolute10(sourcePath) ? sourcePath : resolve9(sourcePath);
34571
+ const absolute = isAbsolute10(sourcePath) ? sourcePath : resolve10(sourcePath);
34078
34572
  let bytes;
34079
34573
  try {
34080
34574
  bytes = await readFile22(absolute);
@@ -34196,7 +34690,7 @@ __export(cli_exports, {
34196
34690
  resolveInternalRoleEntrypoint: () => resolveInternalRoleEntrypoint,
34197
34691
  runAkRole: () => runAkRole
34198
34692
  });
34199
- import { realpath as realpath6 } from "node:fs/promises";
34693
+ import { realpath as realpath7 } from "node:fs/promises";
34200
34694
  import { join as join35 } from "node:path";
34201
34695
  function takePublicGlobalFlag(argv, index, options) {
34202
34696
  const tokens = argv.slice(index);
@@ -34850,7 +35344,7 @@ async function runAkRole(argv, env) {
34850
35344
  try {
34851
35345
  env = {
34852
35346
  ...env,
34853
- packageRoot: await realpath6(env.packageRoot),
35347
+ packageRoot: await realpath7(env.packageRoot),
34854
35348
  principalAuthority: env.principalAuthority ?? piDurablePrincipalAuthority
34855
35349
  };
34856
35350
  let parsed = parseArgv(argv);