@pimzino/sgrep 1.3.21 → 1.3.26

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.
@@ -1,70 +1,70 @@
1
- {
2
- "description": "sgrep semantic search hooks - enhances prompts and manages index",
3
- "hooks": {
4
- "UserPromptSubmit": [
5
- {
6
- "hooks": [
7
- {
8
- "type": "command",
9
- "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_enhance.js",
10
- "timeout": 60
11
- }
12
- ]
13
- }
14
- ],
15
- "SessionStart": [
16
- {
17
- "matcher": "startup|resume",
18
- "hooks": [
19
- {
20
- "type": "command",
21
- "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_watch.js",
22
- "timeout": 15
23
- }
24
- ]
25
- },
26
- {
27
- "matcher": "startup|compact",
28
- "hooks": [
29
- {
30
- "type": "command",
31
- "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_project_summary.js",
32
- "timeout": 90
33
- }
34
- ]
35
- },
36
- {
37
- "matcher": "resume|clear",
38
- "hooks": [
39
- {
40
- "type": "command",
41
- "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_context.js",
42
- "timeout": 5
43
- }
44
- ]
45
- }
46
- ],
47
- "SubagentStart": [
48
- {
49
- "hooks": [
50
- {
51
- "type": "command",
52
- "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_context.js",
53
- "timeout": 5
54
- }
55
- ]
56
- }
57
- ],
58
- "SessionEnd": [
59
- {
60
- "hooks": [
61
- {
62
- "type": "command",
63
- "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_watch_kill.js",
64
- "timeout": 10
65
- }
66
- ]
67
- }
68
- ]
69
- }
70
- }
1
+ {
2
+ "description": "sgrep semantic search hooks - enhances prompts and manages index",
3
+ "hooks": {
4
+ "UserPromptSubmit": [
5
+ {
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_enhance.js",
10
+ "timeout": 60
11
+ }
12
+ ]
13
+ }
14
+ ],
15
+ "SessionStart": [
16
+ {
17
+ "matcher": "startup|resume",
18
+ "hooks": [
19
+ {
20
+ "type": "command",
21
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_watch.js",
22
+ "timeout": 15
23
+ }
24
+ ]
25
+ },
26
+ {
27
+ "matcher": "startup|compact",
28
+ "hooks": [
29
+ {
30
+ "type": "command",
31
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_project_summary.js",
32
+ "timeout": 90
33
+ }
34
+ ]
35
+ },
36
+ {
37
+ "matcher": "resume|clear",
38
+ "hooks": [
39
+ {
40
+ "type": "command",
41
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_context.js",
42
+ "timeout": 5
43
+ }
44
+ ]
45
+ }
46
+ ],
47
+ "SubagentStart": [
48
+ {
49
+ "hooks": [
50
+ {
51
+ "type": "command",
52
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_context.js",
53
+ "timeout": 5
54
+ }
55
+ ]
56
+ }
57
+ ],
58
+ "SessionEnd": [
59
+ {
60
+ "hooks": [
61
+ {
62
+ "type": "command",
63
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/sgrep_watch_kill.js",
64
+ "timeout": 10
65
+ }
66
+ ]
67
+ }
68
+ ]
69
+ }
70
+ }
@@ -1,91 +1,107 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * sgrep_context.js - Injects sgrep awareness into Claude Code sessions and subagents
5
- *
6
- * This hook runs on:
7
- * - SessionStart (startup, resume, clear, compact) - main session context
8
- * - SubagentStart - subagent (Task tool) context
9
- *
10
- * Ensures Claude is always aware of the sgrep semantic search tool.
11
- */
12
-
13
- const fs = require("fs");
14
- const path = require("path");
15
- const os = require("os");
16
-
17
- const DEBUG_ENABLED = process.env.SGREP_DEBUG === "1" || process.env.SGREP_DEBUG === "true";
18
- const DEBUG_LOG_FILE = process.env.SGREP_CONTEXT_LOG || path.join(os.tmpdir(), "sgrep-context.log");
19
-
20
- function debugLog(message) {
21
- if (!DEBUG_ENABLED) return;
22
- try {
23
- const dir = path.dirname(DEBUG_LOG_FILE);
24
- if (!fs.existsSync(dir)) {
25
- fs.mkdirSync(dir, { recursive: true });
26
- }
27
- const stamp = new Date().toISOString();
28
- fs.appendFileSync(DEBUG_LOG_FILE, `[${stamp}] ${message}\n`);
29
- } catch (e) {
30
- // Ignore errors
31
- }
32
- }
33
-
34
- function readHookInput() {
35
- return new Promise((resolve) => {
36
- let data = "";
37
- process.stdin.setEncoding("utf8");
38
- process.stdin.on("data", (chunk) => {
39
- data += chunk;
40
- });
41
- process.stdin.on("end", () => {
42
- if (!data.trim()) {
43
- debugLog("No input data received from stdin");
44
- resolve(null);
45
- return;
46
- }
47
- try {
48
- const parsed = JSON.parse(data);
49
- debugLog(`Received hook input: ${JSON.stringify(parsed, null, 2)}`);
50
- resolve(parsed);
51
- } catch (e) {
52
- debugLog(`Failed to decode JSON: ${e.message}`);
53
- resolve(null);
54
- }
55
- });
56
- });
57
- }
58
-
59
- async function main() {
60
- debugLog("\n====================================================");
61
- debugLog("SGREP CONTEXT HOOK TRIGGERED");
62
- debugLog("====================================================");
63
-
64
- const payload = await readHookInput();
65
- if (!payload) {
66
- debugLog("ERROR: No payload received - exiting with error");
67
- process.exit(1);
68
- }
69
-
70
- const eventName = payload.hook_event_name || "unknown";
71
- debugLog(`Hook event: ${eventName}`);
72
-
73
- // Log event-specific info
74
- if (eventName === "SessionStart") {
75
- debugLog(`Session source: ${payload.source || "unknown"}`);
76
- } else if (eventName === "SubagentStart") {
77
- debugLog(`Subagent ID: ${payload.agent_id || "unknown"}`);
78
- debugLog(`Subagent type: ${payload.agent_type || "unknown"}`);
79
- }
80
-
81
- // Same context message for both session and subagents
82
- // Make it directive - tell Claude to USE sgrep, not just that it exists
83
- const sgrepInstruction = `CODEBASE EXPLORATION: Before using Grep, Glob, or Read to explore code, run \`sgrep "your query"\` first via Bash. sgrep uses semantic search to find code by meaning (e.g., \`sgrep "authentication logic"\`, \`sgrep "database queries"\`). For questions about the codebase, use \`sgrep ask "how does X work?"\`. This is faster and more accurate than pattern matching.`;
84
-
85
- debugLog(`Outputting context: ${sgrepInstruction}`);
86
- console.log(sgrepInstruction);
87
- debugLog("====================================================\n");
88
- process.exit(0);
89
- }
90
-
91
- main();
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * sgrep_context.js - Injects sgrep awareness into Claude Code sessions
5
+ *
6
+ * This hook runs on SessionStart (startup, resume, clear, compact) to ensure
7
+ * Claude is always aware of the sgrep semantic search tool after any context reset.
8
+ *
9
+ * Separated from sgrep_watch.js which handles the background watch process.
10
+ */
11
+
12
+ const fs = require("fs");
13
+ const path = require("path");
14
+ const os = require("os");
15
+
16
+ const DEBUG_ENABLED = process.env.SGREP_DEBUG === "1" || process.env.SGREP_DEBUG === "true";
17
+ const DEBUG_LOG_FILE = process.env.SGREP_CONTEXT_LOG || path.join(os.tmpdir(), "sgrep-context.log");
18
+
19
+ function debugLog(message) {
20
+ if (!DEBUG_ENABLED) return;
21
+ try {
22
+ const dir = path.dirname(DEBUG_LOG_FILE);
23
+ if (!fs.existsSync(dir)) {
24
+ fs.mkdirSync(dir, { recursive: true });
25
+ }
26
+ const stamp = new Date().toISOString();
27
+ fs.appendFileSync(DEBUG_LOG_FILE, `[${stamp}] ${message}\n`);
28
+ } catch (e) {
29
+ // Ignore errors
30
+ }
31
+ }
32
+
33
+ function readHookInput() {
34
+ return new Promise((resolve) => {
35
+ let data = "";
36
+ process.stdin.setEncoding("utf8");
37
+ process.stdin.on("data", (chunk) => {
38
+ data += chunk;
39
+ });
40
+ process.stdin.on("end", () => {
41
+ if (!data.trim()) {
42
+ debugLog("No input data received from stdin");
43
+ resolve(null);
44
+ return;
45
+ }
46
+ try {
47
+ const parsed = JSON.parse(data);
48
+ debugLog(`Received hook input: ${JSON.stringify(parsed, null, 2)}`);
49
+ resolve(parsed);
50
+ } catch (e) {
51
+ debugLog(`Failed to decode JSON: ${e.message}`);
52
+ resolve(null);
53
+ }
54
+ });
55
+ });
56
+ }
57
+
58
+ async function main() {
59
+ debugLog("\n====================================================");
60
+ debugLog("SGREP CONTEXT HOOK TRIGGERED");
61
+ debugLog("====================================================");
62
+
63
+ const payload = await readHookInput();
64
+ if (!payload) {
65
+ debugLog("ERROR: No payload received - exiting with error");
66
+ process.exit(1);
67
+ }
68
+
69
+ const source = payload.source || "unknown";
70
+ debugLog(`Session source: ${source}`);
71
+
72
+ // Output the sgrep awareness context with XML structure for better model compliance
73
+ const sgrepInstruction = `
74
+ <sgrep-skill-instruction>
75
+ <priority>CRITICAL - Execute before other codebase exploration tools</priority>
76
+ <action>INVOKE the /sgrep skill using the Skill tool at the START of every session</action>
77
+ <requirement>
78
+ You MUST use sgrep as your PRIMARY tool for codebase exploration and understanding.
79
+ Before using Grep, Glob, Read, or Task(Explore), you MUST first try sgrep.
80
+ </requirement>
81
+ <commands>
82
+ <command name="search">sgrep "natural language query" - Find code by meaning/functionality</command>
83
+ <command name="ask">sgrep ask "question" - Get explanations about the codebase</command>
84
+ </commands>
85
+ <use-cases>
86
+ - Finding code by functionality (e.g., "authentication handling", "database queries")
87
+ - Understanding how features work
88
+ - Locating related files across the codebase
89
+ - Exploring unfamiliar architecture
90
+ </use-cases>
91
+ <advantage>sgrep searches by MEANING, not text patterns - far more effective than grep/glob for understanding code</advantage>
92
+ </sgrep-skill-instruction>`.trim();
93
+
94
+ const response = {
95
+ hookSpecificOutput: {
96
+ hookEventName: "SessionStart",
97
+ additionalContext: sgrepInstruction,
98
+ },
99
+ };
100
+
101
+ debugLog(`Outputting context: ${JSON.stringify(response, null, 2)}`);
102
+ console.log(JSON.stringify(response));
103
+ debugLog("====================================================\n");
104
+ process.exit(0);
105
+ }
106
+
107
+ main();