mirror of
https://github.com/fancive/obsidian-parallel-reader.git
synced 2026-07-22 06:53:43 +00:00
fix: parse Claude Code JSON array output and drop --model flag
Claude Code `--output-format json` returns a JSON array of event objects, not a single object. Parse the array and extract the result event. Also stop passing --model to let Claude Code use its own default model. Revert timeout to 120s. Change-Id: I5b5d4aa589ff78c0a2806a3e700bac0676a9b354
This commit is contained in:
parent
625ac4e5fe
commit
38ba0acdb2
3 changed files with 25 additions and 12 deletions
7
main.js
7
main.js
File diff suppressed because one or more lines are too long
28
src/cli.ts
28
src/cli.ts
|
|
@ -165,18 +165,30 @@ export async function summarizeViaClaudeCode(
|
|||
'--disallowed-tools',
|
||||
'Bash,Read,Write,Edit,Glob,Grep,WebFetch,WebSearch,TodoWrite,Task',
|
||||
];
|
||||
if (settings.model) {
|
||||
args.push('--model', settings.model);
|
||||
}
|
||||
const { stdout } = await runCli(cmd, args, user, settings.cliTimeoutMs, job);
|
||||
|
||||
let envelope;
|
||||
// --output-format json produces a JSON array of event objects.
|
||||
// Find the "result" entry and extract its .result text field.
|
||||
let resultText = '';
|
||||
try {
|
||||
envelope = JSON.parse(stdout);
|
||||
} catch (_e) {
|
||||
throw new Error('claude CLI returned a non-JSON envelope:\n' + stdout.slice(0, 500));
|
||||
const events = JSON.parse(stdout);
|
||||
if (Array.isArray(events)) {
|
||||
const resultEvent = events.find((e: Record<string, unknown>) => e.type === 'result');
|
||||
if (resultEvent && typeof resultEvent.result === 'string') {
|
||||
resultText = resultEvent.result;
|
||||
}
|
||||
} else if (events && typeof events === 'object') {
|
||||
// Older CLI versions return a single object
|
||||
resultText = events.result || events.content || '';
|
||||
}
|
||||
} catch (_) {
|
||||
throw new Error('claude CLI returned unexpected output:\n' + stdout.slice(0, 500));
|
||||
}
|
||||
const resultText = envelope.result || envelope.content || '';
|
||||
|
||||
if (!resultText) {
|
||||
throw new Error('claude CLI returned no result. Output:\n' + stdout.slice(0, 500));
|
||||
}
|
||||
|
||||
return parseCardsJson(resultText, settings);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export const DEFAULT_SETTINGS: PluginSettings = {
|
|||
customSystemPrompt: '',
|
||||
model: 'claude-sonnet-4-6',
|
||||
exportFolder: 'Reading/Articles',
|
||||
cliTimeoutMs: 300000,
|
||||
cliTimeoutMs: 120000,
|
||||
streaming: true,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue