Skip to content

feat(reflex): runtime guardrails — command/edit guard + Pi hook + dataset export - #30

Merged
bearmug merged 3 commits into
mainfrom
feat/reflex-runtime-guardrails
May 21, 2026
Merged

feat(reflex): runtime guardrails — command/edit guard + Pi hook + dataset export#30
bearmug merged 3 commits into
mainfrom
feat/reflex-runtime-guardrails

Conversation

@bearmug

@bearmug bearmug commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

First implementation of the repo-arch reflex runtime guardrails PRD. Adds a deterministic policy layer for shell commands and file edits, with an event log, test-plan generator, and Pi auto-mode hook.

What changed

New reflex subcommands

repo-arch reflex check-command <shell-command>   → Allow / Ask / Block
repo-arch reflex check-edit <file-path>           → risk + signals + warnings
repo-arch reflex test-plan <file-path>             → recommended tests/checks
repo-arch reflex install                           → install Pi pre-action hook
repo-arch reflex events [limit]                    → event log summary
repo-arch reflex dataset                           → export training dataset

Modules (src/reflex/)

Module Purpose
classify-command.ts Deterministic Allow/Ask/Block for shell commands
classify-edit.ts Risky file edit detection (patterns + fragile-map scoring)
test-plan.ts Test recommendations based on co-change history
events.ts Append-only JSONL event log
install-pi.ts Pi pre-action hook generator + settings update
dataset.ts Export events + synthetic examples as training data
index.ts Public exports

Command guard examples

[BLOCK] risk=critical  rm -rf /home
[ASK]   risk=medium   sudo apt update
[ALLOW] risk=low       git status

Edit classification examples

[CRITICAL] package-lock.json  signals: lockfile(1)
[HIGH]     tsconfig.json     signals: config(0.9)
[LOW]      src/utils.ts       no high-risk signals

Build order (from PRD)

  • ✅ classify-command
  • ✅ classify-edit
  • ✅ test-plan
  • ✅ install-pi
  • ✅ events
  • ✅ dataset
  • ⬜ train (teacher → student classifier — next step)
  • ⬜ session ingest (learn from Pi session failures — future)

Notes

train.ts and session-ingest.ts remain TODOs — wired in the build order but not yet implemented.

bearmug added 2 commits May 21, 2026 22:20
First implementation of the reflex PRD:

- classify-command: deterministic Allow/Ask/Block for shell commands
  - BLOCK: dd, rm -rf /home, curl|sh, hardcoded credentials
  - ASK: sudo apt, kill -9, chmod 777, git push --force
  - low-risk prefixes: git status, git log, ls, npm run, grep, cat

- classify-edit: risky file edit detection
  - Pattern-based: lockfiles, generated files, config files, .env
  - Repo-arch cache scoring: repeated-fix, co-change cards
  - High-churn file heuristics (agent-session.ts, models.generated.ts)

- test-plan: recommend tests/checks for changed files
  - Direct test discovery: same-dir, __tests__/, test/
  - Co-change-based test suggestions
  - TypeScript typecheck, monorepo workspace tests, e2e hints

- events: append-only event log (JSONL)
  - Tracks command_allowed, command_asked, command_blocked,
    edit_classified, pi_hook_triggered, etc.

- install-pi: Pi auto-mode pre-action hook
  - Generates .repo-arch/reflex/pi-hook.js
  - Updates .pi/settings.json with reflex package path
  - beforeCommand + beforeEdit hook functions

- dataset: export training data from events + synthetic examples
  - Converts reflex events to labeled dataset
  - Includes synthetic allow/ask/block examples
  - Splits train/valid for LoRA fine-tuning

Build order from PRD: policy-only command guard → file-edit
classifier → test signals → Pi hook → event capture → dataset
→ training

Related to: repo-arch reflex PRD
@bearmug
bearmug force-pushed the feat/reflex-runtime-guardrails branch from 5b35d3d to cc43f8b Compare May 21, 2026 20:20
@bearmug
bearmug merged commit 8d6ea52 into main May 21, 2026
1 check passed
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