@evomap/evolver-cli 2.0.49 → 2.0.51
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/dist/assetEvolution.d.ts +9 -0
- package/dist/assetEvolution.js +164 -0
- package/dist/commandCatalog.d.ts +4 -0
- package/dist/commandCatalog.js +4 -0
- package/dist/containedWrite.d.ts +8 -0
- package/dist/containedWrite.js +79 -0
- package/dist/dispatch.js +8 -0
- package/dist/experience.js +34 -2
- package/dist/gene.d.ts +3 -0
- package/dist/gene.js +174 -0
- package/dist/jsonCommand.d.ts +34 -0
- package/dist/jsonCommand.js +118 -0
- package/dist/lifecycle.js +1 -4
- package/dist/lifecycleBootstrapTransaction.js +38 -17
- package/dist/localMemoryGraph.js +10 -4
- package/dist/pluginDrafts.d.ts +19 -0
- package/dist/pluginDrafts.js +87 -0
- package/dist/promptRecallRuntime.js +2 -0
- package/dist/publishPolicy.d.ts +6 -0
- package/dist/publishPolicy.js +19 -0
- package/dist/redact.d.ts +3 -0
- package/dist/redact.js +27 -0
- package/dist/sessionIngest.d.ts +1 -0
- package/dist/sessionIngest.js +6 -3
- package/dist/setupHooks.js +70 -13
- package/dist/setupHooksLifecycle.d.ts +19 -3
- package/dist/setupHooksLifecycle.js +17 -246
- package/dist/setupHooksTransaction.d.ts +12 -0
- package/dist/setupHooksTransaction.js +220 -0
- package/dist/skillFetch.d.ts +1 -0
- package/dist/skillFetch.js +18 -26
- package/dist/workflow.d.ts +2 -1
- package/dist/workflow.js +35 -12
- package/package.json +7 -7
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { authoring } from '@evomap/evolver-core';
|
|
2
|
+
export class JsonCommandError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.name = 'JsonCommandError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export const SMALL_REQUEST_BYTES = 64 * 1024;
|
|
11
|
+
export const LARGE_REQUEST_BYTES = 512 * 1024;
|
|
12
|
+
const MAX_ERROR_CHARS = 300;
|
|
13
|
+
function envLocale(io) {
|
|
14
|
+
return authoring.authoringLocale(undefined, io.env ?? process.env);
|
|
15
|
+
}
|
|
16
|
+
export function requestLocale(request, io) {
|
|
17
|
+
return authoring.authoringLocale(request['locale'], io.env ?? process.env);
|
|
18
|
+
}
|
|
19
|
+
export function inputError(locale, zh, en) {
|
|
20
|
+
return new JsonCommandError('INPUT_INVALID', authoring.say(locale, zh, en));
|
|
21
|
+
}
|
|
22
|
+
/** One JSON object on stdin (an interactive terminal counts as `{}`), bounded before it is parsed. */
|
|
23
|
+
export async function readJsonRequest(limit, io) {
|
|
24
|
+
const stdin = io.stdin ?? process.stdin;
|
|
25
|
+
const locale = envLocale(io);
|
|
26
|
+
if (stdin.isTTY)
|
|
27
|
+
return {};
|
|
28
|
+
const chunks = [];
|
|
29
|
+
let bytes = 0;
|
|
30
|
+
for await (const chunk of stdin) {
|
|
31
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
32
|
+
bytes += buffer.length;
|
|
33
|
+
if (bytes > limit)
|
|
34
|
+
throw inputError(locale, `请求超过 ${limit / 1024} KiB 上限。`, `The request exceeds the ${limit / 1024} KiB limit.`);
|
|
35
|
+
chunks.push(buffer);
|
|
36
|
+
}
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks)) || '{}');
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw inputError(locale, '请求不是有效的 JSON。', 'The request is not valid JSON.');
|
|
43
|
+
}
|
|
44
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
45
|
+
throw inputError(locale, '请求需要是一个 JSON 对象。', 'The request must be a JSON object.');
|
|
46
|
+
return parsed;
|
|
47
|
+
}
|
|
48
|
+
function clipped(message) {
|
|
49
|
+
return message.length > MAX_ERROR_CHARS ? `${message.slice(0, MAX_ERROR_CHARS - 1)}…` : message;
|
|
50
|
+
}
|
|
51
|
+
/** The versioned envelope every Desktop-facing command shares: one line of JSON, exit 0 when ok and 1 otherwise. */
|
|
52
|
+
export async function runJsonCommand(schema, operation, io, run) {
|
|
53
|
+
const stdout = io.stdout ?? ((text) => { process.stdout.write(text); });
|
|
54
|
+
const emit = (payload) => stdout(`${JSON.stringify({ schema, operation, ...payload })}\n`);
|
|
55
|
+
try {
|
|
56
|
+
emit({ ok: true, result: await run() });
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
const failure = error instanceof JsonCommandError ? error
|
|
61
|
+
: new JsonCommandError('INTERNAL', authoring.say(envLocale(io), '命令执行失败,请检查本地 Evolver 安装与目录权限。', 'The command failed; check the local Evolver installation and directory permissions.'));
|
|
62
|
+
emit({ ok: false, code: failure.code, error: clipped(failure.message) });
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function optionalString(request, key, locale, maxChars = 100_000) {
|
|
67
|
+
const value = request[key];
|
|
68
|
+
if (value === undefined || value === null)
|
|
69
|
+
return undefined;
|
|
70
|
+
if (typeof value !== 'string' || value.length > maxChars || value.includes('\0'))
|
|
71
|
+
throw inputError(locale, `${key} 需要是不超过 ${maxChars} 字的文本。`, `${key} must be text of at most ${maxChars} characters.`);
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
export function requiredString(request, key, locale, maxChars = 100_000) {
|
|
75
|
+
const value = optionalString(request, key, locale, maxChars);
|
|
76
|
+
if (value === undefined)
|
|
77
|
+
throw inputError(locale, `缺少 ${key}。`, `Missing ${key}.`);
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
export function optionalStrings(request, key, locale, maxItems = 200, maxChars = 2000) {
|
|
81
|
+
const value = request[key];
|
|
82
|
+
if (value === undefined || value === null)
|
|
83
|
+
return undefined;
|
|
84
|
+
if (!Array.isArray(value) || value.length > maxItems || value.some((item) => typeof item !== 'string' || item.length > maxChars || item.includes('\0'))) {
|
|
85
|
+
throw inputError(locale, `${key} 需要是最多 ${maxItems} 条文本的列表。`, `${key} must be a list of at most ${maxItems} strings.`);
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
export function optionalEnum(request, key, values, locale) {
|
|
90
|
+
const value = request[key];
|
|
91
|
+
if (value === undefined || value === null)
|
|
92
|
+
return undefined;
|
|
93
|
+
if (!values.includes(value))
|
|
94
|
+
throw inputError(locale, `${key} 只能是 ${values.join('、')}。`, `${key} must be one of ${values.join(', ')}.`);
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
export function requiredEnum(request, key, values, locale) {
|
|
98
|
+
const value = optionalEnum(request, key, values, locale);
|
|
99
|
+
if (value === undefined)
|
|
100
|
+
throw inputError(locale, `缺少 ${key}(${values.join('、')})。`, `Missing ${key} (${values.join(', ')}).`);
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
export function requiredObject(request, key, locale) {
|
|
104
|
+
const value = request[key];
|
|
105
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
106
|
+
throw inputError(locale, `缺少 ${key} 对象。`, `Missing the ${key} object.`);
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
/** The operation word and that the remaining flags are only `--json`; anything else is an input error. */
|
|
110
|
+
export function operationOf(argv, operations, io) {
|
|
111
|
+
const operation = argv[0] ?? '';
|
|
112
|
+
const locale = envLocale(io);
|
|
113
|
+
if (!operations.includes(operation)) {
|
|
114
|
+
return { operation, error: inputError(locale, `不支持的操作,可用:${operations.join('、')}。`, `Unsupported operation; use one of ${operations.join(', ')}.`) };
|
|
115
|
+
}
|
|
116
|
+
const extra = argv.slice(1).find((arg) => arg !== '--json');
|
|
117
|
+
return extra ? { operation, error: inputError(locale, `不支持的参数:${extra.slice(0, 40)}`, `Unsupported argument: ${extra.slice(0, 40)}`) } : { operation };
|
|
118
|
+
}
|
package/dist/lifecycle.js
CHANGED
|
@@ -5468,10 +5468,7 @@ function forceKill(pid) {
|
|
|
5468
5468
|
function readProxySettings(path, options = {}) {
|
|
5469
5469
|
let descriptor;
|
|
5470
5470
|
try {
|
|
5471
|
-
|
|
5472
|
-
if (process.platform === 'win32' && before.dev === 0n && before.isFile() && !before.isSymbolicLink()) {
|
|
5473
|
-
before = coreUtil.statRegularFileIdentity(path);
|
|
5474
|
-
}
|
|
5471
|
+
const before = coreUtil.statRegularFileIdentity(path);
|
|
5475
5472
|
if (!before.isFile() || before.isSymbolicLink() || before.size > BigInt(MAX_PROXY_SETTINGS_BYTES)
|
|
5476
5473
|
|| before.dev <= 0n || before.ino <= 0n) {
|
|
5477
5474
|
throw new Error('proxy settings are not a bounded regular file');
|
|
@@ -145,11 +145,31 @@ function assertWindowsAclChecksTrusted(checks) {
|
|
|
145
145
|
function assertWindowsAclTrusted(path, ownerCurrentOnly = false) {
|
|
146
146
|
assertWindowsAclChecksTrusted([{ path, parentOnly: false, ownerCurrentOnly }]);
|
|
147
147
|
}
|
|
148
|
+
function statBootstrapFileIdentity(path) {
|
|
149
|
+
const before = lstatSync(path, { bigint: true });
|
|
150
|
+
if (process.platform !== 'win32')
|
|
151
|
+
return before;
|
|
152
|
+
if (before.isSymbolicLink())
|
|
153
|
+
throw new util.UnsafeLockPathError('symlink');
|
|
154
|
+
if (!before.isFile())
|
|
155
|
+
throw new util.UnsafeLockPathError('not_regular_file');
|
|
156
|
+
// Keep the initial pathname metadata, not just the later normalized snapshot.
|
|
157
|
+
// Only a real handle may supply a missing Windows pathname volume identity.
|
|
158
|
+
const identity = util.statRegularFileIdentity(path);
|
|
159
|
+
if (identity.dev <= 0n || identity.ino <= 0n || before.ino !== identity.ino
|
|
160
|
+
|| before.dev < 0n || (before.dev !== 0n && before.dev !== identity.dev)
|
|
161
|
+
|| before.size !== identity.size || before.mtimeNs !== identity.mtimeNs
|
|
162
|
+
|| before.ctimeNs !== identity.ctimeNs || before.nlink !== identity.nlink
|
|
163
|
+
|| before.uid !== identity.uid || before.mode !== identity.mode) {
|
|
164
|
+
throw new util.UnsafeLockPathError('path_changed');
|
|
165
|
+
}
|
|
166
|
+
return identity;
|
|
167
|
+
}
|
|
148
168
|
function hardenWindowsOwnedFile(path, expected) {
|
|
149
169
|
if (process.platform !== 'win32' || bootstrapWindowsAclTrustForTest)
|
|
150
170
|
return;
|
|
151
171
|
const assertIdentity = () => {
|
|
152
|
-
const current =
|
|
172
|
+
const current = statBootstrapFileIdentity(path);
|
|
153
173
|
if (!current.isFile() || current.isSymbolicLink() || current.nlink !== 1n
|
|
154
174
|
|| current.dev !== expected.dev || current.ino !== expected.ino || current.size !== expected.size) {
|
|
155
175
|
throw new Error(`bootstrap Windows owned file changed before hardening: ${path}`);
|
|
@@ -281,7 +301,9 @@ function readBoundedRegularText(path, maxBytes, label, options = {}) {
|
|
|
281
301
|
const uid = platform === 'win32' || typeof process.getuid !== 'function'
|
|
282
302
|
? undefined
|
|
283
303
|
: BigInt(process.getuid());
|
|
284
|
-
|
|
304
|
+
// Windows runtimes in our supported range can report pathname dev=0. Bind
|
|
305
|
+
// each path snapshot to a real handle rather than accepting an unknown volume.
|
|
306
|
+
const before = statBootstrapFileIdentity(path);
|
|
285
307
|
if (before.isSymbolicLink() || !before.isFile() || before.size > BigInt(maxBytes)
|
|
286
308
|
|| (options.requireOwnerOnly === true && before.nlink !== 1n)
|
|
287
309
|
|| before.dev <= 0n || before.ino <= 0n) {
|
|
@@ -332,7 +354,7 @@ function readBoundedRegularText(path, maxBytes, label, options = {}) {
|
|
|
332
354
|
if (platform === 'win32') {
|
|
333
355
|
(options.assertWindowsAcl ?? assertWindowsAclTrusted)(path);
|
|
334
356
|
}
|
|
335
|
-
const settled =
|
|
357
|
+
const settled = statBootstrapFileIdentity(path);
|
|
336
358
|
if (!settled.isFile() || settled.isSymbolicLink()
|
|
337
359
|
|| settled.dev !== opened.dev || settled.ino !== opened.ino || settled.size !== opened.size
|
|
338
360
|
|| settled.mtimeNs !== opened.mtimeNs || settled.ctimeNs !== opened.ctimeNs
|
|
@@ -442,7 +464,7 @@ function writeDurableExclusive(path, content, mode, publication) {
|
|
|
442
464
|
}
|
|
443
465
|
if (publication && claimPath && ownershipReceipt) {
|
|
444
466
|
syncDirectory(directory);
|
|
445
|
-
const receipt =
|
|
467
|
+
const receipt = statBootstrapFileIdentity(ownershipReceipt);
|
|
446
468
|
if (!opened.isFile() || opened.dev <= 0n || opened.ino <= 0n
|
|
447
469
|
|| receipt.dev !== opened.dev || receipt.ino !== opened.ino) {
|
|
448
470
|
throw new Error('bootstrap artifact ownership receipt does not bind the staged claim');
|
|
@@ -450,7 +472,7 @@ function writeDurableExclusive(path, content, mode, publication) {
|
|
|
450
472
|
linkSync(ownershipReceipt, claimPath);
|
|
451
473
|
syncDirectory(directory);
|
|
452
474
|
claimPublished = true;
|
|
453
|
-
const claim =
|
|
475
|
+
const claim = statBootstrapFileIdentity(claimPath);
|
|
454
476
|
if (claim.dev !== opened.dev || claim.ino !== opened.ino) {
|
|
455
477
|
throw new Error('bootstrap artifact claim does not bind the staged ownership receipt');
|
|
456
478
|
}
|
|
@@ -1620,12 +1642,6 @@ function assertTrustedBootstrapArtifactLeaf(stat, platform, uid, path, role) {
|
|
|
1620
1642
|
}
|
|
1621
1643
|
}
|
|
1622
1644
|
export const _assertTrustedBootstrapArtifactLeafForTest = assertTrustedBootstrapArtifactLeaf;
|
|
1623
|
-
function bootstrapPathMetadata(path) {
|
|
1624
|
-
const stat = lstatSync(path, { bigint: true });
|
|
1625
|
-
// Reuse the native file witness; a missing Windows volume is not an identity.
|
|
1626
|
-
return process.platform === 'win32' && stat.dev === 0n && stat.isFile() && !stat.isSymbolicLink()
|
|
1627
|
-
? util.statRegularFileIdentity(path) : stat;
|
|
1628
|
-
}
|
|
1629
1645
|
export function readBootstrapArtifactFile(path, maxBytes = MAX_ARTIFACT_BYTES, hooks = {}) {
|
|
1630
1646
|
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > MAX_ARTIFACT_BYTES) {
|
|
1631
1647
|
throw new Error('bootstrap artifact read limit is invalid');
|
|
@@ -1637,7 +1653,9 @@ export function readBootstrapArtifactFile(path, maxBytes = MAX_ARTIFACT_BYTES, h
|
|
|
1637
1653
|
const assertTrustedLeaf = (stat) => assertTrustedBootstrapArtifactLeaf(stat, process.platform, trustedUid, path, role);
|
|
1638
1654
|
if (process.platform === 'win32')
|
|
1639
1655
|
assertWindowsAclTrusted(path, role === 'owned');
|
|
1640
|
-
|
|
1656
|
+
// Windows runtimes in our supported range can report pathname dev=0. Bind
|
|
1657
|
+
// each path snapshot to a real handle rather than accepting an unknown volume.
|
|
1658
|
+
const before = statBootstrapFileIdentity(path);
|
|
1641
1659
|
if (before.isSymbolicLink() || !before.isFile() || before.size > BigInt(maxBytes)
|
|
1642
1660
|
|| before.dev <= 0n || before.ino <= 0n) {
|
|
1643
1661
|
throw new Error(`bootstrap artifact is not a regular owned file: ${path}`);
|
|
@@ -1647,7 +1665,9 @@ export function readBootstrapArtifactFile(path, maxBytes = MAX_ARTIFACT_BYTES, h
|
|
|
1647
1665
|
try {
|
|
1648
1666
|
const opened = fstatSync(descriptor, { bigint: true });
|
|
1649
1667
|
if (!opened.isFile() || opened.dev !== before.dev || opened.ino !== before.ino
|
|
1650
|
-
|| opened.dev <= 0n || opened.ino <= 0n || opened.size > BigInt(maxBytes)
|
|
1668
|
+
|| opened.dev <= 0n || opened.ino <= 0n || opened.size > BigInt(maxBytes)
|
|
1669
|
+
|| opened.size !== before.size || opened.mtimeNs !== before.mtimeNs
|
|
1670
|
+
|| opened.ctimeNs !== before.ctimeNs || opened.nlink !== before.nlink) {
|
|
1651
1671
|
throw new Error(`bootstrap artifact changed while opening: ${path}`);
|
|
1652
1672
|
}
|
|
1653
1673
|
assertTrustedLeaf(opened);
|
|
@@ -1668,7 +1688,8 @@ export function readBootstrapArtifactFile(path, maxBytes = MAX_ARTIFACT_BYTES, h
|
|
|
1668
1688
|
hash.update(chunk);
|
|
1669
1689
|
}
|
|
1670
1690
|
const after = fstatSync(descriptor, { bigint: true });
|
|
1671
|
-
if (after.
|
|
1691
|
+
if (!after.isFile() || after.dev !== opened.dev || after.ino !== opened.ino
|
|
1692
|
+
|| after.size !== opened.size || after.nlink !== opened.nlink
|
|
1672
1693
|
|| after.mtimeNs !== opened.mtimeNs || after.ctimeNs !== opened.ctimeNs
|
|
1673
1694
|
|| BigInt(size) !== opened.size) {
|
|
1674
1695
|
throw new Error(`bootstrap artifact changed while hashing: ${path}`);
|
|
@@ -1677,11 +1698,11 @@ export function readBootstrapArtifactFile(path, maxBytes = MAX_ARTIFACT_BYTES, h
|
|
|
1677
1698
|
hooks.afterRead?.();
|
|
1678
1699
|
if (process.platform === 'win32')
|
|
1679
1700
|
assertWindowsAclTrusted(path, role === 'owned');
|
|
1680
|
-
const settled =
|
|
1701
|
+
const settled = statBootstrapFileIdentity(path);
|
|
1681
1702
|
if (!settled.isFile() || settled.isSymbolicLink()
|
|
1682
1703
|
|| settled.dev !== opened.dev || settled.ino !== opened.ino
|
|
1683
|
-
|| settled.size !== opened.size || settled.
|
|
1684
|
-
|| settled.ctimeNs !== opened.ctimeNs) {
|
|
1704
|
+
|| settled.size !== opened.size || settled.nlink !== opened.nlink
|
|
1705
|
+
|| settled.mtimeNs !== opened.mtimeNs || settled.ctimeNs !== opened.ctimeNs) {
|
|
1685
1706
|
throw new Error(`bootstrap artifact changed after reading: ${path}`);
|
|
1686
1707
|
}
|
|
1687
1708
|
assertTrustedLeaf(settled);
|
package/dist/localMemoryGraph.js
CHANGED
|
@@ -2044,7 +2044,7 @@ export class LocalMemoryGraph {
|
|
|
2044
2044
|
let closed = false;
|
|
2045
2045
|
let published = false;
|
|
2046
2046
|
try {
|
|
2047
|
-
tempIdentity = graphPathSnapshot(temp);
|
|
2047
|
+
tempIdentity = graphPathSnapshot(temp, 'write');
|
|
2048
2048
|
const descriptorIdentity = fstatSync(fd, { bigint: true });
|
|
2049
2049
|
if (!tempIdentity.isFile() || tempIdentity.isSymbolicLink()
|
|
2050
2050
|
|| !descriptorIdentity.isFile() || descriptorIdentity.isSymbolicLink()
|
|
@@ -2071,7 +2071,7 @@ export class LocalMemoryGraph {
|
|
|
2071
2071
|
}
|
|
2072
2072
|
if (!published && tempIdentity !== null) {
|
|
2073
2073
|
try {
|
|
2074
|
-
const currentIdentity = graphPathSnapshot(temp);
|
|
2074
|
+
const currentIdentity = graphPathSnapshot(temp, 'write');
|
|
2075
2075
|
if (currentIdentity.isFile() && !currentIdentity.isSymbolicLink()
|
|
2076
2076
|
&& sameGraphFileIdentity(tempIdentity, currentIdentity))
|
|
2077
2077
|
unlinkSync(temp);
|
|
@@ -2718,9 +2718,15 @@ function writeAll(fd, payload, position = null) {
|
|
|
2718
2718
|
offset += written;
|
|
2719
2719
|
}
|
|
2720
2720
|
}
|
|
2721
|
-
function graphPathSnapshot(path) {
|
|
2721
|
+
function graphPathSnapshot(path, witnessAccess = 'read') {
|
|
2722
2722
|
const named = lstatSync(path, { bigint: true });
|
|
2723
|
-
|
|
2723
|
+
const stat = named.isFile() && !named.isSymbolicLink()
|
|
2724
|
+
? assetstore.captureRegularAssetFileSnapshot(path, witnessAccess === 'write' ? constants.O_WRONLY : constants.O_RDONLY)
|
|
2725
|
+
: named;
|
|
2726
|
+
if (process.platform === 'win32' && stat.isFile() && (stat.dev <= 0n || stat.ino <= 0n)) {
|
|
2727
|
+
throw new Error('memory_graph_path_rejected');
|
|
2728
|
+
}
|
|
2729
|
+
return stat;
|
|
2724
2730
|
}
|
|
2725
2731
|
function sameGraphFileIdentity(left, right) {
|
|
2726
2732
|
const hasStableFileId = left.dev !== 0n || left.ino !== 0n || right.dev !== 0n || right.ino !== 0n;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface PluginDraft {
|
|
2
|
+
id: string;
|
|
3
|
+
runtime: string;
|
|
4
|
+
title: string;
|
|
5
|
+
summary: string;
|
|
6
|
+
score: number | null;
|
|
7
|
+
createdAt: string;
|
|
8
|
+
gene: Record<string, unknown> | null;
|
|
9
|
+
capsule: Record<string, unknown> | null;
|
|
10
|
+
}
|
|
11
|
+
export interface PluginDrafts {
|
|
12
|
+
drafts: PluginDraft[];
|
|
13
|
+
/** Runtimes whose drafts file exists but could not be read: missing drafts there are unknown, not absent. */
|
|
14
|
+
unreadable: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare const RUNTIME_NAME: RegExp;
|
|
17
|
+
/** The agent plugin's unconfirmed distillation drafts (`~/.evolver/state/<runtime>-distill-drafts.json`), read in place. */
|
|
18
|
+
export declare function pluginDrafts(env: Readonly<Record<string, string | undefined>>, runtime?: string): PluginDrafts;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export const RUNTIME_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
5
|
+
const DRAFTS_FILE = /^([a-z0-9][a-z0-9-]{0,39})-distill-drafts\.json$/;
|
|
6
|
+
const MAX_FILE_BYTES = 16 * 1024 * 1024;
|
|
7
|
+
const isRecord = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
8
|
+
function stateDir(env) {
|
|
9
|
+
return join(env['HOME'] || env['USERPROFILE'] || homedir(), '.evolver', 'state');
|
|
10
|
+
}
|
|
11
|
+
const MAX_DATE_MS = 8.64e15;
|
|
12
|
+
/** One malformed timestamp blanks that draft's date; it must not make the whole file unreadable. */
|
|
13
|
+
function isoTime(value) {
|
|
14
|
+
const time = typeof value === 'number' ? value : typeof value === 'string' ? Date.parse(value) : Number.NaN;
|
|
15
|
+
return Number.isFinite(time) && Math.abs(time) <= MAX_DATE_MS ? new Date(time).toISOString() : '';
|
|
16
|
+
}
|
|
17
|
+
function assetOf(assets, type) {
|
|
18
|
+
return Array.isArray(assets) ? assets.find((asset) => isRecord(asset) && asset['type'] === type) ?? null : null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reads through one descriptor, so the size checked is the size read. The path must be a regular file before opening and the
|
|
22
|
+
* opened file must be that same file, which also holds where `O_NOFOLLOW` does not exist (Windows).
|
|
23
|
+
*/
|
|
24
|
+
function readBounded(path) {
|
|
25
|
+
const before = lstatSync(path);
|
|
26
|
+
if (!before.isFile())
|
|
27
|
+
throw new Error('drafts_file_unreadable');
|
|
28
|
+
const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
29
|
+
try {
|
|
30
|
+
const stat = fstatSync(fd);
|
|
31
|
+
if (!stat.isFile() || stat.dev !== before.dev || stat.ino !== before.ino || stat.size > MAX_FILE_BYTES)
|
|
32
|
+
throw new Error('drafts_file_unreadable');
|
|
33
|
+
const buffer = Buffer.alloc(MAX_FILE_BYTES + 1);
|
|
34
|
+
let length = 0;
|
|
35
|
+
for (let read = -1; read !== 0 && length <= MAX_FILE_BYTES;) {
|
|
36
|
+
read = readSync(fd, buffer, length, buffer.length - length, length);
|
|
37
|
+
length += read;
|
|
38
|
+
}
|
|
39
|
+
if (length > MAX_FILE_BYTES)
|
|
40
|
+
throw new Error('drafts_file_unreadable');
|
|
41
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(buffer.subarray(0, length));
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
closeSync(fd);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function draftsIn(path, runtime) {
|
|
48
|
+
const rows = JSON.parse(readBounded(path));
|
|
49
|
+
if (!Array.isArray(rows))
|
|
50
|
+
throw new Error('drafts_file_unreadable');
|
|
51
|
+
return rows.filter(isRecord).filter((row) => typeof row['id'] === 'string' || typeof row['id'] === 'number').map((row) => ({
|
|
52
|
+
id: String(row['id']),
|
|
53
|
+
runtime,
|
|
54
|
+
title: typeof row['title'] === 'string' ? row['title'] : '',
|
|
55
|
+
summary: typeof row['summary'] === 'string' ? row['summary'] : '',
|
|
56
|
+
score: typeof row['score'] === 'number' ? row['score'] : null,
|
|
57
|
+
createdAt: isoTime(row['createdAt']),
|
|
58
|
+
gene: assetOf(row['assets'], 'Gene'),
|
|
59
|
+
capsule: assetOf(row['assets'], 'Capsule'),
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
/** The agent plugin's unconfirmed distillation drafts (`~/.evolver/state/<runtime>-distill-drafts.json`), read in place. */
|
|
63
|
+
export function pluginDrafts(env, runtime) {
|
|
64
|
+
let names;
|
|
65
|
+
try {
|
|
66
|
+
names = readdirSync(stateDir(env));
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error.code === 'ENOENT')
|
|
70
|
+
return { drafts: [], unreadable: [] };
|
|
71
|
+
throw new Error('drafts_state_unreadable', { cause: error });
|
|
72
|
+
}
|
|
73
|
+
const drafts = [];
|
|
74
|
+
const unreadable = [];
|
|
75
|
+
for (const name of names) {
|
|
76
|
+
const owner = DRAFTS_FILE.exec(name)?.[1];
|
|
77
|
+
if (!owner || (runtime !== undefined && owner !== runtime))
|
|
78
|
+
continue;
|
|
79
|
+
try {
|
|
80
|
+
drafts.push(...draftsIn(join(stateDir(env), name), owner));
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
unreadable.push(owner);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { drafts: drafts.sort((a, b) => b.createdAt.localeCompare(a.createdAt)), unreadable };
|
|
87
|
+
}
|
|
@@ -265,6 +265,7 @@ async function selectPromptGenes(prompt, snapshot, maxGenes, budget, benchmark)
|
|
|
265
265
|
const boundedPrompt = promptTokens.join(' ');
|
|
266
266
|
const receipts = new Map();
|
|
267
267
|
const approved = recall.approvedGenesFromSnapshot(snapshot, PROMPT_RECALL_SCAN_LIMIT, {
|
|
268
|
+
recent: true,
|
|
268
269
|
signal: budget.signal, deadlineAt: budget.deadlineAt,
|
|
269
270
|
...(benchmark ? { benchmark } : {}),
|
|
270
271
|
onQualification: (values) => { for (const receipt of values)
|
|
@@ -574,6 +575,7 @@ async function runPromptRecallHookOwned(argv, deps) {
|
|
|
574
575
|
if (!recall.isBuiltInPromptProvider(store))
|
|
575
576
|
throw new Error('unsupported_prompt_context_provider_v1');
|
|
576
577
|
return store.beginPromptGeneSnapshotV1({
|
|
578
|
+
recent: true,
|
|
577
579
|
deadlineAt: budget.deadlineAt, signal: budget.signal,
|
|
578
580
|
maxFileBytes: MAX_PROMPT_RECALL_LOCAL_FILE_BYTES, maxTotalBytes: MAX_PROMPT_RECALL_LOCAL_TOTAL_BYTES
|
|
579
581
|
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type JsonCommandIo } from './jsonCommand.js';
|
|
2
|
+
/**
|
|
3
|
+
* `evolver publish-policy get|set --json`. In `manual` the Proxy's background curation still promotes trial Genes but
|
|
4
|
+
* never enqueues a publish; the policy lives with this node's asset store and the Proxy rereads it every pass.
|
|
5
|
+
*/
|
|
6
|
+
export declare function runPublishPolicyCommand(argv: string[], io?: JsonCommandIo): Promise<number>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { assetstore, events } from '@evomap/evolver-core';
|
|
2
|
+
import { SMALL_REQUEST_BYTES, operationOf, readJsonRequest, requestLocale, requiredEnum, runJsonCommand } from './jsonCommand.js';
|
|
3
|
+
const PUBLISH_POLICY_COMMAND_SCHEMA = 'evolver.publish-policy.v1';
|
|
4
|
+
/**
|
|
5
|
+
* `evolver publish-policy get|set --json`. In `manual` the Proxy's background curation still promotes trial Genes but
|
|
6
|
+
* never enqueues a publish; the policy lives with this node's asset store and the Proxy rereads it every pass.
|
|
7
|
+
*/
|
|
8
|
+
export async function runPublishPolicyCommand(argv, io = {}) {
|
|
9
|
+
const { operation, error } = operationOf(argv, ['get', 'set'], io);
|
|
10
|
+
return runJsonCommand(PUBLISH_POLICY_COMMAND_SCHEMA, operation, io, async () => {
|
|
11
|
+
if (error)
|
|
12
|
+
throw error;
|
|
13
|
+
const dir = events.assetsDir(io.env ?? process.env);
|
|
14
|
+
if (operation === 'get')
|
|
15
|
+
return assetstore.readPublishPolicy(dir);
|
|
16
|
+
const request = await readJsonRequest(SMALL_REQUEST_BYTES, io);
|
|
17
|
+
return assetstore.writePublishPolicy(dir, requiredEnum(request, 'mode', assetstore.PUBLISH_MODES, requestLocale(request, io)));
|
|
18
|
+
});
|
|
19
|
+
}
|
package/dist/redact.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type JsonCommandIo } from './jsonCommand.js';
|
|
2
|
+
/** `evolver redact --json`: what would be removed from each text before it leaves this machine, with exact offsets. Read-only. */
|
|
3
|
+
export declare function runRedactCommand(argv: string[], io?: JsonCommandIo): Promise<number>;
|
package/dist/redact.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { authoring } from '@evomap/evolver-core';
|
|
2
|
+
import { LARGE_REQUEST_BYTES, inputError, operationOf, optionalStrings, readJsonRequest, requestLocale, runJsonCommand, } from './jsonCommand.js';
|
|
3
|
+
const REDACT_SCHEMA = 'evolver.redact.v1';
|
|
4
|
+
const MAX_TEXTS = 500;
|
|
5
|
+
const MAX_TERMS = 200;
|
|
6
|
+
const MAX_TERM_CHARS = 200;
|
|
7
|
+
/** `evolver redact --json`: what would be removed from each text before it leaves this machine, with exact offsets. Read-only. */
|
|
8
|
+
export async function runRedactCommand(argv, io = {}) {
|
|
9
|
+
const { error } = operationOf(['redact', ...argv], ['redact'], io);
|
|
10
|
+
return runJsonCommand(REDACT_SCHEMA, 'redact', io, async () => {
|
|
11
|
+
if (error)
|
|
12
|
+
throw error;
|
|
13
|
+
const request = await readJsonRequest(LARGE_REQUEST_BYTES, io);
|
|
14
|
+
const locale = requestLocale(request, io);
|
|
15
|
+
const texts = optionalStrings(request, 'texts', locale, MAX_TEXTS, LARGE_REQUEST_BYTES);
|
|
16
|
+
if (!texts)
|
|
17
|
+
throw inputError(locale, `缺少 texts(最多 ${MAX_TEXTS} 段文本)。`, `Missing texts (at most ${MAX_TEXTS}).`);
|
|
18
|
+
const terms = optionalStrings(request, 'terms', locale, MAX_TERMS, MAX_TERM_CHARS);
|
|
19
|
+
const identifiers = optionalStrings(request, 'identifiers', locale, MAX_TERMS, MAX_TERM_CHARS);
|
|
20
|
+
const items = texts.map((text) => {
|
|
21
|
+
const { text: redacted, findings } = authoring.redactWithFindings({ text, env: io.env ?? process.env, locale,
|
|
22
|
+
...(terms ? { terms } : {}), ...(identifiers ? { identifiers } : {}) });
|
|
23
|
+
return { text: redacted, findings };
|
|
24
|
+
});
|
|
25
|
+
return { rulesVersion: authoring.REDACTION_RULES_VERSION, items };
|
|
26
|
+
});
|
|
27
|
+
}
|
package/dist/sessionIngest.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export type SessionContextDeliveryRecovery = {
|
|
|
44
44
|
} | {
|
|
45
45
|
status: 'unknown';
|
|
46
46
|
reason: 'recovery_failed' | 'deadline';
|
|
47
|
+
journal?: events.ContextDeliveryStatus;
|
|
47
48
|
};
|
|
48
49
|
/** Resolve context ownership before any recovery/index I/O. Physical aliases
|
|
49
50
|
* alone are insufficient: protected audit namespaces retain the exact logical
|
package/dist/sessionIngest.js
CHANGED
|
@@ -192,13 +192,16 @@ function finishSessionIndexCleanup(path) {
|
|
|
192
192
|
export async function runSessionIngestTick(dirs, deps = {}) {
|
|
193
193
|
const resolvedDeps = resolveIngestDeps(deps);
|
|
194
194
|
const contextIngestor = resolveContextObservationWriter(resolvedDeps.ingestor, deps.contextIngestor);
|
|
195
|
-
|
|
195
|
+
let contextDeliveryRecovery = contextIngestor
|
|
196
196
|
? await recoverSessionDeliveries(contextIngestor) : undefined;
|
|
197
197
|
if (contextIngestor) {
|
|
198
198
|
// A failed/late protected RPC can outlive its client wait. The existing
|
|
199
199
|
// ordered status RPC joins the service's turn before deciding root admission.
|
|
200
|
-
const journal = contextDeliveryRecovery
|
|
201
|
-
|
|
200
|
+
const journal = contextDeliveryRecovery?.journal ?? events.Ingestor.contextDeliveryStatus(contextIngestor.path);
|
|
201
|
+
// Preserve the admission snapshot without upgrading a late or failed recovery.
|
|
202
|
+
if (contextDeliveryRecovery && contextDeliveryRecovery.journal === undefined) {
|
|
203
|
+
contextDeliveryRecovery = { ...contextDeliveryRecovery, journal };
|
|
204
|
+
}
|
|
202
205
|
if (journal.confirmedPending > 0 || journal.reasons.cleanup_pending)
|
|
203
206
|
return {
|
|
204
207
|
recorded: 0, sourceAgents: [], signalKinds: [], signalStrengths: [],
|