@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,75 @@
1
+ import { createRequire } from "node:module";
2
+ import { readFileSync } from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
+ import { Host } from "./host.js";
6
+ import { provides } from "./runtime.js";
7
+ import { localSource } from "./source.js";
8
+ import { missingPackageTarget } from "./source.package.js";
9
+ let generation = Date.now();
10
+ export async function prepareSource(entrypoint, track) {
11
+ const root = fileURLToPath(entrypoint);
12
+ const files = new Set();
13
+ const visit = (file, search = "") => {
14
+ if (file !== root && file.split(path.sep).includes("node_modules"))
15
+ return;
16
+ if (search)
17
+ delete require.cache[file + search];
18
+ if (files.has(file))
19
+ return;
20
+ files.add(file);
21
+ // Bun exposes ESM here too. Delete known keys even when absent: rejected
22
+ // evaluations are not enumerable, but deletion still invalidates them.
23
+ delete require.cache[file];
24
+ track(file);
25
+ if (!/\.[cm]?[jt]sx?$/.test(file))
26
+ return;
27
+ // Scan dependencies only; the normal runtime loader still owns compilation,
28
+ // package resolution, import attributes, and error reporting.
29
+ const imports = (() => {
30
+ try {
31
+ return new Bun.Transpiler({
32
+ loader: file.endsWith("tsx") ? "tsx" : file.endsWith("jsx") ? "jsx" : /\.[cm]?ts$/.test(file) ? "ts" : "js",
33
+ target: "bun",
34
+ }).scan(readFileSync(file, "utf8")).imports;
35
+ }
36
+ catch {
37
+ return [];
38
+ }
39
+ })();
40
+ for (const item of imports) {
41
+ const local = item.path.startsWith("./") || item.path.startsWith("../")
42
+ ? new URL(item.path, pathToFileURL(file))
43
+ : localSource(item.path, path.dirname(file));
44
+ if (!local) {
45
+ if (provides(item.path))
46
+ continue;
47
+ try {
48
+ Bun.resolveSync(item.path, path.dirname(file));
49
+ }
50
+ catch {
51
+ const target = missingPackageTarget(item.path, file);
52
+ if (target)
53
+ track(target, true);
54
+ }
55
+ continue;
56
+ }
57
+ const requested = fileURLToPath(local);
58
+ // Resolving a workspace symlink can erase its node_modules boundary.
59
+ if (requested.split(path.sep).includes("node_modules"))
60
+ continue;
61
+ try {
62
+ visit(item.kind === "require-call"
63
+ ? createRequire(file).resolve(requested)
64
+ : Bun.resolveSync(requested, path.dirname(file)), local.search);
65
+ }
66
+ catch {
67
+ // A missing local dependency may appear on the next save. Leave its
68
+ // actual failure (or optional fallback) to the native loader.
69
+ track(path.dirname(requested), true);
70
+ }
71
+ }
72
+ };
73
+ visit(root);
74
+ return { version: String(++generation), load: () => Host.load(entrypoint) };
75
+ }
@@ -0,0 +1,8 @@
1
+ export declare function createPluginSources(watch: (file: string) => Promise<void>): {
2
+ read: (entrypoint: string) => Promise<{
3
+ version: string;
4
+ module: unknown;
5
+ }>;
6
+ dispose: () => void;
7
+ };
8
+ export declare function localSource(spec: string, directory: string): URL | undefined;
package/dist/source.js ADDED
@@ -0,0 +1,59 @@
1
+ import { readFileSync, readdirSync } from "node:fs";
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
+ import path from "node:path";
4
+ import { Hash } from "@radheim/util/hash";
5
+ // Keep source fingerprints and import attempts together. Filesystem events
6
+ // should reload changed local graphs, not repeat unchanged evaluations.
7
+ export function createPluginSources(watch) {
8
+ const sources = new Map();
9
+ const cleanups = [];
10
+ const watching = new Set();
11
+ return {
12
+ read: async (entrypoint) => {
13
+ await Promise.all(watching);
14
+ const previous = sources.get(entrypoint);
15
+ if (previous && [...previous.files].every(([file, item]) => item.digest === digest(file, item.directory)))
16
+ return previous.loaded;
17
+ const files = new Map();
18
+ const track = (file, directory = false) => {
19
+ if (files.has(file))
20
+ return;
21
+ files.set(file, { digest: digest(file, directory), directory });
22
+ const pending = watch(file).finally(() => watching.delete(pending));
23
+ watching.add(pending);
24
+ // Watch setup can be interrupted while module evaluation is still pending.
25
+ void pending.catch(() => { });
26
+ };
27
+ track(fileURLToPath(entrypoint));
28
+ const { prepareSource } = await import("#plugin-source");
29
+ const prepared = await prepareSource(entrypoint, track);
30
+ if (prepared.dispose)
31
+ cleanups.push(prepared.dispose);
32
+ // Cache the attempt before evaluating it: unchanged failing modules must
33
+ // not repeat import-time effects on every filesystem notification.
34
+ const loaded = prepared.load().then((module) => ({ version: prepared.version, module }));
35
+ sources.set(entrypoint, { loaded, files });
36
+ return loaded.finally(() => Promise.all(watching));
37
+ },
38
+ dispose: () => {
39
+ for (const cleanup of cleanups.splice(0))
40
+ cleanup();
41
+ sources.clear();
42
+ },
43
+ };
44
+ }
45
+ function digest(file, directory) {
46
+ try {
47
+ return Hash.sha256(directory ? JSON.stringify(readdirSync(file).sort()) : readFileSync(file));
48
+ }
49
+ catch {
50
+ return "missing";
51
+ }
52
+ }
53
+ export function localSource(spec, directory) {
54
+ if (spec.startsWith("file://"))
55
+ return new URL(spec);
56
+ if (spec.startsWith("./") || spec.startsWith("../") || path.isAbsolute(spec))
57
+ return pathToFileURL(path.resolve(directory, spec));
58
+ return undefined;
59
+ }
@@ -0,0 +1,5 @@
1
+ export declare function prepareSource(entrypoint: string, track: (file: string, directory?: boolean) => void): Promise<{
2
+ version: string;
3
+ load: () => Promise<unknown>;
4
+ dispose: () => void;
5
+ }>;
@@ -0,0 +1,55 @@
1
+ import { registerHooks } from "node:module";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { localSource } from "./source.js";
5
+ import { missingPackageTarget } from "./source.package.js";
6
+ import { Host } from "./host.js";
7
+ let generation = Date.now();
8
+ export async function prepareSource(entrypoint, track) {
9
+ const version = String(++generation);
10
+ const fresh = (specifier) => {
11
+ const url = new URL(specifier);
12
+ url.searchParams.set("__opencode_reload", version);
13
+ return url.href;
14
+ };
15
+ const hook = registerHooks({
16
+ resolve(specifier, context, nextResolve) {
17
+ if (!context.parentURL || new URL(context.parentURL).searchParams.get("__opencode_reload") !== version)
18
+ return nextResolve(specifier, context);
19
+ const local = specifier.startsWith("./") || specifier.startsWith("../")
20
+ ? new URL(specifier, context.parentURL)
21
+ : localSource(specifier, path.dirname(fileURLToPath(context.parentURL)));
22
+ if (!local) {
23
+ try {
24
+ return nextResolve(specifier, context);
25
+ }
26
+ catch (error) {
27
+ const target = missingPackageTarget(specifier, fileURLToPath(context.parentURL));
28
+ if (target)
29
+ track(target, true);
30
+ throw error;
31
+ }
32
+ }
33
+ if (fileURLToPath(local).split(path.sep).includes("node_modules"))
34
+ return nextResolve(specifier, context);
35
+ const resolved = (() => {
36
+ try {
37
+ return nextResolve(specifier, context);
38
+ }
39
+ catch (error) {
40
+ track(path.dirname(fileURLToPath(local)), true);
41
+ throw error;
42
+ }
43
+ })();
44
+ if (!resolved.url.startsWith("file:"))
45
+ return resolved;
46
+ const file = fileURLToPath(resolved.url);
47
+ if (file.split(path.sep).includes("node_modules"))
48
+ return resolved;
49
+ track(file);
50
+ return { ...resolved, url: fresh(resolved.url) };
51
+ },
52
+ });
53
+ const specifier = fresh(entrypoint);
54
+ return { version: specifier, load: () => Host.load(specifier), dispose: () => hook.deregister() };
55
+ }
@@ -0,0 +1 @@
1
+ export declare function missingPackageTarget(specifier: string, importer: string): string | undefined;
@@ -0,0 +1,15 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ export function missingPackageTarget(specifier, importer) {
4
+ if (specifier.startsWith("#"))
5
+ return undefined;
6
+ const parts = specifier.split("/");
7
+ const name = specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
8
+ const start = path.dirname(importer);
9
+ for (let directory = start;; directory = path.dirname(directory)) {
10
+ if (existsSync(path.join(directory, "package.json")))
11
+ return path.join(directory, "node_modules", name);
12
+ if (path.dirname(directory) === directory)
13
+ return path.join(start, "node_modules", name);
14
+ }
15
+ }
@@ -0,0 +1,14 @@
1
+ import type { Schema } from "effect";
2
+ export interface StorageEntry {
3
+ readonly key: string;
4
+ readonly value: Schema.Json;
5
+ }
6
+ export interface StorageScanOptions {
7
+ readonly prefix: string;
8
+ readonly after?: string;
9
+ readonly limit?: number;
10
+ }
11
+ export interface StorageScanResult {
12
+ readonly entries: readonly StorageEntry[];
13
+ readonly next?: string;
14
+ }
File without changes