@abhishek944/pi-tasks 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/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/command.d.ts +3 -0
- package/dist/command.js +39 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +37 -0
- package/dist/state.d.ts +34 -0
- package/dist/state.js +225 -0
- package/dist/text.d.ts +2 -0
- package/dist/text.js +24 -0
- package/dist/tool-result.d.ts +31 -0
- package/dist/tool-result.js +23 -0
- package/dist/tools.d.ts +3 -0
- package/dist/tools.js +173 -0
- package/dist/tracking.d.ts +2 -0
- package/dist/tracking.js +27 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.js +1 -0
- package/dist/ui/overlay.d.ts +7 -0
- package/dist/ui/overlay.js +50 -0
- package/dist/ui/panel.d.ts +25 -0
- package/dist/ui/panel.js +145 -0
- package/dist/ui/works-dashboard.d.ts +31 -0
- package/dist/ui/works-dashboard.js +168 -0
- package/docs/REFERENCE.md +35 -0
- package/docs/USAGE_GUIDE.md +47 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abhishek Tatikella
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# pi-tasks
|
|
2
|
+
|
|
3
|
+
A Pi extension for session-scoped work and todo tracking.
|
|
4
|
+
|
|
5
|
+
It adds:
|
|
6
|
+
|
|
7
|
+
- `WorkCreate`, `WorkList`, `WorkUpdate`, and `WorkDelete`
|
|
8
|
+
- `TodoCreate`, `TodoList`, `TodoUpdate`, and `TodoDelete`
|
|
9
|
+
- `/works`, a detailed floating dashboard modeled after `pi-loop-monitor`'s `/monitors`
|
|
10
|
+
- a compact floating top-right panel with work and todo names
|
|
11
|
+
- main-conversation guidance that keeps normal requested work current across every Pi skill
|
|
12
|
+
|
|
13
|
+
Works and todos follow the active Pi session branch. Forking or navigating the session tree restores the state for that branch. `/ask` and `/btw` conversations do not update works, todos, loops, or monitors.
|
|
14
|
+
|
|
15
|
+
The coordination model is intentionally small: a work is the overall outcome, a todo is one concrete step under it, a monitor runs one long-lived background command, and a loop schedules a future or repeated wake. Loops and monitors remain owned by `pi-loop-monitor`.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pi install npm:@abhishek944/pi-tasks@0.1.0
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Restart Pi or run `/reload`.
|
|
24
|
+
|
|
25
|
+
## Use
|
|
26
|
+
|
|
27
|
+
The extension guides Pi to manage work automatically for normal requests that start or continue work. You can also call the tools directly:
|
|
28
|
+
|
|
29
|
+
```text
|
|
30
|
+
WorkCreate workName="Add task tracking" workInfo="Detailed goal, scope, constraints, and expected outcome" status="active"
|
|
31
|
+
TodoCreate workId="W1" taskName="Implement state" taskInfo="Detailed task context and expected result" status="active"
|
|
32
|
+
TodoUpdate taskId="T1" status="completed" taskInfo="Implementation is complete; typecheck and build passed."
|
|
33
|
+
WorkUpdate workId="W1" status="completed"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Run `/works` to inspect full `workInfo` and `taskInfo` in an interactive overlay.
|
|
37
|
+
|
|
38
|
+
The panel defaults to the floating top-right layout. Switch layouts at runtime with `/works-panel floating`, `/works-panel widget`, or `/works-panel off`.
|
|
39
|
+
|
|
40
|
+
See [the usage guide](docs/USAGE_GUIDE.md) and [reference](docs/REFERENCE.md).
|
|
41
|
+
|
|
42
|
+
## Development
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm run lint
|
|
46
|
+
npm run typecheck
|
|
47
|
+
npm run build
|
|
48
|
+
npm run audit:production
|
|
49
|
+
```
|
package/dist/command.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { runWorksOverlay } from "./ui/overlay.js";
|
|
2
|
+
import { WorksDashboard } from "./ui/works-dashboard.js";
|
|
3
|
+
export function registerWorksCommand(pi, state) {
|
|
4
|
+
let closeActiveDashboard;
|
|
5
|
+
pi.on("session_shutdown", () => {
|
|
6
|
+
closeActiveDashboard?.();
|
|
7
|
+
closeActiveDashboard = undefined;
|
|
8
|
+
});
|
|
9
|
+
pi.registerCommand("works", {
|
|
10
|
+
description: "Open the session works and todos dashboard",
|
|
11
|
+
handler: async (_args, ctx) => {
|
|
12
|
+
if (ctx.mode !== "tui") {
|
|
13
|
+
ctx.ui.notify("/works requires interactive TUI mode", "error");
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
let commandClose;
|
|
17
|
+
try {
|
|
18
|
+
closeActiveDashboard?.();
|
|
19
|
+
await runWorksOverlay(ctx, (tui, theme, keybindings, close) => {
|
|
20
|
+
const closeCurrent = () => {
|
|
21
|
+
if (closeActiveDashboard === closeCurrent)
|
|
22
|
+
closeActiveDashboard = undefined;
|
|
23
|
+
close();
|
|
24
|
+
};
|
|
25
|
+
commandClose = closeCurrent;
|
|
26
|
+
closeActiveDashboard = closeCurrent;
|
|
27
|
+
return new WorksDashboard(tui, theme, keybindings, state, closeCurrent);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
ctx.ui.notify(error instanceof Error ? error.message : "The works dashboard could not be opened.", "error");
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
if (closeActiveDashboard === commandClose)
|
|
35
|
+
closeActiveDashboard = undefined;
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Session-scoped work and todo tracking for Pi. */
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
export default function tasksExtension(pi: ExtensionAPI): void;
|
|
4
|
+
export type { Todo, TodoStatus, Work, WorkStatus, WorkWithTodos } from "./types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { registerWorksCommand } from "./command.js";
|
|
2
|
+
import { TaskState } from "./state.js";
|
|
3
|
+
import { registerTaskTools } from "./tools.js";
|
|
4
|
+
import { registerTrackingGuidance } from "./tracking.js";
|
|
5
|
+
import { TasksPanelHost } from "./ui/panel.js";
|
|
6
|
+
export default function tasksExtension(pi) {
|
|
7
|
+
let panel;
|
|
8
|
+
const state = new TaskState(pi, () => panel?.update());
|
|
9
|
+
panel = new TasksPanelHost(state);
|
|
10
|
+
registerTaskTools(pi, state);
|
|
11
|
+
registerTrackingGuidance(pi);
|
|
12
|
+
registerWorksCommand(pi, state);
|
|
13
|
+
pi.registerCommand("works-panel", {
|
|
14
|
+
description: "Set the works panel to floating, widget, or off",
|
|
15
|
+
handler: async (args, ctx) => {
|
|
16
|
+
const requested = args.trim();
|
|
17
|
+
const mode = requested === "floating" || requested === "widget" || requested === "off" ? requested : undefined;
|
|
18
|
+
if (!mode) {
|
|
19
|
+
ctx.ui.notify("Usage: /works-panel floating|widget|off", "info");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
panel?.setMode(mode);
|
|
23
|
+
ctx.ui.notify(`Works panel: ${mode}`, "info");
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
pi.on("session_start", (_event, ctx) => {
|
|
27
|
+
state.restore(ctx);
|
|
28
|
+
if (ctx.mode === "tui")
|
|
29
|
+
panel?.attach(ctx.ui);
|
|
30
|
+
});
|
|
31
|
+
pi.on("session_tree", (_event, ctx) => {
|
|
32
|
+
state.restore(ctx);
|
|
33
|
+
});
|
|
34
|
+
pi.on("session_shutdown", () => {
|
|
35
|
+
panel?.hide();
|
|
36
|
+
});
|
|
37
|
+
}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { Todo, TodoStatus, Work, WorkStatus, WorkWithTodos } from "./types.js";
|
|
3
|
+
export declare const TASK_ENTRY_TYPE = "pi-tasks-state";
|
|
4
|
+
export declare const MAX_WORKS = 100;
|
|
5
|
+
export declare const MAX_TODOS = 500;
|
|
6
|
+
export declare class TaskState {
|
|
7
|
+
private readonly pi;
|
|
8
|
+
private readonly onChange;
|
|
9
|
+
private works;
|
|
10
|
+
private todos;
|
|
11
|
+
private nextWorkId;
|
|
12
|
+
private nextTaskId;
|
|
13
|
+
constructor(pi: ExtensionAPI, onChange: () => void);
|
|
14
|
+
restore(ctx: ExtensionContext): void;
|
|
15
|
+
listWorks(filter?: {
|
|
16
|
+
workId?: string;
|
|
17
|
+
status?: WorkStatus;
|
|
18
|
+
}): WorkWithTodos[];
|
|
19
|
+
listTodos(filter?: {
|
|
20
|
+
taskId?: string;
|
|
21
|
+
workId?: string;
|
|
22
|
+
status?: TodoStatus;
|
|
23
|
+
}): Todo[];
|
|
24
|
+
getWork(workId: string): Work | undefined;
|
|
25
|
+
getTodo(taskId: string): Todo | undefined;
|
|
26
|
+
createWork(workName: string, workInfo: string, status?: WorkStatus): Work;
|
|
27
|
+
updateWork(workId: string, patch: Partial<Pick<Work, "workName" | "workInfo" | "status">>): Work;
|
|
28
|
+
deleteWork(workId: string): boolean;
|
|
29
|
+
createTodo(workId: string, taskName: string, taskInfo: string, status?: TodoStatus): Todo;
|
|
30
|
+
updateTodo(taskId: string, patch: Partial<Pick<Todo, "taskName" | "taskInfo" | "status">>): Todo;
|
|
31
|
+
deleteTodo(taskId: string): boolean;
|
|
32
|
+
private record;
|
|
33
|
+
private apply;
|
|
34
|
+
}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { safeSingleLine } from "./text.js";
|
|
2
|
+
export const TASK_ENTRY_TYPE = "pi-tasks-state";
|
|
3
|
+
export const MAX_WORKS = 100;
|
|
4
|
+
export const MAX_TODOS = 500;
|
|
5
|
+
export class TaskState {
|
|
6
|
+
pi;
|
|
7
|
+
onChange;
|
|
8
|
+
works = new Map();
|
|
9
|
+
todos = new Map();
|
|
10
|
+
nextWorkId = 1;
|
|
11
|
+
nextTaskId = 1;
|
|
12
|
+
constructor(pi, onChange) {
|
|
13
|
+
this.pi = pi;
|
|
14
|
+
this.onChange = onChange;
|
|
15
|
+
}
|
|
16
|
+
restore(ctx) {
|
|
17
|
+
this.works.clear();
|
|
18
|
+
this.todos.clear();
|
|
19
|
+
this.nextWorkId = 1;
|
|
20
|
+
this.nextTaskId = 1;
|
|
21
|
+
for (const entry of ctx.sessionManager.getBranch()) {
|
|
22
|
+
if (entry.type !== "custom" || entry.customType !== TASK_ENTRY_TYPE)
|
|
23
|
+
continue;
|
|
24
|
+
const event = parseEvent(entry.data);
|
|
25
|
+
if (!event)
|
|
26
|
+
continue;
|
|
27
|
+
try {
|
|
28
|
+
this.apply(event);
|
|
29
|
+
}
|
|
30
|
+
catch { /* Ignore malformed extension entries and continue replay. */ }
|
|
31
|
+
}
|
|
32
|
+
this.onChange();
|
|
33
|
+
}
|
|
34
|
+
listWorks(filter) {
|
|
35
|
+
return [...this.works.values()]
|
|
36
|
+
.filter((work) => !filter?.workId || work.workId === filter.workId)
|
|
37
|
+
.filter((work) => !filter?.status || work.status === filter.status)
|
|
38
|
+
.sort((left, right) => left.createdAt - right.createdAt)
|
|
39
|
+
.map((work) => ({ ...work, tasks: this.listTodos({ workId: work.workId }) }));
|
|
40
|
+
}
|
|
41
|
+
listTodos(filter) {
|
|
42
|
+
return [...this.todos.values()]
|
|
43
|
+
.filter((todo) => !filter?.taskId || todo.taskId === filter.taskId)
|
|
44
|
+
.filter((todo) => !filter?.workId || todo.workId === filter.workId)
|
|
45
|
+
.filter((todo) => !filter?.status || todo.status === filter.status)
|
|
46
|
+
.sort((left, right) => left.createdAt - right.createdAt)
|
|
47
|
+
.map((todo) => ({ ...todo }));
|
|
48
|
+
}
|
|
49
|
+
getWork(workId) {
|
|
50
|
+
const work = this.works.get(workId);
|
|
51
|
+
return work ? { ...work } : undefined;
|
|
52
|
+
}
|
|
53
|
+
getTodo(taskId) {
|
|
54
|
+
const todo = this.todos.get(taskId);
|
|
55
|
+
return todo ? { ...todo } : undefined;
|
|
56
|
+
}
|
|
57
|
+
createWork(workName, workInfo, status = "planned") {
|
|
58
|
+
if (this.works.size >= MAX_WORKS)
|
|
59
|
+
throw new Error(`Maximum of ${MAX_WORKS} works reached.`);
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
const work = {
|
|
62
|
+
workId: `W${this.nextWorkId}`,
|
|
63
|
+
workName: requiredName(workName, "workName"),
|
|
64
|
+
workInfo: requiredText(workInfo, "workInfo"),
|
|
65
|
+
status,
|
|
66
|
+
createdAt: now,
|
|
67
|
+
updatedAt: now,
|
|
68
|
+
};
|
|
69
|
+
this.record({ version: 1, type: "work-created", at: now, work });
|
|
70
|
+
return { ...work };
|
|
71
|
+
}
|
|
72
|
+
updateWork(workId, patch) {
|
|
73
|
+
if (!this.works.has(workId))
|
|
74
|
+
throw new Error(`Work ${workId} not found.`);
|
|
75
|
+
const normalized = compactPatch({
|
|
76
|
+
workName: patch.workName === undefined ? undefined : requiredName(patch.workName, "workName"),
|
|
77
|
+
workInfo: patch.workInfo === undefined ? undefined : requiredText(patch.workInfo, "workInfo"),
|
|
78
|
+
status: patch.status,
|
|
79
|
+
});
|
|
80
|
+
if (Object.keys(normalized).length === 0)
|
|
81
|
+
throw new Error("WorkUpdate requires at least one changed field.");
|
|
82
|
+
this.record({ version: 1, type: "work-updated", at: Date.now(), workId, patch: normalized });
|
|
83
|
+
return this.getWork(workId);
|
|
84
|
+
}
|
|
85
|
+
deleteWork(workId) {
|
|
86
|
+
if (!this.works.has(workId))
|
|
87
|
+
return false;
|
|
88
|
+
this.record({ version: 1, type: "work-deleted", at: Date.now(), workId });
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
createTodo(workId, taskName, taskInfo, status = "pending") {
|
|
92
|
+
if (!this.works.has(workId))
|
|
93
|
+
throw new Error(`Work ${workId} not found.`);
|
|
94
|
+
if (this.todos.size >= MAX_TODOS)
|
|
95
|
+
throw new Error(`Maximum of ${MAX_TODOS} todos reached.`);
|
|
96
|
+
const now = Date.now();
|
|
97
|
+
const todo = {
|
|
98
|
+
taskId: `T${this.nextTaskId}`,
|
|
99
|
+
workId,
|
|
100
|
+
taskName: requiredName(taskName, "taskName"),
|
|
101
|
+
taskInfo: requiredText(taskInfo, "taskInfo"),
|
|
102
|
+
status,
|
|
103
|
+
createdAt: now,
|
|
104
|
+
updatedAt: now,
|
|
105
|
+
};
|
|
106
|
+
this.record({ version: 1, type: "todo-created", at: now, todo });
|
|
107
|
+
return { ...todo };
|
|
108
|
+
}
|
|
109
|
+
updateTodo(taskId, patch) {
|
|
110
|
+
if (!this.todos.has(taskId))
|
|
111
|
+
throw new Error(`Todo ${taskId} not found.`);
|
|
112
|
+
const normalized = compactPatch({
|
|
113
|
+
taskName: patch.taskName === undefined ? undefined : requiredName(patch.taskName, "taskName"),
|
|
114
|
+
taskInfo: patch.taskInfo === undefined ? undefined : requiredText(patch.taskInfo, "taskInfo"),
|
|
115
|
+
status: patch.status,
|
|
116
|
+
});
|
|
117
|
+
if (Object.keys(normalized).length === 0)
|
|
118
|
+
throw new Error("TodoUpdate requires at least one changed field.");
|
|
119
|
+
this.record({ version: 1, type: "todo-updated", at: Date.now(), taskId, patch: normalized });
|
|
120
|
+
return this.getTodo(taskId);
|
|
121
|
+
}
|
|
122
|
+
deleteTodo(taskId) {
|
|
123
|
+
if (!this.todos.has(taskId))
|
|
124
|
+
return false;
|
|
125
|
+
this.record({ version: 1, type: "todo-deleted", at: Date.now(), taskId });
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
record(event) {
|
|
129
|
+
this.pi.appendEntry(TASK_ENTRY_TYPE, event);
|
|
130
|
+
this.apply(event);
|
|
131
|
+
this.onChange();
|
|
132
|
+
}
|
|
133
|
+
apply(event) {
|
|
134
|
+
switch (event.type) {
|
|
135
|
+
case "work-created":
|
|
136
|
+
assertId(event.work.workId, "W");
|
|
137
|
+
if (typeof event.work.workName !== "string" || typeof event.work.workInfo !== "string" || !isWorkStatus(event.work.status))
|
|
138
|
+
throw new Error("Malformed work entry.");
|
|
139
|
+
this.works.set(event.work.workId, { ...event.work, workName: safeSingleLine(event.work.workName) });
|
|
140
|
+
this.nextWorkId = Math.max(this.nextWorkId, numericId(event.work.workId) + 1);
|
|
141
|
+
break;
|
|
142
|
+
case "work-updated": {
|
|
143
|
+
const work = this.works.get(event.workId);
|
|
144
|
+
if (work)
|
|
145
|
+
this.works.set(event.workId, {
|
|
146
|
+
...work,
|
|
147
|
+
...(typeof event.patch.workName === "string" ? { workName: safeSingleLine(event.patch.workName) } : {}),
|
|
148
|
+
...(typeof event.patch.workInfo === "string" ? { workInfo: event.patch.workInfo } : {}),
|
|
149
|
+
...(isWorkStatus(event.patch.status) ? { status: event.patch.status } : {}),
|
|
150
|
+
updatedAt: event.at,
|
|
151
|
+
});
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case "work-deleted":
|
|
155
|
+
this.works.delete(event.workId);
|
|
156
|
+
for (const [taskId, todo] of this.todos)
|
|
157
|
+
if (todo.workId === event.workId)
|
|
158
|
+
this.todos.delete(taskId);
|
|
159
|
+
break;
|
|
160
|
+
case "todo-created":
|
|
161
|
+
assertId(event.todo.taskId, "T");
|
|
162
|
+
if (typeof event.todo.workId !== "string" || typeof event.todo.taskName !== "string" || typeof event.todo.taskInfo !== "string" || !isTodoStatus(event.todo.status))
|
|
163
|
+
throw new Error("Malformed todo entry.");
|
|
164
|
+
if (this.works.has(event.todo.workId))
|
|
165
|
+
this.todos.set(event.todo.taskId, { ...event.todo, taskName: safeSingleLine(event.todo.taskName) });
|
|
166
|
+
this.nextTaskId = Math.max(this.nextTaskId, numericId(event.todo.taskId) + 1);
|
|
167
|
+
break;
|
|
168
|
+
case "todo-updated": {
|
|
169
|
+
const todo = this.todos.get(event.taskId);
|
|
170
|
+
if (todo)
|
|
171
|
+
this.todos.set(event.taskId, {
|
|
172
|
+
...todo,
|
|
173
|
+
...(typeof event.patch.taskName === "string" ? { taskName: safeSingleLine(event.patch.taskName) } : {}),
|
|
174
|
+
...(typeof event.patch.taskInfo === "string" ? { taskInfo: event.patch.taskInfo } : {}),
|
|
175
|
+
...(isTodoStatus(event.patch.status) ? { status: event.patch.status } : {}),
|
|
176
|
+
updatedAt: event.at,
|
|
177
|
+
});
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case "todo-deleted":
|
|
181
|
+
this.todos.delete(event.taskId);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function requiredText(value, field) {
|
|
187
|
+
const text = value.trim();
|
|
188
|
+
if (!text)
|
|
189
|
+
throw new Error(`${field} must not be empty.`);
|
|
190
|
+
return text;
|
|
191
|
+
}
|
|
192
|
+
function requiredName(value, field) {
|
|
193
|
+
const text = safeSingleLine(value);
|
|
194
|
+
if (!text)
|
|
195
|
+
throw new Error(`${field} must not be empty.`);
|
|
196
|
+
return text;
|
|
197
|
+
}
|
|
198
|
+
function compactPatch(patch) {
|
|
199
|
+
return Object.fromEntries(Object.entries(patch).filter(([, value]) => value !== undefined));
|
|
200
|
+
}
|
|
201
|
+
function numericId(id) {
|
|
202
|
+
const value = Number.parseInt(id.slice(1), 10);
|
|
203
|
+
return Number.isSafeInteger(value) ? value : 0;
|
|
204
|
+
}
|
|
205
|
+
function assertId(id, prefix) {
|
|
206
|
+
if (typeof id !== "string" || !new RegExp(`^${prefix}[1-9]\\d*$`).test(id) || !Number.isSafeInteger(Number(id.slice(1)))) {
|
|
207
|
+
throw new Error(`Malformed ${prefix === "W" ? "work" : "todo"} ID.`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function isWorkStatus(value) {
|
|
211
|
+
return ["planned", "active", "blocked", "completed", "cancelled"].includes(String(value));
|
|
212
|
+
}
|
|
213
|
+
function isTodoStatus(value) {
|
|
214
|
+
return ["pending", "active", "blocked", "completed", "cancelled"].includes(String(value));
|
|
215
|
+
}
|
|
216
|
+
function parseEvent(value) {
|
|
217
|
+
if (!value || typeof value !== "object")
|
|
218
|
+
return undefined;
|
|
219
|
+
const candidate = value;
|
|
220
|
+
if (candidate.version !== 1 || typeof candidate.type !== "string")
|
|
221
|
+
return undefined;
|
|
222
|
+
if (!["work-created", "work-updated", "work-deleted", "todo-created", "todo-updated", "todo-deleted"].includes(candidate.type))
|
|
223
|
+
return undefined;
|
|
224
|
+
return value;
|
|
225
|
+
}
|
package/dist/text.d.ts
ADDED
package/dist/text.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function safeSingleLine(value) {
|
|
2
|
+
return [...value]
|
|
3
|
+
.map((character) => {
|
|
4
|
+
const code = character.charCodeAt(0);
|
|
5
|
+
if (character === "\n" || character === "\r" || character === "\t")
|
|
6
|
+
return " ";
|
|
7
|
+
if (code <= 31 || (code >= 127 && code <= 159))
|
|
8
|
+
return `\\x${code.toString(16).padStart(2, "0")}`;
|
|
9
|
+
return character;
|
|
10
|
+
})
|
|
11
|
+
.join("")
|
|
12
|
+
.replace(/\s+/g, " ")
|
|
13
|
+
.trim();
|
|
14
|
+
}
|
|
15
|
+
export function safeMultiline(value) {
|
|
16
|
+
return value.split(/\r?\n/).map((line) => [...line].map((character) => {
|
|
17
|
+
const code = character.charCodeAt(0);
|
|
18
|
+
if (character === "\t")
|
|
19
|
+
return " ";
|
|
20
|
+
if (code <= 31 || (code >= 127 && code <= 159))
|
|
21
|
+
return `\\x${code.toString(16).padStart(2, "0")}`;
|
|
22
|
+
return character;
|
|
23
|
+
}).join(""));
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
2
|
+
export interface TaskToolDetails {
|
|
3
|
+
action: string;
|
|
4
|
+
summary: string;
|
|
5
|
+
displaySummary: string;
|
|
6
|
+
data?: unknown;
|
|
7
|
+
}
|
|
8
|
+
export declare function taskResult(summary: string, action: string, data?: unknown, displaySummary?: string): {
|
|
9
|
+
content: Array<{
|
|
10
|
+
type: "text";
|
|
11
|
+
text: string;
|
|
12
|
+
}>;
|
|
13
|
+
details: TaskToolDetails;
|
|
14
|
+
};
|
|
15
|
+
export declare function renderTaskCall(label: string): (args: Record<string, unknown>, theme: {
|
|
16
|
+
fg(name: string, value: string): string;
|
|
17
|
+
bold(value: string): string;
|
|
18
|
+
}) => Text;
|
|
19
|
+
export declare function renderTaskResult(result: {
|
|
20
|
+
content: Array<{
|
|
21
|
+
type: string;
|
|
22
|
+
text?: string;
|
|
23
|
+
}>;
|
|
24
|
+
details?: unknown;
|
|
25
|
+
}, options: {
|
|
26
|
+
expanded: boolean;
|
|
27
|
+
}, theme: {
|
|
28
|
+
fg(name: string, value: string): string;
|
|
29
|
+
}, context: {
|
|
30
|
+
isError: boolean;
|
|
31
|
+
}): Text;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
2
|
+
import { safeSingleLine } from "./text.js";
|
|
3
|
+
export function taskResult(summary, action, data, displaySummary = summary) {
|
|
4
|
+
return { content: [{ type: "text", text: summary }], details: { action, summary, displaySummary, data } };
|
|
5
|
+
}
|
|
6
|
+
export function renderTaskCall(label) {
|
|
7
|
+
return (args, theme) => {
|
|
8
|
+
const action = label.replace(/(?:Work|Todo)/, "").toLowerCase();
|
|
9
|
+
const id = args.workId ?? args.taskId;
|
|
10
|
+
const name = args.workName ?? args.taskName;
|
|
11
|
+
const suffix = [id, name].filter(Boolean).map((value) => safeSingleLine(String(value))).join(" · ");
|
|
12
|
+
return new Text(`${theme.fg("toolTitle", theme.bold(label))}${suffix ? ` ${theme.fg("muted", suffix)}` : ` ${theme.fg("muted", action)}`}`, 0, 0);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function renderTaskResult(result, options, theme, context) {
|
|
16
|
+
const details = result.details;
|
|
17
|
+
const raw = options.expanded ? details?.summary : details?.displaySummary;
|
|
18
|
+
const text = raw ?? result.content.find((part) => part.type === "text")?.text ?? "";
|
|
19
|
+
return new Text(theme.fg(context.isError ? "error" : "success", safeDisplayText(text)), 0, 0);
|
|
20
|
+
}
|
|
21
|
+
function safeDisplayText(value) {
|
|
22
|
+
return value.split(/\r?\n/).map(safeSingleLine).join("\n");
|
|
23
|
+
}
|
package/dist/tools.d.ts
ADDED