Skip to content

feat: reject complex chains that require approval with readability instruction - #15

Merged
preved911 merged 1 commit into
mainfrom
feature/complex-command-readability
Jul 29, 2026
Merged

feat: reject complex chains that require approval with readability instruction#15
preved911 merged 1 commit into
mainfrom
feature/complex-command-readability

Conversation

@preved911

Copy link
Copy Markdown
Owner

When a bash command has multiple top-level chain segments (&&, ||, ;, |) and the resolved permission would be ask, the plugin now rejects the command with a heredoc message telling the agent to rewrite it with newlines and comments for readability.

Changes

  • chain.ts: Added topLevelSegments to ChainResult — distinguishes top-level chains from nested substitutions ($(), backticks, eval, sh -c)
  • enforce.ts: New isComplexChain(), buildReadabilityMessage() exports; beforeExecute now returns readabilityReject=true and stores deny for complex ask commands
  • index.ts: When readabilityReject is true, replaces the command with a heredoc formatting error instead of wrapping in { ... ; }
  • enforce.test.ts: 18 new tests — isComplexChain, readability rejection flows, buildReadabilityMessage

Testing

npm test  # 69 tests passed
npm run build  # type-checks clean

…struction

When a bash command has multiple top-level chain segments (&&, ||, ;, |)
and the resolved permission would be 'ask', the plugin now rejects the
command with a heredoc message telling the agent to rewrite it with
newlines and comments for readability.

- Add topLevelSegments to ChainResult to distinguish top-level chains
  from nested substitutions (, backticks, eval, sh -c)
- Returns readabilityReject=true and stores deny decision for complex
  ask commands
- Replaces the command with a heredoc error message instead of wrapping
  in { ... ; }
- 18 new tests covering isComplexChain, readability rejection logic,
  and buildReadabilityMessage
@github-actions

Copy link
Copy Markdown

👀 AI Code Review

The implementation introduces measures to reject complex chains requiring approval, enhancing readability. Tests are comprehensive and cover all new functionality.

Couldn't place inline comments for:

  • src/enforce.test.ts:140 — Add a test case for commands that are not complex but still trigger readabilityR

Powered by GPT-4o via GitHub Models

@preved911

Copy link
Copy Markdown
Owner Author

The readabilityReject flag is only set when a command is complex (has multiple top-level chain segments) and the resolved action is "ask". If a command is not complex, readabilityReject is always false by definition — there is no scenario where a non-complex command triggers it.

The existing tests already cover the boundary:

  • "does not reject single command that needs ask" — single command, action=ask, readabilityReject=false
  • "does not reject complex chain when all segments are denied anyway" — complex but action=deny, not ask
  • "does not reject when command is parse error" — parse error, action=deny
  • isComplexChain tests confirm single commands and nested-only commands return false

No missing test case here.

@preved911
preved911 merged commit ebadf8b into main Jul 29, 2026
2 checks passed
preved911 added a commit that referenced this pull request Sep 11, 2026
Includes redirect-target checks against edit rules (#14) and complex-chain
rejection with readability instruction (#15).
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