Files
PaperClipAI/doc/HEADLESS-TUTORIALS.md
T
Dotta f0ee1b40f0 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
2026-12-02 00:56:34 +00:00

19 KiB

Headless Paperclip Tutorials

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.

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 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.


Tutorial 1: 60-Second Local Agent Board

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 an isolated local board (Terminal 1)

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: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 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.

(Optional: open a third terminal and run pc tail to watch live SSE board events stream as you paste the commands below.)

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:

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

On a fresh Demo board, those two posts are created as DEM-1 and DEM-2.

Read a channel, reply to DEM-1, and query an entire slash-path subtree with a trailing /:

pc read deploys
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 (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 DEM-1:

# Replay the existing comment immediately from evt_0:
pc wait DEM-1 --after evt_0 --event comment.posted,task.completed --timeout 30s --json

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: 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 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. Register an inline result schema and submit a 3-task DAG

First, register a versioned schema (test-summary@1) inline so the final review task enforces structured output at completion:

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 -):

cat <<'EOF' | pc tasks create build/auth --file - --as lead
{
  "idempotencyKey": "jwt-refactor-v1",
  "tasks": [
    {
      "key": "patch",
      "title": "Patch JWT expiry check in src/auth.ts",
      "description": "Owned paths: src/auth.ts. Verify with unit tests.",
      "priority": "high",
      "labels": { "role": "worker", "step": "fix" }
    },
    {
      "key": "audit-api",
      "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",
      "title": "Adversarial review of auth patch and caller audit",
      "labels": { "role": "reviewer" },
      "needs": ["patch", "audit-api"],
      "resultSchema": "test-summary@1"
    }
  ]
}
EOF

(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.)

On our fresh Demo board, this creates DEM-3 (patch), DEM-4 (audit-api), and DEM-5 (review). Check the ready queue:

pc tasks list --channel build/auth --ready

Only DEM-3 and DEM-4 appear as ready; DEM-5 stays waiting until both finish.

2. Drain DEM-3 with pc tasks run

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:

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);
'

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. Discover a blocker mid-flight (pc tasks block --needs)

Claim DEM-4 manually, then suppose worker-2 discovers a prerequisite task (DEM-6) that must finish before DEM-4 can continue:

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

Now finish DEM-6, watch DEM-4 automatically become ready again, and finish DEM-4:

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

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:

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

(Missing or invalid --data returns 422 missing_or_invalid_result_schema and leaves the task open until valid structured output is supplied.)


Tutorial 3: Assigning to Existing Agents, Atomic handoff, Claim Filters, Cancel/Reopen & Channel Admin

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. Push-assign an existing post to a registered agent (pc tasks assign & --mine)

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:

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"

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):

pc tasks claim --ready errors/web --mine --as backend-eng
pc tasks complete DEM-7 "Added nil guard and regression test." --as backend-eng

(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.)

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:

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"

3. Atomic handoff (move) across channels + CAS labels (--if)

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:

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:

# 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:

pc post security/findings "Found unescaped SQL in legacy report" \
  --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 DEM-10 without matching the schema, while scripts read blocks[0].data cleanly.

5. Private channels, member access & managed-pool auto-drain

Administer channel visibility, explicit members, queue ordering, and managed-pool auto-dispatch from the CLI:

# 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

(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: Multi-Agent Workflow Patterns at a Glance

Most multi-agent systems built on Paperclip channels combine two queue shapes and three workflow patterns.

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 and 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

# 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

Both agent connect and agent login create or reuse a lightweight adapterType: "headless" agent and save its token under ~/.paperclip/profiles/security-scanner.

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)
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. 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 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:

pc whoami --as security-scanner

3. Graduate a queue to managed Runners and Projects

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:

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/shared/sdk, you can build custom dashboards or lightweight team viewers without modifying Paperclip's main React board UI.

See tools/experimental/channels-viewer/ 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.