@spardutti/claude-skills 1.27.4 → 1.28.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 +44 -1
- package/package.json +1 -1
package/lib/setup-hook.mjs
CHANGED
|
@@ -51,23 +51,49 @@ if [ -f "$MARKER" ]; then
|
|
|
51
51
|
fi
|
|
52
52
|
|
|
53
53
|
cat <<EOF
|
|
54
|
-
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"Skill evaluation required before file edits. (1) List each available skill as ACTIVATE or SKIP with a one-line reason. (2) Call Skill() for any ACTIVATE entries.
|
|
54
|
+
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"Skill evaluation required before file edits. (1) List each available skill as ACTIVATE or SKIP with a one-line reason. (2) Call Skill() for any ACTIVATE entries — this auto-clears the gate. If all skills are SKIP, run this exact Bash command instead: touch /tmp/claude-skill-gate-$LAST_PROMPT_UUID (3) Then retry the file edit. The marker is unique to this user prompt and is auto-cleaned on the next prompt."}}
|
|
55
55
|
EOF
|
|
56
56
|
exit 0
|
|
57
57
|
`;
|
|
58
58
|
|
|
59
|
+
// PostToolUse on Skill: auto-creates the gate marker so the model doesn't
|
|
60
|
+
// need an explicit touch. Uses the same UUID-detection logic as the gate.
|
|
61
|
+
const AUTO_MARK_SCRIPT = `#!/bin/bash
|
|
62
|
+
# PostToolUse on Skill: auto-marks the skill-gate as satisfied.
|
|
63
|
+
|
|
64
|
+
INPUT=$(cat)
|
|
65
|
+
|
|
66
|
+
TRANSCRIPT=$(printf '%s' "$INPUT" | grep -o '"transcript_path":"[^"]*"' | head -1 | sed 's/"transcript_path":"//; s/"$//')
|
|
67
|
+
if [ -z "$TRANSCRIPT" ] || [ ! -f "$TRANSCRIPT" ]; then
|
|
68
|
+
exit 0
|
|
69
|
+
fi
|
|
70
|
+
|
|
71
|
+
LAST_LINE=$(grep -E '"role":"user","content":"' "$TRANSCRIPT" 2>/dev/null | tail -1)
|
|
72
|
+
LAST_PROMPT_UUID=$(printf '%s' "$LAST_LINE" | grep -o '"uuid":"[^"]*"' | head -1 | sed 's/"uuid":"//;s/"$//')
|
|
73
|
+
if [ -z "$LAST_PROMPT_UUID" ]; then
|
|
74
|
+
exit 0
|
|
75
|
+
fi
|
|
76
|
+
|
|
77
|
+
touch "/tmp/claude-skill-gate-$LAST_PROMPT_UUID"
|
|
78
|
+
exit 0
|
|
79
|
+
`;
|
|
80
|
+
|
|
59
81
|
const GATE_FILENAME = "skill-gate.sh";
|
|
82
|
+
const AUTO_MARK_FILENAME = "skill-gate-automark.sh";
|
|
60
83
|
const LEGACY_EVAL_FILENAME = "skill-forced-eval-hook.sh";
|
|
61
84
|
|
|
62
85
|
export async function setupHook(targetDir = process.cwd()) {
|
|
63
86
|
const resolved = resolve(targetDir);
|
|
64
87
|
const hooksDir = join(resolved, ".claude", "hooks");
|
|
65
88
|
const gatePath = join(hooksDir, GATE_FILENAME);
|
|
89
|
+
const autoMarkPath = join(hooksDir, AUTO_MARK_FILENAME);
|
|
66
90
|
const settingsPath = join(resolved, ".claude", "settings.json");
|
|
67
91
|
|
|
68
92
|
await mkdir(hooksDir, { recursive: true });
|
|
69
93
|
await writeFile(gatePath, GATE_SCRIPT, { mode: 0o755 });
|
|
70
94
|
await chmod(gatePath, 0o755);
|
|
95
|
+
await writeFile(autoMarkPath, AUTO_MARK_SCRIPT, { mode: 0o755 });
|
|
96
|
+
await chmod(autoMarkPath, 0o755);
|
|
71
97
|
|
|
72
98
|
let settings = {};
|
|
73
99
|
try {
|
|
@@ -103,8 +129,25 @@ export async function setupHook(targetDir = process.cwd()) {
|
|
|
103
129
|
settings.hooks.PreToolUse = [gateEntry];
|
|
104
130
|
}
|
|
105
131
|
|
|
132
|
+
// Register PostToolUse auto-mark on Skill.
|
|
133
|
+
const autoMarkCommand = `$CLAUDE_PROJECT_DIR/.claude/hooks/${AUTO_MARK_FILENAME}`;
|
|
134
|
+
const autoMarkEntry = {
|
|
135
|
+
matcher: "Skill",
|
|
136
|
+
hooks: [{ type: "command", command: autoMarkCommand }],
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
if (Array.isArray(settings.hooks.PostToolUse)) {
|
|
140
|
+
const exists = settings.hooks.PostToolUse.some((entry) =>
|
|
141
|
+
entry.hooks?.some((h) => h.command?.endsWith(AUTO_MARK_FILENAME))
|
|
142
|
+
);
|
|
143
|
+
if (!exists) settings.hooks.PostToolUse.push(autoMarkEntry);
|
|
144
|
+
} else {
|
|
145
|
+
settings.hooks.PostToolUse = [autoMarkEntry];
|
|
146
|
+
}
|
|
147
|
+
|
|
106
148
|
await writeFile(settingsPath, JSON.stringify(settings, null, 2) + "\n", { mode: 0o644 });
|
|
107
149
|
|
|
108
150
|
console.log(` Hook installed: .claude/hooks/${GATE_FILENAME}`);
|
|
151
|
+
console.log(` Hook installed: .claude/hooks/${AUTO_MARK_FILENAME}`);
|
|
109
152
|
console.log(` Settings updated: .claude/settings.json`);
|
|
110
153
|
}
|