jettypod 4.4.7 ā 4.4.9
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/claude-hooks/protect-claude-md.js +182 -0
- package/jettypod.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Claude Code PreToolUse Hook
|
|
4
|
+
*
|
|
5
|
+
* Intercepts Edit/Write operations on CLAUDE.md and blocks
|
|
6
|
+
* forbidden patterns like mode changes or current_work updates.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
|
|
11
|
+
// Read hook input from stdin
|
|
12
|
+
let input = '';
|
|
13
|
+
process.stdin.on('data', chunk => input += chunk);
|
|
14
|
+
process.stdin.on('end', () => {
|
|
15
|
+
try {
|
|
16
|
+
const hookInput = JSON.parse(input);
|
|
17
|
+
const { tool_name, tool_input, cwd } = hookInput;
|
|
18
|
+
|
|
19
|
+
// Only check CLAUDE.md edits
|
|
20
|
+
if (!tool_input.file_path || !tool_input.file_path.endsWith('CLAUDE.md')) {
|
|
21
|
+
allowEdit();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let oldContent, newContent;
|
|
26
|
+
|
|
27
|
+
if (tool_name === 'Edit') {
|
|
28
|
+
oldContent = tool_input.old_string;
|
|
29
|
+
newContent = tool_input.new_string;
|
|
30
|
+
} else if (tool_name === 'Write') {
|
|
31
|
+
// For Write, read the current file content (if exists) to compare
|
|
32
|
+
try {
|
|
33
|
+
oldContent = fs.readFileSync(tool_input.file_path, 'utf8');
|
|
34
|
+
newContent = tool_input.content;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
// File doesn't exist yet - allow new file creation
|
|
37
|
+
allowEdit();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
// Unknown tool
|
|
42
|
+
allowEdit();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const result = checkEdit(oldContent, newContent);
|
|
47
|
+
|
|
48
|
+
if (result.blocked) {
|
|
49
|
+
denyEdit(result.message, result.suggestion);
|
|
50
|
+
} else {
|
|
51
|
+
allowEdit();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
} catch (err) {
|
|
55
|
+
// If we can't parse input, allow the edit (fail open)
|
|
56
|
+
console.error('Hook error:', err.message);
|
|
57
|
+
allowEdit();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Allow the edit
|
|
63
|
+
*/
|
|
64
|
+
function allowEdit() {
|
|
65
|
+
console.log(JSON.stringify({
|
|
66
|
+
hookSpecificOutput: {
|
|
67
|
+
hookEventName: "PreToolUse",
|
|
68
|
+
permissionDecision: "allow"
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
process.exit(0);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Deny the edit with explanation
|
|
76
|
+
*/
|
|
77
|
+
function denyEdit(message, suggestion) {
|
|
78
|
+
const reason = `ā ${message}\n\nš” Hint: ${suggestion}`;
|
|
79
|
+
|
|
80
|
+
console.log(JSON.stringify({
|
|
81
|
+
hookSpecificOutput: {
|
|
82
|
+
hookEventName: "PreToolUse",
|
|
83
|
+
permissionDecision: "deny",
|
|
84
|
+
permissionDecisionReason: reason
|
|
85
|
+
}
|
|
86
|
+
}));
|
|
87
|
+
process.exit(0);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Pattern definitions for forbidden edits
|
|
92
|
+
*/
|
|
93
|
+
const FORBIDDEN_PATTERNS = [
|
|
94
|
+
{
|
|
95
|
+
name: 'mode_change',
|
|
96
|
+
detect: (old, newStr) => {
|
|
97
|
+
const oldMode = old.match(/<mode>(\w+)<\/mode>/);
|
|
98
|
+
const newMode = newStr.match(/<mode>(\w+)<\/mode>/);
|
|
99
|
+
return oldMode && newMode && oldMode[1] !== newMode[1];
|
|
100
|
+
},
|
|
101
|
+
message: 'Cannot change <mode> tag directly',
|
|
102
|
+
suggestion: (old, newStr) => {
|
|
103
|
+
const newMode = newStr.match(/<mode>(\w+)<\/mode>/)?.[1];
|
|
104
|
+
return `Use: jettypod ${newMode}`;
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'current_work_change',
|
|
109
|
+
detect: (old, newStr) => {
|
|
110
|
+
const oldWork = old.match(/<current_work>[\s\S]*?<\/current_work>/);
|
|
111
|
+
const newWork = newStr.match(/<current_work>[\s\S]*?<\/current_work>/);
|
|
112
|
+
|
|
113
|
+
// Block if current_work section content changes
|
|
114
|
+
if (oldWork && newWork && oldWork[0] !== newWork[0]) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Block if adding/removing current_work section
|
|
119
|
+
if ((!oldWork && newWork) || (oldWork && !newWork)) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return false;
|
|
124
|
+
},
|
|
125
|
+
message: 'Cannot modify <current_work> section directly',
|
|
126
|
+
suggestion: (old, newStr) => {
|
|
127
|
+
const workId = newStr.match(/Working on: \[#(\d+)\]/)?.[1];
|
|
128
|
+
if (workId) {
|
|
129
|
+
return `Use: jettypod work start ${workId}`;
|
|
130
|
+
}
|
|
131
|
+
return 'Use: jettypod work start <id> or jettypod work stop';
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'work_status_change',
|
|
136
|
+
detect: (old, newStr) => {
|
|
137
|
+
const oldStatus = old.match(/Status: (\w+)/);
|
|
138
|
+
const newStatus = newStr.match(/Status: (\w+)/);
|
|
139
|
+
return oldStatus && newStatus && oldStatus[1] !== newStatus[1];
|
|
140
|
+
},
|
|
141
|
+
message: 'Cannot change work status directly',
|
|
142
|
+
suggestion: (old, newStr) => {
|
|
143
|
+
const workId = newStr.match(/Working on: \[#(\d+)\]/)?.[1];
|
|
144
|
+
const newStatus = newStr.match(/Status: (\w+)/)?.[1];
|
|
145
|
+
if (workId && newStatus) {
|
|
146
|
+
return `Use: jettypod work status ${workId} ${newStatus}`;
|
|
147
|
+
}
|
|
148
|
+
return 'Use: jettypod work status <id> <status>';
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: 'stage_change',
|
|
153
|
+
detect: (old, newStr) => {
|
|
154
|
+
const oldStage = old.match(/<stage>(\w+)<\/stage>/);
|
|
155
|
+
const newStage = newStr.match(/<stage>(\w+)<\/stage>/);
|
|
156
|
+
return oldStage && newStage && oldStage[1] !== newStage[1];
|
|
157
|
+
},
|
|
158
|
+
message: 'Cannot change <stage> tag directly',
|
|
159
|
+
suggestion: (old, newStr) => {
|
|
160
|
+
const newStage = newStr.match(/<stage>(\w+)<\/stage>/)?.[1];
|
|
161
|
+
return `Use: jettypod stage ${newStage}`;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
];
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Check if an edit should be blocked
|
|
168
|
+
*/
|
|
169
|
+
function checkEdit(oldStr, newStr) {
|
|
170
|
+
for (const pattern of FORBIDDEN_PATTERNS) {
|
|
171
|
+
if (pattern.detect(oldStr, newStr)) {
|
|
172
|
+
return {
|
|
173
|
+
blocked: true,
|
|
174
|
+
pattern: pattern.name,
|
|
175
|
+
message: pattern.message,
|
|
176
|
+
suggestion: pattern.suggestion(oldStr, newStr)
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return { blocked: false };
|
|
182
|
+
}
|
package/jettypod.js
CHANGED
|
@@ -748,9 +748,9 @@ async function initializeProject() {
|
|
|
748
748
|
fs.mkdirSync('.jettypod/hooks', { recursive: true });
|
|
749
749
|
}
|
|
750
750
|
|
|
751
|
-
const hookSource = path.join(__dirname, '
|
|
751
|
+
const hookSource = path.join(__dirname, 'claude-hooks', 'protect-claude-md.js');
|
|
752
752
|
const hookDest = path.join('.jettypod', 'hooks', 'protect-claude-md.js');
|
|
753
|
-
if (fs.existsSync(hookSource)
|
|
753
|
+
if (fs.existsSync(hookSource)) {
|
|
754
754
|
fs.copyFileSync(hookSource, hookDest);
|
|
755
755
|
fs.chmodSync(hookDest, 0o755);
|
|
756
756
|
console.log('š Claude Code hook installed');
|