@lmzhen/dsh-evolution-core 0.41.0 → 0.42.0

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 (55) hide show
  1. package/lib/composition/index.js +2 -2
  2. package/lib/{composition-Da8NfRI7.js → composition-CVafrlEw.js} +2 -2
  3. package/lib/guards-3f02mnf2.js +29 -0
  4. package/lib/http-routes.js +205 -1
  5. package/lib/index.js +3587 -15048
  6. package/lib/mutations-jUuOPaCn.js +718 -0
  7. package/lib/platform/index.js +2 -2
  8. package/lib/{platform-CFp373_0.js → platform-B06_h8t-.js} +4 -1
  9. package/lib/runtime/plugin.js +2 -2
  10. package/lib/{session-projection-CXUNPkq9.js → session-projection-EB7mUOlJ.js} +63 -63
  11. package/lib/skill-health-BLGZTIv8.js +3773 -0
  12. package/lib/skill-history-_Cssts5o.js +1912 -0
  13. package/lib/skills.js +4067 -0
  14. package/lib/subagent/index.js +1 -1
  15. package/lib/types/home-fence.d.ts +7 -0
  16. package/lib/types/home-fence.js +58 -3
  17. package/lib/types/index.d.ts +1 -18
  18. package/lib/types/index.js +1 -18
  19. package/lib/types/io.js +1 -1
  20. package/lib/types/mutation-authority.d.ts +14 -37
  21. package/lib/types/mutation-authority.js +16 -103
  22. package/lib/types/mutation-storage-adapter.js +9 -6
  23. package/lib/types/mutation-unit.d.ts +14 -0
  24. package/lib/types/mutation-unit.js +30 -10
  25. package/lib/types/opt-in.js +1 -1
  26. package/lib/types/platform/index.d.ts +8 -1
  27. package/lib/types/platform/index.js +3 -0
  28. package/lib/types/review-channel.js +3 -1
  29. package/lib/types/review-context.js +3 -1
  30. package/lib/types/run-registry.d.ts +2 -24
  31. package/lib/types/scope.js +1 -1
  32. package/lib/types/signals.d.ts +1 -1
  33. package/lib/types/skill-store.d.ts +7 -1
  34. package/lib/types/skill-store.js +43 -80
  35. package/lib/types/skills.d.ts +11 -0
  36. package/lib/types/skills.js +11 -0
  37. package/lib/types/subagent/types.d.ts +3 -3
  38. package/lib/types/tree-lock.js +4 -1
  39. package/lib/types/unit-claim.d.ts +8 -0
  40. package/lib/types/unit-claim.js +3 -0
  41. package/lib/types/unit-journal.d.ts +3 -1
  42. package/lib/types/unit-journal.js +12 -3
  43. package/lib/types/unit-storage.d.ts +1 -0
  44. package/lib/types/write-gates.d.ts +1 -1
  45. package/lib/types/write-gates.js +3 -1
  46. package/lib/types/write.d.ts +11 -0
  47. package/lib/types/write.js +11 -0
  48. package/lib/write.js +357 -0
  49. package/package.json +16 -4
  50. package/lib/http-routes-_anZVlPf.js +0 -233
  51. package/lib/types/unit-backend.d.ts +0 -5
  52. package/lib/types/unit-backend.js +0 -55
  53. package/lib/types/unit-transaction.d.ts +0 -225
  54. package/lib/types/unit-transaction.js +0 -501
  55. package/lib/{ensure-C5Mo1dbB.js → ensure-BjToTMMj.js} +1 -1
@@ -0,0 +1,11 @@
1
+ /** The one byte-write engine surface. Consumers must import it from the documented subpath. */
2
+ export * from './write-kernel.ts';
3
+ export * from './mutation-unit.ts';
4
+ export * from './mutation-storage-adapter.ts';
5
+ export * from './unit-claim.ts';
6
+ export * from './unit-journal.ts';
7
+ export * from './unit-storage.ts';
8
+ export * from './unit-undo.ts';
9
+ export * from './unit-undo-plan.ts';
10
+ export * from './unit-members.ts';
11
+ //# sourceMappingURL=write.d.ts.map
@@ -0,0 +1,11 @@
1
+ /** The one byte-write engine surface. Consumers must import it from the documented subpath. */
2
+ export * from "./write-kernel.js";
3
+ export * from "./mutation-unit.js";
4
+ export * from "./mutation-storage-adapter.js";
5
+ export * from "./unit-claim.js";
6
+ export * from "./unit-journal.js";
7
+ export * from "./unit-storage.js";
8
+ export * from "./unit-undo.js";
9
+ export * from "./unit-undo-plan.js";
10
+ export * from "./unit-members.js";
11
+ //# sourceMappingURL=write.js.map
package/lib/write.js ADDED
@@ -0,0 +1,357 @@
1
+ import { r as contentHash } from "./mutations-jUuOPaCn.js";
2
+ import { $ as writeUnitSnapshot, A as unitJournalPort, B as readUnitEvidence, F as readUnitJournal, G as unitIndexPath, H as readUnitReceipt, I as unitJournalPath, J as unitSnapshotsDir, K as unitReceiptPath, L as unitJournalPhaseRank, M as UNIT_JOURNAL_PHASES, N as UNIT_JOURNAL_SCHEMA_VERSION, P as assertUnitJournalTransition, Q as writeUnitReceipt, R as writeUnitJournal, U as readUnitSnapshot, V as readUnitIndex, W as unitEvidencePath, X as upsertUnitIndex, Y as unitStorageKey, Z as writeUnitEvidence, et as MutationUnit, f as entryTarget, j as unitSnapshotPort, k as pruneTreeChangeUnits, nt as validateMutationRequest, q as unitSnapshotPath, rt as WriteKernel, tt as fileMutationLock, z as UNIT_STORAGE_SCHEMA_VERSION } from "./skill-history-_Cssts5o.js";
3
+ //#region lib/types/unit-undo.js
4
+ /**
5
+ * Cross-skill unit undo executor.
6
+ *
7
+ * Phase A is a zero-write preflight: every live path still carries the unit's after-bytes and
8
+ * every pre-unit blob is readable. Phase B restores archived members, applies support files,
9
+ * writes the body last, then archives a target the unit created. Any preflight refusal means
10
+ * no write at all.
11
+ */
12
+ async function executeUnitUndo(plan, sink) {
13
+ const refusals = [...plan.refusals];
14
+ const restores = [];
15
+ for (const restore of plan.restores) {
16
+ if (sink.hasArchived !== void 0) {
17
+ if (!await sink.hasArchived(restore.skill)) refusals.push(`${restore.skill}(归档成员不在 .archive)`);
18
+ else restores.push(restore);
19
+ continue;
20
+ }
21
+ restores.push(restore);
22
+ }
23
+ const prepared = [];
24
+ for (const op of plan.ops) {
25
+ const live = op.path === "" ? await sink.readSkill(op.skill) : await sink.readSupport(op.skill, op.path);
26
+ if (live === null) {
27
+ if (op.remove) continue;
28
+ if (op.expectedHash === contentHash("")) {
29
+ const bytes = op.preUnitHash === void 0 ? null : await sink.readBlob(op.preUnitHash);
30
+ if (bytes === null) {
31
+ refusals.push(`${op.skill}/${op.path === "" ? "SKILL.md" : op.path}(单元前字节读不到:blob ${op.preUnitHash ?? "(missing)"})`);
32
+ continue;
33
+ }
34
+ prepared.push({
35
+ ...op,
36
+ bytes,
37
+ live: "",
38
+ absent: true
39
+ });
40
+ continue;
41
+ }
42
+ refusals.push(`${op.skill}/${op.path === "" ? "SKILL.md" : op.path}(盘上文件不存在)`);
43
+ continue;
44
+ }
45
+ if (contentHash(live) !== op.expectedHash) {
46
+ refusals.push(`${op.skill}/${op.path === "" ? "SKILL.md" : op.path}(盘上字节已变,回退会覆盖别人的改动)`);
47
+ continue;
48
+ }
49
+ if (op.remove) {
50
+ prepared.push({
51
+ ...op,
52
+ bytes: "",
53
+ live,
54
+ absent: false
55
+ });
56
+ continue;
57
+ }
58
+ const bytes = op.preUnitHash === void 0 ? null : await sink.readBlob(op.preUnitHash);
59
+ if (bytes === null) {
60
+ refusals.push(`${op.skill}/${op.path === "" ? "SKILL.md" : op.path}(单元前字节读不到:blob ${op.preUnitHash ?? "(missing)"})`);
61
+ continue;
62
+ }
63
+ prepared.push({
64
+ ...op,
65
+ bytes,
66
+ live,
67
+ absent: false
68
+ });
69
+ }
70
+ if (refusals.length > 0) return {
71
+ ok: false,
72
+ message: `整单元撤销未开始(零写)—— 预检未通过:${refusals.join(";")}。修好后可重试。`,
73
+ reverted: []
74
+ };
75
+ const reverted = [];
76
+ const done = () => reverted.length === 0 ? "无" : reverted.join(", ");
77
+ for (const restore of restores) {
78
+ const result = await sink.restoreFromArchive(restore.skill);
79
+ if (!result.ok) return {
80
+ ok: false,
81
+ message: `恢复「${restore.skill}」失败:${result.message} —— 撤销未完成(已回退:${done()})。`,
82
+ reverted
83
+ };
84
+ reverted.push(restore.skill);
85
+ }
86
+ const supportOps = prepared.filter((op) => op.path !== "");
87
+ const bodyOps = prepared.filter((op) => op.path === "");
88
+ for (const op of supportOps) {
89
+ const result = op.remove ? await sink.removeSupportFile(op.skill, op.path, { sha256: op.expectedHash }) : op.absent ? await sink.writeSupportFile(op.skill, op.path, op.bytes) : await sink.writeSupportFile(op.skill, op.path, op.bytes, { sha256: op.expectedHash });
90
+ if (!result.ok) return {
91
+ ok: false,
92
+ message: `${op.skill}/${op.path}:${result.message} —— 撤销未完成(已回退:${done()})。`,
93
+ reverted
94
+ };
95
+ reverted.push(op.skill + "/" + op.path);
96
+ }
97
+ for (const op of bodyOps) {
98
+ const result = await sink.updateSkill(op.skill, op.bytes, { sha256: op.expectedHash });
99
+ if (!result.ok) return {
100
+ ok: false,
101
+ message: `${op.skill}/SKILL.md:${result.message} —— 撤销未完成(已回退:${done()})。`,
102
+ reverted
103
+ };
104
+ reverted.push(op.skill + "/SKILL.md");
105
+ }
106
+ for (const skill of plan.archiveTargets) {
107
+ const result = await sink.archive(skill, "merge undone");
108
+ if (!result.ok) return {
109
+ ok: false,
110
+ message: `归档新目标「${skill}」失败:${result.message} —— 撤销未完成(已回退:${done()})。`,
111
+ reverted
112
+ };
113
+ reverted.push(skill);
114
+ }
115
+ return {
116
+ ok: true,
117
+ message: `已按单元撤销:${reverted.join(", ")}。`,
118
+ reverted
119
+ };
120
+ }
121
+ //#endregion
122
+ //#region lib/types/unit-undo-plan.js
123
+ /**
124
+ * Cross-skill unit undo planner.
125
+ *
126
+ * The curator's single-skill undo already proves the rule: one path is described by
127
+ * (baseline, oldest after, newest after), and a path the unit created is removed. A merge
128
+ * unit adds two shapes:
129
+ *
130
+ * - a source that the merge ARCHIVED: undo restores it from .archive; it has no live ops;
131
+ * - a target the merge CREATED: undo archives the target (never hard-deletes it); it has no
132
+ * body op.
133
+ *
134
+ * The plan is pure; the executor resolves hashes to bytes and applies anchors. Any refusal
135
+ * means the caller writes nothing.
136
+ */
137
+ function slotsOf(entries) {
138
+ const body = {};
139
+ const support = /* @__PURE__ */ new Map();
140
+ const refusals = [];
141
+ for (const entry of entries) {
142
+ if (!(entry.path !== void 0 && entryTarget(entry, entries) === "support")) {
143
+ if (entry.action === "baseline") body.baseline ??= entry;
144
+ else {
145
+ body.oldest ??= entry;
146
+ body.newest = entry;
147
+ }
148
+ continue;
149
+ }
150
+ const path = entry.path;
151
+ const slot = support.get(path) ?? {};
152
+ support.set(path, slot);
153
+ if (entry.action === "baseline") slot.baseline ??= entry;
154
+ else {
155
+ slot.oldest ??= entry;
156
+ slot.newest = entry;
157
+ }
158
+ }
159
+ for (const [path, slot] of support) if (slot.newest === void 0) refusals.push(`${path}(单元里没有该路径的 after 条目)`);
160
+ return {
161
+ body,
162
+ support,
163
+ refusals
164
+ };
165
+ }
166
+ /** Plan one unit across a live target and any archived sources. */
167
+ function planUnitUndoAcross(members) {
168
+ const ops = [];
169
+ const restores = [];
170
+ const archiveTargets = [];
171
+ const refusals = [];
172
+ for (const member of members) {
173
+ if (member.status === "missing") {
174
+ refusals.push(`${member.skill}(成员技能不在活动树或归档里)`);
175
+ continue;
176
+ }
177
+ if (member.status === "archived") {
178
+ if (member.archivedPath === void 0 || member.archivedPath === "") {
179
+ refusals.push(`${member.skill}(归档成员缺少归档路径)`);
180
+ continue;
181
+ }
182
+ restores.push({
183
+ skill: member.skill,
184
+ archivedPath: member.archivedPath
185
+ });
186
+ continue;
187
+ }
188
+ if (member.createdInUnit === true) {
189
+ archiveTargets.push(member.skill);
190
+ continue;
191
+ }
192
+ const { body, support, refusals: slotRefusals } = slotsOf(member.entries);
193
+ refusals.push(...slotRefusals.map((reason) => member.skill + ":" + reason));
194
+ for (const [path, slot] of support) {
195
+ if (slot.newest === void 0) continue;
196
+ const removal = slot.oldest?.removed === true;
197
+ const preUnitHash = removal ? slot.oldest?.hash : slot.baseline !== void 0 ? slot.baseline.hash : slot.oldest?.beforeHash;
198
+ ops.push({
199
+ skill: member.skill,
200
+ path,
201
+ remove: !removal && preUnitHash === void 0,
202
+ ...preUnitHash === void 0 ? {} : { preUnitHash },
203
+ expectedHash: removal ? contentHash("") : slot.newest.hash
204
+ });
205
+ }
206
+ if (body.newest !== void 0) {
207
+ const preUnitHash = body.baseline !== void 0 ? body.baseline.hash : body.oldest?.beforeHash;
208
+ if (preUnitHash === void 0) refusals.push(`${member.skill}:SKILL.md 缺少单元前字节`);
209
+ else ops.push({
210
+ skill: member.skill,
211
+ path: "",
212
+ remove: false,
213
+ preUnitHash,
214
+ expectedHash: body.newest.hash
215
+ });
216
+ }
217
+ }
218
+ return {
219
+ ops,
220
+ restores,
221
+ archiveTargets,
222
+ refusals
223
+ };
224
+ }
225
+ //#endregion
226
+ //#region lib/types/unit-members.js
227
+ /** Candidate skills: head first, then `sources[]` order, DEDUPLICATED (sources may name the head). */
228
+ function candidateSkills(head) {
229
+ const out = [head.skill];
230
+ for (const source of head.sources) if (!out.includes(source.skill)) out.push(source.skill);
231
+ return out;
232
+ }
233
+ /** @param indexes - skill name -> that skill's index text, or null when the index file is absent. */
234
+ /** The `path` of one manifest move, or the empty string when the record carries no string one.
235
+ * Kept as a function so the read never stringifies an object (the linter refuses
236
+ * `String(unknown)` for exactly that reason) and every call site reads the same way. */
237
+ function movePath(move) {
238
+ const raw = move.path;
239
+ return typeof raw === "string" ? raw : "";
240
+ }
241
+ function resolveUnitMembersFromIndexes(head, indexes, readEntries) {
242
+ const members = [];
243
+ const missing = [];
244
+ for (const skill of candidateSkills(head)) {
245
+ const text = indexes.get(skill);
246
+ if (text === void 0 || text === null) {
247
+ missing.push({
248
+ skill,
249
+ reason: "index-absent"
250
+ });
251
+ continue;
252
+ }
253
+ const entries = readEntries(text).filter((entry) => entry.unitId === head.unitId);
254
+ if (entries.length === 0) {
255
+ missing.push({
256
+ skill,
257
+ reason: "unit-absent"
258
+ });
259
+ continue;
260
+ }
261
+ members.push({
262
+ skill,
263
+ entries
264
+ });
265
+ }
266
+ const conflicts = [];
267
+ const manifest = head.unitHead?.moves ?? void 0;
268
+ if (manifest !== void 0) {
269
+ const shardPaths = [];
270
+ for (const slice of members) for (const entry of slice.entries) for (const move of entry.unitHead?.moves ?? []) {
271
+ const path = movePath(move);
272
+ if (path !== "") shardPaths.push(path);
273
+ }
274
+ const wanted = manifest.map((move) => movePath(move)).filter((p) => p !== "");
275
+ for (const path of wanted) if (!shardPaths.includes(path)) conflicts.push({
276
+ kind: "missing",
277
+ path
278
+ });
279
+ for (const path of shardPaths) if (!wanted.includes(path)) conflicts.push({
280
+ kind: "foreign",
281
+ path
282
+ });
283
+ }
284
+ return {
285
+ members,
286
+ missing,
287
+ conflicts
288
+ };
289
+ }
290
+ /** A unit's members are trustworthy only when nothing is missing and nothing conflicts. */
291
+ function unitMembersAreComplete(members) {
292
+ return members.missing.length === 0 && members.conflicts.length === 0;
293
+ }
294
+ /**
295
+ * The io shell (A19.2): open ONLY the known keys -- never enumerate a directory. A skill whose index
296
+ * file is unreadable becomes `null` (index-absent), which the core then reports by name.
297
+ */
298
+ async function resolveUnitMembers(root, io, head, indexPath, readEntries) {
299
+ const indexes = /* @__PURE__ */ new Map();
300
+ for (const skill of candidateSkills(head)) {
301
+ let text = null;
302
+ try {
303
+ text = await io.readText(indexPath(root, skill));
304
+ } catch {
305
+ text = null;
306
+ }
307
+ indexes.set(skill, text);
308
+ }
309
+ return resolveUnitMembersFromIndexes(head, indexes, (raw) => readEntries(raw));
310
+ }
311
+ /** G3b: a LANDMARK carries the owning skill and no manifest (the two forms never coexist). */
312
+ function isLandmark(entry) {
313
+ const head = entry.unitHead;
314
+ return head !== void 0 && head.moves === void 0 && head.skill !== void 0;
315
+ }
316
+ /** @param entry - the entry being judged. @param ownerEntries - the owner skill's index, or null when
317
+ * the owner has no readable index. */
318
+ function landmarkVerdict(entry, ownerEntries) {
319
+ const head = entry.unitHead;
320
+ if ((isLandmark(entry) ? head?.skill : void 0) === void 0 || entry.unitId === void 0) return {
321
+ jumpable: false,
322
+ reason: "not-a-landmark"
323
+ };
324
+ if (ownerEntries === null) return {
325
+ jumpable: false,
326
+ reason: "owner-absent"
327
+ };
328
+ return ownerEntries.some((candidate) => candidate.unitId === entry.unitId) ? { jumpable: true } : {
329
+ jumpable: false,
330
+ reason: "unit-absent"
331
+ };
332
+ }
333
+ /**
334
+ * Scan a whole corpus (skill name -> index entries, or null when unreadable) for stale route stubs.
335
+ * Sorted by (skill, version, owner): a function of the corpus, not of the caller's map order.
336
+ */
337
+ function staleRouteStubs(indexes) {
338
+ const out = [];
339
+ for (const [skill, entries] of indexes) {
340
+ if (entries === null) continue;
341
+ for (const entry of entries) {
342
+ const head = entry.unitHead;
343
+ const owner = isLandmark(entry) ? head?.skill : void 0;
344
+ if (owner === void 0) continue;
345
+ const verdict = landmarkVerdict(entry, indexes.get(owner) ?? null);
346
+ if (!verdict.jumpable && verdict.reason !== "not-a-landmark") out.push({
347
+ skill,
348
+ v: entry.v,
349
+ owner,
350
+ reason: verdict.reason
351
+ });
352
+ }
353
+ }
354
+ return out.sort((a, b) => a.skill.localeCompare(b.skill) || a.v - b.v || a.owner.localeCompare(b.owner));
355
+ }
356
+ //#endregion
357
+ export { MutationUnit, UNIT_JOURNAL_PHASES, UNIT_JOURNAL_SCHEMA_VERSION, UNIT_STORAGE_SCHEMA_VERSION, WriteKernel, assertUnitJournalTransition, candidateSkills, executeUnitUndo, fileMutationLock, isLandmark, landmarkVerdict, planUnitUndoAcross, pruneTreeChangeUnits, readUnitEvidence, readUnitIndex, readUnitJournal, readUnitReceipt, readUnitSnapshot, resolveUnitMembers, resolveUnitMembersFromIndexes, staleRouteStubs, unitEvidencePath, unitIndexPath, unitJournalPath, unitJournalPhaseRank, unitJournalPort, unitMembersAreComplete, unitReceiptPath, unitSnapshotPath, unitSnapshotPort, unitSnapshotsDir, unitStorageKey, upsertUnitIndex, validateMutationRequest, writeUnitEvidence, writeUnitJournal, writeUnitReceipt, writeUnitSnapshot };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-core",
3
3
  "description": "Shared stores, prompts, signals and lifecycle logic for the dsh-evolution plugin family (community build)",
4
- "version": "0.41.0",
4
+ "version": "0.42.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -42,6 +42,14 @@
42
42
  "types": "./lib/types/restrictor.d.ts",
43
43
  "default": "./lib/restrictor.js"
44
44
  },
45
+ "./write": {
46
+ "types": "./lib/types/write.d.ts",
47
+ "default": "./lib/write.js"
48
+ },
49
+ "./skills": {
50
+ "types": "./lib/types/skills.d.ts",
51
+ "default": "./lib/skills.js"
52
+ },
45
53
  "./package.json": "./package.json",
46
54
  "./row-overrides.json": "./row-overrides.json",
47
55
  "./persisted-write-inventory.json": "./persisted-write-inventory.json"
@@ -57,24 +65,27 @@
57
65
  "yaml": "^2.4.2",
58
66
  "zod": "^4.4.3",
59
67
  "js-yaml": "^4.1.0",
60
- "@lmzhen/dsh-evolution-contract": "^0.41.0"
68
+ "@lmzhen/dsh-evolution-contract": "^0.42.0"
61
69
  },
62
70
  "peerDependencies": {
63
71
  "@deepseek-ai/cordis": "^4.0.5",
64
72
  "@deepseek-ai/dsh-scope": "^0.2.2-rc.0",
65
73
  "@deepseek-ai/dsh-session": "^0.2.2-rc.0",
74
+ "@deepseek-ai/dsh-skill": "^0.2.2-rc.0",
66
75
  "@deepseek-ai/dsh-session-projection": "^0.2.2-rc.0",
67
76
  "@deepseek-ai/dsh-agent": "^0.2.2-rc.0",
68
77
  "@deepseek-ai/dsh-subagent": "^0.2.2-rc.0",
69
78
  "@deepseek-ai/dsh-tools": "^0.2.2-rc.0",
70
79
  "@deepseek-ai/dsh-commands": "^0.2.2-rc.0",
71
80
  "@deepseek-ai/dsh-llm": "^0.2.2-rc.0",
72
- "@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.0"
81
+ "@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.0",
82
+ "@deepseek-ai/dsh-storage-domain": "^0.2.2-rc.0"
73
83
  },
74
84
  "devDependencies": {
75
85
  "@deepseek-ai/cordis": "^4.0.5",
76
86
  "@deepseek-ai/dsh-scope": "^0.2.2-rc.0",
77
87
  "@deepseek-ai/dsh-session": "^0.2.2-rc.0",
88
+ "@deepseek-ai/dsh-skill": "^0.2.2-rc.0",
78
89
  "@deepseek-ai/dsh-session-projection": "^0.2.2-rc.0",
79
90
  "@deepseek-ai/dsh-agent": "^0.2.2-rc.0",
80
91
  "@deepseek-ai/dsh-subagent": "^0.2.2-rc.0",
@@ -83,7 +94,8 @@
83
94
  "js-yaml": "^4.1.0",
84
95
  "@deepseek-ai/dsh-commands": "^0.2.2-rc.0",
85
96
  "@deepseek-ai/dsh-llm": "^0.2.2-rc.0",
86
- "@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.0"
97
+ "@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.0",
98
+ "@deepseek-ai/dsh-storage-domain": "^0.2.2-rc.0"
87
99
  },
88
100
  "engines": {
89
101
  "dsh": ">=0.2.2-rc.0 <0.2.3-0"
@@ -1,233 +0,0 @@
1
- //#region lib/types/guards.js
2
- /**
3
- * The family's plain-object predicate, in ONE place (v46 G7.1 / audit A8).
4
- *
5
- * The audit found the same guard — "a non-null object that is not an array" — rewritten fifteen
6
- * times across nine packages, four times inside core itself, and with two byte-identical `asRecord`
7
- * copies in evolution-policy and evolution-threat. This module is the single definition; callers
8
- * import it instead of spelling the clause again.
9
- *
10
- * @module @lmzhen/dsh-evolution-core
11
- */
12
- /**
13
- * Is this a non-null, non-array object (what JSON calls an object)?
14
- * @param value - the value to test.
15
- * @returns whether it is a plain object.
16
- */
17
- function isRecord(value) {
18
- return typeof value === "object" && value !== null && !Array.isArray(value);
19
- }
20
- /**
21
- * Read a value as a record, or undefined when it is not one.
22
- * @param value - the value to read.
23
- * @returns the value typed as a record, or undefined.
24
- */
25
- function asRecord(value) {
26
- return isRecord(value) ? value : void 0;
27
- }
28
- //#endregion
29
- //#region lib/types/http-routes.js
30
- /**
31
- * The Host data-plane contract + Fetch-shaped helpers every family route surface shares (W1/W6).
32
- *
33
- * WHY THIS IS IN CORE: HOST_ROUTES is the ONE path table (clients are generated from it), and the
34
- * response/body helpers are thin platform-Request utilities. The loopback fence that used to live here
35
- * is GONE (G4): trust, browser auth and owner admission are applied by the platform's connection
36
- * carrier BEFORE a route's fetch(request) runs, so a family copy of those rules was a second admission
37
- * path (and did diverge).
38
- *
39
- * Layering: pure transport. Nothing here knows about skills, approvals, curators or route tables.
40
- * @module @lmzhen/dsh-evolution-core/http-routes
41
- */
42
- /** Largest request body a family route accepts; a bigger one reads as "no body" (400 from the handler). */
43
- const MAX_REQUEST_BODY_BYTES = 64 * 1024;
44
- /**
45
- * Read one JSON request body that must be an OBJECT, bounded.
46
- * @param request - the platform Fetch Request handed to a route.
47
- * @param maxBytes - the body bound (defaults to MAX_REQUEST_BODY_BYTES).
48
- * @returns the body as a plain object, or null when it is absent, oversized, not JSON, or not an object.
49
- */
50
- async function readJsonObject(request, maxBytes = MAX_REQUEST_BODY_BYTES) {
51
- const buffer = await request.arrayBuffer();
52
- if (buffer.byteLength > maxBytes || buffer.byteLength === 0) return null;
53
- let parsed;
54
- try {
55
- parsed = JSON.parse(Buffer.from(buffer).toString("utf8"));
56
- } catch {
57
- return null;
58
- }
59
- return isRecord(parsed) ? parsed : null;
60
- }
61
- const HOST_ROUTES = {
62
- approval: {
63
- pending: "/api/dsh-evolution/approval/pending",
64
- preview: "/api/dsh-evolution/approval/preview",
65
- approve: "/api/dsh-evolution/approval/approve",
66
- reject: "/api/dsh-evolution/approval/reject",
67
- release: "/api/dsh-evolution/approval/release"
68
- },
69
- skillHistory: {
70
- skills: "/api/dsh-evolution/skill-history/skills",
71
- versions: "/api/dsh-evolution/skill-history/versions",
72
- diff: "/api/dsh-evolution/skill-history/versions/diff",
73
- body: "/api/dsh-evolution/skill-history/versions/body",
74
- undo: "/api/dsh-evolution/skill-history/undo",
75
- health: "/api/dsh-evolution/skill-history/health"
76
- },
77
- skillHealth: { rows: "/api/dsh-evolution/skill-health/rows" },
78
- merge: {
79
- view: "/api/dsh-evolution/merge/view",
80
- rows: "/api/dsh-evolution/merge/rows",
81
- run: "/api/dsh-evolution/merge/run",
82
- runs: "/api/dsh-evolution/merge/runs",
83
- body: "/api/dsh-evolution/merge/body",
84
- history: "/api/dsh-evolution/merge/history"
85
- },
86
- diagnostics: { view: "/api/dsh-evolution/diagnostics" },
87
- settings: {
88
- describe: "/api/dsh-evolution/settings/describe",
89
- mutate: "/api/dsh-evolution/settings/mutate"
90
- }
91
- };
92
- function hostSurface(ctx) {
93
- const connection = ctx.get("connection");
94
- if (connection === void 0) return {
95
- available: false,
96
- code: "E-325",
97
- reason: "connection-missing"
98
- };
99
- return {
100
- available: true,
101
- allowsRemoteAuthorities: connection.allowsRemoteAuthorities === true
102
- };
103
- }
104
- function isLoopback(address) {
105
- const value = address ?? "";
106
- return value === "127.0.0.1" || value === "::1" || value === "::ffff:127.0.0.1";
107
- }
108
- function sameOrigin(origin, host) {
109
- if (origin === void 0) return true;
110
- try {
111
- const parsed = new URL(origin);
112
- return isLoopback(parsed.hostname) && host !== void 0 && parsed.host === host;
113
- } catch {
114
- return false;
115
- }
116
- }
117
- function nodeRoute(route) {
118
- return {
119
- kind: "exact",
120
- path: route.path,
121
- handler: async (req, res) => {
122
- if (!isLoopback(req.socket.remoteAddress)) {
123
- res.statusCode = 403;
124
- res.end("forbidden");
125
- return;
126
- }
127
- if (!sameOrigin(req.headers.origin, req.headers.host)) {
128
- res.statusCode = 403;
129
- res.end("forbidden");
130
- return;
131
- }
132
- const fetchSite = req.headers["sec-fetch-site"];
133
- if (fetchSite !== void 0 && fetchSite !== "same-origin" && fetchSite !== "none") {
134
- res.statusCode = 403;
135
- res.end("forbidden");
136
- return;
137
- }
138
- const method = req.method ?? "GET";
139
- if (method !== "GET" && method !== "HEAD" && !(req.headers["content-type"] ?? "").toLowerCase().startsWith("application/json")) {
140
- res.statusCode = 415;
141
- res.end("json required");
142
- return;
143
- }
144
- try {
145
- const chunks = [];
146
- for await (const chunk of req) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
147
- const headers = new Headers();
148
- for (const [key, value] of Object.entries(req.headers)) {
149
- if (value === void 0) continue;
150
- headers.set(key, Array.isArray(value) ? value.join(",") : value);
151
- }
152
- const request = new Request(new URL(req.url ?? "/", "http://127.0.0.1"), {
153
- method,
154
- headers,
155
- ...method === "GET" || method === "HEAD" || chunks.length === 0 ? {} : { body: Buffer.concat(chunks) }
156
- });
157
- const response = await route.fetch(request);
158
- res.statusCode = response.status;
159
- response.headers.forEach((value, key) => {
160
- try {
161
- res.setHeader(key, value);
162
- } catch {}
163
- });
164
- res.end(Buffer.from(await response.arrayBuffer()));
165
- } catch (error) {
166
- res.statusCode = 500;
167
- res.end(error instanceof Error ? error.message : String(error));
168
- }
169
- }
170
- };
171
- }
172
- function registerHostRoutes(owner, build) {
173
- const injecting = owner;
174
- if (typeof injecting.inject !== "function") throw new Error("host routes require a context that owns inject()");
175
- injecting.inject(["connection"], (scope) => {
176
- const connection = scope.connection;
177
- const routes = build({
178
- channel: "connection.fetch",
179
- principal: "owner",
180
- deploymentAllowsRemote: connection?.allowsRemoteAuthorities === true
181
- });
182
- for (const route of routes) if (!route.path.startsWith("/api/dsh-evolution/")) throw new Error("host route path must carry the /api/dsh-evolution/ prefix: " + route.path);
183
- const effect = scope.effect;
184
- if (typeof effect !== "function") throw new Error("connection scope has no effect() to own the registration");
185
- if (connection?.fetch !== void 0 && typeof connection.fetch.register === "function") {
186
- const register = connection.fetch.register.bind(connection.fetch);
187
- effect.call(scope, () => {
188
- const disposers = [];
189
- try {
190
- for (const route of routes) disposers.push(register(route));
191
- } catch (error) {
192
- for (const dispose of disposers) try {
193
- dispose();
194
- } catch {}
195
- throw error;
196
- }
197
- return () => {
198
- for (const dispose of disposers) try {
199
- dispose();
200
- } catch {}
201
- };
202
- }, "evolution-host-routes");
203
- return;
204
- }
205
- const web = scope.get?.("webServer") ?? owner.get?.("webServer");
206
- if (web === void 0 || typeof web.register !== "function") throw new Error("connection service has no fetch.register(), and webServer is not mounted for the loopback host-route bridge");
207
- effect.call(scope, () => {
208
- const disposers = routes.map((route) => web.register(nodeRoute(route)));
209
- return () => {
210
- for (const dispose of disposers) try {
211
- dispose();
212
- } catch {}
213
- };
214
- }, "evolution-host-routes");
215
- });
216
- }
217
- function json(status, body) {
218
- return new Response(JSON.stringify(body), {
219
- status,
220
- headers: { "content-type": "application/json; charset=utf-8" }
221
- });
222
- }
223
- function methodNotAllowed(allowed) {
224
- return new Response(JSON.stringify({ error: "method-not-allowed" }), {
225
- status: 405,
226
- headers: {
227
- "content-type": "application/json; charset=utf-8",
228
- allow: allowed.join(", ")
229
- }
230
- });
231
- }
232
- //#endregion
233
- export { methodNotAllowed as a, asRecord as c, json as i, isRecord as l, MAX_REQUEST_BODY_BYTES as n, readJsonObject as o, hostSurface as r, registerHostRoutes as s, HOST_ROUTES as t };
@@ -1,5 +0,0 @@
1
- /** G2 adapter: core UnitBackend over the existing SkillLibrary. */
2
- import type { SkillLibrary } from './skill-store.ts';
3
- import type { UnitBackend } from './unit-transaction.ts';
4
- export declare function skillLibraryUnitBackend(skills: SkillLibrary): UnitBackend;
5
- //# sourceMappingURL=unit-backend.d.ts.map