Skip to content

feat: split pasted env assignments#2075

Open
mezotv wants to merge 2 commits into
generalaction:mainfrom
mezotv:emdash/rich-queens-flow-ztle5
Open

feat: split pasted env assignments#2075
mezotv wants to merge 2 commits into
generalaction:mainfrom
mezotv:emdash/rich-queens-flow-ztle5

Conversation

@mezotv
Copy link
Copy Markdown
Contributor

@mezotv mezotv commented May 17, 2026

Summary

  • split pasted dotenv-style assignments into env key/value rows
  • enable split paste for provider and MCP env fields
  • add parser coverage

Tests

  • pnpm exec vitest run --project node src/renderer/lib/env-paste.test.ts
  • pnpm exec eslint src/renderer/lib/env-paste.ts src/renderer/lib/env-paste.test.ts src/renderer/features/mcp/components/KeyValueSection.tsx src/renderer/features/mcp/components/McpModal.tsx src/renderer/features/settings/components/CustomCommandModal.tsx
  • pnpm exec tsc --noEmit

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 17, 2026

Greptile Summary

This PR adds dotenv-style paste splitting to env var forms in the MCP modal and provider settings modal. When a user pastes multi-line env assignment content, the new parseEnvAssignmentPaste helper detects and parses it, then replaceEnvEntryWithPaste expands the pasted rows starting from the target row.

  • env-paste.ts introduces the parser with strict all-or-nothing validation (any non-comment line that fails the assignment pattern causes the entire paste to be dropped), quoting normalisation, and a generic splice helper used by both call sites.
  • KeyValueSection gains an optional splitEnvPaste prop wired up in McpModal; CustomCommandModal gets its own handleEnvPaste callback that follows the same pattern.
  • Tests cover the core parsing and splice logic.

Confidence Score: 4/5

Safe to merge; the paste feature is additive and falls back to the browser default on any non-env content, so existing behaviour is unchanged for users who do not paste dotenv blocks.

The core parser and splice helper are well-tested and the integration is clean. Two quality gaps exist: inline # comments are not stripped from parsed values (contrary to standard dotenv behaviour), and the value input's paste handler applies the same key-replacing logic as the key input, which could silently overwrite a user's already-typed key name.

src/renderer/lib/env-paste.ts (inline comment stripping) and src/renderer/features/mcp/components/KeyValueSection.tsx (value-field paste behaviour)

Important Files Changed

Filename Overview
src/renderer/lib/env-paste.ts New parser for dotenv-style paste content; correctly rejects non-env blocks but does not strip inline # comments from values
src/renderer/lib/env-paste.test.ts New test file with good coverage of parsing and replacement; no issues found
src/renderer/features/mcp/components/KeyValueSection.tsx Adds paste split behaviour via handlePaste; both key and value inputs share identical paste logic which can overwrite an existing key when pasting into the value field
src/renderer/features/mcp/components/McpModal.tsx One-line change enabling splitEnvPaste on the existing KeyValueSection; straightforward and correct
src/renderer/features/settings/components/CustomCommandModal.tsx handleEnvPaste added correctly; EnvEntry type is structurally identical to EnvPasteEntry so no type unsoundness; same key-overwrite caveat as KeyValueSection applies

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User pastes text into key or value input] --> B{splitEnvPaste enabled?}
    B -- No --> Z[Browser default paste]
    B -- Yes --> C[parseEnvAssignmentPaste]
    C --> D{All non-comment lines\nmatch assignment regex?}
    D -- No or empty --> Z
    D -- Yes --> E[e.preventDefault]
    E --> F[Build pastedEntries with row IDs]
    F --> G[replaceEnvEntryWithPaste\nslice + insert + slice]
    G --> H[onChange or setForm\nwith new entries array]
    H --> I[Rows expanded in UI]
Loading
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
src/renderer/lib/env-paste.ts:6-24
**Inline `#` comments not stripped from values**

Standard dotenv parsers treat anything after an unquoted `#` (preceded by whitespace) as a comment and exclude it from the value. The current regex captures everything after `=` and passes it to `normalizeEnvValue`, which only strips surrounding quotes but leaves trailing comments intact. A user pasting from a real `.env` file where a line ends with a comment will get the comment text appended to the stored value.

### Issue 2 of 2
src/renderer/features/mcp/components/KeyValueSection.tsx:63-80
**Value field paste replaces the row's key**

Both the key and value inputs share the same `handlePaste` path, so a paste into the value input is treated identically to a paste into the key input. If the user has already typed a key name and then pastes a single `NAME=content` string (e.g. copied from a config tool) into the value field, the parser matches it as an env assignment and overwrites the user's existing key name with the parsed key, discarding the value the user intended to set.

Reviews (1): Last reviewed commit: "feat: split pasted env assignments" | Re-trigger Greptile

Comment thread src/renderer/lib/env-paste.ts
Comment thread src/renderer/features/mcp/components/KeyValueSection.tsx
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