@trevonistrevon/pi-loop 0.2.6 → 0.2.7
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 +4 -9
- package/package.json +1 -1
- package/src/index.ts +6 -12
package/dist/index.js
CHANGED
|
@@ -179,9 +179,12 @@ export default function (pi) {
|
|
|
179
179
|
showPersistedLoops(isResume);
|
|
180
180
|
});
|
|
181
181
|
// ── Loop fire handler — sends a user message to re-wake the agent ──
|
|
182
|
-
const pendingFollowUps = new Set();
|
|
183
182
|
pi.events.on("loop:fire", (event) => {
|
|
184
183
|
const data = event;
|
|
184
|
+
if (_latestCtx?.hasPendingMessages()) {
|
|
185
|
+
debug(`loop:fire #${data.loopId} — agent has pending messages, skipping`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
185
188
|
const triggerInfo = typeof data.trigger === "string"
|
|
186
189
|
? data.trigger
|
|
187
190
|
: data.trigger?.type === "cron"
|
|
@@ -190,22 +193,14 @@ export default function (pi) {
|
|
|
190
193
|
? `event: ${data.trigger.source}`
|
|
191
194
|
: `hybrid`;
|
|
192
195
|
const loopId = data.loopId || "?";
|
|
193
|
-
if (pendingFollowUps.has(loopId)) {
|
|
194
|
-
debug(`loop:fire #${loopId} — follow-up already queued, skipping`);
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
pendingFollowUps.add(loopId);
|
|
198
196
|
const prompt = data.prompt || "loop fired";
|
|
199
197
|
const constraint = data.readOnly ? "\n\nREAD-ONLY MODE — use only read tools (Read, TaskList, LoopList, MonitorList, LoopCreate, etc.). No file writes, shell execution, or destructive changes." : "";
|
|
200
198
|
const message = [
|
|
201
199
|
`[pi-loop] Loop #${loopId} fired (${triggerInfo}).${constraint}`,
|
|
202
200
|
prompt,
|
|
203
201
|
].join("\n");
|
|
204
|
-
// deliverAs: "followUp" queues the message when the agent is busy;
|
|
205
|
-
// it delivers after the current turn finishes.
|
|
206
202
|
pi.sendUserMessage(message, { deliverAs: "followUp" });
|
|
207
203
|
});
|
|
208
|
-
pi.on("turn_end", () => { pendingFollowUps.clear(); });
|
|
209
204
|
// ──────────────────────────────────────────────────
|
|
210
205
|
// Tool 1: LoopCreate
|
|
211
206
|
// ──────────────────────────────────────────────────
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -204,10 +204,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
204
204
|
|
|
205
205
|
// ── Loop fire handler — sends a user message to re-wake the agent ──
|
|
206
206
|
|
|
207
|
-
const pendingFollowUps = new Set<string>();
|
|
208
|
-
|
|
209
207
|
pi.events.on("loop:fire", (event: unknown) => {
|
|
210
208
|
const data = event as LoopFireEvent;
|
|
209
|
+
|
|
210
|
+
if (_latestCtx?.hasPendingMessages()) {
|
|
211
|
+
debug(`loop:fire #${data.loopId} — agent has pending messages, skipping`);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
211
215
|
const triggerInfo = typeof data.trigger === "string"
|
|
212
216
|
? data.trigger
|
|
213
217
|
: data.trigger?.type === "cron"
|
|
@@ -217,12 +221,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
217
221
|
: `hybrid`;
|
|
218
222
|
|
|
219
223
|
const loopId = data.loopId || "?";
|
|
220
|
-
if (pendingFollowUps.has(loopId)) {
|
|
221
|
-
debug(`loop:fire #${loopId} — follow-up already queued, skipping`);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
pendingFollowUps.add(loopId);
|
|
225
|
-
|
|
226
224
|
const prompt = data.prompt || "loop fired";
|
|
227
225
|
const constraint = data.readOnly ? "\n\nREAD-ONLY MODE — use only read tools (Read, TaskList, LoopList, MonitorList, LoopCreate, etc.). No file writes, shell execution, or destructive changes." : "";
|
|
228
226
|
const message = [
|
|
@@ -230,13 +228,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
230
228
|
prompt,
|
|
231
229
|
].join("\n");
|
|
232
230
|
|
|
233
|
-
// deliverAs: "followUp" queues the message when the agent is busy;
|
|
234
|
-
// it delivers after the current turn finishes.
|
|
235
231
|
pi.sendUserMessage(message, { deliverAs: "followUp" });
|
|
236
232
|
});
|
|
237
233
|
|
|
238
|
-
pi.on("turn_end", () => { pendingFollowUps.clear(); });
|
|
239
|
-
|
|
240
234
|
// ──────────────────────────────────────────────────
|
|
241
235
|
// Tool 1: LoopCreate
|
|
242
236
|
// ──────────────────────────────────────────────────
|