@akagilnc/pi-workflow-roles 0.1.5015 → 0.1.5063

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 (95) hide show
  1. package/README.md +2 -2
  2. package/README.zh-CN.md +2 -2
  3. package/THIRD_PARTY_NOTICES.md +8 -8
  4. package/dist/acp-host/production-host.js +525 -978
  5. package/dist/headless-host/description.js +0 -2
  6. package/dist/headless-host/production-host.js +528 -1014
  7. package/dist/host-descriptions.js +2 -3
  8. package/dist/migrate-book-topology.js +7 -12
  9. package/dist/packaged-role-registry.js +20 -18
  10. package/dist/pi/role-turn-host.js +3 -27
  11. package/dist/public-cli/cli.js +23 -2
  12. package/dist/public-cli/countersign-run.js +13 -8
  13. package/dist/public-cli/instruction-seat-run.js +75 -107
  14. package/dist/public-cli/invocation.js +13 -32
  15. package/dist/public-cli/machine-method-skills.js +150 -0
  16. package/dist/public-cli/main.js +549 -679
  17. package/dist/public-cli/post-admission.js +10 -5
  18. package/dist/public-cli/registry.js +2 -1
  19. package/dist/public-cli/run-lifecycle.js +12 -15
  20. package/dist/public-cli/seat-ticket-binding.js +5 -8
  21. package/dist/public-cli/settlement.js +12 -99
  22. package/dist/public-cli/turn-request.js +16 -8
  23. package/dist/public-role-summons.js +8 -3
  24. package/package.json +5 -1
  25. package/resources/countersign-ticket-issue.md +5 -0
  26. package/resources/diarist-collect.md +1 -0
  27. package/resources/secretariat-ticket-identity.md +15 -0
  28. package/scripts/build-package.mjs +1 -6
  29. package/src/headless-host/description.ts +0 -3
  30. package/src/headless-host/role-turn-host.ts +2 -23
  31. package/src/host-contracts.ts +2 -23
  32. package/src/host-descriptions.ts +2 -3
  33. package/src/packaged-role-registry.ts +17 -16
  34. package/src/pi/adapter.ts +0 -27
  35. package/src/pi/role-turn-host.ts +3 -31
  36. package/src/public-cli/cli.ts +24 -2
  37. package/src/public-cli/countersign-run.ts +17 -10
  38. package/src/public-cli/instruction-seat-run.ts +75 -105
  39. package/src/public-cli/invocation.ts +10 -38
  40. package/src/public-cli/machine-method-skills.ts +153 -0
  41. package/src/public-cli/post-admission.ts +12 -6
  42. package/src/public-cli/registry.ts +1 -0
  43. package/src/public-cli/run-lifecycle.ts +12 -13
  44. package/src/public-cli/seat-ticket-binding.ts +5 -8
  45. package/src/public-cli/settlement.ts +6 -138
  46. package/src/public-cli/turn-request.ts +24 -16
  47. package/src/public-role-summons.ts +16 -3
  48. package/src/reviewer-role.ts +1 -12
  49. package/src/role-envelope.ts +0 -13
  50. package/src/role-runtime-dependencies.ts +0 -13
  51. package/src/role-runtime.ts +4 -56
  52. package/src/worker-role.ts +1 -81
  53. package/dist/method-host-plugin/.claude-plugin/plugin.json +0 -5
  54. package/dist/method-host-plugin/skills/ak-cross-m-review/CONTEXT.md +0 -48
  55. package/dist/method-host-plugin/skills/ak-cross-m-review/LICENSE +0 -21
  56. package/dist/method-host-plugin/skills/ak-cross-m-review/SKILL.md +0 -170
  57. package/dist/method-host-plugin/skills/ak-cross-m-review/prompts/cmr-completeness.md +0 -118
  58. package/dist/method-host-plugin/skills/ak-cross-m-review/prompts/cmr-reviewer.md +0 -128
  59. package/dist/method-host-plugin/skills/ak-cross-m-review/provenance.json +0 -41
  60. package/dist/method-host-plugin/skills/diagnosing-bugs/SKILL.md +0 -134
  61. package/dist/method-host-plugin/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  62. package/dist/method-host-plugin/skills/diagnosing-bugs/provenance.json +0 -31
  63. package/dist/method-host-plugin/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -41
  64. package/dist/method-host-plugin/skills/resolving-merge-conflicts/SKILL.md +0 -14
  65. package/dist/method-host-plugin/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  66. package/dist/method-host-plugin/skills/resolving-merge-conflicts/provenance.json +0 -26
  67. package/dist/method-host-plugin/skills/tdd/SKILL.md +0 -38
  68. package/dist/method-host-plugin/skills/tdd/agents/openai.yaml +0 -3
  69. package/dist/method-host-plugin/skills/tdd/mocking.md +0 -59
  70. package/dist/method-host-plugin/skills/tdd/provenance.json +0 -36
  71. package/dist/method-host-plugin/skills/tdd/tests.md +0 -77
  72. package/dist/package-resources/method-skill.js +0 -259
  73. package/resources/method-host-plugin/.claude-plugin/plugin.json +0 -5
  74. package/resources/methods/ak-cross-m-review/CONTEXT.md +0 -48
  75. package/resources/methods/ak-cross-m-review/LICENSE +0 -21
  76. package/resources/methods/ak-cross-m-review/SKILL.md +0 -170
  77. package/resources/methods/ak-cross-m-review/prompts/cmr-completeness.md +0 -118
  78. package/resources/methods/ak-cross-m-review/prompts/cmr-reviewer.md +0 -128
  79. package/resources/methods/ak-cross-m-review/provenance.json +0 -41
  80. package/resources/methods/diagnosing-bugs/SKILL.md +0 -134
  81. package/resources/methods/diagnosing-bugs/agents/openai.yaml +0 -3
  82. package/resources/methods/diagnosing-bugs/provenance.json +0 -31
  83. package/resources/methods/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -41
  84. package/resources/methods/resolving-merge-conflicts/SKILL.md +0 -14
  85. package/resources/methods/resolving-merge-conflicts/agents/openai.yaml +0 -3
  86. package/resources/methods/resolving-merge-conflicts/provenance.json +0 -26
  87. package/resources/methods/tdd/SKILL.md +0 -38
  88. package/resources/methods/tdd/agents/openai.yaml +0 -3
  89. package/resources/methods/tdd/mocking.md +0 -59
  90. package/resources/methods/tdd/provenance.json +0 -36
  91. package/resources/methods/tdd/tests.md +0 -77
  92. package/src/canonical-skill-binding.ts +0 -118
  93. package/src/host-native-method.ts +0 -185
  94. package/src/package-resources/method-skill-binding.ts +0 -60
  95. package/src/package-resources/method-skill.ts +0 -363
@@ -62,7 +62,7 @@ async function spawnEngineDetourOnce(input) {
62
62
  }
63
63
  const command = input.argv[0];
64
64
  const args = input.argv.slice(1);
65
- return await new Promise((resolve22, reject) => {
65
+ return await new Promise((resolve21, reject) => {
66
66
  let settled = false;
67
67
  const signal = input.signal;
68
68
  const child = spawn(command, args, {
@@ -92,7 +92,7 @@ async function spawnEngineDetourOnce(input) {
92
92
  if (signal !== void 0) {
93
93
  signal.removeEventListener("abort", onAbort);
94
94
  }
95
- resolve22(result);
95
+ resolve21(result);
96
96
  };
97
97
  const onAbort = () => {
98
98
  fail4(signal !== void 0 ? abortReasonError(signal) : new Error("aborted"));
@@ -1172,12 +1172,12 @@ function createSystemCollectorClock() {
1172
1172
  return {
1173
1173
  wallNow: () => /* @__PURE__ */ new Date(),
1174
1174
  monoNow: () => Number(process.hrtime.bigint() - start) / 1e6,
1175
- sleep: (ms, signal) => new Promise((resolve22, reject) => {
1175
+ sleep: (ms, signal) => new Promise((resolve21, reject) => {
1176
1176
  if (signal?.aborted) {
1177
1177
  reject(signal.reason ?? new Error("aborted"));
1178
1178
  return;
1179
1179
  }
1180
- const timer = setTimeout(resolve22, ms);
1180
+ const timer = setTimeout(resolve21, ms);
1181
1181
  const onAbort = () => {
1182
1182
  clearTimeout(timer);
1183
1183
  reject(signal?.reason ?? new Error("aborted"));
@@ -1863,7 +1863,7 @@ function normalizeReviewComment(raw) {
1863
1863
  function createGhApiRunner(options = {}) {
1864
1864
  const spawnImpl = options.spawnImpl ?? spawn2;
1865
1865
  return async (args, runOptions = {}) => {
1866
- return await new Promise((resolve22, reject) => {
1866
+ return await new Promise((resolve21, reject) => {
1867
1867
  const signal = runOptions.signal;
1868
1868
  if (signal?.aborted) {
1869
1869
  reject(signal.reason ?? new Error("aborted"));
@@ -1936,11 +1936,11 @@ function createGhApiRunner(options = {}) {
1936
1936
  const value = line2.slice(idx + 1).trim();
1937
1937
  headers[name] = value;
1938
1938
  }
1939
- resolve22({ status, headers, bodyText });
1939
+ resolve21({ status, headers, bodyText });
1940
1940
  return;
1941
1941
  }
1942
1942
  if (code === 0) {
1943
- resolve22({ status: 200, headers: {}, bodyText: stdout });
1943
+ resolve21({ status: 200, headers: {}, bodyText: stdout });
1944
1944
  return;
1945
1945
  }
1946
1946
  const failure2 = new Error(
@@ -4045,7 +4045,7 @@ __export(packaged_role_registry_exports, {
4045
4045
  packagedEmitsAuthorityRefs: () => packagedEmitsAuthorityRefs,
4046
4046
  packagedGateStageLabel: () => packagedGateStageLabel,
4047
4047
  packagedGateSummon: () => packagedGateSummon,
4048
- packagedMethodLoadFailureCause: () => packagedMethodLoadFailureCause,
4048
+ packagedMethodSkillNames: () => packagedMethodSkillNames,
4049
4049
  packagedModelParent: () => packagedModelParent,
4050
4050
  packagedNavigatorSubject: () => packagedNavigatorSubject,
4051
4051
  packagedProjectsTargetBindRejection: () => packagedProjectsTargetBindRejection,
@@ -4067,6 +4067,18 @@ __export(packaged_role_registry_exports, {
4067
4067
  function packagedRoleMetadata(role) {
4068
4068
  return PACKAGED_ROLE_REGISTRY.find((entry) => entry.role === role);
4069
4069
  }
4070
+ function packagedMethodSkillNames() {
4071
+ const names = [];
4072
+ for (const record4 of PACKAGED_ROLE_REGISTRY) {
4073
+ if ("methodSkills" in record4 && record4.methodSkills !== void 0) {
4074
+ for (const name of record4.methodSkills) if (!names.includes(name)) names.push(name);
4075
+ }
4076
+ if ("applyMethod" in record4 && record4.applyMethod !== void 0 && !names.includes(record4.applyMethod)) {
4077
+ names.push(record4.applyMethod);
4078
+ }
4079
+ }
4080
+ return names;
4081
+ }
4070
4082
  function isOfficerReviewSeat(role) {
4071
4083
  const record4 = packagedRoleMetadata(role);
4072
4084
  return record4 !== void 0 && "reviewOfficer" in record4 && record4.reviewOfficer === true;
@@ -4101,11 +4113,6 @@ function packagedRolePhaseFlag(role) {
4101
4113
  function packagedRoleOutputTool(role) {
4102
4114
  return packagedRoleMetadata(role)?.outputTool;
4103
4115
  }
4104
- function packagedMethodLoadFailureCause(role) {
4105
- const record4 = packagedRoleMetadata(role);
4106
- if (record4 === void 0 || !("methodLoadFailureCause" in record4)) return void 0;
4107
- return record4.methodLoadFailureCause;
4108
- }
4109
4116
  function packagedBindsBoardTicket(role) {
4110
4117
  const record4 = packagedRoleMetadata(role);
4111
4118
  return record4?.sameParent === "board-ticket";
@@ -4308,8 +4315,7 @@ var init_packaged_role_registry = __esm({
4308
4315
  { key: "packetPath" },
4309
4316
  { key: "prerequisitesPath", omitUndefined: true },
4310
4317
  { key: "prerequisites" }
4311
- ],
4312
- method: "observed"
4318
+ ]
4313
4319
  },
4314
4320
  boardPlacement: "marshal",
4315
4321
  activationFlags: [
@@ -4335,7 +4341,6 @@ var init_packaged_role_registry = __esm({
4335
4341
  worker: true,
4336
4342
  applyMethod: "tdd",
4337
4343
  /** Method-material load failure keeps the activation cause (not reviewer/fixer). */
4338
- methodLoadFailureCause: "activation",
4339
4344
  boardPlacement: "coder",
4340
4345
  phases: ["plan", "apply"],
4341
4346
  outputTool: CODER_OUTPUT_TOOL_NAME,
@@ -4346,8 +4351,7 @@ var init_packaged_role_registry = __esm({
4346
4351
  leaves: [
4347
4352
  { key: "phase" },
4348
4353
  { key: "taskPath" }
4349
- ],
4350
- method: "optional"
4354
+ ]
4351
4355
  },
4352
4356
  activationFlags: [
4353
4357
  { field: "taskPath", flag: "ak-coder-task", binds: "input" },
@@ -4388,8 +4392,7 @@ var init_packaged_role_registry = __esm({
4388
4392
  { key: "lens" },
4389
4393
  { key: "authorityRefs", copyArray: true },
4390
4394
  { key: "callerProvenance", callerProvenance: true }
4391
- ],
4392
- method: "observed"
4395
+ ]
4393
4396
  },
4394
4397
  /** Frozen base/lens/authority become the initial prompt; instruction follows. */
4395
4398
  transportPrompt: "skill-args",
@@ -4488,7 +4491,6 @@ var init_packaged_role_registry = __esm({
4488
4491
  methodSkills: ["resolving-merge-conflicts"],
4489
4492
  settleMethod: "resolving-merge-conflicts",
4490
4493
  /** Method-material load failure keeps the activation cause (not reviewer/fixer). */
4491
- methodLoadFailureCause: "activation",
4492
4494
  phases: [null],
4493
4495
  outputTool: MERGER_OUTPUT_TOOL_NAME,
4494
4496
  settlement: "residual",
@@ -4500,8 +4502,7 @@ var init_packaged_role_registry = __esm({
4500
4502
  leaves: [
4501
4503
  { key: "mergerInputPath" },
4502
4504
  { key: "derived" }
4503
- ],
4504
- method: "observed"
4505
+ ]
4505
4506
  },
4506
4507
  activationFlags: [
4507
4508
  { field: "inputPath", from: "mergerInputPath", flag: "ak-merger-input", binds: "input" }
@@ -4568,7 +4569,7 @@ var init_packaged_role_registry = __esm({
4568
4569
  activationStage: "load-and-install",
4569
4570
  receiptStatusKey: "status",
4570
4571
  // #924: 公用《票面法》三席同装
4571
- sessionMaterials: ["CLAUDE.md", "souls/countersign.md", "souls/ticket-law.md"]
4572
+ sessionMaterials: ["CLAUDE.md", "souls/countersign.md", "souls/ticket-law.md", "resources/countersign-ticket-issue.md"]
4572
4573
  },
4573
4574
  {
4574
4575
  role: "secretariat",
@@ -4576,7 +4577,7 @@ var init_packaged_role_registry = __esm({
4576
4577
  presentSettled: "always",
4577
4578
  summonResume: false,
4578
4579
  admission: "instruction",
4579
- sameParent: "court-diarist",
4580
+ sameParent: "none",
4580
4581
  phases: [null],
4581
4582
  outputTool: SECRETARIAT_OUTPUT_TOOL_NAME,
4582
4583
  settlement: "accepted",
@@ -4592,6 +4593,7 @@ var init_packaged_role_registry = __esm({
4592
4593
  "CLAUDE.md",
4593
4594
  "souls/secretariat.md",
4594
4595
  "souls/ticket-law.md",
4596
+ "resources/secretariat-ticket-identity.md",
4595
4597
  "souls/countersign.md",
4596
4598
  "souls/notary.md"
4597
4599
  ]
@@ -5121,10 +5123,10 @@ __export(session_assistant_usage_exports, {
5121
5123
  });
5122
5124
  import { join as join9 } from "node:path";
5123
5125
  async function readAssistantUsageFromSessionFile(sessionFile) {
5124
- const { readFile: readFile27 } = await import("node:fs/promises");
5126
+ const { readFile: readFile25 } = await import("node:fs/promises");
5125
5127
  let text;
5126
5128
  try {
5127
- text = await readFile27(sessionFile, "utf8");
5129
+ text = await readFile25(sessionFile, "utf8");
5128
5130
  } catch (error) {
5129
5131
  if (error?.code === "ENOENT") return void 0;
5130
5132
  throw error;
@@ -5782,7 +5784,6 @@ var role_turn_host_exports = {};
5782
5784
  __export(role_turn_host_exports, {
5783
5785
  EXPLICIT_INTERNAL_LOAD_PROBE_ARGS: () => EXPLICIT_INTERNAL_LOAD_PROBE_ARGS,
5784
5786
  appendPiSessionCustomEntry: () => appendPiSessionCustomEntry,
5785
- applyPiNativeSkillInvocation: () => applyPiNativeSkillInvocation,
5786
5787
  buildExplicitInternalActivationArgs: () => buildExplicitInternalActivationArgs,
5787
5788
  buildPiTurnExtraArgs: () => buildPiTurnExtraArgs,
5788
5789
  createDefaultPiSpawnRunner: () => createDefaultPiSpawnRunner,
@@ -5792,7 +5793,7 @@ __export(role_turn_host_exports, {
5792
5793
  import { execFile, spawn as spawn3 } from "node:child_process";
5793
5794
  import { constants } from "node:fs";
5794
5795
  import { access, appendFile, readFile as readFile5, realpath } from "node:fs/promises";
5795
- import { basename as basename4, delimiter, dirname as dirname7, isAbsolute as isAbsolute3, join as join13, resolve as resolve5 } from "node:path";
5796
+ import { delimiter, dirname as dirname7, isAbsolute as isAbsolute3, join as join13, resolve as resolve5 } from "node:path";
5796
5797
  import { platform } from "node:process";
5797
5798
  import { promisify } from "node:util";
5798
5799
  import { randomUUID as randomUUID2 } from "node:crypto";
@@ -5825,24 +5826,11 @@ function buildMethodArgs(methods) {
5825
5826
  const skillArgs = [];
5826
5827
  for (const method of methods) {
5827
5828
  if (method.kind === "skill") {
5828
- skillArgs.push("--skill", method.path);
5829
+ skillArgs.push("--skill", dirname7(method.path));
5829
5830
  }
5830
5831
  }
5831
5832
  return skillArgs;
5832
5833
  }
5833
- function applyPiNativeSkillInvocation(methods, prompt) {
5834
- const skills = methods.filter((method) => method.kind === "skill");
5835
- if (skills.length !== 1) return prompt;
5836
- const name = basename4(dirname7(skills[0].path));
5837
- if (name.length === 0) return prompt;
5838
- const token = `/skill:${name}`;
5839
- const trimmed = prompt.trimStart();
5840
- if (trimmed === token || trimmed.startsWith(`${token} `) || trimmed.startsWith(`${token}
5841
- `)) {
5842
- return prompt;
5843
- }
5844
- return prompt.length === 0 ? token : `${token} ${prompt}`;
5845
- }
5846
5834
  function buildPiTurnExtraArgs(request, authority, extraPiArgs = []) {
5847
5835
  const { sessionFile, sessionDirectory } = authority.decode(request.principal);
5848
5836
  return [
@@ -5874,7 +5862,7 @@ function piUserDialogueBody(request) {
5874
5862
  const _exhaustive = request.continuation;
5875
5863
  return _exhaustive;
5876
5864
  })();
5877
- return request.continuation.kind === "resume" ? rawPrompt : applyPiNativeSkillInvocation(request.methods, rawPrompt);
5865
+ return rawPrompt;
5878
5866
  }
5879
5867
  async function resolveSelectedPi(command, cwd, env) {
5880
5868
  const searchPath = env.PATH ?? (platform === "win32" ? process.env.PATH ?? "" : "/usr/bin:/bin");
@@ -7401,7 +7389,7 @@ var init_session_dialogue = __esm({
7401
7389
  // src/ticket-provenance.ts
7402
7390
  import { createHash as createHash7 } from "node:crypto";
7403
7391
  import { readFile as readFile9, unlink } from "node:fs/promises";
7404
- import { basename as basename5, dirname as dirname9, join as join15, resolve as resolve8 } from "node:path";
7392
+ import { basename as basename4, dirname as dirname9, join as join15, resolve as resolve8 } from "node:path";
7405
7393
  function dialogueSessionSourceRoots(home) {
7406
7394
  const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
7407
7395
  return [
@@ -7414,7 +7402,7 @@ function isLedgerRoleSessionFile(absolute, home) {
7414
7402
  const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
7415
7403
  const ledgerHome = resolveActivationLedgerHome(machineHome);
7416
7404
  if (!physicallyContainedIn(ledgerHome, absolute)) return false;
7417
- return basename5(absolute) === "session.jsonl" && basename5(dirname9(absolute)) === "session";
7405
+ return basename4(absolute) === "session.jsonl" && basename4(dirname9(absolute)) === "session";
7418
7406
  }
7419
7407
  function assertDialogueSessionSourcePath(path, home) {
7420
7408
  const absolute = resolve8(path);
@@ -8107,7 +8095,7 @@ __export(run_lifecycle_exports, {
8107
8095
  writeRoleRunState: () => writeRoleRunState
8108
8096
  });
8109
8097
  import { chmod, lstat as lstat2, open, readdir as readdir4, readFile as readFile11, unlink as unlink3, writeFile as writeFile3 } from "node:fs/promises";
8110
- import { basename as basename6, join as join17 } from "node:path";
8098
+ import { basename as basename5, join as join17 } from "node:path";
8111
8099
  function buildAutoResumeContinuationPrompt(options) {
8112
8100
  return appendEngineSessionMaterial(
8113
8101
  [RESUME_TRANSPORT_ENVELOPE],
@@ -8620,7 +8608,7 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
8620
8608
  throw error;
8621
8609
  }
8622
8610
  for (const runDirectory of runDirectories) {
8623
- const entry = basename6(runDirectory);
8611
+ const entry = basename5(runDirectory);
8624
8612
  if (onlyRole === void 0 && (entry === `${runId}@judge` || entry.startsWith(`${runId}@`)) || entry === `${runId}@${onlyRole}`) {
8625
8613
  matches.push(runDirectory);
8626
8614
  }
@@ -8689,12 +8677,12 @@ async function findLatestRunIdForSeatTicket(input) {
8689
8677
  const suffix = `@${input.role}`;
8690
8678
  let best;
8691
8679
  for (const runDirectory of runDirectories) {
8692
- const entry = basename6(runDirectory);
8680
+ const entry = basename5(runDirectory);
8693
8681
  if (!entry.endsWith(suffix)) continue;
8694
8682
  const runId = entry.slice(0, entry.length - suffix.length);
8695
8683
  if (runId.length === 0) continue;
8696
8684
  const parentPath = await readRunParentPath(runDirectory);
8697
- if (parentPath !== input.parentRunPath) continue;
8685
+ if (parentPath !== input.parentRunPath && basename5(parentPath ?? "") !== basename5(input.parentRunPath)) continue;
8698
8686
  if (!await runHasFormedSessionPrincipal(runDirectory)) continue;
8699
8687
  if (best === void 0 || runId > best) best = runId;
8700
8688
  }
@@ -8756,7 +8744,7 @@ function restoredTicketFields(fields) {
8756
8744
  ...fields.courtTicketNumbers === void 0 ? {} : { courtTicketNumbers: fields.courtTicketNumbers }
8757
8745
  };
8758
8746
  }
8759
- async function loadResumableRunRecord(home, runId, authority) {
8747
+ async function loadResumableRunRecord(home, runId, authority, allowUnformedAdmitted = false) {
8760
8748
  const runDirectory = await findRunDirectoryById(home, runId);
8761
8749
  if (runDirectory === void 0) {
8762
8750
  throw new CliUsageError(`unknown role run id: ${runId}`);
@@ -8770,7 +8758,7 @@ async function loadResumableRunRecord(home, runId, authority) {
8770
8758
  throw new CliUsageError(`unknown role run id: ${runId}`);
8771
8759
  }
8772
8760
  const { run, principal } = materialized;
8773
- if (!await isDurablePrincipalAvailable(principal, authority)) {
8761
+ if (!(allowUnformedAdmitted && run.state === "admitted") && !await isDurablePrincipalAvailable(principal, authority)) {
8774
8762
  throw new CliUsageError(
8775
8763
  `role run Pi session principal is unavailable: ${runId}`
8776
8764
  );
@@ -8969,7 +8957,7 @@ async function loadResumableRunRecord(home, runId, authority) {
8969
8957
  } else if (mergedSet.tickets !== void 0) {
8970
8958
  courtTicketNumbers = mergedSet.tickets;
8971
8959
  }
8972
- const sourceRunLeaf = basename6(sourceRunPath ?? "").split("@");
8960
+ const sourceRunLeaf = basename5(sourceRunPath ?? "").split("@");
8973
8961
  const referencedRunId = sourceRun?.runId ?? sourceRunLeaf[0];
8974
8962
  const referencedRole = sourceRun?.role ?? sourceRunLeaf[1];
8975
8963
  if (referencedRunId !== void 0 && referencedRunId !== "") {
@@ -9051,8 +9039,8 @@ async function peekRoleRunRole(home, runId) {
9051
9039
  const run = await readRoleRunIdentity(runDirectory);
9052
9040
  return run?.role;
9053
9041
  }
9054
- async function loadResumablePublicRole(home, runId, authority) {
9055
- const loaded = await loadResumableRunRecord(home, runId, authority);
9042
+ async function loadResumablePublicRole(home, runId, authority, allowUnformedAdmitted = false) {
9043
+ const loaded = await loadResumableRunRecord(home, runId, authority, allowUnformedAdmitted);
9056
9044
  return seatLoadedResult(loaded, admitResumedRole(loaded));
9057
9045
  }
9058
9046
  function admitResumedRole(loaded) {
@@ -9314,7 +9302,7 @@ var init_run_lifecycle = __esm({
9314
9302
  });
9315
9303
 
9316
9304
  // src/notary-source-run.ts
9317
- import { dirname as dirname10, isAbsolute as isAbsolute6, join as join18, resolve as resolve9, basename as basename7 } from "node:path";
9305
+ import { dirname as dirname10, isAbsolute as isAbsolute6, join as join18, resolve as resolve9, basename as basename6 } from "node:path";
9318
9306
  import { lstat as lstat3, realpath as realpath3 } from "node:fs/promises";
9319
9307
  async function readRetainedIdentity(runDirectory) {
9320
9308
  try {
@@ -9355,10 +9343,10 @@ async function requireRunDirectory(candidate, display) {
9355
9343
  `notary --source-run must be a run directory: ${display}`
9356
9344
  );
9357
9345
  }
9358
- const identity = parseRunDirectoryName(basename7(real));
9346
+ const identity = parseRunDirectoryName(basename6(real));
9359
9347
  if (identity === void 0) {
9360
9348
  throw new NotarySourceRunError(
9361
- `notary --source-run must be named <runId>@<role>: ${basename7(real)}`
9349
+ `notary --source-run must be named <runId>@<role>: ${basename6(real)}`
9362
9350
  );
9363
9351
  }
9364
9352
  return real;
@@ -9378,9 +9366,9 @@ async function resolveNotarySourceRunLocator(options) {
9378
9366
  candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join18(bookRunsRoot, `${bare.runId}@${bare.role}`);
9379
9367
  } else {
9380
9368
  candidate = isAbsolute6(raw) ? raw : resolve9(options.projectRoot, raw);
9381
- const identity2 = parseRunDirectoryName(basename7(candidate));
9369
+ const identity2 = parseRunDirectoryName(basename6(candidate));
9382
9370
  const subjectDirectory = dirname10(dirname10(candidate));
9383
- const isLegacyUnboundLocator = identity2 !== void 0 && basename7(dirname10(candidate)) === "runs" && basename7(subjectDirectory) === "unbound" && resolve9(dirname10(subjectDirectory)) === resolve9(bookDirectory);
9371
+ const isLegacyUnboundLocator = identity2 !== void 0 && basename6(dirname10(candidate)) === "runs" && basename6(subjectDirectory) === "unbound" && resolve9(dirname10(subjectDirectory)) === resolve9(bookDirectory);
9384
9372
  if (isLegacyUnboundLocator) {
9385
9373
  candidate = await findRunDirectoryById(
9386
9374
  options.home,
@@ -9391,11 +9379,11 @@ async function resolveNotarySourceRunLocator(options) {
9391
9379
  }
9392
9380
  }
9393
9381
  const real = await requireRunDirectory(candidate, raw);
9394
- const identity = parseRunDirectoryName(basename7(real));
9382
+ const identity = parseRunDirectoryName(basename6(real));
9395
9383
  const bookIdentity = physicalPathIdentity(bookDirectory);
9396
9384
  const parentIdentity = physicalPathIdentity(dirname10(real));
9397
9385
  const subjectBookIdentity = physicalPathIdentity(dirname10(dirname10(dirname10(real))));
9398
- if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename7(dirname10(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
9386
+ if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename6(dirname10(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
9399
9387
  throw new NotarySourceRunError(
9400
9388
  "notary --source-run must resolve to a retained run under the project machine-ledger book"
9401
9389
  );
@@ -9429,7 +9417,7 @@ async function resolveNotarySourceRunLocator(options) {
9429
9417
  }
9430
9418
  async function loadNotarySourceRunLocator(path) {
9431
9419
  const real = await requireRunDirectory(path, path);
9432
- const identity = parseRunDirectoryName(basename7(real));
9420
+ const identity = parseRunDirectoryName(basename6(real));
9433
9421
  const runState = await readRetainedIdentity(real);
9434
9422
  if (runState === void 0) {
9435
9423
  throw new NotarySourceRunError(
@@ -9536,7 +9524,8 @@ var init_registry = __esm({
9536
9524
  "config",
9537
9525
  "help",
9538
9526
  "resume",
9539
- "new"
9527
+ "new",
9528
+ "setup"
9540
9529
  ];
9541
9530
  PUBLIC_DETERMINISTIC_COMMANDS = ["analyst"];
9542
9531
  }
@@ -10604,7 +10593,7 @@ import {
10604
10593
  writeFile as writeFile4
10605
10594
  } from "node:fs/promises";
10606
10595
  import { tmpdir as tmpdir2 } from "node:os";
10607
- import { basename as basename8, dirname as dirname11, isAbsolute as isAbsolute7, join as join19, resolve as resolve10, sep as sep4 } from "node:path";
10596
+ import { basename as basename7, dirname as dirname11, isAbsolute as isAbsolute7, join as join19, resolve as resolve10, sep as sep4 } from "node:path";
10608
10597
  function issueAdmissionPlacement(authority, request) {
10609
10598
  const ledgerHome = resolveActivationLedgerHome(request.home);
10610
10599
  const bookKey = resolveBookKeyFromGit(request.cwd);
@@ -10730,12 +10719,7 @@ async function persistAdmittedSourceRunPath(admitted, sourceRunPath) {
10730
10719
  );
10731
10720
  }
10732
10721
  async function bindAdmittedTicketNumber(admitted, ticketNumber) {
10733
- if (admitted.ticketNumber !== void 0) {
10734
- if (admitted.ticketNumber === ticketNumber) return;
10735
- throw new Error(
10736
- `bindAdmittedTicketNumber refuses to replace existing ticket #${admitted.ticketNumber} with #${ticketNumber}`
10737
- );
10738
- }
10722
+ if (admitted.ticketNumber === ticketNumber) return;
10739
10723
  await bindTicketNumberOnRunDirectory(admitted.runDirectory, ticketNumber);
10740
10724
  admitted.ticketNumber = ticketNumber;
10741
10725
  }
@@ -10819,6 +10803,7 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
10819
10803
  for (const childRunId of Array.isArray(childRunIds) ? childRunIds : []) {
10820
10804
  if (typeof childRunId !== "string") continue;
10821
10805
  const childDirectory = join19(dirname11(oldRunDirectory), `${childRunId}@diarist`);
10806
+ if (!existsSync6(childDirectory)) continue;
10822
10807
  const childTarget = roleRunPlacement(ledgerHome, {
10823
10808
  bookKey: admitted.bookKey,
10824
10809
  subject: { ticketNumber: admitted.ticketNumber },
@@ -10826,7 +10811,6 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
10826
10811
  role: "diarist"
10827
10812
  });
10828
10813
  authority.seal(childTarget);
10829
- if (!existsSync6(childDirectory) && existsSync6(childTarget.runDirectory)) continue;
10830
10814
  await bindTicketNumberOnRunDirectory(childDirectory, admitted.ticketNumber);
10831
10815
  await rehomeUnboundTicketProvenance(childDirectory, admitted.ticketNumber, admitted.projectRoot, homeFromRunDirectory(oldRunDirectory));
10832
10816
  ensureRoleRunDirectory(ledgerHome, dirname11(childTarget.runDirectory));
@@ -10876,25 +10860,8 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
10876
10860
  "bindTicketNumberOnRunDirectory"
10877
10861
  );
10878
10862
  const admittedPath = join19(runDirectory, "admitted-request.json");
10879
- const invocationPath = join19(runDirectory, "invocation.json");
10880
10863
  const admitted = JSON.parse(await readFile12(admittedPath, "utf8"));
10881
- const existing = admitted.ticketNumber;
10882
- if (typeof existing === "number") {
10883
- if (existing === ticketNumber) return;
10884
- throw new Error(
10885
- `bindTicketNumberOnRunDirectory refuses to replace existing ticket #${existing} with #${ticketNumber}`
10886
- );
10887
- }
10888
- if (existsSync6(invocationPath)) {
10889
- const invocation = JSON.parse(
10890
- await readFile12(invocationPath, "utf8")
10891
- );
10892
- if (typeof invocation.ticketNumber === "number" && invocation.ticketNumber !== ticketNumber) {
10893
- throw new Error(
10894
- `bindTicketNumberOnRunDirectory refuses to replace invocation ticket #${invocation.ticketNumber} with #${ticketNumber}`
10895
- );
10896
- }
10897
- }
10864
+ if (admitted.ticketNumber === ticketNumber) return;
10898
10865
  await writeFile4(
10899
10866
  admittedPath,
10900
10867
  `${JSON.stringify({ ...admitted, ticketNumber }, null, 2)}
@@ -11241,7 +11208,7 @@ async function withPreparedAttachments(attachmentPaths, use) {
11241
11208
  async function freezeAttachmentBytes(provenancePath, bytes, destinationDir, index) {
11242
11209
  const frozenPath = join19(
11243
11210
  destinationDir,
11244
- `${String(index).padStart(2, "0")}-${basename8(provenancePath)}`
11211
+ `${String(index).padStart(2, "0")}-${basename7(provenancePath)}`
11245
11212
  );
11246
11213
  await writeFile4(frozenPath, bytes);
11247
11214
  return {
@@ -13415,10 +13382,10 @@ function pairGateRounds(volumes) {
13415
13382
  return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
13416
13383
  }
13417
13384
  async function resolveOfficerSessionFromPointerFile(pointerPath) {
13418
- const { readFile: readFile27 } = await import("node:fs/promises");
13385
+ const { readFile: readFile25 } = await import("node:fs/promises");
13419
13386
  let raw;
13420
13387
  try {
13421
- raw = JSON.parse(await readFile27(pointerPath, "utf8"));
13388
+ raw = JSON.parse(await readFile25(pointerPath, "utf8"));
13422
13389
  } catch (error) {
13423
13390
  throw new Error(
13424
13391
  `direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
@@ -14517,243 +14484,6 @@ var init_dossier_resolution = __esm({
14517
14484
  }
14518
14485
  });
14519
14486
 
14520
- // src/package-resources/method-skill.ts
14521
- import { createHash as createHash8 } from "node:crypto";
14522
- import { readFile as readFile15, realpath as realpath5 } from "node:fs/promises";
14523
- import { join as join28 } from "node:path";
14524
- function gitBlobOid(bytes) {
14525
- const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
14526
- const header = Buffer.from(`blob ${body.byteLength}\0`, "utf8");
14527
- return createHash8("sha1").update(header).update(body).digest("hex");
14528
- }
14529
- function stripSkillFrontmatter(content) {
14530
- if (!content.startsWith("---")) return content;
14531
- const end = content.indexOf("\n---", 3);
14532
- if (end === -1) return content;
14533
- const after = content.slice(end + "\n---".length);
14534
- return after.replace(/^\r?\n/, "");
14535
- }
14536
- function packagedMethodSkillRelativeDirectory(name) {
14537
- return `${METHOD_SKILL_RELATIVE_ROOT}/${name}`;
14538
- }
14539
- function resolvePackagedMethodSkillRoot(packageRoot, name) {
14540
- return join28(packageRoot, packagedMethodSkillRelativeDirectory(name));
14541
- }
14542
- function resolvePackagedMethodSkillPath(packageRoot, name) {
14543
- return join28(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
14544
- }
14545
- function isRecord11(value) {
14546
- return typeof value === "object" && value !== null && !Array.isArray(value);
14547
- }
14548
- function parseProvenance(raw, expectedName) {
14549
- if (!isRecord11(raw)) {
14550
- throw new Error(`Packaged method provenance must be an object for ${expectedName}`);
14551
- }
14552
- if (raw.name !== expectedName) {
14553
- throw new Error(
14554
- `Packaged method provenance name mismatch: expected ${expectedName}, got ${String(raw.name)}`
14555
- );
14556
- }
14557
- if (raw.kind !== "role-method-skill") {
14558
- throw new Error(`Packaged method provenance kind must be role-method-skill`);
14559
- }
14560
- if (typeof raw.packageAdaptation !== "string" || raw.packageAdaptation.trim() === "") {
14561
- throw new Error(`Packaged method provenance packageAdaptation must be nonblank`);
14562
- }
14563
- if (!isRecord11(raw.upstream)) {
14564
- throw new Error(`Packaged method provenance upstream must be an object`);
14565
- }
14566
- const upstream = raw.upstream;
14567
- for (const key of [
14568
- "repository",
14569
- "path",
14570
- "license",
14571
- "copyright",
14572
- "attribution"
14573
- ]) {
14574
- if (typeof upstream[key] !== "string" || upstream[key].trim() === "") {
14575
- throw new Error(`Packaged method provenance upstream.${key} must be nonblank`);
14576
- }
14577
- }
14578
- if (typeof upstream.commit !== "string" || !GIT_COMMIT_RE.test(upstream.commit)) {
14579
- throw new Error(
14580
- `Packaged method provenance upstream.commit must be a 40-char lowercase git object id`
14581
- );
14582
- }
14583
- const tag = typeof upstream.tag === "string" && upstream.tag.trim() !== "" ? upstream.tag.trim() : void 0;
14584
- const version = typeof upstream.version === "string" && upstream.version.trim() !== "" ? upstream.version.trim() : void 0;
14585
- if (tag === void 0 && version === void 0) {
14586
- throw new Error(
14587
- `Packaged method provenance upstream must include nonblank tag or version`
14588
- );
14589
- }
14590
- if (!isRecord11(raw.files)) {
14591
- throw new Error(`Packaged method provenance files must be an object`);
14592
- }
14593
- const files = {};
14594
- for (const [rel, entry] of Object.entries(raw.files)) {
14595
- if (!isRecord11(entry)) {
14596
- throw new Error(`Packaged method provenance file entry must be an object: ${rel}`);
14597
- }
14598
- if (typeof entry.sha256 !== "string" || !SHA256_RE.test(entry.sha256)) {
14599
- throw new Error(`Packaged method provenance file sha256 invalid: ${rel}`);
14600
- }
14601
- if (typeof entry.byteLength !== "number" || !Number.isInteger(entry.byteLength) || entry.byteLength < 0) {
14602
- throw new Error(`Packaged method provenance file byteLength invalid: ${rel}`);
14603
- }
14604
- if (typeof entry.gitBlob !== "string" || !GIT_BLOB_RE.test(entry.gitBlob)) {
14605
- throw new Error(
14606
- `Packaged method provenance file gitBlob must be a 40-char lowercase git object id: ${rel}`
14607
- );
14608
- }
14609
- files[rel] = {
14610
- sha256: entry.sha256,
14611
- byteLength: entry.byteLength,
14612
- gitBlob: entry.gitBlob
14613
- };
14614
- }
14615
- if (files["SKILL.md"] === void 0) {
14616
- throw new Error(`Packaged method provenance must include SKILL.md`);
14617
- }
14618
- return Object.freeze({
14619
- name: expectedName,
14620
- kind: "role-method-skill",
14621
- packageAdaptation: raw.packageAdaptation,
14622
- upstream: Object.freeze({
14623
- repository: upstream.repository,
14624
- path: upstream.path,
14625
- commit: upstream.commit,
14626
- ...tag === void 0 ? {} : { tag },
14627
- ...version === void 0 ? {} : { version },
14628
- license: upstream.license,
14629
- copyright: upstream.copyright,
14630
- attribution: upstream.attribution
14631
- }),
14632
- files: Object.freeze(files)
14633
- });
14634
- }
14635
- async function loadPackagedMethodSkillMaterial(packageRoot, name) {
14636
- const rootDirectory = resolvePackagedMethodSkillRoot(packageRoot, name);
14637
- const skillPathConfigured = join28(rootDirectory, "SKILL.md");
14638
- const provenancePath = join28(rootDirectory, "provenance.json");
14639
- let provenanceRaw;
14640
- try {
14641
- provenanceRaw = await readFile15(provenancePath, "utf8");
14642
- } catch (error) {
14643
- throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
14644
- }
14645
- let provenanceJson;
14646
- try {
14647
- provenanceJson = JSON.parse(provenanceRaw);
14648
- } catch (error) {
14649
- throw new Error(`Packaged method provenance is not valid JSON at ${provenancePath}`, {
14650
- cause: error
14651
- });
14652
- }
14653
- const provenance = parseProvenance(provenanceJson, name);
14654
- for (const [rel, expected] of Object.entries(provenance.files)) {
14655
- const absolute = join28(rootDirectory, rel);
14656
- let bytes;
14657
- try {
14658
- bytes = await readFile15(absolute);
14659
- } catch (error) {
14660
- throw new PackagedMethodSkillUnavailableError(name, absolute, error);
14661
- }
14662
- const actualSha = sha256Hex(bytes);
14663
- const actualBlob = gitBlobOid(bytes);
14664
- if (actualSha !== expected.sha256 || bytes.byteLength !== expected.byteLength || actualBlob !== expected.gitBlob) {
14665
- throw new Error(
14666
- `Packaged method file digest mismatch for ${name}/${rel}: expected sha256=${expected.sha256} byteLength=${expected.byteLength} gitBlob=${expected.gitBlob}, got sha256=${actualSha} byteLength=${bytes.byteLength} gitBlob=${actualBlob}`
14667
- );
14668
- }
14669
- }
14670
- let skillPath;
14671
- let raw;
14672
- try {
14673
- skillPath = await realpath5(skillPathConfigured);
14674
- raw = await readFile15(skillPath, "utf8");
14675
- } catch (error) {
14676
- throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
14677
- }
14678
- const body = stripSkillFrontmatter(raw).trim();
14679
- if (body.length === 0) {
14680
- throw new Error(`Canonical ${name} Skill is empty at ${skillPath}`);
14681
- }
14682
- const companionRelativePaths = REQUIRED_COMPANIONS[name].filter(
14683
- (rel) => provenance.files[rel] !== void 0
14684
- );
14685
- for (const rel of REQUIRED_COMPANIONS[name]) {
14686
- if (provenance.files[rel] === void 0) {
14687
- throw new Error(
14688
- `Packaged method ${name} missing required companion in provenance: ${rel}`
14689
- );
14690
- }
14691
- }
14692
- return Object.freeze({
14693
- name,
14694
- rootDirectory,
14695
- skillPath,
14696
- raw,
14697
- body,
14698
- provenance,
14699
- companionRelativePaths: Object.freeze([...companionRelativePaths])
14700
- });
14701
- }
14702
- function observePackagedMethodSkillInvocation(text, expected) {
14703
- if (!text.startsWith('<skill name="')) return void 0;
14704
- const nameStart = '<skill name="'.length;
14705
- const nameEnd = text.indexOf('"', nameStart);
14706
- if (nameEnd <= nameStart) return void 0;
14707
- const name = text.slice(nameStart, nameEnd);
14708
- if (name !== expected.name) return void 0;
14709
- const locationMarker = '" location="';
14710
- if (!text.startsWith(locationMarker, nameEnd)) return void 0;
14711
- const locationStart = nameEnd + locationMarker.length;
14712
- const locationEnd = text.indexOf('"', locationStart);
14713
- if (locationEnd <= locationStart) return void 0;
14714
- const location = text.slice(locationStart, locationEnd);
14715
- const openTail = ">\n";
14716
- if (!text.startsWith(openTail, locationEnd + 1)) return void 0;
14717
- const closeTag = "\n</skill>";
14718
- const closeAt = text.indexOf(closeTag, locationEnd + 1 + openTail.length);
14719
- if (closeAt === -1) return void 0;
14720
- const afterClose = text.slice(closeAt + closeTag.length);
14721
- if (afterClose.length > 0 && !afterClose.startsWith("\n")) return void 0;
14722
- if (!expected.allowedLocations.includes(location)) return void 0;
14723
- return Object.freeze({ name: expected.name, location });
14724
- }
14725
- var PackagedMethodSkillUnavailableError, METHOD_SKILL_RELATIVE_ROOT, GIT_COMMIT_RE, GIT_BLOB_RE, SHA256_RE, REQUIRED_COMPANIONS;
14726
- var init_method_skill = __esm({
14727
- "src/package-resources/method-skill.ts"() {
14728
- "use strict";
14729
- init_sha256();
14730
- PackagedMethodSkillUnavailableError = class extends Error {
14731
- constructor(skillName, path, cause) {
14732
- super(`Canonical ${skillName} Skill is unavailable at ${path}`, { cause });
14733
- this.skillName = skillName;
14734
- this.name = "CanonicalSkillUnavailableError";
14735
- }
14736
- skillName;
14737
- code = "canonical-skill-unavailable";
14738
- };
14739
- METHOD_SKILL_RELATIVE_ROOT = "resources/methods";
14740
- GIT_COMMIT_RE = /^[0-9a-f]{40}$/;
14741
- GIT_BLOB_RE = /^[0-9a-f]{40}$/;
14742
- SHA256_RE = /^[0-9a-f]{64}$/;
14743
- REQUIRED_COMPANIONS = {
14744
- tdd: ["tests.md", "mocking.md", "agents/openai.yaml"],
14745
- "diagnosing-bugs": ["agents/openai.yaml", "scripts/hitl-loop.template.sh"],
14746
- "ak-cross-m-review": [
14747
- "CONTEXT.md",
14748
- "LICENSE",
14749
- "prompts/cmr-completeness.md",
14750
- "prompts/cmr-reviewer.md"
14751
- ],
14752
- "resolving-merge-conflicts": ["agents/openai.yaml"]
14753
- };
14754
- }
14755
- });
14756
-
14757
14487
  // src/work-subject-identity.ts
14758
14488
  import { resolve as resolve12 } from "node:path";
14759
14489
  function issueRoot(value) {
@@ -14965,11 +14695,11 @@ var init_navigator_invocation_identity = __esm({
14965
14695
  });
14966
14696
 
14967
14697
  // src/receipt-delivery-policy.ts
14968
- function isRecord12(value) {
14698
+ function isRecord11(value) {
14969
14699
  return typeof value === "object" && value !== null && !Array.isArray(value);
14970
14700
  }
14971
14701
  function parseNoReceiptLifecycleFacts(input) {
14972
- if (!isRecord12(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord12(item) && typeof item.reason === "string")) {
14702
+ if (!isRecord11(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord11(item) && typeof item.reason === "string")) {
14973
14703
  throw new TypeError("malformed no-receipt lifecycle facts");
14974
14704
  }
14975
14705
  return {
@@ -15077,7 +14807,6 @@ __export(settlement_exports, {
15077
14807
  formatTerminalResult: () => formatTerminalResult,
15078
14808
  inspectJudgeSession: () => inspectJudgeSession,
15079
14809
  isLawfulTypedTerminalOutcome: () => isLawfulTypedTerminalOutcome,
15080
- observedMethodSkillOptions: () => observedMethodSkillOptions,
15081
14810
  presentControlledFailure: () => presentControlledFailure,
15082
14811
  presentFailureTerminal: () => presentFailureTerminal,
15083
14812
  presentStructuralRejection: () => presentStructuralRejection,
@@ -15104,15 +14833,15 @@ __export(settlement_exports, {
15104
14833
  withSubmissions: () => withSubmissions
15105
14834
  });
15106
14835
  import { randomUUID as randomUUID4 } from "node:crypto";
15107
- import { appendFile as appendFile2, readFile as readFile16, readdir as readdir6, rm as rm3, writeFile as writeFile6 } from "node:fs/promises";
15108
- import { dirname as dirname15, join as join29 } from "node:path";
14836
+ import { appendFile as appendFile2, readFile as readFile15, readdir as readdir6, rm as rm3, writeFile as writeFile6 } from "node:fs/promises";
14837
+ import { dirname as dirname15, join as join28 } from "node:path";
15109
14838
  function sealedLedgerHome(admitted) {
15110
14839
  return homeFromRunDirectory(admitted.runDirectory);
15111
14840
  }
15112
14841
  function ledgerReadScope(admitted, scope) {
15113
14842
  return {
15114
14843
  home: sealedLedgerHome(admitted),
15115
- sessionParent: join29(admitted.runDirectory, "session", "session.jsonl"),
14844
+ sessionParent: join28(admitted.runDirectory, "session", "session.jsonl"),
15116
14845
  ...scope?.courtAttemptId === void 0 || scope.courtAttemptId.length === 0 ? {} : { attemptId: scope.courtAttemptId }
15117
14846
  };
15118
14847
  }
@@ -15262,7 +14991,7 @@ function presentControlledFailure(failure2, io) {
15262
14991
  }
15263
14992
  async function inspectJudgeSession(sessionFile) {
15264
14993
  try {
15265
- await readFile16(sessionFile, "utf8");
14994
+ await readFile15(sessionFile, "utf8");
15266
14995
  return { state: "present" };
15267
14996
  } catch (error) {
15268
14997
  if (isMissingPathError4(error)) return { state: "missing" };
@@ -15502,7 +15231,7 @@ function sessionReadFailure(error, fallbackMessage) {
15502
15231
  return failed;
15503
15232
  }
15504
15233
  async function readBoundSessionEntries(sessionFile) {
15505
- const text = await readFile16(sessionFile, "utf8");
15234
+ const text = await readFile15(sessionFile, "utf8");
15506
15235
  const entries = [];
15507
15236
  for (const line2 of text.trim().split("\n").filter(Boolean)) {
15508
15237
  try {
@@ -15568,7 +15297,7 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
15568
15297
  const { records } = await readSitianRecords(recordFile);
15569
15298
  for (let i = records.length - 1; i >= 0; i -= 1) {
15570
15299
  const payload = records[i]?.payload;
15571
- if (!isRecord13(payload) || !isRecord13(payload.response)) continue;
15300
+ if (!isRecord12(payload) || !isRecord12(payload.response)) continue;
15572
15301
  if (typeof payload.type === "string") continue;
15573
15302
  const stop = sessionProviderStopFromAssistant(payload.response);
15574
15303
  if (stop !== void 0) return stop;
@@ -15598,7 +15327,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
15598
15327
  }
15599
15328
  const parentId = parentEntries.find((entry) => entry.type === "session")?.id;
15600
15329
  if (parentId === void 0) return void 0;
15601
- const childDirectories = [join29(dirname15(sessionFile), "auditor-roles")];
15330
+ const childDirectories = [join28(dirname15(sessionFile), "auditor-roles")];
15602
15331
  const valid = [];
15603
15332
  let sawAnyDirectory = false;
15604
15333
  for (const childDirectory of childDirectories) {
@@ -15613,12 +15342,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
15613
15342
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
15614
15343
  let entries;
15615
15344
  try {
15616
- entries = await readBoundSessionEntries(join29(childDirectory, file));
15345
+ entries = await readBoundSessionEntries(join28(childDirectory, file));
15617
15346
  } catch (error) {
15618
15347
  throw sessionReadFailure(error, "failed to read discovered auditor session");
15619
15348
  }
15620
15349
  const header = entries.find((entry) => entry.type === "session");
15621
- if (!isRecord13(header)) continue;
15350
+ if (!isRecord12(header)) continue;
15622
15351
  const bindingIndexes = [];
15623
15352
  for (let i = 0; i < entries.length; i += 1) {
15624
15353
  const entry = entries[i];
@@ -15632,7 +15361,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
15632
15361
  end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
15633
15362
  })) : [{ entry: void 0, start: 0, end: entries.length }];
15634
15363
  for (const { entry: bindingEntry, start, end } of bindingPasses) {
15635
- const bindingParent = bindingEntry !== void 0 && isRecord13(bindingEntry.data) && isRecord13(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
15364
+ const bindingParent = bindingEntry !== void 0 && isRecord12(bindingEntry.data) && isRecord12(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
15636
15365
  const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
15637
15366
  const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
15638
15367
  if (boundSessionFile !== sessionFile) continue;
@@ -15656,12 +15385,12 @@ function complianceFailureFromAuditorVolumes(volumes) {
15656
15385
  if (stop === void 0) continue;
15657
15386
  for (let i = entries.length - 1; i >= 0; i -= 1) {
15658
15387
  const entry = entries[i];
15659
- if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord13(entry.data)) continue;
15660
- const parent = isRecord13(entry.data.parent) ? entry.data.parent : void 0;
15661
- const failure2 = isRecord13(entry.data.failure) ? entry.data.failure : void 0;
15388
+ if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord12(entry.data)) continue;
15389
+ const parent = isRecord12(entry.data.parent) ? entry.data.parent : void 0;
15390
+ const failure2 = isRecord12(entry.data.failure) ? entry.data.failure : void 0;
15662
15391
  if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId) continue;
15663
15392
  if (failure2 === void 0) continue;
15664
- const identity = isRecord13(failure2.identity) ? failure2.identity : void 0;
15393
+ const identity = isRecord12(failure2.identity) ? failure2.identity : void 0;
15665
15394
  const typedCause = failure2.cause === "provider" || failure2.cause === "activation" || failure2.cause === "session" || failure2.cause === "output" || failure2.cause === "timeout" ? failure2.cause : void 0;
15666
15395
  return {
15667
15396
  ...typedCause === void 0 ? {} : { cause: typedCause },
@@ -15670,7 +15399,7 @@ function complianceFailureFromAuditorVolumes(volumes) {
15670
15399
  ...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
15671
15400
  } },
15672
15401
  ...typeof failure2.diagnostic === "string" ? { diagnostic: failure2.diagnostic } : {},
15673
- ...isRecord13(failure2.details) ? { details: failure2.details } : {}
15402
+ ...isRecord12(failure2.details) ? { details: failure2.details } : {}
15674
15403
  };
15675
15404
  }
15676
15405
  }
@@ -15717,9 +15446,9 @@ function typedFailedTerminatingToolKnownFailure(entries) {
15717
15446
  if (classification.kind !== "infrastructure") continue;
15718
15447
  if (typeof message.toolCallId !== "string" || typeof message.toolName !== "string") continue;
15719
15448
  if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
15720
- const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord13(part) && part.type === "text" && typeof part.text === "string") : void 0;
15721
- const diagnostic = isRecord13(textPart) ? textPart.text : void 0;
15722
- const details = isRecord13(message.details) ? message.details : classification.fact;
15449
+ const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord12(part) && part.type === "text" && typeof part.text === "string") : void 0;
15450
+ const diagnostic = isRecord12(textPart) ? textPart.text : void 0;
15451
+ const details = isRecord12(message.details) ? message.details : classification.fact;
15723
15452
  return {
15724
15453
  cause: "activation",
15725
15454
  identity: { name: message.toolName, code: message.toolCallId },
@@ -15856,7 +15585,7 @@ function controlledFailureInputFromResolution(resolution) {
15856
15585
  } : {}
15857
15586
  };
15858
15587
  }
15859
- function isRecord13(value) {
15588
+ function isRecord12(value) {
15860
15589
  return typeof value === "object" && value !== null && !Array.isArray(value);
15861
15590
  }
15862
15591
  function toolResultText(message) {
@@ -15881,7 +15610,7 @@ function extractCollectorTargetBindRejection(entries) {
15881
15610
  const diagnostic = toolResultText(message);
15882
15611
  if (diagnostic.length === 0) return void 0;
15883
15612
  const details = message.details;
15884
- const code = isRecord13(details) && typeof details.code === "string" && details.code.trim() !== "" ? details.code : void 0;
15613
+ const code = isRecord12(details) && typeof details.code === "string" && details.code.trim() !== "" ? details.code : void 0;
15885
15614
  return code === void 0 ? { diagnostic } : { diagnostic, code };
15886
15615
  }
15887
15616
  return void 0;
@@ -15982,7 +15711,7 @@ function boundRoleToolCallForResult(entries, resultIndex, message, outputToolNam
15982
15711
  const candidateMessage = entries[index]?.message;
15983
15712
  if (candidateMessage?.role === "assistant" && Array.isArray(candidateMessage.content)) {
15984
15713
  for (const part of candidateMessage.content) {
15985
- if (!isRecord13(part) || part.type !== "toolCall" || part.id !== callId) {
15714
+ if (!isRecord12(part) || part.type !== "toolCall" || part.id !== callId) {
15986
15715
  continue;
15987
15716
  }
15988
15717
  if (part.name !== outputToolName) return void 0;
@@ -16053,7 +15782,7 @@ function parseNavigatorAttendanceDetails(details) {
16053
15782
  if (typeof details.prose === "string" && details.prose.trim() !== "") {
16054
15783
  prose = details.prose;
16055
15784
  } else {
16056
- const next = isRecord13(details.next) && typeof details.next.role === "string" ? details.next.role : void 0;
15785
+ const next = isRecord12(details.next) && typeof details.next.role === "string" ? details.next.role : void 0;
16057
15786
  const reason = typeof details.reason === "string" && details.reason.trim() !== "" ? details.reason : void 0;
16058
15787
  const command = typeof details.command === "string" && details.command.trim() !== "" ? details.command : void 0;
16059
15788
  if (reason !== void 0 && next !== void 0) {
@@ -16125,8 +15854,8 @@ function projectTerminalGateFact(rounds) {
16125
15854
  };
16126
15855
  }
16127
15856
  async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
16128
- const directories = [join29(sessionDirectory, "auditor-roles")];
16129
- const parentSessionFile = options.parentSessionFile ?? join29(sessionDirectory, "session.jsonl");
15857
+ const directories = [join28(sessionDirectory, "auditor-roles")];
15858
+ const parentSessionFile = options.parentSessionFile ?? join28(sessionDirectory, "session.jsonl");
16130
15859
  const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
16131
15860
  parentSessionFile
16132
15861
  });
@@ -16162,7 +15891,7 @@ function detourGateContext(admitted, scope) {
16162
15891
  }
16163
15892
  async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
16164
15893
  const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
16165
- const skipGate = isRecord13(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && packagedSkipsGateOnInfrastructureStage(secondaryEvidence.stage);
15894
+ const skipGate = isRecord12(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && packagedSkipsGateOnInfrastructureStage(secondaryEvidence.stage);
16166
15895
  let next = base;
16167
15896
  if (!skipGate) {
16168
15897
  const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
@@ -16206,7 +15935,7 @@ function extractNavigatorFact(entries) {
16206
15935
  const entry = entries[i];
16207
15936
  if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
16208
15937
  const details = entry.message?.details ?? entry.details;
16209
- if (!isRecord13(details)) {
15938
+ if (!isRecord12(details)) {
16210
15939
  return {
16211
15940
  disposition: "unavailable",
16212
15941
  source: "unknown",
@@ -16264,10 +15993,10 @@ async function removeFaceIfPresent(path) {
16264
15993
  async function clearOppositeTerminalArtifactFace(runDirectory) {
16265
15994
  const artifactsDir = roleRunArtifactsDirectory(runDirectory);
16266
15995
  for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
16267
- await removeFaceIfPresent(join29(artifactsDir, file));
15996
+ await removeFaceIfPresent(join28(artifactsDir, file));
16268
15997
  }
16269
15998
  for (const relative4 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
16270
- await removeFaceIfPresent(join29(runDirectory, relative4));
15999
+ await removeFaceIfPresent(join28(runDirectory, relative4));
16271
16000
  }
16272
16001
  for (const path of await listSeamOwnedUniqueErrorFacePaths(runDirectory)) {
16273
16002
  await removeFaceIfPresent(path);
@@ -16296,8 +16025,8 @@ async function publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinat
16296
16025
  roleOutcome
16297
16026
  );
16298
16027
  const artifactsDir = await ensureTerminalArtifactFace(admitted.runDirectory);
16299
- const reportPath = join29(artifactsDir, "report.json");
16300
- const evidencePath = join29(artifactsDir, "evidence.json");
16028
+ const reportPath = join28(artifactsDir, "report.json");
16029
+ const evidencePath = join28(artifactsDir, "evidence.json");
16301
16030
  await writeFile6(
16302
16031
  reportPath,
16303
16032
  `${JSON.stringify(bodies.report, null, 2)}
@@ -16315,8 +16044,8 @@ async function publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinat
16315
16044
  { kind: "evidence", path: evidencePath }
16316
16045
  ];
16317
16046
  }
16318
- async function publishSeatAcceptedArtifacts(admitted, roleOutcome, coordinates, entries = [], options = {}) {
16319
- return publishDeclaredSeatArtifacts(admitted, roleOutcome, coordinates, entries, options);
16047
+ async function publishSeatAcceptedArtifacts(admitted, roleOutcome, coordinates, entries = []) {
16048
+ return publishDeclaredSeatArtifacts(admitted, roleOutcome, coordinates, entries);
16320
16049
  }
16321
16050
  async function readLawfulSettlementEntries(sessionFile) {
16322
16051
  try {
@@ -16357,7 +16086,7 @@ async function settleSealedAcceptedOrToolResidual(admitted, authority, scope, ro
16357
16086
  const residual = boundErroredToolCandidate(entries, index, message, residualToolName);
16358
16087
  if (residual === void 0) continue;
16359
16088
  const candidate = residual.candidate;
16360
- const details = isRecord13(candidate) ? candidate : { candidate };
16089
+ const details = isRecord12(candidate) ? candidate : { candidate };
16361
16090
  const failed = await settleFailureTerminalResult(
16362
16091
  admitted,
16363
16092
  {
@@ -16388,7 +16117,7 @@ async function settleSealedAcceptedOrToolResidual(admitted, authority, scope, ro
16388
16117
  scope
16389
16118
  );
16390
16119
  }
16391
- async function settleSeat(admitted, authority, scope, options) {
16120
+ async function settleSeat(admitted, authority, scope) {
16392
16121
  const record4 = packagedRoleMetadata(admitted.role);
16393
16122
  if (record4 === void 0) {
16394
16123
  throw new Error(`no settlement for ${admitted.role}`);
@@ -16396,7 +16125,7 @@ async function settleSeat(admitted, authority, scope, options) {
16396
16125
  if (record4.settlement === "accepted") {
16397
16126
  return trySettleAcceptedSeatTerminalResult(admitted, authority, scope);
16398
16127
  }
16399
- const publish = (roleOutcome, coordinates, entries) => publishDeclaredSeatArtifacts(admitted, roleOutcome, coordinates, entries, options);
16128
+ const publish = (roleOutcome, coordinates, entries) => publishDeclaredSeatArtifacts(admitted, roleOutcome, coordinates, entries);
16400
16129
  if (record4.settlement === "residual") {
16401
16130
  return settleSealedAcceptedOrToolResidual(
16402
16131
  admitted,
@@ -16411,11 +16140,11 @@ async function settleSeat(admitted, authority, scope, options) {
16411
16140
  const accept = "sealedAcceptedOnly" in record4 && record4.sealedAcceptedOnly === true ? (roleOutcome) => roleOutcome.role === admitted.role && roleOutcome.kind === "accepted" : void 0;
16412
16141
  return settleSealedLedgerTerminal(admitted, authority, scope, publish, accept);
16413
16142
  }
16414
- async function trySettleSeatTerminalResult(admitted, authority, options = {}, scope) {
16415
- return settleSeat(admitted, authority, scope, options);
16143
+ async function trySettleSeatTerminalResult(admitted, authority, scope) {
16144
+ return settleSeat(admitted, authority, scope);
16416
16145
  }
16417
- async function settleSeatTerminalResult(admitted, authority, options = {}, scope) {
16418
- const settled = await settleSeat(admitted, authority, scope, options);
16146
+ async function settleSeatTerminalResult(admitted, authority, scope) {
16147
+ const settled = await settleSeat(admitted, authority, scope);
16419
16148
  if (settled === void 0) {
16420
16149
  const label = admitted.role.charAt(0).toUpperCase() + admitted.role.slice(1);
16421
16150
  throw new Error(
@@ -16424,41 +16153,6 @@ async function settleSeatTerminalResult(admitted, authority, options = {}, scope
16424
16153
  }
16425
16154
  return settled;
16426
16155
  }
16427
- function sessionMessageText(message) {
16428
- if (message === void 0) return "";
16429
- if (typeof message.content === "string") return message.content;
16430
- if (!Array.isArray(message.content)) return "";
16431
- const parts = [];
16432
- for (const part of message.content) {
16433
- if (typeof part === "object" && part !== null && !Array.isArray(part) && part.type === "text" && typeof part.text === "string") {
16434
- parts.push(part.text);
16435
- }
16436
- }
16437
- return parts.join("\n");
16438
- }
16439
- function observedMethodSkillOptions(packageRoot, material) {
16440
- return {
16441
- methodProvenance: material.provenance,
16442
- methodSkillPath: material.skillPath,
16443
- methodSkillConfiguredPath: resolvePackagedMethodSkillPath(packageRoot, material.name)
16444
- };
16445
- }
16446
- function extractObservedMethodInvocations(entries, options) {
16447
- const observed = [];
16448
- for (const entry of entries) {
16449
- if (entry?.type !== "message") continue;
16450
- const message = entry.message;
16451
- if (message?.role !== "user") continue;
16452
- const text = sessionMessageText(message);
16453
- if (text.length === 0) continue;
16454
- const hit = observePackagedMethodSkillInvocation(text, {
16455
- name: options.name,
16456
- allowedLocations: options.allowedLocations
16457
- });
16458
- if (hit !== void 0) observed.push(hit);
16459
- }
16460
- return Object.freeze(observed);
16461
- }
16462
16156
  function extractDoctorCandidateFacts(entries) {
16463
16157
  const scanStart = currentAttemptStartIndex(entries);
16464
16158
  for (let i = entries.length - 1; i >= scanStart; i -= 1) {
@@ -16467,7 +16161,7 @@ function extractDoctorCandidateFacts(entries) {
16467
16161
  continue;
16468
16162
  }
16469
16163
  const data = entry.data;
16470
- if (!isRecord13(data)) return {};
16164
+ if (!isRecord12(data)) return {};
16471
16165
  return {
16472
16166
  ...data.cost === void 0 ? {} : { cost: data.cost },
16473
16167
  ...data.auditNoReceipt === void 0 ? {} : { auditNoReceipt: data.auditNoReceipt }
@@ -16511,25 +16205,7 @@ function doctorReportFacts(face, roleOutcome, entries) {
16511
16205
  ...facts.auditNoReceipt === void 0 ? {} : { auditNoReceipt: facts.auditNoReceipt }
16512
16206
  };
16513
16207
  }
16514
- function observedMethodTail(face, entries, options) {
16515
- if (face.method === void 0) return {};
16516
- if (face.method === "optional") {
16517
- return options.methodProvenance === void 0 ? {} : { methodProvenance: options.methodProvenance };
16518
- }
16519
- if (options.methodProvenance === void 0 || options.methodSkillPath === void 0 || options.methodSkillConfiguredPath === void 0) {
16520
- throw new Error("observed method publication is missing packaged method coordinates");
16521
- }
16522
- const methodInvocations = extractObservedMethodInvocations(entries, {
16523
- name: options.methodProvenance.name,
16524
- allowedLocations: [options.methodSkillPath, options.methodSkillConfiguredPath]
16525
- });
16526
- return {
16527
- methodProvenance: options.methodProvenance,
16528
- methodInvocationObserved: methodInvocations.length > 0,
16529
- methodInvocations
16530
- };
16531
- }
16532
- async function publishDeclaredSeatArtifacts(admitted, roleOutcome, coordinates, entries, options = {}) {
16208
+ async function publishDeclaredSeatArtifacts(admitted, roleOutcome, coordinates, entries) {
16533
16209
  const face = seatArtifactFace(admitted.role);
16534
16210
  const phase = face.reportPhase === true ? { phase: readAdmittedPath(admitted, "phase") } : {};
16535
16211
  return publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinates, {
@@ -16547,8 +16223,7 @@ async function publishDeclaredSeatArtifacts(admitted, roleOutcome, coordinates,
16547
16223
  sessionDirectory: coordinates.sessionDirectory,
16548
16224
  sessionFile: coordinates.sessionFile,
16549
16225
  admittedRequestPath: admitted.admittedRequestPath,
16550
- attachments: acceptedArtifactAttachmentRefs(admitted.attachments),
16551
- ...observedMethodTail(face, entries, options)
16226
+ attachments: acceptedArtifactAttachmentRefs(admitted.attachments)
16552
16227
  }
16553
16228
  });
16554
16229
  }
@@ -16571,7 +16246,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
16571
16246
  let residual;
16572
16247
  for (let index = entries.length - 1; index >= scanStart; index -= 1) {
16573
16248
  const entry = entries[index];
16574
- if (entry?.type === "custom" && entry.customType === "ak-role-submission-closure" && isRecord13(entry.data) && entry.data.toolName === spec.toolName && classifyPackagedRoleTerminalResult(entry.data).kind === "accepted") {
16249
+ if (entry?.type === "custom" && entry.customType === "ak-role-submission-closure" && isRecord12(entry.data) && entry.data.toolName === spec.toolName && classifyPackagedRoleTerminalResult(entry.data).kind === "accepted") {
16575
16250
  thisAttemptHasSeatSuccess = true;
16576
16251
  }
16577
16252
  const message = entries[index]?.message;
@@ -16611,7 +16286,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
16611
16286
  );
16612
16287
  }
16613
16288
  if (residual !== void 0) {
16614
- const details = isRecord13(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
16289
+ const details = isRecord12(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
16615
16290
  const failed = await settleFailureTerminalResult(
16616
16291
  admitted,
16617
16292
  {
@@ -16641,11 +16316,8 @@ async function trySettleAcceptedSeatTerminalResult(admitted, authority, scope) {
16641
16316
  }
16642
16317
  return applySecretariatCountersignTerminal(admitted, authority, settled);
16643
16318
  }
16644
- async function trySettlePublicSeat(admitted, authority, scope, material, packageRoot) {
16645
- const face = seatArtifactFace(admitted.role);
16646
- if (face.method === "observed" && material === void 0) return void 0;
16647
- const options = face.method === "observed" && material !== void 0 ? observedMethodSkillOptions(packageRoot, material) : face.method === "optional" && material !== void 0 ? { methodProvenance: material.provenance } : {};
16648
- return settleSeat(admitted, authority, scope, options);
16319
+ async function trySettlePublicSeat(admitted, authority, scope) {
16320
+ return settleSeat(admitted, authority, scope);
16649
16321
  }
16650
16322
  function countersignTerminalFromEntries(entries) {
16651
16323
  for (let index = entries.length - 1; index >= 0; index -= 1) {
@@ -16664,7 +16336,7 @@ function countersignTerminalFromEntries(entries) {
16664
16336
  return void 0;
16665
16337
  }
16666
16338
  function withCountersignTerminalFact(roleOutcome, officer) {
16667
- const prior = roleOutcome.decisiveFacts !== void 0 && isRecord13(roleOutcome.decisiveFacts) ? roleOutcome.decisiveFacts : {};
16339
+ const prior = roleOutcome.decisiveFacts !== void 0 && isRecord12(roleOutcome.decisiveFacts) ? roleOutcome.decisiveFacts : {};
16668
16340
  return {
16669
16341
  ...roleOutcome,
16670
16342
  decisiveFacts: {
@@ -16677,7 +16349,7 @@ function acceptedSecretariatDefinesOfficerProjection(roleOutcome) {
16677
16349
  const payloads = roleOutcome.payloads ?? [];
16678
16350
  for (let index = payloads.length - 1; index >= 0; index -= 1) {
16679
16351
  const payload = payloads[index];
16680
- if (!isRecord13(payload)) continue;
16352
+ if (!isRecord12(payload)) continue;
16681
16353
  const status = payload.secretariatStatus;
16682
16354
  if (typeof status !== "string") continue;
16683
16355
  return status === "converged";
@@ -16753,7 +16425,7 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
16753
16425
  const candidates = [
16754
16426
  ...preferredCandidates,
16755
16427
  // One unique name per fallback dir — collisions on fixed names cannot exhaust this.
16756
- ...uniqueFallbackDirs.map((dir) => join29(dir, `${stem}.${randomUUID4()}.json`))
16428
+ ...uniqueFallbackDirs.map((dir) => join28(dir, `${stem}.${randomUUID4()}.json`))
16757
16429
  ];
16758
16430
  for (let i = 0; i < candidates.length; i += 1) {
16759
16431
  const path = candidates[i];
@@ -16814,20 +16486,20 @@ async function publishFailureArtifacts(admitted, failure2, authority) {
16814
16486
  baseDir
16815
16487
  );
16816
16488
  const errorCandidates = underArtifacts ? [
16817
- join29(baseDir, "error.json"),
16818
- join29(baseDir, "error.settlement.json"),
16819
- join29(admitted.runDirectory, "error.settlement.json")
16489
+ join28(baseDir, "error.json"),
16490
+ join28(baseDir, "error.settlement.json"),
16491
+ join28(admitted.runDirectory, "error.settlement.json")
16820
16492
  ] : [
16821
- join29(baseDir, "error.settlement.json"),
16822
- join29(baseDir, "error.json")
16493
+ join28(baseDir, "error.settlement.json"),
16494
+ join28(baseDir, "error.json")
16823
16495
  ];
16824
16496
  const evidenceCandidates = underArtifacts ? [
16825
- join29(baseDir, "evidence.json"),
16826
- join29(baseDir, "evidence.settlement.json"),
16827
- join29(admitted.runDirectory, "evidence.settlement.json")
16497
+ join28(baseDir, "evidence.json"),
16498
+ join28(baseDir, "evidence.settlement.json"),
16499
+ join28(admitted.runDirectory, "evidence.settlement.json")
16828
16500
  ] : [
16829
- join29(baseDir, "evidence.settlement.json"),
16830
- join29(baseDir, "evidence.json")
16501
+ join28(baseDir, "evidence.settlement.json"),
16502
+ join28(baseDir, "evidence.json")
16831
16503
  ];
16832
16504
  const errorPayloadBase = {
16833
16505
  kind: "error",
@@ -17003,10 +16675,10 @@ function presentFailureTerminal(terminal, io) {
17003
16675
  }
17004
16676
  function defaultNavigatorGraceSleep() {
17005
16677
  let timer;
17006
- const sleep2 = ((ms) => new Promise((resolve22) => {
16678
+ const sleep2 = ((ms) => new Promise((resolve21) => {
17007
16679
  timer = setTimeout(() => {
17008
16680
  timer = void 0;
17009
- resolve22();
16681
+ resolve21();
17010
16682
  }, ms);
17011
16683
  }));
17012
16684
  sleep2.cancel = () => {
@@ -17018,7 +16690,7 @@ function defaultNavigatorGraceSleep() {
17018
16690
  return sleep2;
17019
16691
  }
17020
16692
  function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep2 = defaultNavigatorGraceSleep()) {
17021
- return new Promise((resolve22, reject) => {
16693
+ return new Promise((resolve21, reject) => {
17022
16694
  let settled = false;
17023
16695
  const finish = (action) => {
17024
16696
  if (settled) return;
@@ -17027,11 +16699,11 @@ function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep2
17027
16699
  action();
17028
16700
  };
17029
16701
  void work.then(
17030
- (value) => finish(() => resolve22({ status: "done", value })),
16702
+ (value) => finish(() => resolve21({ status: "done", value })),
17031
16703
  (error) => finish(() => reject(error))
17032
16704
  );
17033
16705
  void sleep2(graceMs).then(() => {
17034
- finish(() => resolve22({ status: "timeout" }));
16706
+ finish(() => resolve21({ status: "timeout" }));
17035
16707
  });
17036
16708
  });
17037
16709
  }
@@ -17059,7 +16731,6 @@ var init_settlement = __esm({
17059
16731
  init_reviewer_output();
17060
16732
  init_packaged_role_registry();
17061
16733
  init_secretariat_contracts();
17062
- init_method_skill();
17063
16734
  init_navigator_invocation_identity();
17064
16735
  init_receipt_delivery_policy();
17065
16736
  init_role_run_placement();
@@ -17106,17 +16777,17 @@ var init_settlement = __esm({
17106
16777
  });
17107
16778
 
17108
16779
  // src/session-identity.ts
17109
- import { mkdir as mkdir2, readFile as readFile17, rename as rename2, writeFile as writeFile7 } from "node:fs/promises";
17110
- import { dirname as dirname16, join as join30 } from "node:path";
16780
+ import { mkdir as mkdir2, readFile as readFile16, rename as rename2, writeFile as writeFile7 } from "node:fs/promises";
16781
+ import { dirname as dirname16, join as join29 } from "node:path";
17111
16782
  function createSessionIdentityAuthority(authority, sessionBindingFile) {
17112
- const bindingPath = (principal) => join30(authority.decode(principal).sessionDirectory, sessionBindingFile);
16783
+ const bindingPath = (principal) => join29(authority.decode(principal).sessionDirectory, sessionBindingFile);
17113
16784
  return {
17114
16785
  resolveSessionFile(principal) {
17115
16786
  return authority.decode(principal).sessionFile;
17116
16787
  },
17117
16788
  async load(principal) {
17118
16789
  try {
17119
- const value = JSON.parse(await readFile17(bindingPath(principal), "utf8"));
16790
+ const value = JSON.parse(await readFile16(bindingPath(principal), "utf8"));
17120
16791
  if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
17121
16792
  throw new Error("durable session binding is invalid");
17122
16793
  }
@@ -17167,9 +16838,9 @@ __export(case_dossier_delivery_exports, {
17167
16838
  loadCaseDossierReadingMaterial: () => loadCaseDossierReadingMaterial,
17168
16839
  projectCaseDossierPointerSection: () => projectCaseDossierPointerSection
17169
16840
  });
17170
- import { mkdtemp as mkdtemp3, readFile as readFile18, rm as rm4, writeFile as writeFile8 } from "node:fs/promises";
16841
+ import { mkdtemp as mkdtemp3, readFile as readFile17, rm as rm4, writeFile as writeFile8 } from "node:fs/promises";
17171
16842
  import { tmpdir as tmpdir3 } from "node:os";
17172
- import { join as join31 } from "node:path";
16843
+ import { join as join30 } from "node:path";
17173
16844
  async function projectCaseDossierPointerSection(input) {
17174
16845
  if (input.ticketNumber === void 0) {
17175
16846
  return [
@@ -17196,9 +16867,9 @@ async function deliverCaseDossierAsAttachment(input) {
17196
16867
  projectRoot: input.projectRoot,
17197
16868
  home: input.home
17198
16869
  });
17199
- const stagingDir = await mkdtemp3(join31(tmpdir3(), "ak-case-dossier-"));
16870
+ const stagingDir = await mkdtemp3(join30(tmpdir3(), "ak-case-dossier-"));
17200
16871
  try {
17201
- const stagingPath = join31(stagingDir, CASE_DOSSIER_ATTACH_FILE);
16872
+ const stagingPath = join30(stagingDir, CASE_DOSSIER_ATTACH_FILE);
17202
16873
  await writeFile8(stagingPath, `${section}
17203
16874
  `, "utf8");
17204
16875
  return await freezeAttachmentsIntoRun(
@@ -17211,7 +16882,7 @@ async function deliverCaseDossierAsAttachment(input) {
17211
16882
  }
17212
16883
  }
17213
16884
  async function loadCaseDossierReadingMaterial(runDirectory) {
17214
- const frozenPath = join31(
16885
+ const frozenPath = join30(
17215
16886
  runDirectory,
17216
16887
  "attachments",
17217
16888
  CASE_DOSSIER_ATTACH_KEY,
@@ -17219,7 +16890,7 @@ async function loadCaseDossierReadingMaterial(runDirectory) {
17219
16890
  );
17220
16891
  let section;
17221
16892
  try {
17222
- section = await readFile18(frozenPath, "utf8");
16893
+ section = await readFile17(frozenPath, "utf8");
17223
16894
  } catch (error) {
17224
16895
  if (error.code === "ENOENT") return void 0;
17225
16896
  throw error;
@@ -17243,7 +16914,7 @@ var init_case_dossier_delivery = __esm({
17243
16914
 
17244
16915
  // src/host-transition-prior-native.ts
17245
16916
  import { access as access3, readdir as readdir7 } from "node:fs/promises";
17246
- import { dirname as dirname17, join as join32 } from "node:path";
16917
+ import { dirname as dirname17, join as join31 } from "node:path";
17247
16918
  function isEnoent2(error) {
17248
16919
  return typeof error === "object" && error !== null && error.code === "ENOENT";
17249
16920
  }
@@ -17268,7 +16939,7 @@ async function listSitianRecordPaths(sessionParent) {
17268
16939
  const recordPaths = [];
17269
16940
  for (const entry of entries) {
17270
16941
  if (!entry.isDirectory()) continue;
17271
- const recordFile = join32(sessionRoot, entry.name, "records.jsonl");
16942
+ const recordFile = join31(sessionRoot, entry.name, "records.jsonl");
17272
16943
  try {
17273
16944
  await access3(recordFile);
17274
16945
  recordPaths.push(recordFile);
@@ -17320,7 +16991,7 @@ var init_process_cancel = __esm({
17320
16991
  import { constants as fsConstants2 } from "node:fs";
17321
16992
  import { randomUUID as randomUUID5 } from "node:crypto";
17322
16993
  import { lstat as lstat6, mkdir as mkdir3, open as open2 } from "node:fs/promises";
17323
- import { join as join33 } from "node:path";
16994
+ import { join as join32 } from "node:path";
17324
16995
  async function persistReturnedRunState(admitted, authority, options) {
17325
16996
  if (options?.lawful === true) {
17326
16997
  await markRunTerminal(admitted.runDirectory);
@@ -17391,7 +17062,7 @@ function jsonSafeReplacer() {
17391
17062
  };
17392
17063
  }
17393
17064
  async function writeHardenedArtifactFile(artifactsDir, namePrefix, payload) {
17394
- const filePath = join33(artifactsDir, `${namePrefix}-${randomUUID5()}.json`);
17065
+ const filePath = join32(artifactsDir, `${namePrefix}-${randomUUID5()}.json`);
17395
17066
  const body = `${JSON.stringify(payload, jsonSafeReplacer(), 2)}
17396
17067
  `;
17397
17068
  const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
@@ -17680,7 +17351,7 @@ var init_auto_resume = __esm({
17680
17351
  // src/public-cli/post-admission.ts
17681
17352
  import { randomUUID as randomUUID6 } from "node:crypto";
17682
17353
  import { writeFile as writeFile9 } from "node:fs/promises";
17683
- import { isAbsolute as isAbsolute8, join as join34, resolve as resolve13 } from "node:path";
17354
+ import { isAbsolute as isAbsolute8, join as join33, resolve as resolve13 } from "node:path";
17684
17355
  function describeCaughtError(error) {
17685
17356
  if (error instanceof Error) {
17686
17357
  const code = error.code;
@@ -17751,8 +17422,9 @@ function withOnceSuccessfulBeforeDispatch(adapters) {
17751
17422
  ...adapters,
17752
17423
  beforeDispatch: async (admitted, lease) => {
17753
17424
  if (succeeded) return;
17754
- await hook(admitted, lease);
17425
+ const result = await hook(admitted, lease);
17755
17426
  succeeded = true;
17427
+ return result;
17756
17428
  }
17757
17429
  };
17758
17430
  }
@@ -17770,7 +17442,7 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
17770
17442
  try {
17771
17443
  const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
17772
17444
  await writeFile9(
17773
- join34(artifactsDir, `post-admission-diagnostic-${randomUUID6()}.json`),
17445
+ join33(artifactsDir, `post-admission-diagnostic-${randomUUID6()}.json`),
17774
17446
  `${JSON.stringify({ version: 1, ...payload }, null, 2)}
17775
17447
  `,
17776
17448
  { encoding: "utf8", flag: "wx" }
@@ -17787,30 +17459,6 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
17787
17459
  } catch {
17788
17460
  }
17789
17461
  }
17790
- async function resolveResumeMethodMaterialAdapters(input) {
17791
- if (input.shouldLoad === false) {
17792
- return { kind: "continue", adapters: input.emptyAdapters };
17793
- }
17794
- try {
17795
- const material = await input.loadMaterial();
17796
- return { kind: "continue", adapters: input.adaptersWith(material) };
17797
- } catch (error) {
17798
- const terminal = await presentControlledFailure2(
17799
- input.admitted,
17800
- {
17801
- timedOut: false,
17802
- code: null,
17803
- stderr: "",
17804
- thrown: error,
17805
- ...input.knownCause === void 0 ? {} : { knownCause: input.knownCause }
17806
- },
17807
- input.emptyAdapters,
17808
- input.authority,
17809
- input.io
17810
- );
17811
- return { kind: "terminal", ...terminal };
17812
- }
17813
- }
17814
17462
  async function presentControlledFailure2(admitted, failureInput, adapters, authority, io, persistRunState = true) {
17815
17463
  const hasThrown = Object.hasOwn(failureInput, "thrown");
17816
17464
  const resumeObservation = await resolveControlledFailureResumeObservation({
@@ -17935,7 +17583,7 @@ async function dispatchPostAdmissionTurn(input) {
17935
17583
  const rows = await readRecordedSubmissionRows(
17936
17584
  admitted.projectRoot,
17937
17585
  admitted.runId,
17938
- { home: homeFromRunDirectory(admitted.runDirectory), sessionParent: join34(admitted.runDirectory, "session", "session.jsonl") }
17586
+ { home: homeFromRunDirectory(admitted.runDirectory), sessionParent: join33(admitted.runDirectory, "session", "session.jsonl") }
17939
17587
  );
17940
17588
  const asserted = rows.filter((row) => row.kind === "accepted" && row.role === admitted.role).map((row) => row.accepted).find((payload) => {
17941
17589
  if (payload === null || typeof payload !== "object" || Array.isArray(payload)) return false;
@@ -18014,7 +17662,10 @@ async function dispatchPostAdmissionTurn(input) {
18014
17662
  await clearTypedProviderHttpObservation(admitted.runDirectory);
18015
17663
  if (adapters.beforeDispatch !== void 0) {
18016
17664
  try {
18017
- await adapters.beforeDispatch(admitted, lease);
17665
+ const paused = await adapters.beforeDispatch(admitted, lease);
17666
+ if (paused !== void 0) {
17667
+ return { exitCode: 0, admitted, terminal: paused, skipAutoResume: true };
17668
+ }
18018
17669
  } catch (error) {
18019
17670
  const settled2 = await presentControlledFailure2(
18020
17671
  admitted,
@@ -18090,7 +17741,7 @@ async function dispatchPostAdmissionTurn(input) {
18090
17741
  let stderrLogWriteFailure;
18091
17742
  try {
18092
17743
  await writeFile9(
18093
- join34(admitted.runDirectory, "stderr.log"),
17744
+ join33(admitted.runDirectory, "stderr.log"),
18094
17745
  result.stderr,
18095
17746
  "utf8"
18096
17747
  );
@@ -18326,6 +17977,7 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
18326
17977
  return {
18327
17978
  packageRoot: env.packageRoot,
18328
17979
  home: env.home,
17980
+ ...env.host === void 0 ? {} : { host: env.host },
18329
17981
  agentDir: env.agentDir,
18330
17982
  ...env.model === void 0 ? {} : { model: env.model },
18331
17983
  ...pickEngineAxis(env),
@@ -18344,6 +17996,7 @@ function roleTurnOptions(env, admitted, continuation) {
18344
17996
  return {
18345
17997
  packageRoot: env.packageRoot,
18346
17998
  home: env.home,
17999
+ ...env.host === void 0 ? {} : { host: env.host },
18347
18000
  agentDir: env.agentDir,
18348
18001
  ...env.model === void 0 ? {} : { model: env.model },
18349
18002
  ...pickEngineAxis(env),
@@ -18367,7 +18020,7 @@ async function dispatchAfterWriterLease(input) {
18367
18020
  }
18368
18021
  function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
18369
18022
  const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve13(attachmentPath);
18370
- return pathContainedIn(join34(runDirectory, "attachments"), absolute);
18023
+ return pathContainedIn(join33(runDirectory, "attachments"), absolute);
18371
18024
  }
18372
18025
  async function prepareSummonsResumeMaterials(runDirectory, summons) {
18373
18026
  if (summons === void 0) return void 0;
@@ -18696,6 +18349,150 @@ var init_seat_ticket_binding = __esm({
18696
18349
  }
18697
18350
  });
18698
18351
 
18352
+ // src/public-cli/machine-method-skills.ts
18353
+ import { accessSync, constants as constants2, statSync as statSync4 } from "node:fs";
18354
+ import { lstat as lstat7, mkdir as mkdir4, symlink } from "node:fs/promises";
18355
+ import { join as join34 } from "node:path";
18356
+ import { spawnSync } from "node:child_process";
18357
+ function skillRoot(home) {
18358
+ return join34(home, ".agents/skills");
18359
+ }
18360
+ function installedMethodSkillPath(home, name) {
18361
+ return installedSkillPath(skillRoot(home), name);
18362
+ }
18363
+ function installedSkillPath(root, name) {
18364
+ const path = join34(root, name, "SKILL.md");
18365
+ try {
18366
+ if (!statSync4(path).isFile()) return void 0;
18367
+ accessSync(path, constants2.R_OK);
18368
+ return path;
18369
+ } catch (error) {
18370
+ const code = error.code;
18371
+ if (code === "ENOENT" || code === "ENOTDIR" || code === "EACCES" || code === "EPERM" || code === "ELOOP") return void 0;
18372
+ throw error;
18373
+ }
18374
+ }
18375
+ function linkedSkillRoot(home, host) {
18376
+ if (host === "claude" || host === "claude-code") {
18377
+ return join34(process.env.CLAUDE_CONFIG_DIR?.trim() || join34(home, ".claude"), "skills");
18378
+ }
18379
+ if (host === "hermes") return join34(home, ".hermes/skills");
18380
+ return void 0;
18381
+ }
18382
+ async function occupied(path) {
18383
+ try {
18384
+ await lstat7(path);
18385
+ return true;
18386
+ } catch (error) {
18387
+ if (error.code !== "ENOENT") throw error;
18388
+ return false;
18389
+ }
18390
+ }
18391
+ function warnOccupied(path, stdout) {
18392
+ stdout(`Warning: ${path} is already occupied; left untouched.
18393
+ `);
18394
+ }
18395
+ async function warnMissingMethodSkills(home, host, role, skills, stdout) {
18396
+ const missing = [];
18397
+ const linkedRoot = linkedSkillRoot(home, host);
18398
+ for (const skill of skills) {
18399
+ if (installedMethodSkillPath(home, skill) === void 0 || linkedRoot !== void 0 && installedSkillPath(linkedRoot, skill) === void 0) missing.push(skill);
18400
+ }
18401
+ for (const skill of missing) {
18402
+ stdout(`Warning: required machine Skill "${skill}" is missing for ${role}; its method guidance may be unavailable and reduce work quality. Run \`ak-role setup\` to install required Skills.
18403
+ `);
18404
+ }
18405
+ }
18406
+ function runSkillsCli(args, home) {
18407
+ const result = spawnSync("npx", ["--yes", "skills", ...args], {
18408
+ stdio: "inherit",
18409
+ env: { ...process.env, HOME: home }
18410
+ });
18411
+ if (result.error !== void 0) throw result.error;
18412
+ return result.status === 0;
18413
+ }
18414
+ function addSkills(source, skills, home) {
18415
+ if (skills.length === 0) return true;
18416
+ return runSkillsCli([
18417
+ "add",
18418
+ source,
18419
+ ...skills.flatMap((skill) => ["--skill", skill]),
18420
+ "--agent",
18421
+ "codex",
18422
+ "--global",
18423
+ "--yes"
18424
+ ], home);
18425
+ }
18426
+ function updateRequiredSkills(home) {
18427
+ const names = packagedMethodSkillNames();
18428
+ if (names.length === 0) return true;
18429
+ return runSkillsCli(["update", "-g", "-y", ...names], home);
18430
+ }
18431
+ async function runMachineSkillSetup(home, stdout) {
18432
+ const canonical = skillRoot(home);
18433
+ const missingBySource = /* @__PURE__ */ new Map();
18434
+ let unsourced = false;
18435
+ for (const name of packagedMethodSkillNames()) {
18436
+ const path = join34(canonical, name);
18437
+ if (await occupied(path)) {
18438
+ warnOccupied(path, stdout);
18439
+ continue;
18440
+ }
18441
+ const source = SKILL_SOURCE[name];
18442
+ if (source === void 0) {
18443
+ unsourced = true;
18444
+ stdout(`Warning: required machine Skill "${name}" has no install source; setup did not install it.
18445
+ `);
18446
+ continue;
18447
+ }
18448
+ const missing = missingBySource.get(source) ?? [];
18449
+ missing.push(name);
18450
+ missingBySource.set(source, missing);
18451
+ }
18452
+ for (const [source, missing] of missingBySource) {
18453
+ if (!addSkills(source, missing, home)) return 1;
18454
+ }
18455
+ if (unsourced) return 1;
18456
+ for (const host of ["claude-code", "hermes"]) {
18457
+ const root = linkedSkillRoot(home, host);
18458
+ const binaryFromHome = host === "claude-code" ? HEADLESS_HOST_DESCRIPTIONS.claude.binaryFromHome : HOST_DESCRIPTIONS.hermes.binaryFromHome;
18459
+ try {
18460
+ accessSync(join34(home, ...binaryFromHome), constants2.X_OK);
18461
+ } catch (error) {
18462
+ if (["ENOENT", "ENOTDIR", "EACCES"].includes(error.code ?? "")) continue;
18463
+ throw error;
18464
+ }
18465
+ for (const name of packagedMethodSkillNames()) {
18466
+ const target = join34(canonical, name);
18467
+ if (installedMethodSkillPath(home, name) === void 0) continue;
18468
+ const link = join34(root, name);
18469
+ if (await occupied(link)) {
18470
+ warnOccupied(link, stdout);
18471
+ continue;
18472
+ }
18473
+ await mkdir4(root, { recursive: true });
18474
+ await symlink(target, link, "dir");
18475
+ }
18476
+ }
18477
+ if (!updateRequiredSkills(home)) return 1;
18478
+ stdout("Machine method Skills setup finished. Existing same-name Skills were left untouched.\n");
18479
+ return 0;
18480
+ }
18481
+ var SKILL_SOURCE;
18482
+ var init_machine_method_skills = __esm({
18483
+ "src/public-cli/machine-method-skills.ts"() {
18484
+ "use strict";
18485
+ init_host_descriptions();
18486
+ init_packaged_role_registry();
18487
+ SKILL_SOURCE = {
18488
+ tdd: "mattpocock/skills",
18489
+ "diagnosing-bugs": "mattpocock/skills",
18490
+ "resolving-merge-conflicts": "mattpocock/skills",
18491
+ "ak-cross-m-review": "Akagilnc/ak-cross-m-review"
18492
+ };
18493
+ }
18494
+ });
18495
+
18699
18496
  // src/public-cli/turn-request.ts
18700
18497
  function projectRoleTurnRequest(admitted, roleDetails, options) {
18701
18498
  const cwd = admitted.projectRoot ?? admitted.repoRoot ?? admitted.cwd;
@@ -18757,7 +18554,7 @@ function activationForAdmitted(admitted) {
18757
18554
  }
18758
18555
  return activation;
18759
18556
  }
18760
- function methodBindings(admitted, packageRoot) {
18557
+ function requiredMethodSkills(admitted) {
18761
18558
  const record4 = packagedRoleMetadata(admitted.role);
18762
18559
  const names = [];
18763
18560
  if (record4 !== void 0 && "methodSkills" in record4 && record4.methodSkills !== void 0) {
@@ -18765,38 +18562,40 @@ function methodBindings(admitted, packageRoot) {
18765
18562
  }
18766
18563
  const apply = packagedSettleSkill(admitted);
18767
18564
  if (apply !== void 0 && !names.includes(apply)) names.push(apply);
18768
- return names.map((name) => ({
18769
- kind: "skill",
18770
- path: resolvePackagedMethodSkillPath(packageRoot, name)
18771
- }));
18565
+ return names;
18566
+ }
18567
+ function methodBindings(admitted, home, host) {
18568
+ if (host !== void 0 && host !== "pi") return [];
18569
+ return requiredMethodSkills(admitted).flatMap((name) => {
18570
+ const path = installedMethodSkillPath(home, name);
18571
+ return path === void 0 ? [] : [{
18572
+ kind: "skill",
18573
+ path
18574
+ }];
18575
+ });
18772
18576
  }
18773
- function admittedSeatTurnDetails(admitted, packageRoot) {
18577
+ function admittedSeatTurnDetails(admitted, home, host) {
18774
18578
  return {
18775
18579
  activation: activationForAdmitted(admitted),
18776
- methods: methodBindings(admitted, packageRoot)
18580
+ methods: methodBindings(admitted, home, host)
18777
18581
  };
18778
18582
  }
18779
18583
  var init_turn_request = __esm({
18780
18584
  "src/public-cli/turn-request.ts"() {
18781
18585
  "use strict";
18782
18586
  init_engine_material();
18783
- init_method_skill();
18784
18587
  init_packaged_role_registry();
18588
+ init_machine_method_skills();
18785
18589
  init_run_lifecycle();
18786
18590
  }
18787
18591
  });
18788
18592
 
18789
18593
  // src/public-cli/countersign-run.ts
18790
- var countersign_run_exports = {};
18791
- __export(countersign_run_exports, {
18792
- invokeCourtDiarist: () => invokeCourtDiarist,
18793
- runCountersignCourtDiaristStation: () => runCountersignCourtDiaristStation
18794
- });
18795
- function isRecord14(value) {
18594
+ function isRecord13(value) {
18796
18595
  return typeof value === "object" && value !== null && !Array.isArray(value);
18797
18596
  }
18798
18597
  function isEscalatePayload(payload) {
18799
- if (!isRecord14(payload)) return false;
18598
+ if (!isRecord13(payload)) return false;
18800
18599
  return payload.status === "escalate";
18801
18600
  }
18802
18601
  function courtDiaristPayloadRows(roleOutcome, submissions) {
@@ -18891,7 +18690,8 @@ async function invokeCourtDiarist(input, env, io) {
18891
18690
  kind: "escalate",
18892
18691
  diagnostic: courtDiaristEscalateDiagnostic(roleOutcome, submissions)
18893
18692
  },
18894
- ...result.admitted === void 0 ? {} : { admitted: result.admitted }
18693
+ ...result.admitted === void 0 ? {} : { admitted: result.admitted },
18694
+ ...result.terminal === void 0 ? {} : { terminal: result.terminal }
18895
18695
  };
18896
18696
  }
18897
18697
  if (result.exitCode !== 0) {
@@ -18925,7 +18725,7 @@ async function invokeCourtDiarist(input, env, io) {
18925
18725
  ...result.admitted === void 0 ? {} : { admitted: result.admitted }
18926
18726
  };
18927
18727
  }
18928
- async function runCountersignCourtDiaristStation(admitted, env, io) {
18728
+ async function runCountersignCourtDiaristStation(admitted, env, io, afterTicketNumber) {
18929
18729
  if (env.runCourtDiaristStation !== void 0) {
18930
18730
  await env.runCourtDiaristStation(admitted);
18931
18731
  return;
@@ -18942,7 +18742,8 @@ async function runCountersignCourtDiaristStation(admitted, env, io) {
18942
18742
  } else {
18943
18743
  refreshTickets = [admitted.ticketNumber];
18944
18744
  }
18945
- for (const ticketNumber of refreshTickets) {
18745
+ const completedIndex = afterTicketNumber === void 0 ? -1 : refreshTickets.indexOf(afterTicketNumber);
18746
+ for (const ticketNumber of refreshTickets.slice(completedIndex + 1)) {
18946
18747
  const outcome = await invokeCourtDiarist(
18947
18748
  {
18948
18749
  instruction: `\u6574\u7406 #${ticketNumber} \u7684\u672C\u6848\u4F9D\u636E\u3002`,
@@ -18955,14 +18756,17 @@ async function runCountersignCourtDiaristStation(admitted, env, io) {
18955
18756
  env,
18956
18757
  io
18957
18758
  );
18958
- if (outcome.identity.kind === "escalate") {
18959
- throw new StationChildExhaustedError(outcome.identity.diagnostic);
18960
- }
18961
18759
  if (outcome.failedWithoutEscalate !== void 0) {
18962
18760
  throw new StationChildExhaustedError(
18963
18761
  outcome.failedWithoutEscalate.diagnostic
18964
18762
  );
18965
18763
  }
18764
+ if (outcome.identity.kind === "escalate" && outcome.terminal !== void 0) {
18765
+ return {
18766
+ terminal: outcome.terminal,
18767
+ ...outcome.admitted === void 0 ? {} : { childRunId: outcome.admitted.runId }
18768
+ };
18769
+ }
18966
18770
  }
18967
18771
  }
18968
18772
  var init_countersign_run = __esm({
@@ -18979,6 +18783,7 @@ var init_countersign_run = __esm({
18979
18783
  var instruction_seat_run_exports = {};
18980
18784
  __export(instruction_seat_run_exports, {
18981
18785
  buildInstructionSeatTurnRequest: () => buildInstructionSeatTurnRequest,
18786
+ continueParentAfterChild: () => continueParentAfterChild,
18982
18787
  runPublicInstructionSeat: () => runPublicInstructionSeat,
18983
18788
  runPublicInstructionSeatResume: () => runPublicInstructionSeatResume
18984
18789
  });
@@ -18993,7 +18798,7 @@ function roleRecord(role) {
18993
18798
  function buildInstructionSeatTurnRequest(admitted, options) {
18994
18799
  return projectRoleTurnRequest(
18995
18800
  admitted,
18996
- admittedSeatTurnDetails(admitted, options.packageRoot),
18801
+ admittedSeatTurnDetails(admitted, options.home, options.host),
18997
18802
  options
18998
18803
  );
18999
18804
  }
@@ -19026,11 +18831,11 @@ async function bindAndRelocateDiarist(admitted, authority, lease) {
19026
18831
  }
19027
18832
  await relocateAdmittedRunToTicket(admitted, authority, lease);
19028
18833
  }
19029
- function seatAdapters(admitted, env, material) {
18834
+ function seatAdapters(admitted, env) {
19030
18835
  const record4 = roleRecord(admitted.role);
19031
18836
  const present = "presentSettled" in record4 ? record4.presentSettled : "default";
19032
18837
  return {
19033
- trySettle: (seat, authority, scope) => trySettlePublicSeat(seat, authority, scope, material, env.packageRoot),
18838
+ trySettle: (seat, authority, scope) => trySettlePublicSeat(seat, authority, scope),
19034
18839
  ...present === "always" ? { shouldPresentSettled: () => true } : {},
19035
18840
  ...present === "typed" ? { shouldPresentSettled: (terminal) => isLawfulTypedTerminalOutcome(terminal.roleOutcome) } : {},
19036
18841
  ...infraFailure(admitted.role),
@@ -19082,23 +18887,8 @@ async function withAuditorSoulEnv(options) {
19082
18887
  }
19083
18888
  async function dispatchAdmitted(admitted, env, io) {
19084
18889
  const record4 = roleRecord(admitted.role);
19085
- let material;
19086
- const skill = packagedSettleSkill(admitted);
19087
- if (skill !== void 0) {
19088
- try {
19089
- material = await loadPackagedMethodSkillMaterial(env.packageRoot, skill);
19090
- } catch (error) {
19091
- const knownCause = packagedMethodLoadFailureCause(admitted.role);
19092
- return await presentControlledFailure2(admitted, {
19093
- timedOut: false,
19094
- code: null,
19095
- stderr: "",
19096
- thrown: error,
19097
- ...knownCause === void 0 ? {} : { knownCause }
19098
- }, seatAdapters(admitted, env), env.principalAuthority, io);
19099
- }
19100
- }
19101
- const adapters = seatAdapters(admitted, env, material);
18890
+ await warnMissingMethodSkills(env.home, env.host, admitted.role, requiredMethodSkills(admitted), io.stdout);
18891
+ const adapters = seatAdapters(admitted, env);
19102
18892
  const execute = async (activeEnv) => {
19103
18893
  const auto = "inCallAutoResume" in record4 && record4.inCallAutoResume === true;
19104
18894
  if (auto) {
@@ -19204,7 +18994,7 @@ async function runCountersignBody(parsed, env, io) {
19204
18994
  projectRoot: resolve14(parsed.project ?? env.cwd),
19205
18995
  role: "countersign",
19206
18996
  parentRunPath: gateParentRunPath,
19207
- ...env.boundTicketNumber === void 0 ? {} : { ticketNumber: env.boundTicketNumber },
18997
+ ...isSafePositiveTicketNumber(env.boundTicketNumber) ? { ticketNumber: env.boundTicketNumber } : {},
19208
18998
  freshSummons: env.freshSummons,
19209
18999
  summons: {
19210
19000
  sourceRunPath: gateParentRunPath,
@@ -19241,14 +19031,16 @@ async function runCountersignBody(parsed, env, io) {
19241
19031
  let typedTicket;
19242
19032
  let typedCourtTicketNumbers;
19243
19033
  let identityDiaristRan = false;
19244
- let unboundDiaristRunId;
19245
- if (env.runCourtDiaristStation === void 0) {
19034
+ let childDiaristRunId;
19035
+ let pausedDiaristTerminal;
19036
+ if (gateParentRunPath === void 0 && env.runCourtDiaristStation === void 0) {
19246
19037
  let outcome;
19247
19038
  try {
19248
19039
  outcome = await invokeCourtDiarist({
19249
19040
  instruction: parsed.instruction ?? "",
19250
19041
  projectRoot: admitted.projectRoot,
19251
19042
  failureLabel: "unbound summons",
19043
+ correlationId: admitted.runId,
19252
19044
  ...env.boundTicketNumber === void 0 ? {} : { boundTicketNumber: env.boundTicketNumber }
19253
19045
  }, env, io);
19254
19046
  } catch (error) {
@@ -19264,15 +19056,16 @@ async function runCountersignBody(parsed, env, io) {
19264
19056
  }, seatAdapters(admitted, env), env.principalAuthority, io);
19265
19057
  }
19266
19058
  identityDiaristRan = true;
19059
+ if (outcome.identity.kind === "escalate") pausedDiaristTerminal = outcome.terminal;
19267
19060
  if (outcome.admitted?.runDirectory.includes(`${sep5}unbound${sep5}runs${sep5}`)) {
19268
- unboundDiaristRunId = outcome.admitted.runId;
19061
+ childDiaristRunId = outcome.admitted.runId;
19269
19062
  }
19270
- if (outcome.identity.kind === "escalate" || outcome.failedWithoutEscalate !== void 0) {
19271
- const diagnostic = outcome.identity.kind === "escalate" ? outcome.identity.diagnostic : outcome.failedWithoutEscalate?.diagnostic ?? "";
19063
+ if (outcome.failedWithoutEscalate !== void 0) {
19064
+ const diagnostic = outcome.failedWithoutEscalate.diagnostic;
19272
19065
  await materializeAdmission(
19273
19066
  isSafePositiveTicketNumber(env.boundTicketNumber) ? env.boundTicketNumber : void 0
19274
19067
  );
19275
- if (unboundDiaristRunId !== void 0) await recordChildDiaristRun(admitted, unboundDiaristRunId);
19068
+ if (childDiaristRunId !== void 0) await recordChildDiaristRun(admitted, childDiaristRunId);
19276
19069
  await markRunAdmitted(admitted, env.principalAuthority);
19277
19070
  return await presentControlledFailure2(admitted, {
19278
19071
  timedOut: false,
@@ -19282,16 +19075,18 @@ async function runCountersignBody(parsed, env, io) {
19282
19075
  }, seatAdapters(admitted, env), env.principalAuthority, io);
19283
19076
  }
19284
19077
  if (outcome.identity.kind === "ticket") {
19285
- typedTicket = isSafePositiveTicketNumber(env.boundTicketNumber) ? env.boundTicketNumber : outcome.identity.ticketNumber;
19078
+ typedTicket = outcome.identity.ticketNumber;
19286
19079
  typedCourtTicketNumbers = outcome.identity.courtTicketNumbers;
19287
- } else if (isSafePositiveTicketNumber(env.boundTicketNumber)) {
19288
- typedTicket = env.boundTicketNumber;
19289
19080
  }
19290
19081
  }
19291
19082
  await materializeAdmission(typedTicket);
19292
19083
  await markRunAdmitted(admitted, env.principalAuthority);
19293
- if (unboundDiaristRunId !== void 0) {
19294
- await recordChildDiaristRun(admitted, unboundDiaristRunId);
19084
+ if (childDiaristRunId !== void 0) {
19085
+ await recordChildDiaristRun(admitted, childDiaristRunId);
19086
+ }
19087
+ if (pausedDiaristTerminal !== void 0) {
19088
+ io.stdout(formatTerminalResult(pausedDiaristTerminal));
19089
+ return { exitCode: 0, admitted, terminal: pausedDiaristTerminal };
19295
19090
  }
19296
19091
  if (gateParentRunPath !== void 0) {
19297
19092
  await persistAdmittedSourceRunPath(admitted, gateParentRunPath);
@@ -19341,7 +19136,11 @@ async function runCountersignBody(parsed, env, io) {
19341
19136
  beforeDispatch: async (admittedSeat, lease) => {
19342
19137
  if (!packagedAdmitsCountersign(admittedSeat.role)) return;
19343
19138
  if (!identityDiaristRan || typedTicket !== void 0) {
19344
- await runCountersignCourtDiaristStation(admittedSeat, env, io);
19139
+ const refresh = await runCountersignCourtDiaristStation(admittedSeat, env, io);
19140
+ if (refresh !== void 0) {
19141
+ io.stdout(formatTerminalResult(refresh.terminal));
19142
+ return refresh.terminal;
19143
+ }
19345
19144
  }
19346
19145
  await relocateAdmittedRunToTicket(admittedSeat, env.principalAuthority, lease);
19347
19146
  Object.assign(turnRequest, buildInstructionSeatTurnRequest(admittedSeat, turnProjection));
@@ -19418,7 +19217,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
19418
19217
  projectRoot,
19419
19218
  role,
19420
19219
  parentRunPath: sourceDirectory,
19421
- ...auditorTicket === void 0 ? {} : { ticketNumber: auditorTicket },
19422
19220
  freshSummons: env.freshSummons,
19423
19221
  summons,
19424
19222
  resume: (runId, materials) => runPublicInstructionSeatResume(
@@ -19444,7 +19242,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
19444
19242
  projectRoot,
19445
19243
  role,
19446
19244
  parentRunPath,
19447
- ...env.boundTicketNumber === void 0 ? {} : { ticketNumber: env.boundTicketNumber },
19448
19245
  freshSummons: env.freshSummons,
19449
19246
  summons,
19450
19247
  resume: (runId, materials) => runPublicInstructionSeatResume(
@@ -19472,7 +19269,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
19472
19269
  throw error;
19473
19270
  }
19474
19271
  const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
19475
- const knownTicket = await readBoardTicketNumber(source.runDirectory) ?? env.boundTicketNumber;
19476
19272
  const summons = {
19477
19273
  sourceRunPath: source.runDirectory,
19478
19274
  sourceRun: source,
@@ -19483,7 +19279,6 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
19483
19279
  projectRoot,
19484
19280
  role,
19485
19281
  parentRunPath: source.runDirectory,
19486
- ...knownTicket === void 0 ? {} : { ticketNumber: knownTicket },
19487
19282
  freshSummons: env.freshSummons,
19488
19283
  summons,
19489
19284
  resume: (runId, materials) => runPublicInstructionSeatResume(
@@ -19520,50 +19315,38 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv2) {
19520
19315
  }
19521
19316
  const runAdmitted = async () => {
19522
19317
  await markRunAdmitted(admitted, env.principalAuthority);
19523
- if (record4.sameParent === "court-diarist") {
19524
- const { invokeCourtDiarist: invokeCourtDiarist2 } = await Promise.resolve().then(() => (init_countersign_run(), countersign_run_exports));
19525
- const outcome = await invokeCourtDiarist2({
19526
- instruction: parsed.instruction ?? "",
19527
- projectRoot: admitted.projectRoot,
19528
- failureLabel: "secretariat unbound summons",
19529
- attachmentPaths: admitted.attachments.map((attachment) => attachment.frozenPath),
19530
- correlationId: admitted.runId
19531
- }, {
19532
- cwd: env.cwd,
19533
- home: env.home,
19534
- agentDir: env.agentDir,
19535
- packageRoot: env.packageRoot,
19536
- ...env.credentials === void 0 ? {} : { credentials: env.credentials },
19537
- ...env.signal === void 0 ? {} : { signal: env.signal },
19538
- ...env.hostAdapters === void 0 ? {} : { hostAdapters: env.hostAdapters }
19539
- }, io);
19318
+ if (role === "secretariat") {
19319
+ let outcome;
19320
+ try {
19321
+ outcome = await invokeCourtDiarist({
19322
+ instruction: parsed.instruction ?? "",
19323
+ projectRoot: admitted.projectRoot,
19324
+ failureLabel: "secretariat unbound summons",
19325
+ attachmentPaths: admitted.attachments.map((attachment) => attachment.frozenPath),
19326
+ correlationId: admitted.runId
19327
+ }, env, io);
19328
+ } catch (error) {
19329
+ return await presentControlledFailure2(admitted, {
19330
+ timedOut: false,
19331
+ code: null,
19332
+ stderr: "",
19333
+ thrown: error
19334
+ }, seatAdapters(admitted, env), env.principalAuthority, io);
19335
+ }
19540
19336
  if (outcome.admitted?.runDirectory.includes(`${sep5}unbound${sep5}runs${sep5}`)) {
19541
19337
  await recordChildDiaristRun(admitted, outcome.admitted.runId);
19542
19338
  }
19543
- if (outcome.identity.kind === "escalate" || outcome.failedWithoutEscalate !== void 0) {
19544
- const diagnostic = outcome.identity.kind === "escalate" ? outcome.identity.diagnostic : outcome.failedWithoutEscalate?.diagnostic ?? "";
19339
+ if (outcome.failedWithoutEscalate !== void 0) {
19545
19340
  return await presentControlledFailure2(admitted, {
19546
19341
  timedOut: false,
19547
19342
  code: null,
19548
19343
  stderr: "",
19549
- thrown: new Error(diagnostic)
19344
+ thrown: new Error(outcome.failedWithoutEscalate.diagnostic)
19550
19345
  }, seatAdapters(admitted, env), env.principalAuthority, io);
19551
19346
  }
19552
- if (outcome.identity.kind === "ticket") {
19553
- try {
19554
- if (outcome.admitted === void 0) throw new Error("court diarist ticket has no admitted run");
19555
- await bindAdmittedTicketNumber(outcome.admitted, outcome.identity.ticketNumber);
19556
- await relocateAdmittedRunToTicket(outcome.admitted, env.principalAuthority);
19557
- await bindAdmittedTicketNumber(admitted, outcome.identity.ticketNumber);
19558
- await relocateAdmittedRunToTicket(admitted, env.principalAuthority);
19559
- } catch (error) {
19560
- return await presentControlledFailure2(admitted, {
19561
- timedOut: false,
19562
- code: null,
19563
- stderr: "",
19564
- thrown: error
19565
- }, seatAdapters(admitted, env), env.principalAuthority, io);
19566
- }
19347
+ if (outcome.identity.kind === "escalate" && outcome.terminal !== void 0) {
19348
+ io.stdout(formatTerminalResult(outcome.terminal));
19349
+ return { exitCode: 0, admitted, terminal: outcome.terminal };
19567
19350
  }
19568
19351
  }
19569
19352
  return dispatchAdmitted(admitted, env, io);
@@ -19608,32 +19391,34 @@ async function runPublicInstructionSeatResume(request, env, io) {
19608
19391
  adapters: {
19609
19392
  trySettle: async () => void 0
19610
19393
  },
19611
- afterAdmittedLoad: (admitted) => {
19612
- const skill = packagedSettleSkill(admitted);
19613
- if (skill === void 0) {
19614
- return Promise.resolve({ kind: "continue", adapters: seatAdapters(admitted, env) });
19615
- }
19616
- const knownCause = packagedMethodLoadFailureCause(admitted.role);
19617
- return resolveResumeMethodMaterialAdapters({
19618
- admitted,
19619
- authority: env.principalAuthority,
19620
- io,
19621
- loadMaterial: () => loadPackagedMethodSkillMaterial(env.packageRoot, skill),
19622
- adaptersWith: (material) => seatAdapters(admitted, env, material),
19623
- emptyAdapters: seatAdapters(admitted, env),
19624
- ...knownCause === void 0 ? {} : { knownCause }
19625
- });
19394
+ afterAdmittedLoad: async (admitted) => {
19395
+ await warnMissingMethodSkills(env.home, env.host, admitted.role, requiredMethodSkills(admitted), io.stdout);
19396
+ return { kind: "continue", adapters: seatAdapters(admitted, env) };
19626
19397
  },
19627
19398
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
19628
19399
  });
19629
19400
  }
19401
+ async function continueParentAfterChild(parentRunId, child, env, io) {
19402
+ const loaded = await loadResumablePublicRole(env.home, parentRunId, env.principalAuthority, true);
19403
+ if (loaded.run.state !== "admitted") {
19404
+ return runPublicInstructionSeatResume({ runId: parentRunId }, env, io);
19405
+ }
19406
+ const admitted = loaded.admitted;
19407
+ if (admitted.role === "countersign" && admitted.ticketNumber !== void 0) {
19408
+ const refresh = await runCountersignCourtDiaristStation(admitted, env, io, child.ticketNumber);
19409
+ if (refresh !== void 0) {
19410
+ io.stdout(formatTerminalResult(refresh.terminal));
19411
+ return { exitCode: 0, admitted, terminal: refresh.terminal };
19412
+ }
19413
+ }
19414
+ return dispatchAdmitted(admitted, env, io);
19415
+ }
19630
19416
  var init_instruction_seat_run = __esm({
19631
19417
  "src/public-cli/instruction-seat-run.ts"() {
19632
19418
  "use strict";
19633
19419
  init_run_ticket_number();
19634
19420
  init_notary_source_run();
19635
19421
  init_engine_material();
19636
- init_method_skill();
19637
19422
  init_packaged_role_registry();
19638
19423
  init_auditor_soul();
19639
19424
  init_cli_errors();
@@ -19642,6 +19427,7 @@ var init_instruction_seat_run = __esm({
19642
19427
  init_run_lifecycle();
19643
19428
  init_seat_ticket_binding();
19644
19429
  init_settlement();
19430
+ init_machine_method_skills();
19645
19431
  init_terminal();
19646
19432
  init_turn_request();
19647
19433
  init_countersign_run();
@@ -19649,13 +19435,13 @@ var init_instruction_seat_run = __esm({
19649
19435
  });
19650
19436
 
19651
19437
  // src/analyst-book-key.ts
19652
- import { statSync as statSync4 } from "node:fs";
19438
+ import { statSync as statSync5 } from "node:fs";
19653
19439
  import { isAbsolute as isAbsolute9 } from "node:path";
19654
19440
  function resolveAnalystBookKey(projectRoot) {
19655
19441
  const identity = physicalPathIdentity(projectRoot);
19656
19442
  let stats;
19657
19443
  try {
19658
- stats = statSync4(identity);
19444
+ stats = statSync5(identity);
19659
19445
  } catch (error) {
19660
19446
  const code = errnoCode(error);
19661
19447
  if (code === "ENOENT" || code === "ENOTDIR") return `root:${identity}`;
@@ -19704,11 +19490,11 @@ var init_atomic_write = __esm({
19704
19490
  });
19705
19491
 
19706
19492
  // src/analyst-index.ts
19707
- import { open as open3, readFile as readFile19, unlink as unlink5 } from "node:fs/promises";
19493
+ import { open as open3, readFile as readFile18, unlink as unlink5 } from "node:fs/promises";
19708
19494
  import { dirname as dirname19, join as join36 } from "node:path";
19709
19495
  function sleep(ms) {
19710
- return new Promise((resolve22) => {
19711
- setTimeout(resolve22, ms);
19496
+ return new Promise((resolve21) => {
19497
+ setTimeout(resolve21, ms);
19712
19498
  });
19713
19499
  }
19714
19500
  async function withAnalystLibraryIndexLock(ledgerHome, fn) {
@@ -19832,7 +19618,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
19832
19618
  const path = analystLibraryIndexPath(ledgerHome);
19833
19619
  let raw;
19834
19620
  try {
19835
- raw = await readFile19(path, "utf8");
19621
+ raw = await readFile18(path, "utf8");
19836
19622
  } catch (error) {
19837
19623
  if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
19838
19624
  return void 0;
@@ -20036,15 +19822,15 @@ var init_analyst_cohort = __esm({
20036
19822
  });
20037
19823
 
20038
19824
  // src/analyst-ledger.ts
20039
- import { readdir as readdir8, readFile as readFile20 } from "node:fs/promises";
20040
- import { basename as basename9, join as join37 } from "node:path";
19825
+ import { readdir as readdir8, readFile as readFile19 } from "node:fs/promises";
19826
+ import { basename as basename8, join as join37 } from "node:path";
20041
19827
  function isMissingPathError6(error) {
20042
19828
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
20043
19829
  }
20044
19830
  function errorText3(error) {
20045
19831
  return error instanceof Error ? error.message : String(error);
20046
19832
  }
20047
- function isRecord15(value) {
19833
+ function isRecord14(value) {
20048
19834
  return typeof value === "object" && value !== null && !Array.isArray(value);
20049
19835
  }
20050
19836
  async function readExistingRunLifecycleState(runDirectory) {
@@ -20095,13 +19881,13 @@ async function listLedgerBookNames(booksRoot) {
20095
19881
  async function readInvocationScopeFields(runDirectory) {
20096
19882
  let raw;
20097
19883
  try {
20098
- raw = await readFile20(join37(runDirectory, "invocation.json"), "utf8");
19884
+ raw = await readFile19(join37(runDirectory, "invocation.json"), "utf8");
20099
19885
  } catch (error) {
20100
19886
  if (isMissingPathError6(error)) return void 0;
20101
19887
  throw error;
20102
19888
  }
20103
19889
  const parsed = JSON.parse(raw);
20104
- if (!isRecord15(parsed)) return void 0;
19890
+ if (!isRecord14(parsed)) return void 0;
20105
19891
  if (typeof parsed.projectRoot !== "string" || parsed.projectRoot.trim() === "") {
20106
19892
  return void 0;
20107
19893
  }
@@ -20128,9 +19914,9 @@ function decideIssueScope(input) {
20128
19914
  }
20129
19915
  async function resolveSessionFile(runDirectory) {
20130
19916
  try {
20131
- const raw = await readFile20(join37(runDirectory, "invocation.json"), "utf8");
19917
+ const raw = await readFile19(join37(runDirectory, "invocation.json"), "utf8");
20132
19918
  const parsed = JSON.parse(raw);
20133
- if (isRecord15(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
19919
+ if (isRecord14(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
20134
19920
  return parsed.sessionFile;
20135
19921
  }
20136
19922
  } catch (error) {
@@ -20407,7 +20193,7 @@ async function scanAnalystIssueRuns(input) {
20407
20193
  throw error;
20408
20194
  }
20409
20195
  for (const runDirectory of runDirectories) {
20410
- const runName = basename9(runDirectory);
20196
+ const runName = basename8(runDirectory);
20411
20197
  const parsed = parseRunDirectoryName2(runName);
20412
20198
  if (parsed === void 0) continue;
20413
20199
  let scopeFields;
@@ -20468,7 +20254,7 @@ var init_analyst_ledger = __esm({
20468
20254
  });
20469
20255
 
20470
20256
  // src/analyst-metric-families/acceptance-success-rework.ts
20471
- function isRecord16(value) {
20257
+ function isRecord15(value) {
20472
20258
  return typeof value === "object" && value !== null && !Array.isArray(value);
20473
20259
  }
20474
20260
  function wallMsFromSpan(span) {
@@ -20477,21 +20263,21 @@ function wallMsFromSpan(span) {
20477
20263
  function findCollectorGroups(body) {
20478
20264
  if (Array.isArray(body.groups)) return body.groups;
20479
20265
  const receipt = body.receipt;
20480
- if (isRecord16(receipt) && Array.isArray(receipt.groups)) return receipt.groups;
20266
+ if (isRecord15(receipt) && Array.isArray(receipt.groups)) return receipt.groups;
20481
20267
  const outcome = body.outcome;
20482
- if (isRecord16(outcome)) {
20268
+ if (isRecord15(outcome)) {
20483
20269
  const facts = outcome.decisiveFacts;
20484
- if (isRecord16(facts) && Array.isArray(facts.groups)) return facts.groups;
20270
+ if (isRecord15(facts) && Array.isArray(facts.groups)) return facts.groups;
20485
20271
  }
20486
20272
  return void 0;
20487
20273
  }
20488
20274
  function extractStatus(body) {
20489
20275
  const outcome = body.outcome;
20490
- if (isRecord16(outcome) && typeof outcome.status === "string" && outcome.status.trim() !== "") {
20276
+ if (isRecord15(outcome) && typeof outcome.status === "string" && outcome.status.trim() !== "") {
20491
20277
  return outcome.status;
20492
20278
  }
20493
20279
  const receipt = body.receipt;
20494
- if (isRecord16(receipt) && typeof receipt.status === "string" && receipt.status.trim() !== "") {
20280
+ if (isRecord15(receipt) && typeof receipt.status === "string" && receipt.status.trim() !== "") {
20495
20281
  return receipt.status;
20496
20282
  }
20497
20283
  if (typeof body.status === "string" && body.status.trim() !== "") {
@@ -21117,15 +20903,15 @@ var init_leg_wall_clock = __esm({
21117
20903
  });
21118
20904
 
21119
20905
  // src/analyst-metric-families/round-timeline.ts
21120
- function isRecord17(value) {
20906
+ function isRecord16(value) {
21121
20907
  return typeof value === "object" && value !== null && !Array.isArray(value);
21122
20908
  }
21123
20909
  function wallMsFromSpan2(startedAt, endedAt) {
21124
20910
  return Date.parse(endedAt) - Date.parse(startedAt);
21125
20911
  }
21126
20912
  function readClassCount(body) {
21127
- if (!isRecord17(body.outcome)) return void 0;
21128
- if (!isRecord17(body.outcome.decisiveFacts)) return void 0;
20913
+ if (!isRecord16(body.outcome)) return void 0;
20914
+ if (!isRecord16(body.outcome.decisiveFacts)) return void 0;
21129
20915
  const classCount = body.outcome.decisiveFacts.classCount;
21130
20916
  if (typeof classCount !== "number" || !Number.isFinite(classCount)) {
21131
20917
  return void 0;
@@ -21269,7 +21055,7 @@ var init_analyst_metric_family = __esm({
21269
21055
  });
21270
21056
 
21271
21057
  // src/analyst-page.ts
21272
- import { createHash as createHash9 } from "node:crypto";
21058
+ import { createHash as createHash8 } from "node:crypto";
21273
21059
  import { dirname as dirname20, join as join38 } from "node:path";
21274
21060
  function analystIssuePageKey(address) {
21275
21061
  const parts = ["book", address.bookKey];
@@ -21278,7 +21064,7 @@ function analystIssuePageKey(address) {
21278
21064
  } else if (address.scopeRootIdentity !== void 0) {
21279
21065
  parts.push("root", physicalPathIdentity(address.scopeRootIdentity));
21280
21066
  }
21281
- return createHash9("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
21067
+ return createHash8("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
21282
21068
  }
21283
21069
  function analystIssuePagePath(ledgerHome, address) {
21284
21070
  return join38(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
@@ -21417,7 +21203,7 @@ var init_analyst_page = __esm({
21417
21203
  });
21418
21204
 
21419
21205
  // src/analyst-entry.ts
21420
- import { readFile as readFile21 } from "node:fs/promises";
21206
+ import { readFile as readFile20 } from "node:fs/promises";
21421
21207
  import { Type as Type11 } from "typebox";
21422
21208
  function isMissingPathError7(error) {
21423
21209
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
@@ -21448,7 +21234,7 @@ async function readOrComputeAnalystIssuePage(input, options) {
21448
21234
  ...issueNumber === void 0 && input.bookKey === void 0 ? { scopeRootIdentity: projectRoot } : {}
21449
21235
  });
21450
21236
  try {
21451
- const raw = await readFile21(pagePath, "utf8");
21237
+ const raw = await readFile20(pagePath, "utf8");
21452
21238
  const page = JSON.parse(raw);
21453
21239
  if (cachedPageMatchesRequestedScope(page, { bookKey, ...input })) {
21454
21240
  const ghostScan = await scanAnalystIssueRuns({
@@ -21549,7 +21335,7 @@ async function runAnalystModelGroupsMode(input, home) {
21549
21335
  scopeRootIdentity: projectRoot
21550
21336
  });
21551
21337
  try {
21552
- const raw = await readFile21(pagePath, "utf8");
21338
+ const raw = await readFile20(pagePath, "utf8");
21553
21339
  JSON.parse(raw);
21554
21340
  } catch (error) {
21555
21341
  if (!isMissingPathError7(error)) {
@@ -21647,7 +21433,7 @@ var init_analyst_entry = __esm({
21647
21433
  });
21648
21434
 
21649
21435
  // src/public-cli/analyst-run.ts
21650
- import { readFile as readFile22 } from "node:fs/promises";
21436
+ import { readFile as readFile21 } from "node:fs/promises";
21651
21437
  import { isAbsolute as isAbsolute10, resolve as resolve15 } from "node:path";
21652
21438
  import { Value as Value2 } from "typebox/value";
21653
21439
  function resolveAnalystIssueBookKeyFromCwd(cwd = process.cwd()) {
@@ -21701,7 +21487,7 @@ async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
21701
21487
  const absolute = isAbsolute10(sourcePath) ? sourcePath : resolve15(sourcePath);
21702
21488
  let bytes;
21703
21489
  try {
21704
- bytes = await readFile22(absolute);
21490
+ bytes = await readFile21(absolute);
21705
21491
  } catch (error) {
21706
21492
  throw new CliUsageError(
21707
21493
  `analyst sweep attachment is not a readable regular file: ${sourcePath}`,
@@ -21820,7 +21606,7 @@ __export(cli_exports, {
21820
21606
  resolveInternalRoleEntrypoint: () => resolveInternalRoleEntrypoint,
21821
21607
  runAkRole: () => runAkRole
21822
21608
  });
21823
- import { realpath as realpath6 } from "node:fs/promises";
21609
+ import { realpath as realpath5 } from "node:fs/promises";
21824
21610
  import { join as join39 } from "node:path";
21825
21611
  function publicSeatArgv(owner) {
21826
21612
  return {
@@ -22495,7 +22281,7 @@ async function runAkRole(argv, env) {
22495
22281
  try {
22496
22282
  env = {
22497
22283
  ...env,
22498
- packageRoot: await realpath6(env.packageRoot),
22284
+ packageRoot: await realpath5(env.packageRoot),
22499
22285
  principalAuthority: env.principalAuthority ?? piDurablePrincipalAuthority
22500
22286
  };
22501
22287
  let parsed = parseArgv(argv);
@@ -22544,6 +22330,10 @@ async function runAkRole(argv, env) {
22544
22330
  exitCode: await runConfigCommand(parsed.args, home, env.packageRoot, io)
22545
22331
  };
22546
22332
  }
22333
+ if (parsed.command === "setup") {
22334
+ if (parsed.args.length !== 0) throw new CliUsageError("setup takes no arguments");
22335
+ return { exitCode: await runMachineSkillSetup(home, io.stdout) };
22336
+ }
22547
22337
  if (parsed.command === "new") {
22548
22338
  const role = parsed.args[0];
22549
22339
  if (role === void 0) {
@@ -22586,7 +22376,24 @@ async function runAkRole(argv, env) {
22586
22376
  }),
22587
22377
  io
22588
22378
  );
22589
- return cliResultFromRoleRun(result);
22379
+ let current = result;
22380
+ while (current.exitCode === 0 && current.admitted?.correlationId !== void 0 && current.terminal?.roleOutcome.kind === "accepted" && !courtDiaristEscalated(current.terminal.roleOutcome)) {
22381
+ const parentRunId = current.admitted.correlationId;
22382
+ const parentRole = await peekRoleRunRole(home, parentRunId);
22383
+ if (parentRole === void 0) break;
22384
+ const parentSeat = resolveEffectiveSeat(config, parentRole, credentials, invocationFromParsed(parsed));
22385
+ const parentEnv = createRoleEnvironment(env, {
22386
+ role: parentRole,
22387
+ home,
22388
+ agentDir,
22389
+ cwd,
22390
+ credentials,
22391
+ seat: parentSeat,
22392
+ config
22393
+ });
22394
+ current = await continueParentAfterChild(parentRunId, current.admitted, parentEnv, io);
22395
+ }
22396
+ return cliResultFromRoleRun(current);
22590
22397
  }
22591
22398
  if (parsed.command !== void 0 && isPublicCliSupportCommand(parsed.command)) {
22592
22399
  throw new CliUsageError(`unhandled support command: ${parsed.command}`);
@@ -22650,11 +22457,13 @@ var init_cli = __esm({
22650
22457
  init_packaged_role_registry();
22651
22458
  init_registry();
22652
22459
  init_cli_errors();
22460
+ init_machine_method_skills();
22653
22461
  init_role_turn_host();
22654
22462
  init_role_turn_host_resolution();
22655
22463
  init_invocation();
22656
22464
  init_option_definitions();
22657
22465
  init_instruction_seat_run();
22466
+ init_countersign_run();
22658
22467
  init_analyst_run();
22659
22468
  init_run_lifecycle();
22660
22469
  init_registry();
@@ -22683,7 +22492,7 @@ __export(public_role_summons_exports, {
22683
22492
  });
22684
22493
  import { execFile as execFile3 } from "node:child_process";
22685
22494
  import { existsSync as existsSync11 } from "node:fs";
22686
- import { realpath as realpath7 } from "node:fs/promises";
22495
+ import { realpath as realpath6 } from "node:fs/promises";
22687
22496
  import { join as join40 } from "node:path";
22688
22497
  import { promisify as promisify3 } from "node:util";
22689
22498
  function createCapturingIo() {
@@ -22954,7 +22763,10 @@ async function summonPublicRole(options) {
22954
22763
  result = stepped.ok;
22955
22764
  }
22956
22765
  const stderr = captured?.stderrText();
22957
- const runDirectory = result.admitted?.runDirectory;
22766
+ const runDirectory = result.terminal !== void 0 && result.terminal.roleOutcome.role !== options.role && typeof result.terminal.runId === "string" ? await (await Promise.resolve().then(() => (init_run_lifecycle(), run_lifecycle_exports))).findRunDirectoryById(
22767
+ home,
22768
+ result.terminal.runId
22769
+ ) : result.admitted?.runDirectory;
22958
22770
  return {
22959
22771
  exitCode: result.exitCode,
22960
22772
  ...result.terminal === void 0 ? {} : { terminal: result.terminal },
@@ -22969,8 +22781,8 @@ function withReviewerLens(argv, lens) {
22969
22781
  return [...argv.slice(0, separator), "--lens", lens, ...argv.slice(separator)];
22970
22782
  }
22971
22783
  async function resolveReviewerGitToplevel(projectRoot) {
22972
- const callerProjectRoot = await realpath7(projectRoot);
22973
- return await realpath7((await execFileAsync3(
22784
+ const callerProjectRoot = await realpath6(projectRoot);
22785
+ return await realpath6((await execFileAsync3(
22974
22786
  "git",
22975
22787
  ["rev-parse", "--show-toplevel"],
22976
22788
  { cwd: callerProjectRoot }
@@ -23158,8 +22970,10 @@ async function summonGateOfficer(options) {
23158
22970
  `countersign gate summon requires parent runId from sourceRunDirectory: ${options.sourceRunDirectory}`
23159
22971
  );
23160
22972
  }
23161
- const { readBoardTicketNumber: readBoardTicketNumber2 } = await Promise.resolve().then(() => (init_run_ticket_number(), run_ticket_number_exports));
22973
+ const { isSafePositiveTicketNumber: isSafePositiveTicketNumber2, readBoardTicketNumber: readBoardTicketNumber2 } = await Promise.resolve().then(() => (init_run_ticket_number(), run_ticket_number_exports));
23162
22974
  const parentTicket = await readBoardTicketNumber2(options.sourceRunDirectory);
22975
+ const submittedTicket = options.submission !== null && typeof options.submission === "object" && !Array.isArray(options.submission) ? options.submission.ticketNumber : void 0;
22976
+ const courtTicket = isSafePositiveTicketNumber2(submittedTicket) ? submittedTicket : parentTicket;
23163
22977
  const instruction = options.reask ?? gateReviewInstruction ?? "";
23164
22978
  return summonPublicRole({
23165
22979
  role: options.officer,
@@ -23167,7 +22981,7 @@ async function summonGateOfficer(options) {
23167
22981
  ...common,
23168
22982
  correlationId,
23169
22983
  parentRunPath: options.sourceRunDirectory,
23170
- ...parentTicket === void 0 ? {} : { boundTicketNumber: parentTicket }
22984
+ ...courtTicket === void 0 ? {} : { boundTicketNumber: courtTicket }
23171
22985
  });
23172
22986
  }
23173
22987
  return summonPublicRole({
@@ -23194,7 +23008,7 @@ init_engine_detour();
23194
23008
  import { randomUUID as randomUUID9 } from "node:crypto";
23195
23009
  import { appendFile as appendFile3, mkdir as mkdir5, writeFile as writeFile11 } from "node:fs/promises";
23196
23010
  import { createServer } from "node:net";
23197
- import { dirname as dirname23, join as join45 } from "node:path";
23011
+ import { dirname as dirname22, join as join44 } from "node:path";
23198
23012
  import { fileURLToPath as fileURLToPath2 } from "node:url";
23199
23013
 
23200
23014
  // src/submission-gate.ts
@@ -23298,119 +23112,6 @@ async function requireSubmissionGate(options) {
23298
23112
  }
23299
23113
  }
23300
23114
 
23301
- // src/host-native-method.ts
23302
- import { access as access4, lstat as lstat7, mkdir as mkdir4, readdir as readdir9, readFile as readFile23, readlink, realpath as realpath8, symlink } from "node:fs/promises";
23303
- import { basename as basename10, dirname as dirname21, join as join41 } from "node:path";
23304
- var packagedMethodsDir = (root) => join41(root, "resources", "methods");
23305
- function hostMethodSkills(methods) {
23306
- return Object.freeze(methods.flatMap((method) => {
23307
- if (method.kind !== "skill") return [];
23308
- const name = basename10(dirname21(method.path));
23309
- return name ? [Object.freeze({ name })] : [];
23310
- }));
23311
- }
23312
- var isEnoent3 = (error) => error.code === "ENOENT";
23313
- async function packagedMethodSkillNames(packagedMethodsRealpath) {
23314
- const entries = await readdir9(packagedMethodsRealpath, { withFileTypes: true });
23315
- const names = [];
23316
- for (const entry of entries) {
23317
- if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
23318
- try {
23319
- await access4(join41(packagedMethodsRealpath, entry.name, "SKILL.md"));
23320
- } catch (error) {
23321
- if (isEnoent3(error)) continue;
23322
- throw error;
23323
- }
23324
- names.push(entry.name);
23325
- }
23326
- return names;
23327
- }
23328
- async function packagedSkillFileBytes(skillDir) {
23329
- try {
23330
- await access4(join41(skillDir, "SKILL.md"));
23331
- } catch (error) {
23332
- if (isEnoent3(error)) return void 0;
23333
- throw error;
23334
- }
23335
- const files = /* @__PURE__ */ new Map();
23336
- async function walk(dir, prefix) {
23337
- const entries = await readdir9(dir, { withFileTypes: true });
23338
- for (const entry of entries) {
23339
- const rel = prefix === "" ? entry.name : `${prefix}/${entry.name}`;
23340
- const full = join41(dir, entry.name);
23341
- if (entry.isDirectory()) {
23342
- await walk(full, rel);
23343
- continue;
23344
- }
23345
- if (entry.isFile()) {
23346
- files.set(rel, await readFile23(full));
23347
- }
23348
- }
23349
- }
23350
- await walk(skillDir, "");
23351
- return files;
23352
- }
23353
- async function catalogPublishesPackagedSkill(catalogSkillDir, required) {
23354
- for (const [rel, bytes] of required) {
23355
- let other;
23356
- try {
23357
- other = await readFile23(join41(catalogSkillDir, rel));
23358
- } catch (error) {
23359
- if (isEnoent3(error)) return false;
23360
- throw error;
23361
- }
23362
- if (!bytes.equals(other)) return false;
23363
- }
23364
- return true;
23365
- }
23366
- async function isCompatibleMethodCatalog(link, packagedMethodsRealpath) {
23367
- const stat2 = await lstat7(link);
23368
- if (!stat2.isSymbolicLink()) return false;
23369
- let resolved;
23370
- try {
23371
- resolved = await realpath8(link);
23372
- } catch (error) {
23373
- if (isEnoent3(error)) return false;
23374
- throw error;
23375
- }
23376
- if (resolved === packagedMethodsRealpath) return true;
23377
- const names = await packagedMethodSkillNames(packagedMethodsRealpath);
23378
- if (names.length === 0) return false;
23379
- for (const name of names) {
23380
- const required = await packagedSkillFileBytes(join41(packagedMethodsRealpath, name));
23381
- if (required === void 0) return false;
23382
- if (!await catalogPublishesPackagedSkill(join41(resolved, name), required)) return false;
23383
- }
23384
- return true;
23385
- }
23386
- async function installWorkspaceMethodSkills(cwd, packageRoot) {
23387
- const target = await realpath8(packagedMethodsDir(packageRoot));
23388
- const link = join41(cwd, ".agents", "skills");
23389
- let present;
23390
- try {
23391
- await lstat7(link);
23392
- present = true;
23393
- } catch (error) {
23394
- if (!isEnoent3(error)) throw error;
23395
- present = false;
23396
- }
23397
- if (present) {
23398
- if (await isCompatibleMethodCatalog(link, target)) return;
23399
- const stat2 = await lstat7(link);
23400
- const detail = stat2.isSymbolicLink() ? `symlink to ${await readlink(link)}` : "non-symlink entry";
23401
- throw new Error(`workspace method catalog conflict at ${link}: ${detail}`);
23402
- }
23403
- await mkdir4(dirname21(link), { recursive: true });
23404
- try {
23405
- await symlink(target, link);
23406
- } catch (error) {
23407
- if (error.code !== "EEXIST") throw error;
23408
- if (!await isCompatibleMethodCatalog(link, target)) {
23409
- throw new Error(`workspace method catalog conflict at ${link}`);
23410
- }
23411
- }
23412
- }
23413
-
23414
23115
  // src/role-envelope.ts
23415
23116
  init_packaged_role_registry();
23416
23117
 
@@ -23422,7 +23123,7 @@ init_submission_ledger();
23422
23123
  init_collector_ledger();
23423
23124
  import { randomUUID as randomUUID8 } from "node:crypto";
23424
23125
  import { readFileSync as readFileSync6, writeSync as writeSync3 } from "node:fs";
23425
- import { join as join44 } from "node:path";
23126
+ import { join as join43 } from "node:path";
23426
23127
  import { Value as Value5 } from "typebox/value";
23427
23128
 
23428
23129
  // src/activation-trace.ts
@@ -23470,7 +23171,7 @@ init_activation_ledger_topology();
23470
23171
  import {
23471
23172
  lstatSync as lstatSync2,
23472
23173
  realpathSync as realpathSync3,
23473
- statSync as statSync5,
23174
+ statSync as statSync6,
23474
23175
  writeFileSync as writeFileSync3
23475
23176
  } from "node:fs";
23476
23177
  import { isAbsolute as isAbsolute11, resolve as resolve16 } from "node:path";
@@ -23545,7 +23246,7 @@ function durableSessionPointer(sessionManager) {
23545
23246
  }
23546
23247
  let info;
23547
23248
  try {
23548
- info = statSync5(realFile);
23249
+ info = statSync6(realFile);
23549
23250
  } catch (error) {
23550
23251
  throw new Error(
23551
23252
  `Workflow role activation failed to stat durable session file (${realFile}): ${errorText(error)}`,
@@ -23854,8 +23555,8 @@ init_collector_github();
23854
23555
  // src/collector-handbook.ts
23855
23556
  init_atomic_write();
23856
23557
  init_activation_ledger_topology();
23857
- import { readFile as readFile24 } from "node:fs/promises";
23858
- import { join as join42, sep as sep6 } from "node:path";
23558
+ import { readFile as readFile22 } from "node:fs/promises";
23559
+ import { join as join41, sep as sep6 } from "node:path";
23859
23560
 
23860
23561
  // src/collector-tool-schemas.ts
23861
23562
  init_open_tool_schema();
@@ -23970,7 +23671,7 @@ function resolveCollectorHandbookRoot(sessionPath) {
23970
23671
  throw new Error(`\u901A\u8FDB\u53F8\u624B\u518C\u62D2\u7EDD\u4E0D\u5B89\u5168 bookKey ${JSON.stringify(bookKey)}`);
23971
23672
  }
23972
23673
  const ledgerHome = resolveActivationLedgerHomeForPath(sessionPath);
23973
- const root = join42(activationBookDirectory(ledgerHome, bookKey), "collector-handbook");
23674
+ const root = join41(activationBookDirectory(ledgerHome, bookKey), "collector-handbook");
23974
23675
  return { ledgerHome, bookKey, root };
23975
23676
  }
23976
23677
  function collectorHandbookRepoFileName(repositoryCanonical) {
@@ -23982,9 +23683,9 @@ function collectorHandbookRepoFileName(repositoryCanonical) {
23982
23683
  return `${repositoryCanonical.replaceAll("/", "__")}.md`;
23983
23684
  }
23984
23685
  function createCollectorHandbookStore(input) {
23985
- const generalPath = join42(input.handbookRoot, "general.md");
23986
- const repoDir = join42(input.handbookRoot, "repos");
23987
- const repoPath = join42(repoDir, collectorHandbookRepoFileName(input.repositoryCanonical));
23686
+ const generalPath = join41(input.handbookRoot, "general.md");
23687
+ const repoDir = join41(input.handbookRoot, "repos");
23688
+ const repoPath = join41(repoDir, collectorHandbookRepoFileName(input.repositoryCanonical));
23988
23689
  const assertHandbookBudget = (body, label) => {
23989
23690
  const byteLength = Buffer.byteLength(body, "utf8");
23990
23691
  if (byteLength > COLLECTOR_HANDBOOK_MAX_BYTES) {
@@ -23998,7 +23699,7 @@ function createCollectorHandbookStore(input) {
23998
23699
  ensureRealDirectoryTree(input.ledgerHome, parentDir2);
23999
23700
  assertLedgerFileInsideHome(path, input.ledgerHome);
24000
23701
  try {
24001
- const body = await readFile24(path, "utf8");
23702
+ const body = await readFile22(path, "utf8");
24002
23703
  assertHandbookBudget(body, "\u6B63\u6587");
24003
23704
  return body;
24004
23705
  } catch (error) {
@@ -25016,7 +24717,7 @@ var AUDITOR_TOOL_SPEC = {
25016
24717
  };
25017
24718
 
25018
24719
  // src/navigator-attendance.ts
25019
- import { createHash as createHash10 } from "node:crypto";
24720
+ import { createHash as createHash9 } from "node:crypto";
25020
24721
  init_navigator_invocation_identity();
25021
24722
  init_packaged_role_registry();
25022
24723
  init_activation_ledger_topology();
@@ -25026,7 +24727,7 @@ import { Type as Type20 } from "typebox";
25026
24727
 
25027
24728
  // src/navigator-public-session.ts
25028
24729
  init_sitian_facade();
25029
- import { basename as basename11 } from "node:path";
24730
+ import { basename as basename9 } from "node:path";
25030
24731
 
25031
24732
  // src/navigator-session-contracts.ts
25032
24733
  import { Type as Type19 } from "typebox";
@@ -25235,7 +24936,7 @@ function exactRecord2(value) {
25235
24936
  return typeof value === "object" && value !== null && !Array.isArray(value);
25236
24937
  }
25237
24938
  function runIdFromNavigatorDirectory(runDirectory) {
25238
- const entry = basename11(runDirectory);
24939
+ const entry = basename9(runDirectory);
25239
24940
  const suffix = "@navigator";
25240
24941
  if (!entry.endsWith(suffix)) return void 0;
25241
24942
  const runId = entry.slice(0, entry.length - suffix.length);
@@ -25464,7 +25165,7 @@ function navigatorSubjectKey(subjectRoot, subject, provenance = "role_input") {
25464
25165
  if (provenance === "placeholder") return subjectRoot;
25465
25166
  const normalized = subject.trim().replace(/\s+/g, " ");
25466
25167
  if (normalized === "") return subjectRoot;
25467
- return `${subjectRoot}#${createHash10("sha256").update(normalized).digest("hex").slice(0, 32)}`;
25168
+ return `${subjectRoot}#${createHash9("sha256").update(normalized).digest("hex").slice(0, 32)}`;
25468
25169
  }
25469
25170
  function navigatorSubjectKeyForInput(subjectRoot, reference, cwd = process.cwd()) {
25470
25171
  if (issueRoot(subjectRoot) !== void 0 || !subjectRoot.includes("/.ak/work/")) return subjectRoot;
@@ -26123,7 +25824,6 @@ var reviewerOutputSchema = withTerminatingOutputDeclarations(
26123
25824
  );
26124
25825
  function createReviewerRoleRuntime(pi, dependencies, _hostActions) {
26125
25826
  let soul;
26126
- let binding;
26127
25827
  let registered = false;
26128
25828
  let fixedBaseRevision;
26129
25829
  return {
@@ -26131,9 +25831,6 @@ function createReviewerRoleRuntime(pi, dependencies, _hostActions) {
26131
25831
  soul = (await dependencies.loadSoul()).trim();
26132
25832
  if (!soul) throw new Error("Reviewer soul is empty");
26133
25833
  fixedBaseRevision = admitted.baseRevision;
26134
- const loaded = await dependencies.loadCanonicalSkillBinding("ak-cross-m-review");
26135
- if (loaded.name !== "ak-cross-m-review") throw new Error("Canonical Skill binding loader returned tdd for ak-cross-m-review");
26136
- binding = loaded;
26137
25834
  if (!registered) {
26138
25835
  registered = true;
26139
25836
  pi.registerTool({
@@ -26143,7 +25840,7 @@ function createReviewerRoleRuntime(pi, dependencies, _hostActions) {
26143
25840
  promptSnippet: "\u63D0\u4EA4\u5FA1\u53F2\u53F0\u7EC8\u5C40\u56DE\u6267",
26144
25841
  parameters: reviewerOutputSchema,
26145
25842
  async execute(_id, parameters) {
26146
- if (!soul || !binding) throw new Error("\u5FA1\u53F2\u53F0\u8F93\u5165\u672A\u88C5\u8F7D");
25843
+ if (!soul) throw new Error("\u5FA1\u53F2\u53F0\u8F93\u5165\u672A\u88C5\u8F7D");
26147
25844
  return {
26148
25845
  content: [],
26149
25846
  details: parameters,
@@ -26154,11 +25851,9 @@ function createReviewerRoleRuntime(pi, dependencies, _hostActions) {
26154
25851
  }
26155
25852
  const activatedSoul = soul;
26156
25853
  const activatedBase = fixedBaseRevision;
26157
- const activatedBinding = binding;
26158
25854
  return Object.freeze({
26159
25855
  fixedBaseRevision: activatedBase,
26160
- soul: activatedSoul,
26161
- skillBinding: activatedBinding
25856
+ soul: activatedSoul
26162
25857
  });
26163
25858
  }
26164
25859
  };
@@ -26167,7 +25862,6 @@ function createReviewerRoleRuntime(pi, dependencies, _hostActions) {
26167
25862
  // src/worker-role.ts
26168
25863
  init_open_tool_schema();
26169
25864
  init_terminating_infrastructure();
26170
- init_submission_correctable_error();
26171
25865
  init_readable_gate_item();
26172
25866
  init_audit_escalation();
26173
25867
  init_submission_errors();
@@ -26279,7 +25973,7 @@ function uninstallPackageWorkerHooks(cwd) {
26279
25973
  rmOwnedDir(resolve18(gitDir, HOOKS_DIR));
26280
25974
  }
26281
25975
  }
26282
- function isRecord18(value) {
25976
+ function isRecord17(value) {
26283
25977
  return typeof value === "object" && value !== null && !Array.isArray(value);
26284
25978
  }
26285
25979
  function unfinishedReasonPresent(details) {
@@ -26295,7 +25989,7 @@ function readGateState(session) {
26295
25989
  if (entry.type !== "custom") continue;
26296
25990
  if (entry.customType === WORKER_COMMIT_BASELINE_ENTRY_TYPE) {
26297
25991
  const data = entry.data;
26298
- if (isRecord18(data) && (data.head === null || typeof data.head === "string")) {
25992
+ if (isRecord17(data) && (data.head === null || typeof data.head === "string")) {
26299
25993
  baseline = data.head;
26300
25994
  }
26301
25995
  } else if (entry.customType === WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE) {
@@ -26488,7 +26182,7 @@ var FIXER_PHASES = ["plan", "apply"];
26488
26182
  function isWorkerPhase(value) {
26489
26183
  return typeof value === "string" && FIXER_PHASES.includes(value);
26490
26184
  }
26491
- function isRecord19(value) {
26185
+ function isRecord18(value) {
26492
26186
  return typeof value === "object" && value !== null && !Array.isArray(value);
26493
26187
  }
26494
26188
  var WORKER_ROUTING_STATUSES = /* @__PURE__ */ new Set([
@@ -26500,7 +26194,7 @@ var WORKER_ROUTING_STATUSES = /* @__PURE__ */ new Set([
26500
26194
  ]);
26501
26195
  var WORKER_STATUS_REASK = "status \u4E0D\u662F planned\u3001completed\u3001refused\u3001partially_completed\u3001unfinished \u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
26502
26196
  function workerStatusOf(output) {
26503
- return isRecord19(output) && typeof output.status === "string" ? output.status : void 0;
26197
+ return isRecord18(output) && typeof output.status === "string" ? output.status : void 0;
26504
26198
  }
26505
26199
  function requireReadableWorkerStatus(output) {
26506
26200
  const status = workerStatusOf(output);
@@ -26677,10 +26371,6 @@ function createCoderRoleRuntime(pi, dependencies, hostActions) {
26677
26371
  let soul;
26678
26372
  let task;
26679
26373
  let phase;
26680
- let binding;
26681
- let tddInvocationInjected = false;
26682
- let originalRequest;
26683
- let expansionPending = false;
26684
26374
  let lifecycleRegistered = false;
26685
26375
  const submissionGate = createWorkerSubmissionGate();
26686
26376
  pi.registerFlag("ak-coder-task", {
@@ -26693,9 +26383,6 @@ function createCoderRoleRuntime(pi, dependencies, hostActions) {
26693
26383
  });
26694
26384
  return {
26695
26385
  async activate(ctx) {
26696
- tddInvocationInjected = false;
26697
- originalRequest = void 0;
26698
- expansionPending = false;
26699
26386
  soul = (await dependencies.loadSoul()).trim();
26700
26387
  if (soul.length === 0) throw new Error("Coder soul is empty");
26701
26388
  const selectedPhase = pi.getFlag("ak-coder-phase");
@@ -26711,24 +26398,6 @@ function createCoderRoleRuntime(pi, dependencies, hostActions) {
26711
26398
  }
26712
26399
  task = (await dependencies.loadTask(taskPath)).trim();
26713
26400
  if (task.length === 0) throw new Error("Coder task is empty");
26714
- binding = void 0;
26715
- if (phase === "apply") {
26716
- if (dependencies.loadCanonicalSkillBinding === void 0) {
26717
- throw new Error("Coder canonical Skill binding loader is not configured");
26718
- }
26719
- try {
26720
- const loaded = await dependencies.loadCanonicalSkillBinding("tdd");
26721
- if (loaded.name !== "tdd") {
26722
- throw new Error(
26723
- "Canonical Skill binding loader returned ak-cross-m-review for tdd"
26724
- );
26725
- }
26726
- binding = loaded;
26727
- } catch (error) {
26728
- if (ctx === void 0) throw error;
26729
- hostActions.failInfrastructure(error, ctx);
26730
- }
26731
- }
26732
26401
  if (!lifecycleRegistered) {
26733
26402
  lifecycleRegistered = true;
26734
26403
  pi.registerTool({
@@ -26783,28 +26452,8 @@ function createCoderRoleRuntime(pi, dependencies, hostActions) {
26783
26452
  };
26784
26453
  }
26785
26454
  });
26786
- pi.on("input", (event) => {
26787
- if (phase !== "apply" || tddInvocationInjected) {
26788
- return { action: "continue" };
26789
- }
26790
- tddInvocationInjected = true;
26791
- expansionPending = true;
26792
- originalRequest = binding === void 0 ? event.text : pi.capabilities?.skillOriginalRequest?.(binding.name, event.text) ?? event.text;
26793
- return { action: "continue" };
26794
- });
26795
26455
  pi.on("before_agent_start", (event, ctx2) => {
26796
26456
  if (soul === void 0) throw new Error("\u5C06\u4F5C\u76D1\u804C\u5206\u672A\u88C5\u8F7D");
26797
- if (phase === "apply") {
26798
- if (binding === void 0) {
26799
- hostActions.failInfrastructure(
26800
- new Error("Coder canonical tdd Skill binding was not initialized"),
26801
- ctx2
26802
- );
26803
- }
26804
- if (expansionPending) {
26805
- expansionPending = false;
26806
- }
26807
- }
26808
26457
  return {
26809
26458
  systemPrompt: `${event.systemPrompt}
26810
26459
 
@@ -27311,7 +26960,7 @@ function readDiaristTicketAssertion(submitted) {
27311
26960
  function readRoleRunCoordinates(ctx, label) {
27312
26961
  const runDirectory = runDirectoryFromHostContext(ctx);
27313
26962
  if (runDirectory === void 0) throw new Error(`${label} requires AK_ROLE_RUN_DIR`);
27314
- const admittedPath = join44(runDirectory, "admitted-request.json");
26963
+ const admittedPath = join43(runDirectory, "admitted-request.json");
27315
26964
  const admitted = JSON.parse(readFileSync6(admittedPath, "utf8"));
27316
26965
  if (typeof admitted.projectRoot !== "string" || admitted.projectRoot.trim() === "") {
27317
26966
  throw new Error(`${label} admitted-request missing projectRoot (${admittedPath})`);
@@ -27597,8 +27246,6 @@ function createRoleRuntimeExtension(dependencies) {
27597
27246
  let selectedRole;
27598
27247
  let roleReferenceMaterials = "";
27599
27248
  let activeReviewerParent;
27600
- let reviewerOriginalRequest;
27601
- let reviewerExpansionCaptured = false;
27602
27249
  let navigatorAttendance;
27603
27250
  let pendingNavigatorPresentation;
27604
27251
  let pendingNavigatorSettlement;
@@ -27689,16 +27336,9 @@ function createRoleRuntimeExtension(dependencies) {
27689
27336
  () => receiptDelivery.recordAccepted(),
27690
27337
  settleNavigatorProjection
27691
27338
  );
27692
- roleHost.on("input", (event) => {
27693
- const text = event.text;
27339
+ roleHost.on("input", (_event) => {
27694
27340
  const role = roleHost.getFlag(ROLE_FLAG.name);
27695
27341
  if (role !== void 0 && !admitted) return { action: "handled" };
27696
- if (admitted && activeReviewerParent !== void 0 && selectedRole === role && reviewerOriginalRequest === void 0) {
27697
- reviewerOriginalRequest = roleHost.capabilities?.skillOriginalRequest?.(
27698
- activeReviewerParent.skillBinding.name,
27699
- text
27700
- ) ?? text;
27701
- }
27702
27342
  return { action: "continue" };
27703
27343
  });
27704
27344
  roleHost.on("before_agent_start", () => roleReferenceMaterials === "" ? void 0 : { readingMaterial: { kind: "role-reference-materials", content: roleReferenceMaterials } });
@@ -27735,15 +27375,6 @@ function createRoleRuntimeExtension(dependencies) {
27735
27375
  }
27736
27376
  navigatorAttendance?.prepare();
27737
27377
  if (activeReviewerParent !== void 0 && selectedRole === role) {
27738
- if (!reviewerExpansionCaptured) {
27739
- if (reviewerOriginalRequest !== void 0) {
27740
- activeReviewerParent.skillBinding.captureExpansion(
27741
- roleHost.capabilities?.skillExpansion(prompt),
27742
- reviewerOriginalRequest
27743
- );
27744
- }
27745
- reviewerExpansionCaptured = true;
27746
- }
27747
27378
  return {
27748
27379
  systemPrompt: assembleReviewerParentSystemPrompt({
27749
27380
  baseSystemPrompt: event.systemPrompt,
@@ -28016,9 +27647,6 @@ function createRoleRuntimeExtension(dependencies) {
28016
27647
  throw new Error("Coder task loader is not configured");
28017
27648
  }
28018
27649
  return dependencies.loadCoderTask(path);
28019
- },
28020
- ...dependencies.loadCanonicalSkillBinding === void 0 ? {} : {
28021
- loadCanonicalSkillBinding: (name) => dependencies.loadCanonicalSkillBinding(name)
28022
27650
  }
28023
27651
  },
28024
27652
  hostActions
@@ -28026,13 +27654,7 @@ function createRoleRuntimeExtension(dependencies) {
28026
27654
  const reviewer = createReviewerRoleRuntime(
28027
27655
  roleHost,
28028
27656
  {
28029
- loadSoul: () => requireRoleSoul("reviewer"),
28030
- async loadCanonicalSkillBinding(name) {
28031
- if (dependencies.loadCanonicalSkillBinding === void 0) {
28032
- throw new Error("Reviewer runtime dependencies are not configured");
28033
- }
28034
- return dependencies.loadCanonicalSkillBinding(name);
28035
- }
27657
+ loadSoul: () => requireRoleSoul("reviewer")
28036
27658
  },
28037
27659
  hostActions
28038
27660
  );
@@ -28267,8 +27889,6 @@ function createRoleRuntimeExtension(dependencies) {
28267
27889
  activeReviewerParent = void 0;
28268
27890
  activeCollector = void 0;
28269
27891
  collectorFirstDispatchDone = false;
28270
- reviewerOriginalRequest = void 0;
28271
- reviewerExpansionCaptured = false;
28272
27892
  receiptDelivery = createReceiptDeliveryPolicy();
28273
27893
  noReceiptRecorded = false;
28274
27894
  observationFace.reset();
@@ -28415,11 +28035,11 @@ init_submission_correctable_error();
28415
28035
  init_navigator_invocation_identity();
28416
28036
  init_serialize_thrown_value();
28417
28037
  async function listen(server, path) {
28418
- await new Promise((resolve22, reject) => {
28038
+ await new Promise((resolve21, reject) => {
28419
28039
  server.once("error", reject);
28420
28040
  server.listen(path, () => {
28421
28041
  server.off("error", reject);
28422
- resolve22();
28042
+ resolve21();
28423
28043
  });
28424
28044
  });
28425
28045
  }
@@ -28454,8 +28074,8 @@ async function prepareRoleEnvelope(options) {
28454
28074
  const hostAbort = new AbortController();
28455
28075
  const runId = request.runDirectory.split("/").filter(Boolean).at(-1) ?? randomUUID9();
28456
28076
  await mkdir5(request.runDirectory, { recursive: true });
28457
- let sessionFile = options.sessionFile ?? join45(request.runDirectory, "session", "session.jsonl");
28458
- await mkdir5(dirname23(sessionFile), { recursive: true });
28077
+ let sessionFile = options.sessionFile ?? join44(request.runDirectory, "session", "session.jsonl");
28078
+ await mkdir5(dirname22(sessionFile), { recursive: true });
28459
28079
  if (request.continuation.kind !== "resume") {
28460
28080
  try {
28461
28081
  await writeFile11(
@@ -28505,7 +28125,7 @@ async function prepareRoleEnvelope(options) {
28505
28125
  getLeafEntry: () => sessionEntries.at(-1),
28506
28126
  getLeafId: () => runId,
28507
28127
  getEntries: () => sessionEntries,
28508
- getSessionDir: () => dirname23(sessionFile),
28128
+ getSessionDir: () => dirname22(sessionFile),
28509
28129
  getSessionFile: () => sessionFile,
28510
28130
  getHeader: () => ({ type: "session", id: runId }),
28511
28131
  setSessionFile(path) {
@@ -28541,12 +28161,6 @@ async function prepareRoleEnvelope(options) {
28541
28161
  const host = {
28542
28162
  deliverSubmissionRejection(_value) {
28543
28163
  },
28544
- capabilities: {
28545
- // #922: native loaders own expansion; package does not pre-read bodies (ADR 0032).
28546
- skillExpansion() {
28547
- return void 0;
28548
- }
28549
- },
28550
28164
  registerFlag(name, definition) {
28551
28165
  if (!flags.has(name) && definition.default !== void 0) flags.set(name, definition.default);
28552
28166
  },
@@ -28869,8 +28483,8 @@ async function prepareRoleEnvelope(options) {
28869
28483
  try {
28870
28484
  const closeAll = server.closeAllConnections;
28871
28485
  if (typeof closeAll === "function") closeAll.call(server);
28872
- await new Promise((resolve22, reject) => {
28873
- server.close((error) => error ? reject(error) : resolve22());
28486
+ await new Promise((resolve21, reject) => {
28487
+ server.close((error) => error ? reject(error) : resolve21());
28874
28488
  });
28875
28489
  } catch (error) {
28876
28490
  cleanupFailures.push(error);
@@ -28965,13 +28579,6 @@ async function prepareRoleEnvelope(options) {
28965
28579
  throw new Error(`terminating tool not registered after activation: ${terminatingToolName}`);
28966
28580
  }
28967
28581
  const jsonSchema = terminatingToolJsonSchema(terminating.parameters);
28968
- if (request.host === "codex" && hostMethodSkills(request.methods).length > 0) {
28969
- const packageRoot = options.dependencies.packageRoot;
28970
- if (typeof packageRoot !== "string" || packageRoot === "") {
28971
- throw new Error("codex project Skill catalog requires packageRoot");
28972
- }
28973
- await installWorkspaceMethodSkills(request.cwd, packageRoot);
28974
- }
28975
28582
  return {
28976
28583
  mcpServers: [{
28977
28584
  name: `ak-${request.activation.role}`,
@@ -29007,14 +28614,14 @@ async function prepareRoleEnvelope(options) {
29007
28614
 
29008
28615
  // src/role-runtime-dependencies.ts
29009
28616
  init_collector_github();
29010
- import { readFile as readFile26 } from "node:fs/promises";
29011
- import { join as join46 } from "node:path";
28617
+ import { readFile as readFile24 } from "node:fs/promises";
28618
+ import { join as join45 } from "node:path";
29012
28619
  init_doctor_evidence();
29013
28620
 
29014
28621
  // src/navigator-work-context.ts
29015
28622
  init_doctor_evidence();
29016
28623
  init_host_contracts();
29017
- import { readFile as readFile25 } from "node:fs/promises";
28624
+ import { readFile as readFile23 } from "node:fs/promises";
29018
28625
  import { resolve as resolve19 } from "node:path";
29019
28626
  init_notary_source_run();
29020
28627
  init_packaged_role_registry();
@@ -29028,7 +28635,7 @@ function navigatorInputReference(getFlag, role) {
29028
28635
  async function loadNavigatorWorkContext(options) {
29029
28636
  const reference = navigatorInputReference(options.getFlag, options.role);
29030
28637
  const subjectMode = packagedNavigatorSubject(options.role);
29031
- const input = reference === void 0 || subjectMode === "case" || subjectMode === "source-run" ? void 0 : await readFile25(reference, "utf8");
28638
+ const input = reference === void 0 || subjectMode === "case" || subjectMode === "source-run" ? void 0 : await readFile23(reference, "utf8");
29032
28639
  const subjectRoot = subjectPath(reference ?? options.context.sessionManager.getSessionDir(), options.context.cwd);
29033
28640
  let subjectKey = reference === void 0 ? subjectRoot : navigatorSubjectKeyForInput(subjectRoot, reference, options.context.cwd);
29034
28641
  let subject = input ?? `work subject: ${subjectKey}`;
@@ -29085,7 +28692,7 @@ async function loadNavigatorWorkContext(options) {
29085
28692
  let authorityMaterial;
29086
28693
  for (const path of authorityFiles) {
29087
28694
  try {
29088
- const content = await readFile25(path, "utf8");
28695
+ const content = await readFile23(path, "utf8");
29089
28696
  if (content.trim() !== "") {
29090
28697
  authorityMaterial = content;
29091
28698
  break;
@@ -29108,54 +28715,6 @@ async function loadNavigatorWorkContext(options) {
29108
28715
 
29109
28716
  // src/role-runtime-dependencies.ts
29110
28717
  init_notary_source_run();
29111
-
29112
- // src/package-resources/method-skill-binding.ts
29113
- import { dirname as dirname25 } from "node:path";
29114
-
29115
- // src/canonical-skill-binding.ts
29116
- import { dirname as dirname24, resolve as resolve20 } from "node:path";
29117
- import { stripFrontmatter } from "@earendil-works/pi-coding-agent";
29118
- function captureCanonicalSkillExpansion(name, snapshot, configuredPath, evidence, originalRequest) {
29119
- const matchedPath = evidence?.location === configuredPath ? configuredPath : evidence?.location === snapshot.path ? snapshot.path : void 0;
29120
- const expectedContent = matchedPath === void 0 ? void 0 : snapshot.body;
29121
- const prefixedContent = matchedPath === void 0 ? void 0 : `References are relative to ${dirname24(matchedPath)}.
29122
-
29123
- ${snapshot.body}`;
29124
- if (evidence?.name !== name || matchedPath === void 0 || evidence.content !== expectedContent && evidence.content !== prefixedContent || evidence.userMessage !== originalRequest) {
29125
- return void 0;
29126
- }
29127
- return Object.freeze({ ...evidence, name });
29128
- }
29129
-
29130
- // src/package-resources/method-skill-binding.ts
29131
- init_method_skill();
29132
- async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
29133
- const material = await loadPackagedMethodSkillMaterial(packageRoot, name);
29134
- const configuredPath = resolvePackagedMethodSkillPath(packageRoot, name);
29135
- const snapshot = Object.freeze({
29136
- raw: material.raw,
29137
- path: material.skillPath,
29138
- baseDir: dirname25(material.skillPath),
29139
- body: material.body,
29140
- snapshotIdentity: Object.freeze({ text: material.raw })
29141
- });
29142
- const binding = {
29143
- name,
29144
- snapshot,
29145
- captureExpansion(evidence, originalRequest) {
29146
- return captureCanonicalSkillExpansion(
29147
- name,
29148
- snapshot,
29149
- configuredPath,
29150
- evidence,
29151
- originalRequest
29152
- );
29153
- }
29154
- };
29155
- return Object.freeze(binding);
29156
- }
29157
-
29158
- // src/role-runtime-dependencies.ts
29159
28718
  init_auditor_soul();
29160
28719
  init_packaged_role_registry();
29161
28720
  init_session_opening_materials();
@@ -29170,33 +28729,21 @@ function loadRegisteredRoleSoul(role) {
29170
28729
  return usesSubjectSoul(role) ? loadAuditorSoulFromSubjectInput() : loadMainRoleSessionMaterials(role);
29171
28730
  }
29172
28731
  function createRoleRuntimeDependencies(packageRoot) {
29173
- const navigatorRoutePlaybookPath = join46(packageRoot, "resources/navigator-route-playbook.md");
29174
- const collectorHandbookSeedPath = join46(packageRoot, "resources/collector-bot-handbook.md");
28732
+ const navigatorRoutePlaybookPath = join45(packageRoot, "resources/navigator-route-playbook.md");
28733
+ const collectorHandbookSeedPath = join45(packageRoot, "resources/collector-bot-handbook.md");
29175
28734
  const doctorAuditor = createPiDoctorAuditor();
29176
28735
  const navigatorSessionFactory = createNativeNavigatorSessionFactory();
29177
28736
  return {
29178
28737
  packageRoot,
29179
28738
  loadRoleReferenceMaterials: loadPackagedRoleReferenceMaterials,
29180
28739
  loadRoleSoul: loadRegisteredRoleSoul,
29181
- loadFixPacket: (path) => readFile26(path, "utf8"),
29182
- loadCoderTask: (path) => readFile26(path, "utf8"),
29183
- loadCollectorHandbookSeed: () => readFile26(collectorHandbookSeedPath, "utf8"),
28740
+ loadFixPacket: (path) => readFile24(path, "utf8"),
28741
+ loadCoderTask: (path) => readFile24(path, "utf8"),
28742
+ loadCollectorHandbookSeed: () => readFile24(collectorHandbookSeedPath, "utf8"),
29184
28743
  createCollectorTransport: () => createGhCollectorGitHubTransport(),
29185
28744
  loadDoctorCase,
29186
28745
  loadNotarySourceRun: loadNotarySourceRunLocator,
29187
- loadMergerInput: async (path) => JSON.parse(await readFile26(path, "utf8")),
29188
- async loadCanonicalSkillBinding(name) {
29189
- switch (name) {
29190
- case "tdd":
29191
- return loadPackagedCanonicalSkillBinding(packageRoot, name);
29192
- case "ak-cross-m-review":
29193
- return loadPackagedCanonicalSkillBinding(packageRoot, name);
29194
- default: {
29195
- const unexpected = name;
29196
- throw new Error(`Canonical skill is not packaged: ${String(unexpected)}`);
29197
- }
29198
- }
29199
- },
28746
+ loadMergerInput: async (path) => JSON.parse(await readFile24(path, "utf8")),
29200
28747
  // #590: doctor compliance still on disposeCompliance path; judge→auditor is gate queue (#756).
29201
28748
  auditDoctorCompliance: (options) => doctorAuditor(options),
29202
28749
  loadNavigatorWorkContext: (options) => loadNavigatorWorkContext({
@@ -29213,7 +28760,7 @@ function createRoleRuntimeDependencies(packageRoot) {
29213
28760
  authority: options.authority,
29214
28761
  invocationId: options.invocationId,
29215
28762
  loadSoul: () => loadRegisteredRoleSoul("navigator"),
29216
- loadRoutePlaybook: () => readFile26(navigatorRoutePlaybookPath, "utf8"),
28763
+ loadRoutePlaybook: () => readFile24(navigatorRoutePlaybookPath, "utf8"),
29217
28764
  loadRoleHelp: async (role) => formatNavigatorRoleHelp(role),
29218
28765
  createSession: navigatorSessionFactory,
29219
28766
  ...options.contextError === void 0 ? {} : { contextError: options.contextError },
@@ -29226,9 +28773,9 @@ function createRoleRuntimeDependencies(packageRoot) {
29226
28773
  init_session_identity();
29227
28774
 
29228
28775
  // src/acp-host/description.ts
29229
- import { join as join47 } from "node:path";
28776
+ import { join as join46 } from "node:path";
29230
28777
  function resolveAcpBinary(description, operatorHome) {
29231
- return join47(operatorHome, ...description.binaryFromHome);
28778
+ return join46(operatorHome, ...description.binaryFromHome);
29232
28779
  }
29233
28780
  function acpStdioArgs(description, model, seat) {
29234
28781
  const { prefix, suffix, modelFlag, thinkingFlag } = description.argv;
@@ -29277,7 +28824,7 @@ function hostAbortedError(message = "host aborted") {
29277
28824
  function raceAgainstHostAbort(work, abortSignal, message = "host aborted") {
29278
28825
  if (abortSignal?.aborted) return Promise.reject(hostAbortedError(message));
29279
28826
  if (abortSignal === void 0) return work;
29280
- return new Promise((resolve22, reject) => {
28827
+ return new Promise((resolve21, reject) => {
29281
28828
  let settled = false;
29282
28829
  const onAbort = () => {
29283
28830
  if (settled) return;
@@ -29292,7 +28839,7 @@ function raceAgainstHostAbort(work, abortSignal, message = "host aborted") {
29292
28839
  if (settled) return;
29293
28840
  settled = true;
29294
28841
  abortSignal.removeEventListener("abort", onAbort);
29295
- resolve22(value);
28842
+ resolve21(value);
29296
28843
  },
29297
28844
  (error) => {
29298
28845
  if (settled) return;
@@ -29544,8 +29091,8 @@ function connectAcpStdio(options) {
29544
29091
  request(method, params) {
29545
29092
  if (closed) return Promise.reject(terminalError ?? acpError("acp-connection-closed", "ACP connection is closed"));
29546
29093
  const id = ++nextId;
29547
- return new Promise((resolve22, reject) => {
29548
- pending.set(id, { resolve: resolve22, reject });
29094
+ return new Promise((resolve21, reject) => {
29095
+ pending.set(id, { resolve: resolve21, reject });
29549
29096
  child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}
29550
29097
  `, (error) => {
29551
29098
  if (error === null || error === void 0) return;
@@ -29572,7 +29119,7 @@ function connectAcpStdio(options) {
29572
29119
  settleClosed(acpError("acp-connection-closed", "ACP connection is closed"));
29573
29120
  child.stdin.end();
29574
29121
  child.kill("SIGTERM");
29575
- await new Promise((resolve22) => child.once("close", () => resolve22()));
29122
+ await new Promise((resolve21) => child.once("close", () => resolve21()));
29576
29123
  }
29577
29124
  });
29578
29125
  }
@@ -29792,18 +29339,18 @@ function createAcpRoleTurnHost(config) {
29792
29339
  }
29793
29340
 
29794
29341
  // src/acp-host/seat-profile-soul.ts
29795
- import { constants as constants2 } from "node:fs";
29796
- import { access as access5, copyFile, lstat as lstat8, mkdir as mkdir6, readlink as readlink2, symlink as symlink2, unlink as unlink6 } from "node:fs/promises";
29797
- import { dirname as dirname26, join as join48, relative as relative3, resolve as resolve21 } from "node:path";
29342
+ import { constants as constants3 } from "node:fs";
29343
+ import { access as access4, copyFile, lstat as lstat8, mkdir as mkdir6, readlink, symlink as symlink2, unlink as unlink6 } from "node:fs/promises";
29344
+ import { dirname as dirname23, join as join47, relative as relative3, resolve as resolve20 } from "node:path";
29798
29345
  function seatProfileName(spec, role) {
29799
29346
  return `${spec.namePrefix}${role}`;
29800
29347
  }
29801
29348
  function packageRoleSoulPath(packageRoot, role) {
29802
- return join48(packageRoot, "souls", `${role}.md`);
29349
+ return join47(packageRoot, "souls", `${role}.md`);
29803
29350
  }
29804
29351
  async function pathExists2(path) {
29805
29352
  try {
29806
- await access5(path, constants2.F_OK);
29353
+ await access4(path, constants3.F_OK);
29807
29354
  return true;
29808
29355
  } catch {
29809
29356
  return false;
@@ -29812,20 +29359,20 @@ async function pathExists2(path) {
29812
29359
  async function ensureSeatProfileSoul(options) {
29813
29360
  const { spec, operatorHome, packageRoot, role } = options;
29814
29361
  const profileName = seatProfileName(spec, role);
29815
- const soulTarget = resolve21(packageRoleSoulPath(packageRoot, role));
29362
+ const soulTarget = resolve20(packageRoleSoulPath(packageRoot, role));
29816
29363
  if (!await pathExists2(soulTarget)) {
29817
29364
  throw new Error(`packaged role soul missing: ${soulTarget}`);
29818
29365
  }
29819
- const profilesRoot = join48(operatorHome, ...spec.profilesRootFromHome);
29820
- const profileDir = join48(profilesRoot, profileName);
29821
- const hostRoot = dirname26(profilesRoot);
29822
- const soulPath = join48(profileDir, spec.soulFileName);
29366
+ const profilesRoot = join47(operatorHome, ...spec.profilesRootFromHome);
29367
+ const profileDir = join47(profilesRoot, profileName);
29368
+ const hostRoot = dirname23(profilesRoot);
29369
+ const soulPath = join47(profileDir, spec.soulFileName);
29823
29370
  if (!await pathExists2(profileDir)) {
29824
29371
  await mkdir6(profileDir, { recursive: true });
29825
29372
  for (const name of ["auth.json", ".env", "config.yaml"]) {
29826
- const source = join48(hostRoot, name);
29373
+ const source = join47(hostRoot, name);
29827
29374
  if (!await pathExists2(source)) continue;
29828
- await copyFile(source, join48(profileDir, name));
29375
+ await copyFile(source, join47(profileDir, name));
29829
29376
  }
29830
29377
  } else {
29831
29378
  await mkdir6(profileDir, { recursive: true });
@@ -29835,7 +29382,7 @@ async function ensureSeatProfileSoul(options) {
29835
29382
  try {
29836
29383
  const st = await lstat8(soulPath);
29837
29384
  if (st.isSymbolicLink()) {
29838
- current = await readlink2(soulPath);
29385
+ current = await readlink(soulPath);
29839
29386
  }
29840
29387
  } catch {
29841
29388
  current = void 0;