@juicesharp/rpiv-todo 2.14.1 → 2.15.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/package.json +2 -2
- package/state/replay.ts +25 -4
- package/todo.ts +2 -2
- package/view/format.ts +49 -35
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-todo",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.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",
|
|
@@ -71,6 +71,6 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@juicesharp/rpiv-config": "^2.
|
|
74
|
+
"@juicesharp/rpiv-config": "^2.15.0"
|
|
75
75
|
}
|
|
76
76
|
}
|
package/state/replay.ts
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
|
-
import type { TaskDetails } from "../tool/types.ts";
|
|
1
|
+
import type { Task, TaskDetails, TaskStatus } from "../tool/types.ts";
|
|
2
2
|
import { EMPTY_STATE, type TaskState } from "./state.ts";
|
|
3
3
|
|
|
4
|
+
const TASK_STATUSES: ReadonlySet<unknown> = new Set<TaskStatus>(["pending", "in_progress", "completed", "deleted"]);
|
|
5
|
+
|
|
6
|
+
const optional = (value: unknown, valid: (v: unknown) => boolean): boolean => value === undefined || valid(value);
|
|
7
|
+
const isString = (v: unknown): boolean => typeof v === "string";
|
|
8
|
+
|
|
9
|
+
function isTask(value: unknown): value is Task {
|
|
10
|
+
if (!value || typeof value !== "object") return false;
|
|
11
|
+
const t = value as Record<string, unknown>;
|
|
12
|
+
return (
|
|
13
|
+
Number.isSafeInteger(t.id) &&
|
|
14
|
+
typeof t.subject === "string" &&
|
|
15
|
+
TASK_STATUSES.has(t.status) &&
|
|
16
|
+
optional(t.description, isString) &&
|
|
17
|
+
optional(t.activeForm, isString) &&
|
|
18
|
+
optional(t.owner, isString) &&
|
|
19
|
+
optional(t.blockedBy, (v) => Array.isArray(v) && v.every((id) => Number.isSafeInteger(id))) &&
|
|
20
|
+
optional(t.metadata, (v) => typeof v === "object" && v !== null)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
4
24
|
/**
|
|
5
25
|
* Discriminator for `details` envelopes that match the persisted `TaskDetails`
|
|
6
|
-
* shape. Defensive —
|
|
7
|
-
*
|
|
26
|
+
* shape, down to every task. Defensive — a snapshot from an older or corrupt
|
|
27
|
+
* session (e.g. a `tasks[]` another extension truncated with a marker string)
|
|
28
|
+
* is skipped whole, so replay keeps the last valid one.
|
|
8
29
|
*/
|
|
9
30
|
export function isTaskDetails(value: unknown): value is TaskDetails {
|
|
10
31
|
if (!value || typeof value !== "object") return false;
|
|
11
32
|
const v = value as Record<string, unknown>;
|
|
12
|
-
return Array.isArray(v.tasks) &&
|
|
33
|
+
return Array.isArray(v.tasks) && v.tasks.every(isTask) && Number.isSafeInteger(v.nextId);
|
|
13
34
|
}
|
|
14
35
|
|
|
15
36
|
/** Fresh `TaskState` from a persisted snapshot — copies each task so replay never aliases branch data. */
|
package/todo.ts
CHANGED
|
@@ -104,8 +104,8 @@ export function registerTodoTool(pi: ExtensionAPI): void {
|
|
|
104
104
|
return renderTodoCall(args as never, theme, getRenderState());
|
|
105
105
|
},
|
|
106
106
|
|
|
107
|
-
renderResult(result, _opts, theme,
|
|
108
|
-
return renderTodoResult(result, theme);
|
|
107
|
+
renderResult(result, _opts, theme, context) {
|
|
108
|
+
return renderTodoResult(result, theme, context?.isError);
|
|
109
109
|
},
|
|
110
110
|
});
|
|
111
111
|
}
|
package/view/format.ts
CHANGED
|
@@ -24,7 +24,7 @@ export const STATUS_GLYPH: Record<TaskStatus, string> = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Color palette for the renderResult status echo. `deleted` uses `muted` so a
|
|
26
26
|
* successful delete is visually distinct from the error branch (which uses
|
|
27
|
-
* `error` + `✗`)
|
|
27
|
+
* `error` + `✗`).
|
|
28
28
|
*/
|
|
29
29
|
export const STATUS_COLOR: Record<TaskStatus, "dim" | "warning" | "success" | "muted"> = {
|
|
30
30
|
pending: "dim",
|
|
@@ -35,7 +35,7 @@ export const STATUS_COLOR: Record<TaskStatus, "dim" | "warning" | "success" | "m
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Per-action prefix glyph for renderCall. `+` create, `→` update, `×` delete,
|
|
38
|
-
* `›` get, `☰` list, `∅` clear
|
|
38
|
+
* `›` get, `☰` list, `∅` clear.
|
|
39
39
|
*/
|
|
40
40
|
export const ACTION_GLYPH: Record<TaskAction, string> = {
|
|
41
41
|
create: "+",
|
|
@@ -50,7 +50,7 @@ export const ACTION_GLYPH: Record<TaskAction, string> = {
|
|
|
50
50
|
* Glyph for the persistent overlay's per-task row. Differs from `STATUS_GLYPH`
|
|
51
51
|
* for `completed` (`✓` vs `●`) and `deleted` (`✗` vs `⊘`) because the
|
|
52
52
|
* overlay caller never renders a `deleted` row but uses `✗` in its
|
|
53
|
-
* error-toned palette
|
|
53
|
+
* error-toned palette.
|
|
54
54
|
*/
|
|
55
55
|
export function overlayStatusGlyph(status: TaskStatus, theme: Theme): string {
|
|
56
56
|
switch (status) {
|
|
@@ -91,7 +91,7 @@ export function formatOverlayTaskLine(t: Task, theme: Theme, showId: boolean): s
|
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
93
|
* Format a single task line for the `/todos` slash command (no glyph color,
|
|
94
|
-
* indented bullet prefix).
|
|
94
|
+
* indented bullet prefix).
|
|
95
95
|
*/
|
|
96
96
|
export function formatCommandTaskLine(t: Task, glyph: string): string {
|
|
97
97
|
const form = t.status === "in_progress" && t.activeForm ? ` (${sanitizeTerminalText(t.activeForm)})` : "";
|
|
@@ -104,17 +104,17 @@ export function formatCommandTaskLine(t: Task, glyph: string): string {
|
|
|
104
104
|
// ---------------------------------------------------------------------------
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
|
-
* `renderCall` body. Receives the
|
|
108
|
-
* `TaskState` (resolved by the caller via `
|
|
109
|
-
*
|
|
107
|
+
* `renderCall` body. Receives the call's args, the theme, and the live
|
|
108
|
+
* `TaskState` (resolved by the caller via `getRenderState()`). The args may
|
|
109
|
+
* still be streaming or may fail validation, so `action` can be absent.
|
|
110
110
|
*/
|
|
111
111
|
export function renderTodoCall(
|
|
112
|
-
args: TaskMutationParams & { action
|
|
112
|
+
args: TaskMutationParams & { action?: TaskAction },
|
|
113
113
|
theme: Theme,
|
|
114
114
|
state: TaskState,
|
|
115
115
|
): Text {
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
let text = theme.fg("toolTitle", theme.bold("todo "));
|
|
117
|
+
if (args.action) text += theme.fg("muted", ACTION_GLYPH[args.action] ?? args.action);
|
|
118
118
|
|
|
119
119
|
if (args.action === "create" && args.subject) {
|
|
120
120
|
text += ` ${theme.fg("dim", sanitizeTerminalText(args.subject))}`;
|
|
@@ -133,34 +133,48 @@ export function renderTodoCall(
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
|
-
* `renderResult` body.
|
|
137
|
-
*
|
|
138
|
-
* fall back to plain `✓`). Identical visual output to pre-refactor
|
|
139
|
-
* `todo.ts:533-565`.
|
|
136
|
+
* `renderResult` body. A failed call renders `✗` with its reason; a successful
|
|
137
|
+
* `create`/`update`/`delete` echoes the task's status; anything else is `✓`.
|
|
140
138
|
*/
|
|
141
|
-
export function renderTodoResult(result:
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
switch (details.action) {
|
|
147
|
-
case "create":
|
|
148
|
-
status = details.tasks[details.tasks.length - 1]?.status;
|
|
149
|
-
break;
|
|
150
|
-
case "update":
|
|
151
|
-
status = params.status ?? details.tasks.find((t) => t.id === params.id)?.status;
|
|
152
|
-
break;
|
|
153
|
-
case "delete":
|
|
154
|
-
status = details.tasks.find((t) => t.id === params.id)?.status;
|
|
155
|
-
break;
|
|
156
|
-
case "list":
|
|
157
|
-
case "get":
|
|
158
|
-
case "clear":
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
139
|
+
export function renderTodoResult(result: ToolResultView, theme: Theme, isError = false): Text {
|
|
140
|
+
const failure = failureReason(result, isError);
|
|
141
|
+
if (failure !== undefined) return new Text(theme.fg("error", failure ? `✗ ${failure}` : "✗"), 0, 0);
|
|
142
|
+
|
|
143
|
+
const status = echoedStatus(result.details as TaskDetails | undefined);
|
|
162
144
|
if (status) {
|
|
163
145
|
return new Text(theme.fg(STATUS_COLOR[status], `${STATUS_GLYPH[status]} ${formatStatusLabel(status)}`), 0, 0);
|
|
164
146
|
}
|
|
165
147
|
return new Text(theme.fg("success", "✓"), 0, 0);
|
|
166
148
|
}
|
|
149
|
+
|
|
150
|
+
type ToolResultView = { content?: Array<{ type: string; text?: string }>; details?: unknown };
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* First line of the failure message, or `undefined` when the call succeeded.
|
|
154
|
+
* The reducer reports through `details.error`; Pi rejects a call before execute
|
|
155
|
+
* with `isError` and the message as text content.
|
|
156
|
+
*/
|
|
157
|
+
function failureReason(result: ToolResultView, isError: boolean): string | undefined {
|
|
158
|
+
const reducerError = (result.details as TaskDetails | undefined)?.error;
|
|
159
|
+
if (!isError && !reducerError) return undefined;
|
|
160
|
+
const message = reducerError ?? result.content?.find((c) => c.type === "text")?.text ?? "";
|
|
161
|
+
return sanitizeTerminalText(message.split("\n")[0]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Status the result card echoes: the task the call created, updated or deleted. */
|
|
165
|
+
function echoedStatus(details: TaskDetails | undefined): TaskStatus | undefined {
|
|
166
|
+
if (!details) return undefined;
|
|
167
|
+
const params = details.params as TaskMutationParams;
|
|
168
|
+
switch (details.action) {
|
|
169
|
+
case "create":
|
|
170
|
+
return details.tasks.at(-1)?.status;
|
|
171
|
+
case "update":
|
|
172
|
+
return params.status ?? details.tasks.find((t) => t.id === params.id)?.status;
|
|
173
|
+
case "delete":
|
|
174
|
+
return details.tasks.find((t) => t.id === params.id)?.status;
|
|
175
|
+
case "list":
|
|
176
|
+
case "get":
|
|
177
|
+
case "clear":
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
}
|