@kvali/cli 0.7.1 → 0.7.3

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.1",
3
+ "version": "0.7.3",
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",
@@ -20,7 +20,7 @@ With phone notifications set up (`kvali phone`, `kvali phone telegram`, `kvali p
20
20
 
21
21
  ## With the Kvali editor extension
22
22
 
23
- The plugin also writes a small heartbeat file per session to `~/.kvali/live/claude-code/<session>.mod.json`. The [Kvali extension](../../README.md) reads it, so its sidebar shows the same exact state for every Claude Code session on your machine, and it can tell "thinking for 6 minutes" from "Claude Code was closed or froze". The heartbeat never leaves your computer.
23
+ The plugin also writes a small heartbeat file per session to `~/.kvali/live/claude-code/<session>.mod.json`: what the session is doing (the running action's short label and detail), the current step, and your plan usage. The [Kvali extension](../../README.md) reads it, so its sidebar shows the same exact state for every Claude Code session on your machine, and it can tell "thinking for 6 minutes" from "Claude Code was closed or froze". The heartbeat never leaves your computer.
24
24
 
25
25
  ## Install
26
26
 
@@ -41,6 +41,6 @@ claude plugin test packages/claude-plugin
41
41
 
42
42
  ## Privacy
43
43
 
44
- The plugin keeps its state on your computer and has no telemetry. It sends something only when you set up phone notifications: short status lines to the ntfy server, Telegram bot or Discord channel you chose, never code or prompts. [Privacy](https://github.com/webGrandpa/kvali/blob/main/PRIVACY.md) · [Security policy](https://github.com/webGrandpa/kvali/blob/main/SECURITY.md) · MIT License
44
+ The plugin keeps its state on your computer and has no telemetry. It sends something only when you set up phone notifications: short status lines to the ntfy server, Telegram bot or Discord channel you chose, never code, prompts or command lines. [Privacy](https://github.com/webGrandpa/kvali/blob/main/PRIVACY.md) · [Security policy](https://github.com/webGrandpa/kvali/blob/main/SECURITY.md) · MIT License
45
45
 
46
46
  Kvali is an independent open-source project, not affiliated with or endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic, used only to say what this plugin works with.
@@ -60,7 +60,8 @@ export function typicalMs(plan: KvPlan): number | undefined {
60
60
 
61
61
  /**
62
62
  * How long the rest of the plan should take at its own pace: the typical step for each step
63
- * left, less the time already spent on the current one. Undefined until a step has finished.
63
+ * left, less the time already spent on the current one. Undefined until a step has finished,
64
+ * and while the current step runs past twice its usual time.
64
65
  */
65
66
  export function planEtaMs(plan: KvPlan, now: number): number | undefined {
66
67
  const typical = typicalMs(plan)
@@ -69,7 +70,10 @@ export function planEtaMs(plan: KvPlan, now: number): number | undefined {
69
70
  const left = p.total - p.done
70
71
  if (!p.total || left <= 0) return undefined
71
72
  const spent = p.current && plan.step ? Math.max(0, now - plan.step.startedAt) : 0
72
- return Math.max(0, typical - spent) + (left - 1) * typical
73
+ // A step past twice its usual time is one the earlier steps say nothing about: no estimate.
74
+ // One just past its usual time is not done yet: a quarter of a step still counts.
75
+ if (spent > 2 * typical) return undefined
76
+ return Math.max(typical - spent, typical / 4) + (left - 1) * typical
73
77
  }
74
78
 
75
79
  /** One usage window as Claude Code reports it (`session.measure`, `$.session.usage()`). */
@@ -156,6 +160,12 @@ export function sortTasks(tasks: KvTask[]): KvTask[] {
156
160
  * Applies a plan tool call to the task list. `input` is the call's arguments,
157
161
  * `result` the tool's structured result (TaskCreate answers the new id).
158
162
  */
163
+ /** The id of the task a TaskCreate made, from its result. */
164
+ export function createdTaskId(result: unknown): string | undefined {
165
+ const id = (result as { task?: { id?: unknown } } | undefined)?.task?.id
166
+ return id === undefined || id === null ? undefined : String(id)
167
+ }
168
+
159
169
  export function applyPlanTool(tasks: readonly KvTask[], tool: string, input: Record<string, unknown>, result: unknown): KvTask[] {
160
170
  if (tool === 'TodoWrite' && Array.isArray(input.todos)) {
161
171
  return (input.todos as Record<string, unknown>[]).map((t, i) => ({
@@ -14,6 +14,7 @@ import {
14
14
  STALL_MS,
15
15
  advance,
16
16
  applyPlanTool,
17
+ createdTaskId,
17
18
  baseName,
18
19
  autoPlanEnabled,
19
20
  ntfyBody,
@@ -162,6 +163,14 @@ type Runtime = {
162
163
  background: Map<string, { label: string; startedAt: number }>
163
164
  /** Agents whose run's end was heard: the engine's list may call one running a moment longer. */
164
165
  finished: Set<string>
166
+ /**
167
+ * Tasks subagents made for their own work. Their plans are theirs, not the session's: a
168
+ * subagent's TodoWrite would otherwise replace the session's plan, and a task list the
169
+ * engine shares with them would add their steps to it.
170
+ */
171
+ foreignTasks: Set<string>
172
+ /** Teammates of an agent team: the task list they share with the session is the team's plan. */
173
+ teammates: Set<string>
165
174
  /**
166
175
  * A task whose answer handed work to background agents: its end (the phone, the toast) waits
167
176
  * for theirs and for the turn their reports start. `idleSince`: all done, and nothing woke it.
@@ -222,6 +231,8 @@ const fresh = (): Runtime => ({
222
231
  mode: undefined,
223
232
  background: new Map(),
224
233
  finished: new Set(),
234
+ foreignTasks: new Set(),
235
+ teammates: new Set(),
225
236
  held: undefined,
226
237
  limits: undefined,
227
238
  limitSamples: {},
@@ -303,7 +314,8 @@ async function doRefresh($: Engine, force: boolean): Promise<void> {
303
314
  if (loop && rt.pushedLoopFor !== loop.since) {
304
315
  rt.pushedLoopFor = loop.since
305
316
  const u = await read($, usage)
306
- quiet(push($, 'loop', { loop: { what: loop.detail ?? loop.label, count: loop.count, sameError: loop.sameError, forMs: now - loop.since, tokens: totalTokens(u) - loop.tokensAtStart || undefined } }))
317
+ // Claude's description of the command ("Run the tests"), never the command line itself.
318
+ quiet(push($, 'loop', { loop: { what: loop.label, count: loop.count, sameError: loop.sameError, forMs: now - loop.since, tokens: totalTokens(u) - loop.tokensAtStart || undefined } }))
307
319
  }
308
320
  if (rt.pendingPause && !rt.turnActive && now - rt.pendingPause.at >= ASK_PUSH_AFTER_MS) {
309
321
  const { workedMs, sequence } = rt.pendingPause
@@ -445,7 +457,7 @@ async function taskFiles($: Engine): Promise<{ tasks: KvTask[]; times: Map<strin
445
457
  continue
446
458
  }
447
459
  const t = parseTaskFile(text, f.name.slice(0, -5))
448
- if (!t) continue
460
+ if (!t || rt.foreignTasks.has(t.id)) continue
449
461
  tasks.push(t)
450
462
  times.set(t.id, f.mtimeMs)
451
463
  }
@@ -780,7 +792,14 @@ export const register: Register = on => {
780
792
  noteCall(rt.loops, loopKey(e.tool, describeTool(e.tool, input, rt.cwd)), describeTool(e.tool, input, rt.cwd), ran.isError === true ? resultText(ran.result) : undefined, end, totalTokens(await read($, usage)))
781
793
  }
782
794
  if (!isPlan) await update($, recent, list => endAction(list, id, end, ran.deny !== undefined || ran.isError === true))
783
- else if (ran.deny === undefined && !ran.isError && e.tool !== 'TaskList' && e.tool !== 'TaskGet') {
795
+ else if (e.agentId && (e.tool === 'TodoWrite' || !rt.teammates.has(e.agentId))) {
796
+ // A subagent's plan is its own: the session's progress bar follows the main loop (and an
797
+ // agent team's shared list). Its tasks are left out of the list, should the engine share it.
798
+ if (e.tool === 'TaskCreate' && ran.deny === undefined && !ran.isError) {
799
+ const made = createdTaskId(ran.result)
800
+ if (made !== undefined) rt.foreignTasks.add(made)
801
+ }
802
+ } else if (ran.deny === undefined && !ran.isError && e.tool !== 'TaskList' && e.tool !== 'TaskGet') {
784
803
  const files = e.tool === 'TodoWrite' ? undefined : await taskFiles($)
785
804
  const current = await read($, plan)
786
805
  const tasks = files?.tasks ?? applyPlanTool(current.tasks, e.tool, input, ran.result)
@@ -868,6 +887,7 @@ export const register: Register = on => {
868
887
  on('agent.spawn', async ($, e, next) => {
869
888
  const r = await next(e)
870
889
  try {
890
+ if (e.isTeammate && r.agentId) rt.teammates.add(r.agentId)
871
891
  if (e.background && !e.parentAgentId && !e.isTeammate && !e.workflow && r.agentId) {
872
892
  rt.background.set(r.agentId, { label: e.description, startedAt: await $.clock.now() })
873
893
  quiet(refresh($))