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,594 +0,0 @@
1
- # Task File Auto-Pruning (v4.0.0)
2
-
3
- **Feature**: Automatic removal of non-existent watched files with audit trail preservation
4
-
5
- **Problem Solved**: Tasks watching planned files that were never created during implementation block quality gates indefinitely. Auto-pruning maintains clean watch lists while preserving project archaeology.
6
-
7
- ---
8
-
9
- ## Table of Contents
10
-
11
- - [Overview](#overview)
12
- - [How It Works](#how-it-works)
13
- - [Safety Checks](#safety-checks)
14
- - [Audit Trail](#audit-trail)
15
- - [MCP Actions](#mcp-actions)
16
- - [Use Cases](#use-cases)
17
- - [Best Practices](#best-practices)
18
- - [Configuration](#configuration)
19
- - [Examples](#examples)
20
-
21
- ---
22
-
23
- ## Overview
24
-
25
- ### The Problem
26
-
27
- When implementing features, AI agents often watch files that represent planned work:
28
- - `src/api/new-endpoint.ts` - endpoint that was never needed
29
- - `src/utils/helper.ts` - functionality absorbed into existing code
30
- - `tests/integration/feature-x.test.ts` - test file that wasn't created
31
-
32
- When these files remain non-existent, tasks cannot transition to `waiting_review` because the quality gate requires ALL watched files to be modified. This blocks workflow progression.
33
-
34
- ### The Solution
35
-
36
- **v4.0.0 Auto-Pruning** automatically removes non-existent watched files when tasks transition to `waiting_review`, while preserving a complete audit trail for project archaeology.
37
-
38
- ### Key Benefits
39
-
40
- 1. **Clean Watch Lists**: Non-existent files removed automatically
41
- 2. **Audit Trail**: Every pruned file recorded with timestamp
42
- 3. **Decision Linking**: Optional WHY reasoning for project archaeology
43
- 4. **Safety Checks**: Cannot complete tasks with zero work done
44
- 5. **Zero Configuration**: Works out of the box
45
-
46
- ---
47
-
48
- ## How It Works
49
-
50
- ### Trigger Point
51
-
52
- Auto-pruning is triggered during the `in_progress → waiting_review` transition in the `detectAndTransitionToReview()` function. This timing ensures:
53
- - Files are checked only when work is considered "complete"
54
- - Pruning happens before quality gate validation
55
- - No manual intervention required
56
-
57
- ### Execution Flow
58
-
59
- ```
60
- 1. Task idle for configured time (default: 3 minutes)
61
- 2. detectAndTransitionToReview() runs periodic check
62
- 3. FOR EACH candidate task:
63
- a. Get watched files
64
- b. Check filesystem existence
65
- c. Identify non-existent files
66
- d. **SAFETY CHECK**: If ALL files non-existent → BLOCK transition
67
- e. Prune non-existent files
68
- f. Record to v4_task_pruned_files audit table
69
- g. Remove from v4_task_file_links
70
- h. Continue with quality gate checks on remaining files
71
- 4. Transition to waiting_review (if quality gates pass)
72
- ```
73
-
74
- ### Database Changes
75
-
76
- **Table Created**: `v4_task_pruned_files`
77
- ```sql
78
- CREATE TABLE v4_task_pruned_files (
79
- id INTEGER PRIMARY KEY AUTOINCREMENT,
80
- task_id INTEGER NOT NULL REFERENCES v4_tasks(id) ON DELETE CASCADE,
81
- file_path TEXT NOT NULL,
82
- pruned_ts INTEGER DEFAULT (unixepoch()),
83
- linked_decision_id INTEGER REFERENCES v4_decisions(id) ON DELETE SET NULL
84
- );
85
- ```
86
-
87
- **Indexes**:
88
- - `idx_pruned_task`: Fast lookup by task
89
- - `idx_pruned_decision`: Fast lookup by linked decision
90
-
91
- ---
92
-
93
- ## Safety Checks
94
-
95
- ### Zero-Work Prevention
96
-
97
- **Rule**: If ALL watched files are non-existent, the transition is BLOCKED.
98
-
99
- **Rationale**: A task with no existing files indicates no actual work was performed. This prevents tasks from being marked complete when they should be closed or re-scoped.
100
-
101
- **Behavior**:
102
- ```typescript
103
- // Example: Task watches 3 files, all non-existent
104
- watchedFiles = [
105
- "src/feature-a.ts", // doesn't exist
106
- "src/feature-b.ts", // doesn't exist
107
- "tests/feature.test.ts" // doesn't exist
108
- ]
109
-
110
- // Auto-prune attempts to run
111
- // Safety check triggers: ALL files non-existent
112
- // Error: "Cannot prune files for task #42: ALL 3 watched files are non-existent..."
113
- // Task stays in 'in_progress'
114
- ```
115
-
116
- **Resolution Options**:
117
- 1. Verify at least one watched file exists (create placeholder if needed)
118
- 2. Mark task as invalid and close manually
119
- 3. Update watch list to include files that actually exist
120
-
121
- ### Partial Pruning
122
-
123
- **Rule**: If SOME files are non-existent, only those files are pruned.
124
-
125
- **Behavior**:
126
- ```typescript
127
- // Example: Task watches 3 files, 1 non-existent
128
- watchedFiles = [
129
- "src/feature-a.ts", // exists
130
- "src/feature-b.ts", // doesn't exist
131
- "tests/feature.test.ts" // exists
132
- ]
133
-
134
- // Auto-prune runs
135
- // Prunes: src/feature-b.ts
136
- // Keeps: src/feature-a.ts, tests/feature.test.ts
137
- // Records pruned file to audit table
138
- // Task continues to waiting_review
139
- ```
140
-
141
- ---
142
-
143
- ## Audit Trail
144
-
145
- ### Purpose
146
-
147
- The audit trail enables project archaeology:
148
- - **Post-Mortem Analysis**: Understand why planned files weren't created
149
- - **Architecture Reviews**: Track scope changes during implementation
150
- - **Team Handoffs**: Explain decisions to future developers
151
- - **Decision History**: Link to architectural decisions
152
-
153
- ### Data Preserved
154
-
155
- For each pruned file:
156
- - **file_path**: Raw path string (not normalized)
157
- - **pruned_ts**: Unix timestamp when pruned
158
- - **task_id**: Task that watched this file
159
- - **linked_decision_id**: Optional link to decision explaining WHY
160
-
161
- ### Persistence
162
-
163
- **Pruned files survive task archival** - audit records remain even after tasks are archived, enabling long-term project archaeology.
164
-
165
- ---
166
-
167
- ## MCP Actions
168
-
169
- ### get_pruned_files
170
-
171
- Retrieve audit trail for a task.
172
-
173
- **Action**: `get_pruned_files`
174
-
175
- **Parameters**:
176
- - `task_id` (required): Task ID
177
- - `limit` (optional): Max results (default: 100)
178
-
179
- **Example Request**:
180
- ```json
181
- {
182
- "action": "get_pruned_files",
183
- "task_id": 42,
184
- "limit": 50
185
- }
186
- ```
187
-
188
- **Example Response**:
189
- ```json
190
- {
191
- "success": true,
192
- "task_id": 42,
193
- "count": 2,
194
- "pruned_files": [
195
- {
196
- "id": 15,
197
- "file_path": "src/api/v2/endpoint.ts",
198
- "pruned_at": "2025-10-22 08:15:23",
199
- "linked_decision": "api-v1-sufficient"
200
- },
201
- {
202
- "id": 14,
203
- "file_path": "src/utils/deprecated.ts",
204
- "pruned_at": "2025-10-22 08:15:23",
205
- "linked_decision": null
206
- }
207
- ],
208
- "message": "Found 2 pruned file(s) for task 42"
209
- }
210
- ```
211
-
212
- ### link_pruned_file
213
-
214
- Attach WHY reasoning to a pruned file.
215
-
216
- **Action**: `link_pruned_file`
217
-
218
- **Parameters**:
219
- - `pruned_file_id` (required): Pruned file record ID
220
- - `decision_key` (required): Decision key to link
221
-
222
- **Example Request**:
223
- ```json
224
- {
225
- "action": "link_pruned_file",
226
- "pruned_file_id": 15,
227
- "decision_key": "api-v1-sufficient"
228
- }
229
- ```
230
-
231
- **Example Response**:
232
- ```json
233
- {
234
- "success": true,
235
- "pruned_file_id": 15,
236
- "decision_key": "api-v1-sufficient",
237
- "task_id": 42,
238
- "file_path": "src/api/v2/endpoint.ts",
239
- "message": "Linked pruned file \"src/api/v2/endpoint.ts\" to decision \"api-v1-sufficient\""
240
- }
241
- ```
242
-
243
- ---
244
-
245
- ## Use Cases
246
-
247
- ### Use Case 1: Endpoint Not Needed
248
-
249
- **Scenario**: Task planned to create `/api/v2/users` but during implementation, realized v1 endpoint was sufficient.
250
-
251
- **Workflow**:
252
- 1. Task created with watch files: `["src/api/v2/users.ts", "tests/api/v2/users.test.ts"]`
253
- 2. During implementation, agent updates existing v1 endpoint instead
254
- 3. Agent creates decision: `api-v1-sufficient` explaining why v2 wasn't needed
255
- 4. Task transitions to `waiting_review`
256
- 5. Auto-prune detects non-existent files, prunes them, records to audit
257
- 6. Agent links pruned files to decision via `link_pruned_file`
258
- 7. Future developers can see WHY v2 wasn't created
259
-
260
- **Commands**:
261
- ```bash
262
- # 1. Create decision
263
- mcp-tool decision set \
264
- --key "api-v1-sufficient" \
265
- --value "v1 endpoint handles all current requirements" \
266
- --layer "presentation"
267
-
268
- # 2. Get pruned files (after auto-prune)
269
- mcp-tool task get_pruned_files --task_id 42
270
-
271
- # 3. Link decision to pruned files
272
- mcp-tool task link_pruned_file \
273
- --pruned_file_id 15 \
274
- --decision_key "api-v1-sufficient"
275
- ```
276
-
277
- ### Use Case 2: Feature Absorbed into Existing Code
278
-
279
- **Scenario**: Planned utility module absorbed into existing helper.
280
-
281
- **Workflow**:
282
- 1. Task watches `src/utils/new-helper.ts`
283
- 2. During implementation, functionality added to `src/utils/existing-helper.ts`
284
- 3. Auto-prune removes non-existent `new-helper.ts`
285
- 4. Audit trail shows the file was planned but not created
286
-
287
- ### Use Case 3: Test Strategy Changed
288
-
289
- **Scenario**: Planned integration tests replaced with unit tests.
290
-
291
- **Workflow**:
292
- 1. Task watches `tests/integration/feature-x.test.ts`
293
- 2. Team decides unit tests are sufficient
294
- 3. Auto-prune removes integration test file
295
- 4. Decision linked explaining test strategy change
296
-
297
- ---
298
-
299
- ## Best Practices
300
-
301
- ### 1. Document WHY with Decisions
302
-
303
- **DO**: Link pruned files to decisions explaining reasoning
304
- ```bash
305
- # Create decision first
306
- task.decision.set({
307
- key: "feature-x-scope-reduced",
308
- value: "Feature X simplified during implementation"
309
- })
310
-
311
- # Link after pruning
312
- task.link_pruned_file({
313
- pruned_file_id: 15,
314
- decision_key: "feature-x-scope-reduced"
315
- })
316
- ```
317
-
318
- **DON'T**: Leave pruned files undocumented
319
- ```bash
320
- # Missing context - future developers won't understand why
321
- # (no decision link)
322
- ```
323
-
324
- ### 2. Review Pruned Files Regularly
325
-
326
- **DO**: Periodically review audit trail for patterns
327
- ```bash
328
- # Check recent prunings across all tasks
329
- task.get_pruned_files({ limit: 50 })
330
- ```
331
-
332
- **DON'T**: Ignore pruned files - they indicate planning issues
333
-
334
- ### 3. Use Pruning as Feedback
335
-
336
- **DO**: Treat frequent pruning as a signal to improve planning
337
- - If many files are pruned, planning phase needs refinement
338
- - Consider more conservative watch lists
339
- - Focus on must-have files only
340
-
341
- ### 4. Leverage for Post-Mortems
342
-
343
- **DO**: Use audit trail during sprint retrospectives
344
- ```sql
345
- -- Query pruned files for sprint analysis
346
- SELECT
347
- t.title,
348
- tpf.file_path,
349
- datetime(tpf.pruned_ts, 'unixepoch') as pruned_at,
350
- k.key as decision
351
- FROM v4_task_pruned_files tpf
352
- JOIN v4_tasks t ON tpf.task_id = t.id
353
- LEFT JOIN v4_decisions d ON tpf.linked_decision_id = d.id
354
- LEFT JOIN v4_context_keys k ON d.key_id = k.id
355
- WHERE tpf.pruned_ts >= unixepoch('now', '-7 days')
356
- ORDER BY tpf.pruned_ts DESC;
357
- ```
358
-
359
- ---
360
-
361
- ## Configuration
362
-
363
- ### Auto-Prune Timing
364
-
365
- Auto-pruning runs as part of `detectAndTransitionToReview()`, triggered by:
366
- - **Task idle time**: Default 3 minutes (configurable via `review_idle_minutes`)
367
- - **Periodic checks**: Runs on database initialization and periodically
368
-
369
- **Configuration Keys**:
370
- - `review_idle_minutes`: Time before considering task for review (default: 3)
371
- - `review_require_all_files_modified`: Quality gate setting (default: true)
372
-
373
- **Change Configuration**:
374
- ```bash
375
- # Via MCP tool
376
- mcp-tool config update --key review_idle_minutes --value 5
377
-
378
- # Via SQL
379
- UPDATE v4_config SET value = '5' WHERE key = 'review_idle_minutes';
380
- ```
381
-
382
- ### Quality Gates
383
-
384
- Auto-pruning works in conjunction with quality gates:
385
- 1. **File Existence Check**: Prunes non-existent files
386
- 2. **File Modification Check**: Validates remaining files were modified
387
- 3. **Compilation Check**: Ensures TypeScript compiles (if applicable)
388
- 4. **Test Check**: Validates tests pass (if applicable)
389
-
390
- ---
391
-
392
- ## Examples
393
-
394
- ### Example 1: Simple Pruning
395
-
396
- ```typescript
397
- // Task watches 2 files
398
- watchedFiles = ["src/feature.ts", "src/helper.ts"]
399
-
400
- // During implementation, helper absorbed into feature.ts
401
- // helper.ts never created
402
-
403
- // Auto-prune runs:
404
- // ✓ Checks: feature.ts exists
405
- // ✗ Checks: helper.ts doesn't exist
406
- // → Prunes helper.ts
407
- // → Records: { file_path: "src/helper.ts", pruned_ts: 1729584000 }
408
- // → Task continues to waiting_review
409
- ```
410
-
411
- ### Example 2: Safety Check Triggered
412
-
413
- ```typescript
414
- // Task watches 3 files, NONE exist
415
- watchedFiles = ["a.ts", "b.ts", "c.ts"]
416
-
417
- // Auto-prune runs:
418
- // ✗ ALL files non-existent
419
- // → Safety check blocks transition
420
- // → Error: "Cannot prune files for task #X: ALL 3 watched files are non-existent"
421
- // → Task stays in_progress
422
- ```
423
-
424
- ### Example 3: Full Workflow with Decision Linking
425
-
426
- ```typescript
427
- // 1. Create task with watch files
428
- const task = await task.create({
429
- title: "Implement feature X",
430
- watch_files: ["src/feature-x.ts", "src/feature-x-helper.ts"]
431
- });
432
-
433
- // 2. During work, agent creates only feature-x.ts
434
- // (feature-x-helper absorbed into main file)
435
-
436
- // 3. Agent documents decision
437
- await decision.set({
438
- key: "feature-x-no-helper",
439
- value: "Helper functions absorbed into main module for simplicity",
440
- layer: "business"
441
- });
442
-
443
- // 4. Task becomes idle > 3 minutes
444
- // Auto-prune runs automatically:
445
- // - Detects feature-x-helper.ts doesn't exist
446
- // - Prunes it
447
- // - Records to t_task_pruned_files
448
-
449
- // 5. Agent links decision to pruned file
450
- const pruned = await task.get_pruned_files({ task_id: task.id });
451
- await task.link_pruned_file({
452
- pruned_file_id: pruned.pruned_files[0].id,
453
- decision_key: "feature-x-no-helper"
454
- });
455
-
456
- // 6. Future developers can query:
457
- // "Why was feature-x-helper.ts never created?"
458
- // Answer: Linked to decision "feature-x-no-helper"
459
- ```
460
-
461
- ---
462
-
463
- ## Technical Details
464
-
465
- ### Database Schema
466
-
467
- ```sql
468
- -- Audit table
469
- CREATE TABLE v4_task_pruned_files (
470
- id INTEGER PRIMARY KEY AUTOINCREMENT,
471
- task_id INTEGER NOT NULL REFERENCES v4_tasks(id) ON DELETE CASCADE,
472
- file_path TEXT NOT NULL,
473
- pruned_ts INTEGER DEFAULT (unixepoch()),
474
- linked_decision_id INTEGER REFERENCES v4_decisions(id) ON DELETE SET NULL
475
- );
476
-
477
- -- Indexes
478
- CREATE INDEX idx_pruned_task ON v4_task_pruned_files(task_id);
479
- CREATE INDEX idx_pruned_decision ON v4_task_pruned_files(linked_decision_id);
480
- ```
481
-
482
- ### Implementation Files
483
-
484
- - **Migration**: `src/database/migrations/v4/20251126000000_v4_bootstrap.ts`
485
- - **Core Logic**: `src/utils/file-pruning.ts`
486
- - **Integration**: `src/utils/task-stale-detection.ts`
487
- - **MCP Actions**: `src/tools/tasks.ts` (getPrunedFiles, linkPrunedFile)
488
-
489
- ### Token Efficiency
490
-
491
- Auto-pruning maintains token efficiency:
492
- - File paths stored as raw strings (not normalized to m_files)
493
- - Audit queries return only necessary fields
494
- - Pagination supported via `limit` parameter
495
-
496
- ---
497
-
498
- ## Troubleshooting
499
-
500
- ### Issue: Task stuck in in_progress
501
-
502
- **Symptom**: Task won't transition to waiting_review
503
-
504
- **Diagnosis**:
505
- ```bash
506
- # Check if ALL watched files are non-existent
507
- task.get({ task_id: X, include_dependencies: true })
508
- # Look at linked_files array
509
- ```
510
-
511
- **Solution**:
512
- 1. Create at least one watched file (even if placeholder)
513
- 2. Or manually update watch list to remove non-existent files
514
- 3. Or close task as invalid
515
-
516
- ### Issue: Can't find pruned files
517
-
518
- **Symptom**: `get_pruned_files` returns empty
519
-
520
- **Diagnosis**:
521
- - Auto-prune may not have run yet (task must be idle > 3 minutes)
522
- - Task may have no non-existent files
523
-
524
- **Solution**:
525
- ```bash
526
- # Force check by waiting for idle timeout
527
- # Or manually query database:
528
- SELECT * FROM v4_task_pruned_files WHERE task_id = X;
529
- ```
530
-
531
- ### Issue: Decision link not working
532
-
533
- **Symptom**: `link_pruned_file` fails
534
-
535
- **Diagnosis**:
536
- ```bash
537
- # Check if decision exists
538
- decision.get({ key: "your-decision-key" })
539
-
540
- # Check if pruned_file_id is correct
541
- task.get_pruned_files({ task_id: X })
542
- ```
543
-
544
- ---
545
-
546
- ## Migration Notes
547
-
548
- ### Upgrading from v3.9.x
549
-
550
- Auto-pruning is **automatic** in v4.0.0. No configuration required.
551
-
552
- **Database Migration**:
553
- - Runs automatically on startup
554
- - Creates `v4_task_pruned_files` table
555
- - Idempotent (safe to run multiple times)
556
-
557
- **Behavioral Changes**:
558
- - Tasks with non-existent files now auto-prune during review transition
559
- - No impact on existing tasks (pruning only affects future transitions)
560
-
561
- **Rollback**:
562
- If needed, downgrade to v3.9.x:
563
- ```bash
564
- # Audit table will remain but won't be used
565
- # No data loss
566
- git checkout v3.9.0
567
- npm install
568
- ```
569
-
570
- ---
571
-
572
- ## Related Documentation
573
-
574
- - **TASK_OVERVIEW.md**: Task lifecycle and status transitions
575
- - **TASK_ACTIONS.md**: All task action references (including linking)
576
- - **DECISION_CONTEXT.md**: Rich decision documentation
577
- - **ARCHITECTURE.md**: Database schema details
578
-
579
- ---
580
-
581
- ## Changelog
582
-
583
- ### v4.0.0 (2025-11-27)
584
- - Updated to v4.0.0 schema with `v4_` table prefix
585
- - Migrated from legacy table names to unified v4 naming convention
586
- - Updated migration paths to `src/database/migrations/v4/` structure
587
- - All SQL examples updated for v4 schema
588
-
589
- ### v3.5.0 (2025-10-22)
590
- - Initial release of Auto-Pruning feature
591
- - Added `t_task_pruned_files` audit table
592
- - Implemented `pruneNonExistentFiles()` with safety checks
593
- - Added MCP actions: `get_pruned_files`, `link_pruned_file`
594
- - Integrated into `detectAndTransitionToReview()` workflow