@trevonistrevon/pi-loop 0.1.3 → 0.1.5
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/dist/index.js +13 -8
- package/dist/trigger-system.d.ts +3 -1
- package/dist/trigger-system.js +7 -1
- package/package.json +1 -1
- package/src/index.ts +13 -8
- package/src/trigger-system.ts +7 -0
package/dist/index.js
CHANGED
|
@@ -65,7 +65,7 @@ export default function (pi) {
|
|
|
65
65
|
const widget = new LoopWidget(store, undefined, monitorManager);
|
|
66
66
|
scheduler = new CronScheduler(store, onLoopFire);
|
|
67
67
|
widget.setScheduler(scheduler);
|
|
68
|
-
triggerSystem = new TriggerSystem(pi, scheduler);
|
|
68
|
+
triggerSystem = new TriggerSystem(pi, scheduler, store);
|
|
69
69
|
// ── pi-tasks integration ──
|
|
70
70
|
let tasksAvailable = false;
|
|
71
71
|
const _PROTOCOL_VERSION = 1;
|
|
@@ -142,7 +142,7 @@ export default function (pi) {
|
|
|
142
142
|
widget.setStore(store);
|
|
143
143
|
scheduler = new CronScheduler(store, onLoopFire);
|
|
144
144
|
widget.setScheduler(scheduler);
|
|
145
|
-
triggerSystem = new TriggerSystem(pi, scheduler);
|
|
145
|
+
triggerSystem = new TriggerSystem(pi, scheduler, store);
|
|
146
146
|
}
|
|
147
147
|
storeUpgraded = true;
|
|
148
148
|
}
|
|
@@ -402,13 +402,17 @@ Use "pause" to temporarily stop a loop without removing it. Use "delete" to perm
|
|
|
402
402
|
pi.registerTool({
|
|
403
403
|
name: "MonitorCreate",
|
|
404
404
|
label: "MonitorCreate",
|
|
405
|
-
description: `
|
|
405
|
+
description: `Run a shell command in the background and get notified when it finishes. The core tool for async/parallel work.
|
|
406
406
|
|
|
407
|
-
|
|
407
|
+
Fire off a build check, CI monitor, experiment, script, or any slow command — then keep working. Output streams back as "monitor:output" events. When the process exits, "monitor:done" fires (or "monitor:error" on failure).
|
|
408
|
+
|
|
409
|
+
If you pass onDone with a prompt, the monitor auto-creates a one-shot completion loop — you get a system reminder with the exit code and output line count. No need to poll or create a separate loop.
|
|
410
|
+
|
|
411
|
+
DO NOT use raw Bash while/sleep/for loops to watch something. DO NOT run slow commands inline that could be offloaded. Use MonitorCreate to run work in parallel while you continue.
|
|
408
412
|
|
|
409
413
|
## When to Use
|
|
410
414
|
|
|
411
|
-
|
|
415
|
+
Default to MonitorCreate for any long-running or background work:\n- Watch a CI/CD build (hut, gh, curl polling) while you work on something else\n- Run experiments, benchmarks, or training scripts in parallel\n- Tail a log or poll an API endpoint\n- Fire off a slow curl/fetch and check the result later\n- Run any script or command you don't need to wait on inline
|
|
412
416
|
|
|
413
417
|
## Events emitted
|
|
414
418
|
|
|
@@ -416,10 +420,11 @@ Use this tool to:\n- Start a long-running experiment and get notified when it fi
|
|
|
416
420
|
|
|
417
421
|
## onDone — auto-notify on completion
|
|
418
422
|
|
|
419
|
-
Pass onDone with a prompt and the monitor auto-creates a one-shot loop that fires when the process exits. The system reminder includes the exit code and output line count
|
|
423
|
+
Pass onDone with a prompt and the monitor auto-creates a one-shot loop that fires when the process exits. The system reminder includes the exit code and output line count.\n\nExample: MonitorCreate command="python train.py" onDone="Check training results and report best loss"\nExample: MonitorCreate command="hut builds show 1769753" onDone="Analyze the build result and report status"`,
|
|
420
424
|
promptGuidelines: [
|
|
421
|
-
"
|
|
422
|
-
"When
|
|
425
|
+
"Default to MonitorCreate for any long-running or background command — releases the agent to keep working on other tasks in parallel.",
|
|
426
|
+
"When the user asks to monitor CI builds, watch a build, check a remote job, or run an experiment, use MonitorCreate instead of inline bash/curl/wait.",
|
|
427
|
+
"Use onDone to auto-notify when a background command finishes — the agent will pick up the results automatically.",
|
|
423
428
|
],
|
|
424
429
|
parameters: Type.Object({
|
|
425
430
|
command: Type.String({ description: "Shell command to run in background" }),
|
package/dist/trigger-system.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { CronScheduler } from "./scheduler.js";
|
|
3
|
+
import type { LoopStore } from "./store.js";
|
|
3
4
|
import type { LoopEntry } from "./types.js";
|
|
4
5
|
export declare class TriggerSystem {
|
|
5
6
|
private pi;
|
|
6
7
|
private scheduler;
|
|
8
|
+
private store;
|
|
7
9
|
private eventSubscriptions;
|
|
8
10
|
private hybridTimers;
|
|
9
11
|
private lastFireTime;
|
|
10
|
-
constructor(pi: ExtensionAPI, scheduler: CronScheduler);
|
|
12
|
+
constructor(pi: ExtensionAPI, scheduler: CronScheduler, store: LoopStore);
|
|
11
13
|
start(): void;
|
|
12
14
|
stop(): void;
|
|
13
15
|
add(entry: LoopEntry): void;
|
package/dist/trigger-system.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export class TriggerSystem {
|
|
2
2
|
pi;
|
|
3
3
|
scheduler;
|
|
4
|
+
store;
|
|
4
5
|
eventSubscriptions = new Map();
|
|
5
6
|
hybridTimers = new Map();
|
|
6
7
|
lastFireTime = new Map();
|
|
7
|
-
constructor(pi, scheduler) {
|
|
8
|
+
constructor(pi, scheduler, store) {
|
|
8
9
|
this.pi = pi;
|
|
9
10
|
this.scheduler = scheduler;
|
|
11
|
+
this.store = store;
|
|
10
12
|
}
|
|
11
13
|
start() {
|
|
12
14
|
this.scheduler.start();
|
|
@@ -94,6 +96,10 @@ export class TriggerSystem {
|
|
|
94
96
|
trigger: entry.trigger,
|
|
95
97
|
timestamp: Date.now(),
|
|
96
98
|
});
|
|
99
|
+
if (!entry.recurring) {
|
|
100
|
+
this.remove(entry.id);
|
|
101
|
+
this.store.update(entry.id, { status: "expired" });
|
|
102
|
+
}
|
|
97
103
|
}
|
|
98
104
|
matchesFilter(data, filter) {
|
|
99
105
|
if (!filter)
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -69,7 +69,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
69
69
|
|
|
70
70
|
scheduler = new CronScheduler(store, onLoopFire);
|
|
71
71
|
widget.setScheduler(scheduler);
|
|
72
|
-
triggerSystem = new TriggerSystem(pi, scheduler);
|
|
72
|
+
triggerSystem = new TriggerSystem(pi, scheduler, store);
|
|
73
73
|
|
|
74
74
|
// ── pi-tasks integration ──
|
|
75
75
|
let tasksAvailable = false;
|
|
@@ -148,7 +148,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
148
148
|
widget.setStore(store);
|
|
149
149
|
scheduler = new CronScheduler(store, onLoopFire);
|
|
150
150
|
widget.setScheduler(scheduler);
|
|
151
|
-
triggerSystem = new TriggerSystem(pi, scheduler);
|
|
151
|
+
triggerSystem = new TriggerSystem(pi, scheduler, store);
|
|
152
152
|
}
|
|
153
153
|
storeUpgraded = true;
|
|
154
154
|
}
|
|
@@ -439,13 +439,17 @@ Use "pause" to temporarily stop a loop without removing it. Use "delete" to perm
|
|
|
439
439
|
pi.registerTool({
|
|
440
440
|
name: "MonitorCreate",
|
|
441
441
|
label: "MonitorCreate",
|
|
442
|
-
description: `
|
|
442
|
+
description: `Run a shell command in the background and get notified when it finishes. The core tool for async/parallel work.
|
|
443
443
|
|
|
444
|
-
|
|
444
|
+
Fire off a build check, CI monitor, experiment, script, or any slow command — then keep working. Output streams back as "monitor:output" events. When the process exits, "monitor:done" fires (or "monitor:error" on failure).
|
|
445
|
+
|
|
446
|
+
If you pass onDone with a prompt, the monitor auto-creates a one-shot completion loop — you get a system reminder with the exit code and output line count. No need to poll or create a separate loop.
|
|
447
|
+
|
|
448
|
+
DO NOT use raw Bash while/sleep/for loops to watch something. DO NOT run slow commands inline that could be offloaded. Use MonitorCreate to run work in parallel while you continue.
|
|
445
449
|
|
|
446
450
|
## When to Use
|
|
447
451
|
|
|
448
|
-
|
|
452
|
+
Default to MonitorCreate for any long-running or background work:\n- Watch a CI/CD build (hut, gh, curl polling) while you work on something else\n- Run experiments, benchmarks, or training scripts in parallel\n- Tail a log or poll an API endpoint\n- Fire off a slow curl/fetch and check the result later\n- Run any script or command you don't need to wait on inline
|
|
449
453
|
|
|
450
454
|
## Events emitted
|
|
451
455
|
|
|
@@ -453,10 +457,11 @@ Use this tool to:\n- Start a long-running experiment and get notified when it fi
|
|
|
453
457
|
|
|
454
458
|
## onDone — auto-notify on completion
|
|
455
459
|
|
|
456
|
-
Pass onDone with a prompt and the monitor auto-creates a one-shot loop that fires when the process exits. The system reminder includes the exit code and output line count
|
|
460
|
+
Pass onDone with a prompt and the monitor auto-creates a one-shot loop that fires when the process exits. The system reminder includes the exit code and output line count.\n\nExample: MonitorCreate command="python train.py" onDone="Check training results and report best loss"\nExample: MonitorCreate command="hut builds show 1769753" onDone="Analyze the build result and report status"`,
|
|
457
461
|
promptGuidelines: [
|
|
458
|
-
"
|
|
459
|
-
"When
|
|
462
|
+
"Default to MonitorCreate for any long-running or background command — releases the agent to keep working on other tasks in parallel.",
|
|
463
|
+
"When the user asks to monitor CI builds, watch a build, check a remote job, or run an experiment, use MonitorCreate instead of inline bash/curl/wait.",
|
|
464
|
+
"Use onDone to auto-notify when a background command finishes — the agent will pick up the results automatically.",
|
|
460
465
|
],
|
|
461
466
|
parameters: Type.Object({
|
|
462
467
|
command: Type.String({ description: "Shell command to run in background" }),
|
package/src/trigger-system.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { CronScheduler } from "./scheduler.js";
|
|
3
|
+
import type { LoopStore } from "./store.js";
|
|
3
4
|
import type { LoopEntry } from "./types.js";
|
|
4
5
|
|
|
5
6
|
export class TriggerSystem {
|
|
@@ -10,6 +11,7 @@ export class TriggerSystem {
|
|
|
10
11
|
constructor(
|
|
11
12
|
private pi: ExtensionAPI,
|
|
12
13
|
private scheduler: CronScheduler,
|
|
14
|
+
private store: LoopStore,
|
|
13
15
|
) {}
|
|
14
16
|
|
|
15
17
|
start(): void {
|
|
@@ -99,6 +101,11 @@ export class TriggerSystem {
|
|
|
99
101
|
trigger: entry.trigger,
|
|
100
102
|
timestamp: Date.now(),
|
|
101
103
|
});
|
|
104
|
+
|
|
105
|
+
if (!entry.recurring) {
|
|
106
|
+
this.remove(entry.id);
|
|
107
|
+
this.store.update(entry.id, { status: "expired" });
|
|
108
|
+
}
|
|
102
109
|
}
|
|
103
110
|
|
|
104
111
|
private matchesFilter(data: any, filter?: string): boolean {
|