Skip to content

Add methodology analysis phase for RLCR loop exit - #42

Merged
SihaoLiu merged 19 commits into
devfrom
reflection-improve
Mar 29, 2026
Merged

Add methodology analysis phase for RLCR loop exit#42
SihaoLiu merged 19 commits into
devfrom
reflection-improve

Conversation

@SihaoLiu

Copy link
Copy Markdown
Contributor

Summary

  • Add a pre-exit methodology analysis phase that runs before the RLCR loop fully exits (on COMPLETE, STOP, or MAXITER)
  • An independent Opus agent analyzes development records from a pure methodology perspective, sanitized of project-specific information
  • Optionally helps the user file a GitHub issue on the Humanize repo with improvement suggestions
  • Feature is ON by default; disable with --privacy flag on loop start
  • Comprehensive validator enforcement across Read/Write/Edit/Bash hooks during the analysis phase
  • Monitor and statusline correctly display "Analyzing" status during the phase

Changes

  • New files: hooks/lib/methodology-analysis.sh, prompt-template/claude/methodology-analysis-prompt.md
  • Modified hooks: All 4 validators (read/write/edit/bash) enforce methodology analysis restrictions on the originating session
  • Stop hook: Intercepts 3 exit paths (complete/stop/maxiter), enters methodology analysis phase, handles completion
  • Setup/Cancel: --privacy flag support, cancel during methodology analysis phase
  • Monitor/Statusline: Methodology analysis shown as active "Analyzing" phase with green status color

Test plan

  • Start loop with --privacy, verify all 3 exit paths skip methodology analysis
  • Complete a loop without --privacy, verify methodology analysis phase is entered after finalize
  • Cancel during methodology analysis phase, verify clean cancellation
  • Verify Write/Edit/Read/Bash validators block unauthorized operations during analysis
  • Verify originating session cannot read raw development records (only sanitized report)
  • Verify concurrent sessions are not affected by methodology analysis restrictions
  • Verify monitor and statusline display correct status during analysis phase

SihaoLiu added 18 commits March 12, 2026 21:16
Add a pre-exit analysis phase that spawns an Opus agent to review
development records from a methodology perspective. The agent produces
a sanitized report (no project-specific info) and optionally helps the
user file a GitHub issue with improvement suggestions.

New --privacy flag disables the feature; legacy loops default to
privacy=true (opt-in only for new loops). The phase integrates into
all three non-manual exit paths (complete, stop, maxiter) using the
established Finalize Phase pattern with state file renaming and a
completion artifact gate.
Address Codex review findings:
- Require methodology-analysis-report.md to exist before allowing
  completion (prevents silent no-op when Opus agent does not run)
- Fail closed when .methodology-exit-reason marker is missing or
  invalid instead of defaulting to "complete" (prevents misreporting
  stop/maxiter loops as successful)
…y analysis

The Opus analysis agent needs to read all round-*-summary.md and
round-*-review-result.md files, but the read validator was blocking
access to summaries from non-current rounds. Bypass the round number
check when methodology-analysis-state.md is the active state file,
while still requiring files to be within the active loop directory.
…d allowlist

Address Codex review findings:
- Use realpath to canonicalize paths before prefix check, preventing
  directory traversal attacks (e.g., LOOP_DIR/../sensitive-file)
- Restrict allowed reads to an explicit allowlist of files the analysis
  agent actually needs: round summaries, review results, and its own
  artifacts. This prevents exposing plan.md, prompt files, and other
  project-specific loop metadata that would undercut sanitization.
Add methodology analysis restrictions to all four validators:
- Read validator: restrict loop dir reads to allowlisted artifacts only
- Write validator: block all writes except methodology report/done marker
- Edit validator: block all edits except methodology report/done marker
- Bash validator: block git write commands and in-place file editing tools

This prevents source code modifications after Codex has signed off and
prevents project-specific information from leaking into the analysis report.
All four validators now try unfiltered loop search when session-filtered
search returns empty, so spawned agents (with different session_id) are
also subject to methodology analysis restrictions.

Bash validator now blocks: touch, mv, cp, rm, dd, truncate, chmod, chown,
output redirection to non-/dev/ paths, and all git write commands.
Handle BSD/macOS where realpath fails for non-existent files by resolving
the parent directory and appending the basename. This allows the initial
Write to methodology-analysis-report.md to succeed.

Narrow the bash gh allowlist from all gh commands to only gh issue
subcommands, preventing workspace mutations via gh pr checkout, gh repo
clone, or mutating gh api calls.
Read validator now blocks reads of files within the project root (not just
loop dir) during methodology analysis, while still allowing system files
outside the project (CLAUDE.md, configs). This prevents the analysis agent
from accessing source code that could leak into the report.

Bash validator now blocks common interpreter commands (python, ruby, node,
perl, php) during methodology analysis as defense-in-depth against file
write bypasses.
…ology analysis

Add find_methodology_analysis_loop() that scans all loop directories for
methodology-analysis-state.md instead of using the unfiltered find_active_loop
fallback which only returns the newest active loop. This prevents spawned agents
from binding to a wrong concurrent session during methodology analysis.

Block shell script entry points (bash/sh/zsh, build tools, source/dot commands,
direct script execution) in the bash validator during methodology analysis to
prevent bypassing file modification restrictions via wrapper binaries.
…y exit

Remove the gh issue early exit that short-circuited all subsequent methodology
analysis checks. Commands like 'gh issue create; rm file' were bypassing
blockers. Now all commands go through the full blocklist; pure gh issue commands
pass naturally since they match no blocker.

Add cancel-rlcr-loop.sh to the allowlist so the cancel command works during
the methodology analysis phase.

Document concurrent methodology analysis limitation in find_methodology_analysis_loop.
…bcommands

Only fall back to find_methodology_analysis_loop when NO session-matched loop
was found (spawned agent case). If a session has its own active loop, do NOT
search for another session's methodology analysis state -- that would apply
restrictions to an unrelated concurrent session.

Add git restore, clean, rm, mv to the methodology analysis git command blocklist
to prevent working tree modifications after Codex signoff.
…back

Remove unfiltered find_methodology_analysis_loop fallback from all validators.
The fallback incorrectly applied methodology analysis restrictions to unrelated
sessions opened in the same repo. Now only the originating session (matched by
session_id) gets restricted. Spawned agents rely on their prompt for guidance.

Add raw path fallback when realpath is unavailable (older macOS/BSD) to prevent
deadlock where the originating session cannot write completion artifacts.
…tor status

Add git switch/pull/clone/submodule/worktree and mkdir/rmdir/ln/mktemp to the
methodology analysis bash command blocklist.

Require methodology-analysis-report.md to have content (not just exist) before
allowing the methodology analysis phase to complete.

Add methodology-analysis-state.md to statusline state file resolution and show
"Analyzing" status. Treat methodology-analysis as active phase in monitor color.
…ead code

Require cancel-rlcr-loop.sh to be a standalone command (no shell operators)
to prevent chained commands from bypassing methodology analysis restrictions.

Document that spawned agents are not restricted by hooks due to session_id
mismatch -- their sanitization is enforced by the analysis prompt. This is
an inherent limitation of the hook architecture.

Remove unused find_methodology_analysis_loop function.
Remove round-*-summary.md and round-*-review-result.md from the methodology
analysis Read allowlist. The originating session should only read the sanitized
methodology-analysis-report.md, not raw development records that contain
project-specific information. The spawned agent reads raw records directly
(not restricted by hooks due to different session_id).

Document that read-only bash commands are intentionally not blocked during
methodology analysis -- blocking them would break basic operations. The
analysis prompt is the primary enforcement mechanism for sanitization.
Update blocked-read messages to match actual allowlist (methodology-analysis-*
files only). Previous messages incorrectly listed round-*-summary.md and
round-*-review-result.md which were removed from the allowlist.
The template was referenced in loop-common.sh but never created, causing
the CI template-references test to fail.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2cba950a86

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread hooks/loop-bash-validator.sh Outdated
Comment on lines +90 to +91
if echo "$COMMAND_LOWER" | grep -qE '(^|[[:space:]])([^[:space:]]*/)?cancel-rlcr-loop\.sh' && \
! echo "$COMMAND_LOWER" | grep -qE '[;|&]'; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Anchor cancel-script allowlist to actual invocation

The methodology-phase allowlist returns early whenever the command string merely contains a cancel-rlcr-loop.sh token, so non-cancel write commands can bypass every later restriction. For example, cp /path/cancel-rlcr-loop.sh /tmp/x matches this regex and exits 0 before the file-modification/redirection blocks run, which defeats the “no modifications after sign-off” guarantee in this phase.

Useful? React with 👍 / 👎.

Comment thread hooks/loop-codex-stop-hook.sh Outdated
Comment on lines +693 to +696
if [[ "$IS_METHODOLOGY_ANALYSIS_PHASE" == "true" ]]; then
if complete_methodology_analysis; then
# Analysis complete, allow exit
exit 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Run methodology completion check before git-clean gating

The new methodology completion handler is placed after the git-clean/push checks, so methodology-phase exits can still be blocked by git status before complete_methodology_analysis runs. In repos where .humanize files are tracked, writing methodology-analysis-report.md / methodology-analysis-done.md makes the tree dirty, and the session can get stuck in repeated “please commit first” blocks instead of progressing through the analysis-completion path.

Useful? React with 👍 / 👎.

The cancel-rlcr-loop.sh allowlist in the bash validator matched when the
script name appeared as an argument to another command (e.g. cp). Anchor
the regex to the start of the command string so only direct invocations
are allowed.

Move the methodology analysis completion handler in the stop hook to run
before the git-clean check. Writing methodology artifacts can make the
working tree appear dirty when .humanize is tracked, which would block
exit before the handler ever ran.
@ZenusZhang

Copy link
Copy Markdown
Contributor

We'd better allow users to use agents from different vendors that is configured in config system.
And the scripts/lib/model-router.sh may be used in this process.

@SihaoLiu
SihaoLiu merged commit fe1832d into dev Mar 29, 2026
8 checks passed
@SihaoLiu SihaoLiu mentioned this pull request Mar 29, 2026
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.

2 participants