Skip to content

Commit c2d6432

Browse files
feat: RSI builtins, universal archaeology module, apiproxy upgrades, JS runtime
Core builtins (interpreter.rs + code_intel.rs): - omc_code_valid(src) — parse-validates LLM-generated OMC without throwing - fn_snapshot/fn_rollback/fn_snapshot_all/fn_rollback_all — per-fn LIFO stacks for safe recursive self-improvement rollback - fn_bench(name, args, n) — wall-clock micro-benchmark any OMC function - time_ms() — Unix epoch milliseconds - code_parse_check(src) — {ok, error} parse result dict RSI library (examples/lib/rsi.omc): - Full recursive self-improvement framework: score_candidate, inner_loop, meta_improve_hint, run_rsi — reusable by any demo RSI demo hardening (examples/demos/recursive_improve.omc): - Fixed reversed llm_call(MODEL, prompt) → llm_call(prompt, MODEL) - Fixed arr_push reassignment bug (returns null, mutates in place) - Fixed str_find_from (nonexistent) → str_slice+str_find on suffix - Injected OMC_SYNTAX cheatsheet into all LLM prompts - Added omc_code_valid guards before metric calls on generated code Universal archaeology module (examples/lib/archaeology.omc): - detect_language — 10-language extension dispatch - omc_attractor_density as universal scorer (ANY text, no parsing) - omc_code_similarity for OMC, str_similarity for Python/Rust/JS/etc. - cluster_pairs — union-find duplicate grouping via Rc-shared arrays - archaeology_scan(base, opts) — multi-extension, multi-language entry point - archaeology_narrate(results, model) — Claude architectural analysis - Verified on 244 OMC files (3476 fns) and 29 Python ML experiment files New demos: - codebase_archaeologist.omc — thin wrapper using archaeology module - python_archaeologist.omc — cross-language Python substrate analysis JS runtime + demo ports (examples/omc-runtime.js + demos/*.js): - omc-runtime.js: full OMC interpreter in JavaScript - substrate_rag.js, recursive_improve.js, self_improving_agent.js, code_gen_loop.js, context_compression.js — browser/Node-runnable ports Apiproxy upgrades (omnimcode-apiproxy/src/main.rs): - Conversation tracking, differential history, adjacent marker collapse, intra-request dedup, sysreminder templates, streaming side-recording, adaptive compression, omc_proxy_namespace multi-tenant isolation Test suite additions: - test_rsi_builtins.omc, test_rsi_lib.omc, test_batch_llm.omc, test_llm_stream.omc, test_llm_tools.omc, test_process_builtins.omc Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 47497a8 commit c2d6432

29 files changed

Lines changed: 5003 additions & 158 deletions

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/demos/code_gen_loop.js

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# codebase_archaeologist.omc
2+
#
3+
# Thin demo wrapper for the universal archaeology module.
4+
# Works on .omc, .py, .rs, .ts, .js, .go, or any mix.
5+
#
6+
# Usage: omc examples/demos/codebase_archaeologist.omc
7+
# LLM_PROVIDER=anthropic ANTHROPIC_API_KEY=... omc examples/demos/codebase_archaeologist.omc
8+
9+
import "examples/lib/archaeology.omc"
10+
11+
h SCAN_PATH = "examples"
12+
h MODEL = "claude-haiku-4-5-20251001"
13+
h opts = {
14+
"extensions": [".omc"],
15+
"top_n": 8,
16+
"threshold": 0.78,
17+
"check_limit": 40,
18+
"ref_weight": 5.0,
19+
"fn_weight": 0.5
20+
}
21+
22+
# ── Run ────────────────────────────────────────────────────────────────────────
23+
24+
print("╔══════════════════════════════════════════════════╗")
25+
print("║ Codebase Archaeologist (Universal Edition) ║")
26+
print("╚══════════════════════════════════════════════════╝")
27+
print("")
28+
print("[ 1/3 ] Scanning " + SCAN_PATH + " ...")
29+
print("")
30+
31+
h results = archaeology_scan(SCAN_PATH, opts)
32+
h top = results["attractors"]
33+
h clusters = results["clusters"]
34+
h stats = results["stats"]
35+
36+
# ── Top attractors ─────────────────────────────────────────────────────────────
37+
38+
print("╔══════════════════════════════════════════════════╗")
39+
print("║ Top Attractor Modules ║")
40+
print("╚══════════════════════════════════════════════════╝")
41+
print("")
42+
print(" Files: " + to_string(stats["file_count"]))
43+
print(" Functions: " + to_string(stats["total_fns"]))
44+
print(" Language: " + stats["primary_lang"])
45+
print("")
46+
47+
h ti = 0
48+
while ti < arr_len(top) {
49+
h m = top[ti]
50+
h slash = str_rfind(m["path"], "/")
51+
h short = if slash >= 0 { str_slice(m["path"], slash + 1, str_len(m["path"])) } else { m["path"] }
52+
print(" " + to_string(ti + 1) + ". " + short)
53+
print(" attractor: " + to_string(m["attractor_score"]))
54+
print(" density: " + to_string(m["density"]))
55+
print(" functions: " + to_string(m["fn_count"]))
56+
print(" imported-by:" + to_string(m["refs"]) + " other modules")
57+
print(" lang: " + m["lang"])
58+
print("")
59+
ti += 1
60+
}
61+
62+
# ── Duplicate clusters ─────────────────────────────────────────────────────────
63+
64+
if arr_len(clusters) > 0 {
65+
print("╔══════════════════════════════════════════════════╗")
66+
print("║ Semantic Duplicate Clusters ║")
67+
print("╚══════════════════════════════════════════════════╝")
68+
print("")
69+
h ci = 0
70+
while ci < arr_len(clusters) {
71+
h grp = clusters[ci]
72+
print(" Cluster " + to_string(ci + 1) + " (" + to_string(arr_len(grp)) + " members):")
73+
h mi = 0
74+
while mi < arr_len(grp) {
75+
h slash2 = str_rfind(grp[mi], "/")
76+
h short2 = if slash2 >= 0 { str_slice(grp[mi], slash2 + 1, str_len(grp[mi])) } else { grp[mi] }
77+
print(" • " + short2)
78+
mi += 1
79+
}
80+
print("")
81+
ci += 1
82+
}
83+
} else {
84+
print("[ No semantic duplicate clusters found. ]")
85+
print("")
86+
}
87+
88+
# ── Claude narration ───────────────────────────────────────────────────────────
89+
90+
print("[ 2/3 ] Asking Claude to narrate the architecture...")
91+
print("")
92+
h narration = archaeology_narrate(results, MODEL)
93+
94+
print("╔══════════════════════════════════════════════════╗")
95+
print("║ Architectural Analysis (Claude) ║")
96+
print("╚══════════════════════════════════════════════════╝")
97+
print("")
98+
print(narration)
99+
print("")
100+
101+
# ── Summary ────────────────────────────────────────────────────────────────────
102+
103+
print("[ 3/3 ] Done.")
104+
print("")
105+
print("╔══════════════════════════════════════════════════╗")
106+
print("║ Summary ║")
107+
print("╚══════════════════════════════════════════════════╝")
108+
print(" Files scanned: " + to_string(stats["file_count"]))
109+
print(" Functions mapped: " + to_string(stats["total_fns"]))
110+
print(" Dup clusters: " + to_string(arr_len(clusters)))
111+
if arr_len(top) > 0 {
112+
h slash3 = str_rfind(top[0]["path"], "/")
113+
h top_name = if slash3 >= 0 { str_slice(top[0]["path"], slash3 + 1, str_len(top[0]["path"])) } else { top[0]["path"] }
114+
print(" Top attractor: " + top_name + " (score=" + to_string(top[0]["attractor_score"]) + ")")
115+
}
116+
print("")
117+
print(" Signals used:")
118+
print(" omc_attractor_density — phi-pi-fib token density (ANY language)")
119+
print(" omc_code_similarity — structural distance (OMC files)")
120+
print(" str_similarity — text distance (non-OMC files)")
121+
print(" omc_code_extract_fns — surface area mapping (OMC files)")
122+
print(" omc_code_hash — content-addressed dedup")
123+
print(" llm_call — architectural narration")
124+
print("")

examples/demos/context_compression.js

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)