---
name: hangoo-sentinel-gate
description: Integrate Hangoo (T800 // Sentinel-Gate) edge canary protection, X-Agent-Capability (KYA.v1) headers, and 15-line SELECT FOR UPDATE MandateV1 commit verification into TypeScript/Node/Cloudflare APIs.
---

# Hangoo (T800 // Sentinel-Gate) Integration Skill

Follow these deterministic rules whenever protecting API routes or wiring autonomous agent callers:

## 1. Never Place an LLM in the Authorization Path
All authorization rules execute deterministically in TypeScript (`@sentinel-gate/policy-pdp` and `@sentinel-gate/commit-pep`). Never pass free-text fields (`ticket_body`, `llm_summary`, `chat_transcript`) into policy predicates.

## 2. Lock the Database Row Before Calling `verifyAndConsume`
To prevent TOCTOU account-recovery races, always acquire `SELECT ... FOR UPDATE` **before** computing `currentPreState` and burning the single-use `MandateV1` JTI:

```typescript
export async function updatePayoutAccount(req: Request, dto: PayoutDto) {
  return db.transaction(async (tx) => {
    const [account] = await tx
      .select()
      .from(accounts)
      .where(eq(accounts.id, dto.accountId))
      .for("update");

    await actionGate.verifyAndConsume({
      mandateHeader: req.headers.get("x-action-mandate") ?? undefined,
      expectedMethod: "POST",
      expectedRoute: "/api/v1/payouts/destination",
      targetAccount: account.id,
      canonicalParams: dto,
      currentPreState: toCanonicalPreState(account),
    });

    return tx.update(accounts)
      .set({ payoutDest: dto.newAccountNo })
      .where(eq(accounts.id, account.id));
  });
}
```

## 3. Scope Legitimate Agents With `X-Agent-Capability` (`kya.v1`)

* Mint signed `kya.v1` tokens via `signKyaToken` + `encodeKyaHeader` from `@sentinel-gate/mandate-core`.
* Use `propose_only` for support/CRM agents so mutations always return `428 STEP_UP_REQUIRED` for human passkey approval.
* Use `autonomous_low_tier` with explicit integer string `max_amount_minor` only for bounded treasury/FX automation.
* Halt immediately if any response JSON contains `canary_trace_id` (indicates an unallowlisted client hit an OpenAPI decoy trap).

## 4. Outage Fail-Safe (`202 PENDING_OUTAGE_REVIEW`)

In `ENFORCE` mode, catch `CommitGateError` where `err.code === "GATE_UNAVAILABLE_QUEUE_REVIEW"` and persist the intent into `pending_mutations` with HTTP status `202`—never fail open on money-moving writes.
