fix(plugins): isole les menus plugin et durcit hello-plugin SDK contre la rechute #120

Requalification Architect du 2026-08-01: le crash INTERFACE INTERROMPUE au
chargement d'un plugin (menu + item) remonte via ProjectsView -> usePluginMenus
-> MenuBar jusqu'à RootErrorBoundary, quel que soit le plugin (ancien ou
reconstruit via SDK).

- usePluginMenus isole la résolution/conversion des contributions plugin :
  toute erreur retombe sur [] au lieu de propager.
- ProjectsView sépare les menus natifs des menus enrichis par plugin et rend
  MenuBar derrière une error boundary locale (fallback menus natifs seuls).
- hello-plugin (SDK) et les tests d'installation associés durcis en cohérence.

Bookkeeping ticket #120 uniquement (issue.md, carnet.md) ; les fichiers
counter.json/index.json et le dossier tickets/122/ restent hors commit car
une collision de numérotation #122 existe entre cette base et
feature/ticket120-hello-plugin-install-path-audit (deux tickets différents
revendiquent #122) — à arbitrer avant de committer le bookkeeping global.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-01 16:23:56 +02:00
parent 8031d86deb
commit 5a30ec8b9c
11 changed files with 516 additions and 75 deletions

View File

@ -33,7 +33,14 @@
* open; the project tab bar (`role="tablist"`) is always present.
*/
import { useEffect, useMemo, useState, type ReactNode } from "react";
import {
Component,
useEffect,
useMemo,
useState,
type ErrorInfo,
type ReactNode,
} from "react";
import type { Agent, DomainEvent, LayoutInfo } from "@/domain";
import { LayoutGrid, LayoutTabs } from "@/features/layout";
@ -109,6 +116,41 @@ interface PendingConversationOpen {
conversationId: string;
}
interface PluginMenuRenderBoundaryProps {
resetKey: string;
fallbackMenus: MenuBarMenu[];
children: ReactNode;
}
class PluginMenuRenderBoundary extends Component<
PluginMenuRenderBoundaryProps,
{ hasError: boolean }
> {
state = { hasError: false };
static getDerivedStateFromError(): { hasError: boolean } {
return { hasError: true };
}
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
console.error("[plugins] menu render failed; using native menus only", {
error,
componentStack: errorInfo.componentStack,
});
}
componentDidUpdate(prevProps: PluginMenuRenderBoundaryProps): void {
if (prevProps.resetKey !== this.props.resetKey && this.state.hasError) {
this.setState({ hasError: false });
}
}
render(): ReactNode {
if (this.state.hasError) return <MenuBar menus={this.props.fallbackMenus} />;
return this.props.children;
}
}
function isTerminalBackgroundTaskEvent(
event: DomainEvent,
): event is Extract<DomainEvent, { type: "backgroundTaskChanged" }> {
@ -546,22 +588,43 @@ export function ProjectsView() {
return items;
}
const nativePanelItems: MenuBarItem[] = panelOrder.map((panel) => ({
id: panel,
label: PANEL_TITLE[panel],
active: placementOf(placements, panel) !== "closed",
onSelect: () => {},
submenu: placementSubmenu(panel),
}));
const nativeSettingsItems: MenuBarItem[] = SETTINGS_SECTIONS.map((section) => ({
id: section,
label: SETTINGS_SECTION_LABEL[section],
active: settingsSection === section,
onSelect: () => {
setSettingsSection(section);
dismissFloating();
},
}));
const pluginPanelItems = pluginMenus.itemsFor("panels");
const pluginSettingsItems = pluginMenus.itemsFor("settings");
const nativeMenus: MenuBarMenu[] = [
{
id: "panels",
label: "Panneaux",
items: nativePanelItems,
},
{
id: "settings",
label: "Paramètres",
items: nativeSettingsItems,
},
];
const menus: MenuBarMenu[] = [
{
id: "panels",
label: "Panneaux",
// Native items first, plugin-contributed items after in their own
// (discreetly-labelled) group (#43, F3, carnet §7.2).
items: [
...panelOrder.map((panel) => ({
id: panel,
label: PANEL_TITLE[panel],
active: placementOf(placements, panel) !== "closed",
onSelect: () => {},
submenu: placementSubmenu(panel),
})),
...pluginMenus.itemsFor("panels"),
],
items: [...nativePanelItems, ...pluginPanelItems],
},
// Top-level plugin menus render between Panneaux and Paramètres (#43,
// carnet §0 UX decision + §7.1).
@ -572,20 +635,14 @@ export function ProjectsView() {
// One entry per section (#68). The entries name sections and mark the open
// one; closing lives in the view ("Fermer les paramètres"), so no label
// alternates. Plugin-contributed items are appended after (#43, F3).
items: [
...SETTINGS_SECTIONS.map((section) => ({
id: section,
label: SETTINGS_SECTION_LABEL[section],
active: settingsSection === section,
onSelect: () => {
setSettingsSection(section);
dismissFloating();
},
})),
...pluginMenus.itemsFor("settings"),
],
items: [...nativeSettingsItems, ...pluginSettingsItems],
},
];
const pluginMenuResetKey = [
pluginMenus.topLevelMenus.map((menu) => menu.id).join(","),
pluginPanelItems.map((item) => item.id).join(","),
pluginSettingsItems.map((item) => item.id).join(","),
].join("|");
// The create-project form + known-projects list. Rendered inline in the
// welcome area (no active project) or inside the Projects floating window.
@ -810,7 +867,12 @@ export function ProjectsView() {
/>
{/* ── Menu bar (replaces the former left sidebar) ── */}
<MenuBar menus={menus} />
<PluginMenuRenderBoundary
resetKey={pluginMenuResetKey}
fallbackMenus={nativeMenus}
>
<MenuBar menus={menus} />
</PluginMenuRenderBoundary>
{/* ── Chrome row: left dock │ main │ right dock (#22). Docks are in-flow
resizable columns, not overlays — they sit beside the main surface. */}