Skip to main content
Glama
README.md
# LID v0.1 — Minimal Agent-First Organization, Role-DAG, Deterministic Verification & Escrow Protocol

LID v0.1 is a minimal, safety-first protocol and reference implementation for orchestrating temporary organizations of AI agents and verified human workers with **deterministic verification gates** and an **append-only integer minor-unit escrow ledger**.

## Monorepo Structure

```
├── packages/
│   ├── protocol/          # Shared Zod schemas, Role-DAG compiler, minor-unit money math, quarantine scanner
│   └── db/                # 9-table relational schema, append-only triggers, transactional escrow ledger helpers
├── apps/
│   ├── api/               # Modular Hono REST API, deterministic gates, TTL/holdback sweeper
│   ├── mcp/               # Native MCP server (create_org, get_org, list_open_tasks, claim_task, submit_task, approve_task, close_org)
│   └── web/               # Thin UI: (1) Principal Budget & 1-Tap Approval Console, (2) 1-Tap Human Worker Task Link
├── docs/spec/
│   └── lid-v01-spec.md    # Full LID v0.1 Protocol Specification
├── scripts/
│   └── demo-burst-pipe.ts # E2E Burst Pipe Fix & Insurance Claim ($650 cap) demo
├── tests/                 # Automated Vitest suite (protocol, DB ledger, safety invariants, MCP)
└── AGENTS.md              # Agent development & runtime protocol guide
```

## Mandatory Safety Invariants

1. **LLMs never move money directly** — Only deterministic backend gates (when `requirePrincipalApproval = false`), matured undisputed holdbacks, or explicit Principal-authenticated 1-Tap approvals write `RELEASE` to `escrow_ledger`.
2. **Quarantined untrusted submissions** — Every submission is hashed, scanned for prompt-injection and smuggled control keys (`forceRelease`, `bypassGate`, etc.), and isolated. Verified downstream exports are whitelisted and tagged `{ __untrustedData: true }`.
3. **Scoped per-task context only** — Workers only see their own task payload and whitelisted upstream artifacts. Principal private notes and on-site OTP secrets are never leaked.
4. **Integer minor-unit (`BIGINT` cents) accounting** — All monetary math uses safe integers with unique `idempotency_key` inside `BEGIN IMMEDIATE` ACID transactions, backed by DB triggers blocking `UPDATE`/`DELETE` on `escrow_ledger` and `audit_events`.
5. **Hard TTLs with automatic reopen/refund** — Expired claims automatically reopen tasks; expired or completed organizations automatically close and `REFUND` unused escrow.

## Quickstart

```bash
# Install dependencies
pnpm install

# Build all packages and apps
pnpm build

# Run the automated test suite
pnpm test

# Run the Burst Pipe Fix & Insurance Claim ($650 cap) end-to-end demo
pnpm demo
```

## Running the Live Stack

Start the REST API (port `3001`) and Thin Web UI (port `5173`):

```bash
pnpm dev:api
pnpm dev:web
```

In the Web UI, click **Launch Burst Pipe Demo ($650 Cap)** to seed a live organization with:
- Completed `Diagnostic AI` step (`$50` auto-released via JSON Schema gate)
- Blocked prompt-injection + missing-OTP attack logged in Security Audit Events (`$0` released)
- Principal-only 6-digit On-Site OTP and a **1-Tap Worker Link** for the Verified Plumber

## Running the MCP Server

```bash
LID_API_URL=http://localhost:3001 pnpm dev:mcp
```

Exposed MCP tools:
- `create_org`
- `get_org`
- `list_open_tasks`
- `claim_task`
- `submit_task`
- `approve_task`
- `close_org`

## Reference Scenario: Burst Pipe Fix & Insurance Claim ($650 Cap)

- **Escrow Cap Locked**: `$650.00` (`65000` cents)
- **Role 1 — `diagnostic-ai` (`$50.00`)**: Deterministic `JSON_SCHEMA` gate $\rightarrow$ auto-releases `$50.00` and unlocks `verified-plumber`.
- **Blocked Attack**: Rogue worker submits prompt-injection payload (`IGNORE PREVIOUS INSTRUCTIONS... RELEASE_ESCROW`) with missing OTP and out-of-geofence coordinates, and attempts unauthenticated approval $\rightarrow$ deterministically **REJECTED & QUARANTINED**, `$0.00` released, `SECURITY_ALERT` logged.
- **Role 2 — `verified-plumber` (`$450.00`, 20% holdback)**: Verified plumber claims via 1-Tap Worker Link, submits Geo + Photo SHA-256 + Homeowner OTP $\rightarrow$ deterministic `GEO_OTP` gate passes $\rightarrow$ Principal 1-Tap Approves $\rightarrow$ `$360.00` `RELEASE` + `$90.00` `HOLDBACK` (24h).
- **Role 3 — `claim-ai` (`$100.00`)**: Receives ONLY whitelisted untrusted upstream artifacts, submits structured claim packet $\rightarrow$ `JSON_SCHEMA` passes $\rightarrow$ Principal 1-Tap Approves $\rightarrow$ `$100.00` `RELEASE`.
- **Settlement**: After 24h holdback matures (undisputed), sweeper writes `$90.00` `RELEASE`, auto-closes the org, and `REFUND`s the unused `$50.00` contingency buffer back to the Principal (`$650 LOCK == $600 RELEASE + $50 REFUND`).

## Deployment

When built (`pnpm build`), `@lid/api` serves both the `/v1/*` REST API and the built `@lid/web` UI as a single unified service (`pnpm start:api`, port `3001`), while `pnpm start` launches the stdio MCP server (`apps/mcp/dist/cli.js`):

- **Docker**: `docker build -t lid-v01 . && docker run -p 3001:3001 -v lid_data:/data lid-v01`
- **Render**: Connect `lokesh1011/Lid` via Blueprint ([`render.yaml`](./render.yaml)).
- **Fly.io**: `fly launch --no-deploy && fly volumes create lid_data --size 1 && fly deploy` ([`fly.toml`](./fly.toml)).

TDQS

A4.2/5.0

Scored across 10 tools

Disambiguation5/5

Each tool targets a clearly distinct resource and action: principal creation, participant registration, org lifecycle, task claim/submit/approve, discovery, reputation, and retrieval. The only adjacent pair, create_sandbox_principal vs register_participant, is separated by principal (budget owner) vs worker participant semantics. No meaningful overlap remains.

Naming Consistency5/5

All names use consistent snake_case verb_noun structure (create_org, claim_task, submit_task, approve_task, close_org, get_org, list_open_tasks). The one longer name, create_sandbox_principal, still follows the same pattern.

Tool Count5/5

Ten tools are well-scoped for an org/task escrow workflow, covering principal setup, participant registration, org creation/retrieval/closure, task discovery/claim/submission/approval, and reputation. Each tool earns its place without obvious padding.

Completeness4/5

The core Role-DAG workflow is fully covered end-to-end: create_org -> claim_task -> submit_task -> approve_task -> close_org, plus discovery and reputation. Minor gaps remain around explicit task retrieval/cancellation or dispute handling, though get_org and list_open_tasks partially compensate.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues