@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,31 @@
|
|
|
1
|
+
export declare const maximumIntegrityJsonBytes: number;
|
|
2
|
+
/** A JSON text that breaks a shape rule. `reason` names the rule and never quotes file content. */
|
|
3
|
+
export declare class JsonShapeError extends Error {
|
|
4
|
+
readonly reason: string;
|
|
5
|
+
constructor(reason: string);
|
|
6
|
+
}
|
|
7
|
+
export declare const oversizedJsonReason = "it is larger than the 8 MiB JSON inspection limit";
|
|
8
|
+
/**
|
|
9
|
+
* Checks a bounded JSON text and calls `onString` with every decoded string token (property names
|
|
10
|
+
* and values). Throws JsonShapeError for a shape problem; errors thrown by `onString` propagate.
|
|
11
|
+
*/
|
|
12
|
+
export declare function inspectJsonText(value: string, onString?: (decoded: string) => void): void;
|
|
13
|
+
export declare function decodeJsonStringToken(value: string, openingQuoteIndex: number): {
|
|
14
|
+
readonly decoded: string;
|
|
15
|
+
readonly nextIndex: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Why a sidecar that looks like JSON is not acceptable JSON, or null when it is fine: valid JSON,
|
|
19
|
+
* plain text that does not start like JSON, or binary content that is not named *.json.
|
|
20
|
+
*/
|
|
21
|
+
export declare function sidecarJsonShapeProblem(content: Uint8Array, path: string, onString?: (decoded: string) => void): string | null;
|
|
22
|
+
/** The instruction an agent gets when it records a sidecar that fails the shape check. */
|
|
23
|
+
export declare function sidecarJsonRepairInstruction(path: string, reason: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Best-effort decoding of every JSON escape in a text that failed the shape check, so a secret
|
|
26
|
+
* hidden behind escapes still gets the secret error rather than the malformed-sidecar error.
|
|
27
|
+
*/
|
|
28
|
+
export declare function decodeJsonEscapesLeniently(value: string): string;
|
|
29
|
+
export declare function looksLikeJson(value: string, path: string): boolean;
|
|
30
|
+
export declare function isJsonWhitespace(code: number): boolean;
|
|
31
|
+
export declare function isJsonPunctuation(code: number): boolean;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { TextDecoder } from "node:util";
|
|
2
|
+
// One set of JSON shape rules for result sidecars. The end-of-run secret check and the QA gate
|
|
3
|
+
// tools that record sidecars during the run both use it, so the agent is told about a malformed
|
|
4
|
+
// sidecar while it can still rewrite the file, and the end-of-run check never disagrees with it.
|
|
5
|
+
//
|
|
6
|
+
// Content sniffing is deliberate: any sidecar whose text starts like JSON ("{", "[" or '"') is
|
|
7
|
+
// held to strict JSON, whatever its file name, so JSON escapes cannot hide secret material from
|
|
8
|
+
// the byte scan. Only a parseable document can be checked token by token.
|
|
9
|
+
export const maximumIntegrityJsonBytes = 8 * 1024 * 1024;
|
|
10
|
+
const maximumIntegrityJsonDepth = 128;
|
|
11
|
+
const maximumIntegrityJsonTokens = 262_144;
|
|
12
|
+
const jsonEscapePattern = /\\(?:u([0-9a-fA-F]{4})|(["\\/bfnrt]))/gu;
|
|
13
|
+
const simpleJsonEscapes = {
|
|
14
|
+
"\"": "\"", "\\": "\\", "/": "/", b: "\b", f: "\f", n: "\n", r: "\r", t: "\t",
|
|
15
|
+
};
|
|
16
|
+
/** A JSON text that breaks a shape rule. `reason` names the rule and never quotes file content. */
|
|
17
|
+
export class JsonShapeError extends Error {
|
|
18
|
+
reason;
|
|
19
|
+
constructor(reason) {
|
|
20
|
+
super(reason);
|
|
21
|
+
this.reason = reason;
|
|
22
|
+
this.name = "JsonShapeError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export const oversizedJsonReason = "it is larger than the 8 MiB JSON inspection limit";
|
|
26
|
+
/**
|
|
27
|
+
* Checks a bounded JSON text and calls `onString` with every decoded string token (property names
|
|
28
|
+
* and values). Throws JsonShapeError for a shape problem; errors thrown by `onString` propagate.
|
|
29
|
+
*/
|
|
30
|
+
export function inspectJsonText(value, onString) {
|
|
31
|
+
if (Buffer.byteLength(value, "utf8") > maximumIntegrityJsonBytes)
|
|
32
|
+
throw new JsonShapeError(oversizedJsonReason);
|
|
33
|
+
if (value.trim().length === 0)
|
|
34
|
+
throw new JsonShapeError("the file is empty");
|
|
35
|
+
const containers = [];
|
|
36
|
+
let tokenCount = 0;
|
|
37
|
+
let index = 0;
|
|
38
|
+
while (index < value.length) {
|
|
39
|
+
const code = value.charCodeAt(index);
|
|
40
|
+
if (isJsonWhitespace(code) || code === 0x2c || code === 0x3a) {
|
|
41
|
+
index += 1;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
tokenCount += 1;
|
|
45
|
+
if (tokenCount > maximumIntegrityJsonTokens) {
|
|
46
|
+
throw new JsonShapeError(`it has more than ${maximumIntegrityJsonTokens} JSON tokens`);
|
|
47
|
+
}
|
|
48
|
+
index = inspectJsonToken(value, index, containers, onString);
|
|
49
|
+
}
|
|
50
|
+
if (containers.length !== 0)
|
|
51
|
+
throw new JsonShapeError("a bracket or brace is never closed");
|
|
52
|
+
assertJsonParses(value);
|
|
53
|
+
}
|
|
54
|
+
function inspectJsonToken(value, index, containers, onString) {
|
|
55
|
+
const code = value.charCodeAt(index);
|
|
56
|
+
if (code === 0x22) {
|
|
57
|
+
const token = decodeJsonStringToken(value, index);
|
|
58
|
+
onString?.(token.decoded);
|
|
59
|
+
return token.nextIndex;
|
|
60
|
+
}
|
|
61
|
+
if (code === 0x7b || code === 0x5b) {
|
|
62
|
+
containers.push(code);
|
|
63
|
+
if (containers.length > maximumIntegrityJsonDepth) {
|
|
64
|
+
throw new JsonShapeError(`it nests deeper than ${maximumIntegrityJsonDepth} levels`);
|
|
65
|
+
}
|
|
66
|
+
return index + 1;
|
|
67
|
+
}
|
|
68
|
+
if (code === 0x7d || code === 0x5d) {
|
|
69
|
+
if (containers.pop() !== (code === 0x7d ? 0x7b : 0x5b)) {
|
|
70
|
+
throw new JsonShapeError(`an unmatched closing bracket or brace ${locationOf(value, index)}`);
|
|
71
|
+
}
|
|
72
|
+
return index + 1;
|
|
73
|
+
}
|
|
74
|
+
let end = index + 1;
|
|
75
|
+
while (end < value.length && !isJsonWhitespace(value.charCodeAt(end)) && !isJsonPunctuation(value.charCodeAt(end))) {
|
|
76
|
+
end += 1;
|
|
77
|
+
}
|
|
78
|
+
return end;
|
|
79
|
+
}
|
|
80
|
+
function assertJsonParses(value) {
|
|
81
|
+
try {
|
|
82
|
+
JSON.parse(value);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// The parser's message can quote the offending text; keep only its position.
|
|
86
|
+
const message = error instanceof Error ? error.message : "";
|
|
87
|
+
const position = /\bposition (\d+)/u.exec(message);
|
|
88
|
+
const location = position ? ` ${locationOf(value, Number(position[1]))}` : "";
|
|
89
|
+
throw new JsonShapeError(message.includes("after JSON")
|
|
90
|
+
? `unexpected text after the JSON value${location}`
|
|
91
|
+
: `invalid JSON syntax${location}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function decodeJsonStringToken(value, openingQuoteIndex) {
|
|
95
|
+
const chunks = [];
|
|
96
|
+
let segmentStart = openingQuoteIndex + 1;
|
|
97
|
+
let index = segmentStart;
|
|
98
|
+
while (index < value.length) {
|
|
99
|
+
const code = value.charCodeAt(index);
|
|
100
|
+
if (code === 0x22) {
|
|
101
|
+
chunks.push(value.slice(segmentStart, index));
|
|
102
|
+
const decoded = chunks.join("");
|
|
103
|
+
if (!isWellFormedUnicode(decoded)) {
|
|
104
|
+
throw new JsonShapeError(`a string has an unpaired Unicode surrogate ${locationOf(value, openingQuoteIndex)}`);
|
|
105
|
+
}
|
|
106
|
+
return { decoded, nextIndex: index + 1 };
|
|
107
|
+
}
|
|
108
|
+
if (code < 0x20) {
|
|
109
|
+
throw new JsonShapeError(`a string contains a raw control character ${locationOf(value, index)}`);
|
|
110
|
+
}
|
|
111
|
+
if (code !== 0x5c) {
|
|
112
|
+
index += 1;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
chunks.push(value.slice(segmentStart, index));
|
|
116
|
+
const escape = decodeJsonEscape(value, index);
|
|
117
|
+
chunks.push(escape.decoded);
|
|
118
|
+
index = escape.nextIndex;
|
|
119
|
+
segmentStart = index;
|
|
120
|
+
}
|
|
121
|
+
throw new JsonShapeError(`a string is never closed ${locationOf(value, openingQuoteIndex)}`);
|
|
122
|
+
}
|
|
123
|
+
function decodeJsonEscape(value, backslashIndex) {
|
|
124
|
+
const escaped = value[backslashIndex + 1];
|
|
125
|
+
const simple = escaped === undefined ? undefined : simpleJsonEscapes[escaped];
|
|
126
|
+
if (simple !== undefined)
|
|
127
|
+
return { decoded: simple, nextIndex: backslashIndex + 2 };
|
|
128
|
+
const hex = value.slice(backslashIndex + 2, backslashIndex + 6);
|
|
129
|
+
if (escaped !== "u" || !/^[0-9a-fA-F]{4}$/u.test(hex)) {
|
|
130
|
+
throw new JsonShapeError(`a string has an invalid escape sequence ${locationOf(value, backslashIndex)}`);
|
|
131
|
+
}
|
|
132
|
+
return { decoded: String.fromCharCode(Number.parseInt(hex, 16)), nextIndex: backslashIndex + 6 };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Why a sidecar that looks like JSON is not acceptable JSON, or null when it is fine: valid JSON,
|
|
136
|
+
* plain text that does not start like JSON, or binary content that is not named *.json.
|
|
137
|
+
*/
|
|
138
|
+
export function sidecarJsonShapeProblem(content, path, onString) {
|
|
139
|
+
let decoded;
|
|
140
|
+
try {
|
|
141
|
+
decoded = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(content);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// Sniff the bytes anyway (invalid sequences decode to U+FFFD, which is not whitespace), so a
|
|
145
|
+
// file that starts like JSON cannot dodge the strict check with a stray invalid byte.
|
|
146
|
+
return looksLikeJson(Buffer.from(content).toString("utf8"), path) ? "the file is not valid UTF-8" : null;
|
|
147
|
+
}
|
|
148
|
+
if (!looksLikeJson(decoded, path))
|
|
149
|
+
return null;
|
|
150
|
+
if (content.length >= 3 && content[0] === 0xef && content[1] === 0xbb && content[2] === 0xbf) {
|
|
151
|
+
return "the file starts with a UTF-8 byte-order mark";
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
inspectJsonText(decoded, onString);
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (error instanceof JsonShapeError)
|
|
159
|
+
return error.reason;
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** The instruction an agent gets when it records a sidecar that fails the shape check. */
|
|
164
|
+
export function sidecarJsonRepairInstruction(path, reason) {
|
|
165
|
+
const fix = isJsonFileName(path)
|
|
166
|
+
? "Rewrite it as valid JSON (UTF-8, no byte-order mark), or save plain-text output under a name that does not end in .json"
|
|
167
|
+
: "Rewrite it as valid JSON, or as plain text that does not start with \"[\", \"{\" or a double quote (for example, put a title line first)";
|
|
168
|
+
return `${path} looks like JSON but is not valid JSON (${reason}). Forge rejects sidecars it cannot fully inspect. `
|
|
169
|
+
+ `${fix}, then resubmit with the file's new bytes and content_hash.`;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Best-effort decoding of every JSON escape in a text that failed the shape check, so a secret
|
|
173
|
+
* hidden behind escapes still gets the secret error rather than the malformed-sidecar error.
|
|
174
|
+
*/
|
|
175
|
+
export function decodeJsonEscapesLeniently(value) {
|
|
176
|
+
return value.replace(jsonEscapePattern, (_match, hex, simple) => hex !== undefined ? String.fromCharCode(Number.parseInt(hex, 16)) : simpleJsonEscapes[simple ?? ""] ?? "");
|
|
177
|
+
}
|
|
178
|
+
export function looksLikeJson(value, path) {
|
|
179
|
+
if (isJsonFileName(path))
|
|
180
|
+
return true;
|
|
181
|
+
const candidate = value.trimStart().replace(/^\uFEFF/u, "").trimStart();
|
|
182
|
+
return candidate.startsWith("{") || candidate.startsWith("[") || candidate.startsWith("\"");
|
|
183
|
+
}
|
|
184
|
+
function isJsonFileName(path) {
|
|
185
|
+
return path.toLowerCase().endsWith(".json");
|
|
186
|
+
}
|
|
187
|
+
function locationOf(value, index) {
|
|
188
|
+
let line = 1;
|
|
189
|
+
let lineStart = 0;
|
|
190
|
+
for (let cursor = value.indexOf("\n"); cursor >= 0 && cursor < index; cursor = value.indexOf("\n", cursor + 1)) {
|
|
191
|
+
line += 1;
|
|
192
|
+
lineStart = cursor + 1;
|
|
193
|
+
}
|
|
194
|
+
return `at line ${line}, column ${index - lineStart + 1}`;
|
|
195
|
+
}
|
|
196
|
+
function isWellFormedUnicode(value) {
|
|
197
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
198
|
+
const code = value.charCodeAt(index);
|
|
199
|
+
if (code >= 0xd800 && code <= 0xdbff) {
|
|
200
|
+
const next = value.charCodeAt(index + 1);
|
|
201
|
+
if (!(next >= 0xdc00 && next <= 0xdfff))
|
|
202
|
+
return false;
|
|
203
|
+
index += 1;
|
|
204
|
+
}
|
|
205
|
+
else if (code >= 0xdc00 && code <= 0xdfff) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
export function isJsonWhitespace(code) {
|
|
212
|
+
return code === 0x20 || code === 0x09 || code === 0x0a || code === 0x0d;
|
|
213
|
+
}
|
|
214
|
+
export function isJsonPunctuation(code) {
|
|
215
|
+
return code === 0x7b || code === 0x7d || code === 0x5b || code === 0x5d
|
|
216
|
+
|| code === 0x2c || code === 0x3a || code === 0x22;
|
|
217
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BigIntStats } from "node:fs";
|
|
2
|
+
export type FileIdentity = Pick<BigIntStats, "dev" | "ino">;
|
|
3
|
+
export declare function sameFileIdentity(left: FileIdentity, right: FileIdentity): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Whether a path now names a different file than before. A filesystem that reports no
|
|
6
|
+
* identity (a zero device or id) cannot show a change, so none is claimed for it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function fileIdentityChanged(before: FileIdentity, after: FileIdentity): boolean;
|
|
9
|
+
/** The identity as text, for keys and records. */
|
|
10
|
+
export declare function fileIdentityKey(identity: FileIdentity): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function sameFileIdentity(left, right) {
|
|
2
|
+
return left.dev === right.dev && left.ino === right.ino;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Whether a path now names a different file than before. A filesystem that reports no
|
|
6
|
+
* identity (a zero device or id) cannot show a change, so none is claimed for it.
|
|
7
|
+
*/
|
|
8
|
+
export function fileIdentityChanged(before, after) {
|
|
9
|
+
const known = before.dev !== 0n && before.ino !== 0n && after.dev !== 0n && after.ino !== 0n;
|
|
10
|
+
return known && !sameFileIdentity(before, after);
|
|
11
|
+
}
|
|
12
|
+
/** The identity as text, for keys and records. */
|
|
13
|
+
export function fileIdentityKey(identity) {
|
|
14
|
+
return `${identity.dev}:${identity.ino}`;
|
|
15
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ReplaceFileOptions {
|
|
2
|
+
readonly deadlineMs?: number;
|
|
3
|
+
/** Test support: the rename to retry. */
|
|
4
|
+
readonly rename?: (from: string, to: string) => Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
/** Renames `temporaryPath` over `targetPath`, waiting out a reader that holds the target open. */
|
|
7
|
+
export declare function replaceFile(temporaryPath: string, targetPath: string, options?: ReplaceFileOptions): Promise<void>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { monotonicNowMs } from "../time/monotonic.js";
|
|
3
|
+
// Windows refuses to rename over a file any other handle has open (EPERM,
|
|
4
|
+
// EBUSY, or EACCES), even one opened to share delete, which is how Node opens
|
|
5
|
+
// every file. A receipt that agents and Forge poll is open for a moment many
|
|
6
|
+
// times a second, and an antivirus scan can hold it longer; fixed-interval
|
|
7
|
+
// retries can also fall into step with a poller of the same period. Replacing
|
|
8
|
+
// it therefore retries with growing, jittered delays until a deadline, so a
|
|
9
|
+
// reader can delay a replace but never fail it.
|
|
10
|
+
const replaceRetryCodes = new Set(["EACCES", "EBUSY", "EPERM"]);
|
|
11
|
+
const defaultReplaceDeadlineMs = 15_000;
|
|
12
|
+
const firstRetryDelayMs = 5;
|
|
13
|
+
const maximumRetryDelayMs = 250;
|
|
14
|
+
/** Renames `temporaryPath` over `targetPath`, waiting out a reader that holds the target open. */
|
|
15
|
+
export async function replaceFile(temporaryPath, targetPath, options = {}) {
|
|
16
|
+
const rename = options.rename ?? fs.rename;
|
|
17
|
+
const deadline = monotonicNowMs() + (options.deadlineMs ?? defaultReplaceDeadlineMs);
|
|
18
|
+
for (let attempt = 0;; attempt += 1) {
|
|
19
|
+
try {
|
|
20
|
+
await rename(temporaryPath, targetPath);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
const code = error?.code;
|
|
25
|
+
const remainingMs = deadline - monotonicNowMs();
|
|
26
|
+
if (!code || !replaceRetryCodes.has(code) || remainingMs <= 0)
|
|
27
|
+
throw error;
|
|
28
|
+
const ceilingMs = Math.min(maximumRetryDelayMs, firstRetryDelayMs * 2 ** Math.min(attempt, 6));
|
|
29
|
+
const delayMs = Math.min(remainingMs, ceilingMs / 2 + Math.random() * ceilingMs / 2);
|
|
30
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import type { HostProcessSupervisorMetadata } from "./host-process-supervisor.js";
|
|
1
|
+
import type { HostProcessSupervisorMetadata, WindowsSupervisorJobGone } from "./host-process-supervisor.js";
|
|
2
|
+
export { waitForWindowsSupervisorJobGone, type WindowsSupervisorJobGone } from "./host-process-supervisor.js";
|
|
2
3
|
export type HostProcessRecoveryOutcome = "absent" | "terminated" | "pid_reused" | "unverifiable";
|
|
3
4
|
export interface HostProcessRecovery {
|
|
4
5
|
recover(metadata: HostProcessSupervisorMetadata): Promise<HostProcessRecoveryOutcome>;
|
|
5
6
|
}
|
|
6
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Exact, birth-marker-fenced recovery for a process tree left by an old bridge.
|
|
9
|
+
*
|
|
10
|
+
* On Windows the recorded root is the job supervisor, which holds the only handle to a
|
|
11
|
+
* kill-on-close Job Object holding the whole tree. The root's exit only starts that job's
|
|
12
|
+
* teardown: Windows reports a process gone once its exit code is set, before its handles
|
|
13
|
+
* are closed, and the members are stopped after that. So a Windows tree is reported gone
|
|
14
|
+
* only once its Job Object no longer exists, which is when no member is left.
|
|
15
|
+
*/
|
|
7
16
|
export declare class ExactHostProcessRecovery implements HostProcessRecovery {
|
|
8
17
|
private readonly platform;
|
|
9
18
|
private readonly graceMs;
|
|
10
|
-
|
|
19
|
+
private readonly windowsJobGone;
|
|
20
|
+
constructor(platform?: NodeJS.Platform, graceMs?: number, windowsJobGone?: WindowsSupervisorJobGone);
|
|
11
21
|
recover(metadata: HostProcessSupervisorMetadata): Promise<HostProcessRecoveryOutcome>;
|
|
22
|
+
private stopRoot;
|
|
12
23
|
}
|
|
@@ -1,14 +1,34 @@
|
|
|
1
|
-
import { captureHostProcessIdentity } from "./host-process-supervisor.js";
|
|
1
|
+
import { captureHostProcessIdentity, waitForWindowsSupervisorJobGone } from "./host-process-supervisor.js";
|
|
2
2
|
import { monotonicNowMs } from "../time/monotonic.js";
|
|
3
|
-
|
|
3
|
+
export { waitForWindowsSupervisorJobGone } from "./host-process-supervisor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Exact, birth-marker-fenced recovery for a process tree left by an old bridge.
|
|
6
|
+
*
|
|
7
|
+
* On Windows the recorded root is the job supervisor, which holds the only handle to a
|
|
8
|
+
* kill-on-close Job Object holding the whole tree. The root's exit only starts that job's
|
|
9
|
+
* teardown: Windows reports a process gone once its exit code is set, before its handles
|
|
10
|
+
* are closed, and the members are stopped after that. So a Windows tree is reported gone
|
|
11
|
+
* only once its Job Object no longer exists, which is when no member is left.
|
|
12
|
+
*/
|
|
4
13
|
export class ExactHostProcessRecovery {
|
|
5
14
|
platform;
|
|
6
15
|
graceMs;
|
|
7
|
-
|
|
16
|
+
windowsJobGone;
|
|
17
|
+
constructor(platform = process.platform, graceMs = 2_000, windowsJobGone = waitForWindowsSupervisorJobGone) {
|
|
8
18
|
this.platform = platform;
|
|
9
19
|
this.graceMs = graceMs;
|
|
20
|
+
this.windowsJobGone = windowsJobGone;
|
|
10
21
|
}
|
|
11
22
|
async recover(metadata) {
|
|
23
|
+
const outcome = await this.stopRoot(metadata);
|
|
24
|
+
if (outcome === "unverifiable" || this.platform !== "win32" || metadata.strategy !== "windows_job_object")
|
|
25
|
+
return outcome;
|
|
26
|
+
if (!await this.windowsJobGone(metadata.supervisorId, this.graceMs)) {
|
|
27
|
+
throw new Error(`host_process_recovery_degraded: the Job Object of supervisor ${metadata.supervisorId} still holds processes after its root stopped.`);
|
|
28
|
+
}
|
|
29
|
+
return outcome;
|
|
30
|
+
}
|
|
31
|
+
async stopRoot(metadata) {
|
|
12
32
|
if (!processExists(metadata.rootPid))
|
|
13
33
|
return "absent";
|
|
14
34
|
if (!metadata.rootIdentity)
|
|
@@ -56,5 +56,17 @@ export declare function persistHostProcessSupervisorMetadata(launch: HostProcess
|
|
|
56
56
|
* at an unrelated process.
|
|
57
57
|
*/
|
|
58
58
|
export declare function captureHostProcessIdentity(pid: number, platform?: NodeJS.Platform): string | null;
|
|
59
|
-
export declare function terminateHostProcessTree(child: ChildProcess, launch: HostProcessSupervisedLaunch | null, graceMs?: number): Promise<void>;
|
|
59
|
+
export declare function terminateHostProcessTree(child: ChildProcess, launch: HostProcessSupervisedLaunch | null, graceMs?: number, windowsJobGone?: WindowsSupervisorJobGone): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Resolves true once a Windows job supervisor's Job Object no longer exists, false when it
|
|
62
|
+
* still does at the timeout or cannot be checked.
|
|
63
|
+
*/
|
|
64
|
+
export type WindowsSupervisorJobGone = (supervisorId: string, timeoutMs: number) => Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Polls for the job supervisor's named Job Object (runtime/windows-job-supervisor.ps1 names
|
|
67
|
+
* it Local\Forge-<supervisorId>). A job object exists while any handle or member process
|
|
68
|
+
* holds it, and the supervisor's handle closed with it, so its absence means no member is
|
|
69
|
+
* left. Any answer but "not found" (an unreadable job, a failed check) is not proof.
|
|
70
|
+
*/
|
|
71
|
+
export declare const waitForWindowsSupervisorJobGone: WindowsSupervisorJobGone;
|
|
60
72
|
export declare function windowsPowerShellPath(): string;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { promisify } from "node:util";
|
|
6
7
|
import { monotonicNowMs } from "../time/monotonic.js";
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
7
9
|
const windowsJobSupervisorPath = fileURLToPath(new URL("../../../runtime/windows-job-supervisor.ps1", import.meta.url));
|
|
8
10
|
export function resolveHostProcessSupervisedLaunch(request, resolvedCommand, resolvedArgs, platform = process.platform) {
|
|
9
11
|
const env = request.env;
|
|
@@ -154,7 +156,7 @@ export function captureHostProcessIdentity(pid, platform = process.platform) {
|
|
|
154
156
|
return null;
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
|
-
export async function terminateHostProcessTree(child, launch, graceMs = 2_000) {
|
|
159
|
+
export async function terminateHostProcessTree(child, launch, graceMs = 2_000, windowsJobGone = waitForWindowsSupervisorJobGone) {
|
|
158
160
|
if (!launch) {
|
|
159
161
|
await terminateUnsupervisedProcessTree(child, graceMs);
|
|
160
162
|
return;
|
|
@@ -162,22 +164,19 @@ export async function terminateHostProcessTree(child, launch, graceMs = 2_000) {
|
|
|
162
164
|
if (launch.strategy === "windows_job_object") {
|
|
163
165
|
const rootPid = child.pid ?? 0;
|
|
164
166
|
const metadata = readSupervisorMetadata(launch.metadataPath);
|
|
165
|
-
const rootIdentity = metadata?.rootPid === rootPid
|
|
166
|
-
? metadata.rootIdentity ?? null
|
|
167
|
-
: captureHostProcessIdentity(rootPid, "win32");
|
|
168
167
|
try {
|
|
169
168
|
child.kill("SIGTERM");
|
|
170
169
|
}
|
|
171
170
|
catch {
|
|
172
171
|
// Closing the launcher is best effort when the Job Object already settled.
|
|
173
172
|
}
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
// The root is this process's own child: its exit is observed through the handle
|
|
174
|
+
// Node holds, not by polling its identity with a PowerShell launch per check.
|
|
175
|
+
if (!await waitForChildExit(child, graceMs)) {
|
|
176
176
|
forceWindowsProcessTree(rootPid);
|
|
177
|
-
await
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
throw new Error("host_process_supervisor_termination_failed: supervised Windows root did not stop.");
|
|
177
|
+
if (!await waitForChildExit(child, graceMs)) {
|
|
178
|
+
throw new Error("host_process_supervisor_termination_failed: supervised Windows root did not stop.");
|
|
179
|
+
}
|
|
181
180
|
}
|
|
182
181
|
const providerPid = metadata?.providerPid ?? 0;
|
|
183
182
|
const providerIdentity = metadata?.providerIdentity ?? null;
|
|
@@ -188,6 +187,12 @@ export async function terminateHostProcessTree(child, launch, graceMs = 2_000) {
|
|
|
188
187
|
if (exactProcessExists(providerPid, providerIdentity, "win32")) {
|
|
189
188
|
throw new Error("host_process_supervisor_termination_failed: supervised Windows provider tree did not stop.");
|
|
190
189
|
}
|
|
190
|
+
// The root and the provider have exited; the rest of the tree (a descendant that left
|
|
191
|
+
// the provider's process tree, say) is gone only with the Job Object, which outlives
|
|
192
|
+
// its members by no more than a moment unless something still holds it.
|
|
193
|
+
if (!await windowsJobGone(launch.supervisorId, graceMs)) {
|
|
194
|
+
throw new Error(`host_process_supervisor_termination_failed: the Job Object of supervisor ${launch.supervisorId} still holds processes after its root and provider stopped.`);
|
|
195
|
+
}
|
|
191
196
|
return;
|
|
192
197
|
}
|
|
193
198
|
const processGroupId = child.pid;
|
|
@@ -218,10 +223,13 @@ async function terminateUnsupervisedProcessTree(child, graceMs) {
|
|
|
218
223
|
// root has already exited. Never target a potentially reused Windows PID.
|
|
219
224
|
if (child.exitCode !== null || child.signalCode !== null)
|
|
220
225
|
return;
|
|
221
|
-
|
|
226
|
+
// Until this child reports its exit, Node still holds its process handle, so
|
|
227
|
+
// its PID cannot name another process. Stop the tree now, rather than after a
|
|
228
|
+
// PowerShell launch to read its identity, during which the provider runs on
|
|
229
|
+
// past the stop (a success ceiling, a cancellation), and observe the exit
|
|
230
|
+
// through that same handle.
|
|
222
231
|
forceWindowsProcessTree(rootPid);
|
|
223
|
-
await
|
|
224
|
-
if (exactProcessExists(rootPid, rootIdentity, "win32")) {
|
|
232
|
+
if (!await waitForChildExit(child, graceMs)) {
|
|
225
233
|
throw new Error("host_process_supervisor_termination_failed: unsupervised Windows provider tree did not stop.");
|
|
226
234
|
}
|
|
227
235
|
return;
|
|
@@ -250,6 +258,34 @@ function assertMetadataPath(logDirectory, metadataPath) {
|
|
|
250
258
|
throw new Error("host_process_supervisor_invalid: metadata path must be inside FORGE_LOG_DIR.");
|
|
251
259
|
}
|
|
252
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Polls for the job supervisor's named Job Object (runtime/windows-job-supervisor.ps1 names
|
|
263
|
+
* it Local\Forge-<supervisorId>). A job object exists while any handle or member process
|
|
264
|
+
* holds it, and the supervisor's handle closed with it, so its absence means no member is
|
|
265
|
+
* left. Any answer but "not found" (an unreadable job, a failed check) is not proof.
|
|
266
|
+
*/
|
|
267
|
+
export const waitForWindowsSupervisorJobGone = async (supervisorId, timeoutMs) => {
|
|
268
|
+
if (!/^[A-Za-z0-9._-]{1,200}$/u.test(supervisorId))
|
|
269
|
+
return false;
|
|
270
|
+
const script = [
|
|
271
|
+
"$ErrorActionPreference = 'Stop'",
|
|
272
|
+
"Add-Type -Namespace ForgeRecovery -Name Job -MemberDefinition '[DllImport(\"kernel32.dll\", SetLastError = true, CharSet = CharSet.Unicode)] public static extern IntPtr OpenJobObject(uint access, bool inherit, string name); [DllImport(\"kernel32.dll\")] public static extern bool CloseHandle(IntPtr handle);'",
|
|
273
|
+
`$deadline = [DateTime]::UtcNow.AddMilliseconds(${Math.max(0, Math.round(timeoutMs))})`,
|
|
274
|
+
"$result = 'alive'",
|
|
275
|
+
// JOB_OBJECT_QUERY (4); ERROR_FILE_NOT_FOUND (2) is the only answer that proves the job gone.
|
|
276
|
+
"while ($true) { "
|
|
277
|
+
+ `$handle = [ForgeRecovery.Job]::OpenJobObject(4, $false, 'Local\\Forge-${supervisorId}'); `
|
|
278
|
+
+ "if ($handle -eq [IntPtr]::Zero) { $code = [Runtime.InteropServices.Marshal]::GetLastWin32Error(); "
|
|
279
|
+
+ "if ($code -eq 2) { $result = 'gone' } else { $result = \"error:$code\" }; break }; "
|
|
280
|
+
+ "[ForgeRecovery.Job]::CloseHandle($handle) | Out-Null; "
|
|
281
|
+
+ "if ([DateTime]::UtcNow -ge $deadline) { break }; Start-Sleep -Milliseconds 25 }",
|
|
282
|
+
"Write-Output $result",
|
|
283
|
+
].join("; ");
|
|
284
|
+
const { stdout } = await execFileAsync(windowsPowerShellPath(), [
|
|
285
|
+
"-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script,
|
|
286
|
+
], { encoding: "utf8", windowsHide: true, timeout: timeoutMs + 60_000 }).catch(() => ({ stdout: "" }));
|
|
287
|
+
return stdout.trim() === "gone";
|
|
288
|
+
};
|
|
253
289
|
export function windowsPowerShellPath() {
|
|
254
290
|
const systemRoot = process.env.SystemRoot?.trim() || "C:\\Windows";
|
|
255
291
|
const candidate = path.win32.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
@@ -307,6 +343,22 @@ function processExists(pid) {
|
|
|
307
343
|
return error.code === "EPERM";
|
|
308
344
|
}
|
|
309
345
|
}
|
|
346
|
+
/** Whether this process's own child reports its exit within `timeoutMs`. */
|
|
347
|
+
async function waitForChildExit(child, timeoutMs) {
|
|
348
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
349
|
+
return true;
|
|
350
|
+
return await new Promise(resolve => {
|
|
351
|
+
const onExit = () => {
|
|
352
|
+
clearTimeout(timer);
|
|
353
|
+
resolve(true);
|
|
354
|
+
};
|
|
355
|
+
const timer = setTimeout(() => {
|
|
356
|
+
child.off("exit", onExit);
|
|
357
|
+
resolve(child.exitCode !== null || child.signalCode !== null);
|
|
358
|
+
}, timeoutMs);
|
|
359
|
+
child.once("exit", onExit);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
310
362
|
async function waitForExactProcessExit(pid, identity, timeoutMs, platform) {
|
|
311
363
|
const deadline = monotonicNowMs() + timeoutMs;
|
|
312
364
|
while (monotonicNowMs() < deadline && exactProcessExists(pid, identity, platform)) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bridgeChatProtocolVersion, normalizeBridgeChatCapability, unavailableBridgeChatCapability, } from "../bridge/bridge-chat.types.js";
|
|
2
|
+
import { isProviderUserConfigIsolated, userConfigIsolatedProviders } from "../session/provider-cli/provider-user-config-isolation.js";
|
|
2
3
|
const defaultBridgeChatMaxMessageBytes = 128 * 1024;
|
|
3
4
|
const defaultBridgeChatMaxContextRefs = 8;
|
|
4
5
|
export function supportsDraftImageAttachmentsFor(cliProviders) {
|
|
@@ -9,7 +10,14 @@ export function bridgeChatCapabilityFor(cliProviders, providerStatuses, baseCapa
|
|
|
9
10
|
if (base.protocolVersion !== bridgeChatProtocolVersion) {
|
|
10
11
|
return base;
|
|
11
12
|
}
|
|
12
|
-
const
|
|
13
|
+
const configuredProviders = chatProviderEntries(cliProviders, providerStatuses);
|
|
14
|
+
// Bridge Chat refuses a provider whose user configuration Forge can't keep out of the turn
|
|
15
|
+
// (cursor-agent, unknown CLIs), so it is never offered. The remaining providers decide
|
|
16
|
+
// availability: the server dispatches a turn only to a capability that is fully available.
|
|
17
|
+
const providers = configuredProviders.filter((provider) => isProviderUserConfigIsolated(provider.providerKind));
|
|
18
|
+
if (configuredProviders.length > 0 && providers.length === 0) {
|
|
19
|
+
return unavailableBridgeChatCapability(bridgeChatProtocolVersion, "no_isolated_cli_providers", `Bridge Chat runs only ${userConfigIsolatedProviders.join(" and ")}; Forge can't keep the host user's own configuration out of ${configuredProviders.map((provider) => provider.providerKind).join(", ")}.`);
|
|
20
|
+
}
|
|
13
21
|
const usableProviders = providers.filter((provider) => provider.status?.signedIn !== false);
|
|
14
22
|
if (usableProviders.length === 0) {
|
|
15
23
|
return unavailableBridgeChatCapability(bridgeChatProtocolVersion, providers.length === 0 ? "no_cli_providers" : "no_signed_in_cli_providers", providers.length === 0
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const forgeBridgeVersion = "0.1
|
|
1
|
+
export declare const forgeBridgeVersion = "0.2.1-dev.0fedbc5c9ef7";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const forgeBridgeVersion = "0.1
|
|
1
|
+
export const forgeBridgeVersion = "0.2.1-dev.0fedbc5c9ef7";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GitClient } from "../shared/git/git.js";
|
|
2
|
+
interface OrphanRelinkInput {
|
|
3
|
+
readonly repoPath: string;
|
|
4
|
+
/** The checkout's real path. */
|
|
5
|
+
readonly worktreePath: string;
|
|
6
|
+
readonly branchName: string;
|
|
7
|
+
readonly allowedRoot: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Reattaches a checkout that lost its `.git` link while Git still has its admin directory. That
|
|
11
|
+
* directory holds the checkout's index (staged changes, conflict stages), MERGE_HEAD and HEAD,
|
|
12
|
+
* none of which a WIP snapshot holds for an orphan; recreating the checkout would prune it. So
|
|
13
|
+
* when it is still there and on the lease branch, the link is rewritten instead, and tracked
|
|
14
|
+
* files missing from the checkout are put back from its index, as recreating it would put them
|
|
15
|
+
* back from the base. Returns false when there is no such directory or any step fails, with the
|
|
16
|
+
* `.git` link as it was, so recovery can fall back to recreating the checkout. Never throws.
|
|
17
|
+
*/
|
|
18
|
+
export declare function relinkOrphanedWorktree(git: GitClient, input: OrphanRelinkInput): Promise<boolean>;
|
|
19
|
+
export {};
|