@loucompanion/forge-bridge 0.1.4-dev.63db04bcffca → 0.1.4-dev.81e48ecc185d
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 +54 -2
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +125 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +85 -3
- package/dist/bridge/bridge.service.js +361 -122
- package/dist/bridge/bridge.types.d.ts +22 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/runner-host-capabilities.d.ts +2 -0
- package/dist/bridge/runner-host-capabilities.js +4 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +72 -109
- package/dist/cleanup/cleanup.types.d.ts +4 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +18 -0
- package/dist/cli/cli.service.d.ts +16 -0
- package/dist/cli/cli.service.js +142 -16
- package/dist/cli/local-config.d.ts +4 -0
- package/dist/cli/local-config.js +26 -4
- package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
- package/dist/runtime/attempt-process-supervisor.d.ts +19 -0
- package/dist/runtime/attempt-process-supervisor.js +50 -0
- 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-admission.d.ts +64 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +184 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +185 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +126 -0
- package/dist/runtime/host-load-sampler.js +232 -0
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +4 -0
- package/dist/runtime/host-runtime-contract.js +6 -1
- package/dist/runtime/host-runtime-lease.d.ts +74 -4
- package/dist/runtime/host-runtime-lease.js +336 -20
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +48 -0
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +607 -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 +18 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
- package/dist/runtime/runner-settings.d.ts +100 -0
- package/dist/runtime/runner-settings.js +214 -0
- package/dist/sandbox/host-capacity-broker.d.ts +113 -0
- package/dist/sandbox/host-capacity-broker.js +334 -0
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +45 -2
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/session/managed-attempt-tools.d.ts +27 -0
- package/dist/session/managed-attempt-tools.js +356 -41
- package/dist/session/managed-build-coordinator.d.ts +1 -1
- package/dist/session/managed-build-coordinator.js +4 -1
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +98 -25
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +4 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +4 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -3
- package/dist/session/phase-completion.runtime.js +70 -35
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +206 -221
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +46 -92
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +23 -0
- package/dist/session/pre-publication-process.js +109 -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-step-execution.d.ts +11 -0
- package/dist/session/pre-publication-step-execution.js +49 -0
- package/dist/session/pre-publication-validation.d.ts +32 -20
- package/dist/session/pre-publication-validation.js +202 -195
- package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
- 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 +39 -2
- package/dist/session/provider-cli/provider-cli.process.js +276 -42
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +65 -10
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +203 -172
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
- package/dist/session/provider-cli/provider-output-state.js +15 -0
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +238 -0
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +9 -2
- package/dist/session/session.service.js +120 -5
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +15 -3
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +1 -1
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- package/dist/shared/provider-capabilities.js +5 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/worktree.service.d.ts +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +2 -2
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ForgeFailureError } from "../session.types.js";
|
|
4
|
+
const maxListedPaths = 20;
|
|
5
|
+
const pathArgumentChunkSize = 100;
|
|
6
|
+
const objectIdPattern = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/iu;
|
|
7
|
+
/**
|
|
8
|
+
* The publication would re-add files that the target branch deleted, or revert
|
|
9
|
+
* target-branch edits, on paths the story never changed. Forge refuses to commit
|
|
10
|
+
* or push such a merge.
|
|
11
|
+
*/
|
|
12
|
+
export class MergeResolutionRevertsUpstreamChangesError extends ForgeFailureError {
|
|
13
|
+
merge;
|
|
14
|
+
resurrectedPaths;
|
|
15
|
+
revertedPaths;
|
|
16
|
+
code = "merge_resolution_reverts_upstream_changes";
|
|
17
|
+
constructor(merge, resurrectedPaths, revertedPaths) {
|
|
18
|
+
super("merge_resolution_reverts_upstream_changes", describeRevertedUpstreamChanges(merge, resurrectedPaths, revertedPaths), "bridge");
|
|
19
|
+
this.merge = merge;
|
|
20
|
+
this.resurrectedPaths = resurrectedPaths;
|
|
21
|
+
this.revertedPaths = revertedPaths;
|
|
22
|
+
this.name = "MergeResolutionRevertsUpstreamChangesError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A conflict is still unresolved when Forge would stage the merge: a
|
|
27
|
+
* modify/delete conflict nobody decided (`git add -A` would silently keep the
|
|
28
|
+
* modified side), or a content conflict whose file still has conflict markers
|
|
29
|
+
* (`git add -A` would commit them).
|
|
30
|
+
*/
|
|
31
|
+
export class MergeResolutionUnresolvedConflictError extends ForgeFailureError {
|
|
32
|
+
conflicts;
|
|
33
|
+
code = "merge_resolution_unresolved_conflict";
|
|
34
|
+
constructor(conflicts) {
|
|
35
|
+
super("merge_resolution_unresolved_conflict", `merge_resolution_unresolved_conflict: ${conflicts.length} merge conflict(s) were left unresolved: ${listPaths(conflicts.map(conflict => `${conflict.path} (${conflict.kind.replaceAll("_", " ")})`))}. Resolve content conflicts by removing every conflict marker, and resolve each modify/delete or binary conflict explicitly with \`git rm <path>\` to accept the deletion or \`git add <path>\` to stage the chosen file; Forge did not commit or push the merge.`, "bridge");
|
|
36
|
+
this.conflicts = conflicts;
|
|
37
|
+
this.name = "MergeResolutionUnresolvedConflictError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** True while MERGE_HEAD exists, whether or not the histories share a merge base. */
|
|
41
|
+
export async function isMergeInProgress(git, worktreePath) {
|
|
42
|
+
return await tryRevParse(git, worktreePath, "MERGE_HEAD") !== null;
|
|
43
|
+
}
|
|
44
|
+
export async function readInProgressMerge(git, worktreePath) {
|
|
45
|
+
const mergeHeadSha = await tryRevParse(git, worktreePath, "MERGE_HEAD");
|
|
46
|
+
if (!mergeHeadSha)
|
|
47
|
+
return null;
|
|
48
|
+
const headSha = await tryRevParse(git, worktreePath, "HEAD");
|
|
49
|
+
if (!headSha)
|
|
50
|
+
return null;
|
|
51
|
+
let mergeBaseSha;
|
|
52
|
+
try {
|
|
53
|
+
mergeBaseSha = (await git.run(worktreePath, ["merge-base", headSha, mergeHeadSha])).trim();
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// Unrelated histories have no merge base, so there is no upstream deletion to protect.
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
if (!objectIdPattern.test(mergeBaseSha))
|
|
60
|
+
return null;
|
|
61
|
+
return { headSha, mergeHeadSha, mergeBaseSha };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Fails before `git add -A` can silently resolve a conflict:
|
|
65
|
+
* - a modify/delete conflict, by keeping whatever is on disk;
|
|
66
|
+
* - a binary (or other marker-less) conflict, by staging whichever side is on disk;
|
|
67
|
+
* - a content conflict, by staging its conflict markers. This includes markers
|
|
68
|
+
* the provider already staged, which clears the unmerged stages, so every path
|
|
69
|
+
* both sides changed is checked too.
|
|
70
|
+
* A text conflict the agent resolved in the working tree without `git add` is
|
|
71
|
+
* still unmerged here and is accepted once its markers are gone.
|
|
72
|
+
*/
|
|
73
|
+
export async function assertNoUnresolvedMergeConflicts(git, worktreePath) {
|
|
74
|
+
const merge = await readInProgressMerge(git, worktreePath);
|
|
75
|
+
if (!merge)
|
|
76
|
+
return;
|
|
77
|
+
const conflicts = await readUnresolvedMergeConflicts(git, worktreePath, merge);
|
|
78
|
+
if (conflicts.length > 0) {
|
|
79
|
+
throw new MergeResolutionUnresolvedConflictError(conflicts);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export async function readUnresolvedMergeConflicts(git, worktreePath, merge) {
|
|
83
|
+
const stagesByPath = new Map();
|
|
84
|
+
for (const record of splitNul(await git.run(worktreePath, ["ls-files", "--unmerged", "-z"]))) {
|
|
85
|
+
const tab = record.indexOf("\t");
|
|
86
|
+
if (tab < 0)
|
|
87
|
+
continue;
|
|
88
|
+
const stage = record.slice(0, tab).trim().split(/\s+/u).at(-1) ?? "";
|
|
89
|
+
const filePath = record.slice(tab + 1);
|
|
90
|
+
const stages = stagesByPath.get(filePath) ?? new Set();
|
|
91
|
+
stages.add(stage);
|
|
92
|
+
stagesByPath.set(filePath, stages);
|
|
93
|
+
}
|
|
94
|
+
const conflicts = [];
|
|
95
|
+
const contentConflicts = [];
|
|
96
|
+
for (const [filePath, stages] of stagesByPath) {
|
|
97
|
+
const ours = stages.has("2");
|
|
98
|
+
const theirs = stages.has("3");
|
|
99
|
+
if (stages.has("1") && ours && !theirs)
|
|
100
|
+
conflicts.push({ path: filePath, kind: "deleted_by_upstream" });
|
|
101
|
+
else if (stages.has("1") && theirs && !ours)
|
|
102
|
+
conflicts.push({ path: filePath, kind: "deleted_by_story" });
|
|
103
|
+
else
|
|
104
|
+
contentConflicts.push(filePath);
|
|
105
|
+
}
|
|
106
|
+
const binaryByAttributes = await readBinaryByAttributes(git, worktreePath, contentConflicts);
|
|
107
|
+
for (const filePath of contentConflicts) {
|
|
108
|
+
const content = await readWorkingFile(worktreePath, filePath);
|
|
109
|
+
// `git add -A` would stage a missing file as a deletion and clear the conflict
|
|
110
|
+
// stages; only an explicit `git rm` or `git add` resolves it.
|
|
111
|
+
if (!content)
|
|
112
|
+
conflicts.push({ path: filePath, kind: "missing_while_unmerged" });
|
|
113
|
+
// Git writes no markers into a binary conflict (by content, or via `-merge` /
|
|
114
|
+
// `merge=binary`, as the `binary` macro sets), so only an explicit `git add` resolves it.
|
|
115
|
+
else if (binaryByAttributes.has(filePath) || isBinary(content))
|
|
116
|
+
conflicts.push({ path: filePath, kind: "unresolved_binary" });
|
|
117
|
+
else if (hasConflictMarkers(content))
|
|
118
|
+
conflicts.push({ path: filePath, kind: "conflict_markers" });
|
|
119
|
+
}
|
|
120
|
+
const storyChanged = new Set(await diffNames(git, worktreePath, [merge.mergeBaseSha, merge.headSha]));
|
|
121
|
+
const bothChanged = (await diffNames(git, worktreePath, [merge.mergeBaseSha, merge.mergeHeadSha]))
|
|
122
|
+
.filter(filePath => storyChanged.has(filePath) && !stagesByPath.has(filePath));
|
|
123
|
+
for (const filePath of bothChanged) {
|
|
124
|
+
const content = await readWorkingFile(worktreePath, filePath);
|
|
125
|
+
if (content && !isBinary(content) && hasConflictMarkers(content)) {
|
|
126
|
+
conflicts.push({ path: filePath, kind: "conflict_markers" });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return conflicts.sort((left, right) => left.path.localeCompare(right.path));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Staging excludes some worktree changes (Forge runtime output) by unstaging them
|
|
133
|
+
* back to HEAD. During a merge HEAD is the story side, so an excluded path the merge
|
|
134
|
+
* itself changed would lose the target's change. Given the excluded candidate
|
|
135
|
+
* paths, put the merge-owned ones back into the index: the target branch's version
|
|
136
|
+
* where the story never touched the path, and the agent's working-tree resolution
|
|
137
|
+
* where both sides changed it. Returns the restored paths; the rest stay excluded.
|
|
138
|
+
*/
|
|
139
|
+
export async function restoreMergeOwnedPaths(git, worktreePath, candidatePaths) {
|
|
140
|
+
if (candidatePaths.length === 0)
|
|
141
|
+
return [];
|
|
142
|
+
const merge = await readInProgressMerge(git, worktreePath);
|
|
143
|
+
if (!merge)
|
|
144
|
+
return [];
|
|
145
|
+
const candidates = new Set(candidatePaths);
|
|
146
|
+
const upstreamChanged = (await diffNames(git, worktreePath, [merge.mergeBaseSha, merge.mergeHeadSha]))
|
|
147
|
+
.filter(filePath => candidates.has(filePath));
|
|
148
|
+
if (upstreamChanged.length === 0)
|
|
149
|
+
return [];
|
|
150
|
+
const storyChanged = new Set(await diffNames(git, worktreePath, [merge.mergeBaseSha, merge.headSha]));
|
|
151
|
+
const upstreamOnly = upstreamChanged.filter(filePath => !storyChanged.has(filePath));
|
|
152
|
+
const bothChanged = upstreamChanged.filter(filePath => storyChanged.has(filePath));
|
|
153
|
+
for (const chunk of chunks(upstreamOnly)) {
|
|
154
|
+
// Resetting from MERGE_HEAD also removes index entries the target branch deleted.
|
|
155
|
+
await git.run(worktreePath, ["--literal-pathspecs", "reset", "-q", merge.mergeHeadSha, "--", ...chunk]);
|
|
156
|
+
}
|
|
157
|
+
const indexed = new Set();
|
|
158
|
+
for (const chunk of chunks(bothChanged)) {
|
|
159
|
+
for (const filePath of splitNul(await git.run(worktreePath, ["--literal-pathspecs", "ls-files", "-z", "--", ...chunk]))) {
|
|
160
|
+
indexed.add(filePath);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const stageable = [];
|
|
164
|
+
for (const filePath of bothChanged) {
|
|
165
|
+
if (indexed.has(filePath) || await existsOnDisk(worktreePath, filePath))
|
|
166
|
+
stageable.push(filePath);
|
|
167
|
+
}
|
|
168
|
+
for (const chunk of chunks(stageable)) {
|
|
169
|
+
await git.run(worktreePath, ["--literal-pathspecs", "add", "-A", "--", ...chunk]);
|
|
170
|
+
}
|
|
171
|
+
return [...upstreamOnly, ...stageable].sort();
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Final check on the index Forge is about to commit. Throws when the merge
|
|
175
|
+
* resolution re-adds a path the target branch deleted, or drops a target-branch
|
|
176
|
+
* edit, on a path the story never changed.
|
|
177
|
+
*/
|
|
178
|
+
export async function assertMergeResolutionPreservesUpstreamChanges(git, worktreePath, options = {}) {
|
|
179
|
+
const merge = await readInProgressMerge(git, worktreePath);
|
|
180
|
+
if (!merge)
|
|
181
|
+
return { keptOverUpstreamDeletion: [] };
|
|
182
|
+
const upstream = await diffNameStatus(git, worktreePath, [merge.mergeBaseSha, merge.mergeHeadSha]);
|
|
183
|
+
if (upstream.size === 0)
|
|
184
|
+
return { keptOverUpstreamDeletion: [] };
|
|
185
|
+
const storyChanged = new Set(await diffNames(git, worktreePath, [merge.mergeBaseSha, merge.headSha]));
|
|
186
|
+
// Index compared with the merge base: a path absent here is identical to the base.
|
|
187
|
+
const indexVersusBase = await diffNameStatus(git, worktreePath, ["--cached", merge.mergeBaseSha]);
|
|
188
|
+
const resurrectedPaths = [];
|
|
189
|
+
const revertedPaths = [];
|
|
190
|
+
const keptOverUpstreamDeletion = [];
|
|
191
|
+
for (const [filePath, status] of upstream) {
|
|
192
|
+
// Runtime-only paths are never published, so the story's version stays by design.
|
|
193
|
+
if (options.ignorePath?.(filePath))
|
|
194
|
+
continue;
|
|
195
|
+
const indexStatus = indexVersusBase.get(filePath);
|
|
196
|
+
if (status === "D") {
|
|
197
|
+
const presentInIndex = indexStatus !== "D";
|
|
198
|
+
if (!presentInIndex)
|
|
199
|
+
continue;
|
|
200
|
+
if (storyChanged.has(filePath))
|
|
201
|
+
keptOverUpstreamDeletion.push(filePath);
|
|
202
|
+
else
|
|
203
|
+
resurrectedPaths.push(filePath);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
// Equal to the base (undefined) or deleted: the target's edit is discarded. Other
|
|
207
|
+
// index content is a post-merge fixup on top of the target's version and is allowed.
|
|
208
|
+
if (!storyChanged.has(filePath) && (indexStatus === undefined || indexStatus === "D")) {
|
|
209
|
+
revertedPaths.push(filePath);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (resurrectedPaths.length > 0 || revertedPaths.length > 0) {
|
|
213
|
+
throw new MergeResolutionRevertsUpstreamChangesError(merge, resurrectedPaths.sort(), revertedPaths.sort());
|
|
214
|
+
}
|
|
215
|
+
return { keptOverUpstreamDeletion: keptOverUpstreamDeletion.sort() };
|
|
216
|
+
}
|
|
217
|
+
export function mergeResolutionCommitNotes(report) {
|
|
218
|
+
if (report.keptOverUpstreamDeletion.length === 0)
|
|
219
|
+
return [];
|
|
220
|
+
return [
|
|
221
|
+
`Kept ${report.keptOverUpstreamDeletion.length} story-modified path(s) that the target branch deleted (modify/delete conflicts resolved by the agent):\n${report.keptOverUpstreamDeletion.map(filePath => `- ${filePath}`).join("\n")}`,
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
function describeRevertedUpstreamChanges(merge, resurrectedPaths, revertedPaths) {
|
|
225
|
+
const parts = [];
|
|
226
|
+
if (resurrectedPaths.length > 0) {
|
|
227
|
+
parts.push(`re-adds ${resurrectedPaths.length} path(s) that ${merge.mergeHeadSha.slice(0, 12)} deleted and the story never changed: ${listPaths(resurrectedPaths)}`);
|
|
228
|
+
}
|
|
229
|
+
if (revertedPaths.length > 0) {
|
|
230
|
+
parts.push(`reverts or deletes ${revertedPaths.length} upstream edit(s) on path(s) the story never changed: ${listPaths(revertedPaths)}`);
|
|
231
|
+
}
|
|
232
|
+
return `merge_resolution_reverts_upstream_changes: the merge resolution ${parts.join("; and ")} (merge base ${merge.mergeBaseSha.slice(0, 12)}). Forge did not commit or push the merge.`;
|
|
233
|
+
}
|
|
234
|
+
function listPaths(paths) {
|
|
235
|
+
const listed = paths.slice(0, maxListedPaths).join(", ");
|
|
236
|
+
return paths.length > maxListedPaths ? `${listed}, and ${paths.length - maxListedPaths} more` : listed;
|
|
237
|
+
}
|
|
238
|
+
async function tryRevParse(git, worktreePath, ref) {
|
|
239
|
+
try {
|
|
240
|
+
const sha = (await git.run(worktreePath, ["rev-parse", "-q", "--verify", `${ref}^{commit}`])).trim();
|
|
241
|
+
return objectIdPattern.test(sha) ? sha : null;
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async function diffNames(git, worktreePath, args) {
|
|
248
|
+
return splitNul(await git.run(worktreePath, ["diff", "--no-renames", "--name-only", "-z", ...args]));
|
|
249
|
+
}
|
|
250
|
+
async function diffNameStatus(git, worktreePath, args) {
|
|
251
|
+
const fields = splitNul(await git.run(worktreePath, ["diff", "--no-renames", "--name-status", "-z", ...args]));
|
|
252
|
+
const statuses = new Map();
|
|
253
|
+
for (let index = 0; index + 1 < fields.length; index += 2) {
|
|
254
|
+
statuses.set(fields[index + 1], fields[index].charAt(0));
|
|
255
|
+
}
|
|
256
|
+
return statuses;
|
|
257
|
+
}
|
|
258
|
+
function splitNul(output) {
|
|
259
|
+
return output.split("\0").filter(entry => entry.length > 0);
|
|
260
|
+
}
|
|
261
|
+
function chunks(paths) {
|
|
262
|
+
const result = [];
|
|
263
|
+
for (let index = 0; index < paths.length; index += pathArgumentChunkSize) {
|
|
264
|
+
result.push(paths.slice(index, index + pathArgumentChunkSize));
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
const conflictMarkerPattern = /^<{7}(?: |$)[\s\S]*^>{7}(?: |$)/mu;
|
|
269
|
+
function hasConflictMarkers(content) {
|
|
270
|
+
return conflictMarkerPattern.test(content.toString("utf8"));
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Paths whose effective `merge` attribute selects Git's binary merge driver, which
|
|
274
|
+
* writes no conflict markers: `merge` unset (`-merge`, part of the `binary` macro) or
|
|
275
|
+
* `merge=binary`. `-text` and `-diff` do not change how Git merges, so they are ignored.
|
|
276
|
+
*/
|
|
277
|
+
async function readBinaryByAttributes(git, worktreePath, filePaths) {
|
|
278
|
+
const binary = new Set();
|
|
279
|
+
for (const chunk of chunks(filePaths)) {
|
|
280
|
+
const fields = splitNul(await git.run(worktreePath, ["check-attr", "-z", "merge", "--", ...chunk]));
|
|
281
|
+
for (let index = 0; index + 2 < fields.length; index += 3) {
|
|
282
|
+
const [filePath, value] = [fields[index], fields[index + 2]];
|
|
283
|
+
if (value === "unset" || value === "binary")
|
|
284
|
+
binary.add(filePath);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return binary;
|
|
288
|
+
}
|
|
289
|
+
function isBinary(content) {
|
|
290
|
+
// Git's own heuristic: a NUL byte in the first 8000 bytes.
|
|
291
|
+
return content.subarray(0, 8000).includes(0);
|
|
292
|
+
}
|
|
293
|
+
async function readWorkingFile(worktreePath, filePath) {
|
|
294
|
+
try {
|
|
295
|
+
return await fs.readFile(path.join(worktreePath, ...filePath.split("/")));
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
// Missing on disk: `git add -A` stages a deletion, which the upstream-change guard checks.
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
async function existsOnDisk(worktreePath, filePath) {
|
|
303
|
+
try {
|
|
304
|
+
await fs.lstat(path.join(worktreePath, ...filePath.split("/")));
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type LaunchCommand } from "../../shared/process/windows-launch.js";
|
|
2
|
+
import { ForgeFailureError } from "../session.types.js";
|
|
2
3
|
export declare const PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS: number;
|
|
3
4
|
export type ProviderCliCommand = LaunchCommand;
|
|
4
5
|
export interface ProviderProcessRunRequest {
|
|
@@ -14,7 +15,15 @@ export interface ProviderProcessRunRequest {
|
|
|
14
15
|
* supervisor and is never forwarded to the child process.
|
|
15
16
|
*/
|
|
16
17
|
readonly failureRedactionValues?: readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* The run resumes an existing provider thread. Such a run can replay a queued
|
|
20
|
+
* notification turn before the prompt's turn, and that replayed turn must not
|
|
21
|
+
* start the success ceiling.
|
|
22
|
+
*/
|
|
23
|
+
readonly resumesProviderThread?: boolean;
|
|
17
24
|
}
|
|
25
|
+
/** Why Forge stopped a provider still resident after its turn (or its background work, for Claude). */
|
|
26
|
+
export type ProviderTerminalStopReason = "turn_exit_grace" | "success_ceiling" | "turn_ended_with_background_work";
|
|
18
27
|
export interface ProviderProcessRunResult {
|
|
19
28
|
readonly exitCode: number;
|
|
20
29
|
readonly stdout: string;
|
|
@@ -23,6 +32,10 @@ export interface ProviderProcessRunResult {
|
|
|
23
32
|
readonly memorySampleCount?: number;
|
|
24
33
|
readonly memorySource?: string;
|
|
25
34
|
readonly memoryObservedAt?: string;
|
|
35
|
+
/** Present when the caller's cancellation stopped the process before it exited on its own. */
|
|
36
|
+
readonly cancelled?: true;
|
|
37
|
+
/** Present when Forge stopped a provider that stayed resident after its turn ended. */
|
|
38
|
+
readonly terminalStopReason?: ProviderTerminalStopReason;
|
|
26
39
|
}
|
|
27
40
|
export interface ProviderProcessRunner {
|
|
28
41
|
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
@@ -31,9 +44,23 @@ export interface ProviderProcessHandlers {
|
|
|
31
44
|
onStarted?(): Promise<void> | void;
|
|
32
45
|
onStdoutLine?(line: string): Promise<void> | void;
|
|
33
46
|
onStderrLine?(line: string): Promise<void> | void;
|
|
47
|
+
/**
|
|
48
|
+
* True while the provider has a tool call (such as an MCP tool call) in flight. While it
|
|
49
|
+
* is, or while an attempt-owned managed command is non-terminal, Forge suspends the
|
|
50
|
+
* end-of-turn exit grace and the success ceiling.
|
|
51
|
+
*/
|
|
52
|
+
isToolCallInFlight?(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Called before each provider generation (child process) starts, including every
|
|
55
|
+
* relaunch a recovery wrapper or supervisor makes with the same handlers. Per-generation
|
|
56
|
+
* state, such as tool calls in flight, must be reset here: a generation that exited mid
|
|
57
|
+
* call never reports that call's completion.
|
|
58
|
+
*/
|
|
59
|
+
onGenerationStart?(): void;
|
|
34
60
|
}
|
|
35
61
|
/** Recovery must wrap the attempt coordinator, never its raw OS runner. Each
|
|
36
|
-
* relaunch needs a new fenced child generation and exclusive launch files.
|
|
62
|
+
* relaunch needs a new fenced child generation and exclusive launch files. The outer
|
|
63
|
+
* layer fails any run Forge stopped because its turn ended with background work live. */
|
|
37
64
|
export declare function recoveringProviderProcessRunner(inner: ProviderProcessRunner): ProviderProcessRunner;
|
|
38
65
|
/**
|
|
39
66
|
* Codex Desktop and an independently installed Codex CLI can briefly disagree
|
|
@@ -70,11 +97,21 @@ interface ProviderChildEnvironmentOptions {
|
|
|
70
97
|
export declare function buildProviderChildEnvironment(requestEnv?: Readonly<Record<string, string>>, options?: ProviderChildEnvironmentOptions): NodeJS.ProcessEnv;
|
|
71
98
|
export declare class StreamingProviderProcessRunner implements ProviderProcessRunner {
|
|
72
99
|
private readonly terminalExitGraceMs;
|
|
73
|
-
|
|
100
|
+
private readonly terminalSuccessCeilingMs;
|
|
101
|
+
private readonly terminalWorkPollMs;
|
|
102
|
+
constructor(terminalExitGraceMs?: number, terminalSuccessCeilingMs?: number, terminalWorkPollMs?: number);
|
|
74
103
|
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
75
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* The typed failure for a provider run that ended without calling its required Forge
|
|
107
|
+
* completion tool. A run Forge stopped at the success ceiling or for background work is
|
|
108
|
+
* reported as such, so it is not mistaken for an agent that simply ended its turn.
|
|
109
|
+
*/
|
|
110
|
+
export declare function providerCompletionToolMissingFailure(message: string, result?: Pick<ProviderProcessRunResult, "terminalStopReason"> | null): ForgeFailureError;
|
|
76
111
|
/** Returns aggregate resident bytes for the exact supervised Unix process group. */
|
|
77
112
|
export declare function processGroupResidentMemoryBytes(processGroupId: number, platform?: NodeJS.Platform, procRoot?: string): number | null;
|
|
113
|
+
export declare const UNIX_PROVIDER_START_GRANT_LINE = "forge-provider-start-granted\n";
|
|
114
|
+
export declare function buildUnixProviderStartGateLaunch(command: string, args: readonly string[]): LaunchCommand;
|
|
78
115
|
export declare function resolveCodexNpmDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
|
|
79
116
|
/**
|
|
80
117
|
* npm installs of Claude Code (`npm i -g @anthropic-ai/claude-code`) put a `claude.cmd` shim on
|