modboard 0.5.1 → 0.6.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.
@@ -2,16 +2,21 @@ import type { Task } from '../../types'
2
2
  import type { Block, Ctx } from './types'
3
3
  import { goingQuiet, handedOffBy, handoffWaiting } from './attention'
4
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 } {
5
+ // Who a row is about. The group's heading says what they did ("In progress",
6
+ // "Unfinished"), so the row only names them. Warnings are what needs you:
7
+ // an agent gone quiet, or work left partway.
8
+ function status(t: Task, { now, who }: Ctx): { text: string; warn: boolean } {
9
+ // A done task names who finished it: whoever wrote its verification note.
10
+ if (t.status === 'done') {
11
+ const by = t.notes.at(-1)?.by ?? ''
12
+ return { text: by === who ? 'you' : by, warn: false }
13
+ }
8
14
  if (t.claim) {
9
15
  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 }
16
+ if (goingQuiet(t, now)) return { text: `${name} · idle`, warn: true }
17
+ return { text: name, warn: false }
13
18
  }
14
- if (handoffWaiting(t)) return { text: `${handedOffBy(t)} stopped partway${width < 64 ? '' : ' · see its note'}`, warn: true }
19
+ if (handoffWaiting(t)) return { text: handedOffBy(t), warn: true }
15
20
  return { text: '', warn: false }
16
21
  }
17
22
 
@@ -19,14 +24,14 @@ function Row(c: Ctx, t: Task) {
19
24
  const { Box, Text } = c.ui
20
25
  const isMine = t.claim?.owner === c.who
21
26
  const { text, warn } = status(t, c)
22
- return (
27
+ // Work left partway shows its handoff under the title: what is done and what
28
+ // is left, as the agent wrote it, one point a line where it used semicolons.
29
+ const handoff = handoffWaiting(t) ? t.notes.at(-1)!.text.replace(/^HANDOFF:\s*/, '') : ''
30
+ const points = handoff.split(';').map(p => p.trim()).filter(Boolean)
31
+ // The group's heading already says the task's state; the row needs no mark.
32
+ const row = (
23
33
  <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}>
34
+ <Box width={7} flexShrink={0}>
30
35
  <Text dimColor>{t.id}</Text>
31
36
  </Box>
32
37
  <Box flexGrow={1} flexShrink={1}>
@@ -43,34 +48,120 @@ function Row(c: Ctx, t: Task) {
43
48
  )}
44
49
  </Box>
45
50
  )
51
+ if (!handoff) return row
52
+ return (
53
+ <Box flexDirection="column">
54
+ {row}
55
+ {points.map(p => (
56
+ <Box paddingLeft={7}>
57
+ <Text dimColor wrap="truncate">
58
+ {points.length > 1 ? `· ${p}` : p}
59
+ </Text>
60
+ </Box>
61
+ ))}
62
+ </Box>
63
+ )
46
64
  }
47
65
 
48
- function Group(c: Ctx, title: string, list: Task[]) {
49
- const { Box, Text } = c.ui
66
+ // The groups, each a heading that opens and closes like the task file's.
67
+ // What needs you starts open; what nobody has started, and what is done, start
68
+ // closed, one line with its count, so the pane fits on screen.
69
+ export const GROUPS = {
70
+ 'in-progress': { title: 'In progress', open: true },
71
+ partway: { title: 'Unfinished', open: true },
72
+ 'not-started': { title: 'Not started', open: false },
73
+ done: { title: 'Done', open: false },
74
+ // Not a task group: the pane's bars (context, the 5-hour limit), folded the
75
+ // same way. See register.tsx.
76
+ limits: { title: 'Limits', open: true },
77
+ } as const
78
+ export type GroupName = keyof typeof GROUPS
79
+
80
+ // Whether a group is open: as the person last left it, else its default.
81
+ export const groupOpen = (chosen: Record<string, boolean>, name: GroupName) => chosen[name] ?? GROUPS[name].open
82
+
83
+ // A heading that is a button ("▾ In progress · 2"), then, open, all its rows.
84
+ function Group(c: Ctx, name: GroupName, list: Task[], last = false) {
85
+ const { Box, Button, Text } = c.ui
50
86
  if (!list.length) return null
87
+ const open = groupOpen(c.groupsOpen, name)
51
88
  return (
52
89
  <Box flexDirection="column">
53
- <Text bold>{title}</Text>
54
- {list.map(t => Row(c, t))}
90
+ {/* The name is the button, bold; the count is grey text beside it. */}
91
+ <Box>
92
+ <Button key={`group-${name}`} plain onPress={() => c.act.toggleGroup(name)}>
93
+ <Text bold>{`${open ? '▾' : '▸'} ${GROUPS[name].title}`}</Text>
94
+ </Button>
95
+ <Text dimColor>{` · ${list.length}`}</Text>
96
+ </Box>
97
+ {open && (
98
+ // A blank line under the heading and after the rows, so each group
99
+ // reads as its own block; the last leaves that to what follows the pane.
100
+ <Box flexDirection="column" paddingLeft={2} marginTop={1} marginBottom={last ? 0 : 1}>
101
+ {/* Work left partway carries its handoff, so each task there sits apart. */}
102
+ {list.map((t, i) => (name === 'partway' && i > 0 ? <Box marginTop={1}>{Row(c, t)}</Box> : Row(c, t)))}
103
+ </Box>
104
+ )}
55
105
  </Box>
56
106
  )
57
107
  }
58
108
 
59
109
  // In progress first; then work someone stopped partway, which needs picking
60
- // up; then what nobody has started. Done tasks become a count.
110
+ // up; then what nobody has started; then what is done.
111
+ // What needs you is never cut short.
61
112
  export const tasks: Block = {
62
113
  name: 'tasks',
63
114
  pane: c => {
64
115
  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
116
  const todo = c.tasks.filter(t => t.status === 'todo')
67
- const done = c.tasks.filter(t => t.status === 'done').length
117
+ const working = c.tasks.filter(t => t.status === 'claimed').length
118
+ // Most recently finished first: what was just done is what you look for.
119
+ const done = c.tasks.filter(t => t.status === 'done').sort((a, b) => (b.notes.at(-1)?.at ?? '').localeCompare(a.notes.at(-1)?.at ?? ''))
120
+ // The pane's title, with the band's counts at the right: what the whole
121
+ // board holds, before any group is opened.
122
+ const title = (
123
+ <Box justifyContent="space-between" marginBottom={1}>
124
+ {/* Which session this is: "you" in its rows, its name everywhere else. */}
125
+ <Box>
126
+ {/* The logo's green, bold: the pane's name, a heading where the
127
+ surface has sizes (the terminal has one). */}
128
+ <Text bold color="success" size="heading">
129
+ modBOARD
130
+ </Text>
131
+ {c.who ? <Text dimColor> · </Text> : null}
132
+ {c.who ? <Text dimColor>{c.who}</Text> : null}
133
+ </Box>
134
+ <Box>
135
+ {todo.length > 0 && <Text dimColor>{`${todo.length} waiting`}</Text>}
136
+ {todo.length > 0 && working > 0 && <Text dimColor> · </Text>}
137
+ {working > 0 && <Text color="success">{`${working} active`}</Text>}
138
+ </Box>
139
+ </Box>
140
+ )
141
+ if (!c.tasks.length)
142
+ return (
143
+ <Box flexDirection="column">
144
+ {title}
145
+ <Text dimColor>No tasks yet. Ask Claude to add some, or run `board add`.</Text>
146
+ </Box>
147
+ )
148
+ const groups = (
149
+ [
150
+ ['in-progress', c.tasks.filter(t => t.status === 'claimed')],
151
+ ['partway', todo.filter(handoffWaiting)],
152
+ ['not-started', todo.filter(t => !handoffWaiting(t))],
153
+ ['done', done],
154
+ ] as [GroupName, Task[]][]
155
+ ).filter(([, list]) => list.length)
68
156
  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>}
157
+ <Box flexDirection="column">
158
+ {title}
159
+ {groups.map(([name, list], i) => {
160
+ // Each group sits a blank line apart, which an open group above already leaves.
161
+ const apart = i > 0 && !groupOpen(c.groupsOpen, groups[i - 1]![0])
162
+ const group = Group(c, name, list, i === groups.length - 1)
163
+ return apart ? <Box marginTop={1}>{group}</Box> : group
164
+ })}
74
165
  </Box>
75
166
  )
76
167
  },
@@ -1,4 +1,4 @@
1
- import type { Agent, Task, Usage } from '../../types'
1
+ import type { Agent, Task, TaskFile, Usage } from '../../types'
2
2
 
3
3
  // What every block draws from. `ui` is the surface's own element table.
4
4
  export type Ctx = {
@@ -13,13 +13,22 @@ export type Ctx = {
13
13
  effort: string
14
14
  // The last line each command block printed, by block name.
15
15
  custom: Record<string, string>
16
+ // The project's task.md, and whether its list is open in the pane.
17
+ taskfile: TaskFile
18
+ taskfileOpen: boolean
19
+ // The priority the task file's list is turned to: "0" for P0, "all", or ""
20
+ // for the most urgent there is (see taskfile.tsx).
21
+ taskfileTier: string
22
+ // Which task groups the person opened or closed, by name (see tasks.tsx).
23
+ groupsOpen: Record<string, boolean>
16
24
  // What a pressed block can do: each switches the session the way the
17
25
  // matching slash command would.
18
- act: { nextModel: () => Promise<void>; nextEffort: () => Promise<void> }
26
+ act: { nextModel: () => Promise<void>; nextEffort: () => Promise<void>; toggleTaskfile: () => Promise<void>; nextTier: () => Promise<void>; toggleGroup: (name: string) => Promise<void>; showGroup: (name: string) => Promise<void>; compact: () => Promise<void>; openBoard: () => Promise<void> }
19
27
  }
20
28
 
21
29
  // One way a block can draw in the band, and how many columns it takes.
22
- export type BandForm = { tree: any; width: number }
30
+ // `end`: the part sits at the line's right end, by Claude Code's own control.
31
+ export type BandForm = { tree: any; width: number; end?: boolean }
23
32
 
24
33
  // A block is one part of the board's display. It may draw in the band above
25
34
  // the prompt, in the /board pane, or both, and returns null when it has
@@ -30,6 +39,9 @@ export type Block = {
30
39
  name: string
31
40
  band?: (c: Ctx) => BandForm[] | null
32
41
  pane?: (c: Ctx) => any
42
+ // A bar block's figures for the Limits heading when it is folded:
43
+ // "context 72%". Each comes with its percent, which colours it.
44
+ brief?: (c: Ctx) => { name: string; percent: number }[]
33
45
  }
34
46
 
35
47
  // A run of text that never wraps, and its width.
@@ -1,38 +1,28 @@
1
1
  import type { Block, Ctx } from './types'
2
+ import { Bar, CELLS, barWidth } from './meter'
2
3
 
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' }
4
+ const LABEL: Record<string, string> = { five_hour: '5-hour limit', spend_limit: 'spend limit' }
5
+ const SHORT: Record<string, string> = { five_hour: '5h', spend_limit: 'spend' }
6
+ // The name in the folded Limits heading: short, but still words.
7
+ const BRIEF: Record<string, string> = { five_hour: '5-hour', spend_limit: 'spend' }
5
8
  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
9
  const pad = (n: number) => String(n).padStart(2, '0')
23
10
  const when = (iso: string, now: number) => {
24
11
  const d = new Date(iso)
25
- const time = `${pad(d.getHours())}:${pad(d.getMinutes())}`
26
12
  const days = Math.floor((d.getTime() - now) / 86_400_000)
27
- return days >= 1 ? `in ${days}d` : time
13
+ return days >= 1 ? `in ${days}d` : `${pad(d.getHours())}:${pad(d.getMinutes())}`
28
14
  }
29
15
 
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.
16
+ // The weekly window is left off the board: it moves too slowly to act on in a
17
+ // session, and Claude Code's /usage shows it.
18
+ const shown = (u: Ctx['usage']) => u.limits.filter(l => l.kind !== 'seven_day')
19
+
20
+ // This session's plan usage, as a bar. In the band only once a window passes
21
+ // half, since below that it is noise; in the pane, each window with its reset.
32
22
  export const usage: Block = {
33
23
  name: 'usage',
34
24
  band: ({ ui, usage: u }) => {
35
- const top = [...u.limits].sort((a, b) => b.percentUsed - a.percentUsed)[0]
25
+ const top = [...shown(u)].sort((a, b) => b.percentUsed - a.percentUsed)[0]
36
26
  if (!top || top.percentUsed < 50) return null
37
27
  const form = (name: string, cells: number) => ({
38
28
  tree: (
@@ -40,25 +30,26 @@ export const usage: Block = {
40
30
  <ui.Text dimColor wrap="truncate">
41
31
  {name}
42
32
  </ui.Text>
43
- {Meter(ui, top.percentUsed, cells)}
33
+ {Bar(ui, top.percentUsed, cells)}
44
34
  </ui.Box>
45
35
  ),
46
- width: name.length + 1 + cells + 5,
36
+ width: name.length + 1 + barWidth(cells),
47
37
  })
48
38
  return [form(label(top.kind), CELLS), form(SHORT[top.kind] ?? label(top.kind), 5)]
49
39
  },
40
+ brief: ({ usage: u }) => shown(u).map(l => ({ name: BRIEF[l.kind] ?? l.kind, percent: l.percentUsed })),
50
41
  pane: ({ ui, usage: u, now }) => {
51
42
  const { Box, Text } = ui
52
- if (!u.limits.length) return null
43
+ const limits = shown(u)
44
+ if (!limits.length) return null
53
45
  return (
54
46
  <Box flexDirection="column">
55
- <Text bold>Usage</Text>
56
- {u.limits.map(l => (
47
+ {limits.map(l => (
57
48
  <Box>
58
- <Box width={15}>
49
+ <Box width={14}>
59
50
  <Text dimColor>{label(l.kind)}</Text>
60
51
  </Box>
61
- {Meter(ui, l.percentUsed)}
52
+ {Bar(ui, l.percentUsed)}
62
53
  {l.resetsAt && <Text dimColor>{` resets ${when(l.resetsAt, now)}`}</Text>}
63
54
  </Box>
64
55
  ))}