modboard 0.0.0-stage → 0.5.1
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/.claude-plugin/plugin.json +50 -0
- package/CHANGELOG.md +123 -0
- package/LICENSE +21 -0
- package/README.md +549 -2
- package/bin/board.mjs +157 -0
- package/examples/store-memory.mjs +34 -0
- package/hooks/blocks/agents.tsx +8 -0
- package/hooks/blocks/attention.ts +14 -0
- package/hooks/blocks/clock.tsx +10 -0
- package/hooks/blocks/command.tsx +58 -0
- package/hooks/blocks/context.tsx +18 -0
- package/hooks/blocks/effort.tsx +30 -0
- package/hooks/blocks/index.ts +18 -0
- package/hooks/blocks/model.tsx +37 -0
- package/hooks/blocks/summary.tsx +46 -0
- package/hooks/blocks/tasks.tsx +77 -0
- package/hooks/blocks/types.tsx +38 -0
- package/hooks/blocks/usage.tsx +68 -0
- package/hooks/hooks.json +1 -0
- package/hooks/register.tsx +356 -0
- package/lib/contract.mjs +61 -0
- package/lib/engine.mjs +217 -0
- package/lib/load-store.mjs +66 -0
- package/lib/store-file.mjs +118 -0
- package/package.json +22 -4
- package/tsconfig.json +3 -0
- package/types/index.d.ts +23 -0
package/bin/board.mjs
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// board — an agent-neutral task board. Any agent (Claude, Codex, a human)
|
|
3
|
+
// coordinates through this one CLI; nothing else writes the board.
|
|
4
|
+
//
|
|
5
|
+
// The board lives in <repo>/.modboard/, beside the git *common* dir so
|
|
6
|
+
// every worktree of a repo shares one board (BOARD_DIR overrides). A board
|
|
7
|
+
// made before the rename, in .agent-board/, is used where it already exists.
|
|
8
|
+
// Which storage block holds it is named in .modboard/config.json (see
|
|
9
|
+
// lib/load-store.mjs); the default is the built-in "file" block.
|
|
10
|
+
|
|
11
|
+
import { execFileSync } from 'node:child_process'
|
|
12
|
+
import fs from 'node:fs'
|
|
13
|
+
import path from 'node:path'
|
|
14
|
+
|
|
15
|
+
import { BoardError, createEngine } from '../lib/engine.mjs'
|
|
16
|
+
import { loadStore } from '../lib/load-store.mjs'
|
|
17
|
+
|
|
18
|
+
function boardDir() {
|
|
19
|
+
if (process.env.BOARD_DIR) return path.resolve(process.env.BOARD_DIR)
|
|
20
|
+
try {
|
|
21
|
+
const common = execFileSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], {
|
|
22
|
+
encoding: 'utf8',
|
|
23
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
24
|
+
}).trim()
|
|
25
|
+
return inside(path.dirname(common))
|
|
26
|
+
} catch {
|
|
27
|
+
return inside(process.cwd())
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function inside(root) {
|
|
32
|
+
const old = path.join(root, '.agent-board')
|
|
33
|
+
const now = path.join(root, '.modboard')
|
|
34
|
+
return !fs.existsSync(now) && fs.existsSync(old) ? old : now
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parseArgs(argv) {
|
|
38
|
+
const pos = []
|
|
39
|
+
const flags = {}
|
|
40
|
+
for (let i = 0; i < argv.length; i++) {
|
|
41
|
+
const a = argv[i]
|
|
42
|
+
if (a.startsWith('--')) {
|
|
43
|
+
const val = argv[i + 1] !== undefined && !argv[i + 1].startsWith('--') ? argv[++i] : true
|
|
44
|
+
flags[a.slice(2)] = val
|
|
45
|
+
} else pos.push(a)
|
|
46
|
+
}
|
|
47
|
+
return { pos, flags }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const text = v => (typeof v === 'string' ? v : undefined)
|
|
51
|
+
|
|
52
|
+
function actorOf(flags) {
|
|
53
|
+
const a = text(flags.as) ?? process.env.BOARD_AGENT
|
|
54
|
+
if (!a) throw new BoardError(2, 'who are you? pass --as <agent> or set BOARD_AGENT')
|
|
55
|
+
return a
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const SYMBOL = { todo: '○', claimed: '◐', done: '●' }
|
|
59
|
+
const line = t => `${SYMBOL[t.status]} ${t.id} ${t.title}${t.claim ? ` ${t.claim.owner}` : ''}`
|
|
60
|
+
|
|
61
|
+
function describe(t) {
|
|
62
|
+
const out = [line(t), '']
|
|
63
|
+
if (t.description) out.push(t.description, '')
|
|
64
|
+
if (t.accept) out.push(`Accept when: ${t.accept}`, '')
|
|
65
|
+
if (t.claim) out.push(`claimed by ${t.claim.owner} until ${t.claim.expiresAt}`)
|
|
66
|
+
for (const n of t.notes) out.push(`- [${n.at.slice(0, 16)}] ${n.by}: ${n.text}`)
|
|
67
|
+
return out.join('\n')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const DIR = boardDir()
|
|
71
|
+
|
|
72
|
+
// Local clock time, for people: "19:45".
|
|
73
|
+
const hhmm = iso => new Date(iso).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
|
74
|
+
const ids = list => (list.length ? list.join(', ') : 'nothing')
|
|
75
|
+
|
|
76
|
+
// What each command says to a person. --json prints the data instead, and
|
|
77
|
+
// view and events (for programs) always do.
|
|
78
|
+
const SAY = {
|
|
79
|
+
add: t => `added ${line(t)}`,
|
|
80
|
+
claim: t => `claimed ${t.id} ${t.title}\nit's yours until ${hhmm(t.claim.expiresAt)}; a note or heartbeat renews it`,
|
|
81
|
+
heartbeat: r => `renewed ${ids(r.renewed)}`,
|
|
82
|
+
note: t => `noted on ${t.id}; yours until ${hhmm(t.claim.expiresAt)}`,
|
|
83
|
+
release: t => `released ${t.id}${t.notes.at(-1)?.text.startsWith('HANDOFF:') ? ' with a handoff' : ''}; it's back to todo`,
|
|
84
|
+
done: t => `done ${line(t)}\n${t.notes.at(-1).text}`,
|
|
85
|
+
'release-all': r => `released ${ids(r.released)}`,
|
|
86
|
+
register: r => `you are ${r.name}`,
|
|
87
|
+
agents: list => (list.length ? list.map(a => `${a.name} last seen ${hhmm(a.lastSeen)}`).join('\n') : '(no live agents)'),
|
|
88
|
+
doctor: r =>
|
|
89
|
+
[`storage block: ${r.block}`, ...(r.tasks !== undefined ? [`${r.tasks} ${r.tasks === 1 ? 'task' : 'tasks'}, ${r.events ?? '?'} events`] : []), r.ok ? 'ok: the ledger and the state agree' : 'problems:', ...r.problems.map(p => `- ${p}`)].join('\n'),
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const commands = {
|
|
93
|
+
async list(board, _, flags) {
|
|
94
|
+
const tasks = await board.list({ all: !!flags.all })
|
|
95
|
+
if (flags.json) return tasks
|
|
96
|
+
return tasks.length ? tasks.map(line).join('\n') : '(no open tasks)'
|
|
97
|
+
},
|
|
98
|
+
async show(board, [id], flags) {
|
|
99
|
+
const t = await board.show(id)
|
|
100
|
+
return flags.json ? t : describe(t)
|
|
101
|
+
},
|
|
102
|
+
add(board, [title], flags) {
|
|
103
|
+
if (!title) throw new BoardError(2, 'usage: board add "<title>" [--desc "..."] [--accept "how to tell it is done"]')
|
|
104
|
+
return board.add(text(flags.as) ?? process.env.BOARD_AGENT ?? 'human', {
|
|
105
|
+
title,
|
|
106
|
+
description: text(flags.desc),
|
|
107
|
+
accept: text(flags.accept),
|
|
108
|
+
})
|
|
109
|
+
},
|
|
110
|
+
claim: (board, [id], flags) => board.claim(id, actorOf(flags)),
|
|
111
|
+
heartbeat: (board, _, flags) => board.heartbeat(actorOf(flags)),
|
|
112
|
+
note(board, [id, note], flags) {
|
|
113
|
+
if (!note) throw new BoardError(2, 'usage: board note <id> "<text>"')
|
|
114
|
+
return board.note(id, actorOf(flags), note)
|
|
115
|
+
},
|
|
116
|
+
release: (board, [id], flags) => board.release(id, actorOf(flags), text(flags.handoff)),
|
|
117
|
+
done: (board, [id], flags) => board.done(id, actorOf(flags), text(flags.note)),
|
|
118
|
+
'release-all': (board, _, flags) => board.releaseAll(actorOf(flags), { handoff: text(flags.handoff), session: text(flags.session) }),
|
|
119
|
+
register(board, [name], flags) {
|
|
120
|
+
const session = text(flags.session)
|
|
121
|
+
if (!name || !session) throw new BoardError(2, 'usage: board register <name> --session <id>')
|
|
122
|
+
return board.register(name, session)
|
|
123
|
+
},
|
|
124
|
+
agents: board => board.agents(),
|
|
125
|
+
// Everything a display needs, in one call: every task and the live agents.
|
|
126
|
+
view: async board => ({ tasks: await board.list({ all: true }), agents: await board.agents() }),
|
|
127
|
+
events: (board, [since]) => board.events(Number(since ?? 0)),
|
|
128
|
+
doctor: async (board, _, __, store) => ({ block: store, ...(await board.doctor()) }),
|
|
129
|
+
where: () => DIR,
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function main() {
|
|
133
|
+
const [cmd, ...rest] = process.argv.slice(2)
|
|
134
|
+
const { pos, flags } = parseArgs(rest)
|
|
135
|
+
const run = commands[cmd]
|
|
136
|
+
if (!run) {
|
|
137
|
+
console.error(`usage: board <${Object.keys(commands).join('|')}> ... (--json for machine output)`)
|
|
138
|
+
process.exit(2)
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const { store, name } = await loadStore(DIR)
|
|
142
|
+
const board = createEngine(store, {
|
|
143
|
+
leaseMs: Number(process.env.BOARD_LEASE_MS ?? 15 * 60 * 1000),
|
|
144
|
+
presenceMs: Number(process.env.BOARD_PRESENCE_MS ?? 3 * 60 * 1000),
|
|
145
|
+
})
|
|
146
|
+
const out = await run(board, pos, flags, name)
|
|
147
|
+
const say = !flags.json && SAY[cmd]
|
|
148
|
+
console.log(say ? say(out) : flags.json || typeof out !== 'string' ? JSON.stringify(out, null, 2) : out)
|
|
149
|
+
} catch (err) {
|
|
150
|
+
if (!(err instanceof BoardError)) throw err
|
|
151
|
+
if (flags.json) console.log(JSON.stringify({ error: err.message, code: err.code }))
|
|
152
|
+
else console.error(`board: ${err.message}`)
|
|
153
|
+
process.exit(err.code)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
main()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// A storage block in one small file: the reference for writing your own.
|
|
2
|
+
//
|
|
3
|
+
// It keeps the board in memory, so it lasts only as long as one process and
|
|
4
|
+
// is useful for tests, not for a real board. A real block (a database, a
|
|
5
|
+
// server) has the same five methods; the hard one is commit, which must apply
|
|
6
|
+
// all of its writes or none, and only where every version still matches.
|
|
7
|
+
//
|
|
8
|
+
// Check a block with the contract suite:
|
|
9
|
+
// import { storeContract } from 'modboard/lib/contract.mjs'
|
|
10
|
+
// storeContract('my block', () => createStore(config, { dir }))
|
|
11
|
+
|
|
12
|
+
export const createStore = () => memoryStore()
|
|
13
|
+
|
|
14
|
+
export function memoryStore() {
|
|
15
|
+
const state = { tasks: {}, agents: {} }
|
|
16
|
+
const ledger = []
|
|
17
|
+
return {
|
|
18
|
+
now: () => Date.now(),
|
|
19
|
+
snapshot: async () => structuredClone(state),
|
|
20
|
+
commit: async ({ writes, events }) => {
|
|
21
|
+
const table = kind => (kind === 'task' ? state.tasks : state.agents)
|
|
22
|
+
for (const w of writes) if ((table(w.kind)[w.key]?.version ?? 0) !== w.expect) return { ok: false, conflict: w.key }
|
|
23
|
+
for (const w of writes) {
|
|
24
|
+
if (w.value === null) delete table(w.kind)[w.key]
|
|
25
|
+
else table(w.kind)[w.key] = { ...structuredClone(w.value), version: w.expect + 1 }
|
|
26
|
+
}
|
|
27
|
+
for (const e of events) ledger.push({ seq: ledger.length + 1, at: new Date().toISOString(), ...e })
|
|
28
|
+
return { ok: true }
|
|
29
|
+
},
|
|
30
|
+
events: async (since = 0) => ledger.filter(e => e.seq > since),
|
|
31
|
+
verify: async () => ({ ok: true, problems: [] }),
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Block } from './types'
|
|
2
|
+
|
|
3
|
+
// Who is live on the board. Off by default: each task row already names its owner.
|
|
4
|
+
export const agents: Block = {
|
|
5
|
+
name: 'agents',
|
|
6
|
+
pane: ({ ui: { Text }, agents: list, who }) =>
|
|
7
|
+
list.length ? <Text dimColor>{`live: ${list.map(a => (a.name === who ? `${a.name} (you)` : a.name)).join(', ')}`}</Text> : null,
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Task } from '../../types'
|
|
2
|
+
|
|
3
|
+
const QUIET_MS = 5 * 60 * 1000
|
|
4
|
+
|
|
5
|
+
// A task someone released with a handoff, that nobody has picked up yet.
|
|
6
|
+
export const handoffWaiting = (t: Task) => t.status === 'todo' && (t.notes.at(-1)?.text.startsWith('HANDOFF:') ?? false)
|
|
7
|
+
|
|
8
|
+
// The last agent to hand a task off, read from its handoff note.
|
|
9
|
+
export const handedOffBy = (t: Task) => t.notes.at(-1)?.by ?? ''
|
|
10
|
+
|
|
11
|
+
// A claim whose lease is nearly out: its agent has stopped working, or stopped
|
|
12
|
+
// renewing, for most of a lease.
|
|
13
|
+
export const goingQuiet = (t: Task, now: number) =>
|
|
14
|
+
t.status === 'claimed' && t.claim !== null && Date.parse(t.claim.expiresAt) - now < QUIET_MS
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { words, type Block } from './types'
|
|
2
|
+
|
|
3
|
+
const pad = (n: number) => String(n).padStart(2, '0')
|
|
4
|
+
const hhmm = (now: number) => `${pad(new Date(now).getHours())}:${pad(new Date(now).getMinutes())}`
|
|
5
|
+
|
|
6
|
+
export const clock: Block = {
|
|
7
|
+
name: 'clock',
|
|
8
|
+
band: ({ ui: { Text }, now }) => [words(Text, hhmm(now), { dimColor: true })],
|
|
9
|
+
pane: ({ ui: { Text }, now }) => <Text bold>{hhmm(now)}</Text>,
|
|
10
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Block } from './types'
|
|
2
|
+
import { words } from './types'
|
|
3
|
+
|
|
4
|
+
// A block of your own, with no code: the `blocks` setting names it and the
|
|
5
|
+
// shell command whose first line of output it shows, as JSON,
|
|
6
|
+
// {"ci": "gh run list -L1 --json conclusion -q '.[0].conclusion'"}
|
|
7
|
+
// The name then goes in `band` or `pane` like any built-in block. The setting
|
|
8
|
+
// is yours (user config), never the project's, so cloning a repo cannot make
|
|
9
|
+
// your session run its commands.
|
|
10
|
+
export function commandBlock(name: string): Block {
|
|
11
|
+
return {
|
|
12
|
+
name,
|
|
13
|
+
band: ({ ui: { Text }, custom }) => {
|
|
14
|
+
const text = custom[name]
|
|
15
|
+
if (!text) return null
|
|
16
|
+
return [words(Text, `${name} ${text}`, { dimColor: true }), words(Text, text, { dimColor: true })]
|
|
17
|
+
},
|
|
18
|
+
pane: ({ ui: { Box, Text }, custom }) => {
|
|
19
|
+
const text = custom[name]
|
|
20
|
+
if (!text) return null
|
|
21
|
+
return (
|
|
22
|
+
<Box>
|
|
23
|
+
<Box width={8}>
|
|
24
|
+
<Text dimColor>{name}</Text>
|
|
25
|
+
</Box>
|
|
26
|
+
<Text wrap="truncate">{text}</Text>
|
|
27
|
+
</Box>
|
|
28
|
+
)
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const NAME = /^[a-z][a-z0-9-]{0,15}$/
|
|
34
|
+
|
|
35
|
+
// The `blocks` setting, read: name → command. What it cannot use is left out
|
|
36
|
+
// and said in `problems`, so a typo is reported and not silently dropped.
|
|
37
|
+
export function parseCommandBlocks(setting: unknown, taken: string[]): { commands: Record<string, string>; problems: string[] } {
|
|
38
|
+
const commands: Record<string, string> = {}
|
|
39
|
+
const problems: string[] = []
|
|
40
|
+
if (setting === undefined || setting === null || String(setting).trim() === '') return { commands, problems }
|
|
41
|
+
let parsed: unknown
|
|
42
|
+
try {
|
|
43
|
+
parsed = JSON.parse(String(setting))
|
|
44
|
+
} catch {
|
|
45
|
+
return { commands, problems: ['the blocks setting is not JSON; write it as {"name": "command"}'] }
|
|
46
|
+
}
|
|
47
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return { commands, problems: ['the blocks setting must be a JSON object'] }
|
|
48
|
+
for (const [name, command] of Object.entries(parsed)) {
|
|
49
|
+
if (!NAME.test(name)) problems.push(`block name "${name}": use lowercase letters, digits and -, up to 16`)
|
|
50
|
+
else if (taken.includes(name)) problems.push(`block name "${name}" is a built-in block`)
|
|
51
|
+
else if (typeof command !== 'string' || !command.trim()) problems.push(`block "${name}" needs a command`)
|
|
52
|
+
else commands[name] = command
|
|
53
|
+
}
|
|
54
|
+
return { commands, problems }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// A command's output as one short line: its first non-empty line, cut to fit.
|
|
58
|
+
export const firstLine = (out: string) => (out.split('\n').map(l => l.trim()).find(Boolean) ?? '').slice(0, 60)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { words, type Block } from './types'
|
|
2
|
+
|
|
3
|
+
// The context window's fill and what the session has cost. Off by default:
|
|
4
|
+
// Claude Code shows the context already.
|
|
5
|
+
export const context: Block = {
|
|
6
|
+
name: 'context',
|
|
7
|
+
band: ({ ui: { Text }, usage: u }) =>
|
|
8
|
+
u.context === undefined
|
|
9
|
+
? null
|
|
10
|
+
: [words(Text, `context ${Math.round(u.context)}%`, { dimColor: true }), words(Text, `ctx ${Math.round(u.context)}%`, { dimColor: true })],
|
|
11
|
+
pane: ({ ui: { Text }, usage: u }) => {
|
|
12
|
+
const parts = [
|
|
13
|
+
u.context !== undefined && `context ${Math.round(u.context)}% full`,
|
|
14
|
+
u.costUsd !== undefined && `cost $${u.costUsd.toFixed(2)}`,
|
|
15
|
+
].filter(Boolean)
|
|
16
|
+
return parts.length ? <Text dimColor>{parts.join(' · ')}</Text> : null
|
|
17
|
+
},
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Block } from './types'
|
|
2
|
+
|
|
3
|
+
// How hard the model thinks. Pressing it switches to the next level in the
|
|
4
|
+
// `efforts` setting, through Claude Code's own /effort.
|
|
5
|
+
export const effort: Block = {
|
|
6
|
+
name: 'effort',
|
|
7
|
+
band: ({ ui: { Button, Text }, effort: level, act }) => {
|
|
8
|
+
const shown = level || '–'
|
|
9
|
+
const press = (label: string, children: any) => ({
|
|
10
|
+
tree: (
|
|
11
|
+
<Button key="effort" plain onPress={act.nextEffort}>
|
|
12
|
+
{children}
|
|
13
|
+
</Button>
|
|
14
|
+
),
|
|
15
|
+
width: label.length,
|
|
16
|
+
})
|
|
17
|
+
return [
|
|
18
|
+
press(`effort ${shown}`, [<Text dimColor>effort </Text>, <Text bold>{shown}</Text>]),
|
|
19
|
+
press(shown, <Text bold>{shown}</Text>),
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
pane: ({ ui: { Box, Button, Text }, effort: level, act }) => (
|
|
23
|
+
<Box>
|
|
24
|
+
<Box width={8}>
|
|
25
|
+
<Text dimColor>effort</Text>
|
|
26
|
+
</Box>
|
|
27
|
+
<Button key="effort" hotkey="e" label={level || '–'} onPress={act.nextEffort} />
|
|
28
|
+
</Box>
|
|
29
|
+
),
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// The board's display blocks. To add one: write it as its own file beside
|
|
2
|
+
// these (see types.tsx for the shape), import it here, and add it to the list.
|
|
3
|
+
// It can then be named in the `band` or `pane` setting. Blocks that only show a
|
|
4
|
+
// command's output need no code: see command.tsx and the `blocks` setting.
|
|
5
|
+
|
|
6
|
+
import { agents } from './agents'
|
|
7
|
+
import { clock } from './clock'
|
|
8
|
+
import { context } from './context'
|
|
9
|
+
import { effort } from './effort'
|
|
10
|
+
import { model } from './model'
|
|
11
|
+
import { summary } from './summary'
|
|
12
|
+
import { tasks } from './tasks'
|
|
13
|
+
import { usage } from './usage'
|
|
14
|
+
import type { Block } from './types'
|
|
15
|
+
|
|
16
|
+
export const BLOCKS: Block[] = [summary, tasks, usage, model, effort, clock, context, agents]
|
|
17
|
+
|
|
18
|
+
export type { BandForm, Block, Ctx } from './types'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Block } from './types'
|
|
2
|
+
|
|
3
|
+
// "claude-sonnet-5-5" → "Sonnet 5.5"; anything else as the session names it.
|
|
4
|
+
export const modelName = (id: string) => {
|
|
5
|
+
const m = /(opus|sonnet|haiku|fable)[-\s]?(\d+)(?:[-.](\d+))?/i.exec(id)
|
|
6
|
+
if (!m) return id || 'model'
|
|
7
|
+
return `${m[1]![0]!.toUpperCase()}${m[1]!.slice(1).toLowerCase()} ${m[2]}${m[3] ? `.${m[3]}` : ''}`
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// The session's model. Pressing it switches to the next model in the `models`
|
|
11
|
+
// setting, through Claude Code's own /model, as if you had typed it.
|
|
12
|
+
export const model: Block = {
|
|
13
|
+
name: 'model',
|
|
14
|
+
band: ({ ui: { Button, Text }, model: id, act }) => {
|
|
15
|
+
const name = modelName(id)
|
|
16
|
+
const press = (label: string, children: any) => ({
|
|
17
|
+
tree: (
|
|
18
|
+
<Button key="model" plain onPress={act.nextModel}>
|
|
19
|
+
{children}
|
|
20
|
+
</Button>
|
|
21
|
+
),
|
|
22
|
+
width: label.length,
|
|
23
|
+
})
|
|
24
|
+
return [
|
|
25
|
+
press(`model ${name}`, [<Text dimColor>model </Text>, <Text bold>{name}</Text>]),
|
|
26
|
+
press(name, <Text bold>{name}</Text>),
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
pane: ({ ui: { Box, Button, Text }, model: id, act }) => (
|
|
30
|
+
<Box>
|
|
31
|
+
<Box width={8}>
|
|
32
|
+
<Text dimColor>model</Text>
|
|
33
|
+
</Box>
|
|
34
|
+
<Button key="model" hotkey="m" label={modelName(id)} onPress={act.nextModel} />
|
|
35
|
+
</Box>
|
|
36
|
+
),
|
|
37
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Block } from './types'
|
|
2
|
+
import { goingQuiet, handoffWaiting } from './attention'
|
|
3
|
+
|
|
4
|
+
const tasksWord = (n: number) => `${n} ${n === 1 ? 'task' : 'tasks'}`
|
|
5
|
+
|
|
6
|
+
// The band's main line: how much is waiting and in progress, and the one thing
|
|
7
|
+
// that needs you. Plain words: the reader need not know the board's terms.
|
|
8
|
+
export const summary: Block = {
|
|
9
|
+
name: 'summary',
|
|
10
|
+
band: ({ ui: { Box, Text }, tasks, now }) => {
|
|
11
|
+
const working = tasks.filter(t => t.status === 'claimed').length
|
|
12
|
+
const open = tasks.filter(t => t.status === 'todo').length
|
|
13
|
+
if (!working && !open) return null
|
|
14
|
+
const waiting = tasks.filter(handoffWaiting)
|
|
15
|
+
const quiet = tasks.filter(t => goingQuiet(t, now))
|
|
16
|
+
const counts = [open && `${tasksWord(open)} waiting`, working && `${working} in progress`].filter(Boolean).join(' · ')
|
|
17
|
+
const short = [open && `${open} waiting`, working && `${working} active`].filter(Boolean).join(' · ')
|
|
18
|
+
const alert = waiting.length
|
|
19
|
+
? `${waiting[0]!.id} was stopped partway, pick it up${waiting.length > 1 ? ` (+${waiting.length - 1} more)` : ''}`
|
|
20
|
+
: quiet.length
|
|
21
|
+
? `${quiet[0]!.id}: ${quiet[0]!.claim!.owner} stopped responding`
|
|
22
|
+
: ''
|
|
23
|
+
const shortAlert = waiting.length ? `${waiting[0]!.id} needs you` : quiet.length ? `${quiet[0]!.id} stopped` : ''
|
|
24
|
+
// The alert outlasts the counts: it is the one thing that needs you.
|
|
25
|
+
const form = (left: string, right: string) => ({
|
|
26
|
+
tree: (
|
|
27
|
+
<Box gap={3}>
|
|
28
|
+
{left ? (
|
|
29
|
+
<Text dimColor wrap="truncate">
|
|
30
|
+
{left}
|
|
31
|
+
</Text>
|
|
32
|
+
) : null}
|
|
33
|
+
{right ? (
|
|
34
|
+
<Text color="warning" wrap="truncate">
|
|
35
|
+
{right}
|
|
36
|
+
</Text>
|
|
37
|
+
) : null}
|
|
38
|
+
</Box>
|
|
39
|
+
),
|
|
40
|
+
width: left.length + right.length + (left && right ? 3 : 0),
|
|
41
|
+
})
|
|
42
|
+
return alert
|
|
43
|
+
? [form(counts, alert), form(short, alert), form(short, shortAlert), form('', shortAlert)]
|
|
44
|
+
: [form(counts, ''), form(short, '')]
|
|
45
|
+
},
|
|
46
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Task } from '../../types'
|
|
2
|
+
import type { Block, Ctx } from './types'
|
|
3
|
+
import { goingQuiet, handedOffBy, handoffWaiting } from './attention'
|
|
4
|
+
|
|
5
|
+
// What a row says about who has the task, as a sentence: a bare name could mean
|
|
6
|
+
// whoever made it, holds it or dropped it. Warnings are what needs you.
|
|
7
|
+
function status(t: Task, { now, who, width }: Ctx): { text: string; warn: boolean } {
|
|
8
|
+
if (t.claim) {
|
|
9
|
+
const name = t.claim.owner === who ? 'you' : t.claim.owner
|
|
10
|
+
if (goingQuiet(t, now)) return { text: `${name} stopped responding`, warn: true }
|
|
11
|
+
if (width < 64) return { text: name, warn: false }
|
|
12
|
+
return { text: name === 'you' ? "you're on it" : `${name} is on it`, warn: false }
|
|
13
|
+
}
|
|
14
|
+
if (handoffWaiting(t)) return { text: `${handedOffBy(t)} stopped partway${width < 64 ? '' : ' · see its note'}`, warn: true }
|
|
15
|
+
return { text: '', warn: false }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function Row(c: Ctx, t: Task) {
|
|
19
|
+
const { Box, Text } = c.ui
|
|
20
|
+
const isMine = t.claim?.owner === c.who
|
|
21
|
+
const { text, warn } = status(t, c)
|
|
22
|
+
return (
|
|
23
|
+
<Box>
|
|
24
|
+
<Box width={3}>
|
|
25
|
+
<Text color={t.status === 'claimed' ? 'claude' : undefined} dimColor={t.status === 'todo'}>
|
|
26
|
+
{t.status === 'claimed' ? '◐' : '○'}
|
|
27
|
+
</Text>
|
|
28
|
+
</Box>
|
|
29
|
+
<Box width={7}>
|
|
30
|
+
<Text dimColor>{t.id}</Text>
|
|
31
|
+
</Box>
|
|
32
|
+
<Box flexGrow={1} flexShrink={1}>
|
|
33
|
+
<Text bold={isMine} wrap="truncate">
|
|
34
|
+
{t.title}
|
|
35
|
+
</Text>
|
|
36
|
+
</Box>
|
|
37
|
+
{text && (
|
|
38
|
+
<Box marginLeft={2} flexShrink={0}>
|
|
39
|
+
<Text color={warn ? 'warning' : undefined} dimColor={!warn}>
|
|
40
|
+
{text}
|
|
41
|
+
</Text>
|
|
42
|
+
</Box>
|
|
43
|
+
)}
|
|
44
|
+
</Box>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function Group(c: Ctx, title: string, list: Task[]) {
|
|
49
|
+
const { Box, Text } = c.ui
|
|
50
|
+
if (!list.length) return null
|
|
51
|
+
return (
|
|
52
|
+
<Box flexDirection="column">
|
|
53
|
+
<Text bold>{title}</Text>
|
|
54
|
+
{list.map(t => Row(c, t))}
|
|
55
|
+
</Box>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// In progress first; then work someone stopped partway, which needs picking
|
|
60
|
+
// up; then what nobody has started. Done tasks become a count.
|
|
61
|
+
export const tasks: Block = {
|
|
62
|
+
name: 'tasks',
|
|
63
|
+
pane: c => {
|
|
64
|
+
const { Box, Text } = c.ui
|
|
65
|
+
if (!c.tasks.length) return <Text dimColor>No tasks yet. Ask Claude to add some, or run `board add`.</Text>
|
|
66
|
+
const todo = c.tasks.filter(t => t.status === 'todo')
|
|
67
|
+
const done = c.tasks.filter(t => t.status === 'done').length
|
|
68
|
+
return (
|
|
69
|
+
<Box flexDirection="column" gap={1}>
|
|
70
|
+
{Group(c, 'In progress', c.tasks.filter(t => t.status === 'claimed'))}
|
|
71
|
+
{Group(c, 'Needs picking up', todo.filter(handoffWaiting))}
|
|
72
|
+
{Group(c, 'Not started', todo.filter(t => !handoffWaiting(t)))}
|
|
73
|
+
{done > 0 && <Text dimColor>{`${done} done`}</Text>}
|
|
74
|
+
</Box>
|
|
75
|
+
)
|
|
76
|
+
},
|
|
77
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Agent, Task, Usage } from '../../types'
|
|
2
|
+
|
|
3
|
+
// What every block draws from. `ui` is the surface's own element table.
|
|
4
|
+
export type Ctx = {
|
|
5
|
+
ui: { Box: any; Text: any; Button: any }
|
|
6
|
+
width: number
|
|
7
|
+
now: number
|
|
8
|
+
who: string
|
|
9
|
+
tasks: Task[]
|
|
10
|
+
agents: Agent[]
|
|
11
|
+
usage: Usage
|
|
12
|
+
model: string
|
|
13
|
+
effort: string
|
|
14
|
+
// The last line each command block printed, by block name.
|
|
15
|
+
custom: Record<string, string>
|
|
16
|
+
// What a pressed block can do: each switches the session the way the
|
|
17
|
+
// matching slash command would.
|
|
18
|
+
act: { nextModel: () => Promise<void>; nextEffort: () => Promise<void> }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// One way a block can draw in the band, and how many columns it takes.
|
|
22
|
+
export type BandForm = { tree: any; width: number }
|
|
23
|
+
|
|
24
|
+
// A block is one part of the board's display. It may draw in the band above
|
|
25
|
+
// the prompt, in the /board pane, or both, and returns null when it has
|
|
26
|
+
// nothing worth showing. In the band it offers its forms widest first; the
|
|
27
|
+
// band never wraps, so when the line is short it takes a narrower form, and
|
|
28
|
+
// past the narrowest it leaves the block out.
|
|
29
|
+
export type Block = {
|
|
30
|
+
name: string
|
|
31
|
+
band?: (c: Ctx) => BandForm[] | null
|
|
32
|
+
pane?: (c: Ctx) => any
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// A run of text that never wraps, and its width.
|
|
36
|
+
export function words(Text: any, text: string, props: Record<string, unknown> = {}): BandForm {
|
|
37
|
+
return { tree: <Text {...props} wrap="truncate">{text}</Text>, width: [...text].length }
|
|
38
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Block, Ctx } from './types'
|
|
2
|
+
|
|
3
|
+
const LABEL: Record<string, string> = { five_hour: '5-hour limit', seven_day: 'weekly limit', spend_limit: 'spend limit' }
|
|
4
|
+
const SHORT: Record<string, string> = { five_hour: '5h', seven_day: '7d', spend_limit: 'spend' }
|
|
5
|
+
const label = (kind: string) => LABEL[kind] ?? kind
|
|
6
|
+
const CELLS = 10
|
|
7
|
+
const filled = (percent: number, cells = CELLS) => Math.min(cells, Math.round((percent / 100) * cells))
|
|
8
|
+
// Green while there is room, yellow from 70%, red from 90%: theme colours, so
|
|
9
|
+
// they follow the person's terminal theme.
|
|
10
|
+
const tone = (percent: number) => (percent >= 90 ? 'error' : percent >= 70 ? 'warning' : 'success')
|
|
11
|
+
|
|
12
|
+
// The bar's used part in the window's colour, the rest dim, then the percent.
|
|
13
|
+
function Meter({ Box, Text }: Ctx['ui'], percent: number, cells = CELLS) {
|
|
14
|
+
return (
|
|
15
|
+
<Box flexShrink={0}>
|
|
16
|
+
<Text color={tone(percent)}>{'▓'.repeat(filled(percent, cells))}</Text>
|
|
17
|
+
<Text dimColor>{'░'.repeat(cells - filled(percent, cells))}</Text>
|
|
18
|
+
<Text color={tone(percent)}>{` ${String(Math.round(percent)).padStart(3)}%`}</Text>
|
|
19
|
+
</Box>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
const pad = (n: number) => String(n).padStart(2, '0')
|
|
23
|
+
const when = (iso: string, now: number) => {
|
|
24
|
+
const d = new Date(iso)
|
|
25
|
+
const time = `${pad(d.getHours())}:${pad(d.getMinutes())}`
|
|
26
|
+
const days = Math.floor((d.getTime() - now) / 86_400_000)
|
|
27
|
+
return days >= 1 ? `in ${days}d` : time
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// This session's plan usage. In the band only once a window passes half, since
|
|
31
|
+
// below that it is noise; in the pane, every window with its reset.
|
|
32
|
+
export const usage: Block = {
|
|
33
|
+
name: 'usage',
|
|
34
|
+
band: ({ ui, usage: u }) => {
|
|
35
|
+
const top = [...u.limits].sort((a, b) => b.percentUsed - a.percentUsed)[0]
|
|
36
|
+
if (!top || top.percentUsed < 50) return null
|
|
37
|
+
const form = (name: string, cells: number) => ({
|
|
38
|
+
tree: (
|
|
39
|
+
<ui.Box gap={1}>
|
|
40
|
+
<ui.Text dimColor wrap="truncate">
|
|
41
|
+
{name}
|
|
42
|
+
</ui.Text>
|
|
43
|
+
{Meter(ui, top.percentUsed, cells)}
|
|
44
|
+
</ui.Box>
|
|
45
|
+
),
|
|
46
|
+
width: name.length + 1 + cells + 5,
|
|
47
|
+
})
|
|
48
|
+
return [form(label(top.kind), CELLS), form(SHORT[top.kind] ?? label(top.kind), 5)]
|
|
49
|
+
},
|
|
50
|
+
pane: ({ ui, usage: u, now }) => {
|
|
51
|
+
const { Box, Text } = ui
|
|
52
|
+
if (!u.limits.length) return null
|
|
53
|
+
return (
|
|
54
|
+
<Box flexDirection="column">
|
|
55
|
+
<Text bold>Usage</Text>
|
|
56
|
+
{u.limits.map(l => (
|
|
57
|
+
<Box>
|
|
58
|
+
<Box width={15}>
|
|
59
|
+
<Text dimColor>{label(l.kind)}</Text>
|
|
60
|
+
</Box>
|
|
61
|
+
{Meter(ui, l.percentUsed)}
|
|
62
|
+
{l.resetsAt && <Text dimColor>{` resets ${when(l.resetsAt, now)}`}</Text>}
|
|
63
|
+
</Box>
|
|
64
|
+
))}
|
|
65
|
+
</Box>
|
|
66
|
+
)
|
|
67
|
+
},
|
|
68
|
+
}
|
package/hooks/hooks.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "modules": ["./register.tsx"] }
|