@opencode/plugin 2.1.4 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/effect/event.d.ts +8 -2
- package/dist/effect/plugin.d.ts +4 -1
- package/dist/effect/session.d.ts +2 -2
- package/dist/effect/vcs.d.ts +1 -0
- package/dist/gui/browser.d.ts +36 -0
- package/dist/gui/browser.js +3 -0
- package/dist/gui/context.d.ts +271 -0
- package/dist/gui/context.js +0 -0
- package/dist/gui/core.d.ts +560 -0
- package/dist/gui/core.js +86 -0
- package/dist/gui/declarations.d.ts +24 -0
- package/dist/gui/declarations.js +0 -0
- package/dist/gui/file.d.ts +122 -0
- package/dist/gui/file.js +7 -0
- package/dist/gui/host-apis.d.ts +1925 -0
- package/dist/gui/host-apis.js +0 -0
- package/dist/gui/icon-name.d.ts +2 -0
- package/dist/gui/icon-name.js +1 -0
- package/dist/gui/index.d.ts +7 -0
- package/dist/gui/index.js +6 -0
- package/dist/gui/internal.d.ts +44 -0
- package/dist/gui/internal.js +33 -0
- package/dist/gui/main.d.ts +279 -0
- package/dist/gui/main.js +20 -0
- package/dist/gui/modules.d.ts +15 -0
- package/dist/gui/modules.js +30 -0
- package/dist/gui/plugin.d.ts +86 -0
- package/dist/gui/plugin.js +9 -0
- package/dist/gui/reactive.d.ts +93 -0
- package/dist/gui/reactive.js +130 -0
- package/dist/gui/registries.d.ts +783 -0
- package/dist/gui/registries.js +110 -0
- package/dist/gui/review.d.ts +73 -0
- package/dist/gui/review.js +3 -0
- package/dist/gui/scope.d.ts +64 -0
- package/dist/gui/scope.js +85 -0
- package/dist/gui/solid.d.ts +99 -0
- package/dist/gui/solid.js +74 -0
- package/dist/gui/vite.d.ts +24 -0
- package/dist/gui/vite.js +49 -0
- package/dist/host.d.ts +12 -1
- package/dist/host.js +34 -2
- package/dist/promise/adapter.js +13 -1
- package/dist/promise/event.d.ts +6 -2
- package/dist/promise/plugin.d.ts +4 -1
- package/dist/promise/session.d.ts +2 -2
- package/dist/runtime-modules.js +3 -1
- package/package.json +65 -15
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Registry } from "./core.js";
|
|
2
|
+
/**
|
|
3
|
+
* The registry of palette commands, each with an optional keybind and slash command.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* ctx.add(Command, {
|
|
8
|
+
* id: "toggle",
|
|
9
|
+
* bind: "mod+shift+e",
|
|
10
|
+
* get title() {
|
|
11
|
+
* return ctx.t("command.toggle")
|
|
12
|
+
* },
|
|
13
|
+
* run: () => toggle(),
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const Command = Registry.define("command");
|
|
18
|
+
/**
|
|
19
|
+
* The registry of host menu items.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* ctx.add(MenuItem, { menu: "session.panel", id: "open", title: ctx.t("open"), icon: "folder", run: () => open() })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const MenuItem = Registry.define("menu-item");
|
|
27
|
+
/**
|
|
28
|
+
* The registry of panels: tabs in the session's side region.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* ctx.add(Panel, {
|
|
33
|
+
* id: "main",
|
|
34
|
+
* region: "side",
|
|
35
|
+
* list: (input) => (input.open.includes("main") ? [tab] : []),
|
|
36
|
+
* render: (props) => <View session={props.session} />,
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export const Panel = Registry.define("panel");
|
|
41
|
+
/**
|
|
42
|
+
* The registry of settings pages, sections on host pages, and rows in host sections.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* ctx.add(SettingsPage, { id: "updates", page: "general", title: ctx.t("title"), render: () => <Section /> })
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export const SettingsPage = Registry.define("settings-page");
|
|
50
|
+
/**
|
|
51
|
+
* The registry of server sources the app lists.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* ctx.add(Server, () => ({ ready: loaded(), entries: hosts().map(toEntry) }))
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export const Server = Registry.define("server");
|
|
59
|
+
/**
|
|
60
|
+
* The registry of handlers that open local links, such as file paths in messages.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* ctx.add(LinkHandler, { match: (link) => link.href.endsWith(".md"), open: (link) => preview(link) })
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export const LinkHandler = Registry.define("link-handler");
|
|
68
|
+
/**
|
|
69
|
+
* The registry of titlebar pills.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* ctx.add(TitlebarItem, () => (ready() ? { id: "update", label: ctx.t("restart"), run: install } : undefined))
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export const TitlebarItem = Registry.define("titlebar-item");
|
|
77
|
+
/**
|
|
78
|
+
* The registry of pills above the session composer.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* ctx.add(ComposerPill, {
|
|
83
|
+
* id: "pulls",
|
|
84
|
+
* show: (input) => {
|
|
85
|
+
* const pulls = openPulls(input.session.directory)
|
|
86
|
+
* return pulls.length > 0 ? { icon: "github", label: ctx.plural("pulls", pulls.length) } : undefined
|
|
87
|
+
* },
|
|
88
|
+
* })
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export const ComposerPill = Registry.define("composer-pill");
|
|
92
|
+
/**
|
|
93
|
+
* The registry of content for the host's slots (`SlotMap`).
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* ctx.add(Slot, { at: "session.header", render: (input) => <Usage session={input.session} /> })
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export const Slot = Registry.define("slot");
|
|
101
|
+
/**
|
|
102
|
+
* The registry of CSS the host adds to the document while each item is contributed. Import the file with `?inline`.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* import css from "./dialog.css?inline"
|
|
107
|
+
* ctx.add(Style, css)
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export const Style = Registry.define("style");
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { FileDiffInfo } from "@opencode/client/promise";
|
|
2
|
+
import { Contract } from "./core.js";
|
|
3
|
+
import type { SessionRef, SessionScreen } from "./host-apis.js";
|
|
4
|
+
/**
|
|
5
|
+
* How a file or directory changed.
|
|
6
|
+
* - `add`: added.
|
|
7
|
+
* - `del`: deleted.
|
|
8
|
+
* - `mix`: modified, or a directory whose files changed in more than one way.
|
|
9
|
+
*/
|
|
10
|
+
export type ChangeKind = "add" | "del" | "mix";
|
|
11
|
+
/** The routed session's changes as the review panel shows them. Empty for other sessions. */
|
|
12
|
+
export interface Changes {
|
|
13
|
+
/**
|
|
14
|
+
* The current review mode's diffs, empty until they load. Reactive.
|
|
15
|
+
*
|
|
16
|
+
* @param session - The session to read.
|
|
17
|
+
* @returns The diffs.
|
|
18
|
+
*/
|
|
19
|
+
diffs(session: SessionRef): readonly FileDiffInfo[];
|
|
20
|
+
/**
|
|
21
|
+
* False while the current mode's diffs load.
|
|
22
|
+
*
|
|
23
|
+
* @param session - The session to read.
|
|
24
|
+
* @returns Whether the diffs loaded.
|
|
25
|
+
*/
|
|
26
|
+
ready(session: SessionRef): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The change kind of each changed file and each of its directories, keyed by normalized path.
|
|
29
|
+
*
|
|
30
|
+
* @param session - The session to read.
|
|
31
|
+
* @returns The kinds by path.
|
|
32
|
+
*/
|
|
33
|
+
kinds(session: SessionRef): ReadonlyMap<string, ChangeKind>;
|
|
34
|
+
/**
|
|
35
|
+
* The file the review panel shows.
|
|
36
|
+
*
|
|
37
|
+
* @param session - The session to read.
|
|
38
|
+
* @returns Its path, or undefined when the panel shows none.
|
|
39
|
+
*/
|
|
40
|
+
active(session: SessionRef): string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* The session directory's uncommitted changes, independent of the review mode (the session details' changes row).
|
|
43
|
+
* Loads only while a `details` watch holds; undefined until loaded, empty when the load fails.
|
|
44
|
+
*
|
|
45
|
+
* @param session - The session to read.
|
|
46
|
+
* @returns The uncommitted changes.
|
|
47
|
+
*/
|
|
48
|
+
details(session: SessionRef): readonly FileDiffInfo[] | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Opens the side region and shows `path` in the review panel.
|
|
51
|
+
*
|
|
52
|
+
* @param session - The session whose panel shows it.
|
|
53
|
+
* @param path - The changed file's path.
|
|
54
|
+
*/
|
|
55
|
+
focus(session: SessionRef, path: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Shows the changes: opens the side region, or on narrow screens switches to the Changes view.
|
|
58
|
+
*
|
|
59
|
+
* @param session - The session whose changes show.
|
|
60
|
+
*/
|
|
61
|
+
open(session: SessionRef): void;
|
|
62
|
+
/**
|
|
63
|
+
* Keeps the changes of the view the caller renders loaded while it shows them, across the view's session
|
|
64
|
+
* switches. A `tree` is a persistent change list: opening the side region refreshes the changes it shows.
|
|
65
|
+
* `details` loads `details(session)`.
|
|
66
|
+
*
|
|
67
|
+
* @param screen - The owning screen from the panel or session-slot input, available even before publication.
|
|
68
|
+
* @param source - The view's demand: a tree, file markers or session details.
|
|
69
|
+
*/
|
|
70
|
+
watch(screen: SessionScreen, source: "tree" | "files" | "details"): () => void;
|
|
71
|
+
}
|
|
72
|
+
/** The review plugin provides this. The session details' changes row reads the same data. */
|
|
73
|
+
export declare const Changes: Contract<Changes, "review.changes">;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Cleanup } from "./core.js";
|
|
2
|
+
/**
|
|
3
|
+
* A lifetime, named after Effect's `Scope` without its runtime. Closing it aborts `signal`, then runs its finalizers
|
|
4
|
+
* in reverse order, each isolated from the others' failures, under a deadline. The main host makes one per plugin
|
|
5
|
+
* instance, closed when the plugin is disabled, reloaded, removed, or the app quits; a plugin reaches it through
|
|
6
|
+
* `ctx.signal` and `ctx.onCleanup`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const timer = setInterval(poll, 60_000)
|
|
11
|
+
* scope.addFinalizer(() => clearInterval(timer))
|
|
12
|
+
* const session = scope.fork("session")
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface Scope {
|
|
16
|
+
/** Aborts when the scope closes. Pass it to long work, and return after an `await` if it aborted. */
|
|
17
|
+
readonly signal: AbortSignal;
|
|
18
|
+
/**
|
|
19
|
+
* Runs `fn` when the scope closes, or at once when it already has. A throw or rejection is logged and the other
|
|
20
|
+
* finalizers still run.
|
|
21
|
+
*
|
|
22
|
+
* @param fn - The teardown. A named function's name labels it in the timeout log.
|
|
23
|
+
* @returns Runs `fn` early instead, and removes it from the scope.
|
|
24
|
+
*/
|
|
25
|
+
addFinalizer(fn: Cleanup): Cleanup;
|
|
26
|
+
/**
|
|
27
|
+
* A child scope. It closes with this one, in reverse order like a finalizer, or earlier on its own.
|
|
28
|
+
*
|
|
29
|
+
* @param name - Labels the child in logs, as `parent/name`.
|
|
30
|
+
*/
|
|
31
|
+
fork(name: string): Scope;
|
|
32
|
+
/**
|
|
33
|
+
* Aborts `signal` at once; the finalizers start once the calling code yields. Settles when they have, or at the
|
|
34
|
+
* deadline: a finalizer still running then is logged and no longer waited for, and the rest start. Closing again
|
|
35
|
+
* also waits for the finalizers added since.
|
|
36
|
+
*/
|
|
37
|
+
close(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/** Writes a structured log entry; the logger serializes each field of `data` as it is. */
|
|
40
|
+
type Log = <Data extends Readonly<Record<string, unknown>>>(message: string, data: Data) => void;
|
|
41
|
+
type Options = {
|
|
42
|
+
/** How long `close` waits for the finalizers, in milliseconds. */
|
|
43
|
+
readonly timeout: number;
|
|
44
|
+
/** Reports finalizers that failed or timed out. */
|
|
45
|
+
readonly log: Log;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Creates scopes. The main host makes one per plugin instance.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const scope = Scope.make("example", { timeout: 3_000, log: (message, data) => console.error(message, data) })
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const Scope: {
|
|
56
|
+
/**
|
|
57
|
+
* Creates an open scope.
|
|
58
|
+
*
|
|
59
|
+
* @param name - Labels the scope in logs.
|
|
60
|
+
* @param options - The deadline and the log.
|
|
61
|
+
*/
|
|
62
|
+
make: (name: string, options: Options) => Scope;
|
|
63
|
+
};
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates scopes. The main host makes one per plugin instance.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const scope = Scope.make("example", { timeout: 3_000, log: (message, data) => console.error(message, data) })
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export const Scope = {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an open scope.
|
|
12
|
+
*
|
|
13
|
+
* @param name - Labels the scope in logs.
|
|
14
|
+
* @param options - The deadline and the log.
|
|
15
|
+
*/
|
|
16
|
+
make: (name, options) => create(name, options),
|
|
17
|
+
};
|
|
18
|
+
function create(name, options, detach) {
|
|
19
|
+
const controller = new AbortController();
|
|
20
|
+
const finalizers = new Set();
|
|
21
|
+
// Finalizers that started and have not settled or been given up on.
|
|
22
|
+
const running = new Map();
|
|
23
|
+
// The finalizers registered before closing run on this chain, in reverse.
|
|
24
|
+
const closing = { closed: false, chain: Promise.resolve() };
|
|
25
|
+
const start = (finalizer) => {
|
|
26
|
+
const run = Promise.resolve()
|
|
27
|
+
.then(finalizer.run)
|
|
28
|
+
.then(() => undefined, (cause) => options.log("scope finalizer failed", { scope: name, error: cause }))
|
|
29
|
+
.finally(() => running.delete(run));
|
|
30
|
+
running.set(run, finalizer.label);
|
|
31
|
+
return run;
|
|
32
|
+
};
|
|
33
|
+
const settle = (deadline) => Promise.race([Promise.all([closing.chain, ...running.keys()]), deadline.passed])
|
|
34
|
+
.then(() => undefined)
|
|
35
|
+
.finally(deadline.cancel);
|
|
36
|
+
const deadline = () => {
|
|
37
|
+
const passed = Promise.withResolvers();
|
|
38
|
+
const timer = setTimeout(() => {
|
|
39
|
+
running.forEach((label, run) => {
|
|
40
|
+
running.delete(run);
|
|
41
|
+
if (label !== undefined)
|
|
42
|
+
options.log("scope finalizer timed out", { scope: name, finalizer: label });
|
|
43
|
+
});
|
|
44
|
+
passed.resolve();
|
|
45
|
+
}, options.timeout);
|
|
46
|
+
return { passed: passed.promise, cancel: () => clearTimeout(timer) };
|
|
47
|
+
};
|
|
48
|
+
const scope = {
|
|
49
|
+
signal: controller.signal,
|
|
50
|
+
addFinalizer(fn) {
|
|
51
|
+
const finalizer = { label: fn.name || "anonymous", run: fn };
|
|
52
|
+
if (closing.closed) {
|
|
53
|
+
void start(finalizer);
|
|
54
|
+
return () => { };
|
|
55
|
+
}
|
|
56
|
+
finalizers.add(finalizer);
|
|
57
|
+
return () => {
|
|
58
|
+
if (finalizers.delete(finalizer))
|
|
59
|
+
return fn();
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
fork(child) {
|
|
63
|
+
const finalizer = { run: () => forked.close() };
|
|
64
|
+
const forked = create(`${name}/${child}`, options, () => finalizers.delete(finalizer));
|
|
65
|
+
if (closing.closed)
|
|
66
|
+
void forked.close();
|
|
67
|
+
else
|
|
68
|
+
finalizers.add(finalizer);
|
|
69
|
+
return forked;
|
|
70
|
+
},
|
|
71
|
+
close() {
|
|
72
|
+
if (closing.closed)
|
|
73
|
+
return settle(deadline());
|
|
74
|
+
detach?.();
|
|
75
|
+
controller.abort();
|
|
76
|
+
const first = deadline();
|
|
77
|
+
const ordered = [...finalizers].reverse();
|
|
78
|
+
finalizers.clear();
|
|
79
|
+
closing.closed = true;
|
|
80
|
+
closing.chain = ordered.reduce((chain, finalizer) => chain.then(() => Promise.race([start(finalizer), first.passed]).then(() => undefined)), Promise.resolve());
|
|
81
|
+
return settle(first);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
return scope;
|
|
85
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type Accessor, type Component } from "solid-js";
|
|
2
|
+
import type { Context, SetupContext } from "./context.js";
|
|
3
|
+
import type { Declarations } from "./declarations.js";
|
|
4
|
+
/**
|
|
5
|
+
* The plugin's context inside a contribution: the same object setup receives. Pass the definition for the typed
|
|
6
|
+
* declarations. Throws outside a plugin contribution. A component returned by a contract must be bound with
|
|
7
|
+
* `bindPlugin` in the provider's setup; otherwise it reads the consuming plugin's context.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* function View() {
|
|
12
|
+
* const ctx = usePlugin<typeof definition>()
|
|
13
|
+
* return <span>{ctx.stores.prefs.value.shown ? ctx.t("shown") : ctx.t("hidden")}</span>
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function usePlugin<D extends Declarations = never>(): [D] extends [never] ? Context : SetupContext<D>;
|
|
18
|
+
/**
|
|
19
|
+
* Binds one contract component to the providing plugin's context. Call during setup, then provide the returned
|
|
20
|
+
* component: `usePlugin` inside it reads the provider, not the plugin that renders it. Props retain their
|
|
21
|
+
* reactive getters. Data methods need no wrapper. Throws outside a plugin's owner.
|
|
22
|
+
*
|
|
23
|
+
* @param component - One component the contract exposes.
|
|
24
|
+
* @returns The component under the providing plugin's context.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* ctx.provide(FileTree, { Tree: bindPlugin((props) => <Tree {...props} />) })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function bindPlugin<P extends object>(component: Component<P>): Component<P>;
|
|
32
|
+
/** The inner sidebar preference every side panel shares, as `PanelFrame.sidebar`. */
|
|
33
|
+
export interface PanelSidebar {
|
|
34
|
+
/** The inner sidebar is open. Reactive. */
|
|
35
|
+
opened(): boolean;
|
|
36
|
+
/** Its width in CSS pixels. Reactive. */
|
|
37
|
+
width(): number;
|
|
38
|
+
/** False until the stored width loads, so the first layout does not animate. */
|
|
39
|
+
transition(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Stores a new width.
|
|
42
|
+
*
|
|
43
|
+
* @param width - The width in CSS pixels.
|
|
44
|
+
*/
|
|
45
|
+
resize(width: number): void;
|
|
46
|
+
/** Opens or closes the inner sidebar. */
|
|
47
|
+
toggle(): void;
|
|
48
|
+
}
|
|
49
|
+
/** Where a panel render is shown. Read it with `usePanel`. */
|
|
50
|
+
export interface PanelFrame {
|
|
51
|
+
/** Region open and this tab selected. */
|
|
52
|
+
readonly visible: Accessor<boolean>;
|
|
53
|
+
/** Kept on screen while the region animates closed. */
|
|
54
|
+
readonly present: Accessor<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Where the render is placed.
|
|
57
|
+
* - `side`: the side region.
|
|
58
|
+
* - `mobile`: a narrow-screen view (`Panel.mobile`).
|
|
59
|
+
*/
|
|
60
|
+
readonly placement: Accessor<"side" | "mobile">;
|
|
61
|
+
/** Leave room at the end of a header for the host's region toggle. */
|
|
62
|
+
readonly reserve: Accessor<boolean>;
|
|
63
|
+
/** Plays size animations; false while the user drags a region edge. */
|
|
64
|
+
readonly animate: Accessor<boolean>;
|
|
65
|
+
/** One inner sidebar preference shared by every side panel; a panel with a sidebar renders its own toggle. */
|
|
66
|
+
readonly sidebar: PanelSidebar;
|
|
67
|
+
/** This plugin's tab ids stored in the session's side strip (the ids `list` receives as `open`). */
|
|
68
|
+
readonly open: Accessor<readonly string[]>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Where the current panel render is shown. Throws outside a `Panel.render`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const panel = usePanel()
|
|
76
|
+
* const compact = () => panel.placement() === "mobile"
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function usePanel(): PanelFrame;
|
|
80
|
+
/**
|
|
81
|
+
* The drawer showing this panel, or undefined outside one. Close it before an action that opens another view.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const drawer = useDrawer()
|
|
86
|
+
* const open = (path: string) => {
|
|
87
|
+
* drawer?.close()
|
|
88
|
+
* ctx.layout.open(`file:${path}`, session)
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function useDrawer(): {
|
|
93
|
+
readonly close: () => void;
|
|
94
|
+
readonly open: (view: {
|
|
95
|
+
readonly title: string;
|
|
96
|
+
readonly content: import("solid-js").JSX.Element;
|
|
97
|
+
readonly trigger: HTMLElement;
|
|
98
|
+
}) => void;
|
|
99
|
+
} | undefined;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createComponent, useContext } from "solid-js";
|
|
2
|
+
import { DrawerContext, PanelContext, PluginContext } from "./internal.js";
|
|
3
|
+
/**
|
|
4
|
+
* The plugin's context inside a contribution: the same object setup receives. Pass the definition for the typed
|
|
5
|
+
* declarations. Throws outside a plugin contribution. A component returned by a contract must be bound with
|
|
6
|
+
* `bindPlugin` in the provider's setup; otherwise it reads the consuming plugin's context.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* function View() {
|
|
11
|
+
* const ctx = usePlugin<typeof definition>()
|
|
12
|
+
* return <span>{ctx.stores.prefs.value.shown ? ctx.t("shown") : ctx.t("hidden")}</span>
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function usePlugin() {
|
|
17
|
+
const context = useContext(PluginContext);
|
|
18
|
+
if (!context)
|
|
19
|
+
throw new Error("usePlugin must run inside a plugin contribution");
|
|
20
|
+
// SAFETY: the host's context for a plugin also implements `SetupContext` of that plugin's definition.
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Binds one contract component to the providing plugin's context. Call during setup, then provide the returned
|
|
25
|
+
* component: `usePlugin` inside it reads the provider, not the plugin that renders it. Props retain their
|
|
26
|
+
* reactive getters. Data methods need no wrapper. Throws outside a plugin's owner.
|
|
27
|
+
*
|
|
28
|
+
* @param component - One component the contract exposes.
|
|
29
|
+
* @returns The component under the providing plugin's context.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* ctx.provide(FileTree, { Tree: bindPlugin((props) => <Tree {...props} />) })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function bindPlugin(component) {
|
|
37
|
+
const context = usePlugin();
|
|
38
|
+
return (props) => createComponent(PluginContext.Provider, {
|
|
39
|
+
value: context,
|
|
40
|
+
get children() {
|
|
41
|
+
return createComponent(component, props);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Where the current panel render is shown. Throws outside a `Panel.render`.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const panel = usePanel()
|
|
51
|
+
* const compact = () => panel.placement() === "mobile"
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function usePanel() {
|
|
55
|
+
const frame = useContext(PanelContext);
|
|
56
|
+
if (!frame)
|
|
57
|
+
throw new Error("usePanel must run inside a panel render");
|
|
58
|
+
return frame;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The drawer showing this panel, or undefined outside one. Close it before an action that opens another view.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const drawer = useDrawer()
|
|
66
|
+
* const open = (path: string) => {
|
|
67
|
+
* drawer?.close()
|
|
68
|
+
* ctx.layout.open(`file:${path}`, session)
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export function useDrawer() {
|
|
73
|
+
return useContext(DrawerContext);
|
|
74
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
/** Where `gui()` reads a plugin's GUI and writes its `./gui-experimental` bundle. */
|
|
3
|
+
export interface GuiOptions {
|
|
4
|
+
/** The module whose default export is the plugin's `Plugin.define`. Defaults to `src/gui.tsx`. */
|
|
5
|
+
readonly entry?: string;
|
|
6
|
+
/** The CommonJS bundle to write, the file `./gui-experimental` exports. Defaults to `dist/gui-experimental.cjs`. */
|
|
7
|
+
readonly outFile?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Builds a plugin's `./gui-experimental` bundle with Vite: compiles Solid JSX, writes one CommonJS file with every
|
|
11
|
+
* dynamic `import()` inlined, since the app loads no second chunk, and keeps the modules the app provides external,
|
|
12
|
+
* with Electron and Node built-ins. Another module of Effect, Solid or OpenCode fails the build: the app does not
|
|
13
|
+
* provide it, and a bundled copy would not share the app's instance.
|
|
14
|
+
*
|
|
15
|
+
* @param options - The entry and the bundle to write.
|
|
16
|
+
* @returns The Vite plugins.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // vite.config.ts
|
|
21
|
+
* export default defineConfig({ plugins: [gui()] })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function gui(options?: GuiOptions): Plugin[];
|
package/dist/gui/vite.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { isBuiltin } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import solid from "vite-plugin-solid";
|
|
4
|
+
import { pluginSharedModules, pluginWindowModules } from "./modules.js";
|
|
5
|
+
// The modules the app provides to a plugin's GUI, each the app's own instance; the bundle must not include a copy.
|
|
6
|
+
const provided = new Set([...pluginSharedModules, ...pluginWindowModules]);
|
|
7
|
+
/**
|
|
8
|
+
* Builds a plugin's `./gui-experimental` bundle with Vite: compiles Solid JSX, writes one CommonJS file with every
|
|
9
|
+
* dynamic `import()` inlined, since the app loads no second chunk, and keeps the modules the app provides external,
|
|
10
|
+
* with Electron and Node built-ins. Another module of Effect, Solid or OpenCode fails the build: the app does not
|
|
11
|
+
* provide it, and a bundled copy would not share the app's instance.
|
|
12
|
+
*
|
|
13
|
+
* @param options - The entry and the bundle to write.
|
|
14
|
+
* @returns The Vite plugins.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* // vite.config.ts
|
|
19
|
+
* export default defineConfig({ plugins: [gui()] })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function gui(options = {}) {
|
|
23
|
+
const outFile = options.outFile ?? "dist/gui-experimental.cjs";
|
|
24
|
+
return [
|
|
25
|
+
solid(),
|
|
26
|
+
{
|
|
27
|
+
name: "opencode-gui",
|
|
28
|
+
enforce: "pre",
|
|
29
|
+
config: () => ({
|
|
30
|
+
build: {
|
|
31
|
+
outDir: path.dirname(outFile),
|
|
32
|
+
emptyOutDir: false,
|
|
33
|
+
lib: {
|
|
34
|
+
entry: options.entry ?? "src/gui.tsx",
|
|
35
|
+
formats: ["cjs"],
|
|
36
|
+
fileName: () => path.basename(outFile),
|
|
37
|
+
},
|
|
38
|
+
rollupOptions: { output: { exports: "named", inlineDynamicImports: true } },
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
resolveId(source) {
|
|
42
|
+
if (provided.has(source) || source === "electron" || isBuiltin(source))
|
|
43
|
+
return { id: source, external: true };
|
|
44
|
+
if (/^(effect|solid-js|@opencode)\//.test(source))
|
|
45
|
+
this.error(`${source} is not a module the OpenCode app provides to plugin GUIs: ${[...provided].join(", ")}`);
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
}
|
package/dist/host.d.ts
CHANGED
|
@@ -7,6 +7,17 @@ export interface Entrypoints {
|
|
|
7
7
|
readonly server?: string;
|
|
8
8
|
readonly tui?: string;
|
|
9
9
|
readonly rpc?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The prebuilt CommonJS GUI bundle (`./gui-experimental`, or `gui-experimental.cjs` or `gui-experimental.js` in a
|
|
12
|
+
* local directory without `exports`). Each desktop app window runs its default export; the desktop app's main
|
|
13
|
+
* process runs its `main` export.
|
|
14
|
+
*/
|
|
15
|
+
readonly gui?: string;
|
|
10
16
|
}
|
|
11
|
-
export declare function resolve(
|
|
17
|
+
export declare function resolve(input: Target): Entrypoints;
|
|
12
18
|
export declare function load(entrypoint: string): Promise<unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* The id of a plugin without a server part: its package name, or a local directory's name when it has no
|
|
21
|
+
* package.json name. A server part names its plugin in `Plugin.define` instead.
|
|
22
|
+
*/
|
|
23
|
+
export declare function packageID(target: Target): string;
|
package/dist/host.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export * as Host from "./host.js";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
4
|
+
import { Option, Schema } from "effect";
|
|
3
5
|
import { importModule, resolveModule } from "@opencode/util/runtime-import";
|
|
4
|
-
export function resolve(
|
|
6
|
+
export function resolve(input) {
|
|
7
|
+
// A local directory whose package.json names the package and maps `exports` resolves through them, like the
|
|
8
|
+
// published package; without them it uses the conventional file names at its root.
|
|
9
|
+
const manifest = input.name ? undefined : packageManifest(input.directory);
|
|
10
|
+
const target = typeof manifest?.name === "string" && manifest.exports !== undefined ? { ...input, name: manifest.name } : input;
|
|
5
11
|
const entry = (subpaths) => {
|
|
6
12
|
for (const subpath of subpaths) {
|
|
7
13
|
const specifier = target.name
|
|
@@ -26,8 +32,34 @@ export function resolve(target) {
|
|
|
26
32
|
}
|
|
27
33
|
return undefined;
|
|
28
34
|
};
|
|
29
|
-
return {
|
|
35
|
+
return {
|
|
36
|
+
server: entry(["server", ""]),
|
|
37
|
+
tui: entry(["tui"]),
|
|
38
|
+
rpc: entry(["rpc"]),
|
|
39
|
+
// The app evaluates the bundle as CommonJS text, so a TypeScript source or an ES module is never a GUI entry.
|
|
40
|
+
gui: [target.name ? entry(["gui-experimental"]) : entry(["gui-experimental.cjs", "gui-experimental.js"])].find((file) => file && /\.c?js$/.test(file)),
|
|
41
|
+
};
|
|
30
42
|
}
|
|
31
43
|
export function load(entrypoint) {
|
|
32
44
|
return importModule(entrypoint);
|
|
33
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* The id of a plugin without a server part: its package name, or a local directory's name when it has no
|
|
48
|
+
* package.json name. A server part names its plugin in `Plugin.define` instead.
|
|
49
|
+
*/
|
|
50
|
+
export function packageID(target) {
|
|
51
|
+
if (target.name)
|
|
52
|
+
return target.name;
|
|
53
|
+
const name = packageManifest(target.directory)?.name;
|
|
54
|
+
return typeof name === "string" && name ? name : path.basename(target.directory);
|
|
55
|
+
}
|
|
56
|
+
// The fields resolution reads from a local directory's package.json.
|
|
57
|
+
const Manifest = Schema.fromJsonString(Schema.Struct({ name: Schema.optional(Schema.Unknown), exports: Schema.optional(Schema.Unknown) }));
|
|
58
|
+
// A package.json that is not a JSON object counts as missing, so one broken plugin directory never stops the rest
|
|
59
|
+
// from resolving: it falls back to the conventional root file names.
|
|
60
|
+
function packageManifest(directory) {
|
|
61
|
+
const file = path.join(directory, "package.json");
|
|
62
|
+
if (!existsSync(file))
|
|
63
|
+
return undefined;
|
|
64
|
+
return Option.getOrUndefined(Schema.decodeUnknownOption(Manifest)(readFileSync(file, "utf8")));
|
|
65
|
+
}
|