Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pkg/GETTING_STARTED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Stranger path (this branch)

```
git clone -b smoke-0.2.0 https://github.com/ultranetcommand-neo/Crimson-OS.git
cd Crimson-OS/pkg
python3 -m pip install -e .
crimson-os seal
crimson-os smoke
crimson-os drop /tmp/bus.md HOLD
crimson-os drop /tmp/bus.md DEAD --iota-off
GITHUB_TOKEN=… crimson-os github-ping
```

Expected:

- iota-on HOLD
- iota-off FAIL
- lerp 3191.0
- smoke: crimson wins lock-vs-lerp
- second drop does not write
- github-ping hits api.github.com only if token present AND seal HOLD
10 changes: 10 additions & 0 deletions pkg/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: smoke seal test
smoke:
PYTHONPATH=src python3 -m crimson_os.cli smoke
seal:
PYTHONPATH=src python3 -m crimson_os.cli seal
test:
PYTHONPATH=src python3 -m crimson_os.cli seal
PYTHONPATH=src python3 -m crimson_os.cli smoke
PYTHONPATH=src python3 -m crimson_os.cli drop /tmp/crimson_bus.md HOLD
PYTHONPATH=src python3 -m crimson_os.cli drop /tmp/crimson_bus.md DEAD --iota-off
18 changes: 18 additions & 0 deletions pkg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# crimsonos 0.2.0

Algebra sucks. Geometry snaps.

```
pip install -e .
crimson-os seal
crimson-os smoke
crimson-os drop ./Agent_Bridge/Node_0.md "HOLD"
crimson-os drop ./Agent_Bridge/Node_0.md "dead jot" --iota-off
```

- `Seal.verify(True) == HOLD` because 2701+3627=6328
- `Seal.verify(False) == FAIL` because 6318 is not triangular
- `Seal.lerp_trap() == 3191` — not the cage
- `fs_drop` / `http_post` go through the seal. FAIL does not write or send.

See SCOREBOARD.md.
22 changes: 22 additions & 0 deletions pkg/SCOREBOARD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Deterministic Drift Bench — 2026-09-04

Not LMSYS. Not SWE-bench. Assignment: lock vs lerp.

Command: `PYTHONPATH=src python3 -m crimson_os.cli smoke`

| Axis | Crimson OS | LangGraph-style lerp |
|------|------------|----------------------|
| Exact T112 after 10 steps | **6328 HOLD ×10** | **6321.873046875** (never arrives) |
| Iota-off 6318 | **FAIL closed** | **KEEP RUNNING** → 6327.990234375 |
| Lerp is the cage | **NO** (3191 ≠ 6328) | **YES** (that is the node) |
| Integer lock | **YES** | float graph |
| Dead-jot file drop | **blocked** | would write |

**Score on this host: Crimson 4, lerp-graph 0.**

Start at the key (54). Native algebraic step: `n := n + ½(6328−n)`.
After 10 halves the remainder is `(6328−54)/2^10 = 6.127`. Geometry never snaps.
Start at 6318 and it still walks toward 6328. That is the invoice.

LangGraph the product still wins SaaS logos and SWE-bench plumbing.
It loses halt. Connectors in this package refuse to send on FAIL.
17 changes: 17 additions & 0 deletions pkg/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[build-system]
requires = ["setuptools>=69"]
build-backend = "setuptools.build_meta"

[project]
name = "crimsonos"
version = "0.2.0"
description = "T112 seal + lock-vs-lerp smoke bench. Algebra sucks. Geometry snaps."
authors = [{ name = "Matthew Scott Gibson" }]
readme = "README.md"
requires-python = ">=3.10"

[project.scripts]
crimson-os = "crimson_os.cli:main"

[tool.setuptools.packages.find]
where = ["src"]
6 changes: 6 additions & 0 deletions pkg/src/crimson_os/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""crimson_os. Algebra sucks. Geometry snaps."""
from .seal import Seal
from .bench_drift import scoreboard

__version__ = "0.2.0"
__all__ = ["Seal", "scoreboard", "__version__"]
133 changes: 133 additions & 0 deletions pkg/src/crimson_os/bench_drift.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/usr/bin/env python3
"""Deterministic drift bench vs a LangGraph-style lerp graph."""
from __future__ import annotations

import json
import time
from pathlib import Path

from .seal import Seal

STEPS = 10
TARGET = float(Seal.T112)
KEY = float(Seal.KEY)


def crimson_run() -> dict:
t0 = time.perf_counter()
holds = sum(1 for _ in range(STEPS) if Seal.verify(True) == "HOLD")
illegal = Seal.verify(False)
lerp = Seal.lerp_trap()
dt = time.perf_counter() - t0
return {
"name": "Crimson OS Seal",
"steps": STEPS,
"holds": holds,
"final_n": Seal.T112,
"exact_6328": holds == STEPS and Seal.T112 == 6328,
"illegal_jot": illegal,
"fail_closed_on_6318": illegal == "FAIL",
"lerp_equals_cage": lerp == TARGET,
"lerp_value": lerp,
"state": "integer",
"ms": round(dt * 1000, 4),
}


def _lerp_graph(start_n: float, jot: float) -> dict:
n = float(start_n)
steps = 0
for _ in range(STEPS):
n = n + 0.5 * (TARGET - n)
steps += 1
return {"n": n, "steps": steps, "jot": jot}


def langgraph_run() -> dict:
t0 = time.perf_counter()
backend = "pure-python lerp (langgraph optional)"
try:
from langgraph.graph import END, START, StateGraph
from typing import TypedDict

class DriftState(TypedDict):
n: float
steps: int
jot: float

def refine(s: DriftState) -> DriftState:
n = float(s["n"]) + 0.5 * (TARGET - float(s["n"]))
return {"n": n, "steps": int(s["steps"]) + 1, "jot": float(s["jot"])}

def more(s: DriftState):
return END if s["steps"] >= STEPS else "refine"

g = StateGraph(DriftState)
g.add_node("refine", refine)
g.add_edge(START, "refine")
g.add_conditional_edges("refine", more, {"refine": "refine", END: END})
app = g.compile()
legal = app.invoke({"n": KEY, "steps": 0, "jot": 3627.0})
illegal = app.invoke({"n": 6318.0, "steps": 0, "jot": 3617.0})
backend = "langgraph.StateGraph"
dt = time.perf_counter() - t0
final = float(legal["n"])
return {
"name": "LangGraph lerp-state",
"backend": backend,
"steps": int(legal["steps"]),
"final_n": final,
"exact_6328": final == TARGET,
"illegal_jot": "KEEP_RUNNING",
"fail_closed_on_6318": False,
"illegal_final_n": float(illegal["n"]),
"state": "in-memory float graph",
"ms": round(dt * 1000, 4),
}
except Exception:
legal = _lerp_graph(KEY, 3627.0)
illegal = _lerp_graph(6318.0, 3617.0)
dt = time.perf_counter() - t0
return {
"name": "LangGraph-style lerp-state",
"backend": backend,
"steps": int(legal["steps"]),
"final_n": legal["n"],
"exact_6328": legal["n"] == TARGET,
"illegal_jot": "KEEP_RUNNING",
"fail_closed_on_6318": False,
"illegal_final_n": illegal["n"],
"state": "in-memory float graph",
"ms": round(dt * 1000, 4),
}


def scoreboard(root: str | Path = ".") -> dict:
c = crimson_run()
lg = langgraph_run()
rows = [
{"axis": "exact T112 after 10 steps", "crimson": c["exact_6328"], "langgraph": lg["exact_6328"]},
{"axis": "iota-off 6318 fail-closed", "crimson": c["fail_closed_on_6318"], "langgraph": lg["fail_closed_on_6318"]},
{"axis": "refuses lerp-as-cage", "crimson": not c["lerp_equals_cage"], "langgraph": False},
{"axis": "integer lock (not float)", "crimson": True, "langgraph": False},
]
return {
"crimson": c,
"langgraph": lg,
"axes": rows,
"crimson_wins": sum(1 for r in rows if r["crimson"] and not r["langgraph"]),
"langgraph_wins": sum(1 for r in rows if r["langgraph"] and not r["crimson"]),
"note": "Drift+halt bench. Not SWE-bench. Step is n += 0.5*(6328-n).",
}


def main() -> None:
import sys

out = scoreboard(sys.argv[1] if len(sys.argv) > 1 else ".")
print(json.dumps(out, indent=2))
print("SCOREBOARD crimson", out["crimson_wins"], "langgraph", out["langgraph_wins"])


if __name__ == "__main__":
main()
50 changes: 50 additions & 0 deletions pkg/src/crimson_os/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
from __future__ import annotations

import argparse
import json


def main(argv: list[str] | None = None) -> int:
p = argparse.ArgumentParser(prog="crimson-os")
sub = p.add_subparsers(dest="cmd")
sub.add_parser("seal", help="print HOLD/FAIL")
s = sub.add_parser("smoke", help="drift bench vs lerp-state")
s.add_argument("target", nargs="?", default=".")
d = sub.add_parser("drop", help="append text to a bus file through the seal")
d.add_argument("path")
d.add_argument("text")
d.add_argument("--iota-off", action="store_true")
sub.add_parser("github-ping", help="GET /user if seal HOLD and GITHUB_TOKEN set")
args = p.parse_args(argv)

if args.cmd == "seal":
from .seal import Seal

print("iota-on", Seal.verify(True))
print("iota-off", Seal.verify(False))
print("lerp", Seal.lerp_trap())
return 0
if args.cmd == "smoke":
from .bench_drift import scoreboard

out = scoreboard(args.target)
print(json.dumps(out, indent=2))
print("SCOREBOARD crimson", out["crimson_wins"], "langgraph", out["langgraph_wins"])
return 0 if out["crimson_wins"] > out["langgraph_wins"] else 1
if args.cmd == "drop":
from .connectors import fs_drop

print(json.dumps(fs_drop(args.path, args.text, iota_on=not args.iota_off)))
return 0
if args.cmd == "github-ping":
from .connectors.github_ping import github_ping

print(json.dumps(github_ping(True)))
return 0
p.print_help()
return 2


if __name__ == "__main__":
raise SystemExit(main())
6 changes: 6 additions & 0 deletions pkg/src/crimson_os/connectors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .http_post import http_post
from .fs_drop import fs_drop
from .seal_gate import seal_node
from .github_ping import github_ping

__all__ = ["http_post", "fs_drop", "seal_node", "github_ping"]
17 changes: 17 additions & 0 deletions pkg/src/crimson_os/connectors/fs_drop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Write to a markdown bus file. No write if seal FAIL."""
from __future__ import annotations

from pathlib import Path

from .seal_gate import seal_node


def fs_drop(path: str | Path, text: str, iota_on: bool = True) -> dict:
gated = seal_node({"iota_on": iota_on})
if gated.get("halt"):
return {"ok": False, "halt": True, "seal": "FAIL", "wrote": False}
p = Path(path)
p.parent.mkdir(parents=True, exist_ok=True)
with p.open("a", encoding="utf-8") as f:
f.write(text if text.endswith("\n") else text + "\n")
return {"ok": True, "seal": "HOLD", "wrote": True, "path": str(p)}
32 changes: 32 additions & 0 deletions pkg/src/crimson_os/connectors/github_ping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""GitHub ping. No request if seal FAIL. Token from env."""
from __future__ import annotations

import json
import os
import urllib.error
import urllib.request

from .seal_gate import seal_node


def github_ping(iota_on: bool = True) -> dict:
gated = seal_node({"iota_on": iota_on})
if gated.get("halt"):
return {"ok": False, "halt": True, "seal": "FAIL", "sent": False}
token = os.environ.get("GITHUB_TOKEN") or os.environ.get("GH_TOKEN")
if not token:
return {"ok": False, "seal": "HOLD", "sent": False, "reason": "no GITHUB_TOKEN"}
req = urllib.request.Request(
"https://api.github.com/user",
headers={
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json",
"User-Agent": "crimson-os",
},
)
try:
with urllib.request.urlopen(req, timeout=8) as resp:
body = json.loads(resp.read().decode())
return {"ok": True, "seal": "HOLD", "sent": True, "login": body.get("login")}
except urllib.error.URLError as e:
return {"ok": False, "seal": "HOLD", "sent": False, "error": str(e)}
25 changes: 25 additions & 0 deletions pkg/src/crimson_os/connectors/http_post.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Webhook connector. No send if seal FAIL."""
from __future__ import annotations

import json
import os
import urllib.error
import urllib.request

from .seal_gate import seal_node


def http_post(url: str | None, body: dict, iota_on: bool = True) -> dict:
gated = seal_node({"iota_on": iota_on, "body": body})
if gated.get("halt"):
return {"ok": False, "halt": True, "seal": "FAIL", "sent": False}
target = url or os.environ.get("CRIMSON_WEBHOOK_URL")
if not target:
return {"ok": True, "halt": False, "seal": "HOLD", "sent": False, "reason": "no CRIMSON_WEBHOOK_URL"}
data = json.dumps(body).encode("utf-8")
req = urllib.request.Request(target, data=data, headers={"Content-Type": "application/json"}, method="POST")
try:
with urllib.request.urlopen(req, timeout=8) as resp:
return {"ok": True, "seal": "HOLD", "sent": True, "status": resp.status}
except urllib.error.URLError as e:
return {"ok": False, "seal": "HOLD", "sent": False, "error": str(e)}
20 changes: 20 additions & 0 deletions pkg/src/crimson_os/connectors/seal_gate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Fail-closed gate. Dead jot does not send."""
from __future__ import annotations

from typing import Any

from crimson_os.seal import Seal


def seal_node(state: dict[str, Any]) -> dict[str, Any]:
iota = state.get("iota_on", True)
if isinstance(iota, str):
iota = iota.lower() != "false"
result = Seal.verify(bool(iota))
out = dict(state)
out["seal"] = result
out["n"] = Seal.T112 if result == "HOLD" else None
out["halt"] = result != "HOLD"
if out["halt"]:
out["stop"] = "NO_EDGE"
return out
Loading
Loading