Skip to content

Agent hook for src file modification - #844

Open
dario-coscia wants to merge 1 commit into
devfrom
agent-hook
Open

dario-coscia wants to merge 1 commit into
devfrom
agent-hook

Conversation

@dario-coscia

Copy link
Copy Markdown
Member

Description

Summary of Changes

Goal

Relax the old “never modify source code” rule and add automatic approval prompts when an agent edits files under pina/, tests/, or docs/.

Shared instruction

.opencode/skills/RULES.md, added a single shared rule:

Modify files - If the request will modify source files (pina, tests),
announce which files and wait for the user's explicit approval before editing..

opencode

  • .opencode/commands/pina-agentic.md

    • Replaced “never write files” with:
      • confirm target paths before writing;
      • require explicit approval for pina/, tests/, docs/.
    • Updated the delivery guidance so saved scripts require path confirmation.
  • .opencode/opencode.json (new)

    • Added edit permissions:
      "pina/*": "ask",
      "tests/*": "ask",
      "docs/*": "ask",
      "*": "allow"
  • .opencode/plugin/source-edit-guard.ts (new)

    • permission.ask re-asserts ask for protected source paths.
    • tool.execute.before shows a warning toast before an edit/write/patch.
    • Covers edit, write, and patch tools.

Claude Code

  • .claude/settings.json (new)

    • Added a PreToolUse hook for:
      Edit|Write|MultiEdit|NotebookEdit.
  • .claude/hooks/source_edit_guard.py (new)

    • Reads hook JSON from stdin.
    • Extracts file_path / notebook_path.
    • Returns:
      {
        "hookSpecificOutput": {
          "hookEventName": "PreToolUse",
          "permissionDecision": "ask",
          "permissionDecisionReason": "Modifying source file ..."
        }
      }
    • Stays silent for files outside the protected directories.

Tool support

Tool Enforcement
opencode Permission config + TS plugin
Claude Code PreToolUse hook
Codex Instruction-level only via RULES.md / AGENTS.md

Verification

  • opencode plugin logic tested with Node type stripping.
  • Claude hook tested with protected/relative/absolute/out-of-project paths.
  • Both JSON config files validated.
  • Claude Code should pick up the hook automatically; restart if not.

This PR fixes #842.

Checklist

  • Code follows the project’s Code Style Guidelines
  • Tests have been added or updated
  • Documentation has been updated if necessary
  • Pull request is linked to an open issue

@dario-coscia
dario-coscia requested a review from a team as a code owner October 21, 2026 18:38
@dario-coscia dario-coscia changed the title update Agent hook for src file modification Oct 21, 2026

This branch has not been deployed

No deployments
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