mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
7636441c4619cd233cc884dee43e9e11ace5aa8e
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
1c0233526d |
feat(tools): add experimental minimal channels viewer example (#23380)
## 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> |
||
|
|
398d746093 |
build(agent-runtime): harness runtime images for sandboxed execution (stage 3/3) (#7934)
> [!NOTE] > This is **stage 3 of 3** of the staged Kubernetes contribution: stage 1 is the kubernetes sandbox-provider plugin (#5790), stage 2 is the provider backend/hardening refresh filed separately, and this stage ships the runtime images those sandboxes run. ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Sandboxed agent execution (Refs #248) runs each agent turn in an isolated environment; the kubernetes sandbox provider (stage 1, #5790) schedules those runs as hardened pods > - A sandbox pod needs a runtime image with the harness CLI preinstalled: installing CLIs at run start is slow, flaky, and needs network egress the sandbox should not have > - There is no first-party image family for this, so every deployer would have to hand-roll Ubuntu + Node + CLI images per harness and solve signal handling, non-root, and image chaining themselves > - This PR ships the agent-runtime image family: a hardened base (non-root uid 1000, tini, git, the agent shim) plus one derived image per harness, a buildx bake file that chains them, and a publish workflow with cosign keyless signing > - The benefit is that any sandbox infrastructure, the kubernetes provider or otherwise, gets ready-made, signed, security-hardened per-harness runtime images that are verified in production across five harnesses ## Linked Issues or Issue Description Refs #248 (sandboxed agent execution proposal) and #5790 (the kubernetes sandbox provider, stage 1 of this contribution, which consumes these images as per-run runtime images via its adapter defaults). No issue covers the image gap itself, described in-PR: sandbox providers reference `ghcr.io/paperclipai/agent-runtime-*` images, but the repository contains neither the Dockerfiles nor the workflow that builds and publishes them. Without this, self-deployers cannot reproduce or audit the images their agent runs execute in. ## What Changed - `docker/agent-runtime/Dockerfile.base`: foundation image. Ubuntu 22.04 + Node 22 + git + tini (PID 1, signal propagation) + non-root `paperclip` user (uid/gid 1000) + the agent shim compiled in a Go build stage. `WORKDIR /workspace`, entrypoint `tini -- paperclip-agent-shim`. - One derived Dockerfile per harness: `opencode` (opencode-ai), `pi` (@mariozechner/pi-coding-agent), `codex` (@openai/codex), `gemini` (@google/gemini-cli, plus headless auth-mode settings), `claude` (@anthropic-ai/claude-code, symlinked as `claude-code`). Each installs the CLI as root, returns to uid 1000, and asserts the binary is on PATH at build time. - `acpx` and `hermes` Dockerfiles are included in the bake group but are not in the default publish scope (hermes is a stub until a CLI package exists). - `docker/agent-runtime/buildx-bake.hcl`: builds the whole family in one pass. Derived targets chain off the `base` target through bake `contexts` (the literal registry in each `FROM` is overridden to `target:base` at build time, so no intermediate push is needed). `REGISTRY` (default `ghcr.io/paperclipai`) and `VERSION` are overridable variables. - `tools/agent-shim/`: a small Go shim that runs as the container command. It reads `/run/paperclip/runtime-command.json` (`{ "command", "args" }`), resolves the harness CLI on PATH, and `syscall.Exec`s it so SIGTERM from the kubelet reaches the harness directly. Harness-agnostic, with unit tests. - `.github/workflows/agent-runtime-images.yml`: builds and pushes the default scope (base, opencode, pi, codex, gemini, claude) for linux/amd64 on `workflow_dispatch` (explicit version tag) or pushes to `master` touching these paths, then signs every digest with cosign keyless OIDC. Uses only `GITHUB_TOKEN`; no extra secrets. - `docker/agent-runtime/README.md`: image lineup, base contents, local build instructions, the runtime-command contract, and the security model. Additive only: nothing in the product loads these images. Deployments opt in via their sandbox provider configuration (for example the kubernetes plugin's image settings). ## Verification - `cd tools/agent-shim && go build ./... && go test ./... && go vet ./...`: all passing. - `docker buildx bake -f docker/agent-runtime/buildx-bake.hcl --print base opencode pi codex gemini claude`: resolves cleanly; every tag and build context lands on `ghcr.io/paperclipai/agent-runtime-*` and derived targets map the base ref to `target:base`. - Workflow YAML validated (parses, single job, no org-specific secrets). - This exact image family (built from these Dockerfiles, bake file, and workflow) is what runs agent execution in production on paperclip.inc, verified end-to-end across five harnesses (opencode, pi, codex, gemini, claude): each as a full loop from assigned issue to per-run runtime image in a sandboxed pod to completed run. ## Risks - Low risk: purely additive, nothing in paperclip-server or the UI references these files. The workflow only triggers on its own paths. - Derived images install harness CLIs `@latest` at build time; a broken upstream CLI release would surface at image build, not at run time, and the PATH assertion fails the build rather than shipping a broken image. - The hermes image is an explicit stub (documented in its Dockerfile) until a hermes CLI package exists; it is outside the default publish scope. - cosign signing is keyless OIDC with the workflow identity; no long-lived signing keys are introduced. ## Model Used Claude Opus 4.8 (claude-opus-4-8, 1M context, extended thinking, tool use via Claude Code). ## 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 run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots (no UI changes) - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] 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: Claude Opus 4.8 (1M context) <noreply@anthropic.com> |