cc-hooks-ts 0.0.2 → 0.0.4
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/README.md +5 -3
- package/dist/index.d.mts +6 -5
- package/dist/index.mjs +5 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Define Claude Code hooks with full type safety using TypeScript and Valibot vali
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npx
|
|
8
|
+
npx nypm add cc-hooks-ts
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Basic Usage
|
|
@@ -24,11 +24,13 @@ With Bun:
|
|
|
24
24
|
#!/usr/bin/env -S bun run --silent
|
|
25
25
|
import { defineHook, runHook } from "cc-hooks-ts";
|
|
26
26
|
|
|
27
|
+
// Session start hook
|
|
27
28
|
const sessionHook = defineHook({
|
|
28
29
|
trigger: { SessionStart: true },
|
|
29
30
|
run: (context) => {
|
|
31
|
+
// do something great
|
|
30
32
|
return context.success({
|
|
31
|
-
messageForUser: "
|
|
33
|
+
messageForUser: "Welcome to your coding session!"
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
36
|
});
|
|
@@ -46,7 +48,7 @@ import { defineHook, runHook } from "npm:cc-hooks-ts";
|
|
|
46
48
|
const sessionHook = defineHook({
|
|
47
49
|
trigger: { SessionStart: true },
|
|
48
50
|
run: (context) => {
|
|
49
|
-
|
|
51
|
+
// do something great
|
|
50
52
|
return context.success({
|
|
51
53
|
messageForUser: "Welcome to your coding session!"
|
|
52
54
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -143,6 +143,10 @@ interface SessionStartHookOutput extends CommonHookOutputs {
|
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
//#endregion
|
|
146
|
+
//#region src/utils/types.d.ts
|
|
147
|
+
type Awaitable<T> = Promise<T> | T;
|
|
148
|
+
type AutoComplete<T extends string> = Record<string, never> & T;
|
|
149
|
+
//#endregion
|
|
146
150
|
//#region src/input/schemas.d.ts
|
|
147
151
|
/**
|
|
148
152
|
* @package
|
|
@@ -154,8 +158,8 @@ declare const HookInputSchemas: {
|
|
|
154
158
|
readonly session_id: v.StringSchema<undefined>;
|
|
155
159
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
156
160
|
} & {
|
|
161
|
+
tool_name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, AutoComplete<string>>]>;
|
|
157
162
|
tool_input: v.UnknownSchema;
|
|
158
|
-
tool_name: v.IntersectSchema<[v.StringSchema<undefined>, v.RecordSchema<v.StringSchema<undefined>, v.NeverSchema<undefined>, undefined>], undefined>;
|
|
159
163
|
}, undefined>;
|
|
160
164
|
readonly PostToolUse: v.ObjectSchema<{
|
|
161
165
|
readonly hook_event_name: v.LiteralSchema<"PostToolUse", undefined>;
|
|
@@ -163,8 +167,8 @@ declare const HookInputSchemas: {
|
|
|
163
167
|
readonly session_id: v.StringSchema<undefined>;
|
|
164
168
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
165
169
|
} & {
|
|
170
|
+
tool_name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, AutoComplete<string>>]>;
|
|
166
171
|
tool_input: v.UnknownSchema;
|
|
167
|
-
tool_name: v.StringSchema<undefined>;
|
|
168
172
|
tool_response: v.UnknownSchema;
|
|
169
173
|
}, undefined>;
|
|
170
174
|
readonly Notification: v.ObjectSchema<{
|
|
@@ -371,9 +375,6 @@ type HookResultJSON<TTrigger extends HookTrigger> = { [EventKey in keyof TTrigge
|
|
|
371
375
|
output: ExtractHookOutput<EventKey>;
|
|
372
376
|
} : never : never }[keyof TTrigger];
|
|
373
377
|
//#endregion
|
|
374
|
-
//#region src/utils/types.d.ts
|
|
375
|
-
type Awaitable<T> = Promise<T> | T;
|
|
376
|
-
//#endregion
|
|
377
378
|
//#region src/define.d.ts
|
|
378
379
|
/**
|
|
379
380
|
* Creates a type-safe Claude Code hook definition.
|
package/dist/index.mjs
CHANGED
|
@@ -54,12 +54,12 @@ function buildHookInputSchema(hook_event_name, entries) {
|
|
|
54
54
|
}
|
|
55
55
|
const HookInputSchemas = {
|
|
56
56
|
PreToolUse: buildHookInputSchema("PreToolUse", {
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
tool_name: v.pipe(v.string(), v.transform((s) => s)),
|
|
58
|
+
tool_input: v.unknown()
|
|
59
59
|
}),
|
|
60
60
|
PostToolUse: buildHookInputSchema("PostToolUse", {
|
|
61
|
+
tool_name: v.pipe(v.string(), v.transform((s) => s)),
|
|
61
62
|
tool_input: v.unknown(),
|
|
62
|
-
tool_name: v.string(),
|
|
63
63
|
tool_response: v.unknown()
|
|
64
64
|
}),
|
|
65
65
|
Notification: buildHookInputSchema("Notification", { message: v.optional(v.string()) }),
|
|
@@ -103,10 +103,8 @@ function handleHookResult(eventName, hookResult) {
|
|
|
103
103
|
switch (hookResult.kind) {
|
|
104
104
|
case "success":
|
|
105
105
|
if (eventName === "UserPromptSubmit" || eventName === "SessionStart") {
|
|
106
|
-
if (isNonEmptyString(hookResult.payload.additionalClaudeContext))
|
|
107
|
-
|
|
108
|
-
return process.exit(0);
|
|
109
|
-
}
|
|
106
|
+
if (isNonEmptyString(hookResult.payload.additionalClaudeContext)) console.log(hookResult.payload.additionalClaudeContext);
|
|
107
|
+
return process.exit(0);
|
|
110
108
|
}
|
|
111
109
|
if (isNonEmptyString(hookResult.payload.messageForUser)) console.log(hookResult.payload.messageForUser);
|
|
112
110
|
return process.exit(0);
|