@herbertgao/pi-extensions 2026.10.9 → 2026.10.10
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 +4 -2
- package/node_modules/@dietrichgebert/ponytail/.qoder-plugin/plugin.json +1 -1
- package/node_modules/@dietrichgebert/ponytail/README.md +16 -0
- package/node_modules/@dietrichgebert/ponytail/hooks/band/board.ts +560 -0
- package/node_modules/@dietrichgebert/ponytail/hooks/band/logo.ts +3 -0
- package/node_modules/@dietrichgebert/ponytail/hooks/band/metrics.ts +317 -0
- package/node_modules/@dietrichgebert/ponytail/hooks/band/register.tsx +472 -0
- package/node_modules/@dietrichgebert/ponytail/hooks/band/types.d.ts +35 -0
- package/node_modules/@dietrichgebert/ponytail/hooks/claude-band.json +6 -0
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-band-import.js +274 -0
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-mode-tracker.js +43 -5
- package/node_modules/@dietrichgebert/ponytail/package.json +1 -1
- package/node_modules/@dietrichgebert/ponytail/skills/ponytail/SKILL.md +1 -1
- package/node_modules/@dietrichgebert/ponytail/skills/ponytail-debt/SKILL.md +1 -2
- package/node_modules/@dietrichgebert/ponytail/skills/ponytail-gain/SKILL.md +0 -1
- package/node_modules/@dietrichgebert/ponytail/skills/ponytail-help/SKILL.md +6 -0
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +7 -5
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +3 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +5 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +11 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/token-rate.ts +21 -5
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/working-message.ts +23 -4
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/index.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/markdown-enhance.ts +4 -128
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
- package/package.json +3 -3
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { atom, read, update } from 'claude-code'
|
|
2
|
+
import type { EngineInterface, Register } from 'claude-code'
|
|
3
|
+
|
|
4
|
+
import { boardHtml, tasksFrom } from './board'
|
|
5
|
+
import type { Band } from './types'
|
|
6
|
+
import type { Col } from './metrics'
|
|
7
|
+
import {
|
|
8
|
+
GREP_DEFS,
|
|
9
|
+
NO_TOKENS,
|
|
10
|
+
addTokens,
|
|
11
|
+
addedLines,
|
|
12
|
+
callsIn,
|
|
13
|
+
defsIn,
|
|
14
|
+
duplicateOf,
|
|
15
|
+
elapsed,
|
|
16
|
+
fmtTokens,
|
|
17
|
+
hits,
|
|
18
|
+
isCode,
|
|
19
|
+
isSource,
|
|
20
|
+
isTestCommand,
|
|
21
|
+
mainModel,
|
|
22
|
+
markdown,
|
|
23
|
+
metricsSvg,
|
|
24
|
+
MODEL_PATTERN,
|
|
25
|
+
parseDefs,
|
|
26
|
+
percent,
|
|
27
|
+
resume,
|
|
28
|
+
snapshot,
|
|
29
|
+
testCounts,
|
|
30
|
+
sessionTitle,
|
|
31
|
+
taskKey,
|
|
32
|
+
testsLabel,
|
|
33
|
+
TITLE_RECORD,
|
|
34
|
+
totalTokens,
|
|
35
|
+
upsertCsv,
|
|
36
|
+
webhookRequest,
|
|
37
|
+
} from './metrics'
|
|
38
|
+
|
|
39
|
+
const LEVELS = ['off', 'lite', 'full', 'ultra']
|
|
40
|
+
const EMPTY: Band = {
|
|
41
|
+
level: 'off',
|
|
42
|
+
model: '',
|
|
43
|
+
cost: 0,
|
|
44
|
+
spent: 0,
|
|
45
|
+
turns: 0,
|
|
46
|
+
turnCosts: [],
|
|
47
|
+
tokens: NO_TOKENS,
|
|
48
|
+
busyMs: 0,
|
|
49
|
+
name: '',
|
|
50
|
+
project: '',
|
|
51
|
+
session: '',
|
|
52
|
+
transcript: '',
|
|
53
|
+
reused: [],
|
|
54
|
+
created: [],
|
|
55
|
+
dupes: [],
|
|
56
|
+
removed: [],
|
|
57
|
+
openCallers: [],
|
|
58
|
+
tests: { state: 'none' },
|
|
59
|
+
details: false,
|
|
60
|
+
}
|
|
61
|
+
// The counters of one task: what a new session or /clear starts over.
|
|
62
|
+
const TASK = {
|
|
63
|
+
spent: 0,
|
|
64
|
+
turns: 0,
|
|
65
|
+
turnCosts: [],
|
|
66
|
+
tokens: NO_TOKENS,
|
|
67
|
+
busyMs: 0,
|
|
68
|
+
name: '',
|
|
69
|
+
model: '',
|
|
70
|
+
reused: [],
|
|
71
|
+
created: [],
|
|
72
|
+
dupes: [],
|
|
73
|
+
removed: [],
|
|
74
|
+
openCallers: [],
|
|
75
|
+
tests: { state: 'none' as const },
|
|
76
|
+
}
|
|
77
|
+
const band = atom({ plugin: 'ponytail', key: 'band' } as const, EMPTY)
|
|
78
|
+
// State kept from an older version of the band lacks newer fields.
|
|
79
|
+
const load = async ($: EngineInterface): Promise<Band> => ({ ...EMPTY, ...(await read($, band)) })
|
|
80
|
+
|
|
81
|
+
const union = (a: string[], b: string[]) => [...new Set([...a, ...b])]
|
|
82
|
+
const base = (path: string) => path.replace(/\/+$/, '').split('/').pop() ?? path
|
|
83
|
+
|
|
84
|
+
// Windows sets USERPROFILE, not HOME.
|
|
85
|
+
const home = async ($: EngineInterface) => (await $.env.get('HOME')) ?? (await $.env.get('USERPROFILE'))
|
|
86
|
+
const claudeDir = async ($: EngineInterface) => (await $.env.get('CLAUDE_CONFIG_DIR')) ?? `${await home($)}/.claude`
|
|
87
|
+
|
|
88
|
+
// `/ponytail band` (the mode tracker) leaves "off" here to hide the band. Absent flag = shown.
|
|
89
|
+
async function bandHidden($: EngineInterface): Promise<boolean> {
|
|
90
|
+
try {
|
|
91
|
+
return (await $.fs.read(`${await claudeDir($)}/.ponytail-band`)).trim() === 'off'
|
|
92
|
+
} catch {
|
|
93
|
+
return false
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// The level ponytail's own hooks write. Absent flag = off.
|
|
98
|
+
// shortcut: the shared flag the statusline reads, so two sessions in different repos show the last switch; read the per-project flag if that matters.
|
|
99
|
+
async function readLevel($: EngineInterface): Promise<string> {
|
|
100
|
+
const dir = await claudeDir($)
|
|
101
|
+
try {
|
|
102
|
+
const level = (await $.fs.read(`${dir}/.ponytail-active`)).trim()
|
|
103
|
+
return LEVELS.includes(level) ? level : 'off'
|
|
104
|
+
} catch {
|
|
105
|
+
return 'off'
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// The same commands a person types, so ponytail's own skills and hooks stay the only logic.
|
|
110
|
+
const run = ($: EngineInterface, command: string, args = '') => $.command.run({ command, args })
|
|
111
|
+
|
|
112
|
+
type Options = { readonly [field: string]: unknown }
|
|
113
|
+
|
|
114
|
+
// The session's sidebar name. grep, because $.fs.read refuses files over 4 MiB and transcripts grow past that.
|
|
115
|
+
// shortcut: without grep (Windows) only a transcript under 4 MiB is read; findstr would lift that.
|
|
116
|
+
async function readTitle($: EngineInterface, transcript: string): Promise<string | undefined> {
|
|
117
|
+
if (transcript === '') return undefined
|
|
118
|
+
const grep = await $.process.run(['grep', '-F', TITLE_RECORD, transcript]).catch(() => undefined)
|
|
119
|
+
const text = grep !== undefined && grep.exitCode <= 1 ? grep.stdout : await $.fs.read(transcript).catch(() => '')
|
|
120
|
+
return sessionTitle(text)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// The model that wrote most of the session's replies, so the board can tell models apart.
|
|
124
|
+
async function readModel($: EngineInterface, transcript: string): Promise<string> {
|
|
125
|
+
if (transcript === '') return ''
|
|
126
|
+
const grep = await $.process.run(['grep', '-o', MODEL_PATTERN, transcript]).catch(() => undefined)
|
|
127
|
+
return grep?.exitCode === 0 ? mainModel(grep.stdout) : ''
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Where the task ledgers and the board live.
|
|
131
|
+
// shortcut: ~/.config only (XDG respected); Windows would want %APPDATA%.
|
|
132
|
+
async function ledgerDir($: EngineInterface) {
|
|
133
|
+
return `${(await $.env.get('XDG_CONFIG_HOME')) ?? `${await home($)}/.config`}/ponytail/band`
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const ledgerFile = (dir: string, project: string) => `${dir}/${project.replace(/[^\w.-]/g, '_')}.csv`
|
|
137
|
+
|
|
138
|
+
// After every turn: the task's row in a CSV per project, and the same row to a webhook if one is set.
|
|
139
|
+
async function record($: EngineInterface, b: Band, options: Options) {
|
|
140
|
+
const startedAt = (await $.session.usage()).startedAt
|
|
141
|
+
const row = snapshot(b, startedAt)
|
|
142
|
+
if (options.ledger !== false && b.project !== '') {
|
|
143
|
+
const dir = await ledgerDir($)
|
|
144
|
+
const file = ledgerFile(dir, b.project)
|
|
145
|
+
const existing = await $.fs.read(file).catch(() => '')
|
|
146
|
+
// $.fs.write creates the directory: no mkdir, which Windows does not have.
|
|
147
|
+
await $.fs.write(file, upsertCsv(existing, row))
|
|
148
|
+
// The board is a plain file a refresh rereads, so it is rebuilt with every row.
|
|
149
|
+
await writeBoard($, dir)
|
|
150
|
+
}
|
|
151
|
+
const url = typeof options.webhookUrl === 'string' ? options.webhookUrl.trim() : ''
|
|
152
|
+
if (url !== '') {
|
|
153
|
+
const token = typeof options.webhookToken === 'string' ? options.webhookToken.trim() : ''
|
|
154
|
+
const request = webhookRequest(url, token, options.sendNames !== false, row)
|
|
155
|
+
if ('refused' in request) {
|
|
156
|
+
$.ui.status(`ponytail band: ${request.refused}`)
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
// Not awaited: a slow endpoint must never hold up the turn.
|
|
160
|
+
void $.http
|
|
161
|
+
.fetch(request.url, request.init)
|
|
162
|
+
.then(r => $.ui.status(r.ok ? undefined : `ponytail band: webhook answered ${r.status}`))
|
|
163
|
+
.catch(() => $.ui.status('ponytail band: webhook unreachable'))
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Builds board.html from every project's ledger.
|
|
168
|
+
async function writeBoard($: EngineInterface, dir: string) {
|
|
169
|
+
const entries = await $.fs.list(dir).catch(() => [])
|
|
170
|
+
const texts = await Promise.all(entries.filter(f => f.kind === 'file' && f.name.endsWith('.csv')).map(f => $.fs.read(`${dir}/${f.name}`).catch(() => '')))
|
|
171
|
+
const file = `${dir}/board.html`
|
|
172
|
+
await $.fs.write(file, boardHtml(texts.flatMap(tasksFrom), await $.clock.now()))
|
|
173
|
+
return file
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Builds the board fresh and opens it in the browser.
|
|
177
|
+
async function openBoard($: EngineInterface) {
|
|
178
|
+
const file = await writeBoard($, await ledgerDir($))
|
|
179
|
+
const windows = (await $.env.get('OS')) === 'Windows_NT'
|
|
180
|
+
const mac = !windows && (await $.process.run(['uname'])).stdout.trim() === 'Darwin'
|
|
181
|
+
await $.process.run(windows ? ['cmd', '/c', 'start', '', file] : [mac ? 'open' : 'xdg-open', file])
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export const register: Register = (on, options) => {
|
|
185
|
+
// Definitions that existed when the session started: what new code can reuse.
|
|
186
|
+
let known = new Map<string, string>()
|
|
187
|
+
|
|
188
|
+
on('session.start', async ($, e, next) => {
|
|
189
|
+
const grep = await $.process.run(['git', 'grep', '--untracked', '-nE', GREP_DEFS]).catch(() => undefined)
|
|
190
|
+
known = grep?.exitCode === 0 ? parseDefs(grep.stdout) : new Map()
|
|
191
|
+
const level = await readLevel($)
|
|
192
|
+
const details = (await $.store.get('details')) === true
|
|
193
|
+
const repo = await $.session.repo().catch(() => null)
|
|
194
|
+
const project = base(repo?.root ?? (await $.session.cwd()))
|
|
195
|
+
const session = await $.session.id()
|
|
196
|
+
// The cost so far is the baseline for the last turn's own cost.
|
|
197
|
+
const usage = await $.session.usage().catch(() => undefined)
|
|
198
|
+
const csv = usage ? await $.fs.read(ledgerFile(await ledgerDir($), project)).catch(() => '') : ''
|
|
199
|
+
const key = usage ? taskKey(session, usage.startedAt) : ''
|
|
200
|
+
await update($, band, b => resume({ ...EMPTY, ...b, level, details, project, session, cost: usage?.cost?.usd ?? b.cost }, csv, key))
|
|
201
|
+
|
|
202
|
+
return next(e)
|
|
203
|
+
}).catch(($, e, next) => next(e))
|
|
204
|
+
|
|
205
|
+
// /clear starts a new task: the counters start over, the cost baseline stays.
|
|
206
|
+
on('session.end', async ($, e, next) => {
|
|
207
|
+
if (e.reason === 'clear') await update($, band, b => ({ ...EMPTY, ...b, ...TASK }))
|
|
208
|
+
return next(e)
|
|
209
|
+
}).catch(($, e, next) => next(e))
|
|
210
|
+
|
|
211
|
+
// Only the classic hook input carries the transcript path, which holds the sidebar name.
|
|
212
|
+
on('classic.UserPromptSubmit', async ($, e, next) => {
|
|
213
|
+
await update($, band, b => (b.transcript === e.transcript_path ? b : { ...EMPTY, ...b, transcript: e.transcript_path }))
|
|
214
|
+
return next(e)
|
|
215
|
+
}).catch(($, e, next) => next(e))
|
|
216
|
+
|
|
217
|
+
// The first prompt names the task until the session has a sidebar name.
|
|
218
|
+
on('prompt.submit', async ($, e, next) => {
|
|
219
|
+
const text = e.text.trim()
|
|
220
|
+
if (e.origin.kind !== 'plugin' && text !== '' && !text.startsWith('/')) {
|
|
221
|
+
const name = (text.split('\n')[0] ?? '').slice(0, 60)
|
|
222
|
+
await update($, band, b => (b.name === '' ? { ...EMPTY, ...b, name } : b))
|
|
223
|
+
}
|
|
224
|
+
return next(e)
|
|
225
|
+
}).catch(($, e, next) => next(e))
|
|
226
|
+
|
|
227
|
+
on('tool.call', async ($, e, next) => {
|
|
228
|
+
if (e.tool === 'Bash') {
|
|
229
|
+
const ran = await next(e)
|
|
230
|
+
if (ran.deny === undefined && isTestCommand(e.command)) {
|
|
231
|
+
const tests = { state: ran.isError ? ('fail' as const) : ('pass' as const), ...testCounts(ran.text ?? '') }
|
|
232
|
+
await update($, band, b => ({ ...b, tests }))
|
|
233
|
+
}
|
|
234
|
+
return ran
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (e.tool !== 'Edit' && e.tool !== 'Write') return next(e)
|
|
238
|
+
|
|
239
|
+
const file = e.file_path
|
|
240
|
+
const before = e.tool === 'Write' ? await $.fs.read(file).catch(() => '') : e.old_string
|
|
241
|
+
const after = e.tool === 'Write' ? e.content : e.new_string
|
|
242
|
+
const ran = await next(e)
|
|
243
|
+
if (ran.deny !== undefined || ran.isError) return ran
|
|
244
|
+
|
|
245
|
+
const oldDefs = defsIn(file, before)
|
|
246
|
+
const newDefs = defsIn(file, after)
|
|
247
|
+
const created = isSource(file) ? newDefs.filter(n => !oldDefs.includes(n)) : []
|
|
248
|
+
const removed = oldDefs.filter(n => !newDefs.includes(n))
|
|
249
|
+
const reused = isSource(file) ? callsIn(addedLines(before, after), known, newDefs) : []
|
|
250
|
+
const dupes = created.flatMap(name => {
|
|
251
|
+
const like = duplicateOf(name, file, known)
|
|
252
|
+
return like ? [{ name, like }] : []
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
await update($, band, b => ({
|
|
256
|
+
...b,
|
|
257
|
+
reused: union(b.reused, reused),
|
|
258
|
+
created: union(b.created, created),
|
|
259
|
+
dupes: [...b.dupes, ...dupes.filter(d => !b.dupes.some(x => x.name === d.name))],
|
|
260
|
+
removed: union(b.removed, removed),
|
|
261
|
+
tests: isCode(file) && b.tests.state !== 'none' ? { ...b.tests, state: 'stale' as const } : b.tests,
|
|
262
|
+
}))
|
|
263
|
+
|
|
264
|
+
return ran
|
|
265
|
+
}).catch(($, e, next) => next(e))
|
|
266
|
+
|
|
267
|
+
on('turn.complete', async ($, e, next) => {
|
|
268
|
+
const used = e.usage
|
|
269
|
+
if (e.agentId !== undefined) {
|
|
270
|
+
// A subagent's tokens count; its cost is already in the session cost the main turn reads.
|
|
271
|
+
if (used) await update($, band, b => ({ ...EMPTY, ...b, tokens: addTokens(b.tokens ?? NO_TOKENS, used) }))
|
|
272
|
+
return next(e)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const usage = await $.session.usage()
|
|
276
|
+
const turns = await $.session.turns()
|
|
277
|
+
const level = await readLevel($)
|
|
278
|
+
const { removed, transcript } = await load($)
|
|
279
|
+
const title = await readTitle($, transcript)
|
|
280
|
+
const model = await readModel($, transcript)
|
|
281
|
+
|
|
282
|
+
// A removed or renamed definition that is not defined again but still called somewhere.
|
|
283
|
+
// shortcut: name match with git grep, so a same-named call in another module counts too.
|
|
284
|
+
const stillRemoved: string[] = []
|
|
285
|
+
const open: string[] = []
|
|
286
|
+
for (const name of removed) {
|
|
287
|
+
const grep = await $.process.run(['git', 'grep', '--untracked', '-nw', '-e', name]).catch(() => undefined)
|
|
288
|
+
const rows = hits(grep?.stdout ?? '')
|
|
289
|
+
if (rows.some(r => defsIn(r.file, r.text.trimStart()).includes(name))) continue
|
|
290
|
+
const call = new RegExp(`(?<![\\w$])${name.replace(/\$/g, '\\$')}\\s*\\(`)
|
|
291
|
+
const refs = rows.filter(r => call.test(r.text)).map(r => `${r.file}:${r.line}`)
|
|
292
|
+
if (refs.length > 0) {
|
|
293
|
+
stillRemoved.push(name)
|
|
294
|
+
open.push(...refs)
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const b = await update($, band, x => {
|
|
299
|
+
const b = { ...EMPTY, ...x }
|
|
300
|
+
const cost = usage.cost?.usd ?? b.cost
|
|
301
|
+
// A cost below the baseline means the engine started its ledger over.
|
|
302
|
+
const turn = cost >= b.cost ? cost - b.cost : cost
|
|
303
|
+
return {
|
|
304
|
+
...b,
|
|
305
|
+
level,
|
|
306
|
+
cost,
|
|
307
|
+
// Cost and turns are the session's own totals, so a reload or a second band never starts them over.
|
|
308
|
+
spent: usage.cost?.usd ?? b.spent + turn,
|
|
309
|
+
turns,
|
|
310
|
+
turnCosts: [...b.turnCosts, turn].slice(-20),
|
|
311
|
+
tokens: used ? addTokens(b.tokens, used) : b.tokens,
|
|
312
|
+
busyMs: b.busyMs + e.durationMs,
|
|
313
|
+
name: title ?? b.name,
|
|
314
|
+
model: model || b.model,
|
|
315
|
+
removed: stillRemoved,
|
|
316
|
+
openCallers: open,
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
await record($, b, options).catch(() => $.ui.status('ponytail band: could not write the task ledger'))
|
|
320
|
+
|
|
321
|
+
return next(e)
|
|
322
|
+
}).catch(($, e, next) => next(e))
|
|
323
|
+
|
|
324
|
+
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
|
|
325
|
+
if (e.props.hasSurvey || (await bandHidden($))) return next(e)
|
|
326
|
+
// Other mods share this slot: draw theirs below ours instead of replacing it.
|
|
327
|
+
// next(e) rejects only when nothing answers beneath (the test harness): the band still draws.
|
|
328
|
+
const below = await next(e).catch(() => undefined)
|
|
329
|
+
|
|
330
|
+
const b = await load($)
|
|
331
|
+
const now = await $.clock.now()
|
|
332
|
+
const startedAt = (await $.session.usage().catch(() => undefined))?.startedAt ?? now
|
|
333
|
+
const reuse = percent(b.reused.length, b.created.length)
|
|
334
|
+
const avg = b.turns > 0 ? b.spent / b.turns : 0
|
|
335
|
+
const last = b.turnCosts[b.turnCosts.length - 1]
|
|
336
|
+
|
|
337
|
+
const setLevel = async (level: string) => {
|
|
338
|
+
await update($, band, x => ({ ...x, level }))
|
|
339
|
+
await run($, 'ponytail:ponytail', level)
|
|
340
|
+
}
|
|
341
|
+
const toggle = async () => {
|
|
342
|
+
await update($, band, x => ({ ...x, details: !x.details }))
|
|
343
|
+
await $.store.set('details', !b.details)
|
|
344
|
+
}
|
|
345
|
+
const review = () => run($, 'ponytail:ponytail-review')
|
|
346
|
+
const audit = () => run($, 'ponytail:ponytail-audit')
|
|
347
|
+
const board = () => openBoard($).catch(() => $.ui.toast('ponytail band: could not open the board'))
|
|
348
|
+
const copy = async () => {
|
|
349
|
+
const done = await $.ui.copy({ text: markdown(snapshot(await load($), startedAt)), surface: e.surface })
|
|
350
|
+
$.ui.toast(done.isCopied ? 'Task copied as Markdown' : `Copy failed: ${done.reason}`)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const { Box, Text, Button } = $.ui.resolve(e)
|
|
354
|
+
const stack = (mine: NonNullable<typeof below>) => (below ? <Box flexDirection="column">{mine}{below}</Box> : mine)
|
|
355
|
+
|
|
356
|
+
const testsText =
|
|
357
|
+
b.tests.state === 'pass'
|
|
358
|
+
? `✓ ${b.tests.passed ?? ''} tests`
|
|
359
|
+
: b.tests.state === 'fail'
|
|
360
|
+
? `✗ ${b.tests.failed ?? ''} failed`
|
|
361
|
+
: b.tests.state === 'stale'
|
|
362
|
+
? 'no test since change'
|
|
363
|
+
: ''
|
|
364
|
+
const testsColor = b.tests.state === 'pass' ? 'success' : b.tests.state === 'fail' ? 'error' : undefined
|
|
365
|
+
const dupe = b.dupes[0]
|
|
366
|
+
const hasDupes = dupe !== undefined
|
|
367
|
+
const hasOpen = b.openCallers.length > 0
|
|
368
|
+
|
|
369
|
+
if (!b.details) {
|
|
370
|
+
return stack(
|
|
371
|
+
<Box flexDirection="row" alignItems="center" gap={2} width={e.props.bodyColumns}>
|
|
372
|
+
{/* A click opens the four levels: one click, one turn, no stops on levels nobody wanted. */}
|
|
373
|
+
<Button key="level" plain onPress={toggle}>
|
|
374
|
+
<Text color={b.level === 'off' ? 'inactive' : 'suggestion'}>●</Text> {b.level}
|
|
375
|
+
</Button>
|
|
376
|
+
<Text>${b.spent.toFixed(2)}</Text>
|
|
377
|
+
{last !== undefined && <Text dimColor>last ${last.toFixed(2)}</Text>}
|
|
378
|
+
<Text dimColor>{elapsed(b.busyMs)}</Text>
|
|
379
|
+
{reuse !== undefined && <Text>{reuse}% reuse</Text>}
|
|
380
|
+
{hasDupes && <Text color="warning">{b.dupes.length} duplicate?</Text>}
|
|
381
|
+
{hasOpen && <Text color="warning">⚠ {b.openCallers.length} callers open</Text>}
|
|
382
|
+
{testsText !== '' && (
|
|
383
|
+
<Text color={testsColor} dimColor={b.tests.state === 'stale'}>
|
|
384
|
+
{testsText}
|
|
385
|
+
</Text>
|
|
386
|
+
)}
|
|
387
|
+
<Box flexGrow={1} />
|
|
388
|
+
<Button key="review" plain label="Review" onPress={review} />
|
|
389
|
+
<Button key="audit" plain label="Audit" onPress={audit} />
|
|
390
|
+
<Button key="board" plain label="Board" onPress={board} />
|
|
391
|
+
<Button key="details" plain label="Details" onPress={toggle} />
|
|
392
|
+
</Box>
|
|
393
|
+
)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Only columns that say something; callers and tests appear once there is something to report.
|
|
397
|
+
const cols: Col[] = [
|
|
398
|
+
{ key: 'cost', label: 'cost', value: `$${b.spent.toFixed(2)}`, sub: last === undefined ? '' : `last $${last.toFixed(2)} · ⌀ $${avg.toFixed(2)}` },
|
|
399
|
+
{ key: 'tokens', label: 'tokens', value: fmtTokens(totalTokens(b.tokens)), sub: `${fmtTokens(b.tokens.output)} out · ${b.turns} ${b.turns === 1 ? 'turn' : 'turns'}` },
|
|
400
|
+
{ key: 'time', label: 'agent time', value: elapsed(b.busyMs), sub: b.turns > 0 ? `⌀ ${elapsed(b.busyMs / b.turns)} / turn` : '' },
|
|
401
|
+
]
|
|
402
|
+
if (b.reused.length + b.created.length > 0) {
|
|
403
|
+
cols.push({
|
|
404
|
+
key: 'reuse',
|
|
405
|
+
label: 'reuse',
|
|
406
|
+
value: reuse === undefined ? `${b.created.length} new` : `${reuse}%`,
|
|
407
|
+
sub: dupe ? `${dupe.name} ≈ ${dupe.like}` : reuse === undefined ? `${b.reused.length} reused` : `${b.reused.length} used · ${b.created.length} new`,
|
|
408
|
+
tone: hasDupes ? 'warning' : undefined,
|
|
409
|
+
})
|
|
410
|
+
}
|
|
411
|
+
if (hasOpen) {
|
|
412
|
+
cols.push({ key: 'callers', label: 'callers', value: `${b.openCallers.length} open`, sub: b.openCallers.slice(0, 2).join(', '), tone: 'warning' })
|
|
413
|
+
}
|
|
414
|
+
if (b.tests.state !== 'none') {
|
|
415
|
+
cols.push({
|
|
416
|
+
key: 'tests',
|
|
417
|
+
label: 'tests',
|
|
418
|
+
value: testsLabel(b.tests),
|
|
419
|
+
sub: b.tests.state === 'pass' ? 'after last change' : b.tests.state === 'fail' ? 'last run' : 'code changed since',
|
|
420
|
+
tone: b.tests.state === 'pass' ? 'success' : b.tests.state === 'fail' ? 'error' : undefined,
|
|
421
|
+
})
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
let metrics = (
|
|
425
|
+
<Box flexDirection="column" gap={1}>
|
|
426
|
+
<Text dimColor wrap="truncate-end">
|
|
427
|
+
{'─'.repeat(e.props.bodyColumns)}
|
|
428
|
+
</Text>
|
|
429
|
+
<Box flexDirection="row" gap={2}>
|
|
430
|
+
{cols.map(c => (
|
|
431
|
+
<Box key={c.key} flexDirection="column" width={Math.max(10, Math.floor(e.props.bodyColumns / cols.length) - 2)}>
|
|
432
|
+
<Text dimColor>{c.label}</Text>
|
|
433
|
+
<Text bold color={c.tone}>
|
|
434
|
+
{c.value}
|
|
435
|
+
</Text>
|
|
436
|
+
<Text dimColor wrap="truncate-end">
|
|
437
|
+
{c.sub}
|
|
438
|
+
</Text>
|
|
439
|
+
</Box>
|
|
440
|
+
))}
|
|
441
|
+
</Box>
|
|
442
|
+
</Box>
|
|
443
|
+
)
|
|
444
|
+
// Text glyphs make broken lines in the desktop's proportional font; an SVG draws real ones.
|
|
445
|
+
if (e.surface === 'desktop') {
|
|
446
|
+
const { Svg } = $.ui.resolve(e)
|
|
447
|
+
metrics = <Svg source={metricsSvg(cols, b.turnCosts)} alt={cols.map(c => `${c.label} ${c.value}`).join(', ')} />
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return stack(
|
|
451
|
+
<Box flexDirection="column" gap={1} width={e.props.bodyColumns}>
|
|
452
|
+
<Box flexDirection="row" alignItems="center" gap={1}>
|
|
453
|
+
{LEVELS.map(level => (
|
|
454
|
+
<Button
|
|
455
|
+
key={`level-${level}`}
|
|
456
|
+
label={level}
|
|
457
|
+
{...(level === b.level ? { variant: 'primary' as const } : { plain: true as const, dimColor: true })}
|
|
458
|
+
onPress={() => setLevel(level)}
|
|
459
|
+
/>
|
|
460
|
+
))}
|
|
461
|
+
<Box flexGrow={1} />
|
|
462
|
+
<Button key="copy" plain label="Copy" onPress={copy} />
|
|
463
|
+
<Button key="review" plain label="Review" onPress={review} />
|
|
464
|
+
<Button key="audit" plain label="Audit" onPress={audit} />
|
|
465
|
+
<Button key="board" plain label="Board" onPress={board} />
|
|
466
|
+
<Button key="details" plain label="Compact" onPress={toggle} />
|
|
467
|
+
</Box>
|
|
468
|
+
{metrics}
|
|
469
|
+
</Box>
|
|
470
|
+
)
|
|
471
|
+
}).catch(($, e, next) => next(e))
|
|
472
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type Tests = {
|
|
2
|
+
state: 'none' | 'pass' | 'fail' | 'stale'
|
|
3
|
+
passed?: number
|
|
4
|
+
failed?: number
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type Tokens = { input: number; output: number; cacheRead: number; cacheWrite: number }
|
|
8
|
+
|
|
9
|
+
export type Band = {
|
|
10
|
+
level: string
|
|
11
|
+
model: string
|
|
12
|
+
cost: number
|
|
13
|
+
spent: number
|
|
14
|
+
turns: number
|
|
15
|
+
turnCosts: number[]
|
|
16
|
+
tokens: Tokens
|
|
17
|
+
busyMs: number
|
|
18
|
+
name: string
|
|
19
|
+
project: string
|
|
20
|
+
session: string
|
|
21
|
+
transcript: string
|
|
22
|
+
reused: string[]
|
|
23
|
+
created: string[]
|
|
24
|
+
dupes: { name: string; like: string }[]
|
|
25
|
+
removed: string[]
|
|
26
|
+
openCallers: string[]
|
|
27
|
+
tests: Tests
|
|
28
|
+
details: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare module 'claude-code' {
|
|
32
|
+
interface PluginState {
|
|
33
|
+
ponytail: { band: Band }
|
|
34
|
+
}
|
|
35
|
+
}
|