@kvali/cli 0.7.2 → 0.7.4
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.
|
|
3
|
+
"version": "0.7.4",
|
|
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",
|
|
@@ -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
|
-
|
|
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: {},
|
|
@@ -446,7 +457,7 @@ async function taskFiles($: Engine): Promise<{ tasks: KvTask[]; times: Map<strin
|
|
|
446
457
|
continue
|
|
447
458
|
}
|
|
448
459
|
const t = parseTaskFile(text, f.name.slice(0, -5))
|
|
449
|
-
if (!t) continue
|
|
460
|
+
if (!t || rt.foreignTasks.has(t.id)) continue
|
|
450
461
|
tasks.push(t)
|
|
451
462
|
times.set(t.id, f.mtimeMs)
|
|
452
463
|
}
|
|
@@ -781,7 +792,14 @@ export const register: Register = on => {
|
|
|
781
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)))
|
|
782
793
|
}
|
|
783
794
|
if (!isPlan) await update($, recent, list => endAction(list, id, end, ran.deny !== undefined || ran.isError === true))
|
|
784
|
-
else if (
|
|
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') {
|
|
785
803
|
const files = e.tool === 'TodoWrite' ? undefined : await taskFiles($)
|
|
786
804
|
const current = await read($, plan)
|
|
787
805
|
const tasks = files?.tasks ?? applyPlanTool(current.tasks, e.tool, input, ran.result)
|
|
@@ -869,6 +887,7 @@ export const register: Register = on => {
|
|
|
869
887
|
on('agent.spawn', async ($, e, next) => {
|
|
870
888
|
const r = await next(e)
|
|
871
889
|
try {
|
|
890
|
+
if (e.isTeammate && r.agentId) rt.teammates.add(r.agentId)
|
|
872
891
|
if (e.background && !e.parentAgentId && !e.isTeammate && !e.workflow && r.agentId) {
|
|
873
892
|
rt.background.set(r.agentId, { label: e.description, startedAt: await $.clock.now() })
|
|
874
893
|
quiet(refresh($))
|
package/dist/kvali.mjs
CHANGED
|
@@ -80,7 +80,11 @@ function planEta(s, now) {
|
|
|
80
80
|
const left = p2.total - p2.done;
|
|
81
81
|
if (p2.total === 0 || left <= 0) return void 0;
|
|
82
82
|
const spent = s.current ? Math.max(0, now - s.current.startedAt) : 0;
|
|
83
|
-
return
|
|
83
|
+
return restOfPlan(typical, spent, left);
|
|
84
|
+
}
|
|
85
|
+
function restOfPlan(typical, spent, left) {
|
|
86
|
+
if (spent > 2 * typical) return void 0;
|
|
87
|
+
return Math.max(typical - spent, typical / 4) + (left - 1) * typical;
|
|
84
88
|
}
|
|
85
89
|
function fmtClock(ms) {
|
|
86
90
|
return new Date(ms).toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" });
|
|
@@ -1395,6 +1399,8 @@ function loopKey(a) {
|
|
|
1395
1399
|
// ../core/src/adapters/claude-code.ts
|
|
1396
1400
|
var PULSE_FRESH_MS = 3e4;
|
|
1397
1401
|
var PULSE_ACTIVE = /* @__PURE__ */ new Set(["requesting", "thinking", "writing", "tool-input", "running", "needs-you", "stalled"]);
|
|
1402
|
+
var PULSE_ENDED = /* @__PURE__ */ new Set(["idle", "done", "interrupted", "error"]);
|
|
1403
|
+
var WAKE_GRACE_MS = 2 * 6e4;
|
|
1398
1404
|
var WAITING_NOTIFICATIONS = /* @__PURE__ */ new Set([
|
|
1399
1405
|
"permission_prompt",
|
|
1400
1406
|
"elicitation_dialog",
|
|
@@ -1592,6 +1598,8 @@ var ClaudeCodeAdapter = class {
|
|
|
1592
1598
|
maxContext: 0,
|
|
1593
1599
|
tasks: /* @__PURE__ */ new Map(),
|
|
1594
1600
|
pendingCreates: /* @__PURE__ */ new Map(),
|
|
1601
|
+
foreignCreates: /* @__PURE__ */ new Set(),
|
|
1602
|
+
foreignTasks: /* @__PURE__ */ new Set(),
|
|
1595
1603
|
open: /* @__PURE__ */ new Map(),
|
|
1596
1604
|
phase: "idle",
|
|
1597
1605
|
phaseAt: 0,
|
|
@@ -1612,7 +1620,18 @@ var ClaudeCodeAdapter = class {
|
|
|
1612
1620
|
const o = rec;
|
|
1613
1621
|
const ts = parseTime(o.timestamp);
|
|
1614
1622
|
if (tokensOnly) {
|
|
1615
|
-
if (o.type === "assistant" && o.message)
|
|
1623
|
+
if (o.type === "assistant" && o.message) {
|
|
1624
|
+
this.countUsage(st, o, ts, ctx, false);
|
|
1625
|
+
for (const b of Array.isArray(o.message.content) ? o.message.content : []) {
|
|
1626
|
+
if (b?.type === "tool_use" && b.name === "TaskCreate" && typeof b.id === "string") st.foreignCreates.add(b.id);
|
|
1627
|
+
}
|
|
1628
|
+
} else if (o.type === "user" && Array.isArray(o.message?.content) && st.foreignCreates.size) {
|
|
1629
|
+
for (const b of o.message.content) {
|
|
1630
|
+
if (b?.type !== "tool_result" || !st.foreignCreates.delete(b.tool_use_id)) continue;
|
|
1631
|
+
const id = o.toolUseResult?.task?.id ?? /Task #?(\w+) created/i.exec(contentText(b.content))?.[1];
|
|
1632
|
+
if (id !== void 0 && id !== null) st.foreignTasks.add(String(id));
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1616
1635
|
return;
|
|
1617
1636
|
}
|
|
1618
1637
|
if (ts !== void 0) {
|
|
@@ -1647,6 +1666,15 @@ var ClaudeCodeAdapter = class {
|
|
|
1647
1666
|
return;
|
|
1648
1667
|
case "system":
|
|
1649
1668
|
if (o.subtype === "compact_boundary") st.context = void 0;
|
|
1669
|
+
if (!o.isSidechain && (o.subtype === "turn_duration" || o.subtype === "stop_hook_summary" && st.open.size === 0)) {
|
|
1670
|
+
const at = ts ?? st.updatedAt;
|
|
1671
|
+
if (st.phase === "working" || st.phase === "tool") {
|
|
1672
|
+
st.phase = "idle";
|
|
1673
|
+
st.phaseAt = at;
|
|
1674
|
+
}
|
|
1675
|
+
st.open.clear();
|
|
1676
|
+
if (st.turnOpen) this.endTurn(st, at, void 0);
|
|
1677
|
+
}
|
|
1650
1678
|
if (/error|retry/i.test(String(o.subtype ?? "")) || o.level === "error" || o.level === "warning") {
|
|
1651
1679
|
const err = o.error && typeof o.error === "object" ? o.error : {};
|
|
1652
1680
|
const attempt = Number(o.retryAttempt ?? o.attempt ?? err.retryAttempt) || void 0;
|
|
@@ -1719,6 +1747,7 @@ var ClaudeCodeAdapter = class {
|
|
|
1719
1747
|
return;
|
|
1720
1748
|
}
|
|
1721
1749
|
if (typeof m.model === "string" && m.model !== "<synthetic>") st.model = m.model;
|
|
1750
|
+
st.lastModelAt = ts;
|
|
1722
1751
|
this.countUsage(st, o, ts, ctx, true);
|
|
1723
1752
|
if (m.model !== "<synthetic>") st.trouble = void 0;
|
|
1724
1753
|
if (o.isApiErrorMessage || o.error && m.model === "<synthetic>") {
|
|
@@ -1846,6 +1875,7 @@ var ClaudeCodeAdapter = class {
|
|
|
1846
1875
|
if (!st.turnOpen) {
|
|
1847
1876
|
st.phase = "working";
|
|
1848
1877
|
st.phaseAt = ts;
|
|
1878
|
+
st.wokeAt = ts;
|
|
1849
1879
|
st.activity = { kind: "thinking", label: "Thinking", startedAt: ts };
|
|
1850
1880
|
}
|
|
1851
1881
|
}
|
|
@@ -1977,7 +2007,8 @@ var ClaudeCodeAdapter = class {
|
|
|
1977
2007
|
}
|
|
1978
2008
|
}
|
|
1979
2009
|
resolveTasks(st) {
|
|
1980
|
-
|
|
2010
|
+
const own = st.taskDir?.tasks.filter((t) => !st.foreignTasks.has(t.id)) ?? [];
|
|
2011
|
+
if (own.length > 0) return own;
|
|
1981
2012
|
if (st.tasks.size > 0) {
|
|
1982
2013
|
return [...st.tasks.values()].sort((a, b) => Number(a.id) - Number(b.id) || a.id.localeCompare(b.id));
|
|
1983
2014
|
}
|
|
@@ -2007,6 +2038,9 @@ var ClaudeCodeAdapter = class {
|
|
|
2007
2038
|
default:
|
|
2008
2039
|
status = allDone ? "done" : "idle";
|
|
2009
2040
|
}
|
|
2041
|
+
if (status === "working" && !st.turnOpen && st.wokeAt === st.phaseAt && now - st.phaseAt > WAKE_GRACE_MS) {
|
|
2042
|
+
status = allDone ? "done" : "idle";
|
|
2043
|
+
}
|
|
2010
2044
|
let lastSignal = st.updatedAt;
|
|
2011
2045
|
const live = st.pulse ? void 0 : st.live;
|
|
2012
2046
|
if (live?.at && live.at >= st.phaseAt - 1e3) {
|
|
@@ -2065,6 +2099,10 @@ var ClaudeCodeAdapter = class {
|
|
|
2065
2099
|
status = "stale";
|
|
2066
2100
|
detail = "Claude Code stopped responding";
|
|
2067
2101
|
}
|
|
2102
|
+
} else if (beat && beat.at >= st.startedAt && PULSE_ENDED.has(beat.phase) && status === "working" && !background && beat.at >= (st.lastModelAt ?? 0) - 2e3 && now - beat.at > PULSE_FRESH_MS) {
|
|
2103
|
+
status = beat.phase === "error" ? "error" : allDone ? "done" : "idle";
|
|
2104
|
+
if (beat.phase === "interrupted") detail = "Interrupted";
|
|
2105
|
+
else if (beat.phase === "error") detail = st.errorText ?? "Stopped with an error";
|
|
2068
2106
|
}
|
|
2069
2107
|
if (status === "working") {
|
|
2070
2108
|
const stale = staleness(lastSignal, ctx);
|
|
@@ -8526,7 +8564,7 @@ function qrTerminal(text, color = true) {
|
|
|
8526
8564
|
}
|
|
8527
8565
|
|
|
8528
8566
|
// src/index.ts
|
|
8529
|
-
var VERSION = "0.7.
|
|
8567
|
+
var VERSION = "0.7.4";
|
|
8530
8568
|
function parse(argv) {
|
|
8531
8569
|
const opts = {
|
|
8532
8570
|
json: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kvali/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
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)",
|