kovence-cli 1.2.0 → 1.3.1
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/CHANGELOG.md +43 -0
- package/README.md +66 -6
- package/nd.js +22 -1
- package/package.json +1 -1
- package/providers.js +524 -113
- package/src/agent/history.js +502 -9
- package/src/agent/project_context.js +219 -24
- package/src/agent/request_logger.js +148 -0
- package/src/agent/resilience.js +296 -46
- package/src/agent/streaming_write.js +23 -15
- package/src/agent/subagent.js +655 -0
- package/src/agent/turn.js +1211 -269
- package/src/cli/args.js +9 -1
- package/src/cli/sinks.js +193 -106
- package/src/commands/handlers.js +245 -7
- package/src/config/model_registry.js +39 -2
- package/src/config/sessions.js +19 -2
- package/src/config/skills.js +425 -0
- package/src/permissions/engine.js +22 -6
- package/src/permissions/store.js +4 -1
- package/src/settings/schema.js +298 -9
- package/src/settings/store.js +75 -6
- package/src/tools/browser.js +722 -0
- package/src/tools/edit.js +471 -0
- package/src/tools/exec.js +349 -34
- package/src/tools/patch_git.js +12 -1
- package/src/tools/read_tracker.js +87 -0
- package/src/tools/tasks.js +68 -28
- package/tools.js +784 -171
- package/tui.js +142 -30
- package/ui.js +22 -1
package/src/cli/args.js
CHANGED
|
@@ -26,6 +26,7 @@ function parseArgs(argv) {
|
|
|
26
26
|
json: false,
|
|
27
27
|
noSession: false,
|
|
28
28
|
debug: false,
|
|
29
|
+
logRequests: "",
|
|
29
30
|
doctor: false,
|
|
30
31
|
help: false,
|
|
31
32
|
version: false,
|
|
@@ -100,6 +101,9 @@ function parseArgs(argv) {
|
|
|
100
101
|
} else if (a === "--new-session") {
|
|
101
102
|
opts.newSession = takeValue(i, a);
|
|
102
103
|
i++;
|
|
104
|
+
} else if (a === "--log-requests") {
|
|
105
|
+
opts.logRequests = takeValue(i, a);
|
|
106
|
+
i++;
|
|
103
107
|
} else if (a.startsWith("-")) {
|
|
104
108
|
throw new Error(`Unknown option '${a}'. Run with --help to see supported flags.`);
|
|
105
109
|
} else {
|
|
@@ -132,6 +136,7 @@ CLI Options:
|
|
|
132
136
|
--json Emit structured JSON result in -p headless mode
|
|
133
137
|
--no-session Run without persisting session history to disk
|
|
134
138
|
--debug Enable verbose debug tracing
|
|
139
|
+
--log-requests <file> Write scrubbed outgoing request bodies as JSONL
|
|
135
140
|
doctor Run environment, tools & provider connectivity checks
|
|
136
141
|
-t, --temp <num> Sampling temperature (0.0-2.0)
|
|
137
142
|
--max-tokens <num> Max completion tokens
|
|
@@ -147,7 +152,10 @@ Harness Commands:
|
|
|
147
152
|
/settings Open interactive Settings panel (Ctrl+,)
|
|
148
153
|
/set <key> <value> Update persisted setting directly
|
|
149
154
|
/api [subcmd] Open provider picker or list/add/use/rm
|
|
150
|
-
/model [name] Open model picker or switch & save model
|
|
155
|
+
/model [name] Open model & reasoning picker or switch & save model
|
|
156
|
+
/reasoning [level] Pick reasoning level (off|low|medium|high)
|
|
157
|
+
/skills [subcmd] Manage markdown skills (list|add <file>|show|rm)
|
|
158
|
+
/browser [subcmd] Manage headless Playwright runtime (status|install|close)
|
|
151
159
|
/sessions [subcmd] Open session picker (Ctrl+S) or list/new/switch/delete
|
|
152
160
|
/new [name] Create fresh isolated session (Ctrl+N)
|
|
153
161
|
/save <name> Rename and save current session
|
package/src/cli/sinks.js
CHANGED
|
@@ -86,6 +86,29 @@ function createPlainSink(interactive, { headless = false, jsonMode = false } = {
|
|
|
86
86
|
confirm: (label) => (interactive ? promptConfirm(`${C.yellow}${label}${C.reset}`) : Promise.resolve("n")),
|
|
87
87
|
askPrompt: (label) => (interactive ? promptLine(label, []) : Promise.resolve("")),
|
|
88
88
|
askPassword: interactive ? (label) => promptSecret(label) : null,
|
|
89
|
+
async openMultiChoicePicker(title, items = []) {
|
|
90
|
+
if (!interactive || !items.length) return [];
|
|
91
|
+
const selectable = items.filter((x) => x.type !== "header" && x.type !== "skip");
|
|
92
|
+
if (!selectable.length) return [];
|
|
93
|
+
console.log(`\n${C.bold}${C.cyan}${title}${C.reset}`);
|
|
94
|
+
selectable.forEach((it, idx) => {
|
|
95
|
+
console.log(` ${idx + 1}. ${it.label}${it.desc ? ` — ${C.dim}${it.desc}${C.reset}` : ""}`);
|
|
96
|
+
});
|
|
97
|
+
const ans = (await promptLine("Select skill(s) (e.g. 1,2 or 'all', Enter to skip): ", []))
|
|
98
|
+
.trim()
|
|
99
|
+
.toLowerCase();
|
|
100
|
+
if (!ans || ans === "skip" || ans === "none" || ans === "0") return [];
|
|
101
|
+
if (ans === "all" || ans === "*") return selectable.map((x) => x.id);
|
|
102
|
+
const chosen = [];
|
|
103
|
+
for (const part of ans.split(/[\s,]+/)) {
|
|
104
|
+
const n = Number.parseInt(part, 10);
|
|
105
|
+
if (Number.isInteger(n) && n >= 1 && n <= selectable.length) {
|
|
106
|
+
const id = selectable[n - 1].id;
|
|
107
|
+
if (!chosen.includes(id)) chosen.push(id);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return chosen;
|
|
111
|
+
},
|
|
89
112
|
startProgress(initialText = "") {
|
|
90
113
|
if (jsonMode || headless || !process.stdout.isTTY) {
|
|
91
114
|
return { update() {}, done() {} };
|
|
@@ -161,6 +184,7 @@ function createTuiSink(tui, state) {
|
|
|
161
184
|
model: state.model,
|
|
162
185
|
ctxText: getContextLabel(state),
|
|
163
186
|
agentMode: state.settings.agentMode,
|
|
187
|
+
reasoning: state.settings.reasoning || "off",
|
|
164
188
|
colorScheme: state.settings.colorScheme || "amber",
|
|
165
189
|
tools: state.settings.toolsEnabled,
|
|
166
190
|
auto: state.settings.agentMode === "auto",
|
|
@@ -248,6 +272,18 @@ function createTuiSink(tui, state) {
|
|
|
248
272
|
});
|
|
249
273
|
return res?.action === "select" ? res.item?.id || "" : "";
|
|
250
274
|
},
|
|
275
|
+
async openMultiChoicePicker(title, items, preselectedIds = []) {
|
|
276
|
+
if (!items || !items.length) return [];
|
|
277
|
+
const res = await tui.openPicker(title, items, {
|
|
278
|
+
initialIdx: 0,
|
|
279
|
+
multiSelect: true,
|
|
280
|
+
selectedIds: new Set(preselectedIds),
|
|
281
|
+
hint: "↑/↓ move · Space toggle [✓] · a all · Enter apply · Esc skip",
|
|
282
|
+
});
|
|
283
|
+
if (res?.action === "multi") return Array.isArray(res.ids) ? res.ids : [];
|
|
284
|
+
if (res?.action === "select" && res.item?.id && res.item.type !== "skip") return [res.item.id];
|
|
285
|
+
return [];
|
|
286
|
+
},
|
|
251
287
|
async openModePicker(currentMode) {
|
|
252
288
|
const modeMeta = [
|
|
253
289
|
{ id: "default", desc: "Ask confirmation for file edits, downloads & commands" },
|
|
@@ -354,6 +390,7 @@ function createTuiSink(tui, state) {
|
|
|
354
390
|
totalLines: lines.length,
|
|
355
391
|
totalChars: content.length,
|
|
356
392
|
startTime: Date.now(),
|
|
393
|
+
firstChunkAt: null,
|
|
357
394
|
// 5-line rolling preview (last 5 non-blank lines)
|
|
358
395
|
previewLines: lines.filter((l) => l.trim()).slice(-5),
|
|
359
396
|
done: false,
|
|
@@ -395,7 +432,10 @@ function createTuiSink(tui, state) {
|
|
|
395
432
|
},
|
|
396
433
|
finish(fullOutputText = "", isError = false) {
|
|
397
434
|
// Mark write as done so animation stops.
|
|
398
|
-
if (block.writeStats)
|
|
435
|
+
if (block.writeStats) {
|
|
436
|
+
block.writeStats.done = true;
|
|
437
|
+
block.writeStats.doneAt = Date.now();
|
|
438
|
+
}
|
|
399
439
|
if (!details.length && fullOutputText) {
|
|
400
440
|
const fallbackLines = String(fullOutputText)
|
|
401
441
|
.split(/\r?\n/)
|
|
@@ -411,6 +451,44 @@ function createTuiSink(tui, state) {
|
|
|
411
451
|
},
|
|
412
452
|
};
|
|
413
453
|
},
|
|
454
|
+
startSubagent({ agent = "explore", description = "task" } = {}) {
|
|
455
|
+
const baseLabel = `task(${agent}): ${description}`;
|
|
456
|
+
const block = tui.addBlock("tool", baseLabel, {
|
|
457
|
+
collapsible: true,
|
|
458
|
+
expanded: false,
|
|
459
|
+
details: [],
|
|
460
|
+
statusLine: "starting...",
|
|
461
|
+
});
|
|
462
|
+
let lastRenderAt = 0;
|
|
463
|
+
const formatStatus = (toolCalls, elapsedMs, suffix = "") => {
|
|
464
|
+
const sec = Math.max(0, Math.round((elapsedMs || 0) / 1000));
|
|
465
|
+
const base = `${baseLabel} - ${toolCalls || 0} tool calls - ${sec}s`;
|
|
466
|
+
return suffix ? `${base} (${suffix})` : base;
|
|
467
|
+
};
|
|
468
|
+
return {
|
|
469
|
+
update({ toolCalls = 0, elapsedMs = 0 } = {}) {
|
|
470
|
+
const now = Date.now();
|
|
471
|
+
if (now - lastRenderAt < 250) return;
|
|
472
|
+
lastRenderAt = now;
|
|
473
|
+
const text = formatStatus(toolCalls, elapsedMs);
|
|
474
|
+
block.text = text;
|
|
475
|
+
block.statusLine = `${toolCalls} tool calls · ${Math.round(elapsedMs / 1000)}s`;
|
|
476
|
+
block._cache = null;
|
|
477
|
+
tui.scheduleRender();
|
|
478
|
+
},
|
|
479
|
+
finish({ ok = true, toolCalls = 0, elapsedMs = 0, error = "" } = {}) {
|
|
480
|
+
const text = formatStatus(toolCalls, elapsedMs, ok ? "done" : error || "failed");
|
|
481
|
+
block.text = `${ok ? "✓" : "✗"} ${text}`;
|
|
482
|
+
block.statusLine = ok ? "done" : error || "failed";
|
|
483
|
+
block._cache = null;
|
|
484
|
+
tui.setBlockDetails(
|
|
485
|
+
block,
|
|
486
|
+
ok ? [`Completed in ${(elapsedMs / 1000).toFixed(1)}s`] : [String(error)],
|
|
487
|
+
block.statusLine
|
|
488
|
+
);
|
|
489
|
+
},
|
|
490
|
+
};
|
|
491
|
+
},
|
|
414
492
|
/**
|
|
415
493
|
* Called by providers.js as soon as the file path is known during LLM streaming.
|
|
416
494
|
* Creates target directory and file beforehand, registers checkpoint, and pre-registers TUI block.
|
|
@@ -420,7 +498,7 @@ function createTuiSink(tui, state) {
|
|
|
420
498
|
*/
|
|
421
499
|
preRegisterWriteBlock(toolIdx, toolName, filePath) {
|
|
422
500
|
let entry = streamWriteBlocks.get(toolIdx);
|
|
423
|
-
if (entry?.preRegistered && entry.filePath === filePath) return;
|
|
501
|
+
if (entry?.preRegistered && entry.filePath === filePath && !entry.block?.writeStats?.done) return;
|
|
424
502
|
|
|
425
503
|
const workspaceRoot = state.workspaceRoot || process.cwd();
|
|
426
504
|
const absPath = filePath
|
|
@@ -430,7 +508,10 @@ function createTuiSink(tui, state) {
|
|
|
430
508
|
: "";
|
|
431
509
|
|
|
432
510
|
let fileCreated = false;
|
|
433
|
-
|
|
511
|
+
const blockedByReadTracker = Boolean(
|
|
512
|
+
absPath && fs.existsSync(absPath) && state.readTracker && !state.readTracker.isFresh(absPath)
|
|
513
|
+
);
|
|
514
|
+
if (toolName === "write_file" && state.settings?.agentMode !== "plan" && absPath && !blockedByReadTracker) {
|
|
434
515
|
try {
|
|
435
516
|
const targetDir = path.dirname(absPath);
|
|
436
517
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
@@ -450,14 +531,21 @@ function createTuiSink(tui, state) {
|
|
|
450
531
|
|
|
451
532
|
fs.writeFileSync(absPath, "", "utf8");
|
|
452
533
|
fileCreated = true;
|
|
534
|
+
if (!state.streamActiveWriteFiles) state.streamActiveWriteFiles = new Set();
|
|
535
|
+
state.streamActiveWriteFiles.add(absPath);
|
|
453
536
|
} catch {}
|
|
454
537
|
}
|
|
455
538
|
|
|
456
|
-
const fname = filePath ? filePath.replace(/\\/g, "/").split("/").pop() : "
|
|
539
|
+
const fname = filePath ? filePath.replace(/\\/g, "/").split("/").pop() : "...";
|
|
457
540
|
const label = `⚙ ${toolName}(${fname})`;
|
|
458
541
|
const dir = filePath ? filePath.replace(/\\/g, "/").split("/").slice(0, -1).join("/") || "." : "";
|
|
459
542
|
|
|
460
|
-
|
|
543
|
+
const shouldCreateFresh =
|
|
544
|
+
!entry ||
|
|
545
|
+
Boolean(entry.block?.writeStats?.done) ||
|
|
546
|
+
Boolean(entry.filePath && filePath && entry.filePath !== filePath);
|
|
547
|
+
|
|
548
|
+
if (shouldCreateFresh) {
|
|
461
549
|
const rawBlock = {
|
|
462
550
|
kind: "tool",
|
|
463
551
|
text: label,
|
|
@@ -474,6 +562,7 @@ function createTuiSink(tui, state) {
|
|
|
474
562
|
totalLines: 0,
|
|
475
563
|
totalChars: 0,
|
|
476
564
|
startTime: Date.now(),
|
|
565
|
+
firstChunkAt: null,
|
|
477
566
|
lineBuf: "",
|
|
478
567
|
previewLines: [],
|
|
479
568
|
done: false,
|
|
@@ -493,71 +582,43 @@ function createTuiSink(tui, state) {
|
|
|
493
582
|
absPath,
|
|
494
583
|
preRegistered: true,
|
|
495
584
|
fileCreated,
|
|
585
|
+
pendingDiskChunks: [],
|
|
496
586
|
});
|
|
497
587
|
} else {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
if (
|
|
503
|
-
|
|
504
|
-
const rawBlock = {
|
|
505
|
-
kind: "tool",
|
|
506
|
-
text: label,
|
|
507
|
-
collapsible: true,
|
|
508
|
-
expanded: false,
|
|
509
|
-
details: [],
|
|
510
|
-
statusLine: "writing...",
|
|
511
|
-
_ver: 1,
|
|
512
|
-
_cache: null,
|
|
513
|
-
};
|
|
514
|
-
rawBlock.writeStats = {
|
|
588
|
+
entry.filePath = filePath || entry.filePath;
|
|
589
|
+
entry.absPath = absPath || entry.absPath;
|
|
590
|
+
entry.fileCreated = fileCreated || entry.fileCreated;
|
|
591
|
+
if (filePath) entry.block.text = label;
|
|
592
|
+
if (!entry.block.writeStats) {
|
|
593
|
+
entry.block.writeStats = {
|
|
515
594
|
filePath: String(filePath || ""),
|
|
516
595
|
dir: String(dir),
|
|
517
596
|
totalLines: 0,
|
|
518
597
|
totalChars: 0,
|
|
519
598
|
startTime: Date.now(),
|
|
599
|
+
firstChunkAt: null,
|
|
520
600
|
lineBuf: "",
|
|
521
601
|
previewLines: [],
|
|
522
602
|
done: false,
|
|
523
603
|
};
|
|
524
|
-
let insertAt = tui.blocks.length;
|
|
525
|
-
for (let i = tui.blocks.length - 1; i >= 0; i--) {
|
|
526
|
-
if (tui.blocks[i].kind === "thinking") {
|
|
527
|
-
insertAt = i + 1;
|
|
528
|
-
break;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
tui.blocks.splice(insertAt, 0, rawBlock);
|
|
532
|
-
streamWriteBlocks.set(toolIdx, {
|
|
533
|
-
block: rawBlock,
|
|
534
|
-
toolName,
|
|
535
|
-
filePath,
|
|
536
|
-
absPath,
|
|
537
|
-
preRegistered: true,
|
|
538
|
-
fileCreated,
|
|
539
|
-
});
|
|
540
604
|
} else {
|
|
541
|
-
entry.filePath = filePath;
|
|
542
|
-
entry.
|
|
543
|
-
entry.fileCreated = fileCreated || entry.fileCreated;
|
|
544
|
-
entry.block.text = label;
|
|
545
|
-
if (!entry.block.writeStats) {
|
|
546
|
-
entry.block.writeStats = {
|
|
547
|
-
filePath: String(filePath || ""),
|
|
548
|
-
dir: String(dir),
|
|
549
|
-
totalLines: 0,
|
|
550
|
-
totalChars: 0,
|
|
551
|
-
startTime: Date.now(),
|
|
552
|
-
previewLines: [],
|
|
553
|
-
done: false,
|
|
554
|
-
};
|
|
555
|
-
} else {
|
|
556
|
-
entry.block.writeStats.filePath = String(filePath || entry.block.writeStats.filePath || "");
|
|
557
|
-
entry.block.writeStats.dir = String(dir || entry.block.writeStats.dir || "");
|
|
558
|
-
}
|
|
559
|
-
entry.block._cache = null;
|
|
605
|
+
entry.block.writeStats.filePath = String(filePath || entry.block.writeStats.filePath || "");
|
|
606
|
+
entry.block.writeStats.dir = String(dir || entry.block.writeStats.dir || "");
|
|
560
607
|
}
|
|
608
|
+
// Backfill any content chunks streamed before `path` arrived
|
|
609
|
+
if (
|
|
610
|
+
entry.fileCreated &&
|
|
611
|
+
entry.absPath &&
|
|
612
|
+
Array.isArray(entry.pendingDiskChunks) &&
|
|
613
|
+
entry.pendingDiskChunks.length > 0
|
|
614
|
+
) {
|
|
615
|
+
try {
|
|
616
|
+
fs.appendFileSync(entry.absPath, entry.pendingDiskChunks.join(""), "utf8");
|
|
617
|
+
entry.pendingDiskChunks = [];
|
|
618
|
+
} catch {}
|
|
619
|
+
}
|
|
620
|
+
entry.block._ver = (entry.block._ver || 0) + 1;
|
|
621
|
+
entry.block._cache = null;
|
|
561
622
|
}
|
|
562
623
|
tui.scheduleRender();
|
|
563
624
|
},
|
|
@@ -571,22 +632,16 @@ function createTuiSink(tui, state) {
|
|
|
571
632
|
*/
|
|
572
633
|
onWriteStreamChunk(toolIdx, toolName, filePath, unescapedChunk) {
|
|
573
634
|
let entry = streamWriteBlocks.get(toolIdx);
|
|
574
|
-
//
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
635
|
+
// Create block IMMEDIATELY even when content arrives before `path` (filePath === "")
|
|
636
|
+
if (
|
|
637
|
+
!entry ||
|
|
638
|
+
(filePath && entry.filePath && entry.filePath !== filePath) ||
|
|
639
|
+
entry.block?.writeStats?.done
|
|
640
|
+
) {
|
|
641
|
+
this.preRegisterWriteBlock(toolIdx, toolName, filePath || "");
|
|
578
642
|
entry = streamWriteBlocks.get(toolIdx);
|
|
579
643
|
}
|
|
580
|
-
if (!entry
|
|
581
|
-
this.preRegisterWriteBlock(toolIdx, toolName, filePath);
|
|
582
|
-
entry = streamWriteBlocks.get(toolIdx);
|
|
583
|
-
}
|
|
584
|
-
if (!entry) {
|
|
585
|
-
const pending = streamWriteBlocks.get(`pending-${toolIdx}`) || { chunks: [], path: filePath, toolName };
|
|
586
|
-
pending.chunks.push(unescapedChunk);
|
|
587
|
-
streamWriteBlocks.set(`pending-${toolIdx}`, pending);
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
644
|
+
if (!entry) return;
|
|
590
645
|
|
|
591
646
|
const { block } = entry;
|
|
592
647
|
const workspaceRoot = state.workspaceRoot || process.cwd();
|
|
@@ -595,45 +650,63 @@ function createTuiSink(tui, state) {
|
|
|
595
650
|
(filePath ? (path.isAbsolute(filePath) ? filePath : path.resolve(workspaceRoot, filePath)) : "");
|
|
596
651
|
|
|
597
652
|
// If write_file, ensure created in directory and dynamically append token chunks to the file
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
paths: state.paths,
|
|
611
|
-
});
|
|
612
|
-
state.streamCheckpointed.add(absPath);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
fs.writeFileSync(absPath, "", "utf8");
|
|
616
|
-
entry.fileCreated = true;
|
|
617
|
-
entry.absPath = absPath;
|
|
618
|
-
}
|
|
619
|
-
// Retry append once on transient FS errors (ENOENT, EBUSY, EMFILE)
|
|
653
|
+
const blockedByReadTracker = Boolean(
|
|
654
|
+
absPath &&
|
|
655
|
+
!entry.fileCreated &&
|
|
656
|
+
fs.existsSync(absPath) &&
|
|
657
|
+
state.readTracker &&
|
|
658
|
+
!state.readTracker.isFresh(absPath)
|
|
659
|
+
);
|
|
660
|
+
if (toolName === "write_file" && state.settings?.agentMode !== "plan" && !blockedByReadTracker) {
|
|
661
|
+
if (!absPath) {
|
|
662
|
+
if (!Array.isArray(entry.pendingDiskChunks)) entry.pendingDiskChunks = [];
|
|
663
|
+
entry.pendingDiskChunks.push(unescapedChunk);
|
|
664
|
+
} else {
|
|
620
665
|
try {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
if (!
|
|
627
|
-
|
|
628
|
-
|
|
666
|
+
if (!entry.fileCreated) {
|
|
667
|
+
const targetDir = path.dirname(absPath);
|
|
668
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
669
|
+
if (state.paths) {
|
|
670
|
+
if (!state.streamCheckpointed) state.streamCheckpointed = new Set();
|
|
671
|
+
if (!state.streamCheckpointed.has(absPath)) {
|
|
672
|
+
recordCheckpoint({
|
|
673
|
+
sessionId: state.session?.id || "default",
|
|
674
|
+
toolName: "write_file",
|
|
675
|
+
filePaths: [absPath],
|
|
676
|
+
paths: state.paths,
|
|
677
|
+
});
|
|
678
|
+
state.streamCheckpointed.add(absPath);
|
|
629
679
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
680
|
+
}
|
|
681
|
+
fs.writeFileSync(absPath, "", "utf8");
|
|
682
|
+
entry.fileCreated = true;
|
|
683
|
+
entry.absPath = absPath;
|
|
684
|
+
if (!state.streamActiveWriteFiles) state.streamActiveWriteFiles = new Set();
|
|
685
|
+
state.streamActiveWriteFiles.add(absPath);
|
|
686
|
+
if (Array.isArray(entry.pendingDiskChunks) && entry.pendingDiskChunks.length > 0) {
|
|
687
|
+
fs.appendFileSync(absPath, entry.pendingDiskChunks.join(""), "utf8");
|
|
688
|
+
entry.pendingDiskChunks = [];
|
|
633
689
|
}
|
|
634
690
|
}
|
|
635
|
-
|
|
636
|
-
|
|
691
|
+
try {
|
|
692
|
+
fs.appendFileSync(absPath, unescapedChunk, "utf8");
|
|
693
|
+
} catch (appendErr) {
|
|
694
|
+
if (
|
|
695
|
+
appendErr.code === "ENOENT" ||
|
|
696
|
+
appendErr.code === "EBUSY" ||
|
|
697
|
+
appendErr.code === "EMFILE"
|
|
698
|
+
) {
|
|
699
|
+
try {
|
|
700
|
+
if (!fs.existsSync(absPath)) {
|
|
701
|
+
fs.mkdirSync(path.dirname(absPath), { recursive: true });
|
|
702
|
+
fs.writeFileSync(absPath, "", "utf8");
|
|
703
|
+
}
|
|
704
|
+
fs.appendFileSync(absPath, unescapedChunk, "utf8");
|
|
705
|
+
} catch {}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
} catch {}
|
|
709
|
+
}
|
|
637
710
|
}
|
|
638
711
|
|
|
639
712
|
if (!block.writeStats) {
|
|
@@ -643,6 +716,7 @@ function createTuiSink(tui, state) {
|
|
|
643
716
|
totalLines: 0,
|
|
644
717
|
totalChars: 0,
|
|
645
718
|
startTime: Date.now(),
|
|
719
|
+
firstChunkAt: null,
|
|
646
720
|
lineBuf: "",
|
|
647
721
|
previewLines: [],
|
|
648
722
|
done: false,
|
|
@@ -651,6 +725,9 @@ function createTuiSink(tui, state) {
|
|
|
651
725
|
const ws = block.writeStats;
|
|
652
726
|
if (ws.done) return;
|
|
653
727
|
|
|
728
|
+
// Track first-chunk time for accurate tok/s (excludes LLM thinking delay)
|
|
729
|
+
if (!ws.firstChunkAt) ws.firstChunkAt = Date.now();
|
|
730
|
+
|
|
654
731
|
ws.totalChars += unescapedChunk.length;
|
|
655
732
|
ws.lineBuf = (ws.lineBuf || "") + unescapedChunk;
|
|
656
733
|
const parts = ws.lineBuf.split(/\r?\n/);
|
|
@@ -678,6 +755,7 @@ function createTuiSink(tui, state) {
|
|
|
678
755
|
cleanupStreamWrite(toolIdx, revert = false) {
|
|
679
756
|
const entry = streamWriteBlocks.get(toolIdx);
|
|
680
757
|
if (!entry) return;
|
|
758
|
+
if (entry.absPath) state.streamActiveWriteFiles?.delete(entry.absPath);
|
|
681
759
|
if (revert && entry.absPath && entry.fileCreated) {
|
|
682
760
|
const workspaceRoot = state.workspaceRoot || process.cwd();
|
|
683
761
|
if (state.paths && state.streamCheckpointed?.has(entry.absPath)) {
|
|
@@ -696,6 +774,15 @@ function createTuiSink(tui, state) {
|
|
|
696
774
|
}
|
|
697
775
|
}
|
|
698
776
|
},
|
|
777
|
+
cleanupAllStreamWrites(revert = false) {
|
|
778
|
+
const keys = [...streamWriteBlocks.keys()];
|
|
779
|
+
for (const key of keys) {
|
|
780
|
+
if (typeof key === "number") {
|
|
781
|
+
this.cleanupStreamWrite(key, revert);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
streamWriteBlocks.clear();
|
|
785
|
+
},
|
|
699
786
|
};
|
|
700
787
|
}
|
|
701
788
|
|