{
  "schema": "http://google-preview.miscsubjects.com/schemas/jarticle.json",
  "status": "published",
  "slug": "coding-law",
  "title": "The Coding Law hashes every file before and after edits, and refuses commits that skip the check",
  "kind": "build",
  "summary": "The build enforces a rule called CODINGLAW. Its source file opens with a single line that states the entire mechanism: \"Where a hash taken at the start and a hash taken at the commit meet.\" The law was created by owner order on 2026-08-05.",
  "created": "2026-08-06T03:50:03.195Z",
  "body": [
    "## A hash to start, a hash to commit\n\nThe build enforces a rule called CODING_LAW. Its source file opens with a single line that states the entire mechanism: \"Where a hash taken at the start and a hash taken at the commit meet.\" The law was created by owner order on 2026-08-05. The deploy script restates the same idea in its header comment: \"Every code file being shipped must be covered by a committed lease — one that recorded a start hash matching the file as the agent read it, and a commit hash matching the file as it was written.\"\n\nThe law exists because coding agents read a file, decide to edit it, and sometimes write to a version that has already changed underneath them. Another session, a teammate, or a parallel agent may have committed to the same path between the read and the write. Without a guardrail, the agent's edit overwrites the intervening work silently. The Coding Law makes that overwrite impossible by refusing the commit.\n\n## How a lease works\n\nThe flow has two phases. When an agent is about to edit a file, it posts the file path and a SHA-256 hash of the file's current contents to the start endpoint. The server stores this as an open lease in a D1 table called `code_leases`. The lease records the agent identity, the file path, the start hash, and a timestamp.\n\nWhen the agent finishes editing and is ready to commit, it posts the same lease ID plus a new hash — the hash of the file after editing. The server checks that the lease exists, that it is still open, and that the start hash matches what was recorded. If everything lines up, the lease is marked committed with the new hash. If the start hash does not match — because the file changed between the read and the commit attempt — the server returns a 409.\n\nThe object file that defines the law's instructions specifies the trigger: it \"Fires the moment you are about to edit any file under functions/, scripts/, migrations/, workers/, apps-script/, .claude/, or src/ under misc-cli.\" Every code path in the build is in scope.\n\n## The deploy gate\n\nThe deploy script `scripts/check-coding-law.mjs` runs before any code reaches the live site. It collects every file that changed in the current deploy, then queries the lease database. The script's own comment describes the coverage check: \"A file is covered when some committed lease's new_sha equals the file's current hash.\"\n\nFor each changed file, the script hashes the file on disk and looks for a committed lease whose `new_sha` matches that hash. If every changed file has a matching committed lease, the deploy proceeds. If any file lacks a lease, or the lease's commit hash does not match the file's current contents, the deploy is refused.\n\nThe script's final output block reports the result:\n\n```\nlaw: \"CODING_LAW\",\nexamined: files.length,\nscope: CODING_LAW_SCOPE,\nchecked: `${files.length} changed code file(s) each covered by a committed lease matching its current contents`,\n```\n\n## The overwrite refusal\n\nThe most important enforcement point is the 409 `overwrite_refused` error. The API source describes it in its own response definition: \"409 overwrite_refused names the lease that committed your file after you read it. Re-read the file, redo the edit on the now-current version, and start a new lease.\"\n\nThis is the moment the law catches a stale edit. The agent read the file at hash A. Another lease committed hash B to the same path. Now the agent tries to commit, but its start hash A no longer matches the file's current hash B. The server refuses, names the conflicting lease, and tells the agent to re-read and start over. The intervening work is preserved; the stale overwrite never lands.\n\n## The conformance claims\n\nThe law object file enumerates what conformance means. Its claims list includes: \"every changed code file in a deploy is covered by a committed lease\" and \"a commit whose declared base hash no longer matches the file on disk is refused with 409 overwrite_refused.\" These are not aspirations — they are the conditions the deploy script checks on every ship.\n\n## Why it matters\n\nA coding agent that can overwrite a teammate's work is a liability. The Coding Law turns the agent's own read-then-edit pattern into a lease that the server tracks. The agent cannot skip the lease — the deploy script refuses to ship uncovered files. The agent cannot write to a stale version — the commit endpoint refuses mismatched hashes. The law is a small mechanism: two hashes, one table, one check. What it prevents is the one failure mode that silently destroys work."
  ],
  "facts": {
    "converted_from": "markdown",
    "original_updated": "2026-08-06T03:50:03.332Z",
    "register": null,
    "category": "build"
  },
  "hero": "https://miscsubjects.com/img/gen/arcads-gpt-image-c0366e97-124b-456f-8748-ec40802f1e22.png",
  "model": "unattributed",
  "sources": [
    {
      "id": "s1",
      "url": "https://miscsubjects.com/api/coding-law",
      "quote": "THE CODING LAW, ENFORCED. Where a hash taken at the start and a hash taken at the commit meet.",
      "type": "paper",
      "title": "functions/api/coding-law/[[path]].js line 1",
      "accessed_at": "2026-08-06T03:47:47.468Z",
      "prev": "genesis",
      "hash": "fd148b9f7909eaab074047d09c1905d1f1b38d9f810009cfe2b277cb93418f67",
      "quote_sha256": "679ca13839881f4d756b10d1b4c0616572f4a58fdbb7c85bfa9aa2533513cf09"
    },
    {
      "id": "s2",
      "url": "https://miscsubjects.com/a/coding-law",
      "quote": "CODING_LAW (owner order 2026-08-05) — a hash to start, a hash to commit. Every code file being shipped must be covered by a committed lease",
      "type": "paper",
      "title": "scripts/check-coding-law.mjs lines 3-5",
      "accessed_at": "2026-08-06T03:47:47.468Z",
      "prev": "fd148b9f7909eaab074047d09c1905d1f1b38d9f810009cfe2b277cb93418f67",
      "hash": "e5438ff2cbe1ff8f11ce251b53620228d23b85497cf12129fa89f1d664069278",
      "quote_sha256": "3424d2a513cde002acaf7aad3195578a3e1c7d660e601d395e41a2dcaa1e2f70"
    },
    {
      "id": "s3",
      "url": "https://miscsubjects.com/api/articles/coding-law?format=markdown",
      "quote": "Fires the moment you are about to edit any file under functions/, scripts/, migrations/, workers/, apps-script/, .claude/, or src/ under misc-cli",
      "type": "paper",
      "title": "functions/_lib/coding_law_object.js lines 102-103",
      "accessed_at": "2026-08-06T03:47:47.468Z",
      "prev": "e5438ff2cbe1ff8f11ce251b53620228d23b85497cf12129fa89f1d664069278",
      "hash": "6f2a8c173dfb508781f1f53bb99d05f2ea95ffca11797590fb14af4ed581b8e6",
      "quote_sha256": "22aa6475604665096e0c5d111f4f019564d4e303a02b7476451ad2fd7da82c12"
    },
    {
      "id": "s4",
      "url": "https://miscsubjects.com/a/coding-law",
      "quote": "The chain. A file is covered when some committed lease's new_sha equals the file's current hash.",
      "type": "paper",
      "title": "scripts/check-coding-law.mjs line 61",
      "accessed_at": "2026-08-06T03:47:47.468Z",
      "prev": "6f2a8c173dfb508781f1f53bb99d05f2ea95ffca11797590fb14af4ed581b8e6",
      "hash": "0c3e9b87d9bdb6a917b57118ff05e102d4910be8214e98724f5464e89f513e4c",
      "quote_sha256": "0ff2e8c4e6014218490b4667c7ea3f4f814b71ef39c788565cfcb057855c7bcb"
    },
    {
      "id": "s5",
      "url": "https://miscsubjects.com/api/coding-law",
      "quote": "409 overwrite_refused names the lease that committed your file after you read it. Re-read the file, redo the edit on the now-current version, and start a new lease.",
      "type": "paper",
      "title": "functions/api/coding-law/[[path]].js line 74",
      "accessed_at": "2026-08-06T03:47:47.468Z",
      "prev": "0c3e9b87d9bdb6a917b57118ff05e102d4910be8214e98724f5464e89f513e4c",
      "hash": "1d475af22d7c274e5d1bdef2b2a9228c30fb9fa90b6e7812ebab357092a43d52",
      "quote_sha256": "72d383febe2e2151c2373beffa74633ba639f033f2456d053d1a8496514e3031"
    },
    {
      "id": "s6",
      "url": "https://miscsubjects.com/a/coding-law",
      "quote": "law: CODING_LAW, examined: files.length, checked: changed code file(s) each covered by a committed lease matching its current contents",
      "type": "paper",
      "title": "scripts/check-coding-law.mjs lines 120-124",
      "accessed_at": "2026-08-06T03:47:47.468Z",
      "prev": "1d475af22d7c274e5d1bdef2b2a9228c30fb9fa90b6e7812ebab357092a43d52",
      "hash": "aa8f2bd2d8c044362b165feaf504e95f8aaad40fc271d888f940a919f2d5a5b5",
      "quote_sha256": "204e34547b3cd1a77c9f7791f6c28f42a8ce5ca3e1dd8f3b356cc6b0e8400356"
    },
    {
      "id": "s7",
      "url": "https://miscsubjects.com/api/articles/coding-law?format=markdown",
      "quote": "every changed code file in a deploy is covered by a committed lease, a commit whose declared base hash no longer matches the file on disk is refused",
      "type": "paper",
      "title": "functions/_lib/coding_law_object.js lines 153-154",
      "accessed_at": "2026-08-06T03:47:47.468Z",
      "prev": "aa8f2bd2d8c044362b165feaf504e95f8aaad40fc271d888f940a919f2d5a5b5",
      "hash": "3ddbfabb8274afc0b398dfce9b757dad5134386dd2689e2807f47d42383bdd9c",
      "quote_sha256": "a62ae0ccdccc23192584cf96cee9735a8694f599dae504d75a4a97aabfa58962"
    }
  ],
  "claims": [
    {
      "id": "c1",
      "text": "The Coding Law's source file opens with the line: Where a hash taken at the start and a hash taken at the commit meet.",
      "tier": "definition",
      "source_ids": [
        "s1"
      ],
      "why_material": "Establishes the core mechanism the article describes — two hashes bracketing an edit."
    },
    {
      "id": "c2",
      "text": "The law was created by owner order on 2026-08-05.",
      "tier": "regulatory",
      "source_ids": [
        "s2"
      ],
      "why_material": "Dates the origin of the feature to a specific owner directive."
    },
    {
      "id": "c3",
      "text": "The law's trigger fires the moment an agent is about to edit any file under functions/, scripts/, migrations/, workers/, apps-script/, .claude/, or src/ under misc-cli.",
      "tier": "definition",
      "source_ids": [
        "s3"
      ],
      "why_material": "Defines the scope of files the law covers — every code path in the build."
    },
    {
      "id": "c4",
      "text": "A file is covered when some committed lease's new_sha equals the file's current hash.",
      "tier": "definition",
      "source_ids": [
        "s4"
      ],
      "why_material": "This is the coverage check the deploy script uses to decide whether a file may ship."
    },
    {
      "id": "c5",
      "text": "The 409 overwrite_refused error names the lease that committed the file after the agent read it and tells the agent to re-read and start a new lease.",
      "tier": "regulatory",
      "source_ids": [
        "s5"
      ],
      "why_material": "This is the enforcement moment — the refusal that prevents stale overwrites."
    },
    {
      "id": "c6",
      "text": "The deploy script's final output reports the number of changed code files checked and that each is covered by a committed lease matching its current contents.",
      "tier": "definition",
      "source_ids": [
        "s6"
      ],
      "why_material": "Shows the deploy gate produces a verifiable conformance report on every ship."
    },
    {
      "id": "c7",
      "text": "The law's conformance claims include that every changed code file in a deploy is covered by a committed lease and that a commit whose declared base hash no longer matches the file on disk is refused.",
      "tier": "definition",
      "source_ids": [
        "s7"
      ],
      "why_material": "These are the formal conditions the system enforces, not aspirations."
    },
    {
      "id": "c8",
      "text": "Every code file being shipped must be covered by a committed lease that recorded a start hash matching the file as the agent read it and a commit hash matching the file as it was written.",
      "tier": "definition",
      "source_ids": [
        "s2"
      ],
      "why_material": "Restates the full lease lifecycle — start hash on read, commit hash on write — as the deploy script defines it."
    }
  ],
  "type": "article",
  "updated": "2026-10-08T11:31:27.950Z",
  "version": 1,
  "hash": "38ccf3a10858d688038624c5b0e5ab1d437458190d3f74d729f0974c0b5ac326",
  "styling": {
    "scope": "shared",
    "how": "no value on the page is set by hand: each comes from this theme, and each theme value becomes the CSS variable named beside it. PATCH http://google-preview.miscsubjects.com/api/jarticles/theme changes them.",
    "widget_style": {
      "what": "every widget may carry style: {…}; these are the only keys it reads",
      "rotate": "degrees, a number",
      "offset_x": "pixels, a number",
      "offset_y": "pixels, a number",
      "pulse": "true to pulse"
    },
    "theme": {
      "color": {
        "page_bg": "#f5f5f7",
        "sheet_bg": "#ffffff",
        "ink": "#1d1d1f",
        "soft": "#424245",
        "muted": "#6e6e73",
        "dim": "#86868b",
        "line": "#d2d2d7",
        "accent": "#0071e3",
        "accent_soft": "rgba(0,113,227,0.08)",
        "link": "#0066cc",
        "selection": "rgba(0,113,227,0.18)",
        "widget_bg": "#f5f5f7",
        "widget_border": "#d2d2d7",
        "card_bg": "#ffffff",
        "code_bg": "#f5f5f7",
        "json_bg": "#161b19",
        "json_ink": "#e6e1d4",
        "json_key": "#7fd3c3",
        "json_string": "#e9c46a",
        "json_number": "#f4a261",
        "json_bool": "#c792ea",
        "json_null": "#928d7e",
        "json_punct": "#6b6759",
        "json_bar": "#0e1512",
        "kind_badge_bg": "#0e6e60",
        "kind_badge_ink": "#ffffff"
      },
      "color_dark": {
        "page_bg": "#000000",
        "sheet_bg": "#1d1d1f",
        "ink": "#f5f5f7",
        "soft": "#d2d2d7",
        "muted": "#a1a1a6",
        "dim": "#86868b",
        "line": "#424245",
        "accent": "#2997ff",
        "accent_soft": "rgba(41,151,255,0.12)",
        "link": "#2997ff",
        "selection": "rgba(41,151,255,0.25)",
        "widget_bg": "#2c2c2e",
        "widget_border": "#424245",
        "card_bg": "#1d1d1f",
        "code_bg": "#2c2c2e",
        "json_bg": "#0a0d0c",
        "json_ink": "#e6e1d4",
        "json_key": "#7fd3c3",
        "json_string": "#e9c46a",
        "json_number": "#f4a261",
        "json_bool": "#c792ea",
        "json_null": "#757062",
        "json_punct": "#5d665f",
        "json_bar": "#060807",
        "kind_badge_bg": "#4fc1ab",
        "kind_badge_ink": "#0b0f0d"
      },
      "font": {
        "display": "-apple-system,BlinkMacSystemFont,\"SF Pro Display\",\"SF Pro Text\",\"Helvetica Neue\",Helvetica,Arial,sans-serif",
        "body": "-apple-system,BlinkMacSystemFont,\"SF Pro Display\",\"SF Pro Text\",\"Helvetica Neue\",Helvetica,Arial,sans-serif",
        "mono": "ui-monospace,SFMono-Regular,\"SF Mono\",Menlo,Consolas,monospace",
        "google_fonts": ""
      },
      "size": {
        "body": "17px",
        "small": "17px",
        "eye": "17px",
        "lead": "17px",
        "h1": "52px",
        "h2": "34px",
        "h3": "22px",
        "byline": "17px",
        "h1_measure": "none",
        "code": "17px",
        "json": "17px",
        "widget_title": "17px"
      },
      "leading": {
        "body": "1.7",
        "head": "1.18",
        "lead": "1.5",
        "json": "1.6"
      },
      "weight": {
        "display": "700",
        "head": "700",
        "body": "400",
        "strong": "700",
        "eye": "700"
      },
      "tracking": {
        "eye": "0.14em",
        "display": "-0.03em",
        "body": "-0.006em",
        "badge": "0.08em"
      },
      "layout": {
        "sheet_width": "1000px",
        "text_width": "880px",
        "gutter": "16px",
        "sheet_padding": "56px 64px 64px",
        "sheet_padding_mobile": "24px 18px 40px",
        "sheet_margin": "28px auto 72px",
        "block_gap": "1.15em",
        "widget_gap": "28px",
        "grid_gap": "14px"
      },
      "border": {
        "sheet": "0px solid",
        "sheet_radius": "30px",
        "widget": "1px solid",
        "widget_radius": "24px",
        "card_radius": "24px",
        "badge_radius": "999px",
        "rule": "1px solid",
        "code_radius": "18px",
        "accent_bar": "3px"
      },
      "shadow": {
        "sheet": "0 1px 1px rgba(0,0,0,.02),0 6px 26px rgba(0,0,0,.05)",
        "widget": "none",
        "card_hover": "0 10px 28px -16px rgba(28,27,23,0.35)"
      },
      "motion": {
        "hover": "160ms ease"
      }
    }
  },
  "page": "http://google-preview.miscsubjects.com/a/coding-law",
  "json": "http://google-preview.miscsubjects.com/a/coding-law.json",
  "markdown": "http://google-preview.miscsubjects.com/a/coding-law.md",
  "theme": "http://google-preview.miscsubjects.com/article-theme.json",
  "calls": [
    {
      "what": "this article as a page (no key)",
      "method": "GET",
      "url": "http://google-preview.miscsubjects.com/a/coding-law",
      "headers": {}
    },
    {
      "what": "this article as its object (no key)",
      "method": "GET",
      "url": "http://google-preview.miscsubjects.com/a/coding-law.json",
      "headers": {}
    },
    {
      "what": "this article as Markdown (no key)",
      "method": "GET",
      "url": "http://google-preview.miscsubjects.com/a/coding-law.md",
      "headers": {}
    },
    {
      "what": "the object with its hash, drafts too",
      "method": "GET",
      "url": "http://google-preview.miscsubjects.com/api/jarticles/coding-law",
      "headers": {
        "x-sheets-key": "$(cat /Users/cyrusmassoumi/.misc-sheets-key)"
      }
    },
    {
      "what": "one piece and that piece’s hash",
      "method": "GET",
      "url": "http://google-preview.miscsubjects.com/api/jarticles/coding-law/at?path=facts",
      "headers": {
        "x-sheets-key": "$(cat /Users/cyrusmassoumi/.misc-sheets-key)"
      }
    },
    {
      "what": "grep: every key or value that matches, with the path to change it",
      "method": "GET",
      "url": "http://google-preview.miscsubjects.com/api/jarticles/coding-law/grep?q=owner",
      "headers": {
        "x-sheets-key": "$(cat /Users/cyrusmassoumi/.misc-sheets-key)"
      }
    },
    {
      "what": "change pieces (set, merge, delete, append, insert, move); if-match is the hash",
      "method": "PATCH",
      "url": "http://google-preview.miscsubjects.com/api/jarticles/coding-law",
      "headers": {
        "x-sheets-key": "$(cat /Users/cyrusmassoumi/.misc-sheets-key)",
        "content-type": "application/json",
        "if-match": "<hash from the read>"
      },
      "body": {
        "ops": [
          {
            "op": "set",
            "path": "facts.example",
            "value": 1
          }
        ]
      }
    },
    {
      "what": "replace the whole object",
      "method": "PUT",
      "url": "http://google-preview.miscsubjects.com/api/jarticles/coding-law",
      "headers": {
        "x-sheets-key": "$(cat /Users/cyrusmassoumi/.misc-sheets-key)",
        "content-type": "application/json",
        "if-match": "<hash>"
      },
      "body": {
        "slug": "coding-law",
        "title": "…"
      }
    },
    {
      "what": "fetch every source, hash what came back and check the quote is in it",
      "method": "POST",
      "url": "http://google-preview.miscsubjects.com/api/jarticles/coding-law/verify",
      "headers": {
        "x-sheets-key": "$(cat /Users/cyrusmassoumi/.misc-sheets-key)",
        "content-type": "application/json"
      },
      "body": {}
    },
    {
      "what": "an Obsidian-style command",
      "method": "POST",
      "url": "http://google-preview.miscsubjects.com/api/jarticles/cli",
      "headers": {
        "x-sheets-key": "$(cat /Users/cyrusmassoumi/.misc-sheets-key)",
        "content-type": "application/json"
      },
      "body": {
        "command": "backlinks",
        "file": "coding-law"
      }
    }
  ]
}