preserve thinking delta whitespace in runlog streaming
This commit is contained in:
@@ -218,11 +218,13 @@ export function parseCursorStdoutLine(line: string, ts: string): TranscriptEntry
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type === "thinking") {
|
if (type === "thinking") {
|
||||||
const text = asString(parsed.text).trim() || asString(asRecord(parsed.delta)?.text).trim();
|
const textFromTopLevel = asString(parsed.text);
|
||||||
|
const textFromDelta = asString(asRecord(parsed.delta)?.text);
|
||||||
|
const text = textFromTopLevel.length > 0 ? textFromTopLevel : textFromDelta;
|
||||||
const subtype = asString(parsed.subtype).trim().toLowerCase();
|
const subtype = asString(parsed.subtype).trim().toLowerCase();
|
||||||
const isDelta = subtype === "delta" || asRecord(parsed.delta) !== null;
|
const isDelta = subtype === "delta" || asRecord(parsed.delta) !== null;
|
||||||
if (!text) return [];
|
if (!text.trim()) return [];
|
||||||
return [{ kind: "thinking", ts, text, ...(isDelta ? { delta: true } : {}) }];
|
return [{ kind: "thinking", ts, text: isDelta ? text : text.trim(), ...(isDelta ? { delta: true } : {}) }];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "tool_call") {
|
if (type === "tool_call") {
|
||||||
|
|||||||
@@ -164,6 +164,17 @@ describe("cursor ui stdout parser", () => {
|
|||||||
),
|
),
|
||||||
).toEqual([{ kind: "thinking", ts, text: "planning next command", delta: true }]);
|
).toEqual([{ kind: "thinking", ts, text: "planning next command", delta: true }]);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
parseCursorStdoutLine(
|
||||||
|
JSON.stringify({
|
||||||
|
type: "thinking",
|
||||||
|
subtype: "delta",
|
||||||
|
text: " with preserved leading space",
|
||||||
|
}),
|
||||||
|
ts,
|
||||||
|
),
|
||||||
|
).toEqual([{ kind: "thinking", ts, text: " with preserved leading space", delta: true }]);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
parseCursorStdoutLine(
|
parseCursorStdoutLine(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
|||||||
@@ -100,8 +100,8 @@ function parseStdoutChunk(
|
|||||||
const summarized: Array<{ text: string; tone: FeedTone; thinkingDelta?: boolean }> = [];
|
const summarized: Array<{ text: string; tone: FeedTone; thinkingDelta?: boolean }> = [];
|
||||||
const appendSummary = (entry: TranscriptEntry) => {
|
const appendSummary = (entry: TranscriptEntry) => {
|
||||||
if (entry.kind === "thinking" && entry.delta) {
|
if (entry.kind === "thinking" && entry.delta) {
|
||||||
const text = entry.text.trim();
|
const text = entry.text;
|
||||||
if (!text) return;
|
if (!text.trim()) return;
|
||||||
const last = summarized[summarized.length - 1];
|
const last = summarized[summarized.length - 1];
|
||||||
if (last && last.thinkingDelta) {
|
if (last && last.thinkingDelta) {
|
||||||
last.text += text;
|
last.text += text;
|
||||||
|
|||||||
@@ -111,8 +111,8 @@ function parseStdoutChunk(
|
|||||||
const summarized: Array<{ text: string; tone: FeedTone; thinkingDelta?: boolean }> = [];
|
const summarized: Array<{ text: string; tone: FeedTone; thinkingDelta?: boolean }> = [];
|
||||||
const appendSummary = (entry: TranscriptEntry) => {
|
const appendSummary = (entry: TranscriptEntry) => {
|
||||||
if (entry.kind === "thinking" && entry.delta) {
|
if (entry.kind === "thinking" && entry.delta) {
|
||||||
const text = entry.text.trim();
|
const text = entry.text;
|
||||||
if (!text) return;
|
if (!text.trim()) return;
|
||||||
const last = summarized[summarized.length - 1];
|
const last = summarized[summarized.length - 1];
|
||||||
if (last && last.thinkingDelta) {
|
if (last && last.thinkingDelta) {
|
||||||
last.text += text;
|
last.text += text;
|
||||||
|
|||||||
Reference in New Issue
Block a user