Repository navigation
[FIX] Rebuild notebook from unified rows + resolved text areas - #30
Conversation
- Fixes duplicated rows
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis change introduces a UI-provided Changes
Sequence DiagramsequenceDiagram
participant User as User
participant UI as ConflictResolver (Web UI)
participant App as App.tsx
participant Panel as WebConflictPanel
participant Resolver as resolver.ts
User->>UI: Drag/drop and edit rows (choose resolutions)
UI->>UI: Build `resolvedRows` array (per-row choice + resolvedContent)
UI->>App: onResolve(resolutions, markAsResolved, resolvedRows)
App->>Panel: sendMessage({ kind: 'resolve', resolvedRows, ... })
Panel->>Resolver: applySemanticResolutions(unifiedResolution with resolvedRows)
Resolver->>Resolver: if resolvedRows present?
alt rows-based path
Resolver->>Resolver: applySemanticResolutionsFromRows(resolvedRows) -> build NotebookCells, handle deletes, metadata, merging
else legacy path
Resolver->>Resolver: applySemanticResolutionsLegacy(cellMappings...)
end
Resolver->>Resolver: prompt for execution-count renumbering
Resolver->>Resolver: saveResolvedNotebook
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~28 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/resolver.ts`:
- Around line 320-326: The current matching in applySemanticResolutionsFromRows
uses object reference and source string equality to find autoResolvedNotebook
cells, which is fragile; instead extend the ResolvedRow to carry the original
cell index (e.g., add a property like cellIndex or mapping.currentIndex
preserved through serialization) and change applySemanticResolutionsFromRows to
use that index to pick the corresponding cell from autoResolvedNotebook.cells
(fallback to current heuristics only if index is missing); update any code that
constructs ResolvedRow to populate the index so index-based lookup is reliable
across WebSocket/serialization boundaries.
- Around line 302-305: The code currently treats resolvedContent === '' as an
implicit deletion which conflicts with explicit choice === 'delete'; update the
logic in the resolver where resolvedContent and choice are handled so deletion
only occurs when choice === 'delete' (remove the implicit empty-content
continue), and add validation that if choice !== 'delete' and resolvedContent
=== '' the resolver raises/returns a validation error (or marks the cell
invalid) so empty content isn’t silently dropped; reference the resolvedContent
variable and the choice branch in the function handling cell resolution to
locate and modify the behavior.
🧹 Nitpick comments (4)
test/simulate_merge_uu.sh (1)
35-39: UseROOTto avoid hardcoded repo paths.You already compute
ROOTfrom the script’s location; consider using it for the initialcdto make the script portable across different checkout locations.♻️ Suggested update
-cd ~/source/repos/MergeNB - -npm run compile - -ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$ROOT" +npm run compilesrc/web/webTypes.ts (1)
35-53: Consider consolidating the duplicatedResolvedRowtype definition.The
ResolvedRowinterface is defined identically in bothsrc/web/webTypes.ts(lines 39-53) andsrc/web/client/types.ts(lines 77-91). This duplication creates a maintenance risk where changes to one definition might not be reflected in the other.Consider one of these approaches:
- Define
ResolvedRowonly inwebTypes.tsand re-export it fromclient/types.ts- Define it in a shared location and import from both files
♻️ Proposed fix: Re-export from client/types.ts
In
src/web/client/types.ts, replace the duplicate definition with:+// Re-export ResolvedRow from webTypes to avoid duplication +export type { ResolvedRow } from '../webTypes'; -/** - * Resolved row from the UI - represents the final state after drag/drop and user edits. - * This is the source of truth for reconstructing the notebook. - */ -export interface ResolvedRow { - /** Base cell (may be undefined if cell not present in base) */ - baseCell?: import('../../types').NotebookCell; - // ... rest of the interface -}src/web/WebConflictPanel.ts (1)
127-134: Consider using theBrowserToExtensionMessagetype instead of inline type assertion.The manual type shape duplicates what's already defined in
BrowserToExtensionMessage. Using the imported type would ensure consistency and catch future mismatches.♻️ Suggested improvement
+import type { UnifiedConflict, UnifiedResolution, ResolvedRow, BrowserToExtensionMessage } from './webTypes'; private _handleMessage(message: unknown): void { if (this._isDisposed) return; - const msg = message as { - command?: string; - type?: string; - resolutions?: Array<{ index: number; choice: string; resolvedContent: string }>; - resolvedRows?: ResolvedRow[]; - semanticChoice?: string; - markAsResolved?: boolean - }; + const msg = message as BrowserToExtensionMessage & { command?: string };src/resolver.ts (1)
309-319: Casting toanybypasses type safety.Lines 317-318 use
(cellToUse as any)to setexecution_countandoutputs. SinceNotebookCellalready defines these as optional properties for code cells, you can construct the full object conditionally instead.♻️ Proposed improvement
- cellToUse = { - cell_type: cellType, - metadata: referenceCell?.metadata ? JSON.parse(JSON.stringify(referenceCell.metadata)) : {}, - source: resolvedContent.split(/(?<=\n)/) - } as NotebookCell; - - // Add execution_count and outputs for code cells - if (cellType === 'code') { - (cellToUse as any).execution_count = null; - (cellToUse as any).outputs = []; - } + cellToUse = { + cell_type: cellType, + metadata: referenceCell?.metadata ? JSON.parse(JSON.stringify(referenceCell.metadata)) : {}, + source: resolvedContent.split(/(?<=\n)/), + ...(cellType === 'code' ? { execution_count: null, outputs: [] } : {}) + };
| // Check if deletion (empty content) | ||
| if (resolvedContent === '') { | ||
| continue; // Skip this cell | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Is it valid for a Jupyter notebook cell to have empty source content
💡 Result:
Yes—a cell’s source may be empty, e.g. "" (or [] on disk, since multiline strings may be stored as a list of strings). The notebook format treats source as a “multiline string” (a string or string[]), and an empty string/list is still a valid value. [1] [2]
What’s not valid (per the spec/schema) is omitting the source field entirely—cells are defined to include a source property. [1]
Sources:
[1] Jupyter nbformat “The Notebook file format” (cell structure + multiline string rules) (nbformat.readthedocs.io)
[2] JupyterLab nbformat type MultilineString = string | string[] (jupyterlab.readthedocs.io)
Citations:
- 1: https://nbformat.readthedocs.io/en/5.2.0/format_description.html
- 2: https://jupyterlab.readthedocs.io/en/4.0.x/api/types/nbformat.MultilineString.html?utm_source=openai
🏁 Script executed:
# Find and examine the resolver.ts file around lines 298-310
fd -t f "resolver.ts" | head -5Repository: Avni2000/MergeNB
Length of output: 111
🏁 Script executed:
# Read the resolver.ts file around lines 298-310 to understand the deletion logic
wc -l src/resolver.tsRepository: Avni2000/MergeNB
Length of output: 79
🏁 Script executed:
# Read lines 290-315 to get full context of the deletion logic
sed -n '290,315p' src/resolver.tsRepository: Avni2000/MergeNB
Length of output: 1265
🏁 Script executed:
# Let me look at more context to understand the user interaction flow
# Check lines 270-305 to see the broader context
sed -n '270,310p' src/resolver.tsRepository: Avni2000/MergeNB
Length of output: 1819
🏁 Script executed:
# Also check if there's a UI component that handles deletion separately
grep -n "delete" src/resolver.ts | head -20Repository: Avni2000/MergeNB
Length of output: 244
🏁 Script executed:
# Check the UI component to understand how resolvedContent is set and if users can clear it
fd -t f "ConflictResolver.tsx" -o "conflict" | head -5Repository: Avni2000/MergeNB
Length of output: 195
🏁 Script executed:
# Look for how resolvedContent is managed in the UI
rg -n "resolvedContent" src/ -B 2 -A 2 | head -40Repository: Avni2000/MergeNB
Length of output: 2559
🏁 Script executed:
# Find the UI component that handles the text area and see if users can clear content
fd -t f "ConflictResolver.tsx"Repository: Avni2000/MergeNB
Length of output: 95
🏁 Script executed:
# Search for text area handling in the UI
rg -n "textarea\|text area\|resolvedContent" src/web/ -lRepository: Avni2000/MergeNB
Length of output: 42
🏁 Script executed:
# Examine the ConflictResolver.tsx to understand user interaction
wc -l src/web/client/ConflictResolver.tsxRepository: Avni2000/MergeNB
Length of output: 99
🏁 Script executed:
# Search for textarea or text input handling in the resolver UI
rg -n "textarea|input|onChange|resolvedContent" src/web/client/ConflictResolver.tsx -A 2 -B 2 | head -60Repository: Avni2000/MergeNB
Length of output: 2018
🏁 Script executed:
# Find the textarea element in ConflictResolver.tsx
rg -n "textarea|<textarea" src/web/client/ConflictResolver.tsx -B 3 -A 3Repository: Avni2000/MergeNB
Length of output: 42
🏁 Script executed:
# Look at how the resolved content text editor is rendered
sed -n '200,300p' src/web/client/ConflictResolver.tsxRepository: Avni2000/MergeNB
Length of output: 4118
🏁 Script executed:
# Look for more context around how the text editor is rendered and if there are any warnings/validations
sed -n '300,400p' src/web/client/ConflictResolver.tsx | head -80Repository: Avni2000/MergeNB
Length of output: 4435
🏁 Script executed:
# Also check if there's any documentation or comments about the intended behavior
rg -n "empty|clear|delete" src/resolver.ts -B 2 -A 2 | head -40Repository: Avni2000/MergeNB
Length of output: 2090
Clarify whether empty resolvedContent should trigger cell deletion or if it should be explicitly prevented.
The current logic treats empty resolvedContent as implicit cell deletion (line 302–304), which coexists with the explicit choice: 'delete' path (line 297–299). While Jupyter notebook cells can validly have empty source content per the nbformat specification, the implicit deletion here creates a potential issue: if a user selects "current" and then accidentally clears the text area, the cell will be silently deleted rather than resulting in a validation error.
Consider either:
- Removing the empty content check and allowing empty cells to be preserved (valid per Jupyter spec)
- Adding validation to prevent empty content for non-delete choices (flag as error)
- Making deletion explicit in the UI (dedicated delete button/choice) rather than relying on clearing the text
🤖 Prompt for AI Agents
In `@src/resolver.ts` around lines 302 - 305, The code currently treats
resolvedContent === '' as an implicit deletion which conflicts with explicit
choice === 'delete'; update the logic in the resolver where resolvedContent and
choice are handled so deletion only occurs when choice === 'delete' (remove the
implicit empty-content continue), and add validation that if choice !== 'delete'
and resolvedContent === '' the resolver raises/returns a validation error (or
marks the cell invalid) so empty content isn’t silently dropped; reference the
resolvedContent variable and the choice branch in the function handling cell
resolution to locate and modify the behavior.
- Chill on the comments
Closes #27
Rebuilds notebook as {Unified Rows} U {Resolved Text Areas}
Summary by CodeRabbit
New Features
Refactor
Chores