Merge main into thedotmack/file-read-timeline-inject
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -397,6 +397,19 @@ export class PendingMessageStore {
|
||||
return result.count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Peek at pending message types for a session (for tier routing).
|
||||
* Returns list of { message_type, tool_name } without claiming.
|
||||
*/
|
||||
peekPendingTypes(sessionDbId: number): Array<{ message_type: string; tool_name: string | null }> {
|
||||
const stmt = this.db.prepare(`
|
||||
SELECT message_type, tool_name FROM pending_messages
|
||||
WHERE session_db_id = ? AND status IN ('pending', 'processing')
|
||||
ORDER BY id ASC
|
||||
`);
|
||||
return stmt.all(sessionDbId) as Array<{ message_type: string; tool_name: string | null }>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any session has pending work.
|
||||
* Excludes 'processing' messages stuck for >5 minutes (resets them to 'pending' as a side effect).
|
||||
|
||||
@@ -509,6 +509,38 @@ export const migration007: Migration = {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* All migrations in order
|
||||
*/
|
||||
/**
|
||||
* Migration 008: Observation feedback table for tracking observation usage
|
||||
*
|
||||
* Tracks how observations are used (semantic injection hits, search access,
|
||||
* explicit retrieval). Foundation for future Thompson Sampling optimization.
|
||||
*/
|
||||
export const migration008: Migration = {
|
||||
version: 25,
|
||||
up: (db: Database) => {
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS observation_feedback (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
observation_id INTEGER NOT NULL,
|
||||
signal_type TEXT NOT NULL,
|
||||
session_db_id INTEGER,
|
||||
created_at_epoch INTEGER NOT NULL,
|
||||
metadata TEXT,
|
||||
FOREIGN KEY (observation_id) REFERENCES observations(id) ON DELETE CASCADE
|
||||
)
|
||||
`);
|
||||
db.run(`CREATE INDEX IF NOT EXISTS idx_feedback_observation ON observation_feedback(observation_id)`);
|
||||
db.run(`CREATE INDEX IF NOT EXISTS idx_feedback_signal ON observation_feedback(signal_type)`);
|
||||
console.log('✅ Created observation_feedback table for usage tracking');
|
||||
},
|
||||
down: (db: Database) => {
|
||||
db.run(`DROP TABLE IF EXISTS observation_feedback`);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* All migrations in order
|
||||
*/
|
||||
@@ -519,5 +551,6 @@ export const migrations: Migration[] = [
|
||||
migration004,
|
||||
migration005,
|
||||
migration006,
|
||||
migration007
|
||||
migration007,
|
||||
migration008
|
||||
];
|
||||
@@ -34,6 +34,7 @@ export class MigrationRunner {
|
||||
this.addOnUpdateCascadeToForeignKeys();
|
||||
this.addObservationContentHashColumn();
|
||||
this.addSessionCustomTitleColumn();
|
||||
this.createObservationFeedbackTable();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -863,4 +864,31 @@ export class MigrationRunner {
|
||||
|
||||
this.db.prepare('INSERT OR IGNORE INTO schema_versions (version, applied_at) VALUES (?, ?)').run(23, new Date().toISOString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create observation_feedback table for tracking observation usage signals.
|
||||
* Foundation for tier routing optimization and future Thompson Sampling.
|
||||
* Schema version 24.
|
||||
*/
|
||||
private createObservationFeedbackTable(): void {
|
||||
const applied = this.db.query('SELECT 1 FROM schema_versions WHERE version = 24').get();
|
||||
if (applied) return;
|
||||
|
||||
this.db.run(`
|
||||
CREATE TABLE IF NOT EXISTS observation_feedback (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
observation_id INTEGER NOT NULL,
|
||||
signal_type TEXT NOT NULL,
|
||||
session_db_id INTEGER,
|
||||
created_at_epoch INTEGER NOT NULL,
|
||||
metadata TEXT,
|
||||
FOREIGN KEY (observation_id) REFERENCES observations(id) ON DELETE CASCADE
|
||||
)
|
||||
`);
|
||||
this.db.run('CREATE INDEX IF NOT EXISTS idx_feedback_observation ON observation_feedback(observation_id)');
|
||||
this.db.run('CREATE INDEX IF NOT EXISTS idx_feedback_signal ON observation_feedback(signal_type)');
|
||||
|
||||
this.db.prepare('INSERT OR IGNORE INTO schema_versions (version, applied_at) VALUES (?, ?)').run(24, new Date().toISOString());
|
||||
logger.debug('DB', 'Created observation_feedback table for usage tracking');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user