@kvali/cli 0.7.0 → 0.7.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kvali",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
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",
@@ -698,7 +698,8 @@ export const baseName = (p: string): string => p.replace(/[\\/]+$/, '').split(/[
698
698
  /** Sent beside a prompt while the session has no unfinished plan: the same words as Kvali's hook. */
699
699
  export const PLAN_CONTEXT =
700
700
  'Progress tracking (Kvali): if this request takes more than two steps, start by creating a task list with TaskCreate ' +
701
- 'or TodoWrite, whichever you have (if neither is in your tool list, load one with ToolSearch first), keep exactly ' +
701
+ 'or TodoWrite, whichever you have (if neither is in your tool list, look for them once with ToolSearch, and go on ' +
702
+ 'without a list if they are not there), keep exactly ' +
702
703
  'one task in_progress, and mark each task completed as soon as it is done. ' +
703
704
  'The user follows your progress from that list, so keep it current.'
704
705
 
@@ -708,7 +709,8 @@ export const PLAN_ASK_AFTER = 6
708
709
  /** What a long turn with no plan reads after one of its tool results (once a turn). */
709
710
  export const PLAN_REMINDER =
710
711
  'Progress tracking (Kvali): this work has no task list yet. If more than two steps remain, create one now for the ' +
711
- 'steps left with TaskCreate or TodoWrite, whichever you have (load it with ToolSearch if it is not in your tool list), ' +
712
+ 'steps left with TaskCreate or TodoWrite, whichever you have (if neither is in your tool list, look for them once ' +
713
+ 'with ToolSearch, and go on without a list if they are not there), ' +
712
714
  'keep one task in_progress, and mark each completed as you finish it. The user follows your progress from that list.'
713
715
 
714
716
  /** `autoPlan` in Kvali's config file; on unless set to false. */
package/dist/kvali.mjs CHANGED
@@ -5216,9 +5216,228 @@ var HookHub = class {
5216
5216
  };
5217
5217
 
5218
5218
  // ../core/src/hooks/claude-install.ts
5219
- import { promises as fsp5 } from "node:fs";
5219
+ import { promises as fsp6 } from "node:fs";
5220
5220
  import os2 from "node:os";
5221
+ import path14 from "node:path";
5222
+
5223
+ // ../core/src/hooks/claude-plugin.ts
5224
+ import { execFile } from "node:child_process";
5225
+ import { createHash } from "node:crypto";
5226
+ import { constants as fsc, promises as fsp5 } from "node:fs";
5221
5227
  import path13 from "node:path";
5228
+ var CLAUDE_PLUGIN_ID = "kvali@kvali";
5229
+ var CLAUDE_MARKETPLACE = "kvali";
5230
+ var kvaliPluginDir = (home) => path13.join(home, ".kvali", "claude-plugin");
5231
+ var stateFile = (home) => path13.join(home, ".kvali", "state.json");
5232
+ async function filesUnder(dir, base = dir) {
5233
+ const out = [];
5234
+ let entries;
5235
+ try {
5236
+ entries = await fsp5.readdir(dir, { withFileTypes: true });
5237
+ } catch {
5238
+ return out;
5239
+ }
5240
+ for (const e of entries) {
5241
+ const full = path13.join(dir, e.name);
5242
+ if (e.isDirectory()) {
5243
+ if (path13.relative(base, full) === path13.join(".claude-plugin", "types")) continue;
5244
+ out.push(...await filesUnder(full, base));
5245
+ } else if (e.isFile()) out.push(path13.relative(base, full));
5246
+ }
5247
+ return out.sort();
5248
+ }
5249
+ async function pluginFingerprint(dir) {
5250
+ const files = await filesUnder(dir);
5251
+ if (!files.length) return void 0;
5252
+ const h = createHash("sha256");
5253
+ for (const f of files) {
5254
+ h.update(f.split(path13.sep).join("/"));
5255
+ h.update("\0");
5256
+ h.update(await fsp5.readFile(path13.join(dir, f)));
5257
+ h.update("\0");
5258
+ }
5259
+ return h.digest("hex");
5260
+ }
5261
+ async function pluginVersion(dir) {
5262
+ try {
5263
+ const v = JSON.parse(await fsp5.readFile(path13.join(dir, ".claude-plugin", "plugin.json"), "utf8")).version;
5264
+ return typeof v === "string" ? v : void 0;
5265
+ } catch {
5266
+ return void 0;
5267
+ }
5268
+ }
5269
+ function compareVersions(a, b) {
5270
+ const parts = (v) => v.split(/[.+-]/).slice(0, 3).map((n) => Number.parseInt(n, 10) || 0);
5271
+ const [x, y] = [parts(a), parts(b)];
5272
+ for (let i = 0; i < 3; i += 1) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (x[i] ?? 0) - (y[i] ?? 0);
5273
+ return 0;
5274
+ }
5275
+ async function syncClaudePlugin(bundledDir, home) {
5276
+ const target = kvaliPluginDir(home);
5277
+ const [want, have] = await Promise.all([pluginFingerprint(bundledDir), pluginFingerprint(target)]);
5278
+ if (!want) throw new Error(`the Claude Code plugin is missing from ${bundledDir}`);
5279
+ if (want === have) return false;
5280
+ const [mine, theirs] = await Promise.all([pluginVersion(bundledDir), pluginVersion(target)]);
5281
+ if (mine && theirs && compareVersions(mine, theirs) < 0) return false;
5282
+ const next = `${target}.next`;
5283
+ await fsp5.rm(next, { recursive: true, force: true });
5284
+ await fsp5.mkdir(path13.dirname(target), { recursive: true });
5285
+ await fsp5.cp(bundledDir, next, { recursive: true });
5286
+ await fsp5.rm(target, { recursive: true, force: true });
5287
+ await fsp5.rename(next, target);
5288
+ return true;
5289
+ }
5290
+ async function claudeExtensionDirs(home) {
5291
+ const roots = [".vscode", ".vscode-insiders", ".vscode-oss", ".cursor", ".windsurf", ".antigravity", ".antigravity-ide", ".kiro"].map(
5292
+ (d) => path13.join(home, d, "extensions")
5293
+ );
5294
+ const found = [];
5295
+ for (const root of roots) {
5296
+ let names = [];
5297
+ try {
5298
+ names = await fsp5.readdir(root);
5299
+ } catch {
5300
+ continue;
5301
+ }
5302
+ for (const n of names) if (n.toLowerCase().startsWith("anthropic.claude-code-")) found.push(path13.join(root, n));
5303
+ }
5304
+ const ver = (p2) => (/-(\d+)\.(\d+)\.(\d+)/.exec(path13.basename(p2)) ?? []).slice(1).map(Number);
5305
+ return found.sort((a, b) => {
5306
+ const [x, y] = [ver(a), ver(b)];
5307
+ for (let i = 0; i < 3; i += 1) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (y[i] ?? 0) - (x[i] ?? 0);
5308
+ return 0;
5309
+ });
5310
+ }
5311
+ async function findClaudeBinary(opts) {
5312
+ const win = (opts.platform ?? process.platform) === "win32";
5313
+ const names = win ? ["claude.exe", "claude.cmd"] : ["claude"];
5314
+ const candidates = [];
5315
+ for (const d of opts.extensionDirs ?? []) {
5316
+ const bin = path13.join(d, "resources", "native-binary");
5317
+ let inside = [];
5318
+ try {
5319
+ inside = await fsp5.readdir(bin);
5320
+ } catch {
5321
+ continue;
5322
+ }
5323
+ const ranked = inside.filter((n) => /^claude([-.].*)?$/i.test(n) && !/\.(json|md|txt|map)$/i.test(n)).sort((x, y) => x.length - y.length);
5324
+ for (const n of ranked) candidates.push(path13.join(bin, n));
5325
+ }
5326
+ for (const dir of (opts.env?.PATH ?? opts.env?.Path ?? "").split(path13.delimiter)) if (dir) for (const n of names) candidates.push(path13.join(dir, n));
5327
+ candidates.push(path13.join(opts.home, ".claude", "local", names[0]), path13.join(opts.home, ".local", "bin", names[0]));
5328
+ if (!win) candidates.push("/opt/homebrew/bin/claude", "/usr/local/bin/claude");
5329
+ for (const c of candidates) {
5330
+ try {
5331
+ await fsp5.access(c, win ? fsc.F_OK : fsc.X_OK);
5332
+ if ((await fsp5.stat(c)).isFile()) return c;
5333
+ } catch {
5334
+ }
5335
+ }
5336
+ return void 0;
5337
+ }
5338
+ function runClaude(bin, args, env, timeoutMs = 6e4) {
5339
+ const cmdShim = process.platform === "win32" && /\.cmd$/i.test(bin);
5340
+ const argv = cmdShim ? args.map((a) => /[\s"]/.test(a) ? `"${a.replace(/"/g, '\\"')}"` : a) : [...args];
5341
+ return new Promise((resolve) => {
5342
+ execFile(
5343
+ cmdShim ? `"${bin}"` : bin,
5344
+ argv,
5345
+ { env, timeout: timeoutMs, windowsHide: true, maxBuffer: 8 * 1024 * 1024, shell: cmdShim },
5346
+ (err, stdout, stderr) => {
5347
+ const code = err ? typeof err.code === "number" ? err.code : 1 : 0;
5348
+ resolve({ code, out: `${stdout ?? ""}${stderr ?? ""}` });
5349
+ }
5350
+ );
5351
+ });
5352
+ }
5353
+ function lastLine(text) {
5354
+ const lines = text.replace(/\x1b\[[0-9;]*m/g, "").split("\n").map((l) => l.trim()).filter(Boolean);
5355
+ return lines.at(-1) ?? "";
5356
+ }
5357
+ async function listedPlugin(bin, env) {
5358
+ const r = await runClaude(bin, ["plugin", "list", "--json"], env);
5359
+ if (r.code !== 0) return void 0;
5360
+ try {
5361
+ const start = r.out.indexOf("[");
5362
+ const list = JSON.parse(r.out.slice(start));
5363
+ return list.find((p2) => p2.id === CLAUDE_PLUGIN_ID);
5364
+ } catch {
5365
+ return void 0;
5366
+ }
5367
+ }
5368
+ async function installClaudePlugin(bin, dir, env) {
5369
+ const valid = await runClaude(bin, ["plugin", "validate", dir], env);
5370
+ if (valid.code !== 0) return { ok: false, unsupported: true, error: `this Claude Code cannot load the plugin (${lastLine(valid.out) || `exit ${valid.code}`})` };
5371
+ const added = await runClaude(bin, ["plugin", "marketplace", "add", dir], env);
5372
+ if (added.code !== 0 && !/already/i.test(added.out)) return { ok: false, unsupported: false, error: lastLine(added.out) || "could not add the plugin folder" };
5373
+ const installed = await runClaude(bin, ["plugin", "install", CLAUDE_PLUGIN_ID], env);
5374
+ if (installed.code !== 0 && !/already installed/i.test(installed.out)) return { ok: false, unsupported: false, error: lastLine(installed.out) || "could not install the plugin" };
5375
+ const listed = await listedPlugin(bin, env);
5376
+ if (!listed) return { ok: false, unsupported: false, error: "Claude Code does not list the plugin after installing it" };
5377
+ if (listed.enabled === false) {
5378
+ const enabled = await runClaude(bin, ["plugin", "enable", CLAUDE_PLUGIN_ID], env);
5379
+ if (enabled.code !== 0) return { ok: false, unsupported: false, error: lastLine(enabled.out) || "could not enable the plugin" };
5380
+ }
5381
+ return { ok: true, version: listed.version };
5382
+ }
5383
+ async function claudePluginEnabled(settingsFile) {
5384
+ try {
5385
+ const s = JSON.parse(await fsp5.readFile(settingsFile, "utf8"));
5386
+ return s?.enabledPlugins?.[CLAUDE_PLUGIN_ID] === true;
5387
+ } catch {
5388
+ return false;
5389
+ }
5390
+ }
5391
+ async function readKvaliState(home) {
5392
+ try {
5393
+ return JSON.parse(await fsp5.readFile(stateFile(home), "utf8")) ?? {};
5394
+ } catch {
5395
+ return {};
5396
+ }
5397
+ }
5398
+ async function writeKvaliState(home, patch) {
5399
+ const next = { ...await readKvaliState(home), ...patch };
5400
+ await fsp5.mkdir(path13.dirname(stateFile(home)), { recursive: true });
5401
+ await fsp5.writeFile(stateFile(home), `${JSON.stringify(next, null, 2)}
5402
+ `);
5403
+ }
5404
+ async function removeClaudePlugin(opts) {
5405
+ const state = await readKvaliState(opts.home);
5406
+ if (!state.claudePlugin) return false;
5407
+ const dir = kvaliPluginDir(opts.home);
5408
+ if (opts.bin) {
5409
+ await runClaude(opts.bin, ["plugin", "uninstall", CLAUDE_PLUGIN_ID], opts.env);
5410
+ const list = await runClaude(opts.bin, ["plugin", "marketplace", "list", "--json"], opts.env);
5411
+ try {
5412
+ const mk = JSON.parse(list.out.slice(list.out.indexOf("["))).find((m) => m.name === CLAUDE_MARKETPLACE);
5413
+ if (mk && mk.path && path13.resolve(mk.path) === path13.resolve(dir)) await runClaude(opts.bin, ["plugin", "marketplace", "remove", CLAUDE_MARKETPLACE], opts.env);
5414
+ } catch {
5415
+ }
5416
+ } else {
5417
+ try {
5418
+ const raw = await fsp5.readFile(opts.settingsFile, "utf8");
5419
+ const s = JSON.parse(raw);
5420
+ let changed = false;
5421
+ if (s.enabledPlugins && CLAUDE_PLUGIN_ID in s.enabledPlugins) {
5422
+ delete s.enabledPlugins[CLAUDE_PLUGIN_ID];
5423
+ changed = true;
5424
+ }
5425
+ const mk = s.extraKnownMarketplaces?.[CLAUDE_MARKETPLACE];
5426
+ if (mk?.source?.path && path13.resolve(mk.source.path) === path13.resolve(dir)) {
5427
+ delete s.extraKnownMarketplaces[CLAUDE_MARKETPLACE];
5428
+ changed = true;
5429
+ }
5430
+ if (changed) await fsp5.writeFile(opts.settingsFile, `${JSON.stringify(s, null, 2)}
5431
+ `);
5432
+ } catch {
5433
+ }
5434
+ }
5435
+ await fsp5.rm(dir, { recursive: true, force: true });
5436
+ await writeKvaliState(opts.home, { claudePlugin: false });
5437
+ return true;
5438
+ }
5439
+
5440
+ // ../core/src/hooks/claude-install.ts
5222
5441
  var CLAUDE_HOOKS = [
5223
5442
  { event: "UserPromptSubmit", sync: true },
5224
5443
  { event: "Notification", sync: false },
@@ -5228,8 +5447,8 @@ var CLAUDE_HOOKS = [
5228
5447
  var CLAUDE_HOOK_EVENTS = CLAUDE_HOOKS.map((h) => h.event);
5229
5448
  var MARKER = "/v1/events/claude-code";
5230
5449
  function claudeSettingsPath(home = os2.homedir(), env = process.env) {
5231
- const dir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path13.join(home, ".claude");
5232
- return path13.join(dir, "settings.json");
5450
+ const dir = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path14.join(home, ".claude");
5451
+ return path14.join(dir, "settings.json");
5233
5452
  }
5234
5453
  function claudeHookCommand(port = DEFAULT_HOOK_PORT, sync = false) {
5235
5454
  const url = `http://127.0.0.1:${port}${MARKER}`;
@@ -5241,7 +5460,7 @@ function hookEntry(spec, port) {
5241
5460
  async function readSettings(file) {
5242
5461
  let text;
5243
5462
  try {
5244
- text = await fsp5.readFile(file, "utf8");
5463
+ text = await fsp6.readFile(file, "utf8");
5245
5464
  } catch (err) {
5246
5465
  if (err.code === "ENOENT") return {};
5247
5466
  throw err;
@@ -5298,13 +5517,13 @@ async function claudeHooksStatus(file = claudeSettingsPath(), port = DEFAULT_HOO
5298
5517
  return current === CLAUDE_HOOKS.length && total === CLAUDE_HOOKS.length ? "installed" : "outdated";
5299
5518
  }
5300
5519
  async function writeWithBackup(file, before, settings) {
5301
- await fsp5.mkdir(path13.dirname(file), { recursive: true });
5520
+ await fsp6.mkdir(path14.dirname(file), { recursive: true });
5302
5521
  let backup;
5303
5522
  if (before !== void 0) {
5304
5523
  backup = `${file}.kvali-backup`;
5305
- await fsp5.writeFile(backup, before);
5524
+ await fsp6.writeFile(backup, before);
5306
5525
  }
5307
- await fsp5.writeFile(file, JSON.stringify(settings, null, 2) + "\n");
5526
+ await fsp6.writeFile(file, JSON.stringify(settings, null, 2) + "\n");
5308
5527
  return backup;
5309
5528
  }
5310
5529
  function canonical(v) {
@@ -5314,7 +5533,7 @@ function canonical(v) {
5314
5533
  );
5315
5534
  }
5316
5535
  async function installClaudeHooks(file = claudeSettingsPath(), port = DEFAULT_HOOK_PORT) {
5317
- const before = await fsp5.readFile(file, "utf8").catch(() => void 0);
5536
+ const before = await fsp6.readFile(file, "utf8").catch(() => void 0);
5318
5537
  const current = await readSettings(file);
5319
5538
  const settings = withoutKvali(current);
5320
5539
  settings.hooks = settings.hooks && typeof settings.hooks === "object" ? settings.hooks : {};
@@ -5325,8 +5544,40 @@ async function installClaudeHooks(file = claudeSettingsPath(), port = DEFAULT_HO
5325
5544
  if (before !== void 0 && canonical(settings) === canonical(current)) return { changed: false };
5326
5545
  return { backup: await writeWithBackup(file, before, settings), changed: true };
5327
5546
  }
5547
+ var CLAUDE_TODO_TOOLS_ENV = "CLAUDE_CODE_ENABLE_TODO_TOOLS";
5548
+ function envOf(settings) {
5549
+ return settings.env && typeof settings.env === "object" && !Array.isArray(settings.env) ? settings.env : void 0;
5550
+ }
5551
+ async function enableClaudeTodoTools(file, home) {
5552
+ const before = await fsp6.readFile(file, "utf8").catch(() => void 0);
5553
+ const settings = await readSettings(file);
5554
+ const env = envOf(settings);
5555
+ if (env && CLAUDE_TODO_TOOLS_ENV in env) return { changed: false };
5556
+ settings.env = { ...env ?? {}, [CLAUDE_TODO_TOOLS_ENV]: "1" };
5557
+ await writeWithBackup(file, before, settings);
5558
+ await writeKvaliState(home, { claudeTodoTools: true });
5559
+ return { changed: true };
5560
+ }
5561
+ async function disableClaudeTodoTools(file, home) {
5562
+ if (!(await readKvaliState(home)).claudeTodoTools) return { changed: false };
5563
+ const before = await fsp6.readFile(file, "utf8").catch(() => void 0);
5564
+ let changed = false;
5565
+ if (before !== void 0) {
5566
+ const settings = await readSettings(file);
5567
+ const env = envOf(settings);
5568
+ if (env?.[CLAUDE_TODO_TOOLS_ENV] === "1") {
5569
+ const { [CLAUDE_TODO_TOOLS_ENV]: _gone, ...rest } = env;
5570
+ if (Object.keys(rest).length) settings.env = rest;
5571
+ else delete settings.env;
5572
+ await writeWithBackup(file, before, settings);
5573
+ changed = true;
5574
+ }
5575
+ }
5576
+ await writeKvaliState(home, { claudeTodoTools: false });
5577
+ return { changed };
5578
+ }
5328
5579
  async function uninstallClaudeHooks(file = claudeSettingsPath()) {
5329
- const before = await fsp5.readFile(file, "utf8").catch(() => void 0);
5580
+ const before = await fsp6.readFile(file, "utf8").catch(() => void 0);
5330
5581
  if (before === void 0) return { changed: false };
5331
5582
  const settings = await readSettings(file);
5332
5583
  const next = withoutKvali(settings);
@@ -5335,8 +5586,8 @@ async function uninstallClaudeHooks(file = claudeSettingsPath()) {
5335
5586
  }
5336
5587
 
5337
5588
  // ../core/src/protocol.ts
5338
- import { promises as fsp6 } from "node:fs";
5339
- import path14 from "node:path";
5589
+ import { promises as fsp7 } from "node:fs";
5590
+ import path15 from "node:path";
5340
5591
  var PROGRESS_PROTOCOL_MARKER = "<!-- kvali:progress-protocol v2 -->";
5341
5592
  function progressProtocolSnippet() {
5342
5593
  return `${PROGRESS_PROTOCOL_MARKER}
@@ -5388,13 +5639,13 @@ function withBlock(text, name, snippet) {
5388
5639
  return { text: `${text}${sep}${snippet}`, result: "added" };
5389
5640
  }
5390
5641
  function globalInstructionFiles(home, env = {}) {
5391
- const claude = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path14.join(home, ".claude");
5392
- const codex = env.CODEX_HOME || path14.join(home, ".codex");
5393
- const gemini = path14.join(home, ".gemini");
5642
+ const claude = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim() || path15.join(home, ".claude");
5643
+ const codex = env.CODEX_HOME || path15.join(home, ".codex");
5644
+ const gemini = path15.join(home, ".gemini");
5394
5645
  return [
5395
- { id: "claude-code", agent: "Claude Code", dir: claude, file: path14.join(claude, "CLAUDE.md") },
5396
- { id: "codex", agent: "Codex", dir: codex, file: path14.join(codex, "AGENTS.md") },
5397
- { id: "gemini", agent: "Gemini CLI / Antigravity", dir: gemini, file: path14.join(gemini, "GEMINI.md") }
5646
+ { id: "claude-code", agent: "Claude Code", dir: claude, file: path15.join(claude, "CLAUDE.md") },
5647
+ { id: "codex", agent: "Codex", dir: codex, file: path15.join(codex, "AGENTS.md") },
5648
+ { id: "gemini", agent: "Gemini CLI / Antigravity", dir: gemini, file: path15.join(gemini, "GEMINI.md") }
5398
5649
  ];
5399
5650
  }
5400
5651
  var PLAN_RULE_END = "<!-- /kvali:plan-rule -->";
@@ -5403,7 +5654,7 @@ async function removeGlobalPlanRule(home, env = {}) {
5403
5654
  for (const target of globalInstructionFiles(home, env)) {
5404
5655
  let text;
5405
5656
  try {
5406
- text = await fsp6.readFile(target.file, "utf8");
5657
+ text = await fsp7.readFile(target.file, "utf8");
5407
5658
  } catch {
5408
5659
  continue;
5409
5660
  }
@@ -5412,15 +5663,15 @@ async function removeGlobalPlanRule(home, env = {}) {
5412
5663
  const endAt = text.indexOf(PLAN_RULE_END, start);
5413
5664
  const end2 = endAt === -1 ? text.length : endAt + PLAN_RULE_END.length;
5414
5665
  const next = (text.slice(0, start).replace(/\n+$/, "\n") + text.slice(end2).replace(/^\n+/, "")).replace(/^\n+$/, "");
5415
- if (next.trim() === "") await fsp6.unlink(target.file);
5416
- else await fsp6.writeFile(target.file, next);
5666
+ if (next.trim() === "") await fsp7.unlink(target.file);
5667
+ else await fsp7.writeFile(target.file, next);
5417
5668
  changed.push(target.file);
5418
5669
  }
5419
5670
  return changed;
5420
5671
  }
5421
5672
  async function readOptional(file) {
5422
5673
  try {
5423
- return await fsp6.readFile(file, "utf8");
5674
+ return await fsp7.readFile(file, "utf8");
5424
5675
  } catch {
5425
5676
  return void 0;
5426
5677
  }
@@ -5430,32 +5681,32 @@ async function addGlobalPlanRule(home, env = {}, only) {
5430
5681
  for (const target of globalInstructionFiles(home, env)) {
5431
5682
  if (only && !only.includes(target.id)) continue;
5432
5683
  try {
5433
- const st = await fsp6.stat(target.dir);
5684
+ const st = await fsp7.stat(target.dir);
5434
5685
  if (!st.isDirectory()) continue;
5435
5686
  } catch {
5436
5687
  continue;
5437
5688
  }
5438
5689
  const next = withBlock(await readOptional(target.file), "plan-rule", planRuleSnippet());
5439
- if (next.result !== "exists") await fsp6.writeFile(target.file, next.text);
5690
+ if (next.result !== "exists") await fsp7.writeFile(target.file, next.text);
5440
5691
  out.push({ agent: target.agent, file: target.file, result: next.result });
5441
5692
  }
5442
5693
  return out;
5443
5694
  }
5444
5695
  async function addProgressProtocol(root) {
5445
- const file = path14.join(root, "AGENTS.md");
5696
+ const file = path15.join(root, "AGENTS.md");
5446
5697
  const current = await readOptional(file);
5447
5698
  const next = withBlock(current ?? "# AGENTS.md\n\n", "progress-protocol", progressProtocolSnippet());
5448
- if (next.result !== "exists") await fsp6.writeFile(file, next.text);
5699
+ if (next.result !== "exists") await fsp7.writeFile(file, next.text);
5449
5700
  return { file, result: current === void 0 ? "created" : next.result };
5450
5701
  }
5451
5702
 
5452
5703
  // ../core/src/hooks/replies.ts
5453
5704
  import { existsSync as existsSync2 } from "node:fs";
5454
- import path15 from "node:path";
5455
- 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, load one with ToolSearch first), 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.";
5705
+ import path16 from "node:path";
5706
+ 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.";
5456
5707
  function pluginRunsIn(liveDir, sessionId) {
5457
5708
  if (!/^[A-Za-z0-9-]{8,80}$/.test(sessionId)) return false;
5458
- return existsSync2(path15.join(liveDir, "claude-code", `${sessionId}.mod.json`));
5709
+ return existsSync2(path16.join(liveDir, "claude-code", `${sessionId}.mod.json`));
5459
5710
  }
5460
5711
  function claudeHookReply(ev, session, pluginRuns = false) {
5461
5712
  if (ev.event !== "UserPromptSubmit") return void 0;
@@ -5470,209 +5721,6 @@ function claudeHookReply(ev, session, pluginRuns = false) {
5470
5721
  // ../core/src/setup.ts
5471
5722
  import { promises as fsp8 } from "node:fs";
5472
5723
  import path17 from "node:path";
5473
-
5474
- // ../core/src/hooks/claude-plugin.ts
5475
- import { execFile } from "node:child_process";
5476
- import { createHash } from "node:crypto";
5477
- import { constants as fsc, promises as fsp7 } from "node:fs";
5478
- import path16 from "node:path";
5479
- var CLAUDE_PLUGIN_ID = "kvali@kvali";
5480
- var CLAUDE_MARKETPLACE = "kvali";
5481
- var kvaliPluginDir = (home) => path16.join(home, ".kvali", "claude-plugin");
5482
- var stateFile = (home) => path16.join(home, ".kvali", "state.json");
5483
- async function filesUnder(dir, base = dir) {
5484
- const out = [];
5485
- let entries;
5486
- try {
5487
- entries = await fsp7.readdir(dir, { withFileTypes: true });
5488
- } catch {
5489
- return out;
5490
- }
5491
- for (const e of entries) {
5492
- const full = path16.join(dir, e.name);
5493
- if (e.isDirectory()) {
5494
- if (path16.relative(base, full) === path16.join(".claude-plugin", "types")) continue;
5495
- out.push(...await filesUnder(full, base));
5496
- } else if (e.isFile()) out.push(path16.relative(base, full));
5497
- }
5498
- return out.sort();
5499
- }
5500
- async function pluginFingerprint(dir) {
5501
- const files = await filesUnder(dir);
5502
- if (!files.length) return void 0;
5503
- const h = createHash("sha256");
5504
- for (const f of files) {
5505
- h.update(f.split(path16.sep).join("/"));
5506
- h.update("\0");
5507
- h.update(await fsp7.readFile(path16.join(dir, f)));
5508
- h.update("\0");
5509
- }
5510
- return h.digest("hex");
5511
- }
5512
- async function syncClaudePlugin(bundledDir, home) {
5513
- const target = kvaliPluginDir(home);
5514
- const [want, have] = await Promise.all([pluginFingerprint(bundledDir), pluginFingerprint(target)]);
5515
- if (!want) throw new Error(`the Claude Code plugin is missing from ${bundledDir}`);
5516
- if (want === have) return false;
5517
- const next = `${target}.next`;
5518
- await fsp7.rm(next, { recursive: true, force: true });
5519
- await fsp7.mkdir(path16.dirname(target), { recursive: true });
5520
- await fsp7.cp(bundledDir, next, { recursive: true });
5521
- await fsp7.rm(target, { recursive: true, force: true });
5522
- await fsp7.rename(next, target);
5523
- return true;
5524
- }
5525
- async function claudeExtensionDirs(home) {
5526
- const roots = [".vscode", ".vscode-insiders", ".vscode-oss", ".cursor", ".windsurf", ".antigravity", ".antigravity-ide", ".kiro"].map(
5527
- (d) => path16.join(home, d, "extensions")
5528
- );
5529
- const found = [];
5530
- for (const root of roots) {
5531
- let names = [];
5532
- try {
5533
- names = await fsp7.readdir(root);
5534
- } catch {
5535
- continue;
5536
- }
5537
- for (const n of names) if (n.toLowerCase().startsWith("anthropic.claude-code-")) found.push(path16.join(root, n));
5538
- }
5539
- const ver = (p2) => (/-(\d+)\.(\d+)\.(\d+)/.exec(path16.basename(p2)) ?? []).slice(1).map(Number);
5540
- return found.sort((a, b) => {
5541
- const [x, y] = [ver(a), ver(b)];
5542
- for (let i = 0; i < 3; i += 1) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (y[i] ?? 0) - (x[i] ?? 0);
5543
- return 0;
5544
- });
5545
- }
5546
- async function findClaudeBinary(opts) {
5547
- const win = (opts.platform ?? process.platform) === "win32";
5548
- const names = win ? ["claude.exe", "claude.cmd"] : ["claude"];
5549
- const candidates = [];
5550
- for (const d of opts.extensionDirs ?? []) {
5551
- const bin = path16.join(d, "resources", "native-binary");
5552
- let inside = [];
5553
- try {
5554
- inside = await fsp7.readdir(bin);
5555
- } catch {
5556
- continue;
5557
- }
5558
- const ranked = inside.filter((n) => /^claude([-.].*)?$/i.test(n) && !/\.(json|md|txt|map)$/i.test(n)).sort((x, y) => x.length - y.length);
5559
- for (const n of ranked) candidates.push(path16.join(bin, n));
5560
- }
5561
- for (const dir of (opts.env?.PATH ?? opts.env?.Path ?? "").split(path16.delimiter)) if (dir) for (const n of names) candidates.push(path16.join(dir, n));
5562
- candidates.push(path16.join(opts.home, ".claude", "local", names[0]), path16.join(opts.home, ".local", "bin", names[0]));
5563
- if (!win) candidates.push("/opt/homebrew/bin/claude", "/usr/local/bin/claude");
5564
- for (const c of candidates) {
5565
- try {
5566
- await fsp7.access(c, win ? fsc.F_OK : fsc.X_OK);
5567
- if ((await fsp7.stat(c)).isFile()) return c;
5568
- } catch {
5569
- }
5570
- }
5571
- return void 0;
5572
- }
5573
- function runClaude(bin, args, env, timeoutMs = 6e4) {
5574
- const cmdShim = process.platform === "win32" && /\.cmd$/i.test(bin);
5575
- const argv = cmdShim ? args.map((a) => /[\s"]/.test(a) ? `"${a.replace(/"/g, '\\"')}"` : a) : [...args];
5576
- return new Promise((resolve) => {
5577
- execFile(
5578
- cmdShim ? `"${bin}"` : bin,
5579
- argv,
5580
- { env, timeout: timeoutMs, windowsHide: true, maxBuffer: 8 * 1024 * 1024, shell: cmdShim },
5581
- (err, stdout, stderr) => {
5582
- const code = err ? typeof err.code === "number" ? err.code : 1 : 0;
5583
- resolve({ code, out: `${stdout ?? ""}${stderr ?? ""}` });
5584
- }
5585
- );
5586
- });
5587
- }
5588
- function lastLine(text) {
5589
- const lines = text.replace(/\x1b\[[0-9;]*m/g, "").split("\n").map((l) => l.trim()).filter(Boolean);
5590
- return lines.at(-1) ?? "";
5591
- }
5592
- async function listedPlugin(bin, env) {
5593
- const r = await runClaude(bin, ["plugin", "list", "--json"], env);
5594
- if (r.code !== 0) return void 0;
5595
- try {
5596
- const start = r.out.indexOf("[");
5597
- const list = JSON.parse(r.out.slice(start));
5598
- return list.find((p2) => p2.id === CLAUDE_PLUGIN_ID);
5599
- } catch {
5600
- return void 0;
5601
- }
5602
- }
5603
- async function installClaudePlugin(bin, dir, env) {
5604
- const valid = await runClaude(bin, ["plugin", "validate", dir], env);
5605
- if (valid.code !== 0) return { ok: false, unsupported: true, error: `this Claude Code cannot load the plugin (${lastLine(valid.out) || `exit ${valid.code}`})` };
5606
- const added = await runClaude(bin, ["plugin", "marketplace", "add", dir], env);
5607
- if (added.code !== 0 && !/already/i.test(added.out)) return { ok: false, unsupported: false, error: lastLine(added.out) || "could not add the plugin folder" };
5608
- const installed = await runClaude(bin, ["plugin", "install", CLAUDE_PLUGIN_ID], env);
5609
- if (installed.code !== 0 && !/already installed/i.test(installed.out)) return { ok: false, unsupported: false, error: lastLine(installed.out) || "could not install the plugin" };
5610
- const listed = await listedPlugin(bin, env);
5611
- if (!listed) return { ok: false, unsupported: false, error: "Claude Code does not list the plugin after installing it" };
5612
- if (listed.enabled === false) {
5613
- const enabled = await runClaude(bin, ["plugin", "enable", CLAUDE_PLUGIN_ID], env);
5614
- if (enabled.code !== 0) return { ok: false, unsupported: false, error: lastLine(enabled.out) || "could not enable the plugin" };
5615
- }
5616
- return { ok: true, version: listed.version };
5617
- }
5618
- async function claudePluginEnabled(settingsFile) {
5619
- try {
5620
- const s = JSON.parse(await fsp7.readFile(settingsFile, "utf8"));
5621
- return s?.enabledPlugins?.[CLAUDE_PLUGIN_ID] === true;
5622
- } catch {
5623
- return false;
5624
- }
5625
- }
5626
- async function readKvaliState(home) {
5627
- try {
5628
- return JSON.parse(await fsp7.readFile(stateFile(home), "utf8")) ?? {};
5629
- } catch {
5630
- return {};
5631
- }
5632
- }
5633
- async function writeKvaliState(home, patch) {
5634
- const next = { ...await readKvaliState(home), ...patch };
5635
- await fsp7.mkdir(path16.dirname(stateFile(home)), { recursive: true });
5636
- await fsp7.writeFile(stateFile(home), `${JSON.stringify(next, null, 2)}
5637
- `);
5638
- }
5639
- async function removeClaudePlugin(opts) {
5640
- const state = await readKvaliState(opts.home);
5641
- if (!state.claudePlugin) return false;
5642
- const dir = kvaliPluginDir(opts.home);
5643
- if (opts.bin) {
5644
- await runClaude(opts.bin, ["plugin", "uninstall", CLAUDE_PLUGIN_ID], opts.env);
5645
- const list = await runClaude(opts.bin, ["plugin", "marketplace", "list", "--json"], opts.env);
5646
- try {
5647
- const mk = JSON.parse(list.out.slice(list.out.indexOf("["))).find((m) => m.name === CLAUDE_MARKETPLACE);
5648
- if (mk && mk.path && path16.resolve(mk.path) === path16.resolve(dir)) await runClaude(opts.bin, ["plugin", "marketplace", "remove", CLAUDE_MARKETPLACE], opts.env);
5649
- } catch {
5650
- }
5651
- } else {
5652
- try {
5653
- const raw = await fsp7.readFile(opts.settingsFile, "utf8");
5654
- const s = JSON.parse(raw);
5655
- let changed = false;
5656
- if (s.enabledPlugins && CLAUDE_PLUGIN_ID in s.enabledPlugins) {
5657
- delete s.enabledPlugins[CLAUDE_PLUGIN_ID];
5658
- changed = true;
5659
- }
5660
- const mk = s.extraKnownMarketplaces?.[CLAUDE_MARKETPLACE];
5661
- if (mk?.source?.path && path16.resolve(mk.source.path) === path16.resolve(dir)) {
5662
- delete s.extraKnownMarketplaces[CLAUDE_MARKETPLACE];
5663
- changed = true;
5664
- }
5665
- if (changed) await fsp7.writeFile(opts.settingsFile, `${JSON.stringify(s, null, 2)}
5666
- `);
5667
- } catch {
5668
- }
5669
- }
5670
- await fsp7.rm(dir, { recursive: true, force: true });
5671
- await writeKvaliState(opts.home, { claudePlugin: false });
5672
- return true;
5673
- }
5674
-
5675
- // ../core/src/setup.ts
5676
5724
  async function isDir(p2) {
5677
5725
  try {
5678
5726
  return (await fsp8.stat(p2)).isDirectory();
@@ -5693,7 +5741,7 @@ async function detectAgents(home, env = {}) {
5693
5741
  }
5694
5742
  function setupChanges(d) {
5695
5743
  const out = [];
5696
- if (d.claude) out.push("Claude Code: the Kvali plugin (live progress pane, exact status, alerts, automatic plans), added with Claude Code's own plugin command");
5744
+ if (d.claude) out.push("Claude Code: the Kvali plugin (live progress pane, exact status, alerts, automatic plans), added with Claude Code's own plugin command, and its task-list tools turned on in ~/.claude/settings.json (current Claude models do not get them unless asked)");
5697
5745
  if (d.codex) out.push("Codex: a planning rule in ~/.codex/AGENTS.md");
5698
5746
  if (d.gemini) out.push(`${d.antigravity ? "Antigravity / Gemini CLI" : "Gemini CLI"}: a planning rule in ~/.gemini/GEMINI.md`);
5699
5747
  return out;
@@ -5726,6 +5774,8 @@ async function applySetup(home, env = {}, port = DEFAULT_HOOK_PORT, d, opts = {}
5726
5774
  result.claude = "hooks";
5727
5775
  result.claudeNote = plugin.note;
5728
5776
  }
5777
+ if (opts.autoPlan === false) await disableClaudeTodoTools(settings, home);
5778
+ else await enableClaudeTodoTools(settings, home);
5729
5779
  }
5730
5780
  const only = [];
5731
5781
  if (agents.codex) only.push("codex");
@@ -5738,6 +5788,7 @@ async function removeSetup(home, env = {}, opts = {}) {
5738
5788
  const bin = await findClaudeBinary({ home, env, extensionDirs: [...opts.claudeExtensionDirs ?? [], ...await claudeExtensionDirs(home)] }).catch(() => void 0);
5739
5789
  await removeClaudePlugin({ home, env, settingsFile: settings, bin }).catch(() => void 0);
5740
5790
  await uninstallClaudeHooks(settings).catch(() => void 0);
5791
+ await disableClaudeTodoTools(settings, home).catch(() => void 0);
5741
5792
  await removeGlobalPlanRule(home, env).catch(() => void 0);
5742
5793
  }
5743
5794
 
@@ -8134,7 +8185,7 @@ function qrTerminal(text, color = true) {
8134
8185
  }
8135
8186
 
8136
8187
  // src/index.ts
8137
- var VERSION = "0.7.0";
8188
+ var VERSION = "0.7.1";
8138
8189
  function parse(argv) {
8139
8190
  const opts = {
8140
8191
  json: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kvali/cli",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
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)",