pi-shazam 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/filter.d.ts +2 -0
- package/dist/core/filter.d.ts.map +1 -1
- package/dist/core/filter.js +57 -1
- package/dist/core/filter.js.map +1 -1
- package/dist/core/treesitter-queries.d.ts.map +1 -1
- package/dist/core/treesitter-queries.js +1 -0
- package/dist/core/treesitter-queries.js.map +1 -1
- package/dist/hooks/failure-recovery.d.ts +21 -0
- package/dist/hooks/failure-recovery.d.ts.map +1 -0
- package/dist/hooks/failure-recovery.js +124 -0
- package/dist/hooks/failure-recovery.js.map +1 -0
- package/dist/hooks/safety.d.ts +20 -0
- package/dist/hooks/safety.d.ts.map +1 -0
- package/dist/hooks/safety.js +212 -0
- package/dist/hooks/safety.js.map +1 -0
- package/dist/hooks/shazam-guide.d.ts +6 -1
- package/dist/hooks/shazam-guide.d.ts.map +1 -1
- package/dist/hooks/shazam-guide.js +92 -4
- package/dist/hooks/shazam-guide.js.map +1 -1
- package/dist/hooks/stop-verify.d.ts +20 -0
- package/dist/hooks/stop-verify.d.ts.map +1 -0
- package/dist/hooks/stop-verify.js +85 -0
- package/dist/hooks/stop-verify.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/entry.js +1 -1
- package/dist/tools/definitions.js +1 -1
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/find_tests.d.ts.map +1 -1
- package/dist/tools/find_tests.js +35 -14
- package/dist/tools/find_tests.js.map +1 -1
- package/dist/tools/fix.d.ts +1 -1
- package/dist/tools/fix.d.ts.map +1 -1
- package/dist/tools/fix.js +83 -0
- package/dist/tools/fix.js.map +1 -1
- package/dist/tools/hotspots.d.ts.map +1 -1
- package/dist/tools/hotspots.js +26 -1
- package/dist/tools/hotspots.js.map +1 -1
- package/dist/tools/overview.d.ts.map +1 -1
- package/dist/tools/overview.js +116 -1
- package/dist/tools/overview.js.map +1 -1
- package/dist/tools/rename_symbol.d.ts.map +1 -1
- package/dist/tools/rename_symbol.js +93 -15
- package/dist/tools/rename_symbol.js.map +1 -1
- package/package.json +1 -1
package/dist/core/filter.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export declare function isNonSourceFile(file: string): boolean;
|
|
|
29
29
|
* - Test files
|
|
30
30
|
* - Registration functions (register*, createTool) called by MCP/extension frameworks
|
|
31
31
|
* - Exported symbols in registration/entry-point files (called externally)
|
|
32
|
+
* - Language-specific entry point symbols (dunder methods, main, traits)
|
|
33
|
+
* - Framework handler patterns (handle_*, on_*, middleware, *_handler)
|
|
32
34
|
*
|
|
33
35
|
* Returns structured result with separate lists for internal and exported orphans.
|
|
34
36
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../core/filter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAoB5C;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,aA4BpB,CAAC;AAEH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../core/filter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAoB5C;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,aA4BpB,CAAC;AAEH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAwED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG;IAC9C,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IACvF,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACvE,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACvE,CAoCA"}
|
package/dist/core/filter.js
CHANGED
|
@@ -83,6 +83,54 @@ function isRegistrationSymbol(name) {
|
|
|
83
83
|
name === "execute" ||
|
|
84
84
|
name === "handler");
|
|
85
85
|
}
|
|
86
|
+
function isEntryPointSymbol(name, kind) {
|
|
87
|
+
// Python entry points
|
|
88
|
+
if (name === "__init__" ||
|
|
89
|
+
name === "__str__" ||
|
|
90
|
+
name === "__repr__" ||
|
|
91
|
+
name === "__len__" ||
|
|
92
|
+
name === "__iter__" ||
|
|
93
|
+
name === "__getitem__" ||
|
|
94
|
+
name === "__setitem__" ||
|
|
95
|
+
name === "__call__" ||
|
|
96
|
+
name === "__enter__" ||
|
|
97
|
+
name === "__exit__" ||
|
|
98
|
+
name === "__aenter__" ||
|
|
99
|
+
name === "__aexit__" ||
|
|
100
|
+
name === "__anext__" ||
|
|
101
|
+
name === "__aiter__" ||
|
|
102
|
+
name === "__main__") {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
// Rust entry points
|
|
106
|
+
if (name === "main" && kind === "function")
|
|
107
|
+
return true;
|
|
108
|
+
if (name === "Default" && kind === "trait")
|
|
109
|
+
return true;
|
|
110
|
+
if (name === "Drop" && kind === "trait")
|
|
111
|
+
return true;
|
|
112
|
+
// Go entry points
|
|
113
|
+
if (name === "main" && kind === "function")
|
|
114
|
+
return true;
|
|
115
|
+
if (name === "init" && kind === "function")
|
|
116
|
+
return true;
|
|
117
|
+
// Common framework entry points
|
|
118
|
+
if (name.startsWith("test_") || name.startsWith("Test"))
|
|
119
|
+
return true;
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
function isFrameworkHandler(name) {
|
|
123
|
+
// Flask/FastAPI/Django route handlers and middleware
|
|
124
|
+
if (name.startsWith("test_") || name.startsWith("Test"))
|
|
125
|
+
return true;
|
|
126
|
+
if (name.startsWith("handle_") || name.startsWith("on_"))
|
|
127
|
+
return true;
|
|
128
|
+
if (name.startsWith("middleware"))
|
|
129
|
+
return true;
|
|
130
|
+
if (name.endsWith("_handler") || name.endsWith("Handler"))
|
|
131
|
+
return true;
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
86
134
|
/**
|
|
87
135
|
* Shared orphan symbol detection.
|
|
88
136
|
*
|
|
@@ -97,6 +145,8 @@ function isRegistrationSymbol(name) {
|
|
|
97
145
|
* - Test files
|
|
98
146
|
* - Registration functions (register*, createTool) called by MCP/extension frameworks
|
|
99
147
|
* - Exported symbols in registration/entry-point files (called externally)
|
|
148
|
+
* - Language-specific entry point symbols (dunder methods, main, traits)
|
|
149
|
+
* - Framework handler patterns (handle_*, on_*, middleware, *_handler)
|
|
100
150
|
*
|
|
101
151
|
* Returns structured result with separate lists for internal and exported orphans.
|
|
102
152
|
*/
|
|
@@ -116,11 +166,17 @@ export function findOrphans(graph) {
|
|
|
116
166
|
if (sym.kind === "anonymous_function")
|
|
117
167
|
continue;
|
|
118
168
|
// Skip test files
|
|
119
|
-
if (sym.file.includes("tests/") || sym.file.includes(".test."))
|
|
169
|
+
if (sym.file.includes("tests/") || sym.file.includes(".test.") || sym.file.includes("test_") || sym.file.includes("_test.") || sym.file.includes("/test/"))
|
|
120
170
|
continue;
|
|
121
171
|
// Skip registration functions called dynamically by frameworks
|
|
122
172
|
if (isRegistrationSymbol(sym.name))
|
|
123
173
|
continue;
|
|
174
|
+
// Skip language-specific entry point symbols
|
|
175
|
+
if (isEntryPointSymbol(sym.name, sym.kind))
|
|
176
|
+
continue;
|
|
177
|
+
// Skip framework handler patterns
|
|
178
|
+
if (isFrameworkHandler(sym.name))
|
|
179
|
+
continue;
|
|
124
180
|
// Skip exported symbols in registration/entry-point files
|
|
125
181
|
if (sym.visibility === "exported" && isRegistrationFile(sym.file))
|
|
126
182
|
continue;
|
package/dist/core/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../core/filter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;;GAQG;AACH,MAAM,wBAAwB,GAAsB;IACnD,qBAAqB;IACrB,iBAAiB;IACjB,8BAA8B;IAC9B,gBAAgB;IAChB,UAAU;IACV,SAAS;CACT,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IAChC,cAAc;IACd,kBAAkB;IAClB,QAAQ;IACR,MAAM;IACN,OAAO;IACP,KAAK;IACL,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,YAAY;IACZ,YAAY;IACZ,QAAQ;IACR,aAAa;IACb,UAAU;IACV,aAAa;IACb,KAAK;IACL,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;IACR,SAAS;IACT,OAAO;IACP,OAAO;IACP,SAAS;CACT,CAAC,CAAC;AAEH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC3C,OAAO,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;GAGG;AACH,SAAS,kBAAkB,CAAC,IAAY;IACvC,OAAO,CACN,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC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AAG,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;YACpC,IAAI,UAAU,EAAE,CAAC;gBAChB,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACP,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AACpC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treesitter-queries.d.ts","sourceRoot":"","sources":["../../core/treesitter-queries.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,SAAS;IACzB,CAAC,IAAI,EAAE,MAAM,GAAG;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;CACF;AAED,eAAO,MAAM,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"treesitter-queries.d.ts","sourceRoot":"","sources":["../../core/treesitter-queries.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,SAAS;IACzB,CAAC,IAAI,EAAE,MAAM,GAAG;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;CACF;AAED,eAAO,MAAM,OAAO,EAAE,SAqMrB,CAAC"}
|
|
@@ -51,6 +51,7 @@ export const QUERIES = {
|
|
|
51
51
|
function: `\
|
|
52
52
|
(function_declaration name: (identifier) @name) @definition.function
|
|
53
53
|
(variable_declarator name: (identifier) @name value: (arrow_function)) @definition.function
|
|
54
|
+
(variable_declarator name: (identifier) @name value: (call_expression function: (identifier) @_fn (#match? @_fn "^(createContext|create|use[A-Z])"))) @definition.function
|
|
54
55
|
(method_definition name: (property_identifier) @name) @definition.method
|
|
55
56
|
`,
|
|
56
57
|
class: `\
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treesitter-queries.js","sourceRoot":"","sources":["../../core/treesitter-queries.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,MAAM,CAAC,MAAM,OAAO,GAAc;IACjC,MAAM,EAAE;QACP,QAAQ,EAAE;;;;;CAKX;QACC,KAAK,EAAE;;;CAGR;QACC,MAAM,EAAE;;;;;CAKT;QACC,IAAI,EAAE;;;CAGP;KACC;IACD,UAAU,EAAE;QACX,QAAQ,EAAE;;;;;CAKX;QACC,KAAK,EAAE;;CAER;QACC,MAAM,EAAE;;;;CAIT;QACC,IAAI,EAAE;;;CAGP;KACC;IACD,UAAU,EAAE;QACX,QAAQ,EAAE
|
|
1
|
+
{"version":3,"file":"treesitter-queries.js","sourceRoot":"","sources":["../../core/treesitter-queries.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,MAAM,CAAC,MAAM,OAAO,GAAc;IACjC,MAAM,EAAE;QACP,QAAQ,EAAE;;;;;CAKX;QACC,KAAK,EAAE;;;CAGR;QACC,MAAM,EAAE;;;;;CAKT;QACC,IAAI,EAAE;;;CAGP;KACC;IACD,UAAU,EAAE;QACX,QAAQ,EAAE;;;;;CAKX;QACC,KAAK,EAAE;;CAER;QACC,MAAM,EAAE;;;;CAIT;QACC,IAAI,EAAE;;;CAGP;KACC;IACD,UAAU,EAAE;QACX,QAAQ,EAAE;;;;;CAKX;QACC,KAAK,EAAE;;;;;CAKR;QACC,MAAM,EAAE;;;;CAIT;QACC,IAAI,EAAE;;;CAGP;KACC;IACD,EAAE,EAAE;QACH,QAAQ,EAAE;;;CAGX;QACC,KAAK,EAAE;;;CAGR;QACC,MAAM,EAAE;;CAET;QACC,IAAI,EAAE;;;CAGP;KACC;IACD,IAAI,EAAE;QACL,QAAQ,EAAE;;;CAGX;QACC,KAAK,EAAE;;;;;;;CAOR;QACC,MAAM,EAAE;;;;;CAKT;QACC,IAAI,EAAE;;;;CAIP;KACC;IACD,CAAC,EAAE;QACF,QAAQ,EAAE;;CAEX;QACC,KAAK,EAAE;;;;CAIR;QACC,MAAM,EAAE;;CAET;QACC,IAAI,EAAE;;CAEP;KACC;IACD,GAAG,EAAE;QACJ,QAAQ,EAAE;;CAEX;QACC,KAAK,EAAE;;;;CAIR;QACC,MAAM,EAAE;;CAET;QACC,IAAI,EAAE;;CAEP;KACC;IACD,IAAI,EAAE;QACL,QAAQ,EAAE;;;CAGX;QACC,KAAK,EAAE;;;;CAIR;QACC,MAAM,EAAE;;;CAGT;QACC,IAAI,EAAE;;CAEP;KACC;IACD,OAAO,EAAE;QACR,QAAQ,EAAE;;;CAGX;QACC,KAAK,EAAE;;;;;CAKR;QACC,MAAM,EAAE;;CAET;QACC,IAAI,EAAE;;;CAGP;KACC;IACD,IAAI,EAAE;QACL,QAAQ,EAAE;;;CAGX;QACC,KAAK,EAAE;;;CAGR;QACC,MAAM,EAAE;;;CAGT;QACC,IAAI,EAAE;;CAEP;KACC;IACD,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;CACR,CAAC;AAEF,0CAA0C;AAC1C,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,YAAY,CAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-shazam hooks/failure-recovery — Detect consecutive failures and suggest alternatives.
|
|
3
|
+
*
|
|
4
|
+
* When the LLM repeatedly fails at the same task, this hook:
|
|
5
|
+
* 1. Tracks failure patterns per tool
|
|
6
|
+
* 2. After 3 consecutive failures, suggests a different approach
|
|
7
|
+
* 3. After 5 consecutive failures, strongly suggests reorienting with shazam_overview
|
|
8
|
+
*
|
|
9
|
+
* This prevents LLM loops where it keeps trying the same failing approach.
|
|
10
|
+
*
|
|
11
|
+
* Uses tool_result event with isError flag.
|
|
12
|
+
*/
|
|
13
|
+
import type { ExtensionAPI } from "../types/pi-extension.js";
|
|
14
|
+
/**
|
|
15
|
+
* Register the failure-recovery hook.
|
|
16
|
+
*
|
|
17
|
+
* On tool_result with isError, tracks failures and suggests alternatives
|
|
18
|
+
* after repeated failures.
|
|
19
|
+
*/
|
|
20
|
+
export declare function registerFailureRecovery(pi: ExtensionAPI): void;
|
|
21
|
+
//# sourceMappingURL=failure-recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-recovery.d.ts","sourceRoot":"","sources":["../../hooks/failure-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AA4F7D;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CA2B9D"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-shazam hooks/failure-recovery — Detect consecutive failures and suggest alternatives.
|
|
3
|
+
*
|
|
4
|
+
* When the LLM repeatedly fails at the same task, this hook:
|
|
5
|
+
* 1. Tracks failure patterns per tool
|
|
6
|
+
* 2. After 3 consecutive failures, suggests a different approach
|
|
7
|
+
* 3. After 5 consecutive failures, strongly suggests reorienting with shazam_overview
|
|
8
|
+
*
|
|
9
|
+
* This prevents LLM loops where it keeps trying the same failing approach.
|
|
10
|
+
*
|
|
11
|
+
* Uses tool_result event with isError flag.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Failure tracker: tool name -> consecutive failure count.
|
|
15
|
+
*/
|
|
16
|
+
const _failureCounts = new Map();
|
|
17
|
+
/**
|
|
18
|
+
* Track which tools have been warned about (to avoid repeated warnings).
|
|
19
|
+
*/
|
|
20
|
+
const _warnedTools = new Set();
|
|
21
|
+
/**
|
|
22
|
+
* Reset failure count for a tool (called on success).
|
|
23
|
+
*/
|
|
24
|
+
function resetFailure(toolName) {
|
|
25
|
+
_failureCounts.delete(toolName);
|
|
26
|
+
_warnedTools.delete(toolName);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Increment failure count and return new count.
|
|
30
|
+
*/
|
|
31
|
+
function incrementFailure(toolName) {
|
|
32
|
+
const current = _failureCounts.get(toolName) || 0;
|
|
33
|
+
const newCount = current + 1;
|
|
34
|
+
_failureCounts.set(toolName, newCount);
|
|
35
|
+
return newCount;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get suggestion based on failure count and tool type.
|
|
39
|
+
*/
|
|
40
|
+
function getSuggestion(toolName, failCount) {
|
|
41
|
+
// After 5 failures: strong intervention
|
|
42
|
+
if (failCount >= 5) {
|
|
43
|
+
return [
|
|
44
|
+
"[shazam] You've been stuck for a while.",
|
|
45
|
+
"",
|
|
46
|
+
"Consider:",
|
|
47
|
+
"1. Run `shazam_overview` to reorient yourself",
|
|
48
|
+
"2. Simplify the current task",
|
|
49
|
+
"3. Ask the user for clarification",
|
|
50
|
+
].join("\n");
|
|
51
|
+
}
|
|
52
|
+
// After 3 failures: suggest alternatives
|
|
53
|
+
if (failCount >= 3 && !_warnedTools.has(toolName)) {
|
|
54
|
+
_warnedTools.add(toolName);
|
|
55
|
+
switch (toolName) {
|
|
56
|
+
case "bash":
|
|
57
|
+
return [
|
|
58
|
+
"[shazam] Bash command failed 3x consecutively.",
|
|
59
|
+
"",
|
|
60
|
+
"Try a different approach:",
|
|
61
|
+
"- Use `shazam_codesearch` instead of grep/find",
|
|
62
|
+
"- Use `shazam_file_detail` to understand file structure first",
|
|
63
|
+
"- Break the command into smaller steps",
|
|
64
|
+
].join("\n");
|
|
65
|
+
case "edit":
|
|
66
|
+
return [
|
|
67
|
+
"[shazam] Edit failed 3x consecutively.",
|
|
68
|
+
"",
|
|
69
|
+
"Try:",
|
|
70
|
+
"- Use `shazam_file_detail` to see the current file structure",
|
|
71
|
+
"- Use `shazam_symbol` to understand the symbol you're editing",
|
|
72
|
+
"- Read the file first with `read` to see current content",
|
|
73
|
+
].join("\n");
|
|
74
|
+
case "write":
|
|
75
|
+
return [
|
|
76
|
+
"[shazam] Write failed 3x consecutively.",
|
|
77
|
+
"",
|
|
78
|
+
"Try:",
|
|
79
|
+
"- Check if the directory exists",
|
|
80
|
+
"- Use `shazam_impact` to check if the file is referenced elsewhere",
|
|
81
|
+
].join("\n");
|
|
82
|
+
default:
|
|
83
|
+
return [
|
|
84
|
+
`[shazam] ${toolName} failed 3x consecutively.`,
|
|
85
|
+
"",
|
|
86
|
+
"Consider running `shazam_overview` to reorient.",
|
|
87
|
+
].join("\n");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Register the failure-recovery hook.
|
|
94
|
+
*
|
|
95
|
+
* On tool_result with isError, tracks failures and suggests alternatives
|
|
96
|
+
* after repeated failures.
|
|
97
|
+
*/
|
|
98
|
+
export function registerFailureRecovery(pi) {
|
|
99
|
+
pi.on("tool_result", (event, _ctx) => {
|
|
100
|
+
const toolName = event.toolName;
|
|
101
|
+
if (event.isError) {
|
|
102
|
+
// Track failure
|
|
103
|
+
const failCount = incrementFailure(toolName);
|
|
104
|
+
const suggestion = getSuggestion(toolName, failCount);
|
|
105
|
+
if (suggestion) {
|
|
106
|
+
pi.sendMessage({
|
|
107
|
+
customType: "shazam-failure-recovery",
|
|
108
|
+
content: suggestion,
|
|
109
|
+
display: false, // Inject into context, not UI
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// Success — reset failure count
|
|
115
|
+
resetFailure(toolName);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
// Reset all counts on session start
|
|
119
|
+
pi.on("session_start", () => {
|
|
120
|
+
_failureCounts.clear();
|
|
121
|
+
_warnedTools.clear();
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=failure-recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-recovery.js","sourceRoot":"","sources":["../../hooks/failure-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH;;GAEG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEjD;;GAEG;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;AAEvC;;GAEG;AACH,SAAS,YAAY,CAAC,QAAgB;IACrC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB,CAAC,QAAgB;IACzC,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,OAAO,GAAG,CAAC,CAAC;IAC7B,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACvC,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,QAAgB,EAAE,SAAiB;IACzD,wCAAwC;IACxC,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO;YACN,yCAAyC;YACzC,EAAE;YACF,WAAW;YACX,+CAA+C;YAC/C,8BAA8B;YAC9B,mCAAmC;SACnC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAED,yCAAyC;IACzC,IAAI,SAAS,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnD,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAE3B,QAAQ,QAAQ,EAAE,CAAC;YAClB,KA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AAY,CAAC,QAAQ,CAAC,CAAC;QACxB,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,oCAAoC;IACpC,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,GAAG,EAAE;QAC3B,cAAc,CAAC,KAAK,EAAE,CAAC;QACvB,YAAY,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-shazam hooks/safety — Safety gate for bash commands.
|
|
3
|
+
*
|
|
4
|
+
* Provides two safety features:
|
|
5
|
+
* 1. Destructive command detection — shows confirmation dialog for dangerous commands
|
|
6
|
+
* 2. Pre-commit gate — blocks git commit if shazam_verify was not run recently
|
|
7
|
+
*
|
|
8
|
+
* Uses Pi's ctx.ui.confirm() for interactive confirmation (better than Kimi Code's
|
|
9
|
+
* exit 2 blocking, which gives user no choice).
|
|
10
|
+
*/
|
|
11
|
+
import type { ExtensionAPI } from "../types/pi-extension.js";
|
|
12
|
+
/**
|
|
13
|
+
* Register the safety hooks.
|
|
14
|
+
*
|
|
15
|
+
* Intercepts bash tool_call events to:
|
|
16
|
+
* 1. Show confirmation dialog for destructive commands
|
|
17
|
+
* 2. Block git commit if shazam_verify was not run
|
|
18
|
+
*/
|
|
19
|
+
export declare function registerSafetyHooks(pi: ExtensionAPI): void;
|
|
20
|
+
//# sourceMappingURL=safety.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safety.d.ts","sourceRoot":"","sources":["../../hooks/safety.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAmH7D;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAoG1D"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-shazam hooks/safety — Safety gate for bash commands.
|
|
3
|
+
*
|
|
4
|
+
* Provides two safety features:
|
|
5
|
+
* 1. Destructive command detection — shows confirmation dialog for dangerous commands
|
|
6
|
+
* 2. Pre-commit gate — blocks git commit if shazam_verify was not run recently
|
|
7
|
+
*
|
|
8
|
+
* Uses Pi's ctx.ui.confirm() for interactive confirmation (better than Kimi Code's
|
|
9
|
+
* exit 2 blocking, which gives user no choice).
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* High-risk patterns that should always trigger confirmation.
|
|
13
|
+
* Matched as substrings in the command.
|
|
14
|
+
*/
|
|
15
|
+
const HIGH_RISK_PATTERNS = [
|
|
16
|
+
"rm -rf",
|
|
17
|
+
"rm -fr",
|
|
18
|
+
"rm --recursive",
|
|
19
|
+
"dd if=",
|
|
20
|
+
"mkfs",
|
|
21
|
+
"mkswap",
|
|
22
|
+
"fdisk",
|
|
23
|
+
"parted",
|
|
24
|
+
"sfdisk",
|
|
25
|
+
":(){ :|:& };:", // fork bomb
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* Medium-risk patterns that trigger confirmation.
|
|
29
|
+
*/
|
|
30
|
+
const MEDIUM_RISK_PATTERNS = [
|
|
31
|
+
"chmod -R 777",
|
|
32
|
+
"chmod 777 /",
|
|
33
|
+
"chown -R",
|
|
34
|
+
"> /dev/sd",
|
|
35
|
+
"> /dev/nvme",
|
|
36
|
+
"> /dev/mmcblk",
|
|
37
|
+
"pvcreate",
|
|
38
|
+
"vgcreate",
|
|
39
|
+
"lvcreate",
|
|
40
|
+
"iptables -F",
|
|
41
|
+
"iptables -P",
|
|
42
|
+
"rm -r /",
|
|
43
|
+
];
|
|
44
|
+
/**
|
|
45
|
+
* Git commit pattern for pre-commit gate.
|
|
46
|
+
*/
|
|
47
|
+
const GIT_COMMIT_PATTERN = /git\s+commit/;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a command matches any destructive pattern.
|
|
50
|
+
* Returns the risk level and matched pattern, or null if safe.
|
|
51
|
+
*/
|
|
52
|
+
function detectDestructiveCommand(cmd) {
|
|
53
|
+
const lower = cmd.toLowerCase();
|
|
54
|
+
for (const pattern of HIGH_RISK_PATTERNS) {
|
|
55
|
+
if (lower.includes(pattern.toLowerCase())) {
|
|
56
|
+
return { level: "HIGH", pattern };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (const pattern of MEDIUM_RISK_PATTERNS) {
|
|
60
|
+
if (lower.includes(pattern.toLowerCase())) {
|
|
61
|
+
return { level: "MEDIUM", pattern };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Check for rm targeting root
|
|
65
|
+
if (/^rm\s+-(rf|fr|r)\s+\/(\s|$)/.test(cmd)) {
|
|
66
|
+
return { level: "HIGH", pattern: "rm -rf /" };
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if shazam_verify was called recently in this session.
|
|
72
|
+
* Uses the tool-logger's audit log or checks in-memory state.
|
|
73
|
+
*/
|
|
74
|
+
function hasRecentVerify() {
|
|
75
|
+
// Check if shazam_verify appears in recent tool results
|
|
76
|
+
// We can't directly access the tool history, so we check the audit log
|
|
77
|
+
try {
|
|
78
|
+
const { readFileSync, statSync } = require("node:fs");
|
|
79
|
+
const { join } = require("node:path");
|
|
80
|
+
const { homedir } = require("node:os");
|
|
81
|
+
const logFile = join(homedir(), ".pi", "hooks", "audit", "shazam-calls.log");
|
|
82
|
+
// Check if log file exists and was modified recently (within 5 minutes)
|
|
83
|
+
try {
|
|
84
|
+
const stat = statSync(logFile);
|
|
85
|
+
const fiveMinutesAgo = Date.now() - 5 * 60 * 1000;
|
|
86
|
+
if (stat.mtimeMs < fiveMinutesAgo) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return false; // File doesn't exist
|
|
92
|
+
}
|
|
93
|
+
// Read last 20 lines to check for recent shazam_verify calls
|
|
94
|
+
const content = readFileSync(logFile, "utf-8");
|
|
95
|
+
const lines = content.trim().split("\n").slice(-20);
|
|
96
|
+
for (const line of lines) {
|
|
97
|
+
try {
|
|
98
|
+
const entry = JSON.parse(line);
|
|
99
|
+
if (entry.tool === "shazam_verify" && entry.event === "result") {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Skip malformed lines
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// If we can't check, assume verify was not run
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Register the safety hooks.
|
|
115
|
+
*
|
|
116
|
+
* Intercepts bash tool_call events to:
|
|
117
|
+
* 1. Show confirmation dialog for destructive commands
|
|
118
|
+
* 2. Block git commit if shazam_verify was not run
|
|
119
|
+
*/
|
|
120
|
+
export function registerSafetyHooks(pi) {
|
|
121
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
122
|
+
// Only intercept bash commands
|
|
123
|
+
if (event.toolName !== "bash")
|
|
124
|
+
return;
|
|
125
|
+
const input = "input" in event ? event.input : {};
|
|
126
|
+
const cmd = input.command;
|
|
127
|
+
if (!cmd || typeof cmd !== "string")
|
|
128
|
+
return;
|
|
129
|
+
// ── Check 1: Destructive command detection ──
|
|
130
|
+
const destructive = detectDestructiveCommand(cmd);
|
|
131
|
+
if (destructive) {
|
|
132
|
+
const emoji = destructive.level === "HIGH" ? "!!!" : "!";
|
|
133
|
+
const message = [
|
|
134
|
+
`[${emoji}] Destructive command detected [${emoji}]`,
|
|
135
|
+
"",
|
|
136
|
+
`Risk level: ${destructive.level}`,
|
|
137
|
+
`Pattern: ${destructive.pattern}`,
|
|
138
|
+
`Command: ${cmd.slice(0, 200)}${cmd.length > 200 ? "..." : ""}`,
|
|
139
|
+
"",
|
|
140
|
+
"Do you want to continue?",
|
|
141
|
+
].join("\n");
|
|
142
|
+
try {
|
|
143
|
+
const confirmed = await ctx.ui.confirm("Safety Warning", message);
|
|
144
|
+
if (!confirmed) {
|
|
145
|
+
return {
|
|
146
|
+
block: true,
|
|
147
|
+
reason: `Command blocked by safety check: ${destructive.pattern}`,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
// User confirmed, allow the command
|
|
151
|
+
ctx.ui.notify?.(`Proceeding with ${destructive.level}-risk command...`, "warning");
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// If confirm dialog fails (e.g., non-interactive mode), block high-risk
|
|
155
|
+
if (destructive.level === "HIGH") {
|
|
156
|
+
return {
|
|
157
|
+
block: true,
|
|
158
|
+
reason: `High-risk command blocked in non-interactive mode: ${destructive.pattern}`,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
// Allow medium-risk in non-interactive mode
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
// ── Check 2: Pre-commit gate ──
|
|
166
|
+
if (GIT_COMMIT_PATTERN.test(cmd)) {
|
|
167
|
+
// Skip if --no-verify flag is present
|
|
168
|
+
if (cmd.includes("--no-verify")) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
// Check if shazam_verify was run recently
|
|
172
|
+
if (!hasRecentVerify()) {
|
|
173
|
+
try {
|
|
174
|
+
const choice = await ctx.ui.select("Pre-Commit Gate", [
|
|
175
|
+
{
|
|
176
|
+
label: "Run shazam_verify first (Recommended)",
|
|
177
|
+
description: "Verify code before committing",
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
label: "Skip verification",
|
|
181
|
+
description: "Commit without verification",
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
label: "Cancel commit",
|
|
185
|
+
description: "Don't commit yet",
|
|
186
|
+
},
|
|
187
|
+
]);
|
|
188
|
+
if (choice === "Run shazam_verify first (Recommended)") {
|
|
189
|
+
// Block the commit and suggest running verify
|
|
190
|
+
return {
|
|
191
|
+
block: true,
|
|
192
|
+
reason: "Run shazam_verify first, then try committing again.",
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
else if (choice === "Cancel commit") {
|
|
196
|
+
return {
|
|
197
|
+
block: true,
|
|
198
|
+
reason: "Commit cancelled by user.",
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
// "Skip verification" — allow the commit
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// Non-interactive mode: just warn but allow
|
|
205
|
+
ctx.ui.notify?.("[shazam] Tip: Run shazam_verify before committing to catch errors early.", "warning");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=safety.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safety.js","sourceRoot":"","sources":["../../hooks/safety.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;GAGG;AACH,MAAM,kBAAkB,GAAG;IAC1B,QAAQ;IACR,QAAQ;IACR,gBAAgB;IAChB,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,eAAe,EAAE,YAAY;CAC7B,CAAC;AAEF;;GAEG;AACH,MAAM,oBAAoB,GAAG;IAC5B,cAAc;IACd,aAAa;IACb,UAAU;IACV,WAAW;IACX,aAAa;IACb,eAAe;IACf,UAAU;IACV,UAAU;IACV,UAAU;IACV,aAAa;IACb,aAAa;IACb,SAAS;CACT,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAE1C;;;GAGG;AACH,SAAS,wBAAwB,CAAC,GAAW;IAC5C,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IAEhC,KAAK,MAAM,OAAO,IAAI,kBAAkB,EAAE,CAAC;QAC1C,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAA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,aAAa,CAAC,EAAE,CAAC;gBACjC,OAAO;YACR,CAAC;YAED,0CAA0C;YAC1C,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC;gBACxB,IAAI,CAAC;oBACJ,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,iBAAiB,EAAE;wBACrD;4BACC,KAAK,EAAE,uCAAuC;4BAC9C,WAAW,EAAE,+BAA+B;yBAC5C;wBACD;4BACC,KAAK,EAAE,mBAAmB;4BAC1B,WAAW,EAAE,6BAA6B;yBAC1C;wBACD;4BACC,KAAK,EAAE,eAAe;4BACtB,WAAW,EAAE,kBAAkB;yBAC/B;qBACD,CAAC,CAAC;oBAEH,IAAI,MAAM,KAAK,uCAAuC,EAAE,CAAC;wBACxD,8CAA8C;wBAC9C,OAAO;4BACN,KAAK,EAAE,IAAI;4BACX,MAAM,EAAE,qDAAqD;yBAC7D,CAAC;oBACH,CAAC;yBAAM,IAAI,MAAM,KAAK,eAAe,EAAE,CAAC;wBACvC,OAAO;4BACN,KAAK,EAAE,IAAI;4BACX,MAAM,EAAE,2BAA2B;yBACnC,CAAC;oBACH,CAAC;oBACD,yCAAyC;gBAC1C,CAAC;gBAAC,MAAM,CAAC;oBACR,4CAA4C;oBAC5C,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CACd,0EAA0E,EAC1E,SAAS,CACT,CAAC;gBACH,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO;IACR,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Injects context reminders at key lifecycle points:
|
|
5
5
|
* - before_agent_start: inject shazam tool list into system prompt
|
|
6
|
-
* - tool_result (write/edit): suggest running shazam_verify
|
|
6
|
+
* - tool_result (write/edit): auto-format + suggest running shazam_verify
|
|
7
7
|
* - tool_result (shazam_symbol): suggest call_chain when symbol has many callers
|
|
8
8
|
* - tool_call (search/grep/find): suggest shazam_codesearch
|
|
9
9
|
* - tool_call (write/edit): suggest shazam_impact for multi-file edits
|
|
10
|
+
*
|
|
11
|
+
* Auto-format feature (v0.6.4):
|
|
12
|
+
* - After write/edit, detect file type and run native formatter
|
|
13
|
+
* - Supported: ruff (Python), prettier (JS/TS/JSON/MD), gofmt (Go), rustfmt (Rust)
|
|
14
|
+
* - Falls back to shazam_fix suggestion if no native formatter found
|
|
10
15
|
*/
|
|
11
16
|
import type { ExtensionAPI } from "../types/pi-extension.js";
|
|
12
17
|
export declare function registerShazamGuide(pi: ExtensionAPI): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shazam-guide.d.ts","sourceRoot":"","sources":["../../hooks/shazam-guide.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shazam-guide.d.ts","sourceRoot":"","sources":["../../hooks/shazam-guide.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,0BAA0B,CAAC;AA+I/E,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CA6E1D"}
|