fix: snip prepend duplication (#15)#17
Conversation
Greptile SummaryThis PR fixes a snip prefix duplication bug (#15) where an LLM would sometimes emit commands like
|
| 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
Reviews (1): Last reviewed commit: "fix: snip prepend duplication (#15)" | Re-trigger Greptile
No description provided.