@abhishek944/pi-tasks 0.15.0 → 0.17.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 +63 -14
- package/dist/agents/delegation.d.ts +4 -0
- package/dist/agents/delegation.js +130 -0
- package/dist/agents/herdr.d.ts +10 -3
- package/dist/agents/herdr.js +39 -12
- package/dist/agents/links.d.ts +3 -3
- package/dist/agents/links.js +42 -19
- package/dist/auto-continue.js +409 -33
- package/dist/blocked.d.ts +29 -0
- package/dist/blocked.js +100 -0
- package/dist/command.d.ts +2 -2
- package/dist/command.js +7 -3
- package/dist/delegated-time.d.ts +12 -1
- package/dist/delegated-time.js +96 -15
- package/dist/dependency.d.ts +7 -0
- package/dist/dependency.js +13 -0
- package/dist/durable.d.ts +42 -0
- package/dist/durable.js +577 -0
- package/dist/herdr-header.d.ts +3 -0
- package/dist/herdr-header.js +100 -0
- package/dist/herdr-panel.d.ts +15 -0
- package/dist/herdr-panel.js +219 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +125 -56
- package/dist/markdown.js +3 -1
- package/dist/panel-settings.d.ts +11 -0
- package/dist/panel-settings.js +30 -0
- package/dist/progress.js +1 -1
- package/dist/snapshot.d.ts +23 -0
- package/dist/snapshot.js +166 -0
- package/dist/state.d.ts +43 -18
- package/dist/state.js +581 -289
- package/dist/thoughts.d.ts +11 -0
- package/dist/thoughts.js +14 -0
- package/dist/timing.js +9 -2
- package/dist/tools.js +295 -34
- package/dist/tracking.js +25 -13
- package/dist/transition.d.ts +9 -0
- package/dist/transition.js +26 -0
- package/dist/types.d.ts +76 -3
- package/dist/ui/panel.js +38 -19
- package/dist/ui/task-view.d.ts +7 -0
- package/dist/ui/task-view.js +10 -0
- package/dist/ui/works-dashboard.js +37 -19
- package/docs/REFERENCE.md +85 -31
- package/docs/USAGE_GUIDE.md +129 -55
- package/herdr/pi-tasks/README.md +46 -0
- package/herdr/pi-tasks/header.js +212 -0
- package/herdr/pi-tasks/main.js +488 -0
- package/herdr/pi-tasks/mod.json +3 -0
- package/herdr/pi-tasks/spinner.svg +1 -0
- package/package.json +26 -1
- package/dist/agents/tools.d.ts +0 -3
- package/dist/agents/tools.js +0 -143
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { View, div, svg } from "gpui-kit";
|
|
2
|
+
import { Button, ScrollHandle, h_flex, v_flex } from "gpui-base";
|
|
3
|
+
import { readFile } from "fs/promises";
|
|
4
|
+
import { agents, panes, props, readTextFile, run, setShared, shared, terminals, theme, watchFolder } from "herdr";
|
|
5
|
+
|
|
6
|
+
const SESSION = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
7
|
+
const TERMINAL = /^(?:[A-Za-z0-9][A-Za-z0-9._-]*\/)?t[0-9a-z]+$/;
|
|
8
|
+
const STATUSES = ["active", "blocked", "completed", "closed", "cancelled"];
|
|
9
|
+
const FILTERS = ["all", "active", "blocked", "blocked-user", "blocked-agent", "completed", "cancelled"];
|
|
10
|
+
const DEPENDENCIES = ["user-decision", "another-agent"];
|
|
11
|
+
const DEPENDENCY_LABELS = { "user-decision": "User decision", "another-agent": "Another agent" };
|
|
12
|
+
// The pane this view is drawn in; the opener publishes it because a pane content copy
|
|
13
|
+
// receives only its creation props, and the live pane inventory names it. See README "Status filter".
|
|
14
|
+
const PANE = /^p[A-Za-z0-9]+$/;
|
|
15
|
+
const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
16
|
+
const number = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
17
|
+
const text = (value) => typeof value === "string" && value.trim().length > 0;
|
|
18
|
+
|
|
19
|
+
function owner(info) {
|
|
20
|
+
const owners = new Set([...info.matchAll(/^[ \t]*owner:[ \t]*(self|delegate)(?=[ \t.,;:\r]|$)/gim)].map((match) => match[1].toLowerCase()));
|
|
21
|
+
return owners.size === 1 ? [...owners][0] : "unassigned";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function delegate(todo) {
|
|
25
|
+
if (owner(todo.taskInfo) !== "delegate") return null;
|
|
26
|
+
const links = [...todo.taskInfo.matchAll(/^[ \t]*hc-terminal:[ \t]*([^\r\n]*)$/gim)].map((match) => match[1].trim());
|
|
27
|
+
return links.length > 0 && links.every((link) => TERMINAL.test(link)) && new Set(links).size === 1 ? links[0] : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function completion(todo) {
|
|
31
|
+
if (todo.status === "completed" || todo.status === "closed") return 100;
|
|
32
|
+
return number(todo.completionPercent) && todo.completionPercent < 100 ? todo.completionPercent : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function progress(todos) {
|
|
36
|
+
const eligible = todos.filter((todo) => todo.status !== "cancelled");
|
|
37
|
+
const values = eligible.map(completion);
|
|
38
|
+
return !values.length || values.includes(null) ? null : Math.floor(values.reduce((a, b) => a + b, 0) / values.length);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function elapsed(todo, at) {
|
|
42
|
+
if (owner(todo.taskInfo) === "delegate" && !todo.delegatedTimes?.length) return null;
|
|
43
|
+
if (!number(todo.elapsedMs)) return null;
|
|
44
|
+
let total = todo.elapsedMs + (todo.workingSince === undefined ? 0 : Math.max(0, at - todo.workingSince));
|
|
45
|
+
for (const source of todo.delegatedTimes ?? []) {
|
|
46
|
+
if (!number(source.elapsedMs)) return null;
|
|
47
|
+
total += source.elapsedMs;
|
|
48
|
+
}
|
|
49
|
+
return number(total) ? total : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function totalTime(todos, at) {
|
|
53
|
+
const values = todos.map((todo) => elapsed(todo, at));
|
|
54
|
+
if (!values.length || values.includes(null)) return null;
|
|
55
|
+
const total = values.reduce((a, b) => a + b, 0);
|
|
56
|
+
return number(total) ? total : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function duration(ms) {
|
|
60
|
+
if (ms === null) return "—";
|
|
61
|
+
const seconds = Math.floor(ms / 1000);
|
|
62
|
+
const minutes = Math.floor(seconds / 60);
|
|
63
|
+
const hours = Math.floor(minutes / 60);
|
|
64
|
+
return seconds < 60 ? `${seconds}s` : minutes < 60 ? `${minutes}m ${String(seconds % 60).padStart(2, "0")}s` : hours < 1000 ? `${hours}h ${String(minutes % 60).padStart(2, "0")}m` : `${Math.floor(hours / 24)}d`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Legacy blocked records have no blockedAt: omit the age entirely, never an invented or zero one.
|
|
68
|
+
function blockedAge(todo, now = Date.now()) {
|
|
69
|
+
if (todo.status !== "blocked" || !number(todo.blockedAt)) return null;
|
|
70
|
+
return Math.max(0, now - todo.blockedAt);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Null, not a label: callers drop the age when this record does not store one.
|
|
74
|
+
function ageLabel(ms) {
|
|
75
|
+
if (ms === null) return null;
|
|
76
|
+
const minutes = Math.floor(ms / 60000);
|
|
77
|
+
if (minutes < 60) return `${minutes}m`;
|
|
78
|
+
const hours = Math.floor(minutes / 60);
|
|
79
|
+
return hours < 48 ? `${hours}h` : `${Math.floor(hours / 24)}d`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function blockedLabel(todo, now = Date.now()) {
|
|
83
|
+
if (todo.status !== "blocked") return null;
|
|
84
|
+
const dependency = todo.dependentOn === "user-decision" ? "Blocked on you" : todo.dependentOn === "another-agent" ? "Waiting on agents" : "Blocked";
|
|
85
|
+
const age = ageLabel(blockedAge(todo, now));
|
|
86
|
+
return age === null ? dependency : dependency + " · " + age;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// A filter names an outcome, not always one stored status. Verified work is completed first and
|
|
90
|
+
// then closed, so Completed lists both: a closed task is finished work that must not disappear
|
|
91
|
+
// from the view the person uses to find finished work.
|
|
92
|
+
function matchesFilter(todo, filter) {
|
|
93
|
+
if (filter === "all") return true;
|
|
94
|
+
if (filter === "completed") return todo.status === "completed" || todo.status === "closed";
|
|
95
|
+
if (filter === "blocked-user") return todo.status === "blocked" && todo.dependentOn === "user-decision";
|
|
96
|
+
if (filter === "blocked-agent") return todo.status === "blocked" && todo.dependentOn === "another-agent";
|
|
97
|
+
return todo.status === filter;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// The list and the header counts read this one selection, so a count always equals what its entry
|
|
101
|
+
// shows. All statuses stays the live view a running session needs; finished-and-closed and
|
|
102
|
+
// cancelled records are listed by their own entries instead of by every view.
|
|
103
|
+
function visibleTodos(todos, filter) {
|
|
104
|
+
if (filter !== "all") return todos.filter((todo) => matchesFilter(todo, filter));
|
|
105
|
+
return todos.filter((todo) => todo.status !== "closed" && todo.status !== "cancelled");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function validate(value, sessionId) {
|
|
109
|
+
if (!object(value) || value.version !== 1 || value.sessionId !== sessionId || !text(value.cwd) || !number(value.updatedAt)
|
|
110
|
+
|| typeof value.agentRunning !== "boolean" || !Array.isArray(value.works) || value.works.length > 100
|
|
111
|
+
|| !Array.isArray(value.todos) || value.todos.length > 500) throw new Error("Invalid or mismatched session task snapshot.");
|
|
112
|
+
const works = new Set();
|
|
113
|
+
const tasks = new Set();
|
|
114
|
+
for (const work of value.works) {
|
|
115
|
+
if (!object(work) || !/^W[1-9][0-9]*$/.test(work.workId) || works.has(work.workId) || !text(work.workName) || !text(work.workInfo)) throw new Error("Invalid work in the task snapshot.");
|
|
116
|
+
works.add(work.workId);
|
|
117
|
+
}
|
|
118
|
+
for (const todo of value.todos) {
|
|
119
|
+
if (!object(todo) || !/^T[1-9][0-9]*$/.test(todo.taskId) || tasks.has(todo.taskId) || !works.has(todo.workId)
|
|
120
|
+
|| !text(todo.taskName) || !text(todo.taskInfo) || !STATUSES.includes(todo.status)
|
|
121
|
+
|| (todo.worktree !== undefined && (typeof todo.worktree !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(todo.worktree)))
|
|
122
|
+
|| (todo.blockedReason != null && typeof todo.blockedReason !== "string")
|
|
123
|
+
|| (todo.dependentOn !== undefined && (todo.status !== "blocked" || !DEPENDENCIES.includes(todo.dependentOn)))
|
|
124
|
+
|| (todo.blockedAt !== undefined && (todo.status !== "blocked" || !number(todo.blockedAt)))
|
|
125
|
+
|| (todo.decisionQuestionId !== undefined && (todo.status !== "blocked" || todo.dependentOn !== "user-decision" || typeof todo.decisionQuestionId !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(todo.decisionQuestionId)))
|
|
126
|
+
|| (todo.finalThoughts !== undefined && !text(todo.finalThoughts))
|
|
127
|
+
|| (todo.goal !== undefined && (!object(todo.goal) || !text(todo.goal.goal) || !Array.isArray(todo.goal.criteria) || !todo.goal.criteria.every(text)))
|
|
128
|
+
|| (todo.workingSince !== undefined && !number(todo.workingSince))
|
|
129
|
+
|| (todo.delegatedTimes !== undefined && (!Array.isArray(todo.delegatedTimes) || todo.delegatedTimes.some((source) => !object(source) || (source.elapsedMs !== null && !number(source.elapsedMs)))))) throw new Error("Invalid task in the task snapshot.");
|
|
130
|
+
tasks.add(todo.taskId);
|
|
131
|
+
}
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export default class Tasks extends View {
|
|
136
|
+
init(_props, cx) {
|
|
137
|
+
const binding = props() ?? {};
|
|
138
|
+
this.sessionId = binding.sessionId;
|
|
139
|
+
this.path = binding.snapshot;
|
|
140
|
+
this.terminal = binding.terminal;
|
|
141
|
+
this.selected = null;
|
|
142
|
+
this.expanded = new Set();
|
|
143
|
+
this.collapsed = new Set();
|
|
144
|
+
this.document = null;
|
|
145
|
+
this.error = "";
|
|
146
|
+
this.actionError = "";
|
|
147
|
+
this.closed = false;
|
|
148
|
+
this.loading = false;
|
|
149
|
+
this.bound = false;
|
|
150
|
+
this.width = 800;
|
|
151
|
+
this.handle = cx.focus_handle();
|
|
152
|
+
if (typeof this.sessionId !== "string" || !SESSION.test(this.sessionId)) {
|
|
153
|
+
this.error = "Reopen Tasks from the intended Pi session with /works-panel herdr.";
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (typeof this.path !== "string" || !/^(?:\/|[A-Za-z]:[\\/])/.test(this.path) || this.path.includes("\0")) {
|
|
157
|
+
this.error = "Restart Pi, resume this session, then reopen Tasks with /works-panel herdr.";
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this.paneFile = typeof binding.paneFile === "string" && /^(?:\/|[A-Za-z]:[\\/])/.test(binding.paneFile) && !binding.paneFile.includes("\0")
|
|
161
|
+
? binding.paneFile : null;
|
|
162
|
+
this.paneId = null;
|
|
163
|
+
this.filter = "all";
|
|
164
|
+
this.scroll = ScrollHandle.new();
|
|
165
|
+
this.bound = true;
|
|
166
|
+
this.directory = this.path.replace(/[\\/][^\\/]+$/, "");
|
|
167
|
+
cx.spawn(async (cx) => {
|
|
168
|
+
await this.reload(cx);
|
|
169
|
+
try {
|
|
170
|
+
while (!this.closed) {
|
|
171
|
+
const changed = await watchFolder(this.directory);
|
|
172
|
+
if (this.closed) return;
|
|
173
|
+
if (changed.some((path) => path.replace(/\\/g, "/") === this.path.replace(/\\/g, "/"))) await this.reload(cx);
|
|
174
|
+
}
|
|
175
|
+
} catch {
|
|
176
|
+
if (!this.closed) { this.error = "Live updates stopped. Reopen Tasks with /works herdr-off then /works herdr-on."; cx.notify(); }
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
// A measured clock, not a spinner animation. Offline/saved values never tick.
|
|
180
|
+
cx.timer.every(1000, (cx) => {
|
|
181
|
+
if (this.document?.todos.some((todo) => todo.workingSince !== undefined && this.running(todo))) cx.notify();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async reload(cx) {
|
|
186
|
+
if (this.closed || !this.bound) return;
|
|
187
|
+
if (this.loading) { this.reloadPending = true; return; }
|
|
188
|
+
this.loading = true;
|
|
189
|
+
try {
|
|
190
|
+
await this.readPane(cx);
|
|
191
|
+
let content;
|
|
192
|
+
try { content = await readTextFile(this.path); }
|
|
193
|
+
catch { content = await readFile(this.path, "utf8"); }
|
|
194
|
+
if (content === null) throw new Error("The session task file is missing. Resume Pi or restore the file.");
|
|
195
|
+
if (content.length > 16 * 1024 * 1024) throw new Error("The task file exceeds 16 MiB.");
|
|
196
|
+
const next = validate(JSON.parse(content), this.sessionId);
|
|
197
|
+
if (this.closed) return;
|
|
198
|
+
this.document = next;
|
|
199
|
+
this.publishCounts(next);
|
|
200
|
+
this.error = "";
|
|
201
|
+
const ids = new Set(next.todos.map((todo) => todo.taskId));
|
|
202
|
+
for (const id of this.expanded) if (!ids.has(id)) this.expanded.delete(id);
|
|
203
|
+
if (!ids.has(this.selected)) this.selected = null;
|
|
204
|
+
} catch (error) {
|
|
205
|
+
this.document = null;
|
|
206
|
+
this.publishCounts(null);
|
|
207
|
+
this.error = error instanceof Error ? error.message : String(error);
|
|
208
|
+
} finally {
|
|
209
|
+
this.loading = false;
|
|
210
|
+
if (!this.closed) {
|
|
211
|
+
cx.notify();
|
|
212
|
+
if (this.reloadPending) { this.reloadPending = false; await this.reload(cx); }
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
publishCounts(document) {
|
|
218
|
+
if (this.paneId === null) return;
|
|
219
|
+
// Keys are the filter values the header offers, so its lookup by value and the count it shows
|
|
220
|
+
// cannot drift from the rows a selection lists.
|
|
221
|
+
const counts = document ? Object.fromEntries(FILTERS.map((filter) => [filter, visibleTodos(document.todos, filter).length])) : null;
|
|
222
|
+
setShared("pi-tasks-counts:" + this.paneId, counts);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
close() { this.publishCounts(null); this.closed = true; }
|
|
226
|
+
|
|
227
|
+
// A pane content copy is given only its creation props, so the opener publishes the hosting pane
|
|
228
|
+
// id beside the snapshot. A pane opened before that hand-off existed carries no `paneFile` prop,
|
|
229
|
+
// and its stored props never change, so the live inventory is the fallback: the opener always
|
|
230
|
+
// splits the view into the source terminal's tab, where exactly one Tasks pane is this one.
|
|
231
|
+
// Anything absent, malformed or ambiguous leaves this view unfiltered instead of guessing another
|
|
232
|
+
// pane's selection. The file lives beside the watched snapshot, so the directory retries a
|
|
233
|
+
// first-mount race.
|
|
234
|
+
async readPane(_cx) {
|
|
235
|
+
let published = null;
|
|
236
|
+
if (this.paneFile) {
|
|
237
|
+
try {
|
|
238
|
+
const content = await readTextFile(this.paneFile);
|
|
239
|
+
const value = content === null ? "" : content.trim();
|
|
240
|
+
published = PANE.test(value) ? value : null;
|
|
241
|
+
} catch { published = null; }
|
|
242
|
+
}
|
|
243
|
+
const next = published ?? this.paneFromInventory();
|
|
244
|
+
if (this.paneId !== next) {
|
|
245
|
+
this.publishCounts(null);
|
|
246
|
+
this.paneId = next;
|
|
247
|
+
this.publishCounts(null);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
paneFromInventory() {
|
|
252
|
+
if (typeof this.terminal !== "string") return null;
|
|
253
|
+
const host = panes().find((pane) => pane.terminal === this.terminal);
|
|
254
|
+
if (!host) return null;
|
|
255
|
+
const siblings = panes().filter((pane) => pane.mod === "pi-tasks" && pane.terminal === null && pane.tab === host.tab);
|
|
256
|
+
const id = siblings.length === 1 ? siblings[0].pane : null;
|
|
257
|
+
return typeof id === "string" && PANE.test(id) ? id : null;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
statusFilter() {
|
|
261
|
+
const value = this.paneId === null ? "all" : shared("pi-tasks-status:" + this.paneId);
|
|
262
|
+
return FILTERS.includes(value) ? value : "all";
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// The header owns the menu, so a press in this view must dismiss it: Herdr closes a Select on
|
|
266
|
+
// Escape and on presses inside its own mod, never on one that lands here. A press anywhere in the
|
|
267
|
+
// view reaches this root handler; the selected status is a separate value, so dismissing keeps it.
|
|
268
|
+
dismissOnPress(element) {
|
|
269
|
+
if (this.paneId === null) return element;
|
|
270
|
+
return element.on_mouse_down("left", (_event, cx) => {
|
|
271
|
+
if (shared("pi-tasks-status-open:" + this.paneId) !== true) return;
|
|
272
|
+
setShared("pi-tasks-status-open:" + this.paneId, false);
|
|
273
|
+
cx.notify();
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
linked(todo) {
|
|
278
|
+
const link = delegate(todo);
|
|
279
|
+
return link && terminals().some((terminal) => terminal.address === link && terminal.state === "live") ? link : null;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
running(todo) {
|
|
283
|
+
if (todo.status !== "active") return false;
|
|
284
|
+
const link = this.linked(todo);
|
|
285
|
+
if (link) return agents().some((agent) => agent.address === link && agent.status === "working");
|
|
286
|
+
const source = this.document?.terminalId ?? this.terminal;
|
|
287
|
+
return owner(todo.taskInfo) === "self" && todo.status === "active" && todo.workingSince !== undefined
|
|
288
|
+
&& this.document?.agentRunning && this.document.focusedTaskId === todo.taskId
|
|
289
|
+
&& terminals().some((terminal) => terminal.address === source && terminal.state === "live")
|
|
290
|
+
&& agents().some((agent) => agent.address === source && agent.status === "working");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
at(todo) {
|
|
294
|
+
return todo.workingSince !== undefined && this.running(todo) ? Date.now() : this.document.updatedAt;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
state(todo) {
|
|
298
|
+
return this.running(todo) ? "Running" : todo.status === "blocked" ? "Blocked"
|
|
299
|
+
: todo.status === "completed" ? "Completed" : todo.status === "closed" ? "Closed"
|
|
300
|
+
: todo.status === "cancelled" ? "Cancelled" : "Active; not running";
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
button(id, label, accessible, callback, t, underlineFocus = false) {
|
|
304
|
+
return Button.new(id).min_w(0).rounded(4).cursor_pointer().text_color(t.foreground)
|
|
305
|
+
.accessibility_label(accessible).tooltip(accessible).tab_stop(true)
|
|
306
|
+
// Name controls underline on focus; a selected background fill looks like
|
|
307
|
+
// selected text. Task-row selection keeps its own background.
|
|
308
|
+
.focus((style) => underlineFocus ? style.underline() : style.bg(t.selected).text_color(t.accent))
|
|
309
|
+
.on_click((event, cx) => { cx.stop_propagation(); callback(cx, event); }).child(label);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
nameButton(id, label, accessible, callback, t) {
|
|
313
|
+
// Constrain the label itself so long names ellipsize at the end, not under the status glyph.
|
|
314
|
+
return this.button(id, div().flex_1().min_w(0).truncate().text_left().child(label), accessible, callback, t, true)
|
|
315
|
+
.flex().flex_1().min_w(0).items_center().justify_start().overflow_hidden();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
toggleTask(todo, cx) {
|
|
319
|
+
this.selected = todo.taskId;
|
|
320
|
+
if (this.expanded.has(todo.taskId)) this.expanded.delete(todo.taskId);
|
|
321
|
+
else this.expanded.add(todo.taskId);
|
|
322
|
+
cx.notify();
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
openAgent(todo, cx) {
|
|
326
|
+
const link = this.linked(todo);
|
|
327
|
+
if (!link) { this.actionError = "The linked agent is no longer available."; cx.notify(); return; }
|
|
328
|
+
// A pane-less sub-agent cannot be selected; agent.focus acknowledges it but
|
|
329
|
+
// shows nothing. Present its own screen over the current tab instead. The
|
|
330
|
+
// app lists only the first child level, so a deeper child is recognized by
|
|
331
|
+
// its Core parent. A terminal that owns a pane, or another machine's
|
|
332
|
+
// terminal, keeps the normal agent focus. Never navigate to the parent.
|
|
333
|
+
let command;
|
|
334
|
+
if (link.includes("/") || panes().some((pane) => pane.terminal === link)) command = "agent.focus";
|
|
335
|
+
else {
|
|
336
|
+
const record = terminals().find((terminal) => terminal.address === link);
|
|
337
|
+
command = record?.parent ? "terminal.peek" : null;
|
|
338
|
+
}
|
|
339
|
+
if (!command) { this.actionError = "Herdr is not showing this agent. Open its space, then retry."; cx.notify(); return; }
|
|
340
|
+
try { run(command, { terminal: link }); this.actionError = ""; }
|
|
341
|
+
catch { this.actionError = command === "terminal.peek" ? "Could not open the linked agent's screen." : "Could not focus the linked agent."; }
|
|
342
|
+
cx.notify();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
finalThoughts(todo) {
|
|
346
|
+
if (todo.status === "blocked") return (todo.blockedReason || "").trim() || (todo.finalThoughts || "").trim();
|
|
347
|
+
return (todo.finalThoughts || "").trim();
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
stateMark(todo, t) {
|
|
351
|
+
const state = this.state(todo);
|
|
352
|
+
if (state === "Running") {
|
|
353
|
+
return svg("mods/pi-tasks/spinner.svg").size(11).flex_none().text_color(t.working)
|
|
354
|
+
.spin(900).role("image").accessibility_label(state).tooltip(state);
|
|
355
|
+
}
|
|
356
|
+
const mark = state === "Blocked" ? "!" : state === "Completed" || state === "Closed" ? "✓" : state === "Cancelled" ? "×" : "○";
|
|
357
|
+
return div().w(11).flex_none().text_size(12).text_center()
|
|
358
|
+
.text_color(state === "Blocked" ? t.blocked : state === "Completed" ? t.done : t.dim)
|
|
359
|
+
.role("image").accessibility_label(state).tooltip(state).child(mark);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
effortDescription(todo, value) {
|
|
363
|
+
if (value === null) {
|
|
364
|
+
if (owner(todo.taskInfo) === "delegate" && !todo.delegatedTimes?.length) return "Unknown effort; delegate measurement has not been imported";
|
|
365
|
+
if (todo.delegatedTimes?.some((report) => report.elapsedMs === null)) return "Unknown effort; an imported delegate report is unmeasured";
|
|
366
|
+
return "Unknown effort; no complete measurement is recorded, not zero";
|
|
367
|
+
}
|
|
368
|
+
const state = this.running(todo) && todo.workingSince !== undefined ? "Running own measurement"
|
|
369
|
+
: todo.status === "completed" || todo.status === "closed" || todo.status === "cancelled" ? "Stopped own measurement" : "Saved measurement; not currently running";
|
|
370
|
+
return state + (todo.delegatedTimes?.length ? "; includes imported delegate effort once" : "; own measured effort");
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
metric(id, value, label, width, t) {
|
|
374
|
+
return div().id(id).w(width).flex_none().text_right().text_size(11).whitespace_nowrap().text_color(t.muted)
|
|
375
|
+
.role("label").accessibility_label(label + ": " + value).tooltip(label + ": " + value).child(value);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
taskRow(todo, t, columns) {
|
|
379
|
+
const link = this.linked(todo);
|
|
380
|
+
const pct = completion(todo);
|
|
381
|
+
const time = elapsed(todo, this.at(todo));
|
|
382
|
+
const row = h_flex().id("task-" + todo.taskId).h(30).flex_none().min_w(0).px(10).gap(12).items_center().rounded(5)
|
|
383
|
+
.when(this.selected === todo.taskId, (element) => element.bg(t.selected))
|
|
384
|
+
.hover((style) => style.bg(this.selected === todo.taskId ? t.selected : t.hover))
|
|
385
|
+
.child(h_flex().flex_1().min_w(0).pl(this.width < 450 ? 8 : 18).gap(7).items_center()
|
|
386
|
+
.child(div().w(10).h(17).flex_none().border_l(1).border_b(1).border_color(t.input).rounded_bl(4))
|
|
387
|
+
.child(this.stateMark(todo, t))
|
|
388
|
+
.child(this.nameButton("name-" + todo.taskId, todo.taskName,
|
|
389
|
+
todo.taskName + ". " + this.state(todo) + ". " + (this.expanded.has(todo.taskId) ? "Hide final thoughts" : "Show final thoughts"),
|
|
390
|
+
(cx, event) => {
|
|
391
|
+
// A double-click is one activation, not an immediate open followed by close.
|
|
392
|
+
if (event.click_count === 1) this.toggleTask(todo, cx);
|
|
393
|
+
}, t).text_size(this.width < 450 ? 11 : 12.5).font_medium())
|
|
394
|
+
.child(div().flex_none().text_size(this.width < 450 ? 9 : 11).text_color(t.dim).child(todo.taskId))
|
|
395
|
+
.when(todo.status === "blocked", (element) => element.child(div().flex_none().text_size(10).text_color(t.blocked)
|
|
396
|
+
.child(this.width < 450 ? (ageLabel(blockedAge(todo)) ?? blockedLabel(todo)) : blockedLabel(todo))))
|
|
397
|
+
.when(Boolean(link), (element) => element.child(this.button("agent-" + todo.taskId, "Agent ↗",
|
|
398
|
+
"Focus existing linked agent for " + todo.taskName, (cx) => this.openAgent(todo, cx), t)
|
|
399
|
+
.flex_none().px(5).h(23).text_size(this.width < 450 ? 9 : 10).border(1).border_color(t.input).text_color(t.accent))))
|
|
400
|
+
.child(this.metric("progress-" + todo.taskId, pct === null ? "—" : pct + "%", "Estimated progress", columns.progress, t))
|
|
401
|
+
.child(this.metric("time-" + todo.taskId, duration(time), this.effortDescription(todo, time), columns.time, t));
|
|
402
|
+
const elements = [row];
|
|
403
|
+
if (this.expanded.has(todo.taskId)) {
|
|
404
|
+
const thoughts = this.finalThoughts(todo);
|
|
405
|
+
const dependency = todo.status === "blocked" ? DEPENDENCY_LABELS[todo.dependentOn] : undefined;
|
|
406
|
+
const age = todo.status === "blocked" ? ageLabel(blockedAge(todo)) : null;
|
|
407
|
+
const detail = v_flex().id("description-" + todo.taskId).flex_none().min_w(0).ml(this.width < 450 ? 20 : 38)
|
|
408
|
+
.pl(23).pr(10).py(10).gap(8).border_l(1).border_color(t.input).text_size(12).text_color(t.muted);
|
|
409
|
+
if (todo.goal) {
|
|
410
|
+
detail.child(div().min_w(0).whitespace_normal().child("Goal: " + todo.goal.goal));
|
|
411
|
+
detail.child(div().min_w(0).text_size(10).text_color(t.dim).child("Acceptance criteria"));
|
|
412
|
+
for (const criterion of todo.goal.criteria) detail.child(div().min_w(0).whitespace_normal().child("• " + criterion));
|
|
413
|
+
}
|
|
414
|
+
detail.child(h_flex().min_w(0).gap(8).items_center()
|
|
415
|
+
.child(div().flex_none().text_size(10).text_color(t.dim).child("Final thoughts"))
|
|
416
|
+
.when(dependency !== undefined, (row) => row.child(div().min_w(0).truncate().text_size(10).text_color(t.blocked).child("Dependent on: " + dependency)))
|
|
417
|
+
.when(age !== null, (row) => row.child(div().flex_none().text_size(10).text_color(t.blocked).child("Blocked for: " + age))));
|
|
418
|
+
detail.child(div().min_w(0).whitespace_normal().text_color(todo.status === "blocked" ? t.blocked : t.muted)
|
|
419
|
+
.child(thoughts || "No final thoughts recorded."));
|
|
420
|
+
elements.push(detail);
|
|
421
|
+
}
|
|
422
|
+
return elements;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
render(cx) {
|
|
426
|
+
const t = /** @type {any} */ (theme());
|
|
427
|
+
const columns = this.width < 450 ? { progress: 36, time: 64 } : { progress: 48, time: 83 };
|
|
428
|
+
const root = v_flex().id("pi-tasks-root").size_full().min_w(0).min_h(0).bg(t.background).text_color(t.foreground)
|
|
429
|
+
.text_size(12.5).track_focus(this.handle)
|
|
430
|
+
.on_size_change((size, cx) => { if (this.width !== size.width) { this.width = size.width; cx.notify(); } });
|
|
431
|
+
if (this.actionError) root.child(div().px(16).py(6).text_size(12).text_color(t.blocked).whitespace_normal().child(this.actionError));
|
|
432
|
+
if (!this.document) {
|
|
433
|
+
return this.dismissOnPress(root.child(h_flex().px(16).py(12).gap(8)
|
|
434
|
+
.child(div().flex_1().min_w(0).whitespace_normal().text_color(t.muted).child(this.error || "Loading tasks…"))));
|
|
435
|
+
}
|
|
436
|
+
if (this.error) root.child(div().px(16).py(6).text_color(t.blocked).whitespace_normal().child(this.error));
|
|
437
|
+
if (!this.document.works.length) {
|
|
438
|
+
return this.dismissOnPress(root.child(h_flex().px(16).py(12).gap(8)
|
|
439
|
+
.child(div().flex_1().min_w(0).whitespace_normal().text_color(t.muted).child("No works or tasks yet."))));
|
|
440
|
+
}
|
|
441
|
+
// Visibility only: Work progress/effort below still use every task of the Work, and no record
|
|
442
|
+
// is touched. A changed selection starts at the first matching result instead of an old offset.
|
|
443
|
+
const filter = this.statusFilter();
|
|
444
|
+
if (filter !== this.filter) {
|
|
445
|
+
this.filter = filter;
|
|
446
|
+
this.scroll.scroll_to_item(0);
|
|
447
|
+
}
|
|
448
|
+
// A Work is drawn only while it has a task this selection lists, so a Work with no tasks or no
|
|
449
|
+
// match leaves no empty heading. Records stay untouched.
|
|
450
|
+
const rows = [...this.document.works].reverse().map((work) => {
|
|
451
|
+
const todos = this.document.todos.filter((todo) => todo.workId === work.workId);
|
|
452
|
+
return { work, todos, shown: visibleTodos(todos, filter) };
|
|
453
|
+
}).filter((row) => row.shown.length > 0);
|
|
454
|
+
const list = v_flex().id("pi-task-list").flex_1().min_h(0).min_w(0).overflow_y_scrollbar().px(this.width < 450 ? 10 : 20).pt(22).pb(20)
|
|
455
|
+
.track_scroll(this.scroll);
|
|
456
|
+
if (!rows.length) {
|
|
457
|
+
// The trigger beside this pane already names the selected status, so the empty state does not
|
|
458
|
+
// repeat it, and a split blocked entry never leaks its stored value into the copy.
|
|
459
|
+
return this.dismissOnPress(root.child(list.child(div().px(10).py(6).text_color(t.muted)
|
|
460
|
+
.child(filter === "all" ? "No tasks yet." : "No matching tasks."))));
|
|
461
|
+
}
|
|
462
|
+
for (const [index, { work, todos, shown }] of rows.entries()) {
|
|
463
|
+
if (index) list.child(div().h(1).flex_none().my(16).bg(t.border));
|
|
464
|
+
const open = !this.collapsed.has(work.workId);
|
|
465
|
+
const pct = progress(todos);
|
|
466
|
+
const times = todos.map((todo) => elapsed(todo, this.at(todo)));
|
|
467
|
+
const sum = times.length && !times.includes(null) ? times.reduce((a, b) => a + b, 0) : null;
|
|
468
|
+
const total = number(sum) ? sum : null;
|
|
469
|
+
list.child(h_flex().id("work-" + work.workId).h(30).flex_none().min_w(0).px(10).gap(12).items_center()
|
|
470
|
+
.child(h_flex().flex_1().min_w(0).gap(6).items_center()
|
|
471
|
+
.child(this.nameButton("work-name-" + work.workId, work.workName,
|
|
472
|
+
work.workName + ". " + (open ? "Collapse work" : "Expand work"), (cx) => {
|
|
473
|
+
if (this.collapsed.has(work.workId)) this.collapsed.delete(work.workId); else this.collapsed.add(work.workId);
|
|
474
|
+
cx.notify();
|
|
475
|
+
}, t).text_size(this.width < 450 ? 12 : 13).font_semibold())
|
|
476
|
+
.child(div().flex_none().text_size(10).text_color(t.dim).child(work.workId)))
|
|
477
|
+
.child(this.metric("work-progress-" + work.workId, pct === null ? "—" : pct + "%", "Work progress", columns.progress, t))
|
|
478
|
+
.child(this.metric("work-time-" + work.workId, duration(total), total === null ? "Unknown Work effort; a task or report is unmeasured" : "All task effort including cancelled tasks and imported reports once", columns.time, t)));
|
|
479
|
+
if (!open) continue;
|
|
480
|
+
list.child(h_flex().h(25).flex_none().min_w(0).px(10).gap(12).items_center().text_size(10).text_color(t.dim)
|
|
481
|
+
.child(div().flex_1().min_w(0).child("Task"))
|
|
482
|
+
.child(div().w(columns.progress).flex_none().text_right().text_size(this.width < 450 ? 9 : 10).whitespace_nowrap().child("Progress"))
|
|
483
|
+
.child(div().w(columns.time).flex_none().text_right().whitespace_nowrap().child("Effort")));
|
|
484
|
+
for (const todo of shown) list.children(this.taskRow(todo, t, columns));
|
|
485
|
+
}
|
|
486
|
+
return this.dismissOnPress(root.child(list));
|
|
487
|
+
}
|
|
488
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M8 2a6 6 0 1 1-6 6" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abhishek944/pi-tasks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Session-scoped work and todo tracking for Pi.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
],
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/",
|
|
20
|
+
"herdr/pi-tasks/main.js",
|
|
21
|
+
"herdr/pi-tasks/header.js",
|
|
22
|
+
"herdr/pi-tasks/spinner.svg",
|
|
23
|
+
"herdr/pi-tasks/mod.json",
|
|
24
|
+
"herdr/pi-tasks/README.md",
|
|
20
25
|
"docs/USAGE_GUIDE.md",
|
|
21
26
|
"docs/REFERENCE.md",
|
|
22
27
|
"README.md",
|
|
@@ -28,14 +33,25 @@
|
|
|
28
33
|
"import": "./dist/index.js",
|
|
29
34
|
"default": "./dist/index.js"
|
|
30
35
|
},
|
|
36
|
+
"./durable": {
|
|
37
|
+
"types": "./dist/durable.d.ts",
|
|
38
|
+
"import": "./dist/durable.js",
|
|
39
|
+
"default": "./dist/durable.js"
|
|
40
|
+
},
|
|
31
41
|
"./package.json": "./package.json"
|
|
32
42
|
},
|
|
33
43
|
"peerDependencies": {
|
|
34
44
|
"@earendil-works/pi-coding-agent": ">=0.85.1",
|
|
45
|
+
"@earendil-works/pi-durable": "1.1.0",
|
|
35
46
|
"@earendil-works/pi-tui": ">=0.85.1",
|
|
36
47
|
"@earendil-works/pi-ai": "*",
|
|
37
48
|
"typebox": "*"
|
|
38
49
|
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@earendil-works/pi-durable": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
39
55
|
"scripts": {
|
|
40
56
|
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
41
57
|
"build": "npm run clean && tsc",
|
|
@@ -49,6 +65,7 @@
|
|
|
49
65
|
"@earendil-works/pi-ai": "0.85.1",
|
|
50
66
|
"@earendil-works/pi-coding-agent": "0.85.1",
|
|
51
67
|
"@earendil-works/pi-tui": "0.85.1",
|
|
68
|
+
"@earendil-works/pi-durable": "1.1.0",
|
|
52
69
|
"@types/node": "^26.1.2",
|
|
53
70
|
"typebox": "1.3.16",
|
|
54
71
|
"typescript": "^7.0.2"
|
|
@@ -57,5 +74,13 @@
|
|
|
57
74
|
"extensions": [
|
|
58
75
|
"./dist/index.js"
|
|
59
76
|
]
|
|
77
|
+
},
|
|
78
|
+
"repository": {
|
|
79
|
+
"type": "git",
|
|
80
|
+
"url": "https://github.com/abhishek944/astack.git",
|
|
81
|
+
"directory": "packages/pi-tasks"
|
|
82
|
+
},
|
|
83
|
+
"publishConfig": {
|
|
84
|
+
"access": "public"
|
|
60
85
|
}
|
|
61
86
|
}
|
package/dist/agents/tools.d.ts
DELETED