From 67de892fe2f56e68d45482a7648b923586361eb2 Mon Sep 17 00:00:00 2001 From: Patrick CN Martin Date: Tue, 24 Nov 2026 14:27:16 +0100 Subject: [PATCH 01/22] deps: PyYAML for reading and writing whole YAML data files Frontmatter stays with the hand-written parser; PyYAML reads with safe_load only. Needed now for the canvas views, and later for other jobs. Co-Authored-By: Claude Opus 5.5 --- AGENT.md | 7 ++++--- docs/writing-a-function.md | 7 ++++--- pixi.lock | 5 +++++ pyproject.toml | 2 +- uv.lock | 2 ++ 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/AGENT.md b/AGENT.md index 0a777bd..3745a72 100644 --- a/AGENT.md +++ b/AGENT.md @@ -66,9 +66,10 @@ skills and patterns come back here by pull request; raw traces never do. - **Provenance is git blob hashes** (`git hash-object`), so `git cat-file -p` recovers the exact version a summary was built from. - **The frontmatter parser is hand-written,** so key order, flow mappings and quoting survive a - rewrite. No YAML library. -- **The runtime is the standard library plus `python-dotenv`,** which reads `env/.env`. `git` is - the one system dependency. + rewrite. PyYAML never touches frontmatter: it reads and writes whole data files only. +- **PyYAML reads with `safe_load`, never `load`:** a file's content is untrusted input. +- **The runtime is the standard library plus `python-dotenv`,** which reads `env/.env`, **and + PyYAML.** `git` is the one system dependency. - **`labbrain.okf` returns data and `cli.py` prints it.** No `print` below the CLI. - **No state outlives a call.** A cache is made by the function that needs it and passed down (`history(vault, rel, cache)`). The night run is one process running many jobs, and a module-level diff --git a/docs/writing-a-function.md b/docs/writing-a-function.md index 3740499..55862cd 100644 --- a/docs/writing-a-function.md +++ b/docs/writing-a-function.md @@ -47,8 +47,9 @@ and prints their results. Nothing else prints. `add_frontmatter` adds its header. Any other metadata goes into a note's header only when the header says `annotate: true`, with an entry in `annotated`, and never replaces `generated`. Other output goes to summaries, `index.md` blocks or logs. -- **Frontmatter goes through `frontmatter.py`.** There is no YAML library on purpose: one would - reorder keys and change quoting. +- **Frontmatter goes through `frontmatter.py`.** PyYAML is never used on frontmatter, on purpose: + it would reorder keys and change quoting. It reads and writes whole YAML data files only, and + reads with `yaml.safe_load`, because a file's content is untrusted. - **Git goes through `git.py`.** - **An error is an exception that takes data.** Arguments in, attributes stored, and the message formatted in `__init__`: @@ -62,7 +63,7 @@ and prints their results. Nothing else prints. ``` - **A one-line docstring,** and comments only where the code isn't obvious. - **No new dependency without a reason,** written in the audit log. The runtime today is the - standard library plus `python-dotenv`. + standard library, `python-dotenv` and PyYAML. ## An example Say `check` should flag a folder summary that has no `description`, since `index.md` shows the diff --git a/pixi.lock b/pixi.lock index 1bc8624..f373af8 100644 --- a/pixi.lock +++ b/pixi.lock @@ -71,6 +71,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2026e-h5d301ff_0.conda - pypi: ./ - pypi: https://files.pythonhosted.org/packages/60/d1/38f3a3405989a89ac18390803e70c6ad7c7760da4f9b83cbeca0c44a0c72/python_dotenv-1.2.4-py3-none-any.whl + - pypi: https://files.pythonhosted.org/packages/74/27/e5b8f34d02d9995b80abcef563ea1f8b56d20134d8f4e5e81733b1feceb2/pyyaml-6.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl linux-aarch64: - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/_openmp_mutex-4.5-20_gnu.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/bzip2-1.0.8-h4777abc_10.conda @@ -112,6 +113,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/python_abi-3.13-9_cp313.conda - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2026e-h5d301ff_0.conda - pypi: ./ + - pypi: https://files.pythonhosted.org/packages/50/31/b20f376d3f810b9b2371e72ef5adb33879b25edb7a6d072cb7ca0c486398/pyyaml-6.0.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl - pypi: https://files.pythonhosted.org/packages/60/d1/38f3a3405989a89ac18390803e70c6ad7c7760da4f9b83cbeca0c44a0c72/python_dotenv-1.2.4-py3-none-any.whl osx-64: - conda: https://conda.anaconda.org/conda-forge/noarch/ca-certificates-2026.10.23-hbd8a1cb_0.conda @@ -149,6 +151,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-64/zstd-1.5.7-hbc1a06c_7.conda - pypi: ./ - pypi: https://files.pythonhosted.org/packages/60/d1/38f3a3405989a89ac18390803e70c6ad7c7760da4f9b83cbeca0c44a0c72/python_dotenv-1.2.4-py3-none-any.whl + - pypi: https://files.pythonhosted.org/packages/d1/11/0fd08f8192109f7169db964b5707a2f1e8b745d4e239b784a5a1dd80d1db/pyyaml-6.0.3-cp313-cp313-macosx_10_13_x86_64.whl osx-arm64: - conda: https://conda.anaconda.org/conda-forge/noarch/ca-certificates-2026.10.23-hbd8a1cb_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python_abi-3.13-9_cp313.conda @@ -185,6 +188,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-arm64/zstd-1.5.7-hf451053_7.conda - pypi: ./ - pypi: https://files.pythonhosted.org/packages/60/d1/38f3a3405989a89ac18390803e70c6ad7c7760da4f9b83cbeca0c44a0c72/python_dotenv-1.2.4-py3-none-any.whl + - pypi: https://files.pythonhosted.org/packages/b1/16/95309993f1d3748cd644e02e38b75d50cbc0d9561d21f390a76242ce073f/pyyaml-6.0.3-cp313-cp313-macosx_11_0_arm64.whl dev: channels: - url: https://conda.anaconda.org/conda-forge/ @@ -2904,6 +2908,7 @@ packages: name: labbrain requires_dist: - python-dotenv>=1.0 + - pyyaml>=6.0 - ruff ; extra == 'dev' - pytest ; extra == 'dev' - pytest-cov ; extra == 'dev' diff --git a/pyproject.toml b/pyproject.toml index 56b30d7..0d750d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ version = "0.1.0" description = "Tools and skills for agents that read and maintain an OKF lab wiki" readme = "README.md" requires-python = ">=3.11" -dependencies = ["python-dotenv>=1.0"] +dependencies = ["python-dotenv>=1.0", "pyyaml>=6.0"] [project.optional-dependencies] dev = [ diff --git a/uv.lock b/uv.lock index 42a00b9..f072605 100644 --- a/uv.lock +++ b/uv.lock @@ -366,6 +366,7 @@ version = "0.1.0" source = { editable = "." } dependencies = [ { name = "python-dotenv" }, + { name = "pyyaml" }, ] [package.optional-dependencies] @@ -384,6 +385,7 @@ requires-dist = [ { name = "pytest", marker = "extra == 'dev'" }, { name = "pytest-cov", marker = "extra == 'dev'" }, { name = "python-dotenv", specifier = ">=1.0" }, + { name = "pyyaml", specifier = ">=6.0" }, { name = "ruff", marker = "extra == 'dev'" }, ] provides-extras = ["dev"] From d9c41efe1780f84235d33c98ecd3153b39153a7f Mon Sep 17 00:00:00 2001 From: Patrick CN Martin Date: Tue, 24 Nov 2026 14:28:53 +0100 Subject: [PATCH 02/22] _maps/ at the wiki root is labbrain's own: nothing looks inside it listdir skips it, so the pictures the canvas commands will draw there can't make a summary stale, need a header, or show up in a listing. Named with an underscore so a lab's own maps/ folder is never hidden. Co-Authored-By: Claude Opus 5.5 --- AGENT.md | 1 + docs/usage.md | 4 ++-- skills/okf-conventions/SKILL.md | 5 ++++- src/labbrain/okf/files.py | 6 +++++- tests/test_parity.py | 12 ++++++++++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/AGENT.md b/AGENT.md index 3745a72..3849f23 100644 --- a/AGENT.md +++ b/AGENT.md @@ -90,6 +90,7 @@ skills and patterns come back here by pull request; raw traces never do. - a file argument outside the vault is refused, before anything is written; - `links` removes `drift_verification` when it drops the last record, instead of leaving the key empty; + - nothing looks inside `_maps/` at the wiki root, where labbrain draws its pictures; - argparse handles usage and help. --- diff --git a/docs/usage.md b/docs/usage.md index c068652..0b53b5a 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -142,8 +142,8 @@ It ends with `N stale summary(ies).` and exits with 1 if N isn't 0. **What a summary covers:** every text file in its folder (`.md`, `.canvas`, `.sh`, `.nix`, `.lock`, `.txt`, `.py`, `.json`, `.yaml`, `.yml`, `.toml`), and those in subfolders without a summary of their -own. It leaves out other summaries, `index.md`, `log.md`, hidden files and folders, and anything in -another git repo. Images and data files are attachments, not sources. +own. It leaves out other summaries, `index.md`, `log.md`, hidden files and folders, anything in +another git repo, and `_maps/` at the wiki root, where labbrain draws its pictures. Images and data files are attachments, not sources. The hash is taken of the file on disk, so uncommitted edits count. diff --git a/skills/okf-conventions/SKILL.md b/skills/okf-conventions/SKILL.md index 9a3b955..5f1f194 100644 --- a/skills/okf-conventions/SKILL.md +++ b/skills/okf-conventions/SKILL.md @@ -86,7 +86,7 @@ sources: # every file it was built from, with its git bl - **Human review** is OKF's `verified: { by: human:, at: