pi-todo-ledger 0.7.4 → 0.8.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/CONTRACT.md +14 -0
- package/README.md +7 -3
- package/docs/overlay.md +1 -1
- 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/state-reducer.ts +16 -2
- package/src/state/wait-mark.ts +60 -0
- 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
|
@@ -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.
|
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.0",
|
|
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":
|
|
@@ -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.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 {
|