project-brain 0.47.0 → 0.48.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 +6 -0
- package/package.json +6 -6
- package/templates/claude-tui/activity-pane/hooks/feat-running.tsx +14 -8
- package/templates/claude-tui/activity-pane/hooks/register.tsx +103 -0
- package/templates/claude-tui/activity-pane/types/index.d.ts +4 -0
- package/templates/claude-tui/file-preview/.claude-plugin/plugin.json +7 -0
- package/templates/claude-tui/file-preview/hooks/core.ts +573 -0
- package/templates/claude-tui/file-preview/hooks/hooks.json +1 -0
- package/templates/claude-tui/file-preview/hooks/register.tsx +369 -0
- package/templates/claude-tui/file-preview/types/index.d.ts +17 -0
- package/templates/nvim/lua/project-brain/highlights.lua +71 -36
package/README.md
CHANGED
|
@@ -375,8 +375,14 @@ The "Claude TUI" checklist sets up Claude Code's terminal. Every unit changes fi
|
|
|
375
375
|
| `tui:terminal-theme` | Adds a marked block at the end of your Ghostty config (Supacode merges the same file): the active theme's colours, background opacity 0.88 and blur 20, and `background-opacity-cells` so tabs, pills and diff rows are as translucent as the rest. Off by default | Deletes only the block; the rest of the file stays as it was |
|
|
376
376
|
| `tui:claude-theme` | Writes a Claude Code custom theme to `~/.claude/themes/project-brain-<theme>.json` and sets `theme` to it, so the chat, the prompt and the `/diff` view use the same palette as the terminal and the activity pane. Off by default | Deletes the file and puts your previous `theme` back |
|
|
377
377
|
| `nvim:theme` | Writes three files into your Neovim config (`lua/project-brain/palette.lua`, `lua/project-brain/highlights.lua`, `lua/plugins/project-brain-theme.lua`): the active theme's palette on tokyonight, with Dracula's syntax roles and diffs that read as green added, red removed and a stronger tint on changed words. Needs LazyVim. Off by default | Deletes those files; a file of yours at one of those paths is never touched |
|
|
378
|
+
| `terminal:bat-theme` | Writes `themes/project-brain-<theme>.tmTheme` into bat's config directory and a marked `--theme` block at the end of its config, then rebuilds bat's cache. Same syntax colours as the Neovim theme; bat's git gutter markers stay its fixed ANSI green/red/yellow. Needs bat. Off by default | Deletes both and rebuilds the cache; a theme file of yours at that path is never touched. An exported `BAT_THEME` still wins over the config (setup warns when it is set) |
|
|
379
|
+
| `terminal:fzf-theme` | Adds a marked block at the end of `~/.zshrc` (`~/.bashrc` under bash) that appends the theme's `--color` to `FZF_DEFAULT_OPTS`, so your own options stay: current row on a soft raised line, purple focus, orange prompt, pink pointer. Needs fzf. Off by default | Deletes only the block |
|
|
380
|
+
| `terminal:lazygit-theme` | Writes `~/.lazygit.yml`, which lazygit merges over its config in every repository under your home: purple frame on the focused panel, orange while you filter, the current row on a quiet bar that keeps red and green readable. Your `config.yml` is never touched, and a theme you already set there is left alone. Off by default | Deletes the file |
|
|
381
|
+
| `terminal:tmux-theme` | Adds a marked block at the end of your tmux config: a transparent status bar, the session and current window as purple pills, readable pane borders with the focused one purple. It also sets `status-left` and the window-status formats, which overrides your own versions of those options while the block is there. A running tmux is not reloaded (`tmux source-file <file>`). Off by default | Deletes only the block |
|
|
382
|
+
| `terminal:starship-theme` | Adds two marked blocks to `starship.toml`: `palette` at the top and the theme's palette table at the end, so starship's red, green, yellow, cyan, purple and pink become the theme's and your styles can name roles such as `path`, `muted`, `progress` or `git_dirty`. It writes no module tables, so your own module styles have to name those keys to use them. A `palette` of your own is never touched. Needs starship; not tested against a real starship. Off by default | Deletes only the two blocks |
|
|
378
383
|
| `tui:skill-listing` | Writes the `project-brain-skill-listing` mod into the same local marketplace and registers it (`enabledPlugins["project-brain-skill-listing@project-brain"]`); asks for your general-use skills and saves them to `~/.project-brain/skills.json`; writes `~/.project-brain/skill-usage.json`. Unchecked even on a first run: it trades skill descriptions for tokens, which is yours to decide | Deletes its plugin entry, its files and `skill-usage.json`; the marketplace entry goes only with the last mod in it. `skills.json` stays, since the suggest hook reads it too |
|
|
379
384
|
| `tui:context-gate` | Writes the `project-brain-context-gate` mod into the same local marketplace and registers it (`enabledPlugins["project-brain-context-gate@project-brain"]`). Unchecked even on a first run: it leaves context out of what the model reads, which is yours to decide | Deletes its plugin entry and its files; the marketplace entry goes only with the last mod in it |
|
|
385
|
+
| `tui:file-preview` | Writes the `project-brain-file-preview` mod into the same local marketplace and registers it (`enabledPlugins["project-brain-file-preview@project-brain"]`). Under each Read, Edit and Write row, and under a reply that names project files (any path with a slash, or a bare `name.ext` in a code span), it draws the path and an `open` control (fullscreen renderer: they take clicks there). With the activity pane also installed, the controls show only on the tool rows the pane leaves visible; reply rows are not affected. A click on the path previews a text file: the mod reads it once (through `perl`, refusing a symlink, a FIFO, a file with more than one hard link, or one that moved), checks every byte it will show, and hands those bytes to the Neovim whose working directory is this project, which shows them in a floating window without opening the file (focus, cursor and your buffers untouched; it closes on your next cursor move there). With no such Neovim, a copy of those bytes opens read-only in a background Supacode tab, else they show as plain lines in a pane; at most the first 192 KiB. An image or video opens with `open`. `open` sends a text file to that Neovim (`tab drop` at the line), else to a new Supacode tab running your editor. Only regular files inside the session's directory, its project root and `PB_PREVIEW_ROOTS` (symlinks resolved first; a root that is your home folder or `/` is never used). Refused by name, for the file or any folder above it inside the project: `.env*`, keys and certificates (`*.pem`, `*.key`, `id_rsa*` and the other `id_*` keys, `*.p12`, `*.pfx`, `*.asc`, `*.ppk`, `*.keystore`, `*.jks`, `*.kdbx`), `credentials*`, `secrets.*`, `*.token`, `.vault-token`, `*.tfvars`, `terraform.tfstate*`, `.dev.vars`, `.npmrc`, `.netrc`, `.pypirc`, `.pgpass`, `.htpasswd`, `.git-credentials`, `kubeconfig*`, `.mcp.json`, `.claude.json`, `service-account*.json`, shell histories, everything under `.ssh`, `.gnupg`, `.aws` and `.kube`, and `.docker/config.json`, `.git/config`, `.claude/settings*.json`, `.config/gh/hosts.yml`. Refused by content: private keys (PEM, OpenSSH, PGP, PuTTY), AWS key ids, GitHub, OpenAI/Anthropic, Slack and Google keys, JWTs, and `password`/`secret`/`token`/`api_key` assignments with a long value; the toast says which kind, never the text. Both lists are best effort. Settings: `PB_EDITOR` (then `VISUAL`, `EDITOR`, else `nvim`; read as argv, no shell), `PB_NVIM_SERVER` (the Neovim socket to use first, then `$NVIM`), `PB_PREVIEW_ROOTS` (extra allowed roots, colon separated), `PB_PREVIEW_IMAGES=1` (draw images and a video's frame in the pane; untested on Supacode). Cmd+click is not the mod's: Claude Code hands a mod no modifier keys, so `open` is a control of its own. Off by default | Deletes its plugin entry and its files; the marketplace entry goes only with the last mod in it |
|
|
380
386
|
|
|
381
387
|
The activity pane is a side pane named "Actividad" with tabs for todos, commands and uncommitted changes; each changed file expands to its diff against HEAD, with line numbers, and Enter on a file name opens it in one reused nvim split (Supacode, tmux, or a Terminal window) with its diff. When subagents run, a selector shows each one with its own summary, commands and diff; the header and footer stay fixed while the body scrolls. It docks on the right only in the fullscreen renderer (`/tui fullscreen`), which is why the unit switches it on. `/activity` reopens the pane after you close it, and ctrl+o still expands tool rows in the chat. The cost it shows is Claude Code's own estimate for the session, not a bill. If another marketplace is already registered under the name `project-brain`, setup reports the unit as foreign and leaves it alone; other plugins' settings are never touched. Mods need Claude Code 2.1.287 or later, and do not load when `disableAllHooks` is set.
|
|
382
388
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "project-brain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local-first MCP server that gives AI tools semantic memory of your codebase.",
|
|
6
6
|
"author": "jcsoftdev",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"zod": "^4.4.3"
|
|
50
50
|
},
|
|
51
51
|
"optionalDependencies": {
|
|
52
|
-
"project-brain-darwin-arm64": "0.
|
|
53
|
-
"project-brain-linux-x64": "0.
|
|
54
|
-
"project-brain-linux-arm64": "0.
|
|
55
|
-
"project-brain-windows-x64": "0.
|
|
56
|
-
"project-brain-windows-arm64": "0.
|
|
52
|
+
"project-brain-darwin-arm64": "0.48.0",
|
|
53
|
+
"project-brain-linux-x64": "0.48.0",
|
|
54
|
+
"project-brain-linux-arm64": "0.48.0",
|
|
55
|
+
"project-brain-windows-x64": "0.48.0",
|
|
56
|
+
"project-brain-windows-arm64": "0.48.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/bun": "latest",
|
|
@@ -3,7 +3,8 @@ import { atom, read, update } from 'claude-code'
|
|
|
3
3
|
import type { Register } from 'claude-code'
|
|
4
4
|
|
|
5
5
|
import type { Api, Row, Span, Tone } from './register'
|
|
6
|
-
import { ICONS, clean, fit, shortName, span } from './register'
|
|
6
|
+
import { ICONS, agentUsage, clean, fit, shortName, span, usageRight } from './register'
|
|
7
|
+
import type { AgentUsage } from '../types'
|
|
7
8
|
import { notify } from './feat-notify'
|
|
8
9
|
|
|
9
10
|
export type RunningKind = 'bash' | 'monitor' | 'agent' | 'workflow'
|
|
@@ -31,7 +32,8 @@ export type RunningTask = {
|
|
|
31
32
|
isInferred?: boolean
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
/** `usage` is keyed by agent id: a background agent's task id is the agent id its model requests report. */
|
|
36
|
+
export type RunningPart = { tasks: RunningTask[]; now: number; usage?: Record<string, AgentUsage> }
|
|
35
37
|
|
|
36
38
|
/** What a background-launching tool call reported. */
|
|
37
39
|
export type Launch = Pick<RunningTask, 'id' | 'kind' | 'label'> & Partial<Pick<RunningTask, 'outputFile' | 'deadline'>>
|
|
@@ -288,15 +290,18 @@ export const rowsRunning = (part: RunningPart, ctx: { width: number; accent: str
|
|
|
288
290
|
cells: [{ spans: [span(fit(title, width), { bold: true, color: live > 0 ? ctx.accent : undefined })], action: { kind: 'toggle', key: SECTION_KEY }, label: 'En curso', key: `btn-${SECTION_KEY}` }],
|
|
289
291
|
}]
|
|
290
292
|
if (!open) return rows
|
|
293
|
+
const usageOf = (task: RunningTask, base: string): string => (task.kind === 'agent' ? usageRight(part.usage?.[task.id], base, width) : '')
|
|
294
|
+
const withUsage = (spent: string, right: Span[]): Span[] => (spent === '' ? right : [span(spent, { dim: true }), ...right])
|
|
291
295
|
for (const task of shown) {
|
|
292
296
|
const who = task.agentLabel !== undefined ? `${clean(task.agentLabel)} · ` : ''
|
|
293
297
|
const label = clean(task.label)
|
|
294
298
|
if (task.status === 'running') {
|
|
295
299
|
const right = elapsed(part.now - task.startedAt)
|
|
300
|
+
const spent = usageOf(task, right)
|
|
296
301
|
rows.push({
|
|
297
302
|
key: `running-${task.id}`,
|
|
298
|
-
cells: [{ spans: [span(` ${ICONS.running} `, { color: 'warning' }), span(`${kindIcon(task.kind)} ${fit(label, width - right.length - 8)}`)] }],
|
|
299
|
-
right: [span(right, { color: 'warning' })],
|
|
303
|
+
cells: [{ spans: [span(` ${ICONS.running} `, { color: 'warning' }), span(`${kindIcon(task.kind)} ${fit(label, width - spent.length - right.length - 8)}`)] }],
|
|
304
|
+
right: withUsage(spent, [span(right, { color: 'warning' })]),
|
|
300
305
|
})
|
|
301
306
|
const detail = `${who}${clean(task.lastLine ?? '')}`
|
|
302
307
|
if (detail !== '') rows.push({ key: `running-${task.id}-line`, cells: [{ spans: [span(fit(` └ ${detail}`, width), { dim: true })] }] })
|
|
@@ -306,10 +311,11 @@ export const rowsRunning = (part: RunningPart, ctx: { width: number; accent: str
|
|
|
306
311
|
const verdict = verdictOfTask(task)
|
|
307
312
|
const took = elapsed((task.endedAt ?? part.now) - task.startedAt)
|
|
308
313
|
const rightText = verdict ? `${verdict} ${took}` : took
|
|
314
|
+
const spent = usageOf(task, rightText)
|
|
309
315
|
rows.push({
|
|
310
316
|
key: `running-${task.id}`,
|
|
311
|
-
cells: [{ spans: [span(` ${look.icon} `, { color: look.color }), span(`${kindIcon(task.kind)} ${fit(`${who}${label}`, width - rightText.length - 8)}`, { dim: true })] }],
|
|
312
|
-
right: verdict ? [span(verdict, { color: verdict === 'PASS' ? 'success' : 'error' }), span(` ${took}`, { dim: true })] : [span(took, { dim: true })],
|
|
317
|
+
cells: [{ spans: [span(` ${look.icon} `, { color: look.color }), span(`${kindIcon(task.kind)} ${fit(`${who}${label}`, width - spent.length - rightText.length - 8)}`, { dim: true })] }],
|
|
318
|
+
right: withUsage(spent, verdict ? [span(verdict, { color: verdict === 'PASS' ? 'success' : 'error' }), span(` ${took}`, { dim: true })] : [span(took, { dim: true })]),
|
|
313
319
|
})
|
|
314
320
|
}
|
|
315
321
|
return rows
|
|
@@ -346,8 +352,8 @@ export const notifyLineOf = (task: RunningTask): string => {
|
|
|
346
352
|
// ---------------------------------------------------------------- engine
|
|
347
353
|
|
|
348
354
|
export async function readRunning($: Api): Promise<RunningPart> {
|
|
349
|
-
const [tasks, now] = await Promise.all([read($, tasksAtom), $.clock.now(), read($, tickAtom)])
|
|
350
|
-
return { tasks, now }
|
|
355
|
+
const [tasks, now, , usage] = await Promise.all([read($, tasksAtom), $.clock.now(), read($, tickAtom), read($, agentUsage)])
|
|
356
|
+
return { tasks, now, usage }
|
|
351
357
|
}
|
|
352
358
|
|
|
353
359
|
function announce($: Api, ended: RunningTask[]): void {
|
|
@@ -25,6 +25,7 @@ import { notifyCommand, notifyTurnComplete } from './feat-notify'
|
|
|
25
25
|
import type {
|
|
26
26
|
AgentRecord,
|
|
27
27
|
AgentState,
|
|
28
|
+
AgentUsage,
|
|
28
29
|
BranchCommit,
|
|
29
30
|
BranchView,
|
|
30
31
|
CallStatus,
|
|
@@ -133,6 +134,7 @@ const openFiles = atom({ plugin: 'project-brain-activity', key: 'openFiles' } as
|
|
|
133
134
|
const diffs = atom({ plugin: 'project-brain-activity', key: 'diffs' } as const, {} as Record<string, DiffPatch>, { shape: 'diffs-2' })
|
|
134
135
|
const costUsd = atom({ plugin: 'project-brain-activity', key: 'costUsd' } as const, 0, { shape: 'cost-1' })
|
|
135
136
|
const stepContext = atom({ plugin: 'project-brain-activity', key: 'stepContext' } as const, {} as Record<string, StepContext>, { shape: 'step-context-1' })
|
|
137
|
+
export const agentUsage = atom({ plugin: 'project-brain-activity', key: 'agentUsage' } as const, {} as Record<string, AgentUsage>, { shape: 'agent-usage-1' })
|
|
136
138
|
const contextUsage = atom({ plugin: 'project-brain-activity', key: 'context' } as const, { window: 0 } as ContextUsage, { shape: 'context-2' })
|
|
137
139
|
const agents = atom({ plugin: 'project-brain-activity', key: 'agents' } as const, [] as AgentRecord[], { shape: 'agents-1' })
|
|
138
140
|
const pickedAgent = atom({ plugin: 'project-brain-activity', key: 'pickedAgent' } as const, '', { shape: 'picked-1' })
|
|
@@ -1058,6 +1060,106 @@ export const modelLabel = (id: string): string => {
|
|
|
1058
1060
|
return named ? `${named[1]} ${named[2]}${named[3] ? `.${named[3]}` : ''}` : bare
|
|
1059
1061
|
}
|
|
1060
1062
|
|
|
1063
|
+
// ---------------------------------------------------------------- pricing
|
|
1064
|
+
|
|
1065
|
+
/** USD per million tokens. Cache writes at the 5-minute rate, the one Claude Code uses. */
|
|
1066
|
+
export type Rates = { input: number; cacheWrite: number; cacheRead: number; output: number }
|
|
1067
|
+
|
|
1068
|
+
/** One model request's usage as the engine reports it; the cache fields may be null or absent. */
|
|
1069
|
+
export type StepUsage = {
|
|
1070
|
+
input_tokens?: number | null
|
|
1071
|
+
output_tokens?: number | null
|
|
1072
|
+
cache_creation_input_tokens?: number | null
|
|
1073
|
+
cache_read_input_tokens?: number | null
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
const rates = (input: number, cacheWrite: number, cacheRead: number, output: number): Rates => ({ input, cacheWrite, cacheRead, output })
|
|
1077
|
+
|
|
1078
|
+
/** Public list prices as of 2026-11-17, from https://platform.claude.com/docs/en/about-claude/pricing, keyed by `modelLabel`. */
|
|
1079
|
+
const PRICES: Record<string, Rates> = {
|
|
1080
|
+
'fable 5.2': rates(8, 10, 0.2, 40),
|
|
1081
|
+
'fable 5.1': rates(10, 12.5, 0.25, 50),
|
|
1082
|
+
'fable 5': rates(10, 12.5, 1, 50),
|
|
1083
|
+
'opus 5.5': rates(4, 5, 0.2, 20),
|
|
1084
|
+
'opus 5': rates(5, 6.25, 0.5, 25),
|
|
1085
|
+
'opus 4.8': rates(5, 6.25, 0.5, 25),
|
|
1086
|
+
'opus 4.7': rates(5, 6.25, 0.5, 25),
|
|
1087
|
+
'opus 4.6': rates(5, 6.25, 0.5, 25),
|
|
1088
|
+
'opus 4.5': rates(5, 6.25, 0.5, 25),
|
|
1089
|
+
'opus 4.1': rates(15, 18.75, 1.5, 75),
|
|
1090
|
+
'opus 4': rates(15, 18.75, 1.5, 75),
|
|
1091
|
+
'sonnet 5.5': rates(2, 2.5, 0.1, 10),
|
|
1092
|
+
'sonnet 5': rates(2, 2.5, 0.2, 10),
|
|
1093
|
+
'sonnet 4.6': rates(3, 3.75, 0.3, 15),
|
|
1094
|
+
'sonnet 4.5': rates(3, 3.75, 0.3, 15),
|
|
1095
|
+
'sonnet 4': rates(3, 3.75, 0.3, 15),
|
|
1096
|
+
'haiku 4.5': rates(1, 1.25, 0.1, 5),
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
/** Haiku 5.5 is priced by the size of each request's prompt: input, cache writes and cache reads together. */
|
|
1100
|
+
const HAIKU_5_5 = { label: 'haiku 5.5', promptLimit: 100_000, small: rates(0.1, 0.125, 0.01, 0.5), large: rates(0.5, 0.625, 0.05, 2.5) }
|
|
1101
|
+
|
|
1102
|
+
const tokenCount = (value: number | null | undefined): number => (typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0)
|
|
1103
|
+
|
|
1104
|
+
/** The rates for a model id and a request's prompt size; null for any model the price list does not name. */
|
|
1105
|
+
export const priceOf = (modelId: string, promptTokens = 0): Rates | null => {
|
|
1106
|
+
const label = modelLabel(modelId)
|
|
1107
|
+
if (label === HAIKU_5_5.label) return promptTokens > HAIKU_5_5.promptLimit ? HAIKU_5_5.large : HAIKU_5_5.small
|
|
1108
|
+
return PRICES[label] ?? null
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/** The estimated USD one model request cost; null when its model has no known price. */
|
|
1112
|
+
export const costOf = (usage: StepUsage, modelId: string): number | null => {
|
|
1113
|
+
const input = tokenCount(usage.input_tokens)
|
|
1114
|
+
const cacheWrite = tokenCount(usage.cache_creation_input_tokens)
|
|
1115
|
+
const cacheRead = tokenCount(usage.cache_read_input_tokens)
|
|
1116
|
+
const price = priceOf(modelId, input + cacheWrite + cacheRead)
|
|
1117
|
+
if (price === null) return null
|
|
1118
|
+
const perToken = price.input * input + price.cacheWrite * cacheWrite + price.cacheRead * cacheRead + price.output * tokenCount(usage.output_tokens)
|
|
1119
|
+
return perToken / 1_000_000
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
/** Adds one model request to its loop's running total; a request without usage leaves the totals as they were. */
|
|
1123
|
+
export const addUsage = (all: Record<string, AgentUsage>, agentId: string, usage: StepUsage | undefined, modelId: string): Record<string, AgentUsage> => {
|
|
1124
|
+
if (!usage) return all
|
|
1125
|
+
const before = all[agentId] ?? { input: 0, output: 0, cacheWrite: 0, cacheRead: 0, usd: 0 }
|
|
1126
|
+
const step = costOf(usage, modelId)
|
|
1127
|
+
return {
|
|
1128
|
+
...all,
|
|
1129
|
+
[agentId]: {
|
|
1130
|
+
input: before.input + tokenCount(usage.input_tokens),
|
|
1131
|
+
output: before.output + tokenCount(usage.output_tokens),
|
|
1132
|
+
cacheWrite: before.cacheWrite + tokenCount(usage.cache_creation_input_tokens),
|
|
1133
|
+
cacheRead: before.cacheRead + tokenCount(usage.cache_read_input_tokens),
|
|
1134
|
+
usd: before.usd === null || step === null ? null : before.usd + step,
|
|
1135
|
+
},
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
export const totalTokens = (usage: AgentUsage): number => usage.input + usage.cacheWrite + usage.cacheRead + usage.output
|
|
1140
|
+
|
|
1141
|
+
/** `~$1.84` from ten cents up, `~$0.045` below, `<$0.001` for dust. */
|
|
1142
|
+
export const estimatedUsd = (usd: number): string => {
|
|
1143
|
+
if (usd < 0.001) return '<$0.001'
|
|
1144
|
+
return `~$${usd < 0.1 ? usd.toFixed(3) : usd.toFixed(2)}`
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
const USAGE_GAP = ' '
|
|
1148
|
+
const LABEL_ROOM = 12
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* The usage text that goes before a row's right-hand `base` (its duration) in `width` columns, gap included:
|
|
1152
|
+
* `412k tok · ~$1.84 `, then without the price, then nothing, as the room for a readable label runs out.
|
|
1153
|
+
*/
|
|
1154
|
+
export const usageRight = (usage: AgentUsage | undefined, base: string, width: number): string => {
|
|
1155
|
+
if (usage === undefined) return ''
|
|
1156
|
+
const total = totalTokens(usage)
|
|
1157
|
+
if (total <= 0) return ''
|
|
1158
|
+
const tokens = `${compact(total)} tok`
|
|
1159
|
+
const choices = usage.usd === null ? [tokens] : [`${tokens} · ${estimatedUsd(usage.usd)}`, tokens]
|
|
1160
|
+
return choices.map(text => `${text}${USAGE_GAP}`).find(text => text.length + base.length + LABEL_ROOM + 8 <= width) ?? ''
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1061
1163
|
export const mergeAgent = (list: AgentRecord[], record: AgentRecord): AgentRecord[] => {
|
|
1062
1164
|
const known = list.find(one => one.id === record.id)
|
|
1063
1165
|
const merged = known ? { ...known, ...record, startedAt: known.startedAt, description: record.description || known.description } : record
|
|
@@ -1981,6 +2083,7 @@ export const register: Register = on => {
|
|
|
1981
2083
|
if (used) {
|
|
1982
2084
|
const tokens = used.input_tokens + used.cache_creation_input_tokens + used.cache_read_input_tokens
|
|
1983
2085
|
await update($, stepContext, all => ({ ...all, [e.agentId ?? MAIN]: { tokens, model: used.model } })).catch(() => undefined)
|
|
2086
|
+
await update($, agentUsage, all => addUsage(all, e.agentId ?? MAIN, used, used.model ?? '')).catch(() => undefined)
|
|
1984
2087
|
}
|
|
1985
2088
|
return result
|
|
1986
2089
|
})
|
|
@@ -86,6 +86,9 @@ export type ContextUsage = { tokens?: number; window: number; percent?: number }
|
|
|
86
86
|
|
|
87
87
|
export type StepContext = { tokens: number; model: string }
|
|
88
88
|
|
|
89
|
+
/** What one loop has spent across its model requests; `usd` turns null for good once a step's model has no known price. */
|
|
90
|
+
export type AgentUsage = { input: number; output: number; cacheWrite: number; cacheRead: number; usd: number | null }
|
|
91
|
+
|
|
89
92
|
export type SessionIdentityLine = { account: string; sessionId: string; folder: string }
|
|
90
93
|
|
|
91
94
|
export type EditorState = { dir: string; tab: string }
|
|
@@ -100,6 +103,7 @@ declare module 'claude-code' {
|
|
|
100
103
|
costUsd: Shaped<number>
|
|
101
104
|
context: Shaped<ContextUsage>
|
|
102
105
|
stepContext: Shaped<Record<string, StepContext>>
|
|
106
|
+
agentUsage: Shaped<Record<string, AgentUsage>>
|
|
103
107
|
mainModel: Shaped<string>
|
|
104
108
|
identity: Shaped<SessionIdentityLine>
|
|
105
109
|
openFiles: Shaped<string[]>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "project-brain-file-preview",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Adds preview and open controls under the file paths in Read, Edit and Write rows and in replies: a preview floats in the project's running Neovim, an open goes to your editor.",
|
|
5
|
+
"author": { "name": "jcsoftdev" },
|
|
6
|
+
"types": "./types/index.d.ts"
|
|
7
|
+
}
|