@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 0.2.1-dev.0fedbc5c9ef7
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 -1
- 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 +27 -3
- package/dist/bridge/bridge-chat-provider-command.js +131 -26
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.service.d.ts +19 -12
- package/dist/bridge/bridge.service.js +155 -282
- package/dist/bridge/bridge.types.d.ts +5 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.js +14 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +56 -12
- package/dist/cli/cli.service.d.ts +3 -10
- package/dist/cli/cli.service.js +10 -171
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +2 -0
- package/dist/cli/local-config.js +7 -1
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- 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 +10 -1
- package/dist/runtime/host-load-governor.js +33 -3
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- package/dist/runtime/host-load-runtime-settings.js +4 -2
- package/dist/runtime/host-load-sampler.d.ts +8 -1
- package/dist/runtime/host-load-sampler.js +14 -7
- package/dist/runtime/host-load-test-slot.js +7 -0
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +29 -1
- package/dist/runtime/host-runtime-lease.d.ts +28 -3
- package/dist/runtime/host-runtime-lease.js +140 -296
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +78 -2
- package/dist/runtime/host-runtime-promotion.js +307 -14
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +13 -1
- package/dist/runtime/prepared-runtime-readiness.js +63 -16
- package/dist/runtime/runner-settings.d.ts +4 -0
- package/dist/runtime/runner-settings.js +22 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +3 -1
- package/dist/sandbox/host-capacity-broker.js +4 -2
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.js +3 -7
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +50 -82
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/phase-completion.artifacts.js +2 -1
- package/dist/session/phase-completion.d.ts +8 -0
- package/dist/session/phase-completion.js +1 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.runtime.d.ts +0 -8
- package/dist/session/phase-completion.runtime.js +43 -197
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-process.js +10 -10
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +7 -3
- package/dist/session/pre-publication-validation.js +32 -30
- package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
- package/dist/session/provider-cli/claude-background-work.js +4 -3
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
- package/dist/session/provider-cli/pre-publication-repair.js +33 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
- 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/provider-cli/provider-cli.process.d.ts +2 -14
- package/dist/session/provider-cli/provider-cli.process.js +4 -94
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +27 -27
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +23 -2
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +27 -43
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +35 -16
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.service.d.ts +6 -0
- package/dist/session/session.service.js +131 -88
- package/dist/session/session.types.d.ts +1 -0
- package/dist/session/session.types.js +3 -3
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/provider-capabilities.js +9 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +42 -0
- package/dist/worktree/wip-git.js +139 -0
- package/dist/worktree/wip-refs.d.ts +77 -0
- package/dist/worktree/wip-refs.js +146 -0
- package/dist/worktree/wip-restore.d.ts +46 -0
- package/dist/worktree/wip-restore.js +280 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +115 -0
- package/dist/worktree/worktree-wip.d.ts +51 -0
- package/dist/worktree/worktree-wip.js +190 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +27 -5
- package/dist/worktree/worktree.service.js +112 -181
- package/dist/worktree/worktree.types.d.ts +35 -0
- package/package.json +1 -1
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { isSubPath } from "../shared/path/path.js";
|
|
5
|
+
const restoreChunk = 200;
|
|
6
|
+
/**
|
|
7
|
+
* Reattaches a checkout that lost its `.git` link while Git still has its admin directory. That
|
|
8
|
+
* directory holds the checkout's index (staged changes, conflict stages), MERGE_HEAD and HEAD,
|
|
9
|
+
* none of which a WIP snapshot holds for an orphan; recreating the checkout would prune it. So
|
|
10
|
+
* when it is still there and on the lease branch, the link is rewritten instead, and tracked
|
|
11
|
+
* files missing from the checkout are put back from its index, as recreating it would put them
|
|
12
|
+
* back from the base. Returns false when there is no such directory or any step fails, with the
|
|
13
|
+
* `.git` link as it was, so recovery can fall back to recreating the checkout. Never throws.
|
|
14
|
+
*/
|
|
15
|
+
export async function relinkOrphanedWorktree(git, input) {
|
|
16
|
+
const dotGit = path.join(input.worktreePath, ".git");
|
|
17
|
+
let previous;
|
|
18
|
+
let adminDir;
|
|
19
|
+
try {
|
|
20
|
+
const existing = await fs.lstat(dotGit).catch((error) => {
|
|
21
|
+
if (error?.code === "ENOENT")
|
|
22
|
+
return null;
|
|
23
|
+
throw error;
|
|
24
|
+
});
|
|
25
|
+
// Only a missing or plain-file link is rewritten; a directory or symlink there is something else.
|
|
26
|
+
if (existing && !existing.isFile())
|
|
27
|
+
return false;
|
|
28
|
+
// A link that can't be read can't be put back, so it is never replaced.
|
|
29
|
+
previous = existing ? await fs.readFile(dotGit) : null;
|
|
30
|
+
adminDir = await findAdminDir(git, input);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (!adminDir)
|
|
36
|
+
return false;
|
|
37
|
+
try {
|
|
38
|
+
await replaceLink(dotGit, `gitdir: ${adminDir}\n`);
|
|
39
|
+
const branch = (await git.run(input.worktreePath, ["rev-parse", "--abbrev-ref", "HEAD"])).trim();
|
|
40
|
+
if (branch !== input.branchName)
|
|
41
|
+
throw new Error(`relinked checkout is on '${branch}'`);
|
|
42
|
+
await restoreMissingTrackedFiles(git, input.worktreePath);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
await (previous ? replaceLink(dotGit, previous) : fs.rm(dotGit, { force: true })).catch(() => undefined);
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Puts `content` at the checkout's `.git` without following whatever is there now. The checkout is
|
|
52
|
+
* writable by the session that ran in it, so `.git` can turn into a symlink after it was checked; a
|
|
53
|
+
* plain write would then write through it, outside the allowed root. A new file (created exclusively,
|
|
54
|
+
* which never follows a link) is renamed over it instead, and a rename replaces a symlink rather than
|
|
55
|
+
* following it.
|
|
56
|
+
*/
|
|
57
|
+
async function replaceLink(dotGit, content) {
|
|
58
|
+
const staged = `${dotGit}.forge-relink-${randomUUID()}`;
|
|
59
|
+
await fs.writeFile(staged, content, { flag: "wx" });
|
|
60
|
+
try {
|
|
61
|
+
await fs.rename(staged, dotGit);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
await fs.rm(staged, { force: true }).catch(() => undefined);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function findAdminDir(git, input) {
|
|
69
|
+
const commonDir = path.resolve(input.repoPath, (await git.run(input.repoPath, ["rev-parse", "--git-common-dir"])).trim());
|
|
70
|
+
const adminRoot = path.join(commonDir, "worktrees");
|
|
71
|
+
const names = await fs.readdir(adminRoot).catch(() => []);
|
|
72
|
+
for (const name of names) {
|
|
73
|
+
const adminDir = path.join(adminRoot, name);
|
|
74
|
+
const linked = await fs.readFile(path.join(adminDir, "gitdir"), "utf8").catch(() => null);
|
|
75
|
+
if (!linked || !(await pointsAt(adminDir, linked.trim(), input.worktreePath)))
|
|
76
|
+
continue;
|
|
77
|
+
const head = await fs.readFile(path.join(adminDir, "HEAD"), "utf8").catch(() => "");
|
|
78
|
+
if (head.trim() !== `ref: refs/heads/${input.branchName}`)
|
|
79
|
+
return null;
|
|
80
|
+
const realAdminDir = await fs.realpath(adminDir);
|
|
81
|
+
return isSubPath(input.allowedRoot, realAdminDir) ? realAdminDir : null;
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
/** Whether an admin directory's `gitdir` file names this checkout's `.git`. */
|
|
86
|
+
async function pointsAt(adminDir, linked, worktreePath) {
|
|
87
|
+
// Git writes this path absolute, or relative to the admin directory with worktree.useRelativePaths.
|
|
88
|
+
const dotGit = path.resolve(adminDir, linked);
|
|
89
|
+
if (path.basename(dotGit) !== ".git")
|
|
90
|
+
return false;
|
|
91
|
+
const checkout = await fs.realpath(path.dirname(dotGit)).catch(() => null);
|
|
92
|
+
if (!checkout)
|
|
93
|
+
return false;
|
|
94
|
+
return process.platform === "win32"
|
|
95
|
+
? checkout.toLowerCase() === worktreePath.toLowerCase()
|
|
96
|
+
: checkout === worktreePath;
|
|
97
|
+
}
|
|
98
|
+
async function restoreMissingTrackedFiles(git, worktreePath) {
|
|
99
|
+
const unmerged = new Set((await git.run(worktreePath, ["ls-files", "-u", "-z"]))
|
|
100
|
+
.split("\0").filter(Boolean).map(entry => entry.slice(entry.indexOf("\t") + 1)));
|
|
101
|
+
const missing = [...new Set((await git.run(worktreePath, ["ls-files", "-d", "-z"])).split("\0").filter(Boolean))]
|
|
102
|
+
.filter(file => !unmerged.has(file));
|
|
103
|
+
for (let start = 0; start < missing.length; start += restoreChunk) {
|
|
104
|
+
await git.run(worktreePath, ["checkout-index", "-q", "--", ...missing.slice(start, start + restoreChunk)]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ProcessRunner } from "../shared/process/process.js";
|
|
2
|
+
export declare class WipGit {
|
|
3
|
+
private readonly runner;
|
|
4
|
+
private readonly env;
|
|
5
|
+
constructor(runner?: ProcessRunner, env?: NodeJS.ProcessEnv);
|
|
6
|
+
/** The same client with more environment, e.g. GIT_INDEX_FILE for a throwaway index. */
|
|
7
|
+
with(env: NodeJS.ProcessEnv): WipGit;
|
|
8
|
+
run(cwd: string, args: readonly string[]): Promise<string>;
|
|
9
|
+
/** Runs git and returns its exit code with its output, for commands whose non-zero exit is an answer. */
|
|
10
|
+
runWithStatus(cwd: string, args: readonly string[]): Promise<{
|
|
11
|
+
readonly exitCode: number;
|
|
12
|
+
readonly stdout: string;
|
|
13
|
+
readonly stderr: string;
|
|
14
|
+
}>;
|
|
15
|
+
tryRun(cwd: string, args: readonly string[]): Promise<string | null>;
|
|
16
|
+
/** Runs git with `input` on stdin (for `update-index --index-info`). */
|
|
17
|
+
runWithInput(cwd: string, args: readonly string[], input: string): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Runs `git <args> -- <paths>` in batches so long path lists stay under command-line limits.
|
|
20
|
+
* Paths are literal pathspecs unless `pathspecs` is false (for commands such as checkout-index
|
|
21
|
+
* that take plain file names).
|
|
22
|
+
*/
|
|
23
|
+
runForPaths(cwd: string, args: readonly string[], paths: readonly string[], pathspecs?: boolean): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function splitNul(output: string): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Forge runtime output that is never part of a snapshot, matching what publication excludes:
|
|
28
|
+
* `.local/`, `.forge/work-items/`, `.forge/stories/`, and any `.forge/` path the base commit does
|
|
29
|
+
* not track (injected commands, hooks and skills).
|
|
30
|
+
*/
|
|
31
|
+
export declare function isWipExcludedPath(relativePath: string, baseTrackedForgePaths: ReadonlySet<string>): boolean;
|
|
32
|
+
export declare function baseTrackedForgePaths(git: WipGit, cwd: string, base: string): Promise<ReadonlySet<string>>;
|
|
33
|
+
/** Resolves a `git rev-parse --git-path` answer, which may be relative to `cwd`. */
|
|
34
|
+
export declare function gitPath(git: WipGit, cwd: string, name: string): Promise<string>;
|
|
35
|
+
export declare function partialRestoreMarkerPath(git: WipGit, cwd: string): Promise<string>;
|
|
36
|
+
export declare function hasPartialRestoreMarker(git: WipGit, cwd: string): Promise<boolean>;
|
|
37
|
+
export declare function readReapplyConflictRecord(git: WipGit, cwd: string): Promise<string[]>;
|
|
38
|
+
/** Writes the re-apply conflict record (wip-refs.ts), or removes it when there are no paths. */
|
|
39
|
+
export declare function writeReapplyConflictRecord(git: WipGit, cwd: string, paths: readonly string[]): Promise<void>;
|
|
40
|
+
/** A private directory for throwaway index files, removed by the caller. */
|
|
41
|
+
export declare function makeWipTempDir(): Promise<string>;
|
|
42
|
+
export declare function readOptionalFile(filePath: string): Promise<string | null>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { isRuntimeOnlyPath } from "../session/publishable-worktree-changes.js";
|
|
6
|
+
import { NodeProcessRunner } from "../shared/process/process.js";
|
|
7
|
+
import { parseReapplyConflictRecord, wipReapplyConflictRecordName } from "./wip-refs.js";
|
|
8
|
+
// Git plumbing shared by WIP snapshot and restore. Every command can carry extra environment
|
|
9
|
+
// (a temporary index, or GIT_DIR/GIT_WORK_TREE for an orphaned checkout) without touching the
|
|
10
|
+
// worktree's own index, HEAD or config.
|
|
11
|
+
const wipIdentity = {
|
|
12
|
+
GIT_AUTHOR_NAME: "Forge Bridge",
|
|
13
|
+
GIT_AUTHOR_EMAIL: "forge-bridge@forge.local",
|
|
14
|
+
GIT_COMMITTER_NAME: "Forge Bridge",
|
|
15
|
+
GIT_COMMITTER_EMAIL: "forge-bridge@forge.local",
|
|
16
|
+
};
|
|
17
|
+
const pathBatchSize = 200;
|
|
18
|
+
export class WipGit {
|
|
19
|
+
runner;
|
|
20
|
+
env;
|
|
21
|
+
constructor(runner = new NodeProcessRunner(), env = {}) {
|
|
22
|
+
this.runner = runner;
|
|
23
|
+
this.env = env;
|
|
24
|
+
}
|
|
25
|
+
/** The same client with more environment, e.g. GIT_INDEX_FILE for a throwaway index. */
|
|
26
|
+
with(env) {
|
|
27
|
+
return new WipGit(this.runner, { ...this.env, ...env });
|
|
28
|
+
}
|
|
29
|
+
async run(cwd, args) {
|
|
30
|
+
const result = await this.runWithStatus(cwd, args);
|
|
31
|
+
if (result.exitCode !== 0) {
|
|
32
|
+
throw new Error(`git ${args.join(" ")} failed: ${result.stderr.trim() || result.stdout.trim()}`);
|
|
33
|
+
}
|
|
34
|
+
return result.stdout;
|
|
35
|
+
}
|
|
36
|
+
/** Runs git and returns its exit code with its output, for commands whose non-zero exit is an answer. */
|
|
37
|
+
async runWithStatus(cwd, args) {
|
|
38
|
+
const result = await this.runner.run({
|
|
39
|
+
command: "git",
|
|
40
|
+
args,
|
|
41
|
+
cwd,
|
|
42
|
+
env: { ...process.env, ...wipIdentity, ...this.env },
|
|
43
|
+
...(args.includes("-z") ? { rawOutput: true } : {}),
|
|
44
|
+
});
|
|
45
|
+
return { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr };
|
|
46
|
+
}
|
|
47
|
+
async tryRun(cwd, args) {
|
|
48
|
+
return await this.run(cwd, args).catch(() => null);
|
|
49
|
+
}
|
|
50
|
+
/** Runs git with `input` on stdin (for `update-index --index-info`). */
|
|
51
|
+
async runWithInput(cwd, args, input) {
|
|
52
|
+
await new Promise((resolve, reject) => {
|
|
53
|
+
const child = spawn("git", [...args], {
|
|
54
|
+
cwd,
|
|
55
|
+
env: { ...process.env, ...wipIdentity, ...this.env },
|
|
56
|
+
stdio: ["pipe", "ignore", "pipe"],
|
|
57
|
+
windowsHide: true,
|
|
58
|
+
});
|
|
59
|
+
let stderr = "";
|
|
60
|
+
child.stderr.on("data", chunk => { stderr += String(chunk); });
|
|
61
|
+
child.on("error", reject);
|
|
62
|
+
child.on("close", code => code === 0
|
|
63
|
+
? resolve()
|
|
64
|
+
: reject(new Error(`git ${args.join(" ")} failed: ${stderr.trim()}`)));
|
|
65
|
+
child.stdin.end(input);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Runs `git <args> -- <paths>` in batches so long path lists stay under command-line limits.
|
|
70
|
+
* Paths are literal pathspecs unless `pathspecs` is false (for commands such as checkout-index
|
|
71
|
+
* that take plain file names).
|
|
72
|
+
*/
|
|
73
|
+
async runForPaths(cwd, args, paths, pathspecs = true) {
|
|
74
|
+
for (let index = 0; index < paths.length; index += pathBatchSize) {
|
|
75
|
+
const batch = paths.slice(index, index + pathBatchSize).map(filePath => pathspecs ? `:(literal)${filePath}` : filePath);
|
|
76
|
+
await this.run(cwd, [...args, "--", ...batch]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export function splitNul(output) {
|
|
81
|
+
return output.split("\0").filter(Boolean);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Forge runtime output that is never part of a snapshot, matching what publication excludes:
|
|
85
|
+
* `.local/`, `.forge/work-items/`, `.forge/stories/`, and any `.forge/` path the base commit does
|
|
86
|
+
* not track (injected commands, hooks and skills).
|
|
87
|
+
*/
|
|
88
|
+
export function isWipExcludedPath(relativePath, baseTrackedForgePaths) {
|
|
89
|
+
const normalized = relativePath.replaceAll("\\", "/").replace(/\/$/u, "");
|
|
90
|
+
if (isRuntimeOnlyPath(normalized))
|
|
91
|
+
return true;
|
|
92
|
+
if (normalized === ".forge" || normalized.startsWith(".forge/"))
|
|
93
|
+
return !baseTrackedForgePaths.has(normalized);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
export async function baseTrackedForgePaths(git, cwd, base) {
|
|
97
|
+
const output = await git.run(cwd, ["ls-tree", "-r", "-z", "--name-only", base, "--", ".forge"]);
|
|
98
|
+
return new Set(splitNul(output));
|
|
99
|
+
}
|
|
100
|
+
/** Resolves a `git rev-parse --git-path` answer, which may be relative to `cwd`. */
|
|
101
|
+
export async function gitPath(git, cwd, name) {
|
|
102
|
+
const raw = (await git.run(cwd, ["rev-parse", "--git-path", name])).trim();
|
|
103
|
+
return path.isAbsolute(raw) ? raw : path.resolve(cwd, raw);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Set in a worktree's Git directory when a WIP restore could neither finish nor be undone, so its
|
|
107
|
+
* files are a mix of the snapshot and the base. No snapshot of it is ever applied automatically
|
|
108
|
+
* until a restore finds the worktree clean again (wip-restore.ts).
|
|
109
|
+
*/
|
|
110
|
+
const partialRestoreMarkerName = "forge-wip-partial-restore";
|
|
111
|
+
export async function partialRestoreMarkerPath(git, cwd) {
|
|
112
|
+
return await gitPath(git, cwd, partialRestoreMarkerName);
|
|
113
|
+
}
|
|
114
|
+
export async function hasPartialRestoreMarker(git, cwd) {
|
|
115
|
+
const marker = await partialRestoreMarkerPath(git, cwd).catch(() => null);
|
|
116
|
+
return marker !== null && await fs.stat(marker).then(() => true, () => false);
|
|
117
|
+
}
|
|
118
|
+
export async function readReapplyConflictRecord(git, cwd) {
|
|
119
|
+
return parseReapplyConflictRecord(await readOptionalFile(await gitPath(git, cwd, wipReapplyConflictRecordName)));
|
|
120
|
+
}
|
|
121
|
+
/** Writes the re-apply conflict record (wip-refs.ts), or removes it when there are no paths. */
|
|
122
|
+
export async function writeReapplyConflictRecord(git, cwd, paths) {
|
|
123
|
+
const record = await gitPath(git, cwd, wipReapplyConflictRecordName);
|
|
124
|
+
if (paths.length === 0)
|
|
125
|
+
await fs.rm(record, { force: true });
|
|
126
|
+
else
|
|
127
|
+
await fs.writeFile(record, [...new Set(paths)].sort().join("\0"), "utf8");
|
|
128
|
+
}
|
|
129
|
+
/** A private directory for throwaway index files, removed by the caller. */
|
|
130
|
+
export async function makeWipTempDir() {
|
|
131
|
+
return await fs.mkdtemp(path.join(os.tmpdir(), "forge-wip-"));
|
|
132
|
+
}
|
|
133
|
+
export async function readOptionalFile(filePath) {
|
|
134
|
+
return await fs.readFile(filePath, "utf8").catch((error) => {
|
|
135
|
+
if (error.code === "ENOENT")
|
|
136
|
+
return null;
|
|
137
|
+
throw error;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export declare const wipRefRoot = "refs/forge/wip";
|
|
2
|
+
export declare const wipMetadataSchema = "forge.wip.v1";
|
|
3
|
+
/**
|
|
4
|
+
* Kept in a worktree's Git directory after a WIP re-apply across a branch move left conflicts
|
|
5
|
+
* (wip-restore.ts): the conflicted paths, NUL-separated. A re-apply writes no MERGE_HEAD, and staging
|
|
6
|
+
* a conflicted file clears its index stages but keeps its markers, so publication reads this to keep
|
|
7
|
+
* refusing those markers (provider-cli.merge-integrity.ts). Snapshots carry it (reapplyConflicts) and
|
|
8
|
+
* a restore writes it back; a restore that finds the worktree clean removes it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const wipReapplyConflictRecordName = "forge-wip-reapply-conflicts";
|
|
11
|
+
export declare function parseReapplyConflictRecord(content: string | null): string[];
|
|
12
|
+
/** The attempt of a snapshot taken without a Forge-issued attempt number. */
|
|
13
|
+
export declare const unorderedWipAttempt = 0;
|
|
14
|
+
/** Why a snapshot was taken. Session reasons name the session; the others are guards. */
|
|
15
|
+
export type WipSnapshotReason = "session_failed" | "repair_limit" | "session_paused" | "session_stopped" | "pre_reset" | "pre_sync" | "pre_branch_reset" | "pre_release" | "pre_cleanup";
|
|
16
|
+
export interface WipUnmergedEntry {
|
|
17
|
+
readonly mode: string;
|
|
18
|
+
readonly sha: string;
|
|
19
|
+
readonly stage: number;
|
|
20
|
+
readonly path: string;
|
|
21
|
+
}
|
|
22
|
+
export interface WipSnapshotMetadata {
|
|
23
|
+
readonly schema: typeof wipMetadataSchema;
|
|
24
|
+
readonly branch: string;
|
|
25
|
+
readonly baseHead: string;
|
|
26
|
+
readonly sessionId: string | null;
|
|
27
|
+
readonly lane: string | null;
|
|
28
|
+
readonly reason: WipSnapshotReason;
|
|
29
|
+
/** The story attempt the snapshot belongs to (see the ref layout above). */
|
|
30
|
+
readonly attempt: number;
|
|
31
|
+
/** False for snapshots that must never be applied automatically (see wip-snapshot.ts). */
|
|
32
|
+
readonly autoRestore: boolean;
|
|
33
|
+
readonly createdAt: string;
|
|
34
|
+
readonly createdAtMs: number;
|
|
35
|
+
readonly mergeHead: string | null;
|
|
36
|
+
readonly mergeMessage: string | null;
|
|
37
|
+
readonly mergeMode: string | null;
|
|
38
|
+
readonly unmerged: readonly WipUnmergedEntry[];
|
|
39
|
+
/** The worktree's re-apply conflict record when it was taken (see wipReapplyConflictRecordName); [] before it existed. */
|
|
40
|
+
readonly reapplyConflicts: readonly string[];
|
|
41
|
+
readonly changedPaths: number;
|
|
42
|
+
readonly bytes: number;
|
|
43
|
+
}
|
|
44
|
+
export type WipPreservationFailureCode = "wip_snapshot_too_large" | "wip_snapshot_failed" | "wip_push_failed";
|
|
45
|
+
/** Snapshotting or pushing uncommitted work failed; whatever would have destroyed it must not run. */
|
|
46
|
+
export declare class WipPreservationError extends Error {
|
|
47
|
+
readonly code: WipPreservationFailureCode;
|
|
48
|
+
constructor(code: WipPreservationFailureCode, message: string, options?: {
|
|
49
|
+
readonly cause?: unknown;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* `story/<12 hex>` → the 12 hex; any other branch → `b_` and its name with `_` written as `_u` and
|
|
54
|
+
* `/` as `_s`. The encoding is reversible and a story key never starts with `b_`, so no two branches
|
|
55
|
+
* share a key (`task/a-b` and `task-a/b` would under a plain `/` → `-`). GitHubWipRefCleanup.cs
|
|
56
|
+
* computes the same key.
|
|
57
|
+
*/
|
|
58
|
+
export declare function wipOwnerKey(branchName: string): string;
|
|
59
|
+
/** The ref namespace holding every WIP snapshot for a branch, with a trailing slash. */
|
|
60
|
+
export declare function wipRefPrefix(branchName: string): string;
|
|
61
|
+
export declare function wipRefName(branchName: string, id: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* `<attempt>-<session id>` for a session's own snapshot; `<attempt>-[<session id>-]<reason>-<time>-<nonce>`
|
|
64
|
+
* for a guard snapshot.
|
|
65
|
+
*/
|
|
66
|
+
export declare function wipRefId(reason: WipSnapshotReason, sessionId: string | null | undefined, now: Date, attempt?: number): string;
|
|
67
|
+
/** A Forge-issued attempt usable in a ref name; anything else (missing, out of range) is unorderedWipAttempt. */
|
|
68
|
+
export declare function issuedWipAttempt(value: number | null | undefined): number;
|
|
69
|
+
/** The attempt a WIP ref belongs to: its ten-digit id prefix, or unorderedWipAttempt without one. */
|
|
70
|
+
export declare function wipRefAttempt(ref: string): number;
|
|
71
|
+
/** The cap on a snapshot's size, from FORGE_WIP_SNAPSHOT_MAX_BYTES when that is a positive integer. */
|
|
72
|
+
export declare function wipSnapshotMaxBytes(env?: NodeJS.ProcessEnv): number;
|
|
73
|
+
export declare function formatWipCommitMessage(metadata: WipSnapshotMetadata): string;
|
|
74
|
+
/** The metadata of a WIP commit message, or null when the message is not one. */
|
|
75
|
+
export declare function parseWipCommitMessage(message: string): WipSnapshotMetadata | null;
|
|
76
|
+
/** A raw commit object's message: everything after its header block. */
|
|
77
|
+
export declare function commitMessageOf(rawCommit: string): string;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Private WIP refs: where Forge keeps uncommitted work it could otherwise lose.
|
|
2
|
+
//
|
|
3
|
+
// The bridge owns the only commit and push on a story branch, so unfinished work never goes there.
|
|
4
|
+
// Before anything could destroy uncommitted changes (a session that stops, fails, pauses or hits
|
|
5
|
+
// its repair limit; a reset, a release or a cleanup of the worktree), the bridge snapshots them into
|
|
6
|
+
// a commit and pushes it to
|
|
7
|
+
//
|
|
8
|
+
// refs/forge/wip/<owner key>/<attempt>-<session id | [session id-]reason-timestamp-nonce>
|
|
9
|
+
//
|
|
10
|
+
// <attempt> is ten zero-padded digits, so refs sort by it: the dispatch's wipAttempt, which Forge
|
|
11
|
+
// issues from a database sequence when it admits the dispatch attempt, so a later attempt on a story
|
|
12
|
+
// always has a larger one. Newest work wins: a restore takes the highest attempt first. Snapshots
|
|
13
|
+
// taken without an issued attempt (older servers, attempts admitted before it existed, cleanup and
|
|
14
|
+
// branch-reset guards) carry attempt 0.
|
|
15
|
+
//
|
|
16
|
+
// The owner key is the story's short id for a `story/<12 hex>` branch, and `b_` plus the branch
|
|
17
|
+
// name with `_` → `_u` and `/` → `_s` for any other branch (`b_task_s0123456789ab`), so it is
|
|
18
|
+
// unique per branch. The server deletes a key's refs when the pull request for that branch merges
|
|
19
|
+
// or closes (GitHubWipRefCleanup.cs).
|
|
20
|
+
//
|
|
21
|
+
// A snapshot is a commit W whose tree is the worktree (staged, unstaged and untracked files that
|
|
22
|
+
// are not ignored; never Forge runtime output). Its first parent is the HEAD it was based on, its
|
|
23
|
+
// second an index commit I whose tree is the staged state, and its third, when a merge was in
|
|
24
|
+
// progress, MERGE_HEAD. Its message carries the metadata below as JSON.
|
|
25
|
+
import { randomBytes } from "node:crypto";
|
|
26
|
+
export const wipRefRoot = "refs/forge/wip";
|
|
27
|
+
export const wipMetadataSchema = "forge.wip.v1";
|
|
28
|
+
const defaultWipSnapshotMaxBytes = 100 * 1024 * 1024;
|
|
29
|
+
const wipSnapshotMaxBytesEnv = "FORGE_WIP_SNAPSHOT_MAX_BYTES";
|
|
30
|
+
const storyBranchPattern = /^story\/([0-9a-f]{12})$/u;
|
|
31
|
+
const refSegmentPattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u;
|
|
32
|
+
/**
|
|
33
|
+
* Kept in a worktree's Git directory after a WIP re-apply across a branch move left conflicts
|
|
34
|
+
* (wip-restore.ts): the conflicted paths, NUL-separated. A re-apply writes no MERGE_HEAD, and staging
|
|
35
|
+
* a conflicted file clears its index stages but keeps its markers, so publication reads this to keep
|
|
36
|
+
* refusing those markers (provider-cli.merge-integrity.ts). Snapshots carry it (reapplyConflicts) and
|
|
37
|
+
* a restore writes it back; a restore that finds the worktree clean removes it.
|
|
38
|
+
*/
|
|
39
|
+
export const wipReapplyConflictRecordName = "forge-wip-reapply-conflicts";
|
|
40
|
+
export function parseReapplyConflictRecord(content) {
|
|
41
|
+
return content ? [...new Set(content.split("\0").filter(Boolean))].sort() : [];
|
|
42
|
+
}
|
|
43
|
+
/** The attempt of a snapshot taken without a Forge-issued attempt number. */
|
|
44
|
+
export const unorderedWipAttempt = 0;
|
|
45
|
+
const maxWipAttempt = 9_999_999_999;
|
|
46
|
+
/** Snapshotting or pushing uncommitted work failed; whatever would have destroyed it must not run. */
|
|
47
|
+
export class WipPreservationError extends Error {
|
|
48
|
+
code;
|
|
49
|
+
constructor(code, message, options) {
|
|
50
|
+
super(`${code}: ${message}`, options);
|
|
51
|
+
this.code = code;
|
|
52
|
+
this.name = "WipPreservationError";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* `story/<12 hex>` → the 12 hex; any other branch → `b_` and its name with `_` written as `_u` and
|
|
57
|
+
* `/` as `_s`. The encoding is reversible and a story key never starts with `b_`, so no two branches
|
|
58
|
+
* share a key (`task/a-b` and `task-a/b` would under a plain `/` → `-`). GitHubWipRefCleanup.cs
|
|
59
|
+
* computes the same key.
|
|
60
|
+
*/
|
|
61
|
+
export function wipOwnerKey(branchName) {
|
|
62
|
+
const branch = branchName.trim().replace(/^refs\/heads\//u, "");
|
|
63
|
+
const story = storyBranchPattern.exec(branch);
|
|
64
|
+
const key = story ? story[1] : `b_${branch.replaceAll("_", "_u").replaceAll("/", "_s")}`;
|
|
65
|
+
if (!branch || !refSegmentPattern.test(key) || key.includes("..") || key.endsWith(".lock") || key.endsWith(".")) {
|
|
66
|
+
throw new WipPreservationError("wip_snapshot_failed", `branch '${branchName}' has no valid WIP ref key.`);
|
|
67
|
+
}
|
|
68
|
+
return key;
|
|
69
|
+
}
|
|
70
|
+
/** The ref namespace holding every WIP snapshot for a branch, with a trailing slash. */
|
|
71
|
+
export function wipRefPrefix(branchName) {
|
|
72
|
+
return `${wipRefRoot}/${wipOwnerKey(branchName)}/`;
|
|
73
|
+
}
|
|
74
|
+
export function wipRefName(branchName, id) {
|
|
75
|
+
if (!refSegmentPattern.test(id) || id.endsWith(".lock") || id.endsWith(".")) {
|
|
76
|
+
throw new WipPreservationError("wip_snapshot_failed", `'${id}' is not a valid WIP ref id.`);
|
|
77
|
+
}
|
|
78
|
+
return `${wipRefPrefix(branchName)}${id}`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* `<attempt>-<session id>` for a session's own snapshot; `<attempt>-[<session id>-]<reason>-<time>-<nonce>`
|
|
82
|
+
* for a guard snapshot.
|
|
83
|
+
*/
|
|
84
|
+
export function wipRefId(reason, sessionId, now, attempt = unorderedWipAttempt) {
|
|
85
|
+
if (!Number.isSafeInteger(attempt) || attempt < 0 || attempt > maxWipAttempt) {
|
|
86
|
+
throw new WipPreservationError("wip_snapshot_failed", `${attempt} is not a valid WIP attempt number.`);
|
|
87
|
+
}
|
|
88
|
+
const prefix = `${String(attempt).padStart(10, "0")}-`;
|
|
89
|
+
const session = sessionId?.trim();
|
|
90
|
+
if (session && isSessionReason(reason))
|
|
91
|
+
return `${prefix}${session}`;
|
|
92
|
+
const owner = session ? `${session}-` : "";
|
|
93
|
+
return `${prefix}${owner}${reason.replaceAll("_", "-")}-${now.getTime().toString(36)}-${randomBytes(3).toString("hex")}`;
|
|
94
|
+
}
|
|
95
|
+
function isSessionReason(reason) {
|
|
96
|
+
return reason === "session_failed" || reason === "repair_limit"
|
|
97
|
+
|| reason === "session_paused" || reason === "session_stopped";
|
|
98
|
+
}
|
|
99
|
+
/** A Forge-issued attempt usable in a ref name; anything else (missing, out of range) is unorderedWipAttempt. */
|
|
100
|
+
export function issuedWipAttempt(value) {
|
|
101
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && value <= maxWipAttempt ? value : unorderedWipAttempt;
|
|
102
|
+
}
|
|
103
|
+
/** The attempt a WIP ref belongs to: its ten-digit id prefix, or unorderedWipAttempt without one. */
|
|
104
|
+
export function wipRefAttempt(ref) {
|
|
105
|
+
const id = ref.slice(ref.lastIndexOf("/") + 1);
|
|
106
|
+
const match = /^(\d{10})-/u.exec(id);
|
|
107
|
+
return match ? Number(match[1]) : unorderedWipAttempt;
|
|
108
|
+
}
|
|
109
|
+
/** The cap on a snapshot's size, from FORGE_WIP_SNAPSHOT_MAX_BYTES when that is a positive integer. */
|
|
110
|
+
export function wipSnapshotMaxBytes(env = process.env) {
|
|
111
|
+
const configured = Number.parseInt(env[wipSnapshotMaxBytesEnv] ?? "", 10);
|
|
112
|
+
return Number.isSafeInteger(configured) && configured > 0 ? configured : defaultWipSnapshotMaxBytes;
|
|
113
|
+
}
|
|
114
|
+
export function formatWipCommitMessage(metadata) {
|
|
115
|
+
return `forge wip snapshot (${metadata.reason}) of ${metadata.branch} at ${metadata.baseHead.slice(0, 12)}\n\n`
|
|
116
|
+
+ `${JSON.stringify(metadata)}\n`;
|
|
117
|
+
}
|
|
118
|
+
/** The metadata of a WIP commit message, or null when the message is not one. */
|
|
119
|
+
export function parseWipCommitMessage(message) {
|
|
120
|
+
const start = message.indexOf("\n\n");
|
|
121
|
+
if (start < 0)
|
|
122
|
+
return null;
|
|
123
|
+
try {
|
|
124
|
+
const parsed = JSON.parse(message.slice(start + 2).trim());
|
|
125
|
+
if (parsed.schema !== wipMetadataSchema || typeof parsed.baseHead !== "string"
|
|
126
|
+
|| typeof parsed.branch !== "string" || typeof parsed.createdAtMs !== "number") {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
...parsed,
|
|
131
|
+
unmerged: Array.isArray(parsed.unmerged) ? parsed.unmerged : [],
|
|
132
|
+
autoRestore: parsed.autoRestore === true,
|
|
133
|
+
reapplyConflicts: Array.isArray(parsed.reapplyConflicts)
|
|
134
|
+
? parsed.reapplyConflicts.filter(conflict => typeof conflict === "string")
|
|
135
|
+
: [],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** A raw commit object's message: everything after its header block. */
|
|
143
|
+
export function commitMessageOf(rawCommit) {
|
|
144
|
+
const separator = rawCommit.indexOf("\n\n");
|
|
145
|
+
return separator < 0 ? "" : rawCommit.slice(separator + 2);
|
|
146
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ProcessRunner } from "../shared/process/process.js";
|
|
2
|
+
export interface WipRestoreRequest {
|
|
3
|
+
readonly worktreePath: string;
|
|
4
|
+
readonly repoPath: string;
|
|
5
|
+
readonly branchName: string;
|
|
6
|
+
readonly processRunner?: ProcessRunner;
|
|
7
|
+
}
|
|
8
|
+
export type WipRestoreOutcome = {
|
|
9
|
+
readonly status: "none";
|
|
10
|
+
} | {
|
|
11
|
+
readonly status: "restored";
|
|
12
|
+
readonly ref: string;
|
|
13
|
+
readonly commitSha: string;
|
|
14
|
+
readonly baseHead: string;
|
|
15
|
+
readonly sourceSessionId: string | null;
|
|
16
|
+
readonly changedPaths: number;
|
|
17
|
+
readonly mergeInProgress: boolean;
|
|
18
|
+
/** Set when the branch had moved and the snapshot was re-applied onto its new HEAD with a 3-way merge. */
|
|
19
|
+
readonly reapplied: WipReapply | null;
|
|
20
|
+
} | {
|
|
21
|
+
readonly status: "not_restored";
|
|
22
|
+
readonly ref: string;
|
|
23
|
+
readonly commitSha: string;
|
|
24
|
+
readonly reason: "branch_moved" | "apply_failed";
|
|
25
|
+
readonly baseHead: string;
|
|
26
|
+
readonly currentHead: string;
|
|
27
|
+
readonly detail: string;
|
|
28
|
+
} | {
|
|
29
|
+
readonly status: "skipped_dirty";
|
|
30
|
+
readonly ref: string;
|
|
31
|
+
readonly commitSha: string;
|
|
32
|
+
} | {
|
|
33
|
+
readonly status: "unavailable";
|
|
34
|
+
readonly detail: string;
|
|
35
|
+
};
|
|
36
|
+
export interface WipReapply {
|
|
37
|
+
/** The HEAD the snapshot was taken on, used as the merge base. */
|
|
38
|
+
readonly snapshotBaseHead: string;
|
|
39
|
+
/** Paths the merge left unmerged, with conflict markers where Git writes them, for the agent to resolve. */
|
|
40
|
+
readonly conflictedPaths: readonly string[];
|
|
41
|
+
}
|
|
42
|
+
export declare function restoreLatestWip(request: WipRestoreRequest): Promise<WipRestoreOutcome>;
|
|
43
|
+
/** Deletes a WIP ref (on origin, or locally when there is no origin). Never throws. */
|
|
44
|
+
export declare function deleteWipRef(repoPath: string, ref: string, processRunner?: ProcessRunner): Promise<boolean>;
|
|
45
|
+
/** True when the worktree holds nothing a snapshot would save (Forge runtime output aside), and no merge. */
|
|
46
|
+
export declare function hasNoUnsavedWork(worktreePath: string, processRunner?: ProcessRunner): Promise<boolean>;
|