@akagilnc/pi-workflow-roles 0.1.3414 → 0.1.3445

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.
Files changed (72) hide show
  1. package/dist/archivist-record-entry.js +21 -12
  2. package/dist/archivist-record-topology.js +20 -0
  3. package/dist/auditor-dossier-tool.js +67 -76
  4. package/dist/canonical-json.js +66 -69
  5. package/dist/compliance-transport.js +99 -86
  6. package/dist/countersign-contracts.js +23 -25
  7. package/dist/doctor-contracts.js +169 -145
  8. package/dist/engine-detour-tool.js +83 -87
  9. package/dist/engine-detour.js +148 -183
  10. package/dist/evidence-child-executor.js +12 -9
  11. package/dist/exact-utf8.js +11 -10
  12. package/dist/git-object-id.js +10 -5
  13. package/dist/gleaner-left-contracts.js +33 -35
  14. package/dist/grok/production-host.js +239 -154
  15. package/dist/inspector-contracts.js +28 -31
  16. package/dist/institutional-resolution.js +101 -104
  17. package/dist/ledger-session-read.js +241 -0
  18. package/dist/merger-contracts.js +66 -56
  19. package/dist/navigator-attendance.js +0 -6
  20. package/dist/navigator-session-contracts.js +6 -10
  21. package/dist/notary-contracts.js +91 -100
  22. package/dist/open-tool-schema.js +32 -31
  23. package/dist/package-contracts/collector-output.js +56 -43
  24. package/dist/package-contracts/fixer-output.js +52 -50
  25. package/dist/package-contracts/fixer-packet.js +67 -64
  26. package/dist/package-contracts/gatekeeper-output.js +48 -56
  27. package/dist/package-contracts/judge-output.js +23 -20
  28. package/dist/package-contracts/navigator-output.js +35 -40
  29. package/dist/package-contracts/reviewer-output.js +94 -110
  30. package/dist/package-contracts/terminating-infrastructure.js +62 -90
  31. package/dist/package-contracts/worker-output.js +30 -11
  32. package/dist/package-resources/engine-material.js +58 -94
  33. package/dist/pi/in-process-session.js +2 -12
  34. package/dist/public-cli/config.js +403 -485
  35. package/dist/public-cli/main.js +1226 -561
  36. package/dist/public-cli/registry.js +107 -114
  37. package/dist/receipt-delivery-policy.js +74 -76
  38. package/dist/session-opening-materials.js +44 -47
  39. package/dist/sha256.js +5 -3
  40. package/dist/sitian-appender.js +204 -210
  41. package/dist/sitian-contracts.js +15 -19
  42. package/dist/sitian-facade.js +5 -10
  43. package/dist/sitian-reader.js +37 -46
  44. package/dist/stream-idle-guard.js +63 -71
  45. package/dist/ticket-seat-memory.js +244 -0
  46. package/package.json +1 -1
  47. package/scripts/build-package.mjs +41 -0
  48. package/src/analyst-gate-cycles-read.ts +152 -83
  49. package/src/analyst-ledger.ts +170 -43
  50. package/src/archivist-record-entry.ts +32 -11
  51. package/src/archivist-record-topology.ts +39 -0
  52. package/src/evidence-child-executor.ts +18 -10
  53. package/src/grok/production-host.ts +44 -9
  54. package/src/host-contracts.ts +18 -0
  55. package/src/host-transition-prior-native.ts +8 -1
  56. package/src/ledger-session-read.ts +56 -0
  57. package/src/navigator-attendance.ts +0 -6
  58. package/src/navigator-session-contracts.ts +15 -14
  59. package/src/pi/durable-principal.ts +6 -0
  60. package/src/pi/in-process-session.ts +10 -17
  61. package/src/public-cli/cli.ts +2 -14
  62. package/src/public-cli/config.ts +6 -28
  63. package/src/public-cli/inspector-run.ts +21 -10
  64. package/src/public-cli/invocation.ts +8 -25
  65. package/src/public-cli/notary-run.ts +21 -4
  66. package/src/public-cli/option-definitions.ts +2 -2
  67. package/src/public-cli/post-admission.ts +333 -42
  68. package/src/public-cli/registry.ts +2 -8
  69. package/src/public-cli/run-lifecycle.ts +1 -3
  70. package/src/public-cli/settlement.ts +266 -81
  71. package/src/session-opening-materials.ts +4 -2
  72. package/src/ticket-seat-memory.ts +454 -0
@@ -348,6 +348,26 @@ var init_activation_ledger_topology = __esm({
348
348
  }
349
349
  });
350
350
 
351
+ // src/archivist-record-topology.ts
352
+ import { createHash as createHash4 } from "node:crypto";
353
+ import { join as join5 } from "node:path";
354
+ function subjectKeyedRecordDirectory(input) {
355
+ const ledgerHome = input.parentSessionFile !== void 0 && input.parentSessionFile.length > 0 ? resolveActivationLedgerHomeForPath(input.parentSessionFile) : resolveActivationLedgerHome(input.home);
356
+ const digest = createHash4("sha256").update(input.subject).digest("hex").slice(0, 32);
357
+ return join5(
358
+ activationBookDirectory(ledgerHome, resolveBookKeyFromGit(input.cwd)),
359
+ input.kind,
360
+ digest
361
+ );
362
+ }
363
+ var init_archivist_record_topology = __esm({
364
+ "src/archivist-record-topology.ts"() {
365
+ "use strict";
366
+ init_activation_ledger_git();
367
+ init_activation_ledger_topology();
368
+ }
369
+ });
370
+
351
371
  // src/upstream-error-testimony.ts
352
372
  function isNonSuccessHttpStatus(status) {
353
373
  return typeof status === "number" && (status < 200 || status >= 300);
@@ -373,14 +393,15 @@ var init_upstream_error_testimony = __esm({
373
393
  var archivist_record_entry_exports = {};
374
394
  __export(archivist_record_entry_exports, {
375
395
  WORKER_SUBMISSION_GATE_KIND: () => WORKER_SUBMISSION_GATE_KIND,
376
- createRecordSession: () => createRecordSession
396
+ createRecordSession: () => createRecordSession,
397
+ createRecordSessionOpen: () => createRecordSessionOpen,
398
+ subjectKeyedRecordDirectory: () => subjectKeyedRecordDirectory
377
399
  });
378
- import { createHash as createHash4 } from "node:crypto";
379
400
  import { existsSync as existsSync5, readFileSync as readFileSync2, realpathSync as realpathSync2, writeFileSync as writeFileSync3 } from "node:fs";
380
- import { dirname as dirname8, resolve as resolve6, join as join10 } from "node:path";
401
+ import { dirname as dirname8, resolve as resolve6, join as join12 } from "node:path";
381
402
  import { SessionManager } from "@earendil-works/pi-coding-agent";
382
403
  function readCurrentSession(sessionDir) {
383
- const ledger = join10(sessionDir, CURRENT_SESSION_LEDGER);
404
+ const ledger = join12(sessionDir, CURRENT_SESSION_LEDGER);
384
405
  try {
385
406
  const value = JSON.parse(readFileSync2(ledger, "utf8"));
386
407
  if (typeof value !== "object" || value === null || typeof value.sessionFile !== "string" || value.sessionFile.length === 0) {
@@ -395,7 +416,7 @@ function readCurrentSession(sessionDir) {
395
416
  }
396
417
  }
397
418
  function writeCurrentSession(sessionDir, sessionFile) {
398
- const ledger = join10(sessionDir, CURRENT_SESSION_LEDGER);
419
+ const ledger = join12(sessionDir, CURRENT_SESSION_LEDGER);
399
420
  try {
400
421
  writeFileSync3(ledger, `${JSON.stringify({ sessionFile })}
401
422
  `, { flag: "wx" });
@@ -438,25 +459,25 @@ function assertRecentFinalFileUnderSessionDir(sessionDir, recentFile) {
438
459
  );
439
460
  }
440
461
  }
441
- function createRecordSession(options) {
462
+ function createRecordSessionOpen(options) {
442
463
  const cwd = options.cwd;
443
464
  const parentFile = options.parent?.getSessionFile();
444
465
  const ledgerHome = resolveActivationLedgerHomeForPath(parentFile);
445
466
  let sessionDir;
446
467
  let parentSession;
447
468
  if (options.subject !== void 0) {
448
- const digest = createHash4("sha256").update(options.subject).digest("hex").slice(0, 32);
449
- sessionDir = join10(
450
- activationBookDirectory(ledgerHome, resolveBookKeyFromGit(cwd)),
451
- options.kind,
452
- digest
453
- );
469
+ sessionDir = subjectKeyedRecordDirectory({
470
+ cwd,
471
+ kind: options.kind,
472
+ subject: options.subject,
473
+ ...parentFile === void 0 || parentFile.length === 0 ? {} : { parentSessionFile: parentFile }
474
+ });
454
475
  parentSession = parentFile && parentFile.length > 0 ? parentFile : void 0;
455
476
  } else if (parentFile === void 0 || parentFile.length === 0) {
456
- return SessionManager.inMemory(cwd);
477
+ return { session: SessionManager.inMemory(cwd), resumed: false };
457
478
  } else {
458
479
  const parentResolved = resolve6(parentFile);
459
- sessionDir = physicallyContainedIn(ledgerHome, parentResolved) ? join10(dirname8(parentResolved), options.kind) : join10(activationBookDirectory(ledgerHome, resolveBookKeyFromGit(cwd)), options.kind);
480
+ sessionDir = physicallyContainedIn(ledgerHome, parentResolved) ? join12(dirname8(parentResolved), options.kind) : join12(activationBookDirectory(ledgerHome, resolveBookKeyFromGit(cwd)), options.kind);
460
481
  parentSession = parentFile;
461
482
  }
462
483
  const nestAlreadyExists = existsSync5(sessionDir);
@@ -465,7 +486,10 @@ function createRecordSession(options) {
465
486
  if (mayResumeSameNest && nestAlreadyExists) {
466
487
  const recentFile = readCurrentSession(sessionDir);
467
488
  assertRecentFinalFileUnderSessionDir(sessionDir, recentFile);
468
- return SessionManager.open(recentFile, sessionDir, cwd);
489
+ return {
490
+ session: SessionManager.open(recentFile, sessionDir, cwd),
491
+ resumed: true
492
+ };
469
493
  }
470
494
  const session = SessionManager.create(
471
495
  cwd,
@@ -486,7 +510,10 @@ function createRecordSession(options) {
486
510
  writeCurrentSession(sessionDir, file);
487
511
  }
488
512
  }
489
- return session;
513
+ return { session, resumed: false };
514
+ }
515
+ function createRecordSession(options) {
516
+ return createRecordSessionOpen(options).session;
490
517
  }
491
518
  var CURRENT_SESSION_LEDGER, WORKER_SUBMISSION_GATE_KIND;
492
519
  var init_archivist_record_entry = __esm({
@@ -494,6 +521,8 @@ var init_archivist_record_entry = __esm({
494
521
  "use strict";
495
522
  init_activation_ledger_git();
496
523
  init_activation_ledger_topology();
524
+ init_archivist_record_topology();
525
+ init_archivist_record_topology();
497
526
  CURRENT_SESSION_LEDGER = "current-session.json";
498
527
  WORKER_SUBMISSION_GATE_KIND = "worker-submission-gate";
499
528
  }
@@ -575,7 +604,7 @@ __export(in_process_session_exports, {
575
604
  });
576
605
  import { mkdtemp as mkdtemp2, rm as rm2 } from "node:fs/promises";
577
606
  import { tmpdir as tmpdir2 } from "node:os";
578
- import { join as join11 } from "node:path";
607
+ import { join as join13 } from "node:path";
579
608
  import {
580
609
  createAgentSession,
581
610
  DefaultResourceLoader,
@@ -698,7 +727,7 @@ async function openPiInstitutionalSession(options) {
698
727
  let scratchDir;
699
728
  let resolvedAgentDir = options.agentDir;
700
729
  if (resolvedAgentDir === void 0) {
701
- scratchDir = await mkdtemp2(join11(options.credentialScratchParent ?? tmpdir2(), "ak-institutional-"));
730
+ scratchDir = await mkdtemp2(join13(options.credentialScratchParent ?? tmpdir2(), "ak-institutional-"));
702
731
  resolvedAgentDir = scratchDir;
703
732
  }
704
733
  try {
@@ -721,7 +750,7 @@ async function openPiInstitutionalSession(options) {
721
750
  api: fallbackApi,
722
751
  provider: selection.provider,
723
752
  baseUrl: providerDefaultModel?.baseUrl ?? "",
724
- reasoning: selection.thinking !== void 0 && selection.thinking !== "off",
753
+ reasoning: providerDefaultModel?.reasoning ?? false,
725
754
  input: ["text"],
726
755
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
727
756
  contextWindow: 128e3,
@@ -1020,11 +1049,10 @@ async function openPiInstitutionalSession(options) {
1020
1049
  });
1021
1050
  }
1022
1051
  }
1023
- const requestedThinking = options.selection.thinking === "max" ? "max" : "off";
1024
1052
  const { session } = await createAgentSession({
1025
1053
  cwd: options.cwd,
1026
1054
  model: effectiveModel,
1027
- thinkingLevel: requestedThinking,
1055
+ ...options.selection.thinking === void 0 ? {} : { thinkingLevel: options.selection.thinking },
1028
1056
  modelRuntime: runtime,
1029
1057
  sessionManager,
1030
1058
  settingsManager: settings,
@@ -1034,15 +1062,6 @@ async function openPiInstitutionalSession(options) {
1034
1062
  ...options.toolsAllowlist === void 0 ? {} : { tools: options.toolsAllowlist },
1035
1063
  ...customTools.length === 0 ? {} : { customTools }
1036
1064
  });
1037
- if (requestedThinking === "max" && session.thinkingLevel !== "max") {
1038
- session.dispose();
1039
- throw withTypedReason(
1040
- new Error(
1041
- `${label} thinking level max is unavailable for ${selection.provider}/${selection.model}`
1042
- ),
1043
- "thinking"
1044
- );
1045
- }
1046
1065
  const listeners = /* @__PURE__ */ new Set();
1047
1066
  const accumulatedUsage = emptyUsage();
1048
1067
  let lastEmittedAssistant;
@@ -1216,8 +1235,8 @@ var init_in_process_session = __esm({
1216
1235
  });
1217
1236
 
1218
1237
  // src/grok/production-host.ts
1219
- import { readFile as readFile15, rm as rm6, writeFile as writeFile10 } from "node:fs/promises";
1220
- import { join as join25 } from "node:path";
1238
+ import { readFile as readFile16, rm as rm6, writeFile as writeFile11 } from "node:fs/promises";
1239
+ import { join as join27 } from "node:path";
1221
1240
  import { fileURLToPath as fileURLToPath3 } from "node:url";
1222
1241
 
1223
1242
  // src/canonical-skill-binding.ts
@@ -3105,7 +3124,7 @@ import { Type as Type13 } from "typebox";
3105
3124
  // src/evidence-child-executor.ts
3106
3125
  import { mkdtemp as mkdtemp3, rm as rm3 } from "node:fs/promises";
3107
3126
  import { tmpdir as tmpdir3 } from "node:os";
3108
- import { join as join12 } from "node:path";
3127
+ import { join as join14 } from "node:path";
3109
3128
  import "@earendil-works/pi-ai";
3110
3129
 
3111
3130
  // src/sitian-appender.ts
@@ -3388,14 +3407,79 @@ function sitianReport(input) {
3388
3407
  return appendSitianRecord(input);
3389
3408
  }
3390
3409
 
3410
+ // src/ticket-seat-memory.ts
3411
+ import { readFile as readFile4, writeFile } from "node:fs/promises";
3412
+ import { join as join6 } from "node:path";
3413
+ init_activation_ledger_topology();
3414
+ init_archivist_record_topology();
3415
+ var TICKET_SEAT_MEMORY_KIND = "auditor-roles";
3416
+ var TICKET_SEAT_MEMORY_SEATS = ["inspector", "notary", "auditor"];
3417
+ function isTicketSeatMemorySeat(value) {
3418
+ return TICKET_SEAT_MEMORY_SEATS.includes(value);
3419
+ }
3420
+ function isEnoent(error) {
3421
+ return error instanceof Error && "code" in error && error.code === "ENOENT";
3422
+ }
3423
+ function ticketSeatMemorySubject(ticketNumber, seat) {
3424
+ if (!Number.isSafeInteger(ticketNumber) || ticketNumber < 1) {
3425
+ throw new Error(
3426
+ `ticket-seat memory subject requires a positive ticket number, got ${String(ticketNumber)}`
3427
+ );
3428
+ }
3429
+ return `${ticketNumber}:${seat}`;
3430
+ }
3431
+ async function readRunAdmittedPageFacts(runDirectory) {
3432
+ try {
3433
+ const raw = JSON.parse(
3434
+ await readFile4(join6(runDirectory, "admitted-request.json"), "utf8")
3435
+ );
3436
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
3437
+ return {};
3438
+ }
3439
+ const record4 = raw;
3440
+ const ticketNumber = record4.ticketNumber;
3441
+ const projectRoot = record4.projectRoot;
3442
+ return {
3443
+ ...typeof ticketNumber === "number" && Number.isSafeInteger(ticketNumber) && ticketNumber >= 1 ? { ticketNumber } : {},
3444
+ ...typeof projectRoot === "string" ? { projectRoot } : {}
3445
+ };
3446
+ } catch (error) {
3447
+ if (isEnoent(error)) return {};
3448
+ throw error;
3449
+ }
3450
+ }
3451
+ async function readInvocationTicketNumber(runDirectory) {
3452
+ try {
3453
+ const raw = JSON.parse(
3454
+ await readFile4(join6(runDirectory, "invocation.json"), "utf8")
3455
+ );
3456
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
3457
+ return void 0;
3458
+ }
3459
+ const ticketNumber = raw.ticketNumber;
3460
+ if (typeof ticketNumber === "number" && Number.isSafeInteger(ticketNumber) && ticketNumber >= 1) {
3461
+ return ticketNumber;
3462
+ }
3463
+ } catch (error) {
3464
+ if (isEnoent(error)) return void 0;
3465
+ throw error;
3466
+ }
3467
+ return void 0;
3468
+ }
3469
+ async function readRunTicketNumber(runDirectory) {
3470
+ const admitted = await readRunAdmittedPageFacts(runDirectory);
3471
+ if (admitted.ticketNumber !== void 0) return admitted.ticketNumber;
3472
+ return readInvocationTicketNumber(runDirectory);
3473
+ }
3474
+
3391
3475
  // src/engine-detour-tool.ts
3392
3476
  import { Type as Type11 } from "typebox";
3393
3477
 
3394
3478
  // src/engine-detour.ts
3395
3479
  import { spawn as spawn2 } from "node:child_process";
3396
- import { mkdtemp, rm, writeFile } from "node:fs/promises";
3480
+ import { mkdtemp, rm, writeFile as writeFile2 } from "node:fs/promises";
3397
3481
  import { tmpdir } from "node:os";
3398
- import { join as join5 } from "node:path";
3482
+ import { join as join7 } from "node:path";
3399
3483
  var ENGINE_DETOUR_TOOL_NAME = "ak_engine_detour";
3400
3484
  var AK_ROLE_ENGINE_ENV = "AK_ROLE_ENGINE";
3401
3485
  var ENGINE_DETOUR_STAGED_PROMPT_TOKEN = "<<ak-engine-staged-prompt>>";
@@ -3486,12 +3570,12 @@ async function runEngineDetourOnce(input) {
3486
3570
  if (input.stagedPrompt === void 0) {
3487
3571
  return spawnEngineDetourOnce(input);
3488
3572
  }
3489
- const stagingDir = await mkdtemp(join5(tmpdir(), "ak-engine-detour-"));
3490
- const stagedPath = join5(stagingDir, "prompt.txt");
3573
+ const stagingDir = await mkdtemp(join7(tmpdir(), "ak-engine-detour-"));
3574
+ const stagedPath = join7(stagingDir, "prompt.txt");
3491
3575
  let result2;
3492
3576
  let runError;
3493
3577
  try {
3494
- await writeFile(stagedPath, input.stagedPrompt, "utf8");
3578
+ await writeFile2(stagedPath, input.stagedPrompt, "utf8");
3495
3579
  const argv = resolveArgvWithStagedPrompt(input.argv, stagedPath);
3496
3580
  result2 = await spawnEngineDetourOnce({
3497
3581
  argv,
@@ -3623,7 +3707,7 @@ function registerEngineDetourTool(roleHost, hostActions) {
3623
3707
 
3624
3708
  // src/package-resources/engine-material.ts
3625
3709
  import { existsSync as existsSync4, readdirSync } from "node:fs";
3626
- import { join as join6 } from "node:path";
3710
+ import { join as join8 } from "node:path";
3627
3711
  var ENGINE_MATERIAL_RELATIVE_ROOT = "resources/engines";
3628
3712
  function isEngineNameSyntax(name) {
3629
3713
  if (typeof name !== "string") return false;
@@ -3633,11 +3717,11 @@ function isEngineNameSyntax(name) {
3633
3717
  return true;
3634
3718
  }
3635
3719
  function resolveEngineMaterialDirectory(packageRoot) {
3636
- return join6(packageRoot, ENGINE_MATERIAL_RELATIVE_ROOT);
3720
+ return join8(packageRoot, ENGINE_MATERIAL_RELATIVE_ROOT);
3637
3721
  }
3638
3722
  function resolveEngineMaterialPath(packageRoot, name) {
3639
3723
  const legal = assertLegalEngineName(name);
3640
- return join6(resolveEngineMaterialDirectory(packageRoot), `${legal}.md`);
3724
+ return join8(resolveEngineMaterialDirectory(packageRoot), `${legal}.md`);
3641
3725
  }
3642
3726
  function assertLegalEngineName(name) {
3643
3727
  if (!isEngineNameSyntax(name)) {
@@ -3674,8 +3758,8 @@ function appendEngineSessionMaterial(lines, engineMaterial) {
3674
3758
  }
3675
3759
 
3676
3760
  // src/institutional-resolution.ts
3677
- import { readFile as readFile4, writeFile as writeFile2 } from "node:fs/promises";
3678
- import { join as join7 } from "node:path";
3761
+ import { readFile as readFile5, writeFile as writeFile3 } from "node:fs/promises";
3762
+ import { join as join9 } from "node:path";
3679
3763
 
3680
3764
  // src/public-cli/registry.ts
3681
3765
  var PUBLIC_CALLABLE_ROLES = PACKAGED_ROLE_REGISTRY.map(
@@ -3705,10 +3789,10 @@ function cleanSelection(model) {
3705
3789
  };
3706
3790
  }
3707
3791
  async function readInstitutionalSeatSelection(runDirectory, seat) {
3708
- const filePath = join7(runDirectory, INSTITUTIONAL_RESOLUTION_FILE);
3792
+ const filePath = join9(runDirectory, INSTITUTIONAL_RESOLUTION_FILE);
3709
3793
  let raw;
3710
3794
  try {
3711
- raw = await readFile4(filePath, "utf8");
3795
+ raw = await readFile5(filePath, "utf8");
3712
3796
  } catch (error) {
3713
3797
  throw new InstitutionalResolutionError(
3714
3798
  `institutional resolution page is missing at ${filePath}`,
@@ -3750,9 +3834,9 @@ async function readInstitutionalSeatSelection(runDirectory, seat) {
3750
3834
  }
3751
3835
 
3752
3836
  // src/navigator-session-contracts.ts
3753
- import { mkdir, readFile as readFile5, writeFile as writeFile3 } from "node:fs/promises";
3837
+ import { mkdir, readFile as readFile6, writeFile as writeFile4 } from "node:fs/promises";
3754
3838
  import { homedir as homedir2 } from "node:os";
3755
- import { dirname as dirname7, join as join8 } from "node:path";
3839
+ import { dirname as dirname7, join as join10 } from "node:path";
3756
3840
  import { Type as Type12 } from "typebox";
3757
3841
  import { Value as Value2 } from "typebox/value";
3758
3842
  var NAVIGATOR_PREPARE_TOOL_NAME = "ak_navigator_prepare";
@@ -3867,11 +3951,11 @@ var navigatorProviderFailureSchema = Type12.Object({
3867
3951
  ])
3868
3952
  }, { additionalProperties: false });
3869
3953
  function navigatorModelSettingPath() {
3870
- return join8(process.env.PI_CODING_AGENT_DIR ?? join8(homedir2(), ".pi", "agent"), "navigator-model.json");
3954
+ return join10(process.env.PI_CODING_AGENT_DIR ?? join10(homedir2(), ".pi", "agent"), "navigator-model.json");
3871
3955
  }
3872
3956
  async function readNavigatorModelSetting(path = navigatorModelSettingPath()) {
3873
3957
  try {
3874
- const raw = JSON.parse(await readFile5(path, "utf8"));
3958
+ const raw = JSON.parse(await readFile6(path, "utf8"));
3875
3959
  if (!exactRecord(raw) || typeof raw.model !== "string" || raw.model.trim() === "") {
3876
3960
  throw new Error("Navigator model setting is malformed");
3877
3961
  }
@@ -3886,33 +3970,29 @@ async function readNavigatorModelSetting(path = navigatorModelSettingPath()) {
3886
3970
  function parseNavigatorModelSetting(value) {
3887
3971
  const slash = value.indexOf("/");
3888
3972
  if (slash <= 0 || slash === value.length - 1) {
3889
- throw new Error("Navigator model setting must be provider/model[:max]");
3973
+ throw new Error("Navigator model setting must be provider/model[:thinking]");
3890
3974
  }
3891
3975
  const provider = value.slice(0, slash);
3892
3976
  const modelWithThinking = value.slice(slash + 1);
3893
3977
  const colon = modelWithThinking.lastIndexOf(":");
3894
3978
  const suffix = colon < 0 ? void 0 : modelWithThinking.slice(colon + 1);
3895
- if (suffix !== void 0 && suffix !== "max") {
3896
- throw new Error("Navigator model setting must use :max or omit the thinking suffix");
3897
- }
3898
3979
  const model = colon < 0 ? modelWithThinking : modelWithThinking.slice(0, colon);
3899
3980
  if (model === "") throw new Error("Navigator model setting must include a model");
3900
- return { provider, model, thinkingLevel: suffix === "max" ? "max" : "off" };
3981
+ return suffix === void 0 ? { provider, model } : { provider, model, thinkingLevel: suffix };
3901
3982
  }
3902
3983
  async function resolveNavigatorSeatSelection(context, modelSettingPath, defaultModelSettingPath) {
3903
3984
  const runDirectory = auditorRunDirectory(context);
3904
3985
  if (runDirectory !== void 0) {
3905
3986
  try {
3906
3987
  const selection = await readInstitutionalSeatSelection(runDirectory, "navigator");
3907
- const thinkingLevel = selection.thinking === "max" ? "max" : "off";
3908
3988
  return {
3909
3989
  selection: {
3910
3990
  provider: selection.provider,
3911
3991
  model: selection.model,
3912
3992
  ...selection.thinking === void 0 ? {} : { thinking: selection.thinking }
3913
3993
  },
3914
- configuredLabel: `${selection.provider}/${selection.model}${thinkingLevel === "max" ? ":max" : ""}`,
3915
- thinkingLevel
3994
+ configuredLabel: selection.thinking === void 0 ? `${selection.provider}/${selection.model}` : `${selection.provider}/${selection.model}:${selection.thinking}`,
3995
+ ...selection.thinking === void 0 ? {} : { thinkingLevel: selection.thinking }
3916
3996
  };
3917
3997
  } catch (error) {
3918
3998
  if (error instanceof InstitutionalResolutionError && (error.reason === "missing-page" || error.reason === "missing-seat")) {
@@ -3937,10 +4017,10 @@ async function resolveNavigatorSeatSelection(context, modelSettingPath, defaultM
3937
4017
  selection: {
3938
4018
  provider: parsed.provider,
3939
4019
  model: parsed.model,
3940
- thinking: parsed.thinkingLevel
4020
+ ...parsed.thinkingLevel === void 0 ? {} : { thinking: parsed.thinkingLevel }
3941
4021
  },
3942
4022
  configuredLabel: configured,
3943
- thinkingLevel: parsed.thinkingLevel
4023
+ ...parsed.thinkingLevel === void 0 ? {} : { thinkingLevel: parsed.thinkingLevel }
3944
4024
  };
3945
4025
  }
3946
4026
 
@@ -3998,11 +4078,11 @@ function createReceiptDeliveryPolicy() {
3998
4078
  }
3999
4079
 
4000
4080
  // src/typed-provider-http.ts
4001
- import { readFile as readFile6, unlink, writeFile as writeFile4 } from "node:fs/promises";
4002
- import { join as join9 } from "node:path";
4081
+ import { readFile as readFile7, unlink, writeFile as writeFile5 } from "node:fs/promises";
4082
+ import { join as join11 } from "node:path";
4003
4083
  var TYPED_HTTP_FILE = "typed-provider-http.json";
4004
4084
  function typedProviderHttpPath(runDirectory) {
4005
- return join9(runDirectory, TYPED_HTTP_FILE);
4085
+ return join11(runDirectory, TYPED_HTTP_FILE);
4006
4086
  }
4007
4087
  async function clearTypedProviderHttpObservation(runDirectory) {
4008
4088
  try {
@@ -4023,7 +4103,7 @@ async function recordTypedProviderHttpStatus(runDirectory, observation) {
4023
4103
  httpStatus: observation.httpStatus,
4024
4104
  provider: observation.provider
4025
4105
  };
4026
- await writeFile4(
4106
+ await writeFile5(
4027
4107
  typedProviderHttpPath(runDirectory),
4028
4108
  `${JSON.stringify(body)}
4029
4109
  `,
@@ -4044,7 +4124,7 @@ async function buildEvidenceChildSystemPrompt(engineMaterial) {
4044
4124
  return appendEngineSessionMaterial(materials, engineMaterial).join("\n");
4045
4125
  }
4046
4126
  async function withInProcessScratch(options, run) {
4047
- const scratch = await mkdtemp3(join12(options.parentDirectory ?? tmpdir3(), options.prefix));
4127
+ const scratch = await mkdtemp3(join14(options.parentDirectory ?? tmpdir3(), options.prefix));
4048
4128
  let failure2;
4049
4129
  try {
4050
4130
  return await run(scratch);
@@ -4324,9 +4404,12 @@ async function executeAuditorChild(options) {
4324
4404
  const parentHeader = parentSessionManager?.getHeader?.();
4325
4405
  const parentSessionFile = parentSessionManager?.getSessionFile?.();
4326
4406
  const parentAttemptEntryId = parentSessionManager?.getLeafId?.();
4407
+ const ticketNumber = await readRunTicketNumber(runDirectory);
4408
+ const memorySubject = ticketNumber !== void 0 && isTicketSeatMemorySeat(seat) ? ticketSeatMemorySubject(ticketNumber, seat) : void 0;
4327
4409
  const auditorSessionManager = createRecordSession2({
4328
4410
  cwd,
4329
- kind: "auditor-roles",
4411
+ kind: TICKET_SEAT_MEMORY_KIND,
4412
+ ...memorySubject === void 0 ? {} : { subject: memorySubject },
4330
4413
  ...parentSessionManager === void 0 ? {} : { parent: parentSessionManager }
4331
4414
  });
4332
4415
  const { openPiInstitutionalSession: openPiInstitutionalSession2 } = await Promise.resolve().then(() => (init_in_process_session(), in_process_session_exports));
@@ -4755,7 +4838,7 @@ function createNativeNavigatorSessionFactory(defaultModelSettingPath = navigator
4755
4838
  }
4756
4839
  },
4757
4840
  entries: () => sessionManager.getEntries(),
4758
- setModel: async (next, nextThinking) => {
4841
+ setModel: async (next) => {
4759
4842
  let nextParsed;
4760
4843
  try {
4761
4844
  nextParsed = parseNavigatorModelSetting(next);
@@ -4768,16 +4851,10 @@ function createNativeNavigatorSessionFactory(defaultModelSettingPath = navigator
4768
4851
  `Navigator model switch requires a new session: ${configuredLabel} \u2192 ${next}`
4769
4852
  );
4770
4853
  }
4771
- if (nextParsed.thinkingLevel !== nextThinking || thinkingLevel !== nextThinking) {
4772
- throw new NavigatorUnavailableError(
4773
- "thinking",
4774
- `Navigator thinking level ${nextThinking} is unavailable for ${next}`
4775
- );
4776
- }
4777
4854
  selection = {
4778
4855
  provider: nextParsed.provider,
4779
4856
  model: nextParsed.model,
4780
- thinking: nextParsed.thinkingLevel
4857
+ ...nextParsed.thinkingLevel === void 0 ? {} : { thinking: nextParsed.thinkingLevel }
4781
4858
  };
4782
4859
  thinkingLevel = nextParsed.thinkingLevel;
4783
4860
  configuredLabel = next;
@@ -4985,7 +5062,7 @@ function createPiDoctorAuditor() {
4985
5062
  }
4986
5063
 
4987
5064
  // src/doctor-evidence.ts
4988
- import { readdir, readFile as readFile7, realpath as realpath2, stat } from "node:fs/promises";
5065
+ import { readdir, readFile as readFile8, realpath as realpath2, stat } from "node:fs/promises";
4989
5066
  import { dirname as dirname9, relative as relative2, resolve as resolve8, sep as sep2 } from "node:path";
4990
5067
 
4991
5068
  // src/audit-escalation.ts
@@ -5387,7 +5464,7 @@ async function loadDoctorCase(runsPath) {
5387
5464
  const turns = { count: 0, sources: [] }, calls = { count: 0, sources: [] }, tokens = { count: 0, sources: [] };
5388
5465
  for (const path of await discoverCaseFiles(root)) {
5389
5466
  const id = relative2(root, path).split(sep2).join("/");
5390
- const bytes = await readFile7(path);
5467
+ const bytes = await readFile8(path);
5391
5468
  const content = bytes.toString("utf8");
5392
5469
  const kind = id.endsWith(".jsonl") ? "session" : "stderr";
5393
5470
  evidence.push({ id, kind, byteLength: bytes.byteLength, contentLength: content.length, sha256: sha256Hex(bytes), content });
@@ -6098,9 +6175,6 @@ ${text}
6098
6175
  try {
6099
6176
  await created.setModel?.(modelSetting, model.thinkingLevel);
6100
6177
  if (disposed) throw navigatorUnavailableError("session", new Error("Navigator attendance was disposed"));
6101
- if (created.getThinkingLevel?.() !== void 0 && created.getThinkingLevel() !== model.thinkingLevel) {
6102
- throw new NavigatorUnavailableError("thinking", `Navigator thinking level ${model.thinkingLevel} is unavailable for ${modelSetting}`);
6103
- }
6104
6178
  created.appendEntry(INVOCATION_ENTRY, { invocationId, role: options.role, phase: options.phase, subjectKey });
6105
6179
  if (disposed) throw navigatorUnavailableError("session", new Error("Navigator attendance was disposed"));
6106
6180
  session = created;
@@ -6115,9 +6189,6 @@ ${text}
6115
6189
  } else {
6116
6190
  try {
6117
6191
  await session.setModel?.(modelSetting, model.thinkingLevel);
6118
- if (session.getThinkingLevel?.() !== void 0 && session.getThinkingLevel() !== model.thinkingLevel) {
6119
- throw new NavigatorUnavailableError("thinking", `Navigator thinking level ${model.thinkingLevel} is unavailable for ${modelSetting}`);
6120
- }
6121
6192
  } catch (error) {
6122
6193
  throw error instanceof NavigatorUnavailableError ? error : navigatorUnavailableError("session", error);
6123
6194
  }
@@ -6398,23 +6469,23 @@ ${helpContext}
6398
6469
  }
6399
6470
 
6400
6471
  // src/navigator-work-context.ts
6401
- import { readFile as readFile11 } from "node:fs/promises";
6472
+ import { readFile as readFile12 } from "node:fs/promises";
6402
6473
  import { resolve as resolve13 } from "node:path";
6403
6474
 
6404
6475
  // src/notary-source-run.ts
6405
6476
  init_activation_ledger_git();
6406
6477
  init_activation_ledger_topology();
6407
- import { dirname as dirname11, isAbsolute as isAbsolute4, join as join16, resolve as resolve12, basename as basename5 } from "node:path";
6478
+ import { dirname as dirname11, isAbsolute as isAbsolute4, join as join18, resolve as resolve12, basename as basename5 } from "node:path";
6408
6479
  import { lstat as lstat2, realpath as realpath4 } from "node:fs/promises";
6409
6480
 
6410
6481
  // src/public-cli/run-lifecycle.ts
6411
6482
  init_activation_ledger_topology();
6412
- import { chmod, open, readdir as readdir2, readFile as readFile10, unlink as unlink2, writeFile as writeFile6 } from "node:fs/promises";
6413
- import { join as join15 } from "node:path";
6483
+ import { chmod, open, readdir as readdir2, readFile as readFile11, unlink as unlink2, writeFile as writeFile7 } from "node:fs/promises";
6484
+ import { join as join17 } from "node:path";
6414
6485
 
6415
6486
  // src/collector-config.ts
6416
6487
  import { createHash as createHash6 } from "node:crypto";
6417
- import { readFile as readFile8 } from "node:fs/promises";
6488
+ import { readFile as readFile9 } from "node:fs/promises";
6418
6489
  var COLLECTOR_HOST = "github.com";
6419
6490
  var COLLECTOR_OWNER_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;
6420
6491
  var COLLECTOR_REPO_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,98}[A-Za-z0-9])?$/;
@@ -6461,7 +6532,7 @@ function emptyCollectorManifest() {
6461
6532
  async function loadCollectorManifest(path) {
6462
6533
  let bytes;
6463
6534
  try {
6464
- bytes = await readFile8(path);
6535
+ bytes = await readFile9(path);
6465
6536
  } catch (error) {
6466
6537
  fail3(`Collector request manifest is unreadable at ${path}`, error);
6467
6538
  }
@@ -6492,11 +6563,11 @@ init_activation_ledger_git();
6492
6563
  import {
6493
6564
  lstat,
6494
6565
  mkdir as mkdir2,
6495
- readFile as readFile9,
6566
+ readFile as readFile10,
6496
6567
  realpath as realpath3,
6497
- writeFile as writeFile5
6568
+ writeFile as writeFile6
6498
6569
  } from "node:fs/promises";
6499
- import { basename as basename4, isAbsolute as isAbsolute3, join as join14, resolve as resolve11, sep as sep3 } from "node:path";
6570
+ import { basename as basename4, isAbsolute as isAbsolute3, join as join16, resolve as resolve11, sep as sep3 } from "node:path";
6500
6571
 
6501
6572
  // src/public-cli/option-definitions.ts
6502
6573
  var SHARED_PROJECT_SEMANTICS = {
@@ -6959,7 +7030,7 @@ var PUBLIC_COMMAND_HELP = {
6959
7030
  async function loadAdmittedJudgeRequest(runDirectory) {
6960
7031
  try {
6961
7032
  const raw = JSON.parse(
6962
- await readFile9(join14(runDirectory, "admitted-request.json"), "utf8")
7033
+ await readFile10(join16(runDirectory, "admitted-request.json"), "utf8")
6963
7034
  );
6964
7035
  if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
6965
7036
  const record4 = raw;
@@ -6986,7 +7057,7 @@ function isV1ResumableProvider(provider) {
6986
7057
  async function readRoleRunStateDisk(runDirectory) {
6987
7058
  let raw;
6988
7059
  try {
6989
- raw = JSON.parse(await readFile10(join15(runDirectory, RUN_STATE_FILE), "utf8"));
7060
+ raw = JSON.parse(await readFile11(join17(runDirectory, RUN_STATE_FILE), "utf8"));
6990
7061
  } catch {
6991
7062
  return void 0;
6992
7063
  }
@@ -7127,7 +7198,7 @@ function navigatorInputReference(getFlag, role) {
7127
7198
  }
7128
7199
  async function loadNavigatorWorkContext(options) {
7129
7200
  const reference = navigatorInputReference(options.getFlag, options.role);
7130
- const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile11(reference, "utf8");
7201
+ const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile12(reference, "utf8");
7131
7202
  const subjectRoot = subjectPath(reference ?? options.context.sessionManager.getSessionDir(), options.context.cwd);
7132
7203
  let subjectKey = reference === void 0 ? subjectRoot : navigatorSubjectKeyForInput(subjectRoot, reference, options.context.cwd);
7133
7204
  let subject = input ?? `work subject: ${subjectKey}`;
@@ -7184,7 +7255,7 @@ async function loadNavigatorWorkContext(options) {
7184
7255
  let authorityMaterial;
7185
7256
  for (const path of authorityFiles) {
7186
7257
  try {
7187
- const content = await readFile11(path, "utf8");
7258
+ const content = await readFile12(path, "utf8");
7188
7259
  if (content.trim() !== "") {
7189
7260
  authorityMaterial = content;
7190
7261
  break;
@@ -7210,8 +7281,8 @@ import { dirname as dirname12 } from "node:path";
7210
7281
 
7211
7282
  // src/package-resources/method-skill.ts
7212
7283
  import { createHash as createHash7 } from "node:crypto";
7213
- import { readFile as readFile12, realpath as realpath5 } from "node:fs/promises";
7214
- import { join as join17 } from "node:path";
7284
+ import { readFile as readFile13, realpath as realpath5 } from "node:fs/promises";
7285
+ import { join as join19 } from "node:path";
7215
7286
  var PackagedMethodSkillUnavailableError = class extends Error {
7216
7287
  constructor(skillName, path, cause) {
7217
7288
  super(`Canonical ${skillName} Skill is unavailable at ${path}`, { cause });
@@ -7247,10 +7318,10 @@ function packagedMethodSkillRelativeDirectory(name) {
7247
7318
  return `${METHOD_SKILL_RELATIVE_ROOT}/${name}`;
7248
7319
  }
7249
7320
  function resolvePackagedMethodSkillRoot(packageRoot, name) {
7250
- return join17(packageRoot, packagedMethodSkillRelativeDirectory(name));
7321
+ return join19(packageRoot, packagedMethodSkillRelativeDirectory(name));
7251
7322
  }
7252
7323
  function resolvePackagedMethodSkillPath(packageRoot, name) {
7253
- return join17(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
7324
+ return join19(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
7254
7325
  }
7255
7326
  function isRecord11(value) {
7256
7327
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -7344,11 +7415,11 @@ function parseProvenance(raw, expectedName) {
7344
7415
  }
7345
7416
  async function loadPackagedMethodSkillMaterial(packageRoot, name) {
7346
7417
  const rootDirectory = resolvePackagedMethodSkillRoot(packageRoot, name);
7347
- const skillPathConfigured = join17(rootDirectory, "SKILL.md");
7348
- const provenancePath = join17(rootDirectory, "provenance.json");
7418
+ const skillPathConfigured = join19(rootDirectory, "SKILL.md");
7419
+ const provenancePath = join19(rootDirectory, "provenance.json");
7349
7420
  let provenanceRaw;
7350
7421
  try {
7351
- provenanceRaw = await readFile12(provenancePath, "utf8");
7422
+ provenanceRaw = await readFile13(provenancePath, "utf8");
7352
7423
  } catch (error) {
7353
7424
  throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
7354
7425
  }
@@ -7362,10 +7433,10 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
7362
7433
  }
7363
7434
  const provenance = parseProvenance(provenanceJson, name);
7364
7435
  for (const [rel, expected] of Object.entries(provenance.files)) {
7365
- const absolute = join17(rootDirectory, rel);
7436
+ const absolute = join19(rootDirectory, rel);
7366
7437
  let bytes;
7367
7438
  try {
7368
- bytes = await readFile12(absolute);
7439
+ bytes = await readFile13(absolute);
7369
7440
  } catch (error) {
7370
7441
  throw new PackagedMethodSkillUnavailableError(name, absolute, error);
7371
7442
  }
@@ -7381,7 +7452,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
7381
7452
  let raw;
7382
7453
  try {
7383
7454
  skillPath = await realpath5(skillPathConfigured);
7384
- raw = await readFile12(skillPath, "utf8");
7455
+ raw = await readFile13(skillPath, "utf8");
7385
7456
  } catch (error) {
7386
7457
  throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
7387
7458
  }
@@ -7475,7 +7546,7 @@ async function executeReviewerChild(workspace, leg, context, options = {}) {
7475
7546
  import { spawn as spawn3 } from "node:child_process";
7476
7547
  import { mkdtemp as mkdtemp4, rm as rm4 } from "node:fs/promises";
7477
7548
  import { tmpdir as tmpdir4 } from "node:os";
7478
- import { join as join18 } from "node:path";
7549
+ import { join as join20 } from "node:path";
7479
7550
 
7480
7551
  // src/reviewer-git-snapshot.ts
7481
7552
  var REVIEW_REF_PREFIXES = ["refs/heads", "refs/tags", "refs/remotes"];
@@ -7576,8 +7647,8 @@ async function prepareSnapshot(accepted, signal, dependencies) {
7576
7647
  if (!sameReviewerPinnedTarget({ repositoryRoot: accepted.repositoryRoot, objectFormat, targetHead }, accepted)) throw new Error("Accepted Reviewer target identity no longer matches the repository");
7577
7648
  await git2(accepted.repositoryRoot, ["cat-file", "-e", `${targetHead}^{commit}`], signal);
7578
7649
  dependencies.fault?.("mirror.before-create");
7579
- mirrorRoot = await mkdtemp4(join18(tmpdir4(), "ak-reviewer-snapshot-"));
7580
- const mirrorPath = join18(mirrorRoot, "repository.git");
7650
+ mirrorRoot = await mkdtemp4(join20(tmpdir4(), "ak-reviewer-snapshot-"));
7651
+ const mirrorPath = join20(mirrorRoot, "repository.git");
7581
7652
  dependencies.fault?.("mirror.create");
7582
7653
  await runCommand("git", ["init", "--bare", `--object-format=${accepted.objectFormat}`, mirrorPath], signal === void 0 ? {} : { signal });
7583
7654
  await git2(mirrorPath, ["fetch", "--no-tags", accepted.repositoryRoot, targetHead], signal);
@@ -7594,7 +7665,7 @@ async function prepareClone(snapshot, signal, dependencies) {
7594
7665
  const target = { repositoryRoot: snapshot.repositoryRoot, objectFormat: snapshot.objectFormat, targetHead: snapshot.targetHead, refs: { ...snapshot.refs } };
7595
7666
  try {
7596
7667
  dependencies.fault?.("workspace.before-create");
7597
- workspace = await mkdtemp4(join18(tmpdir4(), "ak-reviewer-leg-"));
7668
+ workspace = await mkdtemp4(join20(tmpdir4(), "ak-reviewer-leg-"));
7598
7669
  dependencies.fault?.("workspace.init");
7599
7670
  await git2(workspace, ["init", `--object-format=${snapshot.objectFormat}`, "--initial-branch=ak-reviewer-unborn"], signal);
7600
7671
  dependencies.fault?.("workspace.fetch");
@@ -7776,7 +7847,7 @@ function stringEnum(values, options = {}) {
7776
7847
 
7777
7848
  // src/public-cli/reviewer-dispatch-rejection.ts
7778
7849
  import { writeFileSync as writeFileSync4 } from "node:fs";
7779
- import { join as join19 } from "node:path";
7850
+ import { join as join21 } from "node:path";
7780
7851
 
7781
7852
  // src/adr-path-refs.ts
7782
7853
  var ADR_PATH_IN_BODY = /docs\/adr\/(?:[A-Za-z0-9][A-Za-z0-9._-]*\/)*[A-Za-z0-9][A-Za-z0-9._-]*\.md/g;
@@ -8375,7 +8446,7 @@ function createReviewerDispatcher(d) {
8375
8446
  // src/public-cli/reviewer-dispatch-rejection.ts
8376
8447
  var REVIEWER_DISPATCH_REJECTION_FILE = "typed-known-failure.json";
8377
8448
  function reviewerDispatchRejectionPath(runDirectory) {
8378
- return join19(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
8449
+ return join21(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
8379
8450
  }
8380
8451
  function recordReviewerDispatchRejectionSync(runDirectory, rejection) {
8381
8452
  writeFileSync4(
@@ -8543,7 +8614,7 @@ async function requireGatekeeperPass(options) {
8543
8614
  }
8544
8615
 
8545
8616
  // src/run-terminal-artifacts.ts
8546
- import { basename as basename6, dirname as dirname13, join as join20 } from "node:path";
8617
+ import { basename as basename6, dirname as dirname13, join as join22 } from "node:path";
8547
8618
  function runIdFromRunDirectory(runDirectory) {
8548
8619
  const name = basename6(runDirectory);
8549
8620
  const at = name.lastIndexOf("@");
@@ -13493,15 +13564,15 @@ function createRoleRuntimeExtension(dependencies) {
13493
13564
 
13494
13565
  // src/grok/role-envelope.ts
13495
13566
  import { randomUUID as randomUUID2 } from "node:crypto";
13496
- import { mkdir as mkdir5, readFile as readFile13, writeFile as writeFile8 } from "node:fs/promises";
13567
+ import { mkdir as mkdir5, readFile as readFile14, writeFile as writeFile9 } from "node:fs/promises";
13497
13568
  import { createServer } from "node:net";
13498
- import { basename as basename8, dirname as dirname16, join as join23 } from "node:path";
13569
+ import { basename as basename8, dirname as dirname16, join as join25 } from "node:path";
13499
13570
  import { fileURLToPath as fileURLToPath2 } from "node:url";
13500
13571
 
13501
13572
  // src/grok/role-turn-host.ts
13502
13573
  import { execFile as execFile3, spawn as spawn4 } from "node:child_process";
13503
13574
  import { copyFile, lstat as lstat3, mkdir as mkdir4, open as open2, realpath as realpath7, rm as rm5 } from "node:fs/promises";
13504
- import { basename as basename7, dirname as dirname15, isAbsolute as isAbsolute7, join as join22, relative as pathRelative } from "node:path";
13575
+ import { basename as basename7, dirname as dirname15, isAbsolute as isAbsolute7, join as join24, relative as pathRelative } from "node:path";
13505
13576
  import { createInterface } from "node:readline";
13506
13577
  import { promisify as promisify3 } from "node:util";
13507
13578
 
@@ -13512,8 +13583,8 @@ function renderAgentStartMaterials(body, materials) {
13512
13583
  }
13513
13584
 
13514
13585
  // src/grok/bash-seatbelt.ts
13515
- import { mkdir as mkdir3, writeFile as writeFile7 } from "node:fs/promises";
13516
- import { join as join21 } from "node:path";
13586
+ import { mkdir as mkdir3, writeFile as writeFile8 } from "node:fs/promises";
13587
+ import { join as join23 } from "node:path";
13517
13588
  function renderGrokBashSeatbeltHookScript() {
13518
13589
  const reasons = Object.fromEntries(
13519
13590
  FIXER_BASH_FORBIDDEN_LITERALS.map((literal) => [literal, fixerBashSeatbeltDenyReason(literal)])
@@ -13541,12 +13612,12 @@ process.stdin.on("end", () => {
13541
13612
  `;
13542
13613
  }
13543
13614
  async function installGrokPreToolUseDeny(controlledHome) {
13544
- const hooksDir = join21(controlledHome, "hooks");
13615
+ const hooksDir = join23(controlledHome, "hooks");
13545
13616
  await mkdir3(hooksDir, { recursive: true });
13546
13617
  const scriptName = "ak-bash-seatbelt.mjs";
13547
- const scriptPath = join21(hooksDir, scriptName);
13548
- await writeFile7(scriptPath, renderGrokBashSeatbeltHookScript(), { mode: 493 });
13549
- await writeFile7(join21(hooksDir, "ak-bash-seatbelt.json"), `${JSON.stringify({
13618
+ const scriptPath = join23(hooksDir, scriptName);
13619
+ await writeFile8(scriptPath, renderGrokBashSeatbeltHookScript(), { mode: 493 });
13620
+ await writeFile8(join23(hooksDir, "ak-bash-seatbelt.json"), `${JSON.stringify({
13550
13621
  hooks: {
13551
13622
  PreToolUse: [
13552
13623
  {
@@ -13919,7 +13990,7 @@ async function resolveHeadTreePath(topLevel, relativePath) {
13919
13990
  encoding: "utf8"
13920
13991
  });
13921
13992
  const needle = leaf.toLowerCase();
13922
- const hits = listing.split("\n").map((name) => name.trim()).filter((name) => name !== "" && basename7(name).toLowerCase() === needle).map((name) => parent === "." ? basename7(name) : join22(parent, basename7(name)));
13993
+ const hits = listing.split("\n").map((name) => name.trim()).filter((name) => name !== "" && basename7(name).toLowerCase() === needle).map((name) => parent === "." ? basename7(name) : join24(parent, basename7(name)));
13923
13994
  return hits.length === 1 ? hits[0] : void 0;
13924
13995
  }
13925
13996
  async function isHeadMatchedProjectInstruction(repositoryCwd, absolutePath) {
@@ -13937,14 +14008,14 @@ async function isHeadMatchedProjectInstruction(repositoryCwd, absolutePath) {
13937
14008
  if (parent === void 0) return false;
13938
14009
  const leaf = basename7(absolutePath);
13939
14010
  if (leaf === "" || leaf === "." || leaf === "..") return false;
13940
- const candidate = join22(parent, leaf);
14011
+ const candidate = join24(parent, leaf);
13941
14012
  const relative3 = pathRelative(topLevel, candidate);
13942
14013
  if (relative3 === "" || relative3.startsWith("..") || isAbsolute7(relative3) || relative3.includes("\0")) {
13943
14014
  return false;
13944
14015
  }
13945
14016
  const headRel = await resolveHeadTreePath(topLevel, relative3);
13946
14017
  if (headRel === void 0) return false;
13947
- const headFile = join22(topLevel, headRel);
14018
+ const headFile = join24(topLevel, headRel);
13948
14019
  const { stdout: headBlobOut } = await execFileAsync3(
13949
14020
  "git",
13950
14021
  ["rev-parse", "--verify", `HEAD:${headRel}`],
@@ -14043,20 +14114,20 @@ async function assertControlledGrokAuthIsNotSymlink(authPath) {
14043
14114
  }
14044
14115
  }
14045
14116
  async function scrubAkBashSeatbeltHooks(controlledHome) {
14046
- const hooksDir = join22(controlledHome, "hooks");
14117
+ const hooksDir = join24(controlledHome, "hooks");
14047
14118
  for (const name of AK_BASH_SEATBELT_HOOK_FILES) {
14048
- await rm5(join22(hooksDir, name), { force: true });
14119
+ await rm5(join24(hooksDir, name), { force: true });
14049
14120
  }
14050
14121
  }
14051
14122
  async function prepareControlledGrokHome(sourceHome, controlledHome) {
14052
14123
  await assertControlledGrokHomeIsRealDirectory(controlledHome);
14053
14124
  await mkdir4(controlledHome, { recursive: true, mode: 448 });
14054
14125
  await assertControlledGrokHomeIsRealDirectory(controlledHome);
14055
- const authPath = join22(controlledHome, "auth.json");
14126
+ const authPath = join24(controlledHome, "auth.json");
14056
14127
  await assertControlledGrokAuthIsNotSymlink(authPath);
14057
14128
  await rm5(authPath, { force: true });
14058
14129
  await scrubAkBashSeatbeltHooks(controlledHome);
14059
- await copyFile(join22(sourceHome, ".grok", "auth.json"), authPath);
14130
+ await copyFile(join24(sourceHome, ".grok", "auth.json"), authPath);
14060
14131
  }
14061
14132
  async function inspectControlledGrok(options) {
14062
14133
  const { stdout } = await execFileAsync3(options.binary, ["inspect", "--json"], {
@@ -14177,14 +14248,14 @@ async function prepareGrokRoleEnvelope(options) {
14177
14248
  for (const method of request.methods) {
14178
14249
  if (method.kind !== "skill") continue;
14179
14250
  const name = basename8(dirname16(method.path));
14180
- const raw = await readFile13(method.path, "utf8");
14251
+ const raw = await readFile14(method.path, "utf8");
14181
14252
  methodSkills.set(name, { path: method.path, body: stripSkillFrontmatter(raw).trim() });
14182
14253
  }
14183
- let sessionFile = options.sessionFile ?? join23(request.runDirectory, "session", "session.jsonl");
14254
+ let sessionFile = options.sessionFile ?? join25(request.runDirectory, "session", "session.jsonl");
14184
14255
  await mkdir5(dirname16(sessionFile), { recursive: true });
14185
14256
  if (request.continuation.kind !== "resume") {
14186
14257
  try {
14187
- await writeFile8(
14258
+ await writeFile9(
14188
14259
  sessionFile,
14189
14260
  `${JSON.stringify({
14190
14261
  type: "session",
@@ -14592,7 +14663,7 @@ async function prepareGrokRoleEnvelope(options) {
14592
14663
  message: { role: "user", content: prompt }
14593
14664
  });
14594
14665
  }
14595
- const methodPrompt = (await Promise.all(request.methods.map(({ path }) => readFile13(path, "utf8")))).join("\n\n");
14666
+ const methodPrompt = (await Promise.all(request.methods.map(({ path }) => readFile14(path, "utf8")))).join("\n\n");
14596
14667
  const promptResults = await emit("before_agent_start", {
14597
14668
  prompt,
14598
14669
  systemPrompt: methodPrompt,
@@ -14640,18 +14711,18 @@ async function prepareGrokRoleEnvelope(options) {
14640
14711
  }
14641
14712
 
14642
14713
  // src/grok/session-identity.ts
14643
- import { mkdir as mkdir6, readFile as readFile14, rename, writeFile as writeFile9 } from "node:fs/promises";
14644
- import { dirname as dirname17, join as join24 } from "node:path";
14714
+ import { mkdir as mkdir6, readFile as readFile15, rename, writeFile as writeFile10 } from "node:fs/promises";
14715
+ import { dirname as dirname17, join as join26 } from "node:path";
14645
14716
  var GROK_ACP_SESSION_BINDING = "grok-acp-session.json";
14646
14717
  function createGrokSessionIdentityAuthority(authority) {
14647
- const bindingPath = (principal) => join24(authority.decode(principal).sessionDirectory, GROK_ACP_SESSION_BINDING);
14718
+ const bindingPath = (principal) => join26(authority.decode(principal).sessionDirectory, GROK_ACP_SESSION_BINDING);
14648
14719
  return {
14649
14720
  resolveSessionFile(principal) {
14650
14721
  return authority.decode(principal).sessionFile;
14651
14722
  },
14652
14723
  async load(principal) {
14653
14724
  try {
14654
- const value = JSON.parse(await readFile14(bindingPath(principal), "utf8"));
14725
+ const value = JSON.parse(await readFile15(bindingPath(principal), "utf8"));
14655
14726
  if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
14656
14727
  throw new Error("durable Grok ACP session binding is invalid");
14657
14728
  }
@@ -14665,7 +14736,7 @@ function createGrokSessionIdentityAuthority(authority) {
14665
14736
  const target = bindingPath(principal);
14666
14737
  await mkdir6(dirname17(target), { recursive: true });
14667
14738
  const temporary = `${target}.${process.pid}.tmp`;
14668
- await writeFile9(temporary, `${JSON.stringify({ sessionId })}
14739
+ await writeFile10(temporary, `${JSON.stringify({ sessionId })}
14669
14740
  `, { encoding: "utf8", mode: 384 });
14670
14741
  await rename(temporary, target);
14671
14742
  }
@@ -14674,7 +14745,7 @@ function createGrokSessionIdentityAuthority(authority) {
14674
14745
 
14675
14746
  // src/grok/production-host.ts
14676
14747
  function resolveGrokBinary(operatorHome) {
14677
- return join25(operatorHome, ".grok", "bin", "grok");
14748
+ return join27(operatorHome, ".grok", "bin", "grok");
14678
14749
  }
14679
14750
  var NO_PRODUCTION_GROK_PRIMARY_FAILURE = {
14680
14751
  present: false
@@ -14682,7 +14753,7 @@ var NO_PRODUCTION_GROK_PRIMARY_FAILURE = {
14682
14753
  async function settleProductionGrokHomeCleanup(controlledHome, primaryFailure, concurrentMessage) {
14683
14754
  try {
14684
14755
  await assertControlledGrokHomeIsRealDirectory(controlledHome);
14685
- const authPath = join25(controlledHome, "auth.json");
14756
+ const authPath = join27(controlledHome, "auth.json");
14686
14757
  await assertControlledGrokAuthIsNotSymlink(authPath);
14687
14758
  await rm6(authPath, { force: true });
14688
14759
  await scrubAkBashSeatbeltHooks(controlledHome);
@@ -14699,7 +14770,7 @@ async function settleProductionGrokHomeCleanup(controlledHome, primaryFailure, c
14699
14770
  }
14700
14771
  }
14701
14772
  async function openProductionGrokHome(runDirectory, operatorHome) {
14702
- const controlledHome = join25(runDirectory, "grok-home");
14773
+ const controlledHome = join27(runDirectory, "grok-home");
14703
14774
  try {
14704
14775
  await prepareControlledGrokHome(operatorHome, controlledHome);
14705
14776
  return controlledHome;
@@ -14727,12 +14798,13 @@ async function bindProductionGrokIsolation(runDirectory, operatorHome, packageRo
14727
14798
  env: childEnv(controlledHome, packageRoot)
14728
14799
  };
14729
14800
  }
14730
- async function withProductionGrokIsolation(runDirectory, operatorHome, packageRoot, run) {
14801
+ async function withProductionGrokIsolation(runDirectory, operatorHome, packageRoot, run, noteOpened) {
14731
14802
  let binding;
14732
14803
  let primaryFailure = NO_PRODUCTION_GROK_PRIMARY_FAILURE;
14733
14804
  let value;
14734
14805
  try {
14735
14806
  binding = await bindProductionGrokIsolation(runDirectory, operatorHome, packageRoot);
14807
+ noteOpened?.(runDirectory);
14736
14808
  value = await run(binding);
14737
14809
  } catch (error) {
14738
14810
  primaryFailure = { present: true, value: error };
@@ -14758,9 +14830,9 @@ function createGrokRoleRuntimeDependencies(packageRoot) {
14758
14830
  return {
14759
14831
  loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
14760
14832
  loadFixerSoul: () => loadMainRoleSessionMaterials("fixer"),
14761
- loadFixPacket: (path) => readFile15(path, "utf8"),
14833
+ loadFixPacket: (path) => readFile16(path, "utf8"),
14762
14834
  loadCoderSoul: () => loadMainRoleSessionMaterials("coder"),
14763
- loadCoderTask: (path) => readFile15(path, "utf8"),
14835
+ loadCoderTask: (path) => readFile16(path, "utf8"),
14764
14836
  loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
14765
14837
  createReviewerPinnedGitReader: () => createReviewerPinnedGitReader(),
14766
14838
  createReviewerIssueFetcher: () => createGhIssueSoftFetcher(),
@@ -14776,7 +14848,7 @@ function createGrokRoleRuntimeDependencies(packageRoot) {
14776
14848
  loadGleanerLeftSoul: () => loadMainRoleSessionMaterials("gleaner-left"),
14777
14849
  loadNotarySourceRun: loadNotarySourceRunLocator,
14778
14850
  loadMergerSoul: () => loadMainRoleSessionMaterials("merger"),
14779
- loadMergerInput: async (path) => JSON.parse(await readFile15(path, "utf8")),
14851
+ loadMergerInput: async (path) => JSON.parse(await readFile16(path, "utf8")),
14780
14852
  createMergerGitState: (repositoryRoot) => createProductionMergerGitState(repositoryRoot),
14781
14853
  async loadCanonicalSkillBinding(name) {
14782
14854
  if (name === "tdd") {
@@ -14806,7 +14878,7 @@ function createGrokRoleRuntimeDependencies(packageRoot) {
14806
14878
  authority: options.authority,
14807
14879
  invocationId: options.invocationId,
14808
14880
  loadSoul: () => loadMainRoleSessionMaterials("navigator"),
14809
- loadRoutePlaybook: () => readFile15(navigatorRoutePlaybookPath, "utf8"),
14881
+ loadRoutePlaybook: () => readFile16(navigatorRoutePlaybookPath, "utf8"),
14810
14882
  loadRoleHelp: async (role) => formatNavigatorRoleHelp(role),
14811
14883
  createSession: navigatorSessionFactory,
14812
14884
  ...options.contextError === void 0 ? {} : { contextError: options.contextError },
@@ -14815,13 +14887,19 @@ function createGrokRoleRuntimeDependencies(packageRoot) {
14815
14887
  };
14816
14888
  }
14817
14889
  async function recordGrokCapabilities(request, declaration) {
14818
- await writeFile10(
14819
- join25(request.runDirectory, "grok-capabilities.json"),
14890
+ await writeFile11(
14891
+ join27(request.runDirectory, "grok-capabilities.json"),
14820
14892
  `${JSON.stringify(declaration)}
14821
14893
  `,
14822
14894
  "utf8"
14823
14895
  );
14824
14896
  }
14897
+ function resolveProductionGrokIsolationRunDirectory(request) {
14898
+ if (request.continuation.kind === "resume" && typeof request.nativeHomeRunDirectory === "string" && request.nativeHomeRunDirectory.length > 0) {
14899
+ return request.nativeHomeRunDirectory;
14900
+ }
14901
+ return request.runDirectory;
14902
+ }
14825
14903
  function createProductionGrokRoleTurnHost(options) {
14826
14904
  const { packageRoot, principalAuthority } = options;
14827
14905
  let turn;
@@ -14855,15 +14933,22 @@ function createProductionGrokRoleTurnHost(options) {
14855
14933
  });
14856
14934
  return {
14857
14935
  executeTurn(request) {
14936
+ const isolationRunDirectory = resolveProductionGrokIsolationRunDirectory(request);
14858
14937
  const execution = serial.then(
14859
- () => withProductionGrokIsolation(request.runDirectory, request.home, packageRoot, async (binding) => {
14860
- turn = binding;
14861
- try {
14862
- return await inner.executeTurn({ ...request, home: binding.controlledHome });
14863
- } finally {
14864
- turn = void 0;
14865
- }
14866
- })
14938
+ () => withProductionGrokIsolation(
14939
+ isolationRunDirectory,
14940
+ request.home,
14941
+ packageRoot,
14942
+ async (binding) => {
14943
+ turn = binding;
14944
+ try {
14945
+ return await inner.executeTurn({ ...request, home: binding.controlledHome });
14946
+ } finally {
14947
+ turn = void 0;
14948
+ }
14949
+ },
14950
+ request.noteNativeHomeOpened
14951
+ )
14867
14952
  );
14868
14953
  serial = execution.then(
14869
14954
  () => void 0,