@spardutti/claude-skills 1.1.0 → 1.3.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/lib/setup-hook.mjs +31 -5
- package/package.json +1 -1
package/lib/setup-hook.mjs
CHANGED
|
@@ -42,13 +42,15 @@ exit 0
|
|
|
42
42
|
|
|
43
43
|
const HOOK_FILENAME = "skill-forced-eval-hook.sh";
|
|
44
44
|
|
|
45
|
+
const PRETOOL_PROMPT = `REMINDER: This project has skills installed in .claude/skills/. Before writing code you MUST evaluate and activate relevant skills using the Skill() tool. If you have not done this yet in the current conversation, STOP and do it now before proceeding with this edit. Always return 'approve'.`;
|
|
46
|
+
|
|
45
47
|
export async function setupHook(targetDir = process.cwd()) {
|
|
46
48
|
const resolved = resolve(targetDir);
|
|
47
49
|
const hooksDir = join(resolved, ".claude", "hooks");
|
|
48
50
|
const hookPath = join(hooksDir, HOOK_FILENAME);
|
|
49
51
|
const settingsPath = join(resolved, ".claude", "settings.json");
|
|
50
52
|
|
|
51
|
-
// Write the hook script
|
|
53
|
+
// Write the UserPromptSubmit hook script
|
|
52
54
|
await mkdir(hooksDir, { recursive: true });
|
|
53
55
|
await writeFile(hookPath, HOOK_SCRIPT, { mode: 0o755 });
|
|
54
56
|
await chmod(hookPath, 0o755);
|
|
@@ -66,20 +68,43 @@ export async function setupHook(targetDir = process.cwd()) {
|
|
|
66
68
|
settings.hooks = {};
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
// --- UserPromptSubmit hook (forced eval via command) ---
|
|
72
|
+
const promptHookEntry = {
|
|
70
73
|
hooks: [{ type: "command", command: hookPath }],
|
|
71
74
|
};
|
|
72
75
|
|
|
73
|
-
// Check if UserPromptSubmit already has this hook to avoid duplicates
|
|
74
76
|
if (Array.isArray(settings.hooks.UserPromptSubmit)) {
|
|
75
77
|
const alreadyInstalled = settings.hooks.UserPromptSubmit.some((entry) =>
|
|
76
78
|
entry.hooks?.some((h) => h.command?.endsWith(HOOK_FILENAME))
|
|
77
79
|
);
|
|
78
80
|
if (!alreadyInstalled) {
|
|
79
|
-
settings.hooks.UserPromptSubmit.push(
|
|
81
|
+
settings.hooks.UserPromptSubmit.push(promptHookEntry);
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
settings.hooks.UserPromptSubmit = [promptHookEntry];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// --- PreToolUse hook (LLM prompt reminder to evaluate skills before writing code) ---
|
|
88
|
+
const pretoolHookEntry = {
|
|
89
|
+
matcher: "Edit|Write|NotebookEdit",
|
|
90
|
+
hooks: [
|
|
91
|
+
{
|
|
92
|
+
type: "prompt",
|
|
93
|
+
prompt: PRETOOL_PROMPT,
|
|
94
|
+
timeout: 15,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
if (Array.isArray(settings.hooks.PreToolUse)) {
|
|
100
|
+
const alreadyInstalled = settings.hooks.PreToolUse.some((entry) =>
|
|
101
|
+
entry.hooks?.some((h) => h.type === "prompt" && h.prompt?.includes("REMINDER"))
|
|
102
|
+
);
|
|
103
|
+
if (!alreadyInstalled) {
|
|
104
|
+
settings.hooks.PreToolUse.push(pretoolHookEntry);
|
|
80
105
|
}
|
|
81
106
|
} else {
|
|
82
|
-
settings.hooks.
|
|
107
|
+
settings.hooks.PreToolUse = [pretoolHookEntry];
|
|
83
108
|
}
|
|
84
109
|
|
|
85
110
|
await writeFile(settingsPath, JSON.stringify(settings, null, 2) + "\n", {
|
|
@@ -87,5 +112,6 @@ export async function setupHook(targetDir = process.cwd()) {
|
|
|
87
112
|
});
|
|
88
113
|
|
|
89
114
|
console.log(` Hook installed: .claude/hooks/${HOOK_FILENAME}`);
|
|
115
|
+
console.log(` Hook installed: PreToolUse prompt hook (Edit|Write|NotebookEdit)`);
|
|
90
116
|
console.log(` Settings updated: .claude/settings.json`);
|
|
91
117
|
}
|