v2: SQLite state adapter, admin commands, compact feedback
- Replace in-memory Chat SDK state with SqliteStateAdapter — thread subscriptions now persist across restarts - Add migration 002 for chat_sdk_kv, subscriptions, locks, lists tables - Handle /clear in agent-runner (reset sessionId) — SDK has supportsNonInteractive:false for this command - Pass /compact, /context, /cost, /files through to SDK as admin commands - Skip admin commands in follow-up poll so they start fresh queries - Emit compact_boundary events as user-visible feedback messages - Pass NANOCLAW_ADMIN_USER_ID and NANOCLAW_ASSISTANT_NAME to containers Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
36
src/db/migrations/002-chat-sdk-state.ts
Normal file
36
src/db/migrations/002-chat-sdk-state.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import type Database from 'better-sqlite3';
|
||||
|
||||
import type { Migration } from './index.js';
|
||||
|
||||
export const migration002: Migration = {
|
||||
version: 2,
|
||||
name: 'chat-sdk-state',
|
||||
up(db: Database.Database) {
|
||||
db.exec(`
|
||||
CREATE TABLE chat_sdk_kv (
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT NOT NULL,
|
||||
expires_at INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE chat_sdk_subscriptions (
|
||||
thread_id TEXT PRIMARY KEY,
|
||||
subscribed_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
CREATE TABLE chat_sdk_locks (
|
||||
thread_id TEXT PRIMARY KEY,
|
||||
token TEXT NOT NULL,
|
||||
expires_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE chat_sdk_lists (
|
||||
key TEXT NOT NULL,
|
||||
idx INTEGER NOT NULL,
|
||||
value TEXT NOT NULL,
|
||||
expires_at INTEGER,
|
||||
PRIMARY KEY (key, idx)
|
||||
);
|
||||
`);
|
||||
},
|
||||
};
|
||||
@@ -2,6 +2,7 @@ import type Database from 'better-sqlite3';
|
||||
|
||||
import { log } from '../../log.js';
|
||||
import { migration001 } from './001-initial.js';
|
||||
import { migration002 } from './002-chat-sdk-state.js';
|
||||
|
||||
export interface Migration {
|
||||
version: number;
|
||||
@@ -9,7 +10,7 @@ export interface Migration {
|
||||
up: (db: Database.Database) => void;
|
||||
}
|
||||
|
||||
const migrations: Migration[] = [migration001];
|
||||
const migrations: Migration[] = [migration001, migration002];
|
||||
|
||||
export function runMigrations(db: Database.Database): void {
|
||||
db.exec(`
|
||||
|
||||
Reference in New Issue
Block a user