@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
@@ -1,3 +1,3 @@
1
- import { a as entryListSchema, c as MAINTAINER_PRESET_ID, d as RESTRICTED_TOOLS_ROW_ID, f as RESTRICTOR_MODULE, h as restrictedPresetId, i as composeRestrictedPresetDefinition, l as RESTRICTED_PRESET_DELIVERY, m as normalizeAllow, n as ensureRestrictedPreset, o as parsePresetRows, p as REVIEWER_PRESET_ID, r as restrictedPresetState, s as EVOLUTION_PRESET_IDS, t as disposeRestrictedPreset, u as RESTRICTED_PRESET_DISPLAY } from "../ensure-C5Mo1dbB.js";
2
- import { C as trimTrailingBlankLines, S as rowSiblingEnd, _ as presetRowId, a as composePresetComposition, b as resolveBasePresetPatch, c as composePresetRow, d as listDirectories, f as loadRowOverrides, g as presetRowBody, h as presetRowBlock, i as basePresetPlugins, l as compositionRowIds, m as presetPatchText, n as AGENT_PRESET_ROOT_HINT, o as composePresetEntry, p as mergePresetRow, r as EMPTY_PATCH_SEED, s as composePresetInsert, t as AGENT_PRESET_PACKAGE, u as denseBlockSequence, v as probeDesktopScope, x as rowBlockSpan, y as removePresetRow } from "../composition-Da8NfRI7.js";
1
+ import { a as entryListSchema, c as MAINTAINER_PRESET_ID, d as RESTRICTED_TOOLS_ROW_ID, f as RESTRICTOR_MODULE, h as restrictedPresetId, i as composeRestrictedPresetDefinition, l as RESTRICTED_PRESET_DELIVERY, m as normalizeAllow, n as ensureRestrictedPreset, o as parsePresetRows, p as REVIEWER_PRESET_ID, r as restrictedPresetState, s as EVOLUTION_PRESET_IDS, t as disposeRestrictedPreset, u as RESTRICTED_PRESET_DISPLAY } from "../ensure-BjToTMMj.js";
2
+ import { C as trimTrailingBlankLines, S as rowSiblingEnd, _ as presetRowId, a as composePresetComposition, b as resolveBasePresetPatch, c as composePresetRow, d as listDirectories, f as loadRowOverrides, g as presetRowBody, h as presetRowBlock, i as basePresetPlugins, l as compositionRowIds, m as presetPatchText, n as AGENT_PRESET_ROOT_HINT, o as composePresetEntry, p as mergePresetRow, r as EMPTY_PATCH_SEED, s as composePresetInsert, t as AGENT_PRESET_PACKAGE, u as denseBlockSequence, v as probeDesktopScope, x as rowBlockSpan, y as removePresetRow } from "../composition-CVafrlEw.js";
3
3
  export { AGENT_PRESET_PACKAGE, AGENT_PRESET_ROOT_HINT, EMPTY_PATCH_SEED, EVOLUTION_PRESET_IDS, MAINTAINER_PRESET_ID, RESTRICTED_PRESET_DELIVERY, RESTRICTED_PRESET_DISPLAY, RESTRICTED_TOOLS_ROW_ID, RESTRICTOR_MODULE, REVIEWER_PRESET_ID, basePresetPlugins, composePresetComposition, composePresetEntry, composePresetInsert, composePresetRow, composeRestrictedPresetDefinition, compositionRowIds, denseBlockSequence, disposeRestrictedPreset, ensureRestrictedPreset, entryListSchema, listDirectories, loadRowOverrides, mergePresetRow, normalizeAllow, parsePresetRows, presetPatchText, presetRowBlock, presetRowBody, presetRowId, probeDesktopScope, removePresetRow, resolveBasePresetPatch, restrictedPresetId, restrictedPresetState, rowBlockSpan, rowSiblingEnd, trimTrailingBlankLines };
@@ -1,6 +1,6 @@
1
- import { _ as scopedPackageName } from "./ensure-C5Mo1dbB.js";
2
- import { dirname, join } from "node:path";
1
+ import { _ as scopedPackageName } from "./ensure-BjToTMMj.js";
3
2
  import { existsSync, readFileSync, readdirSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  //#region lib/types/env.js
6
6
  /**
@@ -0,0 +1,29 @@
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
+ export { isRecord as n, asRecord as t };
@@ -1,2 +1,206 @@
1
- import { a as methodNotAllowed, i as json, n as MAX_REQUEST_BODY_BYTES, o as readJsonObject, r as hostSurface, s as registerHostRoutes, t as HOST_ROUTES } from "./http-routes-_anZVlPf.js";
1
+ import { n as isRecord } from "./guards-3f02mnf2.js";
2
+ //#region lib/types/http-routes.js
3
+ /**
4
+ * The Host data-plane contract + Fetch-shaped helpers every family route surface shares (W1/W6).
5
+ *
6
+ * WHY THIS IS IN CORE: HOST_ROUTES is the ONE path table (clients are generated from it), and the
7
+ * response/body helpers are thin platform-Request utilities. The loopback fence that used to live here
8
+ * is GONE (G4): trust, browser auth and owner admission are applied by the platform's connection
9
+ * carrier BEFORE a route's fetch(request) runs, so a family copy of those rules was a second admission
10
+ * path (and did diverge).
11
+ *
12
+ * Layering: pure transport. Nothing here knows about skills, approvals, curators or route tables.
13
+ * @module @lmzhen/dsh-evolution-core/http-routes
14
+ */
15
+ /** Largest request body a family route accepts; a bigger one reads as "no body" (400 from the handler). */
16
+ const MAX_REQUEST_BODY_BYTES = 64 * 1024;
17
+ /**
18
+ * Read one JSON request body that must be an OBJECT, bounded.
19
+ * @param request - the platform Fetch Request handed to a route.
20
+ * @param maxBytes - the body bound (defaults to MAX_REQUEST_BODY_BYTES).
21
+ * @returns the body as a plain object, or null when it is absent, oversized, not JSON, or not an object.
22
+ */
23
+ async function readJsonObject(request, maxBytes = MAX_REQUEST_BODY_BYTES) {
24
+ const buffer = await request.arrayBuffer();
25
+ if (buffer.byteLength > maxBytes || buffer.byteLength === 0) return null;
26
+ let parsed;
27
+ try {
28
+ parsed = JSON.parse(Buffer.from(buffer).toString("utf8"));
29
+ } catch {
30
+ return null;
31
+ }
32
+ return isRecord(parsed) ? parsed : null;
33
+ }
34
+ const HOST_ROUTES = {
35
+ approval: {
36
+ pending: "/api/dsh-evolution/approval/pending",
37
+ preview: "/api/dsh-evolution/approval/preview",
38
+ approve: "/api/dsh-evolution/approval/approve",
39
+ reject: "/api/dsh-evolution/approval/reject",
40
+ release: "/api/dsh-evolution/approval/release"
41
+ },
42
+ skillHistory: {
43
+ skills: "/api/dsh-evolution/skill-history/skills",
44
+ versions: "/api/dsh-evolution/skill-history/versions",
45
+ diff: "/api/dsh-evolution/skill-history/versions/diff",
46
+ body: "/api/dsh-evolution/skill-history/versions/body",
47
+ undo: "/api/dsh-evolution/skill-history/undo",
48
+ health: "/api/dsh-evolution/skill-history/health"
49
+ },
50
+ skillHealth: { rows: "/api/dsh-evolution/skill-health/rows" },
51
+ merge: {
52
+ view: "/api/dsh-evolution/merge/view",
53
+ rows: "/api/dsh-evolution/merge/rows",
54
+ run: "/api/dsh-evolution/merge/run",
55
+ runs: "/api/dsh-evolution/merge/runs",
56
+ body: "/api/dsh-evolution/merge/body",
57
+ history: "/api/dsh-evolution/merge/history"
58
+ },
59
+ diagnostics: { view: "/api/dsh-evolution/diagnostics" },
60
+ settings: {
61
+ describe: "/api/dsh-evolution/settings/describe",
62
+ mutate: "/api/dsh-evolution/settings/mutate"
63
+ }
64
+ };
65
+ function hostSurface(ctx) {
66
+ const connection = ctx.get("connection");
67
+ if (connection === void 0) return {
68
+ available: false,
69
+ code: "E-325",
70
+ reason: "connection-missing"
71
+ };
72
+ return {
73
+ available: true,
74
+ allowsRemoteAuthorities: connection.allowsRemoteAuthorities === true
75
+ };
76
+ }
77
+ function isLoopback(address) {
78
+ const value = address ?? "";
79
+ return value === "127.0.0.1" || value === "::1" || value === "::ffff:127.0.0.1";
80
+ }
81
+ function sameOrigin(origin, host) {
82
+ if (origin === void 0) return true;
83
+ try {
84
+ const parsed = new URL(origin);
85
+ return isLoopback(parsed.hostname) && host !== void 0 && parsed.host === host;
86
+ } catch {
87
+ return false;
88
+ }
89
+ }
90
+ function nodeRoute(route) {
91
+ return {
92
+ kind: "exact",
93
+ path: route.path,
94
+ handler: async (req, res) => {
95
+ if (!isLoopback(req.socket.remoteAddress)) {
96
+ res.statusCode = 403;
97
+ res.end("forbidden");
98
+ return;
99
+ }
100
+ if (!sameOrigin(req.headers.origin, req.headers.host)) {
101
+ res.statusCode = 403;
102
+ res.end("forbidden");
103
+ return;
104
+ }
105
+ const fetchSite = req.headers["sec-fetch-site"];
106
+ if (fetchSite !== void 0 && fetchSite !== "same-origin" && fetchSite !== "none") {
107
+ res.statusCode = 403;
108
+ res.end("forbidden");
109
+ return;
110
+ }
111
+ const method = req.method ?? "GET";
112
+ if (method !== "GET" && method !== "HEAD" && !(req.headers["content-type"] ?? "").toLowerCase().startsWith("application/json")) {
113
+ res.statusCode = 415;
114
+ res.end("json required");
115
+ return;
116
+ }
117
+ try {
118
+ const chunks = [];
119
+ for await (const chunk of req) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
120
+ const headers = new Headers();
121
+ for (const [key, value] of Object.entries(req.headers)) {
122
+ if (value === void 0) continue;
123
+ headers.set(key, Array.isArray(value) ? value.join(",") : value);
124
+ }
125
+ const request = new Request(new URL(req.url ?? "/", "http://127.0.0.1"), {
126
+ method,
127
+ headers,
128
+ ...method === "GET" || method === "HEAD" || chunks.length === 0 ? {} : { body: Buffer.concat(chunks) }
129
+ });
130
+ const response = await route.fetch(request);
131
+ res.statusCode = response.status;
132
+ response.headers.forEach((value, key) => {
133
+ try {
134
+ res.setHeader(key, value);
135
+ } catch {}
136
+ });
137
+ res.end(Buffer.from(await response.arrayBuffer()));
138
+ } catch (error) {
139
+ res.statusCode = 500;
140
+ res.end(error instanceof Error ? error.message : String(error));
141
+ }
142
+ }
143
+ };
144
+ }
145
+ function registerHostRoutes(owner, build) {
146
+ const injecting = owner;
147
+ if (typeof injecting.inject !== "function") throw new Error("host routes require a context that owns inject()");
148
+ injecting.inject(["connection"], (scope) => {
149
+ const connection = scope.connection;
150
+ const routes = build({
151
+ channel: "connection.fetch",
152
+ principal: "owner",
153
+ deploymentAllowsRemote: connection?.allowsRemoteAuthorities === true
154
+ });
155
+ 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);
156
+ const effect = scope.effect;
157
+ if (typeof effect !== "function") throw new Error("connection scope has no effect() to own the registration");
158
+ if (connection?.fetch !== void 0 && typeof connection.fetch.register === "function") {
159
+ const register = connection.fetch.register.bind(connection.fetch);
160
+ effect.call(scope, () => {
161
+ const disposers = [];
162
+ try {
163
+ for (const route of routes) disposers.push(register(route));
164
+ } catch (error) {
165
+ for (const dispose of disposers) try {
166
+ dispose();
167
+ } catch {}
168
+ throw error;
169
+ }
170
+ return () => {
171
+ for (const dispose of disposers) try {
172
+ dispose();
173
+ } catch {}
174
+ };
175
+ }, "evolution-host-routes");
176
+ return;
177
+ }
178
+ const web = scope.get?.("webServer") ?? owner.get?.("webServer");
179
+ 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");
180
+ effect.call(scope, () => {
181
+ const disposers = routes.map((route) => web.register(nodeRoute(route)));
182
+ return () => {
183
+ for (const dispose of disposers) try {
184
+ dispose();
185
+ } catch {}
186
+ };
187
+ }, "evolution-host-routes");
188
+ });
189
+ }
190
+ function json(status, body) {
191
+ return new Response(JSON.stringify(body), {
192
+ status,
193
+ headers: { "content-type": "application/json; charset=utf-8" }
194
+ });
195
+ }
196
+ function methodNotAllowed(allowed) {
197
+ return new Response(JSON.stringify({ error: "method-not-allowed" }), {
198
+ status: 405,
199
+ headers: {
200
+ "content-type": "application/json; charset=utf-8",
201
+ allow: allowed.join(", ")
202
+ }
203
+ });
204
+ }
205
+ //#endregion
2
206
  export { HOST_ROUTES, MAX_REQUEST_BODY_BYTES, hostSurface, json, methodNotAllowed, readJsonObject, registerHostRoutes };