Skip to content
Projects
Demonstration application

agent-approval-console

A human-in-the-loop approval gate for side-effecting actions proposed by AI agents, with a hash-chained, tamper-evident audit trail.

Status
Demonstration application. Demo roles stand in for authentication; the executor is simulated and calls nothing; state is in memory.
Authorship
"Implemented with AI coding agents (Claude Code)," in the repository's own words: an independent demonstration application written from scratch, with all data synthetic.
Stack
Next.js (App Router) · TypeScript (strict) · Tailwind CSS · Vitest · Playwright
Demonstrates
Policy engine with rules as data · Explicit proposal state machine · Separation of duties and two distinct approvers · Idempotent execution under concurrent requests · SHA-256 hash-chained audit log with verification
Verified
130 Vitest unit and API-handler tests and 56 Playwright end-to-end tests pass; lint, type check and production build are clean. Observed at commit 8c5344a7c690d6ab32e165777cc37547127f608e.
Commands run
npm ci
npm run lint
npm run typecheck
npx vitest run
npm run build
E2E_SKIP_BUILD=1 npx playwright test
Repository
github.com/Donovanfitch-dev/agent-approval-console

Engineering problem

An agent that can only talk is easy to supervise. An agent that can act, by moving money, sending mail or changing records, needs a control point between what the model decided and what the system did. The failure modes without one are specific:

  • A hallucinated refund amount that nobody sees until the ledger is wrong
  • A double click or a retry that pays twice
  • An agent approving its own proposal
  • An approval given for one payload and silently applied to another
  • Afterwards, no trustworthy answer to who allowed it and on what basis

Representative solution

The console separates five steps, each with its own guarantee: propose, evaluate, approve, execute and audit. The scenario is the support desk of a fictional outdoor-gear retailer, where simulated support agents propose refunds, account credits, customer replies and shipping-address changes. A risk policy decides what may proceed on its own, what needs one approval, what needs two distinct approvers, and what is denied outright. Nothing executes until it is approved, and every step, including refused attempts, is written to a hash-chained log.

All of the rules live in a framework-free domain core, src/domain/, which imports nothing but Node's crypto module. The Next.js routes and pages are thin glue over it.

Architecture

Route handlers receive a proposal, the service validates it and checks its idempotency key, the policy engine evaluates it, and the repository commits the proposal and its audit entries atomically. Reviewers' decisions and the execute call go through the same service. Execution claims the proposal with a compare-and-set on its version before the executor runs, so concurrent callers cannot both execute it.

The proposal lifecycle is an explicit state machine: proposed, pending_approval, approved, executing, then executed or failed, plus rejected and expired. Illegal transitions throw, and stale pending proposals expire against an injectable clock.

  • app/ and components/

    App Router pages and JSON route handlers

    Pages

    • approval queue
    • proposal detail
    • audit log

    Route handlers

    • /api/proposals
    • /api/proposals/:id/decision
    • /api/proposals/:id/execute
    • /api/audit
    • /api/simulate
  • server/

    Thin Next.js glue: the in-memory store, demo role handling, HTTP helpers

  • domain/

    Framework-free; depends on nothing but Node crypto

    • policy engine
    • state machine
    • approval service
    • validation
    • hash-chained audit log
    • repository port
  • Not built

    Conceptual only; the demonstration uses labelled stand-ins

    • authentication
    • persistent database
    • real executors
    • external anchoring of the audit head
The four source layers and what each holds. Dependencies run one way, into the domain core.

Core components

  • Policy engine (policy.ts, policy-config.ts).Rules are plain data. The outcome is auto_approve, needs_approval, needs_two_approvals or deny, each with a reason code and a message. The strictest matching rule wins, and no matching rule fails closed.
  • State machine (state-machine.ts).Every transition is checked against the table, and an illegal transition throws.
  • ApprovalService (service.ts).Submission, decisions, edit-then-approve, expiry and execution, with separation of duties: the proposer cannot approve, and one reviewer cannot supply both approvals.
  • Validation (validation.ts, payloads.ts).Custom validators, no schema library, returning every problem with a precise path.
  • Audit log (audit.ts).Append-only entries chained with SHA-256, and verifyChain(), which reports the first entry that does not match.
  • Repository port (repository.ts, memory-repository.ts).An in-memory implementation with atomic commit and optimistic concurrency, and a documented mapping to Postgres that is not built.

Engineering decisions

  • Policy as data, not code.Rules can be reviewed in a diff, validated at load and stored without touching the engine, and the policy version is stamped on every decision and audit entry. The cost is a deliberately small expression language.
  • Idempotency in three layers.Submission returns the original proposal for a repeated key with the same content and a 409 for different content; execution claims with a compare-and-set so exactly one of N concurrent callers wins; and the executor receives the idempotency key so a downstream API could deduplicate. The third layer is only simulated here.
  • Edit-then-approve re-evaluates policy.A reviewer who edits a payload is authoring a new proposal. The edit is re-run through policy, earlier approvals of the old payload stop counting, and identifying fields are locked so an edit cannot retarget the action.
  • Approval and execution are separate steps.Approval never runs the side effect. Keeping decided apart from done is what makes retries and failure recording well defined.

Tradeoffs

  • Hash chain versus a write-once store.The chain makes edits, deletions and reordering in the middle of the log detectable at no infrastructure cost. It does not stop someone with write access from truncating the tail or rewriting the whole chain consistently; that needs the head hash anchored somewhere the writer cannot alter. It is tamper evidence, not tamper prevention.
  • A framework-free core.The rules are testable in milliseconds with a manual clock and would survive a framework change, at the price of a little duplication at the route boundary.
  • Keyword rules for message content.The customer-reply rules are regular-expression lists. They demonstrate rules as data; they are not content moderation and are easy to evade.

Verified functionality

Marked implemented and tested in the repository's status table, and exercised by the suites below:

  • Proposal validation, the risk policy engine, the state machine, decisions, edit-then-approve and expiry
  • Idempotent execution with failure recording and retry, including concurrent calls
  • The hash-chained audit log, verifyChain() and tamper detection
  • Route handlers: 401 without a role, 403 for an agent on decide and execute (and the refusal is audited), 415 for non-JSON bodies, 413 above 64 KiB, 422 for fields that do not belong to the decision
  • UI flows end to end in Chromium, keyboard-only flows, layout at 375px and 320px, and axe checks on every page in light and dark at mobile and desktop widths with no serious or critical violations

Demonstration

One proposal, driven through the console's real interface. An agent submits a $300.00 refund through the API; policy requires two distinct approvals because it exceeds $250.00; Reviewer A and Reviewer B each approve; the simulated executor runs once; and the audit log verifies its hash chain, then fails verification after a deliberate out-of-band edit.

What is simulated is labelled in the application itself and in every frame. The role picker is a stand-in for authentication: an unverified cookie, as the banner at the top of each screen says. The agent is a template and seeded generator with no language model. The executor records a receipt in memory and calls no external system. The tamper control exists only to show verification catching an edit.

The frames were captured by a script that builds the public repository at the cited commit, starts it locally with its own demo controls enabled, and drives the interface with Playwright. Timestamps in the frames are the capture time.

The approval queue. A banner reads that the role picker is a stand-in for real authentication. The newest proposal, PR-1013, a $300.00 refund, is pending approval and marked high risk, two approvals.
The queue, acting as Reviewer A. The agent's $300.00 refund arrives as PR-1013, pending and flagged for two approvals.
Proposal PR-1013. The policy explanation shows outcome high risk, two approvals, with two reasons and their machine-readable codes: REFUND_OVER_DUAL_APPROVAL_THRESHOLD and REFUND_OVER_APPROVAL_THRESHOLD. Approvals on the current payload: 0 of 2.
Policy assessment. Each reason carries a message and a machine-readable code, and the agent's rationale is shown as a claim to check, not as evidence.
PR-1013 after approvals from reviewer-a and reviewer-b on payload revision 0. The timeline reads: fully approved by reviewer-a and reviewer-b. An Execute (simulated) button is available.
Two distinct reviewers approve the same payload revision. The same reviewer approving twice is refused by the server.
PR-1013 executed. The execution panel shows attempts: 1, and a receipt for a simulated refund of $300.00 to order ORD-777002, marked simulated; no real system was called. The timeline lists execution started and execution succeeded with audit entry numbers.
Simulated execution. One attempt, one receipt, and the receipt says no real system was called.
The audit log page. Hash chain verified: valid. The newest entries are the execution and approvals for PR-1013, each with its hash.
The append-only audit log. Each entry stores the SHA-256 hash of the entry before it, and the chain verifies.
The audit log after the demo tamper control altered a stored entry. Hash chain verification failed: first inconsistency at entry 25, entry contents do not match its stored hash. Later entries are marked unverified.
After a simulated out-of-band edit, verification fails at the altered entry and everything after it is marked unverified.

Reproduce it

git clone https://github.com/Donovanfitch-dev/agent-approval-console.git && cd agent-approval-console
git checkout 8c5344a
npm ci && npm run build
ENABLE_DEMO_CONTROLS=1 npm start
# then follow the README's guided tour at http://localhost:3000

Failure modes and limitations

  • The demo role is not security.Anyone can claim any role, from a header or a cookie. The approval rules are enforced, but against an identity the client chooses.
  • In-memory state.Everything lives in one Node process. A restart loses all state and re-seeds; two instances would each keep their own store.
  • A crash mid-execution leaves a proposal in executing.A real system needs a reconciliation job that resolves such claims with the idempotency key.
  • A proposer-supplied field is trusted.The address-change policy trusts the agent-reported shipment status; a real policy would read it from the order system.
  • No rate limiting or request signing.CSRF is only partly addressed, by requiring a JSON content type and a SameSite=Lax cookie, and a caller with the agent role can add refusal entries to the audit log by repeating forbidden calls.
  • Integrity, not completeness.The chain proves that stored entries were not altered; it cannot prove nothing was left out.
  • Accessibility is automated only.Axe and targeted keyboard tests; no screen-reader, real-device or user testing, and no conformance claim.

Testing and validation

On 2026-11-10, against commit 8c5344a: lint and type check exited cleanly; Vitest reported 130 passed in 8 files (the domain core plus 18 tests that call the real route handlers with NextRequest objects); the production build succeeded; and Playwright reported 56 passed in Chromium against that build. The repository's GitHub Actions workflow concluded success on the same commit.

  • Concurrency.Concurrent execution is tested in process. There is no multi-process or real HTTP interleaving test.
  • Not covered.Browsers other than Chromium, assistive technology, real touch devices, visual regression, load and security testing, and the real HTTP server stack for the API tests.

Source and documentation