sqlew 4.0.5 → 4.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 (217) hide show
  1. package/CHANGELOG.md +1817 -1782
  2. package/README.md +409 -468
  3. package/assets/claude-md-snippets/plan-mode-integration.md +17 -6
  4. package/assets/config.example.toml +282 -284
  5. package/assets/sample-agents/README.md +36 -40
  6. package/assets/sample-agents/sqlew-architect.md +321 -322
  7. package/assets/sample-agents/sqlew-researcher.md +292 -293
  8. package/assets/sample-agents/sqlew-scrum-master.md +286 -287
  9. package/assets/sample-commands/README.md +56 -57
  10. package/assets/sample-skills/sqlew-plan-guidance/SKILL.md +33 -26
  11. package/dist/cli/hooks/check-completion.d.ts +19 -0
  12. package/dist/cli/hooks/check-completion.d.ts.map +1 -0
  13. package/dist/cli/hooks/check-completion.js +104 -0
  14. package/dist/cli/hooks/check-completion.js.map +1 -0
  15. package/dist/cli/hooks/init-hooks.d.ts +35 -0
  16. package/dist/cli/hooks/init-hooks.d.ts.map +1 -0
  17. package/dist/cli/hooks/init-hooks.js +425 -0
  18. package/dist/cli/hooks/init-hooks.js.map +1 -0
  19. package/dist/cli/hooks/mark-done.d.ts +25 -0
  20. package/dist/cli/hooks/mark-done.d.ts.map +1 -0
  21. package/dist/cli/hooks/mark-done.js +128 -0
  22. package/dist/cli/hooks/mark-done.js.map +1 -0
  23. package/dist/cli/hooks/plan-id-utils.d.ts +83 -0
  24. package/dist/cli/hooks/plan-id-utils.d.ts.map +1 -0
  25. package/dist/cli/hooks/plan-id-utils.js +183 -0
  26. package/dist/cli/hooks/plan-id-utils.js.map +1 -0
  27. package/dist/cli/hooks/save.d.ts +23 -0
  28. package/dist/cli/hooks/save.d.ts.map +1 -0
  29. package/dist/cli/hooks/save.js +90 -0
  30. package/dist/cli/hooks/save.js.map +1 -0
  31. package/dist/cli/hooks/stdin-parser.d.ts +139 -0
  32. package/dist/cli/hooks/stdin-parser.d.ts.map +1 -0
  33. package/dist/cli/hooks/stdin-parser.js +127 -0
  34. package/dist/cli/hooks/stdin-parser.js.map +1 -0
  35. package/dist/cli/hooks/suggest.d.ts +19 -0
  36. package/dist/cli/hooks/suggest.d.ts.map +1 -0
  37. package/dist/cli/hooks/suggest.js +157 -0
  38. package/dist/cli/hooks/suggest.js.map +1 -0
  39. package/dist/cli/hooks/track-plan.d.ts +36 -0
  40. package/dist/cli/hooks/track-plan.d.ts.map +1 -0
  41. package/dist/cli/hooks/track-plan.js +152 -0
  42. package/dist/cli/hooks/track-plan.js.map +1 -0
  43. package/dist/cli.d.ts.map +1 -1
  44. package/dist/cli.js +56 -16
  45. package/dist/cli.js.map +1 -1
  46. package/dist/config/global-config.d.ts +187 -0
  47. package/dist/config/global-config.d.ts.map +1 -0
  48. package/dist/config/global-config.js +206 -0
  49. package/dist/config/global-config.js.map +1 -0
  50. package/dist/config/loader.d.ts +42 -0
  51. package/dist/config/loader.d.ts.map +1 -1
  52. package/dist/config/loader.js +96 -0
  53. package/dist/config/loader.js.map +1 -1
  54. package/dist/constants.d.ts +4 -0
  55. package/dist/constants.d.ts.map +1 -1
  56. package/dist/constants.js +10 -0
  57. package/dist/constants.js.map +1 -1
  58. package/dist/database/migrations/v4/20251126000000_v4_bootstrap.js +59 -59
  59. package/dist/database/migrations/v4/20251126000000_v4_bootstrap.js.map +1 -1
  60. package/dist/database/migrations/v4/20251126000001_v4_migrate_data.js +33 -33
  61. package/dist/database/migrations/v4/20251126000001_v4_migrate_data.js.map +1 -1
  62. package/dist/database/migrations/v4/20251127000000_add_rejected_status.js +7 -7
  63. package/dist/database/migrations/v4/20251127000000_add_rejected_status.js.map +1 -1
  64. package/dist/database/migrations/v4/20251127000001_update_task_move_help.js +11 -11
  65. package/dist/database/migrations/v4/20251127000001_update_task_move_help.js.map +1 -1
  66. package/dist/database/migrations/v4/20251127000002_v4_seed_help_system.js +10 -10
  67. package/dist/database/migrations/v4/20251127000002_v4_seed_help_system.js.map +1 -1
  68. package/dist/database/migrations/v4/20251127000003_add_task_notes_column.js +7 -7
  69. package/dist/database/migrations/v4/20251127000003_add_task_notes_column.js.map +1 -1
  70. package/dist/database/migrations/v4/20251128000000_drop_all_views.js +8 -8
  71. package/dist/database/migrations/v4/20251128000000_drop_all_views.js.map +1 -1
  72. package/dist/database/operations/queries.d.ts.map +1 -1
  73. package/dist/database/operations/queries.js +11 -2
  74. package/dist/database/operations/queries.js.map +1 -1
  75. package/dist/index.js +4 -1
  76. package/dist/index.js.map +1 -1
  77. package/dist/init-agents.js +0 -1
  78. package/dist/init-agents.js.map +1 -1
  79. package/dist/init-skills.d.ts +4 -3
  80. package/dist/init-skills.d.ts.map +1 -1
  81. package/dist/init-skills.js +10 -3
  82. package/dist/init-skills.js.map +1 -1
  83. package/dist/server/setup.d.ts +8 -0
  84. package/dist/server/setup.d.ts.map +1 -1
  85. package/dist/server/setup.js +141 -21
  86. package/dist/server/setup.js.map +1 -1
  87. package/dist/sync-agents.d.ts.map +1 -1
  88. package/dist/sync-agents.js +48 -3
  89. package/dist/sync-agents.js.map +1 -1
  90. package/dist/sync-commands.d.ts.map +1 -1
  91. package/dist/sync-commands.js +43 -3
  92. package/dist/sync-commands.js.map +1 -1
  93. package/dist/tools/constraints/actions/get.d.ts.map +1 -1
  94. package/dist/tools/constraints/actions/get.js +5 -8
  95. package/dist/tools/constraints/actions/get.js.map +1 -1
  96. package/dist/tools/constraints/help/help.d.ts.map +1 -1
  97. package/dist/tools/constraints/help/help.js +1 -6
  98. package/dist/tools/constraints/help/help.js.map +1 -1
  99. package/dist/tools/context/actions/get.d.ts.map +1 -1
  100. package/dist/tools/context/actions/get.js.map +1 -1
  101. package/dist/tools/context/actions/search-layer.d.ts.map +1 -1
  102. package/dist/tools/context/actions/search-layer.js +5 -3
  103. package/dist/tools/context/actions/search-layer.js.map +1 -1
  104. package/dist/tools/context/actions/set-from-policy.d.ts +2 -1
  105. package/dist/tools/context/actions/set-from-policy.d.ts.map +1 -1
  106. package/dist/tools/context/actions/set-from-policy.js.map +1 -1
  107. package/dist/tools/context/help/help.d.ts.map +1 -1
  108. package/dist/tools/context/help/help.js +1 -7
  109. package/dist/tools/context/help/help.js.map +1 -1
  110. package/dist/tools/context/internal/queries.d.ts.map +1 -1
  111. package/dist/tools/context/internal/queries.js +5 -2
  112. package/dist/tools/context/internal/queries.js.map +1 -1
  113. package/dist/tools/context/types.d.ts +1 -1
  114. package/dist/tools/context/types.d.ts.map +1 -1
  115. package/dist/tools/files/actions/get.d.ts.map +1 -1
  116. package/dist/tools/files/actions/get.js +4 -6
  117. package/dist/tools/files/actions/get.js.map +1 -1
  118. package/dist/tools/files/help/help.d.ts.map +1 -1
  119. package/dist/tools/files/help/help.js +1 -6
  120. package/dist/tools/files/help/help.js.map +1 -1
  121. package/dist/tools/suggest/help/constraint-help.d.ts.map +1 -1
  122. package/dist/tools/suggest/help/constraint-help.js +0 -2
  123. package/dist/tools/suggest/help/constraint-help.js.map +1 -1
  124. package/dist/tools/suggest/internal/constraint-queries.d.ts.map +1 -1
  125. package/dist/tools/suggest/internal/constraint-queries.js +12 -5
  126. package/dist/tools/suggest/internal/constraint-queries.js.map +1 -1
  127. package/dist/tools/suggest/internal/queries.js +2 -2
  128. package/dist/tools/suggest/internal/queries.js.map +1 -1
  129. package/dist/tools/tasks/help/help.d.ts.map +1 -1
  130. package/dist/tools/tasks/help/help.js +0 -6
  131. package/dist/tools/tasks/help/help.js.map +1 -1
  132. package/dist/tools/tasks/help/use-case.d.ts.map +1 -1
  133. package/dist/tools/tasks/help/use-case.js +0 -1
  134. package/dist/tools/tasks/help/use-case.js.map +1 -1
  135. package/dist/tools/tasks/watcher/status.d.ts.map +1 -1
  136. package/dist/tools/tasks/watcher/status.js +5 -1
  137. package/dist/tools/tasks/watcher/status.js.map +1 -1
  138. package/dist/types/decision/params.d.ts +7 -6
  139. package/dist/types/decision/params.d.ts.map +1 -1
  140. package/dist/types/decision/templates.d.ts +3 -2
  141. package/dist/types/decision/templates.d.ts.map +1 -1
  142. package/dist/types/view-entities.d.ts +2 -1
  143. package/dist/types/view-entities.d.ts.map +1 -1
  144. package/dist/types.d.ts +19 -11
  145. package/dist/types.d.ts.map +1 -1
  146. package/dist/types.js +4 -1
  147. package/dist/types.js.map +1 -1
  148. package/dist/utils/enum-converter.d.ts +72 -0
  149. package/dist/utils/enum-converter.d.ts.map +1 -0
  150. package/dist/utils/enum-converter.js +76 -0
  151. package/dist/utils/enum-converter.js.map +1 -0
  152. package/dist/utils/hook-queue.d.ts +81 -0
  153. package/dist/utils/hook-queue.d.ts.map +1 -0
  154. package/dist/utils/hook-queue.js +156 -0
  155. package/dist/utils/hook-queue.js.map +1 -0
  156. package/dist/utils/project-root.d.ts +9 -2
  157. package/dist/utils/project-root.d.ts.map +1 -1
  158. package/dist/utils/project-root.js +16 -2
  159. package/dist/utils/project-root.js.map +1 -1
  160. package/dist/utils/tag-parser.d.ts.map +1 -1
  161. package/dist/utils/tag-parser.js +6 -0
  162. package/dist/utils/tag-parser.js.map +1 -1
  163. package/dist/utils/universal-knex.js +3 -3
  164. package/dist/utils/universal-knex.js.map +1 -1
  165. package/dist/utils/validators.d.ts +1 -1
  166. package/dist/utils/validators.d.ts.map +1 -1
  167. package/dist/utils/validators.js +1 -1
  168. package/dist/utils/validators.js.map +1 -1
  169. package/dist/utils/vcs-adapter.d.ts +44 -0
  170. package/dist/utils/vcs-adapter.d.ts.map +1 -1
  171. package/dist/utils/vcs-adapter.js +88 -0
  172. package/dist/utils/vcs-adapter.js.map +1 -1
  173. package/dist/utils/view-queries.d.ts.map +1 -1
  174. package/dist/utils/view-queries.js +9 -19
  175. package/dist/utils/view-queries.js.map +1 -1
  176. package/dist/watcher/base-watcher.d.ts +69 -0
  177. package/dist/watcher/base-watcher.d.ts.map +1 -0
  178. package/dist/watcher/base-watcher.js +130 -0
  179. package/dist/watcher/base-watcher.js.map +1 -0
  180. package/dist/watcher/index.d.ts +3 -0
  181. package/dist/watcher/index.d.ts.map +1 -1
  182. package/dist/watcher/index.js +2 -0
  183. package/dist/watcher/index.js.map +1 -1
  184. package/dist/watcher/queue-watcher.d.ts +64 -0
  185. package/dist/watcher/queue-watcher.d.ts.map +1 -0
  186. package/dist/watcher/queue-watcher.js +187 -0
  187. package/dist/watcher/queue-watcher.js.map +1 -0
  188. package/docs/ADR_CONCEPTS.md +140 -0
  189. package/docs/CONFIGURATION.md +922 -925
  190. package/docs/CROSS_DATABASE.md +153 -0
  191. package/docs/DATABASE_AUTH.md +70 -356
  192. package/docs/HOOKS_GUIDE.md +159 -0
  193. package/docs/SLASH_COMMANDS.md +329 -337
  194. package/docs/TASK_SYSTEM_DEPRECATED.md +88 -0
  195. package/docs/changelogs/CHANGELOG_ARCHIVE_v3.4_and_older.md +293 -296
  196. package/docs/cli/DATA_EXPORT_IMPORT.md +699 -700
  197. package/docs/cli/README.md +276 -277
  198. package/package.json +123 -124
  199. package/docs/ACCEPTANCE_CRITERIA.md +0 -625
  200. package/docs/AI_AGENT_GUIDE.md +0 -299
  201. package/docs/ARCHITECTURE.md +0 -167
  202. package/docs/AUTO_FILE_TRACKING.md +0 -841
  203. package/docs/BATCH_VALIDATION.md +0 -617
  204. package/docs/BEST_PRACTICES.md +0 -168
  205. package/docs/CONSTRAINT_INTELLIGENCE.md +0 -339
  206. package/docs/DECISION_CONTEXT.md +0 -697
  207. package/docs/DECISION_INTELLIGENCE.md +0 -605
  208. package/docs/GIT_AWARE_AUTO_COMPLETE.md +0 -646
  209. package/docs/MIGRATION_GUIDE_V3.9.0.md +0 -371
  210. package/docs/SHARED_CONCEPTS.md +0 -225
  211. package/docs/SPECIALIZED_AGENTS.md +0 -126
  212. package/docs/TASK_ACTIONS.md +0 -1177
  213. package/docs/TASK_OVERVIEW.md +0 -452
  214. package/docs/TASK_PRUNING.md +0 -594
  215. package/docs/TOOL_REFERENCE.md +0 -1077
  216. package/docs/TOOL_SELECTION.md +0 -83
  217. package/docs/WORKFLOWS.md +0 -941
@@ -1,697 +0,0 @@
1
- # ADR Data Model - Architecture Decision Records (v3.2.2+)
2
-
3
- ## Overview
4
-
5
- sqlew implements a **structured ADR (Architecture Decision Record) data model** that captures not just decisions, but the complete context: **WHY** a decision was made, what alternatives were considered, and the trade-offs involved. This transforms traditional text-based ADR into a queryable, AI-native database that maintains architectural knowledge across sessions.
6
-
7
- ### What is an ADR?
8
-
9
- **Architecture Decision Records (ADR)** are documents that capture important architectural decisions made along with their context and consequences. sqlew extends this concept by:
10
-
11
- - **Structured storage** – ADR data stored as relational database records
12
- - **Version history** – Track how decisions evolve over time
13
- - **Relationship tracking** – Link decisions to tasks, files, and constraints
14
- - **AI-native queries** – Search by tags, layers, similarity scores
15
-
16
- > **Preserved in v4.0.0**: This feature is fully preserved in the v4.0.0 schema refactoring. All ADR context data (rationale, alternatives, trade-offs, related links) continues to work without changes. The schema uses `v4_decision_context` table with the same structure and functionality.
17
-
18
- ---
19
-
20
- ## 🆕 Decision Intelligence Integration (v3.9.0)
21
-
22
- ### Project Historical Records with Automatic Updates
23
-
24
- **v3.9.0 introduces intelligent duplicate detection** that treats decisions as **living historical records** rather than static entries. This transforms how you maintain project knowledge:
25
-
26
- #### The Problem: Decision Fragmentation
27
-
28
- Without intelligent detection, teams create fragmented decision records:
29
- ```
30
- api-authentication → "Use JWT"
31
- auth-method → "JWT tokens"
32
- api-auth-strategy → "JWT with refresh tokens"
33
- ```
34
-
35
- **Result**: 3 separate entries for the same decision, making it impossible to track the evolution of your authentication strategy.
36
-
37
- #### The Solution: Three-Tier Historical Record Management
38
-
39
- **Tier 1 (35-44 score): Related Record Alert**
40
- - Shows potentially related historical records
41
- - Allows you to link or update existing records
42
- - Perfect for discovering "we discussed this before"
43
-
44
- **Tier 2 (45-59 score): Update Existing Record**
45
- - High similarity suggests same topic
46
- - Prompts you to update the existing record with new context
47
- - Maintains decision continuity
48
-
49
- **Tier 3 (60+ score): Automatic Historical Update**
50
- - Transparently updates existing record
51
- - Preserves complete version history
52
- - Zero friction for iterative refinement
53
-
54
- #### Example: Evolving Authentication Decision
55
-
56
- **Initial Decision (January)**:
57
- ```typescript
58
- {
59
- action: "set",
60
- key: "api-authentication",
61
- value: "Use JWT tokens for API authentication",
62
- tags: ["api", "security", "authentication"],
63
- layer: "business"
64
- }
65
- ```
66
-
67
- **Updated Context (March)** - After security review:
68
- ```typescript
69
- {
70
- action: "set",
71
- key: "api-auth-jwt-expiration", // Similar key
72
- value: "JWT tokens with 15-minute expiration",
73
- tags: ["api", "security", "authentication"], // Same tags
74
- layer: "business" // Same layer
75
- }
76
-
77
- // v3.9.0 Response:
78
- {
79
- "success": true,
80
- "auto_updated": true,
81
- "requested_key": "api-auth-jwt-expiration",
82
- "actual_key": "api-authentication", // Updated existing record!
83
- "version": "1.0.1", // Version incremented
84
- "message": "Auto-updated existing decision (similarity: 85)"
85
- }
86
- ```
87
-
88
- **Result**: Single historical record with version history:
89
- - v1.0.0: "Use JWT tokens for API authentication"
90
- - v1.0.1: "JWT tokens with 15-minute expiration"
91
-
92
- **Query version history**:
93
- ```typescript
94
- {
95
- action: "versions",
96
- key: "api-authentication"
97
- }
98
- // Returns both versions with timestamps
99
- ```
100
-
101
- ### Benefits for Project History
102
-
103
- 1. **Single Source of Truth**: One record per decision topic, not scattered duplicates
104
- 2. **Complete Version Trail**: Track how decisions evolved over time
105
- 3. **Context Accumulation**: Add context to existing decisions, building richer documentation
106
- 4. **Automatic Consolidation**: Similar decisions merge into the canonical record
107
- 5. **Discoverable History**: `suggest` tool finds related decisions instantly
108
-
109
- ### Combining Context with Duplicate Detection
110
-
111
- **Best Practice**: Use duplicate detection to find existing records, then add context:
112
-
113
- ```typescript
114
- // Step 1: Check for existing related decisions
115
- {
116
- action: "check_duplicate",
117
- key: "cache-strategy-redis",
118
- tags: ["caching", "performance", "redis"]
119
- }
120
-
121
- // Response shows existing "cache-implementation" decision
122
-
123
- // Step 2: Update existing record (Tier 3 auto-update)
124
- {
125
- action: "set",
126
- key: "cache-strategy-redis",
127
- value: "Redis LRU cache with 1000-item limit",
128
- tags: ["caching", "performance", "redis"],
129
- layer: "infrastructure"
130
- }
131
- // Auto-updates "cache-implementation" to v1.0.2
132
-
133
- // Step 3: Add rich context to the canonical record
134
- {
135
- action: "add_decision_context",
136
- key: "cache-implementation", // The actual key that was updated
137
- rationale: "Updated to Redis after hitting memory limits with in-process cache. 1000-item LRU covers 98% of requests.",
138
- alternatives_considered: [
139
- "Increase in-memory cache - Rejected: OOM risk",
140
- "Memcached - Rejected: No persistence",
141
- "Redis with TTL - Rejected: Hot items get evicted"
142
- ],
143
- tradeoffs: {
144
- "pros": ["Persistent cache", "Shared across instances", "Built-in LRU"],
145
- "cons": ["Network latency", "Operational complexity"]
146
- }
147
- }
148
- ```
149
-
150
- ### Policy-Based Historical Record Management
151
-
152
- Enable automatic duplicate checking for all decisions in a category:
153
-
154
- ```typescript
155
- {
156
- action: "create_policy",
157
- name: "architecture-decisions",
158
- defaults: {
159
- layer: "cross-cutting",
160
- tags: ["architecture"]
161
- },
162
- suggest_similar: 1, // Auto-check for duplicates
163
- validation_rules: {
164
- patterns: { key: "^arch/" }
165
- }
166
- }
167
-
168
- // Now all arch/* decisions automatically check history
169
- {
170
- action: "set",
171
- key: "arch/database-strategy",
172
- value: "PostgreSQL with read replicas",
173
- // Automatically checks for related arch/* decisions
174
- // Updates existing record if high similarity found
175
- }
176
- ```
177
-
178
- ### See Also
179
-
180
- - **[DECISION_INTELLIGENCE.md](DECISION_INTELLIGENCE.md)** - Complete three-tier system documentation
181
- - **[WORKFLOWS.md](WORKFLOWS.md)** - Workflow 5: Decision Intelligence & Duplicate Prevention
182
-
183
- ---
184
-
185
- ## When Do You Need This Feature?
186
-
187
- ### ❌ When You DON'T Need It
188
-
189
- **Simple Configuration Decisions** - Use regular `decision` tool:
190
- ```typescript
191
- // Just storing a value - no context needed
192
- { action: "set", key: "max_retries", value: 3 }
193
- { action: "set", key: "api_endpoint", value: "https://api.example.com" }
194
- ```
195
-
196
- **Obvious Choices** - Self-explanatory decisions:
197
- ```typescript
198
- // Technology choices that are industry standard
199
- { action: "set", key: "language", value: "TypeScript" }
200
- ```
201
-
202
- ---
203
-
204
- ### ✅ When You NEED It
205
-
206
- #### **Scenario 1: Multi-Session AI Development**
207
-
208
- **Problem**: You're developing a feature over multiple days. On Day 3, an AI agent revisits a Day 1 decision and doesn't understand why approach X was chosen over Y.
209
-
210
- **Before Decision Context** (Day 1):
211
- ```typescript
212
- // Agent 1 makes a decision
213
- { action: "set", key: "auth/token_storage", value: "httponly_cookie" }
214
- ```
215
-
216
- **On Day 3** - Agent 2 asks: *"Why httponly cookie instead of localStorage?"*
217
- - No documented rationale
218
- - Agent 2 might waste 20 minutes re-evaluating the same alternatives
219
- - Risk of choosing a worse approach due to lack of context
220
-
221
- **With Decision Context** (Day 1):
222
- ```typescript
223
- // Agent 1 documents the decision with full context
224
- {
225
- action: "add_decision_context",
226
- key: "auth/token_storage",
227
- rationale: "Using httpOnly cookies to prevent XSS attacks. The application handles sensitive financial data, so localStorage (vulnerable to XSS) is unacceptable despite better mobile support.",
228
- alternatives_considered: [
229
- "localStorage - Rejected: Vulnerable to XSS attacks",
230
- "sessionStorage - Rejected: Doesn't persist across tabs",
231
- "IndexedDB - Rejected: Overly complex for simple token storage"
232
- ],
233
- tradeoffs: {
234
- "pros": [
235
- "XSS-resistant (httpOnly flag)",
236
- "Automatic CSRF protection with SameSite",
237
- "Works on all modern browsers"
238
- ],
239
- "cons": [
240
- "Requires server-side session management",
241
- "More complex mobile app integration",
242
- "Cannot be accessed by JavaScript"
243
- ]
244
- },
245
- decided_by: "security-agent"
246
- }
247
- ```
248
-
249
- **On Day 3** - Agent 2 reads the context:
250
- - ✅ Instantly understands security was the priority
251
- - ✅ Sees all alternatives were already evaluated
252
- - ✅ No wasted time re-analyzing
253
- - ✅ Can make informed decision if requirements change
254
-
255
- ---
256
-
257
- #### **Scenario 2: Architecture Reviews & Team Handoffs**
258
-
259
- **Problem**: New developer (or AI agent) joins the project 6 months later. They see a non-standard architecture choice and want to "fix" it, not knowing it was intentional.
260
-
261
- **Real Example: Database Choice**
262
-
263
- **Without Context**:
264
- ```typescript
265
- { action: "set", key: "db/engine", value: "sqlite" }
266
- ```
267
-
268
- **New developer thinks**: *"SQLite? That's just for prototypes. Let me migrate to PostgreSQL..."*
269
- - Wastes 2 days migrating
270
- - Breaks deployment (the app runs on edge functions where PostgreSQL isn't available)
271
- - Rolls back changes
272
-
273
- **With Context**:
274
- ```typescript
275
- {
276
- action: "add_decision_context",
277
- key: "db/engine",
278
- rationale: "Using SQLite because this app deploys to Cloudflare Workers (edge compute), which provides D1 (SQLite-compatible). PostgreSQL is not available in this environment. Performance requirements are modest (< 1000 req/min).",
279
- alternatives_considered: [
280
- "PostgreSQL - Rejected: Not available on Cloudflare Workers edge runtime",
281
- "DynamoDB - Rejected: Adds 50-100ms latency vs local SQLite",
282
- "Durable Objects - Rejected: Experimental, limited query capabilities"
283
- ],
284
- tradeoffs: {
285
- "pros": [
286
- "Zero latency (co-located with compute)",
287
- "Native Cloudflare D1 support",
288
- "No external database costs",
289
- "Simple deployment"
290
- ],
291
- "cons": [
292
- "Limited to 1GB database size",
293
- "No real-time multi-write (uses eventual consistency)",
294
- "Fewer advanced SQL features than PostgreSQL"
295
- ]
296
- },
297
- decided_by: "architect-agent",
298
- related_constraint_id: 42 // Links to "must run on edge" constraint
299
- }
300
- ```
301
-
302
- **New developer reads context**:
303
- - ✅ Understands deployment environment constraint
304
- - ✅ Sees PostgreSQL was already evaluated and rejected
305
- - ✅ Saves 2 days of wasted migration work
306
- - ✅ Can propose alternative if constraints change
307
-
308
- ---
309
-
310
- #### **Scenario 3: Breaking Changes & Deprecations**
311
-
312
- **Problem**: You need to introduce a breaking API change. Future agents need to understand why compatibility was broken and how to migrate.
313
-
314
- **Example: API Versioning**
315
-
316
- **Without Context**:
317
- ```typescript
318
- { action: "set", key: "api/version", value: "v2" }
319
- ```
320
-
321
- **Future agent sees v1 code and thinks**: *"This is old, should I delete it?"*
322
-
323
- **With Context**:
324
- ```typescript
325
- {
326
- action: "add_decision_context",
327
- key: "api/version_v2_breaking_change",
328
- rationale: "Introduced v2 API with breaking changes to fix fundamental design flaw in v1's authentication model. V1 used client-provided user IDs (security vulnerability CVE-2024-XXXX). V2 enforces server-side session validation. V1 will be deprecated 2025-12-31.",
329
- alternatives_considered: [
330
- "Patch v1 in-place - Rejected: Would break all existing clients immediately",
331
- "Add optional server-validation flag - Rejected: Allows insecure usage to persist",
332
- "Create v2 with gradual migration - Selected: Gives clients 12 months to migrate"
333
- ],
334
- tradeoffs: {
335
- "pros": [
336
- "Fixes critical security vulnerability",
337
- "Provides migration window for clients",
338
- "Cleaner API design in v2"
339
- ],
340
- "cons": [
341
- "Requires maintaining two API versions for 12 months",
342
- "Client migration effort (approx 2 hours per integration)",
343
- "Potential user confusion during transition"
344
- ]
345
- },
346
- decided_by: "security-team",
347
- related_task_id: 156 // Links to "Implement v2 API" task
348
- }
349
- ```
350
-
351
- **Future agent benefits**:
352
- - ✅ Understands why v1 can't be deleted yet (12-month migration window)
353
- - ✅ Knows exact deprecation date (2025-12-31)
354
- - ✅ Can communicate migration requirements to users
355
- - ✅ Understands security reasoning behind breaking change
356
-
357
- ---
358
-
359
- #### **Scenario 4: Performance Optimization Trade-offs**
360
-
361
- **Problem**: Performance optimization often involves trade-offs (memory vs speed, complexity vs latency). Future agents need to understand these choices to avoid "optimizing" in the wrong direction.
362
-
363
- **Example: Caching Strategy**
364
-
365
- **With Context**:
366
- ```typescript
367
- {
368
- action: "add_decision_context",
369
- key: "cache/strategy",
370
- rationale: "Using LRU cache with 1000-item limit instead of unbounded cache. Benchmarks showed 1000 items covers 98% of requests with 50MB memory usage. Unbounded cache grew to 2GB in production testing, causing OOM errors.",
371
- alternatives_considered: [
372
- "Unbounded cache - Rejected: Memory leaks in long-running processes",
373
- "TTL-based cache - Rejected: Hot items get evicted unnecessarily",
374
- "Two-tier (L1 LRU + L2 Redis) - Rejected: Adds 5ms latency and operational complexity"
375
- ],
376
- tradeoffs: {
377
- "pros": [
378
- "Predictable memory usage (max 50MB)",
379
- "98% hit rate on production traffic",
380
- "Simple implementation (no external dependencies)"
381
- ],
382
- "cons": [
383
- "2% of requests miss cache (cold items)",
384
- "No cross-server cache sharing",
385
- "Requires tuning item limit per deployment size"
386
- ]
387
- },
388
- decided_by: "performance-agent"
389
- }
390
- ```
391
-
392
- **Future optimization agent**:
393
- - ✅ Understands 1000-item limit is intentional (not arbitrary)
394
- - ✅ Knows unbounded cache was already tested and failed
395
- - ✅ Can propose Redis tier if cross-server sharing becomes critical
396
- - ✅ Won't waste time re-benchmarking already-tested alternatives
397
-
398
- ---
399
-
400
- ## Workflow Patterns
401
-
402
- ### Pattern 1: Decision → Context → Task
403
-
404
- **Use when**: A decision requires implementation work
405
-
406
- ```typescript
407
- // Step 1: Make the decision
408
- {
409
- action: "set",
410
- key: "db/connection_pooling",
411
- value: "enabled",
412
- tags: ["performance", "database"]
413
- }
414
-
415
- // Step 2: Document context
416
- {
417
- action: "add_decision_context",
418
- key: "db/connection_pooling",
419
- rationale: "Enabling connection pooling to reduce connection overhead from 50ms to 5ms per query. Application makes 100 req/sec, so this saves 4.5 seconds of connection time per second (90% reduction).",
420
- tradeoffs: {
421
- "pros": ["90% connection time reduction", "Better resource utilization"],
422
- "cons": ["Requires pool size tuning", "More complex error handling"]
423
- }
424
- }
425
-
426
- // Step 3: Create implementation task
427
- {
428
- action: "create",
429
- title: "Implement database connection pooling",
430
- layer: "data",
431
- tags: ["performance"],
432
- priority: "high"
433
- }
434
-
435
- // Step 4: Link decision to task
436
- {
437
- action: "add_decision_context",
438
- key: "db/connection_pooling",
439
- rationale: "...", // Same as above
440
- related_task_id: 123 // Link to the task created in step 3
441
- }
442
- ```
443
-
444
- ---
445
-
446
- ### Pattern 2: Review Decision Context Over Time
447
-
448
- **Use when**: Requirements change, and you need to revisit old decisions
449
-
450
- ```typescript
451
- // Query all decision contexts for a specific layer
452
- {
453
- action: "list_decision_contexts",
454
- decision_key: "auth/token_storage" // Get all context entries for this decision
455
- }
456
-
457
- // Example response:
458
- {
459
- "contexts": [
460
- {
461
- "id": 1,
462
- "decision_key": "auth/token_storage",
463
- "rationale": "Using httpOnly cookies...",
464
- "decided_by": "security-agent",
465
- "decision_date": "2025-01-15T10:00:00Z"
466
- },
467
- {
468
- "id": 5,
469
- "decision_key": "auth/token_storage",
470
- "rationale": "Updated to add SameSite=Strict after CSRF attack attempt...",
471
- "decided_by": "security-team",
472
- "decision_date": "2025-03-20T14:30:00Z"
473
- }
474
- ]
475
- }
476
- ```
477
-
478
- **Insight**: Decision context accumulates over time, showing decision evolution.
479
-
480
- ---
481
-
482
- ## Best Practices
483
-
484
- ### 1. Write for Future You (or Future AI)
485
-
486
- Assume the reader has **zero context** about your project. Explain:
487
- - **Why** this decision was necessary
488
- - **What problem** it solves
489
- - **Why alternatives** were rejected
490
-
491
- ❌ Bad rationale:
492
- ```
493
- "Using Redis for better performance"
494
- ```
495
-
496
- ✅ Good rationale:
497
- ```
498
- "Using Redis for session storage to handle 10,000 concurrent users. Previous in-memory storage caused server crashes under load due to limited RAM (8GB per instance). Redis provides distributed storage with automatic failover."
499
- ```
500
-
501
- ---
502
-
503
- ### 2. Use JSON Arrays for Alternatives
504
-
505
- Make alternatives scannable and structured:
506
-
507
- ```typescript
508
- alternatives_considered: [
509
- "Option A - Rejected: Reason X",
510
- "Option B - Rejected: Reason Y",
511
- "Option C - Selected: Reason Z"
512
- ]
513
- ```
514
-
515
- ---
516
-
517
- ### 3. Balance Pros/Cons Honestly
518
-
519
- Don't hide the downsides - future developers need to know when to revisit:
520
-
521
- ```typescript
522
- tradeoffs: {
523
- "pros": [
524
- "Fast implementation (2 days)",
525
- "Well-documented library"
526
- ],
527
- "cons": [
528
- "Library is deprecated (EOL 2026)", // Important to know!
529
- "License is AGPL (might conflict with commercial use)"
530
- ]
531
- }
532
- ```
533
-
534
- ---
535
-
536
- ### 4. Link to Related Work
537
-
538
- Create traceability:
539
-
540
- ```typescript
541
- {
542
- related_task_id: 42, // Implementation task
543
- related_constraint_id: 7 // "Must support offline mode" constraint
544
- }
545
- ```
546
-
547
- ---
548
-
549
- ## API Reference
550
-
551
- ### Add Decision Context
552
-
553
- ```typescript
554
- {
555
- action: "add_decision_context",
556
- key: "decision_key", // Required: Decision to document
557
- rationale: "Explanation...", // Required: Why this decision?
558
- alternatives_considered: [ // Optional: JSON array
559
- "Alternative 1 - Rejected: Reason",
560
- "Alternative 2 - Selected: Reason"
561
- ],
562
- tradeoffs: { // Optional: JSON object
563
- "pros": ["Pro 1", "Pro 2"],
564
- "cons": ["Con 1", "Con 2"]
565
- },
566
- decided_by: "agent-name", // Optional: Who decided
567
- related_task_id: 123, // Optional: Link to task
568
- related_constraint_id: 45 // Optional: Link to constraint
569
- }
570
- ```
571
-
572
- ### Get Decision with Context
573
-
574
- ```typescript
575
- {
576
- action: "get",
577
- key: "decision_key",
578
- include_context: true // Include all context entries
579
- }
580
- ```
581
-
582
- ### List Decision Contexts
583
-
584
- ```typescript
585
- {
586
- action: "list_decision_contexts",
587
- decision_key: "auth/token_storage", // Optional: Filter by decision
588
- related_task_id: 123, // Optional: Filter by task
589
- limit: 50, // Optional: Default 50
590
- offset: 0 // Optional: Default 0
591
- }
592
- ```
593
-
594
- ---
595
-
596
- ## Version History
597
-
598
- | Version | Changes |
599
- |---------|---------|
600
- | **v4.0.0** | Feature fully preserved. Schema refactored with `v4_` prefix: `v4_decision_context` table. No API changes. |
601
- | **v3.9.0** | Added Decision Intelligence System with duplicate detection and automatic historical record consolidation. Added `check_duplicate`, `versions`, and policy-based management. |
602
- | **v3.2.2** | Initial Release: `add_decision_context` action, `rationale`, `alternatives_considered`, `tradeoffs` fields, `related_task_id` and `related_constraint_id` linking. |
603
-
604
- ---
605
-
606
- ## Token Efficiency
607
-
608
- **Decision Context is optional** - only use it for important decisions where future understanding is critical.
609
-
610
- **Token Cost Comparison**:
611
- - Simple decision: ~50 tokens
612
- - Decision with context: ~200-500 tokens
613
- - Time saved avoiding re-analysis: 1000-5000 tokens
614
-
615
- **Use it when**:
616
- - Decision is non-obvious or controversial
617
- - Trade-offs were significant
618
- - Future developers might question the choice
619
- - Multiple alternatives were considered
620
-
621
- **Skip it when**:
622
- - Decision is self-explanatory
623
- - Value is temporary/experimental
624
- - Standard industry practice
625
-
626
- ---
627
-
628
- ## Migration from Old Decisions
629
-
630
- If you have old decisions that need context, add it retroactively:
631
-
632
- ```typescript
633
- // Step 1: Find old decision
634
- { action: "get", key: "old_decision" }
635
-
636
- // Step 2: Add context
637
- {
638
- action: "add_decision_context",
639
- key: "old_decision",
640
- rationale: "Retroactive documentation: This decision was made on 2024-06-15 to solve problem X. At the time, we chose approach Y because of constraint Z."
641
- }
642
- ```
643
-
644
- ---
645
-
646
- ## Summary: When to Use Decision Context
647
-
648
- | **Scenario** | **Use Decision Context?** | **Why?** |
649
- |-------------|---------------------------|----------|
650
- | Simple config value | ❌ No | Self-explanatory |
651
- | Architecture choice | ✅ Yes | Future developers need to understand trade-offs |
652
- | Breaking change | ✅ Yes | Migration context critical |
653
- | Temporary experiment | ❌ No | Will be replaced soon |
654
- | Performance optimization | ✅ Yes | Trade-offs need documentation |
655
- | Security decision | ✅ Yes | Reasoning must be preserved |
656
- | Technology selection | ✅ Yes | Alternatives evaluation important |
657
-
658
- ---
659
-
660
- ## Key Takeaways
661
-
662
- ### ADR for AI Agents: Context + Intelligence = Complete Knowledge Repository
663
-
664
- **sqlew transforms traditional ADR into an AI-native knowledge system:**
665
-
666
- 1. **ADR Data Model** (v3.2.2) → Structured storage of decisions with rationale, alternatives, and trade-offs
667
- 2. **Decision Intelligence** (v3.9.0) → Automatic duplicate detection and version consolidation
668
- 3. **AI-Native Queries** → Fast, structured access to architectural decisions across sessions
669
-
670
- **Together they provide:**
671
- - **Living ADR repository** – Decisions evolve with your project through version history
672
- - **AI-queryable records** – Search by tags, layers, similarity instead of reading files
673
- - **Automatic consolidation** – Prevent duplicate ADRs, maintain single source of truth
674
- - **Complete context** – Capture WHY, not just WHAT (alternatives, trade-offs, consequences)
675
- - **Cross-session memory** – AI agents maintain architectural understanding across days/weeks
676
-
677
- ### ADR Best Practices for AI
678
-
679
- **Before creating a decision:**
680
- 1. Use `check_duplicate` to find existing related ADRs
681
- 2. Review similar decisions to avoid redundancy
682
- 3. Update existing ADR if it's the same topic
683
-
684
- **When documenting a decision:**
685
- 1. Include **rationale** – Explain WHY this choice was made
686
- 2. Document **alternatives** – Show what was considered and rejected
687
- 3. Capture **trade-offs** – Honest pros/cons for future reference
688
- 4. Link **related entities** – Connect to tasks, files, constraints
689
-
690
- **After implementation:**
691
- 1. Track affected files to show ADR impact
692
- 2. Update decision status as it evolves (active → deprecated → superseded)
693
- 3. Query `versions` to see architectural evolution over time
694
-
695
- **ADR transforms your codebase from "what we built" into "why we built it this way"** - making architectural decisions discoverable and understandable to AI agents across the entire project lifecycle.
696
-
697
- **Decision Intelligence ensures ADRs remain living documents** - automatically consolidated and updated rather than scattered across fragmented entries.