@indexyz/pi-todo 0.0.0-stage → 0.1.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/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +81 -2
- package/config.ts +141 -0
- package/docs/configuration.md +108 -0
- package/docs/overlay.md +128 -0
- package/docs/tool-schema.md +191 -0
- package/index.ts +302 -0
- package/locales/de.json +19 -0
- package/locales/en.json +17 -0
- package/locales/es.json +19 -0
- package/locales/fr.json +19 -0
- package/locales/pt-BR.json +19 -0
- package/locales/pt.json +19 -0
- package/locales/ru.json +19 -0
- package/locales/uk.json +19 -0
- package/locales/zh.json +19 -0
- package/package.json +87 -4
- package/state/i18n-bridge.ts +64 -0
- package/state/invariants.ts +20 -0
- package/state/replay.ts +142 -0
- package/state/selectors.ts +108 -0
- package/state/state-reducer.ts +324 -0
- package/state/state.ts +18 -0
- package/state/store.ts +125 -0
- package/state/task-graph.ts +61 -0
- package/todo-overlay.ts +255 -0
- package/todo.ts +168 -0
- package/tool/normalize-params.ts +44 -0
- package/tool/response-envelope.ts +114 -0
- package/tool/sanitize.ts +34 -0
- package/tool/types.ts +188 -0
- package/view/format.ts +202 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# `todo` tool reference
|
|
2
|
+
|
|
3
|
+
Complete parameter schema, status machine, response envelope, and error strings
|
|
4
|
+
for the `todo` tool registered by `@indexyz/pi-todo`.
|
|
5
|
+
|
|
6
|
+
## Actions
|
|
7
|
+
|
|
8
|
+
| Action | Required params | What it does |
|
|
9
|
+
| -------- | --------------------------------- | ----------------------------------------------------------------- |
|
|
10
|
+
| `create` | `subject` or `tasks[]` (one-of) | Adds one task, or several independent tasks, in `pending`. |
|
|
11
|
+
| `update` | `id` + at least one mutable field | Changes status, fields, or dependencies. |
|
|
12
|
+
| `list` | — | Returns all tasks, optionally filtered by `status`. |
|
|
13
|
+
| `get` | `id` | Returns one task with its `blockedBy` and reverse `blocks` edges. |
|
|
14
|
+
| `delete` | `id` | Tombstones the task (`status: "deleted"`); it is not removed. |
|
|
15
|
+
| `clear` | — | Drops every task and resets the id counter to `1`. |
|
|
16
|
+
|
|
17
|
+
## Parameters
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
todo({
|
|
21
|
+
action: "create" | "update" | "list" | "get" | "delete" | "clear",
|
|
22
|
+
|
|
23
|
+
// create-only (one-of: subject or tasks[])
|
|
24
|
+
subject?: string, // required for single create
|
|
25
|
+
blockedBy?: number[], // initial dependency ids (single create)
|
|
26
|
+
tasks?: Array<{ // batch create; independent items only
|
|
27
|
+
subject: string,
|
|
28
|
+
description?: string,
|
|
29
|
+
activeForm?: string,
|
|
30
|
+
blockedBy?: number[], // existing ids only; no sibling refs
|
|
31
|
+
owner?: string,
|
|
32
|
+
metadata?: Record<string, unknown>,
|
|
33
|
+
}>,
|
|
34
|
+
|
|
35
|
+
// create + update
|
|
36
|
+
description?: string, // long-form detail
|
|
37
|
+
activeForm?: string, // present-continuous label shown while in_progress
|
|
38
|
+
owner?: string, // agent/owner assigned to this task
|
|
39
|
+
metadata?: Record<string, unknown>, // on update, a null value deletes that key
|
|
40
|
+
|
|
41
|
+
// update-only
|
|
42
|
+
addBlockedBy?: number[], // additive merge into blockedBy
|
|
43
|
+
removeBlockedBy?: number[], // additive removal from blockedBy
|
|
44
|
+
|
|
45
|
+
// update / get / delete
|
|
46
|
+
id?: number,
|
|
47
|
+
|
|
48
|
+
// update (sets this task's status) or list (filters by status)
|
|
49
|
+
status?: "pending" | "in_progress" | "completed" | "deleted",
|
|
50
|
+
|
|
51
|
+
// list-only
|
|
52
|
+
includeDeleted?: boolean, // default false — hides tombstones
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`create` takes either `subject` (one task) or `tasks[]` (several independent
|
|
57
|
+
tasks). Passing both is rejected, even with a blank `subject`. Each item carries
|
|
58
|
+
its own `description`, `activeForm`, `blockedBy`, `owner` and `metadata`; the same
|
|
59
|
+
fields at the top level of a batch are rejected rather than dropped. The batch is validated first and committed
|
|
60
|
+
together: one bad item fails the whole call and leaves the list unchanged.
|
|
61
|
+
Items in `tasks[]` cannot `blockedBy` each other; those ids do not exist until
|
|
62
|
+
the call commits. Create the prerequisite first, then the dependent with
|
|
63
|
+
`blockedBy`. `blockedBy` on a batch item may name a task that already exists.
|
|
64
|
+
|
|
65
|
+
`update` merges `metadata` key by key into the existing record; passing `null`
|
|
66
|
+
for a key removes it, and emptying the record drops the field entirely.
|
|
67
|
+
`addBlockedBy` and `removeBlockedBy` are additive — do not resend the whole
|
|
68
|
+
array.
|
|
69
|
+
|
|
70
|
+
## Status transitions
|
|
71
|
+
|
|
72
|
+
| From | Allowed targets |
|
|
73
|
+
| ------------- | ------------------------------------- |
|
|
74
|
+
| `pending` | `in_progress`, `completed`, `deleted` |
|
|
75
|
+
| `in_progress` | `pending`, `completed`, `deleted` |
|
|
76
|
+
| `completed` | `deleted` |
|
|
77
|
+
| `deleted` | _(terminal)_ |
|
|
78
|
+
|
|
79
|
+
A transition to the current status is always accepted and reported as a no-op.
|
|
80
|
+
`delete` keeps the task as a tombstone so historic `blockedBy` references still
|
|
81
|
+
resolve; tombstones are hidden from `list` unless you pass `includeDeleted: true`.
|
|
82
|
+
|
|
83
|
+
## Dependencies
|
|
84
|
+
|
|
85
|
+
`blockedBy` holds the ids this task waits on. Validation runs before the state
|
|
86
|
+
is mutated, so a rejected call leaves the list untouched:
|
|
87
|
+
|
|
88
|
+
- a dependency id that does not exist is rejected;
|
|
89
|
+
- a dependency that is already tombstoned is rejected;
|
|
90
|
+
- blocking a task on itself is rejected;
|
|
91
|
+
- an `addBlockedBy` that would close a cycle in the graph is rejected.
|
|
92
|
+
|
|
93
|
+
`get` also reports the reverse edges as a `blocks:` line, derived from the other
|
|
94
|
+
tasks' `blockedBy` arrays.
|
|
95
|
+
|
|
96
|
+
## Return envelope
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
{
|
|
100
|
+
content: [{ type: "text", text: string }], // human-readable summary of the op
|
|
101
|
+
details: { // compact persisted operation record
|
|
102
|
+
action: TaskAction,
|
|
103
|
+
params: Record<string, unknown>,
|
|
104
|
+
// The live in-memory result also exposes tasks and nextId as compatibility
|
|
105
|
+
// properties; they are omitted from newly serialized session JSON.
|
|
106
|
+
tasks: Array<{
|
|
107
|
+
id: number,
|
|
108
|
+
subject: string,
|
|
109
|
+
description?: string,
|
|
110
|
+
activeForm?: string,
|
|
111
|
+
status: "pending" | "in_progress" | "completed" | "deleted",
|
|
112
|
+
blockedBy?: number[],
|
|
113
|
+
owner?: string,
|
|
114
|
+
metadata?: Record<string, unknown>,
|
|
115
|
+
}>,
|
|
116
|
+
nextId: number,
|
|
117
|
+
taskStatus?: TaskStatus, // render hint for updates without a status parameter
|
|
118
|
+
error?: string, // present only on a rejected call
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Persistence
|
|
124
|
+
|
|
125
|
+
`details` is the persistence boundary. New serialized records contain the
|
|
126
|
+
`action` and `params` needed to replay the operation; they do not repeat the
|
|
127
|
+
cumulative `tasks` and `nextId` snapshot. State-changing calls also save the same
|
|
128
|
+
compact record as a `rpiv-todo-state` custom entry on the session branch. Custom
|
|
129
|
+
entries are never sent to the model.
|
|
130
|
+
|
|
131
|
+
The custom entry matters when `todo` is called from another tool, such as a Pi
|
|
132
|
+
codemode script: Pi records that call only as a short summary on the outer
|
|
133
|
+
tool's result, so its own `details` never reach the branch. Direct calls that
|
|
134
|
+
produce both records are replayed from the custom stream once, not twice.
|
|
135
|
+
|
|
136
|
+
The session-lifecycle handlers rebuild state by replaying compact records in
|
|
137
|
+
branch order. Legacy sessions containing full `tasks`/`nextId` snapshots remain
|
|
138
|
+
supported, and mixed legacy/compact branches are accepted. Either way, tasks
|
|
139
|
+
survive `/reload`, `/resume`, `/tree` and compaction without any disk writes.
|
|
140
|
+
|
|
141
|
+
## Content strings
|
|
142
|
+
|
|
143
|
+
| Situation | `content[0].text` |
|
|
144
|
+
| ------------------------------- | -------------------------------------------------------------------------- |
|
|
145
|
+
| Created | `Created #3: Write the parser (pending)` |
|
|
146
|
+
| Created a batch | one `Created #N: … (pending)` line per task, joined by newlines |
|
|
147
|
+
| Updated with a status change | `Updated #3 (pending → in_progress)` |
|
|
148
|
+
| Updated without a status change | `Updated #3` |
|
|
149
|
+
| Update that changed nothing | `No change: #3 already matches the requested values (status: in_progress)` |
|
|
150
|
+
| Deleted | `Deleted #3: Write the parser` |
|
|
151
|
+
| Cleared | `Cleared 7 tasks` |
|
|
152
|
+
| `list` row | `[in_progress] #3 Write the parser (writing the parser) ⛓ #1,#2` |
|
|
153
|
+
| `list` with nothing to show | `No tasks` |
|
|
154
|
+
| Any rejection | `Error: <message>` |
|
|
155
|
+
|
|
156
|
+
The `No change` reply exists so a model that re-issues an identical update sees
|
|
157
|
+
that it was a no-op instead of a fresh `Updated #N`.
|
|
158
|
+
|
|
159
|
+
## Error messages
|
|
160
|
+
|
|
161
|
+
| Message | Cause |
|
|
162
|
+
| ----------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
163
|
+
| `subject required for create` | `create` without a non-blank `subject` and without `tasks[]`. |
|
|
164
|
+
| `create requires subject or tasks[], not both` | `create` with both `subject` and `tasks[]`. |
|
|
165
|
+
| `tasks[] must be non-empty` | `create` with `tasks: []`. |
|
|
166
|
+
| `create with tasks[] takes <fields> on each item, not at the top level` | `create` with `tasks[]` and a top-level `description`, `activeForm`, `blockedBy`, `owner`, or `metadata`. |
|
|
167
|
+
| `tasks[N]: subject required for create` | A batch item with a blank or missing subject. |
|
|
168
|
+
| `blockedBy: #N not found` | `create` naming an unknown dependency. |
|
|
169
|
+
| `blockedBy: #N is deleted` | `create` naming a tombstoned dependency. |
|
|
170
|
+
| `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. |
|
|
171
|
+
| `id required for update` / `get` / `delete` | `id` omitted. |
|
|
172
|
+
| `#N not found` | No task with that id. |
|
|
173
|
+
| `update requires at least one mutable field: subject, description, activeForm, status, owner, metadata, addBlockedBy, or removeBlockedBy` | `update` with only an `id`. |
|
|
174
|
+
| `illegal transition completed → in_progress` | Target status not reachable from the current one. |
|
|
175
|
+
| `cannot block #N on itself` | `addBlockedBy` includes the task's own id. |
|
|
176
|
+
| `addBlockedBy: #N not found` / `is deleted` | Unknown or tombstoned dependency. |
|
|
177
|
+
| `addBlockedBy would create a cycle in the blockedBy graph` | The edge would close a cycle. |
|
|
178
|
+
| `#N is already deleted` | `delete` on a tombstone. |
|
|
179
|
+
|
|
180
|
+
Errors are returned in-band: `content` carries `Error: …` and `details.error`
|
|
181
|
+
carries the bare message. Task state is unchanged.
|
|
182
|
+
|
|
183
|
+
## Prompt guidance
|
|
184
|
+
|
|
185
|
+
The tool ships a `promptSnippet` and nine `promptGuidelines` bullets telling the
|
|
186
|
+
model when to open a list, to create independent tasks in one `tasks[]` call,
|
|
187
|
+
to keep exactly one task `in_progress`, to mark work completed immediately
|
|
188
|
+
rather than in batches, never to complete a task with failing tests, and the
|
|
189
|
+
literal `update {id, status}` call shape for changing a task's status. Both are
|
|
190
|
+
overridable — see
|
|
191
|
+
[configuration.md](./configuration.md#guidance).
|
package/index.ts
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* rpiv-todo — Pi extension. Registers the `todo` tool, `/todos` slash
|
|
3
|
+
* command, and the persistent TodoOverlay widget.
|
|
4
|
+
*
|
|
5
|
+
* TUI chrome strings localize at render time via the i18n bridge. Strings are
|
|
6
|
+
* registered with rpiv-i18n here, once, at module init — but only when the
|
|
7
|
+
* SDK is actually installed. If `@juicesharp/rpiv-i18n` is missing (standalone
|
|
8
|
+
* install of just this package), the dynamic-load shim no-ops and the bridge's
|
|
9
|
+
* `t(key, fallback)` returns the inline English literal at every call site.
|
|
10
|
+
* The extension stays online either way.
|
|
11
|
+
*
|
|
12
|
+
* Adding a locale: drop `locales/<code>.json` next to en.json (mirroring the
|
|
13
|
+
* key set). No edit needed here — `registerLocalesFromDir` iterates
|
|
14
|
+
* `SUPPORTED_LOCALES` from the SDK. See `@juicesharp/rpiv-i18n` README →
|
|
15
|
+
* "Contributing translations" for the full convention.
|
|
16
|
+
*
|
|
17
|
+
* Extracted from rpiv-pi@7525a5d. Tool name "todo" and widget key
|
|
18
|
+
* "rpiv-todos" preserved verbatim so existing session history replays
|
|
19
|
+
* correctly after upgrade.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { ExtensionAPI, ExtensionUIContext } from "@earendil-works/pi-coding-agent";
|
|
23
|
+
import type { KeyId } from "@earendil-works/pi-tui";
|
|
24
|
+
import { COLLAPSE_KEY_OFF, resolveCollapseKey } from "./config.ts";
|
|
25
|
+
import { I18N_NAMESPACE } from "./state/i18n-bridge.ts";
|
|
26
|
+
import { replayFromBranch } from "./state/replay.ts";
|
|
27
|
+
import {
|
|
28
|
+
clearActiveRenderSession,
|
|
29
|
+
evictSession,
|
|
30
|
+
getActiveRenderSession,
|
|
31
|
+
getRenderState,
|
|
32
|
+
replaceState,
|
|
33
|
+
setActiveRenderSession,
|
|
34
|
+
sid,
|
|
35
|
+
} from "./state/store.ts";
|
|
36
|
+
import { registerTodosCommand, registerTodoTool, TOOL_NAME } from "./todo.ts";
|
|
37
|
+
import type { TodoOverlay } from "./todo-overlay.ts";
|
|
38
|
+
|
|
39
|
+
type I18nLoader = {
|
|
40
|
+
registerLocalesFromDir: (
|
|
41
|
+
namespace: string,
|
|
42
|
+
packageUrl: string,
|
|
43
|
+
options?: { label?: string },
|
|
44
|
+
) => void;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Delay the overlay graph pre-warm until Pi's startup work has settled. */
|
|
48
|
+
export const PREWARM_DELAY_MS = 2000;
|
|
49
|
+
|
|
50
|
+
type TodoOverlayModule = typeof import("./todo-overlay.ts");
|
|
51
|
+
type TodoOverlayImporter = () => Promise<TodoOverlayModule>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Marker shared by the loader's poisoned-namespace error and the
|
|
55
|
+
* `isStaleOverlayModuleError` predicate that lets handlers re-throw it while
|
|
56
|
+
* swallowing transient load failures.
|
|
57
|
+
*/
|
|
58
|
+
const STALE_OVERLAY_MESSAGE = "Todo overlay module cache is stale; restart Pi";
|
|
59
|
+
|
|
60
|
+
/** True for the loader's latched poisoned-namespace error (see below). */
|
|
61
|
+
export function isStaleOverlayModuleError(e: unknown): boolean {
|
|
62
|
+
return String(e).includes(STALE_OVERLAY_MESSAGE);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Memoize the overlay graph after a successful load, but drop a rejected
|
|
67
|
+
* promise so a failed pre-warm does not permanently replay the same rejection.
|
|
68
|
+
* The export guard turns jiti's poisoned-namespace failure into a useful restart
|
|
69
|
+
* error instead of a bare "TodoOverlay is not a constructor" TypeError.
|
|
70
|
+
*/
|
|
71
|
+
export function makeTodoOverlayLoader(
|
|
72
|
+
importOverlay: TodoOverlayImporter = () => import("./todo-overlay.ts"),
|
|
73
|
+
): TodoOverlayImporter {
|
|
74
|
+
let memo: Promise<TodoOverlayModule> | undefined;
|
|
75
|
+
|
|
76
|
+
return async (): Promise<TodoOverlayModule> => {
|
|
77
|
+
memo ??= importOverlay();
|
|
78
|
+
const current = memo;
|
|
79
|
+
let mod: TodoOverlayModule;
|
|
80
|
+
try {
|
|
81
|
+
mod = await current;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
// Clear only OUR rejected promise: a late catch from a concurrent
|
|
84
|
+
// awaiter must never clobber a fresh retry another caller installed.
|
|
85
|
+
if (memo === current) memo = undefined;
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
if (typeof mod.TodoOverlay !== "function") {
|
|
89
|
+
// Deliberately latched: the memo keeps this resolved-but-poisoned
|
|
90
|
+
// namespace, so every subsequent load re-throws instead of retrying.
|
|
91
|
+
// Re-importing would hand back the same cached jiti namespace — a
|
|
92
|
+
// retry can never heal this; only the restart the error asks for can.
|
|
93
|
+
const keys = JSON.stringify(Object.keys(mod));
|
|
94
|
+
throw new Error(`${STALE_OVERLAY_MESSAGE} (resolved namespace keys: ${keys})`);
|
|
95
|
+
}
|
|
96
|
+
return mod;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Dynamic import keeps `@juicesharp/rpiv-i18n` a soft optional peer: when the
|
|
101
|
+
// SDK is installed alongside this package the strings register and
|
|
102
|
+
// `/languages` flips them live; when it isn't, the import rejects here, we
|
|
103
|
+
// no-op, and the bridge's English-fallback shim keeps the extension online.
|
|
104
|
+
//
|
|
105
|
+
// The `/loader` subpath is used instead of the SDK entry so the i18n-ui +
|
|
106
|
+
// pi-tui modules are not pulled into our load graph just to register strings.
|
|
107
|
+
try {
|
|
108
|
+
const sdk = (await import("@juicesharp/rpiv-i18n/loader")) as I18nLoader;
|
|
109
|
+
sdk.registerLocalesFromDir(I18N_NAMESPACE, import.meta.url, { label: "rpiv-todo" });
|
|
110
|
+
} catch {
|
|
111
|
+
// SDK absent — extension still loads with English-only UI.
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// pi-core's ExtensionRunner throws this exact phrase from an invalidated ctx
|
|
115
|
+
// proxy after session replacement/reload. Match the stable substring so genuine
|
|
116
|
+
// replay bugs still propagate instead of being silently swallowed.
|
|
117
|
+
function isStaleCtxError(e: unknown): boolean {
|
|
118
|
+
return /stale after session replacement/.test(String(e));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Render a caught `unknown` as a human-readable message — the `instanceof Error`
|
|
123
|
+
* dance collapsed to one place. Local copy of the `formatError` in
|
|
124
|
+
* packages/rpiv-workflow/internal-utils.ts:56-58 (that module disclaims its
|
|
125
|
+
* public surface, so the cross-package import is not available). M2 boundary
|
|
126
|
+
* duplication: tracked as a documented-constant seam.
|
|
127
|
+
*/
|
|
128
|
+
function formatError(e: unknown): string {
|
|
129
|
+
return e instanceof Error ? e.message : String(e);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export default function (
|
|
133
|
+
pi: ExtensionAPI,
|
|
134
|
+
importOverlay: TodoOverlayImporter = () => import("./todo-overlay.ts"),
|
|
135
|
+
) {
|
|
136
|
+
let todoOverlay: TodoOverlay | undefined;
|
|
137
|
+
const loadTodoOverlay = makeTodoOverlayLoader(importOverlay);
|
|
138
|
+
let uiCtx: ExtensionUIContext | undefined;
|
|
139
|
+
let lifecycleGeneration = 0;
|
|
140
|
+
|
|
141
|
+
async function updateTodoOverlay(
|
|
142
|
+
resetCompletedDisplayState = false,
|
|
143
|
+
generation = lifecycleGeneration,
|
|
144
|
+
): Promise<void> {
|
|
145
|
+
const hasVisibleTasks = getRenderState().tasks.some((task) => task.status !== "deleted");
|
|
146
|
+
if (!uiCtx || (!todoOverlay && !hasVisibleTasks)) return;
|
|
147
|
+
|
|
148
|
+
const { TodoOverlay } = await loadTodoOverlay();
|
|
149
|
+
if (generation !== lifecycleGeneration || !uiCtx) return;
|
|
150
|
+
|
|
151
|
+
todoOverlay ??= new TodoOverlay();
|
|
152
|
+
todoOverlay.setUICtx(uiCtx);
|
|
153
|
+
if (resetCompletedDisplayState) todoOverlay.resetCompletedDisplayState();
|
|
154
|
+
todoOverlay.update();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
registerTodoTool(pi);
|
|
158
|
+
registerTodosCommand(pi);
|
|
159
|
+
|
|
160
|
+
// Collapse/expand hotkey for the todo overlay. The key is resolved once at
|
|
161
|
+
// factory scope from config (register-once contract: a config change needs
|
|
162
|
+
// `/reload` to re-bind, same as lane-switcher's env hotkey) and the binding is
|
|
163
|
+
// skipped entirely when collapseKey is "off". The handler closes over the
|
|
164
|
+
// closure-local `todoOverlay` by reference and re-reads it at fire time, so an
|
|
165
|
+
// overlay loaded after shortcut registration is picked up. No-op in headless
|
|
166
|
+
// mode, before the overlay has loaded, or when the widget isn't currently
|
|
167
|
+
// registered (auto-hidden on an empty list).
|
|
168
|
+
const collapseKey = resolveCollapseKey();
|
|
169
|
+
if (collapseKey !== COLLAPSE_KEY_OFF) {
|
|
170
|
+
pi.registerShortcut(collapseKey as KeyId, {
|
|
171
|
+
description: "Collapse or expand the todo overlay",
|
|
172
|
+
handler: (ctx) => {
|
|
173
|
+
if (!ctx.hasUI || !todoOverlay?.isRegistered()) return;
|
|
174
|
+
todoOverlay.toggleCollapse();
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Re-key a session's slot from its branch, then refresh the overlay only when
|
|
180
|
+
// the refreshed session IS the foreground. Shared by session_compact and
|
|
181
|
+
// session_tree (verbatim-identical pre-extraction). A stale ctx (auto-compaction
|
|
182
|
+
// races session disposal: pi-core invalidates the runner while still emitting the
|
|
183
|
+
// event, so `ctx` may be a dead proxy whose getters throw) keeps current state —
|
|
184
|
+
// the replacement session's session_start replays it. Other errors are real replay
|
|
185
|
+
// bugs and must propagate. The render is sid-gated so a child never refreshes the
|
|
186
|
+
// foreground overlay.
|
|
187
|
+
const replayAndRefresh = async (
|
|
188
|
+
ctx: Parameters<typeof sid>[0] & Parameters<typeof replayFromBranch>[0],
|
|
189
|
+
): Promise<void> => {
|
|
190
|
+
let isForeground = false;
|
|
191
|
+
try {
|
|
192
|
+
const id = sid(ctx);
|
|
193
|
+
replaceState(id, replayFromBranch(ctx));
|
|
194
|
+
isForeground = id === getActiveRenderSession();
|
|
195
|
+
} catch (e) {
|
|
196
|
+
if (!isStaleCtxError(e)) throw e;
|
|
197
|
+
}
|
|
198
|
+
if (isForeground) await updateTodoOverlay(true);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
202
|
+
let id: string;
|
|
203
|
+
try {
|
|
204
|
+
id = sid(ctx);
|
|
205
|
+
// Every session replays into its OWN data slot (Phase 1 isolation).
|
|
206
|
+
replaceState(id, replayFromBranch(ctx));
|
|
207
|
+
} catch (e) {
|
|
208
|
+
// Parity with compact/tree/shutdown: session_start is the fresh-ctx event
|
|
209
|
+
// so the stale risk is low, but a stale/throwing ctx has nothing to bind —
|
|
210
|
+
// swallow the known stale error and bail; let real replay bugs propagate.
|
|
211
|
+
if (!isStaleCtxError(e)) throw e;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (!ctx.hasUI) return;
|
|
215
|
+
// First UI-bearing session_start claims the foreground (the interactive
|
|
216
|
+
// launcher, by spawn-ordering) without eagerly loading the overlay.
|
|
217
|
+
if (getActiveRenderSession() === "") setActiveRenderSession(id);
|
|
218
|
+
// Only the foreground re-binds/refreshes the shared overlay. A child
|
|
219
|
+
// (distinct sid) is skipped — does not rebind to a relay/stale ui.
|
|
220
|
+
if (id !== getActiveRenderSession()) return;
|
|
221
|
+
const generation = ++lifecycleGeneration;
|
|
222
|
+
uiCtx = ctx.ui;
|
|
223
|
+
await updateTodoOverlay(true, generation);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
pi.on("session_compact", async (_event, ctx) => {
|
|
227
|
+
await replayAndRefresh(ctx);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
pi.on("session_tree", async (_event, ctx) => {
|
|
231
|
+
await replayAndRefresh(ctx);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
235
|
+
// Best-effort sid: disposal can race a stale ctx (like compact). An
|
|
236
|
+
// unknown/stale sid resolves to "" and is treated as foreground — the
|
|
237
|
+
// safe pre-isolation default that disposes as before.
|
|
238
|
+
let s: string;
|
|
239
|
+
try {
|
|
240
|
+
s = sid(ctx);
|
|
241
|
+
} catch (e) {
|
|
242
|
+
if (!isStaleCtxError(e)) throw e;
|
|
243
|
+
s = "";
|
|
244
|
+
}
|
|
245
|
+
// The shutting-down session's own data slot is always evicted.
|
|
246
|
+
evictSession(s);
|
|
247
|
+
// Overlay teardown is sid-gated: a child shutdown (distinct sid) must not
|
|
248
|
+
// dispose the foreground's overlay. Only the foreground's own shutdown
|
|
249
|
+
// (or an unknown/stale sid) tears it down and clears the pointer.
|
|
250
|
+
if (s === "" || s === getActiveRenderSession()) {
|
|
251
|
+
// Invalidate pending imports before clearing the foreground binding so a
|
|
252
|
+
// replaced session cannot inherit the stale overlay or UI context.
|
|
253
|
+
lifecycleGeneration++;
|
|
254
|
+
uiCtx = undefined;
|
|
255
|
+
// `dispose()`'s first act is setWidget(KEY, undefined) on a possibly-stale
|
|
256
|
+
// ui proxy, which can throw. evictSession(s) above already deleted this
|
|
257
|
+
// slot, so leaving `activeRenderSession` pointing at it would resolve
|
|
258
|
+
// getRenderState() to a fresh EMPTY_STATE (overlay silently renders empty).
|
|
259
|
+
// try/finally guarantees the pointer-clear + overlay-drop run regardless.
|
|
260
|
+
try {
|
|
261
|
+
todoOverlay?.dispose();
|
|
262
|
+
} finally {
|
|
263
|
+
todoOverlay = undefined;
|
|
264
|
+
clearActiveRenderSession();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// Reads getTodos() at render time; do NOT call replayFromBranch here
|
|
270
|
+
// (branch is stale — message_end runs after tool_execution_end).
|
|
271
|
+
pi.on("tool_execution_end", async (event) => {
|
|
272
|
+
if (event.toolName !== TOOL_NAME || event.isError) return;
|
|
273
|
+
try {
|
|
274
|
+
await updateTodoOverlay();
|
|
275
|
+
} catch (e) {
|
|
276
|
+
// The tool itself succeeded — a transient overlay-load failure only
|
|
277
|
+
// costs this one refresh, and the loader's cleared memo lets the next
|
|
278
|
+
// update retry. Don't surface that as an extension error. The latched
|
|
279
|
+
// stale-namespace error still propagates: it never self-heals, and the
|
|
280
|
+
// user needs its restart guidance.
|
|
281
|
+
if (isStaleOverlayModuleError(e)) throw e;
|
|
282
|
+
console.warn(
|
|
283
|
+
`[rpiv-todo] overlay refresh failed (will retry on next update): ${formatError(e)}`,
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// Evaluate the lazy graph after startup while Pi's boot-time dependency paths
|
|
289
|
+
// are still stable. This loads no widget and constructs no overlay; those stay
|
|
290
|
+
// deferred until a foreground session has visible tasks. A rejected pre-warm
|
|
291
|
+
// is intentionally swallowed after loadTodoOverlay clears its memo, allowing
|
|
292
|
+
// the first real update to retry. unref avoids holding an embedder open.
|
|
293
|
+
const prewarmTimer = setTimeout(
|
|
294
|
+
() => void loadTodoOverlay().catch(() => undefined),
|
|
295
|
+
PREWARM_DELAY_MS,
|
|
296
|
+
);
|
|
297
|
+
prewarmTimer.unref?.();
|
|
298
|
+
|
|
299
|
+
pi.on("agent_start", async () => {
|
|
300
|
+
todoOverlay?.hideCompletedTasksFromPreviousTurn();
|
|
301
|
+
});
|
|
302
|
+
}
|
package/locales/de.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. Unicode box-drawing characters (──) stay untranslated. Note: 'overlay.more' renders as '+5 weitere' which is grammatically loose for plural agreement — accepted for badge brevity.",
|
|
3
|
+
|
|
4
|
+
"status.pending": "ausstehend",
|
|
5
|
+
"status.in_progress": "in Bearbeitung",
|
|
6
|
+
"status.completed": "erledigt",
|
|
7
|
+
"status.deleted": "gelöscht",
|
|
8
|
+
|
|
9
|
+
"overlay.heading": "Todos",
|
|
10
|
+
"overlay.more": "weitere",
|
|
11
|
+
"overlay.expandHint": "{key} zum Ausklappen",
|
|
12
|
+
"overlay.collapsed": "eingeklappt",
|
|
13
|
+
|
|
14
|
+
"command.no_todos": "Noch keine Todos. Bitte den Agenten, welche hinzuzufügen!",
|
|
15
|
+
"command.requires_interactive": "/todos erfordert den interaktiven Modus",
|
|
16
|
+
"command.section.pending": "── Ausstehend ──",
|
|
17
|
+
"command.section.in_progress": "── In Bearbeitung ──",
|
|
18
|
+
"command.section.completed": "── Erledigt ──"
|
|
19
|
+
}
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"status.pending": "pending",
|
|
3
|
+
"status.in_progress": "in progress",
|
|
4
|
+
"status.completed": "completed",
|
|
5
|
+
"status.deleted": "deleted",
|
|
6
|
+
|
|
7
|
+
"overlay.heading": "Todos",
|
|
8
|
+
"overlay.more": "more",
|
|
9
|
+
"overlay.expandHint": "{key} to expand",
|
|
10
|
+
"overlay.collapsed": "collapsed",
|
|
11
|
+
|
|
12
|
+
"command.no_todos": "No todos yet. Ask the agent to add some!",
|
|
13
|
+
"command.requires_interactive": "/todos requires interactive mode",
|
|
14
|
+
"command.section.pending": "── Pending ──",
|
|
15
|
+
"command.section.in_progress": "── In Progress ──",
|
|
16
|
+
"command.section.completed": "── Completed ──"
|
|
17
|
+
}
|
package/locales/es.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. Unicode box-drawing characters (──) stay untranslated.",
|
|
3
|
+
|
|
4
|
+
"status.pending": "pendientes",
|
|
5
|
+
"status.in_progress": "en curso",
|
|
6
|
+
"status.completed": "completadas",
|
|
7
|
+
"status.deleted": "eliminada",
|
|
8
|
+
|
|
9
|
+
"overlay.heading": "Tareas",
|
|
10
|
+
"overlay.more": "más",
|
|
11
|
+
"overlay.expandHint": "{key} para expandir",
|
|
12
|
+
"overlay.collapsed": "contraído",
|
|
13
|
+
|
|
14
|
+
"command.no_todos": "Sin tareas aún. ¡Pídele al agente que añada algunas!",
|
|
15
|
+
"command.requires_interactive": "/todos requiere modo interactivo",
|
|
16
|
+
"command.section.pending": "── Pendientes ──",
|
|
17
|
+
"command.section.in_progress": "── En curso ──",
|
|
18
|
+
"command.section.completed": "── Completadas ──"
|
|
19
|
+
}
|
package/locales/fr.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. Unicode box-drawing characters (──) stay untranslated.",
|
|
3
|
+
|
|
4
|
+
"status.pending": "en attente",
|
|
5
|
+
"status.in_progress": "en cours",
|
|
6
|
+
"status.completed": "terminées",
|
|
7
|
+
"status.deleted": "supprimée",
|
|
8
|
+
|
|
9
|
+
"overlay.heading": "Tâches",
|
|
10
|
+
"overlay.more": "autres",
|
|
11
|
+
"overlay.expandHint": "{key} pour développer",
|
|
12
|
+
"overlay.collapsed": "réduit",
|
|
13
|
+
|
|
14
|
+
"command.no_todos": "Pas encore de tâches. Demandez à l'agent d'en ajouter !",
|
|
15
|
+
"command.requires_interactive": "/todos nécessite le mode interactif",
|
|
16
|
+
"command.section.pending": "── En attente ──",
|
|
17
|
+
"command.section.in_progress": "── En cours ──",
|
|
18
|
+
"command.section.completed": "── Terminées ──"
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. Unicode box-drawing characters (──) stay untranslated.",
|
|
3
|
+
|
|
4
|
+
"status.pending": "pendentes",
|
|
5
|
+
"status.in_progress": "em andamento",
|
|
6
|
+
"status.completed": "concluídas",
|
|
7
|
+
"status.deleted": "excluída",
|
|
8
|
+
|
|
9
|
+
"overlay.heading": "Tarefas",
|
|
10
|
+
"overlay.more": "mais",
|
|
11
|
+
"overlay.expandHint": "{key} para expandir",
|
|
12
|
+
"overlay.collapsed": "recolhido",
|
|
13
|
+
|
|
14
|
+
"command.no_todos": "Nenhuma tarefa ainda. Peça ao agente para adicionar algumas!",
|
|
15
|
+
"command.requires_interactive": "/todos requer modo interativo",
|
|
16
|
+
"command.section.pending": "── Pendentes ──",
|
|
17
|
+
"command.section.in_progress": "── Em andamento ──",
|
|
18
|
+
"command.section.completed": "── Concluídas ──"
|
|
19
|
+
}
|
package/locales/pt.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. Unicode box-drawing characters (──) stay untranslated.",
|
|
3
|
+
|
|
4
|
+
"status.pending": "pendentes",
|
|
5
|
+
"status.in_progress": "em curso",
|
|
6
|
+
"status.completed": "concluídas",
|
|
7
|
+
"status.deleted": "eliminada",
|
|
8
|
+
|
|
9
|
+
"overlay.heading": "Tarefas",
|
|
10
|
+
"overlay.more": "mais",
|
|
11
|
+
"overlay.expandHint": "{key} para expandir",
|
|
12
|
+
"overlay.collapsed": "recolhido",
|
|
13
|
+
|
|
14
|
+
"command.no_todos": "Sem tarefas ainda. Peça ao agente para adicionar algumas!",
|
|
15
|
+
"command.requires_interactive": "/todos requer modo interativo",
|
|
16
|
+
"command.section.pending": "── Pendentes ──",
|
|
17
|
+
"command.section.in_progress": "── Em curso ──",
|
|
18
|
+
"command.section.completed": "── Concluídas ──"
|
|
19
|
+
}
|
package/locales/ru.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_meta.notes": "Автоперевод. Приветствуется проверка носителем языка через PR. Символы юникода (──) не переводятся.",
|
|
3
|
+
|
|
4
|
+
"status.pending": "ожидание",
|
|
5
|
+
"status.in_progress": "в работе",
|
|
6
|
+
"status.completed": "выполнено",
|
|
7
|
+
"status.deleted": "удалена",
|
|
8
|
+
|
|
9
|
+
"overlay.heading": "Задачи",
|
|
10
|
+
"overlay.more": "ещё",
|
|
11
|
+
"overlay.expandHint": "{key} — развернуть",
|
|
12
|
+
"overlay.collapsed": "свёрнуто",
|
|
13
|
+
|
|
14
|
+
"command.no_todos": "Задач пока нет. Попросите агента добавить!",
|
|
15
|
+
"command.requires_interactive": "/todos требует интерактивного режима",
|
|
16
|
+
"command.section.pending": "── Ожидание ──",
|
|
17
|
+
"command.section.in_progress": "── В работе ──",
|
|
18
|
+
"command.section.completed": "── Выполнено ──"
|
|
19
|
+
}
|
package/locales/uk.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_meta.notes": "Автопереклад. Привітна перевірка носієм мови через PR. Символи юнікоду (──) не перекладаються.",
|
|
3
|
+
|
|
4
|
+
"status.pending": "очікування",
|
|
5
|
+
"status.in_progress": "у роботі",
|
|
6
|
+
"status.completed": "виконано",
|
|
7
|
+
"status.deleted": "видалено",
|
|
8
|
+
|
|
9
|
+
"overlay.heading": "Завдання",
|
|
10
|
+
"overlay.more": "ще",
|
|
11
|
+
"overlay.expandHint": "{key} — розгорнути",
|
|
12
|
+
"overlay.collapsed": "згорнуто",
|
|
13
|
+
|
|
14
|
+
"command.no_todos": "Завдань поки немає. Попросіть агента додати!",
|
|
15
|
+
"command.requires_interactive": "/todos потребує інтерактивного режиму",
|
|
16
|
+
"command.section.pending": "── Очікування ──",
|
|
17
|
+
"command.section.in_progress": "── У роботі ──",
|
|
18
|
+
"command.section.completed": "── Виконано ──"
|
|
19
|
+
}
|