@loucompanion/forge-bridge 0.2.1-dev.c3166221b6e7 → 0.2.1-dev.eac6976df5e9
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-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +22 -1
- package/dist/bridge/bridge-chat-provider-command.js +102 -4
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +12 -0
- package/dist/bridge/bridge.service.d.ts +2 -0
- package/dist/bridge/bridge.service.js +11 -31
- package/dist/runtime/host-load-admission.d.ts +5 -0
- package/dist/runtime/host-load-governor-config.d.ts +10 -1
- package/dist/runtime/host-load-governor-config.js +4 -1
- package/dist/runtime/host-load-governor.d.ts +8 -1
- package/dist/runtime/host-load-governor.js +33 -3
- package/dist/runtime/host-load-test-slot.js +7 -0
- package/dist/sandbox/runtime.js +1 -1
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +28 -8
- package/dist/session/sandbox-host-capacity-gate.js +1 -1
- package/dist/session/session.service.js +8 -4
- package/dist/session/session.types.d.ts +1 -0
- package/dist/session/session.types.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/wip-git.d.ts +9 -0
- package/dist/worktree/wip-git.js +21 -4
- package/dist/worktree/wip-refs.d.ts +15 -0
- package/dist/worktree/wip-refs.js +29 -2
- package/dist/worktree/wip-restore.d.ts +8 -0
- package/dist/worktree/wip-restore.js +115 -25
- package/dist/worktree/wip-snapshot.d.ts +5 -2
- package/dist/worktree/wip-snapshot.js +15 -13
- package/dist/worktree/worktree-origin-sync.d.ts +1 -0
- package/dist/worktree/worktree-origin-sync.js +1 -0
- package/dist/worktree/worktree-wip-events.js +19 -2
- package/dist/worktree/worktree-wip.d.ts +1 -0
- package/dist/worktree/worktree-wip.js +6 -1
- package/dist/worktree/worktree.service.js +2 -0
- package/dist/worktree/worktree.types.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { baseTrackedForgePaths, gitPath, hasPartialRestoreMarker, isWipExcludedPath, makeWipTempDir, readOptionalFile, splitNul, WipGit, } from "./wip-git.js";
|
|
4
|
-
import { formatWipCommitMessage,
|
|
3
|
+
import { baseTrackedForgePaths, gitPath, hasPartialRestoreMarker, isWipExcludedPath, makeWipTempDir, readOptionalFile, readReapplyConflictRecord, splitNul, WipGit, } from "./wip-git.js";
|
|
4
|
+
import { formatWipCommitMessage, issuedWipAttempt, WipPreservationError, wipMetadataSchema, wipRefId, wipRefName, wipSnapshotMaxBytes, } from "./wip-refs.js";
|
|
5
5
|
const mergeMessageLimit = 16 * 1024;
|
|
6
6
|
// Snapshots this process already pushed, keyed by worktree: a guard that finds the same state
|
|
7
7
|
// (for example the release right after a failed session's snapshot) does not push it twice. An
|
|
@@ -73,6 +73,8 @@ async function captureWorktree(request, context) {
|
|
|
73
73
|
const base = (await git.run(cwd, ["rev-parse", "--verify", `${request.orphan?.baseRef ?? "HEAD"}^{commit}`])).trim();
|
|
74
74
|
const baseTree = (await git.run(cwd, ["rev-parse", `${base}^{tree}`])).trim();
|
|
75
75
|
const merge = request.orphan ? null : await readMergeState(git, cwd);
|
|
76
|
+
const unmerged = request.orphan ? [] : splitNul(await git.run(cwd, ["ls-files", "-u", "-z"])).map(parseUnmergedEntry);
|
|
77
|
+
const reapplyConflicts = request.orphan ? [] : await readReapplyConflictRecord(git, cwd);
|
|
76
78
|
const forgePaths = await baseTrackedForgePaths(git, cwd, base);
|
|
77
79
|
const excluded = (filePath) => isWipExcludedPath(filePath, forgePaths);
|
|
78
80
|
const worktreeIndex = path.join(context.tempDir, "worktree.index");
|
|
@@ -83,13 +85,13 @@ async function captureWorktree(request, context) {
|
|
|
83
85
|
await copyIndex(worktreeIndex, stagedIndex);
|
|
84
86
|
const indexTree = request.orphan
|
|
85
87
|
? baseTree
|
|
86
|
-
: await writeStagedTree(git.with({ GIT_INDEX_FILE: stagedIndex }), cwd, base,
|
|
88
|
+
: await writeStagedTree(git.with({ GIT_INDEX_FILE: stagedIndex }), cwd, base, unmerged, excluded);
|
|
87
89
|
await indexGit.run(cwd, ["add", "-A"]);
|
|
88
90
|
const changed = await resetExcluded(indexGit, cwd, base, excluded);
|
|
89
91
|
const worktreeTree = (await indexGit.run(cwd, ["write-tree"])).trim();
|
|
90
|
-
if (worktreeTree === baseTree && indexTree === baseTree && !merge)
|
|
92
|
+
if (worktreeTree === baseTree && indexTree === baseTree && !merge && unmerged.length === 0)
|
|
91
93
|
return null;
|
|
92
|
-
return { base, worktreeTree, indexTree, merge, changedPaths: changed.length, bytes };
|
|
94
|
+
return { base, worktreeTree, indexTree, merge, unmerged, reapplyConflicts, changedPaths: changed.length, bytes };
|
|
93
95
|
}
|
|
94
96
|
/** A copy of the worktree's real index; the base tree when it has none or the checkout is orphaned. */
|
|
95
97
|
async function seedIndex(context, request, base, target) {
|
|
@@ -143,8 +145,8 @@ async function measureChanges(git, cwd, base, excluded, maxBytes) {
|
|
|
143
145
|
return total;
|
|
144
146
|
}
|
|
145
147
|
/** The staged state: the real index with unresolved conflicts and runtime output put back to the base. */
|
|
146
|
-
async function writeStagedTree(git, cwd, base,
|
|
147
|
-
const conflicted = [...new Set(
|
|
148
|
+
async function writeStagedTree(git, cwd, base, unmerged, excluded) {
|
|
149
|
+
const conflicted = [...new Set(unmerged.map(entry => entry.path))];
|
|
148
150
|
await git.runForPaths(cwd, ["reset", "-q", base], conflicted);
|
|
149
151
|
await resetExcluded(git, cwd, base, excluded);
|
|
150
152
|
return (await git.run(cwd, ["write-tree"])).trim();
|
|
@@ -165,12 +167,10 @@ async function readMergeState(git, cwd) {
|
|
|
165
167
|
return null;
|
|
166
168
|
const message = await readOptionalFile(await gitPath(git, cwd, "MERGE_MSG"));
|
|
167
169
|
const mode = await readOptionalFile(await gitPath(git, cwd, "MERGE_MODE"));
|
|
168
|
-
const unmerged = splitNul(await git.run(cwd, ["ls-files", "-u", "-z"])).map(parseUnmergedEntry);
|
|
169
170
|
return {
|
|
170
171
|
head,
|
|
171
172
|
message: message === null ? null : message.slice(0, mergeMessageLimit),
|
|
172
173
|
mode: mode?.trim() || null,
|
|
173
|
-
unmerged,
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
function parseUnmergedEntry(record) {
|
|
@@ -191,14 +191,15 @@ async function writeSnapshotCommits(request, capture, context) {
|
|
|
191
191
|
sessionId: request.sessionId?.trim() || null,
|
|
192
192
|
lane: request.lane?.trim() || null,
|
|
193
193
|
reason: request.reason,
|
|
194
|
-
attempt: request.attempt
|
|
194
|
+
attempt: issuedWipAttempt(request.attempt),
|
|
195
195
|
autoRestore: request.autoRestore,
|
|
196
196
|
createdAt: now.toISOString(),
|
|
197
197
|
createdAtMs: now.getTime(),
|
|
198
198
|
mergeHead: capture.merge?.head ?? null,
|
|
199
199
|
mergeMessage: capture.merge?.message ?? null,
|
|
200
200
|
mergeMode: capture.merge?.mode ?? null,
|
|
201
|
-
unmerged: capture.
|
|
201
|
+
unmerged: capture.unmerged,
|
|
202
|
+
reapplyConflicts: capture.reapplyConflicts,
|
|
202
203
|
changedPaths: capture.changedPaths,
|
|
203
204
|
bytes: capture.bytes,
|
|
204
205
|
};
|
|
@@ -214,7 +215,7 @@ async function writeSnapshotCommits(request, capture, context) {
|
|
|
214
215
|
*/
|
|
215
216
|
async function publishSnapshot(git, repoPath, request, commitSha) {
|
|
216
217
|
const now = (request.now ?? (() => new Date()))();
|
|
217
|
-
const ref = wipRefName(request.branchName, wipRefId(request.reason, request.sessionId, now, request.attempt));
|
|
218
|
+
const ref = wipRefName(request.branchName, wipRefId(request.reason, request.sessionId, now, issuedWipAttempt(request.attempt)));
|
|
218
219
|
const origin = (await git.tryRun(repoPath, ["remote", "get-url", "origin"]))?.trim();
|
|
219
220
|
if (!origin) {
|
|
220
221
|
await git.run(repoPath, ["update-ref", ref, commitSha]);
|
|
@@ -239,7 +240,8 @@ async function commonGitDir(git, repoPath) {
|
|
|
239
240
|
return path.isAbsolute(raw) ? raw : path.resolve(repoPath, raw);
|
|
240
241
|
}
|
|
241
242
|
function captureFingerprint(capture) {
|
|
242
|
-
|
|
243
|
+
const stages = capture.unmerged.map(entry => `${entry.stage}${entry.sha}${entry.path}`).join(",");
|
|
244
|
+
return [capture.base, capture.worktreeTree, capture.indexTree, capture.merge?.head ?? "", stages, capture.reapplyConflicts.join(",")].join(":");
|
|
243
245
|
}
|
|
244
246
|
function snapshotKey(worktreePath) {
|
|
245
247
|
const resolved = path.resolve(worktreePath);
|
|
@@ -44,6 +44,7 @@ export async function syncReusedWorktreeToOrigin(request) {
|
|
|
44
44
|
reason: "pre_sync",
|
|
45
45
|
sessionId: request.sessionId,
|
|
46
46
|
lane: request.lane,
|
|
47
|
+
attempt: request.wipAttempt,
|
|
47
48
|
// It was based on the old head, so a later pass must never apply it on the new one by itself.
|
|
48
49
|
autoRestore: false,
|
|
49
50
|
}).catch((error) => {
|
|
@@ -3,7 +3,10 @@ export async function emitWipRestoreEvent(worktree, emit) {
|
|
|
3
3
|
const outcome = worktree.wipRestore;
|
|
4
4
|
if (!outcome || outcome.status === "none")
|
|
5
5
|
return;
|
|
6
|
-
if (outcome.status === "restored") {
|
|
6
|
+
if (outcome.status === "restored" && outcome.reapplied) {
|
|
7
|
+
await emit(checkpoint("worktree_wip_restored", reappliedSummary(worktree.branchName, outcome, outcome.reapplied), outcome));
|
|
8
|
+
}
|
|
9
|
+
else if (outcome.status === "restored") {
|
|
7
10
|
await emit(checkpoint("worktree_wip_restored", `Restored uncommitted work saved in ${outcome.ref}${outcome.sourceSessionId ? ` by session ${outcome.sourceSessionId}` : ""} `
|
|
8
11
|
+ `(${outcome.changedPaths} path(s)${outcome.mergeInProgress ? ", with its merge still in progress" : ""}) onto ${worktree.branchName} before the provider started.`, outcome));
|
|
9
12
|
}
|
|
@@ -18,6 +21,20 @@ export async function emitWipRestoreEvent(worktree, emit) {
|
|
|
18
21
|
await emit(checkpoint("worktree_wip_restore_unavailable", `Could not check origin for saved uncommitted work on ${worktree.branchName}: ${outcome.detail}`, outcome));
|
|
19
22
|
}
|
|
20
23
|
}
|
|
24
|
+
/** The checkpoint for a snapshot re-applied across a branch move: clean, or with the paths left for the agent. */
|
|
25
|
+
function reappliedSummary(branchName, outcome, reapplied) {
|
|
26
|
+
const moved = `${branchName} had moved from ${reapplied.snapshotBaseHead.slice(0, 12)} to ${outcome.baseHead.slice(0, 12)} since it was saved`;
|
|
27
|
+
if (reapplied.conflictedPaths.length === 0) {
|
|
28
|
+
return `Re-applied the uncommitted work saved in ${outcome.ref} across a branch move (${moved}): a 3-way merge onto the new HEAD `
|
|
29
|
+
+ `was clean (${outcome.changedPaths} path(s)) and is restored before the provider started.`;
|
|
30
|
+
}
|
|
31
|
+
const listed = reapplied.conflictedPaths.slice(0, maxListedConflicts).join(", ");
|
|
32
|
+
const more = reapplied.conflictedPaths.length > maxListedConflicts ? ` and ${reapplied.conflictedPaths.length - maxListedConflicts} more` : "";
|
|
33
|
+
return `Re-applied the uncommitted work saved in ${outcome.ref} across a branch move with ${reapplied.conflictedPaths.length} conflict(s) `
|
|
34
|
+
+ `left for the agent to resolve: ${listed}${more}. ${moved}; the conflicted paths are unmerged with conflict markers, `
|
|
35
|
+
+ `Forge will not publish them unresolved, and the ref is kept on origin.`;
|
|
36
|
+
}
|
|
37
|
+
const maxListedConflicts = 20;
|
|
21
38
|
/** How a session ended, for the snapshot it leaves behind. */
|
|
22
39
|
export function sessionWipOutcome(signal, events, succeeded) {
|
|
23
40
|
if (succeeded)
|
|
@@ -72,7 +89,7 @@ async function emitSettlement(worktree, outcome, settlement, emit) {
|
|
|
72
89
|
const snapshot = settlement.snapshot;
|
|
73
90
|
if (snapshot && snapshot.status !== "clean") {
|
|
74
91
|
await emit(checkpoint("worktree_wip_saved", `Saved this session's uncommitted work (${snapshot.changedPaths} path(s)) to ${snapshot.ref}${snapshot.pushed ? " on origin" : " in the runner's repository (it has no origin)"} `
|
|
75
|
-
+ `before the session ended (${outcome.reason}). The next pass on ${worktree.branchName} restores it
|
|
92
|
+
+ `before the session ended (${outcome.reason}). The next pass on ${worktree.branchName} restores it, re-applying it if the branch has moved.`, { ...snapshot, reason: outcome.reason, lane: worktree.lane ?? null }));
|
|
76
93
|
}
|
|
77
94
|
if (settlement.error) {
|
|
78
95
|
await emit({
|
|
@@ -11,6 +11,7 @@ export { relinkOrphanedWorktree } from "./orphan-relink.js";
|
|
|
11
11
|
export declare function guardWorktreeReset(worktreePath: string, branchName: string, owner: {
|
|
12
12
|
readonly sessionId?: string | null;
|
|
13
13
|
readonly lane: string;
|
|
14
|
+
readonly wipAttempt?: number | null;
|
|
14
15
|
}): Promise<WipSnapshotResult>;
|
|
15
16
|
/**
|
|
16
17
|
* Before a local branch is re-pointed at a new start point (`worktree add -B`), saves any commits
|
|
@@ -8,7 +8,8 @@ import { forgetPreservedWip, forgetPreservedWipRef, preserveWorktreeWip } from "
|
|
|
8
8
|
// - every path that could destroy it (a reset to the base, re-pointing the branch, a release that
|
|
9
9
|
// deletes the checkout) saves it to a WIP ref first and does not run when that fails;
|
|
10
10
|
// - a session that ends without succeeding saves it under the session's id;
|
|
11
|
-
// - a publishing lane's next pass puts the newest snapshot back
|
|
11
|
+
// - a publishing lane's next pass puts the newest snapshot back, re-applying it with a 3-way merge
|
|
12
|
+
// when the branch has moved since (wip-restore.ts);
|
|
12
13
|
// - a checkout that lost only its `.git` link is reattached to Git's admin directory for it, which
|
|
13
14
|
// holds its index and MERGE_HEAD, instead of being recreated (orphan-relink.ts).
|
|
14
15
|
export { relinkOrphanedWorktree } from "./orphan-relink.js";
|
|
@@ -30,6 +31,7 @@ export async function guardWorktreeReset(worktreePath, branchName, owner) {
|
|
|
30
31
|
reason: "pre_reset",
|
|
31
32
|
sessionId: owner.sessionId,
|
|
32
33
|
lane: owner.lane,
|
|
34
|
+
attempt: owner.wipAttempt,
|
|
33
35
|
autoRestore: isWipRestoreLane(owner.lane),
|
|
34
36
|
});
|
|
35
37
|
}
|
|
@@ -84,6 +86,7 @@ async function branchTipSnapshot(repoPath, branchName, tip, now) {
|
|
|
84
86
|
mergeMessage: null,
|
|
85
87
|
mergeMode: null,
|
|
86
88
|
unmerged: [],
|
|
89
|
+
reapplyConflicts: [],
|
|
87
90
|
changedPaths: 0,
|
|
88
91
|
bytes: 0,
|
|
89
92
|
});
|
|
@@ -110,6 +113,7 @@ export async function guardWorktreeRelease(handle) {
|
|
|
110
113
|
reason: "pre_release",
|
|
111
114
|
sessionId: handle.sessionId,
|
|
112
115
|
lane: handle.lane,
|
|
116
|
+
attempt: handle.wipAttempt,
|
|
113
117
|
autoRestore: false,
|
|
114
118
|
});
|
|
115
119
|
}
|
|
@@ -134,6 +138,7 @@ export async function settleSessionWip(handle, outcome) {
|
|
|
134
138
|
reason: outcome.reason,
|
|
135
139
|
sessionId: handle.sessionId,
|
|
136
140
|
lane: handle.lane,
|
|
141
|
+
attempt: handle.wipAttempt,
|
|
137
142
|
autoRestore: isWipRestoreLane(handle.lane),
|
|
138
143
|
});
|
|
139
144
|
}
|
|
@@ -105,6 +105,7 @@ export class GitWorktreeService {
|
|
|
105
105
|
hydratedPriorPhaseArtifactCount,
|
|
106
106
|
sessionId: request.sessionId ?? null,
|
|
107
107
|
lane: request.lane,
|
|
108
|
+
wipAttempt: request.wipAttempt ?? null,
|
|
108
109
|
...preparedState,
|
|
109
110
|
};
|
|
110
111
|
}
|
|
@@ -168,6 +169,7 @@ export class GitWorktreeService {
|
|
|
168
169
|
branchName,
|
|
169
170
|
sessionId: request.sessionId,
|
|
170
171
|
lane: request.lane,
|
|
172
|
+
wipAttempt: request.wipAttempt,
|
|
171
173
|
log: this.log,
|
|
172
174
|
});
|
|
173
175
|
}
|
|
@@ -26,6 +26,8 @@ export interface WorktreePrepareRequest {
|
|
|
26
26
|
readonly preserveExistingState?: boolean;
|
|
27
27
|
/** The session this worktree is prepared for; names its WIP snapshots and enables restoring one. */
|
|
28
28
|
readonly sessionId?: string | null;
|
|
29
|
+
/** Forge's issued attempt for this dispatch (sandbox.wipAttempt), stamped on its WIP refs: newest work wins. */
|
|
30
|
+
readonly wipAttempt?: number | null;
|
|
29
31
|
/** The attempt dependency installs reserve host capacity for (decision 0013). */
|
|
30
32
|
readonly hostLoadOwner?: {
|
|
31
33
|
readonly dispatchAttemptId: string | null;
|
|
@@ -45,6 +47,8 @@ export interface WorktreeHandle {
|
|
|
45
47
|
readonly hydratedPriorPhaseArtifactCount?: number;
|
|
46
48
|
readonly sessionId?: string | null;
|
|
47
49
|
readonly lane?: string;
|
|
50
|
+
/** Forge's issued attempt for the dispatch the worktree was prepared for; null from older servers. */
|
|
51
|
+
readonly wipAttempt?: number | null;
|
|
48
52
|
/** What happened to the story's saved WIP when this worktree was prepared. */
|
|
49
53
|
readonly wipRestore?: WipRestoreOutcome;
|
|
50
54
|
/** Set when prepare moved a stale local branch or reused worktree up to origin's head. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loucompanion/forge-bridge",
|
|
3
|
-
"version": "0.2.1-dev.
|
|
3
|
+
"version": "0.2.1-dev.eac6976df5e9",
|
|
4
4
|
"description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|