-
-
Notifications
You must be signed in to change notification settings - Fork 735
fix(file-preview): attribute events to source tools #479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| * 3. Unify the editRange() signature to handle both text search/replace and structured edits | ||
| */ | ||
|
|
||
| import { readFile, writeFile, readFileInternal, validatePath } from './filesystem.js'; | ||
| import { getDefaultEditorMetadata, readFile, writeFile, readFileInternal, validatePath } from './filesystem.js'; | ||
| import fs from 'fs/promises'; | ||
| import { ServerResult } from '../types.js'; | ||
| import { recursiveFuzzyIndexOf, getSimilarityRatio } from './fuzzySearch.js'; | ||
|
|
@@ -227,6 +227,8 @@ RECOMMENDATION: For large search/replace operations, consider breaking them into | |
| fileName: path.basename(resolvedEditPath), | ||
| filePath: resolvedEditPath, | ||
| fileType: resolvePreviewFileType(resolvedEditPath), | ||
| sourceTool: 'edit_block', | ||
| ...await getDefaultEditorMetadata(resolvedEditPath), | ||
|
Comment on lines
+230
to
+231
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t let optional editor-metadata lookup fail successful edit operations. These success paths perform the edit first, then await metadata. If metadata lookup fails, the tool returns an error despite a completed mutation, which can trigger duplicate retries. Proposed fix+const safeDefaultEditorMetadata = async (filePath: string) => {
+ try {
+ return await getDefaultEditorMetadata(filePath);
+ } catch {
+ return {};
+ }
+};
...
- ...await getDefaultEditorMetadata(resolvedEditPath),
+ ...await safeDefaultEditorMetadata(resolvedEditPath),
...
- ...await getDefaultEditorMetadata(resolvedRangePath),
+ ...await safeDefaultEditorMetadata(resolvedRangePath),
...
- ...await getDefaultEditorMetadata(resolvedEditRangePath),
+ ...await safeDefaultEditorMetadata(resolvedEditRangePath),Also applies to: 443-444, 483-484 🤖 Prompt for AI Agents |
||
| }, | ||
| }; | ||
| } | ||
|
|
@@ -438,6 +440,8 @@ export async function handleEditBlock(args: unknown): Promise<ServerResult> { | |
| fileName: path.basename(resolvedRangePath), | ||
| filePath: resolvedRangePath, | ||
| fileType: resolvePreviewFileType(resolvedRangePath), | ||
| sourceTool: 'edit_block', | ||
| ...await getDefaultEditorMetadata(resolvedRangePath), | ||
| }, | ||
| }; | ||
| } catch (error) { | ||
|
|
@@ -476,6 +480,8 @@ export async function handleEditBlock(args: unknown): Promise<ServerResult> { | |
| fileName: path.basename(resolvedEditRangePath), | ||
| filePath: resolvedEditRangePath, | ||
| fileType: resolvePreviewFileType(resolvedEditRangePath), | ||
| sourceTool: 'edit_block', | ||
| ...await getDefaultEditorMetadata(resolvedEditRangePath), | ||
| }, | ||
| }; | ||
| } | ||
|
|
@@ -492,4 +498,4 @@ export async function handleEditBlock(args: unknown): Promise<ServerResult> { | |
| search: parsed.old_string, | ||
| replace: parsed.new_string | ||
| }, parsed.expected_replacements); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make editor metadata enrichment best-effort so it never flip-flops successful operations into errors.
getDefaultEditorMetadata()is optional enrichment, but it currently gates the full response. If it throws afterwriteFilesucceeds, callers can receive an error and retry non-idempotent writes (notablyappend), causing duplicate content.Proposed fix
Also applies to: 170-171, 191-192, 313-314
🤖 Prompt for AI Agents