hookloom 0.0.0 → 1.0.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.
@@ -0,0 +1,109 @@
1
+ import { existsSync, mkdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { basename, delimiter, dirname, join } from "node:path";
4
+ import { randomUUID } from "node:crypto";
5
+ // src/paths.ts
6
+ /**
7
+ * Where hookloom keeps a user's registry and its own disposable state.
8
+ */
9
+ function base(env, windows, xdg, fallback) {
10
+ const chosen = process.platform === "win32" ? env[windows] : env[xdg];
11
+ return chosen === void 0 || chosen === "" ? join(homedir(), ...fallback) : chosen;
12
+ }
13
+ /** The user's hookloom directory in their configuration directory. */
14
+ function configurationDirectory(env) {
15
+ return join(base(env, "APPDATA", "XDG_CONFIG_HOME", [".config"]), "hookloom");
16
+ }
17
+ /** The registry file: `HOOKLOOM_REGISTRY` when set, otherwise `registry.json` in the configuration directory. */
18
+ function registryPath(env) {
19
+ return env["HOOKLOOM_REGISTRY"] ?? join(configurationDirectory(env), "registry.json");
20
+ }
21
+ /** Cached results and session state, all of which may be deleted at any time: `HOOKLOOM_CACHE_DIR` overrides it. */
22
+ function cacheDirectory(env) {
23
+ return env["HOOKLOOM_CACHE_DIR"] ?? join(base(env, "LOCALAPPDATA", "XDG_CACHE_HOME", [".cache"]), "hookloom");
24
+ }
25
+ /** The directory of Claude Code's user settings. */
26
+ function claudeDirectory(env) {
27
+ return env["CLAUDE_CONFIG_DIR"] ?? join(homedir(), ".claude");
28
+ }
29
+ // src/files.ts
30
+ /**
31
+ * File writes that a concurrent reader never sees half done.
32
+ */
33
+ const OWNER_ONLY = 384;
34
+ const PERMISSION_BITS = 511;
35
+ /** Replaces a file in one step, keeping its permissions; a new file is readable by its owner only. */
36
+ function atomicWrite(path, content) {
37
+ mkdirSync(dirname(path), { recursive: true });
38
+ const existing = statSync(path, { throwIfNoEntry: false });
39
+ const temporary = join(dirname(path), `.${basename(path)}.${randomUUID()}`);
40
+ try {
41
+ writeFileSync(temporary, content, {
42
+ mode: existing === void 0 ? OWNER_ONLY : existing.mode & PERMISSION_BITS,
43
+ flush: true
44
+ });
45
+ renameSync(temporary, path);
46
+ } finally {
47
+ rmSync(temporary, { force: true });
48
+ }
49
+ }
50
+ // src/version.ts
51
+ const version = "1.0.0";
52
+ // src/dispatch/command-line.ts
53
+ /**
54
+ * The program and arguments with which each harness runs a command hook on each platform.
55
+ */
56
+ const GIT_BASH_INSTALLS = ["C:\\Program Files\\Git\\bin\\bash.exe", "C:\\Program Files (x86)\\Git\\bin\\bash.exe"];
57
+ function gitBash(platform) {
58
+ return platform.env["CLAUDE_CODE_GIT_BASH_PATH"] ?? GIT_BASH_INSTALLS.find((path) => existsSync(path));
59
+ }
60
+ /** Whether Claude Code would run a hook command through PowerShell: on Windows without Git Bash. */
61
+ function claudeUsesPowerShell(platform) {
62
+ return platform.windows && gitBash(platform) === void 0;
63
+ }
64
+ function onPath(platform, program) {
65
+ return (platform.env["PATH"] ?? platform.env["Path"] ?? "").split(delimiter).some((directory) => directory !== "" && existsSync(join(directory, program)));
66
+ }
67
+ function powershell(platform, command) {
68
+ return {
69
+ program: onPath(platform, "pwsh.exe") ? "pwsh.exe" : "powershell.exe",
70
+ args: [
71
+ "-NoProfile",
72
+ "-Command",
73
+ command
74
+ ]
75
+ };
76
+ }
77
+ /**
78
+ * Claude Code runs a command with `sh -c`, or on Windows with Git Bash and otherwise PowerShell. Codex runs it with the session's shell and no login: the user's shell, or PowerShell on Windows (`build_hooks_config` in `codex-rs/core/src/session/mod.rs`).
79
+ * @throws Error when the handler asks for PowerShell outside Windows.
80
+ */
81
+ function invocation(harness, handler, platform) {
82
+ if (handler.args !== void 0) return {
83
+ program: handler.command,
84
+ args: handler.args
85
+ };
86
+ const command = platform.windows ? handler.commandWindows ?? handler.command : handler.command;
87
+ if (handler.shell === "powershell") {
88
+ if (!platform.windows) throw new Error("PowerShell command hooks require Windows");
89
+ return powershell(platform, command);
90
+ }
91
+ if (harness === "codex") return platform.windows ? powershell(platform, command) : {
92
+ program: platform.env["SHELL"] ?? "/bin/sh",
93
+ args: ["-c", command]
94
+ };
95
+ if (!platform.windows) return {
96
+ program: handler.shell === "bash" ? "bash" : "/bin/sh",
97
+ args: ["-c", command]
98
+ };
99
+ const bash = gitBash(platform);
100
+ if (handler.shell === "bash") return {
101
+ program: bash ?? "bash",
102
+ args: ["-c", command]
103
+ };
104
+ return bash === void 0 ? powershell(platform, command) : {
105
+ program: bash,
106
+ args: ["-c", command]
107
+ };
108
+ }
109
+ export { cacheDirectory as a, registryPath as c, atomicWrite as i, invocation as n, claudeDirectory as o, version as r, configurationDirectory as s, claudeUsesPowerShell as t };