pi-todo-ledger 0.7.4 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRACT.md +14 -0
- package/README.md +7 -3
- package/docs/overlay.md +59 -17
- package/docs/tool-schema.md +20 -6
- package/package.json +1 -1
- package/src/ledger/finish-call.ts +1 -1
- package/src/ledger/namespaces.ts +18 -4
- package/src/state/selectors.ts +0 -35
- package/src/state/state-reducer.ts +16 -2
- package/src/state/wait-mark.ts +60 -0
- package/src/todo-overlay.ts +162 -97
- package/src/todo.ts +1 -0
- package/src/tool/types.ts +16 -0
- package/src/view/task-labels.ts +4 -7
package/CONTRACT.md
CHANGED
|
@@ -152,6 +152,20 @@ Error: metadata.<ns> refused #<id>: <reason>
|
|
|
152
152
|
`clear`, `list`, and `get` run no validators.
|
|
153
153
|
Namespaces nobody registered pass unchecked.
|
|
154
154
|
|
|
155
|
+
### Wait marks (`metadata.waitsOn`, `metadata.until`)
|
|
156
|
+
|
|
157
|
+
Since 0.8.0 the `todo` tool's `waitsOn` and `until` fields write these two top-level metadata keys; earlier releases already read them, and an agent may still set them through `metadata`.
|
|
158
|
+
|
|
159
|
+
| Key | Type | Meaning |
|
|
160
|
+
| --- | --- | --- |
|
|
161
|
+
| `waitsOn` | non-empty string | What the task waits on: a person, CI, a train to end. |
|
|
162
|
+
| `until` | ISO 8601 date or date-time | When the task waits until: `YYYY-MM-DD`, optionally `THH:MM`, seconds, fraction, and `Z` or an offset, on a real calendar day. Another form marks no wait. |
|
|
163
|
+
|
|
164
|
+
A task waits while its `status` is `pending` or `in_progress` and either `waitsOn` is a non-blank string or `until` is a time after now.
|
|
165
|
+
A reader that judges open work, such as a close or stale reminder, treats a waiting task as held up rather than forgotten.
|
|
166
|
+
An `update` to `completed` or `deleted`, and `delete`, remove both keys; a namespace validator registered for a key the task had sees the removal. A validator for a wait key follows the general rule in [Namespaces](#3-namespaces): it runs when the task carries the key after the change, or when the call sets the key or removes one the task had; ending the wait of a task that never had a key does not run that key's validator.
|
|
167
|
+
The snapshot version stays 1.
|
|
168
|
+
|
|
155
169
|
### Optional Herdr launch identity (`metadata.herdr`)
|
|
156
170
|
|
|
157
171
|
When `pi-herdr-agents` acknowledges a `subagent` launch with `details.status: "started"` and echoes the call's `item`, the ledger looks up that task in the **calling session**.
|
package/README.md
CHANGED
|
@@ -55,9 +55,13 @@ The panel claims every run row it paints, so the host's Subagents box shows only
|
|
|
55
55
|
See [docs/overlay.md](docs/overlay.md#other-workers).
|
|
56
56
|
|
|
57
57
|
`/todos` and the panel's full view indent each open task under its first unfinished blocker; the panel's default focus view lists tasks flat and names every unfinished blocker after the subject. Both show the owner as `@owner`.
|
|
58
|
-
To mark a task as waiting
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
To mark a task as waiting, pass `waitsOn` with what it waits on (a person, CI, `trains to end`); to defer it until a particular time, pass `until` with an ISO timestamp, e.g. `2027-01-15T09:00:00+08:00`.
|
|
59
|
+
`create` and `update` take both, `update` with `null` clears one, and completing or deleting the task clears both.
|
|
60
|
+
They are stored as `metadata.waitsOn` and `metadata.until`, which earlier releases already read, so setting those keys directly still works.
|
|
61
|
+
An open task shows `⏸` with what it waits on or the future deadline in local time.
|
|
62
|
+
A wait neither schedules a wake-up nor changes the task's `status`; it tells readers such as anchorloop's close guard and sb's board that the task is held up, not forgotten.
|
|
63
|
+
A wait with only `until` ends when that time passes; a `waitsOn` wait lasts until it is cleared, so to end a wait early clear both fields you set.
|
|
64
|
+
`until` takes an ISO date or date-time with a `T` on a real calendar day, the form pi-straw-boss reads; `2099-02-30` and `2099-12-01 09:00` are refused, and such a value written straight into metadata does not mark the task as waiting.
|
|
61
65
|
|
|
62
66
|
`graph` names the work graph of the plan a task belongs to, one of `single-loop`, `fan-out/fan-in`, and `orchestrator-worker`; any other value is refused.
|
|
63
67
|
One session often runs several plans, so each task carries its own.
|
package/docs/overlay.md
CHANGED
|
@@ -34,18 +34,18 @@ The panel opens in the focus view. It shows what is being worked on and what com
|
|
|
34
34
|
└─ +5 待處理 · ctrl+shift+t 完整
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
Rows
|
|
37
|
+
Rows are drawn in this order:
|
|
38
38
|
|
|
39
39
|
1. the heading;
|
|
40
40
|
2. every task in progress, each followed by its run rows;
|
|
41
41
|
3. the next two open tasks in display order, or the next three when nothing is in progress;
|
|
42
|
-
4.
|
|
43
|
-
5.
|
|
42
|
+
4. completed tasks from the current turn;
|
|
43
|
+
5. the [Other workers](#other-workers) group;
|
|
44
44
|
6. one summary row counting the hidden tasks in progress, pending, and completed, then the hidden other workers, in that order, such as `+1 in progress, 5 pending, 2 completed, 2 workers` (`+1 進行中、5 待處理、2 已完成、2 worker` in zh-TW). Zero counts are left out, and with nothing hidden there is no summary row.
|
|
45
45
|
|
|
46
46
|
The summary row ends with a dim hint that names the panel key and the state it switches to next; see [Switching views](#switching-views).
|
|
47
47
|
|
|
48
|
-
`maxWidgetLines` is a hard cap here too: tasks in progress that do not fit are counted in the summary, and run rows that do not fit fold into `· N runs`.
|
|
48
|
+
`maxWidgetLines` is a hard cap here too. Rows 2 to 5 share the budget by [rank](#overflow): run rows and the group come before the next open tasks, tasks in progress that do not fit are counted in the summary, and run rows that do not fit fold into `· N runs`.
|
|
49
49
|
Rows are flat, so the `⛓` tail lists every unfinished blocker of a task; `⏸`, owners, and the other marks are the same as in the full view.
|
|
50
50
|
Pi's tool-output expansion mode lifts the row cap but keeps this selection. Press the panel key for the tree below, set `"view": "full"` (see [configuration.md](./configuration.md#view)) to start there, or use `/todos` to see everything once.
|
|
51
51
|
|
|
@@ -70,7 +70,7 @@ The full view (`"view": "full"`) draws the whole dependency tree:
|
|
|
70
70
|
Completed and deleted subjects render dim and struck through.
|
|
71
71
|
- **activeForm** — appended dim in parentheses, only while the task is
|
|
72
72
|
`in_progress` and only when it differs from the subject (ignoring leading and trailing spaces).
|
|
73
|
-
- **Waiting** — `⏸` replaces the open-task glyph when `metadata.waitsOn` names a party or `metadata.until` is an ISO time in the future. The row shows the party, the local deadline, or both. An elapsed deadline no longer marks a task as waiting.
|
|
73
|
+
- **Waiting** — `⏸` replaces the open-task glyph when `metadata.waitsOn` names a party or `metadata.until` is an ISO time in the future (the `todo` fields `waitsOn` and `until` write these keys). The row shows the party, the local deadline, or both. An elapsed deadline no longer marks a task as waiting.
|
|
74
74
|
- **Owner** — `@owner` follows the subject in muted text.
|
|
75
75
|
- **Dependencies** — open rows nest under the first unfinished `blockedBy` id; siblings are visited in id order. Other unfinished blockers appear in the `⛓ #1,#2` tail. If another prerequisite interrupts a branch, `↳ #N` names the parent the row returns to.
|
|
76
76
|
- **Graph** — the heading names the graph when all open tasks share it; otherwise a root shows its own graph, if set.
|
|
@@ -127,8 +127,8 @@ The group follows the task rows. It includes unbound runs and runs whose task is
|
|
|
127
127
|
|
|
128
128
|
The group follows the row budget:
|
|
129
129
|
|
|
130
|
-
- In
|
|
131
|
-
-
|
|
130
|
+
- In both views, tasks in progress and their runs come first, then the group, then the pending and completed tasks without a live run (see [Overflow](#overflow)). The group gets its heading and as many runs as fit, or nothing when fewer than two rows are left.
|
|
131
|
+
- The runs that do not fit are added to the summary row as `+2 workers` (`+2 worker` in zh-TW), or after the task counts, as in `+5 待處理、2 worker` in the focus view and `+3 more (3 pending), 2 workers` in the full view.
|
|
132
132
|
- In the collapsed view, the closing row counts the group before the key hint: `└─ +2 worker · ctrl+shift+t 焦點`.
|
|
133
133
|
|
|
134
134
|
The panel claims a group row the way it claims a bound run row: only a row painted in full, checked by its exact line in the fullscreen layout. A row cut by the width, clipped by the layout, covered by a popup, or folded into the summary stays unclaimed, so the Subagents widget keeps showing that run. When no ledger claims a run, the host's own widget is the fallback that shows it.
|
|
@@ -136,20 +136,62 @@ The panel claims a group row the way it claims a bound run row: only a row paint
|
|
|
136
136
|
## Overflow
|
|
137
137
|
|
|
138
138
|
The content-row budget is `maxWidgetLines` (default `12`), and the heading counts
|
|
139
|
-
against it.
|
|
140
|
-
|
|
139
|
+
against it. When the rows do not all fit, one row is reserved for the summary,
|
|
140
|
+
and both views hand out the rest by rank, in display order within each rank:
|
|
141
141
|
|
|
142
|
-
1.
|
|
143
|
-
2.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
4.
|
|
142
|
+
1. task rows of the tasks in progress;
|
|
143
|
+
2. live run rows, all runs of one task together, with that task's row when it has
|
|
144
|
+
none yet; a task in progress whose runs do not fit keeps its row and shows
|
|
145
|
+
`· N runs`;
|
|
146
|
+
3. the [Other workers](#other-workers) group, holding the live runs whose task got no row;
|
|
147
|
+
4. open tasks with no live run;
|
|
148
|
+
5. completed tasks with no live run, oldest first.
|
|
149
|
+
|
|
150
|
+
Rows keep their display order whatever their rank: the full view still draws the
|
|
151
|
+
tree, and the focus view its flat list. The focus view ranks only the tasks it
|
|
152
|
+
selects (in progress, the next open ones, and this turn's completed ones). In the
|
|
153
|
+
full view the last row becomes `+N more (X completed, Y in progress, Z pending)`,
|
|
154
|
+
leaving out zero counts.
|
|
155
|
+
|
|
156
|
+
Ranking run rows above open tasks keeps the workers under their todos, so the
|
|
157
|
+
panel can claim them and the Subagents widget lists only what is left.
|
|
158
|
+
|
|
159
|
+
### Compact mode
|
|
160
|
+
|
|
161
|
+
When some live run would still get no row of its own, the panel switches to
|
|
162
|
+
compact mode for that frame. A task's runs then share the task's row, and the
|
|
163
|
+
Other workers group takes one row:
|
|
164
|
+
|
|
165
|
+
```text
|
|
166
|
+
● Todos (54/71)
|
|
167
|
+
├─ ◐ #35 Final BitD UAT round for the boss
|
|
168
|
+
├─ ◐ #55 S3 地圖 tab on core Table Maps, BitD map retired ⟶ coremaptab-ui · opus · 執行中 4m
|
|
169
|
+
├─ ○ #57 S4 map ports + two-way claims ↔ turf sync
|
|
170
|
+
├─ ◐ #56 F1 faction tracker storage (migration 198) ⟶ factionsdb-build · opus · 執行中 21m
|
|
171
|
+
├─ ◐ #65 EP sheet: centering, morph grid, 更換義體, Select, pictures
|
|
172
|
+
├─ ◐ #66 Site-wide: native selects → shared Select, then lint guard ⟶ selectsweep-ui · opus · 執行中 39m
|
|
173
|
+
├─ ◐ #67 EP rules book: add Flexbot Confidential + Rules Primer; Flexbot … ⟶ epbooks-build · opus · 執行中 30m
|
|
174
|
+
├─ ◐ #68 EP scenarios: 心智獵人, 小心WMD, 異噬, 超企業劫案, 奈米任務 ⟶ epscen-review · opus · 審查中 6m +2
|
|
175
|
+
├─ ◐ #70 Table session: reading dialogs dock to the workspace pane, chat stays usable
|
|
176
|
+
├─ 其他 worker ⟶ skald-scout · opus · 執行中 3m +1
|
|
177
|
+
└─ +62 項未顯示 (54 已完成, 8 待處理) · ctrl+shift+t 收合
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
- After ` ⟶ ` comes the most active run (working, then waiting for a reply, then
|
|
181
|
+
other states, idle last; the host's order breaks ties), in the run row format,
|
|
182
|
+
then `+N` for the task's other live runs.
|
|
183
|
+
- A narrow row cuts the task part with `…` first, so the run stays whole.
|
|
184
|
+
- The ranks above still apply; runs simply cost no rows, and the group costs one.
|
|
185
|
+
A task with no live run keeps its plain row.
|
|
186
|
+
- A compact row painted in full claims every run it stands for, `+N` included,
|
|
187
|
+
through the same inline or screen check as a run row. A row cut into its run,
|
|
188
|
+
or with fewer than 12 columns left for the task, claims none.
|
|
189
|
+
- When every run fits on its own row, the panel keeps the two-row layout.
|
|
148
190
|
|
|
149
191
|
In the full view, Pi's tool-output expansion shortcut (`ctrl+o` by default)
|
|
150
192
|
expands the widget to show every task. Collapsing Pi's tool output reapplies the configured
|
|
151
|
-
row budget. Unfinished work is therefore the last thing to disappear
|
|
152
|
-
|
|
193
|
+
row budget. Unfinished work is therefore the last thing to disappear under the
|
|
194
|
+
row budget. See [configuration.md](./configuration.md#maxwidgetlines) for the
|
|
153
195
|
budget's floor and reload semantics.
|
|
154
196
|
|
|
155
197
|
## Completed tasks fading out
|
package/docs/tool-schema.md
CHANGED
|
@@ -39,6 +39,8 @@ todo({
|
|
|
39
39
|
anchor?: string,
|
|
40
40
|
graph?: string,
|
|
41
41
|
evidence?: Evidence[],
|
|
42
|
+
waitsOn?: string,
|
|
43
|
+
until?: string,
|
|
42
44
|
}>,
|
|
43
45
|
|
|
44
46
|
// create + update
|
|
@@ -56,6 +58,8 @@ todo({
|
|
|
56
58
|
result: "pass" | "fail",
|
|
57
59
|
at?: string, // ISO 8601; stored in UTC; defaults to the time of the call
|
|
58
60
|
}>,
|
|
61
|
+
waitsOn?: string | null, // what the task waits on; stored as metadata.waitsOn; null clears (update only)
|
|
62
|
+
until?: string | null, // future ISO 8601 date or time; stored as metadata.until; null clears (update only)
|
|
59
63
|
|
|
60
64
|
// update-only
|
|
61
65
|
addBlockedBy?: number[], // additive merge into blockedBy
|
|
@@ -75,7 +79,7 @@ todo({
|
|
|
75
79
|
`create` takes either `subject` (one task) or `tasks[]` (several independent
|
|
76
80
|
tasks). Passing both is rejected, even with a blank `subject`. Each item carries
|
|
77
81
|
its own `description`, `activeForm`, `blockedBy`, `owner`, `metadata`, `points`,
|
|
78
|
-
`anchor`, `graph` and `
|
|
82
|
+
`anchor`, `graph`, `evidence`, `waitsOn` and `until`; the same
|
|
79
83
|
fields at the top level of a batch are rejected rather than dropped. The batch is validated first and committed
|
|
80
84
|
together: one bad item fails the whole call and leaves the list unchanged.
|
|
81
85
|
Items in `tasks[]` cannot `blockedBy` each other; those ids do not exist until
|
|
@@ -98,6 +102,14 @@ with a `metadata.graph` that holds a graph name, so a reload does not bring it b
|
|
|
98
102
|
On replay and import, a task without `graph` whose `metadata.graph` holds one of
|
|
99
103
|
these names is read with that graph; its metadata is kept as it was.
|
|
100
104
|
|
|
105
|
+
`waitsOn` and `until` mark an open task as waiting. They write `metadata.waitsOn`
|
|
106
|
+
(trimmed) and `metadata.until` (as given), the keys the panel, `/todos`, and other
|
|
107
|
+
extensions read, so the snapshot keeps its v1 shape; like `graph`, their schema admits
|
|
108
|
+
`null`, which on `update` removes the key. They apply after `metadata`, so they win
|
|
109
|
+
over the same key passed there. `until` must be an ISO 8601 date or date-time (`T` between them, hours 00 to 23) on a
|
|
110
|
+
real calendar day, after the call; to end a wait early, clear both keys that are set. Setting `status` to `completed` or `deleted`, or `delete`, removes both
|
|
111
|
+
keys, however they were written.
|
|
112
|
+
|
|
101
113
|
`import` reads `{ "v": 1, "tasks": [...], "nextId": n }` from a JSON file and keeps every task field as stored.
|
|
102
114
|
With `session` instead of `path`, it reads the newest valid `todo/v1` entry on the
|
|
103
115
|
current branch (the one ending at the last entry) of another session's file. A
|
|
@@ -217,17 +229,18 @@ that it was a no-op instead of a fresh `Updated #N`.
|
|
|
217
229
|
| `subject required for create` | `create` without a non-blank `subject` and without `tasks[]`. |
|
|
218
230
|
| `create requires subject or tasks[], not both` | `create` with both `subject` and `tasks[]`. |
|
|
219
231
|
| `tasks[] must be non-empty` | `create` with `tasks: []`. |
|
|
220
|
-
| `create with tasks[] takes <fields> on each item, not at the top level` | `create` with `tasks[]` and a top-level `description`, `activeForm`, `blockedBy`, `owner`, `metadata`, `points`, `anchor`, `graph`, or `
|
|
232
|
+
| `create with tasks[] takes <fields> on each item, not at the top level` | `create` with `tasks[]` and a top-level `description`, `activeForm`, `blockedBy`, `owner`, `metadata`, `points`, `anchor`, `graph`, `evidence`, `waitsOn`, or `until`. |
|
|
221
233
|
| `tasks[N]: subject required for create` | A batch item with a blank or missing subject. |
|
|
222
234
|
| `blockedBy: #N not found` | `create` naming an unknown dependency. |
|
|
223
235
|
| `blockedBy: #N is deleted` | `create` naming a tombstoned dependency. |
|
|
224
236
|
| `blockedBy: #N is another item in this batch; create the prerequisite first, then the dependent with blockedBy` | A `tasks[]` item naming a sibling that this call would assign. |
|
|
225
237
|
| `id required for update` / `get` / `delete` | `id` omitted. |
|
|
226
238
|
| `#N not found` | No task with that id. |
|
|
227
|
-
| `update requires at least one mutable field: subject, description, activeForm, status, owner, metadata, points, anchor, graph, evidence, addBlockedBy, or removeBlockedBy` | `update` with only an `id`. |
|
|
239
|
+
| `update requires at least one mutable field: subject, description, activeForm, status, owner, metadata, points, anchor, graph, evidence, waitsOn, until, addBlockedBy, or removeBlockedBy` | `update` with only an `id`. |
|
|
228
240
|
| `points must be a number from 0 to 10` | `points` out of range; prefixed `tasks[N]: ` for a batch item. |
|
|
229
241
|
| `anchor must be a non-empty string` | Blank `anchor`. |
|
|
230
242
|
| `graph must be single-loop, fan-out/fan-in, or orchestrator-worker` | Any other `graph`, or `null` on create; on update the message adds ` (null clears)`; prefixed `tasks[N]: ` for a batch item. |
|
|
243
|
+
| `waitsOn must be a non-empty string` / `until must be an ISO 8601 date or time` / `until must be in the future` | A blank `waitsOn`, an `until` that is not an ISO date or date-time or not after the call, or `null` on create; on update the first two add ` (null clears)`; prefixed `tasks[N]: ` for a batch item. |
|
|
231
244
|
| `path or session required for import` / `import takes path or session, not both` | `import` with neither or both. |
|
|
232
245
|
| `no session <id> in <dirs>` / `session <id> is ambiguous: <ids>` / `session <id> has no todo/v1 snapshot` | `import` with a `session` that matches no session, several, or one without a snapshot (flagged `isError`, like every import failure). |
|
|
233
246
|
| `evidence[N]: command must be a non-empty string` / `result must be "pass" or "fail"` / `sha must be a string` / `at must be an ISO 8601 time` / `at must not be in the future` | A malformed evidence item; `at` may lie at most five minutes after the call. |
|
|
@@ -248,11 +261,12 @@ rejections keep rpiv-todo's behaviour and are not flagged.
|
|
|
248
261
|
|
|
249
262
|
## Prompt guidance
|
|
250
263
|
|
|
251
|
-
The tool ships a `promptSnippet` and
|
|
264
|
+
The tool ships a `promptSnippet` and twelve `promptGuidelines` bullets telling the
|
|
252
265
|
model when to open a list, to create independent tasks in one `tasks[]` call,
|
|
253
266
|
to keep exactly one task `in_progress`, to mark work completed immediately
|
|
254
267
|
rather than in batches, never to complete a task with failing tests, and the
|
|
255
|
-
literal `update {id, status}` call shape for changing a task's status; the
|
|
256
|
-
describes `points`, `anchor`, and `evidence
|
|
268
|
+
literal `update {id, status}` call shape for changing a task's status; the
|
|
269
|
+
eleventh describes `points`, `anchor`, and `evidence`, and the twelfth how to mark
|
|
270
|
+
a task waiting with `waitsOn` and `until`. Both are
|
|
257
271
|
overridable — see
|
|
258
272
|
[configuration.md](./configuration.md#guidance).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-todo-ledger",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "A todo list for pi agents with a public bookkeeping contract: snapshot entries, change events, and namespace validators. Fork of @juicesharp/rpiv-todo",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@ export function makeFinishCall(pi: ExtensionAPI, namespaces: NamespaceRegistry,
|
|
|
31
31
|
commitState(sessionId, result.state);
|
|
32
32
|
return buildToolResult(action, input, result.state, result.op);
|
|
33
33
|
}
|
|
34
|
-
const refusal = namespaces.check(changedTasks(result.op, input, result.state)) ?? (await guards.check(guardChange));
|
|
34
|
+
const refusal = namespaces.check(changedTasks(result.op, input, result.state, before)) ?? (await guards.check(guardChange));
|
|
35
35
|
if (refusal) return refuse(action, input, before, refusal);
|
|
36
36
|
if (signal?.aborted) return refuse(action, input, before, ABORTED);
|
|
37
37
|
// Append before committing the live slot; even nested tool calls survive replay, and a failed append changes nothing.
|
package/src/ledger/namespaces.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { Op } from "../state/state-reducer.ts";
|
|
9
|
+
import { WAIT_KEYS } from "../state/wait-mark.ts";
|
|
9
10
|
import type { TaskState } from "../state/state.ts";
|
|
10
11
|
import type { Task, TaskMutationParams } from "../tool/types.ts";
|
|
11
12
|
import { CONTRACT_VERSION, type NamespaceOp, type NamespaceValidator, NAMESPACE_EVENT } from "./contract.ts";
|
|
@@ -25,13 +26,25 @@ function metadataKeys(value: unknown): string[] {
|
|
|
25
26
|
return isRecord(value) ? Object.keys(value) : [];
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* The wait keys a call sets through its `waitsOn` and `until` fields, and those it removes: a `null`, or the end of the wait
|
|
31
|
+
* (`ends`), removes a key only when the task had it (`had`).
|
|
32
|
+
*/
|
|
33
|
+
function waitKeys(spec: unknown, had: Record<string, unknown> | undefined = undefined, ends = false): string[] {
|
|
34
|
+
return WAIT_KEYS.filter((key) => {
|
|
35
|
+
const value = isRecord(spec) ? spec[key] : undefined;
|
|
36
|
+
return typeof value === "string" || ((value === null || ends) && had !== undefined && key in had);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
28
40
|
/**
|
|
29
41
|
* The tasks a committed `op` would create, update, or delete, read from the
|
|
30
42
|
* reducer's proposed state. Reads, `clear`, errors, and no-effect updates
|
|
31
43
|
* change no task and run no validator.
|
|
32
44
|
*/
|
|
33
|
-
export function changedTasks(op: Op, params: TaskMutationParams, next: TaskState): TaskChange[] {
|
|
45
|
+
export function changedTasks(op: Op, params: TaskMutationParams, next: TaskState, before?: TaskState): TaskChange[] {
|
|
34
46
|
const find = (id: number) => next.tasks.find((t) => t.id === id);
|
|
47
|
+
const had = (id: number) => before?.tasks.find((t) => t.id === id)?.metadata;
|
|
35
48
|
switch (op.kind) {
|
|
36
49
|
case "import":
|
|
37
50
|
return next.tasks.map((task) => ({ task, op: "create", touched: [] }));
|
|
@@ -40,16 +53,17 @@ export function changedTasks(op: Op, params: TaskMutationParams, next: TaskState
|
|
|
40
53
|
return op.taskIds.flatMap((id, i) => {
|
|
41
54
|
const task = find(id);
|
|
42
55
|
const spec = items ? items[i] : params;
|
|
43
|
-
return task ? [{ task, op: "create" as const, touched: metadataKeys(spec?.metadata) }] : [];
|
|
56
|
+
return task ? [{ task, op: "create" as const, touched: [...metadataKeys(spec?.metadata), ...waitKeys(spec)] }] : [];
|
|
44
57
|
});
|
|
45
58
|
}
|
|
46
59
|
case "update": {
|
|
47
60
|
const task = op.changed ? find(op.id) : undefined;
|
|
48
|
-
|
|
61
|
+
const ends = op.toStatus === "completed" || op.toStatus === "deleted";
|
|
62
|
+
return task ? [{ task, op: "update", touched: [...metadataKeys(params.metadata), ...waitKeys(params, had(op.id), ends)] }] : [];
|
|
49
63
|
}
|
|
50
64
|
case "delete": {
|
|
51
65
|
const task = find(op.id);
|
|
52
|
-
return task ? [{ task, op: "delete", touched:
|
|
66
|
+
return task ? [{ task, op: "delete", touched: waitKeys(params, had(op.id), true) }] : [];
|
|
53
67
|
}
|
|
54
68
|
case "list":
|
|
55
69
|
case "get":
|
package/src/state/selectors.ts
CHANGED
|
@@ -60,41 +60,6 @@ export function selectTaskSubjectById(state: TaskState, id: number): string | un
|
|
|
60
60
|
return state.tasks.find((t) => t.id === id)?.subject;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
* Overlay layout decision. Encapsulates the "drop completed first, then
|
|
65
|
-
* truncate non-completed tail" rule. `budget` is the body-slot count (caller passes
|
|
66
|
-
* `getMaxWidgetLines() - 1` to reserve the heading row); on overflow the
|
|
67
|
-
* selector reserves one more slot internally for the summary row. Returns
|
|
68
|
-
* the visible task slice plus the overflow summary parts.
|
|
69
|
-
*/
|
|
70
|
-
export interface OverlayLayout {
|
|
71
|
-
visible: readonly Task[];
|
|
72
|
-
hiddenCompleted: number;
|
|
73
|
-
truncatedTail: number;
|
|
74
|
-
}
|
|
75
|
-
export function selectOverlayLayout(state: TaskState, budget: number): OverlayLayout {
|
|
76
|
-
const all = selectVisibleTasks(state);
|
|
77
|
-
if (all.length <= budget) {
|
|
78
|
-
return { visible: all, hiddenCompleted: 0, truncatedTail: 0 };
|
|
79
|
-
}
|
|
80
|
-
const innerBudget = budget - 1;
|
|
81
|
-
const nonCompleted = all.filter((t) => t.status !== "completed");
|
|
82
|
-
const totalCompleted = all.length - nonCompleted.length;
|
|
83
|
-
if (nonCompleted.length <= innerBudget) {
|
|
84
|
-
const kept = new Set<Task>(nonCompleted);
|
|
85
|
-
for (const t of all) {
|
|
86
|
-
if (kept.size >= innerBudget) break;
|
|
87
|
-
if (t.status === "completed") kept.add(t);
|
|
88
|
-
}
|
|
89
|
-
const visible = all.filter((t) => kept.has(t));
|
|
90
|
-
const shownCompleted = visible.filter((t) => t.status === "completed").length;
|
|
91
|
-
return { visible, hiddenCompleted: totalCompleted - shownCompleted, truncatedTail: 0 };
|
|
92
|
-
}
|
|
93
|
-
const visible = nonCompleted.slice(0, innerBudget);
|
|
94
|
-
const truncatedTail = nonCompleted.length - innerBudget;
|
|
95
|
-
return { visible, hiddenCompleted: totalCompleted, truncatedTail };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
63
|
/**
|
|
99
64
|
* Helper: whether any visible task is `pending` or `in_progress`. The overlay
|
|
100
65
|
* uses this to pick the heading icon (`accent`+`●` vs `dim`+`○`).
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import { isTransitionValid } from "./invariants.ts";
|
|
15
15
|
import type { TaskState } from "./state.ts";
|
|
16
16
|
import { detectCycle } from "./task-graph.ts";
|
|
17
|
+
import { validateWaitFields, withoutWait, withWaitFields } from "./wait-mark.ts";
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Reducer outcome. Closed tagged union — adding a new action requires extending
|
|
@@ -76,6 +77,8 @@ const BATCH_ITEM_FIELDS = [
|
|
|
76
77
|
"anchor",
|
|
77
78
|
"graph",
|
|
78
79
|
"evidence",
|
|
80
|
+
"waitsOn",
|
|
81
|
+
"until",
|
|
79
82
|
] as const;
|
|
80
83
|
|
|
81
84
|
/**
|
|
@@ -101,6 +104,8 @@ function validateLedgerFields(spec: TaskMutationParams, now: string, clearable =
|
|
|
101
104
|
if (spec.anchor !== undefined && (typeof spec.anchor !== "string" || !spec.anchor.trim())) {
|
|
102
105
|
return "anchor must be a non-empty string";
|
|
103
106
|
}
|
|
107
|
+
const waitError = validateWaitFields(spec, now, clearable);
|
|
108
|
+
if (waitError) return waitError;
|
|
104
109
|
if (spec.evidence !== undefined) {
|
|
105
110
|
if (!Array.isArray(spec.evidence)) return "evidence must be a list";
|
|
106
111
|
for (let i = 0; i < spec.evidence.length; i++) {
|
|
@@ -167,7 +172,8 @@ function buildCreatedTask(id: number, spec: TaskMutationParams, subject: string,
|
|
|
167
172
|
if (spec.activeForm) newTask.activeForm = spec.activeForm;
|
|
168
173
|
if (spec.blockedBy?.length) newTask.blockedBy = [...spec.blockedBy];
|
|
169
174
|
if (spec.owner) newTask.owner = spec.owner;
|
|
170
|
-
|
|
175
|
+
const metadata = withWaitFields(spec.metadata ? { ...spec.metadata } : undefined, spec);
|
|
176
|
+
if (metadata) newTask.metadata = metadata;
|
|
171
177
|
if (spec.points !== undefined) newTask.points = spec.points;
|
|
172
178
|
if (spec.anchor !== undefined) newTask.anchor = spec.anchor;
|
|
173
179
|
if (isGraph(spec.graph)) newTask.graph = spec.graph;
|
|
@@ -320,13 +326,15 @@ export function applyTaskMutation(
|
|
|
320
326
|
params.points !== undefined ||
|
|
321
327
|
params.anchor !== undefined ||
|
|
322
328
|
params.graph !== undefined ||
|
|
329
|
+
params.waitsOn !== undefined ||
|
|
330
|
+
params.until !== undefined ||
|
|
323
331
|
(params.evidence && params.evidence.length > 0) ||
|
|
324
332
|
(params.addBlockedBy && params.addBlockedBy.length > 0) ||
|
|
325
333
|
(params.removeBlockedBy && params.removeBlockedBy.length > 0);
|
|
326
334
|
if (!hasMutation)
|
|
327
335
|
return errorResult(
|
|
328
336
|
state,
|
|
329
|
-
"update requires at least one mutable field: subject, description, activeForm, status, owner, metadata, points, anchor, graph, evidence, addBlockedBy, or removeBlockedBy",
|
|
337
|
+
"update requires at least one mutable field: subject, description, activeForm, status, owner, metadata, points, anchor, graph, evidence, waitsOn, until, addBlockedBy, or removeBlockedBy",
|
|
330
338
|
);
|
|
331
339
|
const ledgerError = validateLedgerFields(params, now, true);
|
|
332
340
|
if (ledgerError) return errorResult(state, ledgerError);
|
|
@@ -366,6 +374,9 @@ export function applyTaskMutation(
|
|
|
366
374
|
}
|
|
367
375
|
newMetadata = Object.keys(merged).length ? merged : undefined;
|
|
368
376
|
}
|
|
377
|
+
newMetadata = withWaitFields(newMetadata, params);
|
|
378
|
+
// Finishing a task ends its wait.
|
|
379
|
+
if (newStatus === "completed" || newStatus === "deleted") newMetadata = withoutWait(newMetadata);
|
|
369
380
|
|
|
370
381
|
const updated: Task = { ...current, status: newStatus };
|
|
371
382
|
if (params.subject !== undefined) updated.subject = params.subject;
|
|
@@ -428,6 +439,9 @@ export function applyTaskMutation(
|
|
|
428
439
|
const current = state.tasks[idx];
|
|
429
440
|
if (current.status === "deleted") return errorResult(state, `#${current.id} is already deleted`);
|
|
430
441
|
const updated: Task = { ...current, status: "deleted" };
|
|
442
|
+
const metadata = withoutWait(current.metadata);
|
|
443
|
+
if (metadata) updated.metadata = metadata;
|
|
444
|
+
else delete updated.metadata;
|
|
431
445
|
const newTasks = [...state.tasks];
|
|
432
446
|
newTasks[idx] = updated;
|
|
433
447
|
return {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Task, TaskMutationParams } from "../tool/types.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A wait mark: `metadata.waitsOn` names what an open task waits on (a person, CI, a train), and
|
|
5
|
+
* `metadata.until` an ISO time it waits until. The `waitsOn` and `until` tool fields write these keys,
|
|
6
|
+
* the ones the panel, sb's board, and anchorloop's close guard already read, so a snapshot keeps its
|
|
7
|
+
* v1 shape. Completing or deleting the task ends the wait and removes both keys.
|
|
8
|
+
*/
|
|
9
|
+
export const WAIT_KEYS = ["waitsOn", "until"] as const;
|
|
10
|
+
|
|
11
|
+
/** An ISO 8601 date or date-time, the forms `metadata.until` takes; pi-straw-boss (src/todoledger.ts) reads the same. */
|
|
12
|
+
const ISO_DATE_TIME = /^\d{4}-\d\d-\d\d(?:T(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z|[+-](?:[01]\d|2[0-3]):?[0-5]\d)?)?$/;
|
|
13
|
+
|
|
14
|
+
/** The epoch time of an `until` value, or NaN unless it is an ISO date or date-time on a real calendar day (not 2099-02-30). */
|
|
15
|
+
export function untilTime(value: unknown): number {
|
|
16
|
+
if (typeof value !== "string" || !ISO_DATE_TIME.test(value)) return Number.NaN;
|
|
17
|
+
const day = value.slice(0, 10), midnight = Date.parse(day);
|
|
18
|
+
return Number.isFinite(midnight) && new Date(midnight).toISOString().startsWith(day) ? Date.parse(value) : Number.NaN;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The refusal for a call's wait fields, or `undefined`; only an update (`clearable`) takes `null`. */
|
|
22
|
+
export function validateWaitFields(spec: TaskMutationParams, now: string, clearable: boolean): string | undefined {
|
|
23
|
+
const { waitsOn, until } = spec;
|
|
24
|
+
if (waitsOn !== undefined && !(clearable && waitsOn === null) && (typeof waitsOn !== "string" || !waitsOn.trim())) {
|
|
25
|
+
return clearable ? "waitsOn must be a non-empty string (null clears)" : "waitsOn must be a non-empty string";
|
|
26
|
+
}
|
|
27
|
+
if (until === undefined || (clearable && until === null)) return undefined;
|
|
28
|
+
if (Number.isNaN(untilTime(until))) {
|
|
29
|
+
return clearable ? "until must be an ISO 8601 date or time (null clears)" : "until must be an ISO 8601 date or time";
|
|
30
|
+
}
|
|
31
|
+
if (untilTime(until) <= Date.parse(now)) return "until must be in the future";
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Metadata with the call's wait fields applied: a string sets its key, `null` removes it. */
|
|
36
|
+
export function withWaitFields(metadata: Record<string, unknown> | undefined, spec: TaskMutationParams): Record<string, unknown> | undefined {
|
|
37
|
+
if (spec.waitsOn === undefined && spec.until === undefined) return metadata;
|
|
38
|
+
const next: Record<string, unknown> = { ...(metadata ?? {}) };
|
|
39
|
+
if (typeof spec.waitsOn === "string") next.waitsOn = spec.waitsOn.trim();
|
|
40
|
+
else if (spec.waitsOn === null) delete next.waitsOn;
|
|
41
|
+
if (typeof spec.until === "string") next.until = spec.until;
|
|
42
|
+
else if (spec.until === null) delete next.until;
|
|
43
|
+
return Object.keys(next).length ? next : undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Metadata without a wait mark, for a task that is completed or deleted. */
|
|
47
|
+
export function withoutWait(metadata: Record<string, unknown> | undefined): Record<string, unknown> | undefined {
|
|
48
|
+
if (!metadata || !WAIT_KEYS.some((key) => key in metadata)) return metadata;
|
|
49
|
+
const { waitsOn: _on, until: _until, ...rest } = metadata;
|
|
50
|
+
return Object.keys(rest).length ? rest : undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** What an open task waits on and until when, as display text parts; empty when it does not wait. */
|
|
54
|
+
export function waitParts(task: Task): { on?: string; until?: number } {
|
|
55
|
+
if (task.status !== "pending" && task.status !== "in_progress") return {};
|
|
56
|
+
const who = task.metadata?.waitsOn;
|
|
57
|
+
const on = typeof who === "string" && who.trim() ? who : undefined;
|
|
58
|
+
const time = untilTime(task.metadata?.until);
|
|
59
|
+
return { ...(on ? { on } : {}), ...(time > Date.now() ? { until: time } : {}) };
|
|
60
|
+
}
|
package/src/todo-overlay.ts
CHANGED
|
@@ -31,9 +31,9 @@ import {
|
|
|
31
31
|
import { formatStatusLabel, formatWorkerCount, t } from "./state/i18n-bridge.ts";
|
|
32
32
|
import {
|
|
33
33
|
selectHasActive,
|
|
34
|
-
selectOverlayLayout,
|
|
35
34
|
selectShowTaskIds,
|
|
36
35
|
selectTodoCounts,
|
|
36
|
+
selectVisibleTasks,
|
|
37
37
|
} from "./state/selectors.ts";
|
|
38
38
|
import { getRenderState } from "./state/store.ts";
|
|
39
39
|
import { formatPlanTaskLine } from "./view/format.ts";
|
|
@@ -41,7 +41,7 @@ import { type PlanRow, planView } from "./view/plan.ts";
|
|
|
41
41
|
import type { Task } from "./tool/types.ts";
|
|
42
42
|
|
|
43
43
|
import { history } from "./ledger/herdr-runs.ts";
|
|
44
|
-
import { liveRows, runLine, type Query, type RunRow } from "./view/live-runs.ts";
|
|
44
|
+
import { liveRows, runLine, runState, type Query, type RunRow } from "./view/live-runs.ts";
|
|
45
45
|
|
|
46
46
|
const WIDGET_KEY = "rpiv-todos";
|
|
47
47
|
|
|
@@ -72,6 +72,28 @@ interface Frame {
|
|
|
72
72
|
/** Runs of the Other workers group that fit `rows`: the heading and at least one run, or none. */
|
|
73
73
|
const groupFit = (rows: number, runs: number) => (runs > 0 && rows >= 2 ? Math.min(runs, rows - 1) : 0);
|
|
74
74
|
|
|
75
|
+
/** The rows one budget gives, decided by rank (see TodoOverlay.allot). */
|
|
76
|
+
interface Allotment {
|
|
77
|
+
/** Tasks that get a row, in display order. */
|
|
78
|
+
shown: Task[];
|
|
79
|
+
/** Shown tasks whose run rows are drawn; any other shown task with runs counts them on its row. */
|
|
80
|
+
withRuns: Set<Task>;
|
|
81
|
+
/** The Other workers group: live runs of this session whose task has no row. */
|
|
82
|
+
workers: RunRow[];
|
|
83
|
+
/** How many of `workers` get a row under the group heading. */
|
|
84
|
+
group: number;
|
|
85
|
+
/** Rows the budget leaves unused. */
|
|
86
|
+
left: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Narrowest left part (branch, glyph, id, start of the subject) a compact row keeps before its run. */
|
|
90
|
+
const COMPACT_MIN_LEFT = 12;
|
|
91
|
+
|
|
92
|
+
/** How a run ranks for the one spot on a compact row: working, then waiting for a reply, then the rest, idle last. */
|
|
93
|
+
const ACTIVITY: Record<string, number> = { running: 0, waiting: 1, idle: 3 };
|
|
94
|
+
const mostActive = (runs: readonly RunRow[]) =>
|
|
95
|
+
runs.reduce((best, r) => ((ACTIVITY[runState(r) ?? ""] ?? 2) < (ACTIVITY[runState(best) ?? ""] ?? 2) ? r : best));
|
|
96
|
+
|
|
75
97
|
/** What one frame's row drawing needs, shared by the full and focus views. */
|
|
76
98
|
interface DrawContext {
|
|
77
99
|
theme: Theme;
|
|
@@ -85,6 +107,8 @@ interface DrawContext {
|
|
|
85
107
|
showIds: boolean;
|
|
86
108
|
now: number;
|
|
87
109
|
evidence: "inline" | "screen" | undefined;
|
|
110
|
+
/** Compact mode: a task's runs, and the Other workers group, share one row with it (see budgeted). */
|
|
111
|
+
compact: boolean;
|
|
88
112
|
}
|
|
89
113
|
|
|
90
114
|
export class TodoOverlay {
|
|
@@ -408,6 +432,7 @@ export class TodoOverlay {
|
|
|
408
432
|
showIds,
|
|
409
433
|
now: Date.now(),
|
|
410
434
|
evidence: this.evidence(),
|
|
435
|
+
compact: false,
|
|
411
436
|
};
|
|
412
437
|
|
|
413
438
|
// Collapsed view: just the heading + a dim "└─" hint naming the next state,
|
|
@@ -453,68 +478,40 @@ export class TodoOverlay {
|
|
|
453
478
|
return this.withTrailingSpacer([heading, ...body]);
|
|
454
479
|
}
|
|
455
480
|
|
|
456
|
-
/** The whole dependency tree, budgeted by
|
|
481
|
+
/** The whole dependency tree, budgeted by rank (see allot), then the Other workers group (the `"full"` view). */
|
|
457
482
|
private fullBody(
|
|
458
483
|
overlayState: { tasks: Task[]; nextId: number },
|
|
459
484
|
plan: ReturnType<typeof planView>,
|
|
460
485
|
bodyBudget: number,
|
|
461
486
|
draw: DrawContext,
|
|
462
487
|
): string[] {
|
|
463
|
-
const
|
|
464
|
-
const
|
|
465
|
-
const hint = this.keyHint();
|
|
466
|
-
draw.others = this.groupCandidates(layout.visible, draw);
|
|
467
|
-
const others = draw.others.length;
|
|
468
|
-
// With nothing to summarize, the hint takes its own row only when one is spare.
|
|
469
|
-
const needed =
|
|
470
|
-
layout.visible.reduce((n, task) => n + 1 + this.children(task, draw).length, 0) +
|
|
471
|
-
(others ? 1 + others : 0);
|
|
472
|
-
const hintRow = overflow === 0 && hint !== undefined && needed < bodyBudget;
|
|
473
|
-
let spare = bodyBudget - layout.visible.length - Number(overflow > 0 || hintRow);
|
|
474
|
-
// The group gets the rows the bound runs leave; a group cut short needs the summary row.
|
|
475
|
-
let rest = spare - this.boundRows(layout.visible, spare, draw);
|
|
476
|
-
let summarized = overflow > 0;
|
|
477
|
-
let group = others;
|
|
478
|
-
if (1 + others > rest) {
|
|
479
|
-
if (!summarized && rest > 0) {
|
|
480
|
-
summarized = true;
|
|
481
|
-
rest--;
|
|
482
|
-
}
|
|
483
|
-
group = groupFit(rest, others);
|
|
484
|
-
}
|
|
485
|
-
spare -= group ? 1 + group : 0;
|
|
488
|
+
const all = [...selectVisibleTasks(overlayState)];
|
|
489
|
+
const { shown, summarized, hintRow, hint, others } = this.budgeted(all, all.length, bodyBudget, draw);
|
|
486
490
|
const frame: Frame = { drawn: [], marked: new Map(), ticking: false };
|
|
487
491
|
const lines = this.drawTasks(
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
!summarized && !hintRow && !group,
|
|
492
|
+
shown.shown.map((task) => ({ task, row: plan.rows.get(task.id) })),
|
|
493
|
+
shown.withRuns,
|
|
494
|
+
!summarized && !hintRow && !shown.group,
|
|
491
495
|
draw,
|
|
492
496
|
frame,
|
|
493
497
|
);
|
|
494
|
-
lines.push(...this.drawGroup(draw.others.slice(0, group), !summarized && !hintRow, draw, frame));
|
|
498
|
+
lines.push(...this.drawGroup(draw.others.slice(0, shown.group), !summarized && !hintRow, draw, frame));
|
|
495
499
|
this.endFrame(frame, draw);
|
|
496
500
|
if (hintRow) lines.push(this.closingRow(draw, undefined, hint));
|
|
497
501
|
if (!summarized) return lines;
|
|
498
502
|
|
|
499
503
|
const parts: string[] = [];
|
|
504
|
+
const isShown = new Set(shown.shown);
|
|
505
|
+
const hiddenBy = (status: string) => all.filter((task) => task.status === status && !isShown.has(task)).length;
|
|
506
|
+
const overflowParts = (["completed", "in_progress", "pending"] as const)
|
|
507
|
+
.map((status) => [hiddenBy(status), status] as const)
|
|
508
|
+
.filter(([n]) => n > 0);
|
|
509
|
+
const overflow = overflowParts.reduce((sum, [n]) => sum + n, 0);
|
|
500
510
|
if (overflow > 0) {
|
|
501
|
-
const overflowParts: string[] = [];
|
|
502
|
-
if (layout.hiddenCompleted > 0)
|
|
503
|
-
overflowParts.push(
|
|
504
|
-
`${layout.hiddenCompleted} ${formatStatusLabel("completed")}`,
|
|
505
|
-
);
|
|
506
|
-
if (layout.truncatedTail > 0)
|
|
507
|
-
overflowParts.push(
|
|
508
|
-
`${layout.truncatedTail} ${formatStatusLabel("pending")}`,
|
|
509
|
-
);
|
|
510
511
|
const more = t("overlay.more", OVERLAY_MORE);
|
|
511
|
-
parts.push(
|
|
512
|
-
overflowParts.length > 0
|
|
513
|
-
? `+${overflow} ${more} (${overflowParts.join(", ")})`
|
|
514
|
-
: `+${overflow} ${more}`,
|
|
515
|
-
);
|
|
512
|
+
parts.push(`+${overflow} ${more} (${overflowParts.map(([n, status]) => `${n} ${formatStatusLabel(status)}`).join(", ")})`);
|
|
516
513
|
}
|
|
517
|
-
if (group < others) parts.push(`${parts.length ? "" : "+"}${formatWorkerCount(others - group)}`);
|
|
514
|
+
if (shown.group < others) parts.push(`${parts.length ? "" : "+"}${formatWorkerCount(others - shown.group)}`);
|
|
518
515
|
lines.push(this.closingRow(draw, parts.join(t("overlay.separator", OVERLAY_SEPARATOR)), hint));
|
|
519
516
|
return lines;
|
|
520
517
|
}
|
|
@@ -522,9 +519,9 @@ export class TodoOverlay {
|
|
|
522
519
|
/**
|
|
523
520
|
* The focus view (default): in-progress tasks with their runs, the next open
|
|
524
521
|
* tasks (two, or three when nothing is in progress), the Other workers group,
|
|
525
|
-
* then this turn's completed rows
|
|
526
|
-
* whatever is hidden. Completed rows are drawn before the group
|
|
527
|
-
*
|
|
522
|
+
* then this turn's completed rows, budgeted by rank (see allot), and one summary
|
|
523
|
+
* row counting whatever is hidden. Completed rows are drawn before the group.
|
|
524
|
+
* Rows are flat, so every unfinished blocker goes to the `⛓` tail.
|
|
528
525
|
*/
|
|
529
526
|
private focusBody(
|
|
530
527
|
overlayTasks: Task[],
|
|
@@ -537,33 +534,12 @@ export class TodoOverlay {
|
|
|
537
534
|
const completed = overlayTasks.filter((t) => t.status === "completed");
|
|
538
535
|
const next = pending.slice(0, inProgress.length ? 2 : 3);
|
|
539
536
|
const total = inProgress.length + pending.length + completed.length;
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
const candidates = this.groupCandidates([...core, ...completed], draw);
|
|
547
|
-
const initialGroup = groupFit(spare, candidates.length);
|
|
548
|
-
const possibleDone = completed.slice(0, spare - (initialGroup ? 1 + initialGroup : 0));
|
|
549
|
-
const workers = this.groupCandidates([...core, ...possibleDone], draw);
|
|
550
|
-
const group = groupFit(spare, workers.length);
|
|
551
|
-
spare -= group ? 1 + group : 0;
|
|
552
|
-
const done = completed.slice(0, spare);
|
|
553
|
-
const rows = core.length + done.length + (group ? 1 + group : 0);
|
|
554
|
-
return { core, done, group, workers: this.groupCandidates([...core, ...done], draw), spare: slots - rows, left: spare - done.length };
|
|
555
|
-
};
|
|
556
|
-
let shown = fit(bodyBudget);
|
|
557
|
-
const summarized =
|
|
558
|
-
shown.core.length + shown.done.length < total || shown.group < shown.workers.length;
|
|
559
|
-
if (summarized) shown = fit(bodyBudget - 1);
|
|
560
|
-
draw.others = shown.workers;
|
|
561
|
-
const others = shown.workers.length;
|
|
562
|
-
// With nothing to summarize, the hint takes its own row only when one is spare;
|
|
563
|
-
// one row less leaves the same layout then.
|
|
564
|
-
const hint = this.keyHint();
|
|
565
|
-
const hintRow = !summarized && hint !== undefined && shown.left > 0;
|
|
566
|
-
if (hintRow) shown = { ...shown, spare: shown.spare - 1 };
|
|
537
|
+
const { shown, summarized, hintRow, hint, others } = this.budgeted(
|
|
538
|
+
[...inProgress, ...next, ...completed],
|
|
539
|
+
total,
|
|
540
|
+
bodyBudget,
|
|
541
|
+
draw,
|
|
542
|
+
);
|
|
567
543
|
|
|
568
544
|
const openIds = new Set(plan.ordered.map((t) => t.id));
|
|
569
545
|
const flat = (task: Task): PlanRow | undefined => {
|
|
@@ -578,8 +554,8 @@ export class TodoOverlay {
|
|
|
578
554
|
};
|
|
579
555
|
const frame: Frame = { drawn: [], marked: new Map(), ticking: false };
|
|
580
556
|
const lines = this.drawTasks(
|
|
581
|
-
|
|
582
|
-
shown.
|
|
557
|
+
shown.shown.map((task) => ({ task, row: flat(task) })),
|
|
558
|
+
shown.withRuns,
|
|
583
559
|
!summarized && !hintRow && !shown.group,
|
|
584
560
|
draw,
|
|
585
561
|
frame,
|
|
@@ -589,7 +565,7 @@ export class TodoOverlay {
|
|
|
589
565
|
if (hintRow) lines.push(this.closingRow(draw, undefined, hint));
|
|
590
566
|
if (!summarized) return lines;
|
|
591
567
|
|
|
592
|
-
const isShown = new Set(
|
|
568
|
+
const isShown = new Set(shown.shown);
|
|
593
569
|
const hidden = (list: Task[]) => list.filter((t) => !isShown.has(t)).length;
|
|
594
570
|
const parts = (
|
|
595
571
|
[
|
|
@@ -617,14 +593,68 @@ export class TodoOverlay {
|
|
|
617
593
|
return runs.flatMap((r) => draw.live?.get(r.id) ?? []);
|
|
618
594
|
}
|
|
619
595
|
|
|
620
|
-
/**
|
|
621
|
-
|
|
596
|
+
/**
|
|
597
|
+
* Give `slots` rows to the candidates (in display order) by rank:
|
|
598
|
+
* 1. in-progress task rows;
|
|
599
|
+
* 2. live run rows, all of one task's together, with that task's row when it has none yet;
|
|
600
|
+
* 3. the Other workers group, holding every live run whose task got no row;
|
|
601
|
+
* 4. open tasks without a live run;
|
|
602
|
+
* 5. completed tasks without a live run.
|
|
603
|
+
* A task with live runs that missed rank 2 gets no row, so its runs join the group.
|
|
604
|
+
* An in-progress task whose runs do not fit keeps its row and counts them.
|
|
605
|
+
* `compact`: runs take no rows of their own, and the group takes one row.
|
|
606
|
+
*/
|
|
607
|
+
private allot(candidates: readonly Task[], slots: number, draw: DrawContext, compact: boolean): Allotment {
|
|
608
|
+
const chosen = new Set<Task>();
|
|
609
|
+
const withRuns = new Set<Task>();
|
|
622
610
|
let used = 0;
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
611
|
+
const take = (rows: number) => {
|
|
612
|
+
if (used + rows > slots) return false;
|
|
613
|
+
used += rows;
|
|
614
|
+
return true;
|
|
615
|
+
};
|
|
616
|
+
for (const task of candidates) if (task.status === "in_progress" && take(1)) chosen.add(task);
|
|
617
|
+
for (const task of candidates) {
|
|
618
|
+
const runs = this.children(task, draw).length;
|
|
619
|
+
if (runs && take((compact ? 0 : runs) + Number(!chosen.has(task)))) {
|
|
620
|
+
chosen.add(task);
|
|
621
|
+
withRuns.add(task);
|
|
622
|
+
}
|
|
626
623
|
}
|
|
627
|
-
|
|
624
|
+
const workers = this.groupCandidates([...chosen], draw);
|
|
625
|
+
const group = compact ? (workers.length && take(1) ? workers.length : 0) : groupFit(slots - used, workers.length);
|
|
626
|
+
if (!compact) used += group ? 1 + group : 0;
|
|
627
|
+
for (const done of [false, true])
|
|
628
|
+
for (const task of candidates)
|
|
629
|
+
if ((task.status === "completed") === done && !chosen.has(task) && !this.children(task, draw).length && take(1))
|
|
630
|
+
chosen.add(task);
|
|
631
|
+
return { shown: candidates.filter((task) => chosen.has(task)), withRuns, workers, group, left: slots - used };
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* The allotment for `budget` rows, keeping one for the summary when anything of
|
|
636
|
+
* `total` tasks or the group is left out. With nothing to summarize, the hint takes
|
|
637
|
+
* its own row only when one is spare. When some live run would get no row of its
|
|
638
|
+
* own, the panel switches to compact mode (each run joins its task's row, the group
|
|
639
|
+
* takes one row). Sets `draw.others` to the group and `draw.compact`.
|
|
640
|
+
*/
|
|
641
|
+
private budgeted(candidates: readonly Task[], total: number, budget: number, draw: DrawContext) {
|
|
642
|
+
const cut = (a: Allotment) => a.shown.length < total || a.group < a.workers.length;
|
|
643
|
+
const fit = (compact: boolean) => {
|
|
644
|
+
const first = this.allot(candidates, budget, draw, compact);
|
|
645
|
+
return cut(first)
|
|
646
|
+
? { shown: this.allot(candidates, budget - 1, draw, compact), summarized: true }
|
|
647
|
+
: { shown: first, summarized: false };
|
|
648
|
+
};
|
|
649
|
+
let { shown, summarized } = fit(false);
|
|
650
|
+
draw.compact =
|
|
651
|
+
shown.group < shown.workers.length ||
|
|
652
|
+
shown.shown.some((task) => this.children(task, draw).length > 0 && !shown.withRuns.has(task));
|
|
653
|
+
if (draw.compact) ({ shown, summarized } = fit(true));
|
|
654
|
+
draw.others = shown.workers;
|
|
655
|
+
const hint = this.keyHint();
|
|
656
|
+
const hintRow = !summarized && hint !== undefined && shown.left > 0;
|
|
657
|
+
return { shown, summarized, hintRow, hint, others: shown.workers.length };
|
|
628
658
|
}
|
|
629
659
|
|
|
630
660
|
/** End the frame's claim bookkeeping; a group folded into the summary keeps the tick so its count stays current. */
|
|
@@ -651,6 +681,37 @@ export class TodoOverlay {
|
|
|
651
681
|
}
|
|
652
682
|
}
|
|
653
683
|
|
|
684
|
+
/**
|
|
685
|
+
* A compact row: `left` (a task row or the group heading), then ` ⟶ ` and the most
|
|
686
|
+
* active of `runs`, then `+N` for the others. The left part is cut first, so the run
|
|
687
|
+
* stays whole. A row shown in full claims every run it stands for; one cut into the
|
|
688
|
+
* run, or with no room for the left part, carries no marker and claims none.
|
|
689
|
+
* In the group (`group`), a run of a hidden task carries its task number.
|
|
690
|
+
*/
|
|
691
|
+
private drawCompact(lines: string[], left: string, runs: RunRow[], draw: DrawContext, frame: Frame, group = false) {
|
|
692
|
+
const { theme, width, truncate, now, evidence } = draw;
|
|
693
|
+
const lead = mostActive(runs);
|
|
694
|
+
const owner = draw.runOwners.get(lead.id);
|
|
695
|
+
const right =
|
|
696
|
+
theme.fg("dim", " ⟶ ") +
|
|
697
|
+
(group && owner !== undefined ? `#${owner} ` : "") +
|
|
698
|
+
runLine(lead, now, (color, text) => theme.fg(color, text)) +
|
|
699
|
+
(runs.length > 1 ? theme.fg("dim", ` +${runs.length - 1}`) : "");
|
|
700
|
+
const room = width - visibleWidth(right);
|
|
701
|
+
const roomy = visibleWidth(left) <= room || room >= COMPACT_MIN_LEFT;
|
|
702
|
+
const line = roomy ? truncateToWidth(left, Math.max(room, 0), "…") + right : truncate(left + right);
|
|
703
|
+
const whole = roomy && visibleWidth(line) <= width;
|
|
704
|
+
frame.ticking = true;
|
|
705
|
+
if (whole && evidence === "screen") {
|
|
706
|
+
const marked = line + this.marker(lead.id);
|
|
707
|
+
for (const r of runs) frame.marked.set(r.id, marked);
|
|
708
|
+
lines.push(marked);
|
|
709
|
+
} else {
|
|
710
|
+
lines.push(truncate(line));
|
|
711
|
+
if (whole && evidence === "inline") frame.drawn.push(...runs.map((r) => r.id));
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
654
715
|
/**
|
|
655
716
|
* The Other workers group: a heading row, then this session's runs bound to no
|
|
656
717
|
* task, drawn and claimed like bound run rows. `closed` means it ends the panel.
|
|
@@ -658,22 +719,26 @@ export class TodoOverlay {
|
|
|
658
719
|
private drawGroup(runs: RunRow[], closed: boolean, draw: DrawContext, frame: Frame): string[] {
|
|
659
720
|
if (!runs.length) return [];
|
|
660
721
|
const { theme, truncate } = draw;
|
|
661
|
-
const
|
|
662
|
-
|
|
663
|
-
|
|
722
|
+
const heading = `${theme.fg("dim", closed ? "└─" : "├─")} ${theme.fg("muted", t("overlay.others", OVERLAY_OTHERS))}`;
|
|
723
|
+
if (draw.compact) {
|
|
724
|
+
const lines: string[] = [];
|
|
725
|
+
this.drawCompact(lines, heading, runs, draw, frame, true);
|
|
726
|
+
return lines;
|
|
727
|
+
}
|
|
728
|
+
const lines = [truncate(heading)];
|
|
664
729
|
for (const [j, r] of runs.entries())
|
|
665
730
|
this.drawRun(lines, r, `${closed ? " " : "│"} ${j === runs.length - 1 ? "└" : "├"} ${draw.runOwners.has(r.id) ? `#${draw.runOwners.get(r.id)} ` : ''}`, draw, frame);
|
|
666
731
|
return lines;
|
|
667
732
|
}
|
|
668
733
|
|
|
669
734
|
/**
|
|
670
|
-
* Draw task rows and,
|
|
671
|
-
*
|
|
735
|
+
* Draw task rows and, for the tasks in `withRuns`, their run rows; any other task
|
|
736
|
+
* with live runs shows `· N runs`. `closed` means nothing follows, so the last
|
|
672
737
|
* task row takes `└─`.
|
|
673
738
|
*/
|
|
674
739
|
private drawTasks(
|
|
675
740
|
entries: { task: Task; row?: PlanRow }[],
|
|
676
|
-
|
|
741
|
+
withRuns: ReadonlySet<Task>,
|
|
677
742
|
closed: boolean,
|
|
678
743
|
draw: DrawContext,
|
|
679
744
|
frame: Frame,
|
|
@@ -683,7 +748,7 @@ export class TodoOverlay {
|
|
|
683
748
|
for (const [i, { task, row }] of entries.entries()) {
|
|
684
749
|
const { older } = draw.bound.get(task.id) ?? history(undefined);
|
|
685
750
|
const children = this.children(task, draw);
|
|
686
|
-
const fits = children.length
|
|
751
|
+
const fits = !children.length || withRuns.has(task);
|
|
687
752
|
const last = closed && i === entries.length - 1;
|
|
688
753
|
const display =
|
|
689
754
|
fits && children.some((r) => r.name === task.owner)
|
|
@@ -692,13 +757,13 @@ export class TodoOverlay {
|
|
|
692
757
|
const count = !fits
|
|
693
758
|
? ` · ${children.length} ${t("run.count", "runs")}`
|
|
694
759
|
: "";
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
760
|
+
const taskLine = `${theme.fg("dim", last ? "└─" : "├─")} ${formatPlanTaskLine(display, theme, showIds, row)}${count}${older && live ? ` +${older}` : ""}`;
|
|
761
|
+
if (fits && children.length && draw.compact) {
|
|
762
|
+
this.drawCompact(lines, taskLine, children, draw, frame);
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
lines.push(truncate(taskLine));
|
|
700
766
|
if (!fits) continue;
|
|
701
|
-
spare -= children.length;
|
|
702
767
|
const indent = " ".repeat(row?.depth ?? 0);
|
|
703
768
|
for (const [j, r] of children.entries())
|
|
704
769
|
this.drawRun(lines, r, `${last ? " " : "│"} ${indent}${j === children.length - 1 ? "└" : "├"} `, draw, frame);
|
package/src/todo.ts
CHANGED
|
@@ -69,6 +69,7 @@ export const DEFAULT_PROMPT_GUIDELINES: string[] = [
|
|
|
69
69
|
"list hides tombstoned (deleted) tasks by default; pass includeDeleted:true to see them. Pass status to filter by a single status.",
|
|
70
70
|
"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.",
|
|
71
71
|
"Optional bookkeeping fields: points (effort, 0 to 10), anchor (the check that shows the task is done, e.g. a test command), and evidence (runs of checks, each {command, sha?, result: pass|fail, at?}). On update, points and anchor replace; evidence is appended, never replaced.",
|
|
72
|
+
"When a task waits on something outside your control (a person, CI, a train, a release window), mark it with waitsOn (what it waits on) and, if known, until (ISO time); it shows ⏸ and reminders leave it alone while it waits. To end a wait early, clear every field you set (waitsOn: null, until: null), since an until left in place keeps the task waiting; completing the task clears both.",
|
|
72
73
|
];
|
|
73
74
|
|
|
74
75
|
export function registerTodoTool(pi: ExtensionAPI, finish: FinishCall): void {
|
package/src/tool/types.ts
CHANGED
|
@@ -118,6 +118,8 @@ export interface CreateTaskInput {
|
|
|
118
118
|
anchor?: string;
|
|
119
119
|
graph?: string;
|
|
120
120
|
evidence?: EvidenceInput[];
|
|
121
|
+
waitsOn?: string;
|
|
122
|
+
until?: string;
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
export interface TaskMutationParams {
|
|
@@ -136,6 +138,10 @@ export interface TaskMutationParams {
|
|
|
136
138
|
/** A graph name; `null` clears it on update. */
|
|
137
139
|
graph?: string | null;
|
|
138
140
|
evidence?: EvidenceInput[];
|
|
141
|
+
/** What the task waits on, stored as `metadata.waitsOn`; `null` clears it on update. */
|
|
142
|
+
waitsOn?: string | null;
|
|
143
|
+
/** An ISO time the task waits until, stored as `metadata.until`; `null` clears it on update. */
|
|
144
|
+
until?: string | null;
|
|
139
145
|
id?: number;
|
|
140
146
|
path?: string;
|
|
141
147
|
session?: string;
|
|
@@ -164,6 +170,10 @@ const EvidenceInputSchema = Type.Object({
|
|
|
164
170
|
|
|
165
171
|
const EvidenceSchema = (description: string) => Type.Array(EvidenceInputSchema, { description });
|
|
166
172
|
|
|
173
|
+
const WAITS_ON_TEXT =
|
|
174
|
+
"What this task waits on (a person, CI, a train to end); it shows ⏸, and close and stale reminders leave the task alone while it waits. Completing or deleting the task clears it; to end a wait early, clear both waitsOn and until";
|
|
175
|
+
const UNTIL_TEXT = "ISO 8601 time the task waits until, e.g. 2027-01-15T09:00:00+08:00; once it passes, an until-only wait ends";
|
|
176
|
+
|
|
167
177
|
const CreateTaskInputSchema = Type.Object({
|
|
168
178
|
subject: Type.String({ description: "Task subject line" }),
|
|
169
179
|
description: Type.Optional(Type.String({ description: "Long-form task description" })),
|
|
@@ -188,6 +198,8 @@ const CreateTaskInputSchema = Type.Object({
|
|
|
188
198
|
anchor: Type.Optional(AnchorSchema("The check that shows this task is done, e.g. a test command")),
|
|
189
199
|
graph: Type.Optional(Type.String()),
|
|
190
200
|
evidence: Type.Optional(EvidenceSchema("Check runs already recorded for this task")),
|
|
201
|
+
waitsOn: Type.Optional(Type.String({ minLength: 1, description: WAITS_ON_TEXT })),
|
|
202
|
+
until: Type.Optional(Type.String({ description: UNTIL_TEXT })),
|
|
191
203
|
});
|
|
192
204
|
|
|
193
205
|
export const TodoParamsSchema = Type.Object({
|
|
@@ -248,6 +260,10 @@ export const TodoParamsSchema = Type.Object({
|
|
|
248
260
|
"Check runs to record: the initial list on create; on update, appended to the task's evidence (never replaced or removed)",
|
|
249
261
|
),
|
|
250
262
|
),
|
|
263
|
+
waitsOn: Type.Optional(
|
|
264
|
+
Type.Union([Type.String({ minLength: 1 }), Type.Null()], { description: `${WAITS_ON_TEXT}; null clears (update)` }),
|
|
265
|
+
),
|
|
266
|
+
until: Type.Optional(Type.Union([Type.String(), Type.Null()], { description: `${UNTIL_TEXT}; null clears (update)` })),
|
|
251
267
|
id: Type.Optional(
|
|
252
268
|
Type.Number({
|
|
253
269
|
description: "Task id (required for update, get, delete)",
|
package/src/view/task-labels.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { t } from '../state/i18n-bridge.ts';
|
|
2
2
|
import { sanitizeTerminalText } from "../tool/sanitize.ts";
|
|
3
|
+
import { waitParts } from "../state/wait-mark.ts";
|
|
3
4
|
import type { Task } from "../tool/types.ts";
|
|
4
5
|
|
|
5
6
|
export function isOpen(task: Task): boolean {
|
|
@@ -11,17 +12,13 @@ export function uidSuffix(task: Task): string {
|
|
|
11
12
|
return typeof task.uid === "string" ? ` ${sanitizeTerminalText(task.uid)}` : "";
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
const isoDateTime = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/i;
|
|
15
15
|
const localTime = new Intl.DateTimeFormat(undefined, { dateStyle: "short", timeStyle: "short" });
|
|
16
16
|
|
|
17
17
|
/** A hint for this render, never a status transition or a stored field. */
|
|
18
18
|
export function waitingLabel(task: Task): string {
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const until = task.metadata?.until;
|
|
23
|
-
const time = typeof until === "string" && isoDateTime.test(until) ? Date.parse(until) : NaN;
|
|
24
|
-
return [party && `${t('wait.party','waits')} ${party}`, time > Date.now() && `${t('wait.until','until')} ${localTime.format(time)}`].filter(Boolean).join(" · ");
|
|
19
|
+
const { on, until } = waitParts(task);
|
|
20
|
+
const party = on ? sanitizeTerminalText(on).trim() : "";
|
|
21
|
+
return [party && `${t('wait.party','waits')} ${party}`, until !== undefined && `${t('wait.until','until')} ${localTime.format(until)}`].filter(Boolean).join(" · ");
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
export function resultSuffix(task: Task): string {
|