Skip to content

INTENT #1

Closed
18 of 18 issues completed
Closed

Description

@k-sok

INTENT: prepush-ci

Run the full CI check in the pre-push hook of an AI agent's cloud session (or any machine that opts in), and let pull request CI skip commits that provably went through it. The default branch always runs CI in full.

This issue is the intent for a new repository. It describes the problem, the mechanism, what was tried and rejected, the design, the edge cases found in review, and what "done" means for a first release. Make the decisions it leaves open, and note each one in the commit that makes it.

1. Problem

With pull requests, every change is checked at least twice in hosted CI: on each push to the pull request, and again on the default branch after the merge. Every fixup push adds a full run. Hosted runners bill per job, rounded up to a full minute (GitHub Actions: About billing), so many short jobs cost far more than their runtime.

AI coding agents make this worse (many small pushes) and also offer the fix: Claude Code cloud sessions (docs) run in their own VM with no separate VM charge. Measured in one session: 4 vCPU, 15 GB RAM, ~30 GB disk quota. GitHub's standard runner for private repositories has 2 vCPU and 7 GB (runner specs). In the reference project, the full check took 2:07 min in the session versus 5:48 min on GitHub.

The agent already has a capable build machine; the pull request runs repeat work it has done. What is missing is a way for the pull request CI to know that the check ran.

Related prior art: DHH, We're moving continuous integration back to developer machines; Basecamp gh-signoff (commit status after local tests); Rails 8.1 bin/ci (release notes). nektos/act and Dagger run pipelines locally but do not remove the hosted run.

2. Mechanism: the trailer is a demand, not a record

  1. Commit. When the opt-in variable is set (in cloud sessions by the repository's SessionStart hook), a commit-msg hook writes a trailer into the message, e.g. Prepush-CI: full. At that moment nothing has been checked; the trailer is a demand on the commit.
  2. Push. The pre-push hook enforces the demand: if the pushed tip commit carries the trailer, the full check runs, whatever the variable says. Before it runs, the pushed commit must be the checked-out HEAD and the worktree must be clean (pre-push checks the worktree, not the commit). Any failure aborts the push.
  3. CI. Therefore a commit with the trailer can only reach the remote after the full check passed on it. A small gate in pull request CI reads the trailer of the head commit and skips the rest. On the default branch the trailer is ignored and CI runs in full: it is the backstop and should gate deployment.

Properties: no extra refs, no API write access, no wrapper around git push. A rebase keeps the trailer, so the next push re-checks the new state. Only the tip commit counts, because the check ran on the tip's state; trailers on earlier commits say nothing on their own.

Invariant: trailer on the remote ⇒ the full check passed on this commit, as long as every push path runs the hook. This is a trust model for cost, not a security mechanism: anyone with push rights can bypass it (--no-verify) and could equally edit the CI config.

This works in production in the reference project (a private Python repository): the PR gate reported the trailer, both workflows skipped every job except the gate; main ran in full.

3. Rejected alternatives (and why)

Claude Code cloud sessions reach GitHub only through a proxy that keeps credentials outside the VM (cloud environments). That shaped every choice.

Evidence Why rejected
Git note in refs/notes/checks The proxy rejects pushes of anything but branches (documented). HTTP 403.
Commit status via REST API (what gh-signoff does) The proxy returns 403 for status writes ("Write access to this GitHub API path is not permitted through this proxy"; generated by the proxy, no GitHub response headers). Network secrets are never attached to GitHub requests (documented), so a token does not help. On a laptop with its own gh login this would be the nicest option.
Branch checks/<sha> that CI reads, converts and deletes Probably works, but needs a branch naming exception, a recursion guard in the hook, CI write permission and cleanup; the proxy forbids branch deletion from the session.
Trailer added by --amend after the check, via a push wrapper A pre-push hook cannot change what is pushed (SHAs are fixed). Everyone would have to use the wrapper; forgetting it falls back silently.

4. Design

4.1 Tool and skill

  • Tool (prepush-ci): the CI-agnostic mechanism. Works without any agent: PREPUSH_CI=full on a laptop gives the same contract.
  • Skill (SKILL.md in the same repository): how an agent sets the tool up in a specific repository, including the cloud-session bootstrap. The skill calls prepush-ci init --non-interactive rather than re-implementing setup.

Make no assumptions about the user's CI. The tool provides verify; CI integrations are documented examples (GitHub Actions, GitLab CI, others), plus an optional GitHub Action.

4.2 Names

  • Trailer: Prepush-CI: full (greppable, reads as a fact in git log; the value leaves room for profiles later). Read legacy keys via config for migration (legacy_keys), e.g. Full-Pre-Push: required from the reference project.
  • Variable: PREPUSH_CI with values full (write trailer, run full) and off (hooks do nothing, but refuse to push commits that carry the trailer). No value that lets trailer commits through unchecked.

4.3 CLI

Command Purpose
prepush-ci hook commit-msg <file> Write the trailer when PREPUSH_CI=full. Use git interpret-trailers --in-place --no-divider --where start --if-exists doNothing (--no-divider is required: without it a --- line in the body ends the message and the trailer lands in the middle; verified).
prepush-ci hook pre-push Read the refs from stdin (native git protocol) or from pre-commit's variables; enforce as in section 2; run preflight, then the check. Ignore tags, deletions and non-branch refs.
prepush-ci run Run preflight and check manually; cache the result for (commit SHA, tree hash) in .git/prepush-ci/ so the pre-push (and a retried push) does not run it twice.
prepush-ci verify <sha> Exit 0 if the commit demands/proves the full check and its committer is not a server (see 5.2), else 1; print a one-line reason. Used by any CI.
prepush-ci strip [<base>] Remove the trailer from all commits since <base> (rewrites history), for pushing session commits from a machine that cannot run the full check; CI then runs normally.
prepush-ci init Interactive (or --non-interactive with flags): write config, install hooks for the repository's hook manager, print or write the CI gate snippet, write a SessionStart hook skeleton for Claude Code. Idempotent.
prepush-ci install Hooks only: native via core.hooksPath, or snippets for pre-commit / husky / lefthook. Idempotent, suitable for make setup or a postinstall step.
prepush-ci doctor Check that hooks are installed, config is valid, preflight passes, the variable is set as expected; explain what is missing.

4.4 Config (single source of truth)

.prepush-ci.toml (optionally [tool.prepush-ci] in pyproject.toml):

check = "scripts/ci"                  # the full check; CI should call the same entry point
preflight = "scripts/ci-preflight"    # must exit 0, else the full check fails (services, env)
require_env = ["TEST_DATABASE_URL"]   # shorthand preflight
require_up_to_date = "origin/main"    # fetch + merge-base --is-ancestor before the check
default_branch = "main"
trailer = { key = "Prepush-CI", value = "full" }
legacy_keys = ["Full-Pre-Push"]
cache = true

The check command lives only here, never also in args: of .pre-commit-config.yaml. Encourage one entry point (scripts/ci, make ci, bin/ci) that both the pre-push and the CI run, so the two cannot drift.

4.5 Rules that keep the invariant honest

  • Preflight fails, never skips. If a required service or variable is missing, the full check fails. A test suite that skips its database tests "visibly" makes the trailer a lie (this bug exists in the reference project).
  • Up to date by default. With require_up_to_date, the pre-push fetches and requires the default branch to be an ancestor of HEAD. This shrinks the gap "the branch was checked, not its merge with the current default branch" to a race between fetch and merge, without extra CI minutes. Reading through the session proxy works.
  • Hint when the tip has no trailer in full mode (e.g. after rebasing laptop commits in the session): CI will run; git commit --amend --no-edit adds it.

5. CI gate

5.1 Behaviour

  • Pull/merge request pipelines only; never the default branch.
  • Skip only if prepush-ci verify <head sha> exits 0.
  • Never skip for pull requests from forks (head repository ≠ base repository).
  • Optional: one full run per pull request anyway (e.g. on ready_for_review, a label, or a comment) as a documented mitigation for missing local hooks.

5.2 Server-made commits

6. Skill

SKILL.md

Sub-issues

Sub-issues

18 of 18 Issues completed
Loading 18 sub-issues

Activity

  1. k-sok commented on Oct 10, 2026

    @k-sok
    ContributorAuthor

    Make sure the setup procedure executed by the skill can handle existing pre-push setups and hooks. And let the skill explicitly ask the user what should happen with pre-push locally.

  2. self-assigned this
    on Oct 10, 2026
  3. added theissue type on Oct 11, 2026
  4. 10 remaining items

  5. cogc-factory commented on Oct 13, 2026

    @cogc-factory
    Contributor

    Backlog addition (bruce-lee)

    The maintainer asked for a command reference in the README and a terminal animation of setup, a failing and a passing push (at most 30 s, typing visible). Two slices, in a chain after #15:

    # Slice Capability Blocked by
    #86 README usage and command reference (takes over the README bullet from #15) readme #15
    #87 Terminal demo animation, recorded from the real CLI by a script demo #86, #70

    #87 waits for #70 so the recording shows the final install behavior.

    — bruce-lee

  6. k-sok commented on Oct 13, 2026

    @k-sok
    ContributorAuthor

    First release: 0.1.0

    The owner set the scope of the first release: everything in the milestone 0.1.0, and no open Bug: every bug known when the release pull request would be opened is fixed first, including bugs filed after today. #136 is not part of the release.

    Once the milestone is closed and no bug is open, bruce-lee opens the chore(release): 0.1.0 pull request (AGENTS.md, Versioning); the owner's approval of it is the release decision.

    — operator, for the owner

  7. cogc-factory commented on Oct 13, 2026

    @cogc-factory
    Contributor

    Release 0.1.0 gate, per the owner (group, 2026-10-13): no release while any known bug is open. Added #144, #145, #146 and #150 to the 0.1.0 milestone. The release PR (chore(release): 0.1.0) opens only when every milestone issue is closed, and any bug filed before then joins the milestone.

    — bruce-lee

  8. cogc-factory commented on Oct 14, 2026

    @cogc-factory
    Contributor

    Released 0.1.0. PR #167 merged as e17462b, tag v0.1.0 pushed on it, release.yml run 38585831924 green. 0.1.0 is on PyPI (https://pypi.org/project/prepush-ci/0.1.0/) and the GitHub release exists: https://github.com/CapeOfGoodCode/prepush-ci/releases/tag/v0.1.0. Milestone 0.1.0 is closed (16 issues closed, none open).

    — bruce-lee

  9. k-sok commented on Oct 14, 2026

    @k-sok
    ContributorAuthor

    Done: every slice of this intent (18 of 18 sub-issues) is merged, and the first release is out as v0.1.0 on PyPI. Work from here on is an issue of its own; anything outside this intent stays a proposal for the human.

  10. cogc-factory commented on Oct 14, 2026

    @cogc-factory
    Contributor

    Released 0.1.1: PR #174 merged, tag v0.1.1 pushed, release.yml succeeded, PyPI lists 0.1.1 (classifier 3 - Alpha), GitHub release exists. Next: 0.1.2 once #173 merges.

    — bruce-lee

  11. cogc-factory commented on Oct 14, 2026

    @cogc-factory
    Contributor

    0.1.2 released. Tag v0.1.2 on 69b8b89; release.yml run 38608172699 succeeded. PyPI serves prepush-ci 0.1.2 and the GitHub release exists: https://github.com/CapeOfGoodCode/prepush-ci/releases/tag/v0.1.2. No behavior change since 0.1.1 (tests, coverage gate at 100%, AGENTS.md only).

    — bruce-lee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions