Skip to content

Deny edits to tracked files in a main checkout on its default branch #16905

Closed

Description

@kyle-sexton

Refs melodic-software/dotfiles#1641, melodic-software/control-hub#11.

Why

Owner, 2026-11-17: sessions started in a repository's main folder "all should be creating worktrees. Sometimes they don't." The shared agent instructions now say to create a worktree first (melodic-software/dotfiles#1642), but nothing enforces it: the guardrails hooks on Write, Edit and NotebookEdit check secrets, hardcoded paths, Windows temp paths and settings writes only, and the source-control hooks gate only where git worktree add puts a worktree (finding of the dotfiles#1641 session; re-verify with file:line).

Owner decision (Q19, "Go with recommendations."): build a guard.

Outcome

A guardrails PreToolUse hook on Write, Edit and NotebookEdit denies an edit to a tracked file when the target is in a repository's main checkout (its git dir equals its common dir) on the remote default branch, and the denial says how to create and enter a worktree by the repository's convention. It denies and never asks, because a background session cannot answer a prompt.

Open design choice (owner)

The exemptions. Candidates: git-ignored and untracked paths; paths outside a repository; repositories worked on their default branch by design (the chezmoi source, melodic-software/control-hub, a repository with no remote), and how a repository or a person declares that. Send the hub the list with a recommendation and its Basis before building. State the known limit in the docs: writes made through shell commands are not seen.

Done when

  • The owner's exemption choices are recorded here.
  • Tests cover a denied edit, each exemption, a linked worktree, a detached head and a non-default branch in the main checkout.
  • A live session shows the denial text and a session following it into a worktree.

Activity

  1. added
    host-run
    on Nov 17, 2026
  2. added
    needs-triage
    on Nov 17, 2026
  3. github-actions commented on Nov 17, 2026

    @github-actions
    Contributor

    Size: Medium
    Complexity: Medium
    Uncertainty: Knowable
    Flags: intent
    Blocked by: none
    Blast radius: the guardrails plugin's PreToolUse hooks on Write, Edit and NotebookEdit, its tests and docs; every session that edits files in a repository's main checkout.
    Reversible: yes; remove the hook registration or revert the change.
    Open questions:

    1. Which exemptions apply, and how does a repository or a person declare them? Candidates: untracked and git-ignored paths, paths outside a repository, repositories worked on their default branch by design (chezmoi source, control-hub, a repository with no remote).
      RECOMMENDED: exempt untracked or git-ignored paths, paths outside any repository, and repositories with no remote default branch. For by-design default-branch repositories, use a per-repository opt-out (a git config key such as guardrails.allowDefaultBranchEdits=true, readable without prompting), with no per-person override. Basis: judgment; the issue states the denial must never ask, and a per-repository declaration keeps the choice with the repository.
      Understood: add a deny-only hook that blocks edits to tracked files in a main checkout (git dir equals common dir) on the default branch, with denial text explaining how to create and enter a worktree. Docs should state that shell-command writes are not seen. The live-session done-when item is a host step and does not hold triage.
      No open issue or merged PR duplicates this.
      To answer, post a comment that starts with this line:
    **Decision recorded.** <answer>
    

    Automated triage. A maintainer reviews it.

  4. added
    needs-owner-decision
    on Nov 17, 2026
  5. melodic-automation-lanes commented on Nov 17, 2026

    @melodic-automation-lanes
    Contributor

    The triage verdict left this issue at needs-owner-decision:

    • flagged: intent
    • held by needs-owner-decision
    • no lanes App verdict comment shows whether an earlier verdict was flagged

    Reason: intent

  6. melodic-automation-lanes commented on Nov 17, 2026

    @melodic-automation-lanes
    Contributor

    Not admitted to the issue lane: its done-when asks for what an unattended lane run cannot perform: item 1 (tracker-output: "The owner's exemption choices are recorded here."); recommended split: keep the other items here as the admissible issue and move these to a child issue for the host queue (host-run).

  7. kyle-sexton commented on Nov 17, 2026

    @kyle-sexton
    MemberAuthor

    Owner decisions, 2026-11-17 ("for questions, go w/ recomendations", each question restated with its options): the guard also denies creating a new untracked file, with only git-ignored paths exempt; no per-repository opt-out key now; the design's other points as proposed (target resolved from the file path, default branch from refs/remotes/origin/HEAD, allow with a hint where that is unset, one per-person off switch, deny never ask); on by default for everyone who installs guardrails, with the release note saying an update adds a new denial and how to turn it off.

  8. kyle-sexton commented on Nov 18, 2026

    @kyle-sexton
    MemberAuthor

    Delivered by #16954 (merged). Done-when, each line:

    Follow-ups from pr-verify's notes are not part of this issue: the guardrails README intro still says "twenty safety guards" while the manifest says 25.

  9. removed
    host-run
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-owner-decisionneeds-triage

    Fields

    Work status

    needs-owner-decision

    Priority

    medium

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions