@cleocode/playbooks

中文文档
2026.11.1发布于 2026/11/12MITTypeScriptES Module构建来源已验证近 30 天下载 1.1万

Playbook DSL + runtime for CLEO — T889 Orchestration Coherence v3

原始使用文档
文档目录12 节
  1. Status
  2. Install
  3. What a .cantbook looks like
  4. Quick API
  5. Database tables
  6. playbook_runs
  7. playbook_approvals
  8. Approval tokens (HMAC)
  9. Error codes
  10. Policy evaluator
  11. Related packages
  12. Testing

@cleocode/playbooks

Part of CLEO. Start with the root README; run cleo <command> --help for any command.

Playbook DSL + runtime for CLEO — T889 Orchestration Coherence v3.

Playbooks are .cantbook YAML documents that describe a multi-step agent workflow as a DAG of nodes (agentic, deterministic, and approval gates) connected by typed edges. This package parses them, persists execution state to tasks.db, evaluates HITL auto-policies, and manages HMAC-signed approval tokens for human-in-the-loop gates.

Status

WaveConcernStatus
W4-6Drizzle tables + typesshipped
W4-7.cantbook YAML parsershipped
W4-8State layer CRUDshipped
W4-9HITL auto-policy evaluatorshipped
W4-10State-machine runtimepending
W4-16Approval resume tokens (HMAC)shipped

The runtime executor (runtime.ts) is the next ship — parser + state + policy + approval primitives are in place.

Install

This is an internal monorepo package. Consumers use it via workspace dependency:

// package.json
{
  "dependencies": {
    "@cleocode/playbooks": "workspace:*"
  }
}

What a .cantbook looks like

version: "1.0"
name: release-cut
description: Cut a CalVer release and publish to npm

inputs:
  - name: version
    required: true
    description: Target version (e.g. 2026.4.90)

nodes:
  - id: build
    type: deterministic
    command: pnpm
    args: [run, build]

  - id: test
    type: deterministic
    command: pnpm
    args: [run, test]
    depends: [build]

  - id: review
    type: approval
    prompt: "Build + tests green. Publish {{ version }} to npm?"
    depends: [test]

  - id: publish
    type: agentic
    skill: release-publisher
    depends: [review]

edges:
  - from: build
    to: test
    contract:
      requires: [dist-exists]
      ensures: [tests-passed]
  - from: test
    to: review
  - from: review
    to: publish

error_handlers:
  - on: test-failed
    action: abort
    message: "Tests failed — aborting release."

Validation rules enforced by the parser:

  • version MUST be "1.0".
  • name MUST be non-empty.
  • Node ids MUST be unique.
  • Every edges[].from / edges[].to MUST reference a known node id.
  • Nodes + edges MUST form a DAG (no cycles).
  • agentic nodes MUST have skill OR agent (at least one).
  • deterministic nodes MUST have command + args.
  • approval nodes MUST have prompt.
  • depends[] entries MUST be valid node ids.
  • iteration_cap / max_iterations MUST be in 0..10 (hard limit).

Quick API

import {
  parsePlaybook,
  createPlaybookRun,
  updatePlaybookRun,
  evaluatePolicy,
  createApprovalGate,
  approveGate,
  rejectGate,
  DEFAULT_POLICY_RULES,
} from '@cleocode/playbooks';

// 1. Parse a .cantbook file
const { playbook, hash } = parsePlaybook(yamlSource);

// 2. Create a persisted run
const run = createPlaybookRun(tasksDb, {
  runId: 'run_abc123',
  playbookName: playbook.name,
  playbookHash: hash,
  bindings: { version: '2026.4.90' },
  epicId: 'T889',
  sessionId: 'ses_xyz',
});

// 3. Evaluate auto-policy at an approval node
const { autoPassed, reason } = evaluatePolicy(node, DEFAULT_POLICY_RULES, context);

// 4. Create an approval gate (pending) or auto-pass it
const approval = createApprovalGate(tasksDb, {
  runId: run.runId,
  nodeId: 'review',
  autoPassed,
});

// 5. Resolve the gate (human approves via the resume token)
approveGate(tasksDb, approval.token, { approver: 'keaton', reason: 'LGTM' });

Database tables

Both tables live in tasks.db. Migration: packages/core/migrations/drizzle-tasks/20260417220000_t889-playbook-tables/.

playbook_runs

ColumnTypeNotes
run_idtext PKcaller-supplied run id
playbook_nametextfrom parsed playbook
playbook_hashtextSHA-256 of source (parser computes)
current_nodetextid of the active node, null when done
bindingsjson textaccumulated input + per-node output bindings
error_contextjson textpopulated when status = 'failed'
statustextrunning | paused | failed | succeeded | cancelled
iteration_countsjson text{ nodeId: count } — enforced against iteration_cap
epic_idtextlinked task epic (optional)
session_idtextlinked CLEO session (optional)
started_attextISO-8601, defaults to now()
completed_attextISO-8601 when terminal

playbook_approvals

ColumnTypeNotes
approval_idtext PK
run_idtextFK → playbook_runs.run_id
node_idtextapproval node id in the playbook
tokentext UNIQUEHMAC resume token
requested_attextISO-8601
approved_attextISO-8601 on approve/reject
approvertextwho acted
reasontextfree-form rationale
statustextpending | approved | rejected
auto_passedint 0/1set by the policy evaluator

Approval tokens (HMAC)

Resume tokens are HMAC-SHA-256 signed with the secret resolved from getPlaybookSecret(env):

  1. CLEO_PLAYBOOK_SECRET (preferred)
  2. CLEO_SECRET (fallback)
  3. Hard error if neither is set — approval nodes cannot be created without a secret.

Tokens encode {runId, nodeId, issuedAt} and are verified before any approveGate / rejectGate call. Replay-resistant: an already-decided approval returns E_APPROVAL_ALREADY_DECIDED.

Error codes

ConstantMeaning
E_APPROVAL_NOT_FOUNDToken does not match any pending approval row
E_APPROVAL_ALREADY_DECIDEDApproval is already approved or rejected
PlaybookParseErrorThrown by parsePlaybook with a list of validation issues

Policy evaluator

evaluatePolicy(node, rules, context) matches an approval node against an ordered list of PolicyRules. The first rule that matches decides: autoPassed: true | false plus a reason. Used to let low-risk approval gates auto-pass (e.g. "build dist unchanged from last green run") without bothering a human. DEFAULT_POLICY_RULES ships a safe conservative default set.

  • @cleocode/contracts — PlaybookDefinition, PlaybookRun, PlaybookApproval type contracts consumed here.
  • @cleocode/core — owns tasks.db lifecycle. Playbook migrations are applied by core's drizzle runner.
  • @cleocode/cleo — CLI surface that will expose cleo playbook run, cleo playbook approve <token> once the runtime (W4-10) lands.

Testing

pnpm --filter @cleocode/playbooks test

Smoke, parser, schema, state, policy, and approval test suites cover the shipped surface.

版本与发布记录

@cleocode/playbooks 共发布 296 个版本,首次发布于 2026/04/18;过去 12 个月发布了 296 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2026.11.1latest2026/11/12今天
2026.11.1-rc.ci.711canary2026/11/12今天
2026.11.1-canary.122026/11/12今天
2026.11.1-canary.112026/11/12今天
2026.11.1-canary.102026/11/12今天
2026.11.1-canary.92026/11/111 天前

关于 @cleocode/playbooks 的常见问题

@cleocode/playbooks 是什么?

Playbook DSL + runtime for CLEO — T889 Orchestration Coherence v3

如何安装 @cleocode/playbooks?

在项目目录运行 npm install @cleocode/playbooks,或使用 pnpm add / yarn add / bun add。

@cleocode/playbooks 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cleocode/playbooks 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cleocode/playbooks 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.16.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cleocode/playbooks 可以商用吗?

@cleocode/playbooks 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cleocode/playbooks 的下载量有多少?

根据 npm 官方下载统计,@cleocode/playbooks 在 2026/10/10 – 2026/11/08 这 30 天内被下载 10,707 次,日均约 357 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cleocode/playbooks 还在维护吗?

最新版本 2026.11.1 发布于 2026/11/12(今天);至今共发布 296 个版本,其中过去 12 个月发布了 296 个;首次发布于 2026/04/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。