/** * Git hook installer (T1588). * * Copies CLEO's project-agnostic git hooks from the * `@cleocode/core/templates/git-hooks/` directory (T9858 relocated from * `packages/cleo/templates/hooks/`) into the target project's * `.git/hooks/` (or `core.hooksPath` if set). * * Project-agnostic: the templates are POSIX `/bin/sh` and have no * node/pnpm dependencies, so they install cleanly into Rust, Python, * bare-repo, or any other environment cleo init runs against. * * Sentinel-based ownership: only files containing the * `# CLEO_MANAGED_HOOK v1` line in their first 5 lines are considered * CLEO-owned and will be overwritten without `force`. Any pre-existing, * non-CLEO hook is preserved unless `force: true` is passed. */ /** * Sentinel line embedded in every CLEO-managed hook script. Used to * distinguish CLEO-owned hooks from user-customized hooks at upgrade * time, so a `cleo upgrade hooks_sync` (T1588) never clobbers user work. */ export declare const CLEO_HOOK_SENTINEL = "# CLEO_MANAGED_HOOK v1"; /** * The set of hooks CLEO ships and manages. Order matches the order * we iterate them; both names match the on-disk filenames in * `packages/core/templates/git-hooks/` (T9858 relocated cleo→core). */ export declare const CLEO_HOOK_NAMES: readonly ["commit-msg", "pre-push"]; export type CleoHookName = (typeof CLEO_HOOK_NAMES)[number]; /** Options for {@link installCleoHooks}. */ export interface InstallCleoHooksOptions { /** * Override the hook source directory. Defaults to * `/packages/core/templates/git-hooks` (in-monorepo) or the * resolved `@cleocode/core` install location at runtime. T9858 relocated * the hook templates packages/cleo → packages/core. */ templatesDir?: string; /** * If true, overwrite existing hook files even when they are NOT * CLEO-managed (no sentinel). Used for emergency repair / explicit * `--force`. Defaults to false. */ force?: boolean; /** * If true, do not actually write — return what WOULD happen. */ dryRun?: boolean; } /** Result of {@link installCleoHooks}. */ export interface InstallCleoHooksResult { /** Absolute path to the hooks dir we wrote into. */ hooksDir: string; /** Names of hooks that were installed (newly written or overwritten). */ installed: CleoHookName[]; /** Names of hooks skipped because a non-CLEO file already exists. */ skipped: CleoHookName[]; /** Reason for each skip, keyed by hook name. */ skipReasons: Partial>; } /** * Install CLEO's git hooks into a project. * * Resolves `core.hooksPath` first (so Husky / lefthook / nested * worktree configs are respected). Falls back to `/.git/hooks`. * * For each managed hook: * - If the destination file is missing → write it (mode 0o755). * - If it exists AND has the CLEO sentinel → overwrite (refresh). * - If it exists AND has NO sentinel → skip unless `force: true`. * * @param projectRoot Absolute path to the git project root. * @param opts See {@link InstallCleoHooksOptions}. * @returns Summary of installed/skipped hooks. * @throws If `projectRoot` is not a git repository. */ export declare function installCleoHooks(projectRoot: string, opts?: InstallCleoHooksOptions): Promise; /** * Returns true when `filePath` is a CLEO-managed hook (the first 5 lines * contain {@link CLEO_HOOK_SENTINEL}). Returns false on read error. */ export declare function isCleoManagedHook(filePath: string): boolean; /** * Resolve the `.git` directory for a project. Returns `null` when the * path is not inside a git repository. * * Handles both `.git/` (regular repo) and `.git` as a file (worktree * pointing at `gitdir: ...`). */ export declare function resolveGitDir(projectRoot: string): string | null; /** * Resolve the hooks directory the project actually uses. * * If `core.hooksPath` is set (Husky / lefthook / custom), respect it. * Otherwise fall back to `/hooks`. */ export declare function resolveHooksDir(projectRoot: string, gitDir: string): string; /** * Default templates dir resolution. * * Tries (in order): * 1. Sibling to compiled JS: `/../../templates/git-hooks` * (works once @cleocode/core is installed and shipped with templates). * 2. Monorepo source layout: `/packages/core/templates/git-hooks` * (used during local dev / tests against repo source). * * T9858 relocated the hook templates packages/cleo → packages/core, so the * canonical layout is now `packages/core/templates/git-hooks/`. We retain * fallback probes for the legacy `packages/cleo/templates/hooks/` path so * old global installs continue to function during the v2026.5.x upgrade * window. * * Tests should pass `templatesDir` explicitly to bypass resolution. */ export declare function defaultTemplatesDir(): string; //# sourceMappingURL=hooks-install.d.ts.map