@ivotoby/postgram-cli 1.38.2 → 1.39.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.
@@ -0,0 +1,73 @@
1
+ // Postgram pi extension.
2
+ //
3
+ // No dependency on pi packages: it declares the few members it uses and
4
+ // shells out to `pgm here` so there is one code path. `pgm hooks install --pi`
5
+ // copies this file into the pi extensions directory and replaces the
6
+ // PGM_NODE / PGM_SCRIPT placeholders with absolute paths.
7
+
8
+ type Ctx = {
9
+ cwd: string;
10
+ sessionManager: { getSessionId(): string };
11
+ };
12
+
13
+ type Pi = {
14
+ on(event: string, handler: (event: unknown, ctx: Ctx) => unknown): void;
15
+ exec(
16
+ command: string,
17
+ args: string[],
18
+ options: { timeout: number }
19
+ ): Promise<unknown>;
20
+ };
21
+
22
+ const PGM_NODE: string = '__PGM_NODE__';
23
+ const PGM_SCRIPT: string = '__PGM_SCRIPT__';
24
+
25
+ const ACTIVITY_THROTTLE_MS = 60_000;
26
+ let lastActivityAt = 0;
27
+
28
+ function hereArgs(event: string, ctx: Ctx): string[] {
29
+ return [
30
+ PGM_SCRIPT,
31
+ 'here',
32
+ '--agent',
33
+ 'pi',
34
+ '--session-id',
35
+ ctx.sessionManager.getSessionId(),
36
+ '--event',
37
+ event,
38
+ '--cwd',
39
+ ctx.cwd,
40
+ '--quiet'
41
+ ];
42
+ }
43
+
44
+ function fire(pi: Pi, event: string, ctx: Ctx): void {
45
+ void pi
46
+ .exec(PGM_NODE, hereArgs(event, ctx), { timeout: 5000 })
47
+ .catch(() => undefined);
48
+ }
49
+
50
+ export default function postgram(pi: Pi): void {
51
+ pi.on('session_start', (_event, ctx) => {
52
+ fire(pi, 'start', ctx);
53
+ });
54
+
55
+ pi.on('turn_end', (_event, ctx) => {
56
+ const now = Date.now();
57
+ if (now - lastActivityAt < ACTIVITY_THROTTLE_MS) {
58
+ return;
59
+ }
60
+ lastActivityAt = now;
61
+ fire(pi, 'activity', ctx);
62
+ });
63
+
64
+ pi.on('agent_settled', (_event, ctx) => {
65
+ fire(pi, 'stop', ctx);
66
+ });
67
+
68
+ pi.on('session_shutdown', async (_event, ctx) => {
69
+ await pi
70
+ .exec(PGM_NODE, hereArgs('end', ctx), { timeout: 5000 })
71
+ .catch(() => undefined);
72
+ });
73
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ivotoby/postgram-cli",
3
- "version": "1.38.2",
3
+ "version": "1.39.0",
4
4
  "description": "Postgram CLI — store, search, and manage entities from the command line",
5
5
  "type": "module",
6
6
  "bin": {
@@ -8,6 +8,7 @@
8
8
  },
9
9
  "files": [
10
10
  "dist",
11
+ "integrations",
11
12
  "README.md"
12
13
  ],
13
14
  "repository": {