feat(plugins): open workbench in tabs from dock surfaces

This commit is contained in:
Jinpy authored and GitHub committed 2026-09-30 21:22:25 +08:00
1 parent bba60bfa86
commit 0212231421
6 files changed
+31 -11

No files matched your search

@@ -27,7 +27,8 @@ export interface PluginDockEntry {
instanceKey?: string;
title: string;
icon?: string;
/** Host-authored context: workbenchId=id, restored=false, surface="panel". */
/** Host-authored context: workbenchId=id, restored=false, surface="dock". */
/** Surface vocabulary (open set, unknown falls back): "tab" (main multi-tab workbench) / "dock" (bottom dock, was "panel" — renamed 2026-09-30) / "sidebar-left" / "sidebar-right" / "window" (reserved). */
context: Record<string, unknown>;
}
@@ -78,7 +79,7 @@ export function addPluginDockEntry(payload: AddPluginDockEntryPayload): string {
...(payload.commandContext ?? {}),
workbenchId: id,
restored: false,
surface: "panel",
surface: "dock",
},
});
activeEntryId.value = id;
+2 -2
View File
@@ -108,7 +108,7 @@ describe("plugin command registry (PR-A4)", () => {
expect(firstEntry.context.workbenchId).toBe(firstEntry.id);
expect(firstEntry.context.workbenchId).not.toBe("plugin-forged");
expect(firstEntry.context.restored).toBe(false);
expect(firstEntry.context.surface).toBe("panel");
expect(firstEntry.context.surface).toBe("dock");
expect(activeEntryId.value).toBe(firstEntry.id);
// §4.1 reuse key = pluginId + commandId + presentation + instance_key.
expect(firstEntry.instanceKey).toBe("local-terminal");
@@ -270,6 +270,6 @@ describe("plugin command registry (PR-A4)", () => {
// §11: reserved identity fields are host-authored — forged values never pass.
expect(entry.context.workbenchId).toBe(entry.id);
expect(entry.context.restored).toBe(false);
expect(entry.context.surface).toBe("panel");
expect(entry.context.surface).toBe("dock");
});
});
@@ -41,7 +41,7 @@ export function executePluginCommand(registry: FrontendPluginRegistry, queryStor
if (!workbench) return { error: `Command '${pluginId}.${commandId}' references missing workbench '${action.workbench}'` };
// §5.4 re-validate enablement right before execution (against the current context snapshot; the surface key follows
// presentation).
const commandContextKeys: PluginConditionContextKeys = { surface: action.presentation === "panel" ? "panel" : "tab", "connection.state": "none", readOnly: false };
const commandContextKeys: PluginConditionContextKeys = { surface: action.presentation === "panel" ? "dock" : "tab", "connection.state": "none", readOnly: false };
if (!evaluatePluginCommandConditions(command.enablement?.all, commandContextKeys)) {
return { error: `Command '${pluginId}.${commandId}' is disabled by enablement` };
}
@@ -163,7 +163,7 @@ export interface PluginHostBridgeApi {
generateAiText?(pluginName: string, input: PluginAiGenerateRequest): Promise<string>;
openAiConversation?(request: AiPluginConversationRequest): Promise<void>;
setAiRecommendations?(update: PluginAiRecommendationHostUpdate): void;
openWorkbench?(pluginId: string, contributionId: string, context?: PluginWorkbenchContext, options?: { forceNew?: boolean }): Promise<void> | void;
openWorkbench?(pluginId: string, contributionId: string, context?: PluginWorkbenchContext, options?: { forceNew?: boolean; target?: "tab" }): Promise<void> | void;
/**
* §4/§5 command execution asked from a plugin webview: the same registry
* path as menu execution — enablement (§5.4), §4.1 singleton reuse,
@@ -685,7 +685,11 @@ export class PluginHostBridge {
this.requirePermission("host.workbench");
if (!this.api.openWorkbench) throw new Error("Host workbench navigation is unavailable");
const input = requireRecord(params, "host.openWorkbench params");
await this.api.openWorkbench(this.plugin.manifest.id, requireProtocolName(input.contributionId, "workbench contribution"), isRecord(input.context) ? input.context : undefined, { forceNew: input.forceNew === true });
// `target: "tab"` lets a dock-hosted webview ask for a main-workbench
// tab instead of another dock entry (e.g. the SSH dock's "open session
// in tab" button). Surfaces that ignore it keep the old behavior, so
// older handlers stay compatible.
await this.api.openWorkbench(this.plugin.manifest.id, requireProtocolName(input.contributionId, "workbench contribution"), isRecord(input.context) ? input.context : undefined, { forceNew: input.forceNew === true, target: input.target === "tab" ? "tab" : undefined });
return null;
}
if (method === "host.executeCommand") {
@@ -1239,7 +1243,7 @@ export function pluginSdkSource(initialTheme?: PluginBridgeTheme): string {
const asset = await request('ui.readAsset', { path });
return URL.createObjectURL(new Blob([decode(asset.dataBase64)], { type: asset.contentType }));
},
openWorkbench: (contributionId, childContext, options) => request('host.openWorkbench', { contributionId, context: childContext, forceNew: !!(options && options.forceNew) }),
openWorkbench: (contributionId, childContext, options) => request('host.openWorkbench', { contributionId, context: childContext, forceNew: !!(options && options.forceNew), target: options && options.target === "tab" ? "tab" : undefined }),
// §4/§5 command execution from a webview — the same registry path a menu
// placement takes (enablement, §4.1 reuse, host-authored context),
// scoped to the plugin's own declared commands. The optional context
@@ -80,7 +80,7 @@ export function collectPluginShortcuts(registry: FrontendPluginRegistry): Plugin
rootUri,
disabled: command
? !evaluatePluginCommandConditions(command.enablement?.all, {
surface: command.action.presentation === "panel" ? "panel" : "tab",
surface: command.action.presentation === "panel" ? "dock" : "tab",
"connection.state": "none",
readOnly: false,
})