Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

feat(plugins): open docked views from transcript selections

Linuxdazhao0fbb2ddbfaca
diff --git a/apps/desktop/electron/main/ipc/plugin-ui-ipc.ts b/apps/desktop/electron/main/ipc/plugin-ui-ipc.ts
index 8b6631813..93721afc8 100644
--- a/apps/desktop/electron/main/ipc/plugin-ui-ipc.ts
+++ b/apps/desktop/electron/main/ipc/plugin-ui-ipc.ts
@@ -63,6 +63,7 @@ export function registerPluginUiIpc({
* after a newer one cannot restore a session the user already left.
*/
const sessionPushGate = createSessionPushGate();
+ let selectedSession: { id: string; projectPath: string | null } | null = null;
/**
* The session on screen, as the shell sees it.
*
@@ -87,6 +88,7 @@ export function registerPluginUiIpc({
}
const sessionId = typeof payload?.sessionId === "string" ? payload.sessionId.trim() : "";
if (!sessionId) {
+ selectedSession = null;
setActivePluginSession(null);
return { ok: true };
}
@@ -95,6 +97,9 @@ export function registerPluginUiIpc({
}
const projectPath =
typeof payload?.projectPath === "string" ? payload.projectPath.trim() : "";
+ if (selectedSession?.id !== sessionId || selectedSession.projectPath !== (projectPath || null)) {
+ selectedSession = { id: sessionId, projectPath: projectPath || null };
+ }
setActivePluginSession({ sessionId, projectPath: projectPath || null });
return { ok: true };
},
@@ -204,6 +209,7 @@ export function registerPluginUiIpc({
title: resolvePluginLocalizedString(view.title, getUpdaterLocale(), view.id),
pluginName: loaded.manifest.name,
icon: view.icon,
+ ...(view.acceptsTranscriptSelection === true ? { acceptsTranscriptSelection: true } : {}),
order: Number.isFinite(view.order) ? Number(view.order) : index,
});
});
@@ -295,6 +301,7 @@ export function registerPluginUiIpc({
sessionId?: string;
location?: string;
tabId?: string;
+ selection?: string;
}) => {
const pluginId = String(payload?.pluginId ?? "");
const viewId = String(payload?.viewId ?? "");
@@ -313,6 +320,17 @@ export function registerPluginUiIpc({
(candidate) => candidate?.id === viewId,
);
if (!view) throw new Error("plugin has no such view");
+ const selection = payload?.selection;
+ const session = selectedSession;
+ const isCurrentSession = () => session?.id === sessionId && session === selectedSession &&
+ pluginActiveInProject(pluginId, currentWorkspacePath());
+ if (selection !== undefined && (
+ view.acceptsTranscriptSelection !== true || !isCurrentSession() ||
+ !sessionId || sessionId.startsWith("remote:") || typeof selection !== "string" ||
+ !selection.trim() || Buffer.byteLength(selection) >= 64 * 1024
+ )) {
+ throw new Error("INVALID_ARGUMENT: transcript selection is unavailable for this view");
+ }
const htmlPath = join(loaded.path, view.entry);
if (!existsSync(htmlPath)) throw new Error("view entry missing");
if (isBrowserView && sessionId) {
@@ -330,6 +348,9 @@ export function registerPluginUiIpc({
// location keeps going through `browserHost`; every other contributed
// view receives the opener's subject untouched (D320 follow-up).
...(isBrowserView || !location ? {} : { location }),
+ ...(selection === undefined ? {} : {
+ selection: { sessionId, text: selection, isCurrentSession },
+ }),
});
return { ok: true };
},
diff --git a/apps/desktop/electron/main/plugin-view-host.ts b/apps/desktop/electron/main/plugin-view-host.ts
index 72baf263c..ba3932cab 100644
--- a/apps/desktop/electron/main/plugin-view-host.ts
+++ b/apps/desktop/electron/main/plugin-view-host.ts
@@ -6,6 +6,7 @@ import {
type WebContents,
} from "electron";
import { join } from "node:path";
+import type { PluginViewSelection } from "@pi-desktop/plugin-sdk";
import { getModuleDirectory } from "./module-path";
import { parseAllowedExternalUrl } from "./safe-open-external";
import { PanelSenders, pageGoneWithin } from "./plugin-panel-senders";
@@ -82,6 +83,7 @@ export type PluginViewOpenRequest = {
* instead and never receives this.
*/
location?: string;
+ selection?: PluginViewSelection & { isCurrentSession: () => boolean };
};
export type { PluginViewBounds };
@@ -102,6 +104,7 @@ type LiveView = {
location: string | null;
/** False until the first document finished loading. */
loaded: boolean;
+ selection?: PluginViewOpenRequest["selection"];
};
export function pluginViewKey(pluginId: string, viewId: string): string {
@@ -247,6 +250,10 @@ export class PluginViewHost {
if (existing) {
existing.usedAt = ++this.clock;
this.deliverLocation(existing, location);
+ if (request.selection) {
+ existing.selection = request.selection;
+ this.deliverSelection(existing);
+ }
return;
}
const view = this.createView(request);
@@ -258,6 +265,7 @@ export class PluginViewHost {
usedAt: ++this.clock,
location,
loaded: false,
+ selection: request.selection,
};
this.views.set(key, entry);
// A docked view can call the bridge from its first script, so its identity is
@@ -268,6 +276,7 @@ export class PluginViewHost {
view.webContents.once("destroyed", () => this.senders.release(senderId));
view.webContents.once("did-finish-load", () => {
entry.loaded = true;
+ this.deliverSelection(entry);
});
this.load(entry);
this.evictBeyondLimit();
@@ -298,6 +307,16 @@ export class PluginViewHost {
});
}
+ private deliverSelection(entry: LiveView): void {
+ if (!entry.loaded || !entry.selection) return;
+ const { sessionId, text, isCurrentSession } = entry.selection;
+ entry.selection = undefined;
+ const contents = entry.view.webContents;
+ if (!contents.isDestroyed() && isCurrentSession()) {
+ contents.send("pi-plugin-panel-event:view:selection", { sessionId, text });
+ }
+ }
+
private load(entry: LiveView): void {
void entry.view.webContents
.loadURL(viewEntryUrl(entry.htmlPath, entry.location))
diff --git a/apps/desktop/src/components/ContextMenu.tsx b/apps/desktop/src/components/ContextMenu.tsx
index d1c77d790..5d8db1c03 100644
--- a/apps/desktop/src/components/ContextMenu.tsx
+++ b/apps/desktop/src/components/ContextMenu.tsx
@@ -177,8 +177,12 @@ export function useContextMenu() {
Both are applied here so no call site can forget one.
*/
const openContextMenu = useCallback(
- (event: ReactMouseEvent<HTMLElement>, request: ContextMenuRequest) => {
- if (!request.items.length) return;
+ (
+ event: ReactMouseEvent<HTMLElement>,
+ request: ContextMenuRequest,
+ selectionItems?: (selection: string) => ContextMenuItem[],
+ ) => {
+ if (!request.items.length && !selectionItems) return;
event.preventDefault();
event.stopPropagation();
/*
@@ -190,7 +194,10 @@ export function useContextMenu() {
const selection = snapshotSelection(event.currentTarget);
const rect = request.anchor ? event.currentTarget.getBoundingClientRect() : undefined;
const anchorRect = rect ? { left: rect.left, right: rect.right, top: rect.top, bottom: rect.bottom } : undefined;
- setState({ ...request, point: pointForEvent(event), anchorRect, selection });
+ const items = selectionItems
+ ? [...request.items, ...selectionItems(selection)]
+ : request.items;
+ if (items.length) setState({ ...request, items, point: pointForEvent(event), anchorRect, selection });
},
[],
);
diff --git a/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx b/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx
index 90dbaad69..0227013d1 100644
--- a/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx
+++ b/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx
@@ -91,7 +91,7 @@ export const ChatTranscript = memo(function ChatTranscript(
props: ChatTranscriptProps,
) {
return (
- <TranscriptMenuProvider>
+ <TranscriptMenuProvider sessionId={props.paneVisible === false ? undefined : props.sessionId}>
<TranscriptBody {...props} />
</TranscriptMenuProvider>
);
diff --git a/apps/desktop/src/features/chat/transcript/TranscriptMenu.tsx b/apps/desktop/src/features/chat/transcript/TranscriptMenu.tsx
index 8edf5fea9..52158946b 100644
--- a/apps/desktop/src/features/chat/transcript/TranscriptMenu.tsx
+++ b/apps/desktop/src/features/chat/transcript/TranscriptMenu.tsx
@@ -26,6 +26,10 @@ import {
useContextMenu,
type ContextMenuRequest,
} from "../../../components/ContextMenu";
+import { IconPlug } from "../../../components/icons";
+import { api } from "../../../lib/api";
+import { pluginViewIcon } from "../../../lib/plugin-view-icons";
+import { pluginWorkPanelTab } from "../../../lib/work-panel-tabs";
import { useAppStore } from "../../../stores/app-store";
import { copySelectionOrFallback } from "../../../lib/chat-transcript-text";
@@ -44,10 +48,57 @@ export function useTranscriptMenu(): OpenTranscriptMenu {
return useContext(TranscriptMenuContext);
}
-export function TranscriptMenuProvider({ children }: { children: ReactNode }) {
+export function TranscriptMenuProvider({ children, sessionId }: {
+ children: ReactNode;
+ sessionId?: string;
+}) {
const { contextMenu, openContextMenu, closeContextMenu } = useContextMenu();
+ const openTranscriptMenu: OpenTranscriptMenu = useCallback((event, request) => {
+ const state = useAppStore.getState();
+ const views = state.pluginViews.filter((view) => view.acceptsTranscriptSelection);
+ if (views.length === 0) {
+ openContextMenu(event, request);
+ return;
+ }
+ const target = event.target instanceof Element ? event.target.closest(".message-bubble") : null;
+ const selection = target && window.getSelection();
+ if (!sessionId || sessionId !== state.activeSessionId || state.selectingSessionId || sessionId.startsWith("remote:") ||
+ !target || !event.currentTarget.contains(target) || !selection || selection.isCollapsed ||
+ !target.contains(selection.anchorNode) || !target.contains(selection.focusNode)) {
+ openContextMenu(event, request);
+ return;
+ }
+ openContextMenu(event, request, (text) => {
+ if (!text.trim() || new TextEncoder().encode(text).length >= 64 * 1024) return [];
+ return views.map((view, index) => {
+ const Icon = pluginViewIcon(view.icon) ?? IconPlug;
+ return {
+ id: `plugin-selection:${view.ref}`,
+ label: view.title,
+ icon: <Icon size={14} />,
+ separatorBefore: index === 0,
+ onSelect: () => {
+ const selected = useAppStore.getState();
+ if (selected.activeSessionId !== sessionId || selected.selectingSessionId) return;
+ void api.pluginViewOpen(view.pluginId, view.viewId, { sessionId, selection: text }).then(
+ () => {
+ const current = useAppStore.getState();
+ if (current.activeSessionId === sessionId && !current.selectingSessionId) {
+ current.openWorkPanelTabForSession(sessionId, pluginWorkPanelTab(view.pluginId, view.viewId));
+ }
+ },
+ (error: unknown) => {
+ useAppStore.getState().showToast(error instanceof Error ? error.message : String(error), { variant: "error" });
+ },
+ );
+ },
+ };
+ });
+ });
+ }, [openContextMenu, sessionId]);
+
return (
- <TranscriptMenuContext.Provider value={openContextMenu}>
+ <TranscriptMenuContext.Provider value={openTranscriptMenu}>
{children}
<ContextMenu state={contextMenu} onClose={closeContextMenu} />
</TranscriptMenuContext.Provider>
diff --git a/apps/desktop/src/lib/api.ts b/apps/desktop/src/lib/api.ts
index 3b9bfd903..41bdd2856 100644
--- a/apps/desktop/src/lib/api.ts
+++ b/apps/desktop/src/lib/api.ts
@@ -1580,7 +1580,7 @@ export const api = {
pluginViewOpen: (
pluginId: string,
viewId: string,
- extra?: { sessionId?: string; location?: string; tabId?: string },
+ extra?: { sessionId?: string; location?: string; tabId?: string; selection?: string },
) => invoke(IPC.invoke.pluginViewOpen, { pluginId, viewId, ...extra }),
pluginViewClose: (pluginId: string, viewId: string, extra?: { sessionId: string; tabId?: string }) =>
invoke(IPC.invoke.pluginViewClose, { pluginId, viewId, ...extra }),
diff --git a/apps/desktop/src/lib/plugin-view-icons.ts b/apps/desktop/src/lib/plugin-view-icons.ts
index b865c4c74..2461a1d14 100644
--- a/apps/desktop/src/lib/plugin-view-icons.ts
+++ b/apps/desktop/src/lib/plugin-view-icons.ts
@@ -73,8 +73,8 @@ const PLUGIN_VIEW_ICON_MAP: Record<string, ComponentType<IconProps>> = {
export function pluginViewIcon(
token: string | undefined,
): ComponentType<IconProps> | null {
- if (!token) return null;
- return PLUGIN_VIEW_ICON_MAP[token] ?? null;
+ if (!token || !Object.hasOwn(PLUGIN_VIEW_ICON_MAP, token)) return null;
+ return PLUGIN_VIEW_ICON_MAP[token];
}
/** First character of a view title, for the fallback tile. */
diff --git a/apps/desktop/test/plugin-provider-catalog-ipc.test.mjs b/apps/desktop/test/plugin-provider-catalog-ipc.test.mjs
index b5bff9e61..f47239a7e 100644
--- a/apps/desktop/test/plugin-provider-catalog-ipc.test.mjs
+++ b/apps/desktop/test/plugin-provider-catalog-ipc.test.mjs
@@ -139,3 +139,59 @@ test("the plugin session IPC resets ordering on renderer reload and rejects stal
{ sessionId: "after-newer-push", projectPath: "/work/b" },
]);
});
+
+test("selected transcript text goes only to an opted-in view in the current project and session", async () => {
+ const handlers = new Map();
+ const opened = [];
+ let activeInProject = true;
+ const plugin = {
+ path: "/plugin",
+ permissions: new Set(["ui.view"]),
+ manifest: {
+ id: "test.selection",
+ name: "Selection",
+ contributes: { views: [
+ { id: "excerpt", title: "Excerpt", icon: "branch", entry: "one.html", acceptsTranscriptSelection: true },
+ { id: "other", title: "Other", entry: "other.html" },
+ ] },
+ },
+ };
+ loadPluginUiIpc()({
+ registrar: { handle: (channel, handler) => handlers.set(channel, handler) },
+ plugins: { listLoaded: () => [plugin], getLoaded: (id) => id === plugin.manifest.id ? plugin : undefined },
+ pluginViews: { open: (request) => opened.push(request) },
+ pluginPanels: {},
+ pluginActiveInProject: () => activeInProject,
+ currentWorkspacePath: () => "/work/a",
+ getUpdaterLocale: () => "en",
+ getPluginPanelTheme: () => ({}),
+ setActivePluginSession: () => {},
+ });
+
+ const list = handlers.get(IPC.invoke.pluginViews);
+ const [excerpt, other] = await list();
+ assert.equal(excerpt.acceptsTranscriptSelection, true);
+ assert.equal(excerpt.icon, "branch");
+ assert.equal(other.acceptsTranscriptSelection, undefined);
+ const open = handlers.get(IPC.invoke.pluginViewOpen);
+ const choose = handlers.get(IPC.invoke.pluginSessionActive);
+ const request = { pluginId: "test.selection", viewId: "excerpt", sessionId: "parent", selection: "line one\n字" };
+ await assert.rejects(open(request), /selection is unavailable/);
+ await choose({ sessionId: "parent" });
+ await assert.rejects(open({ ...request, viewId: "other" }), /selection is unavailable/);
+ await assert.rejects(open({ ...request, selection: "字".repeat(22_000) }), /selection is unavailable/);
+ activeInProject = false;
+ await assert.rejects(open(request), /not active/);
+ activeInProject = true;
+ await open(request);
+ assert.equal(opened.length, 1);
+ const [item] = opened;
+ assert.equal(item.location, undefined);
+ assert.equal(item.selection.sessionId, "parent");
+ assert.equal(item.selection.text, request.selection);
+ assert.equal(item.selection.isCurrentSession(), true);
+ await choose({ sessionId: "other" });
+ assert.equal(item.selection.isCurrentSession(), false);
+ await choose({ sessionId: "parent" });
+ assert.equal(item.selection.isCurrentSession(), false);
+});
diff --git a/apps/desktop/test/plugin-work-panel-views.test.mjs b/apps/desktop/test/plugin-work-panel-views.test.mjs
index 06c9575d5..e7feb682c 100644
--- a/apps/desktop/test/plugin-work-panel-views.test.mjs
+++ b/apps/desktop/test/plugin-work-panel-views.test.mjs
@@ -126,7 +126,7 @@ test("an unknown icon token degrades instead of rendering plugin markup", () =>
// The manifest carries a token, never SVG: the icon is drawn inside host
// chrome, so plugin markup there would be an injection surface.
assert.doesNotMatch(iconSource, /dangerouslySetInnerHTML|innerHTML/);
- assert.match(iconSource, /return PLUGIN_VIEW_ICON_MAP\[token\] \?\? null/);
+ assert.match(iconSource, /!Object\.hasOwn\(PLUGIN_VIEW_ICON_MAP, token\)\) return null/);
assert.match(panelSource, /work-panel-view-initial/);
});
diff --git a/crates/host-core/src/plugins/validation.rs b/crates/host-core/src/plugins/validation.rs
index df80519c9..8009eb601 100644
--- a/crates/host-core/src/plugins/validation.rs
+++ b/crates/host-core/src/plugins/validation.rs
@@ -497,6 +497,9 @@ pub(crate) fn validate_contributions(root: &Path, manifest: &PluginManifest) ->
if !has_title {
bail!("PLUGIN_INVALID: view {id} requires a title");
}
+ if obj.get("acceptsTranscriptSelection").is_some_and(|value| !value.is_boolean()) {
+ bail!("PLUGIN_INVALID: view {id} acceptsTranscriptSelection must be a boolean");
+ }
let entry_path = obj
.get("entry")
.and_then(Value::as_str)
diff --git a/docs/adr/plugin-transcript-selection-views.md b/docs/adr/plugin-transcript-selection-views.md
new file mode 100644
index 000000000..fe381d461
--- /dev/null
+++ b/docs/adr/plugin-transcript-selection-views.md
@@ -0,0 +1,25 @@
+# ADR: Docked views can accept transcript selections
+
+- Status: Accepted
+- Date: 2026-11-19
+- Related: ADR 0104, ADR 0268, GitHub #2395
+
+## Decision
+
+A contributed docked view can opt into the transcript selection menu with
+`acceptsTranscriptSelection`. The host draws the view's localized title and
+existing icon token. A user click opens that view and delivers the excerpt
+and active session ID in a one-way `view:selection` event. The host keeps
+pending excerpts in memory until the target view finishes loading.
+
+This extends the work-panel view contract. It leaves the retired native quote
+and side-chat actions out of the host. An opt-in requires the existing
+`ui.view` grant and project activation. It does not give a plugin a selection
+reader, inject executable UI, expose the full message, or grant session or
+Composer write access.
+
+## Alternatives
+
+Putting the excerpt in the view's existing location would expose text in its
+URL and replay it on reload. A renderer extension would require a broader
+permission for a host-rendered menu item.
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 9fa993d10..f0d8c5d1f 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -2085,7 +2085,11 @@ Single message render — either user (plaintext) or assistant (markdown streami
streaming or empty assistant turn that would produce no items opens
nothing. Copy on a speaking-turn menu writes the live selection in that
turn captured when the menu opened; a collapsed caret, or a selection
- outside the row, falls back to the whole turn.
+ outside the row, falls back to the whole turn. In the active local session,
+ a non-empty selection inside a message bubble can also show items from
+ opted-in plugin views. Items use the view's localized title and host-drawn
+ icon. Choosing an item opens its work-panel view and gives it only the
+ selected text and session ID.
Copy conversation reads the complete session on demand, including unloaded
history and untruncated message text, and preserves the visible in-flight
tail. It does not change the reading window or scroll position. A failed
diff --git a/docs/spec/06-delivery/e2e/conversation.md b/docs/spec/06-delivery/e2e/conversation.md
index 9f0d0c203..926e54c0a 100644
--- a/docs/spec/06-delivery/e2e/conversation.md
+++ b/docs/spec/06-delivery/e2e/conversation.md
@@ -4908,3 +4908,17 @@ Build two actual runtimes with identical configuration and different scratch dir
wrapped descriptions; preserve detail navigation, Stop and responsive layout.
- Qualification: isolated Chromium geometry checks cover this layout regression;
installed-client and live-provider checks remain separate.
+
+## E2E-PLUGIN-transcript-selection-view
+
+- With an opted-in plugin installed, select part of a message bubble and
+ right-click. The item shows its localized title and host icon. Repeat with
+ no selection, a selection outside the bubble, and the plugin disabled.
+ Each of those menus omits the item.
+- Choose the item on a cold view and again on an already open view. Verify the
+ same docked tab receives one `view:selection` payload per click with the
+ session ID and excerpt only. Escape delivers nothing. Switching sessions
+ while the view is loading discards the pending excerpt.
+- With a side-question plugin, verify the quote preview can be removed
+ atomically and the first explicitly sent prompt contains only the excerpt
+ and the new question. The main conversation and its input remain intact.
diff --git a/docs/spec/07-plugins/02-plugin-manifest-schema.md b/docs/spec/07-plugins/02-plugin-manifest-schema.md
index 4e93de2d2..13f7c6862 100644
--- a/docs/spec/07-plugins/02-plugin-manifest-schema.md
+++ b/docs/spec/07-plugins/02-plugin-manifest-schema.md
@@ -246,6 +246,7 @@ type PluginViewContrib = {
icon?: string; // token from the host icon set; unknown tokens draw a letter tile
entry: string; // relative path to the view's HTML entry
order?: number; // ascending sort key in the plugin-views menu group, default 0
+ acceptsTranscriptSelection?: boolean; // add a selected-text action to the transcript menu
};
type PluginSessionSourceContrib = {
diff --git a/docs/spec/07-plugins/03-plugin-api.md b/docs/spec/07-plugins/03-plugin-api.md
index f5bcda4fa..440da62f4 100644
--- a/docs/spec/07-plugins/03-plugin-api.md
+++ b/docs/spec/07-plugins/03-plugin-api.md
@@ -1689,6 +1689,12 @@ Delivered today:
receives it) — payload is `{ path: string }`, the location the host asked this
view to show. A view created with a location already carried it in its entry
URL; this event delivers a later one.
+- `view:selection` — payload is `{ sessionId: string; text: string }`. A view
+ with `acceptsTranscriptSelection: true` receives this only when the user
+ selects its item in the transcript menu. Register the listener in the
+ view's initial script. The host waits for the document to load, discards
+ a pending excerpt if the user has switched sessions, and delivers each
+ accepted click to that view only. The text is under 64 KiB in UTF-8.
- `session:turnEnded` — the same payload as the plugin-process event in §5,
sent when a host turn reaches a terminal state.
- `session:activated` — the same payload as the plugin-process event in §5, sent
diff --git a/packages/plugin-sdk/src/index.test.ts b/packages/plugin-sdk/src/index.test.ts
index 15e3aae4b..504042497 100644
--- a/packages/plugin-sdk/src/index.test.ts
+++ b/packages/plugin-sdk/src/index.test.ts
@@ -414,6 +414,15 @@ describe("contributes.views", () => {
);
});
+ it("requires an explicit boolean for transcript selection", () => {
+ expect(validateContributions({
+ views: [{ ...view, acceptsTranscriptSelection: true }],
+ })).toBeUndefined();
+ expect(validateContributions({
+ views: [{ ...view, acceptsTranscriptSelection: "true" as never }],
+ })).toMatch(/acceptsTranscriptSelection must be a boolean/);
+ });
+
it("requires both locales for a localized title", () => {
expect(
validateContributions({ views: [{ ...view, title: { en: "Changes" } as never }] }),
diff --git a/packages/plugin-sdk/src/index.ts b/packages/plugin-sdk/src/index.ts
index 00614c4d1..c8bf9ad64 100644
--- a/packages/plugin-sdk/src/index.ts
+++ b/packages/plugin-sdk/src/index.ts
@@ -888,6 +888,9 @@ export const PLUGIN_VIEW_ICONS = [
export type PluginViewIcon = (typeof PLUGIN_VIEW_ICONS)[number];
+/** User-selected transcript text sent to a single docked view. */
+export type PluginViewSelection = { sessionId: string; text: string };
+
/**
* One surface the plugin docks inside the host's work panel.
*
@@ -896,6 +899,8 @@ export type PluginViewIcon = (typeof PLUGIN_VIEW_ICONS)[number];
* plugin can ship "Changes" and "History" as two independent entries.
*/
export type PluginViewContrib = {
+ /** Also offer this view in the context menu for selected transcript text. */
+ acceptsTranscriptSelection?: boolean;
/** Plugin-local view id; `<pluginId>/<id>` addresses it globally. */
id: string;
/** Menu label. Localized objects are resolved against the host locale. */
@@ -2402,6 +2407,9 @@ export function validateContributions(
if (view.order !== undefined && !Number.isFinite(view.order)) {
return `view "${view.id}" order must be a number`;
}
+ if (view.acceptsTranscriptSelection !== undefined && typeof view.acceptsTranscriptSelection !== "boolean") {
+ return `view "${view.id}" acceptsTranscriptSelection must be a boolean`;
+ }
// `icon` is intentionally unchecked: an unknown token degrades to a letter
// tile, so rejecting one would break a plugin over a cosmetic detail.
}
diff --git a/packages/shared/src/types/plugins.ts b/packages/shared/src/types/plugins.ts
index a7e8da91b..a2c63308c 100644
--- a/packages/shared/src/types/plugins.ts
+++ b/packages/shared/src/types/plugins.ts
@@ -133,6 +133,7 @@ export type PluginViewMeta = {
pluginName: string;
icon?: string;
order: number;
+ acceptsTranscriptSelection?: boolean;
};
/** A user-invoked text action available beside the Composer controls. */