@kvali/cli 0.7.8 → 0.7.10

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kvali",
3
- "version": "0.7.8",
3
+ "version": "0.7.10",
4
4
  "description": "Live progress for Claude Code: plan progress, the current step and the time left, what the agent is doing right now, tokens and your plan limits, in a pane beside the chat.",
5
5
  "author": { "name": "Giorgi Khiladze" },
6
6
  "homepage": "https://github.com/webGrandpa/kvali",
package/dist/kvali.mjs CHANGED
@@ -988,17 +988,24 @@ async function isolated(ctx, what, fn) {
988
988
  }
989
989
  }
990
990
  var fileName = (p2) => p2.split(/[\\/]/).pop() ?? p2;
991
+ var SOON_MS = 250;
991
992
  var JsonlSessionAdapter = class {
992
993
  discoveryIntervalMs = 5e3;
993
994
  tracked = /* @__PURE__ */ new Map();
994
995
  lastDiscovery = 0;
996
+ /** A file it does not follow yet changed in a watched folder: look for sessions at once. */
997
+ soon = false;
998
+ changed(file) {
999
+ if (!file || !this.tracked.has(file)) this.soon = true;
1000
+ }
995
1001
  /** Optional hook to read side files (plans, live state) after the transcript was read. */
996
1002
  async afterRead(_state, _ctx, _changed) {
997
1003
  }
998
1004
  async poll(ctx) {
999
1005
  const now = ctx.now();
1000
- if (this.tracked.size === 0 || now - this.lastDiscovery >= this.discoveryIntervalMs) {
1006
+ if (this.tracked.size === 0 || now - this.lastDiscovery >= this.discoveryIntervalMs || this.soon && now - this.lastDiscovery >= SOON_MS) {
1001
1007
  this.lastDiscovery = now;
1008
+ this.soon = false;
1002
1009
  const candidates = (await this.discover(ctx)).filter((c) => now - c.mtimeMs <= ctx.activeWindowMs).sort((a, b) => b.mtimeMs - a.mtimeMs).slice(0, ctx.maxSessionsPerAgent);
1003
1010
  const keep = new Set(candidates.map((c) => c.path));
1004
1011
  for (const c of candidates) {
@@ -1033,6 +1040,7 @@ function staleness(updatedAt, ctx) {
1033
1040
  }
1034
1041
 
1035
1042
  // ../core/src/engine.ts
1043
+ import { existsSync as existsSync2, watch } from "node:fs";
1036
1044
  import os from "node:os";
1037
1045
  import path12 from "node:path";
1038
1046
 
@@ -1361,6 +1369,8 @@ var AntigravityAdapter = class {
1361
1369
  label = "Antigravity";
1362
1370
  tracked = /* @__PURE__ */ new Map();
1363
1371
  lastDiscovery = 0;
1372
+ /** A conversation it does not follow yet changed in a watched folder: look for sessions at once. */
1373
+ soon = false;
1364
1374
  extraBrainDirs;
1365
1375
  constructor(extraBrainDirs = []) {
1366
1376
  this.extraBrainDirs = extraBrainDirs;
@@ -1369,10 +1379,18 @@ var AntigravityAdapter = class {
1369
1379
  const g = path3.join(ctx.home, ".gemini");
1370
1380
  return [path3.join(g, "antigravity-ide", "brain"), path3.join(g, "antigravity", "brain"), ...this.extraBrainDirs];
1371
1381
  }
1382
+ watchRoots(ctx) {
1383
+ return this.brainDirs(ctx);
1384
+ }
1385
+ changed(file) {
1386
+ if (file && [...this.tracked.keys()].some((dir) => file === dir || file.startsWith(dir + path3.sep))) return;
1387
+ this.soon = true;
1388
+ }
1372
1389
  async poll(ctx) {
1373
1390
  const now = ctx.now();
1374
- if (this.tracked.size === 0 || now - this.lastDiscovery >= 5e3) {
1391
+ if (this.tracked.size === 0 || now - this.lastDiscovery >= 5e3 || this.soon && now - this.lastDiscovery >= SOON_MS) {
1375
1392
  this.lastDiscovery = now;
1393
+ this.soon = false;
1376
1394
  await this.discover(ctx);
1377
1395
  }
1378
1396
  const out = [];
@@ -1864,16 +1882,35 @@ var ClaudeCodeAdapter = class {
1864
1882
  dirCache = /* @__PURE__ */ new Map();
1865
1883
  lastDiscovery = 0;
1866
1884
  lastFullScan = 0;
1885
+ /** A transcript it does not follow yet changed in the watched folder: look for sessions at once. */
1886
+ soon = false;
1867
1887
  /** The subscription's usage windows, from every session's plugin heartbeat. */
1868
1888
  limitBook = new LimitBook();
1869
1889
  configDir(ctx) {
1870
1890
  const fromEnv = ctx.env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim();
1871
1891
  return fromEnv || path4.join(ctx.home, ".claude");
1872
1892
  }
1893
+ /** The watched projects folder, as of the last `watchRoots`. */
1894
+ projectsDir;
1895
+ watchRoots(ctx) {
1896
+ this.projectsDir = path4.join(this.configDir(ctx), "projects");
1897
+ return [this.projectsDir];
1898
+ }
1899
+ changed(file) {
1900
+ if (file && this.sessions.has(file)) return;
1901
+ if (file && this.projectsDir) {
1902
+ const parent = path4.dirname(file);
1903
+ const transcript = file.endsWith(".jsonl") && path4.dirname(parent) === this.projectsDir;
1904
+ if (!transcript && parent !== this.projectsDir) return;
1905
+ }
1906
+ if (file?.endsWith(".jsonl")) this.dirCache.delete(path4.dirname(file));
1907
+ this.soon = true;
1908
+ }
1873
1909
  async poll(ctx) {
1874
1910
  const now = ctx.now();
1875
- if (this.sessions.size === 0 || now - this.lastDiscovery >= 5e3) {
1911
+ if (this.sessions.size === 0 || now - this.lastDiscovery >= 5e3 || this.soon && now - this.lastDiscovery >= SOON_MS) {
1876
1912
  this.lastDiscovery = now;
1913
+ this.soon = false;
1877
1914
  await this.discover(ctx);
1878
1915
  }
1879
1916
  const out = [];
@@ -3515,8 +3552,22 @@ function parseArgs(raw) {
3515
3552
  return {};
3516
3553
  }
3517
3554
  }
3555
+ var CODE_CELL = /\btools\.[A-Za-z_]\w*\s*\(/;
3556
+ function codeCommand(js) {
3557
+ const lit = /\bcmd\s*:\s*(?:(["'])((?:\\[\s\S]|(?!\1)[^\\])*)\1|`([^`]*)`)/.exec(js);
3558
+ if (lit) return lit[3] ?? lit[2].replace(/\\[nt]/g, " ").replace(/\\(["'\\])/g, "$1");
3559
+ const raw = /String\.raw\s*`([^`]*)`/.exec(js);
3560
+ return raw?.[1];
3561
+ }
3562
+ function describeCodeCell(js, at) {
3563
+ const cmd = summarizeCommand(codeCommand(js));
3564
+ if (/\btools\.(?:exec_command|shell_command|shell|exec|unified_exec)\s*\(/.test(js)) return { kind: "command", label: "Shell", detail: cmd, startedAt: at };
3565
+ if (/\btools\.apply_patch\s*\(/.test(js)) return { kind: "tool", label: "Editing files", startedAt: at };
3566
+ return { kind: "tool", label: "Running code", detail: cmd, startedAt: at };
3567
+ }
3568
+ var SHELL_TOOLS = /^(?:shell|shell_command|exec_command|exec|unified_exec|container\.exec|local_shell)$/;
3518
3569
  function describeCodexCall(name, args, at) {
3519
- if (name === "shell" || name === "exec_command" || name === "container.exec" || name === "local_shell") {
3570
+ if (SHELL_TOOLS.test(name)) {
3520
3571
  return { kind: "command", label: "Shell", detail: summarizeCommand(args.command ?? args.cmd), startedAt: at };
3521
3572
  }
3522
3573
  if (name === "apply_patch") return { kind: "tool", label: "Editing files", startedAt: at };
@@ -3536,12 +3587,25 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3536
3587
  /** Rollouts in older day folders that were written lately: sessions resumed since they began. */
3537
3588
  resumed = [];
3538
3589
  resumedAt = -Infinity;
3590
+ /** Rollouts a watched folder said were written: a session resumed in any day's folder shows at once. */
3591
+ written = /* @__PURE__ */ new Set();
3539
3592
  limits(ctx) {
3540
3593
  const windows = this.limitBook.windows(ctx.now());
3541
3594
  return windows.length ? { agent: this.id, agentLabel: this.label, windows } : void 0;
3542
3595
  }
3543
3596
  id = "codex";
3544
3597
  label = "Codex";
3598
+ watchRoots(ctx) {
3599
+ return [path7.join(ctx.env.CODEX_HOME || path7.join(ctx.home, ".codex"), "sessions")];
3600
+ }
3601
+ changed(file) {
3602
+ if (file && !/^rollout-.*\.jsonl$/.test(path7.basename(file)) && /\.[A-Za-z]+$/.test(file)) return;
3603
+ super.changed(file);
3604
+ if (file && /^rollout-.*\.jsonl$/.test(path7.basename(file))) {
3605
+ if (this.written.size >= 200) this.written.clear();
3606
+ this.written.add(file);
3607
+ }
3608
+ }
3545
3609
  async discover(ctx) {
3546
3610
  const home = ctx.env.CODEX_HOME || path7.join(ctx.home, ".codex");
3547
3611
  const root = path7.join(home, "sessions");
@@ -3588,10 +3652,12 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3588
3652
  }
3589
3653
  this.resumed = found;
3590
3654
  }
3591
- for (const file of this.resumed) {
3655
+ for (const file of [...this.resumed, ...this.written]) {
3592
3656
  if (seen.has(file)) continue;
3657
+ seen.add(file);
3593
3658
  const st = await statSafe(file);
3594
3659
  if (st) out.push({ path: file, mtimeMs: st.mtimeMs });
3660
+ else this.written.delete(file);
3595
3661
  }
3596
3662
  return out;
3597
3663
  }
@@ -3608,6 +3674,7 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3608
3674
  daily,
3609
3675
  tasks: [],
3610
3676
  open: /* @__PURE__ */ new Map(),
3677
+ callKeys: /* @__PURE__ */ new Map(),
3611
3678
  phase: "idle",
3612
3679
  phaseAt: 0,
3613
3680
  turns: 0,
@@ -3640,6 +3707,7 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3640
3707
  if (typeof p2.originator === "string") st.originator = p2.originator;
3641
3708
  else if (typeof p2.source === "string") st.originator = p2.source;
3642
3709
  if (p2.parent_thread_id || p2.agent_role || p2.agent_nickname) st.isSubagent = true;
3710
+ if (p2.source && typeof p2.source === "object" && "subagent" in p2.source) st.isSubagent = true;
3643
3711
  const started = parseTime(p2.timestamp);
3644
3712
  if (started) st.startedAt = Math.min(st.startedAt ?? started, started);
3645
3713
  return;
@@ -3674,11 +3742,13 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3674
3742
  st.phase = "idle";
3675
3743
  st.phaseAt = ts;
3676
3744
  st.open.clear();
3745
+ st.callKeys.clear();
3677
3746
  return;
3678
3747
  case "turn_aborted":
3679
3748
  st.phase = "interrupted";
3680
3749
  st.phaseAt = ts;
3681
3750
  st.open.clear();
3751
+ st.callKeys.clear();
3682
3752
  st.loops.reset();
3683
3753
  return;
3684
3754
  case "error":
@@ -3688,7 +3758,8 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3688
3758
  return;
3689
3759
  case "user_message":
3690
3760
  if (typeof p2.message === "string" && p2.message.trim()) {
3691
- st.title ??= firstLine(p2.message, 100);
3761
+ const said = codexPrompt(p2.message);
3762
+ if (said) st.title ??= firstLine(said, 100);
3692
3763
  st.loops.reset();
3693
3764
  if (st.phase !== "working") {
3694
3765
  st.phase = "working";
@@ -3788,10 +3859,20 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3788
3859
  return;
3789
3860
  }
3790
3861
  case "custom_tool_call": {
3791
- const act = describeCodexCall(String(p2.name ?? "tool"), {}, ts);
3792
- if (typeof p2.call_id === "string") st.open.set(p2.call_id, act);
3862
+ const name = String(p2.name ?? "tool");
3863
+ const input = typeof p2.input === "string" ? p2.input : void 0;
3864
+ const act = input !== void 0 && CODE_CELL.test(input) ? describeCodeCell(input, ts) : describeCodexCall(name, input !== void 0 ? { command: input } : {}, ts);
3865
+ if (typeof p2.call_id === "string") {
3866
+ st.open.set(p2.call_id, act);
3867
+ if (input) st.callKeys.set(p2.call_id, `${act.kind === "command" ? "command" : name}:${input.slice(0, 2e3)}`);
3868
+ }
3793
3869
  st.activity = act;
3794
3870
  st.turnSteps += 1;
3871
+ if (name !== "update_plan") {
3872
+ st.recent.unshift(act);
3873
+ if (st.recent.length > 6) st.recent.length = 6;
3874
+ st.timer.step();
3875
+ }
3795
3876
  return;
3796
3877
  }
3797
3878
  case "local_shell_call": {
@@ -3806,9 +3887,13 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3806
3887
  const done = typeof p2.call_id === "string" ? st.open.get(p2.call_id) : void 0;
3807
3888
  if (done) {
3808
3889
  done.endedAt = ts;
3809
- st.loops.observe(loopKey(done), done, codexFailure(p2.output), ts, st.tokens ? totalTokens(st.tokens) : void 0);
3890
+ const key = st.callKeys.get(p2.call_id) ?? loopKey(done);
3891
+ st.loops.observe(key, done, codexFailure(p2.output), ts, st.tokens ? totalTokens(st.tokens) : void 0);
3892
+ }
3893
+ if (typeof p2.call_id === "string") {
3894
+ st.open.delete(p2.call_id);
3895
+ st.callKeys.delete(p2.call_id);
3810
3896
  }
3811
- if (typeof p2.call_id === "string") st.open.delete(p2.call_id);
3812
3897
  st.activity = { kind: "thinking", label: "Thinking", startedAt: ts };
3813
3898
  return;
3814
3899
  }
@@ -3819,6 +3904,15 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3819
3904
  st.activity = { kind: "thinking", label: "Thinking", startedAt: ts };
3820
3905
  return;
3821
3906
  case "message":
3907
+ if (p2.role === "user") {
3908
+ const parts = Array.isArray(p2.content) ? p2.content : [p2.content];
3909
+ const said = parts.map((c) => codexPrompt(contentText(Array.isArray(c) ? c : [c]))).find((x) => x !== void 0);
3910
+ if (said) {
3911
+ st.promptTitle ??= firstLine(said, 100);
3912
+ st.loops.reset();
3913
+ }
3914
+ return;
3915
+ }
3822
3916
  if (p2.role === "assistant" && contentText(p2.content).trim()) {
3823
3917
  st.activity = { kind: "message", label: "Writing a reply", startedAt: ts };
3824
3918
  }
@@ -3860,13 +3954,13 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3860
3954
  agent: "codex",
3861
3955
  agentLabel: this.label,
3862
3956
  id: st.id,
3863
- title: st.title ?? "Untitled session",
3864
- titleFromPrompt: st.title !== void 0 ? true : void 0,
3957
+ title: st.title ?? st.promptTitle ?? "Untitled session",
3958
+ titleFromPrompt: (st.title ?? st.promptTitle) !== void 0 ? true : void 0,
3865
3959
  projectPath: st.cwd ? findGitRoot(st.cwd) ?? st.cwd : void 0,
3866
3960
  cwd: st.cwd,
3867
3961
  model: st.model,
3868
3962
  agentVersion: st.version,
3869
- host: st.originator === void 0 ? void 0 : /vscode|ide/.test(st.originator) ? "editor" : /exec|mcp|sdk/.test(st.originator) ? "app" : "terminal",
3963
+ host: codexHost(st.originator),
3870
3964
  status,
3871
3965
  statusDetail: detail,
3872
3966
  startedAt: st.startedAt,
@@ -3887,6 +3981,21 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3887
3981
  };
3888
3982
  }
3889
3983
  };
3984
+ function codexPrompt(text) {
3985
+ let t = text.trim();
3986
+ const req = /^#{1,3}\s*My request for Codex:?[ \t]*$/im.exec(t);
3987
+ if (req) t = t.slice(req.index + req[0].length).trim();
3988
+ else if (/^#\s*(?:Context from my IDE setup|[^\n]*\bby the user)\b[^\n]*$/im.test(t.split("\n", 1)[0] ?? "")) return void 0;
3989
+ if (!t || t.startsWith("<") || /^#\s*AGENTS\.md\b/i.test(t)) return void 0;
3990
+ return t;
3991
+ }
3992
+ function codexHost(originator) {
3993
+ if (originator === void 0) return void 0;
3994
+ if (/desktop/i.test(originator)) return "app";
3995
+ if (/vscode|ide/.test(originator)) return "editor";
3996
+ if (/exec|mcp|sdk/.test(originator)) return "app";
3997
+ return "terminal";
3998
+ }
3890
3999
  function loopOf(st, status, now) {
3891
4000
  const l = status === "working" || status === "stale" ? st.loops.current(now) : void 0;
3892
4001
  if (!l) return void 0;
@@ -4532,6 +4641,8 @@ var GeminiCliAdapter = class {
4532
4641
  label = "Gemini CLI";
4533
4642
  tracked = /* @__PURE__ */ new Map();
4534
4643
  lastDiscovery = 0;
4644
+ /** A chat it does not follow yet changed in a watched folder: look for sessions at once. */
4645
+ soon = false;
4535
4646
  roots(ctx) {
4536
4647
  const homes = [ctx.env.GEMINI_CLI_HOME, ctx.home].filter((h) => !!h);
4537
4648
  const out = /* @__PURE__ */ new Set();
@@ -4541,10 +4652,19 @@ var GeminiCliAdapter = class {
4541
4652
  }
4542
4653
  return [...out];
4543
4654
  }
4655
+ watchRoots(ctx) {
4656
+ return this.roots(ctx);
4657
+ }
4658
+ changed(file) {
4659
+ if (file && this.tracked.has(file)) return;
4660
+ if (file && /\.[A-Za-z]+$/.test(file) && !/^session-.*\.jsonl?$/.test(path9.basename(file))) return;
4661
+ this.soon = true;
4662
+ }
4544
4663
  async poll(ctx) {
4545
4664
  const now = ctx.now();
4546
- if (this.tracked.size === 0 || now - this.lastDiscovery >= 5e3) {
4665
+ if (this.tracked.size === 0 || now - this.lastDiscovery >= 5e3 || this.soon && now - this.lastDiscovery >= SOON_MS) {
4547
4666
  this.lastDiscovery = now;
4667
+ this.soon = false;
4548
4668
  await this.discover(ctx);
4549
4669
  }
4550
4670
  const out = [];
@@ -4790,9 +4910,9 @@ function todosOf(list) {
4790
4910
  if (!Array.isArray(list)) return void 0;
4791
4911
  return list.filter((t) => t && typeof t.content === "string" && t.content.trim()).map((t, i) => ({ id: typeof t.id === "string" ? t.id : String(i + 1), title: t.content.trim(), status: todoStatus3(t.status) }));
4792
4912
  }
4793
- var SHELL_TOOLS = /* @__PURE__ */ new Set(["shell", "bash"]);
4913
+ var SHELL_TOOLS2 = /* @__PURE__ */ new Set(["shell", "bash"]);
4794
4914
  function toolAct(name, input, at) {
4795
- if (SHELL_TOOLS.has(name)) return { kind: "command", label: "Shell", detail: summarizeCommand(input.command), startedAt: at };
4915
+ if (SHELL_TOOLS2.has(name)) return { kind: "command", label: "Shell", detail: summarizeCommand(input.command), startedAt: at };
4796
4916
  const file = typeof input.filePath === "string" ? input.filePath : typeof input.path === "string" ? input.path : void 0;
4797
4917
  const short = (p2) => p2 ? truncate(p2, 80) : void 0;
4798
4918
  switch (name) {
@@ -4831,7 +4951,7 @@ function failureOf(name, state, contentText2) {
4831
4951
  const e = state.error;
4832
4952
  return typeof e === "string" ? e : typeof e?.message === "string" ? e.message : "Tool error";
4833
4953
  }
4834
- if (state.status !== "completed" || !SHELL_TOOLS.has(name)) return void 0;
4954
+ if (state.status !== "completed" || !SHELL_TOOLS2.has(name)) return void 0;
4835
4955
  const m = state.metadata ?? {};
4836
4956
  if (m.timeout === true) return `Timed out
4837
4957
  ${contentText2()}`;
@@ -5557,6 +5677,9 @@ var ProgressFileAdapter = class {
5557
5677
  };
5558
5678
 
5559
5679
  // ../core/src/engine.ts
5680
+ var KICK_MS = 150;
5681
+ var KICK_GAP_MS = 400;
5682
+ var WATCH_SYNC_MS = 3e4;
5560
5683
  function defaultLiveDir(home = os.homedir()) {
5561
5684
  return path12.join(home, ".kvali", "live");
5562
5685
  }
@@ -5647,11 +5770,22 @@ var Engine = class {
5647
5770
  lastSignature = "";
5648
5771
  current = { generatedAt: 0, sessions: [], errors: [] };
5649
5772
  disabled;
5773
+ watchFolders;
5774
+ /** Per adapter and folder (`${id}\n${folder}`). */
5775
+ watchers = /* @__PURE__ */ new Map();
5776
+ /** Folders that could not be watched, said once in the log. */
5777
+ watchFailed = /* @__PURE__ */ new Set();
5778
+ lastWatchSync = -Infinity;
5779
+ kickTimer;
5780
+ /** A change came in while a poll ran: poll again once it is done. */
5781
+ kickAgain = false;
5782
+ lastKickAt = -Infinity;
5650
5783
  constructor(opts = {}) {
5651
5784
  const home = opts.home ?? os.homedir();
5652
5785
  this.adapters = opts.adapters ?? createDefaultAdapters(opts);
5653
5786
  this.disabled = new Set(opts.disabled ?? []);
5654
5787
  this.intervalMs = opts.intervalMs ?? 1500;
5788
+ this.watchFolders = opts.watch ?? (process.platform === "darwin" || process.platform === "win32");
5655
5789
  this.ctx = {
5656
5790
  home,
5657
5791
  env: opts.env ?? process.env,
@@ -5679,10 +5813,12 @@ var Engine = class {
5679
5813
  if (opts.disabled) this.disabled = new Set(opts.disabled);
5680
5814
  if (opts.intervalMs) this.intervalMs = opts.intervalMs;
5681
5815
  this.lastSignature = "";
5816
+ this.lastWatchSync = -Infinity;
5682
5817
  }
5683
5818
  /** Swaps adapters, e.g. after a setting that changes an adapter's constructor options. */
5684
5819
  setAdapters(adapters) {
5685
5820
  for (const a of this.adapters) a.dispose?.();
5821
+ this.closeWatchers();
5686
5822
  this.adapters = adapters;
5687
5823
  this.lastSignature = "";
5688
5824
  }
@@ -5699,6 +5835,9 @@ var Engine = class {
5699
5835
  this.stopped = true;
5700
5836
  if (this.timer) clearTimeout(this.timer);
5701
5837
  this.timer = void 0;
5838
+ if (this.kickTimer) clearTimeout(this.kickTimer);
5839
+ this.kickTimer = void 0;
5840
+ this.closeWatchers();
5702
5841
  }
5703
5842
  dispose() {
5704
5843
  this.stop();
@@ -5707,6 +5846,7 @@ var Engine = class {
5707
5846
  }
5708
5847
  async loop() {
5709
5848
  if (this.stopped) return;
5849
+ if (this.watchFolders) this.syncWatchers();
5710
5850
  try {
5711
5851
  await this.tick();
5712
5852
  } catch (err) {
@@ -5753,8 +5893,78 @@ var Engine = class {
5753
5893
  return this.current;
5754
5894
  } finally {
5755
5895
  this.running = false;
5896
+ if (this.kickAgain) {
5897
+ this.kickAgain = false;
5898
+ this.kick();
5899
+ }
5900
+ }
5901
+ }
5902
+ /** Polls soon after a change in a watched folder, so a new session shows at once. */
5903
+ kick() {
5904
+ if (this.stopped || this.kickTimer) return;
5905
+ const delay = Math.max(KICK_MS, this.lastKickAt + KICK_GAP_MS - Date.now());
5906
+ this.kickTimer = setTimeout(() => {
5907
+ this.kickTimer = void 0;
5908
+ if (this.stopped) return;
5909
+ if (this.running) {
5910
+ this.kickAgain = true;
5911
+ return;
5912
+ }
5913
+ this.lastKickAt = Date.now();
5914
+ this.tick().catch((err) => this.ctx.log(`tick failed: ${err instanceof Error ? err.message : String(err)}`));
5915
+ }, delay);
5916
+ }
5917
+ /** Watches each adapter's folders that exist; one that cannot be watched is only polled, as before. */
5918
+ syncWatchers() {
5919
+ const now = this.ctx.now();
5920
+ if (now - this.lastWatchSync < WATCH_SYNC_MS) return;
5921
+ this.lastWatchSync = now;
5922
+ const want = /* @__PURE__ */ new Map();
5923
+ for (const a of this.adapters) {
5924
+ if (this.disabled.has(a.id) || !a.watchRoots) continue;
5925
+ let roots = [];
5926
+ try {
5927
+ roots = a.watchRoots(this.ctx);
5928
+ } catch {
5929
+ }
5930
+ for (const root of roots) want.set(`${a.id}
5931
+ ${root}`, { adapter: a, root });
5932
+ }
5933
+ for (const [key, w] of this.watchers) {
5934
+ if (want.has(key)) continue;
5935
+ w.close();
5936
+ this.watchers.delete(key);
5937
+ }
5938
+ for (const [key, { adapter, root }] of want) {
5939
+ if (this.watchers.has(key) || !existsSync2(root)) continue;
5940
+ try {
5941
+ const w = watch(root, { recursive: true, persistent: false }, (_event, name) => {
5942
+ const file = name ? path12.join(root, String(name)) : void 0;
5943
+ try {
5944
+ adapter.changed?.(file);
5945
+ } catch {
5946
+ }
5947
+ this.kick();
5948
+ });
5949
+ w.on("error", () => {
5950
+ w.close();
5951
+ this.watchers.delete(key);
5952
+ });
5953
+ this.watchers.set(key, w);
5954
+ this.ctx.log(`[${adapter.id}] watching ${root}`);
5955
+ } catch (err) {
5956
+ if (!this.watchFailed.has(key)) {
5957
+ this.watchFailed.add(key);
5958
+ this.ctx.log(`[${adapter.id}] cannot watch ${root}, polling it: ${err instanceof Error ? err.message : String(err)}`);
5959
+ }
5960
+ }
5756
5961
  }
5757
5962
  }
5963
+ closeWatchers() {
5964
+ for (const w of this.watchers.values()) w.close();
5965
+ this.watchers.clear();
5966
+ this.lastWatchSync = -Infinity;
5967
+ }
5758
5968
  };
5759
5969
 
5760
5970
  // ../core/src/hooks/hub.ts
@@ -6455,12 +6665,12 @@ async function addProgressProtocol(root) {
6455
6665
  }
6456
6666
 
6457
6667
  // ../core/src/hooks/replies.ts
6458
- import { existsSync as existsSync2 } from "node:fs";
6668
+ import { existsSync as existsSync3 } from "node:fs";
6459
6669
  import path17 from "node:path";
6460
6670
  var CLAUDE_PLAN_CONTEXT = "Progress tracking (Kvali): if this request takes more than two steps, start by creating a task list with TaskCreate or TodoWrite, whichever you have (if neither is in your tool list, look for them once with ToolSearch, and go on without a list if they are not there), keep exactly one task in_progress, and mark each task completed as soon as it is done. The user follows your progress from that list, so keep it current.";
6461
6671
  function pluginRunsIn(liveDir, sessionId) {
6462
6672
  if (!/^[A-Za-z0-9-]{8,80}$/.test(sessionId)) return false;
6463
- return existsSync2(path17.join(liveDir, "claude-code", `${sessionId}.mod.json`));
6673
+ return existsSync3(path17.join(liveDir, "claude-code", `${sessionId}.mod.json`));
6464
6674
  }
6465
6675
  function claudeHookReply(ev, session, pluginRuns = false) {
6466
6676
  if (ev.event !== "UserPromptSubmit") return void 0;
@@ -8986,7 +9196,7 @@ function qrTerminal(text, color = true) {
8986
9196
  }
8987
9197
 
8988
9198
  // src/index.ts
8989
- var VERSION = "0.7.8";
9199
+ var VERSION = "0.7.10";
8990
9200
  function parse(argv) {
8991
9201
  const opts = {
8992
9202
  json: false,
@@ -9509,7 +9719,7 @@ async function main() {
9509
9719
  return;
9510
9720
  }
9511
9721
  if (cmd[0] === "phone") return phone(cmd[1], opts, cmd[2]);
9512
- if (cmd[0] === "watch") return watch(opts);
9722
+ if (cmd[0] === "watch") return watch2(opts);
9513
9723
  if (cmd[0] === "week") return week(opts, opts.svg);
9514
9724
  if (cmd[0] === "plan-rule") {
9515
9725
  for (const r of await addGlobalPlanRule(opts.home, process2.env)) console.log(`${r.agent}: ${r.result} (${r.file})`);
@@ -9576,7 +9786,7 @@ ${phoneLine ? `${phoneLine}
9576
9786
  });
9577
9787
  }
9578
9788
  }
9579
- async function watch(opts) {
9789
+ async function watch2(opts) {
9580
9790
  const engine = makeEngine(opts);
9581
9791
  const hub = new HookHub({
9582
9792
  port: opts.port,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kvali/cli",
3
- "version": "0.7.8",
3
+ "version": "0.7.10",
4
4
  "description": "Live progress, time left, tokens, plan limits and phone alerts for AI coding agents (Claude Code, Codex, Gemini CLI, Antigravity, Copilot, Cline, Roo Code, Kilo Code, OpenCode), in your terminal.",
5
5
  "license": "MIT",
6
6
  "author": "Giorgi Khiladze (https://github.com/webGrandpa)",