@trevonistrevon/pi-loop 0.2.3 → 0.2.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 +9 -21
- package/package.json +1 -1
- package/src/index.ts +9 -23
package/dist/index.js
CHANGED
|
@@ -30,10 +30,6 @@ function debug(...args) {
|
|
|
30
30
|
function textResult(msg) {
|
|
31
31
|
return { content: [{ type: "text", text: msg }], details: undefined };
|
|
32
32
|
}
|
|
33
|
-
const SYSTEM_REMINDER_TEMPLATE = `<system-reminder>
|
|
34
|
-
Loop "%prompt%" fired. Execute this instruction now.
|
|
35
|
-
Trigger: %trigger_info%. Loop: %loop_id%.
|
|
36
|
-
</system-reminder>`;
|
|
37
33
|
export default function (pi) {
|
|
38
34
|
const piLoopEnv = process.env.PI_LOOP;
|
|
39
35
|
const piLoopScope = process.env.PI_LOOP_SCOPE;
|
|
@@ -167,16 +163,6 @@ export default function (pi) {
|
|
|
167
163
|
widget.setUICtx(ctx.ui);
|
|
168
164
|
upgradeStoreIfNeeded(ctx);
|
|
169
165
|
showPersistedLoops();
|
|
170
|
-
if (pendingReminders.length > 0) {
|
|
171
|
-
const reminder = pendingReminders.shift();
|
|
172
|
-
return {
|
|
173
|
-
message: {
|
|
174
|
-
customType: "pi-loop",
|
|
175
|
-
content: reminder,
|
|
176
|
-
display: false,
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
166
|
});
|
|
181
167
|
pi.on("session_switch", async (event, ctx) => {
|
|
182
168
|
_latestCtx = ctx;
|
|
@@ -191,8 +177,7 @@ export default function (pi) {
|
|
|
191
177
|
upgradeStoreIfNeeded(ctx);
|
|
192
178
|
showPersistedLoops(isResume);
|
|
193
179
|
});
|
|
194
|
-
// ──
|
|
195
|
-
const pendingReminders = [];
|
|
180
|
+
// ── Loop fire handler — sends a user message to re-wake the agent ──
|
|
196
181
|
pi.events.on("loop:fire", (data) => {
|
|
197
182
|
const triggerInfo = typeof data.trigger === "string"
|
|
198
183
|
? data.trigger
|
|
@@ -201,11 +186,14 @@ export default function (pi) {
|
|
|
201
186
|
: data.trigger?.type === "event"
|
|
202
187
|
? `event: ${data.trigger.source}`
|
|
203
188
|
: `hybrid`;
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
.
|
|
207
|
-
|
|
208
|
-
|
|
189
|
+
const prompt = data.prompt || "loop fired";
|
|
190
|
+
const message = [
|
|
191
|
+
`[pi-loop] Loop #${data.loopId || "?"} fired (${triggerInfo}).`,
|
|
192
|
+
prompt,
|
|
193
|
+
].join("\n");
|
|
194
|
+
// deliverAs: "followUp" queues the message when the agent is busy;
|
|
195
|
+
// it delivers after the current turn finishes.
|
|
196
|
+
pi.sendUserMessage(message, { deliverAs: "followUp" });
|
|
209
197
|
});
|
|
210
198
|
// ──────────────────────────────────────────────────
|
|
211
199
|
// Tool 1: LoopCreate
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -35,10 +35,6 @@ function textResult(msg: string) {
|
|
|
35
35
|
return { content: [{ type: "text" as const, text: msg }], details: undefined as any };
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const SYSTEM_REMINDER_TEMPLATE = `<system-reminder>
|
|
39
|
-
Loop "%prompt%" fired. Execute this instruction now.
|
|
40
|
-
Trigger: %trigger_info%. Loop: %loop_id%.
|
|
41
|
-
</system-reminder>`;
|
|
42
38
|
|
|
43
39
|
export default function (pi: ExtensionAPI) {
|
|
44
40
|
const piLoopEnv = process.env.PI_LOOP;
|
|
@@ -174,17 +170,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
174
170
|
widget.setUICtx(ctx.ui as UICtx);
|
|
175
171
|
upgradeStoreIfNeeded(ctx);
|
|
176
172
|
showPersistedLoops();
|
|
177
|
-
|
|
178
|
-
if (pendingReminders.length > 0) {
|
|
179
|
-
const reminder = pendingReminders.shift()!;
|
|
180
|
-
return {
|
|
181
|
-
message: {
|
|
182
|
-
customType: "pi-loop",
|
|
183
|
-
content: reminder,
|
|
184
|
-
display: false,
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
173
|
});
|
|
189
174
|
|
|
190
175
|
pi.on("session_switch" as any, async (event: any, ctx: ExtensionContext) => {
|
|
@@ -204,9 +189,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
204
189
|
showPersistedLoops(isResume);
|
|
205
190
|
});
|
|
206
191
|
|
|
207
|
-
// ──
|
|
208
|
-
|
|
209
|
-
const pendingReminders: string[] = [];
|
|
192
|
+
// ── Loop fire handler — sends a user message to re-wake the agent ──
|
|
210
193
|
|
|
211
194
|
pi.events.on("loop:fire", (data: any) => {
|
|
212
195
|
const triggerInfo = typeof data.trigger === "string"
|
|
@@ -217,12 +200,15 @@ export default function (pi: ExtensionAPI) {
|
|
|
217
200
|
? `event: ${data.trigger.source}`
|
|
218
201
|
: `hybrid`;
|
|
219
202
|
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
.
|
|
223
|
-
|
|
203
|
+
const prompt = data.prompt || "loop fired";
|
|
204
|
+
const message = [
|
|
205
|
+
`[pi-loop] Loop #${data.loopId || "?"} fired (${triggerInfo}).`,
|
|
206
|
+
prompt,
|
|
207
|
+
].join("\n");
|
|
224
208
|
|
|
225
|
-
|
|
209
|
+
// deliverAs: "followUp" queues the message when the agent is busy;
|
|
210
|
+
// it delivers after the current turn finishes.
|
|
211
|
+
pi.sendUserMessage(message, { deliverAs: "followUp" });
|
|
226
212
|
});
|
|
227
213
|
|
|
228
214
|
// ──────────────────────────────────────────────────
|