@deepseek-ai/cordis-plugin-loader 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,3 +46,7 @@ root.loader.update(id, { config: { enabled: false } })
46
46
  | `loader.locate(fiber?)` | Return the loader entry id that owns a fiber. |
47
47
 
48
48
  For file-backed trees, use `@cordisjs/plugin-include`.
49
+
50
+ ## Volatile configuration
51
+
52
+ `Entry.update` compares raw entry options strictly; when only `config` changed on an active fiber in an unchanged context, the pure `equalExceptVolatile` function in `config/diff.ts` compares the raw configs using Schemastery metadata. It ignores volatile fields at fixed object paths without executing expressions, validators or `internal/config` hooks. Object nodes use their declared defaults for null or absent values, including objects without volatile fields; equivalent defaults skip updates. Other ordinary values, parent expressions and unknown fields retain raw comparison. Recursive schema backedges use raw comparison. Entry passes the actual plugin schema; a non-Schemastery schema compares raw. Context changes, other option changes and pending fibers use ordinary updates. A volatile-only change retains the raw Fiber config for later activation, then `_commitVolatile` parses it through the fiber's `internal/config` hook and schema, commits the new values into the running references when every ordinary effective value still matches, and emits `loader/volatile-update` to the owning fiber with the changed paths. A changed ordinary effective value uses the ordinary remount with a debug log naming the entry; because strict comparison treats class instances other than URL, Date and RegExp by identity, an ordinary field whose transform builds a fresh instance on every parse always takes that remount. An invalid candidate is logged and leaves the running references unchanged. A throwing `loader/volatile-update` listener is logged and does not fail the update; the values are already committed. Group/Include retain child dispatch, and programmatic Fiber updates preserve saving and `noSave`; `simplify` is called with its schema receiver so saved config contains plain values.
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
- import { Context, Inject, Service, composeError } from "@deepseek-ai/cordis";
3
- import { deepEqual, defineProperty, isNonNullable, isNullable, valueMap } from "@deepseek-ai/cosmokit";
2
+ import { Context, Inject, Service, composeError, resolveConfig } from "@deepseek-ai/cordis";
3
+ import { deepEqual, defineProperty, isNonNullable, isNullable, updateVolatile, valueMap, volatileEntries } from "@deepseek-ai/cosmokit";
4
4
  //#region lib/types/internal.js
5
5
  /** Helpers for locating the current Node internal module loader. */
6
6
  var ModuleLoader;
@@ -15,16 +15,26 @@ var ModuleLoader;
15
15
  return require("node-addon-require-builtin").requireBuiltin(id);
16
16
  } catch {}
17
17
  }
18
+ /**
19
+ * Locate and classify the running Node internal module loader.
20
+ *
21
+ * The shape is decided by which module-job API the loader owns, never by the
22
+ * Node version: v2 landed in 24.12.0, so a major-version test mistags every
23
+ * 24.0–24.11.1 loader as v2 and makes consumers call `resolveSync` with
24
+ * reversed parameters. Arity is not usable either — `resolveSync` reports 2
25
+ * under both shapes. A loader owning neither API is left unclassified rather
26
+ * than guessed, so consumers take their documented no-internals path.
27
+ * @returns the classified loader, or `undefined` when none is reachable or its shape is unknown.
28
+ */
18
29
  function fromInternal() {
19
30
  if (_cachedLoader) return _cachedLoader;
20
31
  const [major] = process.versions.node.split(".").map(Number);
21
- if (major >= 24) {
22
- const raw = requireInternal("internal/modules/esm/loader")?.getOrInitializeCascadedLoader();
23
- if (raw) return _cachedLoader = Object.assign(raw, { version: "v2" });
24
- } else if (major >= 22) {
25
- const raw = requireInternal("internal/modules/esm/loader")?.getOrInitializeCascadedLoader();
26
- if (raw) return _cachedLoader = Object.assign(raw, { version: "v1" });
27
- }
32
+ if (major < 22) return;
33
+ const raw = requireInternal("internal/modules/esm/loader")?.getOrInitializeCascadedLoader();
34
+ if (!raw) return;
35
+ const version = typeof raw.getOrCreateModuleJob === "function" ? "v2" : typeof raw.getModuleJobForImport === "function" ? "v1" : void 0;
36
+ if (!version) return;
37
+ return _cachedLoader = Object.assign(raw, { version });
28
38
  }
29
39
  ModuleLoader.fromInternal = fromInternal;
30
40
  })(ModuleLoader || (ModuleLoader = {}));
@@ -47,17 +57,9 @@ var EntryGroup = class {
47
57
  }
48
58
  async create(options) {
49
59
  const id = this.tree.ensureId(options);
50
- const existing = this.tree.store[id];
51
- const entry = existing ?? (this.tree.store[id] = new Entry(this.ctx.loader));
52
- const previousParent = entry.parent;
60
+ const entry = this.tree.store[id] ??= new Entry(this.ctx.loader);
53
61
  entry.parent = this;
54
- try {
55
- await entry.update(options, true, true);
56
- } catch (error) {
57
- if (existing) entry.parent = previousParent;
58
- else delete this.tree.store[id];
59
- throw error;
60
- }
62
+ await entry.update(options, true, true);
61
63
  return entry.id;
62
64
  }
63
65
  unlink(options) {
@@ -65,54 +67,32 @@ var EntryGroup = class {
65
67
  const index = config.indexOf(options);
66
68
  if (index >= 0) config.splice(index, 1);
67
69
  }
68
- async remove(id, isDispose = false) {
70
+ remove(id, isDispose = false) {
69
71
  const entry = this.tree.store[id];
70
72
  if (!entry) return;
71
- await entry._dispose();
73
+ entry.fiber?.dispose();
72
74
  if (!isDispose) this.unlink(entry.options);
73
75
  delete this.tree.store[id];
74
76
  this.context.emit("loader/partial-dispose", entry, entry.options, false);
75
77
  }
76
78
  async update(config) {
77
79
  const oldConfig = this.data;
78
- const seen = /* @__PURE__ */ new Set();
79
- for (const options of config) {
80
- const id = this.tree.ensureId(options);
81
- if (seen.has(id)) throw new TypeError(`duplicate loader entry id: ${id}`);
82
- seen.add(id);
83
- }
80
+ this.data = config;
84
81
  const oldMap = Object.fromEntries(oldConfig.map((options) => [options.id, options]));
85
- const newMap = Object.fromEntries(config.map((options) => [options.id, options]));
86
- try {
87
- const outcomes = await Promise.allSettled(config.map((options) => this.create(options)));
88
- if (this.ctx.fiber.uid === null) return;
89
- const failures = outcomes.filter((outcome) => outcome.status === "rejected").map((outcome) => outcome.reason);
90
- if (failures.length === 1) throw failures[0];
91
- if (failures.length > 1) throw new AggregateError(failures, "loader entries failed to apply");
92
- for (const id of Object.keys(oldMap)) if (!newMap[id]) await this.remove(id, true);
93
- this.data = config;
94
- } catch (error) {
95
- const rollbackErrors = [];
96
- for (const id of Object.keys(newMap).reverse()) {
97
- if (oldMap[id]) continue;
98
- try {
99
- await this.remove(id, true);
100
- } catch (rollbackError) {
101
- rollbackErrors.push(rollbackError);
102
- }
103
- }
104
- for (const options of oldConfig) try {
105
- await this.create(options);
106
- } catch (rollbackError) {
107
- rollbackErrors.push(rollbackError);
108
- }
109
- this.data = oldConfig;
110
- if (rollbackErrors.length) throw new AggregateError([error, ...rollbackErrors], "loader entry rollback failed");
111
- throw error;
112
- }
82
+ const newMap = Object.fromEntries(config.map((options) => [options.id ?? Symbol("anonymous"), options]));
83
+ const ids = Reflect.ownKeys({
84
+ ...oldMap,
85
+ ...newMap
86
+ });
87
+ await Promise.all(ids.map(async (id) => {
88
+ if (newMap[id]) await this.create(newMap[id]).catch((error) => {
89
+ this.ctx.logger.error(error);
90
+ });
91
+ else this.remove(id);
92
+ }));
113
93
  }
114
- async stop() {
115
- for (const options of this.data) await this.remove(options.id, true);
94
+ stop() {
95
+ for (const options of this.data) this.remove(options.id, true);
116
96
  }
117
97
  };
118
98
  /** Plugin that mounts a nested loader entry group. */
@@ -125,7 +105,9 @@ var Group = class extends EntryGroup {
125
105
  super(ctx, ctx.fiber.entry.parent.tree);
126
106
  this.ctx = ctx;
127
107
  this.config = config;
128
- ctx.on("internal/update", (config) => this.update(config));
108
+ ctx.on("internal/update", (config) => {
109
+ this.update(config);
110
+ });
129
111
  }
130
112
  async *[Service.init]() {
131
113
  yield () => this.stop();
@@ -168,22 +150,12 @@ var EntryTree = class EntryTree {
168
150
  getTasks() {
169
151
  return [...this.entries()].map((entry) => entry._initTask || entry.fiber?.inertia).filter(isNonNullable);
170
152
  }
171
- /**
172
- * Wait until this tree has no active import or lifecycle tasks.
173
- * @throws a settled fiber failure, or an aggregate when several fibers failed.
174
- */
153
+ /** Wait until this tree has no pending import or lifecycle tasks. */
175
154
  async await() {
176
155
  while (true) {
177
156
  const tasks = this.getTasks();
178
- if (tasks.length) {
179
- await Promise.allSettled(tasks);
180
- continue;
181
- }
182
- const failures = (await Promise.allSettled([...this.entries()].map((entry) => entry._await()))).filter((outcome) => outcome.status === "rejected").map((outcome) => outcome.reason);
183
- if (failures.length === 1) throw failures[0];
184
- if (failures.length > 1) throw new AggregateError(failures, "loader fibers failed");
185
- this.ctx.reflect.notify(["loader"]);
186
- if (!this.getTasks().length) return;
157
+ if (!tasks.length) return;
158
+ await Promise.allSettled(tasks);
187
159
  }
188
160
  }
189
161
  ensureId(options) {
@@ -214,47 +186,29 @@ var EntryTree = class EntryTree {
214
186
  /** Create an entry in the root group or a nested group. */
215
187
  async create(options, parent = null, position = Infinity) {
216
188
  const group = this.resolveGroup(parent);
217
- const id = await group.create(options);
218
- const entry = this.resolve(id);
219
- group.data.splice(position, 0, entry.options);
189
+ group.data.splice(position, 0, options);
220
190
  group.tree.write();
221
- return id;
191
+ return group.create(options);
222
192
  }
223
193
  /** Stop and remove an entry from its parent group. */
224
- async remove(id) {
194
+ remove(id) {
225
195
  const entry = this.resolve(id);
226
- await entry.parent.remove(id);
196
+ entry.parent.remove(id);
227
197
  entry.parent.tree.write();
228
198
  }
229
199
  /** Update an entry and optionally move it to another group. */
230
200
  async update(id, options, parent, position) {
231
201
  const entry = this.resolve(id);
232
202
  const source = entry.parent;
233
- const sourceIndex = source.data.indexOf(entry.options);
234
- let target = source;
235
203
  if (parent !== void 0) {
236
- target = this.resolveGroup(parent);
204
+ const target = this.resolveGroup(parent);
237
205
  source.unlink(entry.options);
238
206
  target.data.splice(position ?? Infinity, 0, entry.options);
207
+ target.tree.write();
239
208
  entry.parent = target;
240
209
  }
241
- try {
242
- await entry.update(options, false, true);
243
- } catch (error) {
244
- if (parent !== void 0) {
245
- target.unlink(entry.options);
246
- source.data.splice(sourceIndex < 0 ? source.data.length : sourceIndex, 0, entry.options);
247
- entry.parent = source;
248
- try {
249
- await entry.update({}, false, true);
250
- } catch (rollbackError) {
251
- throw new AggregateError([error, rollbackError], `failed to roll back loader entry move ${id}`);
252
- }
253
- }
254
- throw error;
255
- }
256
210
  source.tree.write();
257
- if (target !== source) target.tree.write();
211
+ return entry.update(options, false, true);
258
212
  }
259
213
  /** Import a plugin module from a specifier or `cordis:` builtin. */
260
214
  import(name, getOuterStack) {
@@ -281,7 +235,7 @@ const evaluate = new Function("ctx", "expr", `
281
235
  return eval(expr)
282
236
  }
283
237
  `);
284
- /** Recursively replace YAML `!js` expression nodes with evaluated values. */
238
+ /** Recursively replace YAML `!!js` expression nodes with evaluated values. */
285
239
  function interpolate(ctx, value) {
286
240
  if (isJsExpr(value)) return evaluate(ctx, value.__jsExpr);
287
241
  else if (!value || typeof value !== "object") return value;
@@ -293,11 +247,46 @@ function isJsExpr(value) {
293
247
  return value instanceof Object && "__jsExpr" in value;
294
248
  }
295
249
  //#endregion
296
- //#region lib/types/config/entry.js
297
- function updateError(stage, options, cause) {
298
- const detail = cause instanceof Error ? cause.message : String(cause);
299
- return new Error(`failed to ${stage} loader entry ${options.id} (${options.name}): ${detail}`, { cause });
250
+ //#region lib/types/config/diff.js
251
+ function isSchemastery(schema) {
252
+ return schema?.["~standard"].vendor === "schemastery";
253
+ }
254
+ function isRecord(value) {
255
+ if (!value || typeof value !== "object" || isJsExpr(value)) return false;
256
+ const prototype = Object.getPrototypeOf(value);
257
+ return prototype === Object.prototype || prototype === null;
258
+ }
259
+ function equal(a, b, schema, ancestors) {
260
+ if (schema?.meta?.volatile) return true;
261
+ if (schema?.type !== "object" || !schema.dict || ancestors.has(schema)) return deepEqual(a, b, true);
262
+ const left = a ?? schema.meta?.default;
263
+ const right = b ?? schema.meta?.default;
264
+ if (!isRecord(left) || !isRecord(right)) return deepEqual(left, right, true);
265
+ const { dict } = schema;
266
+ ancestors.add(schema);
267
+ try {
268
+ return Object.keys({
269
+ ...left,
270
+ ...right
271
+ }).every((key) => equal(left[key], right[key], Object.hasOwn(dict, key) ? dict[key] : void 0, ancestors));
272
+ } finally {
273
+ ancestors.delete(schema);
274
+ }
300
275
  }
276
+ /**
277
+ * Compare two raw configs, treating schema-declared volatile fields at fixed object paths as equal and absent objects as their schema default.
278
+ * Schema backedges, expressions, unknown fields and opaque values keep strict raw equality; an absent or non-Schemastery schema compares everything raw.
279
+ * @param previous - previous raw config.
280
+ * @param next - next raw config.
281
+ * @param schema - the plugin's config schema.
282
+ * @returns Whether the configs differ at most in volatile fields, without evaluating expressions, validating config or modifying inputs.
283
+ * @internal
284
+ */
285
+ function equalExceptVolatile(previous, next, schema) {
286
+ return isSchemastery(schema) ? equal(previous, next, schema, /* @__PURE__ */ new Set()) : deepEqual(previous, next, true);
287
+ }
288
+ //#endregion
289
+ //#region lib/types/config/entry.js
301
290
  function takeEntries(object, keys) {
302
291
  const result = [];
303
292
  for (const key of keys) {
@@ -317,10 +306,6 @@ function sortKeys(object, prepend = ["id", "name"], append = ["config"]) {
317
306
  ...part2
318
307
  ]));
319
308
  }
320
- function replaceKeys(target, source) {
321
- for (const key of Object.keys(target)) Reflect.deleteProperty(target, key);
322
- return Object.assign(target, source);
323
- }
324
309
  /** One configured plugin node inside an `EntryTree`. */
325
310
  var Entry = class Entry {
326
311
  loader;
@@ -332,7 +317,6 @@ var Entry = class Entry {
332
317
  subgroup;
333
318
  subtree;
334
319
  _initTask;
335
- _disposing = 0;
336
320
  constructor(loader) {
337
321
  this.loader = loader;
338
322
  this.ctx = loader.ctx.extend({ [Entry.key]: this });
@@ -348,16 +332,12 @@ var Entry = class Entry {
348
332
  }
349
333
  /** True when this entry or any owning parent entry is disabled. */
350
334
  get disabled() {
351
- return this._disabled(this.options);
352
- }
353
- _disabled(options) {
354
- if (options.group) return false;
355
- if (this.disabledOf(options)) return true;
356
- let entry = this.parent.ctx.fiber.entry;
357
- while (entry) {
335
+ if (this.options.group) return false;
336
+ let entry = this;
337
+ do {
358
338
  if (this.disabledOf(entry.options)) return true;
359
339
  entry = entry.parent.ctx.fiber.entry;
360
- }
340
+ } while (entry);
361
341
  return false;
362
342
  }
363
343
  /**
@@ -370,10 +350,10 @@ var Entry = class Entry {
370
350
  evaluate(expr) {
371
351
  return evaluate(this.ctx, expr);
372
352
  }
373
- async _patchContext(diff) {
374
- await this.context.waterfall("loader/patch-context", this, async () => {
353
+ _patchContext(diff) {
354
+ this.context.waterfall("loader/patch-context", this, () => {
375
355
  Object.setPrototypeOf(this.ctx, this.parent.ctx);
376
- if (this.fiber?.uid && (diff.includes("config") || this.options.group)) await this.fiber.update(this.options.config, true);
356
+ if (this.fiber?.uid && (diff.includes("config") || this.options.group)) this.fiber.update(this.options.config, true);
377
357
  });
378
358
  }
379
359
  async refresh() {
@@ -381,104 +361,67 @@ var Entry = class Entry {
381
361
  if (this.disabled) return;
382
362
  await this.init();
383
363
  }
384
- async _dispose(fiber = this.fiber) {
385
- if (!fiber) return;
386
- if (this.fiber === fiber) this.fiber = void 0;
387
- this._disposing += 1;
388
- try {
389
- await fiber.dispose();
390
- } finally {
391
- this._disposing -= 1;
392
- }
393
- }
394
364
  /** Merge new options, restart as needed, and persist through the parent tree. */
395
365
  async update(options, create = false, force = false) {
396
- const previousOptions = this.options;
397
- const legacy = { ...previousOptions };
398
- const candidate = create ? options : { ...previousOptions };
399
- if (!create) for (const [key, value] of Object.entries(options)) if (isNullable(value)) delete candidate[key];
400
- else candidate[key] = value;
401
- sortKeys(candidate);
402
- const diff = Object.keys({
403
- ...candidate,
404
- ...legacy
405
- }).filter((key) => !deepEqual(candidate[key], legacy[key]));
406
- if (!diff.length && !force) return;
407
- const commit = () => {
408
- if (create) return;
409
- this.options = replaceKeys(previousOptions, candidate);
410
- };
411
- const previous = this.fiber;
412
- if (!previous?.uid) {
413
- this.fiber = void 0;
414
- this.options = candidate;
415
- try {
416
- if (!this._disabled(candidate)) await this.init();
417
- } catch (error) {
418
- this.options = previousOptions;
419
- throw error;
420
- }
421
- commit();
422
- return;
423
- }
424
- if (this._disabled(candidate)) {
425
- this.options = candidate;
426
- try {
427
- await this._dispose(previous);
428
- } catch (error) {
429
- this.options = previousOptions;
430
- throw updateError("dispose", candidate, error);
431
- }
432
- commit();
433
- this.context.emit("loader/partial-dispose", this, legacy, true);
366
+ const legacy = { ...this.options };
367
+ if (create) this.options = options;
368
+ else for (const [key, value] of Object.entries(options)) if (isNullable(value)) delete this.options[key];
369
+ else this.options[key] = value;
370
+ sortKeys(this.options);
371
+ if (this.disabled) {
372
+ this.fiber?.dispose();
434
373
  return;
435
374
  }
436
- if (!diff.some((key) => key === "name" || key === "inject" || key === "group")) {
437
- this.options = candidate;
438
- try {
439
- await this._patchContext(diff);
440
- } catch (error) {
441
- this.options = previousOptions;
442
- try {
443
- await this._patchContext(diff);
444
- } catch (rollbackError) {
445
- throw updateError("rollback", legacy, new AggregateError([error, rollbackError]));
446
- }
447
- this.context.emit("loader/partial-dispose", this, candidate, true);
448
- throw updateError("apply", candidate, error);
449
- }
450
- commit();
375
+ if (this.fiber?.uid) {
376
+ const changes = Object.keys({
377
+ ...this.options,
378
+ ...legacy
379
+ }).filter((key) => !deepEqual(this.options[key], legacy[key], key === "config"));
380
+ const volatileOnly = changes.length === 1 && changes[0] === "config" && this.fiber.state === 2 && Object.getPrototypeOf(this.ctx) === this.parent.ctx && equalExceptVolatile(legacy.config, this.options.config, this.fiber.runtime?.Config);
381
+ if (volatileOnly) this.fiber._config = this.options.config;
382
+ const pending = volatileOnly && this._commitVolatile() ? [] : changes;
383
+ if (!pending.length && !force) return;
451
384
  this.context.emit("loader/partial-dispose", this, legacy, true);
452
- return;
453
- }
454
- let plugin;
385
+ this._patchContext(pending);
386
+ } else await this.init();
387
+ }
388
+ /**
389
+ * Parse a volatile-only raw config change and commit its values into the running fiber's references.
390
+ * An invalid candidate is logged and leaves the running references unchanged; the raw config stays retained for the next activation.
391
+ * @returns `false` when an ordinary effective value changed, so the caller applies the ordinary update lifecycle.
392
+ */
393
+ _commitVolatile() {
394
+ const fiber = this.fiber;
395
+ const refs = volatileEntries(fiber.config);
396
+ if (!refs.length) return true;
397
+ const raw = this.options.config;
398
+ let candidate;
455
399
  try {
456
- plugin = diff.includes("name") ? this.loader.unwrapExports(await this.parent.tree.import(candidate.name, this.getOuterStack)) : previous.runtime.callback;
400
+ candidate = resolveConfig(fiber.runtime, fiber.ctx.waterfall(fiber, "internal/config", raw, () => raw));
457
401
  } catch (error) {
458
- throw updateError("import", candidate, error);
402
+ this.ctx.logger.warn("volatile config update failed for %C", this.options.id);
403
+ this.ctx.logger.warn(error);
404
+ return true;
459
405
  }
460
- const previousPlugin = previous.runtime.callback;
461
- this.options = candidate;
462
- try {
463
- await this._dispose(previous);
464
- } catch (error) {
465
- this.options = previousOptions;
466
- throw updateError("dispose", candidate, error);
406
+ if (!deepEqual(fiber.config, candidate, true)) {
407
+ this.ctx.logger.debug("ordinary config values of %C changed with its volatile values; applying the ordinary update", this.options.id);
408
+ return false;
467
409
  }
410
+ const paths = refs.flatMap(({ path, ref }) => {
411
+ const source = path.reduce((value, key) => Reflect.get(value, key), candidate);
412
+ if (deepEqual(ref.get(), source.get(), true)) return [];
413
+ updateVolatile(ref, source);
414
+ return [path];
415
+ });
416
+ if (!paths.length) return true;
417
+ const self = Object.create(fiber.ctx);
418
+ self[Context.filter] = (owner) => owner.fiber === fiber;
468
419
  try {
469
- await this._start(plugin);
420
+ fiber.ctx.emit(self, "loader/volatile-update", paths);
470
421
  } catch (error) {
471
- this.options = previousOptions;
472
- try {
473
- await this._start(previousPlugin);
474
- } catch (rollbackError) {
475
- throw updateError("rollback", legacy, new AggregateError([error, rollbackError]));
476
- }
477
- this.context.emit("loader/partial-dispose", this, candidate, true);
478
- throw updateError("apply", candidate, error);
422
+ this.ctx.logger.warn(error);
479
423
  }
480
- commit();
481
- this.context.emit("loader/partial-dispose", this, legacy, true);
424
+ return true;
482
425
  }
483
426
  getOuterStack = () => {
484
427
  let entry = this;
@@ -495,41 +438,27 @@ var Entry = class Entry {
495
438
  await (this._initTask ??= this._init());
496
439
  } finally {
497
440
  this._initTask = void 0;
498
- if (!this.loader.getTasks().length) this.ctx.reflect.notify(["loader"]);
499
- }
500
- await this._await();
501
- }
502
- async _await() {
503
- try {
504
- await this.fiber?.await();
505
- } catch (error) {
506
- throw updateError("apply", this.options, error);
507
441
  }
442
+ const notify = () => {
443
+ if (this.loader.getTasks().length) return;
444
+ this.ctx.reflect.notify(["loader"]);
445
+ };
446
+ this.fiber?.await().then(notify, notify);
508
447
  }
509
448
  async _init() {
510
- let plugin;
511
- try {
512
- plugin = this.loader.unwrapExports(await this.parent.tree.import(this.options.name, this.getOuterStack));
513
- } catch (error) {
514
- throw updateError("import", this.options, error);
515
- }
516
- try {
517
- await this._start(plugin);
518
- } catch (error) {
519
- throw updateError("apply", this.options, error);
520
- }
521
- }
522
- async _start(plugin) {
523
- let fiber;
449
+ let exports;
524
450
  try {
525
- await this._patchContext([]);
526
- this.loader.showLog(this, "apply");
527
- fiber = this.fiber = this.ctx.registry.plugin(plugin, this.options.config, this.getOuterStack);
528
- await fiber.await();
451
+ exports = await this.parent.tree.import(this.options.name, this.getOuterStack);
529
452
  } catch (error) {
530
- await this._dispose(fiber);
531
- throw error;
453
+ this.ctx.logger.error(error);
454
+ return;
455
+ } finally {
456
+ this._initTask = void 0;
532
457
  }
458
+ const plugin = this.loader.unwrapExports(exports);
459
+ this._patchContext([]);
460
+ this.loader.showLog(this, "apply");
461
+ this.fiber = this.ctx.registry.plugin(plugin, this.options.config, this.getOuterStack).ctx.fiber;
533
462
  }
534
463
  };
535
464
  //#endregion
@@ -591,7 +520,7 @@ function isolate(ctx) {
591
520
  entry.ctx[Context.intercept] = Object.create(entry.ctx[Context.intercept]);
592
521
  entry.ctx[Context.isolate] = Object.create(entry.ctx[Context.isolate]);
593
522
  });
594
- ctx.on("loader/patch-context", async (entry, next) => {
523
+ ctx.on("loader/patch-context", (entry, next) => {
595
524
  const newMap = Object.create(entry.parent.ctx[Context.isolate]);
596
525
  for (const name of Object.keys(entry.options.isolate ?? {})) newMap[name] = access(entry, name, true);
597
526
  const diff = Object.create(null);
@@ -623,7 +552,7 @@ function isolate(ctx) {
623
552
  Object.setPrototypeOf(entry.ctx[Context.intercept], entry.parent.ctx[Context.intercept]);
624
553
  swap(entry.ctx[Context.isolate], newMap);
625
554
  swap(entry.ctx[Context.intercept], entry.options.intercept);
626
- await next();
555
+ next();
627
556
  for (const [symbol1, symbol2, flag1, flag2] of Object.values(diff)) if (flag1 === flag2 && entry.ctx.reflect.store[symbol1] && !entry.ctx.reflect.store[symbol2]) {
628
557
  entry.ctx.reflect.store[symbol2] = entry.ctx.reflect.store[symbol1];
629
558
  delete entry.ctx.reflect.store[symbol1];
@@ -678,12 +607,12 @@ var Loader = class extends EntryTree {
678
607
  if ((this.runtime?.callback)?.[EntryGroup.key]) return config;
679
608
  return interpolate(this.ctx, config);
680
609
  }, { global: true });
681
- ctx.on("internal/update", async function(config, noSave, next) {
610
+ ctx.on("internal/update", function(config, noSave, next) {
682
611
  if (!this.entry || noSave || this.parent.fiber?.entry === this.entry) return next();
683
- await next();
684
612
  const unparse = this.runtime?.Config?.["simplify"];
685
- this.entry.options.config = unparse ? unparse(config) : config;
613
+ this.entry.options.config = unparse ? unparse.call(this.runtime.Config, config) : config;
686
614
  this.entry.parent.tree.write();
615
+ return next();
687
616
  }, {
688
617
  global: true,
689
618
  prepend: true
@@ -704,7 +633,6 @@ var Loader = class extends EntryTree {
704
633
  if (!ctx.registry.has(fiber.runtime.callback)) return;
705
634
  const treeOwner = fiber.entry.parent.tree.ctx.fiber;
706
635
  if (!treeOwner.uid || treeOwner.state === 5) return;
707
- if (fiber.entry._disposing) return;
708
636
  this.showLog(fiber.entry, "unload");
709
637
  if (fiber.entry.disabled) return;
710
638
  fiber.entry.options.disabled = true;
@@ -0,0 +1,13 @@
1
+ /** Compare raw plugin configs using schema metadata without executing config hooks or validators. */
2
+ import type { Plugin } from '@deepseek-ai/cordis';
3
+ /**
4
+ * Compare two raw configs, treating schema-declared volatile fields at fixed object paths as equal and absent objects as their schema default.
5
+ * Schema backedges, expressions, unknown fields and opaque values keep strict raw equality; an absent or non-Schemastery schema compares everything raw.
6
+ * @param previous - previous raw config.
7
+ * @param next - next raw config.
8
+ * @param schema - the plugin's config schema.
9
+ * @returns Whether the configs differ at most in volatile fields, without evaluating expressions, validating config or modifying inputs.
10
+ * @internal
11
+ */
12
+ export declare function equalExceptVolatile(previous: unknown, next: unknown, schema: Plugin.Runtime['Config']): boolean;
13
+ //# sourceMappingURL=diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/config/diff.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAgCjD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAE/G"}
@@ -28,13 +28,11 @@ export declare class Entry {
28
28
  subgroup?: EntryGroup;
29
29
  subtree?: EntryTree;
30
30
  _initTask?: Promise<void>;
31
- _disposing: number;
32
31
  constructor(loader: Loader);
33
32
  get context(): Context;
34
33
  get id(): string;
35
34
  /** True when this entry or any owning parent entry is disabled. */
36
35
  get disabled(): boolean;
37
- private _disabled;
38
36
  /**
39
37
  * Effective disabled state: a `!!js` expression evaluates against the loader
40
38
  * context. The raw node stays in the options, so write-back keeps the form.
@@ -43,14 +41,17 @@ export declare class Entry {
43
41
  evaluate(expr: string): any;
44
42
  private _patchContext;
45
43
  refresh(): Promise<void>;
46
- _dispose(fiber?: Fiber | undefined): Promise<void>;
47
44
  /** Merge new options, restart as needed, and persist through the parent tree. */
48
45
  update(options: Partial<EntryOptions>, create?: boolean, force?: boolean): Promise<void>;
46
+ /**
47
+ * Parse a volatile-only raw config change and commit its values into the running fiber's references.
48
+ * An invalid candidate is logged and leaves the running references unchanged; the raw config stays retained for the next activation.
49
+ * @returns `false` when an ordinary effective value changed, so the caller applies the ordinary update lifecycle.
50
+ */
51
+ private _commitVolatile;
49
52
  getOuterStack: () => string[];
50
53
  /** Import and start the configured plugin if it is not already running. */
51
54
  init(): Promise<void>;
52
- _await(): Promise<void>;
53
55
  private _init;
54
- private _start;
55
56
  }
56
57
  //# sourceMappingURL=entry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../../src/config/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAGrC,qEAAqE;AACrE,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,EAAE,EAAE,MAAM,CAAA;IACV,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,mCAAmC;IACnC,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,0CAA0C;IAC1C,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACtB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACzB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB;AA6BD,wDAAwD;AACxD,qBAAa,KAAK;IAcG,MAAM,EAAE,MAAM;IAbjC,MAAM,CAAC,QAAQ,CAAC,GAAG,gBAA6B;IAEzC,GAAG,EAAE,OAAO,CAAA;IACZ,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,MAAM,EAAG,UAAU,CAAA;IAEnB,OAAO,EAAS,YAAY,CAAA;IAC5B,QAAQ,CAAC,EAAE,UAAU,CAAA;IACrB,OAAO,CAAC,EAAE,SAAS,CAAA;IAE1B,SAAS,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,UAAU,SAAI;gBAEK,MAAM,EAAE,MAAM;IAKjC,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,EAAE,WAML;IAED,mEAAmE;IACnE,IAAI,QAAQ,YAEX;IAED,OAAO,CAAC,SAAS;IAYjB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAMlB,QAAQ,CAAC,IAAI,EAAE,MAAM;YAIP,aAAa;IAUrB,OAAO;IAMP,QAAQ,CAAC,KAAK,oBAAa;IAWjC,iFAAiF;IAC3E,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,EAAE,MAAM,UAAQ,EAAE,KAAK,UAAQ;IA0G1E,aAAa,iBAQZ;IAED,2EAA2E;IACrE,IAAI;IAUJ,MAAM;YAQE,KAAK;YAcL,MAAM;CAYrB"}
1
+ {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../../src/config/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAc,MAAM,EAAiB,MAAM,qBAAqB,CAAA;AAEvF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAIrC,qEAAqE;AACrE,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,EAAE,EAAE,MAAM,CAAA;IACV,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,mCAAmC;IACnC,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,0CAA0C;IAC1C,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACtB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACzB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB;AAmBD,wDAAwD;AACxD,qBAAa,KAAK;IAaG,MAAM,EAAE,MAAM;IAZjC,MAAM,CAAC,QAAQ,CAAC,GAAG,gBAA6B;IAEzC,GAAG,EAAE,OAAO,CAAA;IACZ,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,MAAM,EAAG,UAAU,CAAA;IAEnB,OAAO,EAAS,YAAY,CAAA;IAC5B,QAAQ,CAAC,EAAE,UAAU,CAAA;IACrB,OAAO,CAAC,EAAE,SAAS,CAAA;IAE1B,SAAS,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;gBAEN,MAAM,EAAE,MAAM;IAKjC,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,EAAE,WAML;IAED,mEAAmE;IACnE,IAAI,QAAQ,YASX;IAED;;;OAGG;IACH,OAAO,CAAC,UAAU;IAMlB,QAAQ,CAAC,IAAI,EAAE,MAAM;IAIrB,OAAO,CAAC,aAAa;IAUf,OAAO;IAMb,iFAAiF;IAC3E,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,EAAE,MAAM,UAAQ,EAAE,KAAK,UAAQ;IAyC1E;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAmCvB,aAAa,iBAQZ;IAED,2EAA2E;IACrE,IAAI;YAaI,KAAK;CAepB"}