@akagilnc/pi-workflow-roles 0.1.3873 → 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.
@@ -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
 
@@ -16366,7 +16324,7 @@ var init_sitian_contracts = __esm({
16366
16324
  });
16367
16325
 
16368
16326
  // src/sitian-appender.ts
16369
- import { createHash as createHash2, randomUUID } from "node:crypto";
16327
+ import { createHash, randomUUID } from "node:crypto";
16370
16328
  import {
16371
16329
  appendFileSync,
16372
16330
  existsSync as existsSync5,
@@ -16382,7 +16340,7 @@ function errorCodeOf(error) {
16382
16340
  return error.code;
16383
16341
  }
16384
16342
  function identityClaimPath(recordFile, identity) {
16385
- const digest = createHash2("sha256").update(identity, "utf8").digest("hex");
16343
+ const digest = createHash("sha256").update(identity, "utf8").digest("hex");
16386
16344
  return `${recordFile}.id-${digest}`;
16387
16345
  }
16388
16346
  function createExclusiveFile(path, contents) {
@@ -16526,7 +16484,7 @@ function resolveSitianRecordPathInLedger(input, ledgerHome) {
16526
16484
  } else {
16527
16485
  subjectStr = JSON.stringify(input.subject);
16528
16486
  }
16529
- const digest = createHash2("sha256").update(subjectStr).digest("hex").slice(0, 32);
16487
+ const digest = createHash("sha256").update(subjectStr).digest("hex").slice(0, 32);
16530
16488
  sessionDir = join9(bookDir, category, digest);
16531
16489
  } else {
16532
16490
  sessionDir = join9(bookDir, category);
@@ -16981,6 +16939,17 @@ var init_run_ticket_number = __esm({
16981
16939
  }
16982
16940
  });
16983
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
+
16984
16953
  // src/readable-gate-item.ts
16985
16954
  var init_readable_gate_item = __esm({
16986
16955
  "src/readable-gate-item.ts"() {
@@ -17756,8 +17725,23 @@ var init_collector_target = __esm({
17756
17725
  }
17757
17726
  });
17758
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
+
17759
17740
  // src/merger-git-state.ts
17760
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";
17761
17745
  import { promisify as promisify2 } from "node:util";
17762
17746
  async function git(cwd, args) {
17763
17747
  const { stdout } = await execFileAsync2("git", args, { cwd, encoding: "buffer", maxBuffer: 16 * 1024 * 1024 });
@@ -17768,10 +17752,31 @@ function line(bytes, label) {
17768
17752
  if (!value) throw new Error(`${label} is empty`);
17769
17753
  return value;
17770
17754
  }
17771
- function nulPaths(bytes, label) {
17772
- const raw = exactUtf8(bytes, label);
17773
- if (raw.length > 0 && !raw.endsWith("\0")) throw new Error(`${label} is not NUL terminated`);
17774
- 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;
17775
17780
  }
17776
17781
  async function unmerged(cwd) {
17777
17782
  const raw = exactUtf8(await git(cwd, ["ls-files", "-u", "-z"]), "Git unmerged index");
@@ -17784,40 +17789,39 @@ async function unmerged(cwd) {
17784
17789
  }
17785
17790
  return [...paths].sort((a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b)));
17786
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
+ }
17787
17803
  function createProductionMergerGitState(repositoryRoot = process.cwd()) {
17788
17804
  return {
17789
17805
  async activeMerge() {
17790
- const targetObjectId = line(await git(repositoryRoot, ["rev-parse", "--verify", "HEAD"]), "Git HEAD");
17791
- let mergeHeadRaw;
17792
- try {
17793
- mergeHeadRaw = await git(repositoryRoot, ["rev-parse", "--verify", "MERGE_HEAD"]);
17794
- } catch {
17795
- throw new Error("Assigned repository does not have one ordinary in-progress merge");
17796
- }
17797
- const mergeHeads = exactUtf8(mergeHeadRaw, "Git MERGE_HEAD").trim().split(/\r?\n/).filter(Boolean);
17798
- 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");
17799
- let automaticMergeTreeRaw;
17800
- try {
17801
- automaticMergeTreeRaw = await git(repositoryRoot, ["rev-parse", "--verify", "AUTO_MERGE^{tree}"]);
17802
- } catch {
17803
- 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;
17804
17823
  }
17805
- const automaticMergeTreeId = line(automaticMergeTreeRaw, "Git automatic merge tree");
17806
- if (!isFullGitObjectId(automaticMergeTreeId) || automaticMergeTreeId.length !== targetObjectId.length) throw new Error("Git automatic merge tree identity is unavailable or invalid");
17807
- return { targetObjectId, sourceObjectId: mergeHeads[0], unmergedPaths: await unmerged(repositoryRoot), automaticMergeTreeId };
17808
- },
17809
- async completedMerge(mergeCommitId, automaticMergeTreeId) {
17810
- if (!isFullGitObjectId(mergeCommitId) || !isFullGitObjectId(automaticMergeTreeId) || mergeCommitId.length !== automaticMergeTreeId.length) throw new Error("Merger completion object ID is invalid");
17811
- const identity = exactUtf8(await git(repositoryRoot, ["show", "-s", "--format=%H%x00%P", mergeCommitId]), "Git merge commit").trimEnd().split("\0");
17812
- if (identity.length !== 2 || identity[0] !== mergeCommitId) throw new Error("Git merge completion identity drifted");
17813
- const parentObjectIds = identity[1].split(" ").filter(Boolean);
17814
- const currentHead = line(await git(repositoryRoot, ["rev-parse", "--verify", "HEAD"]), "Git HEAD");
17815
- const status = await git(repositoryRoot, ["status", "--porcelain=v1", "-z", "--untracked-files=all"]);
17816
- const frozenTree = line(await git(repositoryRoot, ["rev-parse", "--verify", `${automaticMergeTreeId}^{tree}`]), "Git frozen automatic merge tree");
17817
- if (frozenTree !== automaticMergeTreeId) throw new Error("Git frozen automatic merge tree identity drifted");
17818
- const mergeTree = line(await git(repositoryRoot, ["rev-parse", "--verify", `${mergeCommitId}^{tree}`]), "Git completed merge tree");
17819
- const resolutionChangedPaths = nulPaths(await git(repositoryRoot, ["diff-tree", "--no-commit-id", "--name-only", "-r", "-z", "--no-renames", automaticMergeTreeId, mergeTree]), "Git resolution path delta");
17820
- return { mergeCommitId: currentHead, parentObjectIds, unmergedPaths: await unmerged(repositoryRoot), worktreeClean: status.byteLength === 0 && currentHead === mergeCommitId, resolutionChangedPaths };
17824
+ return { targetObjectId, sourceObjectId, unmergedPaths: await unmerged(repositoryRoot) };
17821
17825
  }
17822
17826
  };
17823
17827
  }
@@ -17857,7 +17861,7 @@ var init_uuidv7 = __esm({
17857
17861
  });
17858
17862
 
17859
17863
  // src/typed-provider-http.ts
17860
- 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";
17861
17865
  import { join as join12 } from "node:path";
17862
17866
  function typedProviderHttpPath(runDirectory) {
17863
17867
  return join12(runDirectory, TYPED_HTTP_FILE);
@@ -17875,7 +17879,7 @@ async function clearTypedProviderHttpObservation(runDirectory) {
17875
17879
  async function readLatestTypedProviderHttpObservation(runDirectory) {
17876
17880
  let text;
17877
17881
  try {
17878
- text = await readFile7(typedProviderHttpPath(runDirectory), "utf8");
17882
+ text = await readFile8(typedProviderHttpPath(runDirectory), "utf8");
17879
17883
  } catch (error) {
17880
17884
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
17881
17885
  return void 0;
@@ -17904,8 +17908,8 @@ var init_typed_provider_http = __esm({
17904
17908
  });
17905
17909
 
17906
17910
  // src/public-cli/run-lifecycle.ts
17907
- import { chmod, open, readdir as readdir2, readFile as readFile8, unlink as unlink2, writeFile as writeFile3 } from "node:fs/promises";
17908
- 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";
17909
17913
  function resumeRereadInstruction(materialPath, handbook) {
17910
17914
  return handbook ? `\u91CD\u65B0\u8BFB ${materialPath}\uFF0C\u518D\u7EC4\u88C5\u5916\u5305 argv` : `\u91CD\u65B0\u8BFB ${materialPath}`;
17911
17915
  }
@@ -17917,7 +17921,7 @@ function instructResumeHandbookRead(prompt, engineMaterial) {
17917
17921
  if (handbookPath !== void 0 && value === handbookPath) {
17918
17922
  return resumeRereadInstruction(handbookPath, true);
17919
17923
  }
17920
- if (isAbsolute4(value)) return resumeRereadInstruction(value, false);
17924
+ if (isAbsolute5(value)) return resumeRereadInstruction(value, false);
17921
17925
  return line2;
17922
17926
  }).join("\n");
17923
17927
  }
@@ -18003,7 +18007,7 @@ function parseCurrentCourtState(raw) {
18003
18007
  async function readRoleRunStateDisk(runDirectory) {
18004
18008
  let raw;
18005
18009
  try {
18006
- raw = JSON.parse(await readFile8(join13(runDirectory, RUN_STATE_FILE), "utf8"));
18010
+ raw = JSON.parse(await readFile9(join13(runDirectory, RUN_STATE_FILE), "utf8"));
18007
18011
  } catch {
18008
18012
  return void 0;
18009
18013
  }
@@ -18235,7 +18239,7 @@ function isProcessAlive(pid) {
18235
18239
  async function autopsyWriterLock(lockPath) {
18236
18240
  let content;
18237
18241
  try {
18238
- content = await readFile8(lockPath, "utf8");
18242
+ content = await readFile9(lockPath, "utf8");
18239
18243
  } catch (error) {
18240
18244
  if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
18241
18245
  return { verdict: "absent", readFailure: error };
@@ -18404,7 +18408,7 @@ async function readRunParentPath(runDirectory) {
18404
18408
  let raw;
18405
18409
  try {
18406
18410
  raw = JSON.parse(
18407
- await readFile8(join13(runDirectory, "admitted-request.json"), "utf8")
18411
+ await readFile9(join13(runDirectory, "admitted-request.json"), "utf8")
18408
18412
  );
18409
18413
  } catch (error) {
18410
18414
  if (errorCodeOf2(error) === "ENOENT") return void 0;
@@ -18515,7 +18519,7 @@ async function loadResumableRunRecord(home, runId, authority) {
18515
18519
  let sourceRun;
18516
18520
  try {
18517
18521
  const raw = JSON.parse(
18518
- await readFile8(run.admittedRequestPath, "utf8")
18522
+ await readFile9(run.admittedRequestPath, "utf8")
18519
18523
  );
18520
18524
  if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
18521
18525
  const record4 = raw;
@@ -18606,11 +18610,10 @@ async function loadResumableRunRecord(home, runId, authority) {
18606
18610
  }
18607
18611
  if (record4.derived !== null && typeof record4.derived === "object" && !Array.isArray(record4.derived)) {
18608
18612
  const d = record4.derived;
18609
- 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")) {
18610
18614
  derived = {
18611
18615
  targetObjectId: d.targetObjectId,
18612
18616
  sourceObjectId: d.sourceObjectId,
18613
- automaticMergeTreeId: d.automaticMergeTreeId,
18614
18617
  expectedConflictPaths: d.expectedConflictPaths,
18615
18618
  resolutionScope: d.resolutionScope
18616
18619
  };
@@ -18630,7 +18633,7 @@ async function loadResumableRunRecord(home, runId, authority) {
18630
18633
  let model;
18631
18634
  try {
18632
18635
  const invocationRaw = JSON.parse(
18633
- await readFile8(join13(run.runDirectory, "invocation.json"), "utf8")
18636
+ await readFile9(join13(run.runDirectory, "invocation.json"), "utf8")
18634
18637
  );
18635
18638
  if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
18636
18639
  const rec = invocationRaw;
@@ -19040,7 +19043,7 @@ __export(notary_source_run_exports, {
19040
19043
  loadNotarySourceRunLocator: () => loadNotarySourceRunLocator,
19041
19044
  resolveNotarySourceRunLocator: () => resolveNotarySourceRunLocator
19042
19045
  });
19043
- 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";
19044
19047
  import { lstat as lstat2, realpath as realpath3 } from "node:fs/promises";
19045
19048
  function parseRunDirectoryName(name) {
19046
19049
  const match = RUN_DIR_NAME.exec(name);
@@ -19092,7 +19095,7 @@ async function resolveNotarySourceRunLocator(options) {
19092
19095
  if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
19093
19096
  candidate = join14(bookRunsRoot, `${bare.runId}@${bare.role}`);
19094
19097
  } else {
19095
- candidate = isAbsolute5(raw) ? raw : resolve6(options.projectRoot, raw);
19098
+ candidate = isAbsolute6(raw) ? raw : resolve7(options.projectRoot, raw);
19096
19099
  }
19097
19100
  const real = await requireRunDirectory(candidate, raw);
19098
19101
  const identity = parseRunDirectoryName(basename5(real));
@@ -19832,7 +19835,7 @@ var init_option_definitions = __esm({
19832
19835
  }
19833
19836
  ];
19834
19837
  MERGER_OPTIONS = [
19835
- // Merger project face differs: requires an in-progress ordinary merge root.
19838
+ // Merger project face: worktree whose Git materials are handed to the role.
19836
19839
  {
19837
19840
  id: "project",
19838
19841
  owner: "merger",
@@ -19843,8 +19846,8 @@ var init_option_definitions = __esm({
19843
19846
  repeatable: false,
19844
19847
  form: "option",
19845
19848
  description: {
19846
- en: "Project root with one ordinary in-progress merge (defaults to cwd).",
19847
- 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"
19848
19851
  }
19849
19852
  },
19850
19853
  bindOwner("merger", SHARED_ATTACH_SEMANTICS)
@@ -20086,10 +20089,10 @@ var init_option_definitions = __esm({
20086
20089
  },
20087
20090
  merger: {
20088
20091
  command: "merger",
20089
- summary: "Resolve one ordinary merge already in conflict.",
20092
+ summary: "Reconcile merge materials in a worktree (escalate when nothing to merge).",
20090
20093
  usage: ["ak-role merger [options] <instruction>"],
20091
20094
  examples: [
20092
- 'ak-role merger --project /path/to/worktree "Reconcile the active merge."'
20095
+ 'ak-role merger --project /path/to/worktree "Reconcile the merge."'
20093
20096
  ]
20094
20097
  },
20095
20098
  inspector: {
@@ -20226,11 +20229,11 @@ import { execFileSync as execFileSync3 } from "node:child_process";
20226
20229
  import {
20227
20230
  lstat as lstat3,
20228
20231
  mkdir as mkdir2,
20229
- readFile as readFile9,
20232
+ readFile as readFile10,
20230
20233
  realpath as realpath4,
20231
20234
  writeFile as writeFile4
20232
20235
  } from "node:fs/promises";
20233
- 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";
20234
20237
  function issueAdmissionPlacement(authority, request) {
20235
20238
  const principal = authority.issue(request);
20236
20239
  const { sessionDirectory, sessionFile } = authority.decode(principal);
@@ -20290,7 +20293,7 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
20290
20293
  }
20291
20294
  async function recordEffectiveInvocationModel(runDirectory, model, engine, host) {
20292
20295
  const ledgerPath = join15(runDirectory, "invocation.json");
20293
- const current = JSON.parse(await readFile9(ledgerPath, "utf8"));
20296
+ const current = JSON.parse(await readFile10(ledgerPath, "utf8"));
20294
20297
  const next = { ...current };
20295
20298
  if (model !== void 0) {
20296
20299
  next.provider = model.provider;
@@ -20318,7 +20321,7 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host)
20318
20321
  }
20319
20322
  async function mergeInvocationIdentityPage(runDirectory, fields) {
20320
20323
  const ledgerPath = join15(runDirectory, "invocation.json");
20321
- const current = JSON.parse(await readFile9(ledgerPath, "utf8"));
20324
+ const current = JSON.parse(await readFile10(ledgerPath, "utf8"));
20322
20325
  await writeFile4(
20323
20326
  ledgerPath,
20324
20327
  `${JSON.stringify({
@@ -20334,7 +20337,7 @@ async function persistAdmittedSourceRunPath(admitted, sourceRunPath) {
20334
20337
  throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
20335
20338
  }
20336
20339
  const admittedPath = admitted.admittedRequestPath;
20337
- const current = JSON.parse(await readFile9(admittedPath, "utf8"));
20340
+ const current = JSON.parse(await readFile10(admittedPath, "utf8"));
20338
20341
  if (typeof current.sourceRunPath === "string") {
20339
20342
  if (current.sourceRunPath === sourceRunPath) return;
20340
20343
  throw new Error(
@@ -20361,7 +20364,7 @@ async function bindAdmittedTicketNumber(admitted, ticketNumber) {
20361
20364
  admitted.ticketNumber = ticketNumber;
20362
20365
  await mergeInvocationIdentityPage(admitted.runDirectory, { ticketNumber });
20363
20366
  const admittedPath = admitted.admittedRequestPath;
20364
- const current = JSON.parse(await readFile9(admittedPath, "utf8"));
20367
+ const current = JSON.parse(await readFile10(admittedPath, "utf8"));
20365
20368
  await writeFile4(
20366
20369
  admittedPath,
20367
20370
  `${JSON.stringify({ ...current, ticketNumber }, null, 2)}
@@ -20378,7 +20381,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
20378
20381
  async function observeLaunchedRolePackageIdentity(packageRoot2, selectedRoleEntry) {
20379
20382
  const rolePackageRoot = packageRoot2;
20380
20383
  const raw = JSON.parse(
20381
- await readFile9(join15(rolePackageRoot, "package.json"), "utf8")
20384
+ await readFile10(join15(rolePackageRoot, "package.json"), "utf8")
20382
20385
  );
20383
20386
  if (typeof raw.version !== "string" || raw.version.trim() === "") {
20384
20387
  throw new Error(
@@ -20608,7 +20611,7 @@ function parseFixerArgv(args) {
20608
20611
  };
20609
20612
  }
20610
20613
  async function freezeRegularFileAttachment(sourcePath, destinationDir, index) {
20611
- const absolute = isAbsolute6(sourcePath) ? sourcePath : resolve7(sourcePath);
20614
+ const absolute = isAbsolute7(sourcePath) ? sourcePath : resolve8(sourcePath);
20612
20615
  let st;
20613
20616
  try {
20614
20617
  st = await lstat3(absolute);
@@ -20623,7 +20626,7 @@ async function freezeRegularFileAttachment(sourcePath, destinationDir, index) {
20623
20626
  `attachment must be a regular file (not a directory or symlink): ${sourcePath}`
20624
20627
  );
20625
20628
  }
20626
- const bytes = await readFile9(absolute);
20629
+ const bytes = await readFile10(absolute);
20627
20630
  const name = `${String(index).padStart(2, "0")}-${basename6(absolute)}`;
20628
20631
  const frozenPath = join15(destinationDir, name);
20629
20632
  await writeFile4(frozenPath, bytes);
@@ -20664,7 +20667,7 @@ async function admitStandardMaterialInvocation(role, options) {
20664
20667
  if (options.project !== void 0) {
20665
20668
  requireOptionPath("--project", options.project);
20666
20669
  }
20667
- const projectRoot = resolve7(options.project ?? options.cwd);
20670
+ const projectRoot = resolve8(options.project ?? options.cwd);
20668
20671
  const runId = (options.createRunId ?? uuidv7)();
20669
20672
  const {
20670
20673
  principal,
@@ -20767,7 +20770,7 @@ async function admitCountersignInvocation(options) {
20767
20770
  if (options.project !== void 0) {
20768
20771
  requireOptionPath("--project", options.project);
20769
20772
  }
20770
- const projectRoot = resolve7(options.project ?? options.cwd);
20773
+ const projectRoot = resolve8(options.project ?? options.cwd);
20771
20774
  const runId = (options.createRunId ?? uuidv7)();
20772
20775
  const {
20773
20776
  principal,
@@ -20847,7 +20850,7 @@ async function admitCoderInvocation(options) {
20847
20850
  if (options.phase !== "plan" && options.phase !== "apply") {
20848
20851
  throw new CliUsageError("coder phase must be plan or apply");
20849
20852
  }
20850
- const projectRoot = resolve7(options.project ?? options.cwd);
20853
+ const projectRoot = resolve8(options.project ?? options.cwd);
20851
20854
  const runId = (options.createRunId ?? uuidv7)();
20852
20855
  const {
20853
20856
  principal,
@@ -20935,9 +20938,9 @@ async function admitFixerInvocation(options) {
20935
20938
  let prerequisites = Object.freeze([]);
20936
20939
  let prerequisitesSource;
20937
20940
  if (options.prerequisitesPath !== void 0) {
20938
- const absolutePrereq = isAbsolute6(options.prerequisitesPath) ? options.prerequisitesPath : resolve7(options.prerequisitesPath);
20941
+ const absolutePrereq = isAbsolute7(options.prerequisitesPath) ? options.prerequisitesPath : resolve8(options.prerequisitesPath);
20939
20942
  try {
20940
- prerequisitesSource = await readFile9(absolutePrereq, "utf8");
20943
+ prerequisitesSource = await readFile10(absolutePrereq, "utf8");
20941
20944
  } catch (error) {
20942
20945
  throw new CliUsageError(
20943
20946
  `fixer prerequisites path is unreadable: ${options.prerequisitesPath}`,
@@ -20953,7 +20956,7 @@ async function admitFixerInvocation(options) {
20953
20956
  throw error;
20954
20957
  }
20955
20958
  }
20956
- const projectRoot = resolve7(options.project ?? options.cwd);
20959
+ const projectRoot = resolve8(options.project ?? options.cwd);
20957
20960
  const runId = (options.createRunId ?? uuidv7)();
20958
20961
  const {
20959
20962
  principal,
@@ -21178,7 +21181,7 @@ async function admitCollectorInvocation(options) {
21178
21181
  throw new CliUsageError(detail, { cause: error });
21179
21182
  }
21180
21183
  }
21181
- const projectRoot = resolve7(options.project ?? options.cwd);
21184
+ const projectRoot = resolve8(options.project ?? options.cwd);
21182
21185
  let repository;
21183
21186
  if (options.repo !== void 0) {
21184
21187
  try {
@@ -21366,12 +21369,12 @@ async function resolveDoctorCaseRunsPath(options) {
21366
21369
  if (raw === "") {
21367
21370
  throw new CliUsageError("doctor --runs requires a path");
21368
21371
  }
21369
- if (isAbsolute6(raw)) {
21372
+ if (isAbsolute7(raw)) {
21370
21373
  throw new CliUsageError(
21371
21374
  "doctor --runs must be a project-relative path"
21372
21375
  );
21373
21376
  }
21374
- const resolved = resolve7(options.projectRoot, raw);
21377
+ const resolved = resolve8(options.projectRoot, raw);
21375
21378
  if (resolved !== options.projectRoot && !pathContainedIn(options.projectRoot, resolved)) {
21376
21379
  throw new CliUsageError(
21377
21380
  "doctor --runs escapes the project root"
@@ -21410,7 +21413,7 @@ async function admitDoctorInvocation(options) {
21410
21413
  `doctor --issue must be a positive integer, got ${options.issueNumber}`
21411
21414
  );
21412
21415
  }
21413
- const projectRoot = resolve7(options.project ?? options.cwd);
21416
+ const projectRoot = resolve8(options.project ?? options.cwd);
21414
21417
  const runId = (options.createRunId ?? uuidv7)();
21415
21418
  const {
21416
21419
  principal,
@@ -21571,7 +21574,7 @@ async function admitNotaryInvocation(options) {
21571
21574
  if (options.project !== void 0) {
21572
21575
  requireOptionPath("--project", options.project);
21573
21576
  }
21574
- const projectRoot = resolve7(options.project ?? options.cwd);
21577
+ const projectRoot = resolve8(options.project ?? options.cwd);
21575
21578
  let sourceRun;
21576
21579
  try {
21577
21580
  sourceRun = await resolveNotarySourceRunLocator({
@@ -21689,7 +21692,7 @@ async function admitGleanerLeftInvocation(options) {
21689
21692
  if (options.baseRevision.trim() === "") {
21690
21693
  throw new CliUsageError("--base requires a nonempty revision");
21691
21694
  }
21692
- const projectRoot = resolve7(options.project ?? options.cwd);
21695
+ const projectRoot = resolve8(options.project ?? options.cwd);
21693
21696
  const runId = (options.createRunId ?? uuidv7)();
21694
21697
  const {
21695
21698
  principal,
@@ -21810,7 +21813,7 @@ async function admitReviewerInvocation(options) {
21810
21813
  const authorityRefs = Object.freeze(
21811
21814
  (options.authorityRefs ?? []).map((ref) => requireAuthorityRef(ref))
21812
21815
  );
21813
- const projectRoot = resolve7(options.project ?? options.cwd);
21816
+ const projectRoot = resolve8(options.project ?? options.cwd);
21814
21817
  const runId = (options.createRunId ?? uuidv7)();
21815
21818
  const {
21816
21819
  principal,
@@ -21905,7 +21908,7 @@ function parseMergerArgv(args) {
21905
21908
  const token = tokens.shift();
21906
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=")) {
21907
21910
  throw new CliUsageError(
21908
- "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"
21909
21912
  );
21910
21913
  }
21911
21914
  if (token.startsWith("-") && token !== "-") {
@@ -21928,24 +21931,12 @@ function mergerMaterialFromUtf8(text) {
21928
21931
  });
21929
21932
  }
21930
21933
  async function deriveMergerEnvelopeFromActiveMerge(projectRoot, gitState = createProductionMergerGitState(projectRoot)) {
21931
- let state;
21932
- try {
21933
- state = await gitState.activeMerge();
21934
- } catch (error) {
21935
- const message = error instanceof Error && error.message.trim() !== "" ? error.message : "Assigned repository does not have one ordinary in-progress merge";
21936
- throw new MergerEnvelopeDerivationError(message, { cause: error });
21937
- }
21938
- if (state.unmergedPaths.length === 0) {
21939
- throw new MergerEnvelopeDerivationError(
21940
- "Assigned repository does not have one ordinary in-progress merge with a complete conflict set"
21941
- );
21942
- }
21934
+ const state = await gitState.activeMerge();
21943
21935
  const expectedConflictPaths = Object.freeze([...state.unmergedPaths]);
21944
21936
  const resolutionScope = Object.freeze([...state.unmergedPaths]);
21945
21937
  return Object.freeze({
21946
21938
  targetObjectId: state.targetObjectId,
21947
21939
  sourceObjectId: state.sourceObjectId,
21948
- automaticMergeTreeId: state.automaticMergeTreeId,
21949
21940
  expectedConflictPaths,
21950
21941
  resolutionScope
21951
21942
  });
@@ -21958,7 +21949,7 @@ async function admitMergerInvocation(options) {
21958
21949
  if (instruction.trim() === "") {
21959
21950
  throw new CliUsageError("merger requires a nonblank task instruction");
21960
21951
  }
21961
- const projectRoot = resolve7(options.project ?? options.cwd);
21952
+ const projectRoot = resolve8(options.project ?? options.cwd);
21962
21953
  const derived = await deriveMergerEnvelopeFromActiveMerge(
21963
21954
  projectRoot,
21964
21955
  options.gitState ?? createProductionMergerGitState(projectRoot)
@@ -21981,16 +21972,17 @@ async function admitMergerInvocation(options) {
21981
21972
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
21982
21973
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
21983
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;
21984
21977
  const targetIntent = mergerMaterialFromUtf8(
21985
- `Investigate primary sources for target parent ${derived.targetObjectId}. Do not invent intent.`
21978
+ `Investigate primary sources for target parent ${targetLabel}. Do not invent intent.`
21986
21979
  );
21987
21980
  const sourceIntent = mergerMaterialFromUtf8(
21988
- `Investigate primary sources for source parent ${derived.sourceObjectId}. Do not invent intent.`
21981
+ `Investigate primary sources for source parent ${sourceLabel}. Do not invent intent.`
21989
21982
  );
21990
21983
  const taskMaterial = mergerMaterialFromUtf8(instruction);
21991
21984
  const authorityMaterial = mergerMaterialFromUtf8(instruction);
21992
21985
  const mergerInput = validateMergerInput({
21993
- version: 1,
21994
21986
  attemptId: runId,
21995
21987
  targetObjectId: derived.targetObjectId,
21996
21988
  sourceObjectId: derived.sourceObjectId,
@@ -22002,7 +21994,6 @@ async function admitMergerInvocation(options) {
22002
21994
  },
22003
21995
  expectedConflictPaths: [...derived.expectedConflictPaths],
22004
21996
  resolutionScope: [...derived.resolutionScope],
22005
- // Authorized checks remain available on the assignment; default none.
22006
21997
  authorizedChecks: []
22007
21998
  });
22008
21999
  const mergerInputPath = join15(runDirectory, "merger-input.json");
@@ -22025,7 +22016,6 @@ async function admitMergerInvocation(options) {
22025
22016
  derived: {
22026
22017
  targetObjectId: derived.targetObjectId,
22027
22018
  sourceObjectId: derived.sourceObjectId,
22028
- automaticMergeTreeId: derived.automaticMergeTreeId,
22029
22019
  expectedConflictPaths: [...derived.expectedConflictPaths],
22030
22020
  resolutionScope: [...derived.resolutionScope]
22031
22021
  },
@@ -22289,7 +22279,7 @@ function parseAnalystArgv(args) {
22289
22279
  ...ticketRaw === void 0 ? {} : { ticket: parseAnalystTicketNumber(ticketRaw) }
22290
22280
  };
22291
22281
  }
22292
- 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;
22293
22283
  var init_invocation = __esm({
22294
22284
  "src/public-cli/invocation.ts"() {
22295
22285
  "use strict";
@@ -22310,15 +22300,6 @@ var init_invocation = __esm({
22310
22300
  init_engine_material();
22311
22301
  init_cli_errors();
22312
22302
  init_option_definitions();
22313
- MergerEnvelopeDerivationError = class extends Error {
22314
- code = "merger-envelope-derivation";
22315
- /** Typed cause for #107 classifyPostAdmissionFailure (isTypedActivationError). */
22316
- knownCause = "activation";
22317
- constructor(message, options) {
22318
- super(message, options);
22319
- this.name = "MergerEnvelopeDerivationError";
22320
- }
22321
- };
22322
22303
  DOCTOR_ISSUE_NUMBER_PATTERN = /^[1-9]\d*$/;
22323
22304
  DOCTOR_CASE_RUNS_PATH_PATTERN = /\/\.ak-roles\/books\/[^/]+\/issues\/([1-9]\d*)\/runs$/;
22324
22305
  ANALYST_TICKET_NUMBER_PATTERN = /^[1-9]\d*$/;
@@ -22327,7 +22308,7 @@ var init_invocation = __esm({
22327
22308
 
22328
22309
  // src/package-resources/method-skill.ts
22329
22310
  import { createHash as createHash4 } from "node:crypto";
22330
- import { readFile as readFile10, realpath as realpath5 } from "node:fs/promises";
22311
+ import { readFile as readFile11, realpath as realpath5 } from "node:fs/promises";
22331
22312
  import { join as join16 } from "node:path";
22332
22313
  function gitBlobOid(bytes) {
22333
22314
  const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
@@ -22446,7 +22427,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
22446
22427
  const provenancePath = join16(rootDirectory, "provenance.json");
22447
22428
  let provenanceRaw;
22448
22429
  try {
22449
- provenanceRaw = await readFile10(provenancePath, "utf8");
22430
+ provenanceRaw = await readFile11(provenancePath, "utf8");
22450
22431
  } catch (error) {
22451
22432
  throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
22452
22433
  }
@@ -22463,7 +22444,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
22463
22444
  const absolute = join16(rootDirectory, rel);
22464
22445
  let bytes;
22465
22446
  try {
22466
- bytes = await readFile10(absolute);
22447
+ bytes = await readFile11(absolute);
22467
22448
  } catch (error) {
22468
22449
  throw new PackagedMethodSkillUnavailableError(name, absolute, error);
22469
22450
  }
@@ -22479,7 +22460,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
22479
22460
  let raw;
22480
22461
  try {
22481
22462
  skillPath = await realpath5(skillPathConfigured);
22482
- raw = await readFile10(skillPath, "utf8");
22463
+ raw = await readFile11(skillPath, "utf8");
22483
22464
  } catch (error) {
22484
22465
  throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
22485
22466
  }
@@ -22582,12 +22563,12 @@ var init_compliance_transport = __esm({
22582
22563
  });
22583
22564
 
22584
22565
  // src/ledger-session-read.ts
22585
- import { readFile as readFile11 } from "node:fs/promises";
22566
+ import { readFile as readFile12 } from "node:fs/promises";
22586
22567
  function isRecord11(value) {
22587
22568
  return typeof value === "object" && value !== null && !Array.isArray(value);
22588
22569
  }
22589
22570
  async function readLedgerSessionJsonl(path) {
22590
- const text = await readFile11(path, "utf8");
22571
+ const text = await readFile12(path, "utf8");
22591
22572
  const lines = text.split("\n");
22592
22573
  const rows = [];
22593
22574
  for (let index = 0; index < lines.length; index += 1) {
@@ -22989,10 +22970,10 @@ function pairGateRounds(volumes) {
22989
22970
  return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
22990
22971
  }
22991
22972
  async function resolveOfficerSessionFromPointerFile(pointerPath) {
22992
- const { readFile: readFile21 } = await import("node:fs/promises");
22973
+ const { readFile: readFile22 } = await import("node:fs/promises");
22993
22974
  let raw;
22994
22975
  try {
22995
- raw = JSON.parse(await readFile21(pointerPath, "utf8"));
22976
+ raw = JSON.parse(await readFile22(pointerPath, "utf8"));
22996
22977
  } catch (error) {
22997
22978
  throw new Error(
22998
22979
  `direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
@@ -23066,7 +23047,7 @@ var init_analyst_gate_cycles_read = __esm({
23066
23047
  });
23067
23048
 
23068
23049
  // src/run-terminal-artifacts.ts
23069
- import { readdir as readdir4, readFile as readFile12 } from "node:fs/promises";
23050
+ import { readdir as readdir4, readFile as readFile13 } from "node:fs/promises";
23070
23051
  import { basename as basename7, dirname as dirname9, join as join18 } from "node:path";
23071
23052
  function isMissingPathError2(error) {
23072
23053
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
@@ -23098,7 +23079,7 @@ function readUsableTerminalArtifactBody(body) {
23098
23079
  async function readTerminalArtifactAtPath(path, file) {
23099
23080
  let raw;
23100
23081
  try {
23101
- raw = await readFile12(path, "utf8");
23082
+ raw = await readFile13(path, "utf8");
23102
23083
  } catch (error) {
23103
23084
  if (isMissingPathError2(error)) return void 0;
23104
23085
  return {
@@ -23304,7 +23285,7 @@ var init_submission_ledger = __esm({
23304
23285
 
23305
23286
  // src/session-opening-materials.ts
23306
23287
  import { existsSync as existsSync7 } from "node:fs";
23307
- import { readFile as readFile13 } from "node:fs/promises";
23288
+ import { readFile as readFile14 } from "node:fs/promises";
23308
23289
  import { dirname as dirname10, join as join19 } from "node:path";
23309
23290
  import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
23310
23291
  function resolvePackageRootDir(moduleUrl = import.meta.url) {
@@ -23320,7 +23301,7 @@ function resolvePackageRootDir(moduleUrl = import.meta.url) {
23320
23301
  return fileURLToPath(new URL("..", moduleUrl));
23321
23302
  }
23322
23303
  async function readPackageMaterial(relativePath) {
23323
- return readFile13(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
23304
+ return readFile14(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
23324
23305
  }
23325
23306
  async function joinPackageMaterials(relativePaths) {
23326
23307
  const chunks = [];
@@ -23589,7 +23570,7 @@ var init_reviewer_dispatch = __esm({
23589
23570
  });
23590
23571
 
23591
23572
  // src/public-cli/reviewer-dispatch-rejection.ts
23592
- import { readFile as readFile14, unlink as unlink3 } from "node:fs/promises";
23573
+ import { readFile as readFile15, unlink as unlink3 } from "node:fs/promises";
23593
23574
  import { join as join20 } from "node:path";
23594
23575
  function isReviewerPreflightViolation(value) {
23595
23576
  return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
@@ -23610,7 +23591,7 @@ async function clearReviewerDispatchRejection(runDirectory) {
23610
23591
  async function readReviewerDispatchRejection(runDirectory) {
23611
23592
  let raw;
23612
23593
  try {
23613
- raw = await readFile14(reviewerDispatchRejectionPath(runDirectory), "utf8");
23594
+ raw = await readFile15(reviewerDispatchRejectionPath(runDirectory), "utf8");
23614
23595
  } catch (error) {
23615
23596
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
23616
23597
  return void 0;
@@ -23976,7 +23957,7 @@ var init_terminal = __esm({
23976
23957
 
23977
23958
  // src/public-cli/settlement.ts
23978
23959
  import { randomUUID as randomUUID3 } from "node:crypto";
23979
- 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";
23980
23961
  import { dirname as dirname11, join as join21 } from "node:path";
23981
23962
  function sealedLedgerHome(admitted) {
23982
23963
  return homeFromRunDirectory(admitted.runDirectory);
@@ -24094,7 +24075,7 @@ function presentControlledFailure(failure, io) {
24094
24075
  }
24095
24076
  async function inspectJudgeSession(sessionFile) {
24096
24077
  try {
24097
- await readFile15(sessionFile, "utf8");
24078
+ await readFile16(sessionFile, "utf8");
24098
24079
  return { state: "present" };
24099
24080
  } catch (error) {
24100
24081
  if (isMissingPathError3(error)) return { state: "missing" };
@@ -24310,7 +24291,7 @@ function sessionReadFailure(error, fallbackMessage) {
24310
24291
  return failed;
24311
24292
  }
24312
24293
  async function readBoundSessionEntries(sessionFile) {
24313
- const text = await readFile15(sessionFile, "utf8");
24294
+ const text = await readFile16(sessionFile, "utf8");
24314
24295
  const entries = [];
24315
24296
  for (const line2 of text.trim().split("\n").filter(Boolean)) {
24316
24297
  try {
@@ -26491,14 +26472,14 @@ var init_case_dossier_delivery = __esm({
26491
26472
  });
26492
26473
 
26493
26474
  // src/host-transition-prior-native.ts
26494
- import { access as access2, readdir as readdir6 } from "node:fs/promises";
26475
+ import { access as access3, readdir as readdir6 } from "node:fs/promises";
26495
26476
  import { dirname as dirname12, join as join23 } from "node:path";
26496
26477
  function isEnoent2(error) {
26497
26478
  return typeof error === "object" && error !== null && error.code === "ENOENT";
26498
26479
  }
26499
26480
  async function listPiNativeRecordPaths(sessionFile) {
26500
26481
  try {
26501
- await access2(sessionFile);
26482
+ await access3(sessionFile);
26502
26483
  return [sessionFile];
26503
26484
  } catch (error) {
26504
26485
  if (isEnoent2(error)) return [];
@@ -26519,7 +26500,7 @@ async function listSitianRecordPaths(sessionParent) {
26519
26500
  if (!entry.isDirectory()) continue;
26520
26501
  const recordFile = join23(sessionRoot, entry.name, "records.jsonl");
26521
26502
  try {
26522
- await access2(recordFile);
26503
+ await access3(recordFile);
26523
26504
  recordPaths.push(recordFile);
26524
26505
  } catch (error) {
26525
26506
  if (!isEnoent2(error)) throw error;
@@ -26584,7 +26565,7 @@ var init_public_run_credentials = __esm({
26584
26565
  });
26585
26566
 
26586
26567
  // src/public-cli/auto-resume.ts
26587
- import { constants as fsConstants } from "node:fs";
26568
+ import { constants as fsConstants2 } from "node:fs";
26588
26569
  import { randomUUID as randomUUID4 } from "node:crypto";
26589
26570
  import { lstat as lstat5, mkdir as mkdir4, open as open2 } from "node:fs/promises";
26590
26571
  import { join as join24 } from "node:path";
@@ -26704,10 +26685,10 @@ async function retainDispatchError(admitted, principalAuthority, sessionAppender
26704
26685
  2
26705
26686
  )}
26706
26687
  `;
26707
- const noFollowFlag = typeof fsConstants.O_NOFOLLOW === "number" ? fsConstants.O_NOFOLLOW : 0;
26688
+ const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
26708
26689
  const handle = await open2(
26709
26690
  filePath,
26710
- fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_EXCL | noFollowFlag,
26691
+ fsConstants2.O_WRONLY | fsConstants2.O_CREAT | fsConstants2.O_EXCL | noFollowFlag,
26711
26692
  384
26712
26693
  );
26713
26694
  try {
@@ -26937,8 +26918,8 @@ var init_auto_resume = __esm({
26937
26918
 
26938
26919
  // src/public-cli/post-admission.ts
26939
26920
  import { randomUUID as randomUUID5 } from "node:crypto";
26940
- import { readFile as readFile16, writeFile as writeFile6 } from "node:fs/promises";
26941
- 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";
26942
26923
  function appendContinuationSection(continuation, section) {
26943
26924
  const prompt = `${continuation.prompt}
26944
26925
 
@@ -26947,7 +26928,7 @@ ${section}`;
26947
26928
  }
26948
26929
  async function readInvocationHost(runDirectory) {
26949
26930
  try {
26950
- const raw = JSON.parse(await readFile16(join25(runDirectory, "invocation.json"), "utf8"));
26931
+ const raw = JSON.parse(await readFile17(join25(runDirectory, "invocation.json"), "utf8"));
26951
26932
  return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host : void 0;
26952
26933
  } catch (error) {
26953
26934
  if (error.code === "ENOENT") return void 0;
@@ -27209,7 +27190,7 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
27209
27190
  };
27210
27191
  }
27211
27192
  function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
27212
- const absolute = isAbsolute7(attachmentPath) ? attachmentPath : resolve8(attachmentPath);
27193
+ const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve9(attachmentPath);
27213
27194
  return pathContainedIn(join25(runDirectory, "attachments"), absolute);
27214
27195
  }
27215
27196
  async function prepareSummonsResumeMaterials(runDirectory, summons) {
@@ -29380,8 +29361,6 @@ var init_judge_run = __esm({
29380
29361
  });
29381
29362
 
29382
29363
  // src/public-cli/merger-run.ts
29383
- import { mkdir as mkdir5, writeFile as writeFile7 } from "node:fs/promises";
29384
- import { join as join26, resolve as resolve9 } from "node:path";
29385
29364
  function mergerMethods(packageRoot2) {
29386
29365
  return [
29387
29366
  {
@@ -29422,70 +29401,6 @@ async function loadMergerMethodMaterial(packageRoot2) {
29422
29401
  "resolving-merge-conflicts"
29423
29402
  );
29424
29403
  }
29425
- async function admitMergerShellForActivationFailure(options) {
29426
- const projectRoot = resolve9(options.project ?? options.cwd);
29427
- const runId = (options.createRunId ?? uuidv7)();
29428
- const {
29429
- principal,
29430
- sessionDirectory,
29431
- sessionFile,
29432
- runDirectory,
29433
- ledgerHome,
29434
- bookKey
29435
- } = issueAdmissionPlacement(options.principalAuthority, {
29436
- cwd: projectRoot,
29437
- runId,
29438
- role: "merger",
29439
- home: options.home
29440
- });
29441
- ensureRealDirectoryTree(ledgerHome, sessionDirectory);
29442
- await mkdir5(runDirectory, { recursive: true });
29443
- const emptyDerived = {
29444
- targetObjectId: "",
29445
- sourceObjectId: "",
29446
- automaticMergeTreeId: "",
29447
- expectedConflictPaths: [],
29448
- resolutionScope: []
29449
- };
29450
- const admittedRequestPath = join26(runDirectory, "admitted-request.json");
29451
- const mergerInputPath = join26(runDirectory, "merger-input.json");
29452
- await writeFile7(
29453
- admittedRequestPath,
29454
- `${JSON.stringify(
29455
- {
29456
- role: "merger",
29457
- runId,
29458
- bookKey,
29459
- projectRoot,
29460
- instruction: options.instruction,
29461
- instructionEmpty: false,
29462
- mergerInputPath,
29463
- derived: emptyDerived,
29464
- attachments: [],
29465
- sessionDirectory,
29466
- sessionFile
29467
- },
29468
- null,
29469
- 2
29470
- )}
29471
- `,
29472
- "utf8"
29473
- );
29474
- return {
29475
- role: "merger",
29476
- runId,
29477
- bookKey,
29478
- projectRoot,
29479
- instruction: options.instruction,
29480
- instructionEmpty: false,
29481
- attachments: [],
29482
- runDirectory,
29483
- principal,
29484
- admittedRequestPath,
29485
- mergerInputPath,
29486
- derived: emptyDerived
29487
- };
29488
- }
29489
29404
  function mergerTurnOptions(admitted, env) {
29490
29405
  return {
29491
29406
  packageRoot: env.packageRoot,
@@ -29525,31 +29440,6 @@ async function runPublicMerger(argv, env, io, parseMergerArgv2) {
29525
29440
  presentStructuralRejection(error, io);
29526
29441
  return { exitCode: 2 };
29527
29442
  }
29528
- if (error instanceof MergerEnvelopeDerivationError) {
29529
- const shell = await admitMergerShellForActivationFailure({
29530
- home: env.home,
29531
- principalAuthority: env.principalAuthority,
29532
- cwd: env.cwd,
29533
- instruction: parsed.instruction,
29534
- ...parsed.project === void 0 ? {} : { project: parsed.project },
29535
- ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId }
29536
- });
29537
- await markRunAdmitted(shell, env.principalAuthority);
29538
- return await presentControlledFailure2(
29539
- shell,
29540
- {
29541
- timedOut: false,
29542
- code: null,
29543
- stderr: "",
29544
- thrown: error,
29545
- knownCause: "activation",
29546
- knownDiagnostic: error.message
29547
- },
29548
- mergerAdapters(env.packageRoot),
29549
- env.principalAuthority,
29550
- io
29551
- );
29552
- }
29553
29443
  throw error;
29554
29444
  }
29555
29445
  await markRunAdmitted(admitted, env.principalAuthority);
@@ -29654,10 +29544,8 @@ async function runPublicMergerResume(request, env, io) {
29654
29544
  var init_merger_run = __esm({
29655
29545
  "src/public-cli/merger-run.ts"() {
29656
29546
  "use strict";
29657
- init_activation_ledger_topology();
29658
29547
  init_engine_material();
29659
29548
  init_method_skill();
29660
- init_uuidv7();
29661
29549
  init_cli_errors();
29662
29550
  init_invocation();
29663
29551
  init_run_lifecycle();
@@ -29853,7 +29741,7 @@ var init_reviewer_run = __esm({
29853
29741
 
29854
29742
  // src/analyst-book-key.ts
29855
29743
  import { statSync as statSync2 } from "node:fs";
29856
- import { isAbsolute as isAbsolute8 } from "node:path";
29744
+ import { isAbsolute as isAbsolute9 } from "node:path";
29857
29745
  function resolveAnalystBookKey(projectRoot) {
29858
29746
  const identity = physicalPathIdentity(projectRoot);
29859
29747
  let stats;
@@ -29875,7 +29763,7 @@ function resolveAnalystBookKey(projectRoot) {
29875
29763
  }
29876
29764
  }
29877
29765
  function isSyntheticAnalystBookKey(bookKey) {
29878
- return bookKey.startsWith("root:") && isAbsolute8(bookKey.slice("root:".length));
29766
+ return bookKey.startsWith("root:") && isAbsolute9(bookKey.slice("root:".length));
29879
29767
  }
29880
29768
  var init_analyst_book_key = __esm({
29881
29769
  "src/analyst-book-key.ts"() {
@@ -29887,13 +29775,13 @@ var init_analyst_book_key = __esm({
29887
29775
 
29888
29776
  // src/atomic-write.ts
29889
29777
  import { randomUUID as randomUUID6 } from "node:crypto";
29890
- import { rename, rm, writeFile as writeFile8 } from "node:fs/promises";
29891
- 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";
29892
29780
  async function writeFileAtomically(destination, contents) {
29893
29781
  const parent = dirname13(destination);
29894
- const temporary = join27(parent, `.atomic-write-${randomUUID6()}.tmp`);
29782
+ const temporary = join26(parent, `.atomic-write-${randomUUID6()}.tmp`);
29895
29783
  try {
29896
- await writeFile8(temporary, contents);
29784
+ await writeFile7(temporary, contents);
29897
29785
  await rename(temporary, destination);
29898
29786
  } catch (error) {
29899
29787
  await rm(temporary, { force: true }).catch(() => void 0);
@@ -29907,8 +29795,8 @@ var init_atomic_write = __esm({
29907
29795
  });
29908
29796
 
29909
29797
  // src/analyst-index.ts
29910
- import { open as open3, readFile as readFile17, unlink as unlink4 } from "node:fs/promises";
29911
- 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";
29912
29800
  function sleep(ms) {
29913
29801
  return new Promise((resolve11) => {
29914
29802
  setTimeout(resolve11, ms);
@@ -29917,7 +29805,7 @@ function sleep(ms) {
29917
29805
  async function withAnalystLibraryIndexLock(ledgerHome, fn) {
29918
29806
  const indexPath = analystLibraryIndexPath(ledgerHome);
29919
29807
  ensureRealDirectoryTree(ledgerHome, dirname14(indexPath));
29920
- const lockPath = join28(dirname14(indexPath), LIBRARY_INDEX_LOCK_NAME);
29808
+ const lockPath = join27(dirname14(indexPath), LIBRARY_INDEX_LOCK_NAME);
29921
29809
  assertLedgerFileInsideHome(lockPath, ledgerHome);
29922
29810
  const startedAt = Date.now();
29923
29811
  while (true) {
@@ -29944,7 +29832,7 @@ async function withAnalystLibraryIndexLock(ledgerHome, fn) {
29944
29832
  }
29945
29833
  }
29946
29834
  function analystLibraryIndexPath(ledgerHome) {
29947
- return join28(ledgerHome, "analyst", "library-index.json");
29835
+ return join27(ledgerHome, "analyst", "library-index.json");
29948
29836
  }
29949
29837
  function rowFromIssueMetricsPage(page) {
29950
29838
  return {
@@ -30035,7 +29923,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
30035
29923
  const path = analystLibraryIndexPath(ledgerHome);
30036
29924
  let raw;
30037
29925
  try {
30038
- raw = await readFile17(path, "utf8");
29926
+ raw = await readFile18(path, "utf8");
30039
29927
  } catch (error) {
30040
29928
  if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
30041
29929
  return void 0;
@@ -30239,8 +30127,8 @@ var init_analyst_cohort = __esm({
30239
30127
  });
30240
30128
 
30241
30129
  // src/analyst-ledger.ts
30242
- import { readdir as readdir7, readFile as readFile18 } from "node:fs/promises";
30243
- 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";
30244
30132
  function isMissingPathError5(error) {
30245
30133
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
30246
30134
  }
@@ -30253,7 +30141,7 @@ function isRecord16(value) {
30253
30141
  async function readExistingRunLifecycleState(runDirectory) {
30254
30142
  try {
30255
30143
  const raw = JSON.parse(
30256
- await readFile18(join29(runDirectory, "run-state.json"), "utf8")
30144
+ await readFile19(join28(runDirectory, "run-state.json"), "utf8")
30257
30145
  );
30258
30146
  if (!isRecord16(raw) || typeof raw.state !== "string") return void 0;
30259
30147
  return raw.state;
@@ -30285,7 +30173,7 @@ async function listLedgerBookNames(booksRoot) {
30285
30173
  async function readInvocationScopeFields(runDirectory) {
30286
30174
  let raw;
30287
30175
  try {
30288
- raw = await readFile18(join29(runDirectory, "invocation.json"), "utf8");
30176
+ raw = await readFile19(join28(runDirectory, "invocation.json"), "utf8");
30289
30177
  } catch (error) {
30290
30178
  if (isMissingPathError5(error)) return void 0;
30291
30179
  throw error;
@@ -30317,7 +30205,7 @@ function decideIssueScope(input) {
30317
30205
  }
30318
30206
  async function resolveSessionFile(runDirectory) {
30319
30207
  try {
30320
- const raw = await readFile18(join29(runDirectory, "invocation.json"), "utf8");
30208
+ const raw = await readFile19(join28(runDirectory, "invocation.json"), "utf8");
30321
30209
  const parsed = JSON.parse(raw);
30322
30210
  if (isRecord16(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
30323
30211
  return parsed.sessionFile;
@@ -30325,7 +30213,7 @@ async function resolveSessionFile(runDirectory) {
30325
30213
  } catch (error) {
30326
30214
  if (!isMissingPathError5(error)) throw error;
30327
30215
  }
30328
- return join29(runDirectory, "session", "session.jsonl");
30216
+ return join28(runDirectory, "session", "session.jsonl");
30329
30217
  }
30330
30218
  function attributeSessionRowsForRun(input) {
30331
30219
  if (pathContainedIn(input.runDirectory, input.sessionFile)) {
@@ -30497,9 +30385,9 @@ async function classifyScopedRun(input) {
30497
30385
  }
30498
30386
  let gateCycles;
30499
30387
  try {
30500
- const parentSessionFile = join29(input.runDirectory, "session", "session.jsonl");
30388
+ const parentSessionFile = join28(input.runDirectory, "session", "session.jsonl");
30501
30389
  gateCycles = await readAnalystGateCyclesFromAuditorRoles(
30502
- join29(input.runDirectory, "session", "auditor-roles"),
30390
+ join28(input.runDirectory, "session", "auditor-roles"),
30503
30391
  { parentSessionFile }
30504
30392
  );
30505
30393
  } catch (error) {
@@ -30532,7 +30420,7 @@ async function classifyScopedRun(input) {
30532
30420
  async function scanAnalystIssueRuns(input) {
30533
30421
  const ledgerHome = resolveActivationLedgerHome(input.home);
30534
30422
  const scopeTicketNumber = input.ticketNumber;
30535
- const booksRoot = join29(ledgerHome, "books");
30423
+ const booksRoot = join28(ledgerHome, "books");
30536
30424
  let wholeBook = false;
30537
30425
  let scopeRootIdentity;
30538
30426
  let bookNames;
@@ -30564,7 +30452,7 @@ async function scanAnalystIssueRuns(input) {
30564
30452
  const unreadable = [];
30565
30453
  const scopeConflicts = [];
30566
30454
  for (const book of bookNames) {
30567
- const runsDir = join29(booksRoot, book, "runs");
30455
+ const runsDir = join28(booksRoot, book, "runs");
30568
30456
  let runNames;
30569
30457
  try {
30570
30458
  const entries = await readdir7(runsDir, { withFileTypes: true });
@@ -30576,7 +30464,7 @@ async function scanAnalystIssueRuns(input) {
30576
30464
  for (const runName of runNames) {
30577
30465
  const parsed = parseRunDirectoryName2(runName);
30578
30466
  if (parsed === void 0) continue;
30579
- const runDirectory = join29(runsDir, runName);
30467
+ const runDirectory = join28(runsDir, runName);
30580
30468
  let scopeFields;
30581
30469
  try {
30582
30470
  scopeFields = await readInvocationScopeFields(runDirectory);
@@ -31430,7 +31318,7 @@ var init_analyst_metric_family = __esm({
31430
31318
 
31431
31319
  // src/analyst-page.ts
31432
31320
  import { createHash as createHash5 } from "node:crypto";
31433
- import { dirname as dirname15, join as join30 } from "node:path";
31321
+ import { dirname as dirname15, join as join29 } from "node:path";
31434
31322
  function analystIssuePageKey(address) {
31435
31323
  const parts = ["book", address.bookKey];
31436
31324
  if (address.issueNumber !== void 0) {
@@ -31441,7 +31329,7 @@ function analystIssuePageKey(address) {
31441
31329
  return createHash5("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
31442
31330
  }
31443
31331
  function analystIssuePagePath(ledgerHome, address) {
31444
- return join30(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
31332
+ return join29(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
31445
31333
  }
31446
31334
  function analystIssuePageAddressFromPage(page) {
31447
31335
  return {
@@ -31577,7 +31465,7 @@ var init_analyst_page = __esm({
31577
31465
  });
31578
31466
 
31579
31467
  // src/analyst-entry.ts
31580
- import { readFile as readFile19 } from "node:fs/promises";
31468
+ import { readFile as readFile20 } from "node:fs/promises";
31581
31469
  function isMissingPathError6(error) {
31582
31470
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
31583
31471
  }
@@ -31607,7 +31495,7 @@ async function readOrComputeAnalystIssuePage(input, options) {
31607
31495
  ...issueNumber === void 0 && input.bookKey === void 0 ? { scopeRootIdentity: projectRoot } : {}
31608
31496
  });
31609
31497
  try {
31610
- const raw = await readFile19(pagePath, "utf8");
31498
+ const raw = await readFile20(pagePath, "utf8");
31611
31499
  const page = JSON.parse(raw);
31612
31500
  if (cachedPageMatchesRequestedScope(page, { bookKey, ...input })) {
31613
31501
  return { mode: "issue", page, pagePath };
@@ -31702,7 +31590,7 @@ async function runAnalystModelGroupsMode(input, home) {
31702
31590
  scopeRootIdentity: projectRoot
31703
31591
  });
31704
31592
  try {
31705
- const raw = await readFile19(pagePath, "utf8");
31593
+ const raw = await readFile20(pagePath, "utf8");
31706
31594
  JSON.parse(raw);
31707
31595
  } catch (error) {
31708
31596
  if (!isMissingPathError6(error)) {
@@ -31801,8 +31689,8 @@ var init_analyst_entry = __esm({
31801
31689
  });
31802
31690
 
31803
31691
  // src/public-cli/analyst-run.ts
31804
- import { readFile as readFile20 } from "node:fs/promises";
31805
- 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";
31806
31694
  function resolveAnalystIssueBookKeyFromCwd(cwd = process.cwd()) {
31807
31695
  try {
31808
31696
  return resolveBookKeyFromGit(cwd);
@@ -31851,10 +31739,10 @@ async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
31851
31739
  );
31852
31740
  }
31853
31741
  const sourcePath = attachmentPaths[0];
31854
- const absolute = isAbsolute9(sourcePath) ? sourcePath : resolve10(sourcePath);
31742
+ const absolute = isAbsolute10(sourcePath) ? sourcePath : resolve10(sourcePath);
31855
31743
  let bytes;
31856
31744
  try {
31857
- bytes = await readFile20(absolute);
31745
+ bytes = await readFile21(absolute);
31858
31746
  } catch (error) {
31859
31747
  throw new CliUsageError(
31860
31748
  `analyst sweep attachment is not a readable regular file: ${sourcePath}`,
@@ -31974,7 +31862,7 @@ __export(cli_exports, {
31974
31862
  runAkRole: () => runAkRole
31975
31863
  });
31976
31864
  import { realpath as realpath6 } from "node:fs/promises";
31977
- import { join as join31 } from "node:path";
31865
+ import { join as join30 } from "node:path";
31978
31866
  function takePublicGlobalFlag(argv, index, options) {
31979
31867
  const tokens = argv.slice(index);
31980
31868
  const taken = options.takeDashed(tokens);
@@ -32105,7 +31993,7 @@ function resolveHome(env) {
32105
31993
  return env.home ?? packageMachineHome();
32106
31994
  }
32107
31995
  function resolveAgentDir(env, home) {
32108
- 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");
32109
31997
  }
32110
31998
  function parseThinking(value) {
32111
31999
  return value;
@@ -33070,7 +32958,7 @@ var init_cli = __esm({
33070
32958
 
33071
32959
  // src/public-cli/main.ts
33072
32960
  import { existsSync as existsSync8 } from "node:fs";
33073
- import { dirname as dirname16, join as join32 } from "node:path";
32961
+ import { dirname as dirname16, join as join31 } from "node:path";
33074
32962
  import { fileURLToPath as fileURLToPath2 } from "node:url";
33075
32963
 
33076
32964
  // src/public-cli/host-pi-runtime.ts
@@ -33159,8 +33047,8 @@ function linkPackage(packageRoot2, name, targetDir) {
33159
33047
  // src/public-cli/main.ts
33160
33048
  var here = dirname16(fileURLToPath2(import.meta.url));
33161
33049
  function resolvePackageRoot(binDir) {
33162
- const canonical = join32(binDir, "..", "..");
33163
- if (existsSync8(join32(canonical, "package.json"))) {
33050
+ const canonical = join31(binDir, "..", "..");
33051
+ if (existsSync8(join31(canonical, "package.json"))) {
33164
33052
  return canonical;
33165
33053
  }
33166
33054
  return binDir;