sqlew 4.1.2 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +268 -409
  3. package/assets/claude-md-snippets/plan-mode-integration.md +36 -10
  4. package/assets/config.example.toml +120 -282
  5. package/assets/sample-skills/sqlew-decision-format/SKILL.md +73 -0
  6. package/dist/cli/hooks/check-completion.d.ts.map +1 -1
  7. package/dist/cli/hooks/check-completion.js +90 -2
  8. package/dist/cli/hooks/check-completion.js.map +1 -1
  9. package/dist/cli/hooks/init-hooks.d.ts.map +1 -1
  10. package/dist/cli/hooks/init-hooks.js +97 -5
  11. package/dist/cli/hooks/init-hooks.js.map +1 -1
  12. package/dist/cli/hooks/on-enter-plan.d.ts +22 -0
  13. package/dist/cli/hooks/on-enter-plan.d.ts.map +1 -0
  14. package/dist/cli/hooks/on-enter-plan.js +51 -0
  15. package/dist/cli/hooks/on-enter-plan.js.map +1 -0
  16. package/dist/cli/hooks/on-exit-plan.d.ts +20 -0
  17. package/dist/cli/hooks/on-exit-plan.d.ts.map +1 -0
  18. package/dist/cli/hooks/on-exit-plan.js +66 -0
  19. package/dist/cli/hooks/on-exit-plan.js.map +1 -0
  20. package/dist/cli/hooks/on-stop.d.ts +19 -0
  21. package/dist/cli/hooks/on-stop.d.ts.map +1 -0
  22. package/dist/cli/hooks/on-stop.js +152 -0
  23. package/dist/cli/hooks/on-stop.js.map +1 -0
  24. package/dist/cli/hooks/on-subagent-stop.d.ts +20 -0
  25. package/dist/cli/hooks/on-subagent-stop.d.ts.map +1 -0
  26. package/dist/cli/hooks/on-subagent-stop.js +94 -0
  27. package/dist/cli/hooks/on-subagent-stop.js.map +1 -0
  28. package/dist/cli/hooks/plan-pattern-extractor.d.ts +87 -0
  29. package/dist/cli/hooks/plan-pattern-extractor.d.ts.map +1 -0
  30. package/dist/cli/hooks/plan-pattern-extractor.js +218 -0
  31. package/dist/cli/hooks/plan-pattern-extractor.js.map +1 -0
  32. package/dist/cli/hooks/plan-processor.d.ts +43 -0
  33. package/dist/cli/hooks/plan-processor.d.ts.map +1 -0
  34. package/dist/cli/hooks/plan-processor.js +115 -0
  35. package/dist/cli/hooks/plan-processor.js.map +1 -0
  36. package/dist/cli/hooks/plan-toml-parser.d.ts +42 -0
  37. package/dist/cli/hooks/plan-toml-parser.d.ts.map +1 -0
  38. package/dist/cli/hooks/plan-toml-parser.js +178 -0
  39. package/dist/cli/hooks/plan-toml-parser.js.map +1 -0
  40. package/dist/cli/hooks/save.d.ts +7 -9
  41. package/dist/cli/hooks/save.d.ts.map +1 -1
  42. package/dist/cli/hooks/save.js +50 -25
  43. package/dist/cli/hooks/save.js.map +1 -1
  44. package/dist/cli/hooks/stdin-parser.d.ts +66 -2
  45. package/dist/cli/hooks/stdin-parser.d.ts.map +1 -1
  46. package/dist/cli/hooks/stdin-parser.js +57 -2
  47. package/dist/cli/hooks/stdin-parser.js.map +1 -1
  48. package/dist/cli/hooks/suggest.d.ts +8 -4
  49. package/dist/cli/hooks/suggest.d.ts.map +1 -1
  50. package/dist/cli/hooks/suggest.js +21 -123
  51. package/dist/cli/hooks/suggest.js.map +1 -1
  52. package/dist/cli/hooks/track-plan.d.ts +8 -1
  53. package/dist/cli/hooks/track-plan.d.ts.map +1 -1
  54. package/dist/cli/hooks/track-plan.js +64 -66
  55. package/dist/cli/hooks/track-plan.js.map +1 -1
  56. package/dist/cli.d.ts.map +1 -1
  57. package/dist/cli.js +107 -6
  58. package/dist/cli.js.map +1 -1
  59. package/dist/config/global-config.d.ts +90 -0
  60. package/dist/config/global-config.d.ts.map +1 -1
  61. package/dist/config/global-config.js +86 -1
  62. package/dist/config/global-config.js.map +1 -1
  63. package/dist/database/initialization/init.js +3 -3
  64. package/dist/database/initialization/init.js.map +1 -1
  65. package/dist/database/migrations/v4/20260102204000_v4_fix_decision_set_example.d.ts +15 -0
  66. package/dist/database/migrations/v4/20260102204000_v4_fix_decision_set_example.d.ts.map +1 -0
  67. package/dist/database/migrations/v4/20260102204000_v4_fix_decision_set_example.js +74 -0
  68. package/dist/database/migrations/v4/20260102204000_v4_fix_decision_set_example.js.map +1 -0
  69. package/dist/index.js +8 -4
  70. package/dist/index.js.map +1 -1
  71. package/dist/init-skills.d.ts +12 -3
  72. package/dist/init-skills.d.ts.map +1 -1
  73. package/dist/init-skills.js +96 -24
  74. package/dist/init-skills.js.map +1 -1
  75. package/dist/knexfile.d.ts.map +1 -1
  76. package/dist/knexfile.js +16 -12
  77. package/dist/knexfile.js.map +1 -1
  78. package/dist/server/setup.js +5 -5
  79. package/dist/server/setup.js.map +1 -1
  80. package/dist/server/tool-handlers.d.ts.map +1 -1
  81. package/dist/server/tool-handlers.js +7 -1
  82. package/dist/server/tool-handlers.js.map +1 -1
  83. package/dist/server/tool-registry.js +1 -1
  84. package/dist/server/tool-registry.js.map +1 -1
  85. package/dist/tests/feature/decision/truncate.test.d.ts +8 -0
  86. package/dist/tests/feature/decision/truncate.test.d.ts.map +1 -0
  87. package/dist/tests/feature/decision/truncate.test.js +192 -0
  88. package/dist/tests/feature/decision/truncate.test.js.map +1 -0
  89. package/dist/tests/unit/config/plan-toml-cache.test.d.ts +9 -0
  90. package/dist/tests/unit/config/plan-toml-cache.test.d.ts.map +1 -0
  91. package/dist/tests/unit/config/plan-toml-cache.test.js +230 -0
  92. package/dist/tests/unit/config/plan-toml-cache.test.js.map +1 -0
  93. package/dist/tests/unit/hooks/plan-toml-parser.test.d.ts +10 -0
  94. package/dist/tests/unit/hooks/plan-toml-parser.test.d.ts.map +1 -0
  95. package/dist/tests/unit/hooks/plan-toml-parser.test.js +316 -0
  96. package/dist/tests/unit/hooks/plan-toml-parser.test.js.map +1 -0
  97. package/dist/tools/constraints/actions/activate.d.ts +46 -0
  98. package/dist/tools/constraints/actions/activate.d.ts.map +1 -0
  99. package/dist/tools/constraints/actions/activate.js +105 -0
  100. package/dist/tools/constraints/actions/activate.js.map +1 -0
  101. package/dist/tools/constraints/actions/add.d.ts.map +1 -1
  102. package/dist/tools/constraints/actions/add.js +30 -13
  103. package/dist/tools/constraints/actions/add.js.map +1 -1
  104. package/dist/tools/constraints/actions/deactivate.d.ts.map +1 -1
  105. package/dist/tools/constraints/actions/deactivate.js +7 -4
  106. package/dist/tools/constraints/actions/deactivate.js.map +1 -1
  107. package/dist/tools/constraints/actions/get.d.ts.map +1 -1
  108. package/dist/tools/constraints/actions/get.js +10 -7
  109. package/dist/tools/constraints/actions/get.js.map +1 -1
  110. package/dist/tools/constraints/actions/suggest-pending.d.ts +41 -0
  111. package/dist/tools/constraints/actions/suggest-pending.d.ts.map +1 -0
  112. package/dist/tools/constraints/actions/suggest-pending.js +71 -0
  113. package/dist/tools/constraints/actions/suggest-pending.js.map +1 -0
  114. package/dist/tools/constraints/help/example.d.ts.map +1 -1
  115. package/dist/tools/constraints/help/example.js +65 -1
  116. package/dist/tools/constraints/help/example.js.map +1 -1
  117. package/dist/tools/constraints/help/help.d.ts.map +1 -1
  118. package/dist/tools/constraints/help/help.js +10 -5
  119. package/dist/tools/constraints/help/help.js.map +1 -1
  120. package/dist/tools/constraints/index.d.ts +2 -0
  121. package/dist/tools/constraints/index.d.ts.map +1 -1
  122. package/dist/tools/constraints/index.js +2 -0
  123. package/dist/tools/constraints/index.js.map +1 -1
  124. package/dist/tools/context/actions/add-context.d.ts.map +1 -1
  125. package/dist/tools/context/actions/add-context.js +13 -6
  126. package/dist/tools/context/actions/add-context.js.map +1 -1
  127. package/dist/tools/context/actions/has-updates.d.ts.map +1 -1
  128. package/dist/tools/context/actions/has-updates.js +0 -4
  129. package/dist/tools/context/actions/has-updates.js.map +1 -1
  130. package/dist/tools/context/actions/list-contexts.d.ts.map +1 -1
  131. package/dist/tools/context/actions/list-contexts.js +12 -7
  132. package/dist/tools/context/actions/list-contexts.js.map +1 -1
  133. package/dist/tools/context/actions/list.d.ts.map +1 -1
  134. package/dist/tools/context/actions/list.js +8 -0
  135. package/dist/tools/context/actions/list.js.map +1 -1
  136. package/dist/tools/context/actions/search-advanced.d.ts.map +1 -1
  137. package/dist/tools/context/actions/search-advanced.js +41 -27
  138. package/dist/tools/context/actions/search-advanced.js.map +1 -1
  139. package/dist/tools/context/actions/search-layer.d.ts.map +1 -1
  140. package/dist/tools/context/actions/search-layer.js +8 -0
  141. package/dist/tools/context/actions/search-layer.js.map +1 -1
  142. package/dist/tools/context/actions/search-tags.d.ts.map +1 -1
  143. package/dist/tools/context/actions/search-tags.js +8 -0
  144. package/dist/tools/context/actions/search-tags.js.map +1 -1
  145. package/dist/tools/files/actions/check-lock.d.ts.map +1 -1
  146. package/dist/tools/files/actions/check-lock.js +9 -3
  147. package/dist/tools/files/actions/check-lock.js.map +1 -1
  148. package/dist/tools/files/actions/get.d.ts.map +1 -1
  149. package/dist/tools/files/actions/get.js +18 -13
  150. package/dist/tools/files/actions/get.js.map +1 -1
  151. package/dist/tools/files/actions/record-batch.d.ts.map +1 -1
  152. package/dist/tools/files/actions/record-batch.js +11 -6
  153. package/dist/tools/files/actions/record-batch.js.map +1 -1
  154. package/dist/tools/files/actions/record.d.ts.map +1 -1
  155. package/dist/tools/files/actions/record.js +8 -2
  156. package/dist/tools/files/actions/record.js.map +1 -1
  157. package/dist/tools/files/help/example.d.ts.map +1 -1
  158. package/dist/tools/files/help/example.js +11 -0
  159. package/dist/tools/files/help/example.js.map +1 -1
  160. package/dist/tools/files/help/help.d.ts.map +1 -1
  161. package/dist/tools/files/help/help.js +11 -0
  162. package/dist/tools/files/help/help.js.map +1 -1
  163. package/dist/tools/suggest/actions/by-context.d.ts.map +1 -1
  164. package/dist/tools/suggest/actions/by-context.js +5 -15
  165. package/dist/tools/suggest/actions/by-context.js.map +1 -1
  166. package/dist/tools/suggest/actions/by-key.d.ts.map +1 -1
  167. package/dist/tools/suggest/actions/by-key.js +5 -15
  168. package/dist/tools/suggest/actions/by-key.js.map +1 -1
  169. package/dist/tools/suggest/actions/by-tags.d.ts.map +1 -1
  170. package/dist/tools/suggest/actions/by-tags.js +5 -15
  171. package/dist/tools/suggest/actions/by-tags.js.map +1 -1
  172. package/dist/tools/suggest/actions/constraint-by-context.d.ts +1 -1
  173. package/dist/tools/suggest/actions/constraint-by-context.d.ts.map +1 -1
  174. package/dist/tools/suggest/actions/constraint-by-context.js +9 -16
  175. package/dist/tools/suggest/actions/constraint-by-context.js.map +1 -1
  176. package/dist/tools/suggest/actions/constraint-by-tags.d.ts +1 -1
  177. package/dist/tools/suggest/actions/constraint-by-tags.d.ts.map +1 -1
  178. package/dist/tools/suggest/actions/constraint-by-tags.js +11 -17
  179. package/dist/tools/suggest/actions/constraint-by-tags.js.map +1 -1
  180. package/dist/tools/suggest/actions/constraint-by-text.d.ts +1 -1
  181. package/dist/tools/suggest/actions/constraint-by-text.d.ts.map +1 -1
  182. package/dist/tools/suggest/actions/constraint-by-text.js +6 -15
  183. package/dist/tools/suggest/actions/constraint-by-text.js.map +1 -1
  184. package/dist/types/actions.d.ts +1 -1
  185. package/dist/types/actions.d.ts.map +1 -1
  186. package/dist/types.d.ts +9 -230
  187. package/dist/types.d.ts.map +1 -1
  188. package/dist/utils/action-specs/constraint-specs.d.ts +1 -1
  189. package/dist/utils/action-specs/constraint-specs.d.ts.map +1 -1
  190. package/dist/utils/action-specs/constraint-specs.js +22 -5
  191. package/dist/utils/action-specs/constraint-specs.js.map +1 -1
  192. package/dist/utils/action-specs/decision-specs.d.ts.map +1 -1
  193. package/dist/utils/action-specs/decision-specs.js +11 -10
  194. package/dist/utils/action-specs/decision-specs.js.map +1 -1
  195. package/dist/utils/action-specs/file-specs.js +4 -4
  196. package/dist/utils/action-specs/file-specs.js.map +1 -1
  197. package/dist/utils/hook-queue.d.ts +43 -3
  198. package/dist/utils/hook-queue.d.ts.map +1 -1
  199. package/dist/utils/hook-queue.js +326 -32
  200. package/dist/utils/hook-queue.js.map +1 -1
  201. package/dist/utils/param-normalizer.d.ts +52 -0
  202. package/dist/utils/param-normalizer.d.ts.map +1 -0
  203. package/dist/utils/param-normalizer.js +70 -0
  204. package/dist/utils/param-normalizer.js.map +1 -0
  205. package/dist/utils/parameter-validator.d.ts.map +1 -1
  206. package/dist/utils/parameter-validator.js +2 -0
  207. package/dist/utils/parameter-validator.js.map +1 -1
  208. package/dist/utils/suggest-helpers.d.ts +82 -0
  209. package/dist/utils/suggest-helpers.d.ts.map +1 -0
  210. package/dist/utils/suggest-helpers.js +93 -0
  211. package/dist/utils/suggest-helpers.js.map +1 -0
  212. package/dist/utils/text-truncate.d.ts +13 -0
  213. package/dist/utils/text-truncate.d.ts.map +1 -0
  214. package/dist/utils/text-truncate.js +18 -0
  215. package/dist/utils/text-truncate.js.map +1 -0
  216. package/dist/utils/validators.d.ts +1 -1
  217. package/dist/utils/validators.d.ts.map +1 -1
  218. package/dist/utils/validators.js +1 -1
  219. package/dist/utils/validators.js.map +1 -1
  220. package/dist/watcher/base-watcher.d.ts.map +1 -1
  221. package/dist/watcher/base-watcher.js +4 -3
  222. package/dist/watcher/base-watcher.js.map +1 -1
  223. package/dist/watcher/file-watcher.d.ts.map +1 -1
  224. package/dist/watcher/file-watcher.js +5 -1
  225. package/dist/watcher/file-watcher.js.map +1 -1
  226. package/dist/watcher/queue-watcher.d.ts +12 -1
  227. package/dist/watcher/queue-watcher.d.ts.map +1 -1
  228. package/dist/watcher/queue-watcher.js +92 -12
  229. package/dist/watcher/queue-watcher.js.map +1 -1
  230. package/docs/ADR_CONCEPTS.md +4 -0
  231. package/docs/HOOKS_GUIDE.md +1 -1
  232. package/package.json +1 -1
@@ -1,83 +1,20 @@
1
1
  /**
2
2
  * Suggest Hook Command
3
3
  *
4
- * PreToolUse hook for Task tool - suggests related decisions.
5
- * Extracts keywords from task description/prompt and finds related decisions.
4
+ * PreToolUse hook for Task tool - manages Plan agent sessions.
5
+ * Clears stale caches when a new Plan agent starts.
6
+ *
7
+ * NOTE: Template injection removed in v4.2.2 - didn't work reliably.
8
+ * Using Skills-based template injection instead.
6
9
  *
7
10
  * Usage:
8
- * echo '{"tool_input": {"description": "implement auth"}}' | sqlew suggest
11
+ * echo '{"tool_input": {"subagent_type": "Plan"}}' | sqlew suggest
9
12
  *
10
13
  * @since v4.1.0
14
+ * @modified v4.2.2 - Removed template injection, simplified to cache management
11
15
  */
12
- import { readStdinJson, sendContinue, getProjectPath } from './stdin-parser.js';
13
- import { initializeDatabase } from '../../database.js';
14
- import { suggestByContext } from '../../tools/suggest/actions/by-context.js';
15
- import { join } from 'path';
16
- // ============================================================================
17
- // Constants
18
- // ============================================================================
19
- /** Minimum keyword length to use for search */
20
- const MIN_KEYWORD_LENGTH = 3;
21
- /** Default limit for suggestions */
22
- const DEFAULT_LIMIT = 5;
23
- /** Minimum score for suggestions */
24
- const MIN_SCORE = 30;
25
- // ============================================================================
26
- // Keyword Extraction
27
- // ============================================================================
28
- /**
29
- * Extract meaningful keywords from text
30
- *
31
- * Removes common stop words and short words.
32
- *
33
- * @param text - Text to extract keywords from
34
- * @returns Array of keywords
35
- */
36
- function extractKeywords(text) {
37
- // Common stop words to filter out
38
- const stopWords = new Set([
39
- 'the', 'a', 'an', 'and', 'or', 'but', 'in', 'on', 'at', 'to', 'for',
40
- 'of', 'with', 'by', 'from', 'as', 'is', 'was', 'are', 'were', 'been',
41
- 'be', 'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could',
42
- 'should', 'may', 'might', 'must', 'shall', 'can', 'need', 'this', 'that',
43
- 'these', 'those', 'i', 'you', 'he', 'she', 'it', 'we', 'they', 'what',
44
- 'which', 'who', 'when', 'where', 'why', 'how', 'all', 'each', 'every',
45
- 'both', 'few', 'more', 'most', 'other', 'some', 'such', 'no', 'not',
46
- 'only', 'same', 'so', 'than', 'too', 'very', 'just', 'also', 'now',
47
- 'use', 'using', 'implement', 'create', 'add', 'update', 'fix', 'make',
48
- 'get', 'set', 'new', 'file', 'code', 'function', 'method', 'class',
49
- ]);
50
- // Split on word boundaries and filter
51
- const words = text
52
- .toLowerCase()
53
- .replace(/[^a-z0-9\s-_]/g, ' ')
54
- .split(/\s+/)
55
- .filter(word => word.length >= MIN_KEYWORD_LENGTH &&
56
- !stopWords.has(word) &&
57
- !/^\d+$/.test(word) // Filter out pure numbers
58
- );
59
- // Deduplicate while preserving order
60
- return [...new Set(words)];
61
- }
62
- /**
63
- * Extract search context from hook input
64
- *
65
- * Combines description and prompt from Task tool input.
66
- *
67
- * @param input - Hook input
68
- * @returns Combined search text
69
- */
70
- function extractSearchContext(input) {
71
- const parts = [];
72
- // Task tool uses description and prompt
73
- if (input.tool_input?.description) {
74
- parts.push(input.tool_input.description);
75
- }
76
- if (input.tool_input?.prompt) {
77
- parts.push(input.tool_input.prompt);
78
- }
79
- return parts.join(' ');
80
- }
16
+ import { readStdinJson, sendContinue, isPlanAgent, getProjectPath } from './stdin-parser.js';
17
+ import { clearPlanTomlCache, clearCurrentPlan } from '../../config/global-config.js';
81
18
  // ============================================================================
82
19
  // Main Entry Point
83
20
  // ============================================================================
@@ -85,67 +22,28 @@ function extractSearchContext(input) {
85
22
  * Main suggest command entry point
86
23
  *
87
24
  * Called as PreToolUse hook when Task tool is invoked.
88
- * Finds related decisions and injects them as context.
25
+ * For Plan agents: clears stale caches from previous sessions.
89
26
  */
90
27
  export async function suggestCommand() {
91
28
  try {
92
29
  const input = await readStdinJson();
93
- // Only process Task tool
30
+ // Only process Task tool (PreToolUse hook)
94
31
  if (input.tool_name !== 'Task') {
95
32
  sendContinue();
96
33
  return;
97
34
  }
98
- const projectPath = getProjectPath(input);
99
- if (!projectPath) {
100
- sendContinue();
101
- return;
102
- }
103
- // Extract search context
104
- const searchText = extractSearchContext(input);
105
- if (!searchText.trim()) {
106
- sendContinue();
107
- return;
108
- }
109
- // Extract keywords for search
110
- const keywords = extractKeywords(searchText);
111
- if (keywords.length === 0) {
112
- sendContinue();
113
- return;
114
- }
115
- // Initialize database
116
- const dbPath = join(projectPath, '.sqlew', 'sqlew.db');
117
- try {
118
- await initializeDatabase({ configPath: dbPath });
119
- }
120
- catch {
121
- // Database not initialized - continue without suggestions
122
- sendContinue();
123
- return;
124
- }
125
- // Build search key from keywords
126
- const searchKey = keywords.slice(0, 5).join(' ');
127
- // Find related decisions
128
- const result = await suggestByContext({
129
- key: searchKey,
130
- limit: DEFAULT_LIMIT,
131
- min_score: MIN_SCORE,
132
- });
133
- if (result.suggestions.length === 0) {
134
- sendContinue();
135
- return;
136
- }
137
- // Format suggestions as context
138
- const contextLines = [
139
- '[sqlew] Related decisions found:',
140
- '',
141
- ];
142
- for (const suggestion of result.suggestions) {
143
- contextLines.push(`- **${suggestion.key}**: ${suggestion.value}`);
144
- if (suggestion.reason) {
145
- contextLines.push(` (${suggestion.reason})`);
35
+ // Check if this is a Plan agent - clear stale caches
36
+ if (isPlanAgent(input)) {
37
+ const projectPath = getProjectPath(input);
38
+ if (projectPath) {
39
+ // Clear stale caches from previous sessions (v4.2.0+)
40
+ // This prevents false positives in on-subagent-stop hook
41
+ clearCurrentPlan(projectPath);
42
+ clearPlanTomlCache(projectPath);
146
43
  }
147
44
  }
148
- sendContinue(contextLines.join('\n'));
45
+ // Continue without modification
46
+ sendContinue();
149
47
  }
150
48
  catch (error) {
151
49
  // On error, log to stderr but continue execution
@@ -1 +1 @@
1
- {"version":3,"file":"suggest.js","sourceRoot":"","sources":["../../../src/cli/hooks/suggest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAkB,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,+CAA+C;AAC/C,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B,oCAAoC;AACpC,MAAM,aAAa,GAAG,CAA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I,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;YAC1C,IAAI,WAAW,EAAE,CAAC;gBAChB,sDAAsD;gBACtD,yDAAyD;gBACzD,gBAAgB,CAAC,WAAW,CAAC,CAAC;gBAC9B,kBAAkB,CAAC,WAAW,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QAED,gCAAgC;QAChC,YAAY,EAAE,CAAC;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iDAAiD;QACjD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,CAAC,KAAK,CAAC,0BAA0B,OAAO,EAAE,CAAC,CAAC;QACnD,YAAY,EAAE,CAAC;IACjB,CAAC;AACH,CAAC"}
@@ -1,15 +1,20 @@
1
1
  /**
2
2
  * Track Plan Hook Command
3
3
  *
4
- * PreToolUse hook for Write tool - tracks plan files.
4
+ * PreToolUse hook for Write tool - tracks plan files and injects templates.
5
5
  * When a .claude/plans/*.md file is being written:
6
6
  * 1. Ensures plan has sqlew-plan-id in YAML frontmatter
7
7
  * 2. Saves current plan info to session cache
8
+ * 3. Injects Decision/Constraint template on new plan creation
9
+ *
10
+ * Decision/constraint extraction happens in on-exit-plan.ts using pattern matching.
8
11
  *
9
12
  * Usage:
10
13
  * echo '{"tool_input": {"file_path": ".claude/plans/my-plan.md"}}' | sqlew track-plan
11
14
  *
12
15
  * @since v4.1.0
16
+ * @modified v4.2.2 - Removed LLM extraction, simplified to plan tracking only
17
+ * @modified v4.2.3 - Added template injection on new plan creation
13
18
  */
14
19
  import { type CurrentPlanInfo } from '../../config/global-config.js';
15
20
  /**
@@ -17,6 +22,8 @@ import { type CurrentPlanInfo } from '../../config/global-config.js';
17
22
  *
18
23
  * Called as PreToolUse hook when Write tool is invoked.
19
24
  * Only processes .claude/plans/*.md files.
25
+ *
26
+ * v4.2.2: Simplified to plan tracking only. Pattern extraction happens in on-exit-plan.
20
27
  */
21
28
  export declare function trackPlanCommand(): Promise<void>;
22
29
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"track-plan.d.ts","sourceRoot":"","sources":["../../../src/cli/hooks/track-plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAoC,KAAK,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAgBvG;;;;;GAKG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAyHtD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAGjF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEjE"}
1
+ {"version":3,"file":"track-plan.d.ts","sourceRoot":"","sources":["../../../src/cli/hooks/track-plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,+BAA+B,CAAC;AAiCvC;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAoFtD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAEjF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEjE"}
@@ -1,27 +1,49 @@
1
1
  /**
2
2
  * Track Plan Hook Command
3
3
  *
4
- * PreToolUse hook for Write tool - tracks plan files.
4
+ * PreToolUse hook for Write tool - tracks plan files and injects templates.
5
5
  * When a .claude/plans/*.md file is being written:
6
6
  * 1. Ensures plan has sqlew-plan-id in YAML frontmatter
7
7
  * 2. Saves current plan info to session cache
8
+ * 3. Injects Decision/Constraint template on new plan creation
9
+ *
10
+ * Decision/constraint extraction happens in on-exit-plan.ts using pattern matching.
8
11
  *
9
12
  * Usage:
10
13
  * echo '{"tool_input": {"file_path": ".claude/plans/my-plan.md"}}' | sqlew track-plan
11
14
  *
12
15
  * @since v4.1.0
16
+ * @modified v4.2.2 - Removed LLM extraction, simplified to plan tracking only
17
+ * @modified v4.2.3 - Added template injection on new plan creation
13
18
  */
14
19
  import { readStdinJson, sendContinue, isPlanFile, getProjectPath } from './stdin-parser.js';
15
- import { ensurePlanId, extractPlanFileName, getPlanId, parseFrontmatter, generatePlanId } from './plan-id-utils.js';
16
- import { saveCurrentPlan, loadCurrentPlan } from '../../config/global-config.js';
17
- import { enqueueDecisionCreate } from '../../utils/hook-queue.js';
18
- import { existsSync } from 'fs';
20
+ import { extractPlanFileName, parseFrontmatter, generatePlanId, getPlanId } from './plan-id-utils.js';
21
+ import { saveCurrentPlan, loadCurrentPlan, clearPlanTomlCache, } from '../../config/global-config.js';
22
+ import { existsSync, readFileSync } from 'fs';
19
23
  import { resolve } from 'path';
20
24
  // ============================================================================
21
- // Constants
25
+ // Template Constants
22
26
  // ============================================================================
23
- /** Decision key prefix for plan-based decisions */
24
- const PLAN_DECISION_PREFIX = 'plan/implementation';
27
+ /**
28
+ * Decision/Constraint template to inject on new plan creation
29
+ * Compact format for context window efficiency
30
+ */
31
+ const PLAN_TEMPLATE = `
32
+ ---
33
+ ## 📝 Decision/Constraint Recording (auto-detected on ExitPlanMode)
34
+
35
+ ### 📌 Decision: [key/path]
36
+ - **Value**: Description
37
+ - **Layer**: presentation | business | data | infrastructure | cross-cutting
38
+ - **Rationale**: Why this decision was made
39
+
40
+ ### 🚫 Constraint: [category]
41
+ - **Rule**: Description (category: architecture | security | code-style | performance)
42
+ - **Priority**: critical | high | medium | low
43
+ - **Tags**: comma-separated tags
44
+
45
+ ---
46
+ `.trim();
25
47
  // ============================================================================
26
48
  // Main Entry Point
27
49
  // ============================================================================
@@ -30,19 +52,24 @@ const PLAN_DECISION_PREFIX = 'plan/implementation';
30
52
  *
31
53
  * Called as PreToolUse hook when Write tool is invoked.
32
54
  * Only processes .claude/plans/*.md files.
55
+ *
56
+ * v4.2.2: Simplified to plan tracking only. Pattern extraction happens in on-exit-plan.
33
57
  */
34
58
  export async function trackPlanCommand() {
35
59
  try {
36
60
  const input = await readStdinJson();
37
- // Only process plan files
61
+ // Handle EnterPlanMode - prepare for plan tracking
62
+ if (input.tool_name === 'EnterPlanMode') {
63
+ sendContinue('[sqlew] Plan mode entered. Waiting for plan file...');
64
+ return;
65
+ }
66
+ // Only process plan files for Write tool
38
67
  if (!isPlanFile(input)) {
39
- // Not a plan file - continue without action
40
68
  sendContinue();
41
69
  return;
42
70
  }
43
71
  const projectPath = getProjectPath(input);
44
72
  if (!projectPath) {
45
- // No project path - continue without action
46
73
  sendContinue();
47
74
  return;
48
75
  }
@@ -53,78 +80,50 @@ export async function trackPlanCommand() {
53
80
  }
54
81
  // Resolve absolute path
55
82
  const absolutePath = resolve(projectPath, filePath);
56
- // Check if file exists (it might be a new file being created)
83
+ // Parse frontmatter for plan ID (from tool_input content if available)
84
+ let content;
57
85
  if (!existsSync(absolutePath)) {
58
- // File doesn't exist yet - this is PreToolUse for new file creation
59
- // Try to extract plan_id from the content being written (tool_input.content)
60
- const content = input.tool_input?.content;
61
- if (!content) {
62
- // No content to parse - continue without action
63
- sendContinue(`[sqlew] New plan file detected: ${extractPlanFileName(absolutePath)}. ` +
64
- `No content provided, skipping tracking.`);
65
- return;
66
- }
67
- // Parse frontmatter from content being written
86
+ content = input.tool_input?.content;
87
+ }
88
+ else {
89
+ content = input.tool_input?.content || readFileSync(absolutePath, 'utf-8');
90
+ }
91
+ // Get or generate plan ID
92
+ let planId;
93
+ if (content) {
68
94
  const frontmatter = parseFrontmatter(content);
69
- let planId = frontmatter.data['sqlew-plan-id'];
70
- // Generate new plan ID if not present in content
71
- if (!planId) {
72
- planId = generatePlanId();
73
- }
74
- const planFileName = extractPlanFileName(absolutePath);
75
- // Save current plan info to session cache
76
- const planInfo = {
77
- plan_id: planId,
78
- plan_file: planFileName,
79
- plan_updated_at: new Date().toISOString(),
80
- recorded: false,
81
- decision_pending: true,
82
- };
83
- saveCurrentPlan(projectPath, planInfo);
84
- // Enqueue draft decision for later processing by MCP server
85
- const decisionKey = `${PLAN_DECISION_PREFIX}/${planFileName.replace(/\.md$/, '')}`;
86
- enqueueDecisionCreate(projectPath, {
87
- key: decisionKey,
88
- value: `Plan created: ${planFileName}`,
89
- status: 'draft',
90
- layer: 'cross-cutting',
91
- tags: ['plan', 'draft', planId.slice(0, 8)],
92
- });
93
- // Continue with context about the tracked plan
94
- sendContinue(`[sqlew] Tracking new plan: ${planFileName} (ID: ${planId.slice(0, 8)}...)`);
95
- return;
95
+ planId = frontmatter.data['sqlew-plan-id'] || generatePlanId();
96
+ }
97
+ else {
98
+ planId = generatePlanId();
96
99
  }
97
- // Ensure plan has an ID (creates one if missing)
98
- const planId = ensurePlanId(absolutePath);
99
100
  const planFileName = extractPlanFileName(absolutePath);
100
101
  // Check if we already have cached info for this plan
101
102
  const existingPlan = loadCurrentPlan(projectPath);
102
103
  const isNewPlan = !existingPlan || existingPlan.plan_id !== planId;
103
- // Save current plan info to session cache
104
+ // Clear old cache if switching plans
105
+ if (isNewPlan) {
106
+ clearPlanTomlCache(projectPath);
107
+ }
108
+ // Save current plan info to cache
109
+ // CRITICAL: Reset recorded flag on new plan to allow pattern extraction
104
110
  const planInfo = {
105
111
  plan_id: planId,
106
112
  plan_file: planFileName,
107
113
  plan_updated_at: new Date().toISOString(),
108
- recorded: existingPlan?.recorded ?? false,
114
+ recorded: isNewPlan ? false : (existingPlan?.recorded ?? false),
109
115
  decision_pending: isNewPlan ? true : (existingPlan?.decision_pending ?? false),
110
116
  };
111
117
  saveCurrentPlan(projectPath, planInfo);
112
- // Enqueue draft decision for new plans
118
+ // Build context message
119
+ let contextMsg = `[sqlew] Tracking plan: ${planFileName} (ID: ${planId.slice(0, 8)}...)`;
120
+ // Inject template on new plan creation
113
121
  if (isNewPlan) {
114
- const decisionKey = `${PLAN_DECISION_PREFIX}/${planFileName.replace(/\.md$/, '')}`;
115
- enqueueDecisionCreate(projectPath, {
116
- key: decisionKey,
117
- value: `Plan created: ${planFileName}`,
118
- status: 'draft',
119
- layer: 'cross-cutting',
120
- tags: ['plan', 'draft', planId.slice(0, 8)],
121
- });
122
+ contextMsg += `\n\n${PLAN_TEMPLATE}`;
122
123
  }
123
- // Continue with context about the tracked plan
124
- sendContinue(`[sqlew] Tracking plan: ${planFileName} (ID: ${planId.slice(0, 8)}...)`);
124
+ sendContinue(contextMsg);
125
125
  }
126
126
  catch (error) {
127
- // On error, log to stderr but continue execution
128
127
  const message = error instanceof Error ? error.message : String(error);
129
128
  console.error(`[sqlew track-plan] Error: ${message}`);
130
129
  sendContinue();
@@ -137,7 +136,6 @@ export async function trackPlanCommand() {
137
136
  * @returns Current plan info or null
138
137
  */
139
138
  export function getCurrentTrackedPlan(projectPath) {
140
- const { loadCurrentPlan } = require('../../config/global-config.js');
141
139
  return loadCurrentPlan(projectPath);
142
140
  }
143
141
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"track-plan.js","sourceRoot":"","sources":["../../../src/cli/hooks/track-plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpH,OAAO,EAAE,eAAe,EAAE,eAAe,EAAwB,MAAM,+BAA+B,CAAC;AACvG,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,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Q,CAAC,CAAC;AAC7B,CAAC"}
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;GAGG;AAuQH;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA2F7D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAOrD"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;GAGG;AAqVH;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAyH7D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CASrD"}
package/dist/cli.js CHANGED
@@ -16,6 +16,11 @@ import { saveCommand } from './cli/hooks/save.js';
16
16
  import { checkCompletionCommand } from './cli/hooks/check-completion.js';
17
17
  import { markDoneCommand } from './cli/hooks/mark-done.js';
18
18
  import { initHooksCommand } from './cli/hooks/init-hooks.js';
19
+ import { initializeSkills, initializeRules, initializeGitignore } from './init-skills.js';
20
+ import { onSubagentStopCommand } from './cli/hooks/on-subagent-stop.js';
21
+ import { onStopCommand } from './cli/hooks/on-stop.js';
22
+ import { onEnterPlanCommand } from './cli/hooks/on-enter-plan.js';
23
+ import { onExitPlanCommand } from './cli/hooks/on-exit-plan.js';
19
24
  // ============================================================================
20
25
  // Helper Functions
21
26
  // ============================================================================
@@ -35,6 +40,9 @@ function parseArgs(args) {
35
40
  else if (key === 'help') {
36
41
  parsed.help = true;
37
42
  }
43
+ else if (key === 'init') {
44
+ parsed.init = true;
45
+ }
38
46
  else if (value && !value.startsWith('--')) {
39
47
  // Handle different key types
40
48
  if (key === 'limit') {
@@ -106,8 +114,13 @@ sqlew CLI - Query and database migration tool for mcp-sqlew
106
114
 
107
115
  USAGE:
108
116
  sqlew <command> [options]
117
+ sqlew --init # One-shot project setup (recommended)
109
118
 
110
119
  COMMANDS:
120
+ Setup:
121
+ --init One-shot initialization (Skills + CLAUDE.md + Hooks + gitignore)
122
+ init --hooks Initialize Claude Code and Git hooks only
123
+
111
124
  Database:
112
125
  db:dump Generate SQL dump for database migration (schema + data)
113
126
  db:export Export project data to JSON format (data-only, for append-import)
@@ -119,21 +132,27 @@ COMMANDS:
119
132
  save Save decisions on code edit (PostToolUse hook for Edit|Write)
120
133
  check-completion Check task completion (PostToolUse hook for TodoWrite)
121
134
  mark-done Mark decisions as implemented (Git hooks or manual)
122
- init --hooks Initialize Claude Code and Git hooks
135
+
136
+ Plan Mode Hooks (v4.2.0+):
137
+ on-enter-plan Inject TOML template (PostToolUse hook for EnterPlanMode)
138
+ on-exit-plan Prompt TOML documentation (PostToolUse hook for ExitPlanMode)
139
+ on-subagent-stop Process Plan agent completion (SubagentStop hook)
140
+ on-stop Process main agent stop (Stop hook)
123
141
 
124
142
  OPTIONS:
143
+ --init Initialize all sqlew integrations
125
144
  --help Show this help message
126
145
 
127
146
  EXAMPLES:
128
- # Initialize hooks for Claude Code integration
147
+ # Full project setup (Skills, CLAUDE.md, Hooks, gitignore)
148
+ sqlew --init
149
+
150
+ # Initialize only hooks
129
151
  sqlew init --hooks
130
152
 
131
153
  # Generate MySQL dump for database migration
132
154
  npm run db:dump -- mysql -o dump-mysql.sql
133
155
 
134
- # Test hook commands manually
135
- echo '{"tool_input": {"description": "auth"}}' | sqlew suggest
136
-
137
156
  For more information on commands, run:
138
157
  npm run db:dump -- --help
139
158
  npm run db:export -- --help
@@ -211,6 +230,61 @@ async function queryFiles(args) {
211
230
  }
212
231
  }
213
232
  // ============================================================================
233
+ // Initialization Commands
234
+ // ============================================================================
235
+ /**
236
+ * Comprehensive project initialization
237
+ * Sets up Skills, CLAUDE.md integration, Hooks, and gitignore in one command
238
+ */
239
+ async function initAllCommand() {
240
+ const { determineProjectRoot } = await import('./utils/project-root.js');
241
+ const projectPath = determineProjectRoot();
242
+ console.log('[sqlew --init] Starting comprehensive initialization...');
243
+ console.log(`[sqlew --init] Project root: ${projectPath}`);
244
+ console.log('');
245
+ // 1. Initialize Skills
246
+ console.log('[1/4] Initializing Skills...');
247
+ try {
248
+ initializeSkills(projectPath);
249
+ console.log(' ✓ Skills initialized');
250
+ }
251
+ catch (error) {
252
+ console.log(` ✗ Skills failed: ${error instanceof Error ? error.message : String(error)}`);
253
+ }
254
+ // 2. Initialize .claude/rules/
255
+ console.log('[2/4] Setting up .claude/rules/...');
256
+ try {
257
+ initializeRules(projectPath);
258
+ console.log(' ✓ Plan mode integration rule installed');
259
+ }
260
+ catch (error) {
261
+ console.log(` ✗ Rules setup failed: ${error instanceof Error ? error.message : String(error)}`);
262
+ }
263
+ // 3. Initialize Hooks
264
+ console.log('[3/4] Setting up Claude Code Hooks...');
265
+ try {
266
+ await initHooksCommand([]);
267
+ }
268
+ catch (error) {
269
+ console.log(` ✗ Hooks failed: ${error instanceof Error ? error.message : String(error)}`);
270
+ }
271
+ // 4. Initialize gitignore
272
+ console.log('[4/4] Updating .gitignore...');
273
+ try {
274
+ initializeGitignore(projectPath);
275
+ console.log(' ✓ .gitignore updated');
276
+ }
277
+ catch (error) {
278
+ console.log(` ✗ .gitignore failed: ${error instanceof Error ? error.message : String(error)}`);
279
+ }
280
+ console.log('');
281
+ console.log('[sqlew --init] Initialization complete!');
282
+ console.log('');
283
+ console.log('Next steps:');
284
+ console.log(' 1. Restart Claude Code for hooks to take effect');
285
+ console.log(' 2. Run "/sqlew" to start using sqlew context management');
286
+ }
287
+ // ============================================================================
214
288
  // Main Entry Point
215
289
  // ============================================================================
216
290
  /**
@@ -256,7 +330,32 @@ export async function runCli(rawArgs) {
256
330
  await markDoneCommand(rawArgs.slice(1));
257
331
  return;
258
332
  }
259
- // init --hooks command
333
+ // SubagentStop hook (v4.2.0+)
334
+ if (args.command === 'on-subagent-stop') {
335
+ await onSubagentStopCommand();
336
+ return;
337
+ }
338
+ // Stop hook (v4.2.0+)
339
+ if (args.command === 'on-stop') {
340
+ await onStopCommand();
341
+ return;
342
+ }
343
+ // EnterPlanMode hook (v4.2.0+)
344
+ if (args.command === 'on-enter-plan') {
345
+ await onEnterPlanCommand();
346
+ return;
347
+ }
348
+ // ExitPlanMode hook (v4.2.0+)
349
+ if (args.command === 'on-exit-plan') {
350
+ await onExitPlanCommand();
351
+ return;
352
+ }
353
+ // --init flag: comprehensive initialization (Skills + CLAUDE.md + Hooks + gitignore)
354
+ if (args.init) {
355
+ await initAllCommand();
356
+ return;
357
+ }
358
+ // init --hooks command (hooks only)
260
359
  if (args.command === 'init' && rawArgs.includes('--hooks')) {
261
360
  await initHooksCommand(rawArgs.slice(1));
262
361
  return;
@@ -308,6 +407,8 @@ export function isCliCommand(command) {
308
407
  'db:dump', 'db:export', 'db:import', 'query',
309
408
  // Claude Code Hooks commands (v4.1.0+)
310
409
  'suggest', 'track-plan', 'save', 'check-completion', 'mark-done', 'init',
410
+ // New hook events (v4.2.0+)
411
+ 'on-subagent-stop', 'on-stop', 'on-enter-plan', 'on-exit-plan',
311
412
  ];
312
413
  return cliCommands.includes(command);
313
414
  }