@postnesia/hooks 0.1.5 → 0.1.6

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/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # @postnesia/hooks
2
+
3
+ Session bootstrap hook for Postnesia. Loads core memories and high-importance L1 summaries from the database and injects them into the agent's context at session start.
4
+
5
+ ## How it works
6
+
7
+ At session start the hook queries the database for:
8
+ - All **core memories** (always loaded, never decay)
9
+ - **Working memory** — non-core memories with importance >= 3
10
+
11
+ Output is written to stdout in a structured block:
12
+
13
+ ```
14
+ --- POSTNESIA MEMORY CONTEXT ---
15
+
16
+ [CORE MEMORIES]
17
+ #1 [technical] How Postnesia is used...
18
+
19
+ [WORKING MEMORY — L1 summaries, importance >= 3]
20
+ #4 [lesson] (imp:4) Learned that...
21
+
22
+ --- END MEMORY CONTEXT ---
23
+ ```
24
+
25
+ Claude Code injects stdout from `SessionStart` hooks into the conversation, so the agent sees this context before the first user message.
26
+
27
+ If the database does not exist yet the hook exits silently (no error).
28
+
29
+ ## Usage
30
+
31
+ ### Claude Code (SessionStart hook)
32
+
33
+ Add to `.claude/settings.json`:
34
+
35
+ ```json
36
+ {
37
+ "hooks": {
38
+ "SessionStart": [
39
+ {
40
+ "matcher": "",
41
+ "hooks": [
42
+ {
43
+ "type": "command",
44
+ "command": "npx postnesia-claude"
45
+ }
46
+ ]
47
+ }
48
+ ]
49
+ }
50
+ }
51
+ ```
52
+
53
+ ### Programmatic (handler export)
54
+
55
+ The `./handler` export provides a handler that can be wired into other agent frameworks. It populates the `BOOTSTRAP.md` bootstrap file slot with the formatted memory context:
56
+
57
+ ```ts
58
+ import handler from '@postnesia/hooks/handler';
59
+ ```
60
+
61
+ ## Environment Variables
62
+
63
+ Inherits from `@postnesia/db` — requires `DATABASE_URL` to be set.
package/dist/claude.js CHANGED
@@ -1,4 +1,10 @@
1
1
  import { format, loadL1Memories } from './index.js';
2
+ const chunks = [];
3
+ for await (const chunk of process.stdin) {
4
+ chunks.push(chunk);
5
+ }
6
+ const payload = JSON.parse(Buffer.concat(chunks).toString('utf-8'));
7
+ console.log(payload, 'payload');
2
8
  const memories = loadL1Memories();
3
9
  const output = format(memories);
4
10
  if (output)
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ interface L1Memory {
10
10
  core: number;
11
11
  importance: number;
12
12
  effective_importance: number;
13
+ content: string;
13
14
  content_l1: string;
14
15
  last_accessed: string;
15
16
  }
package/dist/index.js CHANGED
@@ -25,7 +25,7 @@ export function format(memories) {
25
25
  if (core.length > 0) {
26
26
  lines.push('\n[CORE MEMORIES]');
27
27
  for (const m of core) {
28
- lines.push(`#${m.id} [${m.type}] ${m.content_l1}`);
28
+ lines.push(m.content);
29
29
  }
30
30
  }
31
31
  if (regular.length > 0) {
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@postnesia/hooks",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Session bootstrap hook — loads L1 memory context at startup",
5
5
  "type": "module",
6
+ "private": false,
6
7
  "files": [
7
8
  "dist"
8
9
  ],
@@ -20,7 +21,7 @@
20
21
  }
21
22
  },
22
23
  "dependencies": {
23
- "@postnesia/db": "^0.1.3"
24
+ "@postnesia/db": "^0.1.5"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@types/node": "^22.10.5",
@@ -28,6 +29,7 @@
28
29
  "typescript": "^5.7.3"
29
30
  },
30
31
  "scripts": {
31
- "build": "tsc -p tsconfig.json"
32
+ "build": "pnpm clean && tsc -p tsconfig.json",
33
+ "clean": "rm -rf ./dist"
32
34
  }
33
35
  }