@akagilnc/pi-workflow-roles 0.1.2152 → 0.1.2169

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.
@@ -18714,7 +18714,7 @@ var init_typed_provider_http = __esm({
18714
18714
  });
18715
18715
 
18716
18716
  // src/public-cli/run-lifecycle.ts
18717
- import { lstat as lstat2, open, readdir as readdir2, readFile as readFile8, unlink as unlink3, writeFile as writeFile4 } from "node:fs/promises";
18717
+ import { chmod, lstat as lstat2, open, readdir as readdir2, readFile as readFile8, unlink as unlink3, writeFile as writeFile4 } from "node:fs/promises";
18718
18718
  import { join as join10 } from "node:path";
18719
18719
  function isV1ResumableProvider(provider) {
18720
18720
  return V1_RESUMABLE_PROVIDERS.includes(provider);
@@ -18866,7 +18866,22 @@ async function isSessionPrincipalAvailable(sessionFile) {
18866
18866
  return false;
18867
18867
  }
18868
18868
  }
18869
- async function acquireRunWriterLease(runDirectory) {
18869
+ function describeErrorIdentity(error) {
18870
+ const candidate = error;
18871
+ const name = typeof candidate?.name === "string" && candidate.name !== "" ? candidate.name : typeof error;
18872
+ const code = typeof candidate?.code === "string" || typeof candidate?.code === "number" ? ` code=${String(candidate.code)}` : "";
18873
+ const message = typeof candidate?.message === "string" && candidate.message !== "" ? `: ${candidate.message}` : "";
18874
+ return `${name}${code}${message}`;
18875
+ }
18876
+ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
18877
+ const reportCleanupFailure = (error) => {
18878
+ try {
18879
+ onCleanupFailure?.(
18880
+ `writer lease lock cleanup failed (best-effort continue; stale lock resurfaces as lease-held on next acquire) at ${join10(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
18881
+ );
18882
+ } catch {
18883
+ }
18884
+ };
18870
18885
  const lockPath = join10(runDirectory, WRITER_LOCK_FILE);
18871
18886
  try {
18872
18887
  const handle = await open(lockPath, "wx");
@@ -18885,7 +18900,20 @@ async function acquireRunWriterLease(runDirectory) {
18885
18900
  if (released) return;
18886
18901
  released = true;
18887
18902
  await handle.close().catch(() => void 0);
18888
- await unlink3(lockPath).catch(() => void 0);
18903
+ try {
18904
+ await unlink3(lockPath);
18905
+ } catch (error) {
18906
+ if (error.code === "EACCES") {
18907
+ try {
18908
+ await chmod(runDirectory, 493);
18909
+ await unlink3(lockPath);
18910
+ } catch (retryError) {
18911
+ reportCleanupFailure(retryError);
18912
+ }
18913
+ } else {
18914
+ reportCleanupFailure(error);
18915
+ }
18916
+ }
18889
18917
  }
18890
18918
  };
18891
18919
  } catch (error) {
@@ -18944,12 +18972,6 @@ async function loadResumableRunRecord(home, runId) {
18944
18972
  if (run === void 0) {
18945
18973
  throw new CliUsageError(`unknown role run id: ${runId}`);
18946
18974
  }
18947
- if (run.state === "terminal") {
18948
- throw new CliUsageError(`role run is already terminal: ${runId}`);
18949
- }
18950
- if (run.state !== "resumable" || run.resumable === void 0) {
18951
- throw new CliUsageError(`role run is not resumable: ${runId}`);
18952
- }
18953
18975
  if (!await isSessionPrincipalAvailable(run.sessionFile)) {
18954
18976
  throw new CliUsageError(
18955
18977
  `role run Pi session principal is unavailable: ${runId}`
@@ -19063,7 +19085,7 @@ async function loadResumableRunRecord(home, runId) {
19063
19085
  }
19064
19086
  return {
19065
19087
  run,
19066
- observation: run.resumable,
19088
+ ...run.resumable === void 0 ? {} : { observation: run.resumable },
19067
19089
  admittedFields: {
19068
19090
  instruction,
19069
19091
  instructionEmpty,
@@ -19106,7 +19128,7 @@ async function loadResumableJudgeRun(home, runId) {
19106
19128
  return {
19107
19129
  admitted,
19108
19130
  run: loaded.run,
19109
- observation: loaded.observation
19131
+ ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
19110
19132
  };
19111
19133
  }
19112
19134
  async function loadResumableCoderRun(home, runId) {
@@ -19152,7 +19174,7 @@ async function loadResumableCoderRun(home, runId) {
19152
19174
  return {
19153
19175
  admitted,
19154
19176
  run: loaded.run,
19155
- observation: loaded.observation
19177
+ ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
19156
19178
  };
19157
19179
  }
19158
19180
  async function loadResumableFixerRun(home, runId) {
@@ -19201,7 +19223,7 @@ async function loadResumableFixerRun(home, runId) {
19201
19223
  return {
19202
19224
  admitted,
19203
19225
  run: loaded.run,
19204
- observation: loaded.observation
19226
+ ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
19205
19227
  };
19206
19228
  }
19207
19229
  async function loadResumableReviewerRun(home, runId) {
@@ -19236,7 +19258,7 @@ async function loadResumableReviewerRun(home, runId) {
19236
19258
  return {
19237
19259
  admitted,
19238
19260
  run: loaded.run,
19239
- observation: loaded.observation
19261
+ ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
19240
19262
  };
19241
19263
  }
19242
19264
  async function loadResumableMergerRun(home, runId) {
@@ -19282,7 +19304,7 @@ async function loadResumableMergerRun(home, runId) {
19282
19304
  return {
19283
19305
  admitted,
19284
19306
  run: loaded.run,
19285
- observation: loaded.observation
19307
+ ...loaded.observation === void 0 ? {} : { observation: loaded.observation }
19286
19308
  };
19287
19309
  }
19288
19310
  async function peekRoleRunRole(home, runId) {
@@ -19291,7 +19313,7 @@ async function peekRoleRunRole(home, runId) {
19291
19313
  const run = await readRoleRunState(runDirectory);
19292
19314
  return run?.role;
19293
19315
  }
19294
- var V1_RESUMABLE_PROVIDERS, RESUME_TRANSPORT_ENVELOPE, RUN_STATE_FILE, WRITER_LOCK_FILE, RunWriterLeaseHeldError;
19316
+ var V1_RESUMABLE_PROVIDERS, AUTO_RESUME_LIMIT, RESUME_TRANSPORT_ENVELOPE, RUN_STATE_FILE, WRITER_LOCK_FILE, RunWriterLeaseHeldError;
19295
19317
  var init_run_lifecycle = __esm({
19296
19318
  "src/public-cli/run-lifecycle.ts"() {
19297
19319
  "use strict";
@@ -19301,6 +19323,7 @@ var init_run_lifecycle = __esm({
19301
19323
  init_typed_provider_http();
19302
19324
  init_invocation();
19303
19325
  V1_RESUMABLE_PROVIDERS = ["openai-codex", "xai"];
19326
+ AUTO_RESUME_LIMIT = 2;
19304
19327
  RESUME_TRANSPORT_ENVELOPE = "[ak-role:resume-continue]";
19305
19328
  RUN_STATE_FILE = "run-state.json";
19306
19329
  WRITER_LOCK_FILE = "writer.lock";
@@ -19314,6 +19337,176 @@ var init_run_lifecycle = __esm({
19314
19337
  }
19315
19338
  });
19316
19339
 
19340
+ // src/public-command-renderer.ts
19341
+ function renderPublicAkRoleCommand(target) {
19342
+ if (!PUBLIC_CALLABLE_ROLES2.has(target.role)) return void 0;
19343
+ const role = target.role;
19344
+ if (target.phase === null || target.phase === void 0) {
19345
+ return `ak-role ${role}`;
19346
+ }
19347
+ if (role === "coder" || role === "fixer") {
19348
+ return `ak-role ${role} ${target.phase}`;
19349
+ }
19350
+ return `ak-role ${role}`;
19351
+ }
19352
+ var PUBLIC_CALLABLE_ROLES2;
19353
+ var init_public_command_renderer = __esm({
19354
+ "src/public-command-renderer.ts"() {
19355
+ "use strict";
19356
+ init_packaged_role_registry();
19357
+ PUBLIC_CALLABLE_ROLES2 = new Set(
19358
+ PACKAGED_ROLE_REGISTRY.map((entry) => entry.role)
19359
+ );
19360
+ }
19361
+ });
19362
+
19363
+ // src/public-cli/command-renderer.ts
19364
+ var init_command_renderer = __esm({
19365
+ "src/public-cli/command-renderer.ts"() {
19366
+ "use strict";
19367
+ init_public_command_renderer();
19368
+ }
19369
+ });
19370
+
19371
+ // src/public-cli/terminal.ts
19372
+ function encodeTerminalField(value) {
19373
+ return JSON.stringify(value);
19374
+ }
19375
+ function jsonSafeComplianceCandidate(value) {
19376
+ return value === void 0 ? JSON_SAFE_UNDEFINED_ARGUMENT : value;
19377
+ }
19378
+ function isLawfulTypedTerminalOutcome(outcome) {
19379
+ return outcome.kind === "accepted" || outcome.kind === "audit_escalation" || outcome.kind === "no_receipt";
19380
+ }
19381
+ function exitCodeForTerminalOutcome(outcome) {
19382
+ return isLawfulTypedTerminalOutcome(outcome) ? 0 : 1;
19383
+ }
19384
+ function buildResidualIncompleteTerminalOutcome(input) {
19385
+ return {
19386
+ kind: "incomplete",
19387
+ role: input.role,
19388
+ status: "incomplete",
19389
+ decision: "no-usable-result",
19390
+ candidate: input.candidate,
19391
+ diagnostic: input.diagnostic,
19392
+ acceptedReceipt: false,
19393
+ decisiveFacts: {
19394
+ decision: "no-usable-result",
19395
+ candidate: input.candidate,
19396
+ diagnostic: input.diagnostic,
19397
+ acceptedReceipt: false
19398
+ }
19399
+ };
19400
+ }
19401
+ function buildAuditIncompleteTerminalOutcome(input) {
19402
+ const roleCandidate = jsonSafeComplianceCandidate(input.roleCandidate);
19403
+ const audit = {
19404
+ ...input.audit,
19405
+ candidate: jsonSafeComplianceCandidate(input.audit.candidate)
19406
+ };
19407
+ return {
19408
+ kind: "audit_incomplete",
19409
+ role: input.role,
19410
+ status: "audit-incomplete",
19411
+ decision: "no-usable-decision",
19412
+ roleCandidate,
19413
+ audit,
19414
+ acceptedReceipt: false,
19415
+ decisiveFacts: {
19416
+ decision: "no-usable-decision",
19417
+ roleCandidate,
19418
+ auditCandidate: audit.candidate,
19419
+ auditObservation: audit.observation,
19420
+ observationKind: audit.observation.kind,
19421
+ observationType: audit.observation.kind === "non-object-arguments" ? audit.observation.type : audit.observation.kind === "object-status-unreadable" ? audit.observation.status : audit.observation.kind === "missing-subject" ? audit.observation.subject : audit.observation.kind,
19422
+ acceptedReceipt: false
19423
+ }
19424
+ };
19425
+ }
19426
+ function redactExactRunId(text, runId) {
19427
+ if (runId.length === 0) return text;
19428
+ if (!text.includes(runId)) return text;
19429
+ return text.split(runId).join(REDACTED_RUN_ID_TOKEN);
19430
+ }
19431
+ function recommendationNavigatorFact(input) {
19432
+ void input.modelCommand;
19433
+ const command = renderPublicAkRoleCommand(input.next);
19434
+ if (command === void 0) {
19435
+ return {
19436
+ disposition: "unavailable",
19437
+ source: "unknown",
19438
+ reason: `recommended role is not a public callable seat: ${input.next.role}`
19439
+ };
19440
+ }
19441
+ return {
19442
+ disposition: "recommendation",
19443
+ next: input.next,
19444
+ reason: input.reason,
19445
+ command,
19446
+ ...input.route === void 0 ? {} : { route: input.route },
19447
+ ...input.advisoryDiagnostic === void 0 ? {} : { advisoryDiagnostic: input.advisoryDiagnostic }
19448
+ };
19449
+ }
19450
+ function formatTerminalResult(result2) {
19451
+ const lines = [];
19452
+ lines.push("role outcome status");
19453
+ const outcomeStatus = result2.roleOutcome.kind === "failure" ? result2.roleOutcome.cause : result2.roleOutcome.status;
19454
+ lines.push(
19455
+ `${result2.roleOutcome.role} ${result2.roleOutcome.kind} ${encodeTerminalField(outcomeStatus)}`
19456
+ );
19457
+ if (result2.roleOutcome.kind === "failure") {
19458
+ lines.push(
19459
+ `diagnostic ${encodeTerminalField(result2.roleOutcome.diagnostic)}`
19460
+ );
19461
+ }
19462
+ const facts = result2.roleOutcome.decisiveFacts;
19463
+ for (const [key, value] of Object.entries(facts)) {
19464
+ if (value === void 0) continue;
19465
+ const rendered = typeof value === "string" ? value : JSON.stringify(value);
19466
+ lines.push(`fact ${encodeTerminalField(key)} ${encodeTerminalField(rendered)}`);
19467
+ }
19468
+ lines.push(`navigator ${result2.navigator.disposition}`);
19469
+ if (result2.navigator.advisoryDiagnostic !== void 0) {
19470
+ lines.push(`navigator-advisory ${encodeTerminalField(result2.navigator.advisoryDiagnostic)}`);
19471
+ }
19472
+ if (result2.navigator.disposition === "recommendation") {
19473
+ lines.push(
19474
+ `next ${result2.navigator.next.role} ${result2.navigator.next.phase ?? "none"}`
19475
+ );
19476
+ lines.push(`reason ${encodeTerminalField(result2.navigator.reason)}`);
19477
+ lines.push(`command ${encodeTerminalField(result2.navigator.command)}`);
19478
+ } else if (result2.navigator.disposition === "unavailable") {
19479
+ lines.push(
19480
+ `unavailable ${result2.navigator.source} ${encodeTerminalField(result2.navigator.reason)}`
19481
+ );
19482
+ }
19483
+ for (const artifact of result2.artifacts) {
19484
+ lines.push(`artifact ${artifact.kind} ${encodeTerminalField(artifact.path)}`);
19485
+ }
19486
+ if (result2.resume !== void 0) {
19487
+ lines.push(`resume ${encodeTerminalField(result2.resume.command)}`);
19488
+ } else if (result2.runId !== void 0) {
19489
+ lines.push(`run ${encodeTerminalField(result2.runId)}`);
19490
+ }
19491
+ if (result2.autoResumeCount !== void 0) {
19492
+ lines.push(`autoResumeCount ${encodeTerminalField(String(result2.autoResumeCount))}`);
19493
+ }
19494
+ return `${lines.join("\n")}
19495
+ `;
19496
+ }
19497
+ var JSON_SAFE_UNDEFINED_ARGUMENT, REDACTED_RUN_ID_TOKEN;
19498
+ var init_terminal = __esm({
19499
+ "src/public-cli/terminal.ts"() {
19500
+ "use strict";
19501
+ init_command_renderer();
19502
+ JSON_SAFE_UNDEFINED_ARGUMENT = Object.freeze({
19503
+ kind: "json-safe-sentinel",
19504
+ type: "undefined"
19505
+ });
19506
+ REDACTED_RUN_ID_TOKEN = "[run-id]";
19507
+ }
19508
+ });
19509
+
19317
19510
  // src/auditor-soul.ts
19318
19511
  import { fileURLToPath } from "node:url";
19319
19512
  var AUDITOR_SOUL_ROLES, auditorSoulPaths;
@@ -19672,213 +19865,47 @@ function bindCurrentDurableTerminalToMarker(entries) {
19672
19865
  break;
19673
19866
  }
19674
19867
  }
19675
- let durableCount = 0;
19676
- for (let i = markerIndex + 1; i < windowEnd; i += 1) {
19677
- if (durableTerminalAt(entries, i) !== void 0) durableCount += 1;
19678
- }
19679
- if (durableCount !== 1) return { kind: "ambiguous" };
19680
- if (terminal.index <= markerIndex || terminal.index >= windowEnd) {
19681
- return { kind: "ambiguous" };
19682
- }
19683
- return {
19684
- kind: "bound",
19685
- terminal,
19686
- marker: { ...marker, index: markerIndex }
19687
- };
19688
- }
19689
- function isReceiptSettlementBindingClear(entries) {
19690
- return bindCurrentDurableTerminalToMarker(entries).kind !== "ambiguous";
19691
- }
19692
- var NAVIGATOR_INVOCATION_ENTRY, NAVIGATOR_INFRASTRUCTURE_FAILURE_KIND, NAVIGATOR_INFRASTRUCTURE_FAILURE_KEYS, PACKAGED_ROLE_OUTPUT_TOOLS;
19693
- var init_navigator_invocation_identity = __esm({
19694
- "src/navigator-invocation-identity.ts"() {
19695
- "use strict";
19696
- init_packaged_role_registry();
19697
- init_uuidv7();
19698
- init_work_subject_identity();
19699
- NAVIGATOR_INVOCATION_ENTRY = "ak-navigator-invocation";
19700
- NAVIGATOR_INFRASTRUCTURE_FAILURE_KIND = "role_infrastructure_failure";
19701
- NAVIGATOR_INFRASTRUCTURE_FAILURE_KEYS = [
19702
- "kind",
19703
- "source",
19704
- "reasonCode"
19705
- ];
19706
- PACKAGED_ROLE_OUTPUT_TOOLS = new Map(
19707
- PACKAGED_ROLE_REGISTRY.map((entry) => [entry.outputTool, entry.role])
19708
- );
19709
- }
19710
- });
19711
-
19712
- // src/public-command-renderer.ts
19713
- function renderPublicAkRoleCommand(target) {
19714
- if (!PUBLIC_CALLABLE_ROLES2.has(target.role)) return void 0;
19715
- const role = target.role;
19716
- if (target.phase === null || target.phase === void 0) {
19717
- return `ak-role ${role}`;
19718
- }
19719
- if (role === "coder" || role === "fixer") {
19720
- return `ak-role ${role} ${target.phase}`;
19721
- }
19722
- return `ak-role ${role}`;
19723
- }
19724
- var PUBLIC_CALLABLE_ROLES2;
19725
- var init_public_command_renderer = __esm({
19726
- "src/public-command-renderer.ts"() {
19727
- "use strict";
19728
- init_packaged_role_registry();
19729
- PUBLIC_CALLABLE_ROLES2 = new Set(
19730
- PACKAGED_ROLE_REGISTRY.map((entry) => entry.role)
19731
- );
19732
- }
19733
- });
19734
-
19735
- // src/public-cli/command-renderer.ts
19736
- var init_command_renderer = __esm({
19737
- "src/public-cli/command-renderer.ts"() {
19738
- "use strict";
19739
- init_public_command_renderer();
19740
- }
19741
- });
19742
-
19743
- // src/public-cli/terminal.ts
19744
- function encodeTerminalField(value) {
19745
- return JSON.stringify(value);
19746
- }
19747
- function jsonSafeComplianceCandidate(value) {
19748
- return value === void 0 ? JSON_SAFE_UNDEFINED_ARGUMENT : value;
19749
- }
19750
- function isLawfulTypedTerminalOutcome(outcome) {
19751
- return outcome.kind === "accepted" || outcome.kind === "audit_escalation" || outcome.kind === "no_receipt";
19752
- }
19753
- function exitCodeForTerminalOutcome(outcome) {
19754
- return isLawfulTypedTerminalOutcome(outcome) ? 0 : 1;
19755
- }
19756
- function buildResidualIncompleteTerminalOutcome(input) {
19757
- return {
19758
- kind: "incomplete",
19759
- role: input.role,
19760
- status: "incomplete",
19761
- decision: "no-usable-result",
19762
- candidate: input.candidate,
19763
- diagnostic: input.diagnostic,
19764
- acceptedReceipt: false,
19765
- decisiveFacts: {
19766
- decision: "no-usable-result",
19767
- candidate: input.candidate,
19768
- diagnostic: input.diagnostic,
19769
- acceptedReceipt: false
19770
- }
19771
- };
19772
- }
19773
- function buildAuditIncompleteTerminalOutcome(input) {
19774
- const roleCandidate = jsonSafeComplianceCandidate(input.roleCandidate);
19775
- const audit = {
19776
- ...input.audit,
19777
- candidate: jsonSafeComplianceCandidate(input.audit.candidate)
19778
- };
19779
- return {
19780
- kind: "audit_incomplete",
19781
- role: input.role,
19782
- status: "audit-incomplete",
19783
- decision: "no-usable-decision",
19784
- roleCandidate,
19785
- audit,
19786
- acceptedReceipt: false,
19787
- decisiveFacts: {
19788
- decision: "no-usable-decision",
19789
- roleCandidate,
19790
- auditCandidate: audit.candidate,
19791
- auditObservation: audit.observation,
19792
- observationKind: audit.observation.kind,
19793
- observationType: audit.observation.kind === "non-object-arguments" ? audit.observation.type : audit.observation.kind === "object-status-unreadable" ? audit.observation.status : audit.observation.kind === "missing-subject" ? audit.observation.subject : audit.observation.kind,
19794
- acceptedReceipt: false
19795
- }
19796
- };
19797
- }
19798
- function redactExactRunId(text, runId) {
19799
- if (runId.length === 0) return text;
19800
- if (!text.includes(runId)) return text;
19801
- return text.split(runId).join(REDACTED_RUN_ID_TOKEN);
19802
- }
19803
- function recommendationNavigatorFact(input) {
19804
- void input.modelCommand;
19805
- const command = renderPublicAkRoleCommand(input.next);
19806
- if (command === void 0) {
19807
- return {
19808
- disposition: "unavailable",
19809
- source: "unknown",
19810
- reason: `recommended role is not a public callable seat: ${input.next.role}`
19811
- };
19812
- }
19813
- return {
19814
- disposition: "recommendation",
19815
- next: input.next,
19816
- reason: input.reason,
19817
- command,
19818
- ...input.route === void 0 ? {} : { route: input.route },
19819
- ...input.advisoryDiagnostic === void 0 ? {} : { advisoryDiagnostic: input.advisoryDiagnostic }
19820
- };
19821
- }
19822
- function formatTerminalResult(result2) {
19823
- const lines = [];
19824
- lines.push("role outcome status");
19825
- const outcomeStatus = result2.roleOutcome.kind === "failure" ? result2.roleOutcome.cause : result2.roleOutcome.status;
19826
- lines.push(
19827
- `${result2.roleOutcome.role} ${result2.roleOutcome.kind} ${encodeTerminalField(outcomeStatus)}`
19828
- );
19829
- if (result2.roleOutcome.kind === "failure") {
19830
- lines.push(
19831
- `diagnostic ${encodeTerminalField(result2.roleOutcome.diagnostic)}`
19832
- );
19833
- }
19834
- const facts = result2.roleOutcome.decisiveFacts;
19835
- for (const [key, value] of Object.entries(facts)) {
19836
- if (value === void 0) continue;
19837
- const rendered = typeof value === "string" ? value : JSON.stringify(value);
19838
- lines.push(`fact ${encodeTerminalField(key)} ${encodeTerminalField(rendered)}`);
19839
- }
19840
- lines.push(`navigator ${result2.navigator.disposition}`);
19841
- if (result2.navigator.advisoryDiagnostic !== void 0) {
19842
- lines.push(`navigator-advisory ${encodeTerminalField(result2.navigator.advisoryDiagnostic)}`);
19843
- }
19844
- if (result2.navigator.disposition === "recommendation") {
19845
- lines.push(
19846
- `next ${result2.navigator.next.role} ${result2.navigator.next.phase ?? "none"}`
19847
- );
19848
- lines.push(`reason ${encodeTerminalField(result2.navigator.reason)}`);
19849
- lines.push(`command ${encodeTerminalField(result2.navigator.command)}`);
19850
- } else if (result2.navigator.disposition === "unavailable") {
19851
- lines.push(
19852
- `unavailable ${result2.navigator.source} ${encodeTerminalField(result2.navigator.reason)}`
19853
- );
19854
- }
19855
- for (const artifact of result2.artifacts) {
19856
- lines.push(`artifact ${artifact.kind} ${encodeTerminalField(artifact.path)}`);
19868
+ let durableCount = 0;
19869
+ for (let i = markerIndex + 1; i < windowEnd; i += 1) {
19870
+ if (durableTerminalAt(entries, i) !== void 0) durableCount += 1;
19857
19871
  }
19858
- if (result2.resume !== void 0) {
19859
- lines.push(`resume ${encodeTerminalField(result2.resume.command)}`);
19860
- } else if (result2.runId !== void 0) {
19861
- lines.push(`run ${encodeTerminalField(result2.runId)}`);
19872
+ if (durableCount !== 1) return { kind: "ambiguous" };
19873
+ if (terminal.index <= markerIndex || terminal.index >= windowEnd) {
19874
+ return { kind: "ambiguous" };
19862
19875
  }
19863
- return `${lines.join("\n")}
19864
- `;
19876
+ return {
19877
+ kind: "bound",
19878
+ terminal,
19879
+ marker: { ...marker, index: markerIndex }
19880
+ };
19865
19881
  }
19866
- var JSON_SAFE_UNDEFINED_ARGUMENT, REDACTED_RUN_ID_TOKEN;
19867
- var init_terminal = __esm({
19868
- "src/public-cli/terminal.ts"() {
19882
+ function isReceiptSettlementBindingClear(entries) {
19883
+ return bindCurrentDurableTerminalToMarker(entries).kind !== "ambiguous";
19884
+ }
19885
+ var NAVIGATOR_INVOCATION_ENTRY, NAVIGATOR_INFRASTRUCTURE_FAILURE_KIND, NAVIGATOR_INFRASTRUCTURE_FAILURE_KEYS, PACKAGED_ROLE_OUTPUT_TOOLS;
19886
+ var init_navigator_invocation_identity = __esm({
19887
+ "src/navigator-invocation-identity.ts"() {
19869
19888
  "use strict";
19870
- init_command_renderer();
19871
- JSON_SAFE_UNDEFINED_ARGUMENT = Object.freeze({
19872
- kind: "json-safe-sentinel",
19873
- type: "undefined"
19874
- });
19875
- REDACTED_RUN_ID_TOKEN = "[run-id]";
19889
+ init_packaged_role_registry();
19890
+ init_uuidv7();
19891
+ init_work_subject_identity();
19892
+ NAVIGATOR_INVOCATION_ENTRY = "ak-navigator-invocation";
19893
+ NAVIGATOR_INFRASTRUCTURE_FAILURE_KIND = "role_infrastructure_failure";
19894
+ NAVIGATOR_INFRASTRUCTURE_FAILURE_KEYS = [
19895
+ "kind",
19896
+ "source",
19897
+ "reasonCode"
19898
+ ];
19899
+ PACKAGED_ROLE_OUTPUT_TOOLS = new Map(
19900
+ PACKAGED_ROLE_REGISTRY.map((entry) => [entry.outputTool, entry.role])
19901
+ );
19876
19902
  }
19877
19903
  });
19878
19904
 
19879
19905
  // src/public-cli/settlement.ts
19880
19906
  import { randomUUID } from "node:crypto";
19881
- import { lstat as lstat3, mkdir as mkdir3, open as open2, readFile as readFile9, readdir as readdir3, writeFile as writeFile5 } from "node:fs/promises";
19907
+ import { constants as fsConstants } from "node:fs";
19908
+ import { appendFile, lstat as lstat3, mkdir as mkdir3, open as open2, readFile as readFile9, readdir as readdir3, writeFile as writeFile5 } from "node:fs/promises";
19882
19909
  import { dirname as dirname6, join as join11 } from "node:path";
19883
19910
  function isChildDiagnosticFloodLine(line2) {
19884
19911
  if (/^at\s+/.test(line2)) return true;
@@ -20192,12 +20219,24 @@ async function readBoundAuditorKnownFailure(sessionFile) {
20192
20219
  }
20193
20220
  const parentId = parentEntries.find((entry) => entry.type === "session")?.id;
20194
20221
  if (parentId === void 0) return void 0;
20222
+ const RESUME_ENVELOPE = RESUME_TRANSPORT_ENVELOPE;
20223
+ const isResumeEnvelope = (msg) => {
20224
+ if (!isRecord5(msg) || msg.role !== "user") return false;
20225
+ const text = typeof msg.text === "string" ? msg.text : typeof msg.content === "string" ? msg.content : void 0;
20226
+ if (text === RESUME_ENVELOPE) return true;
20227
+ const content = msg.content;
20228
+ if (Array.isArray(content)) {
20229
+ return content.some((p) => isRecord5(p) && (p.text === RESUME_ENVELOPE || p.content === RESUME_ENVELOPE));
20230
+ }
20231
+ return false;
20232
+ };
20195
20233
  let latestParentUserIndex = -1;
20196
20234
  for (let i = parentEntries.length - 1; i >= 0; i -= 1) {
20197
- if (parentEntries[i]?.type === "message" && parentEntries[i]?.message?.role === "user") {
20198
- latestParentUserIndex = i;
20199
- break;
20200
- }
20235
+ const entry = parentEntries[i];
20236
+ if (entry?.type !== "message" || entry.message?.role !== "user") continue;
20237
+ if (isResumeEnvelope(entry.message)) continue;
20238
+ latestParentUserIndex = i;
20239
+ break;
20201
20240
  }
20202
20241
  const childDirectory = join11(dirname6(sessionFile), "auditor-roles");
20203
20242
  let names;
@@ -20207,6 +20246,7 @@ async function readBoundAuditorKnownFailure(sessionFile) {
20207
20246
  if (isMissingPathError2(error)) return void 0;
20208
20247
  throw sessionReadFailure(error, "failed to read bound auditor session directory");
20209
20248
  }
20249
+ const validAuditorFiles = [];
20210
20250
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
20211
20251
  let entries;
20212
20252
  try {
@@ -20221,6 +20261,9 @@ async function readBoundAuditorKnownFailure(sessionFile) {
20221
20261
  const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
20222
20262
  const attemptEntryIndex = attemptEntryId === void 0 ? -1 : parentEntries.findIndex((entry) => entry.id === attemptEntryId);
20223
20263
  if (bindingParent?.sessionId !== parentId || bindingParent.sessionFile !== sessionFile || attemptEntryIndex < latestParentUserIndex) continue;
20264
+ validAuditorFiles.push({ file, entries, ...attemptEntryId === void 0 ? {} : { attemptEntryId } });
20265
+ }
20266
+ for (const { entries, attemptEntryId } of validAuditorFiles) {
20224
20267
  const stop = extractSessionProviderStop(entries);
20225
20268
  if (stop === void 0) continue;
20226
20269
  for (let i = entries.length - 1; i >= 0; i -= 1) {
@@ -20240,6 +20283,10 @@ async function readBoundAuditorKnownFailure(sessionFile) {
20240
20283
  ...isRecord5(failure.details) ? { details: failure.details } : {}
20241
20284
  };
20242
20285
  }
20286
+ }
20287
+ for (const { entries } of validAuditorFiles) {
20288
+ const stop = extractSessionProviderStop(entries);
20289
+ if (stop === void 0) continue;
20243
20290
  const primary = knownFailureFromProviderStop(stop);
20244
20291
  return {
20245
20292
  ...primary,
@@ -20973,20 +21020,74 @@ async function ensureAuditEvidenceDirectory(runDirectory) {
20973
21020
  }
20974
21021
  return artifactsDir;
20975
21022
  }
21023
+ async function appendRunAttemptHistory(admitted, outcome) {
21024
+ const entries = await readBoundSessionEntries(admitted.sessionFile);
21025
+ let parentId = null;
21026
+ let priorEntries = 0;
21027
+ for (const entry of entries) {
21028
+ if (typeof entry.id === "string" && entry.type !== "session") parentId = entry.id;
21029
+ if (entry.type === "custom" && entry.customType === ATTEMPT_HISTORY_ENTRY_TYPE) {
21030
+ priorEntries += 1;
21031
+ }
21032
+ }
21033
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
21034
+ const line2 = `${JSON.stringify({
21035
+ type: "custom",
21036
+ customType: ATTEMPT_HISTORY_ENTRY_TYPE,
21037
+ data: {
21038
+ sequence: priorEntries + 1,
21039
+ role: admitted.role,
21040
+ runId: admitted.runId,
21041
+ recordedAt: timestamp2,
21042
+ outcome
21043
+ },
21044
+ id: randomUUID(),
21045
+ parentId,
21046
+ timestamp: timestamp2
21047
+ })}
21048
+ `;
21049
+ await appendFile(admitted.sessionFile, line2, "utf8");
21050
+ }
20976
21051
  async function publishComplianceAuditIncompleteEvidence(admitted, outcome) {
21052
+ await appendRunAttemptHistory(admitted, outcome);
21053
+ if (typeof fsConstants.O_NOFOLLOW !== "number" || typeof fsConstants.O_NONBLOCK !== "number") {
21054
+ throw auditArtifactPublicationError(
21055
+ "audit evidence publication requires O_NOFOLLOW|O_NONBLOCK open-flag support (anti-symlink/anti-planted protection must not be silently dropped); refusing to publish",
21056
+ "ENOSYS"
21057
+ );
21058
+ }
20977
21059
  const artifactsDir = await ensureAuditEvidenceDirectory(admitted.runDirectory);
20978
21060
  const evidencePath = join11(artifactsDir, "audit-incomplete.json");
21061
+ let existing;
20979
21062
  try {
20980
- const existing = await lstat3(evidencePath);
20981
- throw auditArtifactPublicationError(
20982
- existing.isSymbolicLink() ? "audit evidence destination is a symlink" : "audit evidence destination collision",
20983
- existing.isSymbolicLink() ? "ELOOP" : "EEXIST"
20984
- );
21063
+ existing = await lstat3(evidencePath);
20985
21064
  } catch (error) {
20986
21065
  if (!isMissingPathError2(error)) throw error;
20987
21066
  }
20988
- const handle = await open2(evidencePath, "wx", 384);
21067
+ if (existing?.isSymbolicLink()) {
21068
+ throw auditArtifactPublicationError(
21069
+ "audit evidence destination is a symlink",
21070
+ "ELOOP"
21071
+ );
21072
+ }
21073
+ if (existing && !existing.isFile()) {
21074
+ throw auditArtifactPublicationError(
21075
+ "audit evidence destination is not a regular file",
21076
+ "EEXIST"
21077
+ );
21078
+ }
21079
+ const handle = await open2(
21080
+ evidencePath,
21081
+ fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_TRUNC | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK,
21082
+ 384
21083
+ );
20989
21084
  try {
21085
+ if (!(await handle.stat()).isFile()) {
21086
+ throw auditArtifactPublicationError(
21087
+ "audit evidence destination is not a regular file",
21088
+ "EEXIST"
21089
+ );
21090
+ }
20990
21091
  await handle.writeFile(`${JSON.stringify(outcome, null, 2)}
20991
21092
  `, "utf8");
20992
21093
  await handle.sync();
@@ -21239,6 +21340,7 @@ async function extractNavigatorFactFromAdmittedSession(admitted) {
21239
21340
  }
21240
21341
  }
21241
21342
  async function publishJudgeArtifacts(admitted, roleOutcome, sessionDirectory) {
21343
+ await appendRunAttemptHistory(admitted, roleOutcome);
21242
21344
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
21243
21345
  const reportPath = join11(artifactsDir, "report.json");
21244
21346
  const evidencePath = join11(artifactsDir, "evidence.json");
@@ -21283,6 +21385,7 @@ async function publishJudgeArtifacts(admitted, roleOutcome, sessionDirectory) {
21283
21385
  ];
21284
21386
  }
21285
21387
  async function publishCoderArtifacts(admitted, roleOutcome, sessionDirectory, options = {}) {
21388
+ await appendRunAttemptHistory(admitted, roleOutcome);
21286
21389
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
21287
21390
  const reportPath = join11(artifactsDir, "report.json");
21288
21391
  const evidencePath = join11(artifactsDir, "evidence.json");
@@ -21452,6 +21555,7 @@ function extractFixerMethodInvocations(entries, options) {
21452
21555
  return Object.freeze(observed);
21453
21556
  }
21454
21557
  async function publishFixerArtifacts(admitted, roleOutcome, sessionDirectory, options) {
21558
+ await appendRunAttemptHistory(admitted, roleOutcome);
21455
21559
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
21456
21560
  const reportPath = join11(artifactsDir, "report.json");
21457
21561
  const evidencePath = join11(artifactsDir, "evidence.json");
@@ -21563,6 +21667,7 @@ async function settleLawfulFixerTerminalResult(admitted, options) {
21563
21667
  };
21564
21668
  }
21565
21669
  async function publishCollectorArtifacts(admitted, roleOutcome, sessionDirectory, options = {}) {
21670
+ await appendRunAttemptHistory(admitted, roleOutcome);
21566
21671
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
21567
21672
  const reportPath = join11(artifactsDir, "report.json");
21568
21673
  const evidencePath = join11(artifactsDir, "evidence.json");
@@ -21682,6 +21787,7 @@ async function trySettleCollectorTerminalResult(admitted) {
21682
21787
  return settleLawfulCollectorTerminalResult(admitted);
21683
21788
  }
21684
21789
  async function publishDoctorArtifacts(admitted, roleOutcome, sessionDirectory, options = {}) {
21790
+ await appendRunAttemptHistory(admitted, roleOutcome);
21685
21791
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
21686
21792
  const reportPath = join11(artifactsDir, "report.json");
21687
21793
  const evidencePath = join11(artifactsDir, "evidence.json");
@@ -21849,6 +21955,7 @@ function extractReviewerMethodInvocations(entries, options) {
21849
21955
  return Object.freeze(observed);
21850
21956
  }
21851
21957
  async function publishReviewerArtifacts(admitted, roleOutcome, sessionDirectory, options) {
21958
+ await appendRunAttemptHistory(admitted, roleOutcome);
21852
21959
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
21853
21960
  const reportPath = join11(artifactsDir, "report.json");
21854
21961
  const evidencePath = join11(artifactsDir, "evidence.json");
@@ -22017,6 +22124,7 @@ function extractMergerMethodInvocations(entries, options) {
22017
22124
  return Object.freeze(observed);
22018
22125
  }
22019
22126
  async function publishMergerArtifacts(admitted, roleOutcome, sessionDirectory, options) {
22127
+ await appendRunAttemptHistory(admitted, roleOutcome);
22020
22128
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
22021
22129
  const reportPath = join11(artifactsDir, "report.json");
22022
22130
  const evidencePath = join11(artifactsDir, "evidence.json");
@@ -22238,6 +22346,15 @@ async function publishFailureArtifacts(admitted, failure) {
22238
22346
  admitted.runDirectory
22239
22347
  );
22240
22348
  const priorIssues = baseAttempt === void 0 ? [] : [baseAttempt];
22349
+ try {
22350
+ await appendRunAttemptHistory(admitted, {
22351
+ kind: "failure",
22352
+ role: admitted.role,
22353
+ ...failure
22354
+ });
22355
+ } catch (error) {
22356
+ priorIssues.push(publicationAttemptFromError(admitted.sessionFile, error));
22357
+ }
22241
22358
  const underArtifacts = baseDir === join11(admitted.runDirectory, "artifacts");
22242
22359
  const uniqueFallbackDirs = uniqueFailureFallbackDirs(
22243
22360
  admitted.runDirectory,
@@ -22434,7 +22551,7 @@ function presentFailureTerminal(terminal, io) {
22434
22551
  }));
22435
22552
  }
22436
22553
  }
22437
- var CONCISE_DIAGNOSTIC_MAX_CHARS, COLLECTOR_INFRASTRUCTURE_TOOLS, COLLECTOR_INFRASTRUCTURE_FAILURE_SPEC, ENGINE_DETOUR_INFRASTRUCTURE_FAILURE_SPEC;
22554
+ var CONCISE_DIAGNOSTIC_MAX_CHARS, COLLECTOR_INFRASTRUCTURE_TOOLS, COLLECTOR_INFRASTRUCTURE_FAILURE_SPEC, ENGINE_DETOUR_INFRASTRUCTURE_FAILURE_SPEC, ATTEMPT_HISTORY_ENTRY_TYPE;
22438
22555
  var init_settlement = __esm({
22439
22556
  "src/public-cli/settlement.ts"() {
22440
22557
  "use strict";
@@ -22477,6 +22594,71 @@ var init_settlement = __esm({
22477
22594
  cause: "output",
22478
22595
  identityName: "EngineDetourInfrastructureError"
22479
22596
  };
22597
+ ATTEMPT_HISTORY_ENTRY_TYPE = "ak_run_attempt_history";
22598
+ }
22599
+ });
22600
+
22601
+ // src/public-cli/auto-resume.ts
22602
+ function presentTerminal(terminal, io) {
22603
+ if (terminal.roleOutcome.kind === "failure" || terminal.roleOutcome.kind === "no_receipt") {
22604
+ presentFailureTerminal(terminal, io);
22605
+ } else {
22606
+ io.stdout(formatTerminalResult(terminal));
22607
+ }
22608
+ }
22609
+ async function runWithAutoResumeLoop(options) {
22610
+ let autoResumeAttempts = 0;
22611
+ let isFirst = true;
22612
+ let currentExtraArgs = options.buildInitialArgs();
22613
+ while (true) {
22614
+ let lease;
22615
+ try {
22616
+ lease = await acquireRunWriterLease(
22617
+ options.admitted.runDirectory,
22618
+ (diagnostic) => options.io.stderr(diagnostic)
22619
+ );
22620
+ } catch (error) {
22621
+ if (error instanceof RunWriterLeaseHeldError) {
22622
+ presentStructuralRejection(error, options.io);
22623
+ return { exitCode: 2 };
22624
+ }
22625
+ throw error;
22626
+ }
22627
+ const result2 = await options.dispatch(currentExtraArgs, lease, isFirst, dummyIo);
22628
+ const terminal = result2.terminal;
22629
+ if (terminal !== void 0) {
22630
+ terminal.autoResumeCount = autoResumeAttempts;
22631
+ }
22632
+ const lawful = terminal !== void 0 && isLawfulTypedTerminalOutcome(terminal.roleOutcome);
22633
+ if (lawful) {
22634
+ if (terminal !== void 0) {
22635
+ options.io.stdout(formatTerminalResult(terminal));
22636
+ }
22637
+ return result2;
22638
+ }
22639
+ if (autoResumeAttempts >= AUTO_RESUME_LIMIT) {
22640
+ if (terminal !== void 0) presentTerminal(terminal, options.io);
22641
+ return result2;
22642
+ }
22643
+ if (!await isSessionPrincipalAvailable(options.admitted.sessionFile)) {
22644
+ if (terminal !== void 0) presentTerminal(terminal, options.io);
22645
+ return result2;
22646
+ }
22647
+ autoResumeAttempts++;
22648
+ currentExtraArgs = options.buildResumeArgs();
22649
+ isFirst = false;
22650
+ }
22651
+ }
22652
+ var dummyIo;
22653
+ var init_auto_resume = __esm({
22654
+ "src/public-cli/auto-resume.ts"() {
22655
+ "use strict";
22656
+ init_run_lifecycle();
22657
+ init_terminal();
22658
+ init_settlement();
22659
+ dummyIo = { stdout: () => {
22660
+ }, stderr: () => {
22661
+ } };
22480
22662
  }
22481
22663
  });
22482
22664
 
@@ -22723,16 +22905,6 @@ async function runPublicCoder(argv, env, io, parseCoderArgv2) {
22723
22905
  throw error;
22724
22906
  }
22725
22907
  await markRunAdmitted(admitted);
22726
- let lease;
22727
- try {
22728
- lease = await acquireRunWriterLease(admitted.runDirectory);
22729
- } catch (error) {
22730
- if (error instanceof RunWriterLeaseHeldError) {
22731
- presentStructuralRejection(error, io);
22732
- return { exitCode: 2 };
22733
- }
22734
- throw error;
22735
- }
22736
22908
  let methodProvenance;
22737
22909
  if (admitted.phase === "apply") {
22738
22910
  try {
@@ -22742,7 +22914,6 @@ async function runPublicCoder(argv, env, io, parseCoderArgv2) {
22742
22914
  );
22743
22915
  methodProvenance = material.provenance;
22744
22916
  } catch (error) {
22745
- await lease.release();
22746
22917
  return await presentControlledFailure2(
22747
22918
  admitted,
22748
22919
  {
@@ -22756,23 +22927,32 @@ async function runPublicCoder(argv, env, io, parseCoderArgv2) {
22756
22927
  );
22757
22928
  }
22758
22929
  }
22759
- const extraArgs = buildCoderActivationExtraArgs(admitted, {
22760
- packageRoot: env.packageRoot,
22761
- ...env.model === void 0 ? {} : { model: env.model },
22762
- ...env.engine === void 0 ? {} : { engine: env.engine },
22763
- ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
22764
- });
22765
- return await dispatchAdmittedCoder({
22930
+ return runWithAutoResumeLoop({
22766
22931
  admitted,
22767
- env: {
22768
- ...env,
22769
- ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
22770
- },
22771
22932
  io,
22772
- extraArgs,
22773
- lease,
22774
- ...methodProvenance === void 0 ? {} : { methodProvenance },
22775
- ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
22933
+ buildInitialArgs: () => buildCoderActivationExtraArgs(admitted, {
22934
+ packageRoot: env.packageRoot,
22935
+ ...env.model === void 0 ? {} : { model: env.model },
22936
+ ...env.engine === void 0 ? {} : { engine: env.engine },
22937
+ ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
22938
+ }),
22939
+ buildResumeArgs: () => buildCoderResumeActivationExtraArgs(admitted, {
22940
+ packageRoot: env.packageRoot,
22941
+ ...env.model === void 0 ? {} : { model: env.model },
22942
+ ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
22943
+ }),
22944
+ dispatch: (extraArgs, lease, isFirst, attemptIo) => dispatchAdmittedCoder({
22945
+ admitted,
22946
+ env: {
22947
+ ...env,
22948
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
22949
+ },
22950
+ io: attemptIo,
22951
+ extraArgs,
22952
+ lease,
22953
+ ...methodProvenance === void 0 ? {} : { methodProvenance },
22954
+ ...isFirst && env.engine !== void 0 ? { effectiveEngine: env.engine } : {}
22955
+ })
22776
22956
  });
22777
22957
  }
22778
22958
  async function runPublicCoderResume(argv, env, io) {
@@ -22804,7 +22984,7 @@ async function runPublicCoderResume(argv, env, io) {
22804
22984
  const { admitted } = loaded;
22805
22985
  let lease;
22806
22986
  try {
22807
- lease = await acquireRunWriterLease(admitted.runDirectory);
22987
+ lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic) => io.stderr(diagnostic));
22808
22988
  } catch (error) {
22809
22989
  if (error instanceof RunWriterLeaseHeldError) {
22810
22990
  io.stderr(formatCliDiagnostic(error.message));
@@ -22840,7 +23020,7 @@ async function runPublicCoderResume(argv, env, io) {
22840
23020
  ...env.model === void 0 ? {} : { model: env.model },
22841
23021
  ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
22842
23022
  });
22843
- return await dispatchAdmittedCoder({
23023
+ const result2 = await dispatchAdmittedCoder({
22844
23024
  admitted,
22845
23025
  env: {
22846
23026
  ...env,
@@ -22851,6 +23031,10 @@ async function runPublicCoderResume(argv, env, io) {
22851
23031
  lease,
22852
23032
  ...methodProvenance === void 0 ? {} : { methodProvenance }
22853
23033
  });
23034
+ if (result2.terminal !== void 0) {
23035
+ result2.terminal.autoResumeCount = 0;
23036
+ }
23037
+ return result2;
22854
23038
  }
22855
23039
  var init_coder_run = __esm({
22856
23040
  "src/public-cli/coder-run.ts"() {
@@ -22864,6 +23048,7 @@ var init_coder_run = __esm({
22864
23048
  init_config2();
22865
23049
  init_public_run_credentials();
22866
23050
  init_run_lifecycle();
23051
+ init_auto_resume();
22867
23052
  init_settlement();
22868
23053
  }
22869
23054
  });
@@ -23063,7 +23248,7 @@ async function runPublicCollector(argv, env, io, parseCollectorArgv2) {
23063
23248
  await markRunAdmitted(admitted);
23064
23249
  let lease;
23065
23250
  try {
23066
- lease = await acquireRunWriterLease(admitted.runDirectory);
23251
+ lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic) => io.stderr(diagnostic));
23067
23252
  } catch (error) {
23068
23253
  if (error instanceof RunWriterLeaseHeldError) {
23069
23254
  presentStructuralRejection(error, io);
@@ -23298,7 +23483,7 @@ async function runPublicDoctor(argv, env, io, parseDoctorArgv2) {
23298
23483
  await markRunAdmitted(admitted);
23299
23484
  let lease;
23300
23485
  try {
23301
- lease = await acquireRunWriterLease(admitted.runDirectory);
23486
+ lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic) => io.stderr(diagnostic));
23302
23487
  } catch (error) {
23303
23488
  if (error instanceof RunWriterLeaseHeldError) {
23304
23489
  presentStructuralRejection(error, io);
@@ -23611,21 +23796,10 @@ async function runPublicFixer(argv, env, io, parseFixerArgv2) {
23611
23796
  throw error;
23612
23797
  }
23613
23798
  await markRunAdmitted(admitted);
23614
- let lease;
23615
- try {
23616
- lease = await acquireRunWriterLease(admitted.runDirectory);
23617
- } catch (error) {
23618
- if (error instanceof RunWriterLeaseHeldError) {
23619
- presentStructuralRejection(error, io);
23620
- return { exitCode: 2 };
23621
- }
23622
- throw error;
23623
- }
23624
23799
  let methodMaterial;
23625
23800
  try {
23626
23801
  methodMaterial = await loadFixerMethodMaterial(env.packageRoot);
23627
23802
  } catch (error) {
23628
- await lease.release();
23629
23803
  return await presentControlledFailure5(
23630
23804
  admitted,
23631
23805
  {
@@ -23637,24 +23811,32 @@ async function runPublicFixer(argv, env, io, parseFixerArgv2) {
23637
23811
  io
23638
23812
  );
23639
23813
  }
23640
- const extraArgs = buildFixerActivationExtraArgs(admitted, {
23641
- packageRoot: env.packageRoot,
23642
- ...env.model === void 0 ? {} : { model: env.model },
23643
- ...env.engine === void 0 ? {} : { engine: env.engine },
23644
- ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
23645
- });
23646
- return await dispatchAdmittedFixer({
23814
+ return runWithAutoResumeLoop({
23647
23815
  admitted,
23648
- env: {
23649
- ...env,
23650
- ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
23651
- },
23652
23816
  io,
23653
- extraArgs,
23654
- lease,
23655
- methodMaterial,
23656
- // #391: only initial Fixer dispatch records mechanical engine provenance.
23657
- ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
23817
+ buildInitialArgs: () => buildFixerActivationExtraArgs(admitted, {
23818
+ packageRoot: env.packageRoot,
23819
+ ...env.model === void 0 ? {} : { model: env.model },
23820
+ ...env.engine === void 0 ? {} : { engine: env.engine },
23821
+ ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
23822
+ }),
23823
+ buildResumeArgs: () => buildFixerResumeActivationExtraArgs(admitted, {
23824
+ packageRoot: env.packageRoot,
23825
+ ...env.model === void 0 ? {} : { model: env.model },
23826
+ ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
23827
+ }),
23828
+ dispatch: (extraArgs, lease, isFirst, attemptIo) => dispatchAdmittedFixer({
23829
+ admitted,
23830
+ env: {
23831
+ ...env,
23832
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
23833
+ },
23834
+ io: attemptIo,
23835
+ extraArgs,
23836
+ lease,
23837
+ methodMaterial,
23838
+ ...isFirst && env.engine !== void 0 ? { effectiveEngine: env.engine } : {}
23839
+ })
23658
23840
  });
23659
23841
  }
23660
23842
  async function runPublicFixerResume(argv, env, io) {
@@ -23686,7 +23868,7 @@ async function runPublicFixerResume(argv, env, io) {
23686
23868
  const { admitted } = loaded;
23687
23869
  let lease;
23688
23870
  try {
23689
- lease = await acquireRunWriterLease(admitted.runDirectory);
23871
+ lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic) => io.stderr(diagnostic));
23690
23872
  } catch (error) {
23691
23873
  if (error instanceof RunWriterLeaseHeldError) {
23692
23874
  io.stderr(formatCliDiagnostic(error.message));
@@ -23715,7 +23897,7 @@ async function runPublicFixerResume(argv, env, io) {
23715
23897
  ...env.model === void 0 ? {} : { model: env.model },
23716
23898
  ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
23717
23899
  });
23718
- return await dispatchAdmittedFixer({
23900
+ const result2 = await dispatchAdmittedFixer({
23719
23901
  admitted,
23720
23902
  env: {
23721
23903
  ...env,
@@ -23726,6 +23908,8 @@ async function runPublicFixerResume(argv, env, io) {
23726
23908
  lease,
23727
23909
  methodMaterial
23728
23910
  });
23911
+ if (result2.terminal !== void 0) result2.terminal.autoResumeCount = 0;
23912
+ return result2;
23729
23913
  }
23730
23914
  var init_fixer_run = __esm({
23731
23915
  "src/public-cli/fixer-run.ts"() {
@@ -23739,6 +23923,7 @@ var init_fixer_run = __esm({
23739
23923
  init_config2();
23740
23924
  init_public_run_credentials();
23741
23925
  init_run_lifecycle();
23926
+ init_auto_resume();
23742
23927
  init_settlement();
23743
23928
  }
23744
23929
  });
@@ -23990,33 +24175,30 @@ async function runPublicJudge(argv, env, io, parseJudgeArgv2) {
23990
24175
  throw error;
23991
24176
  }
23992
24177
  await markRunAdmitted(admitted);
23993
- let lease;
23994
- try {
23995
- lease = await acquireRunWriterLease(admitted.runDirectory);
23996
- } catch (error) {
23997
- if (error instanceof RunWriterLeaseHeldError) {
23998
- presentStructuralRejection(error, io);
23999
- return { exitCode: 2 };
24000
- }
24001
- throw error;
24002
- }
24003
- const extraArgs = buildJudgeActivationExtraArgs(admitted, {
24004
- packageRoot: env.packageRoot,
24005
- ...env.model === void 0 ? {} : { model: env.model },
24006
- ...env.engine === void 0 ? {} : { engine: env.engine },
24007
- ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
24008
- });
24009
- return await dispatchAdmittedJudge({
24178
+ return runWithAutoResumeLoop({
24010
24179
  admitted,
24011
- env: {
24012
- ...env,
24013
- ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
24014
- },
24015
24180
  io,
24016
- extraArgs,
24017
- lease,
24018
- // #358: only initial Judge dispatch records mechanical engine provenance.
24019
- ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
24181
+ buildInitialArgs: () => buildJudgeActivationExtraArgs(admitted, {
24182
+ packageRoot: env.packageRoot,
24183
+ ...env.model === void 0 ? {} : { model: env.model },
24184
+ ...env.engine === void 0 ? {} : { engine: env.engine },
24185
+ ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
24186
+ }),
24187
+ buildResumeArgs: () => buildJudgeResumeActivationExtraArgs(admitted, {
24188
+ ...env.model === void 0 ? {} : { model: env.model },
24189
+ ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
24190
+ }),
24191
+ dispatch: (extraArgs, lease, isFirst, attemptIo) => dispatchAdmittedJudge({
24192
+ admitted,
24193
+ env: {
24194
+ ...env,
24195
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
24196
+ },
24197
+ io: attemptIo,
24198
+ extraArgs,
24199
+ lease,
24200
+ ...isFirst && env.engine !== void 0 ? { effectiveEngine: env.engine } : {}
24201
+ })
24020
24202
  });
24021
24203
  }
24022
24204
  async function runPublicResume(argv, env, io) {
@@ -24048,7 +24230,7 @@ async function runPublicResume(argv, env, io) {
24048
24230
  const { admitted } = loaded;
24049
24231
  let lease;
24050
24232
  try {
24051
- lease = await acquireRunWriterLease(admitted.runDirectory);
24233
+ lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic) => io.stderr(diagnostic));
24052
24234
  } catch (error) {
24053
24235
  if (error instanceof RunWriterLeaseHeldError) {
24054
24236
  io.stderr(formatCliDiagnostic(error.message));
@@ -24060,7 +24242,7 @@ async function runPublicResume(argv, env, io) {
24060
24242
  ...env.model === void 0 ? {} : { model: env.model },
24061
24243
  ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
24062
24244
  });
24063
- return await dispatchAdmittedJudge({
24245
+ const result2 = await dispatchAdmittedJudge({
24064
24246
  admitted,
24065
24247
  env: {
24066
24248
  ...env,
@@ -24070,6 +24252,10 @@ async function runPublicResume(argv, env, io) {
24070
24252
  extraArgs,
24071
24253
  lease
24072
24254
  });
24255
+ if (result2.terminal !== void 0) {
24256
+ result2.terminal.autoResumeCount = 0;
24257
+ }
24258
+ return result2;
24073
24259
  }
24074
24260
  var init_judge_run = __esm({
24075
24261
  "src/public-cli/judge-run.ts"() {
@@ -24082,6 +24268,7 @@ var init_judge_run = __esm({
24082
24268
  init_config2();
24083
24269
  init_public_run_credentials();
24084
24270
  init_run_lifecycle();
24271
+ init_auto_resume();
24085
24272
  init_settlement();
24086
24273
  }
24087
24274
  });
@@ -24419,21 +24606,10 @@ async function runPublicMerger(argv, env, io, parseMergerArgv2) {
24419
24606
  throw error;
24420
24607
  }
24421
24608
  await markRunAdmitted(admitted);
24422
- let lease;
24423
- try {
24424
- lease = await acquireRunWriterLease(admitted.runDirectory);
24425
- } catch (error) {
24426
- if (error instanceof RunWriterLeaseHeldError) {
24427
- presentStructuralRejection(error, io);
24428
- return { exitCode: 2 };
24429
- }
24430
- throw error;
24431
- }
24432
24609
  let methodMaterial;
24433
24610
  try {
24434
24611
  methodMaterial = await loadMergerMethodMaterial(env.packageRoot);
24435
24612
  } catch (error) {
24436
- await lease.release();
24437
24613
  return await presentControlledFailure7(
24438
24614
  admitted,
24439
24615
  {
@@ -24446,23 +24622,32 @@ async function runPublicMerger(argv, env, io, parseMergerArgv2) {
24446
24622
  io
24447
24623
  );
24448
24624
  }
24449
- const extraArgs = buildMergerActivationExtraArgs(admitted, {
24450
- packageRoot: env.packageRoot,
24451
- ...env.model === void 0 ? {} : { model: env.model },
24452
- ...env.engine === void 0 ? {} : { engine: env.engine },
24453
- ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
24454
- });
24455
- return await dispatchAdmittedMerger({
24625
+ return runWithAutoResumeLoop({
24456
24626
  admitted,
24457
- env: {
24458
- ...env,
24459
- ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
24460
- },
24461
24627
  io,
24462
- extraArgs,
24463
- lease,
24464
- methodMaterial,
24465
- ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
24628
+ buildInitialArgs: () => buildMergerActivationExtraArgs(admitted, {
24629
+ packageRoot: env.packageRoot,
24630
+ ...env.model === void 0 ? {} : { model: env.model },
24631
+ ...env.engine === void 0 ? {} : { engine: env.engine },
24632
+ ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
24633
+ }),
24634
+ buildResumeArgs: () => buildMergerResumeActivationExtraArgs(admitted, {
24635
+ packageRoot: env.packageRoot,
24636
+ ...env.model === void 0 ? {} : { model: env.model },
24637
+ ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
24638
+ }),
24639
+ dispatch: (extraArgs, lease, isFirst, attemptIo) => dispatchAdmittedMerger({
24640
+ admitted,
24641
+ env: {
24642
+ ...env,
24643
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
24644
+ },
24645
+ io: attemptIo,
24646
+ extraArgs,
24647
+ lease,
24648
+ methodMaterial,
24649
+ ...isFirst && env.engine !== void 0 ? { effectiveEngine: env.engine } : {}
24650
+ })
24466
24651
  });
24467
24652
  }
24468
24653
  async function runPublicMergerResume(argv, env, io) {
@@ -24494,7 +24679,7 @@ async function runPublicMergerResume(argv, env, io) {
24494
24679
  const { admitted } = loaded;
24495
24680
  let lease;
24496
24681
  try {
24497
- lease = await acquireRunWriterLease(admitted.runDirectory);
24682
+ lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic) => io.stderr(diagnostic));
24498
24683
  } catch (error) {
24499
24684
  if (error instanceof RunWriterLeaseHeldError) {
24500
24685
  io.stderr(formatCliDiagnostic(error.message));
@@ -24524,7 +24709,7 @@ async function runPublicMergerResume(argv, env, io) {
24524
24709
  ...env.model === void 0 ? {} : { model: env.model },
24525
24710
  ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
24526
24711
  });
24527
- return await dispatchAdmittedMerger({
24712
+ const result2 = await dispatchAdmittedMerger({
24528
24713
  admitted,
24529
24714
  env: {
24530
24715
  ...env,
@@ -24535,6 +24720,8 @@ async function runPublicMergerResume(argv, env, io) {
24535
24720
  lease,
24536
24721
  methodMaterial
24537
24722
  });
24723
+ if (result2.terminal !== void 0) result2.terminal.autoResumeCount = 0;
24724
+ return result2;
24538
24725
  }
24539
24726
  var init_merger_run = __esm({
24540
24727
  "src/public-cli/merger-run.ts"() {
@@ -24551,6 +24738,7 @@ var init_merger_run = __esm({
24551
24738
  init_config2();
24552
24739
  init_public_run_credentials();
24553
24740
  init_run_lifecycle();
24741
+ init_auto_resume();
24554
24742
  init_settlement();
24555
24743
  }
24556
24744
  });
@@ -24835,21 +25023,10 @@ async function runPublicReviewer(argv, env, io, parseReviewerArgv2) {
24835
25023
  throw error;
24836
25024
  }
24837
25025
  await markRunAdmitted(admitted);
24838
- let lease;
24839
- try {
24840
- lease = await acquireRunWriterLease(admitted.runDirectory);
24841
- } catch (error) {
24842
- if (error instanceof RunWriterLeaseHeldError) {
24843
- presentStructuralRejection(error, io);
24844
- return { exitCode: 2 };
24845
- }
24846
- throw error;
24847
- }
24848
25026
  let methodMaterial;
24849
25027
  try {
24850
25028
  methodMaterial = await loadReviewerMethodMaterial(env.packageRoot);
24851
25029
  } catch (error) {
24852
- await lease.release();
24853
25030
  return await presentControlledFailure8(
24854
25031
  admitted,
24855
25032
  {
@@ -24861,24 +25038,32 @@ async function runPublicReviewer(argv, env, io, parseReviewerArgv2) {
24861
25038
  io
24862
25039
  );
24863
25040
  }
24864
- const extraArgs = buildReviewerActivationExtraArgs(admitted, {
24865
- packageRoot: env.packageRoot,
24866
- ...env.model === void 0 ? {} : { model: env.model },
24867
- ...env.engine === void 0 ? {} : { engine: env.engine },
24868
- ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
24869
- });
24870
- return await dispatchAdmittedReviewer({
25041
+ return runWithAutoResumeLoop({
24871
25042
  admitted,
24872
- env: {
24873
- ...env,
24874
- ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
24875
- },
24876
25043
  io,
24877
- extraArgs,
24878
- lease,
24879
- methodMaterial,
24880
- // #378: only initial Reviewer dispatch records mechanical engine provenance.
24881
- ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
25044
+ buildInitialArgs: () => buildReviewerActivationExtraArgs(admitted, {
25045
+ packageRoot: env.packageRoot,
25046
+ ...env.model === void 0 ? {} : { model: env.model },
25047
+ ...env.engine === void 0 ? {} : { engine: env.engine },
25048
+ ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
25049
+ }),
25050
+ buildResumeArgs: () => buildReviewerResumeActivationExtraArgs(admitted, {
25051
+ packageRoot: env.packageRoot,
25052
+ ...env.model === void 0 ? {} : { model: env.model },
25053
+ ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
25054
+ }),
25055
+ dispatch: (extraArgs, lease, isFirst, attemptIo) => dispatchAdmittedReviewer({
25056
+ admitted,
25057
+ env: {
25058
+ ...env,
25059
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
25060
+ },
25061
+ io: attemptIo,
25062
+ extraArgs,
25063
+ lease,
25064
+ methodMaterial,
25065
+ ...isFirst && env.engine !== void 0 ? { effectiveEngine: env.engine } : {}
25066
+ })
24882
25067
  });
24883
25068
  }
24884
25069
  async function runPublicReviewerResume(argv, env, io) {
@@ -24910,7 +25095,7 @@ async function runPublicReviewerResume(argv, env, io) {
24910
25095
  const { admitted } = loaded;
24911
25096
  let lease;
24912
25097
  try {
24913
- lease = await acquireRunWriterLease(admitted.runDirectory);
25098
+ lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic) => io.stderr(diagnostic));
24914
25099
  } catch (error) {
24915
25100
  if (error instanceof RunWriterLeaseHeldError) {
24916
25101
  io.stderr(formatCliDiagnostic(error.message));
@@ -24939,7 +25124,7 @@ async function runPublicReviewerResume(argv, env, io) {
24939
25124
  ...env.model === void 0 ? {} : { model: env.model },
24940
25125
  ...env.extraPiArgs === void 0 ? {} : { extraPiArgs: env.extraPiArgs }
24941
25126
  });
24942
- return await dispatchAdmittedReviewer({
25127
+ const result2 = await dispatchAdmittedReviewer({
24943
25128
  admitted,
24944
25129
  env: {
24945
25130
  ...env,
@@ -24950,6 +25135,8 @@ async function runPublicReviewerResume(argv, env, io) {
24950
25135
  lease,
24951
25136
  methodMaterial
24952
25137
  });
25138
+ if (result2.terminal !== void 0) result2.terminal.autoResumeCount = 0;
25139
+ return result2;
24953
25140
  }
24954
25141
  var init_reviewer_run = __esm({
24955
25142
  "src/public-cli/reviewer-run.ts"() {
@@ -24963,6 +25150,7 @@ var init_reviewer_run = __esm({
24963
25150
  init_config2();
24964
25151
  init_public_run_credentials();
24965
25152
  init_run_lifecycle();
25153
+ init_auto_resume();
24966
25154
  init_settlement();
24967
25155
  }
24968
25156
  });