@lmzhen/dsh-evolution-commands 0.3.14 → 0.3.16

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 (2) hide show
  1. package/lib/index.js +30 -26
  2. package/package.json +3 -3
package/lib/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
3
- import { SkillLibrary, appendEvolutionEvent, buildLearnPrompt, eventsFile } from "@lmzhen/dsh-evolution-core";
3
+ import { SkillLibrary, appendEvolutionEvent, buildLearnPrompt, composePresetComposition, eventsFile } from "@lmzhen/dsh-evolution-core";
4
4
  import { buildEnrichment, buildMaintainFacts, runMaintain, snapshotFromLibrary } from "@lmzhen/dsh-evolution-maintenance";
5
- import { copyFileSync, existsSync, mkdirSync } from "node:fs";
5
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
6
6
  import { homedir } from "node:os";
7
7
  import { dirname, join } from "node:path";
8
8
  import { fileURLToPath } from "node:url";
@@ -205,12 +205,11 @@ function apply(ctx, rawConfig = {}) {
205
205
  const subagents = ctx.get("subagents");
206
206
  if (!ioRegistry) return err("Evolution IO registry not mounted — maintenance scan unavailable.");
207
207
  if (!subagents) return err("Subagents service not mounted — maintenance scan unavailable.");
208
- maintainInFlightSince = Date.now();
209
- const library = new SkillLibrary(config.skillsRoot, ioRegistry.provider());
210
- const enrichment = await buildEnrichment(ctx, library);
211
- let outcome;
212
208
  try {
213
- outcome = await runMaintain({
209
+ maintainInFlightSince = Date.now();
210
+ const library = new SkillLibrary(config.skillsRoot, ioRegistry.provider());
211
+ const enrichment = await buildEnrichment(ctx, library);
212
+ const outcome = await runMaintain({
214
213
  library,
215
214
  subagents,
216
215
  parent: invocation.agent
@@ -223,35 +222,40 @@ function apply(ctx, rawConfig = {}) {
223
222
  catalogInvalid: () => enrichment.catalogInvalid,
224
223
  usageObserved: () => enrichment.usageObservedValue
225
224
  });
225
+ lastMaintainRunId = outcome.runId ?? "";
226
+ if (!outcome.ok) return err(outcome.error ?? "Maintenance scan failed.");
227
+ appendEvolutionEvent(ioRegistry.provider(), eventsFile(process.env.DSH_HOME ?? join(homedir(), ".dsh")), {
228
+ type: "maintain",
229
+ source: "manual",
230
+ runId: outcome.runId,
231
+ verdict: outcome.verdict,
232
+ recommendations: outcome.text?.split("\n").filter((line) => line.startsWith("- [")).length ?? 0
233
+ }).catch((error) => {
234
+ ctx.logger.warn(`evolution-commands: failed to record maintain event: ${String(error)}`);
235
+ });
236
+ return ok(`Maintenance scan ${outcome.runId}:\n${outcome.text ?? ""}`);
237
+ } catch (error) {
238
+ return err(`Maintenance scan failed: ${error instanceof Error ? error.message : String(error)}`);
226
239
  } finally {
227
240
  maintainInFlightSince = 0;
241
+ lastMaintainAt = Date.now();
228
242
  }
229
- lastMaintainAt = Date.now();
230
- lastMaintainRunId = outcome.runId ?? "";
231
- if (!outcome.ok) return err(outcome.error ?? "Maintenance scan failed.");
232
- appendEvolutionEvent(ioRegistry.provider(), eventsFile(process.env.DSH_HOME ?? join(homedir(), ".dsh")), {
233
- type: "maintain",
234
- source: "manual",
235
- runId: outcome.runId,
236
- verdict: outcome.verdict,
237
- recommendations: outcome.text?.split("\n").filter((line) => line.startsWith("- [")).length ?? 0
238
- }).catch((error) => {
239
- ctx.logger.warn(`evolution-commands: failed to record maintain event: ${String(error)}`);
240
- });
241
- return ok(`Maintenance scan ${outcome.runId}:\n${outcome.text ?? ""}`);
242
243
  }
243
244
  if (/^maintain\b/.test(input)) return err("Unknown maintain arguments: expected bare `maintain` or `maintain --timeout <ms>` (a positive integer). Got: " + input);
244
245
  if (input === "preset install") {
245
246
  const target = join(process.env.DSH_HOME ?? join(homedir(), ".dsh"), ".agent-presets", "evolution");
246
247
  try {
247
248
  const source = resolveAgentPresetDir(import.meta.url);
249
+ const deltaPath = join(source, "agent.cordis.yml");
250
+ const presetPath = join(source, "preset.yml");
251
+ if (!existsSync(deltaPath) || !existsSync(presetPath)) return err(`Preset file missing from ${source} — is the dsh-evolution-agent-preset package installed?`);
252
+ const registry = ctx.get("agentPresets");
253
+ if (!registry) return err("Agent preset registry not mounted — cannot compose the Evolution preset against the runtime standard.");
254
+ const composition = composePresetComposition(await registry.read("standard"), readFileSync(deltaPath, "utf8"));
248
255
  mkdirSync(target, { recursive: true });
249
- for (const file of ["agent.cordis.yml", "preset.yml"]) {
250
- const from = join(source, file);
251
- if (!existsSync(from)) return err(`Preset file missing from ${source}/${file} — is @lmzhen/dsh-evolution-agent-preset installed?`);
252
- copyFileSync(from, join(target, file));
253
- }
254
- return ok(`Evolution agent preset installed to ${target} (agent.cordis.yml, preset.yml). Restart the session switcher to select it.`);
256
+ writeFileSync(join(target, "agent.cordis.yml"), composition);
257
+ copyFileSync(presetPath, join(target, "preset.yml"));
258
+ return ok(`Evolution agent preset installed to ${target} (runtime standard + delta). Restart the session switcher to select it.`);
255
259
  } catch (error) {
256
260
  return err(`Preset install failed: ${error instanceof Error ? error.message : String(error)}`);
257
261
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-commands",
3
3
  "description": "Human commands for the evolution family (community build)",
4
- "version": "0.3.14",
4
+ "version": "0.3.16",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -33,8 +33,8 @@
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
35
  "@deepseek-ai/schemastery": "^3.18.1",
36
- "@lmzhen/dsh-evolution-core": "^0.3.14",
37
- "@lmzhen/dsh-evolution-maintenance": "^0.3.14"
36
+ "@lmzhen/dsh-evolution-core": "^0.3.16",
37
+ "@lmzhen/dsh-evolution-maintenance": "^0.3.16"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@deepseek-ai/cordis": "^4.0.1",