@lmzhen/dsh-evolution-commands 0.1.0-rc.6 → 0.1.0-rc.60

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/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { buildLearnPrompt } from "@lmzhen/dsh-evolution-core";
1
2
  //#region lib/types/index.js
2
3
  /**
3
- * Human commands for the evolution family: /evolution status|pending.
4
+ * Human commands for the evolution family: /evolution learn|pending|curator|restore|consolidate.
4
5
  * @module @lmzhen/dsh-evolution-commands
5
6
  */
6
7
  const name = "evolution-commands";
@@ -12,69 +13,130 @@ function apply(ctx) {
12
13
  recordInput: false,
13
14
  async handler(invocation) {
14
15
  const input = invocation.rawInput?.trim() ?? "";
16
+ const ok = (text) => ({
17
+ kind: "success",
18
+ text
19
+ });
20
+ const err = (text) => ({
21
+ kind: "error",
22
+ text
23
+ });
15
24
  const approval = ctx.get("evolutionApproval");
16
25
  if (input === "pending") {
17
26
  const pending = approval ? await approval.list("pending") : [];
18
- return { text: pending.length === 0 ? "No pending evolution writes." : pending.map((p) => `${p.id} ${p.kind} ${p.summary}`).join("\n") };
27
+ return ok(pending.length === 0 ? "No pending evolution writes." : pending.map((p) => `${p.id} ${p.kind} ${p.summary}`).join("\n"));
19
28
  }
20
29
  if (input.startsWith("approve ")) {
21
30
  const id = input.slice(8).trim();
22
- return { text: (approval ? await approval.approve(id) : {
31
+ const result = approval ? await approval.approve(id) : {
23
32
  ok: false,
24
33
  message: "approval service not mounted"
25
- }).message };
34
+ };
35
+ return result.ok ? ok(result.message) : err(result.message);
26
36
  }
27
37
  if (input.startsWith("reject ")) {
28
38
  const id = input.slice(7).trim();
29
- return { text: (approval ? await approval.reject(id) : {
39
+ const result = approval ? await approval.reject(id) : {
30
40
  ok: false,
31
41
  message: "approval service not mounted"
32
- }).message };
42
+ };
43
+ return result.ok ? ok(result.message) : err(result.message);
33
44
  }
34
45
  if (input === "curator run") {
35
46
  const curator = ctx.get("evolutionCurator");
36
- if (!curator) return { text: "Curator service not mounted." };
37
- const result = await curator.run();
38
- return { text: `Curator run complete: ${result.stale.length} stale, ${result.archived.length} archived, ${result.errors.length} failed.\nrunId=${result.report.runId}${result.report.snapshotPath ? `\nsnapshot=${result.report.snapshotPath}` : ""}` };
47
+ if (!curator) return err("Curator service not mounted.");
48
+ const result = await curator.run({ ignoreGates: true });
49
+ return ok(`Curator run complete: ${result.stale.length} stale, ${result.archived.length} archived, ${result.errors.length} failed.\nrunId=${result.report.runId}${result.report.snapshotPath ? `\nsnapshot=${result.report.snapshotPath}` : ""}`);
50
+ }
51
+ if (input === "curator pause" || input === "curator resume") {
52
+ const curator = ctx.get("evolutionCurator");
53
+ if (!curator) return err("Curator service not mounted.");
54
+ const paused = input === "curator pause";
55
+ await curator.setPaused(paused);
56
+ return ok(paused ? "Curator automatic curation paused. Manual /evolution curator run is unaffected; resume with /evolution curator resume." : "Curator automatic curation resumed. The next scheduled pass waits one interval (first-run defer semantics).");
57
+ }
58
+ if (input === "curator status") {
59
+ const curator = ctx.get("evolutionCurator");
60
+ if (!curator) return err("Curator service not mounted.");
61
+ const state = await curator.status();
62
+ if (!state) return ok("No curator state yet: the first automatic pass is deferred until the interval elapses.");
63
+ const lastRun = typeof state.lastRunAt === "number" && Number.isFinite(state.lastRunAt) && state.lastRunAt > 0 ? new Date(state.lastRunAt).toISOString() : "unknown";
64
+ return ok([
65
+ `paused=${state.paused}`,
66
+ `runs=${state.runCount}`,
67
+ `lastRun=${lastRun}`,
68
+ `summary=${state.lastSummary}`
69
+ ].join("\n"));
70
+ }
71
+ if (input === "mutations") {
72
+ const curator = ctx.get("evolutionCurator");
73
+ if (!curator) return err("Curator service not mounted.");
74
+ const records = await curator.skills.listMutations();
75
+ if (records.length === 0) return ok("No mutation records yet.");
76
+ const recent = records.slice(-5).reverse().map((record) => `${record.at.slice(0, 19)} ${record.skillName} ${record.action} ${record.summary}`);
77
+ return ok(`Mutations: ${records.length} recorded (recent 5):\n${recent.join("\n")}`);
78
+ }
79
+ if (input === "curator scope") {
80
+ const curator = ctx.get("evolutionCurator");
81
+ if (!curator) return err("Curator service not mounted.");
82
+ const view = await curator.scopeView();
83
+ const line = (label, names) => `${label}: ${names.length}${names.length === 0 ? "" : `\n ${names.join(", ")}`}`;
84
+ return ok([
85
+ `Lifecycle scope at ${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}`,
86
+ line("Managed (may transition)", view.managed),
87
+ line("Watched (stale / quality-warned)", view.watched),
88
+ line("Quality-warned", view.qualityWarned),
89
+ line("Exempted (exclude / referenced)", view.exempted),
90
+ line("Protected (pinned / bundled / hub)", view.protected)
91
+ ].join("\n"));
39
92
  }
40
93
  if (input === "curator report") {
41
94
  const curator = ctx.get("evolutionCurator");
42
- if (!curator) return { text: "Curator service not mounted." };
95
+ if (!curator) return err("Curator service not mounted.");
43
96
  const report = await curator.latestReport();
44
- if (!report) return { text: "No curator report available." };
45
- return { text: [
97
+ if (!report) return ok("No curator report available.");
98
+ return ok([
46
99
  `runId=${report.runId}`,
47
100
  `startedAt=${report.startedAt}`,
48
101
  `archived=${report.archived.map((item) => item.name).join(", ") || "(none)"}`,
49
102
  `failed=${report.failed.map((item) => `${item.name}: ${item.reason}`).join(", ") || "(none)"}`
50
- ].join("\n") };
103
+ ].join("\n"));
51
104
  }
52
105
  if (input.startsWith("restore ")) {
53
106
  const curator = ctx.get("evolutionCurator");
54
- return { text: (curator ? await curator.skills.restoreLatestSnapshot() : {
107
+ const result = curator ? await curator.restoreSnapshot() : {
55
108
  ok: false,
56
109
  message: "Curator service not mounted."
57
- }).message };
110
+ };
111
+ return result.ok ? ok(result.message) : err(result.message);
58
112
  }
59
113
  if (input.startsWith("consolidate ")) {
60
114
  const [target, ...sources] = input.slice(12).trim().split(/\s+/).filter(Boolean);
61
- if (!target || sources.length === 0) return { text: "Usage: /evolution consolidate <target> <source...>" };
115
+ if (!target || sources.length === 0) return err("Usage: /evolution consolidate <target> <source...>");
62
116
  const curator = ctx.get("evolutionCurator");
63
- return { text: (curator ? await curator.consolidate(target, sources) : {
117
+ const result = curator ? await curator.consolidate(target, sources) : {
64
118
  ok: false,
65
119
  message: "Curator service not mounted."
66
- }).message };
120
+ };
121
+ return result.ok ? ok(result.message) : err(result.message);
67
122
  }
68
123
  if (input.startsWith("skill restore ")) {
69
124
  const name = input.slice(14).trim();
70
- if (!name) return { text: "Usage: /evolution skill restore <name>" };
125
+ if (!name) return err("Usage: /evolution skill restore <name>");
71
126
  const curator = ctx.get("evolutionCurator");
72
- return { text: (curator ? await curator.restore(name) : {
127
+ const result = curator ? await curator.restore(name) : {
73
128
  ok: false,
74
129
  message: "Curator service not mounted."
75
- }).message };
130
+ };
131
+ return result.ok ? ok(result.message) : err(result.message);
132
+ }
133
+ if (input === "learn" || input.startsWith("learn ")) return ok(buildLearnPrompt(input === "learn" ? "" : input.slice(6).trim()));
134
+ if (input === "replay") {
135
+ const replay = ctx.get("evolutionReplay");
136
+ if (!replay) return err("Replay service not mounted.");
137
+ return ok(replay.compare().report);
76
138
  }
77
- return { text: "Evolution: memory, skills, review, curator. Use /evolution pending | curator run | curator report | restore | consolidate <target> <source...> | skill restore <name>." };
139
+ 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> | learn [request] | replay.");
78
140
  }
79
141
  });
80
142
  });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Human commands for the evolution family: /evolution status|pending.
2
+ * Human commands for the evolution family: /evolution learn|pending|curator|restore|consolidate.
3
3
  * @module @deepseek-ai/dsh-evolution-commands
4
4
  */
5
5
  import type { Context } from '@deepseek-ai/cordis';
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.1.0-rc.6",
4
+ "version": "0.1.0-rc.60",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -32,13 +32,14 @@
32
32
  ],
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
- "@deepseek-ai/schemastery": "^3.18.1"
35
+ "@deepseek-ai/schemastery": "^3.18.1",
36
+ "@lmzhen/dsh-evolution-core": "^0.1.0-rc.60"
36
37
  },
37
38
  "peerDependencies": {
38
- "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
39
+ "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
39
40
  "@deepseek-ai/cordis": "^4.0.1"
40
41
  },
41
42
  "devDependencies": {
42
- "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6"
43
+ "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2"
43
44
  }
44
45
  }