@loucompanion/forge-bridge 0.1.4-dev.9e8a5b93cbcb → 0.1.4-dev.d2d83bc81b6a

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.
@@ -23,6 +23,8 @@ export interface ProviderProcessRunResult {
23
23
  readonly memorySampleCount?: number;
24
24
  readonly memorySource?: string;
25
25
  readonly memoryObservedAt?: string;
26
+ /** Present when the caller's cancellation stopped the process before it exited on its own. */
27
+ readonly cancelled?: true;
26
28
  }
27
29
  export interface ProviderProcessRunner {
28
30
  run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
@@ -70,7 +72,8 @@ interface ProviderChildEnvironmentOptions {
70
72
  export declare function buildProviderChildEnvironment(requestEnv?: Readonly<Record<string, string>>, options?: ProviderChildEnvironmentOptions): NodeJS.ProcessEnv;
71
73
  export declare class StreamingProviderProcessRunner implements ProviderProcessRunner {
72
74
  private readonly terminalExitGraceMs;
73
- constructor(terminalExitGraceMs?: number);
75
+ private readonly terminalSuccessCeilingMs;
76
+ constructor(terminalExitGraceMs?: number, terminalSuccessCeilingMs?: number);
74
77
  run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
75
78
  }
76
79
  /** Returns aggregate resident bytes for the exact supervised Unix process group. */
@@ -16,6 +16,9 @@ const execFileAsync = promisify(execFile);
16
16
  // only needs a bounded diagnostic tail for failure classification.
17
17
  export const PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS = 128 * 1024;
18
18
  const PROVIDER_TERMINAL_EXIT_GRACE_MS = 15_000;
19
+ // A provider that keeps starting turns after its first successful one (background-task
20
+ // notifications) is still stopped this long after that first success.
21
+ const PROVIDER_TERMINAL_SUCCESS_CEILING_MS = 10 * 60_000;
19
22
  const maximumRecoverableCodexModelsCacheBytes = 16 * 1024 * 1024;
20
23
  /** Recovery must wrap the attempt coordinator, never its raw OS runner. Each
21
24
  * relaunch needs a new fenced child generation and exclusive launch files. */
@@ -313,8 +316,10 @@ function setEnvironmentValueIfMissing(env, name, value) {
313
316
  }
314
317
  export class StreamingProviderProcessRunner {
315
318
  terminalExitGraceMs;
316
- constructor(terminalExitGraceMs = PROVIDER_TERMINAL_EXIT_GRACE_MS) {
319
+ terminalSuccessCeilingMs;
320
+ constructor(terminalExitGraceMs = PROVIDER_TERMINAL_EXIT_GRACE_MS, terminalSuccessCeilingMs = PROVIDER_TERMINAL_SUCCESS_CEILING_MS) {
317
321
  this.terminalExitGraceMs = terminalExitGraceMs;
322
+ this.terminalSuccessCeilingMs = terminalSuccessCeilingMs;
318
323
  }
319
324
  async run(request, handlers = {}, signal) {
320
325
  assertHostDatabaseCapabilityBoundary();
@@ -369,14 +374,21 @@ export class StreamingProviderProcessRunner {
369
374
  let settled = false;
370
375
  let closed = false;
371
376
  let cancellationRequested = false;
377
+ let cancelledBeforeClose = false;
372
378
  let terminalTerminationStarted = false;
373
379
  let terminalExitTimer = null;
380
+ let terminalCeilingTimer = null;
381
+ let latestTurnFailed = false;
374
382
  let readiness = null;
375
383
  const cleanup = () => {
376
384
  if (terminalExitTimer) {
377
385
  clearTimeout(terminalExitTimer);
378
386
  terminalExitTimer = null;
379
387
  }
388
+ if (terminalCeilingTimer) {
389
+ clearTimeout(terminalCeilingTimer);
390
+ terminalCeilingTimer = null;
391
+ }
380
392
  signal?.removeEventListener("abort", abort);
381
393
  };
382
394
  const fail = (error) => {
@@ -390,6 +402,8 @@ export class StreamingProviderProcessRunner {
390
402
  void terminate().then(() => reject(error), terminationError => reject(new AggregateError([error, terminationError], "Provider process failed and its process tree could not be proven stopped.")));
391
403
  };
392
404
  const abort = () => {
405
+ if (!closed)
406
+ cancelledBeforeClose = true;
393
407
  cancellationRequested = true;
394
408
  // Cancellation is not a launch failure when the supervised tree can be
395
409
  // proven stopped. Let the close handler settle the command after exact
@@ -476,19 +490,46 @@ export class StreamingProviderProcessRunner {
476
490
  });
477
491
  }
478
492
  }
493
+ const finishAfterTerminalSuccess = () => {
494
+ if (closed || settled || cancellationRequested || terminalTerminationStarted)
495
+ return;
496
+ terminalTerminationStarted = true;
497
+ void terminate().catch(fail);
498
+ };
499
+ const armTerminalExit = () => {
500
+ if (terminalExitTimer)
501
+ clearTimeout(terminalExitTimer);
502
+ terminalExitTimer = setTimeout(finishAfterTerminalSuccess, this.terminalExitGraceMs);
503
+ terminalExitTimer.unref?.();
504
+ // Later turns may postpone the grace period, but never past this ceiling.
505
+ if (!terminalCeilingTimer) {
506
+ terminalCeilingTimer = setTimeout(finishAfterTerminalSuccess, this.terminalSuccessCeilingMs);
507
+ terminalCeilingTimer.unref?.();
508
+ }
509
+ };
479
510
  const readers = [
480
511
  readProcessLines(childStdout, (line) => {
481
512
  if (request.captureOutput !== false)
482
513
  stdout.appendLine(line);
483
514
  const handled = handlers.onStdoutLine?.(line);
484
- if (!terminalExitTimer && isProviderTerminalSuccess(line)) {
485
- terminalExitTimer = setTimeout(() => {
486
- if (closed || settled || cancellationRequested)
487
- return;
488
- terminalTerminationStarted = true;
489
- void terminate().catch(fail);
490
- }, this.terminalExitGraceMs);
491
- terminalExitTimer.unref?.();
515
+ if (!terminalTerminationStarted) {
516
+ if (isProviderTerminalSuccess(line)) {
517
+ latestTurnFailed = false;
518
+ armTerminalExit();
519
+ }
520
+ else if (isProviderTerminalFailure(line)) {
521
+ // A later turn that fails reports its failure even after an earlier success.
522
+ latestTurnFailed = true;
523
+ }
524
+ else if (terminalExitTimer && isProviderTurnActivity(line)) {
525
+ // A terminal event ends a turn, not necessarily the provider. Claude Code
526
+ // stays resident while background tasks it started are pending and begins a
527
+ // new turn when one reports (and a resumed session can replay a queued
528
+ // notification turn first). A provider that is working again is not finished;
529
+ // the grace period restarts at its next terminal event.
530
+ clearTimeout(terminalExitTimer);
531
+ terminalExitTimer = null;
532
+ }
492
533
  }
493
534
  return handled;
494
535
  }),
@@ -535,16 +576,53 @@ export class StreamingProviderProcessRunner {
535
576
  // that event, terminate the supervised tree after a short grace
536
577
  // period and preserve the successful handoff so the existing
537
578
  // artifact, commit, and publication gates can run.
538
- exitCode: terminalTerminationStarted && !cancellationRequested ? 0 : code ?? 1,
579
+ // A provider stopped after a successful turn keeps that success. Whenever the
580
+ // most recent turn failed, the run fails, however the process ended.
581
+ exitCode: latestTurnFailed
582
+ ? code && code !== 0 ? code : 1
583
+ : terminalTerminationStarted && !cancellationRequested ? 0 : code ?? 1,
539
584
  stdout: stdout.toString(),
540
585
  stderr: stderr.toString(),
541
586
  ...(memory ?? {}),
587
+ ...(cancelledBeforeClose ? { cancelled: true } : {}),
542
588
  });
543
589
  }).catch(fail);
544
590
  });
545
591
  });
546
592
  }
547
593
  }
594
+ /** A stream event that shows the provider is working on a turn: model output or a tool result. */
595
+ function isProviderTurnActivity(line) {
596
+ const trimmed = line.trim();
597
+ if (!trimmed.startsWith("{"))
598
+ return false;
599
+ try {
600
+ const event = JSON.parse(trimmed);
601
+ return event.type === "assistant"
602
+ || event.type === "user"
603
+ || (event.type === "system" && event.subtype === "init")
604
+ || event.type === "turn.started"
605
+ || event.type === "item.started";
606
+ }
607
+ catch {
608
+ return false;
609
+ }
610
+ }
611
+ function isProviderTerminalFailure(line) {
612
+ const trimmed = line.trim();
613
+ if (!trimmed.startsWith("{"))
614
+ return false;
615
+ try {
616
+ const event = JSON.parse(trimmed);
617
+ // The same events the output parsers report as provider errors.
618
+ return event.type === "turn.failed"
619
+ || event.type === "error"
620
+ || (event.type === "result" && (event.subtype !== "success" || event.is_error === true));
621
+ }
622
+ catch {
623
+ return false;
624
+ }
625
+ }
548
626
  function isProviderTerminalSuccess(line) {
549
627
  const trimmed = line.trim();
550
628
  if (!trimmed.startsWith("{"))
@@ -1397,10 +1397,14 @@ export class ProcessBackedProviderCliService {
1397
1397
  session: { ...dispatch.session, resumeProviderThreadId: providerThreadId },
1398
1398
  };
1399
1399
  const recoveryPrompt = [
1400
- "Forge did not receive the required forge.complete_comment_repair call from your previous turn.",
1400
+ "Forge did not receive the required forge.complete_comment_repair call from your previous turn, so the provider process exited.",
1401
+ "Background watchers, monitors and notifications from that turn did not survive and will never report back,",
1402
+ "and Forge stopped any managed command that process was still running; its receipt reports that.",
1401
1403
  "Resume the existing work exactly where it is. Do not reimplement or discard the prepared changes.",
1402
- "Review the current diff and the durable review snapshot, preserve the validation evidence already gathered,",
1403
- "then call forge.complete_comment_repair with an evidence-backed disposition for every actionable finding.",
1404
+ "Review the current diff and the durable review snapshot and preserve the validation evidence already gathered.",
1405
+ "Check each managed command with forge.get_managed_command, restart any that were interrupted,",
1406
+ "and block on long commands with forge.wait_managed_command, calling it again while command_continues is true.",
1407
+ "Do not end your turn until you have called forge.complete_comment_repair with an evidence-backed disposition for every actionable finding.",
1404
1408
  "Do not commit or push; Forge owns publication after the completion gate succeeds.",
1405
1409
  ].join(" ");
1406
1410
  const providerPrompt = buildProviderCliPrompt(recoveryDispatch, recoveryPrompt, repairEnvironment);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const forgeBridgeVersion = "0.1.4-dev.9e8a5b93cbcb";
1
+ export declare const forgeBridgeVersion = "0.1.4-dev.d2d83bc81b6a";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const forgeBridgeVersion = "0.1.4-dev.9e8a5b93cbcb";
1
+ export const forgeBridgeVersion = "0.1.4-dev.d2d83bc81b6a";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loucompanion/forge-bridge",
3
- "version": "0.1.4-dev.9e8a5b93cbcb",
3
+ "version": "0.1.4-dev.d2d83bc81b6a",
4
4
  "description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",