@juicesharp/rpiv-todo 1.20.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -4
- package/config.ts +91 -4
- package/index.ts +102 -28
- package/locales/de.json +2 -0
- package/locales/en.json +2 -0
- package/locales/es.json +2 -0
- package/locales/fr.json +2 -0
- package/locales/pt-BR.json +2 -0
- package/locales/pt.json +2 -0
- package/locales/ru.json +2 -0
- package/locales/uk.json +2 -0
- package/locales/zh.json +2 -0
- package/package.json +4 -4
- package/state/selectors.ts +1 -1
- package/state/state-reducer.ts +42 -2
- package/state/store.ts +95 -23
- package/todo-overlay.ts +46 -10
- package/todo.ts +15 -17
- package/tool/response-envelope.ts +3 -0
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Give the model a todo list it can keep across long sessions. `rpiv-todo` adds th
|
|
|
18
18
|
- **Survives `/reload` and compaction** - tasks replay from the conversation branch, not disk.
|
|
19
19
|
- **Status states** - pending, in_progress, completed, plus a deleted tombstone for audit.
|
|
20
20
|
- **Dependency tracking** - `blockedBy` with cycle detection, so the model can sequence work.
|
|
21
|
-
- **Smart truncation** - 12
|
|
21
|
+
- **Smart truncation** - collapse threshold (default 12, [configurable](#configuration) via `maxWidgetLines`); completed tasks drop first, pending tasks stay visible last.
|
|
22
22
|
|
|
23
23
|
## Install
|
|
24
24
|
|
|
@@ -106,17 +106,47 @@ Returns:
|
|
|
106
106
|
|
|
107
107
|
- **`/todos`** - print the current todo list grouped by status.
|
|
108
108
|
|
|
109
|
+
## Configuration
|
|
110
|
+
|
|
111
|
+
Optional file at `~/.config/rpiv-todo/config.json`:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"maxWidgetLines": 8,
|
|
116
|
+
"collapseKey": "alt+t",
|
|
117
|
+
"guidance": {
|
|
118
|
+
"promptSnippet": "Use the `todo` tool to track multi-step work before starting it.",
|
|
119
|
+
"promptGuidelines": [
|
|
120
|
+
"Create one task per discrete step.",
|
|
121
|
+
"Mark a task in_progress while working on it; completed when done."
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
| Key | Default | Meaning |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| `maxWidgetLines` | `12` | Content-row budget for the overlay (useful on low-height terminals). The heading and, on overflow, the `+N more` summary row count against this budget — only the trailing spacer sits outside it, so `12` renders up to 13 rows total. Floor of `3`: lower values fall back to the default, as do non-numeric values. Applied on the next repaint — no `/reload` required. |
|
|
130
|
+
| `collapseKey` | `"ctrl+shift+t"` | Shortcut that collapses/expands the overlay, in pi keybinding format (`modifier+key`, e.g. `alt+o`, `ctrl+shift+t`; modifiers: `ctrl`, `shift`, `alt`, `super`). Set to `"off"` to disable the shortcut entirely. Invalid or non-string values fall back to the default. The shortcut binds once at extension load — after changing this value, run `/reload` to re-bind (the collapsed hint text updates on the next repaint, but the old key stays active until `/reload`). |
|
|
131
|
+
| `guidance` | _(absent)_ | LLM guidance overrides (`promptSnippet`, `promptGuidelines`) — optional; absent by default. |
|
|
132
|
+
|
|
133
|
+
Missing or malformed file falls back to defaults - no config required.
|
|
134
|
+
|
|
109
135
|
## Overlay
|
|
110
136
|
|
|
111
137
|
The aboveEditor widget auto-renders whenever any overlay-visible tasks exist.
|
|
112
138
|
Completed tasks stay visible after completion until the next agent response
|
|
113
|
-
starts, then disappear from later overlay renders.
|
|
114
|
-
|
|
139
|
+
starts, then disappear from later overlay renders. Collapse threshold
|
|
140
|
+
defaults to 12 lines (configurable via `maxWidgetLines` — see [Configuration](#configuration)); completed tasks still drop first on overflow, pending tasks
|
|
115
141
|
truncate last. Auto-hides when the list is empty.
|
|
116
142
|
|
|
143
|
+
Press `ctrl+shift+t` (configurable via `collapseKey` — see
|
|
144
|
+
[Configuration](#configuration)) to collapse the overlay down to its heading
|
|
145
|
+
plus a one-line expand hint; press it again to expand.
|
|
146
|
+
|
|
117
147
|
## Localization
|
|
118
148
|
|
|
119
|
-
`rpiv-todo` localizes its TUI chrome (overlay heading, `/todos` section headers, status words) through `@juicesharp/rpiv-i18n` when the SDK is installed. Bundled locales: `de`, `en`, `es`, `fr`, `pt`, `pt-BR`, `ru`, `uk`. LLM-facing output (tool response envelope, reducer errors, schema descriptions) stays English by design.
|
|
149
|
+
`rpiv-todo` localizes its TUI chrome (overlay heading, `/todos` section headers, status words) through `@juicesharp/rpiv-i18n` when the SDK is installed. Bundled locales: `de`, `en`, `es`, `fr`, `pt`, `pt-BR`, `ru`, `uk`, `zh`. LLM-facing output (tool response envelope, reducer errors, schema descriptions) stays English by design.
|
|
120
150
|
|
|
121
151
|
The SDK is a soft optional peer - `rpiv-todo` loads it via dynamic import at module init. If the SDK isn't installed, every render call site returns its inline English fallback and the extension stays online with English UI; no warning, no crash. See the Install section for adding the SDK after the fact. To contribute or override translations, see the `@juicesharp/rpiv-i18n` README "Contributing translations" section.
|
|
122
152
|
|
package/config.ts
CHANGED
|
@@ -1,14 +1,101 @@
|
|
|
1
1
|
import type { GuidanceFields } from "@juicesharp/rpiv-config";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const CONFIG_PATH = configPath("rpiv-todo");
|
|
2
|
+
import { loadJsonConfigWithLegacyFallback, validateGuidanceFields } from "@juicesharp/rpiv-config";
|
|
5
3
|
|
|
6
4
|
interface TodoConfig {
|
|
7
5
|
guidance?: GuidanceFields;
|
|
6
|
+
maxWidgetLines?: number;
|
|
7
|
+
/**
|
|
8
|
+
* Key spec for the overlay collapse/expand shortcut, in the same format as
|
|
9
|
+
* pi-coding-agent keybinding ids (`modifier+key`, e.g. `ctrl+shift+t`, `alt+o`).
|
|
10
|
+
* Defaults to `"ctrl+shift+t"`. Pass `"off"` to disable the collapse shortcut
|
|
11
|
+
* entirely. Validation happens in `resolveCollapseKey`, not at load.
|
|
12
|
+
*/
|
|
13
|
+
collapseKey?: string;
|
|
8
14
|
}
|
|
9
15
|
|
|
16
|
+
/** Default content-row budget when the config is missing/invalid — the prior
|
|
17
|
+
* hardcoded value, preserved as the fallback. */
|
|
18
|
+
export const DEFAULT_MAX_WIDGET_LINES = 12;
|
|
19
|
+
|
|
20
|
+
/** Key spec for the overlay collapse/expand shortcut, e.g. `"ctrl+shift+t"` or `"alt+o"`. */
|
|
21
|
+
export type CollapseKeySpec = string;
|
|
22
|
+
|
|
23
|
+
/** Default collapse/expand key when `collapseKey` is missing/empty/blank/invalid. */
|
|
24
|
+
export const DEFAULT_COLLAPSE_KEY: CollapseKeySpec = "ctrl+shift+t";
|
|
25
|
+
|
|
26
|
+
/** Sentinel value for `collapseKey` that disables the collapse shortcut entirely. */
|
|
27
|
+
export const COLLAPSE_KEY_OFF: CollapseKeySpec = "off";
|
|
28
|
+
|
|
10
29
|
export function loadConfig(): TodoConfig {
|
|
11
|
-
return
|
|
30
|
+
return loadJsonConfigWithLegacyFallback<TodoConfig>("rpiv-todo");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Content-row budget for the overlay, read fresh on every call (per-render —
|
|
34
|
+
* no `/reload`). Mirrors warp's getHeartbeatMs minus its `=== 0` disabled
|
|
35
|
+
* sentinel: a non-number or a value below the floor of 3 falls back to the
|
|
36
|
+
* default; no ceiling. */
|
|
37
|
+
export function getMaxWidgetLines(): number {
|
|
38
|
+
const config = loadConfig();
|
|
39
|
+
const lines = config.maxWidgetLines;
|
|
40
|
+
if (typeof lines !== "number" || lines < 3) return DEFAULT_MAX_WIDGET_LINES;
|
|
41
|
+
return lines;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Named keys accepted by pi-tui's `matchesKey` (keys.js switch on the parsed base key).
|
|
45
|
+
// parseKeyId lowercases the id before matching, so lowercase spellings are canonical.
|
|
46
|
+
const SPECIAL_KEYS = new Set([
|
|
47
|
+
"escape",
|
|
48
|
+
"esc",
|
|
49
|
+
"enter",
|
|
50
|
+
"return",
|
|
51
|
+
"tab",
|
|
52
|
+
"space",
|
|
53
|
+
"backspace",
|
|
54
|
+
"delete",
|
|
55
|
+
"insert",
|
|
56
|
+
"clear",
|
|
57
|
+
"home",
|
|
58
|
+
"end",
|
|
59
|
+
"pageup",
|
|
60
|
+
"pagedown",
|
|
61
|
+
"up",
|
|
62
|
+
"down",
|
|
63
|
+
"left",
|
|
64
|
+
"right",
|
|
65
|
+
...Array.from({ length: 12 }, (_, i) => `f${i + 1}`),
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
const MODIFIERS = new Set(["ctrl", "shift", "alt", "super"]);
|
|
69
|
+
|
|
70
|
+
/** Validate a collapse-key spec against pi-tui's KeyId grammar (verbatim port from
|
|
71
|
+
* rpiv-ask-user-question). Exported for unit tests. */
|
|
72
|
+
export function isValidCollapseKeySpec(spec: string): boolean {
|
|
73
|
+
// Mirror pi-tui's KeyId grammar strictly: zero or more distinct modifiers, then a
|
|
74
|
+
// base key that is a single printable character or a named special key. A loose
|
|
75
|
+
// check is not enough — pi-tui's `parseKeyId` takes the LAST `+`-part as the key
|
|
76
|
+
// and ignores unknown parts, so a typo like `ctr+]` would silently match every
|
|
77
|
+
// bare `]` keypress (and the raw terminal listener would consume them globally).
|
|
78
|
+
if (!spec) return false;
|
|
79
|
+
if (spec.startsWith("+") || spec.endsWith("+") || spec.includes("++")) return false;
|
|
80
|
+
const parts = spec.split("+");
|
|
81
|
+
const base = parts[parts.length - 1] ?? "";
|
|
82
|
+
const modifiers = parts.slice(0, -1);
|
|
83
|
+
if (modifiers.length !== new Set(modifiers).size) return false;
|
|
84
|
+
if (!modifiers.every((m) => MODIFIERS.has(m))) return false;
|
|
85
|
+
return base.length === 1 ? /[a-z0-9_\-!@#$%^&*()|~`'":;,./<>?[\]{}=\\]/.test(base) : SPECIAL_KEYS.has(base);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Resolve the collapse/expand key from config, read fresh on every call
|
|
89
|
+
* (per-render / per-registration — no `/reload`); mirrors getMaxWidgetLines().
|
|
90
|
+
* Returns DEFAULT_COLLAPSE_KEY when the field is missing/non-string/empty/blank/
|
|
91
|
+
* invalid, COLLAPSE_KEY_OFF when set to the sentinel, or the lowercased validated
|
|
92
|
+
* spec. */
|
|
93
|
+
export function resolveCollapseKey(): CollapseKeySpec {
|
|
94
|
+
const config = loadConfig();
|
|
95
|
+
const raw = typeof config.collapseKey === "string" ? config.collapseKey.trim().toLowerCase() : undefined;
|
|
96
|
+
if (raw === undefined || raw === "") return DEFAULT_COLLAPSE_KEY;
|
|
97
|
+
if (raw === COLLAPSE_KEY_OFF) return COLLAPSE_KEY_OFF;
|
|
98
|
+
return isValidCollapseKeySpec(raw) ? raw : DEFAULT_COLLAPSE_KEY;
|
|
12
99
|
}
|
|
13
100
|
|
|
14
101
|
export { validateGuidanceFields };
|
package/index.ts
CHANGED
|
@@ -20,9 +20,18 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
23
|
+
import type { KeyId } from "@earendil-works/pi-tui";
|
|
24
|
+
import { COLLAPSE_KEY_OFF, resolveCollapseKey } from "./config.js";
|
|
23
25
|
import { I18N_NAMESPACE } from "./state/i18n-bridge.js";
|
|
24
26
|
import { replayFromBranch } from "./state/replay.js";
|
|
25
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
clearActiveRenderSession,
|
|
29
|
+
evictSession,
|
|
30
|
+
getActiveRenderSession,
|
|
31
|
+
replaceState,
|
|
32
|
+
setActiveRenderSession,
|
|
33
|
+
sid,
|
|
34
|
+
} from "./state/store.js";
|
|
26
35
|
import { registerTodosCommand, registerTodoTool, TOOL_NAME } from "./todo.js";
|
|
27
36
|
import { TodoOverlay } from "./todo-overlay.js";
|
|
28
37
|
|
|
@@ -58,45 +67,110 @@ export default function (pi: ExtensionAPI) {
|
|
|
58
67
|
registerTodoTool(pi);
|
|
59
68
|
registerTodosCommand(pi);
|
|
60
69
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
// Collapse/expand hotkey for the todo overlay. The key is resolved once at
|
|
71
|
+
// factory scope from config (register-once contract: a config change needs
|
|
72
|
+
// `/reload` to re-bind, same as lane-switcher's env hotkey) and the binding is
|
|
73
|
+
// skipped entirely when collapseKey is "off". The handler closes over the
|
|
74
|
+
// closure-local `todoOverlay` by reference and re-reads it at fire time, so a
|
|
75
|
+
// session_start that (re)creates the overlay is picked up. No-op in headless
|
|
76
|
+
// mode, when the overlay hasn't been created yet, or when the widget isn't
|
|
77
|
+
// currently registered (auto-hidden on an empty list).
|
|
78
|
+
const collapseKey = resolveCollapseKey();
|
|
79
|
+
if (collapseKey !== COLLAPSE_KEY_OFF) {
|
|
80
|
+
pi.registerShortcut(collapseKey as KeyId, {
|
|
81
|
+
description: "Collapse or expand the todo overlay",
|
|
82
|
+
handler: (ctx) => {
|
|
83
|
+
if (!ctx.hasUI || !todoOverlay?.isRegistered()) return;
|
|
84
|
+
todoOverlay.toggleCollapse();
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
70
88
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
89
|
+
// Re-key a session's slot from its branch, then refresh the overlay only when
|
|
90
|
+
// the refreshed session IS the foreground. Shared by session_compact and
|
|
91
|
+
// session_tree (verbatim-identical pre-extraction). A stale ctx (auto-compaction
|
|
92
|
+
// races session disposal: pi-core invalidates the runner while still emitting the
|
|
93
|
+
// event, so `ctx` may be a dead proxy whose getters throw) keeps current state —
|
|
94
|
+
// the replacement session's session_start replays it. Other errors are real replay
|
|
95
|
+
// bugs and must propagate. The render is sid-gated so a child never refreshes the
|
|
96
|
+
// foreground overlay.
|
|
97
|
+
const replayAndRefresh = (ctx: Parameters<typeof sid>[0] & Parameters<typeof replayFromBranch>[0]): void => {
|
|
98
|
+
let isForeground = false;
|
|
78
99
|
try {
|
|
79
|
-
|
|
100
|
+
const id = sid(ctx);
|
|
101
|
+
replaceState(id, replayFromBranch(ctx));
|
|
102
|
+
isForeground = id === getActiveRenderSession();
|
|
80
103
|
} catch (e) {
|
|
81
104
|
if (!isStaleCtxError(e)) throw e;
|
|
82
105
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
106
|
+
if (isForeground) {
|
|
107
|
+
todoOverlay?.resetCompletedDisplayState();
|
|
108
|
+
todoOverlay?.update();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
86
111
|
|
|
87
|
-
pi.on("
|
|
112
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
113
|
+
let id: string;
|
|
88
114
|
try {
|
|
89
|
-
|
|
115
|
+
id = sid(ctx);
|
|
116
|
+
// Every session replays into its OWN data slot (Phase 1 isolation).
|
|
117
|
+
replaceState(id, replayFromBranch(ctx));
|
|
90
118
|
} catch (e) {
|
|
119
|
+
// Parity with compact/tree/shutdown: session_start is the fresh-ctx event
|
|
120
|
+
// so the stale risk is low, but a stale/throwing ctx has nothing to bind —
|
|
121
|
+
// swallow the known stale error and bail; let real replay bugs propagate.
|
|
91
122
|
if (!isStaleCtxError(e)) throw e;
|
|
123
|
+
return;
|
|
92
124
|
}
|
|
93
|
-
|
|
94
|
-
|
|
125
|
+
if (!ctx.hasUI) return;
|
|
126
|
+
// First UI-bearing session_start claims the foreground (the interactive
|
|
127
|
+
// launcher, by spawn-ordering). A child hitting a live overlay cannot
|
|
128
|
+
// clobber the pointer — `todoOverlay` is already set.
|
|
129
|
+
if (todoOverlay === undefined) {
|
|
130
|
+
todoOverlay = new TodoOverlay();
|
|
131
|
+
setActiveRenderSession(id);
|
|
132
|
+
}
|
|
133
|
+
// Only the foreground re-binds/refreshes the shared overlay. A child
|
|
134
|
+
// (distinct sid) is skipped — does not rebind to a relay/stale ui.
|
|
135
|
+
if (id !== getActiveRenderSession()) return;
|
|
136
|
+
todoOverlay.setUICtx(ctx.ui);
|
|
137
|
+
todoOverlay.resetCompletedDisplayState();
|
|
138
|
+
todoOverlay.update();
|
|
95
139
|
});
|
|
96
140
|
|
|
97
|
-
pi.on("
|
|
98
|
-
|
|
99
|
-
|
|
141
|
+
pi.on("session_compact", async (_event, ctx) => replayAndRefresh(ctx));
|
|
142
|
+
|
|
143
|
+
pi.on("session_tree", async (_event, ctx) => replayAndRefresh(ctx));
|
|
144
|
+
|
|
145
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
146
|
+
// Best-effort sid: disposal can race a stale ctx (like compact). An
|
|
147
|
+
// unknown/stale sid resolves to "" and is treated as foreground — the
|
|
148
|
+
// safe pre-isolation default that disposes as before.
|
|
149
|
+
let s: string;
|
|
150
|
+
try {
|
|
151
|
+
s = sid(ctx);
|
|
152
|
+
} catch (e) {
|
|
153
|
+
if (!isStaleCtxError(e)) throw e;
|
|
154
|
+
s = "";
|
|
155
|
+
}
|
|
156
|
+
// The shutting-down session's own data slot is always evicted.
|
|
157
|
+
evictSession(s);
|
|
158
|
+
// Overlay teardown is sid-gated: a child shutdown (distinct sid) must not
|
|
159
|
+
// dispose the foreground's overlay. Only the foreground's own shutdown
|
|
160
|
+
// (or an unknown/stale sid) tears it down and clears the pointer.
|
|
161
|
+
if (s === "" || s === getActiveRenderSession()) {
|
|
162
|
+
// `dispose()`'s first act is setWidget(KEY, undefined) on a possibly-stale
|
|
163
|
+
// ui proxy, which can throw. evictSession(s) above already deleted this
|
|
164
|
+
// slot, so leaving `activeRenderSession` pointing at it would resolve
|
|
165
|
+
// getRenderState() to a fresh EMPTY_STATE (overlay silently renders empty).
|
|
166
|
+
// try/finally guarantees the pointer-clear + overlay-drop run regardless.
|
|
167
|
+
try {
|
|
168
|
+
todoOverlay?.dispose();
|
|
169
|
+
} finally {
|
|
170
|
+
todoOverlay = undefined;
|
|
171
|
+
clearActiveRenderSession();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
100
174
|
});
|
|
101
175
|
|
|
102
176
|
// Reads getTodos() at render time; do NOT call replayFromBranch here
|
package/locales/de.json
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
"overlay.heading": "Todos",
|
|
10
10
|
"overlay.more": "weitere",
|
|
11
|
+
"overlay.expandHint": "{key} zum Ausklappen",
|
|
12
|
+
"overlay.collapsed": "eingeklappt",
|
|
11
13
|
|
|
12
14
|
"command.no_todos": "Noch keine Todos. Bitte den Agenten, welche hinzuzufügen!",
|
|
13
15
|
"command.requires_interactive": "/todos erfordert den interaktiven Modus",
|
package/locales/en.json
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
"overlay.heading": "Todos",
|
|
8
8
|
"overlay.more": "more",
|
|
9
|
+
"overlay.expandHint": "{key} to expand",
|
|
10
|
+
"overlay.collapsed": "collapsed",
|
|
9
11
|
|
|
10
12
|
"command.no_todos": "No todos yet. Ask the agent to add some!",
|
|
11
13
|
"command.requires_interactive": "/todos requires interactive mode",
|
package/locales/es.json
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
"overlay.heading": "Tareas",
|
|
10
10
|
"overlay.more": "más",
|
|
11
|
+
"overlay.expandHint": "{key} para expandir",
|
|
12
|
+
"overlay.collapsed": "contraído",
|
|
11
13
|
|
|
12
14
|
"command.no_todos": "Sin tareas aún. ¡Pídele al agente que añada algunas!",
|
|
13
15
|
"command.requires_interactive": "/todos requiere modo interactivo",
|
package/locales/fr.json
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
"overlay.heading": "Tâches",
|
|
10
10
|
"overlay.more": "autres",
|
|
11
|
+
"overlay.expandHint": "{key} pour développer",
|
|
12
|
+
"overlay.collapsed": "réduit",
|
|
11
13
|
|
|
12
14
|
"command.no_todos": "Pas encore de tâches. Demandez à l'agent d'en ajouter !",
|
|
13
15
|
"command.requires_interactive": "/todos nécessite le mode interactif",
|
package/locales/pt-BR.json
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
"overlay.heading": "Tarefas",
|
|
10
10
|
"overlay.more": "mais",
|
|
11
|
+
"overlay.expandHint": "{key} para expandir",
|
|
12
|
+
"overlay.collapsed": "recolhido",
|
|
11
13
|
|
|
12
14
|
"command.no_todos": "Nenhuma tarefa ainda. Peça ao agente para adicionar algumas!",
|
|
13
15
|
"command.requires_interactive": "/todos requer modo interativo",
|
package/locales/pt.json
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
"overlay.heading": "Tarefas",
|
|
10
10
|
"overlay.more": "mais",
|
|
11
|
+
"overlay.expandHint": "{key} para expandir",
|
|
12
|
+
"overlay.collapsed": "recolhido",
|
|
11
13
|
|
|
12
14
|
"command.no_todos": "Sem tarefas ainda. Peça ao agente para adicionar algumas!",
|
|
13
15
|
"command.requires_interactive": "/todos requer modo interativo",
|
package/locales/ru.json
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
"overlay.heading": "Задачи",
|
|
10
10
|
"overlay.more": "ещё",
|
|
11
|
+
"overlay.expandHint": "{key} — развернуть",
|
|
12
|
+
"overlay.collapsed": "свёрнуто",
|
|
11
13
|
|
|
12
14
|
"command.no_todos": "Задач пока нет. Попросите агента добавить!",
|
|
13
15
|
"command.requires_interactive": "/todos требует интерактивного режима",
|
package/locales/uk.json
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
"overlay.heading": "Завдання",
|
|
10
10
|
"overlay.more": "ще",
|
|
11
|
+
"overlay.expandHint": "{key} — розгорнути",
|
|
12
|
+
"overlay.collapsed": "згорнуто",
|
|
11
13
|
|
|
12
14
|
"command.no_todos": "Завдань поки немає. Попросіть агента додати!",
|
|
13
15
|
"command.requires_interactive": "/todos потребує інтерактивного режиму",
|
package/locales/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-todo",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Pi extension. A todo list for the model, rendered as a live overlay that survives /reload and conversation compaction.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -55,8 +55,7 @@
|
|
|
55
55
|
"@juicesharp/rpiv-i18n": "*",
|
|
56
56
|
"@earendil-works/pi-ai": "*",
|
|
57
57
|
"@earendil-works/pi-coding-agent": "*",
|
|
58
|
-
"@earendil-works/pi-tui": "*"
|
|
59
|
-
"typebox": "*"
|
|
58
|
+
"@earendil-works/pi-tui": "*"
|
|
60
59
|
},
|
|
61
60
|
"peerDependenciesMeta": {
|
|
62
61
|
"@juicesharp/rpiv-i18n": {
|
|
@@ -64,6 +63,7 @@
|
|
|
64
63
|
}
|
|
65
64
|
},
|
|
66
65
|
"dependencies": {
|
|
67
|
-
"@juicesharp/rpiv-config": "^
|
|
66
|
+
"@juicesharp/rpiv-config": "^2.0.0",
|
|
67
|
+
"typebox": "^1.1.24"
|
|
68
68
|
}
|
|
69
69
|
}
|
package/state/selectors.ts
CHANGED
|
@@ -64,7 +64,7 @@ export function selectTaskSubjectById(state: TaskState, id: number): string | un
|
|
|
64
64
|
* Overlay layout decision. Encapsulates the "drop completed first, then
|
|
65
65
|
* truncate non-completed tail" rule pre-refactor lived in
|
|
66
66
|
* `todo-overlay.ts:144-188`. `budget` is the body-slot count (caller passes
|
|
67
|
-
* `
|
|
67
|
+
* `getMaxWidgetLines() - 1` to reserve the heading row); on overflow the
|
|
68
68
|
* selector reserves one more slot internally for the summary row. Returns
|
|
69
69
|
* the visible task slice plus the overflow summary parts.
|
|
70
70
|
*/
|
package/state/state-reducer.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { detectCycle } from "./task-graph.js";
|
|
|
14
14
|
*/
|
|
15
15
|
export type Op =
|
|
16
16
|
| { kind: "create"; taskId: number }
|
|
17
|
-
| { kind: "update"; id: number; fromStatus: TaskStatus; toStatus: TaskStatus }
|
|
17
|
+
| { kind: "update"; id: number; fromStatus: TaskStatus; toStatus: TaskStatus; changed: boolean }
|
|
18
18
|
| { kind: "delete"; id: number; subject: string }
|
|
19
19
|
| { kind: "list"; statusFilter?: TaskStatus; includeDeleted: boolean }
|
|
20
20
|
| { kind: "get"; task: Task }
|
|
@@ -30,6 +30,40 @@ function errorResult(state: TaskState, message: string): ApplyResult {
|
|
|
30
30
|
return { state, op: { kind: "error", message } };
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function sameNumberList(a: number[] | undefined, b: number[] | undefined): boolean {
|
|
34
|
+
const x = a ?? [];
|
|
35
|
+
const y = b ?? [];
|
|
36
|
+
return x.length === y.length && x.every((v, i) => v === y[i]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function sameRecord(a: Record<string, unknown> | undefined, b: Record<string, unknown> | undefined): boolean {
|
|
40
|
+
return JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Did this `update` change anything? Compares the task before/after the params
|
|
45
|
+
* are applied. A no-effect update — `status` set to its current value, or any
|
|
46
|
+
* field re-sent unchanged — returns false, letting the response envelope say
|
|
47
|
+
* "No change" instead of "Updated #N". Without this, a no-op update is
|
|
48
|
+
* indistinguishable from a real mutation, which can drive a model to re-issue
|
|
49
|
+
* the same call in a loop.
|
|
50
|
+
*
|
|
51
|
+
* blockedBy is order-sensitive (the reducer preserves insertion order);
|
|
52
|
+
* metadata round-trips through JSON persistence, so JSON-equality is the
|
|
53
|
+
* operative notion of "changed".
|
|
54
|
+
*/
|
|
55
|
+
function taskChanged(before: Task, after: Task): boolean {
|
|
56
|
+
return (
|
|
57
|
+
before.subject !== after.subject ||
|
|
58
|
+
before.status !== after.status ||
|
|
59
|
+
before.description !== after.description ||
|
|
60
|
+
before.activeForm !== after.activeForm ||
|
|
61
|
+
before.owner !== after.owner ||
|
|
62
|
+
!sameNumberList(before.blockedBy, after.blockedBy) ||
|
|
63
|
+
!sameRecord(before.metadata, after.metadata)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
33
67
|
/**
|
|
34
68
|
* Pure reducer: (state, action, params) → (state, op). Mirrors the
|
|
35
69
|
* `applyTaskMutation` of pre-refactor `todo.ts` minus content/details
|
|
@@ -139,7 +173,13 @@ export function applyTaskMutation(state: TaskState, action: TaskAction, params:
|
|
|
139
173
|
newTasks[idx] = updated;
|
|
140
174
|
return {
|
|
141
175
|
state: { tasks: newTasks, nextId: state.nextId },
|
|
142
|
-
op: {
|
|
176
|
+
op: {
|
|
177
|
+
kind: "update",
|
|
178
|
+
id: updated.id,
|
|
179
|
+
fromStatus: current.status,
|
|
180
|
+
toStatus: newStatus,
|
|
181
|
+
changed: taskChanged(current, updated),
|
|
182
|
+
},
|
|
143
183
|
};
|
|
144
184
|
}
|
|
145
185
|
|
package/state/store.ts
CHANGED
|
@@ -2,53 +2,125 @@ import type { Task } from "../tool/types.js";
|
|
|
2
2
|
import { EMPTY_STATE, type TaskState } from "./state.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Per-session live state. Pre-refactor this was a single scalar `let state`
|
|
6
|
+
* cell; it is now a Map partitioned by session id so a detached/child session
|
|
7
|
+
* (distinct sid) can never read or clobber another session's tasks.
|
|
8
|
+
*
|
|
9
|
+
* The Map is the single mutation seam — only `commitState` / `replaceState` /
|
|
10
|
+
* `evictSession` write it; the reducer (`state/state-reducer.ts`) stays pure.
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
const sessions = new Map<string, TaskState>();
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
+
* Ctx-less render pointer: which slot do the ctx-free readers (the overlay's
|
|
16
|
+
* `getSnapshot()`, the tool's `renderCall()`) render? Set once at overlay
|
|
17
|
+
* creation by the session that first built the overlay (creator-ownership —
|
|
18
|
+
* see `index.ts`). A *distinct* concept from the three task-state mutation
|
|
19
|
+
* seams; it is not a 4th writer of task state.
|
|
15
20
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
let activeRenderSession = "";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Session-id extractor. Structural ctx type (no Pi-runtime import) —
|
|
25
|
+
* mirrors `replay.ts`'s ctx shape so `state/` stays Pi-import-free. Returns
|
|
26
|
+
* `… ?? ""` so an unknown/empty session resolves to "" rather than undefined
|
|
27
|
+
* (keeps the key a plain string for callers and the Phase 2 sid-gate).
|
|
28
|
+
*/
|
|
29
|
+
export function sid(ctx: { sessionManager: { getSessionId(): string } }): string {
|
|
30
|
+
return ctx.sessionManager.getSessionId() ?? "";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Fresh, non-aliasing EMPTY_STATE copy (never returns `EMPTY_STATE.tasks`). */
|
|
34
|
+
function freshState(): TaskState {
|
|
35
|
+
return { tasks: [...EMPTY_STATE.tasks], nextId: EMPTY_STATE.nextId };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Get-or-read a session's slot: the committed slot by identity, or a fresh
|
|
39
|
+
* EMPTY_STATE copy (not stored) when the slot is absent. */
|
|
40
|
+
function slotFor(sessionId: string): TaskState {
|
|
41
|
+
return sessions.get(sessionId) ?? freshState();
|
|
18
42
|
}
|
|
19
43
|
|
|
20
|
-
|
|
21
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Live tasks accessor for a session. Returned `readonly Task[]` so callers
|
|
46
|
+
* (overlay render hook, `/todos` command, `renderCall` subject lookup) cannot
|
|
47
|
+
* mutate the live slot. Consumers must not cast back.
|
|
48
|
+
*/
|
|
49
|
+
export function getTodos(sessionId: string): readonly Task[] {
|
|
50
|
+
return slotFor(sessionId).tasks;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function getNextId(sessionId: string): number {
|
|
54
|
+
return slotFor(sessionId).nextId;
|
|
22
55
|
}
|
|
23
56
|
|
|
24
57
|
/** Snapshot accessor used by reducer callers to pass canonical state in. */
|
|
25
|
-
export function getState(): TaskState {
|
|
26
|
-
return
|
|
58
|
+
export function getState(sessionId: string): TaskState {
|
|
59
|
+
return slotFor(sessionId);
|
|
27
60
|
}
|
|
28
61
|
|
|
29
62
|
/**
|
|
30
63
|
* Replay seam. Lifecycle handlers in `index.ts` call this on
|
|
31
64
|
* `session_start` / `session_compact` / `session_tree` after
|
|
32
|
-
* `replayFromBranch` decodes the latest snapshot.
|
|
65
|
+
* `replayFromBranch` decodes the latest snapshot, keyed to the session.
|
|
33
66
|
*/
|
|
34
|
-
export function replaceState(next: TaskState): void {
|
|
35
|
-
|
|
67
|
+
export function replaceState(sessionId: string, next: TaskState): void {
|
|
68
|
+
sessions.set(sessionId, next);
|
|
36
69
|
}
|
|
37
70
|
|
|
38
71
|
/**
|
|
39
|
-
* Post-reducer commit seam. Tool execute() calls this with the reducer's
|
|
72
|
+
* Post-reducer commit seam. Tool `execute()` calls this with the reducer's
|
|
40
73
|
* `state` output to publish the new canonical state to live readers (overlay,
|
|
41
|
-
* `/todos`, renderCall).
|
|
74
|
+
* `/todos`, `renderCall`), keyed to the calling session.
|
|
75
|
+
*/
|
|
76
|
+
export function commitState(sessionId: string, next: TaskState): void {
|
|
77
|
+
sessions.set(sessionId, next);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Drop a session's slot on `session_shutdown`. No-op if the slot is absent. */
|
|
81
|
+
export function evictSession(sessionId: string): void {
|
|
82
|
+
sessions.delete(sessionId);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Ctx-less render reader: the slot the overlay / `renderCall` render.
|
|
87
|
+
* Resolves to the `activeRenderSession` slot, or a fresh EMPTY_STATE copy when
|
|
88
|
+
* no foreground has been set yet.
|
|
89
|
+
*/
|
|
90
|
+
export function getRenderState(): TaskState {
|
|
91
|
+
return slotFor(activeRenderSession);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Set the ctx-less render pointer (called at overlay creation in `index.ts`). */
|
|
95
|
+
export function setActiveRenderSession(sessionId: string): void {
|
|
96
|
+
activeRenderSession = sessionId;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Reads the foreground render pointer — the sid the `index.ts` sid-gate compares
|
|
101
|
+
* against, and the slot `getRenderState()` resolves to. Distinct from
|
|
102
|
+
* `setActiveRenderSession` (the writer): Slice 1 only ever *set* the pointer;
|
|
103
|
+
* Slice 2's gate must also *read* it, and foreground teardown must *clear* it.
|
|
104
|
+
*/
|
|
105
|
+
export function getActiveRenderSession(): string {
|
|
106
|
+
return activeRenderSession;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Foreground teardown (session_shutdown of the foreground session). Resets the
|
|
111
|
+
* pointer to "" so the next `hasUI` session_start reclaims the foreground.
|
|
42
112
|
*/
|
|
43
|
-
export function
|
|
44
|
-
|
|
113
|
+
export function clearActiveRenderSession(): void {
|
|
114
|
+
activeRenderSession = "";
|
|
45
115
|
}
|
|
46
116
|
|
|
47
117
|
/**
|
|
48
118
|
* Test-setup reset. Wired into the global `test/setup.ts` `beforeEach` via
|
|
49
|
-
* the existing `__resetState` import path.
|
|
50
|
-
*
|
|
119
|
+
* the existing `__resetState` import path. Signature unchanged ⇒ no
|
|
120
|
+
* `test/setup.ts` edit needed. Clears BOTH the session Map and the render
|
|
121
|
+
* pointer so filesystem/detect resets start from a clean state.
|
|
51
122
|
*/
|
|
52
123
|
export function __resetState(): void {
|
|
53
|
-
|
|
124
|
+
sessions.clear();
|
|
125
|
+
activeRenderSession = "";
|
|
54
126
|
}
|
package/todo-overlay.ts
CHANGED
|
@@ -3,28 +3,30 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Lifecycle controller for Pi's `setWidget` contract: factory-form
|
|
5
5
|
* registration in widgetContainerAbove, register-once + requestRender()
|
|
6
|
-
* refresh,
|
|
7
|
-
*
|
|
6
|
+
* refresh, configurable collapse-not-scroll (default 12 content rows via
|
|
7
|
+
* getMaxWidgetLines(); plus a trailing spacer row so the widget renders up
|
|
8
|
+
* to 13 lines), auto-hide when empty.
|
|
8
9
|
*
|
|
9
|
-
* Reads live state via `
|
|
10
|
-
* from `tool_execution_end` (branch is stale;
|
|
10
|
+
* Reads live state via `getRenderState()` (the ctx-less foreground slot) at render
|
|
11
|
+
* time — NEVER `replayFromBranch` from `tool_execution_end` (branch is stale;
|
|
12
|
+
* `message_end` runs after).
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
import type { ExtensionUIContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
14
16
|
import { type TUI, truncateToWidth } from "@earendil-works/pi-tui";
|
|
17
|
+
import { COLLAPSE_KEY_OFF, getMaxWidgetLines, resolveCollapseKey } from "./config.js";
|
|
15
18
|
import { formatStatusLabel, t } from "./state/i18n-bridge.js";
|
|
16
19
|
import { selectHasActive, selectOverlayLayout, selectShowTaskIds, selectTodoCounts } from "./state/selectors.js";
|
|
17
|
-
import {
|
|
20
|
+
import { getRenderState } from "./state/store.js";
|
|
18
21
|
import { formatOverlayTaskLine } from "./view/format.js";
|
|
19
22
|
|
|
20
23
|
const WIDGET_KEY = "rpiv-todos";
|
|
21
|
-
// Budget for content rows (heading + tasks/summary). The rendered widget is
|
|
22
|
-
// one line taller — withTrailingSpacer() appends a blank row below the panel.
|
|
23
|
-
const MAX_WIDGET_LINES = 12;
|
|
24
24
|
|
|
25
25
|
// English fallbacks for localized overlay chrome strings.
|
|
26
26
|
const OVERLAY_HEADING = "Todos";
|
|
27
27
|
const OVERLAY_MORE = "more";
|
|
28
|
+
const OVERLAY_EXPAND_HINT = "{key} to expand";
|
|
29
|
+
const OVERLAY_COLLAPSED = "collapsed";
|
|
28
30
|
|
|
29
31
|
export class TodoOverlay {
|
|
30
32
|
private uiCtx: ExtensionUIContext | undefined;
|
|
@@ -33,6 +35,7 @@ export class TodoOverlay {
|
|
|
33
35
|
private completedTaskIdsPendingHide = new Set<number>();
|
|
34
36
|
private hiddenCompletedTaskIds = new Set<number>();
|
|
35
37
|
private lastNextId: number | undefined;
|
|
38
|
+
private collapsed = false;
|
|
36
39
|
|
|
37
40
|
setUICtx(ctx: ExtensionUIContext): void {
|
|
38
41
|
// Identity-compare so repeat session_start handlers are idempotent;
|
|
@@ -94,8 +97,20 @@ export class TodoOverlay {
|
|
|
94
97
|
this.tui?.requestRender();
|
|
95
98
|
}
|
|
96
99
|
|
|
100
|
+
toggleCollapse(): void {
|
|
101
|
+
this.collapsed = !this.collapsed;
|
|
102
|
+
// Forced full redraw on the collapsed↔expanded height step, mirroring the
|
|
103
|
+
// lane-dock's requestRender(shapeChanged); distinct from the non-forced
|
|
104
|
+
// requestRender() refresh paths in update()/hideCompletedTasksFromPreviousTurn().
|
|
105
|
+
this.tui?.requestRender(true);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
isRegistered(): boolean {
|
|
109
|
+
return this.widgetRegistered;
|
|
110
|
+
}
|
|
111
|
+
|
|
97
112
|
private getSnapshot() {
|
|
98
|
-
const state =
|
|
113
|
+
const state = getRenderState();
|
|
99
114
|
if (this.lastNextId !== undefined && state.nextId < this.lastNextId) {
|
|
100
115
|
this.resetCompletedDisplayState();
|
|
101
116
|
}
|
|
@@ -136,8 +151,28 @@ export class TodoOverlay {
|
|
|
136
151
|
const headingText = `${t("overlay.heading", OVERLAY_HEADING)} (${counts.completed}/${counts.total})`;
|
|
137
152
|
const heading = truncate(`${theme.fg(headingColor, headingIcon)} ${theme.fg(headingColor, headingText)}`);
|
|
138
153
|
|
|
154
|
+
// Collapsed view: just the heading + a dim "└─" expand hint, then the
|
|
155
|
+
// trailing spacer. Short-circuit before the budget math and the completed-
|
|
156
|
+
// display tracking — nothing is shown to track, and skipping the tracking
|
|
157
|
+
// when nothing is rendered is correctness, not optimization. The hint splices
|
|
158
|
+
// the resolved key into the {key} placeholder (per-render, like the row
|
|
159
|
+
// budget); a config edit needs /reload to re-bind the actual shortcut. The
|
|
160
|
+
// "off" sentinel is reachable here mid-session (config edited after the
|
|
161
|
+
// shortcut was bound and the overlay collapsed) — render a static collapsed
|
|
162
|
+
// label instead of splicing the sentinel into the placeholder.
|
|
163
|
+
if (this.collapsed) {
|
|
164
|
+
const key = resolveCollapseKey();
|
|
165
|
+
const hint =
|
|
166
|
+
key === COLLAPSE_KEY_OFF
|
|
167
|
+
? t("overlay.collapsed", OVERLAY_COLLAPSED)
|
|
168
|
+
: t("overlay.expandHint", OVERLAY_EXPAND_HINT).replace("{key}", key);
|
|
169
|
+
return this.withTrailingSpacer([heading, truncate(`${theme.fg("dim", "└─")} ${theme.fg("dim", hint)}`)]);
|
|
170
|
+
}
|
|
171
|
+
|
|
139
172
|
const lines: string[] = [heading];
|
|
140
|
-
|
|
173
|
+
// Budget for content rows (heading + tasks/summary). The rendered widget is
|
|
174
|
+
// one line taller — withTrailingSpacer() appends a blank row below the panel.
|
|
175
|
+
const layout = selectOverlayLayout(overlayState, getMaxWidgetLines() - 1);
|
|
141
176
|
for (const task of layout.visible) {
|
|
142
177
|
lines.push(truncate(`${theme.fg("dim", "├─")} ${formatOverlayTaskLine(task, theme, showIds)}`));
|
|
143
178
|
}
|
|
@@ -189,6 +224,7 @@ export class TodoOverlay {
|
|
|
189
224
|
this.widgetRegistered = false;
|
|
190
225
|
this.tui = undefined;
|
|
191
226
|
this.uiCtx = undefined;
|
|
227
|
+
this.collapsed = false;
|
|
192
228
|
this.resetCompletedDisplayState();
|
|
193
229
|
}
|
|
194
230
|
}
|
package/todo.ts
CHANGED
|
@@ -15,10 +15,9 @@
|
|
|
15
15
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
16
16
|
import { loadConfig, validateGuidanceFields } from "./config.js";
|
|
17
17
|
import { formatStatusLabel, t } from "./state/i18n-bridge.js";
|
|
18
|
-
import { replayFromBranch } from "./state/replay.js";
|
|
19
18
|
import { selectTasksByStatus, selectTodoCounts, selectVisibleTasks } from "./state/selectors.js";
|
|
20
19
|
import { applyTaskMutation } from "./state/state-reducer.js";
|
|
21
|
-
import { commitState, getState,
|
|
20
|
+
import { commitState, getRenderState, getState, sid } from "./state/store.js";
|
|
22
21
|
import { buildToolResult } from "./tool/response-envelope.js";
|
|
23
22
|
import {
|
|
24
23
|
COMMAND_NAME,
|
|
@@ -44,20 +43,11 @@ const SECTION_COMPLETED = "── Completed ──";
|
|
|
44
43
|
|
|
45
44
|
export { isTransitionValid } from "./state/invariants.js";
|
|
46
45
|
export { applyTaskMutation } from "./state/state-reducer.js";
|
|
47
|
-
export { __resetState, getNextId, getTodos } from "./state/store.js";
|
|
46
|
+
export { __resetState, getNextId, getTodos, setActiveRenderSession, sid } from "./state/store.js";
|
|
48
47
|
export { deriveBlocks, detectCycle } from "./state/task-graph.js";
|
|
49
48
|
export type { Task, TaskAction, TaskDetails, TaskStatus } from "./tool/types.js";
|
|
50
49
|
export { TOOL_NAME } from "./tool/types.js";
|
|
51
50
|
|
|
52
|
-
/**
|
|
53
|
-
* Backward-compat replay shim. Pre-refactor `reconstructTodoState(ctx)`
|
|
54
|
-
* mutated module state directly; the new replay seam (`state/replay.ts`)
|
|
55
|
-
* returns a `TaskState` and the caller commits via `replaceState`.
|
|
56
|
-
*/
|
|
57
|
-
export function reconstructTodoState(ctx: Parameters<typeof replayFromBranch>[0]): void {
|
|
58
|
-
replaceState(replayFromBranch(ctx));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
51
|
// ---------------------------------------------------------------------------
|
|
62
52
|
// Tool registration
|
|
63
53
|
// ---------------------------------------------------------------------------
|
|
@@ -84,14 +74,22 @@ export function registerTodoTool(pi: ExtensionAPI): void {
|
|
|
84
74
|
promptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,
|
|
85
75
|
parameters: TodoParamsSchema,
|
|
86
76
|
|
|
87
|
-
async execute(_toolCallId, params, _signal, _onUpdate,
|
|
88
|
-
const result = applyTaskMutation(getState(), params.action, params as TaskMutationParams);
|
|
89
|
-
commitState(result.state);
|
|
77
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
78
|
+
const result = applyTaskMutation(getState(sid(ctx)), params.action, params as TaskMutationParams);
|
|
79
|
+
commitState(sid(ctx), result.state);
|
|
90
80
|
return buildToolResult(params.action, params as TaskMutationParams, result.state, result.op);
|
|
91
81
|
},
|
|
92
82
|
|
|
83
|
+
// renderCall reflects the FOREGROUND slot, not the calling session's. Pi's
|
|
84
|
+
// `ToolRenderContext` carries no session identity (no sessionManager/sessionId),
|
|
85
|
+
// so this ctx-less hook cannot re-key by caller. For the foreground session's
|
|
86
|
+
// own transcript that is exactly right. A detached/child call rendered in the
|
|
87
|
+
// lane-transcript viewer whose task lives only in the child's slot misses the
|
|
88
|
+
// foreground lookup and falls back to `#<id>` (see renderTodoCall). That is the
|
|
89
|
+
// safe outcome: per-session ids restart at 1, so searching sibling slots could
|
|
90
|
+
// surface the WRONG subject — the `#<id>` fallback is intentional, not a gap.
|
|
93
91
|
renderCall(args, theme, _context) {
|
|
94
|
-
return renderTodoCall(args as never, theme,
|
|
92
|
+
return renderTodoCall(args as never, theme, getRenderState());
|
|
95
93
|
},
|
|
96
94
|
|
|
97
95
|
renderResult(result, _opts, theme, _context) {
|
|
@@ -112,7 +110,7 @@ export function registerTodosCommand(pi: ExtensionAPI): void {
|
|
|
112
110
|
ctx.ui.notify(t("command.requires_interactive", ERR_REQUIRES_INTERACTIVE), "error");
|
|
113
111
|
return;
|
|
114
112
|
}
|
|
115
|
-
const state = getState();
|
|
113
|
+
const state = getState(sid(ctx));
|
|
116
114
|
const visible = selectVisibleTasks(state);
|
|
117
115
|
if (visible.length === 0) {
|
|
118
116
|
ctx.ui.notify(t("command.no_todos", MSG_NO_TODOS), "info");
|
|
@@ -49,6 +49,9 @@ export function formatContent(op: Op, state: TaskState): string {
|
|
|
49
49
|
return `Created #${t.id}: ${t.subject} (pending)`;
|
|
50
50
|
}
|
|
51
51
|
case "update": {
|
|
52
|
+
if (!op.changed) {
|
|
53
|
+
return `No change: #${op.id} already matches the requested values (status: ${op.toStatus})`;
|
|
54
|
+
}
|
|
52
55
|
const transition = op.fromStatus !== op.toStatus ? ` (${op.fromStatus} → ${op.toStatus})` : "";
|
|
53
56
|
return `Updated #${op.id}${transition}`;
|
|
54
57
|
}
|