@postnesia/bootstrap 0.1.2
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/claude.d.ts +1 -0
- package/dist/claude.js +5 -0
- package/dist/handler.d.ts +46 -0
- package/dist/handler.js +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +39 -0
- package/package.json +33 -0
package/dist/claude.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/claude.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare const DEFAULT_AGENTS_FILENAME = "AGENTS.md";
|
|
2
|
+
export declare const DEFAULT_SOUL_FILENAME = "SOUL.md";
|
|
3
|
+
export declare const DEFAULT_TOOLS_FILENAME = "TOOLS.md";
|
|
4
|
+
export declare const DEFAULT_IDENTITY_FILENAME = "IDENTITY.md";
|
|
5
|
+
export declare const DEFAULT_USER_FILENAME = "USER.md";
|
|
6
|
+
export declare const DEFAULT_HEARTBEAT_FILENAME = "HEARTBEAT.md";
|
|
7
|
+
export declare const DEFAULT_BOOTSTRAP_FILENAME = "BOOTSTRAP.md";
|
|
8
|
+
export declare const DEFAULT_MEMORY_FILENAME = "MEMORY.md";
|
|
9
|
+
export declare const DEFAULT_MEMORY_ALT_FILENAME = "memory.md";
|
|
10
|
+
export type WorkspaceBootstrapFileName = typeof DEFAULT_AGENTS_FILENAME | typeof DEFAULT_SOUL_FILENAME | typeof DEFAULT_TOOLS_FILENAME | typeof DEFAULT_IDENTITY_FILENAME | typeof DEFAULT_USER_FILENAME | typeof DEFAULT_HEARTBEAT_FILENAME | typeof DEFAULT_BOOTSTRAP_FILENAME | typeof DEFAULT_MEMORY_FILENAME | typeof DEFAULT_MEMORY_ALT_FILENAME;
|
|
11
|
+
export type WorkspaceBootstrapFile = {
|
|
12
|
+
name: WorkspaceBootstrapFileName;
|
|
13
|
+
path: string;
|
|
14
|
+
content?: string;
|
|
15
|
+
missing: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type InternalHookEventType = "command" | "session" | "agent" | "gateway";
|
|
18
|
+
export type AgentBootstrapHookContext = {
|
|
19
|
+
workspaceDir: string;
|
|
20
|
+
bootstrapFiles: WorkspaceBootstrapFile[];
|
|
21
|
+
cfg?: unknown;
|
|
22
|
+
sessionKey?: string;
|
|
23
|
+
sessionId?: string;
|
|
24
|
+
agentId?: string;
|
|
25
|
+
};
|
|
26
|
+
export interface InternalHookEvent {
|
|
27
|
+
/** The type of event (command, session, agent, gateway, etc.) */
|
|
28
|
+
type: InternalHookEventType;
|
|
29
|
+
/** The specific action within the type (e.g., 'new', 'reset', 'stop') */
|
|
30
|
+
action: string;
|
|
31
|
+
/** The session key this event relates to */
|
|
32
|
+
sessionKey: string;
|
|
33
|
+
/** Additional context specific to the event */
|
|
34
|
+
context: Record<string, unknown>;
|
|
35
|
+
/** Timestamp when the event occurred */
|
|
36
|
+
timestamp: Date;
|
|
37
|
+
/** Messages to send back to the user (hooks can push to this array) */
|
|
38
|
+
messages: string[];
|
|
39
|
+
}
|
|
40
|
+
export type AgentBootstrapHookEvent = InternalHookEvent & {
|
|
41
|
+
type: "agent";
|
|
42
|
+
action: "bootstrap";
|
|
43
|
+
context: AgentBootstrapHookContext;
|
|
44
|
+
};
|
|
45
|
+
declare function handler(event: AgentBootstrapHookEvent): void[];
|
|
46
|
+
export default handler;
|
package/dist/handler.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { format, loadL1Memories } from './index.js';
|
|
2
|
+
export const DEFAULT_AGENTS_FILENAME = "AGENTS.md";
|
|
3
|
+
export const DEFAULT_SOUL_FILENAME = "SOUL.md";
|
|
4
|
+
export const DEFAULT_TOOLS_FILENAME = "TOOLS.md";
|
|
5
|
+
export const DEFAULT_IDENTITY_FILENAME = "IDENTITY.md";
|
|
6
|
+
export const DEFAULT_USER_FILENAME = "USER.md";
|
|
7
|
+
export const DEFAULT_HEARTBEAT_FILENAME = "HEARTBEAT.md";
|
|
8
|
+
export const DEFAULT_BOOTSTRAP_FILENAME = "BOOTSTRAP.md";
|
|
9
|
+
export const DEFAULT_MEMORY_FILENAME = "MEMORY.md";
|
|
10
|
+
export const DEFAULT_MEMORY_ALT_FILENAME = "memory.md";
|
|
11
|
+
function handler(event) {
|
|
12
|
+
return event.context.bootstrapFiles.map((file) => {
|
|
13
|
+
if (file.name === 'BOOTSTRAP.md') {
|
|
14
|
+
file.content = format(loadL1Memories());
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export default handler;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Session Bootstrap Hook
|
|
4
|
+
* Loads core and top L1 memories from the Postnesia DB into model context at session start.
|
|
5
|
+
* Output (stdout) is injected into the conversation by the Claude Code SessionStart hook.
|
|
6
|
+
*/
|
|
7
|
+
interface L1Memory {
|
|
8
|
+
id: number;
|
|
9
|
+
type: string;
|
|
10
|
+
core: number;
|
|
11
|
+
importance: number;
|
|
12
|
+
effective_importance: number;
|
|
13
|
+
content_l1: string;
|
|
14
|
+
last_accessed: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function loadL1Memories(): L1Memory[];
|
|
17
|
+
export declare function format(memories: L1Memory[]): string;
|
|
18
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Session Bootstrap Hook
|
|
4
|
+
* Loads core and top L1 memories from the Postnesia DB into model context at session start.
|
|
5
|
+
* Output (stdout) is injected into the conversation by the Claude Code SessionStart hook.
|
|
6
|
+
*/
|
|
7
|
+
import { getDb, queries } from '@postnesia/db';
|
|
8
|
+
export function loadL1Memories() {
|
|
9
|
+
try {
|
|
10
|
+
const db = getDb(true);
|
|
11
|
+
return queries.getL1Summaries(db).all();
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
if (err.code === 'SQLITE_EOPEN')
|
|
15
|
+
process.exit(0);
|
|
16
|
+
throw err;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function format(memories) {
|
|
20
|
+
if (memories.length === 0)
|
|
21
|
+
return '';
|
|
22
|
+
const core = memories.filter(m => m.core === 1);
|
|
23
|
+
const regular = memories.filter(m => m.core === 0);
|
|
24
|
+
const lines = ['--- POSTNESIA MEMORY CONTEXT ---'];
|
|
25
|
+
if (core.length > 0) {
|
|
26
|
+
lines.push('\n[CORE MEMORIES]');
|
|
27
|
+
for (const m of core) {
|
|
28
|
+
lines.push(`#${m.id} [${m.type}] ${m.content_l1}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (regular.length > 0) {
|
|
32
|
+
lines.push('\n[WORKING MEMORY — L1 summaries, importance ≥ 3]');
|
|
33
|
+
for (const m of regular) {
|
|
34
|
+
lines.push(`#${m.id} [${m.type}] (imp:${m.importance}) ${m.content_l1}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
lines.push('\n--- END MEMORY CONTEXT ---');
|
|
38
|
+
return lines.join('\n');
|
|
39
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@postnesia/bootstrap",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Session bootstrap hook — loads L1 memory context at startup",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"bin": {
|
|
10
|
+
"postnesia-claude": "./dist/claude.js"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.ts"
|
|
16
|
+
},
|
|
17
|
+
"./handler": {
|
|
18
|
+
"types": "./dist/handler.d.ts",
|
|
19
|
+
"import": "./dist/handler.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@postnesia/db": "0.1.2"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^22.10.5",
|
|
27
|
+
"tsx": "^4.19.2",
|
|
28
|
+
"typescript": "^5.7.3"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc -p tsconfig.json"
|
|
32
|
+
}
|
|
33
|
+
}
|