@rebon/cli-win32-x64 1.3.0 → 1.5.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.
Files changed (91) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +10 -0
  3. package/README.md +239 -144
  4. package/THIRD_PARTY_NOTICES.txt +1232 -1232
  5. package/bin/rebon.js +22 -22
  6. package/lib/windows-managed.js +390 -390
  7. package/package.json +9 -2
  8. package/payload/compose-runtime/package.json +17 -17
  9. package/payload/compose-runtime/payload/compose/shims/dsh-anonymous-user-id.js +10 -10
  10. package/payload/compose-runtime/payload/compose/shims/dsh-credentials.js +13 -13
  11. package/payload/compose-runtime/payload/compose/shims/dsh-launch-environment.js +21 -21
  12. package/payload/compose-runtime/payload/compose/shims/dsh-llm.js +313 -313
  13. package/payload/compose-runtime/payload/compose/shims/dsh-settings.js +43 -43
  14. package/payload/compose-runtime/payload/compose/shims/dsh-tools.js +20 -20
  15. package/payload/compose-runtime/payload/compose/shims/dsh-web.js +10 -10
  16. package/payload/compose-runtime/payload/compose/shims/llm-adapter.js +32 -32
  17. package/payload/compose-runtime/payload/compose/shims/zod-lite.js +49 -49
  18. package/payload/compose-runtime/payload/vendor/cordis/LICENSE +21 -21
  19. package/payload/compose-runtime/payload/vendor/cordis/index.js +1530 -1530
  20. package/payload/compose-runtime/payload/vendor/cosmokit/LICENSE +21 -21
  21. package/payload/compose-runtime/payload/vendor/cosmokit/index.mjs +357 -357
  22. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-agent +21 -21
  23. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-agent-loop +21 -21
  24. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-llm-core +21 -21
  25. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-llm-deepseek +21 -21
  26. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-logger-console +21 -21
  27. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-scope +21 -21
  28. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-session +21 -21
  29. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-system-prompt +21 -21
  30. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-timeout +21 -21
  31. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-timer +21 -21
  32. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-tool-todo +21 -21
  33. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-tool-web +21 -21
  34. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-tools-schema +21 -21
  35. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-turndown +21 -21
  36. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-turndown-plugin-gfm +21 -21
  37. package/payload/compose-runtime/payload/vendor/dsh/LICENSE-web-search-exa +21 -21
  38. package/payload/compose-runtime/payload/vendor/dsh/agent-loop.js +1193 -1193
  39. package/payload/compose-runtime/payload/vendor/dsh/agent.js +714 -714
  40. package/payload/compose-runtime/payload/vendor/dsh/llm-core.js +269 -269
  41. package/payload/compose-runtime/payload/vendor/dsh/llm-deepseek.js +672 -672
  42. package/payload/compose-runtime/payload/vendor/dsh/logger-console.js +83 -83
  43. package/payload/compose-runtime/payload/vendor/dsh/scope.js +287 -287
  44. package/payload/compose-runtime/payload/vendor/dsh/session.js +1668 -1668
  45. package/payload/compose-runtime/payload/vendor/dsh/system-prompt.js +309 -309
  46. package/payload/compose-runtime/payload/vendor/dsh/timeout.js +100 -100
  47. package/payload/compose-runtime/payload/vendor/dsh/timer.js +128 -128
  48. package/payload/compose-runtime/payload/vendor/dsh/tool-todo.js +143 -143
  49. package/payload/compose-runtime/payload/vendor/dsh/tool-web.js +1527 -1527
  50. package/payload/compose-runtime/payload/vendor/dsh/tools-schema.js +849 -849
  51. package/payload/compose-runtime/payload/vendor/dsh/web-search-exa.js +122 -122
  52. package/payload/compose-runtime/payload/vendor/eventsource-parser/LICENSE +21 -21
  53. package/payload/compose-runtime/payload/vendor/eventsource-parser/index.js +177 -177
  54. package/payload/compose-runtime/payload/vendor/eventsource-parser/stream.js +48 -48
  55. package/payload/compose-runtime/payload/vendor/schemastery/LICENSE +21 -21
  56. package/payload/compose-runtime/payload/vendor/schemastery/index.mjs +656 -656
  57. package/payload/compose-runtime/payload-manifests.json +48 -48
  58. package/payload/compose-runtime/src/bridge.mjs +193 -195
  59. package/payload/compose-runtime/src/credentials-runtime.mjs +50 -50
  60. package/payload/compose-runtime/src/eventsource-stream.mjs +48 -48
  61. package/payload/compose-runtime/src/index.mjs +7 -7
  62. package/payload/compose-runtime/src/llm-runtime.mjs +326 -326
  63. package/payload/compose-runtime/src/loader.mjs +78 -78
  64. package/payload/compose-runtime/src/loop-assembly.mjs +237 -237
  65. package/payload/compose-runtime/src/payload.mjs +49 -49
  66. package/payload/compose-runtime/src/plugin.mjs +59 -59
  67. package/payload/compose-runtime/src/realm.mjs +223 -223
  68. package/payload/compose-runtime/src/registry.mjs +191 -191
  69. package/payload/compose-runtime/src/resolve.mjs +115 -115
  70. package/payload/compose-runtime/src/systemprompt-runtime.mjs +67 -67
  71. package/payload/compose-runtime/src/tools-runtime.mjs +239 -239
  72. package/payload/compose-runtime/src/web-runtime.mjs +209 -209
  73. package/payload/plugin-host/package.json +11 -11
  74. package/payload/plugin-host/src/bridge.mjs +64 -64
  75. package/payload/plugin-host/src/cli.mjs +147 -147
  76. package/payload/plugin-host/src/framing.mjs +113 -113
  77. package/payload/plugin-host/src/host.mjs +691 -691
  78. package/payload/plugin-host/src/json.mjs +208 -208
  79. package/payload/plugin-host/src/lifecycle.mjs +114 -114
  80. package/payload/plugin-host/src/loader.mjs +183 -183
  81. package/payload/plugin-host/src/methods.mjs +377 -377
  82. package/payload/plugin-host/src/ownership.mjs +57 -57
  83. package/payload/plugin-host/src/protocol.mjs +129 -129
  84. package/payload/plugin-host/src/sdk.mjs +7 -7
  85. package/payload/rebon-boa-helper.exe +0 -0
  86. package/payload/rebon-browser-mcp.exe +0 -0
  87. package/payload/rebon-computer-use.exe +0 -0
  88. package/payload/rebon-lsp-mcp.exe +0 -0
  89. package/payload/rebon.exe +2 -2
  90. package/payload/sandbox-win.exe +0 -0
  91. package/scripts/postinstall.js +112 -112
@@ -1,191 +1,191 @@
1
- // What one Cordis entry registered, captured while it mounts.
2
- //
3
- // A Cordis plugin does not know the plugin plane exists: it calls
4
- // `ctx.tools.register(...)`, `ctx.llm.registerAdapter(...)`,
5
- // `ctx.systemPrompt.section(...)`, and the seats it calls are the ones that
6
- // have to turn those into something `plugin/load` can answer with. This is
7
- // where they put it.
8
- //
9
- // The sink reaches a seat through the registering context — `ctx[SINK]`, set
10
- // when the entry's context is derived — for the same reason the old ledger's
11
- // owner stamp did: it is read synchronously at registration time, so an async
12
- // interleaving cannot attribute one plugin's registration to another.
13
- //
14
- // Two rules it enforces, both borrowed from the host's own registrar because a
15
- // composition entry is a plugin and should not get a weaker contract:
16
- //
17
- // * **Declared first.** A registration the load request did not declare is
18
- // refused where the plugin made it, rather than arriving later as a ready
19
- // report rebon has to reject.
20
- // * **Registration closes.** Once the entry's fiber has resolved, the host
21
- // has already been told what this plugin provides; a later registration
22
- // would be a capability nothing downstream knows about.
23
-
24
- /** The key an entry's context carries its sink under. */
25
- export const SINK = Symbol.for('rebon.composeSink');
26
- /** The key an entry's context carries its plugin id under. */
27
- export const OWNER = Symbol.for('rebon.composeOwner');
28
-
29
- class RegistrationError extends Error {
30
- constructor(code, message) {
31
- super(message);
32
- this.code = code;
33
- this.name = 'RegistrationError';
34
- }
35
- }
36
-
37
- export class RegistrationSink {
38
- #sealed = false;
39
-
40
- constructor(pluginId, declared = {}) {
41
- this.pluginId = pluginId;
42
- this.declared = {
43
- services: new Set(declared.services ?? []),
44
- eventTopics: new Set(declared.eventTopics ?? []),
45
- llmProviders: new Set(declared.llmProviders ?? []),
46
- tools: new Set(declared.tools ?? []),
47
- };
48
- /** Protocol-shaped registrations, answered by `plugin/load`. */
49
- this.services = new Map();
50
- this.topics = new Map();
51
- this.llmProviders = new Map();
52
- this.tools = new Map();
53
- /** Handles on a session, handed out when a scope opens. */
54
- this.scopeHandlers = [];
55
- /** The sessions this plugin is currently attached to.
56
- *
57
- * Every entry gets one of these, not just the ones that ask: it is how a
58
- * seat reaches rebon on behalf of code running outside any inbound call.
59
- * An agent loop drives its own turn, and the adapter it reaches for a
60
- * credential is running on the loop's schedule rather than answering
61
- * anything — but it is still that plugin's code, in that session, and the
62
- * call it makes should say so. */
63
- this.sessions = new Set();
64
- this.scopeHandlers.push((scopeCtx) => {
65
- this.sessions.add(scopeCtx);
66
- return () => this.sessions.delete(scopeCtx);
67
- });
68
- /** Facts with no protocol counterpart, fetched from the `compose` service. */
69
- this.sections = [];
70
- this.catalogs = new Map();
71
- this.webProviders = [];
72
- }
73
-
74
- #admit(kind, name, declared) {
75
- if (this.#sealed) {
76
- throw new RegistrationError(
77
- '[REGISTRATION_CLOSED]',
78
- `${kind} ${JSON.stringify(name)} was registered after ${this.pluginId} finished loading`,
79
- );
80
- }
81
- if (typeof name !== 'string' || name.length === 0) {
82
- throw new RegistrationError('[WRONG_SHAPE]', `a ${kind} needs a non-empty name`);
83
- }
84
- if (!declared.has(name)) {
85
- throw new RegistrationError(
86
- '[UNAUTHORIZED_REGISTER]',
87
- `${kind} ${JSON.stringify(name)} is not declared by ${this.pluginId}'s manifest`,
88
- );
89
- }
90
- }
91
-
92
- service(name, handler) {
93
- this.#admit('service', name, this.declared.services);
94
- this.services.set(name, handler);
95
- }
96
-
97
- topic(name, handler) {
98
- this.#admit('topic', name, this.declared.eventTopics);
99
- this.topics.set(name, handler);
100
- }
101
-
102
- llm(provider, handler) {
103
- this.#admit('provider', provider, this.declared.llmProviders);
104
- this.llmProviders.set(provider, handler);
105
- }
106
-
107
- tool(definition, handler) {
108
- this.#admit('tool', definition?.name, this.declared.tools);
109
- this.tools.set(definition.name, { definition, handler });
110
- }
111
-
112
- /// A handle on the session, for a plugin that acts rather than only answers.
113
- ///
114
- /// Not declared, because it is not a capability: every power the handle
115
- /// carries is one of the declarations above, checked when it is used.
116
- scope(handler) {
117
- if (typeof handler !== 'function') {
118
- throw new RegistrationError('[WRONG_SHAPE]', 'a scope handler must be a function');
119
- }
120
- this.scopeHandlers.push(handler);
121
- }
122
-
123
- // ---- extras ----------------------------------------------------------
124
- //
125
- // A model catalog, a prompt section and a web provider are things rebon
126
- // needs and the protocol has no field for. They are reported by the
127
- // composition's own `compose` service rather than by widening the ready
128
- // report, which every plugin shares and only this one would use.
129
-
130
- section(entry) {
131
- this.sections.push(entry);
132
- }
133
-
134
- catalog(provider, catalog) {
135
- this.catalogs.set(provider, catalog);
136
- }
137
-
138
- webProvider(kind, id, available) {
139
- this.webProviders.push({ kind, id, available });
140
- }
141
-
142
- /// Closes registration and hands back what the host asked for.
143
- seal() {
144
- this.#sealed = true;
145
- return this;
146
- }
147
-
148
- /// The `plugin/load` answer, in the shape the host's own loader produces.
149
- loaded() {
150
- return {
151
- services: [...this.services.keys()],
152
- eventTopics: [...this.topics.keys()],
153
- llmProviders: [...this.llmProviders.keys()],
154
- tools: [...this.tools.values()].map((entry) => entry.definition),
155
- serviceHandlers: this.services,
156
- topicHandlers: this.topics,
157
- llmAdapters: this.llmProviders,
158
- toolHandlers: new Map([...this.tools].map(([name, entry]) => [name, entry.handler])),
159
- scopeHandlers: [...this.scopeHandlers],
160
- };
161
- }
162
-
163
- /// What the `compose` service reports for this plugin.
164
- report() {
165
- return {
166
- sections: this.sections.map((section) => ({ ...section })),
167
- providers: [...this.catalogs].map(([provider, catalog]) => ({ provider, ...catalog })),
168
- webProviders: this.webProviders.map((entry) => ({ ...entry })),
169
- };
170
- }
171
- }
172
-
173
- /// The session this plugin is attached to, if it is attached to one.
174
- ///
175
- /// With more than one open, the first is used: a plugin acting on its own
176
- /// schedule is acting in one session, and which one is a fact about how rebon
177
- /// opened them rather than something guessable here.
178
- export function sessionOf(ctx) {
179
- const sink = ctx?.[SINK];
180
- if (sink === undefined) return undefined;
181
- for (const session of sink.sessions) return session;
182
- return undefined;
183
- }
184
-
185
- /// The sink the code currently registering belongs to, or undefined.
186
- ///
187
- /// Undefined is normal: the built-in seats mount into the realm itself, and a
188
- /// seat calling another seat is not a registration by any plugin.
189
- export function sinkOf(ctx) {
190
- return ctx?.[SINK];
191
- }
1
+ // What one Cordis entry registered, captured while it mounts.
2
+ //
3
+ // A Cordis plugin does not know the plugin plane exists: it calls
4
+ // `ctx.tools.register(...)`, `ctx.llm.registerAdapter(...)`,
5
+ // `ctx.systemPrompt.section(...)`, and the seats it calls are the ones that
6
+ // have to turn those into something `plugin/load` can answer with. This is
7
+ // where they put it.
8
+ //
9
+ // The sink reaches a seat through the registering context — `ctx[SINK]`, set
10
+ // when the entry's context is derived — for the same reason the old ledger's
11
+ // owner stamp did: it is read synchronously at registration time, so an async
12
+ // interleaving cannot attribute one plugin's registration to another.
13
+ //
14
+ // Two rules it enforces, both borrowed from the host's own registrar because a
15
+ // composition entry is a plugin and should not get a weaker contract:
16
+ //
17
+ // * **Declared first.** A registration the load request did not declare is
18
+ // refused where the plugin made it, rather than arriving later as a ready
19
+ // report rebon has to reject.
20
+ // * **Registration closes.** Once the entry's fiber has resolved, the host
21
+ // has already been told what this plugin provides; a later registration
22
+ // would be a capability nothing downstream knows about.
23
+
24
+ /** The key an entry's context carries its sink under. */
25
+ export const SINK = Symbol.for('rebon.composeSink');
26
+ /** The key an entry's context carries its plugin id under. */
27
+ export const OWNER = Symbol.for('rebon.composeOwner');
28
+
29
+ class RegistrationError extends Error {
30
+ constructor(code, message) {
31
+ super(message);
32
+ this.code = code;
33
+ this.name = 'RegistrationError';
34
+ }
35
+ }
36
+
37
+ export class RegistrationSink {
38
+ #sealed = false;
39
+
40
+ constructor(pluginId, declared = {}) {
41
+ this.pluginId = pluginId;
42
+ this.declared = {
43
+ services: new Set(declared.services ?? []),
44
+ eventTopics: new Set(declared.eventTopics ?? []),
45
+ llmProviders: new Set(declared.llmProviders ?? []),
46
+ tools: new Set(declared.tools ?? []),
47
+ };
48
+ /** Protocol-shaped registrations, answered by `plugin/load`. */
49
+ this.services = new Map();
50
+ this.topics = new Map();
51
+ this.llmProviders = new Map();
52
+ this.tools = new Map();
53
+ /** Handles on a session, handed out when a scope opens. */
54
+ this.scopeHandlers = [];
55
+ /** The sessions this plugin is currently attached to.
56
+ *
57
+ * Every entry gets one of these, not just the ones that ask: it is how a
58
+ * seat reaches rebon on behalf of code running outside any inbound call.
59
+ * An agent loop drives its own turn, and the adapter it reaches for a
60
+ * credential is running on the loop's schedule rather than answering
61
+ * anything — but it is still that plugin's code, in that session, and the
62
+ * call it makes should say so. */
63
+ this.sessions = new Set();
64
+ this.scopeHandlers.push((scopeCtx) => {
65
+ this.sessions.add(scopeCtx);
66
+ return () => this.sessions.delete(scopeCtx);
67
+ });
68
+ /** Facts with no protocol counterpart, fetched from the `compose` service. */
69
+ this.sections = [];
70
+ this.catalogs = new Map();
71
+ this.webProviders = [];
72
+ }
73
+
74
+ #admit(kind, name, declared) {
75
+ if (this.#sealed) {
76
+ throw new RegistrationError(
77
+ '[REGISTRATION_CLOSED]',
78
+ `${kind} ${JSON.stringify(name)} was registered after ${this.pluginId} finished loading`,
79
+ );
80
+ }
81
+ if (typeof name !== 'string' || name.length === 0) {
82
+ throw new RegistrationError('[WRONG_SHAPE]', `a ${kind} needs a non-empty name`);
83
+ }
84
+ if (!declared.has(name)) {
85
+ throw new RegistrationError(
86
+ '[UNAUTHORIZED_REGISTER]',
87
+ `${kind} ${JSON.stringify(name)} is not declared by ${this.pluginId}'s manifest`,
88
+ );
89
+ }
90
+ }
91
+
92
+ service(name, handler) {
93
+ this.#admit('service', name, this.declared.services);
94
+ this.services.set(name, handler);
95
+ }
96
+
97
+ topic(name, handler) {
98
+ this.#admit('topic', name, this.declared.eventTopics);
99
+ this.topics.set(name, handler);
100
+ }
101
+
102
+ llm(provider, handler) {
103
+ this.#admit('provider', provider, this.declared.llmProviders);
104
+ this.llmProviders.set(provider, handler);
105
+ }
106
+
107
+ tool(definition, handler) {
108
+ this.#admit('tool', definition?.name, this.declared.tools);
109
+ this.tools.set(definition.name, { definition, handler });
110
+ }
111
+
112
+ /// A handle on the session, for a plugin that acts rather than only answers.
113
+ ///
114
+ /// Not declared, because it is not a capability: every power the handle
115
+ /// carries is one of the declarations above, checked when it is used.
116
+ scope(handler) {
117
+ if (typeof handler !== 'function') {
118
+ throw new RegistrationError('[WRONG_SHAPE]', 'a scope handler must be a function');
119
+ }
120
+ this.scopeHandlers.push(handler);
121
+ }
122
+
123
+ // ---- extras ----------------------------------------------------------
124
+ //
125
+ // A model catalog, a prompt section and a web provider are things rebon
126
+ // needs and the protocol has no field for. They are reported by the
127
+ // composition's own `compose` service rather than by widening the ready
128
+ // report, which every plugin shares and only this one would use.
129
+
130
+ section(entry) {
131
+ this.sections.push(entry);
132
+ }
133
+
134
+ catalog(provider, catalog) {
135
+ this.catalogs.set(provider, catalog);
136
+ }
137
+
138
+ webProvider(kind, id, available) {
139
+ this.webProviders.push({ kind, id, available });
140
+ }
141
+
142
+ /// Closes registration and hands back what the host asked for.
143
+ seal() {
144
+ this.#sealed = true;
145
+ return this;
146
+ }
147
+
148
+ /// The `plugin/load` answer, in the shape the host's own loader produces.
149
+ loaded() {
150
+ return {
151
+ services: [...this.services.keys()],
152
+ eventTopics: [...this.topics.keys()],
153
+ llmProviders: [...this.llmProviders.keys()],
154
+ tools: [...this.tools.values()].map((entry) => entry.definition),
155
+ serviceHandlers: this.services,
156
+ topicHandlers: this.topics,
157
+ llmAdapters: this.llmProviders,
158
+ toolHandlers: new Map([...this.tools].map(([name, entry]) => [name, entry.handler])),
159
+ scopeHandlers: [...this.scopeHandlers],
160
+ };
161
+ }
162
+
163
+ /// What the `compose` service reports for this plugin.
164
+ report() {
165
+ return {
166
+ sections: this.sections.map((section) => ({ ...section })),
167
+ providers: [...this.catalogs].map(([provider, catalog]) => ({ provider, ...catalog })),
168
+ webProviders: this.webProviders.map((entry) => ({ ...entry })),
169
+ };
170
+ }
171
+ }
172
+
173
+ /// The session this plugin is attached to, if it is attached to one.
174
+ ///
175
+ /// With more than one open, the first is used: a plugin acting on its own
176
+ /// schedule is acting in one session, and which one is a fact about how rebon
177
+ /// opened them rather than something guessable here.
178
+ export function sessionOf(ctx) {
179
+ const sink = ctx?.[SINK];
180
+ if (sink === undefined) return undefined;
181
+ for (const session of sink.sessions) return session;
182
+ return undefined;
183
+ }
184
+
185
+ /// The sink the code currently registering belongs to, or undefined.
186
+ ///
187
+ /// Undefined is normal: the built-in seats mount into the realm itself, and a
188
+ /// seat calling another seat is not a registration by any plugin.
189
+ export function sinkOf(ctx) {
190
+ return ctx?.[SINK];
191
+ }
@@ -1,115 +1,115 @@
1
- // Module resolution for the composition, on real Node.
2
- //
3
- // Node has no import map, but it has `module.registerHooks()` — synchronous,
4
- // in-thread resolve/load hooks — and this is the composition's map written in
5
- // that vocabulary. There used to be a second map, in the deno_core host's
6
- // `build_import_map`, and a test here holding the two to the same specifier
7
- // set; that host is gone, so this is the only map there is.
8
- //
9
- // Two entries it does not carry, both from the deleted one and both in the
10
- // direction of deleting code:
11
- //
12
- // * the four `node:` entries. `node:async_hooks`, `node:util/types`,
13
- // `node:path` and `node:crypto` resolved to hand-written shims because bare
14
- // deno_core has no standard library; real Node has all four.
15
- // * `eventsource-parser/stream` resolves to this package's module rather than
16
- // the vendored one. The vendored build is not the published package: it was
17
- // rewritten against the "Mini streams" protocol the old host installed,
18
- // because the published `EventSourceParserStream` extends the WHATWG
19
- // `TransformStream` and bare deno_core has none. On real Node that
20
- // rewrite breaks — `body.pipeThrough(new EventSourceParserStream())` throws
21
- // `ERR_INVALID_ARG_TYPE` — so the upstream shape comes back. See
22
- // `eventsource-stream.mjs`.
23
- import { registerHooks } from 'node:module';
24
- import path from 'node:path';
25
- import { pathToFileURL } from 'node:url';
26
- import { payloadDir } from './payload.mjs';
27
-
28
- /// Payload-relative module map, keyed by bare specifier.
29
- ///
30
- /// Mirrors `build_import_map` entry for entry, minus the `node:` shims.
31
- export function payloadModules(dir) {
32
- const at = (relative) => pathToFileURL(path.join(dir, relative)).href;
33
- return new Map(Object.entries({
34
- cordis: at('vendor/cordis/index.js'),
35
- cosmokit: at('vendor/cosmokit/index.mjs'),
36
- schemastery: at('vendor/schemastery/index.mjs'),
37
- '@deepseek-ai/cordis': at('vendor/cordis/index.js'),
38
- '@deepseek-ai/cosmokit': at('vendor/cosmokit/index.mjs'),
39
- '@deepseek-ai/schemastery': at('vendor/schemastery/index.mjs'),
40
- '@deepseek-ai/cordis-plugin-timer': at('vendor/dsh/timer.js'),
41
- '@deepseek-ai/cordis-plugin-logger-console': at('vendor/dsh/logger-console.js'),
42
- '@deepseek-ai/dsh-llm-deepseek': at('vendor/dsh/llm-deepseek.js'),
43
- '@deepseek-ai/dsh-timeout': at('vendor/dsh/timeout.js'),
44
- '@deepseek-ai/dsh-llm': at('compose/shims/dsh-llm.js'),
45
- '@deepseek-ai/dsh-credentials': at('compose/shims/dsh-credentials.js'),
46
- '@deepseek-ai/dsh-settings': at('compose/shims/dsh-settings.js'),
47
- '@deepseek-ai/dsh-launch-environment': at('compose/shims/dsh-launch-environment.js'),
48
- '@deepseek-ai/dsh-anonymous-user-id': at('compose/shims/dsh-anonymous-user-id.js'),
49
- 'eventsource-parser': at('vendor/eventsource-parser/index.js'),
50
- '@deepseek-ai/dsh-tools': at('compose/shims/dsh-tools.js'),
51
- '@deepseek-ai/dsh-tool-todo': at('vendor/dsh/tool-todo.js'),
52
- zod: at('compose/shims/zod-lite.js'),
53
- '@deepseek-ai/dsh-web': at('compose/shims/dsh-web.js'),
54
- '@deepseek-ai/dsh-web-search-exa': at('vendor/dsh/web-search-exa.js'),
55
- '@deepseek-ai/dsh-tool-web': at('vendor/dsh/tool-web.js'),
56
- '@deepseek-ai/dsh-scope': at('vendor/dsh/scope.js'),
57
- '@deepseek-ai/dsh-session': at('vendor/dsh/session.js'),
58
- '@deepseek-ai/dsh-agent': at('vendor/dsh/agent.js'),
59
- '@deepseek-ai/dsh-system-prompt': at('vendor/dsh/system-prompt.js'),
60
- '@deepseek-ai/dsh-agent-loop': at('vendor/dsh/agent-loop.js'),
61
- }));
62
- }
63
-
64
- /// Specifiers this package answers itself rather than from the payload.
65
- export function localModules() {
66
- const at = (relative) => new URL(relative, import.meta.url).href;
67
- return new Map(Object.entries({
68
- rebon: at('./bridge.mjs'),
69
- 'eventsource-parser/stream': at('./eventsource-stream.mjs'),
70
- }));
71
- }
72
-
73
- let installed;
74
-
75
- /// Installs the composition's module resolution, once per process.
76
- ///
77
- /// `extraModules` is the embedder's own map (the `modules` half of a
78
- /// composition config: plugin name → absolute module file), which is how a
79
- /// plugin outside the vendored payload gets a name.
80
- ///
81
- /// Returns the resolved map so callers can report what a specifier became
82
- /// without repeating the lookup rules.
83
- export function installModuleResolution({ dir = payloadDir(), extraModules = {} } = {}) {
84
- const map = new Map([...payloadModules(dir), ...localModules()]);
85
- for (const [name, file] of Object.entries(extraModules)) {
86
- map.set(name, pathToFileURL(path.resolve(file)).href);
87
- }
88
- if (installed) {
89
- // Hooks are process-wide and cannot be unregistered per call; re-running
90
- // with a different map would leave two resolvers disagreeing about the
91
- // same specifier, which is a debugging trap rather than a feature.
92
- for (const [name, url] of map) installed.map.set(name, url);
93
- return installed.map;
94
- }
95
-
96
- const payloadPrefix = pathToFileURL(dir.endsWith(path.sep) ? dir : dir + path.sep).href;
97
- const state = { map };
98
- registerHooks({
99
- resolve(specifier, context, next) {
100
- const mapped = state.map.get(specifier);
101
- if (mapped !== undefined) return { url: mapped, format: 'module', shortCircuit: true };
102
- return next(specifier, context);
103
- },
104
- // The payload's ESM is `.js` under no `package.json`, so Node's own rules
105
- // read it as CommonJS and every `import` in it is a syntax error. The
106
- // deno_core loader had no such ambiguity — everything it loaded was a
107
- // module — so this is a fact about Node, not about the payload.
108
- load(url, context, next) {
109
- if (url.startsWith(payloadPrefix)) return next(url, { ...context, format: 'module' });
110
- return next(url, context);
111
- },
112
- });
113
- installed = state;
114
- return state.map;
115
- }
1
+ // Module resolution for the composition, on real Node.
2
+ //
3
+ // Node has no import map, but it has `module.registerHooks()` — synchronous,
4
+ // in-thread resolve/load hooks — and this is the composition's map written in
5
+ // that vocabulary. There used to be a second map, in the deno_core host's
6
+ // `build_import_map`, and a test here holding the two to the same specifier
7
+ // set; that host is gone, so this is the only map there is.
8
+ //
9
+ // Two entries it does not carry, both from the deleted one and both in the
10
+ // direction of deleting code:
11
+ //
12
+ // * the four `node:` entries. `node:async_hooks`, `node:util/types`,
13
+ // `node:path` and `node:crypto` resolved to hand-written shims because bare
14
+ // deno_core has no standard library; real Node has all four.
15
+ // * `eventsource-parser/stream` resolves to this package's module rather than
16
+ // the vendored one. The vendored build is not the published package: it was
17
+ // rewritten against the "Mini streams" protocol the old host installed,
18
+ // because the published `EventSourceParserStream` extends the WHATWG
19
+ // `TransformStream` and bare deno_core has none. On real Node that
20
+ // rewrite breaks — `body.pipeThrough(new EventSourceParserStream())` throws
21
+ // `ERR_INVALID_ARG_TYPE` — so the upstream shape comes back. See
22
+ // `eventsource-stream.mjs`.
23
+ import { registerHooks } from 'node:module';
24
+ import path from 'node:path';
25
+ import { pathToFileURL } from 'node:url';
26
+ import { payloadDir } from './payload.mjs';
27
+
28
+ /// Payload-relative module map, keyed by bare specifier.
29
+ ///
30
+ /// Mirrors `build_import_map` entry for entry, minus the `node:` shims.
31
+ export function payloadModules(dir) {
32
+ const at = (relative) => pathToFileURL(path.join(dir, relative)).href;
33
+ return new Map(Object.entries({
34
+ cordis: at('vendor/cordis/index.js'),
35
+ cosmokit: at('vendor/cosmokit/index.mjs'),
36
+ schemastery: at('vendor/schemastery/index.mjs'),
37
+ '@deepseek-ai/cordis': at('vendor/cordis/index.js'),
38
+ '@deepseek-ai/cosmokit': at('vendor/cosmokit/index.mjs'),
39
+ '@deepseek-ai/schemastery': at('vendor/schemastery/index.mjs'),
40
+ '@deepseek-ai/cordis-plugin-timer': at('vendor/dsh/timer.js'),
41
+ '@deepseek-ai/cordis-plugin-logger-console': at('vendor/dsh/logger-console.js'),
42
+ '@deepseek-ai/dsh-llm-deepseek': at('vendor/dsh/llm-deepseek.js'),
43
+ '@deepseek-ai/dsh-timeout': at('vendor/dsh/timeout.js'),
44
+ '@deepseek-ai/dsh-llm': at('compose/shims/dsh-llm.js'),
45
+ '@deepseek-ai/dsh-credentials': at('compose/shims/dsh-credentials.js'),
46
+ '@deepseek-ai/dsh-settings': at('compose/shims/dsh-settings.js'),
47
+ '@deepseek-ai/dsh-launch-environment': at('compose/shims/dsh-launch-environment.js'),
48
+ '@deepseek-ai/dsh-anonymous-user-id': at('compose/shims/dsh-anonymous-user-id.js'),
49
+ 'eventsource-parser': at('vendor/eventsource-parser/index.js'),
50
+ '@deepseek-ai/dsh-tools': at('compose/shims/dsh-tools.js'),
51
+ '@deepseek-ai/dsh-tool-todo': at('vendor/dsh/tool-todo.js'),
52
+ zod: at('compose/shims/zod-lite.js'),
53
+ '@deepseek-ai/dsh-web': at('compose/shims/dsh-web.js'),
54
+ '@deepseek-ai/dsh-web-search-exa': at('vendor/dsh/web-search-exa.js'),
55
+ '@deepseek-ai/dsh-tool-web': at('vendor/dsh/tool-web.js'),
56
+ '@deepseek-ai/dsh-scope': at('vendor/dsh/scope.js'),
57
+ '@deepseek-ai/dsh-session': at('vendor/dsh/session.js'),
58
+ '@deepseek-ai/dsh-agent': at('vendor/dsh/agent.js'),
59
+ '@deepseek-ai/dsh-system-prompt': at('vendor/dsh/system-prompt.js'),
60
+ '@deepseek-ai/dsh-agent-loop': at('vendor/dsh/agent-loop.js'),
61
+ }));
62
+ }
63
+
64
+ /// Specifiers this package answers itself rather than from the payload.
65
+ export function localModules() {
66
+ const at = (relative) => new URL(relative, import.meta.url).href;
67
+ return new Map(Object.entries({
68
+ rebon: at('./bridge.mjs'),
69
+ 'eventsource-parser/stream': at('./eventsource-stream.mjs'),
70
+ }));
71
+ }
72
+
73
+ let installed;
74
+
75
+ /// Installs the composition's module resolution, once per process.
76
+ ///
77
+ /// `extraModules` is the embedder's own map (the `modules` half of a
78
+ /// composition config: plugin name → absolute module file), which is how a
79
+ /// plugin outside the vendored payload gets a name.
80
+ ///
81
+ /// Returns the resolved map so callers can report what a specifier became
82
+ /// without repeating the lookup rules.
83
+ export function installModuleResolution({ dir = payloadDir(), extraModules = {} } = {}) {
84
+ const map = new Map([...payloadModules(dir), ...localModules()]);
85
+ for (const [name, file] of Object.entries(extraModules)) {
86
+ map.set(name, pathToFileURL(path.resolve(file)).href);
87
+ }
88
+ if (installed) {
89
+ // Hooks are process-wide and cannot be unregistered per call; re-running
90
+ // with a different map would leave two resolvers disagreeing about the
91
+ // same specifier, which is a debugging trap rather than a feature.
92
+ for (const [name, url] of map) installed.map.set(name, url);
93
+ return installed.map;
94
+ }
95
+
96
+ const payloadPrefix = pathToFileURL(dir.endsWith(path.sep) ? dir : dir + path.sep).href;
97
+ const state = { map };
98
+ registerHooks({
99
+ resolve(specifier, context, next) {
100
+ const mapped = state.map.get(specifier);
101
+ if (mapped !== undefined) return { url: mapped, format: 'module', shortCircuit: true };
102
+ return next(specifier, context);
103
+ },
104
+ // The payload's ESM is `.js` under no `package.json`, so Node's own rules
105
+ // read it as CommonJS and every `import` in it is a syntax error. The
106
+ // deno_core loader had no such ambiguity — everything it loaded was a
107
+ // module — so this is a fact about Node, not about the payload.
108
+ load(url, context, next) {
109
+ if (url.startsWith(payloadPrefix)) return next(url, { ...context, format: 'module' });
110
+ return next(url, context);
111
+ },
112
+ });
113
+ installed = state;
114
+ return state.map;
115
+ }