cc-hooks-ts 2.0.45 → 2.0.56
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/index.d.mts +111 -1
- package/dist/index.mjs +65 -0
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -33,6 +33,19 @@ declare const HookInputSchemas: {
|
|
|
33
33
|
tool_response: v.UnknownSchema;
|
|
34
34
|
tool_use_id: v.StringSchema<undefined>;
|
|
35
35
|
}, undefined>;
|
|
36
|
+
readonly PostToolUseFailure: v.ObjectSchema<{
|
|
37
|
+
readonly cwd: v.StringSchema<undefined>;
|
|
38
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
39
|
+
readonly session_id: v.StringSchema<undefined>;
|
|
40
|
+
readonly transcript_path: v.StringSchema<undefined>;
|
|
41
|
+
readonly hook_event_name: v.LiteralSchema<"PostToolUseFailure", undefined>;
|
|
42
|
+
} & {
|
|
43
|
+
tool_name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, AutoComplete<string>>]>;
|
|
44
|
+
error: v.StringSchema<undefined>;
|
|
45
|
+
is_interrupt: v.ExactOptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
46
|
+
tool_input: v.UnknownSchema;
|
|
47
|
+
tool_use_id: v.StringSchema<undefined>;
|
|
48
|
+
}, undefined>;
|
|
36
49
|
readonly Notification: v.ObjectSchema<{
|
|
37
50
|
readonly cwd: v.StringSchema<undefined>;
|
|
38
51
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
@@ -118,6 +131,43 @@ declare const HookInputSchemas: {
|
|
|
118
131
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
119
132
|
readonly hook_event_name: v.LiteralSchema<"PermissionRequest", undefined>;
|
|
120
133
|
} & {
|
|
134
|
+
permission_suggestions: v.ExactOptionalSchema<v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
135
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
136
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
137
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
138
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
139
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
140
|
+
}, undefined>, undefined>;
|
|
141
|
+
readonly type: v.LiteralSchema<"addRules", undefined>;
|
|
142
|
+
}, undefined>, v.ObjectSchema<{
|
|
143
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
144
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
145
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
146
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
147
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
148
|
+
}, undefined>, undefined>;
|
|
149
|
+
readonly type: v.LiteralSchema<"replaceRules", undefined>;
|
|
150
|
+
}, undefined>, v.ObjectSchema<{
|
|
151
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
152
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
153
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
154
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
155
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
156
|
+
}, undefined>, undefined>;
|
|
157
|
+
readonly type: v.LiteralSchema<"removeRules", undefined>;
|
|
158
|
+
}, undefined>, v.ObjectSchema<{
|
|
159
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
160
|
+
readonly mode: v.UnionSchema<[v.LiteralSchema<"acceptEdits", undefined>, v.LiteralSchema<"bypassPermissions", undefined>, v.LiteralSchema<"default", undefined>, v.LiteralSchema<"dontAsk", undefined>, v.LiteralSchema<"plan", undefined>], undefined>;
|
|
161
|
+
readonly type: v.LiteralSchema<"setMode", undefined>;
|
|
162
|
+
}, undefined>, v.ObjectSchema<{
|
|
163
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
164
|
+
readonly directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
165
|
+
readonly type: v.LiteralSchema<"addDirectories", undefined>;
|
|
166
|
+
}, undefined>, v.ObjectSchema<{
|
|
167
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
168
|
+
readonly directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
169
|
+
readonly type: v.LiteralSchema<"removeDirectories", undefined>;
|
|
170
|
+
}, undefined>], undefined>, undefined>, undefined>;
|
|
121
171
|
tool_input: v.UnknownSchema;
|
|
122
172
|
tool_name: v.StringSchema<undefined>;
|
|
123
173
|
}, undefined>;
|
|
@@ -129,7 +179,7 @@ declare const HookInputSchemas: {
|
|
|
129
179
|
*
|
|
130
180
|
* @package
|
|
131
181
|
*/
|
|
132
|
-
type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "Notification" | "UserPromptSubmit" | "SessionStart" | "SessionEnd" | "Stop" | "SubagentStart" | "SubagentStop" | "PreCompact" | "PermissionRequest";
|
|
182
|
+
type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "PostToolUseFailure" | "Notification" | "UserPromptSubmit" | "SessionStart" | "SessionEnd" | "Stop" | "SubagentStart" | "SubagentStop" | "PreCompact" | "PermissionRequest";
|
|
133
183
|
//#endregion
|
|
134
184
|
//#region src/hooks/input/types.d.ts
|
|
135
185
|
/**
|
|
@@ -147,6 +197,8 @@ type HookInput = { [EventKey in SupportedHookEvent]: EventKey extends "PreToolUs
|
|
|
147
197
|
default: BaseHookInputs["PreToolUse"];
|
|
148
198
|
} : EventKey extends "PostToolUse" ? ToolSpecificPostToolUseInput & {
|
|
149
199
|
default: BaseHookInputs["PostToolUse"];
|
|
200
|
+
} : EventKey extends "PostToolUseFailure" ? ToolSpecificPostToolUseFailureInput & {
|
|
201
|
+
default: BaseHookInputs["PostToolUseFailure"];
|
|
150
202
|
} : {
|
|
151
203
|
default: BaseHookInputs[EventKey];
|
|
152
204
|
} };
|
|
@@ -203,6 +255,53 @@ type ToolSpecificPostToolUseInput = { [K in keyof ToolSchema]: Omit<BaseHookInpu
|
|
|
203
255
|
tool_name: K;
|
|
204
256
|
tool_response: ToolSchema[K]["response"];
|
|
205
257
|
} };
|
|
258
|
+
type ToolSpecificPostToolUseFailureInput = { [K in keyof ToolSchema]: Omit<BaseHookInputs["PostToolUseFailure"], "tool_input" | "tool_name"> & {
|
|
259
|
+
tool_input: ToolSchema[K]["input"];
|
|
260
|
+
tool_name: K;
|
|
261
|
+
} };
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/hooks/permission.d.ts
|
|
264
|
+
/**
|
|
265
|
+
* @package
|
|
266
|
+
*/
|
|
267
|
+
declare const permissionUpdateSchema: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
268
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
269
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
270
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
271
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
272
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
273
|
+
}, undefined>, undefined>;
|
|
274
|
+
readonly type: v.LiteralSchema<"addRules", undefined>;
|
|
275
|
+
}, undefined>, v.ObjectSchema<{
|
|
276
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
277
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
278
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
279
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
280
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
281
|
+
}, undefined>, undefined>;
|
|
282
|
+
readonly type: v.LiteralSchema<"replaceRules", undefined>;
|
|
283
|
+
}, undefined>, v.ObjectSchema<{
|
|
284
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
285
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
286
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
287
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
288
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
289
|
+
}, undefined>, undefined>;
|
|
290
|
+
readonly type: v.LiteralSchema<"removeRules", undefined>;
|
|
291
|
+
}, undefined>, v.ObjectSchema<{
|
|
292
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
293
|
+
readonly mode: v.UnionSchema<[v.LiteralSchema<"acceptEdits", undefined>, v.LiteralSchema<"bypassPermissions", undefined>, v.LiteralSchema<"default", undefined>, v.LiteralSchema<"dontAsk", undefined>, v.LiteralSchema<"plan", undefined>], undefined>;
|
|
294
|
+
readonly type: v.LiteralSchema<"setMode", undefined>;
|
|
295
|
+
}, undefined>, v.ObjectSchema<{
|
|
296
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
297
|
+
readonly directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
298
|
+
readonly type: v.LiteralSchema<"addDirectories", undefined>;
|
|
299
|
+
}, undefined>, v.ObjectSchema<{
|
|
300
|
+
readonly destination: v.UnionSchema<[v.LiteralSchema<"userSettings", undefined>, v.LiteralSchema<"projectSettings", undefined>, v.LiteralSchema<"localSettings", undefined>, v.LiteralSchema<"session", undefined>, v.LiteralSchema<"cliArg", undefined>], undefined>;
|
|
301
|
+
readonly directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
302
|
+
readonly type: v.LiteralSchema<"removeDirectories", undefined>;
|
|
303
|
+
}, undefined>], undefined>;
|
|
304
|
+
type PermissionUpdate = v.InferOutput<typeof permissionUpdateSchema>;
|
|
206
305
|
//#endregion
|
|
207
306
|
//#region src/hooks/output/index.d.ts
|
|
208
307
|
/**
|
|
@@ -211,6 +310,7 @@ type ToolSpecificPostToolUseInput = { [K in keyof ToolSchema]: Omit<BaseHookInpu
|
|
|
211
310
|
type HookOutput = {
|
|
212
311
|
PreToolUse: PreToolUseHookOutput;
|
|
213
312
|
PostToolUse: PostToolUseHookOutput;
|
|
313
|
+
PostToolUseFailure: PostToolUseFailureHookOutput;
|
|
214
314
|
UserPromptSubmit: UserPromptSubmitHookOutput;
|
|
215
315
|
Stop: StopHookOutput;
|
|
216
316
|
SubagentStart: SubagentStartHookOutput;
|
|
@@ -302,6 +402,15 @@ interface PostToolUseHookOutput extends CommonHookOutputs {
|
|
|
302
402
|
};
|
|
303
403
|
reason?: string;
|
|
304
404
|
}
|
|
405
|
+
interface PostToolUseFailureHookOutput extends CommonHookOutputs {
|
|
406
|
+
hookSpecificOutput?: {
|
|
407
|
+
hookEventName: "PostToolUseFailure";
|
|
408
|
+
/**
|
|
409
|
+
* Adds context for Claude to consider.
|
|
410
|
+
*/
|
|
411
|
+
additionalContext?: string;
|
|
412
|
+
};
|
|
413
|
+
}
|
|
305
414
|
/**
|
|
306
415
|
* @see {@link https://docs.anthropic.com/en/docs/claude-code/hooks#userpromptsubmit-decision-control}
|
|
307
416
|
*/
|
|
@@ -380,6 +489,7 @@ interface PermissionRequestHookOutput extends CommonHookOutputs {
|
|
|
380
489
|
decision: {
|
|
381
490
|
behavior: "allow";
|
|
382
491
|
updatedInput?: Record<string, unknown>;
|
|
492
|
+
updatedPermissions?: PermissionUpdate[];
|
|
383
493
|
} | {
|
|
384
494
|
behavior: "deny";
|
|
385
495
|
interrupt?: boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -28,6 +28,63 @@ function createContext(input) {
|
|
|
28
28
|
})
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
+
const permissionBehaviorSchema = v.union([
|
|
32
|
+
v.literal("allow"),
|
|
33
|
+
v.literal("deny"),
|
|
34
|
+
v.literal("ask")
|
|
35
|
+
]);
|
|
36
|
+
const permissionUpdateDestinationSchema = v.union([
|
|
37
|
+
v.literal("userSettings"),
|
|
38
|
+
v.literal("projectSettings"),
|
|
39
|
+
v.literal("localSettings"),
|
|
40
|
+
v.literal("session"),
|
|
41
|
+
v.literal("cliArg")
|
|
42
|
+
]);
|
|
43
|
+
const permissionRuleValueSchema = v.object({
|
|
44
|
+
ruleContent: v.exactOptional(v.string()),
|
|
45
|
+
toolName: v.string()
|
|
46
|
+
});
|
|
47
|
+
const permissionUpdateSchema = v.variant("type", [
|
|
48
|
+
v.object({
|
|
49
|
+
behavior: permissionBehaviorSchema,
|
|
50
|
+
destination: permissionUpdateDestinationSchema,
|
|
51
|
+
rules: v.array(permissionRuleValueSchema),
|
|
52
|
+
type: v.literal("addRules")
|
|
53
|
+
}),
|
|
54
|
+
v.object({
|
|
55
|
+
behavior: permissionBehaviorSchema,
|
|
56
|
+
destination: permissionUpdateDestinationSchema,
|
|
57
|
+
rules: v.array(permissionRuleValueSchema),
|
|
58
|
+
type: v.literal("replaceRules")
|
|
59
|
+
}),
|
|
60
|
+
v.object({
|
|
61
|
+
behavior: permissionBehaviorSchema,
|
|
62
|
+
destination: permissionUpdateDestinationSchema,
|
|
63
|
+
rules: v.array(permissionRuleValueSchema),
|
|
64
|
+
type: v.literal("removeRules")
|
|
65
|
+
}),
|
|
66
|
+
v.object({
|
|
67
|
+
destination: permissionUpdateDestinationSchema,
|
|
68
|
+
mode: v.union([
|
|
69
|
+
v.literal("acceptEdits"),
|
|
70
|
+
v.literal("bypassPermissions"),
|
|
71
|
+
v.literal("default"),
|
|
72
|
+
v.literal("dontAsk"),
|
|
73
|
+
v.literal("plan")
|
|
74
|
+
]),
|
|
75
|
+
type: v.literal("setMode")
|
|
76
|
+
}),
|
|
77
|
+
v.object({
|
|
78
|
+
destination: permissionUpdateDestinationSchema,
|
|
79
|
+
directories: v.array(v.string()),
|
|
80
|
+
type: v.literal("addDirectories")
|
|
81
|
+
}),
|
|
82
|
+
v.object({
|
|
83
|
+
destination: permissionUpdateDestinationSchema,
|
|
84
|
+
directories: v.array(v.string()),
|
|
85
|
+
type: v.literal("removeDirectories")
|
|
86
|
+
})
|
|
87
|
+
]);
|
|
31
88
|
const baseHookInputSchema = v.object({
|
|
32
89
|
cwd: v.string(),
|
|
33
90
|
permission_mode: v.exactOptional(v.string()),
|
|
@@ -53,6 +110,13 @@ const HookInputSchemas = {
|
|
|
53
110
|
tool_response: v.unknown(),
|
|
54
111
|
tool_use_id: v.string()
|
|
55
112
|
}),
|
|
113
|
+
PostToolUseFailure: buildHookInputSchema("PostToolUseFailure", {
|
|
114
|
+
tool_name: v.pipe(v.string(), v.transform((s) => s)),
|
|
115
|
+
error: v.string(),
|
|
116
|
+
is_interrupt: v.exactOptional(v.boolean()),
|
|
117
|
+
tool_input: v.unknown(),
|
|
118
|
+
tool_use_id: v.string()
|
|
119
|
+
}),
|
|
56
120
|
Notification: buildHookInputSchema("Notification", {
|
|
57
121
|
message: v.string(),
|
|
58
122
|
notification_type: v.string(),
|
|
@@ -81,6 +145,7 @@ const HookInputSchemas = {
|
|
|
81
145
|
]) }),
|
|
82
146
|
SessionEnd: buildHookInputSchema("SessionEnd", { reason: v.string() }),
|
|
83
147
|
PermissionRequest: buildHookInputSchema("PermissionRequest", {
|
|
148
|
+
permission_suggestions: v.exactOptional(v.array(permissionUpdateSchema)),
|
|
84
149
|
tool_input: v.unknown(),
|
|
85
150
|
tool_name: v.string()
|
|
86
151
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-hooks-ts",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.56",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Write claude code hooks with type safety",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@arethetypeswrong/core": "0.18.2",
|
|
46
|
-
"@biomejs/biome": "2.3.
|
|
46
|
+
"@biomejs/biome": "2.3.8",
|
|
47
47
|
"@types/node": "24.10.1",
|
|
48
48
|
"@typescript/native-preview": "^7.0.0-dev.20251108.1",
|
|
49
49
|
"@virtual-live-lab/eslint-config": "2.3.1",
|
|
@@ -54,15 +54,15 @@
|
|
|
54
54
|
"publint": "0.3.15",
|
|
55
55
|
"release-it": "19.0.6",
|
|
56
56
|
"release-it-pnpm": "4.6.6",
|
|
57
|
-
"tsdown": "0.16.
|
|
57
|
+
"tsdown": "0.16.8",
|
|
58
58
|
"type-fest": "5.2.0",
|
|
59
59
|
"typescript": "5.9.3",
|
|
60
|
-
"typescript-eslint": "8.
|
|
60
|
+
"typescript-eslint": "8.48.0",
|
|
61
61
|
"unplugin-unused": "0.5.6",
|
|
62
|
-
"vitest": "4.0.
|
|
62
|
+
"vitest": "4.0.14"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@anthropic-ai/claude-agent-sdk": "0.1.
|
|
65
|
+
"@anthropic-ai/claude-agent-sdk": "0.1.56",
|
|
66
66
|
"valibot": "^1.1.0"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|