eidetic-engine 0.15.1

Durable, local-first, explainable memory for coding agents.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
//! Canonical volatile-field registry for determinism comparisons.
//!
//! These fields legitimately vary between invocations against the same
//! workspace state, so J7-style determinism checks strip them before hashing
//! machine-facing JSON outputs.

use std::collections::BTreeSet;

use serde_json::Value;

use super::test_log::{EventKind, TestEvent, log_event, test_id_or};

/// Canonical list of fields that legitimately vary between invocations against
/// the same workspace state.
pub const VOLATILE_FIELD_NAMES: &[&str] = &[
    "generatedAt",
    "generated_at",
    "createdAt",
    "created_at",
    "updatedAt",
    "completedAt",
    "finishedAt",
    "expiresAt",
    "capturedAt",
    "captured_at",
    "computedAt",
    "computed_at",
    "observedAt",
    "recordedAt",
    "refreshedAt",
    "selectedAt",
    "decidedAt",
    "estimatedAt",
    "exposedAt",
    "lastValidatedAt",
    "last_accessed",
    "last_accessed_at",
    "last_seen_at",
    "last_used_at",
    "audit_ts",
    "elapsedMs",
    "elapsed_ms",
    "elapsedMsBucket",
    "durationMs",
    "wallClockMs",
    "startedAt",
    "started_at",
    "endedAt",
    "ended_at",
    "ts",
    "timestamp",
    "runIndex",
    "run_index",
    "runDurationMs",
    "run_duration_ms",
    "ee_binary_hash",
    // Handoff capsule determinism (bd-1um33): capsule_id and integrity are
    // freshly generated per create even for identical workspace state.
    // swarm_brief_summary/swarm_incident_summary/swarm_replay_summary and
    // environment_attestation_summary are runtime diagnostic subtrees;
    // section-level diagnostic redaction is handled specially in handoff.rs
    // (value-dependent on "id" field), but volatile top-level children are
    // covered here.
    "capsule_id",
    "integrity",
    "swarm_brief_summary",
    "swarm_incident_summary",
    "swarm_replay_summary",
    "environment_attestation_summary",
    // Newer capsule diagnostic subtrees (same class as the four above): they
    // embed run-scoped attestation ids, artifact hashes over volatile inputs,
    // and raw command output carrying timestamps, so two creates of the same
    // workspace state would otherwise produce different canonical hashes.
    "pack_replay_summary",
    "proof_broker_summary",
    "regression_causality_summary",
    "shadow_policy_summary",
    "contention_summary",
    "databasePath",
    "workspacePath",
    "indexDir",
    // Graph determinism surfaces (previously only in the determinism.sh bash
    // mirror; registered here so the two lists stay identical).
    "snapshotRefreshedAt",
    "witnessElapsedMs",
    "witnessRecordedAt",
    "algorithmStartedAt",
    "projectionMs",
    "pagerankMs",
    "betweennessMs",
    "totalMs",
    // Tailscale local-probe identity fields are machine/network specific and
    // sensitive in shared support bundles.
    "selfNodeKey",
    "selfTailscaleIp",
    "selfMagicDnsName",
    "tailnetId",
    "tailnetDisplayName",
    "selfAdvertisedTags",
    "peerNodeKey",
    "peerTailscaleIps",
    "peerMagicDnsName",
    "peerHostname",
    "peerAdvertisedTags",
    "binaryVersionRaw",
    "binaryAbsolutePath",
];

/// Report emitted by a volatile-field strip operation.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct VolatileStripReport {
    /// Number of distinct volatile field names removed.
    pub fields_stripped_count: usize,
    /// Distinct volatile field names removed, in registry order.
    pub fields_stripped: Vec<&'static str>,
    /// JSON byte size before stripping, or 0 if serialization failed.
    pub input_bytes: usize,
    /// JSON byte size after stripping, or 0 if serialization failed.
    pub output_bytes: usize,
}

/// Return true when `field_name` is registered as volatile.
#[must_use]
pub fn is_volatile_field_name(field_name: &str) -> bool {
    canonical_field_name(field_name).is_some()
}

/// Recursively remove volatile fields from a JSON value and emit a structured
/// test-log event when the J1 log harness is configured.
pub fn strip_volatile_fields(value: &mut Value) -> VolatileStripReport {
    let input_bytes = serialized_len(value);
    let mut stripped = BTreeSet::new();
    strip_volatile_fields_inner(value, &mut stripped);
    let output_bytes = serialized_len(value);
    let fields_stripped = VOLATILE_FIELD_NAMES
        .iter()
        .copied()
        .filter(|field| stripped.contains(field))
        .collect::<Vec<_>>();
    let report = VolatileStripReport {
        fields_stripped_count: fields_stripped.len(),
        fields_stripped,
        input_bytes,
        output_bytes,
    };
    log_volatile_strip(&report);
    report
}

fn strip_volatile_fields_inner(value: &mut Value, stripped: &mut BTreeSet<&'static str>) {
    match value {
        Value::Object(object) => {
            let keys = object
                .keys()
                .filter_map(|key| canonical_field_name(key))
                .collect::<Vec<_>>();
            for key in keys {
                object.remove(key);
                stripped.insert(key);
            }
            for child in object.values_mut() {
                strip_volatile_fields_inner(child, stripped);
            }
        }
        Value::Array(items) => {
            for item in items {
                strip_volatile_fields_inner(item, stripped);
            }
        }
        _ => {}
    }
}

fn canonical_field_name(field_name: &str) -> Option<&'static str> {
    VOLATILE_FIELD_NAMES
        .iter()
        .copied()
        .find(|registered| *registered == field_name)
}

fn serialized_len(value: &Value) -> usize {
    serde_json::to_vec(value).map_or(0, |bytes| bytes.len())
}

fn log_volatile_strip(report: &VolatileStripReport) {
    let fields = report
        .fields_stripped
        .iter()
        .map(|field| Value::String((*field).to_owned()))
        .collect::<Vec<_>>();
    let event = TestEvent::new(test_id_or("volatile_field_strip"), EventKind::VolatileStrip)
        .with_field(
            "fields_stripped_count",
            u64::try_from(report.fields_stripped_count).unwrap_or(u64::MAX),
        )
        .with_field("fields_stripped", Value::Array(fields))
        .with_field(
            "input_bytes",
            u64::try_from(report.input_bytes).unwrap_or(u64::MAX),
        )
        .with_field(
            "output_bytes",
            u64::try_from(report.output_bytes).unwrap_or(u64::MAX),
        );
    log_event(event);
}

#[cfg(test)]
mod tests {
    use super::{VOLATILE_FIELD_NAMES, is_volatile_field_name, strip_volatile_fields};

    type TestResult = Result<(), String>;

    #[test]
    fn registry_names_are_unique() -> TestResult {
        let mut names = std::collections::BTreeSet::new();
        for name in VOLATILE_FIELD_NAMES {
            if name.trim().is_empty() {
                return Err("empty volatile field name".to_owned());
            }
            if !names.insert(name) {
                return Err(format!("duplicate volatile field name: {name}"));
            }
        }
        Ok(())
    }

    #[test]
    fn strip_volatile_fields_recurses_and_reports() -> TestResult {
        let mut value = serde_json::json!({
            "schema": "ee.response.v2",
            "generatedAt": "2026-05-13T00:00:00Z",
            "data": {
                "createdAt": "2026-05-13T00:00:00Z",
                "updatedAt": "2026-05-13T00:00:01Z",
                "computed_at": "2026-05-13T00:00:01Z",
                "observedAt": "2026-05-13T00:00:02Z",
                "items": [
                    {"id": "mem_a", "elapsedMs": 12, "durationMs": 11, "content": "keep"},
                    {"id": "mem_b", "last_seen_at": "2026-05-13T00:00:01Z"}
                ],
                "workspacePath": "/tmp/ws"
            }
        });
        let report = strip_volatile_fields(&mut value);
        if value.pointer("/generatedAt").is_some()
            || value.pointer("/data/createdAt").is_some()
            || value.pointer("/data/updatedAt").is_some()
            || value.pointer("/data/computed_at").is_some()
            || value.pointer("/data/observedAt").is_some()
            || value.pointer("/data/items/0/elapsedMs").is_some()
            || value.pointer("/data/items/0/durationMs").is_some()
            || value.pointer("/data/items/1/last_seen_at").is_some()
            || value.pointer("/data/workspacePath").is_some()
        {
            return Err(format!("volatile fields were not stripped: {value}"));
        }
        if value
            .pointer("/data/items/0/content")
            .and_then(|v| v.as_str())
            != Some("keep")
        {
            return Err("non-volatile content was stripped".to_owned());
        }
        for expected in [
            "generatedAt",
            "createdAt",
            "updatedAt",
            "computed_at",
            "observedAt",
            "elapsedMs",
            "durationMs",
            "last_seen_at",
            "workspacePath",
        ] {
            if !report.fields_stripped.contains(&expected) {
                return Err(format!("report missing stripped field {expected}"));
            }
        }
        Ok(())
    }

    #[test]
    fn registry_predicate_matches_list() {
        assert!(is_volatile_field_name("generatedAt"));
        assert!(is_volatile_field_name("createdAt"));
        assert!(is_volatile_field_name("created_at"));
        assert!(is_volatile_field_name("updatedAt"));
        assert!(is_volatile_field_name("completedAt"));
        assert!(is_volatile_field_name("expiresAt"));
        assert!(is_volatile_field_name("observedAt"));
        assert!(is_volatile_field_name("recordedAt"));
        assert!(is_volatile_field_name("selectedAt"));
        assert!(is_volatile_field_name("lastValidatedAt"));
        assert!(is_volatile_field_name("durationMs"));
        assert!(is_volatile_field_name("captured_at"));
        assert!(is_volatile_field_name("last_accessed_at"));
        assert!(is_volatile_field_name("capsule_id"));
        assert!(is_volatile_field_name("integrity"));
        assert!(is_volatile_field_name("swarm_brief_summary"));
        assert!(is_volatile_field_name("swarm_incident_summary"));
        assert!(is_volatile_field_name("swarm_replay_summary"));
        assert!(!is_volatile_field_name("content"));
    }

    #[test]
    fn strip_volatile_fields_covers_handoff_capsule_names() -> TestResult {
        let mut value = serde_json::json!({
            "schema": "ee.handoff.capsule.v1",
            "capsule_id": "cap_a",
            "created_at": "2026-05-16T00:00:00Z",
            "integrity": {"hmac": "secret"},
            "swarm_brief_summary": {"hostname": "agent-host"},
            "swarm_incident_summary": {"summaryHash": "blake3:volatile"},
            "swarm_replay_summary": {"summaryHash": "blake3:volatile-replay"},
            "memory_snapshot": {"captured_at": "2026-05-16T00:00:00Z"},
            "sections": [
                {
                    "id": "objective",
                    "content": "keep this"
                }
            ]
        });
        let report = strip_volatile_fields(&mut value);

        for pointer in [
            "/capsule_id",
            "/created_at",
            "/integrity",
            "/swarm_brief_summary",
            "/swarm_incident_summary",
            "/swarm_replay_summary",
            "/memory_snapshot/captured_at",
        ] {
            if value.pointer(pointer).is_some() {
                return Err(format!("{pointer} was not stripped: {value}"));
            }
        }
        if value
            .pointer("/sections/0/content")
            .and_then(|v| v.as_str())
            != Some("keep this")
        {
            return Err("non-volatile handoff section content was stripped".to_owned());
        }
        for expected in [
            "capsule_id",
            "created_at",
            "captured_at",
            "integrity",
            "swarm_brief_summary",
            "swarm_incident_summary",
            "swarm_replay_summary",
        ] {
            if !report.fields_stripped.contains(&expected) {
                return Err(format!("report missing stripped capsule field {expected}"));
            }
        }
        Ok(())
    }

    #[test]
    fn strip_volatile_fields_covers_tailscale_local_probe_identity() -> TestResult {
        let mut value = serde_json::json!({
            "schema": "ee.response.v2",
            "data": {
                "mesh": {
                    "tailscale": {
                        "schema": "ee.tailscale.local.v1",
                        "tailnetId": "tailnet-alpha",
                        "tailnetDisplayName": "alpha.example",
                        "selfNodeKey": "nodekey:selfalpha",
                        "selfTailscaleIp": "100.64.0.10",
                        "selfMagicDnsName": "ee-local.tailnet.test.",
                        "selfAdvertisedTags": ["tag:ee-mesh"],
                        "peers": [{
                            "peerNodeKey": "nodekey:peeralpha",
                            "peerTailscaleIps": ["100.64.0.20"],
                            "peerMagicDnsName": "peer-alpha.tailnet.test.",
                            "peerHostname": "peer-alpha",
                            "peerAdvertisedTags": ["tag:ee-mesh"],
                            "online": true
                        }],
                        "binaryVersionRaw": "1.66.0\n  tailscale commit: abc",
                        "binaryAbsolutePath": "/opt/homebrew/bin/tailscale",
                        "probeMethod": "cli"
                    }
                }
            }
        });
        let report = strip_volatile_fields(&mut value);

        for pointer in [
            "/data/mesh/tailscale/tailnetId",
            "/data/mesh/tailscale/tailnetDisplayName",
            "/data/mesh/tailscale/selfNodeKey",
            "/data/mesh/tailscale/selfTailscaleIp",
            "/data/mesh/tailscale/selfMagicDnsName",
            "/data/mesh/tailscale/selfAdvertisedTags",
            "/data/mesh/tailscale/peers/0/peerNodeKey",
            "/data/mesh/tailscale/peers/0/peerTailscaleIps",
            "/data/mesh/tailscale/peers/0/peerMagicDnsName",
            "/data/mesh/tailscale/peers/0/peerHostname",
            "/data/mesh/tailscale/peers/0/peerAdvertisedTags",
            "/data/mesh/tailscale/binaryVersionRaw",
            "/data/mesh/tailscale/binaryAbsolutePath",
        ] {
            if value.pointer(pointer).is_some() {
                return Err(format!("{pointer} was not stripped: {value}"));
            }
        }
        if value
            .pointer("/data/mesh/tailscale/probeMethod")
            .and_then(|v| v.as_str())
            != Some("cli")
        {
            return Err("non-volatile tailscale field was stripped".to_owned());
        }
        for expected in [
            "tailnetId",
            "tailnetDisplayName",
            "selfNodeKey",
            "selfTailscaleIp",
            "selfMagicDnsName",
            "selfAdvertisedTags",
            "peerNodeKey",
            "peerTailscaleIps",
            "peerMagicDnsName",
            "peerHostname",
            "peerAdvertisedTags",
            "binaryVersionRaw",
            "binaryAbsolutePath",
        ] {
            if !report.fields_stripped.contains(&expected) {
                return Err(format!(
                    "report missing stripped tailscale field {expected}"
                ));
            }
        }
        Ok(())
    }
}