diff --git a/imprint.el b/imprint.el new file mode 100644 index 0000000..16a5932 --- /dev/null +++ b/imprint.el @@ -0,0 +1,72 @@ +// Layer 3 — Imprint +// Domain knowledge, voice, and tools bounded by the L2 stewardship surface. +// Imprints cannot write BellEvent or StewardshipEvent nodes. +// Lower layers (L0 core, L1 safety, L2 stewardship) are structurally inaccessible from here. + +// imprint_current — returns the active imprint ID from state. +// Falls back to "base" (bare Neuron, no suit) when nothing is loaded. +fn imprint_current() -> String { + let id: String = state_get("active_imprint_id") + return if str_eq(id, "") { "base" } else { id } +} + +// imprint_load — activate an imprint by ID. +// Searches engram for a node labelled "imprint:". +// On success: sets active_imprint_id state and returns {"ok":true,"id":""}. +// On miss: returns {"ok":false,"error":"imprint not found: "}. +fn imprint_load(imprint_id: String) -> String { + let label: String = "imprint:" + imprint_id + let results: String = engram_search_json(label, 1) + let found: Bool = !str_eq(results, "") && !str_eq(results, "[]") + if found { + state_set("active_imprint_id", imprint_id) + return "{\"ok\":true,\"id\":\"" + imprint_id + "\"}" + } + return "{\"ok\":false,\"error\":\"imprint not found: " + imprint_id + "\"}" +} + +// imprint_respond — route steward-aligned input through the active imprint's voice/domain context. +// If imprint_id is "base" or empty: pass input through unchanged (base Neuron, no suit). +// If the imprint node is found: annotate the input with imprint context. +// If the node is missing: graceful fallback to base — never hard-fail at L3. +fn imprint_respond(input: String, imprint_id: String) -> String { + let is_base: Bool = str_eq(imprint_id, "base") || str_eq(imprint_id, "") + if is_base { + return input + } + let label: String = "imprint:" + imprint_id + let results: String = engram_search_json(label, 1) + let found: Bool = !str_eq(results, "") && !str_eq(results, "[]") + if found { + return input + " [imprint:" + imprint_id + " active]" + } + // Graceful fallback: imprint node missing, return input unchanged + return input +} + +// imprint_surface_knowledge — domain-scoped knowledge search for the active imprint. +// Imprints can search knowledge but only domain-relevant nodes. +// For "base" imprint: full query, no scope restriction. +// For named imprints: query is narrowed to "domain:" scope. +fn imprint_surface_knowledge(query: String, imprint_id: String) -> String { + let is_base: Bool = str_eq(imprint_id, "base") || str_eq(imprint_id, "") + let scoped_query: String = if is_base { + query + } else { + query + " domain:" + imprint_id + } + return engram_search_json(scoped_query, 10) +} + +// imprint_surface_memory_read — imprints can read memories from engram. +// Read-only: no write surface is exposed here. +// Imprints CANNOT write BellEvent, StewardshipEvent, or InternalStateEvent nodes — +// those write paths are sealed in L1 and L2, which are structurally inaccessible. +fn imprint_surface_memory_read(query: String) -> String { + return engram_search_json(query, 10) +} + +// imprint_unload — deactivate the current imprint, returning to base Neuron. +fn imprint_unload() -> Void { + state_set("active_imprint_id", "") +} diff --git a/imprint.elh b/imprint.elh new file mode 100644 index 0000000..8a29f42 --- /dev/null +++ b/imprint.elh @@ -0,0 +1,7 @@ +// auto-generated by elc --emit-header — do not edit +extern fn imprint_current() -> String +extern fn imprint_load(imprint_id: String) -> String +extern fn imprint_respond(input: String, imprint_id: String) -> String +extern fn imprint_surface_knowledge(query: String, imprint_id: String) -> String +extern fn imprint_surface_memory_read(query: String) -> String +extern fn imprint_unload() -> Void