Verify Live State Before Reporting
Compatibility: Claude Code | Cursor | Codex CLI | Python 3 stdlib | Zero external dependencies
AI agents routinely declare "Done!" right after editing a file or guessing an endpoint works—without checking what actually exists on disk, what hash was written, whether a command exits cleanly, or whether a service responds. This skill inserts a deterministic 3-layer verification gate between execution and final reporting.
Architecture (3-Layer Guardrail)
- Layer 1 -- SOP (
SKILL.md): Strict 3-step Observe -> Diff -> Report protocol plus a Verified-vs-Assumption decision table. - Layer 2 -- Claim Manifest Contract (
schemas/,examples/): JSON Schema Draft 2020-12 (claim_manifest.schema.json), an offline fixture (live_artifact.txt), and ready-to-runsample_claims_fail.json/sample_claims_pass.jsontest manifests. - Layer 3 -- Hard Gate (
scripts/verify_live_state.py): Pure Python 3 stdlib verifier (pathlib,hashlib,urllib.request,subprocess,json) that probes real live state and exits1whenever any claim fails verification.
Mandatory 3-Step SOP: Observe -> Diff -> Report
An agent MUST complete all three steps before telling the user a task succeeded.
Step 1: Observe (Declare Concrete Claims)
Translate every completion statement into an explicit, falsifiable check in a JSON claim manifest conforming to schemas/claim_manifest.schema.json:
file_exists: Confirm a target file exists on disk.file_sha256: Confirm the exact SHA-256 checksum of a deployed or generated artifact.file_contains: Confirm a required string or regex pattern is actually present inside the saved file.command_exit: Run a live verification command and confirm its exact exit code (and optional stdout match).http_status: Issue a real HTTP request with a bounded timeout and confirm the returned status code.
Step 2: Diff (Run the Live Verification Gate)
Execute scripts/verify_live_state.py against the live environment—never against memory, prior turns, or edit intentions:
python scripts/verify_live_state.py --manifest examples/sample_claims_pass.json
If invoked from outside the skill directory, pass --base-dir to anchor relative file paths:
python scripts/verify_live_state.py --manifest examples/sample_claims_pass.json --base-dir .
For machine-readable output, add --json:
python scripts/verify_live_state.py --manifest examples/sample_claims_pass.json --json
Step 3: Report (Evidence-Bound Output Only)
- If
verify_live_state.pyexits0([VERIFIED]): Report completion and cite the exact passing claim IDs and observed values. - If
verify_live_state.pyexits1([BLOCKED]): Do NOT claim the task is done. Report[BLOCKED], list every failed claim with expected vs. observed state, fix the underlying gap, and re-run Step 2.
Verified Claim vs. Unverified Assumption
| Statement Type | Unverified Assumption (FORBIDDEN as "Done") | Verified Live State (REQUIRED) |
|---|---|---|
| Artifact creation | "I wrote release.txt in my previous tool call." | file_exists confirmed path exists on disk now. |
| File integrity | "The file matches the build output." | file_sha256 matched exact 64-char hex digest on disk. |
| Config / code patch | "I updated the version flag to v2.4.0." | file_contains matched exact target string in the saved file. |
| Script / test run | "The script should run cleanly after my edit." | command_exit executed the command live and observed expected exit code 0. |
| Service health | "The API endpoint is up and returning 200." | http_status issued a live HTTP request and observed HTTP 200. |
Hard-Fail Rules
- Zero Optimistic Reporting: Never write "Done", "Fixed", "Deployed", or "Verified" unless every claim in the manifest passed with exit code
0. - No Silent Fallbacks: Missing files, hash mismatches, connection errors, timeouts, and non-zero command exit codes MUST mark the claim
[FAIL]and fail the entire gate (exit 1). - No Stale Evidence: After any subsequent file edit or process restart, previous verification output is invalidated and the gate MUST be re-run.
- Explicit Path Resolution: Relative paths resolve strictly against
--base-dir(defaulting to current working directory). Missing target paths never pass silently.
CLI Usage
python scripts/verify_live_state.py --manifest <claims.json> [--base-dir <dir>] [--timeout <sec>] [--json]
| Flag | Required | Description |
|---|---|---|
--manifest | Yes | Path to the JSON claim manifest. |
--base-dir | No | Base directory for resolving relative claim file paths (defaults to current working directory). |
--timeout | No | Default timeout in seconds for HTTP and command checks (default: 5.0). |
--json | No | Emit machine-readable JSON report to stdout. |
Exit Codes:
0--[VERIFIED]: Every claim matched live state.1--[BLOCKED]: One or more claims failed verification, or the manifest was invalid.
60-Second Quick-Start
Run both bundled offline fixtures from the 01-verify-live-state directory:
# 1. Run the failing claim manifest (expected: BLOCKED, exit 1)
python scripts/verify_live_state.py --manifest examples/sample_claims_fail.json
# 2. Run the passing 4-check offline manifest (expected: VERIFIED, exit 0)
python scripts/verify_live_state.py --manifest examples/sample_claims_pass.json
# 3. Inspect machine-readable JSON output
python scripts/verify_live_state.py --manifest examples/sample_claims_fail.json --json
NEXT_STEPS
Once live-state verification is wired into your daily agent workflow, explore the rest of the 3-layer guardrail catalog (SKILL.md + JSON schemas + zero-dependency Python 3 stdlib hard gates)—covering AI video character locking, safe retention cleanup with rollback, multi-account browser isolation, and pre-write database import checks—at https://www.agensi.io/users/duylam and open utilities/updates on GitHub at https://github.com/duyplus2022.