modboard 0.5.0 → 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.
package/ROADMAP.md ADDED
@@ -0,0 +1,48 @@
1
+ # Roadmap
2
+
3
+ What's planned for modboard, and what's waiting on what. Nothing here is
4
+ promised by a date. Shipped work goes in the [changelog](CHANGELOG.md).
5
+
6
+ ## Next
7
+
8
+ ### Colours: `/board colours`
9
+
10
+ Change the board's colours without touching a setting. `/board colours`
11
+ opens a short screen, one row a colour, each drawn as the thing it colours:
12
+
13
+ ```
14
+ Colours · click one to change it
15
+
16
+ In progress · Fix login terminal
17
+ T-004 · 3 open · from TASKS.md grey
18
+ 1 active green
19
+ [T-005] ▓▓▓▓▓▓▓░░░ 75% yellow
20
+ ▓▓▓▓▓▓▓▓▓░ 95% not updating red
21
+
22
+ reset
23
+ ```
24
+
25
+ - Click a row and Claude Code asks which colour: three ready ones, or any
26
+ typed under Other (`#ff8800`, `orange`, `rgb(255,136,0)`).
27
+ - Every place that means the same thing follows: text covers headings,
28
+ buttons and task titles; grey covers IDs, counts and labels; yellow covers
29
+ the unfinished boxes, idle rows and bars from 70%; red covers bars from
30
+ 90% and the `board not updating` line.
31
+ - Kept between sessions; **reset** puts them back.
32
+ - `modBOARD`'s green is fixed and never offered.
33
+
34
+ It's a separate piece: the board works without it. A first version is
35
+ built on the `colours` branch, kept out of the release until it settles.
36
+
37
+ Left before it ships:
38
+
39
+ - Try the click-to-pick flow by hand in a live session (the test kit
40
+ can't answer Claude Code's question dialog).
41
+ - Work through the issues found trying it.
42
+ - Decide how a fixed colour should behave across light and dark themes.
43
+ - Check exact colours on terminals with 256 colours only (macOS Terminal).
44
+
45
+ ## Later
46
+
47
+ - **The v0.6.0 release**: version bump and npm publish of what's in
48
+ Unreleased.
package/bin/board.mjs CHANGED
@@ -14,6 +14,7 @@ import path from 'node:path'
14
14
 
15
15
  import { BoardError, createEngine } from '../lib/engine.mjs'
16
16
  import { loadStore } from '../lib/load-store.mjs'
17
+ import { readTaskFile } from '../lib/taskfile.mjs'
17
18
 
18
19
  function boardDir() {
19
20
  if (process.env.BOARD_DIR) return path.resolve(process.env.BOARD_DIR)
@@ -28,6 +29,16 @@ function boardDir() {
28
29
  }
29
30
  }
30
31
 
32
+ // The checkout the command runs in (its own worktree, not the shared board's
33
+ // repo), else the current directory: where a task.md is looked for.
34
+ function projectDir() {
35
+ try {
36
+ return execFileSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()
37
+ } catch {
38
+ return process.cwd()
39
+ }
40
+ }
41
+
31
42
  function inside(root) {
32
43
  const old = path.join(root, '.agent-board')
33
44
  const now = path.join(root, '.modboard')
@@ -49,10 +60,15 @@ function parseArgs(argv) {
49
60
 
50
61
  const text = v => (typeof v === 'string' ? v : undefined)
51
62
 
52
- function actorOf(flags) {
63
+ // Who is asking: --as, else BOARD_AGENT, else a Codex thread (Codex marks every
64
+ // shell it runs with CODEX_THREAD_ID), named "codex 1", "codex 2" by when it
65
+ // joined. Codex sends no presence ping, so only its leases end its claims.
66
+ async function actorOf(board, flags) {
53
67
  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
68
+ if (a) return a
69
+ const thread = process.env.CODEX_THREAD_ID
70
+ if (thread) return (await board.join('codex', thread, { presence: false })).name
71
+ throw new BoardError(2, 'who are you? pass --as <agent> or set BOARD_AGENT')
56
72
  }
57
73
 
58
74
  const SYMBOL = { todo: '○', claimed: '◐', done: '●' }
@@ -84,7 +100,13 @@ const SAY = {
84
100
  done: t => `done ${line(t)}\n${t.notes.at(-1).text}`,
85
101
  'release-all': r => `released ${ids(r.released)}`,
86
102
  register: r => `you are ${r.name}`,
103
+ join: r => `you are ${r.name}`,
104
+ whoami: r => `you are ${r.name}`,
87
105
  agents: list => (list.length ? list.map(a => `${a.name} last seen ${hhmm(a.lastSeen)}`).join('\n') : '(no live agents)'),
106
+ taskfile: r =>
107
+ r.file
108
+ ? [r.file, ...r.items.map(i => `${' '.repeat(i.depth)}${i.done === null ? '-' : i.done ? '[x]' : '[ ]'} ${i.priority === null ? '' : `P${i.priority} `}${i.text}`)].join('\n')
109
+ : '(no task.md here)',
88
110
  doctor: r =>
89
111
  [`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
112
  }
@@ -99,36 +121,49 @@ const commands = {
99
121
  const t = await board.show(id)
100
122
  return flags.json ? t : describe(t)
101
123
  },
102
- add(board, [title], flags) {
124
+ async add(board, [title], flags) {
103
125
  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', {
126
+ const by = text(flags.as) ?? process.env.BOARD_AGENT ?? (process.env.CODEX_THREAD_ID ? await actorOf(board, flags) : 'human')
127
+ return board.add(by, {
105
128
  title,
106
129
  description: text(flags.desc),
107
130
  accept: text(flags.accept),
108
131
  })
109
132
  },
110
- claim: (board, [id], flags) => board.claim(id, actorOf(flags)),
111
- heartbeat: (board, _, flags) => board.heartbeat(actorOf(flags)),
112
- note(board, [id, note], flags) {
133
+ claim: async (board, [id], flags) => board.claim(id, await actorOf(board, flags)),
134
+ heartbeat: async (board, _, flags) => board.heartbeat(await actorOf(board, flags)),
135
+ async note(board, [id, note], flags) {
113
136
  if (!note) throw new BoardError(2, 'usage: board note <id> "<text>"')
114
- return board.note(id, actorOf(flags), note)
137
+ return board.note(id, await actorOf(board, flags), note)
115
138
  },
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) }),
139
+ release: async (board, [id], flags) => board.release(id, await actorOf(board, flags), text(flags.handoff)),
140
+ done: async (board, [id], flags) => board.done(id, await actorOf(board, flags), text(flags.note)),
141
+ 'release-all': async (board, _, flags) => board.releaseAll(await actorOf(board, flags), { handoff: text(flags.handoff), session: text(flags.session) }),
119
142
  register(board, [name], flags) {
120
143
  const session = text(flags.session)
121
144
  if (!name || !session) throw new BoardError(2, 'usage: board register <name> --session <id>')
122
145
  return board.register(name, session)
123
146
  },
147
+ // A name from what the session runs and when it joined: "claude 1".
148
+ join(board, [kind], flags) {
149
+ const session = text(flags.session)
150
+ if (!kind || !session) throw new BoardError(2, 'usage: board join <claude|codex|...> --session <id>')
151
+ return board.join(kind, session)
152
+ },
153
+ whoami: async (board, _, flags) => ({ name: await actorOf(board, flags) }),
124
154
  agents: board => board.agents(),
125
155
  // Everything a display needs, in one call: every task and the live agents.
126
156
  view: async board => ({ tasks: await board.list({ all: true }), agents: await board.agents() }),
127
157
  events: (board, [since]) => board.events(Number(since ?? 0)),
128
158
  doctor: async (board, _, __, store) => ({ block: store, ...(await board.doctor()) }),
129
159
  where: () => DIR,
160
+ // The project's own task.md, for display; it never touches the board.
161
+ taskfile: () => readTaskFile(process.env.BOARD_TASKFILE_DIR ?? projectDir()),
130
162
  }
131
163
 
164
+ // Commands that read no board, so no storage block is loaded for them.
165
+ const BOARDLESS = new Set(['where', 'taskfile'])
166
+
132
167
  async function main() {
133
168
  const [cmd, ...rest] = process.argv.slice(2)
134
169
  const { pos, flags } = parseArgs(rest)
@@ -138,11 +173,13 @@ async function main() {
138
173
  process.exit(2)
139
174
  }
140
175
  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
- })
176
+ const { store, name } = BOARDLESS.has(cmd) ? { store: null, name: '' } : await loadStore(DIR)
177
+ const board =
178
+ store &&
179
+ createEngine(store, {
180
+ leaseMs: Number(process.env.BOARD_LEASE_MS ?? 15 * 60 * 1000),
181
+ presenceMs: Number(process.env.BOARD_PRESENCE_MS ?? 3 * 60 * 1000),
182
+ })
146
183
  const out = await run(board, pos, flags, name)
147
184
  const say = !flags.json && SAY[cmd]
148
185
  console.log(say ? say(out) : flags.json || typeof out !== 'string' ? JSON.stringify(out, null, 2) : out)
@@ -0,0 +1,23 @@
1
+ import type { Block } from './types'
2
+
3
+ // The mod's name on the band, bold in the logo's green, as the pane's title
4
+ // is: a button that opens the /board pane, or closes it when it is open. No
5
+ // brackets; the click is the whole of it.
6
+ // It sits at the line's right end, by Claude Code's own [-]. The pane has no
7
+ // part of it.
8
+ export const board: Block = {
9
+ name: 'board',
10
+ band: ({ ui: { Button, Text }, act }) => [
11
+ {
12
+ tree: (
13
+ <Button key="board" plain onPress={act.openBoard}>
14
+ <Text bold color="success">
15
+ modBOARD
16
+ </Text>
17
+ </Button>
18
+ ),
19
+ width: 'modBOARD'.length,
20
+ end: true,
21
+ },
22
+ ],
23
+ }
@@ -6,5 +6,5 @@ const hhmm = (now: number) => `${pad(new Date(now).getHours())}:${pad(new Date(n
6
6
  export const clock: Block = {
7
7
  name: 'clock',
8
8
  band: ({ ui: { Text }, now }) => [words(Text, hhmm(now), { dimColor: true })],
9
- pane: ({ ui: { Text }, now }) => <Text bold>{hhmm(now)}</Text>,
9
+ pane: ({ ui: { Text }, now }) => <Text dimColor>{hhmm(now)}</Text>,
10
10
  }
@@ -0,0 +1,49 @@
1
+ import type { Block } from './types'
2
+ import { Bar, CELLS, barParts, barWidth } from './meter'
3
+
4
+ // The context window as a bar, like the 5-hour limit's, and a button that
5
+ // compacts the conversation (Claude Code's own compaction, the call /compact
6
+ // makes). The fill is Claude Code's local estimate until the first reply,
7
+ // then each reply's measurement. In the band, the whole part is the button;
8
+ // in the pane, the word compact beside the bar, a button like the model's, always there,
9
+ // with an empty bar if no figure has come yet. The bar takes colour from 70%.
10
+ export const compact: Block = {
11
+ name: 'compact',
12
+ band: ({ ui, usage: u, act }) => {
13
+ if (u.context === undefined) return null
14
+ const { Button, Text } = ui
15
+ const press = (name: string, cells: number, withWord: boolean) => ({
16
+ tree: (
17
+ <Button key="compact" plain onPress={act.compact}>
18
+ {[<Text dimColor>{`${name} `}</Text>, ...barParts(ui, u.context!, cells), ...(withWord ? [<Text dimColor> compact</Text>] : [])]}
19
+ </Button>
20
+ ),
21
+ width: name.length + 1 + barWidth(cells) + (withWord ? 8 : 0),
22
+ })
23
+ return [press('context', CELLS, true), press('ctx', 5, false)]
24
+ },
25
+ brief: ({ usage: u }) => (u.context === undefined ? [] : [{ name: 'context', percent: u.context }]),
26
+ pane: ({ ui, usage: u, act }) => {
27
+ const { Box, Button, Text } = ui
28
+ return (
29
+ <Box>
30
+ <Box width={14}>
31
+ <Text dimColor>context</Text>
32
+ </Box>
33
+ {u.context === undefined ? (
34
+ <Box flexShrink={0}>
35
+ <Text dimColor>{'░'.repeat(CELLS)}</Text>
36
+ <Text dimColor>{' –'}</Text>
37
+ </Box>
38
+ ) : (
39
+ Bar(ui, u.context)
40
+ )}
41
+ <Box marginLeft={3}>
42
+ <Button key="compact" plain onPress={act.compact}>
43
+ <Text bold>compact</Text>
44
+ </Button>
45
+ </Box>
46
+ </Box>
47
+ )
48
+ },
49
+ }
@@ -8,6 +8,7 @@ export const context: Block = {
8
8
  u.context === undefined
9
9
  ? null
10
10
  : [words(Text, `context ${Math.round(u.context)}%`, { dimColor: true }), words(Text, `ctx ${Math.round(u.context)}%`, { dimColor: true })],
11
+ brief: ({ usage: u }) => (u.context === undefined ? [] : [{ name: 'context', percent: u.context }]),
11
12
  pane: ({ ui: { Text }, usage: u }) => {
12
13
  const parts = [
13
14
  u.context !== undefined && `context ${Math.round(u.context)}% full`,
@@ -5,18 +5,17 @@ import type { Block } from './types'
5
5
  export const effort: Block = {
6
6
  name: 'effort',
7
7
  band: ({ ui: { Button, Text }, effort: level, act }) => {
8
+ // Beside the model, the level says what it is ("low"), so the band gives it no label.
8
9
  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
10
  return [
18
- press(`effort ${shown}`, [<Text dimColor>effort </Text>, <Text bold>{shown}</Text>]),
19
- press(shown, <Text bold>{shown}</Text>),
11
+ {
12
+ tree: (
13
+ <Button key="effort" plain onPress={act.nextEffort}>
14
+ <Text bold>{shown}</Text>
15
+ </Button>
16
+ ),
17
+ width: shown.length,
18
+ },
20
19
  ]
21
20
  },
22
21
  pane: ({ ui: { Box, Button, Text }, effort: level, act }) => (
@@ -4,15 +4,18 @@
4
4
  // command's output need no code: see command.tsx and the `blocks` setting.
5
5
 
6
6
  import { agents } from './agents'
7
+ import { board } from './board'
7
8
  import { clock } from './clock'
9
+ import { compact } from './compact'
8
10
  import { context } from './context'
9
11
  import { effort } from './effort'
10
12
  import { model } from './model'
11
13
  import { summary } from './summary'
14
+ import { taskfile } from './taskfile'
12
15
  import { tasks } from './tasks'
13
16
  import { usage } from './usage'
14
17
  import type { Block } from './types'
15
18
 
16
- export const BLOCKS: Block[] = [summary, tasks, usage, model, effort, clock, context, agents]
19
+ export const BLOCKS: Block[] = [summary, board, tasks, taskfile, usage, compact, model, effort, clock, context, agents]
17
20
 
18
21
  export type { BandForm, Block, Ctx } from './types'
@@ -0,0 +1,29 @@
1
+ import type { Ctx } from './types'
2
+
3
+ // How the board draws "how full": a bar, for both the 5-hour limit and the
4
+ // context window, so the same idea always looks the same. The used part is in
5
+ // its tone, the rest dim, then the percent.
6
+
7
+ // Colour only when it asks something of you: yellow from 70%, red from 90%.
8
+ // With room left it stays plain. Theme colours, so they follow the terminal.
9
+ export const tone = (percent: number) => (percent >= 90 ? 'error' : percent >= 70 ? 'warning' : undefined)
10
+
11
+ export const CELLS = 10
12
+ const filled = (percent: number, cells: number) => Math.min(cells, Math.round((percent / 100) * cells))
13
+
14
+ // A bar's width in columns: its cells, a space, and "100%".
15
+ export const barWidth = (cells = CELLS) => cells + 5
16
+
17
+ // The bar as Text pieces alone: what a Button may hold.
18
+ export function barParts({ Text }: Ctx['ui'], percent: number, cells = CELLS) {
19
+ const color = tone(percent)
20
+ return [
21
+ <Text color={color}>{'▓'.repeat(filled(percent, cells))}</Text>,
22
+ <Text dimColor>{'░'.repeat(cells - filled(percent, cells))}</Text>,
23
+ <Text color={color} dimColor={!color}>{` ${String(Math.round(percent)).padStart(3)}%`}</Text>,
24
+ ]
25
+ }
26
+
27
+ export function Bar(ui: Ctx['ui'], percent: number, cells = CELLS) {
28
+ return <ui.Box flexShrink={0}>{barParts(ui, percent, cells)}</ui.Box>
29
+ }
@@ -12,18 +12,17 @@ export const modelName = (id: string) => {
12
12
  export const model: Block = {
13
13
  name: 'model',
14
14
  band: ({ ui: { Button, Text }, model: id, act }) => {
15
+ // The name says what it is ("Sonnet 5.5"), so the band gives it no label.
15
16
  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
17
  return [
25
- press(`model ${name}`, [<Text dimColor>model </Text>, <Text bold>{name}</Text>]),
26
- press(name, <Text bold>{name}</Text>),
18
+ {
19
+ tree: (
20
+ <Button key="model" plain onPress={act.nextModel}>
21
+ <Text bold>{name}</Text>
22
+ </Button>
23
+ ),
24
+ width: name.length,
25
+ },
27
26
  ]
28
27
  },
29
28
  pane: ({ ui: { Box, Button, Text }, model: id, act }) => (
@@ -1,46 +1,63 @@
1
1
  import type { Block } from './types'
2
- import { goingQuiet, handoffWaiting } from './attention'
2
+ import { handoffWaiting } from './attention'
3
3
 
4
- const tasksWord = (n: number) => `${n} ${n === 1 ? 'task' : 'tasks'}`
4
+ // How many tasks the alert names in its widest form before the rest become "+N".
5
+ const NAMED = 3
5
6
 
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.
7
+ // The band's main line: how much is waiting and active, and the one thing
8
+ // that needs you. Short words: the reader need not know the board's terms.
8
9
  export const summary: Block = {
9
10
  name: 'summary',
10
- band: ({ ui: { Box, Text }, tasks, now }) => {
11
+ band: ({ ui: { Box, Text, Button }, tasks, act }) => {
11
12
  const working = tasks.filter(t => t.status === 'claimed').length
12
13
  const open = tasks.filter(t => t.status === 'todo').length
13
14
  if (!working && !open) return null
15
+ // Unfinished work, the one thing on the board that waits for someone. A
16
+ // claim gone idle is left to the pane: its lease frees it on its own.
14
17
  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` : ''
18
+ // Each unfinished task is a yellow box, the first thing on the line. It is
19
+ // a button, as everything bold on the band is: pressed, it opens the pane
20
+ // at the Unfinished group.
21
+ const box = (id: string) => (
22
+ <Button key={`task-${id}`} plain onPress={() => act.showGroup('partway')}>
23
+ <Text backgroundColor="warning" color="inverseText" bold>
24
+ {` ${id} `}
25
+ </Text>
26
+ </Button>
27
+ )
28
+ // Boxes for the first `named` tasks, then "+N" for the rest.
29
+ const alert = (named: number) => {
30
+ const shown = waiting.slice(0, named)
31
+ const more = waiting.length - shown.length
32
+ return {
33
+ tree: (
34
+ <Box flexShrink={0}>
35
+ {shown.flatMap((t, i) => (i ? [<Text> </Text>, box(t.id)] : [box(t.id)]))}
36
+ {more ? <Text color="warning">{` +${more}`}</Text> : null}
37
+ </Box>
38
+ ),
39
+ width: shown.reduce((n, t) => n + t.id.length + 2, 0) + Math.max(0, shown.length - 1) + (more ? ` +${more}`.length : 0),
40
+ }
41
+ }
42
+ // Widest first: up to NAMED boxes, then only the first.
43
+ const alerts = waiting.length ? [alert(NAMED), alert(1)] : []
44
+ const countParts = [
45
+ open ? <Text dimColor>{`${open} waiting`}</Text> : null,
46
+ open && working ? <Text dimColor> · </Text> : null,
47
+ working ? <Text color="success">{`${working} active`}</Text> : null,
48
+ ].filter(Boolean)
49
+ const countsWidth = (open ? `${open} waiting`.length : 0) + (open && working ? 3 : 0) + (working ? `${working} active`.length : 0)
24
50
  // The alert outlasts the counts: it is the one thing that needs you.
25
- const form = (left: string, right: string) => ({
51
+ const form = (counts: boolean, right?: { tree: any; width: number }) => ({
26
52
  tree: (
27
53
  <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}
54
+ {counts ? <Box flexShrink={0}>{countParts}</Box> : null}
55
+ {right ? right.tree : null}
38
56
  </Box>
39
57
  ),
40
- width: left.length + right.length + (left && right ? 3 : 0),
58
+ width: (counts ? countsWidth : 0) + (right ? right.width : 0) + (counts && right ? 3 : 0),
41
59
  })
42
- return alert
43
- ? [form(counts, alert), form(short, alert), form(short, shortAlert), form('', shortAlert)]
44
- : [form(counts, ''), form(short, '')]
60
+ if (!alerts.length) return [form(true)]
61
+ return [...alerts.map(a => form(true, a)), form(false, alerts.at(-1))]
45
62
  },
46
63
  }
@@ -0,0 +1,130 @@
1
+ import type { TaskFile } from '../../types'
2
+ import type { Block, Ctx } from './types'
3
+
4
+ type Item = TaskFile['items'][number]
5
+
6
+ // What is left to do: every item not checked off. Plain bullets count too.
7
+ export const openItems = (items: Item[]) => items.filter(i => i.done !== true)
8
+
9
+ const NONE = 99
10
+ const rank = (i: Item) => i.priority ?? NONE
11
+
12
+ // Most urgent first; within a priority, the file's own order (sort is stable).
13
+ const byPriority = (items: Item[]) => [...items].sort((a, b) => rank(a) - rank(b))
14
+
15
+ // The priorities the open items have, most urgent first.
16
+ export const tiers = (items: Item[]) => [...new Set(items.map(i => i.priority).filter((p): p is number => p !== null))].sort((a, b) => a - b)
17
+
18
+ // The tier the list is turned to: the one chosen, while the file still has it;
19
+ // else the most urgent there is. "all" stays "all".
20
+ export function currentTier(items: Item[], chosen: string): number | 'all' {
21
+ if (chosen === 'all') return 'all'
22
+ const have = tiers(items)
23
+ return chosen !== '' && have.includes(Number(chosen)) ? Number(chosen) : (have[0] ?? 'all')
24
+ }
25
+
26
+ // The tier after the current one: each priority the file has, then "all",
27
+ // then round to the most urgent again.
28
+ export function nextTier(items: Item[], chosen: string): string {
29
+ const cycle: (number | 'all')[] = [...tiers(items), 'all']
30
+ return String(cycle[(cycle.indexOf(currentTier(items, chosen)) + 1) % cycle.length])
31
+ }
32
+
33
+ // The priority column of the "all" view: on every row, so each line reads as
34
+ // a task of its own, never as the second line of the one above. Items with
35
+ // none have a dash.
36
+ function Ranked(c: Ctx, i: Item) {
37
+ const { Box, Text } = c.ui
38
+ return (
39
+ <Box>
40
+ <Box width={4} flexShrink={0}>
41
+ <Text dimColor>{i.priority === null ? '–' : `P${i.priority}`}</Text>
42
+ </Box>
43
+ <Box flexGrow={1} flexShrink={1}>
44
+ <Text wrap="truncate">{i.text}</Text>
45
+ </Box>
46
+ </Box>
47
+ )
48
+ }
49
+
50
+ // One item, a grey dot before it, as a handoff's points have.
51
+ function Row(c: Ctx, i: Item, indent: number) {
52
+ const { Box, Text } = c.ui
53
+ return (
54
+ <Box paddingLeft={indent + i.depth * 2}>
55
+ <Text dimColor>· </Text>
56
+ <Text wrap="truncate">{i.text}</Text>
57
+ </Box>
58
+ )
59
+ }
60
+
61
+ // The project's own task file, beside the board, reduced to what is left to
62
+ // do. Closed, one line: the file and how much is open, and, when the file has
63
+ // priorities, a second button that turns through them like the effort block:
64
+ // "P0", "P1", …, "all", and round again: the rows say how many. Pressing it shows that tier.
65
+ // Open, a single tier is just its work; "all" is every priority in order,
66
+ // each row with its own; a file without priorities keeps its own order
67
+ // under its headings. Open, it shows every open item, read again from the
68
+ // file on each press. It is for
69
+ // reading: to work an item through the board, add it there (board add).
70
+ export const taskfile: Block = {
71
+ name: 'taskfile',
72
+ pane: c => {
73
+ const { Box, Button, Text } = c.ui
74
+ const { file } = c.taskfile
75
+ if (!file) return null
76
+ const left = openItems(c.taskfile.items)
77
+ const ranked = tiers(left).length > 0
78
+ const tier = currentTier(left, c.taskfileTier)
79
+ const head = (
80
+ <Box gap={3}>
81
+ {/* Only the name is the button; the count beside it is grey text, so
82
+ the hover highlight covers what you click and nothing else. */}
83
+ <Box>
84
+ <Button key="taskfile" plain onPress={c.act.toggleTaskfile}>
85
+ <Text bold>{`${c.taskfileOpen ? '▾' : '▸'} To do`}</Text>
86
+ </Button>
87
+ <Text dimColor>{` · ${left.length ? `${left.length} open` : 'all done'}`}</Text>
88
+ </Box>
89
+ {ranked && (
90
+ // Bold, like compact: it reads as a button, not a label.
91
+ <Button key="tier" plain onPress={c.act.nextTier}>
92
+ <Text bold>{tier === 'all' ? 'all' : `P${tier}`}</Text>
93
+ </Button>
94
+ )}
95
+ </Box>
96
+ )
97
+ if (!c.taskfileOpen || !left.length) return head
98
+
99
+ const list = !ranked ? left : tier === 'all' ? byPriority(left) : left.filter(i => i.priority === tier)
100
+ // Open, every item shows; the pane scrolls.
101
+ const shown = list
102
+ let body
103
+ if (ranked && tier === 'all') body = shown.map(i => Ranked(c, i))
104
+ // One tier: the button names it, so the rows are only the work.
105
+ else if (ranked) body = shown.map(i => Row(c, i, 2))
106
+ else
107
+ body = [...new Set(shown.map(i => i.section))].map(s => (
108
+ <Box flexDirection="column" marginTop={1}>
109
+ {s && <Text dimColor>{s}</Text>}
110
+ {shown.filter(i => i.section === s).map(i => Row(c, i, 2))}
111
+ </Box>
112
+ ))
113
+ return (
114
+ <Box flexDirection="column">
115
+ {head}
116
+ {/* The heading says what it is; open, this says where it came from. */}
117
+ <Box marginTop={1} paddingLeft={2}>
118
+ <Text dimColor>{`from ${file}`}</Text>
119
+ </Box>
120
+ {ranked ? (
121
+ <Box flexDirection="column" marginTop={1}>
122
+ {body}
123
+ </Box>
124
+ ) : (
125
+ body
126
+ )}
127
+ </Box>
128
+ )
129
+ },
130
+ }