Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0e1bada
fix(vscode): restore native diff approval flow
yiliang114 Aug 30, 2026
f1f45f2
fix(vscode): only accept host-delivered web-shell permission decisions
yiliang114 Aug 30, 2026
1be6b2d
fix(vscode): open web-shell permission diffs read-only
yiliang114 Aug 30, 2026
f9a6d9b
fix(vscode): align showDiff overload signatures with options argument
yiliang114 Aug 30, 2026
2317625
fix(vscode): only vote web-shell approvals from the permission diff
yiliang114 Aug 30, 2026
1744245
fix(web-shell): lowercase tool names inside isEditToolName
yiliang114 Aug 30, 2026
5071a73
docs(web-shell): note pending-edit-approval exception in expand invar…
yiliang114 Aug 30, 2026
eb6ff92
test(web-shell): pin allow_once-first ladder for native edit approvals
yiliang114 Aug 30, 2026
8bac3fd
test(vscode): expect the readOnly options argument in showDiff comman…
yiliang114 Aug 30, 2026
868ade9
fix(vscode): accept host-relayed permission decisions by their source…
yiliang114 Aug 30, 2026
48cafd6
fix(vscode): only accept diff votes targeting a pending permission diff
yiliang114 Aug 30, 2026
59f8a6b
test(vscode): pin web-shell diff source to readOnly showDiff mapping
yiliang114 Aug 30, 2026
ee902f1
fix(vscode): keep read-only approval diffs from reusing writable twins
yiliang114 Aug 30, 2026
01546cf
fix(vscode): clear web-shell permission flag when the chat view disposes
yiliang114 Aug 30, 2026
446610c
test(vscode): pin the command-level diff vote gate chain
yiliang114 Aug 30, 2026
3e86689
test(vscode): expect pending:false when permission diffs are torn down
yiliang114 Aug 30, 2026
d8cefb2
fix(vscode): complete WebShell host interaction parity
yiliang114 Aug 30, 2026
4b408eb
merge: integrate concurrent VS Code diff safeguards
yiliang114 Aug 30, 2026
b546b30
fix(vscode): surface a notice when a diff vote is not applied
yiliang114 Aug 30, 2026
44b9d08
fix(vscode): complete native diff follow-ups
yiliang114 Aug 30, 2026
3a0824a
Merge branch 'main' into codex/vscode-webshell-diff-approval
yiliang114 Aug 30, 2026
258acf9
fix(vscode): address native diff verification findings
yiliang114 Aug 30, 2026
7ecdea9
test(vscode): cover legacy diff permission fallback
yiliang114 Aug 30, 2026
4fee90a
fix(web-shell): accept native votes for structured edits
yiliang114 Aug 31, 2026
427dc2e
Merge branch 'main' into codex/vscode-webshell-diff-approval
yiliang114 Aug 31, 2026
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
33 changes: 33 additions & 0 deletions packages/cli/src/acp-integration/session/permissionUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,39 @@ describe('permissionUtils', () => {
}),
);
});

it('keeps one-shot and always-allow options on edit approvals', () => {
const options = toPermissionOptions({
type: 'edit',
title: 'Confirm edit',
fileName: 'a.txt',
filePath: '/tmp/a.txt',
fileDiff: 'diff',
originalContent: 'a',
newContent: 'b',
onConfirm: async () => undefined,
});

// Both kinds must stay present and in this wire order: the web-shell
// native Accept path selects by kind preference (allow_once first), so
// a missing allow_once would escalate a single Accept into
// "Allow All Edits".
expect(options).toEqual([
expect.objectContaining({
optionId: ToolConfirmationOutcome.ProceedAlways,
name: 'Allow All Edits',
kind: 'allow_always',
}),
expect.objectContaining({
optionId: ToolConfirmationOutcome.ProceedOnce,
kind: 'allow_once',
}),
expect.objectContaining({
optionId: ToolConfirmationOutcome.Cancel,
kind: 'reject_once',
}),
]);
});
});

describe('interactionMetaFields', () => {
Expand Down
11 changes: 9 additions & 2 deletions packages/vscode-ide-companion/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,18 @@ export function registerNewCommands(
disposables.push(
vscode.commands.registerCommand(
showDiffCommand,
async (args: { path: string; oldText: string; newText: string }) => {
async (args: {
path: string;
oldText: string;
newText: string;
readOnly?: boolean;
}) => {
try {
const absolutePath = resolveWorkspaceRelativePath(args.path);
log(`[Command] Showing diff for ${absolutePath}`);
await diffManager.showDiff(absolutePath, args.oldText, args.newText);
await diffManager.showDiff(absolutePath, args.oldText, args.newText, {
readOnly: args.readOnly === true,
});
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
} catch (error) {
const errorMsg = getErrorMessage(error);
log(`[Command] Error showing diff: ${errorMsg}`);
Expand Down
108 changes: 108 additions & 0 deletions packages/vscode-ide-companion/src/diff-manager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

import { beforeEach, describe, expect, it, vi } from 'vitest';

const executeCommand = vi.fn().mockResolvedValue(undefined);

vi.mock('vscode', () => {
class EventEmitter<T> {
private listeners = new Set<(event: T) => void>();
event = (listener: (event: T) => void) => {
this.listeners.add(listener);
return { dispose: () => this.listeners.delete(listener) };
};
fire(event: T): void {
for (const listener of [...this.listeners]) listener(event);
}
dispose(): void {
this.listeners.clear();
}
}

return {
EventEmitter,
Uri: {
file: (filePath: string) => {
const uri: {
fsPath: string;
scheme: string;
query: string;
with: (change: Record<string, unknown>) => unknown;
toString: () => string;
} = {
fsPath: filePath,
scheme: 'file',
query: '',
with(change: Record<string, unknown>) {
return { ...uri, ...change };
},
toString() {
return `${uri.scheme}://${uri.fsPath}?${uri.query}`;
},
};
return uri;
},
},
ViewColumn: { Beside: -2 },
commands: { executeCommand },
window: {
activeTextEditor: undefined,
onDidChangeActiveTextEditor: vi.fn(() => ({ dispose: vi.fn() })),
tabGroups: { all: [] },
},
};
});

// Avoid pulling the full extension module graph; only the scheme constant is
// needed by the diff manager.
vi.mock('./extension.js', () => ({ DIFF_SCHEME: 'qwen-diff' }));

vi.mock('@qwen-code/qwen-code-core', () => ({
IdeDiffAcceptedNotificationSchema: { parse: (value: unknown) => value },
IdeDiffClosedNotificationSchema: { parse: (value: unknown) => value },
}));

const { DiffContentProvider, DiffManager } = await import('./diff-manager.js');

const WRITABLE_COMMAND =
'workbench.action.files.setActiveEditorWriteableInSession';

describe('DiffManager.showDiff writability', () => {
beforeEach(() => {
executeCommand.mockClear();
});

function createManager(): InstanceType<typeof DiffManager> {
return new DiffManager(() => {}, new DiffContentProvider());
}

it('makes regular diffs editable so IDE-mode approvals can round-trip edits', async () => {
const manager = createManager();

await manager.showDiff('/workspace/foo.ts', 'old', 'new');

expect(executeCommand).toHaveBeenCalledWith(WRITABLE_COMMAND);
});

it('keeps read-only diffs locked for flows that cannot round-trip edits', async () => {
const manager = createManager();

await manager.showDiff('/workspace/foo.ts', 'old', 'new', {
readOnly: true,
});

expect(executeCommand).not.toHaveBeenCalledWith(WRITABLE_COMMAND);
// The diff itself still opens.
expect(executeCommand).toHaveBeenCalledWith(
'vscode.diff',
expect.anything(),
expect.anything(),
expect.stringContaining('foo.ts'),
expect.anything(),
);
});
});
39 changes: 34 additions & 5 deletions packages/vscode-ide-companion/src/diff-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ export class DiffContentProvider implements vscode.TextDocumentContentProvider {
}
}

/** Options controlling how a diff editor is opened. */
export interface ShowDiffOptions {
/**
* Open the right-hand (proposed) side as read-only. Use this when the
* approval flow cannot round-trip user edits: the approving daemon tool
* applies its own proposed content, so an editable right side would
* silently discard anything the user typed (e.g. web-shell permission
* diffs opened while IDE mode is off).
*/
readOnly?: boolean;
}

// Information about a diff view that is currently open.
interface DiffInfo {
originalFilePath: string;
Expand Down Expand Up @@ -162,14 +174,25 @@ export class DiffManager {
* If only newContent is provided, the old content will be read from the
* filesystem (empty string when file does not exist).
*/
async showDiff(filePath: string, newContent: string): Promise<void>;
async showDiff(
filePath: string,
newContent: string,
options?: ShowDiffOptions,
): Promise<void>;
async showDiff(
filePath: string,
oldContent: string,
newContent: string,
options?: ShowDiffOptions,
): Promise<void>;
async showDiff(filePath: string, a: string, b?: string): Promise<void> {
async showDiff(
filePath: string,
a: string,
b?: string | ShowDiffOptions,
options?: ShowDiffOptions,
): Promise<void> {
const haveOld = typeof b === 'string';
const resolvedOptions = haveOld ? options : b;
const oldContent = haveOld ? a : await this.readOldContentFromFs(filePath);
const newContent = haveOld ? (b as string) : a;
const normalizedPath = path.normalize(filePath);
Expand Down Expand Up @@ -242,9 +265,15 @@ export class DiffManager {
preserveFocus: true,
},
);
await vscode.commands.executeCommand(
'workbench.action.files.setActiveEditorWriteableInSession',
);
// The writeable-in-session flag exists so users can adjust the proposed
// content before accepting; that only round-trips when an IDE-mode
// resolver consumes the edited text. Read-only callers (web-shell
// permission approvals) would silently lose edits, so keep them locked.
if (!resolvedOptions?.readOnly) {
await vscode.commands.executeCommand(
'workbench.action.files.setActiveEditorWriteableInSession',
);
}
Comment thread
yiliang114 marked this conversation as resolved.
Resolved

this.recentlyShown.set(key, Date.now());
}
Expand Down
8 changes: 6 additions & 2 deletions packages/vscode-ide-companion/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ export async function activate(context: vscode.ExtensionContext) {
for (const provider of chatProviderRegistry?.getPermissionAwareProviders() ??
[]) {
if (provider?.hasPendingPermission()) {
provider.respondToPendingPermission('allow');
provider.respondToPendingPermission('allow', {
fromDiffEditor: !!docUri && docUri.scheme === DIFF_SCHEME,
});
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
}
}
} catch (err) {
Expand All @@ -276,7 +278,9 @@ export async function activate(context: vscode.ExtensionContext) {
for (const provider of chatProviderRegistry?.getPermissionAwareProviders() ??
[]) {
if (provider?.hasPendingPermission()) {
provider.respondToPendingPermission('cancel');
provider.respondToPendingPermission('cancel', {
fromDiffEditor: !!docUri && docUri.scheme === DIFF_SCHEME,
});
}
}
} catch (err) {
Expand Down
54 changes: 54 additions & 0 deletions packages/vscode-ide-companion/src/webview/EmbeddedApp.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,57 @@ describe('EmbeddedApp host wiring', () => {
}
});
});

describe('web shell permission decision messages', () => {
function installShellApi(
api: Record<string, unknown>,
): Record<string, unknown> {
const props = mocks.embeddedProps.current;
expect(props).not.toBeNull();
const shellRef = (props as CapturedProps)['shellRef'] as {
current: unknown;
};
expect(shellRef).toBeTruthy();
shellRef.current = api;
return api;
}

async function dispatchDecision(decision: string, source: Window | null) {
await act(async () => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
type: 'webShellPermissionDecision',
data: { decision },
},
source,
}),
);
await Promise.resolve();
});
}

it('forwards platform-delivered decisions to the web shell', async () => {
await renderApp();
const respondToPendingPermission = vi.fn().mockResolvedValue(true);
installShellApi({ respondToPendingPermission });

await dispatchDecision('allow', null);

expect(respondToPendingPermission).toHaveBeenCalledWith('allow');
});

it('ignores decisions posted by a window source such as a sandboxed iframe', async () => {
await renderApp();
const respondToPendingPermission = vi.fn().mockResolvedValue(true);
installShellApi({ respondToPendingPermission });

// MCP apps and artifact previews run in scriptable sandboxed iframes
// inside this webview; they can postMessage to the top window and must
// not be able to vote on the pending approval.
await dispatchDecision('allow', window);
await dispatchDecision('reject', window);

expect(respondToPendingPermission).not.toHaveBeenCalled();
});
});
Loading
Loading