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.
- package/CHANGELOG.md +59 -0
- package/README.md +268 -409
- package/assets/claude-md-snippets/plan-mode-integration.md +36 -10
- package/assets/config.example.toml +120 -282
- package/assets/sample-skills/sqlew-decision-format/SKILL.md +73 -0
- package/dist/cli/hooks/check-completion.d.ts.map +1 -1
- package/dist/cli/hooks/check-completion.js +90 -2
- package/dist/cli/hooks/check-completion.js.map +1 -1
- package/dist/cli/hooks/init-hooks.d.ts.map +1 -1
- package/dist/cli/hooks/init-hooks.js +97 -5
- package/dist/cli/hooks/init-hooks.js.map +1 -1
- package/dist/cli/hooks/on-enter-plan.d.ts +22 -0
- package/dist/cli/hooks/on-enter-plan.d.ts.map +1 -0
- package/dist/cli/hooks/on-enter-plan.js +51 -0
- package/dist/cli/hooks/on-enter-plan.js.map +1 -0
- package/dist/cli/hooks/on-exit-plan.d.ts +20 -0
- package/dist/cli/hooks/on-exit-plan.d.ts.map +1 -0
- package/dist/cli/hooks/on-exit-plan.js +66 -0
- package/dist/cli/hooks/on-exit-plan.js.map +1 -0
- package/dist/cli/hooks/on-stop.d.ts +19 -0
- package/dist/cli/hooks/on-stop.d.ts.map +1 -0
- package/dist/cli/hooks/on-stop.js +152 -0
- package/dist/cli/hooks/on-stop.js.map +1 -0
- package/dist/cli/hooks/on-subagent-stop.d.ts +20 -0
- package/dist/cli/hooks/on-subagent-stop.d.ts.map +1 -0
- package/dist/cli/hooks/on-subagent-stop.js +94 -0
- package/dist/cli/hooks/on-subagent-stop.js.map +1 -0
- package/dist/cli/hooks/plan-pattern-extractor.d.ts +87 -0
- package/dist/cli/hooks/plan-pattern-extractor.d.ts.map +1 -0
- package/dist/cli/hooks/plan-pattern-extractor.js +218 -0
- package/dist/cli/hooks/plan-pattern-extractor.js.map +1 -0
- package/dist/cli/hooks/plan-processor.d.ts +43 -0
- package/dist/cli/hooks/plan-processor.d.ts.map +1 -0
- package/dist/cli/hooks/plan-processor.js +115 -0
- package/dist/cli/hooks/plan-processor.js.map +1 -0
- package/dist/cli/hooks/plan-toml-parser.d.ts +42 -0
- package/dist/cli/hooks/plan-toml-parser.d.ts.map +1 -0
- package/dist/cli/hooks/plan-toml-parser.js +178 -0
- package/dist/cli/hooks/plan-toml-parser.js.map +1 -0
- package/dist/cli/hooks/save.d.ts +7 -9
- package/dist/cli/hooks/save.d.ts.map +1 -1
- package/dist/cli/hooks/save.js +50 -25
- package/dist/cli/hooks/save.js.map +1 -1
- package/dist/cli/hooks/stdin-parser.d.ts +66 -2
- package/dist/cli/hooks/stdin-parser.d.ts.map +1 -1
- package/dist/cli/hooks/stdin-parser.js +57 -2
- package/dist/cli/hooks/stdin-parser.js.map +1 -1
- package/dist/cli/hooks/suggest.d.ts +8 -4
- package/dist/cli/hooks/suggest.d.ts.map +1 -1
- package/dist/cli/hooks/suggest.js +21 -123
- package/dist/cli/hooks/suggest.js.map +1 -1
- package/dist/cli/hooks/track-plan.d.ts +8 -1
- package/dist/cli/hooks/track-plan.d.ts.map +1 -1
- package/dist/cli/hooks/track-plan.js +64 -66
- package/dist/cli/hooks/track-plan.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +107 -6
- package/dist/cli.js.map +1 -1
- package/dist/config/global-config.d.ts +90 -0
- package/dist/config/global-config.d.ts.map +1 -1
- package/dist/config/global-config.js +86 -1
- package/dist/config/global-config.js.map +1 -1
- package/dist/database/initialization/init.js +3 -3
- package/dist/database/initialization/init.js.map +1 -1
- package/dist/database/migrations/v4/20260102204000_v4_fix_decision_set_example.d.ts +15 -0
- package/dist/database/migrations/v4/20260102204000_v4_fix_decision_set_example.d.ts.map +1 -0
- package/dist/database/migrations/v4/20260102204000_v4_fix_decision_set_example.js +74 -0
- package/dist/database/migrations/v4/20260102204000_v4_fix_decision_set_example.js.map +1 -0
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/init-skills.d.ts +12 -3
- package/dist/init-skills.d.ts.map +1 -1
- package/dist/init-skills.js +96 -24
- package/dist/init-skills.js.map +1 -1
- package/dist/knexfile.d.ts.map +1 -1
- package/dist/knexfile.js +16 -12
- package/dist/knexfile.js.map +1 -1
- package/dist/server/setup.js +5 -5
- package/dist/server/setup.js.map +1 -1
- package/dist/server/tool-handlers.d.ts.map +1 -1
- package/dist/server/tool-handlers.js +7 -1
- package/dist/server/tool-handlers.js.map +1 -1
- package/dist/server/tool-registry.js +1 -1
- package/dist/server/tool-registry.js.map +1 -1
- package/dist/tests/feature/decision/truncate.test.d.ts +8 -0
- package/dist/tests/feature/decision/truncate.test.d.ts.map +1 -0
- package/dist/tests/feature/decision/truncate.test.js +192 -0
- package/dist/tests/feature/decision/truncate.test.js.map +1 -0
- package/dist/tests/unit/config/plan-toml-cache.test.d.ts +9 -0
- package/dist/tests/unit/config/plan-toml-cache.test.d.ts.map +1 -0
- package/dist/tests/unit/config/plan-toml-cache.test.js +230 -0
- package/dist/tests/unit/config/plan-toml-cache.test.js.map +1 -0
- package/dist/tests/unit/hooks/plan-toml-parser.test.d.ts +10 -0
- package/dist/tests/unit/hooks/plan-toml-parser.test.d.ts.map +1 -0
- package/dist/tests/unit/hooks/plan-toml-parser.test.js +316 -0
- package/dist/tests/unit/hooks/plan-toml-parser.test.js.map +1 -0
- package/dist/tools/constraints/actions/activate.d.ts +46 -0
- package/dist/tools/constraints/actions/activate.d.ts.map +1 -0
- package/dist/tools/constraints/actions/activate.js +105 -0
- package/dist/tools/constraints/actions/activate.js.map +1 -0
- package/dist/tools/constraints/actions/add.d.ts.map +1 -1
- package/dist/tools/constraints/actions/add.js +30 -13
- package/dist/tools/constraints/actions/add.js.map +1 -1
- package/dist/tools/constraints/actions/deactivate.d.ts.map +1 -1
- package/dist/tools/constraints/actions/deactivate.js +7 -4
- package/dist/tools/constraints/actions/deactivate.js.map +1 -1
- package/dist/tools/constraints/actions/get.d.ts.map +1 -1
- package/dist/tools/constraints/actions/get.js +10 -7
- package/dist/tools/constraints/actions/get.js.map +1 -1
- package/dist/tools/constraints/actions/suggest-pending.d.ts +41 -0
- package/dist/tools/constraints/actions/suggest-pending.d.ts.map +1 -0
- package/dist/tools/constraints/actions/suggest-pending.js +71 -0
- package/dist/tools/constraints/actions/suggest-pending.js.map +1 -0
- package/dist/tools/constraints/help/example.d.ts.map +1 -1
- package/dist/tools/constraints/help/example.js +65 -1
- package/dist/tools/constraints/help/example.js.map +1 -1
- package/dist/tools/constraints/help/help.d.ts.map +1 -1
- package/dist/tools/constraints/help/help.js +10 -5
- package/dist/tools/constraints/help/help.js.map +1 -1
- package/dist/tools/constraints/index.d.ts +2 -0
- package/dist/tools/constraints/index.d.ts.map +1 -1
- package/dist/tools/constraints/index.js +2 -0
- package/dist/tools/constraints/index.js.map +1 -1
- package/dist/tools/context/actions/add-context.d.ts.map +1 -1
- package/dist/tools/context/actions/add-context.js +13 -6
- package/dist/tools/context/actions/add-context.js.map +1 -1
- package/dist/tools/context/actions/has-updates.d.ts.map +1 -1
- package/dist/tools/context/actions/has-updates.js +0 -4
- package/dist/tools/context/actions/has-updates.js.map +1 -1
- package/dist/tools/context/actions/list-contexts.d.ts.map +1 -1
- package/dist/tools/context/actions/list-contexts.js +12 -7
- package/dist/tools/context/actions/list-contexts.js.map +1 -1
- package/dist/tools/context/actions/list.d.ts.map +1 -1
- package/dist/tools/context/actions/list.js +8 -0
- package/dist/tools/context/actions/list.js.map +1 -1
- package/dist/tools/context/actions/search-advanced.d.ts.map +1 -1
- package/dist/tools/context/actions/search-advanced.js +41 -27
- package/dist/tools/context/actions/search-advanced.js.map +1 -1
- package/dist/tools/context/actions/search-layer.d.ts.map +1 -1
- package/dist/tools/context/actions/search-layer.js +8 -0
- package/dist/tools/context/actions/search-layer.js.map +1 -1
- package/dist/tools/context/actions/search-tags.d.ts.map +1 -1
- package/dist/tools/context/actions/search-tags.js +8 -0
- package/dist/tools/context/actions/search-tags.js.map +1 -1
- package/dist/tools/files/actions/check-lock.d.ts.map +1 -1
- package/dist/tools/files/actions/check-lock.js +9 -3
- package/dist/tools/files/actions/check-lock.js.map +1 -1
- package/dist/tools/files/actions/get.d.ts.map +1 -1
- package/dist/tools/files/actions/get.js +18 -13
- package/dist/tools/files/actions/get.js.map +1 -1
- package/dist/tools/files/actions/record-batch.d.ts.map +1 -1
- package/dist/tools/files/actions/record-batch.js +11 -6
- package/dist/tools/files/actions/record-batch.js.map +1 -1
- package/dist/tools/files/actions/record.d.ts.map +1 -1
- package/dist/tools/files/actions/record.js +8 -2
- package/dist/tools/files/actions/record.js.map +1 -1
- package/dist/tools/files/help/example.d.ts.map +1 -1
- package/dist/tools/files/help/example.js +11 -0
- package/dist/tools/files/help/example.js.map +1 -1
- package/dist/tools/files/help/help.d.ts.map +1 -1
- package/dist/tools/files/help/help.js +11 -0
- package/dist/tools/files/help/help.js.map +1 -1
- package/dist/tools/suggest/actions/by-context.d.ts.map +1 -1
- package/dist/tools/suggest/actions/by-context.js +5 -15
- package/dist/tools/suggest/actions/by-context.js.map +1 -1
- package/dist/tools/suggest/actions/by-key.d.ts.map +1 -1
- package/dist/tools/suggest/actions/by-key.js +5 -15
- package/dist/tools/suggest/actions/by-key.js.map +1 -1
- package/dist/tools/suggest/actions/by-tags.d.ts.map +1 -1
- package/dist/tools/suggest/actions/by-tags.js +5 -15
- package/dist/tools/suggest/actions/by-tags.js.map +1 -1
- package/dist/tools/suggest/actions/constraint-by-context.d.ts +1 -1
- package/dist/tools/suggest/actions/constraint-by-context.d.ts.map +1 -1
- package/dist/tools/suggest/actions/constraint-by-context.js +9 -16
- package/dist/tools/suggest/actions/constraint-by-context.js.map +1 -1
- package/dist/tools/suggest/actions/constraint-by-tags.d.ts +1 -1
- package/dist/tools/suggest/actions/constraint-by-tags.d.ts.map +1 -1
- package/dist/tools/suggest/actions/constraint-by-tags.js +11 -17
- package/dist/tools/suggest/actions/constraint-by-tags.js.map +1 -1
- package/dist/tools/suggest/actions/constraint-by-text.d.ts +1 -1
- package/dist/tools/suggest/actions/constraint-by-text.d.ts.map +1 -1
- package/dist/tools/suggest/actions/constraint-by-text.js +6 -15
- package/dist/tools/suggest/actions/constraint-by-text.js.map +1 -1
- package/dist/types/actions.d.ts +1 -1
- package/dist/types/actions.d.ts.map +1 -1
- package/dist/types.d.ts +9 -230
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/action-specs/constraint-specs.d.ts +1 -1
- package/dist/utils/action-specs/constraint-specs.d.ts.map +1 -1
- package/dist/utils/action-specs/constraint-specs.js +22 -5
- package/dist/utils/action-specs/constraint-specs.js.map +1 -1
- package/dist/utils/action-specs/decision-specs.d.ts.map +1 -1
- package/dist/utils/action-specs/decision-specs.js +11 -10
- package/dist/utils/action-specs/decision-specs.js.map +1 -1
- package/dist/utils/action-specs/file-specs.js +4 -4
- package/dist/utils/action-specs/file-specs.js.map +1 -1
- package/dist/utils/hook-queue.d.ts +43 -3
- package/dist/utils/hook-queue.d.ts.map +1 -1
- package/dist/utils/hook-queue.js +326 -32
- package/dist/utils/hook-queue.js.map +1 -1
- package/dist/utils/param-normalizer.d.ts +52 -0
- package/dist/utils/param-normalizer.d.ts.map +1 -0
- package/dist/utils/param-normalizer.js +70 -0
- package/dist/utils/param-normalizer.js.map +1 -0
- package/dist/utils/parameter-validator.d.ts.map +1 -1
- package/dist/utils/parameter-validator.js +2 -0
- package/dist/utils/parameter-validator.js.map +1 -1
- package/dist/utils/suggest-helpers.d.ts +82 -0
- package/dist/utils/suggest-helpers.d.ts.map +1 -0
- package/dist/utils/suggest-helpers.js +93 -0
- package/dist/utils/suggest-helpers.js.map +1 -0
- package/dist/utils/text-truncate.d.ts +13 -0
- package/dist/utils/text-truncate.d.ts.map +1 -0
- package/dist/utils/text-truncate.js +18 -0
- package/dist/utils/text-truncate.js.map +1 -0
- package/dist/utils/validators.d.ts +1 -1
- package/dist/utils/validators.d.ts.map +1 -1
- package/dist/utils/validators.js +1 -1
- package/dist/utils/validators.js.map +1 -1
- package/dist/watcher/base-watcher.d.ts.map +1 -1
- package/dist/watcher/base-watcher.js +4 -3
- package/dist/watcher/base-watcher.js.map +1 -1
- package/dist/watcher/file-watcher.d.ts.map +1 -1
- package/dist/watcher/file-watcher.js +5 -1
- package/dist/watcher/file-watcher.js.map +1 -1
- package/dist/watcher/queue-watcher.d.ts +12 -1
- package/dist/watcher/queue-watcher.d.ts.map +1 -1
- package/dist/watcher/queue-watcher.js +92 -12
- package/dist/watcher/queue-watcher.js.map +1 -1
- package/docs/ADR_CONCEPTS.md +4 -0
- package/docs/HOOKS_GUIDE.md +1 -1
- package/package.json +1 -1
|
@@ -1,83 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Suggest Hook Command
|
|
3
3
|
*
|
|
4
|
-
* PreToolUse hook for Task tool -
|
|
5
|
-
*
|
|
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": {"
|
|
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 {
|
|
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
|
-
*
|
|
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
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
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
|
|
1
|
+
{"version":3,"file":"suggest.js","sourceRoot":"","sources":["../../../src/cli/hooks/suggest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAErF,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,aAAa,EAAE,CAAC;QAEpC,2CAA2C;QAC3C,IAAI,KAAK,CAAC,SAAS,KAAK,MAAM,EAAE,CAAC;YAC/B,YAAY,EAAE,CAAC;YACf,OAAO;QACT,CAAC;QAED,qDAAqD;QACrD,IAAI,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
|
|
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 {
|
|
16
|
-
import { saveCurrentPlan, loadCurrentPlan } from '../../config/global-config.js';
|
|
17
|
-
import {
|
|
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
|
-
/**
|
|
24
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
83
|
+
// Parse frontmatter for plan ID (from tool_input content if available)
|
|
84
|
+
let content;
|
|
57
85
|
if (!existsSync(absolutePath)) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
1
|
+
{"version":3,"file":"track-plan.js","sourceRoot":"","sources":["../../../src/cli/hooks/track-plan.ts"],"names":[],"mappings":"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"}
|
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;
|
|
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
|
-
|
|
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
|
-
#
|
|
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
|
-
//
|
|
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
|
}
|