claude-ketchup 0.7.0 → 0.8.1
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/bundle/scripts/auto-continue.js +215 -0
- package/dist/bundle/scripts/pre-tool-use.js +11479 -0
- package/dist/bundle/scripts/session-start.js +8566 -0
- package/dist/bundle/scripts/user-prompt-submit.js +8580 -0
- package/dist/src/cli/cli.js +7 -7
- package/dist/src/cli/cli.js.map +1 -1
- package/dist/src/cli/cli.test.js +7 -0
- package/dist/src/cli/cli.test.js.map +1 -1
- package/dist/src/cli/install.d.ts +3 -4
- package/dist/src/cli/install.d.ts.map +1 -1
- package/dist/src/cli/install.js +88 -3
- package/dist/src/cli/install.js.map +1 -1
- package/dist/src/cli/install.test.js +70 -48
- package/dist/src/cli/install.test.js.map +1 -1
- package/dist/src/e2e.test.js +24 -31
- package/dist/src/e2e.test.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/path-resolver.d.ts +0 -2
- package/dist/src/path-resolver.d.ts.map +1 -1
- package/dist/src/path-resolver.js +0 -13
- package/dist/src/path-resolver.js.map +1 -1
- package/package.json +5 -4
- package/bin/postinstall.ts +0 -8
- package/bin/preuninstall.ts +0 -8
- package/dist/bin/postinstall.d.ts +0 -3
- package/dist/bin/postinstall.d.ts.map +0 -1
- package/dist/bin/postinstall.js +0 -9
- package/dist/bin/postinstall.js.map +0 -1
- package/dist/bin/preuninstall.d.ts +0 -3
- package/dist/bin/preuninstall.d.ts.map +0 -1
- package/dist/bin/preuninstall.js +0 -9
- package/dist/bin/preuninstall.js.map +0 -1
- package/dist/src/npm-install.test.d.ts +0 -2
- package/dist/src/npm-install.test.d.ts.map +0 -1
- package/dist/src/npm-install.test.js +0 -70
- package/dist/src/npm-install.test.js.map +0 -1
- package/dist/src/postinstall.d.ts +0 -8
- package/dist/src/postinstall.d.ts.map +0 -1
- package/dist/src/postinstall.js +0 -112
- package/dist/src/postinstall.js.map +0 -1
- package/dist/src/postinstall.test.d.ts +0 -2
- package/dist/src/postinstall.test.d.ts.map +0 -1
- package/dist/src/postinstall.test.js +0 -203
- package/dist/src/postinstall.test.js.map +0 -1
- package/dist/src/preuninstall.d.ts +0 -3
- package/dist/src/preuninstall.d.ts.map +0 -1
- package/dist/src/preuninstall.js +0 -85
- package/dist/src/preuninstall.js.map +0 -1
- package/dist/src/preuninstall.test.d.ts +0 -2
- package/dist/src/preuninstall.test.d.ts.map +0 -1
- package/dist/src/preuninstall.test.js +0 -114
- package/dist/src/preuninstall.test.js.map +0 -1
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
#!/usr/bin/env npx tsx
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// scripts/auto-continue.ts
|
|
27
|
+
var fs3 = __toESM(require("node:fs"));
|
|
28
|
+
var path3 = __toESM(require("node:path"));
|
|
29
|
+
|
|
30
|
+
// src/hook-logger.ts
|
|
31
|
+
var fs = __toESM(require("node:fs"));
|
|
32
|
+
var path = __toESM(require("node:path"));
|
|
33
|
+
function sanitizeForFilename(hookName) {
|
|
34
|
+
return hookName.replace(/[^a-zA-Z0-9-]/g, "-").toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
function writeHookLog(claudeDir2, entry) {
|
|
37
|
+
const logsDir = path.join(claudeDir2, "logs", "hooks");
|
|
38
|
+
if (!fs.existsSync(logsDir)) {
|
|
39
|
+
fs.mkdirSync(logsDir, { recursive: true });
|
|
40
|
+
}
|
|
41
|
+
const sanitizedName = sanitizeForFilename(entry.hookName);
|
|
42
|
+
const logFilename = `${sanitizedName}-${entry.timestamp}.log`;
|
|
43
|
+
const logPath = path.join(logsDir, logFilename);
|
|
44
|
+
const lines = [];
|
|
45
|
+
lines.push(`=== ${entry.hookName} hook log ===`);
|
|
46
|
+
lines.push(`Timestamp: ${entry.timestamp}`);
|
|
47
|
+
if (entry.durationMs !== void 0) {
|
|
48
|
+
lines.push(`Duration: ${entry.durationMs}ms`);
|
|
49
|
+
}
|
|
50
|
+
lines.push("");
|
|
51
|
+
lines.push("--- Input ---");
|
|
52
|
+
lines.push(JSON.stringify(entry.input, null, 2));
|
|
53
|
+
lines.push("");
|
|
54
|
+
if (entry.resolvedPaths) {
|
|
55
|
+
lines.push("--- Resolved Paths ---");
|
|
56
|
+
for (const [key, value] of Object.entries(entry.resolvedPaths)) {
|
|
57
|
+
lines.push(` ${key}: ${String(value)}`);
|
|
58
|
+
}
|
|
59
|
+
lines.push("");
|
|
60
|
+
}
|
|
61
|
+
if (entry.reminderFiles) {
|
|
62
|
+
lines.push(`--- Reminder Files Found (${entry.reminderFiles.length}) ---`);
|
|
63
|
+
for (const file of entry.reminderFiles) {
|
|
64
|
+
lines.push(` ${file}`);
|
|
65
|
+
}
|
|
66
|
+
lines.push("");
|
|
67
|
+
}
|
|
68
|
+
if (entry.matchedReminders) {
|
|
69
|
+
lines.push(`--- Matched Reminders (${entry.matchedReminders.length}) ---`);
|
|
70
|
+
for (const r of entry.matchedReminders) {
|
|
71
|
+
lines.push(` ${r.name} (priority: ${r.priority})`);
|
|
72
|
+
}
|
|
73
|
+
lines.push("");
|
|
74
|
+
}
|
|
75
|
+
if (entry.error) {
|
|
76
|
+
lines.push("--- Error ---");
|
|
77
|
+
lines.push(entry.error);
|
|
78
|
+
lines.push("");
|
|
79
|
+
}
|
|
80
|
+
lines.push("--- Output ---");
|
|
81
|
+
lines.push(JSON.stringify(entry.output, null, 2));
|
|
82
|
+
lines.push("");
|
|
83
|
+
fs.writeFileSync(logPath, lines.join("\n"));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/hook-state.ts
|
|
87
|
+
var fs2 = __toESM(require("node:fs"));
|
|
88
|
+
var path2 = __toESM(require("node:path"));
|
|
89
|
+
var DEFAULT_HOOK_STATE = {
|
|
90
|
+
autoContinue: {
|
|
91
|
+
mode: "smart",
|
|
92
|
+
maxIterations: 0,
|
|
93
|
+
iteration: 0,
|
|
94
|
+
skipModes: ["plan"]
|
|
95
|
+
},
|
|
96
|
+
validateCommit: {
|
|
97
|
+
mode: "strict"
|
|
98
|
+
},
|
|
99
|
+
denyList: {
|
|
100
|
+
enabled: true,
|
|
101
|
+
extraPatterns: []
|
|
102
|
+
},
|
|
103
|
+
promptReminder: {
|
|
104
|
+
enabled: true
|
|
105
|
+
},
|
|
106
|
+
subagentHooks: {
|
|
107
|
+
validateCommitOnExplore: false,
|
|
108
|
+
validateCommitOnWork: true,
|
|
109
|
+
validateCommitOnUnknown: true
|
|
110
|
+
},
|
|
111
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
112
|
+
updatedBy: "default"
|
|
113
|
+
};
|
|
114
|
+
function createHookState(projectDir2) {
|
|
115
|
+
const stateFile = path2.join(projectDir2, ".claude.hooks.json");
|
|
116
|
+
function read() {
|
|
117
|
+
if (!fs2.existsSync(stateFile)) {
|
|
118
|
+
const state = { ...DEFAULT_HOOK_STATE, updatedAt: (/* @__PURE__ */ new Date()).toISOString(), updatedBy: "init" };
|
|
119
|
+
fs2.writeFileSync(stateFile, `${JSON.stringify(state, null, 2)}
|
|
120
|
+
`);
|
|
121
|
+
return state;
|
|
122
|
+
}
|
|
123
|
+
const content = fs2.readFileSync(stateFile, "utf-8");
|
|
124
|
+
const partial = JSON.parse(content);
|
|
125
|
+
return {
|
|
126
|
+
autoContinue: { ...DEFAULT_HOOK_STATE.autoContinue, ...partial.autoContinue },
|
|
127
|
+
validateCommit: { ...DEFAULT_HOOK_STATE.validateCommit, ...partial.validateCommit },
|
|
128
|
+
denyList: { ...DEFAULT_HOOK_STATE.denyList, ...partial.denyList },
|
|
129
|
+
promptReminder: { ...DEFAULT_HOOK_STATE.promptReminder, ...partial.promptReminder },
|
|
130
|
+
subagentHooks: { ...DEFAULT_HOOK_STATE.subagentHooks, ...partial.subagentHooks },
|
|
131
|
+
updatedAt: partial.updatedAt ?? DEFAULT_HOOK_STATE.updatedAt,
|
|
132
|
+
updatedBy: partial.updatedBy
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function write(state) {
|
|
136
|
+
state.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
137
|
+
fs2.writeFileSync(stateFile, `${JSON.stringify(state, null, 2)}
|
|
138
|
+
`);
|
|
139
|
+
}
|
|
140
|
+
function update(updates, updatedBy) {
|
|
141
|
+
const current = read();
|
|
142
|
+
const newState = {
|
|
143
|
+
...current,
|
|
144
|
+
...updates,
|
|
145
|
+
autoContinue: { ...current.autoContinue, ...updates.autoContinue },
|
|
146
|
+
validateCommit: { ...current.validateCommit, ...updates.validateCommit },
|
|
147
|
+
denyList: { ...current.denyList, ...updates.denyList },
|
|
148
|
+
promptReminder: { ...current.promptReminder, ...updates.promptReminder },
|
|
149
|
+
subagentHooks: { ...current.subagentHooks, ...updates.subagentHooks },
|
|
150
|
+
updatedBy: updatedBy ?? "unknown",
|
|
151
|
+
updatedAt: current.updatedAt
|
|
152
|
+
};
|
|
153
|
+
write(newState);
|
|
154
|
+
return newState;
|
|
155
|
+
}
|
|
156
|
+
function incrementIteration() {
|
|
157
|
+
const state = read();
|
|
158
|
+
state.autoContinue.iteration = state.autoContinue.iteration + 1;
|
|
159
|
+
write(state);
|
|
160
|
+
return state.autoContinue.iteration;
|
|
161
|
+
}
|
|
162
|
+
function resetIteration() {
|
|
163
|
+
const state = read();
|
|
164
|
+
state.autoContinue.iteration = 0;
|
|
165
|
+
write(state);
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
read,
|
|
169
|
+
write,
|
|
170
|
+
update,
|
|
171
|
+
incrementIteration,
|
|
172
|
+
resetIteration
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/hooks/auto-continue.ts
|
|
177
|
+
function handleStop(projectDir2, input2) {
|
|
178
|
+
const stateManager = createHookState(projectDir2);
|
|
179
|
+
const state = stateManager.read();
|
|
180
|
+
const { mode, skipModes } = state.autoContinue;
|
|
181
|
+
if (mode === "off") {
|
|
182
|
+
return { decision: "allow", reason: "auto-continue disabled" };
|
|
183
|
+
}
|
|
184
|
+
if (input2.stop_hook_active) {
|
|
185
|
+
return { decision: "allow", reason: "stop hook already active" };
|
|
186
|
+
}
|
|
187
|
+
const modesToSkip = skipModes ?? ["plan"];
|
|
188
|
+
if (input2.permission_mode && modesToSkip.includes(input2.permission_mode)) {
|
|
189
|
+
return { decision: "allow", reason: `skipping mode: ${input2.permission_mode}` };
|
|
190
|
+
}
|
|
191
|
+
return { decision: "allow", reason: "no work remaining" };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// scripts/auto-continue.ts
|
|
195
|
+
var projectDir = process.cwd();
|
|
196
|
+
var claudeDir = path3.resolve(projectDir, ".claude");
|
|
197
|
+
var stdin = fs3.readFileSync(0, "utf8").trim();
|
|
198
|
+
if (!stdin) {
|
|
199
|
+
process.exit(0);
|
|
200
|
+
}
|
|
201
|
+
var input = JSON.parse(stdin);
|
|
202
|
+
var startTime = Date.now();
|
|
203
|
+
var result = handleStop(projectDir, input);
|
|
204
|
+
var output = result.decision === "block" ? { stopReason: result.reason, forceResult: { behaviour: "block" } } : null;
|
|
205
|
+
writeHookLog(claudeDir, {
|
|
206
|
+
hookName: "auto-continue",
|
|
207
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
208
|
+
input,
|
|
209
|
+
output: output ?? { decision: result.decision, reason: result.reason },
|
|
210
|
+
durationMs: Date.now() - startTime
|
|
211
|
+
});
|
|
212
|
+
if (output) {
|
|
213
|
+
console.log(JSON.stringify(output));
|
|
214
|
+
}
|
|
215
|
+
process.exit(0);
|