pi-long-task 0.1.1 → 0.1.3

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 CHANGED
@@ -46,6 +46,18 @@ After installing, start `pi` in your target project and ask it to use the `pi_lo
46
46
 
47
47
  ## Usage
48
48
 
49
+ Use natural language:
50
+
51
+ ```text
52
+ Run a long task without commits to add tests for the parser and fix any failures.
53
+ ```
54
+
55
+ ```text
56
+ Run a long task with commits to implement the TODOs in @TODO.md.
57
+ ```
58
+
59
+ You can also call the tool explicitly.
60
+
49
61
  Run without commits:
50
62
 
51
63
  ```text
@@ -78,6 +90,8 @@ The tool has two inputs:
78
90
  - `inputText` is the request or TODO markdown to work on.
79
91
  - `commit` controls whether Pi Long Task may create git commits.
80
92
 
93
+ For natural-language requests, Pi Long Task routes phrases like "run a long task with commits" to the tool with commits enabled. If you ask for a long task without mentioning commits, commits stay disabled.
94
+
81
95
  No other public options are required.
82
96
 
83
97
  ## Commits and files
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-long-task",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "Pi extension for breaking down and running long coding tasks safely.",
6
6
  "keywords": [
@@ -49,6 +49,19 @@ export type CoordinatorProgressPhase =
49
49
  | "task_failed"
50
50
  | "complete";
51
51
 
52
+ export type CoordinatorProgressItemStatus = "empty" | "in_progress" | "done";
53
+
54
+ export interface CoordinatorProgressTask {
55
+ taskId: string;
56
+ title: string;
57
+ status: CoordinatorProgressItemStatus;
58
+ }
59
+
60
+ export interface CoordinatorProgressSubtask {
61
+ text: string;
62
+ status: CoordinatorProgressItemStatus;
63
+ }
64
+
52
65
  export interface CoordinatorProgressUpdate {
53
66
  message: string;
54
67
  phase: CoordinatorProgressPhase;
@@ -66,6 +79,8 @@ export interface CoordinatorProgressUpdate {
66
79
  workerEventType?: string;
67
80
  isError?: boolean;
68
81
  totalTasks?: number;
82
+ currentTask?: CoordinatorProgressTask;
83
+ subtasks?: CoordinatorProgressSubtask[];
69
84
  }
70
85
 
71
86
  export type CoordinatorProgressHandler = (update: CoordinatorProgressUpdate) => void;
@@ -189,6 +204,7 @@ export async function runCoordinator(options: RunCoordinatorOptions): Promise<Co
189
204
  taskId: nextTask.taskId,
190
205
  title: nextTask.title,
191
206
  attempt,
207
+ ...currentTaskProgress(nextTask, "in_progress"),
192
208
  },
193
209
  );
194
210
  const preExistingDirtyPaths = options.commit
@@ -441,9 +457,40 @@ function emitProgress(
441
457
  });
442
458
  }
443
459
 
460
+ function currentTaskProgress(
461
+ task: Pick<Task, "taskId" | "title" | "statusItems">,
462
+ status: CoordinatorProgressItemStatus,
463
+ ): Pick<CoordinatorProgressUpdate, "currentTask" | "subtasks"> {
464
+ return {
465
+ currentTask: {
466
+ taskId: task.taskId,
467
+ title: task.title,
468
+ status,
469
+ },
470
+ subtasks: subtaskProgress(task, status),
471
+ };
472
+ }
473
+
474
+ function subtaskProgress(
475
+ task: Pick<Task, "statusItems">,
476
+ taskStatus: CoordinatorProgressItemStatus,
477
+ ): CoordinatorProgressSubtask[] {
478
+ let markedInProgress = false;
479
+ return task.statusItems.map((item) => {
480
+ if (item.done || taskStatus === "done") {
481
+ return { text: item.text, status: "done" };
482
+ }
483
+ if (taskStatus === "in_progress" && !markedInProgress) {
484
+ markedInProgress = true;
485
+ return { text: item.text, status: "in_progress" };
486
+ }
487
+ return { text: item.text, status: "empty" };
488
+ });
489
+ }
490
+
444
491
  function emitWorkerEventProgress(
445
492
  runtime: RuntimeOptions,
446
- task: Pick<Task, "taskId" | "title">,
493
+ task: Pick<Task, "taskId" | "title" | "statusItems">,
447
494
  attempt: number,
448
495
  event: { type: string; toolName?: string; isError?: boolean },
449
496
  ): void {
@@ -460,6 +507,7 @@ function emitWorkerEventProgress(
460
507
  toolName: event.toolName,
461
508
  workerEventType: event.type,
462
509
  isError: event.isError,
510
+ ...currentTaskProgress(task, "in_progress"),
463
511
  };
464
512
  if (event.isError) {
465
513
  update.status = "failed";
@@ -469,7 +517,7 @@ function emitWorkerEventProgress(
469
517
 
470
518
  function emitTaskOutcomeProgress(
471
519
  runtime: RuntimeOptions,
472
- task: Pick<Task, "taskId" | "title">,
520
+ task: Pick<Task, "taskId" | "title" | "statusItems">,
473
521
  outcome: SessionOutcome,
474
522
  commitHash: string | undefined,
475
523
  commitError: string | undefined,
@@ -494,6 +542,7 @@ function emitTaskOutcomeProgress(
494
542
  title: task.title,
495
543
  attempt: outcome.attempt,
496
544
  status: outcome.reportedStatus,
545
+ ...currentTaskProgress(task, outcome.done ? "done" : "in_progress"),
497
546
  };
498
547
  if (commitHash) {
499
548
  update.commitHash = commitHash;
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
 
3
3
  import { runCoordinator, type CoordinatorProgressUpdate, type CoordinatorResult } from "./coordinator.ts";
4
+ import { longTaskInputTransform } from "./input_router.ts";
4
5
  import { renderLongTaskToolCall, renderLongTaskToolResult } from "./render.ts";
5
6
  import { PiLongTaskParams } from "./types.ts";
6
7
 
@@ -22,10 +23,24 @@ function toolDetails(result: CoordinatorResult) {
22
23
  }
23
24
 
24
25
  export default function registerPiLongTaskExtension(pi: ExtensionAPI) {
26
+ pi.on("input", (event) => {
27
+ if (event.source === "extension") {
28
+ return { action: "continue" as const };
29
+ }
30
+
31
+ const transformed = longTaskInputTransform(event.text);
32
+ if (!transformed) {
33
+ return { action: "continue" as const };
34
+ }
35
+
36
+ return { action: "transform" as const, text: transformed };
37
+ });
38
+
25
39
  pi.registerTool({
26
40
  name: "pi_long_task",
27
41
  label: "Pi Long Task",
28
- description: "Break down and run long coding tasks from a request or TODO plan.",
42
+ description:
43
+ "Run long or multi-step coding tasks from a request or TODO plan. Use this when the user asks to run/start/handle a long task; set commit true only when they ask for commits or committing as work progresses.",
29
44
  parameters: PiLongTaskParams,
30
45
  renderCall: renderLongTaskToolCall,
31
46
  renderResult: renderLongTaskToolResult,
@@ -0,0 +1,57 @@
1
+ const LONG_TASK_RE = /\b(?:long[-\s]?task|longtask|large[-\s]?task|big[-\s]?task|multi[-\s]?step(?:\s+task)?)\b/i;
2
+ const DIRECT_LONG_TASK_REQUEST_RE =
3
+ /\b(?:run|start|do|handle|execute|launch|kick\s+off|use)\s+(?:a\s+|the\s+)?(?:long[-\s]?task|longtask|large[-\s]?task|big[-\s]?task|multi[-\s]?step(?:\s+task)?)\b/i;
4
+ const WANT_LONG_TASK_RE =
5
+ /\b(?:please|can\s+you|could\s+you|i\s+want|i\s+need|i'd\s+like|i\s+would\s+like|let's|lets)\b[\s\S]*\b(?:long[-\s]?task|longtask|large[-\s]?task|big[-\s]?task|multi[-\s]?step(?:\s+task)?)\b/i;
6
+ const NEGATED_LONG_TASK_RE =
7
+ /\b(?:do\s+not|don't|dont|never)\s+(?:run|start|do|handle|execute|launch|kick\s+off|use)\s+(?:a\s+|the\s+)?(?:long[-\s]?task|longtask|large[-\s]?task|big[-\s]?task|multi[-\s]?step(?:\s+task)?)\b/i;
8
+ const INFORMATION_QUESTION_RE = /^\s*(?:how|what|why|when|where|who)\b/i;
9
+ const EXPLICIT_TOOL_RE = /\bpi_long_task\b/i;
10
+
11
+ const COMMIT_FALSE_RE =
12
+ /\b(?:without|no|disable|disabled|off)\s+commits?\b|\bcommits?\s*(?:false|off|disabled)\b|\bcommit\s*:\s*(?:false|off|no)\b|\b(?:do\s+not|don't|dont)\s+commit\b/i;
13
+ const COMMIT_TRUE_RE =
14
+ /\bwith\s+commits?\b|\bcommits?\s*(?:true|on|enabled)\b|\bcommit\s*:\s*(?:true|on|yes)\b|\bcommit(?:ting)?\s+as\s+(?:you|we)\s+go\b|\b(?:make|create|include|allow|enable)\s+commits?\b/i;
15
+
16
+ export function longTaskInputTransform(text: string): string | undefined {
17
+ if (!isNaturalLanguageLongTaskRequest(text)) {
18
+ return undefined;
19
+ }
20
+
21
+ const commit = inferCommitSetting(text) ?? false;
22
+ return buildLongTaskToolPrompt(text, commit);
23
+ }
24
+
25
+ export function isNaturalLanguageLongTaskRequest(text: string): boolean {
26
+ const trimmed = text.trim();
27
+ if (!trimmed || trimmed.startsWith("/") || EXPLICIT_TOOL_RE.test(trimmed)) {
28
+ return false;
29
+ }
30
+ if (!LONG_TASK_RE.test(trimmed) || INFORMATION_QUESTION_RE.test(trimmed) || NEGATED_LONG_TASK_RE.test(trimmed)) {
31
+ return false;
32
+ }
33
+ return DIRECT_LONG_TASK_REQUEST_RE.test(trimmed) || WANT_LONG_TASK_RE.test(trimmed);
34
+ }
35
+
36
+ export function inferCommitSetting(text: string): boolean | undefined {
37
+ if (COMMIT_FALSE_RE.test(text)) {
38
+ return false;
39
+ }
40
+ if (COMMIT_TRUE_RE.test(text)) {
41
+ return true;
42
+ }
43
+ return undefined;
44
+ }
45
+
46
+ function buildLongTaskToolPrompt(originalText: string, commit: boolean): string {
47
+ return [
48
+ "Use the pi_long_task tool for this request.",
49
+ `Set commit to ${commit ? "true" : "false"}.`,
50
+ "Set inputText to the user's original request below. Do not perform the work directly outside pi_long_task.",
51
+ "",
52
+ "Original request:",
53
+ "```text",
54
+ originalText.trim(),
55
+ "```",
56
+ ].join("\n");
57
+ }
package/src/render.ts CHANGED
@@ -22,6 +22,19 @@ export interface CoordinatorToolRenderDetails extends CoordinatorResultForRender
22
22
  runId?: string;
23
23
  }
24
24
 
25
+ type ProgressItemStatus = "empty" | "in_progress" | "done";
26
+
27
+ interface ProgressTaskRenderDetails {
28
+ taskId: string;
29
+ title: string;
30
+ status: ProgressItemStatus;
31
+ }
32
+
33
+ interface ProgressSubtaskRenderDetails {
34
+ text: string;
35
+ status: ProgressItemStatus;
36
+ }
37
+
25
38
  export function formatCoordinatorResultMessage(result: CoordinatorResultForRendering): string {
26
39
  const resultPath = result.resultPath ?? result.taskResultPath ?? "unknown";
27
40
  const remaining = result.remainingTasks ?? [];
@@ -90,7 +103,26 @@ function renderLongTaskProgress(details: Record<string, unknown> | undefined, fa
90
103
  const phase = stringValue(details?.phase);
91
104
  const toolName = stringValue(details?.toolName);
92
105
  const prefix = phase === "worker_tool" && toolName ? `worker ${toolName}` : phase || "progress";
93
- return `${theme.fg("accent", "●")} ${theme.fg("muted", prefix)} ${message}`;
106
+ const currentTask = progressTaskDetails(details?.currentTask);
107
+ if (!currentTask) {
108
+ return `${theme.fg("accent", "●")} ${theme.fg("muted", prefix)} ${message}`;
109
+ }
110
+
111
+ const taskLabel = `TODO ${currentTask.taskId} — ${currentTask.title}`;
112
+ const lines = [
113
+ `${progressBubble(currentTask.status, theme)} ${theme.fg("muted", prefix)} ${theme.fg(progressTextColor(currentTask.status), taskLabel)}`,
114
+ ];
115
+ if (message && !message.includes(taskLabel)) {
116
+ lines.push(` ${theme.fg("dim", message)}`);
117
+ }
118
+
119
+ for (const subtask of progressSubtaskDetails(details?.subtasks)) {
120
+ lines.push(
121
+ ` ${progressBubble(subtask.status, theme)} ${theme.fg(progressTextColor(subtask.status), subtask.text)}`,
122
+ );
123
+ }
124
+
125
+ return lines.join("\n");
94
126
  }
95
127
 
96
128
  function renderLongTaskSummary(details: CoordinatorToolRenderDetails, expanded: boolean, theme: Theme): string {
@@ -141,6 +173,50 @@ function renderLongTaskSummary(details: CoordinatorToolRenderDetails, expanded:
141
173
  return lines.join("\n");
142
174
  }
143
175
 
176
+ function progressTaskDetails(value: unknown): ProgressTaskRenderDetails | undefined {
177
+ const record = recordOrUndefined(value);
178
+ const taskId = stringValue(record?.taskId);
179
+ const title = stringValue(record?.title);
180
+ const status = progressItemStatus(record?.status);
181
+ if (!taskId || !title || !status) {
182
+ return undefined;
183
+ }
184
+ return { taskId, title, status };
185
+ }
186
+
187
+ function progressSubtaskDetails(value: unknown): ProgressSubtaskRenderDetails[] {
188
+ if (!Array.isArray(value)) {
189
+ return [];
190
+ }
191
+ return value.flatMap((item) => {
192
+ const record = recordOrUndefined(item);
193
+ const text = stringValue(record?.text);
194
+ const status = progressItemStatus(record?.status);
195
+ if (!text || !status) {
196
+ return [];
197
+ }
198
+ return [{ text, status }];
199
+ });
200
+ }
201
+
202
+ function progressItemStatus(value: unknown): ProgressItemStatus | undefined {
203
+ return value === "empty" || value === "in_progress" || value === "done" ? value : undefined;
204
+ }
205
+
206
+ function progressBubble(status: ProgressItemStatus, theme: Theme): string {
207
+ return status === "empty" ? theme.fg("dim", "○") : theme.fg(progressTextColor(status), "●");
208
+ }
209
+
210
+ function progressTextColor(status: ProgressItemStatus): "success" | "warning" | "dim" {
211
+ if (status === "done") {
212
+ return "success";
213
+ }
214
+ if (status === "in_progress") {
215
+ return "warning";
216
+ }
217
+ return "dim";
218
+ }
219
+
144
220
  function longTaskDetails(details: Record<string, unknown> | undefined): CoordinatorToolRenderDetails | undefined {
145
221
  if (!details) {
146
222
  return undefined;
@@ -1,3 +1,8 @@
1
+ export interface TaskStatusItem {
2
+ text: string;
3
+ done: boolean;
4
+ }
5
+
1
6
  export interface Task {
2
7
  taskId: string;
3
8
  title: string;
@@ -7,6 +12,7 @@ export interface Task {
7
12
  done: boolean;
8
13
  progressDone?: boolean;
9
14
  statusCheckboxes: boolean[];
15
+ statusItems: TaskStatusItem[];
10
16
  }
11
17
 
12
18
  export class TodoParseError extends Error {
@@ -78,10 +84,10 @@ function findProgressDone(lines: string[], taskId: string): boolean | undefined
78
84
  return undefined;
79
85
  }
80
86
 
81
- function findStatusCheckboxes(lines: string[], startIdx: number, endIdx: number): boolean[] {
87
+ function findStatusItems(lines: string[], startIdx: number, endIdx: number): TaskStatusItem[] {
82
88
  let inStatus = false;
83
89
  let seenCheckbox = false;
84
- const checkboxes: boolean[] = [];
90
+ const items: TaskStatusItem[] = [];
85
91
 
86
92
  for (let idx = startIdx; idx < endIdx; idx += 1) {
87
93
  const stripped = lines[idx].trim();
@@ -97,7 +103,10 @@ function findStatusCheckboxes(lines: string[], startIdx: number, endIdx: number)
97
103
  const checkbox = CHECKBOX_RE.exec(stripLineBreaks(lines[idx]));
98
104
  if (checkbox) {
99
105
  seenCheckbox = true;
100
- checkboxes.push(checkbox[2].toLowerCase() === "x");
106
+ items.push({
107
+ text: checkbox[3].replace(/^\]\s*/, "").trim(),
108
+ done: checkbox[2].toLowerCase() === "x",
109
+ });
101
110
  continue;
102
111
  }
103
112
 
@@ -110,7 +119,7 @@ function findStatusCheckboxes(lines: string[], startIdx: number, endIdx: number)
110
119
  }
111
120
  }
112
121
 
113
- return checkboxes;
122
+ return items;
114
123
  }
115
124
 
116
125
  function markStatusBlockDone(lines: string[], startIdx: number, endIdx: number): void {
@@ -161,7 +170,8 @@ export function parseTasks(markdown: string): Task[] {
161
170
  const endIdx = pos + 1 < headings.length ? headings[pos + 1].startIdx : lines.length;
162
171
  const section = `${lines.slice(heading.startIdx, endIdx).join("").trimEnd()}\n`;
163
172
  const progressDone = findProgressDone(lines, heading.taskId);
164
- const statusCheckboxes = findStatusCheckboxes(lines, heading.startIdx, endIdx);
173
+ const statusItems = findStatusItems(lines, heading.startIdx, endIdx);
174
+ const statusCheckboxes = statusItems.map((item) => item.done);
165
175
  const done = progressDone ?? (statusCheckboxes.length > 0 ? statusCheckboxes.every(Boolean) : false);
166
176
 
167
177
  const task: Task = {
@@ -172,6 +182,7 @@ export function parseTasks(markdown: string): Task[] {
172
182
  endLine: endIdx,
173
183
  done,
174
184
  statusCheckboxes,
185
+ statusItems,
175
186
  };
176
187
  if (progressDone !== undefined) {
177
188
  task.progressDone = progressDone;
package/src/types.ts CHANGED
@@ -5,8 +5,13 @@ import type { SessionOutcome } from "./worker_session.ts";
5
5
 
6
6
  export const PiLongTaskParams = Type.Object(
7
7
  {
8
- inputText: Type.String({ description: "TODO file content or long-task instructions to process." }),
9
- commit: Type.Boolean({ description: "Whether Pi Long Task may commit completed worker changes." }),
8
+ inputText: Type.String({
9
+ description: "TODO file content or the user's long-task instructions to process.",
10
+ }),
11
+ commit: Type.Boolean({
12
+ description:
13
+ "Whether Pi Long Task may commit completed worker changes. Use true when the user asks for commits or committing as work progresses; otherwise use false.",
14
+ }),
10
15
  },
11
16
  { additionalProperties: false },
12
17
  );