# AGENT-GUIDE: Cybernethicc License Hub integration

> Template for AI coding agents (Claude Code, Cursor, Copilot and similar).
> Copy this file into your repository (or paste it into CLAUDE.md / AGENTS.md),
> fill in the three values under "Project values", and ask your agent to
> "integrate License Hub following AGENT-GUIDE.md".
>
> Full docs: https://cybernethicc.com/docs/license-hub

## Project values (fill these in)

- VENDOR_ID: `<your vendor id, from Portal > Security > License Hub > Integrate>`
- PRODUCT_ID: `<the product id you created in License Hub, e.g. acme-pos>`
- Where the app stores data on the machine: `<path or storage mechanism>`

## What the agent must build

1. **Activation (first start).** If no license token is stored, ask the user
   for the activation code (format `CYB-XXXXX-XXXXX-XXXXX-XXXXX`) and call
   `activate(code, fingerprint, { version })`. Store `license_token`. A code
   works once; on failure show the server's message and let the user retry
   with a new code.
2. **Offline verification (every start).** Call
   `verifyLicense(token, { fingerprint, vendor: VENDOR_ID, lastCheckinAt })`.
   - `state === "ok"`: run normally.
   - `state === "grace"`: run normally, show a non-blocking notice that the
     license could not be confirmed online (days left: `graceDaysLeft`).
   - `state === "expired"`, or verification throws: limit the app (read-only
     mode or a lock screen with a field for a new activation code). Never
     delete the user's data.
   - Also check `claims.product === PRODUCT_ID`.
3. **Daily check-in.** About once every 24 hours while the app runs (and at
   start when the last one is older than that), call
   `checkin(claims, fingerprint, { version })`.
   - Always replace the stored token with `license_token` when one is
     returned, and store the time of the successful check-in (`lastCheckinAt`).
   - `status` other than `active` (`suspended`, `revoked`, `expired`): limit
     the app as above and show the status.
   - `fingerprint_mismatch` (HTTP 409): the license is bound to another
     machine. Ask the user to contact their vendor to move it.
   - Network errors: do nothing; the grace period covers outages.
4. **Entitlements.** Gate features with `hasModule(claims, "<module>")` and
   numeric limits with `claims.limits`. Branding may only be replaced when
   `claims.white_label` is true; extra hostnames only from
   `claims.custom_domains`. Never read these from a local setting.

## Machine fingerprint

Use a value that is stable across restarts and updates but differs between
machines, for example a hash of the OS machine id plus the install path. Do not
use the MAC address alone, a random value regenerated at start, or anything
the user can edit in a config file. Hash it (SHA-256) before sending.

## Rules (do not break these)

- Never hard-code or log the activation code, the token or `checkin_secret`.
- Never skip verification, cache "valid" as a boolean, or trust a token that
  failed `verifyLicense`. The token is the only source of entitlements.
- Always pass `vendor: VENDOR_ID`, so a license issued by another vendor is
  refused.
- Do not call check-in more than a few times a day; it is not a per-request
  check. Verification is offline and costs nothing.
- Keep the user's data readable when the license is limited.

## SDK

TypeScript / Node 18+: `@cybernethicc/license-sdk`

```ts
import { activate, verifyLicense, checkin, hasModule } from "@cybernethicc/license-sdk";

const VENDOR_ID = "<your vendor id>";

// first start
const { license_token } = await activate(code, fingerprint, { version: APP_VERSION });
store.saveToken(license_token);

// every start
const { claims, state, graceDaysLeft } = await verifyLicense(store.loadToken(), {
  fingerprint,
  vendor: VENDOR_ID,
  lastCheckinAt: store.loadLastCheckin(),
});

// once a day
const r = await checkin(claims, fingerprint, { version: APP_VERSION });
if (r.license_token) {
  store.saveToken(r.license_token);
  store.saveLastCheckin(new Date());
}
```

Rust: crate `cyb-portal-license` (see the Rust SDK section of the docs).

Other languages: the HTTP API (activate, JWKS, signed check-in) is documented
at https://cybernethicc.com/docs/license-hub.

## Done when

- [ ] First start asks for an activation code and stores the token.
- [ ] Every start verifies offline with VENDOR_ID and the fingerprint.
- [ ] Check-in runs about daily, replaces the token, stores the time.
- [ ] Suspended, revoked, expired and fingerprint_mismatch each limit the app
      with a clear message, and the user's data stays readable.
- [ ] Features and limits come only from the token's claims.
- [ ] Tests cover: valid token, wrong vendor, wrong fingerprint, expired
      token, grace state, check-in returning suspended.
