sqlew 3.2.5 → 3.5.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 (144) hide show
  1. package/CHANGELOG.md +815 -13
  2. package/README.md +53 -2
  3. package/assets/schema.sql +6 -1
  4. package/dist/config/loader.d.ts +46 -0
  5. package/dist/config/loader.d.ts.map +1 -0
  6. package/dist/config/loader.js +151 -0
  7. package/dist/config/loader.js.map +1 -0
  8. package/dist/config/types.d.ts +77 -0
  9. package/dist/config/types.d.ts.map +1 -0
  10. package/dist/config/types.js +28 -0
  11. package/dist/config/types.js.map +1 -0
  12. package/dist/constants.d.ts +9 -0
  13. package/dist/constants.d.ts.map +1 -1
  14. package/dist/constants.js +10 -0
  15. package/dist/constants.js.map +1 -1
  16. package/dist/database.d.ts +1 -1
  17. package/dist/database.d.ts.map +1 -1
  18. package/dist/database.js +77 -10
  19. package/dist/database.js.map +1 -1
  20. package/dist/index.js +21 -3
  21. package/dist/index.js.map +1 -1
  22. package/dist/migrations/add-v3.5.0-pruned-files.d.ts +26 -0
  23. package/dist/migrations/add-v3.5.0-pruned-files.d.ts.map +1 -0
  24. package/dist/migrations/add-v3.5.0-pruned-files.js +107 -0
  25. package/dist/migrations/add-v3.5.0-pruned-files.js.map +1 -0
  26. package/dist/migrations/index.d.ts +2 -1
  27. package/dist/migrations/index.d.ts.map +1 -1
  28. package/dist/migrations/index.js +16 -1
  29. package/dist/migrations/index.js.map +1 -1
  30. package/dist/tests/git-aware-completion.test.d.ts +6 -0
  31. package/dist/tests/git-aware-completion.test.d.ts.map +1 -0
  32. package/dist/tests/git-aware-completion.test.js +141 -0
  33. package/dist/tests/git-aware-completion.test.js.map +1 -0
  34. package/dist/tests/tasks.auto-pruning-decision-link.test.d.ts +6 -0
  35. package/dist/tests/tasks.auto-pruning-decision-link.test.d.ts.map +1 -0
  36. package/dist/tests/tasks.auto-pruning-decision-link.test.js +250 -0
  37. package/dist/tests/tasks.auto-pruning-decision-link.test.js.map +1 -0
  38. package/dist/tests/tasks.auto-pruning-partial.test.d.ts +6 -0
  39. package/dist/tests/tasks.auto-pruning-partial.test.d.ts.map +1 -0
  40. package/dist/tests/tasks.auto-pruning-partial.test.js +274 -0
  41. package/dist/tests/tasks.auto-pruning-partial.test.js.map +1 -0
  42. package/dist/tests/tasks.auto-pruning-persistence.test.d.ts +6 -0
  43. package/dist/tests/tasks.auto-pruning-persistence.test.d.ts.map +1 -0
  44. package/dist/tests/tasks.auto-pruning-persistence.test.js +232 -0
  45. package/dist/tests/tasks.auto-pruning-persistence.test.js.map +1 -0
  46. package/dist/tests/tasks.auto-pruning-safety.test.d.ts +12 -0
  47. package/dist/tests/tasks.auto-pruning-safety.test.d.ts.map +1 -0
  48. package/dist/tests/tasks.auto-pruning-safety.test.js +196 -0
  49. package/dist/tests/tasks.auto-pruning-safety.test.js.map +1 -0
  50. package/dist/tests/tasks.link-file-backward-compat.test.d.ts +6 -0
  51. package/dist/tests/tasks.link-file-backward-compat.test.d.ts.map +1 -0
  52. package/dist/tests/tasks.link-file-backward-compat.test.js +235 -0
  53. package/dist/tests/tasks.link-file-backward-compat.test.js.map +1 -0
  54. package/dist/tests/tasks.watch-files-action.test.d.ts +6 -0
  55. package/dist/tests/tasks.watch-files-action.test.d.ts.map +1 -0
  56. package/dist/tests/tasks.watch-files-action.test.js +351 -0
  57. package/dist/tests/tasks.watch-files-action.test.js.map +1 -0
  58. package/dist/tests/tasks.watch-files-parameter.test.d.ts +6 -0
  59. package/dist/tests/tasks.watch-files-parameter.test.d.ts.map +1 -0
  60. package/dist/tests/tasks.watch-files-parameter.test.js +249 -0
  61. package/dist/tests/tasks.watch-files-parameter.test.js.map +1 -0
  62. package/dist/tests/two-step-git-completion.test.d.ts +6 -0
  63. package/dist/tests/two-step-git-completion.test.d.ts.map +1 -0
  64. package/dist/tests/two-step-git-completion.test.js +283 -0
  65. package/dist/tests/two-step-git-completion.test.js.map +1 -0
  66. package/dist/tests/vcs-staging.test.d.ts +6 -0
  67. package/dist/tests/vcs-staging.test.d.ts.map +1 -0
  68. package/dist/tests/vcs-staging.test.js +137 -0
  69. package/dist/tests/vcs-staging.test.js.map +1 -0
  70. package/dist/tools/config.d.ts +4 -2
  71. package/dist/tools/config.d.ts.map +1 -1
  72. package/dist/tools/config.js +13 -11
  73. package/dist/tools/config.js.map +1 -1
  74. package/dist/tools/constraints.d.ts +7 -4
  75. package/dist/tools/constraints.d.ts.map +1 -1
  76. package/dist/tools/constraints.js +19 -16
  77. package/dist/tools/constraints.js.map +1 -1
  78. package/dist/tools/context.d.ts +33 -17
  79. package/dist/tools/context.d.ts.map +1 -1
  80. package/dist/tools/context.js +84 -68
  81. package/dist/tools/context.js.map +1 -1
  82. package/dist/tools/files.d.ts +9 -5
  83. package/dist/tools/files.d.ts.map +1 -1
  84. package/dist/tools/files.js +19 -15
  85. package/dist/tools/files.js.map +1 -1
  86. package/dist/tools/messaging.d.ts +9 -5
  87. package/dist/tools/messaging.d.ts.map +1 -1
  88. package/dist/tools/messaging.js +20 -16
  89. package/dist/tools/messaging.js.map +1 -1
  90. package/dist/tools/tasks.d.ts +40 -12
  91. package/dist/tools/tasks.d.ts.map +1 -1
  92. package/dist/tools/tasks.js +475 -87
  93. package/dist/tools/tasks.js.map +1 -1
  94. package/dist/tools/utils.d.ts +11 -6
  95. package/dist/tools/utils.d.ts.map +1 -1
  96. package/dist/tools/utils.js +56 -44
  97. package/dist/tools/utils.js.map +1 -1
  98. package/dist/types.d.ts +4 -0
  99. package/dist/types.d.ts.map +1 -1
  100. package/dist/utils/file-pruning.d.ts +69 -0
  101. package/dist/utils/file-pruning.d.ts.map +1 -0
  102. package/dist/utils/file-pruning.js +185 -0
  103. package/dist/utils/file-pruning.js.map +1 -0
  104. package/dist/utils/quality-checks.d.ts +60 -0
  105. package/dist/utils/quality-checks.d.ts.map +1 -0
  106. package/dist/utils/quality-checks.js +228 -0
  107. package/dist/utils/quality-checks.js.map +1 -0
  108. package/dist/utils/retention.d.ts +8 -0
  109. package/dist/utils/retention.d.ts.map +1 -1
  110. package/dist/utils/retention.js +12 -0
  111. package/dist/utils/retention.js.map +1 -1
  112. package/dist/utils/task-stale-detection.d.ts +69 -1
  113. package/dist/utils/task-stale-detection.d.ts.map +1 -1
  114. package/dist/utils/task-stale-detection.js +494 -17
  115. package/dist/utils/task-stale-detection.js.map +1 -1
  116. package/dist/utils/vcs-adapter.d.ts +68 -0
  117. package/dist/utils/vcs-adapter.d.ts.map +1 -0
  118. package/dist/utils/vcs-adapter.js +187 -0
  119. package/dist/utils/vcs-adapter.js.map +1 -0
  120. package/dist/watcher/file-watcher.d.ts +54 -4
  121. package/dist/watcher/file-watcher.d.ts.map +1 -1
  122. package/dist/watcher/file-watcher.js +312 -30
  123. package/dist/watcher/file-watcher.js.map +1 -1
  124. package/dist/watcher/gitignore-parser.d.ts +70 -0
  125. package/dist/watcher/gitignore-parser.d.ts.map +1 -0
  126. package/dist/watcher/gitignore-parser.js +191 -0
  127. package/dist/watcher/gitignore-parser.js.map +1 -0
  128. package/dist/watcher/index.d.ts +1 -0
  129. package/dist/watcher/index.d.ts.map +1 -1
  130. package/dist/watcher/index.js +1 -0
  131. package/dist/watcher/index.js.map +1 -1
  132. package/docs/AI_AGENT_GUIDE.md +1 -1
  133. package/docs/ARCHITECTURE.md +12 -0
  134. package/docs/AUTO_FILE_TRACKING.md +486 -82
  135. package/docs/CONFIGURATION.md +908 -0
  136. package/docs/GIT_AWARE_AUTO_COMPLETE.md +645 -0
  137. package/docs/MIGRATION_v3.3.md +602 -0
  138. package/docs/SHARED_CONCEPTS.md +2 -1
  139. package/docs/TASK_ACTIONS.md +12 -0
  140. package/docs/TASK_OVERVIEW.md +124 -23
  141. package/docs/TASK_PRUNING.md +589 -0
  142. package/docs/TASK_SYSTEM.md +83 -13
  143. package/docs/TOOL_REFERENCE.md +94 -6
  144. package/package.json +8 -6
@@ -0,0 +1,645 @@
1
+ # Git-Aware Auto-Complete (v3.4.0 - v3.5.2)
2
+
3
+ **Feature Status**: Implemented ✅
4
+ **Current Version**: v3.5.2 (Two-Step Git-Aware Workflow)
5
+ **Previous Version**: v3.4.0 (Commit-Based Auto-Complete)
6
+ **Architecture Decision**: #001 - Replace flawed auto-revert with Git-based task completion
7
+
8
+ ## Version Evolution
9
+
10
+ ### v3.4.0 - Commit-Based Auto-Complete
11
+ - **Workflow**: `waiting_review` → [git commit] → `done`
12
+ - **Problem**: Tasks stay in `done` status indefinitely, board becomes cluttered
13
+
14
+ ### v3.5.2 - Two-Step Git-Aware Workflow ⭐ **NEW**
15
+ - **Step 1 - Staging**: `waiting_review` → [git add] → `done` (work complete)
16
+ - **Step 2 - Archiving**: `done` → [git commit] → `archived` (work finalized, board clean)
17
+ - **Benefit**: Automatic board cleanup while preserving Git workflow semantics
18
+
19
+ ## Problem Statement
20
+
21
+ ### Current Flaw (v3.2.x - v3.3.x)
22
+
23
+ The current stale task detection system has a critical design flaw:
24
+
25
+ ```typescript
26
+ // In src/utils/task-stale-detection.ts lines 105-116
27
+ // FLAWED LOGIC: Reverts completed work after 24h idle
28
+ const waitingReviewTransitioned = db.prepare(`
29
+ UPDATE t_tasks
30
+ SET status_id = ?,
31
+ updated_ts = unixepoch()
32
+ WHERE status_id = ?
33
+ AND updated_ts < unixepoch() - ?
34
+ `).run(
35
+ TASK_STATUS.TODO, // Revert to TODO
36
+ TASK_STATUS.WAITING_REVIEW, // From waiting_review
37
+ waitingReviewThresholdSeconds // After 24h
38
+ );
39
+ ```
40
+
41
+ **Problem**:
42
+ - Task transitions: `todo` → `in_progress` → `waiting_review` (quality gates pass)
43
+ - After 24h idle: `waiting_review` → `todo` (auto-revert)
44
+ - **Result**: Work is DONE but task status discards this fact
45
+
46
+ ### Why This Happens
47
+
48
+ 1. AI agent completes implementation (files modified, tests pass, TypeScript compiles)
49
+ 2. Quality gates detect completion → task moves to `waiting_review`
50
+ 3. Work sits idle for 24+ hours (no additional changes needed)
51
+ 4. Auto-revert logic triggers → task reverts to `todo`
52
+ 5. **Loss of context**: Task appears incomplete when work is already done
53
+
54
+ ## Solution: Two-Step Git-Aware Workflow (v3.5.2)
55
+
56
+ ### Core Concept
57
+
58
+ **Align task status with Git workflow stages.**
59
+
60
+ - **Staging (git add)** = Work complete → `waiting_review` → `done`
61
+ - **Committing (git commit)** = Work finalized → `done` → `archived`
62
+
63
+ ### Rationale (v3.5.2 Enhancement)
64
+
65
+ 1. **Clean Task Board**: Tasks auto-archive after commit, keeping active board focused on current work
66
+ 2. **Fast Feedback**: `git add` provides immediate "work done" signal (faster than waiting for commit)
67
+ 3. **Git Workflow Alignment**: Staging = ready for review, Commit = finalized and permanent
68
+ 4. **Zero-token overhead**: Fully automated, no manual MCP calls needed
69
+ 5. **Multi-agent compatible**: Any agent can stage/commit, all agents see the same VCS state
70
+ 6. **Survives process restarts**: VCS state is persistent (Git/Mercurial/SVN)
71
+
72
+ ## Architecture
73
+
74
+ ### Component Design
75
+
76
+ ```
77
+ ┌─────────────────────────────────────────────────────────────────┐
78
+ │ Git-Aware Task Completion System │
79
+ │ │
80
+ │ ┌───────────────────────────────────────────────────────────┐ │
81
+ │ │ detectAndCompleteReviewedTasks(db: Database) │ │
82
+ │ │ ─────────────────────────────────────────────────────── │ │
83
+ │ │ 1. Find all tasks in waiting_review status │ │
84
+ │ │ 2. Get watched files for each task │ │
85
+ │ │ 3. Check Git log since task creation │ │
86
+ │ │ 4. If ALL files committed → transition to done │ │
87
+ │ │ 5. Return count of auto-completed tasks │ │
88
+ │ └───────────────────────────────────────────────────────────┘ │
89
+ │ │
90
+ │ ┌───────────────────────────────────────────────────────────┐ │
91
+ │ │ Integration Points │ │
92
+ │ │ ─────────────────────────────────────────────────────── │ │
93
+ │ │ • Periodic Checks: Before task.list() and stats.get() │ │
94
+ │ │ • File Watcher: On .git/index change (real-time) │ │
95
+ │ │ • Response Enhancement: Include git_auto_completed │ │
96
+ │ └───────────────────────────────────────────────────────────┘ │
97
+ │ │
98
+ │ ┌───────────────────────────────────────────────────────────┐ │
99
+ │ │ Configuration │ │
100
+ │ │ ─────────────────────────────────────────────────────── │ │
101
+ │ │ • git_auto_complete_enabled (default: '1') │ │
102
+ │ │ • require_all_files_committed (default: '1') │ │
103
+ │ │ • stale_review_notification_hours (default: '48') │ │
104
+ │ └───────────────────────────────────────────────────────────┘ │
105
+ └─────────────────────────────────────────────────────────────────┘
106
+ ```
107
+
108
+ ### Git Log Query Strategy
109
+
110
+ ```bash
111
+ # For a task created at timestamp 1698765432
112
+ # Check if file "src/auth.ts" was committed since task creation
113
+
114
+ git log --since="@1698765432" --name-only -- src/auth.ts
115
+
116
+ # Output if committed:
117
+ # commit abc123def456...
118
+ # Author: AI Agent <agent@example.com>
119
+ # Date: ...
120
+ #
121
+ # src/auth.ts
122
+
123
+ # Output if NOT committed:
124
+ # (empty)
125
+ ```
126
+
127
+ **Logic**:
128
+ - Query `git log --since="@<task.created_ts>" --name-only -- <file_path>`
129
+ - If output is non-empty → file was committed since task creation
130
+ - If ALL watched files have non-empty output → transition task to `done`
131
+
132
+ ## Implementation Tasks
133
+
134
+ ### Task 1: Remove Flawed Auto-Revert Logic
135
+ **Priority**: Critical (Blocker)
136
+ **Layer**: Business Logic
137
+ **AI Time**: 5 minutes
138
+ **Token Budget**: 2k-3k tokens
139
+
140
+ **File**: `/home/kitayama/TypeScriptProject/mcp-sqlew/src/utils/task-stale-detection.ts`
141
+ **Lines to Remove**: 105-116
142
+
143
+ ```typescript
144
+ // DELETE THIS SECTION:
145
+ const waitingReviewTransitioned = db.prepare(`
146
+ UPDATE t_tasks
147
+ SET status_id = ?,
148
+ updated_ts = unixepoch()
149
+ WHERE status_id = ?
150
+ AND updated_ts < unixepoch() - ?
151
+ `).run(
152
+ TASK_STATUS.TODO,
153
+ TASK_STATUS.WAITING_REVIEW,
154
+ waitingReviewThresholdSeconds
155
+ );
156
+
157
+ totalTransitioned += waitingReviewTransitioned.changes;
158
+ ```
159
+
160
+ **Acceptance Criteria**:
161
+ - [ ] Lines 105-116 removed from `task-stale-detection.ts`
162
+ - [ ] No compilation errors after removal
163
+ - [ ] Existing tests still pass (`npm test task-stale`)
164
+
165
+ ---
166
+
167
+ ### Task 2: Implement Git-Aware Auto-Complete
168
+ **Priority**: Critical (Blocker)
169
+ **Layer**: Business Logic
170
+ **AI Time**: 25-30 minutes
171
+ **Token Budget**: 18k-25k tokens
172
+
173
+ **New Function**: `detectAndCompleteReviewedTasks(db: Database): Promise<number>`
174
+ **Location**: `/home/kitayama/TypeScriptProject/mcp-sqlew/src/utils/task-stale-detection.ts`
175
+
176
+ **Function Signature**:
177
+ ```typescript
178
+ /**
179
+ * Detect and auto-complete tasks in waiting_review that have all files committed
180
+ *
181
+ * Git-aware completion logic:
182
+ * - Find all tasks in waiting_review status
183
+ * - Get watched files for each task
184
+ * - Check git log since task creation for each file
185
+ * - If ALL files committed → transition to done
186
+ *
187
+ * @param db - Database instance
188
+ * @returns Count of auto-completed tasks
189
+ */
190
+ export async function detectAndCompleteReviewedTasks(db: Database): Promise<number> {
191
+ // Implementation here
192
+ }
193
+ ```
194
+
195
+ **Algorithm**:
196
+ ```
197
+ 1. Check if git_auto_complete_enabled config is true
198
+ 2. Get all tasks in waiting_review status
199
+ 3. For each task:
200
+ a. Get list of watched files from t_task_file_links
201
+ b. Get task.created_ts
202
+ c. For each watched file:
203
+ - Run: git log --since="@<created_ts>" --name-only -- <file_path>
204
+ - If output is empty → file NOT committed
205
+ d. If require_all_files_committed:
206
+ - ALL files must be committed → transition to done
207
+ e. Else:
208
+ - ANY file committed → transition to done
209
+ 4. Return count of transitioned tasks
210
+ ```
211
+
212
+ **Error Handling**:
213
+ - Skip tasks if `git log` fails (not in a Git repo)
214
+ - Skip tasks with no watched files
215
+ - Log detailed diagnostics to stderr for debugging
216
+
217
+ **Acceptance Criteria**:
218
+ - [ ] Function implemented in `task-stale-detection.ts`
219
+ - [ ] Handles all edge cases (no Git repo, no watched files, partial commits)
220
+ - [ ] Respects `git_auto_complete_enabled` and `require_all_files_committed` config
221
+ - [ ] Returns accurate count of transitioned tasks
222
+ - [ ] Comprehensive error logging to stderr
223
+
224
+ ---
225
+
226
+ ### Task 3: Integration - Periodic Checks
227
+ **Priority**: High
228
+ **Layer**: Business Logic
229
+ **Dependencies**: Task 2
230
+ **AI Time**: 10-15 minutes
231
+ **Token Budget**: 8k-12k tokens
232
+
233
+ **Files**: `/home/kitayama/TypeScriptProject/mcp-sqlew/src/tools/tasks.ts`
234
+ **Actions to Modify**: `list` (line ~750), `stats` in utils.ts
235
+
236
+ **Changes**:
237
+ 1. Call `detectAndCompleteReviewedTasks(db)` before returning results
238
+ 2. Include `git_auto_completed` count in response
239
+
240
+ **Example Integration**:
241
+ ```typescript
242
+ // In listTasks() function
243
+ async function listTasks(db: Database, params: ListTasksParams): Promise<object> {
244
+ // Run stale detection (existing)
245
+ const staleTransitioned = detectAndTransitionStaleTasks(db);
246
+
247
+ // NEW: Run Git-aware auto-complete
248
+ const gitAutoCompleted = await detectAndCompleteReviewedTasks(db);
249
+
250
+ // Get task list
251
+ const tasks = db.prepare('SELECT ...).all();
252
+
253
+ return {
254
+ tasks,
255
+ stale_tasks_transitioned: staleTransitioned,
256
+ git_auto_completed: gitAutoCompleted, // NEW
257
+ };
258
+ }
259
+ ```
260
+
261
+ **Acceptance Criteria**:
262
+ - [ ] `task.list` calls `detectAndCompleteReviewedTasks()` before listing
263
+ - [ ] `stats` tool calls `detectAndCompleteReviewedTasks()` before stats
264
+ - [ ] Response includes `git_auto_completed` count
265
+ - [ ] Async handling properly implemented (await)
266
+ - [ ] No performance degradation for large task lists
267
+
268
+ ---
269
+
270
+ ### Task 4: Integration - File Watcher
271
+ **Priority**: High
272
+ **Layer**: Infrastructure
273
+ **Dependencies**: Task 2
274
+ **AI Time**: 15-20 minutes
275
+ **Token Budget**: 10k-15k tokens
276
+
277
+ **Files**:
278
+ - `/home/kitayama/TypeScriptProject/mcp-sqlew/src/watcher/file-watcher.ts`
279
+ - `/home/kitayama/TypeScriptProject/mcp-sqlew/src/watcher/index.ts`
280
+
281
+ **Changes**:
282
+ 1. Watch `.git/index` file for changes (indicates git commit)
283
+ 2. On `.git/index` change → call `detectAndCompleteReviewedTasks(db)`
284
+ 3. Log real-time auto-completions
285
+
286
+ **Implementation**:
287
+ ```typescript
288
+ // In FileWatcher constructor
289
+ this.watcher = chokidar.watch([...filePaths, '.git/index'], {
290
+ ignored: gitignoreParser.shouldIgnore,
291
+ persistent: true,
292
+ ignoreInitial: true,
293
+ awaitWriteFinish: {
294
+ stabilityThreshold: 2000,
295
+ pollInterval: 100,
296
+ },
297
+ });
298
+
299
+ // In change handler
300
+ this.watcher.on('change', async (path) => {
301
+ if (path === '.git/index') {
302
+ // Git commit detected
303
+ const completed = await detectAndCompleteReviewedTasks(this.db);
304
+ if (completed > 0) {
305
+ console.error(` ✓ Git-aware auto-complete: ${completed} tasks completed`);
306
+ }
307
+ } else {
308
+ // Existing file change logic
309
+ ...
310
+ }
311
+ });
312
+ ```
313
+
314
+ **Acceptance Criteria**:
315
+ - [ ] `.git/index` added to watch list
316
+ - [ ] Git commits trigger `detectAndCompleteReviewedTasks()`
317
+ - [ ] Real-time console output for auto-completions
318
+ - [ ] No performance impact from watching `.git/index`
319
+ - [ ] Graceful handling if `.git/index` doesn't exist (not a Git repo)
320
+
321
+ ---
322
+
323
+ ### Task 5: Enhanced Inline Status
324
+ **Priority**: Medium
325
+ **Layer**: Presentation
326
+ **Dependencies**: Task 3
327
+ **AI Time**: 10 minutes
328
+ **Token Budget**: 5k-8k tokens
329
+
330
+ **File**: `/home/kitayama/TypeScriptProject/mcp-sqlew/src/tools/utils.ts` (stats action)
331
+
332
+ **Changes**:
333
+ Add `review_status` section to stats output showing tasks awaiting Git commits:
334
+
335
+ ```typescript
336
+ // In getStats() function
337
+ const reviewStatus = db.prepare(`
338
+ SELECT
339
+ COUNT(DISTINCT t.id) as awaiting_commit,
340
+ COUNT(DISTINCT tfl.file_id) as total_files,
341
+ COUNT(DISTINCT CASE WHEN <committed_check> THEN tfl.file_id END) as committed_files
342
+ FROM t_tasks t
343
+ JOIN t_task_file_links tfl ON t.id = tfl.task_id
344
+ WHERE t.status_id = ?
345
+ `).get(TASK_STATUS.WAITING_REVIEW);
346
+
347
+ return {
348
+ ...existing_stats,
349
+ review_status: {
350
+ tasks_awaiting_commit: reviewStatus.awaiting_commit,
351
+ files_to_commit: reviewStatus.total_files - reviewStatus.committed_files,
352
+ commit_progress: `${reviewStatus.committed_files}/${reviewStatus.total_files}`,
353
+ }
354
+ };
355
+ ```
356
+
357
+ **Acceptance Criteria**:
358
+ - [ ] Stats output includes `review_status` section
359
+ - [ ] Shows count of tasks awaiting commits
360
+ - [ ] Shows commit progress (files committed / total files)
361
+ - [ ] Query is performant (<100ms for 1000 tasks)
362
+
363
+ ---
364
+
365
+ ### Task 6: Configuration
366
+ **Priority**: Medium
367
+ **Layer**: Infrastructure
368
+ **AI Time**: 5 minutes
369
+ **Token Budget**: 3k-5k tokens
370
+
371
+ **Files**:
372
+ - `/home/kitayama/TypeScriptProject/mcp-sqlew/src/database.ts` (config defaults)
373
+ - `/home/kitayama/TypeScriptProject/mcp-sqlew/docs/CONFIGURATION.md`
374
+
375
+ **New Config Keys**:
376
+ ```typescript
377
+ // In initializeDatabase() function
378
+ const configDefaults = [
379
+ // Existing configs...
380
+
381
+ // NEW: Git-aware auto-complete
382
+ { key: 'git_auto_complete_enabled', value: '1' },
383
+ { key: 'require_all_files_committed', value: '1' },
384
+ { key: 'stale_review_notification_hours', value: '48' },
385
+ ];
386
+ ```
387
+
388
+ **Documentation** (CONFIGURATION.md):
389
+ ```markdown
390
+ ### Git-Aware Auto-Complete (v3.4.0)
391
+
392
+ | Key | Type | Default | Description |
393
+ |-----|------|---------|-------------|
394
+ | `git_auto_complete_enabled` | boolean | `1` (true) | Enable automatic completion based on Git commits |
395
+ | `require_all_files_committed` | boolean | `1` (true) | Require ALL watched files to be committed (vs ANY) |
396
+ | `stale_review_notification_hours` | number | `48` | Hours before notifying about stale review tasks |
397
+
398
+ **Examples**:
399
+ ```typescript
400
+ // Disable Git auto-complete
401
+ config action=update key="git_auto_complete_enabled" value="0"
402
+
403
+ // Complete task when ANY file is committed (not just all)
404
+ config action=update key="require_all_files_committed" value="0"
405
+
406
+ // Notify about stale reviews after 72 hours
407
+ config action=update key="stale_review_notification_hours" value="72"
408
+ ```
409
+ ```
410
+
411
+ **Acceptance Criteria**:
412
+ - [ ] Config defaults added to `database.ts`
413
+ - [ ] Documentation added to `CONFIGURATION.md`
414
+ - [ ] Config values respected by `detectAndCompleteReviewedTasks()`
415
+
416
+ ---
417
+
418
+ ### Task 7: Documentation & Testing
419
+ **Priority**: High
420
+ **Layer**: Cross-Cutting
421
+ **Dependencies**: All previous tasks
422
+ **AI Time**: 35-40 minutes
423
+ **Token Budget**: 23k-32k tokens
424
+
425
+ **Documentation Files**:
426
+ 1. `/home/kitayama/TypeScriptProject/mcp-sqlew/docs/TASK_OVERVIEW.md` - Update lifecycle diagram
427
+ 2. `/home/kitayama/TypeScriptProject/mcp-sqlew/docs/AUTO_FILE_TRACKING.md` - Add Git-aware section
428
+ 3. `/home/kitayama/TypeScriptProject/mcp-sqlew/docs/TASK_ACTIONS.md` - Update status transitions
429
+ 4. `/home/kitayama/TypeScriptProject/mcp-sqlew/CHANGELOG.md` - Add v3.4.0 entry
430
+
431
+ **Test Files** (all in `/home/kitayama/TypeScriptProject/mcp-sqlew/src/tests/`):
432
+ 1. `tasks.git-auto-complete.test.ts` - Comprehensive test suite
433
+ 2. `tasks.git-integration.test.ts` - Git log integration tests
434
+
435
+ **Test Cases**:
436
+ ```typescript
437
+ describe('Git-Aware Auto-Complete', () => {
438
+ describe('detectAndCompleteReviewedTasks', () => {
439
+ it('should complete task when all files committed', async () => {
440
+ // Test: Create task, commit all watched files, verify status=done
441
+ });
442
+
443
+ it('should NOT complete task when some files uncommitted', async () => {
444
+ // Test: Create task, commit only some files, verify status=waiting_review
445
+ });
446
+
447
+ it('should handle tasks with no watched files', async () => {
448
+ // Test: Create task with no files, verify no crash
449
+ });
450
+
451
+ it('should skip if not in Git repo', async () => {
452
+ // Test: Mock git log failure, verify graceful skip
453
+ });
454
+
455
+ it('should respect git_auto_complete_enabled config', async () => {
456
+ // Test: Disable config, verify no auto-completion
457
+ });
458
+
459
+ it('should respect require_all_files_committed config', async () => {
460
+ // Test: Set to false, verify completion with ANY file committed
461
+ });
462
+
463
+ it('should handle multiple tasks simultaneously', async () => {
464
+ // Test: 10 tasks, some committed, some not, verify correct counts
465
+ });
466
+ });
467
+
468
+ describe('File Watcher Integration', () => {
469
+ it('should trigger on .git/index change', async () => {
470
+ // Test: Simulate git commit, verify auto-completion
471
+ });
472
+
473
+ it('should not trigger on regular file changes', async () => {
474
+ // Test: Modify watched file, verify no premature completion
475
+ });
476
+ });
477
+
478
+ describe('Periodic Checks Integration', () => {
479
+ it('should auto-complete before task.list', async () => {
480
+ // Test: Call task.list, verify auto-completion runs first
481
+ });
482
+
483
+ it('should include git_auto_completed in response', async () => {
484
+ // Test: Verify response structure includes count
485
+ });
486
+ });
487
+ });
488
+ ```
489
+
490
+ **Acceptance Criteria**:
491
+ - [ ] All documentation updated with Git-aware feature
492
+ - [ ] CHANGELOG.md includes comprehensive v3.4.0 entry
493
+ - [ ] Test suite covers all scenarios (>90% code coverage)
494
+ - [ ] All tests pass (`npm test`)
495
+ - [ ] TypeScript compiles without errors
496
+
497
+ ---
498
+
499
+ ## Migration Guide (v3.3.x → v3.4.0)
500
+
501
+ ### Breaking Changes
502
+
503
+ **None** - v3.4.0 is fully backward-compatible.
504
+
505
+ ### New Behavior
506
+
507
+ **Before (v3.3.x)**:
508
+ ```
509
+ waiting_review (24h idle) → todo (auto-revert, work discarded)
510
+ ```
511
+
512
+ **After (v3.4.0)**:
513
+ ```
514
+ waiting_review (all files committed) → done (auto-complete, work preserved)
515
+ ```
516
+
517
+ ### Configuration
518
+
519
+ If you want to preserve the old behavior (not recommended):
520
+ ```typescript
521
+ config action=update key="git_auto_complete_enabled" value="0"
522
+ ```
523
+
524
+ ### Recommended Workflow
525
+
526
+ 1. Create task with watched files:
527
+ ```typescript
528
+ task action=create
529
+ title: "Implement feature"
530
+ watch_files: ["src/feature.ts", "src/feature.test.ts"]
531
+ ```
532
+
533
+ 2. Implement feature (files auto-tracked)
534
+ - Task moves: `todo` → `in_progress`
535
+
536
+ 3. Quality gates pass (if configured)
537
+ - Task moves: `in_progress` → `waiting_review`
538
+
539
+ 4. Commit changes to Git:
540
+ ```bash
541
+ git add src/feature.ts src/feature.test.ts
542
+ git commit -m "Implement feature"
543
+ ```
544
+
545
+ 5. **NEW**: Task auto-completes
546
+ - Task moves: `waiting_review` → `done`
547
+ - Console output: `✓ Git-aware auto-complete: 1 task completed`
548
+
549
+ ## Benefits
550
+
551
+ ### 1. Preserves Completed Work
552
+ - No more auto-revert to `todo` after 24h
553
+ - Git commits represent finalized work → task correctly marked `done`
554
+
555
+ ### 2. Zero-Token Overhead
556
+ - No manual MCP calls needed to mark tasks complete
557
+ - Git integration happens automatically in background
558
+
559
+ ### 3. Multi-Agent Compatible
560
+ - Any agent can commit changes
561
+ - All agents see the same Git state (persistent)
562
+
563
+ ### 4. Survives Restarts
564
+ - Git history persists across process restarts
565
+ - Task completion state always accurate based on Git
566
+
567
+ ### 5. Natural Workflow Alignment
568
+ - Developers already commit when work is done
569
+ - System aligns with existing Git-based practices
570
+
571
+ ## Risks & Mitigations
572
+
573
+ ### Risk 1: False Positives (Premature Completion)
574
+ **Scenario**: Files committed but work not actually complete
575
+
576
+ **Mitigation**:
577
+ - Quality gates must pass BEFORE entering `waiting_review`
578
+ - Git auto-complete only applies to tasks already in `waiting_review`
579
+ - If work incomplete, task would still be in `in_progress`
580
+
581
+ ### Risk 2: Not in Git Repo
582
+ **Scenario**: Project not using Git
583
+
584
+ **Mitigation**:
585
+ - `git log` failures are caught and logged
586
+ - Tasks gracefully skip auto-completion if Git unavailable
587
+ - Config option to disable: `git_auto_complete_enabled=0`
588
+
589
+ ### Risk 3: Partial Commits
590
+ **Scenario**: Only some watched files committed
591
+
592
+ **Mitigation**:
593
+ - Default: `require_all_files_committed=1` (strict mode)
594
+ - Alternative: Set to `0` to complete on ANY file committed
595
+ - Console diagnostics show which files committed vs not
596
+
597
+ ### Risk 4: Performance Impact
598
+ **Scenario**: Running `git log` for many tasks is slow
599
+
600
+ **Mitigation**:
601
+ - Periodic checks only run before `list` and `stats` (not continuous)
602
+ - File watcher triggers only on `.git/index` change (infrequent)
603
+ - Git log queries use `--name-only` (minimal output)
604
+ - Benchmark target: <500ms for 100 tasks
605
+
606
+ ## Success Metrics
607
+
608
+ ### Functional Metrics
609
+ - [ ] Zero auto-reverts of completed work (0 `waiting_review` → `todo` transitions)
610
+ - [ ] >95% accuracy: Tasks marked `done` when all files committed
611
+ - [ ] <5% false negatives: Tasks stuck in `waiting_review` when files committed
612
+
613
+ ### Performance Metrics
614
+ - [ ] Periodic checks: <500ms for 100 tasks
615
+ - [ ] File watcher: <100ms response time on `.git/index` change
616
+ - [ ] No performance degradation vs v3.3.x baseline
617
+
618
+ ### Token Efficiency Metrics
619
+ - [ ] Zero MCP calls needed for task completion (100% automated)
620
+ - [ ] Maintain existing 70% token reduction vs decision-based tracking
621
+
622
+ ## Timeline
623
+
624
+ ### Phase 1: Core Implementation (Tasks 1-2)
625
+ **Duration**: 30-35 minutes AI time
626
+ **Deliverable**: `detectAndCompleteReviewedTasks()` function working
627
+
628
+ ### Phase 2: Integration (Tasks 3-4)
629
+ **Duration**: 25-35 minutes AI time
630
+ **Deliverable**: Periodic checks + file watcher integration
631
+
632
+ ### Phase 3: Polish & Documentation (Tasks 5-7)
633
+ **Duration**: 50-55 minutes AI time
634
+ **Deliverable**: Full documentation, tests, and enhanced UI
635
+
636
+ ### Total Timeline
637
+ **AI Time**: 105-140 minutes (~1.75-2.5 hours)
638
+ **Token Budget**: 69k-100k tokens
639
+
640
+ ## Related Documents
641
+
642
+ - [AUTO_FILE_TRACKING.md](./AUTO_FILE_TRACKING.md) - File watcher system overview
643
+ - [TASK_OVERVIEW.md](./TASK_OVERVIEW.md) - Task lifecycle and status transitions
644
+ - [CONFIGURATION.md](./CONFIGURATION.md) - Configuration options
645
+ - [WORKFLOWS.md](./WORKFLOWS.md) - Multi-agent coordination patterns