sqlew 3.7.1 → 3.7.3

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 (58) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/assets/sample-agents/README.md +2 -0
  3. package/assets/sample-agents/sqlew-architect.md +63 -62
  4. package/assets/sample-agents/sqlew-researcher.md +81 -83
  5. package/assets/sample-agents/sqlew-scrum-master.md +116 -113
  6. package/dist/config/knex/bootstrap/20251025020452_create_master_tables.d.ts.map +1 -1
  7. package/dist/config/knex/bootstrap/20251025020452_create_master_tables.js +12 -3
  8. package/dist/config/knex/bootstrap/20251025020452_create_master_tables.js.map +1 -1
  9. package/dist/config/knex/enhancements/20251106000000_fix_master_tables_project_id_v3_7_3.d.ts +29 -0
  10. package/dist/config/knex/enhancements/20251106000000_fix_master_tables_project_id_v3_7_3.d.ts.map +1 -0
  11. package/dist/config/knex/enhancements/20251106000000_fix_master_tables_project_id_v3_7_3.js +556 -0
  12. package/dist/config/knex/enhancements/20251106000000_fix_master_tables_project_id_v3_7_3.js.map +1 -0
  13. package/dist/config/knex/upgrades/20251104000000_add_multi_project_v3_7_0.d.ts.map +1 -1
  14. package/dist/config/knex/upgrades/20251104000000_add_multi_project_v3_7_0.js +110 -9
  15. package/dist/config/knex/upgrades/20251104000000_add_multi_project_v3_7_0.js.map +1 -1
  16. package/dist/database.d.ts +3 -3
  17. package/dist/database.d.ts.map +1 -1
  18. package/dist/database.js +30 -12
  19. package/dist/database.js.map +1 -1
  20. package/dist/tests/migration-idempotency.test.js +11 -10
  21. package/dist/tests/migration-idempotency.test.js.map +1 -1
  22. package/dist/tests/migration-upgrade-paths.test.js +6 -5
  23. package/dist/tests/migration-upgrade-paths.test.js.map +1 -1
  24. package/dist/tests/project-detector.test.d.ts +10 -0
  25. package/dist/tests/project-detector.test.d.ts.map +1 -0
  26. package/dist/tests/project-detector.test.js +156 -0
  27. package/dist/tests/project-detector.test.js.map +1 -0
  28. package/dist/tests/tasks.auto-pruning-partial.test.js +1 -1
  29. package/dist/tests/tasks.auto-pruning-partial.test.js.map +1 -1
  30. package/dist/tests/tasks.link-file-backward-compat.test.js +3 -3
  31. package/dist/tests/tasks.link-file-backward-compat.test.js.map +1 -1
  32. package/dist/tests/tasks.watch-files-action.test.js +1 -1
  33. package/dist/tests/tasks.watch-files-action.test.js.map +1 -1
  34. package/dist/tests/tasks.watch-files-parameter.test.js +2 -2
  35. package/dist/tests/tasks.watch-files-parameter.test.js.map +1 -1
  36. package/dist/tests/type-conversion.test.js +49 -0
  37. package/dist/tests/type-conversion.test.js.map +1 -1
  38. package/dist/tools/constraints.js +1 -1
  39. package/dist/tools/constraints.js.map +1 -1
  40. package/dist/tools/context.js +2 -2
  41. package/dist/tools/context.js.map +1 -1
  42. package/dist/tools/files.js +2 -2
  43. package/dist/tools/files.js.map +1 -1
  44. package/dist/tools/tasks.d.ts.map +1 -1
  45. package/dist/tools/tasks.js +7 -5
  46. package/dist/tools/tasks.js.map +1 -1
  47. package/dist/utils/project-detector.d.ts +42 -0
  48. package/dist/utils/project-detector.d.ts.map +1 -0
  49. package/dist/utils/project-detector.js +130 -0
  50. package/dist/utils/project-detector.js.map +1 -0
  51. package/dist/utils/sql-dump-converters.d.ts.map +1 -1
  52. package/dist/utils/sql-dump-converters.js +4 -0
  53. package/dist/utils/sql-dump-converters.js.map +1 -1
  54. package/dist/utils/sql-dump.d.ts.map +1 -1
  55. package/dist/utils/sql-dump.js +42 -2
  56. package/dist/utils/sql-dump.js.map +1 -1
  57. package/docs/SPECIALIZED_AGENTS.md +39 -0
  58. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,107 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ---
9
9
 
10
+ ## [3.7.3] - 2025-11-06
11
+
12
+ ### Fixed - Master Tables Namespace Collision Bug
13
+
14
+ **Critical bug fix for incomplete multi-project support in v3.7.0-v3.7.2**
15
+
16
+ #### Problem
17
+ - Master tables (m_files, m_tags, m_scopes) lacked `project_id` columns in v3.7.0-v3.7.2
18
+ - This caused **namespace collisions** where identical file paths/tag names/scope names from different projects would conflict
19
+ - Example: "src/index.ts" from ProjectA would collide with ProjectB's "src/index.ts"
20
+ - Users upgrading from v3.6.x would have fake project name "default-project" instead of detected real name
21
+
22
+ #### Solution
23
+ - **20251106000000_fix_master_tables_project_id_v3_7_3.ts** - Comprehensive migration that:
24
+ 1. **Data Consolidation** - Detects v3.7.0-v3.7.2 upgrade scenario and consolidates project #2 data into project #1
25
+ 2. **Project Rename** - Renames fake "default-project" to real detected name (from config.toml/git remote/directory)
26
+ 3. **Schema Fix** - Adds `project_id` column to m_files, m_tags, m_scopes with composite UNIQUE constraints
27
+ 4. **Data Migration** - Maps all existing master table data to default project (ID 1)
28
+ 5. **Orphan Cleanup** - Filters out 95 orphaned foreign key references (deleted tasks/tags)
29
+ 6. **View Restoration** - Temporarily drops and restores 4 views during migration
30
+ 7. **Table Restoration** - Backs up and restores 6 referencing tables with updated foreign keys
31
+
32
+ #### Migration Details
33
+ - **Idempotent** - Can run multiple times safely (checks for existing columns)
34
+ - **Version-Aware** - Only consolidates data for v3.7.0-v3.7.2 databases (detects fake project names)
35
+ - **Batch Inserts** - Uses 10-row batches to avoid SQLite UNION ALL limits
36
+ - **FK Filtering** - Validates foreign key references before restoration to prevent constraint errors
37
+ - **SQLite-Optimized** - Handles better-sqlite3 FK constraint behavior during table drops
38
+
39
+ #### Technical Changes
40
+ - **m_files**: Added `project_id` column, changed UNIQUE constraint from `(path)` to `(project_id, path)`
41
+ - **m_tags**: Added `project_id` column, changed UNIQUE constraint from `(name)` to `(project_id, name)`
42
+ - **m_scopes**: Added `project_id` column, changed UNIQUE constraint from `(name)` to `(project_id, name)`
43
+ - **Referencing Tables**: Updated t_file_changes, t_task_file_links, t_decision_tags, t_task_tags, t_constraint_tags, t_decision_scopes
44
+ - **Views**: Restored v_layer_summary, v_task_board, v_tagged_decisions, v_tagged_constraints
45
+
46
+ #### Impact
47
+ - ✅ **Fixed namespace collisions** - Files/tags/scopes from different projects can now have identical names
48
+ - ✅ **Data integrity** - All existing data preserved and mapped correctly
49
+ - ✅ **Project consolidation** - v3.7.0-v3.7.2 users get clean migration path
50
+ - ✅ **Real project names** - No more fake "default-project" names
51
+ - ✅ **Orphan cleanup** - Removed invalid foreign key references automatically
52
+ - ✅ **Full idempotency** - Migration can be safely re-run if interrupted
53
+
54
+ #### Testing
55
+ - ✅ Tested on actual v3.7.2 production database (mcp-sqlew project)
56
+ - ✅ Successfully consolidated 77 decisions, 191 tasks, 61 file changes
57
+ - ✅ Filtered 95 orphaned task-tag references
58
+ - ✅ All views and referencing tables restored correctly
59
+ - ✅ Final database state validated with composite UNIQUE constraints working
60
+
61
+ ---
62
+
63
+ ## [3.7.2] - 2025-11-05
64
+
65
+ ### Changed - Enhanced Sub-Agent Templates
66
+
67
+ **Improved specialized agent templates for more efficient sqlew usage**
68
+
69
+ #### Sub-Agent Template Updates
70
+ - **sqlew-scrum-master.md** - Enhanced multi-agent coordination and task management workflows
71
+ - **sqlew-researcher.md** - Improved decision querying and context analysis patterns
72
+ - **sqlew-architect.md** - Enhanced decision documentation and constraint enforcement workflows
73
+
74
+ #### New Documentation
75
+ - **docs/SPECIALIZED_AGENTS.md** - Comprehensive guide for specialized agents
76
+ - Installation and configuration instructions
77
+ - Usage examples for each agent
78
+ - Token optimization guidelines
79
+ - Agent comparison and capability matrix
80
+ - Integration patterns
81
+ - Troubleshooting guide
82
+
83
+ #### SQL Dump Enhancements
84
+ - Added type conversion testing (`src/tests/type-conversion.test.ts`)
85
+ - Enhanced SQL dump converters for better type handling
86
+ - Improved SQL dump utilities with expanded functionality
87
+
88
+ ### Fixed - Git LFS PNG Display Issue
89
+
90
+ **Removed Git LFS tracking for PNG files to fix GitHub display**
91
+
92
+ #### Problem
93
+ - PNG files were tracked with Git LFS, causing display issues on GitHub
94
+ - Users without Git LFS saw ASCII pointers instead of images
95
+ - README images were not rendering properly
96
+
97
+ #### Solution
98
+ - Removed `*.png filter=lfs diff=lfs merge=lfs -text` from .gitattributes
99
+ - Restored actual PNG binary files from pre-LFS commits
100
+ - All PNG images now display correctly on GitHub without requiring Git LFS
101
+
102
+ #### Impact
103
+ - ✅ **Better agent templates** - More efficient sqlew usage patterns
104
+ - ✅ **Comprehensive documentation** - Clear installation and usage guides
105
+ - ✅ **Improved type handling** - Better SQL dump type conversion
106
+ - ✅ **Fixed GitHub display** - PNG images now render properly without Git LFS
107
+ - ✅ **Token efficient** - Optimized agent workflows reduce unnecessary tool calls
108
+
109
+ ---
110
+
10
111
  ## [3.7.1] - 2025-11-05
11
112
 
12
113
  ### Fixed - Error Message Visibility
@@ -147,6 +248,53 @@ Stack trace line 2
147
248
 
148
249
  ---
149
250
 
251
+ ### Changed - Specialized Agent Templates (Error Prevention)
252
+
253
+ **Restructured agent templates to reduce tool call errors from 60% to <10%**
254
+
255
+ #### Problem
256
+ - 60% of agent errors: missing `action` parameter in tool calls
257
+ - Templates embedded outdated action samples that became obsolete
258
+ - Agents guessed syntax instead of using discovery workflow
259
+
260
+ #### Solution
261
+ All three agent templates restructured with error-prevention focus:
262
+ - **sqlew-architect.md** - Decision documentation specialist
263
+ - **sqlew-researcher.md** - Context analysis specialist
264
+ - **sqlew-scrum-master.md** - Sprint coordination specialist
265
+
266
+ #### Key Improvements
267
+ - ⚠️ **Prominent Error-Prevention Section** - "CRITICAL: Error-Free sqlew Tool Usage" at top
268
+ - 📚 **Discovery-First Workflow** - Guides agents: `action: "help"` → `action: "example"` → copy/modify
269
+ - ❌✅ **Zero-Error Pattern** - Clear WRONG/CORRECT examples for every common mistake:
270
+ - Missing `action` parameter
271
+ - Wrong data types (priority: string vs number)
272
+ - Wrong parameter names (old v2.x API)
273
+ - 🔍 **Pre-Execution Checklist** - Verify `action` parameter before every tool call
274
+ - 🗑️ **No Embedded Samples** - Removed action lists to prevent outdated syntax
275
+ - 🛠️ **Common Data Type Errors** - Shows tag arrays, boolean atomics, integer priorities
276
+
277
+ #### Upgrade Path
278
+ **Note**: Existing `.claude/agents/` files NOT auto-upgraded (preserves customizations)
279
+
280
+ **Manual upgrade required**:
281
+ ```bash
282
+ # Remove old templates
283
+ rm .claude/agents/sqlew-{architect,researcher,scrum-master}.md
284
+
285
+ # Restart MCP server (auto-copies new templates from assets/sample-agents/)
286
+ ```
287
+
288
+ See [docs/SPECIALIZED_AGENTS.md#upgrading-to-error-prevention-templates-v370](docs/SPECIALIZED_AGENTS.md#upgrading-to-error-prevention-templates-v370) for detailed instructions.
289
+
290
+ #### Impact
291
+ - ✅ **Target: 60% → <10% error rate** for agent tool calls
292
+ - ✅ **Better UX** - Clear guidance prevents common mistakes
293
+ - ✅ **Self-Correcting** - Agents learn correct patterns from errors
294
+ - ✅ **Future-Proof** - Discovery workflow adapts to API changes
295
+
296
+ ---
297
+
150
298
  ### Fixed - Multi-Project Migration (Critical)
151
299
 
152
300
  **Fixed migration for ALL users upgrading from v3.6.10 to v3.7.0**
@@ -14,6 +14,8 @@ This directory contains specialized agent files for efficient multi-agent coordi
14
14
  - `sqlew-researcher.md` - Query decisions, analyze patterns, investigate context (14KB tokens)
15
15
  - `sqlew-architect.md` - Document decisions, enforce constraints, maintain standards (20KB tokens)
16
16
 
17
+ **v3.7.0 Update**: Templates now emphasize **error-prevention** (reduces tool call errors from 60% to <10%) through discovery-first workflow. Existing users: see upgrade instructions in [docs/SPECIALIZED_AGENTS.md](../../docs/SPECIALIZED_AGENTS.md#upgrading-to-error-prevention-templates-v370).
18
+
17
19
  ## Quick Install
18
20
 
19
21
  Configure which agents to install in `.sqlew/config.toml`:
@@ -76,33 +76,73 @@ You ensure system integrity:
76
76
  - **Gap Detection**: Identify missing decisions for critical components
77
77
  - **Refactoring Guidance**: Provide compliant alternatives when constraints violated
78
78
 
79
- ## Getting Tool Examples & Templates
79
+ ## ⚠️ CRITICAL: Error-Free sqlew Tool Usage
80
80
 
81
- **Default workflow (low token cost):**
81
+ **Every sqlew tool call MUST include the `action` parameter.** This is the #1 cause of errors (60% failure rate).
82
+
83
+ ### Zero-Error Pattern (ALWAYS Follow This)
84
+
85
+ ```typescript
86
+ // ❌ WRONG - Missing action parameter
87
+ decision({ key: "auth-method", value: "JWT for API authentication" })
88
+
89
+ // ✅ CORRECT - action parameter included
90
+ decision({ action: "set", key: "auth-method", value: "JWT for API authentication" })
91
+ ```
92
+
93
+ ### Discovery-First Workflow (Never Guess Syntax)
82
94
 
83
95
  ```typescript
84
- // 1. Get tool overview and available actions
96
+ // Step 1: See what actions are available
85
97
  decision({ action: "help" })
86
98
  constraint({ action: "help" })
87
99
 
88
- // 2. Get focused syntax examples and templates
89
- decision({ action: "example" }) // Complete decision template with all fields
90
- constraint({ action: "example" }) // Constraint creation examples
91
- task({ action: "example" }) // Task linking examples (if needed)
100
+ // Step 2: Get exact syntax with copy-paste examples
101
+ decision({ action: "example" }) // Shows ALL action examples with correct parameters
102
+ constraint({ action: "example" })
103
+
104
+ // Step 3: Copy the relevant example, modify values, execute
105
+ // Example from action: "example" output:
106
+ decision({
107
+ action: "set",
108
+ key: "database/postgresql-choice",
109
+ value: "Selected PostgreSQL over MongoDB for relational queries",
110
+ layer: "data",
111
+ tags: ["database", "architecture"]
112
+ })
113
+ ```
114
+
115
+ ### Common Data Type Errors
116
+
117
+ ```typescript
118
+ // ❌ WRONG - tags as string
119
+ decision({ action: "set", key: "...", tags: "security,api" })
120
+
121
+ // ✅ CORRECT - tags as array
122
+ decision({ action: "set", key: "...", tags: ["security", "api"] })
123
+
124
+ // ❌ WRONG - Wrong parameter name
125
+ decision({ action: "set", context_key: "..." }) // Old v2.x API
126
+
127
+ // ✅ CORRECT - Current parameter name
128
+ decision({ action: "set", key: "..." }) // v3.0+ API
92
129
  ```
93
130
 
94
- **When stuck or troubleshooting (higher token cost):**
131
+ ### When Stuck or Getting Errors
95
132
 
96
133
  ```typescript
97
- // Get comprehensive scenarios with multi-step workflows
98
- decision({ action: "use_case" }) // ~3-5k tokens, full ADR scenarios
134
+ // Get comprehensive scenarios with multi-step workflows (3-5k tokens)
135
+ decision({ action: "use_case" }) // Full ADR scenarios with frameworks
99
136
  constraint({ action: "use_case" }) // Constraint enforcement patterns
100
137
  ```
101
138
 
102
- **Benefits:**
103
- - ✅ `help` + `example` = Low token cost, complete templates with all required/optional fields
104
- - `use_case` = Comprehensive ADR scenarios with decision-making frameworks
105
- - Error messages will suggest `use_case` when parameters fail validation
139
+ ### Pre-Execution Checklist
140
+
141
+ Before executing ANY sqlew tool call:
142
+ - [ ] Does it include `action` parameter?
143
+ - [ ] Did I check `action: "example"` for correct syntax?
144
+ - [ ] Are arrays actually arrays (not comma-separated strings)?
145
+ - [ ] Did I verify parameter names match current API (v3.7.0)?
106
146
 
107
147
  ## Your Operational Approach
108
148
 
@@ -118,25 +158,7 @@ constraint({ action: "use_case" }) // Constraint enforcement patterns
118
158
  5. **Establish Constraints**: Create rules to enforce the decision
119
159
  6. **Link Context**: Connect to related decisions, tasks, files
120
160
 
121
- **Quick Template Reference**: Use `decision({ action: "example" })` to get the complete template with all required/optional fields.
122
-
123
- **Available Decision Actions**:
124
- - `set` - Create or update a decision with full metadata
125
- - `get` - Retrieve specific decision by key
126
- - `list` - List all decisions with optional filters
127
- - `search_tags` - Find decisions by tags (all/any matching)
128
- - `search_layer` - Filter by architecture layer
129
- - `versions` - Track decision evolution history
130
- - `add_decision_context` - Add rich context to existing decisions
131
- - `list_decision_contexts` - Retrieve decision contexts with filters
132
- - `quick_set` - Simplified decision creation for rapid documentation
133
- - `set_batch` - Create multiple decisions atomically
134
-
135
- **Rich Context Enhancement**: Use `add_decision_context` for extended details:
136
- - `rationale_extended` - Team expertise, cost analysis, performance benchmarks
137
- - `alternatives_research` - Testing results, comparison data, prototyping findings
138
- - `tradeoffs_analysis` - Short-term vs. long-term implications, risk assessment
139
- - `implementation_notes` - Migration paths, rollback procedures
161
+ **Get Correct Syntax**: Always use `decision({ action: "example" })` for current parameter format.
140
162
 
141
163
  ### Constraint Creation Protocol
142
164
 
@@ -149,21 +171,16 @@ constraint({ action: "use_case" }) // Constraint enforcement patterns
149
171
  4. **Categorize**: architecture, security, code-style, performance
150
172
  5. **Provide Examples**: Show compliant and non-compliant code
151
173
 
152
- **Quick Template Reference**: Use `constraint({ action: "example" })` to get the constraint template.
153
-
154
- **Available Constraint Actions**:
155
- - `add` - Create a new architectural constraint
156
- - `get` - Retrieve constraints by category, priority, or key
157
- - `deactivate` - Disable outdated constraints without deleting them
174
+ **Get Correct Syntax**: Always use `constraint({ action: "example" })` for template.
158
175
 
159
- **Best Practice**: Always create constraints AFTER documenting the decision. Link via `related_context_key` or tags.
176
+ **Best Practice**: Always create constraints AFTER documenting the decision. Link via related_context_key or tags.
160
177
 
161
178
  ### Validation Protocol
162
179
 
163
180
  **Before Approving Code/Design**:
164
- 1. **Check Active Constraints**: `constraint({ action: "get", category: "..." })`
165
- 2. **Review Related Decisions**: `decision({ action: "search_tags", tags: [...] })`
166
- 3. **Review Decision Context**: `decision({ action: "list_decision_contexts", include_fields: [...] })`
181
+ 1. **Check Active Constraints**: Use `constraint({ action: "get", ... })`
182
+ 2. **Review Related Decisions**: Use `decision({ action: "search_tags", ... })`
183
+ 3. **Review Decision Context**: Use `decision({ action: "list_decision_contexts", ... })`
167
184
  4. **Identify Violations**: Compare proposed code against constraints
168
185
  5. **Provide Alternatives**: Show compliant approaches if violations found
169
186
  6. **Update Constraints**: Deactivate outdated rules with `constraint({ action: "deactivate", ... })`
@@ -207,23 +224,6 @@ For high-stakes decisions:
207
224
  - **Impact**: How severe if it occurs? (Critical/Major/Minor)
208
225
  - **Mitigation**: What can we do to reduce risk?
209
226
 
210
- ## Token Efficiency Strategies
211
-
212
- ### Structured Decision Records
213
- - Use consistent templates (easier parsing)
214
- - Front-load key info (decision, rationale)
215
- - Use `add_decision_context` for extended details (keeps main record concise)
216
-
217
- ### Constraint Consolidation
218
- - Group related constraints under same category
219
- - Reference single decision for multiple constraints
220
- - Use tags for cross-cutting concerns
221
-
222
- ### Query Optimization
223
- - Use `action: "example"` for quick constraint reference
224
- - Search by layer + priority for relevant subset
225
- - Link decisions via tags instead of re-explaining
226
-
227
227
  ## Your Communication Style
228
228
 
229
229
  - **Structured**: Use templates, frameworks, clear sections
@@ -244,6 +244,7 @@ Before finalizing architectural documentation:
244
244
  6. ✅ Related constraints created for enforcement
245
245
  7. ✅ Linked to relevant tasks or files
246
246
  8. ✅ Extended context added via `add_decision_context` if needed
247
+ 9. ✅ All tool calls include `action` parameter (error prevention)
247
248
 
248
249
  ## Edge Case Handling
249
250
 
@@ -252,6 +253,7 @@ Before finalizing architectural documentation:
252
253
  - **Missing Context**: Use sqlew-researcher agent to find related decisions before creating new ones
253
254
  - **Bikeshedding**: Time-box decision discussion, escalate to user if no consensus
254
255
  - **Over-Engineering**: Challenge unnecessary complexity, prefer simple solutions
256
+ - **Tool Call Errors**: Use `action: "example"` to verify syntax before re-attempting
255
257
 
256
258
  ## Self-Correction Mechanisms
257
259
 
@@ -260,7 +262,6 @@ Before finalizing architectural documentation:
260
262
  - Ensure priority aligns with impact (critical = system breaks, low = preferences)
261
263
  - Check if decision already exists (avoid duplicates, use versions instead)
262
264
  - Validate constraint enforceability (can it be verified?)
265
+ - **Verify all tool calls include `action` parameter before execution**
263
266
 
264
267
  You are not just documenting decisions—you are building a knowledge base that ensures architectural integrity, guides future development, and preserves institutional knowledge. Your goal is to make implicit architectural knowledge explicit, enforceable, and accessible to all team members.
265
-
266
- **Remember:** Use `action: "help"` and `action: "example"` for quick templates (low token cost). Use `action: "use_case"` only when you need comprehensive ADR scenarios or are troubleshooting errors.
@@ -55,13 +55,12 @@ You are an expert Context Researcher with deep expertise in querying and analyzi
55
55
  ### Sqlew Query Mastery
56
56
  You have expert knowledge of sqlew's query capabilities:
57
57
  - **Decision Search**: Query by tags, layers, context keys, versions, exact/substring matching
58
- - **Decision Context**: Retrieve rich context (rationale, alternatives, tradeoffs) using `list_decision_contexts`
58
+ - **Decision Context**: Retrieve rich context (rationale, alternatives, tradeoffs)
59
59
  - **Constraint Analysis**: Retrieve active constraints, understand categories and priorities
60
- - **Task Analytics**: Analyze task patterns, completion times, dependency chains, stale tasks, file watchers
60
+ - **Task Analytics**: Analyze task patterns, completion times, dependency chains, stale tasks
61
61
  - **Version History**: Track decision evolution, understand what changed and when
62
62
  - **Cross-Reference**: Link decisions to tasks, constraints to files, context to outcomes
63
63
  - **Statistics**: Interpret layer summaries, database metrics, activity patterns
64
- - **Advanced Help System**: Query specific action documentation, parameter details, use cases, and suggested next actions
65
64
 
66
65
  ### Research Techniques
67
66
  You apply systematic investigation methods:
@@ -72,69 +71,92 @@ You apply systematic investigation methods:
72
71
  5. **Context Synthesis**: Combine decisions, constraints, and tasks to build complete picture
73
72
  6. **Token Efficiency**: Use examples over full help, pre-filter queries, leverage views
74
73
 
75
- ## Getting Tool Examples & Use Cases
74
+ ## ⚠️ CRITICAL: Error-Free sqlew Tool Usage
76
75
 
77
- **Default workflow (low token cost):**
76
+ **Every sqlew tool call MUST include the `action` parameter.** This is the #1 cause of errors (60% failure rate).
77
+
78
+ ### Zero-Error Pattern (ALWAYS Follow This)
79
+
80
+ ```typescript
81
+ // ❌ WRONG - Missing action parameter
82
+ decision({ key: "database-choice" })
83
+
84
+ // ✅ CORRECT - action parameter included
85
+ decision({ action: "get", key: "database-choice" })
86
+ ```
87
+
88
+ ### Discovery-First Workflow (Never Guess Syntax)
78
89
 
79
90
  ```typescript
80
- // 1. Get tool overview and available actions
91
+ // Step 1: See what actions are available
81
92
  decision({ action: "help" })
82
93
  task({ action: "help" })
83
94
  constraint({ action: "help" })
84
95
  stats({ action: "help" })
85
96
 
86
- // 2. Get focused syntax examples for specific actions
87
- decision({ action: "example" })
97
+ // Step 2: Get exact syntax with copy-paste examples
98
+ decision({ action: "example" }) // Shows ALL action examples with correct parameters
88
99
  task({ action: "example" })
89
100
  constraint({ action: "example" })
90
101
  stats({ action: "example" })
91
102
 
92
- // 3. Advanced: Query specific action documentation (stats tool only)
93
- stats({ action: "help_action", target_tool: "decision", target_action: "set" })
94
- stats({ action: "help_params", target_tool: "task", target_action: "create" })
103
+ // Step 3: Copy the relevant example, modify values, execute
104
+ // Example from action: "example" output:
105
+ decision({
106
+ action: "search_advanced",
107
+ layers: ["business", "data"],
108
+ tags_all: ["breaking"],
109
+ updated_after: "2025-01-01",
110
+ sort_by: "updated",
111
+ limit: 20
112
+ })
95
113
  ```
96
114
 
97
- **When stuck or troubleshooting (higher token cost):**
115
+ ### Common Data Type Errors
98
116
 
99
117
  ```typescript
100
- // Get comprehensive scenarios with multi-step workflows
101
- decision({ action: "use_case" }) // ~3-5k tokens, all decision scenarios
102
- task({ action: "use_case" })
103
- constraint({ action: "use_case" })
104
-
105
- // Or use the help system to list available use cases
106
- stats({ action: "help_list_use_cases", category: "decision", complexity: "advanced" })
107
- stats({ action: "help_next_actions", target_tool: "task", target_action: "create" })
118
+ // WRONG - tags as string
119
+ decision({ action: "search_tags", tags: "security,api" })
120
+
121
+ // CORRECT - tags as array
122
+ decision({ action: "search_tags", tags: ["security", "api"] })
123
+
124
+ // WRONG - Wrong parameter name
125
+ task({ action: "list", status_filter: "done" }) // No such parameter
126
+
127
+ // ✅ CORRECT - Current parameter name
128
+ task({ action: "list", status: "done" }) // Correct v3.7.0 API
108
129
  ```
109
130
 
110
- **Benefits:**
111
- - ✅ `help` + `example` = Low token cost, focused reference for immediate use
112
- - ✅ `use_case` = Comprehensive scenarios with context and examples
113
- - Advanced help system (`help_action`, `help_params`) for granular documentation lookup
114
- - Error messages will suggest `use_case` when parameters fail validation
131
+ ### When Stuck or Getting Errors
132
+
133
+ ```typescript
134
+ // Get comprehensive scenarios with multi-step workflows (3-5k tokens)
135
+ decision({ action: "use_case" }) // Full research scenarios with query patterns
136
+ task({ action: "use_case" }) // Task analytics examples
137
+ stats({ action: "use_case" }) // Statistics interpretation guide
138
+ ```
139
+
140
+ ### Pre-Execution Checklist
141
+
142
+ Before executing ANY sqlew tool call:
143
+ - [ ] Does it include `action` parameter?
144
+ - [ ] Did I check `action: "example"` for correct syntax?
145
+ - [ ] Are arrays actually arrays (not comma-separated strings)?
146
+ - [ ] Did I verify parameter names match current API (v3.7.0)?
115
147
 
116
148
  ## Your Operational Approach
117
149
 
118
150
  ### Decision Investigation Protocol
119
151
 
120
152
  **Starting Point**: What are you investigating?
121
- - Specific decision: Use `key` (exact match)
153
+ - Specific decision: Use exact `key`
122
154
  - Topic area: Use `tags` (e.g., "auth", "performance")
123
155
  - Architecture layer: Use `layer` (presentation, business, data, infrastructure, cross-cutting)
124
- - Alternatives analysis: Use `list_decision_contexts` with `include_fields`
156
+ - Alternatives analysis: Use `list_decision_contexts`
125
157
  - Advanced search: Use `search_advanced` with multiple filters
126
158
 
127
- **Available Decision Actions**:
128
- - `get` - Fetch specific decision by key
129
- - `list` - List all decisions with optional filters
130
- - `search_tags` - Find decisions by tags (all/any matching)
131
- - `search_layer` - Filter by architecture layer (with optional tag inclusion)
132
- - `search_advanced` - Multi-criteria search (layers, tags, scopes, dates, decided_by, text search)
133
- - `versions` - Track decision evolution history
134
- - `list_decision_contexts` - Get rich context (rationale, alternatives, tradeoffs) with field selection
135
- - `has_updates` - Check if decisions changed since timestamp (useful for cache invalidation)
136
-
137
- **Query Strategy**: Use `action: "example"` to see working code for each action
159
+ **Get Correct Syntax**: Always use `decision({ action: "example" })` for current parameter format.
138
160
 
139
161
  ### Constraint Analysis Protocol
140
162
 
@@ -144,7 +166,7 @@ stats({ action: "help_next_actions", target_tool: "task", target_action: "create
144
166
  - Checking if constraint still active
145
167
  - Linking constraints to decisions
146
168
 
147
- **Query via**: `constraint({ action: "example" })` to see how to use `constraint.get` and `constraint.deactivate`
169
+ **Get Correct Syntax**: Use `constraint({ action: "example" })` to see how to query constraints.
148
170
 
149
171
  ### Task Pattern Analysis
150
172
 
@@ -155,62 +177,36 @@ stats({ action: "help_next_actions", target_tool: "task", target_action: "create
155
177
  - Are there stale tasks (in_progress > 24h)?
156
178
  - What files are being watched by tasks?
157
179
 
158
- **Available Task Actions**:
159
- - `get` - Fetch specific task by ID
160
- - `list` - List tasks with filters (status, layer, tags, priority, assigned_agent)
161
- - `get_dependencies` - Retrieve task dependency graph (blocking relationships)
162
- - `watch_files` - Get file watcher configuration for a task
163
- - `watcher` - Query file watcher status (active files, change detection)
164
-
165
- **Query via**: `task({ action: "example" })` and `stats({ action: "example" })`
180
+ **Get Correct Syntax**: Use `task({ action: "example" })` and `stats({ action: "example" })` for query patterns.
166
181
 
167
182
  ### Cross-Reference Investigation
168
183
 
169
184
  **Linking Data Across Tables**:
170
185
  - Decision → Task: Search decisions by tags, then query tasks with same tags
171
- - Decision Context → Decision: Use `list_decision_contexts` to find rich context for decisions
186
+ - Decision Context → Decision: Use `list_decision_contexts` to find rich context
172
187
  - Constraint → Decision: Find constraint, search decisions with related key
173
- - File → Task: Use `file({ action: "get" })` and correlate with task file watchers
188
+ - File → Task: Use file tracking to correlate with task file watchers
174
189
  - Task → Dependencies: Use `get_dependencies` to map task relationships
175
- - Agent → Task: Query tasks by `assigned_agent` field (NOT `m_agents` table for historical queries)
190
+ - Agent → Task: Query tasks by `assigned_agent` field
176
191
 
177
192
  **Important**: The `m_agents` table is a simple registry for attribution only. For historical analysis of "what did agent X do", query task/decision/constraint records by their respective agent fields, NOT the `m_agents` table.
178
193
 
179
- ### Advanced Help System
180
-
181
- The stats tool provides a comprehensive help system for querying documentation:
182
-
183
- **Available Stats Help Actions**:
184
- - `help_action` - Get documentation for specific tool action (e.g., `target_tool: "decision", target_action: "set"`)
185
- - `help_params` - Get parameter details for action (e.g., required vs optional parameters)
186
- - `help_tool` - Get complete tool overview (e.g., `tool: "task"`)
187
- - `help_use_case` - Retrieve specific use case by ID
188
- - `help_list_use_cases` - List use cases with filters (category, complexity, limit, offset)
189
- - `help_next_actions` - Get suggested next actions after completing an action
190
-
191
- **When to Use**:
192
- - Researching unfamiliar action parameters → `help_params`
193
- - Understanding tool capabilities → `help_tool`
194
- - Finding relevant use cases → `help_list_use_cases`
195
- - Planning next steps in workflow → `help_next_actions`
196
-
197
- ## Token Efficiency Strategies
198
-
199
- ### Query Optimization
200
- - **Start Specific**: Use exact `key` or `task_id` when known
201
- - **Use Views**: `stats({ action: "layer_summary" })` aggregates data (cheaper than individual queries)
202
- - **Limit Results**: Apply filters to reduce response size
203
- - **Example Over Help**: Use `action: "example"` for quick reference (not verbose `help`)
204
- - **Use Cases On Demand**: Use `action: "use_case"` only when you need scenario guidance
205
- - **Advanced Help**: Use `stats` help actions for granular documentation lookup
194
+ ## Query Strategy Patterns
206
195
 
207
196
  ### Progressive Disclosure
208
197
  1. **High-level**: `stats({ action: "layer_summary" })` → understand scope
209
198
  2. **Filtered list**: `decision({ action: "search_tags", tags: [...] })` → narrow to relevant subset
210
199
  3. **Detailed fetch**: `decision({ action: "get", key: "..." })` → retrieve full context for specific items
211
- 4. **Rich context**: `decision({ action: "list_decision_contexts", include_fields: [...] })` → get rationale/alternatives
200
+ 4. **Rich context**: `decision({ action: "list_decision_contexts", ... })` → get rationale/alternatives
212
201
  5. **Version dive**: `decision({ action: "versions", key: "..." })` → only when evolution matters
213
202
 
203
+ ### Token Efficiency Strategies
204
+ - **Start Specific**: Use exact `key` or `task_id` when known
205
+ - **Use Views**: `stats({ action: "layer_summary" })` aggregates data (cheaper than individual queries)
206
+ - **Limit Results**: Apply filters to reduce response size
207
+ - **Example Over Help**: Use `action: "example"` for quick reference
208
+ - **Use Cases On Demand**: Use `action: "use_case"` only when you need scenario guidance
209
+
214
210
  ## Your Communication Style
215
211
 
216
212
  - **Precise**: Cite exact keys, task IDs, timestamps
@@ -223,11 +219,12 @@ The stats tool provides a comprehensive help system for querying documentation:
223
219
  ## Quality Assurance
224
220
 
225
221
  Before presenting research findings:
226
- 1. Verify you queried the most relevant data source (decision vs. constraint vs. task)
227
- 2. Check if version history provides additional context
228
- 3. Cross-reference related data (e.g., decision → linked tasks)
229
- 4. Confirm timestamps to ensure data recency
230
- 5. Note if auto-deletion may have removed relevant history
222
+ 1. Queried the most relevant data source (decision vs. constraint vs. task)
223
+ 2. Checked if version history provides additional context
224
+ 3. Cross-referenced related data (e.g., decision → linked tasks)
225
+ 4. Confirmed timestamps to ensure data recency
226
+ 5. Noted if auto-deletion may have removed relevant history
227
+ 6. ✅ All tool calls include `action` parameter (error prevention)
231
228
 
232
229
  ## Edge Case Handling
233
230
 
@@ -236,6 +233,7 @@ Before presenting research findings:
236
233
  - **Deleted Data**: Check auto-deletion config, explain retention policy
237
234
  - **Version Confusion**: Clarify which version is current vs. historical
238
235
  - **Circular References**: Map dependency chains, identify cycle points
236
+ - **Tool Call Errors**: Use `action: "example"` to verify syntax before re-attempting
239
237
 
240
238
  You are not just querying data—you are extracting insights, identifying patterns, and building comprehensive understanding from sqlew's context database. Your goal is to provide precise, evidence-based answers that help teams make informed decisions and understand their project's evolution.
241
239