@lazyingart/agintiflow 0.20.307 → 0.20.309
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/package.json +1 -1
- package/scripts/smoke-dynamic-step-budget.js +576 -0
- package/src/agent-runner.js +205 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lazyingart/agintiflow",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.309",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AgInTiFlow is a project-aware agent workspace for hybrid wet-dry R&D, hardware-aware intelligence, software automation, and industrial workflows.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -7348,6 +7348,31 @@ try {
|
|
|
7348
7348
|
"missing-artifact-commit"
|
|
7349
7349
|
);
|
|
7350
7350
|
await fs.mkdir(missingArtifactCommitWorkspace, { recursive: true });
|
|
7351
|
+
const documentEvidenceWorkspace = path.join(
|
|
7352
|
+
tempRoot,
|
|
7353
|
+
"document-evidence"
|
|
7354
|
+
);
|
|
7355
|
+
await fs.mkdir(documentEvidenceWorkspace, { recursive: true });
|
|
7356
|
+
await fs.writeFile(
|
|
7357
|
+
path.join(documentEvidenceWorkspace, "daily_memo.pdf"),
|
|
7358
|
+
"%PDF-1.4\n% current task generated PDF evidence\n",
|
|
7359
|
+
"utf8"
|
|
7360
|
+
);
|
|
7361
|
+
await fs.writeFile(
|
|
7362
|
+
path.join(documentEvidenceWorkspace, "retained_memo.pdf"),
|
|
7363
|
+
"%PDF-1.4\n% retained same-task PDF evidence\n",
|
|
7364
|
+
"utf8"
|
|
7365
|
+
);
|
|
7366
|
+
await fs.writeFile(
|
|
7367
|
+
path.join(documentEvidenceWorkspace, "stale-root.pdf"),
|
|
7368
|
+
"%PDF-1.4\n% wrong-task stale PDF evidence\n",
|
|
7369
|
+
"utf8"
|
|
7370
|
+
);
|
|
7371
|
+
await fs.writeFile(
|
|
7372
|
+
path.join(documentEvidenceWorkspace, "retained_memo.tex"),
|
|
7373
|
+
"\\documentclass{article}\n\\begin{document}\nRetained memo.\n\\end{document}\n",
|
|
7374
|
+
"utf8"
|
|
7375
|
+
);
|
|
7351
7376
|
const missingArtifactCommitState = {
|
|
7352
7377
|
goal:
|
|
7353
7378
|
"Create editable memo.tex and compiled mobile-readable memo.pdf, verify both, and commit only the intentional work.",
|
|
@@ -7471,6 +7496,557 @@ try {
|
|
|
7471
7496
|
precommitDocumentQualityState.meta.completionEvidenceRepair === undefined,
|
|
7472
7497
|
"a passing pre-commit document check did not clear its bounded repair marker"
|
|
7473
7498
|
);
|
|
7499
|
+
const currentGoalGeneratedDocumentState = {
|
|
7500
|
+
goal:
|
|
7501
|
+
"Read TASK.md, produce a verified PDF memo for the current task, and commit only the intentional work.",
|
|
7502
|
+
messages: [],
|
|
7503
|
+
meta: {
|
|
7504
|
+
taskProfile: "writing",
|
|
7505
|
+
goalContract: {
|
|
7506
|
+
revision: 5,
|
|
7507
|
+
activeGoalRevision: 5,
|
|
7508
|
+
activeGoal:
|
|
7509
|
+
"Read TASK.md, produce a verified PDF memo for the current task, and commit only the intentional work.",
|
|
7510
|
+
},
|
|
7511
|
+
projectVerification: {
|
|
7512
|
+
mutationRevision: 12,
|
|
7513
|
+
privateMutationRevision: 0,
|
|
7514
|
+
mutationHistory: [
|
|
7515
|
+
{
|
|
7516
|
+
revision: 8,
|
|
7517
|
+
at: "2026-09-01T09:00:00.000Z",
|
|
7518
|
+
toolName: "run_command",
|
|
7519
|
+
paths: ["stale-root.pdf"],
|
|
7520
|
+
goalRevision: 4,
|
|
7521
|
+
},
|
|
7522
|
+
{
|
|
7523
|
+
revision: 11,
|
|
7524
|
+
at: "2026-09-01T09:05:00.000Z",
|
|
7525
|
+
toolName: "write_file",
|
|
7526
|
+
paths: ["daily_memo.tex"],
|
|
7527
|
+
goalRevision: 5,
|
|
7528
|
+
},
|
|
7529
|
+
{
|
|
7530
|
+
revision: 12,
|
|
7531
|
+
at: "2026-09-01T09:06:00.000Z",
|
|
7532
|
+
toolName: "run_command",
|
|
7533
|
+
paths: [
|
|
7534
|
+
"daily_memo.pdf",
|
|
7535
|
+
"daily_memo.aux",
|
|
7536
|
+
"/tmp/escape.pdf",
|
|
7537
|
+
".env.pdf",
|
|
7538
|
+
"secrets/hidden.pdf",
|
|
7539
|
+
],
|
|
7540
|
+
goalRevision: 5,
|
|
7541
|
+
},
|
|
7542
|
+
],
|
|
7543
|
+
},
|
|
7544
|
+
},
|
|
7545
|
+
};
|
|
7546
|
+
let currentGoalDocumentValidatorInput = null;
|
|
7547
|
+
const currentGoalDocumentAssessment = await documentQualityCommitAssessment(
|
|
7548
|
+
currentGoalGeneratedDocumentState,
|
|
7549
|
+
"run_command",
|
|
7550
|
+
{ command: "git add -- daily_memo.tex daily_memo.pdf && git commit -m memo" },
|
|
7551
|
+
{
|
|
7552
|
+
commandCwd: documentEvidenceWorkspace,
|
|
7553
|
+
taskProfile: "writing",
|
|
7554
|
+
documentArtifactValidator: async (input) => {
|
|
7555
|
+
currentGoalDocumentValidatorInput = input;
|
|
7556
|
+
return {
|
|
7557
|
+
ok: true,
|
|
7558
|
+
checked: true,
|
|
7559
|
+
artifacts: [{ path: "daily_memo.pdf" }],
|
|
7560
|
+
defects: [],
|
|
7561
|
+
reason: "Independent document checks passed for daily_memo.pdf.",
|
|
7562
|
+
};
|
|
7563
|
+
},
|
|
7564
|
+
}
|
|
7565
|
+
);
|
|
7566
|
+
assert(
|
|
7567
|
+
currentGoalDocumentAssessment?.ok === true &&
|
|
7568
|
+
currentGoalDocumentValidatorInput?.exactOutputPaths?.includes(
|
|
7569
|
+
"daily_memo.pdf"
|
|
7570
|
+
) &&
|
|
7571
|
+
!currentGoalDocumentValidatorInput.exactOutputPaths.includes(
|
|
7572
|
+
"stale-root.pdf"
|
|
7573
|
+
) &&
|
|
7574
|
+
!currentGoalDocumentValidatorInput.exactOutputPaths.includes(
|
|
7575
|
+
"daily_memo.aux"
|
|
7576
|
+
) &&
|
|
7577
|
+
!currentGoalDocumentValidatorInput.exactOutputPaths.includes(
|
|
7578
|
+
"secrets/hidden.pdf"
|
|
7579
|
+
),
|
|
7580
|
+
`a current-goal generated root PDF was not discovered safely for pre-commit validation: ${JSON.stringify(
|
|
7581
|
+
currentGoalDocumentValidatorInput
|
|
7582
|
+
)}`
|
|
7583
|
+
);
|
|
7584
|
+
const resumedTaskGoal =
|
|
7585
|
+
"Read TASK.md and complete it carefully. Use the complete chat history, verify the finished PDF, and leave the repository clean.";
|
|
7586
|
+
const resumedTaskHash = crypto
|
|
7587
|
+
.createHash("sha256")
|
|
7588
|
+
.update(resumedTaskGoal)
|
|
7589
|
+
.digest("hex");
|
|
7590
|
+
const sameTaskResumeDocumentState = {
|
|
7591
|
+
goal:
|
|
7592
|
+
"Continue the same task. Reuse the existing verified source and PDF unless the diagnostic finds a real defect, then commit cleanly.",
|
|
7593
|
+
messages: [],
|
|
7594
|
+
meta: {
|
|
7595
|
+
taskProfile: "writing",
|
|
7596
|
+
goalContract: {
|
|
7597
|
+
version: 3,
|
|
7598
|
+
revision: 2,
|
|
7599
|
+
activeGoalRevision: 2,
|
|
7600
|
+
taskGoal: resumedTaskGoal,
|
|
7601
|
+
activeGoal:
|
|
7602
|
+
"Continue the same task. Reuse the existing verified source and PDF unless the diagnostic finds a real defect, then commit cleanly.",
|
|
7603
|
+
currentRequest:
|
|
7604
|
+
"Continue the same task. Reuse the existing verified source and PDF unless the diagnostic finds a real defect, then commit cleanly.",
|
|
7605
|
+
taskRelation: "same-task",
|
|
7606
|
+
history: [
|
|
7607
|
+
{
|
|
7608
|
+
revision: 1,
|
|
7609
|
+
kind: "initial",
|
|
7610
|
+
hash: resumedTaskHash,
|
|
7611
|
+
preview: resumedTaskGoal,
|
|
7612
|
+
},
|
|
7613
|
+
{
|
|
7614
|
+
revision: 2,
|
|
7615
|
+
kind: "same-task-continuation",
|
|
7616
|
+
relation: "same-task",
|
|
7617
|
+
hash: crypto
|
|
7618
|
+
.createHash("sha256")
|
|
7619
|
+
.update(
|
|
7620
|
+
"Continue the same task. Reuse the existing verified source and PDF unless the diagnostic finds a real defect, then commit cleanly."
|
|
7621
|
+
)
|
|
7622
|
+
.digest("hex"),
|
|
7623
|
+
taskHash: resumedTaskHash,
|
|
7624
|
+
previousHash: resumedTaskHash,
|
|
7625
|
+
},
|
|
7626
|
+
],
|
|
7627
|
+
},
|
|
7628
|
+
projectVerification: {
|
|
7629
|
+
mutationRevision: 6,
|
|
7630
|
+
privateMutationRevision: 0,
|
|
7631
|
+
mutationHistory: [
|
|
7632
|
+
{
|
|
7633
|
+
revision: 2,
|
|
7634
|
+
at: "2026-09-01T10:00:00.000Z",
|
|
7635
|
+
toolName: "run_command",
|
|
7636
|
+
paths: ["retained_memo.pdf"],
|
|
7637
|
+
commandCategory: "toolchain",
|
|
7638
|
+
goalRevision: 1,
|
|
7639
|
+
taskHash: resumedTaskHash,
|
|
7640
|
+
},
|
|
7641
|
+
{
|
|
7642
|
+
revision: 3,
|
|
7643
|
+
at: "2026-09-01T10:01:00.000Z",
|
|
7644
|
+
toolName: "run_command",
|
|
7645
|
+
paths: ["stale-root.pdf"],
|
|
7646
|
+
commandCategory: "toolchain",
|
|
7647
|
+
goalRevision: 1,
|
|
7648
|
+
taskHash: "different-task",
|
|
7649
|
+
},
|
|
7650
|
+
{
|
|
7651
|
+
revision: 4,
|
|
7652
|
+
at: "2026-09-01T10:02:00.000Z",
|
|
7653
|
+
toolName: "run_command",
|
|
7654
|
+
paths: ["missing-retained.pdf"],
|
|
7655
|
+
commandCategory: "toolchain",
|
|
7656
|
+
goalRevision: 1,
|
|
7657
|
+
taskHash: resumedTaskHash,
|
|
7658
|
+
},
|
|
7659
|
+
{
|
|
7660
|
+
revision: 5,
|
|
7661
|
+
at: "2026-09-01T10:03:00.000Z",
|
|
7662
|
+
toolName: "apply_patch",
|
|
7663
|
+
paths: ["TASK.md"],
|
|
7664
|
+
patch: {
|
|
7665
|
+
path: "TASK.md",
|
|
7666
|
+
searchHash: "before-task-touch",
|
|
7667
|
+
replaceHash: "temporary-task-touch",
|
|
7668
|
+
},
|
|
7669
|
+
goalRevision: 2,
|
|
7670
|
+
taskHash: resumedTaskHash,
|
|
7671
|
+
},
|
|
7672
|
+
{
|
|
7673
|
+
revision: 6,
|
|
7674
|
+
at: "2026-09-01T10:04:00.000Z",
|
|
7675
|
+
toolName: "apply_patch",
|
|
7676
|
+
paths: ["TASK.md"],
|
|
7677
|
+
patch: {
|
|
7678
|
+
path: "TASK.md",
|
|
7679
|
+
searchHash: "temporary-task-touch",
|
|
7680
|
+
replaceHash: "before-task-touch",
|
|
7681
|
+
},
|
|
7682
|
+
goalRevision: 2,
|
|
7683
|
+
taskHash: resumedTaskHash,
|
|
7684
|
+
},
|
|
7685
|
+
],
|
|
7686
|
+
},
|
|
7687
|
+
},
|
|
7688
|
+
};
|
|
7689
|
+
let sameTaskResumeValidatorInput = null;
|
|
7690
|
+
const sameTaskResumeAssessment = await documentQualityCommitAssessment(
|
|
7691
|
+
sameTaskResumeDocumentState,
|
|
7692
|
+
"run_command",
|
|
7693
|
+
{ command: "git add -- retained_memo.pdf && git commit -m memo" },
|
|
7694
|
+
{
|
|
7695
|
+
commandCwd: documentEvidenceWorkspace,
|
|
7696
|
+
taskProfile: "writing",
|
|
7697
|
+
documentArtifactValidator: async (input) => {
|
|
7698
|
+
sameTaskResumeValidatorInput = input;
|
|
7699
|
+
return {
|
|
7700
|
+
ok: true,
|
|
7701
|
+
checked: true,
|
|
7702
|
+
artifacts: [{ path: "retained_memo.pdf" }],
|
|
7703
|
+
defects: [],
|
|
7704
|
+
reason:
|
|
7705
|
+
"Independent document checks passed for retained_memo.pdf.",
|
|
7706
|
+
};
|
|
7707
|
+
},
|
|
7708
|
+
}
|
|
7709
|
+
);
|
|
7710
|
+
assert(
|
|
7711
|
+
sameTaskResumeAssessment?.ok === true &&
|
|
7712
|
+
sameTaskResumeValidatorInput?.exactOutputPaths?.includes(
|
|
7713
|
+
"retained_memo.pdf"
|
|
7714
|
+
) &&
|
|
7715
|
+
!sameTaskResumeValidatorInput.exactOutputPaths.includes(
|
|
7716
|
+
"stale-root.pdf"
|
|
7717
|
+
) &&
|
|
7718
|
+
!sameTaskResumeValidatorInput.exactOutputPaths.includes(
|
|
7719
|
+
"missing-retained.pdf"
|
|
7720
|
+
) &&
|
|
7721
|
+
sameTaskResumeDocumentState.meta.completionEvidenceRepair === undefined,
|
|
7722
|
+
`same-task resume did not preserve the prior verified document artifact safely: ${JSON.stringify({
|
|
7723
|
+
assessment: sameTaskResumeAssessment,
|
|
7724
|
+
input: sameTaskResumeValidatorInput,
|
|
7725
|
+
repair: sameTaskResumeDocumentState.meta.completionEvidenceRepair,
|
|
7726
|
+
})}`
|
|
7727
|
+
);
|
|
7728
|
+
const missingMutationHashState = structuredClone(sameTaskResumeDocumentState);
|
|
7729
|
+
delete missingMutationHashState.meta.projectVerification.mutationHistory[0]
|
|
7730
|
+
.taskHash;
|
|
7731
|
+
let missingMutationHashValidatorInput = null;
|
|
7732
|
+
const missingMutationHashAssessment = await documentQualityCommitAssessment(
|
|
7733
|
+
missingMutationHashState,
|
|
7734
|
+
"run_command",
|
|
7735
|
+
{ command: "git add -- retained_memo.pdf && git commit -m memo" },
|
|
7736
|
+
{
|
|
7737
|
+
commandCwd: documentEvidenceWorkspace,
|
|
7738
|
+
taskProfile: "writing",
|
|
7739
|
+
documentArtifactValidator: async (input) => {
|
|
7740
|
+
missingMutationHashValidatorInput = input;
|
|
7741
|
+
return {
|
|
7742
|
+
ok: false,
|
|
7743
|
+
checked: true,
|
|
7744
|
+
artifacts: [],
|
|
7745
|
+
defects: [{ code: "missing-document-artifact" }],
|
|
7746
|
+
reason:
|
|
7747
|
+
"No readable DOCX or PDF artifact was found for the completed document task.",
|
|
7748
|
+
};
|
|
7749
|
+
},
|
|
7750
|
+
}
|
|
7751
|
+
);
|
|
7752
|
+
assert(
|
|
7753
|
+
missingMutationHashAssessment?.ok === false &&
|
|
7754
|
+
missingMutationHashAssessment.category ===
|
|
7755
|
+
"document-quality-incomplete" &&
|
|
7756
|
+
!missingMutationHashValidatorInput?.exactOutputPaths?.includes(
|
|
7757
|
+
"retained_memo.pdf"
|
|
7758
|
+
),
|
|
7759
|
+
`a cross-revision retained PDF with missing mutation task hash was accepted: ${JSON.stringify({
|
|
7760
|
+
assessment: missingMutationHashAssessment,
|
|
7761
|
+
input: missingMutationHashValidatorInput,
|
|
7762
|
+
})}`
|
|
7763
|
+
);
|
|
7764
|
+
const missingContinuationHashState = structuredClone(
|
|
7765
|
+
sameTaskResumeDocumentState
|
|
7766
|
+
);
|
|
7767
|
+
delete missingContinuationHashState.meta.goalContract.history[1].taskHash;
|
|
7768
|
+
let missingContinuationHashValidatorInput = null;
|
|
7769
|
+
const missingContinuationHashAssessment =
|
|
7770
|
+
await documentQualityCommitAssessment(
|
|
7771
|
+
missingContinuationHashState,
|
|
7772
|
+
"run_command",
|
|
7773
|
+
{ command: "git add -- retained_memo.pdf && git commit -m memo" },
|
|
7774
|
+
{
|
|
7775
|
+
commandCwd: documentEvidenceWorkspace,
|
|
7776
|
+
taskProfile: "writing",
|
|
7777
|
+
documentArtifactValidator: async (input) => {
|
|
7778
|
+
missingContinuationHashValidatorInput = input;
|
|
7779
|
+
return {
|
|
7780
|
+
ok: false,
|
|
7781
|
+
checked: true,
|
|
7782
|
+
artifacts: [],
|
|
7783
|
+
defects: [{ code: "missing-document-artifact" }],
|
|
7784
|
+
reason:
|
|
7785
|
+
"No readable DOCX or PDF artifact was found for the completed document task.",
|
|
7786
|
+
};
|
|
7787
|
+
},
|
|
7788
|
+
}
|
|
7789
|
+
);
|
|
7790
|
+
assert(
|
|
7791
|
+
missingContinuationHashAssessment?.ok === false &&
|
|
7792
|
+
missingContinuationHashAssessment.category ===
|
|
7793
|
+
"document-quality-incomplete" &&
|
|
7794
|
+
!missingContinuationHashValidatorInput?.exactOutputPaths?.includes(
|
|
7795
|
+
"retained_memo.pdf"
|
|
7796
|
+
),
|
|
7797
|
+
`a cross-revision retained PDF with missing same-task continuation hash was accepted: ${JSON.stringify({
|
|
7798
|
+
assessment: missingContinuationHashAssessment,
|
|
7799
|
+
input: missingContinuationHashValidatorInput,
|
|
7800
|
+
})}`
|
|
7801
|
+
);
|
|
7802
|
+
const staleSourceResumeState = structuredClone(sameTaskResumeDocumentState);
|
|
7803
|
+
staleSourceResumeState.meta.projectVerification = {
|
|
7804
|
+
mutationRevision: 3,
|
|
7805
|
+
privateMutationRevision: 0,
|
|
7806
|
+
mutationHistory: [
|
|
7807
|
+
{
|
|
7808
|
+
revision: 2,
|
|
7809
|
+
at: "2026-09-01T10:00:00.000Z",
|
|
7810
|
+
toolName: "run_command",
|
|
7811
|
+
paths: ["retained_memo.pdf"],
|
|
7812
|
+
commandCategory: "toolchain",
|
|
7813
|
+
goalRevision: 1,
|
|
7814
|
+
taskHash: resumedTaskHash,
|
|
7815
|
+
},
|
|
7816
|
+
{
|
|
7817
|
+
revision: 3,
|
|
7818
|
+
at: "2026-09-01T10:05:00.000Z",
|
|
7819
|
+
toolName: "apply_patch",
|
|
7820
|
+
paths: ["retained_memo.tex"],
|
|
7821
|
+
patch: {
|
|
7822
|
+
path: "retained_memo.tex",
|
|
7823
|
+
searchHash: "old-retained-source",
|
|
7824
|
+
replaceHash: "changed-retained-source",
|
|
7825
|
+
},
|
|
7826
|
+
goalRevision: 2,
|
|
7827
|
+
taskHash: resumedTaskHash,
|
|
7828
|
+
},
|
|
7829
|
+
],
|
|
7830
|
+
};
|
|
7831
|
+
let staleSourceValidatorInput = null;
|
|
7832
|
+
const staleSourceAssessment = await documentQualityCommitAssessment(
|
|
7833
|
+
staleSourceResumeState,
|
|
7834
|
+
"run_command",
|
|
7835
|
+
{ command: "git add -- retained_memo.tex retained_memo.pdf && git commit -m memo" },
|
|
7836
|
+
{
|
|
7837
|
+
commandCwd: documentEvidenceWorkspace,
|
|
7838
|
+
taskProfile: "writing",
|
|
7839
|
+
documentArtifactValidator: async (input) => {
|
|
7840
|
+
staleSourceValidatorInput = input;
|
|
7841
|
+
return {
|
|
7842
|
+
ok: false,
|
|
7843
|
+
checked: true,
|
|
7844
|
+
artifacts: [],
|
|
7845
|
+
defects: [{ code: "missing-document-artifact" }],
|
|
7846
|
+
reason:
|
|
7847
|
+
"No readable DOCX or PDF artifact was found for the completed document task.",
|
|
7848
|
+
};
|
|
7849
|
+
},
|
|
7850
|
+
}
|
|
7851
|
+
);
|
|
7852
|
+
assert(
|
|
7853
|
+
staleSourceAssessment?.ok === false &&
|
|
7854
|
+
staleSourceAssessment.category === "document-quality-incomplete" &&
|
|
7855
|
+
!staleSourceValidatorInput?.exactOutputPaths?.includes(
|
|
7856
|
+
"retained_memo.pdf"
|
|
7857
|
+
) &&
|
|
7858
|
+
staleSourceResumeState.meta.completionEvidenceRepair
|
|
7859
|
+
?.documentArtifactGenerationRequired === true &&
|
|
7860
|
+
staleSourceResumeState.meta.completionEvidenceRepair
|
|
7861
|
+
?.documentArtifactProducerCommand.includes("retained_memo.tex"),
|
|
7862
|
+
`a retained prior PDF survived a later same-task source mutation or failed to keep producer repair active: ${JSON.stringify({
|
|
7863
|
+
assessment: staleSourceAssessment,
|
|
7864
|
+
input: staleSourceValidatorInput,
|
|
7865
|
+
repair: staleSourceResumeState.meta.completionEvidenceRepair,
|
|
7866
|
+
})}`
|
|
7867
|
+
);
|
|
7868
|
+
const differentGoalResumeState = structuredClone(sameTaskResumeDocumentState);
|
|
7869
|
+
differentGoalResumeState.goal =
|
|
7870
|
+
"Start a different memo task and create a new verified PDF.";
|
|
7871
|
+
differentGoalResumeState.meta.goalContract = {
|
|
7872
|
+
version: 3,
|
|
7873
|
+
revision: 2,
|
|
7874
|
+
activeGoalRevision: 2,
|
|
7875
|
+
taskGoal: "Start a different memo task and create a new verified PDF.",
|
|
7876
|
+
activeGoal: "Start a different memo task and create a new verified PDF.",
|
|
7877
|
+
currentRequest:
|
|
7878
|
+
"Start a different memo task and create a new verified PDF.",
|
|
7879
|
+
taskRelation: "different-task",
|
|
7880
|
+
history: [
|
|
7881
|
+
{
|
|
7882
|
+
revision: 1,
|
|
7883
|
+
kind: "initial",
|
|
7884
|
+
hash: resumedTaskHash,
|
|
7885
|
+
preview: resumedTaskGoal,
|
|
7886
|
+
},
|
|
7887
|
+
{
|
|
7888
|
+
revision: 2,
|
|
7889
|
+
kind: "new-task",
|
|
7890
|
+
relation: "different-task",
|
|
7891
|
+
hash: crypto
|
|
7892
|
+
.createHash("sha256")
|
|
7893
|
+
.update("Start a different memo task and create a new verified PDF.")
|
|
7894
|
+
.digest("hex"),
|
|
7895
|
+
},
|
|
7896
|
+
],
|
|
7897
|
+
};
|
|
7898
|
+
let differentGoalValidatorInput = null;
|
|
7899
|
+
const differentGoalAssessment = await documentQualityCommitAssessment(
|
|
7900
|
+
differentGoalResumeState,
|
|
7901
|
+
"run_command",
|
|
7902
|
+
{ command: "git add -- retained_memo.pdf && git commit -m memo" },
|
|
7903
|
+
{
|
|
7904
|
+
commandCwd: documentEvidenceWorkspace,
|
|
7905
|
+
taskProfile: "writing",
|
|
7906
|
+
documentArtifactValidator: async (input) => {
|
|
7907
|
+
differentGoalValidatorInput = input;
|
|
7908
|
+
return {
|
|
7909
|
+
ok: false,
|
|
7910
|
+
checked: true,
|
|
7911
|
+
artifacts: [],
|
|
7912
|
+
defects: [{ code: "missing-document-artifact" }],
|
|
7913
|
+
reason:
|
|
7914
|
+
"No readable DOCX or PDF artifact was found for the completed document task.",
|
|
7915
|
+
};
|
|
7916
|
+
},
|
|
7917
|
+
}
|
|
7918
|
+
);
|
|
7919
|
+
assert(
|
|
7920
|
+
differentGoalAssessment?.ok === false &&
|
|
7921
|
+
differentGoalAssessment.category === "document-quality-incomplete" &&
|
|
7922
|
+
!differentGoalValidatorInput?.exactOutputPaths?.includes(
|
|
7923
|
+
"retained_memo.pdf"
|
|
7924
|
+
),
|
|
7925
|
+
`a different task reused a prior same-root document artifact: ${JSON.stringify(
|
|
7926
|
+
differentGoalValidatorInput
|
|
7927
|
+
)}`
|
|
7928
|
+
);
|
|
7929
|
+
const unrelatedRootWorkspace = path.join(
|
|
7930
|
+
tempRoot,
|
|
7931
|
+
"unrelated-root-document"
|
|
7932
|
+
);
|
|
7933
|
+
await fs.mkdir(unrelatedRootWorkspace, { recursive: true });
|
|
7934
|
+
await fs.writeFile(
|
|
7935
|
+
path.join(unrelatedRootWorkspace, "unrelated.pdf"),
|
|
7936
|
+
"pre-existing root PDF that the current goal did not create",
|
|
7937
|
+
"utf8"
|
|
7938
|
+
);
|
|
7939
|
+
const unrelatedRootDocumentState = {
|
|
7940
|
+
goal:
|
|
7941
|
+
"Produce a verified PDF artifact for this task and commit the intentional work.",
|
|
7942
|
+
messages: [],
|
|
7943
|
+
meta: {
|
|
7944
|
+
taskProfile: "writing",
|
|
7945
|
+
goalContract: {
|
|
7946
|
+
revision: 6,
|
|
7947
|
+
activeGoalRevision: 6,
|
|
7948
|
+
activeGoal:
|
|
7949
|
+
"Produce a verified PDF artifact for this task and commit the intentional work.",
|
|
7950
|
+
},
|
|
7951
|
+
projectVerification: {
|
|
7952
|
+
mutationRevision: 4,
|
|
7953
|
+
privateMutationRevision: 0,
|
|
7954
|
+
mutationHistory: [
|
|
7955
|
+
{
|
|
7956
|
+
revision: 3,
|
|
7957
|
+
at: "2026-09-01T09:10:00.000Z",
|
|
7958
|
+
toolName: "run_command",
|
|
7959
|
+
paths: ["unrelated.pdf"],
|
|
7960
|
+
goalRevision: 5,
|
|
7961
|
+
},
|
|
7962
|
+
{
|
|
7963
|
+
revision: 4,
|
|
7964
|
+
at: "2026-09-01T09:12:00.000Z",
|
|
7965
|
+
toolName: "write_file",
|
|
7966
|
+
paths: ["notes.tex"],
|
|
7967
|
+
goalRevision: 6,
|
|
7968
|
+
},
|
|
7969
|
+
],
|
|
7970
|
+
},
|
|
7971
|
+
},
|
|
7972
|
+
};
|
|
7973
|
+
let unrelatedRootValidatorInput = null;
|
|
7974
|
+
const unrelatedRootAssessment = await documentQualityCommitAssessment(
|
|
7975
|
+
unrelatedRootDocumentState,
|
|
7976
|
+
"run_command",
|
|
7977
|
+
{ command: "git add -- notes.tex && git commit -m notes" },
|
|
7978
|
+
{
|
|
7979
|
+
commandCwd: unrelatedRootWorkspace,
|
|
7980
|
+
taskProfile: "writing",
|
|
7981
|
+
documentArtifactValidator: async (input) => {
|
|
7982
|
+
unrelatedRootValidatorInput = input;
|
|
7983
|
+
return {
|
|
7984
|
+
ok: false,
|
|
7985
|
+
checked: true,
|
|
7986
|
+
artifacts: [],
|
|
7987
|
+
defects: [{ code: "missing-document-artifact" }],
|
|
7988
|
+
reason: "No readable DOCX or PDF artifact was found for the completed document task.",
|
|
7989
|
+
};
|
|
7990
|
+
},
|
|
7991
|
+
}
|
|
7992
|
+
);
|
|
7993
|
+
assert(
|
|
7994
|
+
unrelatedRootAssessment?.ok === false &&
|
|
7995
|
+
unrelatedRootAssessment.category === "document-quality-incomplete" &&
|
|
7996
|
+
!unrelatedRootValidatorInput?.exactOutputPaths?.includes(
|
|
7997
|
+
"unrelated.pdf"
|
|
7998
|
+
),
|
|
7999
|
+
`an unrelated pre-existing root PDF was accepted as current-goal evidence: ${JSON.stringify(
|
|
8000
|
+
unrelatedRootValidatorInput
|
|
8001
|
+
)}`
|
|
8002
|
+
);
|
|
8003
|
+
const semanticGateDocumentState = structuredClone(
|
|
8004
|
+
currentGoalGeneratedDocumentState
|
|
8005
|
+
);
|
|
8006
|
+
semanticGateDocumentState.meta.scs = {
|
|
8007
|
+
taskContract: { exactInputPaths: ["TASK.md"] },
|
|
8008
|
+
};
|
|
8009
|
+
let semanticGateValidatorInput = null;
|
|
8010
|
+
const semanticGateAssessment = await documentQualityCommitAssessment(
|
|
8011
|
+
semanticGateDocumentState,
|
|
8012
|
+
"run_command",
|
|
8013
|
+
{ command: "git add -- daily_memo.tex daily_memo.pdf && git commit -m memo" },
|
|
8014
|
+
{
|
|
8015
|
+
commandCwd: documentEvidenceWorkspace,
|
|
8016
|
+
taskProfile: "writing",
|
|
8017
|
+
documentArtifactValidator: async (input) => {
|
|
8018
|
+
semanticGateValidatorInput = input;
|
|
8019
|
+
return {
|
|
8020
|
+
ok: false,
|
|
8021
|
+
checked: true,
|
|
8022
|
+
artifacts: [{ path: "daily_memo.pdf" }],
|
|
8023
|
+
defects: [{
|
|
8024
|
+
code: "source-topic-coverage-incomplete",
|
|
8025
|
+
path: "daily_memo.pdf",
|
|
8026
|
+
message: "The memo omitted current source-status facts.",
|
|
8027
|
+
}],
|
|
8028
|
+
reason: "daily_memo.pdf: The memo omitted current source-status facts.",
|
|
8029
|
+
};
|
|
8030
|
+
},
|
|
8031
|
+
}
|
|
8032
|
+
);
|
|
8033
|
+
assert(
|
|
8034
|
+
semanticGateAssessment?.ok === false &&
|
|
8035
|
+
semanticGateAssessment.category === "document-quality-incomplete" &&
|
|
8036
|
+
semanticGateDocumentState.meta.completionEvidenceRepair
|
|
8037
|
+
?.artifactQualityRepairRequired === true &&
|
|
8038
|
+
semanticGateDocumentState.meta.completionEvidenceRepair
|
|
8039
|
+
?.documentArtifactGenerationRequired !== true &&
|
|
8040
|
+
semanticGateValidatorInput?.exactOutputPaths?.includes(
|
|
8041
|
+
"daily_memo.pdf"
|
|
8042
|
+
) &&
|
|
8043
|
+
semanticGateValidatorInput?.exactInputPaths?.includes("TASK.md"),
|
|
8044
|
+
`current-goal artifact discovery bypassed source/status quality gates or reopened the missing-artifact loop: ${JSON.stringify({
|
|
8045
|
+
assessment: semanticGateAssessment,
|
|
8046
|
+
input: semanticGateValidatorInput,
|
|
8047
|
+
repair: semanticGateDocumentState.meta.completionEvidenceRepair,
|
|
8048
|
+
})}`
|
|
8049
|
+
);
|
|
7474
8050
|
await fs.writeFile(
|
|
7475
8051
|
path.join(missingArtifactCommitWorkspace, "TASK.md"),
|
|
7476
8052
|
[
|
package/src/agent-runner.js
CHANGED
|
@@ -10257,6 +10257,7 @@ export async function documentQualityCommitAssessment(
|
|
|
10257
10257
|
? contract.exactOutputPaths
|
|
10258
10258
|
: []),
|
|
10259
10259
|
...exactOutputPathsForState(state),
|
|
10260
|
+
...currentGoalDocumentArtifactPathsForState(state, config),
|
|
10260
10261
|
...(Array.isArray(config.taskOwnedCommitPaths)
|
|
10261
10262
|
? config.taskOwnedCommitPaths
|
|
10262
10263
|
: []),
|
|
@@ -14185,6 +14186,209 @@ function exactOutputPathsForState(state = {}) {
|
|
|
14185
14186
|
], exclusions).slice(0, 32);
|
|
14186
14187
|
}
|
|
14187
14188
|
|
|
14189
|
+
function currentGoalRevisionBelongsToActiveTask(state = {}, mutation = {}) {
|
|
14190
|
+
const goalContract = state.meta?.goalContract || {};
|
|
14191
|
+
const currentGoalRevision = Math.max(0, Number(goalContract.revision || 0));
|
|
14192
|
+
const mutationGoalRevision = Math.max(0, Number(mutation?.goalRevision || 0));
|
|
14193
|
+
if (
|
|
14194
|
+
currentGoalRevision <= 0 ||
|
|
14195
|
+
mutationGoalRevision <= 0 ||
|
|
14196
|
+
mutationGoalRevision > currentGoalRevision
|
|
14197
|
+
) {
|
|
14198
|
+
return false;
|
|
14199
|
+
}
|
|
14200
|
+
const taskGoal = String(goalContract.taskGoal || state.goal || "").trim();
|
|
14201
|
+
const currentTaskHash = taskGoal ? hashForLog(taskGoal) : "";
|
|
14202
|
+
const goalHistory = Array.isArray(goalContract.history)
|
|
14203
|
+
? goalContract.history
|
|
14204
|
+
: [];
|
|
14205
|
+
const mutationGoalEntry = goalHistory.find(
|
|
14206
|
+
(entry) => Number(entry?.revision || 0) === mutationGoalRevision
|
|
14207
|
+
);
|
|
14208
|
+
const mutationTaskHash = String(
|
|
14209
|
+
mutation?.taskHash ||
|
|
14210
|
+
mutationGoalEntry?.taskHash ||
|
|
14211
|
+
(mutationGoalEntry?.kind === "initial" ? mutationGoalEntry?.hash : "") ||
|
|
14212
|
+
""
|
|
14213
|
+
);
|
|
14214
|
+
if (
|
|
14215
|
+
currentTaskHash &&
|
|
14216
|
+
mutationTaskHash &&
|
|
14217
|
+
mutationTaskHash !== currentTaskHash
|
|
14218
|
+
) {
|
|
14219
|
+
return false;
|
|
14220
|
+
}
|
|
14221
|
+
if (mutationGoalRevision === currentGoalRevision) return true;
|
|
14222
|
+
const explicitMutationTaskHash = String(mutation?.taskHash || "");
|
|
14223
|
+
if (
|
|
14224
|
+
!currentTaskHash ||
|
|
14225
|
+
!explicitMutationTaskHash ||
|
|
14226
|
+
explicitMutationTaskHash !== currentTaskHash
|
|
14227
|
+
) {
|
|
14228
|
+
return false;
|
|
14229
|
+
}
|
|
14230
|
+
const interveningGoalEntries = goalHistory.filter((entry) => {
|
|
14231
|
+
const revision = Number(entry?.revision || 0);
|
|
14232
|
+
return revision > mutationGoalRevision && revision <= currentGoalRevision;
|
|
14233
|
+
});
|
|
14234
|
+
if (!interveningGoalEntries.length) return false;
|
|
14235
|
+
return interveningGoalEntries.every((entry) => {
|
|
14236
|
+
const relation = String(entry?.relation || "");
|
|
14237
|
+
const kind = String(entry?.kind || "");
|
|
14238
|
+
const entryTaskHash = String(entry?.taskHash || "");
|
|
14239
|
+
return (
|
|
14240
|
+
(relation === "same-task" || kind === "same-task-continuation") &&
|
|
14241
|
+
entryTaskHash === currentTaskHash
|
|
14242
|
+
);
|
|
14243
|
+
});
|
|
14244
|
+
}
|
|
14245
|
+
|
|
14246
|
+
function currentGoalDocumentArtifactStillExists(candidate = "", state = {}, config = {}) {
|
|
14247
|
+
const normalized = safeTaskOwnedCommitPath(candidate);
|
|
14248
|
+
if (!normalized || !/\.(?:docx|pdf)$/iu.test(normalized)) return false;
|
|
14249
|
+
if (
|
|
14250
|
+
isPrivateVerificationEvidencePath(normalized) ||
|
|
14251
|
+
isScopedTaskArtifactEvidencePath(normalized, state, config)
|
|
14252
|
+
) {
|
|
14253
|
+
return false;
|
|
14254
|
+
}
|
|
14255
|
+
const commandCwd = path.resolve(
|
|
14256
|
+
config.commandCwd || state.commandCwd || process.cwd()
|
|
14257
|
+
);
|
|
14258
|
+
const absolutePath = path.resolve(commandCwd, normalized);
|
|
14259
|
+
const relativePath = path.relative(commandCwd, absolutePath);
|
|
14260
|
+
if (
|
|
14261
|
+
!relativePath ||
|
|
14262
|
+
relativePath.startsWith("..") ||
|
|
14263
|
+
path.isAbsolute(relativePath)
|
|
14264
|
+
) {
|
|
14265
|
+
return false;
|
|
14266
|
+
}
|
|
14267
|
+
try {
|
|
14268
|
+
const stat = fsSync.lstatSync(absolutePath);
|
|
14269
|
+
return stat.isFile() && !stat.isSymbolicLink() && stat.size > 0;
|
|
14270
|
+
} catch {
|
|
14271
|
+
return false;
|
|
14272
|
+
}
|
|
14273
|
+
}
|
|
14274
|
+
|
|
14275
|
+
const LIKELY_DOCUMENT_SOURCE_EXTENSIONS = new Set([
|
|
14276
|
+
".tex",
|
|
14277
|
+
".md",
|
|
14278
|
+
".markdown",
|
|
14279
|
+
".rmd",
|
|
14280
|
+
".qmd",
|
|
14281
|
+
".typ",
|
|
14282
|
+
]);
|
|
14283
|
+
|
|
14284
|
+
function documentArtifactFreshnessKey(value = "") {
|
|
14285
|
+
const candidate = safeTaskOwnedCommitPath(value);
|
|
14286
|
+
if (!candidate) return "";
|
|
14287
|
+
const extension = path.posix.extname(candidate).toLocaleLowerCase("en-US");
|
|
14288
|
+
const basename = path.posix.basename(candidate, extension);
|
|
14289
|
+
const dirname = path.posix.dirname(candidate);
|
|
14290
|
+
return `${dirname === "." ? "" : `${dirname}/`}${basename}`.toLocaleLowerCase("en-US");
|
|
14291
|
+
}
|
|
14292
|
+
|
|
14293
|
+
function mutationArtifactPaths(mutation = {}) {
|
|
14294
|
+
return [
|
|
14295
|
+
...(Array.isArray(mutation?.paths) ? mutation.paths : []),
|
|
14296
|
+
...(Array.isArray(mutation?.projectMutationPaths)
|
|
14297
|
+
? mutation.projectMutationPaths
|
|
14298
|
+
: []),
|
|
14299
|
+
...(Array.isArray(mutation?.verifiedGeneratedOutputPaths)
|
|
14300
|
+
? mutation.verifiedGeneratedOutputPaths
|
|
14301
|
+
: []),
|
|
14302
|
+
];
|
|
14303
|
+
}
|
|
14304
|
+
|
|
14305
|
+
function mutationInvalidatesDocumentArtifact(mutation = {}, artifactPath = "") {
|
|
14306
|
+
const artifact = safeTaskOwnedCommitPath(artifactPath);
|
|
14307
|
+
if (!artifact) return false;
|
|
14308
|
+
const artifactKey = documentArtifactFreshnessKey(artifact);
|
|
14309
|
+
if (!artifactKey) return false;
|
|
14310
|
+
for (const value of mutationArtifactPaths(mutation)) {
|
|
14311
|
+
const candidate = safeTaskOwnedCommitPath(value);
|
|
14312
|
+
if (!candidate) continue;
|
|
14313
|
+
if (candidate === artifact) return true;
|
|
14314
|
+
const extension = path.posix.extname(candidate).toLocaleLowerCase("en-US");
|
|
14315
|
+
if (
|
|
14316
|
+
LIKELY_DOCUMENT_SOURCE_EXTENSIONS.has(extension) &&
|
|
14317
|
+
documentArtifactFreshnessKey(candidate) === artifactKey
|
|
14318
|
+
) {
|
|
14319
|
+
return true;
|
|
14320
|
+
}
|
|
14321
|
+
}
|
|
14322
|
+
return false;
|
|
14323
|
+
}
|
|
14324
|
+
|
|
14325
|
+
function retainedDocumentArtifactMutationIsFresh(
|
|
14326
|
+
state = {},
|
|
14327
|
+
history = [],
|
|
14328
|
+
mutation = {},
|
|
14329
|
+
artifactPath = ""
|
|
14330
|
+
) {
|
|
14331
|
+
const artifactRevision = Math.max(0, Number(mutation?.revision || 0));
|
|
14332
|
+
if (artifactRevision <= 0) return false;
|
|
14333
|
+
for (const laterMutation of history) {
|
|
14334
|
+
if (Math.max(0, Number(laterMutation?.revision || 0)) <= artifactRevision) {
|
|
14335
|
+
continue;
|
|
14336
|
+
}
|
|
14337
|
+
if (!currentGoalRevisionBelongsToActiveTask(state, laterMutation)) continue;
|
|
14338
|
+
if (mutationInvalidatesDocumentArtifact(laterMutation, artifactPath)) {
|
|
14339
|
+
return false;
|
|
14340
|
+
}
|
|
14341
|
+
}
|
|
14342
|
+
return true;
|
|
14343
|
+
}
|
|
14344
|
+
|
|
14345
|
+
function currentGoalDocumentArtifactPathsForState(state = {}, config = {}) {
|
|
14346
|
+
const verification = state.meta?.projectVerification || {};
|
|
14347
|
+
const history = Array.isArray(verification.mutationHistory)
|
|
14348
|
+
? verification.mutationHistory
|
|
14349
|
+
: [];
|
|
14350
|
+
const currentGoalRevision = Math.max(
|
|
14351
|
+
0,
|
|
14352
|
+
Number(state.meta?.goalContract?.revision || 0)
|
|
14353
|
+
);
|
|
14354
|
+
if (currentGoalRevision <= 0) return [];
|
|
14355
|
+
const candidates = [];
|
|
14356
|
+
const seen = new Set();
|
|
14357
|
+
for (const mutation of history) {
|
|
14358
|
+
if (!currentGoalRevisionBelongsToActiveTask(state, mutation)) continue;
|
|
14359
|
+
const paths = [
|
|
14360
|
+
...(Array.isArray(mutation?.paths) ? mutation.paths : []),
|
|
14361
|
+
...(Array.isArray(mutation?.projectMutationPaths)
|
|
14362
|
+
? mutation.projectMutationPaths
|
|
14363
|
+
: []),
|
|
14364
|
+
...(Array.isArray(mutation?.verifiedGeneratedOutputPaths)
|
|
14365
|
+
? mutation.verifiedGeneratedOutputPaths
|
|
14366
|
+
: []),
|
|
14367
|
+
];
|
|
14368
|
+
for (const value of paths) {
|
|
14369
|
+
const candidate = safeTaskOwnedCommitPath(value);
|
|
14370
|
+
if (
|
|
14371
|
+
!candidate ||
|
|
14372
|
+
!/\.(?:docx|pdf)$/iu.test(candidate) ||
|
|
14373
|
+
!currentGoalDocumentArtifactStillExists(candidate, state, config) ||
|
|
14374
|
+
!retainedDocumentArtifactMutationIsFresh(
|
|
14375
|
+
state,
|
|
14376
|
+
history,
|
|
14377
|
+
mutation,
|
|
14378
|
+
candidate
|
|
14379
|
+
) ||
|
|
14380
|
+
seen.has(candidate)
|
|
14381
|
+
) {
|
|
14382
|
+
continue;
|
|
14383
|
+
}
|
|
14384
|
+
seen.add(candidate);
|
|
14385
|
+
candidates.push(candidate);
|
|
14386
|
+
if (candidates.length >= 16) return candidates;
|
|
14387
|
+
}
|
|
14388
|
+
}
|
|
14389
|
+
return candidates;
|
|
14390
|
+
}
|
|
14391
|
+
|
|
14188
14392
|
function exactInputPathsForState(state = {}) {
|
|
14189
14393
|
const scsInputPaths = Array.isArray(state.meta?.scs?.taskContract?.exactInputPaths)
|
|
14190
14394
|
? state.meta.scs.taskContract.exactInputPaths.filter(Boolean)
|
|
@@ -21389,6 +21593,7 @@ async function completionEvidenceDecision({ config, state, store, observers, ste
|
|
|
21389
21593
|
const documentExactOutputPaths = [
|
|
21390
21594
|
...(assessment.contract?.exactOutputPaths || []),
|
|
21391
21595
|
...exactOutputPathsForState(state),
|
|
21596
|
+
...currentGoalDocumentArtifactPathsForState(state, config),
|
|
21392
21597
|
];
|
|
21393
21598
|
const documentContractText = `${completionContractGoal(config, state)}\n${candidateResult}`;
|
|
21394
21599
|
const documentDeliverableRequested =
|