@punks/cli 3.1.5 → 3.1.7
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/AGENTS.md +1 -1
- package/README.md +1 -1
- package/dist/BASELINE_CHANGELOG.md +44 -0
- package/dist/CHANGELOG.md +60 -0
- package/dist/data/AGENTS.md +4 -110
- package/dist/data/hooks/format-edited-file.mjs +392 -21
- package/dist/data/scripts/harness-projection/adapters/opencode.mjs +0 -15
- package/dist/data/scripts/harness-projection/test-fixtures/opencode/projection.json +0 -15
- package/dist/data/scripts/sync-subagents.mjs +763 -106
- package/dist/index.js +1565 -1081
- package/dist/skills/agnostic/docs/docs-onboarding/SKILL.md +2 -2
- package/dist/skills/agnostic/planning/create-plan/SKILL.md +4 -1
- package/dist/skills/agnostic/planning/create-spec/SKILL.md +7 -4
- package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +3 -0
- package/dist/skills/agnostic/requirements/write-backlog/SKILL.md +2 -1
- package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +14 -1
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +5 -0
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +4 -0
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +14 -1
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +4 -0
- package/dist/skills/agnostic/research/parallel-research/DURABLE-REPORT.md +7 -4
- package/dist/skills/agnostic/research/parallel-research/SKILL.md +8 -9
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/.gitignore +29 -0
- package/dist/skills/misc/wait-what/SKILL.md +7 -3
- package/dist/skills/phases/delivery-phase/phases/router.md +2 -2
- package/dist/skills/phases/delivery-phase/phases/spec.md +4 -1
- package/dist/skills/phases/finder-phase/SKILL.md +3 -0
- package/dist/skills/phases/finder-phase/references/frontier-lifecycle.md +3 -1
- package/package.json +20 -7
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -19,6 +19,16 @@ const sharedSkillsPath = path.join(repoRoot, ".agents/skills");
|
|
|
19
19
|
const sharedHooksPath = path.join(repoRoot, ".agents/hooks");
|
|
20
20
|
const contextPlanPath = path.join(repoRoot, ".devpunks/context-plan.json");
|
|
21
21
|
const projectionReceiptPath = path.join(repoRoot, ".devpunks/harness-projection-receipt.json");
|
|
22
|
+
const scaffoldManifestPath = path.join(repoRoot, ".devpunks/scaffold-manifest.json");
|
|
23
|
+
const projectionReceiptRelativePath = ".devpunks/harness-projection-receipt.json";
|
|
24
|
+
const publicationLockCachePath = path.join(repoRoot, ".devpunks-cache");
|
|
25
|
+
const publicationLockPath = path.join(
|
|
26
|
+
publicationLockCachePath,
|
|
27
|
+
"sync-subagents-publication.lock",
|
|
28
|
+
);
|
|
29
|
+
const publicationLockOwnerFile = "owner.json";
|
|
30
|
+
const defaultPublicationLockStaleAfterMs = 5 * 60 * 1000;
|
|
31
|
+
const maximumConfinedFileBytes = 16 * 1024 * 1024;
|
|
22
32
|
const adapters = [claudeAdapter, codexAdapter, cursorAdapter, openCodeAdapter];
|
|
23
33
|
let previousCopyFallbacks = [];
|
|
24
34
|
const currentCopyFallbacks = new Map();
|
|
@@ -26,6 +36,7 @@ let operationRepoRootIdentity;
|
|
|
26
36
|
|
|
27
37
|
const confinedMutationScript = String.raw`
|
|
28
38
|
import { spawnSync } from "node:child_process";
|
|
39
|
+
import { createHash } from "node:crypto";
|
|
29
40
|
import {
|
|
30
41
|
closeSync,
|
|
31
42
|
constants,
|
|
@@ -82,6 +93,57 @@ const assertExpectedLeaf = (targetPath, expected) => {
|
|
|
82
93
|
return target;
|
|
83
94
|
};
|
|
84
95
|
|
|
96
|
+
const assertExpectedFileContent = (
|
|
97
|
+
targetPath,
|
|
98
|
+
expectedTarget,
|
|
99
|
+
expectedSha256,
|
|
100
|
+
maximumBytes,
|
|
101
|
+
) => {
|
|
102
|
+
let contentDescriptor;
|
|
103
|
+
try {
|
|
104
|
+
contentDescriptor = openSync(
|
|
105
|
+
targetPath,
|
|
106
|
+
constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),
|
|
107
|
+
);
|
|
108
|
+
const opened = fstatSync(contentDescriptor);
|
|
109
|
+
if (
|
|
110
|
+
!opened.isFile() ||
|
|
111
|
+
opened.dev !== expectedTarget.device ||
|
|
112
|
+
opened.ino !== expectedTarget.inode
|
|
113
|
+
) {
|
|
114
|
+
const error = new Error("Confined mutation target changed before content validation.");
|
|
115
|
+
error.code = "ESTALE_TARGET";
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
if (opened.size > maximumBytes) {
|
|
119
|
+
const error = new Error("Confined mutation target exceeds the validation limit.");
|
|
120
|
+
error.code = "EFBIG";
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
const hash = createHash("sha256");
|
|
124
|
+
let total = 0;
|
|
125
|
+
while (total <= maximumBytes) {
|
|
126
|
+
const buffer = Buffer.alloc(Math.min(64 * 1024, maximumBytes + 1 - total));
|
|
127
|
+
const bytesRead = readSync(contentDescriptor, buffer, 0, buffer.length, null);
|
|
128
|
+
if (bytesRead === 0) break;
|
|
129
|
+
hash.update(buffer.subarray(0, bytesRead));
|
|
130
|
+
total += bytesRead;
|
|
131
|
+
}
|
|
132
|
+
if (total > maximumBytes) {
|
|
133
|
+
const error = new Error("Confined mutation target exceeds the validation limit.");
|
|
134
|
+
error.code = "EFBIG";
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
if (hash.digest("hex") !== expectedSha256) {
|
|
138
|
+
const error = new Error("Confined mutation target content changed after validation.");
|
|
139
|
+
error.code = "ESTALE_TARGET";
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
} finally {
|
|
143
|
+
if (contentDescriptor !== undefined) closeSync(contentDescriptor);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
85
147
|
const confinedDirectoryCopyScript = [
|
|
86
148
|
'import { cpSync, statSync } from "node:fs";',
|
|
87
149
|
"const expected = JSON.parse(process.argv[1]);",
|
|
@@ -106,9 +168,57 @@ const copyIntoClaimedDirectory = (request, expected) => {
|
|
|
106
168
|
}
|
|
107
169
|
};
|
|
108
170
|
|
|
171
|
+
const readSmallFile = (targetPath, maximumBytes) => {
|
|
172
|
+
let fileDescriptor;
|
|
173
|
+
try {
|
|
174
|
+
fileDescriptor = openSync(
|
|
175
|
+
targetPath,
|
|
176
|
+
constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),
|
|
177
|
+
);
|
|
178
|
+
const opened = fstatSync(fileDescriptor);
|
|
179
|
+
if (!opened.isFile() || opened.size > maximumBytes) {
|
|
180
|
+
const error = new Error("Confined lock owner is not a bounded regular file.");
|
|
181
|
+
error.code = "EINVAL";
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
const content = Buffer.alloc(opened.size);
|
|
185
|
+
let offset = 0;
|
|
186
|
+
while (offset < content.length) {
|
|
187
|
+
const bytesRead = readSync(
|
|
188
|
+
fileDescriptor,
|
|
189
|
+
content,
|
|
190
|
+
offset,
|
|
191
|
+
content.length - offset,
|
|
192
|
+
null,
|
|
193
|
+
);
|
|
194
|
+
if (bytesRead === 0) break;
|
|
195
|
+
offset += bytesRead;
|
|
196
|
+
}
|
|
197
|
+
return content.subarray(0, offset).toString("base64");
|
|
198
|
+
} finally {
|
|
199
|
+
if (fileDescriptor !== undefined) closeSync(fileDescriptor);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const assertLockOwner = (request, directory = request.target) => {
|
|
204
|
+
const ownerPath = directory + "/" + request.ownerFile;
|
|
205
|
+
const matches =
|
|
206
|
+
request.ownerEvidence === null
|
|
207
|
+
? lstatSync(ownerPath, { throwIfNoEntry: false }) === undefined
|
|
208
|
+
: readSmallFile(ownerPath, request.maximumBytes) === request.ownerEvidence;
|
|
209
|
+
if (!matches) {
|
|
210
|
+
const error = new Error("Confined publication lock ownership changed.");
|
|
211
|
+
error.code = "ESTALE_TARGET";
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
109
216
|
const mutate = (request) => {
|
|
110
217
|
let descriptor;
|
|
218
|
+
let claimedIdentity;
|
|
219
|
+
let claimedPath;
|
|
111
220
|
let createdIdentity;
|
|
221
|
+
let publishedIdentity;
|
|
112
222
|
let response = {};
|
|
113
223
|
let sourceDescriptor;
|
|
114
224
|
let writePath;
|
|
@@ -161,6 +271,26 @@ const mutate = (request) => {
|
|
|
161
271
|
error.code = "EINVAL";
|
|
162
272
|
throw error;
|
|
163
273
|
}
|
|
274
|
+
} else if (request.operation === "acquire-lock") {
|
|
275
|
+
if (lstatSync(request.target, { throwIfNoEntry: false }) !== undefined) {
|
|
276
|
+
const error = new Error("Confined publication lock already exists.");
|
|
277
|
+
error.code = "EEXIST";
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
mkdirSync(request.target, 0o700);
|
|
281
|
+
const created = lstatSync(request.target);
|
|
282
|
+
createdIdentity = { device: created.dev, inode: created.ino };
|
|
283
|
+
writePath = request.target;
|
|
284
|
+
writeFileSync(request.target + "/" + request.ownerFile, request.ownerContent, {
|
|
285
|
+
flag: "wx",
|
|
286
|
+
mode: 0o600,
|
|
287
|
+
});
|
|
288
|
+
assertParentIdentity();
|
|
289
|
+
assertExpectedLeaf(request.target, { ...createdIdentity, kind: "directory" });
|
|
290
|
+
assertLockOwner(request);
|
|
291
|
+
response = { target: createdIdentity };
|
|
292
|
+
writePath = undefined;
|
|
293
|
+
createdIdentity = undefined;
|
|
164
294
|
} else if (request.operation === "write") {
|
|
165
295
|
const target = lstatSync(request.target, { throwIfNoEntry: false });
|
|
166
296
|
if (target !== undefined && (target.isSymbolicLink() || !target.isFile())) {
|
|
@@ -168,10 +298,11 @@ const mutate = (request) => {
|
|
|
168
298
|
error.code = "EINVAL";
|
|
169
299
|
throw error;
|
|
170
300
|
}
|
|
171
|
-
const expectedTarget =
|
|
172
|
-
target === undefined
|
|
301
|
+
const expectedTarget = request.expectedTarget ??
|
|
302
|
+
(target === undefined
|
|
173
303
|
? { kind: "absent" }
|
|
174
|
-
: { device: target.dev, inode: target.ino, kind: leafKind(target) };
|
|
304
|
+
: { device: target.dev, inode: target.ino, kind: leafKind(target) });
|
|
305
|
+
assertExpectedLeaf(request.target, expectedTarget);
|
|
175
306
|
writePath = request.temporary;
|
|
176
307
|
descriptor = openSync(
|
|
177
308
|
writePath,
|
|
@@ -189,10 +320,61 @@ const mutate = (request) => {
|
|
|
189
320
|
descriptor = undefined;
|
|
190
321
|
assertParentIdentity();
|
|
191
322
|
assertExpectedLeaf(request.target, expectedTarget);
|
|
192
|
-
|
|
323
|
+
if (request.expectedContentSha256 !== undefined) {
|
|
324
|
+
if (lstatSync(request.claim, { throwIfNoEntry: false }) !== undefined) {
|
|
325
|
+
const error = new Error("Confined mutation claim path already exists.");
|
|
326
|
+
error.code = "EEXIST";
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
renameSync(request.target, request.claim);
|
|
330
|
+
claimedIdentity = expectedTarget;
|
|
331
|
+
claimedPath = request.claim;
|
|
332
|
+
assertParentIdentity();
|
|
333
|
+
assertExpectedLeaf(request.claim, expectedTarget);
|
|
334
|
+
assertExpectedFileContent(
|
|
335
|
+
request.claim,
|
|
336
|
+
expectedTarget,
|
|
337
|
+
request.expectedContentSha256,
|
|
338
|
+
request.maximumBytes,
|
|
339
|
+
);
|
|
340
|
+
assertExpectedLeaf(request.target, { kind: "absent" });
|
|
341
|
+
if (lstatSync(request.publishedHold, { throwIfNoEntry: false }) !== undefined) {
|
|
342
|
+
const error = new Error("Confined mutation published hold path already exists.");
|
|
343
|
+
error.code = "EEXIST";
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
linkSync(request.temporary, request.target);
|
|
347
|
+
publishedIdentity = createdIdentity;
|
|
348
|
+
unlinkSync(request.temporary);
|
|
349
|
+
writePath = undefined;
|
|
350
|
+
createdIdentity = undefined;
|
|
351
|
+
// Supported publication boundary.
|
|
352
|
+
// Both sides are exact. POSIX cannot exclude a non-cooperating writable descriptor later.
|
|
353
|
+
assertExpectedLeaf(request.claim, expectedTarget);
|
|
354
|
+
assertExpectedFileContent(
|
|
355
|
+
request.claim,
|
|
356
|
+
expectedTarget,
|
|
357
|
+
request.expectedContentSha256,
|
|
358
|
+
request.maximumBytes,
|
|
359
|
+
);
|
|
360
|
+
assertExpectedLeaf(request.target, { ...publishedIdentity, kind: "file" });
|
|
361
|
+
assertExpectedFileContent(
|
|
362
|
+
request.target,
|
|
363
|
+
publishedIdentity,
|
|
364
|
+
createHash("sha256").update(request.content).digest("hex"),
|
|
365
|
+
request.maximumBytes,
|
|
366
|
+
);
|
|
367
|
+
unlinkSync(request.claim);
|
|
368
|
+
claimedIdentity = undefined;
|
|
369
|
+
claimedPath = undefined;
|
|
370
|
+
publishedIdentity = undefined;
|
|
371
|
+
} else {
|
|
372
|
+
renameSync(request.temporary, request.target);
|
|
373
|
+
}
|
|
193
374
|
assertParentIdentity();
|
|
194
375
|
} else if (request.operation === "remove") {
|
|
195
376
|
assertExpectedLeaf(request.target, request.expectedTarget);
|
|
377
|
+
if (request.ownerEvidence !== undefined) assertLockOwner(request);
|
|
196
378
|
if (lstatSync(request.claim, { throwIfNoEntry: false }) !== undefined) {
|
|
197
379
|
const error = new Error("Confined removal claim path already exists.");
|
|
198
380
|
error.code = "EEXIST";
|
|
@@ -202,6 +384,7 @@ const mutate = (request) => {
|
|
|
202
384
|
try {
|
|
203
385
|
assertParentIdentity();
|
|
204
386
|
assertExpectedLeaf(request.claim, request.expectedTarget);
|
|
387
|
+
if (request.ownerEvidence !== undefined) assertLockOwner(request, request.claim);
|
|
205
388
|
rmSync(request.claim, { force: true, recursive: request.recursive });
|
|
206
389
|
} catch (error) {
|
|
207
390
|
if (lstatSync(request.claim, { throwIfNoEntry: false }) !== undefined) {
|
|
@@ -297,6 +480,57 @@ const mutate = (request) => {
|
|
|
297
480
|
if (sourceDescriptor !== undefined) {
|
|
298
481
|
closeSync(sourceDescriptor);
|
|
299
482
|
}
|
|
483
|
+
if (publishedIdentity !== undefined) {
|
|
484
|
+
const publishedTarget = lstatSync(request.target, { throwIfNoEntry: false });
|
|
485
|
+
if (publishedTarget !== undefined) {
|
|
486
|
+
if (lstatSync(request.publishedHold, { throwIfNoEntry: false }) !== undefined) {
|
|
487
|
+
// A private-path collision is not producer-owned. Leave both public and claimed paths.
|
|
488
|
+
} else {
|
|
489
|
+
renameSync(request.target, request.publishedHold);
|
|
490
|
+
const heldTarget = lstatSync(request.publishedHold);
|
|
491
|
+
if (
|
|
492
|
+
heldTarget.dev === publishedIdentity.device &&
|
|
493
|
+
heldTarget.ino === publishedIdentity.inode
|
|
494
|
+
) {
|
|
495
|
+
unlinkSync(request.publishedHold);
|
|
496
|
+
} else {
|
|
497
|
+
try {
|
|
498
|
+
if (lstatSync(request.target, { throwIfNoEntry: false }) !== undefined) {
|
|
499
|
+
throw new Error(
|
|
500
|
+
"Confined mutation target was recreated before published-path restoration.",
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
linkSync(request.publishedHold, request.target);
|
|
504
|
+
unlinkSync(request.publishedHold);
|
|
505
|
+
} catch {
|
|
506
|
+
error.backup ??= request.publishedHold;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
publishedIdentity = undefined;
|
|
512
|
+
}
|
|
513
|
+
if (claimedPath !== undefined && claimedIdentity !== undefined) {
|
|
514
|
+
const claim = lstatSync(claimedPath, { throwIfNoEntry: false });
|
|
515
|
+
if (
|
|
516
|
+
claim !== undefined &&
|
|
517
|
+
claim.dev === claimedIdentity.device &&
|
|
518
|
+
claim.ino === claimedIdentity.inode
|
|
519
|
+
) {
|
|
520
|
+
try {
|
|
521
|
+
if (lstatSync(request.target, { throwIfNoEntry: false }) !== undefined) {
|
|
522
|
+
throw new Error("Confined mutation target was recreated before claim restoration.");
|
|
523
|
+
}
|
|
524
|
+
linkSync(claimedPath, request.target);
|
|
525
|
+
unlinkSync(claimedPath);
|
|
526
|
+
claimedPath = undefined;
|
|
527
|
+
} catch {
|
|
528
|
+
error.backup ??= claimedPath;
|
|
529
|
+
}
|
|
530
|
+
} else if (claim !== undefined) {
|
|
531
|
+
error.backup ??= claimedPath;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
300
534
|
if (writePath !== undefined && createdIdentity !== undefined) {
|
|
301
535
|
const current = lstatSync(writePath, { throwIfNoEntry: false });
|
|
302
536
|
if (
|
|
@@ -306,7 +540,9 @@ const mutate = (request) => {
|
|
|
306
540
|
) {
|
|
307
541
|
rmSync(writePath, {
|
|
308
542
|
force: true,
|
|
309
|
-
recursive:
|
|
543
|
+
recursive:
|
|
544
|
+
request.operation === "acquire-lock" ||
|
|
545
|
+
(request.operation === "copy" && request.recursive === true),
|
|
310
546
|
});
|
|
311
547
|
}
|
|
312
548
|
}
|
|
@@ -704,7 +940,7 @@ async function removeConfinedPath(targetPath, options = {}) {
|
|
|
704
940
|
operation,
|
|
705
941
|
repoRootIdentity,
|
|
706
942
|
);
|
|
707
|
-
const expectedTarget = await captureLeafExpectation(targetPath);
|
|
943
|
+
const expectedTarget = options.expectedTarget ?? (await captureLeafExpectation(targetPath));
|
|
708
944
|
if (expectedTarget.kind === "absent") {
|
|
709
945
|
await assertRepoRootIdentity(repoRootIdentity, operation);
|
|
710
946
|
return;
|
|
@@ -720,6 +956,13 @@ async function removeConfinedPath(targetPath, options = {}) {
|
|
|
720
956
|
claim: `.hi-remove-${randomUUID()}`,
|
|
721
957
|
expectedTarget,
|
|
722
958
|
operation: "remove",
|
|
959
|
+
...(options.ownerEvidence === undefined
|
|
960
|
+
? {}
|
|
961
|
+
: {
|
|
962
|
+
maximumBytes: 4096,
|
|
963
|
+
ownerEvidence: options.ownerEvidence,
|
|
964
|
+
ownerFile: publicationLockOwnerFile,
|
|
965
|
+
}),
|
|
723
966
|
parent: parentIdentity,
|
|
724
967
|
recursive: options.recursive === true,
|
|
725
968
|
target: path.basename(targetPath),
|
|
@@ -727,7 +970,12 @@ async function removeConfinedPath(targetPath, options = {}) {
|
|
|
727
970
|
await assertSameDirectoryIdentity(parentDirectory, parentIdentity, operation, repoRootIdentity);
|
|
728
971
|
}
|
|
729
972
|
|
|
730
|
-
async function writeConfinedTextFile(
|
|
973
|
+
async function writeConfinedTextFile(
|
|
974
|
+
targetPath,
|
|
975
|
+
content,
|
|
976
|
+
expectedTarget,
|
|
977
|
+
expectedContentSha256,
|
|
978
|
+
) {
|
|
731
979
|
const operation = "write scaffold content";
|
|
732
980
|
const repoRootIdentity = repoRootIdentityForOperation(operation);
|
|
733
981
|
await assertConfinedRegularFile(targetPath, repoRootIdentity);
|
|
@@ -748,13 +996,22 @@ async function writeConfinedTextFile(targetPath, content) {
|
|
|
748
996
|
parent: parentIdentity,
|
|
749
997
|
target: path.basename(targetPath),
|
|
750
998
|
temporary: `.hi-${randomUUID()}.tmp`,
|
|
999
|
+
...(expectedTarget === undefined ? {} : { expectedTarget }),
|
|
1000
|
+
...(expectedContentSha256 === undefined
|
|
1001
|
+
? {}
|
|
1002
|
+
: {
|
|
1003
|
+
claim: `.hi-manifest-claim-${randomUUID()}.tmp`,
|
|
1004
|
+
expectedContentSha256,
|
|
1005
|
+
maximumBytes: maximumConfinedFileBytes,
|
|
1006
|
+
publishedHold: `.hi-manifest-published-${randomUUID()}.tmp`,
|
|
1007
|
+
}),
|
|
751
1008
|
},
|
|
752
1009
|
content,
|
|
753
1010
|
);
|
|
754
1011
|
await assertSameDirectoryIdentity(parentDirectory, parentIdentity, operation, repoRootIdentity);
|
|
755
1012
|
}
|
|
756
1013
|
|
|
757
|
-
async function readConfinedRegularFile(targetPath, maximumBytes =
|
|
1014
|
+
async function readConfinedRegularFile(targetPath, maximumBytes = maximumConfinedFileBytes) {
|
|
758
1015
|
const operation = "read scaffold content";
|
|
759
1016
|
const repoRootIdentity = repoRootIdentityForOperation(operation);
|
|
760
1017
|
const target = await assertConfinedRegularFile(targetPath, repoRootIdentity);
|
|
@@ -833,15 +1090,7 @@ const claudeFormatCommand =
|
|
|
833
1090
|
'node "$CLAUDE_PROJECT_DIR"/.claude/hooks/format-edited-file.mjs claude';
|
|
834
1091
|
|
|
835
1092
|
function buildCodexAgentConfig({ hasFormatHook, hasUpdateCheckHook }) {
|
|
836
|
-
const lines = [
|
|
837
|
-
"[agents]",
|
|
838
|
-
"max_depth = 1",
|
|
839
|
-
"",
|
|
840
|
-
"[features]",
|
|
841
|
-
"codex_hooks = true",
|
|
842
|
-
"",
|
|
843
|
-
"[hooks]",
|
|
844
|
-
];
|
|
1093
|
+
const lines = ["[agents]", "max_depth = 1", "", "[features]", "hooks = true", "", "[hooks]"];
|
|
845
1094
|
|
|
846
1095
|
if (hasFormatHook || hasUpdateCheckHook) {
|
|
847
1096
|
const sessionStartHooks = [];
|
|
@@ -982,7 +1231,7 @@ function buildCursorHooksConfig({ hasFormatHook, hasUpdateCheckHook }) {
|
|
|
982
1231
|
};
|
|
983
1232
|
}
|
|
984
1233
|
|
|
985
|
-
function buildOpenCodeConfig(existingConfig
|
|
1234
|
+
function buildOpenCodeConfig(existingConfig) {
|
|
986
1235
|
const config = { ...existingConfig };
|
|
987
1236
|
const formatter =
|
|
988
1237
|
typeof config.formatter === "object" && config.formatter !== null
|
|
@@ -990,12 +1239,6 @@ function buildOpenCodeConfig(existingConfig, { hasFormatHook }) {
|
|
|
990
1239
|
: {};
|
|
991
1240
|
delete formatter["harness-format-edited-file"];
|
|
992
1241
|
|
|
993
|
-
if (hasFormatHook) {
|
|
994
|
-
formatter["harness-format-edited-file"] = {
|
|
995
|
-
command: ["node", ".agents/hooks/format-edited-file.mjs", "files", "$FILE"],
|
|
996
|
-
extensions: [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs", ".json", ".py"],
|
|
997
|
-
};
|
|
998
|
-
}
|
|
999
1242
|
if (Object.keys(formatter).length > 0) {
|
|
1000
1243
|
config.formatter = formatter;
|
|
1001
1244
|
} else {
|
|
@@ -1045,6 +1288,388 @@ function encodeJson(value) {
|
|
|
1045
1288
|
return `${JSON.stringify(value, null, 2)}\n`;
|
|
1046
1289
|
}
|
|
1047
1290
|
|
|
1291
|
+
const compareJsonKeys = (left, right) => Number(left > right) - Number(left < right);
|
|
1292
|
+
|
|
1293
|
+
function canonicalJsonStringify(value) {
|
|
1294
|
+
if (Array.isArray(value)) {
|
|
1295
|
+
return `[${value.map(canonicalJsonStringify).join(",")}]`;
|
|
1296
|
+
}
|
|
1297
|
+
if (value !== null && typeof value === "object") {
|
|
1298
|
+
return `{${Object.entries(value)
|
|
1299
|
+
.toSorted(([left], [right]) => compareJsonKeys(left, right))
|
|
1300
|
+
.map(([key, child]) => `${JSON.stringify(key)}:${canonicalJsonStringify(child)}`)
|
|
1301
|
+
.join(",")}}`;
|
|
1302
|
+
}
|
|
1303
|
+
return JSON.stringify(value) ?? "null";
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
const semanticJsonHash = (value) =>
|
|
1307
|
+
createHash("sha256").update(canonicalJsonStringify(value)).digest("hex");
|
|
1308
|
+
|
|
1309
|
+
const managedFileKinds = new Set([
|
|
1310
|
+
"agent-prompt",
|
|
1311
|
+
"context-plan",
|
|
1312
|
+
"handoff",
|
|
1313
|
+
"harness",
|
|
1314
|
+
"hook",
|
|
1315
|
+
"lint-spec",
|
|
1316
|
+
"manifest",
|
|
1317
|
+
"prompt-spec",
|
|
1318
|
+
"projection-receipt",
|
|
1319
|
+
"required-tools",
|
|
1320
|
+
"script",
|
|
1321
|
+
"skill",
|
|
1322
|
+
"source-guide",
|
|
1323
|
+
"subagent",
|
|
1324
|
+
]);
|
|
1325
|
+
|
|
1326
|
+
const hasExactKeys = (value, keys) =>
|
|
1327
|
+
isObject(value) &&
|
|
1328
|
+
Object.keys(value).length === keys.length &&
|
|
1329
|
+
Object.keys(value).every((key) => keys.includes(key));
|
|
1330
|
+
|
|
1331
|
+
const validOutputFingerprint = (fingerprint) =>
|
|
1332
|
+
(hasExactKeys(fingerprint, ["_tag", "mode", "sha256"]) &&
|
|
1333
|
+
fingerprint._tag === "File" &&
|
|
1334
|
+
Number.isInteger(fingerprint.mode) &&
|
|
1335
|
+
fingerprint.mode >= 0 &&
|
|
1336
|
+
fingerprint.mode <= 0o777 &&
|
|
1337
|
+
/^[0-9a-f]{64}$/u.test(fingerprint.sha256)) ||
|
|
1338
|
+
(hasExactKeys(fingerprint, ["_tag", "sha256", "target"]) &&
|
|
1339
|
+
fingerprint._tag === "Symlink" &&
|
|
1340
|
+
/^[0-9a-f]{64}$/u.test(fingerprint.sha256) &&
|
|
1341
|
+
isNonEmptyString(fingerprint.target));
|
|
1342
|
+
|
|
1343
|
+
function validManagedFileOwnership(ownership) {
|
|
1344
|
+
if (ownership === undefined) return true;
|
|
1345
|
+
if (hasExactKeys(ownership, ["_tag"]) && ownership._tag === "ScaffoldManaged") return true;
|
|
1346
|
+
if (
|
|
1347
|
+
!hasExactKeys(ownership, ["_tag", "evidence"]) ||
|
|
1348
|
+
ownership._tag !== "ProjectGenerated" ||
|
|
1349
|
+
!isObject(ownership.evidence)
|
|
1350
|
+
) {
|
|
1351
|
+
return false;
|
|
1352
|
+
}
|
|
1353
|
+
const evidenceKeys = Object.keys(ownership.evidence);
|
|
1354
|
+
if (
|
|
1355
|
+
!evidenceKeys.every((key) =>
|
|
1356
|
+
["producer", "revision", "authority", "outputFingerprint"].includes(key),
|
|
1357
|
+
) ||
|
|
1358
|
+
![3, 4].includes(evidenceKeys.length) ||
|
|
1359
|
+
!isNonEmptyString(ownership.evidence.producer) ||
|
|
1360
|
+
(ownership.evidence.revision !== undefined &&
|
|
1361
|
+
!isNonEmptyString(ownership.evidence.revision)) ||
|
|
1362
|
+
!hasExactKeys(ownership.evidence.authority, ["_tag", "sourcePath"]) ||
|
|
1363
|
+
ownership.evidence.authority._tag !== "RepositoryMirror" ||
|
|
1364
|
+
!isNonEmptyString(ownership.evidence.authority.sourcePath)
|
|
1365
|
+
) {
|
|
1366
|
+
return false;
|
|
1367
|
+
}
|
|
1368
|
+
return validOutputFingerprint(ownership.evidence.outputFingerprint);
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
function decodeScaffoldManifest(bytes) {
|
|
1372
|
+
let manifest;
|
|
1373
|
+
try {
|
|
1374
|
+
manifest = JSON.parse(bytes.toString("utf8"));
|
|
1375
|
+
} catch (cause) {
|
|
1376
|
+
throw new Error("Scaffold manifest is malformed JSON.", { cause });
|
|
1377
|
+
}
|
|
1378
|
+
if (
|
|
1379
|
+
!isObject(manifest) ||
|
|
1380
|
+
!Array.isArray(manifest.finalPacks) ||
|
|
1381
|
+
!manifest.finalPacks.every((pack) => typeof pack === "string") ||
|
|
1382
|
+
!Array.isArray(manifest.managedFiles) ||
|
|
1383
|
+
manifest.managedFiles.some(
|
|
1384
|
+
(file) =>
|
|
1385
|
+
!isObject(file) ||
|
|
1386
|
+
typeof file.path !== "string" ||
|
|
1387
|
+
typeof file.sha256 !== "string" ||
|
|
1388
|
+
!managedFileKinds.has(file.kind) ||
|
|
1389
|
+
!validManagedFileOwnership(file.ownership),
|
|
1390
|
+
)
|
|
1391
|
+
) {
|
|
1392
|
+
throw new Error("Scaffold manifest does not match the supported schema.");
|
|
1393
|
+
}
|
|
1394
|
+
const receiptEntries = manifest.managedFiles.filter(
|
|
1395
|
+
({ kind }) => kind === "projection-receipt",
|
|
1396
|
+
);
|
|
1397
|
+
const receiptPathEntries = manifest.managedFiles.filter(
|
|
1398
|
+
({ path: managedPath }) => managedPath === projectionReceiptRelativePath,
|
|
1399
|
+
);
|
|
1400
|
+
if (
|
|
1401
|
+
receiptEntries.length !== 1 ||
|
|
1402
|
+
receiptPathEntries.length !== 1 ||
|
|
1403
|
+
receiptEntries[0].path !== projectionReceiptRelativePath ||
|
|
1404
|
+
(receiptEntries[0].ownership !== undefined &&
|
|
1405
|
+
receiptEntries[0].ownership._tag !== "ScaffoldManaged")
|
|
1406
|
+
) {
|
|
1407
|
+
throw new Error(
|
|
1408
|
+
`Scaffold manifest must contain exactly one scaffold-managed projection-receipt entry for ${projectionReceiptRelativePath}.`,
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
return manifest;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
async function preflightScaffoldManifest() {
|
|
1415
|
+
await assertConfinedRegularFile(scaffoldManifestPath);
|
|
1416
|
+
const bytes = await readConfinedRegularFile(scaffoldManifestPath);
|
|
1417
|
+
if (bytes === null) return null;
|
|
1418
|
+
const manifest = decodeScaffoldManifest(bytes);
|
|
1419
|
+
return { identity: semanticJsonHash(manifest) };
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
const publicationLockRetry = (cause) => {
|
|
1423
|
+
const error = new Error(
|
|
1424
|
+
"Harness projection publication is already active; retry sync-subagents.",
|
|
1425
|
+
cause === undefined ? undefined : { cause },
|
|
1426
|
+
);
|
|
1427
|
+
error.code = "PROJECTION_PUBLICATION_RETRY";
|
|
1428
|
+
return error;
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
async function acquireProjectionPublicationLock({
|
|
1432
|
+
now = Date.now,
|
|
1433
|
+
staleAfterMs = defaultPublicationLockStaleAfterMs,
|
|
1434
|
+
} = {}) {
|
|
1435
|
+
if (
|
|
1436
|
+
typeof now !== "function" ||
|
|
1437
|
+
!Number.isFinite(staleAfterMs) ||
|
|
1438
|
+
staleAfterMs <= 0
|
|
1439
|
+
) {
|
|
1440
|
+
throw new Error("Projection publication lock timing configuration is invalid.");
|
|
1441
|
+
}
|
|
1442
|
+
const acquiredAt = now();
|
|
1443
|
+
if (!Number.isFinite(acquiredAt)) {
|
|
1444
|
+
throw new Error("Projection publication lock timing configuration is invalid.");
|
|
1445
|
+
}
|
|
1446
|
+
await ensureConfinedDirectory(publicationLockCachePath);
|
|
1447
|
+
const parentIdentity = await captureConfinedDirectoryIdentity(
|
|
1448
|
+
publicationLockCachePath,
|
|
1449
|
+
"acquire projection publication lock",
|
|
1450
|
+
repoRootIdentityForOperation("acquire projection publication lock"),
|
|
1451
|
+
);
|
|
1452
|
+
const token = randomUUID();
|
|
1453
|
+
const ownerContent = encodeJson({ acquiredAt, token });
|
|
1454
|
+
const ownerEvidence = Buffer.from(ownerContent).toString("base64");
|
|
1455
|
+
const baseRequest = {
|
|
1456
|
+
maximumBytes: 4096,
|
|
1457
|
+
ownerContent,
|
|
1458
|
+
ownerEvidence,
|
|
1459
|
+
ownerFile: publicationLockOwnerFile,
|
|
1460
|
+
parent: parentIdentity,
|
|
1461
|
+
target: path.basename(publicationLockPath),
|
|
1462
|
+
};
|
|
1463
|
+
|
|
1464
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
1465
|
+
try {
|
|
1466
|
+
const result = await runStableMutation(publicationLockCachePath, {
|
|
1467
|
+
...baseRequest,
|
|
1468
|
+
operation: "acquire-lock",
|
|
1469
|
+
});
|
|
1470
|
+
if (
|
|
1471
|
+
!isObject(result.target) ||
|
|
1472
|
+
!Number.isInteger(result.target.device) ||
|
|
1473
|
+
!Number.isInteger(result.target.inode)
|
|
1474
|
+
) {
|
|
1475
|
+
throw new Error("Confined publication lock returned no target identity.");
|
|
1476
|
+
}
|
|
1477
|
+
return {
|
|
1478
|
+
expectedTarget: {
|
|
1479
|
+
device: result.target.device,
|
|
1480
|
+
inode: result.target.inode,
|
|
1481
|
+
kind: "directory",
|
|
1482
|
+
},
|
|
1483
|
+
ownerEvidence,
|
|
1484
|
+
};
|
|
1485
|
+
} catch (cause) {
|
|
1486
|
+
if (cause?.code !== "EEXIST") throw cause;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
const existing = await lstatOrNull(publicationLockPath);
|
|
1490
|
+
if (existing === null) continue;
|
|
1491
|
+
if (existing.isSymbolicLink() || !existing.isDirectory()) {
|
|
1492
|
+
throw publicationLockRetry();
|
|
1493
|
+
}
|
|
1494
|
+
const expectedTarget = {
|
|
1495
|
+
device: existing.dev,
|
|
1496
|
+
inode: existing.ino,
|
|
1497
|
+
kind: "directory",
|
|
1498
|
+
};
|
|
1499
|
+
let lockStartedAt = existing.mtimeMs;
|
|
1500
|
+
const observedAt = now();
|
|
1501
|
+
if (!Number.isFinite(observedAt)) {
|
|
1502
|
+
throw new Error("Projection publication lock timing configuration is invalid.");
|
|
1503
|
+
}
|
|
1504
|
+
let observedOwnerEvidence = null;
|
|
1505
|
+
let ownerBytes;
|
|
1506
|
+
try {
|
|
1507
|
+
ownerBytes = await readConfinedRegularFile(
|
|
1508
|
+
path.join(publicationLockPath, publicationLockOwnerFile),
|
|
1509
|
+
4096,
|
|
1510
|
+
);
|
|
1511
|
+
} catch (cause) {
|
|
1512
|
+
throw publicationLockRetry(cause);
|
|
1513
|
+
}
|
|
1514
|
+
if (ownerBytes !== null) {
|
|
1515
|
+
observedOwnerEvidence = ownerBytes.toString("base64");
|
|
1516
|
+
try {
|
|
1517
|
+
const owner = JSON.parse(ownerBytes.toString("utf8"));
|
|
1518
|
+
if (
|
|
1519
|
+
hasExactKeys(owner, ["acquiredAt", "token"]) &&
|
|
1520
|
+
Number.isFinite(owner.acquiredAt) &&
|
|
1521
|
+
owner.acquiredAt <= observedAt &&
|
|
1522
|
+
isNonEmptyString(owner.token)
|
|
1523
|
+
) {
|
|
1524
|
+
lockStartedAt = owner.acquiredAt;
|
|
1525
|
+
}
|
|
1526
|
+
} catch {
|
|
1527
|
+
// Exact malformed bytes remain bound to recovery; directory mtime supplies the TTL.
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
const lockAge = observedAt - lockStartedAt;
|
|
1531
|
+
if (Math.abs(lockAge) < staleAfterMs) {
|
|
1532
|
+
throw publicationLockRetry();
|
|
1533
|
+
}
|
|
1534
|
+
try {
|
|
1535
|
+
await removeConfinedPath(publicationLockPath, {
|
|
1536
|
+
expectedTarget,
|
|
1537
|
+
ownerEvidence: observedOwnerEvidence,
|
|
1538
|
+
recursive: true,
|
|
1539
|
+
});
|
|
1540
|
+
} catch (cause) {
|
|
1541
|
+
throw publicationLockRetry(cause);
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
throw publicationLockRetry();
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
async function releaseProjectionPublicationLock(lock) {
|
|
1548
|
+
await removeConfinedPath(publicationLockPath, {
|
|
1549
|
+
expectedTarget: lock.expectedTarget,
|
|
1550
|
+
ownerEvidence: lock.ownerEvidence,
|
|
1551
|
+
recursive: true,
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
const scaffoldManifestPreflightRetry = (state) => {
|
|
1556
|
+
const error = new Error(
|
|
1557
|
+
`Scaffold manifest ${state} after preflight; retry sync-subagents.`,
|
|
1558
|
+
);
|
|
1559
|
+
error.code = "SCAFFOLD_MANIFEST_RETRY";
|
|
1560
|
+
return error;
|
|
1561
|
+
};
|
|
1562
|
+
|
|
1563
|
+
async function assertScaffoldManifestPreflight(preflight) {
|
|
1564
|
+
const bytes = await readConfinedRegularFile(scaffoldManifestPath);
|
|
1565
|
+
if (preflight === null) {
|
|
1566
|
+
if (bytes !== null) throw scaffoldManifestPreflightRetry("changed");
|
|
1567
|
+
return;
|
|
1568
|
+
}
|
|
1569
|
+
if (bytes === null) throw scaffoldManifestPreflightRetry("disappeared");
|
|
1570
|
+
if (semanticJsonHash(decodeScaffoldManifest(bytes)) !== preflight.identity) {
|
|
1571
|
+
throw scaffoldManifestPreflightRetry("changed");
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
async function publishReceiptEvidence(preflight, status, receiptHash) {
|
|
1576
|
+
if (preflight === null) return;
|
|
1577
|
+
const expectedTarget = await captureLeafExpectation(scaffoldManifestPath);
|
|
1578
|
+
if (expectedTarget.kind !== "file") {
|
|
1579
|
+
throw new Error("Scaffold manifest changed after preflight.");
|
|
1580
|
+
}
|
|
1581
|
+
const bytes = await readConfinedRegularFile(scaffoldManifestPath);
|
|
1582
|
+
if (bytes === null) {
|
|
1583
|
+
throw new Error("Scaffold manifest disappeared after preflight.");
|
|
1584
|
+
}
|
|
1585
|
+
const manifest = decodeScaffoldManifest(bytes);
|
|
1586
|
+
if (semanticJsonHash(manifest) !== preflight.identity) {
|
|
1587
|
+
throw new Error("Scaffold manifest changed after preflight.");
|
|
1588
|
+
}
|
|
1589
|
+
const receiptIndex = manifest.managedFiles.findIndex(
|
|
1590
|
+
({ kind }) => kind === "projection-receipt",
|
|
1591
|
+
);
|
|
1592
|
+
const updated = {
|
|
1593
|
+
...manifest,
|
|
1594
|
+
projectionReceiptFile: projectionReceiptRelativePath,
|
|
1595
|
+
projectionStatus: status,
|
|
1596
|
+
managedFiles: manifest.managedFiles.map((file, index) =>
|
|
1597
|
+
index === receiptIndex ? { ...file, sha256: receiptHash } : file,
|
|
1598
|
+
),
|
|
1599
|
+
};
|
|
1600
|
+
const expectedContentSha256 = createHash("sha256").update(bytes).digest("hex");
|
|
1601
|
+
await writeConfinedTextFile(
|
|
1602
|
+
scaffoldManifestPath,
|
|
1603
|
+
encodeJson(updated),
|
|
1604
|
+
expectedTarget,
|
|
1605
|
+
expectedContentSha256,
|
|
1606
|
+
);
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
async function assertPublishedReceiptEvidence(preflight, status, receiptHash) {
|
|
1610
|
+
const receiptBytes = await readConfinedRegularFile(projectionReceiptPath);
|
|
1611
|
+
if (receiptBytes === null) {
|
|
1612
|
+
throw new Error("Published harness projection receipt is missing.");
|
|
1613
|
+
}
|
|
1614
|
+
let receipt;
|
|
1615
|
+
try {
|
|
1616
|
+
receipt = JSON.parse(receiptBytes.toString("utf8"));
|
|
1617
|
+
} catch (cause) {
|
|
1618
|
+
throw new Error("Published harness projection receipt is malformed.", { cause });
|
|
1619
|
+
}
|
|
1620
|
+
if (semanticJsonHash(receipt) !== receiptHash) {
|
|
1621
|
+
throw new Error("Published harness projection receipt changed before commit validation.");
|
|
1622
|
+
}
|
|
1623
|
+
if (preflight === null) return;
|
|
1624
|
+
|
|
1625
|
+
const manifestBytes = await readConfinedRegularFile(scaffoldManifestPath);
|
|
1626
|
+
if (manifestBytes === null) {
|
|
1627
|
+
throw new Error("Published scaffold manifest evidence is missing.");
|
|
1628
|
+
}
|
|
1629
|
+
const manifest = decodeScaffoldManifest(manifestBytes);
|
|
1630
|
+
const receiptEntry = manifest.managedFiles.find(({ kind }) => kind === "projection-receipt");
|
|
1631
|
+
if (receiptEntry.sha256 !== receiptHash || manifest.projectionStatus !== status) {
|
|
1632
|
+
throw new Error("Published harness projection receipt and scaffold manifest diverged.");
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
async function commitProjectionEvidence(manifestPreflight, receipt) {
|
|
1637
|
+
await writeConfinedTextFile(projectionReceiptPath, encodeJson(receipt));
|
|
1638
|
+
const committedReceiptBytes = await readConfinedRegularFile(projectionReceiptPath);
|
|
1639
|
+
if (committedReceiptBytes === null) {
|
|
1640
|
+
throw new Error("Committed harness projection receipt is missing.");
|
|
1641
|
+
}
|
|
1642
|
+
let committedReceipt;
|
|
1643
|
+
try {
|
|
1644
|
+
committedReceipt = JSON.parse(committedReceiptBytes.toString("utf8"));
|
|
1645
|
+
} catch (cause) {
|
|
1646
|
+
throw new Error("Committed harness projection receipt is malformed.", { cause });
|
|
1647
|
+
}
|
|
1648
|
+
const committedReceiptHash = semanticJsonHash(committedReceipt);
|
|
1649
|
+
if (committedReceiptHash !== semanticJsonHash(receipt)) {
|
|
1650
|
+
const error = new Error(
|
|
1651
|
+
"Harness projection receipt changed after publication; retry sync-subagents.",
|
|
1652
|
+
);
|
|
1653
|
+
error.code = "PROJECTION_RECEIPT_RETRY";
|
|
1654
|
+
throw error;
|
|
1655
|
+
}
|
|
1656
|
+
try {
|
|
1657
|
+
await publishReceiptEvidence(manifestPreflight, committedReceipt.status, committedReceiptHash);
|
|
1658
|
+
await assertPublishedReceiptEvidence(
|
|
1659
|
+
manifestPreflight,
|
|
1660
|
+
committedReceipt.status,
|
|
1661
|
+
committedReceiptHash,
|
|
1662
|
+
);
|
|
1663
|
+
} catch (cause) {
|
|
1664
|
+
const error = new Error(
|
|
1665
|
+
"Harness projection receipt and scaffold manifest evidence did not commit coherently; retry sync-subagents.",
|
|
1666
|
+
{ cause },
|
|
1667
|
+
);
|
|
1668
|
+
error.code = "SCAFFOLD_MANIFEST_RETRY";
|
|
1669
|
+
throw error;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1048
1673
|
function encodeOpencodeJson(value, depth = 0) {
|
|
1049
1674
|
const indent = " ".repeat(depth);
|
|
1050
1675
|
const childIndent = " ".repeat(depth + 1);
|
|
@@ -1571,6 +2196,9 @@ async function writeAdapterConfig(adapterId, availableHooks) {
|
|
|
1571
2196
|
const hookIdForAction = (action) =>
|
|
1572
2197
|
action.id.includes(":lifecycle-hook:") ? action.trace?.contribution?.id : undefined;
|
|
1573
2198
|
|
|
2199
|
+
const isManagedCanonicalSource = (source) =>
|
|
2200
|
+
typeof source === "string" && source.replaceAll("\\", "/").startsWith(".agents/");
|
|
2201
|
+
|
|
1574
2202
|
async function reconcileLifecycleHooks(action, adapterId, actionPaths) {
|
|
1575
2203
|
const activeHookIds = new Set();
|
|
1576
2204
|
for (const hookId of action.hookIds) {
|
|
@@ -1632,6 +2260,15 @@ async function applyHarnessAction(action, application) {
|
|
|
1632
2260
|
action.operation === "use-native-prompt" ||
|
|
1633
2261
|
action.operation === "native"
|
|
1634
2262
|
) {
|
|
2263
|
+
const canonicalSource = action.source ?? action.canonicalPath;
|
|
2264
|
+
const canonicalSourcePath = actionPaths.source ?? actionPaths.canonicalPath;
|
|
2265
|
+
if (
|
|
2266
|
+
isManagedCanonicalSource(canonicalSource) &&
|
|
2267
|
+
canonicalSourcePath !== undefined &&
|
|
2268
|
+
!(await pathExists(canonicalSourcePath))
|
|
2269
|
+
) {
|
|
2270
|
+
throw new Error(`Missing canonical source: ${canonicalSource}`);
|
|
2271
|
+
}
|
|
1635
2272
|
return;
|
|
1636
2273
|
}
|
|
1637
2274
|
if (action.operation === "mirror") {
|
|
@@ -1718,23 +2355,27 @@ const summaryState = (summary) =>
|
|
|
1718
2355
|
failures: [],
|
|
1719
2356
|
};
|
|
1720
2357
|
|
|
2358
|
+
const neutralOmissionEvidence = ({ warning, ...omission }) => ({
|
|
2359
|
+
...omission,
|
|
2360
|
+
family: warning.family,
|
|
2361
|
+
reason: warning.reason,
|
|
2362
|
+
});
|
|
2363
|
+
|
|
1721
2364
|
const projectionEvidence = ({ adapter, projection, summary }) => {
|
|
1722
2365
|
const state = summaryState(summary);
|
|
1723
2366
|
return {
|
|
1724
2367
|
adapter: adapter.matrix.adapter,
|
|
1725
2368
|
matrixVersion: adapter.matrix.matrixVersion,
|
|
1726
2369
|
actions: projection.actions,
|
|
1727
|
-
warnings: [
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
],
|
|
1737
|
-
omissions: state.omissions,
|
|
2370
|
+
warnings: [],
|
|
2371
|
+
limitations: state.applied
|
|
2372
|
+
.filter(({ support }) => support === "degraded")
|
|
2373
|
+
.map(({ reason, trace }) => ({
|
|
2374
|
+
_tag: "HarnessCapabilityLimitation",
|
|
2375
|
+
reason,
|
|
2376
|
+
trace,
|
|
2377
|
+
})),
|
|
2378
|
+
omissions: state.omissions.map(neutralOmissionEvidence),
|
|
1738
2379
|
failures: state.failures,
|
|
1739
2380
|
};
|
|
1740
2381
|
};
|
|
@@ -1742,7 +2383,7 @@ const projectionEvidence = ({ adapter, projection, summary }) => {
|
|
|
1742
2383
|
const receiptStatus = (projections) =>
|
|
1743
2384
|
projections.some(({ failures }) => failures.length > 0)
|
|
1744
2385
|
? "failure"
|
|
1745
|
-
: projections.some(({ warnings
|
|
2386
|
+
: projections.some(({ warnings }) => warnings.length > 0)
|
|
1746
2387
|
? "partial"
|
|
1747
2388
|
: "success";
|
|
1748
2389
|
|
|
@@ -1940,16 +2581,20 @@ async function prepareProjectionApplication(projection) {
|
|
|
1940
2581
|
continue;
|
|
1941
2582
|
}
|
|
1942
2583
|
if (canonicalSourcePath !== undefined && !(await pathExists(canonicalSourcePath))) {
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
2584
|
+
if (isManagedCanonicalSource(canonicalSource)) {
|
|
2585
|
+
actions.push(action);
|
|
2586
|
+
} else {
|
|
2587
|
+
omissions.push({
|
|
2588
|
+
_tag: "HarnessApplicationOmission",
|
|
2589
|
+
support: "missing",
|
|
2590
|
+
trace: action.trace,
|
|
2591
|
+
warning: {
|
|
2592
|
+
_tag: "MissingCanonicalPromptWarning",
|
|
2593
|
+
family: "scoped-prompt",
|
|
2594
|
+
reason: `Missing canonical prompt source at ${canonicalSource}`,
|
|
2595
|
+
},
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
1953
2598
|
continue;
|
|
1954
2599
|
}
|
|
1955
2600
|
}
|
|
@@ -2381,8 +3026,9 @@ const contextPlanVersion = (contextPlan) =>
|
|
|
2381
3026
|
? contextPlan.version
|
|
2382
3027
|
: "unknown";
|
|
2383
3028
|
|
|
2384
|
-
async function main() {
|
|
3029
|
+
async function main({ publicationLock } = {}) {
|
|
2385
3030
|
operationRepoRootIdentity = await captureRepoRootIdentity("synchronize scaffold output");
|
|
3031
|
+
const manifestPreflight = await preflightScaffoldManifest();
|
|
2386
3032
|
await assertConfinedRegularFile(projectionReceiptPath);
|
|
2387
3033
|
const previousReceiptBytes = await readConfinedRegularFile(projectionReceiptPath);
|
|
2388
3034
|
try {
|
|
@@ -2402,72 +3048,83 @@ async function main() {
|
|
|
2402
3048
|
const loadedContextPlan = await readContextPlan();
|
|
2403
3049
|
const loadedProjectionPlan = await readProjectionPlan();
|
|
2404
3050
|
const application = await prepareHarnessApplication();
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
}
|
|
2409
|
-
const
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
3051
|
+
const renderedOutputSha256 = semanticJsonHash({
|
|
3052
|
+
availableHooks: application.availableHooks,
|
|
3053
|
+
rendered: application.rendered,
|
|
3054
|
+
});
|
|
3055
|
+
const publicationLease = await acquireProjectionPublicationLock(publicationLock);
|
|
3056
|
+
try {
|
|
3057
|
+
await assertScaffoldManifestPreflight(manifestPreflight);
|
|
3058
|
+
if (!loadedContextPlan.exists && !loadedProjectionPlan.exists) {
|
|
3059
|
+
await materializeLegacyHarnesses(application);
|
|
3060
|
+
return;
|
|
3061
|
+
}
|
|
3062
|
+
const contextPlan = loadedContextPlan.value;
|
|
3063
|
+
const suppliedProjectionPlan = loadedProjectionPlan.exists
|
|
3064
|
+
? validateProjectionPlan({ plan: loadedProjectionPlan.value, contextPlan })
|
|
3065
|
+
: undefined;
|
|
3066
|
+
const projected =
|
|
3067
|
+
suppliedProjectionPlan !== undefined
|
|
3068
|
+
? suppliedProjectionPlan.projections.map((projection) => {
|
|
3069
|
+
const adapter = adapters.find(
|
|
3070
|
+
({ matrix }) => matrix.adapter.id === projection.matrix.adapter.id,
|
|
3071
|
+
);
|
|
3072
|
+
if (adapter === undefined) throw new Error("Validated projection adapter is missing");
|
|
3073
|
+
return {
|
|
3074
|
+
adapter,
|
|
3075
|
+
projection: withLifecycleHookReconciliation(
|
|
3076
|
+
adapter,
|
|
3077
|
+
contextPlan,
|
|
3078
|
+
withManagedAgentCleanup(adapter, contextPlan, {
|
|
3079
|
+
actions: projection.actions,
|
|
3080
|
+
summary: projection.summary,
|
|
3081
|
+
}),
|
|
3082
|
+
),
|
|
3083
|
+
};
|
|
3084
|
+
})
|
|
3085
|
+
: adapters.map((adapter) => ({
|
|
2421
3086
|
adapter,
|
|
2422
3087
|
projection: withLifecycleHookReconciliation(
|
|
2423
3088
|
adapter,
|
|
2424
3089
|
contextPlan,
|
|
2425
|
-
withManagedAgentCleanup(adapter, contextPlan,
|
|
2426
|
-
actions: projection.actions,
|
|
2427
|
-
summary: projection.summary,
|
|
2428
|
-
}),
|
|
3090
|
+
withManagedAgentCleanup(adapter, contextPlan, projectSafely(adapter, contextPlan)),
|
|
2429
3091
|
),
|
|
2430
|
-
};
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
contextPlan,
|
|
2437
|
-
withManagedAgentCleanup(adapter, contextPlan, projectSafely(adapter, contextPlan)),
|
|
2438
|
-
),
|
|
2439
|
-
}));
|
|
2440
|
-
const applied = [];
|
|
2441
|
-
|
|
2442
|
-
for (const entry of projected) {
|
|
2443
|
-
const applicationProjection = await prepareProjectionApplication(entry.projection);
|
|
2444
|
-
const summary = await applyProjection({
|
|
2445
|
-
projection: applicationProjection,
|
|
2446
|
-
filesystem: { apply: (action) => applyHarnessAction(action, application) },
|
|
2447
|
-
});
|
|
2448
|
-
applied.push(
|
|
2449
|
-
projectionEvidence({
|
|
2450
|
-
adapter: entry.adapter,
|
|
3092
|
+
}));
|
|
3093
|
+
const applied = [];
|
|
3094
|
+
|
|
3095
|
+
for (const entry of projected) {
|
|
3096
|
+
const applicationProjection = await prepareProjectionApplication(entry.projection);
|
|
3097
|
+
const summary = await applyProjection({
|
|
2451
3098
|
projection: applicationProjection,
|
|
2452
|
-
|
|
2453
|
-
})
|
|
2454
|
-
|
|
2455
|
-
|
|
3099
|
+
filesystem: { apply: (action) => applyHarnessAction(action, application) },
|
|
3100
|
+
});
|
|
3101
|
+
applied.push(
|
|
3102
|
+
projectionEvidence({
|
|
3103
|
+
adapter: entry.adapter,
|
|
3104
|
+
projection: applicationProjection,
|
|
3105
|
+
summary,
|
|
3106
|
+
}),
|
|
3107
|
+
);
|
|
3108
|
+
}
|
|
2456
3109
|
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
3110
|
+
const receipt = {
|
|
3111
|
+
version: "1",
|
|
3112
|
+
contextPlanVersion: contextPlanVersion(contextPlan),
|
|
3113
|
+
renderedOutputSha256,
|
|
3114
|
+
status: receiptStatus(applied),
|
|
3115
|
+
projections: applied,
|
|
3116
|
+
copyFallbacks: [...currentCopyFallbacks.values()].toSorted((left, right) =>
|
|
3117
|
+
copyFallbackKey(left).localeCompare(copyFallbackKey(right)),
|
|
3118
|
+
),
|
|
3119
|
+
};
|
|
3120
|
+
await commitProjectionEvidence(manifestPreflight, receipt);
|
|
3121
|
+
if (receipt.status === "failure") {
|
|
3122
|
+
throw new Error(
|
|
3123
|
+
`Harness projection failed; inspect ${path.relative(repoRoot, projectionReceiptPath)}`,
|
|
3124
|
+
);
|
|
3125
|
+
}
|
|
3126
|
+
} finally {
|
|
3127
|
+
await releaseProjectionPublicationLock(publicationLease);
|
|
2471
3128
|
}
|
|
2472
3129
|
}
|
|
2473
3130
|
|