principles-disciple 1.155.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.
@@ -1,50 +0,0 @@
1
- /**
2
- * Migration: Initialize workflow.db (subagent workflow tracking) tables
3
- */
4
- export const migration = {
5
- id: '001',
6
- name: 'init-workflow',
7
- db: 'workflow.db',
8
- up(db) {
9
- db.exec(`CREATE TABLE IF NOT EXISTS subagent_workflows (
10
- workflow_id TEXT PRIMARY KEY,
11
- workflow_type TEXT NOT NULL,
12
- transport TEXT NOT NULL,
13
- parent_session_id TEXT NOT NULL,
14
- child_session_key TEXT NOT NULL,
15
- run_id TEXT,
16
- state TEXT NOT NULL DEFAULT 'pending',
17
- cleanup_state TEXT NOT NULL DEFAULT 'none',
18
- created_at INTEGER NOT NULL,
19
- updated_at INTEGER NOT NULL,
20
- last_observed_at INTEGER,
21
- duration_ms INTEGER,
22
- metadata_json TEXT NOT NULL DEFAULT '{}'
23
- )`);
24
- db.exec(`CREATE INDEX IF NOT EXISTS idx_workflows_parent_session ON subagent_workflows(parent_session_id)`);
25
- db.exec(`CREATE INDEX IF NOT EXISTS idx_workflows_child_session ON subagent_workflows(child_session_key)`);
26
- db.exec(`CREATE INDEX IF NOT EXISTS idx_workflows_state ON subagent_workflows(state)`);
27
- db.exec(`CREATE INDEX IF NOT EXISTS idx_workflows_type ON subagent_workflows(workflow_type)`);
28
- db.exec(`CREATE TABLE IF NOT EXISTS subagent_workflow_events (
29
- workflow_id TEXT NOT NULL,
30
- event_type TEXT NOT NULL,
31
- from_state TEXT,
32
- to_state TEXT NOT NULL,
33
- reason TEXT NOT NULL,
34
- payload_json TEXT NOT NULL DEFAULT '{}',
35
- created_at INTEGER NOT NULL,
36
- FOREIGN KEY (workflow_id) REFERENCES subagent_workflows(workflow_id) ON DELETE CASCADE
37
- )`);
38
- db.exec(`CREATE INDEX IF NOT EXISTS idx_events_workflow ON subagent_workflow_events(workflow_id)`);
39
- db.exec(`CREATE TABLE IF NOT EXISTS subagent_workflow_stage_outputs (
40
- workflow_id TEXT NOT NULL,
41
- stage TEXT NOT NULL CHECK (stage IN ('dreamer', 'philosopher')),
42
- output_json TEXT NOT NULL,
43
- idempotency_key TEXT NOT NULL,
44
- created_at INTEGER NOT NULL,
45
- FOREIGN KEY (workflow_id) REFERENCES subagent_workflows(workflow_id) ON DELETE CASCADE
46
- )`);
47
- db.exec(`CREATE INDEX IF NOT EXISTS idx_stage_outputs_workflow ON subagent_workflow_stage_outputs(workflow_id)`);
48
- db.exec(`CREATE UNIQUE INDEX IF NOT EXISTS idx_stage_outputs_idempotency ON subagent_workflow_stage_outputs(idempotency_key)`);
49
- },
50
- };
@@ -1,8 +0,0 @@
1
- /**
2
- * Migration: Add thinking_model_events and gfi_state tables to trajectory.db
3
- *
4
- * These tables were added by separate classes (ControlUiDatabase, HealthQueryService)
5
- * after the initial trajectory schema. Consolidated here for unified management.
6
- */
7
- import type { Migration } from '../migration-runner.js';
8
- export declare const migration: Migration;
@@ -1,66 +0,0 @@
1
- /**
2
- * Migration: Add thinking_model_events and gfi_state tables to trajectory.db
3
- *
4
- * These tables were added by separate classes (ControlUiDatabase, HealthQueryService)
5
- * after the initial trajectory schema. Consolidated here for unified management.
6
- */
7
- export const migration = {
8
- id: '002',
9
- name: 'add-thinking-and-gfi',
10
- db: 'trajectory.db',
11
- up(db) {
12
- // Thinking model events (originally from ControlUiDatabase)
13
- db.exec(`CREATE TABLE IF NOT EXISTS thinking_model_events (
14
- id INTEGER PRIMARY KEY AUTOINCREMENT,
15
- session_id TEXT NOT NULL,
16
- run_id TEXT NOT NULL,
17
- assistant_turn_id INTEGER NOT NULL,
18
- model_id TEXT NOT NULL,
19
- matched_pattern TEXT NOT NULL,
20
- scenario_json TEXT NOT NULL,
21
- tool_context_json TEXT NOT NULL,
22
- pain_context_json TEXT NOT NULL,
23
- principle_context_json TEXT NOT NULL,
24
- trigger_excerpt TEXT NOT NULL,
25
- created_at TEXT NOT NULL
26
- )`);
27
- db.exec(`CREATE INDEX IF NOT EXISTS idx_thinking_model_events_model_created ON thinking_model_events(model_id, created_at)`);
28
- db.exec(`CREATE INDEX IF NOT EXISTS idx_thinking_model_events_session_created ON thinking_model_events(session_id, created_at)`);
29
- db.exec(`CREATE INDEX IF NOT EXISTS idx_thinking_model_events_assistant_turn ON thinking_model_events(assistant_turn_id)`);
30
- db.exec(`CREATE INDEX IF NOT EXISTS idx_thinking_model_events_run_id ON thinking_model_events(run_id)`);
31
- // GFI state (originally from HealthQueryService)
32
- db.exec(`CREATE TABLE IF NOT EXISTS gfi_state (
33
- id INTEGER PRIMARY KEY CHECK (id = 1),
34
- current_gfi REAL NOT NULL DEFAULT 0,
35
- daily_gfi_peak REAL NOT NULL DEFAULT 0,
36
- gfi_date TEXT NOT NULL DEFAULT ''
37
- )`);
38
- // Views for thinking model analytics
39
- db.exec(`CREATE VIEW IF NOT EXISTS v_thinking_model_usage AS
40
- SELECT
41
- model_id,
42
- COUNT(*) AS hits,
43
- COUNT(DISTINCT session_id) AS distinctSessions,
44
- COUNT(DISTINCT assistant_turn_id) AS distinctTurns,
45
- CAST(COUNT(DISTINCT session_id) AS REAL) /
46
- NULLIF((SELECT COUNT(DISTINCT session_id) FROM thinking_model_events), 0) AS coverageRate
47
- FROM thinking_model_events GROUP BY model_id`);
48
- db.exec(`CREATE VIEW IF NOT EXISTS v_thinking_model_effectiveness AS
49
- SELECT tme.model_id, tme.id AS event_id,
50
- COUNT(DISTINCT tc.id) AS toolCallsAfter,
51
- SUM(CASE WHEN tc.outcome = 'success' THEN 1 ELSE 0 END) AS successes,
52
- SUM(CASE WHEN tc.outcome = 'failure' THEN 1 ELSE 0 END) AS failures,
53
- COUNT(DISTINCT pe.id) AS painEventsAfter
54
- FROM thinking_model_events tme
55
- LEFT JOIN tool_calls tc ON tc.session_id = tme.session_id AND tc.created_at > tme.created_at
56
- LEFT JOIN pain_events pe ON pe.session_id = tme.session_id AND pe.created_at > tme.created_at
57
- GROUP BY tme.model_id, tme.id`);
58
- db.exec(`CREATE VIEW IF NOT EXISTS v_thinking_model_scenarios AS
59
- SELECT tme.model_id, json_each.value AS scenario, COUNT(*) AS hits
60
- FROM thinking_model_events tme, json_each(tme.scenario_json)
61
- GROUP BY tme.model_id, json_each.value`);
62
- db.exec(`CREATE VIEW IF NOT EXISTS v_thinking_model_daily_trend AS
63
- SELECT date(created_at) AS day, model_id, COUNT(*) AS hits
64
- FROM thinking_model_events GROUP BY date(created_at), model_id ORDER BY day ASC`);
65
- },
66
- };
@@ -1,16 +0,0 @@
1
- /**
2
- * Migration Registry — Auto-imports all migrations.
3
- *
4
- * Add new migration files to this directory and import them here.
5
- * Migrations are automatically sorted by ID.
6
- */
7
- import { migration as m001Trajectory } from './001-init-trajectory.js';
8
- import { migration as m001Central } from './002-init-central.js';
9
- import { migration as m001Workflow } from './003-init-workflow.js';
10
- import { migration as m002ThinkingGfi } from './004-add-thinking-and-gfi.js';
11
- import type { Migration } from '../migration-runner.js';
12
- /**
13
- * All migrations, sorted by database type then ID.
14
- */
15
- export declare const ALL_MIGRATIONS: Migration[];
16
- export { m001Trajectory, m001Central, m001Workflow, m002ThinkingGfi };
@@ -1,27 +0,0 @@
1
- /**
2
- * Migration Registry — Auto-imports all migrations.
3
- *
4
- * Add new migration files to this directory and import them here.
5
- * Migrations are automatically sorted by ID.
6
- */
7
- import { migration as m001Trajectory } from './001-init-trajectory.js';
8
- import { migration as m001Central } from './002-init-central.js';
9
- import { migration as m001Workflow } from './003-init-workflow.js';
10
- import { migration as m002ThinkingGfi } from './004-add-thinking-and-gfi.js';
11
- /**
12
- * All migrations, sorted by database type then ID.
13
- */
14
- export const ALL_MIGRATIONS = [
15
- // trajectory.db
16
- m001Trajectory,
17
- m002ThinkingGfi,
18
- // central.db
19
- m001Central,
20
- // workflow.db
21
- m001Workflow,
22
- ].sort((a, b) => {
23
- if (a.db !== b.db)
24
- return a.db.localeCompare(b.db);
25
- return a.id.localeCompare(b.id);
26
- });
27
- export { m001Trajectory, m001Central, m001Workflow, m002ThinkingGfi };
@@ -1,46 +0,0 @@
1
- /**
2
- * Schema Registry — Central source of truth for all database schemas.
3
- *
4
- * All table, view, and index definitions live here. No more scattered
5
- * CREATE TABLE statements across multiple database classes.
6
- *
7
- * Each definition is keyed by `${dbName}.${name}` for uniqueness.
8
- */
9
- import type { Db } from './db-types.js';
10
- export type DbType = 'trajectory.db' | 'central.db' | 'workflow.db';
11
- export interface TableDefinition {
12
- ddl: string;
13
- indexes?: string[];
14
- }
15
- export interface ViewDefinition {
16
- ddl: string;
17
- }
18
- export interface FtsDefinition {
19
- ddl: string;
20
- }
21
- export interface Migration {
22
- /** Unique ID, e.g. '001' */
23
- id: string;
24
- /** Human-readable name, e.g. 'init-trajectory' */
25
- name: string;
26
- /** Which database file this migration applies to */
27
- db: DbType;
28
- /** Apply this migration */
29
- up: (_db: Db) => void;
30
- /** Revert this migration */
31
- down?: (_db: Db) => void;
32
- }
33
- export interface SchemaCatalog {
34
- tables: Record<string, TableDefinition>;
35
- views: Record<string, ViewDefinition>;
36
- fts: Record<string, FtsDefinition>;
37
- }
38
- /**
39
- * All schema definitions organized by database file.
40
- * Key format: `${dbName}.${tableName}`
41
- */
42
- export declare const SCHEMAS: Record<DbType, SchemaCatalog>;
43
- /** Get all schema definitions for a specific database */
44
- export declare function getCatalog(db: DbType): SchemaCatalog;
45
- /** Get all database types */
46
- export declare const DB_TYPES: DbType[];