@loucompanion/forge-bridge 0.1.4-dev.6b2148ecc60c → 0.1.4-dev.724427ea7be8

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.
Files changed (163) hide show
  1. package/README.md +87 -1
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +5 -2
  3. package/dist/bridge/bridge-chat-provider-command.js +29 -22
  4. package/dist/bridge/bridge-chat.types.d.ts +10 -0
  5. package/dist/bridge/bridge-chat.types.js +16 -1
  6. package/dist/bridge/bridge-state-file.d.ts +161 -0
  7. package/dist/bridge/bridge-state-file.js +376 -0
  8. package/dist/bridge/bridge-state-io.d.ts +11 -0
  9. package/dist/bridge/bridge-state-io.js +50 -0
  10. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  11. package/dist/bridge/bridge-state-lock.js +102 -0
  12. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  13. package/dist/bridge/bridge-state-unpublished.js +111 -0
  14. package/dist/bridge/bridge.service.d.ts +16 -12
  15. package/dist/bridge/bridge.service.js +131 -243
  16. package/dist/bridge/bridge.types.d.ts +5 -0
  17. package/dist/bridge/in-flight-registry.d.ts +62 -0
  18. package/dist/bridge/in-flight-registry.js +207 -0
  19. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  20. package/dist/bridge/readiness-result-outbox.js +20 -0
  21. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  22. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  23. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  24. package/dist/cleanup/cleanup-wip.js +66 -0
  25. package/dist/cleanup/cleanup.service.d.ts +11 -1
  26. package/dist/cleanup/cleanup.service.js +80 -62
  27. package/dist/cleanup/cleanup.types.d.ts +2 -0
  28. package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
  29. package/dist/cleanup/host-runtime-ledger.js +30 -9
  30. package/dist/cli/cli.help.js +56 -12
  31. package/dist/cli/cli.service.d.ts +3 -10
  32. package/dist/cli/cli.service.js +10 -171
  33. package/dist/cli/idle-status.d.ts +84 -0
  34. package/dist/cli/idle-status.js +181 -0
  35. package/dist/cli/local-config.d.ts +2 -0
  36. package/dist/cli/local-config.js +7 -1
  37. package/dist/cli/provider-cli-detection.d.ts +10 -0
  38. package/dist/cli/provider-cli-detection.js +160 -0
  39. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  40. package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
  41. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  42. package/dist/runtime/attempt-node-runtime-launcher.js +9 -0
  43. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  44. package/dist/runtime/attempt-process-supervisor.js +12 -6
  45. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  46. package/dist/runtime/docker-engine-probe.js +7 -0
  47. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  48. package/dist/runtime/dotnet-build-outputs.js +402 -0
  49. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  50. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  51. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  52. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  53. package/dist/runtime/host-load-governor.d.ts +2 -0
  54. package/dist/runtime/host-load-ledger-lock.js +6 -4
  55. package/dist/runtime/host-load-runtime-settings.js +4 -2
  56. package/dist/runtime/host-load-sampler.d.ts +8 -1
  57. package/dist/runtime/host-load-sampler.js +14 -7
  58. package/dist/runtime/host-runtime-contract.d.ts +12 -0
  59. package/dist/runtime/host-runtime-contract.js +29 -1
  60. package/dist/runtime/host-runtime-lease.d.ts +2 -1
  61. package/dist/runtime/host-runtime-lease.js +30 -153
  62. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  63. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  64. package/dist/runtime/managed-command-teardown.js +5 -16
  65. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  66. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  67. package/dist/runtime/runner-settings.d.ts +4 -0
  68. package/dist/runtime/runner-settings.js +22 -0
  69. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  70. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  71. package/dist/sandbox/host-capacity-broker.d.ts +3 -1
  72. package/dist/sandbox/host-capacity-broker.js +4 -2
  73. package/dist/sandbox/managed-branch.d.ts +13 -0
  74. package/dist/sandbox/managed-branch.js +90 -0
  75. package/dist/sandbox/provider-auth/codex.js +11 -11
  76. package/dist/sandbox/runtime.js +2 -6
  77. package/dist/session/architect-waits.d.ts +2 -0
  78. package/dist/session/architect-waits.js +138 -0
  79. package/dist/session/managed-attempt-tools.d.ts +0 -7
  80. package/dist/session/managed-attempt-tools.js +50 -82
  81. package/dist/session/managed-build-coordinator.d.ts +16 -0
  82. package/dist/session/managed-build-coordinator.js +10 -0
  83. package/dist/session/managed-build-receipt.d.ts +5 -0
  84. package/dist/session/managed-build-receipt.js +8 -3
  85. package/dist/session/phase-completion.artifacts.js +2 -1
  86. package/dist/session/phase-completion.d.ts +8 -0
  87. package/dist/session/phase-completion.js +1 -0
  88. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  89. package/dist/session/phase-completion.mcp-args.js +156 -0
  90. package/dist/session/phase-completion.runtime.d.ts +0 -8
  91. package/dist/session/phase-completion.runtime.js +43 -197
  92. package/dist/session/phase-completion.schemas.js +3 -11
  93. package/dist/session/phase-completion.validation.js +3 -1
  94. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  95. package/dist/session/pre-publication-native-postgres.js +111 -0
  96. package/dist/session/pre-publication-process.js +10 -10
  97. package/dist/session/pre-publication-step-execution.d.ts +2 -1
  98. package/dist/session/pre-publication-step-execution.js +6 -5
  99. package/dist/session/pre-publication-validation.d.ts +7 -3
  100. package/dist/session/pre-publication-validation.js +32 -30
  101. package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
  102. package/dist/session/provider-cli/claude-background-work.js +4 -3
  103. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  104. package/dist/session/provider-cli/host-build-lock.js +30 -0
  105. package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
  106. package/dist/session/provider-cli/pre-publication-repair.js +33 -0
  107. package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
  108. package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
  109. package/dist/session/provider-cli/provider-cli.process.js +4 -94
  110. package/dist/session/provider-cli/provider-cli.prompts.d.ts +3 -0
  111. package/dist/session/provider-cli/provider-cli.prompts.js +27 -27
  112. package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
  113. package/dist/session/provider-cli/provider-cli.runtime.js +23 -2
  114. package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
  115. package/dist/session/provider-cli/provider-cli.service.js +27 -43
  116. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  117. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  118. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  119. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  120. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  121. package/dist/session/qa-sidecar-validation.js +28 -0
  122. package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
  123. package/dist/session/sandbox-host-capacity-gate.js +34 -15
  124. package/dist/session/session-redaction.js +31 -181
  125. package/dist/session/session.service.d.ts +2 -0
  126. package/dist/session/session.service.js +69 -64
  127. package/dist/session/session.types.js +1 -1
  128. package/dist/session/sidecar-json-shape.d.ts +31 -0
  129. package/dist/session/sidecar-json-shape.js +217 -0
  130. package/dist/shared/fs/file-identity.d.ts +10 -0
  131. package/dist/shared/fs/file-identity.js +15 -0
  132. package/dist/shared/fs/replace-file.d.ts +7 -0
  133. package/dist/shared/fs/replace-file.js +33 -0
  134. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  135. package/dist/shared/process/host-process-recovery.js +23 -3
  136. package/dist/shared/process/host-process-supervisor.d.ts +13 -1
  137. package/dist/shared/process/host-process-supervisor.js +66 -14
  138. package/dist/shared/provider-capabilities.js +9 -1
  139. package/dist/version.d.ts +1 -1
  140. package/dist/version.js +1 -1
  141. package/dist/worktree/orphan-relink.d.ts +19 -0
  142. package/dist/worktree/orphan-relink.js +106 -0
  143. package/dist/worktree/wip-git.d.ts +33 -0
  144. package/dist/worktree/wip-git.js +122 -0
  145. package/dist/worktree/wip-refs.d.ts +62 -0
  146. package/dist/worktree/wip-refs.js +119 -0
  147. package/dist/worktree/wip-restore.d.ts +38 -0
  148. package/dist/worktree/wip-restore.js +190 -0
  149. package/dist/worktree/wip-snapshot.d.ts +50 -0
  150. package/dist/worktree/wip-snapshot.js +268 -0
  151. package/dist/worktree/worktree-inputs.d.ts +8 -0
  152. package/dist/worktree/worktree-inputs.js +134 -0
  153. package/dist/worktree/worktree-origin-sync.d.ts +34 -0
  154. package/dist/worktree/worktree-origin-sync.js +127 -0
  155. package/dist/worktree/worktree-wip-events.d.ts +18 -0
  156. package/dist/worktree/worktree-wip-events.js +98 -0
  157. package/dist/worktree/worktree-wip.d.ts +50 -0
  158. package/dist/worktree/worktree-wip.js +185 -0
  159. package/dist/worktree/worktree.base.d.ts +7 -1
  160. package/dist/worktree/worktree.service.d.ts +27 -5
  161. package/dist/worktree/worktree.service.js +110 -181
  162. package/dist/worktree/worktree.types.d.ts +31 -0
  163. package/package.json +1 -1
@@ -0,0 +1,111 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { errorCode, isProcessAlive, withFsRetry, writeJsonFileAtomically } from "./bridge-state-io.js";
4
+ // The id is a single safe path component (the publisher's random UUID). A marker's id is
5
+ // always taken from its own file name in the state directory, never from its contents, and
6
+ // the contents must name the same id: no path is ever built from what a file says.
7
+ const publisherIdPattern = /^[A-Za-z0-9-]{1,64}$/u;
8
+ // Allows for a writer clock slightly ahead of the reader's.
9
+ const futureToleranceMs = 60_000;
10
+ export function unpublishedMarkerPathFor(statePath, publisherId) {
11
+ if (!publisherIdPattern.test(publisherId))
12
+ throw new Error(`Invalid publisher id for an unpublished-state marker: ${JSON.stringify(publisherId)}.`);
13
+ return path.join(path.dirname(statePath), markerFileName(statePath, publisherId));
14
+ }
15
+ export async function writeUnpublishedMarker(statePath, marker) {
16
+ await writeJsonFileAtomically(unpublishedMarkerPathFor(statePath, marker.publisherId), marker);
17
+ }
18
+ export async function removeUnpublishedMarker(statePath, publisherId) {
19
+ await withFsRetry(() => fs.rm(unpublishedMarkerPathFor(statePath, publisherId), { force: true }));
20
+ }
21
+ /** Every marker beside the state file. Throws on one it can't trust: idle can't be confirmed then. */
22
+ export async function readUnpublishedMarkers(statePath, now = Date.now()) {
23
+ const listed = await listUnpublishedMarkers(statePath, now);
24
+ const untrusted = listed.find(entry => entry.marker === null);
25
+ if (untrusted)
26
+ throw new Error(`The unpublished-state marker ${untrusted.fileName} is ${untrusted.problem}.`);
27
+ return listed.map(entry => entry.marker);
28
+ }
29
+ /** Removes valid markers whose process has exited: they can no longer hold anything back. */
30
+ export async function removeExitedUnpublishedMarkers(statePath, pidAlive = isProcessAlive) {
31
+ const directory = path.resolve(path.dirname(statePath));
32
+ const listed = await listUnpublishedMarkers(statePath, Date.now()).catch(() => []);
33
+ for (const { fileName, marker } of listed) {
34
+ if (!marker || pidAlive(marker.pid))
35
+ continue;
36
+ // Only the exact file listed, directly inside the state directory.
37
+ const target = path.resolve(directory, fileName);
38
+ if (path.dirname(target) !== directory || path.basename(target) !== fileName)
39
+ continue;
40
+ await withFsRetry(() => fs.rm(target, { force: true })).catch(() => undefined);
41
+ }
42
+ }
43
+ async function listUnpublishedMarkers(statePath, now) {
44
+ const directory = path.dirname(statePath);
45
+ const prefix = `${path.basename(statePath)}.unpublished.`;
46
+ let names;
47
+ try {
48
+ names = await withFsRetry(() => fs.readdir(directory));
49
+ }
50
+ catch (error) {
51
+ if (errorCode(error) === "ENOENT")
52
+ return [];
53
+ throw error;
54
+ }
55
+ const listed = [];
56
+ // Temp files of an atomic write end in ".tmp" and are not markers yet.
57
+ for (const fileName of names.filter(name => name.startsWith(prefix) && name.endsWith(".json"))) {
58
+ const publisherId = fileName.slice(prefix.length, -".json".length);
59
+ if (!publisherIdPattern.test(publisherId)) {
60
+ listed.push({ fileName, marker: null, problem: "not named for a valid publisher id" });
61
+ continue;
62
+ }
63
+ let text;
64
+ try {
65
+ text = await withFsRetry(() => fs.readFile(path.join(directory, fileName), "utf8"));
66
+ }
67
+ catch (error) {
68
+ // Removed between the listing and the read: its publisher has published again.
69
+ if (errorCode(error) === "ENOENT")
70
+ continue;
71
+ throw error;
72
+ }
73
+ const marker = parseMarker(text, publisherId, now);
74
+ listed.push(marker ? { fileName, marker, problem: null } : { fileName, marker: null, problem: "malformed" });
75
+ }
76
+ return listed;
77
+ }
78
+ function markerFileName(statePath, publisherId) {
79
+ return `${path.basename(statePath)}.unpublished.${publisherId}.json`;
80
+ }
81
+ // Every field the evaluator relies on, with its type and range: a marker it could not use to
82
+ // hold readers back (a NaN timestamp or interval) is malformed, which reads as unknown.
83
+ const markerChecks = [
84
+ marker => marker.schemaVersion === 1,
85
+ marker => Number.isInteger(marker.pid) && marker.pid > 0,
86
+ (marker, publisherId) => marker.publisherId === publisherId,
87
+ marker => typeof marker.runnerInstanceId === "string",
88
+ (marker, _publisherId, now) => isPastTimestamp(marker.since, now),
89
+ (marker, _publisherId, now) => isPastTimestamp(marker.updatedAt, now),
90
+ marker => typeof marker.publishIntervalMs === "number" && Number.isFinite(marker.publishIntervalMs) && marker.publishIntervalMs > 0,
91
+ marker => typeof marker.error === "string",
92
+ ];
93
+ function parseMarker(text, publisherId, now) {
94
+ let value;
95
+ try {
96
+ value = JSON.parse(text);
97
+ }
98
+ catch {
99
+ return null;
100
+ }
101
+ if (!value || typeof value !== "object" || Array.isArray(value))
102
+ return null;
103
+ const marker = value;
104
+ return markerChecks.every(check => check(marker, publisherId, now)) ? marker : null;
105
+ }
106
+ function isPastTimestamp(value, now) {
107
+ if (typeof value !== "string")
108
+ return false;
109
+ const at = Date.parse(value);
110
+ return Number.isFinite(at) && at <= now + futureToleranceMs;
111
+ }
@@ -2,9 +2,8 @@ import type { SessionService } from "../session/session.base.js";
2
2
  import { type ProviderProcessRunner } from "../session/provider-cli/provider-cli.service.js";
3
3
  import { type RunnerSettingsReport } from "../runtime/runner-settings.js";
4
4
  import { DockerEngineProbe, type DockerEngineCapabilitySnapshot } from "../runtime/docker-engine-probe.js";
5
- import { type DispatchSandboxResourceRequest, type RunOnceDispatchPacket, type RunOnceResultPacket } from "../session/session.types.js";
5
+ import { type RunOnceDispatchPacket, type RunOnceResultPacket } from "../session/session.types.js";
6
6
  import { DockerPreflight } from "../sandbox/preflight.js";
7
- import type { SandboxPreflightResult } from "../sandbox/sandbox.types.js";
8
7
  import { type SandboxRuntime } from "../sandbox/runtime.js";
9
8
  import type { BridgeConnection, BridgeConnectionFactory, BridgeRevokedNotice, BridgeService } from "./bridge.base.js";
10
9
  import { type RunnerHostCapabilityProbe } from "./runner-host-capabilities.js";
@@ -12,11 +11,11 @@ import { type HostLoadSource } from "../runtime/host-load-sampler.js";
12
11
  import type { BridgeCancelHandler, BridgeChatTurnHandler, BridgeDispatchHandler, BridgeLeaseUpdateRequest, BridgeReapRequest, BridgeServiceConfig } from "./bridge.types.js";
13
12
  import { type ReadinessResultOutbox } from "./readiness-result-outbox.js";
14
13
  import { type DispatchResultOutbox } from "./dispatch-result-outbox.js";
14
+ import { BridgeInFlightRegistry } from "./in-flight-registry.js";
15
+ import { canReserveSandboxResources, resolveDynamicSandboxResources, resolveSandboxResourcesFromRepo, sandboxCapacityFailureMessage, sandboxMemoryCommitmentCapacity, type ResolvedSandboxResourceProfile, type SandboxResourceVector } from "./sandbox-resource-accounting.js";
15
16
  export type SandboxResourceResolver = (dispatch: RunOnceDispatchPacket) => Promise<ResolvedSandboxResourceProfile>;
16
- export interface ResolvedSandboxResourceProfile {
17
- readonly resources: DispatchSandboxResourceRequest;
18
- readonly sandboxConfigCommitSha: string;
19
- }
17
+ export { canReserveSandboxResources, resolveDynamicSandboxResources, resolveSandboxResourcesFromRepo, sandboxCapacityFailureMessage, sandboxMemoryCommitmentCapacity, };
18
+ export type { ResolvedSandboxResourceProfile, SandboxResourceVector };
20
19
  /**
21
20
  * Protocol-v2 events are acknowledged one at a time before runOnce returns.
22
21
  * Sending the complete transcript again in DispatchResult made long QA and CI
@@ -48,6 +47,8 @@ export declare class ForgeBridgeService implements BridgeService {
48
47
  private readonly activeSessions;
49
48
  private readonly reservations;
50
49
  private readonly activeReadinessProbes;
50
+ /** Everything a bridge restart would interrupt, published for `forge-bridge status --idle`. */
51
+ readonly inFlight: BridgeInFlightRegistry;
51
52
  private readonly readinessResultOutbox;
52
53
  private readinessResultFlush;
53
54
  private readonly dispatchResultOutbox;
@@ -65,6 +66,9 @@ export declare class ForgeBridgeService implements BridgeService {
65
66
  private dockerAvailable;
66
67
  private appliedSettingsDocument;
67
68
  private localYield;
69
+ /** The yield Forge last acknowledged in a report (Hello, Heartbeat, SettingsApplied); published as `yielding`. */
70
+ private forgeAckedYield;
71
+ private publishState;
68
72
  private effectiveSettings;
69
73
  private settingsReport;
70
74
  /** Applies run one at a time; offers wait for every apply queued before them. */
@@ -80,6 +84,7 @@ export declare class ForgeBridgeService implements BridgeService {
80
84
  private recoveredHostAttemptsForHello;
81
85
  private registerConnection;
82
86
  run(signal?: AbortSignal): Promise<void>;
87
+ private startStatePublisher;
83
88
  /** The reason Forge gave when it removed this runner, or null while it is paired. */
84
89
  get revoked(): string | null;
85
90
  /**
@@ -128,6 +133,7 @@ export declare class ForgeBridgeService implements BridgeService {
128
133
  * force (`apply_failed`); their previous values stay in force.
129
134
  */
130
135
  private putSettingsInForce;
136
+ private ackYield;
131
137
  /** A failed acknowledgement is not retried here: the next heartbeat carries the same report. */
132
138
  private sendSettingsApplied;
133
139
  stop(): Promise<void>;
@@ -142,6 +148,10 @@ export declare class ForgeBridgeService implements BridgeService {
142
148
  private requiredChatCapabilityFailure;
143
149
  private bridgeChatCapability;
144
150
  private handleDispatch;
151
+ private registerActiveDispatch;
152
+ private dispatchEventSink;
153
+ /** Runs the dispatch on the host or in its Docker sandbox, logging start and end with its ids. */
154
+ private runDispatchOnce;
145
155
  private reservedDispatchHandoffIsCurrent;
146
156
  private releaseReservedDispatchHandoff;
147
157
  private releaseActiveSessionAndRefreshCapacity;
@@ -246,9 +256,3 @@ export declare function canReapManagedSandboxes(preflight: {
246
256
  readonly unavailableCode?: string | null;
247
257
  }): boolean;
248
258
  export declare function dockerEngineRequirementFailure(requiredCapabilities: readonly string[], executionMode: string | undefined, capability: DockerEngineCapabilitySnapshot | null): string | null;
249
- export type SandboxResourceVector = DispatchSandboxResourceRequest;
250
- export declare function canReserveSandboxResources(used: SandboxResourceVector, requested: SandboxResourceVector, capacity: SandboxResourceVector): boolean;
251
- export declare function sandboxMemoryCommitmentCapacity(preflight: Pick<SandboxPreflightResult, "totalMemoryBytes" | "availableMemoryBytes" | "hostReserveBytes">, activeMemoryBytes: number): number;
252
- export declare function sandboxCapacityFailureMessage(used: SandboxResourceVector, requested: SandboxResourceVector, capacity: SandboxResourceVector, preflight: SandboxPreflightResult | null, config: BridgeServiceConfig): string;
253
- export declare function resolveDynamicSandboxResources(requested: DispatchSandboxResourceRequest, serviceCount: number, networkMode: "offline" | "public_allowlist" | "open_public", baseRuntimeOverheadBytes?: number): DispatchSandboxResourceRequest;
254
- export declare function resolveSandboxResourcesFromRepo(dispatch: RunOnceDispatchPacket, baseRuntimeOverheadBytes?: number): Promise<ResolvedSandboxResourceProfile>;