Skip to content

livery.extensions.agents._tasks

livery.extensions.agents._tasks

The hook verbs, fm hooks.*: the guards an agent session's tooling runs.

The extension's plugin, mounted while a workspace lists the extension. Wired from .claude/settings.json (Claude Code) and .agents/hooks.json (Antigravity) through one shim (fm-hook.sh). Under Claude Code each event arrives on stdin and the verdict is the exit code: 0 is quiet, 2 blocks the gated action with stderr as feedback. Under Antigravity each event arrives on stdin as camelCase JSON and the verdict is JSON on stdout. The shim turns infrastructure failures into a pass, because a guard that cannot run must not deny.

Classes:

Name Description
ToolInput

What Claude Code handed the tool, as the hook event carries it.

ToolCall

What Antigravity handed the tool, as the hook event carries it.

HookEvent

One agent hook event, parsed from stdin.

Functions:

Name Description
pre_bash

Refuse shell commands that succeed while silently breaking state.

post_edit

Run the fixers over the edited file; never block an edit.

stop

Block ending a turn whose last Bash result is a red fm verdict.

Attributes:

Name Type Description
hooks
Harness

hooks module-attribute

hooks = group('hooks', hidden=True, help='Agent lifecycle hooks (stdin-driven)')

Harness module-attribute

Harness = Literal['claude', 'antigravity']

ToolInput dataclass

ToolInput(file_path: str = '', command: str = '')

What Claude Code handed the tool, as the hook event carries it.

Attributes:

Name Type Description
file_path str
command str

file_path class-attribute instance-attribute

file_path: str = ''

command class-attribute instance-attribute

command: str = ''

ToolCall dataclass

ToolCall(name: str = '', args: dict[str, object] = dict())

What Antigravity handed the tool, as the hook event carries it.

Attributes:

Name Type Description
name str
args dict[str, object]

name class-attribute instance-attribute

name: str = ''

args class-attribute instance-attribute

args: dict[str, object] = dataclasses.field(default_factory=dict)

HookEvent dataclass

HookEvent(tool_input: ToolInput = ToolInput(), toolCall: ToolCall = ToolCall(), stop_hook_active: bool = False, session_id: str = '', transcript_path: str = '', cwd: str = '')

One agent hook event, parsed from stdin.

Accepts both Claude Code's snake_case payload (tool_input, stop_hook_active, transcript_path) and Antigravity's camelCase payload (toolCall, cwd).

Methods:

Name Description
command

The shell command the tool call is about to run, or empty.

file_path

The path the edit or write tool call targets, or empty.

Attributes:

Name Type Description
tool_input ToolInput
toolCall ToolCall
stop_hook_active bool
session_id str
transcript_path str
cwd str

tool_input class-attribute instance-attribute

tool_input: ToolInput = dataclasses.field(default_factory=ToolInput)

toolCall class-attribute instance-attribute

toolCall: ToolCall = dataclasses.field(default_factory=ToolCall)

stop_hook_active class-attribute instance-attribute

stop_hook_active: bool = False

session_id class-attribute instance-attribute

session_id: str = ''

transcript_path class-attribute instance-attribute

transcript_path: str = ''

cwd class-attribute instance-attribute

cwd: str = ''

command

command() -> str

The shell command the tool call is about to run, or empty.

Source code in packages/extensions/agents/src/livery/extensions/agents/_tasks.py
def command(self) -> str:
    """The shell command the tool call is about to run, or empty."""
    if self.tool_input.command:
        return self.tool_input.command
    raw = self.toolCall.args.get("CommandLine", "")
    return raw if isinstance(raw, str) else ""

file_path

file_path() -> str

The path the edit or write tool call targets, or empty.

Source code in packages/extensions/agents/src/livery/extensions/agents/_tasks.py
def file_path(self) -> str:
    """The path the edit or write tool call targets, or empty."""
    if self.tool_input.file_path:
        return self.tool_input.file_path
    raw = self.toolCall.args.get("Path", "")
    return raw if isinstance(raw, str) else ""

pre_bash

pre_bash(event: Annotated[HookEvent, stdin], harness: Annotated[Harness, doc('the hook protocol to answer in: claude or antigravity')] = 'claude') -> Stdout[str]

Refuse shell commands that succeed while silently breaking state.

Guards two patterns: a footman command piped into tail or head, and a git push of a branch that conflicts with origin/main.

The pipe guard. A gate's exit code is its verdict, and a pipe replaces it with the filter's, so fm check | tail -4 reports 0 whatever happened and prints the step summary while the failing step scrolls past above.

The push guard. Agent sessions share this repository, so main moves while a branch is being built, and a branch pushed from a stale base opens a conflicting pull request for which GitHub cannot build its test-merge and therefore spawns no CI at all. The guard runs git merge-tree --write-tree locally before letting the push through. Tag pushes, deletions, and pushes of main itself pass untouched.

Both are deliberately narrow. Command separators split first, so fm check && echo done | tail stays legal; quoted spans are data, so rg "fm check" | head passes.

Source code in packages/extensions/agents/src/livery/extensions/agents/_tasks.py
@hooks.task(name="pre-bash")
def pre_bash(
    event: Annotated[HookEvent, stdin],
    harness: Annotated[
        Harness,
        doc("the hook protocol to answer in: claude or antigravity"),
    ] = "claude",
) -> Stdout[str]:
    """Refuse shell commands that succeed while silently breaking state.

    Guards two patterns: a footman command piped into ``tail`` or
    ``head``, and a ``git push`` of a branch that conflicts with
    ``origin/main``.

    **The pipe guard.** A gate's exit code is its verdict, and a pipe
    replaces it with the filter's, so ``fm check | tail -4`` reports 0
    whatever happened and prints the step summary while the failing step
    scrolls past above.

    **The push guard.** Agent sessions share this repository, so main moves
    while a branch is being built, and a branch pushed from a stale base
    opens a conflicting pull request for which GitHub cannot build its
    test-merge and therefore spawns no CI at all. The guard runs
    ``git merge-tree --write-tree`` locally before letting the push
    through. Tag pushes, deletions, and pushes of main itself pass
    untouched.

    Both are deliberately narrow. Command separators split first, so
    ``fm check && echo done | tail`` stays legal; quoted spans are data,
    so ``rg "fm check" | head`` passes.
    """
    reason = _pre_bash_refusal(event)
    if harness == "antigravity":
        if reason is not None:
            return json.dumps({"decision": "deny", "reason": reason})
        return json.dumps({"decision": "allow"})
    if reason is not None:
        fail(reason, code=2)
    return ""

post_edit

post_edit(event: Annotated[HookEvent, stdin], harness: Annotated[Harness, doc('the hook protocol to answer in: claude or antigravity')] = 'claude') -> Stdout[str]

Run the fixers over the edited file; never block an edit.

Best-effort by design: every outcome exits 0 and says nothing under Claude Code (or answers {} under Antigravity), because a formatter problem must never block an edit. The gate, not the hook, is the arbiter; this only saves round trips.

Imports are never removed here: an edit in flight legitimately adds an import before the code that uses it, and a hook firing between the two edits would delete it. The full clean, unused imports included, belongs to the stop hook and the gate.

Source code in packages/extensions/agents/src/livery/extensions/agents/_tasks.py
@hooks.task(name="post-edit")
def post_edit(
    event: Annotated[HookEvent, stdin],
    harness: Annotated[
        Harness,
        doc("the hook protocol to answer in: claude or antigravity"),
    ] = "claude",
) -> Stdout[str]:
    """Run the fixers over the edited file; never block an edit.

    Best-effort by design: every outcome exits 0 and says nothing under
    Claude Code (or answers ``{}`` under Antigravity), because a
    formatter problem must never block an edit. The gate, not the hook,
    is the arbiter; this only saves round trips.

    Imports are never removed here: an edit in flight legitimately
    adds an import before the code that uses it, and a hook firing
    between the two edits would delete it. The full clean, unused
    imports included, belongs to the stop hook and the gate.
    """
    import contextlib
    import io

    from livery.workshop import fix_files

    path = event.file_path()
    if path and Path(path).is_file():
        # Through the gate's walk, never a tool: every fixer whose claims
        # reach the file runs over it, a python formatter's for python,
        # clang-format's for C++, an extension's for its own files; a file
        # no claim reaches is the walk's no-op, not the hook's business.
        with (
            contextlib.suppress(Exception, SystemExit),
            contextlib.redirect_stdout(io.StringIO()),
        ):
            fix_files((path,), safe=True)
    return "{}" if harness == "antigravity" else ""

stop

stop(event: Annotated[HookEvent, stdin]) -> int

Block ending a turn whose last Bash result is a red fm verdict.

stop_hook_active (the harness's retry marker) always passes, so a deliberate stop with a reported failure costs one nudge and never loops.

Source code in packages/extensions/agents/src/livery/extensions/agents/_tasks.py
@hooks.task(name="stop")
def stop(event: Annotated[HookEvent, stdin]) -> int:
    """Block ending a turn whose last Bash result is a red fm verdict.

    ``stop_hook_active`` (the harness's retry marker) always passes,
    so a deliberate stop with a reported failure costs one nudge and
    never loops.
    """
    if event.stop_hook_active:
        return 0
    transcript = Path(event.transcript_path)
    if not transcript.is_file():
        return 0
    if not _FAIL.search(_last_bash_result(transcript)):
        return 0
    sys.stderr.write(
        "The last Bash result in this turn is a FAILED fm command."
        " Fix it now, or - if the failure is deliberate and already"
        " reported to the user in your final message - stop again to"
        " proceed.\n"
    )
    return 2