cc-hooks-ts 2.0.43 → 2.0.55
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 +114 -1
- package/dist/index.mjs +63 -1
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -111,6 +111,53 @@ declare const HookInputSchemas: {
|
|
|
111
111
|
} & {
|
|
112
112
|
reason: v.StringSchema<undefined>;
|
|
113
113
|
}, undefined>;
|
|
114
|
+
readonly PermissionRequest: v.ObjectSchema<{
|
|
115
|
+
readonly cwd: v.StringSchema<undefined>;
|
|
116
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
117
|
+
readonly session_id: v.StringSchema<undefined>;
|
|
118
|
+
readonly transcript_path: v.StringSchema<undefined>;
|
|
119
|
+
readonly hook_event_name: v.LiteralSchema<"PermissionRequest", undefined>;
|
|
120
|
+
} & {
|
|
121
|
+
permission_suggestions: v.ExactOptionalSchema<v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
122
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
123
|
+
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>;
|
|
124
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
125
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
126
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
127
|
+
}, undefined>, undefined>;
|
|
128
|
+
readonly type: v.LiteralSchema<"addRules", undefined>;
|
|
129
|
+
}, undefined>, v.ObjectSchema<{
|
|
130
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
131
|
+
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>;
|
|
132
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
133
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
134
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
135
|
+
}, undefined>, undefined>;
|
|
136
|
+
readonly type: v.LiteralSchema<"replaceRules", undefined>;
|
|
137
|
+
}, undefined>, v.ObjectSchema<{
|
|
138
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
139
|
+
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>;
|
|
140
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
141
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
142
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
143
|
+
}, undefined>, undefined>;
|
|
144
|
+
readonly type: v.LiteralSchema<"removeRules", undefined>;
|
|
145
|
+
}, undefined>, v.ObjectSchema<{
|
|
146
|
+
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>;
|
|
147
|
+
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>;
|
|
148
|
+
readonly type: v.LiteralSchema<"setMode", undefined>;
|
|
149
|
+
}, undefined>, v.ObjectSchema<{
|
|
150
|
+
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>;
|
|
151
|
+
readonly directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
152
|
+
readonly type: v.LiteralSchema<"addDirectories", undefined>;
|
|
153
|
+
}, undefined>, v.ObjectSchema<{
|
|
154
|
+
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>;
|
|
155
|
+
readonly directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
156
|
+
readonly type: v.LiteralSchema<"removeDirectories", undefined>;
|
|
157
|
+
}, undefined>], undefined>, undefined>, undefined>;
|
|
158
|
+
tool_input: v.UnknownSchema;
|
|
159
|
+
tool_name: v.StringSchema<undefined>;
|
|
160
|
+
}, undefined>;
|
|
114
161
|
};
|
|
115
162
|
//#endregion
|
|
116
163
|
//#region src/hooks/event.d.ts
|
|
@@ -119,7 +166,7 @@ declare const HookInputSchemas: {
|
|
|
119
166
|
*
|
|
120
167
|
* @package
|
|
121
168
|
*/
|
|
122
|
-
type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "Notification" | "UserPromptSubmit" | "SessionStart" | "SessionEnd" | "Stop" | "SubagentStop" | "PreCompact" | "
|
|
169
|
+
type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "Notification" | "UserPromptSubmit" | "SessionStart" | "SessionEnd" | "Stop" | "SubagentStart" | "SubagentStop" | "PreCompact" | "PermissionRequest";
|
|
123
170
|
//#endregion
|
|
124
171
|
//#region src/hooks/input/types.d.ts
|
|
125
172
|
/**
|
|
@@ -194,6 +241,49 @@ type ToolSpecificPostToolUseInput = { [K in keyof ToolSchema]: Omit<BaseHookInpu
|
|
|
194
241
|
tool_response: ToolSchema[K]["response"];
|
|
195
242
|
} };
|
|
196
243
|
//#endregion
|
|
244
|
+
//#region src/hooks/permission.d.ts
|
|
245
|
+
/**
|
|
246
|
+
* @package
|
|
247
|
+
*/
|
|
248
|
+
declare const permissionUpdateSchema: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
249
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
250
|
+
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>;
|
|
251
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
252
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
253
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
254
|
+
}, undefined>, undefined>;
|
|
255
|
+
readonly type: v.LiteralSchema<"addRules", undefined>;
|
|
256
|
+
}, undefined>, v.ObjectSchema<{
|
|
257
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
258
|
+
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>;
|
|
259
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
260
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
261
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
262
|
+
}, undefined>, undefined>;
|
|
263
|
+
readonly type: v.LiteralSchema<"replaceRules", undefined>;
|
|
264
|
+
}, undefined>, v.ObjectSchema<{
|
|
265
|
+
readonly behavior: v.UnionSchema<[v.LiteralSchema<"allow", undefined>, v.LiteralSchema<"deny", undefined>, v.LiteralSchema<"ask", undefined>], undefined>;
|
|
266
|
+
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>;
|
|
267
|
+
readonly rules: v.ArraySchema<v.ObjectSchema<{
|
|
268
|
+
readonly ruleContent: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
269
|
+
readonly toolName: v.StringSchema<undefined>;
|
|
270
|
+
}, undefined>, undefined>;
|
|
271
|
+
readonly type: v.LiteralSchema<"removeRules", undefined>;
|
|
272
|
+
}, undefined>, v.ObjectSchema<{
|
|
273
|
+
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>;
|
|
274
|
+
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>;
|
|
275
|
+
readonly type: v.LiteralSchema<"setMode", undefined>;
|
|
276
|
+
}, undefined>, v.ObjectSchema<{
|
|
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 directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
279
|
+
readonly type: v.LiteralSchema<"addDirectories", undefined>;
|
|
280
|
+
}, undefined>, v.ObjectSchema<{
|
|
281
|
+
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>;
|
|
282
|
+
readonly directories: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
283
|
+
readonly type: v.LiteralSchema<"removeDirectories", undefined>;
|
|
284
|
+
}, undefined>], undefined>;
|
|
285
|
+
type PermissionUpdate = v.InferOutput<typeof permissionUpdateSchema>;
|
|
286
|
+
//#endregion
|
|
197
287
|
//#region src/hooks/output/index.d.ts
|
|
198
288
|
/**
|
|
199
289
|
* @package
|
|
@@ -206,6 +296,7 @@ type HookOutput = {
|
|
|
206
296
|
SubagentStart: SubagentStartHookOutput;
|
|
207
297
|
SubagentStop: SubagentStopHookOutput;
|
|
208
298
|
SessionStart: SessionStartHookOutput;
|
|
299
|
+
PermissionRequest: PermissionRequestHookOutput;
|
|
209
300
|
Notification: CommonHookOutputs;
|
|
210
301
|
PreCompact: CommonHookOutputs;
|
|
211
302
|
SessionEnd: CommonHookOutputs;
|
|
@@ -355,6 +446,28 @@ interface SessionStartHookOutput extends CommonHookOutputs {
|
|
|
355
446
|
additionalContext?: string;
|
|
356
447
|
};
|
|
357
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* @see {@link https://code.claude.com/docs/en/hooks#permissionrequest-decision-control}
|
|
451
|
+
*/
|
|
452
|
+
interface PermissionRequestHookOutput extends CommonHookOutputs {
|
|
453
|
+
hookSpecificOutput?: {
|
|
454
|
+
hookEventName: "PermissionRequest";
|
|
455
|
+
/**
|
|
456
|
+
* For `behavior: "allow"` you can also optionally pass in an `updatedInput` that modifies the tool’s input parameters before the tool executes.
|
|
457
|
+
*
|
|
458
|
+
* For `behavior: "deny"` you can also optionally pass in a `message` string that tells the model why the permission was denied, and a boolean `interrupt` which will stop Claude.
|
|
459
|
+
*/
|
|
460
|
+
decision: {
|
|
461
|
+
behavior: "allow";
|
|
462
|
+
updatedInput?: Record<string, unknown>;
|
|
463
|
+
updatedPermissions?: PermissionUpdate[];
|
|
464
|
+
} | {
|
|
465
|
+
behavior: "deny";
|
|
466
|
+
interrupt?: boolean;
|
|
467
|
+
message?: string;
|
|
468
|
+
};
|
|
469
|
+
};
|
|
470
|
+
}
|
|
358
471
|
//#endregion
|
|
359
472
|
//#region src/types.d.ts
|
|
360
473
|
type HookTrigger = Partial<{ [TEvent in SupportedHookEvent]: true | Partial<{ [SchemaKey in ExtractExtendedSpecificKeys<TEvent>]?: true }> }>;
|
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()),
|
|
@@ -79,7 +136,12 @@ const HookInputSchemas = {
|
|
|
79
136
|
v.literal("clear"),
|
|
80
137
|
v.literal("compact")
|
|
81
138
|
]) }),
|
|
82
|
-
SessionEnd: buildHookInputSchema("SessionEnd", { reason: v.string() })
|
|
139
|
+
SessionEnd: buildHookInputSchema("SessionEnd", { reason: v.string() }),
|
|
140
|
+
PermissionRequest: buildHookInputSchema("PermissionRequest", {
|
|
141
|
+
permission_suggestions: v.exactOptional(v.array(permissionUpdateSchema)),
|
|
142
|
+
tool_input: v.unknown(),
|
|
143
|
+
tool_name: v.string()
|
|
144
|
+
})
|
|
83
145
|
};
|
|
84
146
|
function isNonEmptyString(value) {
|
|
85
147
|
return typeof value === "string" && value.length > 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-hooks-ts",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.55",
|
|
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.7",
|
|
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.6",
|
|
58
58
|
"type-fest": "5.2.0",
|
|
59
59
|
"typescript": "5.9.3",
|
|
60
|
-
"typescript-eslint": "8.
|
|
60
|
+
"typescript-eslint": "8.47.0",
|
|
61
61
|
"unplugin-unused": "0.5.6",
|
|
62
|
-
"vitest": "4.0.
|
|
62
|
+
"vitest": "4.0.13"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@anthropic-ai/claude-agent-sdk": "0.1.
|
|
65
|
+
"@anthropic-ai/claude-agent-sdk": "0.1.55",
|
|
66
66
|
"valibot": "^1.1.0"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|