@loucompanion/forge-bridge 0.1.4-dev.318bc3bd5b6a → 0.1.4-dev.494233aa2e50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridge/bridge.service.d.ts +12 -1
- package/dist/bridge/bridge.service.js +51 -5
- package/dist/bridge/bridge.types.d.ts +6 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
- package/dist/runtime/host-database-capability-boundary.js +1 -0
- package/dist/runtime/host-facts.d.ts +35 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-sampler.d.ts +83 -0
- package/dist/runtime/host-load-sampler.js +164 -0
- package/dist/runtime/host-pressure-stall.d.ts +41 -0
- package/dist/runtime/host-pressure-stall.js +121 -0
- package/dist/runtime/host-runtime-contract.d.ts +1 -0
- package/dist/runtime/host-runtime-contract.js +2 -0
- package/dist/runtime/host-runtime-lease.js +5 -0
- package/dist/runtime/playwright-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +11 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +48 -54
- package/dist/session/phase-completion.artifacts.js +4 -0
- package/dist/session/pre-publication-process.d.ts +20 -0
- package/dist/session/pre-publication-process.js +97 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-validation.js +27 -57
- package/dist/session/provider-cli/provider-cli.artifacts.js +2 -9
- package/dist/session/provider-cli/provider-cli.service.js +54 -7
- package/dist/session/publishable-worktree-changes.d.ts +45 -0
- package/dist/session/publishable-worktree-changes.js +177 -0
- package/dist/session/session.types.js +3 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,8 @@ import { buildSpecBody, selectLaneCommand } from "../../worktree/artifact-inject
|
|
|
6
6
|
import { defaultWorktreeCoordinatorStateRoot } from "../../worktree/worktree-paths.js";
|
|
7
7
|
import { completionPhaseFromDispatch, prepareCompletionToolRuntime, readCompletionArtifact, usesDebugCycleCompletion, usesDevelopCycleCompletion } from "../phase-completion.js";
|
|
8
8
|
import { ForgeFailureError } from "../session.types.js";
|
|
9
|
-
import { cleanupCompletionTools, commitWorktreeChanges, completionPhaseFromArtifact, emitArchitectStructuredEvents, emitCompletionArtifactRecorded, emitDecomposeGateArtifacts, emitDraftGateArtifacts, emitPhaseCompletionEvent, emitPhaseGateEvents, emitQaArtifactRecorded, emitQaStructuredEvents, enforceQaBrowserLaunchTargetGate, LiveArchitectArtifactEmitter, LiveCompletionArtifactEmitter, LiveQaArtifactEmitter, readCompletionArtifactsForRun, readQaCompletionArtifactBundle,
|
|
9
|
+
import { cleanupCompletionTools, commitWorktreeChanges, completionPhaseFromArtifact, emitArchitectStructuredEvents, emitCompletionArtifactRecorded, emitDecomposeGateArtifacts, emitDraftGateArtifacts, emitPhaseCompletionEvent, emitPhaseGateEvents, emitQaArtifactRecorded, emitQaStructuredEvents, enforceQaBrowserLaunchTargetGate, LiveArchitectArtifactEmitter, LiveCompletionArtifactEmitter, LiveQaArtifactEmitter, readCompletionArtifactsForRun, readQaCompletionArtifactBundle, waitForCompletionArtifact } from "./provider-cli.artifacts.js";
|
|
10
|
+
import { diffClaimedChangedFiles, findUnpublishedWorktreePaths, normalizeChangedFilePath, stagePublishableWorktreeChangeSet, } from "../publishable-worktree-changes.js";
|
|
10
11
|
import { DeterministicProviderCliService } from "./provider-cli.deterministic.js";
|
|
11
12
|
import { buildArchitectPrompt, buildConflictResolvePrompt, buildDebugCyclePrompt, buildDevelopCyclePrompt, buildDraftPrompt, buildDraftSpec, buildImplementationPrompt, buildProviderCliPrompt, buildProviderCliCommand, durableDraftInput, buildPullRequestCheckRepairPrompt, buildPullRequestCommentsPrompt, buildQaPrompt, formatProviderCliCommandForCheckpoint, isDecomposeDraftDispatch, isPullRequestCheckRepairDispatch, isPullRequestCommentsDispatch } from "./provider-cli.prompts.js";
|
|
12
13
|
import { isTransientCodexProviderNotFoundFailure, recoveringProviderProcessRunner, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
@@ -68,12 +69,54 @@ function assertCommentRepairArtifactMatchesChanges(artifact, actualChangedFiles)
|
|
|
68
69
|
const claimed = [...new Set(claimedChangedFiles)].sort();
|
|
69
70
|
const actual = [...new Set(normalizedActual)].sort();
|
|
70
71
|
if (hasFixedDisposition && actual.length === 0) {
|
|
71
|
-
throw
|
|
72
|
+
throw commentRepairChangedFilesMismatch("Comment repair fixed dispositions require an actual publishable source diff.");
|
|
72
73
|
}
|
|
73
74
|
if (claimed.length !== actual.length || claimed.some((value, index) => value !== actual[index])) {
|
|
74
|
-
|
|
75
|
+
const { missing, unexpected } = diffClaimedChangedFiles(claimed, actual);
|
|
76
|
+
throw commentRepairChangedFilesMismatch(`Comment repair changed_files must exactly match the publishable staged source diff${formatChangedFilesDelta(missing, unexpected)}.`);
|
|
75
77
|
}
|
|
76
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* A finding resolved as fixed must not point at a file whose edit Forge leaves out of the
|
|
81
|
+
* published commit; otherwise the thread would be resolved without its fix. That covers
|
|
82
|
+
* runtime output Forge unstaged and untracked or git-ignored files it never stages.
|
|
83
|
+
*/
|
|
84
|
+
async function assertFixedFindingsArePublished(git, worktreePath, dispatch, artifact, changeSet) {
|
|
85
|
+
const findingPaths = new Map((dispatch.pullRequest?.reviewFindings ?? []).map(finding => [
|
|
86
|
+
`${finding.kind.trim().toLowerCase()}:${finding.claimId}:${finding.bodySha256.trim().toLowerCase()}`,
|
|
87
|
+
finding.path ? normalizeChangedFilePath(finding.path) : "",
|
|
88
|
+
]));
|
|
89
|
+
const payload = JSON.parse(artifact.verdictJson);
|
|
90
|
+
const dispositions = Array.isArray(payload.dispositions) ? payload.dispositions : [];
|
|
91
|
+
const fixed = dispositions.flatMap(value => {
|
|
92
|
+
const record = value;
|
|
93
|
+
if (record.disposition !== "fixed")
|
|
94
|
+
return [];
|
|
95
|
+
const identity = `${String(record.kind ?? "").trim().toLowerCase()}:${String(record.claim_id ?? "")}:${String(record.body_sha256 ?? "").trim().toLowerCase()}`;
|
|
96
|
+
const findingPath = findingPaths.get(identity);
|
|
97
|
+
return findingPath ? [{ claimId: String(record.claim_id ?? ""), path: findingPath }] : [];
|
|
98
|
+
});
|
|
99
|
+
if (fixed.length === 0)
|
|
100
|
+
return;
|
|
101
|
+
const unpublished = new Set([
|
|
102
|
+
...changeSet.excluded.map(normalizeChangedFilePath),
|
|
103
|
+
...await findUnpublishedWorktreePaths(git, worktreePath, fixed.map(entry => entry.path), changeSet.publishable),
|
|
104
|
+
]);
|
|
105
|
+
const dropped = fixed.filter(entry => unpublished.has(entry.path)).map(entry => `${entry.claimId} (${entry.path})`);
|
|
106
|
+
if (dropped.length > 0) {
|
|
107
|
+
throw commentRepairChangedFilesMismatch(`Comment repair marked ${dropped.join(", ")} fixed, but Forge does not publish that file (runtime output, untracked, or git-ignored); Forge did not publish or resolve review findings.`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function commentRepairChangedFilesMismatch(message) {
|
|
111
|
+
return new ForgeFailureError("comment_repair_changed_files_mismatch", message);
|
|
112
|
+
}
|
|
113
|
+
function formatChangedFilesDelta(missing, unexpected) {
|
|
114
|
+
const parts = [
|
|
115
|
+
missing.length > 0 ? `missing from changed_files: ${missing.join(", ")}` : "",
|
|
116
|
+
unexpected.length > 0 ? `not in the publishable diff: ${unexpected.join(", ")}` : "",
|
|
117
|
+
].filter(Boolean);
|
|
118
|
+
return parts.length > 0 ? ` (${parts.join("; ")})` : "";
|
|
119
|
+
}
|
|
77
120
|
async function finalizeCommentRepairChangedFiles(artifact, baselineChangedFiles, actualChangedFiles) {
|
|
78
121
|
const payload = JSON.parse(artifact.verdictJson);
|
|
79
122
|
const claimedRecords = Array.isArray(payload.changed_files)
|
|
@@ -90,11 +133,11 @@ async function finalizeCommentRepairChangedFiles(artifact, baselineChangedFiles,
|
|
|
90
133
|
const dispositions = Array.isArray(payload.dispositions) ? payload.dispositions : [];
|
|
91
134
|
const hasFixedDisposition = dispositions.some(value => value.disposition === "fixed");
|
|
92
135
|
if (hasFixedDisposition && authoritativePaths.length === 0) {
|
|
93
|
-
throw
|
|
136
|
+
throw commentRepairChangedFilesMismatch("Comment repair fixed dispositions require an actual publishable source diff.");
|
|
94
137
|
}
|
|
95
138
|
for (const baselinePath of baselineChangedFiles.map(value => value.trim().replaceAll("\\", "/"))) {
|
|
96
139
|
if (baselinePath && !authoritative.has(baselinePath)) {
|
|
97
|
-
throw
|
|
140
|
+
throw commentRepairChangedFilesMismatch(`Comment repair pre-publication repair removed '${baselinePath}' from the publishable staged source diff.`);
|
|
98
141
|
}
|
|
99
142
|
}
|
|
100
143
|
payload.changed_files = authoritativePaths.map(filePath => {
|
|
@@ -1220,7 +1263,9 @@ export class ProcessBackedProviderCliService {
|
|
|
1220
1263
|
}
|
|
1221
1264
|
let commentRepairBaselineChangedFiles = null;
|
|
1222
1265
|
if (addressComments && repairArtifact) {
|
|
1223
|
-
|
|
1266
|
+
const baseline = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1267
|
+
commentRepairBaselineChangedFiles = baseline.publishable;
|
|
1268
|
+
await assertFixedFindingsArePublished(this.git, worktree.worktreePath, dispatch, repairArtifact, baseline);
|
|
1224
1269
|
assertCommentRepairArtifactMatchesChanges(repairArtifact, commentRepairBaselineChangedFiles);
|
|
1225
1270
|
}
|
|
1226
1271
|
const validationProfile = repairChecks
|
|
@@ -1236,8 +1281,10 @@ export class ProcessBackedProviderCliService {
|
|
|
1236
1281
|
preparedHeadSha,
|
|
1237
1282
|
repairScope: "pull_request",
|
|
1238
1283
|
});
|
|
1239
|
-
const
|
|
1284
|
+
const stagedChangeSet = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1285
|
+
const stagedChangedFiles = stagedChangeSet.publishable;
|
|
1240
1286
|
if (addressComments && repairArtifact && commentRepairBaselineChangedFiles) {
|
|
1287
|
+
await assertFixedFindingsArePublished(this.git, worktree.worktreePath, dispatch, repairArtifact, stagedChangeSet);
|
|
1241
1288
|
repairArtifact = await finalizeCommentRepairChangedFiles(repairArtifact, commentRepairBaselineChangedFiles, stagedChangedFiles);
|
|
1242
1289
|
}
|
|
1243
1290
|
const committed = await commitWorktreeChanges(this.git, worktree.worktreePath, dispatch.workItem.id, stagedChangedFiles);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { GitClient } from "../shared/git/git.js";
|
|
2
|
+
import { type ProcessRunner } from "../shared/process/process.js";
|
|
3
|
+
export interface PublishableWorktreeChangeSet {
|
|
4
|
+
/** Paths staged for publication, as `git diff --cached --name-only` reports them. */
|
|
5
|
+
readonly publishable: readonly string[];
|
|
6
|
+
/** Worktree changes Forge treats as runtime output and leaves unstaged. */
|
|
7
|
+
readonly excluded: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Decides whether a staged change is Forge runtime output rather than an author edit.
|
|
11
|
+
*
|
|
12
|
+
* `.local/`, `.forge/work-items/` and `.forge/stories/` are always runtime output. Any
|
|
13
|
+
* other `.forge/` path is runtime output only when HEAD does not track it (status `A`):
|
|
14
|
+
* that covers injected managed commands, hooks and skills. The injector never overwrites a
|
|
15
|
+
* tracked `.forge/` file and restores one that matches the managed body, so a tracked
|
|
16
|
+
* `.forge/` file that differs from HEAD is an author edit and must be published.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isNonPublishableWorktreeChange(relativePath: string, status: string): boolean;
|
|
19
|
+
/** Stages every publishable worktree change in the real index and returns both sets. */
|
|
20
|
+
export declare function stagePublishableWorktreeChangeSet(git: Pick<GitClient, "run">, worktreePath: string): Promise<PublishableWorktreeChangeSet>;
|
|
21
|
+
/**
|
|
22
|
+
* Computes the same change set as {@link stagePublishableWorktreeChangeSet} without
|
|
23
|
+
* touching the worktree's index, using a throwaway copy of it. Returns null when
|
|
24
|
+
* `worktreePath` is not the root of a git worktree.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readPublishableWorktreeChangeSet(worktreePath: string, processRunner?: ProcessRunner): Promise<PublishableWorktreeChangeSet | null>;
|
|
27
|
+
/** Compares claimed `changed_files` paths with the publishable diff. */
|
|
28
|
+
export declare function diffClaimedChangedFiles(claimedPaths: readonly string[], publishablePaths: readonly string[]): {
|
|
29
|
+
readonly missing: readonly string[];
|
|
30
|
+
readonly unexpected: readonly string[];
|
|
31
|
+
};
|
|
32
|
+
export declare function normalizeChangedFilePath(value: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* In-tool check for `forge.complete_comment_repair`: rejects a pass payload whose
|
|
35
|
+
* `changed_files` differs from what Forge would publish, so the agent can correct it
|
|
36
|
+
* in the same turn instead of failing at publication.
|
|
37
|
+
*/
|
|
38
|
+
export declare function assertClaimedChangedFilesMatchPublishableDiff(worktreePath: string, payload: Record<string, unknown>, toolName: string, processRunner?: ProcessRunner): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the given paths whose worktree content differs from HEAD but is not in the
|
|
41
|
+
* publishable set: excluded runtime output, and untracked or git-ignored files that are
|
|
42
|
+
* never staged at all (for example an injected `.forge/` file in a repository that ignores
|
|
43
|
+
* `.forge/`). A review finding on such a path cannot be fixed by the published commit.
|
|
44
|
+
*/
|
|
45
|
+
export declare function findUnpublishedWorktreePaths(git: Pick<GitClient, "run">, worktreePath: string, paths: readonly string[], publishablePaths: readonly string[]): Promise<readonly string[]>;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { GitClient } from "../shared/git/git.js";
|
|
5
|
+
import { NodeProcessRunner } from "../shared/process/process.js";
|
|
6
|
+
/**
|
|
7
|
+
* Forge runtime output that is never published, whether or not the target repository
|
|
8
|
+
* tracks other `.forge/` content. Completion artifacts and evidence live here.
|
|
9
|
+
*/
|
|
10
|
+
const runtimeOnlyPathPrefixes = [".local/", ".forge/work-items/", ".forge/stories/"];
|
|
11
|
+
const resetBatchSize = 200;
|
|
12
|
+
/**
|
|
13
|
+
* Decides whether a staged change is Forge runtime output rather than an author edit.
|
|
14
|
+
*
|
|
15
|
+
* `.local/`, `.forge/work-items/` and `.forge/stories/` are always runtime output. Any
|
|
16
|
+
* other `.forge/` path is runtime output only when HEAD does not track it (status `A`):
|
|
17
|
+
* that covers injected managed commands, hooks and skills. The injector never overwrites a
|
|
18
|
+
* tracked `.forge/` file and restores one that matches the managed body, so a tracked
|
|
19
|
+
* `.forge/` file that differs from HEAD is an author edit and must be published.
|
|
20
|
+
*/
|
|
21
|
+
export function isNonPublishableWorktreeChange(relativePath, status) {
|
|
22
|
+
const normalized = relativePath.trim().replaceAll("\\", "/");
|
|
23
|
+
if (normalized === ".local" || runtimeOnlyPathPrefixes.some(prefix => normalized.startsWith(prefix))) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (normalized === ".forge" || normalized.startsWith(".forge/")) {
|
|
27
|
+
return status.trim().toUpperCase().startsWith("A");
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
/** Stages every publishable worktree change in the real index and returns both sets. */
|
|
32
|
+
export async function stagePublishableWorktreeChangeSet(git, worktreePath) {
|
|
33
|
+
await git.run(worktreePath, ["add", "-A"]);
|
|
34
|
+
const excluded = (await readStagedChanges(git, worktreePath))
|
|
35
|
+
.filter(change => isNonPublishableWorktreeChange(change.path, change.status))
|
|
36
|
+
.map(change => change.path);
|
|
37
|
+
for (let index = 0; index < excluded.length; index += resetBatchSize) {
|
|
38
|
+
const batch = excluded.slice(index, index + resetBatchSize).map(filePath => `:(literal)${filePath}`);
|
|
39
|
+
await git.run(worktreePath, ["reset", "-q", "--", ...batch]);
|
|
40
|
+
}
|
|
41
|
+
const publishable = (await git.run(worktreePath, ["diff", "--cached", "--name-only"]))
|
|
42
|
+
.split(/\r?\n/)
|
|
43
|
+
.map(line => line.trim())
|
|
44
|
+
.filter(Boolean);
|
|
45
|
+
return { publishable, excluded: [...new Set(excluded)].sort() };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Computes the same change set as {@link stagePublishableWorktreeChangeSet} without
|
|
49
|
+
* touching the worktree's index, using a throwaway copy of it. Returns null when
|
|
50
|
+
* `worktreePath` is not the root of a git worktree.
|
|
51
|
+
*/
|
|
52
|
+
export async function readPublishableWorktreeChangeSet(worktreePath, processRunner = new NodeProcessRunner()) {
|
|
53
|
+
const resolvedWorktree = path.resolve(worktreePath);
|
|
54
|
+
const git = new GitClient(processRunner);
|
|
55
|
+
let topLevel;
|
|
56
|
+
try {
|
|
57
|
+
topLevel = (await git.run(resolvedWorktree, ["rev-parse", "--show-toplevel"])).trim();
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (!topLevel || !await samePath(topLevel, resolvedWorktree)) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const realIndex = path.resolve(resolvedWorktree, (await git.run(resolvedWorktree, ["rev-parse", "--git-path", "index"])).trim());
|
|
66
|
+
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "forge-publishable-index-"));
|
|
67
|
+
try {
|
|
68
|
+
const tempIndex = path.join(tempRoot, "index");
|
|
69
|
+
await fs.copyFile(realIndex, tempIndex).catch((error) => {
|
|
70
|
+
if (error.code !== "ENOENT")
|
|
71
|
+
throw error;
|
|
72
|
+
});
|
|
73
|
+
const tempIndexGit = new GitClient({
|
|
74
|
+
run: request => processRunner.run({
|
|
75
|
+
...request,
|
|
76
|
+
env: { ...(request.env ?? process.env), GIT_INDEX_FILE: tempIndex },
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
return await stagePublishableWorktreeChangeSet(tempIndexGit, resolvedWorktree);
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
await fs.rm(tempRoot, { recursive: true, force: true });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Compares claimed `changed_files` paths with the publishable diff. */
|
|
86
|
+
export function diffClaimedChangedFiles(claimedPaths, publishablePaths) {
|
|
87
|
+
const claimed = new Set(claimedPaths.map(normalizeChangedFilePath).filter(Boolean));
|
|
88
|
+
const actual = new Set(publishablePaths.map(normalizeChangedFilePath).filter(Boolean));
|
|
89
|
+
return {
|
|
90
|
+
missing: [...actual].filter(filePath => !claimed.has(filePath)).sort(),
|
|
91
|
+
unexpected: [...claimed].filter(filePath => !actual.has(filePath)).sort(),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export function normalizeChangedFilePath(value) {
|
|
95
|
+
return value.trim().replaceAll("\\", "/");
|
|
96
|
+
}
|
|
97
|
+
async function readStagedChanges(git, worktreePath) {
|
|
98
|
+
const fields = (await git.run(worktreePath, ["diff", "--cached", "--name-status", "--no-renames", "-z"]))
|
|
99
|
+
.split("\0");
|
|
100
|
+
const changes = [];
|
|
101
|
+
for (let index = 0; index + 1 < fields.length; index += 2) {
|
|
102
|
+
const status = fields[index].trim();
|
|
103
|
+
const filePath = fields[index + 1];
|
|
104
|
+
if (status && filePath)
|
|
105
|
+
changes.push({ status, path: filePath });
|
|
106
|
+
}
|
|
107
|
+
return changes;
|
|
108
|
+
}
|
|
109
|
+
async function samePath(left, right) {
|
|
110
|
+
const [realLeft, realRight] = await Promise.all([
|
|
111
|
+
fs.realpath(left).catch(() => path.resolve(left)),
|
|
112
|
+
fs.realpath(right).catch(() => path.resolve(right)),
|
|
113
|
+
]);
|
|
114
|
+
return process.platform === "win32"
|
|
115
|
+
? realLeft.toLowerCase() === realRight.toLowerCase()
|
|
116
|
+
: realLeft === realRight;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* In-tool check for `forge.complete_comment_repair`: rejects a pass payload whose
|
|
120
|
+
* `changed_files` differs from what Forge would publish, so the agent can correct it
|
|
121
|
+
* in the same turn instead of failing at publication.
|
|
122
|
+
*/
|
|
123
|
+
export async function assertClaimedChangedFilesMatchPublishableDiff(worktreePath, payload, toolName, processRunner) {
|
|
124
|
+
const changeSet = await readPublishableWorktreeChangeSet(worktreePath, processRunner);
|
|
125
|
+
if (!changeSet)
|
|
126
|
+
return;
|
|
127
|
+
const claimed = Array.isArray(payload.changed_files)
|
|
128
|
+
? payload.changed_files.map(value => String(value?.path ?? ""))
|
|
129
|
+
: [];
|
|
130
|
+
const { missing, unexpected } = diffClaimedChangedFiles(claimed, changeSet.publishable);
|
|
131
|
+
if (missing.length === 0 && unexpected.length === 0)
|
|
132
|
+
return;
|
|
133
|
+
const details = [
|
|
134
|
+
missing.length > 0 ? `Publishable changes missing from changed_files: ${missing.join(", ")}.` : "",
|
|
135
|
+
unexpected.length > 0 ? `changed_files entries that Forge will not publish: ${unexpected.join(", ")}.` : "",
|
|
136
|
+
].filter(Boolean).join(" ");
|
|
137
|
+
throw new Error(`changed_files must list exactly the files Forge will publish. ${details} `
|
|
138
|
+
+ "Forge publishes every source change, including edits to tracked .forge/ files; it never publishes "
|
|
139
|
+
+ ".local/, .forge/work-items/, .forge/stories/, or new untracked .forge/ files. "
|
|
140
|
+
+ `Correct changed_files (or the worktree) and call ${toolName} again.`);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Returns the given paths whose worktree content differs from HEAD but is not in the
|
|
144
|
+
* publishable set: excluded runtime output, and untracked or git-ignored files that are
|
|
145
|
+
* never staged at all (for example an injected `.forge/` file in a repository that ignores
|
|
146
|
+
* `.forge/`). A review finding on such a path cannot be fixed by the published commit.
|
|
147
|
+
*/
|
|
148
|
+
export async function findUnpublishedWorktreePaths(git, worktreePath, paths, publishablePaths) {
|
|
149
|
+
const candidates = [...new Set(paths.map(normalizeChangedFilePath).filter(Boolean))];
|
|
150
|
+
if (candidates.length === 0)
|
|
151
|
+
return [];
|
|
152
|
+
const publishable = new Set(publishablePaths.map(normalizeChangedFilePath));
|
|
153
|
+
const unpublished = new Set();
|
|
154
|
+
for (let index = 0; index < candidates.length; index += resetBatchSize) {
|
|
155
|
+
const batch = candidates.slice(index, index + resetBatchSize).map(filePath => `:(literal)${filePath}`);
|
|
156
|
+
const output = await git.run(worktreePath, [
|
|
157
|
+
// `traditional` with `--untracked-files=all` lists each file inside an ignored directory.
|
|
158
|
+
"status", "--porcelain=v1", "-z", "--no-renames", "--ignored=traditional", "--untracked-files=all", "--", ...batch,
|
|
159
|
+
]);
|
|
160
|
+
for (const entry of output.split("\0")) {
|
|
161
|
+
if (entry.length < 4)
|
|
162
|
+
continue;
|
|
163
|
+
const reported = normalizeChangedFilePath(entry.slice(3));
|
|
164
|
+
if (!reported)
|
|
165
|
+
continue;
|
|
166
|
+
// A collapsed directory entry ("dir/") covers every candidate beneath it.
|
|
167
|
+
const matches = reported.endsWith("/")
|
|
168
|
+
? candidates.filter(candidate => candidate.startsWith(reported))
|
|
169
|
+
: [reported];
|
|
170
|
+
for (const filePath of matches) {
|
|
171
|
+
if (!publishable.has(filePath))
|
|
172
|
+
unpublished.add(filePath);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return [...unpublished].sort();
|
|
177
|
+
}
|
|
@@ -481,6 +481,9 @@ function unvalidatedFailureFactsForCode(code, source) {
|
|
|
481
481
|
if (["prepublication_validation_failed", "prepublication_contract_invalid", "prepublication_execution_scope_invalid"].includes(code)) {
|
|
482
482
|
return facts(code, "domain", "validation", source, "non_retryable", "fix_input");
|
|
483
483
|
}
|
|
484
|
+
if (code === "comment_repair_changed_files_mismatch") {
|
|
485
|
+
return facts(code, "domain", "validation", source, "non_retryable", "inspect_failure");
|
|
486
|
+
}
|
|
484
487
|
if (["generated_output_reset_failed", "generated_output_reset_unverified", "worktree_prepare_failed", "host_runtime_ledger_write_failed", "host_diagnostics_temporary_unavailable", "attempt_process_supervisor_start_failed", "attempt_process_supervisor_start_timeout"].includes(code)) {
|
|
485
488
|
return facts(code, "transport", "prepare", source, "retryable", "retry_dispatch");
|
|
486
489
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const forgeBridgeVersion = "0.1.4-dev.
|
|
1
|
+
export declare const forgeBridgeVersion = "0.1.4-dev.494233aa2e50";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const forgeBridgeVersion = "0.1.4-dev.
|
|
1
|
+
export const forgeBridgeVersion = "0.1.4-dev.494233aa2e50";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loucompanion/forge-bridge",
|
|
3
|
-
"version": "0.1.4-dev.
|
|
3
|
+
"version": "0.1.4-dev.494233aa2e50",
|
|
4
4
|
"description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|