@thurstonsand/pi-agent-switchboard 0.0.0 → 0.1.0
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/index.js +33 -8
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -97,6 +97,7 @@ function branch(cwd) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// packages/pi/src/index.ts
|
|
100
|
+
import { Type } from "typebox";
|
|
100
101
|
var KEY = Symbol.for("agent-switchboard.recorder");
|
|
101
102
|
var store = globalThis;
|
|
102
103
|
function claim() {
|
|
@@ -230,6 +231,16 @@ function src_default(pi) {
|
|
|
230
231
|
pi.on("session_info_changed", (event, ctx) => {
|
|
231
232
|
writeFor(ctx, (db, id) => db.run("UPDATE sessions SET title = ? WHERE session_id = ?", event.name ?? null, id));
|
|
232
233
|
});
|
|
234
|
+
const markArchived = (ctx) => {
|
|
235
|
+
let archived = false;
|
|
236
|
+
writeFor(ctx, (db, id) => {
|
|
237
|
+
if (!db.get("SELECT 1 FROM sessions WHERE session_id = ?", id))
|
|
238
|
+
return;
|
|
239
|
+
db.run("INSERT INTO marks (session_id, archived_at) VALUES (?, ?) ON CONFLICT (session_id) DO UPDATE SET archived_at = excluded.archived_at", id, Date.now());
|
|
240
|
+
archived = true;
|
|
241
|
+
});
|
|
242
|
+
return archived;
|
|
243
|
+
};
|
|
233
244
|
pi.registerCommand("archive", {
|
|
234
245
|
description: "Archive this session in swb and quit",
|
|
235
246
|
handler: async (_args, ctx) => {
|
|
@@ -237,19 +248,33 @@ function src_default(pi) {
|
|
|
237
248
|
ctx.ui.notify("swb: turn running: wait for it to complete", "error");
|
|
238
249
|
return;
|
|
239
250
|
}
|
|
240
|
-
|
|
241
|
-
writeFor(ctx, (db, id) => {
|
|
242
|
-
if (!db.get("SELECT 1 FROM sessions WHERE session_id = ?", id))
|
|
243
|
-
return;
|
|
244
|
-
db.run("INSERT INTO marks (session_id, archived_at) VALUES (?, ?) ON CONFLICT (session_id) DO UPDATE SET archived_at = excluded.archived_at", id, Date.now());
|
|
245
|
-
archived = true;
|
|
246
|
-
});
|
|
247
|
-
if (archived)
|
|
251
|
+
if (markArchived(ctx))
|
|
248
252
|
ctx.shutdown();
|
|
249
253
|
else if (!proc.failure)
|
|
250
254
|
ctx.ui.notify("swb: nothing to archive before the first prompt", "error");
|
|
251
255
|
}
|
|
252
256
|
});
|
|
257
|
+
pi.registerTool({
|
|
258
|
+
name: "swb_archive",
|
|
259
|
+
label: "Archive session",
|
|
260
|
+
description: "Archive this session in Agent Switchboard. It leaves the user's roster of open sessions, and pi quits as soon as this turn ends. The user can restore it with `swb unarchive <id>`.",
|
|
261
|
+
promptSnippet: "Archive this session when the user asks",
|
|
262
|
+
promptGuidelines: [
|
|
263
|
+
"Use swb_archive only when the user asks to archive this session; never archive on your own initiative.",
|
|
264
|
+
"Call swb_archive as the last action of the turn, then end with a brief final message: pi quits once the turn ends."
|
|
265
|
+
],
|
|
266
|
+
parameters: Type.Object({}),
|
|
267
|
+
async execute(_toolCallId, _params, _signal, _onUpdate, ctx) {
|
|
268
|
+
if (!markArchived(ctx)) {
|
|
269
|
+
throw new Error(proc.failure ? `swb: not recording: ${proc.failure}` : "swb: no session recorded yet");
|
|
270
|
+
}
|
|
271
|
+
ctx.shutdown();
|
|
272
|
+
return {
|
|
273
|
+
content: [{ type: "text", text: "Archived. pi quits when this turn ends." }],
|
|
274
|
+
details: undefined
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
});
|
|
253
278
|
pi.on("session_shutdown", (event, ctx) => {
|
|
254
279
|
if (event.reason !== "quit")
|
|
255
280
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thurstonsand/pi-agent-switchboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Records managed pi sessions for Agent Switchboard (swb)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@earendil-works/pi-coding-agent": "*"
|
|
20
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
21
|
+
"typebox": "*"
|
|
21
22
|
}
|
|
22
23
|
}
|