@saturn-universe/runtime-host 0.0.0-stage → 0.1.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 (116) hide show
  1. package/LICENSE +661 -0
  2. package/dist/builtin-plugins/saturn-plugin-ctf/README.md +13 -0
  3. package/dist/builtin-plugins/saturn-plugin-ctf/index.mjs +1473 -0
  4. package/dist/builtin-plugins/saturn-plugin-ctf/package.json +10 -0
  5. package/dist/builtin-plugins/saturn-plugin-ctf/src/board.mjs +321 -0
  6. package/dist/builtin-plugins/saturn-plugin-ctf/src/ledger.mjs +1143 -0
  7. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/ctfd.mjs +154 -0
  8. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/ctfplus.mjs +769 -0
  9. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/gzctf.mjs +130 -0
  10. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/http.mjs +336 -0
  11. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/index.mjs +133 -0
  12. package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/lease.mjs +153 -0
  13. package/dist/builtin-plugins/saturn-plugin-ctf/src/server.mjs +336 -0
  14. package/dist/builtin-plugins/saturn-plugin-ctf/src/view.mjs +714 -0
  15. package/dist/command-dispatch.d.ts +10 -0
  16. package/dist/command-dispatch.js +65 -0
  17. package/dist/completion-judge.d.ts +10 -0
  18. package/dist/completion-judge.js +156 -0
  19. package/dist/composition.d.ts +108 -0
  20. package/dist/composition.js +1180 -0
  21. package/dist/configuration.d.ts +49 -0
  22. package/dist/configuration.js +51 -0
  23. package/dist/context-extensions.d.ts +681 -0
  24. package/dist/context-extensions.js +289 -0
  25. package/dist/cordis/context-core-plugin.d.ts +35 -0
  26. package/dist/cordis/context-core-plugin.js +296 -0
  27. package/dist/cordis/env-probe-plugin.d.ts +27 -0
  28. package/dist/cordis/env-probe-plugin.js +114 -0
  29. package/dist/cordis/host-context.d.ts +65 -0
  30. package/dist/cordis/host-context.js +199 -0
  31. package/dist/cordis/model-responses-plugin.d.ts +81 -0
  32. package/dist/cordis/model-responses-plugin.js +209 -0
  33. package/dist/cordis/plugin-contributions.d.ts +47 -0
  34. package/dist/cordis/plugin-contributions.js +119 -0
  35. package/dist/cordis/plugin-lifecycle.d.ts +57 -0
  36. package/dist/cordis/plugin-lifecycle.js +222 -0
  37. package/dist/cordis/plugin-loader.d.ts +18 -0
  38. package/dist/cordis/plugin-loader.js +310 -0
  39. package/dist/cordis/plugin-sdk-adapter.d.ts +17 -0
  40. package/dist/cordis/plugin-sdk-adapter.js +283 -0
  41. package/dist/cordis/required-host-plugin.d.ts +6 -0
  42. package/dist/cordis/required-host-plugin.js +1 -0
  43. package/dist/cordis/runtime-hooks-plugin.d.ts +23 -0
  44. package/dist/cordis/runtime-hooks-plugin.js +103 -0
  45. package/dist/cordis/sandbox-plugin.d.ts +18 -0
  46. package/dist/cordis/sandbox-plugin.js +21 -0
  47. package/dist/cordis/scoped-layers.d.ts +63 -0
  48. package/dist/cordis/scoped-layers.js +170 -0
  49. package/dist/cordis/tools/builtin-agent-tools-plugin.d.ts +11 -0
  50. package/dist/cordis/tools/builtin-agent-tools-plugin.js +171 -0
  51. package/dist/cordis/tools/index.d.ts +17 -0
  52. package/dist/cordis/tools/index.js +40 -0
  53. package/dist/cordis/tools/mcp-tools-plugin.d.ts +7 -0
  54. package/dist/cordis/tools/mcp-tools-plugin.js +116 -0
  55. package/dist/cordis/tools/process-manager-plugin.d.ts +11 -0
  56. package/dist/cordis/tools/process-manager-plugin.js +39 -0
  57. package/dist/cordis/tools/sandbox-target-tools-plugin.d.ts +13 -0
  58. package/dist/cordis/tools/sandbox-target-tools-plugin.js +255 -0
  59. package/dist/cordis/tools/tool-guidance.d.ts +4 -0
  60. package/dist/cordis/tools/tool-guidance.js +30 -0
  61. package/dist/cordis/tools/tools-core-plugin.d.ts +128 -0
  62. package/dist/cordis/tools/tools-core-plugin.js +486 -0
  63. package/dist/cordis/tools/web-fetch.d.ts +17 -0
  64. package/dist/cordis/tools/web-fetch.js +529 -0
  65. package/dist/cordis/tools/web-search-tools-plugin.d.ts +10 -0
  66. package/dist/cordis/tools/web-search-tools-plugin.js +191 -0
  67. package/dist/cordis/tools/workspace-tools-plugin.d.ts +8 -0
  68. package/dist/cordis/tools/workspace-tools-plugin.js +145 -0
  69. package/dist/env-probe.d.ts +8 -0
  70. package/dist/env-probe.js +172 -0
  71. package/dist/host-configuration.d.ts +27 -0
  72. package/dist/host-configuration.js +185 -0
  73. package/dist/host-tools.d.ts +19 -0
  74. package/dist/host-tools.js +30 -0
  75. package/dist/index.d.ts +2 -0
  76. package/dist/index.js +140 -0
  77. package/dist/ipc.d.ts +24 -0
  78. package/dist/ipc.js +162 -0
  79. package/dist/logger.d.ts +11 -0
  80. package/dist/logger.js +84 -0
  81. package/dist/mcp-configuration.d.ts +17 -0
  82. package/dist/mcp-configuration.js +50 -0
  83. package/dist/modes.d.ts +27 -0
  84. package/dist/modes.js +472 -0
  85. package/dist/ownership.d.ts +7 -0
  86. package/dist/ownership.js +100 -0
  87. package/dist/plugin-configuration.d.ts +9 -0
  88. package/dist/plugin-configuration.js +21 -0
  89. package/dist/plugin-tool-grants.d.ts +18 -0
  90. package/dist/plugin-tool-grants.js +21 -0
  91. package/dist/process-workspaces.d.ts +4 -0
  92. package/dist/process-workspaces.js +28 -0
  93. package/dist/progress.d.ts +30 -0
  94. package/dist/progress.js +699 -0
  95. package/dist/provider-catalog.d.ts +754 -0
  96. package/dist/provider-catalog.js +471 -0
  97. package/dist/run-budget.d.ts +24 -0
  98. package/dist/run-budget.js +47 -0
  99. package/dist/run-checkpoint.d.ts +2 -0
  100. package/dist/run-checkpoint.js +52 -0
  101. package/dist/sandbox-manager.d.ts +111 -0
  102. package/dist/sandbox-manager.js +1519 -0
  103. package/dist/session-paths.d.ts +15 -0
  104. package/dist/session-paths.js +40 -0
  105. package/dist/side-question.d.ts +14 -0
  106. package/dist/side-question.js +89 -0
  107. package/dist/skills-runtime.d.ts +13 -0
  108. package/dist/skills-runtime.js +243 -0
  109. package/dist/token-estimator.d.ts +3 -0
  110. package/dist/token-estimator.js +73 -0
  111. package/dist/tool-result.d.ts +2 -0
  112. package/dist/tool-result.js +91 -0
  113. package/dist/user-config.d.ts +23 -0
  114. package/dist/user-config.js +36 -0
  115. package/package.json +28 -3
  116. package/README.md +0 -3
@@ -0,0 +1,47 @@
1
+ import type { LoggerPort, ToolHandler } from '@saturn-universe/core';
2
+ export type ContributionKey = {
3
+ kind: 'model';
4
+ ref: string;
5
+ } | {
6
+ kind: 'tool' | 'context' | 'hook';
7
+ id: string;
8
+ version: string;
9
+ scopeKey?: string;
10
+ };
11
+ type Cleanup = () => void | Promise<void>;
12
+ type Registration = {
13
+ deactivate: () => void;
14
+ activate: () => void;
15
+ release: (retired: boolean) => void;
16
+ };
17
+ export declare const contributionVersion: (key: ContributionKey) => string;
18
+ export declare const contributionIdentity: (key: ContributionKey) => string;
19
+ export declare class PluginContributions {
20
+ private readonly pluginId;
21
+ private readonly logger;
22
+ private readonly checkConflict;
23
+ private readonly onIdle;
24
+ private readonly entries;
25
+ private readonly cleanups;
26
+ private readonly work;
27
+ private collecting;
28
+ private disposal?;
29
+ constructor(pluginId: string, logger: LoggerPort, checkConflict: (key: ContributionKey) => void, onIdle: () => void);
30
+ get keys(): ContributionKey[];
31
+ get busy(): boolean;
32
+ setup<T>(apply: () => T): T;
33
+ seal(): void;
34
+ private requireSetup;
35
+ register(key: ContributionKey, register: () => Registration): () => void;
36
+ onDispose(cleanup: Cleanup): void;
37
+ deactivate(): void;
38
+ activate(): void;
39
+ dispose(retired: boolean): Promise<void>;
40
+ use<T>(execute: () => T | Promise<T>): Promise<T>;
41
+ waitForWork(): Promise<void>;
42
+ }
43
+ export declare function registerPluginContribution(key: ContributionKey, register: (managed: boolean) => Registration): () => void;
44
+ export declare function trackPluginWork<Args extends unknown[], Result>(execute: (...args: Args) => Promise<Result>): (...args: Args) => Promise<Result>;
45
+ export declare function trackPluginWork<Args extends unknown[], Result>(execute: (...args: Args) => Result | Promise<Result>): (...args: Args) => Result | Promise<Result>;
46
+ export declare function trackPluginTool(handler: ToolHandler): ToolHandler;
47
+ export {};
@@ -0,0 +1,119 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { RuntimeError } from '@saturn-universe/core';
3
+ const generationSetup = new AsyncLocalStorage();
4
+ export const contributionVersion = (key) => key.kind === 'model'
5
+ ? JSON.stringify([key.kind, key.ref])
6
+ : JSON.stringify([key.kind, key.id, key.version]);
7
+ export const contributionIdentity = (key) => JSON.stringify([contributionVersion(key), 'scopeKey' in key ? key.scopeKey : undefined]);
8
+ export class PluginContributions {
9
+ pluginId;
10
+ logger;
11
+ checkConflict;
12
+ onIdle;
13
+ entries = [];
14
+ cleanups = [];
15
+ work = new Set();
16
+ collecting = true;
17
+ disposal;
18
+ constructor(pluginId, logger, checkConflict, onIdle) {
19
+ this.pluginId = pluginId;
20
+ this.logger = logger;
21
+ this.checkConflict = checkConflict;
22
+ this.onIdle = onIdle;
23
+ }
24
+ get keys() {
25
+ return this.entries.map(({ key }) => key);
26
+ }
27
+ get busy() {
28
+ return this.work.size > 0;
29
+ }
30
+ setup(apply) {
31
+ return generationSetup.run(this, apply);
32
+ }
33
+ seal() {
34
+ this.collecting = false;
35
+ }
36
+ requireSetup() {
37
+ if (!this.collecting)
38
+ throw new RuntimeError('PLUGIN_REGISTRAR_CLOSED', `Plugin ${this.pluginId} setup has ended`);
39
+ }
40
+ register(key, register) {
41
+ this.requireSetup();
42
+ this.checkConflict(key);
43
+ const registration = register();
44
+ const entry = { key, registration, enabled: true };
45
+ this.entries.push(entry);
46
+ this.cleanups.push((retired) => {
47
+ registration.deactivate();
48
+ registration.release(retired);
49
+ });
50
+ registration.deactivate();
51
+ return () => {
52
+ entry.enabled = false;
53
+ registration.deactivate();
54
+ };
55
+ }
56
+ onDispose(cleanup) {
57
+ this.requireSetup();
58
+ this.cleanups.push(cleanup);
59
+ }
60
+ deactivate() {
61
+ for (const { registration } of [...this.entries].reverse())
62
+ registration.deactivate();
63
+ }
64
+ activate() {
65
+ for (const { enabled, registration } of this.entries) {
66
+ if (enabled)
67
+ registration.activate();
68
+ }
69
+ }
70
+ dispose(retired) {
71
+ this.seal();
72
+ this.deactivate();
73
+ return (this.disposal ??= Promise.resolve().then(async () => {
74
+ for (const cleanup of this.cleanups.splice(0).reverse()) {
75
+ try {
76
+ await cleanup(retired);
77
+ }
78
+ catch {
79
+ this.logger.error({ pluginId: this.pluginId, code: 'PLUGIN_CLEANUP_FAILED' }, 'Plugin cleanup failed');
80
+ }
81
+ }
82
+ }));
83
+ }
84
+ async use(execute) {
85
+ const task = Promise.resolve().then(execute);
86
+ this.work.add(task);
87
+ try {
88
+ return await task;
89
+ }
90
+ finally {
91
+ this.work.delete(task);
92
+ if (!this.busy)
93
+ this.onIdle();
94
+ }
95
+ }
96
+ async waitForWork() {
97
+ while (this.busy)
98
+ await Promise.allSettled(this.work);
99
+ }
100
+ }
101
+ export function registerPluginContribution(key, register) {
102
+ const owner = generationSetup.getStore();
103
+ return owner ? owner.register(key, () => register(true)) : register(false).deactivate;
104
+ }
105
+ export function trackPluginWork(execute) {
106
+ const owner = generationSetup.getStore();
107
+ return owner ? (...args) => owner.use(() => execute(...args)) : execute;
108
+ }
109
+ export function trackPluginTool(handler) {
110
+ if (!generationSetup.getStore())
111
+ return handler;
112
+ return {
113
+ invoke: trackPluginWork(handler.invoke.bind(handler)),
114
+ ...(handler.resolveResources && {
115
+ resolveResources: trackPluginWork(handler.resolveResources.bind(handler)),
116
+ }),
117
+ ...(handler.reconcile && { reconcile: trackPluginWork(handler.reconcile.bind(handler)) }),
118
+ };
119
+ }
@@ -0,0 +1,57 @@
1
+ import type { LoggerPort, RunId } from '@saturn-universe/core';
2
+ import type { SqliteStore } from '@saturn-universe/storage';
3
+ import { PluginContributions } from './plugin-contributions.js';
4
+ import type { LoadedHostPlugin } from './plugin-loader.js';
5
+ type Dispose = () => Promise<void>;
6
+ type Dependencies = Awaited<ReturnType<SqliteStore['runDependencies']>>;
7
+ export declare function dependencyKeys({ configs, tools }: Dependencies): Set<string>;
8
+ export declare class PluginLifecycle {
9
+ private readonly store;
10
+ private readonly logger;
11
+ private readonly mount;
12
+ private readonly active;
13
+ private readonly draining;
14
+ private readonly mounted;
15
+ private readonly work;
16
+ private queue;
17
+ private drainRequested;
18
+ private closing;
19
+ private disposal?;
20
+ private workRevision;
21
+ constructor(store: Pick<SqliteStore, 'runDependencies'>, logger: LoggerPort, mount: (plugin: LoadedHostPlugin, contributions: PluginContributions) => Promise<Dispose>);
22
+ status(): {
23
+ id: string;
24
+ version: string;
25
+ kind: "saturn-registrar" | "cordis";
26
+ status: "active" | "draining";
27
+ }[];
28
+ withAdmission<T>(work: () => Promise<T>): Promise<T>;
29
+ trackRun(runId: RunId): () => void;
30
+ replace(load: (active: ReadonlyMap<string, LoadedHostPlugin>) => Promise<readonly LoadedHostPlugin[]>, pluginId?: string): Promise<{
31
+ id: string;
32
+ version: string;
33
+ kind: "saturn-registrar" | "cordis";
34
+ status: "active" | "draining";
35
+ }[]>;
36
+ deactivate(pluginId: string): Promise<{
37
+ id: string;
38
+ version: string;
39
+ kind: "saturn-registrar" | "cordis";
40
+ status: "active" | "draining";
41
+ }[]>;
42
+ drain(): Promise<{
43
+ id: string;
44
+ version: string;
45
+ kind: "saturn-registrar" | "cordis";
46
+ status: "active" | "draining";
47
+ }[]>;
48
+ requestDrain(): void;
49
+ stop(): Promise<void>;
50
+ close(): Promise<void>;
51
+ private enqueue;
52
+ private retire;
53
+ private checkConflict;
54
+ private checkDrain;
55
+ private release;
56
+ }
57
+ export {};
@@ -0,0 +1,222 @@
1
+ import { RuntimeError } from '@saturn-universe/core';
2
+ import { contributionIdentity, contributionVersion, PluginContributions } from './plugin-contributions.js';
3
+ export function dependencyKeys({ configs, tools }) {
4
+ const result = new Set();
5
+ const add = (key) => result.add(contributionIdentity(key));
6
+ const tool = ({ name, version, scopeKey }) => add({ kind: 'tool', id: name, version, ...(scopeKey === undefined ? {} : { scopeKey }) });
7
+ function configKeys({ model, pluginBindings, toolSnapshot }) {
8
+ add({ kind: 'model', ref: pluginBindings?.modelProvider?.profileRef ?? model.profileRef });
9
+ toolSnapshot?.definitions.forEach(tool);
10
+ if (!pluginBindings)
11
+ return;
12
+ for (const { bindings, toolSnapshot } of pluginBindings.derived ?? []) {
13
+ collect(bindings);
14
+ toolSnapshot?.definitions.forEach(tool);
15
+ }
16
+ collect(pluginBindings);
17
+ }
18
+ function collect(bindings) {
19
+ bindings.tools.forEach(tool);
20
+ for (const binding of bindings.contextProviders)
21
+ add({ kind: 'context', ...binding });
22
+ for (const binding of bindings.hooks)
23
+ add({ kind: 'hook', ...binding });
24
+ }
25
+ configs.forEach(configKeys);
26
+ tools.forEach(tool);
27
+ return result;
28
+ }
29
+ export class PluginLifecycle {
30
+ store;
31
+ logger;
32
+ mount;
33
+ active = new Map();
34
+ draining = new Set();
35
+ mounted = new Set();
36
+ work = new Map();
37
+ queue = Promise.resolve();
38
+ drainRequested = false;
39
+ closing = false;
40
+ disposal;
41
+ workRevision = 0;
42
+ constructor(store, logger, mount) {
43
+ this.store = store;
44
+ this.logger = logger;
45
+ this.mount = mount;
46
+ }
47
+ status() {
48
+ const summary = ({ plugin: { descriptor: { id, version, kind }, }, }, status) => ({ id, version, kind, status });
49
+ return [
50
+ ...[...this.active.values()].map((generation) => summary(generation, 'active')),
51
+ ...[...this.draining].map((generation) => summary(generation, 'draining')),
52
+ ].sort((a, b) => a.id.localeCompare(b.id));
53
+ }
54
+ withAdmission(work) {
55
+ return this.enqueue(work);
56
+ }
57
+ trackRun(runId) {
58
+ this.work.set(runId, (this.work.get(runId) ?? 0) + 1);
59
+ this.workRevision++;
60
+ return () => {
61
+ const count = this.work.get(runId);
62
+ if (count === 1)
63
+ this.work.delete(runId);
64
+ else
65
+ this.work.set(runId, count - 1);
66
+ this.workRevision++;
67
+ this.requestDrain();
68
+ };
69
+ }
70
+ async replace(load, pluginId) {
71
+ return this.enqueue(async () => {
72
+ const loaded = await load(new Map([...this.active].map(([id, generation]) => [id, generation.plugin])));
73
+ const next = new Map(loaded.map((plugin) => [plugin.descriptor.id, plugin]));
74
+ const previous = [...this.active.values()].filter(({ plugin }) => {
75
+ const { id } = plugin.descriptor;
76
+ return (pluginId === undefined || id === pluginId) && next.get(id) !== plugin;
77
+ });
78
+ const candidates = [];
79
+ for (const generation of previous)
80
+ this.retire(generation);
81
+ try {
82
+ for (const plugin of loaded) {
83
+ const { id } = plugin.descriptor;
84
+ if (this.active.get(id)?.plugin === plugin)
85
+ continue;
86
+ const contributions = new PluginContributions(id, this.logger, (key) => this.checkConflict(id, key), () => this.requestDrain());
87
+ let disposeFiber;
88
+ try {
89
+ disposeFiber = await this.mount(plugin, contributions);
90
+ }
91
+ catch (error) {
92
+ await contributions.dispose(false);
93
+ throw error;
94
+ }
95
+ contributions.seal();
96
+ const generation = { plugin, contributions, disposeFiber };
97
+ this.mounted.add(generation);
98
+ candidates.push(generation);
99
+ }
100
+ for (const generation of candidates)
101
+ generation.contributions.activate();
102
+ }
103
+ catch (error) {
104
+ for (const generation of candidates)
105
+ generation.contributions.deactivate();
106
+ for (const generation of candidates.reverse())
107
+ await this.release(generation, false);
108
+ for (const generation of previous) {
109
+ generation.contributions.activate();
110
+ this.draining.delete(generation);
111
+ this.active.set(generation.plugin.descriptor.id, generation);
112
+ }
113
+ this.logger.error({ code: 'PLUGIN_RELOAD_FAILED', ...(pluginId === undefined ? {} : { pluginId }) }, 'Plugin activation rolled back');
114
+ throw error;
115
+ }
116
+ for (const generation of candidates)
117
+ this.active.set(generation.plugin.descriptor.id, generation);
118
+ await this.checkDrain();
119
+ return this.status();
120
+ });
121
+ }
122
+ deactivate(pluginId) {
123
+ return this.enqueue(async () => {
124
+ const generation = this.active.get(pluginId);
125
+ if (generation)
126
+ this.retire(generation);
127
+ await this.checkDrain();
128
+ return this.status();
129
+ });
130
+ }
131
+ drain() {
132
+ return this.enqueue(async () => {
133
+ await this.checkDrain();
134
+ return this.status();
135
+ });
136
+ }
137
+ requestDrain() {
138
+ if (this.closing || this.drainRequested || !this.draining.size)
139
+ return;
140
+ this.drainRequested = true;
141
+ void this.drain().catch(() => {
142
+ /* checkDrain logs failures and keeps generations retained. */
143
+ });
144
+ }
145
+ stop() {
146
+ this.closing = true;
147
+ return this.queue;
148
+ }
149
+ close() {
150
+ return (this.disposal ??= (async () => {
151
+ await this.stop();
152
+ await Promise.all([...this.mounted].map(({ contributions }) => contributions.waitForWork()));
153
+ for (const generation of [...this.mounted].reverse())
154
+ await this.release(generation, true);
155
+ })());
156
+ }
157
+ enqueue(work) {
158
+ if (this.closing)
159
+ return Promise.reject(new RuntimeError('HOST_CLOSING', 'Host is shutting down'));
160
+ const next = this.queue.then(work);
161
+ this.queue = next.then(() => undefined, () => undefined);
162
+ return next;
163
+ }
164
+ retire(generation) {
165
+ generation.contributions.deactivate();
166
+ this.active.delete(generation.plugin.descriptor.id);
167
+ this.draining.add(generation);
168
+ }
169
+ checkConflict(pluginId, key) {
170
+ const version = contributionVersion(key);
171
+ for (const { contributions } of this.draining) {
172
+ if (contributions.keys.some((candidate) => contributionVersion(candidate) === version))
173
+ throw new RuntimeError('PLUGIN_VERSION_CONFLICT', `Plugin ${pluginId} reuses a retained contribution version`);
174
+ }
175
+ }
176
+ async checkDrain() {
177
+ this.drainRequested = false;
178
+ if (this.closing || !this.draining.size)
179
+ return;
180
+ let required;
181
+ const revision = this.workRevision;
182
+ try {
183
+ required = dependencyKeys(await this.store.runDependencies([...this.work.keys()]));
184
+ }
185
+ catch {
186
+ this.logger.error({ code: 'PLUGIN_DRAIN_CHECK_FAILED' }, 'Plugin dependency check failed');
187
+ return;
188
+ }
189
+ if (this.workRevision !== revision) {
190
+ this.requestDrain();
191
+ return;
192
+ }
193
+ // Start each eligible retirement before awaiting cleanup. Slow cleanup can itself
194
+ // emit commits or trigger work. The next pass reads a new dependency snapshot.
195
+ for (const generation of [...this.draining].reverse()) {
196
+ if (generation.contributions.busy ||
197
+ generation.contributions.keys.some((key) => required.has(contributionIdentity(key))))
198
+ continue;
199
+ await this.release(generation, true);
200
+ if (this.workRevision !== revision || this.drainRequested) {
201
+ this.requestDrain();
202
+ return;
203
+ }
204
+ }
205
+ }
206
+ async release(generation, retired) {
207
+ const { descriptor: { id: pluginId, version }, } = generation.plugin;
208
+ await generation.contributions.dispose(retired);
209
+ try {
210
+ await generation.disposeFiber();
211
+ }
212
+ catch {
213
+ this.logger.error({ code: 'PLUGIN_CLEANUP_FAILED', pluginId, version }, 'Plugin fiber cleanup failed');
214
+ }
215
+ this.mounted.delete(generation);
216
+ this.draining.delete(generation);
217
+ if (this.active.get(pluginId) === generation)
218
+ this.active.delete(pluginId);
219
+ if (retired)
220
+ this.logger.info({ code: 'PLUGIN_GENERATION_RELEASED', pluginId, version }, 'Plugin generation released');
221
+ }
222
+ }
@@ -0,0 +1,18 @@
1
+ import type { LoggerPort, ModeDefinition } from '@saturn-universe/core';
2
+ import type { SaturnCordisPluginV1, SaturnPluginV1 } from '@saturn-universe/plugin-sdk';
3
+ import type { loadHostConfiguration } from '../host-configuration.js';
4
+ type PluginConfig = NonNullable<ModeDefinition['plugins']>[number]['config'];
5
+ type PluginDescriptor = SaturnPluginV1 | SaturnCordisPluginV1;
6
+ export interface LoadedHostPlugin {
7
+ readonly descriptor: PluginDescriptor;
8
+ readonly config: PluginConfig;
9
+ readonly entryUrl?: string;
10
+ readonly files?: ReadonlyMap<string, string>;
11
+ }
12
+ type PluginConfiguration = Pick<Awaited<ReturnType<typeof loadHostConfiguration>>, 'configSource' | 'configPath' | 'trustedPlugins'>;
13
+ export declare function loadModePlugins(activeMode: ModeDefinition, configuration: PluginConfiguration, logger: LoggerPort, reload?: {
14
+ readonly active: ReadonlyMap<string, LoadedHostPlugin>;
15
+ readonly pluginId?: string;
16
+ readonly timeoutMs?: number;
17
+ }): Promise<LoadedHostPlugin[]>;
18
+ export {};