@akagilnc/pi-workflow-roles 0.1.3873 → 0.1.3886
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.
- package/README.md +2 -2
- package/README.zh-CN.md +3 -3
- package/dist/acp-host/production-host.js +313 -371
- package/dist/headless-host/production-host.js +301 -359
- package/dist/merger-contracts.js +23 -42
- package/dist/merger-git-state.js +69 -42
- package/dist/merger-role.js +30 -41
- package/dist/public-cli/invocation.js +12 -39
- package/dist/public-cli/main.js +219 -331
- package/dist/public-cli/option-definitions.js +5 -5
- package/dist/public-cli/run-lifecycle.js +0 -2
- package/dist/role-runtime.js +1 -13
- package/extensions/role-runtime.ts +0 -3
- package/package.json +1 -1
- package/resources/engines/cursor.md +6 -4
- package/resources/engines/opencode.md +5 -3
- package/souls/merger.md +1 -1
- package/src/merger-contracts.ts +24 -38
- package/src/merger-git-state.ts +67 -37
- package/src/merger-role.ts +52 -48
- package/src/public-cli/invocation.ts +13 -44
- package/src/public-cli/merger-run.ts +2 -113
- package/src/public-cli/option-definitions.ts +5 -5
- package/src/public-cli/run-lifecycle.ts +0 -2
- package/src/role-runtime-dependencies.ts +0 -2
- package/src/role-runtime.ts +2 -13
|
@@ -62,7 +62,7 @@ async function spawnEngineDetourOnce(input) {
|
|
|
62
62
|
}
|
|
63
63
|
const command = input.argv[0];
|
|
64
64
|
const args = input.argv.slice(1);
|
|
65
|
-
return await new Promise((
|
|
65
|
+
return await new Promise((resolve21, reject) => {
|
|
66
66
|
let settled = false;
|
|
67
67
|
const signal = input.signal;
|
|
68
68
|
const child = spawn(command, args, {
|
|
@@ -92,7 +92,7 @@ async function spawnEngineDetourOnce(input) {
|
|
|
92
92
|
if (signal !== void 0) {
|
|
93
93
|
signal.removeEventListener("abort", onAbort);
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
resolve21(result);
|
|
96
96
|
};
|
|
97
97
|
const onAbort = () => {
|
|
98
98
|
fail5(signal !== void 0 ? abortReasonError(signal) : new Error("aborted"));
|
|
@@ -1901,18 +1901,6 @@ var init_doctor_contracts = __esm({
|
|
|
1901
1901
|
}
|
|
1902
1902
|
});
|
|
1903
1903
|
|
|
1904
|
-
// src/git-object-id.ts
|
|
1905
|
-
function isFullGitObjectId(value) {
|
|
1906
|
-
return typeof value === "string" && FULL_GIT_OBJECT_ID_RE.test(value);
|
|
1907
|
-
}
|
|
1908
|
-
var FULL_GIT_OBJECT_ID_RE;
|
|
1909
|
-
var init_git_object_id = __esm({
|
|
1910
|
-
"src/git-object-id.ts"() {
|
|
1911
|
-
"use strict";
|
|
1912
|
-
FULL_GIT_OBJECT_ID_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
1913
|
-
}
|
|
1914
|
-
});
|
|
1915
|
-
|
|
1916
1904
|
// src/exact-utf8.ts
|
|
1917
1905
|
function exactUtf8(bytes, label) {
|
|
1918
1906
|
let text;
|
|
@@ -1931,35 +1919,11 @@ var init_exact_utf8 = __esm({
|
|
|
1931
1919
|
}
|
|
1932
1920
|
});
|
|
1933
1921
|
|
|
1934
|
-
// src/sha256.ts
|
|
1935
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
1936
|
-
function sha256Hex(bytes) {
|
|
1937
|
-
return createHash2("sha256").update(bytes).digest("hex");
|
|
1938
|
-
}
|
|
1939
|
-
var init_sha256 = __esm({
|
|
1940
|
-
"src/sha256.ts"() {
|
|
1941
|
-
"use strict";
|
|
1942
|
-
}
|
|
1943
|
-
});
|
|
1944
|
-
|
|
1945
1922
|
// src/merger-contracts.ts
|
|
1946
1923
|
import { Type as Type10 } from "typebox";
|
|
1947
1924
|
function fail2(message = "Merger input violates its exact contract") {
|
|
1948
1925
|
throw new MergerInputContractError(message);
|
|
1949
1926
|
}
|
|
1950
|
-
function canonicalPath(path) {
|
|
1951
|
-
return typeof path === "string" && path.length > 0 && !path.startsWith("/") && !path.includes("\0") && path.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
1952
|
-
}
|
|
1953
|
-
function validatePathSet(value, label) {
|
|
1954
|
-
if (!Array.isArray(value) || value.length === 0 || !value.every(canonicalPath)) fail2(`Merger ${label} must be a non-empty canonical path set`);
|
|
1955
|
-
return value;
|
|
1956
|
-
}
|
|
1957
|
-
function validateMaterial(value, label) {
|
|
1958
|
-
if (!record(value) || typeof value.bytesBase64 !== "string" || typeof value.sha256 !== "string") fail2(`Merger ${label} material is malformed`);
|
|
1959
|
-
const bytes = Buffer.from(value.bytesBase64, "base64");
|
|
1960
|
-
exactUtf8(bytes, `Merger ${label} material`);
|
|
1961
|
-
if (sha256Hex(bytes) !== value.sha256) fail2(`Merger ${label} material digest mismatch`);
|
|
1962
|
-
}
|
|
1963
1927
|
function deepFreeze(value) {
|
|
1964
1928
|
if (value && typeof value === "object") {
|
|
1965
1929
|
for (const child of Object.values(value)) deepFreeze(child);
|
|
@@ -1967,55 +1931,47 @@ function deepFreeze(value) {
|
|
|
1967
1931
|
}
|
|
1968
1932
|
return value;
|
|
1969
1933
|
}
|
|
1934
|
+
function readMaterial(value, label) {
|
|
1935
|
+
if (!record(value) || typeof value.bytesBase64 !== "string") fail2(`Merger ${label} material is malformed`);
|
|
1936
|
+
exactUtf8(Buffer.from(value.bytesBase64, "base64"), `Merger ${label} material`);
|
|
1937
|
+
return { bytesBase64: value.bytesBase64, sha256: typeof value.sha256 === "string" ? value.sha256 : "" };
|
|
1938
|
+
}
|
|
1970
1939
|
function validateMergerInput(value) {
|
|
1971
|
-
if (!record(value) || blank(value.attemptId)
|
|
1972
|
-
if (!record(value.materials)) fail2();
|
|
1973
|
-
|
|
1974
|
-
const
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
if (!record(check) || !Array.isArray(check.argv) || check.argv.length === 0 || check.argv.some(blank)) fail2("Merger authorized check is malformed");
|
|
1980
|
-
}
|
|
1981
|
-
return deepFreeze(structuredClone(value));
|
|
1982
|
-
}
|
|
1983
|
-
function validateMergerOutput(value, expectedAttemptId) {
|
|
1984
|
-
if (!record(value) || expectedAttemptId !== void 0 && value.attemptId !== expectedAttemptId) throw new Error("\u5408\u5E76\u56DE\u6267 attempt \u4E0D\u5339\u914D");
|
|
1940
|
+
if (!record(value) || blank(value.attemptId)) fail2("Merger input requires a non-empty attemptId for accounting");
|
|
1941
|
+
if (!record(value.materials)) fail2("Merger materials are missing");
|
|
1942
|
+
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") };
|
|
1943
|
+
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) : [];
|
|
1944
|
+
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 }));
|
|
1945
|
+
}
|
|
1946
|
+
function validateMergerOutput(value) {
|
|
1947
|
+
if (!record(value)) throw new Error("\u5408\u5E76\u56DE\u6267\u65E0\u5DF2\u8BC6\u522B\u7684\u6267\u884C\u5224\u522B");
|
|
1985
1948
|
const status = typeof value.status === "string" ? value.status : void 0;
|
|
1986
|
-
if (status === "completed"
|
|
1987
|
-
if (status === "escalate") return structuredClone(value);
|
|
1949
|
+
if (status === "completed" || status === "escalate") return structuredClone(value);
|
|
1988
1950
|
throw new Error("\u5408\u5E76\u56DE\u6267\u65E0\u5DF2\u8BC6\u522B\u7684\u6267\u884C\u5224\u522B");
|
|
1989
1951
|
}
|
|
1990
|
-
var
|
|
1952
|
+
var materialSchema, checkSchema, mergerInputSchema, mergerOutputVariants, mergerOutputSchema, MERGER_OUTPUT_TOOL_NAME, MERGER_ACCEPTED_TEXT, record, blank, MergerInputContractError, asString, asStringArray2;
|
|
1991
1953
|
var init_merger_contracts = __esm({
|
|
1992
1954
|
"src/merger-contracts.ts"() {
|
|
1993
1955
|
"use strict";
|
|
1994
|
-
init_git_object_id();
|
|
1995
1956
|
init_exact_utf8();
|
|
1996
|
-
init_sha256();
|
|
1997
1957
|
init_open_tool_schema();
|
|
1998
1958
|
init_terminating_infrastructure();
|
|
1999
|
-
oidPattern = "^(?:[0-9a-f]{40}|[0-9a-f]{64})$";
|
|
2000
1959
|
materialSchema = Type10.Object({ bytesBase64: Type10.String(), sha256: Type10.String() }, { additionalProperties: false });
|
|
2001
1960
|
checkSchema = Type10.Object({ name: Type10.String({ minLength: 1 }), argv: Type10.Array(Type10.String({ minLength: 1 }), { minItems: 1 }) }, { additionalProperties: false });
|
|
2002
1961
|
mergerInputSchema = Type10.Object({
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
sourceObjectId: Type10.String({ pattern: oidPattern }),
|
|
1962
|
+
attemptId: Type10.String({ minLength: 1, description: "\u5BF9\u8D26 attempt \u8EAB\u4EFD\uFF08transport\uFF09" }),
|
|
1963
|
+
targetObjectId: Type10.String({ description: "\u6750\u6599\uFF1Atarget parent OID\uFF1B\u53EF\u7A7A" }),
|
|
1964
|
+
sourceObjectId: Type10.String({ description: "\u6750\u6599\uFF1Asource parent OID\uFF1B\u53EF\u7A7A" }),
|
|
2007
1965
|
materials: Type10.Object({ task: materialSchema, authority: materialSchema, targetIntent: materialSchema, sourceIntent: materialSchema }, { additionalProperties: false }),
|
|
2008
|
-
expectedConflictPaths: Type10.Array(Type10.String(
|
|
2009
|
-
resolutionScope: Type10.Array(Type10.String(
|
|
1966
|
+
expectedConflictPaths: Type10.Array(Type10.String(), { description: "\u6750\u6599\uFF1A\u5F53\u524D\u672A\u5408\u5E76\u8DEF\u5F84\uFF1B\u53EF\u7A7A" }),
|
|
1967
|
+
resolutionScope: Type10.Array(Type10.String(), { description: "\u6750\u6599\uFF1A\u89E3\u6790\u8303\u56F4\u63D0\u793A\uFF1B\u53EF\u7A7A" }),
|
|
2010
1968
|
authorizedChecks: Type10.Array(checkSchema)
|
|
2011
1969
|
}, { additionalProperties: false });
|
|
2012
1970
|
mergerOutputVariants = Type10.Union([
|
|
2013
|
-
Type10.Object({ status: Type10.Literal("completed", { description: "completed \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), attemptId: Type10.String({ minLength: 1, description: "\u5DF2\u53D7\u7406\u5408\u5E76 attempt \u8EAB\u4EFD" }), report: Type10.String({ minLength: 1, description: "\u5982\u5B9E\u7ED3\u679C\u62A5\u544A" }), mergeCommitId: Type10.String({
|
|
2014
|
-
Type10.Object({ status: Type10.Literal("escalate", { description: "escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), attemptId: Type10.String({ minLength: 1, description: "\u5DF2\u53D7\u7406\u5408\u5E76 attempt \u8EAB\u4EFD" }), diagnosis: Type10.String({ minLength: 1, description: "\u5408\u5E76\u5B8C\u6210\u9700\
|
|
1971
|
+
Type10.Object({ status: Type10.Literal("completed", { description: "completed \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), attemptId: Type10.String({ minLength: 1, description: "\u5DF2\u53D7\u7406\u5408\u5E76 attempt \u8EAB\u4EFD" }), report: Type10.String({ minLength: 1, description: "\u5982\u5B9E\u7ED3\u679C\u62A5\u544A" }), mergeCommitId: Type10.String({ description: "\u5B8C\u6210\u5408\u5E76 commit object ID" }) }, { additionalProperties: false }),
|
|
1972
|
+
Type10.Object({ status: Type10.Literal("escalate", { description: "escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), attemptId: Type10.String({ minLength: 1, description: "\u5DF2\u53D7\u7406\u5408\u5E76 attempt \u8EAB\u4EFD" }), diagnosis: Type10.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: Type10.String({ minLength: 1, description: "\u5982\u5B9E\u7ED3\u679C\u62A5\u544A" }) }, { additionalProperties: false })
|
|
2015
1973
|
]);
|
|
2016
|
-
mergerOutputSchema = withInfrastructureFailureDeclaration(
|
|
2017
|
-
openToolObjectFromUnion(mergerOutputVariants)
|
|
2018
|
-
);
|
|
1974
|
+
mergerOutputSchema = withInfrastructureFailureDeclaration(openToolObjectFromUnion(mergerOutputVariants));
|
|
2019
1975
|
MERGER_OUTPUT_TOOL_NAME = "ak_merger_output";
|
|
2020
1976
|
MERGER_ACCEPTED_TEXT = "\u5408\u5E76\u56DE\u6267\u5DF2\u63A5\u53D7";
|
|
2021
1977
|
record = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -2026,6 +1982,8 @@ var init_merger_contracts = __esm({
|
|
|
2026
1982
|
this.name = "MergerInputContractError";
|
|
2027
1983
|
}
|
|
2028
1984
|
};
|
|
1985
|
+
asString = (v) => typeof v === "string" ? v : "";
|
|
1986
|
+
asStringArray2 = (v) => Array.isArray(v) ? v.filter((item) => typeof item === "string") : [];
|
|
2029
1987
|
}
|
|
2030
1988
|
});
|
|
2031
1989
|
|
|
@@ -2564,7 +2522,7 @@ var init_sitian_contracts = __esm({
|
|
|
2564
2522
|
});
|
|
2565
2523
|
|
|
2566
2524
|
// src/sitian-appender.ts
|
|
2567
|
-
import { createHash as
|
|
2525
|
+
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
2568
2526
|
import {
|
|
2569
2527
|
appendFileSync,
|
|
2570
2528
|
existsSync as existsSync2,
|
|
@@ -2580,7 +2538,7 @@ function errorCodeOf(error) {
|
|
|
2580
2538
|
return error.code;
|
|
2581
2539
|
}
|
|
2582
2540
|
function identityClaimPath(recordFile, identity) {
|
|
2583
|
-
const digest =
|
|
2541
|
+
const digest = createHash2("sha256").update(identity, "utf8").digest("hex");
|
|
2584
2542
|
return `${recordFile}.id-${digest}`;
|
|
2585
2543
|
}
|
|
2586
2544
|
function createExclusiveFile(path, contents) {
|
|
@@ -2724,7 +2682,7 @@ function resolveSitianRecordPathInLedger(input, ledgerHome) {
|
|
|
2724
2682
|
} else {
|
|
2725
2683
|
subjectStr = JSON.stringify(input.subject);
|
|
2726
2684
|
}
|
|
2727
|
-
const digest =
|
|
2685
|
+
const digest = createHash2("sha256").update(subjectStr).digest("hex").slice(0, 32);
|
|
2728
2686
|
sessionDir = join7(bookDir, category, digest);
|
|
2729
2687
|
} else {
|
|
2730
2688
|
sessionDir = join7(bookDir, category);
|
|
@@ -3198,6 +3156,17 @@ var init_run_ticket_number = __esm({
|
|
|
3198
3156
|
}
|
|
3199
3157
|
});
|
|
3200
3158
|
|
|
3159
|
+
// src/sha256.ts
|
|
3160
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
3161
|
+
function sha256Hex(bytes) {
|
|
3162
|
+
return createHash3("sha256").update(bytes).digest("hex");
|
|
3163
|
+
}
|
|
3164
|
+
var init_sha256 = __esm({
|
|
3165
|
+
"src/sha256.ts"() {
|
|
3166
|
+
"use strict";
|
|
3167
|
+
}
|
|
3168
|
+
});
|
|
3169
|
+
|
|
3201
3170
|
// src/audit-escalation.ts
|
|
3202
3171
|
function buildAuditEscalationResult(decision, deliveredOutput) {
|
|
3203
3172
|
const auditOwned = {
|
|
@@ -4070,7 +4039,7 @@ function normalizeReviewComment(raw) {
|
|
|
4070
4039
|
function createGhApiRunner(options = {}) {
|
|
4071
4040
|
const spawnImpl = options.spawnImpl ?? spawn3;
|
|
4072
4041
|
return async (args, runOptions = {}) => {
|
|
4073
|
-
return await new Promise((
|
|
4042
|
+
return await new Promise((resolve21, reject) => {
|
|
4074
4043
|
const signal = runOptions.signal;
|
|
4075
4044
|
if (signal?.aborted) {
|
|
4076
4045
|
reject(signal.reason ?? new Error("aborted"));
|
|
@@ -4143,11 +4112,11 @@ function createGhApiRunner(options = {}) {
|
|
|
4143
4112
|
const value = line2.slice(idx + 1).trim();
|
|
4144
4113
|
headers[name] = value;
|
|
4145
4114
|
}
|
|
4146
|
-
|
|
4115
|
+
resolve21({ status, headers, bodyText });
|
|
4147
4116
|
return;
|
|
4148
4117
|
}
|
|
4149
4118
|
if (code === 0) {
|
|
4150
|
-
|
|
4119
|
+
resolve21({ status: 200, headers: {}, bodyText: stdout });
|
|
4151
4120
|
return;
|
|
4152
4121
|
}
|
|
4153
4122
|
const failure2 = new Error(
|
|
@@ -4603,8 +4572,23 @@ var init_collector_target = __esm({
|
|
|
4603
4572
|
}
|
|
4604
4573
|
});
|
|
4605
4574
|
|
|
4575
|
+
// src/git-object-id.ts
|
|
4576
|
+
function isFullGitObjectId(value) {
|
|
4577
|
+
return typeof value === "string" && FULL_GIT_OBJECT_ID_RE.test(value);
|
|
4578
|
+
}
|
|
4579
|
+
var FULL_GIT_OBJECT_ID_RE;
|
|
4580
|
+
var init_git_object_id = __esm({
|
|
4581
|
+
"src/git-object-id.ts"() {
|
|
4582
|
+
"use strict";
|
|
4583
|
+
FULL_GIT_OBJECT_ID_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
4584
|
+
}
|
|
4585
|
+
});
|
|
4586
|
+
|
|
4606
4587
|
// src/merger-git-state.ts
|
|
4607
4588
|
import { execFile as execFile2 } from "node:child_process";
|
|
4589
|
+
import { access as access2, readFile as readFile6 } from "node:fs/promises";
|
|
4590
|
+
import { constants as fsConstants } from "node:fs";
|
|
4591
|
+
import { isAbsolute as isAbsolute4, resolve as resolve8 } from "node:path";
|
|
4608
4592
|
import { promisify as promisify2 } from "node:util";
|
|
4609
4593
|
async function git(cwd, args) {
|
|
4610
4594
|
const { stdout } = await execFileAsync2("git", args, { cwd, encoding: "buffer", maxBuffer: 16 * 1024 * 1024 });
|
|
@@ -4615,10 +4599,31 @@ function line(bytes, label) {
|
|
|
4615
4599
|
if (!value) throw new Error(`${label} is empty`);
|
|
4616
4600
|
return value;
|
|
4617
4601
|
}
|
|
4618
|
-
function
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4602
|
+
async function pathExists(path) {
|
|
4603
|
+
try {
|
|
4604
|
+
await access2(path, fsConstants.F_OK);
|
|
4605
|
+
return true;
|
|
4606
|
+
} catch (error) {
|
|
4607
|
+
if (error.code === "ENOENT") return false;
|
|
4608
|
+
throw error;
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4611
|
+
async function requireInsideWorkTree(cwd) {
|
|
4612
|
+
const stdout = await git(cwd, ["rev-parse", "--is-inside-work-tree"]);
|
|
4613
|
+
if (exactUtf8(stdout, "Git worktree check").trim() !== "true") throw new Error("Assigned path is not inside a Git work tree");
|
|
4614
|
+
}
|
|
4615
|
+
async function tryResolveCommit(cwd, rev) {
|
|
4616
|
+
let stdout;
|
|
4617
|
+
try {
|
|
4618
|
+
const res = await execFileAsync2("git", ["rev-parse", "--verify", "--quiet", `${rev}^{commit}`], { cwd, encoding: "buffer", maxBuffer: 16 * 1024 * 1024 });
|
|
4619
|
+
stdout = new Uint8Array(res.stdout);
|
|
4620
|
+
} catch (error) {
|
|
4621
|
+
if (error.code === 1) return void 0;
|
|
4622
|
+
throw error;
|
|
4623
|
+
}
|
|
4624
|
+
const oid = line(stdout, `Git ${rev}`);
|
|
4625
|
+
if (!isFullGitObjectId(oid)) throw new Error(`Git ${rev} identity is unavailable or invalid`);
|
|
4626
|
+
return oid;
|
|
4622
4627
|
}
|
|
4623
4628
|
async function unmerged(cwd) {
|
|
4624
4629
|
const raw = exactUtf8(await git(cwd, ["ls-files", "-u", "-z"]), "Git unmerged index");
|
|
@@ -4631,40 +4636,39 @@ async function unmerged(cwd) {
|
|
|
4631
4636
|
}
|
|
4632
4637
|
return [...paths].sort((a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b)));
|
|
4633
4638
|
}
|
|
4639
|
+
async function resolveHeadMaterial(cwd) {
|
|
4640
|
+
const commit = await tryResolveCommit(cwd, "HEAD");
|
|
4641
|
+
if (commit !== void 0) return commit;
|
|
4642
|
+
try {
|
|
4643
|
+
await execFileAsync2("git", ["rev-parse", "--verify", "--quiet", "HEAD"], { cwd, encoding: "buffer", maxBuffer: 16 * 1024 * 1024 });
|
|
4644
|
+
} catch (error) {
|
|
4645
|
+
if (error.code === 1) return "";
|
|
4646
|
+
throw error;
|
|
4647
|
+
}
|
|
4648
|
+
throw new Error("Git HEAD identity is unavailable or invalid");
|
|
4649
|
+
}
|
|
4634
4650
|
function createProductionMergerGitState(repositoryRoot = process.cwd()) {
|
|
4635
4651
|
return {
|
|
4636
4652
|
async activeMerge() {
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4653
|
+
await requireInsideWorkTree(repositoryRoot);
|
|
4654
|
+
const targetObjectId = await resolveHeadMaterial(repositoryRoot);
|
|
4655
|
+
const mergeHeadReported = line(await git(repositoryRoot, ["rev-parse", "--git-path", "MERGE_HEAD"]), "Git MERGE_HEAD path");
|
|
4656
|
+
const mergeHeadPath = isAbsolute4(mergeHeadReported) ? mergeHeadReported : resolve8(repositoryRoot, mergeHeadReported);
|
|
4657
|
+
let sourceObjectId = "";
|
|
4658
|
+
if (await pathExists(mergeHeadPath)) {
|
|
4659
|
+
const raw = exactUtf8(await readFile6(mergeHeadPath), "Git MERGE_HEAD");
|
|
4660
|
+
const mergeHeads = raw.trim().split(/\r?\n/).map((row) => row.trim()).filter(Boolean);
|
|
4661
|
+
if (mergeHeads.length === 0) throw new Error("Git MERGE_HEAD is empty");
|
|
4662
|
+
if (mergeHeads.length !== 1) throw new Error("Assigned repository does not have one ordinary in-progress merge");
|
|
4663
|
+
const source = mergeHeads[0];
|
|
4664
|
+
if (!isFullGitObjectId(source)) throw new Error("Git MERGE_HEAD identity is unavailable or invalid");
|
|
4665
|
+
const resolved = await tryResolveCommit(repositoryRoot, source);
|
|
4666
|
+
if (resolved === void 0 || targetObjectId !== "" && resolved.length !== targetObjectId.length) {
|
|
4667
|
+
throw new Error("Git MERGE_HEAD identity is unavailable or invalid");
|
|
4668
|
+
}
|
|
4669
|
+
sourceObjectId = resolved;
|
|
4651
4670
|
}
|
|
4652
|
-
|
|
4653
|
-
if (!isFullGitObjectId(automaticMergeTreeId) || automaticMergeTreeId.length !== targetObjectId.length) throw new Error("Git automatic merge tree identity is unavailable or invalid");
|
|
4654
|
-
return { targetObjectId, sourceObjectId: mergeHeads[0], unmergedPaths: await unmerged(repositoryRoot), automaticMergeTreeId };
|
|
4655
|
-
},
|
|
4656
|
-
async completedMerge(mergeCommitId, automaticMergeTreeId) {
|
|
4657
|
-
if (!isFullGitObjectId(mergeCommitId) || !isFullGitObjectId(automaticMergeTreeId) || mergeCommitId.length !== automaticMergeTreeId.length) throw new Error("Merger completion object ID is invalid");
|
|
4658
|
-
const identity = exactUtf8(await git(repositoryRoot, ["show", "-s", "--format=%H%x00%P", mergeCommitId]), "Git merge commit").trimEnd().split("\0");
|
|
4659
|
-
if (identity.length !== 2 || identity[0] !== mergeCommitId) throw new Error("Git merge completion identity drifted");
|
|
4660
|
-
const parentObjectIds = identity[1].split(" ").filter(Boolean);
|
|
4661
|
-
const currentHead = line(await git(repositoryRoot, ["rev-parse", "--verify", "HEAD"]), "Git HEAD");
|
|
4662
|
-
const status = await git(repositoryRoot, ["status", "--porcelain=v1", "-z", "--untracked-files=all"]);
|
|
4663
|
-
const frozenTree = line(await git(repositoryRoot, ["rev-parse", "--verify", `${automaticMergeTreeId}^{tree}`]), "Git frozen automatic merge tree");
|
|
4664
|
-
if (frozenTree !== automaticMergeTreeId) throw new Error("Git frozen automatic merge tree identity drifted");
|
|
4665
|
-
const mergeTree = line(await git(repositoryRoot, ["rev-parse", "--verify", `${mergeCommitId}^{tree}`]), "Git completed merge tree");
|
|
4666
|
-
const resolutionChangedPaths = nulPaths(await git(repositoryRoot, ["diff-tree", "--no-commit-id", "--name-only", "-r", "-z", "--no-renames", automaticMergeTreeId, mergeTree]), "Git resolution path delta");
|
|
4667
|
-
return { mergeCommitId: currentHead, parentObjectIds, unmergedPaths: await unmerged(repositoryRoot), worktreeClean: status.byteLength === 0 && currentHead === mergeCommitId, resolutionChangedPaths };
|
|
4671
|
+
return { targetObjectId, sourceObjectId, unmergedPaths: await unmerged(repositoryRoot) };
|
|
4668
4672
|
}
|
|
4669
4673
|
};
|
|
4670
4674
|
}
|
|
@@ -4704,7 +4708,7 @@ var init_uuidv7 = __esm({
|
|
|
4704
4708
|
});
|
|
4705
4709
|
|
|
4706
4710
|
// src/typed-provider-http.ts
|
|
4707
|
-
import { readFile as
|
|
4711
|
+
import { readFile as readFile7, unlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
4708
4712
|
import { join as join10 } from "node:path";
|
|
4709
4713
|
function typedProviderHttpPath(runDirectory) {
|
|
4710
4714
|
return join10(runDirectory, TYPED_HTTP_FILE);
|
|
@@ -4738,7 +4742,7 @@ async function recordTypedProviderHttpStatus(runDirectory, observation) {
|
|
|
4738
4742
|
async function readLatestTypedProviderHttpObservation(runDirectory) {
|
|
4739
4743
|
let text;
|
|
4740
4744
|
try {
|
|
4741
|
-
text = await
|
|
4745
|
+
text = await readFile7(typedProviderHttpPath(runDirectory), "utf8");
|
|
4742
4746
|
} catch (error) {
|
|
4743
4747
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
4744
4748
|
return void 0;
|
|
@@ -4825,8 +4829,8 @@ var init_engine_material = __esm({
|
|
|
4825
4829
|
});
|
|
4826
4830
|
|
|
4827
4831
|
// src/public-cli/run-lifecycle.ts
|
|
4828
|
-
import { chmod, open, readdir as readdir2, readFile as
|
|
4829
|
-
import { isAbsolute as
|
|
4832
|
+
import { chmod, open, readdir as readdir2, readFile as readFile8, unlink as unlink2, writeFile as writeFile3 } from "node:fs/promises";
|
|
4833
|
+
import { isAbsolute as isAbsolute5, join as join12 } from "node:path";
|
|
4830
4834
|
function resumeRereadInstruction(materialPath, handbook) {
|
|
4831
4835
|
return handbook ? `\u91CD\u65B0\u8BFB ${materialPath}\uFF0C\u518D\u7EC4\u88C5\u5916\u5305 argv` : `\u91CD\u65B0\u8BFB ${materialPath}`;
|
|
4832
4836
|
}
|
|
@@ -4838,7 +4842,7 @@ function instructResumeHandbookRead(prompt, engineMaterial) {
|
|
|
4838
4842
|
if (handbookPath !== void 0 && value === handbookPath) {
|
|
4839
4843
|
return resumeRereadInstruction(handbookPath, true);
|
|
4840
4844
|
}
|
|
4841
|
-
if (
|
|
4845
|
+
if (isAbsolute5(value)) return resumeRereadInstruction(value, false);
|
|
4842
4846
|
return line2;
|
|
4843
4847
|
}).join("\n");
|
|
4844
4848
|
}
|
|
@@ -4924,7 +4928,7 @@ function parseCurrentCourtState(raw) {
|
|
|
4924
4928
|
async function readRoleRunStateDisk(runDirectory) {
|
|
4925
4929
|
let raw;
|
|
4926
4930
|
try {
|
|
4927
|
-
raw = JSON.parse(await
|
|
4931
|
+
raw = JSON.parse(await readFile8(join12(runDirectory, RUN_STATE_FILE), "utf8"));
|
|
4928
4932
|
} catch {
|
|
4929
4933
|
return void 0;
|
|
4930
4934
|
}
|
|
@@ -5156,7 +5160,7 @@ function isProcessAlive(pid) {
|
|
|
5156
5160
|
async function autopsyWriterLock(lockPath) {
|
|
5157
5161
|
let content;
|
|
5158
5162
|
try {
|
|
5159
|
-
content = await
|
|
5163
|
+
content = await readFile8(lockPath, "utf8");
|
|
5160
5164
|
} catch (error) {
|
|
5161
5165
|
if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
|
|
5162
5166
|
return { verdict: "absent", readFailure: error };
|
|
@@ -5325,7 +5329,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
5325
5329
|
let raw;
|
|
5326
5330
|
try {
|
|
5327
5331
|
raw = JSON.parse(
|
|
5328
|
-
await
|
|
5332
|
+
await readFile8(join12(runDirectory, "admitted-request.json"), "utf8")
|
|
5329
5333
|
);
|
|
5330
5334
|
} catch (error) {
|
|
5331
5335
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
@@ -5436,7 +5440,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
5436
5440
|
let sourceRun;
|
|
5437
5441
|
try {
|
|
5438
5442
|
const raw = JSON.parse(
|
|
5439
|
-
await
|
|
5443
|
+
await readFile8(run.admittedRequestPath, "utf8")
|
|
5440
5444
|
);
|
|
5441
5445
|
if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
|
|
5442
5446
|
const record4 = raw;
|
|
@@ -5527,11 +5531,10 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
5527
5531
|
}
|
|
5528
5532
|
if (record4.derived !== null && typeof record4.derived === "object" && !Array.isArray(record4.derived)) {
|
|
5529
5533
|
const d = record4.derived;
|
|
5530
|
-
if (typeof d.targetObjectId === "string" && typeof d.sourceObjectId === "string" &&
|
|
5534
|
+
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")) {
|
|
5531
5535
|
derived = {
|
|
5532
5536
|
targetObjectId: d.targetObjectId,
|
|
5533
5537
|
sourceObjectId: d.sourceObjectId,
|
|
5534
|
-
automaticMergeTreeId: d.automaticMergeTreeId,
|
|
5535
5538
|
expectedConflictPaths: d.expectedConflictPaths,
|
|
5536
5539
|
resolutionScope: d.resolutionScope
|
|
5537
5540
|
};
|
|
@@ -5551,7 +5554,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
5551
5554
|
let model;
|
|
5552
5555
|
try {
|
|
5553
5556
|
const invocationRaw = JSON.parse(
|
|
5554
|
-
await
|
|
5557
|
+
await readFile8(join12(run.runDirectory, "invocation.json"), "utf8")
|
|
5555
5558
|
);
|
|
5556
5559
|
if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
|
|
5557
5560
|
const rec = invocationRaw;
|
|
@@ -5750,7 +5753,7 @@ __export(notary_source_run_exports, {
|
|
|
5750
5753
|
loadNotarySourceRunLocator: () => loadNotarySourceRunLocator,
|
|
5751
5754
|
resolveNotarySourceRunLocator: () => resolveNotarySourceRunLocator
|
|
5752
5755
|
});
|
|
5753
|
-
import { dirname as dirname8, isAbsolute as
|
|
5756
|
+
import { dirname as dirname8, isAbsolute as isAbsolute6, join as join13, resolve as resolve9, basename as basename5 } from "node:path";
|
|
5754
5757
|
import { lstat as lstat2, realpath as realpath3 } from "node:fs/promises";
|
|
5755
5758
|
function parseRunDirectoryName(name) {
|
|
5756
5759
|
const match = RUN_DIR_NAME.exec(name);
|
|
@@ -5802,7 +5805,7 @@ async function resolveNotarySourceRunLocator(options) {
|
|
|
5802
5805
|
if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
|
|
5803
5806
|
candidate = join13(bookRunsRoot, `${bare.runId}@${bare.role}`);
|
|
5804
5807
|
} else {
|
|
5805
|
-
candidate =
|
|
5808
|
+
candidate = isAbsolute6(raw) ? raw : resolve9(options.projectRoot, raw);
|
|
5806
5809
|
}
|
|
5807
5810
|
const real = await requireRunDirectory(candidate, raw);
|
|
5808
5811
|
const identity = parseRunDirectoryName(basename5(real));
|
|
@@ -6483,7 +6486,7 @@ var init_option_definitions = __esm({
|
|
|
6483
6486
|
}
|
|
6484
6487
|
];
|
|
6485
6488
|
MERGER_OPTIONS = [
|
|
6486
|
-
// Merger project face
|
|
6489
|
+
// Merger project face: worktree whose Git materials are handed to the role.
|
|
6487
6490
|
{
|
|
6488
6491
|
id: "project",
|
|
6489
6492
|
owner: "merger",
|
|
@@ -6494,8 +6497,8 @@ var init_option_definitions = __esm({
|
|
|
6494
6497
|
repeatable: false,
|
|
6495
6498
|
form: "option",
|
|
6496
6499
|
description: {
|
|
6497
|
-
en: "Project root
|
|
6498
|
-
zh: "\
|
|
6500
|
+
en: "Project root whose Git merge materials are read (defaults to cwd).",
|
|
6501
|
+
zh: "\u8BFB\u53D6 Git merge \u6750\u6599\u7684\u9879\u76EE\u6839\uFF08\u9ED8\u8BA4 cwd\uFF09\u3002"
|
|
6499
6502
|
}
|
|
6500
6503
|
},
|
|
6501
6504
|
bindOwner("merger", SHARED_ATTACH_SEMANTICS)
|
|
@@ -6736,10 +6739,10 @@ var init_option_definitions = __esm({
|
|
|
6736
6739
|
},
|
|
6737
6740
|
merger: {
|
|
6738
6741
|
command: "merger",
|
|
6739
|
-
summary: "
|
|
6742
|
+
summary: "Reconcile merge materials in a worktree (escalate when nothing to merge).",
|
|
6740
6743
|
usage: ["ak-role merger [options] <instruction>"],
|
|
6741
6744
|
examples: [
|
|
6742
|
-
'ak-role merger --project /path/to/worktree "Reconcile the
|
|
6745
|
+
'ak-role merger --project /path/to/worktree "Reconcile the merge."'
|
|
6743
6746
|
]
|
|
6744
6747
|
},
|
|
6745
6748
|
inspector: {
|
|
@@ -6874,7 +6877,6 @@ var init_option_definitions = __esm({
|
|
|
6874
6877
|
// src/public-cli/invocation.ts
|
|
6875
6878
|
var invocation_exports = {};
|
|
6876
6879
|
__export(invocation_exports, {
|
|
6877
|
-
MergerEnvelopeDerivationError: () => MergerEnvelopeDerivationError,
|
|
6878
6880
|
admitAuditorInvocation: () => admitAuditorInvocation,
|
|
6879
6881
|
admitCoderInvocation: () => admitCoderInvocation,
|
|
6880
6882
|
admitCollectorInvocation: () => admitCollectorInvocation,
|
|
@@ -6944,11 +6946,11 @@ import { existsSync as existsSync5 } from "node:fs";
|
|
|
6944
6946
|
import {
|
|
6945
6947
|
lstat as lstat3,
|
|
6946
6948
|
mkdir,
|
|
6947
|
-
readFile as
|
|
6949
|
+
readFile as readFile9,
|
|
6948
6950
|
realpath as realpath4,
|
|
6949
6951
|
writeFile as writeFile4
|
|
6950
6952
|
} from "node:fs/promises";
|
|
6951
|
-
import { basename as basename6, isAbsolute as
|
|
6953
|
+
import { basename as basename6, isAbsolute as isAbsolute7, join as join14, resolve as resolve10, sep as sep3 } from "node:path";
|
|
6952
6954
|
function issueAdmissionPlacement(authority, request) {
|
|
6953
6955
|
const principal = authority.issue(request);
|
|
6954
6956
|
const { sessionDirectory, sessionFile } = authority.decode(principal);
|
|
@@ -7008,7 +7010,7 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
|
|
|
7008
7010
|
}
|
|
7009
7011
|
async function recordEffectiveInvocationModel(runDirectory, model, engine, host) {
|
|
7010
7012
|
const ledgerPath = join14(runDirectory, "invocation.json");
|
|
7011
|
-
const current = JSON.parse(await
|
|
7013
|
+
const current = JSON.parse(await readFile9(ledgerPath, "utf8"));
|
|
7012
7014
|
const next = { ...current };
|
|
7013
7015
|
if (model !== void 0) {
|
|
7014
7016
|
next.provider = model.provider;
|
|
@@ -7036,7 +7038,7 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host)
|
|
|
7036
7038
|
}
|
|
7037
7039
|
async function mergeInvocationIdentityPage(runDirectory, fields) {
|
|
7038
7040
|
const ledgerPath = join14(runDirectory, "invocation.json");
|
|
7039
|
-
const current = JSON.parse(await
|
|
7041
|
+
const current = JSON.parse(await readFile9(ledgerPath, "utf8"));
|
|
7040
7042
|
await writeFile4(
|
|
7041
7043
|
ledgerPath,
|
|
7042
7044
|
`${JSON.stringify({
|
|
@@ -7052,7 +7054,7 @@ async function persistAdmittedSourceRunPath(admitted, sourceRunPath) {
|
|
|
7052
7054
|
throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
|
|
7053
7055
|
}
|
|
7054
7056
|
const admittedPath = admitted.admittedRequestPath;
|
|
7055
|
-
const current = JSON.parse(await
|
|
7057
|
+
const current = JSON.parse(await readFile9(admittedPath, "utf8"));
|
|
7056
7058
|
if (typeof current.sourceRunPath === "string") {
|
|
7057
7059
|
if (current.sourceRunPath === sourceRunPath) return;
|
|
7058
7060
|
throw new Error(
|
|
@@ -7079,7 +7081,7 @@ async function bindAdmittedTicketNumber(admitted, ticketNumber) {
|
|
|
7079
7081
|
admitted.ticketNumber = ticketNumber;
|
|
7080
7082
|
await mergeInvocationIdentityPage(admitted.runDirectory, { ticketNumber });
|
|
7081
7083
|
const admittedPath = admitted.admittedRequestPath;
|
|
7082
|
-
const current = JSON.parse(await
|
|
7084
|
+
const current = JSON.parse(await readFile9(admittedPath, "utf8"));
|
|
7083
7085
|
await writeFile4(
|
|
7084
7086
|
admittedPath,
|
|
7085
7087
|
`${JSON.stringify({ ...current, ticketNumber }, null, 2)}
|
|
@@ -7095,7 +7097,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
|
7095
7097
|
}
|
|
7096
7098
|
const admittedPath = join14(runDirectory, "admitted-request.json");
|
|
7097
7099
|
const invocationPath = join14(runDirectory, "invocation.json");
|
|
7098
|
-
const admitted = JSON.parse(await
|
|
7100
|
+
const admitted = JSON.parse(await readFile9(admittedPath, "utf8"));
|
|
7099
7101
|
const existing = admitted.ticketNumber;
|
|
7100
7102
|
if (typeof existing === "number") {
|
|
7101
7103
|
if (existing === ticketNumber) return;
|
|
@@ -7105,7 +7107,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
|
7105
7107
|
}
|
|
7106
7108
|
if (existsSync5(invocationPath)) {
|
|
7107
7109
|
const invocation = JSON.parse(
|
|
7108
|
-
await
|
|
7110
|
+
await readFile9(invocationPath, "utf8")
|
|
7109
7111
|
);
|
|
7110
7112
|
if (typeof invocation.ticketNumber === "number" && invocation.ticketNumber !== ticketNumber) {
|
|
7111
7113
|
throw new Error(
|
|
@@ -7130,7 +7132,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
|
|
|
7130
7132
|
async function observeLaunchedRolePackageIdentity(packageRoot, selectedRoleEntry) {
|
|
7131
7133
|
const rolePackageRoot = packageRoot;
|
|
7132
7134
|
const raw = JSON.parse(
|
|
7133
|
-
await
|
|
7135
|
+
await readFile9(join14(rolePackageRoot, "package.json"), "utf8")
|
|
7134
7136
|
);
|
|
7135
7137
|
if (typeof raw.version !== "string" || raw.version.trim() === "") {
|
|
7136
7138
|
throw new Error(
|
|
@@ -7371,7 +7373,7 @@ function parseFixerArgv(args) {
|
|
|
7371
7373
|
};
|
|
7372
7374
|
}
|
|
7373
7375
|
async function freezeRegularFileAttachment(sourcePath, destinationDir, index) {
|
|
7374
|
-
const absolute =
|
|
7376
|
+
const absolute = isAbsolute7(sourcePath) ? sourcePath : resolve10(sourcePath);
|
|
7375
7377
|
let st;
|
|
7376
7378
|
try {
|
|
7377
7379
|
st = await lstat3(absolute);
|
|
@@ -7386,7 +7388,7 @@ async function freezeRegularFileAttachment(sourcePath, destinationDir, index) {
|
|
|
7386
7388
|
`attachment must be a regular file (not a directory or symlink): ${sourcePath}`
|
|
7387
7389
|
);
|
|
7388
7390
|
}
|
|
7389
|
-
const bytes = await
|
|
7391
|
+
const bytes = await readFile9(absolute);
|
|
7390
7392
|
const name = `${String(index).padStart(2, "0")}-${basename6(absolute)}`;
|
|
7391
7393
|
const frozenPath = join14(destinationDir, name);
|
|
7392
7394
|
await writeFile4(frozenPath, bytes);
|
|
@@ -7427,7 +7429,7 @@ async function admitStandardMaterialInvocation(role, options) {
|
|
|
7427
7429
|
if (options.project !== void 0) {
|
|
7428
7430
|
requireOptionPath("--project", options.project);
|
|
7429
7431
|
}
|
|
7430
|
-
const projectRoot =
|
|
7432
|
+
const projectRoot = resolve10(options.project ?? options.cwd);
|
|
7431
7433
|
const runId = (options.createRunId ?? uuidv7)();
|
|
7432
7434
|
const {
|
|
7433
7435
|
principal,
|
|
@@ -7530,7 +7532,7 @@ async function admitCountersignInvocation(options) {
|
|
|
7530
7532
|
if (options.project !== void 0) {
|
|
7531
7533
|
requireOptionPath("--project", options.project);
|
|
7532
7534
|
}
|
|
7533
|
-
const projectRoot =
|
|
7535
|
+
const projectRoot = resolve10(options.project ?? options.cwd);
|
|
7534
7536
|
const runId = (options.createRunId ?? uuidv7)();
|
|
7535
7537
|
const {
|
|
7536
7538
|
principal,
|
|
@@ -7595,7 +7597,7 @@ function buildCountersignTransportPrompt(admitted, engineMaterial) {
|
|
|
7595
7597
|
async function loadAdmittedJudgeRequest(runDirectory) {
|
|
7596
7598
|
try {
|
|
7597
7599
|
const raw = JSON.parse(
|
|
7598
|
-
await
|
|
7600
|
+
await readFile9(join14(runDirectory, "admitted-request.json"), "utf8")
|
|
7599
7601
|
);
|
|
7600
7602
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
7601
7603
|
const record4 = raw;
|
|
@@ -7630,7 +7632,7 @@ async function admitCoderInvocation(options) {
|
|
|
7630
7632
|
if (options.phase !== "plan" && options.phase !== "apply") {
|
|
7631
7633
|
throw new CliUsageError("coder phase must be plan or apply");
|
|
7632
7634
|
}
|
|
7633
|
-
const projectRoot =
|
|
7635
|
+
const projectRoot = resolve10(options.project ?? options.cwd);
|
|
7634
7636
|
const runId = (options.createRunId ?? uuidv7)();
|
|
7635
7637
|
const {
|
|
7636
7638
|
principal,
|
|
@@ -7718,9 +7720,9 @@ async function admitFixerInvocation(options) {
|
|
|
7718
7720
|
let prerequisites = Object.freeze([]);
|
|
7719
7721
|
let prerequisitesSource;
|
|
7720
7722
|
if (options.prerequisitesPath !== void 0) {
|
|
7721
|
-
const absolutePrereq =
|
|
7723
|
+
const absolutePrereq = isAbsolute7(options.prerequisitesPath) ? options.prerequisitesPath : resolve10(options.prerequisitesPath);
|
|
7722
7724
|
try {
|
|
7723
|
-
prerequisitesSource = await
|
|
7725
|
+
prerequisitesSource = await readFile9(absolutePrereq, "utf8");
|
|
7724
7726
|
} catch (error) {
|
|
7725
7727
|
throw new CliUsageError(
|
|
7726
7728
|
`fixer prerequisites path is unreadable: ${options.prerequisitesPath}`,
|
|
@@ -7736,7 +7738,7 @@ async function admitFixerInvocation(options) {
|
|
|
7736
7738
|
throw error;
|
|
7737
7739
|
}
|
|
7738
7740
|
}
|
|
7739
|
-
const projectRoot =
|
|
7741
|
+
const projectRoot = resolve10(options.project ?? options.cwd);
|
|
7740
7742
|
const runId = (options.createRunId ?? uuidv7)();
|
|
7741
7743
|
const {
|
|
7742
7744
|
principal,
|
|
@@ -7961,7 +7963,7 @@ async function admitCollectorInvocation(options) {
|
|
|
7961
7963
|
throw new CliUsageError(detail, { cause: error });
|
|
7962
7964
|
}
|
|
7963
7965
|
}
|
|
7964
|
-
const projectRoot =
|
|
7966
|
+
const projectRoot = resolve10(options.project ?? options.cwd);
|
|
7965
7967
|
let repository;
|
|
7966
7968
|
if (options.repo !== void 0) {
|
|
7967
7969
|
try {
|
|
@@ -8149,12 +8151,12 @@ async function resolveDoctorCaseRunsPath(options) {
|
|
|
8149
8151
|
if (raw === "") {
|
|
8150
8152
|
throw new CliUsageError("doctor --runs requires a path");
|
|
8151
8153
|
}
|
|
8152
|
-
if (
|
|
8154
|
+
if (isAbsolute7(raw)) {
|
|
8153
8155
|
throw new CliUsageError(
|
|
8154
8156
|
"doctor --runs must be a project-relative path"
|
|
8155
8157
|
);
|
|
8156
8158
|
}
|
|
8157
|
-
const resolved =
|
|
8159
|
+
const resolved = resolve10(options.projectRoot, raw);
|
|
8158
8160
|
if (resolved !== options.projectRoot && !pathContainedIn(options.projectRoot, resolved)) {
|
|
8159
8161
|
throw new CliUsageError(
|
|
8160
8162
|
"doctor --runs escapes the project root"
|
|
@@ -8193,7 +8195,7 @@ async function admitDoctorInvocation(options) {
|
|
|
8193
8195
|
`doctor --issue must be a positive integer, got ${options.issueNumber}`
|
|
8194
8196
|
);
|
|
8195
8197
|
}
|
|
8196
|
-
const projectRoot =
|
|
8198
|
+
const projectRoot = resolve10(options.project ?? options.cwd);
|
|
8197
8199
|
const runId = (options.createRunId ?? uuidv7)();
|
|
8198
8200
|
const {
|
|
8199
8201
|
principal,
|
|
@@ -8354,7 +8356,7 @@ async function admitNotaryInvocation(options) {
|
|
|
8354
8356
|
if (options.project !== void 0) {
|
|
8355
8357
|
requireOptionPath("--project", options.project);
|
|
8356
8358
|
}
|
|
8357
|
-
const projectRoot =
|
|
8359
|
+
const projectRoot = resolve10(options.project ?? options.cwd);
|
|
8358
8360
|
let sourceRun;
|
|
8359
8361
|
try {
|
|
8360
8362
|
sourceRun = await resolveNotarySourceRunLocator({
|
|
@@ -8472,7 +8474,7 @@ async function admitGleanerLeftInvocation(options) {
|
|
|
8472
8474
|
if (options.baseRevision.trim() === "") {
|
|
8473
8475
|
throw new CliUsageError("--base requires a nonempty revision");
|
|
8474
8476
|
}
|
|
8475
|
-
const projectRoot =
|
|
8477
|
+
const projectRoot = resolve10(options.project ?? options.cwd);
|
|
8476
8478
|
const runId = (options.createRunId ?? uuidv7)();
|
|
8477
8479
|
const {
|
|
8478
8480
|
principal,
|
|
@@ -8593,7 +8595,7 @@ async function admitReviewerInvocation(options) {
|
|
|
8593
8595
|
const authorityRefs = Object.freeze(
|
|
8594
8596
|
(options.authorityRefs ?? []).map((ref) => requireAuthorityRef(ref))
|
|
8595
8597
|
);
|
|
8596
|
-
const projectRoot =
|
|
8598
|
+
const projectRoot = resolve10(options.project ?? options.cwd);
|
|
8597
8599
|
const runId = (options.createRunId ?? uuidv7)();
|
|
8598
8600
|
const {
|
|
8599
8601
|
principal,
|
|
@@ -8688,7 +8690,7 @@ function parseMergerArgv(args) {
|
|
|
8688
8690
|
const token = tokens.shift();
|
|
8689
8691
|
if (isRejectedPublicSpelling("merger", token) || token === "--targetObjectId" || token.startsWith("--targetObjectId=") || token === "--sourceObjectId" || token.startsWith("--sourceObjectId=") || token === "--expectedConflictPaths" || token.startsWith("--expectedConflictPaths=") || token === "--resolutionScope" || token.startsWith("--resolutionScope=")) {
|
|
8690
8692
|
throw new CliUsageError(
|
|
8691
|
-
"merger does not accept public packet fields; the adapter
|
|
8693
|
+
"merger does not accept public packet fields; the adapter reads Git merge materials"
|
|
8692
8694
|
);
|
|
8693
8695
|
}
|
|
8694
8696
|
if (token.startsWith("-") && token !== "-") {
|
|
@@ -8711,24 +8713,12 @@ function mergerMaterialFromUtf8(text) {
|
|
|
8711
8713
|
});
|
|
8712
8714
|
}
|
|
8713
8715
|
async function deriveMergerEnvelopeFromActiveMerge(projectRoot, gitState = createProductionMergerGitState(projectRoot)) {
|
|
8714
|
-
|
|
8715
|
-
try {
|
|
8716
|
-
state = await gitState.activeMerge();
|
|
8717
|
-
} catch (error) {
|
|
8718
|
-
const message = error instanceof Error && error.message.trim() !== "" ? error.message : "Assigned repository does not have one ordinary in-progress merge";
|
|
8719
|
-
throw new MergerEnvelopeDerivationError(message, { cause: error });
|
|
8720
|
-
}
|
|
8721
|
-
if (state.unmergedPaths.length === 0) {
|
|
8722
|
-
throw new MergerEnvelopeDerivationError(
|
|
8723
|
-
"Assigned repository does not have one ordinary in-progress merge with a complete conflict set"
|
|
8724
|
-
);
|
|
8725
|
-
}
|
|
8716
|
+
const state = await gitState.activeMerge();
|
|
8726
8717
|
const expectedConflictPaths = Object.freeze([...state.unmergedPaths]);
|
|
8727
8718
|
const resolutionScope = Object.freeze([...state.unmergedPaths]);
|
|
8728
8719
|
return Object.freeze({
|
|
8729
8720
|
targetObjectId: state.targetObjectId,
|
|
8730
8721
|
sourceObjectId: state.sourceObjectId,
|
|
8731
|
-
automaticMergeTreeId: state.automaticMergeTreeId,
|
|
8732
8722
|
expectedConflictPaths,
|
|
8733
8723
|
resolutionScope
|
|
8734
8724
|
});
|
|
@@ -8741,7 +8731,7 @@ async function admitMergerInvocation(options) {
|
|
|
8741
8731
|
if (instruction.trim() === "") {
|
|
8742
8732
|
throw new CliUsageError("merger requires a nonblank task instruction");
|
|
8743
8733
|
}
|
|
8744
|
-
const projectRoot =
|
|
8734
|
+
const projectRoot = resolve10(options.project ?? options.cwd);
|
|
8745
8735
|
const derived = await deriveMergerEnvelopeFromActiveMerge(
|
|
8746
8736
|
projectRoot,
|
|
8747
8737
|
options.gitState ?? createProductionMergerGitState(projectRoot)
|
|
@@ -8764,16 +8754,17 @@ async function admitMergerInvocation(options) {
|
|
|
8764
8754
|
ensureRealDirectoryTree(ledgerHome, sessionDirectory);
|
|
8765
8755
|
ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
|
|
8766
8756
|
const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
|
|
8757
|
+
const targetLabel = derived.targetObjectId === "" ? "(none observed)" : derived.targetObjectId;
|
|
8758
|
+
const sourceLabel = derived.sourceObjectId === "" ? "(none observed)" : derived.sourceObjectId;
|
|
8767
8759
|
const targetIntent = mergerMaterialFromUtf8(
|
|
8768
|
-
`Investigate primary sources for target parent ${
|
|
8760
|
+
`Investigate primary sources for target parent ${targetLabel}. Do not invent intent.`
|
|
8769
8761
|
);
|
|
8770
8762
|
const sourceIntent = mergerMaterialFromUtf8(
|
|
8771
|
-
`Investigate primary sources for source parent ${
|
|
8763
|
+
`Investigate primary sources for source parent ${sourceLabel}. Do not invent intent.`
|
|
8772
8764
|
);
|
|
8773
8765
|
const taskMaterial = mergerMaterialFromUtf8(instruction);
|
|
8774
8766
|
const authorityMaterial = mergerMaterialFromUtf8(instruction);
|
|
8775
8767
|
const mergerInput = validateMergerInput({
|
|
8776
|
-
version: 1,
|
|
8777
8768
|
attemptId: runId,
|
|
8778
8769
|
targetObjectId: derived.targetObjectId,
|
|
8779
8770
|
sourceObjectId: derived.sourceObjectId,
|
|
@@ -8785,7 +8776,6 @@ async function admitMergerInvocation(options) {
|
|
|
8785
8776
|
},
|
|
8786
8777
|
expectedConflictPaths: [...derived.expectedConflictPaths],
|
|
8787
8778
|
resolutionScope: [...derived.resolutionScope],
|
|
8788
|
-
// Authorized checks remain available on the assignment; default none.
|
|
8789
8779
|
authorizedChecks: []
|
|
8790
8780
|
});
|
|
8791
8781
|
const mergerInputPath = join14(runDirectory, "merger-input.json");
|
|
@@ -8808,7 +8798,6 @@ async function admitMergerInvocation(options) {
|
|
|
8808
8798
|
derived: {
|
|
8809
8799
|
targetObjectId: derived.targetObjectId,
|
|
8810
8800
|
sourceObjectId: derived.sourceObjectId,
|
|
8811
|
-
automaticMergeTreeId: derived.automaticMergeTreeId,
|
|
8812
8801
|
expectedConflictPaths: [...derived.expectedConflictPaths],
|
|
8813
8802
|
resolutionScope: [...derived.resolutionScope]
|
|
8814
8803
|
},
|
|
@@ -9072,7 +9061,7 @@ function parseAnalystArgv(args) {
|
|
|
9072
9061
|
...ticketRaw === void 0 ? {} : { ticket: parseAnalystTicketNumber(ticketRaw) }
|
|
9073
9062
|
};
|
|
9074
9063
|
}
|
|
9075
|
-
var
|
|
9064
|
+
var DOCTOR_ISSUE_NUMBER_PATTERN, DOCTOR_CASE_RUNS_PATH_PATTERN, ANALYST_TICKET_NUMBER_PATTERN;
|
|
9076
9065
|
var init_invocation = __esm({
|
|
9077
9066
|
"src/public-cli/invocation.ts"() {
|
|
9078
9067
|
"use strict";
|
|
@@ -9093,15 +9082,6 @@ var init_invocation = __esm({
|
|
|
9093
9082
|
init_engine_material();
|
|
9094
9083
|
init_cli_errors();
|
|
9095
9084
|
init_option_definitions();
|
|
9096
|
-
MergerEnvelopeDerivationError = class extends Error {
|
|
9097
|
-
code = "merger-envelope-derivation";
|
|
9098
|
-
/** Typed cause for #107 classifyPostAdmissionFailure (isTypedActivationError). */
|
|
9099
|
-
knownCause = "activation";
|
|
9100
|
-
constructor(message, options) {
|
|
9101
|
-
super(message, options);
|
|
9102
|
-
this.name = "MergerEnvelopeDerivationError";
|
|
9103
|
-
}
|
|
9104
|
-
};
|
|
9105
9085
|
DOCTOR_ISSUE_NUMBER_PATTERN = /^[1-9]\d*$/;
|
|
9106
9086
|
DOCTOR_CASE_RUNS_PATH_PATTERN = /\/\.ak-roles\/books\/[^/]+\/issues\/([1-9]\d*)\/runs$/;
|
|
9107
9087
|
ANALYST_TICKET_NUMBER_PATTERN = /^[1-9]\d*$/;
|
|
@@ -9662,7 +9642,7 @@ __export(config_exports, {
|
|
|
9662
9642
|
setPersistentSeatHost: () => setPersistentSeatHost,
|
|
9663
9643
|
validatePublicCliConfigAxes: () => validatePublicCliConfigAxes
|
|
9664
9644
|
});
|
|
9665
|
-
import { mkdir as mkdir2, readFile as
|
|
9645
|
+
import { mkdir as mkdir2, readFile as readFile10, writeFile as writeFile5 } from "node:fs/promises";
|
|
9666
9646
|
import { dirname as dirname9, join as join18 } from "node:path";
|
|
9667
9647
|
function isGateOfficerSeat(value) {
|
|
9668
9648
|
return GATE_OFFICER_SEATS.includes(value);
|
|
@@ -9676,7 +9656,7 @@ function publicCliConfigPath(home) {
|
|
|
9676
9656
|
async function loadPublicCliConfig(home) {
|
|
9677
9657
|
const path = publicCliConfigPath(home);
|
|
9678
9658
|
try {
|
|
9679
|
-
const raw = await
|
|
9659
|
+
const raw = await readFile10(path, "utf8");
|
|
9680
9660
|
return parsePublicCliConfig(JSON.parse(raw));
|
|
9681
9661
|
} catch (error) {
|
|
9682
9662
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -10080,7 +10060,7 @@ function credentialProvidersFromAuthData(data) {
|
|
|
10080
10060
|
}
|
|
10081
10061
|
async function loadCredentialProviders(agentDir) {
|
|
10082
10062
|
try {
|
|
10083
|
-
const raw = await
|
|
10063
|
+
const raw = await readFile10(join18(agentDir, "auth.json"), "utf8");
|
|
10084
10064
|
return credentialProvidersFromAuthData(JSON.parse(raw));
|
|
10085
10065
|
} catch (error) {
|
|
10086
10066
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -10423,14 +10403,14 @@ var init_case_dossier_delivery = __esm({
|
|
|
10423
10403
|
});
|
|
10424
10404
|
|
|
10425
10405
|
// src/host-transition-prior-native.ts
|
|
10426
|
-
import { access as
|
|
10406
|
+
import { access as access3, readdir as readdir3 } from "node:fs/promises";
|
|
10427
10407
|
import { dirname as dirname10, join as join20 } from "node:path";
|
|
10428
10408
|
function isEnoent2(error) {
|
|
10429
10409
|
return typeof error === "object" && error !== null && error.code === "ENOENT";
|
|
10430
10410
|
}
|
|
10431
10411
|
async function listPiNativeRecordPaths(sessionFile) {
|
|
10432
10412
|
try {
|
|
10433
|
-
await
|
|
10413
|
+
await access3(sessionFile);
|
|
10434
10414
|
return [sessionFile];
|
|
10435
10415
|
} catch (error) {
|
|
10436
10416
|
if (isEnoent2(error)) return [];
|
|
@@ -10451,7 +10431,7 @@ async function listSitianRecordPaths(sessionParent) {
|
|
|
10451
10431
|
if (!entry.isDirectory()) continue;
|
|
10452
10432
|
const recordFile = join20(sessionRoot, entry.name, "records.jsonl");
|
|
10453
10433
|
try {
|
|
10454
|
-
await
|
|
10434
|
+
await access3(recordFile);
|
|
10455
10435
|
recordPaths.push(recordFile);
|
|
10456
10436
|
} catch (error) {
|
|
10457
10437
|
if (!isEnoent2(error)) throw error;
|
|
@@ -10841,10 +10821,10 @@ __export(session_assistant_usage_exports, {
|
|
|
10841
10821
|
});
|
|
10842
10822
|
import { join as join22 } from "node:path";
|
|
10843
10823
|
async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
10844
|
-
const { readFile:
|
|
10824
|
+
const { readFile: readFile23 } = await import("node:fs/promises");
|
|
10845
10825
|
let text;
|
|
10846
10826
|
try {
|
|
10847
|
-
text = await
|
|
10827
|
+
text = await readFile23(sessionFile, "utf8");
|
|
10848
10828
|
} catch (error) {
|
|
10849
10829
|
if (error?.code === "ENOENT") return void 0;
|
|
10850
10830
|
throw error;
|
|
@@ -11060,12 +11040,12 @@ var init_compliance_transport = __esm({
|
|
|
11060
11040
|
});
|
|
11061
11041
|
|
|
11062
11042
|
// src/ledger-session-read.ts
|
|
11063
|
-
import { readFile as
|
|
11043
|
+
import { readFile as readFile11 } from "node:fs/promises";
|
|
11064
11044
|
function isRecord12(value) {
|
|
11065
11045
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11066
11046
|
}
|
|
11067
11047
|
async function readLedgerSessionJsonl(path) {
|
|
11068
|
-
const text = await
|
|
11048
|
+
const text = await readFile11(path, "utf8");
|
|
11069
11049
|
const lines = text.split("\n");
|
|
11070
11050
|
const rows = [];
|
|
11071
11051
|
for (let index = 0; index < lines.length; index += 1) {
|
|
@@ -11374,10 +11354,10 @@ function pairGateRounds(volumes) {
|
|
|
11374
11354
|
return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
|
|
11375
11355
|
}
|
|
11376
11356
|
async function resolveOfficerSessionFromPointerFile(pointerPath) {
|
|
11377
|
-
const { readFile:
|
|
11357
|
+
const { readFile: readFile23 } = await import("node:fs/promises");
|
|
11378
11358
|
let raw;
|
|
11379
11359
|
try {
|
|
11380
|
-
raw = JSON.parse(await
|
|
11360
|
+
raw = JSON.parse(await readFile23(pointerPath, "utf8"));
|
|
11381
11361
|
} catch (error) {
|
|
11382
11362
|
throw new Error(
|
|
11383
11363
|
`direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -11452,7 +11432,7 @@ var init_analyst_gate_cycles_read = __esm({
|
|
|
11452
11432
|
|
|
11453
11433
|
// src/session-opening-materials.ts
|
|
11454
11434
|
import { existsSync as existsSync8 } from "node:fs";
|
|
11455
|
-
import { readFile as
|
|
11435
|
+
import { readFile as readFile12 } from "node:fs/promises";
|
|
11456
11436
|
import { dirname as dirname12, join as join24 } from "node:path";
|
|
11457
11437
|
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
11458
11438
|
function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
@@ -11468,7 +11448,7 @@ function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
|
11468
11448
|
return fileURLToPath(new URL("..", moduleUrl));
|
|
11469
11449
|
}
|
|
11470
11450
|
async function readPackageMaterial(relativePath) {
|
|
11471
|
-
return
|
|
11451
|
+
return readFile12(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
|
|
11472
11452
|
}
|
|
11473
11453
|
async function joinPackageMaterials(relativePaths) {
|
|
11474
11454
|
const chunks = [];
|
|
@@ -11567,13 +11547,13 @@ var init_auditor_soul = __esm({
|
|
|
11567
11547
|
|
|
11568
11548
|
// src/dossier-resolution.ts
|
|
11569
11549
|
import { existsSync as existsSync9, statSync as statSync2 } from "node:fs";
|
|
11570
|
-
import { resolve as
|
|
11550
|
+
import { resolve as resolve11 } from "node:path";
|
|
11571
11551
|
function resolveAuditDossier(env = process.env) {
|
|
11572
11552
|
const raw = env[AUDIT_RUN_DIR_ENV];
|
|
11573
11553
|
if (typeof raw !== "string" || raw.trim() === "") {
|
|
11574
11554
|
return { status: "ok" };
|
|
11575
11555
|
}
|
|
11576
|
-
const runDirectory =
|
|
11556
|
+
const runDirectory = resolve11(raw);
|
|
11577
11557
|
try {
|
|
11578
11558
|
if (!existsSync9(runDirectory) || !statSync2(runDirectory).isDirectory()) {
|
|
11579
11559
|
return { status: "incomplete", observation: { kind: "missing-dossier" } };
|
|
@@ -11789,7 +11769,7 @@ var init_reviewer_preflight_error = __esm({
|
|
|
11789
11769
|
|
|
11790
11770
|
// src/reviewer-pinned-git.ts
|
|
11791
11771
|
import { execFile as execFile3 } from "node:child_process";
|
|
11792
|
-
import { access as
|
|
11772
|
+
import { access as access4, realpath as realpath5 } from "node:fs/promises";
|
|
11793
11773
|
import { promisify as promisify3 } from "node:util";
|
|
11794
11774
|
async function execGit(args, options) {
|
|
11795
11775
|
try {
|
|
@@ -11823,7 +11803,7 @@ function isConfirmedPinnedPathAbsent(error, path) {
|
|
|
11823
11803
|
}
|
|
11824
11804
|
async function repositoryIsAvailable(root) {
|
|
11825
11805
|
try {
|
|
11826
|
-
await
|
|
11806
|
+
await access4(`${root}/.git`);
|
|
11827
11807
|
return { available: true };
|
|
11828
11808
|
} catch (cause) {
|
|
11829
11809
|
return { available: false, cause };
|
|
@@ -12409,7 +12389,7 @@ var init_reviewer_dispatch = __esm({
|
|
|
12409
12389
|
|
|
12410
12390
|
// src/public-cli/reviewer-dispatch-rejection.ts
|
|
12411
12391
|
import { writeFileSync as writeFileSync5 } from "node:fs";
|
|
12412
|
-
import { readFile as
|
|
12392
|
+
import { readFile as readFile13, unlink as unlink3 } from "node:fs/promises";
|
|
12413
12393
|
import { join as join25 } from "node:path";
|
|
12414
12394
|
function isReviewerPreflightViolation(value) {
|
|
12415
12395
|
return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
|
|
@@ -12428,7 +12408,7 @@ function recordReviewerDispatchRejectionSync(runDirectory, rejection) {
|
|
|
12428
12408
|
async function readReviewerDispatchRejection(runDirectory) {
|
|
12429
12409
|
let raw;
|
|
12430
12410
|
try {
|
|
12431
|
-
raw = await
|
|
12411
|
+
raw = await readFile13(reviewerDispatchRejectionPath(runDirectory), "utf8");
|
|
12432
12412
|
} catch (error) {
|
|
12433
12413
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
12434
12414
|
return void 0;
|
|
@@ -12470,12 +12450,12 @@ function createSystemCollectorClock() {
|
|
|
12470
12450
|
return {
|
|
12471
12451
|
wallNow: () => /* @__PURE__ */ new Date(),
|
|
12472
12452
|
monoNow: () => Number(process.hrtime.bigint() - start) / 1e6,
|
|
12473
|
-
sleep: (ms, signal) => new Promise((
|
|
12453
|
+
sleep: (ms, signal) => new Promise((resolve21, reject) => {
|
|
12474
12454
|
if (signal?.aborted) {
|
|
12475
12455
|
reject(signal.reason ?? new Error("aborted"));
|
|
12476
12456
|
return;
|
|
12477
12457
|
}
|
|
12478
|
-
const timer = setTimeout(
|
|
12458
|
+
const timer = setTimeout(resolve21, ms);
|
|
12479
12459
|
const onAbort = () => {
|
|
12480
12460
|
clearTimeout(timer);
|
|
12481
12461
|
reject(signal?.reason ?? new Error("aborted"));
|
|
@@ -13819,7 +13799,7 @@ var init_collector_ledger = __esm({
|
|
|
13819
13799
|
|
|
13820
13800
|
// src/package-resources/method-skill.ts
|
|
13821
13801
|
import { createHash as createHash8 } from "node:crypto";
|
|
13822
|
-
import { readFile as
|
|
13802
|
+
import { readFile as readFile14, realpath as realpath6 } from "node:fs/promises";
|
|
13823
13803
|
import { join as join26 } from "node:path";
|
|
13824
13804
|
function gitBlobOid(bytes) {
|
|
13825
13805
|
const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
|
|
@@ -13938,7 +13918,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
13938
13918
|
const provenancePath = join26(rootDirectory, "provenance.json");
|
|
13939
13919
|
let provenanceRaw;
|
|
13940
13920
|
try {
|
|
13941
|
-
provenanceRaw = await
|
|
13921
|
+
provenanceRaw = await readFile14(provenancePath, "utf8");
|
|
13942
13922
|
} catch (error) {
|
|
13943
13923
|
throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
|
|
13944
13924
|
}
|
|
@@ -13955,7 +13935,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
13955
13935
|
const absolute = join26(rootDirectory, rel);
|
|
13956
13936
|
let bytes;
|
|
13957
13937
|
try {
|
|
13958
|
-
bytes = await
|
|
13938
|
+
bytes = await readFile14(absolute);
|
|
13959
13939
|
} catch (error) {
|
|
13960
13940
|
throw new PackagedMethodSkillUnavailableError(name, absolute, error);
|
|
13961
13941
|
}
|
|
@@ -13971,7 +13951,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
13971
13951
|
let raw;
|
|
13972
13952
|
try {
|
|
13973
13953
|
skillPath = await realpath6(skillPathConfigured);
|
|
13974
|
-
raw = await
|
|
13954
|
+
raw = await readFile14(skillPath, "utf8");
|
|
13975
13955
|
} catch (error) {
|
|
13976
13956
|
throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
|
|
13977
13957
|
}
|
|
@@ -14027,7 +14007,7 @@ var init_method_skill = __esm({
|
|
|
14027
14007
|
});
|
|
14028
14008
|
|
|
14029
14009
|
// src/work-subject-identity.ts
|
|
14030
|
-
import { resolve as
|
|
14010
|
+
import { resolve as resolve12 } from "node:path";
|
|
14031
14011
|
function issueRoot(value) {
|
|
14032
14012
|
const normalized = value.replaceAll("\\", "/");
|
|
14033
14013
|
const marker = ".ak/work/issues/";
|
|
@@ -14037,7 +14017,7 @@ function issueRoot(value) {
|
|
|
14037
14017
|
return issue === void 0 || issue === "" ? void 0 : normalized.slice(0, index + marker.length) + issue;
|
|
14038
14018
|
}
|
|
14039
14019
|
function workIdentityFromCwd(cwd) {
|
|
14040
|
-
const resolvedCwd =
|
|
14020
|
+
const resolvedCwd = resolve12(cwd, ".");
|
|
14041
14021
|
const cwdIssue = issueRoot(resolvedCwd);
|
|
14042
14022
|
if (cwdIssue !== void 0) return cwdIssue;
|
|
14043
14023
|
if (resolvedCwd.includes("/.ak/work/")) return resolvedCwd;
|
|
@@ -14048,11 +14028,11 @@ function isMachineLedgerSessionPath(sessionPath) {
|
|
|
14048
14028
|
}
|
|
14049
14029
|
function subjectPath(sessionDir, cwd = process.cwd()) {
|
|
14050
14030
|
if (sessionDir === "") {
|
|
14051
|
-
return workIdentityFromCwd(cwd) ??
|
|
14031
|
+
return workIdentityFromCwd(cwd) ?? resolve12(cwd, ".ak/work");
|
|
14052
14032
|
}
|
|
14053
|
-
const resolvedSession =
|
|
14033
|
+
const resolvedSession = resolve12(cwd, sessionDir || ".ak/work");
|
|
14054
14034
|
if (isMachineLedgerSessionPath(resolvedSession)) {
|
|
14055
|
-
return workIdentityFromCwd(cwd) ??
|
|
14035
|
+
return workIdentityFromCwd(cwd) ?? resolve12(cwd, ".ak/work");
|
|
14056
14036
|
}
|
|
14057
14037
|
const issue = issueRoot(resolvedSession);
|
|
14058
14038
|
if (issue !== void 0) return issue;
|
|
@@ -14467,7 +14447,7 @@ var init_terminal = __esm({
|
|
|
14467
14447
|
|
|
14468
14448
|
// src/public-cli/settlement.ts
|
|
14469
14449
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
14470
|
-
import { appendFile as appendFile2, readFile as
|
|
14450
|
+
import { appendFile as appendFile2, readFile as readFile15, readdir as readdir5, writeFile as writeFile6 } from "node:fs/promises";
|
|
14471
14451
|
import { dirname as dirname13, join as join27 } from "node:path";
|
|
14472
14452
|
function sealedLedgerHome(admitted) {
|
|
14473
14453
|
return homeFromRunDirectory(admitted.runDirectory);
|
|
@@ -14580,7 +14560,7 @@ function presentStructuralRejection(error, io) {
|
|
|
14580
14560
|
}
|
|
14581
14561
|
async function inspectJudgeSession(sessionFile) {
|
|
14582
14562
|
try {
|
|
14583
|
-
await
|
|
14563
|
+
await readFile15(sessionFile, "utf8");
|
|
14584
14564
|
return { state: "present" };
|
|
14585
14565
|
} catch (error) {
|
|
14586
14566
|
if (isMissingPathError2(error)) return { state: "missing" };
|
|
@@ -14796,7 +14776,7 @@ function sessionReadFailure(error, fallbackMessage) {
|
|
|
14796
14776
|
return failed2;
|
|
14797
14777
|
}
|
|
14798
14778
|
async function readBoundSessionEntries(sessionFile) {
|
|
14799
|
-
const text = await
|
|
14779
|
+
const text = await readFile15(sessionFile, "utf8");
|
|
14800
14780
|
const entries = [];
|
|
14801
14781
|
for (const line2 of text.trim().split("\n").filter(Boolean)) {
|
|
14802
14782
|
try {
|
|
@@ -16189,10 +16169,10 @@ function presentFailureTerminal(terminal, io) {
|
|
|
16189
16169
|
}
|
|
16190
16170
|
function defaultNavigatorGraceSleep() {
|
|
16191
16171
|
let timer;
|
|
16192
|
-
const sleep = ((ms) => new Promise((
|
|
16172
|
+
const sleep = ((ms) => new Promise((resolve21) => {
|
|
16193
16173
|
timer = setTimeout(() => {
|
|
16194
16174
|
timer = void 0;
|
|
16195
|
-
|
|
16175
|
+
resolve21();
|
|
16196
16176
|
}, ms);
|
|
16197
16177
|
}));
|
|
16198
16178
|
sleep.cancel = () => {
|
|
@@ -16204,7 +16184,7 @@ function defaultNavigatorGraceSleep() {
|
|
|
16204
16184
|
return sleep;
|
|
16205
16185
|
}
|
|
16206
16186
|
function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep = defaultNavigatorGraceSleep()) {
|
|
16207
|
-
return new Promise((
|
|
16187
|
+
return new Promise((resolve21, reject) => {
|
|
16208
16188
|
let settled = false;
|
|
16209
16189
|
const finish = (action) => {
|
|
16210
16190
|
if (settled) return;
|
|
@@ -16213,11 +16193,11 @@ function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep
|
|
|
16213
16193
|
action();
|
|
16214
16194
|
};
|
|
16215
16195
|
void work.then(
|
|
16216
|
-
(value) => finish(() =>
|
|
16196
|
+
(value) => finish(() => resolve21({ status: "done", value })),
|
|
16217
16197
|
(error) => finish(() => reject(error))
|
|
16218
16198
|
);
|
|
16219
16199
|
void sleep(graceMs).then(() => {
|
|
16220
|
-
finish(() =>
|
|
16200
|
+
finish(() => resolve21({ status: "timeout" }));
|
|
16221
16201
|
});
|
|
16222
16202
|
});
|
|
16223
16203
|
}
|
|
@@ -16270,7 +16250,7 @@ var init_settlement = __esm({
|
|
|
16270
16250
|
});
|
|
16271
16251
|
|
|
16272
16252
|
// src/public-cli/auto-resume.ts
|
|
16273
|
-
import { constants as
|
|
16253
|
+
import { constants as fsConstants2 } from "node:fs";
|
|
16274
16254
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
16275
16255
|
import { lstat as lstat5, mkdir as mkdir4, open as open2 } from "node:fs/promises";
|
|
16276
16256
|
import { join as join28 } from "node:path";
|
|
@@ -16390,10 +16370,10 @@ async function retainDispatchError(admitted, principalAuthority, sessionAppender
|
|
|
16390
16370
|
2
|
|
16391
16371
|
)}
|
|
16392
16372
|
`;
|
|
16393
|
-
const noFollowFlag = typeof
|
|
16373
|
+
const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
|
|
16394
16374
|
const handle = await open2(
|
|
16395
16375
|
filePath,
|
|
16396
|
-
|
|
16376
|
+
fsConstants2.O_WRONLY | fsConstants2.O_CREAT | fsConstants2.O_EXCL | noFollowFlag,
|
|
16397
16377
|
384
|
|
16398
16378
|
);
|
|
16399
16379
|
try {
|
|
@@ -16623,8 +16603,8 @@ var init_auto_resume = __esm({
|
|
|
16623
16603
|
|
|
16624
16604
|
// src/public-cli/post-admission.ts
|
|
16625
16605
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
16626
|
-
import { readFile as
|
|
16627
|
-
import { isAbsolute as
|
|
16606
|
+
import { readFile as readFile16, writeFile as writeFile7 } from "node:fs/promises";
|
|
16607
|
+
import { isAbsolute as isAbsolute8, join as join29, resolve as resolve13 } from "node:path";
|
|
16628
16608
|
function appendContinuationSection(continuation, section) {
|
|
16629
16609
|
const prompt = `${continuation.prompt}
|
|
16630
16610
|
|
|
@@ -16633,7 +16613,7 @@ ${section}`;
|
|
|
16633
16613
|
}
|
|
16634
16614
|
async function readInvocationHost(runDirectory) {
|
|
16635
16615
|
try {
|
|
16636
|
-
const raw = JSON.parse(await
|
|
16616
|
+
const raw = JSON.parse(await readFile16(join29(runDirectory, "invocation.json"), "utf8"));
|
|
16637
16617
|
return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host : void 0;
|
|
16638
16618
|
} catch (error) {
|
|
16639
16619
|
if (error.code === "ENOENT") return void 0;
|
|
@@ -16895,7 +16875,7 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
|
|
|
16895
16875
|
};
|
|
16896
16876
|
}
|
|
16897
16877
|
function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
|
|
16898
|
-
const absolute =
|
|
16878
|
+
const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve13(attachmentPath);
|
|
16899
16879
|
return pathContainedIn(join29(runDirectory, "attachments"), absolute);
|
|
16900
16880
|
}
|
|
16901
16881
|
async function prepareSummonsResumeMaterials(runDirectory, summons) {
|
|
@@ -18667,7 +18647,7 @@ import {
|
|
|
18667
18647
|
statSync as statSync3,
|
|
18668
18648
|
writeFileSync as writeFileSync6
|
|
18669
18649
|
} from "node:fs";
|
|
18670
|
-
import { isAbsolute as
|
|
18650
|
+
import { isAbsolute as isAbsolute9, resolve as resolve14 } from "node:path";
|
|
18671
18651
|
function materializeDeferredSessionFile(sessionManager, resolvedFile) {
|
|
18672
18652
|
const header = sessionManager.getHeader?.();
|
|
18673
18653
|
if (header === null || header === void 0 || header.type !== "session") {
|
|
@@ -18695,12 +18675,12 @@ function durableSessionPointer(sessionManager) {
|
|
|
18695
18675
|
"Workflow role activation requires a durable Pi session file principal (getSessionFile); directory-only or --no-session invocations are rejected"
|
|
18696
18676
|
);
|
|
18697
18677
|
}
|
|
18698
|
-
if (!
|
|
18678
|
+
if (!isAbsolute9(file)) {
|
|
18699
18679
|
throw new Error(
|
|
18700
18680
|
`Workflow role activation requires an absolute durable session file path; got relative path: ${file}`
|
|
18701
18681
|
);
|
|
18702
18682
|
}
|
|
18703
|
-
const resolvedFile =
|
|
18683
|
+
const resolvedFile = resolve14(file);
|
|
18704
18684
|
try {
|
|
18705
18685
|
lstatSync2(resolvedFile);
|
|
18706
18686
|
} catch (error) {
|
|
@@ -18774,7 +18754,7 @@ import {
|
|
|
18774
18754
|
openSync,
|
|
18775
18755
|
writeSync
|
|
18776
18756
|
} from "node:fs";
|
|
18777
|
-
import { dirname as dirname14, isAbsolute as
|
|
18757
|
+
import { dirname as dirname14, isAbsolute as isAbsolute10, resolve as resolve15 } from "node:path";
|
|
18778
18758
|
function correlationIdentityFromEnv(env = process.env) {
|
|
18779
18759
|
const raw = env.AK_CORRELATION_ID;
|
|
18780
18760
|
if (typeof raw === "string" && raw.trim().length > 0) {
|
|
@@ -18803,13 +18783,13 @@ function serializeAcceptedActivationFact(fact) {
|
|
|
18803
18783
|
`;
|
|
18804
18784
|
}
|
|
18805
18785
|
function appendActivationLedgerLine(ledgerPath, line2, options) {
|
|
18806
|
-
if (!
|
|
18786
|
+
if (!isAbsolute10(options.ledgerHome)) {
|
|
18807
18787
|
throw new ActivationLedgerError(
|
|
18808
18788
|
`activation ledger home must be absolute: ${options.ledgerHome}`
|
|
18809
18789
|
);
|
|
18810
18790
|
}
|
|
18811
|
-
const resolvedLedger =
|
|
18812
|
-
const resolvedHome =
|
|
18791
|
+
const resolvedLedger = resolve15(ledgerPath);
|
|
18792
|
+
const resolvedHome = resolve15(options.ledgerHome);
|
|
18813
18793
|
const parent = dirname14(resolvedLedger);
|
|
18814
18794
|
ensureRealDirectoryTree(resolvedHome, parent);
|
|
18815
18795
|
assertLedgerFileInsideHome(resolvedLedger, resolvedHome);
|
|
@@ -19256,7 +19236,7 @@ var init_collector_tool_schemas = __esm({
|
|
|
19256
19236
|
});
|
|
19257
19237
|
|
|
19258
19238
|
// src/collector-handbook.ts
|
|
19259
|
-
import { readFile as
|
|
19239
|
+
import { readFile as readFile17 } from "node:fs/promises";
|
|
19260
19240
|
import { join as join32, sep as sep4 } from "node:path";
|
|
19261
19241
|
function resolveCollectorHandbookRoot(sessionPath) {
|
|
19262
19242
|
if (typeof sessionPath !== "string" || sessionPath.trim().length === 0) {
|
|
@@ -19310,7 +19290,7 @@ function createCollectorHandbookStore(input) {
|
|
|
19310
19290
|
ensureRealDirectoryTree(input.ledgerHome, parentDir2);
|
|
19311
19291
|
assertLedgerFileInsideHome(path, input.ledgerHome);
|
|
19312
19292
|
try {
|
|
19313
|
-
const body = await
|
|
19293
|
+
const body = await readFile17(path, "utf8");
|
|
19314
19294
|
assertHandbookBudget(body, "\u6B63\u6587");
|
|
19315
19295
|
return body;
|
|
19316
19296
|
} catch (error) {
|
|
@@ -20843,7 +20823,7 @@ var init_navigator_public_session = __esm({
|
|
|
20843
20823
|
|
|
20844
20824
|
// src/navigator-attendance.ts
|
|
20845
20825
|
import { createHash as createHash9 } from "node:crypto";
|
|
20846
|
-
import { resolve as
|
|
20826
|
+
import { resolve as resolve16 } from "node:path";
|
|
20847
20827
|
import "@earendil-works/pi-coding-agent";
|
|
20848
20828
|
import { Type as Type23 } from "typebox";
|
|
20849
20829
|
function resolveNavigatorAuthorityMaterial(roleInput, fileAuthority) {
|
|
@@ -20959,7 +20939,7 @@ function navigatorSubjectKey(subjectRoot, subject, provenance = "role_input") {
|
|
|
20959
20939
|
}
|
|
20960
20940
|
function navigatorSubjectKeyForInput(subjectRoot, reference, cwd = process.cwd()) {
|
|
20961
20941
|
if (issueRoot(subjectRoot) !== void 0 || !subjectRoot.includes("/.ak/work/")) return subjectRoot;
|
|
20962
|
-
const resolvedReference =
|
|
20942
|
+
const resolvedReference = resolve16(cwd, reference);
|
|
20963
20943
|
const marker = "/runs/";
|
|
20964
20944
|
if (resolvedReference.includes(marker)) {
|
|
20965
20945
|
return subjectRoot;
|
|
@@ -22855,7 +22835,7 @@ import { mkdtemp as mkdtemp3, rm as rm4 } from "node:fs/promises";
|
|
|
22855
22835
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
22856
22836
|
import { join as join35 } from "node:path";
|
|
22857
22837
|
async function runCommand(command, args, options = {}) {
|
|
22858
|
-
return await new Promise((
|
|
22838
|
+
return await new Promise((resolve21, reject) => {
|
|
22859
22839
|
const child = spawn4(command, args, { ...options.cwd === void 0 ? {} : { cwd: options.cwd }, stdio: ["ignore", "pipe", "pipe"], signal: options.signal });
|
|
22860
22840
|
let stdout = "", stderr = "";
|
|
22861
22841
|
child.stdout.setEncoding("utf8").on("data", (chunk) => {
|
|
@@ -22875,7 +22855,7 @@ async function runCommand(command, args, options = {}) {
|
|
|
22875
22855
|
const actual = code ?? 1;
|
|
22876
22856
|
if ((options.allowedCodes ?? [0]).includes(actual)) {
|
|
22877
22857
|
settled = true;
|
|
22878
|
-
|
|
22858
|
+
resolve21({ stdout, stderr, code: actual });
|
|
22879
22859
|
} else fail5(void 0, code, signal);
|
|
22880
22860
|
});
|
|
22881
22861
|
});
|
|
@@ -23495,7 +23475,7 @@ var init_reviewer_role = __esm({
|
|
|
23495
23475
|
// src/worker-submission-gates.ts
|
|
23496
23476
|
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
23497
23477
|
import { existsSync as existsSync11, lstatSync as lstatSync3, readdirSync as readdirSync2, readFileSync as readFileSync4, rmdirSync, rmSync } from "node:fs";
|
|
23498
|
-
import { resolve as
|
|
23478
|
+
import { resolve as resolve17 } from "node:path";
|
|
23499
23479
|
function git3(cwd, args) {
|
|
23500
23480
|
return execFileSync4("git", args, {
|
|
23501
23481
|
cwd,
|
|
@@ -23534,7 +23514,7 @@ function escapeGitConfigValueRegex(value) {
|
|
|
23534
23514
|
function unsetOwnedHooksPath(file) {
|
|
23535
23515
|
const owned = [];
|
|
23536
23516
|
for (const value of tryGetAll(file, "core.hooksPath")) {
|
|
23537
|
-
if (!ownedHook(
|
|
23517
|
+
if (!ownedHook(resolve17(value, HOOK_FILE))) continue;
|
|
23538
23518
|
try {
|
|
23539
23519
|
gitFile(file, [
|
|
23540
23520
|
"--unset-all",
|
|
@@ -23549,15 +23529,15 @@ function unsetOwnedHooksPath(file) {
|
|
|
23549
23529
|
return owned;
|
|
23550
23530
|
}
|
|
23551
23531
|
function rmOwnedDir(dir) {
|
|
23552
|
-
const hookPath =
|
|
23532
|
+
const hookPath = resolve17(dir, HOOK_FILE);
|
|
23553
23533
|
if (!ownedHook(hookPath)) return;
|
|
23554
23534
|
rmSync(hookPath, { force: true });
|
|
23555
23535
|
if (existsSync11(dir) && readdirSync2(dir).length === 0) rmdirSync(dir);
|
|
23556
23536
|
}
|
|
23557
23537
|
function linkedGitDirs(commonDir) {
|
|
23558
|
-
const root =
|
|
23538
|
+
const root = resolve17(commonDir, "worktrees");
|
|
23559
23539
|
if (!existsSync11(root)) return [];
|
|
23560
|
-
return readdirSync2(root).map((name) =>
|
|
23540
|
+
return readdirSync2(root).map((name) => resolve17(root, name)).filter((dir) => lstatSync3(dir).isDirectory());
|
|
23561
23541
|
}
|
|
23562
23542
|
function uninstallPackageWorkerHooks(cwd) {
|
|
23563
23543
|
let inside;
|
|
@@ -23571,14 +23551,14 @@ function uninstallPackageWorkerHooks(cwd) {
|
|
|
23571
23551
|
const clear = (configFile) => {
|
|
23572
23552
|
for (const hooks of unsetOwnedHooksPath(configFile)) rmOwnedDir(hooks);
|
|
23573
23553
|
};
|
|
23574
|
-
clear(
|
|
23575
|
-
clear(
|
|
23576
|
-
rmOwnedDir(
|
|
23577
|
-
const legacy =
|
|
23554
|
+
clear(resolve17(commonDir, "config"));
|
|
23555
|
+
clear(resolve17(commonDir, "config.worktree"));
|
|
23556
|
+
rmOwnedDir(resolve17(commonDir, HOOKS_DIR));
|
|
23557
|
+
const legacy = resolve17(commonDir, "hooks", HOOK_FILE);
|
|
23578
23558
|
if (ownedHook(legacy)) rmSync(legacy, { force: true });
|
|
23579
23559
|
for (const gitDir of linkedGitDirs(commonDir)) {
|
|
23580
|
-
clear(
|
|
23581
|
-
rmOwnedDir(
|
|
23560
|
+
clear(resolve17(gitDir, "config.worktree"));
|
|
23561
|
+
rmOwnedDir(resolve17(gitDir, HOOKS_DIR));
|
|
23582
23562
|
}
|
|
23583
23563
|
}
|
|
23584
23564
|
function isRecord19(value) {
|
|
@@ -24147,63 +24127,42 @@ var init_worker_role = __esm({
|
|
|
24147
24127
|
});
|
|
24148
24128
|
|
|
24149
24129
|
// src/merger-role.ts
|
|
24150
|
-
function same(a, b) {
|
|
24151
|
-
return a.length === b.length && a.every((value, i) => value === b[i]);
|
|
24152
|
-
}
|
|
24153
24130
|
function materialText(input, key) {
|
|
24154
24131
|
return exactUtf8(Buffer.from(input.materials[key].bytesBase64, "base64"), `Merger ${key}`);
|
|
24155
24132
|
}
|
|
24156
|
-
function createMergerRoleRuntime(pi, dependencies
|
|
24133
|
+
function createMergerRoleRuntime(pi, dependencies) {
|
|
24157
24134
|
let activation;
|
|
24158
24135
|
let registered = false;
|
|
24159
24136
|
let accepted = false;
|
|
24160
24137
|
pi.registerFlag(MERGER_INPUT_FLAG.name, MERGER_INPUT_FLAG.definition);
|
|
24161
|
-
return {
|
|
24162
|
-
|
|
24163
|
-
|
|
24164
|
-
|
|
24165
|
-
|
|
24166
|
-
|
|
24167
|
-
|
|
24168
|
-
|
|
24169
|
-
|
|
24170
|
-
|
|
24171
|
-
|
|
24172
|
-
|
|
24173
|
-
|
|
24174
|
-
|
|
24175
|
-
|
|
24176
|
-
|
|
24177
|
-
|
|
24178
|
-
|
|
24179
|
-
|
|
24180
|
-
|
|
24181
|
-
|
|
24182
|
-
|
|
24183
|
-
try {
|
|
24184
|
-
output = validateMergerOutput(params, activation.input.attemptId);
|
|
24185
|
-
} catch (error) {
|
|
24186
|
-
host.failInfrastructure(error, ctx, id);
|
|
24187
|
-
}
|
|
24188
|
-
if (output.status === "completed") {
|
|
24189
|
-
let state2;
|
|
24190
|
-
try {
|
|
24191
|
-
state2 = await dependencies.gitState.completedMerge(output.mergeCommitId, activation.automaticMergeTreeId);
|
|
24192
|
-
} catch (error) {
|
|
24193
|
-
host.failInfrastructure(error, ctx, id);
|
|
24194
|
-
}
|
|
24195
|
-
const scope = new Set(activation.input.resolutionScope);
|
|
24196
|
-
if (state2.mergeCommitId !== output.mergeCommitId || !same(state2.parentObjectIds, [activation.input.targetObjectId, activation.input.sourceObjectId]) || state2.unmergedPaths.length !== 0 || !state2.worktreeClean || state2.resolutionChangedPaths.some((path2) => !scope.has(path2))) host.failInfrastructure(new Error("Merger completed-state verification failed"), ctx, id);
|
|
24138
|
+
return {
|
|
24139
|
+
async activate() {
|
|
24140
|
+
const path = pi.getFlag(MERGER_INPUT_FLAG.name);
|
|
24141
|
+
if (typeof path !== "string" || path.trim().length === 0) throw new Error("Merger requires --ak-merger-input");
|
|
24142
|
+
const soul = (await dependencies.loadSoul()).trim();
|
|
24143
|
+
if (!soul) throw new Error("Merger soul is empty");
|
|
24144
|
+
const input = validateMergerInput(await dependencies.loadInput(path));
|
|
24145
|
+
activation = { soul, input };
|
|
24146
|
+
accepted = false;
|
|
24147
|
+
if (!registered) {
|
|
24148
|
+
registered = true;
|
|
24149
|
+
pi.registerTool({
|
|
24150
|
+
name: MERGER_OUTPUT_TOOL_NAME,
|
|
24151
|
+
label: "\u5408\u5E76\u8F93\u51FA",
|
|
24152
|
+
description: "\u63D0\u4EA4\u5408\u5E76\u7ED3\u679C\uFF1B\u8F93\u51FA\u5206\u652F\u4E3A completed \u4E0E escalate\u3002",
|
|
24153
|
+
promptSnippet: "\u63D0\u4EA4\u5408\u5E76\u7ED3\u679C",
|
|
24154
|
+
parameters: mergerOutputSchema,
|
|
24155
|
+
async execute(_id, params, _signal, _update, _ctx) {
|
|
24156
|
+
if (!activation) throw new Error("\u6821\u4E66\u90CE\u672A\u6FC0\u6D3B");
|
|
24157
|
+
if (accepted) throw new Error("\u5408\u5E76\u56DE\u6267\u5DF2\u53D7\u7406");
|
|
24158
|
+
accepted = true;
|
|
24159
|
+
return { content: [{ type: "text", text: MERGER_ACCEPTED_TEXT }], details: params, terminate: true };
|
|
24197
24160
|
}
|
|
24198
|
-
|
|
24199
|
-
|
|
24200
|
-
|
|
24201
|
-
|
|
24202
|
-
|
|
24203
|
-
pi.on("before_agent_start", (event) => {
|
|
24204
|
-
if (!activation) throw new Error("\u6821\u4E66\u90CE\u672A\u6FC0\u6D3B");
|
|
24205
|
-
const admitted = { attemptId: activation.input.attemptId, targetObjectId: activation.input.targetObjectId, sourceObjectId: activation.input.sourceObjectId, task: materialText(activation.input, "task"), authority: materialText(activation.input, "authority"), targetIntent: materialText(activation.input, "targetIntent"), sourceIntent: materialText(activation.input, "sourceIntent"), expectedConflictPaths: activation.input.expectedConflictPaths, resolutionScope: activation.input.resolutionScope, authorizedChecks: activation.input.authorizedChecks };
|
|
24206
|
-
return { systemPrompt: `${event.systemPrompt}
|
|
24161
|
+
});
|
|
24162
|
+
pi.on("before_agent_start", (event) => {
|
|
24163
|
+
if (!activation) throw new Error("\u6821\u4E66\u90CE\u672A\u6FC0\u6D3B");
|
|
24164
|
+
const admitted = { attemptId: activation.input.attemptId, targetObjectId: activation.input.targetObjectId, sourceObjectId: activation.input.sourceObjectId, task: materialText(activation.input, "task"), authority: materialText(activation.input, "authority"), targetIntent: materialText(activation.input, "targetIntent"), sourceIntent: materialText(activation.input, "sourceIntent"), expectedConflictPaths: activation.input.expectedConflictPaths, resolutionScope: activation.input.resolutionScope, authorizedChecks: activation.input.authorizedChecks };
|
|
24165
|
+
return { systemPrompt: `${event.systemPrompt}
|
|
24207
24166
|
|
|
24208
24167
|
<merger_soul>
|
|
24209
24168
|
${activation.soul}
|
|
@@ -24212,13 +24171,14 @@ ${activation.soul}
|
|
|
24212
24171
|
<merger_assignment>
|
|
24213
24172
|
${JSON.stringify(admitted)}
|
|
24214
24173
|
</merger_assignment>` };
|
|
24215
|
-
|
|
24216
|
-
|
|
24217
|
-
|
|
24218
|
-
|
|
24219
|
-
|
|
24174
|
+
});
|
|
24175
|
+
}
|
|
24176
|
+
const all = pi.getAllTools().map((tool) => tool.name);
|
|
24177
|
+
if (all.filter((item) => item === MERGER_OUTPUT_TOOL_NAME).length !== 1) {
|
|
24178
|
+
throw new Error(`Merger required tool collision or missing: ${MERGER_OUTPUT_TOOL_NAME}`);
|
|
24179
|
+
}
|
|
24220
24180
|
}
|
|
24221
|
-
}
|
|
24181
|
+
};
|
|
24222
24182
|
}
|
|
24223
24183
|
var MERGER_INPUT_FLAG;
|
|
24224
24184
|
var init_merger_role = __esm({
|
|
@@ -24226,8 +24186,7 @@ var init_merger_role = __esm({
|
|
|
24226
24186
|
"use strict";
|
|
24227
24187
|
init_merger_contracts();
|
|
24228
24188
|
init_exact_utf8();
|
|
24229
|
-
|
|
24230
|
-
MERGER_INPUT_FLAG = { name: "ak-merger-input", definition: { description: "Path to an immutable digest-bound Merger v1 input JSON file", type: "string" } };
|
|
24189
|
+
MERGER_INPUT_FLAG = { name: "ak-merger-input", definition: { description: "Path to Merger assignment materials JSON", type: "string" } };
|
|
24231
24190
|
}
|
|
24232
24191
|
});
|
|
24233
24192
|
|
|
@@ -25180,7 +25139,6 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
25180
25139
|
}
|
|
25181
25140
|
}
|
|
25182
25141
|
);
|
|
25183
|
-
let sessionMergerGitState = dependencies.mergerGitState;
|
|
25184
25142
|
const merger = createMergerRoleRuntime(roleHost, {
|
|
25185
25143
|
async loadSoul() {
|
|
25186
25144
|
if (!dependencies.loadMergerSoul) throw new Error("Merger runtime dependencies are not configured");
|
|
@@ -25189,18 +25147,8 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
25189
25147
|
async loadInput(path) {
|
|
25190
25148
|
if (!dependencies.loadMergerInput) throw new Error("Merger runtime dependencies are not configured");
|
|
25191
25149
|
return dependencies.loadMergerInput(path);
|
|
25192
|
-
},
|
|
25193
|
-
gitState: {
|
|
25194
|
-
activeMerge() {
|
|
25195
|
-
if (!sessionMergerGitState) throw new Error("Merger runtime dependencies are not configured");
|
|
25196
|
-
return sessionMergerGitState.activeMerge();
|
|
25197
|
-
},
|
|
25198
|
-
completedMerge(mergeCommitId, automaticMergeTreeId) {
|
|
25199
|
-
if (!sessionMergerGitState) throw new Error("Merger runtime dependencies are not configured");
|
|
25200
|
-
return sessionMergerGitState.completedMerge(mergeCommitId, automaticMergeTreeId);
|
|
25201
|
-
}
|
|
25202
25150
|
}
|
|
25203
|
-
}
|
|
25151
|
+
});
|
|
25204
25152
|
let activeCollector;
|
|
25205
25153
|
let collectorFirstDispatchDone = false;
|
|
25206
25154
|
const collectorBusiness = createCollectorRoleRuntime(
|
|
@@ -25435,10 +25383,6 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
25435
25383
|
auditor,
|
|
25436
25384
|
diarist,
|
|
25437
25385
|
merger: async () => {
|
|
25438
|
-
if (dependencies.mergerGitState === void 0) {
|
|
25439
|
-
sessionMergerGitState = dependencies.createMergerGitState?.(ctx.cwd);
|
|
25440
|
-
}
|
|
25441
|
-
if (sessionMergerGitState === void 0) throw new Error("Merger runtime dependencies are not configured");
|
|
25442
25386
|
await merger.activate();
|
|
25443
25387
|
}
|
|
25444
25388
|
};
|
|
@@ -25695,7 +25639,7 @@ init_role_activation_flags();
|
|
|
25695
25639
|
init_submission_correctable_error();
|
|
25696
25640
|
init_navigator_invocation_identity();
|
|
25697
25641
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
25698
|
-
import { mkdir as mkdir5, readFile as
|
|
25642
|
+
import { mkdir as mkdir5, readFile as readFile18, writeFile as writeFile9 } from "node:fs/promises";
|
|
25699
25643
|
import { createServer } from "node:net";
|
|
25700
25644
|
import { basename as basename8, dirname as dirname17, join as join37 } from "node:path";
|
|
25701
25645
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
@@ -25715,11 +25659,11 @@ ${method.body}`,
|
|
|
25715
25659
|
});
|
|
25716
25660
|
}
|
|
25717
25661
|
async function listen(server, path) {
|
|
25718
|
-
await new Promise((
|
|
25662
|
+
await new Promise((resolve21, reject) => {
|
|
25719
25663
|
server.once("error", reject);
|
|
25720
25664
|
server.listen(path, () => {
|
|
25721
25665
|
server.off("error", reject);
|
|
25722
|
-
|
|
25666
|
+
resolve21();
|
|
25723
25667
|
});
|
|
25724
25668
|
});
|
|
25725
25669
|
}
|
|
@@ -25757,7 +25701,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
25757
25701
|
for (const method of request.methods) {
|
|
25758
25702
|
if (method.kind !== "skill") continue;
|
|
25759
25703
|
const name = basename8(dirname17(method.path));
|
|
25760
|
-
const raw = await
|
|
25704
|
+
const raw = await readFile18(method.path, "utf8");
|
|
25761
25705
|
methodSkills.set(name, { path: method.path, body: stripSkillFrontmatter(raw).trim() });
|
|
25762
25706
|
}
|
|
25763
25707
|
let sessionFile = options.sessionFile ?? join37(request.runDirectory, "session", "session.jsonl");
|
|
@@ -26118,8 +26062,8 @@ async function prepareRoleEnvelope(options) {
|
|
|
26118
26062
|
try {
|
|
26119
26063
|
const closeAll = server.closeAllConnections;
|
|
26120
26064
|
if (typeof closeAll === "function") closeAll.call(server);
|
|
26121
|
-
await new Promise((
|
|
26122
|
-
server.close((error) => error ? reject(error) :
|
|
26065
|
+
await new Promise((resolve21, reject) => {
|
|
26066
|
+
server.close((error) => error ? reject(error) : resolve21());
|
|
26123
26067
|
});
|
|
26124
26068
|
} catch (error) {
|
|
26125
26069
|
cleanupFailures.push(error);
|
|
@@ -26186,7 +26130,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
26186
26130
|
message: { role: "user", content: prompt }
|
|
26187
26131
|
});
|
|
26188
26132
|
}
|
|
26189
|
-
const methodPrompt = (await Promise.all(request.methods.map(({ path }) =>
|
|
26133
|
+
const methodPrompt = (await Promise.all(request.methods.map(({ path }) => readFile18(path, "utf8")))).join("\n\n");
|
|
26190
26134
|
const promptResults = await emit("before_agent_start", {
|
|
26191
26135
|
prompt,
|
|
26192
26136
|
systemPrompt: methodPrompt,
|
|
@@ -26245,13 +26189,13 @@ async function prepareRoleEnvelope(options) {
|
|
|
26245
26189
|
}
|
|
26246
26190
|
|
|
26247
26191
|
// src/role-runtime-dependencies.ts
|
|
26248
|
-
import { readFile as
|
|
26192
|
+
import { readFile as readFile21 } from "node:fs/promises";
|
|
26249
26193
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
26250
26194
|
|
|
26251
26195
|
// src/canonical-skill-binding.ts
|
|
26252
|
-
import { readFile as
|
|
26196
|
+
import { readFile as readFile19, realpath as realpath7 } from "node:fs/promises";
|
|
26253
26197
|
import { homedir } from "node:os";
|
|
26254
|
-
import { dirname as dirname18, resolve as
|
|
26198
|
+
import { dirname as dirname18, resolve as resolve18 } from "node:path";
|
|
26255
26199
|
import { stripFrontmatter } from "@earendil-works/pi-coding-agent";
|
|
26256
26200
|
function captureCanonicalSkillExpansion(name, snapshot, configuredPath, evidence, originalRequest) {
|
|
26257
26201
|
const matchedPath = evidence?.location === configuredPath ? configuredPath : evidence?.location === snapshot.path ? snapshot.path : void 0;
|
|
@@ -26273,7 +26217,7 @@ var CanonicalSkillUnavailableError = class extends Error {
|
|
|
26273
26217
|
code = "canonical-skill-unavailable";
|
|
26274
26218
|
};
|
|
26275
26219
|
async function loadCanonicalSkillBinding(name) {
|
|
26276
|
-
const configuredPath =
|
|
26220
|
+
const configuredPath = resolve18(
|
|
26277
26221
|
homedir(),
|
|
26278
26222
|
`.agents/skills/${name}/SKILL.md`
|
|
26279
26223
|
);
|
|
@@ -26281,7 +26225,7 @@ async function loadCanonicalSkillBinding(name) {
|
|
|
26281
26225
|
let raw;
|
|
26282
26226
|
try {
|
|
26283
26227
|
path = await realpath7(configuredPath);
|
|
26284
|
-
raw = await
|
|
26228
|
+
raw = await readFile19(path, "utf8");
|
|
26285
26229
|
} catch (error) {
|
|
26286
26230
|
throw new CanonicalSkillUnavailableError(name, configuredPath, error);
|
|
26287
26231
|
}
|
|
@@ -26316,7 +26260,6 @@ async function loadCanonicalSkillBinding(name) {
|
|
|
26316
26260
|
init_collector_github();
|
|
26317
26261
|
init_doctor_auditor();
|
|
26318
26262
|
init_doctor_evidence();
|
|
26319
|
-
init_merger_git_state();
|
|
26320
26263
|
init_navigator_attendance();
|
|
26321
26264
|
|
|
26322
26265
|
// src/navigator-work-context.ts
|
|
@@ -26325,17 +26268,17 @@ init_navigator_attendance();
|
|
|
26325
26268
|
init_notary_source_run();
|
|
26326
26269
|
init_packaged_role_registry();
|
|
26327
26270
|
init_invocation();
|
|
26328
|
-
import { readFile as
|
|
26329
|
-
import { resolve as
|
|
26271
|
+
import { readFile as readFile20 } from "node:fs/promises";
|
|
26272
|
+
import { resolve as resolve19 } from "node:path";
|
|
26330
26273
|
function navigatorInputReference(getFlag, role) {
|
|
26331
26274
|
if (getFlag === void 0) return void 0;
|
|
26332
26275
|
const name = packagedRoleInputFlag(role);
|
|
26333
26276
|
const value = name === void 0 ? void 0 : getFlag(name);
|
|
26334
|
-
return typeof value === "string" && value !== "" ?
|
|
26277
|
+
return typeof value === "string" && value !== "" ? resolve19(value) : void 0;
|
|
26335
26278
|
}
|
|
26336
26279
|
async function loadNavigatorWorkContext(options) {
|
|
26337
26280
|
const reference = navigatorInputReference(options.getFlag, options.role);
|
|
26338
|
-
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await
|
|
26281
|
+
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile20(reference, "utf8");
|
|
26339
26282
|
const subjectRoot = subjectPath(reference ?? options.context.sessionManager.getSessionDir(), options.context.cwd);
|
|
26340
26283
|
let subjectKey = reference === void 0 ? subjectRoot : navigatorSubjectKeyForInput(subjectRoot, reference, options.context.cwd);
|
|
26341
26284
|
let subject = input ?? `work subject: ${subjectKey}`;
|
|
@@ -26352,7 +26295,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
26352
26295
|
}
|
|
26353
26296
|
const publicRunDir = process.env.AK_ROLE_RUN_DIR;
|
|
26354
26297
|
const currentSessionDir = options.context.sessionManager.getSessionDir();
|
|
26355
|
-
const isBoundPublicRun = typeof publicRunDir === "string" && publicRunDir.trim() !== "" &&
|
|
26298
|
+
const isBoundPublicRun = typeof publicRunDir === "string" && publicRunDir.trim() !== "" && resolve19(currentSessionDir) === resolve19(publicRunDir, "session");
|
|
26356
26299
|
if (options.role === "judge" && isBoundPublicRun) {
|
|
26357
26300
|
let admitted;
|
|
26358
26301
|
try {
|
|
@@ -26385,14 +26328,14 @@ async function loadNavigatorWorkContext(options) {
|
|
|
26385
26328
|
}
|
|
26386
26329
|
const workRoot = subjectRoot.includes("/.ak/work/") ? subjectRoot : void 0;
|
|
26387
26330
|
const authorityFiles = workRoot === void 0 ? [] : [
|
|
26388
|
-
|
|
26389
|
-
|
|
26390
|
-
|
|
26331
|
+
resolve19(workRoot, "authority.md"),
|
|
26332
|
+
resolve19(workRoot, "authority.txt"),
|
|
26333
|
+
resolve19(workRoot, "design-v2/owner-direction.md")
|
|
26391
26334
|
];
|
|
26392
26335
|
let authorityMaterial;
|
|
26393
26336
|
for (const path of authorityFiles) {
|
|
26394
26337
|
try {
|
|
26395
|
-
const content = await
|
|
26338
|
+
const content = await readFile20(path, "utf8");
|
|
26396
26339
|
if (content.trim() !== "") {
|
|
26397
26340
|
authorityMaterial = content;
|
|
26398
26341
|
break;
|
|
@@ -26464,14 +26407,14 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
26464
26407
|
return {
|
|
26465
26408
|
loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
|
|
26466
26409
|
loadFixerSoul: () => loadMainRoleSessionMaterials("fixer"),
|
|
26467
|
-
loadFixPacket: (path) =>
|
|
26410
|
+
loadFixPacket: (path) => readFile21(path, "utf8"),
|
|
26468
26411
|
loadCoderSoul: () => loadMainRoleSessionMaterials("coder"),
|
|
26469
|
-
loadCoderTask: (path) =>
|
|
26412
|
+
loadCoderTask: (path) => readFile21(path, "utf8"),
|
|
26470
26413
|
loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
|
|
26471
26414
|
createReviewerPinnedGitReader: () => createReviewerPinnedGitReader(),
|
|
26472
26415
|
createReviewerIssueFetcher: () => createGhIssueSoftFetcher(),
|
|
26473
26416
|
loadCollectorSoul: () => loadMainRoleSessionMaterials("collector"),
|
|
26474
|
-
loadCollectorHandbookSeed: () =>
|
|
26417
|
+
loadCollectorHandbookSeed: () => readFile21(collectorHandbookSeedPath, "utf8"),
|
|
26475
26418
|
createCollectorTransport: () => createGhCollectorGitHubTransport(),
|
|
26476
26419
|
loadDoctorSoul: () => loadMainRoleSessionMaterials("doctor"),
|
|
26477
26420
|
loadDoctorCase,
|
|
@@ -26485,8 +26428,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
26485
26428
|
loadDiaristSoul: () => loadMainRoleSessionMaterials("diarist"),
|
|
26486
26429
|
loadNotarySourceRun: loadNotarySourceRunLocator,
|
|
26487
26430
|
loadMergerSoul: () => loadMainRoleSessionMaterials("merger"),
|
|
26488
|
-
loadMergerInput: async (path) => JSON.parse(await
|
|
26489
|
-
createMergerGitState: (repositoryRoot) => createProductionMergerGitState(repositoryRoot),
|
|
26431
|
+
loadMergerInput: async (path) => JSON.parse(await readFile21(path, "utf8")),
|
|
26490
26432
|
async loadCanonicalSkillBinding(name) {
|
|
26491
26433
|
if (name === "tdd") {
|
|
26492
26434
|
return loadPackagedCanonicalSkillBinding(packageRoot, "tdd");
|
|
@@ -26514,7 +26456,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
26514
26456
|
authority: options.authority,
|
|
26515
26457
|
invocationId: options.invocationId,
|
|
26516
26458
|
loadSoul: () => loadMainRoleSessionMaterials("navigator"),
|
|
26517
|
-
loadRoutePlaybook: () =>
|
|
26459
|
+
loadRoutePlaybook: () => readFile21(navigatorRoutePlaybookPath, "utf8"),
|
|
26518
26460
|
loadRoleHelp: async (role) => formatNavigatorRoleHelp(role),
|
|
26519
26461
|
createSession: navigatorSessionFactory,
|
|
26520
26462
|
...options.contextError === void 0 ? {} : { contextError: options.contextError },
|
|
@@ -26524,7 +26466,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
26524
26466
|
}
|
|
26525
26467
|
|
|
26526
26468
|
// src/session-identity.ts
|
|
26527
|
-
import { mkdir as mkdir6, readFile as
|
|
26469
|
+
import { mkdir as mkdir6, readFile as readFile22, rename as rename2, writeFile as writeFile10 } from "node:fs/promises";
|
|
26528
26470
|
import { dirname as dirname20, join as join38 } from "node:path";
|
|
26529
26471
|
function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
26530
26472
|
const bindingPath = (principal) => join38(authority.decode(principal).sessionDirectory, sessionBindingFile);
|
|
@@ -26534,7 +26476,7 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
|
26534
26476
|
},
|
|
26535
26477
|
async load(principal) {
|
|
26536
26478
|
try {
|
|
26537
|
-
const value = JSON.parse(await
|
|
26479
|
+
const value = JSON.parse(await readFile22(bindingPath(principal), "utf8"));
|
|
26538
26480
|
if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
|
|
26539
26481
|
throw new Error("durable session binding is invalid");
|
|
26540
26482
|
}
|
|
@@ -26603,7 +26545,7 @@ function hostAbortedError(message = "host aborted") {
|
|
|
26603
26545
|
function raceAgainstHostAbort(work, abortSignal, message = "host aborted") {
|
|
26604
26546
|
if (abortSignal?.aborted) return Promise.reject(hostAbortedError(message));
|
|
26605
26547
|
if (abortSignal === void 0) return work;
|
|
26606
|
-
return new Promise((
|
|
26548
|
+
return new Promise((resolve21, reject) => {
|
|
26607
26549
|
let settled = false;
|
|
26608
26550
|
const onAbort = () => {
|
|
26609
26551
|
if (settled) return;
|
|
@@ -26618,7 +26560,7 @@ function raceAgainstHostAbort(work, abortSignal, message = "host aborted") {
|
|
|
26618
26560
|
if (settled) return;
|
|
26619
26561
|
settled = true;
|
|
26620
26562
|
abortSignal.removeEventListener("abort", onAbort);
|
|
26621
|
-
|
|
26563
|
+
resolve21(value);
|
|
26622
26564
|
},
|
|
26623
26565
|
(error) => {
|
|
26624
26566
|
if (settled) return;
|
|
@@ -26803,8 +26745,8 @@ function connectAcpStdio(options) {
|
|
|
26803
26745
|
request(method, params) {
|
|
26804
26746
|
if (closed) return Promise.reject(terminalError ?? acpError("acp-connection-closed", "ACP connection is closed"));
|
|
26805
26747
|
const id = ++nextId;
|
|
26806
|
-
return new Promise((
|
|
26807
|
-
pending.set(id, { resolve:
|
|
26748
|
+
return new Promise((resolve21, reject) => {
|
|
26749
|
+
pending.set(id, { resolve: resolve21, reject });
|
|
26808
26750
|
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}
|
|
26809
26751
|
`, (error) => {
|
|
26810
26752
|
if (error === null || error === void 0) return;
|
|
@@ -26828,7 +26770,7 @@ function connectAcpStdio(options) {
|
|
|
26828
26770
|
settleClosed(acpError("acp-connection-closed", "ACP connection is closed"));
|
|
26829
26771
|
child.stdin.end();
|
|
26830
26772
|
child.kill("SIGTERM");
|
|
26831
|
-
await new Promise((
|
|
26773
|
+
await new Promise((resolve21) => child.once("close", () => resolve21()));
|
|
26832
26774
|
}
|
|
26833
26775
|
});
|
|
26834
26776
|
}
|
|
@@ -26994,17 +26936,17 @@ function createAcpRoleTurnHost(config) {
|
|
|
26994
26936
|
|
|
26995
26937
|
// src/acp-host/seat-profile-soul.ts
|
|
26996
26938
|
import { constants as constants3 } from "node:fs";
|
|
26997
|
-
import { access as
|
|
26998
|
-
import { dirname as dirname21, join as join40, relative as relative3, resolve as
|
|
26939
|
+
import { access as access5, copyFile, lstat as lstat6, mkdir as mkdir7, readlink, symlink, unlink as unlink4 } from "node:fs/promises";
|
|
26940
|
+
import { dirname as dirname21, join as join40, relative as relative3, resolve as resolve20 } from "node:path";
|
|
26999
26941
|
function seatProfileName(spec, role) {
|
|
27000
26942
|
return `${spec.namePrefix}${role}`;
|
|
27001
26943
|
}
|
|
27002
26944
|
function packageRoleSoulPath(packageRoot, role) {
|
|
27003
26945
|
return join40(packageRoot, "souls", `${role}.md`);
|
|
27004
26946
|
}
|
|
27005
|
-
async function
|
|
26947
|
+
async function pathExists2(path) {
|
|
27006
26948
|
try {
|
|
27007
|
-
await
|
|
26949
|
+
await access5(path, constants3.F_OK);
|
|
27008
26950
|
return true;
|
|
27009
26951
|
} catch {
|
|
27010
26952
|
return false;
|
|
@@ -27013,19 +26955,19 @@ async function pathExists(path) {
|
|
|
27013
26955
|
async function ensureSeatProfileSoul(options) {
|
|
27014
26956
|
const { spec, operatorHome, packageRoot, role } = options;
|
|
27015
26957
|
const profileName = seatProfileName(spec, role);
|
|
27016
|
-
const soulTarget =
|
|
27017
|
-
if (!await
|
|
26958
|
+
const soulTarget = resolve20(packageRoleSoulPath(packageRoot, role));
|
|
26959
|
+
if (!await pathExists2(soulTarget)) {
|
|
27018
26960
|
throw new Error(`packaged role soul missing: ${soulTarget}`);
|
|
27019
26961
|
}
|
|
27020
26962
|
const profilesRoot = join40(operatorHome, ...spec.profilesRootFromHome);
|
|
27021
26963
|
const profileDir = join40(profilesRoot, profileName);
|
|
27022
26964
|
const hostRoot = dirname21(profilesRoot);
|
|
27023
26965
|
const soulPath = join40(profileDir, spec.soulFileName);
|
|
27024
|
-
if (!await
|
|
26966
|
+
if (!await pathExists2(profileDir)) {
|
|
27025
26967
|
await mkdir7(profileDir, { recursive: true });
|
|
27026
26968
|
for (const name of ["auth.json", ".env", "config.yaml"]) {
|
|
27027
26969
|
const source = join40(hostRoot, name);
|
|
27028
|
-
if (!await
|
|
26970
|
+
if (!await pathExists2(source)) continue;
|
|
27029
26971
|
await copyFile(source, join40(profileDir, name));
|
|
27030
26972
|
}
|
|
27031
26973
|
} else {
|
|
@@ -27044,7 +26986,7 @@ async function ensureSeatProfileSoul(options) {
|
|
|
27044
26986
|
if (current === desiredLink || current === soulTarget) {
|
|
27045
26987
|
return profileName;
|
|
27046
26988
|
}
|
|
27047
|
-
if (await
|
|
26989
|
+
if (await pathExists2(soulPath) || current !== void 0) {
|
|
27048
26990
|
await unlink4(soulPath);
|
|
27049
26991
|
}
|
|
27050
26992
|
await symlink(desiredLink, soulPath);
|