forked from code-yeongyu/oh-my-openagent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodex-git-bash-hooks.ts
More file actions
25 lines (20 loc) · 1.01 KB
/
Copy pathcodex-git-bash-hooks.ts
File metadata and controls
25 lines (20 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { readFile, writeFile } from "node:fs/promises"
import { join } from "node:path"
import { isPlainRecord } from "./codex-cache-fs"
import type { CodexInstallPlatform } from "./types"
const WINDOWS_ONLY_GIT_BASH_HOOKS = new Set([
"./hooks/pre-tool-use-recommending-git-bash-mcp.json",
"./hooks/post-compact-resetting-git-bash-mcp-reminder.json",
])
export async function removeGitBashHooksOffWindows(input: {
readonly platform: CodexInstallPlatform
readonly pluginRoot: string
}): Promise<void> {
if (input.platform === "win32") return
const manifestPath = join(input.pluginRoot, ".codex-plugin", "plugin.json")
const parsed: unknown = JSON.parse(await readFile(manifestPath, "utf8"))
if (!isPlainRecord(parsed) || !Array.isArray(parsed.hooks)) return
const hooks = parsed.hooks.filter((hook) => typeof hook !== "string" || !WINDOWS_ONLY_GIT_BASH_HOOKS.has(hook))
if (hooks.length === parsed.hooks.length) return
await writeFile(manifestPath, `${JSON.stringify({ ...parsed, hooks }, null, "\t")}\n`)
}