@in-the-loop-labs/pair-review 5.0.2 → 5.1.0

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.
@@ -21,7 +21,7 @@ const logger = require('../utils/logger');
21
21
  const { extractJSON } = require('../utils/json-extractor');
22
22
  const { CancellationError, isAnalysisCancelled } = require('../routes/shared');
23
23
  const { StreamParser, parseCursorAgentLine } = require('./stream-parser');
24
- const { wireAbortToChild, makeAbortError } = require('./abort-signal-wiring');
24
+ const { wireAbortToChild, makeAbortError, killChildSafely } = require('./abort-signal-wiring');
25
25
 
26
26
  // Directory containing bin scripts (git-diff-lines, etc.)
27
27
  const BIN_DIR = path.join(__dirname, '..', '..', 'bin');
@@ -316,7 +316,7 @@ class CursorAgentProvider extends AIProvider {
316
316
  if (timeout) {
317
317
  timeoutId = setTimeout(() => {
318
318
  logger.error(`${levelPrefix} Process ${pid} timed out after ${timeout}ms`);
319
- agent.kill('SIGTERM');
319
+ killChildSafely(agent, { logPrefix: levelPrefix, shell: this.useShell });
320
320
  settle(reject, new Error(`${levelPrefix} Cursor Agent CLI timed out after ${timeout}ms`));
321
321
  }, timeout);
322
322
  }
@@ -420,6 +420,15 @@ class CursorAgentProvider extends AIProvider {
420
420
  logger.info(`${levelPrefix} LLM fallback input length: ${llmFallbackInput.length} characters (${parsed.textContent ? 'text content' : 'raw stdout'})`);
421
421
  logger.info(`${levelPrefix} Attempting LLM-based JSON extraction fallback...`);
422
422
 
423
+ // The agent child has already exited, so a cancel arriving now only
424
+ // makes the abort wiring kill something already dead. The `settled`
425
+ // guard below only covers a cancel that landed BEFORE the await, so
426
+ // without the checks below one landing during extraction would settle
427
+ // as a normal result. The signal is read alongside the wiring flag as
428
+ // the source of truth.
429
+ const cancelledDuringExtraction = () =>
430
+ abortWiring.cancelled() || abortSignal?.aborted === true;
431
+
423
432
  // Use async IIFE to handle the async LLM extraction
424
433
  (async () => {
425
434
  try {
@@ -427,7 +436,14 @@ class CursorAgentProvider extends AIProvider {
427
436
  // orphan processes if timeout fired between close-handler entry
428
437
  // and reaching this point.
429
438
  if (settled) return;
430
- const llmExtracted = await this.extractJSONWithLLM(llmFallbackInput, { level, analysisId, registerProcess, logPrefix: levelPrefix });
439
+ // `abortSignal` lets the extraction spawn be killed rather than
440
+ // merely abandoned until its own 60s timeout.
441
+ const llmExtracted = await this.extractJSONWithLLM(llmFallbackInput, { level, analysisId, registerProcess, logPrefix: levelPrefix, abortSignal });
442
+ if (cancelledDuringExtraction()) {
443
+ logger.info(`${levelPrefix} Cancelled by user during LLM extraction fallback`);
444
+ settle(reject, makeAbortError(`${levelPrefix} Cancelled by user`));
445
+ return;
446
+ }
431
447
  if (llmExtracted.success) {
432
448
  logger.success(`${levelPrefix} LLM extraction fallback succeeded`);
433
449
  settle(resolve, llmExtracted.data);
@@ -437,6 +453,13 @@ class CursorAgentProvider extends AIProvider {
437
453
  settle(resolve, { raw: llmFallbackInput, parsed: false });
438
454
  }
439
455
  } catch (llmError) {
456
+ // An abort that kills the extraction spawn surfaces here as a
457
+ // thrown error; it is a cancellation, not a parse failure.
458
+ if (cancelledDuringExtraction()) {
459
+ logger.info(`${levelPrefix} Cancelled by user during LLM extraction fallback`);
460
+ settle(reject, makeAbortError(`${levelPrefix} Cancelled by user`));
461
+ return;
462
+ }
440
463
  logger.warn(`${levelPrefix} LLM extraction fallback error: ${llmError.message}`);
441
464
  settle(resolve, { raw: llmFallbackInput, parsed: false });
442
465
  }
@@ -465,7 +488,9 @@ class CursorAgentProvider extends AIProvider {
465
488
  agent.stdin.write(prompt, (err) => {
466
489
  if (err) {
467
490
  logger.error(`${levelPrefix} Failed to write prompt to stdin: ${err}`);
468
- agent.kill('SIGTERM');
491
+ // A failed spawn (ENOENT) EPIPEs stdin and lands here with a pidless
492
+ // child; killChildSafely skips the self-directed kill(0).
493
+ killChildSafely(agent, { logPrefix: levelPrefix, shell: this.useShell });
469
494
  settle(reject, new Error(`${levelPrefix} Failed to write prompt to stdin: ${err}`));
470
495
  }
471
496
  });
@@ -815,7 +840,9 @@ class CursorAgentProvider extends AIProvider {
815
840
  if (settled) return;
816
841
  settled = true;
817
842
  logger.warn(`Cursor Agent CLI availability check timed out after ${Math.round(timeoutMs / 1000)}s`);
818
- try { agent.kill(); } catch { /* ignore */ }
843
+ // Not `shell: useShell`: the probe spawn is not `detached`, so
844
+ // group-kill would ESRCH and leave the child running.
845
+ killChildSafely(agent, { logPrefix: '[availability]' });
819
846
  resolve(false);
820
847
  }, timeoutMs);
821
848
 
@@ -18,6 +18,7 @@ const { glob } = require('glob');
18
18
  const fs = require('fs').promises;
19
19
  const path = require('path');
20
20
  const logger = require('../utils/logger');
21
+ const { killChildSafely } = require('./abort-signal-wiring');
21
22
  const jsonExtractor = require('../utils/json-extractor');
22
23
  const configModule = require('../config');
23
24
 
@@ -266,7 +267,10 @@ function createExecutableProviderClass(id, config) {
266
267
  if (stderr.trim()) {
267
268
  logger.warn(`[${id}] stderr before timeout: ${stderr.trim().slice(0, 2000)}`);
268
269
  }
269
- child.kill('SIGTERM');
270
+ // Not `shell: this.useShell`: this spawn is not `detached`, so
271
+ // group-kill would ESRCH and leave the child running — and it
272
+ // would bypass the kill wrapper above that records `cancelled`.
273
+ killChildSafely(child, { logPrefix: `[${id}]` });
270
274
  }, timeout);
271
275
  }
272
276
 
@@ -480,7 +484,9 @@ function createExecutableProviderClass(id, config) {
480
484
  if (settled) return;
481
485
  settled = true;
482
486
  logger.warn(`${id} availability check timed out after ${Math.round(timeoutMs / 1000)}s`);
483
- try { child.kill(); } catch { /* ignore */ }
487
+ // Not `shell: true` (as spawned): the probe is not `detached`, so
488
+ // group-kill would ESRCH and leave the child running.
489
+ killChildSafely(child, { logPrefix: `[${id}]` });
484
490
  resolve(false);
485
491
  }, timeoutMs);
486
492
 
package/src/ai/index.js CHANGED
@@ -55,6 +55,7 @@ require('./copilot-provider');
55
55
  require('./opencode-provider');
56
56
  require('./cursor-agent-provider');
57
57
  require('./pi-provider');
58
+ require('./muse-provider');
58
59
 
59
60
  // Export the unified API
60
61
  module.exports = {