@h-rig/hook-kit 0.0.6-alpha.77 → 0.0.6-alpha.79

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.
@@ -0,0 +1,35 @@
1
+ /** Read build-time baked config. Exported for use by sibling modules in hook-kit. */
2
+ export declare function readBuildConfigForKit(): Record<string, string>;
3
+ export declare const BAKED_PROJECT_ROOT: string;
4
+ export declare const BAKED_TASK_ID: string;
5
+ export declare const BAKED_STATE_DIR: string;
6
+ export declare const BAKED_BUN_PATH: string;
7
+ export declare const BAKED_TASK_CONFIG: string;
8
+ export declare const BAKED_POLICY_CONTENT: string;
9
+ export declare const BAKED_TASK_SCOPES: string;
10
+ export type HookContext = {
11
+ taskId: string;
12
+ role: string;
13
+ scopes: string[];
14
+ validation: string[];
15
+ hostProjectRoot?: string | undefined;
16
+ monorepoMainRoot?: string | undefined;
17
+ stateDir: string;
18
+ policyFile: string;
19
+ };
20
+ /** Load HookContext from the runtime context JSON file, or return null. */
21
+ export declare function loadHookContextFromEnv(): HookContext | null;
22
+ /** Resolve the project root from HookContext, baked constant, env, or CWD heuristic. */
23
+ export declare function resolveProjectRoot(): string;
24
+ /** Resolve the current task ID from HookContext, baked constant, or env vars. */
25
+ export declare function resolveTaskIdForHook(_projectRoot: string): string;
26
+ /** Get task config from HookContext, baked constant, or disk. */
27
+ export declare function resolveTaskConfig(_projectRoot: string, _taskId: string): Promise<{
28
+ scope?: string[];
29
+ validation?: string[];
30
+ role?: string;
31
+ }>;
32
+ /** Get scope globs from HookContext, baked constant, or disk config. */
33
+ export declare function resolveTaskScopes(projectRoot: string, taskId: string): Promise<string[]>;
34
+ /** Get policy content from HookContext, baked constant, or disk. */
35
+ export declare function resolvePolicyContent(projectRoot: string): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Block the current action, log the trip, and exit non-zero.
3
+ *
4
+ * Writes a BLOCKED message to stdout (so Claude Code sees it immediately),
5
+ * appends to the hook_trips.log in stateDir, and calls `process.exit(1)`.
6
+ *
7
+ * After 3 trips for the same hookName an escalation line is appended to the
8
+ * message. The escalation text is intentionally generic so Rig plugins can
9
+ * override the CLAUDE.md reference.
10
+ */
11
+ export declare function block(hookName: string, message: string, projectRoot: string): never;
@@ -0,0 +1,10 @@
1
+ export type { HookInput, ParsedHookInput } from "./io";
2
+ export { readHookInput } from "./io";
3
+ export type { HookContext } from "./context";
4
+ export { BAKED_PROJECT_ROOT, BAKED_TASK_ID, BAKED_STATE_DIR, BAKED_BUN_PATH, BAKED_TASK_CONFIG, BAKED_POLICY_CONTENT, BAKED_TASK_SCOPES, resolveProjectRoot, resolveTaskIdForHook, resolveTaskConfig, resolveTaskScopes, resolvePolicyContent, } from "./context";
5
+ export { block } from "./guard";
6
+ export type { TypedHookOptions } from "./typed";
7
+ export { buildPluginHookContext, hookResultToProtocol, runTypedHook, } from "./typed";
8
+ export { extractToolFilePaths, isTestFilePath } from "./tools";
9
+ export { resolveBunCli, resolveBunCliInvocation } from "./runtime";
10
+ export { escapeRegExp } from "./utils";
@@ -0,0 +1,14 @@
1
+ /** JSON shape of a Claude Code hook payload. */
2
+ export type HookInput = {
3
+ tool_name?: string;
4
+ tool_input?: Record<string, unknown>;
5
+ command?: string;
6
+ };
7
+ /** Wrapper around `HookInput` with parse-success flags. */
8
+ export type ParsedHookInput = {
9
+ input: HookInput;
10
+ valid: boolean;
11
+ hadPayload: boolean;
12
+ };
13
+ /** Read and parse the JSON hook payload from stdin or `RIG_HOOK_INPUT_FILE`. */
14
+ export declare function readHookInput(): Promise<ParsedHookInput>;
@@ -0,0 +1,7 @@
1
+ /** Returns the bun binary path string. */
2
+ export declare function resolveBunCli(): string;
3
+ /** Returns `{ command, env }` for spawning bun. */
4
+ export declare function resolveBunCliInvocation(): {
5
+ command: string;
6
+ env: Record<string, string>;
7
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Tool-input helpers for hook binaries.
3
+ *
4
+ * Moved from packages/runtime/src/control-plane/hooks/shared.ts
5
+ * in Phase 5 Task 5.3 of the Rig extraction.
6
+ */
7
+ /** Extract file path candidates from tool input for pre-guard worktree checks. */
8
+ export declare function extractToolFilePaths(toolName: string, input: Record<string, unknown>): string[];
9
+ /** Check whether a file path looks like a test file. */
10
+ export declare function isTestFilePath(path: string): boolean;
@@ -0,0 +1,33 @@
1
+ import type { HookContext as PluginHookContext, HookEvent, HookImplementation, HookResult } from "@rig/contracts";
2
+ import { type ParsedHookInput } from "./io";
3
+ export interface TypedHookOptions {
4
+ /** The lifecycle event this hook is registered for (from its metadata). */
5
+ event: HookEvent;
6
+ /** Project root override; resolved via `resolveProjectRoot()` when absent. */
7
+ projectRoot?: string;
8
+ /** Task id override; resolved via `resolveTaskIdForHook()` when absent. */
9
+ taskId?: string;
10
+ }
11
+ /**
12
+ * Build the typed-hook input from a parsed Claude Code hook payload.
13
+ * Pure — exported for tests and for the plugin-testkit helpers.
14
+ */
15
+ export declare function buildPluginHookContext(parsed: ParsedHookInput, opts: {
16
+ event: HookEvent;
17
+ projectRoot: string;
18
+ taskId: string;
19
+ }): PluginHookContext;
20
+ /**
21
+ * Serialize a HookResult to the Claude Code hook protocol. Pure — the
22
+ * exit/stdout side effects happen in `runTypedHook`.
23
+ */
24
+ export declare function hookResultToProtocol(result: HookResult): {
25
+ exitCode: 0 | 1;
26
+ stdout: string;
27
+ };
28
+ /**
29
+ * Run a typed hook implementation against the current process's hook
30
+ * invocation: parse stdin into a HookContext, call the function, write the
31
+ * protocol output, and exit. Never returns.
32
+ */
33
+ export declare function runTypedHook(fn: HookImplementation, opts: TypedHookOptions): Promise<never>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * General utility helpers for hook binaries.
3
+ *
4
+ * Moved from packages/runtime/src/control-plane/hooks/shared.ts
5
+ * in Phase 5 Task 5.3 of the Rig extraction.
6
+ */
7
+ /** Escape special regex characters in a string. */
8
+ export declare function escapeRegExp(value: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h-rig/hook-kit",
3
- "version": "0.0.6-alpha.77",
3
+ "version": "0.0.6-alpha.79",
4
4
  "type": "module",
5
5
  "description": "Rig package",
6
6
  "license": "UNLICENSED",
@@ -10,6 +10,7 @@
10
10
  ],
11
11
  "exports": {
12
12
  ".": {
13
+ "types": "./dist/src/index.d.ts",
13
14
  "import": "./dist/src/index.js"
14
15
  }
15
16
  },
@@ -18,8 +19,9 @@
18
19
  },
19
20
  "main": "./dist/src/index.js",
20
21
  "module": "./dist/src/index.js",
22
+ "types": "./dist/src/index.d.ts",
21
23
  "dependencies": {
22
- "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.77",
24
+ "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.79",
23
25
  "effect": "4.0.0-beta.78"
24
26
  }
25
27
  }