A one-line band above the prompt and a roomy Cockpit panel (prompt-cache countdown, context, plan limits, cost, next tasks, shortcuts), plus guards: no Claude…

A one-line band above the Claude Code prompt, a roomy Cockpit panel beside the conversation, and seven community mods, installed as one plugin. The band shows only what you glance at. The panel has everything else: prompt-cache countdown, context, plan limits with their reset times, session cost, your next tasks and project shortcuts. Everything that spends tokens or redraws your screen starts off.
◔ 42m ctx 72.5k Next Write docs/specs/PLAN-2.md for the phase 2 slices Continue Details
The band is drawn with Claude's own text and buttons, so it takes the app's fonts and theme, truncates the task by itself, and cannot flash or resize. Details (or /cockpit) opens the panel as a tab in the right-hand side panel.
<img src="docs/images/band.png" alt="The band above the prompt in the Claude desktop app: working, context 704.8k at 70 percent, the next task, and a Details button" width="720">
<img src="docs/images/panel.png" alt="The Cockpit panel in the side panel: prompt cache with a green bar, context at 70 percent, plan limits with reset times, session cost, next up and shortcuts" width="320">
These are screenshots of the real desktop app, showing the dark theme.
| Plugin | What it does | Default here | Origin |
|---|---|---|---|
| cockpit | The band, the Cockpit panel, next-task list, Continue / What's next / Compact buttons, guards, and a cheat-sheet skill | on | this repo (MIT) |
| polish | Cleans dictated prompts with Haiku: drops ums, stutters and false starts, turns spoken punctuation into symbols, spells your jargon right, learns your vocabulary | auto: only prompts that read like dictation | this repo (MIT) |
| cache-tax | Shows the rewrite price before a cold send; opt-in keep-warm for the prompt cache | warns, never drops; keep-warm off | karanb192/cache-tax |
claude-reflect (reflect-mod) | Notices corrections and offers to save them as rules in CLAUDE.md | paused | BayramAnnakov/claude-reflect |
| skins | Redraws the transcript: tool rows, diff cards, table and code cards, spinner | off, its own band off | hellosverre/claude-skins |
| filetree | IDE-style file tree in the sidebar with git status and read/write activity | opens with /filetree (does not dock by itself) | data-goblin/claude-code-filetree |
| replay-theater | Step through the last turn's file edits, one diff at a time | on | anthropics/claude-code-playground |
| blast-radius | Holds rm -r, git reset --hard, git clean, force push and migrations until you press Proceed | on | anthropics/claude-code-playground |
| savvy-progress | Progress bar and agents panel for flows and subagents | idle until something reports | JohnnyVizz/claude-kit |
The seven community mods are vendored here at pinned commits, with small patches (listed in each folder's SOURCE.md) so they start quiet and stack above each other instead of replacing each other's band. Their original licences are kept.
Needs Claude Code 2.1.287 or later.
/plugin marketplace add cGradying/claude-code-cockpit
/plugin install cockpit@janvin-mods
or from a terminal:
claude plugin marketplace add cGradying/claude-code-cockpit
claude plugin install cockpit@janvin-mods --scope user
cockpit lists the seven mods as dependencies, so installing it installs them all. If a dependency does not install by itself, install it by name, for example claude plugin install skins@janvin-mods. Then restart Claude Code (or the desktop app) and open a new session.
To remove everything: /plugin, pick cockpit, uninstall, and do the same for each mod you no longer want. Each one is independent.
The band. One line above the prompt: the cache countdown (◔ 42m, green, then amber, then red), context, and the next task. The 5-hour and weekly limits join the line only once they pass 60%, and 9router down shows only if it was up and stopped. Buttons sit at the right; click them, or focus the band (ctrl+x then tab) and press the key.
| Button | Key | Does |
|---|---|---|
| Continue | c | Sends "continue with the next task" for the first open line of .claude/NEXT.md, and asks Claude to check it off when done. Hidden while a turn runs. |
| Details | d | Opens the Cockpit panel. |
| Compact | k | Appears past 70% context. Runs /compact and tells it to keep the plan, open tasks, PRs, decisions and open bugs. |
The Cockpit panel. One tab in the side panel with room for each number: prompt cache (time left, a bar, what happens if it lapses), context (tokens, percent, window size, Compact), plan limits (each with a bar and when it resets), this session (cost, 9router), your next five tasks (Continue, What's next?), and your project shortcuts. Bars are solid boxes sized in percent and follow the app's light or dark theme. Open it with Details or /cockpit.
Guards that run quietly. A shell command carrying a Claude or Anthropic co-author line is refused. A prompt containing a pasted API key is held once (press Enter again to send it anyway). Prompts about UI or design get a hidden nudge toward the impeccable skill if you have it.
Commands. /cockpit, /git, /polish, /next, /keepwarm, /cache-tax, /reflect-pause, /reflect-queue, /skin, /filetree, /replay, /agents-info. Details in docs/COMMANDS.md; inside Claude Code, the cockpit:help skill prints the same cheat sheet.
One thing runs by itself and costs a little: polish sends a prompt to Haiku only when it reads like dictation (ums, stutters, spoken punctuation, one long run-on), roughly a few hundred tokens each. /polish off stops it. Three other things can cost tokens or change your screen, so they start off:
/keepwarm. The cold-send guard only warns by default: it shows the rewrite price and still sends your message./reflect-pause turns it on. remember: <rule> works either way and needs no model./skin noir turns it on.How to change each: docs/CONFIGURATION.md.
NEXT.md, quick.json./filetree (set autoOpen to on to dock it at session start). It needs a wide window, and upstream says it does not load in WSL sessions of the desktop app.The code in cockpit/ is MIT, Copyright (c) 2026 cGradying (see LICENSE). Each vendored mod keeps its own licence file and authorship: the two Anthropic mods are Apache-2.0, the rest are MIT. See THIRD_PARTY_NOTICES.md. Thanks to the authors of all seven.
hooks/register.tsx 16 lines1import type { Register } from 'claude-code'
2
3import { register as band } from './band'
4import { register as git } from './git'
5import { register as guards } from './guards'
6import { register as panel } from './panel'
7
8// A plugin has one hooks module and may not hook the same event twice without a matcher,
9// so the parts that share this plugin are called from here and each owns its own events.
10export const register: Register = (on, options) => {
11 band(on, options)
12 panel(on)
13 git(on)
14 guards(on, options)
15}
16hooks/band.tsx 260 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import {
5 COMPACT_AT,
6 GIT_PANEL,
7 PANEL,
8 PANEL_TITLE,
9 ROUTER_URL,
10 TTL_MS,
11 DEFAULT_QUICK,
12 cacheTone,
13 continueText,
14 firstOpen,
15 heat,
16 isLightTheme,
17 palette,
18 tint,
19 nextFile,
20 openTasks,
21 projectRoot,
22} from './shared'
23import type { Quick } from '../types'
24
25const lastAt = atom({ plugin: 'cockpit', key: 'lastAt' } as const, null)
26const tick = atom({ plugin: 'cockpit', key: 'tick' } as const, 0)
27const next = atom({ plugin: 'cockpit', key: 'next' } as const, null)
28const tasks = atom({ plugin: 'cockpit', key: 'tasks' } as const, [])
29// null: 9router never answered this session, so it stays hidden
30const router = atom({ plugin: 'cockpit', key: 'router' } as const, null)
31const quick = atom({ plugin: 'cockpit', key: 'quick' } as const, [])
32
33async function loadQuick($: EngineInterface) {
34 const root = projectRoot(await $.session.root())
35 const file = `${root}/.claude/quick.json`
36 const own: Quick[] | null = (await $.fs.exists(file)) ? JSON.parse(await $.fs.read(file)) : null
37 const found = own ?? DEFAULT_QUICK.find(([re]) => re.test(root))?.[1] ?? []
38 await update($, quick, () => found.slice(0, 4))
39}
40
41async function pulse($: EngineInterface) {
42 await update($, tick, n => n + 1)
43 const isUp = await $.http
44 .fetch(ROUTER_URL)
45 .then(r => r.status < 500)
46 .catch(() => false)
47 const was = await read($, router)
48 const now = isUp ? true : was === null ? null : false
49 if (now !== was) await update($, router, () => now)
50}
51
52async function loadNext($: EngineInterface) {
53 const file = nextFile(await $.session.root())
54 const text = (await $.fs.exists(file)) ? await $.fs.read(file) : ''
55 const list = openTasks(text)
56 await update($, next, () => list[0] ?? null)
57 await update($, tasks, () => list.slice(0, 5))
58 return { file, text }
59}
60
61// A press queues a prompt, so a double click (or a click before the view redraws) would send it twice.
62let lastSent = { text: '', at: 0 }
63
64async function send($: EngineInterface, text: string) {
65 const now = await $.clock.now()
66 if (lastSent.text === text && now - lastSent.at < 10_000) return
67 lastSent = { text, at: now }
68 await $.prompt.submit({ text, asUser: true })
69}
70
71// A press's own work is dropped when the press ends, so /compact starts from a timer and the timer
72// returns the run, which keeps its dispatch alive until compaction is done.
73function compactNow($: EngineInterface, file: string) {
74 void $.clock.after(1, () =>
75 $.command
76 .run({
77 command: 'compact',
78 args: `Keep the current plan, the open tasks in ${file}, open PRs, decisions made and unresolved bugs.`,
79 })
80 .catch((error: unknown) => $.ui.toast(`Compacting failed: ${error instanceof Error ? error.message : String(error)}`)),
81 )
82}
83
84const openGit = ($: EngineInterface) => $.ui.open({ id: GIT_PANEL, title: 'Git' })
85
86async function openPanel($: EngineInterface) {
87 return $.ui.open({ id: PANEL, title: PANEL_TITLE })
88}
89
90
91// The one-line band above the prompt. It carries only what you glance at; the rest is in the panel.
92export const register: Register = on => {
93 on('session.start', async ($, e, nextHook) => {
94 if (e.seconds_since_last_response !== undefined) {
95 const at = (await $.clock.now()) - e.seconds_since_last_response * 1000
96 await update($, lastAt, () => at)
97 }
98 await loadNext($)
99 await $.command.register({
100 name: 'next',
101 description: 'Next task: /next <text> adds one on top, /next done checks it off',
102 })
103 await $.command.register({
104 name: 'cockpit',
105 description: 'Open the cockpit panel: cache, context, limits, cost and the next tasks',
106 })
107 await $.command.register({
108 name: 'git',
109 description: 'Open the git panel: branch, open and stacked PRs, worktrees and what is safe to tidy up',
110 })
111 await loadQuick($).catch(() => undefined)
112 void pulse($)
113 $.clock.every(30_000, () => void pulse($))
114
115 return nextHook(e)
116 })
117
118 let warnedCompact = false
119 on('turn.complete', async ($, e, nextHook) => {
120 const pct = (await $.session.usage()).context.percent ?? 0
121 if (pct >= COMPACT_AT && !warnedCompact) $.ui.toast(`Context at ${pct}%: compact soon. The cockpit panel has a button that keeps the plan.`)
122 warnedCompact = pct >= COMPACT_AT
123
124 if (e.agentId === undefined && e.usage) {
125 const at = await $.clock.now()
126 await update($, lastAt, () => at)
127 }
128 const { file, text } = await loadNext($)
129 const task = firstOpen(text)
130 if (e.agentId === undefined && task) void $.prompt.suggest({ text: continueText(task, file) })
131
132 return nextHook(e)
133 })
134
135 on('command.run', { command: 'next' }, async ($, e) => {
136 const { file, text } = await loadNext($)
137 const arg = e.args.trim()
138 if (arg === '') return { text: `next › ${firstOpen(text) ?? 'nothing queued'} (${file})` }
139
140 const updated =
141 arg === 'done'
142 ? text.replace(/^(\s*- )\[ \]/m, '$1[x]')
143 : `- [ ] ${arg}\n${text}`
144 await $.fs.write(file, updated)
145 await loadNext($)
146
147 return { text: arg === 'done' ? 'Checked off.' : `Queued: ${arg}` }
148 })
149
150 on('command.run', { command: 'cockpit' }, async $ => {
151 const opened = await openPanel($)
152 return { text: opened.isPlaced ? 'Cockpit panel opened.' : `The panel waits: ${opened.reason}` }
153 })
154
155 on('command.run', { command: 'git' }, async $ => {
156 const opened = await openGit($)
157 return { text: opened.isPlaced ? 'Git panel opened.' : `The panel waits: ${opened.reason}` }
158 })
159
160 on('ui.render', { component: 'AbovePrompt' }, async ($, e, nextHook) => {
161 if (e.props.hasSurvey) return nextHook(e)
162
163 // What other plugins draw in this slot (replay hint, reflect proposal, ...) sits beneath our row.
164 const below = await nextHook(e)
165 await read($, tick) // the 30-second pulse redraws the countdown
166 const at = await read($, lastAt)
167 const task = await read($, next)
168 const usage = await $.session.usage()
169 const now = await $.clock.now()
170 const limit = (kind: string) => usage.rateLimits.find(r => r.kind === kind)?.percentUsed
171 const file = nextFile(await $.session.root())
172
173 const cache = cacheTone({ isWorking: e.props.isWorking, left: at === null ? null : TTL_MS - (now - at) })
174 const ctxPct = usage.context.percent
175 const needsCompact = (ctxPct ?? 0) >= COMPACT_AT
176 const isUp = await read($, router)
177 const { Box, Text, Button } = $.ui.resolve(e)
178 const pal = palette(isLightTheme(await $.config.list().catch(() => [])))
179
180 // One piece of the stats: a dim label and a value that turns amber, then red, as it fills.
181 const stat = (label: string, value: string, pct?: number) => (
182 <Text>
183 <Text dimColor>{label} </Text>
184 <Text color={tint(heat(pct), pal)}>{value}</Text>
185 </Text>
186 )
187 // Limits only earn a place on the line once they are worth noticing; the panel always shows them.
188 const five = limit('five_hour')
189 const week = limit('seven_day')
190
191 const stats = (
192 <Box flexDirection="row" gap={2} flexShrink={0}>
193 <Text bold color={tint(cache.color, pal)}>
194 {cache.glyph} {cache.label}
195 </Text>
196 {usage.context.tokens !== undefined &&
197 stat('ctx', `${(usage.context.tokens / 1000).toFixed(1)}k${ctxPct !== undefined && ctxPct >= 60 ? ` ${ctxPct}%` : ''}`, ctxPct)}
198 {five !== undefined && five >= 60 && stat('5h', `${Math.round(five)}%`, five)}
199 {week !== undefined && week >= 60 && stat('wk', `${Math.round(week)}%`, week)}
200 {isUp === false && <Text color={pal.hot}>9router down</Text>}
201 </Box>
202 )
203
204 const upNext = (
205 <Box flexGrow={1} flexShrink={1} minWidth={10}>
206 <Text wrap="truncate-end">
207 <Text bold color={pal.accent}>
208 Next{' '}
209 </Text>
210 {task ?? <Text dimColor>nothing queued</Text>}
211 </Text>
212 </Box>
213 )
214
215 const buttons = (
216 <Box flexDirection="row" gap={2} flexShrink={0}>
217 {!e.props.isWorking && needsCompact && (
218 <Button key="compact" plain hotkey="k" onPress={() => compactNow($, file)}>
219 <Text bold color={pal.accent}>{`[ Compact ${ctxPct}% ]`}</Text>
220 </Button>
221 )}
222 {!e.props.isWorking && task && (
223 <Button key="continue" plain hotkey="c" onPress={() => void send($, continueText(task, file))}>
224 <Text bold color={pal.accent}>[ Continue ]</Text>
225 </Button>
226 )}
227 <Button key="git" plain hotkey="g" onPress={() => void openGit($)}>
228 <Text>[ Git ]</Text>
229 </Button>
230 <Button key="details" plain hotkey="d" onPress={() => void openPanel($)}>
231 <Text>[ Details ]</Text>
232 </Button>
233 </Box>
234 )
235
236 // Wide: one row. Narrow: the stats on their own row so the task and buttons keep room.
237 const isNarrow = (e.props.bodyColumns ?? 120) < 72
238 return (
239 <Box flexDirection="column">
240 {isNarrow ? (
241 <Box flexDirection="column">
242 {stats}
243 <Box flexDirection="row" gap={2}>
244 {upNext}
245 {buttons}
246 </Box>
247 </Box>
248 ) : (
249 <Box flexDirection="row" alignItems="center" gap={3}>
250 {stats}
251 {upNext}
252 {buttons}
253 </Box>
254 )}
255 {below}
256 </Box>
257 )
258 })
259}
260hooks/git.tsx 316 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, On } from 'claude-code'
3
4import { orderPrs, parseLines, parseLog, parsePrs, parseStatus, parseWorktrees, repoName, statusLetter, tidyPlan } from './gitparse'
5import { GIT_PANEL, isLightTheme, palette } from './shared'
6import type { Palette } from './shared'
7import type { GitInfo } from '../types'
8
9const tick = atom({ plugin: 'cockpit', key: 'tick' } as const, 0)
10const git = atom({ plugin: 'cockpit', key: 'git' } as const, null)
11// Which sections the person folded; a section not listed is open.
12const fold = atom({ plugin: 'cockpit', key: 'gitOpen' } as const, {})
13
14const FRESH_MS = 60_000 // git state is re-read at most this often while the panel is drawn
15const GH_FRESH_MS = 180_000 // gh asks the network, so less often
16
17let inflight = false
18let lastSent = { text: '', at: 0 }
19
20async function sh($: EngineInterface, argv: string[], timeoutMs = 20_000): Promise<string | null> {
21 try {
22 const r = await $.process.run(argv, { timeoutMs })
23 return r.exitCode === 0 ? r.stdout : null
24 } catch {
25 return null
26 }
27}
28
29// Reads the repo the session is in. Never changes anything: every change goes through Claude, as a prompt.
30async function refresh($: EngineInterface, withGh: boolean) {
31 if (inflight) return
32 inflight = true
33 try {
34 const now = await $.clock.now()
35 const old = await read($, git)
36 const status = await sh($, ['git', 'status', '--porcelain=v1', '-b'])
37 if (status === null) {
38 await update($, git, () => ({ ...(old ?? EMPTY), at: now, error: 'This folder is not a git repository.' }))
39 return
40 }
41 const root = (await $.session.root()) ?? ''
42 const base = ((await sh($, ['git', 'symbolic-ref', '--short', 'refs/remotes/origin/HEAD'])) ?? 'origin/main').trim().replace(/^origin\//, '')
43 const worktrees = parseWorktrees((await sh($, ['git', 'worktree', 'list', '--porcelain'])) ?? '')
44 const merged = parseLines((await sh($, ['git', 'branch', '--merged', `origin/${base}`, '--format=%(refname:short)'])) ?? '')
45
46 const log = parseLog((await sh($, ['git', 'log', '-12', '--pretty=format:%h%x1f%s%x1f%ar%x1f%D'])) ?? '')
47
48 let prs = old?.prs ?? null
49 let mergedHeads = old?.mergedHeads ?? []
50 let ghAt = old?.ghAt ?? 0
51 if (withGh) {
52 const open = await sh($, ['gh', 'pr', 'list', '--author', '@me', '--state', 'open', '--limit', '40', '--json', 'number,title,headRefName,baseRefName,isDraft,statusCheckRollup'], 30_000)
53 const done = await sh($, ['gh', 'pr', 'list', '--author', '@me', '--state', 'merged', '--limit', '40', '--json', 'headRefName'], 30_000)
54 prs = open === null ? null : parsePrs(open)
55 mergedHeads = done === null ? [] : (JSON.parse(done) as { headRefName: string }[]).map(r => r.headRefName)
56 ghAt = now
57 }
58 await update($, git, () => ({ root, base, worktrees, merged, log, prs, mergedHeads, at: now, ghAt, error: null, ...parseStatus(status) }))
59 } finally {
60 inflight = false
61 }
62}
63
64const EMPTY: GitInfo = {
65 root: '', branch: '', base: 'main', ahead: 0, behind: 0, hasUpstream: false, staged: 0, changed: 0, untracked: 0,
66 files: [], log: [], worktrees: [], merged: [], prs: null, mergedHeads: [], at: 0, ghAt: 0, error: null,
67}
68
69async function send($: EngineInterface, text: string) {
70 const now = await $.clock.now()
71 if (lastSent.text === text && now - lastSent.at < 10_000) return
72 lastSent = { text, at: now }
73 await $.prompt.submit({ text, asUser: true })
74}
75
76const PLAN = {
77 commit: 'Look at my uncommitted changes (git status, git diff). Group them into logical commits with clear messages and commit them. Do not push.',
78 commitWith: (message: string) => `Commit my changes with exactly this message: ${JSON.stringify(message)}. Stage everything that belongs to it first. Do not push.`,
79 push: 'Push the current branch to origin (set the upstream if there is none). Never force push.',
80 pr: (base: string) => `Open a pull request from the current branch into ${base} with a clear title and a description of what changed and why. Check first that no PR is already open for it.`,
81 sync: (base: string) => `Bring this branch up to date with ${base}. In an app-made worktree use the sync_with_base_branch tool; otherwise merge origin/${base} and resolve any conflicts. Tell me what conflicted.`,
82 merge: (n: number, head: string, base: string) =>
83 `Check that PR #${n} (${head} into ${base}) has green checks and no conflicts, then merge it the way this repo usually merges and delete its branch. If other open PRs are stacked on it, retarget them to ${base} afterwards.`,
84 tidy: (worktrees: string[], branches: string[]) =>
85 `Tidy up. These worktree branches and local branches are already merged: ${[...worktrees, ...branches].join(', ')}. For each, first confirm it has no unpushed or uncommitted work, then remove its worktree (use clean_up_worktrees) and delete the local branch. Do not touch anything not listed.`,
86}
87
88export function register(on: On) {
89 on('ui.render', { component: 'Pane', requestId: GIT_PANEL }, async ($, e, nextHook) => {
90 if (e.requestId !== GIT_PANEL) return nextHook(e)
91
92 await read($, tick) // redraws every 30 seconds
93 const g = await read($, git)
94 const now = await $.clock.now()
95 if (g === null || now - g.at > FRESH_MS || (g.ghAt === 0 && g.error === null) || now - g.ghAt > GH_FRESH_MS) {
96 void refresh($, g === null || now - g.ghAt > GH_FRESH_MS)
97 }
98
99 const ui = $.ui.resolve(e)
100 const { Box, Text, Button } = ui
101 const pal: Palette = palette(isLightTheme(await $.config.list().catch(() => [])))
102 const folded = await read($, fold)
103
104 // A control drawn as text, `[ Push ]`, so nothing about it is rounded.
105 const btn = (key: string, label: string, onPress: () => void, isMain = false) => (
106 <Button key={key} plain onPress={onPress}>
107 <Text bold={isMain} color={isMain ? pal.accent : undefined}>{`[ ${label} ]`}</Text>
108 </Button>
109 )
110 // A section like VS Code's: a strip a step off the ground with a fold arrow, the title in capitals and a
111 // square count at the right; the person's fold is remembered.
112 const section = (id: string, title: string, count: number | null, children: unknown) => {
113 const isOpen = folded[id] !== false
114 return (
115 <Box flexDirection="column">
116 <Box flexDirection="row" alignItems="center" backgroundColor={pal.surface} paddingX={1}>
117 <Box flexGrow={1}>
118 <Button key={`fold-${id}`} plain onPress={() => void update($, fold, f => ({ ...f, [id]: !isOpen }))}>
119 <Text bold>{`${isOpen ? '▾' : '▸'} ${title.toUpperCase()}`}</Text>
120 </Button>
121 </Box>
122 {count !== null && count > 0 && (
123 <Box backgroundColor={pal.muted} paddingX={1}>
124 <Text bold color={pal.bg ?? '#ffffff'}>{String(count)}</Text>
125 </Box>
126 )}
127 </Box>
128 {isOpen && (
129 <Box flexDirection="column" paddingX={1} paddingY={1}>
130 {children}
131 </Box>
132 )}
133 </Box>
134 )
135 }
136 const onAccent = pal.bg ?? '#ffffff'
137 // One short ref per commit: not the branch we are on (the bar says it), tags without "tag: ", cut at 18.
138 const chip = (refs: string[]) => {
139 const r = refs.find(x => x !== g?.branch)?.replace(/^tag: /, '')
140 return r === undefined ? undefined : r.length > 18 ? `${r.slice(0, 17)}…` : r
141 }
142 const LETTER: Record<string, string> = { M: pal.warn, A: pal.accent, U: pal.accent, D: pal.hot, R: pal.info, C: pal.info }
143
144 const body = (() => {
145 if (g === null) return <Box paddingX={1}><Text dimColor>Reading the repository…</Text></Box>
146 if (g.error) return <Box paddingX={1}><Text color={pal.hot}>{g.error}</Text></Box>
147
148 const dirty = g.staged + g.changed + g.untracked
149 const ordered = g.prs ? orderPrs(g.prs) : []
150 const hasPr = g.prs?.some(p => p.head === g.branch) ?? false
151 const plan = tidyPlan(g)
152 const tidyCount = plan.worktrees.length + plan.branches.length
153 const mark = (c: string) => (c === 'pass' ? '✓ checks pass' : c === 'fail' ? '✗ checks fail' : c === 'pending' ? '… checks running' : 'no checks')
154 const markColor = (c: string) => (c === 'pass' ? pal.accent : c === 'fail' ? pal.hot : c === 'pending' ? pal.warn : pal.muted)
155 const shown = g.files.slice(0, 14)
156
157 return (
158 <Box flexDirection="column" gap={1}>
159 <Box flexDirection="column" gap={1}>
160 <Box flexDirection="row" alignItems="center" backgroundColor={pal.accent} paddingX={1}>
161 <Box flexGrow={1} flexShrink={1} minWidth={4}>
162 <Text bold color={onAccent} wrap="truncate-end">{`⎇ ${g.branch}`}</Text>
163 </Box>
164 <Text bold color={onAccent}>{g.hasUpstream ? `↑${g.ahead} ↓${g.behind}` : 'not pushed'}</Text>
165 </Box>
166 <Box flexDirection="row" gap={2} flexWrap="wrap" paddingX={1}>
167 {g.behind > 0 && btn('sync', `Sync with ${g.base}`, () => void send($, PLAN.sync(g.base)), true)}
168 {(g.ahead > 0 || !g.hasUpstream) && btn('push', 'Push', () => void send($, PLAN.push), dirty === 0)}
169 {!hasPr && (g.ahead > 0 || g.hasUpstream) && g.branch !== g.base && btn('pr', 'Open PR', () => void send($, PLAN.pr(g.base)))}
170 {g.behind === 0 && g.ahead === 0 && g.hasUpstream && <Text dimColor>Up to date with origin.</Text>}
171 </Box>
172 {dirty > 0 && (
173 <Box paddingX={1}>
174 <ui.Input key="message" placeholder="Commit message" submitLabel="Commit" onSubmit={m => m.trim() !== '' && void send($, PLAN.commitWith(m.trim()))} />
175 </Box>
176 )}
177 </Box>
178
179 {section(
180 'changes',
181 'Changes',
182 dirty,
183 dirty === 0 ? (
184 <Text dimColor>Working tree clean.</Text>
185 ) : (
186 <Box flexDirection="column">
187 {shown.map(f => {
188 const slash = f.path.lastIndexOf('/')
189 const letter = statusLetter(f)
190 return (
191 <Box key={`${f.x}${f.y}${f.path}`} flexDirection="row" gap={1}>
192 <Text bold color={LETTER[letter] ?? pal.muted}>{letter}</Text>
193 <Box flexShrink={1} minWidth={4}>
194 <Text wrap="truncate-start">
195 <Text>{f.path.slice(slash + 1)}</Text>
196 <Text dimColor>{slash > 0 ? ` ${f.path.slice(0, slash)}` : ''}</Text>
197 </Text>
198 </Box>
199 </Box>
200 )
201 })}
202 {g.files.length > shown.length && <Text dimColor>{`+ ${g.files.length - shown.length} more`}</Text>}
203 <Box paddingTop={1} flexDirection="row" gap={2}>
204 {btn('commit', 'Let Claude write the message', () => void send($, PLAN.commit))}
205 </Box>
206 </Box>
207 ),
208 )}
209
210 {section(
211 'graph',
212 'Graph',
213 g.log.length,
214 <Box flexDirection="column">
215 {g.log.map((c, i) => (
216 <Box key={c.hash} flexDirection="row" gap={1}>
217 <Text color={i === 0 ? pal.accent : pal.muted}>{i === 0 ? '●' : '○'}</Text>
218 <Box flexGrow={1} flexShrink={1} minWidth={4}>
219 <Text wrap="truncate-end">{c.subject}</Text>
220 </Box>
221 {chip(c.refs) !== undefined && (
222 <Box flexShrink={0}>
223 <Text color={chip(c.refs)!.startsWith('origin/') ? pal.info : pal.accent}>{chip(c.refs)}</Text>
224 </Box>
225 )}
226 <Text dimColor>{c.when}</Text>
227 </Box>
228 ))}
229 </Box>,
230 )}
231
232 {section(
233 'prs',
234 'Pull requests',
235 g.prs?.length ?? 0,
236 g.prs === null ? (
237 <Text dimColor wrap="wrap">GitHub CLI (gh) is not signed in here, so open PRs are hidden.</Text>
238 ) : ordered.length === 0 ? (
239 <Text dimColor>No open pull requests.</Text>
240 ) : (
241 <Box flexDirection="column" gap={1}>
242 {ordered.map(({ pr, depth }) => (
243 <Box key={`pr${pr.number}`} flexDirection="row" alignItems="center" gap={2}>
244 <Box flexGrow={1} flexShrink={1} minWidth={4} flexDirection="column">
245 <Text wrap="truncate-end" bold={pr.head === g.branch}>{`${depth > 0 ? `${' '.repeat(depth - 1)}└ ` : ''}#${pr.number} ${pr.title}`}</Text>
246 <Text wrap="truncate-end">
247 <Text dimColor>{`${pr.head} → ${pr.base}${pr.isDraft ? ' · draft' : ''} · `}</Text>
248 <Text color={markColor(pr.checks)}>{mark(pr.checks)}</Text>
249 </Text>
250 </Box>
251 {!pr.isDraft && pr.checks === 'pass' && btn(`merge-${pr.number}`, 'Merge', () => void send($, PLAN.merge(pr.number, pr.head, pr.base)), depth === 0)}
252 </Box>
253 ))}
254 {ordered.some(o => o.depth > 0) && <Text dimColor wrap="wrap">Stacked PRs: merge the top one first, then the ones under it.</Text>}
255 </Box>
256 ),
257 )}
258
259 {section(
260 'worktrees',
261 'Worktrees',
262 g.worktrees.length,
263 <Box flexDirection="column">
264 {g.worktrees.slice(0, 8).map(w => {
265 const landed = !w.isMain && w.branch !== null && plan.worktrees.some(p => p.path === w.path)
266 const isHere = w.branch === g.branch
267 return (
268 <Text key={w.path} wrap="truncate-end">
269 <Text color={isHere ? pal.accent : landed ? pal.muted : undefined} bold={isHere}>{`${isHere ? '● ' : ' '}${w.branch ?? w.path.split('/').pop()}`}</Text>
270 {w.isMain && <Text dimColor> · main checkout</Text>}
271 {isHere && <Text dimColor> · you are here</Text>}
272 {landed && <Text color={pal.accent}> · merged</Text>}
273 </Text>
274 )
275 })}
276 {g.worktrees.length > 8 && <Text dimColor>{`+ ${g.worktrees.length - 8} more`}</Text>}
277 </Box>,
278 )}
279
280 {section(
281 'tidy',
282 'Tidy up',
283 tidyCount,
284 tidyCount === 0 ? (
285 <Text dimColor>Nothing merged is left lying around.</Text>
286 ) : (
287 <Box flexDirection="column" gap={1}>
288 <Text wrap="wrap">{`${plan.worktrees.length} merged worktrees and ${plan.branches.length} merged branches can go.`}</Text>
289 <Box>{btn('tidy', `Tidy up ${tidyCount}`, () => void send($, PLAN.tidy(plan.worktrees.map(w => w.branch!), plan.branches)), true)}</Box>
290 </Box>
291 ),
292 )}
293 </Box>
294 )
295 })()
296
297 return (
298 <Box flexDirection="column" gap={1} height="100%" backgroundColor={pal.bg} paddingBottom={1}>
299 <Box flexDirection="row" alignItems="center" paddingX={2} paddingTop={1}>
300 <Box flexGrow={1}>
301 <Text>
302 <Text bold color={pal.muted}>SOURCE CONTROL</Text>
303 <Text dimColor>{g ? ` ${repoName(g.root)}` : ''}</Text>
304 </Text>
305 </Box>
306 {btn('refresh', 'Refresh', () => void refresh($, true))}
307 </Box>
308 {body}
309 <Box paddingX={2}>
310 <Text dimColor wrap="wrap">Buttons ask Claude to do the change, so you see every command. This panel only reads.</Text>
311 </Box>
312 </Box>
313 )
314 })
315}
316hooks/guards.ts 67 lines1import type { Register } from 'claude-code'
2
3// The user's rule: Claude never appears as a co-author on commits, PRs or merges.
4const CLAUDE_CREDIT =
5 /co-authored-by:[^\n"']*(claude|anthropic)|noreply@anthropic\.com|generated with \[?claude code/i
6
7const SECRETS: [string, RegExp][] = [
8 ['sk- API key', /\bsk-[A-Za-z0-9_-]{16,}/],
9 ['sk_ API key', /\bsk_[A-Za-z0-9]{24,}/],
10 ['GitHub token', /\b(ghp_|gho_|ghs_|github_pat_)[A-Za-z0-9_]{20,}/],
11 ['AWS access key', /\bAKIA[0-9A-Z]{16}\b/],
12 ['Slack token', /\bxox[abpr]-[A-Za-z0-9-]{10,}/],
13 ['Google API key', /\bAIza[0-9A-Za-z_-]{35}\b/],
14]
15
16const UI_WORDS =
17 /\b(ui|ux|design|redesign|layout|colou?rs?|theme|palette|animations?|animate|pixel|fonts?|typography|css|styling|landing page|visual)\b/i
18
19function findSecret(text: string): string | null {
20 return SECRETS.find(([, re]) => re.test(text))?.[0] ?? null
21}
22
23function hasClaudeCredit(command: string): boolean {
24 return CLAUDE_CREDIT.test(command)
25}
26
27export const register: Register = on => {
28 let allowOnce: string | null = null
29
30 on('tool.call', { tool: 'Bash' }, ($, e, next) =>
31 hasClaudeCredit(e.command)
32 ? {
33 deny:
34 'guards: the user never wants Claude credited. Remove every Co-Authored-By Claude/Anthropic trailer and any "Generated with Claude Code" line, then run it again.',
35 }
36 : next(e),
37 )
38
39 on('prompt.submit', async ($, e, next) => {
40 if (e.origin?.kind === 'plugin') return next(e)
41
42 const secret = findSecret(e.text)
43 if (secret && allowOnce !== e.text) {
44 allowOnce = e.text
45 void $.prompt.fill({ text: e.text }).catch(() => undefined)
46 return {
47 drop: `Held back: this looks like a ${secret}. Anything sent stays in plain text in the transcript. Put it in an env file or a config instead, or press Enter again to send anyway.`,
48 }
49 }
50 allowOnce = null
51
52 const wantsDesign =
53 !e.text.startsWith('/') && UI_WORDS.test(e.text) && !/impeccable|frontend-design/i.test(e.text)
54 if (wantsDesign) {
55 return next({
56 ...e,
57 context: [
58 ...(e.context ?? []),
59 'This request touches UI or visual design: load and follow the impeccable skill (and frontend-design:frontend-design where it fits) before designing.',
60 ],
61 })
62 }
63
64 return next(e)
65 })
66}
67hooks/panel.tsx 285 lines1import { atom, read } from 'claude-code'
2import type { EngineInterface, On } from 'claude-code'
3
4import {
5 COMPACT_AT,
6 MARK,
7 PANEL,
8 TTL_MS,
9 cacheTone,
10 continueText,
11 heat,
12 isLightTheme,
13 nextFile,
14 palette,
15 planText,
16 tint,
17 until,
18} from './shared'
19import type { Palette, Tone } from './shared'
20
21// The same values the band keeps (same plugin and key, so the same state).
22const lastAt = atom({ plugin: 'cockpit', key: 'lastAt' } as const, null)
23const tick = atom({ plugin: 'cockpit', key: 'tick' } as const, 0)
24const tasks = atom({ plugin: 'cockpit', key: 'tasks' } as const, [])
25// null: 9router never answered this session, so it stays hidden
26const router = atom({ plugin: 'cockpit', key: 'router' } as const, null)
27const quick = atom({ plugin: 'cockpit', key: 'quick' } as const, [])
28
29// A press queues a prompt, so a double click would send it twice.
30let lastSent = { text: '', at: 0 }
31
32async function send($: EngineInterface, text: string) {
33 const now = await $.clock.now()
34 if (lastSent.text === text && now - lastSent.at < 10_000) return
35 lastSent = { text, at: now }
36 await $.prompt.submit({ text, asUser: true })
37}
38
39// A press's own work is dropped when the press ends, so /compact starts from a timer.
40function compactNow($: EngineInterface, file: string) {
41 void $.clock.after(1, () =>
42 $.command
43 .run({
44 command: 'compact',
45 args: `Keep the current plan, the open tasks in ${file}, open PRs, decisions made and unresolved bugs.`,
46 })
47 .catch((error: unknown) => $.ui.toast(`Compacting failed: ${error instanceof Error ? error.message : String(error)}`)),
48 )
49}
50
51// "1M", "200k": the context window as people say it.
52const windowLabel = (n: number) => (n >= 1_000_000 ? `${+(n / 1_000_000).toFixed(1)}M` : `${Math.round(n / 1000)}k`)
53
54// A mod's command, started from a timer so releasing the press does not cancel it.
55function runMod($: EngineInterface, command: string, args?: string) {
56 void $.clock.after(1, () =>
57 $.command
58 .run(args === undefined ? { command } : { command, args })
59 .catch((error: unknown) => $.ui.toast(`/${command} failed: ${error instanceof Error ? error.message : String(error)}`)),
60 )
61}
62
63// The mods this plugin bundles, each with the presses that drive it. Their state lives in their own
64// plugins and cannot be read from here, so a button names the action it does, never a state.
65const MODS: { name: string; note: string; actions: { label: string; command: string; args?: string }[] }[] = [
66 { name: 'Agents & progress', note: 'subagents, cost, flow progress', actions: [{ label: 'Open', command: 'agents-info' }] },
67 { name: 'File tree', note: 'sidebar with git status', actions: [{ label: 'Open', command: 'filetree' }] },
68 { name: 'Replay', note: 'step through the last edits', actions: [{ label: 'Open', command: 'replay' }] },
69 {
70 name: 'Skin',
71 note: 'transcript restyle',
72 actions: [
73 { label: 'Noir', command: 'skin', args: 'noir' },
74 { label: 'Off', command: 'skin', args: 'off' },
75 ],
76 },
77 {
78 name: 'Polish',
79 note: 'clean dictated prompts (Haiku)',
80 actions: [
81 { label: 'Auto', command: 'polish', args: 'auto' },
82 { label: 'Always', command: 'polish', args: 'always' },
83 { label: 'Off', command: 'polish', args: 'off' },
84 ],
85 },
86 { name: 'Reflect', note: 'catch corrections (uses Haiku)', actions: [{ label: 'On / off', command: 'reflect-pause' }] },
87 {
88 name: 'Keep-warm',
89 note: 'spends tokens every ~50 min',
90 actions: [
91 { label: 'Arm', command: 'keepwarm' },
92 { label: 'Stop', command: 'keepwarm', args: 'off' },
93 ],
94 },
95]
96
97// The mark and the name, all square: a prompt in pixel cells and a block cursor, drawn from the palette.
98// Drawn as an image, so it needs the namespace; the surface's own text falls back where it has no Svg.
99const headerSvg = (p: Palette) => {
100 const cells = MARK.flatMap((row, y) =>
101 [...row].map((c, x) => (c === '#' ? `<rect x="${x * 4 + 6}" y="${y * 4 + 6}" width="4" height="4" fill="${y >= 6 ? p.info : p.accent}"/>` : '')),
102 ).join('')
103 return (
104 `<svg xmlns="http://www.w3.org/2000/svg" width="300" height="52" viewBox="0 0 300 52" shape-rendering="crispEdges">` +
105 `<rect x="1" y="1" width="42" height="42" fill="${p.bg ?? '#f6f4ee'}" stroke="${p.accent}" stroke-width="2"/>` +
106 cells +
107 `<text x="58" y="26" font-family="SF Mono, Menlo, ui-monospace, monospace" font-size="22" font-weight="700" letter-spacing="1" fill="${p.fg}">cockpit</text>` +
108 `<rect x="164" y="9" width="12" height="19" fill="${p.accent}"/>` +
109 `<text x="58" y="41" font-family="SF Mono, Menlo, ui-monospace, monospace" font-size="11" fill="${p.muted}">cache, context, limits, mods</text>` +
110 `</svg>`
111 )
112}
113
114const LIMIT_NAMES: Record<string, string> = { five_hour: '5-hour limit', seven_day: 'Weekly limit' }
115
116// The roomy view: everything the band leaves out, in one place beside the conversation.
117export function register(on: On) {
118 on('ui.render', { component: 'Pane', requestId: PANEL }, async ($, e, nextHook) => {
119 if (e.requestId !== PANEL) return nextHook(e)
120
121 await read($, tick) // redraws every 30 seconds
122 const at = await read($, lastAt)
123 const list = await read($, tasks)
124 const shortcuts = await read($, quick)
125 const isUp = await read($, router)
126 const usage = await $.session.usage()
127 const now = await $.clock.now()
128 const file = nextFile(await $.session.root())
129 const ui = $.ui.resolve(e)
130 const { Box, Text, Button } = ui
131 const pal = palette(isLightTheme(await $.config.list().catch(() => [])))
132
133 const left = at === null ? null : TTL_MS - (now - at)
134 const cache = cacheTone({ isWorking: false, left })
135 const ctxPct = usage.context.percent
136
137 // One labelled block; the title is dim and small so the numbers lead.
138 const section = (title: string, children: unknown) => (
139 <Box flexDirection="column">
140 <Text bold color={pal.muted}>{title}</Text>
141 {children}
142 </Box>
143 )
144 // A solid bar: a track and a filled part sized in percent, so it is always exactly as wide as the
145 // panel and can never wrap or show seams the way a row of block characters does.
146 // A control drawn as text, `[ Open ]`, so nothing about it is rounded. The label stays its name.
147 const btn = (key: string, label: string, onPress: () => void, o: { hotkey?: string; isMain?: boolean } = {}) => (
148 <Button key={key} plain hotkey={o.hotkey} onPress={onPress}>
149 <Text bold={o.isMain} color={o.isMain ? pal.accent : undefined}>{`[ ${label} ]`}</Text>
150 </Button>
151 )
152 const meter = (pct: number, tone?: Tone['color']) => (
153 <Box width="100%" height={1} backgroundColor={pal.track}>
154 <Box width={`${Math.max(0, Math.min(100, Math.round(pct)))}%`} height={1} backgroundColor={tint(tone, pal) ?? pal.accent} />
155 </Box>
156 )
157
158 return (
159 <Box flexDirection="column" paddingX={2} paddingY={1} gap={1} flexGrow={1} backgroundColor={pal.bg}>
160 {'Svg' in ui ? (
161 <ui.Svg source={headerSvg(pal)} alt="cockpit" width={300} height={52} />
162 ) : (
163 <Text bold color={pal.accent}>cockpit</Text>
164 )}
165
166 {section(
167 'Prompt cache',
168 <Box flexDirection="column">
169 <Text>
170 <Text bold color={tint(cache.color, pal)}>
171 {`${cache.glyph} ${cache.label === 'expired' || cache.label === 'cold' ? cache.label : `${cache.label} left`}`}
172 </Text>
173 <Text dimColor>{` of ${TTL_MS / 3_600_000} hour`}</Text>
174 </Text>
175 {meter(cache.frac * 100, cache.color)}
176 <Text dimColor wrap="wrap">
177 {left !== null && left > 0 ? 'Refreshes after every answer.' : 'The next message re-writes the context at full price.'}
178 </Text>
179 </Box>,
180 )}
181
182 {section(
183 'Context',
184 <Box flexDirection="column">
185 <Text>
186 <Text bold>{usage.context.tokens === undefined ? 'no reading yet' : `${(usage.context.tokens / 1000).toFixed(1)}k tokens`}</Text>
187 {ctxPct !== undefined && <Text color={tint(heat(ctxPct), pal)}>{` · ${ctxPct}%`}</Text>}
188 <Text dimColor>{` of ${windowLabel(usage.context.window)}`}</Text>
189 </Text>
190 {ctxPct !== undefined && meter(ctxPct, heat(ctxPct))}
191 <Box>
192 {btn('compact', 'Compact', () => compactNow($, file), { hotkey: 'k', isMain: (ctxPct ?? 0) >= COMPACT_AT })}
193 </Box>
194 </Box>,
195 )}
196
197 {usage.rateLimits.length > 0 &&
198 section(
199 'Plan limits',
200 <Box flexDirection="column" gap={1}>
201 {usage.rateLimits.map(r => {
202 const reset = r.resetsAt ? Date.parse(r.resetsAt) - now : NaN
203 return (
204 <Box key={r.kind} flexDirection="column">
205 <Text>
206 <Text>{LIMIT_NAMES[r.kind] ?? r.kind}</Text>
207 <Text bold color={tint(heat(r.percentUsed), pal)}>{` ${Math.round(r.percentUsed)}%`}</Text>
208 {Number.isFinite(reset) && <Text dimColor>{` · resets in ${until(reset)}`}</Text>}
209 </Text>
210 {meter(Math.min(100, r.percentUsed), heat(r.percentUsed))}
211 </Box>
212 )
213 })}
214 </Box>,
215 )}
216
217 {section(
218 'This session',
219 <Box flexDirection="column">
220 {usage.cost !== undefined && <Text bold>{`$${usage.cost.usd.toFixed(2)}`}</Text>}
221 {isUp !== null && (
222 <Text>
223 <Text color={isUp ? pal.accent : pal.hot}>● </Text>
224 <Text dimColor>{`9router ${isUp ? 'running' : 'not answering'}`}</Text>
225 </Text>
226 )}
227 </Box>,
228 )}
229
230 {section(
231 'Next up',
232 <Box flexDirection="column" gap={1}>
233 {list.length === 0 ? (
234 <Text dimColor wrap="wrap">Nothing queued. Press What's next? and Claude will write the next three.</Text>
235 ) : (
236 <Box flexDirection="column">
237 {list.map((t, i) => (
238 <Text key={`t${i}`} wrap="wrap" bold={i === 0} dimColor={i > 0}>
239 {`${i + 1} ${t}`}
240 </Text>
241 ))}
242 </Box>
243 )}
244 <Box flexDirection="row" gap={2}>
245 {list[0] && btn('continue', 'Continue', () => void send($, continueText(list[0]!, file)), { hotkey: 'c', isMain: true })}
246 {btn('plan', "What's next?", () => void send($, planText(file)), { hotkey: 'n' })}
247 </Box>
248 </Box>,
249 )}
250
251 {section(
252 'Mods',
253 <Box flexDirection="column" gap={1}>
254 {MODS.map(m => (
255 <Box key={m.name} flexDirection="row" alignItems="center" gap={2}>
256 <Box flexGrow={1} flexShrink={1} flexDirection="column">
257 <Text bold>{m.name}</Text>
258 <Text dimColor wrap="truncate-end">{m.note}</Text>
259 </Box>
260 {m.actions.map(a => (
261 btn(`${m.name}-${a.label}`, a.label, () => runMod($, a.command, a.args))
262 ))}
263 </Box>
264 ))}
265 </Box>,
266 )}
267
268 {shortcuts.length > 0 &&
269 section(
270 'Shortcuts',
271 <Box flexDirection="row" gap={2} flexWrap="wrap">
272 {shortcuts.map((q, i) => (
273 btn(`quick-${i}`, q.label, () => void send($, q.prompt), { hotkey: String(i + 1) })
274 ))}
275 </Box>,
276 )}
277
278 <Text dimColor wrap="wrap">
279 Tasks live in .claude/NEXT.md. /next adds one, /next done checks one off.
280 </Text>
281 </Box>
282 )
283 })
284}
285hooks/shared.ts 105 lines1import type { Quick } from '../types'
2
3// Everything the band and the panel both use: the values they draw, the project's files, the look.
4// Nothing here takes the engine `$` (the validator only lets `$` go into functions of the same file),
5// and the atoms are declared in each file that uses them (it must see them next to `read` and `update`).
6
7// ponytail: assumes the 1h prompt-cache TTL this session runs on; the engine exposes cache_ttl only on model switch
8export const TTL_MS = 60 * 60 * 1000
9export const COMPACT_AT = 70
10export const ROUTER_URL = 'http://127.0.0.1:20128/v1/models'
11export const PANEL = 'cockpit'
12export const PANEL_TITLE = 'Cockpit'
13export const GIT_PANEL = 'cockpit-git'
14
15export const DEFAULT_QUICK: [RegExp, Quick[]][] = [
16 [
17 /PUPSISPortal|IntPortal|intportal/,
18 [
19 { label: 'Rebuild', prompt: 'Rebuild the app and launch it so I can check the latest change.' },
20 { label: 'Simulator', prompt: 'Build and run the app in the iOS Simulator and open the live panel.' },
21 { label: 'Phone', prompt: 'Build and install the app on my real iPhone, following the phone notes in memory.' },
22 ],
23 ],
24 [
25 /Obsidian/,
26 [
27 { label: 'File → notes', prompt: "Run /file-to-notes on the newest PDF in this course's Resources that has no notes yet." },
28 { label: 'Export PDF', prompt: 'Run /export-to-pdf on the note I edited most recently.' },
29 { label: 'Assignment', prompt: "Run /assignment-notes on this course's newest assignment." },
30 ],
31 ],
32]
33
34// Worktrees share the main checkout's task list.
35export const projectRoot = (root: string) => root.replace(/\/\.claude\/worktrees\/[^/]+$/, '')
36export const nextFile = (root: string) => `${projectRoot(root)}/.claude/NEXT.md`
37
38export const openTasks = (text: string): string[] =>
39 text
40 .split('\n')
41 .filter(line => /^\s*- \[ \]/.test(line))
42 .map(line => line.replace(/^\s*- \[ \]\s*/, ''))
43
44export const firstOpen = (text: string) => openTasks(text)[0] ?? null
45
46export const continueText = (task: string, file: string) =>
47 `Continue with the next task: "${task}". When it is done, check it off in ${file} (- [x]) and add any follow-up tasks as "- [ ]" lines in order.`
48
49export const planText = (file: string) =>
50 `What's next? Read this project's plan, recent commits and open PRs, then write the next 3 concrete tasks as "- [ ]" lines at the top of ${file}. Don't start them.`
51
52// ---- the look ----------------------------------------------------------------------------------
53
54// Monokai on the dark theme, the same hues deepened enough to read on the light one.
55export type Palette = {
56 accent: string // Monokai green: brand, primary buttons, healthy
57 warn: string
58 hot: string
59 info: string
60 fg: string
61 muted: string
62 track: string // the empty part of a bar
63 surface: string // a header strip: a step off the ground
64 bg?: string // the panel's own ground; the light theme keeps the app's
65}
66const DARK: Palette = { accent: '#a6e22e', warn: '#e6db74', hot: '#f92672', info: '#66d9ef', fg: '#f8f8f2', muted: '#75715e', track: '#3e3d32', surface: '#34352d', bg: '#272822' }
67const LIGHT: Palette = { accent: '#4d7c0f', warn: '#8a6d00', hot: '#c2185b', info: '#0b7285', fg: '#272822', muted: '#75715e', track: '#e6e3dc', surface: '#ece9e1' }
68export const palette = (isLight: boolean): Palette => (isLight ? LIGHT : DARK)
69export const isLightTheme = (rows: { key: string; value?: unknown }[]) =>
70 String(rows.find(r => r.key === 'theme')?.value ?? 'dark').includes('light')
71
72export type Tone = { color: 'accent' | 'warn' | 'hot'; glyph: string; label: string; frac: number }
73
74// Tone names become the palette's colours here, so the logic never knows a hex.
75export const tint = (c: Tone['color'] | undefined, p: Palette) => (c === undefined ? undefined : p[c])
76
77// A pie glyph for the share of the cache's hour that is left.
78export const pie = (frac: number) => (frac > 0.875 ? '●' : frac > 0.625 ? '◕' : frac > 0.375 ? '◑' : frac > 0.125 ? '◔' : '○')
79
80export function cacheTone(v: { isWorking: boolean; left: number | null }): Tone {
81 if (v.isWorking) return { color: 'accent', glyph: '✻', label: 'working', frac: 1 }
82 if (v.left === null) return { color: 'hot', glyph: '○', label: 'cold', frac: 0 }
83 if (v.left <= 0) return { color: 'hot', glyph: '○', label: 'expired', frac: 0 }
84 return {
85 color: v.left > 10 * 60_000 ? 'accent' : 'warn',
86 glyph: pie(v.left / TTL_MS),
87 label: `${Math.ceil(v.left / 60_000)}m`,
88 frac: v.left / TTL_MS,
89 }
90}
91
92// Plain until it matters.
93export const heat = (pct?: number): Tone['color'] | undefined => (pct === undefined ? undefined : pct >= 85 ? 'hot' : pct >= 60 ? 'warn' : undefined)
94
95// "2h 10m", "3d 4h", "40m": how long until a limit resets.
96export function until(ms: number): string {
97 const m = Math.max(0, Math.round(ms / 60_000))
98 if (m >= 2880) return `${Math.floor(m / 1440)}d ${Math.floor((m % 1440) / 60)}h`
99 if (m >= 60) return `${Math.floor(m / 60)}h ${m % 60}m`
100 return `${m}m`
101}
102
103// The mark: a prompt in an 8x8 bitmap, drawn as square cells (rows from 6 down are the cursor line).
104export const MARK = ['#.......', '.#......', '..#.....', '.#......', '#.......', '........', '....####', '........']
105hooks/gitparse.ts 114 lines1import type { GitCommit, GitFile, GitInfo, Pr, Worktree } from '../types'
2
3// Pure readers of what git and gh print, so they can be tested without a repository.
4
5export function parseStatus(text: string) {
6 const lines = text.split('\n').filter(Boolean)
7 const head = lines[0]?.startsWith('## ') ? lines[0].slice(3) : ''
8 const branch = head.split('...')[0]!.replace(/^No commits yet on /, '').replace(/^HEAD \(no branch\)/, 'detached HEAD')
9 const hasUpstream = head.includes('...')
10 const ahead = Number(/ahead (\d+)/.exec(head)?.[1] ?? 0)
11 const behind = Number(/behind (\d+)/.exec(head)?.[1] ?? 0)
12 let staged = 0
13 let changed = 0
14 let untracked = 0
15 const files: GitFile[] = []
16 for (const l of lines.slice(1)) {
17 if (files.length < 200) files.push({ x: l[0] ?? ' ', y: l[1] ?? ' ', path: l.slice(3).replace(/^.* -> /, '') })
18 if (l.startsWith('??')) untracked++
19 else {
20 if (l[0] !== ' ') staged++
21 if (l[1] !== ' ') changed++
22 }
23 }
24 return { branch, hasUpstream, ahead, behind, staged, changed, untracked, files }
25}
26
27export function parseWorktrees(text: string): Worktree[] {
28 return text
29 .split('\n\n')
30 .map(b => b.trim())
31 .filter(Boolean)
32 .map((b, i) => ({
33 path: /^worktree (.+)$/m.exec(b)?.[1] ?? '',
34 branch: /^branch refs\/heads\/(.+)$/m.exec(b)?.[1] ?? null,
35 isMain: i === 0,
36 }))
37}
38
39export const parseLines = (text: string) => text.split('\n').map(l => l.trim()).filter(Boolean)
40
41type Check = { conclusion?: string | null; status?: string | null; state?: string | null }
42function rollup(checks: Check[] | undefined): Pr['checks'] {
43 if (!checks || checks.length === 0) return 'none'
44 const bad = ['FAILURE', 'ERROR', 'TIMED_OUT', 'CANCELLED', 'ACTION_REQUIRED']
45 if (checks.some(c => bad.includes(c.conclusion ?? '') || bad.includes(c.state ?? ''))) return 'fail'
46 if (checks.some(c => (c.status && c.status !== 'COMPLETED') || c.state === 'PENDING' || c.state === 'EXPECTED')) return 'pending'
47 return 'pass'
48}
49
50export function parsePrs(json: string): Pr[] {
51 const rows = JSON.parse(json) as {
52 number: number
53 title: string
54 headRefName: string
55 baseRefName: string
56 isDraft: boolean
57 statusCheckRollup?: Check[]
58 }[]
59 return rows.map(r => ({
60 number: r.number,
61 title: r.title,
62 head: r.headRefName,
63 base: r.baseRefName,
64 isDraft: r.isDraft,
65 checks: rollup(r.statusCheckRollup),
66 }))
67}
68
69// Stacks first-to-merge on top: a PR whose base is another open PR's head sits under that PR, indented.
70export function orderPrs(prs: Pr[]): { pr: Pr; depth: number }[] {
71 const heads = new Set(prs.map(p => p.head))
72 const out: { pr: Pr; depth: number }[] = []
73 const place = (pr: Pr, depth: number, seen: Set<number>) => {
74 if (seen.has(pr.number)) return
75 seen.add(pr.number)
76 out.push({ pr, depth })
77 for (const child of prs.filter(c => c.base === pr.head)) place(child, depth + 1, seen)
78 }
79 const seen = new Set<number>()
80 for (const pr of prs.filter(p => !heads.has(p.base))) place(pr, 0, seen)
81 for (const pr of prs) place(pr, 0, seen) // anything in a cycle
82 return out
83}
84
85// What is safe to remove: other worktrees and local branches whose work already landed on the base.
86export function tidyPlan(g: Pick<GitInfo, 'branch' | 'base' | 'worktrees' | 'merged' | 'mergedHeads'>) {
87 const landed = new Set([...g.merged, ...g.mergedHeads])
88 const keep = new Set([g.branch, g.base, 'main', 'master', 'develop'])
89 const worktrees = g.worktrees.filter(w => !w.isMain && w.branch && !keep.has(w.branch) && landed.has(w.branch))
90 const inWorktree = new Set(worktrees.map(w => w.branch))
91 const branches = g.merged.filter(b => !keep.has(b) && !inWorktree.has(b))
92 return { worktrees, branches }
93}
94
95export const repoName = (root: string) => root.replace(/\/\.claude\/worktrees\/[^/]+$/, '').split('/').pop() ?? root
96
97// "3 hours ago" -> "3h", "2 months ago" -> "2mo".
98const UNITS: Record<string, string> = { second: 's', minute: 'm', hour: 'h', day: 'd', week: 'w', month: 'mo', year: 'y' }
99const short = (ago: string) => ago.replace(/^(\d+) (\w+?)s? ago$/, (_, n: string, u: string) => `${n}${UNITS[u] ?? u}`)
100
101// `git log --pretty=format:%h%x1f%s%x1f%ar%x1f%D`: one commit a line, its refs after the time.
102export function parseLog(text: string): GitCommit[] {
103 return text
104 .split('\n')
105 .filter(Boolean)
106 .map(line => {
107 const [hash = '', subject = '', when = '', refs = ''] = line.split('\x1f')
108 return { hash, subject, when: short(when), refs: refs.split(', ').map(r => r.replace('HEAD -> ', '')).filter(Boolean) }
109 })
110}
111
112// The letter VS Code shows for a file: its index column, else its working-tree column; ?? is U.
113export const statusLetter = (f: GitFile) => (f.x === '?' ? 'U' : f.x !== ' ' ? f.x : f.y)
114types/index.d.ts 50 lines1export type NextTask = string | null
2export type Quick = { label: string; prompt: string }
3
4export type Worktree = { path: string; branch: string | null; isMain: boolean }
5export type Pr = {
6 number: number
7 title: string
8 head: string
9 base: string
10 isDraft: boolean
11 checks: 'pass' | 'fail' | 'pending' | 'none'
12}
13export type GitFile = { x: string; y: string; path: string }
14export type GitCommit = { hash: string; subject: string; when: string; refs: string[] }
15export type GitInfo = {
16 root: string
17 branch: string
18 base: string
19 ahead: number
20 behind: number
21 hasUpstream: boolean
22 staged: number
23 changed: number
24 untracked: number
25 files: GitFile[]
26 log: GitCommit[]
27 worktrees: Worktree[]
28 merged: string[] // local branches already merged into the base
29 prs: Pr[] | null // null: gh is missing or not signed in
30 mergedHeads: string[] // heads of my recently merged PRs
31 at: number
32 ghAt: number
33 error: string | null
34}
35
36declare module 'claude-code' {
37 interface PluginState {
38 'cockpit': {
39 lastAt: number | null
40 tick: number
41 next: NextTask
42 tasks: string[]
43 router: boolean | null
44 quick: Quick[]
45 git: GitInfo | null
46 gitOpen: Record<string, boolean>
47 }
48 }
49}
50