@kvali/cli 0.6.8 → 0.7.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.
- package/README.md +14 -5
- package/dist/claude-plugin/.claude-plugin/marketplace.json +1 -1
- package/dist/claude-plugin/.claude-plugin/plugin.json +2 -2
- package/dist/claude-plugin/README.md +6 -3
- package/dist/claude-plugin/hooks/model.ts +240 -12
- package/dist/claude-plugin/hooks/register.tsx +196 -12
- package/dist/kvali.mjs +3228 -223
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# kvali
|
|
2
2
|
|
|
3
|
-
**One progress bar for every AI coding agent, in your terminal.** Live task progress, the current step and what the agent is doing right now, tokens and phone alerts for Claude Code, Codex, Gemini CLI, Antigravity and any agent that reads `AGENTS.md`. Grouped by project. Local and read-only.
|
|
3
|
+
**One progress bar for every AI coding agent, in your terminal.** Live task progress, the current step and the time left, what the agent is doing right now, tokens, plan limits and phone alerts for Claude Code, Codex, Gemini CLI, Antigravity, GitHub Copilot, Cline, Roo Code, Kilo Code, OpenCode and any agent that reads `AGENTS.md`. Grouped by project. Local and read-only.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npx @kvali/cli # live dashboard (q to quit)
|
|
@@ -15,10 +15,18 @@ Installed once with `npm install -g @kvali/cli`, the command is just `kvali`, as
|
|
|
15
15
|
```bash
|
|
16
16
|
kvali setup # alerts and automatic plans for every agent found
|
|
17
17
|
kvali phone # progress and alerts on your phone (shows a QR code for the free ntfy app)
|
|
18
|
+
kvali phone telegram # or through a Telegram bot of your own; kvali phone discord: a Discord channel
|
|
18
19
|
```
|
|
19
20
|
|
|
20
21
|
`kvali setup` installs Kvali's Claude Code plugin with Claude Code's own command (a live progress pane beside the chat, exact status, alerts) and asks Codex and Gemini CLI / Antigravity to keep a plan, so every task gets a real progress bar. `kvali setup off` removes all of it.
|
|
21
22
|
|
|
23
|
+
## Your week
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
kvali week # the last seven days of all your agents, and a post to share them
|
|
27
|
+
kvali week --svg # the same as a card (1200×630 SVG)
|
|
28
|
+
```
|
|
29
|
+
|
|
22
30
|
## Without a dashboard
|
|
23
31
|
|
|
24
32
|
```bash
|
|
@@ -27,14 +35,15 @@ kvali watch # hooks and phone notifications only, e.g. in the backgro
|
|
|
27
35
|
|
|
28
36
|
## More
|
|
29
37
|
|
|
30
|
-
- `kvali phone test` / `kvali phone off`; options `--events needs-you,done,steps,actions,error,stuck` (what reaches the phone), `--done-after <seconds>` (the shortest task worth a notification; 0: every task), `--private` (no project or step names in notifications), `--server <url>` for your own ntfy server.
|
|
31
|
-
- `kvali protocol [dir]` adds the progress protocol to a repository's `AGENTS.md` for agents Kvali has no adapter for (Cursor,
|
|
38
|
+
- `kvali phone test` / `kvali phone off`, `kvali phone telegram off` / `kvali phone discord off`; options `--events needs-you,done,steps,actions,error,stuck,limits` (what reaches the phone), `--done-after <seconds>` (the shortest task worth a notification; 0: every task), `--private` (no project or step names in notifications), `--server <url>` for your own ntfy server.
|
|
39
|
+
- `kvali protocol [dir]` adds the progress protocol to a repository's `AGENTS.md` for agents Kvali has no adapter for (Cursor, Windsurf, Aider, …).
|
|
40
|
+
- OpenCode and Kilo Code sessions need Node 22.13 or later (its built-in SQLite).
|
|
32
41
|
- `kvali --help` lists everything.
|
|
33
42
|
|
|
34
43
|
Kvali also comes as an editor extension (VS Code, Antigravity, Cursor, Windsurf): search for "Kvali" in the Extensions view. Source and docs: https://github.com/webGrandpa/kvali
|
|
35
44
|
|
|
36
|
-
Everything stays on your computer, with no telemetry; only phone notifications, when you set them up, go to the ntfy server you choose. [Privacy](https://github.com/webGrandpa/kvali/blob/main/PRIVACY.md) · [Security policy](https://github.com/webGrandpa/kvali/blob/main/SECURITY.md) · [Third-party notices](https://github.com/webGrandpa/kvali/blob/main/THIRD_PARTY_NOTICES.md)
|
|
45
|
+
Everything stays on your computer, with no telemetry; only phone notifications, when you set them up, go to the ntfy server, Telegram bot or Discord channel you choose. [Privacy](https://github.com/webGrandpa/kvali/blob/main/PRIVACY.md) · [Security policy](https://github.com/webGrandpa/kvali/blob/main/SECURITY.md) · [Third-party notices](https://github.com/webGrandpa/kvali/blob/main/THIRD_PARTY_NOTICES.md)
|
|
37
46
|
|
|
38
47
|
MIT © Giorgi Khiladze
|
|
39
48
|
|
|
40
|
-
Kvali is an independent open-source project, not affiliated with or endorsed by Anthropic, OpenAI, Google, Microsoft or the makers of the other tools it works with. Claude Code, Codex, Gemini CLI, Antigravity, VS Code, Cursor, Windsurf and the other product names here are trademarks of their owners, used only to say what Kvali works with.
|
|
49
|
+
Kvali is an independent open-source project, not affiliated with or endorsed by Anthropic, OpenAI, Google, Microsoft or the makers of the other tools it works with. Claude Code, Codex, Gemini CLI, Antigravity, GitHub Copilot, Cline, Roo Code, Kilo Code, OpenCode, VS Code, Cursor, Windsurf, Telegram, Discord and the other product names here are trademarks of their owners, used only to say what Kvali works with.
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
{
|
|
8
8
|
"name": "kvali",
|
|
9
9
|
"source": "./",
|
|
10
|
-
"description": "Live progress for Claude Code: plan progress, the current step and
|
|
10
|
+
"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."
|
|
11
11
|
}
|
|
12
12
|
]
|
|
13
13
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kvali",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Live progress for Claude Code: plan progress, the current step and
|
|
3
|
+
"version": "0.7.0",
|
|
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",
|
|
7
7
|
"license": "MIT",
|
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
Live progress for long Claude Code tasks, in a pane beside the chat:
|
|
4
4
|
|
|
5
5
|
- **The plan** as a progress bar (Claude Code's Tasks or TodoWrite), with the step in progress.
|
|
6
|
-
- **The current step on a clock**: "4m 12s on this step · usually ~6m", from how long this plan's earlier steps took.
|
|
6
|
+
- **The current step on a clock**: "4m 12s on this step · usually ~6m", and the time left for the whole plan ("~20m left"), from how long this plan's earlier steps took.
|
|
7
7
|
- **What Claude is doing right now**, straight from Claude Code's own events, so nothing is guessed: thinking, writing the answer, preparing a tool call, running “pnpm test” for 41s, waiting for your answer, or "no data from the API for 1m 30s" when the connection stalls.
|
|
8
8
|
- **The latest actions** with their durations, and the **tokens** the session spent with how full the context window is.
|
|
9
|
+
- **Your plan limits**: the 5-hour and weekly usage of your Claude subscription, and when each runs out at the pace of the last hour ("5h 72% · runs out in ~40m"). The Kvali extension and `kvali` show them too.
|
|
10
|
+
- **Going in circles**: when the same action fails again and again with the same error, the pane says so, with the tokens it cost.
|
|
11
|
+
- **Background agents**: agents Claude started in the background count as work until each one reports back, so "finished" comes once, at the real end.
|
|
9
12
|
|
|
10
13
|
The status line shows the short version (`Kvali · 3/7 · 43% · Writing tests · thinking`), and a long turn ends with a notification.
|
|
11
14
|
|
|
@@ -13,7 +16,7 @@ It works wherever Claude Code runs: the terminal, the desktop app, the VS Code e
|
|
|
13
16
|
|
|
14
17
|
## On your phone
|
|
15
18
|
|
|
16
|
-
With phone notifications set up (`kvali phone` or **Kvali: Send Notifications to My Phone** in the editor), the plugin sends this session's pushes through ntfy by itself, no editor needed: the turn's progress through its plan as one silent notification that each finished step updates (at most once a minute) and the turn's end replaces, and alerts when a question has waited a minute for your answer (one answered at the computer sends nothing), a turn of two minutes or more (or one whose progress you followed) finished, or stopped mid-plan and waited a minute, an error,
|
|
19
|
+
With phone notifications set up (`kvali phone`, `kvali phone telegram`, `kvali phone discord`, or **Kvali: Send Notifications to My Phone** in the editor), the plugin sends this session's pushes through ntfy, Telegram or Discord by itself, no editor needed: the turn's progress through its plan as one silent notification that each finished step updates (at most once a minute) and the turn's end replaces, and alerts when a question has waited a minute for your answer (one answered at the computer sends nothing), a turn of two minutes or more (or one whose progress you followed) finished, or stopped mid-plan and waited a minute, an error, no data from the API, an action failing the same way again and again, or a plan limit about to run out. It follows the choices made in Kvali's phone card or with `kvali phone --events` (each finished step, every action live, every task or only longer ones) and reads the shared setup in `~/.kvali/config.json` once a minute.
|
|
17
20
|
|
|
18
21
|
## With the Kvali editor extension
|
|
19
22
|
|
|
@@ -38,6 +41,6 @@ claude plugin test packages/claude-plugin
|
|
|
38
41
|
|
|
39
42
|
## Privacy
|
|
40
43
|
|
|
41
|
-
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 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 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
|
|
42
45
|
|
|
43
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.
|
|
@@ -58,6 +58,76 @@ export function typicalMs(plan: KvPlan): number | undefined {
|
|
|
58
58
|
return median(plan.durations.length >= plan.fileDurations.length ? plan.durations : plan.fileDurations)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/**
|
|
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.
|
|
64
|
+
*/
|
|
65
|
+
export function planEtaMs(plan: KvPlan, now: number): number | undefined {
|
|
66
|
+
const typical = typicalMs(plan)
|
|
67
|
+
if (!typical) return undefined
|
|
68
|
+
const p = progress(plan.tasks)
|
|
69
|
+
const left = p.total - p.done
|
|
70
|
+
if (!p.total || left <= 0) return undefined
|
|
71
|
+
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
|
+
}
|
|
74
|
+
|
|
75
|
+
/** One usage window as Claude Code reports it (`session.measure`, `$.session.usage()`). */
|
|
76
|
+
export type LimitWindow = { kind: string; percentUsed: number; resetsAt?: string }
|
|
77
|
+
/** Each window's readings over the last hour and a half (`[at, percent]`), within its current period. */
|
|
78
|
+
export type LimitSamples = Record<string, { resetsAt?: string; points: [number, number][] }>
|
|
79
|
+
|
|
80
|
+
const LIMIT_KEEP_MS = 90 * 60_000
|
|
81
|
+
const LIMIT_PACE_MS = 60 * 60_000
|
|
82
|
+
|
|
83
|
+
const sameReset = (a?: string, b?: string): boolean => !a || !b || Math.abs(Date.parse(a) - Date.parse(b)) <= 5 * 60_000
|
|
84
|
+
|
|
85
|
+
/** Adds a reading of each window: a new value, or the same one again after five minutes. A window that reset starts over. */
|
|
86
|
+
export function addLimitSamples(prev: LimitSamples, windows: readonly LimitWindow[], now: number): LimitSamples {
|
|
87
|
+
const out: LimitSamples = {}
|
|
88
|
+
for (const w of windows) {
|
|
89
|
+
if (typeof w?.kind !== 'string' || typeof w.percentUsed !== 'number') continue
|
|
90
|
+
const old = prev[w.kind]
|
|
91
|
+
let points: [number, number][] = old && sameReset(old.resetsAt, w.resetsAt) ? old.points.filter(([at]) => now - at <= LIMIT_KEEP_MS) : []
|
|
92
|
+
const last = points[points.length - 1]
|
|
93
|
+
if (!last || last[1] !== w.percentUsed || now - last[0] >= 5 * 60_000) points = [...points, [now, w.percentUsed]]
|
|
94
|
+
out[w.kind] = { resetsAt: w.resetsAt, points: points.slice(-40) }
|
|
95
|
+
}
|
|
96
|
+
return out
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** When a window is used up at the pace of the last hour, if that comes before it resets; the extension's forecast. */
|
|
100
|
+
export function limitRunsOut(points: readonly [number, number][], w: LimitWindow, now: number): number | undefined {
|
|
101
|
+
const last = points[points.length - 1]
|
|
102
|
+
if (!last) return undefined
|
|
103
|
+
if (w.percentUsed >= 100) return last[0]
|
|
104
|
+
if (now - last[0] > LIMIT_PACE_MS) return undefined
|
|
105
|
+
const first = points.find(([at]) => at >= last[0] - LIMIT_PACE_MS)
|
|
106
|
+
if (!first || last[0] - first[0] < 5 * 60_000) return undefined
|
|
107
|
+
const rate = (last[1] - first[1]) / (last[0] - first[0])
|
|
108
|
+
if (!(rate > 0)) return undefined
|
|
109
|
+
const out = last[0] + (100 - last[1]) / rate
|
|
110
|
+
const reset = w.resetsAt ? Date.parse(w.resetsAt) : NaN
|
|
111
|
+
return Number.isFinite(reset) && out >= reset ? undefined : Math.round(out)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Claude Code's window kinds as short labels: `five_hour` 5h, `seven_day` weekly. */
|
|
115
|
+
export function limitLabel(kind: string): string {
|
|
116
|
+
if (kind === 'five_hour') return '5h'
|
|
117
|
+
const week = /^seven_day(?:_(\w+))?$/.exec(kind)
|
|
118
|
+
if (week) return week[1] ? `weekly ${week[1]}` : 'weekly'
|
|
119
|
+
return kind === 'spend_limit' ? 'spend' : kind.replace(/_/g, ' ')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** "~20m left", "~1h 10m left", "under a minute left". */
|
|
123
|
+
export function fmtEta(ms: number): string {
|
|
124
|
+
if (ms < 60_000) return 'under a minute left'
|
|
125
|
+
const m = Math.round(ms / 60_000)
|
|
126
|
+
if (m < 60) return `~${m}m left`
|
|
127
|
+
const h = Math.floor(m / 60)
|
|
128
|
+
return m % 60 ? `~${h}h ${m % 60}m left` : `~${h}h left`
|
|
129
|
+
}
|
|
130
|
+
|
|
61
131
|
function normStatus(s: unknown): KvTask['status'] {
|
|
62
132
|
return s === 'completed' ? 'completed' : s === 'in_progress' ? 'in_progress' : 'pending'
|
|
63
133
|
}
|
|
@@ -221,6 +291,75 @@ export function fmtMinutes(ms: number): string {
|
|
|
221
291
|
return `${Math.floor(m / 60)}h ${String(m % 60).padStart(2, '0')}m`
|
|
222
292
|
}
|
|
223
293
|
|
|
294
|
+
// ---------- going in circles: the same action failing the same way, again and again ----------
|
|
295
|
+
|
|
296
|
+
/** The same error this many times in a row is a loop; so are this many failures whatever their errors. */
|
|
297
|
+
const SAME_ERROR_RUNS = 4
|
|
298
|
+
const ANY_ERROR_RUNS = 8
|
|
299
|
+
const LOOP_FORGET_MS = 30 * 60_000
|
|
300
|
+
|
|
301
|
+
export type LoopStreak = { label: string; detail?: string; count: number; same: number; sig: string; since: number; last: number; tokens: number }
|
|
302
|
+
export type KvLoop = { label: string; detail?: string; count: number; sameError: boolean; since: number; tokensAtStart: number }
|
|
303
|
+
|
|
304
|
+
/** A short fingerprint of an error's last lines; numbers (times, counts, ports) do not count, the same as the extension's. */
|
|
305
|
+
export function errorSignature(text: string): string {
|
|
306
|
+
const tail = text.slice(-600).toLowerCase().replace(/\d+(?:\.\d+)?/g, '#').replace(/\s+/g, ' ').trim()
|
|
307
|
+
let h = 0x811c9dc5
|
|
308
|
+
for (let i = 0; i < tail.length; i++) {
|
|
309
|
+
h ^= tail.charCodeAt(i)
|
|
310
|
+
h = Math.imul(h, 0x01000193)
|
|
311
|
+
}
|
|
312
|
+
return (h >>> 0).toString(36)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** The key of an action: a command by its command line, a file tool by its file. */
|
|
316
|
+
export const loopKey = (tool: string, d: { label: string; detail?: string }): string => (tool === 'Bash' ? `command:${d.detail ?? d.label}` : `${tool}:${d.detail ?? ''}`)
|
|
317
|
+
|
|
318
|
+
/** One finished call: a failure lengthens its action's streak (the same error, or not), a success ends it. */
|
|
319
|
+
export function noteCall(streaks: Map<string, LoopStreak>, key: string, d: { label: string; detail?: string }, error: string | undefined, now: number, tokens: number): void {
|
|
320
|
+
if (error === undefined) {
|
|
321
|
+
streaks.delete(key)
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
const sig = errorSignature(error)
|
|
325
|
+
const s = streaks.get(key)
|
|
326
|
+
if (!s || now - s.last > LOOP_FORGET_MS) {
|
|
327
|
+
streaks.set(key, { label: d.label, detail: d.detail, count: 1, same: 1, sig, since: now, last: now, tokens })
|
|
328
|
+
return
|
|
329
|
+
}
|
|
330
|
+
s.count += 1
|
|
331
|
+
s.same = s.sig === sig ? s.same + 1 : 1
|
|
332
|
+
s.sig = sig
|
|
333
|
+
s.last = now
|
|
334
|
+
s.label = d.label
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** The longest streak that counts as going in circles, if any. */
|
|
338
|
+
export function currentLoop(streaks: ReadonlyMap<string, LoopStreak>, now: number): KvLoop | undefined {
|
|
339
|
+
let best: LoopStreak | undefined
|
|
340
|
+
for (const s of streaks.values()) {
|
|
341
|
+
if (now - s.last > LOOP_FORGET_MS || (s.same < SAME_ERROR_RUNS && s.count < ANY_ERROR_RUNS)) continue
|
|
342
|
+
if (!best || s.count > best.count) best = s
|
|
343
|
+
}
|
|
344
|
+
return best ? { label: best.label, detail: best.detail, count: best.count, sameError: best.same >= SAME_ERROR_RUNS, since: best.since, tokensAtStart: best.tokens } : undefined
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** The text of a failed call's result, for its fingerprint. */
|
|
348
|
+
export function resultText(result: unknown): string {
|
|
349
|
+
if (typeof result === 'string') return result
|
|
350
|
+
try {
|
|
351
|
+
return JSON.stringify(result) ?? 'error'
|
|
352
|
+
} catch {
|
|
353
|
+
return 'error'
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** A forecast, to the minute: "~30m", "~1h 05m". */
|
|
358
|
+
export function fmtAbout(ms: number): string {
|
|
359
|
+
const m = Math.max(1, Math.round(ms / 60_000))
|
|
360
|
+
return m < 60 ? `~${m}m` : `~${Math.floor(m / 60)}h ${String(m % 60).padStart(2, '0')}m`
|
|
361
|
+
}
|
|
362
|
+
|
|
224
363
|
export function fmtTokens(n: number): string {
|
|
225
364
|
if (n < 1_000) return String(Math.round(n))
|
|
226
365
|
if (n < 1_000_000) return `${(n / 1_000).toFixed(n < 10_000 ? 1 : 0)}k`
|
|
@@ -368,11 +507,23 @@ export const projectSlug = (dir: string): string => dir.replace(/[^a-zA-Z0-9]/g,
|
|
|
368
507
|
|
|
369
508
|
// ---------- phone notifications (shared setup in ~/.kvali/config.json) ----------
|
|
370
509
|
|
|
371
|
-
export type PhoneEvent = 'needs-you' | 'done' | 'error' | 'stuck' | 'steps' | 'actions'
|
|
510
|
+
export type PhoneEvent = 'needs-you' | 'done' | 'error' | 'stuck' | 'steps' | 'actions' | 'limits'
|
|
372
511
|
/** `doneAfterSec`: a turn's end is pushed when it took at least this long (0: every turn), or when the phone followed it. */
|
|
373
|
-
export type PhoneCfg = {
|
|
374
|
-
|
|
375
|
-
|
|
512
|
+
export type PhoneCfg = {
|
|
513
|
+
server: string
|
|
514
|
+
/** The ntfy topic; absent when only Telegram or Discord receives the notifications. */
|
|
515
|
+
topic?: string
|
|
516
|
+
token?: string
|
|
517
|
+
telegram?: { token: string; chatId: string }
|
|
518
|
+
discord?: { webhook: string }
|
|
519
|
+
events: PhoneEvent[]
|
|
520
|
+
details: boolean
|
|
521
|
+
doneAfterSec: number
|
|
522
|
+
}
|
|
523
|
+
const PHONE_EVENTS: readonly PhoneEvent[] = ['needs-you', 'done', 'steps', 'actions', 'error', 'stuck', 'limits']
|
|
524
|
+
const DEFAULT_EVENTS: readonly PhoneEvent[] = ['needs-you', 'done', 'error', 'stuck', 'steps', 'limits']
|
|
525
|
+
/** Kvali 0.6's default, before limits: it reads as today's default. */
|
|
526
|
+
const DEFAULT_EVENTS_V2: readonly PhoneEvent[] = ['needs-you', 'done', 'error', 'stuck', 'steps']
|
|
376
527
|
|
|
377
528
|
/** Kvali 0.5 saved this list as its default, before progress existed: it reads as today's default. */
|
|
378
529
|
const DEFAULT_EVENTS_V1: readonly PhoneEvent[] = ['needs-you', 'done', 'error', 'stuck']
|
|
@@ -385,13 +536,32 @@ export function parsePhoneConfig(text: string): PhoneCfg | undefined {
|
|
|
385
536
|
} catch {
|
|
386
537
|
return undefined
|
|
387
538
|
}
|
|
388
|
-
|
|
539
|
+
const topic = typeof r.topic === 'string' && /^[A-Za-z0-9_-]{1,64}$/.test(r.topic) ? r.topic : undefined
|
|
540
|
+
const tg = r.telegram && typeof r.telegram === 'object' ? (r.telegram as Record<string, unknown>) : undefined
|
|
541
|
+
const chatId = typeof tg?.chatId === 'number' ? String(tg.chatId) : tg?.chatId
|
|
542
|
+
const telegram =
|
|
543
|
+
tg && typeof tg.token === 'string' && /^\d{5,15}:[A-Za-z0-9_-]{30,64}$/.test(tg.token) && typeof chatId === 'string' && /^-?\d{1,20}$/.test(chatId)
|
|
544
|
+
? { token: tg.token, chatId }
|
|
545
|
+
: undefined
|
|
546
|
+
const hook = r.discord && typeof r.discord === 'object' ? (r.discord as Record<string, unknown>).webhook : undefined
|
|
547
|
+
const discord =
|
|
548
|
+
typeof hook === 'string' && /^https:\/\/(?:(?:ptb|canary)\.)?discord(?:app)?\.com\/api\/webhooks\/\d{5,25}\/[A-Za-z0-9_-]{20,120}$/.test(hook) ? { webhook: hook } : undefined
|
|
549
|
+
if (!topic && !telegram && !discord) return undefined
|
|
389
550
|
const server = typeof r.server === 'string' && /^https?:\/\/[^\s/]/.test(r.server) ? r.server.replace(/\/+$/, '') : 'https://ntfy.sh'
|
|
390
551
|
let events = Array.isArray(r.events) ? r.events.filter((e): e is PhoneEvent => PHONE_EVENTS.includes(e as PhoneEvent)) : [...DEFAULT_EVENTS]
|
|
391
|
-
const
|
|
392
|
-
if (r.v === undefined &&
|
|
552
|
+
const same = (list: readonly PhoneEvent[]) => events.length === list.length && list.every(e => events.includes(e))
|
|
553
|
+
if ((r.v === undefined && same(DEFAULT_EVENTS_V1)) || (r.v === 2 && same(DEFAULT_EVENTS_V2))) events = [...DEFAULT_EVENTS]
|
|
393
554
|
const doneAfterSec = typeof r.doneAfter === 'number' && Number.isFinite(r.doneAfter) && r.doneAfter >= 0 ? Math.min(Math.round(r.doneAfter), 86_400) : 120
|
|
394
|
-
return {
|
|
555
|
+
return {
|
|
556
|
+
server,
|
|
557
|
+
...(topic ? { topic } : {}),
|
|
558
|
+
token: typeof r.token === 'string' && r.token ? r.token : undefined,
|
|
559
|
+
...(telegram ? { telegram } : {}),
|
|
560
|
+
...(discord ? { discord } : {}),
|
|
561
|
+
events,
|
|
562
|
+
details: r.details !== false,
|
|
563
|
+
doneAfterSec,
|
|
564
|
+
}
|
|
395
565
|
}
|
|
396
566
|
|
|
397
567
|
/** Silent updates pause while fewer messages than this are left for the day, so alerts still get through. */
|
|
@@ -411,12 +581,12 @@ export function messagesLeftOf(text: string): number | undefined {
|
|
|
411
581
|
|
|
412
582
|
/** `sequence`: the notification it replaces (ntfy's sequence ID), so a turn's progress and its end are one notification. */
|
|
413
583
|
export type PhonePush = { title: string; message: string; priority: 2 | 3 | 4; tags: string[]; sequence?: string }
|
|
414
|
-
export type PushKind = 'needs-you' | 'finished' | 'paused' | 'error' | 'stalled' | 'step'
|
|
584
|
+
export type PushKind = 'needs-you' | 'finished' | 'paused' | 'error' | 'stalled' | 'loop' | 'step'
|
|
415
585
|
|
|
416
586
|
/** The words of a push, the same as the extension's. Without details no project or step names leave the computer. */
|
|
417
587
|
export function phonePush(
|
|
418
588
|
kind: PushKind,
|
|
419
|
-
info: { project: string; plan: KvPlan; label?: string; workedMs?: number; tokens?: number; quietMs?: number; doing?: string },
|
|
589
|
+
info: { project: string; plan: KvPlan; label?: string; workedMs?: number; tokens?: number; quietMs?: number; doing?: string; etaMs?: number; loop?: { what: string; count: number; sameError: boolean; forMs: number; tokens?: number } },
|
|
420
590
|
details: boolean,
|
|
421
591
|
): PhonePush {
|
|
422
592
|
const where = details && info.project ? ` · ${info.project}` : ''
|
|
@@ -444,6 +614,12 @@ export function phonePush(
|
|
|
444
614
|
priority: 3,
|
|
445
615
|
tags: ['warning'],
|
|
446
616
|
}
|
|
617
|
+
case 'loop': {
|
|
618
|
+
const l = info.loop
|
|
619
|
+
const what = l ? (details ? `“${truncate(l.what, 80)}”` : 'The same action') : 'An action'
|
|
620
|
+
const facts = l ? [`failed ${l.count} times in a row${l.sameError ? ' with the same error' : ''}`, `for ${fmtDuration(l.forMs)}`, l.tokens ? `${fmtTokens(l.tokens)} tokens` : undefined] : ['keeps failing']
|
|
621
|
+
return { title: `Claude Code is going in circles${where}`, message: `${what} ${facts.filter(Boolean).join(' · ')}. It may need a hint from you.`, priority: 4, tags: ['repeat'] }
|
|
622
|
+
}
|
|
447
623
|
case 'step':
|
|
448
624
|
{
|
|
449
625
|
// The turn's live notification: the plan's progress and, when chosen, the action running now.
|
|
@@ -452,7 +628,7 @@ export function phonePush(
|
|
|
452
628
|
const doing = details && info.doing ? `Doing: ${truncate(info.doing, 120)}` : undefined
|
|
453
629
|
return {
|
|
454
630
|
title: p.total ? `Claude Code${where} · ${p.done}/${p.total}` : `Claude Code${where} · working`,
|
|
455
|
-
message: lines(p.total ? `${phoneBar(p.done, p.total)} ${p.percent}
|
|
631
|
+
message: lines(p.total ? `${phoneBar(p.done, p.total)} ${p.percent}%${info.etaMs !== undefined ? ` · ${fmtEta(info.etaMs)}` : ''}` : undefined, line, doing) || 'Working',
|
|
456
632
|
priority: 2,
|
|
457
633
|
tags: ['arrow_forward'],
|
|
458
634
|
}
|
|
@@ -460,6 +636,48 @@ export function phonePush(
|
|
|
460
636
|
}
|
|
461
637
|
}
|
|
462
638
|
|
|
639
|
+
const TAG_EMOJI: Record<string, string> = {
|
|
640
|
+
white_check_mark: '✅',
|
|
641
|
+
bell: '🔔',
|
|
642
|
+
x: '❌',
|
|
643
|
+
raised_hand: '✋',
|
|
644
|
+
warning: '⚠️',
|
|
645
|
+
hourglass: '⏳',
|
|
646
|
+
hourglass_flowing_sand: '⏳',
|
|
647
|
+
repeat: '🔁',
|
|
648
|
+
arrow_forward: '▶️',
|
|
649
|
+
}
|
|
650
|
+
const emojiOf = (push: PhonePush): string | undefined => push.tags.map(t => TAG_EMOJI[t]).find(Boolean)
|
|
651
|
+
const escapeHtml = (t: string): string => t.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
652
|
+
|
|
653
|
+
/** A push as a Telegram message (HTML): bold title, the message below it; the same as the extension's. */
|
|
654
|
+
export function telegramText(push: PhonePush): string {
|
|
655
|
+
const emoji = emojiOf(push)
|
|
656
|
+
return `${emoji ? `${emoji} ` : ''}<b>${escapeHtml(push.title)}</b>${push.message ? `\n${escapeHtml(push.message)}` : ''}`
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/** Discord embed colors by what happened. */
|
|
660
|
+
export const PUSH_COLOR: Record<PushKind, number> = {
|
|
661
|
+
'needs-you': 0xd29922,
|
|
662
|
+
finished: 0x3fb950,
|
|
663
|
+
paused: 0xd29922,
|
|
664
|
+
error: 0xf85149,
|
|
665
|
+
stalled: 0xdb6d28,
|
|
666
|
+
loop: 0xdb6d28,
|
|
667
|
+
step: 0x58a6ff,
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/** A push as a Discord webhook message: one embed; silent updates do not notify. */
|
|
671
|
+
export function discordBody(push: PhonePush, color: number): Record<string, unknown> {
|
|
672
|
+
const emoji = emojiOf(push)
|
|
673
|
+
return {
|
|
674
|
+
username: 'Kvali',
|
|
675
|
+
allowed_mentions: { parse: [] },
|
|
676
|
+
embeds: [{ title: `${emoji ? `${emoji} ` : ''}${push.title}`.slice(0, 256), description: push.message.slice(0, 4_000), color }],
|
|
677
|
+
...(push.priority <= 2 ? { flags: 4_096 } : {}),
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
463
681
|
export function ntfyBody(cfg: PhoneCfg, push: PhonePush): string {
|
|
464
682
|
return JSON.stringify({ topic: cfg.topic, title: push.title, message: push.message, priority: push.priority, tags: push.tags, ...(push.sequence ? { sequence_id: push.sequence } : {}) })
|
|
465
683
|
}
|
|
@@ -480,9 +698,19 @@ export const baseName = (p: string): string => p.replace(/[\\/]+$/, '').split(/[
|
|
|
480
698
|
/** Sent beside a prompt while the session has no unfinished plan: the same words as Kvali's hook. */
|
|
481
699
|
export const PLAN_CONTEXT =
|
|
482
700
|
'Progress tracking (Kvali): if this request takes more than two steps, start by creating a task list with TaskCreate ' +
|
|
483
|
-
'
|
|
701
|
+
'or TodoWrite, whichever you have (if neither is in your tool list, load one with ToolSearch first), keep exactly ' +
|
|
702
|
+
'one task in_progress, and mark each task completed as soon as it is done. ' +
|
|
484
703
|
'The user follows your progress from that list, so keep it current.'
|
|
485
704
|
|
|
705
|
+
/** Tool calls into a turn with no plan before Kvali asks for one beside a result, once a turn. */
|
|
706
|
+
export const PLAN_ASK_AFTER = 6
|
|
707
|
+
|
|
708
|
+
/** What a long turn with no plan reads after one of its tool results (once a turn). */
|
|
709
|
+
export const PLAN_REMINDER =
|
|
710
|
+
'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
|
+
'keep one task in_progress, and mark each completed as you finish it. The user follows your progress from that list.'
|
|
713
|
+
|
|
486
714
|
/** `autoPlan` in Kvali's config file; on unless set to false. */
|
|
487
715
|
export function autoPlanEnabled(text: string | undefined): boolean {
|
|
488
716
|
if (!text) return true
|