@loucompanion/forge-bridge 0.1.4-dev.494233aa2e50 → 0.1.4-dev.60e18c3cfec6
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 +35 -2
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +72 -1
- package/dist/bridge/bridge.service.js +308 -9
- package/dist/bridge/bridge.types.d.ts +16 -0
- 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/host-load-admission.d.ts +60 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +22 -0
- package/dist/runtime/host-load-child-environment.js +67 -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 +43 -0
- package/dist/runtime/host-load-governor-config.js +76 -0
- package/dist/runtime/host-load-governor.d.ts +174 -0
- package/dist/runtime/host-load-governor.js +541 -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 +43 -0
- package/dist/runtime/host-load-sampler.js +74 -6
- package/dist/runtime/host-load-step-class.d.ts +68 -0
- package/dist/runtime/host-load-step-class.js +106 -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-token-ledger.d.ts +174 -0
- package/dist/runtime/host-load-token-ledger.js +421 -0
- package/dist/runtime/host-pressure-stall.d.ts +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-contract.d.ts +3 -0
- package/dist/runtime/host-runtime-contract.js +4 -1
- package/dist/runtime/host-runtime-lease.d.ts +74 -4
- package/dist/runtime/host-runtime-lease.js +279 -10
- package/dist/runtime/host-runtime-promotion.js +12 -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/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- 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 +107 -0
- package/dist/sandbox/host-capacity-broker.js +315 -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 +2 -0
- package/dist/session/managed-attempt-tools.js +156 -37
- package/dist/session/managed-command-host-load.d.ts +45 -0
- package/dist/session/managed-command-host-load.js +82 -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 +94 -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 +49 -19
- 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 +184 -209
- 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-process.d.ts +3 -0
- package/dist/session/pre-publication-process.js +23 -11
- 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 +9 -9
- package/dist/session/pre-publication-validation.js +21 -55
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +20 -7
- 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 +32 -1
- package/dist/session/provider-cli/provider-cli.process.js +122 -30
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +20 -2
- package/dist/session/provider-cli/provider-cli.service.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.service.js +183 -26
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +6 -0
- package/dist/session/provider-cli/provider-output-state.js +9 -0
- package/dist/session/publishable-worktree-changes.d.ts +10 -1
- package/dist/session/publishable-worktree-changes.js +21 -5
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +229 -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 +12 -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/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 +1 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { constants as fsConstants } from "node:fs";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { validRuntimeIsolationLease } from "../runtime/runtime-isolation-lease.js";
|
|
5
|
+
// The host runtime ledger (<state root>/runtime-ledger/host/*.json) records every runtime lease this
|
|
6
|
+
// bridge holds. Cleanup reads it to keep live leases' worktrees and branches; any ledger it can't
|
|
7
|
+
// trust stops the cleanup rather than guessing.
|
|
8
|
+
/** Reads every host runtime lease, or throws if any ledger file can't be trusted. */
|
|
9
|
+
export async function readHostRuntimeLeases(stateRoot) {
|
|
10
|
+
const ledgerRoot = path.join(stateRoot, "runtime-ledger", "host");
|
|
11
|
+
const entries = await fs.readdir(ledgerRoot, { withFileTypes: true }).catch(error => {
|
|
12
|
+
if (isEnoent(error))
|
|
13
|
+
return [];
|
|
14
|
+
throw error;
|
|
15
|
+
});
|
|
16
|
+
const leases = [];
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
if (!entry.name.endsWith(".json"))
|
|
19
|
+
continue;
|
|
20
|
+
if (!entry.isFile() || entry.isSymbolicLink()) {
|
|
21
|
+
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entry.name} is not a regular file.`);
|
|
22
|
+
}
|
|
23
|
+
const target = path.join(ledgerRoot, entry.name);
|
|
24
|
+
const value = await readRuntimeLedger(target, entry.name);
|
|
25
|
+
const runtimeLease = isRecord(value) ? value.runtimeLease : null;
|
|
26
|
+
if (!validRuntimeIsolationLease(runtimeLease) || runtimeLease.mode !== "host") {
|
|
27
|
+
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entry.name} has no trustworthy host lease.`);
|
|
28
|
+
}
|
|
29
|
+
leases.push(runtimeLease);
|
|
30
|
+
}
|
|
31
|
+
return leases;
|
|
32
|
+
}
|
|
33
|
+
async function readRuntimeLedger(target, entryName) {
|
|
34
|
+
const pathStat = await fs.lstat(target).catch(error => {
|
|
35
|
+
if (isEnoent(error))
|
|
36
|
+
return null;
|
|
37
|
+
throw error;
|
|
38
|
+
});
|
|
39
|
+
if (!pathStat) {
|
|
40
|
+
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} disappeared.`);
|
|
41
|
+
}
|
|
42
|
+
validateRuntimeLedgerStat(entryName, pathStat);
|
|
43
|
+
let handle;
|
|
44
|
+
try {
|
|
45
|
+
handle = await fs.open(target, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (isEnoent(error) || errorCode(error) === "ELOOP") {
|
|
49
|
+
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} is not a regular file.`, { cause: error });
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} could not be opened safely.`, { cause: error });
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const openedStat = await handle.stat();
|
|
55
|
+
const reopenedPathStat = await fs.lstat(target);
|
|
56
|
+
validateRuntimeLedgerStat(entryName, openedStat);
|
|
57
|
+
validateRuntimeLedgerStat(entryName, reopenedPathStat);
|
|
58
|
+
validateSameRuntimeLedgerFile(entryName, pathStat, openedStat);
|
|
59
|
+
validateSameRuntimeLedgerFile(entryName, openedStat, reopenedPathStat);
|
|
60
|
+
const content = await handle.readFile("utf8");
|
|
61
|
+
const afterStat = await handle.stat();
|
|
62
|
+
const afterPathStat = await fs.lstat(target);
|
|
63
|
+
validateRuntimeLedgerStat(entryName, afterStat);
|
|
64
|
+
validateRuntimeLedgerStat(entryName, afterPathStat);
|
|
65
|
+
validateSameRuntimeLedgerFile(entryName, openedStat, afterStat);
|
|
66
|
+
validateSameRuntimeLedgerFile(entryName, afterStat, afterPathStat);
|
|
67
|
+
if (openedStat.size !== afterStat.size || Buffer.byteLength(content, "utf8") !== afterStat.size) {
|
|
68
|
+
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} changed while being read.`);
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(content);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} is invalid.`, { cause: error });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
await handle.close();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function validateRuntimeLedgerStat(entryName, stat) {
|
|
82
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
83
|
+
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} is not a regular file.`);
|
|
84
|
+
}
|
|
85
|
+
if (stat.size > 256 * 1024) {
|
|
86
|
+
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} is oversized.`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function validateSameRuntimeLedgerFile(entryName, before, after) {
|
|
90
|
+
if (before.dev !== 0 && before.ino !== 0 && after.dev !== 0 && after.ino !== 0
|
|
91
|
+
&& (before.dev !== after.dev || before.ino !== after.ino)) {
|
|
92
|
+
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} changed while being read.`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function errorCode(error) {
|
|
96
|
+
return typeof error === "object" && error !== null && "code" in error
|
|
97
|
+
? String(error.code)
|
|
98
|
+
: undefined;
|
|
99
|
+
}
|
|
100
|
+
/** Branches that a lease which isn't released yet may still use. */
|
|
101
|
+
export function liveLeaseBranches(leases) {
|
|
102
|
+
return new Set(leases.filter(lease => lease.state !== "released").map(lease => lease.worktreeKey));
|
|
103
|
+
}
|
|
104
|
+
function isEnoent(error) {
|
|
105
|
+
return error?.code === "ENOENT";
|
|
106
|
+
}
|
|
107
|
+
function isRecord(value) {
|
|
108
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
109
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { GitClient } from "../shared/git/git.js";
|
|
2
|
+
/** A readiness probe's branch: scratch that nothing reads once its worktree is gone. */
|
|
3
|
+
export declare function isRuntimeReadinessBranch(branchName: string): boolean;
|
|
4
|
+
/** A branch Forge named for a work item, Feature or Work Order. */
|
|
5
|
+
export declare function isForgeManagedWorkBranch(branchName: string): boolean;
|
|
6
|
+
export interface ManagedBranchSweepOptions {
|
|
7
|
+
/** Branch whose remote-tracking ref (origin/<base>) decides what counts as merged. */
|
|
8
|
+
readonly baseBranch?: string;
|
|
9
|
+
/** Also delete managed work branches whose changes are already on the base. */
|
|
10
|
+
readonly includeMergedWorkBranches: boolean;
|
|
11
|
+
/** Branches to keep whatever their state, e.g. ones a live lease is about to use. */
|
|
12
|
+
readonly protectedBranches?: ReadonlySet<string>;
|
|
13
|
+
/** Upper bound on branches deleted in one sweep, to keep the repository lock short. */
|
|
14
|
+
readonly limit?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface ManagedBranchSweepResult {
|
|
17
|
+
readonly deletedBranches: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Deletes branches Forge created that no worktree has checked out: every readiness branch, and,
|
|
21
|
+
* when asked, every managed work branch whose changes are already on origin/<base> (as an ancestor,
|
|
22
|
+
* or because merging it into the base would change nothing, as after a squash merge). Branches with work that is not on the base
|
|
23
|
+
* are kept. Must run under the repository coordinator lock, like worktree creation.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sweepManagedBranches(git: GitClient, repoPath: string, options: ManagedBranchSweepOptions): Promise<ManagedBranchSweepResult>;
|
|
26
|
+
/** Deletes one branch unless a worktree still has it checked out. Never throws. */
|
|
27
|
+
export declare function deleteBranchIfUnused(git: GitClient, repoPath: string, branchName: string): Promise<boolean>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Every environment Forge spawns an agent in gets its own local branch: runtime-readiness-<request
|
|
2
|
+
// UUID> for a readiness probe (session.service.ts), <kind>/<12 hex> for a work item (story/, task/,
|
|
3
|
+
// bug/, and architect/ for its Architect phase), and decompose/<feature|work_order>/<12 hex> for a
|
|
4
|
+
// decompose session (ManagedWorkItemBranchNames on the server). Only those exact shapes count, so a
|
|
5
|
+
// person's branch such as fix/0123456789ab or runtime-readiness-hotfix is never touched. The server
|
|
6
|
+
// removes the ones in its own checkout when a pull request merges; this sweep lets every device
|
|
7
|
+
// remove its own, so nothing piles up wherever a bridge runs.
|
|
8
|
+
const runtimeReadinessBranchPattern = /^runtime-readiness-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
9
|
+
const managedWorkBranchPattern = /^(?:(?:story|task|bug|architect)|decompose\/(?:feature|work_order))\/[0-9a-f]{12}$/;
|
|
10
|
+
/** A readiness probe's branch: scratch that nothing reads once its worktree is gone. */
|
|
11
|
+
export function isRuntimeReadinessBranch(branchName) {
|
|
12
|
+
return runtimeReadinessBranchPattern.test(branchName);
|
|
13
|
+
}
|
|
14
|
+
/** A branch Forge named for a work item, Feature or Work Order. */
|
|
15
|
+
export function isForgeManagedWorkBranch(branchName) {
|
|
16
|
+
return managedWorkBranchPattern.test(branchName);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Deletes branches Forge created that no worktree has checked out: every readiness branch, and,
|
|
20
|
+
* when asked, every managed work branch whose changes are already on origin/<base> (as an ancestor,
|
|
21
|
+
* or because merging it into the base would change nothing, as after a squash merge). Branches with work that is not on the base
|
|
22
|
+
* are kept. Must run under the repository coordinator lock, like worktree creation.
|
|
23
|
+
*/
|
|
24
|
+
export async function sweepManagedBranches(git, repoPath, options) {
|
|
25
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
26
|
+
const checkedOut = await checkedOutBranches(git, repoPath);
|
|
27
|
+
const baseRef = options.includeMergedWorkBranches && options.baseBranch
|
|
28
|
+
? await existingRef(git, repoPath, `refs/remotes/origin/${options.baseBranch}`)
|
|
29
|
+
: null;
|
|
30
|
+
const branches = (await git.run(repoPath, ["for-each-ref", "--format=%(refname:short)", "refs/heads"]))
|
|
31
|
+
.split("\n")
|
|
32
|
+
.map(line => line.trim())
|
|
33
|
+
.filter(Boolean);
|
|
34
|
+
const deletedBranches = [];
|
|
35
|
+
for (const branch of branches) {
|
|
36
|
+
if (deletedBranches.length >= limit)
|
|
37
|
+
break;
|
|
38
|
+
if (checkedOut.has(branch) || options.protectedBranches?.has(branch))
|
|
39
|
+
continue;
|
|
40
|
+
const readiness = isRuntimeReadinessBranch(branch);
|
|
41
|
+
if (!readiness) {
|
|
42
|
+
if (!baseRef || !isForgeManagedWorkBranch(branch))
|
|
43
|
+
continue;
|
|
44
|
+
if (!(await changesAreOnBase(git, repoPath, branch, baseRef)))
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
await git.run(repoPath, ["branch", "-D", "--", branch]);
|
|
49
|
+
deletedBranches.push(branch);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// A branch another process just checked out or removed is not ours to fight over.
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { deletedBranches };
|
|
56
|
+
}
|
|
57
|
+
/** Deletes one branch unless a worktree still has it checked out. Never throws. */
|
|
58
|
+
export async function deleteBranchIfUnused(git, repoPath, branchName) {
|
|
59
|
+
try {
|
|
60
|
+
if ((await checkedOutBranches(git, repoPath)).has(branchName))
|
|
61
|
+
return false;
|
|
62
|
+
if (!(await existingRef(git, repoPath, `refs/heads/${branchName}`)))
|
|
63
|
+
return false;
|
|
64
|
+
await git.run(repoPath, ["branch", "-D", "--", branchName]);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function checkedOutBranches(git, repoPath) {
|
|
72
|
+
const output = await git.run(repoPath, ["worktree", "list", "--porcelain", "-z"]);
|
|
73
|
+
const branches = new Set();
|
|
74
|
+
for (const field of output.split("\0")) {
|
|
75
|
+
if (field.startsWith("branch refs/heads/"))
|
|
76
|
+
branches.add(field.slice("branch refs/heads/".length).trim());
|
|
77
|
+
}
|
|
78
|
+
return branches;
|
|
79
|
+
}
|
|
80
|
+
async function existingRef(git, repoPath, ref) {
|
|
81
|
+
try {
|
|
82
|
+
await git.run(repoPath, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]);
|
|
83
|
+
return ref;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// A branch's changes are on the base when it is an ancestor of the base, or when merging it into the
|
|
90
|
+
// base would change nothing: the merge result's tree is the base's own tree. That covers squash
|
|
91
|
+
// merges, and merges followed by unrelated work on the base, without making commits: merge-tree
|
|
92
|
+
// writes only content-addressed trees, so repeated sweeps reuse the same objects. A conflict, an
|
|
93
|
+
// unreadable ref or a git without `merge-tree --write-tree` (before 2.38) keeps the branch.
|
|
94
|
+
async function changesAreOnBase(git, repoPath, branch, baseRef) {
|
|
95
|
+
try {
|
|
96
|
+
await git.run(repoPath, ["merge-base", "--is-ancestor", branch, baseRef]);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Not an ancestor; it may have been squash-merged.
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const merged = (await git.run(repoPath, ["merge-tree", "--write-tree", "--no-messages", baseRef, branch]))
|
|
104
|
+
.split("\n")[0].trim();
|
|
105
|
+
const baseTree = (await git.run(repoPath, ["rev-parse", `${baseRef}^{tree}`])).trim();
|
|
106
|
+
return merged.length > 0 && merged === baseTree;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
package/dist/cli/cli.help.js
CHANGED
|
@@ -21,6 +21,7 @@ export function helpText() {
|
|
|
21
21
|
" remove-repo * Remove a saved repo mapping",
|
|
22
22
|
" cleanup * Prune managed bridge worktrees",
|
|
23
23
|
" sandbox * Initialize, diagnose, smoke-test, or reap Docker sandboxes",
|
|
24
|
+
" yield * Yield this machine to foreground work: no new attempts",
|
|
24
25
|
" version * Print the installed bridge package version",
|
|
25
26
|
" help * Display help for command",
|
|
26
27
|
" run-once * Internal: run one dispatch packet from JSON",
|
|
@@ -179,6 +180,23 @@ export function commandHelpText(command) {
|
|
|
179
180
|
"Stop the connected bridge first so the Docker ownership lock can be acquired.",
|
|
180
181
|
"",
|
|
181
182
|
].join("\n");
|
|
183
|
+
case "yield":
|
|
184
|
+
return [
|
|
185
|
+
"Forge Bridge — yield",
|
|
186
|
+
"Yield this machine to foreground work (for example while you are gaming).",
|
|
187
|
+
"",
|
|
188
|
+
"Usage:",
|
|
189
|
+
" forge-bridge yield on",
|
|
190
|
+
" forge-bridge yield off",
|
|
191
|
+
" forge-bridge yield status",
|
|
192
|
+
"",
|
|
193
|
+
"While yielding, the bridge takes no new attempts; running attempts finish, and",
|
|
194
|
+
"their heavy steps run under the yield CPU budget. A running bridge notices the",
|
|
195
|
+
"change within one heartbeat, without a restart, and reports it to Forge.",
|
|
196
|
+
"The flag is saved in its own file next to bridge.json. Yield is also on when the",
|
|
197
|
+
"runner's Yield toggle in Forge is on: either side turns it on.",
|
|
198
|
+
"",
|
|
199
|
+
].join("\n");
|
|
182
200
|
case "run-once":
|
|
183
201
|
return [
|
|
184
202
|
"Forge Bridge — run-once",
|
|
@@ -17,6 +17,7 @@ export declare class ForgeBridgeCliService implements CliService {
|
|
|
17
17
|
constructor(sessions?: SessionService, bridgeFactory?: (config: BridgeServiceConfig) => BridgeService, pairRunner?: PairRunnerClient, cleanupFactory?: CleanupServiceFactory, dotNetToolchainConfigurator?: DotNetToolchainConfigurator);
|
|
18
18
|
run(argv: readonly string[], io?: CliIo): Promise<number>;
|
|
19
19
|
}
|
|
20
|
+
type YieldAction = "on" | "off" | "status";
|
|
20
21
|
export declare function parseArgs(argv: readonly string[]): {
|
|
21
22
|
readonly ok: true;
|
|
22
23
|
readonly command: "run-once";
|
|
@@ -86,6 +87,10 @@ export declare function parseArgs(argv: readonly string[]): {
|
|
|
86
87
|
} | {
|
|
87
88
|
readonly ok: true;
|
|
88
89
|
readonly command: "sandbox-status";
|
|
90
|
+
} | {
|
|
91
|
+
readonly ok: true;
|
|
92
|
+
readonly command: "yield";
|
|
93
|
+
readonly action: YieldAction;
|
|
89
94
|
} | {
|
|
90
95
|
readonly ok: false;
|
|
91
96
|
readonly error: string;
|
|
@@ -104,13 +109,24 @@ interface PairArgs {
|
|
|
104
109
|
readonly repoRoot?: string;
|
|
105
110
|
readonly cleanupWorktrees: boolean;
|
|
106
111
|
readonly cliProviders: readonly string[];
|
|
112
|
+
/** True when `--cli-provider` named the providers, which then win over the Connect dialog's choice. */
|
|
113
|
+
readonly cliProvidersFromFlag?: boolean;
|
|
107
114
|
readonly projectLabels: readonly string[];
|
|
108
115
|
}
|
|
116
|
+
/** Decision 0014 §5: what the Connect dialog's pairing intent set for this host, echoed by the claim. */
|
|
117
|
+
export interface PairRunnerHost {
|
|
118
|
+
readonly name?: string;
|
|
119
|
+
readonly repoRoot?: string;
|
|
120
|
+
readonly cliProviders?: readonly string[];
|
|
121
|
+
}
|
|
109
122
|
interface PairRunnerClaim {
|
|
110
123
|
readonly runnerId: string;
|
|
111
124
|
readonly deviceToken: string;
|
|
125
|
+
readonly host?: PairRunnerHost;
|
|
112
126
|
}
|
|
113
127
|
type PairRunnerClient = (args: PairArgs) => Promise<PairRunnerClaim>;
|
|
128
|
+
/** Expands `~` in a repo folder chosen in Forge and rejects one shaped for another OS. */
|
|
129
|
+
export declare function resolveHostRepoRoot(value: string, platform?: NodeJS.Platform, home?: string): string | undefined;
|
|
114
130
|
export declare const claudeDefaultModels: readonly string[];
|
|
115
131
|
export declare function parseCodexModelCatalog(raw: string): string[];
|
|
116
132
|
export declare function parseCursorModelList(raw: string): string[];
|
package/dist/cli/cli.service.js
CHANGED
|
@@ -9,10 +9,10 @@ import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
|
|
|
9
9
|
import { configureDotNetToolchain } from "../shared/process/dotnet-toolchain.js";
|
|
10
10
|
import { supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
11
11
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
12
|
-
import { defaultBridgeServiceConfig, ForgeBridgeService } from "../bridge/bridge.service.js";
|
|
12
|
+
import { BridgeRevokedError, bridgeRevokedExitCode, defaultBridgeServiceConfig, ForgeBridgeService, } from "../bridge/bridge.service.js";
|
|
13
13
|
import { forgeBridgeVersion } from "../version.js";
|
|
14
14
|
import { ManagedWorktreeCleanupService } from "../cleanup/cleanup.service.js";
|
|
15
|
-
import { addRepoMapping, applyLocalConfigDefaults, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
|
|
15
|
+
import { addRepoMapping, applyLocalConfigDefaults, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, resolveLocalYieldFlagPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
|
|
16
16
|
import { BridgeSessionService } from "../session/session.service.js";
|
|
17
17
|
import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "../session/session-redaction.js";
|
|
18
18
|
import { validateDockerfilePolicy, validateSandboxContract } from "../sandbox/contract.js";
|
|
@@ -22,6 +22,7 @@ import { DockerSandboxSmoke } from "../sandbox/smoke.js";
|
|
|
22
22
|
import { parseCompletionMcpArgs, runCompletionMcpServer } from "../session/phase-completion.js";
|
|
23
23
|
import { failureFactsFromError, failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
|
|
24
24
|
import { commandHelpText, helpText } from "./cli.help.js";
|
|
25
|
+
import { readLocalYieldFlag, writeLocalYieldFlag } from "../bridge/local-yield-flag.js";
|
|
25
26
|
const apiKeySecretGrantEnv = "FORGE_API_KEY_SECRET_GRANT";
|
|
26
27
|
const execFileAsync = promisify(execFile);
|
|
27
28
|
export class ForgeBridgeCliService {
|
|
@@ -30,7 +31,9 @@ export class ForgeBridgeCliService {
|
|
|
30
31
|
pairRunner;
|
|
31
32
|
cleanupFactory;
|
|
32
33
|
dotNetToolchainConfigurator;
|
|
33
|
-
constructor(
|
|
34
|
+
constructor(
|
|
35
|
+
// In a Docker sandbox the default chain's validator asks the host bridge for host load tokens (decision 0013).
|
|
36
|
+
sessions = new BridgeSessionService(), bridgeFactory = (config) => new ForgeBridgeService(config), pairRunner = claimBridgeRunner, cleanupFactory = stateRoot => new ManagedWorktreeCleanupService(stateRoot), dotNetToolchainConfigurator = configureDotNetToolchain) {
|
|
34
37
|
this.sessions = sessions;
|
|
35
38
|
this.bridgeFactory = bridgeFactory;
|
|
36
39
|
this.pairRunner = pairRunner;
|
|
@@ -89,11 +92,22 @@ export class ForgeBridgeCliService {
|
|
|
89
92
|
if (config.cleanupWorktrees && config.repoMappings.some(mapping => mapping.localPath?.trim())) {
|
|
90
93
|
io.stdout.write("Cleaning stale managed worktrees before accepting dispatches.\n");
|
|
91
94
|
await cleanupRepos(config, "stale", true, this.cleanupFactory(config.sandboxStateRoot), io);
|
|
95
|
+
// Forge branches on this device whose work has merged since the bridge last ran.
|
|
96
|
+
await cleanupRepos(config, "merged", true, this.cleanupFactory(config.sandboxStateRoot), io);
|
|
92
97
|
}
|
|
93
98
|
io.stdout.write(connectStartupText(config));
|
|
94
99
|
await this.bridgeFactory(config).run(controller.signal);
|
|
95
100
|
return 0;
|
|
96
101
|
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (error instanceof BridgeRevokedError) {
|
|
104
|
+
// Decision 0014: removed from Forge. Exit with a distinct code so a supervisor can
|
|
105
|
+
// tell "pair again" apart from a crash.
|
|
106
|
+
io.stderr.write(`${error.message}\n`);
|
|
107
|
+
return bridgeRevokedExitCode;
|
|
108
|
+
}
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
97
111
|
finally {
|
|
98
112
|
process.off("SIGINT", stop);
|
|
99
113
|
process.off("SIGTERM", stop);
|
|
@@ -117,13 +131,22 @@ export class ForgeBridgeCliService {
|
|
|
117
131
|
const current = readLocalConfigSync();
|
|
118
132
|
io.stdout.write(`Pairing with server: ${args.serverUrl}\n`);
|
|
119
133
|
const code = await resolvePairingCode(args.code);
|
|
120
|
-
const
|
|
121
|
-
await
|
|
122
|
-
const pairArgs = await withDetectedPairCliProviders({ ...args, code, repoRoot });
|
|
134
|
+
const provisionalRoot = path.resolve(args.repoRoot ?? current.defaultRepoRoot ?? path.join(os.homedir(), "ForgeRepos"));
|
|
135
|
+
const pairArgs = await withDetectedPairCliProviders({ ...args, code, repoRoot: provisionalRoot });
|
|
123
136
|
const claim = await this.pairRunner(pairArgs);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
137
|
+
// The code is spent now: save the credentials before anything else can fail or prompt.
|
|
138
|
+
const applied = applyPairHost(pairArgs, claim.host, args.repoRoot !== undefined, io);
|
|
139
|
+
await writeLocalConfig(pairedConfig(current, applied.args, claim));
|
|
140
|
+
let repoRoot = applied.args.repoRoot;
|
|
141
|
+
if (!args.repoRoot && !applied.repoRootFromHost) {
|
|
142
|
+
const answered = await promptPairRepoRoot(repoRoot);
|
|
143
|
+
if (answered !== repoRoot) {
|
|
144
|
+
repoRoot = answered;
|
|
145
|
+
await writeLocalConfig(pairedConfig(current, { ...applied.args, repoRoot }, claim));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
await fs.mkdir(repoRoot, { recursive: true });
|
|
149
|
+
io.stdout.write(`Paired runner ${claim.runnerId}${applied.args.name ? ` (${applied.args.name})` : ""}.\n`);
|
|
127
150
|
io.stdout.write(`Repo folder: ${repoRoot}\n`);
|
|
128
151
|
io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
|
|
129
152
|
io.stdout.write("Start the bridge with: forge-bridge connect\n");
|
|
@@ -206,6 +229,9 @@ export class ForgeBridgeCliService {
|
|
|
206
229
|
writeSandboxPolicyStatus(readLocalConfigSync(), io);
|
|
207
230
|
return 0;
|
|
208
231
|
}
|
|
232
|
+
if (args.command === "yield") {
|
|
233
|
+
return await runYieldCommand(args.action, io);
|
|
234
|
+
}
|
|
209
235
|
if (args.command === "mcp") {
|
|
210
236
|
const parsed = parseCompletionMcpArgs(args.argv);
|
|
211
237
|
if (!parsed.ok) {
|
|
@@ -243,6 +269,36 @@ export class ForgeBridgeCliService {
|
|
|
243
269
|
}
|
|
244
270
|
}
|
|
245
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Decision 0014 `forge-bridge yield`: the host's own yield switch. It writes a
|
|
274
|
+
* flag file next to the bridge config (never bridge.json); a running bridge
|
|
275
|
+
* polls it and stops taking new attempts without a restart.
|
|
276
|
+
*/
|
|
277
|
+
async function runYieldCommand(action, io) {
|
|
278
|
+
const flagPath = resolveLocalYieldFlagPath();
|
|
279
|
+
try {
|
|
280
|
+
if (action !== "status") {
|
|
281
|
+
await writeLocalYieldFlag(flagPath, action === "on");
|
|
282
|
+
}
|
|
283
|
+
const on = await readLocalYieldFlag(flagPath);
|
|
284
|
+
if (action === "on") {
|
|
285
|
+
io.stdout.write("Local yield to foreground is on. A running bridge takes no new attempts within one heartbeat; running attempts finish.\n");
|
|
286
|
+
}
|
|
287
|
+
else if (action === "off") {
|
|
288
|
+
io.stdout.write("Local yield to foreground is off. The bridge takes new attempts again unless yield is on in Forge.\n");
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
io.stdout.write(`Local yield to foreground: ${on ? "on" : "off"}\n`);
|
|
292
|
+
}
|
|
293
|
+
io.stdout.write(`Flag file: ${flagPath}\n`);
|
|
294
|
+
io.stdout.write("The effective state also depends on Forge: the runner yields when this flag or its Yield toggle in Forge is on.\n");
|
|
295
|
+
return 0;
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
io.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
299
|
+
return 1;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
246
302
|
function attachEnvSecretGrant(dispatch) {
|
|
247
303
|
if (!dispatch.execution.requiresApiKeySecretGrant) {
|
|
248
304
|
delete process.env[apiKeySecretGrantEnv];
|
|
@@ -346,6 +402,13 @@ export function parseArgs(argv) {
|
|
|
346
402
|
if (argv[0] === "sandbox") {
|
|
347
403
|
return parseSandboxArgs(argv);
|
|
348
404
|
}
|
|
405
|
+
if (argv[0] === "yield") {
|
|
406
|
+
const action = argv[1] ?? "status";
|
|
407
|
+
if (argv.length > 2 || (action !== "on" && action !== "off" && action !== "status")) {
|
|
408
|
+
return { ok: false, error: "Usage: forge-bridge yield [on|off|status]" };
|
|
409
|
+
}
|
|
410
|
+
return { ok: true, command: "yield", action };
|
|
411
|
+
}
|
|
349
412
|
if (argv[0] !== "run-once") {
|
|
350
413
|
return {
|
|
351
414
|
ok: false,
|
|
@@ -759,6 +822,7 @@ function parsePairArgs(argv) {
|
|
|
759
822
|
repoRoot: repoRoot?.trim() ? path.resolve(repoRoot) : undefined,
|
|
760
823
|
cleanupWorktrees: cleanupWorktrees ?? defaultConfig.cleanupWorktrees,
|
|
761
824
|
cliProviders: cliProviders.length > 0 ? cliProviders : localConfig.cliProviders && localConfig.cliProviders.length > 0 ? [...localConfig.cliProviders] : ["codex"],
|
|
825
|
+
cliProvidersFromFlag: cliProviders.length > 0,
|
|
762
826
|
projectLabels: projectLabels.length > 0 ? projectLabels : localConfig.projectLabels ? [...localConfig.projectLabels] : []
|
|
763
827
|
};
|
|
764
828
|
}
|
|
@@ -821,9 +885,71 @@ async function claimBridgeRunner(args) {
|
|
|
821
885
|
}
|
|
822
886
|
return {
|
|
823
887
|
runnerId: value.runnerId,
|
|
824
|
-
deviceToken: value.deviceToken
|
|
888
|
+
deviceToken: value.deviceToken,
|
|
889
|
+
host: parsePairRunnerHost(value.host)
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
function parsePairRunnerHost(value) {
|
|
893
|
+
if (!value || typeof value !== "object") {
|
|
894
|
+
return undefined;
|
|
895
|
+
}
|
|
896
|
+
const host = value;
|
|
897
|
+
const name = typeof host.name === "string" && host.name.trim() ? host.name.trim() : undefined;
|
|
898
|
+
const repoRoot = typeof host.repoRoot === "string" && host.repoRoot.trim() ? host.repoRoot.trim() : undefined;
|
|
899
|
+
const cliProviders = Array.isArray(host.cliProviders)
|
|
900
|
+
? host.cliProviders.filter((provider) => typeof provider === "string" && provider.trim().length > 0)
|
|
901
|
+
: [];
|
|
902
|
+
return { name, repoRoot, cliProviders: cliProviders.length > 0 ? cliProviders : undefined };
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Decision 0014 §5: the claim's host block carries what the Connect dialog chose. The runner name
|
|
906
|
+
* is the server's; providers and the repo folder apply unless a flag named them on this command line.
|
|
907
|
+
*/
|
|
908
|
+
function applyPairHost(args, host, repoRootFromFlag, io) {
|
|
909
|
+
if (!host) {
|
|
910
|
+
return { args, repoRootFromHost: false };
|
|
911
|
+
}
|
|
912
|
+
let repoRoot = args.repoRoot;
|
|
913
|
+
let repoRootFromHost = false;
|
|
914
|
+
if (host.repoRoot && !repoRootFromFlag) {
|
|
915
|
+
const resolved = resolveHostRepoRoot(host.repoRoot);
|
|
916
|
+
if (!resolved) {
|
|
917
|
+
io.stderr.write(`Ignoring the repo folder chosen in Forge (${host.repoRoot}): it is not a path on this machine.\n`);
|
|
918
|
+
}
|
|
919
|
+
else {
|
|
920
|
+
repoRootFromHost = true;
|
|
921
|
+
repoRoot = resolved;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
return {
|
|
925
|
+
args: {
|
|
926
|
+
...args,
|
|
927
|
+
name: host.name ?? args.name,
|
|
928
|
+
cliProviders: host.cliProviders && !args.cliProvidersFromFlag ? [...host.cliProviders] : args.cliProviders,
|
|
929
|
+
repoRoot
|
|
930
|
+
},
|
|
931
|
+
repoRootFromHost
|
|
825
932
|
};
|
|
826
933
|
}
|
|
934
|
+
/** Expands `~` in a repo folder chosen in Forge and rejects one shaped for another OS. */
|
|
935
|
+
export function resolveHostRepoRoot(value, platform = process.platform, home = os.homedir()) {
|
|
936
|
+
const trimmed = value.trim();
|
|
937
|
+
if (!trimmed) {
|
|
938
|
+
return undefined;
|
|
939
|
+
}
|
|
940
|
+
const pathApi = platform === "win32" ? path.win32 : path.posix;
|
|
941
|
+
if (trimmed === "~") {
|
|
942
|
+
return home;
|
|
943
|
+
}
|
|
944
|
+
if (/^~[\\/]/.test(trimmed)) {
|
|
945
|
+
return pathApi.resolve(home, trimmed.slice(2));
|
|
946
|
+
}
|
|
947
|
+
const windowsShaped = /^[A-Za-z]:[\\/]/.test(trimmed) || trimmed.startsWith("\\\\");
|
|
948
|
+
if (platform === "win32") {
|
|
949
|
+
return windowsShaped || trimmed.startsWith("/") ? pathApi.resolve(trimmed) : undefined;
|
|
950
|
+
}
|
|
951
|
+
return !windowsShaped && trimmed.startsWith("/") ? pathApi.resolve(trimmed) : undefined;
|
|
952
|
+
}
|
|
827
953
|
function pairedConfig(current, args, claim) {
|
|
828
954
|
return {
|
|
829
955
|
...current,
|
|
@@ -868,11 +994,7 @@ async function resolvePairingCode(code) {
|
|
|
868
994
|
prompt.close();
|
|
869
995
|
}
|
|
870
996
|
}
|
|
871
|
-
async function
|
|
872
|
-
const fallback = path.resolve(repoRoot ?? configuredRoot ?? path.join(os.homedir(), "ForgeRepos"));
|
|
873
|
-
if (repoRoot?.trim()) {
|
|
874
|
-
return fallback;
|
|
875
|
-
}
|
|
997
|
+
async function promptPairRepoRoot(fallback) {
|
|
876
998
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
877
999
|
return fallback;
|
|
878
1000
|
}
|
|
@@ -1001,7 +1123,11 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
1001
1123
|
io.stdout.write(`Removed ${result.removedWorktrees} stale managed ${result.removedWorktrees === 1 ? "worktree" : "worktrees"} from ${result.worktreeRoot}\n`);
|
|
1002
1124
|
}
|
|
1003
1125
|
else {
|
|
1004
|
-
|
|
1126
|
+
const deleted = result.deletedBranches ?? 0;
|
|
1127
|
+
io.stdout.write(`Pruned stale worktree metadata and deleted ${deleted} Forge ${deleted === 1 ? "branch" : "branches"} (merged work and leftover readiness probes) in ${repoPath}\n`);
|
|
1128
|
+
if (result.mergedBaseUnresolved) {
|
|
1129
|
+
io.stderr.write(`${repoPath}: merged work branches were kept because the base branch couldn't be determined: origin/HEAD is unset or names a branch that no longer exists, and origin has none or more than one of develop, main and master. Run \`git fetch origin && git remote set-head origin --auto\`.\n`);
|
|
1130
|
+
}
|
|
1005
1131
|
}
|
|
1006
1132
|
}
|
|
1007
1133
|
catch (error) {
|
|
@@ -30,8 +30,12 @@ export interface LocalRepoMapping extends BridgeRepoMapping {
|
|
|
30
30
|
export declare function resolveLocalConfigPath(): string;
|
|
31
31
|
export declare function readLocalConfig(): Promise<BridgeLocalConfig>;
|
|
32
32
|
export declare function readLocalConfigSync(): BridgeLocalConfig;
|
|
33
|
+
/** Decision 0014 §5: `bridge.json` holds the device token, so only its owner may read it. */
|
|
34
|
+
export declare const localConfigFileMode = 384;
|
|
33
35
|
export declare function writeLocalConfig(config: BridgeLocalConfig): Promise<void>;
|
|
34
36
|
export declare function applyLocalConfigDefaults(config: BridgeServiceConfig, local: BridgeLocalConfig): BridgeServiceConfig;
|
|
37
|
+
/** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
|
|
38
|
+
export declare function resolveLocalYieldFlagPath(): string;
|
|
35
39
|
export declare function addRepoMapping(label: string, repoPath: string): Promise<BridgeLocalConfig>;
|
|
36
40
|
export declare function removeRepoMapping(label: string): Promise<{
|
|
37
41
|
readonly config: BridgeLocalConfig;
|
package/dist/cli/local-config.js
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import fsSync from "node:fs";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { localYieldFlagPathFor } from "../bridge/local-yield-flag.js";
|
|
5
6
|
export function resolveLocalConfigPath() {
|
|
6
7
|
if (process.env.FORGE_BRIDGE_CONFIG?.trim()) {
|
|
7
8
|
return path.resolve(process.env.FORGE_BRIDGE_CONFIG);
|
|
@@ -28,12 +29,28 @@ export function readLocalConfigSync() {
|
|
|
28
29
|
}
|
|
29
30
|
return parseLocalConfig(fsSync.readFileSync(configPath, "utf8"));
|
|
30
31
|
}
|
|
32
|
+
/** Decision 0014 §5: `bridge.json` holds the device token, so only its owner may read it. */
|
|
33
|
+
export const localConfigFileMode = 0o600;
|
|
34
|
+
const localConfigDirectoryMode = 0o700;
|
|
31
35
|
export async function writeLocalConfig(config) {
|
|
32
36
|
const configPath = resolveLocalConfigPath();
|
|
33
|
-
await fs.mkdir(path.dirname(configPath), { recursive: true });
|
|
37
|
+
await fs.mkdir(path.dirname(configPath), { recursive: true, mode: localConfigDirectoryMode });
|
|
34
38
|
const tempPath = `${configPath}.${process.pid}.${Date.now()}.tmp`;
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
try {
|
|
40
|
+
await fs.writeFile(tempPath, `${JSON.stringify(normalizeLocalConfig(config), null, 2)}\n`, {
|
|
41
|
+
encoding: "utf8",
|
|
42
|
+
mode: localConfigFileMode
|
|
43
|
+
});
|
|
44
|
+
if (process.platform !== "win32") {
|
|
45
|
+
// The create mode is masked by the umask; set it exactly before the file becomes visible.
|
|
46
|
+
await fs.chmod(tempPath, localConfigFileMode);
|
|
47
|
+
}
|
|
48
|
+
await fs.rename(tempPath, configPath);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
await fs.rm(tempPath, { force: true }).catch(() => undefined);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
37
54
|
}
|
|
38
55
|
export function applyLocalConfigDefaults(config, local) {
|
|
39
56
|
const cliProviders = local.cliProviders && local.cliProviders.length > 0 ? [...local.cliProviders] : config.cliProviders;
|
|
@@ -65,9 +82,14 @@ export function applyLocalConfigDefaults(config, local) {
|
|
|
65
82
|
supportsRunnerAuthoredPhaseArtifacts: local.supportsRunnerAuthoredPhaseArtifacts ?? config.supportsRunnerAuthoredPhaseArtifacts,
|
|
66
83
|
supportsDraftRunOnce: local.supportsDraftRunOnce ?? config.supportsDraftRunOnce,
|
|
67
84
|
supportsDraftAttachments: local.supportsDraftAttachments ?? config.supportsDraftAttachments,
|
|
68
|
-
supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments
|
|
85
|
+
supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments,
|
|
86
|
+
localYieldFlagPath: resolveLocalYieldFlagPath()
|
|
69
87
|
};
|
|
70
88
|
}
|
|
89
|
+
/** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
|
|
90
|
+
export function resolveLocalYieldFlagPath() {
|
|
91
|
+
return localYieldFlagPathFor(resolveLocalConfigPath());
|
|
92
|
+
}
|
|
71
93
|
export async function addRepoMapping(label, repoPath) {
|
|
72
94
|
const normalizedLabel = normalizeLabel(label);
|
|
73
95
|
const localPath = path.resolve(repoPath);
|