Add comprehensive documentation for claude-mem codebase and create a test worker script

- Introduced CODEMAP.md detailing project overview, architecture, directory structure, core components, commands, hooks system, SDK, services, shared components, utilities, and key workflows.
- Added a test-worker.sh script to automate testing of the SDK worker, including session creation, worker initiation, socket communication, and cleanup after finalization.
This commit is contained in:
Alex Newman
2025-10-16 13:56:18 -04:00
parent 18aa4f2538
commit 6e9be84a01
10 changed files with 2074 additions and 228 deletions
-56
View File
@@ -103,62 +103,6 @@ export class HooksDatabase {
query.run(sdkSessionId, id);
}
/**
* Queue an observation for SDK processing
*/
queueObservation(
sdkSessionId: string,
toolName: string,
toolInput: string,
toolOutput: string
): void {
const nowEpoch = Date.now();
const query = this.db.query(`
INSERT INTO observation_queue
(sdk_session_id, tool_name, tool_input, tool_output, created_at_epoch)
VALUES (?, ?, ?, ?, ?)
`);
query.run(sdkSessionId, toolName, toolInput, toolOutput, nowEpoch);
}
/**
* Get pending observations for SDK processing
*/
getPendingObservations(sdkSessionId: string, limit: number = 10): Array<{
id: number;
tool_name: string;
tool_input: string;
tool_output: string;
created_at_epoch: number;
}> {
const query = this.db.query(`
SELECT id, tool_name, tool_input, tool_output, created_at_epoch
FROM observation_queue
WHERE sdk_session_id = ? AND processed_at_epoch IS NULL
ORDER BY created_at_epoch ASC
LIMIT ?
`);
return query.all(sdkSessionId, limit) as any[];
}
/**
* Mark observation as processed
*/
markObservationProcessed(id: number): void {
const nowEpoch = Date.now();
const query = this.db.query(`
UPDATE observation_queue
SET processed_at_epoch = ?
WHERE id = ?
`);
query.run(nowEpoch, id);
}
/**
* Store an observation (from SDK parsing)
*/
+59 -1
View File
@@ -305,6 +305,63 @@ export const migration004: Migration = {
}
};
/**
* Migration 005 - Remove orphaned tables
* Drops streaming_sessions (superseded by sdk_sessions)
* Drops observation_queue (superseded by Unix socket communication)
*/
export const migration005: Migration = {
version: 5,
up: (db: Database) => {
// Drop streaming_sessions - superseded by sdk_sessions in migration004
// This table was from v2 architecture and is no longer used
db.run(`DROP TABLE IF EXISTS streaming_sessions`);
// Drop observation_queue - superseded by Unix socket communication
// Worker now uses sockets instead of database polling for observations
db.run(`DROP TABLE IF EXISTS observation_queue`);
console.log('✅ Dropped orphaned tables: streaming_sessions, observation_queue');
},
down: (db: Database) => {
// Recreate tables if needed (though they should never be used)
db.run(`
CREATE TABLE IF NOT EXISTS streaming_sessions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
claude_session_id TEXT UNIQUE NOT NULL,
sdk_session_id TEXT,
project TEXT NOT NULL,
title TEXT,
subtitle TEXT,
user_prompt TEXT,
started_at TEXT NOT NULL,
started_at_epoch INTEGER NOT NULL,
updated_at TEXT,
updated_at_epoch INTEGER,
completed_at TEXT,
completed_at_epoch INTEGER,
status TEXT NOT NULL DEFAULT 'active'
)
`);
db.run(`
CREATE TABLE IF NOT EXISTS observation_queue (
id INTEGER PRIMARY KEY AUTOINCREMENT,
sdk_session_id TEXT NOT NULL,
tool_name TEXT NOT NULL,
tool_input TEXT NOT NULL,
tool_output TEXT NOT NULL,
created_at_epoch INTEGER NOT NULL,
processed_at_epoch INTEGER,
FOREIGN KEY(sdk_session_id) REFERENCES sdk_sessions(sdk_session_id) ON DELETE CASCADE
)
`);
console.log('⚠️ Recreated streaming_sessions and observation_queue (for rollback only)');
}
};
/**
* All migrations in order
*/
@@ -312,5 +369,6 @@ export const migrations: Migration[] = [
migration001,
migration002,
migration003,
migration004
migration004,
migration005
];