@hasna/hooks 0.2.20 → 0.3.0
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 +45 -2
- package/bin/index.js +1157 -84
- package/dist/db/migrations/002_session_events.d.ts +10 -0
- package/dist/db/migrations/003_user_prompt_submit_event.d.ts +10 -0
- package/dist/db/pg-migrations.d.ts +1 -1
- package/dist/db/remote-storage.d.ts +9 -0
- package/dist/db/schema.d.ts +4 -3
- package/dist/db/storage-sync.d.ts +57 -0
- package/dist/index.d.ts +16 -3
- package/dist/index.js +1042 -58
- package/dist/lib/installer.d.ts +25 -5
- package/dist/lib/registry.d.ts +3 -1
- package/dist/storage.d.ts +4 -0
- package/dist/storage.js +696 -0
- package/hooks/codewith-native-common.test.ts +61 -0
- package/hooks/codewith-native-common.ts +478 -0
- package/hooks/hook-agent-rules-version-check/LICENSE +191 -0
- package/hooks/hook-agent-rules-version-check/README.md +50 -0
- package/hooks/hook-agent-rules-version-check/package.json +53 -0
- package/hooks/hook-agent-rules-version-check/src/hook.test.ts +104 -0
- package/hooks/hook-agent-rules-version-check/src/hook.ts +215 -0
- package/hooks/hook-agent-rules-version-check/tsconfig.json +25 -0
- package/hooks/hook-announce-start/README.md +7 -5
- package/hooks/hook-announce-start/package.json +2 -2
- package/hooks/hook-announce-start/src/hook.ts +33 -14
- package/hooks/hook-fleet-blockers-gate/LICENSE +191 -0
- package/hooks/hook-fleet-blockers-gate/README.md +39 -0
- package/hooks/hook-fleet-blockers-gate/package.json +52 -0
- package/hooks/hook-fleet-blockers-gate/src/hook.test.ts +106 -0
- package/hooks/hook-fleet-blockers-gate/src/hook.ts +242 -0
- package/hooks/hook-fleet-blockers-gate/tsconfig.json +25 -0
- package/hooks/hook-fleet-catchup/LICENSE +191 -0
- package/hooks/hook-fleet-catchup/README.md +40 -0
- package/hooks/hook-fleet-catchup/package.json +52 -0
- package/hooks/hook-fleet-catchup/src/hook.test.ts +156 -0
- package/hooks/hook-fleet-catchup/src/hook.ts +283 -0
- package/hooks/hook-fleet-catchup/tsconfig.json +25 -0
- package/hooks/pre-bash/README.md +17 -0
- package/hooks/pre-bash/package.json +12 -0
- package/hooks/pre-bash/src/hook.ts +103 -0
- package/hooks/prompt-guard/README.md +17 -0
- package/hooks/prompt-guard/package.json +12 -0
- package/hooks/prompt-guard/src/hook.ts +76 -0
- package/hooks/session-start/README.md +17 -0
- package/hooks/session-start/package.json +12 -0
- package/hooks/session-start/src/hook.ts +150 -0
- package/hooks/stop-sync/README.md +17 -0
- package/hooks/stop-sync/package.json +12 -0
- package/hooks/stop-sync/src/hook.ts +69 -0
- package/hooks/worktree-guard/README.md +17 -0
- package/hooks/worktree-guard/package.json +12 -0
- package/hooks/worktree-guard/src/hook.ts +88 -0
- package/package.json +14 -6
- package/dist/cli/components/App.d.ts +0 -7
- package/dist/cli/components/CategorySelect.d.ts +0 -7
- package/dist/cli/components/DataTable.d.ts +0 -11
- package/dist/cli/components/Header.d.ts +0 -7
- package/dist/cli/components/HookSelect.d.ts +0 -11
- package/dist/cli/components/InstallProgress.d.ts +0 -9
- package/dist/cli/components/SearchView.d.ts +0 -9
- package/dist/cli/index.d.ts +0 -2
- package/dist/lib/db-writer.d.ts +0 -9
- package/dist/mcp/http.d.ts +0 -16
- package/dist/mcp/server.d.ts +0 -17
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 002 — session events
|
|
3
|
+
* Rebuilds hook_events so the event_type CHECK constraint accepts
|
|
4
|
+
* 'SessionStart' and 'SessionEnd'. SQLite cannot ALTER a CHECK
|
|
5
|
+
* constraint, so the table is recreated and rows are copied over.
|
|
6
|
+
* Skips the rebuild when the constraint already includes SessionStart
|
|
7
|
+
* (fresh databases created from the updated schema.ts).
|
|
8
|
+
*/
|
|
9
|
+
import type { Database } from "bun:sqlite";
|
|
10
|
+
export declare function up(db: Database): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 003 — UserPromptSubmit event.
|
|
3
|
+
*
|
|
4
|
+
* Rebuilds hook_events so the event_type CHECK constraint accepts Codewith's
|
|
5
|
+
* UserPromptSubmit. SQLite cannot ALTER a CHECK constraint, so the table is
|
|
6
|
+
* recreated and rows are copied over. Skips the rebuild when the constraint is
|
|
7
|
+
* already current (fresh databases or databases rebuilt by a newer 002).
|
|
8
|
+
*/
|
|
9
|
+
import type { Database } from "bun:sqlite";
|
|
10
|
+
export declare function up(db: Database): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class PgAdapterAsync {
|
|
2
|
+
private readonly pool;
|
|
3
|
+
constructor(connectionString: string);
|
|
4
|
+
run(sql: string, ...params: unknown[]): Promise<{
|
|
5
|
+
changes: number;
|
|
6
|
+
}>;
|
|
7
|
+
all(sql: string, ...params: unknown[]): Promise<unknown[]>;
|
|
8
|
+
close(): Promise<void>;
|
|
9
|
+
}
|
package/dist/db/schema.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* SQLite schema for @hasna/hooks local data.
|
|
3
|
+
* Owned by this package (no shared runtime dependency).
|
|
3
4
|
*/
|
|
4
5
|
import type { Database } from "bun:sqlite";
|
|
5
|
-
export declare const CREATE_HOOK_EVENTS_TABLE = "\n CREATE TABLE IF NOT EXISTS hook_events (\n id TEXT PRIMARY KEY,\n timestamp TEXT NOT NULL,\n session_id TEXT NOT NULL,\n hook_name TEXT NOT NULL,\n event_type TEXT NOT NULL CHECK (event_type IN ('PreToolUse', 'PostToolUse', 'Stop', 'Notification')),\n tool_name TEXT,\n tool_input TEXT,\n result TEXT CHECK (result IN ('continue', 'block', NULL)),\n error TEXT,\n duration_ms INTEGER,\n project_dir TEXT,\n metadata TEXT\n )\n";
|
|
6
|
+
export declare const CREATE_HOOK_EVENTS_TABLE = "\n CREATE TABLE IF NOT EXISTS hook_events (\n id TEXT PRIMARY KEY,\n timestamp TEXT NOT NULL,\n session_id TEXT NOT NULL,\n hook_name TEXT NOT NULL,\n event_type TEXT NOT NULL CHECK (event_type IN ('PreToolUse', 'PostToolUse', 'Stop', 'Notification', 'SessionStart', 'SessionEnd', 'UserPromptSubmit')),\n tool_name TEXT,\n tool_input TEXT,\n result TEXT CHECK (result IN ('continue', 'block', NULL)),\n error TEXT,\n duration_ms INTEGER,\n project_dir TEXT,\n metadata TEXT\n )\n";
|
|
6
7
|
export declare const CREATE_INDEXES: string[];
|
|
7
8
|
export interface HookEventRow {
|
|
8
9
|
id: string;
|
|
9
10
|
timestamp: string;
|
|
10
11
|
session_id: string;
|
|
11
12
|
hook_name: string;
|
|
12
|
-
event_type: "PreToolUse" | "PostToolUse" | "Stop" | "Notification";
|
|
13
|
+
event_type: "PreToolUse" | "PostToolUse" | "Stop" | "Notification" | "SessionStart" | "SessionEnd" | "UserPromptSubmit";
|
|
13
14
|
tool_name: string | null;
|
|
14
15
|
tool_input: string | null;
|
|
15
16
|
result: "continue" | "block" | null;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { PgAdapterAsync } from "./remote-storage.js";
|
|
2
|
+
export declare const STORAGE_TABLES: readonly ["hook_events", "schema_migrations", "_meta", "feedback"];
|
|
3
|
+
export declare const HOOKS_STORAGE_TABLES: readonly ["hook_events", "schema_migrations", "_meta", "feedback"];
|
|
4
|
+
type StorageTable = (typeof STORAGE_TABLES)[number];
|
|
5
|
+
export type StorageMode = "local" | "hybrid" | "remote";
|
|
6
|
+
export interface StorageEnv {
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
export interface SyncResult {
|
|
10
|
+
table: string;
|
|
11
|
+
rowsRead: number;
|
|
12
|
+
rowsWritten: number;
|
|
13
|
+
errors: string[];
|
|
14
|
+
}
|
|
15
|
+
export interface SyncMeta {
|
|
16
|
+
table_name: string;
|
|
17
|
+
last_synced_at: string | null;
|
|
18
|
+
direction: "push" | "pull";
|
|
19
|
+
}
|
|
20
|
+
export declare const HOOKS_STORAGE_ENV = "HASNA_HOOKS_DATABASE_URL";
|
|
21
|
+
export declare const HOOKS_STORAGE_FALLBACK_ENV = "HOOKS_DATABASE_URL";
|
|
22
|
+
export declare const HOOKS_STORAGE_MODE_ENV = "HASNA_HOOKS_STORAGE_MODE";
|
|
23
|
+
export declare const HOOKS_STORAGE_MODE_FALLBACK_ENV = "HOOKS_STORAGE_MODE";
|
|
24
|
+
export declare const STORAGE_DATABASE_ENV: readonly ["HASNA_HOOKS_DATABASE_URL", "HOOKS_DATABASE_URL"];
|
|
25
|
+
export declare const STORAGE_MODE_ENV: readonly ["HASNA_HOOKS_STORAGE_MODE", "HOOKS_STORAGE_MODE"];
|
|
26
|
+
export interface StorageStatus {
|
|
27
|
+
configured: boolean;
|
|
28
|
+
mode: StorageMode;
|
|
29
|
+
env: typeof STORAGE_DATABASE_ENV;
|
|
30
|
+
activeEnv: string | null;
|
|
31
|
+
service: "hooks";
|
|
32
|
+
tables: typeof STORAGE_TABLES;
|
|
33
|
+
sync: SyncMeta[];
|
|
34
|
+
}
|
|
35
|
+
export declare function getStorageDatabaseEnvName(): (typeof STORAGE_DATABASE_ENV)[number] | null;
|
|
36
|
+
export declare function getStorageDatabaseEnv(): StorageEnv | null;
|
|
37
|
+
export declare function getStorageDatabaseUrl(): string | null;
|
|
38
|
+
export declare function getStorageMode(): StorageMode;
|
|
39
|
+
export declare function getStoragePg(): Promise<PgAdapterAsync>;
|
|
40
|
+
export declare function runStorageMigrations(remote: PgAdapterAsync): Promise<void>;
|
|
41
|
+
export declare function storagePush(options?: {
|
|
42
|
+
tables?: string[];
|
|
43
|
+
}): Promise<SyncResult[]>;
|
|
44
|
+
export declare function storagePull(options?: {
|
|
45
|
+
tables?: string[];
|
|
46
|
+
}): Promise<SyncResult[]>;
|
|
47
|
+
export declare function storageSync(options?: {
|
|
48
|
+
tables?: string[];
|
|
49
|
+
}): Promise<{
|
|
50
|
+
pull: SyncResult[];
|
|
51
|
+
push: SyncResult[];
|
|
52
|
+
}>;
|
|
53
|
+
export declare function getSyncMetaAll(): SyncMeta[];
|
|
54
|
+
export declare function getStorageStatus(): StorageStatus;
|
|
55
|
+
export declare function resolveTables(tables?: string[]): StorageTable[];
|
|
56
|
+
export declare function parseStorageTables(value?: string | string[] | null): StorageTable[] | undefined;
|
|
57
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
* Or use the interactive CLI:
|
|
8
8
|
* npx @hasna/hooks
|
|
9
9
|
*/
|
|
10
|
-
export { HOOKS, CATEGORIES, getHook, getHooksByCategory, searchHooks, type HookMeta, type Category, } from "./lib/registry.js";
|
|
11
|
-
|
|
10
|
+
export { HOOKS, HOOK_EVENTS, CATEGORIES, getHook, getHooksByCategory, searchHooks, type HookMeta, type HookEvent, type Category, } from "./lib/registry.js";
|
|
11
|
+
import type { HookEvent as HookEventType } from "./lib/registry.js";
|
|
12
|
+
export { installHook, installHooks, getInstalledHooks, getRegisteredHooks, getRegisteredHooksForTarget, removeHook, hookExists, buildCodewithTomlFragment, getHookPath, getSettingsPath, isEventSupported, type InstallResult, type InstallOptions, type Scope, type Target, type CodewithInstallMode, } from "./lib/installer.js";
|
|
12
13
|
export interface HookAgentInfo {
|
|
13
14
|
agent_id: string;
|
|
14
|
-
agent_type: "claude" | "gemini" | "custom";
|
|
15
|
+
agent_type: "claude" | "gemini" | "codewith" | "custom";
|
|
15
16
|
name?: string;
|
|
16
17
|
preferences?: Record<string, unknown>;
|
|
17
18
|
}
|
|
@@ -19,6 +20,8 @@ export interface HookAgentInfo {
|
|
|
19
20
|
export interface HookInput {
|
|
20
21
|
session_id?: string;
|
|
21
22
|
cwd?: string;
|
|
23
|
+
hook_event_name?: HookEventType | string;
|
|
24
|
+
prompt?: string;
|
|
22
25
|
tool_name?: string;
|
|
23
26
|
tool_input?: Record<string, unknown>;
|
|
24
27
|
agent?: HookAgentInfo;
|
|
@@ -28,6 +31,14 @@ export interface HookInput {
|
|
|
28
31
|
export interface HookOutput {
|
|
29
32
|
decision?: "approve" | "block";
|
|
30
33
|
reason?: string;
|
|
34
|
+
continue?: boolean;
|
|
35
|
+
hookSpecificOutput?: {
|
|
36
|
+
hookEventName: "SessionStart" | "UserPromptSubmit" | "PreToolUse" | "PostToolUse" | "Stop" | "Notification" | "SessionEnd";
|
|
37
|
+
additionalContext?: string;
|
|
38
|
+
permissionDecision?: "allow" | "deny" | "ask";
|
|
39
|
+
permissionDecisionReason?: string;
|
|
40
|
+
updatedInput?: unknown;
|
|
41
|
+
};
|
|
31
42
|
[key: string]: unknown;
|
|
32
43
|
}
|
|
33
44
|
import type { InstallOptions, InstallResult } from "./lib/installer.js";
|
|
@@ -57,3 +68,5 @@ export interface RunHookResult {
|
|
|
57
68
|
*/
|
|
58
69
|
export declare function runHook(name: string, input: HookInput, options?: RunHookOptions): Promise<RunHookResult>;
|
|
59
70
|
export { createProfile, getProfile, listProfiles, updateProfile, deleteProfile, touchProfile, getProfilesDir, exportProfiles, importProfiles, type AgentProfile, type CreateProfileInput, } from "./lib/profiles.js";
|
|
71
|
+
export { HOOKS_STORAGE_ENV, HOOKS_STORAGE_FALLBACK_ENV, HOOKS_STORAGE_MODE_ENV, HOOKS_STORAGE_MODE_FALLBACK_ENV, HOOKS_STORAGE_TABLES, STORAGE_DATABASE_ENV, STORAGE_MODE_ENV, STORAGE_TABLES, getStorageDatabaseEnv, getStorageDatabaseEnvName, getStorageDatabaseUrl, getStorageMode, getStoragePg, getStorageStatus, getSyncMetaAll, parseStorageTables, resolveTables, runStorageMigrations, storagePull, storagePush, storageSync, } from "./storage.js";
|
|
72
|
+
export type { StorageEnv, StorageMode, StorageStatus, SyncMeta, SyncResult } from "./storage.js";
|