agentleFS
thebharathkumarthebharathkumar/agent-flight-recorder/skills/audit-log/SKILL.md

audit-log

Skill0 starsChanged 4 months agoMITView on GitHub

Add a tamper-evident, hash-chained HMAC audit log to an agent

7 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use error-handling.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • MicrosoftSkill

    error-handling

    统一错误处理系统。在添加 API 端点、修改错误处理、添加前端 API 调用、编写错误相关测试时使用。

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Ensure AUDIT_CHAIN_KEY is set in the environment.

    line 32
  2. Very specific:

    If no anchor file is present, verification still runs but prints a prominent warning that truncation cannot be ruled out.

    line 50

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Audit Log

Gives an agent project an append-only audit trail where every entry is HMAC-chained to the previous one. Any modification, deletion, insertion, or reordering of past entries breaks the chain. A head anchor, written on every append by default, makes truncation from the tail detectable too.

Record format

One JSONL file per run (default audit/<run_id>.jsonl). Entry fields: seq, ts, run_id, actor, action, payload, prev_hash, entry_hash. The hash covers every field except entry_hash itself:

entry_hash = HMAC_SHA256(key, prev_hash + canonical_json(body))

Canonical JSON: sorted keys, compact separators, default=str. Genesis prev_hash is 64 zeros. Each append also rewrites <log>.head.json ({"count": N, "head_hash": "..."}), the anchor used to detect truncation.

Procedure

  1. Copy scripts/chained_log.py into the target project (for example <project>/audit/chained_log.py). It is stdlib-only, no dependencies.
  2. Ensure AUDIT_CHAIN_KEY is set in the environment. Never hardcode it. The script falls back to a built-in dev key with a loud stderr warning; tell the user that key is for local experiments only.
  3. Integrate at the points where the agent acts:
    • LangGraph: follow templates/langgraph_integration.py. Create one ChainedLogger per run before graph invocation, log one entry per node with actor=<node name>, action=<what happened>, and a payload containing the inputs and outputs worth auditing.
    • Plain Python: follow templates/plain_python.py. Log one entry per tool call or state change, including failures.
  4. Smoke test: run the agent once, confirm the JSONL file and the .head.json anchor exist and that the anchor count matches the line count.
  5. Prove integrity: python scripts/verify_chain.py audit/<run_id>.jsonl. It recomputes every hash and checks the anchor. Exit 0 means intact; exit 1 means a broken chain with a line-numbered diagnosis; exit 2 means an anchor mismatch. To demonstrate detection, run --demo-tamper on a COPY of the log and show the failure output.
  6. If no anchor file is present, verification still runs but prints a prominent warning that truncation cannot be ruled out; it never passes silently. Use --require-anchor to turn that into a hard failure.
  7. Explain the trust model to the user (below). Do not overclaim.

Trust model

Detected: any edit to a logged entry, deleted or inserted entries, reordering, and truncation from the tail (via the head anchor). Not detected: an attacker who has both write access to the log and the HMAC key can rebuild the whole chain. Keep the key out of the repo, and for strong truncation protection store the head anchor (or just its head_hash) somewhere log writers cannot touch, such as a CI artifact or a separate store.

Files

  • scripts/chained_log.py: ChainedLogger class, append(), head anchor.
  • scripts/verify_chain.py: CLI verifier and importable verify(). Flags: --key-env, --require-anchor, --demo-tamper.
  • templates/langgraph_integration.py: per-node logging in a LangGraph app.
  • templates/plain_python.py: logging around plain tool calls.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.