Skip to content

fix: snip prepend duplication (#15)#17

Open
blackheaven wants to merge 1 commit into
VincentHardouin:mainfrom
blackheaven:fix/snip-duplication
Open

fix: snip prepend duplication (#15)#17
blackheaven wants to merge 1 commit into
VincentHardouin:mainfrom
blackheaven:fix/snip-duplication

Conversation

@blackheaven

Copy link
Copy Markdown

No description provided.

@greptile-apps

greptile-apps Bot commented May 28, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a snip prefix duplication bug (#15) where an LLM would sometimes emit commands like snip snip snip go test, causing the snip binary to receive snip go test as its argument rather than go test. The fix introduces a stripSnipPrefixes helper that normalises any number of leading snip tokens to exactly one before the command is executed, and removes the broad early-exit guard that was previously skipping processing for all already-prefixed commands.

  • stripSnipPrefixes helper (new in src/index.ts): iteratively strips leading snip tokens so snipCommand always adds exactly one prefix, regardless of how many the LLM hallucinated.
  • Removed early-exit guard: if (command.startsWith("snip ")) return is dropped; all commands now pass through the full pipeline, which also means chained commands like snip go test && go build now get both segments correctly wrapped.
  • New test suite: 10 new test cases covering simple deduplication, operator chains (&&, ;, ||), env-var prefixes, pipe expressions, and extreme repetition scenarios.

Confidence Score: 5/5

Safe to merge — the change is a focused, well-tested normalisation of snip prefix duplication with no regressions on existing behaviour.

The new stripSnipPrefixes helper correctly handles all edge cases (single prefix, multiple prefixes, env-var prefixes, pipe and operator chains), and the removed early-exit guard leaves existing behaviour intact while also fixing the case where chained commands were only partially wrapped. The 10 new tests cover the full range of duplication scenarios, and all prior tests continue to pass.

No files require special attention.

Important Files Changed

Filename Overview
src/index.ts Adds stripSnipPrefixes helper and removes the broad early-exit guard; snipCommand now normalises any number of leading snip prefixes before re-adding exactly one
src/index.test.ts Adds a new describe block covering deduplication across simple commands, chained operators, env-var prefixes, pipe, semicolon,

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[toolExecuteBefore called] --> B{command is non-empty string?}
    B -- No --> Z[return, no change]
    B -- Yes --> C{pipe found outside quotes?}
    C -- Yes --> D[split at first pipe]
    D --> E[snipCommand on firstCmd]
    E --> F[output = result + rest]
    C -- No --> G[split on operators: AND, OR, semicolon, ampersand]
    G --> H{single segment?}
    H -- Yes --> I[output = snipCommand]
    H -- No --> J[map snipCommand over non-operator segments]
    J --> K[output = joined segments]

    subgraph snipCommand
        SC1[extract ENV_VAR prefix] --> SC2[stripSnipPrefixes remainder]
        SC2 --> SC3{bareCmd empty?}
        SC3 -- Yes --> SC4[return original]
        SC3 -- No --> SC5{first word unproxyable?}
        SC5 -- Yes --> SC6[return original]
        SC5 -- No --> SC7[return envPrefix + snip + bareCmd]
    end

    subgraph stripSnipPrefixes
        SP1[trimStart] --> SP2{starts with snip space?}
        SP2 -- Yes --> SP3[slice 5 chars + trimStart]
        SP3 --> SP2
        SP2 -- No --> SP4[return stripped string]
    end
Loading

Reviews (1): Last reviewed commit: "fix: snip prepend duplication (#15)" | Re-trigger Greptile

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