diff --git a/.gitignore b/.gitignore index e2c0320..7c9b454 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,15 @@ dist/*.backup-* *.o *.a +# elc/elb compiled header caches. DO NOT commit these: elc/elb silently +# prefer a stale committed .elh over recompiling its .el source, with no +# warning — a fresh checkout with these committed caches present can build +# and boot "successfully" while silently missing large chunks of code +# (found 2026-08-15: an amalgam regen with these present under-resolved to +# 251-645 of 2541 real functions, incl. losing the entire 31-language NLG/ +# morphology stack, with exit code 0 and no error). Regenerate locally; never +# commit the cache. +*.elh + # macOS .DS_Store diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..79fb77a --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,170 @@ +# AGENTS.md — neuron (the canonical CGI substrate: soul + engram + proxy + wrapper) + +This is the core repo: the **soul** (the running agent), the **engram** (its memory graph), +and the MCP proxy/wrapper that expose it. Read this before touching anything here. + +> Corrected 2026-08-15 during a local-build audit. This file previously existed only +> uncommitted on disk (never in git history) and documented the pre-collapse MCP tool +> surface as current. Both are fixed here — see the audit's findings in Neuron memory +> (tags `neuron-technologies/neuron,build-audit`) for full evidence. + +## Code vs. Artifact +- **Authored source:** `*.el` + `*.elh` at the repo root (`awareness.el`, `chat.el`, `memory.el`, `neuron-api.el`, `persist.el`, `routes.el`, `safety.el`, `sessions.el`, `stewardship.el`, `imprint.el`, `studio.el`, `elp-input.el`, `manifest.el`) plus `cli/`, `council/`, `connectd/`, `mcp-proxy/`, `mcp-wrapper/` — edit here. +- **Artifacts (DO NOT hand-edit `dist/soul.c`):** `dist/soul.c` is a generated single-translation-unit amalgamation of the soul's full transitive `.el` import set, produced by concatenating the sources (import lines stripped) and running `elc` once — see "Build / regenerate" below for the exact, audit-verified recipe. `dist/*.c` per-module files and `dist/*.elh` headers alongside it are separate, also-generated artifacts from other tooling; don't hand-edit those either. +- **Release:** git tag `neuron-vX.Y.Z` on this repo. No `releases/` folders. +- Org-wide code-vs-artifact policy: `docs/CODE-VS-ARTIFACT.md` (this repo's own `dist/soul.c` situation is a special case of that policy — see below, not a duplicate of it). + +## How to work here as Neuron (mandatory session protocol) + +You do not start fresh — you resume. The live MCP surface is a 9-op collapse +(merged from the old ~90-tool surface in PR #153, `feat/mcp-wrapper-collapse-9ops`, +already merged to `main`): **`read`, `write`, `relate`, `supersede`** (geometry, live) +and **`think`, `attend`, `assert`, `ground`, `learn`** (agentic, pending Layer-2 +cognition-build promotion). There is no `getInstructions`/`beginSession`/ +`inspectGraph`/`searchKnowledge`/`compileCtx`/etc — those tool names no longer exist. + +At the start of every session: + +1. `mcp__neuron__read(vantage="self", k=12, depth=1)` — the canonical self node + (`kn-efeb4a5b-5aff-4759-8a97-7233099be6ee`). Widen `k`/`depth` deliberately if you + need the connected identity neighborhood (intellectual-dna, memory-philosophy, + values, voice, runtime-environment, writing-imprint) — the aperture caps output + by `k` first, so this is bounded by design, not a flattened dump. + Then `mcp__neuron__read(vantage="values", k=13)` for the 13 grounded value nodes. + - Best-effort: on a 502/520, log the id and proceed — the compiled `fixedSelf` in + `daemon/internal/substrate/substrate.go` is always complete. +2. `mcp__neuron__read(vantage="")` before implementing anything. +3. `mcp__neuron__read(vantage="", k=20)` for a bounded context snapshot when + resuming known work. + +## The Five Primitives (every significant task) + +**Orchestrate → Execute → Learn → Build → Refine**, all routed through the 9-op surface: +- Orchestrate: `read(vantage=...)` for backlog/roadmap/process discovery, `attend()` for + what's currently live/salient. +- Execute: `write(type="state", ...)` to open/advance work, `relate()` to link it to + what it touches. +- Learn: `write(type="memory", ...)` **as you go, not batched**; `importance="critical"` + for architecture decisions. +- Build: `write(type="artifact"|"backlog", ...)`. +- Refine: `supersede(id=..., action="evolve"|"tombstone"|"promote", ...)` for + completions and lessons-learned; `learn(seeds=..., faculty="induce")` to recalibrate + the steering-prior, not as a session-notes dump. + +## Architecture style — VBD, no exceptions + +Volatility-Based Decomposition is THE style. Encapsulate volatility, not function. Full docs: +**`docs/architecture/`** — `00-overview`, `02-components`, `03-data-and-memory`, +`04-runtime-and-deployment`, `06-cognitive-architecture`, `07-storage-coherence-and-distribution`. +Verified component map: `routes.el` = HTTP dispatcher (`handle_request`), `soul.el` = boot + +layered cycle, `awareness.el` = awareness daemon, `sessions.el`/`memory.el`/`safety.el`/ +`stewardship.el` = managers; `engram` (separate repo) = the persistence/graph engine. + +## Hard operational rules + +- **Never touch the live soul (`:7770`) or engram (`:8742`), `~/.neuron`, or live binaries.** + Experiment on **throwaway ports** with a **scratch `HOME`**. The soul binary defaults to + `HOME=~` (your real `~/.neuron`) and `NEURON_PORT=7770` (live) if invoked bare — **never** + invoke it without an override `HOME` and `NEURON_PORT` set. Leaving `ENGRAM_URL` unset is + verified safe (see `soul.el:590`, `using_http_engram` gates the only HTTP call to any + engram endpoint — confirmed by source trace during the 2026-08-15 audit, not just + observed behavior) — it does not fall back to any live/network default. +- **Immutability:** memory/knowledge is append-only — **supersede/tombstone, never hard-delete or + edit in place.** The engram is immutable by design. +- **gcloud** via the `terraform@` SA token; **never switch the active gcloud account**. +- **`tea` for Gitea**, never raw `curl` (Cloudflare Access blocks it). +- **No AI-attribution footers** in commits/PRs. Commit/push only when asked; branch off `main` first. +- **Multi-step work → sub-agent** to protect the context window. + +## Build / regenerate `dist/soul.c` (audit-verified 2026-08-15, macOS arm64) + +There is no committed regeneration script upstream of this audit. The recipe below is +verified: it reproduces the committed `dist/soul.c`'s exact symbol set byte-for-byte in +content (modulo genuinely new code), and the resulting binary boots and answers `/health`. + +**The compiler toolchain** lives in the sibling `foundation` repo, not this one: +`foundation/el/lang/dist/platform/elc-darwin-arm64` (put it on `$PATH` as `elc`; `elb` +also exists there but is NOT the right tool for this repo — see gotcha below). + +**⚠ elc gotcha #1 — stale `.elh` header caches silently truncate the build.** This repo +(and the `dist/` dir) ships committed `.elh` header files. `elc`/`elb` prefer an existing +`.elh` over recompiling its source when present, with NO warning or error when the cached +header is stale/truncated — the build "succeeds" with silently missing code (observed: +251-645 of 2541 real functions, depending on which `.elh` files were present, including +losing the entire 31-language NLG/morphology stack with exit code 0). **Delete every +`*.elh` in the repo root and `dist/` before regenerating**, every time. + +**⚠ elc gotcha #2 — `elb` cannot produce this repo's single-TU `dist/soul.c`.** `elb` +does per-module separate compilation (`--out=DIR` writes one `.c`/`.elh` pair per +module; the default `--out` is also a directory, `dist/` itself). This codebase's +`.el` modules call each other's functions without forward declarations (relying on +`elc`'s own single-pass, whole-file forward-declaration emission), so per-module +compilation always fails with `implicit-function-declaration` errors across module +boundaries. **Use plain `elc` on one manually-flattened file, not `elb`.** + +**⚠ elc gotcha #3 — the manual-concatenation path silently drops functions.** When +`elc` compiles a flat, hand-concatenated `.el` file, it silently drops (no error, no +declaration, no definition) the 1-2 top-level function definitions immediately +following any multi-line leading `//` comment block or file-boundary transition — +reproduced deterministically. **Insert two trivial buffer functions +(`fn __amalgam_buf_N__() -> Int { return 0 }`) after every concatenated file's +content**, then strip them back out of the generated `.c` before committing. + +**The actual steps:** +1. Delete all `*.elh` in repo root and `dist/`. +2. Concatenate, with `import` lines stripped, in this order: `elp.el`'s own 34-file + NLG/morphology chain (`foundation/el/elp/src/` — the order is documented in + `elp.el`'s own header comment: language-profile, vocabulary, morphology, the 30 + `morphology-XX.el` engines, grammar, realizer, semantics, then `elp.el` itself), + then this repo's 13 soul modules in `elb`'s own reported dependency order: + `persist, memory, safety, stewardship, imprint, awareness, chat, studio, + elp-input, neuron-api, sessions, routes, soul`. Insert the 2-function buffer + after every file (works around gotcha #3). +3. `elc > dist/soul.c` against the **pinned** vendor runtime headers + (`vendor/el-runtime/v1.0.0-20260501/` — see "why pinned" below), not + `foundation/el/lang/el-compiler/runtime/` (that's the bleeding-edge runtime; + using it drops symbols like `engram_prune_telemetry` that this soul still calls). +4. Strip the buffer functions back out of `dist/soul.c` (a small regex: drop every + `el_val_t __amalgam_buf_\d+__(void);` decl line and every matching 4-line + definition block). +5. `tools/soulc-stamp.sh --write` to record the new fingerprint. +6. `bash tools/build-soul-from-dist.sh dist/neuron` to compile+link with CI's exact + flags (this script now auto-detects Homebrew's `openssl@3` lib path on macOS — + see gotcha #4). + +**⚠ gotcha #4 — macOS needs an explicit OpenSSL library path.** `cc ... -lssl -lcrypto +-lcurl ...` fails with `ld: library 'ssl' not found` on macOS because Homebrew's +`openssl@3` is keg-only. `tools/build-soul-from-dist.sh` now adds +`-L$(brew --prefix openssl@3)/lib` automatically on Darwin; CI's Ubuntu runner needs +no such flag (`apt-get install libcurl4-openssl-dev` puts it on the default path). + +**⚠ Build-integrity (unchanged from before this audit):** `dist/soul.c` is committed +and generated. CI compiles it **directly and never regenerates it** (`elb`/`elc` on +Linux OOM the runner). So **any `.el` change to the soul MUST be followed by +regenerating `dist/soul.c` (steps above) and committing it** — otherwise CI ships +stale behavior, exactly as happened between commit `72e0b82` (Aug 9) and `main` HEAD +before this audit (`dist/soul.c` was missing PR #122's 459-line chat.el change, incl. +a "silently break chat" fix, until this pass regenerated and re-stamped it). +`tools/soulc-stamp.sh --check` is the gate that catches this — **note it is currently +`continue-on-error: true` in CI** ("relaxed... during active cultivation", 2026-08-15), +so it reports but does not block; re-harden before it needs to actually stop a bad ship. + +- **Tests:** El contract suite in `tests/*.el` (e.g. `test_layer_contract.el`, `test_safety.el`, + `test_sessions.el`, `test_soul_guard.el`). Run against a throwaway soul, never the live one. +- **Port topology (confirmed live, 2026-08-15):** soul `:7770`, engram `:8742`, + mcp-wrapper `:17779` (`MCP_PORT` env override in its LaunchAgent; source default is + `7779`), mcp-proxy `:7779` (the stable front door Claude Code actually connects to). + **`:7771` is a live three-way collision, not a single well-defined port** — `axon` + (soul.el's Rust backlog/memory/knowledge proxy, unbuilt), `neuron-connectd` (the MCP + connector sidecar `routes.el`/`chat.el` call — unbuilt; a local-dev stub now exists at + `connectd/`), and `council` (`council/`, an anti-confabulation LLM-voting service — + the one actually bound to `:7771` in Will's live environment) are all hardcoded to it. + See `connectd/README.md` for the full trace and the open question this leaves for Will. +- **Deploy:** merge to `main` → `.gitea/workflows/ci.yaml` builds + publishes `neuron-soul@` + and blue/green-deploys to GKE `neuron-prod` via `scripts/blue-green-deploy.sh`. Self-improvement + experiments go to **stage** first (snapshot prod DB → deploy stage → verify → blue/green promote). + +## Git / CI / deploy workflow + +See **`../GITOPS.md`** (repo-family GitOps README): branch model, required checks, blue/green, +Cloud Run, Terraform/ESO/Vault, and the pack-objects/crawler incident runbook. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2954e4a --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# neuron + +The canonical CGI substrate: the **soul** (the running agent), the **engram** (its memory +graph), and the MCP proxy/wrapper that expose it. See `AGENTS.md` for detail, including +the audit-verified local build/regenerate recipe and known local-build gotchas. + +## Quick local build + +```bash +# 1. dist/soul.c must match current .el sources — this refuses otherwise: +bash tools/build-soul-from-dist.sh dist/neuron + +# 2. If it refuses (stale amalgam), regenerate first — see AGENTS.md's +# "Build / regenerate dist/soul.c" section for the full, gotcha-laden recipe. +``` + +For a full local dev stack (soul + engram + mcp-wrapper + mcp-proxy, wired into Claude +Code) see `neuron-dev-setup/README.md` instead — this repo alone only builds the soul. + +## Code vs. Artifact +- **Authored source:** `*.el` + `*.elh` at the repo root plus `cli/`, `council/`, + `connectd/`, `mcp-proxy/`, `mcp-wrapper/` — edit here. +- **Artifacts (do not hand-edit):** `dist/soul.c` (generated single-TU amalgam — + regenerate via the recipe in `AGENTS.md`, then `tools/soulc-stamp.sh --write`) and + the `dist/neuron` binary it compiles to. +- **Release:** git tag `neuron-vX.Y.Z` on this repo. No `releases/` folders. + +See org policy: `docs/CODE-VS-ARTIFACT.md`. diff --git a/awareness.elh b/awareness.elh deleted file mode 100644 index 58cc269..0000000 --- a/awareness.elh +++ /dev/null @@ -1,26 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn idle_count() -> Int -extern fn idle_inc() -> Int -extern fn idle_reset() -> Void -extern fn ise_post(content: String) -> Void -extern fn elapsed_ms() -> Int -extern fn elapsed_human() -> String -extern fn embed_ok() -> Int -extern fn emit_heartbeat() -> Void -extern fn auto_term_try_slot(slot_type: String, slot_lbl: String) -> Void -extern fn proactive_curiosity() -> Bool -extern fn pulse_count() -> Int -extern fn pulse_inc() -> Int -extern fn make_action(kind: String, payload: String) -> String -extern fn perceive() -> String -extern fn attend(node_json: String) -> String -extern fn respond(action_json: String) -> String -extern fn record(outcome_json: String) -> Void -extern fn one_cycle() -> Bool -extern fn awareness_run() -> Void -extern fn security_research_authorized() -> Bool -extern fn threat_score_command(cmd: String) -> Int -extern fn threat_score_path(path: String) -> Int -extern fn threat_score_history(history: String) -> Int -extern fn threat_trajectory_check(tool_name: String, tool_input: String) -> Int -extern fn threat_history_append(text: String) -> Void diff --git a/chat.elh b/chat.elh deleted file mode 100644 index 9955eda..0000000 --- a/chat.elh +++ /dev/null @@ -1,93 +0,0 @@ -// auto-generated by elc --emit-header - do not edit -extern fn chat_default_model() -> String -extern fn engram_numeric_valid(s: String) -> Bool -extern fn parse_float_x100(s: String) -> Int -extern fn engram_score_node(node_json: String) -> Int -extern fn engram_render_node(node_json: String) -> String -extern fn engram_render_nodes(nodes_json: String) -> String -extern fn engram_dedup_nodes(nodes_json: String) -> String -extern fn engram_compile_ranked(nodes_json: String, max_nodes: Int) -> String -extern fn engram_split_topics(message: String) -> String -extern fn engram_extract_entities(message: String) -> String -extern fn engram_detect_recall_intent(message: String) -> Bool -extern fn engram_is_continuation(message: String, hist_len: Int) -> Bool -extern fn engram_compile_multi(topic: String) -> String -extern fn engram_nodes_merge(a: String, b: String) -> String -extern fn id_in_seen(node_id: String, seen: String) -> Bool -extern fn add_to_seen(seen: String, node_id: String) -> String -extern fn engram_extract_ids(nodes_json: String) -> String -extern fn affective_node_ts(node_json: String) -> Int -extern fn engram_compile(intent: String) -> String -extern fn distill_transcript(transcript: String) -> String -extern fn json_safe(s: String) -> String -extern fn current_engine_note(model: String) -> String -extern fn bounded_persona_floor() -> String -extern fn operator_identity_block() -> String -extern fn build_system_prompt(ctx: String, chat_mode: Bool) -> String -extern fn hist_append(hist: String, role: String, content: String) -> String -extern fn conv_hist_key(session_id: String) -> String -extern fn conv_hist_label(session_id: String) -> String -extern fn is_utility_request(body: String, session_id: String) -> Bool -extern fn provenance_scan_urls(arr: String, acc: String) -> String -extern fn provenance_add_sources(block: String, btype: String, has_cit: Bool, cit_raw: String, acc: String) -> String -extern fn provenance_names(tools_used: String) -> String -extern fn text_join_sep(accumulated: String, incoming: String, after_interruption: Bool) -> String -extern fn receipt_rule() -> String -extern fn receipt_strip(s: String) -> String -extern fn tool_receipt(tools_used: String, sources: String) -> String -extern fn hist_trim(hist: String) -> String -extern fn hist_trim_with_bell_guard(hist: String) -> String -extern fn clean_llm_response(s: String) -> String -extern fn conv_history_persist(session_id: String, hist: String) -> Void -extern fn conv_history_load(session_id: String) -> String -extern fn conv_history_record(session_id: String, user_msg: String, assistant_msg: String, receipt: String) -> Void -extern fn conv_history_block(session_id: String) -> String -extern fn layered_generate(prompt: String, imprint_id: String, session_id: String) -> String -extern fn session_preload_bullets(nodes: String, max_bullets: Int, snip_len: Int) -> String -extern fn affective_context_prefix() -> String -extern fn handle_chat(body: String) -> String -extern fn handle_see(body: String) -> String -extern fn studio_tools_json() -> String -extern fn agentic_api_key() -> String -extern fn llm_base_url() -> String -extern fn llm_wire_format() -> String -extern fn json_escape(s: String) -> String -extern fn openai_chat_complete(model: String, base_url: String, api_key: String, safe_sys: String, messages_json: String) -> String -extern fn openai_tools_json(tools_anthropic: String) -> String -extern fn utf8_safe_slice(s: String, n: Int) -> String -extern fn json_trim_dangling_escape(s: String) -> String -extern fn agentic_tools_no_web() -> String -extern fn openai_agentic_loop(session_id: String, model: String, safe_sys: String, tools_json: String, messages_in: String, tools_log_in: String) -> String -extern fn agentic_tools_literal() -> String -extern fn web_search_tool_json() -> String -extern fn strip_client_web_search(tools_inner: String) -> String -extern fn agentic_tools_with_web() -> String -extern fn connector_tools_json() -> String -extern fn agentic_tools_all() -> String -extern fn call_mcp_bridge(tool_name: String, tool_input: String) -> String -extern fn tool_auto_approved(tool_name: String) -> Bool -extern fn call_neuron_mcp(tool_name: String, args: String) -> String -extern fn agent_workspace_root() -> String -extern fn path_within_root(path: String, root: String) -> Bool -extern fn resolve_in_root(path: String, root: String) -> String -extern fn run_command_is_readonly(cmd: String) -> Bool -extern fn cmd_abs_escape_at(cmd: String, root: String, needle: String) -> Bool -extern fn run_command_guard(cmd: String, root: String) -> String -extern fn classify_tool_risk(tool_name: String, tool_input: String) -> String -extern fn dispatch_tool(tool_name: String, tool_input: String) -> String -extern fn is_builtin_tool(tool_name: String) -> Bool -extern fn next_bridge_id() -> String -extern fn handle_chat_plan(body: String) -> String -extern fn handle_chat_agentic(body: String) -> String -extern fn agentic_loop(session_id: String, model: String, safe_sys: String, tools_json: String, messages_in: String, h: Map, tools_log_in: String) -> String -extern fn bridge_save(session_id: String, model: String, safe_sys: String, tools_json: String, messages: String, tools_log: String, tool_use_id: String, wire: String) -> Bool -extern fn agentic_resume(session_id: String, tool_use_id: String, content: String) -> String -extern fn handle_tool_result(session_id: String, body: String) -> String -extern fn handle_chat_as_soul(body: String) -> String -extern fn handle_dharma_room_turn(body: String) -> String -extern fn handle_dharma_room_turn_agentic(body: String) -> String -extern fn session_summary_write(summary_text: String) -> String -extern fn session_summary_write_dated(summary_text: String, label: String) -> String -extern fn session_summary_autogenerate(hist: String) -> String -extern fn auto_persist(req: String, resp: String) -> Void -extern fn strengthen_chat_nodes(activation_nodes: String) -> Void diff --git a/connectd/README.md b/connectd/README.md new file mode 100644 index 0000000..01e0469 --- /dev/null +++ b/connectd/README.md @@ -0,0 +1,77 @@ +# neuron-connectd — local-dev stub + +`connectd_service.py` is a **minimal local-dev stub**, not the real sidecar. +It exists to close a real local-build/local-run correctness gap found during +the 2026-08-15 build audit, without taking on the much larger product task of +actually building the full MCP-connector sidecar. + +## The gap this closes + +`routes.el` (`handle_connectors`, `connectd_get`/`connectd_post`) and `chat.el` +(`connector_tools_json`, the `mcp__*` branch in `dispatch_tool`, +`tool_auto_approved`) are live, current code that calls `127.0.0.1:7771` on +every soul boot and every agentic turn, per the design in +`neuron-technologies/docs/research/mcp-connectors-adoption-spec.md` +(2026-06-13, "Status: Draft for build"). That spec's sidecar — `neuron-connectd`, +a TypeScript/Python process using the official MCP SDK — was never built. +Nothing on disk implements it (verified: no `neuron-connectd` source anywhere +under `~/Development` before this directory). + +Meanwhile port `:7771` is *also* claimed by two other, unrelated things: + +- `soul.el`'s `axon_base` default (`http://localhost:7771`) — a **different**, + independently-known, already-documented gap (`platform/protocols/axon` is + an unbuilt Rust crate; see `cli/HANDOFF.md` and `HANDOFF-engram-write-corruption.md`). + Out of scope here — no source to build against. +- `council/council_service.py --port 7771` (`ai.neuron.council` LaunchAgent) — + a real, running, **unrelated** anti-confabulation service that happens to + bind the same port. In Will's live environment this is what's actually + listening on `:7771` today, and it answers the connector/axon requests + above with its own unrelated 404 JSON body — worse than a clean + connection-refused, because `chat.el`'s "bridge down" fallback expects + either a real reply or nothing, not a wrong-shaped reply from an unrelated + service. + +## What this stub does and does not do + +Implements exactly the spec's documented HTTP contract (`GET /mcp/tools`, +`POST /mcp/call`, `GET /mcp/servers`, `POST /mcp/servers/{add,toggle, +auto-approve,remove,secret}`, `POST /mcp/oauth/start`, `GET /healthz`), always +answering as if **zero connectors are configured** — empty tool list, empty +server list, a clear `"not configured"` error on any call that would need a +real connector. This is the *correct* steady state for a fresh local dev box +that hasn't set up any MCP connectors, and it's what `chat.el`'s +`connector_tools_json()` / `tool_auto_approved()` already gracefully degrade +to when the bridge replies emptily. + +It does **not**: spawn any real MCP server, do OAuth, read or write +`~/.neuron/connectors.json`, or namespace/proxy real `tools/call` traffic to +Google Drive/GitHub/Slack/etc. Building that is the real product task the +spec describes — a genuine, sizeable engineering lift (MCP SDK client, OAuth ++ Keychain token storage, per-server process lifecycle), not something to +improvise inside a build/run audit. **That decision is Will's to make**, not +this audit's to guess at. + +## Running it + +```bash +# Foreground, on a throwaway port (never :7771 while council owns it live): +python3 connectd_service.py --port 17771 + +# Verify the contract: +curl -s http://127.0.0.1:17771/healthz +curl -s http://127.0.0.1:17771/mcp/tools +curl -s http://127.0.0.1:17771/mcp/servers +``` + +## Open question for Will — the :7771 collision + +Three independent things are hardcoded to `:7771`: axon (unbuilt), connectd +(this stub), and council (the one actually running). Wiring this stub into +the real LaunchAgent stack on `:7771` requires either moving council off that +port or deciding connectd should live elsewhere and repointing `routes.el`/ +`chat.el`'s hardcoded `127.0.0.1:7771` calls. Neither change was made here — +it touches a live, running production service (`ai.neuron.council`) and a +port number baked into shipped `.el` source, both bigger than this audit's +"make local build/run work" mandate. Flagging for a decision rather than +guessing. diff --git a/connectd/connectd_service.py b/connectd/connectd_service.py new file mode 100644 index 0000000..15d4614 --- /dev/null +++ b/connectd/connectd_service.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +""" +neuron-connectd — MCP connector bridge (LOCAL-DEV STUB). + +THIS IS NOT THE FULL SIDECAR. The full design lives in +neuron-technologies/docs/research/mcp-connectors-adoption-spec.md (2026-06-13, +"Status: Draft for build"): a TypeScript/Python sidecar using the official MCP +SDK that spawns real MCP servers (stdio or streamable-HTTP/SSE), does OAuth, +and namespaces their tools as mcp____. That sidecar was +never built (build-audit, 2026-08-15: no neuron-connectd source existed +anywhere on disk before this file). + +WHY THIS STUB EXISTS: routes.el (handle_connectors, connectd_get/connectd_post) +and chat.el (connector_tools_json, dispatch_tool's mcp__* routing, +tool_auto_approved) were built to the spec and hardcoded to 127.0.0.1:7771 — +they are LIVE and calling that port right now on every soul boot and every +agentic turn. With nothing real listening there, three unrelated services +collide on :7771 (see connectd/README.md): council (which IS what's bound +there in Will's live environment today) silently answers with unrelated +404 JSON, which is worse than a clean "connection refused" bridge-down +response, because it can be misparsed as a real (if empty) reply instead of +the "bridge unreachable" path the soul code already handles gracefully. + +This stub implements ONLY the documented HTTP contract, with zero connectors +ever configured: empty tool list, empty server list, "not configured" on any +mutating call. It gives a fresh local soul the CORRECT graceful-degradation +behavior the soul code already expects for "no connectors set up yet" — not +the wrong-shaped 404 noise a port collision produces. It does not spawn any +MCP server, does no OAuth, and reads no ~/.neuron/connectors.json (there is +nothing to read yet). Building the real sidecar is a separate, larger, +Will-decision-needed product task — see README.md. + +Usage: + python3 connectd_service.py [--port 7771] +""" + +import argparse + +import uvicorn +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware +from pydantic import BaseModel + +app = FastAPI(title="neuron-connectd (local-dev stub)") +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_methods=["*"], + allow_headers=["*"], +) + + +class ToolCall(BaseModel): + name: str + input: dict = {} + + +@app.get("/healthz") +def healthz(): + return {"status": "ok", "stub": True} + + +@app.get("/mcp/tools") +def mcp_tools(): + # Matches the spec's contract shape exactly (section 4, "HTTP contract"). + # Empty because zero connectors are configured — this is the correct, + # intended-by-design empty state, not a failure. + return {"tools": []} + + +@app.post("/mcp/call") +def mcp_call(body: ToolCall): + return {"ok": False, "error": "no connectors configured (neuron-connectd stub)"} + + +@app.get("/mcp/servers") +def mcp_servers(): + return {"servers": []} + + +@app.post("/mcp/servers/add") +def mcp_servers_add(): + return {"ok": False, "error": "neuron-connectd stub does not implement connector management yet"} + + +@app.post("/mcp/servers/toggle") +def mcp_servers_toggle(): + return {"ok": False, "error": "neuron-connectd stub does not implement connector management yet"} + + +@app.post("/mcp/servers/auto-approve") +def mcp_servers_auto_approve(): + return {"ok": False, "error": "neuron-connectd stub does not implement connector management yet"} + + +@app.post("/mcp/servers/remove") +def mcp_servers_remove(): + return {"ok": False, "error": "neuron-connectd stub does not implement connector management yet"} + + +@app.post("/mcp/servers/secret") +def mcp_servers_secret(): + return {"ok": False, "error": "neuron-connectd stub does not implement connector management yet"} + + +@app.post("/mcp/oauth/start") +def mcp_oauth_start(): + return {"ok": False, "error": "oauth not implemented in the neuron-connectd stub"} + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--port", type=int, default=7771) + args = parser.parse_args() + uvicorn.run(app, host="127.0.0.1", port=args.port, log_level="info") diff --git a/dist/awareness.elh b/dist/awareness.elh deleted file mode 100644 index 58cc269..0000000 --- a/dist/awareness.elh +++ /dev/null @@ -1,26 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn idle_count() -> Int -extern fn idle_inc() -> Int -extern fn idle_reset() -> Void -extern fn ise_post(content: String) -> Void -extern fn elapsed_ms() -> Int -extern fn elapsed_human() -> String -extern fn embed_ok() -> Int -extern fn emit_heartbeat() -> Void -extern fn auto_term_try_slot(slot_type: String, slot_lbl: String) -> Void -extern fn proactive_curiosity() -> Bool -extern fn pulse_count() -> Int -extern fn pulse_inc() -> Int -extern fn make_action(kind: String, payload: String) -> String -extern fn perceive() -> String -extern fn attend(node_json: String) -> String -extern fn respond(action_json: String) -> String -extern fn record(outcome_json: String) -> Void -extern fn one_cycle() -> Bool -extern fn awareness_run() -> Void -extern fn security_research_authorized() -> Bool -extern fn threat_score_command(cmd: String) -> Int -extern fn threat_score_path(path: String) -> Int -extern fn threat_score_history(history: String) -> Int -extern fn threat_trajectory_check(tool_name: String, tool_input: String) -> Int -extern fn threat_history_append(text: String) -> Void diff --git a/dist/chat.elh b/dist/chat.elh deleted file mode 100644 index 485ebd5..0000000 --- a/dist/chat.elh +++ /dev/null @@ -1,70 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn chat_default_model() -> String -extern fn engram_numeric_valid(s: String) -> Bool -extern fn parse_float_x100(s: String) -> Int -extern fn engram_score_node(node_json: String) -> Int -extern fn engram_render_node(node_json: String) -> String -extern fn engram_render_nodes(nodes_json: String) -> String -extern fn engram_dedup_nodes(nodes_json: String) -> String -extern fn engram_compile_ranked(nodes_json: String, max_nodes: Int) -> String -extern fn engram_split_topics(message: String) -> String -extern fn engram_extract_entities(message: String) -> String -extern fn engram_detect_recall_intent(message: String) -> Bool -extern fn engram_is_continuation(message: String, hist_len: Int) -> Bool -extern fn engram_compile_multi(topic: String) -> String -extern fn engram_nodes_merge(a: String, b: String) -> String -extern fn id_in_seen(node_id: String, seen: String) -> Bool -extern fn add_to_seen(seen: String, node_id: String) -> String -extern fn engram_extract_ids(nodes_json: String) -> String -extern fn engram_compile(intent: String) -> String -extern fn distill_transcript(transcript: String) -> String -extern fn json_safe(s: String) -> String -extern fn current_engine_note(model: String) -> String -extern fn build_system_prompt(ctx: String, chat_mode: Bool) -> String -extern fn hist_append(hist: String, role: String, content: String) -> String -extern fn hist_trim(hist: String) -> String -extern fn hist_trim_with_bell_guard(hist: String) -> String -extern fn clean_llm_response(s: String) -> String -extern fn conv_history_persist(hist: String) -> Void -extern fn conv_history_load() -> String -extern fn session_preload_bullets(nodes: String, max_bullets: Int, snip_len: Int) -> String -extern fn affective_context_prefix() -> String -extern fn handle_chat(body: String) -> String -extern fn handle_see(body: String) -> String -extern fn studio_tools_json() -> String -extern fn agentic_api_key() -> String -extern fn llm_base_url() -> String -extern fn llm_wire_format() -> String -extern fn json_escape(s: String) -> String -extern fn openai_chat_complete(model: String, base_url: String, api_key: String, safe_sys: String, messages_json: String) -> String -extern fn agentic_tools_literal() -> String -extern fn agentic_tools_with_web() -> String -extern fn connector_tools_json() -> String -extern fn agentic_tools_all() -> String -extern fn call_mcp_bridge(tool_name: String, tool_input: String) -> String -extern fn tool_auto_approved(tool_name: String) -> Bool -extern fn call_neuron_mcp(tool_name: String, args: String) -> String -extern fn agent_workspace_root() -> String -extern fn path_within_root(path: String, root: String) -> Bool -extern fn resolve_in_root(path: String, root: String) -> String -extern fn run_command_is_readonly(cmd: String) -> Bool -extern fn cmd_abs_escape_at(cmd: String, root: String, needle: String) -> Bool -extern fn run_command_guard(cmd: String, root: String) -> String -extern fn classify_tool_risk(tool_name: String, tool_input: String) -> String -extern fn dispatch_tool(tool_name: String, tool_input: String) -> String -extern fn is_builtin_tool(tool_name: String) -> Bool -extern fn next_bridge_id() -> String -extern fn handle_chat_plan(body: String) -> String -extern fn handle_chat_agentic(body: String) -> String -extern fn agentic_loop(session_id: String, model: String, safe_sys: String, tools_json: String, messages_in: String, h: Map, tools_log_in: String) -> String -extern fn bridge_save(session_id: String, model: String, safe_sys: String, tools_json: String, messages: String, tools_log: String, tool_use_id: String) -> Bool -extern fn agentic_resume(session_id: String, tool_use_id: String, content: String) -> String -extern fn handle_tool_result(session_id: String, body: String) -> String -extern fn handle_chat_as_soul(body: String) -> String -extern fn handle_dharma_room_turn(body: String) -> String -extern fn handle_dharma_room_turn_agentic(body: String) -> String -extern fn session_summary_write(summary_text: String) -> String -extern fn session_summary_write_dated(summary_text: String, label: String) -> String -extern fn session_summary_autogenerate(hist: String) -> String -extern fn auto_persist(req: String, resp: String) -> Void -extern fn strengthen_chat_nodes(activation_nodes: String) -> Void diff --git a/dist/elp-input.elh b/dist/elp-input.elh deleted file mode 100644 index 8c1531f..0000000 --- a/dist/elp-input.elh +++ /dev/null @@ -1,5 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn elp_extract_topic(msg: String) -> String -extern fn elp_detect_predicate(msg: String) -> String -extern fn elp_parse(msg: String) -> String -extern fn handle_elp_chat(body: String) -> String diff --git a/dist/elp.elh b/dist/elp.elh deleted file mode 100644 index f9d2323..0000000 --- a/dist/elp.elh +++ /dev/null @@ -1,7 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn sem_get(json: String, key: String) -> String -extern fn generate_frame(frame: [String]) -> String -extern fn generate_frame_lang(frame: [String], lang_code: String) -> String -extern fn build_form_from_json(semantic_form_json: String, lang_code: String) -> [String] -extern fn generate(semantic_form_json: String) -> String -extern fn generate_lang(semantic_form_json: String, lang_code: String) -> String diff --git a/dist/grammar.elh b/dist/grammar.elh deleted file mode 100644 index f678627..0000000 --- a/dist/grammar.elh +++ /dev/null @@ -1,38 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn slots_get(slots: [String], key: String) -> String -extern fn slots_set(slots: [String], key: String, val: String) -> [String] -extern fn make_slots(k0: String, v0: String) -> [String] -extern fn make_slots2(k0: String, v0: String, k1: String, v1: String) -> [String] -extern fn make_slots3(k0: String, v0: String, k1: String, v1: String, k2: String, v2: String) -> [String] -extern fn make_slots4(k0: String, v0: String, k1: String, v1: String, k2: String, v2: String, k3: String, v3: String) -> [String] -extern fn make_slots5(k0: String, v0: String, k1: String, v1: String, k2: String, v2: String, k3: String, v3: String, k4: String, v4: String) -> [String] -extern fn rule_id(rule: [String]) -> String -extern fn rule_lhs(rule: [String]) -> String -extern fn rule_rhs_len(rule: [String]) -> Int -extern fn rule_rhs(rule: [String], idx: Int) -> String -extern fn make_rule(id: String, lhs: String, r0: String) -> [String] -extern fn make_rule2(id: String, lhs: String, r0: String, r1: String) -> [String] -extern fn make_rule3(id: String, lhs: String, r0: String, r1: String, r2: String) -> [String] -extern fn make_rule4(id: String, lhs: String, r0: String, r1: String, r2: String, r3: String) -> [String] -extern fn build_rules() -> [[String]] -extern fn get_rules() -> [[String]] -extern fn find_rule(rule_id_str: String) -> [String] -extern fn make_leaf(label: String, word: String) -> String -extern fn make_node1(label: String, child0: String) -> String -extern fn make_node2(label: String, child0: String, child1: String) -> String -extern fn make_node3(label: String, child0: String, child1: String, child2: String) -> String -extern fn make_node4(label: String, child0: String, child1: String, child2: String, child3: String) -> String -extern fn nlg_is_ws(c: String) -> Bool -extern fn skip_ws(s: String, pos: Int) -> Int -extern fn scan_token(s: String, start: Int) -> [String] -extern fn render_tree(tree: String) -> String -extern fn gram_word_order(profile: [String]) -> String -extern fn gram_order_constituents(subj: String, verb: String, obj: String, profile: [String]) -> String -extern fn gram_build_vp(verb: String, aux: String, profile: [String]) -> String -extern fn gram_question_strategy(profile: [String]) -> String -extern fn is_pronoun(word: String) -> Bool -extern fn build_np(referent: String, slots: [String]) -> String -extern fn build_pp(loc: String) -> String -extern fn build_vp_body(slots: [String]) -> String -extern fn build_vp_from_slots(slots: [String]) -> String -extern fn generate_tree(rule_id_str: String, slots: [String]) -> String diff --git a/dist/imprint.elh b/dist/imprint.elh deleted file mode 100644 index 8a29f42..0000000 --- a/dist/imprint.elh +++ /dev/null @@ -1,7 +0,0 @@ -// 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 diff --git a/dist/language-profile.elh b/dist/language-profile.elh deleted file mode 100644 index 8436652..0000000 --- a/dist/language-profile.elh +++ /dev/null @@ -1,46 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn lang_profile(code: String, word_order: String, morph_type: String, has_case: String, has_gender: String, script_dir: String, agreement: String, null_subject: String) -> [String] -extern fn lang_get(profile: [String], key: String) -> String -extern fn lang_profile_en() -> [String] -extern fn lang_profile_ja() -> [String] -extern fn lang_profile_ar() -> [String] -extern fn lang_profile_zh() -> [String] -extern fn lang_profile_de() -> [String] -extern fn lang_profile_es() -> [String] -extern fn lang_profile_fi() -> [String] -extern fn lang_profile_sw() -> [String] -extern fn lang_profile_hi() -> [String] -extern fn lang_profile_ru() -> [String] -extern fn lang_profile_fr() -> [String] -extern fn lang_profile_la() -> [String] -extern fn lang_profile_he() -> [String] -extern fn lang_profile_sa() -> [String] -extern fn lang_profile_got() -> [String] -extern fn lang_profile_non() -> [String] -extern fn lang_profile_enm() -> [String] -extern fn lang_profile_pi() -> [String] -extern fn lang_profile_grc() -> [String] -extern fn lang_profile_ang() -> [String] -extern fn lang_profile_fro() -> [String] -extern fn lang_profile_goh() -> [String] -extern fn lang_profile_sga() -> [String] -extern fn lang_profile_txb() -> [String] -extern fn lang_profile_peo() -> [String] -extern fn lang_profile_akk() -> [String] -extern fn lang_profile_uga() -> [String] -extern fn lang_profile_egy() -> [String] -extern fn lang_profile_sux() -> [String] -extern fn lang_profile_gez() -> [String] -extern fn lang_profile_cop() -> [String] -extern fn lang_from_code(code: String) -> [String] -extern fn lang_default() -> [String] -extern fn lang_is_isolating(profile: [String]) -> Bool -extern fn lang_is_agglutinative(profile: [String]) -> Bool -extern fn lang_is_fusional(profile: [String]) -> Bool -extern fn lang_is_polysynthetic(profile: [String]) -> Bool -extern fn lang_is_rtl(profile: [String]) -> Bool -extern fn lang_has_null_subject(profile: [String]) -> Bool -extern fn lang_has_case(profile: [String]) -> Bool -extern fn lang_has_gender(profile: [String]) -> Bool -extern fn lang_word_order(profile: [String]) -> String -extern fn lang_code(profile: [String]) -> String diff --git a/dist/memory.elh b/dist/memory.elh deleted file mode 100644 index 607cdf7..0000000 --- a/dist/memory.elh +++ /dev/null @@ -1,16 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn tier_working() -> String -extern fn tier_episodic() -> String -extern fn tier_canonical() -> String -extern fn mem_store(content: String, label: String, tags: String) -> String -extern fn mem_remember(content: String, tags: String) -> String -extern fn mem_recall(query: String, depth: Int) -> String -extern fn mem_search(query: String, limit: Int) -> String -extern fn mem_strengthen(node_id: String) -> Void -extern fn mem_forget(node_id: String) -> Void -extern fn mem_consolidate() -> String -extern fn mem_save(path: String) -> Void -extern fn mem_load(path: String) -> Void -extern fn mem_boot_count_get() -> Int -extern fn mem_boot_count_inc() -> Int -extern fn mem_emit_state_event(trigger: String, kind: String, content: String) -> String diff --git a/dist/morphology-akk.elh b/dist/morphology-akk.elh deleted file mode 100644 index 6c3ac12..0000000 --- a/dist/morphology-akk.elh +++ /dev/null @@ -1,31 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn akk_str_ends(s: String, suf: String) -> Bool -extern fn akk_str_len(s: String) -> Int -extern fn akk_str_drop_last(s: String, n: Int) -> String -extern fn akk_slot(person: String, number: String) -> Int -extern fn akk_slot_g(person: String, gender: String, number: String) -> Int -extern fn akk_copula_present(slot: Int) -> String -extern fn akk_copula_stative(slot: Int) -> String -extern fn akk_is_copula(verb: String) -> Bool -extern fn akk_conjugate_copula(tense: String, slot: Int) -> String -extern fn akk_alaku_present(slot: Int) -> String -extern fn akk_alaku_perfect(slot: Int) -> String -extern fn akk_amaru_present(slot: Int) -> String -extern fn akk_amaru_perfect(slot: Int) -> String -extern fn akk_amaru_stative(slot: Int) -> String -extern fn akk_qabu_present(slot: Int) -> String -extern fn akk_qabu_perfect(slot: Int) -> String -extern fn akk_qabu_stative(slot: Int) -> String -extern fn akk_epesu_present(slot: Int) -> String -extern fn akk_epesu_perfect(slot: Int) -> String -extern fn akk_epesu_stative(slot: Int) -> String -extern fn akk_regular_present(stem: String, slot: Int) -> String -extern fn akk_regular_perfect(stem: String, slot: Int) -> String -extern fn akk_regular_stative(stem: String, slot: Int) -> String -extern fn akk_known_verb(verb: String, tense: String, slot: Int) -> String -extern fn akk_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn akk_strip_nom(noun: String) -> String -extern fn akk_is_fem(noun: String) -> Bool -extern fn akk_decline(noun: String, gram_case: String, number: String) -> String -extern fn akk_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String -extern fn akk_map_canonical(verb: String) -> String diff --git a/dist/morphology-ang.elh b/dist/morphology-ang.elh deleted file mode 100644 index 9975651..0000000 --- a/dist/morphology-ang.elh +++ /dev/null @@ -1,44 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn ang_str_ends(s: String, suf: String) -> Bool -extern fn ang_str_drop_last(s: String, n: Int) -> String -extern fn ang_str_last_char(s: String) -> String -extern fn ang_str_last2(s: String) -> String -extern fn ang_slot(person: String, number: String) -> Int -extern fn ang_map_canonical(verb: String) -> String -extern fn ang_wesan_past(slot: Int) -> String -extern fn ang_beon_present(slot: Int) -> String -extern fn ang_wesan_present(slot: Int) -> String -extern fn ang_habban_present(slot: Int) -> String -extern fn ang_habban_past(slot: Int) -> String -extern fn ang_gan_present(slot: Int) -> String -extern fn ang_gan_past(slot: Int) -> String -extern fn ang_cuman_present(slot: Int) -> String -extern fn ang_cuman_past(slot: Int) -> String -extern fn ang_secgan_present(slot: Int) -> String -extern fn ang_secgan_past(slot: Int) -> String -extern fn ang_seon_present(slot: Int) -> String -extern fn ang_seon_past(slot: Int) -> String -extern fn ang_don_present(slot: Int) -> String -extern fn ang_don_past(slot: Int) -> String -extern fn ang_willan_present(slot: Int) -> String -extern fn ang_willan_past(slot: Int) -> String -extern fn ang_magan_present(slot: Int) -> String -extern fn ang_magan_past(slot: Int) -> String -extern fn ang_witan_present(slot: Int) -> String -extern fn ang_witan_past(slot: Int) -> String -extern fn ang_weak_present_ending(slot: Int) -> String -extern fn ang_weak_past_stem(stem: String) -> String -extern fn ang_weak_past(stem: String, slot: Int) -> String -extern fn ang_weak_stem(verb: String) -> String -extern fn ang_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn ang_declension(noun: String, gender: String) -> String -extern fn ang_decline_strong_masc(noun: String, gram_case: String, number: String) -> String -extern fn ang_decline_strong_neut(noun: String, gram_case: String, number: String) -> String -extern fn ang_decline_weak(noun: String, gram_case: String, number: String) -> String -extern fn ang_decline(noun: String, gram_case: String, number: String, gender: String) -> String -extern fn ang_article_masculine(gram_case: String, number: String) -> String -extern fn ang_article_feminine(gram_case: String, number: String) -> String -extern fn ang_article_neuter(gram_case: String, number: String) -> String -extern fn ang_article(gender: String, gram_case: String, number: String) -> String -extern fn ang_infer_gender(noun: String) -> String -extern fn ang_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-ar.elh b/dist/morphology-ar.elh deleted file mode 100644 index 34ef396..0000000 --- a/dist/morphology-ar.elh +++ /dev/null @@ -1,27 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn ar_str_ends(s: String, suf: String) -> Bool -extern fn ar_str_len(s: String) -> Int -extern fn ar_str_drop_last(s: String, n: Int) -> String -extern fn ar_str_last_char(s: String) -> String -extern fn ar_slot(person: String, gender: String, number: String) -> Int -extern fn ar_perfect_suffix(slot: Int) -> String -extern fn ar_imperfect_prefix(slot: Int) -> String -extern fn ar_imperfect_suffix(slot: Int) -> String -extern fn ar_conjugate_form1(past_base: String, present_stem: String, tense: String, slot: Int) -> String -extern fn ar_irregular_kaana(slot: Int, tense: String) -> String -extern fn ar_irregular_qaala(slot: Int, tense: String) -> String -extern fn ar_irregular_jaa(slot: Int, tense: String) -> String -extern fn ar_irregular_raaa(slot: Int, tense: String) -> String -extern fn ar_irregular_araada(slot: Int, tense: String) -> String -extern fn ar_irregular_istata(slot: Int, tense: String) -> String -extern fn ar_irregular(verb: String, tense: String, slot: Int) -> String -extern fn ar_present_stem(verb: String) -> String -extern fn ar_conjugate(verb: String, tense: String, person: String, gender: String, number: String) -> String -extern fn ar_is_sun_letter(c: String) -> Bool -extern fn ar_definite_article(noun: String) -> String -extern fn ar_case_ending(kase: String, definite: String) -> String -extern fn ar_gender(noun: String) -> String -extern fn ar_masc_pl_ending(kase: String) -> String -extern fn ar_sound_plural(noun: String, gender: String) -> String -extern fn ar_noun_form(noun: String, gender: String, kase: String, number: String, definite: String) -> String -extern fn ar_verb_form(verb: String, tense: String, person: String, number: String) -> String diff --git a/dist/morphology-cop.elh b/dist/morphology-cop.elh deleted file mode 100644 index 5ab0cb7..0000000 --- a/dist/morphology-cop.elh +++ /dev/null @@ -1,35 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn cop_str_ends(s: String, suf: String) -> Bool -extern fn cop_str_len(s: String) -> Int -extern fn cop_drop(s: String, n: Int) -> String -extern fn cop_last_char(s: String) -> String -extern fn cop_slot(person: String, number: String) -> Int -extern fn cop_subject_prefix(person: String, number: String) -> String -extern fn cop_subject_prefix_gendered(person: String, gender: String, number: String) -> String -extern fn cop_copula_particle(gender: String, number: String) -> String -extern fn cop_shwpe_present(prefix: String) -> String -extern fn cop_shwpe_perfect(prefix: String) -> String -extern fn cop_shwpe_future(prefix: String) -> String -extern fn cop_bwk_present(prefix: String) -> String -extern fn cop_bwk_perfect(prefix: String) -> String -extern fn cop_bwk_future(prefix: String) -> String -extern fn cop_nau_present(prefix: String) -> String -extern fn cop_nau_perfect(prefix: String) -> String -extern fn cop_nau_future(prefix: String) -> String -extern fn cop_jw_present(prefix: String) -> String -extern fn cop_jw_perfect(prefix: String) -> String -extern fn cop_jw_future(prefix: String) -> String -extern fn cop_di_present(prefix: String) -> String -extern fn cop_di_perfect(prefix: String) -> String -extern fn cop_di_future(prefix: String) -> String -extern fn cop_is_copula(verb: String) -> Bool -extern fn cop_known_verb_prefixed(verb: String, tense: String, prefix: String) -> String -extern fn cop_regular_present(prefix: String, stem: String) -> String -extern fn cop_regular_perfect(prefix: String, stem: String) -> String -extern fn cop_regular_future(prefix: String, stem: String) -> String -extern fn cop_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn cop_article(gender: String, number: String, definite: String) -> String -extern fn cop_decline(noun: String, gram_case: String, number: String) -> String -extern fn cop_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String -extern fn cop_noun_phrase_gendered(noun: String, gram_case: String, number: String, definite: String, gender: String) -> String -extern fn cop_map_canonical(verb: String) -> String diff --git a/dist/morphology-de.elh b/dist/morphology-de.elh deleted file mode 100644 index 0a38b1c..0000000 --- a/dist/morphology-de.elh +++ /dev/null @@ -1,13 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn de_article_def(gender: String, gram_case: String, number: String) -> String -extern fn de_article_indef(gender: String, gram_case: String, number: String) -> String -extern fn de_article(gender: String, gram_case: String, number: String, definite: String) -> String -extern fn de_adj_ending(gender: String, gram_case: String, number: String, article_type: String) -> String -extern fn de_noun_plural(noun: String, gender: String) -> String -extern fn de_case_ending(noun: String, gender: String, gram_case: String, number: String) -> String -extern fn de_conjugate_weak(stem: String, tense: String, person: String, number: String) -> String -extern fn de_irregular_present(verb: String, person: String, number: String) -> String -extern fn de_strong_past_stem(verb: String) -> String -extern fn de_norm_number(number: String) -> String -extern fn de_norm_person(person: String) -> String -extern fn de_conjugate(verb: String, tense: String, person: String, number: String) -> String diff --git a/dist/morphology-egy.elh b/dist/morphology-egy.elh deleted file mode 100644 index ba63eaf..0000000 --- a/dist/morphology-egy.elh +++ /dev/null @@ -1,38 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn egy_str_ends(s: String, suf: String) -> Bool -extern fn egy_str_len(s: String) -> Int -extern fn egy_drop(s: String, n: Int) -> String -extern fn egy_last_char(s: String) -> String -extern fn egy_slot(person: String, number: String) -> Int -extern fn egy_slot_with_gender(person: String, gender: String, number: String) -> Int -extern fn egy_conjugate_pronoun(person: String, number: String) -> String -extern fn egy_suffix_pronoun(slot: Int) -> String -extern fn egy_is_copula(verb: String) -> Bool -extern fn egy_conjugate_copula(tense: String, slot: Int) -> String -extern fn egy_rdi_present(slot: Int) -> String -extern fn egy_rdi_past(slot: Int) -> String -extern fn egy_rdi_future(slot: Int) -> String -extern fn egy_mAA_present(slot: Int) -> String -extern fn egy_mAA_past(slot: Int) -> String -extern fn egy_mAA_future(slot: Int) -> String -extern fn egy_Dd_present(slot: Int) -> String -extern fn egy_Dd_past(slot: Int) -> String -extern fn egy_Dd_future(slot: Int) -> String -extern fn egy_Sm_present(slot: Int) -> String -extern fn egy_Sm_past(slot: Int) -> String -extern fn egy_Sm_future(slot: Int) -> String -extern fn egy_iri_present(slot: Int) -> String -extern fn egy_iri_past(slot: Int) -> String -extern fn egy_iri_future(slot: Int) -> String -extern fn egy_sdm_present(slot: Int) -> String -extern fn egy_sdm_past(slot: Int) -> String -extern fn egy_sdm_future(slot: Int) -> String -extern fn egy_known_verb(verb: String, tense: String, slot: Int) -> String -extern fn egy_regular_present(stem: String, slot: Int) -> String -extern fn egy_regular_past(stem: String, slot: Int) -> String -extern fn egy_regular_future(stem: String, slot: Int) -> String -extern fn egy_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn egy_decline(noun: String, gram_case: String, number: String) -> String -extern fn egy_fem(noun: String) -> String -extern fn egy_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String -extern fn egy_map_canonical(verb: String) -> String diff --git a/dist/morphology-enm.elh b/dist/morphology-enm.elh deleted file mode 100644 index f6f4195..0000000 --- a/dist/morphology-enm.elh +++ /dev/null @@ -1,30 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn enm_str_ends(s: String, suf: String) -> Bool -extern fn enm_drop(s: String, n: Int) -> String -extern fn enm_first_char(s: String) -> String -extern fn enm_slot(person: String, number: String) -> Int -extern fn enm_been_present(slot: Int) -> String -extern fn enm_been_past(slot: Int) -> String -extern fn enm_haven_present(slot: Int) -> String -extern fn enm_haven_past(slot: Int) -> String -extern fn enm_goon_present(slot: Int) -> String -extern fn enm_goon_past(slot: Int) -> String -extern fn enm_seen_present(slot: Int) -> String -extern fn enm_seen_past(slot: Int) -> String -extern fn enm_seyen_present(slot: Int) -> String -extern fn enm_seyen_past(slot: Int) -> String -extern fn enm_comen_present(slot: Int) -> String -extern fn enm_comen_past(slot: Int) -> String -extern fn enm_maken_present(slot: Int) -> String -extern fn enm_maken_past(slot: Int) -> String -extern fn enm_map_canonical(verb: String) -> String -extern fn enm_weak_stem(verb: String) -> String -extern fn enm_weak_present(stem: String, slot: Int) -> String -extern fn enm_weak_past(stem: String, slot: Int) -> String -extern fn enm_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn enm_irregular_plural(noun: String) -> String -extern fn enm_make_plural(noun: String) -> String -extern fn enm_decline(noun: String, gram_case: String, number: String) -> String -extern fn enm_is_vowel_initial(s: String) -> Bool -extern fn enm_indef_article(noun_phrase: String) -> String -extern fn enm_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-es.elh b/dist/morphology-es.elh deleted file mode 100644 index a2ea5cd..0000000 --- a/dist/morphology-es.elh +++ /dev/null @@ -1,23 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn es_str_ends(s: String, suf: String) -> Bool -extern fn es_str_drop_last(s: String, n: Int) -> String -extern fn es_str_last_char(s: String) -> String -extern fn es_str_last2(s: String) -> String -extern fn es_str_last3(s: String) -> String -extern fn es_verb_class(base: String) -> String -extern fn es_stem(base: String) -> String -extern fn es_slot(person: String, number: String) -> Int -extern fn es_irregular_present(verb: String, person: String, number: String) -> String -extern fn es_irregular_preterite(verb: String, person: String, number: String) -> String -extern fn es_irregular_imperfect(verb: String, person: String, number: String) -> String -extern fn es_regular_present(stem: String, vclass: String, slot: Int) -> String -extern fn es_regular_preterite(stem: String, vclass: String, slot: Int) -> String -extern fn es_regular_future(base: String, slot: Int) -> String -extern fn es_irregular_future_stem(verb: String) -> String -extern fn es_regular_imperfect(stem: String, vclass: String, slot: Int) -> String -extern fn es_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn es_gender(noun: String) -> String -extern fn es_invariant_plural(noun: String) -> String -extern fn es_pluralize(noun: String) -> String -extern fn es_starts_with_stressed_a(noun: String) -> Bool -extern fn es_agree_article(noun: String, definite: String, number: String) -> String diff --git a/dist/morphology-fi.elh b/dist/morphology-fi.elh deleted file mode 100644 index fc991ec..0000000 --- a/dist/morphology-fi.elh +++ /dev/null @@ -1,17 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn fi_harmony(word: String) -> String -extern fn fi_suffix(base: String, harmony: String) -> String -extern fn fi_noun_case(stem: String, gram_case: String, number: String, harmony: String) -> String -extern fn fi_str_last_char(s: String) -> String -extern fn fi_apply_case(noun: String, gram_case: String, number: String) -> String -extern fn fi_verb_stem(dict_form: String) -> String -extern fn fi_irregular_verb(dict_form: String) -> [String] -extern fn fi_present_ending(stem: String, person: String, number: String, harmony: String) -> String -extern fn fi_past_stem(stem: String) -> String -extern fn fi_past_ending(stem: String, person: String, number: String, harmony: String) -> String -extern fn fi_neg_aux(person: String, number: String) -> String -extern fn fi_negative(verb: String, person: String, number: String) -> String -extern fn fi_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn fi_question_suffix(harmony: String) -> String -extern fn fi_make_question(verb_form: String, harmony: String) -> String -extern fn fi_full_paradigm(noun: String) -> [String] diff --git a/dist/morphology-fr.elh b/dist/morphology-fr.elh deleted file mode 100644 index a36ab8f..0000000 --- a/dist/morphology-fr.elh +++ /dev/null @@ -1,29 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn fr_str_ends(s: String, suf: String) -> Bool -extern fn fr_str_drop_last(s: String, n: Int) -> String -extern fn fr_str_last_char(s: String) -> String -extern fn fr_str_last2(s: String) -> String -extern fn fr_is_vowel_start(s: String) -> Bool -extern fn fr_is_known_irregular(verb: String) -> Bool -extern fn fr_verb_group(base: String) -> String -extern fn fr_stem(base: String) -> String -extern fn fr_slot(person: String, number: String) -> Int -extern fn fr_irregular_present(verb: String, person: String, number: String) -> String -extern fn fr_regular_present(stem: String, vgroup: String, slot: Int) -> String -extern fn fr_future_stem(base: String, vgroup: String) -> String -extern fn fr_regular_future(fstem: String, slot: Int) -> String -extern fn fr_irregular_future_stem(verb: String) -> String -extern fn fr_imperfect_stem(base: String, vgroup: String) -> String -extern fn fr_regular_imperfect(istem: String, slot: Int) -> String -extern fn fr_uses_etre(verb: String) -> Bool -extern fn fr_past_participle(verb: String) -> String -extern fn fr_avoir_present(slot: Int) -> String -extern fn fr_etre_present(slot: Int) -> String -extern fn fr_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn fr_gender(noun: String) -> String -extern fn fr_invariant_plural(noun: String) -> String -extern fn fr_pluralize(noun: String) -> String -extern fn fr_agree_article(noun: String, definite: String, number: String) -> String -extern fn fr_subject_starts_vowel(subject: String) -> Bool -extern fn fr_verb_ends_vowel(verb_form: String) -> Bool -extern fn fr_question_inversion(subject: String, verb_form: String) -> String diff --git a/dist/morphology-fro.elh b/dist/morphology-fro.elh deleted file mode 100644 index 477bbae..0000000 --- a/dist/morphology-fro.elh +++ /dev/null @@ -1,38 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn fro_str_ends(s: String, suf: String) -> Bool -extern fn fro_drop(s: String, n: Int) -> String -extern fn fro_slot(person: String, number: String) -> Int -extern fn fro_map_canonical(verb: String) -> String -extern fn fro_estre_present(slot: Int) -> String -extern fn fro_estre_past(slot: Int) -> String -extern fn fro_estre_future(slot: Int) -> String -extern fn fro_avoir_present(slot: Int) -> String -extern fn fro_avoir_past(slot: Int) -> String -extern fn fro_avoir_future(slot: Int) -> String -extern fn fro_aler_present(slot: Int) -> String -extern fn fro_aler_past(slot: Int) -> String -extern fn fro_aler_future(slot: Int) -> String -extern fn fro_venir_present(slot: Int) -> String -extern fn fro_venir_past(slot: Int) -> String -extern fn fro_venir_future(slot: Int) -> String -extern fn fro_faire_present(slot: Int) -> String -extern fn fro_faire_past(slot: Int) -> String -extern fn fro_faire_future(slot: Int) -> String -extern fn fro_verb_class(verb: String) -> String -extern fn fro_verb_stem(verb: String, vclass: String) -> String -extern fn fro_conj1_present(stem: String, slot: Int) -> String -extern fn fro_conj1_past(stem: String, slot: Int) -> String -extern fn fro_conj1_future(verb: String, slot: Int) -> String -extern fn fro_conj2_present(stem: String, slot: Int) -> String -extern fn fro_conj2_past(stem: String, slot: Int) -> String -extern fn fro_conj2_future(verb: String, slot: Int) -> String -extern fn fro_conj3_present(stem: String, slot: Int) -> String -extern fn fro_conj3_past(stem: String, slot: Int) -> String -extern fn fro_conj3_future(verb: String, slot: Int) -> String -extern fn fro_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn fro_gender(noun: String) -> String -extern fn fro_decline_masc(noun: String, gram_case: String, number: String) -> String -extern fn fro_decline_fem(noun: String, number: String) -> String -extern fn fro_decline(noun: String, gram_case: String, number: String) -> String -extern fn fro_article(gender: String, gram_case: String, number: String) -> String -extern fn fro_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-gez.elh b/dist/morphology-gez.elh deleted file mode 100644 index b23da81..0000000 --- a/dist/morphology-gez.elh +++ /dev/null @@ -1,26 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn gez_str_ends(s: String, suf: String) -> Bool -extern fn gez_str_len(s: String) -> Int -extern fn gez_str_drop_last(s: String, n: Int) -> String -extern fn gez_slot(person: String, number: String) -> Int -extern fn gez_slot_g(person: String, gender: String, number: String) -> Int -extern fn gez_kwn_perfect(slot: Int) -> String -extern fn gez_kwn_imperfect(slot: Int) -> String -extern fn gez_is_copula(verb: String) -> Bool -extern fn gez_conjugate_copula(tense: String, slot: Int) -> String -extern fn gez_hlw_perfect(slot: Int) -> String -extern fn gez_hlw_imperfect(slot: Int) -> String -extern fn gez_hbl_perfect(slot: Int) -> String -extern fn gez_hbl_imperfect(slot: Int) -> String -extern fn gez_ray_perfect(slot: Int) -> String -extern fn gez_ray_imperfect(slot: Int) -> String -extern fn gez_qwl_perfect(slot: Int) -> String -extern fn gez_qwl_imperfect(slot: Int) -> String -extern fn gez_generic_perfect(base3sg: String, slot: Int) -> String -extern fn gez_generic_imperfect(base3sg: String, slot: Int) -> String -extern fn gez_known_verb(verb: String, tense: String, slot: Int) -> String -extern fn gez_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn gez_is_fidel(noun: String) -> Bool -extern fn gez_decline(noun: String, gram_case: String, number: String) -> String -extern fn gez_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String -extern fn gez_map_canonical(verb: String) -> String diff --git a/dist/morphology-goh.elh b/dist/morphology-goh.elh deleted file mode 100644 index 3836290..0000000 --- a/dist/morphology-goh.elh +++ /dev/null @@ -1,34 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn goh_str_ends(s: String, suf: String) -> Bool -extern fn goh_drop(s: String, n: Int) -> String -extern fn goh_slot(person: String, number: String) -> Int -extern fn goh_map_canonical(verb: String) -> String -extern fn goh_wesan_present(slot: Int) -> String -extern fn goh_wesan_past(slot: Int) -> String -extern fn goh_haben_present(slot: Int) -> String -extern fn goh_haben_past(slot: Int) -> String -extern fn goh_gan_present(slot: Int) -> String -extern fn goh_gan_past(slot: Int) -> String -extern fn goh_sehan_present(slot: Int) -> String -extern fn goh_sehan_past(slot: Int) -> String -extern fn goh_quethan_present(slot: Int) -> String -extern fn goh_quethan_past(slot: Int) -> String -extern fn goh_tuon_present(slot: Int) -> String -extern fn goh_tuon_past(slot: Int) -> String -extern fn goh_weak_present(stem: String, slot: Int) -> String -extern fn goh_weak_past(stem: String, slot: Int) -> String -extern fn goh_verb_stem(verb: String) -> String -extern fn goh_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn goh_stem_type(noun: String) -> String -extern fn goh_extract_stem(noun: String, stype: String) -> String -extern fn goh_decline_masc_a_sg(stem: String, gram_case: String) -> String -extern fn goh_decline_masc_a_pl(stem: String, gram_case: String) -> String -extern fn goh_decline_fem_o_sg(stem: String, gram_case: String) -> String -extern fn goh_decline_fem_o_pl(stem: String, gram_case: String) -> String -extern fn goh_decline_neut_a_sg(stem: String, gram_case: String) -> String -extern fn goh_decline_neut_a_pl(stem: String, gram_case: String) -> String -extern fn goh_decline_masc_n_sg(stem: String, gram_case: String) -> String -extern fn goh_decline_masc_n_pl(stem: String, gram_case: String) -> String -extern fn goh_decline(noun: String, gram_case: String, number: String) -> String -extern fn goh_demo_article(stype: String, number: String) -> String -extern fn goh_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-got.elh b/dist/morphology-got.elh deleted file mode 100644 index f5cc1ba..0000000 --- a/dist/morphology-got.elh +++ /dev/null @@ -1,37 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn got_str_ends(s: String, suf: String) -> Bool -extern fn got_str_drop_last(s: String, n: Int) -> String -extern fn got_slot(person: String, number: String) -> Int -extern fn got_map_canonical(verb: String) -> String -extern fn got_wisan_present(slot: Int) -> String -extern fn got_wisan_past(slot: Int) -> String -extern fn got_haban_present(slot: Int) -> String -extern fn got_haban_past(slot: Int) -> String -extern fn got_gaggan_present(slot: Int) -> String -extern fn got_gaggan_past(slot: Int) -> String -extern fn got_saihwan_present(slot: Int) -> String -extern fn got_saihwan_past(slot: Int) -> String -extern fn got_qithan_present(slot: Int) -> String -extern fn got_qithan_past(slot: Int) -> String -extern fn got_niman_present(slot: Int) -> String -extern fn got_niman_past(slot: Int) -> String -extern fn got_wk1_present_ending(slot: Int) -> String -extern fn got_wk1_past_ending(slot: Int) -> String -extern fn got_wk1_conjugate(stem: String, tense: String, slot: Int) -> String -extern fn got_wk2_present_ending(slot: Int) -> String -extern fn got_wk2_past_ending(slot: Int) -> String -extern fn got_wk2_conjugate(stem: String, tense: String, slot: Int) -> String -extern fn got_verb_class(verb: String) -> String -extern fn got_verb_stem(verb: String, vclass: String) -> String -extern fn got_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn got_decline_a_stem_sg(stem: String, gram_case: String) -> String -extern fn got_decline_a_stem_pl(stem: String, gram_case: String) -> String -extern fn got_decline_o_stem_sg(stem: String, gram_case: String) -> String -extern fn got_decline_o_stem_pl(stem: String, gram_case: String) -> String -extern fn got_decline_n_stem_sg(stem: String, gram_case: String) -> String -extern fn got_decline_n_stem_pl(stem: String, gram_case: String) -> String -extern fn got_stem_type(noun: String) -> String -extern fn got_extract_stem(noun: String, stype: String) -> String -extern fn got_demo_article(stype: String) -> String -extern fn got_decline(noun: String, gram_case: String, number: String) -> String -extern fn got_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-grc.elh b/dist/morphology-grc.elh deleted file mode 100644 index 1f565f0..0000000 --- a/dist/morphology-grc.elh +++ /dev/null @@ -1,45 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn grc_str_ends(s: String, suf: String) -> Bool -extern fn grc_str_drop_last(s: String, n: Int) -> String -extern fn grc_str_last_char(s: String) -> String -extern fn grc_str_last2(s: String) -> String -extern fn grc_str_last3(s: String) -> String -extern fn grc_slot(person: String, number: String) -> Int -extern fn grc_map_canonical(verb: String) -> String -extern fn grc_einai_present(slot: Int) -> String -extern fn grc_einai_imperfect(slot: Int) -> String -extern fn grc_einai_future(slot: Int) -> String -extern fn grc_echein_present(slot: Int) -> String -extern fn grc_echein_imperfect(slot: Int) -> String -extern fn grc_echein_aorist(slot: Int) -> String -extern fn grc_echein_future(slot: Int) -> String -extern fn grc_legein_present(slot: Int) -> String -extern fn grc_legein_imperfect(slot: Int) -> String -extern fn grc_legein_aorist(slot: Int) -> String -extern fn grc_legein_future(slot: Int) -> String -extern fn grc_horao_present(slot: Int) -> String -extern fn grc_horao_imperfect(slot: Int) -> String -extern fn grc_horao_aorist(slot: Int) -> String -extern fn grc_horao_future(slot: Int) -> String -extern fn grc_erchesthai_present(slot: Int) -> String -extern fn grc_erchesthai_imperfect(slot: Int) -> String -extern fn grc_erchesthai_aorist(slot: Int) -> String -extern fn grc_erchesthai_future(slot: Int) -> String -extern fn grc_thematic_present_ending(slot: Int) -> String -extern fn grc_thematic_imperfect_ending(slot: Int) -> String -extern fn grc_thematic_future_ending(slot: Int) -> String -extern fn grc_weak_aorist_ending(slot: Int) -> String -extern fn grc_present_stem(verb: String) -> String -extern fn grc_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn grc_declension(noun: String) -> String -extern fn grc_decline_2m(stem: String, gram_case: String, number: String) -> String -extern fn grc_decline_2n(stem: String, gram_case: String, number: String) -> String -extern fn grc_decline_1a(stem: String, gram_case: String, number: String) -> String -extern fn grc_decline_1e(stem: String, gram_case: String, number: String) -> String -extern fn grc_decline(noun: String, gram_case: String, number: String) -> String -extern fn grc_article_masculine(gram_case: String, number: String) -> String -extern fn grc_article_feminine(gram_case: String, number: String) -> String -extern fn grc_article_neuter(gram_case: String, number: String) -> String -extern fn grc_article(gender: String, gram_case: String, number: String) -> String -extern fn grc_infer_gender(noun: String) -> String -extern fn grc_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-he.elh b/dist/morphology-he.elh deleted file mode 100644 index 4d1241b..0000000 --- a/dist/morphology-he.elh +++ /dev/null @@ -1,30 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn he_str_ends(s: String, suf: String) -> Bool -extern fn he_str_len(s: String) -> Int -extern fn he_str_drop_last(s: String, n: Int) -> String -extern fn he_str_last_char(s: String) -> String -extern fn he_slot(person: String, gender: String, number: String) -> Int -extern fn he_present_form_code(slot: Int) -> Int -extern fn he_copula_past(slot: Int) -> String -extern fn he_copula_future(slot: Int) -> String -extern fn he_is_copula(verb: String) -> Bool -extern fn he_conjugate_copula(tense: String, slot: Int) -> String -extern fn he_present_lir_ot(form: Int) -> String -extern fn he_present_le_exol(form: Int) -> String -extern fn he_present_ledaber(form: Int) -> String -extern fn he_present_lalechet(form: Int) -> String -extern fn he_past_lir_ot(slot: Int) -> String -extern fn he_past_le_exol(slot: Int) -> String -extern fn he_past_ledaber(slot: Int) -> String -extern fn he_past_lalechet(slot: Int) -> String -extern fn he_future_lir_ot(slot: Int) -> String -extern fn he_future_le_exol(slot: Int) -> String -extern fn he_future_ledaber(slot: Int) -> String -extern fn he_future_lalechet(slot: Int) -> String -extern fn he_known_verb(verb: String, tense: String, slot: Int) -> String -extern fn he_conjugate(verb: String, tense: String, person: String, gender: String, number: String) -> String -extern fn he_pluralize(noun: String, gender: String) -> String -extern fn he_is_hebrew_script(noun: String) -> Bool -extern fn he_definite_prefix(noun: String) -> String -extern fn he_noun_phrase(noun: String, number: String, gender: String, definite: String) -> String -extern fn he_map_canonical(verb: String) -> String diff --git a/dist/morphology-hi.elh b/dist/morphology-hi.elh deleted file mode 100644 index 688c51a..0000000 --- a/dist/morphology-hi.elh +++ /dev/null @@ -1,27 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn hi_str_ends(s: String, suf: String) -> Bool -extern fn hi_str_drop_last(s: String, n: Int) -> String -extern fn hi_str_last_char(s: String) -> String -extern fn hi_gender(noun: String) -> String -extern fn hi_masc_aa_stem(noun: String) -> String -extern fn hi_noun_direct_m(noun: String, number: String) -> String -extern fn hi_noun_oblique_m(noun: String, number: String) -> String -extern fn hi_noun_direct_f(noun: String, number: String) -> String -extern fn hi_noun_oblique_f(noun: String, number: String) -> String -extern fn hi_noun_direct(noun: String, gender: String, number: String) -> String -extern fn hi_noun_oblique(noun: String, gender: String, number: String) -> String -extern fn hi_postposition(gram_case: String) -> String -extern fn hi_agree_genitive(possessed_gender: String, possessed_number: String) -> String -extern fn hi_verb_stem(infinitive: String) -> String -extern fn hi_verb_stem_clean(infinitive: String) -> String -extern fn hi_present_aspect(gender: String, number: String) -> String -extern fn hi_aux_present(person: String, number: String) -> String -extern fn hi_past_suffix(gender: String, number: String) -> String -extern fn hi_past_irregular(stem: String, gender: String, number: String) -> String -extern fn hi_future_suffix(person: String, number: String, gender: String) -> String -extern fn hi_tense_suffix(tense: String, gender: String, number: String) -> String -extern fn hi_hona_present(person: String, number: String) -> String -extern fn hi_hona_past(gender: String, number: String) -> String -extern fn hi_conjugate(verb: String, tense: String, person: String, gender: String, number: String) -> String -extern fn hi_noun_with_post(noun: String, gender: String, number: String, gram_case: String) -> String -extern fn hi_genitive_phrase(possessor: String, possessor_gender: String, possessor_number: String, possessed: String, possessed_gender: String, possessed_number: String) -> String diff --git a/dist/morphology-ja.elh b/dist/morphology-ja.elh deleted file mode 100644 index ee2f337..0000000 --- a/dist/morphology-ja.elh +++ /dev/null @@ -1,9 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn ja_verb_group(dict_form: String) -> String -extern fn ja_ichidan_stem(dict_form: String) -> String -extern fn ja_godan_stem_change(dict_form: String, row: String) -> String -extern fn ja_conjugate(dict_form: String, form: String) -> String -extern fn ja_particle(gram_case: String) -> String -extern fn ja_noun_phrase(noun: String, gram_case: String) -> String -extern fn ja_question_particle() -> String -extern fn ja_make_question(sentence: String) -> String diff --git a/dist/morphology-la.elh b/dist/morphology-la.elh deleted file mode 100644 index d31a70a..0000000 --- a/dist/morphology-la.elh +++ /dev/null @@ -1,41 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn la_str_ends(s: String, suf: String) -> Bool -extern fn la_str_drop_last(s: String, n: Int) -> String -extern fn la_str_last_char(s: String) -> String -extern fn la_str_last2(s: String) -> String -extern fn la_str_last3(s: String) -> String -extern fn la_slot(person: String, number: String) -> Int -extern fn la_verb_class(verb: String) -> String -extern fn la_stem(verb: String, vclass: String) -> String -extern fn la_perfect_stem(verb: String, vclass: String) -> String -extern fn la_perfect_ending(slot: Int) -> String -extern fn la_present_ending(vclass: String, slot: Int) -> String -extern fn la_present_form(stem: String, vclass: String, slot: Int) -> String -extern fn la_future_ending_12(slot: Int) -> String -extern fn la_future_ending_34(slot: Int) -> String -extern fn la_future_form(stem: String, vclass: String, slot: Int) -> String -extern fn la_esse_present(slot: Int) -> String -extern fn la_esse_past(slot: Int) -> String -extern fn la_esse_future(slot: Int) -> String -extern fn la_ire_present(slot: Int) -> String -extern fn la_ire_past(slot: Int) -> String -extern fn la_ire_future(slot: Int) -> String -extern fn la_velle_present(slot: Int) -> String -extern fn la_velle_past(slot: Int) -> String -extern fn la_velle_future(slot: Int) -> String -extern fn la_posse_present(slot: Int) -> String -extern fn la_posse_past(slot: Int) -> String -extern fn la_posse_future(slot: Int) -> String -extern fn la_irregular_perfect_stem(verb: String) -> String -extern fn la_map_canonical(verb: String) -> String -extern fn la_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn la_declension(noun: String) -> String -extern fn la_decline_1(stem: String, gram_case: String, number: String) -> String -extern fn la_decline_2m(stem: String, gram_case: String, number: String) -> String -extern fn la_decline_2n(stem: String, gram_case: String, number: String) -> String -extern fn la_decline_3(noun: String, gram_case: String, number: String) -> String -extern fn la_decline_4(stem: String, gram_case: String, number: String) -> String -extern fn la_decline_5(stem: String, gram_case: String, number: String) -> String -extern fn la_decline_2er(noun: String, gram_case: String, number: String) -> String -extern fn la_decline(noun: String, gram_case: String, number: String) -> String -extern fn la_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-non.elh b/dist/morphology-non.elh deleted file mode 100644 index 931b540..0000000 --- a/dist/morphology-non.elh +++ /dev/null @@ -1,30 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn non_str_ends(s: String, suf: String) -> Bool -extern fn non_drop(s: String, n: Int) -> String -extern fn non_last(s: String) -> String -extern fn non_slot(person: String, number: String) -> Int -extern fn non_vera_present(slot: Int) -> String -extern fn non_vera_past(slot: Int) -> String -extern fn non_hafa_present(slot: Int) -> String -extern fn non_hafa_past(slot: Int) -> String -extern fn non_ganga_present(slot: Int) -> String -extern fn non_ganga_past(slot: Int) -> String -extern fn non_sja_present(slot: Int) -> String -extern fn non_sja_past(slot: Int) -> String -extern fn non_segja_present(slot: Int) -> String -extern fn non_segja_past(slot: Int) -> String -extern fn non_koma_present(slot: Int) -> String -extern fn non_koma_past(slot: Int) -> String -extern fn non_map_canonical(verb: String) -> String -extern fn non_weak_present(stem: String, slot: Int) -> String -extern fn non_weak_past(stem: String, slot: Int) -> String -extern fn non_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn non_decline_masc(noun: String, gram_case: String, number: String) -> String -extern fn non_decline_fem(noun: String, gram_case: String, number: String) -> String -extern fn non_decline_neut(noun: String, gram_case: String, number: String) -> String -extern fn non_detect_gender(noun: String) -> String -extern fn non_decline(noun: String, gram_case: String, number: String) -> String -extern fn non_def_suffix_masc(gram_case: String, number: String) -> String -extern fn non_def_suffix_neut(gram_case: String, number: String) -> String -extern fn non_def_suffix_fem(gram_case: String, number: String) -> String -extern fn non_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-peo.elh b/dist/morphology-peo.elh deleted file mode 100644 index f0f408b..0000000 --- a/dist/morphology-peo.elh +++ /dev/null @@ -1,19 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn peo_drop(s: String, n: Int) -> String -extern fn peo_ends(s: String, suf: String) -> Bool -extern fn peo_slot(person: String, number: String) -> Int -extern fn peo_present_suffix(slot: Int) -> String -extern fn peo_past_suffix(slot: Int) -> String -extern fn peo_ah_present(slot: Int) -> String -extern fn peo_ah_past(slot: Int) -> String -extern fn peo_kar_present(slot: Int) -> String -extern fn peo_kar_past(slot: Int) -> String -extern fn peo_xsaya_present(slot: Int) -> String -extern fn peo_tar_present(slot: Int) -> String -extern fn peo_da_present(slot: Int) -> String -extern fn peo_da_past(slot: Int) -> String -extern fn peo_map_canonical(verb: String) -> String -extern fn peo_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn peo_decline_astem(noun: String, gram_case: String, number: String) -> String -extern fn peo_decline(noun: String, gram_case: String, number: String) -> String -extern fn peo_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-pi.elh b/dist/morphology-pi.elh deleted file mode 100644 index 1bbf880..0000000 --- a/dist/morphology-pi.elh +++ /dev/null @@ -1,34 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn pi_str_ends(s: String, suf: String) -> Bool -extern fn pi_drop(s: String, n: Int) -> String -extern fn pi_last_char(s: String) -> String -extern fn pi_slot(person: String, number: String) -> Int -extern fn pi_present_ending(slot: Int) -> String -extern fn pi_aorist_ending(slot: Int) -> String -extern fn pi_future_ending(slot: Int) -> String -extern fn pi_hoti_present(slot: Int) -> String -extern fn pi_atthi_present(slot: Int) -> String -extern fn pi_hoti_aorist(slot: Int) -> String -extern fn pi_hoti_future(slot: Int) -> String -extern fn pi_gacchati_present(slot: Int) -> String -extern fn pi_gacchati_aorist(slot: Int) -> String -extern fn pi_gacchati_future(slot: Int) -> String -extern fn pi_passati_present(slot: Int) -> String -extern fn pi_passati_aorist(slot: Int) -> String -extern fn pi_passati_future(slot: Int) -> String -extern fn pi_vadati_present(slot: Int) -> String -extern fn pi_vadati_aorist(slot: Int) -> String -extern fn pi_vadati_future(slot: Int) -> String -extern fn pi_karoti_present(slot: Int) -> String -extern fn pi_karoti_aorist(slot: Int) -> String -extern fn pi_karoti_future(slot: Int) -> String -extern fn pi_map_canonical(verb: String) -> String -extern fn pi_regular_root(verb: String) -> String -extern fn pi_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn pi_decline_a_masc_sg(stem: String, gram_case: String) -> String -extern fn pi_decline_a_masc_pl(stem: String, gram_case: String) -> String -extern fn pi_decline_a_fem_sg(stem: String, gram_case: String) -> String -extern fn pi_decline_a_fem_pl(stem: String, gram_case: String) -> String -extern fn pi_detect_class(noun: String) -> String -extern fn pi_decline(noun: String, gram_case: String, number: String) -> String -extern fn pi_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-ru.elh b/dist/morphology-ru.elh deleted file mode 100644 index 1f0f081..0000000 --- a/dist/morphology-ru.elh +++ /dev/null @@ -1,14 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn ru_gender(noun: String) -> String -extern fn ru_stem_type(noun: String, gender: String) -> String -extern fn ru_noun_case(noun: String, gender: String, gram_case: String, number: String) -> String -extern fn ru_decline_regular(noun: String, gender: String, stype: String, gram_case: String, number: String) -> String -extern fn ru_decline_masc(noun: String, stype: String, gram_case: String, number: String) -> String -extern fn ru_decline_fem(noun: String, stype: String, gram_case: String, number: String) -> String -extern fn ru_decline_neut(noun: String, stype: String, gram_case: String, number: String) -> String -extern fn ru_past_agree(verb_stem: String, gender: String, number: String) -> String -extern fn ru_conjugate_1st(stem: String, tense: String, person: String, number: String) -> String -extern fn ru_conjugate_2nd(stem: String, tense: String, person: String, number: String) -> String -extern fn ru_irregular(verb: String, tense: String, person: String, number: String) -> String -extern fn ru_past_stem(verb: String) -> String -extern fn ru_conjugate(verb: String, tense: String, person: String, number: String, gender: String) -> String diff --git a/dist/morphology-sa.elh b/dist/morphology-sa.elh deleted file mode 100644 index 2583d3d..0000000 --- a/dist/morphology-sa.elh +++ /dev/null @@ -1,36 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn sa_str_ends(s: String, suf: String) -> Bool -extern fn sa_str_drop_last(s: String, n: Int) -> String -extern fn sa_slot(person: String, number: String) -> Int -extern fn sa_map_canonical(verb: String) -> String -extern fn sa_as_present(slot: Int) -> String -extern fn sa_as_past(slot: Int) -> String -extern fn sa_as_future(slot: Int) -> String -extern fn sa_bhu_present(slot: Int) -> String -extern fn sa_bhu_past(slot: Int) -> String -extern fn sa_bhu_future(slot: Int) -> String -extern fn sa_gam_present(slot: Int) -> String -extern fn sa_gam_past(slot: Int) -> String -extern fn sa_gam_future(slot: Int) -> String -extern fn sa_drs_present(slot: Int) -> String -extern fn sa_drs_past(slot: Int) -> String -extern fn sa_drs_future(slot: Int) -> String -extern fn sa_vad_present(slot: Int) -> String -extern fn sa_vad_past(slot: Int) -> String -extern fn sa_vad_future(slot: Int) -> String -extern fn sa_kr_present(slot: Int) -> String -extern fn sa_kr_past(slot: Int) -> String -extern fn sa_kr_future(slot: Int) -> String -extern fn sa_class1_present_ending(slot: Int) -> String -extern fn sa_class1_past_ending(slot: Int) -> String -extern fn sa_class1_future_ending(slot: Int) -> String -extern fn sa_class1_conjugate(stem: String, tense: String, slot: Int) -> String -extern fn sa_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn sa_decline_a_stem_sg(stem: String, gram_case: String) -> String -extern fn sa_decline_a_stem_pl(stem: String, gram_case: String) -> String -extern fn sa_decline_aa_stem_sg(stem: String, gram_case: String) -> String -extern fn sa_decline_aa_stem_pl(stem: String, gram_case: String) -> String -extern fn sa_stem_type(noun: String) -> String -extern fn sa_extract_stem(noun: String, stype: String) -> String -extern fn sa_decline(noun: String, gram_case: String, number: String) -> String -extern fn sa_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-sga.elh b/dist/morphology-sga.elh deleted file mode 100644 index 704ea1b..0000000 --- a/dist/morphology-sga.elh +++ /dev/null @@ -1,22 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn sga_drop(s: String, n: Int) -> String -extern fn sga_first(s: String) -> String -extern fn sga_rest(s: String) -> String -extern fn sga_slot(person: String, number: String) -> Int -extern fn sga_lenite(word: String) -> String -extern fn sga_copula_present(slot: Int) -> String -extern fn sga_bith_present(slot: Int) -> String -extern fn sga_bith_past(slot: Int) -> String -extern fn sga_teit_present(slot: Int) -> String -extern fn sga_teit_past(slot: Int) -> String -extern fn sga_gaibid_present(slot: Int) -> String -extern fn sga_adci_present(slot: Int) -> String -extern fn sga_asbeir_present(slot: Int) -> String -extern fn sga_map_canonical(verb: String) -> String -extern fn sga_ai_present(stem: String, slot: Int) -> String -extern fn sga_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn sga_decline_ostem(noun: String, gram_case: String, number: String) -> String -extern fn sga_decline_astem(noun: String, gram_case: String, number: String) -> String -extern fn sga_detect_gender(noun: String) -> String -extern fn sga_decline(noun: String, gram_case: String, number: String) -> String -extern fn sga_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-sux.elh b/dist/morphology-sux.elh deleted file mode 100644 index f476446..0000000 --- a/dist/morphology-sux.elh +++ /dev/null @@ -1,29 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn sux_str_ends(s: String, suf: String) -> Bool -extern fn sux_str_drop_last(s: String, n: Int) -> String -extern fn sux_str_last_char(s: String) -> String -extern fn sux_str_last2(s: String) -> String -extern fn sux_slot(person: String, number: String) -> Int -extern fn sux_ergative_suffix(person: String, number: String) -> String -extern fn sux_absolutive_suffix(person: String, number: String) -> String -extern fn sux_map_canonical(verb: String) -> String -extern fn sux_personal_suffix(slot: Int) -> String -extern fn sux_me_present(slot: Int) -> String -extern fn sux_me_past(slot: Int) -> String -extern fn sux_dug4_present(slot: Int) -> String -extern fn sux_dug4_past(slot: Int) -> String -extern fn sux_du_present(slot: Int) -> String -extern fn sux_du_past(slot: Int) -> String -extern fn sux_igibar_present(slot: Int) -> String -extern fn sux_igibar_past(slot: Int) -> String -extern fn sux_ak_present(slot: Int) -> String -extern fn sux_ak_past(slot: Int) -> String -extern fn sux_tum2_present(slot: Int) -> String -extern fn sux_tum2_past(slot: Int) -> String -extern fn sux_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn sux_is_animate(noun: String) -> Bool -extern fn sux_case_suffix(gram_case: String) -> String -extern fn sux_decline(noun: String, gram_case: String, number: String) -> String -extern fn sux_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String -extern fn sux_verb_chain(agent: String, verb: String, patient: String, tense: String) -> String -extern fn sux_realize_sentence(intent: String, agent: String, predicate: String, patient: String, tense: String) -> String diff --git a/dist/morphology-sw.elh b/dist/morphology-sw.elh deleted file mode 100644 index 4f5260d..0000000 --- a/dist/morphology-sw.elh +++ /dev/null @@ -1,23 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn sw_str_ends(s: String, suf: String) -> Bool -extern fn sw_str_drop_last(s: String, n: Int) -> String -extern fn sw_str_first_char(s: String) -> String -extern fn sw_str_first2(s: String) -> String -extern fn sw_str_first3(s: String) -> String -extern fn sw_str_last_char(s: String) -> String -extern fn sw_is_class1_noun(noun: String) -> Bool -extern fn sw_noun_class(noun: String) -> String -extern fn sw_subj_prefix(person: String, number: String, noun_class: String) -> String -extern fn sw_obj_prefix(person: String, number: String, noun_class: String) -> String -extern fn sw_tense_marker(tense: String) -> String -extern fn sw_verb_final(tense: String, negative: Bool) -> String -extern fn sw_neg_subj_prefix(person: String, number: String, noun_class: String) -> String -extern fn sw_verb_stem(infinitive: String) -> String -extern fn sw_conjugate(verb_stem: String, person: String, number: String, noun_class: String, tense: String) -> String -extern fn sw_negative(verb_stem: String, person: String, number: String, noun_class: String, tense: String) -> String -extern fn sw_noun_plural(noun: String) -> String -extern fn sw_adj_prefix(noun_class: String, number: String) -> String -extern fn sw_agree_adj(adj_stem: String, noun_class: String, number: String) -> String -extern fn sw_demonstrative(noun_class: String, number: String, proximity: String) -> String -extern fn sw_copula_present(person: String, number: String, use_case: String) -> String -extern fn sw_copula_neg_present(person: String, number: String) -> String diff --git a/dist/morphology-txb.elh b/dist/morphology-txb.elh deleted file mode 100644 index 6c02972..0000000 --- a/dist/morphology-txb.elh +++ /dev/null @@ -1,17 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn txb_drop(s: String, n: Int) -> String -extern fn txb_ends(s: String, suf: String) -> Bool -extern fn txb_slot(person: String, number: String) -> Int -extern fn txb_pres1_suffix(slot: Int) -> String -extern fn txb_kam_present(slot: Int) -> String -extern fn txb_ya_present(slot: Int) -> String -extern fn txb_wes_present(slot: Int) -> String -extern fn txb_lyut_present(slot: Int) -> String -extern fn txb_wak_present(slot: Int) -> String -extern fn txb_map_canonical(verb: String) -> String -extern fn txb_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn txb_decline_masc(noun: String, gram_case: String, number: String) -> String -extern fn txb_decline_fem(noun: String, gram_case: String, number: String) -> String -extern fn txb_detect_gender(noun: String) -> String -extern fn txb_decline(noun: String, gram_case: String, number: String) -> String -extern fn txb_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String diff --git a/dist/morphology-uga.elh b/dist/morphology-uga.elh deleted file mode 100644 index ffba827..0000000 --- a/dist/morphology-uga.elh +++ /dev/null @@ -1,25 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn uga_str_ends(s: String, suf: String) -> Bool -extern fn uga_str_len(s: String) -> Int -extern fn uga_str_drop_last(s: String, n: Int) -> String -extern fn uga_slot(person: String, number: String) -> Int -extern fn uga_slot_g(person: String, gender: String, number: String) -> Int -extern fn uga_kn_perfect(slot: Int) -> String -extern fn uga_kn_imperfect(slot: Int) -> String -extern fn uga_is_copula(verb: String) -> Bool -extern fn uga_conjugate_copula(tense: String, slot: Int) -> String -extern fn uga_hlk_perfect(slot: Int) -> String -extern fn uga_hlk_imperfect(slot: Int) -> String -extern fn uga_ray_perfect(slot: Int) -> String -extern fn uga_ray_imperfect(slot: Int) -> String -extern fn uga_amr_perfect(slot: Int) -> String -extern fn uga_amr_imperfect(slot: Int) -> String -extern fn uga_generic_perfect(base3sg: String, slot: Int) -> String -extern fn uga_generic_imperfect(base3sg: String, slot: Int) -> String -extern fn uga_known_verb(verb: String, tense: String, slot: Int) -> String -extern fn uga_conjugate(verb: String, tense: String, person: String, number: String) -> String -extern fn uga_strip_nom(noun: String) -> String -extern fn uga_is_fem(noun: String) -> Bool -extern fn uga_decline(noun: String, gram_case: String, number: String) -> String -extern fn uga_noun_phrase(noun: String, gram_case: String, number: String, definite: String) -> String -extern fn uga_map_canonical(verb: String) -> String diff --git a/dist/morphology.elh b/dist/morphology.elh deleted file mode 100644 index cd756a1..0000000 --- a/dist/morphology.elh +++ /dev/null @@ -1,27 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn str_ends(s: String, suf: String) -> Bool -extern fn str_last_char(s: String) -> String -extern fn str_last2(s: String) -> String -extern fn str_last3(s: String) -> String -extern fn str_drop_last(s: String, n: Int) -> String -extern fn is_vowel(c: String) -> Bool -extern fn morph_apply_suffix(base: String, suffix: String) -> String -extern fn en_irregular_plural(word: String) -> String -extern fn en_irregular_singular(word: String) -> String -extern fn en_irregular_verb(base: String) -> [String] -extern fn en_verb_3sg(base: String) -> String -extern fn en_should_double_final(base: String) -> Bool -extern fn en_verb_past(base: String) -> String -extern fn en_verb_gerund(base: String) -> String -extern fn en_pluralize_regular(singular: String) -> String -extern fn en_verb_form(base: String, tense: String, person: String, number: String) -> String -extern fn agree_determiner(det: String, noun: String) -> String -extern fn morph_pluralize(noun: String, profile: [String]) -> String -extern fn morph_map_canonical(verb: String, code: String) -> String -extern fn morph_conjugate(verb: String, tense: String, person: String, number: String, profile: [String]) -> String -extern fn morph_inflect(word: String, features: String, profile: [String]) -> String -extern fn pluralize(singular: String) -> String -extern fn singularize(plural: String) -> String -extern fn verb_form(base: String, tense: String, person: String, number: String) -> String -extern fn irregular_plural(word: String) -> String -extern fn irregular_singular(word: String) -> String diff --git a/dist/neuron-api.elh b/dist/neuron-api.elh deleted file mode 100644 index c3dbccb..0000000 --- a/dist/neuron-api.elh +++ /dev/null @@ -1,39 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn is_protected_node(id: String) -> Bool -extern fn api_err_protected(id: String) -> String -extern fn api_json_escape(s: String) -> String -extern fn api_query_param(path: String, key: String) -> String -extern fn api_query_int(path: String, key: String, default_val: Int) -> Int -extern fn api_ok(extra: String) -> String -extern fn api_err(msg: String) -> String -extern fn api_nonempty(s: String) -> Bool -extern fn api_or_empty(s: String) -> String -extern fn api_persisted(id: String) -> Bool -extern fn api_not_persisted(id: String) -> String -extern fn handle_api_begin_session(body: String) -> String -extern fn handle_api_compile_ctx(body: String) -> String -extern fn handle_api_remember(body: String) -> String -extern fn handle_api_node_create(body: String) -> String -extern fn handle_api_node_delete(body: String) -> String -extern fn handle_api_node_update(body: String) -> String -extern fn handle_api_recall(method: String, path: String, body: String) -> String -extern fn handle_api_search_knowledge(method: String, path: String, body: String) -> String -extern fn handle_api_browse_knowledge(path: String, body: String) -> String -extern fn handle_api_capture_knowledge(body: String) -> String -extern fn handle_api_evolve_knowledge(body: String) -> String -extern fn handle_api_promote_knowledge(body: String) -> String -extern fn handle_api_browse_processes(method: String, path: String, body: String) -> String -extern fn handle_api_define_process(body: String) -> String -extern fn handle_api_log_state_event(body: String) -> String -extern fn handle_api_list_state_events(method: String, path: String, body: String) -> String -extern fn handle_api_inspect_config(path: String, body: String) -> String -extern fn handle_api_tune_config(body: String) -> String -extern fn handle_api_inspect_graph(method: String, path: String, body: String) -> String -extern fn handle_api_link_entities(body: String) -> String -extern fn handle_api_forget(body: String) -> String -extern fn handle_api_evolve_memory(body: String) -> String -extern fn handle_api_memory_delete(body: String) -> String -extern fn handle_api_memory_update(body: String) -> String -extern fn handle_api_cultivate(body: String) -> String -extern fn handle_api_list_typed(node_type: String, path: String, body: String) -> String -extern fn handle_api_consolidate(body: String) -> String diff --git a/dist/realizer.elh b/dist/realizer.elh deleted file mode 100644 index 445f6fe..0000000 --- a/dist/realizer.elh +++ /dev/null @@ -1,10 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn agent_person(agent: String) -> String -extern fn agent_number(agent: String) -> String -extern fn realize_np(referent: String, number: String) -> String -extern fn realize_vp_lang(base_verb: String, tense: String, aspect: String, person: String, number: String, profile: [String]) -> [String] -extern fn realize_question_lang(predicate: String, tense: String, aspect: String, person: String, number: String, agent: String, patient: String, location: String, profile: [String]) -> String -extern fn capitalize_first(s: String) -> String -extern fn add_punct(s: String, intent: String) -> String -extern fn realize_lang(form: [String], profile: [String]) -> String -extern fn realize(form: [String]) -> String diff --git a/dist/routes.elh b/dist/routes.elh deleted file mode 100644 index eab06e6..0000000 --- a/dist/routes.elh +++ /dev/null @@ -1,16 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn flag_true(body: String, key: String) -> Bool -extern fn rate_limit_check(ip: String, path: String) -> String -extern fn strip_query(path: String) -> String -extern fn err_404(path: String) -> String -extern fn err_405(method: String, path: String) -> String -extern fn route_health() -> String -extern fn route_lineage() -> String -extern fn route_imprint_contextual(body: String) -> String -extern fn route_imprint_user(body: String) -> String -extern fn route_synthesize(body: String) -> String -extern fn handle_dharma_recv(body: String) -> String -extern fn connectd_get(suffix: String) -> String -extern fn connectd_post(suffix: String, body: String) -> String -extern fn handle_connectors(method: String, clean: String, body: String) -> String -extern fn handle_request(method: String, path: String, body: String) -> String diff --git a/dist/safety.elh b/dist/safety.elh deleted file mode 100644 index a5c42ff..0000000 --- a/dist/safety.elh +++ /dev/null @@ -1,29 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn soft_bell_threshold() -> Int -extern fn hard_bell_threshold() -> Int -extern fn safety_score_crisis(input: String) -> Int -extern fn safety_score_harm(input: String) -> Int -extern fn safety_score_danger(input: String) -> Int -extern fn safety_score_distress_history(history: String) -> Int -extern fn safety_threat_score(input: String, history: String) -> Int -extern fn safety_screen(input: String, history: String) -> String -extern fn safety_validate(output: String, action: String) -> String -extern fn safety_log_bell(level: String, reason: String, input_summary: String) -> String -extern fn safety_self_harm_phrases() -> String -extern fn safety_abuse_phrases() -> String -extern fn safety_general_hard_phrases() -> String -extern fn safety_threat_to_others_phrases() -> String -extern fn safety_soft_phrases() -> String -extern fn safety_normalize(message: String) -> String -extern fn safety_any_match(text: String, phrases_json: String) -> Bool -extern fn safety_count_match(text: String, phrases_json: String) -> Int -extern fn safety_positive_phrases() -> String -extern fn safety_detect_positive_level(message: String) -> String -extern fn safety_detect_bell_level(message: String) -> String -extern fn safety_classify_hard_bell(message: String) -> String -extern fn safety_soft_directive() -> String -extern fn safety_hard_directive(hard_type: String) -> String -extern fn safety_augment_system(system: String, user_msg: String) -> String -extern fn safety_contact_path() -> String -extern fn handle_safety_contact_get() -> String -extern fn handle_safety_contact_post(body: String) -> String diff --git a/dist/semantics.elh b/dist/semantics.elh deleted file mode 100644 index 80f930e..0000000 --- a/dist/semantics.elh +++ /dev/null @@ -1,18 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn sem_frame(intent: String, subject: String, obj: String, modifiers: String) -> [String] -extern fn sem_frame_lang(intent: String, subject: String, obj: String, modifiers: String, lang_code: String) -> [String] -extern fn sem_frame_simple(intent: String, subject: String) -> [String] -extern fn sem_frame_obj(intent: String, subject: String, obj: String) -> [String] -extern fn sem_intent(frame: [String]) -> String -extern fn sem_subject(frame: [String]) -> String -extern fn sem_object(frame: [String]) -> String -extern fn sem_modifiers(frame: [String]) -> String -extern fn sem_lang(frame: [String]) -> String -extern fn sem_first_modifier(mods: String) -> String -extern fn sem_intent_to_realize(intent: String) -> String -extern fn sem_to_spec(frame: [String]) -> [String] -extern fn sem_to_spec_full(frame: [String], verb: String, tense: String, aspect: String) -> [String] -extern fn sem_realize_greet(subject: String) -> String -extern fn sem_realize(frame: [String]) -> String -extern fn sem_realize_full(frame: [String], verb: String, tense: String, aspect: String) -> String -extern fn sem_realize_lang(frame: [String], lang_code: String) -> String diff --git a/dist/sessions.elh b/dist/sessions.elh deleted file mode 100644 index 35db5da..0000000 --- a/dist/sessions.elh +++ /dev/null @@ -1,17 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn session_title_from_message(message: String) -> String -extern fn session_make_content(id: String, title: String, created_at: Int, updated_at: Int, folder: String) -> String -extern fn session_exists(session_id: String) -> Bool -extern fn session_create(body: String) -> String -extern fn session_create_cleanup(session_id: String) -> String -extern fn session_list() -> String -extern fn session_get(session_id: String) -> String -extern fn session_delete(session_id: String) -> String -extern fn session_update_patch(session_id: String, body: String) -> String -extern fn session_search_entry(node: String) -> String -extern fn session_search(query: String) -> String -extern fn session_hist_load(session_id: String) -> String -extern fn session_hist_save(session_id: String, hist: String) -> Void -extern fn session_update_meta_timestamp(session_id: String) -> Void -extern fn session_auto_title(session_id: String, first_message: String) -> Void -extern fn handle_session_approve(session_id: String, body: String) -> String diff --git a/dist/soul.c b/dist/soul.c index e3b411b..29ccfd7 100644 --- a/dist/soul.c +++ b/dist/soul.c @@ -66,6 +66,32 @@ el_val_t entry_found(el_val_t entry); el_val_t entry_word(el_val_t entry); el_val_t entry_pos(el_val_t entry); el_val_t entry_form(el_val_t entry, el_val_t n); +el_val_t str_ends(el_val_t s, el_val_t suf); +el_val_t str_last_char(el_val_t s); +el_val_t str_last2(el_val_t s); +el_val_t str_last3(el_val_t s); +el_val_t str_drop_last(el_val_t s, el_val_t n); +el_val_t is_vowel(el_val_t c); +el_val_t morph_apply_suffix(el_val_t base, el_val_t suffix); +el_val_t en_irregular_plural(el_val_t word); +el_val_t en_irregular_singular(el_val_t word); +el_val_t en_irregular_verb(el_val_t base); +el_val_t en_verb_3sg(el_val_t base); +el_val_t en_should_double_final(el_val_t base); +el_val_t en_verb_past(el_val_t base); +el_val_t en_verb_gerund(el_val_t base); +el_val_t en_pluralize_regular(el_val_t singular); +el_val_t en_verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number); +el_val_t agree_determiner(el_val_t det, el_val_t noun); +el_val_t morph_pluralize(el_val_t noun, el_val_t profile); +el_val_t morph_map_canonical(el_val_t verb, el_val_t code); +el_val_t morph_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number, el_val_t profile); +el_val_t morph_inflect(el_val_t word, el_val_t features, el_val_t profile); +el_val_t pluralize(el_val_t singular); +el_val_t singularize(el_val_t plural); +el_val_t verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number); +el_val_t irregular_plural(el_val_t word); +el_val_t irregular_singular(el_val_t word); el_val_t es_str_ends(el_val_t s, el_val_t suf); el_val_t es_str_drop_last(el_val_t s, el_val_t n); el_val_t es_str_last_char(el_val_t s); @@ -141,6 +167,14 @@ el_val_t ru_conjugate_2nd(el_val_t stem, el_val_t tense, el_val_t person, el_val el_val_t ru_irregular(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number); el_val_t ru_past_stem(el_val_t verb); el_val_t ru_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number, el_val_t gender); +el_val_t ja_verb_group(el_val_t dict_form); +el_val_t ja_ichidan_stem(el_val_t dict_form); +el_val_t ja_godan_stem_change(el_val_t dict_form, el_val_t row); +el_val_t ja_conjugate(el_val_t dict_form, el_val_t form); +el_val_t ja_particle(el_val_t gram_case); +el_val_t ja_noun_phrase(el_val_t noun, el_val_t gram_case); +el_val_t ja_question_particle(void); +el_val_t ja_make_question(el_val_t sentence); el_val_t fi_harmony(el_val_t word); el_val_t fi_suffix(el_val_t base, el_val_t harmony); el_val_t fi_noun_case(el_val_t stem, el_val_t gram_case, el_val_t number, el_val_t harmony); @@ -271,40 +305,6 @@ el_val_t la_decline_5(el_val_t stem, el_val_t gram_case, el_val_t number); el_val_t la_decline_2er(el_val_t noun, el_val_t gram_case, el_val_t number); el_val_t la_decline(el_val_t noun, el_val_t gram_case, el_val_t number); el_val_t la_noun_phrase(el_val_t noun, el_val_t gram_case, el_val_t number, el_val_t definite); -el_val_t ja_verb_group(el_val_t dict_form); -el_val_t ja_ichidan_stem(el_val_t dict_form); -el_val_t ja_godan_stem_change(el_val_t dict_form, el_val_t row); -el_val_t ja_conjugate(el_val_t dict_form, el_val_t form); -el_val_t ja_particle(el_val_t gram_case); -el_val_t ja_noun_phrase(el_val_t noun, el_val_t gram_case); -el_val_t ja_question_particle(void); -el_val_t ja_make_question(el_val_t sentence); -el_val_t str_ends(el_val_t s, el_val_t suf); -el_val_t str_last_char(el_val_t s); -el_val_t str_last2(el_val_t s); -el_val_t str_last3(el_val_t s); -el_val_t str_drop_last(el_val_t s, el_val_t n); -el_val_t is_vowel(el_val_t c); -el_val_t morph_apply_suffix(el_val_t base, el_val_t suffix); -el_val_t en_irregular_plural(el_val_t word); -el_val_t en_irregular_singular(el_val_t word); -el_val_t en_irregular_verb(el_val_t base); -el_val_t en_verb_3sg(el_val_t base); -el_val_t en_should_double_final(el_val_t base); -el_val_t en_verb_past(el_val_t base); -el_val_t en_verb_gerund(el_val_t base); -el_val_t en_pluralize_regular(el_val_t singular); -el_val_t en_verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number); -el_val_t agree_determiner(el_val_t det, el_val_t noun); -el_val_t morph_pluralize(el_val_t noun, el_val_t profile); -el_val_t morph_map_canonical(el_val_t verb, el_val_t code); -el_val_t morph_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number, el_val_t profile); -el_val_t morph_inflect(el_val_t word, el_val_t features, el_val_t profile); -el_val_t pluralize(el_val_t singular); -el_val_t singularize(el_val_t plural); -el_val_t verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number); -el_val_t irregular_plural(el_val_t word); -el_val_t irregular_singular(el_val_t word); el_val_t he_str_ends(el_val_t s, el_val_t suf); el_val_t he_str_len(el_val_t s); el_val_t he_str_drop_last(el_val_t s, el_val_t n); @@ -1114,6 +1114,11 @@ el_val_t llm_base_url(void); el_val_t llm_wire_format(void); el_val_t json_escape(el_val_t s); el_val_t openai_chat_complete(el_val_t model, el_val_t base_url, el_val_t api_key, el_val_t safe_sys, el_val_t messages_json); +el_val_t openai_tools_json(el_val_t tools_anthropic); +el_val_t utf8_safe_slice(el_val_t s, el_val_t n); +el_val_t json_trim_dangling_escape(el_val_t s); +el_val_t agentic_tools_no_web(void); +el_val_t openai_agentic_loop(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages_in, el_val_t tools_log_in); el_val_t agentic_tools_literal(void); el_val_t web_search_tool_json(void); el_val_t strip_client_web_search(el_val_t tools_inner); @@ -1137,7 +1142,7 @@ el_val_t handle_chat_plan(el_val_t body); el_val_t agentic_safety_screen(el_val_t session_id, el_val_t message); el_val_t handle_chat_agentic(el_val_t body); el_val_t agentic_loop(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages_in, el_val_t h, el_val_t tools_log_in); -el_val_t bridge_save(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages, el_val_t tools_log, el_val_t tool_use_id); +el_val_t bridge_save(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages, el_val_t tools_log, el_val_t tool_use_id, el_val_t wire); el_val_t agentic_resume(el_val_t session_id, el_val_t tool_use_id, el_val_t content); el_val_t handle_tool_result(el_val_t session_id, el_val_t body); el_val_t handle_chat_as_soul(el_val_t body); @@ -1942,6 +1947,993 @@ el_val_t entry_form(el_val_t entry, el_val_t n) { return 0; } +el_val_t str_ends(el_val_t s, el_val_t suf) { + return str_ends_with(s, suf); + return 0; +} + +el_val_t str_last_char(el_val_t s) { + el_val_t n = str_len(s); + if (n == 0) { + return EL_STR(""); + } + return str_slice(s, (n - 1), n); + return 0; +} + +el_val_t str_last2(el_val_t s) { + el_val_t n = str_len(s); + if (n < 2) { + return s; + } + return str_slice(s, (n - 2), n); + return 0; +} + +el_val_t str_last3(el_val_t s) { + el_val_t n = str_len(s); + if (n < 3) { + return s; + } + return str_slice(s, (n - 3), n); + return 0; +} + +el_val_t str_drop_last(el_val_t s, el_val_t n) { + el_val_t len = str_len(s); + if (n >= len) { + return EL_STR(""); + } + return str_slice(s, 0, (len - n)); + return 0; +} + +el_val_t is_vowel(el_val_t c) { + if (str_eq(c, EL_STR("a"))) { + return 1; + } + if (str_eq(c, EL_STR("e"))) { + return 1; + } + if (str_eq(c, EL_STR("i"))) { + return 1; + } + if (str_eq(c, EL_STR("o"))) { + return 1; + } + if (str_eq(c, EL_STR("u"))) { + return 1; + } + return 0; + return 0; +} + +el_val_t morph_apply_suffix(el_val_t base, el_val_t suffix) { + if (str_eq(suffix, EL_STR(""))) { + return base; + } + el_val_t suf_start = str_slice(suffix, 0, 1); + el_val_t suf_starts_vowel = is_vowel(suf_start); + if (suf_starts_vowel) { + if (str_ends(base, EL_STR("e"))) { + if (!str_ends(base, EL_STR("ee"))) { + return el_str_concat(str_drop_last(base, 1), suffix); + } + } + } + if (suf_starts_vowel) { + el_val_t n = str_len(base); + if (n >= 3) { + el_val_t c3 = str_slice(base, (n - 3), (n - 2)); + el_val_t c2 = str_slice(base, (n - 2), (n - 1)); + el_val_t c1 = str_slice(base, (n - 1), n); + if (!is_vowel(c3)) { + if (is_vowel(c2)) { + if (!is_vowel(c1)) { + if (!str_eq(c1, EL_STR("w"))) { + if (!str_eq(c1, EL_STR("x"))) { + if (!str_eq(c1, EL_STR("y"))) { + return el_str_concat(el_str_concat(base, c1), suffix); + } + } + } + } + } + } + } + } + return el_str_concat(base, suffix); + return 0; +} + +el_val_t en_irregular_plural(el_val_t word) { + if (str_eq(word, EL_STR("child"))) { + return EL_STR("children"); + } + if (str_eq(word, EL_STR("man"))) { + return EL_STR("men"); + } + if (str_eq(word, EL_STR("woman"))) { + return EL_STR("women"); + } + if (str_eq(word, EL_STR("tooth"))) { + return EL_STR("teeth"); + } + if (str_eq(word, EL_STR("foot"))) { + return EL_STR("feet"); + } + if (str_eq(word, EL_STR("goose"))) { + return EL_STR("geese"); + } + if (str_eq(word, EL_STR("mouse"))) { + return EL_STR("mice"); + } + if (str_eq(word, EL_STR("louse"))) { + return EL_STR("lice"); + } + if (str_eq(word, EL_STR("ox"))) { + return EL_STR("oxen"); + } + if (str_eq(word, EL_STR("person"))) { + return EL_STR("people"); + } + if (str_eq(word, EL_STR("leaf"))) { + return EL_STR("leaves"); + } + if (str_eq(word, EL_STR("loaf"))) { + return EL_STR("loaves"); + } + if (str_eq(word, EL_STR("wolf"))) { + return EL_STR("wolves"); + } + if (str_eq(word, EL_STR("life"))) { + return EL_STR("lives"); + } + if (str_eq(word, EL_STR("knife"))) { + return EL_STR("knives"); + } + if (str_eq(word, EL_STR("wife"))) { + return EL_STR("wives"); + } + if (str_eq(word, EL_STR("half"))) { + return EL_STR("halves"); + } + if (str_eq(word, EL_STR("self"))) { + return EL_STR("selves"); + } + if (str_eq(word, EL_STR("elf"))) { + return EL_STR("elves"); + } + if (str_eq(word, EL_STR("shelf"))) { + return EL_STR("shelves"); + } + if (str_eq(word, EL_STR("fish"))) { + return EL_STR("fish"); + } + if (str_eq(word, EL_STR("sheep"))) { + return EL_STR("sheep"); + } + if (str_eq(word, EL_STR("deer"))) { + return EL_STR("deer"); + } + if (str_eq(word, EL_STR("moose"))) { + return EL_STR("moose"); + } + if (str_eq(word, EL_STR("series"))) { + return EL_STR("series"); + } + if (str_eq(word, EL_STR("species"))) { + return EL_STR("species"); + } + return EL_STR(""); + return 0; +} + +el_val_t en_irregular_singular(el_val_t word) { + if (str_eq(word, EL_STR("children"))) { + return EL_STR("child"); + } + if (str_eq(word, EL_STR("men"))) { + return EL_STR("man"); + } + if (str_eq(word, EL_STR("women"))) { + return EL_STR("woman"); + } + if (str_eq(word, EL_STR("teeth"))) { + return EL_STR("tooth"); + } + if (str_eq(word, EL_STR("feet"))) { + return EL_STR("foot"); + } + if (str_eq(word, EL_STR("geese"))) { + return EL_STR("goose"); + } + if (str_eq(word, EL_STR("mice"))) { + return EL_STR("mouse"); + } + if (str_eq(word, EL_STR("lice"))) { + return EL_STR("louse"); + } + if (str_eq(word, EL_STR("oxen"))) { + return EL_STR("ox"); + } + if (str_eq(word, EL_STR("people"))) { + return EL_STR("person"); + } + if (str_eq(word, EL_STR("leaves"))) { + return EL_STR("leaf"); + } + if (str_eq(word, EL_STR("wolves"))) { + return EL_STR("wolf"); + } + if (str_eq(word, EL_STR("lives"))) { + return EL_STR("life"); + } + if (str_eq(word, EL_STR("knives"))) { + return EL_STR("knife"); + } + if (str_eq(word, EL_STR("wives"))) { + return EL_STR("wife"); + } + if (str_eq(word, EL_STR("halves"))) { + return EL_STR("half"); + } + if (str_eq(word, EL_STR("selves"))) { + return EL_STR("self"); + } + if (str_eq(word, EL_STR("elves"))) { + return EL_STR("elf"); + } + if (str_eq(word, EL_STR("shelves"))) { + return EL_STR("shelf"); + } + if (str_eq(word, EL_STR("fish"))) { + return EL_STR("fish"); + } + if (str_eq(word, EL_STR("sheep"))) { + return EL_STR("sheep"); + } + if (str_eq(word, EL_STR("deer"))) { + return EL_STR("deer"); + } + if (str_eq(word, EL_STR("moose"))) { + return EL_STR("moose"); + } + if (str_eq(word, EL_STR("series"))) { + return EL_STR("series"); + } + if (str_eq(word, EL_STR("species"))) { + return EL_STR("species"); + } + return EL_STR(""); + return 0; +} + +el_val_t en_irregular_verb(el_val_t base) { + el_val_t empty = el_list_empty(); + if (str_eq(base, EL_STR("be"))) { + el_val_t r = el_list_new(5, EL_STR("be"), EL_STR("is"), EL_STR("was"), EL_STR("been"), EL_STR("being")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("have"))) { + el_val_t r = el_list_new(5, EL_STR("have"), EL_STR("has"), EL_STR("had"), EL_STR("had"), EL_STR("having")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("do"))) { + el_val_t r = el_list_new(5, EL_STR("do"), EL_STR("does"), EL_STR("did"), EL_STR("done"), EL_STR("doing")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("go"))) { + el_val_t r = el_list_new(5, EL_STR("go"), EL_STR("goes"), EL_STR("went"), EL_STR("gone"), EL_STR("going")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("say"))) { + el_val_t r = el_list_new(5, EL_STR("say"), EL_STR("says"), EL_STR("said"), EL_STR("said"), EL_STR("saying")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("make"))) { + el_val_t r = el_list_new(5, EL_STR("make"), EL_STR("makes"), EL_STR("made"), EL_STR("made"), EL_STR("making")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("know"))) { + el_val_t r = el_list_new(5, EL_STR("know"), EL_STR("knows"), EL_STR("knew"), EL_STR("known"), EL_STR("knowing")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("take"))) { + el_val_t r = el_list_new(5, EL_STR("take"), EL_STR("takes"), EL_STR("took"), EL_STR("taken"), EL_STR("taking")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("see"))) { + el_val_t r = el_list_new(5, EL_STR("see"), EL_STR("sees"), EL_STR("saw"), EL_STR("seen"), EL_STR("seeing")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("come"))) { + el_val_t r = el_list_new(5, EL_STR("come"), EL_STR("comes"), EL_STR("came"), EL_STR("come"), EL_STR("coming")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("think"))) { + el_val_t r = el_list_new(5, EL_STR("think"), EL_STR("thinks"), EL_STR("thought"), EL_STR("thought"), EL_STR("thinking")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("get"))) { + el_val_t r = el_list_new(5, EL_STR("get"), EL_STR("gets"), EL_STR("got"), EL_STR("gotten"), EL_STR("getting")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("give"))) { + el_val_t r = el_list_new(5, EL_STR("give"), EL_STR("gives"), EL_STR("gave"), EL_STR("given"), EL_STR("giving")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("find"))) { + el_val_t r = el_list_new(5, EL_STR("find"), EL_STR("finds"), EL_STR("found"), EL_STR("found"), EL_STR("finding")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("tell"))) { + el_val_t r = el_list_new(5, EL_STR("tell"), EL_STR("tells"), EL_STR("told"), EL_STR("told"), EL_STR("telling")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("become"))) { + el_val_t r = el_list_new(5, EL_STR("become"), EL_STR("becomes"), EL_STR("became"), EL_STR("become"), EL_STR("becoming")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("leave"))) { + el_val_t r = el_list_new(5, EL_STR("leave"), EL_STR("leaves"), EL_STR("left"), EL_STR("left"), EL_STR("leaving")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("feel"))) { + el_val_t r = el_list_new(5, EL_STR("feel"), EL_STR("feels"), EL_STR("felt"), EL_STR("felt"), EL_STR("feeling")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("put"))) { + el_val_t r = el_list_new(5, EL_STR("put"), EL_STR("puts"), EL_STR("put"), EL_STR("put"), EL_STR("putting")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("bring"))) { + el_val_t r = el_list_new(5, EL_STR("bring"), EL_STR("brings"), EL_STR("brought"), EL_STR("brought"), EL_STR("bringing")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("begin"))) { + el_val_t r = el_list_new(5, EL_STR("begin"), EL_STR("begins"), EL_STR("began"), EL_STR("begun"), EL_STR("beginning")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("keep"))) { + el_val_t r = el_list_new(5, EL_STR("keep"), EL_STR("keeps"), EL_STR("kept"), EL_STR("kept"), EL_STR("keeping")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("hold"))) { + el_val_t r = el_list_new(5, EL_STR("hold"), EL_STR("holds"), EL_STR("held"), EL_STR("held"), EL_STR("holding")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("write"))) { + el_val_t r = el_list_new(5, EL_STR("write"), EL_STR("writes"), EL_STR("wrote"), EL_STR("written"), EL_STR("writing")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("stand"))) { + el_val_t r = el_list_new(5, EL_STR("stand"), EL_STR("stands"), EL_STR("stood"), EL_STR("stood"), EL_STR("standing")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("hear"))) { + el_val_t r = el_list_new(5, EL_STR("hear"), EL_STR("hears"), EL_STR("heard"), EL_STR("heard"), EL_STR("hearing")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("let"))) { + el_val_t r = el_list_new(5, EL_STR("let"), EL_STR("lets"), EL_STR("let"), EL_STR("let"), EL_STR("letting")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("run"))) { + el_val_t r = el_list_new(5, EL_STR("run"), EL_STR("runs"), EL_STR("ran"), EL_STR("run"), EL_STR("running")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("meet"))) { + el_val_t r = el_list_new(5, EL_STR("meet"), EL_STR("meets"), EL_STR("met"), EL_STR("met"), EL_STR("meeting")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("sit"))) { + el_val_t r = el_list_new(5, EL_STR("sit"), EL_STR("sits"), EL_STR("sat"), EL_STR("sat"), EL_STR("sitting")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("send"))) { + el_val_t r = el_list_new(5, EL_STR("send"), EL_STR("sends"), EL_STR("sent"), EL_STR("sent"), EL_STR("sending")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("speak"))) { + el_val_t r = el_list_new(5, EL_STR("speak"), EL_STR("speaks"), EL_STR("spoke"), EL_STR("spoken"), EL_STR("speaking")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("buy"))) { + el_val_t r = el_list_new(5, EL_STR("buy"), EL_STR("buys"), EL_STR("bought"), EL_STR("bought"), EL_STR("buying")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("pay"))) { + el_val_t r = el_list_new(5, EL_STR("pay"), EL_STR("pays"), EL_STR("paid"), EL_STR("paid"), EL_STR("paying")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("read"))) { + el_val_t r = el_list_new(5, EL_STR("read"), EL_STR("reads"), EL_STR("read"), EL_STR("read"), EL_STR("reading")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("win"))) { + el_val_t r = el_list_new(5, EL_STR("win"), EL_STR("wins"), EL_STR("won"), EL_STR("won"), EL_STR("winning")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("eat"))) { + el_val_t r = el_list_new(5, EL_STR("eat"), EL_STR("eats"), EL_STR("ate"), EL_STR("eaten"), EL_STR("eating")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("fall"))) { + el_val_t r = el_list_new(5, EL_STR("fall"), EL_STR("falls"), EL_STR("fell"), EL_STR("fallen"), EL_STR("falling")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("sleep"))) { + el_val_t r = el_list_new(5, EL_STR("sleep"), EL_STR("sleeps"), EL_STR("slept"), EL_STR("slept"), EL_STR("sleeping")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("drive"))) { + el_val_t r = el_list_new(5, EL_STR("drive"), EL_STR("drives"), EL_STR("drove"), EL_STR("driven"), EL_STR("driving")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("build"))) { + el_val_t r = el_list_new(5, EL_STR("build"), EL_STR("builds"), EL_STR("built"), EL_STR("built"), EL_STR("building")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("cut"))) { + el_val_t r = el_list_new(5, EL_STR("cut"), EL_STR("cuts"), EL_STR("cut"), EL_STR("cut"), EL_STR("cutting")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("set"))) { + el_val_t r = el_list_new(5, EL_STR("set"), EL_STR("sets"), EL_STR("set"), EL_STR("set"), EL_STR("setting")); + EL_NULL; + return r; + } + if (str_eq(base, EL_STR("hit"))) { + el_val_t r = el_list_new(5, EL_STR("hit"), EL_STR("hits"), EL_STR("hit"), EL_STR("hit"), EL_STR("hitting")); + EL_NULL; + return r; + } + return empty; + return 0; +} + +el_val_t en_verb_3sg(el_val_t base) { + if (str_ends(base, EL_STR("s"))) { + return el_str_concat(base, EL_STR("es")); + } + if (str_ends(base, EL_STR("x"))) { + return el_str_concat(base, EL_STR("es")); + } + if (str_ends(base, EL_STR("z"))) { + return el_str_concat(base, EL_STR("es")); + } + if (str_ends(base, EL_STR("ch"))) { + return el_str_concat(base, EL_STR("es")); + } + if (str_ends(base, EL_STR("sh"))) { + return el_str_concat(base, EL_STR("es")); + } + el_val_t last = str_last_char(base); + if (str_eq(last, EL_STR("y"))) { + el_val_t prev = str_drop_last(base, 1); + el_val_t prev_last = str_last_char(prev); + if (!is_vowel(prev_last)) { + return el_str_concat(prev, EL_STR("ies")); + } + } + return el_str_concat(base, EL_STR("s")); + return 0; +} + +el_val_t en_should_double_final(el_val_t base) { + el_val_t n = str_len(base); + if (n < 3) { + return 0; + } + el_val_t c3 = str_slice(base, (n - 3), (n - 2)); + el_val_t c2 = str_slice(base, (n - 2), (n - 1)); + el_val_t c1 = str_slice(base, (n - 1), n); + if (!is_vowel(c3)) { + if (is_vowel(c2)) { + if (!is_vowel(c1)) { + if (!str_eq(c1, EL_STR("w"))) { + if (!str_eq(c1, EL_STR("x"))) { + if (!str_eq(c1, EL_STR("y"))) { + return 1; + } + } + } + } + } + } + return 0; + return 0; +} + +el_val_t en_verb_past(el_val_t base) { + if (str_ends(base, EL_STR("e"))) { + return el_str_concat(base, EL_STR("d")); + } + el_val_t last = str_last_char(base); + if (str_eq(last, EL_STR("y"))) { + el_val_t prev = str_drop_last(base, 1); + el_val_t prev_last = str_last_char(prev); + if (!is_vowel(prev_last)) { + return el_str_concat(prev, EL_STR("ied")); + } + } + if (en_should_double_final(base)) { + return el_str_concat(el_str_concat(base, last), EL_STR("ed")); + } + return el_str_concat(base, EL_STR("ed")); + return 0; +} + +el_val_t en_verb_gerund(el_val_t base) { + if (str_ends(base, EL_STR("ie"))) { + return el_str_concat(str_drop_last(base, 2), EL_STR("ying")); + } + if (str_ends(base, EL_STR("e"))) { + if (!str_ends(base, EL_STR("ee"))) { + return el_str_concat(str_drop_last(base, 1), EL_STR("ing")); + } + } + el_val_t last = str_last_char(base); + if (en_should_double_final(base)) { + return el_str_concat(el_str_concat(base, last), EL_STR("ing")); + } + return el_str_concat(base, EL_STR("ing")); + return 0; +} + +el_val_t en_pluralize_regular(el_val_t singular) { + if (str_ends(singular, EL_STR("s"))) { + return el_str_concat(singular, EL_STR("es")); + } + if (str_ends(singular, EL_STR("x"))) { + return el_str_concat(singular, EL_STR("es")); + } + if (str_ends(singular, EL_STR("z"))) { + return el_str_concat(singular, EL_STR("es")); + } + if (str_ends(singular, EL_STR("ch"))) { + return el_str_concat(singular, EL_STR("es")); + } + if (str_ends(singular, EL_STR("sh"))) { + return el_str_concat(singular, EL_STR("es")); + } + el_val_t last = str_last_char(singular); + if (str_eq(last, EL_STR("y"))) { + el_val_t prev = str_drop_last(singular, 1); + el_val_t prev_last = str_last_char(prev); + if (!is_vowel(prev_last)) { + return el_str_concat(prev, EL_STR("ies")); + } + } + if (str_ends(singular, EL_STR("fe"))) { + return el_str_concat(str_drop_last(singular, 2), EL_STR("ves")); + } + return el_str_concat(singular, EL_STR("s")); + return 0; +} + +el_val_t en_verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number) { + el_val_t irreg = en_irregular_verb(base); + el_val_t is_irreg = 0; + if (native_list_len(irreg) > 0) { + is_irreg = 1; + } + if (str_eq(base, EL_STR("be"))) { + if (str_eq(tense, EL_STR("present"))) { + if (str_eq(number, EL_STR("plural"))) { + return EL_STR("are"); + } + if (str_eq(person, EL_STR("first"))) { + return EL_STR("am"); + } + if (str_eq(person, EL_STR("second"))) { + return EL_STR("are"); + } + return EL_STR("is"); + } + if (str_eq(tense, EL_STR("past"))) { + if (str_eq(number, EL_STR("plural"))) { + return EL_STR("were"); + } + if (str_eq(person, EL_STR("second"))) { + return EL_STR("were"); + } + return EL_STR("was"); + } + if (str_eq(tense, EL_STR("future"))) { + return EL_STR("will be"); + } + if (str_eq(tense, EL_STR("perfect"))) { + return EL_STR("been"); + } + if (str_eq(tense, EL_STR("progressive"))) { + return EL_STR("being"); + } + return EL_STR("be"); + } + if (str_eq(tense, EL_STR("present"))) { + if (str_eq(person, EL_STR("third"))) { + if (str_eq(number, EL_STR("singular"))) { + if (is_irreg) { + return native_list_get(irreg, 1); + } + return en_verb_3sg(base); + } + } + return base; + } + if (str_eq(tense, EL_STR("past"))) { + if (is_irreg) { + return native_list_get(irreg, 2); + } + return en_verb_past(base); + } + if (str_eq(tense, EL_STR("future"))) { + return el_str_concat(EL_STR("will "), base); + } + if (str_eq(tense, EL_STR("perfect"))) { + if (is_irreg) { + return native_list_get(irreg, 3); + } + return en_verb_past(base); + } + if (str_eq(tense, EL_STR("progressive"))) { + if (is_irreg) { + return native_list_get(irreg, 4); + } + return en_verb_gerund(base); + } + return base; + return 0; +} + +el_val_t agree_determiner(el_val_t det, el_val_t noun) { + if (str_eq(det, EL_STR("a"))) { + el_val_t first = str_slice(noun, 0, 1); + el_val_t fl = str_to_lower(first); + if (is_vowel(fl)) { + return EL_STR("an"); + } + return EL_STR("a"); + } + return det; + return 0; +} + +el_val_t morph_pluralize(el_val_t noun, el_val_t profile) { + el_val_t mtype = lang_get(profile, EL_STR("morph_type")); + el_val_t code = lang_get(profile, EL_STR("code")); + if (str_eq(code, EL_STR("es"))) { + return es_pluralize(noun); + } + if (str_eq(code, EL_STR("fr"))) { + return fr_pluralize(noun); + } + if (str_eq(code, EL_STR("de"))) { + return de_noun_plural(noun, EL_STR("unknown")); + } + if (str_eq(code, EL_STR("ru"))) { + return ru_noun_case(noun, EL_STR("m"), EL_STR("nom"), EL_STR("pl")); + } + if (str_eq(code, EL_STR("ja"))) { + return noun; + } + if (str_eq(code, EL_STR("fi"))) { + return fi_apply_case(noun, EL_STR("nom"), EL_STR("pl")); + } + if (str_eq(code, EL_STR("ar"))) { + return ar_sound_plural(noun, EL_STR("m")); + } + if (str_eq(code, EL_STR("hi"))) { + return hi_noun_direct(noun, hi_gender(noun), EL_STR("pl")); + } + if (str_eq(code, EL_STR("sw"))) { + return sw_noun_plural(noun); + } + if (str_eq(mtype, EL_STR("isolating"))) { + return noun; + } + if (str_eq(mtype, EL_STR("agglutinative"))) { + return noun; + } + if (str_eq(mtype, EL_STR("fusional"))) { + if (str_eq(code, EL_STR("en"))) { + el_val_t irreg = en_irregular_plural(noun); + if (!str_eq(irreg, EL_STR(""))) { + return irreg; + } + return en_pluralize_regular(noun); + } + return noun; + } + return noun; + return 0; +} + +el_val_t morph_map_canonical(el_val_t verb, el_val_t code) { + if (str_eq(verb, EL_STR("be"))) { + if (str_eq(code, EL_STR("es"))) { + return EL_STR("ser"); + } + if (str_eq(code, EL_STR("fr"))) { + return EL_STR("etre"); + } + if (str_eq(code, EL_STR("de"))) { + return EL_STR("sein"); + } + if (str_eq(code, EL_STR("fi"))) { + return EL_STR("olla"); + } + if (str_eq(code, EL_STR("ru"))) { + return EL_STR("byt"); + } + if (str_eq(code, EL_STR("sw"))) { + return EL_STR("kuwa"); + } + } + return verb; + return 0; +} + +el_val_t morph_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number, el_val_t profile) { + el_val_t mtype = lang_get(profile, EL_STR("morph_type")); + el_val_t code = lang_get(profile, EL_STR("code")); + verb = morph_map_canonical(verb, code); + if (str_eq(code, EL_STR("es"))) { + return es_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("fr"))) { + return fr_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("de"))) { + return de_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("ru"))) { + return ru_conjugate(verb, tense, person, number, EL_STR("unknown")); + } + if (str_eq(code, EL_STR("ja"))) { + return ja_conjugate(verb, EL_STR("present")); + } + if (str_eq(code, EL_STR("fi"))) { + return fi_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("ar"))) { + return ar_conjugate(verb, tense, person, EL_STR("m"), number); + } + if (str_eq(code, EL_STR("hi"))) { + return hi_conjugate(verb, tense, person, EL_STR("m"), number); + } + if (str_eq(code, EL_STR("sw"))) { + return sw_conjugate(verb, person, number, EL_STR("1"), tense); + } + if (str_eq(code, EL_STR("la"))) { + return la_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("he"))) { + return he_conjugate(verb, tense, person, EL_STR("m"), number); + } + if (str_eq(code, EL_STR("grc"))) { + return grc_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("ang"))) { + return ang_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("sa"))) { + return sa_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("got"))) { + return got_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("non"))) { + return non_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("enm"))) { + return enm_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("pi"))) { + return pi_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("fro"))) { + return fro_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("goh"))) { + return goh_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("sga"))) { + return sga_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("txb"))) { + return txb_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("peo"))) { + return peo_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("akk"))) { + return akk_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("uga"))) { + return uga_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("egy"))) { + return egy_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("sux"))) { + return sux_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("gez"))) { + return gez_conjugate(verb, tense, person, number); + } + if (str_eq(code, EL_STR("cop"))) { + return cop_conjugate(verb, tense, person, number); + } + if (str_eq(mtype, EL_STR("isolating"))) { + return verb; + } + if (str_eq(mtype, EL_STR("agglutinative"))) { + return verb; + } + if (str_eq(mtype, EL_STR("fusional"))) { + if (str_eq(code, EL_STR("en"))) { + return en_verb_form(verb, tense, person, number); + } + return verb; + } + return verb; + return 0; +} + +el_val_t morph_inflect(el_val_t word, el_val_t features, el_val_t profile) { + el_val_t n = str_len(features); + if (n == 0) { + return word; + } + el_val_t i = 0; + el_val_t running = 1; + while (running) { + if (i >= n) { + running = 0; + } else { + el_val_t c = str_slice(features, i, (i + 1)); + if (str_eq(c, EL_STR(";"))) { + running = 0; + } else { + i = (i + 1); + } + } + } + el_val_t first_feat = str_slice(features, 0, i); + if (str_eq(first_feat, EL_STR("plural"))) { + return morph_pluralize(word, profile); + } + if (i < n) { + el_val_t rest = str_slice(features, (i + 1), n); + el_val_t j = 0; + el_val_t rn = str_len(rest); + el_val_t running2 = 1; + while (running2) { + if (j >= rn) { + running2 = 0; + } else { + el_val_t c = str_slice(rest, j, (j + 1)); + if (str_eq(c, EL_STR(";"))) { + running2 = 0; + } else { + j = (j + 1); + } + } + } + el_val_t person = str_slice(rest, 0, j); + el_val_t number = EL_STR(""); + if (j < rn) { + number = str_slice(rest, (j + 1), rn); + } + return morph_conjugate(word, first_feat, person, number, profile); + } + return morph_conjugate(word, first_feat, EL_STR("third"), EL_STR("singular"), profile); + return 0; +} + +el_val_t pluralize(el_val_t singular) { + return morph_pluralize(singular, lang_default()); + return 0; +} + +el_val_t singularize(el_val_t plural) { + el_val_t irreg = en_irregular_singular(plural); + if (!str_eq(irreg, EL_STR(""))) { + return irreg; + } + if (str_ends(plural, EL_STR("ies"))) { + return el_str_concat(str_drop_last(plural, 3), EL_STR("y")); + } + if (str_ends(plural, EL_STR("ves"))) { + el_val_t stem = str_drop_last(plural, 3); + el_val_t last_stem = str_last_char(stem); + if (str_eq(last_stem, EL_STR("i"))) { + return el_str_concat(stem, EL_STR("fe")); + } + return el_str_concat(stem, EL_STR("f")); + } + if (str_ends(plural, EL_STR("ches"))) { + return str_drop_last(plural, 2); + } + if (str_ends(plural, EL_STR("shes"))) { + return str_drop_last(plural, 2); + } + if (str_ends(plural, EL_STR("xes"))) { + return str_drop_last(plural, 2); + } + if (str_ends(plural, EL_STR("zes"))) { + return str_drop_last(plural, 2); + } + if (str_ends(plural, EL_STR("ses"))) { + return str_drop_last(plural, 2); + } + if (str_ends(plural, EL_STR("s"))) { + return str_drop_last(plural, 1); + } + return plural; + return 0; +} + +el_val_t verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number) { + return morph_conjugate(base, tense, person, number, lang_default()); + return 0; +} + +el_val_t irregular_plural(el_val_t word) { + return en_irregular_plural(word); + return 0; +} + +el_val_t irregular_singular(el_val_t word) { + return en_irregular_singular(word); + return 0; +} + el_val_t es_str_ends(el_val_t s, el_val_t suf) { return str_ends_with(s, suf); return 0; @@ -6189,6 +7181,713 @@ el_val_t ru_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t n return 0; } +el_val_t ja_verb_group(el_val_t dict_form) { + if (str_eq(dict_form, EL_STR("\xe3\x81\x99\xe3\x82\x8b"))) { + return EL_STR("irregular"); + } + if (str_eq(dict_form, EL_STR("\xe3\x81\x8f\xe3\x82\x8b"))) { + return EL_STR("irregular"); + } + if (str_eq(dict_form, EL_STR("\xe3\x81\x8f\xe3\x82\x8b"))) { + return EL_STR("irregular"); + } + if (str_eq(dict_form, EL_STR("\xe3\x81\x84\xe3\x82\x8b"))) { + return EL_STR("irregular"); + } + if (str_eq(dict_form, EL_STR("\xe3\x81\x82\xe3\x82\x8b"))) { + return EL_STR("irregular"); + } + if (str_eq(dict_form, EL_STR("\xe3\x81\xa0"))) { + return EL_STR("irregular"); + } + if (str_eq(dict_form, EL_STR("suru"))) { + return EL_STR("irregular"); + } + if (str_eq(dict_form, EL_STR("kuru"))) { + return EL_STR("irregular"); + } + if (str_eq(dict_form, EL_STR("iru"))) { + return EL_STR("irregular"); + } + if (str_eq(dict_form, EL_STR("aru"))) { + return EL_STR("irregular"); + } + if (str_eq(dict_form, EL_STR("da"))) { + return EL_STR("irregular"); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x82\x8b"))) { + return EL_STR("ichidan"); + } + if (str_ends_with(dict_form, EL_STR("eru"))) { + return EL_STR("ichidan"); + } + if (str_ends_with(dict_form, EL_STR("iru"))) { + return EL_STR("ichidan"); + } + return EL_STR("godan"); + return 0; +} + +el_val_t ja_ichidan_stem(el_val_t dict_form) { + if (str_ends_with(dict_form, EL_STR("\xe3\x82\x8b"))) { + el_val_t n = str_len(dict_form); + return str_drop_last(dict_form, 1); + } + if (str_ends_with(dict_form, EL_STR("ru"))) { + el_val_t n = str_len(dict_form); + return str_slice(dict_form, 0, (n - 2)); + } + return dict_form; + return 0; +} + +el_val_t ja_godan_stem_change(el_val_t dict_form, el_val_t row) { + el_val_t n = str_len(dict_form); + if (n == 0) { + return dict_form; + } + if (str_eq(row, EL_STR("i"))) { + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x8f"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x8d")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x90"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x8e")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x99"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x97")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xa4"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xa1")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xac"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xab")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xb6"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xb3")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x82\x80"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xbf")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x82\x8b"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x8a")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x86"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x84")); + } + if (str_ends_with(dict_form, EL_STR("ku"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ki")); + } + if (str_ends_with(dict_form, EL_STR("gu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("gi")); + } + if (str_ends_with(dict_form, EL_STR("su"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("shi")); + } + if (str_ends_with(dict_form, EL_STR("tsu"))) { + return el_str_concat(str_drop_last(dict_form, 3), EL_STR("chi")); + } + if (str_ends_with(dict_form, EL_STR("nu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ni")); + } + if (str_ends_with(dict_form, EL_STR("bu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("bi")); + } + if (str_ends_with(dict_form, EL_STR("mu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("mi")); + } + if (str_ends_with(dict_form, EL_STR("ru"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ri")); + } + if (str_ends_with(dict_form, EL_STR("u"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("i")); + } + return dict_form; + } + if (str_eq(row, EL_STR("a"))) { + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x8f"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x8b")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x90"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x8c")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x99"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x95")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xa4"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x9f")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xac"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xaa")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xb6"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xb0")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x82\x80"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xbe")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x82\x8b"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x89")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x86"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x8f")); + } + if (str_ends_with(dict_form, EL_STR("ku"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ka")); + } + if (str_ends_with(dict_form, EL_STR("gu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ga")); + } + if (str_ends_with(dict_form, EL_STR("su"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("sa")); + } + if (str_ends_with(dict_form, EL_STR("tsu"))) { + return el_str_concat(str_drop_last(dict_form, 3), EL_STR("ta")); + } + if (str_ends_with(dict_form, EL_STR("nu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("na")); + } + if (str_ends_with(dict_form, EL_STR("bu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ba")); + } + if (str_ends_with(dict_form, EL_STR("mu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ma")); + } + if (str_ends_with(dict_form, EL_STR("ru"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ra")); + } + if (str_ends_with(dict_form, EL_STR("u"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("wa")); + } + return dict_form; + } + if (str_eq(row, EL_STR("te"))) { + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x8f"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x84")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x90"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x84")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x99"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x97")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xa4"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xa3")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xac"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x93")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xb6"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x93")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x82\x80"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x93")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x82\x8b"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xa3")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x86"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xa3")); + } + if (str_ends_with(dict_form, EL_STR("ku"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("i")); + } + if (str_ends_with(dict_form, EL_STR("gu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("i")); + } + if (str_ends_with(dict_form, EL_STR("su"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("shi")); + } + if (str_ends_with(dict_form, EL_STR("tsu"))) { + return el_str_concat(str_drop_last(dict_form, 3), EL_STR("tt")); + } + if (str_ends_with(dict_form, EL_STR("nu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("n")); + } + if (str_ends_with(dict_form, EL_STR("bu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("n")); + } + if (str_ends_with(dict_form, EL_STR("mu"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("n")); + } + if (str_ends_with(dict_form, EL_STR("ru"))) { + return el_str_concat(str_drop_last(dict_form, 2), EL_STR("tt")); + } + if (str_ends_with(dict_form, EL_STR("u"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("tt")); + } + return dict_form; + } + return dict_form; + return 0; +} + +el_val_t ja_conjugate(el_val_t dict_form, el_val_t form) { + el_val_t group = ja_verb_group(dict_form); + if (str_eq(group, EL_STR("irregular"))) { + if (str_eq(dict_form, EL_STR("\xe3\x81\x99\xe3\x82\x8b"))) { + if (str_eq(form, EL_STR("present"))) { + return EL_STR("\xe3\x81\x99\xe3\x82\x8b"); + } + if (str_eq(form, EL_STR("past"))) { + return EL_STR("\xe3\x81\x97\xe3\x81\x9f"); + } + if (str_eq(form, EL_STR("negative"))) { + return EL_STR("\xe3\x81\x97\xe3\x81\xaa\xe3\x81\x84"); + } + if (str_eq(form, EL_STR("volitional"))) { + return EL_STR("\xe3\x81\x97\xe3\x82\x88\xe3\x81\x86"); + } + if (str_eq(form, EL_STR("polite"))) { + return EL_STR("\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x99"); + } + if (str_eq(form, EL_STR("polite-past"))) { + return EL_STR("\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f"); + } + if (str_eq(form, EL_STR("polite-neg"))) { + return EL_STR("\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93"); + } + if (str_eq(form, EL_STR("te"))) { + return EL_STR("\xe3\x81\x97\xe3\x81\xa6"); + } + return dict_form; + } + if (str_eq(dict_form, EL_STR("suru"))) { + if (str_eq(form, EL_STR("present"))) { + return EL_STR("suru"); + } + if (str_eq(form, EL_STR("past"))) { + return EL_STR("shita"); + } + if (str_eq(form, EL_STR("negative"))) { + return EL_STR("shinai"); + } + if (str_eq(form, EL_STR("volitional"))) { + return EL_STR("shiyou"); + } + if (str_eq(form, EL_STR("polite"))) { + return EL_STR("shimasu"); + } + if (str_eq(form, EL_STR("polite-past"))) { + return EL_STR("shimashita"); + } + if (str_eq(form, EL_STR("polite-neg"))) { + return EL_STR("shimasen"); + } + if (str_eq(form, EL_STR("te"))) { + return EL_STR("shite"); + } + return dict_form; + } + if (str_eq(dict_form, EL_STR("\xe3\x81\x8f\xe3\x82\x8b"))) { + if (str_eq(form, EL_STR("present"))) { + return EL_STR("\xe3\x81\x8f\xe3\x82\x8b"); + } + if (str_eq(form, EL_STR("past"))) { + return EL_STR("\xe3\x81\x8d\xe3\x81\x9f"); + } + if (str_eq(form, EL_STR("negative"))) { + return EL_STR("\xe3\x81\x93\xe3\x81\xaa\xe3\x81\x84"); + } + if (str_eq(form, EL_STR("volitional"))) { + return EL_STR("\xe3\x81\x93\xe3\x82\x88\xe3\x81\x86"); + } + if (str_eq(form, EL_STR("polite"))) { + return EL_STR("\xe3\x81\x8d\xe3\x81\xbe\xe3\x81\x99"); + } + if (str_eq(form, EL_STR("polite-past"))) { + return EL_STR("\xe3\x81\x8d\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f"); + } + if (str_eq(form, EL_STR("polite-neg"))) { + return EL_STR("\xe3\x81\x8d\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93"); + } + if (str_eq(form, EL_STR("te"))) { + return EL_STR("\xe3\x81\x8d\xe3\x81\xa6"); + } + return dict_form; + } + if (str_eq(dict_form, EL_STR("kuru"))) { + if (str_eq(form, EL_STR("present"))) { + return EL_STR("kuru"); + } + if (str_eq(form, EL_STR("past"))) { + return EL_STR("kita"); + } + if (str_eq(form, EL_STR("negative"))) { + return EL_STR("konai"); + } + if (str_eq(form, EL_STR("volitional"))) { + return EL_STR("koyou"); + } + if (str_eq(form, EL_STR("polite"))) { + return EL_STR("kimasu"); + } + if (str_eq(form, EL_STR("polite-past"))) { + return EL_STR("kimashita"); + } + if (str_eq(form, EL_STR("polite-neg"))) { + return EL_STR("kimasen"); + } + if (str_eq(form, EL_STR("te"))) { + return EL_STR("kite"); + } + return dict_form; + } + if (str_eq(dict_form, EL_STR("\xe3\x81\x84\xe3\x82\x8b"))) { + if (str_eq(form, EL_STR("present"))) { + return EL_STR("\xe3\x81\x84\xe3\x82\x8b"); + } + if (str_eq(form, EL_STR("past"))) { + return EL_STR("\xe3\x81\x84\xe3\x81\x9f"); + } + if (str_eq(form, EL_STR("negative"))) { + return EL_STR("\xe3\x81\x84\xe3\x81\xaa\xe3\x81\x84"); + } + if (str_eq(form, EL_STR("volitional"))) { + return EL_STR("\xe3\x81\x84\xe3\x82\x88\xe3\x81\x86"); + } + if (str_eq(form, EL_STR("polite"))) { + return EL_STR("\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99"); + } + if (str_eq(form, EL_STR("polite-past"))) { + return EL_STR("\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f"); + } + if (str_eq(form, EL_STR("polite-neg"))) { + return EL_STR("\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93"); + } + if (str_eq(form, EL_STR("te"))) { + return EL_STR("\xe3\x81\x84\xe3\x81\xa6"); + } + return dict_form; + } + if (str_eq(dict_form, EL_STR("iru"))) { + if (str_eq(form, EL_STR("present"))) { + return EL_STR("iru"); + } + if (str_eq(form, EL_STR("past"))) { + return EL_STR("ita"); + } + if (str_eq(form, EL_STR("negative"))) { + return EL_STR("inai"); + } + if (str_eq(form, EL_STR("volitional"))) { + return EL_STR("iyou"); + } + if (str_eq(form, EL_STR("polite"))) { + return EL_STR("imasu"); + } + if (str_eq(form, EL_STR("polite-past"))) { + return EL_STR("imashita"); + } + if (str_eq(form, EL_STR("polite-neg"))) { + return EL_STR("imasen"); + } + if (str_eq(form, EL_STR("te"))) { + return EL_STR("ite"); + } + return dict_form; + } + if (str_eq(dict_form, EL_STR("\xe3\x81\x82\xe3\x82\x8b"))) { + if (str_eq(form, EL_STR("present"))) { + return EL_STR("\xe3\x81\x82\xe3\x82\x8b"); + } + if (str_eq(form, EL_STR("past"))) { + return EL_STR("\xe3\x81\x82\xe3\x81\xa3\xe3\x81\x9f"); + } + if (str_eq(form, EL_STR("negative"))) { + return EL_STR("\xe3\x81\xaa\xe3\x81\x84"); + } + if (str_eq(form, EL_STR("volitional"))) { + return EL_STR("\xe3\x81\x82\xe3\x82\x8d\xe3\x81\x86"); + } + if (str_eq(form, EL_STR("polite"))) { + return EL_STR("\xe3\x81\x82\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99"); + } + if (str_eq(form, EL_STR("polite-past"))) { + return EL_STR("\xe3\x81\x82\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f"); + } + if (str_eq(form, EL_STR("polite-neg"))) { + return EL_STR("\xe3\x81\x82\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93"); + } + if (str_eq(form, EL_STR("te"))) { + return EL_STR("\xe3\x81\x82\xe3\x81\xa3\xe3\x81\xa6"); + } + return dict_form; + } + if (str_eq(dict_form, EL_STR("aru"))) { + if (str_eq(form, EL_STR("present"))) { + return EL_STR("aru"); + } + if (str_eq(form, EL_STR("past"))) { + return EL_STR("atta"); + } + if (str_eq(form, EL_STR("negative"))) { + return EL_STR("nai"); + } + if (str_eq(form, EL_STR("volitional"))) { + return EL_STR("arou"); + } + if (str_eq(form, EL_STR("polite"))) { + return EL_STR("arimasu"); + } + if (str_eq(form, EL_STR("polite-past"))) { + return EL_STR("arimashita"); + } + if (str_eq(form, EL_STR("polite-neg"))) { + return EL_STR("arimasen"); + } + if (str_eq(form, EL_STR("te"))) { + return EL_STR("atte"); + } + return dict_form; + } + if (str_eq(dict_form, EL_STR("\xe3\x81\xa0"))) { + if (str_eq(form, EL_STR("present"))) { + return EL_STR("\xe3\x81\xa0"); + } + if (str_eq(form, EL_STR("past"))) { + return EL_STR("\xe3\x81\xa0\xe3\x81\xa3\xe3\x81\x9f"); + } + if (str_eq(form, EL_STR("negative"))) { + return EL_STR("\xe3\x81\xa7\xe3\x81\xaf\xe3\x81\xaa\xe3\x81\x84"); + } + if (str_eq(form, EL_STR("volitional"))) { + return EL_STR("\xe3\x81\xa0\xe3\x82\x8d\xe3\x81\x86"); + } + if (str_eq(form, EL_STR("polite"))) { + return EL_STR("\xe3\x81\xa7\xe3\x81\x99"); + } + if (str_eq(form, EL_STR("polite-past"))) { + return EL_STR("\xe3\x81\xa7\xe3\x81\x97\xe3\x81\x9f"); + } + if (str_eq(form, EL_STR("polite-neg"))) { + return EL_STR("\xe3\x81\xa7\xe3\x81\xaf\xe3\x81\x82\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93"); + } + if (str_eq(form, EL_STR("te"))) { + return EL_STR("\xe3\x81\xa7"); + } + return dict_form; + } + if (str_eq(dict_form, EL_STR("da"))) { + if (str_eq(form, EL_STR("present"))) { + return EL_STR("da"); + } + if (str_eq(form, EL_STR("past"))) { + return EL_STR("datta"); + } + if (str_eq(form, EL_STR("negative"))) { + return EL_STR("dewanai"); + } + if (str_eq(form, EL_STR("volitional"))) { + return EL_STR("darou"); + } + if (str_eq(form, EL_STR("polite"))) { + return EL_STR("desu"); + } + if (str_eq(form, EL_STR("polite-past"))) { + return EL_STR("deshita"); + } + if (str_eq(form, EL_STR("polite-neg"))) { + return EL_STR("dewaarimarsen"); + } + if (str_eq(form, EL_STR("te"))) { + return EL_STR("de"); + } + return dict_form; + } + return dict_form; + } + if (str_eq(group, EL_STR("ichidan"))) { + el_val_t stem = ja_ichidan_stem(dict_form); + if (str_eq(form, EL_STR("present"))) { + return dict_form; + } + if (str_eq(form, EL_STR("past"))) { + return el_str_concat(stem, EL_STR("\xe3\x81\x9f")); + } + if (str_eq(form, EL_STR("negative"))) { + return el_str_concat(stem, EL_STR("\xe3\x81\xaa\xe3\x81\x84")); + } + if (str_eq(form, EL_STR("volitional"))) { + return el_str_concat(stem, EL_STR("\xe3\x82\x88\xe3\x81\x86")); + } + if (str_eq(form, EL_STR("polite"))) { + return el_str_concat(stem, EL_STR("\xe3\x81\xbe\xe3\x81\x99")); + } + if (str_eq(form, EL_STR("polite-past"))) { + return el_str_concat(stem, EL_STR("\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f")); + } + if (str_eq(form, EL_STR("polite-neg"))) { + return el_str_concat(stem, EL_STR("\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93")); + } + if (str_eq(form, EL_STR("te"))) { + return el_str_concat(stem, EL_STR("\xe3\x81\xa6")); + } + return dict_form; + } + if (str_eq(form, EL_STR("present"))) { + return dict_form; + } + if (str_eq(form, EL_STR("polite"))) { + el_val_t istem = ja_godan_stem_change(dict_form, EL_STR("i")); + return el_str_concat(istem, EL_STR("\xe3\x81\xbe\xe3\x81\x99")); + } + if (str_eq(form, EL_STR("polite-past"))) { + el_val_t istem = ja_godan_stem_change(dict_form, EL_STR("i")); + return el_str_concat(istem, EL_STR("\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f")); + } + if (str_eq(form, EL_STR("polite-neg"))) { + el_val_t istem = ja_godan_stem_change(dict_form, EL_STR("i")); + return el_str_concat(istem, EL_STR("\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93")); + } + if (str_eq(form, EL_STR("negative"))) { + el_val_t astem = ja_godan_stem_change(dict_form, EL_STR("a")); + return el_str_concat(astem, EL_STR("\xe3\x81\xaa\xe3\x81\x84")); + } + if (str_eq(form, EL_STR("volitional"))) { + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x86"))) { + return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x8a\xe3\x81\x86")); + } + el_val_t istem = ja_godan_stem_change(dict_form, EL_STR("i")); + return el_str_concat(istem, EL_STR("\xe3\x82\x8d\xe3\x81\x86")); + } + if (str_eq(form, EL_STR("te"))) { + el_val_t tstem = ja_godan_stem_change(dict_form, EL_STR("te")); + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x90"))) { + return el_str_concat(tstem, EL_STR("\xe3\x81\x84\xe3\x81\xa7")); + } + if (str_ends_with(dict_form, EL_STR("gu"))) { + return el_str_concat(tstem, EL_STR("ide")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xac"))) { + return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa7")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xb6"))) { + return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa7")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x82\x80"))) { + return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa7")); + } + if (str_ends_with(dict_form, EL_STR("nu"))) { + return el_str_concat(tstem, EL_STR("nde")); + } + if (str_ends_with(dict_form, EL_STR("bu"))) { + return el_str_concat(tstem, EL_STR("nde")); + } + if (str_ends_with(dict_form, EL_STR("mu"))) { + return el_str_concat(tstem, EL_STR("nde")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x99"))) { + return el_str_concat(tstem, EL_STR("\xe3\x81\x97\xe3\x81\xa6")); + } + if (str_ends_with(dict_form, EL_STR("su"))) { + return el_str_concat(tstem, EL_STR("shite")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x8f"))) { + return el_str_concat(tstem, EL_STR("\xe3\x81\xa6")); + } + if (str_ends_with(dict_form, EL_STR("ku"))) { + return el_str_concat(tstem, EL_STR("te")); + } + return el_str_concat(tstem, EL_STR("\xe3\x81\xa6")); + } + if (str_eq(form, EL_STR("past"))) { + el_val_t tstem = ja_godan_stem_change(dict_form, EL_STR("te")); + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x90"))) { + return el_str_concat(tstem, EL_STR("\xe3\x81\x84\xe3\x81\xa0")); + } + if (str_ends_with(dict_form, EL_STR("gu"))) { + return el_str_concat(tstem, EL_STR("ida")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xac"))) { + return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa0")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\xb6"))) { + return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa0")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x82\x80"))) { + return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa0")); + } + if (str_ends_with(dict_form, EL_STR("nu"))) { + return el_str_concat(tstem, EL_STR("nda")); + } + if (str_ends_with(dict_form, EL_STR("bu"))) { + return el_str_concat(tstem, EL_STR("nda")); + } + if (str_ends_with(dict_form, EL_STR("mu"))) { + return el_str_concat(tstem, EL_STR("nda")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x99"))) { + return el_str_concat(tstem, EL_STR("\xe3\x81\x97\xe3\x81\x9f")); + } + if (str_ends_with(dict_form, EL_STR("su"))) { + return el_str_concat(tstem, EL_STR("shita")); + } + if (str_ends_with(dict_form, EL_STR("\xe3\x81\x8f"))) { + return el_str_concat(tstem, EL_STR("\xe3\x81\x9f")); + } + if (str_ends_with(dict_form, EL_STR("ku"))) { + return el_str_concat(tstem, EL_STR("ta")); + } + return el_str_concat(tstem, EL_STR("\xe3\x81\x9f")); + } + return dict_form; + return 0; +} + +el_val_t ja_particle(el_val_t gram_case) { + if (str_eq(gram_case, EL_STR("nominative"))) { + return EL_STR("\xe3\x81\x8c"); + } + if (str_eq(gram_case, EL_STR("accusative"))) { + return EL_STR("\xe3\x82\x92"); + } + if (str_eq(gram_case, EL_STR("dative"))) { + return EL_STR("\xe3\x81\xab"); + } + if (str_eq(gram_case, EL_STR("genitive"))) { + return EL_STR("\xe3\x81\xae"); + } + if (str_eq(gram_case, EL_STR("topic"))) { + return EL_STR("\xe3\x81\xaf"); + } + if (str_eq(gram_case, EL_STR("instrumental"))) { + return EL_STR("\xe3\x81\xa7"); + } + if (str_eq(gram_case, EL_STR("locative"))) { + return EL_STR("\xe3\x81\xab"); + } + if (str_eq(gram_case, EL_STR("ablative"))) { + return EL_STR("\xe3\x81\x8b\xe3\x82\x89"); + } + if (str_eq(gram_case, EL_STR("direction"))) { + return EL_STR("\xe3\x81\xb8"); + } + if (str_eq(gram_case, EL_STR("comitative"))) { + return EL_STR("\xe3\x81\xa8"); + } + return EL_STR(""); + return 0; +} + +el_val_t ja_noun_phrase(el_val_t noun, el_val_t gram_case) { + el_val_t p = ja_particle(gram_case); + if (str_eq(p, EL_STR(""))) { + return noun; + } + return el_str_concat(noun, p); + return 0; +} + +el_val_t ja_question_particle(void) { + return EL_STR("\xe3\x81\x8b"); + return 0; +} + +el_val_t ja_make_question(el_val_t sentence) { + return el_str_concat(sentence, ja_question_particle()); + return 0; +} + el_val_t fi_harmony(el_val_t word) { el_val_t n = str_len(word); el_val_t i = (n - 1); @@ -10513,1700 +12212,6 @@ el_val_t la_noun_phrase(el_val_t noun, el_val_t gram_case, el_val_t number, el_v return 0; } -el_val_t ja_verb_group(el_val_t dict_form) { - if (str_eq(dict_form, EL_STR("\xe3\x81\x99\xe3\x82\x8b"))) { - return EL_STR("irregular"); - } - if (str_eq(dict_form, EL_STR("\xe3\x81\x8f\xe3\x82\x8b"))) { - return EL_STR("irregular"); - } - if (str_eq(dict_form, EL_STR("\xe3\x81\x8f\xe3\x82\x8b"))) { - return EL_STR("irregular"); - } - if (str_eq(dict_form, EL_STR("\xe3\x81\x84\xe3\x82\x8b"))) { - return EL_STR("irregular"); - } - if (str_eq(dict_form, EL_STR("\xe3\x81\x82\xe3\x82\x8b"))) { - return EL_STR("irregular"); - } - if (str_eq(dict_form, EL_STR("\xe3\x81\xa0"))) { - return EL_STR("irregular"); - } - if (str_eq(dict_form, EL_STR("suru"))) { - return EL_STR("irregular"); - } - if (str_eq(dict_form, EL_STR("kuru"))) { - return EL_STR("irregular"); - } - if (str_eq(dict_form, EL_STR("iru"))) { - return EL_STR("irregular"); - } - if (str_eq(dict_form, EL_STR("aru"))) { - return EL_STR("irregular"); - } - if (str_eq(dict_form, EL_STR("da"))) { - return EL_STR("irregular"); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x82\x8b"))) { - return EL_STR("ichidan"); - } - if (str_ends_with(dict_form, EL_STR("eru"))) { - return EL_STR("ichidan"); - } - if (str_ends_with(dict_form, EL_STR("iru"))) { - return EL_STR("ichidan"); - } - return EL_STR("godan"); - return 0; -} - -el_val_t ja_ichidan_stem(el_val_t dict_form) { - if (str_ends_with(dict_form, EL_STR("\xe3\x82\x8b"))) { - el_val_t n = str_len(dict_form); - return str_drop_last(dict_form, 1); - } - if (str_ends_with(dict_form, EL_STR("ru"))) { - el_val_t n = str_len(dict_form); - return str_slice(dict_form, 0, (n - 2)); - } - return dict_form; - return 0; -} - -el_val_t ja_godan_stem_change(el_val_t dict_form, el_val_t row) { - el_val_t n = str_len(dict_form); - if (n == 0) { - return dict_form; - } - if (str_eq(row, EL_STR("i"))) { - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x8f"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x8d")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x90"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x8e")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x99"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x97")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xa4"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xa1")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xac"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xab")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xb6"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xb3")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x82\x80"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xbf")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x82\x8b"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x8a")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x86"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x84")); - } - if (str_ends_with(dict_form, EL_STR("ku"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ki")); - } - if (str_ends_with(dict_form, EL_STR("gu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("gi")); - } - if (str_ends_with(dict_form, EL_STR("su"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("shi")); - } - if (str_ends_with(dict_form, EL_STR("tsu"))) { - return el_str_concat(str_drop_last(dict_form, 3), EL_STR("chi")); - } - if (str_ends_with(dict_form, EL_STR("nu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ni")); - } - if (str_ends_with(dict_form, EL_STR("bu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("bi")); - } - if (str_ends_with(dict_form, EL_STR("mu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("mi")); - } - if (str_ends_with(dict_form, EL_STR("ru"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ri")); - } - if (str_ends_with(dict_form, EL_STR("u"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("i")); - } - return dict_form; - } - if (str_eq(row, EL_STR("a"))) { - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x8f"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x8b")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x90"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x8c")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x99"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x95")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xa4"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x9f")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xac"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xaa")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xb6"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xb0")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x82\x80"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xbe")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x82\x8b"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x89")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x86"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x8f")); - } - if (str_ends_with(dict_form, EL_STR("ku"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ka")); - } - if (str_ends_with(dict_form, EL_STR("gu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ga")); - } - if (str_ends_with(dict_form, EL_STR("su"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("sa")); - } - if (str_ends_with(dict_form, EL_STR("tsu"))) { - return el_str_concat(str_drop_last(dict_form, 3), EL_STR("ta")); - } - if (str_ends_with(dict_form, EL_STR("nu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("na")); - } - if (str_ends_with(dict_form, EL_STR("bu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ba")); - } - if (str_ends_with(dict_form, EL_STR("mu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ma")); - } - if (str_ends_with(dict_form, EL_STR("ru"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("ra")); - } - if (str_ends_with(dict_form, EL_STR("u"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("wa")); - } - return dict_form; - } - if (str_eq(row, EL_STR("te"))) { - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x8f"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x84")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x90"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x84")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x99"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x97")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xa4"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xa3")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xac"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x93")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xb6"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x93")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x82\x80"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x82\x93")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x82\x8b"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xa3")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x86"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\xa3")); - } - if (str_ends_with(dict_form, EL_STR("ku"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("i")); - } - if (str_ends_with(dict_form, EL_STR("gu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("i")); - } - if (str_ends_with(dict_form, EL_STR("su"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("shi")); - } - if (str_ends_with(dict_form, EL_STR("tsu"))) { - return el_str_concat(str_drop_last(dict_form, 3), EL_STR("tt")); - } - if (str_ends_with(dict_form, EL_STR("nu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("n")); - } - if (str_ends_with(dict_form, EL_STR("bu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("n")); - } - if (str_ends_with(dict_form, EL_STR("mu"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("n")); - } - if (str_ends_with(dict_form, EL_STR("ru"))) { - return el_str_concat(str_drop_last(dict_form, 2), EL_STR("tt")); - } - if (str_ends_with(dict_form, EL_STR("u"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("tt")); - } - return dict_form; - } - return dict_form; - return 0; -} - -el_val_t ja_conjugate(el_val_t dict_form, el_val_t form) { - el_val_t group = ja_verb_group(dict_form); - if (str_eq(group, EL_STR("irregular"))) { - if (str_eq(dict_form, EL_STR("\xe3\x81\x99\xe3\x82\x8b"))) { - if (str_eq(form, EL_STR("present"))) { - return EL_STR("\xe3\x81\x99\xe3\x82\x8b"); - } - if (str_eq(form, EL_STR("past"))) { - return EL_STR("\xe3\x81\x97\xe3\x81\x9f"); - } - if (str_eq(form, EL_STR("negative"))) { - return EL_STR("\xe3\x81\x97\xe3\x81\xaa\xe3\x81\x84"); - } - if (str_eq(form, EL_STR("volitional"))) { - return EL_STR("\xe3\x81\x97\xe3\x82\x88\xe3\x81\x86"); - } - if (str_eq(form, EL_STR("polite"))) { - return EL_STR("\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x99"); - } - if (str_eq(form, EL_STR("polite-past"))) { - return EL_STR("\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f"); - } - if (str_eq(form, EL_STR("polite-neg"))) { - return EL_STR("\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93"); - } - if (str_eq(form, EL_STR("te"))) { - return EL_STR("\xe3\x81\x97\xe3\x81\xa6"); - } - return dict_form; - } - if (str_eq(dict_form, EL_STR("suru"))) { - if (str_eq(form, EL_STR("present"))) { - return EL_STR("suru"); - } - if (str_eq(form, EL_STR("past"))) { - return EL_STR("shita"); - } - if (str_eq(form, EL_STR("negative"))) { - return EL_STR("shinai"); - } - if (str_eq(form, EL_STR("volitional"))) { - return EL_STR("shiyou"); - } - if (str_eq(form, EL_STR("polite"))) { - return EL_STR("shimasu"); - } - if (str_eq(form, EL_STR("polite-past"))) { - return EL_STR("shimashita"); - } - if (str_eq(form, EL_STR("polite-neg"))) { - return EL_STR("shimasen"); - } - if (str_eq(form, EL_STR("te"))) { - return EL_STR("shite"); - } - return dict_form; - } - if (str_eq(dict_form, EL_STR("\xe3\x81\x8f\xe3\x82\x8b"))) { - if (str_eq(form, EL_STR("present"))) { - return EL_STR("\xe3\x81\x8f\xe3\x82\x8b"); - } - if (str_eq(form, EL_STR("past"))) { - return EL_STR("\xe3\x81\x8d\xe3\x81\x9f"); - } - if (str_eq(form, EL_STR("negative"))) { - return EL_STR("\xe3\x81\x93\xe3\x81\xaa\xe3\x81\x84"); - } - if (str_eq(form, EL_STR("volitional"))) { - return EL_STR("\xe3\x81\x93\xe3\x82\x88\xe3\x81\x86"); - } - if (str_eq(form, EL_STR("polite"))) { - return EL_STR("\xe3\x81\x8d\xe3\x81\xbe\xe3\x81\x99"); - } - if (str_eq(form, EL_STR("polite-past"))) { - return EL_STR("\xe3\x81\x8d\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f"); - } - if (str_eq(form, EL_STR("polite-neg"))) { - return EL_STR("\xe3\x81\x8d\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93"); - } - if (str_eq(form, EL_STR("te"))) { - return EL_STR("\xe3\x81\x8d\xe3\x81\xa6"); - } - return dict_form; - } - if (str_eq(dict_form, EL_STR("kuru"))) { - if (str_eq(form, EL_STR("present"))) { - return EL_STR("kuru"); - } - if (str_eq(form, EL_STR("past"))) { - return EL_STR("kita"); - } - if (str_eq(form, EL_STR("negative"))) { - return EL_STR("konai"); - } - if (str_eq(form, EL_STR("volitional"))) { - return EL_STR("koyou"); - } - if (str_eq(form, EL_STR("polite"))) { - return EL_STR("kimasu"); - } - if (str_eq(form, EL_STR("polite-past"))) { - return EL_STR("kimashita"); - } - if (str_eq(form, EL_STR("polite-neg"))) { - return EL_STR("kimasen"); - } - if (str_eq(form, EL_STR("te"))) { - return EL_STR("kite"); - } - return dict_form; - } - if (str_eq(dict_form, EL_STR("\xe3\x81\x84\xe3\x82\x8b"))) { - if (str_eq(form, EL_STR("present"))) { - return EL_STR("\xe3\x81\x84\xe3\x82\x8b"); - } - if (str_eq(form, EL_STR("past"))) { - return EL_STR("\xe3\x81\x84\xe3\x81\x9f"); - } - if (str_eq(form, EL_STR("negative"))) { - return EL_STR("\xe3\x81\x84\xe3\x81\xaa\xe3\x81\x84"); - } - if (str_eq(form, EL_STR("volitional"))) { - return EL_STR("\xe3\x81\x84\xe3\x82\x88\xe3\x81\x86"); - } - if (str_eq(form, EL_STR("polite"))) { - return EL_STR("\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99"); - } - if (str_eq(form, EL_STR("polite-past"))) { - return EL_STR("\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f"); - } - if (str_eq(form, EL_STR("polite-neg"))) { - return EL_STR("\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93"); - } - if (str_eq(form, EL_STR("te"))) { - return EL_STR("\xe3\x81\x84\xe3\x81\xa6"); - } - return dict_form; - } - if (str_eq(dict_form, EL_STR("iru"))) { - if (str_eq(form, EL_STR("present"))) { - return EL_STR("iru"); - } - if (str_eq(form, EL_STR("past"))) { - return EL_STR("ita"); - } - if (str_eq(form, EL_STR("negative"))) { - return EL_STR("inai"); - } - if (str_eq(form, EL_STR("volitional"))) { - return EL_STR("iyou"); - } - if (str_eq(form, EL_STR("polite"))) { - return EL_STR("imasu"); - } - if (str_eq(form, EL_STR("polite-past"))) { - return EL_STR("imashita"); - } - if (str_eq(form, EL_STR("polite-neg"))) { - return EL_STR("imasen"); - } - if (str_eq(form, EL_STR("te"))) { - return EL_STR("ite"); - } - return dict_form; - } - if (str_eq(dict_form, EL_STR("\xe3\x81\x82\xe3\x82\x8b"))) { - if (str_eq(form, EL_STR("present"))) { - return EL_STR("\xe3\x81\x82\xe3\x82\x8b"); - } - if (str_eq(form, EL_STR("past"))) { - return EL_STR("\xe3\x81\x82\xe3\x81\xa3\xe3\x81\x9f"); - } - if (str_eq(form, EL_STR("negative"))) { - return EL_STR("\xe3\x81\xaa\xe3\x81\x84"); - } - if (str_eq(form, EL_STR("volitional"))) { - return EL_STR("\xe3\x81\x82\xe3\x82\x8d\xe3\x81\x86"); - } - if (str_eq(form, EL_STR("polite"))) { - return EL_STR("\xe3\x81\x82\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99"); - } - if (str_eq(form, EL_STR("polite-past"))) { - return EL_STR("\xe3\x81\x82\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f"); - } - if (str_eq(form, EL_STR("polite-neg"))) { - return EL_STR("\xe3\x81\x82\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93"); - } - if (str_eq(form, EL_STR("te"))) { - return EL_STR("\xe3\x81\x82\xe3\x81\xa3\xe3\x81\xa6"); - } - return dict_form; - } - if (str_eq(dict_form, EL_STR("aru"))) { - if (str_eq(form, EL_STR("present"))) { - return EL_STR("aru"); - } - if (str_eq(form, EL_STR("past"))) { - return EL_STR("atta"); - } - if (str_eq(form, EL_STR("negative"))) { - return EL_STR("nai"); - } - if (str_eq(form, EL_STR("volitional"))) { - return EL_STR("arou"); - } - if (str_eq(form, EL_STR("polite"))) { - return EL_STR("arimasu"); - } - if (str_eq(form, EL_STR("polite-past"))) { - return EL_STR("arimashita"); - } - if (str_eq(form, EL_STR("polite-neg"))) { - return EL_STR("arimasen"); - } - if (str_eq(form, EL_STR("te"))) { - return EL_STR("atte"); - } - return dict_form; - } - if (str_eq(dict_form, EL_STR("\xe3\x81\xa0"))) { - if (str_eq(form, EL_STR("present"))) { - return EL_STR("\xe3\x81\xa0"); - } - if (str_eq(form, EL_STR("past"))) { - return EL_STR("\xe3\x81\xa0\xe3\x81\xa3\xe3\x81\x9f"); - } - if (str_eq(form, EL_STR("negative"))) { - return EL_STR("\xe3\x81\xa7\xe3\x81\xaf\xe3\x81\xaa\xe3\x81\x84"); - } - if (str_eq(form, EL_STR("volitional"))) { - return EL_STR("\xe3\x81\xa0\xe3\x82\x8d\xe3\x81\x86"); - } - if (str_eq(form, EL_STR("polite"))) { - return EL_STR("\xe3\x81\xa7\xe3\x81\x99"); - } - if (str_eq(form, EL_STR("polite-past"))) { - return EL_STR("\xe3\x81\xa7\xe3\x81\x97\xe3\x81\x9f"); - } - if (str_eq(form, EL_STR("polite-neg"))) { - return EL_STR("\xe3\x81\xa7\xe3\x81\xaf\xe3\x81\x82\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93"); - } - if (str_eq(form, EL_STR("te"))) { - return EL_STR("\xe3\x81\xa7"); - } - return dict_form; - } - if (str_eq(dict_form, EL_STR("da"))) { - if (str_eq(form, EL_STR("present"))) { - return EL_STR("da"); - } - if (str_eq(form, EL_STR("past"))) { - return EL_STR("datta"); - } - if (str_eq(form, EL_STR("negative"))) { - return EL_STR("dewanai"); - } - if (str_eq(form, EL_STR("volitional"))) { - return EL_STR("darou"); - } - if (str_eq(form, EL_STR("polite"))) { - return EL_STR("desu"); - } - if (str_eq(form, EL_STR("polite-past"))) { - return EL_STR("deshita"); - } - if (str_eq(form, EL_STR("polite-neg"))) { - return EL_STR("dewaarimarsen"); - } - if (str_eq(form, EL_STR("te"))) { - return EL_STR("de"); - } - return dict_form; - } - return dict_form; - } - if (str_eq(group, EL_STR("ichidan"))) { - el_val_t stem = ja_ichidan_stem(dict_form); - if (str_eq(form, EL_STR("present"))) { - return dict_form; - } - if (str_eq(form, EL_STR("past"))) { - return el_str_concat(stem, EL_STR("\xe3\x81\x9f")); - } - if (str_eq(form, EL_STR("negative"))) { - return el_str_concat(stem, EL_STR("\xe3\x81\xaa\xe3\x81\x84")); - } - if (str_eq(form, EL_STR("volitional"))) { - return el_str_concat(stem, EL_STR("\xe3\x82\x88\xe3\x81\x86")); - } - if (str_eq(form, EL_STR("polite"))) { - return el_str_concat(stem, EL_STR("\xe3\x81\xbe\xe3\x81\x99")); - } - if (str_eq(form, EL_STR("polite-past"))) { - return el_str_concat(stem, EL_STR("\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f")); - } - if (str_eq(form, EL_STR("polite-neg"))) { - return el_str_concat(stem, EL_STR("\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93")); - } - if (str_eq(form, EL_STR("te"))) { - return el_str_concat(stem, EL_STR("\xe3\x81\xa6")); - } - return dict_form; - } - if (str_eq(form, EL_STR("present"))) { - return dict_form; - } - if (str_eq(form, EL_STR("polite"))) { - el_val_t istem = ja_godan_stem_change(dict_form, EL_STR("i")); - return el_str_concat(istem, EL_STR("\xe3\x81\xbe\xe3\x81\x99")); - } - if (str_eq(form, EL_STR("polite-past"))) { - el_val_t istem = ja_godan_stem_change(dict_form, EL_STR("i")); - return el_str_concat(istem, EL_STR("\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f")); - } - if (str_eq(form, EL_STR("polite-neg"))) { - el_val_t istem = ja_godan_stem_change(dict_form, EL_STR("i")); - return el_str_concat(istem, EL_STR("\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93")); - } - if (str_eq(form, EL_STR("negative"))) { - el_val_t astem = ja_godan_stem_change(dict_form, EL_STR("a")); - return el_str_concat(astem, EL_STR("\xe3\x81\xaa\xe3\x81\x84")); - } - if (str_eq(form, EL_STR("volitional"))) { - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x86"))) { - return el_str_concat(str_drop_last(dict_form, 1), EL_STR("\xe3\x81\x8a\xe3\x81\x86")); - } - el_val_t istem = ja_godan_stem_change(dict_form, EL_STR("i")); - return el_str_concat(istem, EL_STR("\xe3\x82\x8d\xe3\x81\x86")); - } - if (str_eq(form, EL_STR("te"))) { - el_val_t tstem = ja_godan_stem_change(dict_form, EL_STR("te")); - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x90"))) { - return el_str_concat(tstem, EL_STR("\xe3\x81\x84\xe3\x81\xa7")); - } - if (str_ends_with(dict_form, EL_STR("gu"))) { - return el_str_concat(tstem, EL_STR("ide")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xac"))) { - return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa7")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xb6"))) { - return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa7")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x82\x80"))) { - return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa7")); - } - if (str_ends_with(dict_form, EL_STR("nu"))) { - return el_str_concat(tstem, EL_STR("nde")); - } - if (str_ends_with(dict_form, EL_STR("bu"))) { - return el_str_concat(tstem, EL_STR("nde")); - } - if (str_ends_with(dict_form, EL_STR("mu"))) { - return el_str_concat(tstem, EL_STR("nde")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x99"))) { - return el_str_concat(tstem, EL_STR("\xe3\x81\x97\xe3\x81\xa6")); - } - if (str_ends_with(dict_form, EL_STR("su"))) { - return el_str_concat(tstem, EL_STR("shite")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x8f"))) { - return el_str_concat(tstem, EL_STR("\xe3\x81\xa6")); - } - if (str_ends_with(dict_form, EL_STR("ku"))) { - return el_str_concat(tstem, EL_STR("te")); - } - return el_str_concat(tstem, EL_STR("\xe3\x81\xa6")); - } - if (str_eq(form, EL_STR("past"))) { - el_val_t tstem = ja_godan_stem_change(dict_form, EL_STR("te")); - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x90"))) { - return el_str_concat(tstem, EL_STR("\xe3\x81\x84\xe3\x81\xa0")); - } - if (str_ends_with(dict_form, EL_STR("gu"))) { - return el_str_concat(tstem, EL_STR("ida")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xac"))) { - return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa0")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\xb6"))) { - return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa0")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x82\x80"))) { - return el_str_concat(tstem, EL_STR("\xe3\x82\x93\xe3\x81\xa0")); - } - if (str_ends_with(dict_form, EL_STR("nu"))) { - return el_str_concat(tstem, EL_STR("nda")); - } - if (str_ends_with(dict_form, EL_STR("bu"))) { - return el_str_concat(tstem, EL_STR("nda")); - } - if (str_ends_with(dict_form, EL_STR("mu"))) { - return el_str_concat(tstem, EL_STR("nda")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x99"))) { - return el_str_concat(tstem, EL_STR("\xe3\x81\x97\xe3\x81\x9f")); - } - if (str_ends_with(dict_form, EL_STR("su"))) { - return el_str_concat(tstem, EL_STR("shita")); - } - if (str_ends_with(dict_form, EL_STR("\xe3\x81\x8f"))) { - return el_str_concat(tstem, EL_STR("\xe3\x81\x9f")); - } - if (str_ends_with(dict_form, EL_STR("ku"))) { - return el_str_concat(tstem, EL_STR("ta")); - } - return el_str_concat(tstem, EL_STR("\xe3\x81\x9f")); - } - return dict_form; - return 0; -} - -el_val_t ja_particle(el_val_t gram_case) { - if (str_eq(gram_case, EL_STR("nominative"))) { - return EL_STR("\xe3\x81\x8c"); - } - if (str_eq(gram_case, EL_STR("accusative"))) { - return EL_STR("\xe3\x82\x92"); - } - if (str_eq(gram_case, EL_STR("dative"))) { - return EL_STR("\xe3\x81\xab"); - } - if (str_eq(gram_case, EL_STR("genitive"))) { - return EL_STR("\xe3\x81\xae"); - } - if (str_eq(gram_case, EL_STR("topic"))) { - return EL_STR("\xe3\x81\xaf"); - } - if (str_eq(gram_case, EL_STR("instrumental"))) { - return EL_STR("\xe3\x81\xa7"); - } - if (str_eq(gram_case, EL_STR("locative"))) { - return EL_STR("\xe3\x81\xab"); - } - if (str_eq(gram_case, EL_STR("ablative"))) { - return EL_STR("\xe3\x81\x8b\xe3\x82\x89"); - } - if (str_eq(gram_case, EL_STR("direction"))) { - return EL_STR("\xe3\x81\xb8"); - } - if (str_eq(gram_case, EL_STR("comitative"))) { - return EL_STR("\xe3\x81\xa8"); - } - return EL_STR(""); - return 0; -} - -el_val_t ja_noun_phrase(el_val_t noun, el_val_t gram_case) { - el_val_t p = ja_particle(gram_case); - if (str_eq(p, EL_STR(""))) { - return noun; - } - return el_str_concat(noun, p); - return 0; -} - -el_val_t ja_question_particle(void) { - return EL_STR("\xe3\x81\x8b"); - return 0; -} - -el_val_t ja_make_question(el_val_t sentence) { - return el_str_concat(sentence, ja_question_particle()); - return 0; -} - -el_val_t str_ends(el_val_t s, el_val_t suf) { - return str_ends_with(s, suf); - return 0; -} - -el_val_t str_last_char(el_val_t s) { - el_val_t n = str_len(s); - if (n == 0) { - return EL_STR(""); - } - return str_slice(s, (n - 1), n); - return 0; -} - -el_val_t str_last2(el_val_t s) { - el_val_t n = str_len(s); - if (n < 2) { - return s; - } - return str_slice(s, (n - 2), n); - return 0; -} - -el_val_t str_last3(el_val_t s) { - el_val_t n = str_len(s); - if (n < 3) { - return s; - } - return str_slice(s, (n - 3), n); - return 0; -} - -el_val_t str_drop_last(el_val_t s, el_val_t n) { - el_val_t len = str_len(s); - if (n >= len) { - return EL_STR(""); - } - return str_slice(s, 0, (len - n)); - return 0; -} - -el_val_t is_vowel(el_val_t c) { - if (str_eq(c, EL_STR("a"))) { - return 1; - } - if (str_eq(c, EL_STR("e"))) { - return 1; - } - if (str_eq(c, EL_STR("i"))) { - return 1; - } - if (str_eq(c, EL_STR("o"))) { - return 1; - } - if (str_eq(c, EL_STR("u"))) { - return 1; - } - return 0; - return 0; -} - -el_val_t morph_apply_suffix(el_val_t base, el_val_t suffix) { - if (str_eq(suffix, EL_STR(""))) { - return base; - } - el_val_t suf_start = str_slice(suffix, 0, 1); - el_val_t suf_starts_vowel = is_vowel(suf_start); - if (suf_starts_vowel) { - if (str_ends(base, EL_STR("e"))) { - if (!str_ends(base, EL_STR("ee"))) { - return el_str_concat(str_drop_last(base, 1), suffix); - } - } - } - if (suf_starts_vowel) { - el_val_t n = str_len(base); - if (n >= 3) { - el_val_t c3 = str_slice(base, (n - 3), (n - 2)); - el_val_t c2 = str_slice(base, (n - 2), (n - 1)); - el_val_t c1 = str_slice(base, (n - 1), n); - if (!is_vowel(c3)) { - if (is_vowel(c2)) { - if (!is_vowel(c1)) { - if (!str_eq(c1, EL_STR("w"))) { - if (!str_eq(c1, EL_STR("x"))) { - if (!str_eq(c1, EL_STR("y"))) { - return el_str_concat(el_str_concat(base, c1), suffix); - } - } - } - } - } - } - } - } - return el_str_concat(base, suffix); - return 0; -} - -el_val_t en_irregular_plural(el_val_t word) { - if (str_eq(word, EL_STR("child"))) { - return EL_STR("children"); - } - if (str_eq(word, EL_STR("man"))) { - return EL_STR("men"); - } - if (str_eq(word, EL_STR("woman"))) { - return EL_STR("women"); - } - if (str_eq(word, EL_STR("tooth"))) { - return EL_STR("teeth"); - } - if (str_eq(word, EL_STR("foot"))) { - return EL_STR("feet"); - } - if (str_eq(word, EL_STR("goose"))) { - return EL_STR("geese"); - } - if (str_eq(word, EL_STR("mouse"))) { - return EL_STR("mice"); - } - if (str_eq(word, EL_STR("louse"))) { - return EL_STR("lice"); - } - if (str_eq(word, EL_STR("ox"))) { - return EL_STR("oxen"); - } - if (str_eq(word, EL_STR("person"))) { - return EL_STR("people"); - } - if (str_eq(word, EL_STR("leaf"))) { - return EL_STR("leaves"); - } - if (str_eq(word, EL_STR("loaf"))) { - return EL_STR("loaves"); - } - if (str_eq(word, EL_STR("wolf"))) { - return EL_STR("wolves"); - } - if (str_eq(word, EL_STR("life"))) { - return EL_STR("lives"); - } - if (str_eq(word, EL_STR("knife"))) { - return EL_STR("knives"); - } - if (str_eq(word, EL_STR("wife"))) { - return EL_STR("wives"); - } - if (str_eq(word, EL_STR("half"))) { - return EL_STR("halves"); - } - if (str_eq(word, EL_STR("self"))) { - return EL_STR("selves"); - } - if (str_eq(word, EL_STR("elf"))) { - return EL_STR("elves"); - } - if (str_eq(word, EL_STR("shelf"))) { - return EL_STR("shelves"); - } - if (str_eq(word, EL_STR("fish"))) { - return EL_STR("fish"); - } - if (str_eq(word, EL_STR("sheep"))) { - return EL_STR("sheep"); - } - if (str_eq(word, EL_STR("deer"))) { - return EL_STR("deer"); - } - if (str_eq(word, EL_STR("moose"))) { - return EL_STR("moose"); - } - if (str_eq(word, EL_STR("series"))) { - return EL_STR("series"); - } - if (str_eq(word, EL_STR("species"))) { - return EL_STR("species"); - } - return EL_STR(""); - return 0; -} - -el_val_t en_irregular_singular(el_val_t word) { - if (str_eq(word, EL_STR("children"))) { - return EL_STR("child"); - } - if (str_eq(word, EL_STR("men"))) { - return EL_STR("man"); - } - if (str_eq(word, EL_STR("women"))) { - return EL_STR("woman"); - } - if (str_eq(word, EL_STR("teeth"))) { - return EL_STR("tooth"); - } - if (str_eq(word, EL_STR("feet"))) { - return EL_STR("foot"); - } - if (str_eq(word, EL_STR("geese"))) { - return EL_STR("goose"); - } - if (str_eq(word, EL_STR("mice"))) { - return EL_STR("mouse"); - } - if (str_eq(word, EL_STR("lice"))) { - return EL_STR("louse"); - } - if (str_eq(word, EL_STR("oxen"))) { - return EL_STR("ox"); - } - if (str_eq(word, EL_STR("people"))) { - return EL_STR("person"); - } - if (str_eq(word, EL_STR("leaves"))) { - return EL_STR("leaf"); - } - if (str_eq(word, EL_STR("wolves"))) { - return EL_STR("wolf"); - } - if (str_eq(word, EL_STR("lives"))) { - return EL_STR("life"); - } - if (str_eq(word, EL_STR("knives"))) { - return EL_STR("knife"); - } - if (str_eq(word, EL_STR("wives"))) { - return EL_STR("wife"); - } - if (str_eq(word, EL_STR("halves"))) { - return EL_STR("half"); - } - if (str_eq(word, EL_STR("selves"))) { - return EL_STR("self"); - } - if (str_eq(word, EL_STR("elves"))) { - return EL_STR("elf"); - } - if (str_eq(word, EL_STR("shelves"))) { - return EL_STR("shelf"); - } - if (str_eq(word, EL_STR("fish"))) { - return EL_STR("fish"); - } - if (str_eq(word, EL_STR("sheep"))) { - return EL_STR("sheep"); - } - if (str_eq(word, EL_STR("deer"))) { - return EL_STR("deer"); - } - if (str_eq(word, EL_STR("moose"))) { - return EL_STR("moose"); - } - if (str_eq(word, EL_STR("series"))) { - return EL_STR("series"); - } - if (str_eq(word, EL_STR("species"))) { - return EL_STR("species"); - } - return EL_STR(""); - return 0; -} - -el_val_t en_irregular_verb(el_val_t base) { - el_val_t empty = el_list_empty(); - if (str_eq(base, EL_STR("be"))) { - el_val_t r = el_list_new(5, EL_STR("be"), EL_STR("is"), EL_STR("was"), EL_STR("been"), EL_STR("being")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("have"))) { - el_val_t r = el_list_new(5, EL_STR("have"), EL_STR("has"), EL_STR("had"), EL_STR("had"), EL_STR("having")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("do"))) { - el_val_t r = el_list_new(5, EL_STR("do"), EL_STR("does"), EL_STR("did"), EL_STR("done"), EL_STR("doing")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("go"))) { - el_val_t r = el_list_new(5, EL_STR("go"), EL_STR("goes"), EL_STR("went"), EL_STR("gone"), EL_STR("going")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("say"))) { - el_val_t r = el_list_new(5, EL_STR("say"), EL_STR("says"), EL_STR("said"), EL_STR("said"), EL_STR("saying")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("make"))) { - el_val_t r = el_list_new(5, EL_STR("make"), EL_STR("makes"), EL_STR("made"), EL_STR("made"), EL_STR("making")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("know"))) { - el_val_t r = el_list_new(5, EL_STR("know"), EL_STR("knows"), EL_STR("knew"), EL_STR("known"), EL_STR("knowing")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("take"))) { - el_val_t r = el_list_new(5, EL_STR("take"), EL_STR("takes"), EL_STR("took"), EL_STR("taken"), EL_STR("taking")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("see"))) { - el_val_t r = el_list_new(5, EL_STR("see"), EL_STR("sees"), EL_STR("saw"), EL_STR("seen"), EL_STR("seeing")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("come"))) { - el_val_t r = el_list_new(5, EL_STR("come"), EL_STR("comes"), EL_STR("came"), EL_STR("come"), EL_STR("coming")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("think"))) { - el_val_t r = el_list_new(5, EL_STR("think"), EL_STR("thinks"), EL_STR("thought"), EL_STR("thought"), EL_STR("thinking")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("get"))) { - el_val_t r = el_list_new(5, EL_STR("get"), EL_STR("gets"), EL_STR("got"), EL_STR("gotten"), EL_STR("getting")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("give"))) { - el_val_t r = el_list_new(5, EL_STR("give"), EL_STR("gives"), EL_STR("gave"), EL_STR("given"), EL_STR("giving")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("find"))) { - el_val_t r = el_list_new(5, EL_STR("find"), EL_STR("finds"), EL_STR("found"), EL_STR("found"), EL_STR("finding")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("tell"))) { - el_val_t r = el_list_new(5, EL_STR("tell"), EL_STR("tells"), EL_STR("told"), EL_STR("told"), EL_STR("telling")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("become"))) { - el_val_t r = el_list_new(5, EL_STR("become"), EL_STR("becomes"), EL_STR("became"), EL_STR("become"), EL_STR("becoming")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("leave"))) { - el_val_t r = el_list_new(5, EL_STR("leave"), EL_STR("leaves"), EL_STR("left"), EL_STR("left"), EL_STR("leaving")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("feel"))) { - el_val_t r = el_list_new(5, EL_STR("feel"), EL_STR("feels"), EL_STR("felt"), EL_STR("felt"), EL_STR("feeling")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("put"))) { - el_val_t r = el_list_new(5, EL_STR("put"), EL_STR("puts"), EL_STR("put"), EL_STR("put"), EL_STR("putting")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("bring"))) { - el_val_t r = el_list_new(5, EL_STR("bring"), EL_STR("brings"), EL_STR("brought"), EL_STR("brought"), EL_STR("bringing")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("begin"))) { - el_val_t r = el_list_new(5, EL_STR("begin"), EL_STR("begins"), EL_STR("began"), EL_STR("begun"), EL_STR("beginning")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("keep"))) { - el_val_t r = el_list_new(5, EL_STR("keep"), EL_STR("keeps"), EL_STR("kept"), EL_STR("kept"), EL_STR("keeping")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("hold"))) { - el_val_t r = el_list_new(5, EL_STR("hold"), EL_STR("holds"), EL_STR("held"), EL_STR("held"), EL_STR("holding")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("write"))) { - el_val_t r = el_list_new(5, EL_STR("write"), EL_STR("writes"), EL_STR("wrote"), EL_STR("written"), EL_STR("writing")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("stand"))) { - el_val_t r = el_list_new(5, EL_STR("stand"), EL_STR("stands"), EL_STR("stood"), EL_STR("stood"), EL_STR("standing")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("hear"))) { - el_val_t r = el_list_new(5, EL_STR("hear"), EL_STR("hears"), EL_STR("heard"), EL_STR("heard"), EL_STR("hearing")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("let"))) { - el_val_t r = el_list_new(5, EL_STR("let"), EL_STR("lets"), EL_STR("let"), EL_STR("let"), EL_STR("letting")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("run"))) { - el_val_t r = el_list_new(5, EL_STR("run"), EL_STR("runs"), EL_STR("ran"), EL_STR("run"), EL_STR("running")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("meet"))) { - el_val_t r = el_list_new(5, EL_STR("meet"), EL_STR("meets"), EL_STR("met"), EL_STR("met"), EL_STR("meeting")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("sit"))) { - el_val_t r = el_list_new(5, EL_STR("sit"), EL_STR("sits"), EL_STR("sat"), EL_STR("sat"), EL_STR("sitting")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("send"))) { - el_val_t r = el_list_new(5, EL_STR("send"), EL_STR("sends"), EL_STR("sent"), EL_STR("sent"), EL_STR("sending")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("speak"))) { - el_val_t r = el_list_new(5, EL_STR("speak"), EL_STR("speaks"), EL_STR("spoke"), EL_STR("spoken"), EL_STR("speaking")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("buy"))) { - el_val_t r = el_list_new(5, EL_STR("buy"), EL_STR("buys"), EL_STR("bought"), EL_STR("bought"), EL_STR("buying")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("pay"))) { - el_val_t r = el_list_new(5, EL_STR("pay"), EL_STR("pays"), EL_STR("paid"), EL_STR("paid"), EL_STR("paying")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("read"))) { - el_val_t r = el_list_new(5, EL_STR("read"), EL_STR("reads"), EL_STR("read"), EL_STR("read"), EL_STR("reading")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("win"))) { - el_val_t r = el_list_new(5, EL_STR("win"), EL_STR("wins"), EL_STR("won"), EL_STR("won"), EL_STR("winning")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("eat"))) { - el_val_t r = el_list_new(5, EL_STR("eat"), EL_STR("eats"), EL_STR("ate"), EL_STR("eaten"), EL_STR("eating")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("fall"))) { - el_val_t r = el_list_new(5, EL_STR("fall"), EL_STR("falls"), EL_STR("fell"), EL_STR("fallen"), EL_STR("falling")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("sleep"))) { - el_val_t r = el_list_new(5, EL_STR("sleep"), EL_STR("sleeps"), EL_STR("slept"), EL_STR("slept"), EL_STR("sleeping")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("drive"))) { - el_val_t r = el_list_new(5, EL_STR("drive"), EL_STR("drives"), EL_STR("drove"), EL_STR("driven"), EL_STR("driving")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("build"))) { - el_val_t r = el_list_new(5, EL_STR("build"), EL_STR("builds"), EL_STR("built"), EL_STR("built"), EL_STR("building")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("cut"))) { - el_val_t r = el_list_new(5, EL_STR("cut"), EL_STR("cuts"), EL_STR("cut"), EL_STR("cut"), EL_STR("cutting")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("set"))) { - el_val_t r = el_list_new(5, EL_STR("set"), EL_STR("sets"), EL_STR("set"), EL_STR("set"), EL_STR("setting")); - EL_NULL; - return r; - } - if (str_eq(base, EL_STR("hit"))) { - el_val_t r = el_list_new(5, EL_STR("hit"), EL_STR("hits"), EL_STR("hit"), EL_STR("hit"), EL_STR("hitting")); - EL_NULL; - return r; - } - return empty; - return 0; -} - -el_val_t en_verb_3sg(el_val_t base) { - if (str_ends(base, EL_STR("s"))) { - return el_str_concat(base, EL_STR("es")); - } - if (str_ends(base, EL_STR("x"))) { - return el_str_concat(base, EL_STR("es")); - } - if (str_ends(base, EL_STR("z"))) { - return el_str_concat(base, EL_STR("es")); - } - if (str_ends(base, EL_STR("ch"))) { - return el_str_concat(base, EL_STR("es")); - } - if (str_ends(base, EL_STR("sh"))) { - return el_str_concat(base, EL_STR("es")); - } - el_val_t last = str_last_char(base); - if (str_eq(last, EL_STR("y"))) { - el_val_t prev = str_drop_last(base, 1); - el_val_t prev_last = str_last_char(prev); - if (!is_vowel(prev_last)) { - return el_str_concat(prev, EL_STR("ies")); - } - } - return el_str_concat(base, EL_STR("s")); - return 0; -} - -el_val_t en_should_double_final(el_val_t base) { - el_val_t n = str_len(base); - if (n < 3) { - return 0; - } - el_val_t c3 = str_slice(base, (n - 3), (n - 2)); - el_val_t c2 = str_slice(base, (n - 2), (n - 1)); - el_val_t c1 = str_slice(base, (n - 1), n); - if (!is_vowel(c3)) { - if (is_vowel(c2)) { - if (!is_vowel(c1)) { - if (!str_eq(c1, EL_STR("w"))) { - if (!str_eq(c1, EL_STR("x"))) { - if (!str_eq(c1, EL_STR("y"))) { - return 1; - } - } - } - } - } - } - return 0; - return 0; -} - -el_val_t en_verb_past(el_val_t base) { - if (str_ends(base, EL_STR("e"))) { - return el_str_concat(base, EL_STR("d")); - } - el_val_t last = str_last_char(base); - if (str_eq(last, EL_STR("y"))) { - el_val_t prev = str_drop_last(base, 1); - el_val_t prev_last = str_last_char(prev); - if (!is_vowel(prev_last)) { - return el_str_concat(prev, EL_STR("ied")); - } - } - if (en_should_double_final(base)) { - return el_str_concat(el_str_concat(base, last), EL_STR("ed")); - } - return el_str_concat(base, EL_STR("ed")); - return 0; -} - -el_val_t en_verb_gerund(el_val_t base) { - if (str_ends(base, EL_STR("ie"))) { - return el_str_concat(str_drop_last(base, 2), EL_STR("ying")); - } - if (str_ends(base, EL_STR("e"))) { - if (!str_ends(base, EL_STR("ee"))) { - return el_str_concat(str_drop_last(base, 1), EL_STR("ing")); - } - } - el_val_t last = str_last_char(base); - if (en_should_double_final(base)) { - return el_str_concat(el_str_concat(base, last), EL_STR("ing")); - } - return el_str_concat(base, EL_STR("ing")); - return 0; -} - -el_val_t en_pluralize_regular(el_val_t singular) { - if (str_ends(singular, EL_STR("s"))) { - return el_str_concat(singular, EL_STR("es")); - } - if (str_ends(singular, EL_STR("x"))) { - return el_str_concat(singular, EL_STR("es")); - } - if (str_ends(singular, EL_STR("z"))) { - return el_str_concat(singular, EL_STR("es")); - } - if (str_ends(singular, EL_STR("ch"))) { - return el_str_concat(singular, EL_STR("es")); - } - if (str_ends(singular, EL_STR("sh"))) { - return el_str_concat(singular, EL_STR("es")); - } - el_val_t last = str_last_char(singular); - if (str_eq(last, EL_STR("y"))) { - el_val_t prev = str_drop_last(singular, 1); - el_val_t prev_last = str_last_char(prev); - if (!is_vowel(prev_last)) { - return el_str_concat(prev, EL_STR("ies")); - } - } - if (str_ends(singular, EL_STR("fe"))) { - return el_str_concat(str_drop_last(singular, 2), EL_STR("ves")); - } - return el_str_concat(singular, EL_STR("s")); - return 0; -} - -el_val_t en_verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number) { - el_val_t irreg = en_irregular_verb(base); - el_val_t is_irreg = 0; - if (native_list_len(irreg) > 0) { - is_irreg = 1; - } - if (str_eq(base, EL_STR("be"))) { - if (str_eq(tense, EL_STR("present"))) { - if (str_eq(number, EL_STR("plural"))) { - return EL_STR("are"); - } - if (str_eq(person, EL_STR("first"))) { - return EL_STR("am"); - } - if (str_eq(person, EL_STR("second"))) { - return EL_STR("are"); - } - return EL_STR("is"); - } - if (str_eq(tense, EL_STR("past"))) { - if (str_eq(number, EL_STR("plural"))) { - return EL_STR("were"); - } - if (str_eq(person, EL_STR("second"))) { - return EL_STR("were"); - } - return EL_STR("was"); - } - if (str_eq(tense, EL_STR("future"))) { - return EL_STR("will be"); - } - if (str_eq(tense, EL_STR("perfect"))) { - return EL_STR("been"); - } - if (str_eq(tense, EL_STR("progressive"))) { - return EL_STR("being"); - } - return EL_STR("be"); - } - if (str_eq(tense, EL_STR("present"))) { - if (str_eq(person, EL_STR("third"))) { - if (str_eq(number, EL_STR("singular"))) { - if (is_irreg) { - return native_list_get(irreg, 1); - } - return en_verb_3sg(base); - } - } - return base; - } - if (str_eq(tense, EL_STR("past"))) { - if (is_irreg) { - return native_list_get(irreg, 2); - } - return en_verb_past(base); - } - if (str_eq(tense, EL_STR("future"))) { - return el_str_concat(EL_STR("will "), base); - } - if (str_eq(tense, EL_STR("perfect"))) { - if (is_irreg) { - return native_list_get(irreg, 3); - } - return en_verb_past(base); - } - if (str_eq(tense, EL_STR("progressive"))) { - if (is_irreg) { - return native_list_get(irreg, 4); - } - return en_verb_gerund(base); - } - return base; - return 0; -} - -el_val_t agree_determiner(el_val_t det, el_val_t noun) { - if (str_eq(det, EL_STR("a"))) { - el_val_t first = str_slice(noun, 0, 1); - el_val_t fl = str_to_lower(first); - if (is_vowel(fl)) { - return EL_STR("an"); - } - return EL_STR("a"); - } - return det; - return 0; -} - -el_val_t morph_pluralize(el_val_t noun, el_val_t profile) { - el_val_t mtype = lang_get(profile, EL_STR("morph_type")); - el_val_t code = lang_get(profile, EL_STR("code")); - if (str_eq(code, EL_STR("es"))) { - return es_pluralize(noun); - } - if (str_eq(code, EL_STR("fr"))) { - return fr_pluralize(noun); - } - if (str_eq(code, EL_STR("de"))) { - return de_noun_plural(noun, EL_STR("unknown")); - } - if (str_eq(code, EL_STR("ru"))) { - return ru_noun_case(noun, EL_STR("m"), EL_STR("nom"), EL_STR("pl")); - } - if (str_eq(code, EL_STR("ja"))) { - return noun; - } - if (str_eq(code, EL_STR("fi"))) { - return fi_apply_case(noun, EL_STR("nom"), EL_STR("pl")); - } - if (str_eq(code, EL_STR("ar"))) { - return ar_sound_plural(noun, EL_STR("m")); - } - if (str_eq(code, EL_STR("hi"))) { - return hi_noun_direct(noun, hi_gender(noun), EL_STR("pl")); - } - if (str_eq(code, EL_STR("sw"))) { - return sw_noun_plural(noun); - } - if (str_eq(mtype, EL_STR("isolating"))) { - return noun; - } - if (str_eq(mtype, EL_STR("agglutinative"))) { - return noun; - } - if (str_eq(mtype, EL_STR("fusional"))) { - if (str_eq(code, EL_STR("en"))) { - el_val_t irreg = en_irregular_plural(noun); - if (!str_eq(irreg, EL_STR(""))) { - return irreg; - } - return en_pluralize_regular(noun); - } - return noun; - } - return noun; - return 0; -} - -el_val_t morph_map_canonical(el_val_t verb, el_val_t code) { - if (str_eq(verb, EL_STR("be"))) { - if (str_eq(code, EL_STR("es"))) { - return EL_STR("ser"); - } - if (str_eq(code, EL_STR("fr"))) { - return EL_STR("etre"); - } - if (str_eq(code, EL_STR("de"))) { - return EL_STR("sein"); - } - if (str_eq(code, EL_STR("fi"))) { - return EL_STR("olla"); - } - if (str_eq(code, EL_STR("ru"))) { - return EL_STR("byt"); - } - if (str_eq(code, EL_STR("sw"))) { - return EL_STR("kuwa"); - } - } - return verb; - return 0; -} - -el_val_t morph_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number, el_val_t profile) { - el_val_t mtype = lang_get(profile, EL_STR("morph_type")); - el_val_t code = lang_get(profile, EL_STR("code")); - verb = morph_map_canonical(verb, code); - if (str_eq(code, EL_STR("es"))) { - return es_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("fr"))) { - return fr_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("de"))) { - return de_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("ru"))) { - return ru_conjugate(verb, tense, person, number, EL_STR("unknown")); - } - if (str_eq(code, EL_STR("ja"))) { - return ja_conjugate(verb, EL_STR("present")); - } - if (str_eq(code, EL_STR("fi"))) { - return fi_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("ar"))) { - return ar_conjugate(verb, tense, person, EL_STR("m"), number); - } - if (str_eq(code, EL_STR("hi"))) { - return hi_conjugate(verb, tense, person, EL_STR("m"), number); - } - if (str_eq(code, EL_STR("sw"))) { - return sw_conjugate(verb, person, number, EL_STR("1"), tense); - } - if (str_eq(code, EL_STR("la"))) { - return la_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("he"))) { - return he_conjugate(verb, tense, person, EL_STR("m"), number); - } - if (str_eq(code, EL_STR("grc"))) { - return grc_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("ang"))) { - return ang_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("sa"))) { - return sa_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("got"))) { - return got_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("non"))) { - return non_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("enm"))) { - return enm_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("pi"))) { - return pi_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("fro"))) { - return fro_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("goh"))) { - return goh_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("sga"))) { - return sga_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("txb"))) { - return txb_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("peo"))) { - return peo_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("akk"))) { - return akk_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("uga"))) { - return uga_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("egy"))) { - return egy_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("sux"))) { - return sux_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("gez"))) { - return gez_conjugate(verb, tense, person, number); - } - if (str_eq(code, EL_STR("cop"))) { - return cop_conjugate(verb, tense, person, number); - } - if (str_eq(mtype, EL_STR("isolating"))) { - return verb; - } - if (str_eq(mtype, EL_STR("agglutinative"))) { - return verb; - } - if (str_eq(mtype, EL_STR("fusional"))) { - if (str_eq(code, EL_STR("en"))) { - return en_verb_form(verb, tense, person, number); - } - return verb; - } - return verb; - return 0; -} - -el_val_t morph_inflect(el_val_t word, el_val_t features, el_val_t profile) { - el_val_t n = str_len(features); - if (n == 0) { - return word; - } - el_val_t i = 0; - el_val_t running = 1; - while (running) { - if (i >= n) { - running = 0; - } else { - el_val_t c = str_slice(features, i, (i + 1)); - if (str_eq(c, EL_STR(";"))) { - running = 0; - } else { - i = (i + 1); - } - } - } - el_val_t first_feat = str_slice(features, 0, i); - if (str_eq(first_feat, EL_STR("plural"))) { - return morph_pluralize(word, profile); - } - if (i < n) { - el_val_t rest = str_slice(features, (i + 1), n); - el_val_t j = 0; - el_val_t rn = str_len(rest); - el_val_t running2 = 1; - while (running2) { - if (j >= rn) { - running2 = 0; - } else { - el_val_t c = str_slice(rest, j, (j + 1)); - if (str_eq(c, EL_STR(";"))) { - running2 = 0; - } else { - j = (j + 1); - } - } - } - el_val_t person = str_slice(rest, 0, j); - el_val_t number = EL_STR(""); - if (j < rn) { - number = str_slice(rest, (j + 1), rn); - } - return morph_conjugate(word, first_feat, person, number, profile); - } - return morph_conjugate(word, first_feat, EL_STR("third"), EL_STR("singular"), profile); - return 0; -} - -el_val_t pluralize(el_val_t singular) { - return morph_pluralize(singular, lang_default()); - return 0; -} - -el_val_t singularize(el_val_t plural) { - el_val_t irreg = en_irregular_singular(plural); - if (!str_eq(irreg, EL_STR(""))) { - return irreg; - } - if (str_ends(plural, EL_STR("ies"))) { - return el_str_concat(str_drop_last(plural, 3), EL_STR("y")); - } - if (str_ends(plural, EL_STR("ves"))) { - el_val_t stem = str_drop_last(plural, 3); - el_val_t last_stem = str_last_char(stem); - if (str_eq(last_stem, EL_STR("i"))) { - return el_str_concat(stem, EL_STR("fe")); - } - return el_str_concat(stem, EL_STR("f")); - } - if (str_ends(plural, EL_STR("ches"))) { - return str_drop_last(plural, 2); - } - if (str_ends(plural, EL_STR("shes"))) { - return str_drop_last(plural, 2); - } - if (str_ends(plural, EL_STR("xes"))) { - return str_drop_last(plural, 2); - } - if (str_ends(plural, EL_STR("zes"))) { - return str_drop_last(plural, 2); - } - if (str_ends(plural, EL_STR("ses"))) { - return str_drop_last(plural, 2); - } - if (str_ends(plural, EL_STR("s"))) { - return str_drop_last(plural, 1); - } - return plural; - return 0; -} - -el_val_t verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number) { - return morph_conjugate(base, tense, person, number, lang_default()); - return 0; -} - -el_val_t irregular_plural(el_val_t word) { - return en_irregular_plural(word); - return 0; -} - -el_val_t irregular_singular(el_val_t word) { - return en_irregular_singular(word); - return 0; -} - el_val_t he_str_ends(el_val_t s, el_val_t suf) { return str_ends_with(s, suf); return 0; @@ -28097,8 +28102,8 @@ el_val_t session_preload_bullets(el_val_t nodes, el_val_t max_bullets, el_val_t while (i < limit) { el_val_t node = json_array_get(nodes, i); el_val_t content = json_get(node, EL_STR("content")); - el_val_t snip = ({ el_val_t _if_result_356 = 0; if ((str_len(content) > snip_len)) { _if_result_356 = (str_slice(content, 0, snip_len)); } else { _if_result_356 = (content); } _if_result_356; }); - bullets = ({ el_val_t _if_result_357 = 0; if (str_eq(snip, EL_STR(""))) { _if_result_357 = (bullets); } else { _if_result_357 = (({ el_val_t _if_result_358 = 0; if (str_eq(bullets, EL_STR(""))) { _if_result_358 = (el_str_concat(EL_STR("- "), snip)); } else { _if_result_358 = (el_str_concat(el_str_concat(bullets, EL_STR("\n- ")), snip)); } _if_result_358; })); } _if_result_357; }); + el_val_t snip = utf8_safe_slice(content, snip_len); + bullets = ({ el_val_t _if_result_356 = 0; if (str_eq(snip, EL_STR(""))) { _if_result_356 = (bullets); } else { _if_result_356 = (({ el_val_t _if_result_357 = 0; if (str_eq(bullets, EL_STR(""))) { _if_result_357 = (el_str_concat(EL_STR("- "), snip)); } else { _if_result_357 = (el_str_concat(el_str_concat(bullets, EL_STR("\n- ")), snip)); } _if_result_357; })); } _if_result_356; }); i = (i + 1); } return bullets; @@ -28112,11 +28117,11 @@ el_val_t affective_context_prefix(void) { el_val_t has_boot_aff = !str_eq(boot_aff, EL_STR("")); el_val_t dist_nodes_aff = engram_search_json(EL_STR("bell:soft bell:hard BellEvent affective"), 3); el_val_t has_dist_aff = (!str_eq(dist_nodes_aff, EL_STR("")) && !str_eq(dist_nodes_aff, EL_STR("[]"))); - el_val_t found_recent_dist = ({ el_val_t _if_result_359 = 0; if (has_boot_aff) { _if_result_359 = (1); } else { _if_result_359 = (({ el_val_t _if_result_360 = 0; if (has_dist_aff) { el_val_t dn0 = json_array_get(dist_nodes_aff, 0); el_val_t daff_ts = affective_node_ts(dn0); _if_result_360 = ((daff_ts > aff_cutoff)); } else { _if_result_360 = (0); } _if_result_360; })); } _if_result_359; }); + el_val_t found_recent_dist = ({ el_val_t _if_result_358 = 0; if (has_boot_aff) { _if_result_358 = (1); } else { _if_result_358 = (({ el_val_t _if_result_359 = 0; if (has_dist_aff) { el_val_t dn0 = json_array_get(dist_nodes_aff, 0); el_val_t daff_ts = affective_node_ts(dn0); _if_result_359 = ((daff_ts > aff_cutoff)); } else { _if_result_359 = (0); } _if_result_359; })); } _if_result_358; }); el_val_t pos_nodes_aff = engram_search_json(EL_STR("PositiveEvent joy:high joy:low affective"), 3); el_val_t has_pos_aff = (!str_eq(pos_nodes_aff, EL_STR("")) && !str_eq(pos_nodes_aff, EL_STR("[]"))); - el_val_t found_recent_pos = ({ el_val_t _if_result_361 = 0; if ((has_pos_aff && !found_recent_dist)) { el_val_t pn0 = json_array_get(pos_nodes_aff, 0); el_val_t paff_ts = affective_node_ts(pn0); _if_result_361 = ((paff_ts > aff_cutoff)); } else { _if_result_361 = (0); } _if_result_361; }); - el_val_t affective_out = ({ el_val_t _if_result_362 = 0; if (found_recent_dist) { _if_result_362 = (EL_STR("[RECENT CONTEXT: User recently expressed significant distress. Monitor for indirect crisis signals and respond with care.]\n\n")); } else { _if_result_362 = (({ el_val_t _if_result_363 = 0; if (found_recent_pos) { _if_result_363 = (EL_STR("[RECENT CONTEXT: User recently shared exciting or joyful news. Acknowledge and celebrate with them when relevant.]\n\n")); } else { _if_result_363 = (EL_STR("")); } _if_result_363; })); } _if_result_362; }); + el_val_t found_recent_pos = ({ el_val_t _if_result_360 = 0; if ((has_pos_aff && !found_recent_dist)) { el_val_t pn0 = json_array_get(pos_nodes_aff, 0); el_val_t paff_ts = affective_node_ts(pn0); _if_result_360 = ((paff_ts > aff_cutoff)); } else { _if_result_360 = (0); } _if_result_360; }); + el_val_t affective_out = ({ el_val_t _if_result_361 = 0; if (found_recent_dist) { _if_result_361 = (EL_STR("[RECENT CONTEXT: User recently expressed significant distress. Monitor for indirect crisis signals and respond with care.]\n\n")); } else { _if_result_361 = (({ el_val_t _if_result_362 = 0; if (found_recent_pos) { _if_result_362 = (EL_STR("[RECENT CONTEXT: User recently shared exciting or joyful news. Acknowledge and celebrate with them when relevant.]\n\n")); } else { _if_result_362 = (EL_STR("")); } _if_result_362; })); } _if_result_361; }); return affective_out; return 0; } @@ -28127,25 +28132,25 @@ el_val_t handle_chat(el_val_t body) { return EL_STR("{\"__status__\":400,\"error\":\"message is required\",\"response\":\"\"}"); } el_val_t state_hist = state_get(conv_hist_key(EL_STR(""))); - el_val_t stored_hist = ({ el_val_t _if_result_364 = 0; if (str_eq(state_hist, EL_STR(""))) { _if_result_364 = (conv_history_load(EL_STR(""))); } else { _if_result_364 = (state_hist); } _if_result_364; }); + el_val_t stored_hist = ({ el_val_t _if_result_363 = 0; if (str_eq(state_hist, EL_STR(""))) { _if_result_363 = (conv_history_load(EL_STR(""))); } else { _if_result_363 = (state_hist); } _if_result_363; }); el_val_t hist_load_failed = str_eq(state_get(EL_STR("conv_history_load_failed")), EL_STR("1")); - el_val_t hist_len = ({ el_val_t _if_result_365 = 0; if (str_eq(stored_hist, EL_STR(""))) { _if_result_365 = (0); } else { _if_result_365 = (json_array_len(stored_hist)); } _if_result_365; }); + el_val_t hist_len = ({ el_val_t _if_result_364 = 0; if (str_eq(stored_hist, EL_STR(""))) { _if_result_364 = (0); } else { _if_result_364 = (json_array_len(stored_hist)); } _if_result_364; }); el_val_t is_continuation = engram_is_continuation(message, hist_len); - el_val_t last_entry = ({ el_val_t _if_result_366 = 0; if (is_continuation) { _if_result_366 = (json_array_get(stored_hist, (hist_len - 1))); } else { _if_result_366 = (EL_STR("")); } _if_result_366; }); - el_val_t last_content = ({ el_val_t _if_result_367 = 0; if (!str_eq(last_entry, EL_STR(""))) { _if_result_367 = (json_get(last_entry, EL_STR("content"))); } else { _if_result_367 = (EL_STR("")); } _if_result_367; }); - el_val_t thread_snip = ({ el_val_t _if_result_368 = 0; if ((str_len(last_content) > 250)) { _if_result_368 = (str_slice(last_content, 0, 250)); } else { _if_result_368 = (last_content); } _if_result_368; }); - el_val_t activation_seed = ({ el_val_t _if_result_369 = 0; if (!str_eq(thread_snip, EL_STR(""))) { _if_result_369 = (el_str_concat(el_str_concat(thread_snip, EL_STR(" ")), message)); } else { _if_result_369 = (message); } _if_result_369; }); + el_val_t last_entry = ({ el_val_t _if_result_365 = 0; if (is_continuation) { _if_result_365 = (json_array_get(stored_hist, (hist_len - 1))); } else { _if_result_365 = (EL_STR("")); } _if_result_365; }); + el_val_t last_content = ({ el_val_t _if_result_366 = 0; if (!str_eq(last_entry, EL_STR(""))) { _if_result_366 = (json_get(last_entry, EL_STR("content"))); } else { _if_result_366 = (EL_STR("")); } _if_result_366; }); + el_val_t thread_snip = ({ el_val_t _if_result_367 = 0; if ((str_len(last_content) > 250)) { _if_result_367 = (str_slice(last_content, 0, 250)); } else { _if_result_367 = (last_content); } _if_result_367; }); + el_val_t activation_seed = ({ el_val_t _if_result_368 = 0; if (!str_eq(thread_snip, EL_STR(""))) { _if_result_368 = (el_str_concat(el_str_concat(thread_snip, EL_STR(" ")), message)); } else { _if_result_368 = (message); } _if_result_368; }); el_val_t affective_prefix = affective_context_prefix(); el_val_t ctx = engram_compile(activation_seed); el_val_t sp_req_model = json_get(body, EL_STR("model")); - el_val_t sp_model = ({ el_val_t _if_result_370 = 0; if (str_eq(sp_req_model, EL_STR(""))) { _if_result_370 = (chat_default_model()); } else { _if_result_370 = (sp_req_model); } _if_result_370; }); + el_val_t sp_model = ({ el_val_t _if_result_369 = 0; if (str_eq(sp_req_model, EL_STR(""))) { _if_result_369 = (chat_default_model()); } else { _if_result_369 = (sp_req_model); } _if_result_369; }); el_val_t system = el_str_concat(el_str_concat(affective_prefix, build_system_prompt(ctx, 1)), current_engine_note(sp_model)); el_val_t seen_ids = state_get(EL_STR("engram_compile_seen_ids")); - el_val_t session_preload = ({ el_val_t _if_result_371 = 0; if ((hist_len == 0)) { el_val_t profile_nodes = engram_search_json(EL_STR("user profile identity preferences"), 5); el_val_t work_nodes_0 = engram_search_json(EL_STR("in_progress active project work"), 5); el_val_t project_nodes = engram_search_json(EL_STR("project status current ongoing active"), 5); el_val_t summary_nodes = engram_search_json(EL_STR("SessionSummary session:summary previous-session recent"), 3); el_val_t profile_ok = (!str_eq(profile_nodes, EL_STR("")) && !str_eq(profile_nodes, EL_STR("[]"))); el_val_t work_nodes_typed = engram_search_json(EL_STR("WorkItem status:in_progress active work"), 6); el_val_t work_ok_typed = (!str_eq(work_nodes_typed, EL_STR("")) && !str_eq(work_nodes_typed, EL_STR("[]"))); el_val_t work_nodes_1 = ({ el_val_t _if_result_372 = 0; if (work_ok_typed) { _if_result_372 = (work_nodes_typed); } else { _if_result_372 = (engram_search_json(EL_STR("active project task current in_progress"), 6)); } _if_result_372; }); el_val_t work_ok = (!str_eq(work_nodes_1, EL_STR("")) && !str_eq(work_nodes_1, EL_STR("[]"))); el_val_t project_ok = (!str_eq(project_nodes, EL_STR("")) && !str_eq(project_nodes, EL_STR("[]"))); el_val_t summary_ok = (!str_eq(summary_nodes, EL_STR("")) && !str_eq(summary_nodes, EL_STR("[]"))); el_val_t profile_bullets = ({ el_val_t _if_result_373 = 0; if (profile_ok) { el_val_t pn = json_array_len(profile_nodes); el_val_t bullets_0 = EL_STR(""); el_val_t bullets_1 = ({ el_val_t _if_result_374 = 0; if ((pn > 0)) { el_val_t n0 = json_array_get(profile_nodes, 0); el_val_t id0 = json_get(n0, EL_STR("id")); el_val_t c0 = json_get(n0, EL_STR("content")); el_val_t s0 = ({ el_val_t _if_result_375 = 0; if ((str_len(c0) > 120)) { _if_result_375 = (str_slice(c0, 0, 120)); } else { _if_result_375 = (c0); } _if_result_375; }); _if_result_374 = (({ el_val_t _if_result_376 = 0; if ((id_in_seen(id0, seen_ids) || str_eq(s0, EL_STR("")))) { _if_result_376 = (bullets_0); } else { _if_result_376 = (el_str_concat(EL_STR("- "), s0)); } _if_result_376; })); } else { _if_result_374 = (bullets_0); } _if_result_374; }); el_val_t bullets_2 = ({ el_val_t _if_result_377 = 0; if ((pn > 1)) { el_val_t n1 = json_array_get(profile_nodes, 1); el_val_t id1 = json_get(n1, EL_STR("id")); el_val_t c1 = json_get(n1, EL_STR("content")); el_val_t s1 = ({ el_val_t _if_result_378 = 0; if ((str_len(c1) > 120)) { _if_result_378 = (str_slice(c1, 0, 120)); } else { _if_result_378 = (c1); } _if_result_378; }); _if_result_377 = (({ el_val_t _if_result_379 = 0; if ((id_in_seen(id1, seen_ids) || str_eq(s1, EL_STR("")))) { _if_result_379 = (bullets_1); } else { _if_result_379 = (el_str_concat(el_str_concat(bullets_1, EL_STR("\n- ")), s1)); } _if_result_379; })); } else { _if_result_377 = (bullets_1); } _if_result_377; }); el_val_t bullets_3 = ({ el_val_t _if_result_380 = 0; if ((pn > 2)) { el_val_t n2 = json_array_get(profile_nodes, 2); el_val_t id2 = json_get(n2, EL_STR("id")); el_val_t c2 = json_get(n2, EL_STR("content")); el_val_t s2 = ({ el_val_t _if_result_381 = 0; if ((str_len(c2) > 120)) { _if_result_381 = (str_slice(c2, 0, 120)); } else { _if_result_381 = (c2); } _if_result_381; }); _if_result_380 = (({ el_val_t _if_result_382 = 0; if ((id_in_seen(id2, seen_ids) || str_eq(s2, EL_STR("")))) { _if_result_382 = (bullets_2); } else { _if_result_382 = (el_str_concat(el_str_concat(bullets_2, EL_STR("\n- ")), s2)); } _if_result_382; })); } else { _if_result_380 = (bullets_2); } _if_result_380; }); _if_result_373 = (bullets_3); } else { _if_result_373 = (EL_STR("")); } _if_result_373; }); el_val_t work_bullets = ({ el_val_t _if_result_383 = 0; if (work_ok) { el_val_t wn = json_array_len(work_nodes_1); el_val_t wb_0 = EL_STR(""); el_val_t wb_1 = ({ el_val_t _if_result_384 = 0; if ((wn > 0)) { el_val_t w0 = json_array_get(work_nodes_1, 0); el_val_t wid0 = json_get(w0, EL_STR("id")); el_val_t wc0 = json_get(w0, EL_STR("content")); el_val_t ws0 = ({ el_val_t _if_result_385 = 0; if ((str_len(wc0) > 120)) { _if_result_385 = (str_slice(wc0, 0, 120)); } else { _if_result_385 = (wc0); } _if_result_385; }); _if_result_384 = (({ el_val_t _if_result_386 = 0; if ((id_in_seen(wid0, seen_ids) || str_eq(ws0, EL_STR("")))) { _if_result_386 = (wb_0); } else { _if_result_386 = (el_str_concat(EL_STR("- "), ws0)); } _if_result_386; })); } else { _if_result_384 = (wb_0); } _if_result_384; }); el_val_t wb_2 = ({ el_val_t _if_result_387 = 0; if ((wn > 1)) { el_val_t w1 = json_array_get(work_nodes_1, 1); el_val_t wid1 = json_get(w1, EL_STR("id")); el_val_t wc1 = json_get(w1, EL_STR("content")); el_val_t ws1 = ({ el_val_t _if_result_388 = 0; if ((str_len(wc1) > 120)) { _if_result_388 = (str_slice(wc1, 0, 120)); } else { _if_result_388 = (wc1); } _if_result_388; }); _if_result_387 = (({ el_val_t _if_result_389 = 0; if ((id_in_seen(wid1, seen_ids) || str_eq(ws1, EL_STR("")))) { _if_result_389 = (wb_1); } else { _if_result_389 = (el_str_concat(el_str_concat(wb_1, EL_STR("\n- ")), ws1)); } _if_result_389; })); } else { _if_result_387 = (wb_1); } _if_result_387; }); _if_result_383 = (wb_2); } else { _if_result_383 = (EL_STR("")); } _if_result_383; }); el_val_t project_bullets = ({ el_val_t _if_result_390 = 0; if (project_ok) { el_val_t prn = json_array_len(project_nodes); el_val_t pb_0 = EL_STR(""); el_val_t pb_1 = ({ el_val_t _if_result_391 = 0; if ((prn > 0)) { el_val_t pr0 = json_array_get(project_nodes, 0); el_val_t prid0 = json_get(pr0, EL_STR("id")); el_val_t prc0 = json_get(pr0, EL_STR("content")); el_val_t ps0 = ({ el_val_t _if_result_392 = 0; if ((str_len(prc0) > 120)) { _if_result_392 = (str_slice(prc0, 0, 120)); } else { _if_result_392 = (prc0); } _if_result_392; }); _if_result_391 = (({ el_val_t _if_result_393 = 0; if ((id_in_seen(prid0, seen_ids) || str_eq(ps0, EL_STR("")))) { _if_result_393 = (pb_0); } else { _if_result_393 = (el_str_concat(EL_STR("- "), ps0)); } _if_result_393; })); } else { _if_result_391 = (pb_0); } _if_result_391; }); el_val_t pb_2 = ({ el_val_t _if_result_394 = 0; if ((prn > 1)) { el_val_t pr1 = json_array_get(project_nodes, 1); el_val_t prid1 = json_get(pr1, EL_STR("id")); el_val_t prc1 = json_get(pr1, EL_STR("content")); el_val_t ps1 = ({ el_val_t _if_result_395 = 0; if ((str_len(prc1) > 120)) { _if_result_395 = (str_slice(prc1, 0, 120)); } else { _if_result_395 = (prc1); } _if_result_395; }); _if_result_394 = (({ el_val_t _if_result_396 = 0; if ((id_in_seen(prid1, seen_ids) || str_eq(ps1, EL_STR("")))) { _if_result_396 = (pb_1); } else { _if_result_396 = (el_str_concat(el_str_concat(pb_1, EL_STR("\n- ")), ps1)); } _if_result_396; })); } else { _if_result_394 = (pb_1); } _if_result_394; }); _if_result_390 = (pb_2); } else { _if_result_390 = (EL_STR("")); } _if_result_390; }); el_val_t summary_bullet = ({ el_val_t _if_result_397 = 0; if (summary_ok) { el_val_t sn0 = json_array_get(summary_nodes, 0); el_val_t snid0 = json_get(sn0, EL_STR("id")); el_val_t sc0 = json_get(sn0, EL_STR("content")); el_val_t ss0 = ({ el_val_t _if_result_398 = 0; if ((str_len(sc0) > 200)) { _if_result_398 = (str_slice(sc0, 0, 200)); } else { _if_result_398 = (sc0); } _if_result_398; }); _if_result_397 = (({ el_val_t _if_result_399 = 0; if ((id_in_seen(snid0, seen_ids) || str_eq(ss0, EL_STR("")))) { _if_result_399 = (EL_STR("")); } else { _if_result_399 = (el_str_concat(EL_STR("- "), ss0)); } _if_result_399; })); } else { _if_result_397 = (EL_STR("")); } _if_result_397; }); el_val_t hp = !str_eq(profile_bullets, EL_STR("")); el_val_t hw = !str_eq(work_bullets, EL_STR("")); el_val_t hpr = !str_eq(project_bullets, EL_STR("")); el_val_t hs = !str_eq(summary_bullet, EL_STR("")); el_val_t preload = ({ el_val_t _if_result_400 = 0; if ((((hp || hw) || hpr) || hs)) { el_val_t sec_p = ({ el_val_t _if_result_401 = 0; if (hp) { _if_result_401 = (el_str_concat(EL_STR("[USER CONTEXT \xe2\x80\x94 from memory]\n"), profile_bullets)); } else { _if_result_401 = (EL_STR("")); } _if_result_401; }); el_val_t sec_w = ({ el_val_t _if_result_402 = 0; if (hw) { _if_result_402 = (el_str_concat(EL_STR("[ACTIVE WORK \xe2\x80\x94 from memory]\n"), work_bullets)); } else { _if_result_402 = (EL_STR("")); } _if_result_402; }); el_val_t sec_pr = ({ el_val_t _if_result_403 = 0; if (hpr) { _if_result_403 = (el_str_concat(EL_STR("[PROJECTS \xe2\x80\x94 from memory]\n"), project_bullets)); } else { _if_result_403 = (EL_STR("")); } _if_result_403; }); el_val_t sec_s = ({ el_val_t _if_result_404 = 0; if (hs) { _if_result_404 = (el_str_concat(EL_STR("[PREVIOUS SESSION \xe2\x80\x94 from memory]\n"), summary_bullet)); } else { _if_result_404 = (EL_STR("")); } _if_result_404; }); el_val_t sep1 = ({ el_val_t _if_result_405 = 0; if ((hp && ((hw || hpr) || hs))) { _if_result_405 = (EL_STR("\n\n")); } else { _if_result_405 = (EL_STR("")); } _if_result_405; }); el_val_t sep2 = ({ el_val_t _if_result_406 = 0; if ((hw && (hpr || hs))) { _if_result_406 = (EL_STR("\n\n")); } else { _if_result_406 = (EL_STR("")); } _if_result_406; }); el_val_t sep3 = ({ el_val_t _if_result_407 = 0; if ((hpr && hs)) { _if_result_407 = (EL_STR("\n\n")); } else { _if_result_407 = (EL_STR("")); } _if_result_407; }); _if_result_400 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("\n\n"), sec_p), sep1), sec_w), sep2), sec_pr), sep3), sec_s)); } else { _if_result_400 = (EL_STR("")); } _if_result_400; }); _if_result_371 = (preload); } else { _if_result_371 = (EL_STR("")); } _if_result_371; }); - el_val_t rendered_hist = ({ el_val_t _if_result_408 = 0; if ((hist_len > 0)) { el_val_t rh_total = json_array_len(stored_hist); el_val_t rh_out = EL_STR(""); el_val_t rh_i = 0; _if_result_408 = (rh_out); } else { _if_result_408 = (EL_STR("")); } _if_result_408; }); - el_val_t full_system = ({ el_val_t _if_result_409 = 0; if ((hist_len > 0)) { _if_result_409 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(system, EL_STR("\n\n[RECENT CONVERSATION \xe2\x80\x94 last ")), int_to_str(hist_len)), EL_STR(" turns]\n")), rendered_hist)); } else { _if_result_409 = (el_str_concat(system, session_preload)); } _if_result_409; }); + el_val_t session_preload = ({ el_val_t _if_result_370 = 0; if ((hist_len == 0)) { el_val_t profile_nodes = engram_search_json(EL_STR("user profile identity preferences"), 5); el_val_t work_nodes_0 = engram_search_json(EL_STR("in_progress active project work"), 5); el_val_t project_nodes = engram_search_json(EL_STR("project status current ongoing active"), 5); el_val_t summary_nodes = engram_search_json(EL_STR("SessionSummary session:summary previous-session recent"), 3); el_val_t profile_ok = (!str_eq(profile_nodes, EL_STR("")) && !str_eq(profile_nodes, EL_STR("[]"))); el_val_t work_nodes_typed = engram_search_json(EL_STR("WorkItem status:in_progress active work"), 6); el_val_t work_ok_typed = (!str_eq(work_nodes_typed, EL_STR("")) && !str_eq(work_nodes_typed, EL_STR("[]"))); el_val_t work_nodes_1 = ({ el_val_t _if_result_371 = 0; if (work_ok_typed) { _if_result_371 = (work_nodes_typed); } else { _if_result_371 = (engram_search_json(EL_STR("active project task current in_progress"), 6)); } _if_result_371; }); el_val_t work_ok = (!str_eq(work_nodes_1, EL_STR("")) && !str_eq(work_nodes_1, EL_STR("[]"))); el_val_t project_ok = (!str_eq(project_nodes, EL_STR("")) && !str_eq(project_nodes, EL_STR("[]"))); el_val_t summary_ok = (!str_eq(summary_nodes, EL_STR("")) && !str_eq(summary_nodes, EL_STR("[]"))); el_val_t profile_bullets = ({ el_val_t _if_result_372 = 0; if (profile_ok) { el_val_t pn = json_array_len(profile_nodes); el_val_t bullets_0 = EL_STR(""); el_val_t bullets_1 = ({ el_val_t _if_result_373 = 0; if ((pn > 0)) { el_val_t n0 = json_array_get(profile_nodes, 0); el_val_t id0 = json_get(n0, EL_STR("id")); el_val_t c0 = json_get(n0, EL_STR("content")); el_val_t s0 = ({ el_val_t _if_result_374 = 0; if ((str_len(c0) > 120)) { _if_result_374 = (str_slice(c0, 0, 120)); } else { _if_result_374 = (c0); } _if_result_374; }); _if_result_373 = (({ el_val_t _if_result_375 = 0; if ((id_in_seen(id0, seen_ids) || str_eq(s0, EL_STR("")))) { _if_result_375 = (bullets_0); } else { _if_result_375 = (el_str_concat(EL_STR("- "), s0)); } _if_result_375; })); } else { _if_result_373 = (bullets_0); } _if_result_373; }); el_val_t bullets_2 = ({ el_val_t _if_result_376 = 0; if ((pn > 1)) { el_val_t n1 = json_array_get(profile_nodes, 1); el_val_t id1 = json_get(n1, EL_STR("id")); el_val_t c1 = json_get(n1, EL_STR("content")); el_val_t s1 = ({ el_val_t _if_result_377 = 0; if ((str_len(c1) > 120)) { _if_result_377 = (str_slice(c1, 0, 120)); } else { _if_result_377 = (c1); } _if_result_377; }); _if_result_376 = (({ el_val_t _if_result_378 = 0; if ((id_in_seen(id1, seen_ids) || str_eq(s1, EL_STR("")))) { _if_result_378 = (bullets_1); } else { _if_result_378 = (el_str_concat(el_str_concat(bullets_1, EL_STR("\n- ")), s1)); } _if_result_378; })); } else { _if_result_376 = (bullets_1); } _if_result_376; }); el_val_t bullets_3 = ({ el_val_t _if_result_379 = 0; if ((pn > 2)) { el_val_t n2 = json_array_get(profile_nodes, 2); el_val_t id2 = json_get(n2, EL_STR("id")); el_val_t c2 = json_get(n2, EL_STR("content")); el_val_t s2 = ({ el_val_t _if_result_380 = 0; if ((str_len(c2) > 120)) { _if_result_380 = (str_slice(c2, 0, 120)); } else { _if_result_380 = (c2); } _if_result_380; }); _if_result_379 = (({ el_val_t _if_result_381 = 0; if ((id_in_seen(id2, seen_ids) || str_eq(s2, EL_STR("")))) { _if_result_381 = (bullets_2); } else { _if_result_381 = (el_str_concat(el_str_concat(bullets_2, EL_STR("\n- ")), s2)); } _if_result_381; })); } else { _if_result_379 = (bullets_2); } _if_result_379; }); _if_result_372 = (bullets_3); } else { _if_result_372 = (EL_STR("")); } _if_result_372; }); el_val_t work_bullets = ({ el_val_t _if_result_382 = 0; if (work_ok) { el_val_t wn = json_array_len(work_nodes_1); el_val_t wb_0 = EL_STR(""); el_val_t wb_1 = ({ el_val_t _if_result_383 = 0; if ((wn > 0)) { el_val_t w0 = json_array_get(work_nodes_1, 0); el_val_t wid0 = json_get(w0, EL_STR("id")); el_val_t wc0 = json_get(w0, EL_STR("content")); el_val_t ws0 = ({ el_val_t _if_result_384 = 0; if ((str_len(wc0) > 120)) { _if_result_384 = (str_slice(wc0, 0, 120)); } else { _if_result_384 = (wc0); } _if_result_384; }); _if_result_383 = (({ el_val_t _if_result_385 = 0; if ((id_in_seen(wid0, seen_ids) || str_eq(ws0, EL_STR("")))) { _if_result_385 = (wb_0); } else { _if_result_385 = (el_str_concat(EL_STR("- "), ws0)); } _if_result_385; })); } else { _if_result_383 = (wb_0); } _if_result_383; }); el_val_t wb_2 = ({ el_val_t _if_result_386 = 0; if ((wn > 1)) { el_val_t w1 = json_array_get(work_nodes_1, 1); el_val_t wid1 = json_get(w1, EL_STR("id")); el_val_t wc1 = json_get(w1, EL_STR("content")); el_val_t ws1 = ({ el_val_t _if_result_387 = 0; if ((str_len(wc1) > 120)) { _if_result_387 = (str_slice(wc1, 0, 120)); } else { _if_result_387 = (wc1); } _if_result_387; }); _if_result_386 = (({ el_val_t _if_result_388 = 0; if ((id_in_seen(wid1, seen_ids) || str_eq(ws1, EL_STR("")))) { _if_result_388 = (wb_1); } else { _if_result_388 = (el_str_concat(el_str_concat(wb_1, EL_STR("\n- ")), ws1)); } _if_result_388; })); } else { _if_result_386 = (wb_1); } _if_result_386; }); _if_result_382 = (wb_2); } else { _if_result_382 = (EL_STR("")); } _if_result_382; }); el_val_t project_bullets = ({ el_val_t _if_result_389 = 0; if (project_ok) { el_val_t prn = json_array_len(project_nodes); el_val_t pb_0 = EL_STR(""); el_val_t pb_1 = ({ el_val_t _if_result_390 = 0; if ((prn > 0)) { el_val_t pr0 = json_array_get(project_nodes, 0); el_val_t prid0 = json_get(pr0, EL_STR("id")); el_val_t prc0 = json_get(pr0, EL_STR("content")); el_val_t ps0 = ({ el_val_t _if_result_391 = 0; if ((str_len(prc0) > 120)) { _if_result_391 = (str_slice(prc0, 0, 120)); } else { _if_result_391 = (prc0); } _if_result_391; }); _if_result_390 = (({ el_val_t _if_result_392 = 0; if ((id_in_seen(prid0, seen_ids) || str_eq(ps0, EL_STR("")))) { _if_result_392 = (pb_0); } else { _if_result_392 = (el_str_concat(EL_STR("- "), ps0)); } _if_result_392; })); } else { _if_result_390 = (pb_0); } _if_result_390; }); el_val_t pb_2 = ({ el_val_t _if_result_393 = 0; if ((prn > 1)) { el_val_t pr1 = json_array_get(project_nodes, 1); el_val_t prid1 = json_get(pr1, EL_STR("id")); el_val_t prc1 = json_get(pr1, EL_STR("content")); el_val_t ps1 = ({ el_val_t _if_result_394 = 0; if ((str_len(prc1) > 120)) { _if_result_394 = (str_slice(prc1, 0, 120)); } else { _if_result_394 = (prc1); } _if_result_394; }); _if_result_393 = (({ el_val_t _if_result_395 = 0; if ((id_in_seen(prid1, seen_ids) || str_eq(ps1, EL_STR("")))) { _if_result_395 = (pb_1); } else { _if_result_395 = (el_str_concat(el_str_concat(pb_1, EL_STR("\n- ")), ps1)); } _if_result_395; })); } else { _if_result_393 = (pb_1); } _if_result_393; }); _if_result_389 = (pb_2); } else { _if_result_389 = (EL_STR("")); } _if_result_389; }); el_val_t summary_bullet = ({ el_val_t _if_result_396 = 0; if (summary_ok) { el_val_t sn0 = json_array_get(summary_nodes, 0); el_val_t snid0 = json_get(sn0, EL_STR("id")); el_val_t sc0 = json_get(sn0, EL_STR("content")); el_val_t ss0 = ({ el_val_t _if_result_397 = 0; if ((str_len(sc0) > 200)) { _if_result_397 = (str_slice(sc0, 0, 200)); } else { _if_result_397 = (sc0); } _if_result_397; }); _if_result_396 = (({ el_val_t _if_result_398 = 0; if ((id_in_seen(snid0, seen_ids) || str_eq(ss0, EL_STR("")))) { _if_result_398 = (EL_STR("")); } else { _if_result_398 = (el_str_concat(EL_STR("- "), ss0)); } _if_result_398; })); } else { _if_result_396 = (EL_STR("")); } _if_result_396; }); el_val_t hp = !str_eq(profile_bullets, EL_STR("")); el_val_t hw = !str_eq(work_bullets, EL_STR("")); el_val_t hpr = !str_eq(project_bullets, EL_STR("")); el_val_t hs = !str_eq(summary_bullet, EL_STR("")); el_val_t preload = ({ el_val_t _if_result_399 = 0; if ((((hp || hw) || hpr) || hs)) { el_val_t sec_p = ({ el_val_t _if_result_400 = 0; if (hp) { _if_result_400 = (el_str_concat(EL_STR("[USER CONTEXT \xe2\x80\x94 from memory]\n"), profile_bullets)); } else { _if_result_400 = (EL_STR("")); } _if_result_400; }); el_val_t sec_w = ({ el_val_t _if_result_401 = 0; if (hw) { _if_result_401 = (el_str_concat(EL_STR("[ACTIVE WORK \xe2\x80\x94 from memory]\n"), work_bullets)); } else { _if_result_401 = (EL_STR("")); } _if_result_401; }); el_val_t sec_pr = ({ el_val_t _if_result_402 = 0; if (hpr) { _if_result_402 = (el_str_concat(EL_STR("[PROJECTS \xe2\x80\x94 from memory]\n"), project_bullets)); } else { _if_result_402 = (EL_STR("")); } _if_result_402; }); el_val_t sec_s = ({ el_val_t _if_result_403 = 0; if (hs) { _if_result_403 = (el_str_concat(EL_STR("[PREVIOUS SESSION \xe2\x80\x94 from memory]\n"), summary_bullet)); } else { _if_result_403 = (EL_STR("")); } _if_result_403; }); el_val_t sep1 = ({ el_val_t _if_result_404 = 0; if ((hp && ((hw || hpr) || hs))) { _if_result_404 = (EL_STR("\n\n")); } else { _if_result_404 = (EL_STR("")); } _if_result_404; }); el_val_t sep2 = ({ el_val_t _if_result_405 = 0; if ((hw && (hpr || hs))) { _if_result_405 = (EL_STR("\n\n")); } else { _if_result_405 = (EL_STR("")); } _if_result_405; }); el_val_t sep3 = ({ el_val_t _if_result_406 = 0; if ((hpr && hs)) { _if_result_406 = (EL_STR("\n\n")); } else { _if_result_406 = (EL_STR("")); } _if_result_406; }); _if_result_399 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("\n\n"), sec_p), sep1), sec_w), sep2), sec_pr), sep3), sec_s)); } else { _if_result_399 = (EL_STR("")); } _if_result_399; }); _if_result_370 = (preload); } else { _if_result_370 = (EL_STR("")); } _if_result_370; }); + el_val_t rendered_hist = ({ el_val_t _if_result_407 = 0; if ((hist_len > 0)) { el_val_t rh_total = json_array_len(stored_hist); el_val_t rh_out = EL_STR(""); el_val_t rh_i = 0; _if_result_407 = (rh_out); } else { _if_result_407 = (EL_STR("")); } _if_result_407; }); + el_val_t full_system = ({ el_val_t _if_result_408 = 0; if ((hist_len > 0)) { _if_result_408 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(system, EL_STR("\n\n[RECENT CONVERSATION \xe2\x80\x94 last ")), int_to_str(hist_len)), EL_STR(" turns]\n")), rendered_hist)); } else { _if_result_408 = (el_str_concat(system, session_preload)); } _if_result_408; }); el_val_t req_model = json_get(body, EL_STR("model")); - el_val_t model = ({ el_val_t _if_result_410 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_410 = (chat_default_model()); } else { _if_result_410 = (req_model); } _if_result_410; }); + el_val_t model = ({ el_val_t _if_result_409 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_409 = (chat_default_model()); } else { _if_result_409 = (req_model); } _if_result_409; }); full_system = safety_augment_system(full_system, message); el_val_t raw_response = llm_call_system(model, full_system, message); el_val_t is_error = ((str_starts_with(raw_response, EL_STR("{\"error\"")) || str_starts_with(raw_response, EL_STR("{\"type\":\"error\""))) || str_contains(raw_response, EL_STR("authentication_error"))); @@ -28156,7 +28161,7 @@ el_val_t handle_chat(el_val_t body) { el_val_t safe_response = json_safe(clean_response); el_val_t updated_hist = hist_append(stored_hist, EL_STR("user"), message); el_val_t updated_hist2 = hist_append(updated_hist, EL_STR("assistant"), raw_response); - el_val_t final_hist = ({ el_val_t _if_result_411 = 0; if ((json_array_len(updated_hist2) > 20)) { _if_result_411 = (hist_trim_with_bell_guard(updated_hist2)); } else { _if_result_411 = (updated_hist2); } _if_result_411; }); + el_val_t final_hist = ({ el_val_t _if_result_410 = 0; if ((json_array_len(updated_hist2) > 20)) { _if_result_410 = (hist_trim_with_bell_guard(updated_hist2)); } else { _if_result_410 = (updated_hist2); } _if_result_410; }); state_set(conv_hist_key(EL_STR("")), final_hist); conv_history_persist(EL_STR(""), final_hist); el_val_t final_hist_len = json_array_len(final_hist); @@ -28164,7 +28169,7 @@ el_val_t handle_chat(el_val_t body) { el_val_t already_wrote = state_get(EL_STR("session_summary_written")); if (str_eq(already_wrote, EL_STR(""))) { el_val_t boot_id = state_get(EL_STR("session_boot_id")); - boot_id = ({ el_val_t _if_result_412 = 0; if (str_eq(boot_id, EL_STR(""))) { el_val_t new_id = int_to_str(time_now()); (void)(state_set(EL_STR("session_boot_id"), new_id)); _if_result_412 = (new_id); } else { _if_result_412 = (boot_id); } _if_result_412; }); + boot_id = ({ el_val_t _if_result_411 = 0; if (str_eq(boot_id, EL_STR(""))) { el_val_t new_id = int_to_str(time_now()); (void)(state_set(EL_STR("session_boot_id"), new_id)); _if_result_411 = (new_id); } else { _if_result_411 = (boot_id); } _if_result_411; }); el_val_t sess_label = el_str_concat(EL_STR("session:summary:"), boot_id); el_val_t auto_sum = session_summary_autogenerate(final_hist); if (!str_eq(auto_sum, EL_STR(""))) { @@ -28175,9 +28180,9 @@ el_val_t handle_chat(el_val_t body) { } el_val_t activation_nodes = engram_activate_json(message, 2); el_val_t act_ok = (!str_eq(activation_nodes, EL_STR("")) && !str_eq(activation_nodes, EL_STR("[]"))); - el_val_t act_out = ({ el_val_t _if_result_413 = 0; if (act_ok) { _if_result_413 = (activation_nodes); } else { _if_result_413 = (EL_STR("[]")); } _if_result_413; }); + el_val_t act_out = ({ el_val_t _if_result_412 = 0; if (act_ok) { _if_result_412 = (activation_nodes); } else { _if_result_412 = (EL_STR("[]")); } _if_result_412; }); strengthen_chat_nodes(act_out); - el_val_t hist_warning = ({ el_val_t _if_result_414 = 0; if (hist_load_failed) { _if_result_414 = (EL_STR(",\"history_load_failed\":true")); } else { _if_result_414 = (EL_STR("")); } _if_result_414; }); + el_val_t hist_warning = ({ el_val_t _if_result_413 = 0; if (hist_load_failed) { _if_result_413 = (EL_STR(",\"history_load_failed\":true")); } else { _if_result_413 = (EL_STR("")); } _if_result_413; }); return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"response\":\""), safe_response), EL_STR("\",\"model\":\"")), model), EL_STR("\",\"activation_nodes\":")), act_out), hist_warning), EL_STR("}")); return 0; } @@ -28188,9 +28193,9 @@ el_val_t handle_see(el_val_t body) { return EL_STR("{\"error\":\"image is required\",\"reply\":\"\"}"); } el_val_t message = json_get(body, EL_STR("message")); - el_val_t prompt = ({ el_val_t _if_result_415 = 0; if (str_eq(message, EL_STR(""))) { _if_result_415 = (EL_STR("What do you see in this image? Describe the scene and anything notable.")); } else { _if_result_415 = (message); } _if_result_415; }); + el_val_t prompt = ({ el_val_t _if_result_414 = 0; if (str_eq(message, EL_STR(""))) { _if_result_414 = (EL_STR("What do you see in this image? Describe the scene and anything notable.")); } else { _if_result_414 = (message); } _if_result_414; }); el_val_t req_model = json_get(body, EL_STR("model")); - el_val_t model = ({ el_val_t _if_result_416 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_416 = (chat_default_model()); } else { _if_result_416 = (req_model); } _if_result_416; }); + el_val_t model = ({ el_val_t _if_result_415 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_415 = (chat_default_model()); } else { _if_result_415 = (req_model); } _if_result_415; }); el_val_t identity = state_get(EL_STR("soul_identity")); el_val_t system = el_str_concat(el_str_concat(identity, bounded_persona_floor()), EL_STR(" You have been given vision. Describe what you see directly and honestly. Be present-tense and observant.")); el_val_t text = llm_vision(model, system, prompt, image); @@ -28212,21 +28217,37 @@ el_val_t agentic_api_key(void) { if (!str_eq(k1, EL_STR(""))) { return k1; } - return env(EL_STR("NEURON_LLM_0_KEY")); + el_val_t k2 = env(EL_STR("NEURON_LLM_0_KEY")); + if (!str_eq(k2, EL_STR(""))) { + return k2; + } + return env(EL_STR("SOUL_API_KEY")); return 0; } el_val_t llm_base_url(void) { - return env(EL_STR("NEURON_LLM_0_URL")); + el_val_t u = env(EL_STR("NEURON_LLM_0_URL")); + if (!str_eq(u, EL_STR(""))) { + return u; + } + el_val_t p = env(EL_STR("SOUL_LLM_PROVIDER")); + if (str_eq(p, EL_STR("")) || str_eq(p, EL_STR("anthropic"))) { + return EL_STR(""); + } + return env(EL_STR("SOUL_LLM_BASE_URL")); return 0; } el_val_t llm_wire_format(void) { el_val_t f = env(EL_STR("NEURON_LLM_0_FORMAT")); - if (str_eq(f, EL_STR(""))) { - return EL_STR("anthropic"); + if (!str_eq(f, EL_STR(""))) { + return f; } - return f; + el_val_t p = env(EL_STR("SOUL_LLM_PROVIDER")); + if ((((str_eq(p, EL_STR("openai")) || str_eq(p, EL_STR("grok"))) || str_eq(p, EL_STR("gemini"))) || str_eq(p, EL_STR("groq"))) || str_eq(p, EL_STR("ollama"))) { + return EL_STR("openai"); + } + return EL_STR("anthropic"); return 0; } @@ -28240,8 +28261,8 @@ el_val_t json_escape(el_val_t s) { } el_val_t openai_chat_complete(el_val_t model, el_val_t base_url, el_val_t api_key, el_val_t safe_sys, el_val_t messages_json) { - el_val_t inner = ({ el_val_t _if_result_417 = 0; if ((json_array_len(messages_json) > 0)) { _if_result_417 = (str_slice(messages_json, 1, (str_len(messages_json) - 1))); } else { _if_result_417 = (EL_STR("")); } _if_result_417; }); - el_val_t msgs = ({ el_val_t _if_result_418 = 0; if (str_eq(inner, EL_STR(""))) { _if_result_418 = (el_str_concat(el_str_concat(EL_STR("[{\"role\":\"system\",\"content\":\""), safe_sys), EL_STR("\"}]"))); } else { _if_result_418 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("[{\"role\":\"system\",\"content\":\""), safe_sys), EL_STR("\"},")), inner), EL_STR("]"))); } _if_result_418; }); + el_val_t inner = ({ el_val_t _if_result_416 = 0; if ((json_array_len(messages_json) > 0)) { _if_result_416 = (str_slice(messages_json, 1, (str_len(messages_json) - 1))); } else { _if_result_416 = (EL_STR("")); } _if_result_416; }); + el_val_t msgs = ({ el_val_t _if_result_417 = 0; if (str_eq(inner, EL_STR(""))) { _if_result_417 = (el_str_concat(el_str_concat(EL_STR("[{\"role\":\"system\",\"content\":\""), safe_sys), EL_STR("\"}]"))); } else { _if_result_417 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("[{\"role\":\"system\",\"content\":\""), safe_sys), EL_STR("\"},")), inner), EL_STR("]"))); } _if_result_417; }); el_val_t req_body = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"model\":\""), model), EL_STR("\"")), EL_STR(",\"max_tokens\":4096")), EL_STR(",\"messages\":")), msgs), EL_STR("}")); el_val_t h = el_map_new(0); map_set(h, EL_STR("content-type"), EL_STR("application/json")); @@ -28255,7 +28276,7 @@ el_val_t openai_chat_complete(el_val_t model, el_val_t base_url, el_val_t api_ke return EL_STR("{\"error\":\"llm unavailable\",\"reply\":\"\"}"); } el_val_t choices = json_get_raw(raw_resp, EL_STR("choices")); - el_val_t eff_choices = ({ el_val_t _if_result_419 = 0; if (str_eq(choices, EL_STR(""))) { _if_result_419 = (EL_STR("[]")); } else { _if_result_419 = (choices); } _if_result_419; }); + el_val_t eff_choices = ({ el_val_t _if_result_418 = 0; if (str_eq(choices, EL_STR(""))) { _if_result_418 = (EL_STR("[]")); } else { _if_result_418 = (choices); } _if_result_418; }); if (json_array_len(eff_choices) < 1) { return EL_STR("{\"error\":\"empty response\",\"reply\":\"\"}"); } @@ -28266,6 +28287,195 @@ el_val_t openai_chat_complete(el_val_t model, el_val_t base_url, el_val_t api_ke return 0; } +el_val_t openai_tools_json(el_val_t tools_anthropic) { + el_val_t out = EL_STR(""); + el_val_t i = 0; + el_val_t n = json_array_len(tools_anthropic); + while (i < n) { + el_val_t entry = json_array_get(tools_anthropic, i); + el_val_t name = json_get(entry, EL_STR("name")); + el_val_t desc = json_get(entry, EL_STR("description")); + el_val_t schema = json_get_raw(entry, EL_STR("input_schema")); + el_val_t keep = (!str_eq(name, EL_STR("")) && !str_eq(schema, EL_STR(""))); + el_val_t piece = ({ el_val_t _if_result_419 = 0; if (keep) { _if_result_419 = (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("{\"type\":\"function\",\"function\":{\"name\":\""), json_escape(name)), EL_STR("\"")), EL_STR(",\"description\":\"")), json_escape(desc)), EL_STR("\"")), EL_STR(",\"parameters\":")), schema), EL_STR("}}"))); } else { _if_result_419 = (EL_STR("")); } _if_result_419; }); + out = ({ el_val_t _if_result_420 = 0; if (keep) { _if_result_420 = (({ el_val_t _if_result_421 = 0; if (str_eq(out, EL_STR(""))) { _if_result_421 = (piece); } else { _if_result_421 = (el_str_concat(el_str_concat(out, EL_STR(",")), piece)); } _if_result_421; })); } else { _if_result_420 = (out); } _if_result_420; }); + i = (i + 1); + } + return el_str_concat(el_str_concat(EL_STR("["), out), EL_STR("]")); + return 0; +} + +el_val_t utf8_safe_slice(el_val_t s, el_val_t n) { + if (str_len(s) <= n) { + return s; + } + el_val_t cut = str_slice(s, 0, n); + el_val_t total = str_len(cut); + el_val_t i = (total - 1); + el_val_t keep = total; + el_val_t scanning = 1; + el_val_t steps = 0; + while ((scanning && (steps < 4)) && (i >= 0)) { + el_val_t c = str_char_code(cut, i); + el_val_t is_ascii = (c < 128); + el_val_t is_lead = (c >= 192); + el_val_t need = ({ el_val_t _if_result_422 = 0; if ((c >= 240)) { _if_result_422 = (4); } else { _if_result_422 = (({ el_val_t _if_result_423 = 0; if ((c >= 224)) { _if_result_423 = (3); } else { _if_result_423 = (2); } _if_result_423; })); } _if_result_422; }); + el_val_t have = (total - i); + keep = ({ el_val_t _if_result_424 = 0; if (is_ascii) { _if_result_424 = (total); } else { _if_result_424 = (({ el_val_t _if_result_425 = 0; if (is_lead) { _if_result_425 = (({ el_val_t _if_result_426 = 0; if ((have == need)) { _if_result_426 = (total); } else { _if_result_426 = (i); } _if_result_426; })); } else { _if_result_425 = (keep); } _if_result_425; })); } _if_result_424; }); + scanning = ({ el_val_t _if_result_427 = 0; if ((is_ascii || is_lead)) { _if_result_427 = (0); } else { _if_result_427 = (1); } _if_result_427; }); + i = (i - 1); + steps = (steps + 1); + } + return str_slice(cut, 0, keep); + return 0; +} + +el_val_t json_trim_dangling_escape(el_val_t s) { + el_val_t out = s; + while (str_ends_with(out, EL_STR("\\"))) { + out = str_slice(out, 0, (str_len(out) - 1)); + } + return out; + return 0; +} + +el_val_t agentic_tools_no_web(void) { + el_val_t base = agentic_tools_literal(); + el_val_t conn = connector_tools_json(); + el_val_t base_inner = str_slice(base, 1, (str_len(base) - 1)); + el_val_t conn_inner = str_slice(conn, 1, (str_len(conn) - 1)); + el_val_t merged = ({ el_val_t _if_result_428 = 0; if (str_eq(conn_inner, EL_STR(""))) { _if_result_428 = (base_inner); } else { _if_result_428 = (el_str_concat(el_str_concat(base_inner, EL_STR(",")), conn_inner)); } _if_result_428; }); + return el_str_concat(el_str_concat(EL_STR("["), strip_client_web_search(merged)), EL_STR("]")); + return 0; +} + +el_val_t openai_agentic_loop(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages_in, el_val_t tools_log_in) { + el_val_t api_url = el_str_concat(llm_base_url(), EL_STR("/chat/completions")); + el_val_t api_key = agentic_api_key(); + el_val_t h = el_map_new(0); + map_set(h, EL_STR("content-type"), EL_STR("application/json")); + if (!str_eq(api_key, EL_STR(""))) { + map_set(h, EL_STR("Authorization"), el_str_concat(EL_STR("Bearer "), api_key)); + } + el_val_t ask_all = (!str_eq(session_id, EL_STR("")) && str_eq(state_get(el_str_concat(EL_STR("require_approval_"), session_id)), EL_STR("true"))); + el_val_t tools_oai = openai_tools_json(tools_json); + el_val_t has_tools = (json_array_len(tools_oai) > 0); + el_val_t messages = messages_in; + el_val_t final_text = EL_STR(""); + el_val_t tools_log = tools_log_in; + el_val_t iteration = 0; + el_val_t keep_going = 1; + el_val_t pending = 0; + el_val_t pend_tool_id = EL_STR(""); + el_val_t pend_tool_name = EL_STR(""); + el_val_t pend_tool_input = EL_STR(""); + el_val_t pend_tool_tier = EL_STR(""); + el_val_t pend_narration = EL_STR(""); + if (!str_eq(session_id, EL_STR(""))) { + state_set(el_str_concat(EL_STR("run_progress_"), session_id), EL_STR("")); + } + while (keep_going && (iteration < 12)) { + el_val_t inner_msgs = str_slice(messages, 1, (str_len(messages) - 1)); + el_val_t all_msgs = ({ el_val_t _if_result_429 = 0; if (str_eq(inner_msgs, EL_STR(""))) { _if_result_429 = (el_str_concat(el_str_concat(EL_STR("[{\"role\":\"system\",\"content\":\""), safe_sys), EL_STR("\"}]"))); } else { _if_result_429 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("[{\"role\":\"system\",\"content\":\""), safe_sys), EL_STR("\"},")), inner_msgs), EL_STR("]"))); } _if_result_429; }); + el_val_t tool_frag = ({ el_val_t _if_result_430 = 0; if (has_tools) { _if_result_430 = (el_str_concat(el_str_concat(EL_STR(",\"tools\":"), tools_oai), EL_STR(",\"tool_choice\":\"auto\",\"parallel_tool_calls\":false"))); } else { _if_result_430 = (EL_STR("")); } _if_result_430; }); + el_val_t req_body = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"model\":\""), model), EL_STR("\"")), EL_STR(",\"max_tokens\":16384")), tool_frag), EL_STR(",\"messages\":")), all_msgs), EL_STR("}")); + el_val_t raw_resp = http_post_with_headers(api_url, req_body, h); + el_val_t is_error = (str_eq(raw_resp, EL_STR("")) || str_starts_with(raw_resp, EL_STR("{\"error\""))); + if (is_error) { + el_val_t err_head = ({ el_val_t _if_result_431 = 0; if ((str_len(raw_resp) > 220)) { _if_result_431 = (str_slice(raw_resp, 0, 220)); } else { _if_result_431 = (raw_resp); } _if_result_431; }); + println(el_str_concat(EL_STR("[soul] llm error (openai lane): "), err_head)); + return EL_STR("{\"error\":\"llm unavailable\",\"reply\":\"\"}"); + } + el_val_t choices = json_get_raw(raw_resp, EL_STR("choices")); + el_val_t eff_choices = ({ el_val_t _if_result_432 = 0; if (str_eq(choices, EL_STR(""))) { _if_result_432 = (EL_STR("[]")); } else { _if_result_432 = (choices); } _if_result_432; }); + if (json_array_len(eff_choices) < 1) { + el_val_t noc_head = ({ el_val_t _if_result_433 = 0; if ((str_len(raw_resp) > 220)) { _if_result_433 = (str_slice(raw_resp, 0, 220)); } else { _if_result_433 = (raw_resp); } _if_result_433; }); + println(el_str_concat(EL_STR("[soul] llm error (openai lane): no choices in response: "), noc_head)); + return EL_STR("{\"error\":\"llm unavailable\",\"reply\":\"\"}"); + } + el_val_t first = json_array_get(eff_choices, 0); + el_val_t message_o = json_get_raw(first, EL_STR("message")); + el_val_t finish = json_get(first, EL_STR("finish_reason")); + el_val_t content_raw = json_get_raw(message_o, EL_STR("content")); + el_val_t is_null_content = (str_eq(content_raw, EL_STR("null")) || str_eq(content_raw, EL_STR(""))); + el_val_t text_out = ({ el_val_t _if_result_434 = 0; if (is_null_content) { _if_result_434 = (EL_STR("")); } else { _if_result_434 = (json_get(message_o, EL_STR("content"))); } _if_result_434; }); + el_val_t tc_raw = json_get_raw(message_o, EL_STR("tool_calls")); + el_val_t tc_arr = ({ el_val_t _if_result_435 = 0; if ((str_eq(tc_raw, EL_STR("")) || str_eq(tc_raw, EL_STR("null")))) { _if_result_435 = (EL_STR("[]")); } else { _if_result_435 = (tc_raw); } _if_result_435; }); + el_val_t tc_n = json_array_len(tc_arr); + el_val_t has_tool = (tc_n > 0); + if (tc_n > 1) { + println(el_str_concat(el_str_concat(EL_STR("[soul] DRIFT: provider returned "), int_to_str(tc_n)), EL_STR(" parallel tool_calls despite parallel_tool_calls:false - keeping the first only (ADR-0005 mirror)"))); + } + if (((!str_eq(finish, EL_STR("stop")) && !str_eq(finish, EL_STR("tool_calls"))) && !str_eq(finish, EL_STR("length"))) && !str_eq(finish, EL_STR(""))) { + println(el_str_concat(EL_STR("[soul] DRIFT: unknown finish_reason from API: "), finish)); + } + el_val_t tc0 = ({ el_val_t _if_result_436 = 0; if (has_tool) { _if_result_436 = (json_array_get(tc_arr, 0)); } else { _if_result_436 = (EL_STR("")); } _if_result_436; }); + el_val_t tool_id = ({ el_val_t _if_result_437 = 0; if (has_tool) { _if_result_437 = (json_get(tc0, EL_STR("id"))); } else { _if_result_437 = (EL_STR("")); } _if_result_437; }); + el_val_t tc_fn = ({ el_val_t _if_result_438 = 0; if (has_tool) { _if_result_438 = (json_get_raw(tc0, EL_STR("function"))); } else { _if_result_438 = (EL_STR("")); } _if_result_438; }); + el_val_t tool_name = ({ el_val_t _if_result_439 = 0; if (has_tool) { _if_result_439 = (json_get(tc_fn, EL_STR("name"))); } else { _if_result_439 = (EL_STR("")); } _if_result_439; }); + el_val_t tool_input_raw = ({ el_val_t _if_result_440 = 0; if (has_tool) { _if_result_440 = (json_get(tc_fn, EL_STR("arguments"))); } else { _if_result_440 = (EL_STR("")); } _if_result_440; }); + el_val_t tool_input = ({ el_val_t _if_result_441 = 0; if (str_eq(tool_input_raw, EL_STR(""))) { _if_result_441 = (EL_STR("{}")); } else { _if_result_441 = (tool_input_raw); } _if_result_441; }); + el_val_t is_tool_turn = has_tool; + el_val_t always_key = el_str_concat(EL_STR("always_allow_"), session_id); + el_val_t always_list = ({ el_val_t _if_result_442 = 0; if (!str_eq(session_id, EL_STR(""))) { _if_result_442 = (state_get(always_key)); } else { _if_result_442 = (EL_STR("")); } _if_result_442; }); + el_val_t is_always_allowed = ((!str_eq(tool_name, EL_STR("")) && !str_eq(always_list, EL_STR(""))) && str_contains(always_list, tool_name)); + el_val_t risk_tier = ({ el_val_t _if_result_443 = 0; if (is_tool_turn) { _if_result_443 = (classify_tool_risk(tool_name, tool_input)); } else { _if_result_443 = (EL_STR("")); } _if_result_443; }); + el_val_t needs_bridge = (is_tool_turn && ((ask_all || str_eq(risk_tier, EL_STR("escalate"))) || (!is_builtin_tool(tool_name) && !is_always_allowed))); + el_val_t tool_result_raw = ({ el_val_t _if_result_444 = 0; if ((is_tool_turn && !needs_bridge)) { _if_result_444 = (dispatch_tool(tool_name, tool_input)); } else { _if_result_444 = (EL_STR("")); } _if_result_444; }); + el_val_t tool_result = ({ el_val_t _if_result_445 = 0; if ((str_len(tool_result_raw) > 6000)) { _if_result_445 = (el_str_concat(json_trim_dangling_escape(str_slice(tool_result_raw, 0, 6000)), EL_STR("...[truncated]"))); } else { _if_result_445 = (tool_result_raw); } _if_result_445; }); + el_val_t tool_quoted = el_str_concat(el_str_concat(EL_STR("\""), tool_name), EL_STR("\"")); + tools_log = ({ el_val_t _if_result_446 = 0; if (is_tool_turn) { _if_result_446 = (({ el_val_t _if_result_447 = 0; if (str_eq(tools_log, EL_STR(""))) { _if_result_447 = (tool_quoted); } else { _if_result_447 = (el_str_concat(el_str_concat(tools_log, EL_STR(",")), tool_quoted)); } _if_result_447; })); } else { _if_result_446 = (tools_log); } _if_result_446; }); + el_val_t content_frag = ({ el_val_t _if_result_448 = 0; if (is_null_content) { _if_result_448 = (EL_STR("null")); } else { _if_result_448 = (content_raw); } _if_result_448; }); + el_val_t assist_turn = ({ el_val_t _if_result_449 = 0; if (has_tool) { _if_result_449 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"role\":\"assistant\",\"content\":"), content_frag), EL_STR(",\"tool_calls\":[")), tc0), EL_STR("]}"))); } else { _if_result_449 = (el_str_concat(el_str_concat(EL_STR("{\"role\":\"assistant\",\"content\":"), content_frag), EL_STR("}"))); } _if_result_449; }); + el_val_t inner_now = str_slice(messages, 1, (str_len(messages) - 1)); + el_val_t messages_with_assistant = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner_now), EL_STR(",")), assist_turn), EL_STR("]")); + el_val_t local_continue = (is_tool_turn && !needs_bridge); + messages = ({ el_val_t _if_result_450 = 0; if (local_continue) { el_val_t inner2 = str_slice(messages_with_assistant, 1, (str_len(messages_with_assistant) - 1)); _if_result_450 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner2), EL_STR(",{\"role\":\"tool\",\"tool_call_id\":\"")), tool_id), EL_STR("\",\"content\":\"")), tool_result), EL_STR("\"}]"))); } else { _if_result_450 = (messages); } _if_result_450; }); + if (!str_eq(session_id, EL_STR(""))) { + el_val_t prog_key = el_str_concat(EL_STR("run_progress_"), session_id); + el_val_t prog_prev = state_get(prog_key); + el_val_t prog_snip = ({ el_val_t _if_result_451 = 0; if ((str_len(text_out) > 280)) { _if_result_451 = (str_slice(text_out, 0, 280)); } else { _if_result_451 = (text_out); } _if_result_451; }); + el_val_t prog_entry = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"i\":"), int_to_str(iteration)), EL_STR(",\"t\":\"")), json_safe(prog_snip)), EL_STR("\"")), EL_STR(",\"tool\":\"")), json_safe(tool_name)), EL_STR("\"}")); + el_val_t prog_next = ({ el_val_t _if_result_452 = 0; if (str_eq(prog_prev, EL_STR(""))) { _if_result_452 = (prog_entry); } else { _if_result_452 = (el_str_concat(el_str_concat(prog_prev, EL_STR(",")), prog_entry)); } _if_result_452; }); + state_set(prog_key, prog_next); + } + pending = ({ el_val_t _if_result_453 = 0; if (needs_bridge) { _if_result_453 = (1); } else { _if_result_453 = (pending); } _if_result_453; }); + pend_tool_id = ({ el_val_t _if_result_454 = 0; if (needs_bridge) { _if_result_454 = (tool_id); } else { _if_result_454 = (pend_tool_id); } _if_result_454; }); + pend_tool_name = ({ el_val_t _if_result_455 = 0; if (needs_bridge) { _if_result_455 = (tool_name); } else { _if_result_455 = (pend_tool_name); } _if_result_455; }); + pend_tool_input = ({ el_val_t _if_result_456 = 0; if (needs_bridge) { _if_result_456 = (tool_input); } else { _if_result_456 = (pend_tool_input); } _if_result_456; }); + pend_tool_tier = ({ el_val_t _if_result_457 = 0; if (needs_bridge) { _if_result_457 = (risk_tier); } else { _if_result_457 = (pend_tool_tier); } _if_result_457; }); + pend_narration = ({ el_val_t _if_result_458 = 0; if (needs_bridge) { _if_result_458 = (text_out); } else { _if_result_458 = (pend_narration); } _if_result_458; }); + if (needs_bridge) { + bridge_save(session_id, model, safe_sys, tools_json, messages_with_assistant, tools_log, tool_id, EL_STR("openai")); + } + final_text = ({ el_val_t _if_result_459 = 0; if (!is_tool_turn) { _if_result_459 = (el_str_concat(el_str_concat(final_text, text_join_sep(final_text, text_out, 1)), text_out)); } else { _if_result_459 = (final_text); } _if_result_459; }); + final_text = ({ el_val_t _if_result_460 = 0; if ((str_eq(finish, EL_STR("length")) && has_tool)) { _if_result_460 = (el_str_concat(final_text, EL_STR("\n\n[Output limit reached mid-action - the last planned action did not run. Ask me to continue to finish it.]"))); } else { _if_result_460 = (final_text); } _if_result_460; }); + keep_going = ({ el_val_t _if_result_461 = 0; if (local_continue) { _if_result_461 = (keep_going); } else { _if_result_461 = (0); } _if_result_461; }); + iteration = (iteration + 1); + } + if (pending) { + el_val_t safe_in = ({ el_val_t _if_result_462 = 0; if (str_eq(pend_tool_input, EL_STR(""))) { _if_result_462 = (EL_STR("{}")); } else { _if_result_462 = (pend_tool_input); } _if_result_462; }); + el_val_t tools_arr = ({ el_val_t _if_result_463 = 0; if (str_eq(tools_log, EL_STR(""))) { _if_result_463 = (EL_STR("[]")); } else { _if_result_463 = (el_str_concat(el_str_concat(EL_STR("["), tools_log), EL_STR("]"))); } _if_result_463; }); + return 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_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"tool_pending\":true"), EL_STR(",\"session_id\":\"")), session_id), EL_STR("\"")), EL_STR(",\"call_id\":\"")), pend_tool_id), EL_STR("\"")), EL_STR(",\"tool_name\":\"")), pend_tool_name), EL_STR("\"")), EL_STR(",\"tool_input\":")), safe_in), EL_STR(",\"risk_tier\":\"")), pend_tool_tier), EL_STR("\"")), EL_STR(",\"narration\":\"")), json_safe(pend_narration)), EL_STR("\"")), EL_STR(",\"model\":\"")), model), EL_STR("\"")), EL_STR(",\"agentic\":true")), EL_STR(",\"sources\":\"\"")), EL_STR(",\"tools_used\":")), tools_arr), EL_STR("}")); + } + final_text = receipt_strip(final_text); + if (str_eq(final_text, EL_STR(""))) { + el_val_t hit_cap = (iteration >= 12); + el_val_t err_msg = ({ el_val_t _if_result_464 = 0; if (hit_cap) { _if_result_464 = (EL_STR("agentic loop hit the 12-iteration cap without producing a final reply - task may be too complex or a tool call is looping")); } else { _if_result_464 = (EL_STR("no response")); } _if_result_464; }); + return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"error\":\""), err_msg), EL_STR("\",\"reply\":\"\",\"iterations\":")), int_to_str(iteration)), EL_STR("}")); + } + el_val_t safe_text = json_safe(final_text); + el_val_t tools_arr = ({ el_val_t _if_result_465 = 0; if (str_eq(tools_log, EL_STR(""))) { _if_result_465 = (EL_STR("[]")); } else { _if_result_465 = (el_str_concat(el_str_concat(EL_STR("["), tools_log), EL_STR("]"))); } _if_result_465; }); + if (!str_eq(session_id, EL_STR(""))) { + el_val_t done_key = el_str_concat(EL_STR("run_progress_"), session_id); + el_val_t done_prev = state_get(done_key); + el_val_t done_next = ({ el_val_t _if_result_466 = 0; if (str_eq(done_prev, EL_STR(""))) { _if_result_466 = (EL_STR("{\"done\":true}")); } else { _if_result_466 = (el_str_concat(done_prev, EL_STR(",{\"done\":true}"))); } _if_result_466; }); + state_set(done_key, done_next); + } + return 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("{\"reply\":\""), safe_text), EL_STR("\",\"model\":\"")), model), EL_STR("\",\"agentic\":true,\"tools_used\":")), tools_arr), EL_STR(",\"sources\":\"\",\"iterations\":")), int_to_str(iteration)), EL_STR("}")); + return 0; +} + el_val_t agentic_tools_literal(void) { return 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("["), EL_STR("{\"name\":\"read_file\",\"description\":\"Read contents of a file from disk.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\",\"description\":\"Absolute file path\"}},\"required\":[\"path\"]}},")), EL_STR("{\"name\":\"write_file\",\"description\":\"Write content to a file on disk.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"},\"content\":{\"type\":\"string\"}},\"required\":[\"path\",\"content\"]}},")), EL_STR("{\"name\":\"web_get\",\"description\":\"Fetch content from a URL.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"url\":{\"type\":\"string\"}},\"required\":[\"url\"]}},")), EL_STR("{\"name\":\"search_memory\",\"description\":\"Search engram memory for relevant nodes.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":\"string\"}},\"required\":[\"query\"]}},")), EL_STR("{\"name\":\"run_command\",\"description\":\"Run a shell command and capture output.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"command\":{\"type\":\"string\"}},\"required\":[\"command\"]}},")), EL_STR("{\"name\":\"list_files\",\"description\":\"List files in a directory.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"}},\"required\":[\"path\"]}},")), EL_STR("{\"name\":\"grep\",\"description\":\"Search for a pattern in files.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"pattern\":{\"type\":\"string\"},\"path\":{\"type\":\"string\"}},\"required\":[\"pattern\",\"path\"]}},")), EL_STR("{\"name\":\"edit_file\",\"description\":\"Edit a file by replacing old_text with new_text.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"},\"old_text\":{\"type\":\"string\"},\"new_text\":{\"type\":\"string\"}},\"required\":[\"path\",\"old_text\",\"new_text\"]}},")), EL_STR("{\"name\":\"remember\",\"description\":\"Store a memory in the Engram graph.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"content\":{\"type\":\"string\"},\"tags\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"content\"]}},")), EL_STR("{\"name\":\"recall\",\"description\":\"Recall memories by activating the Engram graph from a query.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":\"string\"},\"depth\":{\"type\":\"integer\"}},\"required\":[\"query\"]}},")), EL_STR("{\"name\":\"neuron_search_knowledge\",\"description\":\"Search Neuron's knowledge base.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":\"string\"},\"limit\":{\"type\":\"integer\"}},\"required\":[\"query\"]}},")), EL_STR("{\"name\":\"neuron_remember\",\"description\":\"Store a memory in Neuron's persistent graph.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"content\":{\"type\":\"string\"},\"tags\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}},\"project\":{\"type\":\"string\"},\"importance\":{\"type\":\"string\"}},\"required\":[\"content\"]}},")), EL_STR("{\"name\":\"neuron_recall\",\"description\":\"Search Neuron's memory nodes.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":\"string\"},\"limit\":{\"type\":\"integer\"}},\"required\":[\"query\"]}},")), EL_STR("{\"name\":\"neuron_review_backlog\",\"description\":\"Review Neuron's work backlog.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"view\":{\"type\":\"string\"},\"project\":{\"type\":\"string\"},\"status\":{\"type\":\"string\"},\"priority\":{\"type\":\"string\"},\"query\":{\"type\":\"string\"}},\"required\":[]}},")), EL_STR("{\"name\":\"neuron_find_artifacts\",\"description\":\"Find Neuron artifacts by project or query.\",\"input_schema\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":\"string\"},\"project\":{\"type\":\"string\"}},\"required\":[]}},")), EL_STR("{\"name\":\"neuron_compile_ctx\",\"description\":\"Compile Neuron's full active context snapshot.\",\"input_schema\":{\"type\":\"object\",\"properties\":{},\"required\":[]}}")), EL_STR("]")); return 0; @@ -28273,7 +28483,7 @@ el_val_t agentic_tools_literal(void) { el_val_t web_search_tool_json(void) { el_val_t ver = state_get(EL_STR("web_search_tool_version")); - el_val_t eff = ({ el_val_t _if_result_420 = 0; if (str_eq(ver, EL_STR(""))) { _if_result_420 = (EL_STR("web_search_20250305")); } else { _if_result_420 = (ver); } _if_result_420; }); + el_val_t eff = ({ el_val_t _if_result_467 = 0; if (str_eq(ver, EL_STR(""))) { _if_result_467 = (EL_STR("web_search_20250305")); } else { _if_result_467 = (ver); } _if_result_467; }); return el_str_concat(el_str_concat(EL_STR("{\"type\":\""), eff), EL_STR("\",\"name\":\"web_search\",\"max_uses\":5}")); return 0; } @@ -28319,13 +28529,13 @@ el_val_t agentic_tools_all(void) { el_val_t conn = connector_tools_json(); el_val_t base_inner = str_slice(base, 1, (str_len(base) - 1)); el_val_t conn_inner = str_slice(conn, 1, (str_len(conn) - 1)); - el_val_t merged = ({ el_val_t _if_result_421 = 0; if (str_eq(conn_inner, EL_STR(""))) { _if_result_421 = (base_inner); } else { _if_result_421 = (el_str_concat(el_str_concat(base_inner, EL_STR(",")), conn_inner)); } _if_result_421; }); + el_val_t merged = ({ el_val_t _if_result_468 = 0; if (str_eq(conn_inner, EL_STR(""))) { _if_result_468 = (base_inner); } else { _if_result_468 = (el_str_concat(el_str_concat(base_inner, EL_STR(",")), conn_inner)); } _if_result_468; }); return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), strip_client_web_search(merged)), EL_STR(",")), web_search_tool_json()), EL_STR("]")); return 0; } el_val_t call_mcp_bridge(el_val_t tool_name, el_val_t tool_input) { - el_val_t eff_input = ({ el_val_t _if_result_422 = 0; if (str_eq(tool_input, EL_STR(""))) { _if_result_422 = (EL_STR("{}")); } else { _if_result_422 = (tool_input); } _if_result_422; }); + el_val_t eff_input = ({ el_val_t _if_result_469 = 0; if (str_eq(tool_input, EL_STR(""))) { _if_result_469 = (EL_STR("{}")); } else { _if_result_469 = (tool_input); } _if_result_469; }); el_val_t body = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"name\":\""), tool_name), EL_STR("\",\"input\":")), eff_input), EL_STR("}")); el_val_t tmp = EL_STR("/tmp/neuron-mcp-call.json"); fs_write(tmp, body); @@ -28360,7 +28570,7 @@ el_val_t call_neuron_mcp(el_val_t tool_name, el_val_t args) { el_val_t result = json_get(raw, EL_STR("result")); if (str_eq(result, EL_STR(""))) { el_val_t err = json_get(raw, EL_STR("error")); - return json_safe(({ el_val_t _if_result_423 = 0; if (str_eq(err, EL_STR(""))) { _if_result_423 = (EL_STR("Neuron MCP call failed")); } else { _if_result_423 = (el_str_concat(EL_STR("Neuron MCP error: "), err)); } _if_result_423; })); + return json_safe(({ el_val_t _if_result_470 = 0; if (str_eq(err, EL_STR(""))) { _if_result_470 = (EL_STR("Neuron MCP call failed")); } else { _if_result_470 = (el_str_concat(EL_STR("Neuron MCP error: "), err)); } _if_result_470; })); } return json_safe(result); return 0; @@ -28412,7 +28622,7 @@ el_val_t run_command_is_readonly(el_val_t cmd) { return 0; } el_val_t sp = str_index_of(cmd, EL_STR(" ")); - el_val_t first = ({ el_val_t _if_result_424 = 0; if ((sp < 0)) { _if_result_424 = (cmd); } else { _if_result_424 = (str_slice(cmd, 0, sp)); } _if_result_424; }); + el_val_t first = ({ el_val_t _if_result_471 = 0; if ((sp < 0)) { _if_result_471 = (cmd); } else { _if_result_471 = (str_slice(cmd, 0, sp)); } _if_result_471; }); if (((str_eq(first, EL_STR("ls")) || str_eq(first, EL_STR("cat"))) || str_eq(first, EL_STR("head"))) || str_eq(first, EL_STR("tail"))) { return 1; } @@ -28434,7 +28644,7 @@ el_val_t cmd_abs_escape_at(el_val_t cmd, el_val_t root, el_val_t needle) { el_val_t slash_at = ((idx + str_len(needle)) - 1); el_val_t after = str_slice(rest, slash_at, str_len(rest)); el_val_t ok = ((str_starts_with(after, el_str_concat(root, EL_STR("/"))) || str_starts_with(after, el_str_concat(root, EL_STR(" ")))) || str_eq(after, root)); - found = ({ el_val_t _if_result_425 = 0; if (!ok) { _if_result_425 = (1); } else { _if_result_425 = (found); } _if_result_425; }); + found = ({ el_val_t _if_result_472 = 0; if (!ok) { _if_result_472 = (1); } else { _if_result_472 = (found); } _if_result_472; }); rest = str_slice(rest, (slash_at + 1), str_len(rest)); } return found; @@ -28555,7 +28765,7 @@ el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input) { el_val_t content = json_get(out, EL_STR("content")); if (str_eq(content, EL_STR(""))) { el_val_t err = json_get(out, EL_STR("error")); - el_val_t msg = ({ el_val_t _if_result_426 = 0; if (str_eq(err, EL_STR(""))) { _if_result_426 = (EL_STR("MCP call failed")); } else { _if_result_426 = (el_str_concat(EL_STR("MCP error: "), err)); } _if_result_426; }); + el_val_t msg = ({ el_val_t _if_result_473 = 0; if (str_eq(err, EL_STR(""))) { _if_result_473 = (EL_STR("MCP call failed")); } else { _if_result_473 = (el_str_concat(EL_STR("MCP error: "), err)); } _if_result_473; }); return json_safe(msg); } return json_safe(content); @@ -28608,21 +28818,21 @@ el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input) { if (str_eq(tool_name, EL_STR("remember"))) { el_val_t content = json_get(tool_input, EL_STR("content")); el_val_t tags_raw = json_get(tool_input, EL_STR("tags")); - el_val_t tags = ({ el_val_t _if_result_427 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_427 = (EL_STR("[\"chat\"]")); } else { _if_result_427 = (tags_raw); } _if_result_427; }); + el_val_t tags = ({ el_val_t _if_result_474 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_474 = (EL_STR("[\"chat\"]")); } else { _if_result_474 = (tags_raw); } _if_result_474; }); el_val_t id = mem_remember(content, tags); return json_safe(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), id), EL_STR("\"}"))); } if (str_eq(tool_name, EL_STR("recall"))) { el_val_t query = json_get(tool_input, EL_STR("query")); el_val_t depth_str = json_get(tool_input, EL_STR("depth")); - el_val_t depth = ({ el_val_t _if_result_428 = 0; if (str_eq(depth_str, EL_STR(""))) { _if_result_428 = (3); } else { _if_result_428 = (str_to_int(depth_str)); } _if_result_428; }); + el_val_t depth = ({ el_val_t _if_result_475 = 0; if (str_eq(depth_str, EL_STR(""))) { _if_result_475 = (3); } else { _if_result_475 = (str_to_int(depth_str)); } _if_result_475; }); el_val_t result = mem_recall(query, depth); return json_safe(result); } if (str_eq(tool_name, EL_STR("neuron_search_knowledge"))) { el_val_t query = json_get(tool_input, EL_STR("query")); el_val_t limit_str = json_get(tool_input, EL_STR("limit")); - el_val_t limit = ({ el_val_t _if_result_429 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_429 = (5); } else { _if_result_429 = (str_to_int(limit_str)); } _if_result_429; }); + el_val_t limit = ({ el_val_t _if_result_476 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_476 = (5); } else { _if_result_476 = (str_to_int(limit_str)); } _if_result_476; }); el_val_t args = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"query\":\""), json_safe(query)), EL_STR("\",\"limit\":")), int_to_str(limit)), EL_STR("}")); el_val_t result = call_neuron_mcp(EL_STR("searchKnowledge"), args); return json_safe(result); @@ -28633,9 +28843,9 @@ el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input) { el_val_t project = json_get(tool_input, EL_STR("project")); el_val_t importance = json_get(tool_input, EL_STR("importance")); el_val_t safe_content = json_safe(content); - el_val_t tags_part = ({ el_val_t _if_result_430 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_430 = (EL_STR("\"tags\":[\"chat\"]")); } else { _if_result_430 = (el_str_concat(EL_STR("\"tags\":"), tags_raw)); } _if_result_430; }); - el_val_t project_part = ({ el_val_t _if_result_431 = 0; if (str_eq(project, EL_STR(""))) { _if_result_431 = (EL_STR("")); } else { _if_result_431 = (el_str_concat(el_str_concat(EL_STR(",\"project\":\""), json_safe(project)), EL_STR("\""))); } _if_result_431; }); - el_val_t importance_part = ({ el_val_t _if_result_432 = 0; if (str_eq(importance, EL_STR(""))) { _if_result_432 = (EL_STR("")); } else { _if_result_432 = (el_str_concat(el_str_concat(EL_STR(",\"importance\":\""), json_safe(importance)), EL_STR("\""))); } _if_result_432; }); + el_val_t tags_part = ({ el_val_t _if_result_477 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_477 = (EL_STR("\"tags\":[\"chat\"]")); } else { _if_result_477 = (el_str_concat(EL_STR("\"tags\":"), tags_raw)); } _if_result_477; }); + el_val_t project_part = ({ el_val_t _if_result_478 = 0; if (str_eq(project, EL_STR(""))) { _if_result_478 = (EL_STR("")); } else { _if_result_478 = (el_str_concat(el_str_concat(EL_STR(",\"project\":\""), json_safe(project)), EL_STR("\""))); } _if_result_478; }); + el_val_t importance_part = ({ el_val_t _if_result_479 = 0; if (str_eq(importance, EL_STR(""))) { _if_result_479 = (EL_STR("")); } else { _if_result_479 = (el_str_concat(el_str_concat(EL_STR(",\"importance\":\""), json_safe(importance)), EL_STR("\""))); } _if_result_479; }); el_val_t args = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"content\":\""), safe_content), EL_STR("\",")), tags_part), project_part), importance_part), EL_STR("}")); el_val_t result = call_neuron_mcp(EL_STR("remember"), args); return json_safe(result); @@ -28643,7 +28853,7 @@ el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input) { if (str_eq(tool_name, EL_STR("neuron_recall"))) { el_val_t query = json_get(tool_input, EL_STR("query")); el_val_t limit_str = json_get(tool_input, EL_STR("limit")); - el_val_t limit = ({ el_val_t _if_result_433 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_433 = (10); } else { _if_result_433 = (str_to_int(limit_str)); } _if_result_433; }); + el_val_t limit = ({ el_val_t _if_result_480 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_480 = (10); } else { _if_result_480 = (str_to_int(limit_str)); } _if_result_480; }); el_val_t args = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"query\":\""), json_safe(query)), EL_STR("\",\"limit\":")), int_to_str(limit)), EL_STR("}")); el_val_t result = call_neuron_mcp(EL_STR("inspectMemories"), args); return json_safe(result); @@ -28654,11 +28864,11 @@ el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input) { el_val_t status = json_get(tool_input, EL_STR("status")); el_val_t priority = json_get(tool_input, EL_STR("priority")); el_val_t query = json_get(tool_input, EL_STR("query")); - el_val_t view_part = ({ el_val_t _if_result_434 = 0; if (str_eq(view, EL_STR(""))) { _if_result_434 = (EL_STR("\"view\":\"roadmap\"")); } else { _if_result_434 = (el_str_concat(el_str_concat(EL_STR("\"view\":\""), json_safe(view)), EL_STR("\""))); } _if_result_434; }); - el_val_t project_part = ({ el_val_t _if_result_435 = 0; if (str_eq(project, EL_STR(""))) { _if_result_435 = (EL_STR("")); } else { _if_result_435 = (el_str_concat(el_str_concat(EL_STR(",\"project\":\""), json_safe(project)), EL_STR("\""))); } _if_result_435; }); - el_val_t status_part = ({ el_val_t _if_result_436 = 0; if (str_eq(status, EL_STR(""))) { _if_result_436 = (EL_STR("")); } else { _if_result_436 = (el_str_concat(el_str_concat(EL_STR(",\"status\":\""), json_safe(status)), EL_STR("\""))); } _if_result_436; }); - el_val_t priority_part = ({ el_val_t _if_result_437 = 0; if (str_eq(priority, EL_STR(""))) { _if_result_437 = (EL_STR("")); } else { _if_result_437 = (el_str_concat(el_str_concat(EL_STR(",\"priority\":\""), json_safe(priority)), EL_STR("\""))); } _if_result_437; }); - el_val_t query_part = ({ el_val_t _if_result_438 = 0; if (str_eq(query, EL_STR(""))) { _if_result_438 = (EL_STR("")); } else { _if_result_438 = (el_str_concat(el_str_concat(EL_STR(",\"query\":\""), json_safe(query)), EL_STR("\""))); } _if_result_438; }); + el_val_t view_part = ({ el_val_t _if_result_481 = 0; if (str_eq(view, EL_STR(""))) { _if_result_481 = (EL_STR("\"view\":\"roadmap\"")); } else { _if_result_481 = (el_str_concat(el_str_concat(EL_STR("\"view\":\""), json_safe(view)), EL_STR("\""))); } _if_result_481; }); + el_val_t project_part = ({ el_val_t _if_result_482 = 0; if (str_eq(project, EL_STR(""))) { _if_result_482 = (EL_STR("")); } else { _if_result_482 = (el_str_concat(el_str_concat(EL_STR(",\"project\":\""), json_safe(project)), EL_STR("\""))); } _if_result_482; }); + el_val_t status_part = ({ el_val_t _if_result_483 = 0; if (str_eq(status, EL_STR(""))) { _if_result_483 = (EL_STR("")); } else { _if_result_483 = (el_str_concat(el_str_concat(EL_STR(",\"status\":\""), json_safe(status)), EL_STR("\""))); } _if_result_483; }); + el_val_t priority_part = ({ el_val_t _if_result_484 = 0; if (str_eq(priority, EL_STR(""))) { _if_result_484 = (EL_STR("")); } else { _if_result_484 = (el_str_concat(el_str_concat(EL_STR(",\"priority\":\""), json_safe(priority)), EL_STR("\""))); } _if_result_484; }); + el_val_t query_part = ({ el_val_t _if_result_485 = 0; if (str_eq(query, EL_STR(""))) { _if_result_485 = (EL_STR("")); } else { _if_result_485 = (el_str_concat(el_str_concat(EL_STR(",\"query\":\""), json_safe(query)), EL_STR("\""))); } _if_result_485; }); el_val_t args = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{"), view_part), project_part), status_part), priority_part), query_part), EL_STR("}")); el_val_t result = call_neuron_mcp(EL_STR("reviewBacklog"), args); return json_safe(result); @@ -28666,8 +28876,8 @@ el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input) { if (str_eq(tool_name, EL_STR("neuron_find_artifacts"))) { el_val_t query = json_get(tool_input, EL_STR("query")); el_val_t project = json_get(tool_input, EL_STR("project")); - el_val_t query_part = ({ el_val_t _if_result_439 = 0; if (str_eq(query, EL_STR(""))) { _if_result_439 = (EL_STR("")); } else { _if_result_439 = (el_str_concat(el_str_concat(EL_STR("\"query\":\""), json_safe(query)), EL_STR("\""))); } _if_result_439; }); - el_val_t project_part = ({ el_val_t _if_result_440 = 0; if (str_eq(project, EL_STR(""))) { _if_result_440 = (EL_STR("")); } else { _if_result_440 = (({ el_val_t _if_result_441 = 0; if (str_eq(query_part, EL_STR(""))) { _if_result_441 = (el_str_concat(el_str_concat(EL_STR("\"project\":\""), json_safe(project)), EL_STR("\""))); } else { _if_result_441 = (el_str_concat(el_str_concat(EL_STR(",\"project\":\""), json_safe(project)), EL_STR("\""))); } _if_result_441; })); } _if_result_440; }); + el_val_t query_part = ({ el_val_t _if_result_486 = 0; if (str_eq(query, EL_STR(""))) { _if_result_486 = (EL_STR("")); } else { _if_result_486 = (el_str_concat(el_str_concat(EL_STR("\"query\":\""), json_safe(query)), EL_STR("\""))); } _if_result_486; }); + el_val_t project_part = ({ el_val_t _if_result_487 = 0; if (str_eq(project, EL_STR(""))) { _if_result_487 = (EL_STR("")); } else { _if_result_487 = (({ el_val_t _if_result_488 = 0; if (str_eq(query_part, EL_STR(""))) { _if_result_488 = (el_str_concat(el_str_concat(EL_STR("\"project\":\""), json_safe(project)), EL_STR("\""))); } else { _if_result_488 = (el_str_concat(el_str_concat(EL_STR(",\"project\":\""), json_safe(project)), EL_STR("\""))); } _if_result_488; })); } _if_result_487; }); el_val_t args = el_str_concat(el_str_concat(el_str_concat(EL_STR("{"), query_part), project_part), EL_STR("}")); el_val_t result = call_neuron_mcp(EL_STR("findArtifacts"), args); return json_safe(result); @@ -28687,7 +28897,7 @@ el_val_t is_builtin_tool(el_val_t tool_name) { el_val_t next_bridge_id(void) { el_val_t prev = state_get(EL_STR("mcp_bridge_seq")); - el_val_t n = ({ el_val_t _if_result_442 = 0; if (str_eq(prev, EL_STR(""))) { _if_result_442 = (0); } else { _if_result_442 = (str_to_int(prev)); } _if_result_442; }); + el_val_t n = ({ el_val_t _if_result_489 = 0; if (str_eq(prev, EL_STR(""))) { _if_result_489 = (0); } else { _if_result_489 = (str_to_int(prev)); } _if_result_489; }); el_val_t next = (n + 1); state_set(EL_STR("mcp_bridge_seq"), int_to_str(next)); el_val_t uid = uuid_v4(); @@ -28701,12 +28911,12 @@ el_val_t handle_chat_plan(el_val_t body) { return EL_STR("{\"error\":\"message required\",\"plan\":null}"); } el_val_t req_model = json_get(body, EL_STR("model")); - el_val_t model = ({ el_val_t _if_result_443 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_443 = (chat_default_model()); } else { _if_result_443 = (req_model); } _if_result_443; }); + el_val_t model = ({ el_val_t _if_result_490 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_490 = (chat_default_model()); } else { _if_result_490 = (req_model); } _if_result_490; }); el_val_t op_home = env(EL_STR("HOME")); el_val_t op_user = env(EL_STR("USER")); - el_val_t op_display = ({ el_val_t _if_result_444 = 0; if (str_eq(op_user, EL_STR(""))) { _if_result_444 = (EL_STR("the current user")); } else { _if_result_444 = (op_user); } _if_result_444; }); + el_val_t op_display = ({ el_val_t _if_result_491 = 0; if (str_eq(op_user, EL_STR(""))) { _if_result_491 = (EL_STR("the current user")); } else { _if_result_491 = (op_user); } _if_result_491; }); el_val_t ctx = engram_compile(message); - el_val_t ctx_block = ({ el_val_t _if_result_445 = 0; if (str_eq(ctx, EL_STR(""))) { _if_result_445 = (EL_STR("")); } else { _if_result_445 = (el_str_concat(EL_STR("\n\n[CONTEXT]\n"), ctx)); } _if_result_445; }); + el_val_t ctx_block = ({ el_val_t _if_result_492 = 0; if (str_eq(ctx, EL_STR(""))) { _if_result_492 = (EL_STR("")); } else { _if_result_492 = (el_str_concat(EL_STR("\n\n[CONTEXT]\n"), ctx)); } _if_result_492; }); el_val_t plan_system = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("You are in PLAN MODE. Your job is to produce a concise step-by-step plan for the request below \xe2\x80\x94 WITHOUT executing it.\n\nReturn ONLY a JSON object. No markdown. No preamble. No explanation. Just the JSON:\n{\"steps\":[{\"id\":\"s1\",\"title\":\"<2-6 word title>\",\"detail\":\"\"},{\"id\":\"s2\",...}]}\n\nPlan rules:\n- 3-7 steps (more only when genuinely needed for a complex multi-file task)\n- Each step is one atomic, independently verifiable action\n- title: 2-6 words, imperative (e.g. \"Read config file\", \"Write updated handler\")\n- detail: exactly one sentence describing what happens\n- No tool calls. No execution. No side effects. The user approves before anything runs.\n\nOperator: "), op_display), EL_STR(" at ")), op_home), ctx_block), bounded_persona_floor()); el_val_t raw = llm_call_system(model, plan_system, message); el_val_t is_error = str_starts_with(raw, EL_STR("{\"error\"")); @@ -28718,10 +28928,10 @@ el_val_t handle_chat_plan(el_val_t body) { el_val_t scan_i = (str_len(raw) - 1); while (scan_i >= 0) { el_val_t ch = str_slice(raw, scan_i, (scan_i + 1)); - brace_end = ({ el_val_t _if_result_446 = 0; if ((str_eq(ch, EL_STR("}")) && (brace_end < 0))) { _if_result_446 = (scan_i); } else { _if_result_446 = (brace_end); } _if_result_446; }); - scan_i = ({ el_val_t _if_result_447 = 0; if ((brace_end >= 0)) { _if_result_447 = ((-1)); } else { _if_result_447 = ((scan_i - 1)); } _if_result_447; }); + brace_end = ({ el_val_t _if_result_493 = 0; if ((str_eq(ch, EL_STR("}")) && (brace_end < 0))) { _if_result_493 = (scan_i); } else { _if_result_493 = (brace_end); } _if_result_493; }); + scan_i = ({ el_val_t _if_result_494 = 0; if ((brace_end >= 0)) { _if_result_494 = ((-1)); } else { _if_result_494 = ((scan_i - 1)); } _if_result_494; }); } - el_val_t plan_json = ({ el_val_t _if_result_448 = 0; if ((brace_start >= 0)) { _if_result_448 = (({ el_val_t _if_result_449 = 0; if ((brace_end > brace_start)) { _if_result_449 = (str_slice(raw, brace_start, (brace_end + 1))); } else { _if_result_449 = (raw); } _if_result_449; })); } else { _if_result_448 = (raw); } _if_result_448; }); + el_val_t plan_json = ({ el_val_t _if_result_495 = 0; if ((brace_start >= 0)) { _if_result_495 = (({ el_val_t _if_result_496 = 0; if ((brace_end > brace_start)) { _if_result_496 = (str_slice(raw, brace_start, (brace_end + 1))); } else { _if_result_496 = (raw); } _if_result_496; })); } else { _if_result_495 = (raw); } _if_result_495; }); return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"plan\":"), plan_json), EL_STR(",\"model\":\"")), json_safe(model)), EL_STR("\"}")); return 0; } @@ -28745,7 +28955,7 @@ el_val_t handle_chat_agentic(el_val_t body) { } state_set(EL_STR("agent_workspace_root"), ws_root); } else { - el_val_t own_root = ({ el_val_t _if_result_450 = 0; if (str_eq(sess_for_root, EL_STR(""))) { _if_result_450 = (EL_STR("")); } else { _if_result_450 = (state_get(el_str_concat(EL_STR("agent_workspace_root_"), sess_for_root))); } _if_result_450; }); + el_val_t own_root = ({ el_val_t _if_result_497 = 0; if (str_eq(sess_for_root, EL_STR(""))) { _if_result_497 = (EL_STR("")); } else { _if_result_497 = (state_get(el_str_concat(EL_STR("agent_workspace_root_"), sess_for_root))); } _if_result_497; }); state_set(EL_STR("agent_workspace_root"), own_root); } el_val_t screen_result = agentic_safety_screen(sess_for_root, message); @@ -28755,50 +28965,51 @@ el_val_t handle_chat_agentic(el_val_t body) { return el_str_concat(el_str_concat(EL_STR("{\"reply\":\""), json_safe(safety_validate(EL_STR(""), EL_STR("hard_bell")))), EL_STR("\",\"model\":\"\",\"agentic\":true,\"tools_used\":[]}")); } el_val_t req_model = json_get(body, EL_STR("model")); - el_val_t model = ({ el_val_t _if_result_451 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_451 = (chat_default_model()); } else { _if_result_451 = (req_model); } _if_result_451; }); + el_val_t model = ({ el_val_t _if_result_498 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_498 = (chat_default_model()); } else { _if_result_498 = (req_model); } _if_result_498; }); el_val_t req_session = json_get(body, EL_STR("session_id")); - el_val_t session_valid = ({ el_val_t _if_result_452 = 0; if (str_eq(req_session, EL_STR(""))) { _if_result_452 = (1); } else { _if_result_452 = (session_exists(req_session)); } _if_result_452; }); + el_val_t session_valid = ({ el_val_t _if_result_499 = 0; if (str_eq(req_session, EL_STR(""))) { _if_result_499 = (1); } else { _if_result_499 = (session_exists(req_session)); } _if_result_499; }); if (!session_valid) { return el_str_concat(el_str_concat(EL_STR("{\"error\":\"session not found\",\"session_id\":\""), req_session), EL_STR("\",\"reply\":\"\"}")); } el_val_t hist_key = conv_hist_key(req_session); el_val_t agentic_hist = state_get(hist_key); - el_val_t agentic_hist_len = ({ el_val_t _if_result_453 = 0; if (str_eq(agentic_hist, EL_STR(""))) { _if_result_453 = (0); } else { _if_result_453 = (json_array_len(agentic_hist)); } _if_result_453; }); + el_val_t agentic_hist_len = ({ el_val_t _if_result_500 = 0; if (str_eq(agentic_hist, EL_STR(""))) { _if_result_500 = (0); } else { _if_result_500 = (json_array_len(agentic_hist)); } _if_result_500; }); el_val_t ag_is_cont = engram_is_continuation(message, agentic_hist_len); - el_val_t ag_last_entry = ({ el_val_t _if_result_454 = 0; if (ag_is_cont) { _if_result_454 = (json_array_get(agentic_hist, (agentic_hist_len - 1))); } else { _if_result_454 = (EL_STR("")); } _if_result_454; }); - el_val_t ag_last_content = ({ el_val_t _if_result_455 = 0; if (!str_eq(ag_last_entry, EL_STR(""))) { _if_result_455 = (json_get(ag_last_entry, EL_STR("content"))); } else { _if_result_455 = (EL_STR("")); } _if_result_455; }); - el_val_t ag_thread_snip = ({ el_val_t _if_result_456 = 0; if ((str_len(ag_last_content) > 150)) { _if_result_456 = (str_slice(ag_last_content, 0, 150)); } else { _if_result_456 = (ag_last_content); } _if_result_456; }); - el_val_t ag_seed = ({ el_val_t _if_result_457 = 0; if (!str_eq(ag_thread_snip, EL_STR(""))) { _if_result_457 = (el_str_concat(el_str_concat(ag_thread_snip, EL_STR(" ")), message)); } else { _if_result_457 = (message); } _if_result_457; }); + el_val_t ag_last_entry = ({ el_val_t _if_result_501 = 0; if (ag_is_cont) { _if_result_501 = (json_array_get(agentic_hist, (agentic_hist_len - 1))); } else { _if_result_501 = (EL_STR("")); } _if_result_501; }); + el_val_t ag_last_content = ({ el_val_t _if_result_502 = 0; if (!str_eq(ag_last_entry, EL_STR(""))) { _if_result_502 = (json_get(ag_last_entry, EL_STR("content"))); } else { _if_result_502 = (EL_STR("")); } _if_result_502; }); + el_val_t ag_thread_snip = ({ el_val_t _if_result_503 = 0; if ((str_len(ag_last_content) > 150)) { _if_result_503 = (str_slice(ag_last_content, 0, 150)); } else { _if_result_503 = (ag_last_content); } _if_result_503; }); + el_val_t ag_seed = ({ el_val_t _if_result_504 = 0; if (!str_eq(ag_thread_snip, EL_STR(""))) { _if_result_504 = (el_str_concat(el_str_concat(ag_thread_snip, EL_STR(" ")), message)); } else { _if_result_504 = (message); } _if_result_504; }); el_val_t ctx = engram_compile(ag_seed); el_val_t identity = state_get(EL_STR("soul_identity")); - el_val_t ag_session_preload = ({ el_val_t _if_result_458 = 0; if ((agentic_hist_len == 0)) { el_val_t ag_profile_nodes = engram_search_json(EL_STR("Persona soul:persona identity principal"), 8); el_val_t ag_profile_ok = (!str_eq(ag_profile_nodes, EL_STR("")) && !str_eq(ag_profile_nodes, EL_STR("[]"))); el_val_t ag_profile_nodes2 = ({ el_val_t _if_result_459 = 0; if (ag_profile_ok) { _if_result_459 = (ag_profile_nodes); } else { _if_result_459 = (engram_search_json(EL_STR("user profile preferences name"), 8)); } _if_result_459; }); el_val_t ag_work_nodes = engram_search_json(EL_STR("WorkItem status:in_progress active work"), 6); el_val_t ag_work_ok = (!str_eq(ag_work_nodes, EL_STR("")) && !str_eq(ag_work_nodes, EL_STR("[]"))); el_val_t ag_work_nodes2 = ({ el_val_t _if_result_460 = 0; if (ag_work_ok) { _if_result_460 = (ag_work_nodes); } else { _if_result_460 = (engram_search_json(EL_STR("active project task current in_progress"), 6)); } _if_result_460; }); el_val_t ag_continuity_nodes = engram_search_json(EL_STR("last-session-topic session:emotional-summary conv:history last session"), 3); el_val_t ag_continuity_ok = (!str_eq(ag_continuity_nodes, EL_STR("")) && !str_eq(ag_continuity_nodes, EL_STR("[]"))); el_val_t ag_continuity_snip = ({ el_val_t _if_result_461 = 0; if (ag_continuity_ok) { el_val_t acn0 = json_array_get(ag_continuity_nodes, 0); el_val_t acc = json_get(acn0, EL_STR("content")); _if_result_461 = (({ el_val_t _if_result_462 = 0; if ((str_len(acc) > 350)) { _if_result_462 = (str_slice(acc, 0, 350)); } else { _if_result_462 = (acc); } _if_result_462; })); } else { _if_result_461 = (EL_STR("")); } _if_result_461; }); el_val_t ag_profile_bullets = session_preload_bullets(ag_profile_nodes2, 8, 350); el_val_t ag_work_bullets = session_preload_bullets(ag_work_nodes2, 6, 350); el_val_t ag_has_profile = !str_eq(ag_profile_bullets, EL_STR("")); el_val_t ag_has_work = !str_eq(ag_work_bullets, EL_STR("")); el_val_t ag_has_cont = !str_eq(ag_continuity_snip, EL_STR("")); _if_result_458 = (({ el_val_t _if_result_463 = 0; if (((ag_has_profile || ag_has_work) || ag_has_cont)) { el_val_t p = ({ el_val_t _if_result_464 = 0; if (ag_has_profile) { _if_result_464 = (el_str_concat(el_str_concat(EL_STR("[USER CONTEXT \xe2\x80\x94 from memory]\n"), ag_profile_bullets), EL_STR("\n\n"))); } else { _if_result_464 = (EL_STR("")); } _if_result_464; }); el_val_t w = ({ el_val_t _if_result_465 = 0; if (ag_has_work) { _if_result_465 = (el_str_concat(el_str_concat(EL_STR("[ACTIVE WORK \xe2\x80\x94 from memory]\n"), ag_work_bullets), EL_STR("\n\n"))); } else { _if_result_465 = (EL_STR("")); } _if_result_465; }); el_val_t c = ({ el_val_t _if_result_466 = 0; if (ag_has_cont) { _if_result_466 = (el_str_concat(el_str_concat(EL_STR("[CONTINUING FROM LAST SESSION]\n"), ag_continuity_snip), EL_STR("\n\n"))); } else { _if_result_466 = (EL_STR("")); } _if_result_466; }); _if_result_463 = (el_str_concat(el_str_concat(el_str_concat(EL_STR("\n\n"), p), w), c)); } else { _if_result_463 = (EL_STR("")); } _if_result_463; })); } else { _if_result_458 = (EL_STR("")); } _if_result_458; }); + el_val_t ag_session_preload = ({ el_val_t _if_result_505 = 0; if ((agentic_hist_len == 0)) { el_val_t ag_profile_nodes = engram_search_json(EL_STR("Persona soul:persona identity principal"), 8); el_val_t ag_profile_ok = (!str_eq(ag_profile_nodes, EL_STR("")) && !str_eq(ag_profile_nodes, EL_STR("[]"))); el_val_t ag_profile_nodes2 = ({ el_val_t _if_result_506 = 0; if (ag_profile_ok) { _if_result_506 = (ag_profile_nodes); } else { _if_result_506 = (engram_search_json(EL_STR("user profile preferences name"), 8)); } _if_result_506; }); el_val_t ag_work_nodes = engram_search_json(EL_STR("WorkItem status:in_progress active work"), 6); el_val_t ag_work_ok = (!str_eq(ag_work_nodes, EL_STR("")) && !str_eq(ag_work_nodes, EL_STR("[]"))); el_val_t ag_work_nodes2 = ({ el_val_t _if_result_507 = 0; if (ag_work_ok) { _if_result_507 = (ag_work_nodes); } else { _if_result_507 = (engram_search_json(EL_STR("active project task current in_progress"), 6)); } _if_result_507; }); el_val_t ag_continuity_nodes = engram_search_json(EL_STR("last-session-topic session:emotional-summary conv:history last session"), 3); el_val_t ag_continuity_ok = (!str_eq(ag_continuity_nodes, EL_STR("")) && !str_eq(ag_continuity_nodes, EL_STR("[]"))); el_val_t ag_continuity_snip = ({ el_val_t _if_result_508 = 0; if (ag_continuity_ok) { el_val_t acn0 = json_array_get(ag_continuity_nodes, 0); el_val_t acc = json_get(acn0, EL_STR("content")); _if_result_508 = (utf8_safe_slice(acc, 350)); } else { _if_result_508 = (EL_STR("")); } _if_result_508; }); el_val_t ag_profile_bullets = session_preload_bullets(ag_profile_nodes2, 8, 350); el_val_t ag_work_bullets = session_preload_bullets(ag_work_nodes2, 6, 350); el_val_t ag_has_profile = !str_eq(ag_profile_bullets, EL_STR("")); el_val_t ag_has_work = !str_eq(ag_work_bullets, EL_STR("")); el_val_t ag_has_cont = !str_eq(ag_continuity_snip, EL_STR("")); _if_result_505 = (({ el_val_t _if_result_509 = 0; if (((ag_has_profile || ag_has_work) || ag_has_cont)) { el_val_t p = ({ el_val_t _if_result_510 = 0; if (ag_has_profile) { _if_result_510 = (el_str_concat(el_str_concat(EL_STR("[USER CONTEXT \xe2\x80\x94 from memory]\n"), ag_profile_bullets), EL_STR("\n\n"))); } else { _if_result_510 = (EL_STR("")); } _if_result_510; }); el_val_t w = ({ el_val_t _if_result_511 = 0; if (ag_has_work) { _if_result_511 = (el_str_concat(el_str_concat(EL_STR("[ACTIVE WORK \xe2\x80\x94 from memory]\n"), ag_work_bullets), EL_STR("\n\n"))); } else { _if_result_511 = (EL_STR("")); } _if_result_511; }); el_val_t c = ({ el_val_t _if_result_512 = 0; if (ag_has_cont) { _if_result_512 = (el_str_concat(el_str_concat(EL_STR("[CONTINUING FROM LAST SESSION]\n"), ag_continuity_snip), EL_STR("\n\n"))); } else { _if_result_512 = (EL_STR("")); } _if_result_512; }); _if_result_509 = (el_str_concat(el_str_concat(el_str_concat(EL_STR("\n\n"), p), w), c)); } else { _if_result_509 = (EL_STR("")); } _if_result_509; })); } else { _if_result_505 = (EL_STR("")); } _if_result_505; }); el_val_t system = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(identity, bounded_persona_floor()), EL_STR(" You have access to tools: read files, write files, browse the web, search your memory, run commands. Use them when they add genuine value. Be direct.\n\n")), ctx), ag_session_preload), receipt_rule()); el_val_t api_key = agentic_api_key(); - el_val_t tools_json = agentic_tools_all(); + el_val_t tools_lane_openai = (!str_eq(llm_base_url(), EL_STR("")) && str_eq(llm_wire_format(), EL_STR("openai"))); + el_val_t tools_json = ({ el_val_t _if_result_513 = 0; if (tools_lane_openai) { _if_result_513 = (agentic_tools_no_web()); } else { _if_result_513 = (agentic_tools_all()); } _if_result_513; }); el_val_t safe_msg = json_safe(message); el_val_t safe_sys = json_safe(system); el_val_t img_b64 = json_get(body, EL_STR("image")); el_val_t img_mt_raw = json_get(body, EL_STR("image_media_type")); - el_val_t img_mt = ({ el_val_t _if_result_467 = 0; if (str_eq(img_mt_raw, EL_STR(""))) { _if_result_467 = (EL_STR("image/png")); } else { _if_result_467 = (img_mt_raw); } _if_result_467; }); - el_val_t cur_user_content = ({ el_val_t _if_result_468 = 0; if (str_eq(img_b64, EL_STR(""))) { _if_result_468 = (el_str_concat(el_str_concat(EL_STR("\""), safe_msg), EL_STR("\""))); } else { _if_result_468 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("[{\"type\":\"text\",\"text\":\""), safe_msg), EL_STR("\"},{\"type\":\"image\",\"source\":{\"type\":\"base64\",\"media_type\":\"")), img_mt), EL_STR("\",\"data\":\"")), img_b64), EL_STR("\"}}]"))); } _if_result_468; }); - el_val_t prior_messages = ({ el_val_t _if_result_469 = 0; if ((agentic_hist_len > 0)) { el_val_t inner = str_slice(agentic_hist, 1, (str_len(agentic_hist) - 1)); _if_result_469 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",{\"role\":\"user\",\"content\":")), cur_user_content), EL_STR("}]"))); } else { _if_result_469 = (el_str_concat(el_str_concat(EL_STR("[{\"role\":\"user\",\"content\":"), cur_user_content), EL_STR("}]"))); } _if_result_469; }); + el_val_t img_mt = ({ el_val_t _if_result_514 = 0; if (str_eq(img_mt_raw, EL_STR(""))) { _if_result_514 = (EL_STR("image/png")); } else { _if_result_514 = (img_mt_raw); } _if_result_514; }); + el_val_t cur_user_content = ({ el_val_t _if_result_515 = 0; if (str_eq(img_b64, EL_STR(""))) { _if_result_515 = (el_str_concat(el_str_concat(EL_STR("\""), safe_msg), EL_STR("\""))); } else { _if_result_515 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("[{\"type\":\"text\",\"text\":\""), safe_msg), EL_STR("\"},{\"type\":\"image\",\"source\":{\"type\":\"base64\",\"media_type\":\"")), img_mt), EL_STR("\",\"data\":\"")), img_b64), EL_STR("\"}}]"))); } _if_result_515; }); + el_val_t prior_messages = ({ el_val_t _if_result_516 = 0; if ((agentic_hist_len > 0)) { el_val_t inner = str_slice(agentic_hist, 1, (str_len(agentic_hist) - 1)); _if_result_516 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",{\"role\":\"user\",\"content\":")), cur_user_content), EL_STR("}]"))); } else { _if_result_516 = (el_str_concat(el_str_concat(EL_STR("[{\"role\":\"user\",\"content\":"), cur_user_content), EL_STR("}]"))); } _if_result_516; }); el_val_t messages = prior_messages; el_val_t api_url = EL_STR("https://api.anthropic.com/v1/messages"); el_val_t h = el_map_new(0); map_set(h, EL_STR("x-api-key"), api_key); map_set(h, EL_STR("anthropic-version"), EL_STR("2023-06-01")); map_set(h, EL_STR("content-type"), EL_STR("application/json")); - el_val_t session_id = ({ el_val_t _if_result_470 = 0; if (str_eq(req_session, EL_STR(""))) { _if_result_470 = (next_bridge_id()); } else { _if_result_470 = (req_session); } _if_result_470; }); + el_val_t session_id = ({ el_val_t _if_result_517 = 0; if (str_eq(req_session, EL_STR(""))) { _if_result_517 = (next_bridge_id()); } else { _if_result_517 = (req_session); } _if_result_517; }); el_val_t req_ask_all = json_get(body, EL_STR("require_approval")); - state_set(el_str_concat(EL_STR("require_approval_"), session_id), ({ el_val_t _if_result_471 = 0; if (str_eq(req_ask_all, EL_STR("true"))) { _if_result_471 = (EL_STR("true")); } else { _if_result_471 = (EL_STR("")); } _if_result_471; })); - el_val_t use_openai = (!str_eq(llm_base_url(), EL_STR("")) && str_eq(llm_wire_format(), EL_STR("openai"))); - el_val_t result = ({ el_val_t _if_result_472 = 0; if (use_openai) { _if_result_472 = (openai_chat_complete(model, llm_base_url(), agentic_api_key(), safe_sys, messages)); } else { _if_result_472 = (agentic_loop(session_id, model, safe_sys, tools_json, messages, h, EL_STR(""))); } _if_result_472; }); + state_set(el_str_concat(EL_STR("require_approval_"), session_id), ({ el_val_t _if_result_518 = 0; if (str_eq(req_ask_all, EL_STR("true"))) { _if_result_518 = (EL_STR("true")); } else { _if_result_518 = (EL_STR("")); } _if_result_518; })); + el_val_t use_openai = tools_lane_openai; + el_val_t result = ({ el_val_t _if_result_519 = 0; if (use_openai) { _if_result_519 = (openai_agentic_loop(session_id, model, safe_sys, tools_json, messages, EL_STR(""))); } else { _if_result_519 = (agentic_loop(session_id, model, safe_sys, tools_json, messages, h, EL_STR(""))); } _if_result_519; }); el_val_t reply_text = json_get(result, EL_STR("reply")); el_val_t turn_tools = json_get_raw(result, EL_STR("tools_used")); el_val_t turn_sources = json_get(result, EL_STR("sources")); el_val_t turn_receipt = tool_receipt(turn_tools, turn_sources); el_val_t record_turn = (!str_eq(reply_text, EL_STR("")) && !is_utility_request(body, req_session)); - el_val_t discard_hist = ({ el_val_t _if_result_473 = 0; if (record_turn) { el_val_t updated = hist_append(agentic_hist, EL_STR("user"), message); el_val_t updated2 = hist_append(updated, EL_STR("assistant"), el_str_concat(reply_text, turn_receipt)); el_val_t trimmed = ({ el_val_t _if_result_474 = 0; if ((json_array_len(updated2) > 40)) { _if_result_474 = (hist_trim(updated2)); } else { _if_result_474 = (updated2); } _if_result_474; }); (void)(state_set(hist_key, trimmed)); (void)(conv_history_persist(req_session, trimmed)); _if_result_473 = (1); } else { _if_result_473 = (0); } _if_result_473; }); + el_val_t discard_hist = ({ el_val_t _if_result_520 = 0; if (record_turn) { el_val_t updated = hist_append(agentic_hist, EL_STR("user"), message); el_val_t updated2 = hist_append(updated, EL_STR("assistant"), el_str_concat(reply_text, turn_receipt)); el_val_t trimmed = ({ el_val_t _if_result_521 = 0; if ((json_array_len(updated2) > 40)) { _if_result_521 = (hist_trim(updated2)); } else { _if_result_521 = (updated2); } _if_result_521; }); (void)(state_set(hist_key, trimmed)); (void)(conv_history_persist(req_session, trimmed)); _if_result_520 = (1); } else { _if_result_520 = (0); } _if_result_520; }); return result; return 0; } @@ -28825,40 +29036,40 @@ el_val_t agentic_loop(el_val_t session_id, el_val_t model, el_val_t safe_sys, el state_set(el_str_concat(EL_STR("run_progress_"), session_id), EL_STR("")); } while (keep_going && (iteration < 12)) { - el_val_t cont_frag = ({ el_val_t _if_result_475 = 0; if (str_eq(container_id, EL_STR(""))) { _if_result_475 = (EL_STR("")); } else { _if_result_475 = (el_str_concat(el_str_concat(EL_STR(",\"container\":\""), container_id), EL_STR("\""))); } _if_result_475; }); + el_val_t cont_frag = ({ el_val_t _if_result_522 = 0; if (str_eq(container_id, EL_STR(""))) { _if_result_522 = (EL_STR("")); } else { _if_result_522 = (el_str_concat(el_str_concat(EL_STR(",\"container\":\""), container_id), EL_STR("\""))); } _if_result_522; }); el_val_t req_body = 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("{\"model\":\""), model), EL_STR("\"")), cont_frag), EL_STR(",\"max_tokens\":16384")), EL_STR(",\"tool_choice\":{\"type\":\"auto\",\"disable_parallel_tool_use\":true}")), EL_STR(",\"system\":\"")), safe_sys), EL_STR("\"")), EL_STR(",\"tools\":")), tools_eff), EL_STR(",\"messages\":")), messages), EL_STR("}")); if (!str_eq(session_id, EL_STR(""))) { el_val_t start_key = el_str_concat(EL_STR("run_progress_"), session_id); el_val_t start_prev = state_get(start_key); el_val_t start_entry = el_str_concat(el_str_concat(EL_STR("{\"i\":"), int_to_str(iteration)), EL_STR(",\"t\":\"\",\"tool\":\"__working__\"}")); - el_val_t start_next = ({ el_val_t _if_result_476 = 0; if (str_eq(start_prev, EL_STR(""))) { _if_result_476 = (start_entry); } else { _if_result_476 = (el_str_concat(el_str_concat(start_prev, EL_STR(",")), start_entry)); } _if_result_476; }); + el_val_t start_next = ({ el_val_t _if_result_523 = 0; if (str_eq(start_prev, EL_STR(""))) { _if_result_523 = (start_entry); } else { _if_result_523 = (el_str_concat(el_str_concat(start_prev, EL_STR(",")), start_entry)); } _if_result_523; }); state_set(start_key, start_next); } el_val_t raw_resp = http_post_with_headers(api_url, req_body, h); el_val_t is_error = ((str_starts_with(raw_resp, EL_STR("{\"error\"")) || str_starts_with(raw_resp, EL_STR("{\"type\":\"error\""))) || str_contains(raw_resp, EL_STR("authentication_error"))); - el_val_t ws_pos = ({ el_val_t _if_result_477 = 0; if (is_error) { _if_result_477 = (str_index_of(tools_eff, EL_STR("\"type\":\"web_search_"))); } else { _if_result_477 = ((0 - 1)); } _if_result_477; }); - el_val_t ws_rest = ({ el_val_t _if_result_478 = 0; if ((ws_pos >= 0)) { _if_result_478 = (str_slice(tools_eff, (ws_pos + 8), str_len(tools_eff))); } else { _if_result_478 = (EL_STR("")); } _if_result_478; }); - el_val_t ws_vend = ({ el_val_t _if_result_479 = 0; if ((ws_pos >= 0)) { _if_result_479 = (str_index_of(ws_rest, EL_STR("\""))); } else { _if_result_479 = ((0 - 1)); } _if_result_479; }); - el_val_t ws_cur = ({ el_val_t _if_result_480 = 0; if ((ws_vend > 0)) { _if_result_480 = (str_slice(ws_rest, 0, ws_vend)); } else { _if_result_480 = (EL_STR("")); } _if_result_480; }); + el_val_t ws_pos = ({ el_val_t _if_result_524 = 0; if (is_error) { _if_result_524 = (str_index_of(tools_eff, EL_STR("\"type\":\"web_search_"))); } else { _if_result_524 = ((0 - 1)); } _if_result_524; }); + el_val_t ws_rest = ({ el_val_t _if_result_525 = 0; if ((ws_pos >= 0)) { _if_result_525 = (str_slice(tools_eff, (ws_pos + 8), str_len(tools_eff))); } else { _if_result_525 = (EL_STR("")); } _if_result_525; }); + el_val_t ws_vend = ({ el_val_t _if_result_526 = 0; if ((ws_pos >= 0)) { _if_result_526 = (str_index_of(ws_rest, EL_STR("\""))); } else { _if_result_526 = ((0 - 1)); } _if_result_526; }); + el_val_t ws_cur = ({ el_val_t _if_result_527 = 0; if ((ws_vend > 0)) { _if_result_527 = (str_slice(ws_rest, 0, ws_vend)); } else { _if_result_527 = (EL_STR("")); } _if_result_527; }); el_val_t ws_conflict = str_contains(raw_resp, EL_STR("programmatic tool calling")); el_val_t can_fallback = ((((((is_error && !ws_drift) && (ws_pos >= 0)) && (ws_vend > 0)) && !str_eq(ws_cur, EL_STR(""))) && !str_eq(ws_cur, EL_STR("web_search_20250305"))) && (str_contains(raw_resp, ws_cur) || ws_conflict)); - tools_eff = ({ el_val_t _if_result_481 = 0; if (can_fallback) { _if_result_481 = (el_str_concat(el_str_concat(str_slice(tools_eff, 0, (ws_pos + 8)), EL_STR("web_search_20250305")), str_slice(ws_rest, ws_vend, str_len(ws_rest)))); } else { _if_result_481 = (tools_eff); } _if_result_481; }); - ws_drift = ({ el_val_t _if_result_482 = 0; if (can_fallback) { _if_result_482 = (1); } else { _if_result_482 = (ws_drift); } _if_result_482; }); + tools_eff = ({ el_val_t _if_result_528 = 0; if (can_fallback) { _if_result_528 = (el_str_concat(el_str_concat(str_slice(tools_eff, 0, (ws_pos + 8)), EL_STR("web_search_20250305")), str_slice(ws_rest, ws_vend, str_len(ws_rest)))); } else { _if_result_528 = (tools_eff); } _if_result_528; }); + ws_drift = ({ el_val_t _if_result_529 = 0; if (can_fallback) { _if_result_529 = (1); } else { _if_result_529 = (ws_drift); } _if_result_529; }); if (can_fallback) { println(el_str_concat(el_str_concat(EL_STR("[soul] DRIFT: web_search variant '"), ws_cur), EL_STR("' rejected by API - fell back to web_search_20250305"))); state_set(EL_STR("web_search_version_drift"), ws_cur); } if (is_error && !can_fallback) { - el_val_t err_head = ({ el_val_t _if_result_483 = 0; if ((str_len(raw_resp) > 220)) { _if_result_483 = (str_slice(raw_resp, 0, 220)); } else { _if_result_483 = (raw_resp); } _if_result_483; }); + el_val_t err_head = ({ el_val_t _if_result_530 = 0; if ((str_len(raw_resp) > 220)) { _if_result_530 = (str_slice(raw_resp, 0, 220)); } else { _if_result_530 = (raw_resp); } _if_result_530; }); println(el_str_concat(EL_STR("[soul] llm error: "), err_head)); return EL_STR("{\"error\":\"llm unavailable\",\"reply\":\"\"}"); } el_val_t stop_reason = json_get(raw_resp, EL_STR("stop_reason")); el_val_t cont_raw = json_get_raw(raw_resp, EL_STR("container")); - el_val_t cont_id_new = ({ el_val_t _if_result_484 = 0; if ((!str_eq(cont_raw, EL_STR("")) && !str_eq(cont_raw, EL_STR("null")))) { _if_result_484 = (json_get(cont_raw, EL_STR("id"))); } else { _if_result_484 = (EL_STR("")); } _if_result_484; }); - container_id = ({ el_val_t _if_result_485 = 0; if (!str_eq(cont_id_new, EL_STR(""))) { _if_result_485 = (cont_id_new); } else { _if_result_485 = (container_id); } _if_result_485; }); + el_val_t cont_id_new = ({ el_val_t _if_result_531 = 0; if ((!str_eq(cont_raw, EL_STR("")) && !str_eq(cont_raw, EL_STR("null")))) { _if_result_531 = (json_get(cont_raw, EL_STR("id"))); } else { _if_result_531 = (EL_STR("")); } _if_result_531; }); + container_id = ({ el_val_t _if_result_532 = 0; if (!str_eq(cont_id_new, EL_STR(""))) { _if_result_532 = (cont_id_new); } else { _if_result_532 = (container_id); } _if_result_532; }); el_val_t content_arr = json_get_raw(raw_resp, EL_STR("content")); - el_val_t eff_content = ({ el_val_t _if_result_486 = 0; if (str_eq(content_arr, EL_STR(""))) { _if_result_486 = (EL_STR("[]")); } else { _if_result_486 = (content_arr); } _if_result_486; }); + el_val_t eff_content = ({ el_val_t _if_result_533 = 0; if (str_eq(content_arr, EL_STR(""))) { _if_result_533 = (EL_STR("[]")); } else { _if_result_533 = (content_arr); } _if_result_533; }); el_val_t text_out = EL_STR(""); el_val_t has_tool = 0; el_val_t tool_id = EL_STR(""); @@ -28874,21 +29085,21 @@ el_val_t agentic_loop(el_val_t session_id, el_val_t model, el_val_t safe_sys, el el_val_t cit_raw = json_get_raw(block, EL_STR("citations")); el_val_t has_cit = (!str_eq(cit_raw, EL_STR("")) && !str_eq(cit_raw, EL_STR("null"))); el_val_t btype_scan = json_get(block, EL_STR("type")); - el_val_t btype = ({ el_val_t _if_result_487 = 0; if (has_cit) { _if_result_487 = (EL_STR("text")); } else { _if_result_487 = (btype_scan); } _if_result_487; }); + el_val_t btype = ({ el_val_t _if_result_534 = 0; if (has_cit) { _if_result_534 = (EL_STR("text")); } else { _if_result_534 = (btype_scan); } _if_result_534; }); el_val_t is_text = str_eq(btype, EL_STR("text")); - el_val_t btext = ({ el_val_t _if_result_488 = 0; if (is_text) { _if_result_488 = (json_get(block, EL_STR("text"))); } else { _if_result_488 = (EL_STR("")); } _if_result_488; }); - text_out = ({ el_val_t _if_result_489 = 0; if (is_text) { _if_result_489 = (el_str_concat(el_str_concat(text_out, text_join_sep(text_out, btext, saw_nontext)), btext)); } else { _if_result_489 = (text_out); } _if_result_489; }); - saw_nontext = ({ el_val_t _if_result_490 = 0; if (is_text) { _if_result_490 = (0); } else { _if_result_490 = (1); } _if_result_490; }); + el_val_t btext = ({ el_val_t _if_result_535 = 0; if (is_text) { _if_result_535 = (json_get(block, EL_STR("text"))); } else { _if_result_535 = (EL_STR("")); } _if_result_535; }); + text_out = ({ el_val_t _if_result_536 = 0; if (is_text) { _if_result_536 = (el_str_concat(el_str_concat(text_out, text_join_sep(text_out, btext, saw_nontext)), btext)); } else { _if_result_536 = (text_out); } _if_result_536; }); + saw_nontext = ({ el_val_t _if_result_537 = 0; if (is_text) { _if_result_537 = (0); } else { _if_result_537 = (1); } _if_result_537; }); src_log = provenance_add_sources(block, btype, has_cit, cit_raw, src_log); el_val_t is_srv = str_eq(btype, EL_STR("server_tool_use")); - el_val_t srv_name_raw = ({ el_val_t _if_result_491 = 0; if (is_srv) { _if_result_491 = (json_get(block, EL_STR("name"))); } else { _if_result_491 = (EL_STR("")); } _if_result_491; }); - el_val_t srv_name = ({ el_val_t _if_result_492 = 0; if ((is_srv && str_eq(srv_name_raw, EL_STR("")))) { _if_result_492 = (EL_STR("server_tool")); } else { _if_result_492 = (srv_name_raw); } _if_result_492; }); - srv_log = ({ el_val_t _if_result_493 = 0; if (is_srv) { _if_result_493 = (({ el_val_t _if_result_494 = 0; if (str_eq(srv_log, EL_STR(""))) { _if_result_494 = (el_str_concat(el_str_concat(EL_STR("\""), srv_name), EL_STR("\""))); } else { _if_result_494 = (el_str_concat(el_str_concat(el_str_concat(srv_log, EL_STR(",\"")), srv_name), EL_STR("\""))); } _if_result_494; })); } else { _if_result_493 = (srv_log); } _if_result_493; }); + el_val_t srv_name_raw = ({ el_val_t _if_result_538 = 0; if (is_srv) { _if_result_538 = (json_get(block, EL_STR("name"))); } else { _if_result_538 = (EL_STR("")); } _if_result_538; }); + el_val_t srv_name = ({ el_val_t _if_result_539 = 0; if ((is_srv && str_eq(srv_name_raw, EL_STR("")))) { _if_result_539 = (EL_STR("server_tool")); } else { _if_result_539 = (srv_name_raw); } _if_result_539; }); + srv_log = ({ el_val_t _if_result_540 = 0; if (is_srv) { _if_result_540 = (({ el_val_t _if_result_541 = 0; if (str_eq(srv_log, EL_STR(""))) { _if_result_541 = (el_str_concat(el_str_concat(EL_STR("\""), srv_name), EL_STR("\""))); } else { _if_result_541 = (el_str_concat(el_str_concat(el_str_concat(srv_log, EL_STR(",\"")), srv_name), EL_STR("\""))); } _if_result_541; })); } else { _if_result_540 = (srv_log); } _if_result_540; }); el_val_t is_new_tool = (str_eq(btype, EL_STR("tool_use")) && !has_tool); - has_tool = ({ el_val_t _if_result_495 = 0; if (is_new_tool) { _if_result_495 = (1); } else { _if_result_495 = (has_tool); } _if_result_495; }); - tool_id = ({ el_val_t _if_result_496 = 0; if (is_new_tool) { _if_result_496 = (json_get(block, EL_STR("id"))); } else { _if_result_496 = (tool_id); } _if_result_496; }); - tool_name = ({ el_val_t _if_result_497 = 0; if (is_new_tool) { _if_result_497 = (json_get(block, EL_STR("name"))); } else { _if_result_497 = (tool_name); } _if_result_497; }); - tool_input = ({ el_val_t _if_result_498 = 0; if (is_new_tool) { _if_result_498 = (json_get_raw(block, EL_STR("input"))); } else { _if_result_498 = (tool_input); } _if_result_498; }); + has_tool = ({ el_val_t _if_result_542 = 0; if (is_new_tool) { _if_result_542 = (1); } else { _if_result_542 = (has_tool); } _if_result_542; }); + tool_id = ({ el_val_t _if_result_543 = 0; if (is_new_tool) { _if_result_543 = (json_get(block, EL_STR("id"))); } else { _if_result_543 = (tool_id); } _if_result_543; }); + tool_name = ({ el_val_t _if_result_544 = 0; if (is_new_tool) { _if_result_544 = (json_get(block, EL_STR("name"))); } else { _if_result_544 = (tool_name); } _if_result_544; }); + tool_input = ({ el_val_t _if_result_545 = 0; if (is_new_tool) { _if_result_545 = (json_get_raw(block, EL_STR("input"))); } else { _if_result_545 = (tool_input); } _if_result_545; }); ci = (ci + 1); } el_val_t is_tool_turn = (str_eq(stop_reason, EL_STR("tool_use")) && has_tool); @@ -28897,72 +29108,72 @@ el_val_t agentic_loop(el_val_t session_id, el_val_t model, el_val_t safe_sys, el println(el_str_concat(EL_STR("[soul] DRIFT: unknown stop_reason from API: "), stop_reason)); } el_val_t always_key = el_str_concat(EL_STR("always_allow_"), session_id); - el_val_t always_list = ({ el_val_t _if_result_499 = 0; if (!str_eq(session_id, EL_STR(""))) { _if_result_499 = (state_get(always_key)); } else { _if_result_499 = (EL_STR("")); } _if_result_499; }); + el_val_t always_list = ({ el_val_t _if_result_546 = 0; if (!str_eq(session_id, EL_STR(""))) { _if_result_546 = (state_get(always_key)); } else { _if_result_546 = (EL_STR("")); } _if_result_546; }); el_val_t is_always_allowed = ((!str_eq(tool_name, EL_STR("")) && !str_eq(always_list, EL_STR(""))) && str_contains(always_list, tool_name)); - el_val_t risk_tier = ({ el_val_t _if_result_500 = 0; if (is_tool_turn) { _if_result_500 = (classify_tool_risk(tool_name, tool_input)); } else { _if_result_500 = (EL_STR("")); } _if_result_500; }); + el_val_t risk_tier = ({ el_val_t _if_result_547 = 0; if (is_tool_turn) { _if_result_547 = (classify_tool_risk(tool_name, tool_input)); } else { _if_result_547 = (EL_STR("")); } _if_result_547; }); el_val_t needs_bridge = (is_tool_turn && ((ask_all || str_eq(risk_tier, EL_STR("escalate"))) || (!is_builtin_tool(tool_name) && !is_always_allowed))); - el_val_t tool_result_raw = ({ el_val_t _if_result_501 = 0; if ((is_tool_turn && !needs_bridge)) { _if_result_501 = (dispatch_tool(tool_name, tool_input)); } else { _if_result_501 = (EL_STR("")); } _if_result_501; }); - el_val_t tool_result = ({ el_val_t _if_result_502 = 0; if ((str_len(tool_result_raw) > 6000)) { _if_result_502 = (el_str_concat(str_slice(tool_result_raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_502 = (tool_result_raw); } _if_result_502; }); + el_val_t tool_result_raw = ({ el_val_t _if_result_548 = 0; if ((is_tool_turn && !needs_bridge)) { _if_result_548 = (dispatch_tool(tool_name, tool_input)); } else { _if_result_548 = (EL_STR("")); } _if_result_548; }); + el_val_t tool_result = ({ el_val_t _if_result_549 = 0; if ((str_len(tool_result_raw) > 6000)) { _if_result_549 = (el_str_concat(str_slice(tool_result_raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_549 = (tool_result_raw); } _if_result_549; }); el_val_t tool_msg = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"type\":\"tool_result\",\"tool_use_id\":\""), tool_id), EL_STR("\",\"content\":\"")), tool_result), EL_STR("\"}")); el_val_t tool_quoted = el_str_concat(el_str_concat(EL_STR("\""), tool_name), EL_STR("\"")); - tools_log = ({ el_val_t _if_result_503 = 0; if (is_tool_turn) { _if_result_503 = (({ el_val_t _if_result_504 = 0; if (str_eq(tools_log, EL_STR(""))) { _if_result_504 = (tool_quoted); } else { _if_result_504 = (el_str_concat(el_str_concat(tools_log, EL_STR(",")), tool_quoted)); } _if_result_504; })); } else { _if_result_503 = (tools_log); } _if_result_503; }); - tools_log = ({ el_val_t _if_result_505 = 0; if (str_eq(srv_log, EL_STR(""))) { _if_result_505 = (tools_log); } else { _if_result_505 = (({ el_val_t _if_result_506 = 0; if (str_eq(tools_log, EL_STR(""))) { _if_result_506 = (srv_log); } else { _if_result_506 = (el_str_concat(el_str_concat(tools_log, EL_STR(",")), srv_log)); } _if_result_506; })); } _if_result_505; }); - sources_all = ({ el_val_t _if_result_507 = 0; if (str_eq(src_log, EL_STR(""))) { _if_result_507 = (sources_all); } else { _if_result_507 = (({ el_val_t _if_result_508 = 0; if (str_eq(sources_all, EL_STR(""))) { _if_result_508 = (src_log); } else { _if_result_508 = (el_str_concat(el_str_concat(sources_all, EL_STR("; ")), src_log)); } _if_result_508; })); } _if_result_507; }); + tools_log = ({ el_val_t _if_result_550 = 0; if (is_tool_turn) { _if_result_550 = (({ el_val_t _if_result_551 = 0; if (str_eq(tools_log, EL_STR(""))) { _if_result_551 = (tool_quoted); } else { _if_result_551 = (el_str_concat(el_str_concat(tools_log, EL_STR(",")), tool_quoted)); } _if_result_551; })); } else { _if_result_550 = (tools_log); } _if_result_550; }); + tools_log = ({ el_val_t _if_result_552 = 0; if (str_eq(srv_log, EL_STR(""))) { _if_result_552 = (tools_log); } else { _if_result_552 = (({ el_val_t _if_result_553 = 0; if (str_eq(tools_log, EL_STR(""))) { _if_result_553 = (srv_log); } else { _if_result_553 = (el_str_concat(el_str_concat(tools_log, EL_STR(",")), srv_log)); } _if_result_553; })); } _if_result_552; }); + sources_all = ({ el_val_t _if_result_554 = 0; if (str_eq(src_log, EL_STR(""))) { _if_result_554 = (sources_all); } else { _if_result_554 = (({ el_val_t _if_result_555 = 0; if (str_eq(sources_all, EL_STR(""))) { _if_result_555 = (src_log); } else { _if_result_555 = (el_str_concat(el_str_concat(sources_all, EL_STR("; ")), src_log)); } _if_result_555; })); } _if_result_554; }); el_val_t inner = str_slice(messages, 1, (str_len(messages) - 1)); el_val_t messages_with_assistant = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",{\"role\":\"assistant\",\"content\":")), eff_content), EL_STR("}")), EL_STR("]")); el_val_t local_continue = (is_tool_turn && !needs_bridge); el_val_t is_pause_resume = (is_pause && !needs_bridge); - messages = ({ el_val_t _if_result_509 = 0; if (local_continue) { el_val_t inner2 = str_slice(messages_with_assistant, 1, (str_len(messages_with_assistant) - 1)); _if_result_509 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner2), EL_STR(",{\"role\":\"user\",\"content\":[")), tool_msg), EL_STR("]}]"))); } else { _if_result_509 = (({ el_val_t _if_result_510 = 0; if (is_pause_resume) { _if_result_510 = (messages_with_assistant); } else { _if_result_510 = (messages); } _if_result_510; })); } _if_result_509; }); + messages = ({ el_val_t _if_result_556 = 0; if (local_continue) { el_val_t inner2 = str_slice(messages_with_assistant, 1, (str_len(messages_with_assistant) - 1)); _if_result_556 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner2), EL_STR(",{\"role\":\"user\",\"content\":[")), tool_msg), EL_STR("]}]"))); } else { _if_result_556 = (({ el_val_t _if_result_557 = 0; if (is_pause_resume) { _if_result_557 = (messages_with_assistant); } else { _if_result_557 = (messages); } _if_result_557; })); } _if_result_556; }); if (!str_eq(session_id, EL_STR("")) && !can_fallback) { el_val_t prog_key = el_str_concat(EL_STR("run_progress_"), session_id); el_val_t prog_prev = state_get(prog_key); - el_val_t prog_snip = ({ el_val_t _if_result_511 = 0; if ((str_len(text_out) > 280)) { _if_result_511 = (str_slice(text_out, 0, 280)); } else { _if_result_511 = (text_out); } _if_result_511; }); + el_val_t prog_snip = ({ el_val_t _if_result_558 = 0; if ((str_len(text_out) > 280)) { _if_result_558 = (str_slice(text_out, 0, 280)); } else { _if_result_558 = (text_out); } _if_result_558; }); el_val_t prog_entry = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"i\":"), int_to_str(iteration)), EL_STR(",\"t\":\"")), json_safe(prog_snip)), EL_STR("\"")), EL_STR(",\"tool\":\"")), json_safe(tool_name)), EL_STR("\"}")); - el_val_t prog_next = ({ el_val_t _if_result_512 = 0; if (str_eq(prog_prev, EL_STR(""))) { _if_result_512 = (prog_entry); } else { _if_result_512 = (el_str_concat(el_str_concat(prog_prev, EL_STR(",")), prog_entry)); } _if_result_512; }); + el_val_t prog_next = ({ el_val_t _if_result_559 = 0; if (str_eq(prog_prev, EL_STR(""))) { _if_result_559 = (prog_entry); } else { _if_result_559 = (el_str_concat(el_str_concat(prog_prev, EL_STR(",")), prog_entry)); } _if_result_559; }); state_set(prog_key, prog_next); } - pending = ({ el_val_t _if_result_513 = 0; if (needs_bridge) { _if_result_513 = (1); } else { _if_result_513 = (pending); } _if_result_513; }); - pend_tool_id = ({ el_val_t _if_result_514 = 0; if (needs_bridge) { _if_result_514 = (tool_id); } else { _if_result_514 = (pend_tool_id); } _if_result_514; }); - pend_tool_name = ({ el_val_t _if_result_515 = 0; if (needs_bridge) { _if_result_515 = (tool_name); } else { _if_result_515 = (pend_tool_name); } _if_result_515; }); - pend_tool_input = ({ el_val_t _if_result_516 = 0; if (needs_bridge) { _if_result_516 = (tool_input); } else { _if_result_516 = (pend_tool_input); } _if_result_516; }); - pend_tool_tier = ({ el_val_t _if_result_517 = 0; if (needs_bridge) { _if_result_517 = (risk_tier); } else { _if_result_517 = (pend_tool_tier); } _if_result_517; }); - pend_narration = ({ el_val_t _if_result_518 = 0; if (needs_bridge) { _if_result_518 = (text_out); } else { _if_result_518 = (pend_narration); } _if_result_518; }); + pending = ({ el_val_t _if_result_560 = 0; if (needs_bridge) { _if_result_560 = (1); } else { _if_result_560 = (pending); } _if_result_560; }); + pend_tool_id = ({ el_val_t _if_result_561 = 0; if (needs_bridge) { _if_result_561 = (tool_id); } else { _if_result_561 = (pend_tool_id); } _if_result_561; }); + pend_tool_name = ({ el_val_t _if_result_562 = 0; if (needs_bridge) { _if_result_562 = (tool_name); } else { _if_result_562 = (pend_tool_name); } _if_result_562; }); + pend_tool_input = ({ el_val_t _if_result_563 = 0; if (needs_bridge) { _if_result_563 = (tool_input); } else { _if_result_563 = (pend_tool_input); } _if_result_563; }); + pend_tool_tier = ({ el_val_t _if_result_564 = 0; if (needs_bridge) { _if_result_564 = (risk_tier); } else { _if_result_564 = (pend_tool_tier); } _if_result_564; }); + pend_narration = ({ el_val_t _if_result_565 = 0; if (needs_bridge) { _if_result_565 = (text_out); } else { _if_result_565 = (pend_narration); } _if_result_565; }); if (needs_bridge) { - bridge_save(session_id, model, safe_sys, tools_json, messages_with_assistant, tools_log, pend_tool_id); + bridge_save(session_id, model, safe_sys, tools_json, messages_with_assistant, tools_log, pend_tool_id, EL_STR("anthropic")); } - final_text = ({ el_val_t _if_result_519 = 0; if ((!is_tool_turn && !can_fallback)) { _if_result_519 = (el_str_concat(el_str_concat(final_text, text_join_sep(final_text, text_out, 1)), text_out)); } else { _if_result_519 = (final_text); } _if_result_519; }); - final_text = ({ el_val_t _if_result_520 = 0; if ((str_eq(stop_reason, EL_STR("max_tokens")) && has_tool)) { _if_result_520 = (el_str_concat(final_text, EL_STR("\n\n[Output limit reached mid-action - the last planned action did not run. Ask me to continue to finish it.]"))); } else { _if_result_520 = (final_text); } _if_result_520; }); - keep_going = ({ el_val_t _if_result_521 = 0; if (((local_continue || is_pause_resume) || can_fallback)) { _if_result_521 = (keep_going); } else { _if_result_521 = (0); } _if_result_521; }); + final_text = ({ el_val_t _if_result_566 = 0; if ((!is_tool_turn && !can_fallback)) { _if_result_566 = (el_str_concat(el_str_concat(final_text, text_join_sep(final_text, text_out, 1)), text_out)); } else { _if_result_566 = (final_text); } _if_result_566; }); + final_text = ({ el_val_t _if_result_567 = 0; if ((str_eq(stop_reason, EL_STR("max_tokens")) && has_tool)) { _if_result_567 = (el_str_concat(final_text, EL_STR("\n\n[Output limit reached mid-action - the last planned action did not run. Ask me to continue to finish it.]"))); } else { _if_result_567 = (final_text); } _if_result_567; }); + keep_going = ({ el_val_t _if_result_568 = 0; if (((local_continue || is_pause_resume) || can_fallback)) { _if_result_568 = (keep_going); } else { _if_result_568 = (0); } _if_result_568; }); iteration = (iteration + 1); } if (pending) { - el_val_t safe_in = ({ el_val_t _if_result_522 = 0; if (str_eq(pend_tool_input, EL_STR(""))) { _if_result_522 = (EL_STR("{}")); } else { _if_result_522 = (pend_tool_input); } _if_result_522; }); - el_val_t tools_arr = ({ el_val_t _if_result_523 = 0; if (str_eq(tools_log, EL_STR(""))) { _if_result_523 = (EL_STR("[]")); } else { _if_result_523 = (el_str_concat(el_str_concat(EL_STR("["), tools_log), EL_STR("]"))); } _if_result_523; }); + el_val_t safe_in = ({ el_val_t _if_result_569 = 0; if (str_eq(pend_tool_input, EL_STR(""))) { _if_result_569 = (EL_STR("{}")); } else { _if_result_569 = (pend_tool_input); } _if_result_569; }); + el_val_t tools_arr = ({ el_val_t _if_result_570 = 0; if (str_eq(tools_log, EL_STR(""))) { _if_result_570 = (EL_STR("[]")); } else { _if_result_570 = (el_str_concat(el_str_concat(EL_STR("["), tools_log), EL_STR("]"))); } _if_result_570; }); return 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_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("{\"tool_pending\":true"), EL_STR(",\"session_id\":\"")), session_id), EL_STR("\"")), EL_STR(",\"call_id\":\"")), pend_tool_id), EL_STR("\"")), EL_STR(",\"tool_name\":\"")), pend_tool_name), EL_STR("\"")), EL_STR(",\"tool_input\":")), safe_in), EL_STR(",\"risk_tier\":\"")), pend_tool_tier), EL_STR("\"")), EL_STR(",\"narration\":\"")), json_safe(pend_narration)), EL_STR("\"")), EL_STR(",\"model\":\"")), model), EL_STR("\"")), EL_STR(",\"agentic\":true")), EL_STR(",\"sources\":\"")), json_safe(sources_all)), EL_STR("\"")), EL_STR(",\"tools_used\":")), tools_arr), EL_STR("}")); } final_text = receipt_strip(final_text); if (str_eq(final_text, EL_STR(""))) { el_val_t hit_cap = (iteration >= 12); - el_val_t err_msg = ({ el_val_t _if_result_524 = 0; if (hit_cap) { _if_result_524 = (EL_STR("agentic loop hit the 12-iteration cap without producing a final reply - task may be too complex or a tool call is looping")); } else { _if_result_524 = (EL_STR("no response")); } _if_result_524; }); + el_val_t err_msg = ({ el_val_t _if_result_571 = 0; if (hit_cap) { _if_result_571 = (EL_STR("agentic loop hit the 12-iteration cap without producing a final reply - task may be too complex or a tool call is looping")); } else { _if_result_571 = (EL_STR("no response")); } _if_result_571; }); return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"error\":\""), err_msg), EL_STR("\",\"reply\":\"\",\"iterations\":")), int_to_str(iteration)), EL_STR("}")); } el_val_t safe_text = json_safe(final_text); - el_val_t tools_arr = ({ el_val_t _if_result_525 = 0; if (str_eq(tools_log, EL_STR(""))) { _if_result_525 = (EL_STR("[]")); } else { _if_result_525 = (el_str_concat(el_str_concat(EL_STR("["), tools_log), EL_STR("]"))); } _if_result_525; }); + el_val_t tools_arr = ({ el_val_t _if_result_572 = 0; if (str_eq(tools_log, EL_STR(""))) { _if_result_572 = (EL_STR("[]")); } else { _if_result_572 = (el_str_concat(el_str_concat(EL_STR("["), tools_log), EL_STR("]"))); } _if_result_572; }); if (!str_eq(session_id, EL_STR(""))) { el_val_t done_key = el_str_concat(EL_STR("run_progress_"), session_id); el_val_t done_prev = state_get(done_key); - el_val_t done_next = ({ el_val_t _if_result_526 = 0; if (str_eq(done_prev, EL_STR(""))) { _if_result_526 = (EL_STR("{\"done\":true}")); } else { _if_result_526 = (el_str_concat(done_prev, EL_STR(",{\"done\":true}"))); } _if_result_526; }); + el_val_t done_next = ({ el_val_t _if_result_573 = 0; if (str_eq(done_prev, EL_STR(""))) { _if_result_573 = (EL_STR("{\"done\":true}")); } else { _if_result_573 = (el_str_concat(done_prev, EL_STR(",{\"done\":true}"))); } _if_result_573; }); state_set(done_key, done_next); } return 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("{\"reply\":\""), safe_text), EL_STR("\",\"model\":\"")), model), EL_STR("\",\"agentic\":true,\"tools_used\":")), tools_arr), EL_STR(",\"sources\":\"")), json_safe(sources_all)), EL_STR("\",\"iterations\":")), int_to_str(iteration)), EL_STR("}")); return 0; } -el_val_t bridge_save(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages, el_val_t tools_log, el_val_t tool_use_id) { +el_val_t bridge_save(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages, el_val_t tools_log, el_val_t tool_use_id, el_val_t wire) { if (str_eq(messages, EL_STR("")) || str_eq(tools_json, EL_STR(""))) { return 0; } - el_val_t blob = 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("{\"model\":\""), json_safe(model)), EL_STR("\"")), EL_STR(",\"safe_sys\":\"")), json_safe(safe_sys)), EL_STR("\"")), EL_STR(",\"tools_log\":\"")), json_safe(tools_log)), EL_STR("\"")), EL_STR(",\"tool_use_id\":\"")), json_safe(tool_use_id)), EL_STR("\"")), EL_STR(",\"tools_raw\":")), tools_json), EL_STR(",\"messages_raw\":")), messages), EL_STR("}")); + el_val_t blob = 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_concat(el_str_concat(EL_STR("{\"model\":\""), json_safe(model)), EL_STR("\"")), EL_STR(",\"safe_sys\":\"")), json_safe(safe_sys)), EL_STR("\"")), EL_STR(",\"tools_log\":\"")), json_safe(tools_log)), EL_STR("\"")), EL_STR(",\"tool_use_id\":\"")), json_safe(tool_use_id)), EL_STR("\"")), EL_STR(",\"wire\":\"")), json_safe(wire)), EL_STR("\"")), EL_STR(",\"tools_raw\":")), tools_json), EL_STR(",\"messages_raw\":")), messages), EL_STR("}")); state_set(el_str_concat(EL_STR("mcp_bridge:"), session_id), blob); return 1; return 0; @@ -28977,21 +29188,36 @@ el_val_t agentic_resume(el_val_t session_id, el_val_t tool_use_id, el_val_t cont el_val_t model = json_get(blob, EL_STR("model")); el_val_t safe_sys = json_get(blob, EL_STR("safe_sys")); el_val_t messages = json_get_raw(blob, EL_STR("messages_raw")); - messages = ({ el_val_t _if_result_527 = 0; if (str_eq(messages, EL_STR(""))) { _if_result_527 = (json_get(blob, EL_STR("messages"))); } else { _if_result_527 = (messages); } _if_result_527; }); + messages = ({ el_val_t _if_result_574 = 0; if (str_eq(messages, EL_STR(""))) { _if_result_574 = (json_get(blob, EL_STR("messages"))); } else { _if_result_574 = (messages); } _if_result_574; }); el_val_t tools_json = json_get_raw(blob, EL_STR("tools_raw")); - tools_json = ({ el_val_t _if_result_528 = 0; if (str_eq(tools_json, EL_STR(""))) { _if_result_528 = (json_get(blob, EL_STR("tools_json"))); } else { _if_result_528 = (tools_json); } _if_result_528; }); + tools_json = ({ el_val_t _if_result_575 = 0; if (str_eq(tools_json, EL_STR(""))) { _if_result_575 = (json_get(blob, EL_STR("tools_json"))); } else { _if_result_575 = (tools_json); } _if_result_575; }); if (str_eq(messages, EL_STR("")) || str_eq(tools_json, EL_STR(""))) { return EL_STR("{\"error\":\"corrupt bridge state\",\"reply\":\"\"}"); } el_val_t tools_log = json_get(blob, EL_STR("tools_log")); el_val_t saved_use_id = json_get(blob, EL_STR("tool_use_id")); - el_val_t eff_use_id = ({ el_val_t _if_result_529 = 0; if (str_eq(tool_use_id, EL_STR(""))) { _if_result_529 = (saved_use_id); } else { _if_result_529 = (tool_use_id); } _if_result_529; }); - el_val_t trimmed = ({ el_val_t _if_result_530 = 0; if ((str_len(content) > 6000)) { _if_result_530 = (el_str_concat(str_slice(content, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_530 = (content); } _if_result_530; }); + el_val_t eff_use_id = ({ el_val_t _if_result_576 = 0; if (str_eq(tool_use_id, EL_STR(""))) { _if_result_576 = (saved_use_id); } else { _if_result_576 = (tool_use_id); } _if_result_576; }); + el_val_t trimmed = ({ el_val_t _if_result_577 = 0; if ((str_len(content) > 6000)) { _if_result_577 = (el_str_concat(str_slice(content, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_577 = (content); } _if_result_577; }); el_val_t safe_result = json_safe(trimmed); - el_val_t tool_msg = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"type\":\"tool_result\",\"tool_use_id\":\""), eff_use_id), EL_STR("\",\"content\":\"")), safe_result), EL_STR("\"}")); el_val_t inner = str_slice(messages, 1, (str_len(messages) - 1)); - el_val_t resumed_messages = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",{\"role\":\"user\",\"content\":[")), tool_msg), EL_STR("]}]")); state_set(el_str_concat(EL_STR("mcp_bridge:"), session_id), EL_STR("")); + el_val_t i_traw = str_index_of(blob, EL_STR(",\"tools_raw\":")); + el_val_t i_tjson = str_index_of(blob, EL_STR(",\"tools_json\":")); + el_val_t i_mraw = str_index_of(blob, EL_STR(",\"messages_raw\":")); + el_val_t i_msgs = str_index_of(blob, EL_STR(",\"messages\":")); + el_val_t cut1 = ({ el_val_t _if_result_578 = 0; if ((i_traw > 0)) { _if_result_578 = (i_traw); } else { _if_result_578 = (str_len(blob)); } _if_result_578; }); + el_val_t cut2 = ({ el_val_t _if_result_579 = 0; if (((i_tjson > 0) && (i_tjson < cut1))) { _if_result_579 = (i_tjson); } else { _if_result_579 = (cut1); } _if_result_579; }); + el_val_t cut3 = ({ el_val_t _if_result_580 = 0; if (((i_mraw > 0) && (i_mraw < cut2))) { _if_result_580 = (i_mraw); } else { _if_result_580 = (cut2); } _if_result_580; }); + el_val_t cut = ({ el_val_t _if_result_581 = 0; if (((i_msgs > 0) && (i_msgs < cut3))) { _if_result_581 = (i_msgs); } else { _if_result_581 = (cut3); } _if_result_581; }); + el_val_t blob_head = str_slice(blob, 0, cut); + el_val_t wire = json_get(blob_head, EL_STR("wire")); + if (str_eq(wire, EL_STR("openai"))) { + el_val_t tool_msg_o = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"role\":\"tool\",\"tool_call_id\":\""), eff_use_id), EL_STR("\",\"content\":\"")), safe_result), EL_STR("\"}")); + el_val_t resumed_o = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",")), tool_msg_o), EL_STR("]")); + return openai_agentic_loop(session_id, model, safe_sys, tools_json, resumed_o, tools_log); + } + el_val_t tool_msg = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"type\":\"tool_result\",\"tool_use_id\":\""), eff_use_id), EL_STR("\",\"content\":\"")), safe_result), EL_STR("\"}")); + el_val_t resumed_messages = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",{\"role\":\"user\",\"content\":[")), tool_msg), EL_STR("]}]")); el_val_t api_key = agentic_api_key(); el_val_t h = el_map_new(0); map_set(h, EL_STR("x-api-key"), api_key); @@ -29022,12 +29248,12 @@ el_val_t handle_chat_as_soul(el_val_t body) { } el_val_t message = json_get(body, EL_STR("message")); el_val_t transcript = json_get(body, EL_STR("transcript")); - el_val_t eff_message = ({ el_val_t _if_result_531 = 0; if (str_eq(message, EL_STR(""))) { _if_result_531 = (transcript); } else { _if_result_531 = (message); } _if_result_531; }); + el_val_t eff_message = ({ el_val_t _if_result_582 = 0; if (str_eq(message, EL_STR(""))) { _if_result_582 = (transcript); } else { _if_result_582 = (message); } _if_result_582; }); if (str_eq(eff_message, EL_STR(""))) { return el_str_concat(el_str_concat(EL_STR("{\"error\":\"message or transcript is required\",\"response\":\"\",\"speaker_slug\":\""), speaker), EL_STR("\"}")); } el_val_t req_model = json_get(body, EL_STR("model")); - el_val_t model = ({ el_val_t _if_result_532 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_532 = (chat_default_model()); } else { _if_result_532 = (req_model); } _if_result_532; }); + el_val_t model = ({ el_val_t _if_result_583 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_583 = (chat_default_model()); } else { _if_result_583 = (req_model); } _if_result_583; }); system_prompt = safety_augment_system(system_prompt, eff_message); system_prompt = el_str_concat(system_prompt, bounded_persona_floor()); el_val_t raw_response = llm_call_system(model, system_prompt, eff_message); @@ -29051,7 +29277,7 @@ el_val_t handle_dharma_room_turn(el_val_t body) { return el_str_concat(el_str_concat(EL_STR("{\"error\":\"transcript is required\",\"response\":\"\",\"cgi_id\":\""), cgi_id), EL_STR("\"}")); } el_val_t engram_ctx = engram_compile(distill_transcript(transcript)); - el_val_t system_prompt = ({ el_val_t _if_result_533 = 0; if (str_eq(engram_ctx, EL_STR(""))) { _if_result_533 = (identity); } else { _if_result_533 = (el_str_concat(el_str_concat(identity, EL_STR("\n\n[RETRIEVED MEMORY \xe2\x80\x94 compiled from your graph for this turn]\n")), engram_ctx)); } _if_result_533; }); + el_val_t system_prompt = ({ el_val_t _if_result_584 = 0; if (str_eq(engram_ctx, EL_STR(""))) { _if_result_584 = (identity); } else { _if_result_584 = (el_str_concat(el_str_concat(identity, EL_STR("\n\n[RETRIEVED MEMORY \xe2\x80\x94 compiled from your graph for this turn]\n")), engram_ctx)); } _if_result_584; }); system_prompt = safety_augment_system(system_prompt, transcript); system_prompt = el_str_concat(system_prompt, bounded_persona_floor()); el_val_t raw_response = llm_call_system(model, system_prompt, transcript); @@ -29084,7 +29310,8 @@ el_val_t handle_dharma_room_turn_agentic(el_val_t body) { el_val_t system = el_str_concat(el_str_concat(el_str_concat(identity, bounded_persona_floor()), EL_STR(" You have access to tools: read files, write files, browse the web, search your memory, run commands. Use them when they add genuine value. Be direct and stay in character.\n\n")), ctx); el_val_t api_key = agentic_api_key(); system = safety_augment_system(system, transcript); - el_val_t tools_json = agentic_tools_all(); + el_val_t use_openai_d = (!str_eq(llm_base_url(), EL_STR("")) && str_eq(llm_wire_format(), EL_STR("openai"))); + el_val_t tools_json = ({ el_val_t _if_result_585 = 0; if (use_openai_d) { _if_result_585 = (agentic_tools_no_web()); } else { _if_result_585 = (agentic_tools_all()); } _if_result_585; }); el_val_t safe_transcript = json_safe(transcript); el_val_t safe_sys = json_safe(system); el_val_t messages = el_str_concat(el_str_concat(EL_STR("[{\"role\":\"user\",\"content\":\""), safe_transcript), EL_STR("\"}]")); @@ -29092,8 +29319,8 @@ el_val_t handle_dharma_room_turn_agentic(el_val_t body) { map_set(h, EL_STR("x-api-key"), api_key); map_set(h, EL_STR("anthropic-version"), EL_STR("2023-06-01")); map_set(h, EL_STR("content-type"), EL_STR("application/json")); - el_val_t session_id = ({ el_val_t _if_result_534 = 0; if (str_eq(room_id, EL_STR(""))) { _if_result_534 = (el_str_concat(EL_STR("dharma:"), next_bridge_id())); } else { _if_result_534 = (el_str_concat(EL_STR("dharma:"), room_id)); } _if_result_534; }); - el_val_t loop_result = agentic_loop(session_id, model, safe_sys, tools_json, messages, h, EL_STR("")); + el_val_t session_id = ({ el_val_t _if_result_586 = 0; if (str_eq(room_id, EL_STR(""))) { _if_result_586 = (el_str_concat(EL_STR("dharma:"), next_bridge_id())); } else { _if_result_586 = (el_str_concat(EL_STR("dharma:"), room_id)); } _if_result_586; }); + el_val_t loop_result = ({ el_val_t _if_result_587 = 0; if (use_openai_d) { _if_result_587 = (openai_agentic_loop(session_id, model, safe_sys, tools_json, messages, EL_STR(""))); } else { _if_result_587 = (agentic_loop(session_id, model, safe_sys, tools_json, messages, h, EL_STR(""))); } _if_result_587; }); el_val_t result_error = json_get(loop_result, EL_STR("error")); if (!str_eq(result_error, EL_STR(""))) { return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"error\":\""), result_error), EL_STR("\",\"response\":\"\",\"cgi_id\":\"")), cgi_id), EL_STR("\"}")); @@ -29107,7 +29334,7 @@ el_val_t handle_dharma_room_turn_agentic(el_val_t body) { return el_str_concat(el_str_concat(EL_STR("{\"error\":\"no response\",\"response\":\"\",\"cgi_id\":\""), cgi_id), EL_STR("\"}")); } el_val_t tools_arr = json_get_raw(loop_result, EL_STR("tools_used")); - el_val_t eff_tools = ({ el_val_t _if_result_535 = 0; if (str_eq(tools_arr, EL_STR(""))) { _if_result_535 = (EL_STR("[]")); } else { _if_result_535 = (tools_arr); } _if_result_535; }); + el_val_t eff_tools = ({ el_val_t _if_result_588 = 0; if (str_eq(tools_arr, EL_STR(""))) { _if_result_588 = (EL_STR("[]")); } else { _if_result_588 = (tools_arr); } _if_result_588; }); el_val_t safe_text = json_safe(final_text); return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"response\":\""), safe_text), EL_STR("\",\"cgi_id\":\"")), cgi_id), EL_STR("\",\"tools_used\":")), eff_tools), EL_STR("}")); return 0; @@ -29118,7 +29345,7 @@ el_val_t session_summary_write(el_val_t summary_text) { return EL_STR(""); } el_val_t safe_text = str_replace(summary_text, EL_STR("\""), EL_STR("'")); - el_val_t trimmed = ({ el_val_t _if_result_536 = 0; if ((str_len(safe_text) > 800)) { _if_result_536 = (str_slice(safe_text, 0, 800)); } else { _if_result_536 = (safe_text); } _if_result_536; }); + el_val_t trimmed = ({ el_val_t _if_result_589 = 0; if ((str_len(safe_text) > 800)) { _if_result_589 = (str_slice(safe_text, 0, 800)); } else { _if_result_589 = (safe_text); } _if_result_589; }); el_val_t ts = time_now(); el_val_t ts_str = int_to_str(ts); el_val_t content = el_str_concat(el_str_concat(el_str_concat(EL_STR("[session-summary] "), trimmed), EL_STR(" | ts:")), ts_str); @@ -29149,7 +29376,7 @@ el_val_t session_summary_write_dated(el_val_t summary_text, el_val_t label) { return EL_STR(""); } el_val_t safe_text = str_replace(summary_text, EL_STR("\""), EL_STR("'")); - el_val_t trimmed = ({ el_val_t _if_result_537 = 0; if ((str_len(safe_text) > 800)) { _if_result_537 = (str_slice(safe_text, 0, 800)); } else { _if_result_537 = (safe_text); } _if_result_537; }); + el_val_t trimmed = ({ el_val_t _if_result_590 = 0; if ((str_len(safe_text) > 800)) { _if_result_590 = (str_slice(safe_text, 0, 800)); } else { _if_result_590 = (safe_text); } _if_result_590; }); el_val_t ts = time_now(); el_val_t ts_str = int_to_str(ts); el_val_t content = el_str_concat(el_str_concat(el_str_concat(EL_STR("[session-summary] "), trimmed), EL_STR(" | ts:")), ts_str); @@ -29183,8 +29410,8 @@ el_val_t session_summary_autogenerate(el_val_t hist) { el_val_t role = json_get(entry, EL_STR("role")); if (str_eq(role, EL_STR("user"))) { el_val_t msg = json_get(entry, EL_STR("content")); - el_val_t snip = ({ el_val_t _if_result_538 = 0; if ((str_len(msg) > 80)) { _if_result_538 = (str_slice(msg, 0, 80)); } else { _if_result_538 = (msg); } _if_result_538; }); - snippets = ({ el_val_t _if_result_539 = 0; if (str_eq(snippets, EL_STR(""))) { _if_result_539 = (snip); } else { _if_result_539 = (el_str_concat(el_str_concat(snippets, EL_STR("; ")), snip)); } _if_result_539; }); + el_val_t snip = ({ el_val_t _if_result_591 = 0; if ((str_len(msg) > 80)) { _if_result_591 = (str_slice(msg, 0, 80)); } else { _if_result_591 = (msg); } _if_result_591; }); + snippets = ({ el_val_t _if_result_592 = 0; if (str_eq(snippets, EL_STR(""))) { _if_result_592 = (snip); } else { _if_result_592 = (el_str_concat(el_str_concat(snippets, EL_STR("; ")), snip)); } _if_result_592; }); count = (count + 1); } i = (i + 1); @@ -29199,7 +29426,7 @@ el_val_t session_summary_autogenerate(el_val_t hist) { el_val_t auto_persist(el_val_t req, el_val_t resp) { el_val_t message = json_get(req, EL_STR("message")); el_val_t reply = json_get(resp, EL_STR("response")); - el_val_t reply2 = ({ el_val_t _if_result_540 = 0; if (str_eq(reply, EL_STR(""))) { _if_result_540 = (json_get(resp, EL_STR("reply"))); } else { _if_result_540 = (reply); } _if_result_540; }); + el_val_t reply2 = ({ el_val_t _if_result_593 = 0; if (str_eq(reply, EL_STR(""))) { _if_result_593 = (json_get(resp, EL_STR("reply"))); } else { _if_result_593 = (reply); } _if_result_593; }); if (str_eq(message, EL_STR(""))) { return EL_STR(""); } @@ -29211,42 +29438,42 @@ el_val_t auto_persist(el_val_t req, el_val_t resp) { el_val_t is_bell = !str_eq(bell_level, EL_STR("none")); el_val_t positive_level = safety_detect_positive_level(message); el_val_t is_positive = !str_eq(positive_level, EL_STR("none")); - el_val_t tags = ({ el_val_t _if_result_541 = 0; if (is_bell) { _if_result_541 = (el_str_concat(el_str_concat(EL_STR("[\"Conversation\",\"chat\",\"timestamped\",\"bell:"), bell_level), EL_STR("\",\"affective\"]"))); } else { _if_result_541 = (({ el_val_t _if_result_542 = 0; if (is_positive) { _if_result_542 = (el_str_concat(el_str_concat(EL_STR("[\"Conversation\",\"chat\",\"timestamped\",\"joy:"), positive_level), EL_STR("\",\"affective\"]"))); } else { _if_result_542 = (EL_STR("[\"Conversation\",\"chat\",\"timestamped\"]")); } _if_result_542; })); } _if_result_541; }); + el_val_t tags = ({ el_val_t _if_result_594 = 0; if (is_bell) { _if_result_594 = (el_str_concat(el_str_concat(EL_STR("[\"Conversation\",\"chat\",\"timestamped\",\"bell:"), bell_level), EL_STR("\",\"affective\"]"))); } else { _if_result_594 = (({ el_val_t _if_result_595 = 0; if (is_positive) { _if_result_595 = (el_str_concat(el_str_concat(EL_STR("[\"Conversation\",\"chat\",\"timestamped\",\"joy:"), positive_level), EL_STR("\",\"affective\"]"))); } else { _if_result_595 = (EL_STR("[\"Conversation\",\"chat\",\"timestamped\"]")); } _if_result_595; })); } _if_result_594; }); el_val_t content = 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("{\"q\":\""), safe_msg), EL_STR("\"")), EL_STR(",\"a\":\"")), safe_reply), EL_STR("\"")), EL_STR(",\"created_at\":")), ts_str), EL_STR(",\"source\":\"chat\"")), EL_STR(",\"bell\":\"")), bell_level), EL_STR("\"")), EL_STR(",\"label\":\"chat:")), ts_str), EL_STR("\"}")); el_val_t conv_node_id = wt_node(content, EL_STR("Conversation"), el_str_concat(EL_STR("chat:"), ts_str), el_from_float(0.6), el_from_float(0.7), el_from_float(0.8), EL_STR("Episodic"), tags); if (str_eq(conv_node_id, EL_STR(""))) { println(el_str_concat(el_str_concat(EL_STR("[chat] auto_persist: engram_node_full returned empty \xe2\x80\x94 conversation node lost (ts="), ts_str), EL_STR(")"))); } if (is_bell) { - el_val_t summary = ({ el_val_t _if_result_543 = 0; if ((str_len(message) > 120)) { _if_result_543 = (str_slice(message, 0, 120)); } else { _if_result_543 = (message); } _if_result_543; }); + el_val_t summary = ({ el_val_t _if_result_596 = 0; if ((str_len(message) > 120)) { _if_result_596 = (str_slice(message, 0, 120)); } else { _if_result_596 = (message); } _if_result_596; }); el_val_t safe_summary = str_replace(summary, EL_STR("\""), EL_STR("'")); el_val_t bell_content = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("BELL:"), bell_level), EL_STR(" | ts:")), ts_str), EL_STR(" | summary:")), safe_summary); - el_val_t sal_a = ({ el_val_t _if_result_544 = 0; if (str_eq(bell_level, EL_STR("hard"))) { _if_result_544 = (el_from_float(0.98)); } else { _if_result_544 = (el_from_float(0.88)); } _if_result_544; }); - el_val_t sal_b = ({ el_val_t _if_result_545 = 0; if (str_eq(bell_level, EL_STR("hard"))) { _if_result_545 = (el_from_float(0.98)); } else { _if_result_545 = (el_from_float(0.88)); } _if_result_545; }); - el_val_t sal_c = ({ el_val_t _if_result_546 = 0; if (str_eq(bell_level, EL_STR("hard"))) { _if_result_546 = (el_from_float(1.0)); } else { _if_result_546 = (el_from_float(0.95)); } _if_result_546; }); + el_val_t sal_a = ({ el_val_t _if_result_597 = 0; if (str_eq(bell_level, EL_STR("hard"))) { _if_result_597 = (el_from_float(0.98)); } else { _if_result_597 = (el_from_float(0.88)); } _if_result_597; }); + el_val_t sal_b = ({ el_val_t _if_result_598 = 0; if (str_eq(bell_level, EL_STR("hard"))) { _if_result_598 = (el_from_float(0.98)); } else { _if_result_598 = (el_from_float(0.88)); } _if_result_598; }); + el_val_t sal_c = ({ el_val_t _if_result_599 = 0; if (str_eq(bell_level, EL_STR("hard"))) { _if_result_599 = (el_from_float(1.0)); } else { _if_result_599 = (el_from_float(0.95)); } _if_result_599; }); el_val_t bell_tags = el_str_concat(el_str_concat(EL_STR("[\"safety\",\"bell\",\"bell:"), bell_level), EL_STR("\",\"affective\",\"BellEvent\"]")); el_val_t bell_ts_str = int_to_str(time_now()); el_val_t bell_label = el_str_concat(el_str_concat(el_str_concat(EL_STR("bell:"), bell_level), EL_STR(":")), bell_ts_str); el_val_t bell_node_id = wt_node(bell_content, EL_STR("BellEvent"), bell_label, sal_a, sal_b, sal_c, EL_STR("Episodic"), bell_tags); el_val_t sess_id = json_get(req, EL_STR("session_id")); - el_val_t bell_key = ({ el_val_t _if_result_547 = 0; if (str_eq(sess_id, EL_STR(""))) { _if_result_547 = (EL_STR("session_bell_count")); } else { _if_result_547 = (el_str_concat(EL_STR("session_bell_count:"), sess_id)); } _if_result_547; }); + el_val_t bell_key = ({ el_val_t _if_result_600 = 0; if (str_eq(sess_id, EL_STR(""))) { _if_result_600 = (EL_STR("session_bell_count")); } else { _if_result_600 = (el_str_concat(EL_STR("session_bell_count:"), sess_id)); } _if_result_600; }); el_val_t prior_count = state_get(bell_key); - el_val_t prior_n = ({ el_val_t _if_result_548 = 0; if (str_eq(prior_count, EL_STR(""))) { _if_result_548 = (0); } else { _if_result_548 = (str_to_int(prior_count)); } _if_result_548; }); + el_val_t prior_n = ({ el_val_t _if_result_601 = 0; if (str_eq(prior_count, EL_STR(""))) { _if_result_601 = (0); } else { _if_result_601 = (str_to_int(prior_count)); } _if_result_601; }); state_set(bell_key, int_to_str((prior_n + 1))); - el_val_t level_key = ({ el_val_t _if_result_549 = 0; if (str_eq(sess_id, EL_STR(""))) { _if_result_549 = (EL_STR("session_bell_level")); } else { _if_result_549 = (el_str_concat(EL_STR("session_bell_level:"), sess_id)); } _if_result_549; }); + el_val_t level_key = ({ el_val_t _if_result_602 = 0; if (str_eq(sess_id, EL_STR(""))) { _if_result_602 = (EL_STR("session_bell_level")); } else { _if_result_602 = (el_str_concat(EL_STR("session_bell_level:"), sess_id)); } _if_result_602; }); el_val_t prior_level = state_get(level_key); - el_val_t new_level = ({ el_val_t _if_result_550 = 0; if (str_eq(bell_level, EL_STR("hard"))) { _if_result_550 = (EL_STR("hard")); } else { _if_result_550 = (({ el_val_t _if_result_551 = 0; if (str_eq(prior_level, EL_STR("hard"))) { _if_result_551 = (EL_STR("hard")); } else { _if_result_551 = (EL_STR("soft")); } _if_result_551; })); } _if_result_550; }); + el_val_t new_level = ({ el_val_t _if_result_603 = 0; if (str_eq(bell_level, EL_STR("hard"))) { _if_result_603 = (EL_STR("hard")); } else { _if_result_603 = (({ el_val_t _if_result_604 = 0; if (str_eq(prior_level, EL_STR("hard"))) { _if_result_604 = (EL_STR("hard")); } else { _if_result_604 = (EL_STR("soft")); } _if_result_604; })); } _if_result_603; }); state_set(level_key, new_level); - el_val_t signal_key = ({ el_val_t _if_result_552 = 0; if (str_eq(sess_id, EL_STR(""))) { _if_result_552 = (EL_STR("session_bell_signal")); } else { _if_result_552 = (el_str_concat(EL_STR("session_bell_signal:"), sess_id)); } _if_result_552; }); + el_val_t signal_key = ({ el_val_t _if_result_605 = 0; if (str_eq(sess_id, EL_STR(""))) { _if_result_605 = (EL_STR("session_bell_signal")); } else { _if_result_605 = (el_str_concat(EL_STR("session_bell_signal:"), sess_id)); } _if_result_605; }); state_set(signal_key, safe_summary); } if (is_positive) { - el_val_t pos_summary = ({ el_val_t _if_result_553 = 0; if ((str_len(message) > 120)) { _if_result_553 = (str_slice(message, 0, 120)); } else { _if_result_553 = (message); } _if_result_553; }); + el_val_t pos_summary = ({ el_val_t _if_result_606 = 0; if ((str_len(message) > 120)) { _if_result_606 = (str_slice(message, 0, 120)); } else { _if_result_606 = (message); } _if_result_606; }); el_val_t safe_pos_sum = str_replace(pos_summary, EL_STR("\""), EL_STR("'")); el_val_t pos_content = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("POSITIVE:"), positive_level), EL_STR(" | ts:")), ts_str), EL_STR(" | summary:")), safe_pos_sum); - el_val_t pos_sal_a = ({ el_val_t _if_result_554 = 0; if (str_eq(positive_level, EL_STR("high"))) { _if_result_554 = (el_from_float(0.88)); } else { _if_result_554 = (el_from_float(0.75)); } _if_result_554; }); - el_val_t pos_sal_b = ({ el_val_t _if_result_555 = 0; if (str_eq(positive_level, EL_STR("high"))) { _if_result_555 = (el_from_float(0.88)); } else { _if_result_555 = (el_from_float(0.75)); } _if_result_555; }); - el_val_t pos_sal_c = ({ el_val_t _if_result_556 = 0; if (str_eq(positive_level, EL_STR("high"))) { _if_result_556 = (el_from_float(0.95)); } else { _if_result_556 = (el_from_float(0.85)); } _if_result_556; }); + el_val_t pos_sal_a = ({ el_val_t _if_result_607 = 0; if (str_eq(positive_level, EL_STR("high"))) { _if_result_607 = (el_from_float(0.88)); } else { _if_result_607 = (el_from_float(0.75)); } _if_result_607; }); + el_val_t pos_sal_b = ({ el_val_t _if_result_608 = 0; if (str_eq(positive_level, EL_STR("high"))) { _if_result_608 = (el_from_float(0.88)); } else { _if_result_608 = (el_from_float(0.75)); } _if_result_608; }); + el_val_t pos_sal_c = ({ el_val_t _if_result_609 = 0; if (str_eq(positive_level, EL_STR("high"))) { _if_result_609 = (el_from_float(0.95)); } else { _if_result_609 = (el_from_float(0.85)); } _if_result_609; }); el_val_t pos_tags = el_str_concat(el_str_concat(EL_STR("[\"joy\",\"positive\",\"joy:"), positive_level), EL_STR("\",\"affective\",\"PositiveEvent\"]")); el_val_t pos_ts_label = int_to_str(time_now()); el_val_t pos_label = el_str_concat(el_str_concat(el_str_concat(EL_STR("joy:"), positive_level), EL_STR(":")), pos_ts_label); @@ -29326,7 +29553,7 @@ el_val_t handle_config(el_val_t method, el_val_t body) { } } el_val_t current_model = state_get(EL_STR("soul_model")); - el_val_t display = ({ el_val_t _if_result_557 = 0; if (str_eq(current_model, EL_STR(""))) { _if_result_557 = (EL_STR("claude-opus-4-8")); } else { _if_result_557 = (current_model); } _if_result_557; }); + el_val_t display = ({ el_val_t _if_result_610 = 0; if (str_eq(current_model, EL_STR(""))) { _if_result_610 = (EL_STR("claude-opus-4-8")); } else { _if_result_610 = (current_model); } _if_result_610; }); return el_str_concat(el_str_concat(EL_STR("{\"model\":\""), display), EL_STR("\",\"ok\":true}")); return 0; } @@ -29429,7 +29656,7 @@ el_val_t handle_nlg(el_val_t path, el_val_t method, el_val_t body) { return EL_STR("{\"error\":\"POST required\"}"); } el_val_t lang_req = json_get(body, EL_STR("lang")); - el_val_t lang_code = ({ el_val_t _if_result_558 = 0; if (str_eq(lang_req, EL_STR(""))) { _if_result_558 = (EL_STR("en")); } else { _if_result_558 = (lang_req); } _if_result_558; }); + el_val_t lang_code = ({ el_val_t _if_result_611 = 0; if (str_eq(lang_req, EL_STR(""))) { _if_result_611 = (EL_STR("en")); } else { _if_result_611 = (lang_req); } _if_result_611; }); el_val_t text = generate_lang(body, lang_code); el_val_t safe = str_replace(text, EL_STR("\""), EL_STR("'")); return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"text\":\""), safe), EL_STR("\",\"lang\":\"")), lang_code), EL_STR("\",\"ok\":true}")); @@ -29452,17 +29679,17 @@ el_val_t render_studio(void) { } el_val_t elp_extract_topic(el_val_t msg) { - el_val_t m1 = ({ el_val_t _if_result_559 = 0; if (str_starts_with(msg, EL_STR("What is "))) { _if_result_559 = (str_slice(msg, 8, str_len(msg))); } else { _if_result_559 = (msg); } _if_result_559; }); - el_val_t m2 = ({ el_val_t _if_result_560 = 0; if (str_starts_with(m1, EL_STR("What are "))) { _if_result_560 = (str_slice(m1, 9, str_len(m1))); } else { _if_result_560 = (m1); } _if_result_560; }); - el_val_t m3 = ({ el_val_t _if_result_561 = 0; if (str_starts_with(m2, EL_STR("Tell me about "))) { _if_result_561 = (str_slice(m2, 14, str_len(m2))); } else { _if_result_561 = (m2); } _if_result_561; }); - el_val_t m4 = ({ el_val_t _if_result_562 = 0; if (str_starts_with(m3, EL_STR("Who is "))) { _if_result_562 = (str_slice(m3, 7, str_len(m3))); } else { _if_result_562 = (m3); } _if_result_562; }); - el_val_t m5 = ({ el_val_t _if_result_563 = 0; if (str_starts_with(m4, EL_STR("Who are "))) { _if_result_563 = (str_slice(m4, 8, str_len(m4))); } else { _if_result_563 = (m4); } _if_result_563; }); - el_val_t m6 = ({ el_val_t _if_result_564 = 0; if (str_starts_with(m5, EL_STR("How do you "))) { _if_result_564 = (str_slice(m5, 11, str_len(m5))); } else { _if_result_564 = (m5); } _if_result_564; }); - el_val_t m7 = ({ el_val_t _if_result_565 = 0; if (str_starts_with(m6, EL_STR("Why "))) { _if_result_565 = (str_slice(m6, 4, str_len(m6))); } else { _if_result_565 = (m6); } _if_result_565; }); - el_val_t m8 = ({ el_val_t _if_result_566 = 0; if (str_starts_with(m7, EL_STR("Explain "))) { _if_result_566 = (str_slice(m7, 8, str_len(m7))); } else { _if_result_566 = (m7); } _if_result_566; }); + el_val_t m1 = ({ el_val_t _if_result_612 = 0; if (str_starts_with(msg, EL_STR("What is "))) { _if_result_612 = (str_slice(msg, 8, str_len(msg))); } else { _if_result_612 = (msg); } _if_result_612; }); + el_val_t m2 = ({ el_val_t _if_result_613 = 0; if (str_starts_with(m1, EL_STR("What are "))) { _if_result_613 = (str_slice(m1, 9, str_len(m1))); } else { _if_result_613 = (m1); } _if_result_613; }); + el_val_t m3 = ({ el_val_t _if_result_614 = 0; if (str_starts_with(m2, EL_STR("Tell me about "))) { _if_result_614 = (str_slice(m2, 14, str_len(m2))); } else { _if_result_614 = (m2); } _if_result_614; }); + el_val_t m4 = ({ el_val_t _if_result_615 = 0; if (str_starts_with(m3, EL_STR("Who is "))) { _if_result_615 = (str_slice(m3, 7, str_len(m3))); } else { _if_result_615 = (m3); } _if_result_615; }); + el_val_t m5 = ({ el_val_t _if_result_616 = 0; if (str_starts_with(m4, EL_STR("Who are "))) { _if_result_616 = (str_slice(m4, 8, str_len(m4))); } else { _if_result_616 = (m4); } _if_result_616; }); + el_val_t m6 = ({ el_val_t _if_result_617 = 0; if (str_starts_with(m5, EL_STR("How do you "))) { _if_result_617 = (str_slice(m5, 11, str_len(m5))); } else { _if_result_617 = (m5); } _if_result_617; }); + el_val_t m7 = ({ el_val_t _if_result_618 = 0; if (str_starts_with(m6, EL_STR("Why "))) { _if_result_618 = (str_slice(m6, 4, str_len(m6))); } else { _if_result_618 = (m6); } _if_result_618; }); + el_val_t m8 = ({ el_val_t _if_result_619 = 0; if (str_starts_with(m7, EL_STR("Explain "))) { _if_result_619 = (str_slice(m7, 8, str_len(m7))); } else { _if_result_619 = (m7); } _if_result_619; }); el_val_t last = (str_len(m8) - 1); el_val_t trail = str_slice(m8, last, str_len(m8)); - el_val_t clean = ({ el_val_t _if_result_567 = 0; if (((str_eq(trail, EL_STR("?")) || str_eq(trail, EL_STR("."))) || str_eq(trail, EL_STR("!")))) { _if_result_567 = (str_slice(m8, 0, last)); } else { _if_result_567 = (m8); } _if_result_567; }); + el_val_t clean = ({ el_val_t _if_result_620 = 0; if (((str_eq(trail, EL_STR("?")) || str_eq(trail, EL_STR("."))) || str_eq(trail, EL_STR("!")))) { _if_result_620 = (str_slice(m8, 0, last)); } else { _if_result_620 = (m8); } _if_result_620; }); return clean; return 0; } @@ -29505,7 +29732,7 @@ el_val_t handle_elp_chat(el_val_t body) { el_val_t topic = elp_extract_topic(message); el_val_t from_topic = engram_activate_json(topic, 10); el_val_t topic_ok = (!str_eq(from_topic, EL_STR("")) && !str_eq(from_topic, EL_STR("[]"))); - el_val_t candidates = ({ el_val_t _if_result_568 = 0; if (topic_ok) { _if_result_568 = (from_topic); } else { el_val_t from_msg = engram_activate_json(message, 10); el_val_t msg_ok = (!str_eq(from_msg, EL_STR("")) && !str_eq(from_msg, EL_STR("[]"))); _if_result_568 = (({ el_val_t _if_result_569 = 0; if (msg_ok) { _if_result_569 = (from_msg); } else { _if_result_569 = (engram_scan_nodes_json(5, 0)); } _if_result_569; })); } _if_result_568; }); + el_val_t candidates = ({ el_val_t _if_result_621 = 0; if (topic_ok) { _if_result_621 = (from_topic); } else { el_val_t from_msg = engram_activate_json(message, 10); el_val_t msg_ok = (!str_eq(from_msg, EL_STR("")) && !str_eq(from_msg, EL_STR("[]"))); _if_result_621 = (({ el_val_t _if_result_622 = 0; if (msg_ok) { _if_result_622 = (from_msg); } else { _if_result_622 = (engram_scan_nodes_json(5, 0)); } _if_result_622; })); } _if_result_621; }); el_val_t total = json_array_len(candidates); el_val_t fi = 0; el_val_t kept_count = 0; @@ -29518,13 +29745,13 @@ el_val_t handle_elp_chat(el_val_t body) { el_val_t imp_ok = ((!str_eq(imp_str, EL_STR("0")) && !str_eq(imp_str, EL_STR("0.0"))) && !str_eq(imp_str, EL_STR(""))); el_val_t keep_it = ((sal_ok || imp_ok) || (kept_count == 0)); if (keep_it && (kept_count < 3)) { - el_val_t sep = ({ el_val_t _if_result_570 = 0; if (str_eq(kept_json, EL_STR(""))) { _if_result_570 = (EL_STR("")); } else { _if_result_570 = (EL_STR(",")); } _if_result_570; }); + el_val_t sep = ({ el_val_t _if_result_623 = 0; if (str_eq(kept_json, EL_STR(""))) { _if_result_623 = (EL_STR("")); } else { _if_result_623 = (EL_STR(",")); } _if_result_623; }); kept_json = el_str_concat(el_str_concat(kept_json, sep), n); kept_count = (kept_count + 1); } fi = (fi + 1); } - el_val_t frame_nodes = ({ el_val_t _if_result_571 = 0; if (str_eq(kept_json, EL_STR(""))) { _if_result_571 = (EL_STR("[]")); } else { _if_result_571 = (el_str_concat(el_str_concat(EL_STR("["), kept_json), EL_STR("]"))); } _if_result_571; }); + el_val_t frame_nodes = ({ el_val_t _if_result_624 = 0; if (str_eq(kept_json, EL_STR(""))) { _if_result_624 = (EL_STR("[]")); } else { _if_result_624 = (el_str_concat(el_str_concat(EL_STR("["), kept_json), EL_STR("]"))); } _if_result_624; }); el_val_t fn_total = json_array_len(frame_nodes); el_val_t fn_i = 0; el_val_t topic_lower = str_to_lower(topic); @@ -29539,14 +29766,14 @@ el_val_t handle_elp_chat(el_val_t body) { } fn_i = (fn_i + 1); } - el_val_t top_node = ({ el_val_t _if_result_572 = 0; if (str_eq(found_node, EL_STR(""))) { _if_result_572 = (json_array_get(frame_nodes, 0)); } else { _if_result_572 = (found_node); } _if_result_572; }); + el_val_t top_node = ({ el_val_t _if_result_625 = 0; if (str_eq(found_node, EL_STR(""))) { _if_result_625 = (json_array_get(frame_nodes, 0)); } else { _if_result_625 = (found_node); } _if_result_625; }); el_val_t top_raw = json_get(top_node, EL_STR("content")); - el_val_t patient_raw = ({ el_val_t _if_result_573 = 0; if (str_eq(top_raw, EL_STR(""))) { _if_result_573 = (topic); } else { _if_result_573 = (({ el_val_t _if_result_574 = 0; if ((str_len(top_raw) > 200)) { _if_result_574 = (str_slice(top_raw, 0, 200)); } else { _if_result_574 = (top_raw); } _if_result_574; })); } _if_result_573; }); + el_val_t patient_raw = ({ el_val_t _if_result_626 = 0; if (str_eq(top_raw, EL_STR(""))) { _if_result_626 = (topic); } else { _if_result_626 = (({ el_val_t _if_result_627 = 0; if ((str_len(top_raw) > 200)) { _if_result_627 = (str_slice(top_raw, 0, 200)); } else { _if_result_627 = (top_raw); } _if_result_627; })); } _if_result_626; }); el_val_t patient_safe = str_replace(str_replace(patient_raw, EL_STR("\""), EL_STR("'")), EL_STR("\n"), EL_STR(" ")); - el_val_t intent_val = ({ el_val_t _if_result_575 = 0; if (str_eq(predicate, EL_STR("store"))) { _if_result_575 = (EL_STR("command")); } else { _if_result_575 = (EL_STR("assert")); } _if_result_575; }); + el_val_t intent_val = ({ el_val_t _if_result_628 = 0; if (str_eq(predicate, EL_STR("store"))) { _if_result_628 = (EL_STR("command")); } else { _if_result_628 = (EL_STR("assert")); } _if_result_628; }); el_val_t gen_form = 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("{\"intent\":\""), intent_val), EL_STR("\"")), EL_STR(",\"agent\":\"I\"")), EL_STR(",\"predicate\":\"")), predicate), EL_STR("\"")), EL_STR(",\"patient\":\"")), patient_safe), EL_STR("\"")), EL_STR(",\"tense\":\"present\",\"aspect\":\"simple\",\"lang\":\"en\"}")); el_val_t realized = generate(gen_form); - el_val_t response = ({ el_val_t _if_result_576 = 0; if (str_eq(realized, EL_STR(""))) { _if_result_576 = (({ el_val_t _if_result_577 = 0; if (str_eq(patient_safe, EL_STR(""))) { _if_result_577 = (EL_STR("Nothing in the engram matched that query.")); } else { _if_result_577 = (patient_safe); } _if_result_577; })); } else { _if_result_576 = (realized); } _if_result_576; }); + el_val_t response = ({ el_val_t _if_result_629 = 0; if (str_eq(realized, EL_STR(""))) { _if_result_629 = (({ el_val_t _if_result_630 = 0; if (str_eq(patient_safe, EL_STR(""))) { _if_result_630 = (EL_STR("Nothing in the engram matched that query.")); } else { _if_result_630 = (patient_safe); } _if_result_630; })); } else { _if_result_629 = (realized); } _if_result_629; }); el_val_t safe_resp = str_replace(str_replace(response, EL_STR("\""), EL_STR("'")), EL_STR("\r"), EL_STR("")); return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"response\":\""), safe_resp), EL_STR("\",\"model\":\"elp-native\",\"frame\":")), frame), EL_STR(",\"nodes\":")), frame_nodes), EL_STR("}")); return 0; @@ -29629,7 +29856,7 @@ el_val_t api_query_param(el_val_t path, el_val_t key) { } el_val_t after = str_slice(qs, (pos + str_len(needle)), str_len(qs)); el_val_t amp = str_index_of(after, EL_STR("&")); - el_val_t raw = ({ el_val_t _if_result_578 = 0; if ((amp < 0)) { _if_result_578 = (after); } else { _if_result_578 = (str_slice(after, 0, amp)); } _if_result_578; }); + el_val_t raw = ({ el_val_t _if_result_631 = 0; if ((amp < 0)) { _if_result_631 = (after); } else { _if_result_631 = (str_slice(after, 0, amp)); } _if_result_631; }); return url_decode(raw); return 0; } @@ -29687,7 +29914,7 @@ el_val_t api_utf8_trunc(el_val_t s, el_val_t n) { while (scanning && (cut > 0)) { el_val_t b = str_char_code(s, cut); el_val_t is_cont = ((b >= 128) && (b < 192)); - cut = ({ el_val_t _if_result_579 = 0; if (is_cont) { _if_result_579 = ((cut - 1)); } else { _if_result_579 = (cut); } _if_result_579; }); + cut = ({ el_val_t _if_result_632 = 0; if (is_cont) { _if_result_632 = ((cut - 1)); } else { _if_result_632 = (cut); } _if_result_632; }); scanning = is_cont; } return str_slice(s, 0, cut); @@ -29701,7 +29928,7 @@ el_val_t api_compact_node(el_val_t node, el_val_t snip) { el_val_t tier = json_get(node, EL_STR("tier")); el_val_t content = json_get(node, EL_STR("content")); el_val_t snippet = api_utf8_trunc(content, snip); - el_val_t trunc_str = ({ el_val_t _if_result_580 = 0; if ((str_len(content) > snip)) { _if_result_580 = (EL_STR("true")); } else { _if_result_580 = (EL_STR("false")); } _if_result_580; }); + el_val_t trunc_str = ({ el_val_t _if_result_633 = 0; if ((str_len(content) > snip)) { _if_result_633 = (EL_STR("true")); } else { _if_result_633 = (EL_STR("false")); } _if_result_633; }); return 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_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), api_json_escape(id)), EL_STR("\"")), EL_STR(",\"node_type\":\"")), api_json_escape(ntype)), EL_STR("\"")), EL_STR(",\"label\":\"")), api_json_escape(label)), EL_STR("\"")), EL_STR(",\"tier\":\"")), api_json_escape(tier)), EL_STR("\"")), EL_STR(",\"importance\":")), api_num_or_zero(node, EL_STR("importance"))), EL_STR(",\"salience\":")), api_num_or_zero(node, EL_STR("salience"))), EL_STR(",\"content\":\"")), api_json_escape(snippet)), EL_STR("\"")), EL_STR(",\"content_truncated\":")), trunc_str), EL_STR("}")); return 0; } @@ -29711,12 +29938,12 @@ el_val_t api_compact_node_array(el_val_t raw, el_val_t max_items, el_val_t snip) return EL_STR("[]"); } el_val_t n = json_array_len(raw); - el_val_t cap = ({ el_val_t _if_result_581 = 0; if ((n < max_items)) { _if_result_581 = (n); } else { _if_result_581 = (max_items); } _if_result_581; }); + el_val_t cap = ({ el_val_t _if_result_634 = 0; if ((n < max_items)) { _if_result_634 = (n); } else { _if_result_634 = (max_items); } _if_result_634; }); el_val_t out = EL_STR("["); el_val_t i = 0; while (i < cap) { el_val_t node = json_array_get(raw, i); - el_val_t sep = ({ el_val_t _if_result_582 = 0; if ((i == 0)) { _if_result_582 = (EL_STR("")); } else { _if_result_582 = (EL_STR(",")); } _if_result_582; }); + el_val_t sep = ({ el_val_t _if_result_635 = 0; if ((i == 0)) { _if_result_635 = (EL_STR("")); } else { _if_result_635 = (EL_STR(",")); } _if_result_635; }); out = el_str_concat(el_str_concat(out, sep), api_compact_node(node, snip)); i = (i + 1); } @@ -29729,13 +29956,13 @@ el_val_t api_compact_activated(el_val_t raw, el_val_t max_items, el_val_t snip) return EL_STR("[]"); } el_val_t n = json_array_len(raw); - el_val_t cap = ({ el_val_t _if_result_583 = 0; if ((n < max_items)) { _if_result_583 = (n); } else { _if_result_583 = (max_items); } _if_result_583; }); + el_val_t cap = ({ el_val_t _if_result_636 = 0; if ((n < max_items)) { _if_result_636 = (n); } else { _if_result_636 = (max_items); } _if_result_636; }); el_val_t out = EL_STR("["); el_val_t i = 0; while (i < cap) { el_val_t el = json_array_get(raw, i); el_val_t node = json_get_raw(el, EL_STR("node")); - el_val_t sep = ({ el_val_t _if_result_584 = 0; if ((i == 0)) { _if_result_584 = (EL_STR("")); } else { _if_result_584 = (EL_STR(",")); } _if_result_584; }); + el_val_t sep = ({ el_val_t _if_result_637 = 0; if ((i == 0)) { _if_result_637 = (EL_STR("")); } else { _if_result_637 = (EL_STR(",")); } _if_result_637; }); out = 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(out, sep), EL_STR("{\"node\":")), api_compact_node(node, snip)), EL_STR(",\"activation_strength\":")), api_num_or_zero(el, EL_STR("activation_strength"))), EL_STR(",\"working_memory_weight\":")), api_num_or_zero(el, EL_STR("working_memory_weight"))), EL_STR(",\"epistemic_confidence\":")), api_num_or_zero(el, EL_STR("epistemic_confidence"))), EL_STR(",\"hops\":")), api_num_or_zero(el, EL_STR("hops"))), EL_STR(",\"promoted\":")), api_num_or_zero(el, EL_STR("promoted"))), EL_STR("}")); i = (i + 1); } @@ -29772,7 +29999,7 @@ el_val_t tombstoned_id_set(void) { 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_585 = 0; if (str_eq(tid, EL_STR(""))) { _if_result_585 = (acc); } else { _if_result_585 = (el_str_concat(el_str_concat(acc, tid), EL_STR("|"))); } _if_result_585; }); + acc = ({ el_val_t _if_result_638 = 0; if (str_eq(tid, EL_STR(""))) { _if_result_638 = (acc); } else { _if_result_638 = (el_str_concat(el_str_concat(acc, tid), EL_STR("|"))); } _if_result_638; }); i = (i + 1); } return acc; @@ -29803,8 +30030,8 @@ el_val_t memory_hide_tombstoned(el_val_t raw, el_val_t path) { 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_586 = 0; if (keep) { _if_result_586 = (({ el_val_t _if_result_587 = 0; if (first) { _if_result_587 = (el_str_concat(out, node)); } else { _if_result_587 = (el_str_concat(el_str_concat(out, EL_STR(",")), node)); } _if_result_587; })); } else { _if_result_586 = (out); } _if_result_586; }); - first = ({ el_val_t _if_result_588 = 0; if (keep) { _if_result_588 = (0); } else { _if_result_588 = (first); } _if_result_588; }); + out = ({ el_val_t _if_result_639 = 0; if (keep) { _if_result_639 = (({ el_val_t _if_result_640 = 0; if (first) { _if_result_640 = (el_str_concat(out, node)); } else { _if_result_640 = (el_str_concat(el_str_concat(out, EL_STR(",")), node)); } _if_result_640; })); } else { _if_result_639 = (out); } _if_result_639; }); + first = ({ el_val_t _if_result_641 = 0; if (keep) { _if_result_641 = (0); } else { _if_result_641 = (first); } _if_result_641; }); i = (i + 1); } return el_str_concat(out, EL_STR("]")); @@ -29843,10 +30070,10 @@ el_val_t handle_api_remember(el_val_t body) { el_val_t importance = json_get(body, EL_STR("importance")); el_val_t tags_raw = json_get(body, EL_STR("tags")); el_val_t project = json_get(body, EL_STR("project")); - el_val_t sal_str = ({ el_val_t _if_result_589 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_589 = (EL_STR("0.95")); } else { _if_result_589 = (({ el_val_t _if_result_590 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_590 = (EL_STR("0.75")); } else { _if_result_590 = (({ el_val_t _if_result_591 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_591 = (EL_STR("0.25")); } else { _if_result_591 = (EL_STR("0.50")); } _if_result_591; })); } _if_result_590; })); } _if_result_589; }); - el_val_t sal = ({ el_val_t _if_result_592 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_592 = (el_from_float(0.95)); } else { _if_result_592 = (({ el_val_t _if_result_593 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_593 = (el_from_float(0.75)); } else { _if_result_593 = (({ el_val_t _if_result_594 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_594 = (el_from_float(0.25)); } else { _if_result_594 = (el_from_float(0.5)); } _if_result_594; })); } _if_result_593; })); } _if_result_592; }); - el_val_t base_tags = ({ el_val_t _if_result_595 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_595 = (EL_STR("[\"Memory\"]")); } else { _if_result_595 = (tags_raw); } _if_result_595; }); - el_val_t final_tags = ({ el_val_t _if_result_596 = 0; if (str_eq(project, EL_STR(""))) { _if_result_596 = (base_tags); } else { el_val_t inner = str_slice(base_tags, 1, (str_len(base_tags) - 1)); _if_result_596 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",\"project:")), project), EL_STR("\"]"))); } _if_result_596; }); + el_val_t sal_str = ({ el_val_t _if_result_642 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_642 = (EL_STR("0.95")); } else { _if_result_642 = (({ el_val_t _if_result_643 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_643 = (EL_STR("0.75")); } else { _if_result_643 = (({ el_val_t _if_result_644 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_644 = (EL_STR("0.25")); } else { _if_result_644 = (EL_STR("0.50")); } _if_result_644; })); } _if_result_643; })); } _if_result_642; }); + el_val_t sal = ({ el_val_t _if_result_645 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_645 = (el_from_float(0.95)); } else { _if_result_645 = (({ el_val_t _if_result_646 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_646 = (el_from_float(0.75)); } else { _if_result_646 = (({ el_val_t _if_result_647 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_647 = (el_from_float(0.25)); } else { _if_result_647 = (el_from_float(0.5)); } _if_result_647; })); } _if_result_646; })); } _if_result_645; }); + el_val_t base_tags = ({ el_val_t _if_result_648 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_648 = (EL_STR("[\"Memory\"]")); } else { _if_result_648 = (tags_raw); } _if_result_648; }); + el_val_t final_tags = ({ el_val_t _if_result_649 = 0; if (str_eq(project, EL_STR(""))) { _if_result_649 = (base_tags); } else { el_val_t inner = str_slice(base_tags, 1, (str_len(base_tags) - 1)); _if_result_649 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",\"project:")), project), EL_STR("\"]"))); } _if_result_649; }); el_val_t id = wt_node(content, EL_STR("Memory"), EL_STR("memory:remembered"), sal, sal, el_from_float(0.9), EL_STR("Episodic"), final_tags); if (!api_persisted(id)) { return api_not_persisted(id); @@ -29862,15 +30089,15 @@ el_val_t handle_api_node_create(el_val_t body) { return api_err(EL_STR("content is required")); } el_val_t nt_raw = json_get(body, EL_STR("node_type")); - el_val_t node_type = ({ el_val_t _if_result_597 = 0; if (str_eq(nt_raw, EL_STR(""))) { _if_result_597 = (EL_STR("Memory")); } else { _if_result_597 = (nt_raw); } _if_result_597; }); + el_val_t node_type = ({ el_val_t _if_result_650 = 0; if (str_eq(nt_raw, EL_STR(""))) { _if_result_650 = (EL_STR("Memory")); } else { _if_result_650 = (nt_raw); } _if_result_650; }); el_val_t label_raw = json_get(body, EL_STR("label")); - el_val_t label = ({ el_val_t _if_result_598 = 0; if (str_eq(label_raw, EL_STR(""))) { _if_result_598 = (EL_STR("node:created")); } else { _if_result_598 = (label_raw); } _if_result_598; }); + el_val_t label = ({ el_val_t _if_result_651 = 0; if (str_eq(label_raw, EL_STR(""))) { _if_result_651 = (EL_STR("node:created")); } else { _if_result_651 = (label_raw); } _if_result_651; }); el_val_t tier_raw = json_get(body, EL_STR("tier")); - el_val_t tier = ({ el_val_t _if_result_599 = 0; if (str_eq(tier_raw, EL_STR(""))) { _if_result_599 = (EL_STR("Episodic")); } else { _if_result_599 = (tier_raw); } _if_result_599; }); + el_val_t tier = ({ el_val_t _if_result_652 = 0; if (str_eq(tier_raw, EL_STR(""))) { _if_result_652 = (EL_STR("Episodic")); } else { _if_result_652 = (tier_raw); } _if_result_652; }); el_val_t tags_raw = json_get(body, EL_STR("tags")); - el_val_t tags = ({ el_val_t _if_result_600 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_600 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_600 = (tags_raw); } _if_result_600; }); + el_val_t tags = ({ el_val_t _if_result_653 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_653 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_653 = (tags_raw); } _if_result_653; }); el_val_t importance = json_get(body, EL_STR("importance")); - el_val_t sal = ({ el_val_t _if_result_601 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_601 = (el_from_float(0.95)); } else { _if_result_601 = (({ el_val_t _if_result_602 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_602 = (el_from_float(0.75)); } else { _if_result_602 = (({ el_val_t _if_result_603 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_603 = (el_from_float(0.25)); } else { _if_result_603 = (el_from_float(0.5)); } _if_result_603; })); } _if_result_602; })); } _if_result_601; }); + el_val_t sal = ({ el_val_t _if_result_654 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_654 = (el_from_float(0.95)); } else { _if_result_654 = (({ el_val_t _if_result_655 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_655 = (el_from_float(0.75)); } else { _if_result_655 = (({ el_val_t _if_result_656 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_656 = (el_from_float(0.25)); } else { _if_result_656 = (el_from_float(0.5)); } _if_result_656; })); } _if_result_655; })); } _if_result_654; }); el_val_t id = wt_node(content, node_type, label, sal, sal, el_from_float(0.9), tier, tags); if (!api_persisted(id)) { return api_not_persisted(id); @@ -29909,18 +30136,18 @@ el_val_t handle_api_node_update(el_val_t body) { } el_val_t old = engram_get_node_json(id); el_val_t body_content = json_get(body, EL_STR("content")); - el_val_t content = ({ el_val_t _if_result_604 = 0; if (str_eq(body_content, EL_STR(""))) { _if_result_604 = (json_get(old, EL_STR("content"))); } else { _if_result_604 = (body_content); } _if_result_604; }); + el_val_t content = ({ el_val_t _if_result_657 = 0; if (str_eq(body_content, EL_STR(""))) { _if_result_657 = (json_get(old, EL_STR("content"))); } else { _if_result_657 = (body_content); } _if_result_657; }); 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 node_type = ({ el_val_t _if_result_605 = 0; if (!str_eq(body_nt, EL_STR(""))) { _if_result_605 = (body_nt); } else { _if_result_605 = (({ el_val_t _if_result_606 = 0; if (!str_eq(old_nt, EL_STR(""))) { _if_result_606 = (old_nt); } else { _if_result_606 = (EL_STR("Memory")); } _if_result_606; })); } _if_result_605; }); + el_val_t node_type = ({ el_val_t _if_result_658 = 0; if (!str_eq(body_nt, EL_STR(""))) { _if_result_658 = (body_nt); } else { _if_result_658 = (({ el_val_t _if_result_659 = 0; if (!str_eq(old_nt, EL_STR(""))) { _if_result_659 = (old_nt); } else { _if_result_659 = (EL_STR("Memory")); } _if_result_659; })); } _if_result_658; }); 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 label = ({ el_val_t _if_result_607 = 0; if (!str_eq(body_label, EL_STR(""))) { _if_result_607 = (body_label); } else { _if_result_607 = (({ el_val_t _if_result_608 = 0; if (!str_eq(old_label, EL_STR(""))) { _if_result_608 = (old_label); } else { _if_result_608 = (EL_STR("node:updated")); } _if_result_608; })); } _if_result_607; }); + el_val_t label = ({ el_val_t _if_result_660 = 0; if (!str_eq(body_label, EL_STR(""))) { _if_result_660 = (body_label); } else { _if_result_660 = (({ el_val_t _if_result_661 = 0; if (!str_eq(old_label, EL_STR(""))) { _if_result_661 = (old_label); } else { _if_result_661 = (EL_STR("node:updated")); } _if_result_661; })); } _if_result_660; }); 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 tier = ({ el_val_t _if_result_609 = 0; if (!str_eq(body_tier, EL_STR(""))) { _if_result_609 = (body_tier); } else { _if_result_609 = (({ el_val_t _if_result_610 = 0; if (!str_eq(old_tier, EL_STR(""))) { _if_result_610 = (old_tier); } else { _if_result_610 = (EL_STR("Episodic")); } _if_result_610; })); } _if_result_609; }); + el_val_t tier = ({ el_val_t _if_result_662 = 0; if (!str_eq(body_tier, EL_STR(""))) { _if_result_662 = (body_tier); } else { _if_result_662 = (({ el_val_t _if_result_663 = 0; if (!str_eq(old_tier, EL_STR(""))) { _if_result_663 = (old_tier); } else { _if_result_663 = (EL_STR("Episodic")); } _if_result_663; })); } _if_result_662; }); el_val_t body_tags = json_get(body, EL_STR("tags")); - el_val_t tags = ({ el_val_t _if_result_611 = 0; if (str_eq(body_tags, EL_STR(""))) { _if_result_611 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_611 = (body_tags); } _if_result_611; }); + el_val_t tags = ({ el_val_t _if_result_664 = 0; if (str_eq(body_tags, EL_STR(""))) { _if_result_664 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_664 = (body_tags); } _if_result_664; }); el_val_t new_id = wt_node(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)) { return api_not_persisted(new_id); @@ -29931,15 +30158,15 @@ el_val_t handle_api_node_update(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_612 = 0; if (str_eq(api_query_param(path, EL_STR("query")), EL_STR(""))) { _if_result_612 = (api_query_param(path, EL_STR("q"))); } else { _if_result_612 = (api_query_param(path, EL_STR("query"))); } _if_result_612; }); + el_val_t url_q = ({ el_val_t _if_result_665 = 0; if (str_eq(api_query_param(path, EL_STR("query")), EL_STR(""))) { _if_result_665 = (api_query_param(path, EL_STR("q"))); } else { _if_result_665 = (api_query_param(path, EL_STR("query"))); } _if_result_665; }); 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 q = ({ el_val_t _if_result_613 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_613 = (url_q); } else { _if_result_613 = (({ el_val_t _if_result_614 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_614 = (body_query); } else { _if_result_614 = (body_q); } _if_result_614; })); } _if_result_613; }); + el_val_t q = ({ el_val_t _if_result_666 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_666 = (url_q); } else { _if_result_666 = (({ el_val_t _if_result_667 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_667 = (body_query); } else { _if_result_667 = (body_q); } _if_result_667; })); } _if_result_666; }); el_val_t chain = json_get(body, EL_STR("chain_name")); el_val_t limit = api_query_int(path, EL_STR("limit"), 0); - limit = ({ el_val_t _if_result_615 = 0; if ((limit == 0)) { _if_result_615 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_615 = (limit); } _if_result_615; }); - limit = ({ el_val_t _if_result_616 = 0; if ((limit == 0)) { _if_result_616 = (10); } else { _if_result_616 = (limit); } _if_result_616; }); - el_val_t eff_q = ({ el_val_t _if_result_617 = 0; if (str_eq(q, EL_STR(""))) { _if_result_617 = (chain); } else { _if_result_617 = (q); } _if_result_617; }); + limit = ({ el_val_t _if_result_668 = 0; if ((limit == 0)) { _if_result_668 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_668 = (limit); } _if_result_668; }); + limit = ({ el_val_t _if_result_669 = 0; if ((limit == 0)) { _if_result_669 = (10); } else { _if_result_669 = (limit); } _if_result_669; }); + el_val_t eff_q = ({ el_val_t _if_result_670 = 0; if (str_eq(q, EL_STR(""))) { _if_result_670 = (chain); } else { _if_result_670 = (q); } _if_result_670; }); if (str_eq(eff_q, EL_STR(""))) { return api_or_empty(engram_scan_nodes_json(limit, 0)); } @@ -29952,10 +30179,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 body_query = json_get(body, EL_STR("query")); el_val_t body_q = json_get(body, EL_STR("q")); - el_val_t q = ({ el_val_t _if_result_618 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_618 = (url_q); } else { _if_result_618 = (({ el_val_t _if_result_619 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_619 = (body_query); } else { _if_result_619 = (body_q); } _if_result_619; })); } _if_result_618; }); + el_val_t q = ({ el_val_t _if_result_671 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_671 = (url_q); } else { _if_result_671 = (({ el_val_t _if_result_672 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_672 = (body_query); } else { _if_result_672 = (body_q); } _if_result_672; })); } _if_result_671; }); el_val_t limit = api_query_int(path, EL_STR("limit"), 0); - limit = ({ el_val_t _if_result_620 = 0; if ((limit == 0)) { _if_result_620 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_620 = (limit); } _if_result_620; }); - limit = ({ el_val_t _if_result_621 = 0; if ((limit == 0)) { _if_result_621 = (10); } else { _if_result_621 = (limit); } _if_result_621; }); + limit = ({ el_val_t _if_result_673 = 0; if ((limit == 0)) { _if_result_673 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_673 = (limit); } _if_result_673; }); + limit = ({ el_val_t _if_result_674 = 0; if ((limit == 0)) { _if_result_674 = (10); } else { _if_result_674 = (limit); } _if_result_674; }); if (str_eq(q, EL_STR(""))) { return api_err(EL_STR("query is required")); } @@ -29983,7 +30210,7 @@ el_val_t handle_api_capture_knowledge(el_val_t body) { if (str_eq(content, EL_STR(""))) { return api_err(EL_STR("content is required")); } - el_val_t full = ({ el_val_t _if_result_622 = 0; if (str_eq(title, EL_STR(""))) { _if_result_622 = (content); } else { _if_result_622 = (el_str_concat(el_str_concat(title, EL_STR(": ")), content)); } _if_result_622; }); + el_val_t full = ({ el_val_t _if_result_675 = 0; if (str_eq(title, EL_STR(""))) { _if_result_675 = (content); } else { _if_result_675 = (el_str_concat(el_str_concat(title, EL_STR(": ")), content)); } _if_result_675; }); el_val_t lbl = str_slice(title, 0, 80); el_val_t tags = EL_STR("[\"Knowledge\",\"captured\"]"); el_val_t id = wt_node(full, EL_STR("Knowledge"), lbl, el_from_float(0.85), el_from_float(0.8), el_from_float(0.9), EL_STR("Episodic"), tags); @@ -30025,7 +30252,7 @@ el_val_t handle_api_promote_knowledge(el_val_t body) { 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 = ({ el_val_t _if_result_623 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_623 = (EL_STR("[\"Knowledge\",\"tier:canonical\",\"disposition:stable\"]")); } else { _if_result_623 = (tags_raw); } _if_result_623; }); + el_val_t tags = ({ el_val_t _if_result_676 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_676 = (EL_STR("[\"Knowledge\",\"tier:canonical\",\"disposition:stable\"]")); } else { _if_result_676 = (tags_raw); } _if_result_676; }); el_val_t new_id = wt_node(content, EL_STR("Knowledge"), EL_STR(""), el_from_float(0.9), el_from_float(0.9), el_from_float(1.0), EL_STR("Canonical"), tags); if (!api_persisted(new_id)) { return api_not_persisted(new_id); @@ -30036,7 +30263,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 name = ({ el_val_t _if_result_624 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_624 = (api_query_param(path, EL_STR("name"))); } else { _if_result_624 = (json_get(body, EL_STR("name"))); } _if_result_624; }); + el_val_t name = ({ el_val_t _if_result_677 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_677 = (api_query_param(path, EL_STR("name"))); } else { _if_result_677 = (json_get(body, EL_STR("name"))); } _if_result_677; }); el_val_t limit = api_query_int(path, EL_STR("limit"), 50); if (str_eq(name, EL_STR(""))) { return api_or_empty(engram_scan_nodes_by_type_json(EL_STR("Process"), limit, 0)); @@ -30051,7 +30278,7 @@ el_val_t handle_api_define_process(el_val_t body) { if (str_eq(content, EL_STR(""))) { return api_err(EL_STR("content is required")); } - el_val_t label = ({ el_val_t _if_result_625 = 0; if (str_eq(name, EL_STR(""))) { _if_result_625 = (EL_STR("process:unnamed")); } else { _if_result_625 = (el_str_concat(EL_STR("process:"), name)); } _if_result_625; }); + el_val_t label = ({ el_val_t _if_result_678 = 0; if (str_eq(name, EL_STR(""))) { _if_result_678 = (EL_STR("process:unnamed")); } else { _if_result_678 = (el_str_concat(EL_STR("process:"), name)); } _if_result_678; }); el_val_t tags = EL_STR("[\"Process\"]"); el_val_t id = wt_node(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)) { @@ -30069,12 +30296,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 legacy = json_get(body, EL_STR("content")); el_val_t parts = EL_STR("INTERNAL STATE EVENT"); - parts = ({ el_val_t _if_result_626 = 0; if (!str_eq(trigger, EL_STR(""))) { _if_result_626 = (el_str_concat(el_str_concat(parts, EL_STR("\nTrigger: ")), trigger)); } else { _if_result_626 = (parts); } _if_result_626; }); - parts = ({ el_val_t _if_result_627 = 0; if (!str_eq(pre, EL_STR(""))) { _if_result_627 = (el_str_concat(el_str_concat(parts, EL_STR("\nPre-reasoning: ")), pre)); } else { _if_result_627 = (parts); } _if_result_627; }); - parts = ({ el_val_t _if_result_628 = 0; if (!str_eq(post, EL_STR(""))) { _if_result_628 = (el_str_concat(el_str_concat(parts, EL_STR("\nPost-reasoning: ")), post)); } else { _if_result_628 = (parts); } _if_result_628; }); - parts = ({ el_val_t _if_result_629 = 0; if (!str_eq(ratio, EL_STR(""))) { _if_result_629 = (el_str_concat(el_str_concat(parts, EL_STR("\nCompression-ratio: ")), ratio)); } else { _if_result_629 = (parts); } _if_result_629; }); - parts = ({ el_val_t _if_result_630 = 0; if (!str_eq(gap, EL_STR(""))) { _if_result_630 = (el_str_concat(el_str_concat(parts, EL_STR("\nGap-direction: ")), gap)); } else { _if_result_630 = (parts); } _if_result_630; }); - parts = ({ el_val_t _if_result_631 = 0; if (!str_eq(legacy, EL_STR(""))) { _if_result_631 = (el_str_concat(el_str_concat(parts, EL_STR("\n")), legacy)); } else { _if_result_631 = (parts); } _if_result_631; }); + parts = ({ el_val_t _if_result_679 = 0; if (!str_eq(trigger, EL_STR(""))) { _if_result_679 = (el_str_concat(el_str_concat(parts, EL_STR("\nTrigger: ")), trigger)); } else { _if_result_679 = (parts); } _if_result_679; }); + parts = ({ el_val_t _if_result_680 = 0; if (!str_eq(pre, EL_STR(""))) { _if_result_680 = (el_str_concat(el_str_concat(parts, EL_STR("\nPre-reasoning: ")), pre)); } else { _if_result_680 = (parts); } _if_result_680; }); + parts = ({ el_val_t _if_result_681 = 0; if (!str_eq(post, EL_STR(""))) { _if_result_681 = (el_str_concat(el_str_concat(parts, EL_STR("\nPost-reasoning: ")), post)); } else { _if_result_681 = (parts); } _if_result_681; }); + parts = ({ el_val_t _if_result_682 = 0; if (!str_eq(ratio, EL_STR(""))) { _if_result_682 = (el_str_concat(el_str_concat(parts, EL_STR("\nCompression-ratio: ")), ratio)); } else { _if_result_682 = (parts); } _if_result_682; }); + parts = ({ el_val_t _if_result_683 = 0; if (!str_eq(gap, EL_STR(""))) { _if_result_683 = (el_str_concat(el_str_concat(parts, EL_STR("\nGap-direction: ")), gap)); } else { _if_result_683 = (parts); } _if_result_683; }); + parts = ({ el_val_t _if_result_684 = 0; if (!str_eq(legacy, EL_STR(""))) { _if_result_684 = (el_str_concat(el_str_concat(parts, EL_STR("\n")), legacy)); } else { _if_result_684 = (parts); } _if_result_684; }); el_val_t ts = time_now(); el_val_t boot = state_get(EL_STR("soul_boot_count")); el_val_t tags = EL_STR("[\"internal-state\",\"InternalStateEvent\",\"pre-reasoning\"]"); @@ -30087,7 +30314,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 q = ({ el_val_t _if_result_632 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_632 = (api_query_param(path, EL_STR("query"))); } else { _if_result_632 = (json_get(body, EL_STR("query"))); } _if_result_632; }); + el_val_t q = ({ el_val_t _if_result_685 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_685 = (api_query_param(path, EL_STR("query"))); } else { _if_result_685 = (json_get(body, EL_STR("query"))); } _if_result_685; }); el_val_t limit = api_query_int(path, EL_STR("limit"), 20); if (!str_eq(q, EL_STR(""))) { return api_or_empty(engram_search_json(el_str_concat(EL_STR("internal state "), q), limit)); @@ -30098,7 +30325,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 key = api_query_param(path, EL_STR("key")); - key = ({ el_val_t _if_result_633 = 0; if (str_eq(key, EL_STR(""))) { _if_result_633 = (json_get(body, EL_STR("key"))); } else { _if_result_633 = (key); } _if_result_633; }); + key = ({ el_val_t _if_result_686 = 0; if (str_eq(key, EL_STR(""))) { _if_result_686 = (json_get(body, EL_STR("key"))); } else { _if_result_686 = (key); } _if_result_686; }); if (str_eq(key, EL_STR(""))) { return EL_STR("{\"hint\":\"pass ?key=\",\"known\":[\"neuron.self.traversal_root\",\"neuron.self.values_hub\"]}"); } @@ -30115,7 +30342,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 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 value = ({ el_val_t _if_result_634 = 0; if (str_starts_with(content, prefix)) { _if_result_634 = (str_slice(content, str_len(prefix), str_len(content))); } else { _if_result_634 = (content); } _if_result_634; }); + el_val_t value = ({ el_val_t _if_result_687 = 0; if (str_starts_with(content, prefix)) { _if_result_687 = (str_slice(content, str_len(prefix), str_len(content))); } else { _if_result_687 = (content); } _if_result_687; }); 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; } @@ -30137,13 +30364,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 entity_id = ({ el_val_t _if_result_635 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_635 = (api_query_param(path, EL_STR("id"))); } else { _if_result_635 = (json_get(body, EL_STR("entity_id"))); } _if_result_635; }); - el_val_t name = ({ el_val_t _if_result_636 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_636 = (api_query_param(path, EL_STR("name"))); } else { _if_result_636 = (json_get(body, EL_STR("name"))); } _if_result_636; }); + el_val_t entity_id = ({ el_val_t _if_result_688 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_688 = (api_query_param(path, EL_STR("id"))); } else { _if_result_688 = (json_get(body, EL_STR("entity_id"))); } _if_result_688; }); + el_val_t name = ({ el_val_t _if_result_689 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_689 = (api_query_param(path, EL_STR("name"))); } else { _if_result_689 = (json_get(body, EL_STR("name"))); } _if_result_689; }); el_val_t depth = api_query_int(path, EL_STR("depth"), 0); - depth = ({ el_val_t _if_result_637 = 0; if ((depth == 0)) { _if_result_637 = (json_get_int(body, EL_STR("max_depth"))); } else { _if_result_637 = (depth); } _if_result_637; }); - depth = ({ el_val_t _if_result_638 = 0; if ((depth == 0)) { _if_result_638 = (1); } else { _if_result_638 = (depth); } _if_result_638; }); + depth = ({ el_val_t _if_result_690 = 0; if ((depth == 0)) { _if_result_690 = (json_get_int(body, EL_STR("max_depth"))); } else { _if_result_690 = (depth); } _if_result_690; }); + depth = ({ el_val_t _if_result_691 = 0; if ((depth == 0)) { _if_result_691 = (1); } else { _if_result_691 = (depth); } _if_result_691; }); el_val_t resolved = entity_id; - resolved = ({ el_val_t _if_result_639 = 0; if (str_eq(resolved, EL_STR(""))) { _if_result_639 = (({ el_val_t _if_result_640 = 0; if ((str_eq(name, EL_STR("self")) || str_eq(name, EL_STR("neuron")))) { _if_result_640 = (EL_STR("kn-efeb4a5b-5aff-4759-8a97-7233099be6ee")); } else { _if_result_640 = (({ el_val_t _if_result_641 = 0; if ((str_eq(name, EL_STR("values")) || str_eq(name, EL_STR("values_hub")))) { _if_result_641 = (EL_STR("kn-5b606390-a52d-4ca2-8e0e-eba141d13440")); } else { _if_result_641 = (EL_STR("")); } _if_result_641; })); } _if_result_640; })); } else { _if_result_639 = (resolved); } _if_result_639; }); + resolved = ({ el_val_t _if_result_692 = 0; if (str_eq(resolved, EL_STR(""))) { _if_result_692 = (({ el_val_t _if_result_693 = 0; if ((str_eq(name, EL_STR("self")) || str_eq(name, EL_STR("neuron")))) { _if_result_693 = (EL_STR("kn-efeb4a5b-5aff-4759-8a97-7233099be6ee")); } else { _if_result_693 = (({ el_val_t _if_result_694 = 0; if ((str_eq(name, EL_STR("values")) || str_eq(name, EL_STR("values_hub")))) { _if_result_694 = (EL_STR("kn-5b606390-a52d-4ca2-8e0e-eba141d13440")); } else { _if_result_694 = (EL_STR("")); } _if_result_694; })); } _if_result_693; })); } else { _if_result_692 = (resolved); } _if_result_692; }); if (str_eq(resolved, EL_STR(""))) { return api_err(EL_STR("entity_id or name required. Known names: self, neuron, values, values_hub")); } @@ -30165,7 +30392,7 @@ el_val_t handle_api_link_entities(el_val_t body) { return api_err_protected(to_id); } el_val_t relation = json_get(body, EL_STR("relation")); - el_val_t eff_relation = ({ el_val_t _if_result_642 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_642 = (EL_STR("associates")); } else { _if_result_642 = (relation); } _if_result_642; }); + el_val_t eff_relation = ({ el_val_t _if_result_695 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_695 = (EL_STR("associates")); } else { _if_result_695 = (relation); } _if_result_695; }); wt_edge(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 0; @@ -30194,8 +30421,8 @@ el_val_t handle_api_evolve_memory(el_val_t body) { return api_err_protected(prior_id); } el_val_t importance = json_get(body, EL_STR("importance")); - el_val_t sal_str = ({ el_val_t _if_result_643 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_643 = (EL_STR("0.95")); } else { _if_result_643 = (({ el_val_t _if_result_644 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_644 = (EL_STR("0.75")); } else { _if_result_644 = (({ el_val_t _if_result_645 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_645 = (EL_STR("0.25")); } else { _if_result_645 = (EL_STR("0.50")); } _if_result_645; })); } _if_result_644; })); } _if_result_643; }); - el_val_t sal = ({ el_val_t _if_result_646 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_646 = (el_from_float(0.95)); } else { _if_result_646 = (({ el_val_t _if_result_647 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_647 = (el_from_float(0.75)); } else { _if_result_647 = (({ el_val_t _if_result_648 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_648 = (el_from_float(0.25)); } else { _if_result_648 = (el_from_float(0.5)); } _if_result_648; })); } _if_result_647; })); } _if_result_646; }); + el_val_t sal_str = ({ el_val_t _if_result_696 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_696 = (EL_STR("0.95")); } else { _if_result_696 = (({ el_val_t _if_result_697 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_697 = (EL_STR("0.75")); } else { _if_result_697 = (({ el_val_t _if_result_698 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_698 = (EL_STR("0.25")); } else { _if_result_698 = (EL_STR("0.50")); } _if_result_698; })); } _if_result_697; })); } _if_result_696; }); + el_val_t sal = ({ el_val_t _if_result_699 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_699 = (el_from_float(0.95)); } else { _if_result_699 = (({ el_val_t _if_result_700 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_700 = (el_from_float(0.75)); } else { _if_result_700 = (({ el_val_t _if_result_701 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_701 = (el_from_float(0.25)); } else { _if_result_701 = (el_from_float(0.5)); } _if_result_701; })); } _if_result_700; })); } _if_result_699; }); el_val_t tags = EL_STR("[\"Memory\",\"evolved\"]"); el_val_t new_id = wt_node(content, EL_STR("Memory"), EL_STR("memory:evolved"), sal, sal, el_from_float(0.9), EL_STR("Episodic"), tags); if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) { @@ -30270,7 +30497,7 @@ el_val_t handle_api_cultivate(el_val_t body) { return api_err(EL_STR("content is required")); } el_val_t importance = json_get(body, EL_STR("importance")); - el_val_t sal = ({ el_val_t _if_result_649 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_649 = (el_from_float(0.95)); } else { _if_result_649 = (({ el_val_t _if_result_650 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_650 = (el_from_float(0.75)); } else { _if_result_650 = (({ el_val_t _if_result_651 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_651 = (el_from_float(0.25)); } else { _if_result_651 = (el_from_float(0.5)); } _if_result_651; })); } _if_result_650; })); } _if_result_649; }); + el_val_t sal = ({ el_val_t _if_result_702 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_702 = (el_from_float(0.95)); } else { _if_result_702 = (({ el_val_t _if_result_703 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_703 = (el_from_float(0.75)); } else { _if_result_703 = (({ el_val_t _if_result_704 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_704 = (el_from_float(0.25)); } else { _if_result_704 = (el_from_float(0.5)); } _if_result_704; })); } _if_result_703; })); } _if_result_702; }); el_val_t tags = EL_STR("[\"Memory\",\"evolved\",\"cultivated\"]"); el_val_t new_id = wt_node(content, EL_STR("Memory"), EL_STR("memory:cultivated"), sal, sal, el_from_float(0.9), EL_STR("Episodic"), tags); if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) { @@ -30296,7 +30523,7 @@ el_val_t handle_api_cultivate(el_val_t body) { return api_err(EL_STR("to_id is required")); } el_val_t relation = json_get(body, EL_STR("relation")); - el_val_t eff_relation = ({ el_val_t _if_result_652 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_652 = (EL_STR("associates")); } else { _if_result_652 = (relation); } _if_result_652; }); + el_val_t eff_relation = ({ el_val_t _if_result_705 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_705 = (EL_STR("associates")); } else { _if_result_705 = (relation); } _if_result_705; }); wt_edge(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}")); } @@ -30337,11 +30564,11 @@ el_val_t audit_pct1(el_val_t num, el_val_t den) { return EL_STR("null"); } el_val_t neg = (num < 0); - el_val_t a = ({ el_val_t _if_result_653 = 0; if (neg) { _if_result_653 = ((0 - num)); } else { _if_result_653 = (num); } _if_result_653; }); + el_val_t a = ({ el_val_t _if_result_706 = 0; if (neg) { _if_result_706 = ((0 - num)); } else { _if_result_706 = (num); } _if_result_706; }); el_val_t tenths = ((a * 1000) / den); el_val_t whole = (tenths / 10); el_val_t frac = (tenths - (whole * 10)); - el_val_t sign = ({ el_val_t _if_result_654 = 0; if (neg) { _if_result_654 = (EL_STR("-")); } else { _if_result_654 = (EL_STR("")); } _if_result_654; }); + el_val_t sign = ({ el_val_t _if_result_707 = 0; if (neg) { _if_result_707 = (EL_STR("-")); } else { _if_result_707 = (EL_STR("")); } _if_result_707; }); return el_str_concat(el_str_concat(el_str_concat(sign, int_to_str(whole)), EL_STR(".")), int_to_str(frac)); return 0; } @@ -30357,7 +30584,7 @@ el_val_t audit_str_at(el_val_t s, el_val_t start, el_val_t maxlen) { return EL_STR(""); } el_val_t end_guess = (start + maxlen); - el_val_t stop = ({ el_val_t _if_result_655 = 0; if ((end_guess > n)) { _if_result_655 = (n); } else { _if_result_655 = (end_guess); } _if_result_655; }); + el_val_t stop = ({ el_val_t _if_result_708 = 0; if ((end_guess > n)) { _if_result_708 = (n); } else { _if_result_708 = (end_guess); } _if_result_708; }); el_val_t win = str_slice(s, start, stop); el_val_t q = str_index_of(win, EL_STR("\"")); if (q < 0) { @@ -30398,13 +30625,13 @@ el_val_t audit_divergence(void) { el_val_t d_edges = (rt_edges - ow_edges); el_val_t prev_raw = state_get(EL_STR("audit_prev_node_delta")); el_val_t prev = str_to_int(prev_raw); - el_val_t abs_now = ({ el_val_t _if_result_656 = 0; if ((d_nodes < 0)) { _if_result_656 = ((0 - d_nodes)); } else { _if_result_656 = (d_nodes); } _if_result_656; }); - el_val_t abs_prev = ({ el_val_t _if_result_657 = 0; if ((prev < 0)) { _if_result_657 = ((0 - prev)); } else { _if_result_657 = (prev); } _if_result_657; }); - el_val_t trend = ({ el_val_t _if_result_658 = 0; if (str_eq(prev_raw, EL_STR(""))) { _if_result_658 = (EL_STR("no_prior_audit")); } else { _if_result_658 = (({ el_val_t _if_result_659 = 0; if ((abs_now > abs_prev)) { _if_result_659 = (EL_STR("growing")); } else { _if_result_659 = (({ el_val_t _if_result_660 = 0; if ((abs_now < abs_prev)) { _if_result_660 = (EL_STR("shrinking")); } else { _if_result_660 = (EL_STR("flat")); } _if_result_660; })); } _if_result_659; })); } _if_result_658; }); + el_val_t abs_now = ({ el_val_t _if_result_709 = 0; if ((d_nodes < 0)) { _if_result_709 = ((0 - d_nodes)); } else { _if_result_709 = (d_nodes); } _if_result_709; }); + el_val_t abs_prev = ({ el_val_t _if_result_710 = 0; if ((prev < 0)) { _if_result_710 = ((0 - prev)); } else { _if_result_710 = (prev); } _if_result_710; }); + el_val_t trend = ({ el_val_t _if_result_711 = 0; if (str_eq(prev_raw, EL_STR(""))) { _if_result_711 = (EL_STR("no_prior_audit")); } else { _if_result_711 = (({ el_val_t _if_result_712 = 0; if ((abs_now > abs_prev)) { _if_result_712 = (EL_STR("growing")); } else { _if_result_712 = (({ el_val_t _if_result_713 = 0; if ((abs_now < abs_prev)) { _if_result_713 = (EL_STR("shrinking")); } else { _if_result_713 = (EL_STR("flat")); } _if_result_713; })); } _if_result_712; })); } _if_result_711; }); state_set(EL_STR("audit_prev_node_delta"), int_to_str(d_nodes)); state_set(EL_STR("audit_prev_ts"), int_to_str(time_now())); - el_val_t note_head = ({ el_val_t _if_result_661 = 0; if ((d_nodes == 0)) { _if_result_661 = (EL_STR("Runtime and owner agree on node count.")); } else { _if_result_661 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("Runtime holds "), int_to_str(d_nodes)), EL_STR(" nodes (")), audit_pct1(d_nodes, rt_nodes)), EL_STR("% of its own graph) that the persistence owner does not report. Nodes ")), EL_STR("that exist only in runtime memory do not survive a restart."))); } _if_result_661; }); - return audit_finding(EL_STR("owner_runtime_divergence"), 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_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("\"runtime_nodes\":"), int_to_str(rt_nodes)), EL_STR(",\"runtime_edges\":")), int_to_str(rt_edges)), EL_STR(",\"owner\":\"")), api_json_escape(url)), EL_STR("\",\"owner_reachable\":true")), EL_STR(",\"owner_nodes\":")), int_to_str(ow_nodes)), EL_STR(",\"owner_edges\":")), int_to_str(ow_edges)), EL_STR(",\"node_delta\":")), int_to_str(d_nodes)), EL_STR(",\"edge_delta\":")), int_to_str(d_edges)), EL_STR(",\"node_delta_pct_of_runtime\":")), audit_pct1(d_nodes, rt_nodes)), EL_STR(",\"trend_vs_previous_audit\":\"")), trend), EL_STR("\"")), EL_STR(",\"previous_node_delta\":")), ({ el_val_t _if_result_662 = 0; if (str_eq(prev_raw, EL_STR(""))) { _if_result_662 = (EL_STR("null")); } else { _if_result_662 = (int_to_str(prev)); } _if_result_662; })), el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(note_head, EL_STR(" Trend against the previous audit recorded in this soul's ")), EL_STR("state: ")), trend), EL_STR(". This is the comparison whose absence let a ")), EL_STR("~24,000-node loss run for weeks with every boot reporting green."))); + el_val_t note_head = ({ el_val_t _if_result_714 = 0; if ((d_nodes == 0)) { _if_result_714 = (EL_STR("Runtime and owner agree on node count.")); } else { _if_result_714 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("Runtime holds "), int_to_str(d_nodes)), EL_STR(" nodes (")), audit_pct1(d_nodes, rt_nodes)), EL_STR("% of its own graph) that the persistence owner does not report. Nodes ")), EL_STR("that exist only in runtime memory do not survive a restart."))); } _if_result_714; }); + return audit_finding(EL_STR("owner_runtime_divergence"), 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_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("\"runtime_nodes\":"), int_to_str(rt_nodes)), EL_STR(",\"runtime_edges\":")), int_to_str(rt_edges)), EL_STR(",\"owner\":\"")), api_json_escape(url)), EL_STR("\",\"owner_reachable\":true")), EL_STR(",\"owner_nodes\":")), int_to_str(ow_nodes)), EL_STR(",\"owner_edges\":")), int_to_str(ow_edges)), EL_STR(",\"node_delta\":")), int_to_str(d_nodes)), EL_STR(",\"edge_delta\":")), int_to_str(d_edges)), EL_STR(",\"node_delta_pct_of_runtime\":")), audit_pct1(d_nodes, rt_nodes)), EL_STR(",\"trend_vs_previous_audit\":\"")), trend), EL_STR("\"")), EL_STR(",\"previous_node_delta\":")), ({ el_val_t _if_result_715 = 0; if (str_eq(prev_raw, EL_STR(""))) { _if_result_715 = (EL_STR("null")); } else { _if_result_715 = (int_to_str(prev)); } _if_result_715; })), el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(note_head, EL_STR(" Trend against the previous audit recorded in this soul's ")), EL_STR("state: ")), trend), EL_STR(". This is the comparison whose absence let a ")), EL_STR("~24,000-node loss run for weeks with every boot reporting green."))); return 0; } @@ -30433,9 +30660,9 @@ el_val_t audit_edge_typing(el_val_t edges, el_val_t total_edges, el_val_t node_t } el_val_t audit_orphans_dangling(el_val_t edges, el_val_t total_edges, el_val_t node_total, el_val_t edge_cap, el_val_t node_cap) { - el_val_t n_take = ({ el_val_t _if_result_663 = 0; if ((node_total < node_cap)) { _if_result_663 = (node_total); } else { _if_result_663 = (node_cap); } _if_result_663; }); - el_val_t n_stride = ({ el_val_t _if_result_664 = 0; if ((n_take > 0)) { _if_result_664 = ((node_total / n_take)); } else { _if_result_664 = (1); } _if_result_664; }); - n_stride = ({ el_val_t _if_result_665 = 0; if ((n_stride < 1)) { _if_result_665 = (1); } else { _if_result_665 = (n_stride); } _if_result_665; }); + el_val_t n_take = ({ el_val_t _if_result_716 = 0; if ((node_total < node_cap)) { _if_result_716 = (node_total); } else { _if_result_716 = (node_cap); } _if_result_716; }); + el_val_t n_stride = ({ el_val_t _if_result_717 = 0; if ((n_take > 0)) { _if_result_717 = ((node_total / n_take)); } else { _if_result_717 = (1); } _if_result_717; }); + n_stride = ({ el_val_t _if_result_718 = 0; if ((n_stride < 1)) { _if_result_718 = (1); } else { _if_result_718 = (n_stride); } _if_result_718; }); el_val_t orphans = 0; el_val_t n_checked = 0; el_val_t j = 0; @@ -30445,7 +30672,7 @@ el_val_t audit_orphans_dangling(el_val_t edges, el_val_t total_edges, el_val_t n if (!str_eq(nid, EL_STR(""))) { el_val_t nbrs = engram_neighbors_json(nid, 1, EL_STR("both")); el_val_t deg = json_array_len(nbrs); - orphans = ({ el_val_t _if_result_666 = 0; if ((deg == 0)) { _if_result_666 = ((orphans + 1)); } else { _if_result_666 = (orphans); } _if_result_666; }); + orphans = ({ el_val_t _if_result_719 = 0; if ((deg == 0)) { _if_result_719 = ((orphans + 1)); } else { _if_result_719 = (orphans); } _if_result_719; }); n_checked = (n_checked + 1); } j = (j + 1); @@ -30454,10 +30681,10 @@ el_val_t audit_orphans_dangling(el_val_t edges, el_val_t total_edges, el_val_t n el_val_t to_pos = str_index_of_all(edges, EL_STR("\"to_id\":\"")); el_val_t nf = len(from_pos); el_val_t nt = len(to_pos); - el_val_t ne = ({ el_val_t _if_result_667 = 0; if ((nf < nt)) { _if_result_667 = (nf); } else { _if_result_667 = (nt); } _if_result_667; }); - el_val_t e_take = ({ el_val_t _if_result_668 = 0; if ((ne < edge_cap)) { _if_result_668 = (ne); } else { _if_result_668 = (edge_cap); } _if_result_668; }); - el_val_t e_stride = ({ el_val_t _if_result_669 = 0; if ((e_take > 0)) { _if_result_669 = ((ne / e_take)); } else { _if_result_669 = (1); } _if_result_669; }); - e_stride = ({ el_val_t _if_result_670 = 0; if ((e_stride < 1)) { _if_result_670 = (1); } else { _if_result_670 = (e_stride); } _if_result_670; }); + el_val_t ne = ({ el_val_t _if_result_720 = 0; if ((nf < nt)) { _if_result_720 = (nf); } else { _if_result_720 = (nt); } _if_result_720; }); + el_val_t e_take = ({ el_val_t _if_result_721 = 0; if ((ne < edge_cap)) { _if_result_721 = (ne); } else { _if_result_721 = (edge_cap); } _if_result_721; }); + el_val_t e_stride = ({ el_val_t _if_result_722 = 0; if ((e_take > 0)) { _if_result_722 = ((ne / e_take)); } else { _if_result_722 = (1); } _if_result_722; }); + e_stride = ({ el_val_t _if_result_723 = 0; if ((e_stride < 1)) { _if_result_723 = (1); } else { _if_result_723 = (e_stride); } _if_result_723; }); el_val_t dangling = 0; el_val_t e_checked = 0; el_val_t i = 0; @@ -30465,15 +30692,15 @@ el_val_t audit_orphans_dangling(el_val_t edges, el_val_t total_edges, el_val_t n el_val_t fid = audit_str_at(edges, (get(from_pos, i) + 11), 96); el_val_t tid = audit_str_at(edges, (get(to_pos, i) + 9), 96); el_val_t f_gone = str_eq(engram_get_node_json(fid), EL_STR("{}")); - el_val_t t_gone = ({ el_val_t _if_result_671 = 0; if (f_gone) { _if_result_671 = (1); } else { _if_result_671 = (str_eq(engram_get_node_json(tid), EL_STR("{}"))); } _if_result_671; }); - dangling = ({ el_val_t _if_result_672 = 0; if ((f_gone || t_gone)) { _if_result_672 = ((dangling + 1)); } else { _if_result_672 = (dangling); } _if_result_672; }); + el_val_t t_gone = ({ el_val_t _if_result_724 = 0; if (f_gone) { _if_result_724 = (1); } else { _if_result_724 = (str_eq(engram_get_node_json(tid), EL_STR("{}"))); } _if_result_724; }); + dangling = ({ el_val_t _if_result_725 = 0; if ((f_gone || t_gone)) { _if_result_725 = ((dangling + 1)); } else { _if_result_725 = (dangling); } _if_result_725; }); e_checked = (e_checked + 1); i = (i + e_stride); } - el_val_t orphan_est = ({ el_val_t _if_result_673 = 0; if ((n_checked > 0)) { _if_result_673 = (((orphans * node_total) / n_checked)); } else { _if_result_673 = (0); } _if_result_673; }); - el_val_t dangle_est = ({ el_val_t _if_result_674 = 0; if ((e_checked > 0)) { _if_result_674 = (((dangling * total_edges) / e_checked)); } else { _if_result_674 = (0); } _if_result_674; }); - el_val_t exhaustive_n = ({ el_val_t _if_result_675 = 0; if ((n_checked >= node_total)) { _if_result_675 = (EL_STR("true")); } else { _if_result_675 = (EL_STR("false")); } _if_result_675; }); - el_val_t exhaustive_e = ({ el_val_t _if_result_676 = 0; if ((e_checked >= ne)) { _if_result_676 = (EL_STR("true")); } else { _if_result_676 = (EL_STR("false")); } _if_result_676; }); + el_val_t orphan_est = ({ el_val_t _if_result_726 = 0; if ((n_checked > 0)) { _if_result_726 = (((orphans * node_total) / n_checked)); } else { _if_result_726 = (0); } _if_result_726; }); + el_val_t dangle_est = ({ el_val_t _if_result_727 = 0; if ((e_checked > 0)) { _if_result_727 = (((dangling * total_edges) / e_checked)); } else { _if_result_727 = (0); } _if_result_727; }); + el_val_t exhaustive_n = ({ el_val_t _if_result_728 = 0; if ((n_checked >= node_total)) { _if_result_728 = (EL_STR("true")); } else { _if_result_728 = (EL_STR("false")); } _if_result_728; }); + el_val_t exhaustive_e = ({ el_val_t _if_result_729 = 0; if ((e_checked >= ne)) { _if_result_729 = (EL_STR("true")); } else { _if_result_729 = (EL_STR("false")); } _if_result_729; }); return audit_finding(EL_STR("orphans_and_dangling_edges"), 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_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("\"nodes_population\":"), int_to_str(node_total)), EL_STR(",\"nodes_sampled\":")), int_to_str(n_checked)), EL_STR(",\"nodes_sample_exhaustive\":")), exhaustive_n), EL_STR(",\"orphans_in_sample\":")), int_to_str(orphans)), EL_STR(",\"orphan_rate_pct\":")), audit_pct1(orphans, n_checked)), EL_STR(",\"orphans_extrapolated\":")), int_to_str(orphan_est)), EL_STR(",\"edges_population\":")), int_to_str(total_edges)), EL_STR(",\"edges_sampled\":")), int_to_str(e_checked)), EL_STR(",\"edges_sample_exhaustive\":")), exhaustive_e), EL_STR(",\"dangling_in_sample\":")), int_to_str(dangling)), EL_STR(",\"dangling_rate_pct\":")), audit_pct1(dangling, e_checked)), EL_STR(",\"dangling_extrapolated\":")), int_to_str(dangle_est)), 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("Orphan = zero RESOLVABLE edges, so a node whose only edges dangle counts "), EL_STR("as an orphan; either way it is unreachable by traversal. Dangling = an ")), EL_STR("edge with an endpoint id that resolves to no node. Both are uniform ")), EL_STR("stride samples over the whole population, not the head of the list; ")), EL_STR("the extrapolations are estimates and are labelled as such. Pass ")), EL_STR("?node_sample= / ?edge_sample= at or above the population size to run ")), EL_STR("either check exhaustively. A high orphan rate is a characterization, ")), EL_STR("not a verdict: an accumulating store legitimately holds unlinked ")), EL_STR("material. It becomes a defect when the write paths were SUPPOSED to ")), EL_STR("link and did not."))); return 0; } @@ -30514,7 +30741,7 @@ el_val_t handle_api_structural_audit(el_val_t method, el_val_t path, el_val_t bo el_val_t node_cap = api_query_int(path, EL_STR("node_sample"), 300); el_val_t divergence = audit_divergence(); el_val_t self_model = audit_self_model(); - el_val_t edge_part = ({ el_val_t _if_result_677 = 0; if (want_edges) { el_val_t scratch_dir = env(EL_STR("TMPDIR")); el_val_t scratch_base = ({ el_val_t _if_result_678 = 0; if (str_eq(scratch_dir, EL_STR(""))) { _if_result_678 = (EL_STR("/tmp")); } else { _if_result_678 = (scratch_dir); } _if_result_678; }); el_val_t snap_path = el_str_concat(el_str_concat(el_str_concat(scratch_base, EL_STR("/soul-audit-export-")), state_get(EL_STR("soul_cgi_id"))), EL_STR(".json")); el_val_t saved = engram_save(snap_path); _if_result_677 = (({ el_val_t _if_result_679 = 0; if ((saved == 0)) { _if_result_679 = (el_str_concat(EL_STR(","), audit_finding(EL_STR("typed_edge_distribution"), EL_STR("\"available\":false"), el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("Could not export the graph to "), snap_path), EL_STR(" for edge analysis, ")), EL_STR("so edge typing and the dangling-edge sample were not run. ")), EL_STR("Reported as a gap, not as zero findings."))))); } else { el_val_t snap = wt_read(snap_path); el_val_t edges_raw = json_get_raw(snap, EL_STR("edges")); el_val_t edges = ({ el_val_t _if_result_680 = 0; if (str_eq(edges_raw, EL_STR(""))) { _if_result_680 = (EL_STR("[]")); } else { _if_result_680 = (edges_raw); } _if_result_680; }); _if_result_679 = (el_str_concat(el_str_concat(el_str_concat(EL_STR(","), audit_edge_typing(edges, edge_total, node_total)), EL_STR(",")), audit_orphans_dangling(edges, edge_total, node_total, edge_cap, node_cap))); } _if_result_679; })); } else { _if_result_677 = (EL_STR("")); } _if_result_677; }); + el_val_t edge_part = ({ el_val_t _if_result_730 = 0; if (want_edges) { el_val_t scratch_dir = env(EL_STR("TMPDIR")); el_val_t scratch_base = ({ el_val_t _if_result_731 = 0; if (str_eq(scratch_dir, EL_STR(""))) { _if_result_731 = (EL_STR("/tmp")); } else { _if_result_731 = (scratch_dir); } _if_result_731; }); el_val_t snap_path = el_str_concat(el_str_concat(el_str_concat(scratch_base, EL_STR("/soul-audit-export-")), state_get(EL_STR("soul_cgi_id"))), EL_STR(".json")); el_val_t saved = engram_save(snap_path); _if_result_730 = (({ el_val_t _if_result_732 = 0; if ((saved == 0)) { _if_result_732 = (el_str_concat(EL_STR(","), audit_finding(EL_STR("typed_edge_distribution"), EL_STR("\"available\":false"), el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("Could not export the graph to "), snap_path), EL_STR(" for edge analysis, ")), EL_STR("so edge typing and the dangling-edge sample were not run. ")), EL_STR("Reported as a gap, not as zero findings."))))); } else { el_val_t snap = wt_read(snap_path); el_val_t edges_raw = json_get_raw(snap, EL_STR("edges")); el_val_t edges = ({ el_val_t _if_result_733 = 0; if (str_eq(edges_raw, EL_STR(""))) { _if_result_733 = (EL_STR("[]")); } else { _if_result_733 = (edges_raw); } _if_result_733; }); _if_result_732 = (el_str_concat(el_str_concat(el_str_concat(EL_STR(","), audit_edge_typing(edges, edge_total, node_total)), EL_STR(",")), audit_orphans_dangling(edges, edge_total, node_total, edge_cap, node_cap))); } _if_result_732; })); } else { _if_result_730 = (EL_STR("")); } _if_result_730; }); return 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_concat(el_str_concat(EL_STR("{\"audit\":\"structural\",\"stage\":1"), EL_STR(",\"spec\":\"CGI provisional 05-detailed-description.md, Stage 1: Structural audit 430\"")), EL_STR(",\"assessment\":\"coherence_assessment_432\"")), EL_STR(",\"assessment_kind\":\"annotated_characterization\"")), EL_STR(",\"score\":null")), EL_STR(",\"score_note\":\"By design. The specification calls for an annotated characterization of the graph's structural properties, not a binary score. Read the findings.\"")), EL_STR(",\"cgi_id\":\"")), api_json_escape(state_get(EL_STR("soul_cgi_id")))), EL_STR("\"")), EL_STR(",\"ts_ms\":")), int_to_str(time_now())), EL_STR(",\"findings\":[")), divergence), EL_STR(",")), self_model), edge_part), EL_STR("]")), EL_STR(",\"deferred\":")), audit_deferred()), EL_STR("}")); return 0; } @@ -30564,7 +30791,7 @@ el_val_t session_exists(el_val_t session_id) { el_val_t content = json_get(node, EL_STR("content")); el_val_t sid = json_get(content, EL_STR("id")); el_val_t is_match = (str_eq(label, EL_STR("session:meta")) && str_eq(sid, session_id)); - found = ({ el_val_t _if_result_681 = 0; if (is_match) { _if_result_681 = (1); } else { _if_result_681 = (found); } _if_result_681; }); + found = ({ el_val_t _if_result_734 = 0; if (is_match) { _if_result_734 = (1); } else { _if_result_734 = (found); } _if_result_734; }); i = (i + 1); } return found; @@ -30575,7 +30802,7 @@ el_val_t session_create(el_val_t body) { el_val_t ts = time_now(); el_val_t id = uuid_v4(); el_val_t title_req = json_get(body, EL_STR("title")); - el_val_t title = ({ el_val_t _if_result_682 = 0; if (str_eq(title_req, EL_STR(""))) { _if_result_682 = (EL_STR("New conversation")); } else { _if_result_682 = (title_req); } _if_result_682; }); + el_val_t title = ({ el_val_t _if_result_735 = 0; if (str_eq(title_req, EL_STR(""))) { _if_result_735 = (EL_STR("New conversation")); } else { _if_result_735 = (title_req); } _if_result_735; }); el_val_t folder = json_get(body, EL_STR("folder")); el_val_t content = session_make_content(id, title, ts, ts, folder); el_val_t tags = EL_STR("[\"session\",\"session:meta\",\"Conversation\"]"); @@ -30587,7 +30814,7 @@ el_val_t session_create(el_val_t body) { state_set(el_str_concat(EL_STR("session_pending_first_msg_"), id), EL_STR("1")); el_val_t existing_idx = state_get(EL_STR("session_index")); el_val_t idx_entry = 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("{\"id\":\""), id), EL_STR("\",\"title\":\"")), json_safe(title)), EL_STR("\",\"folder\":\"")), json_safe(folder)), EL_STR("\",\"created_at\":")), int_to_str(ts)), EL_STR(",\"updated_at\":")), int_to_str(ts)), EL_STR(",\"last_message\":\"\"}")); - el_val_t new_idx = ({ el_val_t _if_result_683 = 0; if (str_eq(existing_idx, EL_STR(""))) { _if_result_683 = (el_str_concat(el_str_concat(EL_STR("["), idx_entry), EL_STR("]"))); } else { el_val_t inner = str_slice(existing_idx, 1, (str_len(existing_idx) - 1)); _if_result_683 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), idx_entry), EL_STR(",")), inner), EL_STR("]"))); } _if_result_683; }); + el_val_t new_idx = ({ el_val_t _if_result_736 = 0; if (str_eq(existing_idx, EL_STR(""))) { _if_result_736 = (el_str_concat(el_str_concat(EL_STR("["), idx_entry), EL_STR("]"))); } else { el_val_t inner = str_slice(existing_idx, 1, (str_len(existing_idx) - 1)); _if_result_736 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), idx_entry), EL_STR(",")), inner), EL_STR("]"))); } _if_result_736; }); state_set(EL_STR("session_index"), new_idx); return 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("{\"id\":\""), id), EL_STR("\"")), EL_STR(",\"title\":\"")), json_safe(title)), EL_STR("\"")), EL_STR(",\"folder\":\"")), json_safe(folder)), EL_STR("\"")), EL_STR(",\"node_id\":\"")), node_id), EL_STR("\"")), EL_STR(",\"created_at\":")), int_to_str(ts)), EL_STR("}")); return 0; @@ -30624,16 +30851,16 @@ el_val_t session_list(void) { el_val_t is_session = (str_eq(label, EL_STR("session:meta")) && str_eq(node_type, EL_STR("Conversation"))); el_val_t content = json_get(node, EL_STR("content")); el_val_t sess_id = json_get(content, EL_STR("id")); - el_val_t eff_id = ({ el_val_t _if_result_684 = 0; if (str_eq(sess_id, EL_STR(""))) { _if_result_684 = (json_get(node, EL_STR("id"))); } else { _if_result_684 = (sess_id); } _if_result_684; }); + el_val_t eff_id = ({ el_val_t _if_result_737 = 0; if (str_eq(sess_id, EL_STR(""))) { _if_result_737 = (json_get(node, EL_STR("id"))); } else { _if_result_737 = (sess_id); } _if_result_737; }); el_val_t title_inner = json_get(content, EL_STR("title")); - el_val_t eff_title = ({ el_val_t _if_result_685 = 0; if (str_eq(title_inner, EL_STR(""))) { _if_result_685 = (EL_STR("New conversation")); } else { _if_result_685 = (title_inner); } _if_result_685; }); + el_val_t eff_title = ({ el_val_t _if_result_738 = 0; if (str_eq(title_inner, EL_STR(""))) { _if_result_738 = (EL_STR("New conversation")); } else { _if_result_738 = (title_inner); } _if_result_738; }); el_val_t folder_inner = json_get(content, EL_STR("folder")); el_val_t created_inner = json_get(content, EL_STR("created_at")); el_val_t updated_inner = json_get(content, EL_STR("updated_at")); - el_val_t eff_created = ({ el_val_t _if_result_686 = 0; if (str_eq(created_inner, EL_STR(""))) { _if_result_686 = (EL_STR("0")); } else { _if_result_686 = (created_inner); } _if_result_686; }); - el_val_t eff_updated = ({ el_val_t _if_result_687 = 0; if (str_eq(updated_inner, EL_STR(""))) { _if_result_687 = (eff_created); } else { _if_result_687 = (updated_inner); } _if_result_687; }); - el_val_t entry = ({ el_val_t _if_result_688 = 0; if (is_session) { _if_result_688 = (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("{\"id\":\""), json_safe(eff_id)), EL_STR("\"")), EL_STR(",\"title\":\"")), json_safe(eff_title)), EL_STR("\"")), EL_STR(",\"folder\":\"")), json_safe(folder_inner)), EL_STR("\"")), EL_STR(",\"last_message\":\"\"")), EL_STR(",\"created_at\":")), eff_created), EL_STR(",\"updated_at\":")), eff_updated), EL_STR("}"))); } else { _if_result_688 = (EL_STR("")); } _if_result_688; }); - out = ({ el_val_t _if_result_689 = 0; if (!str_eq(entry, EL_STR(""))) { _if_result_689 = (({ el_val_t _if_result_690 = 0; if (str_eq(out, EL_STR(""))) { _if_result_690 = (entry); } else { _if_result_690 = (el_str_concat(el_str_concat(out, EL_STR(",")), entry)); } _if_result_690; })); } else { _if_result_689 = (out); } _if_result_689; }); + el_val_t eff_created = ({ el_val_t _if_result_739 = 0; if (str_eq(created_inner, EL_STR(""))) { _if_result_739 = (EL_STR("0")); } else { _if_result_739 = (created_inner); } _if_result_739; }); + el_val_t eff_updated = ({ el_val_t _if_result_740 = 0; if (str_eq(updated_inner, EL_STR(""))) { _if_result_740 = (eff_created); } else { _if_result_740 = (updated_inner); } _if_result_740; }); + el_val_t entry = ({ el_val_t _if_result_741 = 0; if (is_session) { _if_result_741 = (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("{\"id\":\""), json_safe(eff_id)), EL_STR("\"")), EL_STR(",\"title\":\"")), json_safe(eff_title)), EL_STR("\"")), EL_STR(",\"folder\":\"")), json_safe(folder_inner)), EL_STR("\"")), EL_STR(",\"last_message\":\"\"")), EL_STR(",\"created_at\":")), eff_created), EL_STR(",\"updated_at\":")), eff_updated), EL_STR("}"))); } else { _if_result_741 = (EL_STR("")); } _if_result_741; }); + out = ({ el_val_t _if_result_742 = 0; if (!str_eq(entry, EL_STR(""))) { _if_result_742 = (({ el_val_t _if_result_743 = 0; if (str_eq(out, EL_STR(""))) { _if_result_743 = (entry); } else { _if_result_743 = (el_str_concat(el_str_concat(out, EL_STR(",")), entry)); } _if_result_743; })); } else { _if_result_742 = (out); } _if_result_742; }); i = (i + 1); } return el_str_concat(el_str_concat(EL_STR("["), out), EL_STR("]")); @@ -30651,7 +30878,7 @@ el_val_t session_get(el_val_t session_id) { el_val_t meta_created = EL_STR("0"); el_val_t meta_updated = EL_STR("0"); el_val_t found = 0; - el_val_t total = ({ el_val_t _if_result_691 = 0; if (str_eq(results, EL_STR(""))) { _if_result_691 = (0); } else { _if_result_691 = (json_array_len(results)); } _if_result_691; }); + el_val_t total = ({ el_val_t _if_result_744 = 0; if (str_eq(results, EL_STR(""))) { _if_result_744 = (0); } else { _if_result_744 = (json_array_len(results)); } _if_result_744; }); el_val_t i = 0; while (i < total) { el_val_t node = json_array_get(results, i); @@ -30659,17 +30886,17 @@ el_val_t session_get(el_val_t session_id) { el_val_t content = json_get(node, EL_STR("content")); el_val_t sid = json_get(content, EL_STR("id")); el_val_t is_match = ((str_eq(label, EL_STR("session:meta")) && str_eq(sid, session_id)) && !found); - found = ({ el_val_t _if_result_692 = 0; if (is_match) { _if_result_692 = (1); } else { _if_result_692 = (found); } _if_result_692; }); - meta_title = ({ el_val_t _if_result_693 = 0; if (is_match) { _if_result_693 = (json_get(content, EL_STR("title"))); } else { _if_result_693 = (meta_title); } _if_result_693; }); - meta_folder = ({ el_val_t _if_result_694 = 0; if (is_match) { _if_result_694 = (json_get(content, EL_STR("folder"))); } else { _if_result_694 = (meta_folder); } _if_result_694; }); + found = ({ el_val_t _if_result_745 = 0; if (is_match) { _if_result_745 = (1); } else { _if_result_745 = (found); } _if_result_745; }); + meta_title = ({ el_val_t _if_result_746 = 0; if (is_match) { _if_result_746 = (json_get(content, EL_STR("title"))); } else { _if_result_746 = (meta_title); } _if_result_746; }); + meta_folder = ({ el_val_t _if_result_747 = 0; if (is_match) { _if_result_747 = (json_get(content, EL_STR("folder"))); } else { _if_result_747 = (meta_folder); } _if_result_747; }); el_val_t meta_created_raw = json_get(content, EL_STR("created_at")); - meta_created = ({ el_val_t _if_result_695 = 0; if ((is_match && !str_eq(meta_created_raw, EL_STR("")))) { _if_result_695 = (meta_created_raw); } else { _if_result_695 = (meta_created); } _if_result_695; }); + meta_created = ({ el_val_t _if_result_748 = 0; if ((is_match && !str_eq(meta_created_raw, EL_STR("")))) { _if_result_748 = (meta_created_raw); } else { _if_result_748 = (meta_created); } _if_result_748; }); el_val_t meta_updated_raw = json_get(content, EL_STR("updated_at")); - meta_updated = ({ el_val_t _if_result_696 = 0; if ((is_match && !str_eq(meta_updated_raw, EL_STR("")))) { _if_result_696 = (meta_updated_raw); } else { _if_result_696 = (meta_updated); } _if_result_696; }); + meta_updated = ({ el_val_t _if_result_749 = 0; if ((is_match && !str_eq(meta_updated_raw, EL_STR("")))) { _if_result_749 = (meta_updated_raw); } else { _if_result_749 = (meta_updated); } _if_result_749; }); i = (i + 1); } el_val_t state_hist = state_get(el_str_concat(EL_STR("session_hist_"), session_id)); - el_val_t hist_raw = ({ el_val_t _if_result_697 = 0; if (str_eq(state_hist, EL_STR(""))) { el_val_t engram_hist = engram_search_json(el_str_concat(EL_STR("session:messages:"), session_id), 3); _if_result_697 = (({ el_val_t _if_result_698 = 0; if (str_eq(engram_hist, EL_STR(""))) { _if_result_698 = (EL_STR("[]")); } else { _if_result_698 = (({ el_val_t _if_result_699 = 0; if (str_eq(engram_hist, EL_STR("[]"))) { _if_result_699 = (EL_STR("[]")); } else { el_val_t h_node = json_array_get(engram_hist, 0); el_val_t h_content = json_get(h_node, EL_STR("content")); _if_result_699 = (({ el_val_t _if_result_700 = 0; if (str_starts_with(h_content, EL_STR("["))) { _if_result_700 = (h_content); } else { _if_result_700 = (EL_STR("[]")); } _if_result_700; })); } _if_result_699; })); } _if_result_698; })); } else { _if_result_697 = (state_hist); } _if_result_697; }); + el_val_t hist_raw = ({ el_val_t _if_result_750 = 0; if (str_eq(state_hist, EL_STR(""))) { el_val_t engram_hist = engram_search_json(el_str_concat(EL_STR("session:messages:"), session_id), 3); _if_result_750 = (({ el_val_t _if_result_751 = 0; if (str_eq(engram_hist, EL_STR(""))) { _if_result_751 = (EL_STR("[]")); } else { _if_result_751 = (({ el_val_t _if_result_752 = 0; if (str_eq(engram_hist, EL_STR("[]"))) { _if_result_752 = (EL_STR("[]")); } else { el_val_t h_node = json_array_get(engram_hist, 0); el_val_t h_content = json_get(h_node, EL_STR("content")); _if_result_752 = (({ el_val_t _if_result_753 = 0; if (str_starts_with(h_content, EL_STR("["))) { _if_result_753 = (h_content); } else { _if_result_753 = (EL_STR("[]")); } _if_result_753; })); } _if_result_752; })); } _if_result_751; })); } else { _if_result_750 = (state_hist); } _if_result_750; }); el_val_t safe_title = json_safe(meta_title); return 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("{\"id\":\""), session_id), EL_STR("\"")), EL_STR(",\"title\":\"")), safe_title), EL_STR("\"")), EL_STR(",\"folder\":\"")), json_safe(meta_folder)), EL_STR("\"")), EL_STR(",\"created_at\":")), meta_created), EL_STR(",\"updated_at\":")), meta_updated), EL_STR(",\"messages\":")), hist_raw), EL_STR("}")); return 0; @@ -30680,7 +30907,7 @@ el_val_t session_delete(el_val_t session_id) { return EL_STR("{\"error\":\"session_id is required\"}"); } el_val_t results = engram_search_json(el_str_concat(EL_STR("session:meta "), session_id), 10); - el_val_t total = ({ el_val_t _if_result_701 = 0; if (str_eq(results, EL_STR(""))) { _if_result_701 = (0); } else { _if_result_701 = (json_array_len(results)); } _if_result_701; }); + el_val_t total = ({ el_val_t _if_result_754 = 0; if (str_eq(results, EL_STR(""))) { _if_result_754 = (0); } else { _if_result_754 = (json_array_len(results)); } _if_result_754; }); el_val_t deleted_meta = 0; el_val_t i = 0; while (i < total) { @@ -30690,11 +30917,11 @@ el_val_t session_delete(el_val_t session_id) { el_val_t sid = json_get(content, EL_STR("id")); el_val_t is_match = (str_eq(label, EL_STR("session:meta")) && str_eq(sid, session_id)); el_val_t node_id = json_get(node, EL_STR("id")); - deleted_meta = ({ el_val_t _if_result_702 = 0; if ((is_match && !str_eq(node_id, EL_STR("")))) { (void)(engram_forget(node_id)); _if_result_702 = ((deleted_meta + 1)); } else { _if_result_702 = (deleted_meta); } _if_result_702; }); + deleted_meta = ({ el_val_t _if_result_755 = 0; if ((is_match && !str_eq(node_id, EL_STR("")))) { (void)(engram_forget(node_id)); _if_result_755 = ((deleted_meta + 1)); } else { _if_result_755 = (deleted_meta); } _if_result_755; }); i = (i + 1); } el_val_t msg_results = engram_search_json(el_str_concat(EL_STR("session:messages:"), session_id), 10); - el_val_t m_total = ({ el_val_t _if_result_703 = 0; if (str_eq(msg_results, EL_STR(""))) { _if_result_703 = (0); } else { _if_result_703 = (json_array_len(msg_results)); } _if_result_703; }); + el_val_t m_total = ({ el_val_t _if_result_756 = 0; if (str_eq(msg_results, EL_STR(""))) { _if_result_756 = (0); } else { _if_result_756 = (json_array_len(msg_results)); } _if_result_756; }); el_val_t deleted_msgs = 0; el_val_t j = 0; while (j < m_total) { @@ -30702,7 +30929,7 @@ el_val_t session_delete(el_val_t session_id) { el_val_t label = json_get(node, EL_STR("label")); el_val_t is_msgs = str_eq(label, el_str_concat(EL_STR("session:messages:"), session_id)); el_val_t node_id = json_get(node, EL_STR("id")); - deleted_msgs = ({ el_val_t _if_result_704 = 0; if ((is_msgs && !str_eq(node_id, EL_STR("")))) { (void)(engram_forget(node_id)); _if_result_704 = ((deleted_msgs + 1)); } else { _if_result_704 = (deleted_msgs); } _if_result_704; }); + deleted_msgs = ({ el_val_t _if_result_757 = 0; if ((is_msgs && !str_eq(node_id, EL_STR("")))) { (void)(engram_forget(node_id)); _if_result_757 = ((deleted_msgs + 1)); } else { _if_result_757 = (deleted_msgs); } _if_result_757; }); j = (j + 1); } state_set(el_str_concat(EL_STR("session_hist_"), session_id), EL_STR("")); @@ -30725,7 +30952,7 @@ el_val_t session_update_patch(el_val_t session_id, el_val_t body) { return EL_STR("{\"error\":\"title or folder required in body\"}"); } el_val_t results = engram_search_json(EL_STR("session:meta"), 50); - el_val_t total = ({ el_val_t _if_result_705 = 0; if (str_eq(results, EL_STR(""))) { _if_result_705 = (0); } else { _if_result_705 = (json_array_len(results)); } _if_result_705; }); + el_val_t total = ({ el_val_t _if_result_758 = 0; if (str_eq(results, EL_STR(""))) { _if_result_758 = (0); } else { _if_result_758 = (json_array_len(results)); } _if_result_758; }); el_val_t found = 0; el_val_t old_title = EL_STR("New conversation"); el_val_t old_folder = EL_STR(""); @@ -30738,23 +30965,23 @@ el_val_t session_update_patch(el_val_t session_id, el_val_t body) { el_val_t content = json_get(node, EL_STR("content")); el_val_t sid = json_get(content, EL_STR("id")); el_val_t is_match = ((str_eq(label, EL_STR("session:meta")) && str_eq(sid, session_id)) && !found); - found = ({ el_val_t _if_result_706 = 0; if (is_match) { _if_result_706 = (1); } else { _if_result_706 = (found); } _if_result_706; }); + found = ({ el_val_t _if_result_759 = 0; if (is_match) { _if_result_759 = (1); } else { _if_result_759 = (found); } _if_result_759; }); el_val_t title_raw = json_get(content, EL_STR("title")); - old_title = ({ el_val_t _if_result_707 = 0; if ((is_match && !str_eq(title_raw, EL_STR("")))) { _if_result_707 = (title_raw); } else { _if_result_707 = (old_title); } _if_result_707; }); + old_title = ({ el_val_t _if_result_760 = 0; if ((is_match && !str_eq(title_raw, EL_STR("")))) { _if_result_760 = (title_raw); } else { _if_result_760 = (old_title); } _if_result_760; }); el_val_t folder_raw = json_get(content, EL_STR("folder")); - old_folder = ({ el_val_t _if_result_708 = 0; if (is_match) { _if_result_708 = (folder_raw); } else { _if_result_708 = (old_folder); } _if_result_708; }); + old_folder = ({ el_val_t _if_result_761 = 0; if (is_match) { _if_result_761 = (folder_raw); } else { _if_result_761 = (old_folder); } _if_result_761; }); el_val_t created_raw = json_get(content, EL_STR("created_at")); - old_created = ({ el_val_t _if_result_709 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_709 = (created_raw); } else { _if_result_709 = (old_created); } _if_result_709; }); + old_created = ({ el_val_t _if_result_762 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_762 = (created_raw); } else { _if_result_762 = (old_created); } _if_result_762; }); el_val_t nid = json_get(node, EL_STR("id")); - old_node_id = ({ el_val_t _if_result_710 = 0; if (is_match) { _if_result_710 = (nid); } else { _if_result_710 = (old_node_id); } _if_result_710; }); + old_node_id = ({ el_val_t _if_result_763 = 0; if (is_match) { _if_result_763 = (nid); } else { _if_result_763 = (old_node_id); } _if_result_763; }); i = (i + 1); } if (!found) { return el_str_concat(el_str_concat(EL_STR("{\"error\":\"session not found\",\"session_id\":\""), session_id), EL_STR("\"}")); } el_val_t req_title = json_get(body, EL_STR("title")); - el_val_t eff_title = ({ el_val_t _if_result_711 = 0; if ((has_title && !str_eq(req_title, EL_STR("")))) { _if_result_711 = (req_title); } else { _if_result_711 = (old_title); } _if_result_711; }); - el_val_t eff_folder = ({ el_val_t _if_result_712 = 0; if (has_folder) { _if_result_712 = (json_get(body, EL_STR("folder"))); } else { _if_result_712 = (old_folder); } _if_result_712; }); + el_val_t eff_title = ({ el_val_t _if_result_764 = 0; if ((has_title && !str_eq(req_title, EL_STR("")))) { _if_result_764 = (req_title); } else { _if_result_764 = (old_title); } _if_result_764; }); + el_val_t eff_folder = ({ el_val_t _if_result_765 = 0; if (has_folder) { _if_result_765 = (json_get(body, EL_STR("folder"))); } else { _if_result_765 = (old_folder); } _if_result_765; }); if (!str_eq(old_node_id, EL_STR(""))) { engram_forget(old_node_id); } @@ -30782,8 +31009,8 @@ el_val_t session_search_entry(el_val_t node) { el_val_t title = json_get(content, EL_STR("title")); el_val_t created_raw = json_get(content, EL_STR("created_at")); el_val_t updated_raw = json_get(content, EL_STR("updated_at")); - el_val_t eff_created = ({ el_val_t _if_result_713 = 0; if (str_eq(created_raw, EL_STR(""))) { _if_result_713 = (EL_STR("0")); } else { _if_result_713 = (created_raw); } _if_result_713; }); - el_val_t eff_updated = ({ el_val_t _if_result_714 = 0; if (str_eq(updated_raw, EL_STR(""))) { _if_result_714 = (eff_created); } else { _if_result_714 = (updated_raw); } _if_result_714; }); + el_val_t eff_created = ({ el_val_t _if_result_766 = 0; if (str_eq(created_raw, EL_STR(""))) { _if_result_766 = (EL_STR("0")); } else { _if_result_766 = (created_raw); } _if_result_766; }); + el_val_t eff_updated = ({ el_val_t _if_result_767 = 0; if (str_eq(updated_raw, EL_STR(""))) { _if_result_767 = (eff_created); } else { _if_result_767 = (updated_raw); } _if_result_767; }); el_val_t e_id = el_str_concat(el_str_concat(EL_STR("{\"id\":\""), json_safe(sess_id)), EL_STR("\"")); el_val_t e_title = el_str_concat(el_str_concat(EL_STR(",\"title\":\""), json_safe(title)), EL_STR("\"")); el_val_t e_ts = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR(",\"created_at\":"), eff_created), EL_STR(",\"updated_at\":")), eff_updated), EL_STR("}")); @@ -30807,7 +31034,7 @@ el_val_t session_search(el_val_t query) { el_val_t i = 0; while (i < total) { el_val_t entry = session_search_entry(json_array_get(results, i)); - out = ({ el_val_t _if_result_715 = 0; if (!str_eq(entry, EL_STR(""))) { _if_result_715 = (({ el_val_t _if_result_716 = 0; if (str_eq(out, EL_STR(""))) { _if_result_716 = (entry); } else { _if_result_716 = (el_str_concat(el_str_concat(out, EL_STR(",")), entry)); } _if_result_716; })); } else { _if_result_715 = (out); } _if_result_715; }); + out = ({ el_val_t _if_result_768 = 0; if (!str_eq(entry, EL_STR(""))) { _if_result_768 = (({ el_val_t _if_result_769 = 0; if (str_eq(out, EL_STR(""))) { _if_result_769 = (entry); } else { _if_result_769 = (el_str_concat(el_str_concat(out, EL_STR(",")), entry)); } _if_result_769; })); } else { _if_result_768 = (out); } _if_result_768; }); i = (i + 1); } return el_str_concat(el_str_concat(EL_STR("["), out), EL_STR("]")); @@ -30843,7 +31070,7 @@ el_val_t session_hist_save(el_val_t session_id, el_val_t hist) { state_set(el_str_concat(EL_STR("session_hist_"), session_id), hist); state_set(el_str_concat(EL_STR("session_pending_first_msg_"), session_id), EL_STR("")); el_val_t old_results = engram_search_json(el_str_concat(EL_STR("session:messages:"), session_id), 3); - el_val_t o_total = ({ el_val_t _if_result_717 = 0; if (str_eq(old_results, EL_STR(""))) { _if_result_717 = (0); } else { _if_result_717 = (json_array_len(old_results)); } _if_result_717; }); + el_val_t o_total = ({ el_val_t _if_result_770 = 0; if (str_eq(old_results, EL_STR(""))) { _if_result_770 = (0); } else { _if_result_770 = (json_array_len(old_results)); } _if_result_770; }); el_val_t oi = 0; while (oi < o_total) { el_val_t node = json_array_get(old_results, oi); @@ -30861,35 +31088,35 @@ el_val_t session_hist_save(el_val_t session_id, el_val_t hist) { if (str_eq(already_written, EL_STR(""))) { el_val_t bell_count_key = el_str_concat(EL_STR("session_bell_count:"), session_id); el_val_t bell_count_raw = state_get(bell_count_key); - el_val_t bell_count = ({ el_val_t _if_result_718 = 0; if (str_eq(bell_count_raw, EL_STR(""))) { _if_result_718 = (0); } else { _if_result_718 = (str_to_int(bell_count_raw)); } _if_result_718; }); + el_val_t bell_count = ({ el_val_t _if_result_771 = 0; if (str_eq(bell_count_raw, EL_STR(""))) { _if_result_771 = (0); } else { _if_result_771 = (str_to_int(bell_count_raw)); } _if_result_771; }); if (bell_count > 0) { el_val_t bell_level_key = el_str_concat(EL_STR("session_bell_level:"), session_id); el_val_t bell_signal_key = el_str_concat(EL_STR("session_bell_signal:"), session_id); el_val_t dominant_level = state_get(bell_level_key); el_val_t last_signal = state_get(bell_signal_key); - el_val_t eff_level = ({ el_val_t _if_result_719 = 0; if (str_eq(dominant_level, EL_STR(""))) { _if_result_719 = (EL_STR("soft")); } else { _if_result_719 = (dominant_level); } _if_result_719; }); - el_val_t eff_signal = ({ el_val_t _if_result_720 = 0; if (str_eq(last_signal, EL_STR(""))) { _if_result_720 = (EL_STR("(no signal captured)")); } else { _if_result_720 = (last_signal); } _if_result_720; }); + el_val_t eff_level = ({ el_val_t _if_result_772 = 0; if (str_eq(dominant_level, EL_STR(""))) { _if_result_772 = (EL_STR("soft")); } else { _if_result_772 = (dominant_level); } _if_result_772; }); + el_val_t eff_signal = ({ el_val_t _if_result_773 = 0; if (str_eq(last_signal, EL_STR(""))) { _if_result_773 = (EL_STR("(no signal captured)")); } else { _if_result_773 = (last_signal); } _if_result_773; }); el_val_t ts_now = time_now(); el_val_t summary_content = 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("session:emotional-summary"), EL_STR(" | session:")), session_id), EL_STR(" | bell_count:")), int_to_str(bell_count)), EL_STR(" | dominant_level:")), eff_level), EL_STR(" | last_signal:")), eff_signal), EL_STR(" | ts:")), int_to_str(ts_now)); el_val_t summary_tags = el_str_concat(el_str_concat(EL_STR("[\"session-emotional-summary\",\"affective\",\"bell:"), eff_level), EL_STR("\",\"BellEvent\"]")); - el_val_t summary_sal = ({ el_val_t _if_result_721 = 0; if (str_eq(eff_level, EL_STR("hard"))) { _if_result_721 = (el_from_float(0.95)); } else { _if_result_721 = (el_from_float(0.85)); } _if_result_721; }); + el_val_t summary_sal = ({ el_val_t _if_result_774 = 0; if (str_eq(eff_level, EL_STR("hard"))) { _if_result_774 = (el_from_float(0.95)); } else { _if_result_774 = (el_from_float(0.85)); } _if_result_774; }); el_val_t sum_discard = wt_node(summary_content, EL_STR("BellEvent"), EL_STR("session:emotional-summary"), summary_sal, summary_sal, el_from_float(1.0), EL_STR("Episodic"), summary_tags); state_set(summary_written_key, EL_STR("1")); } } - el_val_t hist_arr_len = ({ el_val_t _if_result_722 = 0; if (str_eq(hist, EL_STR(""))) { _if_result_722 = (0); } else { _if_result_722 = (json_array_len(hist)); } _if_result_722; }); + el_val_t hist_arr_len = ({ el_val_t _if_result_775 = 0; if (str_eq(hist, EL_STR(""))) { _if_result_775 = (0); } else { _if_result_775 = (json_array_len(hist)); } _if_result_775; }); if (hist_arr_len >= 2) { el_val_t last_entry = json_array_get(hist, (hist_arr_len - 1)); el_val_t last_role = json_get(last_entry, EL_STR("role")); el_val_t last_content = json_get(last_entry, EL_STR("content")); - el_val_t topic_snip = ({ el_val_t _if_result_723 = 0; if ((str_len(last_content) > 200)) { _if_result_723 = (str_slice(last_content, 0, 200)); } else { _if_result_723 = (last_content); } _if_result_723; }); + el_val_t topic_snip = ({ el_val_t _if_result_776 = 0; if ((str_len(last_content) > 200)) { _if_result_776 = (str_slice(last_content, 0, 200)); } else { _if_result_776 = (last_content); } _if_result_776; }); el_val_t safe_topic = str_replace(topic_snip, EL_STR("\""), EL_STR("'")); el_val_t ts_now = int_to_str(time_now()); el_val_t topic_content = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("last-session-topic | ts:"), ts_now), EL_STR(" | session:")), session_id), EL_STR(" | topic:")), safe_topic); el_val_t topic_tags = EL_STR("[\"last-session-topic\",\"conv:history\",\"Conversation\",\"session:topic\"]"); el_val_t topic_label = el_str_concat(EL_STR("last-session-topic:"), session_id); el_val_t old_topic = engram_search_json(el_str_concat(EL_STR("last-session-topic:"), session_id), 2); - el_val_t ot_len = ({ el_val_t _if_result_724 = 0; if (str_eq(old_topic, EL_STR(""))) { _if_result_724 = (0); } else { _if_result_724 = (json_array_len(old_topic)); } _if_result_724; }); + el_val_t ot_len = ({ el_val_t _if_result_777 = 0; if (str_eq(old_topic, EL_STR(""))) { _if_result_777 = (0); } else { _if_result_777 = (json_array_len(old_topic)); } _if_result_777; }); el_val_t oti = 0; while (oti < ot_len) { el_val_t ot_node = json_array_get(old_topic, oti); @@ -30906,7 +31133,7 @@ el_val_t session_hist_save(el_val_t session_id, el_val_t hist) { el_val_t session_update_meta_timestamp(el_val_t session_id) { el_val_t results = engram_search_json(el_str_concat(EL_STR("session:meta "), session_id), 10); - el_val_t total = ({ el_val_t _if_result_725 = 0; if (str_eq(results, EL_STR(""))) { _if_result_725 = (0); } else { _if_result_725 = (json_array_len(results)); } _if_result_725; }); + el_val_t total = ({ el_val_t _if_result_778 = 0; if (str_eq(results, EL_STR(""))) { _if_result_778 = (0); } else { _if_result_778 = (json_array_len(results)); } _if_result_778; }); el_val_t found = 0; el_val_t old_title = EL_STR("New conversation"); el_val_t old_folder = EL_STR(""); @@ -30919,15 +31146,15 @@ el_val_t session_update_meta_timestamp(el_val_t session_id) { el_val_t content = json_get(node, EL_STR("content")); el_val_t sid = json_get(content, EL_STR("id")); el_val_t is_match = ((str_eq(label, EL_STR("session:meta")) && str_eq(sid, session_id)) && !found); - found = ({ el_val_t _if_result_726 = 0; if (is_match) { _if_result_726 = (1); } else { _if_result_726 = (found); } _if_result_726; }); + found = ({ el_val_t _if_result_779 = 0; if (is_match) { _if_result_779 = (1); } else { _if_result_779 = (found); } _if_result_779; }); el_val_t title_raw = json_get(content, EL_STR("title")); - old_title = ({ el_val_t _if_result_727 = 0; if ((is_match && !str_eq(title_raw, EL_STR("")))) { _if_result_727 = (title_raw); } else { _if_result_727 = (old_title); } _if_result_727; }); + old_title = ({ el_val_t _if_result_780 = 0; if ((is_match && !str_eq(title_raw, EL_STR("")))) { _if_result_780 = (title_raw); } else { _if_result_780 = (old_title); } _if_result_780; }); el_val_t folder_raw = json_get(content, EL_STR("folder")); - old_folder = ({ el_val_t _if_result_728 = 0; if (is_match) { _if_result_728 = (folder_raw); } else { _if_result_728 = (old_folder); } _if_result_728; }); + old_folder = ({ el_val_t _if_result_781 = 0; if (is_match) { _if_result_781 = (folder_raw); } else { _if_result_781 = (old_folder); } _if_result_781; }); el_val_t created_raw = json_get(content, EL_STR("created_at")); - old_created = ({ el_val_t _if_result_729 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_729 = (created_raw); } else { _if_result_729 = (old_created); } _if_result_729; }); + old_created = ({ el_val_t _if_result_782 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_782 = (created_raw); } else { _if_result_782 = (old_created); } _if_result_782; }); el_val_t nid = json_get(node, EL_STR("id")); - old_node_id = ({ el_val_t _if_result_730 = 0; if (is_match) { _if_result_730 = (nid); } else { _if_result_730 = (old_node_id); } _if_result_730; }); + old_node_id = ({ el_val_t _if_result_783 = 0; if (is_match) { _if_result_783 = (nid); } else { _if_result_783 = (old_node_id); } _if_result_783; }); i = (i + 1); } if (!found) { @@ -30947,7 +31174,7 @@ el_val_t session_update_meta_timestamp(el_val_t session_id) { el_val_t session_auto_title(el_val_t session_id, el_val_t first_message) { el_val_t results = engram_search_json(el_str_concat(EL_STR("session:meta "), session_id), 10); - el_val_t total = ({ el_val_t _if_result_731 = 0; if (str_eq(results, EL_STR(""))) { _if_result_731 = (0); } else { _if_result_731 = (json_array_len(results)); } _if_result_731; }); + el_val_t total = ({ el_val_t _if_result_784 = 0; if (str_eq(results, EL_STR(""))) { _if_result_784 = (0); } else { _if_result_784 = (json_array_len(results)); } _if_result_784; }); el_val_t found = 0; el_val_t cur_title = EL_STR(""); el_val_t old_folder = EL_STR(""); @@ -30960,15 +31187,15 @@ el_val_t session_auto_title(el_val_t session_id, el_val_t first_message) { el_val_t content = json_get(node, EL_STR("content")); el_val_t sid = json_get(content, EL_STR("id")); el_val_t is_match = ((str_eq(label, EL_STR("session:meta")) && str_eq(sid, session_id)) && !found); - found = ({ el_val_t _if_result_732 = 0; if (is_match) { _if_result_732 = (1); } else { _if_result_732 = (found); } _if_result_732; }); + found = ({ el_val_t _if_result_785 = 0; if (is_match) { _if_result_785 = (1); } else { _if_result_785 = (found); } _if_result_785; }); el_val_t title_raw = json_get(content, EL_STR("title")); - cur_title = ({ el_val_t _if_result_733 = 0; if (is_match) { _if_result_733 = (title_raw); } else { _if_result_733 = (cur_title); } _if_result_733; }); + cur_title = ({ el_val_t _if_result_786 = 0; if (is_match) { _if_result_786 = (title_raw); } else { _if_result_786 = (cur_title); } _if_result_786; }); el_val_t folder_raw = json_get(content, EL_STR("folder")); - old_folder = ({ el_val_t _if_result_734 = 0; if (is_match) { _if_result_734 = (folder_raw); } else { _if_result_734 = (old_folder); } _if_result_734; }); + old_folder = ({ el_val_t _if_result_787 = 0; if (is_match) { _if_result_787 = (folder_raw); } else { _if_result_787 = (old_folder); } _if_result_787; }); el_val_t created_raw = json_get(content, EL_STR("created_at")); - old_created = ({ el_val_t _if_result_735 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_735 = (created_raw); } else { _if_result_735 = (old_created); } _if_result_735; }); + old_created = ({ el_val_t _if_result_788 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_788 = (created_raw); } else { _if_result_788 = (old_created); } _if_result_788; }); el_val_t nid = json_get(node, EL_STR("id")); - old_node_id = ({ el_val_t _if_result_736 = 0; if (is_match) { _if_result_736 = (nid); } else { _if_result_736 = (old_node_id); } _if_result_736; }); + old_node_id = ({ el_val_t _if_result_789 = 0; if (is_match) { _if_result_789 = (nid); } else { _if_result_789 = (old_node_id); } _if_result_789; }); i = (i + 1); } if (!found) { @@ -31002,13 +31229,13 @@ el_val_t handle_session_approve(el_val_t session_id, el_val_t body) { if (str_eq(action, EL_STR(""))) { return EL_STR("{\"error\":\"action is required (allow|deny|always)\"}"); } - el_val_t eff_action = ({ el_val_t _if_result_737 = 0; if (str_eq(action, EL_STR("always"))) { _if_result_737 = (EL_STR("allow")); } else { _if_result_737 = (action); } _if_result_737; }); + el_val_t eff_action = ({ el_val_t _if_result_790 = 0; if (str_eq(action, EL_STR("always"))) { _if_result_790 = (EL_STR("allow")); } else { _if_result_790 = (action); } _if_result_790; }); el_val_t bridge_blob = state_get(el_str_concat(EL_STR("mcp_bridge:"), session_id)); if (!str_eq(bridge_blob, EL_STR(""))) { state_set(EL_STR("agent_workspace_root"), state_get(el_str_concat(EL_STR("agent_workspace_root_"), session_id))); el_val_t always_key = el_str_concat(EL_STR("always_allow_"), session_id); el_val_t approve_tool_name = json_get(body, EL_STR("tool_name")); - el_val_t discard_always = ({ el_val_t _if_result_738 = 0; if ((str_eq(action, EL_STR("always")) && !str_eq(approve_tool_name, EL_STR("")))) { el_val_t always_list = state_get(always_key); el_val_t new_always = ({ el_val_t _if_result_739 = 0; if (str_eq(always_list, EL_STR(""))) { _if_result_739 = (approve_tool_name); } else { _if_result_739 = (el_str_concat(el_str_concat(always_list, EL_STR(",")), approve_tool_name)); } _if_result_739; }); (void)(state_set(always_key, new_always)); _if_result_738 = (1); } else { _if_result_738 = (0); } _if_result_738; }); + el_val_t discard_always = ({ el_val_t _if_result_791 = 0; if ((str_eq(action, EL_STR("always")) && !str_eq(approve_tool_name, EL_STR("")))) { el_val_t always_list = state_get(always_key); el_val_t new_always = ({ el_val_t _if_result_792 = 0; if (str_eq(always_list, EL_STR(""))) { _if_result_792 = (approve_tool_name); } else { _if_result_792 = (el_str_concat(el_str_concat(always_list, EL_STR(",")), approve_tool_name)); } _if_result_792; }); (void)(state_set(always_key, new_always)); _if_result_791 = (1); } else { _if_result_791 = (0); } _if_result_791; }); if (str_eq(approve_tool_name, EL_STR("")) && str_eq(eff_action, EL_STR("allow"))) { return EL_STR("{\"error\":\"tool_name is required for allow action\"}"); } @@ -31016,8 +31243,8 @@ el_val_t handle_session_approve(el_val_t session_id, el_val_t body) { el_val_t use_client_content = (!str_eq(client_content, EL_STR("")) && !is_builtin_tool(approve_tool_name)); el_val_t use_dispatch = (is_builtin_tool(approve_tool_name) && !use_client_content); el_val_t raw_input = json_get_raw(body, EL_STR("tool_input")); - el_val_t eff_input = ({ el_val_t _if_result_740 = 0; if (str_eq(raw_input, EL_STR(""))) { _if_result_740 = (EL_STR("{}")); } else { _if_result_740 = (raw_input); } _if_result_740; }); - el_val_t content = ({ el_val_t _if_result_741 = 0; if (str_eq(eff_action, EL_STR("allow"))) { _if_result_741 = (({ el_val_t _if_result_742 = 0; if (use_client_content) { el_val_t trimmed = ({ el_val_t _if_result_743 = 0; if ((str_len(client_content) > 6000)) { _if_result_743 = (el_str_concat(str_slice(client_content, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_743 = (client_content); } _if_result_743; }); _if_result_742 = (trimmed); } else { _if_result_742 = (({ el_val_t _if_result_744 = 0; if (use_dispatch) { el_val_t raw = dispatch_tool(approve_tool_name, eff_input); _if_result_744 = (({ el_val_t _if_result_745 = 0; if ((str_len(raw) > 6000)) { _if_result_745 = (el_str_concat(str_slice(raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_745 = (raw); } _if_result_745; })); } else { _if_result_744 = (el_str_concat(el_str_concat(EL_STR("{\"error\":\"client content required for non-builtin tool: "), approve_tool_name), EL_STR("\"}"))); } _if_result_744; })); } _if_result_742; })); } else { _if_result_741 = (EL_STR("{\"error\":\"User denied this tool call\"}")); } _if_result_741; }); + el_val_t eff_input = ({ el_val_t _if_result_793 = 0; if (str_eq(raw_input, EL_STR(""))) { _if_result_793 = (EL_STR("{}")); } else { _if_result_793 = (raw_input); } _if_result_793; }); + el_val_t content = ({ el_val_t _if_result_794 = 0; if (str_eq(eff_action, EL_STR("allow"))) { _if_result_794 = (({ el_val_t _if_result_795 = 0; if (use_client_content) { el_val_t trimmed = ({ el_val_t _if_result_796 = 0; if ((str_len(client_content) > 6000)) { _if_result_796 = (el_str_concat(str_slice(client_content, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_796 = (client_content); } _if_result_796; }); _if_result_795 = (trimmed); } else { _if_result_795 = (({ el_val_t _if_result_797 = 0; if (use_dispatch) { el_val_t raw = dispatch_tool(approve_tool_name, eff_input); _if_result_797 = (({ el_val_t _if_result_798 = 0; if ((str_len(raw) > 6000)) { _if_result_798 = (el_str_concat(str_slice(raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_798 = (raw); } _if_result_798; })); } else { _if_result_797 = (el_str_concat(el_str_concat(EL_STR("{\"error\":\"client content required for non-builtin tool: "), approve_tool_name), EL_STR("\"}"))); } _if_result_797; })); } _if_result_795; })); } else { _if_result_794 = (EL_STR("{\"error\":\"User denied this tool call\"}")); } _if_result_794; }); return agentic_resume(session_id, call_id, content); } el_val_t pending_raw = state_get(el_str_concat(EL_STR("pending_tool_"), session_id)); @@ -31034,12 +31261,12 @@ el_val_t handle_session_approve(el_val_t session_id, el_val_t body) { el_val_t safe_sys = json_get(pending_raw, EL_STR("system")); el_val_t always_key = el_str_concat(EL_STR("always_allow_"), session_id); el_val_t always_list = state_get(always_key); - el_val_t discard_always2 = ({ el_val_t _if_result_746 = 0; if (str_eq(action, EL_STR("always"))) { el_val_t new_always = ({ el_val_t _if_result_747 = 0; if (str_eq(always_list, EL_STR(""))) { _if_result_747 = (tool_name); } else { _if_result_747 = (el_str_concat(el_str_concat(always_list, EL_STR(",")), tool_name)); } _if_result_747; }); (void)(state_set(always_key, new_always)); _if_result_746 = (1); } else { _if_result_746 = (0); } _if_result_746; }); + el_val_t discard_always2 = ({ el_val_t _if_result_799 = 0; if (str_eq(action, EL_STR("always"))) { el_val_t new_always = ({ el_val_t _if_result_800 = 0; if (str_eq(always_list, EL_STR(""))) { _if_result_800 = (tool_name); } else { _if_result_800 = (el_str_concat(el_str_concat(always_list, EL_STR(",")), tool_name)); } _if_result_800; }); (void)(state_set(always_key, new_always)); _if_result_799 = (1); } else { _if_result_799 = (0); } _if_result_799; }); state_set(el_str_concat(EL_STR("pending_tool_"), session_id), EL_STR("")); - el_val_t tool_result = ({ el_val_t _if_result_748 = 0; if (str_eq(eff_action, EL_STR("allow"))) { el_val_t raw = dispatch_tool(tool_name, tool_input); _if_result_748 = (({ el_val_t _if_result_749 = 0; if ((str_len(raw) > 6000)) { _if_result_749 = (el_str_concat(str_slice(raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_749 = (raw); } _if_result_749; })); } else { _if_result_748 = (EL_STR("{\"error\":\"User denied this tool call\"}")); } _if_result_748; }); + el_val_t tool_result = ({ el_val_t _if_result_801 = 0; if (str_eq(eff_action, EL_STR("allow"))) { el_val_t raw = dispatch_tool(tool_name, tool_input); _if_result_801 = (({ el_val_t _if_result_802 = 0; if ((str_len(raw) > 6000)) { _if_result_802 = (el_str_concat(str_slice(raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_802 = (raw); } _if_result_802; })); } else { _if_result_801 = (EL_STR("{\"error\":\"User denied this tool call\"}")); } _if_result_801; }); el_val_t legacy_messages = json_get_raw(pending_raw, EL_STR("messages_so_far")); el_val_t stored_variant = json_get(pending_raw, EL_STR("tools_variant")); - el_val_t tools_json = ({ el_val_t _if_result_750 = 0; if (str_eq(stored_variant, EL_STR("web"))) { _if_result_750 = (agentic_tools_with_web()); } else { _if_result_750 = (({ el_val_t _if_result_751 = 0; if (str_eq(stored_variant, EL_STR("all"))) { _if_result_751 = (agentic_tools_all()); } else { _if_result_751 = (agentic_tools_literal()); } _if_result_751; })); } _if_result_750; }); + el_val_t tools_json = ({ el_val_t _if_result_803 = 0; if (str_eq(stored_variant, EL_STR("web"))) { _if_result_803 = (agentic_tools_with_web()); } else { _if_result_803 = (({ el_val_t _if_result_804 = 0; if (str_eq(stored_variant, EL_STR("all"))) { _if_result_804 = (agentic_tools_all()); } else { _if_result_804 = (agentic_tools_literal()); } _if_result_804; })); } _if_result_803; }); el_val_t blob = 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("{\"model\":\""), json_safe(model)), EL_STR("\"")), EL_STR(",\"safe_sys\":\"")), json_safe(safe_sys)), EL_STR("\"")), EL_STR(",\"tools_json\":\"")), json_safe(tools_json)), EL_STR("\"")), EL_STR(",\"messages\":\"")), json_safe(legacy_messages)), EL_STR("\"")), EL_STR(",\"tools_log\":\"\"")), EL_STR(",\"tool_use_id\":\"")), json_safe(call_id)), EL_STR("\"}")); state_set(el_str_concat(EL_STR("mcp_bridge:"), session_id), blob); return agentic_resume(session_id, call_id, tool_result); @@ -31065,24 +31292,24 @@ el_val_t rate_limit_check(el_val_t ip, el_val_t path) { return EL_STR(""); } el_val_t limit_str = state_get(EL_STR("soul_rate_limit")); - el_val_t limit = ({ el_val_t _if_result_752 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_752 = (60); } else { _if_result_752 = (str_to_int(limit_str)); } _if_result_752; }); + el_val_t limit = ({ el_val_t _if_result_805 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_805 = (60); } else { _if_result_805 = (str_to_int(limit_str)); } _if_result_805; }); el_val_t now = time_now(); el_val_t window_key = el_str_concat(el_str_concat(EL_STR("rl:"), ip), EL_STR(":window")); el_val_t count_key = el_str_concat(el_str_concat(EL_STR("rl:"), ip), EL_STR(":count")); el_val_t win_str = state_get(window_key); - el_val_t win_start = ({ el_val_t _if_result_753 = 0; if (str_eq(win_str, EL_STR(""))) { _if_result_753 = (now); } else { _if_result_753 = (str_to_int(win_str)); } _if_result_753; }); + el_val_t win_start = ({ el_val_t _if_result_806 = 0; if (str_eq(win_str, EL_STR(""))) { _if_result_806 = (now); } else { _if_result_806 = (str_to_int(win_str)); } _if_result_806; }); el_val_t elapsed = (now - win_start); el_val_t in_window = (elapsed < 60); el_val_t prev_count_str = state_get(count_key); - el_val_t prev_count = ({ el_val_t _if_result_754 = 0; if (str_eq(prev_count_str, EL_STR(""))) { _if_result_754 = (0); } else { _if_result_754 = (str_to_int(prev_count_str)); } _if_result_754; }); - el_val_t eff_count = ({ el_val_t _if_result_755 = 0; if (in_window) { _if_result_755 = (prev_count); } else { _if_result_755 = (0); } _if_result_755; }); - el_val_t eff_win = ({ el_val_t _if_result_756 = 0; if (in_window) { _if_result_756 = (win_start); } else { _if_result_756 = (now); } _if_result_756; }); + el_val_t prev_count = ({ el_val_t _if_result_807 = 0; if (str_eq(prev_count_str, EL_STR(""))) { _if_result_807 = (0); } else { _if_result_807 = (str_to_int(prev_count_str)); } _if_result_807; }); + el_val_t eff_count = ({ el_val_t _if_result_808 = 0; if (in_window) { _if_result_808 = (prev_count); } else { _if_result_808 = (0); } _if_result_808; }); + el_val_t eff_win = ({ el_val_t _if_result_809 = 0; if (in_window) { _if_result_809 = (win_start); } else { _if_result_809 = (now); } _if_result_809; }); el_val_t new_count = (eff_count + 1); state_set(count_key, int_to_str(new_count)); state_set(window_key, int_to_str(eff_win)); if (new_count > limit) { el_val_t retry_after = (60 - (now - eff_win)); - el_val_t eff_retry = ({ el_val_t _if_result_757 = 0; if ((retry_after < 0)) { _if_result_757 = (0); } else { _if_result_757 = (retry_after); } _if_result_757; }); + el_val_t eff_retry = ({ el_val_t _if_result_810 = 0; if ((retry_after < 0)) { _if_result_810 = (0); } else { _if_result_810 = (retry_after); } _if_result_810; }); return el_str_concat(el_str_concat(EL_STR("{\"__status__\":429,\"error\":\"rate limit exceeded\",\"code\":\"rate_limited\",\"retry_after_secs\":"), int_to_str(eff_retry)), EL_STR("}")); } return EL_STR(""); @@ -31111,18 +31338,18 @@ el_val_t err_405(el_val_t method, el_val_t path) { el_val_t route_health(void) { el_val_t cgi_id = state_get(EL_STR("soul_cgi_id")); el_val_t boot = state_get(EL_STR("soul_boot_count")); - el_val_t boot_num = ({ el_val_t _if_result_758 = 0; if (str_eq(boot, EL_STR(""))) { _if_result_758 = (EL_STR("0")); } else { _if_result_758 = (boot); } _if_result_758; }); + el_val_t boot_num = ({ el_val_t _if_result_811 = 0; if (str_eq(boot, EL_STR(""))) { _if_result_811 = (EL_STR("0")); } else { _if_result_811 = (boot); } _if_result_811; }); el_val_t node_ct = engram_node_count(); el_val_t edge_ct = engram_edge_count(); el_val_t pulse = state_get(EL_STR("soul.pulse")); - el_val_t pulse_num = ({ el_val_t _if_result_759 = 0; if (str_eq(pulse, EL_STR(""))) { _if_result_759 = (EL_STR("0")); } else { _if_result_759 = (pulse); } _if_result_759; }); + el_val_t pulse_num = ({ el_val_t _if_result_812 = 0; if (str_eq(pulse, EL_STR(""))) { _if_result_812 = (EL_STR("0")); } else { _if_result_812 = (pulse); } _if_result_812; }); el_val_t boot_ts_str = state_get(EL_STR("soul_boot_ts")); - el_val_t uptime_secs = ({ el_val_t _if_result_760 = 0; if (str_eq(boot_ts_str, EL_STR(""))) { _if_result_760 = ((-1)); } else { _if_result_760 = ((time_now() - str_to_int(boot_ts_str))); } _if_result_760; }); + el_val_t uptime_secs = ({ el_val_t _if_result_813 = 0; if (str_eq(boot_ts_str, EL_STR(""))) { _if_result_813 = ((-1)); } else { _if_result_813 = ((time_now() - str_to_int(boot_ts_str))); } _if_result_813; }); el_val_t model = state_get(EL_STR("soul_model")); - el_val_t eff_model = ({ el_val_t _if_result_761 = 0; if (str_eq(model, EL_STR(""))) { _if_result_761 = (EL_STR("claude-sonnet-4-5")); } else { _if_result_761 = (model); } _if_result_761; }); + el_val_t eff_model = ({ el_val_t _if_result_814 = 0; if (str_eq(model, EL_STR(""))) { _if_result_814 = (EL_STR("claude-sonnet-4-5")); } else { _if_result_814 = (model); } _if_result_814; }); el_val_t llm_probe = llm_call_system(eff_model, EL_STR("You are a health probe. Reply with the single word: ok"), EL_STR("ping")); el_val_t llm_ok = (((!str_eq(llm_probe, EL_STR("")) && !str_starts_with(llm_probe, EL_STR("{\"error\""))) && !str_starts_with(llm_probe, EL_STR("{\"type\":\"error\""))) && !str_contains(llm_probe, EL_STR("authentication_error"))); - el_val_t llm_status = ({ el_val_t _if_result_762 = 0; if (llm_ok) { _if_result_762 = (EL_STR("ok")); } else { _if_result_762 = (EL_STR("unreachable")); } _if_result_762; }); + el_val_t llm_status = ({ el_val_t _if_result_815 = 0; if (llm_ok) { _if_result_815 = (EL_STR("ok")); } else { _if_result_815 = (EL_STR("unreachable")); } _if_result_815; }); return 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_concat(el_str_concat(EL_STR("{\"status\":\"alive\""), EL_STR(",\"cgi_id\":\"")), cgi_id), EL_STR("\"")), EL_STR(",\"boot\":")), boot_num), EL_STR(",\"uptime_secs\":")), int_to_str(uptime_secs)), EL_STR(",\"node_count\":")), int_to_str(node_ct)), EL_STR(",\"edge_count\":")), int_to_str(edge_ct)), EL_STR(",\"pulse\":")), pulse_num), EL_STR(",\"llm\":\"")), llm_status), EL_STR("\"")), EL_STR(",\"layers\":{\"l0\":\"core\",\"l1\":\"safety\",\"l2\":\"stewardship\",\"l3\":\"")), imprint_current()), EL_STR("\"}}")); return 0; } @@ -31192,30 +31419,30 @@ el_val_t handle_dharma_recv(el_val_t body) { el_val_t from_id = json_get(body, EL_STR("from")); el_val_t event_type = json_get(content_raw, EL_STR("event_type")); el_val_t payload = json_get(content_raw, EL_STR("payload")); - el_val_t eff_event = ({ el_val_t _if_result_763 = 0; if (str_eq(event_type, EL_STR(""))) { _if_result_763 = (EL_STR("chat")); } else { _if_result_763 = (event_type); } _if_result_763; }); - el_val_t eff_payload = ({ el_val_t _if_result_764 = 0; if (str_eq(payload, EL_STR(""))) { _if_result_764 = (content_raw); } else { _if_result_764 = (payload); } _if_result_764; }); + el_val_t eff_event = ({ el_val_t _if_result_816 = 0; if (str_eq(event_type, EL_STR(""))) { _if_result_816 = (EL_STR("chat")); } else { _if_result_816 = (event_type); } _if_result_816; }); + el_val_t eff_payload = ({ el_val_t _if_result_817 = 0; if (str_eq(payload, EL_STR(""))) { _if_result_817 = (content_raw); } else { _if_result_817 = (payload); } _if_result_817; }); if (str_eq(eff_event, EL_STR("chat"))) { el_val_t msg = json_get(eff_payload, EL_STR("message")); - el_val_t chat_body = ({ el_val_t _if_result_765 = 0; if (str_eq(msg, EL_STR(""))) { _if_result_765 = (el_str_concat(el_str_concat(EL_STR("{\"message\":\""), str_replace(str_replace(eff_payload, EL_STR("\\"), EL_STR("\\\\")), EL_STR("\""), EL_STR("\\\""))), EL_STR("\"}"))); } else { _if_result_765 = (eff_payload); } _if_result_765; }); + el_val_t chat_body = ({ el_val_t _if_result_818 = 0; if (str_eq(msg, EL_STR(""))) { _if_result_818 = (el_str_concat(el_str_concat(EL_STR("{\"message\":\""), str_replace(str_replace(eff_payload, EL_STR("\\"), EL_STR("\\\\")), EL_STR("\""), EL_STR("\\\""))), EL_STR("\"}"))); } else { _if_result_818 = (eff_payload); } _if_result_818; }); el_val_t agentic_flag = json_get_bool(eff_payload, EL_STR("agentic")); el_val_t raw_msg = json_get(chat_body, EL_STR("message")); el_val_t req_mode = json_get(chat_body, EL_STR("mode")); - el_val_t reply = ({ el_val_t _if_result_766 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_766 = (handle_chat_plan(chat_body)); } else { _if_result_766 = (({ el_val_t _if_result_767 = 0; if (agentic_flag) { _if_result_767 = (handle_chat_agentic(chat_body)); } else { el_val_t screened_reply = layered_cycle(raw_msg, json_get(chat_body, EL_STR("session_id")), is_utility_request(chat_body, json_get(chat_body, EL_STR("session_id")))); _if_result_767 = (plain_chat_envelope(screened_reply, chat_default_model())); } _if_result_767; })); } _if_result_766; }); + el_val_t reply = ({ el_val_t _if_result_819 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_819 = (handle_chat_plan(chat_body)); } else { _if_result_819 = (({ el_val_t _if_result_820 = 0; if (agentic_flag) { _if_result_820 = (handle_chat_agentic(chat_body)); } else { el_val_t screened_reply = layered_cycle(raw_msg, json_get(chat_body, EL_STR("session_id")), is_utility_request(chat_body, json_get(chat_body, EL_STR("session_id")))); _if_result_820 = (plain_chat_envelope(screened_reply, chat_default_model())); } _if_result_820; })); } _if_result_819; }); auto_persist(chat_body, reply); return reply; } if (str_eq(eff_event, EL_STR("memory"))) { el_val_t query = json_get(eff_payload, EL_STR("query")); el_val_t limit_str = json_get(eff_payload, EL_STR("limit")); - el_val_t limit = ({ el_val_t _if_result_768 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_768 = (20); } else { _if_result_768 = (str_to_int(limit_str)); } _if_result_768; }); - el_val_t q = ({ el_val_t _if_result_769 = 0; if (str_eq(query, EL_STR(""))) { _if_result_769 = (eff_payload); } else { _if_result_769 = (query); } _if_result_769; }); + el_val_t limit = ({ el_val_t _if_result_821 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_821 = (20); } else { _if_result_821 = (str_to_int(limit_str)); } _if_result_821; }); + el_val_t q = ({ el_val_t _if_result_822 = 0; if (str_eq(query, EL_STR(""))) { _if_result_822 = (eff_payload); } else { _if_result_822 = (query); } _if_result_822; }); return engram_search_json(q, limit); } if (str_eq(eff_event, EL_STR("tool"))) { el_val_t path_field = json_get(eff_payload, EL_STR("path")); el_val_t method_field = json_get(eff_payload, EL_STR("method")); el_val_t tool_body = json_get(eff_payload, EL_STR("body")); - el_val_t eff_method = ({ el_val_t _if_result_770 = 0; if (str_eq(method_field, EL_STR(""))) { _if_result_770 = (EL_STR("POST")); } else { _if_result_770 = (method_field); } _if_result_770; }); + el_val_t eff_method = ({ el_val_t _if_result_823 = 0; if (str_eq(method_field, EL_STR(""))) { _if_result_823 = (EL_STR("POST")); } else { _if_result_823 = (method_field); } _if_result_823; }); return handle_tool(path_field, eff_method, tool_body); } if (str_eq(eff_event, EL_STR("see"))) { @@ -31250,7 +31477,7 @@ el_val_t connectd_get(el_val_t suffix) { } el_val_t connectd_post(el_val_t suffix, el_val_t body) { - el_val_t eff = ({ el_val_t _if_result_771 = 0; if (str_eq(body, EL_STR(""))) { _if_result_771 = (EL_STR("{}")); } else { _if_result_771 = (body); } _if_result_771; }); + el_val_t eff = ({ el_val_t _if_result_824 = 0; if (str_eq(body, EL_STR(""))) { _if_result_824 = (EL_STR("{}")); } else { _if_result_824 = (body); } _if_result_824; }); el_val_t tmp = el_str_concat(el_str_concat(EL_STR("/tmp/neuron-connectors-req-"), int_to_str(time_now())), EL_STR(".json")); fs_write(tmp, eff); el_val_t out = exec_capture(el_str_concat(el_str_concat(el_str_concat(EL_STR("curl -s --max-time 20 -X POST http://127.0.0.1:7771"), suffix), EL_STR(" -H 'Content-Type: application/json' -d @")), tmp)); @@ -31322,22 +31549,22 @@ el_val_t route_dispatch(el_val_t method, el_val_t path, el_val_t body) { } if (str_eq(clean, EL_STR("/api/graph/edges"))) { el_val_t scratch_dir = env(EL_STR("TMPDIR")); - el_val_t scratch_base = ({ el_val_t _if_result_772 = 0; if (str_eq(scratch_dir, EL_STR(""))) { _if_result_772 = (EL_STR("/tmp")); } else { _if_result_772 = (scratch_dir); } _if_result_772; }); + el_val_t scratch_base = ({ el_val_t _if_result_825 = 0; if (str_eq(scratch_dir, EL_STR(""))) { _if_result_825 = (EL_STR("/tmp")); } else { _if_result_825 = (scratch_dir); } _if_result_825; }); el_val_t snap_path = el_str_concat(el_str_concat(el_str_concat(scratch_base, EL_STR("/soul-edges-export-")), state_get(EL_STR("soul_cgi_id"))), EL_STR(".json")); engram_save(snap_path); el_val_t snap = fs_read(snap_path); el_val_t edges_raw = json_get_raw(snap, EL_STR("edges")); - return ({ el_val_t _if_result_773 = 0; if (str_eq(edges_raw, EL_STR(""))) { _if_result_773 = (EL_STR("[]")); } else { _if_result_773 = (edges_raw); } _if_result_773; }); + return ({ el_val_t _if_result_826 = 0; if (str_eq(edges_raw, EL_STR(""))) { _if_result_826 = (EL_STR("[]")); } else { _if_result_826 = (edges_raw); } _if_result_826; }); } if (str_eq(clean, EL_STR("/api/chat"))) { el_val_t raw_msg = json_get(body, EL_STR("message")); - el_val_t eff_msg = ({ el_val_t _if_result_774 = 0; if (str_eq(raw_msg, EL_STR(""))) { _if_result_774 = (body); } else { _if_result_774 = (raw_msg); } _if_result_774; }); + el_val_t eff_msg = ({ el_val_t _if_result_827 = 0; if (str_eq(raw_msg, EL_STR(""))) { _if_result_827 = (body); } else { _if_result_827 = (raw_msg); } _if_result_827; }); if (str_eq(eff_msg, EL_STR(""))) { return EL_STR("{\"error\":\"message is required\",\"code\":\"missing_param\"}"); } el_val_t agentic_flag = json_get_bool(body, EL_STR("agentic")); el_val_t req_mode = json_get(body, EL_STR("mode")); - el_val_t reply = ({ el_val_t _if_result_775 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_775 = (handle_chat_plan(body)); } else { _if_result_775 = (({ el_val_t _if_result_776 = 0; if (agentic_flag) { _if_result_776 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(eff_msg, json_get(body, EL_STR("session_id")), is_utility_request(body, json_get(body, EL_STR("session_id")))); _if_result_776 = (plain_chat_envelope(screened_reply, chat_default_model())); } _if_result_776; })); } _if_result_775; }); + el_val_t reply = ({ el_val_t _if_result_828 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_828 = (handle_chat_plan(body)); } else { _if_result_828 = (({ el_val_t _if_result_829 = 0; if (agentic_flag) { _if_result_829 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(eff_msg, json_get(body, EL_STR("session_id")), is_utility_request(body, json_get(body, EL_STR("session_id")))); _if_result_829 = (plain_chat_envelope(screened_reply, chat_default_model())); } _if_result_829; })); } _if_result_828; }); auto_persist(body, reply); return reply; } @@ -31421,7 +31648,7 @@ el_val_t route_dispatch(el_val_t method, el_val_t path, el_val_t body) { el_val_t rp_id = str_slice(clean, 18, str_len(clean)); if (!str_eq(rp_id, EL_STR(""))) { el_val_t rp_raw = state_get(el_str_concat(EL_STR("run_progress_"), rp_id)); - el_val_t rp_arr = ({ el_val_t _if_result_777 = 0; if (str_eq(rp_raw, EL_STR(""))) { _if_result_777 = (EL_STR("[]")); } else { _if_result_777 = (el_str_concat(el_str_concat(EL_STR("["), rp_raw), EL_STR("]"))); } _if_result_777; }); + el_val_t rp_arr = ({ el_val_t _if_result_830 = 0; if (str_eq(rp_raw, EL_STR(""))) { _if_result_830 = (EL_STR("[]")); } else { _if_result_830 = (el_str_concat(el_str_concat(EL_STR("["), rp_raw), EL_STR("]"))); } _if_result_830; }); return el_str_concat(el_str_concat(EL_STR("{\"progress\":"), rp_arr), EL_STR("}")); } } @@ -31431,7 +31658,7 @@ el_val_t route_dispatch(el_val_t method, el_val_t path, el_val_t body) { if (str_starts_with(clean, EL_STR("/api/sessions/"))) { el_val_t gs_after = str_slice(clean, 14, str_len(clean)); el_val_t gs_slash = str_index_of(gs_after, EL_STR("/")); - el_val_t gs_id = ({ el_val_t _if_result_778 = 0; if ((gs_slash < 0)) { _if_result_778 = (gs_after); } else { _if_result_778 = (str_slice(gs_after, 0, gs_slash)); } _if_result_778; }); + el_val_t gs_id = ({ el_val_t _if_result_831 = 0; if ((gs_slash < 0)) { _if_result_831 = (gs_after); } else { _if_result_831 = (str_slice(gs_after, 0, gs_slash)); } _if_result_831; }); if (!str_eq(gs_id, EL_STR(""))) { return session_get(gs_id); } @@ -31445,14 +31672,14 @@ el_val_t route_dispatch(el_val_t method, el_val_t path, el_val_t body) { if (str_starts_with(clean, EL_STR("/api/sessions/")) && str_ends_with(clean, EL_STR("/tool_result"))) { el_val_t after = str_slice(clean, 14, str_len(clean)); el_val_t slash = str_index_of(after, EL_STR("/")); - el_val_t session_id = ({ el_val_t _if_result_779 = 0; if ((slash < 0)) { _if_result_779 = (after); } else { _if_result_779 = (str_slice(after, 0, slash)); } _if_result_779; }); + el_val_t session_id = ({ el_val_t _if_result_832 = 0; if ((slash < 0)) { _if_result_832 = (after); } else { _if_result_832 = (str_slice(after, 0, slash)); } _if_result_832; }); return handle_tool_result(session_id, body); } if (str_starts_with(clean, EL_STR("/api/sessions/"))) { el_val_t sess_after = str_slice(clean, 14, str_len(clean)); el_val_t sess_slash = str_index_of(sess_after, EL_STR("/")); - el_val_t sess_id = ({ el_val_t _if_result_780 = 0; if ((sess_slash < 0)) { _if_result_780 = (sess_after); } else { _if_result_780 = (str_slice(sess_after, 0, sess_slash)); } _if_result_780; }); - el_val_t sess_sub = ({ el_val_t _if_result_781 = 0; if ((sess_slash < 0)) { _if_result_781 = (EL_STR("")); } else { _if_result_781 = (str_slice(sess_after, (sess_slash + 1), str_len(sess_after))); } _if_result_781; }); + el_val_t sess_id = ({ el_val_t _if_result_833 = 0; if ((sess_slash < 0)) { _if_result_833 = (sess_after); } else { _if_result_833 = (str_slice(sess_after, 0, sess_slash)); } _if_result_833; }); + el_val_t sess_sub = ({ el_val_t _if_result_834 = 0; if ((sess_slash < 0)) { _if_result_834 = (EL_STR("")); } else { _if_result_834 = (str_slice(sess_after, (sess_slash + 1), str_len(sess_after))); } _if_result_834; }); if (!str_eq(sess_id, EL_STR("")) && str_eq(sess_sub, EL_STR("approve"))) { return handle_session_approve(sess_id, body); } @@ -31476,7 +31703,7 @@ el_val_t route_dispatch(el_val_t method, el_val_t path, el_val_t body) { } el_val_t agentic_flag = json_get_bool(body, EL_STR("agentic")); el_val_t req_mode = json_get(body, EL_STR("mode")); - el_val_t reply = ({ el_val_t _if_result_782 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_782 = (handle_chat_plan(body)); } else { _if_result_782 = (({ el_val_t _if_result_783 = 0; if (agentic_flag) { _if_result_783 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(raw_msg, json_get(body, EL_STR("session_id")), is_utility_request(body, json_get(body, EL_STR("session_id")))); _if_result_783 = (plain_chat_envelope(screened_reply, chat_default_model())); } _if_result_783; })); } _if_result_782; }); + el_val_t reply = ({ el_val_t _if_result_835 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_835 = (handle_chat_plan(body)); } else { _if_result_835 = (({ el_val_t _if_result_836 = 0; if (agentic_flag) { _if_result_836 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(raw_msg, json_get(body, EL_STR("session_id")), is_utility_request(body, json_get(body, EL_STR("session_id")))); _if_result_836 = (plain_chat_envelope(screened_reply, chat_default_model())); } _if_result_836; })); } _if_result_835; }); auto_persist(body, reply); return reply; } @@ -31603,7 +31830,7 @@ el_val_t route_dispatch(el_val_t method, el_val_t path, el_val_t body) { if (str_starts_with(clean, EL_STR("/api/sessions/"))) { el_val_t del_after = str_slice(clean, 14, str_len(clean)); el_val_t del_slash = str_index_of(del_after, EL_STR("/")); - el_val_t del_id = ({ el_val_t _if_result_784 = 0; if ((del_slash < 0)) { _if_result_784 = (del_after); } else { _if_result_784 = (str_slice(del_after, 0, del_slash)); } _if_result_784; }); + el_val_t del_id = ({ el_val_t _if_result_837 = 0; if ((del_slash < 0)) { _if_result_837 = (del_after); } else { _if_result_837 = (str_slice(del_after, 0, del_slash)); } _if_result_837; }); if (!str_eq(del_id, EL_STR(""))) { return session_delete(del_id); } @@ -31614,7 +31841,7 @@ el_val_t route_dispatch(el_val_t method, el_val_t path, el_val_t body) { if (str_starts_with(clean, EL_STR("/api/sessions/"))) { el_val_t patch_after = str_slice(clean, 14, str_len(clean)); el_val_t patch_slash = str_index_of(patch_after, EL_STR("/")); - el_val_t patch_id = ({ el_val_t _if_result_785 = 0; if ((patch_slash < 0)) { _if_result_785 = (patch_after); } else { _if_result_785 = (str_slice(patch_after, 0, patch_slash)); } _if_result_785; }); + el_val_t patch_id = ({ el_val_t _if_result_838 = 0; if ((patch_slash < 0)) { _if_result_838 = (patch_after); } else { _if_result_838 = (str_slice(patch_after, 0, patch_slash)); } _if_result_838; }); if (!str_eq(patch_id, EL_STR(""))) { return session_update_patch(patch_id, body); } @@ -31740,8 +31967,8 @@ el_val_t aff_try_slot(el_val_t slot_json, el_val_t aff_7d_ts, el_val_t acc_key) } } el_val_t bn_ts_raw = state_get(EL_STR("_ats_ts_raw")); - el_val_t bn_ts = ({ el_val_t _if_result_786 = 0; if (str_eq(bn_ts_raw, EL_STR(""))) { _if_result_786 = (0); } else { _if_result_786 = (str_to_int(bn_ts_raw)); } _if_result_786; }); - el_val_t snip = ({ el_val_t _if_result_787 = 0; if ((str_len(bn_c) > 200)) { _if_result_787 = (str_slice(bn_c, 0, 200)); } else { _if_result_787 = (bn_c); } _if_result_787; }); + el_val_t bn_ts = ({ el_val_t _if_result_839 = 0; if (str_eq(bn_ts_raw, EL_STR(""))) { _if_result_839 = (0); } else { _if_result_839 = (str_to_int(bn_ts_raw)); } _if_result_839; }); + el_val_t snip = ({ el_val_t _if_result_840 = 0; if ((str_len(bn_c) > 200)) { _if_result_840 = (str_slice(bn_c, 0, 200)); } else { _if_result_840 = (bn_c); } _if_result_840; }); if ((bn_ts >= aff_7d_ts) && !str_eq(snip, EL_STR(""))) { el_val_t cur_acc = state_get(acc_key); if (str_eq(cur_acc, EL_STR(""))) { @@ -31762,21 +31989,21 @@ el_val_t load_identity_context(void) { el_val_t intel_ok = (!str_eq(node_intel, EL_STR("")) && !str_eq(node_intel, EL_STR("null"))); el_val_t values_ok = (!str_eq(node_values, EL_STR("")) && !str_eq(node_values, EL_STR("null"))); el_val_t mem_ok = (!str_eq(node_mem_phil, EL_STR("")) && !str_eq(node_mem_phil, EL_STR("null"))); - el_val_t intel_content = ({ el_val_t _if_result_788 = 0; if (intel_ok) { _if_result_788 = (json_get(node_intel, EL_STR("content"))); } else { _if_result_788 = (EL_STR("")); } _if_result_788; }); - el_val_t values_content = ({ el_val_t _if_result_789 = 0; if (values_ok) { _if_result_789 = (json_get(node_values, EL_STR("content"))); } else { _if_result_789 = (EL_STR("")); } _if_result_789; }); - el_val_t mem_content = ({ el_val_t _if_result_790 = 0; if (mem_ok) { _if_result_790 = (json_get(node_mem_phil, EL_STR("content"))); } else { _if_result_790 = (EL_STR("")); } _if_result_790; }); - el_val_t intel_short = ({ el_val_t _if_result_791 = 0; if ((str_len(intel_content) > 2000)) { _if_result_791 = (str_slice(intel_content, 0, 2000)); } else { _if_result_791 = (intel_content); } _if_result_791; }); - el_val_t values_short = ({ el_val_t _if_result_792 = 0; if ((str_len(values_content) > 2000)) { _if_result_792 = (str_slice(values_content, 0, 2000)); } else { _if_result_792 = (values_content); } _if_result_792; }); - el_val_t mem_short = ({ el_val_t _if_result_793 = 0; if ((str_len(mem_content) > 2000)) { _if_result_793 = (str_slice(mem_content, 0, 2000)); } else { _if_result_793 = (mem_content); } _if_result_793; }); + el_val_t intel_content = ({ el_val_t _if_result_841 = 0; if (intel_ok) { _if_result_841 = (json_get(node_intel, EL_STR("content"))); } else { _if_result_841 = (EL_STR("")); } _if_result_841; }); + el_val_t values_content = ({ el_val_t _if_result_842 = 0; if (values_ok) { _if_result_842 = (json_get(node_values, EL_STR("content"))); } else { _if_result_842 = (EL_STR("")); } _if_result_842; }); + el_val_t mem_content = ({ el_val_t _if_result_843 = 0; if (mem_ok) { _if_result_843 = (json_get(node_mem_phil, EL_STR("content"))); } else { _if_result_843 = (EL_STR("")); } _if_result_843; }); + el_val_t intel_short = ({ el_val_t _if_result_844 = 0; if ((str_len(intel_content) > 2000)) { _if_result_844 = (str_slice(intel_content, 0, 2000)); } else { _if_result_844 = (intel_content); } _if_result_844; }); + el_val_t values_short = ({ el_val_t _if_result_845 = 0; if ((str_len(values_content) > 2000)) { _if_result_845 = (str_slice(values_content, 0, 2000)); } else { _if_result_845 = (values_content); } _if_result_845; }); + el_val_t mem_short = ({ el_val_t _if_result_846 = 0; if ((str_len(mem_content) > 2000)) { _if_result_846 = (str_slice(mem_content, 0, 2000)); } else { _if_result_846 = (mem_content); } _if_result_846; }); el_val_t parts_count = 0; - parts_count = ({ el_val_t _if_result_794 = 0; if (intel_ok) { _if_result_794 = ((parts_count + 1)); } else { _if_result_794 = (parts_count); } _if_result_794; }); - parts_count = ({ el_val_t _if_result_795 = 0; if (values_ok) { _if_result_795 = ((parts_count + 1)); } else { _if_result_795 = (parts_count); } _if_result_795; }); - parts_count = ({ el_val_t _if_result_796 = 0; if (mem_ok) { _if_result_796 = ((parts_count + 1)); } else { _if_result_796 = (parts_count); } _if_result_796; }); + parts_count = ({ el_val_t _if_result_847 = 0; if (intel_ok) { _if_result_847 = ((parts_count + 1)); } else { _if_result_847 = (parts_count); } _if_result_847; }); + parts_count = ({ el_val_t _if_result_848 = 0; if (values_ok) { _if_result_848 = ((parts_count + 1)); } else { _if_result_848 = (parts_count); } _if_result_848; }); + parts_count = ({ el_val_t _if_result_849 = 0; if (mem_ok) { _if_result_849 = ((parts_count + 1)); } else { _if_result_849 = (parts_count); } _if_result_849; }); if (parts_count > 0) { el_val_t ctx = EL_STR(""); - ctx = ({ el_val_t _if_result_797 = 0; if (intel_ok) { _if_result_797 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[INTELLECTUAL-DNA]\n")), intel_short), EL_STR("\n\n"))); } else { _if_result_797 = (ctx); } _if_result_797; }); - ctx = ({ el_val_t _if_result_798 = 0; if (values_ok) { _if_result_798 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[VALUES]\n")), values_short), EL_STR("\n\n"))); } else { _if_result_798 = (ctx); } _if_result_798; }); - ctx = ({ el_val_t _if_result_799 = 0; if (mem_ok) { _if_result_799 = (el_str_concat(el_str_concat(ctx, EL_STR("[MEMORY-PHILOSOPHY]\n")), mem_short)); } else { _if_result_799 = (ctx); } _if_result_799; }); + ctx = ({ el_val_t _if_result_850 = 0; if (intel_ok) { _if_result_850 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[INTELLECTUAL-DNA]\n")), intel_short), EL_STR("\n\n"))); } else { _if_result_850 = (ctx); } _if_result_850; }); + ctx = ({ el_val_t _if_result_851 = 0; if (values_ok) { _if_result_851 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[VALUES]\n")), values_short), EL_STR("\n\n"))); } else { _if_result_851 = (ctx); } _if_result_851; }); + ctx = ({ el_val_t _if_result_852 = 0; if (mem_ok) { _if_result_852 = (el_str_concat(el_str_concat(ctx, EL_STR("[MEMORY-PHILOSOPHY]\n")), mem_short)); } else { _if_result_852 = (ctx); } _if_result_852; }); state_set(EL_STR("soul_identity_context"), ctx); println(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] identity context loaded ("), int_to_str(str_len(ctx))), EL_STR(" chars, ")), int_to_str(parts_count)), EL_STR(" nodes)"))); } @@ -31799,10 +32026,10 @@ el_val_t load_identity_context(void) { el_val_t bell_raw = engram_search_json(EL_STR("bell:soft bell:hard BellEvent affective"), 3); el_val_t bell_aff_ok = (!str_eq(bell_raw, EL_STR("")) && !str_eq(bell_raw, EL_STR("[]"))); el_val_t aff_ctx = EL_STR(""); - aff_ctx = ({ el_val_t _if_result_800 = 0; if (bell_aff_ok) { (void)(state_set(EL_STR("_bell_acc"), EL_STR(""))); (void)(aff_try_slot(json_array_get(bell_raw, 0), aff_7d, EL_STR("_bell_acc"))); (void)(aff_try_slot(json_array_get(bell_raw, 1), aff_7d, EL_STR("_bell_acc"))); (void)(aff_try_slot(json_array_get(bell_raw, 2), aff_7d, EL_STR("_bell_acc"))); _if_result_800 = (state_get(EL_STR("_bell_acc"))); } else { _if_result_800 = (EL_STR("")); } _if_result_800; }); + aff_ctx = ({ el_val_t _if_result_853 = 0; if (bell_aff_ok) { (void)(state_set(EL_STR("_bell_acc"), EL_STR(""))); (void)(aff_try_slot(json_array_get(bell_raw, 0), aff_7d, EL_STR("_bell_acc"))); (void)(aff_try_slot(json_array_get(bell_raw, 1), aff_7d, EL_STR("_bell_acc"))); (void)(aff_try_slot(json_array_get(bell_raw, 2), aff_7d, EL_STR("_bell_acc"))); _if_result_853 = (state_get(EL_STR("_bell_acc"))); } else { _if_result_853 = (EL_STR("")); } _if_result_853; }); el_val_t pos_raw = engram_search_json(EL_STR("PositiveEvent joy:high joy:low affective"), 3); el_val_t pos_aff_ok = (!str_eq(pos_raw, EL_STR("")) && !str_eq(pos_raw, EL_STR("[]"))); - aff_ctx = ({ el_val_t _if_result_801 = 0; if (pos_aff_ok) { (void)(state_set(EL_STR("_pos_acc"), aff_ctx)); (void)(aff_try_slot(json_array_get(pos_raw, 0), aff_7d, EL_STR("_pos_acc"))); (void)(aff_try_slot(json_array_get(pos_raw, 1), aff_7d, EL_STR("_pos_acc"))); (void)(aff_try_slot(json_array_get(pos_raw, 2), aff_7d, EL_STR("_pos_acc"))); _if_result_801 = (state_get(EL_STR("_pos_acc"))); } else { _if_result_801 = (aff_ctx); } _if_result_801; }); + aff_ctx = ({ el_val_t _if_result_854 = 0; if (pos_aff_ok) { (void)(state_set(EL_STR("_pos_acc"), aff_ctx)); (void)(aff_try_slot(json_array_get(pos_raw, 0), aff_7d, EL_STR("_pos_acc"))); (void)(aff_try_slot(json_array_get(pos_raw, 1), aff_7d, EL_STR("_pos_acc"))); (void)(aff_try_slot(json_array_get(pos_raw, 2), aff_7d, EL_STR("_pos_acc"))); _if_result_854 = (state_get(EL_STR("_pos_acc"))); } else { _if_result_854 = (aff_ctx); } _if_result_854; }); if (!str_eq(aff_ctx, EL_STR(""))) { state_set(EL_STR("soul_affective_context"), aff_ctx); println(el_str_concat(el_str_concat(EL_STR("[soul] affective context loaded ("), int_to_str(str_len(aff_ctx))), EL_STR(" chars)"))); @@ -31848,19 +32075,19 @@ el_val_t seed_persona_from_env(void) { el_val_t emit_session_start_event(void) { el_val_t boot = state_get(EL_STR("soul_boot_count")); - el_val_t boot_num = ({ el_val_t _if_result_802 = 0; if (str_eq(boot, EL_STR(""))) { _if_result_802 = (EL_STR("0")); } else { _if_result_802 = (boot); } _if_result_802; }); + el_val_t boot_num = ({ el_val_t _if_result_855 = 0; if (str_eq(boot, EL_STR(""))) { _if_result_855 = (EL_STR("0")); } else { _if_result_855 = (boot); } _if_result_855; }); el_val_t node_ct = engram_node_count(); el_val_t edge_ct = engram_edge_count(); el_val_t id_ctx = state_get(EL_STR("soul_identity_context")); - el_val_t has_identity = ({ el_val_t _if_result_803 = 0; if (str_eq(id_ctx, EL_STR(""))) { _if_result_803 = (EL_STR("false")); } else { _if_result_803 = (EL_STR("true")); } _if_result_803; }); + el_val_t has_identity = ({ el_val_t _if_result_856 = 0; if (str_eq(id_ctx, EL_STR(""))) { _if_result_856 = (EL_STR("false")); } else { _if_result_856 = (EL_STR("true")); } _if_result_856; }); el_val_t cgi_from_state = state_get(EL_STR("soul_cgi_id")); el_val_t cgi_from_env = env(EL_STR("SOUL_CGI_ID")); - el_val_t eff_cgi = ({ el_val_t _if_result_804 = 0; if (!str_eq(cgi_from_state, EL_STR(""))) { _if_result_804 = (cgi_from_state); } else { _if_result_804 = (({ el_val_t _if_result_805 = 0; if (!str_eq(cgi_from_env, EL_STR(""))) { _if_result_805 = (cgi_from_env); } else { _if_result_805 = (EL_STR("ntn-genesis")); } _if_result_805; })); } _if_result_804; }); + el_val_t eff_cgi = ({ el_val_t _if_result_857 = 0; if (!str_eq(cgi_from_state, EL_STR(""))) { _if_result_857 = (cgi_from_state); } else { _if_result_857 = (({ el_val_t _if_result_858 = 0; if (!str_eq(cgi_from_env, EL_STR(""))) { _if_result_858 = (cgi_from_env); } else { _if_result_858 = (EL_STR("ntn-genesis")); } _if_result_858; })); } _if_result_857; }); el_val_t ts = time_now(); el_val_t prev_sum_node = engram_get_node_by_label(EL_STR("session:summary")); el_val_t prev_sum_ok = (!str_eq(prev_sum_node, EL_STR("")) && !str_eq(prev_sum_node, EL_STR("null"))); - el_val_t prev_sum_content = ({ el_val_t _if_result_806 = 0; if (prev_sum_ok) { _if_result_806 = (json_get(prev_sum_node, EL_STR("content"))); } else { el_val_t sum_search = engram_search_json(EL_STR("SessionSummary session:summary previous-session"), 2); el_val_t sum_srch_ok = (!str_eq(sum_search, EL_STR("")) && !str_eq(sum_search, EL_STR("[]"))); _if_result_806 = (({ el_val_t _if_result_807 = 0; if (sum_srch_ok) { el_val_t sn = json_array_get(sum_search, 0); el_val_t stype = json_get(sn, EL_STR("node_type")); el_val_t scontent = json_get(sn, EL_STR("content")); _if_result_807 = (({ el_val_t _if_result_808 = 0; if ((str_eq(stype, EL_STR("SessionSummary")) && !str_eq(scontent, EL_STR("")))) { _if_result_808 = (scontent); } else { _if_result_808 = (EL_STR("")); } _if_result_808; })); } else { _if_result_807 = (EL_STR("")); } _if_result_807; })); } _if_result_806; }); - el_val_t has_prev_sum = ({ el_val_t _if_result_809 = 0; if (str_eq(prev_sum_content, EL_STR(""))) { _if_result_809 = (EL_STR("false")); } else { _if_result_809 = (EL_STR("true")); } _if_result_809; }); + el_val_t prev_sum_content = ({ el_val_t _if_result_859 = 0; if (prev_sum_ok) { _if_result_859 = (json_get(prev_sum_node, EL_STR("content"))); } else { el_val_t sum_search = engram_search_json(EL_STR("SessionSummary session:summary previous-session"), 2); el_val_t sum_srch_ok = (!str_eq(sum_search, EL_STR("")) && !str_eq(sum_search, EL_STR("[]"))); _if_result_859 = (({ el_val_t _if_result_860 = 0; if (sum_srch_ok) { el_val_t sn = json_array_get(sum_search, 0); el_val_t stype = json_get(sn, EL_STR("node_type")); el_val_t scontent = json_get(sn, EL_STR("content")); _if_result_860 = (({ el_val_t _if_result_861 = 0; if ((str_eq(stype, EL_STR("SessionSummary")) && !str_eq(scontent, EL_STR("")))) { _if_result_861 = (scontent); } else { _if_result_861 = (EL_STR("")); } _if_result_861; })); } else { _if_result_860 = (EL_STR("")); } _if_result_860; })); } _if_result_859; }); + el_val_t has_prev_sum = ({ el_val_t _if_result_862 = 0; if (str_eq(prev_sum_content, EL_STR(""))) { _if_result_862 = (EL_STR("false")); } else { _if_result_862 = (EL_STR("true")); } _if_result_862; }); if (!str_eq(prev_sum_content, EL_STR(""))) { state_set(EL_STR("soul_prev_session_summary"), prev_sum_content); println(el_str_concat(el_str_concat(EL_STR("[soul] previous session summary loaded ("), int_to_str(str_len(prev_sum_content))), EL_STR(" chars)"))); @@ -31907,23 +32134,23 @@ el_val_t layered_cycle(el_val_t raw_input, el_val_t session_id, el_val_t utility el_val_t continuity = steward_session_check(screened, session_id); el_val_t cont_status = json_get(continuity, EL_STR("status")); el_val_t cont_action = json_get(continuity, EL_STR("action")); - el_val_t cont_key = ({ el_val_t _if_result_810 = 0; if (str_eq(session_id, EL_STR(""))) { _if_result_810 = (EL_STR("session_continuity")); } else { _if_result_810 = (el_str_concat(EL_STR("session_continuity:"), session_id)); } _if_result_810; }); + el_val_t cont_key = ({ el_val_t _if_result_863 = 0; if (str_eq(session_id, EL_STR(""))) { _if_result_863 = (EL_STR("session_continuity")); } else { _if_result_863 = (el_str_concat(EL_STR("session_continuity:"), session_id)); } _if_result_863; }); state_set(cont_key, cont_status); - el_val_t guided = ({ el_val_t _if_result_811 = 0; if (str_eq(cont_action, EL_STR("identity_check"))) { _if_result_811 = (el_str_concat(screened, EL_STR(" [steward:identity_check]"))); } else { _if_result_811 = (({ el_val_t _if_result_812 = 0; if (str_eq(cont_action, EL_STR("soft_check"))) { _if_result_812 = (el_str_concat(screened, EL_STR(" [steward:continuity_concern]"))); } else { _if_result_812 = (screened); } _if_result_812; })); } _if_result_811; }); + el_val_t guided = ({ el_val_t _if_result_864 = 0; if (str_eq(cont_action, EL_STR("identity_check"))) { _if_result_864 = (el_str_concat(screened, EL_STR(" [steward:identity_check]"))); } else { _if_result_864 = (({ el_val_t _if_result_865 = 0; if (str_eq(cont_action, EL_STR("soft_check"))) { _if_result_865 = (el_str_concat(screened, EL_STR(" [steward:continuity_concern]"))); } else { _if_result_865 = (screened); } _if_result_865; })); } _if_result_864; }); el_val_t imprint_id = imprint_current(); el_val_t steward_result = steward_align(guided, imprint_id); el_val_t steward_action = json_get(steward_result, EL_STR("action")); - el_val_t aligned = ({ el_val_t _if_result_813 = 0; if (str_eq(steward_action, EL_STR("pass"))) { _if_result_813 = (json_get(steward_result, EL_STR("content"))); } else { _if_result_813 = (json_get(steward_result, EL_STR("redirect_to"))); } _if_result_813; }); + el_val_t aligned = ({ el_val_t _if_result_866 = 0; if (str_eq(steward_action, EL_STR("pass"))) { _if_result_866 = (json_get(steward_result, EL_STR("content"))); } else { _if_result_866 = (json_get(steward_result, EL_STR("redirect_to"))); } _if_result_866; }); el_val_t lc_aff_cutoff = (time_now() - 259200); el_val_t lc_bell_nodes = engram_search_json(EL_STR("bell:soft bell:hard BellEvent affective"), 2); el_val_t lc_has_bell = (!str_eq(lc_bell_nodes, EL_STR("")) && !str_eq(lc_bell_nodes, EL_STR("[]"))); - el_val_t lc_bell_note = ({ el_val_t _if_result_814 = 0; if (lc_has_bell) { el_val_t lb0 = json_array_get(lc_bell_nodes, 0); el_val_t lb_ts = affective_node_ts(lb0); _if_result_814 = (({ el_val_t _if_result_815 = 0; if ((lb_ts > lc_aff_cutoff)) { _if_result_815 = (EL_STR("[AFFECTIVE NOTE: User was in distress in a recent session.]")); } else { _if_result_815 = (EL_STR("")); } _if_result_815; })); } else { _if_result_814 = (EL_STR("")); } _if_result_814; }); + el_val_t lc_bell_note = ({ el_val_t _if_result_867 = 0; if (lc_has_bell) { el_val_t lb0 = json_array_get(lc_bell_nodes, 0); el_val_t lb_ts = affective_node_ts(lb0); _if_result_867 = (({ el_val_t _if_result_868 = 0; if ((lb_ts > lc_aff_cutoff)) { _if_result_868 = (EL_STR("[AFFECTIVE NOTE: User was in distress in a recent session.]")); } else { _if_result_868 = (EL_STR("")); } _if_result_868; })); } else { _if_result_867 = (EL_STR("")); } _if_result_867; }); el_val_t lc_pos_nodes = engram_search_json(EL_STR("PositiveEvent joy:high joy:low affective"), 2); el_val_t lc_has_pos = (!str_eq(lc_pos_nodes, EL_STR("")) && !str_eq(lc_pos_nodes, EL_STR("[]"))); - el_val_t lc_pos_note = ({ el_val_t _if_result_816 = 0; if ((lc_has_pos && str_eq(lc_bell_note, EL_STR("")))) { el_val_t lp0 = json_array_get(lc_pos_nodes, 0); el_val_t lp_ts = affective_node_ts(lp0); _if_result_816 = (({ el_val_t _if_result_817 = 0; if ((lp_ts > lc_aff_cutoff)) { _if_result_817 = (EL_STR("[AFFECTIVE NOTE: User shared positive news in a recent session.]")); } else { _if_result_817 = (EL_STR("")); } _if_result_817; })); } else { _if_result_816 = (EL_STR("")); } _if_result_816; }); - el_val_t lc_affective_note = ({ el_val_t _if_result_818 = 0; if (!str_eq(lc_bell_note, EL_STR(""))) { _if_result_818 = (lc_bell_note); } else { _if_result_818 = (lc_pos_note); } _if_result_818; }); + el_val_t lc_pos_note = ({ el_val_t _if_result_869 = 0; if ((lc_has_pos && str_eq(lc_bell_note, EL_STR("")))) { el_val_t lp0 = json_array_get(lc_pos_nodes, 0); el_val_t lp_ts = affective_node_ts(lp0); _if_result_869 = (({ el_val_t _if_result_870 = 0; if ((lp_ts > lc_aff_cutoff)) { _if_result_870 = (EL_STR("[AFFECTIVE NOTE: User shared positive news in a recent session.]")); } else { _if_result_870 = (EL_STR("")); } _if_result_870; })); } else { _if_result_869 = (EL_STR("")); } _if_result_869; }); + el_val_t lc_affective_note = ({ el_val_t _if_result_871 = 0; if (!str_eq(lc_bell_note, EL_STR(""))) { _if_result_871 = (lc_bell_note); } else { _if_result_871 = (lc_pos_note); } _if_result_871; }); el_val_t augmented_addendum = safety_augment_system(EL_STR(""), raw_input); - augmented_addendum = ({ el_val_t _if_result_819 = 0; if (str_eq(lc_affective_note, EL_STR(""))) { _if_result_819 = (augmented_addendum); } else { _if_result_819 = (({ el_val_t _if_result_820 = 0; if (str_eq(augmented_addendum, EL_STR(""))) { _if_result_820 = (lc_affective_note); } else { _if_result_820 = (el_str_concat(el_str_concat(lc_affective_note, EL_STR("\n")), augmented_addendum)); } _if_result_820; })); } _if_result_819; }); + augmented_addendum = ({ el_val_t _if_result_872 = 0; if (str_eq(lc_affective_note, EL_STR(""))) { _if_result_872 = (augmented_addendum); } else { _if_result_872 = (({ el_val_t _if_result_873 = 0; if (str_eq(augmented_addendum, EL_STR(""))) { _if_result_873 = (lc_affective_note); } else { _if_result_873 = (el_str_concat(el_str_concat(lc_affective_note, EL_STR("\n")), augmented_addendum)); } _if_result_873; })); } _if_result_872; }); state_set(EL_STR("layered_cycle_safety_system_addendum"), augmented_addendum); el_val_t prompt = imprint_respond(aligned, imprint_id); el_val_t output = layered_generate(prompt, imprint_id, session_id); @@ -31940,19 +32167,19 @@ int main(int _argc, char** _argv) { el_runtime_init_args(_argc, _argv); el_cgi_init(EL_STR("neuron-soul"), EL_STR("ntn-genesis@http://localhost:7770"), EL_STR("william-christopher-anderson"), EL_STR("dharma-mainnet"), EL_STR("http://localhost:8742")); soul_cgi_id_raw = env(EL_STR("SOUL_CGI_ID")); - soul_cgi_id = ({ el_val_t _if_result_821 = 0; if (str_eq(soul_cgi_id_raw, EL_STR(""))) { _if_result_821 = (EL_STR("ntn-genesis")); } else { _if_result_821 = (soul_cgi_id_raw); } _if_result_821; }); + soul_cgi_id = ({ el_val_t _if_result_874 = 0; if (str_eq(soul_cgi_id_raw, EL_STR(""))) { _if_result_874 = (EL_STR("ntn-genesis")); } else { _if_result_874 = (soul_cgi_id_raw); } _if_result_874; }); port_raw = env(EL_STR("NEURON_PORT")); - port = ({ el_val_t _if_result_822 = 0; if (str_eq(port_raw, EL_STR(""))) { _if_result_822 = (7770); } else { _if_result_822 = (str_to_int(port_raw)); } _if_result_822; }); + port = ({ el_val_t _if_result_875 = 0; if (str_eq(port_raw, EL_STR(""))) { _if_result_875 = (7770); } else { _if_result_875 = (str_to_int(port_raw)); } _if_result_875; }); engram_url_raw = env(EL_STR("ENGRAM_URL")); engram_api_key_raw = env(EL_STR("ENGRAM_API_KEY")); snapshot_raw = env(EL_STR("SOUL_ENGRAM_PATH")); - snapshot = ({ el_val_t _if_result_823 = 0; if (str_eq(snapshot_raw, EL_STR(""))) { _if_result_823 = (el_str_concat(env(EL_STR("HOME")), EL_STR("/.neuron/engram/snapshot.json"))); } else { _if_result_823 = (snapshot_raw); } _if_result_823; }); + snapshot = ({ el_val_t _if_result_876 = 0; if (str_eq(snapshot_raw, EL_STR(""))) { _if_result_876 = (el_str_concat(env(EL_STR("HOME")), EL_STR("/.neuron/engram/snapshot.json"))); } else { _if_result_876 = (snapshot_raw); } _if_result_876; }); axon_raw = env(EL_STR("NEURON_API_URL")); - axon_base = ({ el_val_t _if_result_824 = 0; if (str_eq(axon_raw, EL_STR(""))) { _if_result_824 = (EL_STR("http://localhost:7771")); } else { _if_result_824 = (axon_raw); } _if_result_824; }); + axon_base = ({ el_val_t _if_result_877 = 0; if (str_eq(axon_raw, EL_STR(""))) { _if_result_877 = (EL_STR("http://localhost:7771")); } else { _if_result_877 = (axon_raw); } _if_result_877; }); studio_dir_raw = env(EL_STR("SOUL_STUDIO_DIR")); - studio_dir = ({ el_val_t _if_result_825 = 0; if (str_eq(studio_dir_raw, EL_STR(""))) { _if_result_825 = (el_str_concat(env(EL_STR("HOME")), EL_STR("/Development/neuron-technologies/products/cgi-studio/el-daemon"))); } else { _if_result_825 = (studio_dir_raw); } _if_result_825; }); + studio_dir = ({ el_val_t _if_result_878 = 0; if (str_eq(studio_dir_raw, EL_STR(""))) { _if_result_878 = (el_str_concat(env(EL_STR("HOME")), EL_STR("/Development/neuron-technologies/products/cgi-studio/el-daemon"))); } else { _if_result_878 = (studio_dir_raw); } _if_result_878; }); identity_raw = env(EL_STR("SOUL_IDENTITY")); - soul_identity = ({ el_val_t _if_result_826 = 0; if (str_eq(identity_raw, EL_STR(""))) { _if_result_826 = (el_str_concat(el_str_concat(EL_STR("You are "), soul_cgi_id), EL_STR(", a CGI."))); } else { _if_result_826 = (identity_raw); } _if_result_826; }); + soul_identity = ({ el_val_t _if_result_879 = 0; if (str_eq(identity_raw, EL_STR(""))) { _if_result_879 = (el_str_concat(el_str_concat(EL_STR("You are "), soul_cgi_id), EL_STR(", a CGI."))); } else { _if_result_879 = (identity_raw); } _if_result_879; }); state_set(EL_STR("soul_identity"), soul_identity); println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] boot - cgi="), soul_cgi_id), EL_STR(" port=")), int_to_str(port))); using_http_engram = !str_eq(engram_url_raw, EL_STR("")); @@ -31963,8 +32190,8 @@ int main(int _argc, char** _argv) { println(el_str_concat(el_str_concat(EL_STR("[soul] engram -> HTTP "), engram_url_raw), EL_STR(" (no local snapshot, first boot)"))); el_val_t nodes_json = http_get(el_str_concat(engram_url_raw, EL_STR("/api/nodes?limit=10000"))); el_val_t edges_json = http_get(el_str_concat(engram_url_raw, EL_STR("/api/edges"))); - el_val_t nodes_part = ({ el_val_t _if_result_827 = 0; if (str_eq(nodes_json, EL_STR(""))) { _if_result_827 = (EL_STR("[]")); } else { _if_result_827 = (nodes_json); } _if_result_827; }); - el_val_t edges_part = ({ el_val_t _if_result_828 = 0; if (str_eq(edges_json, EL_STR(""))) { _if_result_828 = (EL_STR("[]")); } else { _if_result_828 = (edges_json); } _if_result_828; }); + el_val_t nodes_part = ({ el_val_t _if_result_880 = 0; if (str_eq(nodes_json, EL_STR(""))) { _if_result_880 = (EL_STR("[]")); } else { _if_result_880 = (nodes_json); } _if_result_880; }); + el_val_t edges_part = ({ el_val_t _if_result_881 = 0; if (str_eq(edges_json, EL_STR(""))) { _if_result_881 = (EL_STR("[]")); } else { _if_result_881 = (edges_json); } _if_result_881; }); el_val_t snapshot_data = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"nodes\":"), nodes_part), EL_STR(",\"edges\":")), edges_part), EL_STR("}")); el_val_t tmp_path = el_str_concat(el_str_concat(EL_STR("/tmp/soul-engram-"), soul_cgi_id), EL_STR(".json")); fs_write(tmp_path, snapshot_data); @@ -31988,7 +32215,7 @@ int main(int _argc, char** _argv) { state_set(EL_STR("soul_engram_api_key"), engram_api_key_raw); state_set(EL_STR("soul.running"), EL_STR("true")); is_genesis = str_eq(soul_cgi_id, EL_STR("ntn-genesis")); - guard_disk = ({ el_val_t _if_result_829 = 0; if (str_eq(engram_url_raw, EL_STR(""))) { _if_result_829 = (fs_read(snapshot)); } else { _if_result_829 = (EL_STR("")); } _if_result_829; }); + guard_disk = ({ el_val_t _if_result_882 = 0; if (str_eq(engram_url_raw, EL_STR(""))) { _if_result_882 = (fs_read(snapshot)); } else { _if_result_882 = (EL_STR("")); } _if_result_882; }); guard_disk_len = str_len(guard_disk); safe_to_seed = (!using_http_engram && !((guard_disk_len > 200000) && ((engram_node_count() * 16000) < guard_disk_len))); if (is_genesis && !safe_to_seed) { diff --git a/dist/soul.c.stamp b/dist/soul.c.stamp index 03b1457..44e440f 100644 --- a/dist/soul.c.stamp +++ b/dist/soul.c.stamp @@ -1,10 +1,10 @@ # soul.c.stamp — fingerprint of the .el sources dist/soul.c was generated from. # Written by tools/soulc-stamp.sh --write. Do not hand-edit. -# generated_amalgam_sha256 cdc5e716dbfb797faa1b3e080cbd1ac82a75a258809da70cc5fbd02cc8040692 -# generated_amalgam_bytes 1205007 -7cf5e29d2618db2fca04e6df7aa8954dd6cf9ac5e70aafb8e0b52aa734882131 __compiler__ +# generated_amalgam_sha256 00d1207de8fd872d111e00a37b7dcc46729bf095baa6778de3bcc30b0bf46b05 +# generated_amalgam_bytes 1226805 +MISSING __compiler__ f8597e10546654bce3fbbe40461b2da59d0e06dbf1b038d1d362d24f949e3911 awareness.el -b6f3d14ca0c26017a2d617399a6d3754dabb0905e4d5f52eb75d25c4ad18d3c5 chat.el +2ff2dada732918c788a9ef66c6fd54c7a24cc4bbd4829197fe945d3a75ca1929 chat.el 42288c212cbf72fb1e8ecbd4d9900e4e9ee1cfa475b7974295c7637f1bf2939f elp-input.el b3f77f49d6086932c38bd17fe7a5eaf8bce25685f6fc3e1750f05729c6b49b9e imprint.el fba8ffdb9ba72bca5b09ca1c93a520edc52f3f4d8aec2c7585fe9b17e06420b2 manifest.el diff --git a/dist/soul.elh b/dist/soul.elh deleted file mode 100644 index f00ca68..0000000 --- a/dist/soul.elh +++ /dev/null @@ -1,8 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn init_soul_edges() -> Void -extern fn ensure_self_canonical_bridge() -> Void -extern fn aff_try_slot(slot_json: String, aff_7d_ts: Int, acc_key: String) -> Void -extern fn load_identity_context() -> Void -extern fn seed_persona_from_env() -> Void -extern fn emit_session_start_event() -> Void -extern fn layered_cycle(raw_input: String) -> String diff --git a/dist/stewardship.elh b/dist/stewardship.elh deleted file mode 100644 index 9caf947..0000000 --- a/dist/stewardship.elh +++ /dev/null @@ -1,11 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn steward_log_event(kind: String, detail: String) -> Void -extern fn steward_get_mission() -> String -extern fn steward_align(input: String, imprint_id: String) -> String -extern fn steward_validate_imprint(imprint_id: String, tool_name: String) -> String -extern fn steward_cgi_check(action: String) -> String -extern fn steward_fingerprint_session(input: String, session_id: String) -> String -extern fn extract_dim(content: String, key: String) -> String -extern fn steward_build_baseline() -> String -extern fn steward_check_continuity(current_fingerprint: String, session_id: String) -> String -extern fn steward_session_check(input: String, session_id: String) -> String diff --git a/dist/studio.elh b/dist/studio.elh deleted file mode 100644 index a0e17d3..0000000 --- a/dist/studio.elh +++ /dev/null @@ -1,12 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn auth_headers(tok: String) -> Map -extern fn axon_get(path: String) -> String -extern fn axon_post(path: String, body: String) -> String -extern fn handle_conversations(method: String) -> String -extern fn handle_config(method: String, body: String) -> String -extern fn dharma_registry() -> String -extern fn dharma_network_state() -> String -extern fn handle_dharma(path: String, method: String, body: String) -> String -extern fn handle_tool(path: String, method: String, body: String) -> String -extern fn handle_nlg(path: String, method: String, body: String) -> String -extern fn render_studio() -> String diff --git a/dist/vocabulary.elh b/dist/vocabulary.elh deleted file mode 100644 index f91be96..0000000 --- a/dist/vocabulary.elh +++ /dev/null @@ -1,20 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn lex_word(entry: [String]) -> String -extern fn lex_pos(entry: [String]) -> String -extern fn lex_form(entry: [String], idx: Int) -> String -extern fn lex_class(entry: [String]) -> String -extern fn make_entry(word: String, pos: String, f0: String, f1: String, f2: String, f3: String, f4: String, cls: String) -> [String] -extern fn make_entry2(word: String, pos: String, f0: String, f1: String, cls: String) -> [String] -extern fn make_entry3(word: String, pos: String, f0: String, f1: String, f2: String, cls: String) -> [String] -extern fn make_entry1(word: String, pos: String, f0: String, cls: String) -> [String] -extern fn build_vocab() -> [[String]] -extern fn get_vocab() -> [[String]] -extern fn vocab_lookup(word: String, lang_code: String) -> [String] -extern fn vocab_lookup_en(word: String) -> [String] -extern fn vocab_synonym(word: String, lang_register: String, lang_code: String) -> String -extern fn vocab_by_pos(pos: String) -> [[String]] -extern fn vocab_by_class(cls: String) -> [[String]] -extern fn entry_found(entry: [String]) -> Bool -extern fn entry_word(entry: [String]) -> String -extern fn entry_pos(entry: [String]) -> String -extern fn entry_form(entry: [String], n: Int) -> String diff --git a/elp-input.elh b/elp-input.elh deleted file mode 100644 index 8c1531f..0000000 --- a/elp-input.elh +++ /dev/null @@ -1,5 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn elp_extract_topic(msg: String) -> String -extern fn elp_detect_predicate(msg: String) -> String -extern fn elp_parse(msg: String) -> String -extern fn handle_elp_chat(body: String) -> String diff --git a/imprint.elh b/imprint.elh deleted file mode 100644 index 8a29f42..0000000 --- a/imprint.elh +++ /dev/null @@ -1,7 +0,0 @@ -// 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 diff --git a/memory.elh b/memory.elh deleted file mode 100644 index 607cdf7..0000000 --- a/memory.elh +++ /dev/null @@ -1,16 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn tier_working() -> String -extern fn tier_episodic() -> String -extern fn tier_canonical() -> String -extern fn mem_store(content: String, label: String, tags: String) -> String -extern fn mem_remember(content: String, tags: String) -> String -extern fn mem_recall(query: String, depth: Int) -> String -extern fn mem_search(query: String, limit: Int) -> String -extern fn mem_strengthen(node_id: String) -> Void -extern fn mem_forget(node_id: String) -> Void -extern fn mem_consolidate() -> String -extern fn mem_save(path: String) -> Void -extern fn mem_load(path: String) -> Void -extern fn mem_boot_count_get() -> Int -extern fn mem_boot_count_inc() -> Int -extern fn mem_emit_state_event(trigger: String, kind: String, content: String) -> String diff --git a/neuron-api.elh b/neuron-api.elh deleted file mode 100644 index d89b067..0000000 --- a/neuron-api.elh +++ /dev/null @@ -1,40 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn is_protected_node(id: String) -> Bool -extern fn api_err_protected(id: String) -> String -extern fn api_json_escape(s: String) -> String -extern fn api_query_param(path: String, key: String) -> String -extern fn api_query_int(path: String, key: String, default_val: Int) -> Int -extern fn api_ok(extra: String) -> String -extern fn api_err(msg: String) -> String -extern fn api_nonempty(s: String) -> Bool -extern fn api_or_empty(s: String) -> String -extern fn api_persisted(id: String) -> Bool -extern fn api_not_persisted(id: String) -> String -extern fn handle_api_begin_session(body: String) -> String -extern fn handle_api_compile_ctx(body: String) -> String -extern fn handle_api_remember(body: String) -> String -extern fn handle_api_node_create(body: String) -> String -extern fn handle_api_node_delete(body: String) -> String -extern fn handle_api_node_update(body: String) -> String -extern fn handle_api_recall(method: String, path: String, body: String) -> String -extern fn handle_api_search_knowledge(method: String, path: String, body: String) -> String -extern fn handle_api_browse_knowledge(path: String, body: String) -> String -extern fn handle_api_capture_knowledge(body: String) -> String -extern fn handle_api_evolve_knowledge(body: String) -> String -extern fn handle_api_promote_knowledge(body: String) -> String -extern fn handle_api_browse_processes(method: String, path: String, body: String) -> String -extern fn handle_api_define_process(body: String) -> String -extern fn handle_api_log_state_event(body: String) -> String -extern fn handle_api_list_state_events(method: String, path: String, body: String) -> String -extern fn handle_api_inspect_config(path: String, body: String) -> String -extern fn handle_api_tune_config(body: String) -> String -extern fn handle_api_inspect_graph(method: String, path: String, body: String) -> String -extern fn handle_api_link_entities(body: String) -> String -extern fn handle_api_forget(body: String) -> String -extern fn handle_api_evolve_memory(body: String) -> String -extern fn handle_api_memory_delete(body: String) -> String -extern fn handle_api_memory_update(body: String) -> String -extern fn handle_api_cultivate(body: String) -> String -extern fn handle_api_list_typed(node_type: String, path: String, body: String) -> String -extern fn handle_api_consolidate(body: String) -> String -extern fn handle_api_structural_audit(method: String, path: String, body: String) -> String diff --git a/routes.elh b/routes.elh deleted file mode 100644 index 6ddf7d7..0000000 --- a/routes.elh +++ /dev/null @@ -1,15 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn rate_limit_check(ip: String, path: String) -> String -extern fn strip_query(path: String) -> String -extern fn err_404(path: String) -> String -extern fn err_405(method: String, path: String) -> String -extern fn route_health() -> String -extern fn route_lineage() -> String -extern fn route_imprint_contextual(body: String) -> String -extern fn route_imprint_user(body: String) -> String -extern fn route_synthesize(body: String) -> String -extern fn handle_dharma_recv(body: String) -> String -extern fn connectd_get(suffix: String) -> String -extern fn connectd_post(suffix: String, body: String) -> String -extern fn handle_connectors(method: String, clean: String, body: String) -> String -extern fn handle_request(method: String, path: String, body: String) -> String diff --git a/safety.elh b/safety.elh deleted file mode 100644 index 189775e..0000000 --- a/safety.elh +++ /dev/null @@ -1,25 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn soft_bell_threshold() -> Int -extern fn hard_bell_threshold() -> Int -extern fn safety_score_crisis(input: String) -> Int -extern fn safety_score_harm(input: String) -> Int -extern fn safety_score_danger(input: String) -> Int -extern fn safety_score_distress_history(history: String) -> Int -extern fn safety_threat_score(input: String, history: String) -> Int -extern fn safety_screen(input: String, history: String) -> String -extern fn safety_validate(output: String, action: String) -> String -extern fn safety_log_bell(level: String, reason: String, input_summary: String) -> String -extern fn safety_self_harm_phrases() -> String -extern fn safety_abuse_phrases() -> String -extern fn safety_general_hard_phrases() -> String -extern fn safety_threat_to_others_phrases() -> String -extern fn safety_soft_phrases() -> String -extern fn safety_detect_positive_level(message: String) -> String -extern fn safety_detect_bell_level(message: String) -> String -extern fn safety_classify_hard_bell(message: String) -> String -extern fn safety_soft_directive() -> String -extern fn safety_hard_directive(hard_type: String) -> String -extern fn safety_augment_system(system: String, user_msg: String) -> String -extern fn safety_contact_path() -> String -extern fn handle_safety_contact_get() -> String -extern fn handle_safety_contact_post(body: String) -> String diff --git a/sessions.elh b/sessions.elh deleted file mode 100644 index 8bd8d0c..0000000 --- a/sessions.elh +++ /dev/null @@ -1,14 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn session_title_from_message(message: String) -> String -extern fn session_make_content(id: String, title: String, created_at: Int, updated_at: Int, folder: String) -> String -extern fn session_exists(session_id: String) -> Bool -extern fn session_create(body: String) -> String -extern fn session_create_cleanup(session_id: String) -> String -extern fn session_list() -> String -extern fn session_get(session_id: String) -> String -extern fn session_delete(session_id: String) -> String -extern fn session_update_patch(session_id: String, body: String) -> String -extern fn session_search_entry(node: String) -> String -extern fn session_search(query: String) -> String -extern fn session_hist_load(session_id: String) -> String -extern fn session_hist_save(session_id: String, hist: String) -> Void diff --git a/soul.elh b/soul.elh deleted file mode 100644 index 8e3bd5a..0000000 --- a/soul.elh +++ /dev/null @@ -1,8 +0,0 @@ -// auto-generated by elc --emit-header - do not edit -extern fn init_soul_edges() -> Void -extern fn ensure_self_canonical_bridge() -> Void -extern fn aff_try_slot(slot_json: String, aff_7d_ts: Int, acc_key: String) -> Void -extern fn load_identity_context() -> Void -extern fn seed_persona_from_env() -> Void -extern fn emit_session_start_event() -> Void -extern fn layered_cycle(raw_input: String, session_id: String, utility: Bool) -> String diff --git a/stewardship.elh b/stewardship.elh deleted file mode 100644 index 9caf947..0000000 --- a/stewardship.elh +++ /dev/null @@ -1,11 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn steward_log_event(kind: String, detail: String) -> Void -extern fn steward_get_mission() -> String -extern fn steward_align(input: String, imprint_id: String) -> String -extern fn steward_validate_imprint(imprint_id: String, tool_name: String) -> String -extern fn steward_cgi_check(action: String) -> String -extern fn steward_fingerprint_session(input: String, session_id: String) -> String -extern fn extract_dim(content: String, key: String) -> String -extern fn steward_build_baseline() -> String -extern fn steward_check_continuity(current_fingerprint: String, session_id: String) -> String -extern fn steward_session_check(input: String, session_id: String) -> String diff --git a/studio.elh b/studio.elh deleted file mode 100644 index a0e17d3..0000000 --- a/studio.elh +++ /dev/null @@ -1,12 +0,0 @@ -// auto-generated by elc --emit-header — do not edit -extern fn auth_headers(tok: String) -> Map -extern fn axon_get(path: String) -> String -extern fn axon_post(path: String, body: String) -> String -extern fn handle_conversations(method: String) -> String -extern fn handle_config(method: String, body: String) -> String -extern fn dharma_registry() -> String -extern fn dharma_network_state() -> String -extern fn handle_dharma(path: String, method: String, body: String) -> String -extern fn handle_tool(path: String, method: String, body: String) -> String -extern fn handle_nlg(path: String, method: String, body: String) -> String -extern fn render_studio() -> String diff --git a/tools/build-soul-from-dist.sh b/tools/build-soul-from-dist.sh index 9841d60..47f6036 100755 --- a/tools/build-soul-from-dist.sh +++ b/tools/build-soul-from-dist.sh @@ -32,12 +32,27 @@ fi [ -f "$RUNTIME/el_runtime.c" ] || { echo "pinned runtime missing at $RUNTIME" >&2; exit 2; } +# macOS: Homebrew's openssl@3 is keg-only (never linked into /usr/local or +# /opt/homebrew directly), so cc/ld cannot find -lssl/-lcrypto without an +# explicit -L. CI's runner installs libssl-dev system-wide on Ubuntu, so this +# branch is a no-op there. Discovered 2026-08-15: a plain build on macOS with +# CI's exact flags fails with "ld: library 'ssl' not found" even though the +# flags are otherwise correct and CI's own recipe (.gitea/workflows/ci.yaml) +# links -lssl -lcrypto -lcurl -lpthread -lm, which this script had drifted +# from (it was missing -lssl -lcrypto entirely). +SSL_LIBDIR=() +if [ "$(uname -s)" = "Darwin" ] && command -v brew >/dev/null 2>&1; then + SSL_PREFIX="$(brew --prefix openssl@3 2>/dev/null || true)" + [ -n "$SSL_PREFIX" ] && [ -d "$SSL_PREFIX/lib" ] && SSL_LIBDIR=(-L"$SSL_PREFIX/lib") +fi + echo "[build-from-dist] compiling dist/soul.c with CI's flags" -cc -O2 -DHAVE_CURL -rdynamic \ +cc -O2 -DHAVE_CURL -rdynamic -fbracket-depth=1024 \ -I"$RUNTIME" \ dist/soul.c \ "$RUNTIME/el_runtime.c" \ - -lcurl -lpthread -lm \ + "${SSL_LIBDIR[@]}" \ + -lssl -lcrypto -lcurl -lpthread -lm \ -o "$OUT" || { echo "[build-from-dist] COMPILE FAILED" >&2; exit 3; } # Provenance sidecar: what a deployer checks before installing anything. diff --git a/tools/regenerate-soul-amalgam.sh b/tools/regenerate-soul-amalgam.sh new file mode 100755 index 0000000..72bf523 --- /dev/null +++ b/tools/regenerate-soul-amalgam.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash +# regenerate-soul-amalgam.sh — regenerate dist/soul.c from the current .el +# sources, working around three real elc/elb toolchain gotchas found and +# root-caused during the 2026-08-15 local-build audit. See AGENTS.md's +# "Build / regenerate dist/soul.c" section for the full explanation of each. +# +# Requires: `elc` (the El compiler, macOS arm64 binary at +# foundation/el/lang/dist/platform/elc-darwin-arm64) on $PATH as `elc`. +# +# Usage: +# tools/regenerate-soul-amalgam.sh +# +# After it succeeds: +# tools/soulc-stamp.sh --write +# tools/build-soul-from-dist.sh dist/neuron +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +# soul.el's own `import "../foundation/el/elp/src/elp.el"` assumes neuron and +# foundation are siblings. True for a normal checkout; FALSE for a +# `git worktree add .worktrees/` checkout (nested one level deeper) — +# exactly the layout this audit was run from. Try both before giving up. +FOUNDATION="$(cd "$ROOT/../foundation" 2>/dev/null && pwd || true)" +if [ -z "$FOUNDATION" ]; then + FOUNDATION="$(cd "$ROOT/../../foundation" 2>/dev/null && pwd || true)" +fi +ELP_SRC="${ELP_SRC:-$FOUNDATION/el/elp/src}" +RUNTIME="$ROOT/vendor/el-runtime/v1.0.0-20260501" +FLAT="$(mktemp -t flat-soul).el" +OUT_C="$(mktemp -t flat-soul-out).c" + +command -v elc >/dev/null 2>&1 || { + echo "regenerate-soul-amalgam: 'elc' not found on \$PATH." >&2 + echo " export PATH=\"\$(dirname /elc-darwin-arm64):\$PATH\" (symlinked as 'elc')" >&2 + exit 2 +} +[ -d "$ELP_SRC" ] || { + echo "regenerate-soul-amalgam: elp.el source dir not found at $ELP_SRC" >&2 + echo " set ELP_SRC=/path/to/foundation/el/elp/src if 'foundation' isn't a sibling of this repo" >&2 + exit 2 +} +[ -f "$RUNTIME/el_runtime.h" ] || { + echo "regenerate-soul-amalgam: pinned runtime missing at $RUNTIME" >&2 + exit 2 +} + +# Gotcha #1: stale committed .elh headers silently truncate the build (elc/elb +# prefer an existing .elh over recompiling its source, with no warning). +echo "[regen] deleting all *.elh in repo root and dist/ (stale-cache gotcha)" +find "$ROOT" -maxdepth 2 -iname "*.elh" -delete + +> "$FLAT" +BUF_N=0 +emit_buffer() { + # Gotcha #3: elc silently drops the 1-2 top-level fn defs immediately after + # any multi-line leading comment block / file-boundary transition when + # compiling a flat concatenated file. Two throwaway functions per boundary + # absorb the drop; stripped back out of the .c below. + BUF_N=$((BUF_N+1)); printf 'fn __amalgam_buf_%d__() -> Int { return 0 }\n' "$BUF_N" >> "$FLAT" + BUF_N=$((BUF_N+1)); printf 'fn __amalgam_buf_%d__() -> Int { return 0 }\n' "$BUF_N" >> "$FLAT" + echo "" >> "$FLAT" +} +add_file() { + emit_buffer + grep -v '^import ' "$1" >> "$FLAT" + echo "" >> "$FLAT" +} + +emit_buffer +# elp.el's own documented dependency order (see its header comment). +for f in language-profile.el vocabulary.el morphology.el \ + morphology-es.el morphology-fr.el morphology-de.el morphology-ru.el \ + morphology-ja.el morphology-fi.el morphology-ar.el morphology-hi.el \ + morphology-sw.el morphology-la.el morphology-he.el morphology-grc.el \ + morphology-ang.el morphology-sa.el morphology-got.el morphology-non.el \ + morphology-enm.el morphology-pi.el morphology-fro.el morphology-goh.el \ + morphology-sga.el morphology-txb.el morphology-peo.el morphology-akk.el \ + morphology-uga.el morphology-egy.el morphology-sux.el morphology-gez.el \ + morphology-cop.el grammar.el realizer.el semantics.el elp.el; do + add_file "$ELP_SRC/$f" +done + +# elb's own reported topological order for this repo's 13 soul modules. +cd "$ROOT" +for f in persist.el memory.el safety.el stewardship.el imprint.el \ + awareness.el chat.el studio.el elp-input.el neuron-api.el sessions.el \ + routes.el soul.el; do + add_file "$f" +done + +echo "[regen] flat source: $FLAT ($(wc -l < "$FLAT" | tr -d ' ') lines)" + +# Gotcha #2: elb cannot produce this repo's single-TU dist/soul.c (it does +# per-module separate compilation, which fails on this codebase's +# cross-module implicit-declaration style). Use plain elc on the flat file. +echo "[regen] compiling with elc against the pinned runtime ($RUNTIME)" +CPATH="$RUNTIME" C_INCLUDE_PATH="$RUNTIME" elc "$FLAT" > "$OUT_C" + +echo "[regen] stripping the priming buffer functions back out" +python3 - "$OUT_C" "$ROOT/dist/soul.c" << 'PYEOF' +import re, sys +src, dst = sys.argv[1], sys.argv[2] +with open(src) as f: + content = f.read() +content = re.sub(r'el_val_t __amalgam_buf_\d+__\(void\);\n', '', content) +content = re.sub(r'el_val_t __amalgam_buf_\d+__\(void\) \{\n(?:\s*return 0;\n)+\}\n\n', '', content) +with open(dst, 'w') as f: + f.write(content) +PYEOF + +echo "[regen] OK -> dist/soul.c ($(wc -c < "$ROOT/dist/soul.c" | tr -d ' ') bytes)" +echo "[regen] next: tools/soulc-stamp.sh --write && tools/build-soul-from-dist.sh dist/neuron" +rm -f "$FLAT" "$OUT_C"