sqlew 1.0.0 → 1.1.1

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +98 -10
  3. package/assets/schema.sql +104 -108
  4. package/dist/constants.d.ts +8 -0
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/constants.js +11 -0
  7. package/dist/constants.js.map +1 -1
  8. package/dist/database.d.ts +41 -0
  9. package/dist/database.d.ts.map +1 -1
  10. package/dist/database.js +140 -18
  11. package/dist/database.js.map +1 -1
  12. package/dist/index.js +112 -3
  13. package/dist/index.js.map +1 -1
  14. package/dist/migrations/add-table-prefixes.d.ts +29 -0
  15. package/dist/migrations/add-table-prefixes.d.ts.map +1 -0
  16. package/dist/migrations/add-table-prefixes.js +150 -0
  17. package/dist/migrations/add-table-prefixes.js.map +1 -0
  18. package/dist/schema.d.ts +1 -1
  19. package/dist/schema.d.ts.map +1 -1
  20. package/dist/schema.js +19 -14
  21. package/dist/schema.js.map +1 -1
  22. package/dist/tools/config.d.ts +35 -0
  23. package/dist/tools/config.d.ts.map +1 -0
  24. package/dist/tools/config.js +61 -0
  25. package/dist/tools/config.js.map +1 -0
  26. package/dist/tools/constraints.d.ts +3 -3
  27. package/dist/tools/constraints.js +15 -15
  28. package/dist/tools/constraints.js.map +1 -1
  29. package/dist/tools/context.d.ts +7 -7
  30. package/dist/tools/context.js +41 -41
  31. package/dist/tools/context.js.map +1 -1
  32. package/dist/tools/files.d.ts.map +1 -1
  33. package/dist/tools/files.js +13 -10
  34. package/dist/tools/files.js.map +1 -1
  35. package/dist/tools/messaging.d.ts.map +1 -1
  36. package/dist/tools/messaging.js +8 -5
  37. package/dist/tools/messaging.js.map +1 -1
  38. package/dist/tools/utils.d.ts +5 -2
  39. package/dist/tools/utils.d.ts.map +1 -1
  40. package/dist/tools/utils.js +48 -35
  41. package/dist/tools/utils.js.map +1 -1
  42. package/dist/utils/cleanup.d.ts +45 -0
  43. package/dist/utils/cleanup.d.ts.map +1 -0
  44. package/dist/utils/cleanup.js +63 -0
  45. package/dist/utils/cleanup.js.map +1 -0
  46. package/dist/utils/retention.d.ts +47 -0
  47. package/dist/utils/retention.d.ts.map +1 -0
  48. package/dist/utils/retention.js +125 -0
  49. package/dist/utils/retention.js.map +1 -0
  50. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -5,6 +5,66 @@ All notable changes to sqlew will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.1] - 2025-10-11
9
+
10
+ ### Fixed
11
+ - **Migration Bug:** Fixed migration from v1.0.0 to v1.1.0 failing with "no such table: m_config" error
12
+ - Migration now creates `m_config` table if it doesn't exist (new in v1.1.0, not present in v1.0.0)
13
+ - Automatically inserts default config values during migration
14
+ - Users who already migrated can manually fix by running: `sqlite3 <path-to-db> "CREATE TABLE IF NOT EXISTS m_config (key TEXT PRIMARY KEY, value TEXT NOT NULL); INSERT OR IGNORE INTO m_config VALUES ('autodelete_ignore_weekend', '0'), ('autodelete_message_hours', '24'), ('autodelete_file_history_days', '7');"`
15
+
16
+ ### Technical Details
17
+ - Added table creation step to migration script for tables new in v1.1.0
18
+ - Migration now handles both table renaming (v1.0.0 → v1.1.0) and new table creation
19
+ - 100% backward compatible with v1.0.0 databases
20
+
21
+ ## [1.1.0] - 2025-10-11
22
+
23
+ ### Added
24
+ - **Category-Based Table Prefixes:** All database objects now use prefixes for better SQL utility navigation
25
+ - Master tables: `m_` prefix (8 tables)
26
+ - Transaction tables: `t_` prefix (9 tables)
27
+ - Views: `v_` prefix (6 views)
28
+ - Triggers: `trg_` prefix (1 trigger)
29
+ - **Automatic Migration System:** Seamless upgrade from v1.0.x to v1.1.0
30
+ - Detects old unprefixed schema automatically
31
+ - Transaction-based migration with rollback on failure
32
+ - Zero downtime - runs on startup
33
+ - Detailed migration logging
34
+ - **Migration Script:** New `src/migrations/add-table-prefixes.ts` module
35
+ - Safe table renaming in transaction
36
+ - Backward compatibility check
37
+ - Comprehensive error handling
38
+
39
+ ### Changed
40
+ - Database schema structure updated to v1.1.0
41
+ - All SQL queries updated to use prefixed table names
42
+ - Schema initialization now supports both old and new table structures
43
+ - Documentation updated to reflect new table naming convention
44
+
45
+ ### Technical Details
46
+ - 24 database objects renamed (8 master tables, 9 transaction tables, 6 views, 1 trigger)
47
+ - Migration preserves all existing data
48
+ - No breaking changes for MCP tool API
49
+ - Full backward compatibility with existing databases
50
+
51
+ ## [1.0.1] - 2025-10-11
52
+
53
+ ### Added
54
+ - **Database Schema Validation:** Comprehensive validation on startup for existing databases
55
+ - Detects missing tables, views, and triggers
56
+ - Verifies standard data integrity (layers, categories, tags)
57
+ - Displays detailed error messages with actionable solutions
58
+ - Prevents data corruption from incompatible schemas
59
+ - Graceful exit with error code 1 on validation failure
60
+
61
+ ### Fixed
62
+ - Database initialization now validates existing schema before proceeding
63
+ - Organized test files into `tests/` directory for better project structure
64
+
65
+ ### Changed
66
+ - Updated `.gitignore` to properly handle test files (root vs tests directory)
67
+
8
68
  ## [1.0.0] - 2025-01-10
9
69
 
10
70
  ### Initial Release
@@ -104,4 +164,7 @@ First production release of sqlew - MCP server for efficient context sharing bet
104
164
  - Full type safety
105
165
  - Comprehensive error handling
106
166
 
167
+ [1.1.1]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v1.1.1
168
+ [1.1.0]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v1.1.0
169
+ [1.0.1]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v1.0.1
107
170
  [1.0.0]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v1.0.0
package/README.md CHANGED
@@ -12,7 +12,7 @@ When coordinating multiple Claude Code agents on a complex project, context shar
12
12
  - **72% Token Reduction:** ID-based normalization, integer enums, and pre-aggregated views
13
13
  - **Structured Metadata:** Tags, layers, scopes, versions, and priorities for intelligent organization
14
14
  - **Fast & Reliable:** SQLite-backed with ACID guarantees and automatic cleanup
15
- - **18 MCP Tools:** Comprehensive API for decisions, messaging, file tracking, and constraints
15
+ - **20 MCP Tools:** Comprehensive API for decisions, messaging, file tracking, constraints, and configuration
16
16
 
17
17
  ## Features
18
18
 
@@ -21,7 +21,8 @@ When coordinating multiple Claude Code agents on a complex project, context shar
21
21
  - **File Change Tracking:** Layer-based file organization with lock detection
22
22
  - **Constraint Management:** Track performance, architecture, and security constraints
23
23
  - **Token Efficient:** Pre-aggregated views and integer enums minimize token consumption
24
- - **Automatic Cleanup:** Configurable retention policies for messages and file changes
24
+ - **Weekend-Aware Auto-Cleanup:** Smart retention policies that pause during weekends
25
+ - **Configurable Retention:** Adjust cleanup periods via CLI args or MCP tools
25
26
  - **Version History:** Track decision evolution over time
26
27
  - **Concurrent Access:** Supports multiple agents simultaneously
27
28
 
@@ -61,6 +62,24 @@ Or with a custom database path:
61
62
  }
62
63
  ```
63
64
 
65
+ Or with weekend-aware auto-deletion enabled:
66
+
67
+ ```json
68
+ {
69
+ "mcpServers": {
70
+ "sqlew": {
71
+ "command": "npx",
72
+ "args": [
73
+ "sqlew",
74
+ "--autodelete-ignore-weekend",
75
+ "--autodelete-message-hours=48",
76
+ "--autodelete-file-history-days=10"
77
+ ]
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
64
83
  ### Using with MCP Inspector
65
84
 
66
85
  Test all tools interactively:
@@ -187,20 +206,51 @@ Deactivate a constraint (soft delete).
187
206
  Get aggregated statistics per architecture layer.
188
207
 
189
208
  #### `clear_old_data`
190
- Manually clear old messages and file changes.
209
+ Manually clear old messages and file changes (uses weekend-aware config when no params provided).
191
210
 
192
211
  #### `get_stats`
193
212
  Get comprehensive database statistics.
194
213
 
214
+ ### Configuration (2 tools)
215
+
216
+ #### `get_config`
217
+ Get current auto-deletion configuration settings.
218
+
219
+ ```typescript
220
+ // Returns:
221
+ {
222
+ ignoreWeekend: false,
223
+ messageRetentionHours: 24,
224
+ fileHistoryRetentionDays: 7
225
+ }
226
+ ```
227
+
228
+ #### `update_config`
229
+ Update auto-deletion configuration settings.
230
+
231
+ ```typescript
232
+ {
233
+ ignoreWeekend: true,
234
+ messageRetentionHours: 48,
235
+ fileHistoryRetentionDays: 10
236
+ }
237
+ ```
238
+
195
239
  ## Database Schema
196
240
 
197
- sqlew uses a normalized SQLite schema optimized for token efficiency:
241
+ sqlew uses a normalized SQLite schema (v1.3.0) optimized for token efficiency with category-based table prefixes:
242
+
243
+ **Master Tables (m_ prefix):** m_agents, m_files, m_context_keys, m_layers, m_tags, m_scopes, m_constraint_categories, m_config
198
244
 
199
- **Master Tables:** agents, files, context_keys, layers, tags, scopes, constraint_categories
245
+ **Transaction Tables (t_ prefix):** t_decisions, t_decisions_numeric, t_decision_history, t_decision_tags, t_decision_scopes, t_agent_messages, t_file_changes, t_constraints, t_constraint_tags
200
246
 
201
- **Transaction Tables:** decisions, decisions_numeric, decision_history, agent_messages, file_changes, constraints
247
+ **Token-Efficient Views (v_ prefix):** v_tagged_decisions, v_active_context, v_layer_summary, v_unread_messages_by_priority, v_recent_file_changes, v_tagged_constraints
202
248
 
203
- **Token-Efficient Views:** tagged_decisions, active_context, layer_summary, recent_file_changes, tagged_constraints
249
+ **Triggers (trg_ prefix):** trg_record_decision_history
250
+
251
+ ### Automatic Migration
252
+
253
+ When upgrading from v1.2.0 to v1.3.0, the server automatically migrates your database to use the new prefixed table names. The migration is safe and runs in a transaction - if it fails, the database is unchanged.
204
254
 
205
255
  ## Token Efficiency
206
256
 
@@ -303,10 +353,48 @@ sqlew/
303
353
 
304
354
  ## Configuration
305
355
 
306
- ### Retention Periods
356
+ ### Weekend-Aware Auto-Deletion
357
+
358
+ sqlew supports weekend-aware retention policies that intelligently handle 3-day weekends and holidays:
359
+
360
+ **How it works:**
361
+ - When `ignoreWeekend: false` (default): Standard time-based deletion
362
+ - When `ignoreWeekend: true`: Weekends (Sat/Sun) don't count toward retention period
363
+
364
+ **Example:** With 24-hour retention and `ignoreWeekend: true`:
365
+ - Message sent Friday 3pm → Deleted Monday 3pm (skips Sat/Sun)
366
+ - Message sent Monday 10am → Deleted Tuesday 10am (no weekend in between)
367
+
368
+ **Configuration Methods:**
369
+
370
+ 1. **CLI Arguments (at startup):**
371
+ ```bash
372
+ npx sqlew \
373
+ --autodelete-ignore-weekend \
374
+ --autodelete-message-hours=48 \
375
+ --autodelete-file-history-days=10
376
+ ```
377
+
378
+ 2. **MCP Tools (runtime):**
379
+ ```typescript
380
+ // Get current config
381
+ get_config()
382
+
383
+ // Update config
384
+ update_config({
385
+ ignoreWeekend: true,
386
+ messageRetentionHours: 72,
387
+ fileHistoryRetentionDays: 14
388
+ })
389
+ ```
390
+
391
+ 3. **Database (persisted):**
392
+ Config is stored in the database and travels with the DB file.
393
+
394
+ ### Default Retention Periods
307
395
 
308
- - **Messages:** Auto-deleted after 24 hours
309
- - **File Changes:** Auto-deleted after 7 days
396
+ - **Messages:** 24 hours (weekend-aware optional)
397
+ - **File Changes:** 7 days (weekend-aware optional)
310
398
  - **Decisions:** Permanent (version history preserved)
311
399
  - **Constraints:** Permanent (soft delete only)
312
400
 
package/assets/schema.sql CHANGED
@@ -1,107 +1,113 @@
1
1
  -- MCP Shared Context Server - Database Schema
2
- -- Version: 1.1.0 (with metadata support)
2
+ -- Version: 1.1.0 (with configurable weekend-aware auto-deletion)
3
3
 
4
4
  -- ============================================================================
5
5
  -- マスターテーブル群(正規化)
6
6
  -- ============================================================================
7
7
 
8
8
  -- エージェント管理
9
- CREATE TABLE IF NOT EXISTS agents (
9
+ CREATE TABLE IF NOT EXISTS m_agents (
10
10
  id INTEGER PRIMARY KEY AUTOINCREMENT,
11
11
  name TEXT UNIQUE NOT NULL
12
12
  );
13
13
 
14
14
  -- ファイルパス管理
15
- CREATE TABLE IF NOT EXISTS files (
15
+ CREATE TABLE IF NOT EXISTS m_files (
16
16
  id INTEGER PRIMARY KEY AUTOINCREMENT,
17
17
  path TEXT UNIQUE NOT NULL
18
18
  );
19
19
 
20
20
  -- コンテキストキー管理
21
- CREATE TABLE IF NOT EXISTS context_keys (
21
+ CREATE TABLE IF NOT EXISTS m_context_keys (
22
22
  id INTEGER PRIMARY KEY AUTOINCREMENT,
23
23
  key TEXT UNIQUE NOT NULL
24
24
  );
25
25
 
26
26
  -- 制約カテゴリ管理
27
- CREATE TABLE IF NOT EXISTS constraint_categories (
27
+ CREATE TABLE IF NOT EXISTS m_constraint_categories (
28
28
  id INTEGER PRIMARY KEY AUTOINCREMENT,
29
29
  name TEXT UNIQUE NOT NULL
30
30
  );
31
31
 
32
32
  -- レイヤー管理
33
- CREATE TABLE IF NOT EXISTS layers (
33
+ CREATE TABLE IF NOT EXISTS m_layers (
34
34
  id INTEGER PRIMARY KEY AUTOINCREMENT,
35
35
  name TEXT UNIQUE NOT NULL
36
36
  );
37
37
 
38
38
  -- タグ管理
39
- CREATE TABLE IF NOT EXISTS tags (
39
+ CREATE TABLE IF NOT EXISTS m_tags (
40
40
  id INTEGER PRIMARY KEY AUTOINCREMENT,
41
41
  name TEXT UNIQUE NOT NULL
42
42
  );
43
43
 
44
44
  -- スコープ管理(モジュール・コンポーネント)
45
- CREATE TABLE IF NOT EXISTS scopes (
45
+ CREATE TABLE IF NOT EXISTS m_scopes (
46
46
  id INTEGER PRIMARY KEY AUTOINCREMENT,
47
47
  name TEXT UNIQUE NOT NULL
48
48
  );
49
49
 
50
+ -- 設定管理(サーバー設定)
51
+ CREATE TABLE IF NOT EXISTS m_config (
52
+ key TEXT PRIMARY KEY,
53
+ value TEXT NOT NULL
54
+ );
55
+
50
56
  -- ============================================================================
51
57
  -- トランザクションテーブル群
52
58
  -- ============================================================================
53
59
 
54
60
  -- 決定事項(文字列値)
55
- CREATE TABLE IF NOT EXISTS decisions (
56
- key_id INTEGER PRIMARY KEY REFERENCES context_keys(id),
61
+ CREATE TABLE IF NOT EXISTS t_decisions (
62
+ key_id INTEGER PRIMARY KEY REFERENCES m_context_keys(id),
57
63
  value TEXT NOT NULL,
58
- agent_id INTEGER REFERENCES agents(id),
59
- layer_id INTEGER REFERENCES layers(id),
64
+ agent_id INTEGER REFERENCES m_agents(id),
65
+ layer_id INTEGER REFERENCES m_layers(id),
60
66
  version TEXT DEFAULT '1.0.0',
61
67
  status INTEGER DEFAULT 1, -- 1=active, 2=deprecated, 3=draft
62
68
  ts INTEGER DEFAULT (unixepoch())
63
69
  );
64
70
 
65
71
  -- 決定事項(数値)
66
- CREATE TABLE IF NOT EXISTS decisions_numeric (
67
- key_id INTEGER PRIMARY KEY REFERENCES context_keys(id),
72
+ CREATE TABLE IF NOT EXISTS t_decisions_numeric (
73
+ key_id INTEGER PRIMARY KEY REFERENCES m_context_keys(id),
68
74
  value REAL NOT NULL,
69
- agent_id INTEGER REFERENCES agents(id),
70
- layer_id INTEGER REFERENCES layers(id),
75
+ agent_id INTEGER REFERENCES m_agents(id),
76
+ layer_id INTEGER REFERENCES m_layers(id),
71
77
  version TEXT DEFAULT '1.0.0',
72
78
  status INTEGER DEFAULT 1,
73
79
  ts INTEGER DEFAULT (unixepoch())
74
80
  );
75
81
 
76
82
  -- 決定事項のバージョン履歴
77
- CREATE TABLE IF NOT EXISTS decision_history (
83
+ CREATE TABLE IF NOT EXISTS t_decision_history (
78
84
  id INTEGER PRIMARY KEY AUTOINCREMENT,
79
- key_id INTEGER REFERENCES context_keys(id),
85
+ key_id INTEGER REFERENCES m_context_keys(id),
80
86
  version TEXT NOT NULL,
81
87
  value TEXT NOT NULL,
82
- agent_id INTEGER REFERENCES agents(id),
88
+ agent_id INTEGER REFERENCES m_agents(id),
83
89
  ts INTEGER NOT NULL
84
90
  );
85
91
 
86
92
  -- 決定事項へのタグ付け(多対多)
87
- CREATE TABLE IF NOT EXISTS decision_tags (
88
- decision_key_id INTEGER REFERENCES context_keys(id),
89
- tag_id INTEGER REFERENCES tags(id),
93
+ CREATE TABLE IF NOT EXISTS t_decision_tags (
94
+ decision_key_id INTEGER REFERENCES m_context_keys(id),
95
+ tag_id INTEGER REFERENCES m_tags(id),
90
96
  PRIMARY KEY (decision_key_id, tag_id)
91
97
  );
92
98
 
93
99
  -- 決定事項のスコープ(多対多)
94
- CREATE TABLE IF NOT EXISTS decision_scopes (
95
- decision_key_id INTEGER REFERENCES context_keys(id),
96
- scope_id INTEGER REFERENCES scopes(id),
100
+ CREATE TABLE IF NOT EXISTS t_decision_scopes (
101
+ decision_key_id INTEGER REFERENCES m_context_keys(id),
102
+ scope_id INTEGER REFERENCES m_scopes(id),
97
103
  PRIMARY KEY (decision_key_id, scope_id)
98
104
  );
99
105
 
100
106
  -- エージェント間メッセージ
101
- CREATE TABLE IF NOT EXISTS agent_messages (
107
+ CREATE TABLE IF NOT EXISTS t_agent_messages (
102
108
  id INTEGER PRIMARY KEY AUTOINCREMENT,
103
- from_agent_id INTEGER NOT NULL REFERENCES agents(id),
104
- to_agent_id INTEGER REFERENCES agents(id), -- NULL = broadcast
109
+ from_agent_id INTEGER NOT NULL REFERENCES m_agents(id),
110
+ to_agent_id INTEGER REFERENCES m_agents(id), -- NULL = broadcast
105
111
  msg_type INTEGER NOT NULL, -- 1=decision, 2=warning, 3=request, 4=info
106
112
  priority INTEGER DEFAULT 2, -- 1=low, 2=medium, 3=high, 4=critical
107
113
  payload TEXT, -- JSON文字列(必要な場合のみ)
@@ -110,32 +116,32 @@ CREATE TABLE IF NOT EXISTS agent_messages (
110
116
  );
111
117
 
112
118
  -- ファイル変更履歴
113
- CREATE TABLE IF NOT EXISTS file_changes (
119
+ CREATE TABLE IF NOT EXISTS t_file_changes (
114
120
  id INTEGER PRIMARY KEY AUTOINCREMENT,
115
- file_id INTEGER NOT NULL REFERENCES files(id),
116
- agent_id INTEGER NOT NULL REFERENCES agents(id),
117
- layer_id INTEGER REFERENCES layers(id),
121
+ file_id INTEGER NOT NULL REFERENCES m_files(id),
122
+ agent_id INTEGER NOT NULL REFERENCES m_agents(id),
123
+ layer_id INTEGER REFERENCES m_layers(id),
118
124
  change_type INTEGER NOT NULL, -- 1=created, 2=modified, 3=deleted
119
125
  description TEXT,
120
126
  ts INTEGER DEFAULT (unixepoch())
121
127
  );
122
128
 
123
129
  -- 制約・要件
124
- CREATE TABLE IF NOT EXISTS constraints (
130
+ CREATE TABLE IF NOT EXISTS t_constraints (
125
131
  id INTEGER PRIMARY KEY AUTOINCREMENT,
126
- category_id INTEGER NOT NULL REFERENCES constraint_categories(id),
127
- layer_id INTEGER REFERENCES layers(id),
132
+ category_id INTEGER NOT NULL REFERENCES m_constraint_categories(id),
133
+ layer_id INTEGER REFERENCES m_layers(id),
128
134
  constraint_text TEXT NOT NULL,
129
135
  priority INTEGER DEFAULT 2, -- 1=low, 2=medium, 3=high, 4=critical
130
136
  active INTEGER DEFAULT 1,
131
- created_by INTEGER REFERENCES agents(id),
137
+ created_by INTEGER REFERENCES m_agents(id),
132
138
  ts INTEGER DEFAULT (unixepoch())
133
139
  );
134
140
 
135
141
  -- 制約へのタグ付け(多対多)
136
- CREATE TABLE IF NOT EXISTS constraint_tags (
137
- constraint_id INTEGER REFERENCES constraints(id),
138
- tag_id INTEGER REFERENCES tags(id),
142
+ CREATE TABLE IF NOT EXISTS t_constraint_tags (
143
+ constraint_id INTEGER REFERENCES t_constraints(id),
144
+ tag_id INTEGER REFERENCES m_tags(id),
139
145
  PRIMARY KEY (constraint_id, tag_id)
140
146
  );
141
147
 
@@ -143,47 +149,47 @@ CREATE TABLE IF NOT EXISTS constraint_tags (
143
149
  -- インデックス
144
150
  -- ============================================================================
145
151
 
146
- CREATE INDEX IF NOT EXISTS idx_decisions_ts ON decisions(ts DESC);
147
- CREATE INDEX IF NOT EXISTS idx_decisions_layer ON decisions(layer_id);
148
- CREATE INDEX IF NOT EXISTS idx_decisions_status ON decisions(status);
149
- CREATE INDEX IF NOT EXISTS idx_messages_to_agent ON agent_messages(to_agent_id, read);
150
- CREATE INDEX IF NOT EXISTS idx_messages_ts ON agent_messages(ts DESC);
151
- CREATE INDEX IF NOT EXISTS idx_messages_priority ON agent_messages(priority DESC);
152
- CREATE INDEX IF NOT EXISTS idx_file_changes_ts ON file_changes(ts DESC);
153
- CREATE INDEX IF NOT EXISTS idx_file_changes_file ON file_changes(file_id);
154
- CREATE INDEX IF NOT EXISTS idx_file_changes_layer ON file_changes(layer_id);
155
- CREATE INDEX IF NOT EXISTS idx_constraints_active ON constraints(active, category_id);
156
- CREATE INDEX IF NOT EXISTS idx_constraints_priority ON constraints(priority DESC);
157
- CREATE INDEX IF NOT EXISTS idx_decision_tags_tag ON decision_tags(tag_id);
158
- CREATE INDEX IF NOT EXISTS idx_decision_scopes_scope ON decision_scopes(scope_id);
152
+ CREATE INDEX IF NOT EXISTS idx_decisions_ts ON t_decisions(ts DESC);
153
+ CREATE INDEX IF NOT EXISTS idx_decisions_layer ON t_decisions(layer_id);
154
+ CREATE INDEX IF NOT EXISTS idx_decisions_status ON t_decisions(status);
155
+ CREATE INDEX IF NOT EXISTS idx_messages_to_agent ON t_agent_messages(to_agent_id, read);
156
+ CREATE INDEX IF NOT EXISTS idx_messages_ts ON t_agent_messages(ts DESC);
157
+ CREATE INDEX IF NOT EXISTS idx_messages_priority ON t_agent_messages(priority DESC);
158
+ CREATE INDEX IF NOT EXISTS idx_file_changes_ts ON t_file_changes(ts DESC);
159
+ CREATE INDEX IF NOT EXISTS idx_file_changes_file ON t_file_changes(file_id);
160
+ CREATE INDEX IF NOT EXISTS idx_file_changes_layer ON t_file_changes(layer_id);
161
+ CREATE INDEX IF NOT EXISTS idx_constraints_active ON t_constraints(active, category_id);
162
+ CREATE INDEX IF NOT EXISTS idx_constraints_priority ON t_constraints(priority DESC);
163
+ CREATE INDEX IF NOT EXISTS idx_decision_tags_tag ON t_decision_tags(tag_id);
164
+ CREATE INDEX IF NOT EXISTS idx_decision_scopes_scope ON t_decision_scopes(scope_id);
159
165
 
160
166
  -- ============================================================================
161
167
  -- ビュー(トークン効率化)
162
168
  -- ============================================================================
163
169
 
164
170
  -- タグ付き決定事項(最も効率的なビュー)
165
- CREATE VIEW IF NOT EXISTS tagged_decisions AS
171
+ CREATE VIEW IF NOT EXISTS v_tagged_decisions AS
166
172
  SELECT
167
173
  k.key,
168
174
  d.value,
169
175
  d.version,
170
176
  CASE d.status WHEN 1 THEN 'active' WHEN 2 THEN 'deprecated' ELSE 'draft' END as status,
171
177
  l.name as layer,
172
- (SELECT GROUP_CONCAT(t2.name, ',') FROM decision_tags dt2
173
- JOIN tags t2 ON dt2.tag_id = t2.id
178
+ (SELECT GROUP_CONCAT(t2.name, ',') FROM t_decision_tags dt2
179
+ JOIN m_tags t2 ON dt2.tag_id = t2.id
174
180
  WHERE dt2.decision_key_id = d.key_id) as tags,
175
- (SELECT GROUP_CONCAT(s2.name, ',') FROM decision_scopes ds2
176
- JOIN scopes s2 ON ds2.scope_id = s2.id
181
+ (SELECT GROUP_CONCAT(s2.name, ',') FROM t_decision_scopes ds2
182
+ JOIN m_scopes s2 ON ds2.scope_id = s2.id
177
183
  WHERE ds2.decision_key_id = d.key_id) as scopes,
178
184
  a.name as decided_by,
179
185
  datetime(d.ts, 'unixepoch') as updated
180
- FROM decisions d
181
- JOIN context_keys k ON d.key_id = k.id
182
- LEFT JOIN layers l ON d.layer_id = l.id
183
- LEFT JOIN agents a ON d.agent_id = a.id;
186
+ FROM t_decisions d
187
+ JOIN m_context_keys k ON d.key_id = k.id
188
+ LEFT JOIN m_layers l ON d.layer_id = l.id
189
+ LEFT JOIN m_agents a ON d.agent_id = a.id;
184
190
 
185
191
  -- アクティブなコンテキスト(直近1時間、アクティブのみ)
186
- CREATE VIEW IF NOT EXISTS active_context AS
192
+ CREATE VIEW IF NOT EXISTS v_active_context AS
187
193
  SELECT
188
194
  k.key,
189
195
  d.value,
@@ -191,40 +197,40 @@ SELECT
191
197
  l.name as layer,
192
198
  a.name as decided_by,
193
199
  datetime(d.ts, 'unixepoch') as updated
194
- FROM decisions d
195
- JOIN context_keys k ON d.key_id = k.id
196
- LEFT JOIN layers l ON d.layer_id = l.id
197
- LEFT JOIN agents a ON d.agent_id = a.id
200
+ FROM t_decisions d
201
+ JOIN m_context_keys k ON d.key_id = k.id
202
+ LEFT JOIN m_layers l ON d.layer_id = l.id
203
+ LEFT JOIN m_agents a ON d.agent_id = a.id
198
204
  WHERE d.status = 1 AND d.ts > unixepoch() - 3600
199
205
  ORDER BY d.ts DESC;
200
206
 
201
207
  -- レイヤー別サマリー
202
- CREATE VIEW IF NOT EXISTS layer_summary AS
208
+ CREATE VIEW IF NOT EXISTS v_layer_summary AS
203
209
  SELECT
204
210
  l.name as layer,
205
211
  COUNT(DISTINCT d.key_id) as decisions_count,
206
212
  COUNT(DISTINCT fc.id) as file_changes_count,
207
213
  COUNT(DISTINCT c.id) as constraints_count
208
- FROM layers l
209
- LEFT JOIN decisions d ON l.id = d.layer_id AND d.status = 1
210
- LEFT JOIN file_changes fc ON l.id = fc.layer_id AND fc.ts > unixepoch() - 3600
211
- LEFT JOIN constraints c ON l.id = c.layer_id AND c.active = 1
214
+ FROM m_layers l
215
+ LEFT JOIN t_decisions d ON l.id = d.layer_id AND d.status = 1
216
+ LEFT JOIN t_file_changes fc ON l.id = fc.layer_id AND fc.ts > unixepoch() - 3600
217
+ LEFT JOIN t_constraints c ON l.id = c.layer_id AND c.active = 1
212
218
  GROUP BY l.id;
213
219
 
214
220
  -- 優先度別未読メッセージ
215
- CREATE VIEW IF NOT EXISTS unread_messages_by_priority AS
221
+ CREATE VIEW IF NOT EXISTS v_unread_messages_by_priority AS
216
222
  SELECT
217
223
  a.name as agent,
218
224
  CASE m.priority WHEN 4 THEN 'critical' WHEN 3 THEN 'high' WHEN 2 THEN 'medium' ELSE 'low' END as priority,
219
225
  COUNT(*) as count
220
- FROM agent_messages m
221
- JOIN agents a ON m.to_agent_id = a.id
226
+ FROM t_agent_messages m
227
+ JOIN m_agents a ON m.to_agent_id = a.id
222
228
  WHERE m.read = 0
223
229
  GROUP BY m.to_agent_id, m.priority
224
230
  ORDER BY m.priority DESC;
225
231
 
226
232
  -- 最近のファイル変更(レイヤー付き)
227
- CREATE VIEW IF NOT EXISTS recent_file_changes AS
233
+ CREATE VIEW IF NOT EXISTS v_recent_file_changes AS
228
234
  SELECT
229
235
  f.path,
230
236
  a.name as changed_by,
@@ -232,30 +238,30 @@ SELECT
232
238
  CASE fc.change_type WHEN 1 THEN 'created' WHEN 2 THEN 'modified' ELSE 'deleted' END as change_type,
233
239
  fc.description,
234
240
  datetime(fc.ts, 'unixepoch') as changed_at
235
- FROM file_changes fc
236
- JOIN files f ON fc.file_id = f.id
237
- JOIN agents a ON fc.agent_id = a.id
238
- LEFT JOIN layers l ON fc.layer_id = l.id
241
+ FROM t_file_changes fc
242
+ JOIN m_files f ON fc.file_id = f.id
243
+ JOIN m_agents a ON fc.agent_id = a.id
244
+ LEFT JOIN m_layers l ON fc.layer_id = l.id
239
245
  WHERE fc.ts > unixepoch() - 3600
240
246
  ORDER BY fc.ts DESC;
241
247
 
242
248
  -- タグ付き制約
243
- CREATE VIEW IF NOT EXISTS tagged_constraints AS
249
+ CREATE VIEW IF NOT EXISTS v_tagged_constraints AS
244
250
  SELECT
245
251
  c.id,
246
252
  cc.name as category,
247
253
  l.name as layer,
248
254
  c.constraint_text,
249
255
  CASE c.priority WHEN 4 THEN 'critical' WHEN 3 THEN 'high' WHEN 2 THEN 'medium' ELSE 'low' END as priority,
250
- (SELECT GROUP_CONCAT(t2.name, ',') FROM constraint_tags ct2
251
- JOIN tags t2 ON ct2.tag_id = t2.id
256
+ (SELECT GROUP_CONCAT(t2.name, ',') FROM t_constraint_tags ct2
257
+ JOIN m_tags t2 ON ct2.tag_id = t2.id
252
258
  WHERE ct2.constraint_id = c.id) as tags,
253
259
  a.name as created_by,
254
260
  datetime(c.ts, 'unixepoch') as created_at
255
- FROM constraints c
256
- JOIN constraint_categories cc ON c.category_id = cc.id
257
- LEFT JOIN layers l ON c.layer_id = l.id
258
- LEFT JOIN agents a ON c.created_by = a.id
261
+ FROM t_constraints c
262
+ JOIN m_constraint_categories cc ON c.category_id = cc.id
263
+ LEFT JOIN m_layers l ON c.layer_id = l.id
264
+ LEFT JOIN m_agents a ON c.created_by = a.id
259
265
  WHERE c.active = 1
260
266
  ORDER BY c.priority DESC, cc.name, c.ts DESC;
261
267
 
@@ -263,28 +269,12 @@ ORDER BY c.priority DESC, cc.name, c.ts DESC;
263
269
  -- トリガー(自動処理)
264
270
  -- ============================================================================
265
271
 
266
- -- 古いメッセージの自動削除(24時間以上前)
267
- CREATE TRIGGER IF NOT EXISTS cleanup_old_messages
268
- AFTER INSERT ON agent_messages
269
- BEGIN
270
- DELETE FROM agent_messages
271
- WHERE ts < unixepoch() - 86400;
272
- END;
273
-
274
- -- 古いファイル変更履歴の削除(7日以上前)
275
- CREATE TRIGGER IF NOT EXISTS cleanup_old_file_changes
276
- AFTER INSERT ON file_changes
277
- BEGIN
278
- DELETE FROM file_changes
279
- WHERE ts < unixepoch() - 604800;
280
- END;
281
-
282
272
  -- バージョン履歴の自動記録
283
- CREATE TRIGGER IF NOT EXISTS record_decision_history
284
- AFTER UPDATE ON decisions
273
+ CREATE TRIGGER IF NOT EXISTS trg_record_decision_history
274
+ AFTER UPDATE ON t_decisions
285
275
  WHEN OLD.value != NEW.value OR OLD.version != NEW.version
286
276
  BEGIN
287
- INSERT INTO decision_history (key_id, version, value, agent_id, ts)
277
+ INSERT INTO t_decision_history (key_id, version, value, agent_id, ts)
288
278
  VALUES (OLD.key_id, OLD.version, OLD.value, OLD.agent_id, OLD.ts);
289
279
  END;
290
280
 
@@ -293,7 +283,7 @@ END;
293
283
  -- ============================================================================
294
284
 
295
285
  -- 標準レイヤー
296
- INSERT OR IGNORE INTO layers (name) VALUES
286
+ INSERT OR IGNORE INTO m_layers (name) VALUES
297
287
  ('presentation'),
298
288
  ('business'),
299
289
  ('data'),
@@ -301,13 +291,13 @@ INSERT OR IGNORE INTO layers (name) VALUES
301
291
  ('cross-cutting');
302
292
 
303
293
  -- 標準カテゴリ
304
- INSERT OR IGNORE INTO constraint_categories (name) VALUES
294
+ INSERT OR IGNORE INTO m_constraint_categories (name) VALUES
305
295
  ('performance'),
306
296
  ('architecture'),
307
297
  ('security');
308
298
 
309
299
  -- よくあるタグ
310
- INSERT OR IGNORE INTO tags (name) VALUES
300
+ INSERT OR IGNORE INTO m_tags (name) VALUES
311
301
  ('authentication'),
312
302
  ('authorization'),
313
303
  ('performance'),
@@ -318,3 +308,9 @@ INSERT OR IGNORE INTO tags (name) VALUES
318
308
  ('testing'),
319
309
  ('validation'),
320
310
  ('error-handling');
311
+
312
+ -- デフォルト設定(自動削除の設定)
313
+ INSERT OR IGNORE INTO m_config (key, value) VALUES
314
+ ('autodelete_ignore_weekend', '0'),
315
+ ('autodelete_message_hours', '24'),
316
+ ('autodelete_file_history_days', '7');
@@ -126,6 +126,14 @@ export declare const SQLITE_TRUE = 1;
126
126
  * SQLite boolean false value
127
127
  */
128
128
  export declare const SQLITE_FALSE = 0;
129
+ /**
130
+ * Configuration key names
131
+ */
132
+ export declare const CONFIG_KEYS: {
133
+ readonly AUTODELETE_IGNORE_WEEKEND: "autodelete_ignore_weekend";
134
+ readonly AUTODELETE_MESSAGE_HOURS: "autodelete_message_hours";
135
+ readonly AUTODELETE_FILE_HISTORY_DAYS: "autodelete_file_history_days";
136
+ };
129
137
  export declare const ERROR_MESSAGES: {
130
138
  readonly DB_INIT_FAILED: "Failed to initialize database";
131
139
  readonly DB_CONNECTION_FAILED: "Failed to connect to database";
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAMvE;;GAEG;AACH,eAAO,MAAM,iBAAiB,WAAW,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,eAAe,oB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