@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
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
2
|
+
import { safeMultiline, safeSingleLine } from "../text.js";
|
|
3
|
+
import { border, frame, rule, todoIcon, workIcon } from "./panel.js";
|
|
4
|
+
const CHROME_LINES = 8;
|
|
5
|
+
export class WorksDashboard {
|
|
6
|
+
tui;
|
|
7
|
+
theme;
|
|
8
|
+
keybindings;
|
|
9
|
+
state;
|
|
10
|
+
close;
|
|
11
|
+
focused = false;
|
|
12
|
+
selectedKey;
|
|
13
|
+
scrollOffset = 0;
|
|
14
|
+
detailOffset = 0;
|
|
15
|
+
detailPageSize = 1;
|
|
16
|
+
detailsVisible = true;
|
|
17
|
+
message = "Ready. Select an item; Escape closes.";
|
|
18
|
+
disposed = false;
|
|
19
|
+
refreshTimer;
|
|
20
|
+
constructor(tui, theme, keybindings, state, close) {
|
|
21
|
+
this.tui = tui;
|
|
22
|
+
this.theme = theme;
|
|
23
|
+
this.keybindings = keybindings;
|
|
24
|
+
this.state = state;
|
|
25
|
+
this.close = close;
|
|
26
|
+
this.refreshTimer = setInterval(() => {
|
|
27
|
+
if (!this.disposed)
|
|
28
|
+
this.tui.requestRender();
|
|
29
|
+
}, 1_000);
|
|
30
|
+
this.refreshTimer.unref?.();
|
|
31
|
+
}
|
|
32
|
+
render(width) {
|
|
33
|
+
const dialogWidth = Math.max(1, width);
|
|
34
|
+
const innerWidth = Math.max(1, dialogWidth - 2);
|
|
35
|
+
const items = this.items();
|
|
36
|
+
this.syncSelection(items);
|
|
37
|
+
const terminalRows = this.tui.terminal.rows || process.stdout.rows || 30;
|
|
38
|
+
const dialogHeight = Math.max(8, Math.min(36, Math.floor(terminalRows * 0.82)));
|
|
39
|
+
const works = this.state.listWorks();
|
|
40
|
+
const todos = works.flatMap((work) => work.tasks);
|
|
41
|
+
const activeWorks = works.filter((work) => work.status === "active").length;
|
|
42
|
+
const completedTodos = todos.filter((todo) => todo.status === "completed").length;
|
|
43
|
+
const summary = `${activeWorks}/${works.length} works active · ${completedTodos}/${todos.length} todos completed · session scoped`;
|
|
44
|
+
const bodyHeight = Math.max(0, dialogHeight - CHROME_LINES);
|
|
45
|
+
const detailBudget = this.detailsVisible ? Math.max(0, Math.floor(bodyHeight / 2)) : 0;
|
|
46
|
+
const details = this.renderDetails(items, innerWidth, detailBudget);
|
|
47
|
+
const listHeight = Math.max(0, bodyHeight - details.length);
|
|
48
|
+
if (listHeight > 0)
|
|
49
|
+
this.keepSelectionVisible(items, listHeight);
|
|
50
|
+
const rows = items.slice(this.scrollOffset, this.scrollOffset + listHeight).map((item) => this.renderRow(item, innerWidth));
|
|
51
|
+
while (rows.length < listHeight)
|
|
52
|
+
rows.push("");
|
|
53
|
+
return [
|
|
54
|
+
border(innerWidth, "top", this.theme),
|
|
55
|
+
frame(this.theme.fg("accent", this.theme.bold("Works · session work and todos")), innerWidth, this.theme),
|
|
56
|
+
frame(this.theme.fg("dim", summary), innerWidth, this.theme),
|
|
57
|
+
rule(innerWidth, this.theme),
|
|
58
|
+
...[...rows, ...details].map((line) => frame(line, innerWidth, this.theme)),
|
|
59
|
+
rule(innerWidth, this.theme),
|
|
60
|
+
frame(this.theme.fg("warning", truncateToWidth(this.message, innerWidth, "")), innerWidth, this.theme),
|
|
61
|
+
frame(this.renderFooter(innerWidth), innerWidth, this.theme),
|
|
62
|
+
border(innerWidth, "bottom", this.theme),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
handleInput(data) {
|
|
66
|
+
if (this.disposed)
|
|
67
|
+
return;
|
|
68
|
+
const items = this.items();
|
|
69
|
+
this.syncSelection(items);
|
|
70
|
+
const index = Math.max(0, items.findIndex((item) => item.key === this.selectedKey));
|
|
71
|
+
if (this.keybindings.matches(data, "tui.select.cancel")) {
|
|
72
|
+
this.close();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (this.keybindings.matches(data, "tui.select.up")) {
|
|
76
|
+
this.select(items, index - 1);
|
|
77
|
+
}
|
|
78
|
+
else if (this.keybindings.matches(data, "tui.select.down")) {
|
|
79
|
+
this.select(items, index + 1);
|
|
80
|
+
}
|
|
81
|
+
else if (this.keybindings.matches(data, "tui.select.pageUp")) {
|
|
82
|
+
this.detailOffset = Math.max(0, this.detailOffset - this.detailPageSize);
|
|
83
|
+
this.message = "Moved detail view up.";
|
|
84
|
+
}
|
|
85
|
+
else if (this.keybindings.matches(data, "tui.select.pageDown")) {
|
|
86
|
+
this.detailOffset += this.detailPageSize;
|
|
87
|
+
this.message = "Moved detail view down.";
|
|
88
|
+
}
|
|
89
|
+
else if (this.keybindings.matches(data, "tui.select.confirm")) {
|
|
90
|
+
this.detailsVisible = !this.detailsVisible;
|
|
91
|
+
this.detailOffset = 0;
|
|
92
|
+
this.message = this.detailsVisible ? "Details shown." : "Details hidden.";
|
|
93
|
+
}
|
|
94
|
+
this.tui.requestRender();
|
|
95
|
+
}
|
|
96
|
+
invalidate() { }
|
|
97
|
+
dispose() {
|
|
98
|
+
if (this.disposed)
|
|
99
|
+
return;
|
|
100
|
+
this.disposed = true;
|
|
101
|
+
clearInterval(this.refreshTimer);
|
|
102
|
+
}
|
|
103
|
+
items() {
|
|
104
|
+
const items = [];
|
|
105
|
+
for (const work of this.state.listWorks()) {
|
|
106
|
+
items.push({ key: `work:${work.workId}`, kind: "work", work });
|
|
107
|
+
for (const todo of work.tasks)
|
|
108
|
+
items.push({ key: `todo:${todo.taskId}`, kind: "todo", todo, workName: work.workName });
|
|
109
|
+
}
|
|
110
|
+
return items;
|
|
111
|
+
}
|
|
112
|
+
syncSelection(items) {
|
|
113
|
+
if (items.some((item) => item.key === this.selectedKey))
|
|
114
|
+
return;
|
|
115
|
+
this.selectedKey = items[0]?.key;
|
|
116
|
+
this.scrollOffset = 0;
|
|
117
|
+
}
|
|
118
|
+
select(items, index) {
|
|
119
|
+
if (items.length === 0)
|
|
120
|
+
return;
|
|
121
|
+
this.selectedKey = items[Math.max(0, Math.min(index, items.length - 1))]?.key;
|
|
122
|
+
this.detailOffset = 0;
|
|
123
|
+
}
|
|
124
|
+
keepSelectionVisible(items, height) {
|
|
125
|
+
const index = Math.max(0, items.findIndex((item) => item.key === this.selectedKey));
|
|
126
|
+
if (index < this.scrollOffset)
|
|
127
|
+
this.scrollOffset = index;
|
|
128
|
+
if (index >= this.scrollOffset + height)
|
|
129
|
+
this.scrollOffset = index - height + 1;
|
|
130
|
+
this.scrollOffset = Math.max(0, Math.min(this.scrollOffset, Math.max(0, items.length - height)));
|
|
131
|
+
}
|
|
132
|
+
renderRow(item, width) {
|
|
133
|
+
const selected = item.key === this.selectedKey;
|
|
134
|
+
const prefix = selected ? this.theme.fg("accent", "▶ ") : " ";
|
|
135
|
+
if (item.kind === "work") {
|
|
136
|
+
const done = item.work.tasks.filter((todo) => todo.status === "completed").length;
|
|
137
|
+
return truncateToWidth(`${prefix}${workIcon(item.work.status, this.theme)} ${this.theme.bold(safeSingleLine(item.work.workName))} ${this.theme.fg("dim", `${item.work.workId} · ${item.work.status} · ${done}/${item.work.tasks.length}`)}`, width, "");
|
|
138
|
+
}
|
|
139
|
+
return truncateToWidth(`${prefix} ${todoIcon(item.todo.status, this.theme)} ${safeSingleLine(item.todo.taskName)} ${this.theme.fg("dim", `${item.todo.taskId} · ${item.todo.status}`)}`, width, "");
|
|
140
|
+
}
|
|
141
|
+
renderDetails(items, width, budget) {
|
|
142
|
+
if (!this.detailsVisible || budget === 0)
|
|
143
|
+
return [];
|
|
144
|
+
const item = items.find((candidate) => candidate.key === this.selectedKey);
|
|
145
|
+
if (!item)
|
|
146
|
+
return [this.theme.fg("muted", "No works or todos in this session.")].slice(0, budget);
|
|
147
|
+
const heading = item.kind === "work"
|
|
148
|
+
? `${item.work.workId} · ${safeSingleLine(item.work.workName)} · ${item.work.status}`
|
|
149
|
+
: `${item.todo.taskId} · ${safeSingleLine(item.todo.taskName)} · ${item.todo.status} · ${item.todo.workId} ${safeSingleLine(item.workName)}`;
|
|
150
|
+
const info = item.kind === "work" ? item.work.workInfo : item.todo.taskInfo;
|
|
151
|
+
const infoLines = safeMultiline(info).flatMap((line) => wrapTextWithAnsi(this.theme.fg("dim", line || " "), width));
|
|
152
|
+
const contentBudget = Math.max(0, budget - 3);
|
|
153
|
+
this.detailPageSize = Math.max(1, contentBudget);
|
|
154
|
+
const maxOffset = Math.max(0, infoLines.length - contentBudget);
|
|
155
|
+
this.detailOffset = Math.min(this.detailOffset, maxOffset);
|
|
156
|
+
const shown = infoLines.slice(this.detailOffset, this.detailOffset + contentBudget);
|
|
157
|
+
const position = infoLines.length > shown.length ? ` · lines ${this.detailOffset + 1}-${this.detailOffset + shown.length}/${infoLines.length}` : "";
|
|
158
|
+
return [
|
|
159
|
+
this.theme.fg("accent", this.theme.bold(`DETAILS${position}`)),
|
|
160
|
+
truncateToWidth(heading, width, ""),
|
|
161
|
+
...shown,
|
|
162
|
+
].slice(0, budget);
|
|
163
|
+
}
|
|
164
|
+
renderFooter(width) {
|
|
165
|
+
const text = "configured ↑/↓ select · PgUp/PgDn scroll details · confirm toggles · cancel closes";
|
|
166
|
+
return truncateToWidth(this.theme.fg("muted", text), width, "");
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# pi-tasks reference
|
|
2
|
+
|
|
3
|
+
## Ownership and persistence
|
|
4
|
+
|
|
5
|
+
`TaskState` owns work and todo state. Every mutation appends a versioned `pi-tasks-state` custom entry to the current Pi session. Custom entries do not enter model context. State restoration replays entries from `sessionManager.getBranch()`, so resume, fork, and tree navigation follow the active session branch.
|
|
6
|
+
|
|
7
|
+
A work deletion also deletes every associated todo. A todo cannot be created for a missing work. IDs are stable within a branch and use `W<number>` for works and `T<number>` for todos.
|
|
8
|
+
|
|
9
|
+
Limits:
|
|
10
|
+
|
|
11
|
+
- 100 works per session branch
|
|
12
|
+
- 500 todos per session branch
|
|
13
|
+
- 240 characters per name
|
|
14
|
+
- 10,000 characters per information field
|
|
15
|
+
- list tool text is truncated at 50KB or 2,000 lines
|
|
16
|
+
|
|
17
|
+
## Data
|
|
18
|
+
|
|
19
|
+
A work contains `workId`, `workName`, `workInfo`, `status`, `createdAt`, and `updatedAt`. Work status is `planned`, `active`, `blocked`, `completed`, or `cancelled`.
|
|
20
|
+
|
|
21
|
+
A todo contains `taskId`, `workId`, `taskName`, `taskInfo`, `status`, `createdAt`, and `updatedAt`. Todo status is `pending`, `active`, `blocked`, `completed`, or `cancelled`.
|
|
22
|
+
|
|
23
|
+
The public list shape assembles each work with `tasks: Todo[]`; tasks are stored separately to avoid duplicate state.
|
|
24
|
+
|
|
25
|
+
## Tracking behavior
|
|
26
|
+
|
|
27
|
+
When all tracking tools are active, the extension adds hidden per-turn guidance for every normal request that starts or continues work. Pi finds or creates work, synchronizes todos, marks the current todo active before the attempt, and updates statuses afterward. Tracking is not skipped merely because the request looks small.
|
|
28
|
+
|
|
29
|
+
The guidance is not added when the tracking tools have been removed from the active tool set. Pi Ask removes them during `/ask`. Pi BTW executes its side conversation outside the main conversation. The guidance also explicitly forbids changing works, todos, loops, or monitors during either mode.
|
|
30
|
+
|
|
31
|
+
## Interfaces
|
|
32
|
+
|
|
33
|
+
The compact panel defaults to a non-capturing floating overlay anchored at the top-right. It shows work and todo names, status icons, and completion counts, and hides on terminals narrower than 90 columns or shorter than 18 rows. Because Pi treats any persistent overlay as active, the floating mode can block display-mode changes. `/works-panel widget` switches to a right-aligned widget above the editor, and `/works-panel off` hides it.
|
|
34
|
+
|
|
35
|
+
`/works` opens a top-centered detailed overlay. Configured selection keys choose records, configured Page Up and Page Down keys scroll long details, the configured confirmation key toggles details, and the configured cancel key closes it.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# pi-tasks usage
|
|
2
|
+
|
|
3
|
+
## Automatic tracking
|
|
4
|
+
|
|
5
|
+
For every normal request that starts or continues work, Pi should:
|
|
6
|
+
|
|
7
|
+
1. Find existing work and todos.
|
|
8
|
+
2. Create or update the relevant work and mark it active.
|
|
9
|
+
3. Create or update detailed todos for the requested scope.
|
|
10
|
+
4. Mark the current todo active before starting it.
|
|
11
|
+
5. Mark the todo completed, blocked, or cancelled after the attempt.
|
|
12
|
+
6. Complete the work only when its required todos are complete.
|
|
13
|
+
|
|
14
|
+
The extension applies this guidance across all loaded skills and does not skip work merely because it looks small. It does not update tracking during `/ask`, `/btw`, or BTW side threads.
|
|
15
|
+
|
|
16
|
+
## Work tools
|
|
17
|
+
|
|
18
|
+
```text
|
|
19
|
+
WorkCreate workName="Improve authentication" workInfo="Detailed context..." status="active"
|
|
20
|
+
WorkList
|
|
21
|
+
WorkList workId="W1"
|
|
22
|
+
WorkUpdate workId="W1" status="blocked" workInfo="Detailed blocker and retained context..."
|
|
23
|
+
WorkDelete workId="W1"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`WorkDelete` also removes associated todos.
|
|
27
|
+
|
|
28
|
+
## Todo tools
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
TodoCreate workId="W1" taskName="Inspect token flow" taskInfo="Detailed context..."
|
|
32
|
+
TodoList workId="W1"
|
|
33
|
+
TodoList status="active"
|
|
34
|
+
TodoUpdate taskId="T1" status="completed" taskInfo="Detailed outcome..."
|
|
35
|
+
TodoDelete taskId="T1"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## TUI
|
|
39
|
+
|
|
40
|
+
The panel defaults to a floating top-right layout and does not take keyboard focus. It hides on small terminals. Use `/works-panel widget` for the earlier right-aligned layout above the editor, `/works-panel floating` to return to the floating layout, or `/works-panel off` to hide it.
|
|
41
|
+
|
|
42
|
+
Run `/works` for full details:
|
|
43
|
+
|
|
44
|
+
- Configured Up/Down keys: select
|
|
45
|
+
- Configured Page Up/Page Down keys: scroll long details
|
|
46
|
+
- Configured confirmation key: show or hide detailed information
|
|
47
|
+
- Configured cancel key or Ctrl+C: close
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@abhishek944/pi-tasks",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Session-scoped work and todo tracking for Pi.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22.19.0"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"pi-package",
|
|
12
|
+
"pi",
|
|
13
|
+
"pi-extension",
|
|
14
|
+
"tasks",
|
|
15
|
+
"todos",
|
|
16
|
+
"work-tracking"
|
|
17
|
+
],
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/",
|
|
20
|
+
"docs/USAGE_GUIDE.md",
|
|
21
|
+
"docs/REFERENCE.md",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@earendil-works/pi-coding-agent": ">=0.84.3",
|
|
35
|
+
"@earendil-works/pi-tui": "*",
|
|
36
|
+
"@earendil-works/pi-ai": "*",
|
|
37
|
+
"typebox": "*"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
41
|
+
"build": "npm run clean && tsc",
|
|
42
|
+
"audit:production": "npm audit --omit=dev --audit-level=moderate",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"lint": "biome check src/",
|
|
45
|
+
"lint:fix": "biome check --fix src/"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@biomejs/biome": "^2.4.13",
|
|
49
|
+
"@earendil-works/pi-ai": "0.84.3",
|
|
50
|
+
"@earendil-works/pi-coding-agent": "0.84.3",
|
|
51
|
+
"@earendil-works/pi-tui": "0.84.3",
|
|
52
|
+
"@types/node": "^26.1.2",
|
|
53
|
+
"typebox": "1.3.16",
|
|
54
|
+
"typescript": "^7.0.2"
|
|
55
|
+
},
|
|
56
|
+
"pi": {
|
|
57
|
+
"extensions": [
|
|
58
|
+
"./dist/index.js"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
}
|