@loucompanion/forge-bridge 0.1.3-dev.8687c5099dce → 0.1.3-dev.88e93f53db5b

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 (75) hide show
  1. package/README.md +18 -1
  2. package/dist/bridge/bridge.base.d.ts +2 -0
  3. package/dist/bridge/bridge.service.d.ts +25 -1
  4. package/dist/bridge/bridge.service.js +341 -74
  5. package/dist/bridge/bridge.types.d.ts +4 -0
  6. package/dist/cleanup/cleanup.service.d.ts +1 -0
  7. package/dist/cleanup/cleanup.service.js +70 -9
  8. package/dist/cli/cli.service.js +9 -4
  9. package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
  10. package/dist/runtime/aspnet-runtime-prebuild.js +340 -0
  11. package/dist/runtime/attempt-node-runtime-launcher.js +5 -1
  12. package/dist/runtime/attempt-process-supervisor.d.ts +11 -0
  13. package/dist/runtime/attempt-process-supervisor.js +36 -2
  14. package/dist/runtime/host-listener-inspector.d.ts +2 -0
  15. package/dist/runtime/host-listener-inspector.js +25 -0
  16. package/dist/runtime/host-runtime-lease.d.ts +66 -5
  17. package/dist/runtime/host-runtime-lease.js +714 -38
  18. package/dist/runtime/memory-capacity.d.ts +68 -0
  19. package/dist/runtime/memory-capacity.js +121 -0
  20. package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
  21. package/dist/runtime/node-host-runtime-adapter.js +24 -8
  22. package/dist/runtime/playwright-host-runtime-adapter.d.ts +1 -0
  23. package/dist/runtime/playwright-host-runtime-adapter.js +5 -0
  24. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  25. package/dist/runtime/workspace-resource-estimator.js +174 -0
  26. package/dist/sandbox/preflight.d.ts +31 -1
  27. package/dist/sandbox/preflight.js +237 -51
  28. package/dist/sandbox/repository-lock.js +4 -2
  29. package/dist/sandbox/sandbox.types.d.ts +7 -0
  30. package/dist/session/managed-attempt-tools.d.ts +7 -1
  31. package/dist/session/managed-attempt-tools.js +257 -13
  32. package/dist/session/managed-build-coordinator.d.ts +5 -0
  33. package/dist/session/managed-build-coordinator.js +105 -0
  34. package/dist/session/managed-build-receipt.d.ts +21 -0
  35. package/dist/session/managed-build-receipt.js +335 -0
  36. package/dist/session/phase-completion.artifacts.d.ts +17 -0
  37. package/dist/session/phase-completion.artifacts.js +224 -22
  38. package/dist/session/phase-completion.prompts.js +2 -2
  39. package/dist/session/phase-completion.runtime.js +10 -3
  40. package/dist/session/phase-completion.schemas.js +1 -1
  41. package/dist/session/phase-completion.validation.js +7 -3
  42. package/dist/session/provider-cli/ci-repair-readiness.d.ts +6 -0
  43. package/dist/session/provider-cli/ci-repair-readiness.js +12 -2
  44. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  45. package/dist/session/provider-cli/provider-cli.artifacts.js +37 -3
  46. package/dist/session/provider-cli/provider-cli.process.d.ts +7 -0
  47. package/dist/session/provider-cli/provider-cli.process.js +218 -17
  48. package/dist/session/provider-cli/provider-cli.prompts.js +17 -4
  49. package/dist/session/provider-cli/provider-cli.runtime.js +3 -1
  50. package/dist/session/provider-cli/provider-cli.service.d.ts +5 -2
  51. package/dist/session/provider-cli/provider-cli.service.js +83 -34
  52. package/dist/session/provider-cli/provider-output-state.js +61 -14
  53. package/dist/session/provider-cli/provider-usage.d.ts +7 -0
  54. package/dist/session/provider-cli/provider-usage.js +28 -5
  55. package/dist/session/session-redaction.js +16 -1
  56. package/dist/session/session.service.js +81 -9
  57. package/dist/session/session.types.d.ts +15 -0
  58. package/dist/session/session.types.js +3 -1
  59. package/dist/shared/format/format-bytes.d.ts +1 -0
  60. package/dist/shared/format/format-bytes.js +9 -0
  61. package/dist/shared/path/path.d.ts +1 -0
  62. package/dist/shared/path/path.js +18 -0
  63. package/dist/shared/process/host-process-supervisor.d.ts +2 -0
  64. package/dist/shared/process/host-process-supervisor.js +57 -9
  65. package/dist/shared/redaction/redaction.js +6 -1
  66. package/dist/version.d.ts +1 -1
  67. package/dist/version.js +1 -1
  68. package/dist/worktree/dependency-warmer.d.ts +18 -0
  69. package/dist/worktree/dependency-warmer.js +218 -8
  70. package/dist/worktree/index.d.ts +1 -1
  71. package/dist/worktree/worktree.service.d.ts +2 -0
  72. package/dist/worktree/worktree.service.js +158 -17
  73. package/dist/worktree/worktree.types.d.ts +2 -0
  74. package/package.json +3 -2
  75. package/runtime/windows-job-supervisor.ps1 +89 -1
@@ -90,7 +90,7 @@ export class AttemptProcessSupervisor {
90
90
  this.currentByName.set(name, record);
91
91
  const result = this.runner.run(childRequest, handlers, combinedSignal);
92
92
  record.result = result;
93
- void result.then(value => this.settleChild(record, "exited", value.exitCode), error => this.settleChild(record, "failed", undefined, error));
93
+ void result.then(value => this.settleChild(record, "exited", value.exitCode, undefined, value), error => this.settleChild(record, "failed", undefined, error));
94
94
  try {
95
95
  await this.persist();
96
96
  }
@@ -213,9 +213,32 @@ export class AttemptProcessSupervisor {
213
213
  ...(record.settledAt ? { settledAt: record.settledAt } : {}),
214
214
  ...(record.exitCode === undefined ? {} : { exitCode: record.exitCode }),
215
215
  ...(record.failure ? { failure: record.failure } : {}),
216
+ ...(record.peakMemoryBytes === undefined ? {} : { peakMemoryBytes: record.peakMemoryBytes }),
217
+ ...(record.memorySampleCount === undefined ? {} : { memorySampleCount: record.memorySampleCount }),
218
+ ...(record.memorySource ? { memorySource: record.memorySource } : {}),
219
+ ...(record.memoryObservedAt ? { memoryObservedAt: record.memoryObservedAt } : {}),
216
220
  })),
217
221
  };
218
222
  }
223
+ providerMemoryTelemetry() {
224
+ const observations = this.records
225
+ .filter(record => record.name === "provider"
226
+ && record.peakMemoryBytes !== undefined
227
+ && record.peakMemoryBytes > 0
228
+ && record.memorySampleCount !== undefined
229
+ && record.memorySampleCount > 0
230
+ && record.memorySource
231
+ && record.memoryObservedAt);
232
+ if (observations.length === 0)
233
+ return null;
234
+ const peak = observations.reduce((current, candidate) => (candidate.peakMemoryBytes ?? 0) > (current.peakMemoryBytes ?? 0) ? candidate : current);
235
+ return {
236
+ peakMemoryBytes: peak.peakMemoryBytes,
237
+ sampleCount: observations.reduce((total, candidate) => total + (candidate.memorySampleCount ?? 0), 0),
238
+ source: peak.memorySource,
239
+ observedAt: peak.memoryObservedAt,
240
+ };
241
+ }
219
242
  async observeChildReady(record) {
220
243
  const deadline = Date.now() + this.metadataReadyTimeoutMs;
221
244
  while (Date.now() <= deadline) {
@@ -236,11 +259,22 @@ export class AttemptProcessSupervisor {
236
259
  const detail = await childStartFailureDetail(record);
237
260
  throw new Error(`attempt_process_supervisor_start_timeout: child '${record.childId}' did not become supervised${detail ? `: ${detail}` : "."}`);
238
261
  }
239
- async settleChild(record, status, exitCode, failure) {
262
+ async settleChild(record, status, exitCode, failure, result) {
240
263
  record.status = status;
241
264
  record.settledAt = new Date().toISOString();
242
265
  record.exitCode = exitCode;
243
266
  record.failure = failure === undefined ? undefined : boundedFailure(failure);
267
+ if (result?.peakMemoryBytes !== undefined
268
+ && result.peakMemoryBytes > 0
269
+ && result.memorySampleCount !== undefined
270
+ && result.memorySampleCount > 0
271
+ && result.memorySource
272
+ && result.memoryObservedAt) {
273
+ record.peakMemoryBytes = result.peakMemoryBytes;
274
+ record.memorySampleCount = result.memorySampleCount;
275
+ record.memorySource = result.memorySource;
276
+ record.memoryObservedAt = result.memoryObservedAt;
277
+ }
244
278
  await this.persist().catch(error => {
245
279
  this.persistenceFailure ??= error;
246
280
  this.status = "degraded";
@@ -18,6 +18,8 @@ export declare class HostListenerInspector {
18
18
  inspect(child: AttemptProcessChildHandle, reservation: HostPortReservation, owner: HostPortLeaseOwner): Promise<HostListenerOwnership>;
19
19
  /** Returns loopback TCP ports opened by one exact supervised child process tree. */
20
20
  inspectOwnedLoopbackListeners(child: AttemptProcessChildHandle, owner: HostPortLeaseOwner): Promise<readonly number[]>;
21
+ /** Snapshots loopback TCP ports that predate a supervised child launch. */
22
+ inspectLoopbackListeners(): Promise<readonly number[]>;
21
23
  private inspectWindows;
22
24
  private inspectAllWindows;
23
25
  private inspectUnix;
@@ -35,6 +35,31 @@ export class HostListenerInspector {
35
35
  ? await this.inspectAllWindows(metadata.rootPid)
36
36
  : await this.inspectAllUnix(metadata.rootPid);
37
37
  }
38
+ /** Snapshots loopback TCP ports that predate a supervised child launch. */
39
+ async inspectLoopbackListeners() {
40
+ if (this.platform === "win32") {
41
+ const netstat = await this.commands.run("netstat.exe", ["-ano", "-p", "TCP"]);
42
+ if (netstat.exitCode !== 0)
43
+ throw commandError("netstat", netstat);
44
+ return uniqueSorted(parseWindowsLoopbackListeners(netstat.stdout).map(listener => listener.port));
45
+ }
46
+ const lsof = await this.commands.run("lsof", [
47
+ "-nP",
48
+ "-a",
49
+ "-iTCP@127.0.0.1",
50
+ "-sTCP:LISTEN",
51
+ "-Fpn",
52
+ ]);
53
+ if (lsof.exitCode === 0 || lsof.exitCode === 1) {
54
+ return uniqueSorted(parseLsofLoopbackListeners(lsof.stdout).map(listener => listener.port));
55
+ }
56
+ if (lsof.errorCode !== "ENOENT")
57
+ throw commandError("lsof", lsof);
58
+ const ss = await this.commands.run("ss", ["-H", "-ltnp"]);
59
+ if (ss.exitCode !== 0)
60
+ throw commandError("ss", ss);
61
+ return uniqueSorted(parseSsLoopbackListeners(ss.stdout).map(listener => listener.port));
62
+ }
38
63
  async inspectWindows(rootPid, port) {
39
64
  const netstat = await this.commands.run("netstat.exe", ["-ano", "-p", "TCP"]);
40
65
  if (netstat.exitCode !== 0) {
@@ -4,8 +4,10 @@ import { type RuntimeIsolationLease } from "./runtime-isolation-lease.js";
4
4
  import { type LoadedHostRuntimeContract } from "./host-runtime-contract.js";
5
5
  import { HostPortBroker } from "./host-port-broker.js";
6
6
  import { NodeHostRuntimeAdapter, type NodeRuntimeAdapterLaunch, type NodeRuntimeCommand, type NodeRuntimeCommandLauncher } from "./node-host-runtime-adapter.js";
7
+ import type { AttemptProcessTreeMemoryTelemetry } from "./attempt-process-supervisor.js";
7
8
  import { AttemptProcessSupervisorRegistry } from "./attempt-process-supervisor-registry.js";
8
9
  import { HostListenerInspector } from "./host-listener-inspector.js";
10
+ import { type MemoryAdmissionDiagnostics } from "./memory-capacity.js";
9
11
  import { PlaywrightHostRuntimeAdapter } from "./playwright-host-runtime-adapter.js";
10
12
  import { HostParallelPromotionStore } from "./host-runtime-promotion.js";
11
13
  import { type HostProcessRecovery } from "../shared/process/host-process-recovery.js";
@@ -15,6 +17,18 @@ export interface HostRuntimeLeaseStart {
15
17
  readonly runtimeContract: LoadedHostRuntimeContract;
16
18
  readonly executionClass: HostRuntimeExecutionClass;
17
19
  }
20
+ export interface HostRuntimeAdmissionCheckpoint {
21
+ readonly code: "host_runtime_serial_admission_waiting";
22
+ readonly message: string;
23
+ readonly expiresAt: string;
24
+ }
25
+ export type HostRuntimeAdmissionCheckpointHandler = (checkpoint: HostRuntimeAdmissionCheckpoint) => void | Promise<void>;
26
+ export interface HostRuntimeProjectCheckpoint {
27
+ readonly code: "host_runtime_build_started" | "host_runtime_build_cached" | "host_runtime_build_completed";
28
+ readonly message: string;
29
+ readonly data?: Readonly<Record<string, unknown>>;
30
+ }
31
+ export type HostRuntimeProjectCheckpointHandler = (checkpoint: HostRuntimeProjectCheckpoint) => void | Promise<void>;
18
32
  export type HostRuntimeExecutionClass = "analysis_only" | "managed_runtime";
19
33
  export type HostRuntimeSafetyClass = "host_serial_only" | "host_parallel_candidate" | "host_parallel_safe";
20
34
  export interface HostRuntimeProjectCapacitySnapshot {
@@ -35,6 +49,18 @@ export interface HostRuntimeCapacitySnapshot {
35
49
  readonly degradedAttempts: number;
36
50
  readonly exclusiveReservations: number;
37
51
  readonly sharedReservations: number;
52
+ readonly hardMaxAttempts: number;
53
+ readonly effectiveMaxAttempts: number;
54
+ readonly availableAttempts: number;
55
+ readonly totalMemoryBytes: number;
56
+ readonly availableMemoryBytes: number;
57
+ readonly hostReserveBytes: number;
58
+ readonly availableCpuMillis: number;
59
+ readonly availableWorkspaceBytes: number;
60
+ readonly activeReservationMemoryBytes: number;
61
+ readonly memoryAdmission: MemoryAdmissionDiagnostics;
62
+ readonly unavailableCode?: string | null;
63
+ readonly unavailableReason?: string | null;
38
64
  readonly projects: readonly HostRuntimeProjectCapacitySnapshot[];
39
65
  }
40
66
  export interface HostRuntimeReapOptions {
@@ -54,15 +80,23 @@ export interface HostNodeRuntimeLaunch<T> extends NodeRuntimeAdapterLaunch<T> {
54
80
  }
55
81
  export interface HostRuntimeLeaseRuntime {
56
82
  acquire(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
57
- start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal): Promise<HostRuntimeLeaseStart>;
58
- startConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal): Promise<HostRuntimeLeaseStart>;
83
+ start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal, onAdmissionCheckpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostRuntimeLeaseStart>;
84
+ startConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
59
85
  updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
60
86
  providerProcessRunner?(dispatchAttemptId: string, fencingToken: string): ProviderProcessRunner | null;
87
+ providerMemoryTelemetry?(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
61
88
  release(dispatchAttemptId: string, fencingToken: string): Promise<RuntimeIsolationLease | null>;
62
89
  invalidatePromotion?(repoId: string): Promise<void>;
90
+ hasForegroundDemand?(): boolean;
63
91
  reap?(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport>;
64
92
  snapshot?(): HostRuntimeCapacitySnapshot;
65
93
  }
94
+ export interface HostCapacityResourceSample {
95
+ readonly totalMemoryBytes: number;
96
+ readonly availableMemoryBytes: number;
97
+ readonly totalCpuMillis: number;
98
+ readonly availableWorkspaceBytes: number;
99
+ }
66
100
  export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime {
67
101
  private readonly stateRoot;
68
102
  private readonly processSupervisors;
@@ -71,6 +105,7 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
71
105
  private readonly promotionStore;
72
106
  private readonly playwrightAdapter;
73
107
  private readonly processRecovery;
108
+ private readonly capacityResourceSample?;
74
109
  private readonly active;
75
110
  private readonly pendingRenewals;
76
111
  private readonly admissions;
@@ -78,20 +113,42 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
78
113
  private readonly singletonWaiters;
79
114
  private readonly parallelProjectOwners;
80
115
  private readonly parallelProjectWaiters;
116
+ private readonly capacityReservations;
117
+ private readonly capacityWaiters;
118
+ private capacityWaiterScanCursor;
119
+ private readonly backgroundAdmissionWaiters;
81
120
  private readonly degraded;
82
121
  private readonly knownPromotions;
122
+ private workspaceAvailableBytes;
123
+ private ambientMemoryCommitmentBytes;
83
124
  private readonly portBroker;
84
125
  private readonly nodeAdapter;
85
- constructor(stateRoot: string, portBroker?: HostPortBroker, nodeAdapter?: NodeHostRuntimeAdapter, processSupervisors?: AttemptProcessSupervisorRegistry, processRunner?: ProviderProcessRunner, listenerInspector?: HostListenerInspector, promotionStore?: HostParallelPromotionStore, playwrightAdapter?: PlaywrightHostRuntimeAdapter, processRecovery?: HostProcessRecovery);
126
+ private readonly capacityConfiguration;
127
+ private readonly memoryAvailability;
128
+ constructor(stateRoot: string, portBroker?: HostPortBroker, nodeAdapter?: NodeHostRuntimeAdapter, processSupervisors?: AttemptProcessSupervisorRegistry, processRunner?: ProviderProcessRunner, listenerInspector?: HostListenerInspector, promotionStore?: HostParallelPromotionStore, playwrightAdapter?: PlaywrightHostRuntimeAdapter, processRecovery?: HostProcessRecovery, capacityResourceSample?: HostCapacityResourceSample | undefined);
86
129
  reap(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport>;
87
130
  snapshot(): HostRuntimeCapacitySnapshot;
131
+ hasForegroundDemand(): boolean;
88
132
  acquire(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
133
+ private reserveHostCapacity;
134
+ private reserveBackgroundAdmission;
135
+ private hostCapacityAvailable;
136
+ private hostCapacityImpossibleReason;
137
+ private hostResourceSnapshot;
138
+ private refreshWorkspaceCapacity;
139
+ private releaseHostCapacity;
140
+ private drainCapacityWaiters;
141
+ private capacityWaitersForScan;
142
+ private detachCapacityWaiter;
89
143
  private reserveSingletonKeys;
90
144
  private reserveParallelProject;
91
- start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal): Promise<HostRuntimeLeaseStart>;
145
+ private upgradeParallelProjectToSingleton;
146
+ start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal, onAdmissionCheckpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostRuntimeLeaseStart>;
92
147
  updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
93
- startConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal): Promise<HostRuntimeLeaseStart>;
148
+ startConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
94
149
  providerProcessRunner(dispatchAttemptId: string, fencingToken: string): ProviderProcessRunner | null;
150
+ private markCapacityReservationRunning;
151
+ providerMemoryTelemetry(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
95
152
  private promoteVerifiedRuntime;
96
153
  launchNodeRuntime<T>(dispatchAttemptId: string, fencingToken: string, portName: string, command: NodeRuntimeCommand, launcher: NodeRuntimeCommandLauncher<T>, signal?: AbortSignal): Promise<HostNodeRuntimeLaunch<T>>;
97
154
  release(dispatchAttemptId: string, fencingToken: string): Promise<RuntimeIsolationLease | null>;
@@ -118,6 +175,7 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
118
175
  private cancelAdmissionWaiters;
119
176
  private drainSingletonWaiters;
120
177
  private drainParallelProjectWaiters;
178
+ private drainBackgroundAdmissionWaiters;
121
179
  private refreshKnownPromotions;
122
180
  invalidatePromotion(repoId: string): Promise<void>;
123
181
  private drainAdmissionWaiters;
@@ -129,5 +187,8 @@ export declare class HostRuntimeLeaseCleanupError extends Error {
129
187
  export declare class HostRuntimeAdmissionExpiredError extends Error {
130
188
  constructor();
131
189
  }
190
+ export declare class HostRuntimeCapacityRequestImpossibleError extends Error {
191
+ constructor(reason: string);
192
+ }
132
193
  export declare function hostRuntimeEventResources(lease: RuntimeIsolationLease, runtimeContract?: LoadedHostRuntimeContract, executionClass?: HostRuntimeExecutionClass): Record<string, unknown>;
133
194
  export declare function hostRuntimeSingletonKeys(dispatch: RunOnceDispatchPacket): readonly string[];