@abhishek944/pi-tasks 0.11.1 → 0.12.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 +10 -1
- package/dist/index.js +2 -0
- package/dist/markdown.js +3 -2
- package/dist/state.d.ts +12 -1
- package/dist/state.js +91 -5
- package/dist/time.d.ts +6 -0
- package/dist/time.js +34 -0
- package/dist/timing.d.ts +4 -0
- package/dist/timing.js +47 -0
- package/dist/tools.js +11 -6
- package/dist/tracking.js +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/ui/panel.d.ts +3 -0
- package/dist/ui/panel.js +43 -17
- package/dist/ui/works-dashboard.js +11 -8
- package/docs/REFERENCE.md +14 -2
- package/docs/USAGE_GUIDE.md +16 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ It adds:
|
|
|
7
7
|
- `WorkCreate`, `WorkList`, `WorkUpdate`, and `WorkDelete`
|
|
8
8
|
- `TodoCreate`, `TodoList`, `TodoUpdate`, and `TodoDelete`
|
|
9
9
|
- `/works`, a detailed floating dashboard modeled after `pi-loop-monitor`'s `/monitors`
|
|
10
|
-
- a compact floating top-right panel with work and todo names and
|
|
10
|
+
- a compact floating top-right panel with work and todo names, completion percentages, and measured active time
|
|
11
11
|
- main-conversation guidance that keeps normal requested work current across every Pi skill and requires each delegated agent to establish its own Work and Todo IDs before assigned work
|
|
12
12
|
|
|
13
13
|
Works and todos follow the active Pi session branch. Forking or navigating the session tree restores the state for that branch. `/ask` and `/btw` conversations do not update works, todos, loops, or monitors.
|
|
@@ -31,6 +31,7 @@ The extension guides Pi to manage work automatically for normal requests that st
|
|
|
31
31
|
```text
|
|
32
32
|
WorkCreate workName="Add task tracking" workInfo="Detailed goal, scope, constraints, and expected outcome"
|
|
33
33
|
TodoCreate workId="W1" taskName="Implement state" taskInfo="Detailed task context and expected result" status="active"
|
|
34
|
+
TodoUpdate taskId="T1" working=true
|
|
34
35
|
TodoUpdate taskId="T1" completionPercent=40 taskInfo="The state changes are implemented; rendering and verification remain."
|
|
35
36
|
TodoUpdate taskId="T1" status="completed" taskInfo="Implementation is complete; typecheck and build passed."
|
|
36
37
|
WorkUpdate workId="W1" workInfo="Task tracking is implemented; state and UI checks passed."
|
|
@@ -42,6 +43,14 @@ Works are collections with no status. Tasks use four statuses: `active` (the def
|
|
|
42
43
|
|
|
43
44
|
Pi reports approximate task progress through the existing `TodoCreate`/`TodoUpdate` tools using optional `completionPercent` (an integer from 0 to 100, or `null` for unknown). Work progress is the equal average of non-cancelled tasks, rounded down—not the fraction of finished tasks. For example, task values 100, 40, 0, 0 give work progress 35%. A missing estimate makes work progress unknown (`—`); blocked tasks retain their estimate. Completed tasks are 100%; reporting 100 without completed status is rejected. For longer tasks, the guidance asks Pi to include interim estimates after roughly 5–10 meaningful working steps or a milestone, rather than waiting until completion. Estimates remain optional and must be supported by evidence; this is guidance, not an enforced schedule. These percentages are estimates, not time predictions. The floating panel keeps percentages in a reserved right-hand column so long names cannot hide them. Existing keyboard controls are unchanged.
|
|
44
45
|
|
|
46
|
+
### Active task time
|
|
47
|
+
|
|
48
|
+
The panel and `/works` reserve **Done** and **Time** columns. Select the task you are actually working on with `TodoUpdate taskId="T1" working=true`; it must be active and have `owner: self` in its details. Selecting another task pauses the previous one. Use `working=false` to pause without changing status. Select again at the beginning of each fresh run; merely creating or marking a task active never starts its timer.
|
|
49
|
+
|
|
50
|
+
The extension uses `Date.now()` to add working intervals, including thinking and foreground tools. Idle time, native retry delays between agent loops, and blocking user prompts do not count. Completion, blocking, cancellation, ownership changes, abort, and shutdown stop the timer automatically. Saved totals survive reload and branch navigation; restored tasks are paused and offline time never counts. A running time has a `▶` marker. Totals are saved on interval boundaries, not every display tick. A forced process kill can lose the current unsaved interval. Blocking prompt exclusion needs a Pi host that emits `ui_prompt_start`/`ui_prompt_end`; older hosts still pause at agent-loop boundaries.
|
|
51
|
+
|
|
52
|
+
New tasks start at `0s`; historical tasks without timing show `—` until measured, with no attempt to reconstruct earlier time. Work time sums every task's measured effort, including cancelled tasks; any unknown task makes the total unknown. It is not wall-clock duration or an estimate of remaining time. Every delegated agent times its own local tasks; the parent delegate record shows `—` because remote time is unmeasured, and makes the Work total unknown. It never treats waiting as work. Listings and copied Markdown include the same totals.
|
|
53
|
+
|
|
45
54
|
The panel and `/works` prefix work names with IDs and task names with IDs plus ownership, such as `[W1] Locate subagent restrictions` and `[T1] [self] Inspect the implement skill`. Task ownership comes from an explicit `owner: self` or `owner: delegate` declaration at the start of a line in `taskInfo`; preserve it on updates. Missing or conflicting decisions show `[unassigned]`, without rewriting stored names or old records. Inside Herdr, `AgentCreate` automatically links its task to an underlined, clickable `[delegate]` badge; Open actions are also underlined. See [delegate pane links](docs/USAGE_GUIDE.md#delegate-pane-links) for linking and keyboard access.
|
|
46
55
|
|
|
47
56
|
The panel defaults to the floating top-right layout. The compact header no longer displays the session ID. An underlined Open session action beside Copy opens this agent's artifact folder in Cursor, including existing nested delegated paths; if none exists, it creates `var/<sessionId>/`. The existing Open still opens the repository. Use `/works-panel open-session` without mouse input. Narrow headers shorten Minimize/Maximize to `[-]`/`[+]`. The `/works` dashboard title stays unchanged. Its top border centers the current repository's Git branch and staged/unstaged/untracked file counts, refreshed asynchronously with a one-second cache. Clean repositories show `clean`. In fullscreen TUI mode, its title bar has clickable Copy, Open, and Minimize/Maximize actions, and you can scroll overflowing rows directly with the mouse wheel. Open runs `cursor .` in the current session directory (the Cursor CLI must be on PATH). Open `/works` to inspect every row or copy from the keyboard. Use `/works-panel minimize`, `/works-panel maximize`, or `/works-panel open` when mouse input is unavailable. In `/works`, press `o` to open Cursor. Switch layouts with `/works-panel floating`, `/works-panel widget`, or `/works-panel off`.
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { GitStatusCache } from "./git-status.js";
|
|
|
6
6
|
import { openRepository, openSession } from "./open-repository.js";
|
|
7
7
|
import { TaskState } from "./state.js";
|
|
8
8
|
import { safeSingleLine } from "./text.js";
|
|
9
|
+
import { registerTaskTiming } from "./timing.js";
|
|
9
10
|
import { registerTaskTools } from "./tools.js";
|
|
10
11
|
import { registerTrackingGuidance } from "./tracking.js";
|
|
11
12
|
import { TasksPanelHost } from "./ui/panel.js";
|
|
@@ -15,6 +16,7 @@ export default function tasksExtension(pi) {
|
|
|
15
16
|
const git = new GitStatusCache();
|
|
16
17
|
panel = new TasksPanelHost(state, git);
|
|
17
18
|
registerTaskTools(pi, state);
|
|
19
|
+
registerTaskTiming(pi, state);
|
|
18
20
|
registerAgentTools(pi, state);
|
|
19
21
|
registerTrackingGuidance(pi);
|
|
20
22
|
registerTaskAutoContinue(pi, state);
|
package/dist/markdown.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { formatCompletion, taskCompletion, workCompletion } from "./progress.js";
|
|
2
2
|
import { safeMultiline, safeSingleLine } from "./text.js";
|
|
3
|
+
import { formatTime, taskTime, workTime } from "./time.js";
|
|
3
4
|
export function formatWorksMarkdown(works) {
|
|
4
5
|
const lines = ["# Works and Todos", ""];
|
|
5
6
|
if (works.length === 0)
|
|
6
7
|
return `${lines.join("\n")}\n_No works or todos in this session._\n`;
|
|
7
8
|
for (const work of works) {
|
|
8
|
-
lines.push(`## ${work.workId} — ${escapeMarkdownInline(safeSingleLine(work.workName))}`, "", `**Completion:** ${formatCompletion(workCompletion(work))}`, "", "### Details", "", markdownBody(work.workInfo), "", "### Todos", "");
|
|
9
|
+
lines.push(`## ${work.workId} — ${escapeMarkdownInline(safeSingleLine(work.workName))}`, "", `**Completion:** ${formatCompletion(workCompletion(work))}`, `**Time (task effort):** ${formatTime(workTime(work))}`, "", "### Details", "", markdownBody(work.workInfo), "", "### Todos", "");
|
|
9
10
|
if (work.tasks.length === 0) {
|
|
10
11
|
lines.push("_No todos._", "");
|
|
11
12
|
continue;
|
|
12
13
|
}
|
|
13
14
|
for (const todo of work.tasks) {
|
|
14
|
-
lines.push(`#### ${todo.taskId} — ${escapeMarkdownInline(safeSingleLine(todo.taskName))}`, "", `**Status:** ${todo.status}`, `**Completion:** ${formatCompletion(taskCompletion(todo))}`, "", markdownBody(todo.taskInfo), "");
|
|
15
|
+
lines.push(`#### ${todo.taskId} — ${escapeMarkdownInline(safeSingleLine(todo.taskName))}`, "", `**Status:** ${todo.status}`, `**Completion:** ${formatCompletion(taskCompletion(todo))}`, `**Time:** ${formatTime(taskTime(todo))}${todo.workingSince === undefined ? "" : " (running)"}`, "", markdownBody(todo.taskInfo), "");
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
return `${lines.join("\n").trimEnd()}\n`;
|
package/dist/state.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ export declare class TaskState {
|
|
|
10
10
|
private todos;
|
|
11
11
|
private nextWorkId;
|
|
12
12
|
private nextTaskId;
|
|
13
|
+
private focusedTaskId;
|
|
14
|
+
private workingSince;
|
|
15
|
+
private agentRunning;
|
|
13
16
|
constructor(pi: ExtensionAPI, onChange: () => void);
|
|
14
17
|
restore(ctx: ExtensionContext): void;
|
|
15
18
|
listWorks(filter?: {
|
|
@@ -22,11 +25,19 @@ export declare class TaskState {
|
|
|
22
25
|
}): Todo[];
|
|
23
26
|
getWork(workId: string): Work | undefined;
|
|
24
27
|
getTodo(taskId: string): Todo | undefined;
|
|
28
|
+
private snapshot;
|
|
29
|
+
/** Gate the selected task on actual agent execution, not task status. */
|
|
30
|
+
setAgentRunning(running: boolean): void;
|
|
31
|
+
setWorking(taskId: string, working: boolean): void;
|
|
32
|
+
clearWorking(): void;
|
|
33
|
+
private saveInterval;
|
|
25
34
|
createWork(workName: string, workInfo: string): Work;
|
|
26
35
|
updateWork(workId: string, patch: Partial<Pick<Work, "workName" | "workInfo">>): Work;
|
|
27
36
|
deleteWork(workId: string): boolean;
|
|
28
37
|
createTodo(workId: string, taskName: string, taskInfo: string, status?: TodoStatus, completionPercent?: number | null): Todo;
|
|
29
|
-
updateTodo(taskId: string, patch: Partial<Pick<Todo, "taskName" | "taskInfo" | "status" | "completionPercent">>
|
|
38
|
+
updateTodo(taskId: string, patch: Partial<Pick<Todo, "taskName" | "taskInfo" | "status" | "completionPercent">> & {
|
|
39
|
+
working?: boolean;
|
|
40
|
+
}): Todo;
|
|
30
41
|
deleteTodo(taskId: string): boolean;
|
|
31
42
|
private record;
|
|
32
43
|
private apply;
|
package/dist/state.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { taskOwner } from "./ownership.js";
|
|
1
2
|
import { taskCompletion } from "./progress.js";
|
|
2
3
|
import { safeSingleLine } from "./text.js";
|
|
3
4
|
export const TASK_ENTRY_TYPE = "pi-tasks-state";
|
|
@@ -10,11 +11,18 @@ export class TaskState {
|
|
|
10
11
|
todos = new Map();
|
|
11
12
|
nextWorkId = 1;
|
|
12
13
|
nextTaskId = 1;
|
|
14
|
+
focusedTaskId;
|
|
15
|
+
workingSince;
|
|
16
|
+
agentRunning = false;
|
|
13
17
|
constructor(pi, onChange) {
|
|
14
18
|
this.pi = pi;
|
|
15
19
|
this.onChange = onChange;
|
|
16
20
|
}
|
|
17
21
|
restore(ctx) {
|
|
22
|
+
// The branch has already changed. Never append the old interval to it.
|
|
23
|
+
this.focusedTaskId = undefined;
|
|
24
|
+
this.workingSince = undefined;
|
|
25
|
+
this.agentRunning = false;
|
|
18
26
|
this.works.clear();
|
|
19
27
|
this.todos.clear();
|
|
20
28
|
this.nextWorkId = 1;
|
|
@@ -44,7 +52,7 @@ export class TaskState {
|
|
|
44
52
|
.filter((todo) => !filter?.workId || todo.workId === filter.workId)
|
|
45
53
|
.filter((todo) => !filter?.status || todo.status === filter.status)
|
|
46
54
|
.sort((left, right) => left.createdAt - right.createdAt)
|
|
47
|
-
.map((todo) => (
|
|
55
|
+
.map((todo) => this.snapshot(todo));
|
|
48
56
|
}
|
|
49
57
|
getWork(workId) {
|
|
50
58
|
const work = this.works.get(workId);
|
|
@@ -52,7 +60,60 @@ export class TaskState {
|
|
|
52
60
|
}
|
|
53
61
|
getTodo(taskId) {
|
|
54
62
|
const todo = this.todos.get(taskId);
|
|
55
|
-
return todo ?
|
|
63
|
+
return todo ? this.snapshot(todo) : undefined;
|
|
64
|
+
}
|
|
65
|
+
snapshot(todo) {
|
|
66
|
+
return { ...todo, workingSince: todo.taskId === this.focusedTaskId ? this.workingSince : undefined };
|
|
67
|
+
}
|
|
68
|
+
/** Gate the selected task on actual agent execution, not task status. */
|
|
69
|
+
setAgentRunning(running) {
|
|
70
|
+
if (this.agentRunning === running)
|
|
71
|
+
return;
|
|
72
|
+
if (!running)
|
|
73
|
+
this.saveInterval();
|
|
74
|
+
this.agentRunning = running;
|
|
75
|
+
if (running && this.focusedTaskId)
|
|
76
|
+
this.workingSince = Date.now();
|
|
77
|
+
this.onChange();
|
|
78
|
+
}
|
|
79
|
+
setWorking(taskId, working) {
|
|
80
|
+
const todo = this.todos.get(taskId);
|
|
81
|
+
if (!todo)
|
|
82
|
+
throw new Error(`Todo ${taskId} not found.`);
|
|
83
|
+
if (!working) {
|
|
84
|
+
if (this.focusedTaskId === taskId)
|
|
85
|
+
this.clearWorking();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (todo.status !== "active" || taskOwner(todo.taskInfo) !== "self") {
|
|
89
|
+
throw new Error("working=true requires an active task with owner: self in this session.");
|
|
90
|
+
}
|
|
91
|
+
if (this.focusedTaskId === taskId)
|
|
92
|
+
return;
|
|
93
|
+
this.clearWorking();
|
|
94
|
+
if (todo.elapsedMs === undefined || todo.elapsedMs === null) {
|
|
95
|
+
this.record({ version: 1, type: "todo-time", at: Date.now(), taskId, elapsedMs: 0 });
|
|
96
|
+
}
|
|
97
|
+
this.focusedTaskId = taskId;
|
|
98
|
+
if (this.agentRunning)
|
|
99
|
+
this.workingSince = Date.now();
|
|
100
|
+
this.onChange();
|
|
101
|
+
}
|
|
102
|
+
clearWorking() {
|
|
103
|
+
this.saveInterval();
|
|
104
|
+
this.focusedTaskId = undefined;
|
|
105
|
+
this.onChange();
|
|
106
|
+
}
|
|
107
|
+
saveInterval() {
|
|
108
|
+
if (!this.focusedTaskId || this.workingSince === undefined)
|
|
109
|
+
return;
|
|
110
|
+
const todo = this.todos.get(this.focusedTaskId);
|
|
111
|
+
const now = Date.now();
|
|
112
|
+
if (todo) {
|
|
113
|
+
this.record({ version: 1, type: "todo-time", at: now, taskId: todo.taskId,
|
|
114
|
+
elapsedMs: (todo.elapsedMs ?? 0) + Math.max(0, now - this.workingSince) });
|
|
115
|
+
}
|
|
116
|
+
this.workingSince = undefined;
|
|
56
117
|
}
|
|
57
118
|
createWork(workName, workInfo) {
|
|
58
119
|
if (this.works.size >= MAX_WORKS)
|
|
@@ -83,6 +144,8 @@ export class TaskState {
|
|
|
83
144
|
deleteWork(workId) {
|
|
84
145
|
if (!this.works.has(workId))
|
|
85
146
|
return false;
|
|
147
|
+
if (this.focusedTaskId && this.todos.get(this.focusedTaskId)?.workId === workId)
|
|
148
|
+
this.clearWorking();
|
|
86
149
|
this.record({ version: 1, type: "work-deleted", at: Date.now(), workId });
|
|
87
150
|
return true;
|
|
88
151
|
}
|
|
@@ -100,6 +163,7 @@ export class TaskState {
|
|
|
100
163
|
taskInfo: requiredText(taskInfo, "taskInfo"),
|
|
101
164
|
status,
|
|
102
165
|
completionPercent: status === "completed" ? 100 : completionPercent ?? null,
|
|
166
|
+
elapsedMs: 0,
|
|
103
167
|
createdAt: now,
|
|
104
168
|
updatedAt: now,
|
|
105
169
|
};
|
|
@@ -117,14 +181,25 @@ export class TaskState {
|
|
|
117
181
|
status: patch.status,
|
|
118
182
|
completionPercent: patch.completionPercent,
|
|
119
183
|
});
|
|
120
|
-
if (Object.keys(normalized).length === 0)
|
|
184
|
+
if (Object.keys(normalized).length === 0 && patch.working === undefined)
|
|
121
185
|
throw new Error("TodoUpdate requires at least one changed field.");
|
|
122
|
-
|
|
186
|
+
const effective = { ...current, ...normalized };
|
|
187
|
+
const canWork = effective.status === "active" && taskOwner(effective.taskInfo) === "self";
|
|
188
|
+
if (patch.working === true && !canWork)
|
|
189
|
+
throw new Error("working=true requires an active task with owner: self in this session.");
|
|
190
|
+
if (this.focusedTaskId === taskId && (!canWork || patch.working === false))
|
|
191
|
+
this.clearWorking();
|
|
192
|
+
if (Object.keys(normalized).length > 0)
|
|
193
|
+
this.record({ version: 1, type: "todo-updated", at: Date.now(), taskId, patch: normalized });
|
|
194
|
+
if (patch.working !== undefined)
|
|
195
|
+
this.setWorking(taskId, patch.working);
|
|
123
196
|
return this.getTodo(taskId);
|
|
124
197
|
}
|
|
125
198
|
deleteTodo(taskId) {
|
|
126
199
|
if (!this.todos.has(taskId))
|
|
127
200
|
return false;
|
|
201
|
+
if (this.focusedTaskId === taskId)
|
|
202
|
+
this.clearWorking();
|
|
128
203
|
this.record({ version: 1, type: "todo-deleted", at: Date.now(), taskId });
|
|
129
204
|
return true;
|
|
130
205
|
}
|
|
@@ -178,6 +253,8 @@ export class TaskState {
|
|
|
178
253
|
status,
|
|
179
254
|
taskName: safeSingleLine(event.todo.taskName),
|
|
180
255
|
completionPercent: taskCompletion(event.todo),
|
|
256
|
+
elapsedMs: validElapsed(event.todo.elapsedMs) ? event.todo.elapsedMs : null,
|
|
257
|
+
workingSince: undefined,
|
|
181
258
|
});
|
|
182
259
|
this.nextTaskId = Math.max(this.nextTaskId, numericId(event.todo.taskId) + 1);
|
|
183
260
|
break;
|
|
@@ -198,12 +275,21 @@ export class TaskState {
|
|
|
198
275
|
}
|
|
199
276
|
break;
|
|
200
277
|
}
|
|
278
|
+
case "todo-time": {
|
|
279
|
+
const todo = this.todos.get(event.taskId);
|
|
280
|
+
if (todo && validElapsed(event.elapsedMs))
|
|
281
|
+
this.todos.set(event.taskId, { ...todo, elapsedMs: event.elapsedMs });
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
201
284
|
case "todo-deleted":
|
|
202
285
|
this.todos.delete(event.taskId);
|
|
203
286
|
break;
|
|
204
287
|
}
|
|
205
288
|
}
|
|
206
289
|
}
|
|
290
|
+
function validElapsed(value) {
|
|
291
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
292
|
+
}
|
|
207
293
|
function validateCompletion(status, value) {
|
|
208
294
|
if (value === undefined || value === null)
|
|
209
295
|
return;
|
|
@@ -252,7 +338,7 @@ function parseEvent(value) {
|
|
|
252
338
|
const candidate = value;
|
|
253
339
|
if (candidate.version !== 1 || typeof candidate.type !== "string")
|
|
254
340
|
return undefined;
|
|
255
|
-
if (!["work-created", "work-updated", "work-deleted", "todo-created", "todo-updated", "todo-deleted"].includes(candidate.type))
|
|
341
|
+
if (!["work-created", "work-updated", "work-deleted", "todo-created", "todo-updated", "todo-deleted", "todo-time"].includes(candidate.type))
|
|
256
342
|
return undefined;
|
|
257
343
|
return value;
|
|
258
344
|
}
|
package/dist/time.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Todo, WorkWithTodos } from "./types.js";
|
|
2
|
+
/** Measured task effort, not time since task creation. */
|
|
3
|
+
export declare function taskTime(todo: Todo, now?: number): number | null;
|
|
4
|
+
/** Cancelled tasks still consumed effort. Unknown historical time stays unknown. */
|
|
5
|
+
export declare function workTime(work: WorkWithTodos, now?: number): number | null;
|
|
6
|
+
export declare function formatTime(elapsedMs: number | null): string;
|
package/dist/time.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { taskOwner } from "./ownership.js";
|
|
2
|
+
/** Measured task effort, not time since task creation. */
|
|
3
|
+
export function taskTime(todo, now = Date.now()) {
|
|
4
|
+
// Parent delegate records have no remote timing source. Keep local intervals
|
|
5
|
+
// stored, but never present a local subtotal as the full delegated effort.
|
|
6
|
+
if (taskOwner(todo.taskInfo) === "delegate" || todo.elapsedMs === undefined || todo.elapsedMs === null)
|
|
7
|
+
return null;
|
|
8
|
+
return todo.elapsedMs + (todo.workingSince === undefined ? 0 : Math.max(0, now - todo.workingSince));
|
|
9
|
+
}
|
|
10
|
+
/** Cancelled tasks still consumed effort. Unknown historical time stays unknown. */
|
|
11
|
+
export function workTime(work, now = Date.now()) {
|
|
12
|
+
let total = 0;
|
|
13
|
+
for (const todo of work.tasks) {
|
|
14
|
+
const elapsed = taskTime(todo, now);
|
|
15
|
+
if (elapsed === null)
|
|
16
|
+
return null;
|
|
17
|
+
total += elapsed;
|
|
18
|
+
}
|
|
19
|
+
return work.tasks.length ? total : null;
|
|
20
|
+
}
|
|
21
|
+
export function formatTime(elapsedMs) {
|
|
22
|
+
if (elapsedMs === null)
|
|
23
|
+
return "—";
|
|
24
|
+
const seconds = Math.floor(elapsedMs / 1_000);
|
|
25
|
+
if (seconds < 60)
|
|
26
|
+
return `${seconds}s`;
|
|
27
|
+
const minutes = Math.floor(seconds / 60);
|
|
28
|
+
if (minutes < 60)
|
|
29
|
+
return `${minutes}m ${String(seconds % 60).padStart(2, "0")}s`;
|
|
30
|
+
const hours = Math.floor(minutes / 60);
|
|
31
|
+
if (hours < 1_000)
|
|
32
|
+
return `${hours}h ${String(minutes % 60).padStart(2, "0")}m`;
|
|
33
|
+
return `${Math.floor(hours / 24)}d`;
|
|
34
|
+
}
|
package/dist/timing.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { TaskState } from "./state.js";
|
|
3
|
+
/** Runtime activity gates timing; task status never implies execution. */
|
|
4
|
+
export declare function registerTaskTiming(pi: ExtensionAPI, state: TaskState): void;
|
package/dist/timing.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { areTrackingToolsActive } from "./tracking.js";
|
|
2
|
+
/** Runtime activity gates timing; task status never implies execution. */
|
|
3
|
+
export function registerTaskTiming(pi, state) {
|
|
4
|
+
let running = false;
|
|
5
|
+
let prompts = 0;
|
|
6
|
+
let detachAbort;
|
|
7
|
+
const sync = () => state.setAgentRunning(running && prompts === 0 && areTrackingToolsActive(pi));
|
|
8
|
+
const pause = () => {
|
|
9
|
+
running = false;
|
|
10
|
+
detachAbort?.();
|
|
11
|
+
detachAbort = undefined;
|
|
12
|
+
sync();
|
|
13
|
+
};
|
|
14
|
+
const reset = () => {
|
|
15
|
+
pause();
|
|
16
|
+
prompts = 0;
|
|
17
|
+
state.clearWorking();
|
|
18
|
+
};
|
|
19
|
+
// A fresh prompt must explicitly select its task instead of inheriting focus.
|
|
20
|
+
pi.on("before_agent_start", () => { reset(); });
|
|
21
|
+
pi.on("agent_start", (_event, ctx) => {
|
|
22
|
+
running = true;
|
|
23
|
+
const signal = ctx.signal;
|
|
24
|
+
if (signal?.aborted) {
|
|
25
|
+
reset();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (signal) {
|
|
29
|
+
signal.addEventListener("abort", reset, { once: true });
|
|
30
|
+
detachAbort = () => signal.removeEventListener("abort", reset);
|
|
31
|
+
}
|
|
32
|
+
sync();
|
|
33
|
+
});
|
|
34
|
+
// Close every loop interval, including older hosts without agent_settled.
|
|
35
|
+
// Native automatic continuation may resume the focus on its next agent_start.
|
|
36
|
+
pi.on("agent_end", pause);
|
|
37
|
+
pi.on("agent_settled", reset);
|
|
38
|
+
pi.on("ui_prompt_start", () => { prompts += 1; sync(); });
|
|
39
|
+
pi.on("ui_prompt_end", () => { prompts = Math.max(0, prompts - 1); sync(); });
|
|
40
|
+
pi.on("session_before_switch", reset);
|
|
41
|
+
pi.on("session_before_fork", reset);
|
|
42
|
+
pi.on("session_before_tree", reset);
|
|
43
|
+
pi.on("session_shutdown", reset);
|
|
44
|
+
// restore() discards runtime state; these only reset the lifecycle gate.
|
|
45
|
+
pi.on("session_start", reset);
|
|
46
|
+
pi.on("session_tree", reset);
|
|
47
|
+
}
|
package/dist/tools.js
CHANGED
|
@@ -3,7 +3,9 @@ import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead } from "
|
|
|
3
3
|
import { Type } from "typebox";
|
|
4
4
|
import { preservePaneLink } from "./agents/links.js";
|
|
5
5
|
import { formatCompletion, taskCompletion, workCompletion } from "./progress.js";
|
|
6
|
+
import { formatTime, taskTime, workTime } from "./time.js";
|
|
6
7
|
import { renderTaskCall, renderTaskResult, taskResult } from "./tool-result.js";
|
|
8
|
+
import { areTrackingToolsActive } from "./tracking.js";
|
|
7
9
|
const StatusSchema = StringEnum(["active", "blocked", "completed", "cancelled"]);
|
|
8
10
|
const STATUS_GUIDANCE = "New tasks default to active. Use blocked immediately when the next step must wait for agent output, review, an external response, user input, permission, or another obstacle. Record the dependency and resume condition in taskInfo and retain progress. Return blocked tasks to active when the dependency resolves and work resumes. Works are collections and have no status.";
|
|
9
11
|
const CompletionSchema = Type.Union([Type.Integer({ minimum: 0, maximum: 100 }), Type.Null()], {
|
|
@@ -131,20 +133,23 @@ export function registerTaskTools(pi, state) {
|
|
|
131
133
|
pi.registerTool({
|
|
132
134
|
name: "TodoUpdate",
|
|
133
135
|
label: "TodoUpdate",
|
|
134
|
-
description: `Update a todo's name, detailed information, status, or
|
|
136
|
+
description: `Update a todo's name, detailed information, status, completionPercent, or working selection. Set working=true immediately before working on an active owner: self task; it pauses any previously selected task. Set working=false to pause without changing status. Timing is calculated automatically, never estimated. Re-select with working=true on each fresh run. Delegated agents time their own local tasks; never select a parent delegate task. For longer tasks, include an optional completionPercent estimate after roughly 5–10 meaningful working steps or a milestone, not just at completion or in status-only updates. Explain evidence and remaining work in taskInfo; use null when unknown and never increase a percentage without evidence. Blocking retains progress. Reserve completed/100 for verified completion. ${STATUS_GUIDANCE} ${DETAILS_GUIDANCE}`,
|
|
135
137
|
promptSnippet: "Keep todo status and detailed context synchronized with active work",
|
|
136
|
-
promptGuidelines: ["Use TodoUpdate immediately before
|
|
138
|
+
promptGuidelines: ["Use TodoUpdate with working=true immediately before working on an active owner: self task, including when resuming on a fresh run. Use working=false when pausing without a status change. Only one local task is timed; runtime idle and user waits pause automatically. Never update tracking during /ask or /btw.", "During longer tasks, include an evidence-based completionPercent estimate after roughly 5–10 meaningful working steps or a milestone; do not wait until completion or only update status. Estimates remain optional: use null when unknown, and leave a percentage unchanged if there is no new evidence. Explain evidence and remaining work in taskInfo; only verified completed tasks may reach 100. Work completion is calculated automatically from tasks.", DETAILS_GUIDANCE],
|
|
137
139
|
parameters: Type.Object({
|
|
138
140
|
taskId: Type.String(),
|
|
139
141
|
taskName: Type.Optional(NameSchema),
|
|
140
142
|
taskInfo: Type.Optional(InfoSchema),
|
|
141
143
|
status: Type.Optional(StatusSchema),
|
|
142
144
|
completionPercent: Type.Optional(CompletionSchema),
|
|
145
|
+
working: Type.Optional(Type.Boolean({ description: "Select this active owner: self task for automatic timing, or pause it. Selection switches away from the previously timed task. No timestamps or duration estimates are accepted." })),
|
|
143
146
|
}, { additionalProperties: false, minProperties: 2 }),
|
|
144
147
|
execute(_id, params) {
|
|
148
|
+
if (params.working !== undefined && !areTrackingToolsActive(pi))
|
|
149
|
+
throw new Error("Task timing is available only in tracked main-conversation work, not /ask or /btw.");
|
|
145
150
|
const taskInfo = params.taskInfo === undefined ? undefined : preservePaneLink(state.getTodo(params.taskId)?.taskInfo ?? "", params.taskInfo);
|
|
146
|
-
const todo = state.updateTodo(params.taskId, { taskName: params.taskName, taskInfo, status: params.status, completionPercent: params.completionPercent });
|
|
147
|
-
return Promise.resolve(taskResult(`Updated todo ${todo.taskId}: ${todo.taskName} · ${formatCompletion(taskCompletion(todo))} [${todo.status}]`, "todo-update", { taskId: todo.taskId, workId: todo.workId, completionPercent: taskCompletion(todo) }));
|
|
151
|
+
const todo = state.updateTodo(params.taskId, { taskName: params.taskName, taskInfo, status: params.status, completionPercent: params.completionPercent, working: params.working });
|
|
152
|
+
return Promise.resolve(taskResult(`Updated todo ${todo.taskId}: ${todo.taskName} · ${formatCompletion(taskCompletion(todo))} · ${formatTime(taskTime(todo))}${todo.workingSince === undefined ? "" : " running"} [${todo.status}]`, "todo-update", { taskId: todo.taskId, workId: todo.workId, completionPercent: taskCompletion(todo), elapsedMs: taskTime(todo), working: todo.workingSince !== undefined }));
|
|
148
153
|
},
|
|
149
154
|
renderCall: renderTaskCall("TodoUpdate"),
|
|
150
155
|
renderResult: renderTaskResult,
|
|
@@ -169,7 +174,7 @@ function formatWorks(works) {
|
|
|
169
174
|
if (works.length === 0)
|
|
170
175
|
return "No works found in this session.";
|
|
171
176
|
return works.map((work) => [
|
|
172
|
-
`${work.workId} ${work.workName} · ${formatCompletion(workCompletion(work))}`,
|
|
177
|
+
`${work.workId} ${work.workName} · ${formatCompletion(workCompletion(work))} · Time: ${formatTime(workTime(work))}`,
|
|
173
178
|
`Work info:\n${work.workInfo}`,
|
|
174
179
|
work.tasks.length ? `Todos:\n${formatTodos(work.tasks)}` : "Todos: none",
|
|
175
180
|
].join("\n")).join("\n\n---\n\n");
|
|
@@ -177,7 +182,7 @@ function formatWorks(works) {
|
|
|
177
182
|
function formatTodos(todos) {
|
|
178
183
|
if (todos.length === 0)
|
|
179
184
|
return "No todos found.";
|
|
180
|
-
return todos.map((todo) => `${todo.taskId} [${todo.status}] ${todo.taskName} · ${formatCompletion(taskCompletion(todo))}\nWork: ${todo.workId}\nTask info:\n${todo.taskInfo}`).join("\n\n");
|
|
185
|
+
return todos.map((todo) => `${todo.taskId} [${todo.status}] ${todo.taskName} · ${formatCompletion(taskCompletion(todo))} · Time: ${formatTime(taskTime(todo))}${todo.workingSince === undefined ? "" : " (running)"}\nWork: ${todo.workId}\nTask info:\n${todo.taskInfo}`).join("\n\n");
|
|
181
186
|
}
|
|
182
187
|
function bounded(text) {
|
|
183
188
|
const result = truncateHead(text, { maxBytes: DEFAULT_MAX_BYTES, maxLines: DEFAULT_MAX_LINES });
|
package/dist/tracking.js
CHANGED
|
@@ -20,7 +20,7 @@ Before implementation, investigation, or any other requested work:
|
|
|
20
20
|
1. Use WorkList and TodoList to find the relevant existing records and avoid duplicates.
|
|
21
21
|
2. If no suitable work exists, create one with WorkCreate. Otherwise use WorkUpdate when its scope or shared context needs refreshing.
|
|
22
22
|
3. Create or update the work's todos so they match the requested scope. Works have no status. New todos default to active; task statuses are active, blocked, completed, and cancelled. Keep taskInfo detailed and self-contained.
|
|
23
|
-
4. Mark the todo being attempted active with TodoUpdate before doing that work.
|
|
23
|
+
4. Mark the todo being attempted active with TodoUpdate before doing that work. For an owner: self task, include working=true to select it for automatic time measurement on every fresh run. Only one local task can be timed; selecting another pauses the previous one. Use working=false when pausing without changing status. Idle, blocking user prompts, and terminal statuses pause automatically. Delegated agents time their own local tasks; a parent delegate record is not a running local task. Never estimate or submit durations.
|
|
24
24
|
5. completionPercent on TodoCreate/TodoUpdate is optional. When estimating, use an approximate integer from 0 to 100 based on actual work and verification, not elapsed time or a fixed mapping from status. Use 0 for genuinely unstarted tasks and null when unknown. Never invent progress to make a work look further along.
|
|
25
25
|
|
|
26
26
|
During and after the attempt:
|
package/dist/types.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ export interface Todo {
|
|
|
13
13
|
taskInfo: string;
|
|
14
14
|
status: TodoStatus;
|
|
15
15
|
completionPercent?: number | null;
|
|
16
|
+
/** Accumulated measured time; missing/null means historical time is unknown. */
|
|
17
|
+
elapsedMs?: number | null;
|
|
18
|
+
/** Current interval start, exposed only in live snapshots, never restored. */
|
|
19
|
+
workingSince?: number;
|
|
16
20
|
createdAt: number;
|
|
17
21
|
updatedAt: number;
|
|
18
22
|
}
|
|
@@ -46,6 +50,12 @@ export type TaskEvent = {
|
|
|
46
50
|
at: number;
|
|
47
51
|
taskId: string;
|
|
48
52
|
patch: Partial<Pick<Todo, "taskName" | "taskInfo" | "status" | "completionPercent">>;
|
|
53
|
+
} | {
|
|
54
|
+
version: 1;
|
|
55
|
+
type: "todo-time";
|
|
56
|
+
at: number;
|
|
57
|
+
taskId: string;
|
|
58
|
+
elapsedMs: number;
|
|
49
59
|
} | {
|
|
50
60
|
version: 1;
|
|
51
61
|
type: "todo-deleted";
|
package/dist/ui/panel.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { GitSnapshot, GitStatusCache } from "../git-status.js";
|
|
|
4
4
|
import type { TaskState } from "../state.js";
|
|
5
5
|
import type { TodoStatus } from "../types.js";
|
|
6
6
|
export type TasksPanelMode = "floating" | "widget" | "off";
|
|
7
|
+
export declare function metricsContentWidth(width: number): number;
|
|
7
8
|
export declare class TasksPanelHost {
|
|
8
9
|
private readonly state;
|
|
9
10
|
private readonly git;
|
|
@@ -35,6 +36,8 @@ export type DelegateHitRegion = {
|
|
|
35
36
|
};
|
|
36
37
|
export declare function delegateHitRegion(link: DelegateLink | undefined, start: number, line: string, y: number, leftPad?: number): DelegateHitRegion | undefined;
|
|
37
38
|
export declare function progressName(name: string, completion: number | null, width: number, prefix?: string): string;
|
|
39
|
+
export declare function metricsColumn(content: string, completion: number | null, elapsed: number | null, running: boolean, width: number, theme: Theme): string;
|
|
40
|
+
export declare function metricsHeader(width: number, theme: Theme): string;
|
|
38
41
|
export declare function todoIcon(status: TodoStatus, theme: Theme): string;
|
|
39
42
|
export declare function frame(content: string, innerWidth: number, theme: Theme): string;
|
|
40
43
|
export declare function rule(innerWidth: number, theme: Theme): string;
|
package/dist/ui/panel.js
CHANGED
|
@@ -7,9 +7,14 @@ import { openRepository, openSession } from "../open-repository.js";
|
|
|
7
7
|
import { taskOwner } from "../ownership.js";
|
|
8
8
|
import { formatCompletion, taskCompletion, workCompletion } from "../progress.js";
|
|
9
9
|
import { safeSingleLine } from "../text.js";
|
|
10
|
+
import { formatTime, taskTime, workTime } from "../time.js";
|
|
10
11
|
const EMPTY_COMPONENT = { render: () => [], invalidate: () => { } };
|
|
11
12
|
const PROGRESS_VALUE_WIDTH = 4;
|
|
12
|
-
const
|
|
13
|
+
const TIME_VALUE_WIDTH = 8;
|
|
14
|
+
const METRICS_COLUMN_WIDTH = PROGRESS_VALUE_WIDTH + TIME_VALUE_WIDTH + 6;
|
|
15
|
+
export function metricsContentWidth(width) {
|
|
16
|
+
return Math.max(0, width - METRICS_COLUMN_WIDTH);
|
|
17
|
+
}
|
|
13
18
|
export class TasksPanelHost {
|
|
14
19
|
state;
|
|
15
20
|
git;
|
|
@@ -79,7 +84,7 @@ export class TasksPanelHost {
|
|
|
79
84
|
this.handle = tui.showOverlay(this.panel, {
|
|
80
85
|
anchor: "top-right",
|
|
81
86
|
width: "42%",
|
|
82
|
-
minWidth:
|
|
87
|
+
minWidth: 48,
|
|
83
88
|
maxHeight: "48%",
|
|
84
89
|
margin: { top: 1, right: 1 },
|
|
85
90
|
nonCapturing: true,
|
|
@@ -123,6 +128,7 @@ class TasksPanel {
|
|
|
123
128
|
delegateHits = [];
|
|
124
129
|
disposed = false;
|
|
125
130
|
unsubscribeGit;
|
|
131
|
+
refreshTimer;
|
|
126
132
|
copyHitRegion;
|
|
127
133
|
openHitRegion;
|
|
128
134
|
sessionHitRegion;
|
|
@@ -142,11 +148,11 @@ class TasksPanel {
|
|
|
142
148
|
render(width) {
|
|
143
149
|
this.delegateHits = [];
|
|
144
150
|
if (this.placement === "widget")
|
|
145
|
-
this.setVisible(width >=
|
|
146
|
-
if (width <
|
|
151
|
+
this.setVisible(width >= 48);
|
|
152
|
+
if (width < 48)
|
|
147
153
|
return [];
|
|
148
154
|
const works = this.state.listWorks();
|
|
149
|
-
const boxWidth = this.placement === "floating" ? width : Math.min(54, Math.max(
|
|
155
|
+
const boxWidth = this.placement === "floating" ? width : Math.min(54, Math.max(48, Math.floor(width * 0.44)));
|
|
150
156
|
const innerWidth = boxWidth - 2;
|
|
151
157
|
const leftPad = this.placement === "widget" ? " ".repeat(Math.max(0, width - boxWidth)) : "";
|
|
152
158
|
if (this.minimized) {
|
|
@@ -157,26 +163,26 @@ class TasksPanel {
|
|
|
157
163
|
border(innerWidth, "bottom", this.theme),
|
|
158
164
|
].map((line) => `${leftPad}${line}`);
|
|
159
165
|
}
|
|
160
|
-
const contentWidth = innerWidth
|
|
166
|
+
const contentWidth = metricsContentWidth(innerWidth);
|
|
161
167
|
const content = [];
|
|
162
168
|
const delegateRows = new Map();
|
|
163
169
|
if (works.length === 0)
|
|
164
|
-
content.push(
|
|
170
|
+
content.push(metricsColumn(this.theme.fg("muted", "No works yet."), null, null, false, innerWidth, this.theme));
|
|
165
171
|
for (const work of works) {
|
|
166
172
|
const completed = work.tasks.filter((todo) => todo.status === "completed").length;
|
|
167
173
|
const summary = workSummaryLine(work.workName, `${completed}/${work.tasks.length}`, contentWidth, this.theme, work.workId);
|
|
168
|
-
content.push(
|
|
174
|
+
content.push(metricsColumn(summary, workCompletion(work), workTime(work), work.tasks.some((todo) => todo.workingSince !== undefined), innerWidth, this.theme));
|
|
169
175
|
for (const todo of work.tasks) {
|
|
170
176
|
const agent = delegateLink(todo.taskInfo);
|
|
171
177
|
const lead = ` ${todoIcon(todo.status, this.theme)} ${recordId(todo.taskId, this.theme)} `;
|
|
172
178
|
const label = `${lead}${ownerBadge(todo.taskInfo, this.theme, Boolean(agent))} ${this.theme.fg(todo.status === "completed" ? "muted" : "text", safeSingleLine(todo.taskName))}`;
|
|
173
179
|
delegateRows.set(content.length, { agent, start: visibleWidth(lead) });
|
|
174
|
-
content.push(
|
|
180
|
+
content.push(metricsColumn(label, taskCompletion(todo), taskTime(todo), todo.workingSince !== undefined, innerWidth, this.theme));
|
|
175
181
|
}
|
|
176
182
|
}
|
|
177
183
|
this.contentLength = content.length;
|
|
178
184
|
const terminalRows = this.tui.terminal.rows || process.stdout.rows || 30;
|
|
179
|
-
this.pageSize = this.placement === "widget" ? Math.max(1, content.length) : Math.max(1, Math.floor(terminalRows * 0.48) -
|
|
185
|
+
this.pageSize = this.placement === "widget" ? Math.max(1, content.length) : Math.max(1, Math.floor(terminalRows * 0.48) - 5);
|
|
180
186
|
if (this.placement === "widget") {
|
|
181
187
|
this.scrollOffset = 0;
|
|
182
188
|
this.followTail = true;
|
|
@@ -192,7 +198,7 @@ class TasksPanel {
|
|
|
192
198
|
const row = delegateRows.get(this.scrollOffset + index);
|
|
193
199
|
if (!row)
|
|
194
200
|
return;
|
|
195
|
-
const hit = delegateHitRegion(row.agent, row.start, line,
|
|
201
|
+
const hit = delegateHitRegion(row.agent, row.start, line, 4 + index, leftPad.length);
|
|
196
202
|
if (hit)
|
|
197
203
|
this.delegateHits.push(hit);
|
|
198
204
|
});
|
|
@@ -205,9 +211,10 @@ class TasksPanel {
|
|
|
205
211
|
const lines = [
|
|
206
212
|
gitBorder(innerWidth, this.theme, this.git.getSnapshot()),
|
|
207
213
|
frame(header, innerWidth, this.theme),
|
|
208
|
-
|
|
214
|
+
metricsRule(innerWidth, "middle", this.theme),
|
|
215
|
+
frame(metricsHeader(innerWidth, this.theme), innerWidth, this.theme),
|
|
209
216
|
...shown.map((line) => frame(line, innerWidth, this.theme)),
|
|
210
|
-
|
|
217
|
+
metricsRule(innerWidth, "bottom", this.theme),
|
|
211
218
|
];
|
|
212
219
|
return lines.map((line) => `${leftPad}${line}`);
|
|
213
220
|
}
|
|
@@ -265,10 +272,17 @@ class TasksPanel {
|
|
|
265
272
|
return;
|
|
266
273
|
if (visible) {
|
|
267
274
|
this.unsubscribeGit ??= this.git.subscribe(() => this.tui.requestRender());
|
|
275
|
+
this.refreshTimer ??= setInterval(() => {
|
|
276
|
+
if (!this.minimized && this.state.listTodos().some((todo) => todo.workingSince !== undefined))
|
|
277
|
+
this.tui.requestRender();
|
|
278
|
+
}, 1_000);
|
|
279
|
+
this.refreshTimer.unref?.();
|
|
268
280
|
}
|
|
269
281
|
else {
|
|
270
282
|
this.unsubscribeGit?.();
|
|
271
283
|
this.unsubscribeGit = undefined;
|
|
284
|
+
clearInterval(this.refreshTimer);
|
|
285
|
+
this.refreshTimer = undefined;
|
|
272
286
|
}
|
|
273
287
|
}
|
|
274
288
|
setMinimized(minimized) {
|
|
@@ -406,12 +420,24 @@ export function progressName(name, completion, width, prefix = "") {
|
|
|
406
420
|
const suffix = ` · ${formatCompletion(completion)}`;
|
|
407
421
|
return `${truncateToWidth(`${prefix}${safeSingleLine(name)}`, Math.max(0, width - visibleWidth(suffix)), "…")}${suffix}`;
|
|
408
422
|
}
|
|
409
|
-
function
|
|
410
|
-
const
|
|
423
|
+
export function metricsColumn(content, completion, elapsed, running, width, theme) {
|
|
424
|
+
const value = theme.fg(completion === null ? "muted" : "accent", formatCompletion(completion).padStart(PROGRESS_VALUE_WIDTH));
|
|
425
|
+
const time = truncateToWidth(`${running ? "▶" : ""}${formatTime(elapsed)}`, TIME_VALUE_WIDTH, "…");
|
|
426
|
+
return metricsRow(content, value, theme.fg(running ? "accent" : elapsed === null ? "muted" : "dim", time.padStart(TIME_VALUE_WIDTH)), width, theme);
|
|
427
|
+
}
|
|
428
|
+
export function metricsHeader(width, theme) {
|
|
429
|
+
return metricsRow(theme.fg("dim", "Task / Work"), theme.fg("dim", "Done"), theme.fg("dim", "Time".padStart(TIME_VALUE_WIDTH)), width, theme);
|
|
430
|
+
}
|
|
431
|
+
function metricsRow(content, completion, time, width, theme) {
|
|
432
|
+
const contentWidth = metricsContentWidth(width);
|
|
411
433
|
const left = truncateToWidth(content, contentWidth, "…");
|
|
412
434
|
const padding = " ".repeat(Math.max(0, contentWidth - visibleWidth(left)));
|
|
413
|
-
const
|
|
414
|
-
return `${left}${padding}${
|
|
435
|
+
const separator = theme.fg("border", " │ ");
|
|
436
|
+
return truncateToWidth(`${left}${padding}${separator}${completion}${separator}${time}`, width, "");
|
|
437
|
+
}
|
|
438
|
+
function metricsRule(width, edge, theme) {
|
|
439
|
+
const contentWidth = metricsContentWidth(width);
|
|
440
|
+
return theme.fg("border", `${edge === "middle" ? "├" : "└"}${"─".repeat(contentWidth + 1)}${edge === "middle" ? "┬" : "┴"}${"─".repeat(PROGRESS_VALUE_WIDTH + 2)}${edge === "middle" ? "┬" : "┴"}${"─".repeat(TIME_VALUE_WIDTH + 1)}${edge === "middle" ? "┤" : "┘"}`);
|
|
415
441
|
}
|
|
416
442
|
function workSummaryLine(name, count, width, theme, workId) {
|
|
417
443
|
const right = theme.fg("dim", count);
|
|
@@ -5,8 +5,9 @@ import { formatWorksMarkdown } from "../markdown.js";
|
|
|
5
5
|
import { openRepository } from "../open-repository.js";
|
|
6
6
|
import { formatCompletion, taskCompletion, workCompletion } from "../progress.js";
|
|
7
7
|
import { safeMultiline, safeSingleLine } from "../text.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import { formatTime, taskTime, workTime } from "../time.js";
|
|
9
|
+
import { border, delegateHitRegion, frame, gitBorder, metricsColumn, metricsHeader, ownerBadge, progressName, recordId, rule, todoIcon } from "./panel.js";
|
|
10
|
+
const CHROME_LINES = 9;
|
|
10
11
|
export class WorksDashboard {
|
|
11
12
|
tui;
|
|
12
13
|
theme;
|
|
@@ -78,13 +79,13 @@ export class WorksDashboard {
|
|
|
78
79
|
const listHeight = Math.max(0, bodyHeight - details.length);
|
|
79
80
|
if (listHeight > 0)
|
|
80
81
|
this.keepSelectionVisible(items, listHeight);
|
|
81
|
-
const rows = items.slice(this.scrollOffset, this.scrollOffset + listHeight).map((item, index) => this.renderRow(item, innerWidth,
|
|
82
|
+
const rows = items.slice(this.scrollOffset, this.scrollOffset + listHeight).map((item, index) => this.renderRow(item, innerWidth, 5 + index));
|
|
82
83
|
while (rows.length < listHeight)
|
|
83
84
|
rows.push("");
|
|
84
85
|
const selected = items.find((item) => item.key === this.selectedKey);
|
|
85
86
|
if (selected?.kind === "todo" && details[1] !== undefined) {
|
|
86
87
|
const start = visibleWidth(`${recordId(selected.todo.taskId, this.theme)} `);
|
|
87
|
-
const hit = delegateHitRegion(delegateLink(selected.todo.taskInfo), start, details[1],
|
|
88
|
+
const hit = delegateHitRegion(delegateLink(selected.todo.taskInfo), start, details[1], 6 + listHeight);
|
|
88
89
|
if (hit)
|
|
89
90
|
this.delegateHits.push(hit);
|
|
90
91
|
}
|
|
@@ -93,6 +94,7 @@ export class WorksDashboard {
|
|
|
93
94
|
frame(header, innerWidth, this.theme),
|
|
94
95
|
frame(this.theme.fg("dim", summary), innerWidth, this.theme),
|
|
95
96
|
rule(innerWidth, this.theme),
|
|
97
|
+
frame(metricsHeader(innerWidth, this.theme), innerWidth, this.theme),
|
|
96
98
|
...[...rows, ...details].map((line) => frame(line, innerWidth, this.theme)),
|
|
97
99
|
rule(innerWidth, this.theme),
|
|
98
100
|
frame(this.theme.fg(this.messageColor, truncateToWidth(this.message, innerWidth, "")), innerWidth, this.theme),
|
|
@@ -235,12 +237,12 @@ export class WorksDashboard {
|
|
|
235
237
|
if (item.kind === "work") {
|
|
236
238
|
const done = item.work.tasks.filter((todo) => todo.status === "completed").length;
|
|
237
239
|
const metadata = this.theme.fg("dim", `${done}/${item.work.tasks.length} completed`);
|
|
238
|
-
const
|
|
239
|
-
return
|
|
240
|
+
const label = `${prefix}${this.theme.bold(`${recordId(item.work.workId, this.theme)} ${safeSingleLine(item.work.workName)}`)} ${metadata}`;
|
|
241
|
+
return metricsColumn(label, workCompletion(item.work), workTime(item.work), item.work.tasks.some((todo) => todo.workingSince !== undefined), width, this.theme);
|
|
240
242
|
}
|
|
241
243
|
const metadata = this.theme.fg("dim", item.todo.status);
|
|
242
|
-
const
|
|
243
|
-
const line =
|
|
244
|
+
const label = `${prefix} ${todoIcon(item.todo.status, this.theme)} ${recordId(item.todo.taskId, this.theme)} ${ownerBadge(item.todo.taskInfo, this.theme, Boolean(delegateLink(item.todo.taskInfo)))} ${safeSingleLine(item.todo.taskName)} ${metadata}`;
|
|
245
|
+
const line = metricsColumn(label, taskCompletion(item.todo), taskTime(item.todo), item.todo.workingSince !== undefined, width, this.theme);
|
|
244
246
|
const start = visibleWidth(`${prefix} ${todoIcon(item.todo.status, this.theme)} ${recordId(item.todo.taskId, this.theme)} `);
|
|
245
247
|
const hit = delegateHitRegion(delegateLink(item.todo.taskInfo), start, line, y);
|
|
246
248
|
if (hit)
|
|
@@ -283,6 +285,7 @@ export class WorksDashboard {
|
|
|
283
285
|
return [
|
|
284
286
|
this.theme.fg("accent", this.theme.bold(`DETAILS${position}`)),
|
|
285
287
|
truncateToWidth(heading, width, ""),
|
|
288
|
+
this.theme.fg("dim", `Time${item.kind === "work" ? " (task effort)" : ""}: ${formatTime(item.kind === "work" ? workTime(item.work) : taskTime(item.todo))}`),
|
|
286
289
|
...shown,
|
|
287
290
|
].slice(0, budget);
|
|
288
291
|
}
|
package/docs/REFERENCE.md
CHANGED
|
@@ -20,7 +20,7 @@ Limits:
|
|
|
20
20
|
|
|
21
21
|
A work contains `workId`, `workName`, `workInfo`, `createdAt`, and `updatedAt`. It is a collection with no stored or derived lifecycle status. Work tools do not accept status, and WorkList has no status filter. The public WorkStatus type is removed; consumers should use TodoStatus for task lifecycle.
|
|
22
22
|
|
|
23
|
-
A todo contains `taskId`, `workId`, `taskName`, `taskInfo`, `status`, optional `completionPercent`, `createdAt`, and `updatedAt`. Todo status is `active`, `blocked`, `completed`, or `cancelled`; new todos default to `active`.
|
|
23
|
+
A todo contains `taskId`, `workId`, `taskName`, `taskInfo`, `status`, optional `completionPercent`, optional `elapsedMs`, runtime-only optional `workingSince`, `createdAt`, and `updatedAt`. Todo status is `active`, `blocked`, `completed`, or `cancelled`; new todos default to `active`.
|
|
24
24
|
|
|
25
25
|
The public list shape assembles each work with `tasks: Todo[]`; tasks are stored separately to avoid duplicate state. Work progress is derived, not independently stored or editable.
|
|
26
26
|
|
|
@@ -38,7 +38,19 @@ Replay accepts version-1 Work events with or without status, ignores retired Wor
|
|
|
38
38
|
- Any unknown eligible task makes the work unknown (`—`); unknown is not silently 0. With no eligible tasks (empty Work or only cancelled tasks), work is unknown.
|
|
39
39
|
- Work progress reaches 100 only when all eligible tasks are completed; there is no parent status override. Progress never changes task statuses or auto-continuation eligibility.
|
|
40
40
|
- Optional progress fields are additive to version-1 branch events. Legacy completed tasks show 100%; other legacy tasks remain unknown until reported. Invalid optional progress is sanitized on replay without discarding the task.
|
|
41
|
-
- Dashboard, compact panel, list output and copied Markdown share these calculations. The compact panel
|
|
41
|
+
- Dashboard, compact panel, list output and copied Markdown share these calculations. The compact panel and `/works` reserve separated Done and Time columns; names truncate independently and navigation is unchanged. Percentages do not predict remaining time; no subtasks, weights or separate navigation sidebar are added.
|
|
42
|
+
|
|
43
|
+
### Measured time
|
|
44
|
+
|
|
45
|
+
`TodoUpdate` accepts optional `working: boolean`, separate from status and progress. `true` selects an active `owner: self` task in this session; a missing task, non-active status, or other ownership is rejected before changing state. The selected task is exclusive per session. `false` pauses that task without changing status; it does not interrupt a different selected task. Changing status away from active, changing ownership away from self, or deleting the task/Work closes its interval. The field is an operation, not persistent task status; callers cannot provide elapsed duration or timestamps.
|
|
46
|
+
|
|
47
|
+
TaskState owns focus, an agent-running gate, and an in-memory interval timestamp. Snapshot `workingSince` exists only during a running interval. Saved `elapsedMs` is a non-negative safe integer; version-1 `todo-time` custom entries save cumulative totals without altering status, completion, or the task's descriptive `updatedAt`. Replay accepts old entries and sanitizes invalid duration fields to unknown. Restored records never restore running focus or count offline time. New tasks start at zero; older records remain unknown until selected, which begins measurement from that point rather than reconstructing history. Negative intervals following a backward wall-clock change clamp to zero; forward clock corrections can affect measured time because the agreed clock is Date.now().
|
|
48
|
+
|
|
49
|
+
`registerTaskTiming` gates focus with agent start/end and nested blocking user-prompt events. Every new `before_agent_start` clears prior selection; native loop continuations can retain selection until final settlement. Abort signals close the interval immediately. Settlement, shutdown, and pre-navigation boundaries close and clear selection. Tool execution and model thinking within an agent loop count; idle and native retry waits between loops do not. Hosts without blocking-prompt events cannot exclude an in-loop extension dialog, but retain loop-boundary pauses. There is no per-second persistence, heartbeat, or crash-recovery registry: forced termination may lose the uncommitted interval.
|
|
50
|
+
|
|
51
|
+
`taskTime`, `workTime`, and `formatTime` supply shared display calculations. Work time sums all tasks, including cancelled tasks, because already-spent effort is real; an empty Work or any unknown task yields unknown. This differs deliberately from completion, which excludes cancelled tasks and averages rather than sums. Delegated workers measure their own session-local self tasks. Parent delegate task records display unknown and propagate unknown to Work totals; they do not import child timing or use prompt-to-completion duration as a substitute. Stored local intervals survive ownership changes but are not displayed as the full delegated duration. No cross-session task registry or parent monitor timing bridge is added.
|
|
52
|
+
|
|
53
|
+
Compact floating/widget views refresh running durations once per second while visible and dispose the render timer on hide. `/works` reuses its existing refresh interval. Neither timer writes session entries. Both views reserve Done and Time columns with name clipping, a running marker, and explicit unknown duration. The compact box minimum is 48 columns so the task prefix does not consume the entire name area; widget views hide below that width. Lists, dashboard details, and copied Markdown show the same measured totals.
|
|
42
54
|
|
|
43
55
|
## Tracking behavior
|
|
44
56
|
|
package/docs/USAGE_GUIDE.md
CHANGED
|
@@ -7,7 +7,7 @@ For every normal request that starts or continues work, Pi should:
|
|
|
7
7
|
1. Find existing work and todos.
|
|
8
8
|
2. Create the relevant Work collection, or refresh its shared context when needed.
|
|
9
9
|
3. Create or update detailed todos for the requested scope.
|
|
10
|
-
4. Mark the current todo active before starting it.
|
|
10
|
+
4. Mark the current todo active before starting it. For an `owner: self` task, include `working=true` to select it for automatic timing; re-select at the start of each fresh run.
|
|
11
11
|
5. During longer tasks, report interim progress after roughly 5–10 meaningful working steps or a milestone, when an estimate is possible.
|
|
12
12
|
6. Mark the todo blocked immediately if its next step must wait on a dependency; otherwise update it after the attempt as active, completed, or cancelled.
|
|
13
13
|
7. Keep status on tasks only; update Work context when scope or shared decisions change.
|
|
@@ -107,6 +107,20 @@ TodoDelete taskId="T1"
|
|
|
107
107
|
|
|
108
108
|
`TodoList` returns all matching todos when `limit` is omitted. A positive integer `limit` selects the newest matching todos after filters, displayed oldest-to-newest. The result shows how many todos were returned and how many matched in total. Both list tools can still truncate very long text output at 50KB or 2,000 lines.
|
|
109
109
|
|
|
110
|
+
### Active task time
|
|
111
|
+
|
|
112
|
+
```text
|
|
113
|
+
TodoUpdate taskId="T1" status="active" working=true
|
|
114
|
+
TodoUpdate taskId="T2" working=true
|
|
115
|
+
TodoUpdate taskId="T2" working=false
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The first call selects T1; the second pauses T1 and selects T2; the third pauses T2 without changing its status. `working=true` requires an active task with `owner: self` in its details. Creation and active status alone do not start timing. The model selects the task, but never submits timestamps or estimates of duration.
|
|
119
|
+
|
|
120
|
+
Time is saved total milliseconds plus `Date.now() - workingSince` while running. The extension saves each interval when paused, switched, or finished, not on every one-second display refresh. Thinking and foreground tool execution count. Idle periods, retry delays between agent loops, and blocking extension UI prompts pause timing. Blocking, completion, cancellation, changing away from self ownership, abort, and shutdown close the interval. Select again at the beginning of each new run. A restored session or branch always starts paused and excludes offline time. Abrupt process termination can lose the unsaved current interval; there is no background checkpoint writer. Blocking prompt exclusion requires a Pi host emitting `ui_prompt_start` and `ui_prompt_end`; older hosts retain loop-boundary timing.
|
|
121
|
+
|
|
122
|
+
The compact panel and `/works` show reserved Done and Time columns; `▶` beside a duration means it is running. New tasks show `0s`. Legacy tasks without timing show `—`; selecting one begins measurement from now, not from its creation date. Work time sums task effort, including cancelled tasks; any unknown duration makes its total unknown. This is not elapsed wall-clock time and does not predict completion. Each delegated agent times its own local self tasks; parent delegate records show `—` because remote time is unmeasured, making the Work total unknown rather than a misleading local-only subtotal. List tools and copied Markdown include durations too.
|
|
123
|
+
|
|
110
124
|
### Completion percentages
|
|
111
125
|
|
|
112
126
|
During longer tasks, Pi should include a `completionPercent` estimate in `TodoUpdate` after roughly 5–10 meaningful working steps or a milestone, rather than waiting until completion or only updating status. Explain the evidence and remaining work in `taskInfo`. Estimates remain optional: use `null` when unknown, and leave a percentage unchanged if there is no new evidence. This is model-facing guidance, not an enforced schedule or an automatic percentage increase. These are approximate AI-reported values, not a fixed percentage for each status and not a time prediction. Use an integer 0–100 or `null` for unknown. Completed status means verified completion and displays 100%; 100 without completed status is rejected. Partial progress requires reopening a completed task; reopening without a fresh estimate makes it unknown. Blocking retains the current estimate.
|
|
@@ -173,7 +187,7 @@ Navigation directly focuses the linked paneId through Herdr. Closed panes, missi
|
|
|
173
187
|
|
|
174
188
|
The compact panel no longer displays the session ID. Before Copy, its header shows nonzero task-state counts across all Works: `3!` blocked, `2▶` active, `5✓` completed, and `1×` cancelled, using the same icon colors as task rows. Counts update in floating, widget and minimized layouts; narrow headers shorten the toggle and truncate the summary when needed. Its underlined `[Open session]` action sits immediately after Copy in floating, widget and minimized layouts. It opens this agent's existing artifact directory under repository `var/` in Cursor, including a nested delegated session folder. If no folder exists, it creates `var/<full-sessionId>/`; multiple matching folders report an ambiguity rather than guessing. Session identity comes from Pi's context, not a pane name. Folder resolution and Cursor launch happen only on activation, never during rendering. `/works-panel open-session` is the keyboard-command alternative. The existing Open action still opens the repository. Narrow compact headers use `[-]`/`[+]` for Minimize/Maximize so all actions fit. The `/works` dashboard retains its existing title and controls.
|
|
175
189
|
|
|
176
|
-
The panel defaults to a floating top-right layout and does not take keyboard focus.
|
|
190
|
+
The panel defaults to a floating top-right layout and does not take keyboard focus. Its minimum box width is 48 columns to leave room for names beside both metrics; the widget hides below 48 columns. Separated right-hand Done and Time columns keep work/task percentages and measured durations aligned and visible even when names are long; the left side retains names, task status icons and Work task-counts. Work rows have no status icons. It hides on small terminals. The top border centers repository-wide Git status: `git main · S2 U3 ?1` means two staged files, three unstaged files, and one untracked file; a file with both staged and unstaged edits counts in both. A clean repository shows `git main · clean`. Long branches shorten before counts. Detached HEAD shows `@` plus the short commit. Git remains visible while minimized and adds no content row.
|
|
177
191
|
|
|
178
192
|
The asynchronous Git cache refreshes every second while a view is attached; file-changing tool results expire it sooner without blanking the last snapshot. Initial reads show `git loading…`; outside Git the border is plain, and initial failures show `git unavailable`. Later refresh failures retain the last snapshot until a successful read. Polling is read-only and stops when both the panel and dashboard are closed/off.
|
|
179
193
|
|