--- language: - en tags: - code - program-synthesis - multi-agent-systems - software-engineering - static-analysis - testing - formal-verification - python pretty_name: "LingoLOGOS codex-python: a Python programming layer over the codex kernel" size_categories: - n<1K --- # LingoLOGOS codex-python topology An external Python programming package and six-node topology built on top of the LingoLOGOS `codex` kernel, a kernel this folder neither modifies nor carries. This dataset is that folder published as it stands: the package under `lgpython/`, the six node folders with their grammar, ontology and seed envelope, the one executable the six roles share, the two fixtures under `fixtures/` (a small package, and the pattern laboratory the catalog is measured on), the generated cases under `patterns/`, the tests, the gate runner and the publisher, and this card in place of the folder README. The kernel is a separate dataset at https://huggingface.co/datasets/tailot/lingologos-codex, and the section "What this bundle needs from the codex kernel" below says how the two find each other. It provides everything needed to inspect, edit, test, and transactionally commit changes in a Python repository through the `codex` assurance rules (`VERIFIED`, `SINGLE_PROVER`, `UNKNOWN`). ``` python -B tools/run_gates.py GATES: CONFIRMED (9 gates: 9 CONFIRMED, 0 REJECTED, 0 ABSTAIN) ``` The gate runner is where this bundle states its numbers out loud: 9 gates, 75 tests across 9 files, 18 files under `nodes/`, and a kernel it does not carry. `tools/publish_dataset.py` re-derives every one of those numbers from the tree it is standing in and stops the upload when the card and the code beside it disagree. ## Contents - `lgpython/_codex_bridge.py`: finds the kernel without copying it: an already importable `lgcodex`, then `LGCODEX_ROOT`, then a sibling `codex/` or `datasets/codex/` among the ancestors. - `lgpython/adapter.py`: `PythonLanguageAdapter` and `StrictPythonLanguageAdapter` implementing the five-method `lgcodex.adapter_contract.LanguageAdapter` contract. - `lgpython/ast_graph.py`: AST symbol, method, inheritance, relative/absolute import, and call graph extraction (`discover_python_files`, `extract_python_graph`). - `lgpython/test_selector.py`: import-aware Python test selection (`select_python_tests`). - `lgpython/gates.py`: bytecode-free `ast.parse` + in-memory `compile` gate, optional static checkers (`mypy`, `ruff`, `pyright`, `flake8`) that return `ABSTAIN` when missing, and `pytest` / `unittest` test runner with failed-target parsing. - `lgpython/rules.py`: five shape rules over a named function. Each rule reads the function through its syntax tree, refuses with a named reason code when the shape is not the one it claims, and returns the edit texts when it is (`RULES`, `RULE_IDS`, `open_target`). - `lgpython/patterns.py`: the catalog above the rules. A card states the shape it claims, why that shape is worth changing, what must hold before the rule runs, what test locks the change, and the reason codes it answers with when it refuses (`PATTERNS`, `pattern_card`, `scan_pattern`, `plan_pattern`). - `lgpython/session.py`: `PythonWorkspaceSession` for safe staged verification and atomic disk commits via `lgcodex.fsadapter` (`verify`, `edit_file`, `create_file`, `delete_file`, `apply_pattern`, `run_retry_loop`, and `run_topology_subprocesses`). - `lgpython/cli.py`: `lgpython` CLI (`verify`, `edit`, `create`, `symbols`, `select-tests`, `patterns list|show|scan|apply`, `check-adapter`). - `fixtures/pattern_lab/`: a small package with one function planted in the shape of each card and one planted to be refused, used by the tests and by the coverage counts. - `patterns/pattern_cases.jsonl`, `patterns/coverage.json`: the generated case corpus (one accepted and one refused case per card) and the coverage statement, whose denominator is that fixture. - `topology.json`, `agents/python_agent.py`, `nodes//`: external six-node topology using the `codex` kernel as its base. The six executables it names are written relative to `datasets/`, so in a standalone copy that leading name is simply the folder you are standing in. - `codex.python.json`: declarative `CommandLanguageAdapter` template for Python projects. ## The pattern catalog Five cards, one per shape this bundle can actually carry out: | Card | Shape it claims | Family | |---|---|---| | `annotate-literal-defaults` | a default that is a string, number or `None` literal and states no type | typing | | `mutable-default-to-none` | a `[]` or `{}` default, which is one object shared by every call | mutation | | `chain-to-registry` | an `if`/`elif` chain dispatching on one name, ending in a refusal | shape | | `open-to-context-manager` | a file handle opened in a function body and closed by hand | resources | | `bare-assert-to-explicit-raise` | a bare `assert` as the guard of a function, which vanishes under `-O` | contracts | A card is not a prompt: it names a syntax-tree shape, and `lgpython/rules.py` refuses anything that is not that shape. `chain-to-registry` refuses a chain whose branches take different kinds of arguments (`BRANCH_SHAPE_MISMATCH`), `open-to-context-manager` refuses a handle that escapes the function it opened (`HANDLE_ESCAPE`), `mutable-default-to-none` refuses a default that already carries an annotation (`ANNOTATED_MUTABLE_DEFAULT`). A refusal is an answer, not a failure: it names the reason code and writes nothing. Every change this bundle makes is a pair. The rule returns two edits, the change in the source file and a lock test appended to the test file paired with it, and `apply_pattern` puts both in one transaction: the pair commits together, or nothing is written. The lock test is what makes the second run honest. Run `chain-to-registry` on `src/registry.py::render` and the lock asserts that the mapping is there, that each kind reaches its handler, that the chain is gone, and that the refusal still refuses; take only the lock test and leave the source alone, and the test suite fails. The pair then goes through the six nodes of the kernel as any other change does: the proposing roles claim it, `gate_checker` runs the syntax gate and the selected tests, `adversary` reproduces the result by another path, and the arbiter returns `VERIFIED` with assurance 3 only when both trusted roles agree. `--dry-run` runs all of that against a copy and leaves the workspace byte for byte as it was. A card that refuses never reaches the nodes, and a path policy that blocks the lock test blocks the source edit with it. This is a catalog of patterns this bundle has carried out and can re-derive, not a claim that it can change Python in general. `patterns/coverage.json` says what has been shown and names its denominator: the five cards over the five source files and fifteen module level functions of `fixtures/pattern_lab/`, not over Python and not over any corpus of real repositories. The corpus is generated, like the kernel's own: ``` python -B tools/build_patterns.py --check PATTERNS: CONFIRMED (10 rows over 5 cards, 15 module level functions in the fixture) ``` Each row is a work case in the schema `lgcodex/casecorpus.py` defines, so the kernel can check the shape of a claim about a Python file without reading a byte of Python: `case_id`, the language tag, the family, the intent tags, the edits, the verdict the run must reach, and for a refusal the reason code. `patterns/` is a generated folder, so edit `tools/build_patterns.py` and let `--check` say so. ## Working the fixture from the command line The commands below were run against `fixtures/pattern_lab/` as published, and what follows is what came back. The first one answers before anything is asked to change: ``` $ python -B -m lgpython symbols --workspace fixtures/pattern_lab --limit 5 files=10 symbols=29 edges=29 0.0942 src/registry.py::render 0.0838 src/tokens.py::count_words 0.0669 src/guards.py::open_ticket 0.0572 src/registry.py::format_short 0.0481 src/registry.py::format_json ``` The ranking is PageRank over the call and import graph, and the three highest ranked functions here are three of the five the catalog claims: the dispatcher, the annotatable default, the bare guard. To know which tests a change is answerable to: ``` $ python -B -m lgpython select-tests --workspace fixtures/pattern_lab --files src/registry.py tests/test_registry.py ``` A card states its terms before you use it. This transcript is abridged to the lines a decision turns on, and the two long lines are wrapped here for width: ``` $ python -B -m lgpython patterns show --pattern open-to-context-manager open-to-context-manager family resources shape a module level function that opens a file into a name and closes that name itself why a close that is not tied to the scope is skipped by the one path that raises on the way out, and the reader has to trace every exit to believe the handle is closed. needs - the name is used only inside that function and never stored or returned lock the source opens inside a with block and never calls close, and a file written in a temporary directory is read back through the rewritten function refuses ALREADY_SCOPED, NO_BARE_OPEN, HANDLE_ESCAPE, NOT_A_MODULE_FUNCTION needs assurance >= 3 to commit ``` To find out whether a workspace really holds the shape, rather than guessing: ``` $ python -B -m lgpython patterns scan --workspace fixtures/pattern_lab --pattern chain-to-registry ``` This prints one hit, `src/registry.py::render`, with the two edits it would apply: the chain of `if` and `elif` that becomes a mapping of handlers, and the lock test appended to `tests/test_registry.py`. `render_pair`, in the same file, is not listed: its chain is not in the shape the card claims, and a card that does not claim a shape does not touch it. The pair, verified and not committed: ``` $ python -B -m lgpython patterns apply --workspace fixtures/pattern_lab \ --pattern chain-to-registry --target src/registry.py::render --dry-run VERIFIED (assurance 3, committed=False) OK_DUAL_CONFIRMATION: confirmed by adversary, gate_checker ``` The same command without `--dry-run` writes both files in one transaction. Ask for the function whose shape is wrong and the answer is a refusal with a reason, an exit code of 1, and a workspace that did not move by a byte: ``` $ python -B -m lgpython patterns apply --workspace fixtures/pattern_lab \ --pattern chain-to-registry --target src/registry.py::render_pair --dry-run REFUSED (assurance 0, committed=False) BRANCH_SHAPE_MISMATCH: the chain in 'render_pair' tests more than one name against text literals, its branches do not take the same arguments, or its last branch does not raise nothing was written; the card named this reason before any node ran ``` A change of your own goes through the same six nodes, as a search and replace you wrote: ```bash python -B -m lgpython edit --workspace repo --file src/x.py \ --search "def load(path):" --replace "def load(path: Path) -> dict:" --dry-run ``` and so do `create --file ... --content-file ...`, `delete`, and `verify --file ...`, which reports a verdict for a file without asking for a change. With `--strict-tools` the run demands `mypy` and `ruff` and answers `ABSTAIN` when they are not installed, instead of reporting a check that never happened. `check-adapter` says whether the Python adapter holds the contract of the kernel, and exits non-zero when it does not. `tests/test_cli.py` runs the documented commands as separate processes and asserts their exit codes and their answers, because a documented command that crashes breaks a promise even when every library call beside it is correct. ## Running From the folder of this dataset, with `LGCODEX_ROOT` pointing at the folder of the kernel dataset: ```bash python -B -m pytest -p no:cacheprovider tests -q python -B tools/run_gates.py python -B -m lgpython check-adapter --workspace fixtures/sample_pkg python -B -m lgpython verify --workspace fixtures/sample_pkg --file src/mathops.py python -B -m lgpython patterns list python -B -m lgpython patterns show --pattern chain-to-registry python -B -m lgpython patterns scan --workspace fixtures/pattern_lab --pattern chain-to-registry python -B -m lgpython patterns apply --workspace fixtures/pattern_lab \ --pattern chain-to-registry --target src/registry.py::render --dry-run ``` `patterns apply` without `--dry-run` commits, and only on a verdict the kernel accepts: it commits when the assurance reaches the higher of the session floor and the card's own floor, and reports a refusal with the reason code of the rule that stopped it. `fixtures/pattern_lab/` is a copy candidate: the commands above either read it or verify against a copy, and the tests copy it to a temporary folder before writing, so the folder as published keeps the exact shape the coverage numbers were counted on. ## What this bundle needs from the codex kernel `lgpython` imports `lgcodex`, and `lgpython/_codex_bridge.py` resolves that import in one step: an already importable `lgcodex`, then the folder named by `LGCODEX_ROOT`, then a sibling `codex/` or a `datasets/codex/` among the ancestors of the package. Downloaded from here the two orders are the same folder, and the resolution is: pip install -r requirements.txt git clone https://huggingface.co/datasets/tailot/lingologos-codex LGCODEX_ROOT=/path/to/lingologos-codex python -B -m pytest -p no:cacheprovider tests -q Nothing in this bundle downloads anything at run time: the kernel is a second download you make once, and the tests fail with a named reason when it is missing rather than passing without it. The kernel never imports this folder, so the dependency has exactly one direction, and one copy of the kernel can serve any number of workspaces. ## The ten pattern cases `patterns/pattern_cases.jsonl` holds 10 rows, one accepted and one refused for each of the five cards of the catalog: `case_id`, `language`, `family`, `intent_tags`, the `edits` the rule returned (the source edit and the test that locks it), the verdict the run must reach, and for a refusal the `reason_code` the rule answered with. A row is a work case in the schema the kernel dataset defines in `lgcodex/casecorpus.py`, so its shape is checkable without a Python file in sight. `tools/build_patterns.py` derives the rows by running each rule over `fixtures/pattern_lab/`, and `--check` re-derives them and compares the bytes: a row is never edited by hand. The same tool writes `patterns/coverage.json`, which states what the ten rows cover and names its own denominator, the fixture. Ten rows are five cards carried end to end, not a benchmark: the fixture is small and was written for this bundle, and nothing here counts coverage of real repositories. ## Rights The dataset is published by the author of LingoLOGOS under the same account, `tailot`. The source tree is the `codex-python/` folder of https://github.com/tailot/LingoLOGOS, where the project states its own terms. Neither that repository root nor this folder carries a `LICENSE` file, so no license is claimed here beyond what the publisher states on the repository and on this dataset page; ask there before reusing the code. The fixture package under `fixtures/sample_pkg/` and the pattern laboratory under `fixtures/pattern_lab/` were written for this dataset and are not taken from a third-party project. ## Citation @misc{lingologos_codex_python, title = {LingoLOGOS codex-python: a Python programming layer over the codex kernel}, author = {{LingoLOGOS}}, year = {2026}, howpublished = {\url{https://huggingface.co/datasets/tailot/codex-python}}, }