dsh-auto-compaction-engine 0.2.1 → 0.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-auto-compaction-engine",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -21,6 +21,7 @@
21
21
  *
22
22
  * Usage:
23
23
  * node scripts/preset-scope.mjs status [--preset <cordis.patch.yml>] [--profile-patch <cordis.patch.yml>] [--all-local] [--skip-profile]
24
+ * node scripts/preset-scope.mjs state [--preset <cordis.patch.yml>] [--profile-patch <cordis.patch.yml>] # one JSON line
24
25
  * node scripts/preset-scope.mjs enable [--preset <cordis.patch.yml>] [--profile-patch <cordis.patch.yml>] [--all-local] [--skip-profile]
25
26
  * node scripts/preset-scope.mjs disable [--preset <cordis.patch.yml>] [--profile-patch <cordis.patch.yml>] [--all-local] [--skip-profile]
26
27
  * Restart DSH afterwards.
@@ -334,8 +335,72 @@ function profileStatus() {
334
335
  console.log(`${profilePatch}\n 原生守卫: ${guardState(lines, bounds)}\n YAML: ${validateProfile(original)}`);
335
336
  }
336
337
 
338
+ const PLUGIN_ROWS = new Set(["dsh-auto-compaction-engine", "dsh-auto-compaction", "dsh-handoff-compaction"]);
339
+
340
+ /** Which compaction implementation a preset's slot currently names. */
341
+ function ownerOf(row) {
342
+ if (PLUGIN_ROWS.has(row)) return "plugin";
343
+ if (row === "@deepseek-ai/dsh-compaction-basic") return "native";
344
+ return "unknown";
345
+ }
346
+
347
+ /** Profile-level native fallback: "off" means the plugin guard is holding it. */
348
+ function rootGuardState() {
349
+ if (!fs.existsSync(profilePatch)) return "missing";
350
+ const lines = fs.readFileSync(profilePatch, "utf8").split(/\r?\n/);
351
+ const bounds = nativeBounds(lines);
352
+ if (bounds === undefined) return "missing";
353
+ const state = guardState(lines, bounds);
354
+ if (state.startsWith("auto:false")) return "off";
355
+ if (state.startsWith("absent") || state.startsWith("auto:true")) return "on";
356
+ return "other";
357
+ }
358
+
359
+ /**
360
+ * Machine-readable takeover report, one entry per editable preset. The settings
361
+ * page renders this verbatim instead of guessing from its own config: the YAML
362
+ * on disk is what decides who compacts.
363
+ */
364
+ function stateReport() {
365
+ const settings = readSettings() ?? {};
366
+ const selected = new Set(Array.isArray(settings.presets) ? settings.presets : []);
367
+ const files = presetArg >= 0 ? [argv[presetArg + 1]] : discoverPresetFiles();
368
+ const presets = [];
369
+ for (const file of files) {
370
+ let text;
371
+ try {
372
+ text = fs.readFileSync(file, "utf8");
373
+ } catch {
374
+ continue;
375
+ }
376
+ const lines = text.split(/\r?\n/);
377
+ const id = presetIdOf(text) ?? path.basename(path.dirname(file));
378
+ const row = activeName(lines);
379
+ presets.push({
380
+ id,
381
+ file,
382
+ row,
383
+ owner: slotBounds(lines) === undefined ? "no-slot" : ownerOf(row),
384
+ selected: settings.scope === "global" ? true : selected.has(id),
385
+ });
386
+ }
387
+ return {
388
+ enabled: settings.enabled !== false,
389
+ scope: settings.scope === "preset" ? "preset" : "global",
390
+ presets,
391
+ taken: presets.filter((entry) => entry.owner === "plugin").length,
392
+ total: presets.length,
393
+ rootGuard: rootGuardState(),
394
+ };
395
+ }
396
+
397
+ if (mode === "state") {
398
+ console.log(JSON.stringify(stateReport()));
399
+ process.exit(0);
400
+ }
401
+
337
402
  if (mode !== "status" && mode !== "enable" && mode !== "disable") {
338
- console.error("usage: preset-scope.mjs <status|enable|disable> [--preset <file>] [--profile-patch <file>] [--all-local] [--skip-profile]");
403
+ console.error("usage: preset-scope.mjs <status|state|enable|disable> [--preset <file>] [--profile-patch <file>] [--all-local] [--skip-profile]");
339
404
  process.exit(2);
340
405
  }
341
406