Skip to content

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

4.4 KB
Raw Blame
export const PLUGIN_PANEL_TITLEBAR_HEIGHT = 46;

/**
 * Opt-in marker for plugin pages that use the host-published titlebar CSS
 * variable. Pages with this marker own their normal-flow top spacing; legacy
 * pages keep the host's additive padding fallback.
 */
export const PLUGIN_PANEL_CHROME_META_NAME = "pi-plugin-chrome";
export const PLUGIN_PANEL_CHROME_VERSION = "v2";
/**
 * Opt-in mode for pages that draw through the transparent host drag band.
 * The host keeps the capsule above the page, while the page owns hit testing
 * and supplies its own drag/no-drag regions.
 */
export const PLUGIN_PANEL_CHROME_PAINT_THROUGH_VERSION = "v3";

export type PluginPanelTheme = "light" | "dark";

/**
 * The appearance the host is currently showing, handed to plugin panels.
 *
 * `theme` is the user's raw preference (`light` | `dark` | `system`, or
 * `plugin:<pluginId>:<themeId>` when a plugin theme is active). `base` is the
 * palette that preference resolves to — `"system"` only when the host could
 * not resolve it, which the panel renderer treats as "follow the OS".
 * `pluginTheme` carries the active contributed theme's sanitized CSS so a
 * panel can mirror the app's custom palette exactly.
 */
export type PluginAppearance = {
  /** Raw preference stored in AppSettings.theme. */
  theme: string;
  /** Resolved palette: "light" | "dark", or "system" when unresolved. */
  base: "light" | "dark" | "system";
  /** Active app language tag (e.g. "en", "zh-CN"). */
  locale: string;
  /** The active contributed theme, when the preference selects one. */
  pluginTheme: { id: string; base: "light" | "dark"; css: string } | null;
};

export const PLUGIN_PANEL_LOCALE_ARGUMENT_PREFIX = "--pi-plugin-panel-locale=";

/**
 * Marks a plugin surface as docked inside the host work panel rather than
 * living in its own window.
 *
 * An embedded view has no window to minimize, maximize, or drag, so the preload
 * skips the control capsule and the 46px safe area entirely and reports a
 * titlebar height of 0. Both placements use the same panel bridge, so the
 * same HTML entry works in both placements (ADR 0092 §2 addendum).
 */
export const PLUGIN_PANEL_EMBEDDED_ARGUMENT = "--pi-plugin-panel-embedded=1";
export const PLUGIN_PANEL_COMPOSER_FILE_LINES_ARGUMENT = "--pi-plugin-panel-composer-file-lines=1";

/**
 * Marks a plugin surface as a floating widget: a transparent, frameless window
 * with no 46px titlebar band and no host control capsule. The preload publishes
 * a titlebar height of 0, installs a drag map over the whole window, and routes
 * right-click to the host's widget menu. `window.pluginBridge` is identical to
 * a panel, so one HTML entry can serve both placements.
 */
export const PLUGIN_PANEL_WIDGET_ARGUMENT = "--pi-plugin-panel-widget=1";

/**
 * Event name the launcher uses to hand a plugin the input that summoned it.
 *
 * The payload arrives after the panel page has loaded, so it cannot race the
 * document; `pluginBridge.consumeLauncherPayload()` reads it exactly once, which
 * is what keeps one typed input from being delivered twice or kept available for
 * a later time the user did not type it.
 */
export const PLUGIN_PANEL_LAUNCH_EVENT = "launcher:payload";

/**
 * Smallest surface each placement may ask for. A panel is sized around
 * plugin-drawn content; a widget draws its own silhouette — a floating orb —
 * and may shrink far below that.
 */
export const PLUGIN_PANEL_MIN_SIZE = { width: 360, height: 280 } as const;
export const PLUGIN_PANEL_WIDGET_MIN_SIZE = { width: 120, height: 120 } as const;

export const PLUGIN_PANEL_WINDOW_CONTROL_CHANNEL =
  "pi-plugin-panel-window-control";
export const PLUGIN_PANEL_WINDOW_STATE_CHANNEL =
  "pi-plugin-panel-window-state";

export const PLUGIN_PANEL_WINDOW_CONTROL_ACTIONS = [
  "getState",
  "minimize",
  "toggleMaximize",
  // A floating widget has no capsule, so right-click on the surface asks the
  // host for its widget menu: close, minimize, always on top. A panel answers
  // the same action with a no-op — panels keep the capsule.
  "contextMenu",
  "close",
] as const;

export type PluginPanelWindowControlAction =
  (typeof PLUGIN_PANEL_WINDOW_CONTROL_ACTIONS)[number];

export function isPluginPanelWindowControlAction(
  value: unknown,
): value is PluginPanelWindowControlAction {
  return (
    typeof value === "string" &&
    PLUGIN_PANEL_WINDOW_CONTROL_ACTIONS.includes(
      value as PluginPanelWindowControlAction,
    )
  );
}