@juicesharp/rpiv-todo 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -127
- package/docs/configuration.md +108 -0
- package/docs/overlay.md +127 -0
- package/docs/tool-schema.md +152 -0
- package/index.ts +129 -25
- package/package.json +6 -2
- package/state/state-reducer.ts +5 -1
- package/state/store.ts +4 -4
- package/todo-overlay.ts +4 -4
- package/todo.ts +1 -0
- package/tool/types.ts +2 -1
- package/view/format.ts +7 -6
package/README.md
CHANGED
|
@@ -1,158 +1,122 @@
|
|
|
1
|
-
# rpiv-todo
|
|
1
|
+
# @juicesharp/rpiv-todo
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@juicesharp/rpiv-todo)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
2
5
|
|
|
3
6
|
<div align="center">
|
|
4
7
|
<a href="https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo">
|
|
5
|
-
<
|
|
6
|
-
<img src="https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-todo/docs/cover.png" alt="rpiv-todo cover" width="50%">
|
|
7
|
-
</picture>
|
|
8
|
+
<img src="https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-todo/docs/cover.png" alt="rpiv-todo — a persistent todo overlay for Pi Agent, showing a task panel with completed, in-progress, and pending rows" width="50%">
|
|
8
9
|
</a>
|
|
9
10
|
</div>
|
|
10
11
|
|
|
11
|
-
Give the model a
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- **Live overlay above the editor** - see the model's plan at all times; completed items stay visible until the next agent response starts, then fall away; auto-hides when empty.
|
|
18
|
-
- **Survives `/reload` and compaction** - tasks replay from the conversation branch, not disk.
|
|
19
|
-
- **Status states** - pending, in_progress, completed, plus a deleted tombstone for audit.
|
|
20
|
-
- **Dependency tracking** - `blockedBy` with cycle detection, so the model can sequence work.
|
|
21
|
-
- **Smart truncation** - collapse threshold (default 12, [configurable](#configuration) via `maxWidgetLines`); completed tasks drop first, pending tasks stay visible last.
|
|
12
|
+
Give the model a task list you can see. `rpiv-todo` adds a `todo` tool, a
|
|
13
|
+
`/todos` command, and a live panel above the editor to
|
|
14
|
+
[Pi Agent](https://github.com/badlogic/pi-mono), so you always know what the
|
|
15
|
+
agent is doing now, what it finished, and what is queued. The list is rebuilt
|
|
16
|
+
from the conversation itself, so it survives `/reload` and compaction — useful
|
|
17
|
+
on long research → design → implement sessions.
|
|
22
18
|
|
|
23
19
|
## Install
|
|
24
20
|
|
|
25
|
-
```
|
|
21
|
+
```sh
|
|
26
22
|
pi install npm:@juicesharp/rpiv-todo
|
|
27
23
|
```
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
### Optional: localization
|
|
32
|
-
|
|
33
|
-
`rpiv-todo` works standalone - install only this package and you get the full English UI. Install `@juicesharp/rpiv-i18n` alongside it to flip the overlay heading, `/todos` section headers, and status words to your active locale:
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
pi install npm:@juicesharp/rpiv-i18n
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
With the SDK present, locale resolves from `--locale <code>` → `~/.config/rpiv-i18n/locale.json` → `LANG` / `LC_ALL` → English. The `/languages` interactive picker and `pi --locale <code>` startup flag are also enabled. Without the SDK, the extension stays online and renders English at every call site - no warning, no crash. Users who installed via `pi install npm:@juicesharp/rpiv-pi` + `/rpiv-setup` get the SDK automatically.
|
|
40
|
-
|
|
41
|
-
## Tool
|
|
42
|
-
|
|
43
|
-
- **`todo`** - create / update / list / get / delete / clear tasks. 4-state
|
|
44
|
-
machine (pending → in_progress → completed, plus deleted tombstone).
|
|
45
|
-
Supports `blockedBy` dependency tracking with cycle detection. Tasks persist
|
|
46
|
-
via branch replay - survive session compact and `/reload`.
|
|
47
|
-
|
|
48
|
-
### Schema
|
|
49
|
-
|
|
50
|
-
```ts
|
|
51
|
-
todo({
|
|
52
|
-
action: "create" | "update" | "list" | "get" | "delete" | "clear",
|
|
53
|
-
|
|
54
|
-
// create-only
|
|
55
|
-
subject?: string, // required for create
|
|
56
|
-
blockedBy?: number[], // initial dependency ids
|
|
57
|
-
|
|
58
|
-
// create + update
|
|
59
|
-
description?: string,
|
|
60
|
-
activeForm?: string, // present-continuous label shown while in_progress
|
|
61
|
-
owner?: string,
|
|
62
|
-
metadata?: Record<string, unknown>, // pass null per key to delete that key on update
|
|
25
|
+
Restart your Pi session.
|
|
63
26
|
|
|
64
|
-
|
|
65
|
-
addBlockedBy?: number[], // additive merge into blockedBy
|
|
66
|
-
removeBlockedBy?: number[], // additive removal from blockedBy
|
|
27
|
+
## Quick start
|
|
67
28
|
|
|
68
|
-
|
|
69
|
-
|
|
29
|
+
Run `/todos` after the restart to confirm the extension is loaded. On a fresh
|
|
30
|
+
session it prints:
|
|
70
31
|
|
|
71
|
-
// update (target) or list (filter)
|
|
72
|
-
status?: "pending" | "in_progress" | "completed" | "deleted",
|
|
73
|
-
|
|
74
|
-
// list-only
|
|
75
|
-
includeDeleted?: boolean, // default false - hides tombstones
|
|
76
|
-
})
|
|
77
32
|
```
|
|
78
|
-
|
|
79
|
-
Valid status transitions: `pending ⇄ in_progress`, either → `completed`, any → `deleted` (terminal). `delete` keeps the task as a tombstone so historic `blockedBy` references still resolve.
|
|
80
|
-
|
|
81
|
-
Returns:
|
|
82
|
-
|
|
83
|
-
```ts
|
|
84
|
-
{
|
|
85
|
-
content: [{ type: "text", text: string }], // human-readable summary of the op
|
|
86
|
-
details: { // full snapshot - replay reads this back
|
|
87
|
-
action: TaskAction,
|
|
88
|
-
params: Record<string, unknown>,
|
|
89
|
-
tasks: Array<{
|
|
90
|
-
id: number,
|
|
91
|
-
subject: string,
|
|
92
|
-
description?: string,
|
|
93
|
-
activeForm?: string,
|
|
94
|
-
status: "pending" | "in_progress" | "completed" | "deleted",
|
|
95
|
-
blockedBy?: number[],
|
|
96
|
-
owner?: string,
|
|
97
|
-
metadata?: Record<string, unknown>,
|
|
98
|
-
}>,
|
|
99
|
-
nextId: number,
|
|
100
|
-
error?: string, // present only on validation/transition failures
|
|
101
|
-
}
|
|
102
|
-
}
|
|
33
|
+
No todos yet. Ask the agent to add some!
|
|
103
34
|
```
|
|
104
35
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
36
|
+
Then ask for something with several steps — "add a repository layer with tests,
|
|
37
|
+
and track it as todos". The model calls `todo` and the panel appears above your
|
|
38
|
+
input box, updating as work moves:
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
Press `ctrl+shift+t` to collapse the panel to its heading plus a one-line hint,
|
|
43
|
+
and again to expand it. Run `/todos` at any time to print the full list grouped
|
|
44
|
+
by status.
|
|
45
|
+
|
|
46
|
+
## What you get
|
|
47
|
+
|
|
48
|
+
- **The plan stays on screen.** A panel above the editor shows every task with a
|
|
49
|
+
status glyph, the label of whatever is in progress, and a `Todos (done/total)`
|
|
50
|
+
heading — you never have to ask the agent where it is.
|
|
51
|
+
- **Tasks survive `/reload` and compaction.** Each tool call carries the full
|
|
52
|
+
post-mutation snapshot, and the list is replayed from the session branch. No
|
|
53
|
+
disk writes, nothing to lose.
|
|
54
|
+
- **Finished work gets out of the way.** Completed rows stay visible for the rest
|
|
55
|
+
of the turn, then drop at the start of the next one; the panel disappears
|
|
56
|
+
entirely when the list empties.
|
|
57
|
+
- **The overlay never eats your terminal.** Past the row budget it drops
|
|
58
|
+
completed tasks first, truncates unfinished ones last, and tells you what it
|
|
59
|
+
hid with `+3 more (2 completed, 1 pending)`.
|
|
60
|
+
- **The agent can sequence work, not just list it.** `blockedBy` dependencies are
|
|
61
|
+
validated before anything is written — dangling ids, deleted dependencies,
|
|
62
|
+
self-blocks, and cycles are all rejected.
|
|
63
|
+
- **Parallel sessions stay separate.** Task state is keyed by session, so a
|
|
64
|
+
detached or child session can neither read nor overwrite the foreground list.
|
|
65
|
+
- **Localized UI, no setup required.** Nine locales ship with the package and
|
|
66
|
+
activate when [`@juicesharp/rpiv-i18n`](https://www.npmjs.com/package/@juicesharp/rpiv-i18n)
|
|
67
|
+
is installed; without it, everything falls back to English.
|
|
108
68
|
|
|
109
69
|
## Configuration
|
|
110
70
|
|
|
111
|
-
Optional
|
|
71
|
+
Optional. Create `~/.config/rpiv-todo/config.json` (or
|
|
72
|
+
`$XDG_CONFIG_HOME/rpiv-todo/config.json` if you set that variable):
|
|
112
73
|
|
|
113
74
|
```json
|
|
114
75
|
{
|
|
115
76
|
"maxWidgetLines": 8,
|
|
116
|
-
"collapseKey": "alt+t"
|
|
117
|
-
"guidance": {
|
|
118
|
-
"promptSnippet": "Use the `todo` tool to track multi-step work before starting it.",
|
|
119
|
-
"promptGuidelines": [
|
|
120
|
-
"Create one task per discrete step.",
|
|
121
|
-
"Mark a task in_progress while working on it; completed when done."
|
|
122
|
-
]
|
|
123
|
-
}
|
|
77
|
+
"collapseKey": "alt+t"
|
|
124
78
|
}
|
|
125
79
|
```
|
|
126
80
|
|
|
127
|
-
|
|
|
128
|
-
|
|
129
|
-
| `maxWidgetLines` |
|
|
130
|
-
| `collapseKey` |
|
|
131
|
-
| `guidance` |
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
81
|
+
| Setting | What it does | Default |
|
|
82
|
+
| --- | --- | --- |
|
|
83
|
+
| `maxWidgetLines` | Content rows the overlay may use, heading included. Minimum `3`. Applies on the next repaint. | `12` |
|
|
84
|
+
| `collapseKey` | Key that collapses and expands the panel, in Pi keybinding form (`alt+o`, `ctrl+shift+t`). Set `"off"` to register no shortcut. Needs `/reload` to rebind. | `"ctrl+shift+t"` |
|
|
85
|
+
| `guidance` | Replaces the built-in instructions the extension gives the model about when and how to use the todo list. Needs `/reload`. | _(built-ins)_ |
|
|
86
|
+
|
|
87
|
+
A missing or malformed file falls back to these defaults. `rpiv-todo` only reads
|
|
88
|
+
this file — it never writes one. Full semantics:
|
|
89
|
+
[Configuration](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-todo/docs/configuration.md).
|
|
90
|
+
|
|
91
|
+
## Reference
|
|
92
|
+
|
|
93
|
+
- [`todo` tool reference](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-todo/docs/tool-schema.md)
|
|
94
|
+
— every `todo` parameter, the status machine, the response envelope, and the
|
|
95
|
+
exact error strings.
|
|
96
|
+
- [Configuration](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-todo/docs/configuration.md)
|
|
97
|
+
— config file resolution, option validation rules, and the accepted keybinding
|
|
98
|
+
grammar.
|
|
99
|
+
- [Overlay and `/todos`](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-todo/docs/overlay.md)
|
|
100
|
+
— overlay lifecycle, glyphs, overflow behavior, `/todos` output, and
|
|
101
|
+
localization.
|
|
102
|
+
|
|
103
|
+
## Requirements
|
|
104
|
+
|
|
105
|
+
- A Pi Agent host. No API key, no model selection, no native dependencies.
|
|
106
|
+
- An interactive session for the panel and `/todos`. Headless runs still get the
|
|
107
|
+
`todo` tool; nothing is rendered.
|
|
108
|
+
- [`@juicesharp/rpiv-i18n`](https://www.npmjs.com/package/@juicesharp/rpiv-i18n)
|
|
109
|
+
is an optional peer — install it for a localized UI, skip it for English.
|
|
110
|
+
|
|
111
|
+
## Related
|
|
112
|
+
|
|
113
|
+
- [`@juicesharp/rpiv-i18n`](https://www.npmjs.com/package/@juicesharp/rpiv-i18n)
|
|
114
|
+
([source](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-i18n))
|
|
115
|
+
— localizes this extension's UI chrome and adds a `/languages` picker.
|
|
116
|
+
- [`@juicesharp/rpiv-pi`](https://www.npmjs.com/package/@juicesharp/rpiv-pi)
|
|
117
|
+
([source](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-pi))
|
|
118
|
+
— the umbrella package that installs this extension alongside its siblings.
|
|
152
119
|
|
|
153
120
|
## License
|
|
154
121
|
|
|
155
|
-
[
|
|
156
|
-
[](https://opensource.org/licenses/MIT)
|
|
157
|
-
|
|
158
|
-
MIT
|
|
122
|
+
MIT — see [LICENSE](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-todo/LICENSE).
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Configuration reference
|
|
2
|
+
|
|
3
|
+
Every option
|
|
4
|
+
[`@juicesharp/rpiv-todo`](https://www.npmjs.com/package/@juicesharp/rpiv-todo)
|
|
5
|
+
reads, where the file lives, and exactly what happens when a value is wrong.
|
|
6
|
+
|
|
7
|
+
## Where the file lives
|
|
8
|
+
|
|
9
|
+
The config file is optional. It is resolved in this order:
|
|
10
|
+
|
|
11
|
+
1. `$XDG_CONFIG_HOME/rpiv-todo/config.json` — used when `XDG_CONFIG_HOME` is set
|
|
12
|
+
to an absolute path. A bare `~` or a leading `~/` is expanded first; a `~user`
|
|
13
|
+
form is not expanded and therefore falls through.
|
|
14
|
+
2. `~/.config/rpiv-todo/config.json` — used when `XDG_CONFIG_HOME` is unset,
|
|
15
|
+
empty, whitespace-only, or relative.
|
|
16
|
+
3. If the XDG file does not exist, the legacy `~/.config/rpiv-todo/config.json`
|
|
17
|
+
is read anyway, so a pre-XDG file is still found after you set
|
|
18
|
+
`XDG_CONFIG_HOME`. This fallback is one-way: if the XDG file exists but is
|
|
19
|
+
malformed, you get a warning and defaults — it does **not** quietly read the
|
|
20
|
+
legacy file instead.
|
|
21
|
+
|
|
22
|
+
Both files missing means every default applies. Malformed JSON prints a
|
|
23
|
+
`rpiv-config: invalid JSON at …` warning and is treated as `{}`. A JSON array or
|
|
24
|
+
a non-object value (`null`, a string, a number, a boolean) is silently treated as
|
|
25
|
+
`{}` — no warning.
|
|
26
|
+
|
|
27
|
+
`rpiv-todo` never writes this file — you create and edit it yourself, and the
|
|
28
|
+
extension only reads it.
|
|
29
|
+
|
|
30
|
+
## Example
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"maxWidgetLines": 8,
|
|
35
|
+
"collapseKey": "alt+t",
|
|
36
|
+
"guidance": {
|
|
37
|
+
"promptSnippet": "Use the `todo` tool to track multi-step work before starting it.",
|
|
38
|
+
"promptGuidelines": [
|
|
39
|
+
"Create one task per discrete step.",
|
|
40
|
+
"Mark a task in_progress while working on it; completed when done."
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## `maxWidgetLines`
|
|
47
|
+
|
|
48
|
+
**Default `12`.** The content-row budget for the overlay — the heading row and,
|
|
49
|
+
on overflow, the `+N more` summary row both count against it. Only the trailing
|
|
50
|
+
blank spacer sits outside the budget, so `12` renders up to 13 terminal rows.
|
|
51
|
+
|
|
52
|
+
- Floor of `3`. A number below `3` falls back to the default.
|
|
53
|
+
- A non-number falls back to the default.
|
|
54
|
+
- No ceiling.
|
|
55
|
+
- Read fresh on every render, so a change takes effect on the next repaint —
|
|
56
|
+
no `/reload`.
|
|
57
|
+
|
|
58
|
+
## `collapseKey`
|
|
59
|
+
|
|
60
|
+
**Default `"ctrl+shift+t"`.** The shortcut that collapses and expands the
|
|
61
|
+
overlay.
|
|
62
|
+
|
|
63
|
+
The value is trimmed and lowercased, then matched against Pi's keybinding
|
|
64
|
+
grammar: zero or more distinct modifiers joined by `+`, then a base key.
|
|
65
|
+
|
|
66
|
+
| Part | Accepted |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| Modifiers | `ctrl`, `shift`, `alt`, `super` — each at most once |
|
|
69
|
+
| Base key | one printable character (`a`, `7`, `]`, `/`, …) |
|
|
70
|
+
| Base key | a named key: `escape`, `esc`, `enter`, `return`, `tab`, `space`, `backspace`, `delete`, `insert`, `clear`, `home`, `end`, `pageup`, `pagedown`, `up`, `down`, `left`, `right`, `f1`–`f12` |
|
|
71
|
+
|
|
72
|
+
Examples: `alt+o`, `ctrl+shift+t`, `super+alt+f5`.
|
|
73
|
+
|
|
74
|
+
- A missing, empty, blank, non-string, or ungrammatical value falls back to the
|
|
75
|
+
default. The grammar is checked strictly on purpose: Pi takes the last `+`-part
|
|
76
|
+
as the base key and ignores unknown parts, so a typo like `ctr+]` would
|
|
77
|
+
otherwise capture every bare `]` keypress globally.
|
|
78
|
+
- `"off"` disables the feature — no shortcut is registered at all.
|
|
79
|
+
- The binding is resolved **once at extension load**. After editing this value,
|
|
80
|
+
run `/reload` to rebind; until you do, the old key stays active even though the
|
|
81
|
+
collapsed panel's hint text (which is resolved per render) already shows the
|
|
82
|
+
new one.
|
|
83
|
+
|
|
84
|
+
## Guidance
|
|
85
|
+
|
|
86
|
+
`guidance.promptSnippet` (string) and `guidance.promptGuidelines` (array of
|
|
87
|
+
strings) replace the prompt copy the `todo` tool advertises to the model. Both
|
|
88
|
+
are absent by default, in which case the built-in snippet and the eight built-in
|
|
89
|
+
guideline bullets are used.
|
|
90
|
+
|
|
91
|
+
- `promptSnippet` must be a non-empty string; an empty string or a wrong type
|
|
92
|
+
falls back to the default.
|
|
93
|
+
- `promptGuidelines` must be a non-empty array of non-empty strings. A non-array,
|
|
94
|
+
or an array containing an empty string, falls back to the default — the array
|
|
95
|
+
is all-or-nothing, not merged item by item.
|
|
96
|
+
- Both are read at extension load, so `/reload` after editing them.
|
|
97
|
+
|
|
98
|
+
## Environment variables
|
|
99
|
+
|
|
100
|
+
| Variable | Effect |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| `XDG_CONFIG_HOME` | Relocates the config directory, as described above. |
|
|
103
|
+
| `HOME` | Anchors `~/.config` when `XDG_CONFIG_HOME` does not apply. |
|
|
104
|
+
|
|
105
|
+
`rpiv-todo` reads no environment variables of its own. If you have
|
|
106
|
+
[`@juicesharp/rpiv-i18n`](https://www.npmjs.com/package/@juicesharp/rpiv-i18n)
|
|
107
|
+
installed, that package has its own locale configuration and its own env-var
|
|
108
|
+
chain — see its README.
|
package/docs/overlay.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Overlay and `/todos` display
|
|
2
|
+
|
|
3
|
+
How
|
|
4
|
+
[`@juicesharp/rpiv-todo`](https://www.npmjs.com/package/@juicesharp/rpiv-todo)
|
|
5
|
+
renders the task list — when the overlay appears, what each glyph means, how
|
|
6
|
+
overflow is trimmed, and which strings localize.
|
|
7
|
+
|
|
8
|
+
## When the overlay exists
|
|
9
|
+
|
|
10
|
+
The widget is mounted above the Pi editor under the key `rpiv-todos`.
|
|
11
|
+
|
|
12
|
+
| Stage | Condition |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| Created | At the first session start that has a UI. A headless session never creates it. |
|
|
15
|
+
| Registered | Only while at least one overlay-visible task exists. The widget unregisters itself when the list empties, and re-registers when a task reappears. |
|
|
16
|
+
| Bound | Only the foreground session's overlay is refreshed. A detached or child session has its own task state and never rebinds or repaints the foreground panel. |
|
|
17
|
+
| Disposed | On the foreground session's shutdown. A child session shutting down leaves the overlay alone. |
|
|
18
|
+
|
|
19
|
+
Task state is partitioned by session id, so parallel sessions cannot read or
|
|
20
|
+
overwrite each other's lists. Nothing is written to disk: on session start,
|
|
21
|
+
compaction, and session-tree changes, the list is rebuilt by walking the branch
|
|
22
|
+
and taking the last `todo` tool result's snapshot, which replaces the whole list
|
|
23
|
+
(last-write-wins).
|
|
24
|
+
|
|
25
|
+
## Anatomy of a row
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
● Todos (2/5)
|
|
29
|
+
├─ ✓ Create DemoTodo domain entity
|
|
30
|
+
├─ ✓ Create IDemoTodoRepository interface
|
|
31
|
+
├─ ◐ Create DemoTodoRepository (creating the repository)
|
|
32
|
+
├─ ○ Register DI bindings
|
|
33
|
+
└─ ○ Add integration tests
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- **Heading** — `● Todos (done/total)` in the accent color while any task is
|
|
37
|
+
`pending` or `in_progress`; `○ Todos (done/total)` dimmed once everything is
|
|
38
|
+
completed.
|
|
39
|
+
- **Glyphs** — `○` pending, `◐` in_progress, `✓` completed, `✗` deleted.
|
|
40
|
+
Completed and deleted subjects render dim and struck through.
|
|
41
|
+
- **activeForm** — appended dim in parentheses, only while the task is
|
|
42
|
+
`in_progress`.
|
|
43
|
+
- **Dependencies** — appended as `⛓ #1,#2` when the task has a `blockedBy` set.
|
|
44
|
+
- **`#id` prefix** — shown on every row only when at least one visible task
|
|
45
|
+
carries a `blockedBy`. Without a `⛓ #N` anywhere, the per-row ids have nothing
|
|
46
|
+
to point at, so they are omitted.
|
|
47
|
+
- **Prefixes** — `├─` on each row, `└─` on the last one. A blank spacer line is
|
|
48
|
+
always appended below the panel so it is not flush against the input box.
|
|
49
|
+
|
|
50
|
+
Rows longer than the terminal width are truncated with `…`.
|
|
51
|
+
|
|
52
|
+
## Overflow
|
|
53
|
+
|
|
54
|
+
The content-row budget is `maxWidgetLines` (default `12`), and the heading counts
|
|
55
|
+
against it. When there are more tasks than fit:
|
|
56
|
+
|
|
57
|
+
1. one row is reserved for the summary line;
|
|
58
|
+
2. completed tasks are dropped first, newest first — the oldest completed rows
|
|
59
|
+
are the last completed rows to go;
|
|
60
|
+
3. if the unfinished tasks alone still overflow, the tail of that list is
|
|
61
|
+
truncated;
|
|
62
|
+
4. the last row becomes `+N more (X completed, Y pending)`.
|
|
63
|
+
|
|
64
|
+
Unfinished work is therefore the last thing to disappear. See
|
|
65
|
+
[configuration.md](./configuration.md#maxwidgetlines) for the budget's floor and
|
|
66
|
+
reload semantics.
|
|
67
|
+
|
|
68
|
+
## Completed tasks fading out
|
|
69
|
+
|
|
70
|
+
A completed task stays on screen for the remainder of the turn in which it was
|
|
71
|
+
completed. At the start of the next agent turn, every completed row that has
|
|
72
|
+
already been displayed is hidden from later renders. Reloading or compacting the
|
|
73
|
+
session resets that tracking, so a fresh session shows the full list again.
|
|
74
|
+
|
|
75
|
+
## Collapsing
|
|
76
|
+
|
|
77
|
+
Press `ctrl+shift+t` to collapse the panel to two lines — the heading plus a dim
|
|
78
|
+
`└─ ctrl+shift+t to expand` hint — and again to expand it. The hint always shows
|
|
79
|
+
the currently configured key.
|
|
80
|
+
|
|
81
|
+
Rebind or disable the shortcut with the `collapseKey` option; see
|
|
82
|
+
[configuration.md](./configuration.md#collapsekey). If the shortcut is set to
|
|
83
|
+
`"off"` while the panel is collapsed, the hint becomes a static `collapsed`
|
|
84
|
+
label rather than advertising an unbindable key.
|
|
85
|
+
|
|
86
|
+
## `/todos`
|
|
87
|
+
|
|
88
|
+
`/todos` prints the whole list grouped by status, independent of the overlay's
|
|
89
|
+
row budget and auto-hiding:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
2/7 completed · 1 in progress · 4 pending
|
|
93
|
+
── Pending ──
|
|
94
|
+
○ #4 Register DI bindings
|
|
95
|
+
○ #5 Add integration tests ⛓ #4
|
|
96
|
+
○ #6 Wire up the HTTP endpoint
|
|
97
|
+
○ #7 Update the API docs
|
|
98
|
+
── In Progress ──
|
|
99
|
+
◐ #3 Create DemoTodoRepository (creating the repository)
|
|
100
|
+
── Completed ──
|
|
101
|
+
✓ #1 Create DemoTodo domain entity
|
|
102
|
+
✓ #2 Create IDemoTodoRepository interface
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The header omits any count that is zero. Sections appear only when they have
|
|
106
|
+
tasks. Tombstoned tasks are never listed.
|
|
107
|
+
|
|
108
|
+
- With no tasks: `No todos yet. Ask the agent to add some!`
|
|
109
|
+
- In a non-interactive session: `/todos requires interactive mode`
|
|
110
|
+
|
|
111
|
+
## Localization
|
|
112
|
+
|
|
113
|
+
The overlay heading, the `+N more` summary, the collapse hint, the `/todos`
|
|
114
|
+
section headers, and the status words all localize through
|
|
115
|
+
[`@juicesharp/rpiv-i18n`](https://www.npmjs.com/package/@juicesharp/rpiv-i18n)
|
|
116
|
+
when that package is installed. Bundled locales: `de`, `en`, `es`, `fr`, `pt`,
|
|
117
|
+
`pt-BR`, `ru`, `uk`, `zh`.
|
|
118
|
+
|
|
119
|
+
LLM-facing output — the tool response envelope, reducer error messages, and the
|
|
120
|
+
schema descriptions — stays English by design.
|
|
121
|
+
|
|
122
|
+
The SDK is a soft optional peer, loaded through a dynamic import at module init.
|
|
123
|
+
When it is absent, every call site returns its inline English literal and the
|
|
124
|
+
extension stays online: no warning, no crash. Install it at any time with
|
|
125
|
+
`pi install npm:@juicesharp/rpiv-i18n` and restart the session. To add or
|
|
126
|
+
override a translation, drop a `locales/<code>.json` file mirroring `en.json` —
|
|
127
|
+
see the `@juicesharp/rpiv-i18n` README's "Contributing translations" section.
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# `todo` tool reference
|
|
2
|
+
|
|
3
|
+
Complete parameter schema, status machine, response envelope, and error strings
|
|
4
|
+
for the `todo` tool registered by
|
|
5
|
+
[`@juicesharp/rpiv-todo`](https://www.npmjs.com/package/@juicesharp/rpiv-todo).
|
|
6
|
+
|
|
7
|
+
## Actions
|
|
8
|
+
|
|
9
|
+
| Action | Required params | What it does |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `create` | `subject` | Adds a task in `pending`, assigns the next id. |
|
|
12
|
+
| `update` | `id` + at least one mutable field | Changes status, fields, or dependencies. |
|
|
13
|
+
| `list` | — | Returns all tasks, optionally filtered by `status`. |
|
|
14
|
+
| `get` | `id` | Returns one task with its `blockedBy` and reverse `blocks` edges. |
|
|
15
|
+
| `delete` | `id` | Tombstones the task (`status: "deleted"`); it is not removed. |
|
|
16
|
+
| `clear` | — | Drops every task and resets the id counter to `1`. |
|
|
17
|
+
|
|
18
|
+
## Parameters
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
todo({
|
|
22
|
+
action: "create" | "update" | "list" | "get" | "delete" | "clear",
|
|
23
|
+
|
|
24
|
+
// create-only
|
|
25
|
+
subject?: string, // required for create
|
|
26
|
+
blockedBy?: number[], // initial dependency ids
|
|
27
|
+
|
|
28
|
+
// create + update
|
|
29
|
+
description?: string, // long-form detail
|
|
30
|
+
activeForm?: string, // present-continuous label shown while in_progress
|
|
31
|
+
owner?: string, // agent/owner assigned to this task
|
|
32
|
+
metadata?: Record<string, unknown>, // on update, a null value deletes that key
|
|
33
|
+
|
|
34
|
+
// update-only
|
|
35
|
+
addBlockedBy?: number[], // additive merge into blockedBy
|
|
36
|
+
removeBlockedBy?: number[], // additive removal from blockedBy
|
|
37
|
+
|
|
38
|
+
// update / get / delete
|
|
39
|
+
id?: number,
|
|
40
|
+
|
|
41
|
+
// update (sets this task's status) or list (filters by status)
|
|
42
|
+
status?: "pending" | "in_progress" | "completed" | "deleted",
|
|
43
|
+
|
|
44
|
+
// list-only
|
|
45
|
+
includeDeleted?: boolean, // default false — hides tombstones
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`update` merges `metadata` key by key into the existing record; passing `null`
|
|
50
|
+
for a key removes it, and emptying the record drops the field entirely.
|
|
51
|
+
`addBlockedBy` and `removeBlockedBy` are additive — do not resend the whole
|
|
52
|
+
array.
|
|
53
|
+
|
|
54
|
+
## Status transitions
|
|
55
|
+
|
|
56
|
+
| From | Allowed targets |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| `pending` | `in_progress`, `completed`, `deleted` |
|
|
59
|
+
| `in_progress` | `pending`, `completed`, `deleted` |
|
|
60
|
+
| `completed` | `deleted` |
|
|
61
|
+
| `deleted` | _(terminal)_ |
|
|
62
|
+
|
|
63
|
+
A transition to the current status is always accepted and reported as a no-op.
|
|
64
|
+
`delete` keeps the task as a tombstone so historic `blockedBy` references still
|
|
65
|
+
resolve; tombstones are hidden from `list` unless you pass `includeDeleted: true`.
|
|
66
|
+
|
|
67
|
+
## Dependencies
|
|
68
|
+
|
|
69
|
+
`blockedBy` holds the ids this task waits on. Validation runs before the state
|
|
70
|
+
is mutated, so a rejected call leaves the list untouched:
|
|
71
|
+
|
|
72
|
+
- a dependency id that does not exist is rejected;
|
|
73
|
+
- a dependency that is already tombstoned is rejected;
|
|
74
|
+
- blocking a task on itself is rejected;
|
|
75
|
+
- an `addBlockedBy` that would close a cycle in the graph is rejected.
|
|
76
|
+
|
|
77
|
+
`get` also reports the reverse edges as a `blocks:` line, derived from the other
|
|
78
|
+
tasks' `blockedBy` arrays.
|
|
79
|
+
|
|
80
|
+
## Return envelope
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
{
|
|
84
|
+
content: [{ type: "text", text: string }], // human-readable summary of the op
|
|
85
|
+
details: { // full snapshot — replay reads this back
|
|
86
|
+
action: TaskAction,
|
|
87
|
+
params: Record<string, unknown>,
|
|
88
|
+
tasks: Array<{
|
|
89
|
+
id: number,
|
|
90
|
+
subject: string,
|
|
91
|
+
description?: string,
|
|
92
|
+
activeForm?: string,
|
|
93
|
+
status: "pending" | "in_progress" | "completed" | "deleted",
|
|
94
|
+
blockedBy?: number[],
|
|
95
|
+
owner?: string,
|
|
96
|
+
metadata?: Record<string, unknown>,
|
|
97
|
+
}>,
|
|
98
|
+
nextId: number,
|
|
99
|
+
error?: string, // present only on a rejected call
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`details` is the persistence format. Every successful call embeds the complete
|
|
105
|
+
post-mutation snapshot, and the session-lifecycle handlers rebuild state by
|
|
106
|
+
walking the branch and taking the last snapshot they find — which is why tasks
|
|
107
|
+
survive `/reload` and compaction without any disk writes.
|
|
108
|
+
|
|
109
|
+
## Content strings
|
|
110
|
+
|
|
111
|
+
| Situation | `content[0].text` |
|
|
112
|
+
| --- | --- |
|
|
113
|
+
| Created | `Created #3: Write the parser (pending)` |
|
|
114
|
+
| Updated with a status change | `Updated #3 (pending → in_progress)` |
|
|
115
|
+
| Updated without a status change | `Updated #3` |
|
|
116
|
+
| Update that changed nothing | `No change: #3 already matches the requested values (status: in_progress)` |
|
|
117
|
+
| Deleted | `Deleted #3: Write the parser` |
|
|
118
|
+
| Cleared | `Cleared 7 tasks` |
|
|
119
|
+
| `list` row | `[in_progress] #3 Write the parser (writing the parser) ⛓ #1,#2` |
|
|
120
|
+
| `list` with nothing to show | `No tasks` |
|
|
121
|
+
| Any rejection | `Error: <message>` |
|
|
122
|
+
|
|
123
|
+
The `No change` reply exists so a model that re-issues an identical update sees
|
|
124
|
+
that it was a no-op instead of a fresh `Updated #N`.
|
|
125
|
+
|
|
126
|
+
## Error messages
|
|
127
|
+
|
|
128
|
+
| Message | Cause |
|
|
129
|
+
| --- | --- |
|
|
130
|
+
| `subject required for create` | `create` without a non-blank `subject`. |
|
|
131
|
+
| `blockedBy: #N not found` | `create` naming an unknown dependency. |
|
|
132
|
+
| `blockedBy: #N is deleted` | `create` naming a tombstoned dependency. |
|
|
133
|
+
| `id required for update` / `get` / `delete` | `id` omitted. |
|
|
134
|
+
| `#N not found` | No task with that id. |
|
|
135
|
+
| `update requires at least one mutable field: subject, description, activeForm, status, owner, metadata, addBlockedBy, or removeBlockedBy` | `update` with only an `id`. |
|
|
136
|
+
| `illegal transition completed → in_progress` | Target status not reachable from the current one. |
|
|
137
|
+
| `cannot block #N on itself` | `addBlockedBy` includes the task's own id. |
|
|
138
|
+
| `addBlockedBy: #N not found` / `is deleted` | Unknown or tombstoned dependency. |
|
|
139
|
+
| `addBlockedBy would create a cycle in the blockedBy graph` | The edge would close a cycle. |
|
|
140
|
+
| `#N is already deleted` | `delete` on a tombstone. |
|
|
141
|
+
|
|
142
|
+
Errors are returned in-band: `content` carries `Error: …` and `details.error`
|
|
143
|
+
carries the bare message. Task state is unchanged.
|
|
144
|
+
|
|
145
|
+
## Prompt guidance
|
|
146
|
+
|
|
147
|
+
The tool ships a `promptSnippet` and eight `promptGuidelines` bullets telling the
|
|
148
|
+
model when to open a list, to keep exactly one task `in_progress`, to mark work
|
|
149
|
+
completed immediately rather than in batches, never to complete a task with
|
|
150
|
+
failing tests, and the literal `update {id, status}` call shape for changing a
|
|
151
|
+
task's status. Both are overridable — see
|
|
152
|
+
[configuration.md](./configuration.md#guidance).
|
package/index.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* correctly after upgrade.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
22
|
+
import type { ExtensionAPI, ExtensionUIContext } from "@earendil-works/pi-coding-agent";
|
|
23
23
|
import type { KeyId } from "@earendil-works/pi-tui";
|
|
24
24
|
import { COLLAPSE_KEY_OFF, resolveCollapseKey } from "./config.js";
|
|
25
25
|
import { I18N_NAMESPACE } from "./state/i18n-bridge.js";
|
|
@@ -28,17 +28,71 @@ import {
|
|
|
28
28
|
clearActiveRenderSession,
|
|
29
29
|
evictSession,
|
|
30
30
|
getActiveRenderSession,
|
|
31
|
+
getRenderState,
|
|
31
32
|
replaceState,
|
|
32
33
|
setActiveRenderSession,
|
|
33
34
|
sid,
|
|
34
35
|
} from "./state/store.js";
|
|
35
36
|
import { registerTodosCommand, registerTodoTool, TOOL_NAME } from "./todo.js";
|
|
36
|
-
import { TodoOverlay } from "./todo-overlay.js";
|
|
37
|
+
import type { TodoOverlay } from "./todo-overlay.js";
|
|
37
38
|
|
|
38
39
|
type I18nLoader = {
|
|
39
40
|
registerLocalesFromDir: (namespace: string, packageUrl: string, options?: { label?: string }) => void;
|
|
40
41
|
};
|
|
41
42
|
|
|
43
|
+
/** Delay the overlay graph pre-warm until Pi's startup work has settled. */
|
|
44
|
+
export const PREWARM_DELAY_MS = 2000;
|
|
45
|
+
|
|
46
|
+
type TodoOverlayModule = typeof import("./todo-overlay.js");
|
|
47
|
+
type TodoOverlayImporter = () => Promise<TodoOverlayModule>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Marker shared by the loader's poisoned-namespace error and the
|
|
51
|
+
* `isStaleOverlayModuleError` predicate that lets handlers re-throw it while
|
|
52
|
+
* swallowing transient load failures.
|
|
53
|
+
*/
|
|
54
|
+
const STALE_OVERLAY_MESSAGE = "Todo overlay module cache is stale; restart Pi";
|
|
55
|
+
|
|
56
|
+
/** True for the loader's latched poisoned-namespace error (see below). */
|
|
57
|
+
export function isStaleOverlayModuleError(e: unknown): boolean {
|
|
58
|
+
return String(e).includes(STALE_OVERLAY_MESSAGE);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Memoize the overlay graph after a successful load, but drop a rejected
|
|
63
|
+
* promise so a failed pre-warm does not permanently replay the same rejection.
|
|
64
|
+
* The export guard turns jiti's poisoned-namespace failure into a useful restart
|
|
65
|
+
* error instead of a bare "TodoOverlay is not a constructor" TypeError.
|
|
66
|
+
*/
|
|
67
|
+
export function makeTodoOverlayLoader(
|
|
68
|
+
importOverlay: TodoOverlayImporter = () => import("./todo-overlay.js"),
|
|
69
|
+
): TodoOverlayImporter {
|
|
70
|
+
let memo: Promise<TodoOverlayModule> | undefined;
|
|
71
|
+
|
|
72
|
+
return async (): Promise<TodoOverlayModule> => {
|
|
73
|
+
memo ??= importOverlay();
|
|
74
|
+
const current = memo;
|
|
75
|
+
let mod: TodoOverlayModule;
|
|
76
|
+
try {
|
|
77
|
+
mod = await current;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
// Clear only OUR rejected promise: a late catch from a concurrent
|
|
80
|
+
// awaiter must never clobber a fresh retry another caller installed.
|
|
81
|
+
if (memo === current) memo = undefined;
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
if (typeof mod.TodoOverlay !== "function") {
|
|
85
|
+
// Deliberately latched: the memo keeps this resolved-but-poisoned
|
|
86
|
+
// namespace, so every subsequent load re-throws instead of retrying.
|
|
87
|
+
// Re-importing would hand back the same cached jiti namespace — a
|
|
88
|
+
// retry can never heal this; only the restart the error asks for can.
|
|
89
|
+
const keys = JSON.stringify(Object.keys(mod));
|
|
90
|
+
throw new Error(`${STALE_OVERLAY_MESSAGE} (resolved namespace keys: ${keys})`);
|
|
91
|
+
}
|
|
92
|
+
return mod;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
42
96
|
// Dynamic import keeps `@juicesharp/rpiv-i18n` a soft optional peer: when the
|
|
43
97
|
// SDK is installed alongside this package the strings register and
|
|
44
98
|
// `/languages` flips them live; when it isn't, the import rejects here, we
|
|
@@ -60,9 +114,38 @@ function isStaleCtxError(e: unknown): boolean {
|
|
|
60
114
|
return /stale after session replacement/.test(String(e));
|
|
61
115
|
}
|
|
62
116
|
|
|
63
|
-
|
|
64
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Render a caught `unknown` as a human-readable message — the `instanceof Error`
|
|
119
|
+
* dance collapsed to one place. Local copy of the `formatError` in
|
|
120
|
+
* packages/rpiv-workflow/internal-utils.ts:56-58 (that module disclaims its
|
|
121
|
+
* public surface, so the cross-package import is not available). M2 boundary
|
|
122
|
+
* duplication: tracked as a documented-constant seam.
|
|
123
|
+
*/
|
|
124
|
+
function formatError(e: unknown): string {
|
|
125
|
+
return e instanceof Error ? e.message : String(e);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export default function (pi: ExtensionAPI, importOverlay: TodoOverlayImporter = () => import("./todo-overlay.js")) {
|
|
65
129
|
let todoOverlay: TodoOverlay | undefined;
|
|
130
|
+
const loadTodoOverlay = makeTodoOverlayLoader(importOverlay);
|
|
131
|
+
let uiCtx: ExtensionUIContext | undefined;
|
|
132
|
+
let lifecycleGeneration = 0;
|
|
133
|
+
|
|
134
|
+
async function updateTodoOverlay(
|
|
135
|
+
resetCompletedDisplayState = false,
|
|
136
|
+
generation = lifecycleGeneration,
|
|
137
|
+
): Promise<void> {
|
|
138
|
+
const hasVisibleTasks = getRenderState().tasks.some((task) => task.status !== "deleted");
|
|
139
|
+
if (!uiCtx || (!todoOverlay && !hasVisibleTasks)) return;
|
|
140
|
+
|
|
141
|
+
const { TodoOverlay } = await loadTodoOverlay();
|
|
142
|
+
if (generation !== lifecycleGeneration || !uiCtx) return;
|
|
143
|
+
|
|
144
|
+
todoOverlay ??= new TodoOverlay();
|
|
145
|
+
todoOverlay.setUICtx(uiCtx);
|
|
146
|
+
if (resetCompletedDisplayState) todoOverlay.resetCompletedDisplayState();
|
|
147
|
+
todoOverlay.update();
|
|
148
|
+
}
|
|
66
149
|
|
|
67
150
|
registerTodoTool(pi);
|
|
68
151
|
registerTodosCommand(pi);
|
|
@@ -71,10 +154,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
71
154
|
// factory scope from config (register-once contract: a config change needs
|
|
72
155
|
// `/reload` to re-bind, same as lane-switcher's env hotkey) and the binding is
|
|
73
156
|
// skipped entirely when collapseKey is "off". The handler closes over the
|
|
74
|
-
// closure-local `todoOverlay` by reference and re-reads it at fire time, so
|
|
75
|
-
//
|
|
76
|
-
// mode,
|
|
77
|
-
//
|
|
157
|
+
// closure-local `todoOverlay` by reference and re-reads it at fire time, so an
|
|
158
|
+
// overlay loaded after shortcut registration is picked up. No-op in headless
|
|
159
|
+
// mode, before the overlay has loaded, or when the widget isn't currently
|
|
160
|
+
// registered (auto-hidden on an empty list).
|
|
78
161
|
const collapseKey = resolveCollapseKey();
|
|
79
162
|
if (collapseKey !== COLLAPSE_KEY_OFF) {
|
|
80
163
|
pi.registerShortcut(collapseKey as KeyId, {
|
|
@@ -94,7 +177,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
94
177
|
// the replacement session's session_start replays it. Other errors are real replay
|
|
95
178
|
// bugs and must propagate. The render is sid-gated so a child never refreshes the
|
|
96
179
|
// foreground overlay.
|
|
97
|
-
const replayAndRefresh = (
|
|
180
|
+
const replayAndRefresh = async (
|
|
181
|
+
ctx: Parameters<typeof sid>[0] & Parameters<typeof replayFromBranch>[0],
|
|
182
|
+
): Promise<void> => {
|
|
98
183
|
let isForeground = false;
|
|
99
184
|
try {
|
|
100
185
|
const id = sid(ctx);
|
|
@@ -103,10 +188,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
103
188
|
} catch (e) {
|
|
104
189
|
if (!isStaleCtxError(e)) throw e;
|
|
105
190
|
}
|
|
106
|
-
if (isForeground)
|
|
107
|
-
todoOverlay?.resetCompletedDisplayState();
|
|
108
|
-
todoOverlay?.update();
|
|
109
|
-
}
|
|
191
|
+
if (isForeground) await updateTodoOverlay(true);
|
|
110
192
|
};
|
|
111
193
|
|
|
112
194
|
pi.on("session_start", async (_event, ctx) => {
|
|
@@ -124,23 +206,23 @@ export default function (pi: ExtensionAPI) {
|
|
|
124
206
|
}
|
|
125
207
|
if (!ctx.hasUI) return;
|
|
126
208
|
// First UI-bearing session_start claims the foreground (the interactive
|
|
127
|
-
// launcher, by spawn-ordering)
|
|
128
|
-
|
|
129
|
-
if (todoOverlay === undefined) {
|
|
130
|
-
todoOverlay = new TodoOverlay();
|
|
131
|
-
setActiveRenderSession(id);
|
|
132
|
-
}
|
|
209
|
+
// launcher, by spawn-ordering) without eagerly loading the overlay.
|
|
210
|
+
if (getActiveRenderSession() === "") setActiveRenderSession(id);
|
|
133
211
|
// Only the foreground re-binds/refreshes the shared overlay. A child
|
|
134
212
|
// (distinct sid) is skipped — does not rebind to a relay/stale ui.
|
|
135
213
|
if (id !== getActiveRenderSession()) return;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
214
|
+
const generation = ++lifecycleGeneration;
|
|
215
|
+
uiCtx = ctx.ui;
|
|
216
|
+
await updateTodoOverlay(true, generation);
|
|
139
217
|
});
|
|
140
218
|
|
|
141
|
-
pi.on("session_compact", async (_event, ctx) =>
|
|
219
|
+
pi.on("session_compact", async (_event, ctx) => {
|
|
220
|
+
await replayAndRefresh(ctx);
|
|
221
|
+
});
|
|
142
222
|
|
|
143
|
-
pi.on("session_tree", async (_event, ctx) =>
|
|
223
|
+
pi.on("session_tree", async (_event, ctx) => {
|
|
224
|
+
await replayAndRefresh(ctx);
|
|
225
|
+
});
|
|
144
226
|
|
|
145
227
|
pi.on("session_shutdown", async (_event, ctx) => {
|
|
146
228
|
// Best-effort sid: disposal can race a stale ctx (like compact). An
|
|
@@ -159,6 +241,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
159
241
|
// dispose the foreground's overlay. Only the foreground's own shutdown
|
|
160
242
|
// (or an unknown/stale sid) tears it down and clears the pointer.
|
|
161
243
|
if (s === "" || s === getActiveRenderSession()) {
|
|
244
|
+
// Invalidate pending imports before clearing the foreground binding so a
|
|
245
|
+
// replaced session cannot inherit the stale overlay or UI context.
|
|
246
|
+
lifecycleGeneration++;
|
|
247
|
+
uiCtx = undefined;
|
|
162
248
|
// `dispose()`'s first act is setWidget(KEY, undefined) on a possibly-stale
|
|
163
249
|
// ui proxy, which can throw. evictSession(s) above already deleted this
|
|
164
250
|
// slot, so leaving `activeRenderSession` pointing at it would resolve
|
|
@@ -177,9 +263,27 @@ export default function (pi: ExtensionAPI) {
|
|
|
177
263
|
// (branch is stale — message_end runs after tool_execution_end).
|
|
178
264
|
pi.on("tool_execution_end", async (event) => {
|
|
179
265
|
if (event.toolName !== TOOL_NAME || event.isError) return;
|
|
180
|
-
|
|
266
|
+
try {
|
|
267
|
+
await updateTodoOverlay();
|
|
268
|
+
} catch (e) {
|
|
269
|
+
// The tool itself succeeded — a transient overlay-load failure only
|
|
270
|
+
// costs this one refresh, and the loader's cleared memo lets the next
|
|
271
|
+
// update retry. Don't surface that as an extension error. The latched
|
|
272
|
+
// stale-namespace error still propagates: it never self-heals, and the
|
|
273
|
+
// user needs its restart guidance.
|
|
274
|
+
if (isStaleOverlayModuleError(e)) throw e;
|
|
275
|
+
console.warn(`[rpiv-todo] overlay refresh failed (will retry on next update): ${formatError(e)}`);
|
|
276
|
+
}
|
|
181
277
|
});
|
|
182
278
|
|
|
279
|
+
// Evaluate the lazy graph after startup while Pi's boot-time dependency paths
|
|
280
|
+
// are still stable. This loads no widget and constructs no overlay; those stay
|
|
281
|
+
// deferred until a foreground session has visible tasks. A rejected pre-warm
|
|
282
|
+
// is intentionally swallowed after loadTodoOverlay clears its memo, allowing
|
|
283
|
+
// the first real update to retry. unref avoids holding an embedder open.
|
|
284
|
+
const prewarmTimer = setTimeout(() => void loadTodoOverlay().catch(() => undefined), PREWARM_DELAY_MS);
|
|
285
|
+
prewarmTimer.unref?.();
|
|
286
|
+
|
|
183
287
|
pi.on("agent_start", async () => {
|
|
184
288
|
todoOverlay?.hideCompletedTasksFromPreviousTurn();
|
|
185
289
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-todo",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Pi extension. A todo list for the model, rendered as a live overlay that survives /reload and conversation compaction.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"todo.ts",
|
|
34
34
|
"todo-overlay.ts",
|
|
35
35
|
"LICENSE",
|
|
36
|
+
"docs/",
|
|
37
|
+
"!docs/*.png",
|
|
38
|
+
"!docs/*.jpg",
|
|
39
|
+
"!docs/*.svg",
|
|
36
40
|
"README.md",
|
|
37
41
|
"state/invariants.ts",
|
|
38
42
|
"state/i18n-bridge.ts",
|
|
@@ -63,7 +67,7 @@
|
|
|
63
67
|
}
|
|
64
68
|
},
|
|
65
69
|
"dependencies": {
|
|
66
|
-
"@juicesharp/rpiv-config": "^2.
|
|
70
|
+
"@juicesharp/rpiv-config": "^2.2.0",
|
|
67
71
|
"typebox": "^1.1.24"
|
|
68
72
|
}
|
|
69
73
|
}
|
package/state/state-reducer.ts
CHANGED
|
@@ -121,7 +121,11 @@ export function applyTaskMutation(state: TaskState, action: TaskAction, params:
|
|
|
121
121
|
params.metadata !== undefined ||
|
|
122
122
|
(params.addBlockedBy && params.addBlockedBy.length > 0) ||
|
|
123
123
|
(params.removeBlockedBy && params.removeBlockedBy.length > 0);
|
|
124
|
-
if (!hasMutation)
|
|
124
|
+
if (!hasMutation)
|
|
125
|
+
return errorResult(
|
|
126
|
+
state,
|
|
127
|
+
"update requires at least one mutable field: subject, description, activeForm, status, owner, metadata, addBlockedBy, or removeBlockedBy",
|
|
128
|
+
);
|
|
125
129
|
|
|
126
130
|
let newStatus = current.status;
|
|
127
131
|
if (params.status !== undefined) {
|
package/state/store.ts
CHANGED
|
@@ -13,9 +13,9 @@ const sessions = new Map<string, TaskState>();
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Ctx-less render pointer: which slot do the ctx-free readers (the overlay's
|
|
16
|
-
* `getSnapshot()`, the tool's `renderCall()`) render? Set
|
|
17
|
-
*
|
|
18
|
-
* see `index.ts`). A *distinct* concept from the three task-state mutation
|
|
16
|
+
* `getSnapshot()`, the tool's `renderCall()`) render? Set when the first UI
|
|
17
|
+
* session claims the foreground, before the overlay is loaded (creator-ownership
|
|
18
|
+
* — see `index.ts`). A *distinct* concept from the three task-state mutation
|
|
19
19
|
* seams; it is not a 4th writer of task state.
|
|
20
20
|
*/
|
|
21
21
|
let activeRenderSession = "";
|
|
@@ -91,7 +91,7 @@ export function getRenderState(): TaskState {
|
|
|
91
91
|
return slotFor(activeRenderSession);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/** Set the ctx-less render pointer
|
|
94
|
+
/** Set the ctx-less render pointer when the first UI session claims foreground. */
|
|
95
95
|
export function setActiveRenderSession(sessionId: string): void {
|
|
96
96
|
activeRenderSession = sessionId;
|
|
97
97
|
}
|
package/todo-overlay.ts
CHANGED
|
@@ -64,13 +64,13 @@ export class TodoOverlay {
|
|
|
64
64
|
if (!this.widgetRegistered) {
|
|
65
65
|
this.uiCtx.setWidget(
|
|
66
66
|
WIDGET_KEY,
|
|
67
|
-
(tui,
|
|
67
|
+
(tui, factoryTheme) => {
|
|
68
68
|
this.tui = tui;
|
|
69
69
|
return {
|
|
70
|
-
render: (width: number) => this.renderWidget(theme, width),
|
|
70
|
+
render: (width: number) => this.renderWidget(this.uiCtx?.theme ?? factoryTheme, width),
|
|
71
71
|
invalidate: () => {
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
// No rendered strings are cached. Pi invalidates on theme changes;
|
|
73
|
+
// the next render reads uiCtx.theme.
|
|
74
74
|
},
|
|
75
75
|
};
|
|
76
76
|
},
|
package/todo.ts
CHANGED
|
@@ -58,6 +58,7 @@ export const DEFAULT_PROMPT_GUIDELINES: string[] = [
|
|
|
58
58
|
"When starting any task, mark it in_progress BEFORE beginning work. Mark it completed IMMEDIATELY when done — never batch completions. Exactly one task should be in_progress at a time.",
|
|
59
59
|
"Never mark a task completed if tests are failing, the implementation is partial, or you hit unresolved errors — keep it in_progress and create a new task for the blocker instead.",
|
|
60
60
|
"Task status is a 4-state machine: pending → in_progress → completed, plus deleted as a tombstone. Pass activeForm (present-continuous label, e.g. 'researching existing tool') when marking in_progress.",
|
|
61
|
+
'To change a task\'s status, call update with the task id and the target status, e.g. {"action":"update","id":3,"status":"completed"} or {"action":"update","id":3,"status":"in_progress","activeForm":"writing tests"}. status is the field that changes the task; an update without a mutable field (status or another) is rejected.',
|
|
61
62
|
"Use blockedBy to express dependencies (A is blocked by B). On create, pass blockedBy as the initial set. On update, use addBlockedBy / removeBlockedBy (additive merge — do not resend the full array). Cycles are rejected.",
|
|
62
63
|
"list hides tombstoned (deleted) tasks by default; pass includeDeleted:true to see them. Pass status to filter by a single status.",
|
|
63
64
|
"Subject must be short and imperative (e.g. 'Research existing tool'); description is for long-form detail. activeForm is a present-continuous label shown while in_progress.",
|
package/tool/types.ts
CHANGED
|
@@ -89,7 +89,8 @@ export const TodoParamsSchema = Type.Object({
|
|
|
89
89
|
),
|
|
90
90
|
status: Type.Optional(
|
|
91
91
|
StringEnum(["pending", "in_progress", "completed", "deleted"] as const, {
|
|
92
|
-
description:
|
|
92
|
+
description:
|
|
93
|
+
"Set this task's status (update): one of pending, in_progress, completed, deleted. When action is list, filters returned tasks by this status.",
|
|
93
94
|
}),
|
|
94
95
|
),
|
|
95
96
|
blockedBy: Type.Optional(
|
package/view/format.ts
CHANGED
|
@@ -65,24 +65,25 @@ export function overlayStatusGlyph(status: TaskStatus, theme: Theme): string {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* Format a single task for the overlay
|
|
69
|
-
*
|
|
68
|
+
* Format a single task row for the persistent overlay. The subject color
|
|
69
|
+
* reflects task state while IDs and supporting metadata stay visually quiet.
|
|
70
70
|
*/
|
|
71
71
|
export function formatOverlayTaskLine(t: Task, theme: Theme, showId: boolean): string {
|
|
72
72
|
const glyph = overlayStatusGlyph(t.status, theme);
|
|
73
|
-
const subjectColor =
|
|
73
|
+
const subjectColor =
|
|
74
|
+
t.status === "in_progress" ? "accent" : t.status === "completed" || t.status === "deleted" ? "muted" : "text";
|
|
74
75
|
let subject = theme.fg(subjectColor, t.subject);
|
|
75
76
|
if (t.status === "completed" || t.status === "deleted") {
|
|
76
77
|
subject = theme.strikethrough(subject);
|
|
77
78
|
}
|
|
78
79
|
let line = `${glyph}`;
|
|
79
|
-
if (showId) line += ` ${theme.fg("
|
|
80
|
+
if (showId) line += ` ${theme.fg("dim", `#${t.id}`)}`;
|
|
80
81
|
line += ` ${subject}`;
|
|
81
82
|
if (t.status === "in_progress" && t.activeForm) {
|
|
82
|
-
line += ` ${theme.fg("
|
|
83
|
+
line += ` ${theme.fg("muted", `(${t.activeForm})`)}`;
|
|
83
84
|
}
|
|
84
85
|
if (t.blockedBy && t.blockedBy.length > 0) {
|
|
85
|
-
line += ` ${theme.fg("
|
|
86
|
+
line += ` ${theme.fg("muted", `⛓ ${t.blockedBy.map((id) => `#${id}`).join(",")}`)}`;
|
|
86
87
|
}
|
|
87
88
|
return line;
|
|
88
89
|
}
|