diff --git a/Assistant.md b/Assistant.md new file mode 100644 index 0000000..15ce2bb --- /dev/null +++ b/Assistant.md @@ -0,0 +1,485 @@ +# Assistant Guide + +This file is a concise, assistant-facing guide for working with `@anikitenko/fdo-sdk`. +It is intended for Mintlify or other docs surfaces that need one high-signal overview instead of many separate internal documents. + +## What This SDK Is + +`@anikitenko/fdo-sdk` is an SDK for building FDO desktop application plugins. + +The SDK spans two runtimes: + +- Backend/plugin runtime + - plugin class lifecycle + - handler registration + - storage + - logging + - host IPC +- Iframe UI runtime + - UI returned by `render()` + - browser DOM access + - host-injected helpers and UI libraries + - sandboxed iframe execution managed by FDO + +The most important rule is: plugin backend logic and plugin UI logic do not run in the same environment. + +## Core Mental Model + +Treat `render()` output as UI source for the FDO iframe render pipeline, not as arbitrary raw HTML inserted directly into the host page. + +That means: + +- `render()` must synchronously return a string +- `renderOnLoad()` may synchronously return: + - a string + - a function + - a `defineRenderOnLoad(...)` payload +- FDO serializes and transports these pieces separately +- UI code runs later inside a sandboxed iframe + +If you are generating UI with SDK DOM helpers and expect helper-generated styles to work, you must wrap the final helper output with `renderHTML(...)`. + +## Start Here + +Recommended order for understanding and building plugins: + +1. Read `README.md` +2. Read `docs/RENDER_RUNTIME_CONTRACT.md` +3. Read `docs/SAFE_PLUGIN_AUTHORING.md` +4. Read `docs/EXTENSION_POINTS.md` +5. Study `examples/fixtures/minimal-plugin.fixture.ts` +6. Then move to numbered examples in `examples/` + +## Minimal Plugin Shape + +Every plugin should provide: + +- `metadata` +- `init()` +- `render()` + +Typical shape: + +```ts +import { FDO_SDK, FDOInterface, PluginMetadata } from "@anikitenko/fdo-sdk"; + +export default class MyPlugin extends FDO_SDK implements FDOInterface { + private readonly _metadata: PluginMetadata = { + name: "My Plugin", + version: "1.0.0", + author: "Your Name", + description: "Plugin description", + icon: "cog", + }; + + get metadata(): PluginMetadata { + return this._metadata; + } + + init(): void { + this.info("plugin initialized"); + } + + render(): string { + return `
Hello World
`; + } +} +``` + +## Metadata Rules + +Plugin metadata is part of the host contract. + +Rules: + +- define full metadata: `name`, `version`, `author`, `description`, `icon` +- prefer a stable `metadata.id` if your host/plugin flow supports it +- `metadata.icon` must be a valid BlueprintJS v6 icon name + +## Backend Runtime Rules + +Use backend runtime for: + +- `init()` +- registering handlers +- stores +- logging +- diagnostics +- host-mediated privileged actions + +Do not assume browser-only globals or injected UI libraries exist here. + +Do not use iframe-specific APIs in backend/bootstrap paths. + +## Iframe UI Runtime Rules + +Use iframe runtime for: + +- DOM access +- event binding +- `window.createBackendReq(...)` +- host-injected helpers +- UI libraries injected by FDO + +Common helpers available in iframe runtime: + +- `window.createBackendReq(...)` +- `window.waitForElement(...)` +- `window.executeInjectedScript(...)` +- `window.addGlobalEventListener(...)` +- `window.removeGlobalEventListener(...)` +- `window.applyClassToSelector(...)` + +Common injected libraries: + +- Notyf +- Highlight.js +- ACE +- Split Grid +- FontAwesome +- Pure CSS + +Do not assume these libraries exist in backend runtime or failure/bootstrap paths. + +## Safe Markup Rules + +The iframe render pipeline is JSX-like and stricter than “whatever a browser would parse.” + +Important rules: + +- prefer JSX-safe void tags like `
` +- avoid inline `