@lmzhen/dsh-evolution-core 0.47.0 → 0.48.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/authority-plugin.js +1 -1
- package/lib/index.js +27 -114
- package/lib/{io-BCBSr6Ot.js → io-GxghO3Ip.js} +30 -8
- package/lib/io-node.js +1 -1
- package/lib/io-registry.js +1 -20
- package/lib/{mutation-authority-CM6wRgyK.js → mutation-authority-l57R626O.js} +14 -2
- package/lib/{mutations-DihgpfgG.js → mutations-DQXddSJd.js} +1 -1
- package/lib/{numeric-DLeLvvGb.js → numeric-D8js3sqC.js} +1 -5
- package/lib/platform/index.js +1 -1
- package/lib/{platform-CFA12Jam.js → platform-Cc9cNt5j.js} +4 -28
- package/lib/policy.js +1 -1
- package/lib/runtime/plugin.js +21 -43
- package/lib/{session-projection-BhlDXqws.js → session-projection-DSXnUNZG.js} +1 -19
- package/lib/{skill-health-BzkUQDi7.js → skill-health-DP8z9TPf.js} +3 -3
- package/lib/{skill-history-RWt1-kbZ.js → skill-history-CxrDE3Rb.js} +43 -51
- package/lib/skills.js +165 -183
- package/lib/types/authority.d.ts +2 -0
- package/lib/types/authority.js +5 -0
- package/lib/types/constants.d.ts +0 -4
- package/lib/types/constants.js +0 -4
- package/lib/types/contract.d.ts +0 -5
- package/lib/types/health-baseline.d.ts +0 -13
- package/lib/types/health-baseline.js +0 -20
- package/lib/types/home-fence.d.ts +2 -0
- package/lib/types/home-fence.js +11 -1
- package/lib/types/io-registry.d.ts +0 -16
- package/lib/types/io-registry.js +0 -24
- package/lib/types/io.d.ts +6 -1
- package/lib/types/io.js +35 -9
- package/lib/types/memory-store.js +13 -5
- package/lib/types/mutation-authority.js +5 -0
- package/lib/types/mutation-unit.d.ts +1 -1
- package/lib/types/mutation-unit.js +9 -27
- package/lib/types/params.d.ts +11 -29
- package/lib/types/params.js +13 -60
- package/lib/types/platform/llm.d.ts +2 -3
- package/lib/types/platform/llm.js +3 -10
- package/lib/types/platform/projections.d.ts +4 -5
- package/lib/types/platform/projections.js +4 -18
- package/lib/types/runtime/llm.js +2 -2
- package/lib/types/runtime/platform.d.ts +7 -11
- package/lib/types/runtime/platform.js +13 -19
- package/lib/types/runtime/plugin.d.ts +1 -1
- package/lib/types/runtime/plugin.js +6 -4
- package/lib/types/runtime/projections.js +1 -2
- package/lib/types/skill-health.d.ts +29 -1
- package/lib/types/skill-store.d.ts +6 -0
- package/lib/types/skill-store.js +130 -142
- package/lib/types/tool-dispatch.d.ts +1 -16
- package/lib/types/tool-dispatch.js +0 -18
- package/lib/types/unit-journal.js +19 -12
- package/lib/types/write-inventory.d.ts +0 -4
- package/lib/types/write-inventory.js +0 -9
- package/lib/types/write-kernel.d.ts +3 -4
- package/lib/types/write-kernel.js +13 -25
- package/lib/write.js +2 -2
- package/package.json +1 -1
- package/persisted-write-inventory.json +31 -13
package/lib/runtime/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as evolutionSignalsProjection, i as evolutionReadsProjection, n as evolutionEvidenceProjection, r as evolutionProjectionHistoryProjection, t as evolutionActivityProjection } from "../session-projection-
|
|
1
|
+
import { a as evolutionSignalsProjection, i as evolutionReadsProjection, n as evolutionEvidenceProjection, r as evolutionProjectionHistoryProjection, t as evolutionActivityProjection } from "../session-projection-DSXnUNZG.js";
|
|
2
2
|
import { t as presetsPort } from "../presets-C8vuCuNA.js";
|
|
3
|
-
import { d as EvolutionLlmError, f as llmPort, m as projectionPort, p as modelRoute } from "../platform-
|
|
3
|
+
import { d as EvolutionLlmError, f as llmPort, m as projectionPort, p as modelRoute } from "../platform-Cc9cNt5j.js";
|
|
4
4
|
import { n as toolsPort } from "../tools-DzcNFex2.js";
|
|
5
5
|
import { Service } from "@deepseek-ai/cordis";
|
|
6
6
|
//#region lib/types/runtime/llm.js
|
|
@@ -17,7 +17,7 @@ var EvolutionLlm = class extends Service {
|
|
|
17
17
|
}
|
|
18
18
|
[Service.init]() {
|
|
19
19
|
const platform = this.ctx.get("evolutionPlatform");
|
|
20
|
-
this.port = platform?.ports
|
|
20
|
+
this.port = platform?.ports.llm;
|
|
21
21
|
if (this.port === void 0) this.ctx.logger.warn("evolution-core-runtime: llm service unavailable; model calls fail with llm-unavailable");
|
|
22
22
|
}
|
|
23
23
|
/** Whether the platform llm service is mounted. */
|
|
@@ -79,44 +79,22 @@ var EvolutionLlm = class extends Service {
|
|
|
79
79
|
/** Domain service owning the host port table. */
|
|
80
80
|
var EvolutionPlatform = class extends Service {
|
|
81
81
|
static inject = [];
|
|
82
|
-
|
|
82
|
+
resolved;
|
|
83
83
|
constructor(ctx) {
|
|
84
84
|
super(ctx, "evolutionPlatform");
|
|
85
|
-
this.ports = {
|
|
86
|
-
projections: projectionPort(ctx),
|
|
87
|
-
llm: llmPort(ctx),
|
|
88
|
-
tools: toolsPort(ctx),
|
|
89
|
-
presets: presetsPort(ctx)
|
|
90
|
-
};
|
|
91
85
|
}
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
{
|
|
105
|
-
name: "llm",
|
|
106
|
-
available: this.ports.llm !== void 0,
|
|
107
|
-
...this.ports.llm === void 0 ? { reason: "llm unavailable" } : {}
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: "tools",
|
|
111
|
-
available: this.ports.tools !== void 0,
|
|
112
|
-
...this.ports.tools === void 0 ? { reason: "tools unavailable" } : {}
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
name: "presets",
|
|
116
|
-
available: this.ports.presets !== void 0,
|
|
117
|
-
...this.ports.presets === void 0 ? { reason: "agentPresets unavailable" } : {}
|
|
118
|
-
}
|
|
119
|
-
];
|
|
86
|
+
/**
|
|
87
|
+
* Resolve the host ports on first use and keep that answer for the service
|
|
88
|
+
* lifetime. Consumers read this one table; they never fall back to a direct
|
|
89
|
+
* platform import (the second resolution D7 removed).
|
|
90
|
+
*/
|
|
91
|
+
get ports() {
|
|
92
|
+
return this.resolved ??= {
|
|
93
|
+
projections: projectionPort(this.ctx),
|
|
94
|
+
llm: llmPort(this.ctx),
|
|
95
|
+
tools: toolsPort(this.ctx),
|
|
96
|
+
presets: presetsPort(this.ctx)
|
|
97
|
+
};
|
|
120
98
|
}
|
|
121
99
|
};
|
|
122
100
|
//#endregion
|
|
@@ -136,7 +114,7 @@ var EvolutionProjections = class extends Service {
|
|
|
136
114
|
super(ctx, "evolutionProjections");
|
|
137
115
|
}
|
|
138
116
|
async [Service.init]() {
|
|
139
|
-
const port = this.ctx.get("evolutionPlatform")?.ports
|
|
117
|
+
const port = this.ctx.get("evolutionPlatform")?.ports.projections;
|
|
140
118
|
if (port === void 0) {
|
|
141
119
|
this.markDegraded("sessionProjections service unavailable");
|
|
142
120
|
return;
|
|
@@ -195,10 +173,10 @@ var EvolutionProjections = class extends Service {
|
|
|
195
173
|
//#region lib/types/runtime/plugin.js
|
|
196
174
|
const name = "evolution-core-runtime";
|
|
197
175
|
/** @param ctx - the composition context that owns the runtime services. */
|
|
198
|
-
function apply(ctx) {
|
|
199
|
-
ctx.plugin(EvolutionPlatform);
|
|
200
|
-
ctx.plugin(EvolutionProjections);
|
|
201
|
-
ctx.plugin(EvolutionLlm);
|
|
176
|
+
async function apply(ctx) {
|
|
177
|
+
await ctx.plugin(EvolutionPlatform);
|
|
178
|
+
await ctx.plugin(EvolutionProjections);
|
|
179
|
+
await ctx.plugin(EvolutionLlm);
|
|
202
180
|
}
|
|
203
181
|
//#endregion
|
|
204
182
|
export { apply, name };
|
|
@@ -502,7 +502,6 @@ function isSkillReadToolName(name) {
|
|
|
502
502
|
return SKILL_READ_TOOL_NAMES.has(name);
|
|
503
503
|
}
|
|
504
504
|
/** Tool names whose dispatch opens a code program, i.e. whose sub-dispatches are \`program\`. */
|
|
505
|
-
const PROGRAM_TOOL_NAMES = new Set(["run_code"]);
|
|
506
505
|
/**
|
|
507
506
|
* Does this signal read one skill, and did it not fail?
|
|
508
507
|
* @param signal - a normalized dispatch.
|
|
@@ -651,14 +650,6 @@ function isSkillToolName(name) {
|
|
|
651
650
|
return SKILL_TOOL_NAMES.has(name);
|
|
652
651
|
}
|
|
653
652
|
/**
|
|
654
|
-
* Does this dispatched tool name open a code program?
|
|
655
|
-
* @param name - the dispatched tool name.
|
|
656
|
-
* @returns \`true\` for the tool whose sub-dispatches are \`program\` kind.
|
|
657
|
-
*/
|
|
658
|
-
function isProgramToolName(name) {
|
|
659
|
-
return PROGRAM_TOOL_NAMES.has(name);
|
|
660
|
-
}
|
|
661
|
-
/**
|
|
662
653
|
* Assert that a payload really is the dispatch event it claims to be.
|
|
663
654
|
*
|
|
664
655
|
* The normalizer is deliberately lenient (it also folds persisted logs, where a
|
|
@@ -687,15 +678,6 @@ function assertDispatchPayload(event) {
|
|
|
687
678
|
if (event.type === "tool/result") return;
|
|
688
679
|
throw new ToolDispatchPayloadError(`${event.type} is not a platform dispatch event; compare signal.kind instead of event types`);
|
|
689
680
|
}
|
|
690
|
-
/**
|
|
691
|
-
* Total dispatches in a log, deduplicated.
|
|
692
|
-
* @param events - the log, oldest first.
|
|
693
|
-
* @returns the number of distinct dispatches, one per dispatch regardless of
|
|
694
|
-
* how many events carried it.
|
|
695
|
-
*/
|
|
696
|
-
function countDispatches(events) {
|
|
697
|
-
return foldToolDispatches(events).length;
|
|
698
|
-
}
|
|
699
681
|
//#endregion
|
|
700
682
|
//#region lib/types/evidence.js
|
|
701
683
|
/**
|
|
@@ -1247,4 +1229,4 @@ function sessionEvidenceIndex(ctx, session) {
|
|
|
1247
1229
|
return { has: (seq) => Number.isInteger(seq) && seq >= 0 && seq <= through && !bookkeeping.includes(seq) };
|
|
1248
1230
|
}
|
|
1249
1231
|
//#endregion
|
|
1250
|
-
export {
|
|
1232
|
+
export { dispatchKeyOf as A, CITATION_SUPPORT_DIRS as B, PTC_DISPATCH_EVENT as C, assertDispatchPayload as D, ToolDispatchPayloadError as E, isSkillToolName as F, resolveCitations as G, HOOK_LINE_RE as H, readDispatchSignal as I, scanBodyHooks as K, skillReadNameOf as L, dispatchStepOf as M, foldToolDispatches as N, collectReadSkillNames as O, isSkillReadToolName as P, supportFileReadFromPath as R, NATIVE_RESULT_EVENT as S, ToolDispatchNormalizer as T, KEEP_LINE_RE as U, DEFAULT_CITATION_REF_BUDGET as V, isFileShapedPath as W, isBookkeepingFrame as _, evolutionSignalsProjection as a, MODEL_SESSION_EVENT_TYPES as b, sessionLastEventTime as c, advanceReview as d, foldTurnEvent as f, evidenceKindIndex as g, observeEvent as h, evolutionReadsProjection as i, dispatchPathOf as j, collectReadSupportFiles as k, sessionReadNames as l, initialTurnFold as m, evolutionEvidenceProjection as n, isProjectableSession as o, foldTurnEvents as p, evolutionProjectionHistoryProjection as r, sessionEvidenceIndex as s, evolutionActivityProjection as t, sessionTurnSignals as u, DEFAULT_SUPPORT_READ_TOOL_NAMES as v, PTC_DISPATCH_START_EVENT as w, NATIVE_CALL_EVENT as x, DISPATCH_EVENT_TYPES as y, supportFileReadOf as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { c as transactIo, o as nodeEvolutionIo } from "./io-GxghO3Ip.js";
|
|
2
|
+
import { G as resolveCitations, O as collectReadSkillNames, R as supportFileReadFromPath, k as collectReadSupportFiles, l as sessionReadNames, o as isProjectableSession, v as DEFAULT_SUPPORT_READ_TOOL_NAMES } from "./session-projection-DSXnUNZG.js";
|
|
3
|
+
import { K as SKILL_NAME_RE, M as DEFAULT_THREAT_MAX_SCAN_CHARS, Y as UPSTREAM_LIMIT_CHARS_PER_TOKEN, a as DEFAULT_SKILL_LIMITS, d as CONTENT_SPLIT_HINT, t as clampedNumber, u as AUTHORING_SPLIT_LINE_CHARS } from "./numeric-D8js3sqC.js";
|
|
4
4
|
import { n as isRecord } from "./guards-3f02mnf2.js";
|
|
5
5
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as contentHash } from "./mutations-
|
|
1
|
+
import { a as isProcessAlive, b as probeText, c as transactIo, i as isCommittedWarning, m as isUnknown, p as isPresent, t as TransactionNotInvokedError } from "./io-GxghO3Ip.js";
|
|
2
|
+
import { r as contentHash } from "./mutations-DQXddSJd.js";
|
|
3
3
|
import { basename, dirname, isAbsolute, join, relative } from "node:path";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
//#region lib/types/write-kernel.js
|
|
@@ -30,6 +30,7 @@ var WriteKernel = class {
|
|
|
30
30
|
async run(target, task) {
|
|
31
31
|
let invoked = false;
|
|
32
32
|
let conflict = false;
|
|
33
|
+
let transactionWarnings;
|
|
33
34
|
const invoke = async (current) => {
|
|
34
35
|
if (target.expected !== void 0 && current !== target.expected) {
|
|
35
36
|
conflict = true;
|
|
@@ -39,21 +40,15 @@ var WriteKernel = class {
|
|
|
39
40
|
return await task(current);
|
|
40
41
|
};
|
|
41
42
|
try {
|
|
42
|
-
if (this.transact !== void 0) await this.transact(this.io, target.path, invoke);
|
|
43
|
-
else
|
|
44
|
-
else {
|
|
45
|
-
const current = await this.io.readText(target.path);
|
|
46
|
-
const next = await invoke(current);
|
|
47
|
-
if (next === null && current !== null) await this.io.remove(target.path);
|
|
48
|
-
else if (next !== null && next !== current) await this.io.writeText(target.path, next);
|
|
49
|
-
}
|
|
43
|
+
if (this.transact !== void 0) transactionWarnings = await this.transact(this.io, target.path, invoke);
|
|
44
|
+
else transactionWarnings = await transactIo(this.io, target.path, invoke);
|
|
50
45
|
} catch (error) {
|
|
51
46
|
if (conflict) throw Object.assign(/* @__PURE__ */ new Error("concurrent modification detected: " + target.path), { noWrite: true });
|
|
52
47
|
if (isCommittedWarning(error)) return { warnings: [error instanceof Error ? error.message : String(error)] };
|
|
53
48
|
throw error;
|
|
54
49
|
}
|
|
55
50
|
if (!invoked) throw new Error("internal error: the write transaction for " + target.path + " did not invoke the task; no write was performed");
|
|
56
|
-
return {};
|
|
51
|
+
return transactionWarnings === void 0 ? {} : { warnings: transactionWarnings };
|
|
57
52
|
}
|
|
58
53
|
/**
|
|
59
54
|
* Write one target only if the current bytes still equal the baseline.
|
|
@@ -66,6 +61,7 @@ var WriteKernel = class {
|
|
|
66
61
|
let wrote = false;
|
|
67
62
|
let deferred = false;
|
|
68
63
|
let conflict = false;
|
|
64
|
+
let transactionWarnings;
|
|
69
65
|
const task = (current) => {
|
|
70
66
|
if (current !== target.expected) {
|
|
71
67
|
if (guard) {
|
|
@@ -79,14 +75,8 @@ var WriteKernel = class {
|
|
|
79
75
|
return target.next;
|
|
80
76
|
};
|
|
81
77
|
try {
|
|
82
|
-
if (this.transact !== void 0) await this.transact(this.io, target.path, task);
|
|
83
|
-
else
|
|
84
|
-
else {
|
|
85
|
-
const current = await this.io.readText(target.path);
|
|
86
|
-
const next = task(current);
|
|
87
|
-
if (next === null && current !== null) await this.io.remove(target.path);
|
|
88
|
-
else if (next !== null && next !== current) await this.io.writeText(target.path, next);
|
|
89
|
-
}
|
|
78
|
+
if (this.transact !== void 0) transactionWarnings = await this.transact(this.io, target.path, task);
|
|
79
|
+
else transactionWarnings = await transactIo(this.io, target.path, task);
|
|
90
80
|
} catch (error) {
|
|
91
81
|
if (conflict) return {
|
|
92
82
|
ok: false,
|
|
@@ -103,6 +93,15 @@ var WriteKernel = class {
|
|
|
103
93
|
errors: [],
|
|
104
94
|
warnings: [error instanceof Error ? error.message : String(error)]
|
|
105
95
|
};
|
|
96
|
+
if (error instanceof TransactionNotInvokedError) return {
|
|
97
|
+
ok: false,
|
|
98
|
+
changed: [],
|
|
99
|
+
errors: [{
|
|
100
|
+
code: "transact-not-invoked",
|
|
101
|
+
message: error.message,
|
|
102
|
+
target: target.path
|
|
103
|
+
}]
|
|
104
|
+
};
|
|
106
105
|
return {
|
|
107
106
|
ok: false,
|
|
108
107
|
changed: [],
|
|
@@ -134,7 +133,8 @@ var WriteKernel = class {
|
|
|
134
133
|
return {
|
|
135
134
|
ok: true,
|
|
136
135
|
changed: [target.path],
|
|
137
|
-
errors: []
|
|
136
|
+
errors: [],
|
|
137
|
+
...transactionWarnings === void 0 ? {} : { warnings: transactionWarnings }
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
@@ -411,7 +411,7 @@ var MutationUnit = class {
|
|
|
411
411
|
dryRun: false,
|
|
412
412
|
changed: [],
|
|
413
413
|
errors: [{
|
|
414
|
-
code: "unit-fence-failed",
|
|
414
|
+
code: error instanceof TransactionNotInvokedError ? "transact-not-invoked" : "unit-fence-failed",
|
|
415
415
|
message: error instanceof Error ? error.message : String(error)
|
|
416
416
|
}]
|
|
417
417
|
};
|
|
@@ -572,6 +572,7 @@ var MutationUnit = class {
|
|
|
572
572
|
rollbackFailure = rollbackError instanceof Error ? rollbackError.message : String(rollbackError);
|
|
573
573
|
}
|
|
574
574
|
const detail = rollbackFailure === "" ? message : message + "; rollback failed: " + rollbackFailure;
|
|
575
|
+
const failureCode = error?.code === "transact-not-invoked" ? "transact-not-invoked" : "write-failed";
|
|
575
576
|
await this.journal?.write({
|
|
576
577
|
unitId,
|
|
577
578
|
journalId: this.journalId,
|
|
@@ -602,7 +603,7 @@ var MutationUnit = class {
|
|
|
602
603
|
dryRun: false,
|
|
603
604
|
changed,
|
|
604
605
|
errors: [{
|
|
605
|
-
code:
|
|
606
|
+
code: failureCode,
|
|
606
607
|
message: detail
|
|
607
608
|
}]
|
|
608
609
|
};
|
|
@@ -653,7 +654,7 @@ var MutationUnit = class {
|
|
|
653
654
|
dryRun: false,
|
|
654
655
|
changed: [],
|
|
655
656
|
errors: [{
|
|
656
|
-
code: "unit-fence-failed",
|
|
657
|
+
code: error instanceof TransactionNotInvokedError ? "transact-not-invoked" : "unit-fence-failed",
|
|
657
658
|
message: error instanceof Error ? error.message : String(error)
|
|
658
659
|
}]
|
|
659
660
|
};
|
|
@@ -876,7 +877,10 @@ var MutationUnit = class {
|
|
|
876
877
|
next: op.kind === "delete" ? null : op.content,
|
|
877
878
|
...op.skill === void 0 ? {} : { skill: op.skill }
|
|
878
879
|
}, { guardBaseline: this.transactGuard });
|
|
879
|
-
if (!result.ok) throw Object.assign(new Error(result.errors[0]?.message ?? "write failed: " + op.target), {
|
|
880
|
+
if (!result.ok) throw Object.assign(new Error(result.errors[0]?.message ?? "write failed: " + op.target), {
|
|
881
|
+
noWrite: true,
|
|
882
|
+
code: result.errors[0]?.code
|
|
883
|
+
});
|
|
880
884
|
return [...result.warnings ?? []];
|
|
881
885
|
}
|
|
882
886
|
async rollback(snapshots) {
|
|
@@ -917,22 +921,7 @@ function fileMutationLock(io, root, options = {}) {
|
|
|
917
921
|
const now = options.now ?? Date.now;
|
|
918
922
|
const sleep = options.sleep ?? defaultSleep;
|
|
919
923
|
const update = async (task) => {
|
|
920
|
-
|
|
921
|
-
let ran = false;
|
|
922
|
-
await io.transact(path, (current) => {
|
|
923
|
-
ran = true;
|
|
924
|
-
return task(current);
|
|
925
|
-
});
|
|
926
|
-
if (!ran) throw new Error("mutation-lock-transact-not-run: " + path);
|
|
927
|
-
return;
|
|
928
|
-
}
|
|
929
|
-
const next = task(await io.readText(path));
|
|
930
|
-
try {
|
|
931
|
-
if (next === null) await io.remove(path);
|
|
932
|
-
else await io.writeText(path, next);
|
|
933
|
-
} catch (error) {
|
|
934
|
-
if (!isCommittedWarning(error)) throw error;
|
|
935
|
-
}
|
|
924
|
+
await transactIo(io, path, task);
|
|
936
925
|
};
|
|
937
926
|
return { async acquire() {
|
|
938
927
|
const deadline = now() + waitMs;
|
|
@@ -1096,17 +1085,7 @@ function assertUnitJournalTransition(from, to) {
|
|
|
1096
1085
|
if (from === "failed" || from === "rolled-back") throw new Error("unit-journal-terminal:" + from);
|
|
1097
1086
|
if (unitJournalPhaseRank(to) <= unitJournalPhaseRank(from)) throw new Error("unit-journal-nonmonotonic:" + from + "->" + to);
|
|
1098
1087
|
}
|
|
1099
|
-
|
|
1100
|
-
const key = journal.journalId ?? journal.unitId;
|
|
1101
|
-
const path = unitJournalPath(home, key, scope);
|
|
1102
|
-
const existing = await readUnitJournal(io, home, key, scope);
|
|
1103
|
-
if (existing !== null) assertUnitJournalTransition(existing.phase, journal.phase);
|
|
1104
|
-
const content = JSON.stringify(journal, null, 2) + "\n";
|
|
1105
|
-
await transactIo(io, path, () => content);
|
|
1106
|
-
return path;
|
|
1107
|
-
}
|
|
1108
|
-
async function readUnitJournal(io, home, unitId, scope = "merge") {
|
|
1109
|
-
const raw = await io.readText(unitJournalPath(home, unitId, scope));
|
|
1088
|
+
function parseUnitJournal(raw) {
|
|
1110
1089
|
if (raw === null) return null;
|
|
1111
1090
|
try {
|
|
1112
1091
|
return JSON.parse(raw);
|
|
@@ -1114,6 +1093,19 @@ async function readUnitJournal(io, home, unitId, scope = "merge") {
|
|
|
1114
1093
|
return null;
|
|
1115
1094
|
}
|
|
1116
1095
|
}
|
|
1096
|
+
async function writeUnitJournal(io, home, journal, scope = "merge") {
|
|
1097
|
+
const path = unitJournalPath(home, journal.journalId ?? journal.unitId, scope);
|
|
1098
|
+
const content = JSON.stringify(journal, null, 2) + "\n";
|
|
1099
|
+
await transactIo(io, path, (current) => {
|
|
1100
|
+
const existing = parseUnitJournal(current);
|
|
1101
|
+
if (existing !== null) assertUnitJournalTransition(existing.phase, journal.phase);
|
|
1102
|
+
return content;
|
|
1103
|
+
});
|
|
1104
|
+
return path;
|
|
1105
|
+
}
|
|
1106
|
+
async function readUnitJournal(io, home, unitId, scope = "merge") {
|
|
1107
|
+
return parseUnitJournal(await io.readText(unitJournalPath(home, unitId, scope)));
|
|
1108
|
+
}
|
|
1117
1109
|
//#endregion
|
|
1118
1110
|
//#region lib/types/mutation-storage-adapter.js
|
|
1119
1111
|
/**
|