@lmzhen/dsh-evolution-commands 0.3.13 → 0.3.15

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 +45 -5
  2. package/package.json +3 -3
package/lib/index.js CHANGED
@@ -1,8 +1,11 @@
1
+ import { createRequire } from "node:module";
1
2
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
2
- import { SkillLibrary, appendEvolutionEvent, buildLearnPrompt, eventsFile } from "@lmzhen/dsh-evolution-core";
3
+ import { SkillLibrary, appendEvolutionEvent, buildLearnPrompt, composePresetComposition, eventsFile } from "@lmzhen/dsh-evolution-core";
3
4
  import { buildEnrichment, buildMaintainFacts, runMaintain, snapshotFromLibrary } from "@lmzhen/dsh-evolution-maintenance";
5
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
6
  import { homedir } from "node:os";
5
- import { join } from "node:path";
7
+ import { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
6
9
  //#region lib/types/index.js
7
10
  /**
8
11
  * Human commands for the evolution family: /evolution learn|pending|curator|restore|consolidate.
@@ -20,7 +23,7 @@ function apply(ctx, rawConfig = {}) {
20
23
  name: "evolution",
21
24
  description: "Self-evolution status and approval controls",
22
25
  recordInput: false,
23
- input: { hint: "pending | approve <id> | reject <id> | curator run|pause|resume|status|report|scope | restore | consolidate <target> <sources...> | skill restore <name> | skills health | learn [request] | maintain [--timeout ms] | restructure <name> \"<heading>\" <to_file> | replay" },
26
+ input: { hint: "pending | approve <id> | reject <id> | curator run|pause|resume|status|report|scope | restore | consolidate <target> <sources...> | skill restore <name> | skills health | learn [request] | maintain [--timeout ms] | preset install | restructure <name> \"<heading>\" <to_file> | replay" },
24
27
  async handler(invocation) {
25
28
  const input = invocation.rawInput?.trim() ?? "";
26
29
  const ok = (text) => ({
@@ -202,9 +205,9 @@ function apply(ctx, rawConfig = {}) {
202
205
  const subagents = ctx.get("subagents");
203
206
  if (!ioRegistry) return err("Evolution IO registry not mounted — maintenance scan unavailable.");
204
207
  if (!subagents) return err("Subagents service not mounted — maintenance scan unavailable.");
208
+ maintainInFlightSince = Date.now();
205
209
  const library = new SkillLibrary(config.skillsRoot, ioRegistry.provider());
206
210
  const enrichment = await buildEnrichment(ctx, library);
207
- maintainInFlightSince = Date.now();
208
211
  let outcome;
209
212
  try {
210
213
  outcome = await runMaintain({
@@ -237,6 +240,25 @@ function apply(ctx, rawConfig = {}) {
237
240
  });
238
241
  return ok(`Maintenance scan ${outcome.runId}:\n${outcome.text ?? ""}`);
239
242
  }
243
+ if (/^maintain\b/.test(input)) return err("Unknown maintain arguments: expected bare `maintain` or `maintain --timeout <ms>` (a positive integer). Got: " + input);
244
+ if (input === "preset install") {
245
+ const target = join(process.env.DSH_HOME ?? join(homedir(), ".dsh"), ".agent-presets", "evolution");
246
+ try {
247
+ const source = resolveAgentPresetDir(import.meta.url);
248
+ const deltaPath = join(source, "agent.cordis.yml");
249
+ const presetPath = join(source, "preset.yml");
250
+ if (!existsSync(deltaPath) || !existsSync(presetPath)) return err(`Preset file missing from ${source} — is the dsh-evolution-agent-preset package installed?`);
251
+ const registry = ctx.get("agentPresets");
252
+ if (!registry) return err("Agent preset registry not mounted — cannot compose the Evolution preset against the runtime standard.");
253
+ const composition = composePresetComposition(await registry.read("standard"), readFileSync(deltaPath, "utf8"));
254
+ mkdirSync(target, { recursive: true });
255
+ writeFileSync(join(target, "agent.cordis.yml"), composition);
256
+ copyFileSync(presetPath, join(target, "preset.yml"));
257
+ return ok(`Evolution agent preset installed to ${target} (runtime standard + delta). Restart the session switcher to select it.`);
258
+ } catch (error) {
259
+ return err(`Preset install failed: ${error instanceof Error ? error.message : String(error)}`);
260
+ }
261
+ }
240
262
  if (input.startsWith("restructure ")) {
241
263
  const planTail = /\s--plan\s+(\S+)\s*$/.exec(input) ?? null;
242
264
  const planRunId = planTail?.[1] ?? void 0;
@@ -261,10 +283,28 @@ function apply(ctx, rawConfig = {}) {
261
283
  if (!replay) return err("Replay service not mounted.");
262
284
  return ok(replay.compare().report);
263
285
  }
264
- return ok("Evolution: memory, skills, review, curator. Use /evolution pending | approve <id> | reject <id> | curator run | curator status | curator pause | curator resume | curator report | curator scope | restore | consolidate <target> <source...> | skill restore <name> | skills health | learn [request] | maintain | restructure <name> \"<heading>\" <to_file> | replay.");
286
+ return ok("Evolution: memory, skills, review, curator. Use /evolution pending | approve <id> | reject <id> | curator run | curator status | curator pause | curator resume | curator report | curator scope | restore | consolidate <target> <source...> | skill restore <name> | skills health | learn [request] | maintain | preset install | restructure <name> \"<heading>\" <to_file> | replay.");
265
287
  }
266
288
  });
267
289
  });
268
290
  }
291
+ /**
292
+ * 0.3.14 (P1-1): locate the installed `dsh-evolution-agent-preset` package
293
+ * (the delivery container for agent.cordis.yml/preset.yml). Resolution order:
294
+ * npm-name sibling (published profile layout), dev-tree sibling (source/test
295
+ * layout), then module resolution. The package dir name differs from the npm
296
+ * name (`evolution-agent` vs `@lmzhen/dsh-evolution-agent-preset` — the rc.44
297
+ * dir≠name trap), so BOTH sibling shapes are probed.
298
+ */
299
+ function resolveAgentPresetDir(importMetaUrl) {
300
+ const dir = dirname(fileURLToPath(importMetaUrl));
301
+ const candidates = [join(dir, "..", "dsh-evolution-agent-preset"), join(dir, "..", "..", "evolution-agent")];
302
+ for (const candidate of candidates) if (existsSync(join(candidate, "agent.cordis.yml")) && existsSync(join(candidate, "preset.yml"))) return candidate;
303
+ try {
304
+ return dirname(createRequire(importMetaUrl).resolve("@lmzhen/dsh-evolution-agent-preset/package.json"));
305
+ } catch {
306
+ return candidates[0] ?? join(dir, "..", "dsh-evolution-agent-preset");
307
+ }
308
+ }
269
309
  //#endregion
270
310
  export { apply, name };
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.13",
4
+ "version": "0.3.15",
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.13",
37
- "@lmzhen/dsh-evolution-maintenance": "^0.3.13"
36
+ "@lmzhen/dsh-evolution-core": "^0.3.15",
37
+ "@lmzhen/dsh-evolution-maintenance": "^0.3.15"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@deepseek-ai/cordis": "^4.0.1",