@trevonistrevon/pi-loop 0.5.7 → 0.5.8
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/coverage/coverage-final.json +23 -23
- package/coverage/index.html +39 -39
- package/coverage/src/commands/index.html +1 -1
- package/coverage/src/commands/loop-command.ts.html +1 -1
- package/coverage/src/commands/tasks-command.ts.html +1 -1
- package/coverage/src/coordinator.ts.html +20 -20
- package/coverage/src/goal-coordinator.ts.html +1 -1
- package/coverage/src/goal-reducer.ts.html +1 -1
- package/coverage/src/goal-store.ts.html +1 -1
- package/coverage/src/goal-verifier.ts.html +1 -1
- package/coverage/src/index.html +33 -33
- package/coverage/src/index.ts.html +16 -16
- package/coverage/src/loop-parse.ts.html +62 -62
- package/coverage/src/loop-reducer.ts.html +21 -21
- package/coverage/src/monitor-completion-coordinator.ts.html +3 -3
- package/coverage/src/monitor-manager.ts.html +75 -69
- package/coverage/src/monitor-reducer.ts.html +28 -28
- package/coverage/src/notification-reducer.ts.html +6 -6
- package/coverage/src/reducer-backed-store.ts.html +28 -28
- package/coverage/src/runtime/index.html +45 -45
- package/coverage/src/runtime/monitor-ondone-runtime.ts.html +39 -39
- package/coverage/src/runtime/notification-runtime.ts.html +15 -15
- package/coverage/src/runtime/scope.ts.html +34 -34
- package/coverage/src/runtime/session-runtime.ts.html +58 -52
- package/coverage/src/runtime/task-backlog-runtime.ts.html +48 -48
- package/coverage/src/runtime/task-rpc.ts.html +80 -80
- package/coverage/src/scheduler.ts.html +35 -35
- package/coverage/src/store.ts.html +24 -24
- package/coverage/src/task-backlog-coordinator.ts.html +8 -8
- package/coverage/src/task-reducer.ts.html +39 -39
- package/coverage/src/task-store.ts.html +55 -55
- package/coverage/src/tools/index.html +43 -43
- package/coverage/src/tools/loop-tools.ts.html +94 -94
- package/coverage/src/tools/monitor-tools.ts.html +53 -53
- package/coverage/src/tools/native-task-tools.ts.html +66 -66
- package/coverage/src/trigger-system.ts.html +1 -1
- package/coverage/src/ui/index.html +1 -1
- package/coverage/src/ui/widget.ts.html +1 -1
- package/dist/commands/tasks-command.js +12 -9
- package/dist/monitor-manager.js +3 -1
- package/dist/runtime/session-runtime.js +3 -1
- package/dist/runtime/task-events.d.ts +15 -0
- package/dist/runtime/task-events.js +13 -0
- package/dist/runtime/task-rpc.js +2 -0
- package/dist/tools/native-task-tools.js +20 -9
- package/package.json +1 -1
- package/src/commands/tasks-command.ts +9 -9
- package/src/monitor-manager.ts +3 -1
- package/src/runtime/session-runtime.ts +3 -1
- package/src/runtime/task-events.ts +41 -0
- package/src/runtime/task-rpc.ts +2 -0
- package/src/tools/native-task-tools.ts +16 -9
- package/vitest.config.ts +7 -7
|
@@ -23,30 +23,30 @@
|
|
|
23
23
|
<div class='clearfix'>
|
|
24
24
|
|
|
25
25
|
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">
|
|
26
|
+
<span class="strong">100% </span>
|
|
27
27
|
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>
|
|
28
|
+
<span class='fraction'>50/50</span>
|
|
29
29
|
</div>
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">
|
|
33
|
+
<span class="strong">94.11% </span>
|
|
34
34
|
<span class="quiet">Branches</span>
|
|
35
|
-
<span class='fraction'>
|
|
35
|
+
<span class='fraction'>32/34</span>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
<div class='fl pad1y space-right2'>
|
|
40
|
-
<span class="strong">
|
|
40
|
+
<span class="strong">100% </span>
|
|
41
41
|
<span class="quiet">Functions</span>
|
|
42
|
-
<span class='fraction'>
|
|
42
|
+
<span class='fraction'>6/6</span>
|
|
43
43
|
</div>
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">
|
|
47
|
+
<span class="strong">100% </span>
|
|
48
48
|
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>
|
|
49
|
+
<span class='fraction'>43/43</span>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
52
|
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
</div>
|
|
62
62
|
</template>
|
|
63
63
|
</div>
|
|
64
|
-
<div class='status-line
|
|
64
|
+
<div class='status-line high'></div>
|
|
65
65
|
<pre><table class="coverage">
|
|
66
66
|
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
|
67
67
|
<a name='L2'></a><a href='#L2'>2</a>
|
|
@@ -230,13 +230,13 @@
|
|
|
230
230
|
<span class="cline-any cline-neutral"> </span>
|
|
231
231
|
<span class="cline-any cline-neutral"> </span>
|
|
232
232
|
<span class="cline-any cline-neutral"> </span>
|
|
233
|
-
<span class="cline-any cline-yes">
|
|
233
|
+
<span class="cline-any cline-yes">82x</span>
|
|
234
234
|
<span class="cline-any cline-neutral"> </span>
|
|
235
235
|
<span class="cline-any cline-neutral"> </span>
|
|
236
236
|
<span class="cline-any cline-neutral"> </span>
|
|
237
|
-
<span class="cline-any cline-yes">
|
|
237
|
+
<span class="cline-any cline-yes">55x</span>
|
|
238
238
|
<span class="cline-any cline-neutral"> </span>
|
|
239
|
-
<span class="cline-any cline-yes">
|
|
239
|
+
<span class="cline-any cline-yes">55x</span>
|
|
240
240
|
<span class="cline-any cline-neutral"> </span>
|
|
241
241
|
<span class="cline-any cline-neutral"> </span>
|
|
242
242
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -261,49 +261,50 @@
|
|
|
261
261
|
<span class="cline-any cline-neutral"> </span>
|
|
262
262
|
<span class="cline-any cline-neutral"> </span>
|
|
263
263
|
<span class="cline-any cline-neutral"> </span>
|
|
264
|
-
<span class="cline-any cline-yes">
|
|
265
|
-
<span class="cline-any cline-yes">
|
|
264
|
+
<span class="cline-any cline-yes">42x</span>
|
|
265
|
+
<span class="cline-any cline-yes">42x</span>
|
|
266
266
|
<span class="cline-any cline-neutral"> </span>
|
|
267
267
|
<span class="cline-any cline-neutral"> </span>
|
|
268
268
|
<span class="cline-any cline-neutral"> </span>
|
|
269
269
|
<span class="cline-any cline-neutral"> </span>
|
|
270
270
|
<span class="cline-any cline-neutral"> </span>
|
|
271
|
-
<span class="cline-any cline-yes">
|
|
272
|
-
<span class="cline-any cline-yes">
|
|
271
|
+
<span class="cline-any cline-yes">42x</span>
|
|
272
|
+
<span class="cline-any cline-yes">42x</span>
|
|
273
273
|
<span class="cline-any cline-neutral"> </span>
|
|
274
|
-
<span class="cline-any cline-yes">
|
|
274
|
+
<span class="cline-any cline-yes">42x</span>
|
|
275
275
|
<span class="cline-any cline-neutral"> </span>
|
|
276
276
|
<span class="cline-any cline-neutral"> </span>
|
|
277
|
-
<span class="cline-any cline-yes">
|
|
277
|
+
<span class="cline-any cline-yes">42x</span>
|
|
278
278
|
<span class="cline-any cline-neutral"> </span>
|
|
279
279
|
<span class="cline-any cline-neutral"> </span>
|
|
280
280
|
<span class="cline-any cline-neutral"> </span>
|
|
281
|
-
<span class="cline-any cline-yes">
|
|
281
|
+
<span class="cline-any cline-yes">55x</span>
|
|
282
282
|
<span class="cline-any cline-neutral"> </span>
|
|
283
283
|
<span class="cline-any cline-neutral"> </span>
|
|
284
284
|
<span class="cline-any cline-neutral"> </span>
|
|
285
285
|
<span class="cline-any cline-neutral"> </span>
|
|
286
286
|
<span class="cline-any cline-neutral"> </span>
|
|
287
|
-
<span class="cline-any cline-yes">
|
|
288
|
-
<span class="cline-any cline-yes">
|
|
287
|
+
<span class="cline-any cline-yes">7x</span>
|
|
288
|
+
<span class="cline-any cline-yes">7x</span>
|
|
289
289
|
<span class="cline-any cline-neutral"> </span>
|
|
290
|
-
<span class="cline-any cline-yes">
|
|
291
|
-
<span class="cline-any cline-yes">
|
|
290
|
+
<span class="cline-any cline-yes">6x</span>
|
|
291
|
+
<span class="cline-any cline-yes">6x</span>
|
|
292
292
|
<span class="cline-any cline-neutral"> </span>
|
|
293
293
|
<span class="cline-any cline-neutral"> </span>
|
|
294
294
|
<span class="cline-any cline-neutral"> </span>
|
|
295
295
|
<span class="cline-any cline-neutral"> </span>
|
|
296
|
-
<span class="cline-any cline-yes">5x</span>
|
|
297
296
|
<span class="cline-any cline-yes">6x</span>
|
|
297
|
+
<span class="cline-any cline-yes">8x</span>
|
|
298
|
+
<span class="cline-any cline-yes">8x</span>
|
|
299
|
+
<span class="cline-any cline-yes">8x</span>
|
|
300
|
+
<span class="cline-any cline-neutral"> </span>
|
|
298
301
|
<span class="cline-any cline-yes">6x</span>
|
|
299
302
|
<span class="cline-any cline-yes">6x</span>
|
|
300
303
|
<span class="cline-any cline-neutral"> </span>
|
|
301
|
-
<span class="cline-any cline-yes">5x</span>
|
|
302
|
-
<span class="cline-any cline-yes">5x</span>
|
|
303
304
|
<span class="cline-any cline-neutral"> </span>
|
|
304
305
|
<span class="cline-any cline-neutral"> </span>
|
|
306
|
+
<span class="cline-any cline-yes">55x</span>
|
|
305
307
|
<span class="cline-any cline-neutral"> </span>
|
|
306
|
-
<span class="cline-any cline-yes">45x</span>
|
|
307
308
|
<span class="cline-any cline-neutral"> </span>
|
|
308
309
|
<span class="cline-any cline-neutral"> </span>
|
|
309
310
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -321,45 +322,44 @@
|
|
|
321
322
|
<span class="cline-any cline-neutral"> </span>
|
|
322
323
|
<span class="cline-any cline-neutral"> </span>
|
|
323
324
|
<span class="cline-any cline-neutral"> </span>
|
|
325
|
+
<span class="cline-any cline-yes">31x</span>
|
|
326
|
+
<span class="cline-any cline-yes">31x</span>
|
|
327
|
+
<span class="cline-any cline-yes">31x</span>
|
|
324
328
|
<span class="cline-any cline-neutral"> </span>
|
|
325
|
-
<span class="cline-any cline-yes">
|
|
326
|
-
<span class="cline-any cline-yes">
|
|
327
|
-
<span class="cline-any cline-yes">
|
|
329
|
+
<span class="cline-any cline-yes">30x</span>
|
|
330
|
+
<span class="cline-any cline-yes">27x</span>
|
|
331
|
+
<span class="cline-any cline-yes">8x</span>
|
|
328
332
|
<span class="cline-any cline-neutral"> </span>
|
|
329
|
-
<span class="cline-any cline-yes">
|
|
330
|
-
<span class="cline-any cline-yes">
|
|
331
|
-
<span class="cline-any cline-yes">
|
|
333
|
+
<span class="cline-any cline-yes">30x</span>
|
|
334
|
+
<span class="cline-any cline-yes">30x</span>
|
|
335
|
+
<span class="cline-any cline-yes">1x</span>
|
|
332
336
|
<span class="cline-any cline-neutral"> </span>
|
|
333
|
-
<span class="cline-any cline-yes">
|
|
334
|
-
<span class="cline-any cline-yes">
|
|
335
|
-
<span class="cline-any cline-
|
|
337
|
+
<span class="cline-any cline-yes">30x</span>
|
|
338
|
+
<span class="cline-any cline-yes">30x</span>
|
|
339
|
+
<span class="cline-any cline-yes">30x</span>
|
|
340
|
+
<span class="cline-any cline-yes">30x</span>
|
|
341
|
+
<span class="cline-any cline-yes">31x</span>
|
|
336
342
|
<span class="cline-any cline-neutral"> </span>
|
|
337
|
-
<span class="cline-any cline-yes">26x</span>
|
|
338
|
-
<span class="cline-any cline-yes">26x</span>
|
|
339
|
-
<span class="cline-any cline-yes">26x</span>
|
|
340
|
-
<span class="cline-any cline-yes">26x</span>
|
|
341
|
-
<span class="cline-any cline-yes">26x</span>
|
|
342
343
|
<span class="cline-any cline-neutral"> </span>
|
|
344
|
+
<span class="cline-any cline-yes">31x</span>
|
|
343
345
|
<span class="cline-any cline-neutral"> </span>
|
|
344
|
-
<span class="cline-any cline-yes">26x</span>
|
|
345
346
|
<span class="cline-any cline-neutral"> </span>
|
|
346
347
|
<span class="cline-any cline-neutral"> </span>
|
|
348
|
+
<span class="cline-any cline-yes">55x</span>
|
|
347
349
|
<span class="cline-any cline-neutral"> </span>
|
|
348
|
-
<span class="cline-any cline-yes">45x</span>
|
|
349
350
|
<span class="cline-any cline-neutral"> </span>
|
|
350
351
|
<span class="cline-any cline-neutral"> </span>
|
|
351
352
|
<span class="cline-any cline-neutral"> </span>
|
|
352
353
|
<span class="cline-any cline-neutral"> </span>
|
|
353
354
|
<span class="cline-any cline-neutral"> </span>
|
|
354
355
|
<span class="cline-any cline-neutral"> </span>
|
|
356
|
+
<span class="cline-any cline-yes">2x</span>
|
|
357
|
+
<span class="cline-any cline-yes">2x</span>
|
|
358
|
+
<span class="cline-any cline-yes">2x</span>
|
|
359
|
+
<span class="cline-any cline-yes">1x</span>
|
|
360
|
+
<span class="cline-any cline-yes">1x</span>
|
|
355
361
|
<span class="cline-any cline-neutral"> </span>
|
|
356
|
-
<span class="cline-any cline-
|
|
357
|
-
<span class="cline-any cline-no"> </span>
|
|
358
|
-
<span class="cline-any cline-no"> </span>
|
|
359
|
-
<span class="cline-any cline-no"> </span>
|
|
360
|
-
<span class="cline-any cline-no"> </span>
|
|
361
|
-
<span class="cline-any cline-neutral"> </span>
|
|
362
|
-
<span class="cline-any cline-no"> </span>
|
|
362
|
+
<span class="cline-any cline-yes">1x</span>
|
|
363
363
|
<span class="cline-any cline-neutral"> </span>
|
|
364
364
|
<span class="cline-any cline-neutral"> </span>
|
|
365
365
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -435,7 +435,7 @@ Fields:
|
|
|
435
435
|
parameters: Type.Object({}),
|
|
436
436
|
execute() {
|
|
437
437
|
const tasks = taskStore.list();
|
|
438
|
-
|
|
438
|
+
if (tasks.length === 0) return Promise.resolve(textResult("No tasks."));
|
|
439
439
|
|
|
440
440
|
const lines: string[] = [];
|
|
441
441
|
const statuses: Record<"pending" | "in_progress" | "completed", number> = {
|
|
@@ -474,20 +474,20 @@ Parameters: id (required), status, subject, description`,
|
|
|
474
474
|
async execute(_toolCallId, params) {
|
|
475
475
|
const { id, status, subject, description } = params;
|
|
476
476
|
let entry = taskStore.get(id);
|
|
477
|
-
|
|
477
|
+
if (!entry) return Promise.resolve(textResult(`Task #${id} not found`));
|
|
478
478
|
|
|
479
479
|
if (status === "in_progress") entry = taskStore.start(id);
|
|
480
480
|
else if (status === "completed") entry = taskStore.complete(id);
|
|
481
|
-
else
|
|
481
|
+
else if (status === "pending") entry = taskStore.reopen(id);
|
|
482
482
|
|
|
483
|
-
<span class="missing-if-branch" title="if path not taken" >I</span>if (!entry)
|
|
484
|
-
|
|
485
|
-
|
|
483
|
+
<span class="missing-if-branch" title="if path not taken" >I</span>if (!entry) return Promise.resolve(textResult(`Task #${id} not found`));
|
|
484
|
+
if (subject !== undefined || description !== undefined) {
|
|
485
|
+
entry = taskStore.updateDetails(id, { subject, description });
|
|
486
486
|
}
|
|
487
|
-
<span class="missing-if-branch" title="if path not taken" >I</span>if (!entry)
|
|
487
|
+
<span class="missing-if-branch" title="if path not taken" >I</span>if (!entry) return Promise.resolve(textResult(`Task #${id} not found`));
|
|
488
488
|
updateWidget();
|
|
489
489
|
const backlog = await evaluateTaskBacklog(taskStore, taskStore.pendingCount());
|
|
490
|
-
const statusMsg = status ? ` → ${status}` :
|
|
490
|
+
const statusMsg = status ? ` → ${status}` : "";
|
|
491
491
|
const autoLoopMsg = backlog.created && backlog.entry
|
|
492
492
|
? `\nBacklog worker loop #${backlog.entry.id} created`
|
|
493
493
|
: "";
|
|
@@ -502,14 +502,14 @@ Parameters: id (required), status, subject, description`,
|
|
|
502
502
|
parameters: Type.Object({
|
|
503
503
|
id: Type.String({ description: "Task ID to delete" }),
|
|
504
504
|
}),
|
|
505
|
-
async
|
|
506
|
-
const deleted =
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
505
|
+
async execute(_toolCallId, params) {
|
|
506
|
+
const deleted = taskStore.delete(params.id);
|
|
507
|
+
updateWidget();
|
|
508
|
+
if (deleted) {
|
|
509
|
+
await evaluateTaskBacklog(taskStore, taskStore.pendingCount());
|
|
510
|
+
return Promise.resolve(textResult(`Task #${params.id} deleted`));
|
|
511
511
|
}
|
|
512
|
-
|
|
512
|
+
return Promise.resolve(textResult(`Task #${params.id} not found`));
|
|
513
513
|
},
|
|
514
514
|
});
|
|
515
515
|
}
|
|
@@ -520,7 +520,7 @@ Parameters: id (required), status, subject, description`,
|
|
|
520
520
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
521
521
|
Code coverage generated by
|
|
522
522
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
523
|
-
at 2026-06-
|
|
523
|
+
at 2026-06-19T00:56:38.236Z
|
|
524
524
|
</div>
|
|
525
525
|
<script src="../../prettify.js"></script>
|
|
526
526
|
<script>
|
|
@@ -532,7 +532,7 @@ export class TriggerSystem {
|
|
|
532
532
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
533
533
|
Code coverage generated by
|
|
534
534
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
535
|
-
at 2026-06-
|
|
535
|
+
at 2026-06-19T00:56:38.236Z
|
|
536
536
|
</div>
|
|
537
537
|
<script src="../prettify.js"></script>
|
|
538
538
|
<script>
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
102
102
|
Code coverage generated by
|
|
103
103
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
104
|
-
at 2026-06-
|
|
104
|
+
at 2026-06-19T00:56:38.236Z
|
|
105
105
|
</div>
|
|
106
106
|
<script src="../../prettify.js"></script>
|
|
107
107
|
<script>
|
|
@@ -277,7 +277,7 @@ function isStatusVisibleLoop(loop: LoopEntry): boolean {
|
|
|
277
277
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
278
278
|
Code coverage generated by
|
|
279
279
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
280
|
-
at 2026-06-
|
|
280
|
+
at 2026-06-19T00:56:38.236Z
|
|
281
281
|
</div>
|
|
282
282
|
<script src="../../prettify.js"></script>
|
|
283
283
|
<script>
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
+
import { emitNativeTaskEvent } from "../runtime/task-events.js";
|
|
1
2
|
export function registerTasksCommand(options) {
|
|
2
3
|
const { pi, getNativeTaskStore, evaluateTaskBacklog, updateWidget } = options;
|
|
3
4
|
async function emitCreated(entry) {
|
|
4
|
-
pi
|
|
5
|
-
taskId: entry.id,
|
|
6
|
-
subject: entry.subject,
|
|
7
|
-
description: entry.description,
|
|
8
|
-
status: entry.status,
|
|
9
|
-
});
|
|
5
|
+
emitNativeTaskEvent(pi, "tasks:created", entry);
|
|
10
6
|
const taskStore = getNativeTaskStore();
|
|
11
7
|
if (!taskStore)
|
|
12
8
|
return { created: false };
|
|
@@ -75,18 +71,25 @@ export function registerTasksCommand(options) {
|
|
|
75
71
|
return viewNativeTasks(ui);
|
|
76
72
|
if (action === "x Delete") {
|
|
77
73
|
taskStore.delete(task.id);
|
|
74
|
+
emitNativeTaskEvent(pi, "tasks:deleted", task, task.status);
|
|
78
75
|
ui.notify(`Task #${task.id} deleted`, "info");
|
|
79
76
|
}
|
|
80
77
|
else if (action === "> Start") {
|
|
81
|
-
taskStore.start(task.id);
|
|
78
|
+
const next = taskStore.start(task.id);
|
|
79
|
+
if (next)
|
|
80
|
+
emitNativeTaskEvent(pi, "tasks:started", next, task.status);
|
|
82
81
|
ui.notify(`Task #${task.id} started`, "info");
|
|
83
82
|
}
|
|
84
83
|
else if (action === "ok Complete") {
|
|
85
|
-
taskStore.complete(task.id);
|
|
84
|
+
const next = taskStore.complete(task.id);
|
|
85
|
+
if (next)
|
|
86
|
+
emitNativeTaskEvent(pi, "tasks:completed", next, task.status);
|
|
86
87
|
ui.notify(`Task #${task.id} completed`, "info");
|
|
87
88
|
}
|
|
88
89
|
else if (action === "* Return to pending" || action === "* Reopen") {
|
|
89
|
-
taskStore.reopen(task.id);
|
|
90
|
+
const next = taskStore.reopen(task.id);
|
|
91
|
+
if (next)
|
|
92
|
+
emitNativeTaskEvent(pi, "tasks:reopened", next, task.status);
|
|
90
93
|
ui.notify(`Task #${task.id} reopened`, "info");
|
|
91
94
|
}
|
|
92
95
|
updateWidget();
|
package/dist/monitor-manager.js
CHANGED
|
@@ -46,7 +46,8 @@ export class MonitorManager {
|
|
|
46
46
|
// finish() and stop() so every terminal status is pruned consistently — a
|
|
47
47
|
// stopped monitor that is never pruned lingers in list() and the widget count.
|
|
48
48
|
schedulePrune(id) {
|
|
49
|
-
|
|
49
|
+
// unref so a pending prune never keeps a one-shot (`pi -p`) process alive.
|
|
50
|
+
const timer = setTimeout(() => {
|
|
50
51
|
this.applyReducerEvent({
|
|
51
52
|
type: "MONITOR_PRUNED",
|
|
52
53
|
at: Date.now(),
|
|
@@ -56,6 +57,7 @@ export class MonitorManager {
|
|
|
56
57
|
payload: { id },
|
|
57
58
|
});
|
|
58
59
|
}, 30000);
|
|
60
|
+
timer.unref?.();
|
|
59
61
|
}
|
|
60
62
|
create(command, description, timeout = 300000) {
|
|
61
63
|
const now = Date.now();
|
|
@@ -14,7 +14,9 @@ export function registerSessionRuntimeHooks(options) {
|
|
|
14
14
|
if (heartbeatTimer)
|
|
15
15
|
return;
|
|
16
16
|
heartbeatTimer = setInterval(() => {
|
|
17
|
-
|
|
17
|
+
// Swallow pump failures so a transient error never surfaces as an
|
|
18
|
+
// unhandled rejection; the next tick retries.
|
|
19
|
+
void pumpLoops().catch(() => { });
|
|
18
20
|
}, HEARTBEAT_MS);
|
|
19
21
|
heartbeatTimer.unref?.();
|
|
20
22
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { TaskEntry, TaskStatus } from "../task-types.js";
|
|
3
|
+
export type NativeTaskEventName = "tasks:created" | "tasks:started" | "tasks:completed" | "tasks:reopened" | "tasks:updated" | "tasks:deleted";
|
|
4
|
+
export interface NativeTaskEventPayload {
|
|
5
|
+
taskId: string;
|
|
6
|
+
subject: string;
|
|
7
|
+
description: string;
|
|
8
|
+
status: TaskStatus;
|
|
9
|
+
previousStatus?: TaskStatus;
|
|
10
|
+
createdAt: number;
|
|
11
|
+
updatedAt: number;
|
|
12
|
+
completedAt?: number;
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export declare function emitNativeTaskEvent(pi: ExtensionAPI, name: NativeTaskEventName, entry: TaskEntry, previousStatus?: TaskStatus): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function emitNativeTaskEvent(pi, name, entry, previousStatus) {
|
|
2
|
+
pi.events.emit(name, {
|
|
3
|
+
taskId: entry.id,
|
|
4
|
+
subject: entry.subject,
|
|
5
|
+
description: entry.description,
|
|
6
|
+
status: entry.status,
|
|
7
|
+
previousStatus,
|
|
8
|
+
createdAt: entry.createdAt,
|
|
9
|
+
updatedAt: entry.updatedAt,
|
|
10
|
+
completedAt: entry.completedAt,
|
|
11
|
+
metadata: entry.metadata,
|
|
12
|
+
});
|
|
13
|
+
}
|
package/dist/runtime/task-rpc.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { emitNativeTaskEvent } from "./task-events.js";
|
|
2
3
|
export function createTaskRuntimeBridge(options) {
|
|
3
4
|
const { pi, isTasksAvailable, setTasksAvailable, getNativeTaskStore, onNativeTaskCreated, onNativeTasksPruned, debug, } = options;
|
|
4
5
|
function checkTasksVersion() {
|
|
@@ -52,6 +53,7 @@ export function createTaskRuntimeBridge(options) {
|
|
|
52
53
|
if (!nativeTaskStore)
|
|
53
54
|
return undefined;
|
|
54
55
|
const task = nativeTaskStore.create(entry.prompt.slice(0, 80), `Auto-created from loop #${entry.id}`, { loopId: entry.id, trigger: entry.trigger });
|
|
56
|
+
emitNativeTaskEvent(pi, "tasks:created", task);
|
|
55
57
|
onNativeTaskCreated?.(nativeTaskStore);
|
|
56
58
|
return task.id;
|
|
57
59
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
+
import { emitNativeTaskEvent } from "../runtime/task-events.js";
|
|
2
3
|
function textResult(msg) {
|
|
3
4
|
return { content: [{ type: "text", text: msg }], details: undefined };
|
|
4
5
|
}
|
|
@@ -30,12 +31,7 @@ Fields:
|
|
|
30
31
|
}),
|
|
31
32
|
async execute(_toolCallId, params) {
|
|
32
33
|
const entry = taskStore.create(params.subject, params.description);
|
|
33
|
-
pi
|
|
34
|
-
taskId: entry.id,
|
|
35
|
-
subject: entry.subject,
|
|
36
|
-
description: entry.description,
|
|
37
|
-
status: entry.status,
|
|
38
|
-
});
|
|
34
|
+
emitNativeTaskEvent(pi, "tasks:created", entry);
|
|
39
35
|
const backlog = await evaluateTaskBacklog(taskStore, taskStore.pendingCount());
|
|
40
36
|
updateWidget();
|
|
41
37
|
const autoLoopMsg = backlog.created && backlog.entry
|
|
@@ -91,16 +87,28 @@ Parameters: id (required), status, subject, description`,
|
|
|
91
87
|
let entry = taskStore.get(id);
|
|
92
88
|
if (!entry)
|
|
93
89
|
return Promise.resolve(textResult(`Task #${id} not found`));
|
|
94
|
-
|
|
90
|
+
const previousStatus = entry.status;
|
|
91
|
+
if (status === "in_progress") {
|
|
95
92
|
entry = taskStore.start(id);
|
|
96
|
-
|
|
93
|
+
if (entry)
|
|
94
|
+
emitNativeTaskEvent(pi, "tasks:started", entry, previousStatus);
|
|
95
|
+
}
|
|
96
|
+
else if (status === "completed") {
|
|
97
97
|
entry = taskStore.complete(id);
|
|
98
|
-
|
|
98
|
+
if (entry)
|
|
99
|
+
emitNativeTaskEvent(pi, "tasks:completed", entry, previousStatus);
|
|
100
|
+
}
|
|
101
|
+
else if (status === "pending") {
|
|
99
102
|
entry = taskStore.reopen(id);
|
|
103
|
+
if (entry)
|
|
104
|
+
emitNativeTaskEvent(pi, "tasks:reopened", entry, previousStatus);
|
|
105
|
+
}
|
|
100
106
|
if (!entry)
|
|
101
107
|
return Promise.resolve(textResult(`Task #${id} not found`));
|
|
102
108
|
if (subject !== undefined || description !== undefined) {
|
|
103
109
|
entry = taskStore.updateDetails(id, { subject, description });
|
|
110
|
+
if (entry)
|
|
111
|
+
emitNativeTaskEvent(pi, "tasks:updated", entry, previousStatus);
|
|
104
112
|
}
|
|
105
113
|
if (!entry)
|
|
106
114
|
return Promise.resolve(textResult(`Task #${id} not found`));
|
|
@@ -121,9 +129,12 @@ Parameters: id (required), status, subject, description`,
|
|
|
121
129
|
id: Type.String({ description: "Task ID to delete" }),
|
|
122
130
|
}),
|
|
123
131
|
async execute(_toolCallId, params) {
|
|
132
|
+
const existing = taskStore.get(params.id);
|
|
124
133
|
const deleted = taskStore.delete(params.id);
|
|
125
134
|
updateWidget();
|
|
126
135
|
if (deleted) {
|
|
136
|
+
if (existing)
|
|
137
|
+
emitNativeTaskEvent(pi, "tasks:deleted", existing, existing.status);
|
|
127
138
|
await evaluateTaskBacklog(taskStore, taskStore.pendingCount());
|
|
128
139
|
return Promise.resolve(textResult(`Task #${params.id} deleted`));
|
|
129
140
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionCommandContext, ExtensionUIContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { emitNativeTaskEvent } from "../runtime/task-events.js";
|
|
2
3
|
import { TaskStore } from "../task-store.js";
|
|
3
4
|
import type { TaskEntry } from "../task-types.js";
|
|
4
5
|
|
|
@@ -18,12 +19,7 @@ export function registerTasksCommand(options: TasksCommandOptions): void {
|
|
|
18
19
|
const { pi, getNativeTaskStore, evaluateTaskBacklog, updateWidget } = options;
|
|
19
20
|
|
|
20
21
|
async function emitCreated(entry: TaskEntry) {
|
|
21
|
-
pi
|
|
22
|
-
taskId: entry.id,
|
|
23
|
-
subject: entry.subject,
|
|
24
|
-
description: entry.description,
|
|
25
|
-
status: entry.status,
|
|
26
|
-
});
|
|
22
|
+
emitNativeTaskEvent(pi, "tasks:created", entry);
|
|
27
23
|
const taskStore = getNativeTaskStore();
|
|
28
24
|
if (!taskStore) return { created: false } satisfies TaskBacklogResult;
|
|
29
25
|
const backlog = await evaluateTaskBacklog(taskStore, taskStore.pendingCount());
|
|
@@ -94,15 +90,19 @@ export function registerTasksCommand(options: TasksCommandOptions): void {
|
|
|
94
90
|
|
|
95
91
|
if (action === "x Delete") {
|
|
96
92
|
taskStore.delete(task.id);
|
|
93
|
+
emitNativeTaskEvent(pi, "tasks:deleted", task, task.status);
|
|
97
94
|
ui.notify(`Task #${task.id} deleted`, "info");
|
|
98
95
|
} else if (action === "> Start") {
|
|
99
|
-
taskStore.start(task.id);
|
|
96
|
+
const next = taskStore.start(task.id);
|
|
97
|
+
if (next) emitNativeTaskEvent(pi, "tasks:started", next, task.status);
|
|
100
98
|
ui.notify(`Task #${task.id} started`, "info");
|
|
101
99
|
} else if (action === "ok Complete") {
|
|
102
|
-
taskStore.complete(task.id);
|
|
100
|
+
const next = taskStore.complete(task.id);
|
|
101
|
+
if (next) emitNativeTaskEvent(pi, "tasks:completed", next, task.status);
|
|
103
102
|
ui.notify(`Task #${task.id} completed`, "info");
|
|
104
103
|
} else if (action === "* Return to pending" || action === "* Reopen") {
|
|
105
|
-
taskStore.reopen(task.id);
|
|
104
|
+
const next = taskStore.reopen(task.id);
|
|
105
|
+
if (next) emitNativeTaskEvent(pi, "tasks:reopened", next, task.status);
|
|
106
106
|
ui.notify(`Task #${task.id} reopened`, "info");
|
|
107
107
|
}
|
|
108
108
|
|
package/src/monitor-manager.ts
CHANGED
|
@@ -58,7 +58,8 @@ export class MonitorManager {
|
|
|
58
58
|
// finish() and stop() so every terminal status is pruned consistently — a
|
|
59
59
|
// stopped monitor that is never pruned lingers in list() and the widget count.
|
|
60
60
|
private schedulePrune(id: string): void {
|
|
61
|
-
|
|
61
|
+
// unref so a pending prune never keeps a one-shot (`pi -p`) process alive.
|
|
62
|
+
const timer = setTimeout(() => {
|
|
62
63
|
this.applyReducerEvent({
|
|
63
64
|
type: "MONITOR_PRUNED",
|
|
64
65
|
at: Date.now(),
|
|
@@ -68,6 +69,7 @@ export class MonitorManager {
|
|
|
68
69
|
payload: { id },
|
|
69
70
|
});
|
|
70
71
|
}, 30000);
|
|
72
|
+
timer.unref?.();
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
create(command: string, description?: string, timeout = 300000): MonitorEntry {
|
|
@@ -61,7 +61,9 @@ export function registerSessionRuntimeHooks(options: SessionRuntimeOptions): voi
|
|
|
61
61
|
function ensureHeartbeat(): void {
|
|
62
62
|
if (heartbeatTimer) return;
|
|
63
63
|
heartbeatTimer = setInterval(() => {
|
|
64
|
-
|
|
64
|
+
// Swallow pump failures so a transient error never surfaces as an
|
|
65
|
+
// unhandled rejection; the next tick retries.
|
|
66
|
+
void pumpLoops().catch(() => {});
|
|
65
67
|
}, HEARTBEAT_MS);
|
|
66
68
|
heartbeatTimer.unref?.();
|
|
67
69
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { TaskEntry, TaskStatus } from "../task-types.js";
|
|
3
|
+
|
|
4
|
+
export type NativeTaskEventName =
|
|
5
|
+
| "tasks:created"
|
|
6
|
+
| "tasks:started"
|
|
7
|
+
| "tasks:completed"
|
|
8
|
+
| "tasks:reopened"
|
|
9
|
+
| "tasks:updated"
|
|
10
|
+
| "tasks:deleted";
|
|
11
|
+
|
|
12
|
+
export interface NativeTaskEventPayload {
|
|
13
|
+
taskId: string;
|
|
14
|
+
subject: string;
|
|
15
|
+
description: string;
|
|
16
|
+
status: TaskStatus;
|
|
17
|
+
previousStatus?: TaskStatus;
|
|
18
|
+
createdAt: number;
|
|
19
|
+
updatedAt: number;
|
|
20
|
+
completedAt?: number;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function emitNativeTaskEvent(
|
|
25
|
+
pi: ExtensionAPI,
|
|
26
|
+
name: NativeTaskEventName,
|
|
27
|
+
entry: TaskEntry,
|
|
28
|
+
previousStatus?: TaskStatus,
|
|
29
|
+
): void {
|
|
30
|
+
pi.events.emit(name, {
|
|
31
|
+
taskId: entry.id,
|
|
32
|
+
subject: entry.subject,
|
|
33
|
+
description: entry.description,
|
|
34
|
+
status: entry.status,
|
|
35
|
+
previousStatus,
|
|
36
|
+
createdAt: entry.createdAt,
|
|
37
|
+
updatedAt: entry.updatedAt,
|
|
38
|
+
completedAt: entry.completedAt,
|
|
39
|
+
metadata: entry.metadata,
|
|
40
|
+
} satisfies NativeTaskEventPayload);
|
|
41
|
+
}
|
package/src/runtime/task-rpc.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import type { TaskStore } from "../task-store.js";
|
|
4
4
|
import type { LoopEntry } from "../types.js";
|
|
5
|
+
import { emitNativeTaskEvent } from "./task-events.js";
|
|
5
6
|
|
|
6
7
|
export interface TaskRuntimeBridgeOptions {
|
|
7
8
|
pi: ExtensionAPI;
|
|
@@ -82,6 +83,7 @@ export function createTaskRuntimeBridge(options: TaskRuntimeBridgeOptions): Task
|
|
|
82
83
|
`Auto-created from loop #${entry.id}`,
|
|
83
84
|
{ loopId: entry.id, trigger: entry.trigger },
|
|
84
85
|
);
|
|
86
|
+
emitNativeTaskEvent(pi, "tasks:created", task);
|
|
85
87
|
onNativeTaskCreated?.(nativeTaskStore);
|
|
86
88
|
return task.id;
|
|
87
89
|
}
|