pi-orchestrator-config 4.2.0 → 4.3.2

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.
Files changed (100) hide show
  1. package/README.md +76 -67
  2. package/agents/code-reviewer-docs.md +11 -1
  3. package/agents/code-reviewer-guidelines.md +11 -1
  4. package/agents/code-reviewer-quality.md +11 -1
  5. package/agents/code-reviewer-security.md +11 -1
  6. package/agents/code-reviewer-spec.md +11 -1
  7. package/agents/git-expert.md +42 -3
  8. package/agents/github-expert.md +11 -0
  9. package/extensions/acpx-provider/runtime-models.ts +18 -6
  10. package/extensions/cli-provider/agents/claude.ts +3 -2
  11. package/extensions/cli-provider/agents/cursor.ts +3 -5
  12. package/extensions/cli-provider/agents/gemini.ts +3 -2
  13. package/extensions/cli-provider/discover.ts +7 -7
  14. package/extensions/cli-provider/index.ts +5 -0
  15. package/extensions/cli-provider/runtime-models.ts +18 -6
  16. package/extensions/cli-provider/session-reaper.ts +5 -7
  17. package/extensions/cli-provider/sessions.ts +4 -0
  18. package/extensions/cli-provider/shared/discover-cache.ts +17 -176
  19. package/extensions/coms/coms-p2p.ts +1719 -423
  20. package/extensions/coms/coms-shared.ts +261 -39
  21. package/extensions/coms/coms-wrapper.ts +100 -62
  22. package/extensions/coms/index.ts +8 -4
  23. package/extensions/coms/mixed-turn.ts +26 -0
  24. package/extensions/coms/probe-socket.ts +42 -0
  25. package/extensions/coms/themeMap.ts +0 -1
  26. package/extensions/image-gen/image-gen.ts +19 -1
  27. package/extensions/orchestrator/async-agents.ts +563 -102
  28. package/extensions/orchestrator/async-capability.ts +8 -8
  29. package/extensions/orchestrator/cron.ts +15 -9
  30. package/extensions/orchestrator/dreaming.ts +32 -25
  31. package/extensions/orchestrator/enforcement-helpers.ts +459 -17
  32. package/extensions/orchestrator/enforcement-rules.ts +5 -4
  33. package/extensions/orchestrator/enforcement.ts +80 -27
  34. package/extensions/orchestrator/extended-autocomplete.ts +7 -0
  35. package/extensions/orchestrator/git-helpers.ts +2 -2
  36. package/extensions/orchestrator/index.ts +78 -10
  37. package/extensions/orchestrator/markdown-transformer.ts +313 -0
  38. package/extensions/orchestrator/memory-embeddings.ts +36 -34
  39. package/extensions/orchestrator/memory-provenance.ts +29 -25
  40. package/extensions/orchestrator/memory-scoring.ts +23 -18
  41. package/extensions/orchestrator/memory-tools.ts +10 -3
  42. package/extensions/orchestrator/overlay-dashboard.ts +17 -5
  43. package/extensions/orchestrator/parse-model-override.ts +29 -0
  44. package/extensions/orchestrator/pi-config-review-state.ts +57 -33
  45. package/extensions/orchestrator/project-settings.ts +333 -127
  46. package/extensions/orchestrator/resolve-agent-model.ts +24 -13
  47. package/extensions/orchestrator/review-porcelain.ts +4 -0
  48. package/extensions/orchestrator/review-ui.ts +63 -15
  49. package/extensions/orchestrator/rule-placeholders.ts +411 -2
  50. package/extensions/orchestrator/rules.ts +80 -132
  51. package/extensions/orchestrator/settings-tui-helpers.ts +380 -0
  52. package/extensions/orchestrator/settings-tui-submenus.ts +647 -0
  53. package/extensions/orchestrator/settings-tui.ts +636 -0
  54. package/extensions/orchestrator/state-jsonl.ts +431 -0
  55. package/extensions/orchestrator/subagent-tool.ts +157 -59
  56. package/extensions/orchestrator/sync-limit.ts +23 -0
  57. package/extensions/orchestrator/task-lifecycle.ts +77 -67
  58. package/extensions/orchestrator/utils.ts +8 -5
  59. package/extensions/pidash/pidash.ts +193 -156
  60. package/extensions/pidiff/pidiff.ts +96 -38
  61. package/extensions/pidiff/spawn-lock.ts +62 -0
  62. package/extensions/pitasks/index.ts +430 -0
  63. package/extensions/pitasks/reminders.ts +37 -0
  64. package/extensions/pitasks/task-store.ts +467 -0
  65. package/extensions/pitasks/task-tools.ts +375 -0
  66. package/extensions/pitasks/task-widget.ts +181 -0
  67. package/extensions/pitasks/types.ts +38 -0
  68. package/extensions/providers/acpx-driver.ts +12 -2
  69. package/extensions/providers/built-in-drivers.ts +6 -6
  70. package/extensions/providers/claude-driver.ts +1 -1
  71. package/extensions/providers/cursor-cli-driver.ts +1 -1
  72. package/extensions/providers/gemini-driver.ts +1 -1
  73. package/extensions/providers/index.ts +144 -26
  74. package/extensions/providers/initialized-guard.ts +27 -0
  75. package/extensions/providers/restore-default-model.ts +596 -0
  76. package/extensions/providers/session-shutdown.ts +39 -0
  77. package/extensions/shared/coms-active.ts +23 -0
  78. package/extensions/shared/create-runtime-provider.ts +2 -0
  79. package/extensions/shared/daemon-manager.ts +0 -8
  80. package/extensions/shared/file-logger.ts +132 -25
  81. package/extensions/shared/logger.ts +50 -0
  82. package/extensions/shared/models-dev.ts +421 -0
  83. package/extensions/shared/oneshot.ts +116 -0
  84. package/extensions/shared/resolve-binary.ts +191 -0
  85. package/extensions/shared/types.ts +3 -0
  86. package/package.json +9 -3
  87. package/prompts/coderabbit-rate-limit.md +2 -0
  88. package/rules/00-orchestrator-core.md +3 -0
  89. package/rules/10-agent-routing.md +12 -1
  90. package/rules/20-code-review-loop.md +52 -25
  91. package/rules/30-prompt-templates.md +4 -0
  92. package/rules/35-memory.md +3 -3
  93. package/rules/40-critical-rules.md +3 -0
  94. package/rules/55-coms-protocol.md +84 -18
  95. package/rules/60-task-tracking.md +2 -0
  96. package/settings-keys.json +563 -0
  97. package/templates/coms-feature-manager-prompt.md +4 -6
  98. package/extensions/coms/coms-net-server.ts +0 -1642
  99. package/extensions/coms/coms-net-wrapper.ts +0 -521
  100. package/extensions/coms/coms-net.ts +0 -1589
@@ -0,0 +1,375 @@
1
+ /**
2
+ * task-tools.ts — Task management tool registrations.
3
+ * Copied from @tintinweb/pi-tasks (MIT license).
4
+ * Removed: TaskExecute, TaskOutput, TaskStop (handled by async-agents.ts).
5
+ */
6
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
7
+ import { Type } from "typebox";
8
+ import type { TaskStore } from "./task-store.js";
9
+ import type { TaskWidget } from "./task-widget.js";
10
+
11
+ function textResult(msg: string) {
12
+ return { content: [{ type: "text" as const, text: msg }], details: undefined };
13
+ }
14
+
15
+ export function registerTaskTools(
16
+ pi: ExtensionAPI,
17
+ getStore: () => TaskStore,
18
+ widget: TaskWidget,
19
+ ): void {
20
+ // ── TaskCreate ──
21
+ pi.registerTool({
22
+ name: "TaskCreate",
23
+ label: "TaskCreate",
24
+ description: `Use this tool to create a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
25
+ It also helps the user understand the progress of the task and overall progress of their requests.
26
+
27
+ ## When to Use This Tool
28
+
29
+ Use this tool proactively in these scenarios:
30
+
31
+ - Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
32
+ - Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
33
+ - Plan mode - When using plan mode, create a task list to track the work
34
+ - User explicitly requests todo list - When the user directly asks you to use the todo list
35
+ - User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
36
+ - After receiving new instructions - Immediately capture user requirements as tasks
37
+ - When you start working on a task - Mark it as in_progress BEFORE beginning work
38
+ - After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
39
+
40
+ ## When NOT to Use This Tool
41
+
42
+ Skip using this tool when:
43
+ - There is only a single, straightforward task
44
+ - The task is trivial and tracking it provides no organizational benefit
45
+ - The task can be completed in less than 3 trivial steps
46
+ - The task is purely conversational or informational
47
+
48
+ NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
49
+
50
+ ## Task Fields
51
+
52
+ - **subject**: A brief, actionable title in imperative form (e.g., "Fix authentication bug in login flow")
53
+ - **description**: Detailed description of what needs to be done, including context and acceptance criteria
54
+ - **activeForm** (optional): Present continuous form shown in the spinner when the task is in_progress (e.g., "Fixing authentication bug"). If omitted, the spinner shows the subject instead.
55
+
56
+ All tasks are created with status \`pending\`.
57
+
58
+ ## Tips
59
+
60
+ - Create tasks with clear, specific subjects that describe the outcome
61
+ - Include enough detail in the description for another agent to understand and complete the task
62
+ - After creating tasks, use TaskUpdate to set up dependencies (blocks/blockedBy) if needed
63
+ - Check TaskList first to avoid creating duplicate tasks
64
+ - Include \`agentType\` (e.g., "general-purpose", "Explore") to mark tasks for subagent execution via TaskExecute`,
65
+ promptGuidelines: [
66
+ "When working on complex multi-step tasks, use TaskCreate to track progress and TaskUpdate to update status.",
67
+ "Mark tasks as in_progress before starting work and completed when done.",
68
+ "Use TaskList to check for available work after completing a task.",
69
+ ],
70
+ parameters: Type.Object({
71
+ subject: Type.String({ description: "A brief title for the task" }),
72
+ description: Type.String({ description: "A detailed description of what needs to be done" }),
73
+ activeForm: Type.Optional(Type.String({ description: "Present continuous form shown in spinner when in_progress (e.g., 'Running tests')" })),
74
+ agentType: Type.Optional(Type.String({ description: "Agent type for subagent execution (e.g., 'general-purpose', 'Explore'). Tasks with agentType can be started via TaskExecute." })),
75
+ metadata: Type.Optional(Type.Record(Type.String(), Type.Any(), { description: "Arbitrary metadata to attach to the task" })),
76
+ }),
77
+ execute(_toolCallId: string, params: any) {
78
+ const store = getStore();
79
+ const meta = params.metadata ?? {};
80
+ if (params.agentType) meta.agentType = params.agentType;
81
+ const createdBy = { type: "local" as const, origin: "system", session: "", project: "" };
82
+ const task = store.create(params.subject, params.description, createdBy, params.activeForm, Object.keys(meta).length > 0 ? meta : undefined);
83
+ widget.update();
84
+ return Promise.resolve(textResult(`Task #${task.id} created successfully: ${task.subject}`));
85
+ },
86
+ });
87
+
88
+ // ── TaskList ──
89
+ pi.registerTool({
90
+ name: "TaskList",
91
+ label: "TaskList",
92
+ description: `Use this tool to list all tasks in the task list.
93
+
94
+ ## When to Use This Tool
95
+
96
+ - To see what tasks are available to work on (status: 'pending', no owner, not blocked)
97
+ - To check overall progress on the project
98
+ - To find tasks that are blocked and need dependencies resolved
99
+ - After completing a task, to check for newly unblocked work or claim the next available task
100
+ - **Prefer working on tasks in ID order** (lowest ID first) when multiple tasks are available, as earlier tasks often set up context for later ones
101
+
102
+ ## Output
103
+
104
+ Returns a summary of each task:
105
+ - **id**: Task identifier (use with TaskGet, TaskUpdate)
106
+ - **subject**: Brief description of the task
107
+ - **status**: 'pending', 'in_progress', or 'completed'
108
+ - **owner**: Agent ID if assigned, empty if available
109
+ - **blockedBy**: List of open task IDs that must be resolved first (tasks with blockedBy cannot be claimed until dependencies resolve)
110
+
111
+ Use TaskGet with a specific task ID to view full details including description and comments.`,
112
+ parameters: Type.Object({}),
113
+ execute() {
114
+ const store = getStore();
115
+ const tasks = store.list();
116
+ if (tasks.length === 0) return Promise.resolve(textResult("No tasks found"));
117
+ const statusOrder: Record<string, number> = { pending: 0, in_progress: 1, completed: 2 };
118
+ const sorted = [...tasks].sort((a, b) => {
119
+ const so = (statusOrder[a.status] ?? 0) - (statusOrder[b.status] ?? 0);
120
+ if (so !== 0) return so;
121
+ return Number(a.id) - Number(b.id);
122
+ });
123
+ const lines = sorted.map(task => {
124
+ let line = `#${task.id} [${task.status}] ${task.subject}`;
125
+ if (task.owner) line += ` (${task.owner})`;
126
+ if (task.blockedBy.length > 0) {
127
+ const openBlockers = task.blockedBy.filter(bid => {
128
+ const blocker = store.get(bid);
129
+ return blocker && blocker.status !== "completed";
130
+ });
131
+ if (openBlockers.length > 0) line += ` [blocked by ${openBlockers.map(id => "#" + id).join(", ")}]`;
132
+ }
133
+ return line;
134
+ });
135
+ return Promise.resolve(textResult(lines.join("\n")));
136
+ },
137
+ });
138
+
139
+ // ── TaskGet ──
140
+ pi.registerTool({
141
+ name: "TaskGet",
142
+ label: "TaskGet",
143
+ description: `Use this tool to retrieve a task by its ID from the task list.
144
+
145
+ ## When to Use This Tool
146
+
147
+ - When you need the full description and context before starting work on a task
148
+ - To understand task dependencies (what it blocks, what blocks it)
149
+ - After being assigned a task, to get complete requirements
150
+
151
+ ## Output
152
+
153
+ Returns full task details:
154
+ - **subject**: Task title
155
+ - **description**: Detailed requirements and context
156
+ - **status**: 'pending', 'in_progress', or 'completed'
157
+ - **blocks**: Tasks waiting on this one to complete
158
+ - **blockedBy**: Tasks that must complete before this one can start
159
+
160
+ ## Tips
161
+
162
+ - After fetching a task, verify its blockedBy list is empty before beginning work.
163
+ - Use TaskList to see all tasks in summary form.`,
164
+ parameters: Type.Object({
165
+ taskId: Type.String({ description: "The ID of the task to retrieve" }),
166
+ }),
167
+ execute(_toolCallId: string, params: any) {
168
+ const store = getStore();
169
+ const task = store.get(params.taskId);
170
+ if (!task) return Promise.resolve(textResult("Task not found"));
171
+ const desc = task.description.replace(/\\n/g, "\n");
172
+ const lines = [`Task #${task.id}: ${task.subject}`, `Status: ${task.status}`];
173
+ if (task.owner) lines.push(`Owner: ${task.owner}`);
174
+ lines.push(`Description: ${desc}`);
175
+ if (task.blockedBy.length > 0) {
176
+ const openBlockers = task.blockedBy.filter(bid => { const b = store.get(bid); return b && b.status !== "completed"; });
177
+ if (openBlockers.length > 0) lines.push(`Blocked by: ${openBlockers.map(id => "#" + id).join(", ")}`);
178
+ }
179
+ if (task.blocks.length > 0) lines.push(`Blocks: ${task.blocks.map(id => "#" + id).join(", ")}`);
180
+ if (task.statusHistory) {
181
+ const sh = task.statusHistory;
182
+ const parts: string[] = [];
183
+ if (sh.pending_at) parts.push(`Created: ${sh.pending_at}`);
184
+ if (sh.in_progress_at) parts.push(`Started: ${sh.in_progress_at}`);
185
+ if (sh.completed_at) parts.push(`Completed: ${sh.completed_at}`);
186
+ if (parts.length > 0) lines.push(`Timeline: ${parts.join(" → ")}`);
187
+ }
188
+ if (task.createdBy) lines.push(`Created by: ${task.createdBy.origin} (${task.createdBy.type})`);
189
+ const metaKeys = Object.keys(task.metadata);
190
+ if (metaKeys.length > 0) lines.push(`Metadata: ${JSON.stringify(task.metadata)}`);
191
+ return Promise.resolve(textResult(lines.join("\n")));
192
+ },
193
+ });
194
+
195
+ // ── TaskUpdate ──
196
+ pi.registerTool({
197
+ name: "TaskUpdate",
198
+ label: "TaskUpdate",
199
+ description: `Use this tool to update a task in the task list.
200
+
201
+ ## When to Use This Tool
202
+
203
+ **Before starting work on a task:**
204
+ - Mark it in_progress BEFORE beginning — do not start work without updating status first
205
+ - After resolving, call TaskList to find your next task
206
+
207
+ **Mark tasks as resolved:**
208
+ - When you have completed the work described in a task
209
+ - When a task is no longer needed or has been superseded
210
+ - IMPORTANT: Always mark your assigned tasks as resolved when you finish them
211
+ - After resolving, call TaskList to find your next task
212
+
213
+ - ONLY mark a task as completed when you have FULLY accomplished it
214
+ - If you encounter errors, blockers, or cannot finish, keep the task as in_progress
215
+ - When blocked, create a new task describing what needs to be resolved
216
+ - Never mark a task as completed if:
217
+ - Tests are failing
218
+ - Implementation is partial
219
+ - You encountered unresolved errors
220
+ - You couldn't find necessary files or dependencies
221
+
222
+ **Delete tasks:**
223
+ - When a task is no longer relevant or was created in error
224
+ - Setting status to \`deleted\` permanently removes the task
225
+
226
+ **Update task details:**
227
+ - When requirements change or become clearer
228
+ - When establishing dependencies between tasks
229
+
230
+ ## Fields You Can Update
231
+
232
+ - **status**: The task status (see Status Workflow below)
233
+ - **subject**: Change the task title (imperative form, e.g., "Run tests")
234
+ - **description**: Change the task description
235
+ - **activeForm**: Present continuous form shown in spinner when in_progress (e.g., "Running tests")
236
+ - **owner**: Change the task owner (agent name)
237
+ - **metadata**: Merge metadata keys into the task (set a key to null to delete it)
238
+ - **addBlocks**: Mark tasks that cannot start until this one completes
239
+ - **addBlockedBy**: Mark tasks that must complete before this one can start
240
+
241
+ ## Status Workflow
242
+
243
+ Status progresses: \`pending\` → \`in_progress\` → \`completed\`
244
+
245
+ Use \`deleted\` to permanently remove a task.
246
+
247
+ ## Staleness
248
+
249
+ Make sure to read a task's latest state using \`TaskGet\` before updating it.
250
+
251
+ ## Examples
252
+
253
+ Mark task as in progress when starting work:
254
+ \`\`\`json
255
+ {"taskId": "1", "status": "in_progress"}
256
+ \`\`\`
257
+
258
+ Mark task as completed after finishing work:
259
+ \`\`\`json
260
+ {"taskId": "1", "status": "completed"}
261
+ \`\`\`
262
+
263
+ Delete a task:
264
+ \`\`\`json
265
+ {"taskId": "1", "status": "deleted"}
266
+ \`\`\`
267
+
268
+ Claim a task by setting owner:
269
+ \`\`\`json
270
+ {"taskId": "1", "owner": "my-name"}
271
+ \`\`\`
272
+
273
+ Set up task dependencies:
274
+ \`\`\`json
275
+ {"taskId": "2", "addBlockedBy": ["1"]}
276
+ \`\`\``,
277
+ parameters: Type.Object({
278
+ taskId: Type.String({ description: "The ID of the task to update" }),
279
+ status: Type.Optional(Type.Unsafe({ type: "string", enum: ["pending", "in_progress", "completed", "deleted"], description: "New status for the task" })),
280
+ subject: Type.Optional(Type.String({ description: "New subject for the task" })),
281
+ description: Type.Optional(Type.String({ description: "New description for the task" })),
282
+ activeForm: Type.Optional(Type.String({ description: "Present continuous form shown in spinner when in_progress" })),
283
+ owner: Type.Optional(Type.String({ description: "New owner for the task" })),
284
+ metadata: Type.Optional(Type.Record(Type.String(), Type.Any(), { description: "Metadata keys to merge into the task. Set a key to null to delete it." })),
285
+ addBlocks: Type.Optional(Type.Array(Type.String(), { description: "Task IDs that this task blocks" })),
286
+ addBlockedBy: Type.Optional(Type.Array(Type.String(), { description: "Task IDs that block this task" })),
287
+ }),
288
+ execute(_toolCallId: string, params: any) {
289
+ const store = getStore();
290
+ const { taskId, ...fields } = params;
291
+ const { task, changedFields, warnings } = store.update(taskId, fields);
292
+ if (changedFields.length === 0 && !task) return Promise.resolve(textResult(`Task #${taskId} not found`));
293
+ if (fields.status === "in_progress") { widget.setActiveTask(taskId); }
294
+ else if (fields.status === "completed" || fields.status === "deleted") {
295
+ widget.setActiveTask(taskId, false);
296
+ }
297
+ widget.update();
298
+ let msg = `Updated task #${taskId} ${changedFields.join(", ")}`;
299
+ if (warnings.length > 0) msg += ` (warning: ${warnings.join("; ")})`;
300
+ return Promise.resolve(textResult(msg));
301
+ },
302
+ });
303
+
304
+ // ── TaskBulkCreate ──
305
+ pi.registerTool({
306
+ name: "TaskBulkCreate",
307
+ label: "TaskBulkCreate",
308
+ description: "Create multiple tasks at once. More efficient than calling TaskCreate multiple times.",
309
+ parameters: Type.Object({
310
+ tasks: Type.Array(Type.Object({
311
+ subject: Type.String({ description: "Brief task title" }),
312
+ description: Type.String({ description: "Detailed task description" }),
313
+ blockedBy: Type.Optional(Type.Array(Type.String(), { description: "Task IDs that block this task" })),
314
+ }), { description: "Array of tasks to create" }),
315
+ }),
316
+ async execute(_callId, params) {
317
+ const store = getStore();
318
+ const createdBy = { type: "local" as const, origin: "system", session: "", project: "" };
319
+ const created = store.createTasks(params.tasks.map(t => ({ ...t, createdBy })));
320
+ widget.update();
321
+ const lines = created.map(t => `#${t.id}: ${t.subject}`);
322
+ return textResult(`Created ${created.length} tasks:\n${lines.join("\n")}`);
323
+ },
324
+ });
325
+
326
+ // ── TaskBulkDelete ──
327
+ pi.registerTool({
328
+ name: "TaskBulkDelete",
329
+ label: "TaskBulkDelete",
330
+ description: "Delete multiple tasks at once by ID.",
331
+ parameters: Type.Object({
332
+ taskIds: Type.Array(Type.String(), { description: "Task IDs to delete" }),
333
+ }),
334
+ async execute(_callId, params) {
335
+ const store = getStore();
336
+ const count = store.deleteTasks(params.taskIds);
337
+ widget.update();
338
+ return textResult(`Deleted ${count} task(s)`);
339
+ },
340
+ });
341
+
342
+ // ── TaskBulkUpdate ──
343
+ pi.registerTool({
344
+ name: "TaskBulkUpdate",
345
+ label: "TaskBulkUpdate",
346
+ description: "Update multiple tasks at once. More efficient than calling TaskUpdate multiple times.",
347
+ parameters: Type.Object({
348
+ updates: Type.Array(Type.Object({
349
+ taskId: Type.String({ description: "Task ID to update" }),
350
+ status: Type.Optional(Type.Unsafe({ type: "string", enum: ["pending", "in_progress", "completed", "deleted"], description: "New status" })),
351
+ subject: Type.Optional(Type.String({ description: "New subject" })),
352
+ description: Type.Optional(Type.String({ description: "New description" })),
353
+ addBlockedBy: Type.Optional(Type.Array(Type.String(), { description: "Task IDs that block this task" })),
354
+ addBlocks: Type.Optional(Type.Array(Type.String(), { description: "Task IDs this task blocks" })),
355
+ }), { description: "Array of task updates" }),
356
+ }),
357
+ async execute(_callId, params) {
358
+ const store = getStore();
359
+ const updates = params.updates.map(u => ({
360
+ id: u.taskId,
361
+ fields: {
362
+ ...(u.status !== undefined ? { status: u.status } : {}),
363
+ ...(u.subject !== undefined ? { subject: u.subject } : {}),
364
+ ...(u.description !== undefined ? { description: u.description } : {}),
365
+ ...(u.addBlockedBy !== undefined ? { addBlockedBy: u.addBlockedBy } : {}),
366
+ ...(u.addBlocks !== undefined ? { addBlocks: u.addBlocks } : {}),
367
+ },
368
+ }));
369
+ const results = store.updateTasks(updates);
370
+ widget.update();
371
+ const lines = results.map(r => r.success ? `#${r.id}: ${r.changedFields?.join(", ") || "no changes"}` : `#${r.id}: not found`);
372
+ return textResult(`Updated ${results.filter(r => r.success).length} task(s):\n${lines.join("\n")}`);
373
+ },
374
+ });
375
+ }
@@ -0,0 +1,181 @@
1
+ /**
2
+ * task-widget.ts — Persistent widget showing task list with status icons and progress.
3
+ * Copied from @tintinweb/pi-tasks (MIT license).
4
+ */
5
+ import { truncateToWidth } from "@earendil-works/pi-tui";
6
+ import type { TaskStore } from "./task-store.js";
7
+
8
+ const SPINNER = ["✳", "✴", "✵", "✶", "✷", "✸", "✹", "✺", "✻", "✼", "✽"];
9
+ const DEFAULT_MAX_VISIBLE_TASKS = 10;
10
+
11
+ function truncateFromTop(tasks: any[], limit: number): any[] { return tasks.slice(-limit); }
12
+ function truncateFromBottom(tasks: any[], limit: number): any[] { return tasks.slice(0, limit); }
13
+ const TRUNCATE_FNS: Record<string, (t: any[], l: number) => any[]> = { top: truncateFromTop, bottom: truncateFromBottom };
14
+
15
+ function formatDuration(ms: number): string {
16
+ const totalSec = Math.floor(ms / 1000);
17
+ if (totalSec < 60) return `${totalSec}s`;
18
+ const min = Math.floor(totalSec / 60);
19
+ const sec = totalSec % 60;
20
+ if (min < 60) return sec > 0 ? `${min}m ${sec}s` : `${min}m`;
21
+ const hr = Math.floor(min / 60);
22
+ const remMin = min % 60;
23
+ return remMin > 0 ? `${hr}h ${remMin}m` : `${hr}h`;
24
+ }
25
+
26
+ function formatTokens(n: number): string {
27
+ if (n < 1000) return String(n);
28
+ return (n / 1000).toFixed(1).replace(/\.0$/, "") + "k";
29
+ }
30
+
31
+ export class TaskWidget {
32
+ private uiCtx: any;
33
+ private widgetFrame = 0;
34
+ private widgetInterval: ReturnType<typeof setInterval> | undefined;
35
+ private activeTaskIds = new Set<string>();
36
+ private metrics = new Map<string, { startedAt: number; inputTokens: number; outputTokens: number }>();
37
+ private tui: any;
38
+ private widgetRegistered = false;
39
+
40
+ constructor(private store: TaskStore, private config: Record<string, any> = {}) {}
41
+
42
+ setStore(store: TaskStore): void { this.store = store; }
43
+ setUICtx(ctx: any): void { this.uiCtx = ctx; }
44
+
45
+ setActiveTask(taskId: string, active = true): void {
46
+ if (taskId && active) {
47
+ this.activeTaskIds.add(taskId);
48
+ if (!this.metrics.has(taskId)) {
49
+ this.metrics.set(taskId, { startedAt: Date.now(), inputTokens: 0, outputTokens: 0 });
50
+ }
51
+ this.ensureTimer();
52
+ } else if (taskId) {
53
+ this.activeTaskIds.delete(taskId);
54
+ }
55
+ this.update();
56
+ }
57
+
58
+ addTokenUsage(inputTokens: number, outputTokens: number): void {
59
+ for (const id of this.activeTaskIds) {
60
+ const m = this.metrics.get(id);
61
+ if (m) { m.inputTokens += inputTokens; m.outputTokens += outputTokens; }
62
+ }
63
+ }
64
+
65
+ private ensureTimer(): void {
66
+ if (!this.widgetInterval) {
67
+ this.widgetInterval = setInterval(() => this.update(), 150);
68
+ }
69
+ }
70
+
71
+ private renderWidget(tui: any, theme: any): string[] {
72
+ try { return this.buildWidgetLines(tui, theme); } catch { return []; }
73
+ }
74
+
75
+ private buildWidgetLines(tui: any, theme: any): string[] {
76
+ const sortOrder = this.config.sortOrder ?? "id";
77
+ const tasks = this.store.list(sortOrder);
78
+ const w = tui.terminal.columns;
79
+ const truncate = (line: string) => truncateToWidth(line, w);
80
+ if (tasks.length === 0) return [];
81
+
82
+ const completed = tasks.filter(t => t.status === "completed");
83
+ const inProgress = tasks.filter(t => t.status === "in_progress");
84
+ const pending = tasks.filter(t => t.status === "pending");
85
+ const parts: string[] = [];
86
+ if (completed.length > 0) parts.push(`${completed.length} done`);
87
+ if (inProgress.length > 0) parts.push(`${inProgress.length} in progress`);
88
+ if (pending.length > 0) parts.push(`${pending.length} open`);
89
+ const statusText = `${tasks.length} tasks (${parts.join(", ")})`;
90
+ const spinnerChar = SPINNER[this.widgetFrame % SPINNER.length];
91
+ const lines: string[] = [truncate(theme.fg("accent", "●") + " " + theme.fg("accent", statusText))];
92
+
93
+ const showAll = this.config.showAll ?? false;
94
+ const limit = this.config.maxVisible ?? DEFAULT_MAX_VISIBLE_TASKS;
95
+ const hiddenAt = this.config.hiddenAt ?? "bottom";
96
+ const visible = showAll ? tasks : TRUNCATE_FNS[hiddenAt](tasks, limit);
97
+ const hiddenCount = tasks.length - visible.length;
98
+ const overflowLine = hiddenCount > 0 ? truncate(theme.fg("dim", ` … and ${hiddenCount} more`)) : undefined;
99
+
100
+ if (overflowLine && hiddenAt === "top") lines.push(overflowLine);
101
+
102
+ for (const task of visible) {
103
+ let icon: string;
104
+ if (task.status === "in_progress") icon = theme.fg("accent", spinnerChar);
105
+ else if (task.status === "completed") icon = theme.fg("success", "✔");
106
+ else icon = "◻";
107
+
108
+ let suffix = "";
109
+ if (task.status === "pending" && task.blockedBy.length > 0) {
110
+ const openBlockers = task.blockedBy.filter((bid: string) => {
111
+ const blocker = this.store.get(bid);
112
+ return blocker && blocker.status !== "completed";
113
+ });
114
+ if (openBlockers.length > 0) suffix = theme.fg("dim", ` › blocked by ${openBlockers.map((id: string) => "#" + id).join(", ")}`);
115
+ }
116
+
117
+ let text: string;
118
+ if (task.status === "in_progress") {
119
+ const form = task.activeForm || task.subject;
120
+ const agentId = task.metadata?.agentId;
121
+ const agentLabel = agentId ? ` (agent ${agentId.slice(0, 5)})` : "";
122
+ const m = this.metrics.get(task.id);
123
+ let stats = "";
124
+ if (m) {
125
+ const elapsed = formatDuration(Date.now() - m.startedAt);
126
+ const tokenParts: string[] = [];
127
+ if (m.inputTokens > 0) tokenParts.push(`↑ ${formatTokens(m.inputTokens)}`);
128
+ if (m.outputTokens > 0) tokenParts.push(`↓ ${formatTokens(m.outputTokens)}`);
129
+ stats = tokenParts.length > 0
130
+ ? ` ${theme.fg("dim", `(${elapsed} · ${tokenParts.join(" ")})`)}`
131
+ : ` ${theme.fg("dim", `(${elapsed})`)}`;
132
+ }
133
+ text = ` ${icon} ${theme.fg("dim", "#" + task.id)} ${theme.fg("accent", form + agentLabel + "…")}${stats}`;
134
+ } else if (task.status === "completed") {
135
+ text = ` ${icon} ${theme.fg("dim", theme.strikethrough("#" + task.id + " " + task.subject))}`;
136
+ } else {
137
+ const agentSuffix = task.status === "in_progress" && task.metadata?.agentId
138
+ ? theme.fg("dim", ` (agent ${task.metadata.agentId.slice(0, 5)})`) : "";
139
+ text = ` ${icon} ${theme.fg("dim", "#" + task.id)} ${task.subject}${agentSuffix}`;
140
+ }
141
+ lines.push(truncate(text + suffix));
142
+ }
143
+
144
+ if (overflowLine && hiddenAt !== "top") lines.push(overflowLine);
145
+ return lines;
146
+ }
147
+
148
+ update(): void {
149
+ if (!this.uiCtx) return;
150
+ const tasks = this.store.list();
151
+ if (tasks.length === 0) {
152
+ if (this.widgetRegistered) { this.uiCtx.setWidget("tasks", undefined); this.widgetRegistered = false; }
153
+ if (this.widgetInterval) { clearInterval(this.widgetInterval); this.widgetInterval = undefined; }
154
+ return;
155
+ }
156
+ for (const id of this.activeTaskIds) {
157
+ const t = this.store.get(id);
158
+ if (!t || t.status !== "in_progress") { this.activeTaskIds.delete(id); this.metrics.delete(id); }
159
+ }
160
+ const hasActiveSpinner = tasks.some(t => t.status === "in_progress");
161
+ if (hasActiveSpinner) this.ensureTimer();
162
+ else if (this.widgetInterval) { clearInterval(this.widgetInterval); this.widgetInterval = undefined; }
163
+ this.widgetFrame++;
164
+ if (!this.widgetRegistered) {
165
+ this.uiCtx.setWidget("tasks", (tui: any, theme: any) => {
166
+ this.tui = tui;
167
+ return { render: () => this.renderWidget(tui, theme), invalidate: () => {} };
168
+ }, { placement: "aboveEditor" });
169
+ this.widgetRegistered = true;
170
+ } else if (this.tui) {
171
+ this.tui.requestRender();
172
+ }
173
+ }
174
+
175
+ dispose(): void {
176
+ if (this.widgetInterval) { clearInterval(this.widgetInterval); this.widgetInterval = undefined; }
177
+ if (this.uiCtx) this.uiCtx.setWidget("tasks", undefined);
178
+ this.widgetRegistered = false;
179
+ this.tui = undefined;
180
+ }
181
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * types.ts — Type definitions for the task management system.
3
+ * Copied from @tintinweb/pi-tasks (MIT license).
4
+ */
5
+
6
+ export type TaskStatus = "pending" | "in_progress" | "completed";
7
+
8
+ export interface Task {
9
+ id: string;
10
+ subject: string;
11
+ description: string;
12
+ status: TaskStatus;
13
+ activeForm?: string;
14
+ owner?: string;
15
+ metadata: Record<string, any>;
16
+ blocks: string[];
17
+ blockedBy: string[];
18
+ createdBy: {
19
+ type: "local" | "coms";
20
+ origin: string;
21
+ session: string;
22
+ project: string;
23
+ };
24
+ createdAt: number;
25
+ updatedAt: number;
26
+ statusHistory: {
27
+ pending_at: string;
28
+ in_progress_at: string | null;
29
+ completed_at: string | null;
30
+ deleted_at: string | null;
31
+ };
32
+ }
33
+
34
+ /** Serialized store format on disk. */
35
+ export interface TaskStoreData {
36
+ nextId: number;
37
+ tasks: Task[];
38
+ }
@@ -35,6 +35,7 @@ import { loadAcpxRuntime, type AcpxRuntimeModule } from "../acpx-provider/load-r
35
35
  import { modelIdToDisplayName } from "../acpx-provider/runtime-models.js";
36
36
  import { buildExternalSystemPrompt } from "../shared/build-system-prompt.js";
37
37
  import { fileLog } from "../shared/file-logger.js";
38
+ import { resolveBinary } from "../shared/resolve-binary.js";
38
39
 
39
40
  const LOG_DOMAIN = "acpx-driver";
40
41
  const DRIVER_KIND = "acpx";
@@ -378,12 +379,21 @@ export const AcpxDriver: ProviderDriver<AcpxConfig> = {
378
379
  driverKind: DRIVER_KIND,
379
380
  metadata: {
380
381
  displayName: "ACPX",
381
- supportsMultipleInstances: false,
382
+ supportsMultipleInstances: true,
382
383
  },
383
384
  configSchema: acpxConfigSchema,
384
385
  defaultConfig: () => ({ agent: "cursor", enabled: true }),
385
386
 
386
- probe: async (_config: AcpxConfig): Promise<ProviderProbeResult> => {
387
+ probe: async (config: AcpxConfig): Promise<ProviderProbeResult> => {
388
+ // Check that the underlying CLI binary is installed (e.g. cursor, claude, gemini)
389
+ const binaryName = config.agent === "cursor" ? "agent" : config.agent;
390
+ const binary = resolveBinary(binaryName);
391
+ if (!binary) {
392
+ return {
393
+ available: false,
394
+ reason: `CLI binary '${binaryName}' for acpx agent '${config.agent}' not found on PATH`,
395
+ };
396
+ }
387
397
  try {
388
398
  await loadAcpxRuntime();
389
399
  return { available: true };
@@ -39,14 +39,14 @@ export const BUILT_IN_DRIVERS: readonly AnyProviderDriver[] = [
39
39
  * Drivers use kinds like "cursor-cli", "acpx", "claude-cli".
40
40
  * This map resolves the mapping.
41
41
  */
42
- export const CLI_AGENT_TO_DRIVER: Record<string, string> = {
42
+ export const CLI_AGENT_TO_DRIVER: Record<string, string> = Object.assign(Object.create(null), {
43
43
  claude: "claude-cli",
44
44
  gemini: "gemini-cli",
45
45
  cursor: "cursor-cli",
46
- };
46
+ });
47
47
 
48
- export const ACPX_AGENT_TO_DRIVER: Record<string, string> = {
48
+ export const ACPX_AGENT_TO_DRIVER: Record<string, string> = Object.assign(Object.create(null), {
49
49
  cursor: "acpx",
50
- // Add more as they're implemented:
51
- // copilot: "acpx",
52
- };
50
+ claude: "acpx",
51
+ gemini: "acpx",
52
+ });
@@ -32,7 +32,7 @@ import type {
32
32
  } from "../shared/provider-driver.js";
33
33
  import { ProviderDriverError } from "../shared/provider-errors.js";
34
34
  import { makeManagedSnapshot, buildInitialSnapshot } from "../shared/managed-refresh.js";
35
- import { resolveBinary } from "../cli-provider/shared/discover-cache.js";
35
+ import { resolveBinary } from "../shared/resolve-binary.js";
36
36
  import { discoverCliModelsDetailed } from "../cli-provider/discover.js";
37
37
  import { runCliAgent } from "../cli-provider/runner.js";
38
38
  import {
@@ -29,7 +29,7 @@ import type {
29
29
  TurnResult,
30
30
  } from "../shared/provider-driver.js";
31
31
  import { makeManagedSnapshot, buildInitialSnapshot } from "../shared/managed-refresh.js";
32
- import { resolveBinary } from "../cli-provider/shared/discover-cache.js";
32
+ import { resolveBinary } from "../shared/resolve-binary.js";
33
33
  import { discoverCliModelsDetailed } from "../cli-provider/discover.js";
34
34
  import { runCliAgent } from "../cli-provider/runner.js";
35
35
  import {
@@ -28,7 +28,7 @@ import type {
28
28
  TurnResult,
29
29
  } from "../shared/provider-driver.js";
30
30
  import { makeManagedSnapshot, buildInitialSnapshot } from "../shared/managed-refresh.js";
31
- import { resolveBinary } from "../cli-provider/shared/discover-cache.js";
31
+ import { resolveBinary } from "../shared/resolve-binary.js";
32
32
  import { discoverCliModelsDetailed } from "../cli-provider/discover.js";
33
33
  import { runCliAgent } from "../cli-provider/runner.js";
34
34
  import {