@lmzhen/dsh-evolution-learning-graph 0.1.0-rc.27 → 0.1.0-rc.29

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 +36 -19
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -94,18 +94,25 @@ const name = "evolution-learning-graph";
94
94
  function apply(ctx) {
95
95
  ctx.inject(["commands"], (commandCtx) => {
96
96
  commandCtx.commands.register({
97
- name: "evolution graph",
98
- description: "Show the learning graph, or act on a node: evolution graph [detail|edit|delete] <nodeId>",
97
+ name: "graph",
98
+ description: "Show the learning graph, or act on a node: graph [detail|edit|delete] <nodeId>",
99
99
  recordInput: false,
100
100
  handler: async (invocation) => {
101
+ const ok = (text) => ({
102
+ kind: "success",
103
+ text
104
+ });
105
+ const err = (text) => ({
106
+ kind: "error",
107
+ text
108
+ });
101
109
  const usageService = ctx.get("skillUsage");
102
110
  const memoryService = ctx.get("memory");
103
111
  const ioService = ctx.get("evolutionIo");
104
- if (!usageService || !memoryService || !ioService) return { text: "skill-usage, memory or evolution-io service is not mounted." };
112
+ if (!usageService || !memoryService || !ioService) return err("skill-usage, memory or evolution-io service is not mounted.");
105
113
  const usage = usageService;
106
114
  const memory = memoryService;
107
115
  const io = ioService;
108
- const directory = await renderGraph();
109
116
  const input = (invocation.rawInput ?? "").trim();
110
117
  const detail = /^detail\s+(\S+)$/.exec(input);
111
118
  if (detail && detail[1]) return await nodeDetail(detail[1]);
@@ -113,8 +120,9 @@ function apply(ctx) {
113
120
  if (edit && edit[1] && edit[2] !== void 0) return await nodeEdit(edit[1], edit[2]);
114
121
  const remove = /^delete\s+(\S+)$/.exec(input);
115
122
  if (remove && remove[1]) return await nodeDelete(remove[1]);
116
- if (input !== "") return { text: `Unknown graph subcommand "${input.split(" ")[0]}". ${directory}` };
117
- return { text: directory };
123
+ const directory = await renderGraph();
124
+ if (input !== "") return err(`Unknown graph subcommand "${input.split(" ")[0]}". ${directory}`);
125
+ return ok(directory);
118
126
  async function renderGraph() {
119
127
  const graph = buildLearningGraph(await usage.report(), await memory.read("memory"), await memory.read("user"));
120
128
  const lines = graph.nodes.map((node) => (node.kind === "memory" ? "◆" : "●") + " " + node.label);
@@ -126,36 +134,45 @@ function apply(ctx) {
126
134
  }
127
135
  async function nodeDetail(id) {
128
136
  const parsed = parseGraphNodeId(id);
129
- if (parsed === null) return { text: `Invalid node id "${id}". Skill names or memory:<source>:<index> expected.` };
130
- return { text: (await resolveGraphNode(parsed, {
137
+ if (parsed === null) return err(`Invalid node id "${id}". Skill names or memory:<source>:<index> expected.`);
138
+ const resolved = await resolveGraphNode(parsed, {
131
139
  readSkill: (name) => withSkills().read(name),
132
140
  readMemory: (target) => memory.read(target)
133
- })).message };
141
+ });
142
+ return resolved.ok ? ok(resolved.message) : err(resolved.message);
134
143
  }
135
144
  async function nodeEdit(id, content) {
136
145
  const parsed = parseGraphNodeId(id);
137
- if (parsed === null) return { text: `Invalid node id "${id}". Skill names or memory:<source>:<index> expected.` };
138
- if (parsed.kind === "skill") return { text: (await withSkills().update(parsed.name, content, "foreground")).message };
146
+ if (parsed === null) return err(`Invalid node id "${id}". Skill names or memory:<source>:<index> expected.`);
147
+ if (parsed.kind === "skill") {
148
+ const result = await withSkills().update(parsed.name, content, "foreground");
149
+ return result.ok ? ok(result.message) : err(result.message);
150
+ }
139
151
  const entries = await memory.read(parsed.source);
140
152
  const entry = entries[parsed.index];
141
- if (entry === void 0) return { text: `Memory ${parsed.source}[${parsed.index}] does not exist (${entries.length} entries).` };
142
- return { text: (await memory.applyBatch(parsed.source, [{
153
+ if (entry === void 0) return err(`Memory ${parsed.source}[${parsed.index}] does not exist (${entries.length} entries).`);
154
+ const result = await memory.applyBatch(parsed.source, [{
143
155
  action: "replace",
144
156
  old_text: entry,
145
157
  facts: content
146
- }])).message };
158
+ }]);
159
+ return result.ok ? ok(result.message) : err(result.message);
147
160
  }
148
161
  async function nodeDelete(id) {
149
162
  const parsed = parseGraphNodeId(id);
150
- if (parsed === null) return { text: `Invalid node id "${id}". Skill names or memory:<source>:<index> expected.` };
151
- if (parsed.kind === "skill") return { text: (await withSkills().archive(parsed.name)).message };
163
+ if (parsed === null) return err(`Invalid node id "${id}". Skill names or memory:<source>:<index> expected.`);
164
+ if (parsed.kind === "skill") {
165
+ const result = await withSkills().archive(parsed.name);
166
+ return result.ok ? ok(result.message) : err(result.message);
167
+ }
152
168
  const entries = await memory.read(parsed.source);
153
169
  const entry = entries[parsed.index];
154
- if (entry === void 0) return { text: `Memory ${parsed.source}[${parsed.index}] does not exist (${entries.length} entries).` };
155
- return { text: (await memory.applyBatch(parsed.source, [{
170
+ if (entry === void 0) return err(`Memory ${parsed.source}[${parsed.index}] does not exist (${entries.length} entries).`);
171
+ const result = await memory.applyBatch(parsed.source, [{
156
172
  action: "remove",
157
173
  old_text: entry
158
- }])).message };
174
+ }]);
175
+ return result.ok ? ok(result.message) : err(result.message);
159
176
  }
160
177
  }
161
178
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-learning-graph",
3
3
  "description": "Learning graph over skills and memory (community build)",
4
- "version": "0.1.0-rc.27",
4
+ "version": "0.1.0-rc.29",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -33,7 +33,7 @@
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
35
  "@deepseek-ai/schemastery": "^3.18.1",
36
- "@lmzhen/dsh-evolution-core": "^0.1.0-rc.27"
36
+ "@lmzhen/dsh-evolution-core": "^0.1.0-rc.29"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",