sqlew 3.1.2 → 3.2.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 (70) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/README.md +58 -3
  3. package/assets/schema.sql +28 -1
  4. package/dist/database.d.ts +65 -0
  5. package/dist/database.d.ts.map +1 -1
  6. package/dist/database.js +190 -0
  7. package/dist/database.js.map +1 -1
  8. package/dist/index.js +47 -1005
  9. package/dist/index.js.map +1 -1
  10. package/dist/migrations/add-decision-context.d.ts +28 -0
  11. package/dist/migrations/add-decision-context.d.ts.map +1 -0
  12. package/dist/migrations/add-decision-context.js +125 -0
  13. package/dist/migrations/add-decision-context.js.map +1 -0
  14. package/dist/migrations/add-task-dependencies.d.ts +26 -0
  15. package/dist/migrations/add-task-dependencies.d.ts.map +1 -0
  16. package/dist/migrations/add-task-dependencies.js +94 -0
  17. package/dist/migrations/add-task-dependencies.js.map +1 -0
  18. package/dist/migrations/index.d.ts +3 -1
  19. package/dist/migrations/index.d.ts.map +1 -1
  20. package/dist/migrations/index.js +32 -2
  21. package/dist/migrations/index.js.map +1 -1
  22. package/dist/schema.js +2 -2
  23. package/dist/schema.js.map +1 -1
  24. package/dist/tests/migrations/test-v3.2-migration.d.ts +6 -0
  25. package/dist/tests/migrations/test-v3.2-migration.d.ts.map +1 -0
  26. package/dist/tests/migrations/test-v3.2-migration.js +191 -0
  27. package/dist/tests/migrations/test-v3.2-migration.js.map +1 -0
  28. package/dist/tests/tasks.dependencies.test.d.ts +7 -0
  29. package/dist/tests/tasks.dependencies.test.d.ts.map +1 -0
  30. package/dist/tests/tasks.dependencies.test.js +613 -0
  31. package/dist/tests/tasks.dependencies.test.js.map +1 -0
  32. package/dist/tools/config.d.ts +10 -0
  33. package/dist/tools/config.d.ts.map +1 -1
  34. package/dist/tools/config.js +105 -0
  35. package/dist/tools/config.js.map +1 -1
  36. package/dist/tools/constraints.d.ts +10 -0
  37. package/dist/tools/constraints.d.ts.map +1 -1
  38. package/dist/tools/constraints.js +167 -0
  39. package/dist/tools/constraints.js.map +1 -1
  40. package/dist/tools/context.d.ts +29 -2
  41. package/dist/tools/context.d.ts.map +1 -1
  42. package/dist/tools/context.js +442 -106
  43. package/dist/tools/context.js.map +1 -1
  44. package/dist/tools/files.d.ts +8 -0
  45. package/dist/tools/files.d.ts.map +1 -1
  46. package/dist/tools/files.js +125 -0
  47. package/dist/tools/files.js.map +1 -1
  48. package/dist/tools/messaging.d.ts +8 -0
  49. package/dist/tools/messaging.d.ts.map +1 -1
  50. package/dist/tools/messaging.js +134 -0
  51. package/dist/tools/messaging.js.map +1 -1
  52. package/dist/tools/tasks.d.ts +32 -0
  53. package/dist/tools/tasks.d.ts.map +1 -1
  54. package/dist/tools/tasks.js +651 -8
  55. package/dist/tools/tasks.js.map +1 -1
  56. package/dist/tools/utils.d.ts +10 -0
  57. package/dist/tools/utils.d.ts.map +1 -1
  58. package/dist/tools/utils.js +179 -21
  59. package/dist/tools/utils.js.map +1 -1
  60. package/dist/types.d.ts +26 -0
  61. package/dist/types.d.ts.map +1 -1
  62. package/docs/AI_AGENT_GUIDE.md +25 -3
  63. package/docs/DECISION_CONTEXT.md +474 -0
  64. package/docs/HELP_PREVIEW_COMPARISON.md +259 -0
  65. package/docs/TASK_ACTIONS.md +311 -10
  66. package/docs/TASK_DEPENDENCIES.md +748 -0
  67. package/docs/TASK_LINKING.md +188 -8
  68. package/docs/TOOL_REFERENCE.md +158 -1
  69. package/docs/WORKFLOWS.md +25 -3
  70. package/package.json +4 -2
@@ -0,0 +1,474 @@
1
+ # Decision Context - Rich Decision Documentation (v3.2.2)
2
+
3
+ ## Overview
4
+
5
+ The **Decision Context** feature allows you to attach rich documentation to architectural and implementation decisions, explaining **WHY** a decision was made, what alternatives were considered, and the trade-offs involved. This goes beyond simple key-value storage to provide deep historical context that helps future developers (both human and AI) understand past reasoning.
6
+
7
+ ---
8
+
9
+ ## When Do You Need This Feature?
10
+
11
+ ### ❌ When You DON'T Need It
12
+
13
+ **Simple Configuration Decisions** - Use regular `decision` tool:
14
+ ```typescript
15
+ // Just storing a value - no context needed
16
+ { action: "set", key: "max_retries", value: 3 }
17
+ { action: "set", key: "api_endpoint", value: "https://api.example.com" }
18
+ ```
19
+
20
+ **Obvious Choices** - Self-explanatory decisions:
21
+ ```typescript
22
+ // Technology choices that are industry standard
23
+ { action: "set", key: "language", value: "TypeScript" }
24
+ ```
25
+
26
+ ---
27
+
28
+ ### ✅ When You NEED It
29
+
30
+ #### **Scenario 1: Multi-Session AI Development**
31
+
32
+ **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.
33
+
34
+ **Before Decision Context** (Day 1):
35
+ ```typescript
36
+ // Agent 1 makes a decision
37
+ { action: "set", key: "auth/token_storage", value: "httponly_cookie" }
38
+ ```
39
+
40
+ **On Day 3** - Agent 2 asks: *"Why httponly cookie instead of localStorage?"*
41
+ - No documented rationale
42
+ - Agent 2 might waste 20 minutes re-evaluating the same alternatives
43
+ - Risk of choosing a worse approach due to lack of context
44
+
45
+ **With Decision Context** (Day 1):
46
+ ```typescript
47
+ // Agent 1 documents the decision with full context
48
+ {
49
+ action: "add_decision_context",
50
+ key: "auth/token_storage",
51
+ 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.",
52
+ alternatives_considered: [
53
+ "localStorage - Rejected: Vulnerable to XSS attacks",
54
+ "sessionStorage - Rejected: Doesn't persist across tabs",
55
+ "IndexedDB - Rejected: Overly complex for simple token storage"
56
+ ],
57
+ tradeoffs: {
58
+ "pros": [
59
+ "XSS-resistant (httpOnly flag)",
60
+ "Automatic CSRF protection with SameSite",
61
+ "Works on all modern browsers"
62
+ ],
63
+ "cons": [
64
+ "Requires server-side session management",
65
+ "More complex mobile app integration",
66
+ "Cannot be accessed by JavaScript"
67
+ ]
68
+ },
69
+ decided_by: "security-agent"
70
+ }
71
+ ```
72
+
73
+ **On Day 3** - Agent 2 reads the context:
74
+ - ✅ Instantly understands security was the priority
75
+ - ✅ Sees all alternatives were already evaluated
76
+ - ✅ No wasted time re-analyzing
77
+ - ✅ Can make informed decision if requirements change
78
+
79
+ ---
80
+
81
+ #### **Scenario 2: Architecture Reviews & Team Handoffs**
82
+
83
+ **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.
84
+
85
+ **Real Example: Database Choice**
86
+
87
+ **Without Context**:
88
+ ```typescript
89
+ { action: "set", key: "db/engine", value: "sqlite" }
90
+ ```
91
+
92
+ **New developer thinks**: *"SQLite? That's just for prototypes. Let me migrate to PostgreSQL..."*
93
+ - Wastes 2 days migrating
94
+ - Breaks deployment (the app runs on edge functions where PostgreSQL isn't available)
95
+ - Rolls back changes
96
+
97
+ **With Context**:
98
+ ```typescript
99
+ {
100
+ action: "add_decision_context",
101
+ key: "db/engine",
102
+ 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).",
103
+ alternatives_considered: [
104
+ "PostgreSQL - Rejected: Not available on Cloudflare Workers edge runtime",
105
+ "DynamoDB - Rejected: Adds 50-100ms latency vs local SQLite",
106
+ "Durable Objects - Rejected: Experimental, limited query capabilities"
107
+ ],
108
+ tradeoffs: {
109
+ "pros": [
110
+ "Zero latency (co-located with compute)",
111
+ "Native Cloudflare D1 support",
112
+ "No external database costs",
113
+ "Simple deployment"
114
+ ],
115
+ "cons": [
116
+ "Limited to 1GB database size",
117
+ "No real-time multi-write (uses eventual consistency)",
118
+ "Fewer advanced SQL features than PostgreSQL"
119
+ ]
120
+ },
121
+ decided_by: "architect-agent",
122
+ related_constraint_id: 42 // Links to "must run on edge" constraint
123
+ }
124
+ ```
125
+
126
+ **New developer reads context**:
127
+ - ✅ Understands deployment environment constraint
128
+ - ✅ Sees PostgreSQL was already evaluated and rejected
129
+ - ✅ Saves 2 days of wasted migration work
130
+ - ✅ Can propose alternative if constraints change
131
+
132
+ ---
133
+
134
+ #### **Scenario 3: Breaking Changes & Deprecations**
135
+
136
+ **Problem**: You need to introduce a breaking API change. Future agents need to understand why compatibility was broken and how to migrate.
137
+
138
+ **Example: API Versioning**
139
+
140
+ **Without Context**:
141
+ ```typescript
142
+ { action: "set", key: "api/version", value: "v2" }
143
+ ```
144
+
145
+ **Future agent sees v1 code and thinks**: *"This is old, should I delete it?"*
146
+
147
+ **With Context**:
148
+ ```typescript
149
+ {
150
+ action: "add_decision_context",
151
+ key: "api/version_v2_breaking_change",
152
+ 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.",
153
+ alternatives_considered: [
154
+ "Patch v1 in-place - Rejected: Would break all existing clients immediately",
155
+ "Add optional server-validation flag - Rejected: Allows insecure usage to persist",
156
+ "Create v2 with gradual migration - Selected: Gives clients 12 months to migrate"
157
+ ],
158
+ tradeoffs: {
159
+ "pros": [
160
+ "Fixes critical security vulnerability",
161
+ "Provides migration window for clients",
162
+ "Cleaner API design in v2"
163
+ ],
164
+ "cons": [
165
+ "Requires maintaining two API versions for 12 months",
166
+ "Client migration effort (approx 2 hours per integration)",
167
+ "Potential user confusion during transition"
168
+ ]
169
+ },
170
+ decided_by: "security-team",
171
+ related_task_id: 156 // Links to "Implement v2 API" task
172
+ }
173
+ ```
174
+
175
+ **Future agent benefits**:
176
+ - ✅ Understands why v1 can't be deleted yet (12-month migration window)
177
+ - ✅ Knows exact deprecation date (2025-12-31)
178
+ - ✅ Can communicate migration requirements to users
179
+ - ✅ Understands security reasoning behind breaking change
180
+
181
+ ---
182
+
183
+ #### **Scenario 4: Performance Optimization Trade-offs**
184
+
185
+ **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.
186
+
187
+ **Example: Caching Strategy**
188
+
189
+ **With Context**:
190
+ ```typescript
191
+ {
192
+ action: "add_decision_context",
193
+ key: "cache/strategy",
194
+ 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.",
195
+ alternatives_considered: [
196
+ "Unbounded cache - Rejected: Memory leaks in long-running processes",
197
+ "TTL-based cache - Rejected: Hot items get evicted unnecessarily",
198
+ "Two-tier (L1 LRU + L2 Redis) - Rejected: Adds 5ms latency and operational complexity"
199
+ ],
200
+ tradeoffs: {
201
+ "pros": [
202
+ "Predictable memory usage (max 50MB)",
203
+ "98% hit rate on production traffic",
204
+ "Simple implementation (no external dependencies)"
205
+ ],
206
+ "cons": [
207
+ "2% of requests miss cache (cold items)",
208
+ "No cross-server cache sharing",
209
+ "Requires tuning item limit per deployment size"
210
+ ]
211
+ },
212
+ decided_by: "performance-agent"
213
+ }
214
+ ```
215
+
216
+ **Future optimization agent**:
217
+ - ✅ Understands 1000-item limit is intentional (not arbitrary)
218
+ - ✅ Knows unbounded cache was already tested and failed
219
+ - ✅ Can propose Redis tier if cross-server sharing becomes critical
220
+ - ✅ Won't waste time re-benchmarking already-tested alternatives
221
+
222
+ ---
223
+
224
+ ## Workflow Patterns
225
+
226
+ ### Pattern 1: Decision → Context → Task
227
+
228
+ **Use when**: A decision requires implementation work
229
+
230
+ ```typescript
231
+ // Step 1: Make the decision
232
+ {
233
+ action: "set",
234
+ key: "db/connection_pooling",
235
+ value: "enabled",
236
+ tags: ["performance", "database"]
237
+ }
238
+
239
+ // Step 2: Document context
240
+ {
241
+ action: "add_decision_context",
242
+ key: "db/connection_pooling",
243
+ 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).",
244
+ tradeoffs: {
245
+ "pros": ["90% connection time reduction", "Better resource utilization"],
246
+ "cons": ["Requires pool size tuning", "More complex error handling"]
247
+ }
248
+ }
249
+
250
+ // Step 3: Create implementation task
251
+ {
252
+ action: "create",
253
+ title: "Implement database connection pooling",
254
+ layer: "data",
255
+ tags: ["performance"],
256
+ priority: "high"
257
+ }
258
+
259
+ // Step 4: Link decision to task
260
+ {
261
+ action: "add_decision_context",
262
+ key: "db/connection_pooling",
263
+ rationale: "...", // Same as above
264
+ related_task_id: 123 // Link to the task created in step 3
265
+ }
266
+ ```
267
+
268
+ ---
269
+
270
+ ### Pattern 2: Review Decision Context Over Time
271
+
272
+ **Use when**: Requirements change, and you need to revisit old decisions
273
+
274
+ ```typescript
275
+ // Query all decision contexts for a specific layer
276
+ {
277
+ action: "list_decision_contexts",
278
+ decision_key: "auth/token_storage" // Get all context entries for this decision
279
+ }
280
+
281
+ // Example response:
282
+ {
283
+ "contexts": [
284
+ {
285
+ "id": 1,
286
+ "decision_key": "auth/token_storage",
287
+ "rationale": "Using httpOnly cookies...",
288
+ "decided_by": "security-agent",
289
+ "decision_date": "2025-01-15T10:00:00Z"
290
+ },
291
+ {
292
+ "id": 5,
293
+ "decision_key": "auth/token_storage",
294
+ "rationale": "Updated to add SameSite=Strict after CSRF attack attempt...",
295
+ "decided_by": "security-team",
296
+ "decision_date": "2025-03-20T14:30:00Z"
297
+ }
298
+ ]
299
+ }
300
+ ```
301
+
302
+ **Insight**: Decision context accumulates over time, showing decision evolution.
303
+
304
+ ---
305
+
306
+ ## Best Practices
307
+
308
+ ### 1. Write for Future You (or Future AI)
309
+
310
+ Assume the reader has **zero context** about your project. Explain:
311
+ - **Why** this decision was necessary
312
+ - **What problem** it solves
313
+ - **Why alternatives** were rejected
314
+
315
+ ❌ Bad rationale:
316
+ ```
317
+ "Using Redis for better performance"
318
+ ```
319
+
320
+ ✅ Good rationale:
321
+ ```
322
+ "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."
323
+ ```
324
+
325
+ ---
326
+
327
+ ### 2. Use JSON Arrays for Alternatives
328
+
329
+ Make alternatives scannable and structured:
330
+
331
+ ```typescript
332
+ alternatives_considered: [
333
+ "Option A - Rejected: Reason X",
334
+ "Option B - Rejected: Reason Y",
335
+ "Option C - Selected: Reason Z"
336
+ ]
337
+ ```
338
+
339
+ ---
340
+
341
+ ### 3. Balance Pros/Cons Honestly
342
+
343
+ Don't hide the downsides - future developers need to know when to revisit:
344
+
345
+ ```typescript
346
+ tradeoffs: {
347
+ "pros": [
348
+ "Fast implementation (2 days)",
349
+ "Well-documented library"
350
+ ],
351
+ "cons": [
352
+ "Library is deprecated (EOL 2026)", // Important to know!
353
+ "License is AGPL (might conflict with commercial use)"
354
+ ]
355
+ }
356
+ ```
357
+
358
+ ---
359
+
360
+ ### 4. Link to Related Work
361
+
362
+ Create traceability:
363
+
364
+ ```typescript
365
+ {
366
+ related_task_id: 42, // Implementation task
367
+ related_constraint_id: 7 // "Must support offline mode" constraint
368
+ }
369
+ ```
370
+
371
+ ---
372
+
373
+ ## API Reference
374
+
375
+ ### Add Decision Context
376
+
377
+ ```typescript
378
+ {
379
+ action: "add_decision_context",
380
+ key: "decision_key", // Required: Decision to document
381
+ rationale: "Explanation...", // Required: Why this decision?
382
+ alternatives_considered: [ // Optional: JSON array
383
+ "Alternative 1 - Rejected: Reason",
384
+ "Alternative 2 - Selected: Reason"
385
+ ],
386
+ tradeoffs: { // Optional: JSON object
387
+ "pros": ["Pro 1", "Pro 2"],
388
+ "cons": ["Con 1", "Con 2"]
389
+ },
390
+ decided_by: "agent-name", // Optional: Who decided
391
+ related_task_id: 123, // Optional: Link to task
392
+ related_constraint_id: 45 // Optional: Link to constraint
393
+ }
394
+ ```
395
+
396
+ ### Get Decision with Context
397
+
398
+ ```typescript
399
+ {
400
+ action: "get",
401
+ key: "decision_key",
402
+ include_context: true // Include all context entries
403
+ }
404
+ ```
405
+
406
+ ### List Decision Contexts
407
+
408
+ ```typescript
409
+ {
410
+ action: "list_decision_contexts",
411
+ decision_key: "auth/token_storage", // Optional: Filter by decision
412
+ related_task_id: 123, // Optional: Filter by task
413
+ limit: 50, // Optional: Default 50
414
+ offset: 0 // Optional: Default 0
415
+ }
416
+ ```
417
+
418
+ ---
419
+
420
+ ## Token Efficiency
421
+
422
+ **Decision Context is optional** - only use it for important decisions where future understanding is critical.
423
+
424
+ **Token Cost Comparison**:
425
+ - Simple decision: ~50 tokens
426
+ - Decision with context: ~200-500 tokens
427
+ - Time saved avoiding re-analysis: 1000-5000 tokens
428
+
429
+ **Use it when**:
430
+ - Decision is non-obvious or controversial
431
+ - Trade-offs were significant
432
+ - Future developers might question the choice
433
+ - Multiple alternatives were considered
434
+
435
+ **Skip it when**:
436
+ - Decision is self-explanatory
437
+ - Value is temporary/experimental
438
+ - Standard industry practice
439
+
440
+ ---
441
+
442
+ ## Migration from Old Decisions
443
+
444
+ If you have old decisions that need context, add it retroactively:
445
+
446
+ ```typescript
447
+ // Step 1: Find old decision
448
+ { action: "get", key: "old_decision" }
449
+
450
+ // Step 2: Add context
451
+ {
452
+ action: "add_decision_context",
453
+ key: "old_decision",
454
+ 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."
455
+ }
456
+ ```
457
+
458
+ ---
459
+
460
+ ## Summary: When to Use Decision Context
461
+
462
+ | **Scenario** | **Use Decision Context?** | **Why?** |
463
+ |-------------|---------------------------|----------|
464
+ | Simple config value | ❌ No | Self-explanatory |
465
+ | Architecture choice | ✅ Yes | Future developers need to understand trade-offs |
466
+ | Breaking change | ✅ Yes | Migration context critical |
467
+ | Temporary experiment | ❌ No | Will be replaced soon |
468
+ | Performance optimization | ✅ Yes | Trade-offs need documentation |
469
+ | Security decision | ✅ Yes | Reasoning must be preserved |
470
+ | Technology selection | ✅ Yes | Alternatives evaluation important |
471
+
472
+ ---
473
+
474
+ **Decision Context transforms decisions from "what" into "why"** - making your codebase understandable to future developers and AI agents across months or years of development.