kovence-cli 1.0.2 → 1.2.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.
@@ -24,7 +24,7 @@ const DEFAULT_SETTINGS = {
24
24
  provider: "",
25
25
  toolsEnabled: true,
26
26
  autoSummarize: true,
27
- maxToolSteps: 25,
27
+ maxToolSteps: 100,
28
28
  maxHistoryMessages: 24,
29
29
  contextWindow: 128000,
30
30
  temperature: null,
@@ -38,6 +38,7 @@ const DEFAULT_SETTINGS = {
38
38
  notifications: true,
39
39
  colorScheme: "amber",
40
40
  systemPrompt: DEFAULT_SYSTEM_PROMPT,
41
+ chatHistoryRetentionDays: 30,
41
42
  };
42
43
 
43
44
  /**
@@ -98,8 +99,8 @@ const SETTINGS_SCHEMA = [
98
99
  label: "Max Tool Steps",
99
100
  type: "integer",
100
101
  min: 1,
101
- max: 100,
102
- description: "Maximum consecutive tool-calling loop iterations per user turn (1-100).",
102
+ max: 1000,
103
+ description: "Maximum consecutive tool-calling loop iterations per user turn (1-1000).",
103
104
  },
104
105
  {
105
106
  key: "maxHistoryMessages",
@@ -194,6 +195,15 @@ const SETTINGS_SCHEMA = [
194
195
  type: "multilineString",
195
196
  description: "Base system instructions injected at the start of every request (press Enter to edit).",
196
197
  },
198
+ {
199
+ key: "chatHistoryRetentionDays",
200
+ label: "Chat History Retention (Days)",
201
+ type: "nullableInteger",
202
+ min: 0,
203
+ max: 3650,
204
+ description:
205
+ "Auto-delete sessions older than N days on startup (0 = never delete). Default: 30. Set to 'null' to disable.",
206
+ },
197
207
  {
198
208
  key: "managePermissions",
199
209
  label: "Manage Permissions",
@@ -227,6 +237,9 @@ const KEY_ALIASES = {
227
237
  show_active_tasks: "showActiveTasks",
228
238
  color_scheme: "colorScheme",
229
239
  system_prompt: "systemPrompt",
240
+ chat_history_retention: "chatHistoryRetentionDays",
241
+ chat_history_retention_days: "chatHistoryRetentionDays",
242
+ retention_days: "chatHistoryRetentionDays",
230
243
  };
231
244
 
232
245
  const PERSISTABLE_KEYS = new Set(Object.keys(DEFAULT_SETTINGS));
package/store.js CHANGED
@@ -88,6 +88,8 @@ module.exports = {
88
88
  loadInputHistory: (paths = getDefaultPaths()) => sessionsMod.loadInputHistory(paths),
89
89
  saveInputHistory: (items, paths = getDefaultPaths()) => sessionsMod.saveInputHistory(items, paths),
90
90
  deleteSession: (id, paths = getDefaultPaths()) => sessionsMod.deleteSession(id, paths),
91
+ cleanupOldSessions: (retentionDays, paths = getDefaultPaths(), activeSessionId = "") =>
92
+ sessionsMod.cleanupOldSessions(retentionDays, paths, activeSessionId),
91
93
 
92
94
  // Permissions
93
95
  loadPermissionRules: permStoreMod.loadPermissionRules,
package/tools.js CHANGED
@@ -743,7 +743,7 @@ const TOOL_HANDLERS = {
743
743
  const abs = resolvePath(filePath, root);
744
744
  assertToolFileAccess(abs, "write_file", ctx);
745
745
  const real = resolveRealWithMissingLeaf(abs);
746
- if (ctx?.paths)
746
+ if (ctx?.paths && !ctx?.streamCheckpointed?.has(real) && !ctx?.streamCheckpointed?.has(abs))
747
747
  recordCheckpoint({
748
748
  sessionId: ctx.session?.id || "default",
749
749
  toolName: "write_file",
package/tui.js CHANGED
@@ -25,8 +25,46 @@ const {
25
25
  parseSettingValue,
26
26
  } = require("./src/tui/settings_panel");
27
27
 
28
- function copyToClipboardOsc52(text, stdout = process.stdout) {
28
+ const { spawnSync } = require("node:child_process");
29
+
30
+ /**
31
+ * Copy text to system clipboard.
32
+ * Strategy (in order):
33
+ * 1. wl-copy (Wayland)
34
+ * 2. xclip (X11)
35
+ * 3. xsel (X11 fallback)
36
+ * 4. pbcopy (macOS)
37
+ * 5. OSC 52 (terminal escape — only works in Kitty / iTerm2 / WezTerm)
38
+ */
39
+ function copyToClipboard(text, stdout = process.stdout) {
29
40
  if (!text) return false;
41
+
42
+ // Try system clipboard tools silently (no shell, no PATH-injection risk).
43
+ const candidates = [];
44
+ if (process.env.WAYLAND_DISPLAY) {
45
+ candidates.push({ cmd: "wl-copy", args: [] });
46
+ }
47
+ if (process.env.DISPLAY) {
48
+ candidates.push({ cmd: "xclip", args: ["-selection", "clipboard"] });
49
+ candidates.push({ cmd: "xsel", args: ["--clipboard", "--input"] });
50
+ }
51
+ candidates.push({ cmd: "pbcopy", args: [] }); // macOS
52
+
53
+ for (const { cmd, args } of candidates) {
54
+ try {
55
+ const result = spawnSync(cmd, args, {
56
+ input: text,
57
+ encoding: "utf8",
58
+ stdio: ["pipe", "ignore", "ignore"],
59
+ timeout: 1000,
60
+ });
61
+ if (result.status === 0) return true;
62
+ } catch {
63
+ // Not found or failed — try next.
64
+ }
65
+ }
66
+
67
+ // OSC 52 fallback (terminal must support it).
30
68
  const b64 = Buffer.from(text, "utf8").toString("base64");
31
69
  stdout.write(`\x1b]52;c;${b64}\x07`);
32
70
  return true;
@@ -38,7 +76,7 @@ function styleInlineMarkdown(line, ansi) {
38
76
  .replace(/\*\*([^*]+)\*\*/g, `${ansi.bold}${ansi.amber}$1${ansi.reset}${ansi.white}`);
39
77
  }
40
78
 
41
- function formatAssistantLines(text, innerW, ansi) {
79
+ function formatAssistantLines(text, innerW, ansi, isStreaming = false, animTick = 0) {
42
80
  const out = [];
43
81
  const rawLines = String(text || "").split(/\r?\n/);
44
82
  let inCode = false;
@@ -74,6 +112,21 @@ function formatAssistantLines(text, innerW, ansi) {
74
112
  out.push(` ${ansi.orange}┃ ${ansi.white}${styleInlineMarkdown(wl, ansi)}${ansi.reset}`);
75
113
  }
76
114
  }
115
+
116
+ if (isStreaming) {
117
+ // Animated braille spinner — 6 frames cycling every render tick.
118
+ const SPIN = ["⠇", "⠋", "⠙", "⠸", "⠴", "⠦"];
119
+ const dot = SPIN[animTick % SPIN.length];
120
+ if (inCode) {
121
+ out.push(` ${ansi.gray}│ ${ansi.amber}${ansi.dim}${dot} writing...${ansi.reset}`);
122
+ } else if (!text || text.endsWith("\n")) {
123
+ out.push(` ${ansi.orange}┃ ${ansi.amber}${ansi.dim}${dot} writing...${ansi.reset}`);
124
+ } else {
125
+ // Mid-line: append animated dot inline
126
+ out[out.length - 1] = (out[out.length - 1] || "") + ` ${ansi.dim}${dot}${ansi.reset}`;
127
+ }
128
+ }
129
+
77
130
  return out;
78
131
  }
79
132
 
@@ -223,6 +276,10 @@ class KovenceTUI {
223
276
  this.onKey = this.onKey.bind(this);
224
277
  this.onRawData = this.onRawData.bind(this);
225
278
  this.onResize = () => this.scheduleRender();
279
+
280
+ // Spinner/animation tick — increments every 150 ms while active.
281
+ this.animTick = 0;
282
+ this._animTimer = null;
226
283
  }
227
284
 
228
285
  getPalette() {
@@ -257,7 +314,7 @@ class KovenceTUI {
257
314
  this.flashNotice("No AI response to copy yet");
258
315
  return false;
259
316
  }
260
- copyToClipboardOsc52(lastAi.text, this.stdout);
317
+ copyToClipboard(lastAi.text, this.stdout);
261
318
  this.flashNotice(`Copied last response (${lastAi.text.length} chars)`);
262
319
  return true;
263
320
  }
@@ -383,7 +440,7 @@ class KovenceTUI {
383
440
  }
384
441
  const text = this.extractSelectedText();
385
442
  if (text) {
386
- copyToClipboardOsc52(text, this.stdout);
443
+ copyToClipboard(text, this.stdout);
387
444
  this.flashNotice(`Copied ${text.length} chars to clipboard`);
388
445
  }
389
446
  this.scheduleRender();
@@ -517,6 +574,23 @@ class KovenceTUI {
517
574
  this.stdin.on("data", this.onRawData);
518
575
  }
519
576
  this.stdout.on("resize", this.onResize);
577
+ // Start animation timer for spinner/dot animation.
578
+ this._animTimer = setInterval(() => {
579
+ this.animTick++;
580
+ // Re-render if there is an active write block OR a streaming assistant block.
581
+ const hasActive = this.blocks.some((b) => (b.writeStats && !b.writeStats.done) || b._streaming);
582
+ if (hasActive) {
583
+ // Invalidate cache for all animated blocks so spinner dots re-render.
584
+ for (const b of this.blocks) {
585
+ if ((b.writeStats && !b.writeStats.done) || b._streaming) {
586
+ b._ver = (b._ver || 0) + 1;
587
+ b._cache = null;
588
+ }
589
+ }
590
+ this.scheduleRender();
591
+ }
592
+ }, 150);
593
+ this._animTimer.unref?.();
520
594
  this.render();
521
595
  }
522
596
 
@@ -536,6 +610,10 @@ class KovenceTUI {
536
610
  this.stdin.setRawMode(false);
537
611
  } catch {}
538
612
  }
613
+ if (this._animTimer) {
614
+ clearInterval(this._animTimer);
615
+ this._animTimer = null;
616
+ }
539
617
  this.stdout.write(CONTROL_SEQ.keysOff + CONTROL_SEQ.mouseOff + CONTROL_SEQ.showCur + CONTROL_SEQ.altOff);
540
618
  }
541
619
 
@@ -684,7 +762,9 @@ class KovenceTUI {
684
762
  blockLines.push("");
685
763
  } else if (b.kind === "assistant") {
686
764
  blockLines.push(` ${ansi.orange}${ansi.bold}◆ KOVENCE CLI${ansi.reset}`);
687
- blockLines.push(...formatAssistantLines(b.text, innerW, ansi));
765
+ blockLines.push(
766
+ ...formatAssistantLines(b.text, innerW, ansi, Boolean(b._streaming), this.animTick)
767
+ );
688
768
  } else if (b.kind === "thinking") {
689
769
  blockLines.push(` ${ansi.orange}${ansi.bold}◆ KOVENCE CLI${ansi.reset}`);
690
770
  for (const wl of wrapped) {
@@ -692,8 +772,27 @@ class KovenceTUI {
692
772
  }
693
773
  } else if (b.kind === "tool") {
694
774
  if (b.collapsible) {
775
+ const ws = b.writeStats;
776
+ // Show write stats always (even after done) as a summary.
777
+ // isActiveWrite controls the spinner animation only.
778
+ const hasWriteStats = Boolean(ws);
779
+ const isActiveWrite = ws && !ws.done;
780
+
781
+ // --- Animated write indicator dots ---
782
+ // DOT_FRAMES cycles through 4 states every 150 ms (animTick steps each interval).
783
+ const DOT_FRAMES = ["⠇", "⠋", "⠙", "⠸", "⠴", "⠦"];
784
+ const dot = DOT_FRAMES[this.animTick % DOT_FRAMES.length];
785
+
695
786
  const arrow = b.expanded ? "▾" : "▸";
696
- const hint = b.expanded ? " (click to hide)" : " (click for live details)";
787
+ // For active writes, show expand toggle; for others, show generic hint.
788
+ const hint = hasWriteStats
789
+ ? b.expanded
790
+ ? " (click or Ctrl+O to collapse)"
791
+ : " ▸ expand for live preview"
792
+ : b.expanded
793
+ ? " (click or Ctrl+O to hide)"
794
+ : " (click for live details)";
795
+
697
796
  for (let i = 0; i < wrapped.length; i++) {
698
797
  const wl = wrapped[i];
699
798
  if (i === 0) {
@@ -705,7 +804,46 @@ class KovenceTUI {
705
804
  }
706
805
  }
707
806
  const detailW = Math.max(12, innerW - 6);
708
- if (b.expanded) {
807
+
808
+ if (hasWriteStats) {
809
+ // --- Stats line: spinner (if active) or ✓ (if done) + lines + tokens + speed ---
810
+ const elapsedSec = Math.max(0.1, (Date.now() - ws.startTime) / 1000);
811
+ // Rough token estimate: ~4 chars per token.
812
+ const tokEst = Math.round(ws.totalChars / 4);
813
+ const tokSec = Math.round(tokEst / elapsedSec);
814
+ const statusIcon = isActiveWrite ? dot : "✓";
815
+ const statsLine = `${statusIcon} ${ws.totalLines} lines · ~${tokEst} tokens · ${tokSec} tok/s`;
816
+ blockLines.push(
817
+ ` ${ansi.gray}│ ${ansi.amber}${clipToWidth(statsLine, detailW)}${ansi.reset}`
818
+ );
819
+
820
+ if (b.expanded) {
821
+ // Live Path line
822
+ const livePath = ws.filePath || (ws.dir ? `${ws.dir}/` : "");
823
+ if (livePath) {
824
+ const pathLine = `📄 Live Path: ${livePath}`;
825
+ blockLines.push(
826
+ ` ${ansi.gray}│ ${ansi.dim}${ansi.gray}${clipToWidth(pathLine, detailW)}${ansi.reset}`
827
+ );
828
+ }
829
+ // 5-line window of last written code (auto-scroll: always last 5 lines)
830
+ const preview = (ws.currentPreview || ws.previewLines || []).slice(-5);
831
+ if (preview.length) {
832
+ blockLines.push(
833
+ ` ${ansi.gray}│ ${ansi.dim}${ansi.gray}${"─".repeat(Math.min(detailW, 40))}${ansi.reset}`
834
+ );
835
+ for (const pl of preview) {
836
+ blockLines.push(
837
+ ` ${ansi.gray}│ ${ansi.dim}${ansi.gray}${clipToWidth(pl, detailW)}${ansi.reset}`
838
+ );
839
+ }
840
+ } else {
841
+ blockLines.push(
842
+ ` ${ansi.gray}│ ${ansi.dim}${ansi.gray}${clipToWidth("… waiting for written tokens …", detailW)}${ansi.reset}`
843
+ );
844
+ }
845
+ }
846
+ } else if (b.expanded) {
709
847
  const visDetails = (b.details || []).slice(-16);
710
848
  if (!visDetails.length) {
711
849
  const emptyMsg = b.statusLine || "… waiting for live command output …";
@@ -951,15 +1089,17 @@ class KovenceTUI {
951
1089
  for (let i = 0; i < visCompLines.length; i++) {
952
1090
  const pfx = i === 0 && compStart === 0 ? promptPrefix : prefixSpace;
953
1091
  const txt = visCompLines[i];
1092
+ const isBusy = Boolean(this.status.isBusy || this.status.busyLabel);
1093
+ const defaultPh = "Type message · Shift+Enter newline · / commands...";
1094
+ const phText = isBusy && this.status.busyLabel ? `⏳ ${this.status.busyLabel}` : defaultPh;
954
1095
  const showPh =
955
1096
  i === 0 &&
956
1097
  compStart === 0 &&
957
1098
  !this.modal &&
958
1099
  !this.input &&
959
1100
  this.status.showTips !== false &&
960
- cols >= 2 + displayWidth(pfx) + 52;
961
- const phText = "Type message · Shift+Enter newline · / commands...";
962
- const placeholder = showPh ? `${ansi.gray}${phText}${ansi.reset}` : "";
1101
+ cols >= 2 + displayWidth(pfx) + displayWidth(phText);
1102
+ const placeholder = showPh ? `${isBusy ? ansi.amber : ansi.gray}${phText}${ansi.reset}` : "";
963
1103
  const phLen = showPh ? displayWidth(phText) : 0;
964
1104
  const linePlainLen = 2 + displayWidth(pfx) + displayWidth(txt);
965
1105
  const padComposer = Math.max(0, cols - linePlainLen - phLen);
package/ui.js CHANGED
@@ -82,7 +82,7 @@ const SUBCOMMAND_HINTS = {
82
82
  { fill: "/set nonWorkspaceAccess ", desc: "ask | allow | deny" },
83
83
  { fill: "/set toolsEnabled ", desc: "true | false" },
84
84
  { fill: "/set autoSummarize ", desc: "true | false" },
85
- { fill: "/set maxToolSteps ", desc: "integer 1-100 (default 25)" },
85
+ { fill: "/set maxToolSteps ", desc: "integer 1-1000 (default 100)" },
86
86
  { fill: "/set maxHistoryMessages ", desc: "integer 2-500 (default 24)" },
87
87
  { fill: "/set contextWindow ", desc: "integer >= 1024 (default 128000)" },
88
88
  { fill: "/set temperature ", desc: "0.0-2.0 | null" },