@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.
- package/README.md +44 -3
- package/package.json +5 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin-code-critic/.claude-plugin/plugin.json +1 -1
- package/plugin-pair-loop/.claude-plugin/plugin.json +1 -1
- package/public/js/utils/markdown.js +202 -65
- package/public/js/vendor/pierre-diffs-worker.js +3446 -5992
- package/public/js/vendor/pierre-diffs.js +731 -1047
- package/public/local.html +2 -0
- package/public/pr.html +2 -0
- package/src/ai/abort-signal-wiring.js +91 -46
- package/src/ai/analyzer.js +64 -11
- package/src/ai/antigravity-provider.js +31 -5
- package/src/ai/claude-cli.js +8 -2
- package/src/ai/claude-provider.js +34 -5
- package/src/ai/codex-provider.js +31 -5
- package/src/ai/copilot-provider.js +28 -4
- package/src/ai/cursor-agent-provider.js +32 -5
- package/src/ai/executable-provider.js +8 -2
- package/src/ai/index.js +1 -0
- package/src/ai/muse-provider.js +1224 -0
- package/src/ai/opencode-provider.js +31 -5
- package/src/ai/pi-provider.js +29 -4
- package/src/ai/provider.js +111 -28
- package/src/ai/stream-parser.js +71 -0
- package/src/config.js +35 -2
- package/src/database.js +96 -16
- package/src/git/fetch-helpers.js +48 -0
- package/src/git/pack-cleanup.js +120 -0
- package/src/git/worktree.js +65 -43
- package/src/main.js +243 -47
- package/src/routes/pr.js +2 -3
|
@@ -18,7 +18,7 @@ const logger = require('../utils/logger');
|
|
|
18
18
|
const { extractJSON } = require('../utils/json-extractor');
|
|
19
19
|
const { CancellationError, isAnalysisCancelled } = require('../routes/shared');
|
|
20
20
|
const { StreamParser, parseOpenCodeLine } = require('./stream-parser');
|
|
21
|
-
const { wireAbortToChild, makeAbortError } = require('./abort-signal-wiring');
|
|
21
|
+
const { wireAbortToChild, makeAbortError, killChildSafely } = require('./abort-signal-wiring');
|
|
22
22
|
|
|
23
23
|
// Directory containing bin scripts (git-diff-lines, etc.)
|
|
24
24
|
const BIN_DIR = path.join(__dirname, '..', '..', 'bin');
|
|
@@ -169,7 +169,7 @@ class OpenCodeProvider extends AIProvider {
|
|
|
169
169
|
if (timeout) {
|
|
170
170
|
timeoutId = setTimeout(() => {
|
|
171
171
|
logger.error(`${levelPrefix} Process ${pid} timed out after ${timeout}ms`);
|
|
172
|
-
opencode.
|
|
172
|
+
killChildSafely(opencode, { logPrefix: levelPrefix, shell: this.useShell });
|
|
173
173
|
settle(reject, new Error(`${levelPrefix} OpenCode CLI timed out after ${timeout}ms`));
|
|
174
174
|
}, timeout);
|
|
175
175
|
}
|
|
@@ -274,10 +274,25 @@ class OpenCodeProvider extends AIProvider {
|
|
|
274
274
|
logger.info(`${levelPrefix} LLM fallback input length: ${llmFallbackInput.length} characters (${parsed.textContent ? 'text content' : 'raw stdout'})`);
|
|
275
275
|
logger.info(`${levelPrefix} Attempting LLM-based JSON extraction fallback...`);
|
|
276
276
|
|
|
277
|
+
// The opencode child has already exited, so a cancel arriving now only
|
|
278
|
+
// makes the abort wiring kill something already dead. Nothing else on
|
|
279
|
+
// this path consults it, so without the checks below a cancelled
|
|
280
|
+
// analysis would settle as a normal result. The signal is read
|
|
281
|
+
// alongside the wiring flag as the source of truth.
|
|
282
|
+
const cancelledDuringExtraction = () =>
|
|
283
|
+
abortWiring.cancelled() || abortSignal?.aborted === true;
|
|
284
|
+
|
|
277
285
|
// Use async IIFE to handle the async LLM extraction
|
|
278
286
|
(async () => {
|
|
279
287
|
try {
|
|
280
|
-
|
|
288
|
+
// `abortSignal` lets the extraction spawn be killed rather than
|
|
289
|
+
// merely abandoned until its own 60s timeout.
|
|
290
|
+
const llmExtracted = await this.extractJSONWithLLM(llmFallbackInput, { level, analysisId, registerProcess, logPrefix: levelPrefix, abortSignal });
|
|
291
|
+
if (cancelledDuringExtraction()) {
|
|
292
|
+
logger.info(`${levelPrefix} Cancelled by user during LLM extraction fallback`);
|
|
293
|
+
settle(reject, makeAbortError(`${levelPrefix} Cancelled by user`));
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
281
296
|
if (llmExtracted.success) {
|
|
282
297
|
logger.success(`${levelPrefix} LLM extraction fallback succeeded`);
|
|
283
298
|
settle(resolve, llmExtracted.data);
|
|
@@ -287,6 +302,13 @@ class OpenCodeProvider extends AIProvider {
|
|
|
287
302
|
settle(resolve, { raw: llmFallbackInput, parsed: false });
|
|
288
303
|
}
|
|
289
304
|
} catch (llmError) {
|
|
305
|
+
// An abort that kills the extraction spawn surfaces here as a
|
|
306
|
+
// thrown error; it is a cancellation, not a parse failure.
|
|
307
|
+
if (cancelledDuringExtraction()) {
|
|
308
|
+
logger.info(`${levelPrefix} Cancelled by user during LLM extraction fallback`);
|
|
309
|
+
settle(reject, makeAbortError(`${levelPrefix} Cancelled by user`));
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
290
312
|
logger.warn(`${levelPrefix} LLM extraction fallback error: ${llmError.message}`);
|
|
291
313
|
settle(resolve, { raw: llmFallbackInput, parsed: false });
|
|
292
314
|
}
|
|
@@ -319,7 +341,9 @@ class OpenCodeProvider extends AIProvider {
|
|
|
319
341
|
opencode.stdin.write(prompt, (err) => {
|
|
320
342
|
if (err) {
|
|
321
343
|
logger.error(`${levelPrefix} Failed to write prompt to stdin: ${err}`);
|
|
322
|
-
|
|
344
|
+
// A failed spawn (ENOENT) EPIPEs stdin and lands here with a pidless
|
|
345
|
+
// child; killChildSafely skips the self-directed kill(0).
|
|
346
|
+
killChildSafely(opencode, { logPrefix: levelPrefix, shell: this.useShell });
|
|
323
347
|
settle(reject, new Error(`${levelPrefix} Failed to write prompt to stdin: ${err}`));
|
|
324
348
|
}
|
|
325
349
|
});
|
|
@@ -621,7 +645,9 @@ class OpenCodeProvider extends AIProvider {
|
|
|
621
645
|
if (settled) return;
|
|
622
646
|
settled = true;
|
|
623
647
|
logger.warn(`OpenCode CLI availability check timed out after ${Math.round(timeoutMs / 1000)}s`);
|
|
624
|
-
|
|
648
|
+
// Not `shell: useShell`: the probe spawn is not `detached`, so
|
|
649
|
+
// group-kill would ESRCH and leave the child running.
|
|
650
|
+
killChildSafely(opencode, { logPrefix: '[availability]' });
|
|
625
651
|
resolve(false);
|
|
626
652
|
}, timeoutMs);
|
|
627
653
|
|
package/src/ai/pi-provider.js
CHANGED
|
@@ -26,7 +26,7 @@ const logger = require('../utils/logger');
|
|
|
26
26
|
const { extractJSON } = require('../utils/json-extractor');
|
|
27
27
|
const { CancellationError, isAnalysisCancelled } = require('../routes/shared');
|
|
28
28
|
const { createPiLineParser } = require('./stream-parser');
|
|
29
|
-
const { wireAbortToChild, makeAbortError } = require('./abort-signal-wiring');
|
|
29
|
+
const { wireAbortToChild, makeAbortError, killChildSafely } = require('./abort-signal-wiring');
|
|
30
30
|
|
|
31
31
|
// Directory containing bin scripts (git-diff-lines, etc.)
|
|
32
32
|
const BIN_DIR = path.join(__dirname, '..', '..', 'bin');
|
|
@@ -681,7 +681,7 @@ class PiProvider extends AIProvider {
|
|
|
681
681
|
if (timeout) {
|
|
682
682
|
timeoutId = setTimeout(() => {
|
|
683
683
|
logger.error(`${levelPrefix} Process ${pid} timed out after ${timeout}ms`);
|
|
684
|
-
pi.
|
|
684
|
+
killChildSafely(pi, { logPrefix: levelPrefix, shell: this.useShell });
|
|
685
685
|
settle(reject, new Error(`${levelPrefix} Pi CLI timed out after ${timeout}ms`));
|
|
686
686
|
}, timeout);
|
|
687
687
|
}
|
|
@@ -798,6 +798,15 @@ class PiProvider extends AIProvider {
|
|
|
798
798
|
logger.info(`${levelPrefix} LLM fallback input length: ${llmFallbackInput.length} characters (${parsed.textContent ? 'text content' : 'raw fallback output'})`);
|
|
799
799
|
logger.info(`${levelPrefix} Attempting LLM-based JSON extraction fallback...`);
|
|
800
800
|
|
|
801
|
+
// The pi child has already exited, so a cancel arriving now only makes
|
|
802
|
+
// the abort wiring kill something already dead. The `settled` guard
|
|
803
|
+
// below only covers a cancel that landed BEFORE the await, so without
|
|
804
|
+
// the checks below one landing during extraction would settle as a
|
|
805
|
+
// normal result. The signal is read alongside the wiring flag as the
|
|
806
|
+
// source of truth.
|
|
807
|
+
const cancelledDuringExtraction = () =>
|
|
808
|
+
abortWiring.cancelled() || abortSignal?.aborted === true;
|
|
809
|
+
|
|
801
810
|
// Use async IIFE to handle the async LLM extraction
|
|
802
811
|
(async () => {
|
|
803
812
|
// Guard: if already settled (by timeout, process error, or cancellation),
|
|
@@ -805,7 +814,14 @@ class PiProvider extends AIProvider {
|
|
|
805
814
|
if (settled) return;
|
|
806
815
|
|
|
807
816
|
try {
|
|
808
|
-
|
|
817
|
+
// `abortSignal` lets the extraction spawn be killed rather than
|
|
818
|
+
// merely abandoned until its own 60s timeout.
|
|
819
|
+
const llmExtracted = await this.extractJSONWithLLM(llmFallbackInput, { level, analysisId, registerProcess, logPrefix: levelPrefix, abortSignal });
|
|
820
|
+
if (cancelledDuringExtraction()) {
|
|
821
|
+
logger.info(`${levelPrefix} Cancelled by user during LLM extraction fallback`);
|
|
822
|
+
settle(reject, makeAbortError(`${levelPrefix} Cancelled by user`));
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
809
825
|
if (llmExtracted.success) {
|
|
810
826
|
logger.success(`${levelPrefix} LLM extraction fallback succeeded`);
|
|
811
827
|
settle(resolve, llmExtracted.data);
|
|
@@ -815,6 +831,13 @@ class PiProvider extends AIProvider {
|
|
|
815
831
|
settle(resolve, { raw: llmFallbackInput, parsed: false });
|
|
816
832
|
}
|
|
817
833
|
} catch (llmError) {
|
|
834
|
+
// An abort that kills the extraction spawn surfaces here as a
|
|
835
|
+
// thrown error; it is a cancellation, not a parse failure.
|
|
836
|
+
if (cancelledDuringExtraction()) {
|
|
837
|
+
logger.info(`${levelPrefix} Cancelled by user during LLM extraction fallback`);
|
|
838
|
+
settle(reject, makeAbortError(`${levelPrefix} Cancelled by user`));
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
818
841
|
logger.warn(`${levelPrefix} LLM extraction fallback error: ${llmError.message}`);
|
|
819
842
|
settle(resolve, { raw: llmFallbackInput, parsed: false });
|
|
820
843
|
}
|
|
@@ -1137,7 +1160,9 @@ class PiProvider extends AIProvider {
|
|
|
1137
1160
|
if (settled) return;
|
|
1138
1161
|
settled = true;
|
|
1139
1162
|
logger.warn(`${name} CLI availability check timed out after ${Math.round(timeoutMs / 1000)}s`);
|
|
1140
|
-
|
|
1163
|
+
// Not `shell: useShell`: the probe spawn is not `detached`, so
|
|
1164
|
+
// group-kill would ESRCH and leave the child running.
|
|
1165
|
+
killChildSafely(pi, { logPrefix: '[availability]' });
|
|
1141
1166
|
resolve(false);
|
|
1142
1167
|
}, timeoutMs);
|
|
1143
1168
|
|
package/src/ai/provider.js
CHANGED
|
@@ -13,6 +13,7 @@ const fs = require('fs');
|
|
|
13
13
|
const { spawn } = require('child_process');
|
|
14
14
|
const logger = require('../utils/logger');
|
|
15
15
|
const { extractJSON } = require('../utils/json-extractor');
|
|
16
|
+
const { killChildSafely, wireAbortToChild, makeAbortError } = require('./abort-signal-wiring');
|
|
16
17
|
const { TIERS, TIER_ALIASES } = require('./prompts/config');
|
|
17
18
|
|
|
18
19
|
// Directory containing bin scripts (git-diff-lines, etc.)
|
|
@@ -190,6 +191,10 @@ class AIProvider {
|
|
|
190
191
|
* @property {boolean} useShell - Whether to use shell mode
|
|
191
192
|
* @property {boolean} promptViaStdin - If true, send prompt to stdin; if false, append to args
|
|
192
193
|
* @property {boolean} promptViaFile - If true, write prompt to a temp file and pass @filepath as a positional arg (Pi-specific @file syntax; currently only used by PiProvider)
|
|
194
|
+
* @property {string} promptFileArg - If set (e.g. `'--prompt-file'`), write prompt to a temp file
|
|
195
|
+
* and append `[promptFileArg, filepath]` to args. For CLIs that take the prompt from a file via
|
|
196
|
+
* a named flag (Muse). Takes precedence over promptViaFile; both keep the prompt off argv, so
|
|
197
|
+
* neither can hit the OS single-argument limit.
|
|
193
198
|
*/
|
|
194
199
|
getExtractionConfig(model) {
|
|
195
200
|
// Default: extraction not supported
|
|
@@ -204,10 +209,15 @@ class AIProvider {
|
|
|
204
209
|
* @param {string|number} options.level - Analysis level for logging
|
|
205
210
|
* @param {string} options.analysisId - Analysis ID for process tracking (enables cancellation)
|
|
206
211
|
* @param {Function} options.registerProcess - Function to register child process for cancellation
|
|
212
|
+
* @param {AbortSignal} [options.abortSignal] - Optional cancellation signal. When
|
|
213
|
+
* supplied and aborted, the extraction child is killed and the returned promise
|
|
214
|
+
* REJECTS with an AbortError (`isCancellation: true`) instead of resolving.
|
|
215
|
+
* Callers that omit it keep the original resolve-only contract: every failure
|
|
216
|
+
* still comes back as `{ success: false, error }`.
|
|
207
217
|
* @returns {Promise<{success: boolean, data?: Object, error?: string}>}
|
|
208
218
|
*/
|
|
209
219
|
async extractJSONWithLLM(rawResponse, options = {}) {
|
|
210
|
-
const { level = 'extraction', analysisId, registerProcess, logPrefix } = options;
|
|
220
|
+
const { level = 'extraction', analysisId, registerProcess, logPrefix, abortSignal } = options;
|
|
211
221
|
const levelPrefix = logPrefix || `[Level ${level}]`;
|
|
212
222
|
|
|
213
223
|
// Get the fast-tier model, with fallback to analysis model
|
|
@@ -222,27 +232,38 @@ class AIProvider {
|
|
|
222
232
|
};
|
|
223
233
|
}
|
|
224
234
|
|
|
225
|
-
const { command, args, useShell, promptViaStdin, promptViaFile, env: configEnv } = config;
|
|
235
|
+
const { command, args, useShell, promptViaStdin, promptViaFile, promptFileArg, env: configEnv } = config;
|
|
226
236
|
const prompt = `Extract the JSON object from the following text. Return ONLY the valid JSON, nothing else. Do not include any explanation, markdown formatting, or code blocks - just the raw JSON.
|
|
227
237
|
|
|
228
238
|
=== BEGIN INPUT TEXT ===
|
|
229
239
|
${rawResponse}
|
|
230
240
|
=== END INPUT TEXT ===`;
|
|
231
241
|
|
|
232
|
-
return new Promise((resolve) => {
|
|
242
|
+
return new Promise((resolve, reject) => {
|
|
243
|
+
// Already cancelled before we got here: don't spawn at all. Nothing has
|
|
244
|
+
// been written to disk yet, so there is nothing to clean up.
|
|
245
|
+
if (abortSignal && abortSignal.aborted) {
|
|
246
|
+
logger.info(`${levelPrefix} LLM extraction skipped: already cancelled`);
|
|
247
|
+
reject(makeAbortError(`${levelPrefix} Cancelled by user`));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
233
251
|
// Build final command and args based on prompt delivery method
|
|
234
|
-
//
|
|
252
|
+
// promptFileArg: write to temp file, pass `<flag> <path>` (Muse --prompt-file)
|
|
253
|
+
// promptViaFile: write to temp file, pass `@filepath` as positional arg (Pi @file syntax)
|
|
235
254
|
// promptViaStdin: write to process stdin after spawn
|
|
236
255
|
// default: pass prompt as positional CLI arg
|
|
256
|
+
// The two file modes share one write/cleanup path and differ only in how
|
|
257
|
+
// the path reaches argv, so there is a single place that can leak a file.
|
|
237
258
|
let tmpFile = null;
|
|
238
259
|
let cleanupTmpFile = () => {};
|
|
239
260
|
let finalArgs;
|
|
240
261
|
|
|
241
|
-
if (promptViaFile) {
|
|
262
|
+
if (promptFileArg || promptViaFile) {
|
|
242
263
|
tmpFile = path.join(os.tmpdir(), `pair-review-extract-${Date.now()}-${process.pid}-${crypto.randomUUID()}.txt`);
|
|
243
264
|
fs.writeFileSync(tmpFile, prompt);
|
|
244
265
|
cleanupTmpFile = () => { try { fs.unlinkSync(tmpFile); } catch { /* ignore */ } };
|
|
245
|
-
finalArgs = [...args, `@${tmpFile}`];
|
|
266
|
+
finalArgs = promptFileArg ? [...args, promptFileArg, tmpFile] : [...args, `@${tmpFile}`];
|
|
246
267
|
} else {
|
|
247
268
|
finalArgs = promptViaStdin ? args : [...args, prompt];
|
|
248
269
|
}
|
|
@@ -265,21 +286,47 @@ ${rawResponse}
|
|
|
265
286
|
logger.info(`${levelPrefix} Registered extraction process ${proc.pid} for analysis ${analysisId}`);
|
|
266
287
|
}
|
|
267
288
|
|
|
289
|
+
// Wire the optional AbortSignal -> SIGTERM. With no signal this is inert
|
|
290
|
+
// (`cancelled()` is always false, `detach()` a no-op), so callers that
|
|
291
|
+
// omit `abortSignal` behave exactly as before.
|
|
292
|
+
//
|
|
293
|
+
// Not `shell: useShell`: this spawn is not `detached`, so there is no
|
|
294
|
+
// process group to signal — group-kill would ESRCH and leave the child
|
|
295
|
+
// running. Plain child.kill, with the pid guard from killChildSafely.
|
|
296
|
+
// Same reasoning applies to the timeout path below.
|
|
297
|
+
const abortWiring = wireAbortToChild(proc, abortSignal, { logPrefix: levelPrefix });
|
|
298
|
+
|
|
268
299
|
let stdout = '';
|
|
269
300
|
let stderr = '';
|
|
270
301
|
let settled = false;
|
|
271
302
|
const timeout = 60000; // 60 second timeout for extraction
|
|
272
303
|
|
|
273
|
-
|
|
304
|
+
// Detaching is centralized here so it ALWAYS runs when this call returns,
|
|
305
|
+
// including via the timeout path that settles before the child exits.
|
|
306
|
+
// Analysis jobs reuse a single per-job signal across many provider calls,
|
|
307
|
+
// so a listener that outlives one call accumulates for the whole job.
|
|
308
|
+
const finish = (fn, value) => {
|
|
274
309
|
if (settled) return;
|
|
275
310
|
settled = true;
|
|
276
311
|
if (timeoutId) clearTimeout(timeoutId);
|
|
277
|
-
|
|
312
|
+
abortWiring.detach();
|
|
313
|
+
fn(value);
|
|
278
314
|
};
|
|
315
|
+
const settle = (result) => finish(resolve, result);
|
|
316
|
+
const cancel = () => finish(reject, makeAbortError(`${levelPrefix} Cancelled by user`));
|
|
279
317
|
|
|
280
318
|
const timeoutId = setTimeout(() => {
|
|
281
|
-
|
|
282
|
-
|
|
319
|
+
const cancelled = abortWiring.cancelled();
|
|
320
|
+
logger.warn(cancelled
|
|
321
|
+
? `${levelPrefix} LLM extraction did not exit after cancellation`
|
|
322
|
+
: `${levelPrefix} LLM extraction timed out after ${timeout}ms`);
|
|
323
|
+
killChildSafely(proc, { logPrefix: levelPrefix });
|
|
324
|
+
if (cancelled) {
|
|
325
|
+
// Killed on cancel but the child never exited. Report the cancel, not
|
|
326
|
+
// the timeout, so the caller still sees an AbortError.
|
|
327
|
+
cancel();
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
283
330
|
settle({ success: false, error: 'LLM extraction timed out' });
|
|
284
331
|
}, timeout);
|
|
285
332
|
|
|
@@ -295,6 +342,15 @@ ${rawResponse}
|
|
|
295
342
|
cleanupTmpFile();
|
|
296
343
|
if (settled) return;
|
|
297
344
|
|
|
345
|
+
// We SIGTERMed the child because the caller's signal aborted. Surface
|
|
346
|
+
// it as an AbortError so upstream can tell a user cancel from a real
|
|
347
|
+
// failure, rather than reporting a bogus non-zero exit.
|
|
348
|
+
if (abortWiring.cancelled()) {
|
|
349
|
+
logger.info(`${levelPrefix} LLM extraction cancelled by user (exit code ${code})`);
|
|
350
|
+
cancel();
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
298
354
|
if (code !== 0) {
|
|
299
355
|
logger.warn(`${levelPrefix} LLM extraction process exited with code ${code}`);
|
|
300
356
|
if (stderr.trim()) {
|
|
@@ -320,28 +376,55 @@ ${rawResponse}
|
|
|
320
376
|
|
|
321
377
|
proc.on('error', (error) => {
|
|
322
378
|
cleanupTmpFile();
|
|
379
|
+
if (abortWiring.cancelled()) {
|
|
380
|
+
// A pidless child (spawn failure) is never signalled, so a cancel can
|
|
381
|
+
// land here instead of on `close`.
|
|
382
|
+
logger.info(`${levelPrefix} LLM extraction cancelled by user`);
|
|
383
|
+
cancel();
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
323
386
|
logger.warn(`${levelPrefix} LLM extraction process error: ${error.message}`);
|
|
324
387
|
settle({ success: false, error: error.message });
|
|
325
388
|
});
|
|
326
389
|
|
|
327
|
-
// Deliver prompt
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
390
|
+
// Deliver the prompt, then close stdin on EVERY delivery path — including
|
|
391
|
+
// plain-argv delivery, which used to leave it open. The target CLI may
|
|
392
|
+
// ignore stdin, but a wrapper command (`devx muse --`, `docker exec ...`)
|
|
393
|
+
// can block on an open stdin and hang until the extraction timeout above.
|
|
394
|
+
// The analysis paths in every provider end stdin for exactly this reason.
|
|
395
|
+
const stdin = proc.stdin;
|
|
396
|
+
if (stdin) {
|
|
397
|
+
// EPIPE arrives asynchronously when the CLI exits before the write
|
|
398
|
+
// drains; with no listener it becomes an unhandled 'error' event.
|
|
399
|
+
// Guarded because a stdin that is not a writable stream must not throw
|
|
400
|
+
// inside this executor and reject a promise callers expect to resolve.
|
|
401
|
+
if (typeof stdin.on === 'function') {
|
|
402
|
+
stdin.on('error', (err) => {
|
|
403
|
+
logger.warn(`${levelPrefix} extraction stdin error: ${err.message}`);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (promptViaStdin) {
|
|
408
|
+
stdin.write(prompt, (err) => {
|
|
409
|
+
if (err) {
|
|
410
|
+
// A cancel kills the child, which EPIPEs this write. That lands
|
|
411
|
+
// here before `close` fires, so without this check the cancelled
|
|
412
|
+
// call would settle as an ordinary write failure.
|
|
413
|
+
if (abortWiring.cancelled()) {
|
|
414
|
+
logger.info(`${levelPrefix} LLM extraction cancelled by user before the prompt was written`);
|
|
415
|
+
cancel();
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
logger.warn(`${levelPrefix} Failed to write extraction prompt: ${err}`);
|
|
419
|
+
killChildSafely(proc, { logPrefix: levelPrefix });
|
|
420
|
+
settle({ success: false, error: `Failed to write prompt: ${err}` });
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (typeof stdin.end === 'function') {
|
|
426
|
+
stdin.end();
|
|
427
|
+
}
|
|
345
428
|
}
|
|
346
429
|
});
|
|
347
430
|
}
|
package/src/ai/stream-parser.js
CHANGED
|
@@ -267,6 +267,76 @@ function parseOpenCodeLine(line, options = {}) {
|
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
/**
|
|
271
|
+
* Parse a single Muse JSONL line into a normalized event.
|
|
272
|
+
* Returns null if the line should not be emitted.
|
|
273
|
+
*
|
|
274
|
+
* Muse wraps every record in an envelope; the discriminator is `payload_type`
|
|
275
|
+
* and the interesting fields live under `payload`:
|
|
276
|
+
* - run.output.delta (payload.text) → assistant_text
|
|
277
|
+
* - task.lifecycle.side_effect_intent with payload.event.operation === 'tool:<name>' → tool_use
|
|
278
|
+
* - everything else (run.lifecycle.*, task.lifecycle.{proposed,accepted,started,
|
|
279
|
+
* scheduled,status,completed,failed,rejected,output}, tool.result,
|
|
280
|
+
* run.model.configured, run.terminal.*) → filtered out
|
|
281
|
+
*
|
|
282
|
+
* Note: side_effect_intent also fires for `model.meta.response` (the model call
|
|
283
|
+
* itself, not a tool); only `tool:`-prefixed operations become tool_use events.
|
|
284
|
+
*
|
|
285
|
+
* @param {string} line - A single JSONL line from Muse stdout
|
|
286
|
+
* @param {Object} [options] - Parse options
|
|
287
|
+
* @param {string} [options.cwd] - Working directory to strip from file paths
|
|
288
|
+
* @returns {{ type: string, text: string, timestamp: number } | null}
|
|
289
|
+
*/
|
|
290
|
+
function parseMuseLine(line, options = {}) {
|
|
291
|
+
if (!line || !line.trim()) return null;
|
|
292
|
+
|
|
293
|
+
const { cwd } = options;
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
const event = JSON.parse(line);
|
|
297
|
+
const payloadType = event.payload_type;
|
|
298
|
+
const payload = event.payload || {};
|
|
299
|
+
|
|
300
|
+
if (payloadType === 'run.output.delta') {
|
|
301
|
+
const text = payload.text;
|
|
302
|
+
if (text && text.trim()) {
|
|
303
|
+
return {
|
|
304
|
+
type: 'assistant_text',
|
|
305
|
+
text: truncateSnippet(text),
|
|
306
|
+
timestamp: Date.now()
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (payloadType === 'task.lifecycle.side_effect_intent') {
|
|
313
|
+
const operation = payload.event?.operation || '';
|
|
314
|
+
if (!operation.startsWith('tool:')) return null;
|
|
315
|
+
|
|
316
|
+
const toolName = operation.slice('tool:'.length) || 'unknown';
|
|
317
|
+
// Muse's side_effect_intent record carries no tool arguments, so this
|
|
318
|
+
// resolves to '' today and the event shows the bare tool name. The lookup
|
|
319
|
+
// stays so a future muse release that adds arguments needs no code change.
|
|
320
|
+
const detail = extractToolDetail(
|
|
321
|
+
payload.event?.input || payload.event?.args || payload.event?.arguments,
|
|
322
|
+
cwd
|
|
323
|
+
);
|
|
324
|
+
const text = detail ? `${toolName}: ${detail}` : toolName;
|
|
325
|
+
return {
|
|
326
|
+
type: 'tool_use',
|
|
327
|
+
text: truncateSnippet(text),
|
|
328
|
+
timestamp: Date.now()
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return null;
|
|
333
|
+
} catch {
|
|
334
|
+
// Best-effort side channel — silently ignore non-JSON or malformed lines.
|
|
335
|
+
// The main stdout buffer handles authoritative response parsing.
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
270
340
|
/**
|
|
271
341
|
* Line-buffered stream parser that handles partial lines across chunks.
|
|
272
342
|
* Feeds data incrementally and calls onEvent for each parsed event.
|
|
@@ -586,6 +656,7 @@ module.exports = {
|
|
|
586
656
|
extractToolDetail,
|
|
587
657
|
parseClaudeLine,
|
|
588
658
|
parseCodexLine,
|
|
659
|
+
parseMuseLine,
|
|
589
660
|
parseOpenCodeLine,
|
|
590
661
|
parseCursorAgentLine,
|
|
591
662
|
parsePiLine,
|
package/src/config.js
CHANGED
|
@@ -54,6 +54,7 @@ const ALLOWED_FEATURE_VALUES = new Set(['graphql', 'rest', 'host']);
|
|
|
54
54
|
|
|
55
55
|
const CONFIG_DIR = path.join(os.homedir(), '.pair-review');
|
|
56
56
|
const DEFAULT_CHECKOUT_TIMEOUT_MS = 300000;
|
|
57
|
+
const DEFAULT_FETCH_TIMEOUT_MS = 300000;
|
|
57
58
|
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
58
59
|
const CONFIG_LOCAL_FILE = path.join(CONFIG_DIR, 'config.local.json');
|
|
59
60
|
const CONFIG_EXAMPLE_FILE = path.join(CONFIG_DIR, 'config.example.json');
|
|
@@ -66,7 +67,7 @@ const DEFAULT_CONFIG = {
|
|
|
66
67
|
port: 7247,
|
|
67
68
|
single_port: true, // When true, reuse a single server on the configured port; new invocations delegate to the running server
|
|
68
69
|
theme: "light",
|
|
69
|
-
default_provider: "claude", // AI provider: 'claude', 'antigravity', 'codex', 'copilot', 'opencode', 'cursor-agent', 'pi'
|
|
70
|
+
default_provider: "claude", // AI provider: 'claude', 'antigravity', 'codex', 'copilot', 'opencode', 'cursor-agent', 'pi', 'muse'
|
|
70
71
|
default_model: "opus", // Model within the provider (e.g., 'opus' for Claude, 'gemini-3.1-pro-low' for Antigravity)
|
|
71
72
|
tours: {
|
|
72
73
|
enabled: false, // When true, the guided-tour feature is available (toolbar button visible, etc.)
|
|
@@ -1400,6 +1401,30 @@ function getRepoCheckoutTimeout(config, repository) {
|
|
|
1400
1401
|
return DEFAULT_CHECKOUT_TIMEOUT_MS; // 5 minutes default
|
|
1401
1402
|
}
|
|
1402
1403
|
|
|
1404
|
+
/**
|
|
1405
|
+
* Gets the configured git fetch timeout for a repository.
|
|
1406
|
+
*
|
|
1407
|
+
* Scope: the BACKGROUND POOL fetch. Foreground worktree creation and refresh
|
|
1408
|
+
* issue targeted ref fetches and are not governed by this timeout.
|
|
1409
|
+
*
|
|
1410
|
+
* This is simple-git's `timeout.block` — an IDLE timeout: the child `git fetch`
|
|
1411
|
+
* is killed when it produces no output for this long, not when the total fetch
|
|
1412
|
+
* exceeds it. Large monorepos can be legitimately silent for minutes during
|
|
1413
|
+
* delta resolution, so raise this (or rely on `--progress`, which keeps output
|
|
1414
|
+
* flowing) when background pool fetches are being killed mid-pack.
|
|
1415
|
+
*
|
|
1416
|
+
* @param {Object} config - Configuration object from loadConfig()
|
|
1417
|
+
* @param {string} repository - Repository in "owner/repo" format
|
|
1418
|
+
* @returns {number} - Timeout in milliseconds (default: 300000 = 5 minutes)
|
|
1419
|
+
*/
|
|
1420
|
+
function getRepoFetchTimeout(config, repository) {
|
|
1421
|
+
const repoConfig = getRepoConfig(config, repository);
|
|
1422
|
+
if (repoConfig?.fetch_timeout_seconds > 0) {
|
|
1423
|
+
return repoConfig.fetch_timeout_seconds * 1000;
|
|
1424
|
+
}
|
|
1425
|
+
return DEFAULT_FETCH_TIMEOUT_MS; // 5 minutes default
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1403
1428
|
/**
|
|
1404
1429
|
* Gets the configured reset script for a repository
|
|
1405
1430
|
* @param {Object} config - Configuration object from loadConfig()
|
|
@@ -1412,7 +1437,13 @@ function getRepoResetScript(config, repository) {
|
|
|
1412
1437
|
}
|
|
1413
1438
|
|
|
1414
1439
|
/**
|
|
1415
|
-
* Gets whether
|
|
1440
|
+
* Gets whether bulk `git fetch <remote> --prune` should be skipped for a repo.
|
|
1441
|
+
*
|
|
1442
|
+
* Applies to the periodic background fetch over pool worktrees, which is
|
|
1443
|
+
* entirely disabled for the repo when this is set. The foreground refresh
|
|
1444
|
+
* path no longer performs bulk fetches for any repo (it uses targeted
|
|
1445
|
+
* refspec fetches), so this flag does not affect it.
|
|
1446
|
+
*
|
|
1416
1447
|
* @param {Object} config - Configuration object from loadConfig()
|
|
1417
1448
|
* @param {string} repository - Repository in "owner/repo" format
|
|
1418
1449
|
* @returns {boolean} - true if the bulk fetch should be skipped (default: false)
|
|
@@ -1668,6 +1699,7 @@ module.exports = {
|
|
|
1668
1699
|
getRepoWorktreeNameTemplate,
|
|
1669
1700
|
getWorktreeDisplayName,
|
|
1670
1701
|
getRepoCheckoutTimeout,
|
|
1702
|
+
getRepoFetchTimeout,
|
|
1671
1703
|
resolveRepoOptions,
|
|
1672
1704
|
getRepoResetScript,
|
|
1673
1705
|
getRepoSkipBulkFetch,
|
|
@@ -1682,6 +1714,7 @@ module.exports = {
|
|
|
1682
1714
|
shouldSkipUpdateNotifier,
|
|
1683
1715
|
_resetTokenCache,
|
|
1684
1716
|
DEFAULT_CHECKOUT_TIMEOUT_MS,
|
|
1717
|
+
DEFAULT_FETCH_TIMEOUT_MS,
|
|
1685
1718
|
// Canonical lists for per-area feature dispatch. Exported so tests
|
|
1686
1719
|
// (and `src/github/client.js`'s `DEFAULT_FEATURES`) can assert against
|
|
1687
1720
|
// a single source of truth.
|