@abhishek944/pi-tasks 0.9.0 → 0.11.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 +17 -9
- package/dist/agents/herdr.d.ts +4 -0
- package/dist/agents/herdr.js +23 -0
- package/dist/agents/links.d.ts +7 -0
- package/dist/agents/links.js +30 -0
- package/dist/agents/tools.d.ts +3 -0
- package/dist/agents/tools.js +140 -0
- package/dist/auto-continue.js +11 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +30 -6
- package/dist/markdown.js +1 -1
- package/dist/open-repository.d.ts +2 -0
- package/dist/open-repository.js +22 -0
- package/dist/ownership.d.ts +1 -0
- package/dist/ownership.js +9 -0
- package/dist/progress.js +1 -1
- package/dist/state.d.ts +3 -4
- package/dist/state.js +10 -9
- package/dist/tools.js +14 -15
- package/dist/tracking.js +17 -6
- package/dist/types.d.ts +2 -4
- package/dist/ui/panel.d.ts +14 -4
- package/dist/ui/panel.js +110 -46
- package/dist/ui/works-dashboard.d.ts +3 -0
- package/dist/ui/works-dashboard.js +89 -18
- package/docs/REFERENCE.md +41 -13
- package/docs/USAGE_GUIDE.md +107 -14
- package/package.json +1 -1
package/dist/tools.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
2
2
|
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { Type } from "typebox";
|
|
4
|
+
import { preservePaneLink } from "./agents/links.js";
|
|
4
5
|
import { formatCompletion, taskCompletion, workCompletion } from "./progress.js";
|
|
5
6
|
import { renderTaskCall, renderTaskResult, taskResult } from "./tool-result.js";
|
|
6
7
|
const StatusSchema = StringEnum(["active", "blocked", "completed", "cancelled"]);
|
|
7
|
-
const STATUS_GUIDANCE = "New
|
|
8
|
+
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.";
|
|
8
9
|
const CompletionSchema = Type.Union([Type.Integer({ minimum: 0, maximum: 100 }), Type.Null()], {
|
|
9
10
|
description: "AI-reported approximate task completion, not elapsed time or a status-to-percentage mapping. Use null for unknown; reserve 100 for verified completed status. Work progress is the equal average of non-cancelled tasks.",
|
|
10
11
|
});
|
|
@@ -15,7 +16,7 @@ export function registerTaskTools(pi, state) {
|
|
|
15
16
|
pi.registerTool({
|
|
16
17
|
name: "WorkCreate",
|
|
17
18
|
label: "WorkCreate",
|
|
18
|
-
description: `Create a session-scoped work item. Use detailed workInfo that preserves the goal, context, scope, constraints, decisions, and expected outcome.
|
|
19
|
+
description: `Create a session-scoped work item. Use detailed workInfo that preserves the goal, context, scope, constraints, decisions, and expected outcome. Works are collections of tasks and have no status. ${DETAILS_GUIDANCE}`,
|
|
19
20
|
promptSnippet: "Create a session-scoped work item before starting substantial actionable work",
|
|
20
21
|
promptGuidelines: [
|
|
21
22
|
"Use WorkCreate for normal requests that start new work in the main conversation; never use it during /ask or /btw.",
|
|
@@ -25,11 +26,10 @@ export function registerTaskTools(pi, state) {
|
|
|
25
26
|
parameters: Type.Object({
|
|
26
27
|
workName: NameSchema,
|
|
27
28
|
workInfo: InfoSchema,
|
|
28
|
-
status: Type.Optional(StatusSchema),
|
|
29
29
|
}, { additionalProperties: false }),
|
|
30
30
|
execute(_id, params) {
|
|
31
|
-
const work = state.createWork(params.workName, params.workInfo
|
|
32
|
-
return Promise.resolve(taskResult(`Created work ${work.workId}: ${work.workName}
|
|
31
|
+
const work = state.createWork(params.workName, params.workInfo);
|
|
32
|
+
return Promise.resolve(taskResult(`Created work ${work.workId}: ${work.workName}`, "work-create", { workId: work.workId }));
|
|
33
33
|
},
|
|
34
34
|
renderCall: renderTaskCall("WorkCreate"),
|
|
35
35
|
renderResult: renderTaskResult,
|
|
@@ -40,11 +40,10 @@ export function registerTaskTools(pi, state) {
|
|
|
40
40
|
description: "List session-scoped works and their associated todos. Optional limit returns the newest N matching works after filtering, in chronological order; omitted returns all. Results include detailed workInfo and taskInfo and are truncated at 50KB or 2000 lines.",
|
|
41
41
|
parameters: Type.Object({
|
|
42
42
|
workId: Type.Optional(Type.String()),
|
|
43
|
-
status: Type.Optional(StatusSchema),
|
|
44
43
|
limit: Type.Optional(Type.Integer({ minimum: 1, description: "Return only the newest N matching works; omit for all." })),
|
|
45
44
|
}, { additionalProperties: false }),
|
|
46
45
|
execute(_id, params) {
|
|
47
|
-
const matches = state.listWorks({ workId: params.workId
|
|
46
|
+
const matches = state.listWorks({ workId: params.workId });
|
|
48
47
|
const works = params.limit === undefined ? matches : matches.slice(-params.limit);
|
|
49
48
|
const summary = `Showing ${works.length} of ${matches.length} matching works`;
|
|
50
49
|
return Promise.resolve(taskResult(bounded(`${summary}\n\n${formatWorks(works)}`), "work-list", { count: works.length, total: matches.length }, summary));
|
|
@@ -55,18 +54,17 @@ export function registerTaskTools(pi, state) {
|
|
|
55
54
|
pi.registerTool({
|
|
56
55
|
name: "WorkUpdate",
|
|
57
56
|
label: "WorkUpdate",
|
|
58
|
-
description: `Update a work's name
|
|
59
|
-
promptSnippet: "Update work
|
|
60
|
-
promptGuidelines: ["Use WorkUpdate
|
|
57
|
+
description: `Update a work's name or detailed information as its scope or shared context changes. Works are collections of tasks and have no status. ${DETAILS_GUIDANCE}`,
|
|
58
|
+
promptSnippet: "Update work context as its scope or shared decisions change",
|
|
59
|
+
promptGuidelines: ["Use WorkUpdate when shared scope or context changes; keep execution status on tasks with TodoUpdate. Never update tracking during /ask or /btw.", DETAILS_GUIDANCE],
|
|
61
60
|
parameters: Type.Object({
|
|
62
61
|
workId: Type.String(),
|
|
63
62
|
workName: Type.Optional(NameSchema),
|
|
64
63
|
workInfo: Type.Optional(InfoSchema),
|
|
65
|
-
status: Type.Optional(StatusSchema),
|
|
66
64
|
}, { additionalProperties: false, minProperties: 2 }),
|
|
67
65
|
execute(_id, params) {
|
|
68
|
-
const work = state.updateWork(params.workId, { workName: params.workName, workInfo: params.workInfo
|
|
69
|
-
return Promise.resolve(taskResult(`Updated work ${work.workId}: ${work.workName}
|
|
66
|
+
const work = state.updateWork(params.workId, { workName: params.workName, workInfo: params.workInfo });
|
|
67
|
+
return Promise.resolve(taskResult(`Updated work ${work.workId}: ${work.workName}`, "work-update", { workId: work.workId }));
|
|
70
68
|
},
|
|
71
69
|
renderCall: renderTaskCall("WorkUpdate"),
|
|
72
70
|
renderResult: renderTaskResult,
|
|
@@ -144,7 +142,8 @@ export function registerTaskTools(pi, state) {
|
|
|
144
142
|
completionPercent: Type.Optional(CompletionSchema),
|
|
145
143
|
}, { additionalProperties: false, minProperties: 2 }),
|
|
146
144
|
execute(_id, params) {
|
|
147
|
-
const
|
|
145
|
+
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 });
|
|
148
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) }));
|
|
149
148
|
},
|
|
150
149
|
renderCall: renderTaskCall("TodoUpdate"),
|
|
@@ -170,7 +169,7 @@ function formatWorks(works) {
|
|
|
170
169
|
if (works.length === 0)
|
|
171
170
|
return "No works found in this session.";
|
|
172
171
|
return works.map((work) => [
|
|
173
|
-
`${work.workId}
|
|
172
|
+
`${work.workId} ${work.workName} · ${formatCompletion(workCompletion(work))}`,
|
|
174
173
|
`Work info:\n${work.workInfo}`,
|
|
175
174
|
work.tasks.length ? `Todos:\n${formatTodos(work.tasks)}` : "Todos: none",
|
|
176
175
|
].join("\n")).join("\n\n---\n\n");
|
package/dist/tracking.js
CHANGED
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
const REQUIRED_TRACKING_TOOLS = ["WorkCreate", "WorkList", "WorkUpdate", "TodoCreate", "TodoList", "TodoUpdate"];
|
|
2
2
|
const TRACKING_GUIDANCE = `[SESSION COORDINATION]
|
|
3
|
-
Work is
|
|
3
|
+
Work is a collection of tasks with shared context and no status of its own. A todo is a concrete step that belongs to a work and owns its execution status. A monitor runs one long-lived background command. A loop schedules a future, recurring, event-driven, or idle continuation.
|
|
4
4
|
|
|
5
5
|
For every normal user request that starts or continues work, keep the session's work and todo records synchronized. Do not skip tracking because the work looks small.
|
|
6
6
|
Write workInfo and taskInfo in normal prose with full sentences and spaces between words. Conversational brevity modes must not compress stored records or concatenate words.
|
|
7
7
|
|
|
8
|
+
Every delegated subagent, at every delegation depth, must use these tools to create or resume its own session-local Work and Todos before assigned work. Do not begin assigned work without a real workId and an active taskId for the current step. Keep these records current and return the IDs with results, checks, and blockers. Parent assignment IDs are context, not shared records: IDs are session-scoped. Record the parent assignment in the worker's details; do not mutate the parent's session records. Include this requirement in every subagent prompt. If tracking tools or IDs are unavailable, report the blocker and do not begin delegated work; a parent-owned Todo or Markdown checklist is not a substitute. Do not invent IDs or backdate tracking. This is an instruction, not a runtime enforcement hook, and does not change the /ask or /btw exceptions.
|
|
9
|
+
|
|
10
|
+
Shared workflow contract:
|
|
11
|
+
- Every tracked Work, including each subagent's local Work, follows the global implement skill for coordination. Read it before execution, or reuse it if already active; do not recursively invoke it. Specialized skills retain their scope and safety limits: research/review stay read-only and planning does not authorize implementation. If the skill is unavailable, report the blocker rather than executing without it.
|
|
12
|
+
- Before execution, read the full current sessionId through the agent's own shell tool using printf '%s\\n' "$PI_SESSION_ID". Require a nonempty safe component matching [A-Za-z0-9][A-Za-z0-9_-]* and real tool-returned Work/Task IDs. Missing tools, identity, or IDs block execution; never substitute the parent's identity or invent IDs. Reading instructions, obtaining identity, and establishing tracking are startup steps.
|
|
13
|
+
- Root task artifacts use repository-relative var/<sessionId>/<workId>/<taskId>/, not system /var/. A delegated worker appends its own <childSessionId>/<childWorkId>/<childTaskId>/ beneath the exact parentTaskDir supplied in its assignment, recursively. Keep resolved paths inside the repository's var/, including through symlinks. Record canonical paths and parent IDs in taskInfo, pass them unchanged in handoffs, and return them with results. Validate ownership before reuse after resume or branch navigation; do not overwrite artifacts just because numeric IDs match. Create artifacts only when useful; feature names are descriptions, not path keys. Do not migrate existing artifacts implicitly. Follow implement for the detailed contract and report incompatible helper paths rather than inventing arguments.
|
|
14
|
+
- For every task, start taskInfo with owner: self or owner: delegate followed by a short reason before execution. Preserve this explicit declaration when updating taskInfo; the panel reads this line to show the ownership badge, with unassigned for missing or conflicting decisions. Delegate only when scope/acceptance criteria are clear, ownership can be isolated, inputs and prerequisites are ready, and useful parallelism or expertise outweighs startup and integration costs. Respect skill-specific delegation restrictions and required tracking/monitor tools. Keep small, tightly coupled, shared-interface, or expensive-to-explain work with one owner. Delegating agents retain responsibility for monitoring, integration, verification, and cleanup; children apply the same rule when allowed to delegate. No arbitrary worker, file-count, or depth thresholds.
|
|
15
|
+
- Herdr subagent root panes are named exactly with the parent's delegated Task ID, such as T34, with no brackets, descriptions, Work IDs, or other prefixes. This is a display label, not the child's session or local Task ID. Use returned resource IDs for lifecycle operations because pane names can repeat across sessions; rename an owned worker pane when assigning it a different parent Todo.
|
|
16
|
+
- Prefer pi-tasks AgentCreate/List/Status/Output/Send/Interrupt/Close/Focus CLI wrappers for supported Herdr operations; use CLI only for unavailable capabilities. AgentCreate takes an existing owner: delegate task, canonical taskDir, explicit model flags and onSignal/optional onDone instructions, creates the pane and monitor, and automatically links the delegate badge. It does not send work: confirm MonitorList shows subscription ready, then AgentSend the returned assignment to the actual paneId. Follow-ups keep that same monitor/callbacks. onSignal handles worker state changes; onDone means the monitor process ended, not the task finished. Do not add duplicate monitors, infer completion from signals or close workers before follow-ups finish. Use AgentClose only with paneId/monitorId values for resources you created. Wrappers assume panes are not repurposed and add no registry, process checks or automatic recovery.
|
|
17
|
+
- Pi-tasks owns task records/progress and task-owned agent tool orchestration; implement owns coordination and artifact paths; Herdr owns panes/processes and pi-loop-monitor owns supervision. The shared skill/path guidance is instruction-only, not automatic cross-session shared records; Agent tools simply wrap the CLI and existing monitor tools. Plain conversation, /ask, and /btw remain outside this workflow.
|
|
18
|
+
|
|
8
19
|
Before implementation, investigation, or any other requested work:
|
|
9
20
|
1. Use WorkList and TodoList to find the relevant existing records and avoid duplicates.
|
|
10
|
-
2. If no suitable work exists, create one with WorkCreate. Otherwise use WorkUpdate
|
|
11
|
-
3. Create or update the work's todos so they match the requested scope.
|
|
21
|
+
2. If no suitable work exists, create one with WorkCreate. Otherwise use WorkUpdate when its scope or shared context needs refreshing.
|
|
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.
|
|
12
23
|
4. Mark the todo being attempted active with TodoUpdate before doing that work.
|
|
13
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.
|
|
14
25
|
|
|
15
26
|
During and after the attempt:
|
|
16
27
|
- When available, use MonitorCreate only when a command should continue in the background; inspect it with MonitorList and do not poll it with shell sleep loops.
|
|
17
28
|
- When available, use LoopCreate only when work needs a future or repeated wake. Do not create a loop for ordinary synchronous work.
|
|
18
|
-
- A loop or monitor does not replace
|
|
29
|
+
- A loop or monitor does not replace task status. Mark a task blocked immediately when its next step must wait for another agent’s output, review, an external response, user input, permission, or another obstacle. Record which dependency it awaits and what will unblock it in taskInfo; preserve its progress. Tasks actually executing in another agent may remain active, but dependent tasks awaiting that output are blocked. When the dependency resolves and work resumes, mark the affected tasks active and update their context.
|
|
19
30
|
- During longer tasks, include an evidence-based completionPercent estimate in TodoUpdate after roughly 5–10 meaningful working steps or a milestone. Do not wait until completion or only update status when an estimate is possible. 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. Keep estimates current, including after scope changes. Work completion is derived as the equal average of non-cancelled task percentages; any unknown child makes it unknown. Do not set an independent work percentage.
|
|
20
31
|
- Mark the todo completed, blocked, or cancelled as appropriate and update taskInfo with important current context. Only use completed/100 after verification. Blocking retains the last percentage; it does not erase completed effort. Reopening a completed task needs a fresh estimate (otherwise it becomes unknown).
|
|
21
|
-
- Percentages are approximate completion, not ETA or proof. Never
|
|
22
|
-
-
|
|
32
|
+
- Percentages are approximate completion, not ETA or proof. Never change task statuses merely because a percentage looks complete.
|
|
33
|
+
- Work is only a collection: never assign it active, blocked, completed, or cancelled status. Track every executable step as a todo; empty works do not trigger continuation. Automatic continuation checks active todos across all works on the current session branch; blocked, completed, and cancelled tasks do not trigger it. Update workInfo only when shared scope, context, or decisions change.
|
|
23
34
|
- Never create or update works, todos, loops, or monitors during /ask, /btw, or any BTW side thread.`;
|
|
24
35
|
export function areTrackingToolsActive(pi) {
|
|
25
36
|
const active = new Set(pi.getActiveTools());
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export type TodoStatus = WorkStatus;
|
|
1
|
+
export type TodoStatus = "active" | "blocked" | "completed" | "cancelled";
|
|
3
2
|
export interface Work {
|
|
4
3
|
workId: string;
|
|
5
4
|
workName: string;
|
|
6
5
|
workInfo: string;
|
|
7
|
-
status: WorkStatus;
|
|
8
6
|
createdAt: number;
|
|
9
7
|
updatedAt: number;
|
|
10
8
|
}
|
|
@@ -31,7 +29,7 @@ export type TaskEvent = {
|
|
|
31
29
|
type: "work-updated";
|
|
32
30
|
at: number;
|
|
33
31
|
workId: string;
|
|
34
|
-
patch: Partial<Pick<Work, "workName" | "workInfo"
|
|
32
|
+
patch: Partial<Pick<Work, "workName" | "workInfo">>;
|
|
35
33
|
} | {
|
|
36
34
|
version: 1;
|
|
37
35
|
type: "work-deleted";
|
package/dist/ui/panel.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type ExtensionUIContext, type Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type DelegateLink } from "../agents/links.js";
|
|
2
3
|
import type { GitSnapshot, GitStatusCache } from "../git-status.js";
|
|
3
4
|
import type { TaskState } from "../state.js";
|
|
4
|
-
import type { TodoStatus
|
|
5
|
+
import type { TodoStatus } from "../types.js";
|
|
5
6
|
export type TasksPanelMode = "floating" | "widget" | "off";
|
|
6
7
|
export declare class TasksPanelHost {
|
|
7
8
|
private readonly state;
|
|
@@ -13,8 +14,9 @@ export declare class TasksPanelHost {
|
|
|
13
14
|
private mode;
|
|
14
15
|
private minimized;
|
|
15
16
|
private cwd;
|
|
17
|
+
private sessionId;
|
|
16
18
|
constructor(state: TaskState, git: GitStatusCache);
|
|
17
|
-
attach(ui: ExtensionUIContext, cwd: string): void;
|
|
19
|
+
attach(ui: ExtensionUIContext, cwd: string, sessionId: string): void;
|
|
18
20
|
setMode(mode: TasksPanelMode): void;
|
|
19
21
|
getMode(): TasksPanelMode;
|
|
20
22
|
setMinimized(minimized: boolean): void;
|
|
@@ -23,8 +25,16 @@ export declare class TasksPanelHost {
|
|
|
23
25
|
private applyMode;
|
|
24
26
|
private hideCurrent;
|
|
25
27
|
}
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function
|
|
28
|
+
export declare function recordId(id: string, theme: Theme): string;
|
|
29
|
+
export declare function ownerBadge(taskInfo: string, theme: Theme, linked?: boolean): string;
|
|
30
|
+
export type DelegateHitRegion = {
|
|
31
|
+
start: number;
|
|
32
|
+
end: number;
|
|
33
|
+
y: number;
|
|
34
|
+
link: DelegateLink;
|
|
35
|
+
};
|
|
36
|
+
export declare function delegateHitRegion(link: DelegateLink | undefined, start: number, line: string, y: number, leftPad?: number): DelegateHitRegion | undefined;
|
|
37
|
+
export declare function progressName(name: string, completion: number | null, width: number, prefix?: string): string;
|
|
28
38
|
export declare function todoIcon(status: TodoStatus, theme: Theme): string;
|
|
29
39
|
export declare function frame(content: string, innerWidth: number, theme: Theme): string;
|
|
30
40
|
export declare function rule(innerWidth: number, theme: Theme): string;
|
package/dist/ui/panel.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { stripVTControlCharacters } from "node:util";
|
|
2
2
|
import { copyToClipboard } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import { sliceByColumn, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
4
|
+
import { delegateLink, focusPane } from "../agents/links.js";
|
|
4
5
|
import { formatWorksMarkdown } from "../markdown.js";
|
|
5
|
-
import { openRepository } from "../open-repository.js";
|
|
6
|
+
import { openRepository, openSession } from "../open-repository.js";
|
|
7
|
+
import { taskOwner } from "../ownership.js";
|
|
6
8
|
import { formatCompletion, taskCompletion, workCompletion } from "../progress.js";
|
|
7
9
|
import { safeSingleLine } from "../text.js";
|
|
8
10
|
const EMPTY_COMPONENT = { render: () => [], invalidate: () => { } };
|
|
@@ -18,13 +20,15 @@ export class TasksPanelHost {
|
|
|
18
20
|
mode = "floating";
|
|
19
21
|
minimized = false;
|
|
20
22
|
cwd = "";
|
|
23
|
+
sessionId = "Session unavailable";
|
|
21
24
|
constructor(state, git) {
|
|
22
25
|
this.state = state;
|
|
23
26
|
this.git = git;
|
|
24
27
|
}
|
|
25
|
-
attach(ui, cwd) {
|
|
28
|
+
attach(ui, cwd, sessionId) {
|
|
26
29
|
this.hideCurrent();
|
|
27
30
|
this.cwd = cwd;
|
|
31
|
+
this.sessionId = safeSingleLine(sessionId) || "Session unavailable";
|
|
28
32
|
this.ui = ui;
|
|
29
33
|
this.applyMode();
|
|
30
34
|
}
|
|
@@ -62,7 +66,7 @@ export class TasksPanelHost {
|
|
|
62
66
|
this.tui = tui;
|
|
63
67
|
this.panel = new TasksPanel(tui, this.state, theme, "widget", this.minimized, (minimized) => {
|
|
64
68
|
this.minimized = minimized;
|
|
65
|
-
}, (message, type) => ui.notify(message, type), this.cwd, this.git);
|
|
69
|
+
}, (message, type) => ui.notify(message, type), this.cwd, this.git, this.sessionId);
|
|
66
70
|
return this.panel;
|
|
67
71
|
});
|
|
68
72
|
return;
|
|
@@ -71,7 +75,7 @@ export class TasksPanelHost {
|
|
|
71
75
|
this.tui = tui;
|
|
72
76
|
this.panel = new TasksPanel(tui, this.state, theme, "floating", this.minimized, (minimized) => {
|
|
73
77
|
this.minimized = minimized;
|
|
74
|
-
}, (message, type) => ui.notify(message, type), this.cwd, this.git);
|
|
78
|
+
}, (message, type) => ui.notify(message, type), this.cwd, this.git, this.sessionId);
|
|
75
79
|
this.handle = tui.showOverlay(this.panel, {
|
|
76
80
|
anchor: "top-right",
|
|
77
81
|
width: "42%",
|
|
@@ -108,18 +112,22 @@ class TasksPanel {
|
|
|
108
112
|
notify;
|
|
109
113
|
cwd;
|
|
110
114
|
git;
|
|
115
|
+
sessionId;
|
|
111
116
|
scrollOffset = 0;
|
|
112
117
|
pageSize = 1;
|
|
113
118
|
contentLength = 0;
|
|
114
119
|
followTail = true;
|
|
115
120
|
copying = false;
|
|
116
121
|
opening = false;
|
|
122
|
+
openingDelegate = false;
|
|
123
|
+
delegateHits = [];
|
|
117
124
|
disposed = false;
|
|
118
125
|
unsubscribeGit;
|
|
119
126
|
copyHitRegion;
|
|
120
127
|
openHitRegion;
|
|
128
|
+
sessionHitRegion;
|
|
121
129
|
toggleHitRegion;
|
|
122
|
-
constructor(tui, state, theme, placement, minimized, onMinimizedChange, notify, cwd, git) {
|
|
130
|
+
constructor(tui, state, theme, placement, minimized, onMinimizedChange, notify, cwd, git, sessionId) {
|
|
123
131
|
this.tui = tui;
|
|
124
132
|
this.state = state;
|
|
125
133
|
this.theme = theme;
|
|
@@ -129,8 +137,10 @@ class TasksPanel {
|
|
|
129
137
|
this.notify = notify;
|
|
130
138
|
this.cwd = cwd;
|
|
131
139
|
this.git = git;
|
|
140
|
+
this.sessionId = sessionId;
|
|
132
141
|
}
|
|
133
142
|
render(width) {
|
|
143
|
+
this.delegateHits = [];
|
|
134
144
|
if (this.placement === "widget")
|
|
135
145
|
this.setVisible(width >= 38);
|
|
136
146
|
if (width < 38)
|
|
@@ -140,7 +150,7 @@ class TasksPanel {
|
|
|
140
150
|
const innerWidth = boxWidth - 2;
|
|
141
151
|
const leftPad = this.placement === "widget" ? " ".repeat(Math.max(0, width - boxWidth)) : "";
|
|
142
152
|
if (this.minimized) {
|
|
143
|
-
const header = this.renderHeader(
|
|
153
|
+
const header = this.renderHeader(innerWidth, leftPad.length);
|
|
144
154
|
return [
|
|
145
155
|
gitBorder(innerWidth, this.theme, this.git.getSnapshot()),
|
|
146
156
|
frame(header, innerWidth, this.theme),
|
|
@@ -149,14 +159,18 @@ class TasksPanel {
|
|
|
149
159
|
}
|
|
150
160
|
const contentWidth = innerWidth - PROGRESS_COLUMN_WIDTH;
|
|
151
161
|
const content = [];
|
|
162
|
+
const delegateRows = new Map();
|
|
152
163
|
if (works.length === 0)
|
|
153
164
|
content.push(progressColumn(this.theme.fg("muted", "No works yet."), null, innerWidth, this.theme));
|
|
154
165
|
for (const work of works) {
|
|
155
166
|
const completed = work.tasks.filter((todo) => todo.status === "completed").length;
|
|
156
|
-
const summary = workSummaryLine(work.
|
|
167
|
+
const summary = workSummaryLine(work.workName, `${completed}/${work.tasks.length}`, contentWidth, this.theme, work.workId);
|
|
157
168
|
content.push(progressColumn(summary, workCompletion(work), innerWidth, this.theme));
|
|
158
169
|
for (const todo of work.tasks) {
|
|
159
|
-
const
|
|
170
|
+
const agent = delegateLink(todo.taskInfo);
|
|
171
|
+
const lead = ` ${todoIcon(todo.status, this.theme)} ${recordId(todo.taskId, this.theme)} `;
|
|
172
|
+
const label = `${lead}${ownerBadge(todo.taskInfo, this.theme, Boolean(agent))} ${this.theme.fg(todo.status === "completed" ? "muted" : "text", safeSingleLine(todo.taskName))}`;
|
|
173
|
+
delegateRows.set(content.length, { agent, start: visibleWidth(lead) });
|
|
160
174
|
content.push(progressColumn(label, taskCompletion(todo), innerWidth, this.theme));
|
|
161
175
|
}
|
|
162
176
|
}
|
|
@@ -174,15 +188,20 @@ class TasksPanel {
|
|
|
174
188
|
this.clampScrollOffset();
|
|
175
189
|
}
|
|
176
190
|
const shown = content.slice(this.scrollOffset, this.scrollOffset + this.pageSize);
|
|
191
|
+
shown.forEach((line, index) => {
|
|
192
|
+
const row = delegateRows.get(this.scrollOffset + index);
|
|
193
|
+
if (!row)
|
|
194
|
+
return;
|
|
195
|
+
const hit = delegateHitRegion(row.agent, row.start, line, 3 + index, leftPad.length);
|
|
196
|
+
if (hit)
|
|
197
|
+
this.delegateHits.push(hit);
|
|
198
|
+
});
|
|
177
199
|
const hasOverflow = content.length > this.pageSize;
|
|
178
200
|
const range = `${this.scrollOffset + 1}–${this.scrollOffset + shown.length}/${content.length}`;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
: ` · ${range} · latest · /works for all`;
|
|
184
|
-
}
|
|
185
|
-
const header = this.renderHeader(title, innerWidth, leftPad.length);
|
|
201
|
+
const suffix = this.placement === "floating" && hasOverflow
|
|
202
|
+
? this.tui.mode === "fullscreen" ? ` · ${range}` : ` · ${range} · latest · /works for all`
|
|
203
|
+
: "";
|
|
204
|
+
const header = this.renderHeader(innerWidth, leftPad.length, suffix);
|
|
186
205
|
const lines = [
|
|
187
206
|
gitBorder(innerWidth, this.theme, this.git.getSnapshot()),
|
|
188
207
|
frame(header, innerWidth, this.theme),
|
|
@@ -195,7 +214,23 @@ class TasksPanel {
|
|
|
195
214
|
handleMouse(event) {
|
|
196
215
|
if (this.disposed)
|
|
197
216
|
return undefined;
|
|
198
|
-
if (event.type === "
|
|
217
|
+
if (event.type === "press" && event.button === "left") {
|
|
218
|
+
const delegateHit = this.delegateHits.some((region) => event.y === region.y && this.isHit(event.x, region));
|
|
219
|
+
const headerHit = event.y === 1 && [this.copyHitRegion, this.sessionHitRegion, this.openHitRegion, this.toggleHitRegion].some((region) => this.isHit(event.x, region));
|
|
220
|
+
// Own the gesture so Pi does not turn repeated control clicks into text selection.
|
|
221
|
+
if (delegateHit || headerHit)
|
|
222
|
+
return { handled: true };
|
|
223
|
+
}
|
|
224
|
+
// Legacy mouse releases omit the button; Pi still normalizes the gesture as a click.
|
|
225
|
+
const primaryClick = event.type === "click" && (event.button === "left" || event.button === "none");
|
|
226
|
+
if (primaryClick) {
|
|
227
|
+
const hit = this.delegateHits.find((region) => event.y === region.y && this.isHit(event.x, region));
|
|
228
|
+
if (hit) {
|
|
229
|
+
void this.openLinkedDelegate(hit.link);
|
|
230
|
+
return { handled: true, render: true };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (primaryClick && event.y === 1) {
|
|
199
234
|
if (this.isHit(event.x, this.toggleHitRegion)) {
|
|
200
235
|
this.setMinimized(!this.minimized);
|
|
201
236
|
return { handled: true, render: true };
|
|
@@ -204,6 +239,10 @@ class TasksPanel {
|
|
|
204
239
|
void this.copyAllAsMarkdown();
|
|
205
240
|
return { handled: true, render: true };
|
|
206
241
|
}
|
|
242
|
+
if (this.isHit(event.x, this.sessionHitRegion)) {
|
|
243
|
+
void this.openInCursor(true);
|
|
244
|
+
return { handled: true, render: true };
|
|
245
|
+
}
|
|
207
246
|
if (this.isHit(event.x, this.openHitRegion)) {
|
|
208
247
|
void this.openInCursor();
|
|
209
248
|
return { handled: true, render: true };
|
|
@@ -239,43 +278,66 @@ class TasksPanel {
|
|
|
239
278
|
this.onMinimizedChange(minimized);
|
|
240
279
|
this.tui.requestRender();
|
|
241
280
|
}
|
|
242
|
-
renderHeader(
|
|
243
|
-
const title = this.theme.fg("accent", this.theme.bold(titleText));
|
|
281
|
+
renderHeader(width, leftPadWidth, suffix = "") {
|
|
244
282
|
const copyAction = this.copying
|
|
245
283
|
? this.theme.fg("dim", "[Copying…]")
|
|
246
284
|
: this.theme.fg("accent", this.theme.bold("[Copy]"));
|
|
247
|
-
const
|
|
248
|
-
const
|
|
285
|
+
const sessionAction = this.theme.fg(this.opening ? "dim" : "accent", this.theme.underline(this.theme.bold("[Open session]")));
|
|
286
|
+
const openAction = this.theme.fg(this.opening ? "dim" : "accent", this.theme.underline(this.theme.bold("[Open]")));
|
|
287
|
+
const fixedWidth = visibleWidth(copyAction) + visibleWidth(sessionAction) + visibleWidth(openAction) + 3;
|
|
288
|
+
const fullToggle = this.minimized ? "[Maximize]" : "[Minimize]";
|
|
289
|
+
const toggleLabel = fixedWidth + visibleWidth(fullToggle) <= width ? fullToggle : this.minimized ? "[+]" : "[-]";
|
|
249
290
|
const toggleAction = this.theme.fg("accent", this.theme.bold(toggleLabel));
|
|
250
|
-
const actionsWidth =
|
|
291
|
+
const actionsWidth = fixedWidth + visibleWidth(toggleAction);
|
|
251
292
|
const titleWidth = Math.max(0, width - actionsWidth - 1);
|
|
252
|
-
const
|
|
253
|
-
const gap = " ".repeat(Math.max(
|
|
254
|
-
const copyStart = leftPadWidth + 1 + visibleWidth(
|
|
293
|
+
const context = truncateToWidth(this.theme.fg("dim", suffix.replace(/^\s*·\s*/, "")), titleWidth, "…");
|
|
294
|
+
const gap = " ".repeat(Math.max(0, width - visibleWidth(context) - actionsWidth));
|
|
295
|
+
const copyStart = leftPadWidth + 1 + visibleWidth(context) + gap.length;
|
|
255
296
|
this.copyHitRegion = { start: copyStart, end: copyStart + visibleWidth(copyAction) };
|
|
256
|
-
const
|
|
297
|
+
const sessionStart = this.copyHitRegion.end + 1;
|
|
298
|
+
this.sessionHitRegion = { start: sessionStart, end: sessionStart + visibleWidth(sessionAction) };
|
|
299
|
+
const openStart = this.sessionHitRegion.end + 1;
|
|
257
300
|
this.openHitRegion = { start: openStart, end: openStart + visibleWidth(openAction) };
|
|
258
301
|
const toggleStart = this.openHitRegion.end + 1;
|
|
259
302
|
this.toggleHitRegion = { start: toggleStart, end: toggleStart + visibleWidth(toggleAction) };
|
|
260
|
-
return `${
|
|
303
|
+
return `${context}${gap}${copyAction} ${sessionAction} ${openAction} ${toggleAction}`;
|
|
261
304
|
}
|
|
262
305
|
isHit(x, region) {
|
|
263
306
|
return region !== undefined && x >= region.start && x < region.end;
|
|
264
307
|
}
|
|
265
|
-
async
|
|
308
|
+
async openLinkedDelegate(link) {
|
|
309
|
+
if (this.openingDelegate)
|
|
310
|
+
return;
|
|
311
|
+
this.openingDelegate = true;
|
|
312
|
+
try {
|
|
313
|
+
await focusPane(link.paneId, this.cwd);
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
const reason = error instanceof Error ? safeSingleLine(error.message) : "Unknown error.";
|
|
317
|
+
if (!this.disposed)
|
|
318
|
+
this.notify(`Could not open delegate. ${reason}`, "error");
|
|
319
|
+
}
|
|
320
|
+
finally {
|
|
321
|
+
this.openingDelegate = false;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
async openInCursor(session = false) {
|
|
266
325
|
if (this.opening)
|
|
267
326
|
return;
|
|
268
327
|
this.opening = true;
|
|
269
328
|
this.tui.requestRender();
|
|
270
329
|
try {
|
|
271
|
-
|
|
330
|
+
if (session)
|
|
331
|
+
await openSession(this.cwd, this.sessionId);
|
|
332
|
+
else
|
|
333
|
+
await openRepository(this.cwd);
|
|
272
334
|
if (!this.disposed)
|
|
273
|
-
this.notify("Opened repository in Cursor.", "info");
|
|
335
|
+
this.notify(session ? "Opened session artifacts in Cursor." : "Opened repository in Cursor.", "info");
|
|
274
336
|
}
|
|
275
337
|
catch (error) {
|
|
276
338
|
const reason = error instanceof Error ? ` ${safeSingleLine(error.message)}` : "";
|
|
277
339
|
if (!this.disposed)
|
|
278
|
-
this.notify(`Could not open Cursor. Check that cursor is installed on PATH.${reason}`, "error");
|
|
340
|
+
this.notify(session ? `Could not open session artifacts in Cursor.${reason}` : `Could not open Cursor. Check that cursor is installed on PATH.${reason}`, "error");
|
|
279
341
|
}
|
|
280
342
|
finally {
|
|
281
343
|
this.opening = false;
|
|
@@ -321,9 +383,22 @@ class TasksPanel {
|
|
|
321
383
|
return Math.max(0, this.contentLength - this.pageSize);
|
|
322
384
|
}
|
|
323
385
|
}
|
|
324
|
-
export function
|
|
386
|
+
export function recordId(id, theme) {
|
|
387
|
+
return theme.fg(id.startsWith("W") ? "accent" : "syntaxType", `[${safeSingleLine(id)}]`);
|
|
388
|
+
}
|
|
389
|
+
export function ownerBadge(taskInfo, theme, linked = false) {
|
|
390
|
+
const owner = taskOwner(taskInfo);
|
|
391
|
+
const label = owner === "delegate" && linked ? theme.underline(`[${owner}]`) : `[${owner}]`;
|
|
392
|
+
return theme.fg(owner === "self" ? "success" : owner === "delegate" ? "warning" : "muted", label);
|
|
393
|
+
}
|
|
394
|
+
export function delegateHitRegion(link, start, line, y, leftPad = 0) {
|
|
395
|
+
if (!link || stripVTControlCharacters(sliceByColumn(line, start, 10)) !== "[delegate]")
|
|
396
|
+
return undefined;
|
|
397
|
+
return { start: leftPad + 1 + start, end: leftPad + 1 + start + 10, y, link };
|
|
398
|
+
}
|
|
399
|
+
export function progressName(name, completion, width, prefix = "") {
|
|
325
400
|
const suffix = ` · ${formatCompletion(completion)}`;
|
|
326
|
-
return `${truncateToWidth(safeSingleLine(name)
|
|
401
|
+
return `${truncateToWidth(`${prefix}${safeSingleLine(name)}`, Math.max(0, width - visibleWidth(suffix)), "…")}${suffix}`;
|
|
327
402
|
}
|
|
328
403
|
function progressColumn(content, completion, width, theme) {
|
|
329
404
|
const contentWidth = width - PROGRESS_COLUMN_WIDTH;
|
|
@@ -332,25 +407,14 @@ function progressColumn(content, completion, width, theme) {
|
|
|
332
407
|
const value = theme.fg(completion === null ? "muted" : "accent", formatCompletion(completion).padStart(PROGRESS_VALUE_WIDTH));
|
|
333
408
|
return `${left}${padding}${theme.fg("border", " │ ")}${value}`;
|
|
334
409
|
}
|
|
335
|
-
function workSummaryLine(
|
|
410
|
+
function workSummaryLine(name, count, width, theme, workId) {
|
|
336
411
|
const right = theme.fg("dim", count);
|
|
337
412
|
const leftWidth = Math.max(0, width - visibleWidth(right) - 1);
|
|
338
|
-
const left = `${
|
|
413
|
+
const left = `${recordId(workId, theme)} ${theme.fg("text", safeSingleLine(name))}`;
|
|
339
414
|
const shownLeft = truncateToWidth(left, leftWidth, "…");
|
|
340
415
|
const gap = " ".repeat(Math.max(1, width - visibleWidth(shownLeft) - visibleWidth(right)));
|
|
341
416
|
return `${shownLeft}${gap}${right}`;
|
|
342
417
|
}
|
|
343
|
-
export function workIcon(status, theme) {
|
|
344
|
-
if (status === "completed")
|
|
345
|
-
return theme.fg("success", "✓");
|
|
346
|
-
if (status === "active")
|
|
347
|
-
return theme.fg("accent", "▶");
|
|
348
|
-
if (status === "blocked")
|
|
349
|
-
return theme.fg("warning", "!");
|
|
350
|
-
if (status === "cancelled")
|
|
351
|
-
return theme.fg("error", "×");
|
|
352
|
-
return theme.fg("muted", "○");
|
|
353
|
-
}
|
|
354
418
|
export function todoIcon(status, theme) {
|
|
355
419
|
if (status === "completed")
|
|
356
420
|
return theme.fg("success", "✓");
|
|
@@ -21,6 +21,8 @@ export declare class WorksDashboard implements Component, Focusable {
|
|
|
21
21
|
private messageColor;
|
|
22
22
|
private copying;
|
|
23
23
|
private opening;
|
|
24
|
+
private openingDelegate;
|
|
25
|
+
private delegateHits;
|
|
24
26
|
private minimized;
|
|
25
27
|
private readonly unsubscribeGit;
|
|
26
28
|
private openHitRegion;
|
|
@@ -43,6 +45,7 @@ export declare class WorksDashboard implements Component, Focusable {
|
|
|
43
45
|
private renderHeader;
|
|
44
46
|
private toggleMinimized;
|
|
45
47
|
private isHit;
|
|
48
|
+
private openLinkedDelegate;
|
|
46
49
|
private openInCursor;
|
|
47
50
|
private copyAllAsMarkdown;
|
|
48
51
|
private renderFooter;
|