@akagilnc/pi-workflow-roles 0.1.3837 → 0.1.3884

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 (59) hide show
  1. package/README.md +2 -2
  2. package/README.zh-CN.md +3 -3
  3. package/dist/acp-host/production-host.js +22736 -22720
  4. package/dist/engine-detour-tool.js +2 -2
  5. package/dist/engine-detour.js +23 -7
  6. package/dist/headless-host/production-host.js +4926 -4926
  7. package/dist/host-descriptions.js +5 -2
  8. package/dist/merger-contracts.js +23 -42
  9. package/dist/merger-git-state.js +69 -42
  10. package/dist/merger-role.js +30 -41
  11. package/dist/pi/role-turn-host.js +20 -92
  12. package/dist/public-cli/invocation.js +12 -39
  13. package/dist/public-cli/load-production-acp-host.js +1 -1
  14. package/dist/public-cli/load-production-external-host.js +10 -0
  15. package/dist/public-cli/load-production-headless-host.js +1 -1
  16. package/dist/public-cli/main.js +314 -433
  17. package/dist/public-cli/option-definitions.js +5 -5
  18. package/dist/public-cli/run-lifecycle.js +0 -2
  19. package/dist/public-role-summons.js +7 -49
  20. package/dist/reviewer-agent.js +1 -0
  21. package/dist/reviewer-child-executor.js +3 -2
  22. package/dist/role-activation-flags.js +50 -0
  23. package/dist/role-runtime.js +9 -16
  24. package/extensions/role-runtime.ts +0 -3
  25. package/package.json +1 -1
  26. package/scripts/build-package.mjs +2 -2
  27. package/souls/merger.md +1 -1
  28. package/src/acp-host/production-host.ts +31 -94
  29. package/src/acp-host/role-turn-host.ts +178 -263
  30. package/src/diagnostic-tail.ts +18 -0
  31. package/src/engine-detour-tool.ts +5 -4
  32. package/src/engine-detour.ts +44 -9
  33. package/src/external-host-turn-loop.ts +172 -0
  34. package/src/headless-host/production-host.ts +10 -7
  35. package/src/headless-host/role-turn-host.ts +271 -263
  36. package/src/host-descriptions.ts +5 -2
  37. package/src/host-session-record.ts +41 -0
  38. package/src/merger-contracts.ts +24 -38
  39. package/src/merger-git-state.ts +67 -37
  40. package/src/merger-role.ts +52 -48
  41. package/src/pi/role-turn-host.ts +18 -93
  42. package/src/prepared-role-turn.ts +68 -0
  43. package/src/public-cli/cli.ts +11 -20
  44. package/src/public-cli/invocation.ts +13 -44
  45. package/src/public-cli/load-production-acp-host.ts +2 -1
  46. package/src/public-cli/load-production-external-host.ts +17 -0
  47. package/src/public-cli/load-production-headless-host.ts +2 -1
  48. package/src/public-cli/merger-run.ts +2 -113
  49. package/src/public-cli/option-definitions.ts +5 -5
  50. package/src/public-cli/run-lifecycle.ts +0 -2
  51. package/src/public-role-summons.ts +12 -69
  52. package/src/reviewer-agent.ts +12 -1
  53. package/src/reviewer-child-executor.ts +10 -2
  54. package/src/role-activation-flags.ts +53 -0
  55. package/src/{acp-host/role-envelope.ts → role-envelope.ts} +28 -84
  56. package/src/role-runtime-dependencies.ts +89 -0
  57. package/src/role-runtime.ts +16 -17
  58. package/src/{acp-host/session-identity.ts → session-identity.ts} +6 -6
  59. /package/src/{acp-host/mcp-relay.mjs → mcp-relay.mjs} +0 -0
@@ -14756,18 +14756,6 @@ var init_doctor_contracts = __esm({
14756
14756
  }
14757
14757
  });
14758
14758
 
14759
- // src/git-object-id.ts
14760
- function isFullGitObjectId(value) {
14761
- return typeof value === "string" && FULL_GIT_OBJECT_ID_RE.test(value);
14762
- }
14763
- var FULL_GIT_OBJECT_ID_RE;
14764
- var init_git_object_id = __esm({
14765
- "src/git-object-id.ts"() {
14766
- "use strict";
14767
- FULL_GIT_OBJECT_ID_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
14768
- }
14769
- });
14770
-
14771
14759
  // src/exact-utf8.ts
14772
14760
  function exactUtf8(bytes, label) {
14773
14761
  let text;
@@ -14786,34 +14774,10 @@ var init_exact_utf8 = __esm({
14786
14774
  }
14787
14775
  });
14788
14776
 
14789
- // src/sha256.ts
14790
- import { createHash } from "node:crypto";
14791
- function sha256Hex(bytes) {
14792
- return createHash("sha256").update(bytes).digest("hex");
14793
- }
14794
- var init_sha256 = __esm({
14795
- "src/sha256.ts"() {
14796
- "use strict";
14797
- }
14798
- });
14799
-
14800
14777
  // src/merger-contracts.ts
14801
14778
  function fail2(message = "Merger input violates its exact contract") {
14802
14779
  throw new MergerInputContractError(message);
14803
14780
  }
14804
- function canonicalPath(path) {
14805
- return typeof path === "string" && path.length > 0 && !path.startsWith("/") && !path.includes("\0") && path.split("/").every((part) => part !== "" && part !== "." && part !== "..");
14806
- }
14807
- function validatePathSet(value, label) {
14808
- if (!Array.isArray(value) || value.length === 0 || !value.every(canonicalPath)) fail2(`Merger ${label} must be a non-empty canonical path set`);
14809
- return value;
14810
- }
14811
- function validateMaterial(value, label) {
14812
- if (!record(value) || typeof value.bytesBase64 !== "string" || typeof value.sha256 !== "string") fail2(`Merger ${label} material is malformed`);
14813
- const bytes = Buffer.from(value.bytesBase64, "base64");
14814
- exactUtf8(bytes, `Merger ${label} material`);
14815
- if (sha256Hex(bytes) !== value.sha256) fail2(`Merger ${label} material digest mismatch`);
14816
- }
14817
14781
  function deepFreeze(value) {
14818
14782
  if (value && typeof value === "object") {
14819
14783
  for (const child of Object.values(value)) deepFreeze(child);
@@ -14821,56 +14785,48 @@ function deepFreeze(value) {
14821
14785
  }
14822
14786
  return value;
14823
14787
  }
14788
+ function readMaterial(value, label) {
14789
+ if (!record(value) || typeof value.bytesBase64 !== "string") fail2(`Merger ${label} material is malformed`);
14790
+ exactUtf8(Buffer.from(value.bytesBase64, "base64"), `Merger ${label} material`);
14791
+ return { bytesBase64: value.bytesBase64, sha256: typeof value.sha256 === "string" ? value.sha256 : "" };
14792
+ }
14824
14793
  function validateMergerInput(value) {
14825
- if (!record(value) || blank(value.attemptId) || !isFullGitObjectId(value.targetObjectId) || !isFullGitObjectId(value.sourceObjectId) || value.targetObjectId.length !== value.sourceObjectId.length) fail2("Merger input has invalid identity or object ID");
14826
- if (!record(value.materials)) fail2();
14827
- for (const key of ["task", "authority", "targetIntent", "sourceIntent"]) validateMaterial(value.materials[key], key);
14828
- const conflicts = validatePathSet(value.expectedConflictPaths, "expected conflict paths");
14829
- const scope = validatePathSet(value.resolutionScope, "resolution scope");
14830
- if (!conflicts.every((path) => scope.includes(path))) fail2("Merger resolution scope must contain the complete conflict set");
14831
- if (!Array.isArray(value.authorizedChecks)) fail2("Merger authorized checks are malformed");
14832
- for (const check of value.authorizedChecks) {
14833
- if (!record(check) || !Array.isArray(check.argv) || check.argv.length === 0 || check.argv.some(blank)) fail2("Merger authorized check is malformed");
14834
- }
14835
- return deepFreeze(structuredClone(value));
14836
- }
14837
- function validateMergerOutput(value, expectedAttemptId) {
14838
- if (!record(value) || expectedAttemptId !== void 0 && value.attemptId !== expectedAttemptId) throw new Error("\u5408\u5E76\u56DE\u6267 attempt \u4E0D\u5339\u914D");
14794
+ if (!record(value) || blank(value.attemptId)) fail2("Merger input requires a non-empty attemptId for accounting");
14795
+ if (!record(value.materials)) fail2("Merger materials are missing");
14796
+ const materials = { task: readMaterial(value.materials.task, "task"), authority: readMaterial(value.materials.authority, "authority"), targetIntent: readMaterial(value.materials.targetIntent, "targetIntent"), sourceIntent: readMaterial(value.materials.sourceIntent, "sourceIntent") };
14797
+ const authorizedChecks = Array.isArray(value.authorizedChecks) ? value.authorizedChecks.filter((check) => record(check)).map((c) => ({ name: asString(c.name), argv: asStringArray2(c.argv).filter((a) => a.trim().length > 0) })).filter((c) => c.name.trim().length > 0 && c.argv.length > 0) : [];
14798
+ return deepFreeze(structuredClone({ attemptId: value.attemptId.trim(), targetObjectId: asString(value.targetObjectId), sourceObjectId: asString(value.sourceObjectId), materials, expectedConflictPaths: asStringArray2(value.expectedConflictPaths), resolutionScope: asStringArray2(value.resolutionScope), authorizedChecks }));
14799
+ }
14800
+ function validateMergerOutput(value) {
14801
+ if (!record(value)) throw new Error("\u5408\u5E76\u56DE\u6267\u65E0\u5DF2\u8BC6\u522B\u7684\u6267\u884C\u5224\u522B");
14839
14802
  const status = typeof value.status === "string" ? value.status : void 0;
14840
- if (status === "completed" && isFullGitObjectId(value.mergeCommitId)) return structuredClone(value);
14841
- if (status === "escalate") return structuredClone(value);
14803
+ if (status === "completed" || status === "escalate") return structuredClone(value);
14842
14804
  throw new Error("\u5408\u5E76\u56DE\u6267\u65E0\u5DF2\u8BC6\u522B\u7684\u6267\u884C\u5224\u522B");
14843
14805
  }
14844
- var oidPattern, materialSchema, checkSchema, mergerInputSchema, mergerOutputVariants, mergerOutputSchema, MERGER_OUTPUT_TOOL_NAME, record, blank, MergerInputContractError;
14806
+ var materialSchema, checkSchema, mergerInputSchema, mergerOutputVariants, mergerOutputSchema, MERGER_OUTPUT_TOOL_NAME, record, blank, MergerInputContractError, asString, asStringArray2;
14845
14807
  var init_merger_contracts = __esm({
14846
14808
  "src/merger-contracts.ts"() {
14847
14809
  "use strict";
14848
14810
  init_build();
14849
- init_git_object_id();
14850
14811
  init_exact_utf8();
14851
- init_sha256();
14852
14812
  init_open_tool_schema();
14853
14813
  init_terminating_infrastructure();
14854
- oidPattern = "^(?:[0-9a-f]{40}|[0-9a-f]{64})$";
14855
14814
  materialSchema = typebox_exports.Object({ bytesBase64: typebox_exports.String(), sha256: typebox_exports.String() }, { additionalProperties: false });
14856
14815
  checkSchema = typebox_exports.Object({ name: typebox_exports.String({ minLength: 1 }), argv: typebox_exports.Array(typebox_exports.String({ minLength: 1 }), { minItems: 1 }) }, { additionalProperties: false });
14857
14816
  mergerInputSchema = typebox_exports.Object({
14858
- version: typebox_exports.Literal(1),
14859
- attemptId: typebox_exports.String({ minLength: 1 }),
14860
- targetObjectId: typebox_exports.String({ pattern: oidPattern }),
14861
- sourceObjectId: typebox_exports.String({ pattern: oidPattern }),
14817
+ attemptId: typebox_exports.String({ minLength: 1, description: "\u5BF9\u8D26 attempt \u8EAB\u4EFD\uFF08transport\uFF09" }),
14818
+ targetObjectId: typebox_exports.String({ description: "\u6750\u6599\uFF1Atarget parent OID\uFF1B\u53EF\u7A7A" }),
14819
+ sourceObjectId: typebox_exports.String({ description: "\u6750\u6599\uFF1Asource parent OID\uFF1B\u53EF\u7A7A" }),
14862
14820
  materials: typebox_exports.Object({ task: materialSchema, authority: materialSchema, targetIntent: materialSchema, sourceIntent: materialSchema }, { additionalProperties: false }),
14863
- expectedConflictPaths: typebox_exports.Array(typebox_exports.String({ minLength: 1 }), { minItems: 1 }),
14864
- resolutionScope: typebox_exports.Array(typebox_exports.String({ minLength: 1 }), { minItems: 1 }),
14821
+ expectedConflictPaths: typebox_exports.Array(typebox_exports.String(), { description: "\u6750\u6599\uFF1A\u5F53\u524D\u672A\u5408\u5E76\u8DEF\u5F84\uFF1B\u53EF\u7A7A" }),
14822
+ resolutionScope: typebox_exports.Array(typebox_exports.String(), { description: "\u6750\u6599\uFF1A\u89E3\u6790\u8303\u56F4\u63D0\u793A\uFF1B\u53EF\u7A7A" }),
14865
14823
  authorizedChecks: typebox_exports.Array(checkSchema)
14866
14824
  }, { additionalProperties: false });
14867
14825
  mergerOutputVariants = typebox_exports.Union([
14868
- typebox_exports.Object({ status: typebox_exports.Literal("completed", { description: "completed \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), attemptId: typebox_exports.String({ minLength: 1, description: "\u5DF2\u53D7\u7406\u5408\u5E76 attempt \u8EAB\u4EFD" }), report: typebox_exports.String({ minLength: 1, description: "\u5982\u5B9E\u7ED3\u679C\u62A5\u544A" }), mergeCommitId: typebox_exports.String({ pattern: oidPattern, description: "\u5DF2\u6838\u9A8C\u7684\u5B8C\u6210\u5408\u5E76 commit object ID" }) }, { additionalProperties: false }),
14869
- typebox_exports.Object({ status: typebox_exports.Literal("escalate", { description: "escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), attemptId: typebox_exports.String({ minLength: 1, description: "\u5DF2\u53D7\u7406\u5408\u5E76 attempt \u8EAB\u4EFD" }), diagnosis: typebox_exports.String({ minLength: 1, description: "\u5408\u5E76\u5B8C\u6210\u9700\u5347\u7EA7\u7684\u539F\u56E0" }), report: typebox_exports.String({ minLength: 1, description: "\u5982\u5B9E\u7ED3\u679C\u62A5\u544A" }) }, { additionalProperties: false })
14826
+ typebox_exports.Object({ status: typebox_exports.Literal("completed", { description: "completed \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), attemptId: typebox_exports.String({ minLength: 1, description: "\u5DF2\u53D7\u7406\u5408\u5E76 attempt \u8EAB\u4EFD" }), report: typebox_exports.String({ minLength: 1, description: "\u5982\u5B9E\u7ED3\u679C\u62A5\u544A" }), mergeCommitId: typebox_exports.String({ description: "\u5B8C\u6210\u5408\u5E76 commit object ID" }) }, { additionalProperties: false }),
14827
+ typebox_exports.Object({ status: typebox_exports.Literal("escalate", { description: "escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), attemptId: typebox_exports.String({ minLength: 1, description: "\u5DF2\u53D7\u7406\u5408\u5E76 attempt \u8EAB\u4EFD" }), diagnosis: typebox_exports.String({ minLength: 1, description: "\u5408\u5E76\u65E0\u6CD5\u6216\u4E0D\u5E94\u7531\u672C\u5E2D\u5B8C\u6210\u7684\u539F\u56E0\uFF08\u542B\u65E0\u8FDB\u884C\u4E2D\u5408\u5E76\u3001\u65E0\u6D3B\u53EF\u5E72\u3001\u9700\u65B0\u7684\u4EA7\u54C1/\u6743\u529B\u51B3\u5B9A\uFF09" }), report: typebox_exports.String({ minLength: 1, description: "\u5982\u5B9E\u7ED3\u679C\u62A5\u544A" }) }, { additionalProperties: false })
14870
14828
  ]);
14871
- mergerOutputSchema = withInfrastructureFailureDeclaration(
14872
- openToolObjectFromUnion(mergerOutputVariants)
14873
- );
14829
+ mergerOutputSchema = withInfrastructureFailureDeclaration(openToolObjectFromUnion(mergerOutputVariants));
14874
14830
  MERGER_OUTPUT_TOOL_NAME = "ak_merger_output";
14875
14831
  record = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
14876
14832
  blank = (v) => typeof v !== "string" || v.trim().length === 0;
@@ -14880,6 +14836,8 @@ var init_merger_contracts = __esm({
14880
14836
  this.name = "MergerInputContractError";
14881
14837
  }
14882
14838
  };
14839
+ asString = (v) => typeof v === "string" ? v : "";
14840
+ asStringArray2 = (v) => Array.isArray(v) ? v.filter((item) => typeof item === "string") : [];
14883
14841
  }
14884
14842
  });
14885
14843
 
@@ -15090,6 +15048,12 @@ var init_diarist_contracts = __esm({
15090
15048
  function packagedRoleMetadata(role) {
15091
15049
  return PACKAGED_ROLE_REGISTRY.find((entry) => entry.role === role);
15092
15050
  }
15051
+ function packagedRoleInputFlag(role) {
15052
+ return packagedRoleMetadata(role)?.inputFlag;
15053
+ }
15054
+ function packagedRolePhaseFlag(role) {
15055
+ return packagedRoleMetadata(role)?.phaseFlag;
15056
+ }
15093
15057
  var NOTARY_SESSION_MATERIALS, INSPECTOR_SESSION_MATERIALS, AUDITOR_PUBLIC_SESSION_MATERIALS, PUBLIC_ROLE_RECORDS, PACKAGED_ROLE_REGISTRY;
15094
15058
  var init_packaged_role_registry = __esm({
15095
15059
  "src/packaged-role-registry.ts"() {
@@ -15527,9 +15491,11 @@ var init_host_descriptions = __esm({
15527
15491
  binaryFromHome: Object.freeze([".local", "bin", "claude"]),
15528
15492
  sessionBindingFile: "claude-headless-session.json",
15529
15493
  fixedArgs: Object.freeze([
15530
- // One result envelope (not stream-json): typed receipt only; no event-stream copy.
15494
+ // Live NDJSON events → sitian host-session records (#811); last line is the result receipt.
15531
15495
  "--output-format",
15532
- "json",
15496
+ "stream-json",
15497
+ // Intermediate assistant/tool/system events require verbose with stream-json.
15498
+ "--verbose",
15533
15499
  "--permission-mode",
15534
15500
  "bypassPermissions",
15535
15501
  // Empty sources: no user/project/local operator surface (envelope owns materials).
@@ -16180,7 +16146,7 @@ async function loadProductionAcpHostFactory(packageRoot2, host) {
16180
16146
  const href = pathToFileURL(target).href;
16181
16147
  const mod = await import(href);
16182
16148
  const create = mod.createProductionAcpRoleTurnHost;
16183
- return (options) => create({ ...options, description });
16149
+ return (options) => create({ ...options, description, hostName: host });
16184
16150
  }
16185
16151
  var init_load_production_acp_host = __esm({
16186
16152
  "src/public-cli/load-production-acp-host.ts"() {
@@ -16204,7 +16170,7 @@ async function loadProductionHeadlessHostFactory(packageRoot2, host) {
16204
16170
  const href = pathToFileURL2(target).href;
16205
16171
  const mod = await import(href);
16206
16172
  const create = mod.createProductionHeadlessRoleTurnHost;
16207
- return (options) => create({ ...options, description });
16173
+ return (options) => create({ ...options, description, hostName: host });
16208
16174
  }
16209
16175
  var init_load_production_headless_host = __esm({
16210
16176
  "src/public-cli/load-production-headless-host.ts"() {
@@ -16224,6 +16190,17 @@ async function loadProductionExternalHostFactory(packageRoot2, host) {
16224
16190
  }
16225
16191
  throw new Error(`unregistered host: ${host}`);
16226
16192
  }
16193
+ function createLazyProductionExternalHost(options) {
16194
+ let hostPromise;
16195
+ return {
16196
+ executeTurn: async (request) => {
16197
+ hostPromise ??= loadProductionExternalHostFactory(options.packageRoot, options.hostName).then(
16198
+ (create) => create({ packageRoot: options.packageRoot, principalAuthority: options.principalAuthority })
16199
+ );
16200
+ return (await hostPromise).executeTurn(request);
16201
+ }
16202
+ };
16203
+ }
16227
16204
  var init_load_production_external_host = __esm({
16228
16205
  "src/public-cli/load-production-external-host.ts"() {
16229
16206
  "use strict";
@@ -16258,11 +16235,17 @@ var init_host_contracts = __esm({
16258
16235
  });
16259
16236
 
16260
16237
  // src/engine-detour.ts
16238
+ function normalizeEngineName(engine) {
16239
+ if (engine === void 0) return void 0;
16240
+ const trimmed = engine.trim();
16241
+ return trimmed === "" ? void 0 : trimmed;
16242
+ }
16261
16243
  function applyEngineChildEnv(childEnv, engine) {
16262
16244
  delete childEnv[AK_ROLE_ENGINE_ENV];
16263
- if (engine !== void 0 && engine.trim() !== "") {
16264
- childEnv[AK_ROLE_ENGINE_ENV] = engine.trim();
16265
- } else {
16245
+ const normalized = normalizeEngineName(engine);
16246
+ if (normalized !== void 0) {
16247
+ childEnv[AK_ROLE_ENGINE_ENV] = normalized;
16248
+ } else if (childEnv !== process.env) {
16266
16249
  childEnv[AK_ROLE_ENGINE_ENV] = void 0;
16267
16250
  }
16268
16251
  }
@@ -16275,6 +16258,50 @@ var init_engine_detour = __esm({
16275
16258
  }
16276
16259
  });
16277
16260
 
16261
+ // src/role-activation-flags.ts
16262
+ function projectActivationFlags(request) {
16263
+ const activation = request.activation;
16264
+ const flags = /* @__PURE__ */ new Map([["ak-role", activation.role]]);
16265
+ const inputFlag = packagedRoleInputFlag(activation.role);
16266
+ const phaseFlag = packagedRolePhaseFlag(activation.role);
16267
+ if ("phase" in activation && phaseFlag !== void 0) flags.set(phaseFlag, activation.phase);
16268
+ if (inputFlag !== void 0) {
16269
+ const path = "taskPath" in activation ? activation.taskPath : "packetPath" in activation ? activation.packetPath : "casePath" in activation ? activation.casePath : "inputPath" in activation ? activation.inputPath : "sourceRun" in activation ? activation.sourceRun : void 0;
16270
+ if (path !== void 0) flags.set(inputFlag, path);
16271
+ }
16272
+ if (activation.role === "fixer" && activation.prerequisitesPath !== void 0) {
16273
+ flags.set("ak-fixer-prerequisites", activation.prerequisitesPath);
16274
+ }
16275
+ if (activation.role === "reviewer") {
16276
+ flags.set("ak-review-base", activation.baseRevision);
16277
+ flags.set("ak-review-authority-refs", JSON.stringify(activation.authorityRefs));
16278
+ if (activation.ticketNumber !== void 0) {
16279
+ flags.set("ak-review-ticket-number", String(activation.ticketNumber));
16280
+ }
16281
+ }
16282
+ if (activation.role === "notary" && activation.ticketNumber !== void 0) {
16283
+ flags.set("ak-notary-ticket-number", String(activation.ticketNumber));
16284
+ }
16285
+ if (activation.role === "gleaner-left") {
16286
+ flags.set("ak-gleaner-left-base", activation.baseRevision);
16287
+ }
16288
+ if (activation.role === "collector") {
16289
+ flags.set("ak-collector-repo", activation.repo);
16290
+ if (activation.pr !== void 0) flags.set("ak-collector-pr", activation.pr);
16291
+ if (activation.requestManifestPath !== void 0) {
16292
+ flags.set("ak-collector-request-manifest", activation.requestManifestPath);
16293
+ }
16294
+ if (activation.waitMs !== void 0) flags.set("ak-collector-wait-ms", activation.waitMs);
16295
+ }
16296
+ return flags;
16297
+ }
16298
+ var init_role_activation_flags = __esm({
16299
+ "src/role-activation-flags.ts"() {
16300
+ "use strict";
16301
+ init_packaged_role_registry();
16302
+ }
16303
+ });
16304
+
16278
16305
  // src/sitian-contracts.ts
16279
16306
  function attachDirectErrnoCode(error, cause) {
16280
16307
  if (cause === null || typeof cause !== "object" || !("code" in cause)) return;
@@ -16297,7 +16324,7 @@ var init_sitian_contracts = __esm({
16297
16324
  });
16298
16325
 
16299
16326
  // src/sitian-appender.ts
16300
- import { createHash as createHash2, randomUUID } from "node:crypto";
16327
+ import { createHash, randomUUID } from "node:crypto";
16301
16328
  import {
16302
16329
  appendFileSync,
16303
16330
  existsSync as existsSync5,
@@ -16313,7 +16340,7 @@ function errorCodeOf(error) {
16313
16340
  return error.code;
16314
16341
  }
16315
16342
  function identityClaimPath(recordFile, identity) {
16316
- const digest = createHash2("sha256").update(identity, "utf8").digest("hex");
16343
+ const digest = createHash("sha256").update(identity, "utf8").digest("hex");
16317
16344
  return `${recordFile}.id-${digest}`;
16318
16345
  }
16319
16346
  function createExclusiveFile(path, contents) {
@@ -16457,7 +16484,7 @@ function resolveSitianRecordPathInLedger(input, ledgerHome) {
16457
16484
  } else {
16458
16485
  subjectStr = JSON.stringify(input.subject);
16459
16486
  }
16460
- const digest = createHash2("sha256").update(subjectStr).digest("hex").slice(0, 32);
16487
+ const digest = createHash("sha256").update(subjectStr).digest("hex").slice(0, 32);
16461
16488
  sessionDir = join9(bookDir, category, digest);
16462
16489
  } else {
16463
16490
  sessionDir = join9(bookDir, category);
@@ -16604,84 +16631,14 @@ function buildSeatModelCliArgs(model) {
16604
16631
  ...model.thinking === void 0 ? [] : ["--thinking", model.thinking]
16605
16632
  ];
16606
16633
  }
16607
- function buildActivationFlagArgs(activation) {
16608
- switch (activation.role) {
16609
- case "judge":
16610
- return ["--ak-role", "judge"];
16611
- case "coder":
16612
- return [
16613
- "--ak-role",
16614
- "coder",
16615
- "--ak-coder-phase",
16616
- activation.phase,
16617
- "--ak-coder-task",
16618
- activation.taskPath
16619
- ];
16620
- case "fixer":
16621
- return [
16622
- "--ak-role",
16623
- "fixer",
16624
- "--ak-fixer-phase",
16625
- activation.phase,
16626
- "--ak-fix-packet",
16627
- activation.packetPath,
16628
- ...activation.prerequisitesPath === void 0 ? [] : ["--ak-fixer-prerequisites", activation.prerequisitesPath]
16629
- ];
16630
- case "reviewer":
16631
- return [
16632
- "--ak-role",
16633
- "reviewer",
16634
- "--ak-review-base",
16635
- activation.baseRevision,
16636
- ...activation.authorityRefs.length === 0 ? [] : ["--ak-review-authority-refs", JSON.stringify([...activation.authorityRefs])],
16637
- ...activation.ticketNumber === void 0 ? [] : ["--ak-review-ticket-number", String(activation.ticketNumber)]
16638
- ];
16639
- case "merger":
16640
- return ["--ak-role", "merger", "--ak-merger-input", activation.inputPath];
16641
- case "collector":
16642
- return [
16643
- "--ak-role",
16644
- "collector",
16645
- "--ak-collector-repo",
16646
- activation.repo,
16647
- ...activation.pr === void 0 ? [] : ["--ak-collector-pr", activation.pr],
16648
- ...activation.requestManifestPath === void 0 ? [] : ["--ak-collector-request-manifest", activation.requestManifestPath],
16649
- ...activation.waitMs === void 0 ? [] : ["--ak-collector-wait-ms", activation.waitMs]
16650
- ];
16651
- case "doctor":
16652
- return ["--ak-role", "doctor", "--ak-doctor-case", activation.casePath];
16653
- case "notary":
16654
- return [
16655
- "--ak-role",
16656
- "notary",
16657
- "--ak-notary-source-run",
16658
- activation.sourceRun,
16659
- ...activation.ticketNumber === void 0 ? [] : ["--ak-notary-ticket-number", String(activation.ticketNumber)]
16660
- ];
16661
- case "countersign":
16662
- return ["--ak-role", "countersign"];
16663
- case "gleaner-left":
16664
- return [
16665
- "--ak-role",
16666
- "gleaner-left",
16667
- "--ak-gleaner-left-base",
16668
- activation.baseRevision
16669
- ];
16670
- case "inspector":
16671
- return ["--ak-role", "inspector"];
16672
- case "gatekeeper":
16673
- return ["--ak-role", "gatekeeper"];
16674
- case "navigator":
16675
- return ["--ak-role", "navigator"];
16676
- case "auditor":
16677
- return ["--ak-role", "auditor"];
16678
- case "diarist":
16679
- return ["--ak-role", "diarist"];
16680
- default: {
16681
- const _exhaustive = activation;
16682
- return _exhaustive;
16683
- }
16634
+ function activationFlagsToPiArgv(flags) {
16635
+ const args = [];
16636
+ for (const [name, value] of flags) {
16637
+ if (value === false) continue;
16638
+ args.push(`--${name}`);
16639
+ if (value !== true) args.push(String(value));
16684
16640
  }
16641
+ return args;
16685
16642
  }
16686
16643
  function buildMethodArgs(methods) {
16687
16644
  const skillArgs = [];
@@ -16723,7 +16680,8 @@ function buildPiTurnExtraArgs(request, authority, extraPiArgs = []) {
16723
16680
  "--session-dir",
16724
16681
  sessionDirectory,
16725
16682
  ...extraPiArgs,
16726
- ...buildActivationFlagArgs(request.activation),
16683
+ // Envelope assembly = projectActivationFlags; pi only renders argv pairs.
16684
+ ...activationFlagsToPiArgv(projectActivationFlags(request)),
16727
16685
  "--mode",
16728
16686
  "json",
16729
16687
  ...buildSeatModelCliArgs(request.model),
@@ -16940,6 +16898,7 @@ var init_role_turn_host = __esm({
16940
16898
  "use strict";
16941
16899
  init_host_contracts();
16942
16900
  init_engine_detour();
16901
+ init_role_activation_flags();
16943
16902
  init_sitian_facade();
16944
16903
  INTERNAL_ROLE_ENTRYPOINT_RELATIVE2 = "extensions/role-runtime.ts";
16945
16904
  execFileAsync = promisify(execFile);
@@ -16980,6 +16939,17 @@ var init_run_ticket_number = __esm({
16980
16939
  }
16981
16940
  });
16982
16941
 
16942
+ // src/sha256.ts
16943
+ import { createHash as createHash2 } from "node:crypto";
16944
+ function sha256Hex(bytes) {
16945
+ return createHash2("sha256").update(bytes).digest("hex");
16946
+ }
16947
+ var init_sha256 = __esm({
16948
+ "src/sha256.ts"() {
16949
+ "use strict";
16950
+ }
16951
+ });
16952
+
16983
16953
  // src/readable-gate-item.ts
16984
16954
  var init_readable_gate_item = __esm({
16985
16955
  "src/readable-gate-item.ts"() {
@@ -17755,8 +17725,23 @@ var init_collector_target = __esm({
17755
17725
  }
17756
17726
  });
17757
17727
 
17728
+ // src/git-object-id.ts
17729
+ function isFullGitObjectId(value) {
17730
+ return typeof value === "string" && FULL_GIT_OBJECT_ID_RE.test(value);
17731
+ }
17732
+ var FULL_GIT_OBJECT_ID_RE;
17733
+ var init_git_object_id = __esm({
17734
+ "src/git-object-id.ts"() {
17735
+ "use strict";
17736
+ FULL_GIT_OBJECT_ID_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
17737
+ }
17738
+ });
17739
+
17758
17740
  // src/merger-git-state.ts
17759
17741
  import { execFile as execFile2 } from "node:child_process";
17742
+ import { access as access2, readFile as readFile7 } from "node:fs/promises";
17743
+ import { constants as fsConstants } from "node:fs";
17744
+ import { isAbsolute as isAbsolute4, resolve as resolve6 } from "node:path";
17760
17745
  import { promisify as promisify2 } from "node:util";
17761
17746
  async function git(cwd, args) {
17762
17747
  const { stdout } = await execFileAsync2("git", args, { cwd, encoding: "buffer", maxBuffer: 16 * 1024 * 1024 });
@@ -17767,10 +17752,31 @@ function line(bytes, label) {
17767
17752
  if (!value) throw new Error(`${label} is empty`);
17768
17753
  return value;
17769
17754
  }
17770
- function nulPaths(bytes, label) {
17771
- const raw = exactUtf8(bytes, label);
17772
- if (raw.length > 0 && !raw.endsWith("\0")) throw new Error(`${label} is not NUL terminated`);
17773
- return raw.split("\0").filter(Boolean).sort((a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b)));
17755
+ async function pathExists(path) {
17756
+ try {
17757
+ await access2(path, fsConstants.F_OK);
17758
+ return true;
17759
+ } catch (error) {
17760
+ if (error.code === "ENOENT") return false;
17761
+ throw error;
17762
+ }
17763
+ }
17764
+ async function requireInsideWorkTree(cwd) {
17765
+ const stdout = await git(cwd, ["rev-parse", "--is-inside-work-tree"]);
17766
+ if (exactUtf8(stdout, "Git worktree check").trim() !== "true") throw new Error("Assigned path is not inside a Git work tree");
17767
+ }
17768
+ async function tryResolveCommit(cwd, rev) {
17769
+ let stdout;
17770
+ try {
17771
+ const res = await execFileAsync2("git", ["rev-parse", "--verify", "--quiet", `${rev}^{commit}`], { cwd, encoding: "buffer", maxBuffer: 16 * 1024 * 1024 });
17772
+ stdout = new Uint8Array(res.stdout);
17773
+ } catch (error) {
17774
+ if (error.code === 1) return void 0;
17775
+ throw error;
17776
+ }
17777
+ const oid = line(stdout, `Git ${rev}`);
17778
+ if (!isFullGitObjectId(oid)) throw new Error(`Git ${rev} identity is unavailable or invalid`);
17779
+ return oid;
17774
17780
  }
17775
17781
  async function unmerged(cwd) {
17776
17782
  const raw = exactUtf8(await git(cwd, ["ls-files", "-u", "-z"]), "Git unmerged index");
@@ -17783,40 +17789,39 @@ async function unmerged(cwd) {
17783
17789
  }
17784
17790
  return [...paths].sort((a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b)));
17785
17791
  }
17792
+ async function resolveHeadMaterial(cwd) {
17793
+ const commit = await tryResolveCommit(cwd, "HEAD");
17794
+ if (commit !== void 0) return commit;
17795
+ try {
17796
+ await execFileAsync2("git", ["rev-parse", "--verify", "--quiet", "HEAD"], { cwd, encoding: "buffer", maxBuffer: 16 * 1024 * 1024 });
17797
+ } catch (error) {
17798
+ if (error.code === 1) return "";
17799
+ throw error;
17800
+ }
17801
+ throw new Error("Git HEAD identity is unavailable or invalid");
17802
+ }
17786
17803
  function createProductionMergerGitState(repositoryRoot = process.cwd()) {
17787
17804
  return {
17788
17805
  async activeMerge() {
17789
- const targetObjectId = line(await git(repositoryRoot, ["rev-parse", "--verify", "HEAD"]), "Git HEAD");
17790
- let mergeHeadRaw;
17791
- try {
17792
- mergeHeadRaw = await git(repositoryRoot, ["rev-parse", "--verify", "MERGE_HEAD"]);
17793
- } catch {
17794
- throw new Error("Assigned repository does not have one ordinary in-progress merge");
17795
- }
17796
- const mergeHeads = exactUtf8(mergeHeadRaw, "Git MERGE_HEAD").trim().split(/\r?\n/).filter(Boolean);
17797
- if (mergeHeads.length !== 1 || !isFullGitObjectId(targetObjectId) || !isFullGitObjectId(mergeHeads[0]) || targetObjectId.length !== mergeHeads[0].length) throw new Error("Assigned repository does not have one ordinary in-progress merge");
17798
- let automaticMergeTreeRaw;
17799
- try {
17800
- automaticMergeTreeRaw = await git(repositoryRoot, ["rev-parse", "--verify", "AUTO_MERGE^{tree}"]);
17801
- } catch {
17802
- throw new Error("Git automatic merge tree identity is unavailable or invalid");
17806
+ await requireInsideWorkTree(repositoryRoot);
17807
+ const targetObjectId = await resolveHeadMaterial(repositoryRoot);
17808
+ const mergeHeadReported = line(await git(repositoryRoot, ["rev-parse", "--git-path", "MERGE_HEAD"]), "Git MERGE_HEAD path");
17809
+ const mergeHeadPath = isAbsolute4(mergeHeadReported) ? mergeHeadReported : resolve6(repositoryRoot, mergeHeadReported);
17810
+ let sourceObjectId = "";
17811
+ if (await pathExists(mergeHeadPath)) {
17812
+ const raw = exactUtf8(await readFile7(mergeHeadPath), "Git MERGE_HEAD");
17813
+ const mergeHeads = raw.trim().split(/\r?\n/).map((row) => row.trim()).filter(Boolean);
17814
+ if (mergeHeads.length === 0) throw new Error("Git MERGE_HEAD is empty");
17815
+ if (mergeHeads.length !== 1) throw new Error("Assigned repository does not have one ordinary in-progress merge");
17816
+ const source = mergeHeads[0];
17817
+ if (!isFullGitObjectId(source)) throw new Error("Git MERGE_HEAD identity is unavailable or invalid");
17818
+ const resolved = await tryResolveCommit(repositoryRoot, source);
17819
+ if (resolved === void 0 || targetObjectId !== "" && resolved.length !== targetObjectId.length) {
17820
+ throw new Error("Git MERGE_HEAD identity is unavailable or invalid");
17821
+ }
17822
+ sourceObjectId = resolved;
17803
17823
  }
17804
- const automaticMergeTreeId = line(automaticMergeTreeRaw, "Git automatic merge tree");
17805
- if (!isFullGitObjectId(automaticMergeTreeId) || automaticMergeTreeId.length !== targetObjectId.length) throw new Error("Git automatic merge tree identity is unavailable or invalid");
17806
- return { targetObjectId, sourceObjectId: mergeHeads[0], unmergedPaths: await unmerged(repositoryRoot), automaticMergeTreeId };
17807
- },
17808
- async completedMerge(mergeCommitId, automaticMergeTreeId) {
17809
- if (!isFullGitObjectId(mergeCommitId) || !isFullGitObjectId(automaticMergeTreeId) || mergeCommitId.length !== automaticMergeTreeId.length) throw new Error("Merger completion object ID is invalid");
17810
- const identity = exactUtf8(await git(repositoryRoot, ["show", "-s", "--format=%H%x00%P", mergeCommitId]), "Git merge commit").trimEnd().split("\0");
17811
- if (identity.length !== 2 || identity[0] !== mergeCommitId) throw new Error("Git merge completion identity drifted");
17812
- const parentObjectIds = identity[1].split(" ").filter(Boolean);
17813
- const currentHead = line(await git(repositoryRoot, ["rev-parse", "--verify", "HEAD"]), "Git HEAD");
17814
- const status = await git(repositoryRoot, ["status", "--porcelain=v1", "-z", "--untracked-files=all"]);
17815
- const frozenTree = line(await git(repositoryRoot, ["rev-parse", "--verify", `${automaticMergeTreeId}^{tree}`]), "Git frozen automatic merge tree");
17816
- if (frozenTree !== automaticMergeTreeId) throw new Error("Git frozen automatic merge tree identity drifted");
17817
- const mergeTree = line(await git(repositoryRoot, ["rev-parse", "--verify", `${mergeCommitId}^{tree}`]), "Git completed merge tree");
17818
- const resolutionChangedPaths = nulPaths(await git(repositoryRoot, ["diff-tree", "--no-commit-id", "--name-only", "-r", "-z", "--no-renames", automaticMergeTreeId, mergeTree]), "Git resolution path delta");
17819
- return { mergeCommitId: currentHead, parentObjectIds, unmergedPaths: await unmerged(repositoryRoot), worktreeClean: status.byteLength === 0 && currentHead === mergeCommitId, resolutionChangedPaths };
17824
+ return { targetObjectId, sourceObjectId, unmergedPaths: await unmerged(repositoryRoot) };
17820
17825
  }
17821
17826
  };
17822
17827
  }
@@ -17856,7 +17861,7 @@ var init_uuidv7 = __esm({
17856
17861
  });
17857
17862
 
17858
17863
  // src/typed-provider-http.ts
17859
- import { readFile as readFile7, unlink, writeFile as writeFile2 } from "node:fs/promises";
17864
+ import { readFile as readFile8, unlink, writeFile as writeFile2 } from "node:fs/promises";
17860
17865
  import { join as join12 } from "node:path";
17861
17866
  function typedProviderHttpPath(runDirectory) {
17862
17867
  return join12(runDirectory, TYPED_HTTP_FILE);
@@ -17874,7 +17879,7 @@ async function clearTypedProviderHttpObservation(runDirectory) {
17874
17879
  async function readLatestTypedProviderHttpObservation(runDirectory) {
17875
17880
  let text;
17876
17881
  try {
17877
- text = await readFile7(typedProviderHttpPath(runDirectory), "utf8");
17882
+ text = await readFile8(typedProviderHttpPath(runDirectory), "utf8");
17878
17883
  } catch (error) {
17879
17884
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
17880
17885
  return void 0;
@@ -17903,8 +17908,8 @@ var init_typed_provider_http = __esm({
17903
17908
  });
17904
17909
 
17905
17910
  // src/public-cli/run-lifecycle.ts
17906
- import { chmod, open, readdir as readdir2, readFile as readFile8, unlink as unlink2, writeFile as writeFile3 } from "node:fs/promises";
17907
- import { isAbsolute as isAbsolute4, join as join13 } from "node:path";
17911
+ import { chmod, open, readdir as readdir2, readFile as readFile9, unlink as unlink2, writeFile as writeFile3 } from "node:fs/promises";
17912
+ import { isAbsolute as isAbsolute5, join as join13 } from "node:path";
17908
17913
  function resumeRereadInstruction(materialPath, handbook) {
17909
17914
  return handbook ? `\u91CD\u65B0\u8BFB ${materialPath}\uFF0C\u518D\u7EC4\u88C5\u5916\u5305 argv` : `\u91CD\u65B0\u8BFB ${materialPath}`;
17910
17915
  }
@@ -17916,7 +17921,7 @@ function instructResumeHandbookRead(prompt, engineMaterial) {
17916
17921
  if (handbookPath !== void 0 && value === handbookPath) {
17917
17922
  return resumeRereadInstruction(handbookPath, true);
17918
17923
  }
17919
- if (isAbsolute4(value)) return resumeRereadInstruction(value, false);
17924
+ if (isAbsolute5(value)) return resumeRereadInstruction(value, false);
17920
17925
  return line2;
17921
17926
  }).join("\n");
17922
17927
  }
@@ -18002,7 +18007,7 @@ function parseCurrentCourtState(raw) {
18002
18007
  async function readRoleRunStateDisk(runDirectory) {
18003
18008
  let raw;
18004
18009
  try {
18005
- raw = JSON.parse(await readFile8(join13(runDirectory, RUN_STATE_FILE), "utf8"));
18010
+ raw = JSON.parse(await readFile9(join13(runDirectory, RUN_STATE_FILE), "utf8"));
18006
18011
  } catch {
18007
18012
  return void 0;
18008
18013
  }
@@ -18234,7 +18239,7 @@ function isProcessAlive(pid) {
18234
18239
  async function autopsyWriterLock(lockPath) {
18235
18240
  let content;
18236
18241
  try {
18237
- content = await readFile8(lockPath, "utf8");
18242
+ content = await readFile9(lockPath, "utf8");
18238
18243
  } catch (error) {
18239
18244
  if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
18240
18245
  return { verdict: "absent", readFailure: error };
@@ -18403,7 +18408,7 @@ async function readRunParentPath(runDirectory) {
18403
18408
  let raw;
18404
18409
  try {
18405
18410
  raw = JSON.parse(
18406
- await readFile8(join13(runDirectory, "admitted-request.json"), "utf8")
18411
+ await readFile9(join13(runDirectory, "admitted-request.json"), "utf8")
18407
18412
  );
18408
18413
  } catch (error) {
18409
18414
  if (errorCodeOf2(error) === "ENOENT") return void 0;
@@ -18514,7 +18519,7 @@ async function loadResumableRunRecord(home, runId, authority) {
18514
18519
  let sourceRun;
18515
18520
  try {
18516
18521
  const raw = JSON.parse(
18517
- await readFile8(run.admittedRequestPath, "utf8")
18522
+ await readFile9(run.admittedRequestPath, "utf8")
18518
18523
  );
18519
18524
  if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
18520
18525
  const record4 = raw;
@@ -18605,11 +18610,10 @@ async function loadResumableRunRecord(home, runId, authority) {
18605
18610
  }
18606
18611
  if (record4.derived !== null && typeof record4.derived === "object" && !Array.isArray(record4.derived)) {
18607
18612
  const d = record4.derived;
18608
- if (typeof d.targetObjectId === "string" && typeof d.sourceObjectId === "string" && typeof d.automaticMergeTreeId === "string" && Array.isArray(d.expectedConflictPaths) && Array.isArray(d.resolutionScope) && d.expectedConflictPaths.every((p) => typeof p === "string") && d.resolutionScope.every((p) => typeof p === "string")) {
18613
+ if (typeof d.targetObjectId === "string" && typeof d.sourceObjectId === "string" && Array.isArray(d.expectedConflictPaths) && Array.isArray(d.resolutionScope) && d.expectedConflictPaths.every((p) => typeof p === "string") && d.resolutionScope.every((p) => typeof p === "string")) {
18609
18614
  derived = {
18610
18615
  targetObjectId: d.targetObjectId,
18611
18616
  sourceObjectId: d.sourceObjectId,
18612
- automaticMergeTreeId: d.automaticMergeTreeId,
18613
18617
  expectedConflictPaths: d.expectedConflictPaths,
18614
18618
  resolutionScope: d.resolutionScope
18615
18619
  };
@@ -18629,7 +18633,7 @@ async function loadResumableRunRecord(home, runId, authority) {
18629
18633
  let model;
18630
18634
  try {
18631
18635
  const invocationRaw = JSON.parse(
18632
- await readFile8(join13(run.runDirectory, "invocation.json"), "utf8")
18636
+ await readFile9(join13(run.runDirectory, "invocation.json"), "utf8")
18633
18637
  );
18634
18638
  if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
18635
18639
  const rec = invocationRaw;
@@ -19039,7 +19043,7 @@ __export(notary_source_run_exports, {
19039
19043
  loadNotarySourceRunLocator: () => loadNotarySourceRunLocator,
19040
19044
  resolveNotarySourceRunLocator: () => resolveNotarySourceRunLocator
19041
19045
  });
19042
- import { dirname as dirname8, isAbsolute as isAbsolute5, join as join14, resolve as resolve6, basename as basename5 } from "node:path";
19046
+ import { dirname as dirname8, isAbsolute as isAbsolute6, join as join14, resolve as resolve7, basename as basename5 } from "node:path";
19043
19047
  import { lstat as lstat2, realpath as realpath3 } from "node:fs/promises";
19044
19048
  function parseRunDirectoryName(name) {
19045
19049
  const match = RUN_DIR_NAME.exec(name);
@@ -19091,7 +19095,7 @@ async function resolveNotarySourceRunLocator(options) {
19091
19095
  if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
19092
19096
  candidate = join14(bookRunsRoot, `${bare.runId}@${bare.role}`);
19093
19097
  } else {
19094
- candidate = isAbsolute5(raw) ? raw : resolve6(options.projectRoot, raw);
19098
+ candidate = isAbsolute6(raw) ? raw : resolve7(options.projectRoot, raw);
19095
19099
  }
19096
19100
  const real = await requireRunDirectory(candidate, raw);
19097
19101
  const identity = parseRunDirectoryName(basename5(real));
@@ -19831,7 +19835,7 @@ var init_option_definitions = __esm({
19831
19835
  }
19832
19836
  ];
19833
19837
  MERGER_OPTIONS = [
19834
- // Merger project face differs: requires an in-progress ordinary merge root.
19838
+ // Merger project face: worktree whose Git materials are handed to the role.
19835
19839
  {
19836
19840
  id: "project",
19837
19841
  owner: "merger",
@@ -19842,8 +19846,8 @@ var init_option_definitions = __esm({
19842
19846
  repeatable: false,
19843
19847
  form: "option",
19844
19848
  description: {
19845
- en: "Project root with one ordinary in-progress merge (defaults to cwd).",
19846
- zh: "\u5DF2\u6709\u8FDB\u884C\u4E2D ordinary merge \u7684\u9879\u76EE\u6839\uFF08\u9ED8\u8BA4 cwd\uFF09\u3002"
19849
+ en: "Project root whose Git merge materials are read (defaults to cwd).",
19850
+ zh: "\u8BFB\u53D6 Git merge \u6750\u6599\u7684\u9879\u76EE\u6839\uFF08\u9ED8\u8BA4 cwd\uFF09\u3002"
19847
19851
  }
19848
19852
  },
19849
19853
  bindOwner("merger", SHARED_ATTACH_SEMANTICS)
@@ -20085,10 +20089,10 @@ var init_option_definitions = __esm({
20085
20089
  },
20086
20090
  merger: {
20087
20091
  command: "merger",
20088
- summary: "Resolve one ordinary merge already in conflict.",
20092
+ summary: "Reconcile merge materials in a worktree (escalate when nothing to merge).",
20089
20093
  usage: ["ak-role merger [options] <instruction>"],
20090
20094
  examples: [
20091
- 'ak-role merger --project /path/to/worktree "Reconcile the active merge."'
20095
+ 'ak-role merger --project /path/to/worktree "Reconcile the merge."'
20092
20096
  ]
20093
20097
  },
20094
20098
  inspector: {
@@ -20225,11 +20229,11 @@ import { execFileSync as execFileSync3 } from "node:child_process";
20225
20229
  import {
20226
20230
  lstat as lstat3,
20227
20231
  mkdir as mkdir2,
20228
- readFile as readFile9,
20232
+ readFile as readFile10,
20229
20233
  realpath as realpath4,
20230
20234
  writeFile as writeFile4
20231
20235
  } from "node:fs/promises";
20232
- import { basename as basename6, isAbsolute as isAbsolute6, join as join15, resolve as resolve7, sep as sep3 } from "node:path";
20236
+ import { basename as basename6, isAbsolute as isAbsolute7, join as join15, resolve as resolve8, sep as sep3 } from "node:path";
20233
20237
  function issueAdmissionPlacement(authority, request) {
20234
20238
  const principal = authority.issue(request);
20235
20239
  const { sessionDirectory, sessionFile } = authority.decode(principal);
@@ -20289,7 +20293,7 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
20289
20293
  }
20290
20294
  async function recordEffectiveInvocationModel(runDirectory, model, engine, host) {
20291
20295
  const ledgerPath = join15(runDirectory, "invocation.json");
20292
- const current = JSON.parse(await readFile9(ledgerPath, "utf8"));
20296
+ const current = JSON.parse(await readFile10(ledgerPath, "utf8"));
20293
20297
  const next = { ...current };
20294
20298
  if (model !== void 0) {
20295
20299
  next.provider = model.provider;
@@ -20317,7 +20321,7 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host)
20317
20321
  }
20318
20322
  async function mergeInvocationIdentityPage(runDirectory, fields) {
20319
20323
  const ledgerPath = join15(runDirectory, "invocation.json");
20320
- const current = JSON.parse(await readFile9(ledgerPath, "utf8"));
20324
+ const current = JSON.parse(await readFile10(ledgerPath, "utf8"));
20321
20325
  await writeFile4(
20322
20326
  ledgerPath,
20323
20327
  `${JSON.stringify({
@@ -20333,7 +20337,7 @@ async function persistAdmittedSourceRunPath(admitted, sourceRunPath) {
20333
20337
  throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
20334
20338
  }
20335
20339
  const admittedPath = admitted.admittedRequestPath;
20336
- const current = JSON.parse(await readFile9(admittedPath, "utf8"));
20340
+ const current = JSON.parse(await readFile10(admittedPath, "utf8"));
20337
20341
  if (typeof current.sourceRunPath === "string") {
20338
20342
  if (current.sourceRunPath === sourceRunPath) return;
20339
20343
  throw new Error(
@@ -20360,7 +20364,7 @@ async function bindAdmittedTicketNumber(admitted, ticketNumber) {
20360
20364
  admitted.ticketNumber = ticketNumber;
20361
20365
  await mergeInvocationIdentityPage(admitted.runDirectory, { ticketNumber });
20362
20366
  const admittedPath = admitted.admittedRequestPath;
20363
- const current = JSON.parse(await readFile9(admittedPath, "utf8"));
20367
+ const current = JSON.parse(await readFile10(admittedPath, "utf8"));
20364
20368
  await writeFile4(
20365
20369
  admittedPath,
20366
20370
  `${JSON.stringify({ ...current, ticketNumber }, null, 2)}
@@ -20377,7 +20381,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
20377
20381
  async function observeLaunchedRolePackageIdentity(packageRoot2, selectedRoleEntry) {
20378
20382
  const rolePackageRoot = packageRoot2;
20379
20383
  const raw = JSON.parse(
20380
- await readFile9(join15(rolePackageRoot, "package.json"), "utf8")
20384
+ await readFile10(join15(rolePackageRoot, "package.json"), "utf8")
20381
20385
  );
20382
20386
  if (typeof raw.version !== "string" || raw.version.trim() === "") {
20383
20387
  throw new Error(
@@ -20607,7 +20611,7 @@ function parseFixerArgv(args) {
20607
20611
  };
20608
20612
  }
20609
20613
  async function freezeRegularFileAttachment(sourcePath, destinationDir, index) {
20610
- const absolute = isAbsolute6(sourcePath) ? sourcePath : resolve7(sourcePath);
20614
+ const absolute = isAbsolute7(sourcePath) ? sourcePath : resolve8(sourcePath);
20611
20615
  let st;
20612
20616
  try {
20613
20617
  st = await lstat3(absolute);
@@ -20622,7 +20626,7 @@ async function freezeRegularFileAttachment(sourcePath, destinationDir, index) {
20622
20626
  `attachment must be a regular file (not a directory or symlink): ${sourcePath}`
20623
20627
  );
20624
20628
  }
20625
- const bytes = await readFile9(absolute);
20629
+ const bytes = await readFile10(absolute);
20626
20630
  const name = `${String(index).padStart(2, "0")}-${basename6(absolute)}`;
20627
20631
  const frozenPath = join15(destinationDir, name);
20628
20632
  await writeFile4(frozenPath, bytes);
@@ -20663,7 +20667,7 @@ async function admitStandardMaterialInvocation(role, options) {
20663
20667
  if (options.project !== void 0) {
20664
20668
  requireOptionPath("--project", options.project);
20665
20669
  }
20666
- const projectRoot = resolve7(options.project ?? options.cwd);
20670
+ const projectRoot = resolve8(options.project ?? options.cwd);
20667
20671
  const runId = (options.createRunId ?? uuidv7)();
20668
20672
  const {
20669
20673
  principal,
@@ -20766,7 +20770,7 @@ async function admitCountersignInvocation(options) {
20766
20770
  if (options.project !== void 0) {
20767
20771
  requireOptionPath("--project", options.project);
20768
20772
  }
20769
- const projectRoot = resolve7(options.project ?? options.cwd);
20773
+ const projectRoot = resolve8(options.project ?? options.cwd);
20770
20774
  const runId = (options.createRunId ?? uuidv7)();
20771
20775
  const {
20772
20776
  principal,
@@ -20846,7 +20850,7 @@ async function admitCoderInvocation(options) {
20846
20850
  if (options.phase !== "plan" && options.phase !== "apply") {
20847
20851
  throw new CliUsageError("coder phase must be plan or apply");
20848
20852
  }
20849
- const projectRoot = resolve7(options.project ?? options.cwd);
20853
+ const projectRoot = resolve8(options.project ?? options.cwd);
20850
20854
  const runId = (options.createRunId ?? uuidv7)();
20851
20855
  const {
20852
20856
  principal,
@@ -20934,9 +20938,9 @@ async function admitFixerInvocation(options) {
20934
20938
  let prerequisites = Object.freeze([]);
20935
20939
  let prerequisitesSource;
20936
20940
  if (options.prerequisitesPath !== void 0) {
20937
- const absolutePrereq = isAbsolute6(options.prerequisitesPath) ? options.prerequisitesPath : resolve7(options.prerequisitesPath);
20941
+ const absolutePrereq = isAbsolute7(options.prerequisitesPath) ? options.prerequisitesPath : resolve8(options.prerequisitesPath);
20938
20942
  try {
20939
- prerequisitesSource = await readFile9(absolutePrereq, "utf8");
20943
+ prerequisitesSource = await readFile10(absolutePrereq, "utf8");
20940
20944
  } catch (error) {
20941
20945
  throw new CliUsageError(
20942
20946
  `fixer prerequisites path is unreadable: ${options.prerequisitesPath}`,
@@ -20952,7 +20956,7 @@ async function admitFixerInvocation(options) {
20952
20956
  throw error;
20953
20957
  }
20954
20958
  }
20955
- const projectRoot = resolve7(options.project ?? options.cwd);
20959
+ const projectRoot = resolve8(options.project ?? options.cwd);
20956
20960
  const runId = (options.createRunId ?? uuidv7)();
20957
20961
  const {
20958
20962
  principal,
@@ -21177,7 +21181,7 @@ async function admitCollectorInvocation(options) {
21177
21181
  throw new CliUsageError(detail, { cause: error });
21178
21182
  }
21179
21183
  }
21180
- const projectRoot = resolve7(options.project ?? options.cwd);
21184
+ const projectRoot = resolve8(options.project ?? options.cwd);
21181
21185
  let repository;
21182
21186
  if (options.repo !== void 0) {
21183
21187
  try {
@@ -21365,12 +21369,12 @@ async function resolveDoctorCaseRunsPath(options) {
21365
21369
  if (raw === "") {
21366
21370
  throw new CliUsageError("doctor --runs requires a path");
21367
21371
  }
21368
- if (isAbsolute6(raw)) {
21372
+ if (isAbsolute7(raw)) {
21369
21373
  throw new CliUsageError(
21370
21374
  "doctor --runs must be a project-relative path"
21371
21375
  );
21372
21376
  }
21373
- const resolved = resolve7(options.projectRoot, raw);
21377
+ const resolved = resolve8(options.projectRoot, raw);
21374
21378
  if (resolved !== options.projectRoot && !pathContainedIn(options.projectRoot, resolved)) {
21375
21379
  throw new CliUsageError(
21376
21380
  "doctor --runs escapes the project root"
@@ -21409,7 +21413,7 @@ async function admitDoctorInvocation(options) {
21409
21413
  `doctor --issue must be a positive integer, got ${options.issueNumber}`
21410
21414
  );
21411
21415
  }
21412
- const projectRoot = resolve7(options.project ?? options.cwd);
21416
+ const projectRoot = resolve8(options.project ?? options.cwd);
21413
21417
  const runId = (options.createRunId ?? uuidv7)();
21414
21418
  const {
21415
21419
  principal,
@@ -21570,7 +21574,7 @@ async function admitNotaryInvocation(options) {
21570
21574
  if (options.project !== void 0) {
21571
21575
  requireOptionPath("--project", options.project);
21572
21576
  }
21573
- const projectRoot = resolve7(options.project ?? options.cwd);
21577
+ const projectRoot = resolve8(options.project ?? options.cwd);
21574
21578
  let sourceRun;
21575
21579
  try {
21576
21580
  sourceRun = await resolveNotarySourceRunLocator({
@@ -21688,7 +21692,7 @@ async function admitGleanerLeftInvocation(options) {
21688
21692
  if (options.baseRevision.trim() === "") {
21689
21693
  throw new CliUsageError("--base requires a nonempty revision");
21690
21694
  }
21691
- const projectRoot = resolve7(options.project ?? options.cwd);
21695
+ const projectRoot = resolve8(options.project ?? options.cwd);
21692
21696
  const runId = (options.createRunId ?? uuidv7)();
21693
21697
  const {
21694
21698
  principal,
@@ -21809,7 +21813,7 @@ async function admitReviewerInvocation(options) {
21809
21813
  const authorityRefs = Object.freeze(
21810
21814
  (options.authorityRefs ?? []).map((ref) => requireAuthorityRef(ref))
21811
21815
  );
21812
- const projectRoot = resolve7(options.project ?? options.cwd);
21816
+ const projectRoot = resolve8(options.project ?? options.cwd);
21813
21817
  const runId = (options.createRunId ?? uuidv7)();
21814
21818
  const {
21815
21819
  principal,
@@ -21904,7 +21908,7 @@ function parseMergerArgv(args) {
21904
21908
  const token = tokens.shift();
21905
21909
  if (isRejectedPublicSpelling("merger", token) || token === "--targetObjectId" || token.startsWith("--targetObjectId=") || token === "--sourceObjectId" || token.startsWith("--sourceObjectId=") || token === "--expectedConflictPaths" || token.startsWith("--expectedConflictPaths=") || token === "--resolutionScope" || token.startsWith("--resolutionScope=")) {
21906
21910
  throw new CliUsageError(
21907
- "merger does not accept public packet fields; the adapter derives the active-merge envelope"
21911
+ "merger does not accept public packet fields; the adapter reads Git merge materials"
21908
21912
  );
21909
21913
  }
21910
21914
  if (token.startsWith("-") && token !== "-") {
@@ -21927,24 +21931,12 @@ function mergerMaterialFromUtf8(text) {
21927
21931
  });
21928
21932
  }
21929
21933
  async function deriveMergerEnvelopeFromActiveMerge(projectRoot, gitState = createProductionMergerGitState(projectRoot)) {
21930
- let state;
21931
- try {
21932
- state = await gitState.activeMerge();
21933
- } catch (error) {
21934
- const message = error instanceof Error && error.message.trim() !== "" ? error.message : "Assigned repository does not have one ordinary in-progress merge";
21935
- throw new MergerEnvelopeDerivationError(message, { cause: error });
21936
- }
21937
- if (state.unmergedPaths.length === 0) {
21938
- throw new MergerEnvelopeDerivationError(
21939
- "Assigned repository does not have one ordinary in-progress merge with a complete conflict set"
21940
- );
21941
- }
21934
+ const state = await gitState.activeMerge();
21942
21935
  const expectedConflictPaths = Object.freeze([...state.unmergedPaths]);
21943
21936
  const resolutionScope = Object.freeze([...state.unmergedPaths]);
21944
21937
  return Object.freeze({
21945
21938
  targetObjectId: state.targetObjectId,
21946
21939
  sourceObjectId: state.sourceObjectId,
21947
- automaticMergeTreeId: state.automaticMergeTreeId,
21948
21940
  expectedConflictPaths,
21949
21941
  resolutionScope
21950
21942
  });
@@ -21957,7 +21949,7 @@ async function admitMergerInvocation(options) {
21957
21949
  if (instruction.trim() === "") {
21958
21950
  throw new CliUsageError("merger requires a nonblank task instruction");
21959
21951
  }
21960
- const projectRoot = resolve7(options.project ?? options.cwd);
21952
+ const projectRoot = resolve8(options.project ?? options.cwd);
21961
21953
  const derived = await deriveMergerEnvelopeFromActiveMerge(
21962
21954
  projectRoot,
21963
21955
  options.gitState ?? createProductionMergerGitState(projectRoot)
@@ -21980,16 +21972,17 @@ async function admitMergerInvocation(options) {
21980
21972
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
21981
21973
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
21982
21974
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
21975
+ const targetLabel = derived.targetObjectId === "" ? "(none observed)" : derived.targetObjectId;
21976
+ const sourceLabel = derived.sourceObjectId === "" ? "(none observed)" : derived.sourceObjectId;
21983
21977
  const targetIntent = mergerMaterialFromUtf8(
21984
- `Investigate primary sources for target parent ${derived.targetObjectId}. Do not invent intent.`
21978
+ `Investigate primary sources for target parent ${targetLabel}. Do not invent intent.`
21985
21979
  );
21986
21980
  const sourceIntent = mergerMaterialFromUtf8(
21987
- `Investigate primary sources for source parent ${derived.sourceObjectId}. Do not invent intent.`
21981
+ `Investigate primary sources for source parent ${sourceLabel}. Do not invent intent.`
21988
21982
  );
21989
21983
  const taskMaterial = mergerMaterialFromUtf8(instruction);
21990
21984
  const authorityMaterial = mergerMaterialFromUtf8(instruction);
21991
21985
  const mergerInput = validateMergerInput({
21992
- version: 1,
21993
21986
  attemptId: runId,
21994
21987
  targetObjectId: derived.targetObjectId,
21995
21988
  sourceObjectId: derived.sourceObjectId,
@@ -22001,7 +21994,6 @@ async function admitMergerInvocation(options) {
22001
21994
  },
22002
21995
  expectedConflictPaths: [...derived.expectedConflictPaths],
22003
21996
  resolutionScope: [...derived.resolutionScope],
22004
- // Authorized checks remain available on the assignment; default none.
22005
21997
  authorizedChecks: []
22006
21998
  });
22007
21999
  const mergerInputPath = join15(runDirectory, "merger-input.json");
@@ -22024,7 +22016,6 @@ async function admitMergerInvocation(options) {
22024
22016
  derived: {
22025
22017
  targetObjectId: derived.targetObjectId,
22026
22018
  sourceObjectId: derived.sourceObjectId,
22027
- automaticMergeTreeId: derived.automaticMergeTreeId,
22028
22019
  expectedConflictPaths: [...derived.expectedConflictPaths],
22029
22020
  resolutionScope: [...derived.resolutionScope]
22030
22021
  },
@@ -22288,7 +22279,7 @@ function parseAnalystArgv(args) {
22288
22279
  ...ticketRaw === void 0 ? {} : { ticket: parseAnalystTicketNumber(ticketRaw) }
22289
22280
  };
22290
22281
  }
22291
- var MergerEnvelopeDerivationError, DOCTOR_ISSUE_NUMBER_PATTERN, DOCTOR_CASE_RUNS_PATH_PATTERN, ANALYST_TICKET_NUMBER_PATTERN;
22282
+ var DOCTOR_ISSUE_NUMBER_PATTERN, DOCTOR_CASE_RUNS_PATH_PATTERN, ANALYST_TICKET_NUMBER_PATTERN;
22292
22283
  var init_invocation = __esm({
22293
22284
  "src/public-cli/invocation.ts"() {
22294
22285
  "use strict";
@@ -22309,15 +22300,6 @@ var init_invocation = __esm({
22309
22300
  init_engine_material();
22310
22301
  init_cli_errors();
22311
22302
  init_option_definitions();
22312
- MergerEnvelopeDerivationError = class extends Error {
22313
- code = "merger-envelope-derivation";
22314
- /** Typed cause for #107 classifyPostAdmissionFailure (isTypedActivationError). */
22315
- knownCause = "activation";
22316
- constructor(message, options) {
22317
- super(message, options);
22318
- this.name = "MergerEnvelopeDerivationError";
22319
- }
22320
- };
22321
22303
  DOCTOR_ISSUE_NUMBER_PATTERN = /^[1-9]\d*$/;
22322
22304
  DOCTOR_CASE_RUNS_PATH_PATTERN = /\/\.ak-roles\/books\/[^/]+\/issues\/([1-9]\d*)\/runs$/;
22323
22305
  ANALYST_TICKET_NUMBER_PATTERN = /^[1-9]\d*$/;
@@ -22326,7 +22308,7 @@ var init_invocation = __esm({
22326
22308
 
22327
22309
  // src/package-resources/method-skill.ts
22328
22310
  import { createHash as createHash4 } from "node:crypto";
22329
- import { readFile as readFile10, realpath as realpath5 } from "node:fs/promises";
22311
+ import { readFile as readFile11, realpath as realpath5 } from "node:fs/promises";
22330
22312
  import { join as join16 } from "node:path";
22331
22313
  function gitBlobOid(bytes) {
22332
22314
  const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
@@ -22445,7 +22427,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
22445
22427
  const provenancePath = join16(rootDirectory, "provenance.json");
22446
22428
  let provenanceRaw;
22447
22429
  try {
22448
- provenanceRaw = await readFile10(provenancePath, "utf8");
22430
+ provenanceRaw = await readFile11(provenancePath, "utf8");
22449
22431
  } catch (error) {
22450
22432
  throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
22451
22433
  }
@@ -22462,7 +22444,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
22462
22444
  const absolute = join16(rootDirectory, rel);
22463
22445
  let bytes;
22464
22446
  try {
22465
- bytes = await readFile10(absolute);
22447
+ bytes = await readFile11(absolute);
22466
22448
  } catch (error) {
22467
22449
  throw new PackagedMethodSkillUnavailableError(name, absolute, error);
22468
22450
  }
@@ -22478,7 +22460,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
22478
22460
  let raw;
22479
22461
  try {
22480
22462
  skillPath = await realpath5(skillPathConfigured);
22481
- raw = await readFile10(skillPath, "utf8");
22463
+ raw = await readFile11(skillPath, "utf8");
22482
22464
  } catch (error) {
22483
22465
  throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
22484
22466
  }
@@ -22581,12 +22563,12 @@ var init_compliance_transport = __esm({
22581
22563
  });
22582
22564
 
22583
22565
  // src/ledger-session-read.ts
22584
- import { readFile as readFile11 } from "node:fs/promises";
22566
+ import { readFile as readFile12 } from "node:fs/promises";
22585
22567
  function isRecord11(value) {
22586
22568
  return typeof value === "object" && value !== null && !Array.isArray(value);
22587
22569
  }
22588
22570
  async function readLedgerSessionJsonl(path) {
22589
- const text = await readFile11(path, "utf8");
22571
+ const text = await readFile12(path, "utf8");
22590
22572
  const lines = text.split("\n");
22591
22573
  const rows = [];
22592
22574
  for (let index = 0; index < lines.length; index += 1) {
@@ -22988,10 +22970,10 @@ function pairGateRounds(volumes) {
22988
22970
  return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
22989
22971
  }
22990
22972
  async function resolveOfficerSessionFromPointerFile(pointerPath) {
22991
- const { readFile: readFile21 } = await import("node:fs/promises");
22973
+ const { readFile: readFile22 } = await import("node:fs/promises");
22992
22974
  let raw;
22993
22975
  try {
22994
- raw = JSON.parse(await readFile21(pointerPath, "utf8"));
22976
+ raw = JSON.parse(await readFile22(pointerPath, "utf8"));
22995
22977
  } catch (error) {
22996
22978
  throw new Error(
22997
22979
  `direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
@@ -23065,7 +23047,7 @@ var init_analyst_gate_cycles_read = __esm({
23065
23047
  });
23066
23048
 
23067
23049
  // src/run-terminal-artifacts.ts
23068
- import { readdir as readdir4, readFile as readFile12 } from "node:fs/promises";
23050
+ import { readdir as readdir4, readFile as readFile13 } from "node:fs/promises";
23069
23051
  import { basename as basename7, dirname as dirname9, join as join18 } from "node:path";
23070
23052
  function isMissingPathError2(error) {
23071
23053
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
@@ -23097,7 +23079,7 @@ function readUsableTerminalArtifactBody(body) {
23097
23079
  async function readTerminalArtifactAtPath(path, file) {
23098
23080
  let raw;
23099
23081
  try {
23100
- raw = await readFile12(path, "utf8");
23082
+ raw = await readFile13(path, "utf8");
23101
23083
  } catch (error) {
23102
23084
  if (isMissingPathError2(error)) return void 0;
23103
23085
  return {
@@ -23303,7 +23285,7 @@ var init_submission_ledger = __esm({
23303
23285
 
23304
23286
  // src/session-opening-materials.ts
23305
23287
  import { existsSync as existsSync7 } from "node:fs";
23306
- import { readFile as readFile13 } from "node:fs/promises";
23288
+ import { readFile as readFile14 } from "node:fs/promises";
23307
23289
  import { dirname as dirname10, join as join19 } from "node:path";
23308
23290
  import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
23309
23291
  function resolvePackageRootDir(moduleUrl = import.meta.url) {
@@ -23319,7 +23301,7 @@ function resolvePackageRootDir(moduleUrl = import.meta.url) {
23319
23301
  return fileURLToPath(new URL("..", moduleUrl));
23320
23302
  }
23321
23303
  async function readPackageMaterial(relativePath) {
23322
- return readFile13(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
23304
+ return readFile14(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
23323
23305
  }
23324
23306
  async function joinPackageMaterials(relativePaths) {
23325
23307
  const chunks = [];
@@ -23588,7 +23570,7 @@ var init_reviewer_dispatch = __esm({
23588
23570
  });
23589
23571
 
23590
23572
  // src/public-cli/reviewer-dispatch-rejection.ts
23591
- import { readFile as readFile14, unlink as unlink3 } from "node:fs/promises";
23573
+ import { readFile as readFile15, unlink as unlink3 } from "node:fs/promises";
23592
23574
  import { join as join20 } from "node:path";
23593
23575
  function isReviewerPreflightViolation(value) {
23594
23576
  return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
@@ -23609,7 +23591,7 @@ async function clearReviewerDispatchRejection(runDirectory) {
23609
23591
  async function readReviewerDispatchRejection(runDirectory) {
23610
23592
  let raw;
23611
23593
  try {
23612
- raw = await readFile14(reviewerDispatchRejectionPath(runDirectory), "utf8");
23594
+ raw = await readFile15(reviewerDispatchRejectionPath(runDirectory), "utf8");
23613
23595
  } catch (error) {
23614
23596
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
23615
23597
  return void 0;
@@ -23975,7 +23957,7 @@ var init_terminal = __esm({
23975
23957
 
23976
23958
  // src/public-cli/settlement.ts
23977
23959
  import { randomUUID as randomUUID3 } from "node:crypto";
23978
- import { appendFile as appendFile2, readFile as readFile15, readdir as readdir5, writeFile as writeFile5 } from "node:fs/promises";
23960
+ import { appendFile as appendFile2, readFile as readFile16, readdir as readdir5, writeFile as writeFile5 } from "node:fs/promises";
23979
23961
  import { dirname as dirname11, join as join21 } from "node:path";
23980
23962
  function sealedLedgerHome(admitted) {
23981
23963
  return homeFromRunDirectory(admitted.runDirectory);
@@ -24093,7 +24075,7 @@ function presentControlledFailure(failure, io) {
24093
24075
  }
24094
24076
  async function inspectJudgeSession(sessionFile) {
24095
24077
  try {
24096
- await readFile15(sessionFile, "utf8");
24078
+ await readFile16(sessionFile, "utf8");
24097
24079
  return { state: "present" };
24098
24080
  } catch (error) {
24099
24081
  if (isMissingPathError3(error)) return { state: "missing" };
@@ -24309,7 +24291,7 @@ function sessionReadFailure(error, fallbackMessage) {
24309
24291
  return failed;
24310
24292
  }
24311
24293
  async function readBoundSessionEntries(sessionFile) {
24312
- const text = await readFile15(sessionFile, "utf8");
24294
+ const text = await readFile16(sessionFile, "utf8");
24313
24295
  const entries = [];
24314
24296
  for (const line2 of text.trim().split("\n").filter(Boolean)) {
24315
24297
  try {
@@ -26490,14 +26472,14 @@ var init_case_dossier_delivery = __esm({
26490
26472
  });
26491
26473
 
26492
26474
  // src/host-transition-prior-native.ts
26493
- import { access as access2, readdir as readdir6 } from "node:fs/promises";
26475
+ import { access as access3, readdir as readdir6 } from "node:fs/promises";
26494
26476
  import { dirname as dirname12, join as join23 } from "node:path";
26495
26477
  function isEnoent2(error) {
26496
26478
  return typeof error === "object" && error !== null && error.code === "ENOENT";
26497
26479
  }
26498
26480
  async function listPiNativeRecordPaths(sessionFile) {
26499
26481
  try {
26500
- await access2(sessionFile);
26482
+ await access3(sessionFile);
26501
26483
  return [sessionFile];
26502
26484
  } catch (error) {
26503
26485
  if (isEnoent2(error)) return [];
@@ -26518,7 +26500,7 @@ async function listSitianRecordPaths(sessionParent) {
26518
26500
  if (!entry.isDirectory()) continue;
26519
26501
  const recordFile = join23(sessionRoot, entry.name, "records.jsonl");
26520
26502
  try {
26521
- await access2(recordFile);
26503
+ await access3(recordFile);
26522
26504
  recordPaths.push(recordFile);
26523
26505
  } catch (error) {
26524
26506
  if (!isEnoent2(error)) throw error;
@@ -26583,7 +26565,7 @@ var init_public_run_credentials = __esm({
26583
26565
  });
26584
26566
 
26585
26567
  // src/public-cli/auto-resume.ts
26586
- import { constants as fsConstants } from "node:fs";
26568
+ import { constants as fsConstants2 } from "node:fs";
26587
26569
  import { randomUUID as randomUUID4 } from "node:crypto";
26588
26570
  import { lstat as lstat5, mkdir as mkdir4, open as open2 } from "node:fs/promises";
26589
26571
  import { join as join24 } from "node:path";
@@ -26703,10 +26685,10 @@ async function retainDispatchError(admitted, principalAuthority, sessionAppender
26703
26685
  2
26704
26686
  )}
26705
26687
  `;
26706
- const noFollowFlag = typeof fsConstants.O_NOFOLLOW === "number" ? fsConstants.O_NOFOLLOW : 0;
26688
+ const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
26707
26689
  const handle = await open2(
26708
26690
  filePath,
26709
- fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_EXCL | noFollowFlag,
26691
+ fsConstants2.O_WRONLY | fsConstants2.O_CREAT | fsConstants2.O_EXCL | noFollowFlag,
26710
26692
  384
26711
26693
  );
26712
26694
  try {
@@ -26936,8 +26918,8 @@ var init_auto_resume = __esm({
26936
26918
 
26937
26919
  // src/public-cli/post-admission.ts
26938
26920
  import { randomUUID as randomUUID5 } from "node:crypto";
26939
- import { readFile as readFile16, writeFile as writeFile6 } from "node:fs/promises";
26940
- import { isAbsolute as isAbsolute7, join as join25, resolve as resolve8 } from "node:path";
26921
+ import { readFile as readFile17, writeFile as writeFile6 } from "node:fs/promises";
26922
+ import { isAbsolute as isAbsolute8, join as join25, resolve as resolve9 } from "node:path";
26941
26923
  function appendContinuationSection(continuation, section) {
26942
26924
  const prompt = `${continuation.prompt}
26943
26925
 
@@ -26946,7 +26928,7 @@ ${section}`;
26946
26928
  }
26947
26929
  async function readInvocationHost(runDirectory) {
26948
26930
  try {
26949
- const raw = JSON.parse(await readFile16(join25(runDirectory, "invocation.json"), "utf8"));
26931
+ const raw = JSON.parse(await readFile17(join25(runDirectory, "invocation.json"), "utf8"));
26950
26932
  return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host : void 0;
26951
26933
  } catch (error) {
26952
26934
  if (error.code === "ENOENT") return void 0;
@@ -27208,7 +27190,7 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
27208
27190
  };
27209
27191
  }
27210
27192
  function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
27211
- const absolute = isAbsolute7(attachmentPath) ? attachmentPath : resolve8(attachmentPath);
27193
+ const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve9(attachmentPath);
27212
27194
  return pathContainedIn(join25(runDirectory, "attachments"), absolute);
27213
27195
  }
27214
27196
  async function prepareSummonsResumeMaterials(runDirectory, summons) {
@@ -29379,8 +29361,6 @@ var init_judge_run = __esm({
29379
29361
  });
29380
29362
 
29381
29363
  // src/public-cli/merger-run.ts
29382
- import { mkdir as mkdir5, writeFile as writeFile7 } from "node:fs/promises";
29383
- import { join as join26, resolve as resolve9 } from "node:path";
29384
29364
  function mergerMethods(packageRoot2) {
29385
29365
  return [
29386
29366
  {
@@ -29421,70 +29401,6 @@ async function loadMergerMethodMaterial(packageRoot2) {
29421
29401
  "resolving-merge-conflicts"
29422
29402
  );
29423
29403
  }
29424
- async function admitMergerShellForActivationFailure(options) {
29425
- const projectRoot = resolve9(options.project ?? options.cwd);
29426
- const runId = (options.createRunId ?? uuidv7)();
29427
- const {
29428
- principal,
29429
- sessionDirectory,
29430
- sessionFile,
29431
- runDirectory,
29432
- ledgerHome,
29433
- bookKey
29434
- } = issueAdmissionPlacement(options.principalAuthority, {
29435
- cwd: projectRoot,
29436
- runId,
29437
- role: "merger",
29438
- home: options.home
29439
- });
29440
- ensureRealDirectoryTree(ledgerHome, sessionDirectory);
29441
- await mkdir5(runDirectory, { recursive: true });
29442
- const emptyDerived = {
29443
- targetObjectId: "",
29444
- sourceObjectId: "",
29445
- automaticMergeTreeId: "",
29446
- expectedConflictPaths: [],
29447
- resolutionScope: []
29448
- };
29449
- const admittedRequestPath = join26(runDirectory, "admitted-request.json");
29450
- const mergerInputPath = join26(runDirectory, "merger-input.json");
29451
- await writeFile7(
29452
- admittedRequestPath,
29453
- `${JSON.stringify(
29454
- {
29455
- role: "merger",
29456
- runId,
29457
- bookKey,
29458
- projectRoot,
29459
- instruction: options.instruction,
29460
- instructionEmpty: false,
29461
- mergerInputPath,
29462
- derived: emptyDerived,
29463
- attachments: [],
29464
- sessionDirectory,
29465
- sessionFile
29466
- },
29467
- null,
29468
- 2
29469
- )}
29470
- `,
29471
- "utf8"
29472
- );
29473
- return {
29474
- role: "merger",
29475
- runId,
29476
- bookKey,
29477
- projectRoot,
29478
- instruction: options.instruction,
29479
- instructionEmpty: false,
29480
- attachments: [],
29481
- runDirectory,
29482
- principal,
29483
- admittedRequestPath,
29484
- mergerInputPath,
29485
- derived: emptyDerived
29486
- };
29487
- }
29488
29404
  function mergerTurnOptions(admitted, env) {
29489
29405
  return {
29490
29406
  packageRoot: env.packageRoot,
@@ -29524,31 +29440,6 @@ async function runPublicMerger(argv, env, io, parseMergerArgv2) {
29524
29440
  presentStructuralRejection(error, io);
29525
29441
  return { exitCode: 2 };
29526
29442
  }
29527
- if (error instanceof MergerEnvelopeDerivationError) {
29528
- const shell = await admitMergerShellForActivationFailure({
29529
- home: env.home,
29530
- principalAuthority: env.principalAuthority,
29531
- cwd: env.cwd,
29532
- instruction: parsed.instruction,
29533
- ...parsed.project === void 0 ? {} : { project: parsed.project },
29534
- ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId }
29535
- });
29536
- await markRunAdmitted(shell, env.principalAuthority);
29537
- return await presentControlledFailure2(
29538
- shell,
29539
- {
29540
- timedOut: false,
29541
- code: null,
29542
- stderr: "",
29543
- thrown: error,
29544
- knownCause: "activation",
29545
- knownDiagnostic: error.message
29546
- },
29547
- mergerAdapters(env.packageRoot),
29548
- env.principalAuthority,
29549
- io
29550
- );
29551
- }
29552
29443
  throw error;
29553
29444
  }
29554
29445
  await markRunAdmitted(admitted, env.principalAuthority);
@@ -29653,10 +29544,8 @@ async function runPublicMergerResume(request, env, io) {
29653
29544
  var init_merger_run = __esm({
29654
29545
  "src/public-cli/merger-run.ts"() {
29655
29546
  "use strict";
29656
- init_activation_ledger_topology();
29657
29547
  init_engine_material();
29658
29548
  init_method_skill();
29659
- init_uuidv7();
29660
29549
  init_cli_errors();
29661
29550
  init_invocation();
29662
29551
  init_run_lifecycle();
@@ -29852,7 +29741,7 @@ var init_reviewer_run = __esm({
29852
29741
 
29853
29742
  // src/analyst-book-key.ts
29854
29743
  import { statSync as statSync2 } from "node:fs";
29855
- import { isAbsolute as isAbsolute8 } from "node:path";
29744
+ import { isAbsolute as isAbsolute9 } from "node:path";
29856
29745
  function resolveAnalystBookKey(projectRoot) {
29857
29746
  const identity = physicalPathIdentity(projectRoot);
29858
29747
  let stats;
@@ -29874,7 +29763,7 @@ function resolveAnalystBookKey(projectRoot) {
29874
29763
  }
29875
29764
  }
29876
29765
  function isSyntheticAnalystBookKey(bookKey) {
29877
- return bookKey.startsWith("root:") && isAbsolute8(bookKey.slice("root:".length));
29766
+ return bookKey.startsWith("root:") && isAbsolute9(bookKey.slice("root:".length));
29878
29767
  }
29879
29768
  var init_analyst_book_key = __esm({
29880
29769
  "src/analyst-book-key.ts"() {
@@ -29886,13 +29775,13 @@ var init_analyst_book_key = __esm({
29886
29775
 
29887
29776
  // src/atomic-write.ts
29888
29777
  import { randomUUID as randomUUID6 } from "node:crypto";
29889
- import { rename, rm, writeFile as writeFile8 } from "node:fs/promises";
29890
- import { dirname as dirname13, join as join27 } from "node:path";
29778
+ import { rename, rm, writeFile as writeFile7 } from "node:fs/promises";
29779
+ import { dirname as dirname13, join as join26 } from "node:path";
29891
29780
  async function writeFileAtomically(destination, contents) {
29892
29781
  const parent = dirname13(destination);
29893
- const temporary = join27(parent, `.atomic-write-${randomUUID6()}.tmp`);
29782
+ const temporary = join26(parent, `.atomic-write-${randomUUID6()}.tmp`);
29894
29783
  try {
29895
- await writeFile8(temporary, contents);
29784
+ await writeFile7(temporary, contents);
29896
29785
  await rename(temporary, destination);
29897
29786
  } catch (error) {
29898
29787
  await rm(temporary, { force: true }).catch(() => void 0);
@@ -29906,8 +29795,8 @@ var init_atomic_write = __esm({
29906
29795
  });
29907
29796
 
29908
29797
  // src/analyst-index.ts
29909
- import { open as open3, readFile as readFile17, unlink as unlink4 } from "node:fs/promises";
29910
- import { dirname as dirname14, join as join28 } from "node:path";
29798
+ import { open as open3, readFile as readFile18, unlink as unlink4 } from "node:fs/promises";
29799
+ import { dirname as dirname14, join as join27 } from "node:path";
29911
29800
  function sleep(ms) {
29912
29801
  return new Promise((resolve11) => {
29913
29802
  setTimeout(resolve11, ms);
@@ -29916,7 +29805,7 @@ function sleep(ms) {
29916
29805
  async function withAnalystLibraryIndexLock(ledgerHome, fn) {
29917
29806
  const indexPath = analystLibraryIndexPath(ledgerHome);
29918
29807
  ensureRealDirectoryTree(ledgerHome, dirname14(indexPath));
29919
- const lockPath = join28(dirname14(indexPath), LIBRARY_INDEX_LOCK_NAME);
29808
+ const lockPath = join27(dirname14(indexPath), LIBRARY_INDEX_LOCK_NAME);
29920
29809
  assertLedgerFileInsideHome(lockPath, ledgerHome);
29921
29810
  const startedAt = Date.now();
29922
29811
  while (true) {
@@ -29943,7 +29832,7 @@ async function withAnalystLibraryIndexLock(ledgerHome, fn) {
29943
29832
  }
29944
29833
  }
29945
29834
  function analystLibraryIndexPath(ledgerHome) {
29946
- return join28(ledgerHome, "analyst", "library-index.json");
29835
+ return join27(ledgerHome, "analyst", "library-index.json");
29947
29836
  }
29948
29837
  function rowFromIssueMetricsPage(page) {
29949
29838
  return {
@@ -30034,7 +29923,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
30034
29923
  const path = analystLibraryIndexPath(ledgerHome);
30035
29924
  let raw;
30036
29925
  try {
30037
- raw = await readFile17(path, "utf8");
29926
+ raw = await readFile18(path, "utf8");
30038
29927
  } catch (error) {
30039
29928
  if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
30040
29929
  return void 0;
@@ -30238,8 +30127,8 @@ var init_analyst_cohort = __esm({
30238
30127
  });
30239
30128
 
30240
30129
  // src/analyst-ledger.ts
30241
- import { readdir as readdir7, readFile as readFile18 } from "node:fs/promises";
30242
- import { join as join29 } from "node:path";
30130
+ import { readdir as readdir7, readFile as readFile19 } from "node:fs/promises";
30131
+ import { join as join28 } from "node:path";
30243
30132
  function isMissingPathError5(error) {
30244
30133
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
30245
30134
  }
@@ -30252,7 +30141,7 @@ function isRecord16(value) {
30252
30141
  async function readExistingRunLifecycleState(runDirectory) {
30253
30142
  try {
30254
30143
  const raw = JSON.parse(
30255
- await readFile18(join29(runDirectory, "run-state.json"), "utf8")
30144
+ await readFile19(join28(runDirectory, "run-state.json"), "utf8")
30256
30145
  );
30257
30146
  if (!isRecord16(raw) || typeof raw.state !== "string") return void 0;
30258
30147
  return raw.state;
@@ -30284,7 +30173,7 @@ async function listLedgerBookNames(booksRoot) {
30284
30173
  async function readInvocationScopeFields(runDirectory) {
30285
30174
  let raw;
30286
30175
  try {
30287
- raw = await readFile18(join29(runDirectory, "invocation.json"), "utf8");
30176
+ raw = await readFile19(join28(runDirectory, "invocation.json"), "utf8");
30288
30177
  } catch (error) {
30289
30178
  if (isMissingPathError5(error)) return void 0;
30290
30179
  throw error;
@@ -30316,7 +30205,7 @@ function decideIssueScope(input) {
30316
30205
  }
30317
30206
  async function resolveSessionFile(runDirectory) {
30318
30207
  try {
30319
- const raw = await readFile18(join29(runDirectory, "invocation.json"), "utf8");
30208
+ const raw = await readFile19(join28(runDirectory, "invocation.json"), "utf8");
30320
30209
  const parsed = JSON.parse(raw);
30321
30210
  if (isRecord16(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
30322
30211
  return parsed.sessionFile;
@@ -30324,7 +30213,7 @@ async function resolveSessionFile(runDirectory) {
30324
30213
  } catch (error) {
30325
30214
  if (!isMissingPathError5(error)) throw error;
30326
30215
  }
30327
- return join29(runDirectory, "session", "session.jsonl");
30216
+ return join28(runDirectory, "session", "session.jsonl");
30328
30217
  }
30329
30218
  function attributeSessionRowsForRun(input) {
30330
30219
  if (pathContainedIn(input.runDirectory, input.sessionFile)) {
@@ -30496,9 +30385,9 @@ async function classifyScopedRun(input) {
30496
30385
  }
30497
30386
  let gateCycles;
30498
30387
  try {
30499
- const parentSessionFile = join29(input.runDirectory, "session", "session.jsonl");
30388
+ const parentSessionFile = join28(input.runDirectory, "session", "session.jsonl");
30500
30389
  gateCycles = await readAnalystGateCyclesFromAuditorRoles(
30501
- join29(input.runDirectory, "session", "auditor-roles"),
30390
+ join28(input.runDirectory, "session", "auditor-roles"),
30502
30391
  { parentSessionFile }
30503
30392
  );
30504
30393
  } catch (error) {
@@ -30531,7 +30420,7 @@ async function classifyScopedRun(input) {
30531
30420
  async function scanAnalystIssueRuns(input) {
30532
30421
  const ledgerHome = resolveActivationLedgerHome(input.home);
30533
30422
  const scopeTicketNumber = input.ticketNumber;
30534
- const booksRoot = join29(ledgerHome, "books");
30423
+ const booksRoot = join28(ledgerHome, "books");
30535
30424
  let wholeBook = false;
30536
30425
  let scopeRootIdentity;
30537
30426
  let bookNames;
@@ -30563,7 +30452,7 @@ async function scanAnalystIssueRuns(input) {
30563
30452
  const unreadable = [];
30564
30453
  const scopeConflicts = [];
30565
30454
  for (const book of bookNames) {
30566
- const runsDir = join29(booksRoot, book, "runs");
30455
+ const runsDir = join28(booksRoot, book, "runs");
30567
30456
  let runNames;
30568
30457
  try {
30569
30458
  const entries = await readdir7(runsDir, { withFileTypes: true });
@@ -30575,7 +30464,7 @@ async function scanAnalystIssueRuns(input) {
30575
30464
  for (const runName of runNames) {
30576
30465
  const parsed = parseRunDirectoryName2(runName);
30577
30466
  if (parsed === void 0) continue;
30578
- const runDirectory = join29(runsDir, runName);
30467
+ const runDirectory = join28(runsDir, runName);
30579
30468
  let scopeFields;
30580
30469
  try {
30581
30470
  scopeFields = await readInvocationScopeFields(runDirectory);
@@ -31429,7 +31318,7 @@ var init_analyst_metric_family = __esm({
31429
31318
 
31430
31319
  // src/analyst-page.ts
31431
31320
  import { createHash as createHash5 } from "node:crypto";
31432
- import { dirname as dirname15, join as join30 } from "node:path";
31321
+ import { dirname as dirname15, join as join29 } from "node:path";
31433
31322
  function analystIssuePageKey(address) {
31434
31323
  const parts = ["book", address.bookKey];
31435
31324
  if (address.issueNumber !== void 0) {
@@ -31440,7 +31329,7 @@ function analystIssuePageKey(address) {
31440
31329
  return createHash5("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
31441
31330
  }
31442
31331
  function analystIssuePagePath(ledgerHome, address) {
31443
- return join30(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
31332
+ return join29(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
31444
31333
  }
31445
31334
  function analystIssuePageAddressFromPage(page) {
31446
31335
  return {
@@ -31576,7 +31465,7 @@ var init_analyst_page = __esm({
31576
31465
  });
31577
31466
 
31578
31467
  // src/analyst-entry.ts
31579
- import { readFile as readFile19 } from "node:fs/promises";
31468
+ import { readFile as readFile20 } from "node:fs/promises";
31580
31469
  function isMissingPathError6(error) {
31581
31470
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
31582
31471
  }
@@ -31606,7 +31495,7 @@ async function readOrComputeAnalystIssuePage(input, options) {
31606
31495
  ...issueNumber === void 0 && input.bookKey === void 0 ? { scopeRootIdentity: projectRoot } : {}
31607
31496
  });
31608
31497
  try {
31609
- const raw = await readFile19(pagePath, "utf8");
31498
+ const raw = await readFile20(pagePath, "utf8");
31610
31499
  const page = JSON.parse(raw);
31611
31500
  if (cachedPageMatchesRequestedScope(page, { bookKey, ...input })) {
31612
31501
  return { mode: "issue", page, pagePath };
@@ -31701,7 +31590,7 @@ async function runAnalystModelGroupsMode(input, home) {
31701
31590
  scopeRootIdentity: projectRoot
31702
31591
  });
31703
31592
  try {
31704
- const raw = await readFile19(pagePath, "utf8");
31593
+ const raw = await readFile20(pagePath, "utf8");
31705
31594
  JSON.parse(raw);
31706
31595
  } catch (error) {
31707
31596
  if (!isMissingPathError6(error)) {
@@ -31800,8 +31689,8 @@ var init_analyst_entry = __esm({
31800
31689
  });
31801
31690
 
31802
31691
  // src/public-cli/analyst-run.ts
31803
- import { readFile as readFile20 } from "node:fs/promises";
31804
- import { isAbsolute as isAbsolute9, resolve as resolve10 } from "node:path";
31692
+ import { readFile as readFile21 } from "node:fs/promises";
31693
+ import { isAbsolute as isAbsolute10, resolve as resolve10 } from "node:path";
31805
31694
  function resolveAnalystIssueBookKeyFromCwd(cwd = process.cwd()) {
31806
31695
  try {
31807
31696
  return resolveBookKeyFromGit(cwd);
@@ -31850,10 +31739,10 @@ async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
31850
31739
  );
31851
31740
  }
31852
31741
  const sourcePath = attachmentPaths[0];
31853
- const absolute = isAbsolute9(sourcePath) ? sourcePath : resolve10(sourcePath);
31742
+ const absolute = isAbsolute10(sourcePath) ? sourcePath : resolve10(sourcePath);
31854
31743
  let bytes;
31855
31744
  try {
31856
- bytes = await readFile20(absolute);
31745
+ bytes = await readFile21(absolute);
31857
31746
  } catch (error) {
31858
31747
  throw new CliUsageError(
31859
31748
  `analyst sweep attachment is not a readable regular file: ${sourcePath}`,
@@ -31973,7 +31862,7 @@ __export(cli_exports, {
31973
31862
  runAkRole: () => runAkRole
31974
31863
  });
31975
31864
  import { realpath as realpath6 } from "node:fs/promises";
31976
- import { join as join31 } from "node:path";
31865
+ import { join as join30 } from "node:path";
31977
31866
  function takePublicGlobalFlag(argv, index, options) {
31978
31867
  const tokens = argv.slice(index);
31979
31868
  const taken = options.takeDashed(tokens);
@@ -32019,23 +31908,15 @@ function resolveRoleTurnHost(env, options) {
32019
31908
  { name: "pi", create: () => ({ ok: true, host: piHost }) },
32020
31909
  ...packagedExternalHostNames().map((name) => ({
32021
31910
  name,
32022
- create: () => {
32023
- let hostPromise;
32024
- return {
32025
- ok: true,
32026
- host: {
32027
- executeTurn: async (request) => {
32028
- hostPromise ??= loadProductionExternalHostFactory(env.packageRoot, name).then(
32029
- (create) => create({
32030
- packageRoot: env.packageRoot,
32031
- principalAuthority: options.principalAuthority
32032
- })
32033
- );
32034
- return (await hostPromise).executeTurn(request);
32035
- }
32036
- }
32037
- };
32038
- }
31911
+ create: () => ({
31912
+ ok: true,
31913
+ // Factory loads outside the public bin static graph (ADR 0052 peer-free discovery).
31914
+ host: createLazyProductionExternalHost({
31915
+ packageRoot: env.packageRoot,
31916
+ hostName: name,
31917
+ principalAuthority: options.principalAuthority
31918
+ })
31919
+ })
32039
31920
  }))
32040
31921
  ];
32041
31922
  const hostName = options.seat.host;
@@ -32112,7 +31993,7 @@ function resolveHome(env) {
32112
31993
  return env.home ?? packageMachineHome();
32113
31994
  }
32114
31995
  function resolveAgentDir(env, home) {
32115
- return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join31(home, ".pi", "agent");
31996
+ return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join30(home, ".pi", "agent");
32116
31997
  }
32117
31998
  function parseThinking(value) {
32118
31999
  return value;
@@ -33077,7 +32958,7 @@ var init_cli = __esm({
33077
32958
 
33078
32959
  // src/public-cli/main.ts
33079
32960
  import { existsSync as existsSync8 } from "node:fs";
33080
- import { dirname as dirname16, join as join32 } from "node:path";
32961
+ import { dirname as dirname16, join as join31 } from "node:path";
33081
32962
  import { fileURLToPath as fileURLToPath2 } from "node:url";
33082
32963
 
33083
32964
  // src/public-cli/host-pi-runtime.ts
@@ -33166,8 +33047,8 @@ function linkPackage(packageRoot2, name, targetDir) {
33166
33047
  // src/public-cli/main.ts
33167
33048
  var here = dirname16(fileURLToPath2(import.meta.url));
33168
33049
  function resolvePackageRoot(binDir) {
33169
- const canonical = join32(binDir, "..", "..");
33170
- if (existsSync8(join32(canonical, "package.json"))) {
33050
+ const canonical = join31(binDir, "..", "..");
33051
+ if (existsSync8(join31(canonical, "package.json"))) {
33171
33052
  return canonical;
33172
33053
  }
33173
33054
  return binDir;