Skip to content

Commit 2ba1086

Browse files
feat: v1.3.0 stdlib + recursive self-improvement demo suite
OMC stdlib (examples/lib/): - llm.omc: ReAct agent, CoT, cot_verify, few_shot, chain, critique_revise, gen_and_test - cache.omc: memoize, memoize2, LRU cache, TTL cache, disk cache, batch_cached - graph.omc: BFS, DFS, Dijkstra, toposort, PageRank, connected_components, has_cycle - text.omc: tokenize, TF-IDF, BM25, Levenshtein, closest, chunk_fixed, chunk_sentences, ngrams - schema.omc: validate, coerce, assert_valid, schema_string/number/object/array/enum - cli.omc: ANSI colors, parse_args, progress_bar, table formatter, box drawer, confirm Recursive self-improvement demos (examples/demos/): - self_improving_agent.omc: OMC asks Claude to write OMC, tests it, repairs until passing - code_gen_loop.omc: generate → run → evaluate → improve multi-generation loop - recursive_improve.omc: meta-improver that improves itself then improves programs - auto_improve_daemon.omc: 24/7 continuous improvement daemon with quality scoring - population_evolve.omc: genetic programming with Claude as mutation operator - code_evolution_loop.omc: multi-lineage evolution + crossbreeding - substrate_rag.omc: phi-pi-fibonacci RAG with cosine similarity retrieval - benchmark_dashboard.omc: perf regression tracker with baseline comparison - mcp_tool_gen.omc: auto-generate MCP tool schemas from OMC function signatures Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ddfe462 commit 2ba1086

19 files changed

Lines changed: 4286 additions & 0 deletions
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Task 33: Native HTTP builtins — http_get, http_post, http_put, http_delete
2+
3+
## Goal
4+
Add 4 native HTTP builtins to the OMC interpreter using the already-available `ureq` crate.
5+
ureq is already a dependency (feature `native-llm`) and is available in the workspace.
6+
7+
## Working directory
8+
/home/thearchitect/OMC
9+
10+
## What already exists
11+
- `omnimcode-core/src/llm_builtins.rs` — already uses ureq for HTTP in llm_call
12+
- ureq 2.x is in Cargo.toml under `native-llm` feature
13+
- `omnimcode-core/src/interpreter.rs` — the main interpreter, ~14000+ lines
14+
15+
## Functions to add
16+
17+
### 1. http_get(url, headers?)
18+
- url: string
19+
- headers: optional dict {header_name: header_value}
20+
- returns: dict {status: int, body: string, ok: bool}
21+
22+
### 2. http_post(url, body, headers?)
23+
- url: string
24+
- body: string (raw body)
25+
- headers: optional dict
26+
- returns: dict {status: int, body: string, ok: bool}
27+
28+
### 3. http_post_json(url, data, headers?)
29+
- url: string
30+
- data: dict or array (will be json_stringify'd)
31+
- headers: optional dict
32+
- returns: dict {status: int, body: string, json: parsed_json_or_null, ok: bool}
33+
34+
### 4. http_put(url, body, headers?)
35+
- Same signature as http_post but uses PUT
36+
37+
### 5. http_delete(url, headers?)
38+
- url: string
39+
- headers: optional dict
40+
- returns: dict {status: int, body: string, ok: bool}
41+
42+
## Implementation steps
43+
44+
### Step 1: Add to llm_builtins.rs (or create http_builtins.rs)
45+
Add a new file `omnimcode-core/src/http_builtins.rs` with these functions:
46+
47+
```rust
48+
use crate::interpreter::Value;
49+
use std::collections::HashMap;
50+
use std::rc::Rc;
51+
use std::cell::RefCell;
52+
53+
pub fn http_get(args: &[Value]) -> Result<Value, String> {
54+
// args[0] = url string
55+
// args[1] = optional headers dict
56+
// Use ureq::get(url).call()
57+
// Return Value::Dict with status, body, ok
58+
}
59+
60+
pub fn http_post(args: &[Value]) -> Result<Value, String> { ... }
61+
pub fn http_post_json(args: &[Value]) -> Result<Value, String> { ... }
62+
pub fn http_put(args: &[Value]) -> Result<Value, String> { ... }
63+
pub fn http_delete(args: &[Value]) -> Result<Value, String> { ... }
64+
```
65+
66+
### Step 2: Wire into interpreter.rs
67+
68+
In the builtin match guard (around line 2219 where "llm_call" | "llm_chat" are listed), add:
69+
```
70+
| "http_get" | "http_post" | "http_post_json" | "http_put" | "http_delete"
71+
```
72+
73+
Add dispatch arms that call `crate::http_builtins::http_get(args)` etc.
74+
75+
### Step 3: Add to ALL_BUILTINS and HEAL_BUILTIN_NAMES
76+
77+
Search for where `"llm_call"` is listed in the ALL_BUILTINS array or similar, add the new names there too.
78+
79+
### Step 4: Add to docs.rs
80+
81+
Add a category "http" with doc entries for each function.
82+
83+
### Step 5: Write a test
84+
85+
Create `examples/test_http.omc`:
86+
```omc
87+
h result = http_get("https://httpbin.org/get", null)
88+
print(result["status"])
89+
print(result["ok"])
90+
91+
h post_result = http_post_json("https://httpbin.org/post", {key: "value"}, null)
92+
print(post_result["status"])
93+
```
94+
95+
## Important ureq patterns
96+
97+
```rust
98+
// GET
99+
let resp = ureq::get(&url)
100+
.call()
101+
.map_err(|e| format!("http_get failed: {e}"))?;
102+
let status = resp.status();
103+
let body = resp.into_string().map_err(|e| format!("read body: {e}"))?;
104+
105+
// POST with JSON body
106+
let resp = ureq::post(&url)
107+
.set("Content-Type", "application/json")
108+
.send_string(&json_body)
109+
.map_err(|e| format!("http_post failed: {e}"))?;
110+
111+
// Add custom headers
112+
let mut req = ureq::get(&url);
113+
for (k, v) in &headers {
114+
req = req.set(k, v);
115+
}
116+
```
117+
118+
## Value dict construction pattern (from existing llm_builtins.rs)
119+
120+
```rust
121+
fn make_response_dict(status: u16, body: String) -> Value {
122+
let mut map = HashMap::new();
123+
map.insert("status".to_string(), Value::Int(status as i64));
124+
map.insert("body".to_string(), Value::Str(body));
125+
map.insert("ok".to_string(), Value::Bool(status >= 200 && status < 300));
126+
Value::Dict(Rc::new(RefCell::new(map)))
127+
}
128+
```
129+
130+
## After implementing
131+
132+
Run:
133+
```bash
134+
cd /home/thearchitect/OMC
135+
cargo build -p omnimcode-core 2>&1 | tail -20
136+
```
137+
138+
Fix any compile errors. When it builds clean, commit:
139+
```bash
140+
git add omnimcode-core/src/http_builtins.rs omnimcode-core/src/interpreter.rs omnimcode-core/src/docs.rs omnimcode-core/src/lib.rs examples/test_http.omc
141+
git commit -m "feat: http_get + http_post + http_post_json + http_put + http_delete native HTTP builtins"
142+
```
143+
144+
## DO NOT
145+
- Do not use async/tokio — ureq is synchronous
146+
- Do not change Cargo.toml (ureq is already there)
147+
- Do not launch sub-agents
148+
- Do not modify any other files beyond what's listed above
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Task 34: Introspection builtins — get_scope_vars, list_defined_fns, fn_arity, fn_source
2+
3+
## Goal
4+
Add 4 runtime introspection builtins to the OMC interpreter.
5+
These let OMC programs inspect themselves at runtime — critical for self-improvement and meta-programming.
6+
7+
## Working directory
8+
/home/thearchitect/OMC
9+
10+
## Functions to add
11+
12+
### 1. get_scope_vars() → dict
13+
Returns all currently-defined variables in scope as a dict {name: value}.
14+
Useful for debugging and inspection.
15+
16+
### 2. list_defined_fns() → array of strings
17+
Returns all currently-defined function names as an array.
18+
Example: ["fib", "is_palindrome", "my_fn"]
19+
20+
### 3. fn_arity(fn_name) → int or null
21+
Given a function name string, returns the number of parameters.
22+
Returns null if the function doesn't exist.
23+
Example: fn_arity("fib") → 1 (because fn fib(n))
24+
25+
### 4. fn_source(fn_name) → string or null
26+
Given a function name string, returns the source-reconstructed OMC code for that function.
27+
Reconstructs from the AST — "fn name(params) { ... }"
28+
Returns null if the function doesn't exist.
29+
30+
## Where to make changes
31+
32+
### interpreter.rs
33+
The interpreter has an `env` / environment/scope structure. You need to:
34+
35+
1. Find where variables are stored (likely a HashMap<String, Value> or similar)
36+
2. Find where functions are stored (likely a separate map of function definitions)
37+
38+
Look for patterns like:
39+
- `self.env` or `env` HashMap
40+
- `self.functions` or `module.functions`
41+
- `FunctionDef`, `CompiledFunction`, or `UserFunction` variants
42+
43+
The interpreter is large (~14000 lines). Search for:
44+
- `"fn_arity"` (may not exist yet)
45+
- `BuiltinFunction` or `Builtin` match arms
46+
- Where `"llm_call"` is dispatched (near line 2219)
47+
48+
### Implementation approach
49+
50+
For `get_scope_vars()`:
51+
- The interpreter likely has access to the current environment frame
52+
- Return a dict copy of all bindings visible in the current scope
53+
- Filter out function objects (only return data values)
54+
55+
For `list_defined_fns()`:
56+
- Look at where user-defined functions are stored
57+
- Return their names as an array of strings
58+
59+
For `fn_arity(name)`:
60+
- Find the function definition by name
61+
- Return the parameter count
62+
63+
For `fn_source(name)`:
64+
- Find the function definition
65+
- Reconstruct "fn name(p1, p2) { <body as OMC string> }"
66+
- You can do a simple AST-to-string reconstruction for the signature,
67+
and use "{ <native body> }" for the body if full reconstruction is too complex
68+
- At minimum: return "fn name(p1, p2) { ... }"
69+
70+
## Wire into interpreter.rs
71+
72+
In the builtin match guard, add:
73+
```
74+
| "get_scope_vars" | "list_defined_fns" | "fn_arity" | "fn_source"
75+
```
76+
77+
Add dispatch arms.
78+
79+
## Add to ALL_BUILTINS and docs
80+
81+
Add these 4 names to the ALL_BUILTINS list and add doc entries in the "meta" or "introspection" category.
82+
83+
## Test file
84+
85+
Create `examples/test_introspection.omc`:
86+
```omc
87+
fn my_func(a, b, c) { return a + b + c }
88+
fn other(x) { return x * 2 }
89+
90+
h fns = list_defined_fns()
91+
print(fns)
92+
93+
h arity = fn_arity("my_func")
94+
print(arity)
95+
96+
h src = fn_source("my_func")
97+
print(src)
98+
99+
h vars = get_scope_vars()
100+
print(dict_keys(vars))
101+
```
102+
103+
Expected output:
104+
- fns should contain "my_func" and "other"
105+
- arity should be 3
106+
- src should show the function signature
107+
- vars should show defined variables
108+
109+
## Build and commit
110+
111+
```bash
112+
cd /home/thearchitect/OMC
113+
cargo build -p omnimcode-core 2>&1 | tail -20
114+
# fix errors
115+
git add omnimcode-core/src/interpreter.rs omnimcode-core/src/docs.rs examples/test_introspection.omc
116+
git commit -m "feat: get_scope_vars + list_defined_fns + fn_arity + fn_source introspection builtins"
117+
```
118+
119+
## DO NOT
120+
- Do not launch sub-agents
121+
- Do not break existing tests
122+
- Keep changes focused to interpreter.rs and docs.rs only

0 commit comments

Comments
 (0)