fix: fix bugs in core modules
- tty: fix isStdoutTTY to use fstat first, fall back to TERM heuristic - git: fix commit regex to handle root-commit output format - git: fix parseNameStatus to handle edge cases (empty lines, missing tabs) - ai: fix readStream to cancel reader instead of releaseLock - cli: remove dead code resolveFlagName function - clipboard: fix inconsistent indentation Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -123,7 +123,6 @@ async function readStream(body: ReadableStream<Uint8Array>, callbacks: StreamCal
|
||||
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
const lines = buffer.split("\n");
|
||||
// Keep the last potentially incomplete line
|
||||
buffer = lines.pop() ?? "";
|
||||
|
||||
for (const line of lines) {
|
||||
@@ -136,7 +135,12 @@ async function readStream(body: ReadableStream<Uint8Array>, callbacks: StreamCal
|
||||
try {
|
||||
const parsed = JSON.parse(data) as {
|
||||
choices?: Array<{ delta?: { content?: string }; finish_reason?: string }>;
|
||||
error?: { message?: string };
|
||||
};
|
||||
if (parsed.error) {
|
||||
callbacks.onError?.(new Error(`Stream error: ${parsed.error.message ?? "unknown"}`));
|
||||
continue;
|
||||
}
|
||||
const token = parsed.choices?.[0]?.delta?.content;
|
||||
if (token) {
|
||||
fullText += token;
|
||||
@@ -152,7 +156,8 @@ async function readStream(body: ReadableStream<Uint8Array>, callbacks: StreamCal
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
reader.releaseLock();
|
||||
try { await reader.cancel(); } catch {}
|
||||
// releaseLock is not needed after cancel
|
||||
}
|
||||
|
||||
callbacks.onDone?.(fullText);
|
||||
|
||||
Reference in New Issue
Block a user