@lmzhen/dsh-evolution-core 0.46.0 → 0.47.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 +26 -138
- package/lib/{io-AmUf4lVY.js → io-BCBSr6Ot.js} +1 -63
- package/lib/io-node.js +1 -1
- package/lib/io-registry.js +14 -29
- package/lib/{mutation-authority-DeJ_Wz14.js → mutation-authority-CM6wRgyK.js} +4 -14
- package/lib/{mutations-DwvbjRHF.js → mutations-DihgpfgG.js} +1 -1
- package/lib/runtime/plugin.js +1 -1
- package/lib/{session-projection-EB7mUOlJ.js → session-projection-BhlDXqws.js} +2 -2
- package/lib/{skill-health-D1pZGk5V.js → skill-health-BzkUQDi7.js} +3 -24
- package/lib/{skill-history-CjypdYqv.js → skill-history-RWt1-kbZ.js} +14 -54
- package/lib/skills.js +7 -7
- package/lib/subagent/index.js +4 -10
- package/lib/types/composition/preset-ids.d.ts +0 -1
- package/lib/types/composition/preset-ids.js +0 -1
- 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/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 +11 -11
- package/lib/types/io-registry.js +13 -16
- package/lib/types/io.d.ts +0 -53
- package/lib/types/io.js +0 -56
- 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 +0 -1
- package/lib/types/mutation-unit.js +5 -4
- 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/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-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/subagent/readiness.d.ts +0 -1
- package/lib/types/subagent/readiness.js +2 -8
- package/lib/types/unit-journal.d.ts +1 -1
- package/lib/types/unit-journal.js +2 -4
- package/lib/types/unit-storage.d.ts +1 -1
- package/lib/types/unit-storage.js +5 -16
- package/lib/write.js +2 -2
- package/package.json +1 -1
- package/persisted-write-inventory.json +47 -2
- 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
package/lib/types/index.d.ts
CHANGED
|
@@ -18,8 +18,6 @@
|
|
|
18
18
|
* `payload.ts` (which of `facts`/`content` is the payload — one rule for the whole family).
|
|
19
19
|
* - **Security primitives** — `threats.ts` (content threat scanner),
|
|
20
20
|
* `redact.ts` (credential masking at model boundaries),
|
|
21
|
-
* `fold-untrusted.ts` (untrusted text must not become prompt structure). Consumers:
|
|
22
|
-
* evolution-policy/threat, both stores, review, maintenance.
|
|
23
21
|
* - **Core domain stores/logic** — `skill-store.ts` (skill tree engine +
|
|
24
22
|
* IO-seam consumer), `memory-store.ts`, `usage.ts`, `curator.ts`,
|
|
25
23
|
* `quality.ts`, `signals.ts`, `skill-reads.ts` (the read-before-write rule, shared by the
|
|
@@ -99,7 +97,6 @@ export * from './live.ts';
|
|
|
99
97
|
export * from './numeric.ts';
|
|
100
98
|
export * from './opt-in.ts';
|
|
101
99
|
export * from './payload.ts';
|
|
102
|
-
export * from './fold-untrusted.ts';
|
|
103
100
|
export * from './subagent/index.ts';
|
|
104
101
|
export { EVOLUTION_PRESET_IDS, REVIEWER_PRESET_ID, MAINTAINER_PRESET_ID, RESTRICTED_TOOLS_ROW_ID, RESTRICTOR_MODULE, RESTRICTED_PRESET_DISPLAY, } from './composition/index.ts';
|
|
105
102
|
export type { RestrictedPresetKind, RestrictedPresetDisplay, RestrictedPresetRequest, RestrictedPresetState, } from './composition/index.ts';
|
package/lib/types/index.js
CHANGED
|
@@ -18,8 +18,6 @@
|
|
|
18
18
|
* `payload.ts` (which of `facts`/`content` is the payload — one rule for the whole family).
|
|
19
19
|
* - **Security primitives** — `threats.ts` (content threat scanner),
|
|
20
20
|
* `redact.ts` (credential masking at model boundaries),
|
|
21
|
-
* `fold-untrusted.ts` (untrusted text must not become prompt structure). Consumers:
|
|
22
|
-
* evolution-policy/threat, both stores, review, maintenance.
|
|
23
21
|
* - **Core domain stores/logic** — `skill-store.ts` (skill tree engine +
|
|
24
22
|
* IO-seam consumer), `memory-store.ts`, `usage.ts`, `curator.ts`,
|
|
25
23
|
* `quality.ts`, `signals.ts`, `skill-reads.ts` (the read-before-write rule, shared by the
|
|
@@ -100,7 +98,6 @@ export * from "./live.js";
|
|
|
100
98
|
export * from "./numeric.js";
|
|
101
99
|
export * from "./opt-in.js";
|
|
102
100
|
export * from "./payload.js";
|
|
103
|
-
export * from "./fold-untrusted.js";
|
|
104
101
|
// G0 contract surface: /subagent types + state probe, /composition preset constants.
|
|
105
102
|
export * from "./subagent/index.js";
|
|
106
103
|
export { EVOLUTION_PRESET_IDS, REVIEWER_PRESET_ID, MAINTAINER_PRESET_ID, RESTRICTED_TOOLS_ROW_ID, RESTRICTOR_MODULE, RESTRICTED_PRESET_DISPLAY, } from "./composition/index.js";
|
|
@@ -52,18 +52,18 @@ export declare class EvolutionIoRegistry extends Service {
|
|
|
52
52
|
provider(name?: string): EvolutionIo;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
55
|
+
* Resolve the seam implementation for a consumer, preferring a backend the deployment mounted.
|
|
56
|
+
*
|
|
57
|
+
* Contract C2 (declared gaps) has no other shape: a consumer that can work on either medium asks for
|
|
58
|
+
* its preference and the DEPLOYMENT decides which backends exist. The lookup is contained here because
|
|
59
|
+
* the registry deliberately has no presence probe (v20 A-3 removed `hasProvider`; a presence probe goes
|
|
60
|
+
* through `provider(name)`, which fails loud) — so this function is the ONE sanctioned place that turns
|
|
61
|
+
* that failure into a fallback. A caller that needs a SPECIFIC backend must call `provider(name)` and
|
|
62
|
+
* take the error.
|
|
63
|
+
* @param registry - the seam registry (`ctx.evolutionIo`).
|
|
64
|
+
* @param names - preferred provider names, most preferred first.
|
|
65
|
+
* @returns the first registered preference, else the registry default.
|
|
58
66
|
*/
|
|
59
|
-
export declare function describeMedium(registry: object): {
|
|
60
|
-
readonly state: 'known';
|
|
61
|
-
readonly requested: readonly string[];
|
|
62
|
-
readonly resolved: string | undefined;
|
|
63
|
-
readonly via: string;
|
|
64
|
-
} | {
|
|
65
|
-
readonly state: 'unknown';
|
|
66
|
-
};
|
|
67
67
|
export declare function preferProvider<T>(registry: {
|
|
68
68
|
provider(name?: string): T;
|
|
69
69
|
}, names: readonly string[]): T;
|
package/lib/types/io-registry.js
CHANGED
|
@@ -95,32 +95,29 @@ export class EvolutionIoRegistry extends Service {
|
|
|
95
95
|
return first;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
const mediumObservations = new WeakMap();
|
|
99
98
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
99
|
+
* Resolve the seam implementation for a consumer, preferring a backend the deployment mounted.
|
|
100
|
+
*
|
|
101
|
+
* Contract C2 (declared gaps) has no other shape: a consumer that can work on either medium asks for
|
|
102
|
+
* its preference and the DEPLOYMENT decides which backends exist. The lookup is contained here because
|
|
103
|
+
* the registry deliberately has no presence probe (v20 A-3 removed `hasProvider`; a presence probe goes
|
|
104
|
+
* through `provider(name)`, which fails loud) — so this function is the ONE sanctioned place that turns
|
|
105
|
+
* that failure into a fallback. A caller that needs a SPECIFIC backend must call `provider(name)` and
|
|
106
|
+
* take the error.
|
|
107
|
+
* @param registry - the seam registry (`ctx.evolutionIo`).
|
|
108
|
+
* @param names - preferred provider names, most preferred first.
|
|
109
|
+
* @returns the first registered preference, else the registry default.
|
|
103
110
|
*/
|
|
104
|
-
export function describeMedium(registry) {
|
|
105
|
-
const observation = mediumObservations.get(registry);
|
|
106
|
-
if (observation === undefined)
|
|
107
|
-
return { state: 'unknown' };
|
|
108
|
-
return { state: 'known', requested: observation.requested, resolved: observation.resolved, via: observation.via };
|
|
109
|
-
}
|
|
110
111
|
export function preferProvider(registry, names) {
|
|
111
112
|
for (const name of names) {
|
|
112
113
|
try {
|
|
113
|
-
|
|
114
|
-
mediumObservations.set(registry, { requested: names, resolved: name, via: 'preference' });
|
|
115
|
-
return resolved;
|
|
114
|
+
return registry.provider(name);
|
|
116
115
|
}
|
|
117
116
|
catch {
|
|
118
117
|
// Not registered: this name is a preference, not a requirement (see the JSDoc).
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
|
-
|
|
122
|
-
mediumObservations.set(registry, { requested: names, resolved: undefined, via: 'default' });
|
|
123
|
-
return fallback;
|
|
120
|
+
return registry.provider();
|
|
124
121
|
}
|
|
125
122
|
export default EvolutionIoRegistry;
|
|
126
123
|
//# sourceMappingURL=io-registry.js.map
|
package/lib/types/io.d.ts
CHANGED
|
@@ -75,59 +75,6 @@ export interface EvolutionIoLike {
|
|
|
75
75
|
* node backend's V5-03 short-circuit).
|
|
76
76
|
*/
|
|
77
77
|
export declare function transactIo(io: EvolutionIoLike, path: string, task: (current: string | null) => string | null | Promise<string | null>): Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* The result of one durable write, in the shape W9-commit-protocol §3.3 requires: a caller may not
|
|
80
|
-
* retry an `unknown` (the bytes landed), and must roll back a `rejected` one.
|
|
81
|
-
*/
|
|
82
|
-
export type WriteOutcome = {
|
|
83
|
-
readonly kind: 'landed';
|
|
84
|
-
} | {
|
|
85
|
-
readonly kind: 'rejected';
|
|
86
|
-
readonly code: string;
|
|
87
|
-
readonly message: string;
|
|
88
|
-
} | {
|
|
89
|
-
readonly kind: 'unknown';
|
|
90
|
-
readonly message: string;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Read-modify-commit that reports what actually happened instead of collapsing the two failure
|
|
94
|
-
* kinds. `transactIo` deliberately turns a committed-warning into success (the bytes are visible),
|
|
95
|
-
* which is right for callers that only need the write; a two-phase caller needs to know that its
|
|
96
|
-
* follow-up step is unconfirmed, so it uses this instead.
|
|
97
|
-
* @param io - the IO backend.
|
|
98
|
-
* @param path - the durable file.
|
|
99
|
-
* @param task - the read-modify-render step.
|
|
100
|
-
* @returns `landed`, `unknown` (written, durability unconfirmed) or `rejected`.
|
|
101
|
-
*/
|
|
102
|
-
export declare function transactOutcome(io: EvolutionIoLike, path: string, task: (current: string | null) => string | null | Promise<string | null>): Promise<WriteOutcome>;
|
|
103
|
-
/**
|
|
104
|
-
* V43 F-4 (S0-6): the shared "the transaction really invoked the task" guard.
|
|
105
|
-
* A backend that implements `transact` but never calls `task` resolves
|
|
106
|
-
* cleanly, so every caller that reads the outcome out of the task itself (a
|
|
107
|
-
* result slot filled inside it, a `Promise<void>` save path) reported success
|
|
108
|
-
* for a write that never happened — the silent-lost-write family the inline
|
|
109
|
-
* C-01 (memory-store) and V6-19 (skill-store) guards cover one call site at a
|
|
110
|
-
* time. Wrap the task handed to `transactIo`/`io.transact` and probe after
|
|
111
|
-
* the call: `invoked()` for a path that owns a structured refusal, or
|
|
112
|
-
* `assertInvoked()` for a void-returning path with no result channel (the
|
|
113
|
-
* family's fail-loud discipline, same wording as skill-store's guard).
|
|
114
|
-
*
|
|
115
|
-
* The wrapper is an identity pass-through — neither the backend nor the task
|
|
116
|
-
* sees a difference — and a task that IS invoked but skips the write (a
|
|
117
|
-
* dedupe no-op) counts as invoked: the probe answers "did the write path get
|
|
118
|
-
* to decide", not "did bytes change".
|
|
119
|
-
* @param what - the write being attempted, named in the thrown message
|
|
120
|
-
*/
|
|
121
|
-
export interface TransactTaskGuard {
|
|
122
|
-
/** Wrap the task handed to the transact backend, marking its invocation. */
|
|
123
|
-
wrap<A, R>(task: (current: A) => R): (current: A) => R;
|
|
124
|
-
/** Did the backend invoke the wrapped task? */
|
|
125
|
-
invoked(): boolean;
|
|
126
|
-
/** Throw when the backend never invoked it (nothing was written). */
|
|
127
|
-
assertInvoked(): void;
|
|
128
|
-
}
|
|
129
|
-
/** Build a {@link TransactTaskGuard} for one write path. See its doc. */
|
|
130
|
-
export declare function transactTaskGuard(what: string): TransactTaskGuard;
|
|
131
78
|
/** Lazy adapter over an IO provider registry, shared by every evolution consumer. */
|
|
132
79
|
export declare function evolutionIoAdapter(provider: () => EvolutionIoLike): EvolutionIoLike;
|
|
133
80
|
/**
|
package/lib/types/io.js
CHANGED
|
@@ -59,62 +59,6 @@ export async function transactIo(io, path, task) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
function outcomeFailure(error) {
|
|
63
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
64
|
-
if (isCommittedWarning(error))
|
|
65
|
-
return { kind: 'unknown', message };
|
|
66
|
-
const code = error?.code;
|
|
67
|
-
return { kind: 'rejected', code: typeof code === 'string' ? code : 'io', message };
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Read-modify-commit that reports what actually happened instead of collapsing the two failure
|
|
71
|
-
* kinds. `transactIo` deliberately turns a committed-warning into success (the bytes are visible),
|
|
72
|
-
* which is right for callers that only need the write; a two-phase caller needs to know that its
|
|
73
|
-
* follow-up step is unconfirmed, so it uses this instead.
|
|
74
|
-
* @param io - the IO backend.
|
|
75
|
-
* @param path - the durable file.
|
|
76
|
-
* @param task - the read-modify-render step.
|
|
77
|
-
* @returns `landed`, `unknown` (written, durability unconfirmed) or `rejected`.
|
|
78
|
-
*/
|
|
79
|
-
export async function transactOutcome(io, path, task) {
|
|
80
|
-
if (io.transact) {
|
|
81
|
-
try {
|
|
82
|
-
await io.transact(path, task);
|
|
83
|
-
return { kind: 'landed' };
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
return outcomeFailure(error);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
const current = await io.readText(path);
|
|
91
|
-
const next = await task(current);
|
|
92
|
-
if (next === null)
|
|
93
|
-
await io.remove(path);
|
|
94
|
-
else if (next !== current)
|
|
95
|
-
await io.writeText(path, next);
|
|
96
|
-
return { kind: 'landed' };
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
return outcomeFailure(error);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/** Build a {@link TransactTaskGuard} for one write path. See its doc. */
|
|
103
|
-
export function transactTaskGuard(what) {
|
|
104
|
-
let invoked = false;
|
|
105
|
-
return {
|
|
106
|
-
wrap: (task) => (current) => {
|
|
107
|
-
invoked = true;
|
|
108
|
-
return task(current);
|
|
109
|
-
},
|
|
110
|
-
invoked: () => invoked,
|
|
111
|
-
assertInvoked: () => {
|
|
112
|
-
if (invoked)
|
|
113
|
-
return;
|
|
114
|
-
throw new Error(`internal error: the write transaction for ${what} did not invoke the task; no write was performed`);
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
62
|
/** Lazy adapter over an IO provider registry, shared by every evolution consumer. */
|
|
119
63
|
export function evolutionIoAdapter(provider) {
|
|
120
64
|
return {
|
|
@@ -17,19 +17,4 @@ export interface JournalProtocol<P extends string> {
|
|
|
17
17
|
/** The restart decision for a journal left in `phase`. */
|
|
18
18
|
recoveryOf(phase: P): JournalRecovery;
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
21
|
-
* True when `from` may advance to `to`.
|
|
22
|
-
* @param protocol - the journal's protocol.
|
|
23
|
-
* @param from - the recorded phase.
|
|
24
|
-
* @param to - the phase the caller wants to record next.
|
|
25
|
-
* @returns whether the transition is declared.
|
|
26
|
-
*/
|
|
27
|
-
export declare function canAdvance<P extends string>(protocol: JournalProtocol<P>, from: P, to: P): boolean;
|
|
28
|
-
/**
|
|
29
|
-
* True when the phase is terminal (nothing may follow it).
|
|
30
|
-
* @param protocol - the journal's protocol.
|
|
31
|
-
* @param phase - the phase to test.
|
|
32
|
-
* @returns whether the phase is terminal.
|
|
33
|
-
*/
|
|
34
|
-
export declare function isTerminal<P extends string>(protocol: JournalProtocol<P>, phase: P): boolean;
|
|
35
20
|
//# sourceMappingURL=journal-protocol.d.ts.map
|
|
@@ -7,23 +7,5 @@
|
|
|
7
7
|
* shape, so a resumer can be written once against `JournalProtocol` instead of per operation.
|
|
8
8
|
* @module @lmzhen/dsh-evolution-core/journal-protocol
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
* True when `from` may advance to `to`.
|
|
12
|
-
* @param protocol - the journal's protocol.
|
|
13
|
-
* @param from - the recorded phase.
|
|
14
|
-
* @param to - the phase the caller wants to record next.
|
|
15
|
-
* @returns whether the transition is declared.
|
|
16
|
-
*/
|
|
17
|
-
export function canAdvance(protocol, from, to) {
|
|
18
|
-
return protocol.next[from].includes(to);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* True when the phase is terminal (nothing may follow it).
|
|
22
|
-
* @param protocol - the journal's protocol.
|
|
23
|
-
* @param phase - the phase to test.
|
|
24
|
-
* @returns whether the phase is terminal.
|
|
25
|
-
*/
|
|
26
|
-
export function isTerminal(protocol, phase) {
|
|
27
|
-
return protocol.next[phase].length === 0;
|
|
28
|
-
}
|
|
10
|
+
export {};
|
|
29
11
|
//# sourceMappingURL=journal-protocol.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MutationOwner } from './contract.ts';
|
|
2
|
-
import type
|
|
2
|
+
import { type EvolutionIoLike } from './io.ts';
|
|
3
3
|
/** One persisted run/claim lease. Epoch increments on every re-acquire. */
|
|
4
4
|
export interface LeaseRecord {
|
|
5
5
|
readonly id: string;
|
package/lib/types/lease-store.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import { transactIo } from "./io.js";
|
|
3
4
|
export const DEFAULT_LEASE_TTL_MS = 30_000;
|
|
4
5
|
export function leaseFile(home, runId) {
|
|
5
6
|
return join(home, 'leases', encodeURIComponent(runId) + '.json');
|
|
@@ -17,18 +18,6 @@ function parseLease(raw) {
|
|
|
17
18
|
return undefined;
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
async function transact(io, path, task) {
|
|
21
|
-
if (io.transact !== undefined) {
|
|
22
|
-
await io.transact(path, task);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const current = await io.readText(path);
|
|
26
|
-
const next = task(current);
|
|
27
|
-
if (next === null)
|
|
28
|
-
await io.remove(path);
|
|
29
|
-
else if (next !== current)
|
|
30
|
-
await io.writeText(path, next);
|
|
31
|
-
}
|
|
32
21
|
function tokenOf(record) {
|
|
33
22
|
return { id: record.id, owner: record.owner, runId: record.runId, epoch: record.epoch };
|
|
34
23
|
}
|
|
@@ -58,7 +47,7 @@ export class LeaseStore {
|
|
|
58
47
|
const now = this.now();
|
|
59
48
|
let created;
|
|
60
49
|
let holder;
|
|
61
|
-
await
|
|
50
|
+
await transactIo(this.io, path, (raw) => {
|
|
62
51
|
const current = parseLease(raw);
|
|
63
52
|
if (current !== undefined && current.state === 'active' && now < current.expiresAt) {
|
|
64
53
|
holder = current;
|
|
@@ -93,7 +82,7 @@ export class LeaseStore {
|
|
|
93
82
|
async renew(token, ttlMs = this.ttlMs) {
|
|
94
83
|
const path = this.path(token.runId);
|
|
95
84
|
let next = null;
|
|
96
|
-
await
|
|
85
|
+
await transactIo(this.io, path, (raw) => {
|
|
97
86
|
const current = parseLease(raw);
|
|
98
87
|
if (current === undefined || current.state !== 'active' || current.id !== token.id || current.epoch !== token.epoch)
|
|
99
88
|
return raw;
|
|
@@ -105,7 +94,7 @@ export class LeaseStore {
|
|
|
105
94
|
}
|
|
106
95
|
async release(token) {
|
|
107
96
|
const path = this.path(token.runId);
|
|
108
|
-
await
|
|
97
|
+
await transactIo(this.io, path, (raw) => {
|
|
109
98
|
const current = parseLease(raw);
|
|
110
99
|
if (current === undefined || current.id !== token.id || current.epoch !== token.epoch)
|
|
111
100
|
return raw;
|
package/lib/types/live.d.ts
CHANGED
|
@@ -63,16 +63,4 @@ export declare function clampOnce(warned: Set<string>, warn: (message: string) =
|
|
|
63
63
|
* reference, which is the silent failure this reader exists to prevent.
|
|
64
64
|
*/
|
|
65
65
|
export declare function liveBool(value: LiveValue<boolean>, fallback?: boolean): boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Read a string (live or plain). Blank/whitespace counts as unset — the same rule `evolutionRoot` uses
|
|
68
|
-
* for `DSH_HOME`.
|
|
69
|
-
*/
|
|
70
|
-
export declare function liveString(value: LiveValue<string>, fallback: string): string;
|
|
71
|
-
/**
|
|
72
|
-
* Read an enumerated string (live or plain); a value outside `allowed` falls back.
|
|
73
|
-
*
|
|
74
|
-
* Used for the mode-like knobs (review mode, trigger, citation policy, write-confirm mode) where a
|
|
75
|
-
* bare `?? default` would accept a typo the schema never saw.
|
|
76
|
-
*/
|
|
77
|
-
export declare function liveEnum<T extends string>(value: LiveValue<T>, allowed: readonly T[], fallback: T): T;
|
|
78
66
|
//# sourceMappingURL=live.d.ts.map
|
package/lib/types/live.js
CHANGED
|
@@ -86,22 +86,4 @@ export function clampOnce(warned, warn, name, value, fallback, min, max) {
|
|
|
86
86
|
export function liveBool(value, fallback = false) {
|
|
87
87
|
return unwrapLive(value) ?? fallback;
|
|
88
88
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Read a string (live or plain). Blank/whitespace counts as unset — the same rule `evolutionRoot` uses
|
|
91
|
-
* for `DSH_HOME`.
|
|
92
|
-
*/
|
|
93
|
-
export function liveString(value, fallback) {
|
|
94
|
-
const current = unwrapLive(value)?.trim();
|
|
95
|
-
return current === undefined || current.length === 0 ? fallback : current;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Read an enumerated string (live or plain); a value outside `allowed` falls back.
|
|
99
|
-
*
|
|
100
|
-
* Used for the mode-like knobs (review mode, trigger, citation policy, write-confirm mode) where a
|
|
101
|
-
* bare `?? default` would accept a typo the schema never saw.
|
|
102
|
-
*/
|
|
103
|
-
export function liveEnum(value, allowed, fallback) {
|
|
104
|
-
const current = unwrapLive(value);
|
|
105
|
-
return current !== undefined && allowed.includes(current) ? current : fallback;
|
|
106
|
-
}
|
|
107
89
|
//# sourceMappingURL=live.js.map
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Stores are MEMORY.md and USER.md under $DSH_HOME/memories (~/.dsh/memories).
|
|
4
4
|
*/
|
|
5
5
|
import { type EvolutionIoLike } from './io.ts';
|
|
6
|
-
export { ENTRY_DELIMITER } from './constants.ts';
|
|
7
6
|
export type MemoryTarget = 'memory' | 'user';
|
|
8
7
|
export interface MemoryOperation {
|
|
9
8
|
action: 'add' | 'replace' | 'remove';
|
|
@@ -9,7 +9,6 @@ import { makeSerialQueue } from "./serial.js";
|
|
|
9
9
|
import { payloadText } from "./payload.js";
|
|
10
10
|
import { scanMemoryThreats } from "./threats.js";
|
|
11
11
|
import { ENTRY_DELIMITER, DEFAULT_MEMORY_CHAR_LIMIT, DEFAULT_USER_CHAR_LIMIT, DEFAULT_CONSOLIDATION_FAILURES } from "./constants.js";
|
|
12
|
-
export { ENTRY_DELIMITER } from "./constants.js";
|
|
13
12
|
/**
|
|
14
13
|
* Read-guard factor: a memory file larger than this multiple of its target's
|
|
15
14
|
* char limit is treated as externally corrupted and skipped instead of being
|
|
@@ -390,10 +390,11 @@ export class MutationUnit {
|
|
|
390
390
|
if (op === undefined)
|
|
391
391
|
continue;
|
|
392
392
|
try {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
393
|
+
// restore(target) writes `before` only while the current bytes equal `after`; the undo
|
|
394
|
+
// wrote op.before, so the compensation passes (before=op.after, after=op.before).
|
|
395
|
+
const restored = await this.kernel.restore({ path: target, before: op.after, after: op.before });
|
|
396
|
+
if (!restored.ok)
|
|
397
|
+
throw new Error(restored.errors[0]?.message ?? 'compensation blocked: ' + target);
|
|
397
398
|
}
|
|
398
399
|
catch {
|
|
399
400
|
// best-effort undo compensation; the structured error below remains honest
|
package/lib/types/probe.d.ts
CHANGED
|
@@ -39,9 +39,6 @@ export declare function isUnknown<T>(probe: Probe<T>): probe is {
|
|
|
39
39
|
kind: 'unknown';
|
|
40
40
|
reason: string;
|
|
41
41
|
};
|
|
42
|
-
/** Only a PRESENT probe yields a value; absent and unknown both fall back. */
|
|
43
|
-
export declare function valueOr<T>(probe: Probe<T>, fallback: T): T;
|
|
44
|
-
export declare function mapProbe<T, U>(probe: Probe<T>, transform: (value: T) => U): Probe<U>;
|
|
45
42
|
/** The reason an `unknown` probe carries (message, never a bare String(object)). */
|
|
46
43
|
export declare function probeReason(error: unknown): string;
|
|
47
44
|
/**
|
package/lib/types/probe.js
CHANGED
|
@@ -16,13 +16,6 @@ export function isAbsent(probe) {
|
|
|
16
16
|
export function isUnknown(probe) {
|
|
17
17
|
return probe.kind === 'unknown';
|
|
18
18
|
}
|
|
19
|
-
/** Only a PRESENT probe yields a value; absent and unknown both fall back. */
|
|
20
|
-
export function valueOr(probe, fallback) {
|
|
21
|
-
return probe.kind === 'present' ? probe.value : fallback;
|
|
22
|
-
}
|
|
23
|
-
export function mapProbe(probe, transform) {
|
|
24
|
-
return probe.kind === 'present' ? probePresent(transform(probe.value)) : probe;
|
|
25
|
-
}
|
|
26
19
|
/** The reason an `unknown` probe carries (message, never a bare String(object)). */
|
|
27
20
|
export function probeReason(error) {
|
|
28
21
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -160,6 +160,13 @@ export function newRunRegistry(options) {
|
|
|
160
160
|
}
|
|
161
161
|
return [...live, ...[...perKind.values()].flat()].sort((a, b) => b.startedAt - a.startedAt);
|
|
162
162
|
};
|
|
163
|
+
/** One serialization for every run-index write (live first, then terminal, then foreign rows). */
|
|
164
|
+
const serializeIndex = (records, foreignRows) => {
|
|
165
|
+
const kept = capped(records);
|
|
166
|
+
const live = kept.filter(row => row.state === 'running');
|
|
167
|
+
const done = kept.filter(row => TERMINAL.has(row.state));
|
|
168
|
+
return JSON.stringify({ schemaVersion: RUNS_SCHEMA_VERSION, runs: [...live, ...done, ...foreignRows] }, null, 2);
|
|
169
|
+
};
|
|
163
170
|
/**
|
|
164
171
|
* Update a surviving foreign row in place (identity stable), or add it.
|
|
165
172
|
*
|
|
@@ -218,12 +225,9 @@ export function newRunRegistry(options) {
|
|
|
218
225
|
if (row.state === 'running' && !owned.has(id) && ownerIsGone(row))
|
|
219
226
|
merged.set(id, orphanOf(row));
|
|
220
227
|
}
|
|
221
|
-
const kept = capped([...merged.values()]);
|
|
222
|
-
const live = kept.filter(row => row.state === 'running');
|
|
223
|
-
const done = kept.filter(row => TERMINAL.has(row.state));
|
|
224
228
|
// Rows this build does not understand ride along untouched (P2-5): it cannot
|
|
225
229
|
// judge them, and dropping them would erase another writer's record.
|
|
226
|
-
return
|
|
230
|
+
return serializeIndex([...merged.values()], onDisk.foreign);
|
|
227
231
|
});
|
|
228
232
|
}
|
|
229
233
|
catch (error) {
|
|
@@ -380,10 +384,7 @@ export function newRunRegistry(options) {
|
|
|
380
384
|
row.supersededAt = now();
|
|
381
385
|
marked += 1;
|
|
382
386
|
}
|
|
383
|
-
|
|
384
|
-
const live = kept.filter(row => row.state === 'running');
|
|
385
|
-
const done = kept.filter(row => TERMINAL.has(row.state));
|
|
386
|
-
return JSON.stringify({ schemaVersion: RUNS_SCHEMA_VERSION, runs: [...live, ...done, ...onDisk.foreign] }, null, 2);
|
|
387
|
+
return serializeIndex([...merged.values()], onDisk.foreign);
|
|
387
388
|
});
|
|
388
389
|
return marked;
|
|
389
390
|
},
|
|
@@ -429,10 +430,7 @@ export function newRunRegistry(options) {
|
|
|
429
430
|
...(outcome.resultRef === undefined ? {} : { resultRef: outcome.resultRef }),
|
|
430
431
|
...(outcome.failure === undefined ? {} : { failure: outcome.failure }),
|
|
431
432
|
};
|
|
432
|
-
|
|
433
|
-
const live = kept.filter(item => item.state === 'running');
|
|
434
|
-
const done = kept.filter(item => TERMINAL.has(item.state));
|
|
435
|
-
return JSON.stringify({ schemaVersion: RUNS_SCHEMA_VERSION, runs: [...live, ...done, ...onDisk.foreign] }, null, 2);
|
|
433
|
+
return serializeIndex(onDisk.records.map(item => item.id === id ? next : item), onDisk.foreign);
|
|
436
434
|
});
|
|
437
435
|
// Rebuild the foreign view so this process answers the upgraded verdict at once.
|
|
438
436
|
if (changed)
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
export type SessionEventClass = 'model' | 'plugin-record' | 'unknown';
|
|
2
|
-
/** Frames the model authored/saw (the only frames evidence, reads and usage accounting may consume). */
|
|
3
|
-
import { MODEL_SESSION_EVENT_TYPES } from './tool-dispatch.ts';
|
|
4
|
-
export { MODEL_SESSION_EVENT_TYPES as MODEL_SESSION_EVENTS };
|
|
5
2
|
/** Classify one session event WITHOUT interpreting it (pure). */
|
|
6
3
|
export declare function classifySessionEvent(event: {
|
|
7
4
|
readonly type?: unknown;
|
|
8
5
|
readonly ignorable?: unknown;
|
|
9
6
|
}): SessionEventClass;
|
|
10
|
-
/** True when the event must be skipped by evidence/usage readers (tolerant, never fatal). */
|
|
11
|
-
export declare function isIgnorableEvent(event: {
|
|
12
|
-
readonly type?: unknown;
|
|
13
|
-
readonly ignorable?: unknown;
|
|
14
|
-
}): boolean;
|
|
15
7
|
//# sourceMappingURL=session-fold.d.ts.map
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
// helper would make the contract depend on the bed rather than on the rule.
|
|
12
12
|
/** Frames the model authored/saw (the only frames evidence, reads and usage accounting may consume). */
|
|
13
13
|
import { MODEL_SESSION_EVENT_TYPES } from "./tool-dispatch.js";
|
|
14
|
-
export { MODEL_SESSION_EVENT_TYPES as MODEL_SESSION_EVENTS };
|
|
15
14
|
const MODEL_EVENT_TYPES = new Set(MODEL_SESSION_EVENT_TYPES);
|
|
16
15
|
/** Classify one session event WITHOUT interpreting it (pure). */
|
|
17
16
|
export function classifySessionEvent(event) {
|
|
@@ -21,8 +20,4 @@ export function classifySessionEvent(event) {
|
|
|
21
20
|
}
|
|
22
21
|
return MODEL_EVENT_TYPES.has(type) ? 'model' : 'unknown';
|
|
23
22
|
}
|
|
24
|
-
/** True when the event must be skipped by evidence/usage readers (tolerant, never fatal). */
|
|
25
|
-
export function isIgnorableEvent(event) {
|
|
26
|
-
return classifySessionEvent(event) !== 'model';
|
|
27
|
-
}
|
|
28
23
|
//# sourceMappingURL=session-fold.js.map
|
|
@@ -103,7 +103,7 @@ const readsStateSchema = z.object({
|
|
|
103
103
|
failed: z.boolean(),
|
|
104
104
|
file: z.string().nullable().optional(),
|
|
105
105
|
tool: z.string().optional(),
|
|
106
|
-
}).strict()),
|
|
106
|
+
}).strict()).max(512),
|
|
107
107
|
}).strict();
|
|
108
108
|
const signalsStateSchema = z.object({
|
|
109
109
|
through: z.number().int().min(-1).max(Number.MAX_SAFE_INTEGER),
|
|
@@ -202,7 +202,7 @@ export const evolutionReadsProjection = {
|
|
|
202
202
|
arguments: step.arguments,
|
|
203
203
|
ok: step.outcome?.ok,
|
|
204
204
|
}) ?? null;
|
|
205
|
-
return { reads: [...state.reads, { key: step.key, skill, failed: step.outcome?.ok === false }] };
|
|
205
|
+
return { reads: [...state.reads.slice(-511), { key: step.key, skill, failed: step.outcome?.ok === false }] };
|
|
206
206
|
},
|
|
207
207
|
};
|
|
208
208
|
/** The `evolutionSignals` unit (host-only: no client view is registered for it). */
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/** 技能名文法(与平台 `isSkillName` 等价:kebab-case,点前缀与下划线一律不是技能名)。 */
|
|
2
|
-
export declare const SKILL_NAME_RE: RegExp;
|
|
3
1
|
/** 名字是否是技能名 —— `._x`、`Bad_Name`、`.archive` 都返回 false。 */
|
|
4
2
|
export declare function isSkillName(name: string): boolean;
|
|
5
3
|
/** 相对技能根的路径是否落在平台会发现的位置(depth<=2 且最后一段是 SKILL.md 或 `<name>.md`)。 */
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
11
11
|
import { join } from 'node:path';
|
|
12
|
-
|
|
13
|
-
export const SKILL_NAME_RE = /^[a-z0-9][a-z0-9-]*$/;
|
|
12
|
+
import { SKILL_NAME_RE } from "./constants.js";
|
|
14
13
|
/** 名字是否是技能名 —— `._x`、`Bad_Name`、`.archive` 都返回 false。 */
|
|
15
14
|
export function isSkillName(name) {
|
|
16
15
|
return SKILL_NAME_RE.test(name);
|
|
@@ -347,30 +347,6 @@ export declare const TEXT_DIFF_MAX_CHARS = 4000;
|
|
|
347
347
|
* @returns the counts, the windowed hunk, and whether the window cut anything.
|
|
348
348
|
*/
|
|
349
349
|
export declare function textDiffFacts(before: string, after: string, path: string, maxLines?: number): TextDiffFacts;
|
|
350
|
-
/** Characters one generated summary may carry. */
|
|
351
|
-
export declare const VERSION_SUMMARY_MAX_CHARS = 80;
|
|
352
|
-
/**
|
|
353
|
-
* The fixed prompt the optional per-write summarizer runs (registry `skillVersionSummary`).
|
|
354
|
-
*
|
|
355
|
-
* Model-visible, so it is written from the model’s perspective and pinned: the tests assert that it
|
|
356
|
-
* carries the skill name, the character cap and both bodies, because a silent change to a prompt is a
|
|
357
|
-
* silent change to what every recorded version says.
|
|
358
|
-
* @param input - the skill, the action, and the two bodies (null when absent).
|
|
359
|
-
* @returns the prompt text.
|
|
360
|
-
*/
|
|
361
|
-
export declare function versionSummaryPrompt(input: {
|
|
362
|
-
name: string;
|
|
363
|
-
action: string;
|
|
364
|
-
before: string | null;
|
|
365
|
-
after: string | null;
|
|
366
|
-
}): string;
|
|
367
|
-
/**
|
|
368
|
-
* Reduce a model answer to the one line the index stores.
|
|
369
|
-
* @param raw - the model’s answer, whatever shape it came in.
|
|
370
|
-
* @param maxChars - the character cap.
|
|
371
|
-
* @returns the one line, or undefined when there is nothing usable (callers store no summary).
|
|
372
|
-
*/
|
|
373
|
-
export declare function normalizeVersionSummary(raw: string, maxChars?: number): string | undefined;
|
|
374
350
|
/** A relative age, in the shape the platform’s own `relativeTime(at, now)` returns. */
|
|
375
351
|
export interface RelativeAge {
|
|
376
352
|
readonly unit: 'now' | 'minutes' | 'hours' | 'days' | 'months' | 'years';
|