@mrciphersmith/keryx 0.4.28 → 0.4.29
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/dist/cli.js +2710 -2488
- package/dist/core.js +5 -5
- package/dist/keryx-general-worker-entry.js +335 -219
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +1 -0
- package/src/gdskills/bundled/rules/core/clean-architecture.mdc +25 -153
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +1 -0
- package/src/gdskills/bundled/rules/core/error-handling.mdc +57 -108
- package/src/gdskills/bundled/rules/core/skill-authoring.mdc +190 -0
- package/src/gdskills/bundled/rules/core/skills-storage-workflow.mdc +5 -0
- package/src/gdskills/bundled/rules/core/solid-principles.mdc +48 -123
- package/src/gdskills/bundled/skills/orchestration/task-implementer/SKILL.md +2 -2
- package/src/gdskills/bundled/skills/quality/tests-creator/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +3 -5
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +100 -421
- package/src/gdskills/bundled/skills/review/review-core-boundaries/SKILL.md +2 -2
- package/src/gdskills/bundled/skills/review/review-degradation/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-flow-graph/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +4 -5
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +2 -3
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-premise/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-regression/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +32 -36
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +1 -1
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +4 -3
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +3 -3
- package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +4 -4
|
@@ -95,6 +95,21 @@ function appendOwnerOnlyLine(file, line) {
|
|
|
95
95
|
chmodSync(file, 384);
|
|
96
96
|
} catch {}
|
|
97
97
|
}
|
|
98
|
+
function appendPrivateRecord(file, line) {
|
|
99
|
+
const fd = openSync(file, constants.O_WRONLY | constants.O_CREAT | constants.O_APPEND | constants.O_NOFOLLOW | constants.O_NONBLOCK, 384);
|
|
100
|
+
try {
|
|
101
|
+
const info = fstatSync(fd);
|
|
102
|
+
if (!info.isFile() || process.platform !== "win32" && (info.mode & 63) !== 0 || info.nlink !== 1) {
|
|
103
|
+
throw new Error("Private journal requires an owner-only regular file.");
|
|
104
|
+
}
|
|
105
|
+
const bytes = Buffer.from(`${line}
|
|
106
|
+
`);
|
|
107
|
+
if (writeSync(fd, bytes) !== bytes.length)
|
|
108
|
+
throw new Error("Incomplete private journal write.");
|
|
109
|
+
} finally {
|
|
110
|
+
closeSync(fd);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
98
113
|
function writeOwnerOnlyFileAtomic(file, body) {
|
|
99
114
|
const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
100
115
|
try {
|
|
@@ -11329,12 +11344,12 @@ var init_skill_length_ceilings = __esm(() => {
|
|
|
11329
11344
|
"quality/ui-craft": 173,
|
|
11330
11345
|
"review/code-learned-review": 283,
|
|
11331
11346
|
"review/review-architecture": 373,
|
|
11332
|
-
"review/review-backend":
|
|
11333
|
-
"review/review-clean-code":
|
|
11347
|
+
"review/review-backend": 359,
|
|
11348
|
+
"review/review-clean-code": 217,
|
|
11334
11349
|
"review/review-core-boundaries": 158,
|
|
11335
11350
|
"review/review-degradation": 191,
|
|
11336
11351
|
"review/review-flow-graph": 183,
|
|
11337
|
-
"review/review-frontend":
|
|
11352
|
+
"review/review-frontend": 610,
|
|
11338
11353
|
"review/review-frontend-conventions": 206,
|
|
11339
11354
|
"review/review-highload": 472,
|
|
11340
11355
|
"review/review-jev-comments": 179,
|
|
@@ -11344,7 +11359,7 @@ var init_skill_length_ceilings = __esm(() => {
|
|
|
11344
11359
|
"review/review-jev-rules": 262,
|
|
11345
11360
|
"review/review-jev-scenarios": 182,
|
|
11346
11361
|
"review/review-layout": 237,
|
|
11347
|
-
"review/review-logic":
|
|
11362
|
+
"review/review-logic": 364,
|
|
11348
11363
|
"review/review-orchestrator": 1565,
|
|
11349
11364
|
"review/review-performance": 354,
|
|
11350
11365
|
"review/review-pr-contract": 190,
|
|
@@ -11352,7 +11367,7 @@ var init_skill_length_ceilings = __esm(() => {
|
|
|
11352
11367
|
"review/review-premise": 180,
|
|
11353
11368
|
"review/review-regression": 212,
|
|
11354
11369
|
"review/review-security-code": 358,
|
|
11355
|
-
"review/review-style":
|
|
11370
|
+
"review/review-style": 350,
|
|
11356
11371
|
"review/review-testing-practices": 293,
|
|
11357
11372
|
"review/review-ui-ux": 267,
|
|
11358
11373
|
"review/review-verifier": 299
|
|
@@ -20429,8 +20444,8 @@ var init_repomap = __esm(() => {
|
|
|
20429
20444
|
|
|
20430
20445
|
// src/session/preservation.ts
|
|
20431
20446
|
import { createHash as createHash10, randomUUID as randomUUID5 } from "crypto";
|
|
20432
|
-
import { closeSync as closeSync4, fsyncSync, mkdirSync as mkdirSync4, openSync as openSync4, readdirSync as readdirSync5, readFileSync as readFileSync15, renameSync as
|
|
20433
|
-
import
|
|
20447
|
+
import { closeSync as closeSync4, fsyncSync, mkdirSync as mkdirSync4, openSync as openSync4, readdirSync as readdirSync5, readFileSync as readFileSync15, renameSync as renameSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync5 } from "fs";
|
|
20448
|
+
import path70 from "path";
|
|
20434
20449
|
function syncDir(dir) {
|
|
20435
20450
|
if (process.platform === "win32")
|
|
20436
20451
|
return;
|
|
@@ -20442,7 +20457,7 @@ function syncDir(dir) {
|
|
|
20442
20457
|
}
|
|
20443
20458
|
}
|
|
20444
20459
|
function writePreservationFile(file, body) {
|
|
20445
|
-
const dir =
|
|
20460
|
+
const dir = path70.dirname(file);
|
|
20446
20461
|
mkdirSync4(dir, { recursive: true, mode: 448 });
|
|
20447
20462
|
const tmp = `${file}.${randomUUID5()}.tmp`;
|
|
20448
20463
|
const fd = openSync4(tmp, "wx", 384);
|
|
@@ -20453,7 +20468,7 @@ function writePreservationFile(file, body) {
|
|
|
20453
20468
|
closeSync4(fd);
|
|
20454
20469
|
}
|
|
20455
20470
|
try {
|
|
20456
|
-
|
|
20471
|
+
renameSync5(tmp, file);
|
|
20457
20472
|
syncDir(dir);
|
|
20458
20473
|
} catch (error) {
|
|
20459
20474
|
try {
|
|
@@ -20478,21 +20493,21 @@ function commitPreservation(dir, files, beforeSelect) {
|
|
|
20478
20493
|
throw new Error("preservation snapshot exceeds readable size limit");
|
|
20479
20494
|
}
|
|
20480
20495
|
const id = hash(body);
|
|
20481
|
-
const base =
|
|
20482
|
-
mkdirSync4(
|
|
20496
|
+
const base = path70.join(dir, "preservation");
|
|
20497
|
+
mkdirSync4(path70.join(base, "generations"), { recursive: true, mode: 448 });
|
|
20483
20498
|
syncDir(dir);
|
|
20484
20499
|
syncDir(base);
|
|
20485
|
-
writePreservationFile(
|
|
20500
|
+
writePreservationFile(path70.join(base, "generations", `${id}.json`), body);
|
|
20486
20501
|
beforeSelect?.();
|
|
20487
|
-
writePreservationFile(
|
|
20502
|
+
writePreservationFile(path70.join(base, "CURRENT"), id);
|
|
20488
20503
|
return id;
|
|
20489
20504
|
}
|
|
20490
20505
|
function readPreservation(dir, snapshotId) {
|
|
20491
|
-
const base =
|
|
20506
|
+
const base = path70.join(dir, "preservation");
|
|
20492
20507
|
let id = snapshotId;
|
|
20493
20508
|
if (id === undefined) {
|
|
20494
20509
|
try {
|
|
20495
|
-
id = readFileSync15(
|
|
20510
|
+
id = readFileSync15(path70.join(base, "CURRENT"), "utf8");
|
|
20496
20511
|
} catch (e) {
|
|
20497
20512
|
if (e.code === "ENOENT")
|
|
20498
20513
|
return;
|
|
@@ -20501,7 +20516,7 @@ function readPreservation(dir, snapshotId) {
|
|
|
20501
20516
|
}
|
|
20502
20517
|
if (!/^[a-f0-9]{64}$/.test(id))
|
|
20503
20518
|
throw new Error("invalid preservation identity");
|
|
20504
|
-
const read = readTranscriptFile(
|
|
20519
|
+
const read = readTranscriptFile(path70.join(base, "generations", `${id}.json`));
|
|
20505
20520
|
if (!read.ok)
|
|
20506
20521
|
throw new Error(`snapshot unreadable: ${read.reason}`);
|
|
20507
20522
|
if (hash(read.text) !== id)
|
|
@@ -20531,7 +20546,7 @@ function collectPreservationFiles(dir, rawSlate) {
|
|
|
20531
20546
|
for (const name of allowed) {
|
|
20532
20547
|
if (name === "slate.json")
|
|
20533
20548
|
continue;
|
|
20534
|
-
const read = readTranscriptFile(
|
|
20549
|
+
const read = readTranscriptFile(path70.join(dir, name));
|
|
20535
20550
|
if (read.ok)
|
|
20536
20551
|
files[name] = read.text;
|
|
20537
20552
|
else if (read.reason !== "absent")
|
|
@@ -20556,17 +20571,17 @@ function queuePreservedWrapUp(dir, rawSlate) {
|
|
|
20556
20571
|
...files["archive.jsonl"]?.trim() ? ["Transcript retained for evidence review"] : []
|
|
20557
20572
|
]
|
|
20558
20573
|
};
|
|
20559
|
-
const outbox =
|
|
20560
|
-
const target =
|
|
20574
|
+
const outbox = path70.join(dir, "preservation", "outbox");
|
|
20575
|
+
const target = path70.join(outbox, `${snapshot}.json`);
|
|
20561
20576
|
mkdirSync4(outbox, { recursive: true, mode: 448 });
|
|
20562
|
-
syncDir(
|
|
20577
|
+
syncDir(path70.dirname(outbox));
|
|
20563
20578
|
writePreservationFile(target, JSON.stringify(receipt));
|
|
20564
20579
|
return receipt;
|
|
20565
20580
|
}
|
|
20566
20581
|
function readPendingHistory(dir) {
|
|
20567
|
-
let read = readConfigFile(
|
|
20582
|
+
let read = readConfigFile(path70.join(dir, "preservation", "HISTORY"));
|
|
20568
20583
|
if (!read.ok && read.reason === "absent") {
|
|
20569
|
-
read = readConfigFile(
|
|
20584
|
+
read = readConfigFile(path70.join(dir, "preservation", "MIRRORING"));
|
|
20570
20585
|
}
|
|
20571
20586
|
if (!read.ok) {
|
|
20572
20587
|
if (read.reason === "absent")
|
|
@@ -20590,7 +20605,7 @@ var init_preservation = __esm(() => {
|
|
|
20590
20605
|
|
|
20591
20606
|
// src/session/slate.ts
|
|
20592
20607
|
import { mkdir as mkdir13, readFile as readFile32, readdir as readdir18, stat as stat12 } from "fs/promises";
|
|
20593
|
-
import
|
|
20608
|
+
import path71 from "path";
|
|
20594
20609
|
import { unlinkSync as unlinkSync3 } from "fs";
|
|
20595
20610
|
function isReservedNoteKey(key) {
|
|
20596
20611
|
return key.toLowerCase().startsWith(ASK_ANSWER_NOTE_PREFIX);
|
|
@@ -20601,7 +20616,7 @@ function modelNotesOf(notes) {
|
|
|
20601
20616
|
return Object.fromEntries(Object.entries(notes).filter(([key]) => !isReservedNoteKey(key)));
|
|
20602
20617
|
}
|
|
20603
20618
|
function slatePath(dir) {
|
|
20604
|
-
return
|
|
20619
|
+
return path71.join(dir, "slate.json");
|
|
20605
20620
|
}
|
|
20606
20621
|
function slateLockPath(dir) {
|
|
20607
20622
|
return `${slatePath(dir)}.lock`;
|
|
@@ -20625,14 +20640,14 @@ function workingMemoryOf(slate) {
|
|
|
20625
20640
|
};
|
|
20626
20641
|
}
|
|
20627
20642
|
async function readArchivedWorkingMemory(dir) {
|
|
20628
|
-
const archiveDir =
|
|
20643
|
+
const archiveDir = path71.join(dir, "slate-archive");
|
|
20629
20644
|
try {
|
|
20630
20645
|
const names = (await readdir18(archiveDir)).filter((n) => n.endsWith(".json"));
|
|
20631
|
-
const dated = await Promise.all(names.map(async (n) => ({ n, at: (await stat12(
|
|
20646
|
+
const dated = await Promise.all(names.map(async (n) => ({ n, at: (await stat12(path71.join(archiveDir, n))).mtimeMs })));
|
|
20632
20647
|
dated.sort((a, b) => b.at - a.at || (a.n < b.n ? 1 : -1));
|
|
20633
20648
|
for (const { n } of dated) {
|
|
20634
20649
|
try {
|
|
20635
|
-
const slate = JSON.parse(await readFile32(
|
|
20650
|
+
const slate = JSON.parse(await readFile32(path71.join(archiveDir, n), "utf8"));
|
|
20636
20651
|
const carry = workingMemoryOf(slate);
|
|
20637
20652
|
if (carry.trail !== undefined || carry.notes !== undefined || carry.answers !== undefined)
|
|
20638
20653
|
return carry;
|
|
@@ -20667,11 +20682,11 @@ async function archiveIfExistsLocked(dir, attemptId, signal) {
|
|
|
20667
20682
|
return;
|
|
20668
20683
|
throw error;
|
|
20669
20684
|
}
|
|
20670
|
-
const archiveDir =
|
|
20685
|
+
const archiveDir = path71.join(dir, "slate-archive");
|
|
20671
20686
|
await mkdir13(archiveDir, { recursive: true });
|
|
20672
20687
|
signal?.throwIfAborted();
|
|
20673
20688
|
queuePreservedWrapUp(dir, raw);
|
|
20674
|
-
writePreservationFile(
|
|
20689
|
+
writePreservationFile(path71.join(archiveDir, `${attemptId}.json`), raw);
|
|
20675
20690
|
unlinkSync3(slatePath(dir));
|
|
20676
20691
|
}
|
|
20677
20692
|
async function openSlateAtomic(dir, mintAttemptId, build, signal) {
|
|
@@ -20687,7 +20702,7 @@ async function openSlateAtomic(dir, mintAttemptId, build, signal) {
|
|
|
20687
20702
|
writePreservationFile(slatePath(dir), `${JSON.stringify(next, null, 2)}
|
|
20688
20703
|
`);
|
|
20689
20704
|
try {
|
|
20690
|
-
unlinkSync3(
|
|
20705
|
+
unlinkSync3(path71.join(dir, "terminal-state.json"));
|
|
20691
20706
|
} catch (error) {
|
|
20692
20707
|
if (!isNotFound(error))
|
|
20693
20708
|
throw error;
|
|
@@ -21089,9 +21104,9 @@ var init_validation = __esm(() => {
|
|
|
21089
21104
|
});
|
|
21090
21105
|
|
|
21091
21106
|
// src/memory/config.ts
|
|
21092
|
-
import
|
|
21107
|
+
import path81 from "path";
|
|
21093
21108
|
function memoryConfigPath(cwd) {
|
|
21094
|
-
return
|
|
21109
|
+
return path81.join(cwd, ".metaproject", "memory.config.json");
|
|
21095
21110
|
}
|
|
21096
21111
|
async function loadMemoryConfig(cwd) {
|
|
21097
21112
|
const file = memoryConfigPath(cwd);
|
|
@@ -21169,12 +21184,12 @@ var init_config4 = __esm(() => {
|
|
|
21169
21184
|
|
|
21170
21185
|
// src/memory/write.ts
|
|
21171
21186
|
import { mkdir as mkdir18, open as open6, readFile as readFile39, rename as rename4, rm as rm7, writeFile as writeFile9 } from "fs/promises";
|
|
21172
|
-
import
|
|
21187
|
+
import path84 from "path";
|
|
21173
21188
|
async function resolveCanonicalEntryPath(cwd, relativePath) {
|
|
21174
|
-
const root =
|
|
21175
|
-
const absolutePath =
|
|
21176
|
-
const normalized = toPosix2(
|
|
21177
|
-
if (!normalized || normalized.startsWith("../") ||
|
|
21189
|
+
const root = path84.resolve(memoryRoot(cwd));
|
|
21190
|
+
const absolutePath = path84.resolve(root, relativePath);
|
|
21191
|
+
const normalized = toPosix2(path84.relative(root, absolutePath));
|
|
21192
|
+
if (!normalized || normalized.startsWith("../") || path84.isAbsolute(normalized) || !normalized.endsWith(".md")) {
|
|
21178
21193
|
return null;
|
|
21179
21194
|
}
|
|
21180
21195
|
return { absolutePath, relativePath: normalized };
|
|
@@ -21227,9 +21242,9 @@ function validateNextEntry(relativePath, content) {
|
|
|
21227
21242
|
return null;
|
|
21228
21243
|
}
|
|
21229
21244
|
async function replaceAtomically(target, content) {
|
|
21230
|
-
const dir =
|
|
21245
|
+
const dir = path84.dirname(target);
|
|
21231
21246
|
await mkdir18(dir, { recursive: true });
|
|
21232
|
-
const tmp =
|
|
21247
|
+
const tmp = path84.join(dir, `.${path84.basename(target)}.keryx-tmp-${process.pid}-${Math.random().toString(16).slice(2)}`);
|
|
21233
21248
|
try {
|
|
21234
21249
|
await writeFile9(tmp, content, "utf8");
|
|
21235
21250
|
const file = await open6(tmp, "r");
|
|
@@ -21258,7 +21273,7 @@ function header(content, name) {
|
|
|
21258
21273
|
return content.match(new RegExp(`^${name}:\\s*(.+)$`, "mi"))?.[1]?.trim() ?? null;
|
|
21259
21274
|
}
|
|
21260
21275
|
function toPosix2(value) {
|
|
21261
|
-
return value.split(
|
|
21276
|
+
return value.split(path84.sep).join("/");
|
|
21262
21277
|
}
|
|
21263
21278
|
function message(cause) {
|
|
21264
21279
|
return cause instanceof Error ? cause.message : String(cause);
|
|
@@ -21370,9 +21385,9 @@ var init_evidence = __esm(() => {
|
|
|
21370
21385
|
});
|
|
21371
21386
|
|
|
21372
21387
|
// src/wiki/config.ts
|
|
21373
|
-
import
|
|
21388
|
+
import path85 from "path";
|
|
21374
21389
|
function wikiConfigPath(cwd) {
|
|
21375
|
-
return
|
|
21390
|
+
return path85.join(cwd, ".metaproject", "wiki.config.json");
|
|
21376
21391
|
}
|
|
21377
21392
|
function mergeWikiConfig(parsed) {
|
|
21378
21393
|
const base = DEFAULT_WIKI_CONFIG;
|
|
@@ -21450,12 +21465,12 @@ var init_config5 = __esm(() => {
|
|
|
21450
21465
|
// src/wiki/history.ts
|
|
21451
21466
|
import { createHash as createHash20, randomBytes as randomBytes4 } from "crypto";
|
|
21452
21467
|
import { appendFile as appendFile3, mkdir as mkdir19, open as open7, readFile as readFile41, rm as rm8, stat as stat13, writeFile as writeFile10 } from "fs/promises";
|
|
21453
|
-
import
|
|
21468
|
+
import path86 from "path";
|
|
21454
21469
|
function wikiRootPath(cwd) {
|
|
21455
|
-
return
|
|
21470
|
+
return path86.join(cwd, ".metaproject", "wiki");
|
|
21456
21471
|
}
|
|
21457
21472
|
function wikiHistoryRoot(cwd) {
|
|
21458
|
-
return
|
|
21473
|
+
return path86.join(cwd, ".metaproject", "data", "gdwiki", "history");
|
|
21459
21474
|
}
|
|
21460
21475
|
function newWikiRunId(now = new Date) {
|
|
21461
21476
|
const stamp = now.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
|
|
@@ -21476,26 +21491,26 @@ async function openWikiWriteContext(cwd, command) {
|
|
|
21476
21491
|
return createWikiWriteContext(cwd, command, { keep: (await loadWikiConfig(cwd)).history.keep });
|
|
21477
21492
|
}
|
|
21478
21493
|
function wikiPageKey(cwd, absolutePath) {
|
|
21479
|
-
const relative =
|
|
21480
|
-
if (relative === "" || relative.startsWith("..") ||
|
|
21494
|
+
const relative = path86.relative(wikiRootPath(cwd), path86.resolve(absolutePath));
|
|
21495
|
+
if (relative === "" || relative.startsWith("..") || path86.isAbsolute(relative)) {
|
|
21481
21496
|
throw new Error(`not a wiki page: ${absolutePath}`);
|
|
21482
21497
|
}
|
|
21483
21498
|
return toPosix(relative);
|
|
21484
21499
|
}
|
|
21485
21500
|
function assertPageKey(page) {
|
|
21486
21501
|
const segments = page.split("/");
|
|
21487
|
-
if (page.length === 0 || page.includes("\\") ||
|
|
21502
|
+
if (page.length === 0 || page.includes("\\") || path86.isAbsolute(page) || segments.some((segment) => segment === "" || segment === "." || segment === "..")) {
|
|
21488
21503
|
throw new Error(`not a wiki page path: ${page}`);
|
|
21489
21504
|
}
|
|
21490
21505
|
return page;
|
|
21491
21506
|
}
|
|
21492
21507
|
function pageHistoryDir(cwd, page) {
|
|
21493
|
-
return
|
|
21508
|
+
return path86.join(wikiHistoryRoot(cwd), ...assertPageKey(page).replace(/\.md$/i, "").split("/"));
|
|
21494
21509
|
}
|
|
21495
21510
|
function versionFilePath(cwd, page, file) {
|
|
21496
21511
|
const dir = pageHistoryDir(cwd, page);
|
|
21497
|
-
const target =
|
|
21498
|
-
if (!VERSION_FILE.test(file) ||
|
|
21512
|
+
const target = path86.join(dir, file);
|
|
21513
|
+
if (!VERSION_FILE.test(file) || path86.dirname(target) !== dir) {
|
|
21499
21514
|
throw new Error(`history index names an invalid version file for ${page}: ${file}`);
|
|
21500
21515
|
}
|
|
21501
21516
|
return target;
|
|
@@ -21562,7 +21577,7 @@ function parsePageHistoryIndex(markdown, page) {
|
|
|
21562
21577
|
return { page, rows };
|
|
21563
21578
|
}
|
|
21564
21579
|
async function readPageHistory(cwd, page) {
|
|
21565
|
-
const indexPath =
|
|
21580
|
+
const indexPath = path86.join(pageHistoryDir(cwd, page), INDEX_FILE);
|
|
21566
21581
|
const raw = await readBufferOrNull(indexPath);
|
|
21567
21582
|
if (raw === null)
|
|
21568
21583
|
return null;
|
|
@@ -21574,8 +21589,8 @@ async function readPageHistory(cwd, page) {
|
|
|
21574
21589
|
}
|
|
21575
21590
|
async function storeVersion(cwd, page, version, at, content) {
|
|
21576
21591
|
const fileName = `${versionLabel(version)}-${at.replace(/[:.]/g, "-")}.md`;
|
|
21577
|
-
const target =
|
|
21578
|
-
await mkdir19(
|
|
21592
|
+
const target = path86.join(pageHistoryDir(cwd, page), fileName);
|
|
21593
|
+
await mkdir19(path86.dirname(target), { recursive: true });
|
|
21579
21594
|
await writeFile10(target, content);
|
|
21580
21595
|
if (sha2562(await readFile41(target)) !== sha2562(content)) {
|
|
21581
21596
|
throw new Error(`history: stored version does not match the page bytes: ${target}`);
|
|
@@ -21613,7 +21628,7 @@ function planPrune2(history, keep, maxRows = MAX_INDEX_ROWS) {
|
|
|
21613
21628
|
}
|
|
21614
21629
|
async function ensureHistoryRoot(cwd) {
|
|
21615
21630
|
const root = wikiHistoryRoot(cwd);
|
|
21616
|
-
const ignore =
|
|
21631
|
+
const ignore = path86.join(root, ".gitignore");
|
|
21617
21632
|
if (await readBufferOrNull(ignore))
|
|
21618
21633
|
return;
|
|
21619
21634
|
await mkdir19(root, { recursive: true });
|
|
@@ -21643,14 +21658,14 @@ async function endsWithoutNewline(file) {
|
|
|
21643
21658
|
}
|
|
21644
21659
|
async function appendRun(cwd, entry) {
|
|
21645
21660
|
const root = wikiHistoryRoot(cwd);
|
|
21646
|
-
const file =
|
|
21661
|
+
const file = path86.join(root, RUNS_FILE);
|
|
21647
21662
|
const lead = await endsWithoutNewline(file) ? `
|
|
21648
21663
|
` : "";
|
|
21649
21664
|
await appendFile3(file, `${lead}${JSON.stringify(entry)}
|
|
21650
21665
|
`, "utf8");
|
|
21651
21666
|
if ((await stat13(file)).size <= MAX_RUNS_BYTES)
|
|
21652
21667
|
return;
|
|
21653
|
-
await withFileLock2(
|
|
21668
|
+
await withFileLock2(path86.join(root, ".runs.lock"), async () => {
|
|
21654
21669
|
if ((await stat13(file)).size <= MAX_RUNS_BYTES)
|
|
21655
21670
|
return;
|
|
21656
21671
|
const lines = (await readFile41(file, "utf8")).split(`
|
|
@@ -21664,7 +21679,7 @@ async function mutatePage(ctx, absolutePath, next) {
|
|
|
21664
21679
|
const page = wikiPageKey(ctx.cwd, absolutePath);
|
|
21665
21680
|
const dir = pageHistoryDir(ctx.cwd, page);
|
|
21666
21681
|
await ensureHistoryRoot(ctx.cwd);
|
|
21667
|
-
return withFileLock2(
|
|
21682
|
+
return withFileLock2(path86.join(path86.dirname(dir), `.${path86.basename(dir)}.lock`), async () => {
|
|
21668
21683
|
const live = await readBufferOrNull(absolutePath);
|
|
21669
21684
|
if (next === null ? live === null : live !== null && live.equals(next)) {
|
|
21670
21685
|
return { changed: false };
|
|
@@ -21688,7 +21703,7 @@ async function mutatePage(ctx, absolutePath, next) {
|
|
|
21688
21703
|
if (next === null) {
|
|
21689
21704
|
await rm8(absolutePath, { force: true });
|
|
21690
21705
|
} else {
|
|
21691
|
-
await mkdir19(
|
|
21706
|
+
await mkdir19(path86.dirname(absolutePath), { recursive: true });
|
|
21692
21707
|
await writeFile10(absolutePath, next);
|
|
21693
21708
|
}
|
|
21694
21709
|
} catch (error) {
|
|
@@ -21696,7 +21711,7 @@ async function mutatePage(ctx, absolutePath, next) {
|
|
|
21696
21711
|
await rm8(versionFilePath(ctx.cwd, page, row.file), { force: true });
|
|
21697
21712
|
throw error;
|
|
21698
21713
|
}
|
|
21699
|
-
await writeFileAtomic(
|
|
21714
|
+
await writeFileAtomic(path86.join(dir, INDEX_FILE), renderPageHistoryIndex(history));
|
|
21700
21715
|
for (const file of pruned)
|
|
21701
21716
|
await rm8(versionFilePath(ctx.cwd, page, file), { force: true });
|
|
21702
21717
|
return { changed: true, action };
|
|
@@ -28744,9 +28759,52 @@ init_validator();
|
|
|
28744
28759
|
import { appendFileSync as appendFileSync2 } from "fs";
|
|
28745
28760
|
|
|
28746
28761
|
// src/lib/call-diagnostics.ts
|
|
28747
|
-
init_config_dir();
|
|
28748
28762
|
import { statSync as statSync5 } from "fs";
|
|
28763
|
+
import path66 from "path";
|
|
28764
|
+
|
|
28765
|
+
// src/lib/diagnostics-journal.ts
|
|
28766
|
+
init_config_dir();
|
|
28767
|
+
import { lstatSync as lstatSync4, renameSync as renameSync4 } from "fs";
|
|
28749
28768
|
import path65 from "path";
|
|
28769
|
+
function createDiagnosticsJournal(opts) {
|
|
28770
|
+
const name = opts.sessionId.replace(/[^A-Za-z0-9._-]/g, "_") || "session";
|
|
28771
|
+
const file = path65.join(keryxConfigDir(opts.configDir), "diagnostics", `${name}.events.ndjson`);
|
|
28772
|
+
const cap = opts.maxFileBytes ?? 1e6;
|
|
28773
|
+
return {
|
|
28774
|
+
path: () => file,
|
|
28775
|
+
write(row) {
|
|
28776
|
+
try {
|
|
28777
|
+
const line = JSON.stringify(row);
|
|
28778
|
+
if (line === undefined || Buffer.byteLength(line) + 1 > cap)
|
|
28779
|
+
return { ok: false, error: "ROW_TOO_LARGE" };
|
|
28780
|
+
ensureKeryxSubdir(["diagnostics"], opts.configDir);
|
|
28781
|
+
let size = 0;
|
|
28782
|
+
try {
|
|
28783
|
+
const info = lstatSync4(file);
|
|
28784
|
+
if (!info.isFile() || info.nlink !== 1)
|
|
28785
|
+
return { ok: false, error: "UNSAFE_FILE" };
|
|
28786
|
+
size = info.size;
|
|
28787
|
+
} catch (error) {
|
|
28788
|
+
if (error.code !== "ENOENT")
|
|
28789
|
+
throw error;
|
|
28790
|
+
}
|
|
28791
|
+
if (size + Buffer.byteLength(line) + 1 > cap)
|
|
28792
|
+
renameSync4(file, `${file}.1`);
|
|
28793
|
+
appendPrivateRecord(file, line);
|
|
28794
|
+
return { ok: true };
|
|
28795
|
+
} catch (error) {
|
|
28796
|
+
const code = error?.code;
|
|
28797
|
+
return { ok: false, error: typeof code === "string" && /^[A-Z0-9_]+$/.test(code) ? code : "JOURNAL_WRITE_FAILED" };
|
|
28798
|
+
}
|
|
28799
|
+
}
|
|
28800
|
+
};
|
|
28801
|
+
}
|
|
28802
|
+
function diagnosticMeasurements(input) {
|
|
28803
|
+
return Object.fromEntries(Object.entries(input).filter(([key, value]) => /^[a-zA-Z][a-zA-Z0-9]{0,39}$/.test(key) && (typeof value === "boolean" || typeof value === "number" && Number.isFinite(value))));
|
|
28804
|
+
}
|
|
28805
|
+
|
|
28806
|
+
// src/lib/call-diagnostics.ts
|
|
28807
|
+
init_config_dir();
|
|
28750
28808
|
var DEFAULT_WATCH_INTERVAL_MS = 30000;
|
|
28751
28809
|
var DEFAULT_STALL_MS = 10 * 60000;
|
|
28752
28810
|
var DEFAULT_REPEAT_MS = 15 * 60000;
|
|
@@ -28778,6 +28836,39 @@ function createCallDiagnostics(options = {}) {
|
|
|
28778
28836
|
let repeatMs = DEFAULT_REPEAT_MS;
|
|
28779
28837
|
let lastDumpAt;
|
|
28780
28838
|
let lastDumpIds = new Set;
|
|
28839
|
+
let journal;
|
|
28840
|
+
let journalFailure;
|
|
28841
|
+
let warnJournal;
|
|
28842
|
+
let warningDelivered = false;
|
|
28843
|
+
const persist = (kind, fields = {}) => {
|
|
28844
|
+
if (journal === undefined)
|
|
28845
|
+
return;
|
|
28846
|
+
const result = journal.write({ ts: new Date(now()).toISOString(), kind, ...fields });
|
|
28847
|
+
if (result.ok)
|
|
28848
|
+
return;
|
|
28849
|
+
journalFailure = result.error;
|
|
28850
|
+
if (!warningDelivered) {
|
|
28851
|
+
warningDelivered = true;
|
|
28852
|
+
try {
|
|
28853
|
+
warnJournal?.(result.error);
|
|
28854
|
+
} catch {
|
|
28855
|
+
journalFailure = "JOURNAL_WARNING_FAILED";
|
|
28856
|
+
}
|
|
28857
|
+
}
|
|
28858
|
+
};
|
|
28859
|
+
const persistSnapshot = () => persist("snapshot", {
|
|
28860
|
+
calls: [...calls.values()].map((c) => ({
|
|
28861
|
+
id: c.id,
|
|
28862
|
+
name: c.name,
|
|
28863
|
+
stage: c.stage,
|
|
28864
|
+
ageMs: now() - c.startedAt,
|
|
28865
|
+
stageAgeMs: now() - c.stageSince,
|
|
28866
|
+
stageChanges: c.stageChanges
|
|
28867
|
+
})),
|
|
28868
|
+
callsStarted: metrics.callsStarted,
|
|
28869
|
+
callsSettled: metrics.callsSettled,
|
|
28870
|
+
lastLagMs
|
|
28871
|
+
});
|
|
28781
28872
|
const record = (label) => {
|
|
28782
28873
|
ring.push(`${new Date(now()).toISOString()} ${label}`);
|
|
28783
28874
|
if (ring.length > ringSize)
|
|
@@ -28865,6 +28956,7 @@ function createCallDiagnostics(options = {}) {
|
|
|
28865
28956
|
metrics.maxLoopLagMs = lag;
|
|
28866
28957
|
}
|
|
28867
28958
|
lastTickAt = at;
|
|
28959
|
+
persistSnapshot();
|
|
28868
28960
|
const suspects = [...calls.values()].filter((c) => c.watched && at - c.stageSince >= (HUMAN_STAGES.has(c.stage) ? stallMs * HUMAN_STAGE_FACTOR : stallMs));
|
|
28869
28961
|
if (suspects.length === 0) {
|
|
28870
28962
|
lastDumpIds = new Set;
|
|
@@ -28888,6 +28980,7 @@ function createCallDiagnostics(options = {}) {
|
|
|
28888
28980
|
key = `${id}~${n}`;
|
|
28889
28981
|
calls.set(key, { id: key, name, startedAt: at, watched: opts?.watched !== false, stage: "start", stageSince: at, stageChanges: 0 });
|
|
28890
28982
|
metrics.callsStarted += 1;
|
|
28983
|
+
persist("call.begin", { id: key, name });
|
|
28891
28984
|
return key;
|
|
28892
28985
|
},
|
|
28893
28986
|
stage(id, next) {
|
|
@@ -28899,6 +28992,7 @@ function createCallDiagnostics(options = {}) {
|
|
|
28899
28992
|
call.stage = next;
|
|
28900
28993
|
call.stageSince = at;
|
|
28901
28994
|
call.stageChanges += 1;
|
|
28995
|
+
persist("call.stage", { id, stage: next });
|
|
28902
28996
|
},
|
|
28903
28997
|
end(id, outcome) {
|
|
28904
28998
|
const call = calls.get(id);
|
|
@@ -28908,10 +29002,12 @@ function createCallDiagnostics(options = {}) {
|
|
|
28908
29002
|
calls.delete(id);
|
|
28909
29003
|
metrics.callsSettled += 1;
|
|
28910
29004
|
metrics.callsByOutcome[outcome] = (metrics.callsByOutcome[outcome] ?? 0) + 1;
|
|
29005
|
+
persist("call.end", { id, outcome, ageMs: now() - call.startedAt });
|
|
28911
29006
|
},
|
|
28912
29007
|
event(kind, detail) {
|
|
28913
29008
|
metrics.events[kind] = (metrics.events[kind] ?? 0) + 1;
|
|
28914
29009
|
record(detail === undefined ? `event ${kind}` : `event ${kind} ${detail}`);
|
|
29010
|
+
persist(kind);
|
|
28915
29011
|
},
|
|
28916
29012
|
record,
|
|
28917
29013
|
probe(name, fn) {
|
|
@@ -28925,6 +29021,9 @@ function createCallDiagnostics(options = {}) {
|
|
|
28925
29021
|
dump,
|
|
28926
29022
|
inFlight: () => [...calls.values()],
|
|
28927
29023
|
dumpPath: () => file,
|
|
29024
|
+
journalPath: () => journal?.path(),
|
|
29025
|
+
journalError: () => journalFailure,
|
|
29026
|
+
observe: (kind, measurements) => persist(kind, diagnosticMeasurements(measurements)),
|
|
28928
29027
|
tick,
|
|
28929
29028
|
start(opts) {
|
|
28930
29029
|
sessionId = opts.sessionId;
|
|
@@ -28932,11 +29031,19 @@ function createCallDiagnostics(options = {}) {
|
|
|
28932
29031
|
stallMs = opts.stallMs ?? DEFAULT_STALL_MS;
|
|
28933
29032
|
repeatMs = opts.repeatMs ?? DEFAULT_REPEAT_MS;
|
|
28934
29033
|
const cap = opts.maxFileBytes ?? DEFAULT_MAX_FILE_BYTES;
|
|
29034
|
+
journal = opts.continuous ? createDiagnosticsJournal(opts) : undefined;
|
|
29035
|
+
journalFailure = undefined;
|
|
29036
|
+
warningDelivered = false;
|
|
29037
|
+
warnJournal = opts.onJournalError ?? ((code) => {
|
|
29038
|
+
process.stderr.write(`keryx: diagnostics journal unavailable (${code}).
|
|
29039
|
+
`);
|
|
29040
|
+
});
|
|
29041
|
+
persist("session.start", { pid: process.pid, sessionId });
|
|
28935
29042
|
if (sink === undefined) {
|
|
28936
29043
|
sink = (line) => {
|
|
28937
29044
|
if (file === undefined) {
|
|
28938
29045
|
const dir = ensureKeryxSubdir(["diagnostics"], opts.configDir);
|
|
28939
|
-
file =
|
|
29046
|
+
file = path66.join(dir, `${opts.sessionId.replace(/[^A-Za-z0-9._-]/g, "_")}.ndjson`);
|
|
28940
29047
|
}
|
|
28941
29048
|
let size = 0;
|
|
28942
29049
|
try {
|
|
@@ -28954,7 +29061,16 @@ function createCallDiagnostics(options = {}) {
|
|
|
28954
29061
|
} catch {}
|
|
28955
29062
|
}, intervalMs);
|
|
28956
29063
|
timer.unref?.();
|
|
28957
|
-
|
|
29064
|
+
let stopped = false;
|
|
29065
|
+
return () => {
|
|
29066
|
+
if (stopped)
|
|
29067
|
+
return;
|
|
29068
|
+
stopped = true;
|
|
29069
|
+
clearInterval(timer);
|
|
29070
|
+
persistSnapshot();
|
|
29071
|
+
persist("session.stop");
|
|
29072
|
+
journal = undefined;
|
|
29073
|
+
};
|
|
28958
29074
|
}
|
|
28959
29075
|
};
|
|
28960
29076
|
}
|
|
@@ -28977,7 +29093,7 @@ function tracePhase(label, env = process.env) {
|
|
|
28977
29093
|
init_json();
|
|
28978
29094
|
init_shell_syntax();
|
|
28979
29095
|
import { readdir as readdir17, stat as stat11 } from "fs/promises";
|
|
28980
|
-
import
|
|
29096
|
+
import path67 from "path";
|
|
28981
29097
|
var PR_REF = /(?:github\.com\/([\w.-]+\/[\w.-]+)\/pull\/(\d+))|^#?(\d+)$/;
|
|
28982
29098
|
var REVIEW_ENDPOINT = /(?:^|\/)repos\/([^/]+\/[^/]+)\/pulls\/(\d+)\/reviews(?:\/\d+\/events)?\/?$/;
|
|
28983
29099
|
var PR_REVIEW_VALUE_FLAGS = new Set(["-R", "--repo", "-b", "--body", "-F", "--body-file"]);
|
|
@@ -29056,12 +29172,12 @@ async function boundPackages(cwd) {
|
|
|
29056
29172
|
}
|
|
29057
29173
|
const found = [];
|
|
29058
29174
|
for (const name of names) {
|
|
29059
|
-
const dir =
|
|
29060
|
-
const manifest = await readJsonFileOr(
|
|
29175
|
+
const dir = path67.join(reviewsRoot(cwd), name);
|
|
29176
|
+
const manifest = await readJsonFileOr(path67.join(dir, "manifest.json"), undefined);
|
|
29061
29177
|
if (manifest === undefined || !isPrBound(manifest.target))
|
|
29062
29178
|
continue;
|
|
29063
29179
|
const ref = parseRef(manifest.target.ref);
|
|
29064
|
-
const info = await stat11(
|
|
29180
|
+
const info = await stat11(path67.join(dir, "manifest.json")).catch(() => {
|
|
29065
29181
|
return;
|
|
29066
29182
|
});
|
|
29067
29183
|
found.push({ dir, id: manifest.reviewId, status: manifest.status, number: ref.number, repo: ref.repo, mtime: info?.mtimeMs ?? 0 });
|
|
@@ -29234,7 +29350,7 @@ init_command_risk();
|
|
|
29234
29350
|
init_contained_path();
|
|
29235
29351
|
import { createHash as createHash9 } from "crypto";
|
|
29236
29352
|
import { closeSync as closeSync3, constants as constants6, fstatSync as fstatSync3, openSync as openSync3, readSync } from "fs";
|
|
29237
|
-
import
|
|
29353
|
+
import path68 from "path";
|
|
29238
29354
|
|
|
29239
29355
|
// src/lib/review-path-flags.ts
|
|
29240
29356
|
init_args();
|
|
@@ -29392,7 +29508,7 @@ function carriesPreload(text) {
|
|
|
29392
29508
|
}
|
|
29393
29509
|
var MAX_BUNFIG_BYTES = 256 * 1024;
|
|
29394
29510
|
function readBunfig(root) {
|
|
29395
|
-
const file =
|
|
29511
|
+
const file = path68.join(root, "bunfig.toml");
|
|
29396
29512
|
let fd;
|
|
29397
29513
|
try {
|
|
29398
29514
|
fd = openSync3(file, constants6.O_RDONLY | constants6.O_NONBLOCK);
|
|
@@ -29473,10 +29589,10 @@ function movedTo(cwd, target) {
|
|
|
29473
29589
|
if (cwd === undefined || target === "" || target.startsWith("-") || isExpandable(target))
|
|
29474
29590
|
return;
|
|
29475
29591
|
const cdpath = process.env.CDPATH;
|
|
29476
|
-
if (cdpath !== undefined && cdpath !== "" && !
|
|
29592
|
+
if (cdpath !== undefined && cdpath !== "" && !path68.isAbsolute(target) && !target.startsWith("./") && !target.startsWith("../")) {
|
|
29477
29593
|
return;
|
|
29478
29594
|
}
|
|
29479
|
-
const lexical =
|
|
29595
|
+
const lexical = path68.resolve(cwd, target);
|
|
29480
29596
|
return realOrResolved(lexical) === lexical ? lexical : undefined;
|
|
29481
29597
|
}
|
|
29482
29598
|
function areReviewPathFlagsInside(sub, args, walk) {
|
|
@@ -29511,11 +29627,11 @@ function isOutsideReadFlag(word) {
|
|
|
29511
29627
|
return name.length >= 3 && name.startsWith("--") && GIT_OUTSIDE_READ_FLAGS.some((flag) => flag.startsWith(name));
|
|
29512
29628
|
}
|
|
29513
29629
|
function isOutsideRoot(projectRoot, target) {
|
|
29514
|
-
const relative =
|
|
29515
|
-
return relative === ".." || relative.startsWith(`..${
|
|
29630
|
+
const relative = path68.relative(projectRoot, target);
|
|
29631
|
+
return relative === ".." || relative.startsWith(`..${path68.sep}`) || path68.isAbsolute(relative);
|
|
29516
29632
|
}
|
|
29517
29633
|
function isEscapingOperand(word, cwd, projectRoot) {
|
|
29518
|
-
return isOutsideRoot(projectRoot, realOrResolved(
|
|
29634
|
+
return isOutsideRoot(projectRoot, realOrResolved(path68.resolve(cwd, word)));
|
|
29519
29635
|
}
|
|
29520
29636
|
function isGitReadConfined(words, walk) {
|
|
29521
29637
|
const cwd = walk.cwd;
|
|
@@ -29556,7 +29672,7 @@ function isTrustRoutineCommand(command, context = {}) {
|
|
|
29556
29672
|
const segments = splitSegments(command);
|
|
29557
29673
|
if (segments.length === 0 || segments.length > MAX_CHAIN_SEGMENTS)
|
|
29558
29674
|
return false;
|
|
29559
|
-
const cwd = realOrResolved(
|
|
29675
|
+
const cwd = realOrResolved(path68.resolve(context.cwd ?? process.cwd()));
|
|
29560
29676
|
const walk = { projectRoot: realOrResolved(resolveProjectRoot(cwd)), cwd, untrusted: context.untrustedContent === true };
|
|
29561
29677
|
return segments.every((seg) => (seg.precededBy === undefined || seg.precededBy === "&&") && !hasUnquotedMetacharacter(seg.raw) && !(isJudgedByWords(seg.words) && hasUnquotedExpansion(seg.raw)) && isRoutineSegment(seg.words, walk));
|
|
29562
29678
|
}
|
|
@@ -29591,9 +29707,9 @@ function resolveQuestionAnswerer(mode) {
|
|
|
29591
29707
|
}
|
|
29592
29708
|
|
|
29593
29709
|
// src/commands/automatic-review.ts
|
|
29594
|
-
import { existsSync as existsSync17, lstatSync as
|
|
29710
|
+
import { existsSync as existsSync17, lstatSync as lstatSync5, realpathSync as realpathSync4 } from "fs";
|
|
29595
29711
|
import { mkdir as mkdir12, writeFile as writeFile7 } from "fs/promises";
|
|
29596
|
-
import
|
|
29712
|
+
import path69 from "path";
|
|
29597
29713
|
|
|
29598
29714
|
// src/harness/tool/builtin/ask-user-tool.ts
|
|
29599
29715
|
var ASK_USER_DESCRIPTION = "Ask the user an interactive multiple-choice question (Claude-style interview). " + "Use when requirements are unclear, for interview steps, or to confirm a plan. " + "Provide 2\u20136 options with short descriptions; mark at most ONE option recommended when sensible (more than one is rejected). " + "Whenever you mark an option recommended, ALWAYS set recommendationReason: one sentence on why it is the better choice. " + "Input: { question: string, options: [{ id, label, description, recommended? }], recommendationReason?: string, allow_freeform?: boolean, action?: string, irreversible?: boolean, emergency?: string }. " + "Returns the chosen option id (or freeform text if allow_freeform). " + "irreversible: true means the question decides something that cannot be undone (release, publish, deploy, delete, push, merge to a shared branch, drop, force, reset, tag a version). " + 'action names that irreversible action (e.g. action: "release"). ' + "policy: { kind, facts } optionally tags a review question with its kind (scope, budget, option_choice, partial_coverage, smaller_slice, slice_order) " + "and numeric or boolean facts about the recommended option; only the automatic answerer reads it, as numbers and flags, never as text. " + `emergency: "gate-waiver" (a gate refusal needs the operator's quote) or "reduced-reviewer-set"; the only two cases an automatic review may put to the operator.`;
|
|
@@ -29805,7 +29921,7 @@ var OPERATOR_ONLY_NAMES = new Set([foldFileName(OPERATOR_DECISIONS_FILE), foldFi
|
|
|
29805
29921
|
var PLAIN_SEGMENT = /^[A-Za-z0-9._-]+$/;
|
|
29806
29922
|
function entryExists(file) {
|
|
29807
29923
|
try {
|
|
29808
|
-
|
|
29924
|
+
lstatSync5(file);
|
|
29809
29925
|
return true;
|
|
29810
29926
|
} catch {
|
|
29811
29927
|
return false;
|
|
@@ -29815,20 +29931,20 @@ function realTarget(target) {
|
|
|
29815
29931
|
let existing = target;
|
|
29816
29932
|
const rest = [];
|
|
29817
29933
|
while (!entryExists(existing)) {
|
|
29818
|
-
const parent =
|
|
29934
|
+
const parent = path69.dirname(existing);
|
|
29819
29935
|
if (parent === existing)
|
|
29820
29936
|
return target;
|
|
29821
|
-
rest.unshift(
|
|
29937
|
+
rest.unshift(path69.basename(existing));
|
|
29822
29938
|
existing = parent;
|
|
29823
29939
|
}
|
|
29824
29940
|
try {
|
|
29825
|
-
return
|
|
29941
|
+
return path69.join(realpathSync4(existing), ...rest);
|
|
29826
29942
|
} catch {
|
|
29827
29943
|
return "";
|
|
29828
29944
|
}
|
|
29829
29945
|
}
|
|
29830
29946
|
function segmentsBelow(base, target) {
|
|
29831
|
-
return
|
|
29947
|
+
return path69.relative(base, target).split(/[\\/]/);
|
|
29832
29948
|
}
|
|
29833
29949
|
function hasOnlyPlainSegments(base, target) {
|
|
29834
29950
|
return segmentsBelow(base, target).every((segment) => PLAIN_SEGMENT.test(segment));
|
|
@@ -29837,7 +29953,7 @@ function touchesOperatorOnlyName(base, target) {
|
|
|
29837
29953
|
return segmentsBelow(base, target).some((segment) => OPERATOR_ONLY_NAMES.has(foldFileName(segment)));
|
|
29838
29954
|
}
|
|
29839
29955
|
function escapesPackage(realDir, real) {
|
|
29840
|
-
return !real.startsWith(`${realDir}${
|
|
29956
|
+
return !real.startsWith(`${realDir}${path69.sep}`);
|
|
29841
29957
|
}
|
|
29842
29958
|
|
|
29843
29959
|
class AutomaticReviewRun {
|
|
@@ -29875,11 +29991,11 @@ class AutomaticReviewRun {
|
|
|
29875
29991
|
return false;
|
|
29876
29992
|
}
|
|
29877
29993
|
const realDir = realTarget(dir);
|
|
29878
|
-
const isData = (file) => PACKAGE_DATA_EXTENSIONS.has(
|
|
29994
|
+
const isData = (file) => PACKAGE_DATA_EXTENSIONS.has(path69.extname(file).toLowerCase());
|
|
29879
29995
|
return targets.every((target) => {
|
|
29880
|
-
const resolved =
|
|
29996
|
+
const resolved = path69.resolve(this.cwd, target);
|
|
29881
29997
|
const real = realTarget(resolved);
|
|
29882
|
-
return resolved.startsWith(`${dir}${
|
|
29998
|
+
return resolved.startsWith(`${dir}${path69.sep}`) && !escapesPackage(realDir, real) && hasOnlyPlainSegments(dir, resolved) && hasOnlyPlainSegments(realDir, real) && isData(resolved) && isData(real) && !touchesOperatorOnlyName(dir, resolved) && !touchesOperatorOnlyName(realDir, real);
|
|
29883
29999
|
});
|
|
29884
30000
|
}
|
|
29885
30001
|
observe(command, result) {
|
|
@@ -29898,8 +30014,8 @@ class AutomaticReviewRun {
|
|
|
29898
30014
|
if (id === undefined || printed === undefined) {
|
|
29899
30015
|
return;
|
|
29900
30016
|
}
|
|
29901
|
-
const dir =
|
|
29902
|
-
const metaproject =
|
|
30017
|
+
const dir = path69.resolve(this.cwd, printed);
|
|
30018
|
+
const metaproject = path69.join(path69.resolve(this.cwd), ".metaproject") + path69.sep;
|
|
29903
30019
|
if (dir.startsWith(metaproject)) {
|
|
29904
30020
|
this.binding = { id, dir };
|
|
29905
30021
|
}
|
|
@@ -29944,13 +30060,13 @@ class AutomaticReviewRun {
|
|
|
29944
30060
|
}
|
|
29945
30061
|
summaryLine() {
|
|
29946
30062
|
const { manual, automatic } = this.disclosure();
|
|
29947
|
-
return `[automatic review] inputs: ${manual} manual, ${automatic} automatic${this.binding === undefined ? "" : ` (${
|
|
30063
|
+
return `[automatic review] inputs: ${manual} manual, ${automatic} automatic${this.binding === undefined ? "" : ` (${path69.relative(this.cwd, path69.join(this.binding.dir, AUTOMATIC_REVIEW_DISCLOSURE_FILE))})`}`;
|
|
29948
30064
|
}
|
|
29949
30065
|
async writeDisclosure() {
|
|
29950
30066
|
if (this.binding === undefined) {
|
|
29951
30067
|
return;
|
|
29952
30068
|
}
|
|
29953
|
-
const file =
|
|
30069
|
+
const file = path69.join(this.binding.dir, AUTOMATIC_REVIEW_DISCLOSURE_FILE);
|
|
29954
30070
|
await mkdir12(this.binding.dir, { recursive: true });
|
|
29955
30071
|
await writeFile7(file, `${JSON.stringify(this.disclosure(), null, 2)}
|
|
29956
30072
|
`, "utf8");
|
|
@@ -30011,27 +30127,27 @@ class AutomaticReviewRun {
|
|
|
30011
30127
|
if (this.binding !== undefined) {
|
|
30012
30128
|
return this.insidePackage(value);
|
|
30013
30129
|
}
|
|
30014
|
-
const resolved =
|
|
30015
|
-
return resolved.startsWith(reviewsRoot(
|
|
30130
|
+
const resolved = path69.resolve(this.cwd, value);
|
|
30131
|
+
return resolved.startsWith(reviewsRoot(path69.resolve(this.cwd)) + path69.sep);
|
|
30016
30132
|
}
|
|
30017
30133
|
insidePackage(value) {
|
|
30018
30134
|
const dir = this.binding?.dir;
|
|
30019
30135
|
if (dir === undefined) {
|
|
30020
30136
|
return false;
|
|
30021
30137
|
}
|
|
30022
|
-
const resolved =
|
|
30023
|
-
return resolved === dir || resolved.startsWith(`${dir}${
|
|
30138
|
+
const resolved = path69.resolve(this.cwd, value);
|
|
30139
|
+
return resolved === dir || resolved.startsWith(`${dir}${path69.sep}`);
|
|
30024
30140
|
}
|
|
30025
30141
|
insideCwd(value) {
|
|
30026
|
-
const resolved =
|
|
30027
|
-
const root =
|
|
30028
|
-
return resolved === root || resolved.startsWith(`${root}${
|
|
30142
|
+
const resolved = path69.resolve(this.cwd, value);
|
|
30143
|
+
const root = path69.resolve(this.cwd);
|
|
30144
|
+
return resolved === root || resolved.startsWith(`${root}${path69.sep}`);
|
|
30029
30145
|
}
|
|
30030
30146
|
namesReviewPackage(value) {
|
|
30031
30147
|
if (value === "" || value.startsWith("-"))
|
|
30032
30148
|
return false;
|
|
30033
|
-
const asPath =
|
|
30034
|
-
if (!/[\\/]/.test(value) && value !== "." && value !== ".." && !existsSync17(
|
|
30149
|
+
const asPath = path69.resolve(this.cwd, value);
|
|
30150
|
+
if (!/[\\/]/.test(value) && value !== "." && value !== ".." && !existsSync17(path69.join(asPath, "manifest.json")))
|
|
30035
30151
|
return true;
|
|
30036
30152
|
return this.insideCwd(value) && isReviewPackageDir(asPath, this.cwd);
|
|
30037
30153
|
}
|
|
@@ -30039,7 +30155,7 @@ class AutomaticReviewRun {
|
|
|
30039
30155
|
if (this.binding === undefined) {
|
|
30040
30156
|
return false;
|
|
30041
30157
|
}
|
|
30042
|
-
return ref === this.binding.id ||
|
|
30158
|
+
return ref === this.binding.id || path69.resolve(this.cwd, ref) === this.binding.dir;
|
|
30043
30159
|
}
|
|
30044
30160
|
}
|
|
30045
30161
|
|
|
@@ -31056,7 +31172,7 @@ function consolidateAnchors(removed) {
|
|
|
31056
31172
|
// src/harness/tool/output-spill.ts
|
|
31057
31173
|
import { createHash as createHash11 } from "crypto";
|
|
31058
31174
|
import { chmod as chmod4, mkdir as mkdir14, open as open5 } from "fs/promises";
|
|
31059
|
-
import
|
|
31175
|
+
import path72 from "path";
|
|
31060
31176
|
var TOOL_OUTPUT_SPILL_MAX_LINES = 2000;
|
|
31061
31177
|
var TOOL_OUTPUT_SPILL_MAX_BYTES = 50 * 1024;
|
|
31062
31178
|
var TOOL_OUTPUT_PREVIEW_CHARS = 16 * 1024;
|
|
@@ -31112,14 +31228,14 @@ var TOOL_OUTPUT_DIR_MODE = 448;
|
|
|
31112
31228
|
var TOOL_OUTPUT_FILE_MODE = 384;
|
|
31113
31229
|
var MAX_NAME_ATTEMPTS = 50;
|
|
31114
31230
|
async function writeUniqueOutputFile(sessionDir, toolCallId, text) {
|
|
31115
|
-
const dir =
|
|
31231
|
+
const dir = path72.join(sessionDir, TOOL_OUTPUT_DIRNAME);
|
|
31116
31232
|
try {
|
|
31117
31233
|
await mkdir14(dir, { recursive: true, mode: TOOL_OUTPUT_DIR_MODE });
|
|
31118
31234
|
await chmod4(dir, TOOL_OUTPUT_DIR_MODE);
|
|
31119
31235
|
const hash = createHash11("sha256").update(text).digest("hex").slice(0, 8);
|
|
31120
31236
|
const base = `${Date.now()}-${hash}-${safeFileStem(toolCallId)}`;
|
|
31121
31237
|
for (let attempt = 0;attempt < MAX_NAME_ATTEMPTS; attempt++) {
|
|
31122
|
-
const filePath =
|
|
31238
|
+
const filePath = path72.join(dir, `${base}${attempt === 0 ? "" : `-${attempt}`}.txt`);
|
|
31123
31239
|
let handle;
|
|
31124
31240
|
try {
|
|
31125
31241
|
handle = await open5(filePath, "wx", TOOL_OUTPUT_FILE_MODE);
|
|
@@ -31145,11 +31261,11 @@ async function writeToolOutputFile(sessionDir, toolCallId, text) {
|
|
|
31145
31261
|
return writeUniqueOutputFile(sessionDir, toolCallId, text);
|
|
31146
31262
|
}
|
|
31147
31263
|
function isInsideToolOutputDir(sessionDir, candidate) {
|
|
31148
|
-
if (!
|
|
31264
|
+
if (!path72.isAbsolute(candidate)) {
|
|
31149
31265
|
return false;
|
|
31150
31266
|
}
|
|
31151
|
-
const rel =
|
|
31152
|
-
return rel !== "" && rel !== ".." && !rel.startsWith(`..${
|
|
31267
|
+
const rel = path72.relative(path72.join(sessionDir, TOOL_OUTPUT_DIRNAME), path72.resolve(candidate));
|
|
31268
|
+
return rel !== "" && rel !== ".." && !rel.startsWith(`..${path72.sep}`) && !path72.isAbsolute(rel);
|
|
31153
31269
|
}
|
|
31154
31270
|
async function spillToolOutput(text, ctx) {
|
|
31155
31271
|
if (ctx.sessionDir === undefined || !exceedsSpillThreshold(text)) {
|
|
@@ -31468,15 +31584,15 @@ import {
|
|
|
31468
31584
|
existsSync as existsSync19,
|
|
31469
31585
|
mkdirSync as mkdirSync5,
|
|
31470
31586
|
readdirSync as readdirSync6,
|
|
31471
|
-
renameSync as
|
|
31587
|
+
renameSync as renameSync6,
|
|
31472
31588
|
writeFileSync as writeFileSync6
|
|
31473
31589
|
} from "fs";
|
|
31474
|
-
import
|
|
31590
|
+
import path74 from "path";
|
|
31475
31591
|
|
|
31476
31592
|
// src/session/paths.ts
|
|
31477
31593
|
import { existsSync as existsSync18 } from "fs";
|
|
31478
31594
|
import { homedir as homedir3 } from "os";
|
|
31479
|
-
import
|
|
31595
|
+
import path73 from "path";
|
|
31480
31596
|
function keryxDataDir(override) {
|
|
31481
31597
|
if (override !== undefined && override.length > 0) {
|
|
31482
31598
|
return override;
|
|
@@ -31488,22 +31604,22 @@ function keryxDataDir(override) {
|
|
|
31488
31604
|
const home = homedir3();
|
|
31489
31605
|
if (process.platform === "win32") {
|
|
31490
31606
|
const appData = process.env.APPDATA;
|
|
31491
|
-
const base = appData !== undefined && appData.length > 0 ? appData :
|
|
31492
|
-
return
|
|
31607
|
+
const base = appData !== undefined && appData.length > 0 ? appData : path73.join(home, "AppData", "Roaming");
|
|
31608
|
+
return path73.join(base, "keryx");
|
|
31493
31609
|
}
|
|
31494
31610
|
const xdg = process.env.XDG_DATA_HOME;
|
|
31495
|
-
const base = xdg !== undefined && xdg.length > 0 ? xdg :
|
|
31496
|
-
return
|
|
31611
|
+
const base = xdg !== undefined && xdg.length > 0 ? xdg : path73.join(home, ".local", "share");
|
|
31612
|
+
return path73.join(base, "keryx");
|
|
31497
31613
|
}
|
|
31498
31614
|
function resolveProjectRoot2(cwd) {
|
|
31499
|
-
const abs =
|
|
31615
|
+
const abs = path73.resolve(cwd);
|
|
31500
31616
|
let dir = abs;
|
|
31501
31617
|
for (;; ) {
|
|
31502
|
-
const gitPath =
|
|
31618
|
+
const gitPath = path73.join(dir, ".git");
|
|
31503
31619
|
if (existsSync18(gitPath)) {
|
|
31504
31620
|
return dir;
|
|
31505
31621
|
}
|
|
31506
|
-
const parent =
|
|
31622
|
+
const parent = path73.dirname(dir);
|
|
31507
31623
|
if (parent === dir) {
|
|
31508
31624
|
break;
|
|
31509
31625
|
}
|
|
@@ -31512,12 +31628,12 @@ function resolveProjectRoot2(cwd) {
|
|
|
31512
31628
|
return abs;
|
|
31513
31629
|
}
|
|
31514
31630
|
function projectKeyFromPath(projectPath) {
|
|
31515
|
-
const abs =
|
|
31631
|
+
const abs = path73.resolve(projectPath);
|
|
31516
31632
|
const encoded = encodeURIComponent(abs);
|
|
31517
31633
|
if (encoded.length <= 200) {
|
|
31518
31634
|
return encoded;
|
|
31519
31635
|
}
|
|
31520
|
-
const base =
|
|
31636
|
+
const base = path73.basename(abs).replace(/[^a-zA-Z0-9._-]+/g, "_").slice(0, 40);
|
|
31521
31637
|
let h = 0;
|
|
31522
31638
|
for (let i = 0;i < abs.length; i++) {
|
|
31523
31639
|
h = Math.imul(31, h) + abs.charCodeAt(i) | 0;
|
|
@@ -31527,10 +31643,10 @@ function projectKeyFromPath(projectPath) {
|
|
|
31527
31643
|
}
|
|
31528
31644
|
function projectSessionsDir(projectPath, dataDir) {
|
|
31529
31645
|
const key = projectKeyFromPath(resolveProjectRoot2(projectPath));
|
|
31530
|
-
return
|
|
31646
|
+
return path73.join(keryxDataDir(dataDir), "sessions", key);
|
|
31531
31647
|
}
|
|
31532
31648
|
function sessionDir(projectPath, sessionId, dataDir) {
|
|
31533
|
-
return
|
|
31649
|
+
return path73.join(projectSessionsDir(projectPath, dataDir), sessionId);
|
|
31534
31650
|
}
|
|
31535
31651
|
|
|
31536
31652
|
// src/session/store.ts
|
|
@@ -31626,7 +31742,7 @@ function parseRemote(value) {
|
|
|
31626
31742
|
function readSummaryFile(file) {
|
|
31627
31743
|
let pending;
|
|
31628
31744
|
try {
|
|
31629
|
-
pending = readPendingHistory(
|
|
31745
|
+
pending = readPendingHistory(path74.dirname(file));
|
|
31630
31746
|
} catch {
|
|
31631
31747
|
pending = undefined;
|
|
31632
31748
|
}
|
|
@@ -31678,11 +31794,11 @@ class TranscriptUnreadableError extends Error {
|
|
|
31678
31794
|
}
|
|
31679
31795
|
}
|
|
31680
31796
|
function readJsonl(file) {
|
|
31681
|
-
const pending = readPendingHistory(
|
|
31797
|
+
const pending = readPendingHistory(path74.dirname(file));
|
|
31682
31798
|
if (pending === undefined && !existsSync19(file)) {
|
|
31683
31799
|
return [];
|
|
31684
31800
|
}
|
|
31685
|
-
const read = pending !== undefined ? { ok: true, text: pending.files[
|
|
31801
|
+
const read = pending !== undefined ? { ok: true, text: pending.files[path74.basename(file)] } : readTranscriptFile(file);
|
|
31686
31802
|
if (!read.ok) {
|
|
31687
31803
|
throw new TranscriptUnreadableError(file, read.reason);
|
|
31688
31804
|
}
|
|
@@ -31733,11 +31849,11 @@ function listSessions(cwd, dataDir) {
|
|
|
31733
31849
|
if (name.startsWith(".")) {
|
|
31734
31850
|
continue;
|
|
31735
31851
|
}
|
|
31736
|
-
const summary = readSummaryFile(
|
|
31852
|
+
const summary = readSummaryFile(path74.join(root, name, "summary.json"));
|
|
31737
31853
|
if (summary === undefined) {
|
|
31738
31854
|
continue;
|
|
31739
31855
|
}
|
|
31740
|
-
if (
|
|
31856
|
+
if (path74.resolve(summary.projectPath) !== path74.resolve(projectPath)) {
|
|
31741
31857
|
continue;
|
|
31742
31858
|
}
|
|
31743
31859
|
out.push(summary);
|
|
@@ -31770,15 +31886,15 @@ async function readSessionSlate(cwd, sessionId, dataDir) {
|
|
|
31770
31886
|
}
|
|
31771
31887
|
function loadContext(cwd, sessionId, dataDir) {
|
|
31772
31888
|
const dir = sessionDir(resolveProjectRoot2(cwd), sessionId, dataDir);
|
|
31773
|
-
const contextPath =
|
|
31889
|
+
const contextPath = path74.join(dir, "context.jsonl");
|
|
31774
31890
|
if (readPendingHistory(dir) !== undefined || existsSync19(contextPath)) {
|
|
31775
31891
|
return readJsonl(contextPath);
|
|
31776
31892
|
}
|
|
31777
|
-
return readJsonl(
|
|
31893
|
+
return readJsonl(path74.join(dir, "transcript.jsonl"));
|
|
31778
31894
|
}
|
|
31779
31895
|
function loadArchive(cwd, sessionId, dataDir, onDegraded) {
|
|
31780
31896
|
const dir = sessionDir(resolveProjectRoot2(cwd), sessionId, dataDir);
|
|
31781
|
-
const archivePath =
|
|
31897
|
+
const archivePath = path74.join(dir, "archive.jsonl");
|
|
31782
31898
|
if (readPendingHistory(dir) !== undefined || existsSync19(archivePath)) {
|
|
31783
31899
|
try {
|
|
31784
31900
|
const archive = readJsonl(archivePath);
|
|
@@ -32872,13 +32988,13 @@ async function executeWaves(tasks, waves, deps) {
|
|
|
32872
32988
|
init_fs();
|
|
32873
32989
|
init_slate();
|
|
32874
32990
|
import { mkdir as mkdir15, readFile as readFile33 } from "fs/promises";
|
|
32875
|
-
import
|
|
32991
|
+
import path75 from "path";
|
|
32876
32992
|
var listeners = new Set;
|
|
32877
32993
|
function clonePlan(plan) {
|
|
32878
32994
|
return { revision: plan.revision, items: plan.items.map((item) => ({ ...item })) };
|
|
32879
32995
|
}
|
|
32880
32996
|
function executionPlanPath(dir) {
|
|
32881
|
-
return
|
|
32997
|
+
return path75.join(dir, "plan.json");
|
|
32882
32998
|
}
|
|
32883
32999
|
async function readPlanFile(dir) {
|
|
32884
33000
|
let raw;
|
|
@@ -33015,7 +33131,7 @@ init_fs();
|
|
|
33015
33131
|
init_slate();
|
|
33016
33132
|
import { createHash as createHash23, randomUUID as randomUUID11 } from "crypto";
|
|
33017
33133
|
import { mkdir as mkdir21 } from "fs/promises";
|
|
33018
|
-
import
|
|
33134
|
+
import path89 from "path";
|
|
33019
33135
|
|
|
33020
33136
|
// src/sac/trusted-wrap-up.ts
|
|
33021
33137
|
import { createHash as createHash13, randomUUID as randomUUID6 } from "crypto";
|
|
@@ -33059,12 +33175,12 @@ function digest(value) {
|
|
|
33059
33175
|
init_fs();
|
|
33060
33176
|
import { createHash as createHash22, randomUUID as randomUUID9 } from "crypto";
|
|
33061
33177
|
import { appendFile as appendFile4, mkdir as mkdir20, readdir as readdir21, readFile as readFile44 } from "fs/promises";
|
|
33062
|
-
import
|
|
33178
|
+
import path88 from "path";
|
|
33063
33179
|
|
|
33064
33180
|
// src/sac/index.ts
|
|
33065
33181
|
import { access as access2, readFile as readFile34, realpath as realpath10 } from "fs/promises";
|
|
33066
33182
|
import { createHash as createHash14 } from "crypto";
|
|
33067
|
-
import
|
|
33183
|
+
import path76 from "path";
|
|
33068
33184
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
33069
33185
|
|
|
33070
33186
|
// src/sac/workspace-reference.ts
|
|
@@ -33087,21 +33203,21 @@ var normativeSchemaFiles = {
|
|
|
33087
33203
|
"review-decision": "review-decision.schema.json"
|
|
33088
33204
|
};
|
|
33089
33205
|
var normativeSchemas = new Map;
|
|
33090
|
-
var NORMATIVE_SCHEMA_DIR =
|
|
33206
|
+
var NORMATIVE_SCHEMA_DIR = path76.join("docs", "requirements", "shared-agent-context", "schemas");
|
|
33091
33207
|
async function resolveSacNormativeSchemaPath(fileName, searchFrom = [fileURLToPath3(new URL(".", import.meta.url)), process.cwd()]) {
|
|
33092
33208
|
const seen = new Set;
|
|
33093
33209
|
for (const start of searchFrom) {
|
|
33094
|
-
let dir =
|
|
33210
|
+
let dir = path76.resolve(start);
|
|
33095
33211
|
for (let i = 0;i < 10; i++) {
|
|
33096
33212
|
if (seen.has(dir))
|
|
33097
33213
|
break;
|
|
33098
33214
|
seen.add(dir);
|
|
33099
|
-
const candidate =
|
|
33215
|
+
const candidate = path76.join(dir, NORMATIVE_SCHEMA_DIR, fileName);
|
|
33100
33216
|
try {
|
|
33101
33217
|
await access2(candidate);
|
|
33102
33218
|
return candidate;
|
|
33103
33219
|
} catch {}
|
|
33104
|
-
const parent =
|
|
33220
|
+
const parent = path76.dirname(dir);
|
|
33105
33221
|
if (parent === dir)
|
|
33106
33222
|
break;
|
|
33107
33223
|
dir = parent;
|
|
@@ -33763,12 +33879,12 @@ class SacReferenceError extends Error {
|
|
|
33763
33879
|
code = "unsafe_workspace_reference";
|
|
33764
33880
|
}
|
|
33765
33881
|
async function resolveWorkspaceReference(input) {
|
|
33766
|
-
if (!workspacePathPattern.test(input.uri) ||
|
|
33882
|
+
if (!workspacePathPattern.test(input.uri) || path76.isAbsolute(input.uri) || /^[a-z][a-z0-9+.-]*:/i.test(input.uri) || input.uri.includes("\\"))
|
|
33767
33883
|
throw new SacReferenceError("unsafe workspace reference");
|
|
33768
|
-
const lexicalRoot =
|
|
33884
|
+
const lexicalRoot = path76.resolve(input.workspaceRoot);
|
|
33769
33885
|
const root = await realpath10(lexicalRoot);
|
|
33770
|
-
const candidate =
|
|
33771
|
-
if (candidate !== lexicalRoot && !candidate.startsWith(`${lexicalRoot}${
|
|
33886
|
+
const candidate = path76.resolve(lexicalRoot, input.uri.slice(2));
|
|
33887
|
+
if (candidate !== lexicalRoot && !candidate.startsWith(`${lexicalRoot}${path76.sep}`))
|
|
33772
33888
|
throw new SacReferenceError("workspace reference escapes root");
|
|
33773
33889
|
let resolved;
|
|
33774
33890
|
try {
|
|
@@ -33776,7 +33892,7 @@ async function resolveWorkspaceReference(input) {
|
|
|
33776
33892
|
} catch {
|
|
33777
33893
|
throw new SacReferenceError("workspace reference is not resolvable");
|
|
33778
33894
|
}
|
|
33779
|
-
if (resolved !== root && !resolved.startsWith(`${root}${
|
|
33895
|
+
if (resolved !== root && !resolved.startsWith(`${root}${path76.sep}`))
|
|
33780
33896
|
throw new SacReferenceError("workspace reference escapes root after realpath");
|
|
33781
33897
|
return candidate;
|
|
33782
33898
|
}
|
|
@@ -33832,16 +33948,16 @@ async function evaluateStrictSacGuard(input) {
|
|
|
33832
33948
|
init_fs();
|
|
33833
33949
|
import { mkdir as mkdir16, readdir as readdir19, readFile as readFile35 } from "fs/promises";
|
|
33834
33950
|
import { createHash as createHash15, randomUUID as randomUUID7 } from "crypto";
|
|
33835
|
-
import
|
|
33951
|
+
import path78 from "path";
|
|
33836
33952
|
|
|
33837
33953
|
// src/sac/secure-resource-read.ts
|
|
33838
33954
|
init_contained_read();
|
|
33839
33955
|
init_descriptor_read();
|
|
33840
|
-
import
|
|
33956
|
+
import path77 from "path";
|
|
33841
33957
|
function readWorkspaceFileNoFollow(workspaceRoot, absolutePath) {
|
|
33842
|
-
const relativePath =
|
|
33843
|
-
const components = relativePath.split(
|
|
33844
|
-
if (!relativePath ||
|
|
33958
|
+
const relativePath = path77.relative(workspaceRoot, absolutePath);
|
|
33959
|
+
const components = relativePath.split(path77.sep);
|
|
33960
|
+
if (!relativePath || path77.isAbsolute(relativePath) || components.some((component) => !component || component === "." || component === "..")) {
|
|
33845
33961
|
throw new Error("safe source path is not workspace-relative");
|
|
33846
33962
|
}
|
|
33847
33963
|
return readDescriptorChain(workspaceRoot, absolutePath, {
|
|
@@ -33868,8 +33984,8 @@ class WorkspaceService {
|
|
|
33868
33984
|
now;
|
|
33869
33985
|
constructor(options) {
|
|
33870
33986
|
this.options = options;
|
|
33871
|
-
this.root =
|
|
33872
|
-
this.storageRoot =
|
|
33987
|
+
this.root = path78.resolve(options.workspaceRoot);
|
|
33988
|
+
this.storageRoot = path78.resolve(options.storageRoot ?? path78.join(this.root, ".metaproject", "workspaces"));
|
|
33873
33989
|
this.now = options.now ?? (() => new Date);
|
|
33874
33990
|
}
|
|
33875
33991
|
async create(input) {
|
|
@@ -34195,13 +34311,13 @@ class WorkspaceService {
|
|
|
34195
34311
|
return parsed;
|
|
34196
34312
|
}
|
|
34197
34313
|
workspaceDir(id) {
|
|
34198
|
-
return
|
|
34314
|
+
return path78.join(this.storageRoot, id);
|
|
34199
34315
|
}
|
|
34200
34316
|
manifestPath(id) {
|
|
34201
|
-
return
|
|
34317
|
+
return path78.join(this.workspaceDir(id), "workspace.json");
|
|
34202
34318
|
}
|
|
34203
34319
|
lockPath(id) {
|
|
34204
|
-
return
|
|
34320
|
+
return path78.join(this.storageRoot, `.${id}.lock`);
|
|
34205
34321
|
}
|
|
34206
34322
|
timestamp() {
|
|
34207
34323
|
return this.now().toISOString();
|
|
@@ -34256,7 +34372,7 @@ function bindingHash(owner, intent) {
|
|
|
34256
34372
|
// src/sac/session-wrap-up.ts
|
|
34257
34373
|
import { createHash as createHash17 } from "crypto";
|
|
34258
34374
|
import { mkdir as mkdir17, writeFile as writeFile8 } from "fs/promises";
|
|
34259
|
-
import
|
|
34375
|
+
import path79 from "path";
|
|
34260
34376
|
init_wrap_up_evidence();
|
|
34261
34377
|
var WRAP_UP_TTL_MS = 60 * 60 * 1000;
|
|
34262
34378
|
|
|
@@ -34272,7 +34388,7 @@ function sessionEvidenceRef(workspaceId, sessionId) {
|
|
|
34272
34388
|
}
|
|
34273
34389
|
async function resolveSessionWrapUp(input) {
|
|
34274
34390
|
const now = input.now ?? (() => new Date);
|
|
34275
|
-
const sessionId =
|
|
34391
|
+
const sessionId = path79.posix.basename(input.sourceRef, ".md");
|
|
34276
34392
|
const summary = findSession(input.cwd, sessionId);
|
|
34277
34393
|
if (summary === undefined || input.sourceRef !== sessionEvidenceRef(input.workspaceId, summary.id)) {
|
|
34278
34394
|
throw new SessionWrapUpError("session_not_found", `no session matching "${input.sourceRef}" in this project \u2014 use \`keryx sessions list\``);
|
|
@@ -34289,7 +34405,7 @@ async function resolveSessionWrapUp(input) {
|
|
|
34289
34405
|
throw new SessionWrapUpError("session_unreadable", `session "${summary.id}" could not be read: ${cause.message}`);
|
|
34290
34406
|
}
|
|
34291
34407
|
const relPath = sessionEvidenceRef(input.workspaceId, summary.id).slice(2);
|
|
34292
|
-
const evidenceDir =
|
|
34408
|
+
const evidenceDir = path79.dirname(relPath);
|
|
34293
34409
|
const slate = await readSessionSlate(input.cwd, summary.id);
|
|
34294
34410
|
const diff = await gitDiff(input.cwd);
|
|
34295
34411
|
const diffBody = diff.kind === "measured" ? diff.text : unmeasurableDiffBody(diff.detail);
|
|
@@ -34311,23 +34427,23 @@ async function resolveSessionWrapUp(input) {
|
|
|
34311
34427
|
""
|
|
34312
34428
|
].join(`
|
|
34313
34429
|
`);
|
|
34314
|
-
const wrapUpRelPath =
|
|
34315
|
-
const diffRelPath =
|
|
34316
|
-
const noticeRelPath =
|
|
34430
|
+
const wrapUpRelPath = path79.join(evidenceDir, `${summary.id}.wrap-up.md`);
|
|
34431
|
+
const diffRelPath = path79.join(evidenceDir, `${summary.id}.diff.txt`);
|
|
34432
|
+
const noticeRelPath = path79.join(evidenceDir, `${summary.id}.redaction.md`);
|
|
34317
34433
|
const floor = await applyEvidenceRedactionFloor(input.cwd, [
|
|
34318
|
-
{ name:
|
|
34319
|
-
{ name:
|
|
34320
|
-
{ name:
|
|
34434
|
+
{ name: path79.basename(relPath), content: markdown, path: relPath, source: "generated" },
|
|
34435
|
+
{ name: path79.basename(wrapUpRelPath), content: wrapUpMarkdown, path: wrapUpRelPath, source: "generated" },
|
|
34436
|
+
{ name: path79.basename(diffRelPath), content: diffBody, path: diffRelPath, source: "tool-output" }
|
|
34321
34437
|
]);
|
|
34322
34438
|
if (!floor.ok)
|
|
34323
34439
|
throw new SessionWrapUpError("security_denied", floor.reason);
|
|
34324
34440
|
const [safeSession, safeWrapUp, safeDiff] = floor.bodies;
|
|
34325
|
-
await mkdir17(
|
|
34326
|
-
await writeFile8(
|
|
34327
|
-
await writeFile8(
|
|
34328
|
-
await writeFile8(
|
|
34441
|
+
await mkdir17(path79.join(input.cwd, evidenceDir), { recursive: true });
|
|
34442
|
+
await writeFile8(path79.join(input.cwd, relPath), safeSession.content, "utf8");
|
|
34443
|
+
await writeFile8(path79.join(input.cwd, wrapUpRelPath), safeWrapUp.content, "utf8");
|
|
34444
|
+
await writeFile8(path79.join(input.cwd, diffRelPath), safeDiff.content, "utf8");
|
|
34329
34445
|
if (floor.notice !== undefined)
|
|
34330
|
-
await writeFile8(
|
|
34446
|
+
await writeFile8(path79.join(input.cwd, noticeRelPath), floor.notice, "utf8");
|
|
34331
34447
|
const observedAt = now().toISOString();
|
|
34332
34448
|
const evidence = [
|
|
34333
34449
|
{ kind: "wrap-up", uri: `./${wrapUpRelPath}`, revision: createHash17("sha256").update(safeWrapUp.content).digest("hex"), observedAt },
|
|
@@ -34350,13 +34466,13 @@ async function resolveSessionWrapUp(input) {
|
|
|
34350
34466
|
init_fs();
|
|
34351
34467
|
import { createHash as createHash18, randomBytes as randomBytes3 } from "crypto";
|
|
34352
34468
|
import { readFile as readFile36 } from "fs/promises";
|
|
34353
|
-
import
|
|
34469
|
+
import path80 from "path";
|
|
34354
34470
|
var CONFIRM_TOKEN_TTL_MS = 2 * 60000;
|
|
34355
34471
|
function confirmTokenPath(cwd, workspaceId, proposalId) {
|
|
34356
|
-
return
|
|
34472
|
+
return path80.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.confirm-token.json`);
|
|
34357
34473
|
}
|
|
34358
34474
|
function confirmReceiptPath(cwd, workspaceId, proposalId, idempotencyKey) {
|
|
34359
|
-
return
|
|
34475
|
+
return path80.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${sha256(idempotencyKey)}.confirm-receipt.json`);
|
|
34360
34476
|
}
|
|
34361
34477
|
function sha256(text) {
|
|
34362
34478
|
return createHash18("sha256").update(text).digest("hex");
|
|
@@ -34397,21 +34513,21 @@ init_store();
|
|
|
34397
34513
|
init_config4();
|
|
34398
34514
|
import { readFile as readFile38, readdir as readdir20 } from "fs/promises";
|
|
34399
34515
|
import { randomUUID as randomUUID8 } from "crypto";
|
|
34400
|
-
import
|
|
34516
|
+
import path83 from "path";
|
|
34401
34517
|
|
|
34402
34518
|
// src/sac/proposal-evidence.ts
|
|
34403
34519
|
init_fs();
|
|
34404
34520
|
import { createHash as createHash19 } from "crypto";
|
|
34405
34521
|
import { readFile as readFile37, rm as rm6 } from "fs/promises";
|
|
34406
|
-
import
|
|
34522
|
+
import path82 from "path";
|
|
34407
34523
|
function proposalPath(cwd, workspaceId, proposalId) {
|
|
34408
|
-
return
|
|
34524
|
+
return path82.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.json`);
|
|
34409
34525
|
}
|
|
34410
34526
|
function ownerReceiptPath(cwd, owner, workspaceId, idempotencyKey) {
|
|
34411
|
-
return
|
|
34527
|
+
return path82.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-write-receipts`, `${idempotencyKey}.json`);
|
|
34412
34528
|
}
|
|
34413
34529
|
function proposalNotePath(cwd, workspaceId, proposalId) {
|
|
34414
|
-
return
|
|
34530
|
+
return path82.join(cwd, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.note.txt`);
|
|
34415
34531
|
}
|
|
34416
34532
|
async function readVerifiedProposalEvidence(cwd, workspaceId, proposalId) {
|
|
34417
34533
|
let proposal;
|
|
@@ -34425,7 +34541,7 @@ async function readVerifiedProposalEvidence(cwd, workspaceId, proposalId) {
|
|
|
34425
34541
|
return { ok: false, code: "no_evidence_to_write" };
|
|
34426
34542
|
let content;
|
|
34427
34543
|
try {
|
|
34428
|
-
content = await readFile37(
|
|
34544
|
+
content = await readFile37(path82.join(cwd, evidence.uri), "utf8");
|
|
34429
34545
|
} catch {
|
|
34430
34546
|
return { ok: false, code: "evidence_file_unreadable" };
|
|
34431
34547
|
}
|
|
@@ -34455,22 +34571,22 @@ function targetRelPath(targetRef) {
|
|
|
34455
34571
|
return targetRef.replace(/^\.\//, "");
|
|
34456
34572
|
}
|
|
34457
34573
|
function targetAbsolutePath(cwd, targetRef) {
|
|
34458
|
-
return
|
|
34574
|
+
return path82.join(cwd, ".metaproject", targetRelPath(targetRef));
|
|
34459
34575
|
}
|
|
34460
34576
|
function targetKey(targetRef) {
|
|
34461
34577
|
return digestOf(targetRelPath(targetRef)).slice(0, 32);
|
|
34462
34578
|
}
|
|
34463
34579
|
function ownerTargetVersionPath(cwd, owner, workspaceId, targetRef) {
|
|
34464
|
-
return
|
|
34580
|
+
return path82.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-target-versions`, `${targetKey(targetRef)}.json`);
|
|
34465
34581
|
}
|
|
34466
34582
|
function ownerTargetLockPath(cwd, owner, targetRef) {
|
|
34467
|
-
return
|
|
34583
|
+
return path82.join(cwd, ".metaproject", "data", "sac", "target-locks", owner, `${targetKey(targetRef)}.lock`);
|
|
34468
34584
|
}
|
|
34469
34585
|
function ownerStagingDir(cwd, owner, workspaceId, idempotencyKey) {
|
|
34470
|
-
return
|
|
34586
|
+
return path82.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-write-staging`, digestOf(idempotencyKey).slice(0, 32));
|
|
34471
34587
|
}
|
|
34472
34588
|
function ownerConflictDir(cwd, owner, workspaceId, idempotencyKey) {
|
|
34473
|
-
return
|
|
34589
|
+
return path82.join(cwd, ".metaproject", "workspaces", workspaceId, `${owner}-write-conflicts`, digestOf(idempotencyKey).slice(0, 32));
|
|
34474
34590
|
}
|
|
34475
34591
|
async function readJson7(file) {
|
|
34476
34592
|
try {
|
|
@@ -34541,7 +34657,7 @@ async function applyGuardedTargetWrite(input) {
|
|
|
34541
34657
|
staged: input.staged,
|
|
34542
34658
|
stagedAt: receipt.completedAt
|
|
34543
34659
|
};
|
|
34544
|
-
await writeFileAtomic(
|
|
34660
|
+
await writeFileAtomic(path82.join(ownerStagingDir(cwd, owner, intent.workspaceId, intent.idempotencyKey), "plan.json"), `${JSON.stringify(staged, null, 2)}
|
|
34545
34661
|
`);
|
|
34546
34662
|
const applied = await input.apply(input.staged);
|
|
34547
34663
|
if (!applied.ok) {
|
|
@@ -34567,15 +34683,15 @@ async function recoverStagedOwnerWrite(input) {
|
|
|
34567
34683
|
});
|
|
34568
34684
|
}
|
|
34569
34685
|
async function readStagedOwnerWrite(cwd, owner, workspaceId, idempotencyKey) {
|
|
34570
|
-
return readJson7(
|
|
34686
|
+
return readJson7(path82.join(ownerStagingDir(cwd, owner, workspaceId, idempotencyKey), "plan.json"));
|
|
34571
34687
|
}
|
|
34572
34688
|
async function recordConflict(input) {
|
|
34573
34689
|
const base = { targetRef: input.targetRef, expectedVersion: input.expectedVersion, currentVersion: input.currentVersion };
|
|
34574
34690
|
if (input.proposedContent === undefined)
|
|
34575
34691
|
return base;
|
|
34576
34692
|
const dir = ownerConflictDir(input.cwd, input.owner, input.intent.workspaceId, input.intent.idempotencyKey);
|
|
34577
|
-
await writeFileAtomic(
|
|
34578
|
-
const diffRef = `./workspaces/${input.intent.workspaceId}/${input.owner}-write-conflicts/${
|
|
34693
|
+
await writeFileAtomic(path82.join(dir, "proposed"), input.proposedContent);
|
|
34694
|
+
const diffRef = `./workspaces/${input.intent.workspaceId}/${input.owner}-write-conflicts/${path82.basename(dir)}/proposed`;
|
|
34579
34695
|
return { ...base, diffRef };
|
|
34580
34696
|
}
|
|
34581
34697
|
|
|
@@ -34625,7 +34741,7 @@ async function resolveWorkspaceModule(cwd, workspaceId) {
|
|
|
34625
34741
|
}
|
|
34626
34742
|
}
|
|
34627
34743
|
async function collectWikiDecisionEntries(cwd) {
|
|
34628
|
-
const dir =
|
|
34744
|
+
const dir = path83.join(cwd, ".metaproject", "wiki", "decisions");
|
|
34629
34745
|
let files;
|
|
34630
34746
|
try {
|
|
34631
34747
|
files = (await readdir20(dir)).filter((name) => name.endsWith(".md"));
|
|
@@ -34634,12 +34750,12 @@ async function collectWikiDecisionEntries(cwd) {
|
|
|
34634
34750
|
}
|
|
34635
34751
|
const entries = [];
|
|
34636
34752
|
for (const file of files) {
|
|
34637
|
-
const absolutePath =
|
|
34753
|
+
const absolutePath = path83.join(dir, file);
|
|
34638
34754
|
try {
|
|
34639
34755
|
const content = await readFile38(absolutePath, "utf8");
|
|
34640
34756
|
entries.push({
|
|
34641
34757
|
absolutePath,
|
|
34642
|
-
relativePath:
|
|
34758
|
+
relativePath: path83.posix.join("decisions", file),
|
|
34643
34759
|
type: extractHeaderField(content, "Type") ?? "decision",
|
|
34644
34760
|
title: extractTitle(content),
|
|
34645
34761
|
version: extractHeaderField(content, "Version") ?? null,
|
|
@@ -34861,7 +34977,7 @@ function createRealMemoryOwnerWriter(cwd, opts) {
|
|
|
34861
34977
|
init_service4();
|
|
34862
34978
|
init_guard2();
|
|
34863
34979
|
import { readFile as readFile42 } from "fs/promises";
|
|
34864
|
-
import
|
|
34980
|
+
import path87 from "path";
|
|
34865
34981
|
function renderWrapUpDecisionPage(input) {
|
|
34866
34982
|
const note = input.note?.trim();
|
|
34867
34983
|
return `# ${input.title}
|
|
@@ -34902,7 +35018,7 @@ export is the source of truth for what actually happened.
|
|
|
34902
35018
|
`;
|
|
34903
35019
|
}
|
|
34904
35020
|
function wikiPageRelativePath(proposalId) {
|
|
34905
|
-
return
|
|
35021
|
+
return path87.posix.join("decisions", `sac-${proposalId}.md`);
|
|
34906
35022
|
}
|
|
34907
35023
|
function createRealWikiOwnerWriter(cwd, opts) {
|
|
34908
35024
|
const now = opts?.now ?? (() => new Date);
|
|
@@ -34910,7 +35026,7 @@ function createRealWikiOwnerWriter(cwd, opts) {
|
|
|
34910
35026
|
const relativePath = staged.relativePath;
|
|
34911
35027
|
const content = staged.content;
|
|
34912
35028
|
const history = await openWikiWriteContext(cwd, "sac proposal accept");
|
|
34913
|
-
await writeWikiPage(history,
|
|
35029
|
+
await writeWikiPage(history, path87.join(cwd, ".metaproject", "wiki", relativePath), content);
|
|
34914
35030
|
return { ok: true };
|
|
34915
35031
|
};
|
|
34916
35032
|
return {
|
|
@@ -35059,7 +35175,7 @@ class ProposalLifecycleService {
|
|
|
35059
35175
|
now;
|
|
35060
35176
|
constructor(options) {
|
|
35061
35177
|
this.options = options;
|
|
35062
|
-
this.root =
|
|
35178
|
+
this.root = path88.resolve(options.workspaceRoot);
|
|
35063
35179
|
this.now = options.now ?? (() => new Date);
|
|
35064
35180
|
}
|
|
35065
35181
|
async create(input) {
|
|
@@ -35079,7 +35195,7 @@ class ProposalLifecycleService {
|
|
|
35079
35195
|
if (manifest.status === "archived")
|
|
35080
35196
|
throw new ProposalLifecycleError("guard_denied", "workspace is archived");
|
|
35081
35197
|
const file = this.proposalPath(workspaceId, proposal.id);
|
|
35082
|
-
await mkdir20(
|
|
35198
|
+
await mkdir20(path88.dirname(file), { recursive: true, mode: 448 });
|
|
35083
35199
|
return withFileLock2(`${file}.lock`, async () => {
|
|
35084
35200
|
const consume = this.options.wrapUpAuthority.consume(input.wrapUp, { actor, workspaceId });
|
|
35085
35201
|
if (consume !== "ok")
|
|
@@ -35107,7 +35223,7 @@ class ProposalLifecycleService {
|
|
|
35107
35223
|
return this.options.workspaces.withAuthorizedActor({ actorContext: actor, workspaceId: input.workspaceId, action: "review", execute: async (manifest) => {
|
|
35108
35224
|
const proposal = await this.loadProposal(input.workspaceId, input.proposalId);
|
|
35109
35225
|
const ledger = this.ledgerPath(input.workspaceId);
|
|
35110
|
-
await mkdir20(
|
|
35226
|
+
await mkdir20(path88.dirname(ledger), { recursive: true, mode: 448 });
|
|
35111
35227
|
return withFileLock2(`${ledger}.lock`, async () => {
|
|
35112
35228
|
const records = (await this.records(ledger)).filter((record) => record.proposalId === proposal.id);
|
|
35113
35229
|
const events = records.filter((record) => record.recordType === "proposal-transition");
|
|
@@ -35149,7 +35265,7 @@ class ProposalLifecycleService {
|
|
|
35149
35265
|
} });
|
|
35150
35266
|
}
|
|
35151
35267
|
async listProposedProposals(workspaceId) {
|
|
35152
|
-
const proposalsDir =
|
|
35268
|
+
const proposalsDir = path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals");
|
|
35153
35269
|
let entries;
|
|
35154
35270
|
try {
|
|
35155
35271
|
entries = (await readdir21(proposalsDir)).filter((name) => name.endsWith(".json"));
|
|
@@ -35161,7 +35277,7 @@ class ProposalLifecycleService {
|
|
|
35161
35277
|
const proposals = [];
|
|
35162
35278
|
for (const entry of entries) {
|
|
35163
35279
|
try {
|
|
35164
|
-
const parsed = JSON.parse(await readFile44(
|
|
35280
|
+
const parsed = JSON.parse(await readFile44(path88.join(proposalsDir, entry), "utf8"));
|
|
35165
35281
|
if (parsed.recordType === "proposal-created")
|
|
35166
35282
|
proposals.push(parsed);
|
|
35167
35283
|
} catch {}
|
|
@@ -35427,31 +35543,31 @@ class ProposalLifecycleService {
|
|
|
35427
35543
|
}
|
|
35428
35544
|
}
|
|
35429
35545
|
proposalPath(workspaceId, proposalId) {
|
|
35430
|
-
return
|
|
35546
|
+
return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.json`);
|
|
35431
35547
|
}
|
|
35432
35548
|
decisionRef(proposalId, key) {
|
|
35433
35549
|
return `./proposals/${proposalId}.${hash2(key)}.decision.json`;
|
|
35434
35550
|
}
|
|
35435
35551
|
decisionPath(workspaceId, proposalId, key) {
|
|
35436
|
-
return
|
|
35552
|
+
return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.decision.json`);
|
|
35437
35553
|
}
|
|
35438
35554
|
approvalRef(proposalId, key) {
|
|
35439
35555
|
return `./proposals/${proposalId}.${hash2(key)}.approval.json`;
|
|
35440
35556
|
}
|
|
35441
35557
|
approvalPath(workspaceId, proposalId, key) {
|
|
35442
|
-
return
|
|
35558
|
+
return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.approval.json`);
|
|
35443
35559
|
}
|
|
35444
35560
|
writeResultPath(workspaceId, proposalId, key) {
|
|
35445
|
-
return
|
|
35561
|
+
return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.write-result.json`);
|
|
35446
35562
|
}
|
|
35447
35563
|
intentRef(proposalId, key) {
|
|
35448
35564
|
return `./proposals/${proposalId}.${hash2(key)}.write-intent.json`;
|
|
35449
35565
|
}
|
|
35450
35566
|
intentPath(workspaceId, proposalId, key) {
|
|
35451
|
-
return
|
|
35567
|
+
return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.write-intent.json`);
|
|
35452
35568
|
}
|
|
35453
35569
|
attemptPath(workspaceId, proposalId, key) {
|
|
35454
|
-
return
|
|
35570
|
+
return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "proposals", `${proposalId}.${hash2(key)}.owner-write-attempt.json`);
|
|
35455
35571
|
}
|
|
35456
35572
|
async loadWriteResult(workspaceId, proposalId, key) {
|
|
35457
35573
|
try {
|
|
@@ -35478,7 +35594,7 @@ class ProposalLifecycleService {
|
|
|
35478
35594
|
}
|
|
35479
35595
|
}
|
|
35480
35596
|
ledgerPath(workspaceId) {
|
|
35481
|
-
return
|
|
35597
|
+
return path88.join(this.root, ".metaproject", "workspaces", workspaceId, "activity.jsonl");
|
|
35482
35598
|
}
|
|
35483
35599
|
timestamp() {
|
|
35484
35600
|
return this.now().toISOString();
|
|
@@ -35707,11 +35823,11 @@ async function resolveMachineWrapUp(input) {
|
|
|
35707
35823
|
`;
|
|
35708
35824
|
const seedsJson = `${JSON.stringify(seedsForKind.map((seed) => ({ text: seed.text, source: describeSource(seed.source) })), null, 2)}
|
|
35709
35825
|
`;
|
|
35710
|
-
const evidenceRelBase =
|
|
35826
|
+
const evidenceRelBase = path89.posix.join(".metaproject", "workspaces", input.workspaceId, "machine-evidence");
|
|
35711
35827
|
const floor = await applyEvidenceRedactionFloor(input.cwd, [
|
|
35712
|
-
{ name: `${input.kind}.diff.txt`, content: diffBody, path:
|
|
35713
|
-
{ name: `${input.kind}.flow.json`, content: flowSnapshotJson, path:
|
|
35714
|
-
{ name: `${input.kind}.seeds.json`, content: seedsJson, path:
|
|
35828
|
+
{ name: `${input.kind}.diff.txt`, content: diffBody, path: path89.posix.join(evidenceRelBase, `${input.kind}.diff.txt`), source: "tool-output" },
|
|
35829
|
+
{ name: `${input.kind}.flow.json`, content: flowSnapshotJson, path: path89.posix.join(evidenceRelBase, `${input.kind}.flow.json`), source: "generated" },
|
|
35830
|
+
{ name: `${input.kind}.seeds.json`, content: seedsJson, path: path89.posix.join(evidenceRelBase, `${input.kind}.seeds.json`), source: "generated" }
|
|
35715
35831
|
]);
|
|
35716
35832
|
if (!floor.ok)
|
|
35717
35833
|
return { ok: false, code: "security_denied", detail: floor.reason };
|
|
@@ -35765,14 +35881,14 @@ ${safeSeeds.content}`;
|
|
|
35765
35881
|
}
|
|
35766
35882
|
summary = result.text.trim().length > 0 ? result.text.trim() : mechanicalSummary(summaryDiff, course);
|
|
35767
35883
|
}
|
|
35768
|
-
const evidenceDir =
|
|
35884
|
+
const evidenceDir = path89.join(input.cwd, ".metaproject", "workspaces", input.workspaceId, "machine-evidence");
|
|
35769
35885
|
await mkdir21(evidenceDir, { recursive: true });
|
|
35770
35886
|
const diffFile = `${input.kind}.${shortHash}.diff.txt`;
|
|
35771
35887
|
const flowFile = `${input.kind}.${shortHash}.flow.json`;
|
|
35772
35888
|
const seedsFile = `${input.kind}.${shortHash}.seeds.json`;
|
|
35773
|
-
await writeFileAtomic(
|
|
35774
|
-
await writeFileAtomic(
|
|
35775
|
-
await writeFileAtomic(
|
|
35889
|
+
await writeFileAtomic(path89.join(evidenceDir, diffFile), safeDiff.content);
|
|
35890
|
+
await writeFileAtomic(path89.join(evidenceDir, flowFile), safeFlow.content);
|
|
35891
|
+
await writeFileAtomic(path89.join(evidenceDir, seedsFile), safeSeeds.content);
|
|
35776
35892
|
const observedAt = now().toISOString();
|
|
35777
35893
|
const relBase = `./.metaproject/workspaces/${input.workspaceId}/machine-evidence`;
|
|
35778
35894
|
const evidence = [
|
|
@@ -35782,7 +35898,7 @@ ${safeSeeds.content}`;
|
|
|
35782
35898
|
];
|
|
35783
35899
|
if (floor.notice !== undefined) {
|
|
35784
35900
|
const noticeFile = `${input.kind}.${shortHash}.redaction.md`;
|
|
35785
|
-
await writeFileAtomic(
|
|
35901
|
+
await writeFileAtomic(path89.join(evidenceDir, noticeFile), floor.notice);
|
|
35786
35902
|
evidence.push({ kind: REDACTION_NOTICE_KIND, uri: `${relBase}/${noticeFile}`, revision: sha2563(floor.notice), observedAt });
|
|
35787
35903
|
}
|
|
35788
35904
|
return {
|
|
@@ -35801,18 +35917,18 @@ async function writeFlooredArchiveArtifact(params) {
|
|
|
35801
35917
|
{
|
|
35802
35918
|
name: params.filename,
|
|
35803
35919
|
content: params.content,
|
|
35804
|
-
path:
|
|
35920
|
+
path: path89.posix.join("slate-archive", params.filename),
|
|
35805
35921
|
source: "generated"
|
|
35806
35922
|
}
|
|
35807
35923
|
]);
|
|
35808
35924
|
if (!floor.ok)
|
|
35809
35925
|
return { ok: false, code: "security_denied", detail: floor.reason };
|
|
35810
35926
|
const body = floor.bodies[0];
|
|
35811
|
-
const archiveDir =
|
|
35927
|
+
const archiveDir = path89.join(params.dir, "slate-archive");
|
|
35812
35928
|
await mkdir21(archiveDir, { recursive: true });
|
|
35813
|
-
await writeFileAtomic(
|
|
35929
|
+
await writeFileAtomic(path89.join(archiveDir, params.filename), body.content);
|
|
35814
35930
|
if (floor.notice !== undefined) {
|
|
35815
|
-
await writeFileAtomic(
|
|
35931
|
+
await writeFileAtomic(path89.join(archiveDir, `${params.filename}${ARCHIVE_REDACTION_NOTICE_SUFFIX}`), floor.notice);
|
|
35816
35932
|
}
|
|
35817
35933
|
return { ok: true, altered: body.altered };
|
|
35818
35934
|
}
|
|
@@ -35848,9 +35964,9 @@ async function writeWrapUpOutcomeArtifact(cwd, dir, trigger, now, groups) {
|
|
|
35848
35964
|
return;
|
|
35849
35965
|
const refusalIso = now().toISOString();
|
|
35850
35966
|
const refusalFilename = `${refusalIso.replace(/[:.]/g, "-")}-wrap-up-outcome.json`;
|
|
35851
|
-
const archiveDir =
|
|
35967
|
+
const archiveDir = path89.join(dir, "slate-archive");
|
|
35852
35968
|
await mkdir21(archiveDir, { recursive: true });
|
|
35853
|
-
await writeFileAtomic(
|
|
35969
|
+
await writeFileAtomic(path89.join(archiveDir, refusalFilename), `${JSON.stringify({
|
|
35854
35970
|
recordType: "wrap-up-outcome",
|
|
35855
35971
|
trigger,
|
|
35856
35972
|
generatedAt: refusalIso,
|
|
@@ -36185,7 +36301,7 @@ init_fs();
|
|
|
36185
36301
|
init_repomap();
|
|
36186
36302
|
init_redact();
|
|
36187
36303
|
init_slate();
|
|
36188
|
-
import
|
|
36304
|
+
import path90 from "path";
|
|
36189
36305
|
var DEFAULT_TERMINAL_STATE_MAX_TOKENS = 2000;
|
|
36190
36306
|
function boundedRedactedAnchorsSnapshot(anchors, maxTokens) {
|
|
36191
36307
|
const fence = anchors.fence?.map((entry) => redactSensitiveText(entry));
|
|
@@ -36220,7 +36336,7 @@ function renderTerminalStateBlock(state, opts) {
|
|
|
36220
36336
|
`);
|
|
36221
36337
|
}
|
|
36222
36338
|
async function writeTerminalState(dir, state) {
|
|
36223
|
-
await writeFileAtomic(
|
|
36339
|
+
await writeFileAtomic(path90.join(dir, "terminal-state.json"), `${JSON.stringify(state, null, 2)}
|
|
36224
36340
|
`);
|
|
36225
36341
|
}
|
|
36226
36342
|
|