principles-disciple 1.154.0 → 1.156.0
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/core/control-ui-db.d.ts +11 -0
- package/dist/core/control-ui-db.js +40 -16
- package/dist/core/trajectory.d.ts +16 -0
- package/dist/core/trajectory.js +343 -254
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/service/subagent-workflow/workflow-store.d.ts +14 -0
- package/dist/service/subagent-workflow/workflow-store.js +91 -2
- package/openclaw.plugin.json +1 -1
- package/package.json +7 -3
- package/dist/core/schema/db-types.d.ts +0 -11
- package/dist/core/schema/db-types.js +0 -5
- package/dist/core/schema/index.d.ts +0 -17
- package/dist/core/schema/index.js +0 -15
- package/dist/core/schema/migration-runner.d.ts +0 -53
- package/dist/core/schema/migration-runner.js +0 -170
- package/dist/core/schema/migrations/001-init-trajectory.d.ts +0 -6
- package/dist/core/schema/migrations/001-init-trajectory.js +0 -190
- package/dist/core/schema/migrations/002-init-central.d.ts +0 -5
- package/dist/core/schema/migrations/002-init-central.js +0 -108
- package/dist/core/schema/migrations/003-init-workflow.d.ts +0 -5
- package/dist/core/schema/migrations/003-init-workflow.js +0 -50
- package/dist/core/schema/migrations/004-add-thinking-and-gfi.d.ts +0 -8
- package/dist/core/schema/migrations/004-add-thinking-and-gfi.js +0 -66
- package/dist/core/schema/migrations/index.d.ts +0 -16
- package/dist/core/schema/migrations/index.js +0 -27
- package/dist/core/schema/schema-definitions.d.ts +0 -46
- package/dist/core/schema/schema-definitions.js +0 -599
- package/scripts/db-migrate.mjs +0 -170
|
@@ -78,8 +78,12 @@ export class WorkflowStore {
|
|
|
78
78
|
this.db.exec('ALTER TABLE subagent_workflows ADD COLUMN duration_ms INTEGER');
|
|
79
79
|
console.info(`[PD:WorkflowStore] Schema migration v${fromVersion} → v${toVersion}: added duration_ms column`);
|
|
80
80
|
}
|
|
81
|
-
catch {
|
|
82
|
-
void 0
|
|
81
|
+
catch (err) {
|
|
82
|
+
// rc-9: surface failure reason instead of silent void 0
|
|
83
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
84
|
+
if (!message.includes('duplicate column name')) {
|
|
85
|
+
console.info(`[PD:WorkflowStore] Schema migration v${fromVersion} → v${toVersion} failed: ${message}`);
|
|
86
|
+
}
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
}
|
|
@@ -207,3 +211,88 @@ export class WorkflowStore {
|
|
|
207
211
|
return rows.map(r => r.duration_ms);
|
|
208
212
|
}
|
|
209
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Initialize subagent_workflows.db schema at the given workspace directory.
|
|
216
|
+
*
|
|
217
|
+
* Opens the DB in write mode, applies the full schema (tables + indexes + migrations),
|
|
218
|
+
* then closes the DB. Used by `pd runtime init` for unified DB initialization.
|
|
219
|
+
*
|
|
220
|
+
* Idempotent: safe to call on an existing DB; all CREATE statements use IF NOT EXISTS.
|
|
221
|
+
*
|
|
222
|
+
* @returns list of created/verified table names and any warnings
|
|
223
|
+
*/
|
|
224
|
+
export function initWorkflowSchema(workspaceDir) {
|
|
225
|
+
const resolvedDir = path.resolve(workspaceDir);
|
|
226
|
+
const stateDir = path.join(resolvedDir, '.state');
|
|
227
|
+
const dbPath = path.join(stateDir, 'subagent_workflows.db');
|
|
228
|
+
const warnings = [];
|
|
229
|
+
const tables = ['schema_version', 'subagent_workflows', 'subagent_workflow_events'];
|
|
230
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
231
|
+
const db = new Database(dbPath);
|
|
232
|
+
try {
|
|
233
|
+
db.pragma('journal_mode = WAL');
|
|
234
|
+
db.pragma('foreign_keys = ON');
|
|
235
|
+
db.pragma('synchronous = NORMAL');
|
|
236
|
+
db.pragma(`busy_timeout = ${DEFAULT_BUSY_TIMEOUT_MS}`);
|
|
237
|
+
db.exec(`
|
|
238
|
+
CREATE TABLE IF NOT EXISTS schema_version (
|
|
239
|
+
version INTEGER NOT NULL
|
|
240
|
+
);
|
|
241
|
+
CREATE TABLE IF NOT EXISTS subagent_workflows (
|
|
242
|
+
workflow_id TEXT PRIMARY KEY,
|
|
243
|
+
workflow_type TEXT NOT NULL,
|
|
244
|
+
transport TEXT NOT NULL,
|
|
245
|
+
parent_session_id TEXT NOT NULL,
|
|
246
|
+
child_session_key TEXT NOT NULL,
|
|
247
|
+
run_id TEXT,
|
|
248
|
+
state TEXT NOT NULL DEFAULT 'pending',
|
|
249
|
+
cleanup_state TEXT NOT NULL DEFAULT 'none',
|
|
250
|
+
created_at INTEGER NOT NULL,
|
|
251
|
+
updated_at INTEGER NOT NULL,
|
|
252
|
+
last_observed_at INTEGER,
|
|
253
|
+
duration_ms INTEGER,
|
|
254
|
+
metadata_json TEXT NOT NULL DEFAULT '{}'
|
|
255
|
+
);
|
|
256
|
+
CREATE TABLE IF NOT EXISTS subagent_workflow_events (
|
|
257
|
+
workflow_id TEXT NOT NULL,
|
|
258
|
+
event_type TEXT NOT NULL,
|
|
259
|
+
from_state TEXT,
|
|
260
|
+
to_state TEXT NOT NULL,
|
|
261
|
+
reason TEXT NOT NULL,
|
|
262
|
+
payload_json TEXT NOT NULL DEFAULT '{}',
|
|
263
|
+
created_at INTEGER NOT NULL,
|
|
264
|
+
FOREIGN KEY (workflow_id) REFERENCES subagent_workflows(workflow_id) ON DELETE CASCADE
|
|
265
|
+
);
|
|
266
|
+
CREATE INDEX IF NOT EXISTS idx_workflows_parent_session ON subagent_workflows(parent_session_id);
|
|
267
|
+
CREATE INDEX IF NOT EXISTS idx_workflows_child_session ON subagent_workflows(child_session_key);
|
|
268
|
+
CREATE INDEX IF NOT EXISTS idx_workflows_state ON subagent_workflows(state);
|
|
269
|
+
CREATE INDEX IF NOT EXISTS idx_workflows_type ON subagent_workflows(workflow_type);
|
|
270
|
+
CREATE INDEX IF NOT EXISTS idx_events_workflow ON subagent_workflow_events(workflow_id);
|
|
271
|
+
`);
|
|
272
|
+
// Run migrations to bring schema up to SCHEMA_VERSION
|
|
273
|
+
const row = db.prepare('SELECT version FROM schema_version LIMIT 1').get();
|
|
274
|
+
const currentVersion = row?.version ?? 0;
|
|
275
|
+
if (currentVersion === 0) {
|
|
276
|
+
db.prepare('INSERT INTO schema_version (version) VALUES (?)').run(SCHEMA_VERSION);
|
|
277
|
+
}
|
|
278
|
+
else if (currentVersion < SCHEMA_VERSION) {
|
|
279
|
+
// Inline migration logic (mirrors WorkflowStore.runMigrations)
|
|
280
|
+
if (currentVersion < 2 && SCHEMA_VERSION >= 2) {
|
|
281
|
+
try {
|
|
282
|
+
db.exec('ALTER TABLE subagent_workflows ADD COLUMN duration_ms INTEGER');
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
286
|
+
if (!message.includes('duplicate column name')) {
|
|
287
|
+
warnings.push(`migration v${currentVersion}→v${SCHEMA_VERSION} duration_ms failed: ${message}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
db.prepare('UPDATE schema_version SET version = ?').run(SCHEMA_VERSION);
|
|
292
|
+
}
|
|
293
|
+
return { tables, warnings };
|
|
294
|
+
}
|
|
295
|
+
finally {
|
|
296
|
+
db.close();
|
|
297
|
+
}
|
|
298
|
+
}
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "principles-disciple",
|
|
3
3
|
"name": "Principles Disciple",
|
|
4
4
|
"description": "Evolutionary programming agent framework with strategic guardrails and reflection loops.",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.156.0",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onCapabilities": [
|
|
8
8
|
"hook"
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "principles-disciple",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.156.0",
|
|
4
4
|
"description": "Native OpenClaw plugin for Principles Disciple",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
7
8
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
9
13
|
},
|
|
10
14
|
"repository": {
|
|
11
15
|
"type": "git",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared type definitions for database operations.
|
|
3
|
-
* Kept separate to avoid circular dependencies between schema-definitions and migration-runner.
|
|
4
|
-
*/
|
|
5
|
-
/** Minimal interface for better-sqlite3 Database instances. */
|
|
6
|
-
export interface Db {
|
|
7
|
-
exec(_sql: string): unknown;
|
|
8
|
-
get<T = unknown>(_sql: string, ..._params: unknown[]): T | undefined;
|
|
9
|
-
run(_sql: string, ..._params: unknown[]): unknown;
|
|
10
|
-
close(): void;
|
|
11
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema Management — Unified database schema definitions and migrations.
|
|
3
|
-
*
|
|
4
|
-
* Usage:
|
|
5
|
-
* // In a database class constructor:
|
|
6
|
-
* import { ensureDatabaseSchema } from './schema';
|
|
7
|
-
* ensureDatabaseSchema(db, 'trajectory.db');
|
|
8
|
-
*
|
|
9
|
-
* CLI:
|
|
10
|
-
* node scripts/db-migrate.mjs status
|
|
11
|
-
* node scripts/db-migrate.mjs run
|
|
12
|
-
*/
|
|
13
|
-
export { MigrationRunner, ensureDatabaseSchema } from './migration-runner.js';
|
|
14
|
-
export { SCHEMAS, getCatalog, DB_TYPES } from './schema-definitions.js';
|
|
15
|
-
export { ALL_MIGRATIONS } from './migrations/index.js';
|
|
16
|
-
export type { Db } from './db-types.js';
|
|
17
|
-
export type { Migration, DbType, TableDefinition, ViewDefinition, FtsDefinition, SchemaCatalog, } from './migration-runner.js';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema Management — Unified database schema definitions and migrations.
|
|
3
|
-
*
|
|
4
|
-
* Usage:
|
|
5
|
-
* // In a database class constructor:
|
|
6
|
-
* import { ensureDatabaseSchema } from './schema';
|
|
7
|
-
* ensureDatabaseSchema(db, 'trajectory.db');
|
|
8
|
-
*
|
|
9
|
-
* CLI:
|
|
10
|
-
* node scripts/db-migrate.mjs status
|
|
11
|
-
* node scripts/db-migrate.mjs run
|
|
12
|
-
*/
|
|
13
|
-
export { MigrationRunner, ensureDatabaseSchema } from './migration-runner.js';
|
|
14
|
-
export { SCHEMAS, getCatalog, DB_TYPES } from './schema-definitions.js';
|
|
15
|
-
export { ALL_MIGRATIONS } from './migrations/index.js';
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Migration Runner — Executes and tracks schema migrations.
|
|
3
|
-
*
|
|
4
|
-
* Each migration is versioned. The runner reads the current version from
|
|
5
|
-
* the `schema_version` table and only executes migrations with higher IDs.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* const runner = new MigrationRunner(db);
|
|
9
|
-
* runner.run(allMigrations.filter(m => m.db === 'trajectory.db'));
|
|
10
|
-
*/
|
|
11
|
-
import type { Migration } from './schema-definitions.js';
|
|
12
|
-
import { type DbType } from './schema-definitions.js';
|
|
13
|
-
import type { Db } from './db-types.js';
|
|
14
|
-
export declare class MigrationRunner {
|
|
15
|
-
private readonly db;
|
|
16
|
-
constructor(db: Db);
|
|
17
|
-
/**
|
|
18
|
-
* Run all pending migrations for a given database type.
|
|
19
|
-
* @returns Array of migration names that were applied
|
|
20
|
-
*/
|
|
21
|
-
runMigrations(migrations: Migration[], _dbType: DbType): string[];
|
|
22
|
-
/**
|
|
23
|
-
* Apply all schema definitions (tables, indexes, views, FTS) for a database.
|
|
24
|
-
* This is a convenience method that creates everything from the schema catalog.
|
|
25
|
-
* Used for initial setup when no migrations exist yet.
|
|
26
|
-
*/
|
|
27
|
-
applySchemaCatalog(dbType: DbType): void;
|
|
28
|
-
/**
|
|
29
|
-
* Get the current migration version.
|
|
30
|
-
* Returns '000' if no version is set (fresh database).
|
|
31
|
-
*/
|
|
32
|
-
getCurrentVersion(): string;
|
|
33
|
-
/**
|
|
34
|
-
* Get all available migration info for a database type.
|
|
35
|
-
*/
|
|
36
|
-
getMigrationInfo(migrations: Migration[], dbType: DbType): {
|
|
37
|
-
id: string;
|
|
38
|
-
name: string;
|
|
39
|
-
applied: boolean;
|
|
40
|
-
}[];
|
|
41
|
-
/**
|
|
42
|
-
* Rollback the latest migration (if down migration is defined).
|
|
43
|
-
*/
|
|
44
|
-
rollback(migrations: Migration[], dbType: DbType): string | null;
|
|
45
|
-
private ensureVersionTable;
|
|
46
|
-
private setVersion;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Factory: create a MigrationRunner and apply schema catalog for a given database.
|
|
50
|
-
* This is the main entry point for database classes.
|
|
51
|
-
*/
|
|
52
|
-
export declare function ensureDatabaseSchema(db: Db, dbType: DbType): void;
|
|
53
|
-
export type { Migration, DbType, TableDefinition, ViewDefinition, FtsDefinition, SchemaCatalog } from './schema-definitions.js';
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Migration Runner — Executes and tracks schema migrations.
|
|
3
|
-
*
|
|
4
|
-
* Each migration is versioned. The runner reads the current version from
|
|
5
|
-
* the `schema_version` table and only executes migrations with higher IDs.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* const runner = new MigrationRunner(db);
|
|
9
|
-
* runner.run(allMigrations.filter(m => m.db === 'trajectory.db'));
|
|
10
|
-
*/
|
|
11
|
-
import { getCatalog } from './schema-definitions.js';
|
|
12
|
-
export class MigrationRunner {
|
|
13
|
-
db;
|
|
14
|
-
constructor(db) {
|
|
15
|
-
this.db = db;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Run all pending migrations for a given database type.
|
|
19
|
-
* @returns Array of migration names that were applied
|
|
20
|
-
*/
|
|
21
|
-
runMigrations(migrations, _dbType) {
|
|
22
|
-
// NOTE: _dbType is kept for API signature compatibility but migrations are pre-filtered by caller
|
|
23
|
-
void _dbType;
|
|
24
|
-
// Ensure schema_version table exists before anything else
|
|
25
|
-
this.ensureVersionTable();
|
|
26
|
-
const currentVersion = this.getCurrentVersion();
|
|
27
|
-
const applied = [];
|
|
28
|
-
// Filter to pending migrations (higher ID than current)
|
|
29
|
-
const pending = migrations
|
|
30
|
-
.filter(m => m.id > currentVersion)
|
|
31
|
-
.sort((a, b) => a.id.localeCompare(b.id));
|
|
32
|
-
for (const migration of pending) {
|
|
33
|
-
console.log(`[MigrationRunner] Applying ${migration.id}-${migration.name}...`);
|
|
34
|
-
try {
|
|
35
|
-
migration.up(this.db);
|
|
36
|
-
this.setVersion(migration.id);
|
|
37
|
-
applied.push(`${migration.id}-${migration.name}`);
|
|
38
|
-
}
|
|
39
|
-
catch (err) {
|
|
40
|
-
throw new Error(`Migration ${migration.id}-${migration.name} failed: ${String(err)}`, { cause: err });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (applied.length > 0) {
|
|
44
|
-
console.log(`[MigrationRunner] Applied ${applied.length} migration(s): ${applied.join(', ')}`);
|
|
45
|
-
}
|
|
46
|
-
return applied;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Apply all schema definitions (tables, indexes, views, FTS) for a database.
|
|
50
|
-
* This is a convenience method that creates everything from the schema catalog.
|
|
51
|
-
* Used for initial setup when no migrations exist yet.
|
|
52
|
-
*/
|
|
53
|
-
applySchemaCatalog(dbType) {
|
|
54
|
-
this.ensureVersionTable();
|
|
55
|
-
const catalog = getCatalog(dbType);
|
|
56
|
-
// Tables
|
|
57
|
-
for (const [key, table] of Object.entries(catalog.tables)) {
|
|
58
|
-
try {
|
|
59
|
-
this.db.exec(table.ddl);
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
throw new Error(`Failed to create table ${key}: ${String(err)}`, { cause: err });
|
|
63
|
-
}
|
|
64
|
-
// Indexes
|
|
65
|
-
for (const indexDdl of table.indexes ?? []) {
|
|
66
|
-
try {
|
|
67
|
-
this.db.exec(indexDdl);
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
throw new Error(`Failed to create index for ${key}: ${String(err)}`, { cause: err });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Views
|
|
75
|
-
for (const [key, view] of Object.entries(catalog.views)) {
|
|
76
|
-
try {
|
|
77
|
-
this.db.exec(view.ddl);
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
throw new Error(`Failed to create view ${key}: ${String(err)}`, { cause: err });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// FTS5 virtual tables
|
|
84
|
-
for (const [key, fts] of Object.entries(catalog.fts)) {
|
|
85
|
-
try {
|
|
86
|
-
this.db.exec(fts.ddl);
|
|
87
|
-
}
|
|
88
|
-
catch (err) {
|
|
89
|
-
throw new Error(`Failed to create FTS table ${key}: ${String(err)}`, { cause: err });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Get the current migration version.
|
|
95
|
-
* Returns '000' if no version is set (fresh database).
|
|
96
|
-
*/
|
|
97
|
-
getCurrentVersion() {
|
|
98
|
-
try {
|
|
99
|
-
const row = this.db.get('SELECT version FROM schema_version ORDER BY version DESC LIMIT 1');
|
|
100
|
-
return row?.version ?? '000';
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
return '000';
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Get all available migration info for a database type.
|
|
108
|
-
*/
|
|
109
|
-
getMigrationInfo(migrations, dbType) {
|
|
110
|
-
const currentVersion = this.getCurrentVersion();
|
|
111
|
-
return migrations
|
|
112
|
-
.filter(m => m.db === dbType)
|
|
113
|
-
.sort((a, b) => a.id.localeCompare(b.id))
|
|
114
|
-
.map(m => ({
|
|
115
|
-
id: m.id,
|
|
116
|
-
name: m.name,
|
|
117
|
-
applied: m.id <= currentVersion,
|
|
118
|
-
}));
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Rollback the latest migration (if down migration is defined).
|
|
122
|
-
*/
|
|
123
|
-
rollback(migrations, dbType) {
|
|
124
|
-
const currentVersion = this.getCurrentVersion();
|
|
125
|
-
if (currentVersion === '000')
|
|
126
|
-
return null;
|
|
127
|
-
const migration = migrations.find(m => m.db === dbType && m.id === currentVersion);
|
|
128
|
-
if (!migration)
|
|
129
|
-
return null;
|
|
130
|
-
if (!migration.down) {
|
|
131
|
-
throw new Error(`Migration ${migration.id}-${migration.name} has no down migration`);
|
|
132
|
-
}
|
|
133
|
-
console.log(`[MigrationRunner] Rolling back ${migration.id}-${migration.name}...`);
|
|
134
|
-
migration.down(this.db);
|
|
135
|
-
// Set version to previous migration
|
|
136
|
-
const previousMigrations = migrations
|
|
137
|
-
.filter(m => m.db === dbType && m.id < currentVersion)
|
|
138
|
-
.sort((a, b) => b.id.localeCompare(a.id));
|
|
139
|
-
const newVersion = previousMigrations[0]?.id ?? '000';
|
|
140
|
-
this.setVersion(newVersion);
|
|
141
|
-
console.log(`[MigrationRunner] Rolled back to ${newVersion}`);
|
|
142
|
-
return migration.id;
|
|
143
|
-
}
|
|
144
|
-
// -----------------------------------------------------------------------
|
|
145
|
-
// Private helpers
|
|
146
|
-
// -----------------------------------------------------------------------
|
|
147
|
-
ensureVersionTable() {
|
|
148
|
-
this.db.exec(`
|
|
149
|
-
CREATE TABLE IF NOT EXISTS schema_version (
|
|
150
|
-
version TEXT NOT NULL DEFAULT '000'
|
|
151
|
-
)
|
|
152
|
-
`);
|
|
153
|
-
// Ensure at least one row exists
|
|
154
|
-
const count = this.db.get('SELECT COUNT(*) as cnt FROM schema_version');
|
|
155
|
-
if (!count || count.cnt === 0) {
|
|
156
|
-
this.db.exec("INSERT INTO schema_version (version) VALUES ('000')");
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
setVersion(version) {
|
|
160
|
-
this.db.exec(`UPDATE schema_version SET version = '${version}'`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Factory: create a MigrationRunner and apply schema catalog for a given database.
|
|
165
|
-
* This is the main entry point for database classes.
|
|
166
|
-
*/
|
|
167
|
-
export function ensureDatabaseSchema(db, dbType) {
|
|
168
|
-
const runner = new MigrationRunner(db);
|
|
169
|
-
runner.applySchemaCatalog(dbType);
|
|
170
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Migration: Initialize trajectory.db tables
|
|
3
|
-
* This creates all core event store tables.
|
|
4
|
-
*/
|
|
5
|
-
export const migration = {
|
|
6
|
-
id: '001',
|
|
7
|
-
name: 'init-trajectory',
|
|
8
|
-
db: 'trajectory.db',
|
|
9
|
-
up(db) {
|
|
10
|
-
// Core tables
|
|
11
|
-
db.exec(`CREATE TABLE IF NOT EXISTS sessions (
|
|
12
|
-
session_id TEXT PRIMARY KEY,
|
|
13
|
-
started_at TEXT NOT NULL,
|
|
14
|
-
updated_at TEXT NOT NULL
|
|
15
|
-
)`);
|
|
16
|
-
db.exec(`CREATE TABLE IF NOT EXISTS assistant_turns (
|
|
17
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
18
|
-
session_id TEXT NOT NULL,
|
|
19
|
-
run_id TEXT NOT NULL,
|
|
20
|
-
provider TEXT NOT NULL,
|
|
21
|
-
model TEXT NOT NULL,
|
|
22
|
-
raw_text TEXT,
|
|
23
|
-
sanitized_text TEXT NOT NULL,
|
|
24
|
-
usage_json TEXT NOT NULL,
|
|
25
|
-
empathy_signal_json TEXT NOT NULL,
|
|
26
|
-
blob_ref TEXT,
|
|
27
|
-
raw_excerpt TEXT,
|
|
28
|
-
created_at TEXT NOT NULL
|
|
29
|
-
)`);
|
|
30
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_assistant_turns_session_id ON assistant_turns(session_id)`);
|
|
31
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_assistant_turns_created_at ON assistant_turns(created_at)`);
|
|
32
|
-
db.exec(`CREATE TABLE IF NOT EXISTS user_turns (
|
|
33
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
34
|
-
session_id TEXT NOT NULL,
|
|
35
|
-
turn_index INTEGER NOT NULL,
|
|
36
|
-
raw_text TEXT,
|
|
37
|
-
blob_ref TEXT,
|
|
38
|
-
raw_excerpt TEXT,
|
|
39
|
-
correction_detected INTEGER NOT NULL DEFAULT 0,
|
|
40
|
-
correction_cue TEXT,
|
|
41
|
-
references_assistant_turn_id INTEGER,
|
|
42
|
-
created_at TEXT NOT NULL
|
|
43
|
-
)`);
|
|
44
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_user_turns_session_id ON user_turns(session_id)`);
|
|
45
|
-
db.exec(`CREATE TABLE IF NOT EXISTS tool_calls (
|
|
46
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
47
|
-
session_id TEXT NOT NULL,
|
|
48
|
-
tool_name TEXT NOT NULL,
|
|
49
|
-
outcome TEXT NOT NULL,
|
|
50
|
-
duration_ms INTEGER,
|
|
51
|
-
exit_code INTEGER,
|
|
52
|
-
error_type TEXT,
|
|
53
|
-
error_message TEXT,
|
|
54
|
-
gfi_before REAL,
|
|
55
|
-
gfi_after REAL,
|
|
56
|
-
params_json TEXT NOT NULL,
|
|
57
|
-
created_at TEXT NOT NULL
|
|
58
|
-
)`);
|
|
59
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_tool_calls_session_id ON tool_calls(session_id)`);
|
|
60
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_tool_calls_created_at ON tool_calls(created_at)`);
|
|
61
|
-
db.exec(`CREATE TABLE IF NOT EXISTS pain_events (
|
|
62
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
63
|
-
session_id TEXT NOT NULL,
|
|
64
|
-
source TEXT NOT NULL,
|
|
65
|
-
score REAL NOT NULL,
|
|
66
|
-
reason TEXT,
|
|
67
|
-
severity TEXT,
|
|
68
|
-
origin TEXT,
|
|
69
|
-
confidence REAL,
|
|
70
|
-
text TEXT,
|
|
71
|
-
created_at TEXT NOT NULL
|
|
72
|
-
)`);
|
|
73
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_pain_events_session_id ON pain_events(session_id)`);
|
|
74
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_pain_events_created_at ON pain_events(created_at)`);
|
|
75
|
-
// pain_events_fts FTS5 virtual table removed (PRI-451 Wave 1): the only
|
|
76
|
-
// reader (searchPainEvents) was dead code. Existing DBs keep the orphan
|
|
77
|
-
// table harmlessly (CREATE was IF NOT EXISTS); new DBs simply don't create it.
|
|
78
|
-
db.exec(`CREATE TABLE IF NOT EXISTS gate_blocks (
|
|
79
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
80
|
-
session_id TEXT,
|
|
81
|
-
tool_name TEXT NOT NULL,
|
|
82
|
-
file_path TEXT,
|
|
83
|
-
reason TEXT NOT NULL,
|
|
84
|
-
plan_status TEXT,
|
|
85
|
-
gfi REAL,
|
|
86
|
-
gfi_after REAL,
|
|
87
|
-
trust_stage INTEGER,
|
|
88
|
-
gate_type TEXT,
|
|
89
|
-
created_at TEXT NOT NULL
|
|
90
|
-
)`);
|
|
91
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_gate_blocks_created_at ON gate_blocks(created_at)`);
|
|
92
|
-
db.exec(`CREATE TABLE IF NOT EXISTS trust_changes (
|
|
93
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
94
|
-
session_id TEXT,
|
|
95
|
-
previous_score REAL NOT NULL,
|
|
96
|
-
new_score REAL NOT NULL,
|
|
97
|
-
delta REAL NOT NULL,
|
|
98
|
-
reason TEXT NOT NULL,
|
|
99
|
-
created_at TEXT NOT NULL
|
|
100
|
-
)`);
|
|
101
|
-
db.exec(`CREATE TABLE IF NOT EXISTS principle_events (
|
|
102
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
103
|
-
principle_id TEXT,
|
|
104
|
-
event_type TEXT NOT NULL,
|
|
105
|
-
payload_json TEXT NOT NULL,
|
|
106
|
-
created_at TEXT NOT NULL
|
|
107
|
-
)`);
|
|
108
|
-
db.exec(`CREATE TABLE IF NOT EXISTS task_outcomes (
|
|
109
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
110
|
-
session_id TEXT NOT NULL,
|
|
111
|
-
task_id TEXT,
|
|
112
|
-
outcome TEXT NOT NULL,
|
|
113
|
-
summary TEXT,
|
|
114
|
-
principle_ids_json TEXT NOT NULL,
|
|
115
|
-
created_at TEXT NOT NULL
|
|
116
|
-
)`);
|
|
117
|
-
db.exec(`CREATE TABLE IF NOT EXISTS correction_samples (
|
|
118
|
-
sample_id TEXT PRIMARY KEY,
|
|
119
|
-
session_id TEXT NOT NULL,
|
|
120
|
-
bad_assistant_turn_id INTEGER NOT NULL,
|
|
121
|
-
user_correction_turn_id INTEGER NOT NULL,
|
|
122
|
-
recovery_tool_span_json TEXT NOT NULL,
|
|
123
|
-
diff_excerpt TEXT NOT NULL,
|
|
124
|
-
principle_ids_json TEXT NOT NULL,
|
|
125
|
-
quality_score REAL NOT NULL,
|
|
126
|
-
review_status TEXT NOT NULL,
|
|
127
|
-
export_mode TEXT NOT NULL,
|
|
128
|
-
created_at TEXT NOT NULL,
|
|
129
|
-
updated_at TEXT NOT NULL
|
|
130
|
-
)`);
|
|
131
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_correction_samples_review_status ON correction_samples(review_status)`);
|
|
132
|
-
db.exec(`CREATE TABLE IF NOT EXISTS sample_reviews (
|
|
133
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
134
|
-
sample_id TEXT NOT NULL,
|
|
135
|
-
review_status TEXT NOT NULL,
|
|
136
|
-
note TEXT,
|
|
137
|
-
created_at TEXT NOT NULL
|
|
138
|
-
)`);
|
|
139
|
-
db.exec(`CREATE TABLE IF NOT EXISTS exports_audit (
|
|
140
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
141
|
-
export_kind TEXT NOT NULL,
|
|
142
|
-
mode TEXT NOT NULL,
|
|
143
|
-
approved_only INTEGER NOT NULL,
|
|
144
|
-
file_path TEXT NOT NULL,
|
|
145
|
-
row_count INTEGER NOT NULL,
|
|
146
|
-
created_at TEXT NOT NULL
|
|
147
|
-
)`);
|
|
148
|
-
db.exec(`CREATE TABLE IF NOT EXISTS evolution_tasks (
|
|
149
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
150
|
-
task_id TEXT UNIQUE NOT NULL,
|
|
151
|
-
trace_id TEXT NOT NULL,
|
|
152
|
-
source TEXT NOT NULL,
|
|
153
|
-
reason TEXT,
|
|
154
|
-
score INTEGER DEFAULT 0,
|
|
155
|
-
status TEXT DEFAULT 'pending',
|
|
156
|
-
enqueued_at TEXT,
|
|
157
|
-
started_at TEXT,
|
|
158
|
-
completed_at TEXT,
|
|
159
|
-
resolution TEXT,
|
|
160
|
-
task_kind TEXT,
|
|
161
|
-
priority TEXT,
|
|
162
|
-
retry_count INTEGER,
|
|
163
|
-
max_retries INTEGER,
|
|
164
|
-
last_error TEXT,
|
|
165
|
-
result_ref TEXT,
|
|
166
|
-
created_at TEXT NOT NULL,
|
|
167
|
-
updated_at TEXT NOT NULL
|
|
168
|
-
)`);
|
|
169
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_evolution_tasks_trace_id ON evolution_tasks(trace_id)`);
|
|
170
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_evolution_tasks_status ON evolution_tasks(status)`);
|
|
171
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_evolution_tasks_created_at ON evolution_tasks(created_at)`);
|
|
172
|
-
db.exec(`CREATE TABLE IF NOT EXISTS evolution_events (
|
|
173
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
174
|
-
trace_id TEXT NOT NULL,
|
|
175
|
-
task_id TEXT,
|
|
176
|
-
stage TEXT NOT NULL,
|
|
177
|
-
level TEXT DEFAULT 'info',
|
|
178
|
-
message TEXT NOT NULL,
|
|
179
|
-
summary TEXT,
|
|
180
|
-
metadata_json TEXT,
|
|
181
|
-
created_at TEXT NOT NULL
|
|
182
|
-
)`);
|
|
183
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_evolution_events_trace_id ON evolution_events(trace_id)`);
|
|
184
|
-
db.exec(`CREATE INDEX IF NOT EXISTS idx_evolution_events_created_at ON evolution_events(created_at)`);
|
|
185
|
-
db.exec(`CREATE TABLE IF NOT EXISTS ingest_checkpoint (
|
|
186
|
-
source_key TEXT PRIMARY KEY,
|
|
187
|
-
imported_at TEXT NOT NULL
|
|
188
|
-
)`);
|
|
189
|
-
},
|
|
190
|
-
};
|