@lmzhen/dsh-evolution-core 0.46.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/composition/index.js +3 -3
- package/lib/{composition-Da8NfRI7.js → composition-Cqjbho0t.js} +1 -1
- package/lib/{ensure-C5Mo1dbB.js → ensure-CAjLGd9f.js} +1 -2
- package/lib/http-routes.js +21 -96
- package/lib/index.js +47 -246
- package/lib/{io-AmUf4lVY.js → io-GxghO3Ip.js} +30 -70
- package/lib/io-node.js +1 -1
- package/lib/io-registry.js +1 -35
- package/lib/{mutation-authority-DeJ_Wz14.js → mutation-authority-l57R626O.js} +17 -15
- package/lib/{mutations-DwvbjRHF.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-EB7mUOlJ.js → session-projection-DSXnUNZG.js} +3 -21
- package/lib/{skill-health-D1pZGk5V.js → skill-health-DP8z9TPf.js} +4 -25
- package/lib/{skill-history-CjypdYqv.js → skill-history-CxrDE3Rb.js} +54 -102
- package/lib/skills.js +166 -184
- package/lib/subagent/index.js +4 -10
- package/lib/types/authority.d.ts +2 -0
- package/lib/types/authority.js +5 -0
- package/lib/types/composition/preset-ids.d.ts +0 -1
- package/lib/types/composition/preset-ids.js +0 -1
- 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/curator.d.ts +0 -1
- package/lib/types/curator.js +0 -1
- package/lib/types/document-body.d.ts +0 -12
- package/lib/types/document-body.js +0 -14
- 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/http-routes.d.ts +9 -4
- package/lib/types/http-routes.js +36 -116
- package/lib/types/index.d.ts +0 -3
- package/lib/types/index.js +0 -3
- package/lib/types/io-registry.d.ts +0 -16
- package/lib/types/io-registry.js +0 -27
- package/lib/types/io.d.ts +6 -54
- package/lib/types/io.js +35 -65
- package/lib/types/journal-protocol.d.ts +0 -15
- package/lib/types/journal-protocol.js +1 -19
- package/lib/types/lease-store.d.ts +1 -1
- package/lib/types/lease-store.js +4 -15
- package/lib/types/live.d.ts +0 -12
- package/lib/types/live.js +0 -18
- package/lib/types/memory-store.d.ts +0 -1
- package/lib/types/memory-store.js +13 -6
- package/lib/types/mutation-authority.js +5 -0
- package/lib/types/mutation-unit.d.ts +1 -1
- package/lib/types/mutation-unit.js +14 -31
- 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/probe.d.ts +0 -3
- package/lib/types/probe.js +0 -7
- package/lib/types/run-registry.js +10 -12
- 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/session-fold.d.ts +0 -8
- package/lib/types/session-fold.js +0 -5
- package/lib/types/session-projection.js +2 -2
- package/lib/types/skill-discovery.d.ts +0 -2
- package/lib/types/skill-discovery.js +1 -2
- package/lib/types/skill-health.d.ts +29 -1
- package/lib/types/skill-history.d.ts +0 -24
- package/lib/types/skill-history.js +0 -41
- package/lib/types/skill-lint.d.ts +0 -3
- package/lib/types/skill-lint.js +0 -12
- package/lib/types/skill-store.d.ts +6 -0
- package/lib/types/skill-store.js +130 -142
- package/lib/types/subagent/readiness.d.ts +0 -1
- package/lib/types/subagent/readiness.js +2 -8
- package/lib/types/tool-dispatch.d.ts +1 -16
- package/lib/types/tool-dispatch.js +0 -18
- package/lib/types/unit-journal.d.ts +1 -1
- package/lib/types/unit-journal.js +20 -15
- package/lib/types/unit-storage.d.ts +1 -1
- package/lib/types/unit-storage.js +5 -16
- 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 +72 -9
- package/lib/types/fold-untrusted.d.ts +0 -35
- package/lib/types/fold-untrusted.js +0 -44
- package/lib/types/unit-recovery.d.ts +0 -5
- package/lib/types/unit-recovery.js +0 -12
|
@@ -222,6 +222,7 @@ export declare function readDispatchSignal(event: {
|
|
|
222
222
|
* @returns \`true\` only for the read tool whose arguments name one skill.
|
|
223
223
|
*/
|
|
224
224
|
export declare function isSkillReadToolName(name: string): boolean;
|
|
225
|
+
/** Tool names whose dispatch opens a code program, i.e. whose sub-dispatches are \`program\`. */
|
|
225
226
|
/**
|
|
226
227
|
* Does this signal read one skill, and did it not fail?
|
|
227
228
|
* @param signal - a normalized dispatch.
|
|
@@ -296,12 +297,6 @@ export declare function collectReadSupportFiles(events: Iterable<{
|
|
|
296
297
|
* skill signal, which has always covered reads and writes alike.
|
|
297
298
|
*/
|
|
298
299
|
export declare function isSkillToolName(name: string): boolean;
|
|
299
|
-
/**
|
|
300
|
-
* Does this dispatched tool name open a code program?
|
|
301
|
-
* @param name - the dispatched tool name.
|
|
302
|
-
* @returns \`true\` for the tool whose sub-dispatches are \`program\` kind.
|
|
303
|
-
*/
|
|
304
|
-
export declare function isProgramToolName(name: string): boolean;
|
|
305
300
|
/**
|
|
306
301
|
* Assert that a payload really is the dispatch event it claims to be.
|
|
307
302
|
*
|
|
@@ -321,14 +316,4 @@ export declare function assertDispatchPayload(event: {
|
|
|
321
316
|
type: string;
|
|
322
317
|
data?: unknown;
|
|
323
318
|
}): void;
|
|
324
|
-
/**
|
|
325
|
-
* Total dispatches in a log, deduplicated.
|
|
326
|
-
* @param events - the log, oldest first.
|
|
327
|
-
* @returns the number of distinct dispatches, one per dispatch regardless of
|
|
328
|
-
* how many events carried it.
|
|
329
|
-
*/
|
|
330
|
-
export declare function countDispatches(events: Iterable<{
|
|
331
|
-
type: string;
|
|
332
|
-
data?: unknown;
|
|
333
|
-
}>): number;
|
|
334
319
|
//# sourceMappingURL=tool-dispatch.d.ts.map
|
|
@@ -346,7 +346,6 @@ export function isSkillReadToolName(name) {
|
|
|
346
346
|
return SKILL_READ_TOOL_NAMES.has(name);
|
|
347
347
|
}
|
|
348
348
|
/** Tool names whose dispatch opens a code program, i.e. whose sub-dispatches are \`program\`. */
|
|
349
|
-
const PROGRAM_TOOL_NAMES = new Set(['run_code']);
|
|
350
349
|
/**
|
|
351
350
|
* Does this signal read one skill, and did it not fail?
|
|
352
351
|
* @param signal - a normalized dispatch.
|
|
@@ -510,14 +509,6 @@ const SKILL_TOOL_NAMES = new Set([...SKILL_READ_TOOL_NAMES, 'skill_manage']);
|
|
|
510
509
|
export function isSkillToolName(name) {
|
|
511
510
|
return SKILL_TOOL_NAMES.has(name);
|
|
512
511
|
}
|
|
513
|
-
/**
|
|
514
|
-
* Does this dispatched tool name open a code program?
|
|
515
|
-
* @param name - the dispatched tool name.
|
|
516
|
-
* @returns \`true\` for the tool whose sub-dispatches are \`program\` kind.
|
|
517
|
-
*/
|
|
518
|
-
export function isProgramToolName(name) {
|
|
519
|
-
return PROGRAM_TOOL_NAMES.has(name);
|
|
520
|
-
}
|
|
521
512
|
/**
|
|
522
513
|
* Assert that a payload really is the dispatch event it claims to be.
|
|
523
514
|
*
|
|
@@ -554,13 +545,4 @@ export function assertDispatchPayload(event) {
|
|
|
554
545
|
return;
|
|
555
546
|
throw new ToolDispatchPayloadError(`${event.type} is not a platform dispatch event; compare signal.kind instead of event types`);
|
|
556
547
|
}
|
|
557
|
-
/**
|
|
558
|
-
* Total dispatches in a log, deduplicated.
|
|
559
|
-
* @param events - the log, oldest first.
|
|
560
|
-
* @returns the number of distinct dispatches, one per dispatch regardless of
|
|
561
|
-
* how many events carried it.
|
|
562
|
-
*/
|
|
563
|
-
export function countDispatches(events) {
|
|
564
|
-
return foldToolDispatches(events).length;
|
|
565
|
-
}
|
|
566
548
|
//# sourceMappingURL=tool-dispatch.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EvolutionIoLike } from './io.ts';
|
|
2
2
|
export declare const UNIT_JOURNAL_SCHEMA_VERSION = 1;
|
|
3
3
|
export declare const UNIT_JOURNAL_PHASES: readonly ["prepared", "target-pending", "target-written", "source-archiving", "support-pending", "sources-archived", "unit-written", "committed", "failed", "rolled-back"];
|
|
4
4
|
export type UnitJournalPhase = typeof UNIT_JOURNAL_PHASES[number];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** G2 unit journal: intent/phase/checkpoint only, never evidence bodies. */
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { transactIo } from "./io.js";
|
|
4
5
|
export const UNIT_JOURNAL_SCHEMA_VERSION = 1;
|
|
5
6
|
export const UNIT_JOURNAL_PHASES = [
|
|
6
7
|
'prepared',
|
|
@@ -34,21 +35,7 @@ export function assertUnitJournalTransition(from, to) {
|
|
|
34
35
|
if (unitJournalPhaseRank(to) <= unitJournalPhaseRank(from))
|
|
35
36
|
throw new Error('unit-journal-nonmonotonic:' + from + '->' + to);
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
const key = journal.journalId ?? journal.unitId;
|
|
39
|
-
const path = unitJournalPath(home, key, scope);
|
|
40
|
-
const existing = await readUnitJournal(io, home, key, scope);
|
|
41
|
-
if (existing !== null)
|
|
42
|
-
assertUnitJournalTransition(existing.phase, journal.phase);
|
|
43
|
-
const content = JSON.stringify(journal, null, 2) + '\n';
|
|
44
|
-
if (io.transact !== undefined)
|
|
45
|
-
await io.transact(path, () => content);
|
|
46
|
-
else
|
|
47
|
-
await io.writeText(path, content);
|
|
48
|
-
return path;
|
|
49
|
-
}
|
|
50
|
-
export async function readUnitJournal(io, home, unitId, scope = 'merge') {
|
|
51
|
-
const raw = await io.readText(unitJournalPath(home, unitId, scope));
|
|
38
|
+
function parseUnitJournal(raw) {
|
|
52
39
|
if (raw === null)
|
|
53
40
|
return null;
|
|
54
41
|
try {
|
|
@@ -58,4 +45,22 @@ export async function readUnitJournal(io, home, unitId, scope = 'merge') {
|
|
|
58
45
|
return null;
|
|
59
46
|
}
|
|
60
47
|
}
|
|
48
|
+
export async function writeUnitJournal(io, home, journal, scope = 'merge') {
|
|
49
|
+
const key = journal.journalId ?? journal.unitId;
|
|
50
|
+
const path = unitJournalPath(home, key, scope);
|
|
51
|
+
const content = JSON.stringify(journal, null, 2) + '\n';
|
|
52
|
+
// The read and the monotonicity assertion share the write's critical section; reading them
|
|
53
|
+
// outside transact left a window where two writers both validated the old phase and the
|
|
54
|
+
// slower one silently overwrote a committed journal.
|
|
55
|
+
await transactIo(io, path, (current) => {
|
|
56
|
+
const existing = parseUnitJournal(current);
|
|
57
|
+
if (existing !== null)
|
|
58
|
+
assertUnitJournalTransition(existing.phase, journal.phase);
|
|
59
|
+
return content;
|
|
60
|
+
});
|
|
61
|
+
return path;
|
|
62
|
+
}
|
|
63
|
+
export async function readUnitJournal(io, home, unitId, scope = 'merge') {
|
|
64
|
+
return parseUnitJournal(await io.readText(unitJournalPath(home, unitId, scope)));
|
|
65
|
+
}
|
|
61
66
|
//# sourceMappingURL=unit-journal.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** G2 unit storage: opaque unitId -> Windows-safe storage key. */
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { transactIo } from "./io.js";
|
|
4
5
|
export const UNIT_STORAGE_SCHEMA_VERSION = 1;
|
|
5
6
|
/** Stable, filesystem-safe key; unitId stays opaque (may contain ':' or '/'). */
|
|
6
7
|
export function unitStorageKey(unitId) {
|
|
@@ -21,10 +22,7 @@ export function unitIndexPath(home) {
|
|
|
21
22
|
export async function writeUnitSnapshot(io, home, snapshot, scope = 'merge') {
|
|
22
23
|
const path = unitSnapshotPath(home, snapshot.unitId, scope);
|
|
23
24
|
const content = JSON.stringify(snapshot, null, 2) + '\n';
|
|
24
|
-
|
|
25
|
-
await io.transact(path, () => content);
|
|
26
|
-
else
|
|
27
|
-
await io.writeText(path, content);
|
|
25
|
+
await transactIo(io, path, () => content);
|
|
28
26
|
return path;
|
|
29
27
|
}
|
|
30
28
|
export async function readUnitSnapshot(io, home, unitId, scope = 'merge') {
|
|
@@ -41,10 +39,7 @@ export async function readUnitSnapshot(io, home, unitId, scope = 'merge') {
|
|
|
41
39
|
export async function writeUnitEvidence(io, home, evidence) {
|
|
42
40
|
const path = unitEvidencePath(home, evidence.unitId);
|
|
43
41
|
const content = JSON.stringify(evidence, null, 2) + '\n';
|
|
44
|
-
|
|
45
|
-
await io.transact(path, () => content);
|
|
46
|
-
else
|
|
47
|
-
await io.writeText(path, content);
|
|
42
|
+
await transactIo(io, path, () => content);
|
|
48
43
|
await upsertUnitIndex(io, home, {
|
|
49
44
|
unitId: evidence.unitId,
|
|
50
45
|
storageKey: unitStorageKey(evidence.unitId),
|
|
@@ -93,10 +88,7 @@ export async function upsertUnitIndex(io, home, entry) {
|
|
|
93
88
|
const next = entries.filter(item => item.unitId !== entry.unitId).concat(entry);
|
|
94
89
|
return JSON.stringify({ schemaVersion: UNIT_STORAGE_SCHEMA_VERSION, entries: next }, null, 2) + '\n';
|
|
95
90
|
};
|
|
96
|
-
|
|
97
|
-
await io.transact(path, content);
|
|
98
|
-
else
|
|
99
|
-
await io.writeText(path, content(await io.readText(path)));
|
|
91
|
+
await transactIo(io, path, content);
|
|
100
92
|
}
|
|
101
93
|
export function unitReceiptPath(home, unitId) {
|
|
102
94
|
return join(home, 'merge', 'unit-receipts', unitStorageKey(unitId) + '.json');
|
|
@@ -104,10 +96,7 @@ export function unitReceiptPath(home, unitId) {
|
|
|
104
96
|
export async function writeUnitReceipt(io, home, receipt) {
|
|
105
97
|
const path = unitReceiptPath(home, receipt.unitId);
|
|
106
98
|
const text = JSON.stringify(receipt, null, 2) + '\n';
|
|
107
|
-
|
|
108
|
-
await io.transact(path, () => text);
|
|
109
|
-
else
|
|
110
|
-
await io.writeText(path, text);
|
|
99
|
+
await transactIo(io, path, () => text);
|
|
111
100
|
return path;
|
|
112
101
|
}
|
|
113
102
|
export async function readUnitReceipt(io, home, unitId) {
|
|
@@ -70,10 +70,6 @@ export declare const INSTANCE_KEYS: {
|
|
|
70
70
|
* @returns the sites, in file order.
|
|
71
71
|
*/
|
|
72
72
|
export declare function persistedWriteSites(): readonly PersistedWriteSite[];
|
|
73
|
-
/** The inventory's symbol legend — the roots every declared path is written against, with the
|
|
74
|
-
* segments the gate checks against the resolver's source.
|
|
75
|
-
* @internal no production caller — the gates read the JSON asset directly. */
|
|
76
|
-
export declare function writePathSymbols(): Readonly<Record<string, WritePathSymbol>>;
|
|
77
73
|
/** Sites serialized by the per-home instance claim, with their instance keys.
|
|
78
74
|
* @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
|
|
79
75
|
* reads the JSON asset directly; the tests are the only in-tree consumers. */
|
|
@@ -103,7 +103,6 @@ export const INSTANCE_KEYS = {
|
|
|
103
103
|
// Both caches are READONLY on purpose: the table's own shape is readonly, and copying it into a
|
|
104
104
|
// mutable array would be a second source of truth for the same rows.
|
|
105
105
|
let cachedSites;
|
|
106
|
-
let cachedSymbols;
|
|
107
106
|
/**
|
|
108
107
|
* The declared persisted write sites, in file order.
|
|
109
108
|
*
|
|
@@ -131,16 +130,8 @@ export function persistedWriteSites() {
|
|
|
131
130
|
}
|
|
132
131
|
const table = parseTable(JSON.parse(raw));
|
|
133
132
|
cachedSites = table.sites;
|
|
134
|
-
cachedSymbols = table.symbols;
|
|
135
133
|
return table.sites;
|
|
136
134
|
}
|
|
137
|
-
/** The inventory's symbol legend — the roots every declared path is written against, with the
|
|
138
|
-
* segments the gate checks against the resolver's source.
|
|
139
|
-
* @internal no production caller — the gates read the JSON asset directly. */
|
|
140
|
-
export function writePathSymbols() {
|
|
141
|
-
persistedWriteSites();
|
|
142
|
-
return cachedSymbols ?? {};
|
|
143
|
-
}
|
|
144
135
|
/** Sites serialized by the per-home instance claim, with their instance keys.
|
|
145
136
|
* @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
|
|
146
137
|
* reads the JSON asset directly; the tests are the only in-tree consumers. */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { type EvolutionIoLike } from './io.ts';
|
|
1
|
+
import { transactIo, type EvolutionIoLike } from './io.ts';
|
|
2
2
|
/** The four persistent writer kinds the family permits. */
|
|
3
|
-
export type WriteUnitKind = 'skill' | 'state' | 'merge' | 'curator';
|
|
4
3
|
/** One planned write: expected is the baseline read before the plan, next is the new bytes. */
|
|
5
4
|
export interface WriteTarget {
|
|
6
5
|
readonly path: string;
|
|
@@ -10,7 +9,7 @@ export interface WriteTarget {
|
|
|
10
9
|
}
|
|
11
10
|
/** A structured failure; conflict always means the target changed before/inside the write. */
|
|
12
11
|
export interface WriteKernelError {
|
|
13
|
-
readonly code: 'cas-conflict' | 'write-failed' | 'compensation-blocked';
|
|
12
|
+
readonly code: 'cas-conflict' | 'write-failed' | 'compensation-blocked' | 'transact-not-invoked';
|
|
14
13
|
readonly message: string;
|
|
15
14
|
readonly target: string;
|
|
16
15
|
}
|
|
@@ -23,7 +22,7 @@ export interface WriteKernelResult {
|
|
|
23
22
|
}
|
|
24
23
|
export interface WriteKernelOptions {
|
|
25
24
|
readonly io: EvolutionIoLike;
|
|
26
|
-
readonly transact?:
|
|
25
|
+
readonly transact?: typeof transactIo | undefined;
|
|
27
26
|
readonly now?: (() => number) | undefined;
|
|
28
27
|
}
|
|
29
28
|
export interface WriteOneOptions {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCommittedWarning } from "./io.js";
|
|
1
|
+
import { isCommittedWarning, TransactionNotInvokedError, transactIo } from "./io.js";
|
|
2
2
|
/**
|
|
3
3
|
* The family's single write primitive: compare the baseline INSIDE the write
|
|
4
4
|
* transaction, never overwrite a concurrent value, and compensate only this
|
|
@@ -24,6 +24,7 @@ export class WriteKernel {
|
|
|
24
24
|
async run(target, task) {
|
|
25
25
|
let invoked = false;
|
|
26
26
|
let conflict = false;
|
|
27
|
+
let transactionWarnings;
|
|
27
28
|
const invoke = async (current) => {
|
|
28
29
|
if (target.expected !== undefined && current !== target.expected) {
|
|
29
30
|
conflict = true;
|
|
@@ -34,17 +35,9 @@ export class WriteKernel {
|
|
|
34
35
|
};
|
|
35
36
|
try {
|
|
36
37
|
if (this.transact !== undefined)
|
|
37
|
-
await this.transact(this.io, target.path, invoke);
|
|
38
|
-
else
|
|
39
|
-
await this.io
|
|
40
|
-
else {
|
|
41
|
-
const current = await this.io.readText(target.path);
|
|
42
|
-
const next = await invoke(current);
|
|
43
|
-
if (next === null && current !== null)
|
|
44
|
-
await this.io.remove(target.path);
|
|
45
|
-
else if (next !== null && next !== current)
|
|
46
|
-
await this.io.writeText(target.path, next);
|
|
47
|
-
}
|
|
38
|
+
transactionWarnings = await this.transact(this.io, target.path, invoke);
|
|
39
|
+
else
|
|
40
|
+
transactionWarnings = await transactIo(this.io, target.path, invoke);
|
|
48
41
|
}
|
|
49
42
|
catch (error) {
|
|
50
43
|
if (conflict)
|
|
@@ -55,7 +48,7 @@ export class WriteKernel {
|
|
|
55
48
|
}
|
|
56
49
|
if (!invoked)
|
|
57
50
|
throw new Error('internal error: the write transaction for ' + target.path + ' did not invoke the task; no write was performed');
|
|
58
|
-
return {};
|
|
51
|
+
return transactionWarnings === undefined ? {} : { warnings: transactionWarnings };
|
|
59
52
|
}
|
|
60
53
|
/**
|
|
61
54
|
* Write one target only if the current bytes still equal the baseline.
|
|
@@ -68,6 +61,7 @@ export class WriteKernel {
|
|
|
68
61
|
let wrote = false;
|
|
69
62
|
let deferred = false;
|
|
70
63
|
let conflict = false;
|
|
64
|
+
let transactionWarnings;
|
|
71
65
|
const task = (current) => {
|
|
72
66
|
if (current !== target.expected) {
|
|
73
67
|
if (guard) {
|
|
@@ -82,30 +76,24 @@ export class WriteKernel {
|
|
|
82
76
|
};
|
|
83
77
|
try {
|
|
84
78
|
if (this.transact !== undefined)
|
|
85
|
-
await this.transact(this.io, target.path, task);
|
|
86
|
-
else
|
|
87
|
-
await this.io
|
|
88
|
-
else {
|
|
89
|
-
const current = await this.io.readText(target.path);
|
|
90
|
-
const next = task(current);
|
|
91
|
-
if (next === null && current !== null)
|
|
92
|
-
await this.io.remove(target.path);
|
|
93
|
-
else if (next !== null && next !== current)
|
|
94
|
-
await this.io.writeText(target.path, next);
|
|
95
|
-
}
|
|
79
|
+
transactionWarnings = await this.transact(this.io, target.path, task);
|
|
80
|
+
else
|
|
81
|
+
transactionWarnings = await transactIo(this.io, target.path, task);
|
|
96
82
|
}
|
|
97
83
|
catch (error) {
|
|
98
84
|
if (conflict)
|
|
99
85
|
return { ok: false, changed: [], errors: [{ code: 'cas-conflict', message: error instanceof Error ? error.message : String(error), target: target.path }] };
|
|
100
86
|
if (isCommittedWarning(error))
|
|
101
87
|
return { ok: true, changed: [target.path], errors: [], warnings: [error instanceof Error ? error.message : String(error)] };
|
|
88
|
+
if (error instanceof TransactionNotInvokedError)
|
|
89
|
+
return { ok: false, changed: [], errors: [{ code: 'transact-not-invoked', message: error.message, target: target.path }] };
|
|
102
90
|
return { ok: false, changed: [], errors: [{ code: 'write-failed', message: error instanceof Error ? error.message : String(error), target: target.path }] };
|
|
103
91
|
}
|
|
104
92
|
if (conflict || (!wrote && deferred))
|
|
105
93
|
return { ok: false, changed: [], errors: [{ code: 'cas-conflict', message: 'concurrent modification detected: ' + target.path, target: target.path }] };
|
|
106
94
|
if (!wrote)
|
|
107
95
|
return { ok: false, changed: [], errors: [{ code: 'write-failed', message: 'transaction did not invoke the write task: ' + target.path, target: target.path }] };
|
|
108
|
-
return { ok: true, changed: [target.path], errors: [] };
|
|
96
|
+
return { ok: true, changed: [target.path], errors: [], ...(transactionWarnings === undefined ? {} : { warnings: transactionWarnings }) };
|
|
109
97
|
}
|
|
110
98
|
/**
|
|
111
99
|
* Write a plan in order. A preflight drift writes nothing; a later failure
|
package/lib/write.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as contentHash } from "./mutations-
|
|
2
|
-
import { $ as
|
|
1
|
+
import { r as contentHash } from "./mutations-DQXddSJd.js";
|
|
2
|
+
import { $ as validateMutationRequest, A as UNIT_JOURNAL_SCHEMA_VERSION, B as readUnitSnapshot, D as unitJournalPort, E as pruneTreeChangeUnits, F as writeUnitJournal, G as unitSnapshotsDir, H as unitIndexPath, I as UNIT_STORAGE_SCHEMA_VERSION, J as writeUnitEvidence, K as unitStorageKey, L as readUnitEvidence, M as readUnitJournal, N as unitJournalPath, O as unitSnapshotPort, P as unitJournalPhaseRank, Q as fileMutationLock, R as readUnitIndex, U as unitReceiptPath, V as unitEvidencePath, W as unitSnapshotPath, X as writeUnitSnapshot, Y as writeUnitReceipt, Z as MutationUnit, d as entryTarget, et as WriteKernel, j as assertUnitJournalTransition, k as UNIT_JOURNAL_PHASES, q as upsertUnitIndex, z as readUnitReceipt } from "./skill-history-CxrDE3Rb.js";
|
|
3
3
|
//#region lib/types/unit-undo.js
|
|
4
4
|
/**
|
|
5
5
|
* Cross-skill unit undo executor.
|
package/package.json
CHANGED
|
@@ -114,9 +114,9 @@
|
|
|
114
114
|
"path": "<skillsRoot>/**",
|
|
115
115
|
"writer": "evolution-core/src/skill-store.ts",
|
|
116
116
|
"serializedBy": "write-lock",
|
|
117
|
-
"marker": "
|
|
117
|
+
"marker": "withMutationLock(",
|
|
118
118
|
"state": [],
|
|
119
|
-
"note": "The skill tree itself. G1: ordinary byte writers take the root mutation lock (
|
|
119
|
+
"note": "The skill tree itself. G1: ordinary byte writers take the root mutation lock through withMutationLock (the injected authority lock) and still run their per-file read-modify-write through `transact`; the root lock is what keeps extract/restructure/update/patch/create from interleaving. Destructive movers refuse only when a support directory cannot be listed (fail-closed). N20 (W11 E): the marker is the PRODUCTION symbol withMutationLock; lockPort()'s test fallback (fileMutationLock) is not evidence for a production write."
|
|
120
120
|
},
|
|
121
121
|
{
|
|
122
122
|
"id": "activity-log-fenced",
|
|
@@ -141,9 +141,9 @@
|
|
|
141
141
|
"path": "<callerSupplied>",
|
|
142
142
|
"writer": "evolution-core/src/skill-store.ts",
|
|
143
143
|
"serializedBy": "transact",
|
|
144
|
-
"marker": "
|
|
144
|
+
"marker": "this.transact = transact ?? (io.transact ? transactIo : undefined)",
|
|
145
145
|
"state": [],
|
|
146
|
-
"note": "The store's transaction
|
|
146
|
+
"note": "The store's ONE transaction seam: explicit injection wins, a backend with transact binds transactIo (typed not-invoked + committed warnings), a backend without it keeps the plain read→write. The target is the caller's path — each durable target has its own row above; this row vouches for the primitive itself."
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
149
|
"id": "feedback-events",
|
|
@@ -272,13 +272,76 @@
|
|
|
272
272
|
"note": "Stale-lock removal after a failed release (W9-authority): repair() only removes a lock whose holder is gone; the release itself is the platform lock."
|
|
273
273
|
},
|
|
274
274
|
{
|
|
275
|
-
"id": "
|
|
276
|
-
"path": "<evolutionHome>/merge/
|
|
277
|
-
"writer": "evolution-
|
|
275
|
+
"id": "unit-snapshot-and-evidence",
|
|
276
|
+
"path": "<evolutionHome>/merge/unit-snapshots/** | <evolutionHome>/units/skill/snapshots/** | <evolutionHome>/merge/units/**/evidence.json",
|
|
277
|
+
"writer": "evolution-core/src/unit-storage.ts",
|
|
278
278
|
"serializedBy": "transact",
|
|
279
|
-
"marker": "transactIo(io,
|
|
279
|
+
"marker": "transactIo(io, path, () => content)",
|
|
280
280
|
"state": [],
|
|
281
|
-
"note": "
|
|
281
|
+
"note": "Unit snapshot + evidence writes (W11 E): both go through transactIo now instead of a conditional io.transact/writeText fallback, so a committed-fsync warning is tolerated uniformly and a byte-identical write is a no-op."
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
"id": "unit-index",
|
|
285
|
+
"path": "<evolutionHome>/merge/unit-index.json",
|
|
286
|
+
"writer": "evolution-core/src/unit-storage.ts",
|
|
287
|
+
"serializedBy": "transact",
|
|
288
|
+
"marker": "transactIo(io, path, content)",
|
|
289
|
+
"state": [],
|
|
290
|
+
"note": "The unit index is a read-modify-write of the shared entries array; the task reads the current value inside the transaction (no lost update)."
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
"id": "unit-receipt",
|
|
294
|
+
"path": "<evolutionHome>/merge/unit-receipts/**",
|
|
295
|
+
"writer": "evolution-core/src/unit-storage.ts",
|
|
296
|
+
"serializedBy": "transact",
|
|
297
|
+
"marker": "transactIo(io, path, () => text)",
|
|
298
|
+
"state": [],
|
|
299
|
+
"note": "Receipts are written once per unit; the path is derived from the hashed unit id."
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
"id": "unit-journal",
|
|
303
|
+
"path": "<evolutionHome>/merge/unit-journals/** | <evolutionHome>/units/skill/journals/**",
|
|
304
|
+
"writer": "evolution-core/src/unit-journal.ts",
|
|
305
|
+
"serializedBy": "transact",
|
|
306
|
+
"marker": "transactIo(io, path, (current) => {",
|
|
307
|
+
"state": [],
|
|
308
|
+
"note": "Phase transitions are validated against the current journal inside the transactIo callback; the callback returns the new bytes only after the monotonicity check."
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"id": "run-lease",
|
|
312
|
+
"path": "<evolutionHome>/leases/**",
|
|
313
|
+
"writer": "evolution-core/src/lease-store.ts",
|
|
314
|
+
"serializedBy": "transact",
|
|
315
|
+
"marker": "transactIo(this.io, path, (raw)",
|
|
316
|
+
"state": [],
|
|
317
|
+
"note": "Lease acquire/heartbeat/release all use transactIo now: the old private fallback did not tolerate a committed-fsync warning, so acquire could report failure after the active lease had landed."
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
"id": "write-kernel-run",
|
|
321
|
+
"path": "<evolutionHome>/units/**",
|
|
322
|
+
"writer": "evolution-core/src/write-kernel.ts",
|
|
323
|
+
"serializedBy": "transact",
|
|
324
|
+
"marker": "transactIo(this.io, target.path, invoke)",
|
|
325
|
+
"state": [],
|
|
326
|
+
"note": "Run/task path: the kernel no longer carries its own direct-write fallback; transactIo is the one seam and reports a typed not-invoked error."
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
"id": "write-kernel-write-one",
|
|
330
|
+
"path": "<evolutionHome>/units/**",
|
|
331
|
+
"writer": "evolution-core/src/write-kernel.ts",
|
|
332
|
+
"serializedBy": "transact",
|
|
333
|
+
"marker": "transactIo(this.io, target.path, task)",
|
|
334
|
+
"state": [],
|
|
335
|
+
"note": "Single-target CAS path: same transactIo seam."
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
"id": "mutation-lock",
|
|
339
|
+
"path": "<evolutionHome>/.mutation-lock",
|
|
340
|
+
"writer": "evolution-core/src/mutation-unit.ts",
|
|
341
|
+
"serializedBy": "transact",
|
|
342
|
+
"marker": "transactIo(io, path, task)",
|
|
343
|
+
"state": [],
|
|
344
|
+
"note": "fileMutationLock updates the lock record through transactIo; no private direct-write fallback remains."
|
|
282
345
|
}
|
|
283
346
|
]
|
|
284
347
|
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Untrusted text rendered as prompt lines (T3-03/A31) — ONE folding rule.
|
|
3
|
-
*
|
|
4
|
-
* The background-review digest embeds conversation text and tool output into a
|
|
5
|
-
* plain-text prompt whose PRODUCT is a plan with write permission. Anything the
|
|
6
|
-
* session ingested (a fetched page, a file body, command output) can therefore
|
|
7
|
-
* carry a newline plus a line shaped like the prompt's own structure — a
|
|
8
|
-
* `SYSTEM:`/`Review kind:` header, a `[result]` evidence line, a second copy
|
|
9
|
-
* of the closing instruction — and forge structure or inject instructions.
|
|
10
|
-
*
|
|
11
|
-
* FOLDING, not deleting: the reader (the model) must still SEE what the data
|
|
12
|
-
* said, it just must never become structure. Line separators become a visible
|
|
13
|
-
* `⏎`, and a line that would read as a role/evidence header gets a visible
|
|
14
|
-
* marker in front of it. Every original character stays in place.
|
|
15
|
-
*
|
|
16
|
-
* The boundary is the separator itself, not only a real newline: a payload can
|
|
17
|
-
* paste the separator verbatim, so neutralization matches after `⏎` whether it
|
|
18
|
-
* came from the fold or from the data. Both edits are idempotent (a second pass
|
|
19
|
-
* cannot add a second marker).
|
|
20
|
-
*
|
|
21
|
-
* Scope: text rendered as its OWN line(s) of a prompt. `render-facts`'
|
|
22
|
-
* sanitizer (evolution-maintenance) is the same posture for `key=value` fields
|
|
23
|
-
* and additionally escapes its block delimiter; it is not superseded here.
|
|
24
|
-
* @module @lmzhen/dsh-evolution-core
|
|
25
|
-
*/
|
|
26
|
-
/** Visible stand-in for a folded line separator: one character that cannot be read as line structure. */
|
|
27
|
-
export declare const UNTRUSTED_LINE_BREAK = " \u23CE ";
|
|
28
|
-
/** Visible marker prefixed to a line that would otherwise read as a role/structure header. */
|
|
29
|
-
export declare const UNTRUSTED_LINE_MARK = "\u00B7 ";
|
|
30
|
-
/**
|
|
31
|
-
* Fold untrusted `text` so it cannot become structure, then bound it to `limit`
|
|
32
|
-
* visible characters. A non-positive `limit` means "no truncation".
|
|
33
|
-
*/
|
|
34
|
-
export declare function foldUntrustedLines(text: string, limit: number): string;
|
|
35
|
-
//# sourceMappingURL=fold-untrusted.d.ts.map
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Untrusted text rendered as prompt lines (T3-03/A31) — ONE folding rule.
|
|
3
|
-
*
|
|
4
|
-
* The background-review digest embeds conversation text and tool output into a
|
|
5
|
-
* plain-text prompt whose PRODUCT is a plan with write permission. Anything the
|
|
6
|
-
* session ingested (a fetched page, a file body, command output) can therefore
|
|
7
|
-
* carry a newline plus a line shaped like the prompt's own structure — a
|
|
8
|
-
* `SYSTEM:`/`Review kind:` header, a `[result]` evidence line, a second copy
|
|
9
|
-
* of the closing instruction — and forge structure or inject instructions.
|
|
10
|
-
*
|
|
11
|
-
* FOLDING, not deleting: the reader (the model) must still SEE what the data
|
|
12
|
-
* said, it just must never become structure. Line separators become a visible
|
|
13
|
-
* `⏎`, and a line that would read as a role/evidence header gets a visible
|
|
14
|
-
* marker in front of it. Every original character stays in place.
|
|
15
|
-
*
|
|
16
|
-
* The boundary is the separator itself, not only a real newline: a payload can
|
|
17
|
-
* paste the separator verbatim, so neutralization matches after `⏎` whether it
|
|
18
|
-
* came from the fold or from the data. Both edits are idempotent (a second pass
|
|
19
|
-
* cannot add a second marker).
|
|
20
|
-
*
|
|
21
|
-
* Scope: text rendered as its OWN line(s) of a prompt. `render-facts`'
|
|
22
|
-
* sanitizer (evolution-maintenance) is the same posture for `key=value` fields
|
|
23
|
-
* and additionally escapes its block delimiter; it is not superseded here.
|
|
24
|
-
* @module @lmzhen/dsh-evolution-core
|
|
25
|
-
*/
|
|
26
|
-
/** Visible stand-in for a folded line separator: one character that cannot be read as line structure. */
|
|
27
|
-
export const UNTRUSTED_LINE_BREAK = ' ⏎ ';
|
|
28
|
-
/** Visible marker prefixed to a line that would otherwise read as a role/structure header. */
|
|
29
|
-
export const UNTRUSTED_LINE_MARK = '· ';
|
|
30
|
-
const NEWLINES = /\r\n|\r|\n/g;
|
|
31
|
-
/** A line that reads as structure: a `Label:` head (SYSTEM:, Review kind:, Signals:) or a digest evidence tag.
|
|
32
|
-
* The head is case-TOLERANT on purpose: this family's own prompt labels are mixed case, so an
|
|
33
|
-
* uppercase-only rule neutralized SYSTEM: while leaving a forged "Review kind:" untouched. */
|
|
34
|
-
const STRUCTURAL_HEAD = /(^|⏎)([ \t]*)((?:[A-Za-z][A-Za-z0-9 _]{2,}:|\[result\]|\[call\]))/g;
|
|
35
|
-
/**
|
|
36
|
-
* Fold untrusted `text` so it cannot become structure, then bound it to `limit`
|
|
37
|
-
* visible characters. A non-positive `limit` means "no truncation".
|
|
38
|
-
*/
|
|
39
|
-
export function foldUntrustedLines(text, limit) {
|
|
40
|
-
const folded = text.replace(NEWLINES, UNTRUSTED_LINE_BREAK);
|
|
41
|
-
const marked = folded.replace(STRUCTURAL_HEAD, (_match, boundary, spaces, head) => `${boundary}${spaces}${UNTRUSTED_LINE_MARK}${head}`);
|
|
42
|
-
return limit > 0 ? marked.slice(0, limit) : marked;
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=fold-untrusted.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/** G2 recovery arbitration: unit journal/evidence wins over a legacy commit journal. */
|
|
2
|
-
import type { EvolutionIoLike } from './io.ts';
|
|
3
|
-
export type UnitAuthority = 'unit' | 'legacy' | 'none';
|
|
4
|
-
export declare function resolveUnitAuthority(io: EvolutionIoLike, home: string, unitId: string, legacyExists: boolean): Promise<UnitAuthority>;
|
|
5
|
-
//# sourceMappingURL=unit-recovery.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { readUnitEvidence, readUnitSnapshot } from "./unit-storage.js";
|
|
2
|
-
import { readUnitJournal } from "./unit-journal.js";
|
|
3
|
-
export async function resolveUnitAuthority(io, home, unitId, legacyExists) {
|
|
4
|
-
if (await readUnitEvidence(io, home, unitId) !== null)
|
|
5
|
-
return 'unit';
|
|
6
|
-
if (await readUnitJournal(io, home, unitId) !== null)
|
|
7
|
-
return 'unit';
|
|
8
|
-
if (await readUnitSnapshot(io, home, unitId) !== null)
|
|
9
|
-
return 'unit';
|
|
10
|
-
return legacyExists ? 'legacy' : 'none';
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=unit-recovery.js.map
|