/** * The history guard — published history is owner-written, decided by git * itself (`git push --dry-run`), not by enumerating spellings. * * AGENTS.md → Working rules states the way this repository integrates work: * short branches off `main`, `main` only advances through a PR, and when `main` * moves the conflicted branch is handed back for the owner to integrate. A * local `git rebase` is a private rewrite; the moment it is pushed it rewrites * commits a reviewer, another session or a CI artifact may already be building * on, so the block sits where the rewrite becomes public — on `git push`. * * The outcome, not the spelling, is what is judged. Every direct `git push` * runs first as `git push --dry-run` (the same arguments, plus `--dry-run` — * git resolves flags and refspecs itself), and the printed outcome decides: a * `(forced update)`, a `[deleted]` ref, or a destination of `main` declines * the push. One mechanism covers every force flag spelling and `+`/`:ref` * refspec, because the answer comes from git, not from this file. When the * dry-run cannot run (offline — where a real push would fail anyway), a simple * text check on the push's own segment is the fallback. * * The guard is config-gated (`guards.history`): off by default for every * project, enabled where an operator asks for it. The only way through is an * explicit owner instruction in the same turn, carried as the command's first * word: `AW_ALLOW=force` — which never enables a push to `main`, because main * advances only through a PR. * * What is deliberately out of scope: payloads hidden inside scripts or * interpreter one-liners that never spell `git push` in the command text, and * a git alias invoked as `git fp` — the dry-run sees what git is told to push, * not what an alias named `fp` expands to. The dry-run sees what git sees; it * cannot see what a script builds at runtime, and no text predicate honestly * can. The residual risk is documented, not chased with a regex zoo. */ import { type GuardDecision, type ToolCallLike } from "./guard-util.js"; /** The outcome a dry-run can report for one push. */ export type PushOutcome = "clean" | "forced" | "deleted" | "main" | "unknown"; export interface PushRunnerResult { status: number; stdout: string; stderr: string; } export type PushRunner = (args: string[]) => PushRunnerResult; /** The default runner: git in the session's working directory. */ export declare function spawnPushRunner(cwd: string): PushRunner; /** Shell-tokenize the arguments of one push segment (quotes stripped). */ export declare function pushArgs(segment: string): string[]; /** Read the outcome git printed for one dry-run. */ export declare function readPushOutcome(result: PushRunnerResult): PushOutcome; /** * The `tool_call` gate. `enabled` comes from the config (`guards.history`); * the guard is a no-op while disabled. `runner`/`cwd` are injectable so the * suite never touches the network. */ export declare function historyGuard({ toolName, command }: ToolCallLike, enabled?: boolean, { runner, cwd, offlineFallback }?: { runner?: PushRunner; cwd?: string; offlineFallback?: (segment: string) => PushOutcome; }): GuardDecision; export declare const HISTORY_REASON: string;