@loucompanion/forge-bridge 0.1.3-dev.0b2f81d660c0 → 0.1.3-dev.0d26c10244e1

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 (148) hide show
  1. package/README.md +79 -0
  2. package/dist/bridge/bridge.base.d.ts +8 -1
  3. package/dist/bridge/bridge.service.d.ts +77 -3
  4. package/dist/bridge/bridge.service.js +1113 -34
  5. package/dist/bridge/bridge.types.d.ts +168 -1
  6. package/dist/cleanup/cleanup.service.d.ts +14 -2
  7. package/dist/cleanup/cleanup.service.js +469 -3
  8. package/dist/cleanup/cleanup.types.d.ts +10 -0
  9. package/dist/cleanup/index.d.ts +1 -1
  10. package/dist/cleanup/index.js +1 -1
  11. package/dist/cleanup/internals.d.ts +2 -2
  12. package/dist/cleanup/internals.js +1 -1
  13. package/dist/cli/cli.help.js +47 -1
  14. package/dist/cli/cli.service.d.ts +42 -2
  15. package/dist/cli/cli.service.js +357 -26
  16. package/dist/cli/local-config.d.ts +4 -0
  17. package/dist/cli/local-config.js +41 -1
  18. package/dist/runtime/aspnet-runtime-prebuild.d.ts +35 -0
  19. package/dist/runtime/aspnet-runtime-prebuild.js +168 -0
  20. package/dist/runtime/attempt-node-runtime-launcher.d.ts +17 -0
  21. package/dist/runtime/attempt-node-runtime-launcher.js +105 -0
  22. package/dist/runtime/attempt-process-supervisor-registry.d.ts +20 -0
  23. package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
  24. package/dist/runtime/attempt-process-supervisor.d.ts +86 -0
  25. package/dist/runtime/attempt-process-supervisor.js +350 -0
  26. package/dist/runtime/generated-output-reset.d.ts +10 -0
  27. package/dist/runtime/generated-output-reset.js +103 -0
  28. package/dist/runtime/host-listener-inspector.d.ts +46 -0
  29. package/dist/runtime/host-listener-inspector.js +349 -0
  30. package/dist/runtime/host-port-broker.d.ts +76 -0
  31. package/dist/runtime/host-port-broker.js +333 -0
  32. package/dist/runtime/host-runtime-contract.d.ts +47 -0
  33. package/dist/runtime/host-runtime-contract.js +700 -0
  34. package/dist/runtime/host-runtime-lease.d.ts +179 -0
  35. package/dist/runtime/host-runtime-lease.js +1990 -0
  36. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  37. package/dist/runtime/host-runtime-promotion.js +159 -0
  38. package/dist/runtime/node-host-runtime-adapter.d.ts +54 -0
  39. package/dist/runtime/node-host-runtime-adapter.js +284 -0
  40. package/dist/runtime/playwright-host-runtime-adapter.d.ts +20 -0
  41. package/dist/runtime/playwright-host-runtime-adapter.js +220 -0
  42. package/dist/runtime/runtime-isolation-lease.d.ts +67 -0
  43. package/dist/runtime/runtime-isolation-lease.js +158 -0
  44. package/dist/runtime/workspace-resource-estimator.d.ts +16 -0
  45. package/dist/runtime/workspace-resource-estimator.js +165 -0
  46. package/dist/sandbox/command-runner.d.ts +4 -0
  47. package/dist/sandbox/command-runner.js +47 -0
  48. package/dist/sandbox/contract.d.ts +5 -0
  49. package/dist/sandbox/contract.js +276 -0
  50. package/dist/sandbox/event-budget.d.ts +11 -0
  51. package/dist/sandbox/event-budget.js +27 -0
  52. package/dist/sandbox/image-policy.d.ts +35 -0
  53. package/dist/sandbox/image-policy.js +247 -0
  54. package/dist/sandbox/index.d.ts +5 -0
  55. package/dist/sandbox/index.js +5 -0
  56. package/dist/sandbox/lease-watchdog.d.ts +18 -0
  57. package/dist/sandbox/lease-watchdog.js +67 -0
  58. package/dist/sandbox/preflight.d.ts +55 -0
  59. package/dist/sandbox/preflight.js +343 -0
  60. package/dist/sandbox/process.d.ts +20 -0
  61. package/dist/sandbox/process.js +209 -0
  62. package/dist/sandbox/provider-auth/codex.d.ts +26 -0
  63. package/dist/sandbox/provider-auth/codex.js +212 -0
  64. package/dist/sandbox/repository-lock.d.ts +5 -0
  65. package/dist/sandbox/repository-lock.js +119 -0
  66. package/dist/sandbox/runtime.d.ts +297 -0
  67. package/dist/sandbox/runtime.js +2338 -0
  68. package/dist/sandbox/sandbox.types.d.ts +86 -0
  69. package/dist/sandbox/sandbox.types.js +1 -0
  70. package/dist/sandbox/smoke.d.ts +76 -0
  71. package/dist/sandbox/smoke.js +380 -0
  72. package/dist/sandbox/worker-supervisor.d.ts +13 -0
  73. package/dist/sandbox/worker-supervisor.js +36 -0
  74. package/dist/sandbox/worker.d.ts +1 -0
  75. package/dist/sandbox/worker.js +225 -0
  76. package/dist/sandbox/workspace.service.d.ts +13 -0
  77. package/dist/sandbox/workspace.service.js +72 -0
  78. package/dist/session/managed-attempt-tools.d.ts +18 -0
  79. package/dist/session/managed-attempt-tools.js +797 -0
  80. package/dist/session/managed-build-coordinator.d.ts +5 -0
  81. package/dist/session/managed-build-coordinator.js +105 -0
  82. package/dist/session/phase-completion.artifacts.js +21 -3
  83. package/dist/session/phase-completion.d.ts +11 -2
  84. package/dist/session/phase-completion.helpers.d.ts +5 -0
  85. package/dist/session/phase-completion.helpers.js +51 -10
  86. package/dist/session/phase-completion.js +12 -3
  87. package/dist/session/phase-completion.prompts.d.ts +3 -3
  88. package/dist/session/phase-completion.prompts.js +21 -6
  89. package/dist/session/phase-completion.runtime.d.ts +13 -1
  90. package/dist/session/phase-completion.runtime.js +187 -8
  91. package/dist/session/phase-completion.schemas.js +108 -3
  92. package/dist/session/phase-completion.validation.d.ts +4 -1
  93. package/dist/session/phase-completion.validation.js +150 -21
  94. package/dist/session/provider-cli/ci-repair-readiness.d.ts +14 -0
  95. package/dist/session/provider-cli/ci-repair-readiness.js +105 -0
  96. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +3 -2
  97. package/dist/session/provider-cli/provider-cli.artifacts.js +65 -7
  98. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  99. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +2 -0
  100. package/dist/session/provider-cli/provider-cli.deterministic.js +66 -9
  101. package/dist/session/provider-cli/provider-cli.process.d.ts +16 -0
  102. package/dist/session/provider-cli/provider-cli.process.js +212 -25
  103. package/dist/session/provider-cli/provider-cli.prompts.d.ts +6 -1
  104. package/dist/session/provider-cli/provider-cli.prompts.js +129 -18
  105. package/dist/session/provider-cli/provider-cli.qa-sidecars.js +1 -0
  106. package/dist/session/provider-cli/provider-cli.runtime.d.ts +1 -1
  107. package/dist/session/provider-cli/provider-cli.runtime.js +3 -2
  108. package/dist/session/provider-cli/provider-cli.service.d.ts +23 -2
  109. package/dist/session/provider-cli/provider-cli.service.js +507 -88
  110. package/dist/session/provider-cli/provider-cli.types.d.ts +5 -0
  111. package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
  112. package/dist/session/provider-cli/provider-output-state.js +69 -7
  113. package/dist/session/session-redaction.d.ts +3 -0
  114. package/dist/session/session-redaction.js +38 -0
  115. package/dist/session/session.base.d.ts +6 -1
  116. package/dist/session/session.service.d.ts +8 -2
  117. package/dist/session/session.service.js +490 -42
  118. package/dist/session/session.types.d.ts +111 -1
  119. package/dist/session/session.types.js +192 -3
  120. package/dist/shared/format/format-bytes.d.ts +1 -0
  121. package/dist/shared/format/format-bytes.js +9 -0
  122. package/dist/shared/path/path.js +3 -1
  123. package/dist/shared/process/host-process-recovery.d.ts +12 -0
  124. package/dist/shared/process/host-process-recovery.js +78 -0
  125. package/dist/shared/process/host-process-supervisor.d.ts +57 -0
  126. package/dist/shared/process/host-process-supervisor.js +282 -0
  127. package/dist/shared/process/process.d.ts +1 -0
  128. package/dist/shared/process/process.js +1 -0
  129. package/dist/shared/redaction/redaction.js +6 -1
  130. package/dist/version.d.ts +1 -1
  131. package/dist/version.js +1 -1
  132. package/dist/worktree/artifact-injector.d.ts +3 -2
  133. package/dist/worktree/artifact-injector.js +43 -4
  134. package/dist/worktree/dependency-warmer.d.ts +10 -1
  135. package/dist/worktree/dependency-warmer.js +94 -5
  136. package/dist/worktree/index.d.ts +1 -0
  137. package/dist/worktree/index.js +1 -0
  138. package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
  139. package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
  140. package/dist/worktree/worktree-paths.d.ts +4 -0
  141. package/dist/worktree/worktree-paths.js +30 -0
  142. package/dist/worktree/worktree.base.d.ts +3 -0
  143. package/dist/worktree/worktree.service.d.ts +8 -2
  144. package/dist/worktree/worktree.service.js +206 -43
  145. package/dist/worktree/worktree.types.d.ts +4 -1
  146. package/package.json +6 -3
  147. package/runtime/windows-job-supervisor.ps1 +356 -0
  148. package/runtime/windows-listener-owner.ps1 +33 -0
@@ -1,14 +1,19 @@
1
1
  import type { RunOnceDispatchPacket, RunnerDispatchArtifact, RunnerDispatchEvent, RunnerDispatchSpec } from "../session.types.js";
2
2
  import type { WorktreeHandle } from "../../worktree/worktree.types.js";
3
+ import type { ProviderProcessRunner } from "./provider-cli.process.js";
3
4
  export interface ProviderCliRunContext {
4
5
  readonly dispatch: RunOnceDispatchPacket;
5
6
  readonly worktree: WorktreeHandle;
7
+ readonly runtimeEnvironment?: Readonly<Record<string, string>>;
8
+ readonly processRunner?: ProviderProcessRunner;
6
9
  readonly signal?: AbortSignal;
7
10
  emit(event: RunnerDispatchEvent): Promise<void>;
8
11
  }
9
12
  export interface ProviderCliDraftContext {
10
13
  readonly dispatch: RunOnceDispatchPacket;
11
14
  readonly worktree: WorktreeHandle;
15
+ readonly runtimeEnvironment?: Readonly<Record<string, string>>;
16
+ readonly processRunner?: ProviderProcessRunner;
12
17
  readonly signal?: AbortSignal;
13
18
  emit(event: RunnerDispatchEvent): Promise<void>;
14
19
  }
@@ -5,6 +5,8 @@ export declare function clip(value: string, maxLength: number): string;
5
5
  export interface ProviderOutputState {
6
6
  readonly sessionLabel: string | null;
7
7
  finalMessage: string | null;
8
+ /** True only while the provider has reported a tool/command start without a matching completion. */
9
+ readonly hasActiveToolCall: boolean;
8
10
  /** Accumulated provider-reported token usage for this run, or null when none was reported. */
9
11
  readonly usage: ProviderUsage | null;
10
12
  consume(line: string): readonly RunnerDispatchEvent[];
@@ -25,12 +25,16 @@ class CursorStreamJsonState {
25
25
  finalMessage = null;
26
26
  emittedSession = false;
27
27
  accumulatedUsage = null;
28
+ activeToolCallCount = 0;
28
29
  get sessionLabel() {
29
30
  return this.sessionId ? `session ${this.sessionId}` : null;
30
31
  }
31
32
  get usage() {
32
33
  return this.accumulatedUsage;
33
34
  }
35
+ get hasActiveToolCall() {
36
+ return this.activeToolCallCount > 0;
37
+ }
34
38
  consume(line) {
35
39
  const event = parseJsonLine(line);
36
40
  if (!event) {
@@ -65,6 +69,7 @@ class CursorStreamJsonState {
65
69
  const subtype = stringField(event, "subtype");
66
70
  const toolCall = objectField(event, "tool_call");
67
71
  if (subtype === "started") {
72
+ this.activeToolCallCount += 1;
68
73
  const summary = formatCursorToolCallStarted(toolCall);
69
74
  if (summary) {
70
75
  return [{
@@ -76,6 +81,7 @@ class CursorStreamJsonState {
76
81
  }
77
82
  }
78
83
  if (subtype === "completed") {
84
+ this.activeToolCallCount = Math.max(0, this.activeToolCallCount - 1);
79
85
  const completed = formatCursorToolCallCompleted(toolCall);
80
86
  if (completed) {
81
87
  return [{
@@ -224,18 +230,23 @@ class CodexJsonState {
224
230
  finalMessage = null;
225
231
  emittedThread = false;
226
232
  accumulatedUsage = null;
233
+ activeToolCallCount = 0;
227
234
  get sessionLabel() {
228
235
  return this.threadId ? `thread ${this.threadId}` : null;
229
236
  }
230
237
  get usage() {
231
238
  return this.accumulatedUsage;
232
239
  }
240
+ get hasActiveToolCall() {
241
+ return this.activeToolCallCount > 0;
242
+ }
233
243
  consume(line) {
234
244
  const event = parseJsonLine(line);
235
245
  if (!event) {
236
246
  return [];
237
247
  }
238
248
  const type = stringField(event, "type") ?? "";
249
+ this.trackToolActivity(type, event);
239
250
  if (type === "thread.started") {
240
251
  this.threadId = stringField(event, "thread_id");
241
252
  if (this.threadId && !this.emittedThread) {
@@ -265,7 +276,7 @@ class CodexJsonState {
265
276
  eventType: "provider_cli_error"
266
277
  }];
267
278
  }
268
- if (type === "item.completed" || type === "item.updated") {
279
+ if (type === "item.started" || type === "item.completed" || type === "item.updated") {
269
280
  const item = objectField(event, "item");
270
281
  const itemType = stringField(item, "type");
271
282
  if (itemType === "agent_message") {
@@ -287,7 +298,7 @@ class CodexJsonState {
287
298
  return [{
288
299
  role: "worker",
289
300
  kind: "checkpoint",
290
- content: `Codex command ${status || "completed"}: ${clip(command, 500)}`,
301
+ content: `Codex command ${status || (type === "item.started" ? "started" : "completed")}: ${clip(command, 500)}`,
291
302
  eventType: "provider_command"
292
303
  }];
293
304
  }
@@ -299,6 +310,23 @@ class CodexJsonState {
299
310
  }
300
311
  return [];
301
312
  }
313
+ trackToolActivity(type, event) {
314
+ if (type !== "item.started" && type !== "item.completed") {
315
+ return;
316
+ }
317
+ const item = objectField(event, "item");
318
+ const itemType = (stringField(item, "type") ?? "").toLowerCase();
319
+ const toolName = mcpToolName(item);
320
+ const isTool = itemType === "command_execution"
321
+ || itemType.includes("mcp")
322
+ || Boolean(toolName);
323
+ if (!isTool) {
324
+ return;
325
+ }
326
+ this.activeToolCallCount = type === "item.started"
327
+ ? this.activeToolCallCount + 1
328
+ : Math.max(0, this.activeToolCallCount - 1);
329
+ }
302
330
  accumulateUsage(event) {
303
331
  const usage = objectField(event, "usage");
304
332
  if (Object.keys(usage).length === 0) {
@@ -397,11 +425,45 @@ function mcpErrorSummary(item) {
397
425
  if (direct) {
398
426
  return clip(direct, 600);
399
427
  }
400
- const error = objectField(item, "error");
401
- return stringField(error, "message")
402
- ?? stringField(error, "summary")
403
- ?? stringField(objectField(item, "result"), "error")
404
- ?? null;
428
+ const messages = uniqueErrorMessages([
429
+ item.error,
430
+ item.result,
431
+ item.content,
432
+ ]);
433
+ return messages.length > 0 ? clip(messages.join(" Caused by: "), 600) : null;
434
+ }
435
+ function uniqueErrorMessages(values) {
436
+ const messages = [];
437
+ const seenMessages = new Set();
438
+ const seenObjects = new Set();
439
+ const visit = (value, depth) => {
440
+ if (depth > 8 || value === null || value === undefined)
441
+ return;
442
+ if (typeof value === "string") {
443
+ const message = value.trim();
444
+ if (message.length > 0 && !seenMessages.has(message)) {
445
+ seenMessages.add(message);
446
+ messages.push(message);
447
+ }
448
+ return;
449
+ }
450
+ if (typeof value !== "object" || seenObjects.has(value))
451
+ return;
452
+ seenObjects.add(value);
453
+ if (Array.isArray(value)) {
454
+ for (const entry of value)
455
+ visit(entry, depth + 1);
456
+ return;
457
+ }
458
+ const record = value;
459
+ for (const key of ["message", "summary", "error", "cause", "data", "details", "result", "content"]) {
460
+ if (key in record)
461
+ visit(record[key], depth + 1);
462
+ }
463
+ };
464
+ for (const value of values)
465
+ visit(value, 0);
466
+ return messages;
405
467
  }
406
468
  function safeProviderMcpData(item, serverName, toolName, status) {
407
469
  const elapsedMs = numericField(item, "elapsed_ms") ?? numericField(item, "duration_ms");
@@ -0,0 +1,3 @@
1
+ import type { RunOnceResultPacket, RunnerDispatchEvent } from "./session.types.js";
2
+ export declare function redactRunnerDispatchEvent(event: RunnerDispatchEvent, exactSecrets?: readonly string[]): RunnerDispatchEvent;
3
+ export declare function redactRunOnceResultPacket(result: RunOnceResultPacket, exactSecrets?: readonly string[]): RunOnceResultPacket;
@@ -0,0 +1,38 @@
1
+ import { redactSecrets } from "../shared/redaction/redaction.js";
2
+ const integrityProtectedEventDataTypes = new Set(["sandbox_started"]);
3
+ export function redactRunnerDispatchEvent(event, exactSecrets = []) {
4
+ if (!event.data || !integrityProtectedEventDataTypes.has(event.eventType)) {
5
+ return redactSecrets(event, exactSecrets);
6
+ }
7
+ // sandbox_started data is runner-authored protocol metadata. Its runtime
8
+ // lease repeats the dispatch fence so the API can validate ownership. The
9
+ // transcript redactor treats any serialized `*Token` field as a secret and
10
+ // must not rewrite that identity before transport or result persistence.
11
+ const { data, ...transcript } = event;
12
+ return {
13
+ ...redactSecrets(transcript, exactSecrets),
14
+ data,
15
+ };
16
+ }
17
+ export function redactRunOnceResultPacket(result, exactSecrets = []) {
18
+ const { events, artifact, artifacts, ...payload } = result;
19
+ return {
20
+ ...redactSecrets(payload, exactSecrets),
21
+ ...(artifact !== undefined
22
+ ? { artifact: artifact === null ? null : redactArtifact(artifact, exactSecrets) }
23
+ : {}),
24
+ ...(artifacts !== undefined
25
+ ? { artifacts: artifacts === null ? null : artifacts.map(item => redactArtifact(item, exactSecrets)) }
26
+ : {}),
27
+ events: events.map(event => redactRunnerDispatchEvent(event, exactSecrets)),
28
+ };
29
+ }
30
+ function redactArtifact(artifact, exactSecrets) {
31
+ const { sidecars, ...payload } = artifact;
32
+ return {
33
+ ...redactSecrets(payload, exactSecrets),
34
+ // These bytes already passed the QA path/hash/size checks. The generic
35
+ // redactor strips contentBase64 fields and must not corrupt the payload.
36
+ ...(sidecars !== undefined ? { sidecars } : {}),
37
+ };
38
+ }
@@ -1,7 +1,12 @@
1
- import type { RunOnceDispatchPacket, RunOnceResultPacket, RunnerDispatchEvent } from "./session.types.js";
1
+ import type { HostRuntimeReadinessProbeRequest, HostRuntimeReadinessProbeResult, RunOnceDispatchPacket, RunOnceResultPacket, RunnerDispatchEvent } from "./session.types.js";
2
+ import type { HostRuntimeCapacitySnapshot, HostRuntimeReapOptions, HostRuntimeReapReport } from "../runtime/host-runtime-lease.js";
2
3
  export interface SessionEventSink {
3
4
  emit(event: RunnerDispatchEvent): Promise<void>;
4
5
  }
5
6
  export interface SessionService {
6
7
  runOnce(dispatch: RunOnceDispatchPacket, sink: SessionEventSink, signal?: AbortSignal): Promise<RunOnceResultPacket>;
8
+ updateLease?(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
9
+ reapHostRuntime?(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport | null>;
10
+ runtimeCapacity?(): HostRuntimeCapacitySnapshot | null;
11
+ probeHostRuntime?(request: HostRuntimeReadinessProbeRequest, signal?: AbortSignal): Promise<HostRuntimeReadinessProbeResult>;
7
12
  }
@@ -1,10 +1,16 @@
1
1
  import type { ProviderCliService } from "./provider-cli/provider-cli.base.js";
2
2
  import type { SessionEventSink, SessionService } from "./session.base.js";
3
- import type { RunOnceDispatchPacket, RunOnceResultPacket } from "./session.types.js";
3
+ import type { HostRuntimeReadinessProbeRequest, HostRuntimeReadinessProbeResult, RunOnceDispatchPacket, RunOnceResultPacket } from "./session.types.js";
4
4
  import type { WorktreeService } from "../worktree/worktree.base.js";
5
+ import { type HostRuntimeCapacitySnapshot, type HostRuntimeLeaseRuntime, type HostRuntimeReapOptions, type HostRuntimeReapReport } from "../runtime/host-runtime-lease.js";
5
6
  export declare class BridgeSessionService implements SessionService {
6
7
  private readonly worktrees;
7
8
  private readonly providerCli;
8
- constructor(worktrees?: WorktreeService, providerCli?: ProviderCliService);
9
+ private readonly hostRuntime?;
10
+ constructor(worktrees?: WorktreeService, providerCli?: ProviderCliService, hostRuntime?: HostRuntimeLeaseRuntime | undefined);
11
+ updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
12
+ reapHostRuntime(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport | null>;
13
+ runtimeCapacity(): HostRuntimeCapacitySnapshot | null;
14
+ probeHostRuntime(request: HostRuntimeReadinessProbeRequest, signal?: AbortSignal): Promise<HostRuntimeReadinessProbeResult>;
9
15
  runOnce(dispatch: RunOnceDispatchPacket, sink: SessionEventSink, signal?: AbortSignal): Promise<RunOnceResultPacket>;
10
16
  }