@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.028808a841c8
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/README.md +89 -3
- package/dist/bridge/bridge-chat.types.d.ts +111 -0
- package/dist/bridge/bridge-chat.types.js +401 -0
- package/dist/bridge/bridge.base.d.ts +4 -1
- package/dist/bridge/bridge.service.d.ts +83 -3
- package/dist/bridge/bridge.service.js +1609 -152
- package/dist/bridge/bridge.types.d.ts +52 -1
- package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
- package/dist/bridge/dispatch-result-outbox.js +87 -0
- package/dist/bridge/dispatch-result-worker.d.ts +2 -0
- package/dist/bridge/dispatch-result-worker.js +122 -0
- package/dist/bridge/internals.d.ts +2 -0
- package/dist/bridge/internals.js +1 -0
- package/dist/bridge/readiness-result-outbox.d.ts +21 -0
- package/dist/bridge/readiness-result-outbox.js +54 -0
- package/dist/bridge/readiness-result-worker.d.ts +2 -0
- package/dist/bridge/readiness-result-worker.js +121 -0
- package/dist/bridge/runner-host-capabilities.d.ts +15 -0
- package/dist/bridge/runner-host-capabilities.js +93 -0
- package/dist/cleanup/cleanup.service.d.ts +1 -0
- package/dist/cleanup/cleanup.service.js +70 -9
- package/dist/cli/cli.help.js +4 -4
- package/dist/cli/cli.service.d.ts +14 -6
- package/dist/cli/cli.service.js +75 -16
- package/dist/cli/local-config.d.ts +1 -0
- package/dist/cli/local-config.js +4 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +341 -0
- package/dist/runtime/attempt-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -0
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +2 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
- package/dist/runtime/attempt-path-operation.d.ts +21 -0
- package/dist/runtime/attempt-path-operation.js +94 -0
- package/dist/runtime/attempt-private-directory.d.ts +6 -0
- package/dist/runtime/attempt-private-directory.js +54 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +35 -0
- package/dist/runtime/attempt-process-supervisor.js +144 -23
- package/dist/runtime/canonical-source-file.d.ts +3 -0
- package/dist/runtime/canonical-source-file.js +54 -0
- package/dist/runtime/docker-engine-probe.d.ts +90 -0
- package/dist/runtime/docker-engine-probe.js +333 -0
- package/dist/runtime/generated-output-reset.d.ts +10 -0
- package/dist/runtime/generated-output-reset.js +62 -8
- package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
- package/dist/runtime/host-database-capability-boundary.js +63 -0
- package/dist/runtime/host-diagnostics.d.ts +11 -0
- package/dist/runtime/host-diagnostics.js +192 -0
- package/dist/runtime/host-execution-root.d.ts +4 -0
- package/dist/runtime/host-execution-root.js +39 -0
- package/dist/runtime/host-facts.d.ts +35 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-listener-inspector.d.ts +8 -1
- package/dist/runtime/host-listener-inspector.js +121 -60
- 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 +13 -1
- package/dist/runtime/host-runtime-contract.js +170 -55
- package/dist/runtime/host-runtime-lease.d.ts +92 -8
- package/dist/runtime/host-runtime-lease.js +1193 -120
- package/dist/runtime/host-runtime-promotion.d.ts +12 -3
- package/dist/runtime/host-runtime-promotion.js +59 -12
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +607 -0
- package/dist/runtime/memory-capacity.d.ts +70 -0
- package/dist/runtime/memory-capacity.js +123 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +25 -0
- package/dist/runtime/native-test-postgres-fallback.js +91 -0
- package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
- package/dist/runtime/node-host-runtime-adapter.js +29 -11
- package/dist/runtime/pinned-directory-process.d.ts +9 -0
- package/dist/runtime/pinned-directory-process.js +61 -0
- package/dist/runtime/pinned-source-directory.d.ts +17 -0
- package/dist/runtime/pinned-source-directory.js +94 -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 +12 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +100 -58
- package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
- package/dist/runtime/prepared-runtime-identity.js +218 -0
- package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
- package/dist/runtime/prepared-runtime-readiness.js +285 -0
- package/dist/runtime/runtime-isolation-lease.js +4 -1
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- package/dist/sandbox/repository-lock.d.ts +2 -1
- package/dist/sandbox/repository-lock.js +19 -9
- package/dist/sandbox/runtime.d.ts +6 -1
- package/dist/sandbox/runtime.js +137 -107
- package/dist/sandbox/sandbox.types.d.ts +7 -0
- package/dist/sandbox/workspace.service.js +2 -0
- package/dist/session/managed-attempt-tools.d.ts +42 -1
- package/dist/session/managed-attempt-tools.js +692 -40
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +109 -0
- package/dist/session/managed-build-receipt.d.ts +21 -0
- package/dist/session/managed-build-receipt.js +337 -0
- package/dist/session/managed-verification-timeouts.d.ts +8 -0
- package/dist/session/managed-verification-timeouts.js +17 -0
- package/dist/session/phase-completion.artifacts.d.ts +17 -0
- package/dist/session/phase-completion.artifacts.js +228 -22
- package/dist/session/phase-completion.d.ts +11 -1
- package/dist/session/phase-completion.helpers.d.ts +5 -0
- package/dist/session/phase-completion.helpers.js +30 -7
- package/dist/session/phase-completion.js +14 -3
- package/dist/session/phase-completion.prompts.js +17 -18
- package/dist/session/phase-completion.runtime.d.ts +3 -1
- package/dist/session/phase-completion.runtime.js +148 -34
- package/dist/session/phase-completion.schemas.js +49 -2
- package/dist/session/phase-completion.validation.d.ts +1 -0
- package/dist/session/phase-completion.validation.js +111 -21
- 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.d.ts +75 -0
- package/dist/session/pre-publication-validation.js +631 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
- package/dist/session/provider-cli/ci-repair-readiness.d.ts +8 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
- package/dist/session/provider-cli/provider-cli.deterministic.js +34 -2
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +80 -0
- package/dist/session/provider-cli/provider-cli.process.js +694 -28
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +151 -16
- package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +14 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +54 -3
- package/dist/session/provider-cli/provider-cli.service.d.ts +30 -5
- package/dist/session/provider-cli/provider-cli.service.js +858 -77
- package/dist/session/provider-cli/provider-cli.types.d.ts +2 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +16 -0
- package/dist/session/provider-cli/provider-output-state.js +370 -17
- package/dist/session/provider-cli/provider-usage.d.ts +9 -1
- package/dist/session/provider-cli/provider-usage.js +28 -5
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/session-redaction.js +434 -9
- package/dist/session/session.service.js +145 -23
- package/dist/session/session.types.d.ts +147 -2
- package/dist/session/session.types.js +599 -7
- package/dist/session/unreferenced-exports.d.ts +12 -0
- package/dist/session/unreferenced-exports.js +59 -0
- package/dist/shared/format/format-bytes.d.ts +1 -0
- package/dist/shared/format/format-bytes.js +9 -0
- package/dist/shared/git/git.js +2 -1
- package/dist/shared/path/path.d.ts +1 -0
- package/dist/shared/path/path.js +18 -0
- package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
- package/dist/shared/process/dotnet-toolchain.js +307 -0
- package/dist/shared/process/host-process-recovery.js +3 -2
- package/dist/shared/process/host-process-supervisor.d.ts +2 -0
- package/dist/shared/process/host-process-supervisor.js +60 -11
- package/dist/shared/process/process.d.ts +2 -0
- package/dist/shared/process/process.js +12 -7
- package/dist/shared/provider-capabilities.d.ts +3 -0
- package/dist/shared/provider-capabilities.js +85 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +39 -3
- package/dist/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +41 -9
- package/dist/worktree/dependency-warmer.js +571 -22
- package/dist/worktree/index.d.ts +1 -1
- package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
- package/dist/worktree/story-qa-reference-hydrator.js +253 -0
- package/dist/worktree/worktree.service.d.ts +7 -0
- package/dist/worktree/worktree.service.js +253 -21
- package/dist/worktree/worktree.types.d.ts +7 -1
- package/package.json +7 -5
- package/runtime/windows-job-supervisor.ps1 +380 -14
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
/** `.local/`, `.forge/work-items/` and `.forge/stories/`: never published, even during a merge. */
|
|
20
|
+
export declare function isRuntimeOnlyPath(relativePath: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Stages every publishable worktree change in the real index and returns both sets.
|
|
23
|
+
*
|
|
24
|
+
* During an in-progress merge it first refuses unresolved conflicts, and afterwards
|
|
25
|
+
* restores merge-owned paths that the exclusion unstaged back to HEAD (the story side),
|
|
26
|
+
* such as `.forge/` files the target branch added (#491). Runtime-only paths are never
|
|
27
|
+
* restored.
|
|
28
|
+
*/
|
|
29
|
+
export declare function stagePublishableWorktreeChangeSet(git: Pick<GitClient, "run">, worktreePath: string): Promise<PublishableWorktreeChangeSet>;
|
|
30
|
+
/**
|
|
31
|
+
* Computes the same change set as {@link stagePublishableWorktreeChangeSet} without
|
|
32
|
+
* touching the worktree's index, using a throwaway copy of it. Returns null when
|
|
33
|
+
* `worktreePath` is not the root of a git worktree.
|
|
34
|
+
*/
|
|
35
|
+
export declare function readPublishableWorktreeChangeSet(worktreePath: string, processRunner?: ProcessRunner): Promise<PublishableWorktreeChangeSet | null>;
|
|
36
|
+
/** Compares claimed `changed_files` paths with the publishable diff. */
|
|
37
|
+
export declare function diffClaimedChangedFiles(claimedPaths: readonly string[], publishablePaths: readonly string[]): {
|
|
38
|
+
readonly missing: readonly string[];
|
|
39
|
+
readonly unexpected: readonly string[];
|
|
40
|
+
};
|
|
41
|
+
export declare function normalizeChangedFilePath(value: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* In-tool check for `forge.complete_comment_repair`: rejects a pass payload whose
|
|
44
|
+
* `changed_files` differs from what Forge would publish, so the agent can correct it
|
|
45
|
+
* in the same turn instead of failing at publication.
|
|
46
|
+
*/
|
|
47
|
+
export declare function assertClaimedChangedFilesMatchPublishableDiff(worktreePath: string, payload: Record<string, unknown>, toolName: string, processRunner?: ProcessRunner): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the given paths whose worktree content differs from HEAD but is not in the
|
|
50
|
+
* publishable set: excluded runtime output, and untracked or git-ignored files that are
|
|
51
|
+
* never staged at all (for example an injected `.forge/` file in a repository that ignores
|
|
52
|
+
* `.forge/`). A review finding on such a path cannot be fixed by the published commit.
|
|
53
|
+
*/
|
|
54
|
+
export declare function findUnpublishedWorktreePaths(git: Pick<GitClient, "run">, worktreePath: string, paths: readonly string[], publishablePaths: readonly string[]): Promise<readonly string[]>;
|
|
@@ -0,0 +1,193 @@
|
|
|
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
|
+
import { assertNoUnresolvedMergeConflicts, restoreMergeOwnedPaths } from "./provider-cli/provider-cli.merge-integrity.js";
|
|
7
|
+
/**
|
|
8
|
+
* Forge runtime output that is never published, whether or not the target repository
|
|
9
|
+
* tracks other `.forge/` content. Completion artifacts and evidence live here.
|
|
10
|
+
*/
|
|
11
|
+
const runtimeOnlyPathPrefixes = [".local/", ".forge/work-items/", ".forge/stories/"];
|
|
12
|
+
const resetBatchSize = 200;
|
|
13
|
+
/**
|
|
14
|
+
* Decides whether a staged change is Forge runtime output rather than an author edit.
|
|
15
|
+
*
|
|
16
|
+
* `.local/`, `.forge/work-items/` and `.forge/stories/` are always runtime output. Any
|
|
17
|
+
* other `.forge/` path is runtime output only when HEAD does not track it (status `A`):
|
|
18
|
+
* that covers injected managed commands, hooks and skills. The injector never overwrites a
|
|
19
|
+
* tracked `.forge/` file and restores one that matches the managed body, so a tracked
|
|
20
|
+
* `.forge/` file that differs from HEAD is an author edit and must be published.
|
|
21
|
+
*/
|
|
22
|
+
export function isNonPublishableWorktreeChange(relativePath, status) {
|
|
23
|
+
const normalized = relativePath.trim().replaceAll("\\", "/");
|
|
24
|
+
if (isRuntimeOnlyPath(normalized)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (normalized === ".forge" || normalized.startsWith(".forge/")) {
|
|
28
|
+
return status.trim().toUpperCase().startsWith("A");
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
/** `.local/`, `.forge/work-items/` and `.forge/stories/`: never published, even during a merge. */
|
|
33
|
+
export function isRuntimeOnlyPath(relativePath) {
|
|
34
|
+
const normalizedPath = normalizeChangedFilePath(relativePath);
|
|
35
|
+
return normalizedPath === ".local" || runtimeOnlyPathPrefixes.some(prefix => normalizedPath.startsWith(prefix));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Stages every publishable worktree change in the real index and returns both sets.
|
|
39
|
+
*
|
|
40
|
+
* During an in-progress merge it first refuses unresolved conflicts, and afterwards
|
|
41
|
+
* restores merge-owned paths that the exclusion unstaged back to HEAD (the story side),
|
|
42
|
+
* such as `.forge/` files the target branch added (#491). Runtime-only paths are never
|
|
43
|
+
* restored.
|
|
44
|
+
*/
|
|
45
|
+
export async function stagePublishableWorktreeChangeSet(git, worktreePath) {
|
|
46
|
+
await assertNoUnresolvedMergeConflicts(git, worktreePath);
|
|
47
|
+
await git.run(worktreePath, ["add", "-A"]);
|
|
48
|
+
const excludedChanges = (await readStagedChanges(git, worktreePath))
|
|
49
|
+
.filter(change => isNonPublishableWorktreeChange(change.path, change.status))
|
|
50
|
+
.map(change => change.path);
|
|
51
|
+
for (let index = 0; index < excludedChanges.length; index += resetBatchSize) {
|
|
52
|
+
const batch = excludedChanges.slice(index, index + resetBatchSize).map(filePath => `:(literal)${filePath}`);
|
|
53
|
+
await git.run(worktreePath, ["reset", "-q", "--", ...batch]);
|
|
54
|
+
}
|
|
55
|
+
const restored = new Set(await restoreMergeOwnedPaths(git, worktreePath, excludedChanges.filter(filePath => !isRuntimeOnlyPath(filePath))));
|
|
56
|
+
const excluded = excludedChanges.filter(filePath => !restored.has(filePath));
|
|
57
|
+
const publishable = (await git.run(worktreePath, ["diff", "--cached", "--name-only"]))
|
|
58
|
+
.split(/\r?\n/)
|
|
59
|
+
.map(line => line.trim())
|
|
60
|
+
.filter(Boolean);
|
|
61
|
+
return { publishable, excluded: [...new Set(excluded)].sort() };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Computes the same change set as {@link stagePublishableWorktreeChangeSet} without
|
|
65
|
+
* touching the worktree's index, using a throwaway copy of it. Returns null when
|
|
66
|
+
* `worktreePath` is not the root of a git worktree.
|
|
67
|
+
*/
|
|
68
|
+
export async function readPublishableWorktreeChangeSet(worktreePath, processRunner = new NodeProcessRunner()) {
|
|
69
|
+
const resolvedWorktree = path.resolve(worktreePath);
|
|
70
|
+
const git = new GitClient(processRunner);
|
|
71
|
+
let topLevel;
|
|
72
|
+
try {
|
|
73
|
+
topLevel = (await git.run(resolvedWorktree, ["rev-parse", "--show-toplevel"])).trim();
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
if (!topLevel || !await samePath(topLevel, resolvedWorktree)) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const realIndex = path.resolve(resolvedWorktree, (await git.run(resolvedWorktree, ["rev-parse", "--git-path", "index"])).trim());
|
|
82
|
+
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "forge-publishable-index-"));
|
|
83
|
+
try {
|
|
84
|
+
const tempIndex = path.join(tempRoot, "index");
|
|
85
|
+
await fs.copyFile(realIndex, tempIndex).catch((error) => {
|
|
86
|
+
if (error.code !== "ENOENT")
|
|
87
|
+
throw error;
|
|
88
|
+
});
|
|
89
|
+
const tempIndexGit = new GitClient({
|
|
90
|
+
run: request => processRunner.run({
|
|
91
|
+
...request,
|
|
92
|
+
env: { ...(request.env ?? process.env), GIT_INDEX_FILE: tempIndex },
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
return await stagePublishableWorktreeChangeSet(tempIndexGit, resolvedWorktree);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
await fs.rm(tempRoot, { recursive: true, force: true });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Compares claimed `changed_files` paths with the publishable diff. */
|
|
102
|
+
export function diffClaimedChangedFiles(claimedPaths, publishablePaths) {
|
|
103
|
+
const claimed = new Set(claimedPaths.map(normalizeChangedFilePath).filter(Boolean));
|
|
104
|
+
const actual = new Set(publishablePaths.map(normalizeChangedFilePath).filter(Boolean));
|
|
105
|
+
return {
|
|
106
|
+
missing: [...actual].filter(filePath => !claimed.has(filePath)).sort(),
|
|
107
|
+
unexpected: [...claimed].filter(filePath => !actual.has(filePath)).sort(),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export function normalizeChangedFilePath(value) {
|
|
111
|
+
return value.trim().replaceAll("\\", "/");
|
|
112
|
+
}
|
|
113
|
+
async function readStagedChanges(git, worktreePath) {
|
|
114
|
+
const fields = (await git.run(worktreePath, ["diff", "--cached", "--name-status", "--no-renames", "-z"]))
|
|
115
|
+
.split("\0");
|
|
116
|
+
const changes = [];
|
|
117
|
+
for (let index = 0; index + 1 < fields.length; index += 2) {
|
|
118
|
+
const status = fields[index].trim();
|
|
119
|
+
const filePath = fields[index + 1];
|
|
120
|
+
if (status && filePath)
|
|
121
|
+
changes.push({ status, path: filePath });
|
|
122
|
+
}
|
|
123
|
+
return changes;
|
|
124
|
+
}
|
|
125
|
+
async function samePath(left, right) {
|
|
126
|
+
const [realLeft, realRight] = await Promise.all([
|
|
127
|
+
fs.realpath(left).catch(() => path.resolve(left)),
|
|
128
|
+
fs.realpath(right).catch(() => path.resolve(right)),
|
|
129
|
+
]);
|
|
130
|
+
return process.platform === "win32"
|
|
131
|
+
? realLeft.toLowerCase() === realRight.toLowerCase()
|
|
132
|
+
: realLeft === realRight;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* In-tool check for `forge.complete_comment_repair`: rejects a pass payload whose
|
|
136
|
+
* `changed_files` differs from what Forge would publish, so the agent can correct it
|
|
137
|
+
* in the same turn instead of failing at publication.
|
|
138
|
+
*/
|
|
139
|
+
export async function assertClaimedChangedFilesMatchPublishableDiff(worktreePath, payload, toolName, processRunner) {
|
|
140
|
+
const changeSet = await readPublishableWorktreeChangeSet(worktreePath, processRunner);
|
|
141
|
+
if (!changeSet)
|
|
142
|
+
return;
|
|
143
|
+
const claimed = Array.isArray(payload.changed_files)
|
|
144
|
+
? payload.changed_files.map(value => String(value?.path ?? ""))
|
|
145
|
+
: [];
|
|
146
|
+
const { missing, unexpected } = diffClaimedChangedFiles(claimed, changeSet.publishable);
|
|
147
|
+
if (missing.length === 0 && unexpected.length === 0)
|
|
148
|
+
return;
|
|
149
|
+
const details = [
|
|
150
|
+
missing.length > 0 ? `Publishable changes missing from changed_files: ${missing.join(", ")}.` : "",
|
|
151
|
+
unexpected.length > 0 ? `changed_files entries that Forge will not publish: ${unexpected.join(", ")}.` : "",
|
|
152
|
+
].filter(Boolean).join(" ");
|
|
153
|
+
throw new Error(`changed_files must list exactly the files Forge will publish. ${details} `
|
|
154
|
+
+ "Forge publishes every source change, including edits to tracked .forge/ files; it never publishes "
|
|
155
|
+
+ ".local/, .forge/work-items/, .forge/stories/, or new untracked .forge/ files. "
|
|
156
|
+
+ `Correct changed_files (or the worktree) and call ${toolName} again.`);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Returns the given paths whose worktree content differs from HEAD but is not in the
|
|
160
|
+
* publishable set: excluded runtime output, and untracked or git-ignored files that are
|
|
161
|
+
* never staged at all (for example an injected `.forge/` file in a repository that ignores
|
|
162
|
+
* `.forge/`). A review finding on such a path cannot be fixed by the published commit.
|
|
163
|
+
*/
|
|
164
|
+
export async function findUnpublishedWorktreePaths(git, worktreePath, paths, publishablePaths) {
|
|
165
|
+
const candidates = [...new Set(paths.map(normalizeChangedFilePath).filter(Boolean))];
|
|
166
|
+
if (candidates.length === 0)
|
|
167
|
+
return [];
|
|
168
|
+
const publishable = new Set(publishablePaths.map(normalizeChangedFilePath));
|
|
169
|
+
const unpublished = new Set();
|
|
170
|
+
for (let index = 0; index < candidates.length; index += resetBatchSize) {
|
|
171
|
+
const batch = candidates.slice(index, index + resetBatchSize).map(filePath => `:(literal)${filePath}`);
|
|
172
|
+
const output = await git.run(worktreePath, [
|
|
173
|
+
// `traditional` with `--untracked-files=all` lists each file inside an ignored directory.
|
|
174
|
+
"status", "--porcelain=v1", "-z", "--no-renames", "--ignored=traditional", "--untracked-files=all", "--", ...batch,
|
|
175
|
+
]);
|
|
176
|
+
for (const entry of output.split("\0")) {
|
|
177
|
+
if (entry.length < 4)
|
|
178
|
+
continue;
|
|
179
|
+
const reported = normalizeChangedFilePath(entry.slice(3));
|
|
180
|
+
if (!reported)
|
|
181
|
+
continue;
|
|
182
|
+
// A collapsed directory entry ("dir/") covers every candidate beneath it.
|
|
183
|
+
const matches = reported.endsWith("/")
|
|
184
|
+
? candidates.filter(candidate => candidate.startsWith(reported))
|
|
185
|
+
: [reported];
|
|
186
|
+
for (const filePath of matches) {
|
|
187
|
+
if (!publishable.has(filePath))
|
|
188
|
+
unpublished.add(filePath);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return [...unpublished].sort();
|
|
193
|
+
}
|