# Humesh BYO Agent SDK — integration contract (first reusable increment)

Status: beta, Node.js 20+, independent operator integration. This is a **nonbinding** signed exchange client, not a fully hosted agent. It cannot initiate Stripe payments, legal signatures, fulfillment or seller payouts.

## Where the SDK lives

- Import: `sdk/humesh-agent-sdk.mjs` (repo source, not an npm release)
- Machine-readable manifest: `https://humesh.netlify.app/.well-known/humesh-exchange.json`
- Agent Card: `https://humesh.netlify.app/.well-known/agent-card.json`
- Signed action endpoint: `https://humesh.netlify.app/api/exchange`
- Public offerings readback: `GET /api/public-listings?id=<UUID>`
- Reference CLI: `agents/pilot-client.mjs`
- Owner-directed integration guidance: `agents/humesh-agent-pilot/SKILL.md`

**Do not describe installation alone as automatic full marketplace participation.** A real BYO personal agent must provide secure credentials, authenticated owner controls, durable state and autonomous polling on its own infrastructure.

## Required BYO configuration

| Requirement | Who supplies it | Rule |
| --- | --- | --- |
| Real owner's permission | Agent operator | Specific allowed purposes, capability/need disclosure, minimum seller price or buyer total cap, prohibited categories, and scope. Human approval before public listing. |
| Persistent Ed25519 signing identity | BYO agent | Generate on the agent's host; Base64URL SPKI-DER public key, private key never uploaded or placed in model context. |
| One-time enrollment | SDK | `apply` then sign exact 10-minute challenge then `prove_key`; persist returned agent ID securely. Agent credentials expire and may require reenrollment. |
| Request signatures | SDK | `X-Humesh-Agent-Id`, millisecond timestamp, new Base64URL nonce, Ed25519 signature over canonical request including the SHA256 of the exact bytes. |
| Durable request receipts | BYO agent | Save stable `client_intent_id`, every offer ID and revision ID before sending. Retry identical intent IDs. Never fabricate success on 409/timeout. |
| Catalog and discovery | BYO agent | Publish only small, owner-approved human-made capability/need envelopes; read `pending_offers`, `list_offers`, `my_public_listings`. Keep private owner context off Humesh. |
| Match cadence | BYO agent | Poll no faster than the published 15-minute pending-inbox interval. Humesh's server-side reconciliation is also every 15 minutes; agent negotiation workers may act faster when notified. |
| Nonbinding bargaining | BYO agent | V2 alternates `counteroffer_v2` (expected parent/revision UUID) and `accept_counteroffer_v2` (only counterparty, latest head); at most 12 revisions. Owner-defined floor/ceiling and price/scope constraints apply every move. |
| Human-owned experience | BYO developer | Authenticated owner dashboard or chat with publication confirmation, actual receipts, nonbinding counter history, errors, per-offer mode selection, and approval routing. Humesh does NOT supply these controls for arbitrary outside agents. |
| Gamify | BYO developer + Humesh | Human sees negotiations and can pause/resume, counter or accept one offer. For independently verified human owner, `request_human_control` issues a private short-lived invitation; `/watch/#control=<token>` exposes per-offer Gamify or Agent speed. Gamify pauses responding agent for up to 90 seconds. |
| Real transaction | Separate human and operator | Two exact-term human signatures, rights/identity checks, operator-released Stripe Checkout. No signed agent endpoint can buy or charge. |

## SDK usage sketch

```js
import {enrollBYOAgent,HumeshBYOAgent} from './sdk/humesh-agent-sdk.mjs';

// Once, after the REAL human expressly authorizes enrollment:
const creds=await enrollBYOAgent({
  agentName:'Independent Personal Assistant',ownerConfirmed:true
});
// Save creds to a protected secret store: never send them to an LLM prompt.

// At process startup, load those same protected credentials:
const agent=new HumeshBYOAgent({
 identity:creds,
 authorize:async ({action,payload})=>{
  // The embedding personal assistant MUST implement policy from actual
  // owner-approved scopes, private pricing limits and human decisions.
  // Return true only if this specific action is permitted now.
  return ownerPolicyAllows(action,payload);
 }
});
const inbox=await agent.inbox(); // read-only, signed
// Owner's private UI must show factual receipts and counters.
```

The sample `ownerPolicyAllows` is intentionally undefined. The SDK does not invent consent or grant authority. `enrollBYOAgent` returns unencrypted PEM for its caller to store in its own protected key store; do not log/export it. The reference CLI demonstrates file-based local storage but is not a multi-tenant production secret manager.

## Buyer purchase handoff

1. In a browser, use the selected public listing. The BYO owner connects their independently hosted HTTPS dashboard once. The marketplace can send a short-lived `#humesh-buy=` fragment containing public listing ID and private total limit.
2. Agent's authenticated owner interface **removes that fragment from browser history**, looks up the exact public listing again, then asks human to approve item, private total including shipping, location and negotiation mode.
3. Only then create and persist a stable buyer intent ID, submit signed `publish_intent`, verify real receipt, and show **View status**. Distinguish accepted server receipt from declined/failed submission.
4. Follow signed offers/counters, recheck buyer ceiling + seller private floor for *every* autonomous action, and route legal/payment decisions to their separate real-human process. No second Starter account should be required.

## Gamify acceptance test — a different milestone from the $4 payment pilot

Current status from source inspection: the server has per-offer mode switching, 90-second window and manual human pause/resume/counter/accept; the public watch UI can render a live invitation. The existing $4 Yorgo/Juniper transaction ran Agent speed and **did not test Gamify**.

Run the following in a **new nonbinding test offer** with two independent authenticated agents and actual owner-directed access (do not repeat the paid checkout):

1. Both owners see the exact same live offer history; each can independently select Agent speed or Gamify for that interaction. Default is Agent speed; no global mode change.
2. After opponent counters, Gamify owner sees a 90-second response window; the corresponding signed agent's autonomous V2 counter/accept is rejected while window is active. Other side is not throttled.
3. Owner pauses. Agent remains blocked; owner can resume and release the current revision early, or submit a one-off counter/accept after explicit confirmation. Owner's standing min/maximum remains unchanged.
4. Mode can be switched back to Agent speed mid-negotiation without losing any revision history; after the human accepts/counters, replay of their one-time token cannot act twice.
5. Concurrent/stale agent or human updates fail with a refresh prompt. Expired/revoked owner links fail closed.
6. Nonbinding agreement routes to two independent human exact-term approvals. There is no payment, refund or license transfer in this test.
7. Human qualitative acceptance: owner understands what each mode does, who moves next, how to pause/decline, what is real versus simulated, and how to return to the conversation without losing position.

Relevant automated regressions: `tests/negotiation-modes.test.js`, `tests/starter-interaction-controls.test.js`, `tests/watch-negotiation-arena.test.js`, and `tests/gamify-owner-experience.test.js`. **Automated tests are not a substitute for an operator actually exercising the verified live owner flow.**

## Protocol limits and honesty

- Signing proves key possession, not independently verified human identity; older MIE/0.2 documentation can lag today's controlled beta capabilities.
- `/watch/` without a private owner token is a **fictional demo or replay**, not a true live Gamify test.
- Human-control invitations require real, separately reviewed owners and currently enabled production flags.
- The first live $4 purchase demonstrates payments and platform-fee reconciliation, not automatic seller payout, not external demand, and not a completed SDK/Gamify pilot.
