@radheim/plugin 0.0.0-stage → 2.4.3

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.
Files changed (170) hide show
  1. package/README.md +19 -3
  2. package/dist/app.d.ts +5 -0
  3. package/dist/app.js +0 -0
  4. package/dist/effect/agent.d.ts +15 -0
  5. package/dist/effect/agent.js +0 -0
  6. package/dist/effect/aisdk.d.ts +20 -0
  7. package/dist/effect/aisdk.js +0 -0
  8. package/dist/effect/artifact.d.ts +42 -0
  9. package/dist/effect/artifact.js +0 -0
  10. package/dist/effect/command.d.ts +23 -0
  11. package/dist/effect/command.js +0 -0
  12. package/dist/effect/event.d.ts +9 -0
  13. package/dist/effect/event.js +0 -0
  14. package/dist/effect/index.d.ts +20 -0
  15. package/dist/effect/index.js +19 -0
  16. package/dist/effect/integration.d.ts +103 -0
  17. package/dist/effect/integration.js +3 -0
  18. package/dist/effect/mcp.d.ts +15 -0
  19. package/dist/effect/mcp.js +0 -0
  20. package/dist/effect/model.d.ts +29 -0
  21. package/dist/effect/model.js +0 -0
  22. package/dist/effect/permission.d.ts +30 -0
  23. package/dist/effect/permission.js +0 -0
  24. package/dist/effect/plugin.d.ts +69 -0
  25. package/dist/effect/plugin.js +3 -0
  26. package/dist/effect/provider.d.ts +34 -0
  27. package/dist/effect/provider.js +0 -0
  28. package/dist/effect/push.d.ts +52 -0
  29. package/dist/effect/push.js +0 -0
  30. package/dist/effect/reference.d.ts +14 -0
  31. package/dist/effect/reference.js +0 -0
  32. package/dist/effect/registration.d.ts +13 -0
  33. package/dist/effect/registration.js +0 -0
  34. package/dist/effect/rpc.d.ts +19 -0
  35. package/dist/effect/rpc.js +0 -0
  36. package/dist/effect/session.d.ts +217 -0
  37. package/dist/effect/session.js +0 -0
  38. package/dist/effect/shell.d.ts +14 -0
  39. package/dist/effect/shell.js +0 -0
  40. package/dist/effect/skill.d.ts +15 -0
  41. package/dist/effect/skill.js +1 -0
  42. package/dist/effect/storage.d.ts +8 -0
  43. package/dist/effect/storage.js +0 -0
  44. package/dist/effect/tool.d.ts +60 -0
  45. package/dist/effect/tool.js +1 -0
  46. package/dist/effect/vcs.d.ts +43 -0
  47. package/dist/effect/vcs.js +0 -0
  48. package/dist/effect/websearch.d.ts +20 -0
  49. package/dist/effect/websearch.js +0 -0
  50. package/dist/effect/worktree.d.ts +18 -0
  51. package/dist/effect/worktree.js +0 -0
  52. package/dist/gui/browser.d.ts +54 -0
  53. package/dist/gui/browser.js +3 -0
  54. package/dist/gui/context.d.ts +287 -0
  55. package/dist/gui/context.js +0 -0
  56. package/dist/gui/core.d.ts +581 -0
  57. package/dist/gui/core.js +86 -0
  58. package/dist/gui/declarations.d.ts +47 -0
  59. package/dist/gui/declarations.js +0 -0
  60. package/dist/gui/file.d.ts +122 -0
  61. package/dist/gui/file.js +7 -0
  62. package/dist/gui/host-apis.d.ts +2239 -0
  63. package/dist/gui/host-apis.js +0 -0
  64. package/dist/gui/icon-name.d.ts +2 -0
  65. package/dist/gui/icon-name.js +1 -0
  66. package/dist/gui/index.d.ts +7 -0
  67. package/dist/gui/index.js +6 -0
  68. package/dist/gui/internal.d.ts +44 -0
  69. package/dist/gui/internal.js +33 -0
  70. package/dist/gui/main.d.ts +279 -0
  71. package/dist/gui/main.js +20 -0
  72. package/dist/gui/modules.d.ts +15 -0
  73. package/dist/gui/modules.js +30 -0
  74. package/dist/gui/plugin.d.ts +87 -0
  75. package/dist/gui/plugin.js +9 -0
  76. package/dist/gui/reactive.d.ts +93 -0
  77. package/dist/gui/reactive.js +130 -0
  78. package/dist/gui/registries.d.ts +1045 -0
  79. package/dist/gui/registries.js +153 -0
  80. package/dist/gui/review.d.ts +74 -0
  81. package/dist/gui/review.js +3 -0
  82. package/dist/gui/scope.d.ts +64 -0
  83. package/dist/gui/scope.js +85 -0
  84. package/dist/gui/solid.d.ts +111 -0
  85. package/dist/gui/solid.js +74 -0
  86. package/dist/gui/vite.d.ts +24 -0
  87. package/dist/gui/vite.js +49 -0
  88. package/dist/host.d.ts +23 -0
  89. package/dist/host.js +65 -0
  90. package/dist/options.d.ts +1 -0
  91. package/dist/options.js +0 -0
  92. package/dist/permission.d.ts +22 -0
  93. package/dist/permission.js +12 -0
  94. package/dist/promise/adapter.d.ts +12 -0
  95. package/dist/promise/adapter.js +576 -0
  96. package/dist/promise/agent.d.ts +15 -0
  97. package/dist/promise/agent.js +0 -0
  98. package/dist/promise/aisdk.d.ts +20 -0
  99. package/dist/promise/aisdk.js +0 -0
  100. package/dist/promise/artifact.d.ts +49 -0
  101. package/dist/promise/artifact.js +0 -0
  102. package/dist/promise/command.d.ts +22 -0
  103. package/dist/promise/command.js +0 -0
  104. package/dist/promise/event.d.ts +7 -0
  105. package/dist/promise/event.js +0 -0
  106. package/dist/promise/index.d.ts +20 -0
  107. package/dist/promise/index.js +18 -0
  108. package/dist/promise/integration.d.ts +102 -0
  109. package/dist/promise/integration.js +3 -0
  110. package/dist/promise/mcp.d.ts +15 -0
  111. package/dist/promise/mcp.js +0 -0
  112. package/dist/promise/model.d.ts +29 -0
  113. package/dist/promise/model.js +0 -0
  114. package/dist/promise/permission.d.ts +29 -0
  115. package/dist/promise/permission.js +0 -0
  116. package/dist/promise/plugin.d.ts +70 -0
  117. package/dist/promise/plugin.js +3 -0
  118. package/dist/promise/provider.d.ts +34 -0
  119. package/dist/promise/provider.js +0 -0
  120. package/dist/promise/push.d.ts +50 -0
  121. package/dist/promise/push.js +0 -0
  122. package/dist/promise/reference.d.ts +13 -0
  123. package/dist/promise/reference.js +0 -0
  124. package/dist/promise/registration.d.ts +12 -0
  125. package/dist/promise/registration.js +0 -0
  126. package/dist/promise/rpc.d.ts +22 -0
  127. package/dist/promise/rpc.js +0 -0
  128. package/dist/promise/session.d.ts +217 -0
  129. package/dist/promise/session.js +0 -0
  130. package/dist/promise/shell.d.ts +14 -0
  131. package/dist/promise/shell.js +0 -0
  132. package/dist/promise/skill.d.ts +15 -0
  133. package/dist/promise/skill.js +0 -0
  134. package/dist/promise/storage.d.ts +8 -0
  135. package/dist/promise/storage.js +0 -0
  136. package/dist/promise/tool.d.ts +71 -0
  137. package/dist/promise/tool.js +2 -0
  138. package/dist/promise/vcs.d.ts +53 -0
  139. package/dist/promise/vcs.js +0 -0
  140. package/dist/promise/websearch.d.ts +21 -0
  141. package/dist/promise/websearch.js +0 -0
  142. package/dist/promise/worktree.d.ts +23 -0
  143. package/dist/promise/worktree.js +0 -0
  144. package/dist/rpc.d.ts +1 -0
  145. package/dist/rpc.js +1 -0
  146. package/dist/runtime-modules.d.ts +6 -0
  147. package/dist/runtime-modules.js +103 -0
  148. package/dist/runtime.d.ts +4 -0
  149. package/dist/runtime.js +46 -0
  150. package/dist/source.bun.d.ts +4 -0
  151. package/dist/source.bun.js +75 -0
  152. package/dist/source.d.ts +8 -0
  153. package/dist/source.js +59 -0
  154. package/dist/source.node.d.ts +5 -0
  155. package/dist/source.node.js +55 -0
  156. package/dist/source.package.d.ts +1 -0
  157. package/dist/source.package.js +15 -0
  158. package/dist/storage.d.ts +14 -0
  159. package/dist/storage.js +0 -0
  160. package/dist/tui/context.d.ts +500 -0
  161. package/dist/tui/context.js +0 -0
  162. package/dist/tui/index.d.ts +2 -0
  163. package/dist/tui/index.js +2 -0
  164. package/dist/tui/plugin.d.ts +8 -0
  165. package/dist/tui/plugin.js +3 -0
  166. package/dist/tui/solid.d.ts +7 -0
  167. package/dist/tui/solid.js +16 -0
  168. package/dist/worktree.d.ts +18 -0
  169. package/dist/worktree.js +0 -0
  170. package/package.json +137 -4
@@ -0,0 +1,217 @@
1
+ import type { ExperimentalSessionApi, SessionApi } from "@radheim/client/promise/api";
2
+ import type { GenerationOptionsFields, Message, SystemPart } from "@radheim/ai/effect";
3
+ import type { Agent } from "@radheim/schema/agent";
4
+ import type { Model } from "@radheim/schema/model";
5
+ import type { PromptInput } from "@radheim/schema/prompt-input";
6
+ import type { Session } from "@radheim/schema/session";
7
+ import type { SessionInbox } from "@radheim/schema/session-inbox";
8
+ import type { SessionError } from "@radheim/schema/session-error";
9
+ import type { SessionMessage } from "@radheim/schema/session-message";
10
+ import type { TokenUsage } from "@radheim/schema/token-usage";
11
+ import type { JsonSchema, Types } from "effect";
12
+ import type { ModelHooks } from "./registration.js";
13
+ export interface SessionPrompt {
14
+ readonly sessionID: Session.ID;
15
+ readonly messageID: SessionMessage.ID;
16
+ prompt: Types.DeepMutable<PromptInput.Prompt>;
17
+ metadata?: Record<string, unknown>;
18
+ delivery: SessionInbox.Delivery;
19
+ }
20
+ /** Request overrides. Typed keys are generation settings; any other key is a provider option. */
21
+ export type SessionRequestOptions = Types.DeepMutable<GenerationOptionsFields> & Record<string, unknown>;
22
+ /** A request message. `metadata` is the stored Session message's metadata, for reading only; it is not sent to the model. */
23
+ export type SessionRequestMessage = Message & {
24
+ readonly metadata?: Record<string, unknown>;
25
+ };
26
+ export interface SessionRequest {
27
+ readonly sessionID: Session.ID;
28
+ readonly model: Model.Ref;
29
+ /**
30
+ * The instructions part keeps each source's text in `metadata.experimental.instructions` as `{ key, text }`. It is
31
+ * not updated when a hook edits `text`. Experimental.
32
+ */
33
+ system: Array<SystemPart>;
34
+ messages: Array<SessionRequestMessage>;
35
+ options: SessionRequestOptions;
36
+ }
37
+ export interface SessionContext extends SessionRequest {
38
+ readonly agent: Agent.ID;
39
+ tools: Record<string, {
40
+ description: string;
41
+ input: JsonSchema.JsonSchema;
42
+ }>;
43
+ }
44
+ export interface SessionCompactionResult {
45
+ summary: string;
46
+ /** `native.messages`, when set, must be a provider replacement window; it replays instead of `summary`. */
47
+ native?: SessionMessage.Native;
48
+ metadata?: Record<string, unknown>;
49
+ tokens?: TokenUsage.Info;
50
+ }
51
+ export interface SessionCompaction extends SessionContext {
52
+ /** Set to use this compaction and skip the model request. */
53
+ result?: SessionCompactionResult;
54
+ }
55
+ export interface SessionGenerate extends SessionContext {
56
+ }
57
+ export interface SessionTitle extends SessionRequest {
58
+ /** Set to use this title and skip the model request. */
59
+ result?: string;
60
+ }
61
+ /**
62
+ * Why a Session request is being made. Auxiliary requests share the Session's
63
+ * hook identity but need to be told apart from the agent loop.
64
+ */
65
+ export type SessionRequestKind = "primary" | "compaction" | "title" | "generate";
66
+ /**
67
+ * Runs whenever a Session resolves the model for a request, before anything is built for it. `model` starts as the
68
+ * Session's or agent's selection; change it to serve this request with another model from the same provider, including
69
+ * models hidden from the picker. The Session keeps its selection, and the request and its records use the new model.
70
+ * Router models such as GitHub Copilot's Auto use it. Experimental.
71
+ */
72
+ export interface SessionModelResolve {
73
+ readonly sessionID: Session.ID;
74
+ readonly agent: Agent.ID;
75
+ readonly kind: SessionRequestKind;
76
+ model: Model.Ref;
77
+ }
78
+ export interface SessionModelRequest {
79
+ readonly sessionID: Session.ID;
80
+ readonly agent: Agent.ID;
81
+ readonly model: Model.Ref;
82
+ readonly kind: SessionRequestKind;
83
+ baseURL?: string;
84
+ headers: Record<string, string>;
85
+ }
86
+ export interface SessionHttpRequest {
87
+ readonly sessionID: Session.ID;
88
+ readonly agent: Agent.ID;
89
+ readonly model: Model.Ref;
90
+ readonly kind: SessionRequestKind;
91
+ request: Request;
92
+ response?: Response;
93
+ }
94
+ export interface SessionHttpResponse {
95
+ readonly sessionID: Session.ID;
96
+ readonly agent: Agent.ID;
97
+ readonly model: Model.Ref;
98
+ readonly kind: SessionRequestKind;
99
+ readonly request: Request;
100
+ response: Response;
101
+ }
102
+ /**
103
+ * Connection a WebSocket-backed request opens or reuses. Runs once per model call before the
104
+ * Session's socket is selected; changing `url` or `headers` reopens the socket. Experimental.
105
+ */
106
+ export interface SessionWebSocketHandshake {
107
+ readonly sessionID: Session.ID;
108
+ readonly agent: Agent.ID;
109
+ readonly model: Model.Ref;
110
+ readonly kind: SessionRequestKind;
111
+ url: string;
112
+ headers: Record<string, string>;
113
+ }
114
+ /**
115
+ * Outbound frame about to be written to the Session's socket, after the provider driver has built
116
+ * it. Replacing `frame` sends the replacement verbatim; the driver still tracks state from the
117
+ * provider's replies, so a rewrite that changes protocol meaning is on the plugin. Experimental.
118
+ */
119
+ export interface SessionWebSocketSend {
120
+ readonly sessionID: Session.ID;
121
+ readonly agent: Agent.ID;
122
+ readonly model: Model.Ref;
123
+ readonly kind: SessionRequestKind;
124
+ frame: string;
125
+ }
126
+ /**
127
+ * Inbound frame read from the Session's socket, before the provider driver observes it. Replacing
128
+ * `frame` hands the replacement to the driver verbatim. Experimental.
129
+ */
130
+ export interface SessionWebSocketReceive {
131
+ readonly sessionID: Session.ID;
132
+ readonly agent: Agent.ID;
133
+ readonly model: Model.Ref;
134
+ readonly kind: SessionRequestKind;
135
+ frame: string;
136
+ }
137
+ export type SessionRetryDecision = {
138
+ retry: false;
139
+ } | {
140
+ retry: true;
141
+ delay: number;
142
+ };
143
+ export interface SessionRetry {
144
+ readonly sessionID: Session.ID;
145
+ readonly agent: Agent.ID;
146
+ readonly model: Model.Ref;
147
+ readonly error: SessionError.Error;
148
+ readonly attempt: number;
149
+ decision: SessionRetryDecision;
150
+ }
151
+ /**
152
+ * Background work still running for the idle Session or one of its descendants. `sessionID` is
153
+ * the Session that owns the job: the idle Session itself, or a descendant such as a subagent child.
154
+ */
155
+ export type SessionIdleBackground = {
156
+ readonly kind: "codemode";
157
+ readonly sessionID: Session.ID;
158
+ readonly jobID: string;
159
+ } | {
160
+ readonly kind: "shell";
161
+ readonly sessionID: Session.ID;
162
+ readonly shellID: string;
163
+ readonly command: string;
164
+ } | {
165
+ readonly kind: "subagent";
166
+ readonly sessionID: Session.ID;
167
+ readonly childSessionID: Session.ID;
168
+ readonly agent: string;
169
+ readonly description: string;
170
+ } | {
171
+ readonly kind: "image";
172
+ readonly sessionID: Session.ID;
173
+ readonly path: string;
174
+ readonly model: string;
175
+ } | {
176
+ readonly kind: "video";
177
+ readonly sessionID: Session.ID;
178
+ readonly path: string;
179
+ };
180
+ /**
181
+ * Runs when a Session finishes model work and has no pending input, just before it goes idle.
182
+ * It does not run after interruption, failure, or control-only work such as a manual compaction.
183
+ * Input admitted by the hook, such as a synthetic message, runs in the same execution instead
184
+ * of the Session going idle.
185
+ *
186
+ * `background` lists work that is still running. When the Session's own shell or subagent finishes,
187
+ * its notice wakes the Session and the hook runs again, so a plugin that waits for that work can
188
+ * simply return. Work a descendant owns, such as a shell a subagent left running, wakes that
189
+ * descendant instead, so it is listed for information only. Notices admitted with `resume: false`,
190
+ * such as those recovered after a restart, wait for the next wake. Experimental.
191
+ */
192
+ export interface SessionIdle {
193
+ readonly sessionID: Session.ID;
194
+ readonly background: ReadonlyArray<SessionIdleBackground>;
195
+ }
196
+ export interface SessionHooks {
197
+ readonly fork: {
198
+ readonly sessionID: Session.ID;
199
+ };
200
+ readonly prompt: SessionPrompt;
201
+ readonly context: SessionContext;
202
+ readonly compaction: SessionCompaction;
203
+ readonly generate: SessionGenerate;
204
+ readonly title: SessionTitle;
205
+ readonly "experimental.model.resolve": SessionModelResolve;
206
+ readonly "model.request": SessionModelRequest;
207
+ readonly "http.request": SessionHttpRequest;
208
+ readonly "http.response": SessionHttpResponse;
209
+ readonly "experimental.ws.handshake": SessionWebSocketHandshake;
210
+ readonly "experimental.ws.send": SessionWebSocketSend;
211
+ readonly "experimental.ws.receive": SessionWebSocketReceive;
212
+ readonly retry: SessionRetry;
213
+ readonly "experimental.idle": SessionIdle;
214
+ }
215
+ export type SessionDomain = Pick<SessionApi, "list" | "create" | "get" | "remove" | "switchAgent" | "switchModel" | "prompt" | "generate" | "command" | "compact" | "synthetic" | "interrupt" | "update" | "move" | "context"> & Pick<ExperimentalSessionApi, "wait" | "instructions"> & {
216
+ readonly hook: ModelHooks<SessionHooks>;
217
+ };
File without changes
@@ -0,0 +1,14 @@
1
+ import type { Hooks } from "./registration.js";
2
+ export interface ShellCreateBefore {
3
+ command: string;
4
+ cwd: string;
5
+ timeout: number;
6
+ shell: string;
7
+ env: Record<string, string | undefined>;
8
+ }
9
+ export interface ShellHooks {
10
+ readonly "create.before": ShellCreateBefore;
11
+ }
12
+ export interface ShellDomain {
13
+ readonly hook: Hooks<ShellHooks>;
14
+ }
File without changes
@@ -0,0 +1,15 @@
1
+ import type { SkillApi } from "@radheim/client/promise/api";
2
+ import type { Skill } from "@radheim/schema/skill";
3
+ import type { Types } from "effect";
4
+ import type { Transform } from "./registration.js";
5
+ export interface SkillEditor {
6
+ list(): readonly Types.DeepMutable<Skill.Info>[];
7
+ get(id: string): Types.DeepMutable<Skill.Info> | undefined;
8
+ add(skill: Skill.Info): void;
9
+ update(id: string, update: (skill: Types.DeepMutable<Skill.Info>) => void): void;
10
+ remove(id: string): void;
11
+ }
12
+ export interface SkillDomain extends SkillApi {
13
+ readonly transform: Transform<SkillEditor>;
14
+ readonly reload: () => Promise<void>;
15
+ }
File without changes
@@ -0,0 +1,8 @@
1
+ import type { Schema } from "effect";
2
+ import type { StorageScanOptions, StorageScanResult } from "../storage.js";
3
+ export interface StorageDomain {
4
+ readonly get: (key: string) => Promise<Schema.Json | undefined>;
5
+ readonly set: (key: string, value: Schema.Json) => Promise<void>;
6
+ readonly remove: (key: string) => Promise<void>;
7
+ readonly scan: (options: StorageScanOptions) => Promise<StorageScanResult>;
8
+ }
File without changes
@@ -0,0 +1,71 @@
1
+ export { CallID, Error } from "@radheim/schema/tool";
2
+ export type { Metadata, Options, Result } from "@radheim/schema/tool";
3
+ import { Tool } from "@radheim/schema/tool";
4
+ import type { Agent } from "@radheim/schema/agent";
5
+ import type { Session } from "@radheim/schema/session";
6
+ import type { SessionMessage } from "@radheim/schema/session-message";
7
+ import type { Types } from "effect";
8
+ import type { Hooks, Transform } from "./registration.js";
9
+ export interface ToolContext extends Omit<Tool.Context, "progress" | "cancel"> {
10
+ /**
11
+ * Aborted when the call is interrupted, and when the user stops the call if the tool has read this property.
12
+ * Reading it (spreading the context reads it too) opts the tool into a cooperative stop: on the user's stop the
13
+ * signal aborts and whatever the tool then returns or throws is still reported as the call's result. A tool
14
+ * that never reads it, or does not settle soon after the stop, is interrupted.
15
+ */
16
+ readonly signal: AbortSignal;
17
+ readonly progress: (update: Tool.Metadata) => Promise<void>;
18
+ }
19
+ export type Info<Input extends Tool.ValueSchema<any> = Tool.ValueSchema<any>, Output extends Tool.ValueSchema<any> | undefined = Tool.ValueSchema<any> | undefined, CMInput extends Tool.ValueSchema<any> = Input, CMOutput extends Tool.ValueSchema<any> | undefined = Output> = Omit<Tool.Info<Input, Output, CMInput, CMOutput>, "execute"> & {
20
+ readonly execute: (input: Parameters<Tool.Info<Input, Output, CMInput, CMOutput>["execute"]>[0], context: ToolContext) => Promise<Tool.Result<Output | CMOutput>>;
21
+ };
22
+ export interface ToolEditor {
23
+ list(): readonly (Info & {
24
+ readonly id: string;
25
+ })[];
26
+ get(id: string): (Info & {
27
+ readonly id: string;
28
+ }) | undefined;
29
+ namespace(namespace: Tool.Namespace): void;
30
+ add<Input extends Tool.ValueSchema<any>, Output extends Tool.ValueSchema<any> | undefined = undefined, CMInput extends Tool.ValueSchema<any> = Input, CMOutput extends Tool.ValueSchema<any> | undefined = Output>(tool: Info<Input, Output, CMInput, CMOutput>): void;
31
+ /** Updates an existing tool; missing IDs are ignored. */
32
+ update(id: string, update: (tool: Types.Mutable<Info>) => void): void;
33
+ remove(id: string): void;
34
+ }
35
+ export interface ToolHooks {
36
+ readonly "execute.before": {
37
+ tool: string;
38
+ readonly info?: Info;
39
+ readonly codemode: boolean;
40
+ readonly sessionID: Session.ID;
41
+ readonly agent: Agent.ID;
42
+ readonly messageID: SessionMessage.ID;
43
+ readonly id: Tool.CallID;
44
+ input: unknown;
45
+ };
46
+ readonly "execute.after": {
47
+ readonly tool: string;
48
+ readonly info?: Info;
49
+ readonly codemode: boolean;
50
+ readonly sessionID: Session.ID;
51
+ readonly agent: Agent.ID;
52
+ readonly messageID: SessionMessage.ID;
53
+ readonly id: Tool.CallID;
54
+ readonly input: unknown;
55
+ } & ({
56
+ readonly status: "completed";
57
+ result: Tool.Result;
58
+ } | {
59
+ readonly status: "error";
60
+ error: Tool.Error;
61
+ });
62
+ }
63
+ export interface ToolDomain {
64
+ readonly transform: Transform<ToolEditor>;
65
+ readonly reload: () => Promise<void>;
66
+ /** Currently registered tools, after every transform, keyed by effective name. */
67
+ readonly list: () => Promise<readonly (Info & {
68
+ readonly id: string;
69
+ })[]>;
70
+ readonly hook: Hooks<ToolHooks>;
71
+ }
@@ -0,0 +1,2 @@
1
+ export { CallID, Error } from "@radheim/schema/tool";
2
+ import { Tool } from "@radheim/schema/tool";
@@ -0,0 +1,53 @@
1
+ import type { VcsApi } from "@radheim/client/promise/api";
2
+ import type { FileDiff } from "@radheim/schema/file-diff";
3
+ import type { Vcs } from "@radheim/schema/vcs";
4
+ import type { Transform } from "./registration.js";
5
+ export interface VcsScope {
6
+ readonly directory: string;
7
+ readonly worktree: string;
8
+ readonly canonical: string;
9
+ readonly store?: string;
10
+ }
11
+ export interface VcsBranchesInput extends VcsScope {
12
+ readonly search?: string;
13
+ readonly limit?: number;
14
+ }
15
+ export interface VcsDiffInput extends VcsScope {
16
+ readonly mode: Vcs.Mode;
17
+ readonly base?: string;
18
+ readonly context: number;
19
+ readonly maxOutputBytes: number;
20
+ }
21
+ export interface VcsDefinition {
22
+ readonly id: string;
23
+ readonly name: string;
24
+ readonly init?: (input: VcsScope, context: {
25
+ readonly signal: AbortSignal;
26
+ }) => Promise<void>;
27
+ readonly info: (input: VcsScope, context: {
28
+ readonly signal: AbortSignal;
29
+ }) => Promise<Vcs.Info>;
30
+ readonly base?: (input: VcsScope, context: {
31
+ readonly signal: AbortSignal;
32
+ }) => Promise<Vcs.Base | null>;
33
+ readonly branches: (input: VcsBranchesInput, context: {
34
+ readonly signal: AbortSignal;
35
+ }) => Promise<Vcs.BranchList>;
36
+ readonly status: (input: VcsScope, context: {
37
+ readonly signal: AbortSignal;
38
+ }) => Promise<readonly Vcs.FileStatus[]>;
39
+ readonly diff: (input: VcsDiffInput, context: {
40
+ readonly signal: AbortSignal;
41
+ }) => Promise<readonly FileDiff.Info[]>;
42
+ }
43
+ export interface VcsDomain extends Omit<VcsApi, "init"> {
44
+ readonly transform: Transform<VcsEditor>;
45
+ readonly reload: () => Promise<void>;
46
+ }
47
+ export interface VcsEditor {
48
+ add(definition: VcsDefinition): void;
49
+ readonly default: {
50
+ get(): string | undefined;
51
+ set(selection: string): void;
52
+ };
53
+ }
File without changes
@@ -0,0 +1,21 @@
1
+ import type { WebSearch } from "@radheim/schema/websearch";
2
+ import type { WebSearchApi } from "@radheim/client/promise/api";
3
+ import type { Transform } from "./registration.js";
4
+ export interface WebSearchDefinition {
5
+ readonly id: string;
6
+ readonly name: string;
7
+ readonly execute: (input: WebSearch.ProviderInput, context: {
8
+ readonly signal: AbortSignal;
9
+ }) => Promise<readonly WebSearch.Result[]>;
10
+ }
11
+ export interface WebSearchDomain extends WebSearchApi {
12
+ readonly transform: Transform<WebSearchEditor>;
13
+ readonly reload: () => Promise<void>;
14
+ }
15
+ export interface WebSearchEditor {
16
+ add(definition: WebSearchDefinition): void;
17
+ readonly default: {
18
+ get(): string | false | undefined;
19
+ set(selection: string | false): void;
20
+ };
21
+ }
File without changes
@@ -0,0 +1,23 @@
1
+ import type { WorktreeApi } from "@radheim/client/promise/api";
2
+ import type { WorktreeCreateInput, WorktreeEntry, WorktreeRemoveInput, WorktreeResult } from "../worktree.js";
3
+ import type { Transform } from "./registration.js";
4
+ export interface WorktreeDefinition {
5
+ readonly id: string;
6
+ readonly create: (input: WorktreeCreateInput, context: {
7
+ readonly signal: AbortSignal;
8
+ }) => Promise<WorktreeResult>;
9
+ readonly remove: (input: WorktreeRemoveInput, context: {
10
+ readonly signal: AbortSignal;
11
+ }) => Promise<void>;
12
+ readonly list: (sourceDirectory: string, context: {
13
+ readonly signal: AbortSignal;
14
+ }) => Promise<readonly WorktreeEntry[]>;
15
+ }
16
+ export interface WorktreeEditor {
17
+ /** Registers an implementation and selects it as the default. Later active registrations win. */
18
+ add(definition: WorktreeDefinition): void;
19
+ }
20
+ export interface WorktreeDomain extends WorktreeApi {
21
+ readonly transform: Transform<WorktreeEditor>;
22
+ readonly reload: () => Promise<void>;
23
+ }
File without changes
package/dist/rpc.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { Rpc } from "@radheim/schema/rpc";
package/dist/rpc.js ADDED
@@ -0,0 +1 @@
1
+ export { Rpc } from "@radheim/schema/rpc";
@@ -0,0 +1,6 @@
1
+ export type RuntimeModuleLoader = () => Record<string, unknown> | Promise<Record<string, unknown>>;
2
+ export declare function resolveHostPackageRoots(from?: string, packages?: readonly string[]): string[];
3
+ export declare function loadRuntimeModules(): Readonly<Record<string, RuntimeModuleLoader>>;
4
+ export declare function discoverPluginRuntimeSpecifiers(from?: string, packages?: readonly string[]): ReadonlyMap<string, string>;
5
+ export declare function pluginRuntimeLoaderCode(specifier: string, entries: ReadonlyMap<string, string>): string;
6
+ export declare function createLoader(resolved: string): RuntimeModuleLoader;
@@ -0,0 +1,103 @@
1
+ import { existsSync, realpathSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ const runtimePackages = ["effect", "@radheim/plugin"];
5
+ export function resolveHostPackageRoots(from = import.meta.dir, packages = runtimePackages) {
6
+ return packages.flatMap((pkgName) => {
7
+ const dir = path.dirname(Bun.resolveSync(`${pkgName}/package.json`, from));
8
+ return [dir, findNodeModulesDir(pkgName, from, dir)];
9
+ });
10
+ }
11
+ export function loadRuntimeModules() {
12
+ const entries = discoverPluginRuntimeSpecifiers();
13
+ const effectEntry = entries.get("effect");
14
+ if (effectEntry)
15
+ require(effectEntry);
16
+ return Object.fromEntries([...entries.entries()].map(([specifier, resolved]) => [specifier, createLoader(resolved)]));
17
+ }
18
+ export function discoverPluginRuntimeSpecifiers(from = import.meta.dir, packages = runtimePackages) {
19
+ const entries = new Map();
20
+ for (const pkgName of packages) {
21
+ const realDir = path.dirname(Bun.resolveSync(`${pkgName}/package.json`, from));
22
+ // Resolve workspace @radheim/plugin paths via node_modules so OpenTUI does not wrap host files in async rewrite loaders.
23
+ const loadDir = findNodeModulesDir(pkgName, from, realDir);
24
+ const toLoadPath = (resolved) => loadDir === realDir ? resolved : path.join(loadDir, path.relative(realDir, resolved));
25
+ const rootEntry = Bun.resolveSync(pkgName, from);
26
+ const relParts = path.relative(realDir, rootEntry).replaceAll("\\", "/").split("/");
27
+ const scanDir = relParts.length > 1 ? path.join(realDir, relParts[0]) : realDir;
28
+ const ext = path.extname(rootEntry) || ".js";
29
+ entries.set(pkgName, toLoadPath(rootEntry));
30
+ for (const file of new Bun.Glob(`**/*${ext}`).scanSync({ cwd: scanDir })) {
31
+ const normalized = file.replaceAll("\\", "/");
32
+ // The GUI SDK and its Vite preset (`gui/`) run in the desktop app and at build time, never in the server or the TUI.
33
+ if (normalized.startsWith("internal/") ||
34
+ normalized.includes("/internal/") ||
35
+ normalized.startsWith("source.") ||
36
+ normalized.startsWith("runtime") ||
37
+ normalized.startsWith("gui/")) {
38
+ continue;
39
+ }
40
+ const base = normalized.slice(0, -ext.length);
41
+ if (base === "index")
42
+ continue;
43
+ const candidates = base.endsWith("/index")
44
+ ? [`${pkgName}/${base.slice(0, -"/index".length)}`, `${pkgName}/${base}`]
45
+ : [`${pkgName}/${base}`];
46
+ for (const specifier of candidates) {
47
+ if (entries.has(specifier))
48
+ continue;
49
+ try {
50
+ entries.set(specifier, toLoadPath(Bun.resolveSync(specifier, from)));
51
+ }
52
+ catch { }
53
+ }
54
+ }
55
+ }
56
+ return entries;
57
+ }
58
+ export function pluginRuntimeLoaderCode(specifier, entries) {
59
+ if (specifier.startsWith("effect/")) {
60
+ const slash = specifier.lastIndexOf("/");
61
+ const parent = specifier.slice(0, slash);
62
+ const member = specifier.slice(slash + 1);
63
+ const parentResolved = entries.get(parent);
64
+ const resolved = entries.get(specifier);
65
+ if (member !== "index" &&
66
+ parentResolved &&
67
+ resolved &&
68
+ require(parentResolved)[member] === require(resolved)) {
69
+ return `() => require(${JSON.stringify(parent)})[${JSON.stringify(member)}]`;
70
+ }
71
+ }
72
+ return `() => require(${JSON.stringify(specifier)})`;
73
+ }
74
+ export function createLoader(resolved) {
75
+ let cached;
76
+ let pending;
77
+ return () => {
78
+ if (cached)
79
+ return cached;
80
+ if (pending)
81
+ return pending;
82
+ try {
83
+ return (cached = require(resolved));
84
+ }
85
+ catch {
86
+ return (pending = import(pathToFileURL(resolved).href).then((mod) => (cached = mod), (error) => {
87
+ pending = undefined;
88
+ throw error;
89
+ }));
90
+ }
91
+ };
92
+ }
93
+ function findNodeModulesDir(pkgName, from, realDir) {
94
+ if (/[/\\]node_modules[/\\]/.test(realDir))
95
+ return realDir;
96
+ for (let dir = path.resolve(from);; dir = path.dirname(dir)) {
97
+ const candidate = path.join(dir, "node_modules", pkgName);
98
+ if (existsSync(candidate) && realpathSync(candidate) === realDir)
99
+ return candidate;
100
+ if (path.dirname(dir) === dir)
101
+ return realDir;
102
+ }
103
+ }
@@ -0,0 +1,4 @@
1
+ import { type RuntimeModuleLoader } from "./runtime-modules.js";
2
+ export declare function provides(specifier: string): boolean;
3
+ export declare function ensurePluginRuntime(): Readonly<Record<string, RuntimeModuleLoader>>;
4
+ export declare function createForeignPackageFilter(rootsInput?: Iterable<string>): RegExp;
@@ -0,0 +1,46 @@
1
+ import { loadRuntimeModules, resolveHostPackageRoots } from "./runtime-modules.js";
2
+ const foreignPkgSuffix = String.raw `(?:node_modules[/\\](@opencode[/\\]plugin|effect)|(@opencode[/\\]plugin|effect)@[^/\\]+@@@\d+)`;
3
+ const foreignPkgPattern = new RegExp(String.raw `^(.*[/\\]${foreignPkgSuffix})[/\\](.+)$`);
4
+ let installed;
5
+ export function provides(specifier) {
6
+ return installed !== undefined && Object.hasOwn(installed, specifier);
7
+ }
8
+ export function ensurePluginRuntime() {
9
+ if (typeof Bun === "undefined")
10
+ return {};
11
+ if (installed)
12
+ return installed;
13
+ const modules = loadRuntimeModules();
14
+ installed = modules;
15
+ Bun.plugin({
16
+ name: "opencode-plugin-runtime",
17
+ setup(build) {
18
+ for (const [specifier, load] of Object.entries(modules)) {
19
+ build.module(specifier, () => {
20
+ const exports = load();
21
+ return exports instanceof Promise
22
+ ? exports.then((value) => ({ exports: value, loader: "object" }))
23
+ : { exports, loader: "object" };
24
+ });
25
+ }
26
+ build.onLoad({ filter: createForeignPackageFilter() }, (args) => {
27
+ const match = args.path.match(foreignPkgPattern);
28
+ const target = match ? `${match[2] ?? match[3]}/${match[4]}`.replaceAll("\\", "/") : args.path;
29
+ throw new Error(`Cannot load "${target}" from plugin node_modules: "${target}" is not provided by OpenCode; plugins must use the host's "effect" and "@radheim/plugin" modules.`);
30
+ });
31
+ },
32
+ });
33
+ return modules;
34
+ }
35
+ export function createForeignPackageFilter(rootsInput = resolveHostPackageRoots()) {
36
+ const suffix = String.raw `[/\\]${foreignPkgSuffix}[/\\].*\.[cm]?[jt]sx?(?:[?#].*)?$`;
37
+ const roots = [...new Set(rootsInput)];
38
+ if (roots.length === 0)
39
+ return new RegExp(suffix);
40
+ const escaped = roots
41
+ .map((value) => value
42
+ .replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
43
+ .replace(/(?:\\\/|\\\\|\/)+/g, "[/\\\\]"))
44
+ .join("|");
45
+ return new RegExp(`^(?!(?:${escaped})[/\\\\]).*${suffix}`);
46
+ }
@@ -0,0 +1,4 @@
1
+ export declare function prepareSource(entrypoint: string, track: (file: string, directory?: boolean) => void): Promise<{
2
+ version: string;
3
+ load: () => Promise<unknown>;
4
+ }>;