Skip to content

feat(code-editor): add a CodeMirror-based code and merge editor [1/21] - #322

Open
gusfcarvalho wants to merge 1 commit into
mainfrom
agent-config/01-code-editor
Open

gusfcarvalho wants to merge 1 commit into
mainfrom
agent-config/01-code-editor

Conversation

@gusfcarvalho

@gusfcarvalho gusfcarvalho commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Part 1 of 21 of the stacked split of #318 (agent remote configuration). Every layer adds the final version of its files from #318, and only imports from layers below it, so each layer passes make reviewable on its own. Nothing is reachable in the app until layer 20 wires the Configuration tab in.

What

Adds a reusable CodeMirror 6 editor (CodeEditor) and side-by-side merge view (CodeMergeView) under src/components/code-editor/, with JSON/YAML languages, a light/dark theme, lint diagnostics and an async-load fallback/error state. Adds the CodeMirror and js-yaml dependencies, jsdom stubs for Range rects and ResizeObserver in vitest.setup.ts, and a shared codeEditorMock for component specs higher up the stack.

Tests

Own specs for the editor, merge view, diagnostics and the lazy index.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added an interactive code editor with JSON, YAML, and plain-text modes, editable or read-only views, and inline diagnostics.
    • Added side-by-side and unified views for comparing code, with unchanged sections collapsed.
    • Editor themes now follow the app’s light or dark mode, and editor loading and failure states provide feedback and retry support.

Copilot AI balanced review requested due to automatic review settings October 5, 2026 10:51
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: fe237ed2-1555-4ed2-be1e-fb246bab3664
📥 Commits

Reviewing files that changed from the base of the PR and between facc992 and dd93179.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (15)
  • package.json
  • src/components/agents/config/__tests__/codeEditorMock.ts
  • src/components/code-editor/CodeEditor.vue
  • src/components/code-editor/CodeEditorError.vue
  • src/components/code-editor/CodeEditorFallback.vue
  • src/components/code-editor/CodeMergeView.vue
  • src/components/code-editor/__tests__/CodeEditor.spec.ts
  • src/components/code-editor/__tests__/CodeMergeView.spec.ts
  • src/components/code-editor/__tests__/diagnostics.spec.ts
  • src/components/code-editor/__tests__/index.spec.ts
  • src/components/code-editor/diagnostics.ts
  • src/components/code-editor/index.ts
  • src/components/code-editor/languages/index.ts
  • src/components/code-editor/theme.ts
  • vitest.setup.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: bff5dc67-16f6-488c-bdc4-9d8cb8551460
📥 Commits

Reviewing files that changed from the base of the PR and between d645bbe and facc992.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (15)
  • package.json
  • src/components/agents/config/__tests__/codeEditorMock.ts
  • src/components/code-editor/CodeEditor.vue
  • src/components/code-editor/CodeEditorError.vue
  • src/components/code-editor/CodeEditorFallback.vue
  • src/components/code-editor/CodeMergeView.vue
  • src/components/code-editor/__tests__/CodeEditor.spec.ts
  • src/components/code-editor/__tests__/CodeMergeView.spec.ts
  • src/components/code-editor/__tests__/diagnostics.spec.ts
  • src/components/code-editor/__tests__/index.spec.ts
  • src/components/code-editor/diagnostics.ts
  • src/components/code-editor/index.ts
  • src/components/code-editor/languages/index.ts
  • src/components/code-editor/theme.ts
  • vitest.setup.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds editable CodeMirror and read-only diff components, language and diagnostic support, theme updates, and lazy loading with retry, loading, and error states. It also adds component tests and test-environment shims.

Changes

Code editor components

Layer / File(s) Summary
Editor support and configuration
package.json, src/components/code-editor/diagnostics.ts, src/components/code-editor/languages/index.ts, src/components/code-editor/theme.ts, src/components/code-editor/__tests__/diagnostics.spec.ts, vitest.setup.ts
Adds CodeMirror and YAML dependencies, YAML and JSON language extensions, diagnostic conversion from rows and columns to document ranges, light and dark themes, and missing jsdom API shims.
Editor behavior and model synchronization
src/components/code-editor/CodeEditor.vue, src/components/code-editor/__tests__/CodeEditor.spec.ts, src/components/agents/config/__tests__/codeEditorMock.ts
Adds an editable editor with model updates, external document replacement, accessibility attributes, diagnostics, reactive settings, and theme synchronization. Tests cover editor behavior; the mock provides a textarea stand-in.
Split and unified diff views
src/components/code-editor/CodeMergeView.vue, src/components/code-editor/__tests__/CodeMergeView.spec.ts, src/components/agents/config/__tests__/codeEditorMock.ts
Adds read-only split and unified diff views with collapsible unchanged regions. Tests cover theme changes; the mock renders the original and modified values.
Asynchronous component loading
src/components/code-editor/index.ts, src/components/code-editor/CodeEditorFallback.vue, src/components/code-editor/CodeEditorError.vue, src/components/code-editor/__tests__/index.spec.ts
Adds lazy-loaded component exports, loading and error displays, and retry handling with a limit of two retries. Tests cover retry and error states.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant VueParent
  participant CodeEditor
  participant EditorView
  VueParent->>CodeEditor: Pass modelValue and editor props
  CodeEditor->>EditorView: Create editor with modelValue
  EditorView->>CodeEditor: Report document changes
  CodeEditor->>VueParent: Emit update:modelValue
  VueParent->>CodeEditor: Pass updated modelValue
  CodeEditor->>EditorView: Replace document when values differ
Loading

Merge Risk: ⚪ Minimal · up to facc9

This adds reusable editor components that are not yet reachable in the app. No actionable merge-blocking risk was found.

Security Architecture Review

Security architecture risk: 🔵 Low · up to facc9

The new components are not wired into the application and do not directly save, transmit, or execute their content. Risk is limited, but isolation of undo history when an editor instance switches documents remains unresolved.

Retained concerns

  • Low · architecture · inferred: Cross-document undo/redo isolation is not established for the new reusable editor contract. External model replacement updates the existing history-enabled state without an explicit document-identity or history reset. The available undo check starts with empty history, leaving carryover after prior edits unresolved. This affects document ownership when consumers reuse an instance; no current production consumer or application-level disclosure was demonstrated.
Security review details

Security Blast Radius

  • inferred — Repository-visible exposure is limited to the new UI contracts and their tests. No production caller or direct persistence, network, credential, or execution sink was identified in the inspected component path. Future configuration-tab integration is outside this PR's assessed exposure.

Trust Boundaries and Controls

  • observed — The async loader targets are literal local module paths rather than caller-controlled URLs. Document strings flow into CodeMirror state and model events; the component contracts do not themselves grant service or infrastructure authority. The exposed EditorView remains available to parent code.

Resilience and Maintainability Implications

  • inferred — Explicit teardown and bounded loading retries constrain component lifecycle failures. Document switching is the remaining ownership uncertainty: suppressing a replacement's history entry has not established isolation from history accumulated before that replacement.

Hardening Proposals

  • proposed — Before integrating consumers that switch assets or configuration documents, define a document-identity boundary and verify prior-edit undo/redo across replacement. An identity-keyed remount or explicit state/history reset can provide isolation while allowing ordinary same-document synchronization to follow a separately defined policy.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 10 files. (5 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the CodeMirror-based code and merge editor, which is the main change in the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 10 files. (5 skipped: 5 unsupported.)

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit taps keys in a burrow of light
YAML and JSON line up just right
A diff splits the page, then reunites
Dark themes shift softly from day into night
The editor loads, and the hare hops in delight

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

JSON custom diagnostics can be overwritten, and the new editor surfaces have unresolved accessibility issues.

Review effort: Balanced
Findings: 4 Medium severity

Open (4)
What changed in this PR

Adds reusable, asynchronously loaded CodeMirror editors for future agent configuration features.

Changes:

  • Adds editable and merge-view components with JSON/YAML support, diagnostics, themes, and load states.
  • Adds focused component tests and jsdom browser API stubs.
  • Adds required CodeMirror and YAML dependencies.
File Description
vitest.setup.ts Stubs editor-required browser APIs.
src/​components/​code-editor/​theme.ts Defines light/dark editor themes.
src/​components/​code-editor/​languages/​index.ts Configures text, JSON, and YAML modes.
src/​components/​code-editor/​index.ts Exposes lazy-loaded editor components.
src/​components/​code-editor/​diagnostics.ts Converts positional errors to diagnostics.
src/​components/​code-editor/​CodeMergeView.vue Implements split and unified diffs.
src/​components/​code-editor/​CodeEditorFallback.vue Provides the loading placeholder.
src/​components/​code-editor/​CodeEditorError.vue Provides the load-error state.
src/​components/​code-editor/​CodeEditor.vue Implements the reusable editor.
src/​components/​code-editor/​__tests__/​index.spec.ts Tests loading retries and errors.
src/​components/​code-editor/​__tests__/​diagnostics.spec.ts Tests diagnostic position conversion.
src/​components/​code-editor/​__tests__/​CodeMergeView.spec.ts Tests merge-view theme updates.
src/​components/​code-editor/​__tests__/​CodeEditor.spec.ts Tests editor behavior and accessibility.
src/​components/​agents/​config/​__tests__/​codeEditorMock.ts Adds lightweight editor test doubles.
package.json Declares editor dependencies.
package-lock.json Locks added dependency versions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

<p
v-if="!readonly"
:id="hintId"
class="text-[0.7rem] text-gray-400 dark:text-slate-500"
Comment on lines +106 to +108
v.dispatch(
setDiagnostics(v.state, toDiagnostics(v.state.doc, props.diagnostics)),
);
Comment on lines +40 to +43
EditorState.readOnly.of(true),
EditorView.editable.of(false),
languageExtension(props.language, false),
themeConf.of(editorTheme(isDarkMode())),
{
backgroundColor: '#bae6fd',
},
'&.cm-focused': { outline: '2px solid #38bdf8' },
Layer 1 of 21 in the stacked split of #318.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gusfcarvalho
gusfcarvalho force-pushed the agent-config/01-code-editor branch from facc992 to dd93179 Compare October 5, 2026 16:32
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