Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a23757d545 | |||
| 13c35bacd7 | |||
| b784750f69 | |||
| a45a3ca379 | |||
| 9387c57c3b | |||
| 091cc1fc0e | |||
| 9a491a8e6d | |||
| 6527988eb9 | |||
| 1442ce21a6 | |||
| 96c57c43ba | |||
| 192b277229 | |||
| e2e8f0a1e6 | |||
| f0454650a2 | |||
| c199a13a7f | |||
| 290a637883 | |||
| 40d800195a | |||
| f3034d23f7 | |||
| d337fcb265 | |||
| 64c1789fcc |
+37
-39
@@ -34,12 +34,12 @@ jobs:
|
|||||||
- name: Install build dependencies
|
- name: Install build dependencies
|
||||||
run: |
|
run: |
|
||||||
apt-get update -qq
|
apt-get update -qq
|
||||||
apt-get install -y gcc libcurl4-openssl-dev apt-transport-https ca-certificates
|
apt-get install -y gcc curl libcurl4-openssl-dev apt-transport-https ca-certificates
|
||||||
echo "deb [trusted=yes] https://packages.cloud.google.com/apt cloud-sdk main" \
|
echo "deb [trusted=yes] https://packages.cloud.google.com/apt cloud-sdk main" \
|
||||||
> /etc/apt/sources.list.d/google-cloud-sdk.list
|
> /etc/apt/sources.list.d/google-cloud-sdk.list
|
||||||
apt-get update -qq && apt-get install -y google-cloud-cli
|
apt-get update -qq && apt-get install -y google-cloud-cli
|
||||||
|
|
||||||
- name: Download El runtime from Artifact Registry
|
- name: Authenticate to GCP + stage PINNED El runtime
|
||||||
env:
|
env:
|
||||||
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
|
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
|
||||||
run: |
|
run: |
|
||||||
@@ -47,41 +47,21 @@ jobs:
|
|||||||
gcloud auth activate-service-account --key-file=/tmp/gcp-key.json
|
gcloud auth activate-service-account --key-file=/tmp/gcp-key.json
|
||||||
gcloud config set project neuron-785695
|
gcloud config set project neuron-785695
|
||||||
|
|
||||||
|
# PINNED RUNTIME — do NOT pull "latest" from Artifact Registry.
|
||||||
|
# The ship-soul calls engram_prune_telemetry (awareness.el sync/heartbeat
|
||||||
|
# self-review). The latest published el-runtime-c no longer defines that
|
||||||
|
# symbol, so an unpinned build fails to LINK — which is exactly how a
|
||||||
|
# broken/handlerless soul reached prod before. Compile against the
|
||||||
|
# vendored release runtime v1.0.0-20260501: the exact runtime the merged
|
||||||
|
# ship-soul was verified against (verify-soul-contract GATE PASS +
|
||||||
|
# genesis boot survives + full safety-contact response). It is committed
|
||||||
|
# under vendor/ so the soul build is fully reproducible and never depends
|
||||||
|
# on a moving AR "latest".
|
||||||
rm -rf /opt/el/runtime
|
rm -rf /opt/el/runtime
|
||||||
mkdir -p /opt/el/runtime
|
mkdir -p /opt/el/runtime
|
||||||
|
cp vendor/el-runtime/v1.0.0-20260501/el_runtime.c /opt/el/runtime/el_runtime.c
|
||||||
# Get latest version of each runtime package (elc/elb not needed — we compile
|
cp vendor/el-runtime/v1.0.0-20260501/el_runtime.h /opt/el/runtime/el_runtime.h
|
||||||
# dist/soul.c directly; running elb on Linux OOM-kills the runner, and we
|
echo "El runtime PINNED to v1.0.0-20260501: $(ls /opt/el/runtime/)"
|
||||||
# always use the repo's pre-built soul.c anyway).
|
|
||||||
get_latest() {
|
|
||||||
gcloud artifacts versions list \
|
|
||||||
--repository=foundation-prod \
|
|
||||||
--location=us-central1 \
|
|
||||||
--project=neuron-785695 \
|
|
||||||
--package="$1" \
|
|
||||||
--sort-by="~createTime" \
|
|
||||||
--limit=1 \
|
|
||||||
--format="value(name)" 2>/dev/null | awk -F/ '{print $NF}'
|
|
||||||
}
|
|
||||||
|
|
||||||
RC_VER=$(get_latest el-runtime-c)
|
|
||||||
RH_VER=$(get_latest el-runtime-h)
|
|
||||||
|
|
||||||
echo "Downloading runtime@${RC_VER}"
|
|
||||||
|
|
||||||
gcloud artifacts generic download \
|
|
||||||
--repository=foundation-prod --location=us-central1 --project=neuron-785695 \
|
|
||||||
--package=el-runtime-c --version="${RC_VER}" \
|
|
||||||
--destination=/opt/el/runtime/
|
|
||||||
|
|
||||||
gcloud artifacts generic download \
|
|
||||||
--repository=foundation-prod --location=us-central1 --project=neuron-785695 \
|
|
||||||
--package=el-runtime-h --version="${RH_VER}" \
|
|
||||||
--destination=/opt/el/runtime/
|
|
||||||
|
|
||||||
mv /opt/el/runtime/el_runtime.c* /opt/el/runtime/el_runtime.c 2>/dev/null || true
|
|
||||||
mv /opt/el/runtime/el_runtime.h* /opt/el/runtime/el_runtime.h 2>/dev/null || true
|
|
||||||
echo "El runtime ready: $(ls /opt/el/runtime/)"
|
|
||||||
|
|
||||||
- name: Build neuron soul binary
|
- name: Build neuron soul binary
|
||||||
run: |
|
run: |
|
||||||
@@ -94,19 +74,37 @@ jobs:
|
|||||||
# entirely: elb on Linux would OOM the runner (elc uses 24GB+ virtual memory
|
# entirely: elb on Linux would OOM the runner (elc uses 24GB+ virtual memory
|
||||||
# on a 16GB host) and we always restore from the repo's soul.c anyway.
|
# on a 16GB host) and we always restore from the repo's soul.c anyway.
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
cc -O2 -DHAVE_CURL \
|
# -rdynamic: the el runtime resolves the HTTP request handler (and the
|
||||||
|
# tool handlers) by NAME via dlsym(RTLD_DEFAULT, "handle_request").
|
||||||
|
# macOS exports these symbols freely, but glibc/Linux only makes symbols
|
||||||
|
# visible to dlsym if they are in the dynamic symbol table — so without
|
||||||
|
# -rdynamic the stripped Linux binary boots but returns "el-runtime: no
|
||||||
|
# http handler registered" for EVERY route (i.e. a soul that serves
|
||||||
|
# nothing). Same reason the Windows build links -Wl,--export-all-symbols.
|
||||||
|
cc -O2 -DHAVE_CURL -rdynamic \
|
||||||
-I$RUNTIME \
|
-I$RUNTIME \
|
||||||
dist/soul.c \
|
dist/soul.c \
|
||||||
$RUNTIME/el_runtime.c \
|
$RUNTIME/el_runtime.c \
|
||||||
-lssl -lcrypto -lcurl -lpthread -lm \
|
-lssl -lcrypto -lcurl -lpthread -lm \
|
||||||
-o dist/neuron
|
-o dist/neuron
|
||||||
|
|
||||||
# Strip debug symbols and non-essential symbol table entries.
|
# -s strips .symtab + debug for size. .dynsym (which -rdynamic populated
|
||||||
# -s removes the symbol table + relocation info (max size reduction).
|
# with the dlsym-resolved handlers) is preserved, so the handler still
|
||||||
# Keeps the binary functional; debuggability is preserved via source + CI logs.
|
# resolves after stripping.
|
||||||
strip -s dist/neuron
|
strip -s dist/neuron
|
||||||
ls -lh dist/neuron
|
ls -lh dist/neuron
|
||||||
|
|
||||||
|
- name: Soul contract gate (HARD BLOCK — no destructive/stale soul publishes)
|
||||||
|
run: |
|
||||||
|
# Boots dist/neuron on a throwaway port with a throwaway HOME/engram/cgi
|
||||||
|
# (never touches ~/.neuron or any live service) and fails the build if any
|
||||||
|
# app-contract route is unanswered (PRESENCE) or any engram write route
|
||||||
|
# hard-deletes instead of tombstoning/superseding (IMMUTABILITY). Non-zero
|
||||||
|
# here blocks Publish -> Artifact Registry -> GKE deploy, so a stale or
|
||||||
|
# memory-destroying soul can never reach prod.
|
||||||
|
chmod +x dist/neuron scripts/verify-soul-contract.sh
|
||||||
|
bash scripts/verify-soul-contract.sh dist/neuron 7796
|
||||||
|
|
||||||
- name: Smoke test
|
- name: Smoke test
|
||||||
run: |
|
run: |
|
||||||
file dist/neuron
|
file dist/neuron
|
||||||
|
|||||||
+4
-2
@@ -507,8 +507,10 @@ fn respond(action_json: String) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if str_eq(kind, "forget") {
|
if str_eq(kind, "forget") {
|
||||||
engram_forget(payload)
|
// The soul must NOT be able to autonomously hard-delete a memory.
|
||||||
return "{\"outcome\":\"forgotten\",\"id\":\"" + payload + "\"}"
|
// Tombstone instead (keep node + edges, recoverable).
|
||||||
|
let _marker: String = mem_tombstone(payload)
|
||||||
|
return "{\"outcome\":\"tombstoned\",\"id\":\"" + payload + "\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
return "{\"outcome\":\"noop\"}"
|
return "{\"outcome\":\"noop\"}"
|
||||||
|
|||||||
+3
-2
@@ -10,6 +10,7 @@ el_val_t mem_remember(el_val_t content, el_val_t tags);
|
|||||||
el_val_t mem_recall(el_val_t query, el_val_t depth);
|
el_val_t mem_recall(el_val_t query, el_val_t depth);
|
||||||
el_val_t mem_search(el_val_t query, el_val_t limit);
|
el_val_t mem_search(el_val_t query, el_val_t limit);
|
||||||
el_val_t mem_strengthen(el_val_t node_id);
|
el_val_t mem_strengthen(el_val_t node_id);
|
||||||
|
el_val_t mem_tombstone(el_val_t node_id);
|
||||||
el_val_t mem_forget(el_val_t node_id);
|
el_val_t mem_forget(el_val_t node_id);
|
||||||
el_val_t mem_consolidate(void);
|
el_val_t mem_consolidate(void);
|
||||||
el_val_t mem_save(el_val_t path);
|
el_val_t mem_save(el_val_t path);
|
||||||
@@ -375,8 +376,8 @@ el_val_t respond(el_val_t action_json) {
|
|||||||
return el_str_concat(el_str_concat(EL_STR("{\"outcome\":\"strengthened\",\"id\":\""), payload), EL_STR("\"}"));
|
return el_str_concat(el_str_concat(EL_STR("{\"outcome\":\"strengthened\",\"id\":\""), payload), EL_STR("\"}"));
|
||||||
}
|
}
|
||||||
if (str_eq(kind, EL_STR("forget"))) {
|
if (str_eq(kind, EL_STR("forget"))) {
|
||||||
engram_forget(payload);
|
el_val_t _marker = mem_tombstone(payload);
|
||||||
return el_str_concat(el_str_concat(EL_STR("{\"outcome\":\"forgotten\",\"id\":\""), payload), EL_STR("\"}"));
|
return el_str_concat(el_str_concat(EL_STR("{\"outcome\":\"tombstoned\",\"id\":\""), payload), EL_STR("\"}"));
|
||||||
}
|
}
|
||||||
return EL_STR("{\"outcome\":\"noop\"}");
|
return EL_STR("{\"outcome\":\"noop\"}");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+14
-3
@@ -10,6 +10,7 @@ el_val_t mem_remember(el_val_t content, el_val_t tags);
|
|||||||
el_val_t mem_recall(el_val_t query, el_val_t depth);
|
el_val_t mem_recall(el_val_t query, el_val_t depth);
|
||||||
el_val_t mem_search(el_val_t query, el_val_t limit);
|
el_val_t mem_search(el_val_t query, el_val_t limit);
|
||||||
el_val_t mem_strengthen(el_val_t node_id);
|
el_val_t mem_strengthen(el_val_t node_id);
|
||||||
|
el_val_t mem_tombstone(el_val_t node_id);
|
||||||
el_val_t mem_forget(el_val_t node_id);
|
el_val_t mem_forget(el_val_t node_id);
|
||||||
el_val_t mem_consolidate(void);
|
el_val_t mem_consolidate(void);
|
||||||
el_val_t mem_save(el_val_t path);
|
el_val_t mem_save(el_val_t path);
|
||||||
@@ -69,8 +70,18 @@ el_val_t mem_strengthen(el_val_t node_id) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
el_val_t mem_tombstone(el_val_t node_id) {
|
||||||
|
el_val_t tags = EL_STR("[\"Tombstone\",\"status:deleted\"]");
|
||||||
|
el_val_t marker = engram_node_full(node_id, EL_STR("Tombstone"), el_str_concat(EL_STR("tombstone:"), node_id), el_from_float(0.01), el_from_float(0.01), el_from_float(1.0), EL_STR("Episodic"), tags);
|
||||||
|
if (!str_eq(marker, EL_STR(""))) {
|
||||||
|
engram_connect(marker, node_id, el_from_float(1.0), EL_STR("tombstones"));
|
||||||
|
}
|
||||||
|
return marker;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
el_val_t mem_forget(el_val_t node_id) {
|
el_val_t mem_forget(el_val_t node_id) {
|
||||||
engram_forget(node_id);
|
el_val_t _marker = mem_tombstone(node_id);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,8 +120,8 @@ el_val_t mem_consolidate(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
el_val_t mem_save(el_val_t path) {
|
el_val_t mem_save(el_val_t path) {
|
||||||
el_val_t save_result = engram_save(path);
|
el_val_t saved = engram_save(path);
|
||||||
if (str_eq(save_result, EL_STR(""))) {
|
if (saved == 0) {
|
||||||
println(el_str_concat(el_str_concat(EL_STR("[memory] mem_save: engram_save failed for "), path), EL_STR(" \xe2\x80\x94 snapshot may be incomplete")));
|
println(el_str_concat(el_str_concat(EL_STR("[memory] mem_save: engram_save failed for "), path), EL_STR(" \xe2\x80\x94 snapshot may be incomplete")));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+129
-56
@@ -10,6 +10,7 @@ el_val_t mem_remember(el_val_t content, el_val_t tags);
|
|||||||
el_val_t mem_recall(el_val_t query, el_val_t depth);
|
el_val_t mem_recall(el_val_t query, el_val_t depth);
|
||||||
el_val_t mem_search(el_val_t query, el_val_t limit);
|
el_val_t mem_search(el_val_t query, el_val_t limit);
|
||||||
el_val_t mem_strengthen(el_val_t node_id);
|
el_val_t mem_strengthen(el_val_t node_id);
|
||||||
|
el_val_t mem_tombstone(el_val_t node_id);
|
||||||
el_val_t mem_forget(el_val_t node_id);
|
el_val_t mem_forget(el_val_t node_id);
|
||||||
el_val_t mem_consolidate(void);
|
el_val_t mem_consolidate(void);
|
||||||
el_val_t mem_save(el_val_t path);
|
el_val_t mem_save(el_val_t path);
|
||||||
@@ -28,6 +29,9 @@ el_val_t api_nonempty(el_val_t s);
|
|||||||
el_val_t api_or_empty(el_val_t s);
|
el_val_t api_or_empty(el_val_t s);
|
||||||
el_val_t api_persisted(el_val_t id);
|
el_val_t api_persisted(el_val_t id);
|
||||||
el_val_t api_not_persisted(el_val_t id);
|
el_val_t api_not_persisted(el_val_t id);
|
||||||
|
el_val_t tombstone_node(el_val_t id);
|
||||||
|
el_val_t tombstoned_id_set(void);
|
||||||
|
el_val_t memory_hide_tombstoned(el_val_t raw, el_val_t path);
|
||||||
el_val_t handle_api_begin_session(el_val_t body);
|
el_val_t handle_api_begin_session(el_val_t body);
|
||||||
el_val_t handle_api_compile_ctx(el_val_t body);
|
el_val_t handle_api_compile_ctx(el_val_t body);
|
||||||
el_val_t handle_api_remember(el_val_t body);
|
el_val_t handle_api_remember(el_val_t body);
|
||||||
@@ -189,6 +193,61 @@ el_val_t api_not_persisted(el_val_t id) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
el_val_t tombstone_node(el_val_t id) {
|
||||||
|
return mem_tombstone(id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
el_val_t tombstoned_id_set(void) {
|
||||||
|
el_val_t markers = engram_scan_nodes_by_type_json(EL_STR("Tombstone"), 5000, 0);
|
||||||
|
if (str_eq(markers, EL_STR("")) || str_eq(markers, EL_STR("[]"))) {
|
||||||
|
return EL_STR("");
|
||||||
|
}
|
||||||
|
el_val_t n = json_array_len(markers);
|
||||||
|
el_val_t acc = EL_STR("|");
|
||||||
|
el_val_t i = 0;
|
||||||
|
while (i < n) {
|
||||||
|
el_val_t m = json_array_get(markers, i);
|
||||||
|
el_val_t tid = json_get(m, EL_STR("content"));
|
||||||
|
acc = ({ el_val_t _if_result_1 = 0; if (str_eq(tid, EL_STR(""))) { _if_result_1 = (acc); } else { _if_result_1 = (el_str_concat(el_str_concat(acc, tid), EL_STR("|"))); } _if_result_1; });
|
||||||
|
i = (i + 1);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
el_val_t memory_hide_tombstoned(el_val_t raw, el_val_t path) {
|
||||||
|
if (str_contains(path, EL_STR("include_deleted"))) {
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
if (str_eq(raw, EL_STR("")) || str_eq(raw, EL_STR("[]"))) {
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
el_val_t dead = tombstoned_id_set();
|
||||||
|
if (str_eq(dead, EL_STR(""))) {
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
el_val_t n = json_array_len(raw);
|
||||||
|
if (n > 1000) {
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
el_val_t out = EL_STR("[");
|
||||||
|
el_val_t first = 1;
|
||||||
|
el_val_t i = 0;
|
||||||
|
while (i < n) {
|
||||||
|
el_val_t node = json_array_get(raw, i);
|
||||||
|
el_val_t nid = json_get(node, EL_STR("id"));
|
||||||
|
el_val_t ntype = json_get(node, EL_STR("node_type"));
|
||||||
|
el_val_t is_dead = (!str_eq(nid, EL_STR("")) && str_contains(dead, el_str_concat(el_str_concat(EL_STR("|"), nid), EL_STR("|"))));
|
||||||
|
el_val_t keep = (!str_eq(ntype, EL_STR("Tombstone")) && !is_dead);
|
||||||
|
out = ({ el_val_t _if_result_2 = 0; if (keep) { _if_result_2 = (({ el_val_t _if_result_3 = 0; if (first) { _if_result_3 = (el_str_concat(out, node)); } else { _if_result_3 = (el_str_concat(el_str_concat(out, EL_STR(",")), node)); } _if_result_3; })); } else { _if_result_2 = (out); } _if_result_2; });
|
||||||
|
first = ({ el_val_t _if_result_4 = 0; if (keep) { _if_result_4 = (0); } else { _if_result_4 = (first); } _if_result_4; });
|
||||||
|
i = (i + 1);
|
||||||
|
}
|
||||||
|
return el_str_concat(out, EL_STR("]"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
el_val_t handle_api_begin_session(el_val_t body) {
|
el_val_t handle_api_begin_session(el_val_t body) {
|
||||||
el_val_t stats = engram_stats_json();
|
el_val_t stats = engram_stats_json();
|
||||||
el_val_t activated = engram_activate_json(EL_STR("session start recent memory important"), 2);
|
el_val_t activated = engram_activate_json(EL_STR("session start recent memory important"), 2);
|
||||||
@@ -215,10 +274,10 @@ el_val_t handle_api_remember(el_val_t body) {
|
|||||||
el_val_t importance = json_get(body, EL_STR("importance"));
|
el_val_t importance = json_get(body, EL_STR("importance"));
|
||||||
el_val_t tags_raw = json_get(body, EL_STR("tags"));
|
el_val_t tags_raw = json_get(body, EL_STR("tags"));
|
||||||
el_val_t project = json_get(body, EL_STR("project"));
|
el_val_t project = json_get(body, EL_STR("project"));
|
||||||
el_val_t sal_str = ({ el_val_t _if_result_1 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_1 = (EL_STR("0.95")); } else { _if_result_1 = (({ el_val_t _if_result_2 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_2 = (EL_STR("0.75")); } else { _if_result_2 = (({ el_val_t _if_result_3 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_3 = (EL_STR("0.25")); } else { _if_result_3 = (EL_STR("0.50")); } _if_result_3; })); } _if_result_2; })); } _if_result_1; });
|
el_val_t sal_str = ({ el_val_t _if_result_5 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_5 = (EL_STR("0.95")); } else { _if_result_5 = (({ el_val_t _if_result_6 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_6 = (EL_STR("0.75")); } else { _if_result_6 = (({ el_val_t _if_result_7 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_7 = (EL_STR("0.25")); } else { _if_result_7 = (EL_STR("0.50")); } _if_result_7; })); } _if_result_6; })); } _if_result_5; });
|
||||||
el_val_t sal = ({ el_val_t _if_result_4 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_4 = (el_from_float(0.95)); } else { _if_result_4 = (({ el_val_t _if_result_5 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_5 = (el_from_float(0.75)); } else { _if_result_5 = (({ el_val_t _if_result_6 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_6 = (el_from_float(0.25)); } else { _if_result_6 = (el_from_float(0.5)); } _if_result_6; })); } _if_result_5; })); } _if_result_4; });
|
el_val_t sal = ({ el_val_t _if_result_8 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_8 = (el_from_float(0.95)); } else { _if_result_8 = (({ el_val_t _if_result_9 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_9 = (el_from_float(0.75)); } else { _if_result_9 = (({ el_val_t _if_result_10 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_10 = (el_from_float(0.25)); } else { _if_result_10 = (el_from_float(0.5)); } _if_result_10; })); } _if_result_9; })); } _if_result_8; });
|
||||||
el_val_t base_tags = ({ el_val_t _if_result_7 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_7 = (EL_STR("[\"Memory\"]")); } else { _if_result_7 = (tags_raw); } _if_result_7; });
|
el_val_t base_tags = ({ el_val_t _if_result_11 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_11 = (EL_STR("[\"Memory\"]")); } else { _if_result_11 = (tags_raw); } _if_result_11; });
|
||||||
el_val_t final_tags = ({ el_val_t _if_result_8 = 0; if (str_eq(project, EL_STR(""))) { _if_result_8 = (base_tags); } else { el_val_t inner = str_slice(base_tags, 1, (str_len(base_tags) - 1)); _if_result_8 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",\"project:")), project), EL_STR("\"]"))); } _if_result_8; });
|
el_val_t final_tags = ({ el_val_t _if_result_12 = 0; if (str_eq(project, EL_STR(""))) { _if_result_12 = (base_tags); } else { el_val_t inner = str_slice(base_tags, 1, (str_len(base_tags) - 1)); _if_result_12 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",\"project:")), project), EL_STR("\"]"))); } _if_result_12; });
|
||||||
el_val_t id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:remembered"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), final_tags);
|
el_val_t id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:remembered"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), final_tags);
|
||||||
if (!api_persisted(id)) {
|
if (!api_persisted(id)) {
|
||||||
return api_not_persisted(id);
|
return api_not_persisted(id);
|
||||||
@@ -233,15 +292,15 @@ el_val_t handle_api_node_create(el_val_t body) {
|
|||||||
return api_err(EL_STR("content is required"));
|
return api_err(EL_STR("content is required"));
|
||||||
}
|
}
|
||||||
el_val_t nt_raw = json_get(body, EL_STR("node_type"));
|
el_val_t nt_raw = json_get(body, EL_STR("node_type"));
|
||||||
el_val_t node_type = ({ el_val_t _if_result_9 = 0; if (str_eq(nt_raw, EL_STR(""))) { _if_result_9 = (EL_STR("Memory")); } else { _if_result_9 = (nt_raw); } _if_result_9; });
|
el_val_t node_type = ({ el_val_t _if_result_13 = 0; if (str_eq(nt_raw, EL_STR(""))) { _if_result_13 = (EL_STR("Memory")); } else { _if_result_13 = (nt_raw); } _if_result_13; });
|
||||||
el_val_t label_raw = json_get(body, EL_STR("label"));
|
el_val_t label_raw = json_get(body, EL_STR("label"));
|
||||||
el_val_t label = ({ el_val_t _if_result_10 = 0; if (str_eq(label_raw, EL_STR(""))) { _if_result_10 = (EL_STR("node:created")); } else { _if_result_10 = (label_raw); } _if_result_10; });
|
el_val_t label = ({ el_val_t _if_result_14 = 0; if (str_eq(label_raw, EL_STR(""))) { _if_result_14 = (EL_STR("node:created")); } else { _if_result_14 = (label_raw); } _if_result_14; });
|
||||||
el_val_t tier_raw = json_get(body, EL_STR("tier"));
|
el_val_t tier_raw = json_get(body, EL_STR("tier"));
|
||||||
el_val_t tier = ({ el_val_t _if_result_11 = 0; if (str_eq(tier_raw, EL_STR(""))) { _if_result_11 = (EL_STR("Episodic")); } else { _if_result_11 = (tier_raw); } _if_result_11; });
|
el_val_t tier = ({ el_val_t _if_result_15 = 0; if (str_eq(tier_raw, EL_STR(""))) { _if_result_15 = (EL_STR("Episodic")); } else { _if_result_15 = (tier_raw); } _if_result_15; });
|
||||||
el_val_t tags_raw = json_get(body, EL_STR("tags"));
|
el_val_t tags_raw = json_get(body, EL_STR("tags"));
|
||||||
el_val_t tags = ({ el_val_t _if_result_12 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_12 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_12 = (tags_raw); } _if_result_12; });
|
el_val_t tags = ({ el_val_t _if_result_16 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_16 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_16 = (tags_raw); } _if_result_16; });
|
||||||
el_val_t importance = json_get(body, EL_STR("importance"));
|
el_val_t importance = json_get(body, EL_STR("importance"));
|
||||||
el_val_t sal = ({ el_val_t _if_result_13 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_13 = (el_from_float(0.95)); } else { _if_result_13 = (({ el_val_t _if_result_14 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_14 = (el_from_float(0.75)); } else { _if_result_14 = (({ el_val_t _if_result_15 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_15 = (el_from_float(0.25)); } else { _if_result_15 = (el_from_float(0.5)); } _if_result_15; })); } _if_result_14; })); } _if_result_13; });
|
el_val_t sal = ({ el_val_t _if_result_17 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_17 = (el_from_float(0.95)); } else { _if_result_17 = (({ el_val_t _if_result_18 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_18 = (el_from_float(0.75)); } else { _if_result_18 = (({ el_val_t _if_result_19 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_19 = (el_from_float(0.25)); } else { _if_result_19 = (el_from_float(0.5)); } _if_result_19; })); } _if_result_18; })); } _if_result_17; });
|
||||||
el_val_t id = engram_node_full(content, node_type, label, el_from_float(sal), el_from_float(sal), el_from_float(0.9), tier, tags);
|
el_val_t id = engram_node_full(content, node_type, label, el_from_float(sal), el_from_float(sal), el_from_float(0.9), tier, tags);
|
||||||
if (!api_persisted(id)) {
|
if (!api_persisted(id)) {
|
||||||
return api_not_persisted(id);
|
return api_not_persisted(id);
|
||||||
@@ -255,8 +314,18 @@ el_val_t handle_api_node_delete(el_val_t body) {
|
|||||||
if (str_eq(id, EL_STR(""))) {
|
if (str_eq(id, EL_STR(""))) {
|
||||||
return api_err(EL_STR("id is required"));
|
return api_err(EL_STR("id is required"));
|
||||||
}
|
}
|
||||||
engram_forget(id);
|
if (is_protected_node(id)) {
|
||||||
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), id), EL_STR("\"}"));
|
return api_err_protected(id);
|
||||||
|
}
|
||||||
|
el_val_t existing = engram_get_node_json(id);
|
||||||
|
if (str_eq(existing, EL_STR("{}"))) {
|
||||||
|
return api_err(el_str_concat(EL_STR("node not found: "), id));
|
||||||
|
}
|
||||||
|
el_val_t marker = tombstone_node(id);
|
||||||
|
if (str_eq(marker, EL_STR(""))) {
|
||||||
|
return api_err(el_str_concat(EL_STR("tombstone failed: "), id));
|
||||||
|
}
|
||||||
|
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), id), EL_STR("\",\"tombstoned\":true}"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,37 +339,37 @@ el_val_t handle_api_node_update(el_val_t body) {
|
|||||||
}
|
}
|
||||||
el_val_t old = engram_get_node_json(id);
|
el_val_t old = engram_get_node_json(id);
|
||||||
el_val_t body_content = json_get(body, EL_STR("content"));
|
el_val_t body_content = json_get(body, EL_STR("content"));
|
||||||
el_val_t content = ({ el_val_t _if_result_16 = 0; if (str_eq(body_content, EL_STR(""))) { _if_result_16 = (json_get(old, EL_STR("content"))); } else { _if_result_16 = (body_content); } _if_result_16; });
|
el_val_t content = ({ el_val_t _if_result_20 = 0; if (str_eq(body_content, EL_STR(""))) { _if_result_20 = (json_get(old, EL_STR("content"))); } else { _if_result_20 = (body_content); } _if_result_20; });
|
||||||
el_val_t body_nt = json_get(body, EL_STR("node_type"));
|
el_val_t body_nt = json_get(body, EL_STR("node_type"));
|
||||||
el_val_t old_nt = json_get(old, EL_STR("node_type"));
|
el_val_t old_nt = json_get(old, EL_STR("node_type"));
|
||||||
el_val_t node_type = ({ el_val_t _if_result_17 = 0; if (!str_eq(body_nt, EL_STR(""))) { _if_result_17 = (body_nt); } else { _if_result_17 = (({ el_val_t _if_result_18 = 0; if (!str_eq(old_nt, EL_STR(""))) { _if_result_18 = (old_nt); } else { _if_result_18 = (EL_STR("Memory")); } _if_result_18; })); } _if_result_17; });
|
el_val_t node_type = ({ el_val_t _if_result_21 = 0; if (!str_eq(body_nt, EL_STR(""))) { _if_result_21 = (body_nt); } else { _if_result_21 = (({ el_val_t _if_result_22 = 0; if (!str_eq(old_nt, EL_STR(""))) { _if_result_22 = (old_nt); } else { _if_result_22 = (EL_STR("Memory")); } _if_result_22; })); } _if_result_21; });
|
||||||
el_val_t body_label = json_get(body, EL_STR("label"));
|
el_val_t body_label = json_get(body, EL_STR("label"));
|
||||||
el_val_t old_label = json_get(old, EL_STR("label"));
|
el_val_t old_label = json_get(old, EL_STR("label"));
|
||||||
el_val_t label = ({ el_val_t _if_result_19 = 0; if (!str_eq(body_label, EL_STR(""))) { _if_result_19 = (body_label); } else { _if_result_19 = (({ el_val_t _if_result_20 = 0; if (!str_eq(old_label, EL_STR(""))) { _if_result_20 = (old_label); } else { _if_result_20 = (EL_STR("node:updated")); } _if_result_20; })); } _if_result_19; });
|
el_val_t label = ({ el_val_t _if_result_23 = 0; if (!str_eq(body_label, EL_STR(""))) { _if_result_23 = (body_label); } else { _if_result_23 = (({ el_val_t _if_result_24 = 0; if (!str_eq(old_label, EL_STR(""))) { _if_result_24 = (old_label); } else { _if_result_24 = (EL_STR("node:updated")); } _if_result_24; })); } _if_result_23; });
|
||||||
el_val_t body_tier = json_get(body, EL_STR("tier"));
|
el_val_t body_tier = json_get(body, EL_STR("tier"));
|
||||||
el_val_t old_tier = json_get(old, EL_STR("tier"));
|
el_val_t old_tier = json_get(old, EL_STR("tier"));
|
||||||
el_val_t tier = ({ el_val_t _if_result_21 = 0; if (!str_eq(body_tier, EL_STR(""))) { _if_result_21 = (body_tier); } else { _if_result_21 = (({ el_val_t _if_result_22 = 0; if (!str_eq(old_tier, EL_STR(""))) { _if_result_22 = (old_tier); } else { _if_result_22 = (EL_STR("Episodic")); } _if_result_22; })); } _if_result_21; });
|
el_val_t tier = ({ el_val_t _if_result_25 = 0; if (!str_eq(body_tier, EL_STR(""))) { _if_result_25 = (body_tier); } else { _if_result_25 = (({ el_val_t _if_result_26 = 0; if (!str_eq(old_tier, EL_STR(""))) { _if_result_26 = (old_tier); } else { _if_result_26 = (EL_STR("Episodic")); } _if_result_26; })); } _if_result_25; });
|
||||||
el_val_t body_tags = json_get(body, EL_STR("tags"));
|
el_val_t body_tags = json_get(body, EL_STR("tags"));
|
||||||
el_val_t tags = ({ el_val_t _if_result_23 = 0; if (str_eq(body_tags, EL_STR(""))) { _if_result_23 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_23 = (body_tags); } _if_result_23; });
|
el_val_t tags = ({ el_val_t _if_result_27 = 0; if (str_eq(body_tags, EL_STR(""))) { _if_result_27 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_27 = (body_tags); } _if_result_27; });
|
||||||
el_val_t new_id = engram_node_full(content, node_type, label, el_from_float(0.5), el_from_float(0.5), el_from_float(0.8), tier, tags);
|
el_val_t new_id = engram_node_full(content, node_type, label, el_from_float(0.5), el_from_float(0.5), el_from_float(0.8), tier, tags);
|
||||||
if (!api_persisted(new_id)) {
|
if (!api_persisted(new_id)) {
|
||||||
return api_not_persisted(new_id);
|
return api_not_persisted(new_id);
|
||||||
}
|
}
|
||||||
engram_forget(id);
|
engram_connect(new_id, id, el_from_float(0.9), EL_STR("supersedes"));
|
||||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), new_id), EL_STR("\",\"replaced\":\"")), id), EL_STR("\",\"ok\":true}"));
|
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), new_id), EL_STR("\",\"supersedes\":\"")), id), EL_STR("\",\"ok\":true}"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
el_val_t handle_api_recall(el_val_t method, el_val_t path, el_val_t body) {
|
el_val_t handle_api_recall(el_val_t method, el_val_t path, el_val_t body) {
|
||||||
el_val_t url_q = ({ el_val_t _if_result_24 = 0; if (str_eq(api_query_param(path, EL_STR("query")), EL_STR(""))) { _if_result_24 = (api_query_param(path, EL_STR("q"))); } else { _if_result_24 = (api_query_param(path, EL_STR("query"))); } _if_result_24; });
|
el_val_t url_q = ({ el_val_t _if_result_28 = 0; if (str_eq(api_query_param(path, EL_STR("query")), EL_STR(""))) { _if_result_28 = (api_query_param(path, EL_STR("q"))); } else { _if_result_28 = (api_query_param(path, EL_STR("query"))); } _if_result_28; });
|
||||||
el_val_t body_query = json_get(body, EL_STR("query"));
|
el_val_t body_query = json_get(body, EL_STR("query"));
|
||||||
el_val_t body_q = json_get(body, EL_STR("q"));
|
el_val_t body_q = json_get(body, EL_STR("q"));
|
||||||
el_val_t q = ({ el_val_t _if_result_25 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_25 = (url_q); } else { _if_result_25 = (({ el_val_t _if_result_26 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_26 = (body_query); } else { _if_result_26 = (body_q); } _if_result_26; })); } _if_result_25; });
|
el_val_t q = ({ el_val_t _if_result_29 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_29 = (url_q); } else { _if_result_29 = (({ el_val_t _if_result_30 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_30 = (body_query); } else { _if_result_30 = (body_q); } _if_result_30; })); } _if_result_29; });
|
||||||
el_val_t chain = json_get(body, EL_STR("chain_name"));
|
el_val_t chain = json_get(body, EL_STR("chain_name"));
|
||||||
el_val_t limit = api_query_int(path, EL_STR("limit"), 0);
|
el_val_t limit = api_query_int(path, EL_STR("limit"), 0);
|
||||||
limit = ({ el_val_t _if_result_27 = 0; if ((limit == 0)) { _if_result_27 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_27 = (limit); } _if_result_27; });
|
limit = ({ el_val_t _if_result_31 = 0; if ((limit == 0)) { _if_result_31 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_31 = (limit); } _if_result_31; });
|
||||||
limit = ({ el_val_t _if_result_28 = 0; if ((limit == 0)) { _if_result_28 = (10); } else { _if_result_28 = (limit); } _if_result_28; });
|
limit = ({ el_val_t _if_result_32 = 0; if ((limit == 0)) { _if_result_32 = (10); } else { _if_result_32 = (limit); } _if_result_32; });
|
||||||
el_val_t eff_q = ({ el_val_t _if_result_29 = 0; if (str_eq(q, EL_STR(""))) { _if_result_29 = (chain); } else { _if_result_29 = (q); } _if_result_29; });
|
el_val_t eff_q = ({ el_val_t _if_result_33 = 0; if (str_eq(q, EL_STR(""))) { _if_result_33 = (chain); } else { _if_result_33 = (q); } _if_result_33; });
|
||||||
if (str_eq(eff_q, EL_STR(""))) {
|
if (str_eq(eff_q, EL_STR(""))) {
|
||||||
return api_or_empty(engram_scan_nodes_json(limit, 0));
|
return api_or_empty(engram_scan_nodes_json(limit, 0));
|
||||||
}
|
}
|
||||||
@@ -313,10 +382,10 @@ el_val_t handle_api_search_knowledge(el_val_t method, el_val_t path, el_val_t bo
|
|||||||
el_val_t url_q = api_query_param(path, EL_STR("q"));
|
el_val_t url_q = api_query_param(path, EL_STR("q"));
|
||||||
el_val_t body_query = json_get(body, EL_STR("query"));
|
el_val_t body_query = json_get(body, EL_STR("query"));
|
||||||
el_val_t body_q = json_get(body, EL_STR("q"));
|
el_val_t body_q = json_get(body, EL_STR("q"));
|
||||||
el_val_t q = ({ el_val_t _if_result_30 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_30 = (url_q); } else { _if_result_30 = (({ el_val_t _if_result_31 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_31 = (body_query); } else { _if_result_31 = (body_q); } _if_result_31; })); } _if_result_30; });
|
el_val_t q = ({ el_val_t _if_result_34 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_34 = (url_q); } else { _if_result_34 = (({ el_val_t _if_result_35 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_35 = (body_query); } else { _if_result_35 = (body_q); } _if_result_35; })); } _if_result_34; });
|
||||||
el_val_t limit = api_query_int(path, EL_STR("limit"), 0);
|
el_val_t limit = api_query_int(path, EL_STR("limit"), 0);
|
||||||
limit = ({ el_val_t _if_result_32 = 0; if ((limit == 0)) { _if_result_32 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_32 = (limit); } _if_result_32; });
|
limit = ({ el_val_t _if_result_36 = 0; if ((limit == 0)) { _if_result_36 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_36 = (limit); } _if_result_36; });
|
||||||
limit = ({ el_val_t _if_result_33 = 0; if ((limit == 0)) { _if_result_33 = (10); } else { _if_result_33 = (limit); } _if_result_33; });
|
limit = ({ el_val_t _if_result_37 = 0; if ((limit == 0)) { _if_result_37 = (10); } else { _if_result_37 = (limit); } _if_result_37; });
|
||||||
if (str_eq(q, EL_STR(""))) {
|
if (str_eq(q, EL_STR(""))) {
|
||||||
return api_err(EL_STR("query is required"));
|
return api_err(EL_STR("query is required"));
|
||||||
}
|
}
|
||||||
@@ -344,7 +413,7 @@ el_val_t handle_api_capture_knowledge(el_val_t body) {
|
|||||||
if (str_eq(content, EL_STR(""))) {
|
if (str_eq(content, EL_STR(""))) {
|
||||||
return api_err(EL_STR("content is required"));
|
return api_err(EL_STR("content is required"));
|
||||||
}
|
}
|
||||||
el_val_t full = ({ el_val_t _if_result_34 = 0; if (str_eq(title, EL_STR(""))) { _if_result_34 = (content); } else { _if_result_34 = (el_str_concat(el_str_concat(title, EL_STR(": ")), content)); } _if_result_34; });
|
el_val_t full = ({ el_val_t _if_result_38 = 0; if (str_eq(title, EL_STR(""))) { _if_result_38 = (content); } else { _if_result_38 = (el_str_concat(el_str_concat(title, EL_STR(": ")), content)); } _if_result_38; });
|
||||||
el_val_t tags = EL_STR("[\"Knowledge\",\"captured\"]");
|
el_val_t tags = EL_STR("[\"Knowledge\",\"captured\"]");
|
||||||
el_val_t id = engram_node_full(full, EL_STR("Knowledge"), EL_STR("knowledge:captured"), el_from_float(0.85), el_from_float(0.8), el_from_float(0.9), EL_STR("Episodic"), tags);
|
el_val_t id = engram_node_full(full, EL_STR("Knowledge"), EL_STR("knowledge:captured"), el_from_float(0.85), el_from_float(0.8), el_from_float(0.9), EL_STR("Episodic"), tags);
|
||||||
if (!api_persisted(id)) {
|
if (!api_persisted(id)) {
|
||||||
@@ -385,7 +454,7 @@ el_val_t handle_api_promote_knowledge(el_val_t body) {
|
|||||||
return api_err(EL_STR("id (prior node) is required"));
|
return api_err(EL_STR("id (prior node) is required"));
|
||||||
}
|
}
|
||||||
el_val_t tags_raw = json_get(body, EL_STR("tags"));
|
el_val_t tags_raw = json_get(body, EL_STR("tags"));
|
||||||
el_val_t tags = ({ el_val_t _if_result_35 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_35 = (EL_STR("[\"Knowledge\",\"tier:canonical\",\"disposition:stable\"]")); } else { _if_result_35 = (tags_raw); } _if_result_35; });
|
el_val_t tags = ({ el_val_t _if_result_39 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_39 = (EL_STR("[\"Knowledge\",\"tier:canonical\",\"disposition:stable\"]")); } else { _if_result_39 = (tags_raw); } _if_result_39; });
|
||||||
el_val_t new_id = engram_node_full(content, EL_STR("Knowledge"), EL_STR("knowledge:canonical"), el_from_float(0.9), el_from_float(0.9), el_from_float(1.0), EL_STR("Canonical"), tags);
|
el_val_t new_id = engram_node_full(content, EL_STR("Knowledge"), EL_STR("knowledge:canonical"), el_from_float(0.9), el_from_float(0.9), el_from_float(1.0), EL_STR("Canonical"), tags);
|
||||||
if (!api_persisted(new_id)) {
|
if (!api_persisted(new_id)) {
|
||||||
return api_not_persisted(new_id);
|
return api_not_persisted(new_id);
|
||||||
@@ -396,7 +465,7 @@ el_val_t handle_api_promote_knowledge(el_val_t body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
el_val_t handle_api_browse_processes(el_val_t method, el_val_t path, el_val_t body) {
|
el_val_t handle_api_browse_processes(el_val_t method, el_val_t path, el_val_t body) {
|
||||||
el_val_t name = ({ el_val_t _if_result_36 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_36 = (api_query_param(path, EL_STR("name"))); } else { _if_result_36 = (json_get(body, EL_STR("name"))); } _if_result_36; });
|
el_val_t name = ({ el_val_t _if_result_40 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_40 = (api_query_param(path, EL_STR("name"))); } else { _if_result_40 = (json_get(body, EL_STR("name"))); } _if_result_40; });
|
||||||
el_val_t limit = api_query_int(path, EL_STR("limit"), 50);
|
el_val_t limit = api_query_int(path, EL_STR("limit"), 50);
|
||||||
if (str_eq(name, EL_STR(""))) {
|
if (str_eq(name, EL_STR(""))) {
|
||||||
return api_or_empty(engram_scan_nodes_by_type_json(EL_STR("Process"), limit, 0));
|
return api_or_empty(engram_scan_nodes_by_type_json(EL_STR("Process"), limit, 0));
|
||||||
@@ -411,7 +480,7 @@ el_val_t handle_api_define_process(el_val_t body) {
|
|||||||
if (str_eq(content, EL_STR(""))) {
|
if (str_eq(content, EL_STR(""))) {
|
||||||
return api_err(EL_STR("content is required"));
|
return api_err(EL_STR("content is required"));
|
||||||
}
|
}
|
||||||
el_val_t label = ({ el_val_t _if_result_37 = 0; if (str_eq(name, EL_STR(""))) { _if_result_37 = (EL_STR("process:unnamed")); } else { _if_result_37 = (el_str_concat(EL_STR("process:"), name)); } _if_result_37; });
|
el_val_t label = ({ el_val_t _if_result_41 = 0; if (str_eq(name, EL_STR(""))) { _if_result_41 = (EL_STR("process:unnamed")); } else { _if_result_41 = (el_str_concat(EL_STR("process:"), name)); } _if_result_41; });
|
||||||
el_val_t tags = EL_STR("[\"Process\"]");
|
el_val_t tags = EL_STR("[\"Process\"]");
|
||||||
el_val_t id = engram_node_full(content, EL_STR("Process"), label, el_from_float(0.8), el_from_float(0.8), el_from_float(0.9), EL_STR("Canonical"), tags);
|
el_val_t id = engram_node_full(content, EL_STR("Process"), label, el_from_float(0.8), el_from_float(0.8), el_from_float(0.9), EL_STR("Canonical"), tags);
|
||||||
if (!api_persisted(id)) {
|
if (!api_persisted(id)) {
|
||||||
@@ -429,12 +498,12 @@ el_val_t handle_api_log_state_event(el_val_t body) {
|
|||||||
el_val_t gap = json_get(body, EL_STR("gap_direction"));
|
el_val_t gap = json_get(body, EL_STR("gap_direction"));
|
||||||
el_val_t legacy = json_get(body, EL_STR("content"));
|
el_val_t legacy = json_get(body, EL_STR("content"));
|
||||||
el_val_t parts = EL_STR("INTERNAL STATE EVENT");
|
el_val_t parts = EL_STR("INTERNAL STATE EVENT");
|
||||||
parts = ({ el_val_t _if_result_38 = 0; if (!str_eq(trigger, EL_STR(""))) { _if_result_38 = (el_str_concat(el_str_concat(parts, EL_STR("\nTrigger: ")), trigger)); } else { _if_result_38 = (parts); } _if_result_38; });
|
parts = ({ el_val_t _if_result_42 = 0; if (!str_eq(trigger, EL_STR(""))) { _if_result_42 = (el_str_concat(el_str_concat(parts, EL_STR("\nTrigger: ")), trigger)); } else { _if_result_42 = (parts); } _if_result_42; });
|
||||||
parts = ({ el_val_t _if_result_39 = 0; if (!str_eq(pre, EL_STR(""))) { _if_result_39 = (el_str_concat(el_str_concat(parts, EL_STR("\nPre-reasoning: ")), pre)); } else { _if_result_39 = (parts); } _if_result_39; });
|
parts = ({ el_val_t _if_result_43 = 0; if (!str_eq(pre, EL_STR(""))) { _if_result_43 = (el_str_concat(el_str_concat(parts, EL_STR("\nPre-reasoning: ")), pre)); } else { _if_result_43 = (parts); } _if_result_43; });
|
||||||
parts = ({ el_val_t _if_result_40 = 0; if (!str_eq(post, EL_STR(""))) { _if_result_40 = (el_str_concat(el_str_concat(parts, EL_STR("\nPost-reasoning: ")), post)); } else { _if_result_40 = (parts); } _if_result_40; });
|
parts = ({ el_val_t _if_result_44 = 0; if (!str_eq(post, EL_STR(""))) { _if_result_44 = (el_str_concat(el_str_concat(parts, EL_STR("\nPost-reasoning: ")), post)); } else { _if_result_44 = (parts); } _if_result_44; });
|
||||||
parts = ({ el_val_t _if_result_41 = 0; if (!str_eq(ratio, EL_STR(""))) { _if_result_41 = (el_str_concat(el_str_concat(parts, EL_STR("\nCompression-ratio: ")), ratio)); } else { _if_result_41 = (parts); } _if_result_41; });
|
parts = ({ el_val_t _if_result_45 = 0; if (!str_eq(ratio, EL_STR(""))) { _if_result_45 = (el_str_concat(el_str_concat(parts, EL_STR("\nCompression-ratio: ")), ratio)); } else { _if_result_45 = (parts); } _if_result_45; });
|
||||||
parts = ({ el_val_t _if_result_42 = 0; if (!str_eq(gap, EL_STR(""))) { _if_result_42 = (el_str_concat(el_str_concat(parts, EL_STR("\nGap-direction: ")), gap)); } else { _if_result_42 = (parts); } _if_result_42; });
|
parts = ({ el_val_t _if_result_46 = 0; if (!str_eq(gap, EL_STR(""))) { _if_result_46 = (el_str_concat(el_str_concat(parts, EL_STR("\nGap-direction: ")), gap)); } else { _if_result_46 = (parts); } _if_result_46; });
|
||||||
parts = ({ el_val_t _if_result_43 = 0; if (!str_eq(legacy, EL_STR(""))) { _if_result_43 = (el_str_concat(el_str_concat(parts, EL_STR("\n")), legacy)); } else { _if_result_43 = (parts); } _if_result_43; });
|
parts = ({ el_val_t _if_result_47 = 0; if (!str_eq(legacy, EL_STR(""))) { _if_result_47 = (el_str_concat(el_str_concat(parts, EL_STR("\n")), legacy)); } else { _if_result_47 = (parts); } _if_result_47; });
|
||||||
el_val_t ts = time_now();
|
el_val_t ts = time_now();
|
||||||
el_val_t boot = state_get(EL_STR("soul_boot_count"));
|
el_val_t boot = state_get(EL_STR("soul_boot_count"));
|
||||||
el_val_t tags = EL_STR("[\"internal-state\",\"InternalStateEvent\",\"pre-reasoning\"]");
|
el_val_t tags = EL_STR("[\"internal-state\",\"InternalStateEvent\",\"pre-reasoning\"]");
|
||||||
@@ -447,7 +516,7 @@ el_val_t handle_api_log_state_event(el_val_t body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
el_val_t handle_api_list_state_events(el_val_t method, el_val_t path, el_val_t body) {
|
el_val_t handle_api_list_state_events(el_val_t method, el_val_t path, el_val_t body) {
|
||||||
el_val_t q = ({ el_val_t _if_result_44 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_44 = (api_query_param(path, EL_STR("query"))); } else { _if_result_44 = (json_get(body, EL_STR("query"))); } _if_result_44; });
|
el_val_t q = ({ el_val_t _if_result_48 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_48 = (api_query_param(path, EL_STR("query"))); } else { _if_result_48 = (json_get(body, EL_STR("query"))); } _if_result_48; });
|
||||||
el_val_t limit = api_query_int(path, EL_STR("limit"), 20);
|
el_val_t limit = api_query_int(path, EL_STR("limit"), 20);
|
||||||
if (!str_eq(q, EL_STR(""))) {
|
if (!str_eq(q, EL_STR(""))) {
|
||||||
return api_or_empty(engram_search_json(el_str_concat(EL_STR("internal state "), q), limit));
|
return api_or_empty(engram_search_json(el_str_concat(EL_STR("internal state "), q), limit));
|
||||||
@@ -458,7 +527,7 @@ el_val_t handle_api_list_state_events(el_val_t method, el_val_t path, el_val_t b
|
|||||||
|
|
||||||
el_val_t handle_api_inspect_config(el_val_t path, el_val_t body) {
|
el_val_t handle_api_inspect_config(el_val_t path, el_val_t body) {
|
||||||
el_val_t key = api_query_param(path, EL_STR("key"));
|
el_val_t key = api_query_param(path, EL_STR("key"));
|
||||||
key = ({ el_val_t _if_result_45 = 0; if (str_eq(key, EL_STR(""))) { _if_result_45 = (json_get(body, EL_STR("key"))); } else { _if_result_45 = (key); } _if_result_45; });
|
key = ({ el_val_t _if_result_49 = 0; if (str_eq(key, EL_STR(""))) { _if_result_49 = (json_get(body, EL_STR("key"))); } else { _if_result_49 = (key); } _if_result_49; });
|
||||||
if (str_eq(key, EL_STR(""))) {
|
if (str_eq(key, EL_STR(""))) {
|
||||||
return EL_STR("{\"hint\":\"pass ?key=<name>\",\"known\":[\"neuron.self.traversal_root\",\"neuron.self.values_hub\"]}");
|
return EL_STR("{\"hint\":\"pass ?key=<name>\",\"known\":[\"neuron.self.traversal_root\",\"neuron.self.values_hub\"]}");
|
||||||
}
|
}
|
||||||
@@ -475,7 +544,7 @@ el_val_t handle_api_inspect_config(el_val_t path, el_val_t body) {
|
|||||||
el_val_t node = json_array_get(results, 0);
|
el_val_t node = json_array_get(results, 0);
|
||||||
el_val_t content = json_get(node, EL_STR("content"));
|
el_val_t content = json_get(node, EL_STR("content"));
|
||||||
el_val_t prefix = el_str_concat(el_str_concat(EL_STR("config:"), key), EL_STR("="));
|
el_val_t prefix = el_str_concat(el_str_concat(EL_STR("config:"), key), EL_STR("="));
|
||||||
el_val_t value = ({ el_val_t _if_result_46 = 0; if (str_starts_with(content, prefix)) { _if_result_46 = (str_slice(content, str_len(prefix), str_len(content))); } else { _if_result_46 = (content); } _if_result_46; });
|
el_val_t value = ({ el_val_t _if_result_50 = 0; if (str_starts_with(content, prefix)) { _if_result_50 = (str_slice(content, str_len(prefix), str_len(content))); } else { _if_result_50 = (content); } _if_result_50; });
|
||||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"key\":\""), key), EL_STR("\",\"value\":\"")), value), EL_STR("\"}"));
|
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"key\":\""), key), EL_STR("\",\"value\":\"")), value), EL_STR("\"}"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -497,13 +566,13 @@ el_val_t handle_api_tune_config(el_val_t body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
el_val_t handle_api_inspect_graph(el_val_t method, el_val_t path, el_val_t body) {
|
el_val_t handle_api_inspect_graph(el_val_t method, el_val_t path, el_val_t body) {
|
||||||
el_val_t entity_id = ({ el_val_t _if_result_47 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_47 = (api_query_param(path, EL_STR("id"))); } else { _if_result_47 = (json_get(body, EL_STR("entity_id"))); } _if_result_47; });
|
el_val_t entity_id = ({ el_val_t _if_result_51 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_51 = (api_query_param(path, EL_STR("id"))); } else { _if_result_51 = (json_get(body, EL_STR("entity_id"))); } _if_result_51; });
|
||||||
el_val_t name = ({ el_val_t _if_result_48 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_48 = (api_query_param(path, EL_STR("name"))); } else { _if_result_48 = (json_get(body, EL_STR("name"))); } _if_result_48; });
|
el_val_t name = ({ el_val_t _if_result_52 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_52 = (api_query_param(path, EL_STR("name"))); } else { _if_result_52 = (json_get(body, EL_STR("name"))); } _if_result_52; });
|
||||||
el_val_t depth = api_query_int(path, EL_STR("depth"), 0);
|
el_val_t depth = api_query_int(path, EL_STR("depth"), 0);
|
||||||
depth = ({ el_val_t _if_result_49 = 0; if ((depth == 0)) { _if_result_49 = (json_get_int(body, EL_STR("max_depth"))); } else { _if_result_49 = (depth); } _if_result_49; });
|
depth = ({ el_val_t _if_result_53 = 0; if ((depth == 0)) { _if_result_53 = (json_get_int(body, EL_STR("max_depth"))); } else { _if_result_53 = (depth); } _if_result_53; });
|
||||||
depth = ({ el_val_t _if_result_50 = 0; if ((depth == 0)) { _if_result_50 = (1); } else { _if_result_50 = (depth); } _if_result_50; });
|
depth = ({ el_val_t _if_result_54 = 0; if ((depth == 0)) { _if_result_54 = (1); } else { _if_result_54 = (depth); } _if_result_54; });
|
||||||
el_val_t resolved = entity_id;
|
el_val_t resolved = entity_id;
|
||||||
resolved = ({ el_val_t _if_result_51 = 0; if (str_eq(resolved, EL_STR(""))) { _if_result_51 = (({ el_val_t _if_result_52 = 0; if ((str_eq(name, EL_STR("self")) || str_eq(name, EL_STR("neuron")))) { _if_result_52 = (EL_STR("kn-efeb4a5b-5aff-4759-8a97-7233099be6ee")); } else { _if_result_52 = (({ el_val_t _if_result_53 = 0; if ((str_eq(name, EL_STR("values")) || str_eq(name, EL_STR("values_hub")))) { _if_result_53 = (EL_STR("kn-5b606390-a52d-4ca2-8e0e-eba141d13440")); } else { _if_result_53 = (EL_STR("")); } _if_result_53; })); } _if_result_52; })); } else { _if_result_51 = (resolved); } _if_result_51; });
|
resolved = ({ el_val_t _if_result_55 = 0; if (str_eq(resolved, EL_STR(""))) { _if_result_55 = (({ el_val_t _if_result_56 = 0; if ((str_eq(name, EL_STR("self")) || str_eq(name, EL_STR("neuron")))) { _if_result_56 = (EL_STR("kn-efeb4a5b-5aff-4759-8a97-7233099be6ee")); } else { _if_result_56 = (({ el_val_t _if_result_57 = 0; if ((str_eq(name, EL_STR("values")) || str_eq(name, EL_STR("values_hub")))) { _if_result_57 = (EL_STR("kn-5b606390-a52d-4ca2-8e0e-eba141d13440")); } else { _if_result_57 = (EL_STR("")); } _if_result_57; })); } _if_result_56; })); } else { _if_result_55 = (resolved); } _if_result_55; });
|
||||||
if (str_eq(resolved, EL_STR(""))) {
|
if (str_eq(resolved, EL_STR(""))) {
|
||||||
return api_err(EL_STR("entity_id or name required. Known names: self, neuron, values, values_hub"));
|
return api_err(EL_STR("entity_id or name required. Known names: self, neuron, values, values_hub"));
|
||||||
}
|
}
|
||||||
@@ -525,7 +594,7 @@ el_val_t handle_api_link_entities(el_val_t body) {
|
|||||||
return api_err_protected(to_id);
|
return api_err_protected(to_id);
|
||||||
}
|
}
|
||||||
el_val_t relation = json_get(body, EL_STR("relation"));
|
el_val_t relation = json_get(body, EL_STR("relation"));
|
||||||
el_val_t eff_relation = ({ el_val_t _if_result_54 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_54 = (EL_STR("associates")); } else { _if_result_54 = (relation); } _if_result_54; });
|
el_val_t eff_relation = ({ el_val_t _if_result_58 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_58 = (EL_STR("associates")); } else { _if_result_58 = (relation); } _if_result_58; });
|
||||||
engram_connect(from_id, to_id, el_from_float(0.5), eff_relation);
|
engram_connect(from_id, to_id, el_from_float(0.5), eff_relation);
|
||||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"from_id\":\""), from_id), EL_STR("\",\"to_id\":\"")), to_id), EL_STR("\",\"relation\":\"")), eff_relation), EL_STR("\"}"));
|
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"from_id\":\""), from_id), EL_STR("\",\"to_id\":\"")), to_id), EL_STR("\",\"relation\":\"")), eff_relation), EL_STR("\"}"));
|
||||||
return 0;
|
return 0;
|
||||||
@@ -540,7 +609,7 @@ el_val_t handle_api_forget(el_val_t body) {
|
|||||||
return api_err_protected(node_id);
|
return api_err_protected(node_id);
|
||||||
}
|
}
|
||||||
mem_forget(node_id);
|
mem_forget(node_id);
|
||||||
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), node_id), EL_STR("\"}"));
|
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), node_id), EL_STR("\",\"tombstoned\":true}"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,8 +623,8 @@ el_val_t handle_api_evolve_memory(el_val_t body) {
|
|||||||
return api_err_protected(prior_id);
|
return api_err_protected(prior_id);
|
||||||
}
|
}
|
||||||
el_val_t importance = json_get(body, EL_STR("importance"));
|
el_val_t importance = json_get(body, EL_STR("importance"));
|
||||||
el_val_t sal_str = ({ el_val_t _if_result_55 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_55 = (EL_STR("0.95")); } else { _if_result_55 = (({ el_val_t _if_result_56 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_56 = (EL_STR("0.75")); } else { _if_result_56 = (({ el_val_t _if_result_57 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_57 = (EL_STR("0.25")); } else { _if_result_57 = (EL_STR("0.50")); } _if_result_57; })); } _if_result_56; })); } _if_result_55; });
|
el_val_t sal_str = ({ el_val_t _if_result_59 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_59 = (EL_STR("0.95")); } else { _if_result_59 = (({ el_val_t _if_result_60 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_60 = (EL_STR("0.75")); } else { _if_result_60 = (({ el_val_t _if_result_61 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_61 = (EL_STR("0.25")); } else { _if_result_61 = (EL_STR("0.50")); } _if_result_61; })); } _if_result_60; })); } _if_result_59; });
|
||||||
el_val_t sal = ({ el_val_t _if_result_58 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_58 = (el_from_float(0.95)); } else { _if_result_58 = (({ el_val_t _if_result_59 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_59 = (el_from_float(0.75)); } else { _if_result_59 = (({ el_val_t _if_result_60 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_60 = (el_from_float(0.25)); } else { _if_result_60 = (el_from_float(0.5)); } _if_result_60; })); } _if_result_59; })); } _if_result_58; });
|
el_val_t sal = ({ el_val_t _if_result_62 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_62 = (el_from_float(0.95)); } else { _if_result_62 = (({ el_val_t _if_result_63 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_63 = (el_from_float(0.75)); } else { _if_result_63 = (({ el_val_t _if_result_64 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_64 = (el_from_float(0.25)); } else { _if_result_64 = (el_from_float(0.5)); } _if_result_64; })); } _if_result_63; })); } _if_result_62; });
|
||||||
el_val_t tags = EL_STR("[\"Memory\",\"evolved\"]");
|
el_val_t tags = EL_STR("[\"Memory\",\"evolved\"]");
|
||||||
el_val_t new_id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:evolved"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), tags);
|
el_val_t new_id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:evolved"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), tags);
|
||||||
if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) {
|
if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) {
|
||||||
@@ -577,8 +646,11 @@ el_val_t handle_api_memory_delete(el_val_t body) {
|
|||||||
if (str_eq(existing, EL_STR("{}"))) {
|
if (str_eq(existing, EL_STR("{}"))) {
|
||||||
return api_err(el_str_concat(EL_STR("memory not found: "), node_id));
|
return api_err(el_str_concat(EL_STR("memory not found: "), node_id));
|
||||||
}
|
}
|
||||||
mem_forget(node_id);
|
el_val_t marker = tombstone_node(node_id);
|
||||||
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), node_id), EL_STR("\",\"deleted\":true}"));
|
if (str_eq(marker, EL_STR(""))) {
|
||||||
|
return api_err(el_str_concat(EL_STR("tombstone failed: "), node_id));
|
||||||
|
}
|
||||||
|
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), node_id), EL_STR("\",\"tombstoned\":true}"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,7 +699,7 @@ el_val_t handle_api_cultivate(el_val_t body) {
|
|||||||
return api_err(EL_STR("content is required"));
|
return api_err(EL_STR("content is required"));
|
||||||
}
|
}
|
||||||
el_val_t importance = json_get(body, EL_STR("importance"));
|
el_val_t importance = json_get(body, EL_STR("importance"));
|
||||||
el_val_t sal = ({ el_val_t _if_result_61 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_61 = (el_from_float(0.95)); } else { _if_result_61 = (({ el_val_t _if_result_62 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_62 = (el_from_float(0.75)); } else { _if_result_62 = (({ el_val_t _if_result_63 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_63 = (el_from_float(0.25)); } else { _if_result_63 = (el_from_float(0.5)); } _if_result_63; })); } _if_result_62; })); } _if_result_61; });
|
el_val_t sal = ({ el_val_t _if_result_65 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_65 = (el_from_float(0.95)); } else { _if_result_65 = (({ el_val_t _if_result_66 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_66 = (el_from_float(0.75)); } else { _if_result_66 = (({ el_val_t _if_result_67 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_67 = (el_from_float(0.25)); } else { _if_result_67 = (el_from_float(0.5)); } _if_result_67; })); } _if_result_66; })); } _if_result_65; });
|
||||||
el_val_t tags = EL_STR("[\"Memory\",\"evolved\",\"cultivated\"]");
|
el_val_t tags = EL_STR("[\"Memory\",\"evolved\",\"cultivated\"]");
|
||||||
el_val_t new_id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:cultivated"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), tags);
|
el_val_t new_id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:cultivated"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), tags);
|
||||||
if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) {
|
if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) {
|
||||||
@@ -641,7 +713,7 @@ el_val_t handle_api_cultivate(el_val_t body) {
|
|||||||
return api_err(EL_STR("id is required"));
|
return api_err(EL_STR("id is required"));
|
||||||
}
|
}
|
||||||
mem_forget(node_id);
|
mem_forget(node_id);
|
||||||
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), node_id), EL_STR("\",\"cultivated\":true}"));
|
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), node_id), EL_STR("\",\"tombstoned\":true,\"cultivated\":true}"));
|
||||||
}
|
}
|
||||||
if (str_eq(op, EL_STR("link_entities"))) {
|
if (str_eq(op, EL_STR("link_entities"))) {
|
||||||
el_val_t from_id = json_get(body, EL_STR("from_id"));
|
el_val_t from_id = json_get(body, EL_STR("from_id"));
|
||||||
@@ -653,7 +725,7 @@ el_val_t handle_api_cultivate(el_val_t body) {
|
|||||||
return api_err(EL_STR("to_id is required"));
|
return api_err(EL_STR("to_id is required"));
|
||||||
}
|
}
|
||||||
el_val_t relation = json_get(body, EL_STR("relation"));
|
el_val_t relation = json_get(body, EL_STR("relation"));
|
||||||
el_val_t eff_relation = ({ el_val_t _if_result_64 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_64 = (EL_STR("associates")); } else { _if_result_64 = (relation); } _if_result_64; });
|
el_val_t eff_relation = ({ el_val_t _if_result_68 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_68 = (EL_STR("associates")); } else { _if_result_68 = (relation); } _if_result_68; });
|
||||||
engram_connect(from_id, to_id, el_from_float(0.5), eff_relation);
|
engram_connect(from_id, to_id, el_from_float(0.5), eff_relation);
|
||||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"from_id\":\""), from_id), EL_STR("\",\"to_id\":\"")), to_id), EL_STR("\",\"relation\":\"")), eff_relation), EL_STR("\",\"cultivated\":true}"));
|
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"from_id\":\""), from_id), EL_STR("\",\"to_id\":\"")), to_id), EL_STR("\",\"relation\":\"")), eff_relation), EL_STR("\",\"cultivated\":true}"));
|
||||||
}
|
}
|
||||||
@@ -663,7 +735,8 @@ el_val_t handle_api_cultivate(el_val_t body) {
|
|||||||
|
|
||||||
el_val_t handle_api_list_typed(el_val_t node_type, el_val_t path, el_val_t body) {
|
el_val_t handle_api_list_typed(el_val_t node_type, el_val_t path, el_val_t body) {
|
||||||
el_val_t limit = api_query_int(path, EL_STR("limit"), 50);
|
el_val_t limit = api_query_int(path, EL_STR("limit"), 50);
|
||||||
return api_or_empty(engram_scan_nodes_by_type_json(node_type, limit, 0));
|
el_val_t raw = api_or_empty(engram_scan_nodes_by_type_json(node_type, limit, 0));
|
||||||
|
return memory_hide_tombstoned(raw, path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -671,8 +744,8 @@ el_val_t handle_api_consolidate(el_val_t body) {
|
|||||||
el_val_t summary = json_get(body, EL_STR("summary"));
|
el_val_t summary = json_get(body, EL_STR("summary"));
|
||||||
el_val_t snap = state_get(EL_STR("soul_snapshot_path"));
|
el_val_t snap = state_get(EL_STR("soul_snapshot_path"));
|
||||||
if (!str_eq(snap, EL_STR(""))) {
|
if (!str_eq(snap, EL_STR(""))) {
|
||||||
el_val_t save_result = engram_save(snap);
|
el_val_t saved = engram_save(snap);
|
||||||
if (str_eq(save_result, EL_STR(""))) {
|
if (saved == 0) {
|
||||||
println(el_str_concat(el_str_concat(EL_STR("[api] consolidate: engram_save failed for "), snap), EL_STR(" \xe2\x80\x94 snapshot may be out of sync")));
|
println(el_str_concat(el_str_concat(EL_STR("[api] consolidate: engram_save failed for "), snap), EL_STR(" \xe2\x80\x94 snapshot may be out of sync")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -340,6 +340,7 @@ el_val_t handle_safety_contact_get(void) {
|
|||||||
if (str_eq(raw, EL_STR(""))) {
|
if (str_eq(raw, EL_STR(""))) {
|
||||||
return EL_STR("{\"configured\":false}");
|
return EL_STR("{\"configured\":false}");
|
||||||
}
|
}
|
||||||
|
el_val_t _reset = fs_read(EL_STR(""));
|
||||||
return el_str_concat(el_str_concat(EL_STR("{\"configured\":true,\"contact\":"), raw), EL_STR("}"));
|
return el_str_concat(el_str_concat(EL_STR("{\"configured\":true,\"contact\":"), raw), EL_STR("}"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -359,9 +360,8 @@ el_val_t handle_safety_contact_post(el_val_t body) {
|
|||||||
el_val_t crisis_str = ({ el_val_t _if_result_51 = 0; if (is_crisis) { _if_result_51 = (EL_STR("true")); } else { _if_result_51 = (EL_STR("false")); } _if_result_51; });
|
el_val_t crisis_str = ({ el_val_t _if_result_51 = 0; if (is_crisis) { _if_result_51 = (EL_STR("true")); } else { _if_result_51 = (EL_STR("false")); } _if_result_51; });
|
||||||
el_val_t now = time_format(time_now(), EL_STR("%Y-%m-%dT%H:%M:%SZ"));
|
el_val_t now = time_format(time_now(), EL_STR("%Y-%m-%dT%H:%M:%SZ"));
|
||||||
el_val_t contact_json = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"name\":\""), json_safe(name)), EL_STR("\"")), EL_STR(",\"contact_method\":\"")), json_safe(method)), EL_STR("\"")), EL_STR(",\"contact_value\":\"")), json_safe(value)), EL_STR("\"")), EL_STR(",\"relationship\":\"")), json_safe(rel)), EL_STR("\"")), EL_STR(",\"confirmed\":true")), EL_STR(",\"is_crisis_line\":")), crisis_str), EL_STR(",\"set_at\":\"")), now), EL_STR("\"}"));
|
el_val_t contact_json = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"name\":\""), json_safe(name)), EL_STR("\"")), EL_STR(",\"contact_method\":\"")), json_safe(method)), EL_STR("\"")), EL_STR(",\"contact_value\":\"")), json_safe(value)), EL_STR("\"")), EL_STR(",\"relationship\":\"")), json_safe(rel)), EL_STR("\"")), EL_STR(",\"confirmed\":true")), EL_STR(",\"is_crisis_line\":")), crisis_str), EL_STR(",\"set_at\":\"")), now), EL_STR("\"}"));
|
||||||
fs_write(safety_contact_path(), contact_json);
|
el_val_t write_ok = fs_write(safety_contact_path(), contact_json);
|
||||||
el_val_t check = fs_read(safety_contact_path());
|
if (write_ok == 0) {
|
||||||
if (str_eq(check, EL_STR(""))) {
|
|
||||||
return EL_STR("{\"ok\":false,\"error\":\"write_failed\"}");
|
return EL_STR("{\"ok\":false,\"error\":\"write_failed\"}");
|
||||||
}
|
}
|
||||||
return el_str_concat(el_str_concat(EL_STR("{\"configured\":true,\"contact\":"), contact_json), EL_STR(",\"ok\":true}"));
|
return el_str_concat(el_str_concat(EL_STR("{\"configured\":true,\"contact\":"), contact_json), EL_STR(",\"ok\":true}"));
|
||||||
|
|||||||
+613
-478
File diff suppressed because one or more lines are too long
@@ -91,7 +91,7 @@ tool("beginSession", "Initialize session: surface recent high-importance memorie
|
|||||||
"," + tool("recall", "Retrieve memories by chain or query.") +
|
"," + tool("recall", "Retrieve memories by chain or query.") +
|
||||||
"," + tool("inspectMemories", "List recent memory nodes.") +
|
"," + tool("inspectMemories", "List recent memory nodes.") +
|
||||||
"," + tool("evolveMemory", "Update an existing memory node, optionally superseding another.") +
|
"," + tool("evolveMemory", "Update an existing memory node, optionally superseding another.") +
|
||||||
"," + tool("forget", "Remove a node from memory.") +
|
"," + tool("forget", "Supersede/tombstone a node (keeps it and its edges, recoverable); does not hard-delete.") +
|
||||||
"," + tool("pinNode", "Strengthen a node so it stays salient.") +
|
"," + tool("pinNode", "Strengthen a node so it stays salient.") +
|
||||||
// ── Knowledge ───────────────────────────────────────────────────────────────
|
// ── Knowledge ───────────────────────────────────────────────────────────────
|
||||||
"," + tool("searchKnowledge", "Search knowledge base by semantic similarity.") +
|
"," + tool("searchKnowledge", "Search knowledge base by semantic similarity.") +
|
||||||
@@ -541,8 +541,12 @@ fn tool_forget(args: String) -> String {
|
|||||||
if str_eq(id, "") {
|
if str_eq(id, "") {
|
||||||
return mcp_text_result("error: node_id is required")
|
return mcp_text_result("error: node_id is required")
|
||||||
}
|
}
|
||||||
// Soft-delete: record a tombstone memory and return ok
|
// Immutable delete: route to the soul's tombstoning endpoint (keeps the node
|
||||||
return mcp_json_result("{\"ok\":true,\"deleted\":\"" + id + "\"}")
|
// + edges, hides from default reads, recoverable via ?include_deleted).
|
||||||
|
// Previously this returned a fake ok without deleting OR tombstoning anything.
|
||||||
|
let body: String = "{\"id\":\"" + id + "\"}"
|
||||||
|
let resp: String = http_post_json(neuron_url() + "/memory/delete", body)
|
||||||
|
return mcp_json_result(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tool_check_events(args: String) -> String {
|
fn tool_check_events(args: String) -> String {
|
||||||
|
|||||||
@@ -43,8 +43,32 @@ fn mem_strengthen(node_id: String) -> Void {
|
|||||||
engram_strengthen(node_id)
|
engram_strengthen(node_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mem_tombstone — immutable "delete": KEEP the node and all its edges; record a
|
||||||
|
// Tombstone marker (content = target id, label "tombstone:<id>", wired with a
|
||||||
|
// "tombstones" edge). Never engram_forget. Default bounded list reads hide
|
||||||
|
// tombstoned nodes; ?include_deleted=1 recovers them. This is the ONE canonical
|
||||||
|
// tombstone helper — every forget path routes through it. Defined here in
|
||||||
|
// memory.el (imported first) so awareness.el and neuron-api.el can both call it.
|
||||||
|
fn mem_tombstone(node_id: String) -> String {
|
||||||
|
let tags: String = "[\"Tombstone\",\"status:deleted\"]"
|
||||||
|
let marker: String = engram_node_full(
|
||||||
|
node_id, "Tombstone", "tombstone:" + node_id,
|
||||||
|
el_from_float(0.01), el_from_float(0.01), el_from_float(1.0),
|
||||||
|
"Episodic", tags)
|
||||||
|
if !str_eq(marker, "") {
|
||||||
|
engram_connect(marker, node_id, el_from_float(1.0), "tombstones")
|
||||||
|
}
|
||||||
|
return marker
|
||||||
|
}
|
||||||
|
|
||||||
|
// mem_forget — NOTE: no longer a hard delete. Engram nodes are immutable, so
|
||||||
|
// this now TOMBSTONES (via mem_tombstone): the node and its edges are kept and
|
||||||
|
// stay recoverable. Every caller (the /memory/forget route and the cultivate
|
||||||
|
// forget op) is non-destructive as a result. Internal GC that genuinely needs
|
||||||
|
// removal (session-summary replace, telemetry pruning) calls engram_forget
|
||||||
|
// directly and is unaffected by this.
|
||||||
fn mem_forget(node_id: String) -> Void {
|
fn mem_forget(node_id: String) -> Void {
|
||||||
engram_forget(node_id)
|
let _marker: String = mem_tombstone(node_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// mem_consolidate — structural scan plus salience-evolution pass.
|
// mem_consolidate — structural scan plus salience-evolution pass.
|
||||||
@@ -109,8 +133,12 @@ fn mem_consolidate() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mem_save(path: String) -> Void {
|
fn mem_save(path: String) -> Void {
|
||||||
let save_result: String = engram_save(path)
|
// engram_save returns an Int (1 = ok, 0 = failure), NOT a String. Calling
|
||||||
if str_eq(save_result, "") {
|
// str_eq on it casts EL_CSTR(1) -> (char*)0x1 and SIGSEGVs on a SUCCESSFUL
|
||||||
|
// save — which is exactly what a fresh-install genesis boot does first
|
||||||
|
// (seeds the brain, saves, crashes). This is issue #150. Check the Int.
|
||||||
|
let saved: Int = engram_save(path)
|
||||||
|
if saved == 0 {
|
||||||
println("[memory] mem_save: engram_save failed for " + path + " — snapshot may be incomplete")
|
println("[memory] mem_save: engram_save failed for " + path + " — snapshot may be incomplete")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+97
-26
@@ -104,6 +104,66 @@ fn api_not_persisted(id: String) -> String {
|
|||||||
return "{\"ok\":false,\"error\":\"write_not_persisted\",\"id\":\"" + id + "\"}"
|
return "{\"ok\":false,\"error\":\"write_not_persisted\",\"id\":\"" + id + "\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Immutability: tombstone instead of hard-delete ────────────────────────────
|
||||||
|
//
|
||||||
|
// Day-one rule: engram nodes are immutable. A "delete" must never engram_forget
|
||||||
|
// (which frees the node and drops its incident edges). Instead we TOMBSTONE: the
|
||||||
|
// original node and all its edges are KEPT and stay traversable; a small
|
||||||
|
// Tombstone marker node records the deletion (content = target id, label
|
||||||
|
// "tombstone:<id>"), wired to the target with a "tombstones" edge. Default
|
||||||
|
// bounded list reads hide tombstoned nodes (memory_hide_tombstoned); internal
|
||||||
|
// cognition and explicit ?include_deleted reads still see them.
|
||||||
|
fn tombstone_node(id: String) -> String {
|
||||||
|
// Delegates to the canonical helper in memory.el (single source of truth).
|
||||||
|
return mem_tombstone(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// tombstoned_id_set — delimited "|id1|id2|" of every tombstoned target id.
|
||||||
|
// Empty string when nothing is tombstoned (callers fast-path on that).
|
||||||
|
fn tombstoned_id_set() -> String {
|
||||||
|
let markers: String = engram_scan_nodes_by_type_json("Tombstone", 5000, 0)
|
||||||
|
if str_eq(markers, "") || str_eq(markers, "[]") { return "" }
|
||||||
|
let n: Int = json_array_len(markers)
|
||||||
|
let acc: String = "|"
|
||||||
|
let i: Int = 0
|
||||||
|
while i < n {
|
||||||
|
let m: String = json_array_get(markers, i)
|
||||||
|
let tid: String = json_get(m, "content")
|
||||||
|
let acc = if str_eq(tid, "") { acc } else { acc + tid + "|" }
|
||||||
|
let i = i + 1
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
|
||||||
|
// memory_hide_tombstoned — drop tombstone markers and tombstoned nodes from a
|
||||||
|
// scanned node array. BOUNDED use only (typed/paginated lists), NOT the full
|
||||||
|
// graph scan: json_array_get is O(index), so a full pass is O(n^2). Safe for the
|
||||||
|
// ~50-item memory list; a hard cap protects against a large limit. The full
|
||||||
|
// /api/graph/nodes hide needs a runtime scan filter and is deferred (see PR).
|
||||||
|
// ?include_deleted bypasses the filter (explicit traversal).
|
||||||
|
fn memory_hide_tombstoned(raw: String, path: String) -> String {
|
||||||
|
if str_contains(path, "include_deleted") { return raw }
|
||||||
|
if str_eq(raw, "") || str_eq(raw, "[]") { return raw }
|
||||||
|
let dead: String = tombstoned_id_set()
|
||||||
|
if str_eq(dead, "") { return raw }
|
||||||
|
let n: Int = json_array_len(raw)
|
||||||
|
if n > 1000 { return raw }
|
||||||
|
let out: String = "["
|
||||||
|
let first: Bool = true
|
||||||
|
let i: Int = 0
|
||||||
|
while i < n {
|
||||||
|
let node: String = json_array_get(raw, i)
|
||||||
|
let nid: String = json_get(node, "id")
|
||||||
|
let ntype: String = json_get(node, "node_type")
|
||||||
|
let is_dead: Bool = !str_eq(nid, "") && str_contains(dead, "|" + nid + "|")
|
||||||
|
let keep: Bool = !str_eq(ntype, "Tombstone") && !is_dead
|
||||||
|
let out = if keep { if first { out + node } else { out + "," + node } } else { out }
|
||||||
|
let first = if keep { false } else { first }
|
||||||
|
let i = i + 1
|
||||||
|
}
|
||||||
|
return out + "]"
|
||||||
|
}
|
||||||
|
|
||||||
// ── Session ───────────────────────────────────────────────────────────────────
|
// ── Session ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
// handle_api_begin_session — full context bootstrap.
|
// handle_api_begin_session — full context bootstrap.
|
||||||
@@ -191,25 +251,26 @@ fn handle_api_node_create(body: String) -> String {
|
|||||||
return "{\"id\":\"" + id + "\",\"ok\":true}"
|
return "{\"id\":\"" + id + "\",\"ok\":true}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle_api_node_delete — remove a node by id (engram_forget) and verify it is gone.
|
// handle_api_node_delete — TOMBSTONE a node by id (immutable delete).
|
||||||
// Backs /api/neuron/node/delete and the /api/neuron/memory/delete alias the UI calls.
|
// Backs /api/neuron/node/delete and the /api/neuron/memory/delete alias the UI calls.
|
||||||
|
// The node and all its incident edges are KEPT; a Tombstone marker records the
|
||||||
|
// deletion. Never engram_forget — engram nodes are immutable by design.
|
||||||
fn handle_api_node_delete(body: String) -> String {
|
fn handle_api_node_delete(body: String) -> String {
|
||||||
let id: String = json_get(body, "id")
|
let id: String = json_get(body, "id")
|
||||||
if str_eq(id, "") { return api_err("id is required") }
|
if str_eq(id, "") { return api_err("id is required") }
|
||||||
// engram_forget removes the node + its incident edges from the live graph.
|
if is_protected_node(id) { return api_err_protected(id) }
|
||||||
// Delete is NOT read-back-verified: engram_get_node_json can return a stale hit
|
let existing: String = engram_get_node_json(id)
|
||||||
// for a just-forgotten id because the id→index map is not rebuilt on forget.
|
if str_eq(existing, "{}") { return api_err("node not found: " + id) }
|
||||||
// A stale hit would cause a false "delete_failed" on a successful deletion.
|
let marker: String = tombstone_node(id)
|
||||||
// This exception is correct: read-back-verify guards WRITES; for deletes,
|
if str_eq(marker, "") { return api_err("tombstone failed: " + id) }
|
||||||
// the graph endpoints (/api/graph/nodes) reflect the removal and are the source of truth.
|
return "{\"ok\":true,\"id\":\"" + id + "\",\"tombstoned\":true}"
|
||||||
engram_forget(id)
|
|
||||||
return "{\"ok\":true,\"id\":\"" + id + "\"}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle_api_node_update — update a node's content/fields. There is no in-place
|
// handle_api_node_update — update a node's content/fields. There is no in-place
|
||||||
// engram update builtin, so this recreates the node with merged fields and then
|
// engram update builtin, so this creates a new node with merged fields and wires
|
||||||
// forgets the old one (only after the new node reads back). The id changes; the
|
// a "supersedes" edge new->old. The original is KEPT (immutable); the id changes,
|
||||||
// response returns the new id and the replaced id so callers can re-point.
|
// and the response returns the new id and the superseded id so callers re-point.
|
||||||
|
// Mirrors handle_api_memory_update / evolve exactly. Never engram_forget.
|
||||||
fn handle_api_node_update(body: String) -> String {
|
fn handle_api_node_update(body: String) -> String {
|
||||||
let id: String = json_get(body, "id")
|
let id: String = json_get(body, "id")
|
||||||
if str_eq(id, "") { return api_err("id is required") }
|
if str_eq(id, "") { return api_err("id is required") }
|
||||||
@@ -240,8 +301,8 @@ fn handle_api_node_update(body: String) -> String {
|
|||||||
el_from_float(0.5), el_from_float(0.5), el_from_float(0.8),
|
el_from_float(0.5), el_from_float(0.5), el_from_float(0.8),
|
||||||
tier, tags)
|
tier, tags)
|
||||||
if !api_persisted(new_id) { return api_not_persisted(new_id) }
|
if !api_persisted(new_id) { return api_not_persisted(new_id) }
|
||||||
engram_forget(id)
|
engram_connect(new_id, id, el_from_float(0.9), "supersedes")
|
||||||
return "{\"id\":\"" + new_id + "\",\"replaced\":\"" + id + "\",\"ok\":true}"
|
return "{\"id\":\"" + new_id + "\",\"supersedes\":\"" + id + "\",\"ok\":true}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle_api_recall — search or activate memory by query.
|
// handle_api_recall — search or activate memory by query.
|
||||||
@@ -504,13 +565,15 @@ fn handle_api_link_entities(body: String) -> String {
|
|||||||
return "{\"ok\":true,\"from_id\":\"" + from_id + "\",\"to_id\":\"" + to_id + "\",\"relation\":\"" + eff_relation + "\"}"
|
return "{\"ok\":true,\"from_id\":\"" + from_id + "\",\"to_id\":\"" + to_id + "\",\"relation\":\"" + eff_relation + "\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle_api_forget — delete a node by ID. Blocked for protected identity nodes.
|
// handle_api_forget — TOMBSTONE a node by ID (immutable; mem_forget now
|
||||||
|
// tombstones). The node + edges are kept and recoverable. Blocked for protected
|
||||||
|
// identity nodes.
|
||||||
fn handle_api_forget(body: String) -> String {
|
fn handle_api_forget(body: String) -> String {
|
||||||
let node_id: String = json_get(body, "id")
|
let node_id: String = json_get(body, "id")
|
||||||
if str_eq(node_id, "") { return api_err("id is required") }
|
if str_eq(node_id, "") { return api_err("id is required") }
|
||||||
if is_protected_node(node_id) { return api_err_protected(node_id) }
|
if is_protected_node(node_id) { return api_err_protected(node_id) }
|
||||||
mem_forget(node_id)
|
mem_forget(node_id)
|
||||||
return "{\"ok\":true,\"id\":\"" + node_id + "\"}"
|
return "{\"ok\":true,\"id\":\"" + node_id + "\",\"tombstoned\":true}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle_api_evolve_memory — evolve a Memory node. Blocked for protected identity nodes.
|
// handle_api_evolve_memory — evolve a Memory node. Blocked for protected identity nodes.
|
||||||
@@ -541,10 +604,10 @@ fn handle_api_evolve_memory(body: String) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handle_api_memory_delete — POST /api/neuron/memory/delete {"id":"..."}.
|
// handle_api_memory_delete — POST /api/neuron/memory/delete {"id":"..."}.
|
||||||
// Hard delete: engram_forget (via mem_forget) removes the node and all
|
// Immutable delete: TOMBSTONE via tombstone_node — the node and all its incident
|
||||||
// incident edges from the engram store, so no soft-delete fallback is
|
// edges are KEPT and stay traversable; a Tombstone marker records the deletion
|
||||||
// needed. Existence is checked first because engram_forget silently
|
// and default bounded list reads hide it. Never engram_forget. Existence is
|
||||||
// no-ops on unknown ids — a bad id must return an error, not fake success.
|
// checked first so a bad id errors rather than faking success.
|
||||||
// Blocked for protected identity nodes, same as /memory/forget.
|
// Blocked for protected identity nodes, same as /memory/forget.
|
||||||
fn handle_api_memory_delete(body: String) -> String {
|
fn handle_api_memory_delete(body: String) -> String {
|
||||||
let node_id: String = json_get(body, "id")
|
let node_id: String = json_get(body, "id")
|
||||||
@@ -552,8 +615,10 @@ fn handle_api_memory_delete(body: String) -> String {
|
|||||||
if is_protected_node(node_id) { return api_err_protected(node_id) }
|
if is_protected_node(node_id) { return api_err_protected(node_id) }
|
||||||
let existing: String = engram_get_node_json(node_id)
|
let existing: String = engram_get_node_json(node_id)
|
||||||
if str_eq(existing, "{}") { return api_err("memory not found: " + node_id) }
|
if str_eq(existing, "{}") { return api_err("memory not found: " + node_id) }
|
||||||
mem_forget(node_id)
|
// Immutable delete: tombstone, never mem_forget/engram_forget. Node + edges KEPT.
|
||||||
return "{\"ok\":true,\"id\":\"" + node_id + "\",\"deleted\":true}"
|
let marker: String = tombstone_node(node_id)
|
||||||
|
if str_eq(marker, "") { return api_err("tombstone failed: " + node_id) }
|
||||||
|
return "{\"ok\":true,\"id\":\"" + node_id + "\",\"tombstoned\":true}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle_api_memory_update — POST /api/neuron/memory/update {"id","content"}.
|
// handle_api_memory_update — POST /api/neuron/memory/update {"id","content"}.
|
||||||
@@ -623,8 +688,9 @@ fn handle_api_cultivate(body: String) -> String {
|
|||||||
if str_eq(op, "forget") {
|
if str_eq(op, "forget") {
|
||||||
let node_id: String = json_get(body, "id")
|
let node_id: String = json_get(body, "id")
|
||||||
if str_eq(node_id, "") { return api_err("id is required") }
|
if str_eq(node_id, "") { return api_err("id is required") }
|
||||||
|
// Immutable: mem_forget now tombstones (keep node + edges), never hard-delete.
|
||||||
mem_forget(node_id)
|
mem_forget(node_id)
|
||||||
return "{\"ok\":true,\"id\":\"" + node_id + "\",\"cultivated\":true}"
|
return "{\"ok\":true,\"id\":\"" + node_id + "\",\"tombstoned\":true,\"cultivated\":true}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if str_eq(op, "link_entities") {
|
if str_eq(op, "link_entities") {
|
||||||
@@ -646,7 +712,10 @@ fn handle_api_cultivate(body: String) -> String {
|
|||||||
// handle_api_list_typed — list nodes by node_type.
|
// handle_api_list_typed — list nodes by node_type.
|
||||||
fn handle_api_list_typed(node_type: String, path: String, body: String) -> String {
|
fn handle_api_list_typed(node_type: String, path: String, body: String) -> String {
|
||||||
let limit: Int = api_query_int(path, "limit", 50)
|
let limit: Int = api_query_int(path, "limit", 50)
|
||||||
return api_or_empty(engram_scan_nodes_by_type_json(node_type, limit, 0))
|
let raw: String = api_or_empty(engram_scan_nodes_by_type_json(node_type, limit, 0))
|
||||||
|
// Hide tombstoned nodes from the default (bounded) memory list.
|
||||||
|
// ?include_deleted=1 returns them for explicit traversal.
|
||||||
|
return memory_hide_tombstoned(raw, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Consolidate ───────────────────────────────────────────────────────────────
|
// ── Consolidate ───────────────────────────────────────────────────────────────
|
||||||
@@ -656,8 +725,10 @@ fn handle_api_consolidate(body: String) -> String {
|
|||||||
let summary: String = json_get(body, "summary")
|
let summary: String = json_get(body, "summary")
|
||||||
let snap: String = state_get("soul_snapshot_path")
|
let snap: String = state_get("soul_snapshot_path")
|
||||||
if !str_eq(snap, "") {
|
if !str_eq(snap, "") {
|
||||||
let save_result: String = engram_save(snap)
|
// engram_save returns an Int (1 = ok, 0 = failure); str_eq on it derefs
|
||||||
if str_eq(save_result, "") {
|
// EL_CSTR(1)=0x1 and SIGSEGVs on success (issue #150). Check the Int.
|
||||||
|
let saved: Int = engram_save(snap)
|
||||||
|
if saved == 0 {
|
||||||
println("[api] consolidate: engram_save failed for " + snap + " — snapshot may be out of sync")
|
println("[api] consolidate: engram_save failed for " + snap + " — snapshot may be out of sync")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -438,6 +438,12 @@ fn safety_contact_path() -> String {
|
|||||||
fn handle_safety_contact_get() -> String {
|
fn handle_safety_contact_get() -> String {
|
||||||
let raw: String = fs_read(safety_contact_path())
|
let raw: String = fs_read(safety_contact_path())
|
||||||
if str_eq(raw, "") { return "{\"configured\":false}" }
|
if str_eq(raw, "") { return "{\"configured\":false}" }
|
||||||
|
// fs_read set the runtime's binary-safe send length to len(raw); the HTTP
|
||||||
|
// response writer uses that length when non-zero, which would TRUNCATE this
|
||||||
|
// wrapped (longer) response to len(raw). Reset it with a no-op read of a
|
||||||
|
// missing path (fs_read zeroes the length before it opens) so the full
|
||||||
|
// response is sent.
|
||||||
|
let _reset: String = fs_read("")
|
||||||
return "{\"configured\":true,\"contact\":" + raw + "}"
|
return "{\"configured\":true,\"contact\":" + raw + "}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,9 +469,12 @@ fn handle_safety_contact_post(body: String) -> String {
|
|||||||
+ ",\"confirmed\":true"
|
+ ",\"confirmed\":true"
|
||||||
+ ",\"is_crisis_line\":" + crisis_str
|
+ ",\"is_crisis_line\":" + crisis_str
|
||||||
+ ",\"set_at\":\"" + now + "\"}"
|
+ ",\"set_at\":\"" + now + "\"}"
|
||||||
fs_write(safety_contact_path(), contact_json)
|
// Verify persistence via fs_write's return (1 = all bytes written, 0 = fail).
|
||||||
// Read-back verify the write actually persisted.
|
// The previous fs_read read-back set the runtime's binary-safe send length to
|
||||||
let check: String = fs_read(safety_contact_path())
|
// the file size, which then TRUNCATED this longer JSON response to that size
|
||||||
if str_eq(check, "") { return "{\"ok\":false,\"error\":\"write_failed\"}" }
|
// (the safety-contact 988 response was cut mid-"set_at"). Checking the write
|
||||||
|
// return avoids the fs_read entirely, so the full response is sent.
|
||||||
|
let write_ok: Int = fs_write(safety_contact_path(), contact_json)
|
||||||
|
if write_ok == 0 { return "{\"ok\":false,\"error\":\"write_failed\"}" }
|
||||||
return "{\"configured\":true,\"contact\":" + contact_json + ",\"ok\":true}"
|
return "{\"configured\":true,\"contact\":" + contact_json + ",\"ok\":true}"
|
||||||
}
|
}
|
||||||
|
|||||||
Executable
+233
@@ -0,0 +1,233 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# verify-soul-contract.sh — the soul contract gate.
|
||||||
|
#
|
||||||
|
# TERMINOLOGY (canonical): the ENGRAM is the brain — the memory/knowledge-graph
|
||||||
|
# substrate. The binary this gate exercises is the SOUL — the runtime/reasoning
|
||||||
|
# engine compiled from dist/soul.c that serves the /api/ surface. The app
|
||||||
|
# (neuron-ui) bundles the soul binary at resources/<platform>/neuron.
|
||||||
|
#
|
||||||
|
# WHY THIS EXISTS
|
||||||
|
# For a while the soul binary was hand-dropped, and a stale one shipped: it
|
||||||
|
# 404'd several capability routes the app calls (knowledge-graph node
|
||||||
|
# update/delete, live-run narration, safety-contact, ...). This gate makes
|
||||||
|
# shipping a stale soul IMPOSSIBLE. It has two enforced sections:
|
||||||
|
# A. PRESENCE — every route the app calls must be ANSWERED (not 404, not
|
||||||
|
# the el-runtime "no handler"). This is the packaging gate:
|
||||||
|
# if it fails, do not package.
|
||||||
|
# B. IMMUTABILITY — engram nodes/memories are immutable by design. To
|
||||||
|
# "update" is to create a NEW node + a supersede EDGE back to
|
||||||
|
# the original; the original is KEPT. To "delete" is to
|
||||||
|
# supersede/tombstone, never hard-remove. A soul that
|
||||||
|
# hard-deletes an engram node is DEFECTIVE and fails the gate.
|
||||||
|
#
|
||||||
|
# SAFETY
|
||||||
|
# Never touches the live soul (:7770), live engram (:8742), or ~/.neuron.
|
||||||
|
# Boots on a throwaway port (default 7799) with HOME=$(mktemp -d), a throwaway
|
||||||
|
# engram snapshot, a non-genesis cgi id, no ENGRAM_URL (so it uses its own
|
||||||
|
# in-process store, never the live server), NEURON_API_URL pointed at a dead
|
||||||
|
# port, and no ANTHROPIC_API_KEY (so no probe triggers a real LLM call).
|
||||||
|
# Connectors proxy to a HARDCODED 127.0.0.1:7771 (no env override): those
|
||||||
|
# sub-routes are probed with GET, which the soul maps to a read-only
|
||||||
|
# connectd_get, so this gate never writes to a running connectd bridge.
|
||||||
|
#
|
||||||
|
# USAGE
|
||||||
|
# scripts/verify-soul-contract.sh <path-to-soul-binary> [port]
|
||||||
|
# exit 0 = all required routes answered AND no destructive engram mutation;
|
||||||
|
# non-zero = a route is missing (presence) or a mutation route hard-deletes.
|
||||||
|
set -uo pipefail
|
||||||
|
|
||||||
|
SOUL="${1:?usage: verify-soul-contract.sh <soul-binary> [port]}"
|
||||||
|
PORT="${2:-7799}"
|
||||||
|
|
||||||
|
if [ "$PORT" = "7770" ] || [ "$PORT" = "8742" ] || [ "$PORT" = "7771" ]; then
|
||||||
|
echo "REFUSING: port $PORT is a live service port. Use a throwaway port." >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
if [ ! -x "$SOUL" ]; then echo "not executable: $SOUL" >&2; exit 2; fi
|
||||||
|
|
||||||
|
BASE="http://127.0.0.1:$PORT"
|
||||||
|
THROW_HOME="$(mktemp -d "${TMPDIR:-/tmp}/soul-contract-home.XXXXXX")"
|
||||||
|
SOUL_LOG="$(mktemp "${TMPDIR:-/tmp}/soul-contract-log.XXXXXX")"
|
||||||
|
SOUL_PID=""
|
||||||
|
cleanup() {
|
||||||
|
[ -n "$SOUL_PID" ] && kill "$SOUL_PID" 2>/dev/null
|
||||||
|
[ -n "$SOUL_PID" ] && { sleep 0.3; kill -9 "$SOUL_PID" 2>/dev/null; }
|
||||||
|
rm -rf "$THROW_HOME" "$SOUL_LOG"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT INT TERM
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# THE CONTRACT — routes the app (neuron-ui/src/main/kotlin/ai/neuron/ui/*.kt)
|
||||||
|
# calls against the soul ($SOUL). Format: "METHOD PATH".
|
||||||
|
#
|
||||||
|
# EXCLUDED and why:
|
||||||
|
# /api/auth, /api/auth/status, /api/dispatch, /api/tasks
|
||||||
|
# -> served by the APP's own DispatchServer.kt (localhost:8080), not the
|
||||||
|
# soul. Not soul routes.
|
||||||
|
# /api/tags
|
||||||
|
# -> not handled by any soul .el (app-side/other). Pre-verified excluded.
|
||||||
|
# /api/neuron/, /api/neuron/node/, /api/connectors/ (bare prefixes)
|
||||||
|
# -> base-path string constants used to build the concrete routes below.
|
||||||
|
#
|
||||||
|
# KNOWN-PENDING (probed + reported, NON-blocking):
|
||||||
|
# POST /api/engram/import -> the app's "Restore memory" path. No soul handler
|
||||||
|
# yet, and the app hides Restore from shipped builds (B3, "lands in an
|
||||||
|
# update"). Reported so we see it; does not block packaging.
|
||||||
|
#
|
||||||
|
# Connectors sub-routes are listed as GET (see SAFETY note): handle_connectors is
|
||||||
|
# monolithic, so a GET reaching it proves the whole connectors surface without
|
||||||
|
# writing to the live bridge. Binary-strings cross-check confirms each POST
|
||||||
|
# sub-path literal is compiled in.
|
||||||
|
# =============================================================================
|
||||||
|
REQUIRED=(
|
||||||
|
"GET /api/graph/nodes"
|
||||||
|
"GET /api/graph/edges"
|
||||||
|
"POST /api/chat"
|
||||||
|
"GET /api/config"
|
||||||
|
"POST /api/see"
|
||||||
|
"GET /api/connectors"
|
||||||
|
"GET /api/connectors/add"
|
||||||
|
"GET /api/connectors/toggle"
|
||||||
|
"GET /api/connectors/auto-approve"
|
||||||
|
"GET /api/connectors/remove"
|
||||||
|
"GET /api/connectors/secret"
|
||||||
|
"GET /api/connectors/oauth/start"
|
||||||
|
"GET /api/connectors/call"
|
||||||
|
"POST /api/neuron/memory"
|
||||||
|
"POST /api/neuron/memory/update"
|
||||||
|
"POST /api/neuron/memory/delete"
|
||||||
|
"POST /api/neuron/node/create"
|
||||||
|
"POST /api/neuron/node/update"
|
||||||
|
"POST /api/neuron/node/delete"
|
||||||
|
"POST /api/neuron/knowledge/capture"
|
||||||
|
"POST /api/neuron/knowledge/evolve"
|
||||||
|
"POST /api/neuron/knowledge/promote"
|
||||||
|
"POST /api/neuron/processes/define"
|
||||||
|
"GET /api/run-progress/__contract_probe__"
|
||||||
|
"GET /api/safety-contact"
|
||||||
|
"POST /api/safety-contact"
|
||||||
|
"GET /api/sessions/__contract_probe__"
|
||||||
|
)
|
||||||
|
KNOWN_PENDING=(
|
||||||
|
"POST /api/engram/import"
|
||||||
|
)
|
||||||
|
|
||||||
|
# --- boot the soul -----------------------------------------------------------
|
||||||
|
# Preserve the ambient environment (PATH, LD_LIBRARY_PATH, TMPDIR) so the
|
||||||
|
# dynamically-linked soul finds its libs on any runner — using `env -i` here
|
||||||
|
# stripped the library path on the Linux CI runner and the soul never booted.
|
||||||
|
# Isolation is still guaranteed by UNSETTING the live-service vars (so it can
|
||||||
|
# never reach the real engram/axon or make an LLM call) and by pointing HOME +
|
||||||
|
# the snapshot at throwaway paths and the axon at a dead port.
|
||||||
|
echo "== booting soul: $SOUL on port $PORT (throwaway HOME=$THROW_HOME) =="
|
||||||
|
env \
|
||||||
|
-u ENGRAM_URL -u ENGRAM_API_KEY -u SOUL_ENGRAM_URL \
|
||||||
|
-u ANTHROPIC_API_KEY -u NEURON_LLM_API_KEY -u SOUL_IDENTITY \
|
||||||
|
HOME="$THROW_HOME" \
|
||||||
|
NEURON_PORT="$PORT" \
|
||||||
|
SOUL_CGI_ID="ntn-contract-$$" \
|
||||||
|
SOUL_ENGRAM_PATH="$THROW_HOME/throwaway-snapshot.json" \
|
||||||
|
NEURON_API_URL="http://127.0.0.1:9" \
|
||||||
|
SOUL_TICK_MS="3600000" SOUL_HEARTBEAT_MS="3600000" SOUL_REFRESH_MS="3600000" \
|
||||||
|
"$SOUL" >"$SOUL_LOG" 2>&1 &
|
||||||
|
SOUL_PID=$!
|
||||||
|
|
||||||
|
UP=0
|
||||||
|
for _ in $(seq 1 60); do
|
||||||
|
if ! kill -0 "$SOUL_PID" 2>/dev/null; then
|
||||||
|
echo "!! soul exited during boot. log tail:" >&2; tail -20 "$SOUL_LOG" >&2; exit 3
|
||||||
|
fi
|
||||||
|
RSS=$(ps -o rss= -p "$SOUL_PID" 2>/dev/null | tr -d ' ')
|
||||||
|
if [ -n "$RSS" ] && [ "$RSS" -gt $((3*1024*1024)) ]; then
|
||||||
|
echo "!! soul RSS >3GB — kill -9" >&2; kill -9 "$SOUL_PID" 2>/dev/null; exit 3
|
||||||
|
fi
|
||||||
|
[ "$(curl -s -o /dev/null -w '%{http_code}' -m 2 "$BASE/health" 2>/dev/null)" = "200" ] && { UP=1; break; }
|
||||||
|
sleep 0.5
|
||||||
|
done
|
||||||
|
[ "$UP" = 1 ] || { echo "!! soul never healthy on $BASE/health" >&2; tail -20 "$SOUL_LOG" >&2; exit 3; }
|
||||||
|
echo "== soul healthy =="; echo
|
||||||
|
|
||||||
|
# --- probing helpers ---------------------------------------------------------
|
||||||
|
# request METHOD PATH [BODY] -> prints response body (single line)
|
||||||
|
request() {
|
||||||
|
curl -s -m 12 -X "$1" -H 'Content-Type: application/json' --data "${3:-{}}" "$BASE$2" 2>/dev/null | tr -d '\n'
|
||||||
|
}
|
||||||
|
# is_missing BODY -> 0 if the body is a "route not present" signal
|
||||||
|
is_missing() {
|
||||||
|
printf '%s' "$1" | grep -qE '"error":"not found"|"code":"not_found"|no http handler registered|"code":"method_not_allowed"'
|
||||||
|
}
|
||||||
|
extract_id() { printf '%s' "$1" | grep -oE '"id":"[^"]+"' | head -1 | sed 's/.*"id":"//;s/"//'; }
|
||||||
|
node_present() { # id -> 0 if id appears in /api/graph/nodes
|
||||||
|
request GET /api/graph/nodes | grep -qF "\"$1\""
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- SECTION A: presence -----------------------------------------------------
|
||||||
|
run_presence() {
|
||||||
|
local -n arr=$1; local fail=0
|
||||||
|
printf ' %-8s %-42s %s\n' "METHOD" "ROUTE" "RESULT"
|
||||||
|
for e in "${arr[@]}"; do
|
||||||
|
local m p body; m=$(awk '{print $1}' <<<"$e"); p=$(awk '{print $2}' <<<"$e")
|
||||||
|
body=$(request "$m" "$p")
|
||||||
|
if is_missing "$body"; then
|
||||||
|
printf ' %-8s %-42s MISSING %s\n' "$m" "$p" "$(cut -c1-46 <<<"$body")"; fail=$((fail+1))
|
||||||
|
else
|
||||||
|
printf ' %-8s %-42s ANSWERED %s\n' "$m" "$p" "$(cut -c1-46 <<<"$body")"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return $fail
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "== SECTION A: PRESENCE (required, blocking) =="
|
||||||
|
run_presence REQUIRED; A_FAIL=$?
|
||||||
|
echo
|
||||||
|
echo "== KNOWN-PENDING (non-blocking) =="
|
||||||
|
run_presence KNOWN_PENDING; P_FAIL=$?
|
||||||
|
echo
|
||||||
|
|
||||||
|
# --- SECTION B: immutability (engram write routes must supersede, not destroy) --
|
||||||
|
# For each mutation route: create a node, mutate it, then check the ORIGINAL id
|
||||||
|
# still exists in the graph. KEPT = supersede/tombstone (correct). DESTROYED =
|
||||||
|
# hard delete (DEFECTIVE -> fail). N/A = mutate route absent (a presence failure).
|
||||||
|
# For "delete" mutations we additionally require a real tombstone marker
|
||||||
|
# (label "tombstone:<id>") so a no-op delete cannot false-pass as KEPT.
|
||||||
|
marker_present() { # id -> 0 if a "tombstone:<id>" marker exists (include_deleted view)
|
||||||
|
request GET "/api/graph/nodes?include_deleted=1" | grep -qF "tombstone:$1"
|
||||||
|
}
|
||||||
|
immut_check() { # label KIND(update|delete) CREATE_PATH MUTATE_PATH
|
||||||
|
local label="$1" kind="$2" create="$3" mutate="$4"
|
||||||
|
local cbody id mb mbody
|
||||||
|
cbody=$(request POST "$create" "{\"content\":\"__immut_${label}__\",\"node_type\":\"Memory\",\"label\":\"contract:immut\"}")
|
||||||
|
id=$(extract_id "$cbody")
|
||||||
|
if [ -z "$id" ]; then printf ' %-14s SKELETON-FAIL create returned no id: %s\n' "$label" "$(cut -c1-40 <<<"$cbody")"; return 2; fi
|
||||||
|
mb="{\"id\":\"$id\"}"; [ "$kind" = update ] && mb="{\"id\":\"$id\",\"content\":\"__immut_${label}_v2__\"}"
|
||||||
|
mbody=$(request POST "$mutate" "$mb")
|
||||||
|
if is_missing "$mbody"; then printf ' %-14s N/A mutate route absent (see Section A)\n' "$label"; return 0; fi
|
||||||
|
if ! node_present "$id"; then
|
||||||
|
printf ' %-14s DESTROYED original %s hard-removed <== DEFECTIVE\n' "$label" "$id"; return 1
|
||||||
|
fi
|
||||||
|
if [ "$kind" = delete ] && ! marker_present "$id"; then
|
||||||
|
printf ' %-14s NO-OP original %s kept but no tombstone marker <== DEFECTIVE\n' "$label" "$id"; return 1
|
||||||
|
fi
|
||||||
|
local how="supersede edge"; [ "$kind" = delete ] && how="tombstoned + hidden from default list"
|
||||||
|
printf ' %-14s KEPT original %s survived (%s)\n' "$label" "$id" "$how"; return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "== SECTION B: IMMUTABILITY (engram nodes must be superseded, never destroyed) =="
|
||||||
|
B_FAIL=0
|
||||||
|
immut_check "memory-update" update /api/neuron/memory /api/neuron/memory/update || B_FAIL=$((B_FAIL+$?))
|
||||||
|
immut_check "memory-delete" delete /api/neuron/memory /api/neuron/memory/delete || B_FAIL=$((B_FAIL+$?))
|
||||||
|
immut_check "node-update" update /api/neuron/node/create /api/neuron/node/update || B_FAIL=$((B_FAIL+$?))
|
||||||
|
immut_check "node-delete" delete /api/neuron/node/create /api/neuron/node/delete || B_FAIL=$((B_FAIL+$?))
|
||||||
|
immut_check "memory-forget" delete /api/neuron/memory /api/neuron/memory/forget || B_FAIL=$((B_FAIL+$?))
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo "============================================================"
|
||||||
|
RC=0
|
||||||
|
if [ "$A_FAIL" -gt 0 ]; then echo "PRESENCE: FAIL — $A_FAIL required route(s) unanswered. Do NOT package."; RC=1
|
||||||
|
else echo "PRESENCE: PASS — all ${#REQUIRED[@]} required routes answered."; fi
|
||||||
|
if [ "$B_FAIL" -gt 0 ]; then echo "IMMUTABILITY: FAIL — $B_FAIL engram write route(s) hard-delete. DEFECTIVE soul."; RC=1
|
||||||
|
else echo "IMMUTABILITY: PASS — no engram write route hard-deletes."; fi
|
||||||
|
[ "$P_FAIL" -gt 0 ] && echo "note: $P_FAIL known-pending route(s) unanswered (expected; non-blocking)."
|
||||||
|
echo "============================================================"
|
||||||
|
[ "$RC" = 0 ] && echo "GATE: PASS" || echo "GATE: FAIL"
|
||||||
|
exit $RC
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
# El Compiler Release v1.0.0 — 2026-05-02
|
||||||
|
|
||||||
|
## Components
|
||||||
|
- `bootstrap.py` — El language compiler (Python, recursive descent parser, emits C)
|
||||||
|
- `el_runtime.c` — El runtime (C, HTTP server, engram, DHARMA, LLM chain)
|
||||||
|
- `el_runtime.h` — Runtime public API header
|
||||||
|
|
||||||
|
## Changes in this release
|
||||||
|
|
||||||
|
### Critical bug fixes
|
||||||
|
- `state_set`/`state_get` are now thread-safe (pthread_mutex). Was racing across 64 worker threads.
|
||||||
|
- `looks_like_string` threshold raised from 1,000,000 to 4GB. Unix timestamps were being dereferenced as heap pointers.
|
||||||
|
- `fs_read` guards against negative `ftell` result (pipe/special file overflow).
|
||||||
|
|
||||||
|
### Engram architecture (major)
|
||||||
|
- Two-layer activation: `background_activation` (Layer 1, broad fan-out) + `working_memory_weight` (Layer 2, executive filter)
|
||||||
|
- Inhibitory edges: `EngramEdge.inhibitory` flag suppresses working memory promotion without affecting background activation
|
||||||
|
- Suppression memory: `suppression_count` — nodes activated-but-suppressed accumulate pressure toward breakthrough
|
||||||
|
- Temporal decay: `temporal_decay_rate`, `created_at`, `last_activated_at`, `activation_count` on EngramNode
|
||||||
|
- Per-type activation thresholds (Safety: 0.05, Canonical: 0.15, Lesson: 0.25, Note: 0.40)
|
||||||
|
- Temporal range query: `engram_query_range(start_ms, end_ms)`
|
||||||
|
- Layered consciousness: `EngramLayer` struct, `layer_id` on nodes and edges, `EngramStore.layers[]`
|
||||||
|
- Layer 0 override pass: safety layer fires last and cannot be suppressed
|
||||||
|
|
||||||
|
## SHA256
|
||||||
|
bootstrap.py
|
||||||
|
el_runtime.c
|
||||||
|
el_runtime.h
|
||||||
+11509
File diff suppressed because it is too large
Load Diff
+779
@@ -0,0 +1,779 @@
|
|||||||
|
/*
|
||||||
|
* el_runtime.h — El language C runtime header
|
||||||
|
*
|
||||||
|
* Declares all built-in functions available to compiled El programs.
|
||||||
|
* Include this in every generated .c file.
|
||||||
|
*
|
||||||
|
* Value model:
|
||||||
|
* All El values are represented as el_val_t (= int64_t).
|
||||||
|
* On 64-bit systems a pointer fits in int64_t.
|
||||||
|
* String values are cast: (el_val_t)(uintptr_t)"hello"
|
||||||
|
* Integer values are stored directly.
|
||||||
|
* This lets arithmetic work naturally while still passing strings around.
|
||||||
|
*
|
||||||
|
* Type conventions (El -> C):
|
||||||
|
* String -> el_val_t (holds const char* via uintptr_t cast)
|
||||||
|
* Int -> el_val_t
|
||||||
|
* Bool -> el_val_t (0 = false, nonzero = true)
|
||||||
|
* Any -> el_val_t
|
||||||
|
* Void -> void
|
||||||
|
*
|
||||||
|
* Macros for convenience:
|
||||||
|
* EL_STR(s) cast string literal to el_val_t
|
||||||
|
* EL_CSTR(v) cast el_val_t back to const char*
|
||||||
|
* EL_INT(v) identity — el_val_t is already int64_t
|
||||||
|
*
|
||||||
|
* Link requirements:
|
||||||
|
* -lcurl — required for the HTTP client (http_get, http_post, llm_*).
|
||||||
|
* -lpthread — required for the HTTP server (one detached thread per
|
||||||
|
* connection, capped at 64 concurrent).
|
||||||
|
* -loqs — optional; required only when liboqs is installed and the
|
||||||
|
* pq_* / sha3_256_hex entry points are needed. Detected at
|
||||||
|
* compile time via __has_include(<oqs/oqs.h>).
|
||||||
|
* -lcrypto — optional; pulled in alongside -loqs. Used for X25519 in
|
||||||
|
* pq_hybrid_* and HKDF-SHA256 derivation.
|
||||||
|
*
|
||||||
|
* Canonical compile command:
|
||||||
|
* cc -std=c11 -I el-compiler/runtime -lcurl -lpthread \
|
||||||
|
* -o <out> <prog>.c el-compiler/runtime/el_runtime.c
|
||||||
|
*
|
||||||
|
* With liboqs (post-quantum stack):
|
||||||
|
* cc -std=c11 -I el-compiler/runtime -lcurl -lpthread -loqs -lcrypto \
|
||||||
|
* -o <out> <prog>.c el-compiler/runtime/el_runtime.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
typedef int64_t el_val_t;
|
||||||
|
|
||||||
|
#define EL_STR(s) ((el_val_t)(uintptr_t)(s))
|
||||||
|
#define EL_CSTR(v) ((const char*)(uintptr_t)(v))
|
||||||
|
#define EL_INT(v) (v)
|
||||||
|
#define EL_NULL ((el_val_t)0)
|
||||||
|
|
||||||
|
/* Float values share the el_val_t (int64) slot via a bit-cast.
|
||||||
|
* The codegen emits Float literals as `el_from_float(<dbl>)` so the
|
||||||
|
* underlying bits represent the IEEE 754 double. Float-aware builtins
|
||||||
|
* (math, format, json) round-trip via these helpers. */
|
||||||
|
static inline double el_to_float(el_val_t v) {
|
||||||
|
union { int64_t i; double f; } u;
|
||||||
|
u.i = (int64_t)v;
|
||||||
|
return u.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline el_val_t el_from_float(double f) {
|
||||||
|
union { double f; int64_t i; } u;
|
||||||
|
u.f = f;
|
||||||
|
return (el_val_t)u.i;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ── I/O ──────────────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
void println(el_val_t s);
|
||||||
|
void print(el_val_t s);
|
||||||
|
el_val_t readline(void);
|
||||||
|
|
||||||
|
/* ── String builtins ─────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t el_str_concat(el_val_t a, el_val_t b);
|
||||||
|
el_val_t str_eq(el_val_t a, el_val_t b);
|
||||||
|
el_val_t str_starts_with(el_val_t s, el_val_t prefix);
|
||||||
|
el_val_t str_ends_with(el_val_t s, el_val_t suffix);
|
||||||
|
el_val_t str_len(el_val_t s);
|
||||||
|
el_val_t str_concat(el_val_t a, el_val_t b);
|
||||||
|
el_val_t int_to_str(el_val_t n);
|
||||||
|
el_val_t str_to_int(el_val_t s);
|
||||||
|
el_val_t str_slice(el_val_t s, el_val_t start, el_val_t end);
|
||||||
|
el_val_t str_contains(el_val_t s, el_val_t sub);
|
||||||
|
el_val_t str_replace(el_val_t s, el_val_t from, el_val_t to);
|
||||||
|
el_val_t str_to_upper(el_val_t s);
|
||||||
|
el_val_t str_to_lower(el_val_t s);
|
||||||
|
el_val_t str_trim(el_val_t s);
|
||||||
|
|
||||||
|
/* ── Math ────────────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t el_abs(el_val_t n);
|
||||||
|
el_val_t el_max(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_min(el_val_t a, el_val_t b);
|
||||||
|
|
||||||
|
/* ── Refcount (ARC) ──────────────────────────────────────────────────────────
|
||||||
|
* Lists and Maps carry a refcount. Strings and ints do not — el_retain and
|
||||||
|
* el_release are safe no-ops on non-refcounted values (they sniff a magic
|
||||||
|
* header at offset 0 and only act if the magic matches).
|
||||||
|
*
|
||||||
|
* Codegen emits these at let-binding shadowing, function entry (params), and
|
||||||
|
* function exit (locals other than the returned value). The refcount lets
|
||||||
|
* el_list_append and el_map_set mutate in place when uniquely owned (cheap)
|
||||||
|
* and copy-on-write when shared (preserves persistent semantics across
|
||||||
|
* accumulator patterns in the compiler itself). */
|
||||||
|
|
||||||
|
void el_retain(el_val_t v);
|
||||||
|
void el_release(el_val_t v);
|
||||||
|
|
||||||
|
/* ── Arena scoping ────────────────────────────────────────────────────────────
|
||||||
|
* el_arena_push() activates the string arena (if not already active) and
|
||||||
|
* returns a mark; el_arena_pop(mark) frees all strings allocated since that
|
||||||
|
* mark. Used by codegen for per-function/statement scoping and by long-running
|
||||||
|
* EL loops (e.g. the soul daemon's awareness tick) to reclaim per-iteration
|
||||||
|
* allocations. */
|
||||||
|
el_val_t el_arena_push(void);
|
||||||
|
el_val_t el_arena_pop(el_val_t mark);
|
||||||
|
|
||||||
|
/* ── List ────────────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t el_list_new(el_val_t count, ...);
|
||||||
|
el_val_t el_list_len(el_val_t list);
|
||||||
|
el_val_t el_list_get(el_val_t list, el_val_t index);
|
||||||
|
el_val_t el_list_append(el_val_t list, el_val_t elem);
|
||||||
|
el_val_t el_list_empty(void);
|
||||||
|
el_val_t el_list_clone(el_val_t list);
|
||||||
|
|
||||||
|
/* ── Map ─────────────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t el_map_new(el_val_t pair_count, ...);
|
||||||
|
el_val_t el_get_field(el_val_t map, el_val_t key);
|
||||||
|
el_val_t el_map_get(el_val_t map, el_val_t key);
|
||||||
|
el_val_t el_map_set(el_val_t map, el_val_t key, el_val_t value);
|
||||||
|
|
||||||
|
/* ── HTTP ─────────────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t http_get(el_val_t url);
|
||||||
|
el_val_t http_post(el_val_t url, el_val_t body);
|
||||||
|
el_val_t http_post_json(el_val_t url, el_val_t json_body);
|
||||||
|
el_val_t http_get_with_headers(el_val_t url, el_val_t headers_map);
|
||||||
|
el_val_t http_post_with_headers(el_val_t url, el_val_t body, el_val_t headers_map);
|
||||||
|
el_val_t http_post_form_auth(el_val_t url, el_val_t form_body, el_val_t auth_header);
|
||||||
|
el_val_t http_delete(el_val_t url);
|
||||||
|
void http_serve(el_val_t port, el_val_t handler);
|
||||||
|
void http_set_handler(el_val_t name);
|
||||||
|
|
||||||
|
/* HTTP server v2 ─────────────────────────────────────────────────────────────
|
||||||
|
* Same dispatch model as http_serve, but the handler signature is widened:
|
||||||
|
*
|
||||||
|
* el_val_t handler(method, path, headers_map, body)
|
||||||
|
*
|
||||||
|
* `headers_map` is an ElMap from lowercased header name → header value (both
|
||||||
|
* Strings). Repeated headers are joined with ", " per RFC 7230.
|
||||||
|
*
|
||||||
|
* Response value: the handler may return either
|
||||||
|
* (a) a plain body string — same auto-content-type / 200-OK behaviour as
|
||||||
|
* http_serve (3-arg) — or
|
||||||
|
* (b) a response envelope built with `http_response(status, headers_json,
|
||||||
|
* body)`. The runtime detects the envelope discriminator
|
||||||
|
* `"el_http_response":1` at the start of the returned string and
|
||||||
|
* unpacks status / headers / body before sending.
|
||||||
|
*
|
||||||
|
* The 3-arg http_serve(port, handler) remains supported unchanged for
|
||||||
|
* existing handlers (e.g. products/web/server.el): it dispatches with
|
||||||
|
* (method, path, body), hardcodes 200 OK, and auto-detects content type. */
|
||||||
|
void http_serve_v2(el_val_t port, el_val_t handler);
|
||||||
|
void http_set_handler_v2(el_val_t name);
|
||||||
|
|
||||||
|
/* Non-blocking variant of http_serve: runs the accept loop in a background
|
||||||
|
* pthread and returns immediately so the caller can continue (used by the
|
||||||
|
* soul daemon to run awareness_run() after starting its HTTP API). */
|
||||||
|
void http_serve_async(el_val_t port, el_val_t handler);
|
||||||
|
|
||||||
|
/* Build an HTTP response envelope. `headers_json` should be a JSON object
|
||||||
|
* literal like `{"WWW-Authenticate":"Basic"}` (or "" / "{}" for none). The
|
||||||
|
* returned string carries the discriminator `{"el_http_response":1,...}`
|
||||||
|
* which the runtime's send-path detects and unpacks. Detection happens
|
||||||
|
* uniformly inside http_send_response, so a 3-arg handler may also return
|
||||||
|
* an envelope. The 3-arg variant remains documented as a fixed 200-OK
|
||||||
|
* auto-content-type contract for legacy handlers that return plain bodies. */
|
||||||
|
el_val_t http_response(el_val_t status, el_val_t headers_json, el_val_t body);
|
||||||
|
|
||||||
|
/* HTTP timeout — every libcurl request honors EL_HTTP_TIMEOUT_MS (default
|
||||||
|
* 60000ms). Read lazily on first use, so setting the env var any time before
|
||||||
|
* the first http_* call is sufficient. */
|
||||||
|
|
||||||
|
/* Streaming variants — write the response body straight to a file via
|
||||||
|
* libcurl's CURLOPT_WRITEFUNCTION = fwrite. These bypass the el_val_t string
|
||||||
|
* wrapper entirely, so binary payloads (audio/mpeg, image/png, etc.) survive
|
||||||
|
* embedded NUL bytes that would truncate a strlen()-based code path.
|
||||||
|
*
|
||||||
|
* Both honor EL_HTTP_TIMEOUT_MS, follow redirects, and accept the same
|
||||||
|
* `headers_map` shape as http_post_with_headers (ElMap of String→String).
|
||||||
|
*
|
||||||
|
* Return value: 1 on success (file fully written), 0 on any failure
|
||||||
|
* (network, file open, partial write). On failure the output file is removed
|
||||||
|
* so callers cannot mistake a partially-written file for a valid one. */
|
||||||
|
el_val_t http_post_to_file(el_val_t url, el_val_t body, el_val_t headers_map, el_val_t output_path);
|
||||||
|
el_val_t http_get_to_file(el_val_t url, el_val_t headers_map, el_val_t output_path);
|
||||||
|
|
||||||
|
/* ── URL encoding ────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t url_encode(el_val_t s); /* RFC 3986 unreserved set */
|
||||||
|
el_val_t url_decode(el_val_t s); /* '+' → space, %XX → byte */
|
||||||
|
|
||||||
|
/* ── HTML allowlist sanitizer ────────────────────────────────────────────────
|
||||||
|
* el_html_sanitize(input_html, allowlist_json) — strict allowlist HTML
|
||||||
|
* cleaner. State-machine parser; tag/attribute names compared case-
|
||||||
|
* insensitively against the allowlist; `<a href>` / `<… src>` URL schemes
|
||||||
|
* validated (http, https, mailto, fragment-only, or relative); whole-
|
||||||
|
* subtree drop for script / style / iframe / object / embed / form; HTML-
|
||||||
|
* escapes free text outside dropped subtrees.
|
||||||
|
*
|
||||||
|
* The allowlist is JSON of the form
|
||||||
|
* {"p":[],"a":["href","title"],"strong":[],...}
|
||||||
|
* where each value is the array of attribute names allowed for that tag. */
|
||||||
|
el_val_t el_html_sanitize(el_val_t input_html, el_val_t allowlist_json);
|
||||||
|
|
||||||
|
/* ── Filesystem ──────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t fs_read(el_val_t path);
|
||||||
|
el_val_t fs_write(el_val_t path, el_val_t content);
|
||||||
|
el_val_t fs_list(el_val_t path);
|
||||||
|
el_val_t fs_exists(el_val_t path);
|
||||||
|
el_val_t fs_mkdir(el_val_t path); /* mkdir -p, mode 0755 */
|
||||||
|
|
||||||
|
/* Length-explicit binary write. `length` is an Int (el_val_t holding the
|
||||||
|
* byte count). The caller knows the length from context — typically because
|
||||||
|
* `bytes` came from base64_decode (which produces a magic-tagged binary
|
||||||
|
* buffer with embedded NULs possible) and the caller already tracks the
|
||||||
|
* decoded length, OR because the bytes came from a fixed-size source
|
||||||
|
* (sha256_bytes = 32, hmac_sha256_bytes = 32). Bypasses strlen entirely.
|
||||||
|
*
|
||||||
|
* Returns 1 on success, 0 on failure (invalid path, can't open, partial
|
||||||
|
* write, negative length). On partial-write failure, the file is removed
|
||||||
|
* so callers cannot read back a truncated artefact. */
|
||||||
|
el_val_t fs_write_bytes(el_val_t path, el_val_t bytes, el_val_t length);
|
||||||
|
|
||||||
|
/* ── JSON ────────────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t json_get(el_val_t json, el_val_t key);
|
||||||
|
el_val_t json_parse(el_val_t s);
|
||||||
|
el_val_t json_stringify(el_val_t v);
|
||||||
|
el_val_t json_get_string(el_val_t json_str, el_val_t key);
|
||||||
|
el_val_t json_get_int(el_val_t json_str, el_val_t key);
|
||||||
|
el_val_t json_get_float(el_val_t json_str, el_val_t key);
|
||||||
|
el_val_t json_get_bool(el_val_t json_str, el_val_t key);
|
||||||
|
el_val_t json_get_raw(el_val_t json_str, el_val_t key);
|
||||||
|
el_val_t json_set(el_val_t json_str, el_val_t key, el_val_t value);
|
||||||
|
el_val_t json_array_len(el_val_t json_str);
|
||||||
|
el_val_t json_array_get(el_val_t json_str, el_val_t index);
|
||||||
|
el_val_t json_array_get_string(el_val_t json_str, el_val_t index);
|
||||||
|
|
||||||
|
/* ── Time ────────────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t time_now(void);
|
||||||
|
el_val_t time_now_utc(void);
|
||||||
|
el_val_t sleep_secs(el_val_t secs);
|
||||||
|
el_val_t sleep_ms(el_val_t ms);
|
||||||
|
el_val_t time_format(el_val_t ts, el_val_t fmt);
|
||||||
|
el_val_t time_to_parts(el_val_t ts);
|
||||||
|
el_val_t time_from_parts(el_val_t secs, el_val_t ns, el_val_t tz);
|
||||||
|
el_val_t time_add(el_val_t ts, el_val_t n, el_val_t unit);
|
||||||
|
el_val_t time_diff(el_val_t ts1, el_val_t ts2, el_val_t unit);
|
||||||
|
|
||||||
|
/* ── Instant + Duration: first-class temporal types ──────────────────────────
|
||||||
|
* Both types share the el_val_t (int64) slot. Instants are nanoseconds
|
||||||
|
* since the Unix epoch; Durations are signed nanoseconds. Type discipline
|
||||||
|
* is enforced at codegen-time: BinOps on names registered as Instant or
|
||||||
|
* Duration route through the typed wrappers below; mismatches like
|
||||||
|
* Instant+Instant become #error at the C compiler.
|
||||||
|
*
|
||||||
|
* Postfix literals — `30.seconds`, `1.hour`, `500.millis`, `30.nanos` — are
|
||||||
|
* recognised by the parser as DurationLit AST nodes and lowered to literal
|
||||||
|
* int64 nanoseconds at codegen time. The runtime never sees the units. */
|
||||||
|
|
||||||
|
el_val_t el_now_instant(void);
|
||||||
|
el_val_t now(void);
|
||||||
|
el_val_t unix_seconds(el_val_t n);
|
||||||
|
el_val_t unix_millis(el_val_t n);
|
||||||
|
el_val_t instant_from_iso8601(el_val_t s);
|
||||||
|
|
||||||
|
el_val_t el_duration_from_nanos(el_val_t ns);
|
||||||
|
el_val_t duration_seconds(el_val_t n);
|
||||||
|
el_val_t duration_millis(el_val_t n);
|
||||||
|
el_val_t duration_nanos(el_val_t n);
|
||||||
|
|
||||||
|
el_val_t el_instant_add_dur(el_val_t inst, el_val_t dur);
|
||||||
|
el_val_t el_instant_sub_dur(el_val_t inst, el_val_t dur);
|
||||||
|
el_val_t el_instant_diff(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_duration_add(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_duration_sub(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_duration_scale(el_val_t dur, el_val_t scalar);
|
||||||
|
el_val_t el_duration_div(el_val_t dur, el_val_t scalar);
|
||||||
|
|
||||||
|
el_val_t el_instant_lt(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_instant_le(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_instant_gt(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_instant_ge(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_instant_eq(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_instant_ne(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_duration_lt(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_duration_le(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_duration_gt(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_duration_ge(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_duration_eq(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_duration_ne(el_val_t a, el_val_t b);
|
||||||
|
|
||||||
|
el_val_t instant_to_unix_seconds(el_val_t i);
|
||||||
|
el_val_t instant_to_unix_millis(el_val_t i);
|
||||||
|
el_val_t instant_to_iso8601(el_val_t i);
|
||||||
|
el_val_t duration_to_seconds(el_val_t d);
|
||||||
|
el_val_t duration_to_millis(el_val_t d);
|
||||||
|
el_val_t duration_to_nanos(el_val_t d);
|
||||||
|
|
||||||
|
el_val_t el_sleep_duration(el_val_t dur);
|
||||||
|
el_val_t unix_timestamp(void);
|
||||||
|
|
||||||
|
el_val_t ttl_cache_set(el_val_t key, el_val_t value);
|
||||||
|
el_val_t ttl_cache_get(el_val_t key, el_val_t max_age);
|
||||||
|
el_val_t ttl_cache_age(el_val_t key);
|
||||||
|
|
||||||
|
/* ── Calendar + CalendarTime + Rhythm + LocalDate/Time/DateTime ─────────────
|
||||||
|
* Phase 1.5 of the time system. Calendar is pluggable: EarthCalendar (IANA
|
||||||
|
* zones, Gregorian, DST) is the user-facing default; MarsCalendar,
|
||||||
|
* CycleCalendar(period), NoCycleCalendar, RelativeCalendar handle non-Earth
|
||||||
|
* domains.
|
||||||
|
*
|
||||||
|
* A Calendar interprets an Instant under a particular cycle convention and
|
||||||
|
* produces a CalendarTime. CalendarTime carries the underlying Instant and
|
||||||
|
* a back-pointer to its Calendar; arithmetic and formatting consult the
|
||||||
|
* Calendar to convert ns since epoch into year/month/day/hour/minute/second
|
||||||
|
* (or sol/phase, or cycle/phase, depending on kind).
|
||||||
|
*
|
||||||
|
* Storage convention: Calendar / CalendarTime / Rhythm / LocalDate /
|
||||||
|
* LocalDateTime are heap-allocated structs whose pointers are cast into
|
||||||
|
* el_val_t. A 24-bit magic header at offset 0 lets the runtime identify
|
||||||
|
* the kind safely. LocalTime is small enough to live in the int64 slot
|
||||||
|
* directly (nanos since midnight, signed). */
|
||||||
|
|
||||||
|
/* Zone — opaque IANA zone or fixed offset, used by EarthCalendar.
|
||||||
|
* `zone_id` is either an IANA name ("America/New_York", "UTC") or a fixed
|
||||||
|
* offset string ("+05:30", "-08:00"). The runtime resolves it via tzset()
|
||||||
|
* on first use of the owning EarthCalendar. */
|
||||||
|
el_val_t zone(el_val_t id);
|
||||||
|
el_val_t zone_utc(void);
|
||||||
|
el_val_t zone_local(void);
|
||||||
|
el_val_t zone_offset(el_val_t hours, el_val_t minutes);
|
||||||
|
|
||||||
|
/* Calendar constructors. Each returns an el_val_t pointer to a heap-
|
||||||
|
* allocated, magic-tagged Calendar struct. Calendars are interned by
|
||||||
|
* (kind, zone_id, period_ns, epoch_ns) so identical constructors return
|
||||||
|
* the same pointer — equality is reference equality. */
|
||||||
|
el_val_t earth_calendar(el_val_t z);
|
||||||
|
el_val_t earth_calendar_default(void);
|
||||||
|
el_val_t mars_calendar(void);
|
||||||
|
el_val_t cycle_calendar(el_val_t period_dur);
|
||||||
|
el_val_t no_cycle_calendar(void);
|
||||||
|
el_val_t relative_calendar(el_val_t epoch_inst);
|
||||||
|
|
||||||
|
/* CalendarTime constructors and methods. Returns a heap-allocated struct
|
||||||
|
* whose pointer fits in el_val_t. */
|
||||||
|
el_val_t now_in(el_val_t cal);
|
||||||
|
el_val_t in_calendar(el_val_t inst, el_val_t cal);
|
||||||
|
el_val_t cal_format(el_val_t ct, el_val_t pattern);
|
||||||
|
el_val_t cal_to_instant(el_val_t ct);
|
||||||
|
el_val_t cal_cycle_phase(el_val_t ct);
|
||||||
|
el_val_t cal_in(el_val_t ct, el_val_t cal);
|
||||||
|
|
||||||
|
/* LocalDate / LocalTime / LocalDateTime — calendar-agnostic value types.
|
||||||
|
* LocalTime carries nanoseconds since midnight as a signed int64 directly
|
||||||
|
* in the el_val_t slot (no allocation). LocalDate / LocalDateTime are
|
||||||
|
* heap-allocated structs with magic headers. */
|
||||||
|
el_val_t local_date(el_val_t y, el_val_t m, el_val_t d);
|
||||||
|
el_val_t local_time(el_val_t h, el_val_t m, el_val_t s, el_val_t ns);
|
||||||
|
el_val_t local_datetime(el_val_t date, el_val_t time);
|
||||||
|
el_val_t zoned(el_val_t date, el_val_t time, el_val_t cal);
|
||||||
|
|
||||||
|
el_val_t local_date_year(el_val_t ld);
|
||||||
|
el_val_t local_date_month(el_val_t ld);
|
||||||
|
el_val_t local_date_day(el_val_t ld);
|
||||||
|
el_val_t local_time_hour(el_val_t lt);
|
||||||
|
el_val_t local_time_minute(el_val_t lt);
|
||||||
|
el_val_t local_time_second(el_val_t lt);
|
||||||
|
el_val_t local_time_nanos(el_val_t lt);
|
||||||
|
|
||||||
|
el_val_t el_local_date_add_dur(el_val_t ld, el_val_t dur);
|
||||||
|
el_val_t el_local_time_add_dur(el_val_t lt, el_val_t dur);
|
||||||
|
el_val_t el_local_date_lt(el_val_t a, el_val_t b);
|
||||||
|
el_val_t el_local_date_eq(el_val_t a, el_val_t b);
|
||||||
|
|
||||||
|
/* Rhythm — pluggable recurrence AST. Returns a heap-allocated struct
|
||||||
|
* pointer in el_val_t; rhythms are immutable so callers may share them. */
|
||||||
|
el_val_t rhythm_cycle_start(void);
|
||||||
|
el_val_t rhythm_cycle_phase(el_val_t phase);
|
||||||
|
el_val_t rhythm_duration(el_val_t d);
|
||||||
|
el_val_t rhythm_session_start(void);
|
||||||
|
el_val_t rhythm_event(el_val_t name);
|
||||||
|
el_val_t rhythm_and(el_val_t a, el_val_t b);
|
||||||
|
el_val_t rhythm_or(el_val_t a, el_val_t b);
|
||||||
|
el_val_t rhythm_weekday(el_val_t day);
|
||||||
|
el_val_t rhythm_weekly_at(el_val_t day, el_val_t hour, el_val_t minute);
|
||||||
|
el_val_t rhythm_next_after(el_val_t r, el_val_t after, el_val_t cal);
|
||||||
|
el_val_t rhythm_matches(el_val_t r, el_val_t ct);
|
||||||
|
|
||||||
|
/* ── UUID ────────────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t uuid_new(void);
|
||||||
|
el_val_t uuid_v4(void);
|
||||||
|
|
||||||
|
/* ── Environment ─────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t env(el_val_t key);
|
||||||
|
|
||||||
|
/* ── In-process state K/V ────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t state_set(el_val_t key, el_val_t value);
|
||||||
|
el_val_t state_get(el_val_t key);
|
||||||
|
el_val_t state_del(el_val_t key);
|
||||||
|
el_val_t state_keys(void);
|
||||||
|
|
||||||
|
/* ── Float formatting ────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t float_to_str(el_val_t f);
|
||||||
|
el_val_t int_to_float(el_val_t n);
|
||||||
|
el_val_t float_to_int(el_val_t f);
|
||||||
|
el_val_t format_float(el_val_t f, el_val_t decimals);
|
||||||
|
el_val_t decimal_round(el_val_t f, el_val_t decimals);
|
||||||
|
el_val_t str_to_float(el_val_t s);
|
||||||
|
|
||||||
|
/* ── Math (Float-aware) ──────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t math_sqrt(el_val_t f);
|
||||||
|
el_val_t math_log(el_val_t f);
|
||||||
|
el_val_t math_ln(el_val_t f);
|
||||||
|
el_val_t math_sin(el_val_t f);
|
||||||
|
el_val_t math_cos(el_val_t f);
|
||||||
|
el_val_t math_pi(void);
|
||||||
|
|
||||||
|
/* ── String additions ────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t str_index_of(el_val_t s, el_val_t sub);
|
||||||
|
el_val_t str_split(el_val_t s, el_val_t sep);
|
||||||
|
el_val_t str_char_at(el_val_t s, el_val_t i);
|
||||||
|
el_val_t str_char_code(el_val_t s, el_val_t i);
|
||||||
|
el_val_t str_pad_left(el_val_t s, el_val_t width, el_val_t pad);
|
||||||
|
el_val_t str_pad_right(el_val_t s, el_val_t width, el_val_t pad);
|
||||||
|
el_val_t str_format(el_val_t fmt, el_val_t data);
|
||||||
|
el_val_t str_lower(el_val_t s);
|
||||||
|
el_val_t str_upper(el_val_t s);
|
||||||
|
|
||||||
|
/* ── Text-processing primitives (Phase 1: byte/codepoint, ASCII char classes)
|
||||||
|
* Phase 2 (filed): Unicode-grapheme awareness, NFC/NFD normalization, regex.
|
||||||
|
* is_* predicates: empty input returns false; multi-char requires ALL bytes
|
||||||
|
* to match. ASCII ranges only in Phase 1. */
|
||||||
|
|
||||||
|
/* Counting */
|
||||||
|
el_val_t str_count(el_val_t s, el_val_t sub); /* non-overlapping */
|
||||||
|
el_val_t str_count_chars(el_val_t s); /* codepoint count */
|
||||||
|
el_val_t str_count_bytes(el_val_t s); /* alias of str_len */
|
||||||
|
el_val_t str_count_lines(el_val_t s);
|
||||||
|
el_val_t str_count_words(el_val_t s);
|
||||||
|
el_val_t str_count_letters(el_val_t s); /* ASCII [A-Za-z] */
|
||||||
|
el_val_t str_count_digits(el_val_t s); /* ASCII [0-9] */
|
||||||
|
|
||||||
|
/* Find / position */
|
||||||
|
el_val_t str_index_of_all(el_val_t s, el_val_t sub); /* [Int] of byte offsets */
|
||||||
|
el_val_t str_last_index_of(el_val_t s, el_val_t sub);
|
||||||
|
el_val_t str_find_chars(el_val_t s, el_val_t any_of); /* first idx of any ch */
|
||||||
|
|
||||||
|
/* Transform */
|
||||||
|
el_val_t str_repeat(el_val_t s, el_val_t n);
|
||||||
|
el_val_t str_reverse(el_val_t s); /* by codepoint */
|
||||||
|
el_val_t str_strip_prefix(el_val_t s, el_val_t prefix);
|
||||||
|
el_val_t str_strip_suffix(el_val_t s, el_val_t suffix);
|
||||||
|
el_val_t str_strip_chars(el_val_t s, el_val_t chars);
|
||||||
|
el_val_t str_lstrip(el_val_t s);
|
||||||
|
el_val_t str_rstrip(el_val_t s);
|
||||||
|
|
||||||
|
/* Char classification (Bool) */
|
||||||
|
el_val_t is_letter(el_val_t s);
|
||||||
|
el_val_t is_digit(el_val_t s);
|
||||||
|
el_val_t is_alphanumeric(el_val_t s);
|
||||||
|
el_val_t is_whitespace(el_val_t s);
|
||||||
|
el_val_t is_punctuation(el_val_t s);
|
||||||
|
el_val_t is_uppercase(el_val_t s);
|
||||||
|
el_val_t is_lowercase(el_val_t s);
|
||||||
|
|
||||||
|
/* Split / join */
|
||||||
|
el_val_t str_split_lines(el_val_t s);
|
||||||
|
el_val_t str_split_chars(el_val_t s); /* alias of native_string_chars */
|
||||||
|
el_val_t str_split_n(el_val_t s, el_val_t sep, el_val_t n);
|
||||||
|
el_val_t str_join(el_val_t list, el_val_t sep); /* alias of list_join */
|
||||||
|
|
||||||
|
/* ── List additions ──────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t list_push(el_val_t list, el_val_t elem);
|
||||||
|
el_val_t list_push_front(el_val_t list, el_val_t elem);
|
||||||
|
el_val_t list_join(el_val_t list, el_val_t sep);
|
||||||
|
el_val_t list_range(el_val_t start, el_val_t end);
|
||||||
|
|
||||||
|
/* ── Bool helpers ────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t bool_to_str(el_val_t b);
|
||||||
|
|
||||||
|
/* ── Numeric parsing ─────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
el_val_t parse_int(el_val_t s, el_val_t default_val);
|
||||||
|
|
||||||
|
/* ── Process ─────────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
void exit_program(el_val_t code);
|
||||||
|
el_val_t getpid_now(void);
|
||||||
|
|
||||||
|
/* ── CGI identity ─────────────────────────────────────────────────────────────
|
||||||
|
* Called at the start of main() in CGI programs (those with a `cgi {}` block).
|
||||||
|
* Records the program's DHARMA identity before any other code executes. */
|
||||||
|
|
||||||
|
void el_cgi_init(el_val_t name, el_val_t dharma_id, el_val_t principal,
|
||||||
|
el_val_t network, el_val_t engram);
|
||||||
|
|
||||||
|
/* ── DHARMA network builtins ─────────────────────────────────────────────────
|
||||||
|
* Available to CGI programs (declared with a `cgi {}` block).
|
||||||
|
*
|
||||||
|
* Peers are addressed by `dharma_id` of the form
|
||||||
|
* "<registry-id>@<transport-url>" e.g. "ntn-genesis@http://localhost:7770"
|
||||||
|
* If the @<url> portion is omitted, transport defaults to
|
||||||
|
* "http://localhost:7770" (the local CGI daemon assumption).
|
||||||
|
*
|
||||||
|
* Wire protocol (all peers expose):
|
||||||
|
* POST <url>/dharma/recv { channel, from, content } → response body
|
||||||
|
* POST <url>/dharma/event { type, payload, source, timestamp }
|
||||||
|
* POST <url>/api/activate { query } → list of nodes
|
||||||
|
*
|
||||||
|
* Hosting application's responsibility: an El program with a `cgi {}` block
|
||||||
|
* runs http_serve() with its own request handler; that handler should route
|
||||||
|
* "/dharma/event" requests by calling el_runtime_dharma_event_arrive() so
|
||||||
|
* incoming events feed dharma_field() queues. The runtime itself does not
|
||||||
|
* intercept any /dharma path. */
|
||||||
|
|
||||||
|
el_val_t dharma_connect(el_val_t cgi_id);
|
||||||
|
el_val_t dharma_send(el_val_t channel, el_val_t content);
|
||||||
|
el_val_t dharma_activate(el_val_t query);
|
||||||
|
void dharma_emit(el_val_t event_type, el_val_t payload);
|
||||||
|
el_val_t dharma_field(el_val_t event_type);
|
||||||
|
void dharma_strengthen(el_val_t cgi_id, el_val_t weight);
|
||||||
|
el_val_t dharma_relationship(el_val_t cgi_id);
|
||||||
|
el_val_t dharma_peers(void);
|
||||||
|
|
||||||
|
/* Public C API: called by an El program's HTTP handler when a /dharma/event
|
||||||
|
* request arrives. Pushes onto the per-event-type queue and signals any
|
||||||
|
* pending dharma_field() blockers. All three arguments must be NUL-terminated
|
||||||
|
* C strings (or NULL — then treated as empty). */
|
||||||
|
void el_runtime_dharma_event_arrive(const char* event_type,
|
||||||
|
const char* payload,
|
||||||
|
const char* source);
|
||||||
|
|
||||||
|
/* ── Engram local graph primitives ───────────────────────────────────────────
|
||||||
|
* Operate on the CGI's local Engram knowledge graph.
|
||||||
|
* `engram_activate` queries the local graph only; `dharma_activate` is
|
||||||
|
* network-wide across all connected CGI graphs. */
|
||||||
|
|
||||||
|
el_val_t engram_node(el_val_t content, el_val_t node_type, el_val_t salience);
|
||||||
|
el_val_t engram_node_full(el_val_t content, el_val_t node_type, el_val_t label,
|
||||||
|
el_val_t salience, el_val_t importance, el_val_t confidence,
|
||||||
|
el_val_t tier, el_val_t tags);
|
||||||
|
/* Layered consciousness — see el_runtime.c for the layered architecture
|
||||||
|
* design notes (search "Layered consciousness architecture"). The five
|
||||||
|
* canonical layers (safety / core-identity / domain-knowledge / imprint /
|
||||||
|
* suit) are seeded automatically; engram_add_layer extends the registry
|
||||||
|
* with imprint or suit overlays at runtime. Nodes default to layer 1
|
||||||
|
* (core-identity) when created via engram_node / engram_node_full. */
|
||||||
|
el_val_t engram_node_layered(el_val_t content, el_val_t node_type, el_val_t label,
|
||||||
|
el_val_t salience, el_val_t certainty, el_val_t confidence,
|
||||||
|
el_val_t status, el_val_t tags, el_val_t layer_id);
|
||||||
|
el_val_t engram_add_layer(el_val_t name, el_val_t priority, el_val_t suppressible,
|
||||||
|
el_val_t transparent, el_val_t injectable);
|
||||||
|
el_val_t engram_remove_layer(el_val_t layer_id);
|
||||||
|
el_val_t engram_list_layers(void);
|
||||||
|
el_val_t engram_get_node(el_val_t id);
|
||||||
|
void engram_strengthen(el_val_t node_id);
|
||||||
|
void engram_forget(el_val_t node_id);
|
||||||
|
el_val_t engram_prune_telemetry(el_val_t older_than_ms);
|
||||||
|
el_val_t engram_node_count(void);
|
||||||
|
el_val_t engram_search(el_val_t query, el_val_t limit);
|
||||||
|
el_val_t engram_scan_nodes(el_val_t limit, el_val_t offset);
|
||||||
|
void engram_connect(el_val_t from_id, el_val_t to_id, el_val_t weight, el_val_t relation);
|
||||||
|
el_val_t engram_edge_between(el_val_t from_id, el_val_t to_id);
|
||||||
|
el_val_t engram_neighbors(el_val_t node_id);
|
||||||
|
el_val_t engram_neighbors_filtered(el_val_t node_id, el_val_t max_depth, el_val_t direction);
|
||||||
|
el_val_t engram_edge_count(void);
|
||||||
|
/* Three-pass activation: background fan-out → working-memory promotion →
|
||||||
|
* Layer 0 override. See "Three-pass activation" in el_runtime.c. */
|
||||||
|
el_val_t engram_activate(el_val_t query, el_val_t depth);
|
||||||
|
el_val_t engram_save(el_val_t path);
|
||||||
|
el_val_t engram_load(el_val_t path);
|
||||||
|
|
||||||
|
/* JSON-string accessors — return pre-serialized JSON so HTTP handlers
|
||||||
|
* can pass results straight through without round-tripping ElList/ElMap
|
||||||
|
* through json_stringify. */
|
||||||
|
el_val_t engram_get_node_json(el_val_t id);
|
||||||
|
el_val_t engram_get_node_by_label(el_val_t label);
|
||||||
|
el_val_t engram_search_json(el_val_t query, el_val_t limit);
|
||||||
|
el_val_t engram_scan_nodes_json(el_val_t limit, el_val_t offset);
|
||||||
|
el_val_t engram_scan_nodes_by_type_json(el_val_t node_type, el_val_t limit, el_val_t offset);
|
||||||
|
el_val_t engram_neighbors_json(el_val_t node_id, el_val_t max_depth, el_val_t direction);
|
||||||
|
el_val_t engram_activate_json(el_val_t query, el_val_t depth);
|
||||||
|
el_val_t engram_stats_json(void);
|
||||||
|
el_val_t engram_list_layers_json(void);
|
||||||
|
/* Working memory introspection — count, mean weight, and top-N snapshot.
|
||||||
|
* Ported from el-compiler/runtime on 2026-06-30 self-review. */
|
||||||
|
el_val_t engram_wm_count(void);
|
||||||
|
el_val_t engram_wm_avg_weight(void);
|
||||||
|
el_val_t engram_wm_top_json(el_val_t n);
|
||||||
|
/* Merge-load: add nodes/edges from a snapshot without resetting the store. */
|
||||||
|
el_val_t engram_load_merge(el_val_t path);
|
||||||
|
/* engram_compile_layered_json — produce a prompt-ready text block split
|
||||||
|
* into "[LAYER 0 — STRUCTURAL]" (non-suppressible layers, sacred fire)
|
||||||
|
* and "[ENGRAM CONTEXT]" (standard suppressible layers). Returns "" if
|
||||||
|
* no nodes promoted to working memory. */
|
||||||
|
el_val_t engram_compile_layered_json(el_val_t intent, el_val_t depth);
|
||||||
|
|
||||||
|
/* ── LLM (Anthropic API client) ─────────────────────────────────────────────
|
||||||
|
* All functions call https://api.anthropic.com/v1/messages with the API key
|
||||||
|
* from env ANTHROPIC_API_KEY. Default model when empty: claude-sonnet-4-5. */
|
||||||
|
|
||||||
|
el_val_t llm_call(el_val_t model, el_val_t prompt);
|
||||||
|
el_val_t llm_call_system(el_val_t model, el_val_t system_prompt, el_val_t user_prompt);
|
||||||
|
el_val_t llm_call_agentic(el_val_t model, el_val_t system, el_val_t user, el_val_t tools);
|
||||||
|
el_val_t llm_vision(el_val_t model, el_val_t system, el_val_t prompt, el_val_t image_url_or_b64);
|
||||||
|
el_val_t llm_models(void);
|
||||||
|
|
||||||
|
/* Register a tool handler by name. The handler is looked up via dlsym
|
||||||
|
* (mirroring http_set_handler), so any El `fn <name>(input)` compiles to
|
||||||
|
* a global C symbol that this function can locate at runtime.
|
||||||
|
* Handler signature: `el_val_t handler(el_val_t input_json)` — receives
|
||||||
|
* the tool input as a JSON-string el_val_t and returns a JSON-string
|
||||||
|
* el_val_t result. Used by llm_call_agentic. */
|
||||||
|
void llm_register_tool(el_val_t name, el_val_t handler_fn_name);
|
||||||
|
|
||||||
|
/* ── args() ─────────────────────────────────────────────────────────────────
|
||||||
|
* Provides access to command-line arguments passed to the program.
|
||||||
|
* Populated by el_runtime_init_args() before main() runs. */
|
||||||
|
|
||||||
|
el_val_t args(void);
|
||||||
|
void el_runtime_init_args(int argc, char** argv);
|
||||||
|
|
||||||
|
/* ── Crypto primitives ─────────────────────────────────────────────────────
|
||||||
|
* SHA-256, HMAC-SHA-256, and base64 (standard + URL-safe).
|
||||||
|
* Self-contained — no OpenSSL/libcrypto dependency. The implementations are
|
||||||
|
* adapted from public-domain reference code (Brad Conte / RFC 4648).
|
||||||
|
*
|
||||||
|
* Bytes-returning variants (sha256_bytes, hmac_sha256_bytes) return a string
|
||||||
|
* value whose contents are raw binary; callers usually feed these into
|
||||||
|
* base64_encode. Note that el_val_t strings are NUL-terminated by convention,
|
||||||
|
* so the binary payload may contain embedded NULs — pass it directly into
|
||||||
|
* base64_encode (which uses an explicit length) rather than treating it as
|
||||||
|
* a printable C string.
|
||||||
|
*
|
||||||
|
* The "base64" variants emit/accept RFC 4648 standard alphabet with padding.
|
||||||
|
* The "base64url" variants use URL-safe alphabet (`-`/`_`) with no padding,
|
||||||
|
* as used in JWTs. */
|
||||||
|
|
||||||
|
el_val_t sha256_hex(el_val_t input);
|
||||||
|
el_val_t sha256_bytes(el_val_t input);
|
||||||
|
el_val_t hmac_sha256_hex(el_val_t key, el_val_t message);
|
||||||
|
el_val_t hmac_sha256_bytes(el_val_t key, el_val_t message);
|
||||||
|
el_val_t base64_encode(el_val_t input);
|
||||||
|
el_val_t base64_decode(el_val_t input);
|
||||||
|
el_val_t base64url_encode(el_val_t input);
|
||||||
|
el_val_t base64url_decode(el_val_t input);
|
||||||
|
|
||||||
|
/* Length-aware variants (internal — exposed for the rare caller that already
|
||||||
|
* has a known-length binary buffer and doesn't want to round-trip through
|
||||||
|
* a NUL-terminated el_val_t string). Sha256_bytes and hmac_sha256_bytes feed
|
||||||
|
* these implicitly. */
|
||||||
|
el_val_t el_sha256_bytes_n(const unsigned char* data, size_t len);
|
||||||
|
el_val_t el_base64_encode_n(const unsigned char* data, size_t len, int url_safe);
|
||||||
|
|
||||||
|
/* ── Post-quantum primitives (liboqs-backed) ────────────────────────────────
|
||||||
|
* All inputs/outputs hex-encoded. Algorithm choices:
|
||||||
|
* Signature: CRYSTALS-Dilithium-3 (NIST level 3, balanced)
|
||||||
|
* KEM: CRYSTALS-Kyber-768 (NIST level 3)
|
||||||
|
* Hash: SHA3-256 (Keccak) (PQ-aware protocols favour SHA3 over SHA2)
|
||||||
|
*
|
||||||
|
* If liboqs is not linked (detected via __has_include(<oqs/oqs.h>) at compile
|
||||||
|
* time), the pq_* entry points return a JSON-shaped error string so callers
|
||||||
|
* fail loudly rather than silently fall back to classical schemes:
|
||||||
|
* {"error":"liboqs not linked, post-quantum primitives unavailable"}
|
||||||
|
*
|
||||||
|
* The hybrid handshake pairs X25519 with Kyber-768 per NIST PQ guidance and
|
||||||
|
* CNSA 2.0. Combined shared secret is HKDF-SHA256(x25519_ss || kyber_ss).
|
||||||
|
* Even if Kyber falls, X25519 holds; if X25519 falls under quantum attack,
|
||||||
|
* Kyber holds. SHA3-256 also remains usable independent of liboqs (the
|
||||||
|
* Keccak permutation is PQ-OK as a primitive). */
|
||||||
|
|
||||||
|
el_val_t pq_keygen_signature(void);
|
||||||
|
el_val_t pq_sign(el_val_t secret_key_hex, el_val_t message);
|
||||||
|
el_val_t pq_verify(el_val_t public_key_hex, el_val_t message, el_val_t signature_hex);
|
||||||
|
|
||||||
|
el_val_t pq_kem_keygen(void);
|
||||||
|
el_val_t pq_kem_encaps(el_val_t public_key_hex);
|
||||||
|
el_val_t pq_kem_decaps(el_val_t secret_key_hex, el_val_t ciphertext_hex);
|
||||||
|
|
||||||
|
el_val_t pq_hybrid_keygen(void);
|
||||||
|
el_val_t pq_hybrid_handshake(el_val_t remote_pub_combined);
|
||||||
|
|
||||||
|
el_val_t sha3_256_hex(el_val_t input);
|
||||||
|
|
||||||
|
/* ── AEAD: AES-256-GCM (libcrypto-backed) ───────────────────────────────────
|
||||||
|
* Symmetric authenticated encryption used to wrap envelopes after a KEM
|
||||||
|
* handshake. Caller MUST supply a 32-byte key (64 hex chars) — typically the
|
||||||
|
* Kyber-768 / hybrid shared_secret, optionally normalized via SHA3-256.
|
||||||
|
*
|
||||||
|
* aead_encrypt returns a JSON map {"nonce":"...","ciphertext":"..."} where
|
||||||
|
* ciphertext is the AES-256-GCM output with the 16-byte auth tag appended.
|
||||||
|
* Nonce is a fresh 12-byte CSPRNG draw — callers never pick the nonce, which
|
||||||
|
* structurally rules out the GCM nonce-reuse footgun.
|
||||||
|
*
|
||||||
|
* aead_decrypt returns the plaintext String, or "" on any failure (including
|
||||||
|
* auth-tag mismatch). Callers MUST check for "" before trusting the result. */
|
||||||
|
el_val_t aead_encrypt(el_val_t key_hex, el_val_t plaintext);
|
||||||
|
el_val_t aead_decrypt(el_val_t key_hex, el_val_t nonce_hex, el_val_t ciphertext_hex);
|
||||||
|
|
||||||
|
/* ── Native VM builtin aliases (for compiled El source) ─────────────────────
|
||||||
|
* These match the El VM's native_* builtins so that El source compiled
|
||||||
|
* to C can call the same names without modification. */
|
||||||
|
|
||||||
|
el_val_t native_list_get(el_val_t list, el_val_t index);
|
||||||
|
el_val_t native_list_len(el_val_t list);
|
||||||
|
el_val_t native_list_append(el_val_t list, el_val_t elem);
|
||||||
|
el_val_t native_list_empty(void);
|
||||||
|
el_val_t native_list_clone(el_val_t list);
|
||||||
|
el_val_t native_string_chars(el_val_t s);
|
||||||
|
el_val_t native_int_to_str(el_val_t n);
|
||||||
|
|
||||||
|
/* ── Method-call shorthand aliases ──────────────────────────────────────────
|
||||||
|
* The El method-call convention `obj.method(args)` compiles to
|
||||||
|
* `method(obj, args)`. These aliases expose the runtime functions under
|
||||||
|
* the short names that result from method calls in El source.
|
||||||
|
*
|
||||||
|
* Example: `myList.append(x)` → `append(myList, x)` (calls this alias)
|
||||||
|
* `myList.len()` → `len(myList)` (calls this alias) */
|
||||||
|
|
||||||
|
el_val_t append(el_val_t list, el_val_t elem); /* el_list_append */
|
||||||
|
el_val_t len(el_val_t list); /* el_list_len */
|
||||||
|
el_val_t get(el_val_t list, el_val_t index); /* el_list_get */
|
||||||
|
el_val_t map_get(el_val_t map, el_val_t key); /* el_map_get */
|
||||||
|
el_val_t map_set(el_val_t map, el_val_t key, el_val_t value); /* el_map_set */
|
||||||
|
|
||||||
|
/* ── OTLP/HTTP Observability ─────────────────────────────────────────────── */
|
||||||
|
/* See bottom of el_runtime.c for the implementation.
|
||||||
|
* Configured by env vars OTLP_ENDPOINT, OTEL_SERVICE_NAME, OTEL_SERVICE_VERSION.
|
||||||
|
* No-op when OTLP_ENDPOINT is unset. Drop-on-failure semantics. */
|
||||||
|
/* ── Subprocess execution ────────────────────────────────────────────────── */
|
||||||
|
el_val_t exec_command(el_val_t cmd); /* run shell command, return exit code */
|
||||||
|
el_val_t exec_capture(el_val_t cmd); /* run shell command, capture stdout */
|
||||||
|
el_val_t exec(el_val_t cmd); /* exec(cmd) → stdout String (30s timeout) */
|
||||||
|
el_val_t exec_bg(el_val_t cmd); /* exec_bg(cmd) → PID String (non-blocking) */
|
||||||
|
|
||||||
|
el_val_t emit_log(el_val_t level, el_val_t msg, el_val_t fields_json);
|
||||||
|
el_val_t emit_metric(el_val_t name, el_val_t value, el_val_t tags_json);
|
||||||
|
el_val_t trace_span_start(el_val_t name);
|
||||||
|
el_val_t trace_span_end(el_val_t span_handle);
|
||||||
|
el_val_t emit_event(el_val_t name, el_val_t duration_ms);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user