Skip to content

O(k) Intelligence ​

Recompute, evaluation and provenance in this.me 4.2.1. Every example below was run with node against npm this.me 4.2.1; the comments are its real output. Source links point at tag v4.2.1.

Concept first: O(k) · me.explain(path) · Axioms. Data structures: Core.

Module (v4.2.1)Role
derivation.tsregister, invalidate, recompute, explain
evaluator.tstokenizer and RPN evaluator
core-write.tspostulate, replayMemories (L361–421)
core-read.tsreads, selectors, filters
core-snapshot.tsexportSnapshot, hydrate, importSnapshot

Incremental recompute ​

ts
import ME from "this.me";
const me = new ME();
me.finance.fuel_price(24.5);
me.fleet.trucks[1].fuel(200);
me.fleet.trucks[2].fuel(350);
me.fleet["trucks[i]"]["="]("cost", "fuel * finance.fuel_price");
me("fleet.trucks[1].cost"); // 4900
me("fleet.trucks[2].cost"); // 8575

me.finance.fuel_price(25);
me("fleet.trucks[1].cost"); // 5000
me("fleet.trucks[2].cost"); // 8750

me.fleet.trucks[3].fuel(100);
me("fleet.trucks[3].cost"); // 2500  ([i] also applies to children added later)

The write to finance.fuel_price goes through invalidateFromPaths L824–961: refSubscribers["finance.fuel_price"] names the two costs, and each is recomputed by recomputeTarget L705–710. In lazy mode (setRecomputeMode("lazy"), core-dispatch.ts L11) the write only marks them stale; ensureTargetFresh L757–812 recomputes one when it is read.

Evaluator ​

No eval, no new Function. Before anything runs, the expression must match a character whitelist, and the kernel's unsafeEval flag (kernel-state.ts L114) turns the evaluator off:

ts
// evaluator.ts L334–335 (v4.2.1)
if (!/^[A-Za-z0-9_\s+\-*/%().<>=!&|\[\]"']+$/.test(raw)) return { ok: false };
if (self.unsafeEval) return { ok: false };

Then tokenizeEvalExpression L47–151 and compileUncached L228–322 (precedence table L232) produce RPN, cached per expression up to COMPILED_EVAL_MAX (L199). Operators: + - * / %, > >= < <= == !=, && || !, parentheses.

ts
me["="]("x", "2 + 3 * 4");             // me("x") → 14
me["="]("y", "(2 + 3) * 4");           // me("y") → 20
me["="]("z", "x > 10 && y % 3 == 2");  // me("z") → true

me.profile.age(21);
me.profile["="]("adult", "age >= 18"); // me("profile.adult") → true
me.profile["="]("bad", "1 + console.log(1)");
me("profile.bad");                     // undefined

console.log is not code here; it is read as a path that does not exist:

json
{
  "path": "profile.bad",
  "derivation": {
    "expression": "1 + console.log(1)",
    "inputs": [{ "label": "console.log", "path": "console.log", "origin": "public", "masked": false, "status": "missing" }]
  },
  "meta": { "dependsOn": ["console.log"], "unresolved": { "reason": "missing-input", "inputs": ["profile.console.log"] } }
}

explain ​

explain L140–251. A secret branch (["_"]) still feeds the formula; its value is masked in the trace (L214–215).

ts
const me = new ME();
me.finance["_"]("k-2026");
me.finance.fuel_price(24.5);
me.fleet.trucks[2].fuel(350);
me.fleet.trucks[2]["="]("cost", "fuel * finance.fuel_price");
me.explain("fleet.trucks.2.cost");
json
{
  "path": "fleet.trucks.2.cost",
  "value": 8575,
  "expr": "fuel * finance.fuel_price",
  "derivation": {
    "expression": "fuel * finance.fuel_price",
    "inputs": [
      { "label": "fuel", "path": "fleet.trucks.2.fuel", "value": 350, "origin": "public", "masked": false, "status": "resolved" },
      { "label": "finance.fuel_price", "path": "finance.fuel_price", "value": "●●●●", "origin": "stealth", "masked": true, "status": "masked" }
    ]
  },
  "meta": { "dependsOn": ["fleet.trucks.2.fuel", "finance.fuel_price"], "lastComputedAt": 1792006834327 }
}

After a write, meta also carries the wave: k, recomputed, changed, sourcePath.

Cycles ​

ts
const me = new ME();
me["="]("b", "c + 1");
me["="]("c", "b + 1");
me("b"); // undefined
me("c"); // undefined
me.explain("b").meta.unresolved; // { reason: "cycle", cycle: ["b", "c"] }

Both members are committed as undefined by failCycle L712–719; nothing throws and the stack does not overflow.

Snapshots ​

ts
const snapshot = me.exportSnapshot();
Object.keys(snapshot);
// formatVersion, memories, localSecrets, localNoises, encryptedBranches,
// keySpaces, operators, identityRoot, migrationV4, migrationV4Values

const me2 = new ME();
me2.importSnapshot(snapshot);
me2("fleet.trucks.2.cost"); // 8575
me2.fleet.trucks[2].fuel(400);
me2("fleet.trucks.2.cost"); // 8575  (value restored, formula not live)

hydrate L73–111 resets derivations (L95) and replays the memories; a = memory comes back as its value. A snapshot restores state, not the derivation graph: declare formulas again after import to make them live.

Tests (v4.2.1) ​

bash
npm run test:derivations   # refs, waves, pointer invalidation
npm run test:perf-fix      # compile cache, kernel perf fixes
npm run test:contracts     # DSL contract, incl. explain masks

Core · Benchmarks · Operators · Proxy calls · me.explain(path) · O(k)

Human owns meaning. Everything else asks.