Skip to content

Commit 97c78b0

Browse files
llm_workflow: high-level bundles for LLM sessions
New module omnimcode-core/src/llm_workflow.rs and 7 builtins giving an LLM single-call access to common "I need a summary" operations: omc_cheatsheet(topic) -> string (markdown by category) omc_unique_overview() -> string (OMC-only surface) omc_python_translation() -> string (Python ↔ OMC table) omc_builtin_index_markdown() -> string (full index by category) omc_bootstrap_pack() -> string (~20KB session-start doc) omc_change_report(old, new) -> dict (diff + metrics + actions) omc_id(code) -> string ("omcid-<fp>-<hash>") The bootstrap_pack composes index + unique-overview + python- translation + 4 cheatsheets (substrate / autograd / code_intel / tokenizer). An LLM loads it once at session start and has enough knowledge to write idiomatic OMC without further round-trips. omc_id gives a stable string identifier for code regions — "omcid-<substrate-fingerprint>-<canonical-hash>". Two alpha- equivalent programs get the same id; the LLM's working-memory key for "this is the same function I edited 10 messages ago". Tests: 14 OMC + 6 Rust unit covering cheatsheet topics, unique overview content, python-translation entries, index categories, bootstrap-pack size, change-report dict keys + modification detection, omc_id stability + format + change. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e57dae9 commit 97c78b0

6 files changed

Lines changed: 527 additions & 2 deletions

File tree

OMC_REFERENCE.md

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
Auto-generated from `omnimcode-core/src/docs.rs`. Run `omc --gen-docs > OMC_REFERENCE.md` to regenerate.
44

5-
**Total documented builtins**: 612
5+
**Total documented builtins**: 619
66

7-
**OMC-unique**: 61 (no direct Python/NumPy equivalent — these are why you reach for OMC over numpy)
7+
**OMC-unique**: 63 (no direct Python/NumPy equivalent — these are why you reach for OMC over numpy)
88

99
---
1010

@@ -26,6 +26,7 @@ Auto-generated from `omnimcode-core/src/docs.rs`. Run `omc --gen-docs > OMC_REFE
2626
- [introspection](#introspection) (22 builtins)
2727
- [tokenizer](#tokenizer) (16 builtins)
2828
- [code_intel](#code_intel) (16 builtins)
29+
- [llm_workflow](#llm_workflow) (7 builtins)
2930
- [math](#math) (82 builtins)
3031
- [dicts](#dicts) (31 builtins)
3132
- [test_runner](#test_runner) (8 builtins)
@@ -4859,6 +4860,80 @@ omc_code_metrics(src) // all stats at once
48594860

48604861
---
48614862

4863+
## llm_workflow
4864+
4865+
### `omc_cheatsheet`
4866+
4867+
**Signature**: `(topic: string) -> string`
4868+
4869+
Markdown cheatsheet for a category (substrate, autograd, tokenizer, ml_kernels, ...). Bundles ~10 builtins with examples.
4870+
4871+
```omc
4872+
omc_cheatsheet("substrate") // markdown
4873+
```
4874+
4875+
### `omc_unique_overview` 🔱 *OMC-unique*
4876+
4877+
**Signature**: `() -> string`
4878+
4879+
Markdown list of every OMC-unique builtin, grouped by category.
4880+
4881+
```omc
4882+
omc_unique_overview()
4883+
```
4884+
4885+
### `omc_python_translation`
4886+
4887+
**Signature**: `() -> string`
4888+
4889+
Markdown table: Python op → OMC equivalent. Bootstrap reference.
4890+
4891+
```omc
4892+
omc_python_translation()
4893+
```
4894+
4895+
### `omc_builtin_index_markdown`
4896+
4897+
**Signature**: `() -> string`
4898+
4899+
Categorized Markdown index of all documented builtins.
4900+
4901+
```omc
4902+
omc_builtin_index_markdown()
4903+
```
4904+
4905+
### `omc_bootstrap_pack`
4906+
4907+
**Signature**: `() -> string`
4908+
4909+
Index + unique-overview + python-translation + 4 cheatsheets. Single ~20KB doc for session-start LLM bootstrapping.
4910+
4911+
```omc
4912+
omc_bootstrap_pack()
4913+
```
4914+
4915+
### `omc_change_report`
4916+
4917+
**Signature**: `(old, new) -> dict`
4918+
4919+
Diff + metrics + suggested next-actions in one dict.
4920+
4921+
```omc
4922+
omc_change_report(old, new)
4923+
```
4924+
4925+
### `omc_id` 🔱 *OMC-unique*
4926+
4927+
**Signature**: `(code: string) -> string`
4928+
4929+
Canonical OMC ID: 'omcid-<fp>-<short>'. Stable under cosmetic edits. Session-memory key for code.
4930+
4931+
```omc
4932+
omc_id(src) // "omcid-12345-abcd"
4933+
```
4934+
4935+
---
4936+
48624937
## math
48634938

48644939
### `abs`
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# LLM workflow primitives.
2+
3+
fn assert_eq(actual, expected, msg) {
4+
if actual != expected {
5+
test_record_failure(msg + ": expected " + to_string(expected) + " got " + to_string(actual));
6+
}
7+
}
8+
9+
fn assert_true(cond, msg) { if !cond { test_record_failure(msg); } }
10+
11+
# Cheatsheets
12+
fn test_cheatsheet_substrate_has_entries() {
13+
h s = omc_cheatsheet("substrate");
14+
assert_true(str_len(s) > 100, "non-trivial cheatsheet");
15+
}
16+
17+
fn test_cheatsheet_autograd() {
18+
h s = omc_cheatsheet("autograd");
19+
assert_true(str_len(s) > 100, "autograd cheatsheet non-empty");
20+
}
21+
22+
fn test_cheatsheet_unknown_lists_topics() {
23+
h s = omc_cheatsheet("nope_no_such_topic");
24+
assert_true(re_match("Available topics", s) == 1, "lists topics on miss");
25+
}
26+
27+
# Unique overview
28+
fn test_unique_overview_nonempty() {
29+
h s = omc_unique_overview();
30+
assert_true(str_len(s) > 100, "overview is substantive");
31+
}
32+
33+
fn test_unique_overview_mentions_attractor() {
34+
h s = omc_unique_overview();
35+
assert_true(re_match("attractor", s) == 1, "mentions attractor");
36+
}
37+
38+
# Python translation
39+
fn test_python_translation_mentions_arr_get() {
40+
h s = omc_python_translation();
41+
assert_true(re_match("arr_get", s) == 1, "has arr_get mapping");
42+
}
43+
44+
fn test_python_translation_mentions_softmax() {
45+
h s = omc_python_translation();
46+
assert_true(re_match("softmax", s) == 1, "has softmax mapping");
47+
}
48+
49+
# Builtin index
50+
fn test_builtin_index_lists_categories() {
51+
h s = omc_builtin_index_markdown();
52+
assert_true(re_match("## arrays", s) == 1, "has arrays section");
53+
assert_true(re_match("## substrate", s) == 1, "has substrate section");
54+
}
55+
56+
# Bootstrap pack — large composite
57+
fn test_bootstrap_pack_substantive() {
58+
h s = omc_bootstrap_pack();
59+
assert_true(str_len(s) > 5000, "bootstrap pack substantial");
60+
}
61+
62+
# Change report
63+
fn test_change_report_keys() {
64+
h r = omc_change_report(
65+
"fn f(x) { return x; }",
66+
"fn f(x) { return x + 1; } fn g() { return 0; }"
67+
);
68+
assert_true(dict_has(r, "added"), "has added");
69+
assert_true(dict_has(r, "removed"), "has removed");
70+
assert_true(dict_has(r, "modified"), "has modified");
71+
assert_true(dict_has(r, "suggested_action"), "has suggested action");
72+
}
73+
74+
fn test_change_report_detects_modification() {
75+
h r = omc_change_report(
76+
"fn f(x) { return x; }",
77+
"fn f(x) { return x + 1; }"
78+
);
79+
assert_true(re_match("f", dict_get(r, "modified")) == 1, "f is in modified");
80+
}
81+
82+
# omc_id stability
83+
fn test_omc_id_stable() {
84+
h a = omc_id("fn f(x) { return x; }");
85+
h b = omc_id("fn f(y) { return y; }");
86+
assert_eq(a, b, "stable under alpha-rename");
87+
}
88+
89+
fn test_omc_id_format() {
90+
h a = omc_id("h x = 1;");
91+
assert_true(re_match("^omcid-", a) == 1, "starts with omcid-");
92+
}
93+
94+
fn test_omc_id_changes_on_real_diff() {
95+
h a = omc_id("fn f(x) { return x; }");
96+
h b = omc_id("fn f(x) { return x + 1; }");
97+
assert_true(a != b, "different code → different id");
98+
}

omnimcode-core/src/docs.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,56 @@ pub const BUILTINS: &[BuiltinDoc] = &[
10731073
example: "omc_code_metrics(src) // all stats at once",
10741074
unique_to_omc: false,
10751075
},
1076+
// ---- LLM workflow bundles ----
1077+
BuiltinDoc {
1078+
name: "omc_cheatsheet", category: "llm_workflow",
1079+
signature: "(topic: string) -> string",
1080+
description: "Markdown cheatsheet for a category (substrate, autograd, tokenizer, ml_kernels, ...). Bundles ~10 builtins with examples.",
1081+
example: "omc_cheatsheet(\"substrate\") // markdown",
1082+
unique_to_omc: false,
1083+
},
1084+
BuiltinDoc {
1085+
name: "omc_unique_overview", category: "llm_workflow",
1086+
signature: "() -> string",
1087+
description: "Markdown list of every OMC-unique builtin, grouped by category.",
1088+
example: "omc_unique_overview()",
1089+
unique_to_omc: true,
1090+
},
1091+
BuiltinDoc {
1092+
name: "omc_python_translation", category: "llm_workflow",
1093+
signature: "() -> string",
1094+
description: "Markdown table: Python op → OMC equivalent. Bootstrap reference.",
1095+
example: "omc_python_translation()",
1096+
unique_to_omc: false,
1097+
},
1098+
BuiltinDoc {
1099+
name: "omc_builtin_index_markdown", category: "llm_workflow",
1100+
signature: "() -> string",
1101+
description: "Categorized Markdown index of all documented builtins.",
1102+
example: "omc_builtin_index_markdown()",
1103+
unique_to_omc: false,
1104+
},
1105+
BuiltinDoc {
1106+
name: "omc_bootstrap_pack", category: "llm_workflow",
1107+
signature: "() -> string",
1108+
description: "Index + unique-overview + python-translation + 4 cheatsheets. Single ~20KB doc for session-start LLM bootstrapping.",
1109+
example: "omc_bootstrap_pack()",
1110+
unique_to_omc: false,
1111+
},
1112+
BuiltinDoc {
1113+
name: "omc_change_report", category: "llm_workflow",
1114+
signature: "(old, new) -> dict",
1115+
description: "Diff + metrics + suggested next-actions in one dict.",
1116+
example: "omc_change_report(old, new)",
1117+
unique_to_omc: false,
1118+
},
1119+
BuiltinDoc {
1120+
name: "omc_id", category: "llm_workflow",
1121+
signature: "(code: string) -> string",
1122+
description: "Canonical OMC ID: 'omcid-<fp>-<short>'. Stable under cosmetic edits. Session-memory key for code.",
1123+
example: "omc_id(src) // \"omcid-12345-abcd\"",
1124+
unique_to_omc: true,
1125+
},
10761126
// ---- Auto-generated docs for previously-undocumented builtins ----
10771127
// Each entry covers one runtime builtin that lacked introspection.
10781128
// Stubs are conservative — refine as you learn the actual signatures.

omnimcode-core/src/interpreter.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7705,6 +7705,52 @@ impl Interpreter {
77057705
.collect();
77067706
Ok(Value::Array(HArray::from_vec(out)))
77077707
}
7708+
// ---- LLM workflow primitives (single-call bundles) ----
7709+
"omc_cheatsheet" => {
7710+
if args.is_empty() {
7711+
return Err("omc_cheatsheet requires (topic: string)".to_string());
7712+
}
7713+
let topic = self.eval_expr(&args[0])?.to_display_string();
7714+
Ok(Value::String(crate::llm_workflow::cheatsheet(&topic)))
7715+
}
7716+
"omc_unique_overview" => {
7717+
Ok(Value::String(crate::llm_workflow::unique_overview()))
7718+
}
7719+
"omc_python_translation" => {
7720+
Ok(Value::String(crate::llm_workflow::python_translation()))
7721+
}
7722+
"omc_builtin_index_markdown" => {
7723+
Ok(Value::String(crate::llm_workflow::builtin_index_markdown()))
7724+
}
7725+
"omc_bootstrap_pack" => {
7726+
Ok(Value::String(crate::llm_workflow::bootstrap_pack()))
7727+
}
7728+
"omc_change_report" => {
7729+
if args.len() < 2 {
7730+
return Err("omc_change_report requires (old, new)".to_string());
7731+
}
7732+
let a = self.eval_expr(&args[0])?.to_display_string();
7733+
let b = self.eval_expr(&args[1])?.to_display_string();
7734+
let r = crate::llm_workflow::change_report(&a, &b)
7735+
.map_err(|e| format!("omc_change_report: {}", e))?;
7736+
let mut map = std::collections::BTreeMap::new();
7737+
for (k, v) in r {
7738+
map.insert(k, Value::String(v));
7739+
}
7740+
Ok(Value::dict_from(map))
7741+
}
7742+
"omc_id" => {
7743+
// Canonical OMC ID: "omcid-<fp>-<short_hash>" — stable
7744+
// under cosmetic edits. The session-memory key for code.
7745+
if args.is_empty() {
7746+
return Err("omc_id requires (code)".to_string());
7747+
}
7748+
let code = self.eval_expr(&args[0])?.to_display_string();
7749+
match crate::llm_workflow::omc_id(&code) {
7750+
Ok(id) => Ok(Value::String(id)),
7751+
Err(e) => Err(format!("omc_id: {}", e)),
7752+
}
7753+
}
77087754
"omc_code_diff" => {
77097755
// Structural diff: returns {added, removed, modified, unchanged}.
77107756
// Compared after canonicalization so renames don't show.

omnimcode-core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod errors;
1010
pub mod tokenizer;
1111
pub mod canonical;
1212
pub mod code_intel;
13+
pub mod llm_workflow;
1314
pub mod runtime;
1415
pub mod circuits; // Genetic logic circuits
1516
pub mod evolution; // Genetic operators

0 commit comments

Comments
 (0)