Skip to content

gate: refuse a publish into a repository whose claim this session does not hold - #28

Merged
tannevaled merged 3 commits into
mainfrom
gate-publishing-on-claim
Nov 12, 2026
Merged

tannevaled merged 3 commits into
mainfrom
gate-publishing-on-claim

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Why

The claim was advisory and nothing read it where it matters. Two recorded occurrences: 2026-09-02, and 2026-11-12, when go-scikit's claim on go-numerics/optimize expired at 12:54, another session claimed it, and at 16:02-16:14 go-scikit pushed and merged go-numerics/optimize#62 without claiming again. No damage; nothing refused it.

What

agentsync gate --hook reads a PreToolUse payload on stdin (modelled on recur --hook: decision in the JSON, exit always 0).

  • Gated programs (matched as the PROGRAM of a simple command, so echo gitpush is left alone): gitpush, ghmerge, ghrelease, ghpr, ghissue, ghrun, ghrel. cd X && is followed.
  • Target: an owner/repo or GitHub URL argument (or --repo/-repo/-R), else the remote of the cwd / cd / -C directory (gitpush uses the remote it is given, default origin).
  • Deny when another session holds a live claim (holder, expiry, note) or when none does ("claim it first"; an expired claim, including the session's own, is no claim).
  • Allow when this session holds it; an organisation claim or a bare-name claim covers the repository (lease.Store.Covering).
  • Allow, with a note on stderr, whenever it cannot decide: unreadable payload, missing/unreadable claims directory, unresolvable remote, no session identity, ghrelease backfill.
  • agentsync gate <owner/repo>... answers the same question by hand.

Session identity

Same as claim/whoami (owner()), plus what only a hook has: AGENTSYNC_OWNER, else the payload's session_id, else CLAUDE_CODE_SESSION_ID. With none, allow (owner()'s unidentified-<host> would match nothing and refuse everything).

Known limits

  • It is a gate on the Bash tool's command text, not on the repository: a session without the hook is not stopped.
  • A here-document body with a line beginning with a gated program is read as that command.
  • ghpr review/ghissue comments by a reviewer session in a repo claimed by the author are also refused; the reviewer claims it or messages the holder.
  • The CLI here uses the standard flag package like every other verb; moving agentsync to cobra is a separate change.

Wiring (NOT done here; the user's decision)

Add to ~/.claude/settings.json:

{"hooks": {"PreToolUse": [{"matcher": "Bash",
  "hooks": [{"type": "command", "command": "agentsync gate --hook"}]}]}}

(merged into the existing PreToolUse array), after installing the release with GOBIN=~/.local/bin go install github.com/go-agentsync/agentsync/cmd/agentsync@latest.

Tests

Holder allowed (all seven programs), another holder refused with name/expiry/note, no claim refused, expired own claim refused, expired foreign claim ignored, organisation and bare-name claims, unreadable store / non-JSON / no identity / unresolvable remote / backfill all allow, non-publishing commands and non-Bash tools untouched, target resolution table, identity precedence, Covering. gofmt, go vet (linux, darwin, windows), go test -race clean.

🤖 Generated with Claude Code

…s not hold

`agentsync gate --hook` answers a Claude Code PreToolUse payload. For gitpush,
ghmerge, ghrelease, ghpr, ghissue, ghrun and ghrel it resolves the target
repository and denies when another session holds the claim (naming holder and
expiry) or when nobody does. It allows when this session holds it, including
through an organisation claim, and allows whenever it cannot read: payload,
claims directory, remote, session identity.

lease.Store.Covering lists the leases about a repository: itself, its
organisation, or the bare name.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled force-pushed the gate-publishing-on-claim branch from 8c7fcc1 to 0f07f81 Compare November 12, 2026 15:25
tannevaled and others added 2 commits November 12, 2026 16:37
…sing, push target, unreadable leases)

- decide denies when ANY other session holds a live lease covering the target,
  whatever this session holds; a bare "optimize" no longer outranks another
  session's live "go-numerics/optimize".
- Acquire treats a bare name and an owner/name ending in it as overlapping, in
  both orders.
- Command parsing uses gitsafe's shellcmd (quoted heredocs, comments, statement
  split); inside a statement a gated program word anywhere, unquoted, counts, and
  a quoted word is read as a command only after bash/sh/zsh/eval. A cd inside
  parentheses does not outlive them; redirections are not arguments.
- gitpush follows branch.<b>.pushRemote, remote.pushDefault, branch.<b>.remote and
  the push URL.
- Covering fails on an unreadable lease, which the gate reads as "cannot read":
  allow, with a note.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…i-line quote state

- A gated program counts only as the COMMAND (after assignments and wrappers
  sudo/timeout/xargs/nice/env/..., reserved words), or inside bash -c/eval,
  $(...) and backticks: `go test ./cmd/ghmerge`, `cat ~/.local/bin/gitpush` and
  `echo ghmerge` are no longer denied.
- $(...) and backticks inside double quotes are run as commands.
- `#` comment stripping tracks quote state across lines.
- README: the gate guards against mistakes, not adversaries.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 9b1cf6f into main Nov 12, 2026
2 checks passed
@tannevaled
tannevaled deleted the gate-publishing-on-claim branch November 12, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant