@hasna/hooks 0.0.6 → 0.1.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.
Files changed (49) hide show
  1. package/.claude/settings.json +24 -0
  2. package/bin/index.js +758 -319
  3. package/dist/index.js +156 -1
  4. package/hooks/hook-autoformat/README.md +39 -0
  5. package/hooks/hook-autoformat/package.json +58 -0
  6. package/hooks/hook-autoformat/src/hook.ts +223 -0
  7. package/hooks/hook-autostage/README.md +70 -0
  8. package/hooks/hook-autostage/package.json +12 -0
  9. package/hooks/hook-autostage/src/hook.ts +167 -0
  10. package/hooks/hook-commandlog/README.md +45 -0
  11. package/hooks/hook-commandlog/package.json +12 -0
  12. package/hooks/hook-commandlog/src/hook.ts +92 -0
  13. package/hooks/hook-costwatch/README.md +61 -0
  14. package/hooks/hook-costwatch/package.json +12 -0
  15. package/hooks/hook-costwatch/src/hook.ts +178 -0
  16. package/hooks/hook-desktopnotify/README.md +50 -0
  17. package/hooks/hook-desktopnotify/package.json +57 -0
  18. package/hooks/hook-desktopnotify/src/hook.ts +112 -0
  19. package/hooks/hook-envsetup/README.md +40 -0
  20. package/hooks/hook-envsetup/package.json +58 -0
  21. package/hooks/hook-envsetup/src/hook.ts +197 -0
  22. package/hooks/hook-errornotify/README.md +66 -0
  23. package/hooks/hook-errornotify/package.json +12 -0
  24. package/hooks/hook-errornotify/src/hook.ts +197 -0
  25. package/hooks/hook-permissionguard/README.md +48 -0
  26. package/hooks/hook-permissionguard/package.json +58 -0
  27. package/hooks/hook-permissionguard/src/hook.ts +268 -0
  28. package/hooks/hook-promptguard/README.md +64 -0
  29. package/hooks/hook-promptguard/package.json +12 -0
  30. package/hooks/hook-promptguard/src/hook.ts +200 -0
  31. package/hooks/hook-protectfiles/README.md +62 -0
  32. package/hooks/hook-protectfiles/package.json +58 -0
  33. package/hooks/hook-protectfiles/src/hook.ts +267 -0
  34. package/hooks/hook-sessionlog/README.md +48 -0
  35. package/hooks/hook-sessionlog/package.json +12 -0
  36. package/hooks/hook-sessionlog/src/hook.ts +100 -0
  37. package/hooks/hook-slacknotify/README.md +62 -0
  38. package/hooks/hook-slacknotify/package.json +12 -0
  39. package/hooks/hook-slacknotify/src/hook.ts +146 -0
  40. package/hooks/hook-soundnotify/README.md +63 -0
  41. package/hooks/hook-soundnotify/package.json +12 -0
  42. package/hooks/hook-soundnotify/src/hook.ts +173 -0
  43. package/hooks/hook-taskgate/README.md +62 -0
  44. package/hooks/hook-taskgate/package.json +12 -0
  45. package/hooks/hook-taskgate/src/hook.ts +169 -0
  46. package/hooks/hook-tddguard/README.md +50 -0
  47. package/hooks/hook-tddguard/package.json +12 -0
  48. package/hooks/hook-tddguard/src/hook.ts +263 -0
  49. package/package.json +4 -3
package/bin/index.js CHANGED
@@ -17,6 +17,16 @@ var __toESM = (mod, isNodeMode, target) => {
17
17
  return to;
18
18
  };
19
19
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, {
23
+ get: all[name],
24
+ enumerable: true,
25
+ configurable: true,
26
+ set: (newValue) => all[name] = () => newValue
27
+ });
28
+ };
29
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
20
30
  var __require = import.meta.require;
21
31
 
22
32
  // node_modules/commander/lib/error.js
@@ -1858,6 +1868,335 @@ var require_commander = __commonJS((exports) => {
1858
1868
  exports.InvalidOptionArgumentError = InvalidArgumentError;
1859
1869
  });
1860
1870
 
1871
+ // src/lib/registry.ts
1872
+ function getHooksByCategory(category) {
1873
+ return HOOKS.filter((h) => h.category === category);
1874
+ }
1875
+ function searchHooks(query) {
1876
+ const q = query.toLowerCase();
1877
+ return HOOKS.filter((h) => h.name.toLowerCase().includes(q) || h.displayName.toLowerCase().includes(q) || h.description.toLowerCase().includes(q) || h.tags.some((t) => t.includes(q)));
1878
+ }
1879
+ function getHook(name) {
1880
+ return HOOKS.find((h) => h.name === name);
1881
+ }
1882
+ var CATEGORIES, HOOKS;
1883
+ var init_registry = __esm(() => {
1884
+ CATEGORIES = [
1885
+ "Git Safety",
1886
+ "Code Quality",
1887
+ "Security",
1888
+ "Notifications",
1889
+ "Context Management",
1890
+ "Workflow Automation",
1891
+ "Environment",
1892
+ "Permissions",
1893
+ "Observability",
1894
+ "Agent Teams"
1895
+ ];
1896
+ HOOKS = [
1897
+ {
1898
+ name: "gitguard",
1899
+ displayName: "Git Guard",
1900
+ description: "Blocks destructive git operations like reset --hard, push --force, clean -f",
1901
+ version: "0.1.0",
1902
+ category: "Git Safety",
1903
+ event: "PreToolUse",
1904
+ matcher: "Bash",
1905
+ tags: ["git", "safety", "destructive", "guard"]
1906
+ },
1907
+ {
1908
+ name: "branchprotect",
1909
+ displayName: "Branch Protect",
1910
+ description: "Prevents editing files directly on main/master branch",
1911
+ version: "0.1.0",
1912
+ category: "Git Safety",
1913
+ event: "PreToolUse",
1914
+ matcher: "Write|Edit|NotebookEdit",
1915
+ tags: ["git", "branch", "protection", "main"]
1916
+ },
1917
+ {
1918
+ name: "checkpoint",
1919
+ displayName: "Checkpoint",
1920
+ description: "Creates shadow git snapshots before file modifications for easy rollback",
1921
+ version: "0.1.0",
1922
+ category: "Git Safety",
1923
+ event: "PreToolUse",
1924
+ matcher: "Write|Edit|NotebookEdit",
1925
+ tags: ["git", "snapshot", "rollback", "backup"]
1926
+ },
1927
+ {
1928
+ name: "checktests",
1929
+ displayName: "Check Tests",
1930
+ description: "Checks for missing tests after file edits",
1931
+ version: "0.1.6",
1932
+ category: "Code Quality",
1933
+ event: "PostToolUse",
1934
+ matcher: "Edit|Write|NotebookEdit",
1935
+ tags: ["tests", "coverage", "quality"]
1936
+ },
1937
+ {
1938
+ name: "checklint",
1939
+ displayName: "Check Lint",
1940
+ description: "Runs linting after file edits and creates tasks for errors",
1941
+ version: "0.1.7",
1942
+ category: "Code Quality",
1943
+ event: "PostToolUse",
1944
+ matcher: "Edit|Write|NotebookEdit",
1945
+ tags: ["lint", "style", "quality"]
1946
+ },
1947
+ {
1948
+ name: "checkfiles",
1949
+ displayName: "Check Files",
1950
+ description: "Runs headless agent to review files and create tasks",
1951
+ version: "0.1.4",
1952
+ category: "Code Quality",
1953
+ event: "PostToolUse",
1954
+ matcher: "Edit|Write|NotebookEdit",
1955
+ tags: ["review", "files", "quality"]
1956
+ },
1957
+ {
1958
+ name: "checkbugs",
1959
+ displayName: "Check Bugs",
1960
+ description: "Checks for bugs via Codex headless agent",
1961
+ version: "0.1.6",
1962
+ category: "Code Quality",
1963
+ event: "PostToolUse",
1964
+ matcher: "Edit|Write|NotebookEdit",
1965
+ tags: ["bugs", "analysis", "quality"]
1966
+ },
1967
+ {
1968
+ name: "checkdocs",
1969
+ displayName: "Check Docs",
1970
+ description: "Checks for missing documentation and creates tasks",
1971
+ version: "0.2.1",
1972
+ category: "Code Quality",
1973
+ event: "PostToolUse",
1974
+ matcher: "Edit|Write|NotebookEdit",
1975
+ tags: ["docs", "documentation", "quality"]
1976
+ },
1977
+ {
1978
+ name: "checktasks",
1979
+ displayName: "Check Tasks",
1980
+ description: "Validates task completion and tracks progress",
1981
+ version: "1.0.8",
1982
+ category: "Code Quality",
1983
+ event: "PostToolUse",
1984
+ matcher: "Edit|Write|NotebookEdit",
1985
+ tags: ["tasks", "tracking", "quality"]
1986
+ },
1987
+ {
1988
+ name: "checksecurity",
1989
+ displayName: "Check Security",
1990
+ description: "Runs security checks via Claude and Codex headless agents",
1991
+ version: "0.1.6",
1992
+ category: "Security",
1993
+ event: "PostToolUse",
1994
+ matcher: "Edit|Write|NotebookEdit",
1995
+ tags: ["security", "audit", "vulnerabilities"]
1996
+ },
1997
+ {
1998
+ name: "packageage",
1999
+ displayName: "Package Age",
2000
+ description: "Checks package age before install to prevent typosquatting",
2001
+ version: "0.1.1",
2002
+ category: "Security",
2003
+ event: "PreToolUse",
2004
+ matcher: "Bash",
2005
+ tags: ["npm", "packages", "typosquatting", "supply-chain"]
2006
+ },
2007
+ {
2008
+ name: "phonenotify",
2009
+ displayName: "Phone Notify",
2010
+ description: "Sends push notifications to phone via ntfy.sh",
2011
+ version: "0.1.0",
2012
+ category: "Notifications",
2013
+ event: "Stop",
2014
+ matcher: "",
2015
+ tags: ["notification", "phone", "push", "ntfy"]
2016
+ },
2017
+ {
2018
+ name: "agentmessages",
2019
+ displayName: "Agent Messages",
2020
+ description: "Inter-agent messaging integration for service-message",
2021
+ version: "0.1.0",
2022
+ category: "Notifications",
2023
+ event: "Stop",
2024
+ matcher: "",
2025
+ tags: ["messaging", "agents", "inter-agent"]
2026
+ },
2027
+ {
2028
+ name: "contextrefresh",
2029
+ displayName: "Context Refresh",
2030
+ description: "Re-injects important context every N prompts to prevent drift",
2031
+ version: "0.1.0",
2032
+ category: "Context Management",
2033
+ event: "Notification",
2034
+ matcher: "",
2035
+ tags: ["context", "memory", "prompts", "refresh"]
2036
+ },
2037
+ {
2038
+ name: "precompact",
2039
+ displayName: "Pre-Compact",
2040
+ description: "Saves session state before context compaction",
2041
+ version: "0.1.0",
2042
+ category: "Context Management",
2043
+ event: "Notification",
2044
+ matcher: "",
2045
+ tags: ["context", "compaction", "state", "backup"]
2046
+ },
2047
+ {
2048
+ name: "autoformat",
2049
+ displayName: "Auto Format",
2050
+ description: "Runs project formatter (Prettier, Biome, Ruff, Black, gofmt) after file edits",
2051
+ version: "0.1.0",
2052
+ category: "Workflow Automation",
2053
+ event: "PostToolUse",
2054
+ matcher: "Edit|Write",
2055
+ tags: ["format", "prettier", "biome", "ruff", "black", "gofmt", "style"]
2056
+ },
2057
+ {
2058
+ name: "autostage",
2059
+ displayName: "Auto Stage",
2060
+ description: "Automatically git-stages files after Claude edits them",
2061
+ version: "0.1.0",
2062
+ category: "Workflow Automation",
2063
+ event: "PostToolUse",
2064
+ matcher: "Edit|Write",
2065
+ tags: ["git", "stage", "add", "auto"]
2066
+ },
2067
+ {
2068
+ name: "tddguard",
2069
+ displayName: "TDD Guard",
2070
+ description: "Blocks implementation edits unless corresponding test files exist",
2071
+ version: "0.1.0",
2072
+ category: "Workflow Automation",
2073
+ event: "PreToolUse",
2074
+ matcher: "Edit|Write",
2075
+ tags: ["tdd", "tests", "red-green-refactor", "enforcement"]
2076
+ },
2077
+ {
2078
+ name: "envsetup",
2079
+ displayName: "Env Setup",
2080
+ description: "Warns when nvm, virtualenv, asdf, or rbenv may need activation before commands",
2081
+ version: "0.1.0",
2082
+ category: "Environment",
2083
+ event: "PreToolUse",
2084
+ matcher: "Bash",
2085
+ tags: ["nvm", "virtualenv", "asdf", "rbenv", "environment", "python", "node"]
2086
+ },
2087
+ {
2088
+ name: "permissionguard",
2089
+ displayName: "Permission Guard",
2090
+ description: "Auto-approves safe read-only commands and blocks dangerous operations",
2091
+ version: "0.1.0",
2092
+ category: "Permissions",
2093
+ event: "PreToolUse",
2094
+ matcher: "Bash",
2095
+ tags: ["permission", "allowlist", "blocklist", "safety", "auto-approve"]
2096
+ },
2097
+ {
2098
+ name: "protectfiles",
2099
+ displayName: "Protect Files",
2100
+ description: "Blocks access to .env, secrets, SSH keys, and lock files",
2101
+ version: "0.1.0",
2102
+ category: "Permissions",
2103
+ event: "PreToolUse",
2104
+ matcher: "Edit|Write|Read|Bash",
2105
+ tags: ["security", "env", "secrets", "keys", "lock-files", "protect"]
2106
+ },
2107
+ {
2108
+ name: "promptguard",
2109
+ displayName: "Prompt Guard",
2110
+ description: "Blocks prompt injection attempts and credential access requests",
2111
+ version: "0.1.0",
2112
+ category: "Permissions",
2113
+ event: "PreToolUse",
2114
+ matcher: "",
2115
+ tags: ["prompt", "injection", "security", "validation", "guard"]
2116
+ },
2117
+ {
2118
+ name: "desktopnotify",
2119
+ displayName: "Desktop Notify",
2120
+ description: "Sends native desktop notifications via osascript (macOS) or notify-send (Linux)",
2121
+ version: "0.1.0",
2122
+ category: "Notifications",
2123
+ event: "Stop",
2124
+ matcher: "",
2125
+ tags: ["notification", "desktop", "macos", "linux", "native"]
2126
+ },
2127
+ {
2128
+ name: "slacknotify",
2129
+ displayName: "Slack Notify",
2130
+ description: "Sends Slack webhook notifications when Claude finishes",
2131
+ version: "0.1.0",
2132
+ category: "Notifications",
2133
+ event: "Stop",
2134
+ matcher: "",
2135
+ tags: ["notification", "slack", "webhook", "team"]
2136
+ },
2137
+ {
2138
+ name: "soundnotify",
2139
+ displayName: "Sound Notify",
2140
+ description: "Plays a system sound when Claude finishes (macOS/Linux)",
2141
+ version: "0.1.0",
2142
+ category: "Notifications",
2143
+ event: "Stop",
2144
+ matcher: "",
2145
+ tags: ["notification", "sound", "audio", "alert"]
2146
+ },
2147
+ {
2148
+ name: "sessionlog",
2149
+ displayName: "Session Log",
2150
+ description: "Logs every tool call to .claude/session-log-<date>.jsonl",
2151
+ version: "0.1.0",
2152
+ category: "Observability",
2153
+ event: "PostToolUse",
2154
+ matcher: "",
2155
+ tags: ["logging", "audit", "session", "history", "jsonl"]
2156
+ },
2157
+ {
2158
+ name: "commandlog",
2159
+ displayName: "Command Log",
2160
+ description: "Logs every bash command Claude runs to .claude/commands.log",
2161
+ version: "0.1.0",
2162
+ category: "Observability",
2163
+ event: "PostToolUse",
2164
+ matcher: "Bash",
2165
+ tags: ["logging", "bash", "commands", "audit"]
2166
+ },
2167
+ {
2168
+ name: "costwatch",
2169
+ displayName: "Cost Watch",
2170
+ description: "Estimates session token usage and warns when budget threshold is exceeded",
2171
+ version: "0.1.0",
2172
+ category: "Observability",
2173
+ event: "Stop",
2174
+ matcher: "",
2175
+ tags: ["cost", "tokens", "budget", "usage", "monitoring"]
2176
+ },
2177
+ {
2178
+ name: "errornotify",
2179
+ displayName: "Error Notify",
2180
+ description: "Detects tool failures and logs errors to .claude/errors.log",
2181
+ version: "0.1.0",
2182
+ category: "Observability",
2183
+ event: "PostToolUse",
2184
+ matcher: "",
2185
+ tags: ["errors", "failures", "logging", "debugging"]
2186
+ },
2187
+ {
2188
+ name: "taskgate",
2189
+ displayName: "Task Gate",
2190
+ description: "Validates task completion criteria before allowing tasks to be marked done",
2191
+ version: "0.1.0",
2192
+ category: "Agent Teams",
2193
+ event: "PostToolUse",
2194
+ matcher: "",
2195
+ tags: ["tasks", "completion", "gate", "quality", "agent-teams"]
2196
+ }
2197
+ ];
2198
+ });
2199
+
1861
2200
  // node_modules/cli-spinners/spinners.json
1862
2201
  var require_spinners = __commonJS((exports, module) => {
1863
2202
  module.exports = {
@@ -3498,6 +3837,397 @@ var require_cli_spinners = __commonJS((exports, module) => {
3498
3837
  module.exports = spinners;
3499
3838
  });
3500
3839
 
3840
+ // src/lib/installer.ts
3841
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
3842
+ import { join, dirname } from "path";
3843
+ import { homedir } from "os";
3844
+ import { fileURLToPath } from "url";
3845
+ function getSettingsPath(scope = "global") {
3846
+ if (scope === "project") {
3847
+ return join(process.cwd(), ".claude", "settings.json");
3848
+ }
3849
+ return join(homedir(), ".claude", "settings.json");
3850
+ }
3851
+ function getHookPath(name) {
3852
+ const hookName = name.startsWith("hook-") ? name : `hook-${name}`;
3853
+ return join(HOOKS_DIR, hookName);
3854
+ }
3855
+ function hookExists(name) {
3856
+ return existsSync(getHookPath(name));
3857
+ }
3858
+ function readSettings(scope = "global") {
3859
+ const path = getSettingsPath(scope);
3860
+ try {
3861
+ if (existsSync(path)) {
3862
+ return JSON.parse(readFileSync(path, "utf-8"));
3863
+ }
3864
+ } catch {}
3865
+ return {};
3866
+ }
3867
+ function writeSettings(settings, scope = "global") {
3868
+ const path = getSettingsPath(scope);
3869
+ const dir = dirname(path);
3870
+ if (!existsSync(dir)) {
3871
+ mkdirSync(dir, { recursive: true });
3872
+ }
3873
+ writeFileSync(path, JSON.stringify(settings, null, 2) + `
3874
+ `);
3875
+ }
3876
+ function installHook(name, options = {}) {
3877
+ const { scope = "global", overwrite = false } = options;
3878
+ const hookName = name.startsWith("hook-") ? name : `hook-${name}`;
3879
+ const shortName = hookName.replace("hook-", "");
3880
+ if (!hookExists(shortName)) {
3881
+ return { hook: shortName, success: false, error: `Hook '${shortName}' not found` };
3882
+ }
3883
+ const registered = getRegisteredHooks(scope);
3884
+ if (registered.includes(shortName) && !overwrite) {
3885
+ return { hook: shortName, success: false, error: "Already installed. Use --overwrite to replace.", scope };
3886
+ }
3887
+ try {
3888
+ registerHook(shortName, scope);
3889
+ return { hook: shortName, success: true, scope };
3890
+ } catch (error) {
3891
+ return {
3892
+ hook: shortName,
3893
+ success: false,
3894
+ error: error instanceof Error ? error.message : "Unknown error"
3895
+ };
3896
+ }
3897
+ }
3898
+ function registerHook(name, scope = "global") {
3899
+ const meta = getHook(name);
3900
+ if (!meta)
3901
+ return;
3902
+ const settings = readSettings(scope);
3903
+ if (!settings.hooks)
3904
+ settings.hooks = {};
3905
+ const eventKey = meta.event;
3906
+ if (!settings.hooks[eventKey])
3907
+ settings.hooks[eventKey] = [];
3908
+ const hookCommand = `hooks run ${name}`;
3909
+ settings.hooks[eventKey] = settings.hooks[eventKey].filter((entry2) => !entry2.hooks?.some((h) => h.command === hookCommand));
3910
+ const entry = {
3911
+ hooks: [{ type: "command", command: hookCommand }]
3912
+ };
3913
+ if (meta.matcher) {
3914
+ entry.matcher = meta.matcher;
3915
+ }
3916
+ settings.hooks[eventKey].push(entry);
3917
+ writeSettings(settings, scope);
3918
+ }
3919
+ function unregisterHook(name, scope = "global") {
3920
+ const meta = getHook(name);
3921
+ if (!meta)
3922
+ return;
3923
+ const settings = readSettings(scope);
3924
+ if (!settings.hooks)
3925
+ return;
3926
+ const eventKey = meta.event;
3927
+ if (!settings.hooks[eventKey])
3928
+ return;
3929
+ const hookCommand = `hooks run ${name}`;
3930
+ settings.hooks[eventKey] = settings.hooks[eventKey].filter((entry) => !entry.hooks?.some((h) => h.command === hookCommand));
3931
+ if (settings.hooks[eventKey].length === 0) {
3932
+ delete settings.hooks[eventKey];
3933
+ }
3934
+ if (Object.keys(settings.hooks).length === 0) {
3935
+ delete settings.hooks;
3936
+ }
3937
+ writeSettings(settings, scope);
3938
+ }
3939
+ function getRegisteredHooks(scope = "global") {
3940
+ const settings = readSettings(scope);
3941
+ if (!settings.hooks)
3942
+ return [];
3943
+ const registered = [];
3944
+ for (const eventKey of Object.keys(settings.hooks)) {
3945
+ for (const entry of settings.hooks[eventKey]) {
3946
+ for (const hook of entry.hooks || []) {
3947
+ const newMatch = hook.command?.match(/^hooks run (\w+)$/);
3948
+ const oldMatch = hook.command?.match(/^hook-(\w+)$/);
3949
+ const match = newMatch || oldMatch;
3950
+ if (match) {
3951
+ registered.push(match[1]);
3952
+ }
3953
+ }
3954
+ }
3955
+ }
3956
+ return [...new Set(registered)];
3957
+ }
3958
+ function getInstalledHooks(scope = "global") {
3959
+ return getRegisteredHooks(scope);
3960
+ }
3961
+ function removeHook(name, scope = "global") {
3962
+ const hookName = name.startsWith("hook-") ? name : `hook-${name}`;
3963
+ const shortName = hookName.replace("hook-", "");
3964
+ const registered = getRegisteredHooks(scope);
3965
+ if (!registered.includes(shortName)) {
3966
+ return false;
3967
+ }
3968
+ unregisterHook(shortName, scope);
3969
+ return true;
3970
+ }
3971
+ var __dirname2, HOOKS_DIR;
3972
+ var init_installer = __esm(() => {
3973
+ init_registry();
3974
+ __dirname2 = dirname(fileURLToPath(import.meta.url));
3975
+ HOOKS_DIR = existsSync(join(__dirname2, "..", "..", "hooks", "hook-gitguard")) ? join(__dirname2, "..", "..", "hooks") : join(__dirname2, "..", "hooks");
3976
+ });
3977
+
3978
+ // src/mcp/server.ts
3979
+ var exports_server = {};
3980
+ __export(exports_server, {
3981
+ startStdioServer: () => startStdioServer,
3982
+ startSSEServer: () => startSSEServer,
3983
+ createHooksServer: () => createHooksServer,
3984
+ MCP_PORT: () => MCP_PORT
3985
+ });
3986
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3987
+ import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
3988
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3989
+ import { z } from "zod";
3990
+ import { createServer } from "http";
3991
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
3992
+ import { join as join2 } from "path";
3993
+ function createHooksServer() {
3994
+ const server = new McpServer({
3995
+ name: "@hasna/hooks",
3996
+ version: "0.0.7"
3997
+ });
3998
+ server.tool("hooks_list", "List all available Claude Code hooks, optionally filtered by category", { category: z.string().optional().describe("Filter by category name (e.g. 'Git Safety', 'Code Quality', 'Security', 'Notifications', 'Context Management')") }, async ({ category }) => {
3999
+ if (category) {
4000
+ const cat = CATEGORIES.find((c) => c.toLowerCase() === category.toLowerCase());
4001
+ if (!cat) {
4002
+ return { content: [{ type: "text", text: JSON.stringify({ error: `Unknown category: ${category}`, available: [...CATEGORIES] }) }] };
4003
+ }
4004
+ return { content: [{ type: "text", text: JSON.stringify(getHooksByCategory(cat)) }] };
4005
+ }
4006
+ const result = {};
4007
+ for (const cat of CATEGORIES) {
4008
+ result[cat] = getHooksByCategory(cat);
4009
+ }
4010
+ return { content: [{ type: "text", text: JSON.stringify(result) }] };
4011
+ });
4012
+ server.tool("hooks_search", "Search for hooks by name, description, or tags", { query: z.string().describe("Search query") }, async ({ query }) => {
4013
+ const results = searchHooks(query);
4014
+ return { content: [{ type: "text", text: JSON.stringify(results) }] };
4015
+ });
4016
+ server.tool("hooks_info", "Get detailed information about a specific hook including install status", { name: z.string().describe("Hook name (e.g. 'gitguard', 'checkpoint')") }, async ({ name }) => {
4017
+ const meta = getHook(name);
4018
+ if (!meta) {
4019
+ return { content: [{ type: "text", text: JSON.stringify({ error: `Hook '${name}' not found` }) }] };
4020
+ }
4021
+ const globalInstalled = getRegisteredHooks("global").includes(meta.name);
4022
+ const projectInstalled = getRegisteredHooks("project").includes(meta.name);
4023
+ return { content: [{ type: "text", text: JSON.stringify({ ...meta, global: globalInstalled, project: projectInstalled }) }] };
4024
+ });
4025
+ server.tool("hooks_install", "Install one or more hooks by registering them in Claude settings. Use scope 'global' for ~/.claude/settings.json or 'project' for .claude/settings.json", {
4026
+ hooks: z.array(z.string()).describe("Hook names to install"),
4027
+ scope: z.enum(["global", "project"]).default("global").describe("Install scope"),
4028
+ overwrite: z.boolean().default(false).describe("Overwrite if already installed")
4029
+ }, async ({ hooks, scope, overwrite }) => {
4030
+ const results = hooks.map((name) => installHook(name, { scope, overwrite }));
4031
+ return {
4032
+ content: [{
4033
+ type: "text",
4034
+ text: JSON.stringify({
4035
+ installed: results.filter((r) => r.success).map((r) => r.hook),
4036
+ failed: results.filter((r) => !r.success).map((r) => ({ hook: r.hook, error: r.error })),
4037
+ total: results.length,
4038
+ success: results.filter((r) => r.success).length,
4039
+ scope
4040
+ })
4041
+ }]
4042
+ };
4043
+ });
4044
+ server.tool("hooks_install_category", "Install all hooks in a category", {
4045
+ category: z.string().describe("Category name"),
4046
+ scope: z.enum(["global", "project"]).default("global").describe("Install scope"),
4047
+ overwrite: z.boolean().default(false).describe("Overwrite if already installed")
4048
+ }, async ({ category, scope, overwrite }) => {
4049
+ const cat = CATEGORIES.find((c) => c.toLowerCase() === category.toLowerCase());
4050
+ if (!cat) {
4051
+ return { content: [{ type: "text", text: JSON.stringify({ error: `Unknown category: ${category}`, available: [...CATEGORIES] }) }] };
4052
+ }
4053
+ const hooks = getHooksByCategory(cat).map((h) => h.name);
4054
+ const results = hooks.map((name) => installHook(name, { scope, overwrite }));
4055
+ return {
4056
+ content: [{
4057
+ type: "text",
4058
+ text: JSON.stringify({
4059
+ installed: results.filter((r) => r.success).map((r) => r.hook),
4060
+ failed: results.filter((r) => !r.success).map((r) => ({ hook: r.hook, error: r.error })),
4061
+ category: cat,
4062
+ scope
4063
+ })
4064
+ }]
4065
+ };
4066
+ });
4067
+ server.tool("hooks_install_all", "Install all available hooks", {
4068
+ scope: z.enum(["global", "project"]).default("global").describe("Install scope"),
4069
+ overwrite: z.boolean().default(false).describe("Overwrite if already installed")
4070
+ }, async ({ scope, overwrite }) => {
4071
+ const results = HOOKS.map((h) => installHook(h.name, { scope, overwrite }));
4072
+ return {
4073
+ content: [{
4074
+ type: "text",
4075
+ text: JSON.stringify({
4076
+ installed: results.filter((r) => r.success).map((r) => r.hook),
4077
+ failed: results.filter((r) => !r.success).map((r) => ({ hook: r.hook, error: r.error })),
4078
+ total: results.length,
4079
+ success: results.filter((r) => r.success).length,
4080
+ scope
4081
+ })
4082
+ }]
4083
+ };
4084
+ });
4085
+ server.tool("hooks_remove", "Remove (unregister) a hook from Claude settings", {
4086
+ name: z.string().describe("Hook name to remove"),
4087
+ scope: z.enum(["global", "project"]).default("global").describe("Scope to remove from")
4088
+ }, async ({ name, scope }) => {
4089
+ const removed = removeHook(name, scope);
4090
+ return { content: [{ type: "text", text: JSON.stringify({ hook: name, removed, scope }) }] };
4091
+ });
4092
+ server.tool("hooks_doctor", "Check health of installed hooks \u2014 verifies hook source exists, settings are correct", {
4093
+ scope: z.enum(["global", "project"]).default("global").describe("Scope to check")
4094
+ }, async ({ scope }) => {
4095
+ const settingsPath = getSettingsPath(scope);
4096
+ const issues = [];
4097
+ const healthy = [];
4098
+ const settingsExist = existsSync2(settingsPath);
4099
+ if (!settingsExist) {
4100
+ issues.push({ hook: "(settings)", issue: `${settingsPath} not found`, severity: "warning" });
4101
+ }
4102
+ const registered = getRegisteredHooks(scope);
4103
+ for (const name of registered) {
4104
+ const meta = getHook(name);
4105
+ let hookHealthy = true;
4106
+ if (!hookExists(name)) {
4107
+ issues.push({ hook: name, issue: "Hook not found in @hasna/hooks package", severity: "error" });
4108
+ continue;
4109
+ }
4110
+ const hookDir = getHookPath(name);
4111
+ if (!existsSync2(join2(hookDir, "src", "hook.ts"))) {
4112
+ issues.push({ hook: name, issue: "Missing src/hook.ts in package", severity: "error" });
4113
+ hookHealthy = false;
4114
+ }
4115
+ if (meta && settingsExist) {
4116
+ try {
4117
+ const settings = JSON.parse(readFileSync2(settingsPath, "utf-8"));
4118
+ const eventHooks = settings.hooks?.[meta.event] || [];
4119
+ const found = eventHooks.some((entry) => entry.hooks?.some((h) => h.command === `hooks run ${name}`));
4120
+ if (!found) {
4121
+ issues.push({ hook: name, issue: `Not registered under correct event (${meta.event})`, severity: "error" });
4122
+ hookHealthy = false;
4123
+ }
4124
+ } catch {}
4125
+ }
4126
+ if (hookHealthy)
4127
+ healthy.push(name);
4128
+ }
4129
+ return { content: [{ type: "text", text: JSON.stringify({ healthy, issues, registered, scope }) }] };
4130
+ });
4131
+ server.tool("hooks_categories", "List all hook categories with counts", {}, async () => {
4132
+ const result = CATEGORIES.map((cat) => ({
4133
+ name: cat,
4134
+ count: getHooksByCategory(cat).length
4135
+ }));
4136
+ return { content: [{ type: "text", text: JSON.stringify(result) }] };
4137
+ });
4138
+ server.tool("hooks_docs", "Get documentation \u2014 general overview or README for a specific hook", { name: z.string().optional().describe("Hook name for specific docs, omit for general docs") }, async ({ name }) => {
4139
+ if (name) {
4140
+ const meta = getHook(name);
4141
+ if (!meta) {
4142
+ return { content: [{ type: "text", text: JSON.stringify({ error: `Hook '${name}' not found` }) }] };
4143
+ }
4144
+ const hookPath = getHookPath(name);
4145
+ const readmePath = join2(hookPath, "README.md");
4146
+ let readme = "";
4147
+ if (existsSync2(readmePath)) {
4148
+ readme = readFileSync2(readmePath, "utf-8");
4149
+ }
4150
+ return { content: [{ type: "text", text: JSON.stringify({ ...meta, readme }) }] };
4151
+ }
4152
+ return {
4153
+ content: [{
4154
+ type: "text",
4155
+ text: JSON.stringify({
4156
+ overview: "Claude Code hooks are scripts that run at specific points in a Claude Code session. Install @hasna/hooks globally, then register hooks \u2014 no files are copied to your project.",
4157
+ events: {
4158
+ PreToolUse: "Fires before a tool executes. Can block the operation.",
4159
+ PostToolUse: "Fires after a tool executes. Runs asynchronously.",
4160
+ Stop: "Fires when a session ends. Useful for notifications.",
4161
+ Notification: "Fires on notification events like context compaction."
4162
+ },
4163
+ commands: {
4164
+ install: "hooks install <name>",
4165
+ installProject: "hooks install <name> --project",
4166
+ installAll: "hooks install --all",
4167
+ remove: "hooks remove <name>",
4168
+ list: "hooks list",
4169
+ search: "hooks search <query>",
4170
+ doctor: "hooks doctor"
4171
+ }
4172
+ })
4173
+ }]
4174
+ };
4175
+ });
4176
+ server.tool("hooks_registered", "Get list of currently registered hooks for a scope", {
4177
+ scope: z.enum(["global", "project"]).default("global").describe("Scope to check")
4178
+ }, async ({ scope }) => {
4179
+ const registered = getRegisteredHooks(scope);
4180
+ const result = registered.map((name) => {
4181
+ const meta = getHook(name);
4182
+ return { name, event: meta?.event, version: meta?.version, description: meta?.description };
4183
+ });
4184
+ return { content: [{ type: "text", text: JSON.stringify(result) }] };
4185
+ });
4186
+ return server;
4187
+ }
4188
+ async function startSSEServer(port = MCP_PORT) {
4189
+ const server = createHooksServer();
4190
+ const transports = new Map;
4191
+ const httpServer = createServer(async (req, res) => {
4192
+ const url = new URL(req.url || "/", `http://localhost:${port}`);
4193
+ if (url.pathname === "/sse") {
4194
+ const transport = new SSEServerTransport("/messages", res);
4195
+ transports.set(transport.sessionId, transport);
4196
+ res.on("close", () => transports.delete(transport.sessionId));
4197
+ await server.connect(transport);
4198
+ } else if (url.pathname === "/messages") {
4199
+ const sessionId = url.searchParams.get("sessionId");
4200
+ if (!sessionId || !transports.has(sessionId)) {
4201
+ res.writeHead(400);
4202
+ res.end("Invalid session");
4203
+ return;
4204
+ }
4205
+ const transport = transports.get(sessionId);
4206
+ let body = "";
4207
+ for await (const chunk of req)
4208
+ body += chunk;
4209
+ await transport.handlePostMessage(req, res, body);
4210
+ } else {
4211
+ res.writeHead(200, { "Content-Type": "application/json" });
4212
+ res.end(JSON.stringify({ name: "@hasna/hooks", version: "0.0.7", transport: "sse", port }));
4213
+ }
4214
+ });
4215
+ httpServer.listen(port, () => {
4216
+ console.error(`@hasna/hooks MCP server running on http://localhost:${port}`);
4217
+ console.error(`SSE endpoint: http://localhost:${port}/sse`);
4218
+ });
4219
+ }
4220
+ async function startStdioServer() {
4221
+ const server = createHooksServer();
4222
+ const transport = new StdioServerTransport;
4223
+ await server.connect(transport);
4224
+ }
4225
+ var MCP_PORT = 39427;
4226
+ var init_server = __esm(() => {
4227
+ init_registry();
4228
+ init_installer();
4229
+ });
4230
+
3501
4231
  // src/cli/index.tsx
3502
4232
  import { render } from "ink";
3503
4233
 
@@ -3519,8 +4249,8 @@ var {
3519
4249
 
3520
4250
  // src/cli/index.tsx
3521
4251
  import chalk2 from "chalk";
3522
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
3523
- import { join as join2 } from "path";
4252
+ import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
4253
+ import { join as join3 } from "path";
3524
4254
 
3525
4255
  // src/cli/components/App.tsx
3526
4256
  import { useState as useState7 } from "react";
@@ -3952,179 +4682,7 @@ function Header({ title = "Hooks", subtitle }) {
3952
4682
 
3953
4683
  // src/cli/components/CategorySelect.tsx
3954
4684
  import { Box as Box4, Text as Text4 } from "ink";
3955
-
3956
- // src/lib/registry.ts
3957
- var CATEGORIES = [
3958
- "Git Safety",
3959
- "Code Quality",
3960
- "Security",
3961
- "Notifications",
3962
- "Context Management"
3963
- ];
3964
- var HOOKS = [
3965
- {
3966
- name: "gitguard",
3967
- displayName: "Git Guard",
3968
- description: "Blocks destructive git operations like reset --hard, push --force, clean -f",
3969
- version: "0.1.0",
3970
- category: "Git Safety",
3971
- event: "PreToolUse",
3972
- matcher: "Bash",
3973
- tags: ["git", "safety", "destructive", "guard"]
3974
- },
3975
- {
3976
- name: "branchprotect",
3977
- displayName: "Branch Protect",
3978
- description: "Prevents editing files directly on main/master branch",
3979
- version: "0.1.0",
3980
- category: "Git Safety",
3981
- event: "PreToolUse",
3982
- matcher: "Write|Edit|NotebookEdit",
3983
- tags: ["git", "branch", "protection", "main"]
3984
- },
3985
- {
3986
- name: "checkpoint",
3987
- displayName: "Checkpoint",
3988
- description: "Creates shadow git snapshots before file modifications for easy rollback",
3989
- version: "0.1.0",
3990
- category: "Git Safety",
3991
- event: "PreToolUse",
3992
- matcher: "Write|Edit|NotebookEdit",
3993
- tags: ["git", "snapshot", "rollback", "backup"]
3994
- },
3995
- {
3996
- name: "checktests",
3997
- displayName: "Check Tests",
3998
- description: "Checks for missing tests after file edits",
3999
- version: "0.1.6",
4000
- category: "Code Quality",
4001
- event: "PostToolUse",
4002
- matcher: "Edit|Write|NotebookEdit",
4003
- tags: ["tests", "coverage", "quality"]
4004
- },
4005
- {
4006
- name: "checklint",
4007
- displayName: "Check Lint",
4008
- description: "Runs linting after file edits and creates tasks for errors",
4009
- version: "0.1.7",
4010
- category: "Code Quality",
4011
- event: "PostToolUse",
4012
- matcher: "Edit|Write|NotebookEdit",
4013
- tags: ["lint", "style", "quality"]
4014
- },
4015
- {
4016
- name: "checkfiles",
4017
- displayName: "Check Files",
4018
- description: "Runs headless agent to review files and create tasks",
4019
- version: "0.1.4",
4020
- category: "Code Quality",
4021
- event: "PostToolUse",
4022
- matcher: "Edit|Write|NotebookEdit",
4023
- tags: ["review", "files", "quality"]
4024
- },
4025
- {
4026
- name: "checkbugs",
4027
- displayName: "Check Bugs",
4028
- description: "Checks for bugs via Codex headless agent",
4029
- version: "0.1.6",
4030
- category: "Code Quality",
4031
- event: "PostToolUse",
4032
- matcher: "Edit|Write|NotebookEdit",
4033
- tags: ["bugs", "analysis", "quality"]
4034
- },
4035
- {
4036
- name: "checkdocs",
4037
- displayName: "Check Docs",
4038
- description: "Checks for missing documentation and creates tasks",
4039
- version: "0.2.1",
4040
- category: "Code Quality",
4041
- event: "PostToolUse",
4042
- matcher: "Edit|Write|NotebookEdit",
4043
- tags: ["docs", "documentation", "quality"]
4044
- },
4045
- {
4046
- name: "checktasks",
4047
- displayName: "Check Tasks",
4048
- description: "Validates task completion and tracks progress",
4049
- version: "1.0.8",
4050
- category: "Code Quality",
4051
- event: "PostToolUse",
4052
- matcher: "Edit|Write|NotebookEdit",
4053
- tags: ["tasks", "tracking", "quality"]
4054
- },
4055
- {
4056
- name: "checksecurity",
4057
- displayName: "Check Security",
4058
- description: "Runs security checks via Claude and Codex headless agents",
4059
- version: "0.1.6",
4060
- category: "Security",
4061
- event: "PostToolUse",
4062
- matcher: "Edit|Write|NotebookEdit",
4063
- tags: ["security", "audit", "vulnerabilities"]
4064
- },
4065
- {
4066
- name: "packageage",
4067
- displayName: "Package Age",
4068
- description: "Checks package age before install to prevent typosquatting",
4069
- version: "0.1.1",
4070
- category: "Security",
4071
- event: "PreToolUse",
4072
- matcher: "Bash",
4073
- tags: ["npm", "packages", "typosquatting", "supply-chain"]
4074
- },
4075
- {
4076
- name: "phonenotify",
4077
- displayName: "Phone Notify",
4078
- description: "Sends push notifications to phone via ntfy.sh",
4079
- version: "0.1.0",
4080
- category: "Notifications",
4081
- event: "Stop",
4082
- matcher: "",
4083
- tags: ["notification", "phone", "push", "ntfy"]
4084
- },
4085
- {
4086
- name: "agentmessages",
4087
- displayName: "Agent Messages",
4088
- description: "Inter-agent messaging integration for service-message",
4089
- version: "0.1.0",
4090
- category: "Notifications",
4091
- event: "Stop",
4092
- matcher: "",
4093
- tags: ["messaging", "agents", "inter-agent"]
4094
- },
4095
- {
4096
- name: "contextrefresh",
4097
- displayName: "Context Refresh",
4098
- description: "Re-injects important context every N prompts to prevent drift",
4099
- version: "0.1.0",
4100
- category: "Context Management",
4101
- event: "Notification",
4102
- matcher: "",
4103
- tags: ["context", "memory", "prompts", "refresh"]
4104
- },
4105
- {
4106
- name: "precompact",
4107
- displayName: "Pre-Compact",
4108
- description: "Saves session state before context compaction",
4109
- version: "0.1.0",
4110
- category: "Context Management",
4111
- event: "Notification",
4112
- matcher: "",
4113
- tags: ["context", "compaction", "state", "backup"]
4114
- }
4115
- ];
4116
- function getHooksByCategory(category) {
4117
- return HOOKS.filter((h) => h.category === category);
4118
- }
4119
- function searchHooks(query) {
4120
- const q = query.toLowerCase();
4121
- return HOOKS.filter((h) => h.name.toLowerCase().includes(q) || h.displayName.toLowerCase().includes(q) || h.description.toLowerCase().includes(q) || h.tags.some((t) => t.includes(q)));
4122
- }
4123
- function getHook(name) {
4124
- return HOOKS.find((h) => h.name === name);
4125
- }
4126
-
4127
- // src/cli/components/CategorySelect.tsx
4685
+ init_registry();
4128
4686
  import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
4129
4687
  function CategorySelect({ onSelect, onBack }) {
4130
4688
  const items = CATEGORIES.map((cat) => ({
@@ -4414,6 +4972,7 @@ function TextInput({ value: originalValue, placeholder = "", focus = true, mask,
4414
4972
  var build_default = TextInput;
4415
4973
 
4416
4974
  // src/cli/components/SearchView.tsx
4975
+ init_registry();
4417
4976
  import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
4418
4977
  function SearchView({
4419
4978
  selected,
@@ -4520,141 +5079,9 @@ function Spinner({ type = "dots" }) {
4520
5079
  }
4521
5080
  var build_default2 = Spinner;
4522
5081
 
4523
- // src/lib/installer.ts
4524
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
4525
- import { join, dirname } from "path";
4526
- import { homedir } from "os";
4527
- import { fileURLToPath } from "url";
4528
- var __dirname2 = dirname(fileURLToPath(import.meta.url));
4529
- var HOOKS_DIR = existsSync(join(__dirname2, "..", "..", "hooks", "hook-gitguard")) ? join(__dirname2, "..", "..", "hooks") : join(__dirname2, "..", "hooks");
4530
- function getSettingsPath(scope = "global") {
4531
- if (scope === "project") {
4532
- return join(process.cwd(), ".claude", "settings.json");
4533
- }
4534
- return join(homedir(), ".claude", "settings.json");
4535
- }
4536
- function getHookPath(name) {
4537
- const hookName = name.startsWith("hook-") ? name : `hook-${name}`;
4538
- return join(HOOKS_DIR, hookName);
4539
- }
4540
- function hookExists(name) {
4541
- return existsSync(getHookPath(name));
4542
- }
4543
- function readSettings(scope = "global") {
4544
- const path = getSettingsPath(scope);
4545
- try {
4546
- if (existsSync(path)) {
4547
- return JSON.parse(readFileSync(path, "utf-8"));
4548
- }
4549
- } catch {}
4550
- return {};
4551
- }
4552
- function writeSettings(settings, scope = "global") {
4553
- const path = getSettingsPath(scope);
4554
- const dir = dirname(path);
4555
- if (!existsSync(dir)) {
4556
- mkdirSync(dir, { recursive: true });
4557
- }
4558
- writeFileSync(path, JSON.stringify(settings, null, 2) + `
4559
- `);
4560
- }
4561
- function installHook(name, options = {}) {
4562
- const { scope = "global", overwrite = false } = options;
4563
- const hookName = name.startsWith("hook-") ? name : `hook-${name}`;
4564
- const shortName = hookName.replace("hook-", "");
4565
- if (!hookExists(shortName)) {
4566
- return { hook: shortName, success: false, error: `Hook '${shortName}' not found` };
4567
- }
4568
- const registered = getRegisteredHooks(scope);
4569
- if (registered.includes(shortName) && !overwrite) {
4570
- return { hook: shortName, success: false, error: "Already installed. Use --overwrite to replace.", scope };
4571
- }
4572
- try {
4573
- registerHook(shortName, scope);
4574
- return { hook: shortName, success: true, scope };
4575
- } catch (error) {
4576
- return {
4577
- hook: shortName,
4578
- success: false,
4579
- error: error instanceof Error ? error.message : "Unknown error"
4580
- };
4581
- }
4582
- }
4583
- function registerHook(name, scope = "global") {
4584
- const meta = getHook(name);
4585
- if (!meta)
4586
- return;
4587
- const settings = readSettings(scope);
4588
- if (!settings.hooks)
4589
- settings.hooks = {};
4590
- const eventKey = meta.event;
4591
- if (!settings.hooks[eventKey])
4592
- settings.hooks[eventKey] = [];
4593
- const hookCommand = `hooks run ${name}`;
4594
- settings.hooks[eventKey] = settings.hooks[eventKey].filter((entry2) => !entry2.hooks?.some((h) => h.command === hookCommand));
4595
- const entry = {
4596
- hooks: [{ type: "command", command: hookCommand }]
4597
- };
4598
- if (meta.matcher) {
4599
- entry.matcher = meta.matcher;
4600
- }
4601
- settings.hooks[eventKey].push(entry);
4602
- writeSettings(settings, scope);
4603
- }
4604
- function unregisterHook(name, scope = "global") {
4605
- const meta = getHook(name);
4606
- if (!meta)
4607
- return;
4608
- const settings = readSettings(scope);
4609
- if (!settings.hooks)
4610
- return;
4611
- const eventKey = meta.event;
4612
- if (!settings.hooks[eventKey])
4613
- return;
4614
- const hookCommand = `hooks run ${name}`;
4615
- settings.hooks[eventKey] = settings.hooks[eventKey].filter((entry) => !entry.hooks?.some((h) => h.command === hookCommand));
4616
- if (settings.hooks[eventKey].length === 0) {
4617
- delete settings.hooks[eventKey];
4618
- }
4619
- if (Object.keys(settings.hooks).length === 0) {
4620
- delete settings.hooks;
4621
- }
4622
- writeSettings(settings, scope);
4623
- }
4624
- function getRegisteredHooks(scope = "global") {
4625
- const settings = readSettings(scope);
4626
- if (!settings.hooks)
4627
- return [];
4628
- const registered = [];
4629
- for (const eventKey of Object.keys(settings.hooks)) {
4630
- for (const entry of settings.hooks[eventKey]) {
4631
- for (const hook of entry.hooks || []) {
4632
- const newMatch = hook.command?.match(/^hooks run (\w+)$/);
4633
- const oldMatch = hook.command?.match(/^hook-(\w+)$/);
4634
- const match = newMatch || oldMatch;
4635
- if (match) {
4636
- registered.push(match[1]);
4637
- }
4638
- }
4639
- }
4640
- }
4641
- return [...new Set(registered)];
4642
- }
4643
- function getInstalledHooks(scope = "global") {
4644
- return getRegisteredHooks(scope);
4645
- }
4646
- function removeHook(name, scope = "global") {
4647
- const hookName = name.startsWith("hook-") ? name : `hook-${name}`;
4648
- const shortName = hookName.replace("hook-", "");
4649
- const registered = getRegisteredHooks(scope);
4650
- if (!registered.includes(shortName)) {
4651
- return false;
4652
- }
4653
- unregisterHook(shortName, scope);
4654
- return true;
4655
- }
4656
-
4657
5082
  // src/cli/components/InstallProgress.tsx
5083
+ init_installer();
5084
+ init_registry();
4658
5085
  import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
4659
5086
  function InstallProgress({
4660
5087
  hooks,
@@ -4782,6 +5209,7 @@ function InstallProgress({
4782
5209
  }
4783
5210
 
4784
5211
  // src/cli/components/App.tsx
5212
+ init_registry();
4785
5213
  import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
4786
5214
  function App({ initialHooks, overwrite = false }) {
4787
5215
  const { exit } = useApp();
@@ -4988,6 +5416,8 @@ function App({ initialHooks, overwrite = false }) {
4988
5416
  }
4989
5417
 
4990
5418
  // src/cli/index.tsx
5419
+ init_registry();
5420
+ init_installer();
4991
5421
  import { jsxDEV as jsxDEV8 } from "react/jsx-dev-runtime";
4992
5422
  var program2 = new Command;
4993
5423
  function resolveScope(options) {
@@ -4995,7 +5425,7 @@ function resolveScope(options) {
4995
5425
  return "project";
4996
5426
  return "global";
4997
5427
  }
4998
- program2.name("hooks").description("Install Claude Code hooks for your project").version("0.0.6");
5428
+ program2.name("hooks").description("Install Claude Code hooks for your project").version("0.1.0");
4999
5429
  program2.command("interactive", { isDefault: true }).alias("i").description("Interactive hook browser").action(() => {
5000
5430
  render(/* @__PURE__ */ jsxDEV8(App, {}, undefined, false, undefined, this));
5001
5431
  });
@@ -5006,8 +5436,8 @@ program2.command("run").argument("<hook>", "Hook to run").description("Execute a
5006
5436
  process.exit(1);
5007
5437
  }
5008
5438
  const hookDir = getHookPath(hook);
5009
- const hookScript = join2(hookDir, "src", "hook.ts");
5010
- if (!existsSync2(hookScript)) {
5439
+ const hookScript = join3(hookDir, "src", "hook.ts");
5440
+ if (!existsSync3(hookScript)) {
5011
5441
  console.error(JSON.stringify({ error: `Hook script not found: ${hookScript}` }));
5012
5442
  process.exit(1);
5013
5443
  }
@@ -5242,7 +5672,7 @@ program2.command("doctor").option("-g, --global", "Check global settings", false
5242
5672
  const settingsPath = getSettingsPath(scope);
5243
5673
  const issues = [];
5244
5674
  const healthy = [];
5245
- const settingsExist = existsSync2(settingsPath);
5675
+ const settingsExist = existsSync3(settingsPath);
5246
5676
  if (!settingsExist) {
5247
5677
  issues.push({ hook: "(settings)", issue: `${settingsPath} not found`, severity: "warning" });
5248
5678
  }
@@ -5256,14 +5686,14 @@ program2.command("doctor").option("-g, --global", "Check global settings", false
5256
5686
  continue;
5257
5687
  }
5258
5688
  const hookDir = getHookPath(name);
5259
- const hookScript = join2(hookDir, "src", "hook.ts");
5260
- if (!existsSync2(hookScript)) {
5689
+ const hookScript = join3(hookDir, "src", "hook.ts");
5690
+ if (!existsSync3(hookScript)) {
5261
5691
  issues.push({ hook: name, issue: "Missing src/hook.ts in package", severity: "error" });
5262
5692
  hookHealthy = false;
5263
5693
  }
5264
5694
  if (meta && settingsExist) {
5265
5695
  try {
5266
- const settings = JSON.parse(readFileSync2(settingsPath, "utf-8"));
5696
+ const settings = JSON.parse(readFileSync3(settingsPath, "utf-8"));
5267
5697
  const eventHooks = settings.hooks?.[meta.event] || [];
5268
5698
  const found = eventHooks.some((entry) => entry.hooks?.some((h) => h.command === `hooks run ${name}`));
5269
5699
  if (!found) {
@@ -5358,10 +5788,10 @@ program2.command("docs").argument("[hook]", "Hook name (shows general docs if om
5358
5788
  return;
5359
5789
  }
5360
5790
  const hookPath = getHookPath(hook);
5361
- const readmePath = join2(hookPath, "README.md");
5791
+ const readmePath = join3(hookPath, "README.md");
5362
5792
  let readme = "";
5363
- if (existsSync2(readmePath)) {
5364
- readme = readFileSync2(readmePath, "utf-8");
5793
+ if (existsSync3(readmePath)) {
5794
+ readme = readFileSync3(readmePath, "utf-8");
5365
5795
  }
5366
5796
  if (options.json) {
5367
5797
  console.log(JSON.stringify({ ...meta, readme }));
@@ -5464,4 +5894,13 @@ ${meta.displayName} v${meta.version}
5464
5894
  console.log(` hooks docs --json Machine-readable documentation`);
5465
5895
  console.log();
5466
5896
  });
5897
+ program2.command("mcp").option("-s, --stdio", "Use stdio transport (for Claude Code integration)", false).option("-p, --port <port>", "Port for SSE transport", "39427").description("Start MCP server for AI agent integration").action(async (options) => {
5898
+ if (options.stdio) {
5899
+ const { startStdioServer: startStdioServer2 } = await Promise.resolve().then(() => (init_server(), exports_server));
5900
+ await startStdioServer2();
5901
+ } else {
5902
+ const { startSSEServer: startSSEServer2 } = await Promise.resolve().then(() => (init_server(), exports_server));
5903
+ await startSSEServer2(parseInt(options.port));
5904
+ }
5905
+ });
5467
5906
  program2.parse();