@deepseek-ai/cordis-plugin-loader 1.0.3 → 1.0.5

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;
@@ -57,17 +57,9 @@ var EntryGroup = class {
57
57
  }
58
58
  async create(options) {
59
59
  const id = this.tree.ensureId(options);
60
- const existing = this.tree.store[id];
61
- const entry = existing ?? (this.tree.store[id] = new Entry(this.ctx.loader));
62
- const previousParent = entry.parent;
60
+ const entry = this.tree.store[id] ??= new Entry(this.ctx.loader);
63
61
  entry.parent = this;
64
- try {
65
- await entry.update(options, true, true);
66
- } catch (error) {
67
- if (existing) entry.parent = previousParent;
68
- else delete this.tree.store[id];
69
- throw error;
70
- }
62
+ await entry.update(options, true, true);
71
63
  return entry.id;
72
64
  }
73
65
  unlink(options) {
@@ -75,54 +67,32 @@ var EntryGroup = class {
75
67
  const index = config.indexOf(options);
76
68
  if (index >= 0) config.splice(index, 1);
77
69
  }
78
- async remove(id, isDispose = false) {
70
+ remove(id, isDispose = false) {
79
71
  const entry = this.tree.store[id];
80
72
  if (!entry) return;
81
- await entry._dispose();
73
+ entry.fiber?.dispose();
82
74
  if (!isDispose) this.unlink(entry.options);
83
75
  delete this.tree.store[id];
84
76
  this.context.emit("loader/partial-dispose", entry, entry.options, false);
85
77
  }
86
78
  async update(config) {
87
79
  const oldConfig = this.data;
88
- const seen = /* @__PURE__ */ new Set();
89
- for (const options of config) {
90
- const id = this.tree.ensureId(options);
91
- if (seen.has(id)) throw new TypeError(`duplicate loader entry id: ${id}`);
92
- seen.add(id);
93
- }
80
+ this.data = config;
94
81
  const oldMap = Object.fromEntries(oldConfig.map((options) => [options.id, options]));
95
- const newMap = Object.fromEntries(config.map((options) => [options.id, options]));
96
- try {
97
- const outcomes = await Promise.allSettled(config.map((options) => this.create(options)));
98
- if (this.ctx.fiber.uid === null) return;
99
- const failures = outcomes.filter((outcome) => outcome.status === "rejected").map((outcome) => outcome.reason);
100
- if (failures.length === 1) throw failures[0];
101
- if (failures.length > 1) throw new AggregateError(failures, "loader entries failed to apply");
102
- for (const id of Object.keys(oldMap)) if (!newMap[id]) await this.remove(id, true);
103
- this.data = config;
104
- } catch (error) {
105
- const rollbackErrors = [];
106
- for (const id of Object.keys(newMap).reverse()) {
107
- if (oldMap[id]) continue;
108
- try {
109
- await this.remove(id, true);
110
- } catch (rollbackError) {
111
- rollbackErrors.push(rollbackError);
112
- }
113
- }
114
- for (const options of oldConfig) try {
115
- await this.create(options);
116
- } catch (rollbackError) {
117
- rollbackErrors.push(rollbackError);
118
- }
119
- this.data = oldConfig;
120
- if (rollbackErrors.length) throw new AggregateError([error, ...rollbackErrors], "loader entry rollback failed");
121
- throw error;
122
- }
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
+ }));
123
93
  }
124
- async stop() {
125
- 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);
126
96
  }
127
97
  };
128
98
  /** Plugin that mounts a nested loader entry group. */
@@ -135,7 +105,9 @@ var Group = class extends EntryGroup {
135
105
  super(ctx, ctx.fiber.entry.parent.tree);
136
106
  this.ctx = ctx;
137
107
  this.config = config;
138
- ctx.on("internal/update", (config) => this.update(config));
108
+ ctx.on("internal/update", (config) => {
109
+ this.update(config);
110
+ });
139
111
  }
140
112
  async *[Service.init]() {
141
113
  yield () => this.stop();
@@ -178,22 +150,12 @@ var EntryTree = class EntryTree {
178
150
  getTasks() {
179
151
  return [...this.entries()].map((entry) => entry._initTask || entry.fiber?.inertia).filter(isNonNullable);
180
152
  }
181
- /**
182
- * Wait until this tree has no active import or lifecycle tasks.
183
- * @throws a settled fiber failure, or an aggregate when several fibers failed.
184
- */
153
+ /** Wait until this tree has no pending import or lifecycle tasks. */
185
154
  async await() {
186
155
  while (true) {
187
156
  const tasks = this.getTasks();
188
- if (tasks.length) {
189
- await Promise.allSettled(tasks);
190
- continue;
191
- }
192
- const failures = (await Promise.allSettled([...this.entries()].map((entry) => entry._await()))).filter((outcome) => outcome.status === "rejected").map((outcome) => outcome.reason);
193
- if (failures.length === 1) throw failures[0];
194
- if (failures.length > 1) throw new AggregateError(failures, "loader fibers failed");
195
- this.ctx.reflect.notify(["loader"]);
196
- if (!this.getTasks().length) return;
157
+ if (!tasks.length) return;
158
+ await Promise.allSettled(tasks);
197
159
  }
198
160
  }
199
161
  ensureId(options) {
@@ -224,47 +186,29 @@ var EntryTree = class EntryTree {
224
186
  /** Create an entry in the root group or a nested group. */
225
187
  async create(options, parent = null, position = Infinity) {
226
188
  const group = this.resolveGroup(parent);
227
- const id = await group.create(options);
228
- const entry = this.resolve(id);
229
- group.data.splice(position, 0, entry.options);
189
+ group.data.splice(position, 0, options);
230
190
  group.tree.write();
231
- return id;
191
+ return group.create(options);
232
192
  }
233
193
  /** Stop and remove an entry from its parent group. */
234
- async remove(id) {
194
+ remove(id) {
235
195
  const entry = this.resolve(id);
236
- await entry.parent.remove(id);
196
+ entry.parent.remove(id);
237
197
  entry.parent.tree.write();
238
198
  }
239
199
  /** Update an entry and optionally move it to another group. */
240
200
  async update(id, options, parent, position) {
241
201
  const entry = this.resolve(id);
242
202
  const source = entry.parent;
243
- const sourceIndex = source.data.indexOf(entry.options);
244
- let target = source;
245
203
  if (parent !== void 0) {
246
- target = this.resolveGroup(parent);
204
+ const target = this.resolveGroup(parent);
247
205
  source.unlink(entry.options);
248
206
  target.data.splice(position ?? Infinity, 0, entry.options);
207
+ target.tree.write();
249
208
  entry.parent = target;
250
209
  }
251
- try {
252
- await entry.update(options, false, true);
253
- } catch (error) {
254
- if (parent !== void 0) {
255
- target.unlink(entry.options);
256
- source.data.splice(sourceIndex < 0 ? source.data.length : sourceIndex, 0, entry.options);
257
- entry.parent = source;
258
- try {
259
- await entry.update({}, false, true);
260
- } catch (rollbackError) {
261
- throw new AggregateError([error, rollbackError], `failed to roll back loader entry move ${id}`);
262
- }
263
- }
264
- throw error;
265
- }
266
210
  source.tree.write();
267
- if (target !== source) target.tree.write();
211
+ return entry.update(options, false, true);
268
212
  }
269
213
  /** Import a plugin module from a specifier or `cordis:` builtin. */
270
214
  import(name, getOuterStack) {
@@ -291,7 +235,7 @@ const evaluate = new Function("ctx", "expr", `
291
235
  return eval(expr)
292
236
  }
293
237
  `);
294
- /** Recursively replace YAML `!js` expression nodes with evaluated values. */
238
+ /** Recursively replace YAML `!!js` expression nodes with evaluated values. */
295
239
  function interpolate(ctx, value) {
296
240
  if (isJsExpr(value)) return evaluate(ctx, value.__jsExpr);
297
241
  else if (!value || typeof value !== "object") return value;
@@ -303,11 +247,46 @@ function isJsExpr(value) {
303
247
  return value instanceof Object && "__jsExpr" in value;
304
248
  }
305
249
  //#endregion
306
- //#region lib/types/config/entry.js
307
- function updateError(stage, options, cause) {
308
- const detail = cause instanceof Error ? cause.message : String(cause);
309
- 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
+ }
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);
310
287
  }
288
+ //#endregion
289
+ //#region lib/types/config/entry.js
311
290
  function takeEntries(object, keys) {
312
291
  const result = [];
313
292
  for (const key of keys) {
@@ -327,10 +306,6 @@ function sortKeys(object, prepend = ["id", "name"], append = ["config"]) {
327
306
  ...part2
328
307
  ]));
329
308
  }
330
- function replaceKeys(target, source) {
331
- for (const key of Object.keys(target)) Reflect.deleteProperty(target, key);
332
- return Object.assign(target, source);
333
- }
334
309
  /** One configured plugin node inside an `EntryTree`. */
335
310
  var Entry = class Entry {
336
311
  loader;
@@ -342,7 +317,6 @@ var Entry = class Entry {
342
317
  subgroup;
343
318
  subtree;
344
319
  _initTask;
345
- _disposing = 0;
346
320
  constructor(loader) {
347
321
  this.loader = loader;
348
322
  this.ctx = loader.ctx.extend({ [Entry.key]: this });
@@ -358,16 +332,12 @@ var Entry = class Entry {
358
332
  }
359
333
  /** True when this entry or any owning parent entry is disabled. */
360
334
  get disabled() {
361
- return this._disabled(this.options);
362
- }
363
- _disabled(options) {
364
- if (options.group) return false;
365
- if (this.disabledOf(options)) return true;
366
- let entry = this.parent.ctx.fiber.entry;
367
- while (entry) {
335
+ if (this.options.group) return false;
336
+ let entry = this;
337
+ do {
368
338
  if (this.disabledOf(entry.options)) return true;
369
339
  entry = entry.parent.ctx.fiber.entry;
370
- }
340
+ } while (entry);
371
341
  return false;
372
342
  }
373
343
  /**
@@ -380,10 +350,10 @@ var Entry = class Entry {
380
350
  evaluate(expr) {
381
351
  return evaluate(this.ctx, expr);
382
352
  }
383
- async _patchContext(diff) {
384
- await this.context.waterfall("loader/patch-context", this, async () => {
353
+ _patchContext(diff) {
354
+ this.context.waterfall("loader/patch-context", this, () => {
385
355
  Object.setPrototypeOf(this.ctx, this.parent.ctx);
386
- 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);
387
357
  });
388
358
  }
389
359
  async refresh() {
@@ -391,104 +361,67 @@ var Entry = class Entry {
391
361
  if (this.disabled) return;
392
362
  await this.init();
393
363
  }
394
- async _dispose(fiber = this.fiber) {
395
- if (!fiber) return;
396
- if (this.fiber === fiber) this.fiber = void 0;
397
- this._disposing += 1;
398
- try {
399
- await fiber.dispose();
400
- } finally {
401
- this._disposing -= 1;
402
- }
403
- }
404
364
  /** Merge new options, restart as needed, and persist through the parent tree. */
405
365
  async update(options, create = false, force = false) {
406
- const previousOptions = this.options;
407
- const legacy = { ...previousOptions };
408
- const candidate = create ? options : { ...previousOptions };
409
- if (!create) for (const [key, value] of Object.entries(options)) if (isNullable(value)) delete candidate[key];
410
- else candidate[key] = value;
411
- sortKeys(candidate);
412
- const diff = Object.keys({
413
- ...candidate,
414
- ...legacy
415
- }).filter((key) => !deepEqual(candidate[key], legacy[key]));
416
- if (!diff.length && !force) return;
417
- const commit = () => {
418
- if (create) return;
419
- this.options = replaceKeys(previousOptions, candidate);
420
- };
421
- const previous = this.fiber;
422
- if (!previous?.uid) {
423
- this.fiber = void 0;
424
- this.options = candidate;
425
- try {
426
- if (!this._disabled(candidate)) await this.init();
427
- } catch (error) {
428
- this.options = previousOptions;
429
- throw error;
430
- }
431
- commit();
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();
432
373
  return;
433
374
  }
434
- if (this._disabled(candidate)) {
435
- this.options = candidate;
436
- try {
437
- await this._dispose(previous);
438
- } catch (error) {
439
- this.options = previousOptions;
440
- throw updateError("dispose", candidate, error);
441
- }
442
- 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;
443
384
  this.context.emit("loader/partial-dispose", this, legacy, true);
444
- return;
445
- }
446
- if (!diff.some((key) => key === "name" || key === "inject" || key === "group")) {
447
- this.options = candidate;
448
- try {
449
- await this._patchContext(diff);
450
- } catch (error) {
451
- this.options = previousOptions;
452
- try {
453
- await this._patchContext(diff);
454
- } catch (rollbackError) {
455
- throw updateError("rollback", legacy, new AggregateError([error, rollbackError]));
456
- }
457
- this.context.emit("loader/partial-dispose", this, candidate, true);
458
- throw updateError("apply", candidate, error);
459
- }
460
- commit();
461
- this.context.emit("loader/partial-dispose", this, legacy, true);
462
- return;
463
- }
464
- 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;
465
399
  try {
466
- 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));
467
401
  } catch (error) {
468
- 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;
469
405
  }
470
- const previousPlugin = previous.runtime.callback;
471
- this.options = candidate;
472
- try {
473
- await this._dispose(previous);
474
- } catch (error) {
475
- this.options = previousOptions;
476
- 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;
477
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;
478
419
  try {
479
- await this._start(plugin);
420
+ fiber.ctx.emit(self, "loader/volatile-update", paths);
480
421
  } catch (error) {
481
- this.options = previousOptions;
482
- try {
483
- await this._start(previousPlugin);
484
- } catch (rollbackError) {
485
- throw updateError("rollback", legacy, new AggregateError([error, rollbackError]));
486
- }
487
- this.context.emit("loader/partial-dispose", this, candidate, true);
488
- throw updateError("apply", candidate, error);
422
+ this.ctx.logger.warn(error);
489
423
  }
490
- commit();
491
- this.context.emit("loader/partial-dispose", this, legacy, true);
424
+ return true;
492
425
  }
493
426
  getOuterStack = () => {
494
427
  let entry = this;
@@ -505,41 +438,27 @@ var Entry = class Entry {
505
438
  await (this._initTask ??= this._init());
506
439
  } finally {
507
440
  this._initTask = void 0;
508
- if (!this.loader.getTasks().length) this.ctx.reflect.notify(["loader"]);
509
- }
510
- await this._await();
511
- }
512
- async _await() {
513
- try {
514
- await this.fiber?.await();
515
- } catch (error) {
516
- throw updateError("apply", this.options, error);
517
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);
518
447
  }
519
448
  async _init() {
520
- let plugin;
449
+ let exports;
521
450
  try {
522
- plugin = this.loader.unwrapExports(await this.parent.tree.import(this.options.name, this.getOuterStack));
451
+ exports = await this.parent.tree.import(this.options.name, this.getOuterStack);
523
452
  } catch (error) {
524
- throw updateError("import", this.options, error);
525
- }
526
- try {
527
- await this._start(plugin);
528
- } catch (error) {
529
- throw updateError("apply", this.options, error);
530
- }
531
- }
532
- async _start(plugin) {
533
- let fiber;
534
- try {
535
- await this._patchContext([]);
536
- this.loader.showLog(this, "apply");
537
- fiber = this.fiber = this.ctx.registry.plugin(plugin, this.options.config, this.getOuterStack);
538
- await fiber.await();
539
- } catch (error) {
540
- await this._dispose(fiber);
541
- throw error;
453
+ this.ctx.logger.error(error);
454
+ return;
455
+ } finally {
456
+ this._initTask = void 0;
542
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;
543
462
  }
544
463
  };
545
464
  //#endregion
@@ -601,7 +520,7 @@ function isolate(ctx) {
601
520
  entry.ctx[Context.intercept] = Object.create(entry.ctx[Context.intercept]);
602
521
  entry.ctx[Context.isolate] = Object.create(entry.ctx[Context.isolate]);
603
522
  });
604
- ctx.on("loader/patch-context", async (entry, next) => {
523
+ ctx.on("loader/patch-context", (entry, next) => {
605
524
  const newMap = Object.create(entry.parent.ctx[Context.isolate]);
606
525
  for (const name of Object.keys(entry.options.isolate ?? {})) newMap[name] = access(entry, name, true);
607
526
  const diff = Object.create(null);
@@ -633,7 +552,7 @@ function isolate(ctx) {
633
552
  Object.setPrototypeOf(entry.ctx[Context.intercept], entry.parent.ctx[Context.intercept]);
634
553
  swap(entry.ctx[Context.isolate], newMap);
635
554
  swap(entry.ctx[Context.intercept], entry.options.intercept);
636
- await next();
555
+ next();
637
556
  for (const [symbol1, symbol2, flag1, flag2] of Object.values(diff)) if (flag1 === flag2 && entry.ctx.reflect.store[symbol1] && !entry.ctx.reflect.store[symbol2]) {
638
557
  entry.ctx.reflect.store[symbol2] = entry.ctx.reflect.store[symbol1];
639
558
  delete entry.ctx.reflect.store[symbol1];
@@ -688,12 +607,12 @@ var Loader = class extends EntryTree {
688
607
  if ((this.runtime?.callback)?.[EntryGroup.key]) return config;
689
608
  return interpolate(this.ctx, config);
690
609
  }, { global: true });
691
- ctx.on("internal/update", async function(config, noSave, next) {
610
+ ctx.on("internal/update", function(config, noSave, next) {
692
611
  if (!this.entry || noSave || this.parent.fiber?.entry === this.entry) return next();
693
- await next();
694
612
  const unparse = this.runtime?.Config?.["simplify"];
695
- this.entry.options.config = unparse ? unparse(config) : config;
613
+ this.entry.options.config = unparse ? unparse.call(this.runtime.Config, config) : config;
696
614
  this.entry.parent.tree.write();
615
+ return next();
697
616
  }, {
698
617
  global: true,
699
618
  prepend: true
@@ -714,7 +633,6 @@ var Loader = class extends EntryTree {
714
633
  if (!ctx.registry.has(fiber.runtime.callback)) return;
715
634
  const treeOwner = fiber.entry.parent.tree.ctx.fiber;
716
635
  if (!treeOwner.uid || treeOwner.state === 5) return;
717
- if (fiber.entry._disposing) return;
718
636
  this.showLog(fiber.entry, "unload");
719
637
  if (fiber.entry.disabled) return;
720
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,UAA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AC,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"}
@@ -11,9 +11,9 @@ export declare class EntryGroup {
11
11
  get context(): Context;
12
12
  create(options: Omit<EntryOptions, 'id'>): Promise<string>;
13
13
  unlink(options: EntryOptions): void;
14
- remove(id: string, isDispose?: boolean): Promise<void>;
14
+ remove(id: string, isDispose?: boolean): void;
15
15
  update(config: EntryOptions[]): Promise<void>;
16
- stop(): Promise<void>;
16
+ stop(): void;
17
17
  }
18
18
  /** Plugin that mounts a nested loader entry group. */
19
19
  export declare class Group extends EntryGroup {
@@ -22,6 +22,6 @@ export declare class Group extends EntryGroup {
22
22
  static initial: Omit<EntryOptions, 'id'>[];
23
23
  static readonly [EntryGroup.key] = true;
24
24
  constructor(ctx: Context, config: EntryOptions[]);
25
- [Service.init](): AsyncGenerator<() => Promise<void>, void, unknown>;
25
+ [Service.init](): AsyncGenerator<() => void, void, unknown>;
26
26
  }
27
27
  //# sourceMappingURL=group.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../../src/config/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,wDAAwD;AACxD,qBAAa,UAAU;IAKF,GAAG,EAAE,OAAO;IAAS,IAAI,EAAE,SAAS;IAJvD,MAAM,CAAC,QAAQ,CAAC,GAAG,gBAA6B;IAEzC,IAAI,EAAE,YAAY,EAAE,CAAK;gBAEb,GAAG,EAAE,OAAO,EAAS,IAAI,EAAE,SAAS;IAKvD,IAAI,OAAO,IAAI,OAAO,CAErB;IAEK,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC;IAsB9C,MAAM,CAAC,OAAO,EAAE,YAAY;IAMtB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,UAAQ;IAWpC,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE;IAiD7B,IAAI;CAKX;AAED,sDAAsD;AACtD,qBAAa,KAAM,SAAQ,UAAU;IAIhB,GAAG,EAAE,OAAO;IAAS,MAAM,EAAE,YAAY,EAAE;IAH9D,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,CAAK;IAC/C,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,QAAO;gBAEpB,GAAG,EAAE,OAAO,EAAS,MAAM,EAAE,YAAY,EAAE;IAKvD,CAAC,OAAO,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