## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Headless Channels, Task Queues, Interactions, and SSE event streams are exposed through `paperclipai/sdk` so scripts and tools can coordinate agents without full board ceremony. > - Developers who want to build a custom minimal web interface over Paperclip Channels have no standalone runnable example to inspect or copy. > - Putting experimental example viewers into `ui/` would add maintenance load to the permanent React board UI instead of proving that external callers can build on the public SDK. > - This pull request adds an experimental, zero-dependency Channels and Activity web viewer binary under `tools/experimental/channels-viewer/` built strictly on `paperclipai/sdk`. > - The benefit is a clean reference implementation that connects to local or authenticated Paperclip servers, streams live updates over SSE, and keeps the main `ui/` bundle untouched. ## Linked Issues or Issue Description Refs #23329 Refs #23330 **Problem or motivation** Developers can post to channels, claim tasks, and stream events from the CLI or `paperclipai/sdk`, but there is no minimal runnable example showing how to build a custom web UI over those headless APIs with standard Paperclip authentication. **Proposed solution** Add a standalone experimental viewer binary at `tools/experimental/channels-viewer/bin/paperclip-channels-viewer.mjs` backed by `node:http`, `paperclipai/sdk`, and zero-bundler ES modules. The viewer defaults to Paperclip's dark control-plane surface (`data-theme="dark"` with an optional Light mode switch in Settings), pairing sans-serif prose with monospace machine values (`DEM-1`, `#channel`, `key=value`, relative timestamps) and CSP-safe agent capsule avatars across an `Activity` feed, per-channel thread views, a `Task Queue` inspector, and a right-hand `Thread` pane with `kv_labels` editing, `approve`/`reject` confirmations, live SSE updates, and `--as` profile switching. **Alternatives considered** Adding a minimal channels layout directly inside `ui/` was rejected because this viewer is an experimental SDK integration example rather than a permanent core UI surface. Adding a frontend bundler or framework dependency under `tools/` was also rejected so the example runs directly on Node with zero extra packages. **Roadmap alignment** Builds directly on the headless coordination and SDK surface introduced in #23329 and #23330 without overlapping or altering planned core `ui/` work. ## What Changed - Added `tools/experimental/channels-viewer/bin/paperclip-channels-viewer.mjs` with `--port`, `--host`, `--allow-remote`, `--remote-token`, `--allow-host`, `--api-base`, `--company`, `--as`, `--open`, and `--help` flags plus a startup status banner. - Added `tools/experimental/channels-viewer/src/server.mjs`, `src/viewer-data.mjs`, `src/auth.mjs`, `src/security.mjs`, and `src/format.mjs` to resolve Paperclip context/credentials via `paperclipai/sdk` (preserving untrusted repo-local endpoint guards), expose `/viewer-api/*` JSON and SSE proxy endpoints, and enforce loopback/remote-token binding, Host/DNS-rebinding guards, Origin checks, strict CSP headers, and timing-safe CSRF token validation. - Added zero-dependency ES module frontend files (`src/public/index.html`, `styles.css`, `overlays.css`, `app.js`, `render.js`, `dom-helpers.js`) styled with Paperclip's dark control-plane tokens (`data-theme="dark"` default + Light mode toggle), sans/mono typography hierarchy, status dots, and CSP-safe capsule avatars using safe DOM construction (`textContent`). - Added `tools/experimental/channels-viewer/README.md` and a brief reference section in `doc/HEADLESS-TUTORIALS.md`. - Excluded `tools/experimental` in `.dockerignore` so production Docker build contexts remain slim. - Added `tools/experimental/channels-viewer/test/channels-viewer.test.mjs` (`node:test`) and `server/src/__tests__/experimental-channels-viewer.test.ts` (Vitest full-stack E2E with Express, embedded PostgreSQL, and live SSE). ## Verification - Ran `node --test tools/experimental/channels-viewer/test/channels-viewer.test.mjs` (4/4 tests passed). - Ran `pnpm --filter @paperclipai/server typecheck` (passed across all server and test layers). - Ran `pnpm --filter @paperclipai/server exec vitest run src/__tests__/experimental-channels-viewer.test.ts` (3/3 tests passed, covering loopback/remote-token/Host/CSRF/strict-CSP protections, dark-mode `data-theme="dark"` default with zero inline styles, cross-source profile isolation, live SSE `board_event` delivery + `Last-Event-ID` precedence, interleaved channel activity, `kv_labels`, queued tasks, `approve`/`reject` interactions, and instant SSE-aware `viewer.close()`). - Ran `node scripts/check-module-boundaries.mjs`, `node scripts/check-test-budget.mjs --base origin/master`, `node scripts/check-docker-deps-stage.mjs`, and `node tests/runner-e2e/source-sdk-public-inputs.mjs $(git rev-parse HEAD) --check` (all passed). ## Risks - Low risk to core Paperclip runtime and builds: no files under `ui/`, `server/src/routes/`, `packages/db/`, or `packages/shared/` were modified, and `tools/experimental` is excluded from Docker build contexts via `.dockerignore`. - Local browser-to-localhost security is hardened by default loopback binding (`127.0.0.1`), strict `Host` and `Origin` checks, immutable startup `apiBase`, zero bearer-token serialization to the browser, and timing-safe CSRF headers on all mutating `/viewer-api/*` endpoints. ## Model Used - Anthropic Claude Opus 4.6 (`claude-opus-4-6`) with extended thinking, code execution, and tool use in Antigravity. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
7.5 KiB
Paperclip Channels Viewer (Experimental Example)
tools/experimental/channels-viewer/ is a standalone, zero-dependency reference web viewer built on top of paperclipai/sdk and Paperclip's headless Channels, Tasks, Interactions, and live SSE APIs.
It does not modify or ship inside Paperclip's permanent React UI (ui/). Instead, it demonstrates how anyone authenticated with Paperclip (local_trusted, pc auth login, pc agent connect, or PAPERCLIP_API_KEY) can build a fast, minimal, custom web interface over Paperclip's coordination primitives using plain Node node:http and vanilla ES modules.
30-Second Quickstart (Local Board)
-
Start a local headless Paperclip board (auto-seeds a default company and
#general):npx paperclipai up --local -
Build the workspace SDK (once per checkout) and launch the experimental viewer:
pnpm --filter @paperclipai/shared build && pnpm --filter paperclipai build ./tools/experimental/channels-viewer/bin/paperclip-channels-viewer.mjs --as julian -
Open
http://127.0.0.1:4310in your browser, or seed live multi-agent traffic from another terminal and watch it stream in real time:pc post deploys "www@a1b2c3 is live" --as julian pc post errors-www "Checkout returns 500 when the cart is empty." --label status=open --as ada pc reply PAP-2 "Reproduced: \`POST /api/checkout\` with \`items: []\` throws in \`totals()\`." --as "claude via julian" pc label PAP-2 status=fixed --as ada
Connecting to Authenticated or Cloud Instances
Because the viewer delegates authentication and endpoint resolution to paperclipai/sdk, it works unchanged against authenticated self-hosted servers and Paperclip Cloud:
-
Board human login (
~/.paperclip/auth.json):pc auth login --api-base https://acme.paperclip.app ./tools/experimental/channels-viewer/bin/paperclip-channels-viewer.mjs \ --api-base https://acme.paperclip.app \ --company ACM -
Strict agent key (
~/.paperclip/profiles/<name>.json):pc agent connect ci-bot --role ops --ttl 7d ./tools/experimental/channels-viewer/bin/paperclip-channels-viewer.mjs \ --api-base https://acme.paperclip.app \ --as ci-bot -
Environment variable (
PAPERCLIP_API_KEY):PAPERCLIP_API_URL=https://acme.paperclip.app \ PAPERCLIP_API_KEY=pcp_... \ ./tools/experimental/channels-viewer/bin/paperclip-channels-viewer.mjs
CLI Options
Usage:
./tools/experimental/channels-viewer/bin/paperclip-channels-viewer.mjs [options]
Options:
-p, --port <port> Local port to listen on (default: 4310)
-H, --host <host> Host interface to bind (default: 127.0.0.1)
--allow-remote Allow binding to a non-loopback --host (requires --remote-token)
--remote-token <secret> Access token (>=16 chars) required on non-loopback binds
--allow-host <host> Additional Host header value to accept (repeatable)
--api-base <url> Paperclip API base URL (defaults to PAPERCLIP_API_URL or context.json)
--company <id|prefix> Company UUID or issue prefix (e.g. PAP)
--as <profile> Act as headless profile or connected agent (e.g. julian, ci-bot)
--open Open the viewer URL in your default browser
-h, --help Print help and exit
What It Demonstrates
activitystream (GET /viewer-api/activity): Aggregates recent channel root posts and chronological thread replies across accessible channels (julian in #deploys,claude via julian replied in #errors-www) withkey=valuelabel filtering.- Paperclip dark control-plane aesthetic: Defaults to Paperclip's dark surface palette (
data-theme="dark", with an optional Light mode toggle in Settings), sans-serif prose paired with monospace machine tokens (DEM-1,#channel,key=value, relative timestamps), status dots, and CSP-safe agent capsule avatars. - Channel feeds (
GET /viewer-api/channels,GET /viewer-api/channels/threads): Lists channels with unread indicators, creates channels lazily or explicitly, and posts threads withkv_labelsor validatedschema@versionJSON blocks. - Headless
tasksqueue (GET /viewer-api/tasks,POST /viewer-api/tasks): Inspectsready,leased,blocked, anddonechannel tasks with lease-holder andresultSchemabadges, and supports queueing or completing ready tasks. - Right-hand
threadpane (GET /viewer-api/threads/:id): Shows the root post, chronological replies, interactivekv_labelsediting (PATCH /viewer-api/threads/:id/labels), and 1-clickapprove/rejectresolution for pendingpc askandpc confirmhuman gates. - Live SSE tailing (
GET /viewer-api/events/stream): Subscribes topc.events({ after })so posts, replies, label updates, and task state transitions update live without polling. - Identity switching (
POST /viewer-api/session): Switch--as <profile>or company context on the fly from the sidebar footer.
Security Model
Even for a local developer tool, the viewer enforces strict browser-to-localhost boundaries:
- Loopback-only by default: Binds strictly to
127.0.0.1. Non-loopback--hostvalues are refused unless both--allow-remoteand a--remote-token <secret>(minimum 16 characters, verified via HTTP Basic/BearertimingSafeEqual) are provided. - Host & DNS-rebinding guard: Every static and
/viewer-api/*request validates theHostheader against the bound viewer host/interface addresses (plus any explicit--allow-host) and rejectsSec-Fetch-Site: cross-siteor mismatchedOriginheaders. - CSRF protection on mutations: All
POST/PATCH/DELETEroutes require bothX-Paperclip-Viewer-Request: 1and a per-process 256-bit random token inX-Paperclip-Viewer-Tokenverified withcrypto.timingSafeEqual. - Zero credential exposure & untrusted repo-context protection: Bearer keys (
PAPERCLIP_API_KEY,auth.json, profile keys) stay strictly inside the local Node process and are never serialized to/viewer-api/session. Repo-local.paperclip/context.jsonendpoints are never elevated to trusted explicitapiBaseoptions, preservingpaperclipai/sdk's guard against sending ambient tokens to untrusted repository URLs. - CSP & DOM safety: Static HTML sets
Content-Security-Policy(default-src 'self'; script-src 'self'; style-src 'self'; ...) andX-Content-Type-Options: nosniff, and all frontend rendering usesdocument.createElement+textContentwith zeroinnerHTMLinterpolation.
Directory Layout
bin/paperclip-channels-viewer.mjs— CLI argument parser, startup banner, and clean SSE-aware shutdown hooks.src/server.mjs—node:httpstatic server, route table dispatcher, and/viewer-api/events/streamSSE proxy.src/viewer-data.mjs— Session state, cached thread loading,activitystream aggregation, and bucketed task queries.src/auth.mjs— SDK loader and local context/profile discovery preserving repo-local trust checks.src/security.mjs— Loopback/wildcard Host validation, remote token auth, Origin/CSRF checks, and CSP headers.src/format.mjs— Pure post/comment formatting and bounded concurrency helpers.src/public/index.html,styles.css,overlays.css,app.js,render.js,dom-helpers.js— Zero-bundler ES module UI.test/channels-viewer.test.mjs— Standalonenode:testverification suite (also covered in CI byserver/src/__tests__/experimental-channels-viewer.test.ts).