sqlew 4.0.4 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/CHANGELOG.md +1805 -1762
  2. package/LICENSE +177 -39
  3. package/NOTICE +24 -0
  4. package/README.md +409 -390
  5. package/assets/claude-md-snippets/plan-mode-integration.md +17 -6
  6. package/assets/config.example.toml +282 -284
  7. package/assets/sample-agents/README.md +36 -40
  8. package/assets/sample-agents/sqlew-architect.md +321 -322
  9. package/assets/sample-agents/sqlew-researcher.md +292 -293
  10. package/assets/sample-agents/sqlew-scrum-master.md +286 -287
  11. package/assets/sample-commands/README.md +56 -57
  12. package/assets/sample-skills/sqlew-plan-guidance/SKILL.md +33 -26
  13. package/dist/cli/hooks/check-completion.d.ts +19 -0
  14. package/dist/cli/hooks/check-completion.d.ts.map +1 -0
  15. package/dist/cli/hooks/check-completion.js +104 -0
  16. package/dist/cli/hooks/check-completion.js.map +1 -0
  17. package/dist/cli/hooks/init-hooks.d.ts +35 -0
  18. package/dist/cli/hooks/init-hooks.d.ts.map +1 -0
  19. package/dist/cli/hooks/init-hooks.js +425 -0
  20. package/dist/cli/hooks/init-hooks.js.map +1 -0
  21. package/dist/cli/hooks/mark-done.d.ts +25 -0
  22. package/dist/cli/hooks/mark-done.d.ts.map +1 -0
  23. package/dist/cli/hooks/mark-done.js +128 -0
  24. package/dist/cli/hooks/mark-done.js.map +1 -0
  25. package/dist/cli/hooks/plan-id-utils.d.ts +83 -0
  26. package/dist/cli/hooks/plan-id-utils.d.ts.map +1 -0
  27. package/dist/cli/hooks/plan-id-utils.js +183 -0
  28. package/dist/cli/hooks/plan-id-utils.js.map +1 -0
  29. package/dist/cli/hooks/save.d.ts +23 -0
  30. package/dist/cli/hooks/save.d.ts.map +1 -0
  31. package/dist/cli/hooks/save.js +90 -0
  32. package/dist/cli/hooks/save.js.map +1 -0
  33. package/dist/cli/hooks/stdin-parser.d.ts +139 -0
  34. package/dist/cli/hooks/stdin-parser.d.ts.map +1 -0
  35. package/dist/cli/hooks/stdin-parser.js +127 -0
  36. package/dist/cli/hooks/stdin-parser.js.map +1 -0
  37. package/dist/cli/hooks/suggest.d.ts +19 -0
  38. package/dist/cli/hooks/suggest.d.ts.map +1 -0
  39. package/dist/cli/hooks/suggest.js +157 -0
  40. package/dist/cli/hooks/suggest.js.map +1 -0
  41. package/dist/cli/hooks/track-plan.d.ts +36 -0
  42. package/dist/cli/hooks/track-plan.d.ts.map +1 -0
  43. package/dist/cli/hooks/track-plan.js +152 -0
  44. package/dist/cli/hooks/track-plan.js.map +1 -0
  45. package/dist/cli.d.ts.map +1 -1
  46. package/dist/cli.js +56 -16
  47. package/dist/cli.js.map +1 -1
  48. package/dist/config/global-config.d.ts +187 -0
  49. package/dist/config/global-config.d.ts.map +1 -0
  50. package/dist/config/global-config.js +206 -0
  51. package/dist/config/global-config.js.map +1 -0
  52. package/dist/config/loader.d.ts +42 -0
  53. package/dist/config/loader.d.ts.map +1 -1
  54. package/dist/config/loader.js +96 -0
  55. package/dist/config/loader.js.map +1 -1
  56. package/dist/constants.d.ts +4 -0
  57. package/dist/constants.d.ts.map +1 -1
  58. package/dist/constants.js +10 -0
  59. package/dist/constants.js.map +1 -1
  60. package/dist/database/operations/queries.d.ts.map +1 -1
  61. package/dist/database/operations/queries.js +11 -2
  62. package/dist/database/operations/queries.js.map +1 -1
  63. package/dist/index.js +5 -2
  64. package/dist/index.js.map +1 -1
  65. package/dist/init-agents.js +0 -1
  66. package/dist/init-agents.js.map +1 -1
  67. package/dist/init-skills.d.ts +4 -3
  68. package/dist/init-skills.d.ts.map +1 -1
  69. package/dist/init-skills.js +10 -3
  70. package/dist/init-skills.js.map +1 -1
  71. package/dist/server/setup.d.ts +8 -0
  72. package/dist/server/setup.d.ts.map +1 -1
  73. package/dist/server/setup.js +141 -21
  74. package/dist/server/setup.js.map +1 -1
  75. package/dist/sync-agents.d.ts.map +1 -1
  76. package/dist/sync-agents.js +48 -3
  77. package/dist/sync-agents.js.map +1 -1
  78. package/dist/sync-commands.d.ts.map +1 -1
  79. package/dist/sync-commands.js +43 -3
  80. package/dist/sync-commands.js.map +1 -1
  81. package/dist/tools/constraints/actions/get.d.ts.map +1 -1
  82. package/dist/tools/constraints/actions/get.js +5 -8
  83. package/dist/tools/constraints/actions/get.js.map +1 -1
  84. package/dist/tools/constraints/help/help.d.ts.map +1 -1
  85. package/dist/tools/constraints/help/help.js +1 -6
  86. package/dist/tools/constraints/help/help.js.map +1 -1
  87. package/dist/tools/context/actions/get.d.ts.map +1 -1
  88. package/dist/tools/context/actions/get.js.map +1 -1
  89. package/dist/tools/context/actions/search-layer.d.ts.map +1 -1
  90. package/dist/tools/context/actions/search-layer.js +5 -3
  91. package/dist/tools/context/actions/search-layer.js.map +1 -1
  92. package/dist/tools/context/actions/set-from-policy.d.ts +2 -1
  93. package/dist/tools/context/actions/set-from-policy.d.ts.map +1 -1
  94. package/dist/tools/context/actions/set-from-policy.js.map +1 -1
  95. package/dist/tools/context/help/help.d.ts.map +1 -1
  96. package/dist/tools/context/help/help.js +1 -7
  97. package/dist/tools/context/help/help.js.map +1 -1
  98. package/dist/tools/context/internal/queries.d.ts.map +1 -1
  99. package/dist/tools/context/internal/queries.js +5 -2
  100. package/dist/tools/context/internal/queries.js.map +1 -1
  101. package/dist/tools/context/types.d.ts +1 -1
  102. package/dist/tools/context/types.d.ts.map +1 -1
  103. package/dist/tools/files/actions/get.d.ts.map +1 -1
  104. package/dist/tools/files/actions/get.js +4 -6
  105. package/dist/tools/files/actions/get.js.map +1 -1
  106. package/dist/tools/files/help/help.d.ts.map +1 -1
  107. package/dist/tools/files/help/help.js +1 -6
  108. package/dist/tools/files/help/help.js.map +1 -1
  109. package/dist/tools/suggest/help/constraint-help.d.ts.map +1 -1
  110. package/dist/tools/suggest/help/constraint-help.js +0 -2
  111. package/dist/tools/suggest/help/constraint-help.js.map +1 -1
  112. package/dist/tools/suggest/internal/constraint-queries.d.ts.map +1 -1
  113. package/dist/tools/suggest/internal/constraint-queries.js +12 -5
  114. package/dist/tools/suggest/internal/constraint-queries.js.map +1 -1
  115. package/dist/tools/suggest/internal/queries.js +2 -2
  116. package/dist/tools/suggest/internal/queries.js.map +1 -1
  117. package/dist/tools/tasks/help/help.d.ts.map +1 -1
  118. package/dist/tools/tasks/help/help.js +0 -6
  119. package/dist/tools/tasks/help/help.js.map +1 -1
  120. package/dist/tools/tasks/help/use-case.d.ts.map +1 -1
  121. package/dist/tools/tasks/help/use-case.js +0 -1
  122. package/dist/tools/tasks/help/use-case.js.map +1 -1
  123. package/dist/tools/tasks/watcher/status.d.ts.map +1 -1
  124. package/dist/tools/tasks/watcher/status.js +5 -1
  125. package/dist/tools/tasks/watcher/status.js.map +1 -1
  126. package/dist/types/decision/params.d.ts +7 -6
  127. package/dist/types/decision/params.d.ts.map +1 -1
  128. package/dist/types/decision/templates.d.ts +3 -2
  129. package/dist/types/decision/templates.d.ts.map +1 -1
  130. package/dist/types/view-entities.d.ts +2 -1
  131. package/dist/types/view-entities.d.ts.map +1 -1
  132. package/dist/types.d.ts +19 -11
  133. package/dist/types.d.ts.map +1 -1
  134. package/dist/types.js +4 -1
  135. package/dist/types.js.map +1 -1
  136. package/dist/utils/enum-converter.d.ts +72 -0
  137. package/dist/utils/enum-converter.d.ts.map +1 -0
  138. package/dist/utils/enum-converter.js +76 -0
  139. package/dist/utils/enum-converter.js.map +1 -0
  140. package/dist/utils/hook-queue.d.ts +81 -0
  141. package/dist/utils/hook-queue.d.ts.map +1 -0
  142. package/dist/utils/hook-queue.js +156 -0
  143. package/dist/utils/hook-queue.js.map +1 -0
  144. package/dist/utils/project-root.d.ts +9 -2
  145. package/dist/utils/project-root.d.ts.map +1 -1
  146. package/dist/utils/project-root.js +16 -2
  147. package/dist/utils/project-root.js.map +1 -1
  148. package/dist/utils/tag-parser.d.ts.map +1 -1
  149. package/dist/utils/tag-parser.js +6 -0
  150. package/dist/utils/tag-parser.js.map +1 -1
  151. package/dist/utils/validators.d.ts +1 -1
  152. package/dist/utils/validators.d.ts.map +1 -1
  153. package/dist/utils/validators.js +1 -1
  154. package/dist/utils/validators.js.map +1 -1
  155. package/dist/utils/vcs-adapter.d.ts +44 -0
  156. package/dist/utils/vcs-adapter.d.ts.map +1 -1
  157. package/dist/utils/vcs-adapter.js +88 -0
  158. package/dist/utils/vcs-adapter.js.map +1 -1
  159. package/dist/utils/view-queries.d.ts.map +1 -1
  160. package/dist/utils/view-queries.js +9 -19
  161. package/dist/utils/view-queries.js.map +1 -1
  162. package/dist/watcher/base-watcher.d.ts +69 -0
  163. package/dist/watcher/base-watcher.d.ts.map +1 -0
  164. package/dist/watcher/base-watcher.js +130 -0
  165. package/dist/watcher/base-watcher.js.map +1 -0
  166. package/dist/watcher/index.d.ts +3 -0
  167. package/dist/watcher/index.d.ts.map +1 -1
  168. package/dist/watcher/index.js +2 -0
  169. package/dist/watcher/index.js.map +1 -1
  170. package/dist/watcher/queue-watcher.d.ts +64 -0
  171. package/dist/watcher/queue-watcher.d.ts.map +1 -0
  172. package/dist/watcher/queue-watcher.js +187 -0
  173. package/dist/watcher/queue-watcher.js.map +1 -0
  174. package/docs/ADR_CONCEPTS.md +140 -0
  175. package/docs/CONFIGURATION.md +922 -925
  176. package/docs/CROSS_DATABASE.md +153 -0
  177. package/docs/DATABASE_AUTH.md +70 -356
  178. package/docs/HOOKS_GUIDE.md +159 -0
  179. package/docs/SLASH_COMMANDS.md +329 -337
  180. package/docs/TASK_SYSTEM_DEPRECATED.md +88 -0
  181. package/docs/changelogs/CHANGELOG_ARCHIVE_v3.4_and_older.md +293 -296
  182. package/docs/cli/DATA_EXPORT_IMPORT.md +699 -700
  183. package/docs/cli/README.md +276 -277
  184. package/package.json +123 -119
  185. package/docs/ACCEPTANCE_CRITERIA.md +0 -625
  186. package/docs/AI_AGENT_GUIDE.md +0 -198
  187. package/docs/ARCHITECTURE.md +0 -167
  188. package/docs/AUTO_FILE_TRACKING.md +0 -841
  189. package/docs/BATCH_VALIDATION.md +0 -617
  190. package/docs/BEST_PRACTICES.md +0 -168
  191. package/docs/CONSTRAINT_INTELLIGENCE.md +0 -339
  192. package/docs/DECISION_CONTEXT.md +0 -675
  193. package/docs/DECISION_INTELLIGENCE.md +0 -605
  194. package/docs/GIT_AWARE_AUTO_COMPLETE.md +0 -646
  195. package/docs/MIGRATION_GUIDE_V3.9.0.md +0 -371
  196. package/docs/SHARED_CONCEPTS.md +0 -225
  197. package/docs/SPECIALIZED_AGENTS.md +0 -126
  198. package/docs/TASK_ACTIONS.md +0 -1177
  199. package/docs/TASK_OVERVIEW.md +0 -452
  200. package/docs/TASK_PRUNING.md +0 -594
  201. package/docs/TOOL_REFERENCE.md +0 -1077
  202. package/docs/TOOL_SELECTION.md +0 -83
  203. package/docs/WORKFLOWS.md +0 -941
@@ -1,168 +0,0 @@
1
- # Best Practices & Troubleshooting
2
-
3
- ## Critical Rules
4
-
5
- ### 1. Always Include `action` Parameter
6
- **#1 cause of errors**
7
-
8
- ```javascript
9
- ❌ { key: "some_key", value: "some value" }
10
- ✅ { action: "set", key: "some_key", value: "some value" }
11
- ```
12
-
13
- ### 2. Store WHY in Decisions, Not WHAT
14
-
15
- **Organizational memory gap:**
16
- - Git history → WHAT changed
17
- - Code comments → HOW it works
18
- - **Decisions** → WHY it was changed (reasoning, trade-offs)
19
- - **Tasks** → WHAT needs to be done (work status)
20
-
21
- ### Good vs Bad Examples
22
-
23
- **✅ GOOD - Store WHY:**
24
- - "Chose JWT because: stateless scales, mobile caching, distributed auth. Trade-off: needs blacklist."
25
- - "Nested transaction bug: setDecision wraps, batch wraps → extract internal helper."
26
- - "Duration must NOT be in Loom - breaks architectural separation."
27
-
28
- **❌ BAD - Don't store WHAT:**
29
- - "v3.0.2 testing complete. All tools verified working." → Use tasks
30
- - "Refactoring complete. Query builder created." → Use git commits
31
- - "PASS - All tests passing." → Use CI/CD logs
32
- - "Doc restructure complete." → Use git commits
33
-
34
- ---
35
-
36
- ## Parameter Validation Patterns
37
-
38
- **NEW in dev branch**: sqlew provides comprehensive parameter validation with helpful error messages.
39
-
40
- ### How Validation Helps
41
-
42
- 1. **Catch Typos Early** - Get instant feedback on misspelled parameter names
43
- 2. **Learn by Example** - Every error includes a working example
44
- 3. **Clear Requirements** - Know exactly which parameters are required vs optional
45
- 4. **Visual Markers** - Help responses show 🔴 REQUIRED and ⚪ OPTIONAL
46
-
47
- ### Common Validation Errors and Fixes
48
-
49
- **Missing Required Parameter:**
50
- ```javascript
51
- // ❌ ERROR: Missing required parameter 'value'
52
- { action: "set", key: "auth_method" }
53
-
54
- // ✅ FIX: Add required parameter
55
- { action: "set", key: "auth_method", value: "JWT authentication chosen" }
56
- ```
57
-
58
- **Typo in Parameter Name:**
59
- ```javascript
60
- // ❌ ERROR: Unknown parameter 'tgas' (did you mean 'tags'?)
61
- { action: "set", key: "api/v2", value: "New API", tgas: ["api"] }
62
-
63
- // ✅ FIX: Correct the typo
64
- { action: "set", key: "api/v2", value: "New API", tags: ["api"] }
65
- ```
66
-
67
- **Wrong Action Name:**
68
- ```javascript
69
- // ❌ ERROR: Unknown action 'create_task' (did you mean 'create'?)
70
- { action: "create_task", title: "Implement auth" }
71
-
72
- // ✅ FIX: Use correct action name
73
- { action: "create", title: "Implement auth" }
74
- ```
75
-
76
- **Parameters from Wrong Action:**
77
- ```javascript
78
- // ❌ ERROR: Unknown parameter 'task_id' for action 'create'
79
- { action: "create", task_id: 5, title: "New task" }
80
-
81
- // ✅ FIX: Use 'update' action instead
82
- { action: "update", task_id: 5, title: "Updated task" }
83
- ```
84
-
85
- ### Reading Validation Error Messages
86
-
87
- Error messages provide structured guidance:
88
-
89
- ```json
90
- {
91
- "error": "Missing required parameter for action 'set': value",
92
- "missing_params": ["value"], // What you're missing
93
- "required_params": ["key", "value"], // All required fields
94
- "optional_params": ["agent", "layer"], // All optional fields
95
- "you_provided": ["key", "layer"], // What you actually sent
96
- "example": { ... }, // Working example
97
- "hint": "Use 'quick_set' for simpler..." // Helpful tip
98
- }
99
- ```
100
-
101
- ---
102
-
103
- ## Common Errors
104
-
105
- | Error | Cause | Solution |
106
- |-------|-------|----------|
107
- | "Unknown action: undefined" | Missing `action` | Always include `action` parameter |
108
- | "Missing required parameter" | Omitted required field | Check `required_params` in error message |
109
- | "Unknown parameter" | Typo or wrong action | Check `did_you_mean` suggestions |
110
- | "Parameter 'value' is required" | Using `defaults` with templates | Pass parameters directly, not in `defaults` |
111
- | "Invalid layer" | Wrong layer name | Use: presentation, business, data, infrastructure, cross-cutting |
112
- | "Invalid status" | Wrong status | Use: active, deprecated, draft |
113
- | "Batch limit exceeded" | >50 items | Split into batches of ≤50 |
114
-
115
- ---
116
-
117
- ## Best Practices
118
-
119
- 1. **Always use `action` parameter** - Required in ALL calls
120
- 2. **Use `atomic: false` for batches** - Avoid transaction failures
121
- 3. **Choose right search action** - `list` (simple), `search_tags` (tag-focused), `search_advanced` (complex)
122
- 4. **Use templates** - For repeated decision patterns
123
- 5. **Meaningful tags** - Descriptive, consistent naming
124
- 6. **Always specify `layer`** - Organizes architectural concerns
125
- 7. **Use `has_updates`** - Check before fetching (95% token savings)
126
- 8. **Handle errors** - Check for `error` field in responses
127
- 9. **Constraints for requirements** - Use `constraint` for rules, `decision` for choices
128
- 10. **Clean up regularly** - Use `clear` action or auto-cleanup config
129
-
130
- ### Decision Intelligence Best Practices (v3.9.0)
131
-
132
- 11. **Use `check_duplicate` before `set`** - Prevent redundant decisions
133
- 12. **Enable policy auto-triggering** - Set `suggest_similar: 1` for consistent checks
134
- 13. **Handle three-tier responses** - Review gentle nudges, resolve hard blocks, trust auto-updates
135
- 14. **Provide `ignore_reason`** - Always document why bypassing duplicate detection
136
- 15. **Use consistent tag taxonomy** - Better similarity scoring with consistent tags
137
- 16. **Use descriptive keys** - Pattern-based keys (`api/users/auth`) enable better matching
138
-
139
- ---
140
-
141
- ## Performance Tips
142
-
143
- **Token Efficiency:**
144
- - `has_updates` before fetching (95% savings)
145
- - Metadata-only task queries (70% smaller)
146
- - Batch operations (52% reduction)
147
-
148
- **Database Health:**
149
- - Monitor with `db_stats`
150
- - Enable auto-cleanup
151
- - Archive completed tasks
152
-
153
- **Multi-Agent:**
154
- - Priority levels for messages
155
- - Link tasks to decisions
156
- - Update status promptly
157
-
158
- ---
159
-
160
- ## Related Documentation
161
-
162
- - [TOOL_SELECTION.md](TOOL_SELECTION.md) - Tool selection guide
163
- - [TOOL_REFERENCE.md](TOOL_REFERENCE.md) - Parameter reference
164
- - [WORKFLOWS.md](WORKFLOWS.md) - Multi-step workflows
165
- - [SHARED_CONCEPTS.md](SHARED_CONCEPTS.md) - Layers, enums, concepts
166
- - [DECISION_INTELLIGENCE.md](DECISION_INTELLIGENCE.md) - Three-tier duplicate detection (v3.9.0)
167
-
168
- **Tip**: Use `{action: "help"}` for any tool's detailed documentation.
@@ -1,339 +0,0 @@
1
- # Constraint Intelligence System (v4.0.0)
2
-
3
- **Status:** Production Ready
4
- **Release Date:** 2025-11-27
5
-
6
- ---
7
-
8
- ## Overview
9
-
10
- The Constraint Intelligence System provides duplicate detection and similarity-based suggestions for architectural constraints. It complements the [Decision Intelligence System](DECISION_INTELLIGENCE.md) with constraint-specific scoring and workflows.
11
-
12
- ### Key Features
13
-
14
- - **Duplicate Detection**: Two-phase check (exact match, then similarity)
15
- - **Hybrid Scoring**: Combines text, tags, layer, recency, and priority
16
- - **Constraint-Specific Scoring**: Optimized for rule-based content
17
- - **Pre-Creation Validation**: Check before adding new constraints
18
-
19
- ---
20
-
21
- ## Accessing Constraint Suggestions
22
-
23
- Use `target: "constraint"` with the suggest tool:
24
-
25
- ```javascript
26
- // Default is target: "decision"
27
- suggest({
28
- action: "by_tags",
29
- target: "constraint", // Required for constraint suggestions
30
- tags: ["api", "performance"]
31
- })
32
- ```
33
-
34
- ---
35
-
36
- ## Scoring Algorithm
37
-
38
- ### Components (100 points max)
39
-
40
- | Component | Max Points | Description |
41
- |-----------|-----------|-------------|
42
- | Tag overlap | 40 | 10 per matching tag (max 4 tags) |
43
- | Layer match | 25 | Exact layer match |
44
- | Text similarity | 20 | Levenshtein distance calculation |
45
- | Recency | 10 | Recently updated constraints score higher |
46
- | Priority | 5 | Higher priority constraints score higher |
47
-
48
- ### Recency Tiers
49
-
50
- | Age | Points |
51
- |-----|--------|
52
- | < 30 days | 10 |
53
- | 30-90 days | 5 |
54
- | 90-180 days | 2 |
55
- | > 180 days | 0 |
56
-
57
- ### Priority Scores
58
-
59
- | Priority | Level | Points |
60
- |----------|-------|--------|
61
- | 4 | Critical | 5 |
62
- | 3 | High | 4 |
63
- | 2 | Medium | 3 |
64
- | 1 | Low | 2 |
65
-
66
- ### Thresholds
67
-
68
- | Threshold | Value | Description |
69
- |-----------|-------|-------------|
70
- | Default min_score | 30 | Minimum score for suggestions |
71
- | Duplicate threshold | 70 | Score triggering duplicate warning |
72
-
73
- ---
74
-
75
- ## Actions
76
-
77
- ### by_key - Text Pattern Search
78
-
79
- Find similar constraints by text pattern (alias for by_context with text only).
80
-
81
- ```javascript
82
- suggest({
83
- action: "by_key",
84
- target: "constraint",
85
- text: "API response time", // Required: text to match
86
- layer: "business", // Optional: filter by layer
87
- limit: 5, // Optional: max results (default: 5)
88
- min_score: 30 // Optional: minimum score (default: 30)
89
- })
90
- ```
91
-
92
- ### by_tags - Tag-Based Discovery
93
-
94
- Find constraints by tag overlap (fast).
95
-
96
- ```javascript
97
- suggest({
98
- action: "by_tags",
99
- target: "constraint",
100
- tags: ["api", "performance"], // Required: tags to match
101
- layer: "business", // Optional: filter by layer
102
- limit: 5, // Optional
103
- min_score: 30 // Optional
104
- })
105
- ```
106
-
107
- ### by_context - Hybrid Search
108
-
109
- Comprehensive search combining text, tags, layer, and priority.
110
-
111
- ```javascript
112
- suggest({
113
- action: "by_context",
114
- target: "constraint",
115
- text: "database query", // Optional
116
- tags: ["sql"], // Optional
117
- layer: "data", // Optional (also used for scoring)
118
- priority: 3, // Optional (for scoring)
119
- limit: 5, // Optional
120
- min_score: 30 // Optional
121
- })
122
-
123
- // Note: At least one of text, tags, or layer required
124
- ```
125
-
126
- ### check_duplicate - Pre-Creation Check
127
-
128
- Two-phase duplicate detection before creating constraints.
129
-
130
- ```javascript
131
- suggest({
132
- action: "check_duplicate",
133
- target: "constraint",
134
- text: "API response time must be under 100ms", // Required
135
- category: "performance" // Optional: filter by category
136
- })
137
-
138
- // Response:
139
- {
140
- is_duplicate: false,
141
- match_type: "similar", // "exact" | "similar" | "none"
142
- existing: null, // Existing constraint (if exact)
143
- similar_constraints: [...], // Array of similar constraints
144
- score: 65, // Similarity score of top match
145
- recommendation: "Similar constraint found..."
146
- }
147
- ```
148
-
149
- ---
150
-
151
- ## Workflows
152
-
153
- ### Before Creating a Constraint
154
-
155
- ```javascript
156
- // Step 1: Check for duplicates
157
- const result = await suggest({
158
- action: "check_duplicate",
159
- target: "constraint",
160
- text: "API response time must be under 100ms"
161
- });
162
-
163
- // Step 2: Handle result
164
- if (result.is_duplicate) {
165
- // Exact match exists - update instead
166
- console.log("Constraint exists:", result.existing);
167
- } else if (result.match_type === "similar") {
168
- // Review similar constraints
169
- console.log("Similar constraints:", result.similar_constraints);
170
- // Decide: create new or update existing
171
- } else {
172
- // Safe to create new constraint
173
- constraint({ action: "add", ... });
174
- }
175
- ```
176
-
177
- ### Finding Related Constraints
178
-
179
- ```javascript
180
- // Fast: Tag-based discovery
181
- const byTags = await suggest({
182
- action: "by_tags",
183
- target: "constraint",
184
- tags: ["security", "authentication"]
185
- });
186
-
187
- // Comprehensive: Hybrid search
188
- const byContext = await suggest({
189
- action: "by_context",
190
- target: "constraint",
191
- text: "password policy",
192
- tags: ["security"],
193
- layer: "business"
194
- });
195
-
196
- // Review score_breakdown to understand relevance
197
- byContext.suggestions.forEach(s => {
198
- console.log(s.constraint_text, s.score_breakdown);
199
- });
200
- ```
201
-
202
- ---
203
-
204
- ## Response Structure
205
-
206
- ### Suggestion Object
207
-
208
- ```typescript
209
- {
210
- id: number, // Constraint ID
211
- constraint_text: string, // Full constraint text
212
- category: string, // Constraint category
213
- score: number, // Total relevance score (0-100)
214
- reason: string, // Human-readable explanation
215
- score_breakdown: {
216
- tag_overlap: number,
217
- layer_match: number,
218
- text_similarity: number,
219
- recency: number,
220
- priority: number
221
- },
222
- layer?: string, // Assigned layer
223
- tags?: string[], // Associated tags
224
- ts?: number // Last updated timestamp
225
- }
226
- ```
227
-
228
- ---
229
-
230
- ## Comparison: Decision vs Constraint Intelligence
231
-
232
- | Feature | Decision Intelligence | Constraint Intelligence |
233
- |---------|----------------------|------------------------|
234
- | Target | `"decision"` (default) | `"constraint"` |
235
- | Scoring max | 100 points | 100 points |
236
- | Key/Text weight | 40 points | 20 points |
237
- | Tag weight | 30 points | 40 points |
238
- | Layer weight | 15 points | 25 points |
239
- | Recency | - | 10 points |
240
- | Priority | - | 5 points |
241
- | Auto-update tier | Yes (60+) | No |
242
- | Hard block tier | Yes (45-59) | No |
243
- | Duplicate threshold | 60+ auto-update | 70 warning |
244
-
245
- ### Why Different Scoring?
246
-
247
- **Decisions** focus on key patterns and value similarity (choices already made).
248
-
249
- **Constraints** focus on tag overlap and layer match (rules that must be enforced).
250
-
251
- ---
252
-
253
- ## Best Practices
254
-
255
- ### 1. Use Consistent Tags
256
-
257
- ```javascript
258
- // Good: Consistent taxonomy
259
- tags: ["api", "performance", "latency"]
260
-
261
- // Avoid: Inconsistent naming
262
- tags: ["API", "perf", "response-time"]
263
- ```
264
-
265
- ### 2. Check Before Creating
266
-
267
- ```javascript
268
- // Always check for duplicates
269
- suggest({
270
- action: "check_duplicate",
271
- target: "constraint",
272
- text: "Your constraint text"
273
- })
274
- ```
275
-
276
- ### 3. Use by_tags for Discovery
277
-
278
- ```javascript
279
- // Fast discovery of related constraints
280
- suggest({
281
- action: "by_tags",
282
- target: "constraint",
283
- tags: ["security"]
284
- })
285
- ```
286
-
287
- ### 4. Review score_breakdown
288
-
289
- ```javascript
290
- // Understand why a constraint was suggested
291
- suggestions.forEach(s => {
292
- if (s.score_breakdown.tag_overlap > 30) {
293
- // High tag overlap - likely related
294
- }
295
- if (s.score_breakdown.layer_match === 25) {
296
- // Same layer - consider consolidation
297
- }
298
- });
299
- ```
300
-
301
- ---
302
-
303
- ## Configuration
304
-
305
- **File:** `src/constants.ts`
306
-
307
- ```typescript
308
- // Constraint suggestion defaults
309
- export const CONSTRAINT_SUGGEST_DEFAULTS = {
310
- MIN_SCORE: 30,
311
- LIMIT: 5,
312
- DUPLICATE_THRESHOLD: 70,
313
- } as const;
314
-
315
- // Score weights
316
- export const CONSTRAINT_SCORE_WEIGHTS = {
317
- TAG_OVERLAP: 10, // Per matching tag (max 40)
318
- LAYER_MATCH: 25, // Exact match
319
- TEXT_SIMILARITY: 20, // Max based on Levenshtein
320
- RECENCY_MAX: 10, // Based on age tiers
321
- PRIORITY_MAX: 5, // Based on priority level
322
- } as const;
323
- ```
324
-
325
- ---
326
-
327
- ## Related Documentation
328
-
329
- | Document | Content |
330
- |----------|---------|
331
- | [DECISION_INTELLIGENCE.md](DECISION_INTELLIGENCE.md) | Decision duplicate detection |
332
- | [TOOL_REFERENCE.md](TOOL_REFERENCE.md) | Complete parameter reference |
333
- | [SHARED_CONCEPTS.md](SHARED_CONCEPTS.md) | Layers, priorities, tags |
334
- | [TOOL_SELECTION.md](TOOL_SELECTION.md) | Constraint vs Decision selection |
335
-
336
- ---
337
-
338
- **Version:** 4.0.0
339
- **Last Updated:** 2025-11-27