@evomap/evolver-cli 2.0.48 → 2.0.50
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/autoDistillTranscript.d.ts +1 -1
- package/dist/autoDistillTranscript.js +9 -2
- package/dist/autoexec.js +3 -0
- package/dist/cliContracts.js +5 -28
- package/dist/cycleConsumer.js +3 -0
- package/dist/distillAdmission.d.ts +8 -1
- package/dist/distillAdmission.js +30 -0
- package/dist/distillObserver.d.ts +0 -6
- package/dist/distillObserver.js +17 -5
- package/dist/distillPrimitives.d.ts +4 -3
- package/dist/distillPrimitives.js +27 -18
- package/dist/doctor.d.ts +3 -0
- package/dist/doctor.js +17 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/lifecycle.d.ts +9 -0
- package/dist/lifecycle.js +159 -102
- package/dist/lifecycleAutoexecCompanion.d.ts +40 -0
- package/dist/lifecycleAutoexecCompanion.js +102 -0
- package/dist/lifecycleBootstrapTransaction.js +38 -17
- package/dist/llmCycle.js +15 -5
- package/dist/localMemoryGraph.js +29 -19
- package/dist/promptRecallRuntime.d.ts +3 -0
- package/dist/promptRecallRuntime.js +8 -0
- package/dist/promptRecallShared.d.ts +2 -0
- package/dist/promptRecallShared.js +13 -3
- package/dist/protectedAuditStatus.d.ts +22 -0
- package/dist/protectedAuditStatus.js +234 -0
- package/dist/recall.js +2 -3
- package/dist/runtimeCapabilities.d.ts +1 -1
- package/dist/runtimeCapabilities.js +24 -0
- package/dist/runtimeSessionSource.js +4 -4
- package/dist/sessionIngest.js +3 -0
- package/dist/setupHooks.d.ts +3 -0
- package/dist/setupHooks.js +98 -17
- 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/trajectoryExport.js +2 -2
- package/package.json +7 -7
|
@@ -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/llmCycle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from 'node:fs';
|
|
2
|
-
import { exec, verify } from '@evomap/evolver-core';
|
|
2
|
+
import { assetstore, exec, verify } from '@evomap/evolver-core';
|
|
3
3
|
import { createLlmGit } from './llmGit.js';
|
|
4
4
|
/** Read the operator's acceptance plan once, before any material is claimed or model dispatched. */
|
|
5
5
|
export function readCycleValidationSpec(path) {
|
|
@@ -7,12 +7,19 @@ export function readCycleValidationSpec(path) {
|
|
|
7
7
|
throw new Error('--validation-spec requires a file path');
|
|
8
8
|
let fd;
|
|
9
9
|
try {
|
|
10
|
-
const
|
|
11
|
-
if (!
|
|
10
|
+
const named = lstatSync(path, { bigint: true });
|
|
11
|
+
if (!named.isFile() || named.isSymbolicLink() || named.nlink !== 1n || named.size > 65536n)
|
|
12
|
+
throw new Error();
|
|
13
|
+
const before = assetstore.captureRegularAssetFileSnapshot(path);
|
|
14
|
+
if (((process.platform !== 'win32' || named.dev !== 0n) && named.dev !== before.dev)
|
|
15
|
+
|| named.ino !== before.ino || named.birthtimeNs !== before.birthtimeNs || named.nlink !== before.nlink
|
|
16
|
+
|| named.mode !== before.mode || named.size !== before.size
|
|
17
|
+
|| named.mtimeNs !== before.mtimeNs || named.ctimeNs !== before.ctimeNs)
|
|
12
18
|
throw new Error();
|
|
13
19
|
fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
14
20
|
const opened = fstatSync(fd, { bigint: true });
|
|
15
|
-
if (before.dev !== opened.dev || before.ino !== opened.ino || before.
|
|
21
|
+
if (before.dev !== opened.dev || before.ino !== opened.ino || before.birthtimeNs !== opened.birthtimeNs
|
|
22
|
+
|| before.nlink !== opened.nlink || before.mode !== opened.mode || before.size !== opened.size
|
|
16
23
|
|| before.mtimeNs !== opened.mtimeNs || before.ctimeNs !== opened.ctimeNs)
|
|
17
24
|
throw new Error();
|
|
18
25
|
const buffer = Buffer.alloc(65_537);
|
|
@@ -25,7 +32,10 @@ export function readCycleValidationSpec(path) {
|
|
|
25
32
|
}
|
|
26
33
|
const bytes = buffer.subarray(0, count);
|
|
27
34
|
const after = fstatSync(fd, { bigint: true });
|
|
28
|
-
|
|
35
|
+
const pathAfter = assetstore.captureRegularAssetFileSnapshot(path);
|
|
36
|
+
if (bytes.length > 65_536 || [after, pathAfter].some(stat => stat.dev !== opened.dev || stat.ino !== opened.ino
|
|
37
|
+
|| stat.birthtimeNs !== opened.birthtimeNs || stat.nlink !== opened.nlink || stat.mode !== opened.mode
|
|
38
|
+
|| stat.size !== opened.size || stat.mtimeNs !== opened.mtimeNs || stat.ctimeNs !== opened.ctimeNs))
|
|
29
39
|
throw new Error();
|
|
30
40
|
return verify.parseDeclarativeValidationSpec(JSON.parse(bytes.toString('utf8')));
|
|
31
41
|
}
|
package/dist/localMemoryGraph.js
CHANGED
|
@@ -3,7 +3,7 @@ import { closeSync, constants, existsSync, fstatSync, ftruncateSync, fsyncSync,
|
|
|
3
3
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
4
4
|
import { userInfo } from 'node:os';
|
|
5
5
|
import { gzipSync, gunzipSync } from 'node:zlib';
|
|
6
|
-
import { reference, algo, events, util } from '@evomap/evolver-core';
|
|
6
|
+
import { reference, algo, events, util, assetstore } from '@evomap/evolver-core';
|
|
7
7
|
import { MAX_TRIGGER_FEEDBACK_BYTES, TRIGGER_FEEDBACK_FILE, readLocalTriggerFeedback, upsertLocalTriggerFeedback, triggerFeedbackRecords } from './localTriggerFeedback.js';
|
|
8
8
|
import { authorizeTriggerFeedbackDelivery, claimTriggerFeedbackDelivery, markTriggerFeedbackDispatched, settleTriggerFeedbackDelivery } from './triggerFeedbackSyncState.js';
|
|
9
9
|
const ACTIVE_FILE = 'memory_graph.v2.jsonl';
|
|
@@ -524,7 +524,7 @@ export class LocalMemoryGraph {
|
|
|
524
524
|
const payload = this.readResetSource(file);
|
|
525
525
|
const destination = join(backup.pendingDir, file.name);
|
|
526
526
|
this.writeAtomic(destination, payload);
|
|
527
|
-
const copiedIdentity =
|
|
527
|
+
const copiedIdentity = graphPathSnapshot(destination);
|
|
528
528
|
const copiedPayload = this.readRawBounded(destination, payload.length);
|
|
529
529
|
if (!copiedIdentity.isFile() || copiedIdentity.isSymbolicLink()
|
|
530
530
|
|| copiedPayload === null || !copiedPayload.equals(payload)) {
|
|
@@ -596,7 +596,7 @@ export class LocalMemoryGraph {
|
|
|
596
596
|
const path = join(this.dir, name);
|
|
597
597
|
let identity;
|
|
598
598
|
try {
|
|
599
|
-
identity =
|
|
599
|
+
identity = graphPathSnapshot(path);
|
|
600
600
|
}
|
|
601
601
|
catch (error) {
|
|
602
602
|
if (isObject(error) && error['code'] === 'ENOENT')
|
|
@@ -661,7 +661,7 @@ export class LocalMemoryGraph {
|
|
|
661
661
|
cleanupResetPendingDirectory(backup, copied) {
|
|
662
662
|
for (const file of [...copied].reverse()) {
|
|
663
663
|
try {
|
|
664
|
-
const current =
|
|
664
|
+
const current = graphPathSnapshot(file.path);
|
|
665
665
|
if (current.isFile() && !current.isSymbolicLink()
|
|
666
666
|
&& sameGraphFileIdentity(file.identity, current))
|
|
667
667
|
unlinkSync(file.path);
|
|
@@ -773,7 +773,7 @@ export class LocalMemoryGraph {
|
|
|
773
773
|
const path = join(this.dir, EPOCH_FILE);
|
|
774
774
|
let identity;
|
|
775
775
|
try {
|
|
776
|
-
identity =
|
|
776
|
+
identity = graphPathSnapshot(path);
|
|
777
777
|
}
|
|
778
778
|
catch (error) {
|
|
779
779
|
if (isObject(error) && error['code'] === 'ENOENT') {
|
|
@@ -856,7 +856,7 @@ export class LocalMemoryGraph {
|
|
|
856
856
|
if (!baseline)
|
|
857
857
|
return false;
|
|
858
858
|
try {
|
|
859
|
-
const current =
|
|
859
|
+
const current = graphPathSnapshot(join(this.dir, COMPACT_FILE));
|
|
860
860
|
return current.isFile() && !current.isSymbolicLink()
|
|
861
861
|
&& serializedSnapshotMatches(baseline, current);
|
|
862
862
|
}
|
|
@@ -886,7 +886,7 @@ export class LocalMemoryGraph {
|
|
|
886
886
|
const path = join(this.dir, ACTIVE_FILE);
|
|
887
887
|
let identity;
|
|
888
888
|
try {
|
|
889
|
-
identity =
|
|
889
|
+
identity = graphPathSnapshot(path);
|
|
890
890
|
}
|
|
891
891
|
catch (error) {
|
|
892
892
|
if (isObject(error) && error['code'] === 'ENOENT') {
|
|
@@ -955,7 +955,7 @@ export class LocalMemoryGraph {
|
|
|
955
955
|
if (!expected)
|
|
956
956
|
return true;
|
|
957
957
|
try {
|
|
958
|
-
const current =
|
|
958
|
+
const current = graphPathSnapshot(join(this.dir, file));
|
|
959
959
|
return !current.isFile() || current.isSymbolicLink()
|
|
960
960
|
|| !serializedSnapshotMatches(expected, current);
|
|
961
961
|
}
|
|
@@ -1074,7 +1074,7 @@ export class LocalMemoryGraph {
|
|
|
1074
1074
|
const archives = this.archiveFiles().length;
|
|
1075
1075
|
let activeOversized = false;
|
|
1076
1076
|
if (existsSync(activePath) && this.secureRegularFile(activePath)) {
|
|
1077
|
-
const activeIdentity =
|
|
1077
|
+
const activeIdentity = graphPathSnapshot(activePath);
|
|
1078
1078
|
const window = this.activeLogicalWindow(epoch, activeIdentity);
|
|
1079
1079
|
activeOversized = window.invalid || window.size > this.maxActiveBytes;
|
|
1080
1080
|
}
|
|
@@ -1199,7 +1199,7 @@ export class LocalMemoryGraph {
|
|
|
1199
1199
|
const path = join(this.dir, file);
|
|
1200
1200
|
let stat;
|
|
1201
1201
|
try {
|
|
1202
|
-
stat =
|
|
1202
|
+
stat = graphPathSnapshot(path);
|
|
1203
1203
|
}
|
|
1204
1204
|
catch (error) {
|
|
1205
1205
|
if (isObject(error) && error['code'] === 'ENOENT')
|
|
@@ -1681,7 +1681,7 @@ export class LocalMemoryGraph {
|
|
|
1681
1681
|
rotationTargetMatches(path, target) {
|
|
1682
1682
|
let identity;
|
|
1683
1683
|
try {
|
|
1684
|
-
identity =
|
|
1684
|
+
identity = graphPathSnapshot(path);
|
|
1685
1685
|
}
|
|
1686
1686
|
catch (error) {
|
|
1687
1687
|
if (isObject(error) && error['code'] === 'ENOENT')
|
|
@@ -1716,7 +1716,7 @@ export class LocalMemoryGraph {
|
|
|
1716
1716
|
removeVerifiedRotationFile(path, identity, reason) {
|
|
1717
1717
|
let current;
|
|
1718
1718
|
try {
|
|
1719
|
-
current =
|
|
1719
|
+
current = graphPathSnapshot(path);
|
|
1720
1720
|
}
|
|
1721
1721
|
catch {
|
|
1722
1722
|
throw new Error(reason);
|
|
@@ -1736,7 +1736,7 @@ export class LocalMemoryGraph {
|
|
|
1736
1736
|
readVerifiedRotationFile(path, maxBytes, optional, reason, range) {
|
|
1737
1737
|
let pathBefore;
|
|
1738
1738
|
try {
|
|
1739
|
-
pathBefore =
|
|
1739
|
+
pathBefore = graphPathSnapshot(path);
|
|
1740
1740
|
}
|
|
1741
1741
|
catch (error) {
|
|
1742
1742
|
if (optional && isObject(error) && error['code'] === 'ENOENT')
|
|
@@ -1772,7 +1772,7 @@ export class LocalMemoryGraph {
|
|
|
1772
1772
|
const openedAfter = fstatSync(fd, { bigint: true });
|
|
1773
1773
|
let pathAfter;
|
|
1774
1774
|
try {
|
|
1775
|
-
pathAfter =
|
|
1775
|
+
pathAfter = graphPathSnapshot(path);
|
|
1776
1776
|
}
|
|
1777
1777
|
catch {
|
|
1778
1778
|
throw new Error(reason);
|
|
@@ -1811,7 +1811,7 @@ export class LocalMemoryGraph {
|
|
|
1811
1811
|
const path = join(this.dir, name);
|
|
1812
1812
|
let identity;
|
|
1813
1813
|
try {
|
|
1814
|
-
identity =
|
|
1814
|
+
identity = graphPathSnapshot(path);
|
|
1815
1815
|
}
|
|
1816
1816
|
catch (error) {
|
|
1817
1817
|
if (isObject(error) && error['code'] === 'ENOENT')
|
|
@@ -1935,7 +1935,7 @@ export class LocalMemoryGraph {
|
|
|
1935
1935
|
if (!this.secureRegularFile(activePath)) {
|
|
1936
1936
|
throw new MemoryGraphImportStateRejectedError();
|
|
1937
1937
|
}
|
|
1938
|
-
const activeWindow = this.activeLogicalWindow(epoch,
|
|
1938
|
+
const activeWindow = this.activeLogicalWindow(epoch, graphPathSnapshot(activePath));
|
|
1939
1939
|
if (activeWindow.invalid || activeWindow.size > this.maxActiveBytes) {
|
|
1940
1940
|
throw new MemoryGraphImportStateRejectedError();
|
|
1941
1941
|
}
|
|
@@ -2044,7 +2044,7 @@ export class LocalMemoryGraph {
|
|
|
2044
2044
|
let closed = false;
|
|
2045
2045
|
let published = false;
|
|
2046
2046
|
try {
|
|
2047
|
-
tempIdentity =
|
|
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 =
|
|
2074
|
+
const currentIdentity = graphPathSnapshot(temp, 'write');
|
|
2075
2075
|
if (currentIdentity.isFile() && !currentIdentity.isSymbolicLink()
|
|
2076
2076
|
&& sameGraphFileIdentity(tempIdentity, currentIdentity))
|
|
2077
2077
|
unlinkSync(temp);
|
|
@@ -2187,7 +2187,7 @@ export class LocalMemoryGraph {
|
|
|
2187
2187
|
if (!existsSync(path))
|
|
2188
2188
|
return null;
|
|
2189
2189
|
try {
|
|
2190
|
-
const identity =
|
|
2190
|
+
const identity = graphPathSnapshot(path);
|
|
2191
2191
|
if (epoch.baseline?.recovery
|
|
2192
2192
|
&& serializedSnapshotMatches(epoch.baseline.recovery, identity))
|
|
2193
2193
|
return null;
|
|
@@ -2718,6 +2718,16 @@ function writeAll(fd, payload, position = null) {
|
|
|
2718
2718
|
offset += written;
|
|
2719
2719
|
}
|
|
2720
2720
|
}
|
|
2721
|
+
function graphPathSnapshot(path, witnessAccess = 'read') {
|
|
2722
|
+
const named = lstatSync(path, { bigint: true });
|
|
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;
|
|
2730
|
+
}
|
|
2721
2731
|
function sameGraphFileIdentity(left, right) {
|
|
2722
2732
|
const hasStableFileId = left.dev !== 0n || left.ino !== 0n || right.dev !== 0n || right.ino !== 0n;
|
|
2723
2733
|
if (hasStableFileId)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as recall from '@evomap/evolver-core/prompt-recall';
|
|
2
|
+
import { type ProtectedAuditSessionNoticeOptions } from './protectedAuditStatus.js';
|
|
2
3
|
type HookInputReader = (signal?: AbortSignal) => string | undefined | Promise<string | undefined>;
|
|
3
4
|
export interface PromptRecallHookDeps {
|
|
4
5
|
store?: recall.AssetStoreProvider;
|
|
@@ -15,6 +16,8 @@ export interface PromptRecallHookDeps {
|
|
|
15
16
|
/** External delivery writers must own preparation, projection and terminal release. */
|
|
16
17
|
ingestor?: Pick<recall.Ingestor, 'prepareContextDelivery'> & Partial<Pick<recall.Ingestor, 'prepareContextDeliveryAsync' | 'recoverContextDeliveries'>>;
|
|
17
18
|
selectionTimeoutMs?: number;
|
|
19
|
+
/** Test seam for the protected audit probe and its per-session notice state. */
|
|
20
|
+
protectedAuditNotice?: ProtectedAuditSessionNoticeOptions;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
23
|
* Shared Claude Code/Codex UserPromptSubmit entrypoint. It is intentionally local-only and fail-open: no Hub
|
|
@@ -2,6 +2,7 @@ import * as recall from '@evomap/evolver-core/prompt-recall';
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { performance } from 'node:perf_hooks';
|
|
4
4
|
import { deliverContextOutput, waitContextDelivery } from './contextDelivery.js';
|
|
5
|
+
import { writeProtectedAuditSessionNotice, protectedAuditNoticeStatePath } from './protectedAuditStatus.js';
|
|
5
6
|
import { MAX_PROMPT_RECALL_STDIN_BYTES, MAX_PROMPT_RECALL_LOCAL_FILE_BYTES, MAX_PROMPT_RECALL_LOCAL_TOTAL_BYTES, promptRecallMode, wrapGeneContext, writeHookStdout, writeContextReadDiagnostic } from './promptRecallShared.js';
|
|
6
7
|
const PROMPT_RECALL_STDIN_TIMEOUT_MS = 250;
|
|
7
8
|
const PROMPT_RECALL_SELECTION_TIMEOUT_MS = 750;
|
|
@@ -264,6 +265,7 @@ async function selectPromptGenes(prompt, snapshot, maxGenes, budget, benchmark)
|
|
|
264
265
|
const boundedPrompt = promptTokens.join(' ');
|
|
265
266
|
const receipts = new Map();
|
|
266
267
|
const approved = recall.approvedGenesFromSnapshot(snapshot, PROMPT_RECALL_SCAN_LIMIT, {
|
|
268
|
+
recent: true,
|
|
267
269
|
signal: budget.signal, deadlineAt: budget.deadlineAt,
|
|
268
270
|
...(benchmark ? { benchmark } : {}),
|
|
269
271
|
onQualification: (values) => { for (const receipt of values)
|
|
@@ -543,6 +545,11 @@ async function runPromptRecallHookOwned(argv, deps) {
|
|
|
543
545
|
if (typeof input.hook_event_name === 'string' && input.hook_event_name !== 'UserPromptSubmit') {
|
|
544
546
|
throw new Error('unexpected hook event');
|
|
545
547
|
}
|
|
548
|
+
const auditReadiness = (deps.protectedAuditNotice?.readiness ?? recall.protectedAuditReadiness)();
|
|
549
|
+
if (auditReadiness.state === 'unavailable') {
|
|
550
|
+
await writeProtectedAuditSessionNotice(typeof input.session_id === 'string' ? input.session_id : undefined, auditReadiness, deps.protectedAuditNotice?.statePath ?? protectedAuditNoticeStatePath(recall.evomapHome(env)), deps, '{}\n');
|
|
551
|
+
return 0;
|
|
552
|
+
}
|
|
546
553
|
const prompt = input.prompt;
|
|
547
554
|
if (typeof prompt !== 'string')
|
|
548
555
|
throw new Error('prompt is not recallable');
|
|
@@ -568,6 +575,7 @@ async function runPromptRecallHookOwned(argv, deps) {
|
|
|
568
575
|
if (!recall.isBuiltInPromptProvider(store))
|
|
569
576
|
throw new Error('unsupported_prompt_context_provider_v1');
|
|
570
577
|
return store.beginPromptGeneSnapshotV1({
|
|
578
|
+
recent: true,
|
|
571
579
|
deadlineAt: budget.deadlineAt, signal: budget.signal,
|
|
572
580
|
maxFileBytes: MAX_PROMPT_RECALL_LOCAL_FILE_BYTES, maxTotalBytes: MAX_PROMPT_RECALL_LOCAL_TOTAL_BYTES
|
|
573
581
|
});
|
|
@@ -11,6 +11,8 @@ export declare function waitContextDelivery<T>(promise: Promise<T>, timeoutMs?:
|
|
|
11
11
|
export declare function promptRecallMode(env?: NodeJS.ProcessEnv): PromptRecallMode;
|
|
12
12
|
/** Rebind section offsets/digest to the actual prompt, including wrappers; never slice an assembled body. */
|
|
13
13
|
export declare function wrapGeneContext(context: assetstore.AssembledGeneContext, prefix: string, suffix: string): assetstore.AssembledGeneContext;
|
|
14
|
+
/** Only the transport's own pre-dispatch refusal proves no bytes were submitted. */
|
|
15
|
+
export declare function hookStdoutNotSubmitted(error: unknown): boolean;
|
|
14
16
|
/** A successful callback means stdout_written, not host_received. One attempt only, even on EPIPE. */
|
|
15
17
|
export declare function writeHookStdout(text: string, options?: {
|
|
16
18
|
destroyOnTimeout?: boolean;
|
|
@@ -47,13 +47,23 @@ export function wrapGeneContext(context, prefix, suffix) {
|
|
|
47
47
|
// One submitted write owns the stream until callback/close, including after
|
|
48
48
|
// caller timeout. Refuse retries instead of accumulating listeners and queued bytes.
|
|
49
49
|
const pendingStdoutWrites = new WeakMap();
|
|
50
|
+
class HookStdoutNotSubmittedError extends Error {
|
|
51
|
+
constructor() { super('hook_stdout_unconfirmed'); }
|
|
52
|
+
}
|
|
53
|
+
/** Only the transport's own pre-dispatch refusal proves no bytes were submitted. */
|
|
54
|
+
export function hookStdoutNotSubmitted(error) {
|
|
55
|
+
return error instanceof HookStdoutNotSubmittedError;
|
|
56
|
+
}
|
|
50
57
|
/** A successful callback means stdout_written, not host_received. One attempt only, even on EPIPE. */
|
|
51
58
|
export function writeHookStdout(text, options = {}) {
|
|
52
59
|
return new Promise((resolve, reject) => {
|
|
53
60
|
const stdout = process.stdout;
|
|
54
|
-
if (pendingStdoutWrites.has(stdout)) {
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
if (pendingStdoutWrites.has(stdout) || stdout.destroyed || stdout.writableEnded) {
|
|
62
|
+
try {
|
|
63
|
+
options.onSettled?.(false);
|
|
64
|
+
}
|
|
65
|
+
catch { /* The observer does not own the stream. */ }
|
|
66
|
+
reject(new HookStdoutNotSubmittedError());
|
|
57
67
|
return;
|
|
58
68
|
}
|
|
59
69
|
const owner = {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ProtectedAuditReadiness } from '@evomap/evolver-core/prompt-recall';
|
|
2
|
+
export type { ProtectedAuditReadiness };
|
|
3
|
+
export type ProtectedAuditInstallState = 'ready' | 'not_required' | 'not_provisioned' | 'unavailable';
|
|
4
|
+
export declare const PROTECTED_AUDIT_INSTALL_GUIDE: string;
|
|
5
|
+
export interface ProtectedAuditInstallReport {
|
|
6
|
+
protected_audit: ProtectedAuditInstallState;
|
|
7
|
+
protected_audit_next_step?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function protectedAuditInstallReport(readiness: ProtectedAuditReadiness): ProtectedAuditInstallReport;
|
|
10
|
+
export interface ProtectedAuditSessionNoticeOptions {
|
|
11
|
+
readiness?: () => ProtectedAuditReadiness;
|
|
12
|
+
statePath?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function protectedAuditNoticeStatePath(evomapHome: string): string;
|
|
15
|
+
interface NoticeWriter {
|
|
16
|
+
/** A trusted writer resolves only after its output is complete. */
|
|
17
|
+
stdout?: (text: string) => void | Promise<void>;
|
|
18
|
+
stdoutWithSettlement?: (text: string, onSettled: (written: boolean) => void) => Promise<void>;
|
|
19
|
+
onOutputWritten?: () => void;
|
|
20
|
+
}
|
|
21
|
+
/** Reserve before attempting one write; only the actual transport acknowledgement confirms it. */
|
|
22
|
+
export declare function writeProtectedAuditSessionNotice(sessionId: string | undefined, readiness: ProtectedAuditReadiness, path: string, writer: NoticeWriter, emptyOutput?: string): Promise<void>;
|