Files
el/engram/test/test_interoception_p5_dreams.c
T
will.anderson 77a4bc9326 M-INTEROCEPTION P5: dream-recall builtin engram_dreams_json (honesty rail)
Adds a read-only builtin that returns the curiosity_scan InternalStateEvents
created after a `since` cutoff that are STILL RESIDENT — "what I was chewing on
while you were gone." curiosity_scan is identified by the marker the soul writes
into each ISE's JSON content; heartbeat and other ISEs are excluded.

HARD honesty rail: it reports only ISEs still in the buffer. Anything rotated
out by the 48h engram_prune_telemetry is simply ABSENT — rotated-out = "I don't
remember", never a synthesized/plausible dream. Purely additive, no flag.

The HTTP route (GET /api/dreams?since=) is DEFERRED to cutover per the elc-drift
blocker (regenerating engram/dist diverges with no source change); the builtin
is exercised directly by the pure-C gate.

MEASURED on a copy: seeded 3 curiosity_scan (ancient/1h/now) + 1 heartbeat;
before prune dreams returned exactly the 3 curiosity_scan (heartbeat excluded);
after the 48h prune the ancient one was ABSENT (not confabulated), leaving 2;
the since-filter returned only the post-cutoff event; no returned id was ever
fabricated. ASan+UBSan clean.
2026-08-12 23:49:51 -05:00

48 lines
2.4 KiB
C

/* test_interoception_p5_dreams.c — M-INTEROCEPTION Priority 5.
* Dream-recall-on-wake: engram_dreams_json(since_ms). Honesty rail — only
* curiosity_scan ISEs still resident are returned; pruned (rotated-out) ones are
* ABSENT (never confabulated); heartbeat ISEs are excluded.
*/
#include "el_runtime.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
static el_val_t S(const char* s){ return EL_STR(s); }
int main(int argc,char** argv){
if(argc<2){ fprintf(stderr,"usage: %s <dir>\n",argv[0]); return 2; }
const char* dir=argv[1];
struct timeval tv; gettimeofday(&tv,NULL);
long long now=(long long)tv.tv_sec*1000+tv.tv_usec/1000;
long long mid=now-3600000; /* 1h ago */
long long ancient=1000; /* pruned by 48h retention */
char p[1024]; snprintf(p,sizeof p,"%s/seed.json",dir);
FILE* f=fopen(p,"w");
fprintf(f,"{\"nodes\":["
"{\"id\":\"cur_old\",\"content\":\"{\\\"kind\\\":\\\"curiosity_scan\\\",\\\"q\\\":\\\"old wondering\\\"}\","
"\"node_type\":\"InternalStateEvent\",\"label\":\"state-event\",\"created_at\":%lld},"
"{\"id\":\"cur_mid\",\"content\":\"{\\\"kind\\\":\\\"curiosity_scan\\\",\\\"q\\\":\\\"mid wondering\\\"}\","
"\"node_type\":\"InternalStateEvent\",\"label\":\"state-event\",\"created_at\":%lld},"
"{\"id\":\"cur_recent\",\"content\":\"{\\\"kind\\\":\\\"curiosity_scan\\\",\\\"q\\\":\\\"recent wondering\\\"}\","
"\"node_type\":\"InternalStateEvent\",\"label\":\"state-event\",\"created_at\":%lld},"
"{\"id\":\"hb_recent\",\"content\":\"{\\\"kind\\\":\\\"heartbeat\\\",\\\"wm\\\":3}\","
"\"node_type\":\"InternalStateEvent\",\"label\":\"state-event\",\"created_at\":%lld}"
"],\"edges\":[]}", ancient, mid, now, now);
fclose(f);
if(!engram_load(S(p))){ fprintf(stderr,"load failed\n"); return 2; }
/* before prune: all resident curiosity_scan after since=0 */
printf("BEFORE %s\n", EL_CSTR(engram_dreams_json((el_val_t)0)));
/* prune 48h — cur_old (ancient) rotates out */
long long pruned=(long long)(int64_t)engram_prune_telemetry((el_val_t)0);
printf("PRUNED %lld\n", pruned);
printf("AFTER %s\n", EL_CSTR(engram_dreams_json((el_val_t)0)));
/* since filter: only events created after 30 min ago -> cur_recent only */
long long since=now-1800000;
printf("SINCE %lld %s\n", since, EL_CSTR(engram_dreams_json((el_val_t)(int64_t)since)));
return 0;
}