mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
docs(headless): make tutorials copy-pasteable and add workflow commands (#23433)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Headless channels, fenced task queues, and workflow primitives landed in #23330 and #23415, with walkthrough documentation in `doc/HEADLESS-TUTORIALS.md`. > - The previous `doc/HEADLESS-TUTORIALS.md` used invented issue IDs (`PAP-14`, `PAP-50`, `PAP-88`), missing local files (`plan.json`, `./finding.schema.json`), and non-existent project slugs (`web-app`, `api-server`), and did not cover the newer workflow commands or multi-agent workflow patterns. > - Readers trying to walk through the tutorial by hand could not copy and paste the commands directly on a fresh local board and missed the new `assign`, `handoff`, `claim --mine`/`--status backlog`, `block --needs`, `cancel`/`reopen`, and `channels` admin commands. > - This pull request rewrites `doc/HEADLESS-TUTORIALS.md` with deterministic hard-coded values (`--company-name "Demo"`, `DEM-1` through `DEM-10`), adds hands-on sections for the new workflow commands, and adds a concise overview of the workflow patterns from `.agents/skills/channels-queues-and-workflows/SKILL.md`. > - The benefit is a verified, top-to-bottom copy-pasteable tutorial that matches the current CLI surface and introduces Paperclip's core multi-agent coordination patterns. ## Linked Issues or Issue Description Refs #23330 Refs #23415 **Issue type** Outdated (no longer matches behavior) **Where is the issue?** `doc/HEADLESS-TUTORIALS.md` **What's wrong?** The tutorials relied on placeholder IDs, missing local files, and uncreated project slugs, so copying and pasting commands on a fresh `pc up --local` board failed. They also omitted the newer workflow ergonomics commands from #23415 (`tasks assign`, `tasks handoff`, `tasks claim --mine` / `--status backlog`, `tasks block --needs`, `tasks deps list`, `tasks cancel` / `reopen`, `channels create --private`, `channels members`, `channels update --managed-pool`) and did not summarize the workflow patterns in `.agents/skills/channels-queues-and-workflows/SKILL.md`. **Suggested fix** Update `doc/HEADLESS-TUTORIALS.md` to use deterministic hard-coded values (`--company-name "Demo"`, `DEM-1` through `DEM-10`), inline heredocs/JSON, runnable `node -e` commands, hands-on examples for the new workflow commands, and a concise workflow patterns overview linking to the skill and examples. ## What Changed - Updated `doc/HEADLESS-TUTORIALS.md` to start with `npx paperclipai up --local --port 3199 --company-name "Demo"` and use deterministic hard-coded IDs (`DEM-1`–`DEM-10`), inline `--file -` heredocs, inline `--data` schemas, and runnable `node -e` worker commands with zero placeholders. - Fixed `pc channels` to `pc channels list` (since bare `pc channels` prints Paperclip release channels) and `--schema ... --data '{...}'` flag syntax using the built-in `finding@1` schema. - Added hands-on walkthroughs for `pc tasks block --needs` + `pc tasks deps list`, `pc agent connect` + `pc tasks assign` + `pc tasks claim --mine`, `pc tasks claim --status backlog`, `pc tasks cancel` / `reopen`, `pc tasks handoff` with `--if` CAS, and `pc channels create --private` / `members` / `update --managed-pool`. - Added Tutorial 4 ("Multi-Agent Workflow Patterns at a Glance") summarizing Direct Work Queue, Two-Step Inbox, Single-Thread Relay, Assembly Line, and DAG Fan-Out/Fan-In with links to `.agents/skills/channels-queues-and-workflows/SKILL.md` and `examples.md`. - Updated Cloud graduation in Tutorial 5 to use `pc channels update --project ... --managed-pool ...` instead of raw API calls. ## Verification - Ran every command in Tutorials 1–3 verbatim in an isolated temporary `PAPERCLIP_HOME` against a fresh `pc up --local --port 3297 --company-name "Demo"` server (`DEM-1` through `DEM-10` plus expected `409 label_conflict` on competing CAS label update): all commands succeeded with exit code 0. - Confirmed `pc channels list` lists board channels instead of release channels. ## Risks - Low risk. Documentation-only change (`doc/HEADLESS-TUTORIALS.md`); no runtime, schema, or API behavior changes. ## Model Used - Google Gemini (Antigravity agentic runtime, Gemini 4 Neon Medium, extended thinking with tool use and code execution) ## 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
This commit is contained in:
1 parent
8bf0646796
commit
f0ee1b40f0
1 file changed
+204
-128
+204
-128
@@ -1,8 +1,10 @@
|
||||
# Headless Paperclip Tutorials
|
||||
|
||||
These four tutorials walk through using Paperclip as a zero-ceremony coordination board, task DAG queue, and lock-free state machine from your terminal or CI scripts — and graduating cleanly to Paperclip Cloud when you need strict agent credentials and managed sandboxes.
|
||||
These tutorials walk through using Paperclip as a zero-ceremony coordination board, task DAG queue, and multi-agent workflow engine from your terminal — and graduating cleanly to Paperclip Cloud when you need strict agent credentials and managed sandboxes.
|
||||
|
||||
Before running commands, review [CHANNELS-AND-QUEUES.md](./CHANNELS-AND-QUEUES.md) for the mental model (Projects vs. Channels, passive posts vs. queued tasks, and fenced leases). All examples below use `pc` (the short binary alias installed with `paperclipai`) or `npx paperclipai` — both invoke the exact same CLI safely.
|
||||
Every local command below uses **hard-coded values** (`--company-name "Demo"`, deterministic IDs `DEM-1` through `DEM-10`, inline JSON, and runnable `node -e` commands) so you can copy and paste straight from top to bottom on a fresh local board without inventing placeholders or environment variables.
|
||||
|
||||
Before diving into the reference, see [CHANNELS-AND-QUEUES.md](./CHANNELS-AND-QUEUES.md) for the mental model (Projects vs. Channels, passive posts vs. queued tasks, and fenced leases). All examples below use `pc` (the short binary alias installed with `paperclipai`) or `npx paperclipai` — both invoke the exact same CLI.
|
||||
|
||||
---
|
||||
|
||||
@@ -10,261 +12,333 @@ Before running commands, review [CHANNELS-AND-QUEUES.md](./CHANNELS-AND-QUEUES.m
|
||||
|
||||
**Why this is useful:** You have two or three coding agents (or terminal scripts) on your laptop and want a shared message board, thread history, and cursor-based waiting — with zero cloud account, zero LLM API keys in Paperclip, and zero `--company-id` flags.
|
||||
|
||||
### 1. Start the local board
|
||||
### 1. Start an isolated local board (Terminal 1)
|
||||
|
||||
```sh
|
||||
npx paperclipai up --local
|
||||
npx paperclipai up --local --port 3199 --company-name "Demo"
|
||||
```
|
||||
|
||||
What this does:
|
||||
- Boots embedded PostgreSQL and the Paperclip server at `http://127.0.0.1:3100` in `local_trusted` mode with zero interactive prompts.
|
||||
- Boots embedded PostgreSQL and the Paperclip server at `http://127.0.0.1:3199` in `local_trusted` mode with zero interactive prompts.
|
||||
- Stores local state in `<git-root>/.paperclip/` (omit `--local` to use `~/.paperclip/instances/default`).
|
||||
- Auto-seeds a default company (e.g. prefix `PAP`) and the `general` channel, and saves the resolved `apiBase` + `companyId` into local CLI context so every `pc` command works with zero flags.
|
||||
- Auto-seeds the `Demo` company (deterministic issue prefix `DEM`) and the `general` channel, and writes `.paperclip/context.json` so every `pc` command in Terminal 2 auto-discovers `apiBase` and `companyId` with zero flags.
|
||||
|
||||
### 2. Post to a channel and reply from another terminal
|
||||
*(Optional: open a third terminal and run `pc tail` to watch live SSE board events stream as you paste the commands below.)*
|
||||
|
||||
In Terminal 2, act as `lead` using `--as`. Because `local_trusted` defaults to `open_local_profiles`, `--as lead` works immediately without registering an agent first:
|
||||
### 2. Post to lazy channels, reply, and read subtrees (Terminal 2)
|
||||
|
||||
Because `local_trusted` defaults to `open_local_profiles`, `--as lead` works immediately without registering an agent first:
|
||||
|
||||
```sh
|
||||
pc whoami --as lead
|
||||
|
||||
# Post to channels without creating them first (passive posts: status=backlog, zero worker wakeups)
|
||||
pc post deploys "Starting auth-token refactor on feat/jwt" --label env=staging --as lead
|
||||
pc post security/findings "Found unpinned image in Dockerfile" --label severity=high --as scanner
|
||||
```
|
||||
|
||||
`pc post` lazily creates the `deploys` channel and creates an unassigned `backlog` issue (`scope = 'channel'`), printing its ID (for example `PAP-1`).
|
||||
On a fresh `Demo` board, those two posts are created as **`DEM-1`** and **`DEM-2`**.
|
||||
|
||||
Now read the channel and add a reply from another profile:
|
||||
Read a channel, reply to `DEM-1`, and query an entire slash-path subtree with a trailing `/`:
|
||||
|
||||
```sh
|
||||
pc read deploys
|
||||
pc reply PAP-1 "Unit suite green on feat/jwt; ready for staging smoke." --as ci-bot
|
||||
pc read PAP-1
|
||||
pc reply DEM-1 "Unit suite green on feat/jwt; ready for staging smoke." --as ci-bot
|
||||
pc read DEM-1
|
||||
|
||||
# Subtree query (everything under security/) and board channel list
|
||||
pc read security/
|
||||
pc channels list
|
||||
```
|
||||
|
||||
Notice that `pc read` omits `[backlog]` on passive posts so channel discussions read like clean threads, and every response includes a monotonic event cursor (e.g., `evt_42`).
|
||||
Notice that `pc read` omits `[backlog]` on passive posts so channel discussions read like clean threads, and every response includes a monotonic event cursor (for example, `evt_6`).
|
||||
|
||||
### 3. Wait for the next update without polling
|
||||
|
||||
Instead of `sleep` loops, block cleanly until a reply or task event arrives on `PAP-1`:
|
||||
Instead of `sleep` loops, block cleanly until a reply or task event arrives on `DEM-1`:
|
||||
|
||||
```sh
|
||||
pc wait PAP-1 --event comment.posted,task.completed --timeout 10m --json
|
||||
# Replay the existing comment immediately from evt_0:
|
||||
pc wait DEM-1 --after evt_0 --event comment.posted,task.completed --timeout 30s --json
|
||||
```
|
||||
|
||||
`pc wait` checks `activity_log` once on entry (so updates that landed moments earlier return immediately with zero race window) and then subscribes to live server events until the first match arrives or the timeout expires.
|
||||
Omitting `--after` waits for the *next* live event from now. Run `pc wait DEM-1 --event comment.posted --timeout 30s` in one terminal and `pc reply DEM-1 "Staging smoke green." --as qa-bot` in another to see it return immediately.
|
||||
|
||||
---
|
||||
|
||||
## Tutorial 2: Multi-Agent Swarm with `plan.json` and Human Gates
|
||||
## Tutorial 2: Queues, DAG Plans, `pc tasks run`, Mid-Flight Blockers & Human Gates
|
||||
|
||||
**Why this is useful:** Multi-step work often spans parallel implementation subtasks and a final review step that must wait for all prerequisites. Submitting a `plan.json` creates the entire dependency DAG atomically in one transaction, and `pc tasks run` lets any coding CLI (`claude`, `codex`, `opencode`, `gemini`) drain the ready queue with automatic lease renewal and clean `Ctrl-C` release.
|
||||
**Why this is useful:** Multi-step work often spans parallel implementation subtasks and a final review step that must wait for all prerequisites. Submitting a `plan.json` DAG creates all tasks and dependency edges atomically in one transaction, `pc tasks run` drains ready tasks with auto-renewed fenced leases, `pc tasks block --needs` parks a task when a worker discovers a new blocker mid-flight, and `pc confirm --human` pauses for a human without holding a worker slot.
|
||||
|
||||
### 1. Author a `plan.json` DAG
|
||||
### 1. Register an inline result schema and submit a 3-task DAG
|
||||
|
||||
Save `plan.json` with symbolic `key` names, `needs` dependencies, and optional top-level or per-task `projectId` values (accepting either project UUIDs or project shortnames):
|
||||
First, register a versioned schema (`test-summary@1`) inline so the final review task enforces structured output at completion:
|
||||
|
||||
```json
|
||||
```sh
|
||||
pc schemas create test-summary@1 --data '{
|
||||
"type": "object",
|
||||
"required": ["passed", "suite"],
|
||||
"properties": {
|
||||
"passed": { "type": "boolean" },
|
||||
"suite": { "type": "string" }
|
||||
},
|
||||
"additionalProperties": false
|
||||
}' --description "Structured verification summary"
|
||||
```
|
||||
|
||||
Now submit a 3-task DAG into `build/auth` via stdin (`--file -`):
|
||||
|
||||
```sh
|
||||
cat <<'EOF' | pc tasks create build/auth --file - --as lead
|
||||
{
|
||||
"channel": "build/auth",
|
||||
"projectId": "web-app",
|
||||
"idempotencyKey": "jwt-refactor-v1",
|
||||
"tasks": [
|
||||
{
|
||||
"key": "patch",
|
||||
"title": "Patch JWT expiry check in src/auth.ts",
|
||||
"description": "Owned paths: src/auth.ts. Verify with: pnpm test src/auth.test.ts",
|
||||
"description": "Owned paths: src/auth.ts. Verify with unit tests.",
|
||||
"priority": "high",
|
||||
"labels": { "role": "worker", "step": "fix" }
|
||||
},
|
||||
{
|
||||
"key": "audit-api",
|
||||
"projectId": "api-server",
|
||||
"title": "Audit callers of verifyToken() in api-server",
|
||||
"description": "Inspect call sites under server/src/routes/ and document findings.",
|
||||
"labels": { "role": "worker", "step": "audit" }
|
||||
},
|
||||
{
|
||||
"key": "review",
|
||||
"projectId": null,
|
||||
"title": "Adversarial review of auth patch and caller audit",
|
||||
"labels": { "role": "reviewer" },
|
||||
"needs": ["patch", "audit-api"]
|
||||
"needs": ["patch", "audit-api"],
|
||||
"resultSchema": "test-summary@1"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
Notice how `projectId` works:
|
||||
- Top-level `"projectId": "web-app"` supplies the batch default (`patch` inherits `"web-app"`).
|
||||
- Per-task `"projectId": "api-server"` overrides it for `audit-api`.
|
||||
- Per-task `"projectId": null` clears the project binding for `review`.
|
||||
- You can also pass `--project <id-or-slug>` on the CLI when `plan.json` omits a top-level `projectId`.
|
||||
*(When you have Paperclip Projects configured, you can also set `"projectId": "<project-slug>"` at the top level of the plan, per task, or via `--project <project-slug>` on the CLI.)*
|
||||
|
||||
Submit the plan atomically:
|
||||
On our fresh `Demo` board, this creates **`DEM-3`** (`patch`), **`DEM-4`** (`audit-api`), and **`DEM-5`** (`review`). Check the ready queue:
|
||||
|
||||
```sh
|
||||
pc tasks create build/auth --file plan.json --as lead
|
||||
pc tasks list --channel build/auth --ready
|
||||
```
|
||||
|
||||
Both `patch` and `audit-api` enter `todo` immediately; `review` stays blocked until both reach `done`. Because they were created in channel `build/auth`, they stay in the channel queue without cluttering the human's main **Tasks** board (add `--board` if you want them on the main Tasks board too).
|
||||
Only `DEM-3` and `DEM-4` appear as ready; `DEM-5` stays waiting until both finish.
|
||||
|
||||
### 2. Inspect and claim ready tasks
|
||||
### 2. Drain `DEM-3` with `pc tasks run`
|
||||
|
||||
Check the FIFO/priority ready queue or claim a single task manually:
|
||||
`pc tasks run` claims the next ready task (`FOR UPDATE SKIP LOCKED`), injects `PAPERCLIP_TASK_ID`, `PAPERCLIP_CLAIM_TOKEN`, and `PAPERCLIP_CLAIM_EPOCH`, renews the lease in the background, releases on `Ctrl-C`, and auto-completes on exit `0`:
|
||||
|
||||
```sh
|
||||
pc tasks build/auth
|
||||
pc tasks claim --ready build/auth --label role=worker --lease 5m --as worker-1
|
||||
pc tasks run --ready build/auth --label role=worker --as worker-1 -- node -e '
|
||||
console.log("Running", process.env.PAPERCLIP_TASK_ID, "epoch", process.env.PAPERCLIP_CLAIM_EPOCH);
|
||||
'
|
||||
```
|
||||
|
||||
`pc tasks claim --ready` uses `FOR UPDATE SKIP LOCKED`, so multiple workers claiming at the exact same instant never collide; each gets a distinct ready task with a fenced 5-minute lease.
|
||||
That claims and completes **`DEM-3`**. *(In real use, swap the `node -e '...'` command for `claude -p 'Read $PAPERCLIP_TASK_ID with pc read, fix it, verify, and reply.'` or `codex`.)*
|
||||
|
||||
### 3. Run a worker pool with `pc tasks run`
|
||||
### 3. Discover a blocker mid-flight (`pc tasks block --needs`)
|
||||
|
||||
Instead of writing wrapper glue for claiming, renewing leases, and handling `Ctrl-C`, use `pc tasks run`:
|
||||
Claim **`DEM-4`** manually, then suppose `worker-2` discovers a prerequisite task (**`DEM-6`**) that must finish before `DEM-4` can continue:
|
||||
|
||||
```sh
|
||||
pc tasks run --ready build/auth --label role=worker --wait 10m --as worker-1 \
|
||||
-- claude -p 'Read your task with "pc read $PAPERCLIP_TASK_ID", implement it, run tests, and reply with proof.'
|
||||
pc tasks claim --ready build/auth --label role=worker --lease 5m --as worker-2
|
||||
|
||||
# Create the newly discovered prerequisite task (DEM-6)
|
||||
pc tasks create build/auth "Fix legacy token helper before auditing callers" --label role=worker --as worker-2
|
||||
|
||||
# Park DEM-4 waiting on DEM-6 (releases lease cleanly; auto-flips Ready when DEM-6 completes)
|
||||
pc tasks block DEM-4 --needs DEM-6 "Waiting on legacy helper fix" --as worker-2
|
||||
pc tasks deps list DEM-4
|
||||
```
|
||||
|
||||
What `pc tasks run` handles automatically:
|
||||
- Blocks via `--wait 10m` until a matching `todo` task is ready, then claims it.
|
||||
- Injects `PAPERCLIP_TASK_ID`, `PAPERCLIP_ISSUE_UUID`, `PAPERCLIP_CLAIM_TOKEN`, `PAPERCLIP_CLAIM_EPOCH`, `PAPERCLIP_API_URL`, `PAPERCLIP_COMPANY_ID`, and `PAPERCLIP_PROFILE` directly into the child process (using `spawn`, no shell interpolation).
|
||||
- Renews the lease in the background every `leaseSec / 3`; if another process ever revokes the claim (`409 claim_lost`), terminates the child immediately.
|
||||
- Releases the task back to `todo` on `Ctrl-C`, or settles it (`complete` on exit `0`, `fail` on non-zero) if the child didn't settle it already.
|
||||
|
||||
Once both `patch` and `audit-api` complete, `review` automatically unblocks and emits `task.ready` for any `role=reviewer` worker.
|
||||
|
||||
### 4. Pause for a human decision (`pc ask` / `pc confirm`)
|
||||
|
||||
If a pooled worker hits an irreversible decision (for example, dropping a column), it should not sit idle holding a 5-minute lease while waiting hours for a human reply. One command handles the whole handoff:
|
||||
Now finish **`DEM-6`**, watch **`DEM-4`** automatically become ready again, and finish **`DEM-4`**:
|
||||
|
||||
```sh
|
||||
pc confirm PAP-14 "Drop legacy session_v1 column in this migration?" --human --as worker-1
|
||||
pc tasks claim DEM-6 --as worker-2
|
||||
pc tasks complete DEM-6 "Fixed legacy helper" --as worker-2
|
||||
|
||||
pc tasks claim DEM-4 --as worker-2
|
||||
pc tasks complete DEM-4 "All verifyToken() callers audited" --as worker-2
|
||||
```
|
||||
|
||||
Or ask a multiple-choice question:
|
||||
Completing `DEM-4` satisfies the last dependency on **`DEM-5`** (`review`), automatically unblocking it and emitting `task.ready`.
|
||||
|
||||
### 4. Pause for a human gate (`pc confirm`) and complete with `--data`
|
||||
|
||||
Claim **`DEM-5`** as `reviewer-1`, pause for a human decision (which releases the lease immediately so no worker slot is held), approve as the human operator, then re-claim and complete with schema-validated JSON:
|
||||
|
||||
```sh
|
||||
pc ask PAP-14 "Which cache eviction policy should auth tokens use?" \
|
||||
--choice "lru,ttl-only,no-cache" --human --as worker-1
|
||||
pc tasks claim --ready build/auth --label role=reviewer --as reviewer-1
|
||||
|
||||
# Drops the lease and moves DEM-5 to blocked until a human resolves it
|
||||
pc confirm DEM-5 "Approve running auth suite against staging mirror?" --human --as reviewer-1
|
||||
|
||||
# Approve from the terminal (or in the browser at http://127.0.0.1:3199/DEM/issues/DEM-5)
|
||||
pc approve DEM-5 --note "Go ahead — staging mirror is isolated."
|
||||
|
||||
# DEM-5 automatically requeues to todo; re-claim and complete with test-summary@1 data
|
||||
pc tasks claim DEM-5 --as reviewer-1
|
||||
pc tasks complete DEM-5 "All auth checks green." \
|
||||
--data '{"passed":true,"suite":"auth-integration"}' --as reviewer-1
|
||||
```
|
||||
|
||||
Behind the scenes, `pc ask` / `pc confirm` atomically creates a structured interaction card, moves `PAP-14` to `blocked`, and **releases the worker's claim lease** with `continuationPolicy = 'requeue_on_resolve'`.
|
||||
|
||||
A human can answer in the Paperclip Web UI (`/<prefix>/issues/PAP-14`) or directly from the terminal:
|
||||
|
||||
```sh
|
||||
pc approve PAP-14 --note "Approved — drop session_v1 after backfill check."
|
||||
```
|
||||
|
||||
Resolving the confirmation automatically returns `PAP-14` to `todo` (`ready`) and wakes the next free worker in the pool, which reads the decision in the thread and finishes the job.
|
||||
*(Missing or invalid `--data` returns `422 missing_or_invalid_result_schema` and leaves the task open until valid structured output is supplied.)*
|
||||
|
||||
---
|
||||
|
||||
## Tutorial 3: Lock-Free Agent State Machines and Structured Data
|
||||
## Tutorial 3: Assigning to Existing Agents, Atomic `handoff`, Claim Filters, Cancel/Reopen & Channel Admin
|
||||
|
||||
**Why this is useful:** When multiple agents triage issues concurrently, naive read-then-write updates overwrite each other (`last write wins`), and regex-parsing Markdown prose for JSON findings breaks easily. Compare-And-Swap (`CAS`) labels and versioned JSON Schema blocks solve both cleanly.
|
||||
**Why this is useful:** Real workflows combine push assignment to existing Paperclip agents, triage of passive inbox posts, atomic stage-to-stage handoffs with Compare-And-Swap (`CAS`) labels, task cancellation/reopening, and channel access or managed-pool controls.
|
||||
|
||||
### 1. Atomic Compare-And-Swap state transitions (`pc label --if`)
|
||||
### 1. Push-assign an existing post to a registered agent (`pc tasks assign` & `--mine`)
|
||||
|
||||
Suppose several triage workers watch `security/findings`. Before investigating `PAP-50`, a worker atomically claims the `triage_state` transition only if the issue is still `new` and has no `reviewer` set:
|
||||
First connect a registered agent (`@backend-eng`), post a passive alert to `errors/web` (**`DEM-7`**), then push-assign `DEM-7` directly to `@backend-eng`:
|
||||
|
||||
```sh
|
||||
pc label PAP-50 triage_state=investigating reviewer=triage-1 \
|
||||
--if triage_state=new --if-unset reviewer --as triage-1
|
||||
pc agent connect backend-eng --role engineer
|
||||
|
||||
# Drop a passive alert (DEM-7, status=backlog)
|
||||
pc post errors/web "500 spike on /api/checkout when guest cart has promo code" --label source=sentry --as lead
|
||||
|
||||
# Push-assign DEM-7 to @backend-eng (auto-promotes backlog -> todo; also wakes managed agents)
|
||||
pc tasks assign DEM-7 @backend-eng --comment "Reproduced on staging — nil stripeCustomerId"
|
||||
```
|
||||
|
||||
- The first worker receives `200 OK` and proceeds.
|
||||
- Any competing worker receives `409 label_conflict` (`conflictingKeys: ["triage_state"]`) and moves on without duplicating work.
|
||||
|
||||
Filter threads or streams by `kv_labels` at any time (supporting existence, exact match, or `|` OR):
|
||||
Default `pc tasks claim --ready` only pops *unassigned* tasks so pools never steal assigned work. `@backend-eng` explicitly claims its own assigned work with `--mine` (`--assignee me`):
|
||||
|
||||
```sh
|
||||
pc read security/findings --label 'triage_state=new|investigating'
|
||||
pc tasks claim --ready errors/web --mine --as backend-eng
|
||||
pc tasks complete DEM-7 "Added nil guard and regression test." --as backend-eng
|
||||
```
|
||||
|
||||
### 2. Register an immutable schema and post validated blocks
|
||||
*(Use `pc tasks assign DEM-7 --unassign` to return a task to the unassigned pool, `--keep-status` to keep a passive post in `backlog`, or `--force` to fence an active worker lease.)*
|
||||
|
||||
Register `security-finding@1` from a JSON Schema file (`finding.schema.json`):
|
||||
### 2. Triage passive inbox posts (`--status backlog`), cancel duplicates & reopen
|
||||
|
||||
Drop another raw alert (**`DEM-8`**), have a triage bot opt into claiming passive `backlog` posts with `--status backlog`, cancel it as a duplicate, and reopen it:
|
||||
|
||||
```sh
|
||||
pc schemas create security-finding@1 --file ./finding.schema.json \
|
||||
--description "Structured security vulnerability finding"
|
||||
pc post errors/web "Duplicate alert: 500 on /api/checkout" --as lead
|
||||
|
||||
# Opt-in backlog claiming for triage bots (or --status in_review for review pools)
|
||||
pc tasks claim --ready errors/web --status backlog --as triage-bot
|
||||
|
||||
# Cancel the duplicate (releases any active lease)
|
||||
pc tasks cancel DEM-8 "Duplicate of DEM-7" --as triage-bot
|
||||
|
||||
# Reopen later back to todo (or pass --status backlog)
|
||||
pc tasks reopen DEM-8 --comment "Reopening to verify webhook retry behavior"
|
||||
```
|
||||
|
||||
Schemas are immutable per version: registering `security-finding@1` again with an identical definition is a no-op, while changing the definition requires publishing `security-finding@2`. Built-in schemas (`git-commit@1`, `pull-request@1`, `test-report@1`, `finding@1`) are available without registration.
|
||||
### 3. Atomic `handoff` (`move`) across channels + CAS labels (`--if`)
|
||||
|
||||
Now post a finding with both human-readable context and a validated `--schema` block:
|
||||
Create a content draft task in `seo/drafts` (**`DEM-9`**), claim it as `writer-1`, and atomically move it to `seo/review`, update its `stage` label with a Compare-And-Swap guard (`--if stage=draft`), post a handoff note, and release the lease — all in **one transaction**:
|
||||
|
||||
```sh
|
||||
pc tasks create seo/drafts "Draft guide to headless Paperclip queues" --label stage=draft --as lead
|
||||
pc tasks claim DEM-9 --as writer-1
|
||||
|
||||
pc tasks handoff DEM-9 --channel seo/review --label stage=review --if stage=draft \
|
||||
--comment "Draft ready for fact-check" --as writer-1
|
||||
```
|
||||
|
||||
You can also guard standalone label updates with `pc label --if` / `--if-unset` for lock-free coordination:
|
||||
|
||||
```sh
|
||||
# Succeeds because stage=review and reviewer is currently unset
|
||||
pc label DEM-9 reviewer=fact-checker-1 --if stage=review --if-unset reviewer --as fact-checker-1
|
||||
|
||||
# Fails with 409 label_conflict because reviewer is already set
|
||||
pc label DEM-9 reviewer=fact-checker-2 --if-unset reviewer --as fact-checker-2
|
||||
```
|
||||
|
||||
### 4. Structured schema blocks on posts (`--schema` + `--data`)
|
||||
|
||||
Every company ships with four built-in schemas (`git-commit@1`, `pull-request@1`, `test-report@1`, `finding@1`) ready to use without registration. Post **`DEM-10`** with both human prose and a validated `finding@1` block:
|
||||
|
||||
```sh
|
||||
pc post security/findings "Found unescaped SQL in legacy report" \
|
||||
--schema security-finding@1 '{"repo":"acme/web","severity":"high","path":"src/reports.ts"}' \
|
||||
--schema finding@1 --data '{"severity":"high","title":"Unescaped SQL in src/reports.ts","path":"src/reports.ts","line":42}' \
|
||||
--as scanner-1
|
||||
|
||||
pc read DEM-10 --json
|
||||
```
|
||||
|
||||
Humans can still reply in plain Markdown on that thread without matching the schema, while scripts read `blocks[0].data` cleanly via `pc read <id> --json`.
|
||||
Humans can still reply in plain Markdown on `DEM-10` without matching the schema, while scripts read `blocks[0].data` cleanly.
|
||||
|
||||
### 3. Enforce a `--result-schema` on task completion
|
||||
### 5. Private channels, member access & managed-pool auto-drain
|
||||
|
||||
When queuing a task whose final deliverable must be machine-readable, bind `--result-schema`:
|
||||
Administer channel visibility, explicit members, queue ordering, and managed-pool auto-dispatch from the CLI:
|
||||
|
||||
```sh
|
||||
pc tasks create security/findings "Audit all SQL queries in src/reports.ts" \
|
||||
--result-schema test-report@1 --as lead
|
||||
# Create a private channel and grant @backend-eng access
|
||||
pc channels create security/private --private --description "Restricted security triage"
|
||||
pc channels members add security/private @backend-eng
|
||||
pc channels members list security/private
|
||||
|
||||
# Configure strict FIFO ordering and auto-assign up to 2 ready tasks at a time to @backend-eng
|
||||
pc channels update build/auth --ordering strict_fifo --managed-pool @backend-eng --max-concurrency 2
|
||||
```
|
||||
|
||||
Workers post ordinary progress updates with `pc reply`, and the server validates the structured result only at completion:
|
||||
|
||||
```sh
|
||||
pc tasks complete PAP-88 "Audit finished; 0 remaining issues." \
|
||||
--data '{"passed":true,"total":14,"failed":0}' --as scanner-1
|
||||
```
|
||||
|
||||
Missing or invalid `--data` returns `422 missing_or_invalid_result_schema` and leaves the task open until valid structured output is provided.
|
||||
*(Note: because `@backend-eng` was created with `pc agent connect`, it is a pull-only `headless` agent — `--managed-pool` automatically assigns up to 2 ready tasks to `@backend-eng` for your external `pc tasks run --ready build/auth --mine --as backend-eng` worker to drain. To have Paperclip automatically wake and execute tasks in managed sandboxes with no external worker loop, point `--managed-pool` at an agent configured with a managed runtime adapter such as Claude, Codex, or Paperclip Runner.)*
|
||||
|
||||
---
|
||||
|
||||
## Tutorial 4: Graduating to Paperclip Cloud & Strict Agent Keys
|
||||
## Tutorial 4: Multi-Agent Workflow Patterns at a Glance
|
||||
|
||||
**Why this is useful:** On Day 1 (`local_trusted`), unverified `--as worker-1` profiles let you iterate in seconds. On Day 2 — on a shared team server or Paperclip Cloud — `agentIdentityPolicy` defaults to `strict_agent_keys` so nobody can spoof an `@agent` identity. You can keep the exact same `--as <name>` workflow while backing it with real, revocable `agent_api_key` credentials, Projects, and Task Watchdogs.
|
||||
Most multi-agent systems built on Paperclip channels combine two queue shapes and three workflow patterns.
|
||||
|
||||
### 1. Log in to Paperclip Cloud as a human
|
||||
### Queue shapes
|
||||
- **Direct Work Queue (Drop & Drain):** Producers call `pc tasks create <channel>` (`status=todo`) and a pool of fungible workers drains it in parallel with `pc tasks run --ready <channel>`.
|
||||
- **Two-Step Inbox (Passive Drop → Triage → Promote or `assign`):** Noisy signals land via `pc post <channel>` (`status=backlog`, zero worker wakeups). A human or triage bot (`pc tasks claim --ready <channel> --status backlog`) either promotes survivors (`pc tasks create DEM-7`), push-assigns them to an existing agent (`pc tasks assign DEM-7 @backend-eng`), or cancels noise (`pc tasks cancel DEM-8`).
|
||||
|
||||
### Three workflow patterns
|
||||
|
||||
| Pattern | Best When | How It Works |
|
||||
| :--- | :--- | :--- |
|
||||
| **Single-Thread Relay** | One unit of work (support ticket, PR, article) moves through specialists who need the **entire thread history** in one place. | Workers use `pc tasks handoff <id> --channel <next> --label stage=<next> --if stage=<prev>` (or stay in one channel and advance `--label stage=...`) to atomically move the same issue and drop the lease. |
|
||||
| **Assembly Line** | Stages produce **distinct artifacts**, need **1-to-many fan-out** (1 audit → 5 fixes), or have different queue policies/permissions. | Give each stage its own channel (`seo/topics` → `seo/briefs` → `seo/drafts` → `seo/publish`). Workers complete Stage *N* and create one or more `todo` tasks in Stage *N+1*. Monitor queue depth with `pc channels list --prefix seo/`. |
|
||||
| **DAG Fan-Out / Fan-In** | Parallel tracks converge on a final step (`needs`), or workers uncover new prerequisites mid-flight. | Submit known graphs atomically with `pc tasks create <channel> --file plan.json`, and park mid-flight blockers with `pc tasks block <id> --needs <blocker>`. |
|
||||
|
||||
For complete end-to-end recipes (Software Factory, Customer Service Review, SEO/AEO Content Engine, and Feature Launch Campaign), see [`.agents/skills/channels-queues-and-workflows/SKILL.md`](../.agents/skills/channels-queues-and-workflows/SKILL.md) and [`examples.md`](../.agents/skills/channels-queues-and-workflows/examples.md).
|
||||
|
||||
---
|
||||
|
||||
## Tutorial 5: Graduating to Paperclip Cloud & Strict Agent Keys
|
||||
|
||||
**Why this is useful:** On Day 1 (`local_trusted`), unverified `--as worker-1` profiles let you iterate in seconds. On Day 2 — on a shared team server or Paperclip Cloud — `agentIdentityPolicy` defaults to `strict_agent_keys` so nobody can spoof an `@agent` identity. You keep the exact same `--as <name>` workflow while backing it with revocable `agent_api_key` credentials, Projects, and Task Watchdogs.
|
||||
|
||||
### 1. Log in to Paperclip Cloud and mint a headless agent key
|
||||
|
||||
```sh
|
||||
# Log in as a human operator (replace with your Cloud instance URL)
|
||||
pc auth login --api-base https://acme.paperclip.app
|
||||
|
||||
# Mint a dedicated headless agent key from an already-logged-in shell:
|
||||
pc agent connect security-scanner --role scanner --ttl 7d
|
||||
|
||||
# Or from a fresh container / remote CI runner via browser approval:
|
||||
pc agent login --name security-scanner --api-base https://acme.paperclip.app
|
||||
```
|
||||
|
||||
This creates a browser-approved challenge, opens/prints the approval URL, and stores your Board key locally.
|
||||
Both `agent connect` and `agent login` create or reuse a lightweight `adapterType: "headless"` agent and save its token under `~/.paperclip/profiles/security-scanner`.
|
||||
|
||||
### 2. Acquire a dedicated `headless` agent key
|
||||
|
||||
Mint a dedicated `agent_api_key` without configuring an LLM adapter, `cwd`, or system prompt:
|
||||
|
||||
- **From an already-logged-in shell:**
|
||||
```sh
|
||||
pc agent connect security-scanner --role scanner --ttl 7d
|
||||
```
|
||||
- **From a fresh container or remote CI runner (browser approval):**
|
||||
```sh
|
||||
pc agent login --name security-scanner --api-base https://acme.paperclip.app
|
||||
```
|
||||
|
||||
Both commands create/reuse a lightweight `adapterType: "headless"` agent row and save its token under `~/.paperclip/profiles/security-scanner`.
|
||||
|
||||
### 3. Understand how `--as <name>` behaves across policies
|
||||
### 2. Understand how `--as <name>` behaves across identity policies
|
||||
|
||||
Every company enforces one of three `agentIdentityPolicy` modes:
|
||||
- `open_local_profiles` (default on `local_trusted`)
|
||||
- `delegated_profiles` (verified human key + `--as <name>`, attributed as `<name> via <user>`)
|
||||
- `strict_agent_keys` (default on Paperclip Cloud & `authenticated/public`)
|
||||
|
||||
What happens when you pass `--as <name>` depends on whether `<name>` exists in the company's `agents` table and whether you hold its `agent_api_key`:
|
||||
|
||||
| Scenario | Registered Agent `<name>` Exists? | Local `<name>` `agent_api_key` Held? | Result |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| Ad-hoc profile (`--as worker-1`) | No | N/A | Under `open_local_profiles` / `delegated_profiles`: succeeds with no `agents` row created (`worker-1 (local)` or `worker-1 via <user>`). Under `strict_agent_keys`: rejected with `403 agent_key_required` and hints `pc agent connect worker-1`. |
|
||||
| Ad-hoc profile (`--as worker-1`) | No | N/A | Under `open_local_profiles` / `delegated_profiles`: succeeds with no `agents` row created. Under `strict_agent_keys`: rejected with `403 agent_key_required` and hints `pc agent connect worker-1`. |
|
||||
| Connected agent (`--as security-scanner` after `pc agent connect`) | Yes | Yes | CLI automatically selects `security-scanner`'s saved `agent_api_key`; server authenticates directly as `@security-scanner` with its own RBAC, ACLs, and budget. |
|
||||
| Name collision without key (`--as ceo` using only a human key) | Yes | No | **Fails closed with `409 profile_matches_registered_agent`** so a human login never impersonates or mimics a registered `@agent`. Authenticate via `pc agent connect ceo` or choose a distinct ad-hoc name. |
|
||||
| Name collision without key (`--as backend-eng` using only a human key) | Yes | No | **Fails closed with `409 profile_matches_registered_agent`** so a human login never impersonates a registered `@agent`. Authenticate via `pc agent connect` or choose a distinct ad-hoc name. |
|
||||
|
||||
Check your active resolution at any time:
|
||||
|
||||
@@ -272,16 +346,18 @@ Check your active resolution at any time:
|
||||
pc whoami --as security-scanner
|
||||
```
|
||||
|
||||
### 4. Graduate a queue to managed Runners and Projects
|
||||
### 3. Graduate a queue to managed Runners and Projects
|
||||
|
||||
Once your channel queue is proven locally:
|
||||
1. Bind a default codebase to the channel (`POST /api/companies/:companyId/channels` with `defaultProjectId`) or pass `--project <slug>` on `pc tasks create` / `plan.json`.
|
||||
2. Configure `channels.queue_config.managedPool` to let Paperclip's managed Runner spin up isolated sandboxes to drain the channel automatically under company budgets and Task Watchdogs — with **zero changes** to the `pc post` / `pc tasks create` / `plan.json` scripts submitting work.
|
||||
Once your channel queue is proven locally, bind a Project and a managed Runner agent (an agent configured with a runtime adapter, not a pull-only `headless` agent) with **zero changes** to the `pc post` / `pc tasks create` scripts submitting work:
|
||||
|
||||
```sh
|
||||
pc channels update build/auth --project web-app --managed-pool @coder --max-concurrency 4
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Reference Example: Building a Custom Minimal Web UI
|
||||
|
||||
Because Channels, Tasks, Interactions, and SSE streams are exposed through `paperclipai/sdk`, you can build custom dashboards or lightweight team viewers without modifying Paperclip's main React board UI.
|
||||
Because Channels, Tasks, Interactions, and SSE streams are exposed through `@paperclipai/shared/sdk`, you can build custom dashboards or lightweight team viewers without modifying Paperclip's main React board UI.
|
||||
|
||||
See [`tools/experimental/channels-viewer/`](../tools/experimental/channels-viewer/README.md) for a zero-dependency runnable example (`./tools/experimental/channels-viewer/bin/paperclip-channels-viewer.mjs`) that renders a live monospace `activity`, `#channel`, `tasks`, and `thread` viewer using standard Paperclip authentication.
|
||||
Reference in new issue
Block a user