@abhishek944/pi-tasks 0.14.0 → 0.16.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 +59 -12
- package/dist/agents/delegation.d.ts +4 -0
- package/dist/agents/delegation.js +59 -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 +160 -27
- package/dist/command.d.ts +2 -2
- package/dist/command.js +8 -4
- package/dist/delegated-time.d.ts +11 -0
- package/dist/delegated-time.js +51 -2
- package/dist/dependency.d.ts +7 -0
- package/dist/dependency.js +13 -0
- package/dist/durable.d.ts +38 -0
- package/dist/durable.js +515 -0
- package/dist/herdr-header.d.ts +3 -0
- package/dist/herdr-header.js +100 -0
- package/dist/herdr-panel.d.ts +7 -0
- package/dist/herdr-panel.js +182 -0
- package/dist/index.js +98 -56
- package/dist/markdown.js +3 -1
- package/dist/open-repository.d.ts +5 -3
- package/dist/open-repository.js +19 -5
- package/dist/panel-settings.d.ts +11 -0
- package/dist/panel-settings.js +30 -0
- package/dist/snapshot.d.ts +23 -0
- package/dist/snapshot.js +123 -0
- package/dist/state.d.ts +21 -18
- package/dist/state.js +357 -286
- package/dist/thoughts.d.ts +11 -0
- package/dist/thoughts.js +14 -0
- package/dist/timing.js +2 -1
- package/dist/tools.js +48 -29
- package/dist/tracking.js +18 -11
- package/dist/types.d.ts +9 -2
- package/dist/ui/panel.d.ts +2 -1
- package/dist/ui/panel.js +33 -21
- package/dist/ui/task-view.d.ts +7 -0
- package/dist/ui/task-view.js +10 -0
- package/dist/ui/works-dashboard.d.ts +3 -2
- package/dist/ui/works-dashboard.js +33 -24
- package/docs/REFERENCE.md +58 -30
- package/docs/USAGE_GUIDE.md +129 -51
- package/herdr/pi-tasks/README.md +45 -0
- package/herdr/pi-tasks/header.js +192 -0
- package/herdr/pi-tasks/main.js +413 -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,192 @@
|
|
|
1
|
+
// Installed as the entry point of a personal clone of the current pane header.
|
|
2
|
+
// base.js and its assets come from Herdr's official mod.clone, never a shipped-file edit.
|
|
3
|
+
import BaseHeader from "./base.js";
|
|
4
|
+
import { div } from "gpui-kit";
|
|
5
|
+
import { Button, h_flex, Popup, Select, v_flex } from "gpui-base";
|
|
6
|
+
import { panes, props, run, setShared, shared, theme } from "herdr";
|
|
7
|
+
|
|
8
|
+
// Stored task statuses only; "Running" is derived from an active task with a live source, so it
|
|
9
|
+
// belongs to Active. Works have no status and are never filtered by value.
|
|
10
|
+
const STATUSES = [
|
|
11
|
+
{ value: "all", label: "All statuses" },
|
|
12
|
+
{ value: "active", label: "Active" },
|
|
13
|
+
{ value: "blocked", label: "Blocked" },
|
|
14
|
+
{ value: "completed", label: "Completed" },
|
|
15
|
+
{ value: "cancelled", label: "Cancelled" },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export default class TasksHeader extends BaseHeader {
|
|
19
|
+
init(props, cx) {
|
|
20
|
+
super.init?.(props, cx);
|
|
21
|
+
this.activityFocus = [cx.focus_handle(), cx.focus_handle()];
|
|
22
|
+
this.statusIndex = 0;
|
|
23
|
+
this.statusTrigger = cx.focus_handle();
|
|
24
|
+
this.statusContent = cx.focus_handle();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
activityHeader(id) {
|
|
28
|
+
const t = theme();
|
|
29
|
+
const key = "pi-activity-section:" + id;
|
|
30
|
+
const selected = shared(key) === "monitors" ? "monitors" : "loops";
|
|
31
|
+
const sections = ["loops", "monitors"];
|
|
32
|
+
const select = (index) => {
|
|
33
|
+
const target = panes().find((item) => item.pane === id);
|
|
34
|
+
if (target?.mod !== "pi-loop-monitor" || target.terminal !== null) return;
|
|
35
|
+
run("pane.focus", { pane: id });
|
|
36
|
+
setShared(key, sections[index]);
|
|
37
|
+
this.activityFocus[index].focus();
|
|
38
|
+
};
|
|
39
|
+
return h_flex().id("activity-header-" + id).size_full().px(10).gap(12).items_center()
|
|
40
|
+
.bg(t.background).border_b(1).border_color(t.border).text_size(12)
|
|
41
|
+
.child(h_flex().h_full().gap(12).role("tab_list").accessibility_label("Loops and Monitors sections")
|
|
42
|
+
.children(sections.map((section, index) => Button.new("activity-tab-" + id + section)
|
|
43
|
+
.h_full().px(4).role("tab").selected(selected === section).set_position(index + 1, 2)
|
|
44
|
+
.track_focus(this.activityFocus[index]).tab_stop(selected === section)
|
|
45
|
+
.text_color(selected === section ? t.foreground : t.dim)
|
|
46
|
+
.when(selected === section, (style) => style.font_semibold().border_b(2).border_color(t.accent))
|
|
47
|
+
.hover((style) => style.bg(t.hover)).focus((style) => style.bg(t.selected))
|
|
48
|
+
.accessibility_label(section === "loops" ? "Loops" : "Monitors")
|
|
49
|
+
.on_mouse_down("left", (_event, cx) => cx.stop_propagation())
|
|
50
|
+
.on_click((_event, cx) => { cx.stop_propagation(); select(index); })
|
|
51
|
+
.on_key_down((event, cx) => {
|
|
52
|
+
if (!["left", "right", "home", "end"].includes(event.key)) return;
|
|
53
|
+
cx.stop_propagation();
|
|
54
|
+
const next = event.key === "home" ? 0 : event.key === "end" ? 1 : 1 - index;
|
|
55
|
+
select(next);
|
|
56
|
+
}).child(section === "loops" ? "Loops" : "Monitors"))))
|
|
57
|
+
.child(div().flex_1())
|
|
58
|
+
.child(Button.new("activity-close-" + id).size(30).flex_none().rounded(4).cursor_pointer()
|
|
59
|
+
.text_size(22).text_color(t.muted).hover((style) => style.bg(t.hover).text_color(t.foreground))
|
|
60
|
+
.focus((style) => style.bg(t.selected).text_color(t.accent)).tab_stop(true)
|
|
61
|
+
.accessibility_label("Close Loops and Monitors view").tooltip("Close only this view; Tasks, Pi, loops and monitors continue")
|
|
62
|
+
.on_mouse_down("left", (_event, cx) => cx.stop_propagation())
|
|
63
|
+
.on_click((_event, cx) => {
|
|
64
|
+
cx.stop_propagation();
|
|
65
|
+
const target = panes().find((item) => item.pane === id);
|
|
66
|
+
if (target?.mod === "pi-loop-monitor" && target.terminal === null) run("pane.close", { pane: id });
|
|
67
|
+
}).child("×"));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The content copy cannot name its own pane, so this pane's header publishes the selected status
|
|
71
|
+
// under a pane-scoped key; the Tasks view reads the same key through the pane id it is given.
|
|
72
|
+
statusKey(id) {
|
|
73
|
+
return "pi-tasks-status:" + id;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
statusValue(id) {
|
|
77
|
+
const value = shared(this.statusKey(id));
|
|
78
|
+
return STATUSES.some((item) => item.value === value) ? value : "all";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Open state is shared with this pane's view, which closes the menu when the pointer goes down
|
|
82
|
+
// anywhere in the task list: Herdr's Select owns Escape and its own dismissal, but a click
|
|
83
|
+
// outside this mod never reaches it.
|
|
84
|
+
statusOpenKey(id) {
|
|
85
|
+
return "pi-tasks-status-open:" + id;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
statusOpen(id) {
|
|
89
|
+
return shared(this.statusOpenKey(id)) === true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
setStatusOpen(id, open) {
|
|
93
|
+
setShared(this.statusOpenKey(id), open);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
statusControl(id, t) {
|
|
97
|
+
const value = this.statusValue(id);
|
|
98
|
+
const current = STATUSES.find((item) => item.value === value) ?? STATUSES[0];
|
|
99
|
+
const open = this.statusOpen(id);
|
|
100
|
+
const choose = (entry, cx) => {
|
|
101
|
+
setShared(this.statusKey(id), entry.value);
|
|
102
|
+
this.setStatusOpen(id, false);
|
|
103
|
+
this.statusIndex = Math.max(0, STATUSES.findIndex((item) => item.value === entry.value));
|
|
104
|
+
this.statusTrigger.focus();
|
|
105
|
+
cx.notify();
|
|
106
|
+
};
|
|
107
|
+
const close = (cx) => {
|
|
108
|
+
this.setStatusOpen(id, false);
|
|
109
|
+
this.statusTrigger.focus();
|
|
110
|
+
cx.notify();
|
|
111
|
+
};
|
|
112
|
+
const trigger = h_flex().id("tasks-status-trigger-" + id).h(26).w(120).flex_none().min_w(0).px(8).gap(4).items_center()
|
|
113
|
+
.bg(t.background).rounded(6).border(1).border_color(t.input)
|
|
114
|
+
.track_focus(this.statusTrigger).tab_index(0).cursor_pointer()
|
|
115
|
+
.accessibility_label("Task status: " + current.label).tooltip("Show only tasks with one status")
|
|
116
|
+
.focus((style) => style.border_color(t.accent))
|
|
117
|
+
.on_mouse_down("left", (_event, cx) => cx.stop_propagation())
|
|
118
|
+
.on_click((_event, cx) => {
|
|
119
|
+
cx.stop_propagation();
|
|
120
|
+
const next = !this.statusOpen(id);
|
|
121
|
+
this.setStatusOpen(id, next);
|
|
122
|
+
if (next) this.statusIndex = Math.max(0, STATUSES.findIndex((item) => item.value === value));
|
|
123
|
+
(next ? this.statusContent : this.statusTrigger).focus();
|
|
124
|
+
cx.notify();
|
|
125
|
+
})
|
|
126
|
+
.child(div().flex_1().min_w(0).truncate().text_size(12).text_color(t.foreground).child(current.label))
|
|
127
|
+
.child(div().flex_none().text_size(11).text_color(t.muted).child("⌄"));
|
|
128
|
+
// Anchoring to the trigger and growing down-right is the one placement this 32px pane header
|
|
129
|
+
// supports: an anchor above the trigger would land outside the window.
|
|
130
|
+
const menu = v_flex().id("tasks-status-menu-" + id).w(190).min_w(0).p(5).gap(1).rounded(6)
|
|
131
|
+
.border(1).border_color(t.input).bg(t.popover).text_color(t.foreground)
|
|
132
|
+
.track_focus(this.statusContent).role("list_box").accessibility_label("Task status")
|
|
133
|
+
.on_key_down((event, cx) => {
|
|
134
|
+
if (event.key === "up" || event.key === "down") {
|
|
135
|
+
const step = event.key === "down" ? 1 : -1;
|
|
136
|
+
this.statusIndex = (this.statusIndex + step + STATUSES.length) % STATUSES.length;
|
|
137
|
+
cx.stop_propagation(); cx.notify();
|
|
138
|
+
} else if (event.key === "enter" || event.key === "return") {
|
|
139
|
+
choose(STATUSES[this.statusIndex], cx); cx.stop_propagation();
|
|
140
|
+
} else if (event.key === "escape") {
|
|
141
|
+
close(cx); cx.stop_propagation();
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
.children(STATUSES.map((entry, index) => h_flex().id("tasks-status-option-" + id + entry.value).h(30).flex_none().min_w(0).px(6).gap(6).items_center()
|
|
145
|
+
.rounded(4).role("list_box_option").accessibility_label(entry.label).selected(entry.value === value)
|
|
146
|
+
.when(index === this.statusIndex, (row) => row.aria_active_descendant())
|
|
147
|
+
.bg(index === this.statusIndex ? t.selected : t.popover).hover((style) => style.bg(t.hover))
|
|
148
|
+
.cursor_pointer()
|
|
149
|
+
.on_mouse_down("left", (_event, cx) => cx.stop_propagation())
|
|
150
|
+
.on_click((_event, cx) => { cx.stop_propagation(); choose(entry, cx); })
|
|
151
|
+
.child(div().w(12).flex_none().text_size(12).text_color(t.foreground).child(entry.value === value ? "✓" : ""))
|
|
152
|
+
.child(div().flex_1().min_w(0).truncate().text_size(12).child(entry.label))));
|
|
153
|
+
const select = Select.new("tasks-status-" + id).accessibility_label("Task status").open(open)
|
|
154
|
+
.track_focus(this.statusTrigger).content_focus_handle(this.statusContent)
|
|
155
|
+
.on_open_change((next, cx) => {
|
|
156
|
+
this.setStatusOpen(id, next);
|
|
157
|
+
if (next) this.statusIndex = Math.max(0, STATUSES.findIndex((item) => item.value === value));
|
|
158
|
+
cx.notify();
|
|
159
|
+
})
|
|
160
|
+
.on_confirm((_event, cx) => choose(STATUSES[this.statusIndex], cx))
|
|
161
|
+
.on_dismiss((_event, cx) => close(cx))
|
|
162
|
+
.child(Popup.new("tasks-status-popup-" + id, trigger).anchor("bottom_right")
|
|
163
|
+
.when(open, (el) => el.content(menu)));
|
|
164
|
+
return select;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
render(cx) {
|
|
168
|
+
const id = props()?.pane;
|
|
169
|
+
const pane = panes().find((item) => item.pane === id);
|
|
170
|
+
if (pane?.mod === "pi-loop-monitor" && pane.terminal === null) return this.activityHeader(id);
|
|
171
|
+
if (pane?.mod !== "pi-tasks" || pane.terminal !== null) return super.render(cx);
|
|
172
|
+
const t = theme();
|
|
173
|
+
return h_flex().id("tasks-header-" + id).size_full().px(10).items_center().gap(8)
|
|
174
|
+
.bg(t.background).border_b(1).border_color(t.border).text_size(12)
|
|
175
|
+
.on_click(() => {
|
|
176
|
+
if (this.statusOpen(id)) this.setStatusOpen(id, false);
|
|
177
|
+
run("pane.focus", { pane: id });
|
|
178
|
+
})
|
|
179
|
+
.child(div().flex_1().min_w(0).truncate().text_color(t.muted).child("Tasks"))
|
|
180
|
+
.child(this.statusControl(id, t))
|
|
181
|
+
.child(Button.new("tasks-close-" + id).size(32).flex_none().rounded(4).cursor_pointer()
|
|
182
|
+
.text_size(22).text_color(t.muted).hover((style) => style.bg(t.hover).text_color(t.foreground))
|
|
183
|
+
.focus((style) => style.bg(t.selected).text_color(t.accent))
|
|
184
|
+
.accessibility_label("Close Tasks view").tooltip("Close Tasks only; Pi, agents and tracking continue").tab_stop(true)
|
|
185
|
+
.on_mouse_down("left", (_event, cx) => cx.stop_propagation())
|
|
186
|
+
.on_click((_event, cx) => {
|
|
187
|
+
cx.stop_propagation();
|
|
188
|
+
const target = panes().find((item) => item.pane === id);
|
|
189
|
+
if (target?.mod === "pi-tasks" && target.terminal === null) run("pane.close", { pane: id });
|
|
190
|
+
}).child("×"));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -0,0 +1,413 @@
|
|
|
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", "cancelled"];
|
|
9
|
+
const DEPENDENCIES = ["user-decision", "another-agent"];
|
|
10
|
+
const DEPENDENCY_LABELS = { "user-decision": "User decision", "another-agent": "Another agent" };
|
|
11
|
+
// The pane this view is drawn in; the opener publishes it because a pane content copy
|
|
12
|
+
// receives only its creation props, and the live pane inventory names it. See README "Status filter".
|
|
13
|
+
const PANE = /^p[A-Za-z0-9]+$/;
|
|
14
|
+
const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
15
|
+
const number = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
16
|
+
const text = (value) => typeof value === "string" && value.trim().length > 0;
|
|
17
|
+
|
|
18
|
+
function owner(info) {
|
|
19
|
+
const owners = new Set([...info.matchAll(/^[ \t]*owner:[ \t]*(self|delegate)(?=[ \t.,;:\r]|$)/gim)].map((match) => match[1].toLowerCase()));
|
|
20
|
+
return owners.size === 1 ? [...owners][0] : "unassigned";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function delegate(todo) {
|
|
24
|
+
if (owner(todo.taskInfo) !== "delegate") return null;
|
|
25
|
+
const links = [...todo.taskInfo.matchAll(/^[ \t]*hc-terminal:[ \t]*([^\r\n]*)$/gim)].map((match) => match[1].trim());
|
|
26
|
+
return links.length > 0 && links.every((link) => TERMINAL.test(link)) && new Set(links).size === 1 ? links[0] : null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function completion(todo) {
|
|
30
|
+
if (todo.status === "completed") return 100;
|
|
31
|
+
return number(todo.completionPercent) && todo.completionPercent < 100 ? todo.completionPercent : null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function progress(todos) {
|
|
35
|
+
const eligible = todos.filter((todo) => todo.status !== "cancelled");
|
|
36
|
+
const values = eligible.map(completion);
|
|
37
|
+
return !values.length || values.includes(null) ? null : Math.floor(values.reduce((a, b) => a + b, 0) / values.length);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function elapsed(todo, at) {
|
|
41
|
+
if (owner(todo.taskInfo) === "delegate" && !todo.delegatedTimes?.length) return null;
|
|
42
|
+
if (!number(todo.elapsedMs)) return null;
|
|
43
|
+
let total = todo.elapsedMs + (todo.workingSince === undefined ? 0 : Math.max(0, at - todo.workingSince));
|
|
44
|
+
for (const source of todo.delegatedTimes ?? []) {
|
|
45
|
+
if (!number(source.elapsedMs)) return null;
|
|
46
|
+
total += source.elapsedMs;
|
|
47
|
+
}
|
|
48
|
+
return number(total) ? total : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function totalTime(todos, at) {
|
|
52
|
+
const values = todos.map((todo) => elapsed(todo, at));
|
|
53
|
+
if (!values.length || values.includes(null)) return null;
|
|
54
|
+
const total = values.reduce((a, b) => a + b, 0);
|
|
55
|
+
return number(total) ? total : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function duration(ms) {
|
|
59
|
+
if (ms === null) return "—";
|
|
60
|
+
const seconds = Math.floor(ms / 1000);
|
|
61
|
+
const minutes = Math.floor(seconds / 60);
|
|
62
|
+
const hours = Math.floor(minutes / 60);
|
|
63
|
+
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`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function validate(value, sessionId) {
|
|
67
|
+
if (!object(value) || value.version !== 1 || value.sessionId !== sessionId || !text(value.cwd) || !number(value.updatedAt)
|
|
68
|
+
|| typeof value.agentRunning !== "boolean" || !Array.isArray(value.works) || value.works.length > 100
|
|
69
|
+
|| !Array.isArray(value.todos) || value.todos.length > 500) throw new Error("Invalid or mismatched session task snapshot.");
|
|
70
|
+
const works = new Set();
|
|
71
|
+
const tasks = new Set();
|
|
72
|
+
for (const work of value.works) {
|
|
73
|
+
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.");
|
|
74
|
+
works.add(work.workId);
|
|
75
|
+
}
|
|
76
|
+
for (const todo of value.todos) {
|
|
77
|
+
if (!object(todo) || !/^T[1-9][0-9]*$/.test(todo.taskId) || tasks.has(todo.taskId) || !works.has(todo.workId)
|
|
78
|
+
|| !text(todo.taskName) || !text(todo.taskInfo) || !STATUSES.includes(todo.status)
|
|
79
|
+
|| (todo.blockedReason != null && typeof todo.blockedReason !== "string")
|
|
80
|
+
|| (todo.dependentOn !== undefined && (todo.status !== "blocked" || !DEPENDENCIES.includes(todo.dependentOn)))
|
|
81
|
+
|| (todo.finalThoughts !== undefined && !text(todo.finalThoughts))
|
|
82
|
+
|| (todo.workingSince !== undefined && !number(todo.workingSince))
|
|
83
|
+
|| (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.");
|
|
84
|
+
tasks.add(todo.taskId);
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default class Tasks extends View {
|
|
90
|
+
init(_props, cx) {
|
|
91
|
+
const binding = props() ?? {};
|
|
92
|
+
this.sessionId = binding.sessionId;
|
|
93
|
+
this.path = binding.snapshot;
|
|
94
|
+
this.terminal = binding.terminal;
|
|
95
|
+
this.selected = null;
|
|
96
|
+
this.expanded = new Set();
|
|
97
|
+
this.collapsed = new Set();
|
|
98
|
+
this.document = null;
|
|
99
|
+
this.error = "";
|
|
100
|
+
this.actionError = "";
|
|
101
|
+
this.closed = false;
|
|
102
|
+
this.loading = false;
|
|
103
|
+
this.bound = false;
|
|
104
|
+
this.width = 800;
|
|
105
|
+
this.handle = cx.focus_handle();
|
|
106
|
+
if (typeof this.sessionId !== "string" || !SESSION.test(this.sessionId)) {
|
|
107
|
+
this.error = "Reopen Tasks from the intended Pi session with /works-panel herdr.";
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (typeof this.path !== "string" || !/^(?:\/|[A-Za-z]:[\\/])/.test(this.path) || this.path.includes("\0")) {
|
|
111
|
+
this.error = "Restart Pi, resume this session, then reopen Tasks with /works-panel herdr.";
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this.paneFile = typeof binding.paneFile === "string" && /^(?:\/|[A-Za-z]:[\\/])/.test(binding.paneFile) && !binding.paneFile.includes("\0")
|
|
115
|
+
? binding.paneFile : null;
|
|
116
|
+
this.paneId = null;
|
|
117
|
+
this.filter = "all";
|
|
118
|
+
this.scroll = ScrollHandle.new();
|
|
119
|
+
this.bound = true;
|
|
120
|
+
this.directory = this.path.replace(/[\\/][^\\/]+$/, "");
|
|
121
|
+
cx.spawn(async (cx) => {
|
|
122
|
+
await this.reload(cx);
|
|
123
|
+
try {
|
|
124
|
+
while (!this.closed) {
|
|
125
|
+
const changed = await watchFolder(this.directory);
|
|
126
|
+
if (this.closed) return;
|
|
127
|
+
if (changed.some((path) => path.replace(/\\/g, "/") === this.path.replace(/\\/g, "/"))) await this.reload(cx);
|
|
128
|
+
}
|
|
129
|
+
} catch {
|
|
130
|
+
if (!this.closed) { this.error = "Live updates stopped. Reopen Tasks with /works herdr-off then /works herdr-on."; cx.notify(); }
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
// A measured clock, not a spinner animation. Offline/saved values never tick.
|
|
134
|
+
cx.timer.every(1000, (cx) => {
|
|
135
|
+
if (this.document?.todos.some((todo) => todo.workingSince !== undefined && this.running(todo))) cx.notify();
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async reload(cx) {
|
|
140
|
+
if (this.closed || !this.bound) return;
|
|
141
|
+
if (this.loading) { this.reloadPending = true; return; }
|
|
142
|
+
this.loading = true;
|
|
143
|
+
try {
|
|
144
|
+
await this.readPane(cx);
|
|
145
|
+
let content;
|
|
146
|
+
try { content = await readTextFile(this.path); }
|
|
147
|
+
catch { content = await readFile(this.path, "utf8"); }
|
|
148
|
+
if (content === null) throw new Error("The session task file is missing. Resume Pi or restore the file.");
|
|
149
|
+
if (content.length > 16 * 1024 * 1024) throw new Error("The task file exceeds 16 MiB.");
|
|
150
|
+
const next = validate(JSON.parse(content), this.sessionId);
|
|
151
|
+
if (this.closed) return;
|
|
152
|
+
this.document = next;
|
|
153
|
+
this.error = "";
|
|
154
|
+
const ids = new Set(next.todos.map((todo) => todo.taskId));
|
|
155
|
+
for (const id of this.expanded) if (!ids.has(id)) this.expanded.delete(id);
|
|
156
|
+
if (!ids.has(this.selected)) this.selected = null;
|
|
157
|
+
} catch (error) {
|
|
158
|
+
this.document = null;
|
|
159
|
+
this.error = error instanceof Error ? error.message : String(error);
|
|
160
|
+
} finally {
|
|
161
|
+
this.loading = false;
|
|
162
|
+
if (!this.closed) {
|
|
163
|
+
cx.notify();
|
|
164
|
+
if (this.reloadPending) { this.reloadPending = false; await this.reload(cx); }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
close() { this.closed = true; }
|
|
170
|
+
|
|
171
|
+
// A pane content copy is given only its creation props, so the opener publishes the hosting pane
|
|
172
|
+
// id beside the snapshot. A pane opened before that hand-off existed carries no `paneFile` prop,
|
|
173
|
+
// and its stored props never change, so the live inventory is the fallback: the opener always
|
|
174
|
+
// splits the view into the source terminal's tab, where exactly one Tasks pane is this one.
|
|
175
|
+
// Anything absent, malformed or ambiguous leaves this view unfiltered instead of guessing another
|
|
176
|
+
// pane's selection. The file lives beside the watched snapshot, so the directory retries a
|
|
177
|
+
// first-mount race.
|
|
178
|
+
async readPane(_cx) {
|
|
179
|
+
let published = null;
|
|
180
|
+
if (this.paneFile) {
|
|
181
|
+
try {
|
|
182
|
+
const content = await readTextFile(this.paneFile);
|
|
183
|
+
const value = content === null ? "" : content.trim();
|
|
184
|
+
published = PANE.test(value) ? value : null;
|
|
185
|
+
} catch { published = null; }
|
|
186
|
+
}
|
|
187
|
+
this.paneId = published ?? this.paneFromInventory();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
paneFromInventory() {
|
|
191
|
+
if (typeof this.terminal !== "string") return null;
|
|
192
|
+
const host = panes().find((pane) => pane.terminal === this.terminal);
|
|
193
|
+
if (!host) return null;
|
|
194
|
+
const siblings = panes().filter((pane) => pane.mod === "pi-tasks" && pane.terminal === null && pane.tab === host.tab);
|
|
195
|
+
const id = siblings.length === 1 ? siblings[0].pane : null;
|
|
196
|
+
return typeof id === "string" && PANE.test(id) ? id : null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
statusFilter() {
|
|
200
|
+
const value = this.paneId === null ? "all" : shared("pi-tasks-status:" + this.paneId);
|
|
201
|
+
return STATUSES.includes(value) ? value : "all";
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// The header owns the menu, so a press in this view must dismiss it: Herdr closes a Select on
|
|
205
|
+
// Escape and on presses inside its own mod, never on one that lands here. A press anywhere in the
|
|
206
|
+
// view reaches this root handler; the selected status is a separate value, so dismissing keeps it.
|
|
207
|
+
dismissOnPress(element) {
|
|
208
|
+
if (this.paneId === null) return element;
|
|
209
|
+
return element.on_mouse_down("left", (_event, cx) => {
|
|
210
|
+
if (shared("pi-tasks-status-open:" + this.paneId) !== true) return;
|
|
211
|
+
setShared("pi-tasks-status-open:" + this.paneId, false);
|
|
212
|
+
cx.notify();
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
linked(todo) {
|
|
217
|
+
const link = delegate(todo);
|
|
218
|
+
return link && terminals().some((terminal) => terminal.address === link && terminal.state === "live") ? link : null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
running(todo) {
|
|
222
|
+
if (todo.status !== "active") return false;
|
|
223
|
+
const link = this.linked(todo);
|
|
224
|
+
if (link) return agents().some((agent) => agent.address === link && agent.status === "working");
|
|
225
|
+
const source = this.document?.terminalId ?? this.terminal;
|
|
226
|
+
return owner(todo.taskInfo) === "self" && todo.status === "active" && todo.workingSince !== undefined
|
|
227
|
+
&& this.document?.agentRunning && this.document.focusedTaskId === todo.taskId
|
|
228
|
+
&& terminals().some((terminal) => terminal.address === source && terminal.state === "live")
|
|
229
|
+
&& agents().some((agent) => agent.address === source && agent.status === "working");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
at(todo) {
|
|
233
|
+
return todo.workingSince !== undefined && this.running(todo) ? Date.now() : this.document.updatedAt;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
state(todo) {
|
|
237
|
+
return this.running(todo) ? "Running" : todo.status === "blocked" ? "Blocked"
|
|
238
|
+
: todo.status === "completed" ? "Completed" : todo.status === "cancelled" ? "Cancelled" : "Active; not running";
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
button(id, label, accessible, callback, t, underlineFocus = false) {
|
|
242
|
+
return Button.new(id).min_w(0).rounded(4).cursor_pointer().text_color(t.foreground)
|
|
243
|
+
.accessibility_label(accessible).tooltip(accessible).tab_stop(true)
|
|
244
|
+
// Name controls underline on focus; a selected background fill looks like
|
|
245
|
+
// selected text. Task-row selection keeps its own background.
|
|
246
|
+
.focus((style) => underlineFocus ? style.underline() : style.bg(t.selected).text_color(t.accent))
|
|
247
|
+
.on_click((event, cx) => { cx.stop_propagation(); callback(cx, event); }).child(label);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
nameButton(id, label, accessible, callback, t) {
|
|
251
|
+
// Constrain the label itself so long names ellipsize at the end, not under the status glyph.
|
|
252
|
+
return this.button(id, div().flex_1().min_w(0).truncate().text_left().child(label), accessible, callback, t, true)
|
|
253
|
+
.flex().flex_1().min_w(0).items_center().justify_start().overflow_hidden();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
toggleTask(todo, cx) {
|
|
257
|
+
this.selected = todo.taskId;
|
|
258
|
+
if (this.expanded.has(todo.taskId)) this.expanded.delete(todo.taskId);
|
|
259
|
+
else this.expanded.add(todo.taskId);
|
|
260
|
+
cx.notify();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
openAgent(todo, cx) {
|
|
264
|
+
const link = this.linked(todo);
|
|
265
|
+
if (!link) { this.actionError = "The linked agent is no longer available."; cx.notify(); return; }
|
|
266
|
+
// A pane-less sub-agent cannot be selected; agent.focus acknowledges it but
|
|
267
|
+
// shows nothing. Present its own screen over the current tab instead. The
|
|
268
|
+
// app lists only the first child level, so a deeper child is recognized by
|
|
269
|
+
// its Core parent. A terminal that owns a pane, or another machine's
|
|
270
|
+
// terminal, keeps the normal agent focus. Never navigate to the parent.
|
|
271
|
+
let command;
|
|
272
|
+
if (link.includes("/") || panes().some((pane) => pane.terminal === link)) command = "agent.focus";
|
|
273
|
+
else {
|
|
274
|
+
const record = terminals().find((terminal) => terminal.address === link);
|
|
275
|
+
command = record?.parent ? "terminal.peek" : null;
|
|
276
|
+
}
|
|
277
|
+
if (!command) { this.actionError = "Herdr is not showing this agent. Open its space, then retry."; cx.notify(); return; }
|
|
278
|
+
try { run(command, { terminal: link }); this.actionError = ""; }
|
|
279
|
+
catch { this.actionError = command === "terminal.peek" ? "Could not open the linked agent's screen." : "Could not focus the linked agent."; }
|
|
280
|
+
cx.notify();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
finalThoughts(todo) {
|
|
284
|
+
if (todo.status === "blocked") return (todo.blockedReason || "").trim() || (todo.finalThoughts || "").trim();
|
|
285
|
+
return (todo.finalThoughts || "").trim();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
stateMark(todo, t) {
|
|
289
|
+
const state = this.state(todo);
|
|
290
|
+
if (state === "Running") {
|
|
291
|
+
return svg("mods/pi-tasks/spinner.svg").size(11).flex_none().text_color(t.working)
|
|
292
|
+
.spin(900).role("image").accessibility_label(state).tooltip(state);
|
|
293
|
+
}
|
|
294
|
+
const mark = state === "Blocked" ? "!" : state === "Completed" ? "✓" : state === "Cancelled" ? "×" : "○";
|
|
295
|
+
return div().w(11).flex_none().text_size(12).text_center()
|
|
296
|
+
.text_color(state === "Blocked" ? t.blocked : state === "Completed" ? t.done : t.dim)
|
|
297
|
+
.role("image").accessibility_label(state).tooltip(state).child(mark);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
effortDescription(todo, value) {
|
|
301
|
+
if (value === null) {
|
|
302
|
+
if (owner(todo.taskInfo) === "delegate" && !todo.delegatedTimes?.length) return "Unknown effort; delegate measurement has not been imported";
|
|
303
|
+
if (todo.delegatedTimes?.some((report) => report.elapsedMs === null)) return "Unknown effort; an imported delegate report is unmeasured";
|
|
304
|
+
return "Unknown effort; no complete measurement is recorded, not zero";
|
|
305
|
+
}
|
|
306
|
+
const state = this.running(todo) && todo.workingSince !== undefined ? "Running own measurement"
|
|
307
|
+
: todo.status === "completed" || todo.status === "cancelled" ? "Stopped own measurement" : "Saved measurement; not currently running";
|
|
308
|
+
return state + (todo.delegatedTimes?.length ? "; includes imported delegate effort once" : "; own measured effort");
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
metric(id, value, label, width, t) {
|
|
312
|
+
return div().id(id).w(width).flex_none().text_right().text_size(11).whitespace_nowrap().text_color(t.muted)
|
|
313
|
+
.role("label").accessibility_label(label + ": " + value).tooltip(label + ": " + value).child(value);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
taskRow(todo, t, columns) {
|
|
317
|
+
const link = this.linked(todo);
|
|
318
|
+
const pct = completion(todo);
|
|
319
|
+
const time = elapsed(todo, this.at(todo));
|
|
320
|
+
const row = h_flex().id("task-" + todo.taskId).h(30).flex_none().min_w(0).px(10).gap(12).items_center().rounded(5)
|
|
321
|
+
.when(this.selected === todo.taskId, (element) => element.bg(t.selected))
|
|
322
|
+
.hover((style) => style.bg(this.selected === todo.taskId ? t.selected : t.hover))
|
|
323
|
+
.child(h_flex().flex_1().min_w(0).pl(this.width < 450 ? 8 : 18).gap(7).items_center()
|
|
324
|
+
.child(div().w(10).h(17).flex_none().border_l(1).border_b(1).border_color(t.input).rounded_bl(4))
|
|
325
|
+
.child(this.stateMark(todo, t))
|
|
326
|
+
.child(this.nameButton("name-" + todo.taskId, todo.taskName,
|
|
327
|
+
todo.taskName + ". " + this.state(todo) + ". " + (this.expanded.has(todo.taskId) ? "Hide final thoughts" : "Show final thoughts"),
|
|
328
|
+
(cx, event) => {
|
|
329
|
+
// A double-click is one activation, not an immediate open followed by close.
|
|
330
|
+
if (event.click_count === 1) this.toggleTask(todo, cx);
|
|
331
|
+
}, t).text_size(this.width < 450 ? 11 : 12.5).font_medium())
|
|
332
|
+
.child(div().flex_none().text_size(this.width < 450 ? 9 : 11).text_color(t.dim).child(todo.taskId))
|
|
333
|
+
.when(Boolean(link), (element) => element.child(this.button("agent-" + todo.taskId, "Agent ↗",
|
|
334
|
+
"Focus existing linked agent for " + todo.taskName, (cx) => this.openAgent(todo, cx), t)
|
|
335
|
+
.flex_none().px(5).h(23).text_size(this.width < 450 ? 9 : 10).border(1).border_color(t.input).text_color(t.accent))))
|
|
336
|
+
.child(this.metric("progress-" + todo.taskId, pct === null ? "—" : pct + "%", "Estimated progress", columns.progress, t))
|
|
337
|
+
.child(this.metric("time-" + todo.taskId, duration(time), this.effortDescription(todo, time), columns.time, t));
|
|
338
|
+
const elements = [row];
|
|
339
|
+
if (this.expanded.has(todo.taskId)) {
|
|
340
|
+
const thoughts = this.finalThoughts(todo);
|
|
341
|
+
const dependency = todo.status === "blocked" ? DEPENDENCY_LABELS[todo.dependentOn] : undefined;
|
|
342
|
+
const detail = v_flex().id("description-" + todo.taskId).flex_none().min_w(0).ml(this.width < 450 ? 20 : 38)
|
|
343
|
+
.pl(23).pr(10).py(10).gap(8).border_l(1).border_color(t.input).text_size(12).text_color(t.muted);
|
|
344
|
+
detail.child(h_flex().min_w(0).gap(8).items_center()
|
|
345
|
+
.child(div().flex_none().text_size(10).text_color(t.dim).child("Final thoughts"))
|
|
346
|
+
.when(dependency !== undefined, (row) => row.child(div().min_w(0).truncate().text_size(10).text_color(t.blocked).child("Dependent on: " + dependency))));
|
|
347
|
+
detail.child(div().min_w(0).whitespace_normal().text_color(todo.status === "blocked" ? t.blocked : t.muted)
|
|
348
|
+
.child(thoughts || "No final thoughts recorded."));
|
|
349
|
+
elements.push(detail);
|
|
350
|
+
}
|
|
351
|
+
return elements;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
render(cx) {
|
|
355
|
+
const t = /** @type {any} */ (theme());
|
|
356
|
+
const columns = this.width < 450 ? { progress: 36, time: 64 } : { progress: 48, time: 83 };
|
|
357
|
+
const root = v_flex().id("pi-tasks-root").size_full().min_w(0).min_h(0).bg(t.background).text_color(t.foreground)
|
|
358
|
+
.text_size(12.5).track_focus(this.handle)
|
|
359
|
+
.on_size_change((size, cx) => { if (this.width !== size.width) { this.width = size.width; cx.notify(); } });
|
|
360
|
+
if (this.actionError) root.child(div().px(16).py(6).text_size(12).text_color(t.blocked).whitespace_normal().child(this.actionError));
|
|
361
|
+
if (!this.document) {
|
|
362
|
+
return this.dismissOnPress(root.child(h_flex().px(16).py(12).gap(8)
|
|
363
|
+
.child(div().flex_1().min_w(0).whitespace_normal().text_color(t.muted).child(this.error || "Loading tasks…"))));
|
|
364
|
+
}
|
|
365
|
+
if (this.error) root.child(div().px(16).py(6).text_color(t.blocked).whitespace_normal().child(this.error));
|
|
366
|
+
if (!this.document.works.length) {
|
|
367
|
+
return this.dismissOnPress(root.child(h_flex().px(16).py(12).gap(8)
|
|
368
|
+
.child(div().flex_1().min_w(0).whitespace_normal().text_color(t.muted).child("No works or tasks yet."))));
|
|
369
|
+
}
|
|
370
|
+
// Visibility only: Work progress/effort below still use every task of the Work, and no record
|
|
371
|
+
// is touched. A changed selection starts at the first matching result instead of an old offset.
|
|
372
|
+
const filter = this.statusFilter();
|
|
373
|
+
if (filter !== this.filter) {
|
|
374
|
+
this.filter = filter;
|
|
375
|
+
this.scroll.scroll_to_item(0);
|
|
376
|
+
}
|
|
377
|
+
const rows = [...this.document.works].reverse().map((work) => {
|
|
378
|
+
const todos = this.document.todos.filter((todo) => todo.workId === work.workId);
|
|
379
|
+
return { work, todos, shown: filter === "all" ? todos : todos.filter((todo) => todo.status === filter) };
|
|
380
|
+
}).filter((row) => filter === "all" || row.shown.length > 0);
|
|
381
|
+
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)
|
|
382
|
+
.track_scroll(this.scroll);
|
|
383
|
+
if (!rows.length) {
|
|
384
|
+
return this.dismissOnPress(root.child(list.child(div().px(10).py(6).text_color(t.muted).child("No " + filter + " tasks."))));
|
|
385
|
+
}
|
|
386
|
+
for (const [index, { work, todos, shown }] of rows.entries()) {
|
|
387
|
+
if (index) list.child(div().h(1).flex_none().my(16).bg(t.border));
|
|
388
|
+
const open = !this.collapsed.has(work.workId);
|
|
389
|
+
const pct = progress(todos);
|
|
390
|
+
const times = todos.map((todo) => elapsed(todo, this.at(todo)));
|
|
391
|
+
const sum = times.length && !times.includes(null) ? times.reduce((a, b) => a + b, 0) : null;
|
|
392
|
+
const total = number(sum) ? sum : null;
|
|
393
|
+
list.child(h_flex().id("work-" + work.workId).h(30).flex_none().min_w(0).px(10).gap(12).items_center()
|
|
394
|
+
.child(h_flex().flex_1().min_w(0).gap(6).items_center()
|
|
395
|
+
.child(this.nameButton("work-name-" + work.workId, work.workName,
|
|
396
|
+
work.workName + ". " + (open ? "Collapse work" : "Expand work"), (cx) => {
|
|
397
|
+
if (this.collapsed.has(work.workId)) this.collapsed.delete(work.workId); else this.collapsed.add(work.workId);
|
|
398
|
+
cx.notify();
|
|
399
|
+
}, t).text_size(this.width < 450 ? 12 : 13).font_semibold())
|
|
400
|
+
.child(div().flex_none().text_size(10).text_color(t.dim).child(work.workId)))
|
|
401
|
+
.child(this.metric("work-progress-" + work.workId, pct === null ? "—" : pct + "%", "Work progress", columns.progress, t))
|
|
402
|
+
.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)));
|
|
403
|
+
if (!open) continue;
|
|
404
|
+
list.child(h_flex().h(25).flex_none().min_w(0).px(10).gap(12).items_center().text_size(10).text_color(t.dim)
|
|
405
|
+
.child(div().flex_1().min_w(0).child("Task"))
|
|
406
|
+
.child(div().w(columns.progress).flex_none().text_right().text_size(this.width < 450 ? 9 : 10).whitespace_nowrap().child("Progress"))
|
|
407
|
+
.child(div().w(columns.time).flex_none().text_right().whitespace_nowrap().child("Effort")));
|
|
408
|
+
for (const todo of shown) list.children(this.taskRow(todo, t, columns));
|
|
409
|
+
if (!shown.length) list.child(div().px(28).py(6).text_color(t.dim).child("No tasks yet."));
|
|
410
|
+
}
|
|
411
|
+
return this.dismissOnPress(root.child(list));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
@@ -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>
|