From 71e89bdfd83ddd3a4e1f3114ba8d47ad06bf0a07 Mon Sep 17 00:00:00 2001 From: pextacy Date: Sat, 20 Jun 2026 01:19:22 +0300 Subject: [PATCH] feat(lepton): attribution package (RFB 6.01) + creator-dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds @settlekit/attribution — reuse-detection, weighted provenance lineage, and HMAC-signed proofs-of-citation — wired live into the rsshub-citation-toll sidecar (POST /attribution/{detect,proof,verify}) and persisted via PgLineageStore/PgProofStore over new lepton_lineage_edges + lepton_citation_proofs tables. Adds apps/creator-dashboard — a Next.js earnings view in the Statement greenbar-ledger design system, driven by real domain logic (createSource + computeRoyaltyDistribution + detectReuse, not mocks). Statement / Sources / Payouts / Reuse & proofs (interactive) / Wallet. next build green. Also bundles in-progress settlement hardening: settlement-core idempotency concurrency, api env validation, bundles + contracts/worker tweaks. Verified: 943 vitest tests, 27 Foundry tests, next build all green. Co-Authored-By: Claude Opus 4.8 --- LEPTON_PRODUCTION_PLAN.md | 4 + apps/api/package.json | 2 +- apps/api/src/config/env.ts | 60 +- apps/api/src/context.ts | 21 +- apps/api/test/env.test.ts | 29 + apps/cli/package.json | 2 +- apps/creator-dashboard/.gitignore | 1 + .../creator-dashboard/app/api/detect/route.ts | 12 + .../app/attribution/page.tsx | 75 ++ apps/creator-dashboard/app/globals.css | 754 ++++++++++++++++++ apps/creator-dashboard/app/layout.tsx | 38 + apps/creator-dashboard/app/not-found.tsx | 16 + apps/creator-dashboard/app/page.tsx | 53 ++ apps/creator-dashboard/app/payouts/page.tsx | 43 + .../app/settings/wallet/page.tsx | 50 ++ apps/creator-dashboard/app/sources/page.tsx | 63 ++ .../components/ReuseDetector.tsx | 116 +++ apps/creator-dashboard/components/Sidebar.tsx | 42 + apps/creator-dashboard/components/ui.tsx | 183 +++++ apps/creator-dashboard/lib/data.ts | 391 +++++++++ apps/creator-dashboard/lib/format.ts | 45 ++ apps/creator-dashboard/lib/nav.ts | 31 + apps/creator-dashboard/next-env.d.ts | 5 + apps/creator-dashboard/next.config.mjs | 18 + apps/creator-dashboard/package.json | 29 + apps/creator-dashboard/tsconfig.json | 24 + apps/creator-dashboard/vercel.json | 6 + apps/examples/package.json | 2 +- apps/worker/package.json | 1 + apps/worker/src/config.ts | 10 + contracts/src/LeptonStreamSettlement.sol | 5 + contracts/test/LeptonStreamSettlement.t.sol | 12 + package.json | 1 + packages/attribution/package.json | 26 + packages/attribution/src/index.ts | 5 + packages/attribution/src/lineage-graph.ts | 179 +++++ packages/attribution/src/proof.ts | 107 +++ packages/attribution/src/reuse-detector.ts | 96 +++ packages/attribution/src/store.ts | 93 +++ packages/attribution/src/types.ts | 138 ++++ .../attribution/test/lineage-graph.test.ts | 107 +++ packages/attribution/test/proof.test.ts | 80 ++ .../attribution/test/reuse-detector.test.ts | 71 ++ packages/attribution/test/store.test.ts | 42 + packages/attribution/tsconfig.json | 11 + packages/bundles/src/bundle.ts | 14 +- packages/bundles/src/service.ts | 2 +- packages/bundles/test/service.test.ts | 20 +- packages/database/src/schema/index.ts | 4 + packages/database/src/schema/lepton.ts | 37 + packages/database/test/schema.test.ts | 2 + packages/persistence/package.json | 1 + packages/persistence/src/attribution-store.ts | 122 +++ packages/persistence/src/index.ts | 1 + .../src/lepton-settlement-store.ts | 34 + packages/persistence/tsconfig.json | 1 + .../settlement-core/src/circle-provider.ts | 2 +- .../settlement-core/src/gateway-provider.ts | 2 +- packages/settlement-core/src/idempotency.ts | 89 ++- .../settlement-core/src/local-provider.ts | 2 +- packages/settlement-core/src/types.ts | 16 + .../test/idempotency-concurrency.test.ts | 87 ++ pnpm-lock.yaml | 62 ++ .../rsshub-citation-toll/package.json | 1 + .../rsshub-citation-toll/src/attribution.ts | 103 +++ .../rsshub-citation-toll/src/config.ts | 3 + .../rsshub-citation-toll/src/sidecar.ts | 62 ++ .../test/attribution.test.ts | 102 +++ .../rsshub-citation-toll/tsconfig.json | 1 + 69 files changed, 3825 insertions(+), 44 deletions(-) create mode 100644 apps/api/test/env.test.ts create mode 100644 apps/creator-dashboard/.gitignore create mode 100644 apps/creator-dashboard/app/api/detect/route.ts create mode 100644 apps/creator-dashboard/app/attribution/page.tsx create mode 100644 apps/creator-dashboard/app/globals.css create mode 100644 apps/creator-dashboard/app/layout.tsx create mode 100644 apps/creator-dashboard/app/not-found.tsx create mode 100644 apps/creator-dashboard/app/page.tsx create mode 100644 apps/creator-dashboard/app/payouts/page.tsx create mode 100644 apps/creator-dashboard/app/settings/wallet/page.tsx create mode 100644 apps/creator-dashboard/app/sources/page.tsx create mode 100644 apps/creator-dashboard/components/ReuseDetector.tsx create mode 100644 apps/creator-dashboard/components/Sidebar.tsx create mode 100644 apps/creator-dashboard/components/ui.tsx create mode 100644 apps/creator-dashboard/lib/data.ts create mode 100644 apps/creator-dashboard/lib/format.ts create mode 100644 apps/creator-dashboard/lib/nav.ts create mode 100644 apps/creator-dashboard/next-env.d.ts create mode 100644 apps/creator-dashboard/next.config.mjs create mode 100644 apps/creator-dashboard/package.json create mode 100644 apps/creator-dashboard/tsconfig.json create mode 100644 apps/creator-dashboard/vercel.json create mode 100644 packages/attribution/package.json create mode 100644 packages/attribution/src/index.ts create mode 100644 packages/attribution/src/lineage-graph.ts create mode 100644 packages/attribution/src/proof.ts create mode 100644 packages/attribution/src/reuse-detector.ts create mode 100644 packages/attribution/src/store.ts create mode 100644 packages/attribution/src/types.ts create mode 100644 packages/attribution/test/lineage-graph.test.ts create mode 100644 packages/attribution/test/proof.test.ts create mode 100644 packages/attribution/test/reuse-detector.test.ts create mode 100644 packages/attribution/test/store.test.ts create mode 100644 packages/attribution/tsconfig.json create mode 100644 packages/persistence/src/attribution-store.ts create mode 100644 packages/settlement-core/test/idempotency-concurrency.test.ts create mode 100644 services/sidecars/rsshub-citation-toll/src/attribution.ts create mode 100644 services/sidecars/rsshub-citation-toll/test/attribution.test.ts diff --git a/LEPTON_PRODUCTION_PLAN.md b/LEPTON_PRODUCTION_PLAN.md index 77cc26b..5e9b114 100644 --- a/LEPTON_PRODUCTION_PLAN.md +++ b/LEPTON_PRODUCTION_PLAN.md @@ -30,6 +30,10 @@ Also done: **`services/sidecars/owncast-stream`** — per-second streaming settl Three creator-monetization patterns now share one settlement spine: **per-citation** (RSSHub), **per-listen** (Navidrome), **per-second** (Owncast). +Also done (Phase 3 — creator products): **`apps/creator-dashboard`** — a Next.js earnings view in the Statement greenbar-ledger design system (gradient-free, tabular-mono, credit/debit semantics). It is NOT mocked: `lib/data.ts` drives the real domain logic — sources built with `createSource`, every paid access run through `computeRoyaltyDistribution` (so a creator earns their author share *plus* the recursive cut of everything that cites them), and the attribution panel runs `detectReuse` + issues a real signed proof. Pages: **Statement** (lifetime/settled/pending + recent royalty lines), **Sources** (authored vs cited, recursive cut), **Payouts** (settlement sweeps), **Reuse & proofs** (interactive `/api/detect` + worked proof-of-citation), **Wallet**. `next build` green (9 routes); swap `lib/data.ts` for the Pg stores to go live. Public (no auth gate) so it doubles as the demo link. + +Also done (RFB 6.01): **`@settlekit/attribution`** — the reuse-detection / proof-of-citation layer the citation toll was designed around. A weighted provenance DAG (`LineageGraph` + `computeAttributionShares`, the citation split expressed as fractions any consumer can use), w-shingling reuse detection (`detectReuse`: does an agent's generated text get grounded in a known source?), and HMAC-signed, expiring, replay-protected proofs-of-citation (`issueCitationProof`/`verifyCitationProof`). Pure + fully tested (30 tests), persisted via `PgLineageStore`/`PgProofStore` over new `lepton_lineage_edges` + `lepton_citation_proofs` tables. Wired live into the **rsshub-citation-toll** sidecar: `POST /attribution/detect` quotes the toll owed for implicit reuse, `POST /attribution/proof` issues a presentable proof, `POST /attribution/verify` checks + consumes its nonce. This closes the loop from *explicit* fetch-tolls to *implicit* reuse-tolls at the agent boundary. + **Live-wiring seams done:** `settlementProviderFromEnv` (flip to Circle by `SETTLEMENT_PROVIDER=circle` + creds, no code change) is wired into every sidecar's `startSidecar`; the RSS sidecar has a `createFeedPoller` that fetches a live RSSHub JSON feed and ingests on an interval. Gateway settlement is wired via `configureSettlement` with a `GatewayTransferPort` (host supplies the signer). ## Phase 4 status (on-chain contracts — done, Foundry-tested) diff --git a/apps/api/package.json b/apps/api/package.json index f88b846..d76fc60 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -19,7 +19,7 @@ "build": "tsc -b", "dev": "node --import tsx/esm src/server.ts", "start": "node dist/server.js", - "typecheck": "tsc -b --noEmit", + "typecheck": "tsc -b", "test": "vitest run" }, "dependencies": { diff --git a/apps/api/src/config/env.ts b/apps/api/src/config/env.ts index 0179fc5..73bad80 100644 --- a/apps/api/src/config/env.ts +++ b/apps/api/src/config/env.ts @@ -386,6 +386,54 @@ function loadFileDelivery(env: Env): FileDeliveryConfig { * Build {@link ApiConfig} from a process environment. Defaults to `process.env` * but accepts an explicit env map for tests. */ +/** + * Dev-only fallback secrets. They keep `pnpm dev` zero-config, but are public + * (they live in this source file) so using them in production would let anyone + * forge sessions, webhook signatures, and license tokens. {@link assertProductionReady} + * rejects them when NODE_ENV=production. + */ +const DEV_DEFAULT_SECRETS = { + LICENSE_TOKEN_SECRET: "settlekit-dev-license-secret", + WEBHOOK_SIGNING_SECRET: "settlekit-dev-webhook-secret", + AUTH_COOKIE_SECRET: "settlekit-dev-auth-cookie-secret", +} as const; + +/** + * Fail closed in production: a misconfigured deploy must crash on boot with a + * clear message rather than silently running on in-memory data (lost on every + * restart) or with publicly-known signing secrets. Dev/test keep the + * convenient fallbacks. + */ +function assertProductionReady( + env: Env, + cfg: { + database: DatabaseConfig | null; + licenseTokenSecret: string; + webhookSigningSecret: string; + authCookieSecret: string; + }, +): void { + if (env.NODE_ENV !== "production") return; + const problems: string[] = []; + if (cfg.database === null) { + problems.push("DATABASE_URL must be set (in-memory stores lose all data on restart)"); + } + if (cfg.licenseTokenSecret === DEV_DEFAULT_SECRETS.LICENSE_TOKEN_SECRET) { + problems.push("LICENSE_TOKEN_SECRET must be set (the dev default is public and forgeable)"); + } + if (cfg.webhookSigningSecret === DEV_DEFAULT_SECRETS.WEBHOOK_SIGNING_SECRET) { + problems.push("WEBHOOK_SIGNING_SECRET must be set (the dev default is public and forgeable)"); + } + if (cfg.authCookieSecret === DEV_DEFAULT_SECRETS.AUTH_COOKIE_SECRET) { + problems.push("AUTH_COOKIE_SECRET must be set (the dev default is public and forgeable)"); + } + if (problems.length > 0) { + throw new Error( + `Refusing to boot in production with insecure configuration:\n - ${problems.join("\n - ")}`, + ); + } +} + export function loadConfig(env: Env = process.env): ApiConfig { const database = loadDatabase(env); const arc = loadArc(env); @@ -399,11 +447,17 @@ export function loadConfig(env: Env = process.env): ApiConfig { const email = loadEmail(env); const s3 = loadS3(env); + const licenseTokenSecret = optionalString(env, "LICENSE_TOKEN_SECRET", DEV_DEFAULT_SECRETS.LICENSE_TOKEN_SECRET); + const webhookSigningSecret = optionalString(env, "WEBHOOK_SIGNING_SECRET", DEV_DEFAULT_SECRETS.WEBHOOK_SIGNING_SECRET); + const authCookieSecret = optionalString(env, "AUTH_COOKIE_SECRET", DEV_DEFAULT_SECRETS.AUTH_COOKIE_SECRET); + + assertProductionReady(env, { database, licenseTokenSecret, webhookSigningSecret, authCookieSecret }); + return { port: intInRange(env, "PORT", 8787, 1, 65_535), - licenseTokenSecret: optionalString(env, "LICENSE_TOKEN_SECRET", "settlekit-dev-license-secret"), - webhookSigningSecret: optionalString(env, "WEBHOOK_SIGNING_SECRET", "settlekit-dev-webhook-secret"), - authCookieSecret: optionalString(env, "AUTH_COOKIE_SECRET", "settlekit-dev-auth-cookie-secret"), + licenseTokenSecret, + webhookSigningSecret, + authCookieSecret, fileDelivery: loadFileDelivery(env), ...(optionalRaw(env, "CCTP_IRIS_BASE_URL") ? { cctpIrisBaseUrl: optionalRaw(env, "CCTP_IRIS_BASE_URL") as string } diff --git a/apps/api/src/context.ts b/apps/api/src/context.ts index a968d8a..1b55263 100644 --- a/apps/api/src/context.ts +++ b/apps/api/src/context.ts @@ -292,17 +292,12 @@ export async function createContext(): Promise { const products = pick>(db, (d) => new PgProductStore(d), () => new InMemoryEntityStore()); - // Bundle validation needs a synchronous product-existence check, but Postgres - // lookups are async — so track known product ids in a set (primed at boot, - // updated on save) and gate bundle creation against it. - const knownProductIds = new Set(); - for (const p of await products.list()) knownProductIds.add(p.id); - const trackedProducts: EntityStore = { - async save(p) { const r = await products.save(p); knownProductIds.add(p.id); return r; }, - findById: (id) => products.findById(id), - list: (predicate) => products.list(predicate), - async delete(id) { const ok = await products.delete(id); if (ok) knownProductIds.delete(id); return ok; }, - }; + // Bundle validation checks product existence against the store directly (async). + // A previous process-local id cache went stale across instances under + // horizontal scaling, spuriously rejecting bundles whose products were created + // on another instance; querying the store is always consistent. + const productExists = async (productId: string): Promise => + (await products.findById(productId)) != null; const entitlementRepo = pick(db, (d) => new PgEntitlementRepository(d), () => new InMemoryEntitlementRepository()); const apiKeyStore = pick(db, (d) => new PgApiKeyStore(d), () => new InMemoryApiKeyStore()); @@ -398,7 +393,7 @@ export async function createContext(): Promise { entitlementRepo, entitlements: new EntitlementService(entitlementRepo), - products: trackedProducts, + products, prices, customers: pick>(db, (d) => new PgCustomerStore(d), () => new InMemoryEntityStore()), deliveryRuns: pick>(db, (d) => new PgDeliveryRunStore(d), () => new InMemoryEntityStore()), @@ -472,7 +467,7 @@ export async function createContext(): Promise { discordGrants, saas: new SaasService({ plans: planStore, seats: seatStore }), - bundles: new BundleService(bundleStore, (productId: string) => knownProductIds.has(productId)), + bundles: new BundleService(bundleStore, productExists), bundleStore, agentServices: new AgentServiceService({ services: agentServiceStore, diff --git a/apps/api/test/env.test.ts b/apps/api/test/env.test.ts new file mode 100644 index 0000000..6fc5e1d --- /dev/null +++ b/apps/api/test/env.test.ts @@ -0,0 +1,29 @@ +import { describe, expect, it } from "vitest"; +import { loadConfig } from "../src/config/env.js"; + +const prodSecrets = { + DATABASE_URL: "postgres://user:pass@localhost:5432/settlekit", + LICENSE_TOKEN_SECRET: "a-real-license-secret", + WEBHOOK_SIGNING_SECRET: "a-real-webhook-secret", + AUTH_COOKIE_SECRET: "a-real-auth-cookie-secret", +}; + +describe("loadConfig production fail-closed guard", () => { + it("boots with dev defaults when NODE_ENV is not production", () => { + expect(() => loadConfig({})).not.toThrow(); + }); + + it("refuses to boot in production without DATABASE_URL", () => { + expect(() => loadConfig({ NODE_ENV: "production" })).toThrow(/DATABASE_URL must be set/); + }); + + it("refuses to boot in production with dev-default signing secrets", () => { + expect(() => + loadConfig({ NODE_ENV: "production", DATABASE_URL: prodSecrets.DATABASE_URL }), + ).toThrow(/LICENSE_TOKEN_SECRET must be set/); + }); + + it("boots in production once DB and real secrets are supplied", () => { + expect(() => loadConfig({ NODE_ENV: "production", ...prodSecrets })).not.toThrow(); + }); +}); diff --git a/apps/cli/package.json b/apps/cli/package.json index ef37ede..e5a77ba 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -15,7 +15,7 @@ "scripts": { "build": "tsc -b", "dev": "node --import tsx/esm src/index.ts", - "typecheck": "tsc -b --noEmit", + "typecheck": "tsc -b", "clean": "rm -rf dist" }, "engines": { diff --git a/apps/creator-dashboard/.gitignore b/apps/creator-dashboard/.gitignore new file mode 100644 index 0000000..e985853 --- /dev/null +++ b/apps/creator-dashboard/.gitignore @@ -0,0 +1 @@ +.vercel diff --git a/apps/creator-dashboard/app/api/detect/route.ts b/apps/creator-dashboard/app/api/detect/route.ts new file mode 100644 index 0000000..53542cd --- /dev/null +++ b/apps/creator-dashboard/app/api/detect/route.ts @@ -0,0 +1,12 @@ +import { NextResponse } from "next/server"; +import { detectGroundingForText } from "@/lib/data"; + +// Run reuse detection over the demo source corpus. The same call the +// rsshub-citation-toll sidecar exposes at POST /attribution/detect. +export async function POST(request: Request) { + const body = (await request.json().catch(() => null)) as { text?: string } | null; + if (body === null || typeof body.text !== "string") { + return NextResponse.json({ error: "text required" }, { status: 400 }); + } + return NextResponse.json({ data: detectGroundingForText(body.text) }); +} diff --git a/apps/creator-dashboard/app/attribution/page.tsx b/apps/creator-dashboard/app/attribution/page.tsx new file mode 100644 index 0000000..56004c9 --- /dev/null +++ b/apps/creator-dashboard/app/attribution/page.tsx @@ -0,0 +1,75 @@ +import { Card, PageHeader } from "@/components/ui"; +import { ReuseDetector } from "@/components/ReuseDetector"; +import { getCreatorContext } from "@/lib/data"; +import { formatUsdc } from "@/lib/format"; + +export default function AttributionPage() { + const { attribution } = getCreatorContext(); + const { proof } = attribution; + + return ( + <> + + + + + + + +

+ An agent produced this answer: +

+
+ {attribution.answer} +
+ +
+
Grounded in
+
+ {attribution.matches.map((m) => ( + + {m.title} · {(m.score * 100).toFixed(0)}% + + ))} +
+
Toll owed
+
{formatUsdc(attribution.quoteUsdc)}
+
+
+ + +

+ After settling, the agent receives a signed, expiring, replay-protected token it presents downstream. + Anyone holding the secret can verify it without re-querying the chain. +

+
+
Agent
+
{proof.agent}
+
Access
+
{proof.accessId}
+
Sources
+
{proof.sourceIds.join(", ")}
+
Amount
+
{proof.amountUsdc ? formatUsdc(proof.amountUsdc) : "—"}
+
Expires
+
{proof.expiresAt ?? "never"}
+
Signature
+
+ {proof.signature} +
+
+
+ + ); +} diff --git a/apps/creator-dashboard/app/globals.css b/apps/creator-dashboard/app/globals.css new file mode 100644 index 0000000..4d2fbaa --- /dev/null +++ b/apps/creator-dashboard/app/globals.css @@ -0,0 +1,754 @@ +:root { + /* STATEMENT — greenbar ledger palette (see @settlekit/ui) */ + --bg: #ebede4; + --bg-panel: #f3f4ec; + --bg-elevated: #dde3d1; + --border: #cdd3c5; + --border-strong: #b4bca9; + --text: #18211c; + --text-muted: #45524b; + --text-dim: #79847c; + --accent: #1e40a2; + --accent-hover: #16306f; + --accent-soft: rgba(30, 64, 162, 0.1); + --good: #2c6e49; + --good-soft: rgba(44, 110, 73, 0.12); + --warn: #9a6a18; + --warn-soft: rgba(154, 106, 24, 0.12); + --bad: #a33a2b; + --bad-soft: rgba(163, 58, 43, 0.1); + --radius: 4px; + --radius-sm: 3px; + --font-sans: var(--font-archivo), "Archivo", system-ui, -apple-system, + "Segoe UI", Roboto, sans-serif; + --font-mono: var(--font-mono-plex), "IBM Plex Mono", ui-monospace, "SF Mono", + Menlo, Consolas, monospace; +} + +* { + box-sizing: border-box; +} + +html, +body { + margin: 0; + padding: 0; + background: var(--bg); + color: var(--text); + font-family: var(--font-sans); + font-size: 14px; + line-height: 1.5; + -webkit-font-smoothing: antialiased; +} + +a { + color: inherit; + text-decoration: none; +} + +code { + font-family: var(--font-mono); + font-size: 0.85em; + background: var(--bg-elevated); + padding: 1px 5px; + border-radius: 4px; +} + +/* ---------- App shell ---------- */ +.app-shell { + display: grid; + grid-template-columns: 248px 1fr; + min-height: 100vh; +} + +.sidebar { + background: var(--bg-panel); + border-right: 1px solid var(--border); + display: flex; + flex-direction: column; + position: sticky; + top: 0; + height: 100vh; + overflow-y: auto; +} + +.sidebar-brand { + display: flex; + align-items: center; + gap: 10px; + font-weight: 700; + font-size: 16px; + padding: 18px 20px; + border-bottom: 1px solid var(--border); +} + +.sidebar-logo { + color: var(--accent); +} + +.sidebar-nav { + padding: 12px 12px 24px; + flex: 1; +} + +.nav-group { + margin-bottom: 18px; +} + +.nav-group-title { + text-transform: uppercase; + letter-spacing: 0.06em; + font-size: 10px; + font-weight: 600; + color: var(--text-dim); + padding: 6px 10px; +} + +.nav-link { + display: block; + padding: 7px 10px; + border-radius: var(--radius-sm); + color: var(--text-muted); + font-size: 13px; + transition: background 0.12s, color 0.12s; +} + +.nav-link:hover { + background: var(--bg-elevated); + color: var(--text); +} + +.nav-link.active { + background: var(--accent-soft); + color: var(--accent); + font-weight: 600; +} + +.sidebar-footer { + padding: 14px 20px; + border-top: 1px solid var(--border); + font-size: 11px; + color: var(--text-dim); + display: flex; + flex-direction: column; + gap: 8px; +} + +.sidebar-signout { + display: inline-block; + align-self: flex-start; + font-size: 12px; + font-weight: 600; + color: var(--text-muted); + padding: 4px 0; +} + +.sidebar-signout:hover { + color: var(--accent); +} + +/* ---------- Auth shell ---------- */ +.auth-shell { + display: flex; + align-items: center; + justify-content: center; + min-height: 100vh; + padding: 32px 20px; +} + +.auth-shell-inner { + width: 100%; + max-width: 400px; + display: flex; + flex-direction: column; + gap: 22px; +} + +.auth-brand { + display: flex; + align-items: center; + justify-content: center; + gap: 10px; + font-weight: 700; + font-size: 18px; +} + +.auth-heading { + text-align: center; +} + +.auth-heading .page-title { + font-size: 20px; +} + +.auth-card { + background: var(--bg-panel); + border: 1px solid var(--border); + border-radius: var(--radius); + padding: 24px; + display: flex; + flex-direction: column; + gap: 18px; +} + +.auth-card .form { + max-width: none; +} + +.auth-method-toggle { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 8px; +} + +.auth-alt { + text-align: center; + font-size: 13px; + color: var(--text-muted); +} + +.auth-alt a { + color: var(--accent); + font-weight: 600; +} + +.main { + padding: 28px 32px 64px; + max-width: 1180px; + width: 100%; +} + +/* ---------- Page header ---------- */ +.page-header { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 16px; + margin-bottom: 24px; +} + +.page-title { + font-size: 22px; + font-weight: 700; + margin: 0; +} + +.page-desc { + color: var(--text-muted); + margin: 4px 0 0; + font-size: 13px; +} + +/* ---------- Cards & stats ---------- */ +.card { + background: var(--bg-panel); + border: 1px solid var(--border); + border-radius: var(--radius); + padding: 20px; + margin-bottom: 20px; +} + +.card-title { + font-size: 14px; + font-weight: 600; + margin: 0 0 14px; +} + +.stat-grid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); + gap: 14px; + margin-bottom: 24px; +} + +.stat-card { + background: var(--bg-panel); + border: 1px solid var(--border); + border-left: 3px solid var(--border-strong); + border-radius: var(--radius); + padding: 16px 18px; +} + +.stat-card.tone-good { + border-left-color: var(--good); +} +.stat-card.tone-warn { + border-left-color: var(--warn); +} +.stat-card.tone-bad { + border-left-color: var(--bad); +} +.stat-card.tone-default { + border-left-color: var(--accent); +} + +.stat-label { + font-size: 12px; + color: var(--text-muted); + margin-bottom: 6px; +} + +.stat-value { + font-size: 24px; + font-weight: 700; + letter-spacing: -0.01em; +} + +.stat-hint { + font-size: 11px; + color: var(--text-dim); + margin-top: 4px; +} + +/* ---------- Tables ---------- */ +.table-wrap { + overflow-x: auto; + border: 1px solid var(--border); + border-radius: var(--radius); +} + +.data-table { + width: 100%; + border-collapse: collapse; + font-size: 13px; +} + +.data-table th { + text-align: left; + font-weight: 600; + color: var(--text-muted); + padding: 10px 14px; + background: var(--bg-elevated); + border-bottom: 1px solid var(--border); + white-space: nowrap; +} + +.data-table td { + padding: 11px 14px; + border-bottom: 1px solid var(--border); + vertical-align: middle; +} + +.data-table tr:last-child td { + border-bottom: none; +} + +.data-table tbody tr:hover { + background: var(--bg-elevated); +} + +.ta-right { + text-align: right; +} + +.mono { + font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; + font-size: 12px; +} + +/* ---------- Badges ---------- */ +.badge { + display: inline-block; + padding: 2px 9px; + border-radius: 999px; + font-size: 11px; + font-weight: 600; + text-transform: capitalize; + border: 1px solid transparent; +} + +.badge-good { + background: var(--good-soft); + color: var(--good); +} +.badge-warn { + background: var(--warn-soft); + color: var(--warn); +} +.badge-bad { + background: var(--bad-soft); + color: var(--bad); +} +.badge-neutral { + background: var(--bg-elevated); + color: var(--text-muted); + border-color: var(--border); +} + +/* ---------- Buttons ---------- */ +.btn { + display: inline-flex; + align-items: center; + gap: 6px; + padding: 8px 14px; + border-radius: var(--radius-sm); + font-size: 13px; + font-weight: 600; + cursor: pointer; + border: 1px solid var(--border-strong); + background: var(--bg-elevated); + color: var(--text); + transition: background 0.12s, border-color 0.12s; +} + +.btn:hover { + border-color: var(--accent); +} + +.btn-primary { + background: var(--accent); + border-color: var(--accent); + color: #fff; +} + +.btn-primary:hover { + background: var(--accent-hover); +} + +.btn:disabled { + opacity: 0.55; + cursor: not-allowed; +} + +/* ---------- Empty / error states ---------- */ +.empty-state { + text-align: center; + padding: 48px 24px; + border: 1px dashed var(--border-strong); + border-radius: var(--radius); + background: var(--bg-panel); +} + +.empty-icon { + font-size: 28px; + color: var(--text-dim); + margin-bottom: 8px; +} + +.empty-title { + font-weight: 600; + font-size: 15px; +} + +.empty-message { + color: var(--text-muted); + max-width: 420px; + margin: 6px auto 0; + font-size: 13px; +} + +.empty-action { + margin-top: 16px; +} + +.error-banner { + background: var(--bad-soft); + border: 1px solid rgba(240, 99, 99, 0.4); + color: var(--bad); + padding: 10px 14px; + border-radius: var(--radius-sm); + font-size: 12px; + margin-bottom: 18px; +} + +/* ---------- Sub navigation ---------- */ +.subnav { + display: flex; + gap: 4px; + margin-bottom: 22px; + border-bottom: 1px solid var(--border); + flex-wrap: wrap; +} + +.subnav-link { + padding: 8px 14px; + font-size: 13px; + color: var(--text-muted); + border-bottom: 2px solid transparent; + font-weight: 500; +} + +.subnav-link:hover { + color: var(--text); +} + +/* ---------- Forms ---------- */ +.form { + display: flex; + flex-direction: column; + gap: 16px; + max-width: 640px; +} + +.field { + display: flex; + flex-direction: column; + gap: 6px; +} + +.field label { + font-size: 13px; + font-weight: 600; +} + +.field-hint { + font-size: 12px; + color: var(--text-dim); +} + +.input, +.select, +.textarea { + background: var(--bg); + border: 1px solid var(--border-strong); + border-radius: var(--radius-sm); + color: var(--text); + padding: 9px 11px; + font-size: 13px; + font-family: inherit; +} + +.input:focus, +.select:focus, +.textarea:focus { + outline: none; + border-color: var(--accent); +} + +.textarea { + resize: vertical; + min-height: 80px; +} + +.form-row { + display: flex; + gap: 12px; + flex-wrap: wrap; +} + +.form-row > .field { + flex: 1; + min-width: 160px; +} + +.form-message { + font-size: 13px; + padding: 8px 12px; + border-radius: var(--radius-sm); +} + +.form-message.ok { + background: var(--good-soft); + color: var(--good); +} + +.form-message.err { + background: var(--bad-soft); + color: var(--bad); +} + +/* ---------- Choice grid (product builder) ---------- */ +.choice-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); + gap: 12px; +} + +.choice { + text-align: left; + background: var(--bg); + border: 1px solid var(--border-strong); + border-radius: var(--radius); + padding: 14px 16px; + cursor: pointer; + transition: border-color 0.12s, background 0.12s; +} + +.choice:hover { + border-color: var(--accent); +} + +.choice.selected { + border-color: var(--accent); + background: var(--accent-soft); +} + +.choice-title { + font-weight: 600; + font-size: 14px; +} + +.choice-desc { + font-size: 12px; + color: var(--text-muted); + margin-top: 3px; +} + +.step-label { + font-size: 12px; + font-weight: 700; + text-transform: uppercase; + letter-spacing: 0.05em; + color: var(--accent); + margin-bottom: 10px; +} + +.builder-actions { + display: flex; + justify-content: flex-end; + gap: 10px; + margin-top: 8px; +} + +/* ---------- Misc ---------- */ +.muted { + color: var(--text-muted); +} +.dim { + color: var(--text-dim); +} +.row-between { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; +} +.tag-list { + display: flex; + gap: 6px; + flex-wrap: wrap; +} +.tag { + background: var(--bg-elevated); + border: 1px solid var(--border); + border-radius: 4px; + padding: 1px 7px; + font-size: 11px; + color: var(--text-muted); +} +.detail-grid { + display: grid; + grid-template-columns: 160px 1fr; + gap: 10px 18px; + font-size: 13px; +} +.detail-grid dt { + color: var(--text-muted); +} +.detail-grid dd { + margin: 0; + font-weight: 500; +} +.breadcrumb { + font-size: 12px; + color: var(--text-dim); + margin-bottom: 6px; +} +.breadcrumb a:hover { + color: var(--accent); +} + +/* ---------- Button variants ---------- */ +.btn-ghost { + background: transparent; + border-color: var(--border-strong); + color: var(--text-muted); +} +.btn-ghost:hover { + color: var(--text); + border-color: var(--accent); +} +.btn-sm { + padding: 5px 11px; + font-size: 12px; +} + +/* ---------- Onboarding checklist ---------- */ +.onboarding { + border-color: var(--accent); + background: var(--bg-panel); + border-left: 3px solid var(--accent); +} +.onboarding-head { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 16px; +} +.onboarding-pct { + font-size: 22px; + font-weight: 700; + color: var(--accent); + font-variant-numeric: tabular-nums; +} +.onboarding-progress { + height: 6px; + border-radius: 999px; + background: var(--bg-elevated); + overflow: hidden; + margin: 14px 0 18px; +} +.onboarding-progress-fill { + height: 100%; + background: var(--accent); + border-radius: 999px; + transition: width 0.3s ease; +} +.onboarding-steps { + list-style: none; + margin: 0; + padding: 0; + display: flex; + flex-direction: column; + gap: 8px; +} +.onboarding-step { + display: flex; + align-items: center; + gap: 12px; + padding: 12px 14px; + border: 1px solid var(--border); + border-radius: var(--radius-sm); + background: var(--bg-elevated); +} +.onboarding-step.next { + border-color: var(--accent); +} +.onboarding-step.done { + opacity: 0.7; +} +.onboarding-check { + flex: 0 0 22px; + width: 22px; + height: 22px; + display: inline-flex; + align-items: center; + justify-content: center; + border-radius: 999px; + font-size: 13px; + background: var(--bg-panel); + color: var(--text-dim); +} +.onboarding-step.done .onboarding-check { + background: var(--good-soft); + color: var(--good); +} +.onboarding-step-body { + display: flex; + flex-direction: column; + gap: 2px; + flex: 1 1 auto; + min-width: 0; +} +.onboarding-step-title { + font-weight: 600; + font-size: 14px; +} +.onboarding-step.done .onboarding-step-title { + text-decoration: line-through; + text-decoration-color: var(--text-dim); +} +.onboarding-step-status { + font-size: 12px; + flex: 0 0 auto; +} diff --git a/apps/creator-dashboard/app/layout.tsx b/apps/creator-dashboard/app/layout.tsx new file mode 100644 index 0000000..23486cd --- /dev/null +++ b/apps/creator-dashboard/app/layout.tsx @@ -0,0 +1,38 @@ +import type { Metadata } from "next"; +import type { ReactNode } from "react"; +import { Archivo, IBM_Plex_Mono } from "next/font/google"; +import { Sidebar } from "@/components/Sidebar"; +import "./globals.css"; + +const archivo = Archivo({ + subsets: ["latin"], + weight: ["400", "500", "600", "700", "800", "900"], + variable: "--font-archivo", + display: "swap", +}); + +const plexMono = IBM_Plex_Mono({ + subsets: ["latin"], + weight: ["400", "500", "600", "700"], + variable: "--font-mono-plex", + display: "swap", +}); + +export const metadata: Metadata = { + title: "SettleKit — Creator Earnings", + description: + "See your per-citation, per-listen, and per-second USDC royalties — the recursive split that follows your work through every hand that cites it.", +}; + +export default function RootLayout({ children }: { children: ReactNode }) { + return ( + + +
+ +
{children}
+
+ + + ); +} diff --git a/apps/creator-dashboard/app/not-found.tsx b/apps/creator-dashboard/app/not-found.tsx new file mode 100644 index 0000000..073bee3 --- /dev/null +++ b/apps/creator-dashboard/app/not-found.tsx @@ -0,0 +1,16 @@ +import Link from "next/link"; + +export default function NotFound() { + return ( +
+
∅
+
Page not found
+

This statement line doesn't exist.

+
+ + Back to statement + +
+
+ ); +} diff --git a/apps/creator-dashboard/app/page.tsx b/apps/creator-dashboard/app/page.tsx new file mode 100644 index 0000000..7695af9 --- /dev/null +++ b/apps/creator-dashboard/app/page.tsx @@ -0,0 +1,53 @@ +import { Card, DataTable, EmptyState, PageHeader, StatCard, StatGrid, StatusBadge } from "@/components/ui"; +import { getCreatorContext, type StatementLine } from "@/lib/data"; +import { formatNumber, formatUsdc, formatDateTime } from "@/lib/format"; + +export default function StatementPage() { + const ctx = getCreatorContext(); + const { totals, statement, me } = ctx; + + return ( + <> + + + + + + + + + + + + + rows={statement} + getKey={(r) => `${r.accessId}-${r.depth}-${r.createdAt}`} + columns={[ + { header: "Posted", cell: (r) => {formatDateTime(r.createdAt)} }, + { header: "Source", cell: (r) => r.sourceTitle }, + { + header: "Tier", + cell: (r) => ( + {r.depth === 0 ? "Author" : `Citation · L${r.depth}`} + ), + }, + { header: "Status", cell: (r) => }, + { + header: "Credit", + align: "right", + cell: (r) => ( + + +{formatUsdc(r.amount.amount)} + + ), + }, + ]} + empty={} + /> + + + ); +} diff --git a/apps/creator-dashboard/app/payouts/page.tsx b/apps/creator-dashboard/app/payouts/page.tsx new file mode 100644 index 0000000..85d9cfb --- /dev/null +++ b/apps/creator-dashboard/app/payouts/page.tsx @@ -0,0 +1,43 @@ +import { Card, DataTable, EmptyState, PageHeader, StatCard, StatGrid } from "@/components/ui"; +import { getCreatorContext, type PayoutSweep } from "@/lib/data"; +import { formatNumber, formatUsdc } from "@/lib/format"; + +export default function PayoutsPage() { + const { payouts, totals } = getCreatorContext(); + + return ( + <> + + + + + + + + + + + rows={payouts} + getKey={(r) => r.settlementId} + columns={[ + { header: "Settlement", cell: (r) => {r.settlementId} }, + { header: "Lines batched", align: "right", cell: (r) => {formatNumber(r.legs)} }, + { + header: "Amount", + align: "right", + cell: (r) => ( + + +{formatUsdc(r.amount.amount)} + + ), + }, + ]} + empty={} + /> + + + ); +} diff --git a/apps/creator-dashboard/app/settings/wallet/page.tsx b/apps/creator-dashboard/app/settings/wallet/page.tsx new file mode 100644 index 0000000..d084bb9 --- /dev/null +++ b/apps/creator-dashboard/app/settings/wallet/page.tsx @@ -0,0 +1,50 @@ +import { Card, PageHeader } from "@/components/ui"; +import { getCreatorContext } from "@/lib/data"; +import { shortWallet } from "@/lib/format"; + +export default function WalletSettingsPage() { + const { me } = getCreatorContext(); + + return ( + <> + + + +
+
Creator
+
+ {me.name} ({me.handle}) +
+
Network
+
arc
+
Address
+
+ {shortWallet(me.wallet)} +
+
Payee key
+
rss · {me.handle}
+
+

+ Registered in the payee registry as {`{ kind: "rss", externalId: "${me.handle}" } → ${shortWallet(me.wallet)}`}. + Until a creator claims their handle, earnings accrue to an escrow wallet and are released on registration. +

+
+ + +

+ Settled USDC can be swept to fiat through the Circle Payments Network off-ramp (e.g. USDC → local + currency). This is wired in packages/payouts-cpn and activates once Circle CPN credentials + are configured. +

+
+ +
+
+ + ); +} diff --git a/apps/creator-dashboard/app/sources/page.tsx b/apps/creator-dashboard/app/sources/page.tsx new file mode 100644 index 0000000..c600b0b --- /dev/null +++ b/apps/creator-dashboard/app/sources/page.tsx @@ -0,0 +1,63 @@ +import { Card, DataTable, EmptyState, PageHeader, StatusBadge } from "@/components/ui"; +import { getCreatorContext, type SourceStat } from "@/lib/data"; +import { formatNumber, formatUsdc } from "@/lib/format"; + +export default function SourcesPage() { + const { sources } = getCreatorContext(); + const mine = sources.filter((s) => s.isMine); + const others = sources.filter((s) => !s.isMine); + + return ( + <> + + + + + rows={mine} + getKey={(r) => r.id} + columns={[ + { header: "Title", cell: (r) => r.title }, + { header: "Per-access toll", cell: (r) => {formatUsdc(r.priceUsdc)} }, + { header: "Accesses", align: "right", cell: (r) => {formatNumber(r.accesses)} }, + { header: "Cites", cell: (r) => (r.citesCount > 0 ? : —) }, + { + header: "Earned by you", + align: "right", + cell: (r) => ( + + +{formatUsdc(r.earnedByMe.amount)} + + ), + }, + ]} + empty={} + /> + + + + + rows={others} + getKey={(r) => r.id} + columns={[ + { header: "Title", cell: (r) => r.title }, + { header: "Per-access toll", cell: (r) => {formatUsdc(r.priceUsdc)} }, + { header: "Accesses", align: "right", cell: (r) => {formatNumber(r.accesses)} }, + { + header: "Your recursive cut", + align: "right", + cell: (r) => ( + + {r.earnedByMe.amount === "0" ? "—" : `+${formatUsdc(r.earnedByMe.amount)}`} + + ), + }, + ]} + empty={} + /> + + + ); +} diff --git a/apps/creator-dashboard/components/ReuseDetector.tsx b/apps/creator-dashboard/components/ReuseDetector.tsx new file mode 100644 index 0000000..ed55d38 --- /dev/null +++ b/apps/creator-dashboard/components/ReuseDetector.tsx @@ -0,0 +1,116 @@ +"use client"; + +import { useState } from "react"; + +interface Match { + sourceId: string; + title: string; + score: number; + matched: number; + total: number; + wallet?: string; +} + +interface DetectResult { + grounded: boolean; + matches: Match[]; + quoteUsdc: string; +} + +const SAMPLE = + "Royalties should follow a work through every hand that made it, and when settlement is sub-cent and gas-free a citation can pay its source automatically."; + +export function ReuseDetector() { + const [text, setText] = useState(SAMPLE); + const [result, setResult] = useState(null); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + + async function run() { + setLoading(true); + setError(null); + try { + const res = await fetch("/api/detect", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ text }), + }); + const json = (await res.json()) as { data?: DetectResult; error?: string }; + if (!res.ok || json.data === undefined) { + setError(json.error ?? "detection failed"); + setResult(null); + } else { + setResult(json.data); + } + } catch { + setError("network error"); + setResult(null); + } finally { + setLoading(false); + } + } + + return ( +
+
+ +