@kvali/cli 0.6.6 → 0.6.8
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.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"description": "Live progress for Claude Code: plan progress, the current step and its time, what the agent is doing right now, and tokens, in a pane beside the chat.",
|
|
5
5
|
"author": { "name": "Giorgi Khiladze" },
|
|
6
6
|
"homepage": "https://github.com/webGrandpa/kvali",
|
|
@@ -49,6 +49,8 @@ const PANE = 'kvali'
|
|
|
49
49
|
const TICK_MS = 2_000
|
|
50
50
|
const PULSE_EVERY_MS = 10_000
|
|
51
51
|
const LONG_TURN_MS = 120_000
|
|
52
|
+
/** Every background agent is done and nothing woke the session in this time: the task is over. */
|
|
53
|
+
const HELD_RELEASE_MS = 30_000
|
|
52
54
|
/** A question to the person is worth a push only after this long unanswered: sooner, they were at the computer. */
|
|
53
55
|
const ASK_PUSH_AFTER_MS = 60_000
|
|
54
56
|
/** `$.fs.read` copies at most 4 MiB into the plugin. */
|
|
@@ -65,6 +67,8 @@ type Running = {
|
|
|
65
67
|
label: string
|
|
66
68
|
detail?: string
|
|
67
69
|
startedAt: number
|
|
70
|
+
/** The subagent whose call it is; absent for the main loop's. */
|
|
71
|
+
agent?: string
|
|
68
72
|
asks?: string
|
|
69
73
|
/** The same question for a phone push: no command text leaves the computer. */
|
|
70
74
|
askPush?: string
|
|
@@ -129,6 +133,15 @@ type Runtime = {
|
|
|
129
133
|
autoPlan: boolean
|
|
130
134
|
/** The session's permission mode, as the last classic event carried it: who answers an ask. */
|
|
131
135
|
mode: string | undefined
|
|
136
|
+
/** Agents the main loop started in the background, at work until their run ends. */
|
|
137
|
+
background: Map<string, { label: string; startedAt: number }>
|
|
138
|
+
/** Agents whose run's end was heard: the engine's list may call one running a moment longer. */
|
|
139
|
+
finished: Set<string>
|
|
140
|
+
/**
|
|
141
|
+
* A task whose answer handed work to background agents: its end (the phone, the toast) waits
|
|
142
|
+
* for theirs and for the turn their reports start. `idleSince`: all done, and nothing woke it.
|
|
143
|
+
*/
|
|
144
|
+
held: { startedAt: number; sequence?: string; followed: boolean; idleSince?: number } | undefined
|
|
132
145
|
}
|
|
133
146
|
|
|
134
147
|
const fresh = (): Runtime => ({
|
|
@@ -170,6 +183,9 @@ const fresh = (): Runtime => ({
|
|
|
170
183
|
budgetLeft: undefined,
|
|
171
184
|
autoPlan: true,
|
|
172
185
|
mode: undefined,
|
|
186
|
+
background: new Map(),
|
|
187
|
+
finished: new Set(),
|
|
188
|
+
held: undefined,
|
|
173
189
|
})
|
|
174
190
|
|
|
175
191
|
/** Marks a call as waiting for the person's permission. */
|
|
@@ -190,6 +206,12 @@ function derive(now: number): KvLive {
|
|
|
190
206
|
const all = [...rt.running.values()]
|
|
191
207
|
const asking = all.filter(r => r.asks).pop()
|
|
192
208
|
if (asking) return { ...base, phase: 'needs-you', since: asking.askedAt ?? asking.startedAt, label: asking.asks }
|
|
209
|
+
// The turn is over and agents it started work on: they are what runs.
|
|
210
|
+
if (!rt.turnActive && rt.background.size) {
|
|
211
|
+
const n = rt.background.size
|
|
212
|
+
const since = Math.min(...[...rt.background.values()].map(b => b.startedAt))
|
|
213
|
+
return { ...base, phase: 'running', since, label: `${n} background agent${n > 1 ? 's' : ''}` }
|
|
214
|
+
}
|
|
193
215
|
const last = all.pop()
|
|
194
216
|
if (last) return { ...base, phase: 'running', since: last.startedAt, label: last.label, detail: last.detail }
|
|
195
217
|
if (rt.stream) {
|
|
@@ -218,6 +240,12 @@ async function doRefresh($: Engine, force: boolean): Promise<void> {
|
|
|
218
240
|
if (rt.stream && rt.pendingPhase && (rt.pendingPhase.phase !== rt.stream.phase || rt.pendingPhase.label !== rt.stream.label)) {
|
|
219
241
|
rt.stream = { phase: rt.pendingPhase.phase, since: now, label: rt.pendingPhase.label }
|
|
220
242
|
}
|
|
243
|
+
if (rt.held?.idleSince !== undefined && !rt.turnActive && now - rt.held.idleSince >= HELD_RELEASE_MS) {
|
|
244
|
+
const { startedAt, sequence, followed, idleSince } = rt.held
|
|
245
|
+
rt.held = undefined
|
|
246
|
+
rt.ended = { phase: 'done', since: idleSince, lastTurnMs: idleSince - startedAt }
|
|
247
|
+
quiet(finish($, 'done', idleSince - startedAt, sequence, followed, now))
|
|
248
|
+
}
|
|
221
249
|
const l = derive(now)
|
|
222
250
|
await loadPhone($, now)
|
|
223
251
|
if (l.phase === 'needs-you' && rt.pushedNeedsFor !== l.since && now - l.since >= ASK_PUSH_AFTER_MS) {
|
|
@@ -317,7 +345,7 @@ function turnSeq(now: number): string {
|
|
|
317
345
|
*/
|
|
318
346
|
async function pulse($: Engine, l: KvLive, now: number, force: boolean): Promise<void> {
|
|
319
347
|
if (!rt.pulseFile) return
|
|
320
|
-
const key = [l.phase, l.since, l.label ?? ''].join('|')
|
|
348
|
+
const key = [l.phase, l.since, l.label ?? '', rt.background.size].join('|')
|
|
321
349
|
const due = isActivePhase(l.phase) ? now - rt.lastPulseAt >= PULSE_EVERY_MS : false
|
|
322
350
|
if (!force && key === rt.lastPulseKey && !due) return
|
|
323
351
|
rt.lastPulseKey = key
|
|
@@ -336,6 +364,7 @@ async function pulse($: Engine, l: KvLive, now: number, force: boolean): Promise
|
|
|
336
364
|
detail: l.detail,
|
|
337
365
|
lastDataAt: l.lastDataAt,
|
|
338
366
|
turnStartedAt: l.turnStartedAt,
|
|
367
|
+
background: rt.background.size,
|
|
339
368
|
step: pr.current && p.step ? { title: pr.current.title, startedAt: p.step.startedAt, actions: p.step.actions, typicalMs: typicalMs(p) } : undefined,
|
|
340
369
|
}
|
|
341
370
|
try {
|
|
@@ -438,6 +467,54 @@ async function push($: Engine, kind: PushKind, extra: { label?: string; workedMs
|
|
|
438
467
|
}
|
|
439
468
|
}
|
|
440
469
|
|
|
470
|
+
/**
|
|
471
|
+
* A task's end on the phone and in Claude Code. A task the phone followed always gets its end,
|
|
472
|
+
* other tasks only when they were long; a stop in the middle of the plan asks the person
|
|
473
|
+
* something, so it waits like a question.
|
|
474
|
+
*/
|
|
475
|
+
async function finish($: Engine, phase: KvPhase, workedMs: number, sequence: string | undefined, followed: boolean, now: number): Promise<void> {
|
|
476
|
+
if (phase === 'error') quiet(push($, 'error', { label: rt.ended?.label, sequence }))
|
|
477
|
+
if (phase === 'done' && (workedMs >= (rt.phone?.doneAfterSec ?? 120) * 1000 || followed)) {
|
|
478
|
+
const pr = progress((await read($, plan)).tasks)
|
|
479
|
+
if (pr.total > 0 && pr.done < pr.total) rt.pendingPause = { at: now, workedMs, sequence }
|
|
480
|
+
else quiet(push($, 'finished', { workedMs, sequence }))
|
|
481
|
+
}
|
|
482
|
+
if (workedMs >= LONG_TURN_MS && phase !== 'interrupted') {
|
|
483
|
+
const p = progress((await read($, plan)).tasks)
|
|
484
|
+
const text = phase === 'done' ? `Done in ${fmtDuration(workedMs)}${p.total ? ` · ${p.done}/${p.total} tasks` : ''}` : `Stopped: ${rt.ended?.label}`
|
|
485
|
+
$.ui.toast(text)
|
|
486
|
+
quiet($.ui.notify(text, { title: 'Claude Code' }))
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Checks the background agents against the engine's own list, which knows one that ended unheard.
|
|
492
|
+
* After an answer, an agent of the main loop still at work is a background one (Kvali may have
|
|
493
|
+
* loaded after it started).
|
|
494
|
+
*/
|
|
495
|
+
async function countBackground($: Engine, afterAnswer: boolean): Promise<void> {
|
|
496
|
+
let agents: Awaited<ReturnType<Engine['agent']['list']>>
|
|
497
|
+
try {
|
|
498
|
+
agents = await $.agent.list()
|
|
499
|
+
} catch {
|
|
500
|
+
return
|
|
501
|
+
}
|
|
502
|
+
const now = await $.clock.now()
|
|
503
|
+
for (const a of agents) {
|
|
504
|
+
if (a.parentId || a.teammateId) continue
|
|
505
|
+
const atWork = a.status === 'running' || a.status === 'pending' || a.status === 'waiting'
|
|
506
|
+
if (!atWork) rt.background.delete(a.id)
|
|
507
|
+
else if (afterAnswer && !rt.background.has(a.id) && !rt.finished.has(a.id)) rt.background.set(a.id, { label: a.description, startedAt: now })
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/** Forgets the calls of a finished loop: the main loop's, or a subagent's when `agent` is given. */
|
|
512
|
+
function dropCalls(agent?: string): void {
|
|
513
|
+
for (const [id, r] of rt.running) {
|
|
514
|
+
if (agent !== undefined ? r.agent === agent : !r.agent || !rt.background.has(r.agent)) rt.running.delete(id)
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
441
518
|
export const register: Register = on => {
|
|
442
519
|
on('session.start', async ($, e, next) => {
|
|
443
520
|
const result = await next(e)
|
|
@@ -485,8 +562,10 @@ export const register: Register = on => {
|
|
|
485
562
|
rt.betweenSince = now
|
|
486
563
|
rt.ended = undefined
|
|
487
564
|
rt.stream = undefined
|
|
488
|
-
|
|
489
|
-
|
|
565
|
+
dropCalls()
|
|
566
|
+
// A turn that background agents' reports set going (or a prompt meanwhile) is part of their task.
|
|
567
|
+
rt.turnSeq = rt.held?.sequence ?? turnSequence(rt.sessionId, now)
|
|
568
|
+
if (rt.held) rt.held.idleSince = undefined
|
|
490
569
|
rt.progressSent = false
|
|
491
570
|
rt.pendingPause = undefined // the person answered
|
|
492
571
|
rt.progressSentDone = progress((await read($, plan)).tasks).done
|
|
@@ -549,7 +628,7 @@ export const register: Register = on => {
|
|
|
549
628
|
if (!e.agentId) rt.turnActive = true
|
|
550
629
|
if (!isPlan) {
|
|
551
630
|
const d = describeTool(e.tool, input, rt.cwd)
|
|
552
|
-
rt.running.set(id, { ...d, startedAt: now, asks: ASKS_PERSON[e.tool], askedAt: ASKS_PERSON[e.tool] ? now : undefined })
|
|
631
|
+
rt.running.set(id, { ...d, startedAt: now, agent: e.agentId, asks: ASKS_PERSON[e.tool], askedAt: ASKS_PERSON[e.tool] ? now : undefined })
|
|
553
632
|
await update($, recent, list => pushAction(list, { id, label: d.label, detail: d.detail, startedAt: now }))
|
|
554
633
|
await update($, plan, p => (p.step ? { ...p, step: { ...p.step, actions: p.step.actions + 1 } } : p))
|
|
555
634
|
quiet(refresh($))
|
|
@@ -619,39 +698,60 @@ export const register: Register = on => {
|
|
|
619
698
|
}
|
|
620
699
|
}).catch(($, e, next) => next(e))
|
|
621
700
|
|
|
701
|
+
// An agent the model started in the background: the turn may end while it works on.
|
|
702
|
+
on('agent.spawn', async ($, e, next) => {
|
|
703
|
+
const r = await next(e)
|
|
704
|
+
try {
|
|
705
|
+
if (e.background && !e.parentAgentId && !e.isTeammate && !e.workflow && r.agentId) {
|
|
706
|
+
rt.background.set(r.agentId, { label: e.description, startedAt: await $.clock.now() })
|
|
707
|
+
quiet(refresh($))
|
|
708
|
+
}
|
|
709
|
+
} catch {
|
|
710
|
+
// an observer: the spawn stands
|
|
711
|
+
}
|
|
712
|
+
return r
|
|
713
|
+
})
|
|
714
|
+
|
|
622
715
|
on('turn.complete', async ($, e, next) => {
|
|
623
716
|
const result = await next(e)
|
|
624
|
-
if (e.agentId) return result
|
|
625
717
|
const now = await $.clock.now()
|
|
718
|
+
if (e.agentId) {
|
|
719
|
+
// A background agent's run ended: the task it was part of may be over.
|
|
720
|
+
rt.finished.add(e.agentId)
|
|
721
|
+
if (rt.background.delete(e.agentId)) {
|
|
722
|
+
dropCalls(e.agentId)
|
|
723
|
+
if (rt.background.size === 0 && rt.held && !rt.turnActive) rt.held.idleSince = now
|
|
724
|
+
quiet(refresh($, true))
|
|
725
|
+
}
|
|
726
|
+
return result
|
|
727
|
+
}
|
|
626
728
|
rt.turnActive = false
|
|
627
729
|
rt.stream = undefined
|
|
628
|
-
|
|
730
|
+
await countBackground($, e.reason === 'answer')
|
|
731
|
+
dropCalls()
|
|
629
732
|
const phase: KvPhase = e.reason === 'answer' ? 'done' : e.reason === 'aborted' ? 'interrupted' : 'error'
|
|
733
|
+
// A task that background agents carried on is timed from its first turn.
|
|
734
|
+
const held = rt.held
|
|
735
|
+
const workedMs = held ? now - held.startedAt : e.durationMs
|
|
736
|
+
const sequence = held?.sequence ?? rt.turnSeq
|
|
737
|
+
const followed = rt.progressSent || held?.followed === true
|
|
630
738
|
rt.ended = {
|
|
631
739
|
phase,
|
|
632
740
|
since: now,
|
|
633
|
-
lastTurnMs:
|
|
741
|
+
lastTurnMs: workedMs,
|
|
634
742
|
label: e.reason === 'refusal' ? 'the model declined' : e.reason === 'error' ? 'an API error ended the turn' : undefined,
|
|
635
743
|
}
|
|
636
|
-
const sequence = rt.turnSeq
|
|
637
|
-
const followed = rt.progressSent
|
|
638
744
|
rt.turnSeq = undefined
|
|
639
745
|
rt.progressSent = false
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
const pr = progress((await read($, plan)).tasks)
|
|
646
|
-
if (pr.total > 0 && pr.done < pr.total) rt.pendingPause = { at: now, workedMs: e.durationMs, sequence }
|
|
647
|
-
else quiet(push($, 'finished', { workedMs: e.durationMs, sequence }))
|
|
648
|
-
}
|
|
649
|
-
if (e.durationMs >= LONG_TURN_MS && phase !== 'interrupted') {
|
|
650
|
-
const p = progress((await read($, plan)).tasks)
|
|
651
|
-
const text = phase === 'done' ? `Done in ${fmtDuration(e.durationMs)}${p.total ? ` · ${p.done}/${p.total} tasks` : ''}` : `Stopped: ${rt.ended.label}`
|
|
652
|
-
$.ui.toast(text)
|
|
653
|
-
quiet($.ui.notify(text, { title: 'Claude Code' }))
|
|
746
|
+
if (phase === 'done' && rt.background.size > 0) {
|
|
747
|
+
// The answer handed work to agents in the background: the task ends when they are done.
|
|
748
|
+
rt.held = { startedAt: held?.startedAt ?? now - e.durationMs, sequence, followed }
|
|
749
|
+
await refresh($, true)
|
|
750
|
+
return result
|
|
654
751
|
}
|
|
752
|
+
rt.held = undefined
|
|
753
|
+
await refresh($, true)
|
|
754
|
+
await finish($, phase, workedMs, sequence, followed, now)
|
|
655
755
|
return result
|
|
656
756
|
})
|
|
657
757
|
|
|
@@ -659,6 +759,8 @@ export const register: Register = on => {
|
|
|
659
759
|
rt.turnActive = false
|
|
660
760
|
rt.stream = undefined
|
|
661
761
|
rt.running.clear()
|
|
762
|
+
rt.background.clear() // they end with the session
|
|
763
|
+
rt.held = undefined
|
|
662
764
|
rt.ended = { phase: 'ended', since: await $.clock.now() }
|
|
663
765
|
rt.pendingPause = undefined
|
|
664
766
|
await refresh($, true).catch(() => undefined)
|
package/dist/kvali.mjs
CHANGED
|
@@ -261,6 +261,10 @@ var JsonlTail = class {
|
|
|
261
261
|
get position() {
|
|
262
262
|
return this.offset;
|
|
263
263
|
}
|
|
264
|
+
/** When the file was last modified, as of the last read (-1 before the first). */
|
|
265
|
+
get modifiedAt() {
|
|
266
|
+
return this.mtimeMs;
|
|
267
|
+
}
|
|
264
268
|
async read(onRecord, onReset) {
|
|
265
269
|
let st;
|
|
266
270
|
try {
|
|
@@ -932,6 +936,31 @@ var WAITING_NOTIFICATIONS = /* @__PURE__ */ new Set([
|
|
|
932
936
|
"elicitation_url_dialog",
|
|
933
937
|
"agent_needs_input"
|
|
934
938
|
]);
|
|
939
|
+
var TASK_NOTIFICATION = /<task-notification>([\s\S]*?)(?:<\/task-notification>|$)/g;
|
|
940
|
+
var STILL_RUNNING = /* @__PURE__ */ new Set(["running", "pending", "waiting", "blocked"]);
|
|
941
|
+
function endedBackgroundTasks(text) {
|
|
942
|
+
const ids = [];
|
|
943
|
+
for (const m of text.matchAll(TASK_NOTIFICATION)) {
|
|
944
|
+
const body = m[1] ?? "";
|
|
945
|
+
const id = /<task-id>([^<]+)<\/task-id>/.exec(body)?.[1]?.trim();
|
|
946
|
+
const status = /<status>([^<]*)<\/status>/.exec(body)?.[1]?.trim().toLowerCase();
|
|
947
|
+
if (id && status && !STILL_RUNNING.has(status)) ids.push(id);
|
|
948
|
+
}
|
|
949
|
+
return ids;
|
|
950
|
+
}
|
|
951
|
+
function backgroundLabel(tasks) {
|
|
952
|
+
let agents = 0;
|
|
953
|
+
let workflows = 0;
|
|
954
|
+
for (const t of tasks) {
|
|
955
|
+
if (t.kind === "workflow") workflows += 1;
|
|
956
|
+
else agents += 1;
|
|
957
|
+
}
|
|
958
|
+
const parts = [
|
|
959
|
+
agents ? `${agents} background agent${agents > 1 ? "s" : ""}` : "",
|
|
960
|
+
workflows ? `${workflows} workflow${workflows > 1 ? "s" : ""}` : ""
|
|
961
|
+
].filter(Boolean);
|
|
962
|
+
return parts.join(" and ");
|
|
963
|
+
}
|
|
935
964
|
function normStatus(s) {
|
|
936
965
|
switch (s) {
|
|
937
966
|
case "completed":
|
|
@@ -1098,7 +1127,9 @@ var ClaudeCodeAdapter = class {
|
|
|
1098
1127
|
phaseAt: 0,
|
|
1099
1128
|
turns: 0,
|
|
1100
1129
|
turnSteps: 0,
|
|
1130
|
+
turnOpen: false,
|
|
1101
1131
|
subagents: /* @__PURE__ */ new Map(),
|
|
1132
|
+
background: /* @__PURE__ */ new Map(),
|
|
1102
1133
|
timer: new TaskTimer(),
|
|
1103
1134
|
recent: [],
|
|
1104
1135
|
lastSubagentScan: 0
|
|
@@ -1154,6 +1185,14 @@ var ClaudeCodeAdapter = class {
|
|
|
1154
1185
|
st.errorText = firstLine(String(o.content ?? o.error ?? "API error"), 120);
|
|
1155
1186
|
}
|
|
1156
1187
|
return;
|
|
1188
|
+
case "attachment": {
|
|
1189
|
+
const a = o.attachment;
|
|
1190
|
+
if (a?.type === "queued_command") {
|
|
1191
|
+
const text = contentText(a.prompt);
|
|
1192
|
+
if (text.includes("<task-notification>")) for (const id of endedBackgroundTasks(text)) st.background.delete(id);
|
|
1193
|
+
}
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1157
1196
|
default:
|
|
1158
1197
|
return;
|
|
1159
1198
|
}
|
|
@@ -1211,8 +1250,15 @@ var ClaudeCodeAdapter = class {
|
|
|
1211
1250
|
st.phase = "error";
|
|
1212
1251
|
st.phaseAt = ts;
|
|
1213
1252
|
st.errorText = firstLine(contentText(m.content) || "API error", 120);
|
|
1253
|
+
this.endTurn(st, ts, void 0);
|
|
1214
1254
|
return;
|
|
1215
1255
|
}
|
|
1256
|
+
const msgId = typeof m.id === "string" ? m.id : void 0;
|
|
1257
|
+
if (!st.turnOpen && !(msgId && msgId === st.turnEndedBy)) {
|
|
1258
|
+
st.turnOpen = true;
|
|
1259
|
+
st.turnSteps = 0;
|
|
1260
|
+
st.turnStartedAt = st.promptAt !== void 0 && st.promptAt >= (st.turnEndedAt ?? 0) ? st.promptAt : ts;
|
|
1261
|
+
}
|
|
1216
1262
|
let sawToolUse = false;
|
|
1217
1263
|
for (const block of Array.isArray(m.content) ? m.content : []) {
|
|
1218
1264
|
if (!block || typeof block !== "object") continue;
|
|
@@ -1230,9 +1276,15 @@ var ClaudeCodeAdapter = class {
|
|
|
1230
1276
|
else if (stop === "end_turn" || stop === "stop_sequence" || stop === "max_tokens" || stop === "refusal") {
|
|
1231
1277
|
st.phase = "idle";
|
|
1232
1278
|
st.open.clear();
|
|
1279
|
+
this.endTurn(st, ts, msgId);
|
|
1233
1280
|
} else st.phase = "working";
|
|
1234
1281
|
st.phaseAt = ts;
|
|
1235
1282
|
}
|
|
1283
|
+
endTurn(st, ts, by) {
|
|
1284
|
+
st.turnOpen = false;
|
|
1285
|
+
st.turnEndedAt = ts;
|
|
1286
|
+
st.turnEndedBy = by;
|
|
1287
|
+
}
|
|
1236
1288
|
onToolUse(st, block, ts) {
|
|
1237
1289
|
const name = String(block.name ?? "tool");
|
|
1238
1290
|
const input = block.input && typeof block.input === "object" ? block.input : {};
|
|
@@ -1297,28 +1349,49 @@ var ClaudeCodeAdapter = class {
|
|
|
1297
1349
|
if (done) done.endedAt = ts;
|
|
1298
1350
|
st.open.delete(b.tool_use_id);
|
|
1299
1351
|
}
|
|
1352
|
+
const launched = o.toolUseResult;
|
|
1353
|
+
if (launched && typeof launched === "object" && launched.status === "async_launched" && !launched.error) {
|
|
1354
|
+
const agentId = typeof launched.agentId === "string" ? launched.agentId : void 0;
|
|
1355
|
+
const id = agentId ?? (typeof launched.taskId === "string" ? launched.taskId : void 0);
|
|
1356
|
+
const label = [launched.description, launched.workflowName, launched.summary].find((v) => typeof v === "string" && v.trim());
|
|
1357
|
+
if (id) st.background.set(id, { kind: agentId ? "agent" : "workflow", label: label ? truncate(label, 60) : "", startedAt: ts });
|
|
1358
|
+
}
|
|
1300
1359
|
st.phase = st.open.size > 0 ? "tool" : "working";
|
|
1301
1360
|
st.phaseAt = ts;
|
|
1302
1361
|
return;
|
|
1303
1362
|
}
|
|
1304
|
-
if (o.isMeta) return;
|
|
1305
1363
|
const raw = contentText(content);
|
|
1364
|
+
const notice = raw.includes("<task-notification>");
|
|
1365
|
+
if (notice) {
|
|
1366
|
+
for (const id of endedBackgroundTasks(raw)) st.background.delete(id);
|
|
1367
|
+
st.promptAt = ts;
|
|
1368
|
+
if (!st.turnOpen) {
|
|
1369
|
+
st.phase = "working";
|
|
1370
|
+
st.phaseAt = ts;
|
|
1371
|
+
st.activity = { kind: "thinking", label: "Thinking", startedAt: ts };
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
if (o.isMeta) return;
|
|
1306
1375
|
if (!raw) return;
|
|
1307
1376
|
if (/^\s*\[Request interrupted by user/.test(raw)) {
|
|
1308
1377
|
st.phase = "interrupted";
|
|
1309
1378
|
st.phaseAt = ts;
|
|
1310
1379
|
st.open.clear();
|
|
1380
|
+
this.endTurn(st, ts, void 0);
|
|
1311
1381
|
return;
|
|
1312
1382
|
}
|
|
1383
|
+
st.promptAt = ts;
|
|
1313
1384
|
const isCommand = raw.includes("<command-name>") || raw.includes("<local-command-");
|
|
1314
1385
|
const text = stripInjectedTags(raw);
|
|
1315
1386
|
if (!text) return;
|
|
1316
1387
|
const origin = o.origin?.kind;
|
|
1317
|
-
if (!isCommand && (origin === void 0 || origin === "human")) {
|
|
1388
|
+
if (!isCommand && !notice && (origin === void 0 || origin === "human")) {
|
|
1318
1389
|
st.firstPrompt ??= firstLine(text, 100);
|
|
1319
1390
|
st.turns += 1;
|
|
1320
1391
|
st.turnSteps = 0;
|
|
1321
1392
|
st.turnStartedAt = ts;
|
|
1393
|
+
st.turnOpen = true;
|
|
1394
|
+
st.turnEndedBy = void 0;
|
|
1322
1395
|
}
|
|
1323
1396
|
if (!isCommand) {
|
|
1324
1397
|
st.phase = "working";
|
|
@@ -1375,16 +1448,17 @@ var ClaudeCodeAdapter = class {
|
|
|
1375
1448
|
if (now - st.lastSubagentScan >= 5e3) {
|
|
1376
1449
|
st.lastSubagentScan = now;
|
|
1377
1450
|
const subDir = path3.join(st.projectDir, st.sessionId, "subagents");
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1451
|
+
const dirs = [subDir];
|
|
1452
|
+
for (const run of await listDir(path3.join(subDir, "workflows"))) if (run.isDirectory()) dirs.push(path3.join(subDir, "workflows", run.name));
|
|
1453
|
+
for (const dir of dirs) {
|
|
1454
|
+
for (const f of await listDir(dir)) {
|
|
1455
|
+
if (!f.isFile() || !f.name.endsWith(".jsonl")) continue;
|
|
1456
|
+
const file = path3.join(dir, f.name);
|
|
1457
|
+
if (!st.subagents.has(file)) st.subagents.set(file, { tail: new JsonlTail(file) });
|
|
1458
|
+
}
|
|
1382
1459
|
}
|
|
1383
1460
|
}
|
|
1384
|
-
for (const [, sub] of st.subagents)
|
|
1385
|
-
const res = await sub.tail.read((rec) => this.onRecord(st, rec, ctx, true));
|
|
1386
|
-
if (res.changed) sub.updatedAt = now;
|
|
1387
|
-
}
|
|
1461
|
+
for (const [, sub] of st.subagents) await sub.tail.read((rec) => this.onRecord(st, rec, ctx, true));
|
|
1388
1462
|
}
|
|
1389
1463
|
/** Older Claude Code versions wrote subagents as top-level agent-*.jsonl files that reference the parent session. */
|
|
1390
1464
|
async readLegacyAgents(ctx) {
|
|
@@ -1452,8 +1526,30 @@ var ClaudeCodeAdapter = class {
|
|
|
1452
1526
|
detail = "Session ended";
|
|
1453
1527
|
}
|
|
1454
1528
|
}
|
|
1455
|
-
let pulse;
|
|
1456
1529
|
const beat = st.pulse;
|
|
1530
|
+
let background;
|
|
1531
|
+
if (st.background.size > 0) {
|
|
1532
|
+
const endedAt = Math.max(live?.event === "SessionEnd" ? live.at ?? 0 : 0, beat?.phase === "ended" ? beat.at : 0);
|
|
1533
|
+
const counted = beat && typeof beat.background === "number" && beat.at >= (st.turnEndedAt ?? 0) - 5e3 ? beat : void 0;
|
|
1534
|
+
for (const [id, b] of st.background) {
|
|
1535
|
+
if (b.startedAt <= endedAt || counted?.background === 0 && b.kind === "agent" && b.startedAt <= counted.at) st.background.delete(id);
|
|
1536
|
+
}
|
|
1537
|
+
let lastWrite = st.updatedAt;
|
|
1538
|
+
for (const sub of st.subagents.values()) lastWrite = Math.max(lastWrite, sub.tail.modifiedAt);
|
|
1539
|
+
const tasks2 = [...st.background.values()];
|
|
1540
|
+
if (tasks2.length > 0 && !st.turnOpen && (status === "idle" || status === "done") && now - lastWrite < ctx.staleAfterMs) {
|
|
1541
|
+
status = "working";
|
|
1542
|
+
detail = void 0;
|
|
1543
|
+
background = {
|
|
1544
|
+
kind: "subagent",
|
|
1545
|
+
label: backgroundLabel(tasks2),
|
|
1546
|
+
detail: truncate(tasks2.map((t) => t.label).filter(Boolean).join(", "), 90) || void 0,
|
|
1547
|
+
startedAt: st.turnEndedAt ?? now
|
|
1548
|
+
};
|
|
1549
|
+
lastSignal = Math.max(lastSignal, lastWrite);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
let pulse;
|
|
1457
1553
|
if (beat && beat.at >= st.startedAt && PULSE_ACTIVE.has(beat.phase)) {
|
|
1458
1554
|
if (now - beat.at < PULSE_FRESH_MS) {
|
|
1459
1555
|
pulse = { phase: beat.phase, since: beat.since, at: beat.at, label: beat.label, detail: beat.detail, lastDataAt: beat.lastDataAt };
|
|
@@ -1475,11 +1571,11 @@ var ClaudeCodeAdapter = class {
|
|
|
1475
1571
|
detail = stale;
|
|
1476
1572
|
}
|
|
1477
1573
|
}
|
|
1478
|
-
const activeSubagents = [...st.subagents.values()].filter((s) => now - s.
|
|
1574
|
+
const activeSubagents = [...st.subagents.values()].filter((s) => s.tail.modifiedAt > 0 && now - s.tail.modifiedAt < 6e4).length;
|
|
1479
1575
|
const window = /\[1m\]/i.test(st.model ?? "") || st.maxContext > 2e5 ? 1e6 : 2e5;
|
|
1480
1576
|
const ownTitle = st.customTitle || st.aiTitle || st.summary;
|
|
1481
1577
|
const title = ownTitle || st.firstPrompt || "Untitled session";
|
|
1482
|
-
let activity = status === "working" ? st.activity : void 0;
|
|
1578
|
+
let activity = status === "working" ? background ?? st.activity : void 0;
|
|
1483
1579
|
if (status === "working" && st.phase === "tool" && st.open.size > 0) activity = [...st.open.values()].pop();
|
|
1484
1580
|
return {
|
|
1485
1581
|
key: `claude-code:${st.sessionId}`,
|
|
@@ -5143,7 +5239,7 @@ function qrTerminal(text, color = true) {
|
|
|
5143
5239
|
}
|
|
5144
5240
|
|
|
5145
5241
|
// src/index.ts
|
|
5146
|
-
var VERSION = "0.6.
|
|
5242
|
+
var VERSION = "0.6.8";
|
|
5147
5243
|
function parse(argv) {
|
|
5148
5244
|
const opts = {
|
|
5149
5245
|
json: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kvali/cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"description": "Live progress, tokens and phone alerts for AI coding agents (Claude Code, Codex, Gemini CLI, Antigravity), in your terminal.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Giorgi Khiladze (https://github.com/webGrandpa)",
|