@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
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import {
|
|
5
5
|
accessSync,
|
|
6
|
+
closeSync,
|
|
6
7
|
constants,
|
|
7
8
|
existsSync,
|
|
9
|
+
fstatSync,
|
|
10
|
+
lstatSync,
|
|
8
11
|
mkdirSync,
|
|
12
|
+
openSync,
|
|
13
|
+
readSync,
|
|
9
14
|
readFileSync,
|
|
10
15
|
realpathSync,
|
|
11
16
|
writeFileSync,
|
|
@@ -69,7 +74,31 @@ function normalizeRelativePath(root, filePath, managedPaths, caseInsensitivePath
|
|
|
69
74
|
return null;
|
|
70
75
|
}
|
|
71
76
|
|
|
77
|
+
let canonicalRelativePath;
|
|
78
|
+
try {
|
|
79
|
+
canonicalRelativePath = path.relative(
|
|
80
|
+
realpathSync.native(root),
|
|
81
|
+
realpathSync.native(absolutePath),
|
|
82
|
+
);
|
|
83
|
+
if (
|
|
84
|
+
!canonicalRelativePath ||
|
|
85
|
+
canonicalRelativePath.startsWith("..") ||
|
|
86
|
+
path.isAbsolute(canonicalRelativePath)
|
|
87
|
+
) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
72
94
|
const normalizedPath = relativePath.split(path.sep).join("/");
|
|
95
|
+
const canonicalNormalizedPath = canonicalRelativePath.split(path.sep).join("/");
|
|
96
|
+
if (
|
|
97
|
+
managedPathKey(normalizedPath, caseInsensitivePaths) !==
|
|
98
|
+
managedPathKey(canonicalNormalizedPath, caseInsensitivePaths)
|
|
99
|
+
) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
73
102
|
const extension = path.extname(normalizedPath);
|
|
74
103
|
|
|
75
104
|
if (!formattableSuffixes.has(extension)) {
|
|
@@ -260,11 +289,13 @@ function formatCommandForPath(root, relativePath) {
|
|
|
260
289
|
nearestPythonProject(root, relativePath),
|
|
261
290
|
"ruff",
|
|
262
291
|
"format",
|
|
292
|
+
"--stdin-filename",
|
|
263
293
|
relativePath,
|
|
294
|
+
"-",
|
|
264
295
|
];
|
|
265
296
|
}
|
|
266
297
|
|
|
267
|
-
return toolCommand(root, "oxfmt", ["--
|
|
298
|
+
return toolCommand(root, "oxfmt", ["--stdin-filepath", relativePath]);
|
|
268
299
|
}
|
|
269
300
|
|
|
270
301
|
function lintCommandForPath(root, relativePath) {
|
|
@@ -277,7 +308,9 @@ function lintCommandForPath(root, relativePath) {
|
|
|
277
308
|
"ruff",
|
|
278
309
|
"check",
|
|
279
310
|
"--fix",
|
|
311
|
+
"--stdin-filename",
|
|
280
312
|
relativePath,
|
|
313
|
+
"-",
|
|
281
314
|
];
|
|
282
315
|
}
|
|
283
316
|
|
|
@@ -299,11 +332,7 @@ function normalizeManagedPath(filePath) {
|
|
|
299
332
|
}
|
|
300
333
|
|
|
301
334
|
const normalizedPath = path.posix.normalize(posixPath);
|
|
302
|
-
if (
|
|
303
|
-
normalizedPath === "." ||
|
|
304
|
-
normalizedPath === ".." ||
|
|
305
|
-
normalizedPath.startsWith("../")
|
|
306
|
-
) {
|
|
335
|
+
if (normalizedPath === "." || normalizedPath === ".." || normalizedPath.startsWith("../")) {
|
|
307
336
|
return null;
|
|
308
337
|
}
|
|
309
338
|
|
|
@@ -332,7 +361,299 @@ function loadManagedPaths(root, caseInsensitivePaths) {
|
|
|
332
361
|
return managedPaths;
|
|
333
362
|
}
|
|
334
363
|
|
|
335
|
-
function
|
|
364
|
+
function contentHash(content) {
|
|
365
|
+
return createHash("sha256").update(content).digest("hex");
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function readDescriptor(descriptor) {
|
|
369
|
+
const size = fstatSync(descriptor).size;
|
|
370
|
+
const content = Buffer.alloc(size);
|
|
371
|
+
let offset = 0;
|
|
372
|
+
|
|
373
|
+
while (offset < size) {
|
|
374
|
+
const bytesRead = readSync(descriptor, content, offset, size - offset, offset);
|
|
375
|
+
if (bytesRead === 0) {
|
|
376
|
+
throw new Error("Edited file changed while reading");
|
|
377
|
+
}
|
|
378
|
+
offset += bytesRead;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return content;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function sameRegularFile(filePath, opened) {
|
|
385
|
+
try {
|
|
386
|
+
const current = lstatSync(filePath);
|
|
387
|
+
return (
|
|
388
|
+
current.isFile() &&
|
|
389
|
+
current.nlink === 1 &&
|
|
390
|
+
current.dev === opened.dev &&
|
|
391
|
+
current.ino === opened.ino
|
|
392
|
+
);
|
|
393
|
+
} catch {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function openFormattingTarget(filePath, expectedFingerprint) {
|
|
399
|
+
let descriptor;
|
|
400
|
+
try {
|
|
401
|
+
const before = lstatSync(filePath);
|
|
402
|
+
if (!before.isFile() || before.nlink !== 1) {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
descriptor = openSync(filePath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
407
|
+
const opened = fstatSync(descriptor);
|
|
408
|
+
if (!opened.isFile() || opened.nlink !== 1 || !sameRegularFile(filePath, opened)) {
|
|
409
|
+
closeSync(descriptor);
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const content = readDescriptor(descriptor);
|
|
414
|
+
const fingerprint = contentHash(content);
|
|
415
|
+
if (typeof expectedFingerprint === "string" && fingerprint !== expectedFingerprint) {
|
|
416
|
+
closeSync(descriptor);
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return { content, descriptor, fingerprint, opened };
|
|
421
|
+
} catch {
|
|
422
|
+
if (descriptor !== undefined) {
|
|
423
|
+
closeSync(descriptor);
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function runTransformCommand(root, command, content) {
|
|
430
|
+
const [executable, ...args] = command;
|
|
431
|
+
const result = spawnSync(executable, args, {
|
|
432
|
+
cwd: root,
|
|
433
|
+
input: content,
|
|
434
|
+
maxBuffer: Math.max(16 * 1024 * 1024, content.length * 4),
|
|
435
|
+
stdio: ["pipe", "pipe", "inherit"],
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
return {
|
|
439
|
+
ok: result.status === 0,
|
|
440
|
+
output: result.error === undefined && Buffer.isBuffer(result.stdout) ? result.stdout : content,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const publicationWorkerScript = `
|
|
445
|
+
import { createHash } from "node:crypto";
|
|
446
|
+
import {
|
|
447
|
+
closeSync,
|
|
448
|
+
constants,
|
|
449
|
+
fchmodSync,
|
|
450
|
+
fstatSync,
|
|
451
|
+
fsyncSync,
|
|
452
|
+
linkSync,
|
|
453
|
+
lstatSync,
|
|
454
|
+
openSync,
|
|
455
|
+
readFileSync,
|
|
456
|
+
readSync,
|
|
457
|
+
renameSync,
|
|
458
|
+
statSync,
|
|
459
|
+
unlinkSync,
|
|
460
|
+
writeSync,
|
|
461
|
+
} from "node:fs";
|
|
462
|
+
|
|
463
|
+
const request = JSON.parse(process.argv[1]);
|
|
464
|
+
const content = readFileSync(0);
|
|
465
|
+
let claimIdentity;
|
|
466
|
+
let claimPath = request.claim;
|
|
467
|
+
let originalDescriptor;
|
|
468
|
+
let publishedDescriptor;
|
|
469
|
+
let publishedIdentity;
|
|
470
|
+
let stageDescriptor;
|
|
471
|
+
let stageIdentity;
|
|
472
|
+
let stagePath = request.stage;
|
|
473
|
+
|
|
474
|
+
const assertParentIdentity = () => {
|
|
475
|
+
const current = statSync(".");
|
|
476
|
+
if (current.dev !== request.parent.device || current.ino !== request.parent.inode) {
|
|
477
|
+
throw new Error("Formatting parent identity changed");
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
const sameRegularFile = (filePath, expected) => {
|
|
481
|
+
const current = lstatSync(filePath, { throwIfNoEntry: false });
|
|
482
|
+
return (
|
|
483
|
+
current !== undefined &&
|
|
484
|
+
current.isFile() &&
|
|
485
|
+
current.nlink === 1 &&
|
|
486
|
+
current.dev === expected.device &&
|
|
487
|
+
current.ino === expected.inode
|
|
488
|
+
);
|
|
489
|
+
};
|
|
490
|
+
const descriptorHash = (descriptor) => {
|
|
491
|
+
const size = fstatSync(descriptor).size;
|
|
492
|
+
const buffer = Buffer.alloc(size);
|
|
493
|
+
let offset = 0;
|
|
494
|
+
while (offset < size) {
|
|
495
|
+
const bytesRead = readSync(descriptor, buffer, offset, size - offset, offset);
|
|
496
|
+
if (bytesRead === 0) throw new Error("Formatting target changed while reading");
|
|
497
|
+
offset += bytesRead;
|
|
498
|
+
}
|
|
499
|
+
return createHash("sha256").update(buffer).digest("hex");
|
|
500
|
+
};
|
|
501
|
+
const closeDescriptors = () => {
|
|
502
|
+
if (publishedDescriptor !== undefined) closeSync(publishedDescriptor);
|
|
503
|
+
if (originalDescriptor !== undefined) closeSync(originalDescriptor);
|
|
504
|
+
if (stageDescriptor !== undefined) closeSync(stageDescriptor);
|
|
505
|
+
publishedDescriptor = undefined;
|
|
506
|
+
originalDescriptor = undefined;
|
|
507
|
+
stageDescriptor = undefined;
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
try {
|
|
511
|
+
assertParentIdentity();
|
|
512
|
+
stageDescriptor = openSync(
|
|
513
|
+
stagePath,
|
|
514
|
+
constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | (constants.O_NOFOLLOW ?? 0),
|
|
515
|
+
request.targetIdentity.mode,
|
|
516
|
+
);
|
|
517
|
+
const staged = fstatSync(stageDescriptor);
|
|
518
|
+
if (!staged.isFile() || staged.nlink !== 1) throw new Error("Formatting stage is unsafe");
|
|
519
|
+
stageIdentity = { device: staged.dev, inode: staged.ino };
|
|
520
|
+
let offset = 0;
|
|
521
|
+
while (offset < content.length) {
|
|
522
|
+
offset += writeSync(stageDescriptor, content, offset, content.length - offset, offset);
|
|
523
|
+
}
|
|
524
|
+
fchmodSync(stageDescriptor, request.targetIdentity.mode & 0o7777);
|
|
525
|
+
fsyncSync(stageDescriptor);
|
|
526
|
+
closeSync(stageDescriptor);
|
|
527
|
+
stageDescriptor = undefined;
|
|
528
|
+
assertParentIdentity();
|
|
529
|
+
|
|
530
|
+
originalDescriptor = openSync(
|
|
531
|
+
request.target,
|
|
532
|
+
constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),
|
|
533
|
+
);
|
|
534
|
+
const original = fstatSync(originalDescriptor);
|
|
535
|
+
if (
|
|
536
|
+
!original.isFile() ||
|
|
537
|
+
original.nlink !== 1 ||
|
|
538
|
+
original.dev !== request.targetIdentity.device ||
|
|
539
|
+
original.ino !== request.targetIdentity.inode ||
|
|
540
|
+
descriptorHash(originalDescriptor) !== request.fingerprint ||
|
|
541
|
+
!sameRegularFile(request.target, request.targetIdentity)
|
|
542
|
+
) {
|
|
543
|
+
throw new Error("Formatting target changed before publication");
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (lstatSync(claimPath, { throwIfNoEntry: false }) !== undefined) {
|
|
547
|
+
throw new Error("Formatting claim path already exists");
|
|
548
|
+
}
|
|
549
|
+
claimIdentity = request.targetIdentity;
|
|
550
|
+
renameSync(request.target, claimPath);
|
|
551
|
+
const claimed = lstatSync(claimPath);
|
|
552
|
+
claimIdentity = { device: claimed.dev, inode: claimed.ino };
|
|
553
|
+
if (
|
|
554
|
+
!sameRegularFile(claimPath, request.targetIdentity) ||
|
|
555
|
+
descriptorHash(originalDescriptor) !== request.fingerprint ||
|
|
556
|
+
lstatSync(request.target, { throwIfNoEntry: false }) !== undefined
|
|
557
|
+
) {
|
|
558
|
+
throw new Error("Formatting target changed while being claimed");
|
|
559
|
+
}
|
|
560
|
+
assertParentIdentity();
|
|
561
|
+
|
|
562
|
+
linkSync(stagePath, request.target);
|
|
563
|
+
publishedIdentity = stageIdentity;
|
|
564
|
+
unlinkSync(stagePath);
|
|
565
|
+
stagePath = undefined;
|
|
566
|
+
stageIdentity = undefined;
|
|
567
|
+
publishedDescriptor = openSync(
|
|
568
|
+
request.target,
|
|
569
|
+
constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),
|
|
570
|
+
);
|
|
571
|
+
const published = fstatSync(publishedDescriptor);
|
|
572
|
+
if (
|
|
573
|
+
!sameRegularFile(claimPath, request.targetIdentity) ||
|
|
574
|
+
descriptorHash(originalDescriptor) !== request.fingerprint ||
|
|
575
|
+
!published.isFile() ||
|
|
576
|
+
published.nlink !== 1 ||
|
|
577
|
+
published.dev !== publishedIdentity.device ||
|
|
578
|
+
published.ino !== publishedIdentity.inode ||
|
|
579
|
+
descriptorHash(publishedDescriptor) !== request.outputFingerprint ||
|
|
580
|
+
!sameRegularFile(request.target, publishedIdentity)
|
|
581
|
+
) {
|
|
582
|
+
throw new Error("Formatting target changed across publication");
|
|
583
|
+
}
|
|
584
|
+
assertParentIdentity();
|
|
585
|
+
|
|
586
|
+
closeDescriptors();
|
|
587
|
+
unlinkSync(claimPath);
|
|
588
|
+
claimPath = undefined;
|
|
589
|
+
claimIdentity = undefined;
|
|
590
|
+
publishedIdentity = undefined;
|
|
591
|
+
} catch (error) {
|
|
592
|
+
closeDescriptors();
|
|
593
|
+
if (claimIdentity !== undefined && claimPath !== undefined) {
|
|
594
|
+
try {
|
|
595
|
+
const claim = lstatSync(claimPath, { throwIfNoEntry: false });
|
|
596
|
+
if (
|
|
597
|
+
claim !== undefined &&
|
|
598
|
+
claim.dev === claimIdentity.device &&
|
|
599
|
+
claim.ino === claimIdentity.inode &&
|
|
600
|
+
claim.isFile() &&
|
|
601
|
+
lstatSync(request.target, { throwIfNoEntry: false }) === undefined
|
|
602
|
+
) {
|
|
603
|
+
linkSync(claimPath, request.target);
|
|
604
|
+
unlinkSync(claimPath);
|
|
605
|
+
claimPath = undefined;
|
|
606
|
+
}
|
|
607
|
+
} catch {
|
|
608
|
+
// Retain the exact claim when it cannot be restored without replacement.
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
if (stageIdentity !== undefined && stagePath !== undefined) {
|
|
612
|
+
try {
|
|
613
|
+
const stage = lstatSync(stagePath, { throwIfNoEntry: false });
|
|
614
|
+
if (
|
|
615
|
+
stage !== undefined &&
|
|
616
|
+
stage.dev === stageIdentity.device &&
|
|
617
|
+
stage.ino === stageIdentity.inode
|
|
618
|
+
) {
|
|
619
|
+
unlinkSync(stagePath);
|
|
620
|
+
stagePath = undefined;
|
|
621
|
+
}
|
|
622
|
+
} catch {
|
|
623
|
+
// A private-path collision is not producer-owned.
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
process.exitCode = 1;
|
|
627
|
+
}
|
|
628
|
+
`;
|
|
629
|
+
|
|
630
|
+
function publishFormattedContent(filePath, target, content) {
|
|
631
|
+
const directory = path.dirname(filePath);
|
|
632
|
+
const parent = lstatSync(directory);
|
|
633
|
+
if (!parent.isDirectory()) return false;
|
|
634
|
+
const suffix = randomUUID();
|
|
635
|
+
const request = {
|
|
636
|
+
claim: `.hi-format-claim-${suffix}.tmp`,
|
|
637
|
+
fingerprint: target.fingerprint,
|
|
638
|
+
outputFingerprint: contentHash(content),
|
|
639
|
+
parent: { device: parent.dev, inode: parent.ino },
|
|
640
|
+
stage: `.hi-format-stage-${suffix}.tmp`,
|
|
641
|
+
target: path.basename(filePath),
|
|
642
|
+
targetIdentity: {
|
|
643
|
+
device: target.opened.dev,
|
|
644
|
+
inode: target.opened.ino,
|
|
645
|
+
mode: target.opened.mode,
|
|
646
|
+
},
|
|
647
|
+
};
|
|
648
|
+
const result = spawnSync(
|
|
649
|
+
process.execPath,
|
|
650
|
+
["--input-type=module", "--eval", publicationWorkerScript, JSON.stringify(request)],
|
|
651
|
+
{ cwd: directory, input: content, stdio: ["pipe", "ignore", "ignore"] },
|
|
652
|
+
);
|
|
653
|
+
return result.error === undefined && result.status === 0;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
|
|
336
657
|
const caseSemantics = pathCaseSemantics(root);
|
|
337
658
|
if (caseSemantics === "unknown") {
|
|
338
659
|
return { format_failed: [], formatted: [], lint_failed: [] };
|
|
@@ -363,17 +684,48 @@ function formatAndLintFiles(root, filePaths) {
|
|
|
363
684
|
const lintFailed = [];
|
|
364
685
|
|
|
365
686
|
for (const relativePath of normalizedFiles) {
|
|
366
|
-
const
|
|
687
|
+
const expectedFingerprint = expectedFingerprints?.[relativePath];
|
|
688
|
+
if (expectedFingerprints !== null && typeof expectedFingerprint !== "string") {
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
367
691
|
|
|
368
|
-
|
|
692
|
+
const absolutePath = path.join(root, relativePath);
|
|
693
|
+
const target = openFormattingTarget(absolutePath, expectedFingerprint);
|
|
694
|
+
if (target === null) {
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// Keep mutating tools off the live path; stage output before claiming the validated target.
|
|
699
|
+
const formatResult = runTransformCommand(
|
|
700
|
+
root,
|
|
701
|
+
formatCommandForPath(root, relativePath),
|
|
702
|
+
target.content,
|
|
703
|
+
);
|
|
704
|
+
|
|
705
|
+
if (!formatResult.ok) {
|
|
706
|
+
closeSync(target.descriptor);
|
|
369
707
|
formatFailed.push(relativePath);
|
|
370
708
|
continue;
|
|
371
709
|
}
|
|
372
710
|
|
|
711
|
+
const lintCommand = lintCommandForPath(root, relativePath);
|
|
712
|
+
const lintResult =
|
|
713
|
+
lintCommand !== null && isPythonPath(relativePath)
|
|
714
|
+
? runTransformCommand(root, lintCommand, formatResult.output)
|
|
715
|
+
: null;
|
|
716
|
+
const formattedContent = lintResult?.ok ? lintResult.output : formatResult.output;
|
|
717
|
+
const published = publishFormattedContent(absolutePath, target, formattedContent);
|
|
718
|
+
closeSync(target.descriptor);
|
|
719
|
+
if (!published) {
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
|
|
373
723
|
formatted.push(relativePath);
|
|
374
724
|
|
|
375
|
-
|
|
376
|
-
|
|
725
|
+
if (
|
|
726
|
+
(lintResult !== null && !lintResult.ok) ||
|
|
727
|
+
(lintCommand !== null && lintResult === null && !runCommand(root, lintCommand).ok)
|
|
728
|
+
) {
|
|
377
729
|
lintFailed.push(relativePath);
|
|
378
730
|
}
|
|
379
731
|
}
|
|
@@ -475,9 +827,7 @@ function dirtyFiles(root) {
|
|
|
475
827
|
}
|
|
476
828
|
|
|
477
829
|
function fileHash(filePath) {
|
|
478
|
-
|
|
479
|
-
hash.update(readFileSync(filePath));
|
|
480
|
-
return hash.digest("hex");
|
|
830
|
+
return contentHash(readFileSync(filePath));
|
|
481
831
|
}
|
|
482
832
|
|
|
483
833
|
function codexStateFilePath(root, sessionId) {
|
|
@@ -622,7 +972,28 @@ function runCodexSnapshotMode(mode) {
|
|
|
622
972
|
|
|
623
973
|
const current = fingerprints(root);
|
|
624
974
|
pruneProcessedFingerprints(state, current);
|
|
625
|
-
const
|
|
975
|
+
const hasPatchCommand =
|
|
976
|
+
payload.tool_name === "apply_patch" && typeof payload.tool_input?.command === "string";
|
|
977
|
+
const patchedPaths = hasPatchCommand ? extractPatchedPaths(payload.tool_input.command, root) : [];
|
|
978
|
+
const pending = pendingCodexFiles(state, current);
|
|
979
|
+
const caseInsensitivePaths = pathCaseSemantics(root) === "case-insensitive";
|
|
980
|
+
const pendingPaths = new Map(
|
|
981
|
+
pending.map((relativePath) => [
|
|
982
|
+
managedPathKey(relativePath, caseInsensitivePaths),
|
|
983
|
+
relativePath,
|
|
984
|
+
]),
|
|
985
|
+
);
|
|
986
|
+
const touched = hasPatchCommand
|
|
987
|
+
? [
|
|
988
|
+
...new Set(
|
|
989
|
+
patchedPaths
|
|
990
|
+
.map((relativePath) =>
|
|
991
|
+
pendingPaths.get(managedPathKey(relativePath, caseInsensitivePaths)),
|
|
992
|
+
)
|
|
993
|
+
.filter(Boolean),
|
|
994
|
+
),
|
|
995
|
+
]
|
|
996
|
+
: pending;
|
|
626
997
|
|
|
627
998
|
if (toolUseId) {
|
|
628
999
|
state.lastToolUseId = toolUseId;
|
|
@@ -633,7 +1004,7 @@ function runCodexSnapshotMode(mode) {
|
|
|
633
1004
|
return;
|
|
634
1005
|
}
|
|
635
1006
|
|
|
636
|
-
const summary = formatAndLintFiles(root, touched);
|
|
1007
|
+
const summary = formatAndLintFiles(root, touched, current);
|
|
637
1008
|
updateProcessedFingerprints(root, state, summary.formatted);
|
|
638
1009
|
saveCodexState(stateFile, state);
|
|
639
1010
|
|
|
@@ -692,9 +1063,9 @@ function extractPatchedPaths(patchText, worktree) {
|
|
|
692
1063
|
return paths;
|
|
693
1064
|
}
|
|
694
1065
|
|
|
695
|
-
function editedPathsForTool(input,
|
|
1066
|
+
function editedPathsForTool(input, worktree) {
|
|
696
1067
|
const toolName = input?.tool;
|
|
697
|
-
const args =
|
|
1068
|
+
const args = input?.args ?? {};
|
|
698
1069
|
|
|
699
1070
|
if (toolName === "apply_patch") {
|
|
700
1071
|
return extractPatchedPaths(args.patchText, worktree);
|
|
@@ -715,12 +1086,12 @@ function parseSummary(stdout) {
|
|
|
715
1086
|
|
|
716
1087
|
export const FormatAndLintPlugin = async ({ client, worktree }) => {
|
|
717
1088
|
return {
|
|
718
|
-
"tool.execute.after": async (input
|
|
1089
|
+
"tool.execute.after": async (input) => {
|
|
719
1090
|
if (!["edit", "write", "multiedit", "apply_patch"].includes(input.tool)) {
|
|
720
1091
|
return;
|
|
721
1092
|
}
|
|
722
1093
|
|
|
723
|
-
const editedPaths = [...new Set(editedPathsForTool(input,
|
|
1094
|
+
const editedPaths = [...new Set(editedPathsForTool(input, worktree))].filter(Boolean);
|
|
724
1095
|
|
|
725
1096
|
if (editedPaths.length === 0) {
|
|
726
1097
|
return;
|
|
@@ -63,21 +63,6 @@ const openCodeProject = ({ scopeId, contribution }) => {
|
|
|
63
63
|
target: `.opencode/plugins/${contributionId}.mjs`,
|
|
64
64
|
contributionId,
|
|
65
65
|
},
|
|
66
|
-
{
|
|
67
|
-
id: `opencode:lifecycle-hook:${scopeId}:${contributionId}:configure`,
|
|
68
|
-
operation: "merge-json",
|
|
69
|
-
target: "opencode.json",
|
|
70
|
-
value: {
|
|
71
|
-
$schema: "https://opencode.ai/config.json",
|
|
72
|
-
formatter: {
|
|
73
|
-
"harness-format-edited-file": {
|
|
74
|
-
command: ["node", ".agents/hooks/format-edited-file.mjs", "files", "$FILE"],
|
|
75
|
-
extensions: [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs", ".json", ".py"],
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
contributionId,
|
|
80
|
-
},
|
|
81
66
|
];
|
|
82
67
|
case "subagent-template":
|
|
83
68
|
return [
|
|
@@ -26,21 +26,6 @@
|
|
|
26
26
|
"target": ".opencode/plugins/format-edited-file.mjs",
|
|
27
27
|
"contributionId": "format-edited-file"
|
|
28
28
|
},
|
|
29
|
-
{
|
|
30
|
-
"id": "opencode:lifecycle-hook:root:format-edited-file:configure",
|
|
31
|
-
"operation": "merge-json",
|
|
32
|
-
"target": "opencode.json",
|
|
33
|
-
"value": {
|
|
34
|
-
"$schema": "https://opencode.ai/config.json",
|
|
35
|
-
"formatter": {
|
|
36
|
-
"harness-format-edited-file": {
|
|
37
|
-
"command": ["node", ".agents/hooks/format-edited-file.mjs", "files", "$FILE"],
|
|
38
|
-
"extensions": [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs", ".json", ".py"]
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
"contributionId": "format-edited-file"
|
|
43
|
-
},
|
|
44
29
|
{
|
|
45
30
|
"id": "opencode:subagent-template:root:code-review",
|
|
46
31
|
"operation": "render",
|