diff --git a/Blog.code-workspace b/Blog.code-workspace index dca73245..9df62c4a 100644 --- a/Blog.code-workspace +++ b/Blog.code-workspace @@ -1,6 +1,3 @@ -// Standard workspace fragment carried by every fleet repo (catalog/snippets/vscode/base.jsonc, -// https://github.com/ptr727/ProjectTemplate/blob/main/catalog/snippets/vscode/README.md). -// This repo ships no dotnet/python/docker target, so it carries base.jsonc only. { "folders": [{ "path": "." }], "settings": { @@ -13,14 +10,10 @@ }, "extensions": { "recommendations": [ - "anthropic.claude-code", - "arahata.linter-actionlint", "davidanson.vscode-markdownlint", "editorconfig.editorconfig", "fanaticpythoner.better-todo-tree", - "github.vscode-github-actions", "streetsidesoftware.code-spell-checker", - "timonwong.shellcheck", "yzhang.markdown-all-in-one" ] } diff --git a/CONTENT.md b/CONTENT.md index 0b7d689a..48ae240c 100644 --- a/CONTENT.md +++ b/CONTENT.md @@ -159,7 +159,7 @@ Treat that as a judgment about the archive, never as a precedent for a new post. - **`##` carries the spine, `###` only for genuinely nested steps.** The migration post uses `###` for numbered procedure steps inside one section and nowhere else. - **A heading states a finding rather than labeling a topic.** "Your export is not a complete copy of your media" beats "Media". Sentence case, no trailing question mark. - **No hand-written table of contents.** The theme generates one from the headings. -- **Three unheaded paragraphs open a post**: the concrete situation, what the post is really about, and one sentence on what it covers. +- **A one-sentence lede opens a post, followed by ``.** It says what the post covers and stands on its own. The post list shows it under the title, and it becomes the page's meta description and social card. It carries no links, since the list and the meta description drop them, so a name's first link is in the body. The unheaded paragraphs after it give the concrete situation and what the post is really about. - **Every fenced code block carries a language tag**, so highlighting picks the right lexer instead of guessing. ## Voice diff --git a/HISTORY.md b/HISTORY.md index 4191c48a..bb31f8bd 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,17 +2,17 @@ Pieter Viljoen's blog, and the tooling that builds, verifies, and deploys it. -The blog's public address is [blog.insanegenius.com][blog-link]. Until its DNS records are cut over, that address still serves the old WordPress site, and the site this repository builds is served at `blog.insanegenius.net`. +The blog's public address is [blog.insanegenius.com][blog-link]. + +> Until its DNS records are cut over, that address still serves the old WordPress site, and the site this repository builds is served at `blog.insanegenius.net`. ## Release History - Version 1.0: - - The blog's content, media, URL contract, and deploy tooling live in one repository, under version control and gated by CI. - - 108 posts and 2 pages as Hugo content, in a tree that mirrors the URLs it serves, with 778 media files carried at their original bytes. - - The URL contract as committed ground truth: 328 addresses that must render, 917 that must redirect, and 778 legacy image URLs that must resolve, each verified with a live request rather than predicted. - - CI gates that contract on every pull request, alongside the doc, shell, and workflow linters, with the Hugo version pinned by checksum so a build is reproducible. - - A self-contained release bundle carrying the site, the web-server config, and the redirect maps together, so a rollback reverts the rules and the content they refer to as one unit. - - The site is not yet serving its public address. This release is the source and its pipeline, not the cutover. + - The blog moved from WordPress to a Hugo site built and verified by GitHub Actions and served by Caddy. The public address cuts over separately. + - 108 posts, 2 static pages, 778 media files, converted to a Hugo site in a tree that mirrors the original URLs. + - Personal data gates: image metadata stripped to an allowlist, archive redactions declared in a manifest and verified by hash, and the text of the pages and new posts scanned for addresses, coordinates, and other identifiers. + - Publishes a self-contained release bundle carrying the site, the web-server config, and the redirect maps together, so a rollback reverts the rules and the content they refer to as one unit. diff --git a/README.md b/README.md index 624b0c11..d8386091 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ -# Blog +# Blog Pieter Viljoen's blog, and the tooling that builds, verifies, and deploys it. -The blog's public address is [blog.insanegenius.com][blog-link]. Until its DNS records are cut over, that address still serves the old WordPress site, and the site this repository builds is served at `blog.insanegenius.net`. +The blog's public address is [blog.insanegenius.com][blog-link]. + +> Until its DNS records are cut over, that address still serves the old WordPress site, and the site this repository builds is served at `blog.insanegenius.net`. ## Build and Distribution @@ -25,9 +27,7 @@ The blog's public address is [blog.insanegenius.com][blog-link]. Until its DNS r **Summary**: -- First public release. The content, media, URL contract, and deploy tooling are published as a repository for the first time. -- The URL contract is committed ground truth and gated in CI: 328 addresses that must render, 917 that must redirect, and 778 legacy image URLs that must resolve. -- The site is not yet serving its public address. This release is the source and its pipeline, not the cutover. +- The blog moved from WordPress to a Hugo site built and verified by GitHub Actions and served by Caddy. The public address cuts over separately. See [Release History][history] for complete release notes and older versions. @@ -36,6 +36,8 @@ See [Release History][history] for complete release notes and older versions. - [Overview](#overview) - [Migration from WordPress](#migration-from-wordpress) - [How a Change Reaches the Site](#how-a-change-reaches-the-site) + - [Keeping Personal Data Off the Site](#keeping-personal-data-off-the-site) + - [What Happens While the Site Runs](#what-happens-while-the-site-runs) - [Configuration](#configuration) - [Questions or Issues](#questions-or-issues) - [Development Environment Setup](#development-environment-setup) @@ -123,7 +125,17 @@ flowchart LR main -.->|manual dispatch| prod["production site"] ``` -### What Happens While the Site Runs +### Keeping Personal Data Off the Site + +A post is public the moment it deploys, and a photo or a pasted configuration can carry more than its author meant to publish. Three gates keep personal data out. Each runs in this repository's validate action on every pull request, under the required status check, so a finding blocks the merge. + +- **Image metadata.** Before an image is committed, its author runs [`scripts/normalize-media.py`][normalize-media], which strips it to an allowlist of what it needs to render. That is its dimensions, a pinned color profile, and on a JPEG its orientation. A JPEG keeps its capture time only when nothing else in its Exif fails the gate. Location, device, and authorship are not on the list, so they go without anyone having to name them. The removal is lossless, and a file it cannot clean unambiguously is refused rather than guessed at. [`checks/check-media-metadata.py`][check-media-metadata] is the gate, and it fails the build on anything left over, including inside a `.zip`. +- **Redactions.** A house number, a face, or a serial number is covered with a flat opaque fill, never a blur. A fill on an image already published is declared in [`checks/media-redactions.json`][media-redactions] and applied by a script. [`checks/check-media-redactions.py`][check-media-redactions] fails when a redacted file no longer matches its recorded hash, which is how a quietly restored original is caught. +- **Text.** [`checks/check-text-pii.py`][check-text-pii] reads every page and post under `content/` outside the imported archive years, front matter and code blocks included. It reports email addresses, hardware addresses, public IP addresses, coordinates, street addresses, and phone numbers. It also reports a URL that carries coordinates or names one specific sensor or station. A finding names the file, the line, and the class, never the value, so the CI log does not republish it. A value a post prints on purpose is declared in an allow file with a reason, and an entry that stops matching fails the gate. + +A fuzzer feeds the metadata parsers malformed images in the same action, because the carried tree is all well formed and would never exercise a refusal. What no gate can judge, whether a picture locates the home or identifies a person, is the checklist in [CONTENT.md][content]. + +### What Happens While the Site Runs Publishing is half of it. The other half runs on its own cadence, because the contract proves only the addresses someone wrote down. @@ -220,6 +232,9 @@ Licensed under the [MIT License][license]\ [capture]: ./capture/ [capture-readme]: ./capture/README.md +[check-media-metadata]: ./checks/check-media-metadata.py +[check-media-redactions]: ./checks/check-media-redactions.py +[check-text-pii]: ./checks/check-text-pii.py [checks]: ./checks/ [content]: ./CONTENT.md [deploy]: ./deploy/ @@ -229,7 +244,9 @@ Licensed under the [MIT License][license]\ [history]: ./HISTORY.md [hugo-config]: ./hugo.yaml [license]: ./LICENSE +[media-redactions]: ./checks/media-redactions.json [migration-post]: ./content/posts/2026/08/01/moving-this-blog-from-wordpress-to-hugo.md +[normalize-media]: ./scripts/normalize-media.py [operations]: ./OPERATIONS.md [workflow]: ./WORKFLOW.md diff --git a/content/posts/2026/08/01/moving-this-blog-from-wordpress-to-hugo.md b/content/posts/2026/08/01/moving-this-blog-from-wordpress-to-hugo.md index 8cec43a9..84b70b3b 100644 --- a/content/posts/2026/08/01/moving-this-blog-from-wordpress-to-hugo.md +++ b/content/posts/2026/08/01/moving-this-blog-from-wordpress-to-hugo.md @@ -14,12 +14,14 @@ tags: - migration discussions: https://github.com/ptr727/Blog/discussions --- +I moved this blog from WordPress to a Hugo static site, and the real work was not converting the posts but keeping every inbound link since 2008 working. + + + This blog has been quiet since May 2024, and it was still costing about $140 a year to sit there. That is a silly amount to pay for a site nobody was updating, so I moved it: the content is now a [Hugo](https://gohugo.io/) static site, the source lives on GitHub, CI builds and verifies it, and [Caddy](https://caddyserver.com/) serves it from a small VPS. The interesting part of this migration was not Hugo. Converting the posts took an afternoon. The interesting part was that this blog has been at the same domain since 2008 across **three** platforms, and each platform left its own URL shapes behind. Getting the content across is easy. Not breaking sixteen years of inbound links is the actual job. -This post is about what that took, and about the things that silently went wrong and only showed up because I went looking. - ## This is the second time I have done this The first move is documented on this blog, which turned out to be genuinely useful fourteen years later. @@ -249,6 +251,16 @@ Two things I would do again: **Demonstrate each gate failing before trusting it.** I deleted a post and confirmed the parity check failed. I deleted one media file and confirmed the media and asset checks failed separately. I pointed a redirect map entry at a page that does not exist and confirmed the live check caught it. A gate that has only ever passed is indistinguishable from one that checks nothing. +## Your original photos know where you live + +A few weeks after the move, I found that keeping the originals from the export tar had a cost. **206 files held GPS coordinates that located my house to about a meter**, along with camera bearing and altitude. Once the files sit in a public repository, anyone can read that metadata. + +So personal data became a gate too. A normalizer strips every image down to what it needs to render: its dimensions, a standard color profile, and a JPEG's orientation. A JPEG keeps its capture time only when the rest of its Exif is already clean. Location, device, and authorship are not on that list, so they go without anyone having to think of them. The strip is lossless, and it refuses a file it cannot clean unambiguously rather than guessing. CI then fails the build on any image carrying anything else, including inside a zip. + +Metadata is only half of it. A house number, a face, or a license plate is in the pixels, so those get a flat opaque fill, never a blur, which can be reversed for a short string. The fills on old images are declared in a manifest and checked by hash, so a restored original fails the build. A third check reads the text of every page and every new post for email addresses, hardware addresses, public IP addresses, coordinates, street addresses, and phone numbers. It also flags a link that carries coordinates or points at one specific sensor or station. It reports the file, the line, and the kind of finding, but never the value, so the CI log does not publish what it caught. + +All three run on every pull request, next to the URL checks. How it works in detail is in the [repository README](https://github.com/ptr727/Blog/blob/main/README.md). + ## Do not do this by hand I did almost none of this manually. I ran it as a series of tasks through [Claude Code](https://claude.com/claude-code), and it is worth saying plainly that this is the kind of work it is genuinely good at. diff --git a/content/posts/2026/09/16/reverse-engineering-the-easystart-bluetooth-protocol.md b/content/posts/2026/09/16/reverse-engineering-the-easystart-bluetooth-protocol.md index 0ced98a9..ee9b5d87 100644 --- a/content/posts/2026/09/16/reverse-engineering-the-easystart-bluetooth-protocol.md +++ b/content/posts/2026/09/16/reverse-engineering-the-easystart-bluetooth-protocol.md @@ -14,11 +14,15 @@ tags: - claude discussions: https://github.com/ptr727/ESPHome-Config/discussions --- +I decoded the Bluetooth protocol of my Micro-Air EasyStart soft starters from the vendor's Android app, with help from Claude Code, and now read their compressor data into Home Assistant through ESPHome. + + + I have [Micro-Air EasyStart](https://www.microair.net/products/easystart-flex-home-ac-soft-starter) soft starters installed on both my HVAC compressors. I installed them in the summer of 2023, after I started getting frequent brownouts whenever a compressor started. The brownouts came from a combination of low supply voltage, later addressed by my electricity provider, and rising neighborhood demand. Older homes are being torn down and replaced with much larger ones, so panels are going from 80 A to 400 A. Every year more homes add AC and electric car chargers. The EasyStart modules have built-in Bluetooth Low Energy (BLE), and the vendor's phone app shows live current, line frequency, peak startup current, and a start counter. I monitor whole-home power usage and solar generation in [Home Assistant](https://www.home-assistant.io/). I wanted to use the BLE data for more granular AC power usage reporting, without installing additional current monitors in my panel. I reached out to Micro-Air, but they would not share the protocol. At the time I could not find anyone else who had decoded the protocol, and I lost interest. -In the meantime I had been watching [Matt Brown's YouTube channel](https://www.youtube.com/@mattbrwn) on reverse engineering and Internet of Things (IoT) hacking. [ESPHome](https://esphome.io/) had also made BLE device support much easier. With renewed motivation I set out to reverse engineer the BLE protocol myself, or rather, myself with a lot of automation and decoding help from [Claude Code](https://claude.com/claude-code). This post walks through pulling the protocol out of the vendor's Android app and checking the decode against the live module. It ends with the result running in Home Assistant through ESPHome. +In the meantime I had been watching [Matt Brown's YouTube channel](https://www.youtube.com/@mattbrwn) on reverse engineering and Internet of Things (IoT) hacking. [ESPHome](https://esphome.io/) had also made BLE device support much easier. With renewed motivation I set out to reverse engineer the BLE protocol myself, or rather, myself with a lot of automation and decoding help from [Claude Code](https://claude.com/claude-code). ## The app already has the protocol in it diff --git a/content/posts/2026/09/26/dont-trust-your-agents.md b/content/posts/2026/09/26/dont-trust-your-agents.md index 1c5ab8b8..4b183b34 100644 --- a/content/posts/2026/09/26/dont-trust-your-agents.md +++ b/content/posts/2026/09/26/dont-trust-your-agents.md @@ -8,12 +8,14 @@ tags: - claude - github --- +Written rules did not stop my coding agents from posting in a stranger's GitHub repo or taking down my server, so I added hooks and resource limits that enforce what the rules could not. + + + I have various repos on GitHub: private and public, C# and Python, NuGet and PyPI packages, CLI tools, Docker containers, configuration, utilities, and docs. In my typical engineering mindset I always try to improve with every iteration. For me this means I want to go back and apply a new style or pattern to my other repos. Keeping repos in top shape is not my day job. I have to balance the time I spend on upkeep with being responsive on my open source projects, and with my personal interest in new projects and features. -This post covers how the repo I built to keep them in sync became a rule orchestrator for coding agents, and the guardrails I built when rules alone did not stop them. - ## How it started I created a single repo containing my best-of patterns in the form of example projects. I created a workspace with one of each of the project types I often use: a C# CLI console app, a C# NuGet package, a Python PyPI package, a multi-stage Docker container, and a docs-only project. @@ -78,6 +80,7 @@ I had Claude implement [`gh-write-guard`](https://github.com/ptr727/ProjectTempl - a hand-built review thread resolve, or a reply through the REST API, where my [`pr_review.py`](https://github.com/ptr727/ProjectTemplate/blob/main/scripts/pr_review.py) wrapper script does the same job without an ID to type - a mutating git command run in my primary checkout rather than in a worktree - a bypass flag such as `git push --no-verify` or `gh pr merge --admin` +- a shell wait loop that sleeps with no timeout or counter, which would outlive the agent that wrote it The installer registers the hook in `~/.claude/settings.json`, together with a permission rule that lets the wrapper script run without a prompt. Simplified, it looks like this: @@ -125,11 +128,31 @@ Allowing my user account and user processes to consume all memory is my fault, f The write guard reads command text, and it could not have caught this one. The recursion lived in a script file that the command only named. -So instead of judging what a command says, [`tool-containment.py`](https://github.com/ptr727/ProjectTemplate/blob/develop/host-setup/agent-safety/claude/tool-containment.py) bounds what any command can do. Claude Code's [`CLAUDE_CODE_SHELL_PREFIX`](https://code.claude.com/docs/en/env-vars) setting names a program that wraps every shell command the agent runs. The prefix runs each Bash tool call in its own [`systemd-run --user --scope`](https://www.freedesktop.org/software/systemd/man/latest/systemd-run.html), with a [`TasksMax`](https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html) of 8192 processes and a `MemoryMax` of 25% of RAM. A recursive fan-out then fails fast at the ceiling, instead of growing silently. The limits belong to the scope, so they still hold when the harness moves a timed-out command into the background. +So instead of judging what a command says, [`tool-containment.py`](https://github.com/ptr727/ProjectTemplate/blob/main/host-setup/agent-safety/claude/tool-containment.py) bounds what any command can do. Claude Code's [`CLAUDE_CODE_SHELL_PREFIX`](https://code.claude.com/docs/en/env-vars) setting names a program that wraps every shell command the agent runs. The prefix runs each Bash tool call in its own [`systemd-run --user --scope`](https://www.freedesktop.org/software/systemd/man/latest/systemd-run.html) control group (cgroup). The scope gets a [`TasksMax`](https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html) of 8192 processes and a `MemoryMax` of 25% of RAM. Its `MemorySwapMax` is zero, so a runaway at the memory ceiling is killed instead of pushing the host into swap. A recursive fan-out then fails fast at the ceiling, instead of growing silently. The limits belong to the scope, so they still hold when the harness moves a timed-out command into the background. + +A `SessionEnd` hook, [`stray-process-sweep.py`](https://github.com/ptr727/ProjectTemplate/blob/main/host-setup/agent-safety/claude/stray-process-sweep.py), stops any scope the session left behind and reports what it held. It also reports, but never kills, any process still descended from the session that runs outside those scopes, and hands me the `kill` line. When I ran the original shim under a 64-task ceiling, it failed at once with `fork: Resource temporarily unavailable`, and nothing survived. The cost is about 35 ms per tool call. The [PR](https://github.com/ptr727/ProjectTemplate/pull/1900) has the design decisions, including why a `PreToolUse` rewrite of the command did not work. + +It is not finished. Each nested agent session gets fresh ceilings of its own, so a chain of agents calling agents has no total cap, and that is [the next gap](https://github.com/ptr727/ProjectTemplate/issues/1903). Containment also needs a systemd user manager, so where there is none, such as on macOS, a tool call runs uncontained. + +## Capping the host, not just the agent + +Per-command scopes only cover commands an agent runs through Claude Code. A script I start by hand, a cron job, or an agent without a hook would still run with no limit. The fix I should have had in place from the start is on the host itself, and it applies to any process, not just an agent's. + +On a Linux host that runs systemd, every login session sits under a `user-.slice` cgroup. By default that slice gets a task limit of a third of the kernel's thread maximum, and no memory limit at all. My host runs [Proxmox VE](https://www.proxmox.com/en/products/proxmox-virtual-environment/overview), which caps its virtual machines and containers, but a session on the host itself only got those defaults. A drop-in for the `user-.slice` template applies to every user's slice. Each account gets its own ceilings, and every session of that account shares them: + +```ini +# /etc/systemd/system/user-.slice.d/50-limits.conf +[Slice] +TasksMax=2% +MemoryHigh=60% +MemoryMax=70% +``` + +systemd resolves the percentages against the host's own RAM and task limit, so the file does not change when the hardware does. On my host, `TasksMax=2%` is about 57 thousand tasks, against a normal peak of about 1.3 thousand. A fork past that fails inside the slice, and the runaway stops instead of the host. Past `MemoryHigh` the slice is throttled through memory reclaim before anything is killed, which keeps the host responsive. Past `MemoryMax` the kernel's OOM killer acts inside the slice only, so the rest of the host keeps running. -A `SessionEnd` hook stops any scope the session left behind and reports what it held. When I ran the original shim under a 64-task ceiling, it failed at once with `fork: Resource temporarily unavailable`, and nothing survived. The cost is about 35 ms per tool call. The [PR](https://github.com/ptr727/ProjectTemplate/pull/1900) has the design decisions, including why a `PreToolUse` rewrite of the command did not work. +A drop-in only reaches a slice when it starts, so the install script also applies the values to slices that are already running with `systemctl set-property --runtime`. It then reads `pids.max`, `memory.high`, and `memory.max` back from `/sys/fs/cgroup` rather than trusting what systemd says it set. The same script sets `kernel.panic` so a panicked host reboots after ten seconds instead of hanging. It also adds [Netdata](https://www.netdata.cloud) alarms on the process count and on memory pressure, because the stock alarms either could not fire on this host or fired about 30 minutes into the incident. -It is not finished. Each nested agent session gets fresh ceilings of its own, so a chain of agents calling agents has no total cap, and that is [the next gap](https://github.com/ptr727/ProjectTemplate/issues/1903). Capping my user slice on the host itself is tracked separately, and it is the fix I should have had in place from the start. +The two layers are complementary. The per-command scope stops one agent's runaway early, with a clear error the agent can read. The slice limit is the backstop for everything else running under my account, agent or not. ## Instructions are only guidelines diff --git a/cspell.json b/cspell.json index 76df2f59..97506fd6 100644 --- a/cspell.json +++ b/cspell.json @@ -24,6 +24,7 @@ "codegen", "cutover", "dependabot", + "exif", "goldmark", "insanegenius", "nbgv", @@ -35,6 +36,7 @@ "pieter", "proxmox", "racknerd", + "redactions", "taxonomies", "traefik", "unattended",