@lmzhen/dsh-evolution-core 0.40.1 → 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.
- package/lib/composition/index.js +2 -2
- package/lib/{composition-dy0gJWDd.js → composition-CVafrlEw.js} +2 -2
- package/lib/{ensure-B4fjEI0w.js → ensure-BjToTMMj.js} +2 -2
- package/lib/errors-BxzLTVbS.js +399 -0
- package/lib/guards-3f02mnf2.js +29 -0
- package/lib/http-routes.js +205 -1
- package/lib/index.js +3588 -15049
- package/lib/mutations-jUuOPaCn.js +718 -0
- package/lib/platform/index.js +2 -2
- package/lib/{platform-CFp373_0.js → platform-B06_h8t-.js} +4 -1
- package/lib/restrictor.js +1 -1
- package/lib/runtime/plugin.js +2 -2
- package/lib/{session-projection-CXUNPkq9.js → session-projection-EB7mUOlJ.js} +63 -63
- package/lib/skill-health-BLGZTIv8.js +3773 -0
- package/lib/skill-history-_Cssts5o.js +1912 -0
- package/lib/skills.js +4067 -0
- package/lib/subagent/index.js +1 -1
- package/lib/types/errors.d.ts +12 -0
- package/lib/types/errors.js +17 -0
- package/lib/types/generated/errors.localized.d.ts +320 -0
- package/lib/types/generated/errors.localized.js +318 -0
- package/lib/types/home-fence.d.ts +7 -0
- package/lib/types/home-fence.js +58 -3
- package/lib/types/index.d.ts +1 -18
- package/lib/types/index.js +1 -18
- package/lib/types/io.js +1 -1
- package/lib/types/mutation-authority.d.ts +14 -37
- package/lib/types/mutation-authority.js +16 -103
- package/lib/types/mutation-storage-adapter.js +9 -6
- package/lib/types/mutation-unit.d.ts +14 -0
- package/lib/types/mutation-unit.js +30 -10
- package/lib/types/opt-in.js +1 -1
- package/lib/types/platform/index.d.ts +8 -1
- package/lib/types/platform/index.js +3 -0
- package/lib/types/review-channel.js +3 -1
- package/lib/types/review-context.js +3 -1
- package/lib/types/run-registry.d.ts +2 -24
- package/lib/types/scope.js +1 -1
- package/lib/types/signals.d.ts +1 -1
- package/lib/types/skill-store.d.ts +7 -1
- package/lib/types/skill-store.js +43 -80
- package/lib/types/skills.d.ts +11 -0
- package/lib/types/skills.js +11 -0
- package/lib/types/subagent/types.d.ts +3 -3
- package/lib/types/tree-lock.js +4 -1
- package/lib/types/unit-claim.d.ts +8 -0
- package/lib/types/unit-claim.js +3 -0
- package/lib/types/unit-journal.d.ts +3 -1
- package/lib/types/unit-journal.js +12 -3
- package/lib/types/unit-storage.d.ts +1 -0
- package/lib/types/write-gates.d.ts +1 -1
- package/lib/types/write-gates.js +3 -1
- package/lib/types/write.d.ts +11 -0
- package/lib/types/write.js +11 -0
- package/lib/write.js +357 -0
- package/package.json +16 -4
- package/lib/errors-DUcEoTLR.js +0 -58
- package/lib/http-routes-_anZVlPf.js +0 -233
- package/lib/types/unit-backend.d.ts +0 -5
- package/lib/types/unit-backend.js +0 -55
- package/lib/types/unit-transaction.d.ts +0 -225
- package/lib/types/unit-transaction.js +0 -501
|
@@ -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
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export function skillLibraryUnitBackend(skills) {
|
|
2
|
-
return {
|
|
3
|
-
async readSkill(name) { return await skills.read(name); },
|
|
4
|
-
async readSupportFile(name, path) {
|
|
5
|
-
const probe = skills.readSupportFile;
|
|
6
|
-
return typeof probe === 'function' ? await probe.call(skills, name, path) : null;
|
|
7
|
-
},
|
|
8
|
-
async commit(plan, onPhase, signal, assertFence) {
|
|
9
|
-
const result = await skills.commitMerge({
|
|
10
|
-
...(plan.runId === undefined ? {} : { runId: plan.runId }),
|
|
11
|
-
...(plan.unitId === undefined ? {} : { unitId: plan.unitId }),
|
|
12
|
-
target: plan.target,
|
|
13
|
-
targetExists: plan.targetExists,
|
|
14
|
-
sources: plan.sources,
|
|
15
|
-
body: plan.body,
|
|
16
|
-
supportFiles: plan.supportFiles,
|
|
17
|
-
expectedTargetBody: plan.expectedTargetBody,
|
|
18
|
-
expectedSourceBodies: plan.expectedSourceBodies,
|
|
19
|
-
origin: plan.origin,
|
|
20
|
-
summary: plan.summary,
|
|
21
|
-
...(plan.skillLimits === undefined ? {} : { limits: plan.skillLimits }),
|
|
22
|
-
...(plan.targetRevision === undefined ? {} : { targetRevision: plan.targetRevision }),
|
|
23
|
-
...(plan.sourceRevisions === undefined ? {} : { sourceRevisions: plan.sourceRevisions }),
|
|
24
|
-
...(plan.supportDigest === undefined ? {} : { supportDigest: plan.supportDigest }),
|
|
25
|
-
...(onPhase === undefined ? {} : { onPhase }),
|
|
26
|
-
...(signal === undefined ? {} : { signal }),
|
|
27
|
-
...(assertFence === undefined ? {} : { assertFence }),
|
|
28
|
-
});
|
|
29
|
-
return { ok: result.ok, message: result.message, ...(result.code === undefined ? {} : { code: result.code }), ...(result.archived === undefined ? {} : { archived: result.archived }), ...(result.mutations === undefined ? {} : { mutations: result.mutations }) };
|
|
30
|
-
},
|
|
31
|
-
async restoreTarget(name, body) {
|
|
32
|
-
if (body === null) {
|
|
33
|
-
await skills.archive(name, { reason: 'unit-rollback' });
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const result = await skills.update(name, body);
|
|
37
|
-
if (!result.ok)
|
|
38
|
-
throw new Error(result.message);
|
|
39
|
-
},
|
|
40
|
-
async restoreSupportFile(name, path, content) {
|
|
41
|
-
const result = content === null ? await skills.removeSupportFile(name, path) : await skills.writeSupportFile(name, path, content);
|
|
42
|
-
if (!result.ok)
|
|
43
|
-
throw new Error(result.message);
|
|
44
|
-
},
|
|
45
|
-
async restoreSource(name, body) {
|
|
46
|
-
const restored = await skills.restoreFromArchive(name);
|
|
47
|
-
if (restored.ok)
|
|
48
|
-
return;
|
|
49
|
-
const result = await skills.update(name, body);
|
|
50
|
-
if (!result.ok)
|
|
51
|
-
throw new Error(result.message);
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=unit-backend.js.map
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import type { EvolutionIoLike } from "./io.ts";
|
|
2
|
-
import type { HomeFence } from './home-fence.ts';
|
|
3
|
-
import { type UnitEvidenceRecord } from "./unit-storage.ts";
|
|
4
|
-
import { type UnitJournalPhase } from "./unit-journal.ts";
|
|
5
|
-
export interface UnitSupportFile {
|
|
6
|
-
readonly path: string;
|
|
7
|
-
readonly content: string;
|
|
8
|
-
}
|
|
9
|
-
export interface UnitPlan {
|
|
10
|
-
readonly runId: string;
|
|
11
|
-
/** Filled by the transaction before the backend write; history records it. */
|
|
12
|
-
readonly unitId?: string;
|
|
13
|
-
readonly pairKey: string;
|
|
14
|
-
readonly target: string;
|
|
15
|
-
readonly targetExists: boolean;
|
|
16
|
-
readonly sources: readonly string[];
|
|
17
|
-
readonly body: string;
|
|
18
|
-
readonly supportFiles: readonly UnitSupportFile[];
|
|
19
|
-
readonly expectedTargetBody: string | null;
|
|
20
|
-
readonly expectedSourceBodies: readonly {
|
|
21
|
-
name: string;
|
|
22
|
-
body: string;
|
|
23
|
-
}[];
|
|
24
|
-
readonly origin: "foreground" | "subagent" | "background_review";
|
|
25
|
-
readonly summary: string;
|
|
26
|
-
readonly skillLimits?: import("./limits.ts").SkillLimits;
|
|
27
|
-
readonly limitsDigest?: string;
|
|
28
|
-
readonly validationPlan?: {
|
|
29
|
-
readonly planVersion: 1;
|
|
30
|
-
readonly stageDigest: string;
|
|
31
|
-
readonly revision: string;
|
|
32
|
-
};
|
|
33
|
-
readonly targetRevision?: {
|
|
34
|
-
readonly kind: 'absent';
|
|
35
|
-
} | {
|
|
36
|
-
readonly kind: 'present';
|
|
37
|
-
readonly sha256: string;
|
|
38
|
-
};
|
|
39
|
-
readonly sourceRevisions?: Readonly<Record<string, {
|
|
40
|
-
readonly kind: 'absent';
|
|
41
|
-
} | {
|
|
42
|
-
readonly kind: 'present';
|
|
43
|
-
readonly sha256: string;
|
|
44
|
-
}>>;
|
|
45
|
-
readonly supportDigest?: string;
|
|
46
|
-
}
|
|
47
|
-
export interface UnitCommitResult {
|
|
48
|
-
readonly ok: boolean;
|
|
49
|
-
readonly message: string;
|
|
50
|
-
/** Typed backend refusal (revision CAS); absent means a generic commit failure. */
|
|
51
|
-
readonly code?: UnitErrorCode;
|
|
52
|
-
readonly archived?: readonly string[];
|
|
53
|
-
readonly mutations?: number;
|
|
54
|
-
}
|
|
55
|
-
export interface UnitBackend {
|
|
56
|
-
readSkill(name: string): Promise<string | null>;
|
|
57
|
-
readSupportFile(name: string, path: string): Promise<string | null>;
|
|
58
|
-
commit(plan: UnitPlan, onPhase?: (phase: "target-pending" | "target-applied" | "target-written" | "source-archiving" | "sources-archived" | "support-pending" | "unit-written", detail?: {
|
|
59
|
-
source?: string;
|
|
60
|
-
}) => void | Promise<void>, signal?: AbortSignal, assertFence?: () => Promise<boolean>): Promise<UnitCommitResult>;
|
|
61
|
-
restoreTarget(name: string, body: string | null): Promise<void>;
|
|
62
|
-
restoreSource(name: string, body: string): Promise<void>;
|
|
63
|
-
restoreSupportFile?(name: string, path: string, content: string | null): Promise<void>;
|
|
64
|
-
}
|
|
65
|
-
export interface UnitClaim {
|
|
66
|
-
release(): Promise<void>;
|
|
67
|
-
}
|
|
68
|
-
export interface UnitClaimPort {
|
|
69
|
-
acquire(target: string, runId: string): Promise<UnitClaim>;
|
|
70
|
-
}
|
|
71
|
-
export interface UnitTransactionOptions {
|
|
72
|
-
readonly io: EvolutionIoLike;
|
|
73
|
-
readonly home: string;
|
|
74
|
-
readonly backend: UnitBackend;
|
|
75
|
-
readonly claim: UnitClaimPort;
|
|
76
|
-
readonly now?: () => number;
|
|
77
|
-
readonly waitMs?: number;
|
|
78
|
-
/** Gate/fault-injection seam: called after each journal phase is durable. */
|
|
79
|
-
readonly onPhase?: (phase: UnitJournalPhase) => void | Promise<void>;
|
|
80
|
-
/** Gate instrumentation: tree fence then target claim. */
|
|
81
|
-
readonly onLock?: (lock: "tree" | "claim") => void;
|
|
82
|
-
/** One home fence owned by authority; when set, UnitTransactions must not acquire tree-lock itself. */
|
|
83
|
-
readonly fence?: HomeFence;
|
|
84
|
-
/** Optional run liveness gate: false means the run is terminal and must not commit. */
|
|
85
|
-
readonly isActive?: (runId: string) => boolean | Promise<boolean>;
|
|
86
|
-
}
|
|
87
|
-
export type UnitErrorCode = "unit-plan-missing" | "unit-conflict" | "unit-committed" | "unit-prepare-failed" | "unit-commit-failed" | "unit-claim-failed" | "unit-fence-failed" | "unit-run-inactive" | "unit-rollback-blocked" | "target-changed" | "source-changed" | "support-changed";
|
|
88
|
-
export interface UnitFailure {
|
|
89
|
-
readonly ok: false;
|
|
90
|
-
readonly code: UnitErrorCode;
|
|
91
|
-
readonly message: string;
|
|
92
|
-
}
|
|
93
|
-
export interface UnitPrepared {
|
|
94
|
-
readonly unitId: string;
|
|
95
|
-
readonly planDigest: string;
|
|
96
|
-
}
|
|
97
|
-
export interface UnitTransaction {
|
|
98
|
-
prepare(plan: UnitPlan): Promise<{
|
|
99
|
-
ok: true;
|
|
100
|
-
prepared: UnitPrepared;
|
|
101
|
-
} | UnitFailure>;
|
|
102
|
-
commit(prepared: UnitPrepared, options?: {
|
|
103
|
-
signal?: AbortSignal;
|
|
104
|
-
}): Promise<{
|
|
105
|
-
ok: true;
|
|
106
|
-
evidence: UnitEvidenceRecord;
|
|
107
|
-
} | UnitFailure>;
|
|
108
|
-
verify(ref: {
|
|
109
|
-
unitId: string;
|
|
110
|
-
} | {
|
|
111
|
-
runId: string;
|
|
112
|
-
}): Promise<UnitEvidenceRecord | UnitEvidenceRecord[] | null>;
|
|
113
|
-
rollback(ref: {
|
|
114
|
-
unitId: string;
|
|
115
|
-
reason: string;
|
|
116
|
-
}): Promise<{
|
|
117
|
-
ok: true;
|
|
118
|
-
evidence: UnitEvidenceRecord;
|
|
119
|
-
} | UnitFailure>;
|
|
120
|
-
finalize(unitId: string): Promise<{
|
|
121
|
-
ok: true;
|
|
122
|
-
evidence: UnitEvidenceRecord;
|
|
123
|
-
} | UnitFailure>;
|
|
124
|
-
rollForward(unitId: string): Promise<{
|
|
125
|
-
ok: true;
|
|
126
|
-
evidence: UnitEvidenceRecord;
|
|
127
|
-
} | UnitFailure>;
|
|
128
|
-
cancel(unitId: string, reason: string): Promise<{
|
|
129
|
-
ok: boolean;
|
|
130
|
-
phase: UnitJournalPhase | "none";
|
|
131
|
-
}>;
|
|
132
|
-
}
|
|
133
|
-
export declare function unitEvidenceDigest(evidence: UnitEvidenceRecord): string;
|
|
134
|
-
export declare class UnitTransactions implements UnitTransaction {
|
|
135
|
-
private readonly options;
|
|
136
|
-
private readonly prepared;
|
|
137
|
-
private readonly commits;
|
|
138
|
-
private readonly now;
|
|
139
|
-
constructor(options: UnitTransactionOptions);
|
|
140
|
-
private unitId;
|
|
141
|
-
private snapshot;
|
|
142
|
-
prepare(plan: UnitPlan): Promise<{
|
|
143
|
-
ok: true;
|
|
144
|
-
prepared: {
|
|
145
|
-
unitId: string;
|
|
146
|
-
planDigest: string;
|
|
147
|
-
};
|
|
148
|
-
code?: never;
|
|
149
|
-
message?: never;
|
|
150
|
-
} | {
|
|
151
|
-
ok: false;
|
|
152
|
-
code: "unit-conflict";
|
|
153
|
-
message: string;
|
|
154
|
-
prepared?: never;
|
|
155
|
-
}>;
|
|
156
|
-
commit(prepared: UnitPrepared, options?: {
|
|
157
|
-
signal?: AbortSignal;
|
|
158
|
-
}): Promise<{
|
|
159
|
-
ok: true;
|
|
160
|
-
evidence: UnitEvidenceRecord;
|
|
161
|
-
} | UnitFailure>;
|
|
162
|
-
private commitOnce;
|
|
163
|
-
verify(ref: {
|
|
164
|
-
unitId: string;
|
|
165
|
-
} | {
|
|
166
|
-
runId: string;
|
|
167
|
-
}): Promise<UnitEvidenceRecord | UnitEvidenceRecord[] | null>;
|
|
168
|
-
finalize(unitId: string): Promise<{
|
|
169
|
-
ok: true;
|
|
170
|
-
evidence: UnitEvidenceRecord;
|
|
171
|
-
code?: never;
|
|
172
|
-
message?: never;
|
|
173
|
-
} | {
|
|
174
|
-
ok: false;
|
|
175
|
-
code: "unit-rollback-blocked";
|
|
176
|
-
message: string;
|
|
177
|
-
evidence?: never;
|
|
178
|
-
}>;
|
|
179
|
-
rollForward(unitId: string): Promise<{
|
|
180
|
-
ok: true;
|
|
181
|
-
evidence: UnitEvidenceRecord;
|
|
182
|
-
code?: never;
|
|
183
|
-
message?: never;
|
|
184
|
-
} | {
|
|
185
|
-
ok: false;
|
|
186
|
-
code: "unit-rollback-blocked";
|
|
187
|
-
message: string;
|
|
188
|
-
evidence?: never;
|
|
189
|
-
}>;
|
|
190
|
-
rollback(ref: {
|
|
191
|
-
unitId: string;
|
|
192
|
-
reason: string;
|
|
193
|
-
}): Promise<{
|
|
194
|
-
ok: false;
|
|
195
|
-
code: "unit-committed";
|
|
196
|
-
message: string;
|
|
197
|
-
evidence?: never;
|
|
198
|
-
} | {
|
|
199
|
-
ok: false;
|
|
200
|
-
code: "unit-rollback-blocked";
|
|
201
|
-
message: string;
|
|
202
|
-
evidence?: never;
|
|
203
|
-
} | {
|
|
204
|
-
ok: false;
|
|
205
|
-
code: "unit-fence-failed";
|
|
206
|
-
message: string;
|
|
207
|
-
evidence?: never;
|
|
208
|
-
} | {
|
|
209
|
-
ok: true;
|
|
210
|
-
evidence: UnitEvidenceRecord;
|
|
211
|
-
code?: never;
|
|
212
|
-
message?: never;
|
|
213
|
-
}>;
|
|
214
|
-
cancel(unitId: string, reason: string): Promise<{
|
|
215
|
-
ok: boolean;
|
|
216
|
-
phase: "none";
|
|
217
|
-
} | {
|
|
218
|
-
ok: boolean;
|
|
219
|
-
phase: "target-pending" | "target-written" | "source-archiving" | "sources-archived";
|
|
220
|
-
} | {
|
|
221
|
-
ok: boolean;
|
|
222
|
-
phase: "failed" | "prepared" | "unit-written" | "committed" | "support-pending" | "rolled-back";
|
|
223
|
-
}>;
|
|
224
|
-
}
|
|
225
|
-
//# sourceMappingURL=unit-transaction.d.ts.map
|