Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
},
"dependencies": {
"@guolao/vue-monaco-editor": "^1.5.4",
"@hey-api/client-axios": "0.2.12",
"@lucide/vue": "^1.23.0",
"@tiptap/starter-kit": "2.1.7",
Expand All @@ -35,12 +34,11 @@
"markdown-it-ts": "^1.1.7",
"markstream-vue": "2.0.26",
"mermaid": "^11.12.2",
"monaco-editor": "^0.52.2",
"pinia": "2.1.6",
"pinyin-pro": "^3.26.0",
"qrcode": "^1.5.4",
"shiki": "^3.23.0",
"stream-diffs": "0.0.2",
"stream-diffs": "0.0.5",

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.

🟠 High · Select-all edits retain old text

When a user selects all editor contents and types several characters consecutively, the edit callback accepts the surface's contents without correcting the known select-all replacement defect, so typing several characters after selecting all leaves trailing tokens from the previous document in the editor; users can save corrupted text.

Upgrade or patch the underlying edit surface so select-all followed by consecutive typing fully replaces the selection before enabling this editor in the dashboard.

Also at dashboard/src/components/shared/StreamDiffsEditor.vue:96-98.

Prompt for AI agents
In `dashboard/package.json` at line 41:

**Select-all edits retain old text**

When a user selects all editor contents and types several characters consecutively, the edit callback accepts the surface's contents without correcting the known select-all replacement defect, so typing several characters after selecting all leaves trailing tokens from the previous document in the editor; users can save corrupted text.

Upgrade or patch the underlying edit surface so select-all followed by consecutive typing fully replaces the selection before enabling this editor in the dashboard.

Also at `dashboard/src/components/shared/StreamDiffsEditor.vue:96-98`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not fixed here on purpose — this is an upstream @pierre/diffs 1.7.1 defect, not something this wrapper introduced, and it is already documented in the PR description under "Known limitation".

Repro on a bare createDiffSurface with no Vue wrapper and no app code: select-all, then per-key typing leaves the trailing characters of the previous document; a single key press over the same selection replaces correctly, and paste/IME (insertText) replaces correctly. A setEdges/selection workaround was tried and made it worse (text inserted at the start of the document), so I dropped it rather than ship a hack.

The auto-format path is not exposed to this: replaceAll() applies one explicit full-range edit, and applyEdits is exact. So the blast radius is "user selects all and types several characters by hand" in the 8 editable surfaces.

Agreed this needs a fix, but the fix belongs in stream-diffs. Happy to keep this PR open until that lands if you would rather gate the merge on it — just say which you prefer.

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.

Thanks for confirming it reproduces on the bare surface. Please keep the PR gated until stream-diffs fixes this or there’s a reliable workaround: the bug affects the editable surfaces and can leave stale text in content users may save, so documenting it alone isn’t enough. Once addressed upstream, please add a regression check for select-all followed by consecutive typing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updating this thread with new evidence — my first reply undersold the bug, and the PR description has been rewritten accordingly.

It reproduces in the real dashboard, on the File surface, at every document size. Driven end-to-end on this branch (/data/conversations/legacy → view → Edit Conversation), real Chromium, mocked /api/**, seeded with JSON.stringify(history, null, 2), select-all then typing {"b":2} character by character:

history messages document lines rows rendered text after typing leftover
1 7 7 {"b":2}"} 2 chars
2 12 12 {"b":2}"} 2 chars
5 27 27 {"b":2} + the whole original document 433 chars
12 62 62 {"b":2} + the whole original document 1,046 chars
40 202 202 {"b":2} + the whole original document 3,525 chars

rows rendered == document lines in every row, so my earlier assumption that this needed a virtualized surface was wrong. This is not a rendering artifact either — the editor model is corrupted: pressing Save Changes shows "Invalid JSON format" and sends no request, while the control case (same select-all, content delivered as one insertText) formats and saves normally via PUT /api/v1/conversations/{cid}/messages.

It is upstream, and not reachable from either wrapper. stream-diffs has no select-all code at all (grep -rn selectAll src/ dist/ → nothing); src/edit.ts is export * from '@pierre/diffs/edit', and DiffSurfaceController.startEditing() only constructs the upstream Editor and calls editor.edit(instance). cmd/ctrl+A is an upstream keybinding command (dist/editor/command.js maps it to selectAll; the editor's own keydown listener runs the private #runCommand('selectAll')). The race is inside @pierre/diffs: selectAll sets the whole-document selection, then focus() collapses the native selection, then it widens the native selection only to the rendered range with #suppressNativeSelectionSync = true — and the keydown handler clears that flag as its first statement, so a queued selectionchange dispatched after the first keystroke is read back over #selections. #selections, #suppressNativeSelectionSync and #runCommand are all #private, so neither stream-diffs nor StreamDiffsEditor.vue can fix or shim it; a programmatic setEditorSelections substitute was tried and made it worse (text inserted at the start of the document), which is why I did not ship one.

On your gating request: agreed, and I am not asking to merge around it. An upstream issue is being filed with this repro and the proposed fix (stop clearing the suppression flag on keydown, clear it once the edit completes, and stop selectAll from being collapsed by its own focus()), plus a regression check that types several characters over a select-all selection at 7 / 27 / 202 lines as you asked. The PR description now carries the evidence table, the mechanism, the blast radius (JSON surfaces block the save; the T2I template and skills editors have no JSON gate and are unverified — flagged as a risk), and an explicit "merge only if you accept this, or wait for the upstream fix" note.

I would rather this PR stayed blocked until the upstream fix lands. If a reviewer prefers to take it earlier, the honest framing is that it moves nine dashboard editors onto a known data-integrity bug.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Root cause found and mitigated in 77c94f5 — and one correction to my previous reply.

The root cause is auto-surround, not a selection race. @pierre/diffs auto-surrounds any non-collapsed selection, including one spanning the whole document: typing { after cmd/ctrl+A produces {<whole document>} instead of replacing it, and the caret then sits just after the inserted opener, so every following character lands near the start of the buffer while the original content stays.

A/B on the same harness (history editor, real Chromium, mocked /api/**, select-all then typing {"b":2} one key at a time), three consecutive runs with identical results:

document lines default autoSurround autoSurround: 'never'
7 87 stale chars, save rejected (Invalid JSON format, 0 requests) {"b":2} → formatted → saved
12 2 stale chars, rejected saved
27 2 stale chars, rejected saved
62 1,047 stale chars, rejected saved
202 3,525 stale chars, rejected saved

Typing { alone over the select-all: default wraps the whole document (length +1), 'never' replaces it (length 1).

The fix in this PR: StreamDiffsEditor.vue now passes autoSurround: 'never' to startEditing(). It removes the symptom entirely and matches Monaco's behaviour (Monaco never wrapped a selection), so it is not a behaviour change users would notice. It is a mitigation — the surprising default is still upstream, tracked in pierrecomputer/pierre#1338 with this evidence and a suggested fix.

Correction: my previous reply described a second defect — a selectionchange read-back race in #runCommand('selectAll'). That came from a hacked local build where I had forced the auto-surround helper to return early, not from the public option. With autoSurround: 'never' the select-all path behaved correctly at every size. I have corrected the PR description too: those code paths are worth upstream attention, but this PR makes no claim that they misbehave on their own. Mode B was my instrumentation, not your product.

Residual risk, stated plainly: the A/B was measured on the conversation history editor; the other eight surfaces share the same wrapper and therefore the same option but were not re-measured. The T2I template editor and skills editor have no JSON gate, so a corrupted document there would still save silently — not re-driven after this change.

Gates on the pushed commit: pnpm run i18n:check PASS, pnpm run build (includes vue-tsc --noEmit) exit 0.

Given the symptom is now gone and the mechanism is understood, I would treat the gating request as satisfiable by this commit plus the upstream issue — but say the word if you would rather keep it blocked until #1338 ships.

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.

The current wrapper sets autoSurround: 'never' for every edit session, addressing the select-all replacement failure. This resolves my gating concern for this PR; thanks for the reproduction and follow-up evidence.

"vee-validate": "4.11.3",
"vite-plugin-vuetify": "2.1.3",
"vue": "3.3.4",
Expand Down
99 changes: 30 additions & 69 deletions dashboard/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 9 additions & 14 deletions dashboard/src/components/extension/McpServersSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,8 @@
{{ tm('dialogs.addServer.tips.transportRecommendation') }}
</v-alert>

<div class="monaco-container" style="margin-top: 16px;">
<VueMonacoEditor v-model:value="serverConfigJson" theme="vs-dark" language="json" :options="{
minimap: {
enabled: false
},
scrollBeyondLastLine: false,
automaticLayout: true,
lineNumbers: 'on',
roundedSelection: true,
tabSize: 2
}" @change="validateJson" />
<div class="server-config-editor" style="margin-top: 16px;">
<StreamDiffsEditor v-model="serverConfigJson" language="json" theme-type="dark" :font-size="13" @change="validateJson" />
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
</div>

<div v-if="jsonError" class="mt-2 text-error">
Expand Down Expand Up @@ -429,7 +420,7 @@
</template>

<script>
import { LazyMonacoEditor as VueMonacoEditor } from '@/components/shared/LazyMonacoEditor';
import StreamDiffsEditor from '@/components/shared/StreamDiffsEditor.vue';
import { mcpApi } from '@/api/v1';
import { useI18n, useModuleI18n } from '@/i18n/composables';
import OutlinedActionListItem from '@/components/shared/OutlinedActionListItem.vue';
Expand All @@ -442,7 +433,7 @@ import {
export default {
name: 'McpServersSection',
components: {
VueMonacoEditor,
StreamDiffsEditor,
OutlinedActionListItem
},
setup() {
Expand Down Expand Up @@ -625,6 +616,10 @@ export default {
};
}
this.serverConfigJson = JSON.stringify(template, null, 2);
// The editor swaps an externally assigned document without emitting
// `change`, so re-run validation here or an error from the previous
// content would stay on screen next to valid JSON.
this.validateJson();
},
saveServer() {
if (!this.validateJson()) {
Expand Down Expand Up @@ -979,7 +974,7 @@ export default {
transform: translateY(-4px) scale(1.05);
}

.monaco-container {
.server-config-editor {
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 8px;
height: 300px;
Expand Down
Loading
Loading