@postnesia/hooks 0.1.4 → 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 +63 -0
- package/dist/claude.js +6 -0
- package/dist/handler.d.ts +1 -1
- package/dist/handler.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +5 -3
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/handler.d.ts
CHANGED
|
@@ -42,5 +42,5 @@ export type AgentBootstrapHookEvent = InternalHookEvent & {
|
|
|
42
42
|
action: "bootstrap";
|
|
43
43
|
context: AgentBootstrapHookContext;
|
|
44
44
|
};
|
|
45
|
-
declare function handler(event: AgentBootstrapHookEvent):
|
|
45
|
+
declare function handler(event: AgentBootstrapHookEvent): AgentBootstrapHookEvent;
|
|
46
46
|
export default handler;
|
package/dist/handler.js
CHANGED
|
@@ -9,10 +9,11 @@ export const DEFAULT_BOOTSTRAP_FILENAME = "BOOTSTRAP.md";
|
|
|
9
9
|
export const DEFAULT_MEMORY_FILENAME = "MEMORY.md";
|
|
10
10
|
export const DEFAULT_MEMORY_ALT_FILENAME = "memory.md";
|
|
11
11
|
function handler(event) {
|
|
12
|
-
|
|
12
|
+
event.context.bootstrapFiles.map((file) => {
|
|
13
13
|
if (file.name === 'BOOTSTRAP.md') {
|
|
14
14
|
file.content = format(loadL1Memories());
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
+
return event;
|
|
17
18
|
}
|
|
18
19
|
export default handler;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postnesia/hooks",
|
|
3
|
-
"version": "0.1.
|
|
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.
|
|
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
|
}
|