@sublang/playbook 7.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +20 -7
  2. package/docs/cli.md +88 -43
  3. package/docs/configuration.md +221 -119
  4. package/docs/embedding.md +78 -27
  5. package/package.json +4 -3
  6. package/reference/sdlc/captain.playbook/captain.playbook.js +16 -5
  7. package/reference/sdlc/captain.playbook/captain.playbook.ts +20 -6
  8. package/reference/sdlc/code.md +1 -1
  9. package/reference/sdlc/code.playbook/bin/interactive-session.js +816 -0
  10. package/reference/sdlc/code.playbook/bin/launch-config.js +1078 -116
  11. package/reference/sdlc/code.playbook/bin/playbook.js +489 -34
  12. package/reference/sdlc/code.playbook/bin/run.js +283 -298
  13. package/reference/sdlc/code.playbook/bin/session-store.js +818 -26
  14. package/reference/sdlc/code.playbook/code.fsm.d.ts +9 -6
  15. package/reference/sdlc/code.playbook/code.fsm.introspect.js +2 -2
  16. package/reference/sdlc/code.playbook/code.fsm.introspect.ts +2 -2
  17. package/reference/sdlc/code.playbook/code.fsm.js +18 -15
  18. package/reference/sdlc/code.playbook/code.fsm.ts +21 -21
  19. package/reference/sdlc/code.playbook/code.gears.md +1 -1
  20. package/reference/sdlc/code.playbook/code.playbook.d.ts +2 -1
  21. package/reference/sdlc/code.playbook/code.playbook.js +25 -15
  22. package/reference/sdlc/code.playbook/code.playbook.ts +34 -17
  23. package/reference/sdlc/code.playbook/code.registry.d.ts +5 -13
  24. package/reference/sdlc/code.playbook/code.registry.js +3 -10
  25. package/reference/sdlc/code.playbook/code.registry.ts +7 -32
  26. package/reference/sdlc/code.playbook/playbook-captain.d.ts +39 -14
  27. package/reference/sdlc/code.playbook/playbook-captain.js +1014 -299
  28. package/reference/sdlc/code.playbook/playbook-captain.ts +1450 -406
  29. package/reference/sdlc/code.playbook/playbook.config.template.yaml +41 -49
  30. package/reference/sdlc/decide.md +4 -4
  31. package/reference/sdlc/decide.playbook/decide.fsm.d.ts +10 -10
  32. package/reference/sdlc/decide.playbook/decide.fsm.js +21 -14
  33. package/reference/sdlc/decide.playbook/decide.fsm.ts +27 -23
  34. package/reference/sdlc/decide.playbook/decide.gears.md +3 -5
  35. package/reference/sdlc/decide.playbook/decide.playbook.d.ts +11 -13
  36. package/reference/sdlc/decide.playbook/decide.playbook.js +465 -246
  37. package/reference/sdlc/decide.playbook/decide.playbook.ts +623 -283
  38. package/reference/sdlc/decide.playbook/decide.registry.d.ts +5 -13
  39. package/reference/sdlc/decide.playbook/decide.registry.js +3 -9
  40. package/reference/sdlc/decide.playbook/decide.registry.ts +7 -31
  41. package/reference/sdlc/review.md +4 -5
  42. package/reference/sdlc/review.playbook/review.fsm.d.ts +9 -11
  43. package/reference/sdlc/review.playbook/review.fsm.js +30 -24
  44. package/reference/sdlc/review.playbook/review.fsm.ts +39 -35
  45. package/reference/sdlc/review.playbook/review.gears.md +6 -5
  46. package/reference/sdlc/review.playbook/review.playbook.d.ts +2 -1
  47. package/reference/sdlc/review.playbook/review.playbook.js +29 -23
  48. package/reference/sdlc/review.playbook/review.playbook.ts +38 -28
  49. package/reference/sdlc/review.playbook/review.registry.d.ts +5 -13
  50. package/reference/sdlc/review.playbook/review.registry.js +3 -16
  51. package/reference/sdlc/review.playbook/review.registry.ts +7 -38
  52. package/slc/gears2fsm.md +45 -24
  53. package/slc/link.md +297 -135
  54. package/slc/text2gears.md +19 -18
  55. package/src/runtime.d.ts +21 -16
  56. package/src/runtime.ts +20 -23
  57. package/src/xstate-playbook-runtime.d.ts +34 -20
  58. package/src/xstate-playbook-runtime.js +973 -400
  59. package/src/xstate-playbook-runtime.ts +1203 -457
  60. package/src/xstate-runtime.d.ts +17 -7
  61. package/src/xstate-runtime.js +198 -81
  62. package/src/xstate-runtime.ts +339 -112
@@ -3,7 +3,7 @@
3
3
 
4
4
  # Configuring agents
5
5
 
6
- `playbook` and every fresh `playbook run` read one config at
6
+ Fresh launches and ordinary reopens read one config at
7
7
  `${XDG_CONFIG_HOME:-$HOME/.config}/playbook/playbook.config.yaml`. The
8
8
  first launch seeds it from the bundled starter and prints the path;
9
9
  later launches reuse it untouched.
@@ -14,28 +14,35 @@ $EDITOR "${XDG_CONFIG_HOME:-$HOME/.config}/playbook/playbook.config.yaml"
14
14
 
15
15
  ## Anatomy
16
16
 
17
- The config is top-level (no `config:` wrapper): a `captain` agent (it
18
- runs the session Captain's hidden control calls, the hidden judge calls,
19
- and the replies you see in the Captain pane or on headless stdout), optional
20
- `layout` / `notifications` / `theme`, and a `playbooks` map of enabled
21
- playbooks. Those three presentation fields apply only to interactive tmux;
22
- headless runs ignore them.
23
-
24
- Each `captain` or `players.<role>` value is either an adapter shorthand
25
- (`claude`, `codex`) or a block carrying that agent's own `adapter`,
26
- `model`, `effort`, and `permissions`. Settings are inline per agent, so
27
- tuning one player never changes another
28
- ([DR-021](../specs/decisions/021-inline-agent-settings.md)). Other
29
- adapter ids pass through to `tmux-play` with a warning, because
30
- `playbook` cannot preflight their auth.
31
-
32
- Within a `playbooks.<id>` block, `from` (the registry module), `command`
33
- (an optional slash-command override), and `players` are launcher-owned;
34
- every other key is that playbook's option slice. The launcher injects
35
- the rest you do not write host wiring by hand.
36
-
37
- The seeded config runs each Coder on Claude Opus 4.8 1m and each
38
- Reviewer on GPT-5.5:
17
+ The config is top-level (no `config:` wrapper): a `captain` agent, one flat
18
+ `players` map of stable Captain-session agents, a `playbooks` map of enabled
19
+ workflows and their explicit role bindings, and optional `layout` /
20
+ `notifications` / `theme`. The Captain runs hidden control and judge calls and
21
+ writes the replies you see in the Captain pane or on headless stdout. The three
22
+ presentation fields apply only to interactive tmux; headless runs ignore them.
23
+
24
+ A **role** is local to a playbook artifact: CODE's `coder` and REVIEW's `coder`
25
+ have the same semantic name but remain separate declarations. A **player** is
26
+ a stable session-wide provider conversation with an exact ID such as
27
+ `dev.coder`. A role uses only the player named by its binding; matching role
28
+ names, nesting, and ancestry never infer a binding.
29
+
30
+ Each `captain` or `players.<player-id>` value is either an adapter shorthand
31
+ (`claude`, `codex`) or a block carrying that agent's own `adapter`, `model`,
32
+ `effort`, `instruction`, and `permissions`. Settings are inline per stable
33
+ agent ([DR-021](https://github.com/sublang-ai/playbook/blob/main/specs/decisions/021-inline-agent-settings.md)). Dots in a
34
+ player ID are literal characters, not YAML hierarchy. Other adapter IDs pass
35
+ through to `tmux-play` with a warning because `playbook` cannot preflight their
36
+ auth.
37
+
38
+ Within a `playbooks.<id>` block, `from` (the registry module), `command` (an
39
+ optional slash-command override), and `roles` are launcher-owned; every other
40
+ key is that playbook's option slice. Every manifest role must be present
41
+ exactly once. The launcher injects the rest — you do not write host wiring by
42
+ hand.
43
+
44
+ The seeded config runs the stable Coder player on Claude Opus 4.8 1m and the
45
+ stable Reviewer player on GPT-5.5:
39
46
 
40
47
  ```yaml
41
48
  captain:
@@ -45,86 +52,116 @@ captain:
45
52
  permissions:
46
53
  mode: auto # protected auto mode for the Claude Captain
47
54
 
55
+ players:
56
+ dev.coder:
57
+ adapter: claude
58
+ model: claude-opus-4-8[1m]
59
+ effort: xhigh
60
+ permissions:
61
+ mode: auto # protected auto mode for the Claude Coder
62
+
63
+ dev.reviewer:
64
+ adapter: codex
65
+ model: gpt-5.5
66
+ effort: xhigh
67
+ permissions:
68
+ mode: auto
69
+ writablePaths:
70
+ - .git # allow git metadata writes under Codex auto mode
71
+
48
72
  playbooks:
49
73
  code:
50
74
  from: '@sublang/playbook/code/registry'
51
- players:
52
- coder:
53
- adapter: claude
54
- model: claude-opus-4-8[1m]
55
- effort: xhigh
56
- permissions:
57
- mode: auto # protected auto mode for the Claude Coder
75
+ roles:
76
+ coder: dev.coder
58
77
 
59
78
  review:
60
79
  from: '@sublang/playbook/review/registry'
61
- players:
62
- coder:
63
- adapter: claude
64
- model: claude-opus-4-8[1m]
65
- effort: xhigh
66
- permissions:
67
- mode: auto
68
- reviewer:
69
- adapter: codex
70
- model: gpt-5.5
71
- effort: xhigh
72
- permissions:
73
- mode: auto
74
- writablePaths:
75
- - .git # allow git metadata writes under Codex auto mode
80
+ roles:
81
+ coder: dev.coder
82
+ reviewer: dev.reviewer
76
83
 
77
84
  decide:
78
85
  from: '@sublang/playbook/decide/registry'
79
- players:
80
- coder:
81
- adapter: claude
82
- model: claude-opus-4-8[1m]
83
- effort: xhigh
84
- permissions:
85
- mode: auto
86
- reviewer:
87
- adapter: codex
88
- model: gpt-5.5
89
- effort: xhigh
90
- permissions:
91
- mode: auto
92
- writablePaths:
93
- - .git
86
+ roles:
87
+ coder: dev.coder
88
+ reviewer: dev.reviewer
94
89
  ```
95
90
 
96
91
  The current bundled workflows accept no workflow-specific options.
97
- Each role's per-run prompt names its pinned `model`, else its `adapter`
98
- ([[playbook-runtime-4](../specs/packages/playbook-runtime.md#playbook-runtime-4)]),
92
+ Each role's per-call prompt names its current `model`, else its player's
93
+ `adapter`
94
+ ([[playbook-runtime-4](https://github.com/sublang-ai/playbook/blob/main/specs/packages/playbook-runtime.md#playbook-runtime-4)]),
99
95
  so commit trailers credit the concrete model rather than the adapter
100
96
  family.
101
97
 
102
- ## Nested roles and sessions
98
+ ## Role binding forms
99
+
100
+ The shortest binding is a scalar stable player ID:
101
+
102
+ ```yaml
103
+ roles:
104
+ coder: dev.coder
105
+ ```
106
+
107
+ Use a block to override only that role invocation's model or effort:
108
+
109
+ ```yaml
110
+ roles:
111
+ coder:
112
+ player: dev.coder
113
+ model: claude-opus-4-8[1m]
114
+ effort: false # explicitly reset to this provider's default
115
+ ```
116
+
117
+ Omitting `model` or `effort` inherits that player's top-level default. The
118
+ boolean `false` is different: it selects the provider default explicitly, so a
119
+ resumed conversation cannot accidentally retain an earlier selection. A role
120
+ binding cannot override adapter, instruction, permissions, workspace, or tool
121
+ posture; those define the stable player envelope.
103
122
 
104
- The launcher creates a namespaced fallback player for every configured
105
- playbook role, but a nested call maps an exact same-name role to the
106
- nearest ancestor's effective player and backend conversation. CODE's
107
- nested REVIEW therefore continues CODE's `coder` and uses REVIEW's
108
- configured `reviewer`; DECIDE's nested REVIEW continues both of
109
- DECIDE's roles. A standalone REVIEW starts with REVIEW's own configured
110
- players, and every new root engagement starts fresh
111
- ([DR-030](../specs/decisions/030-shared-mapped-player-continuity.md)).
123
+ ## Sharing, isolation, and concurrency
112
124
 
113
- The separate fallback entries are still required because tmux creates
114
- its roster at launch time. The host changes which existing panes are
115
- visible as the active nested leaf changes; it does not create a new
116
- host player or backend agent session for a mapped role.
125
+ Two bindings that name the same player ID deliberately share one sequential
126
+ provider conversation throughout the logical Captain session across nested
127
+ calls, returns, and later root engagements. CODE's and REVIEW's `coder` roles
128
+ therefore share `dev.coder` in the starter, and DECIDE and its nested REVIEW
129
+ share both starter players. Disposal of one playbook frame does not clear that
130
+ session ledger.
131
+
132
+ Two distinct player IDs stay isolated even when their agent blocks are
133
+ byte-for-byte equal. To give standalone REVIEW an independent Coder, define a
134
+ second top-level player and change only its binding:
135
+
136
+ ```yaml
137
+ players:
138
+ review.coder:
139
+ adapter: claude
140
+ model: claude-opus-4-8[1m]
141
+ effort: xhigh
142
+
143
+ playbooks:
144
+ review:
145
+ from: '@sublang/playbook/review/registry'
146
+ roles:
147
+ coder: review.coder
148
+ reviewer: dev.reviewer
149
+ ```
150
+
151
+ Roles a manifest may run concurrently must bind to distinct IDs. DECIDE's
152
+ `coder` and `reviewer` are concurrent, so aliasing both to one player rejects
153
+ before registry import, host creation, or agent work.
117
154
 
118
155
  ## Choosing the Captain agent
119
156
 
120
157
  Every session-Captain call and adjudication call is hidden and runs
121
158
  tool-free, which is what keeps the Captain deciding and reporting
122
- instead of doing the work itself. Claude enforces
123
- that at the provider level. The Codex adapter cannot — it rejects any
124
- tool list — so a `captain:` on `codex` falls back to a prompt-level
125
- restriction
126
- ([DR-013](../specs/decisions/013-routing-only-captain-control.md) A1).
127
- Codex remains a good choice for *players*, where full tools are wanted.
159
+ instead of doing the work itself. Claude and Gemini enforce that at the
160
+ provider level. The Codex, Kimi, and OpenCode adapters cannot — they
161
+ reject any tool list — so a `captain:` using one of them falls back to a
162
+ prompt-level restriction
163
+ ([DR-013](https://github.com/sublang-ai/playbook/blob/main/specs/decisions/013-routing-only-captain-control.md) A1).
164
+ Those adapters remain good choices for *players*, where full tools are wanted.
128
165
 
129
166
  Adapter readiness is intentionally light: `claude` is ready with local
130
167
  Claude Code auth or `ANTHROPIC_API_KEY`; `codex` with local Codex CLI
@@ -143,40 +180,52 @@ playbook run --with fast-lineup.yaml "/code implement the approved change"
143
180
  ```
144
181
 
145
182
  ```yaml
146
- # fast-lineup.yaml — swap the Coder for one run; nothing is written back.
183
+ # fast-lineup.yaml — retune the shared Coder; nothing is written back.
184
+ players:
185
+ dev.coder:
186
+ model: claude-opus-4-8
187
+ effort: medium
188
+ ```
189
+
190
+ Fragments merge into the agent block rather than replacing it, so
191
+ settings the base defines and the fragment omits — here the adapter,
192
+ instruction, and permissions — survive. Retuning a top-level player affects
193
+ every bound role that does not override that field. To retune only one role,
194
+ overlay its binding instead:
195
+
196
+ ```yaml
147
197
  playbooks:
148
198
  code:
149
- players:
199
+ roles:
150
200
  coder:
151
- adapter: codex
152
- model: gpt-5.5
153
- effort: medium
154
- permissions:
155
- mode: auto
156
- # CODE's Coder commits, so Codex needs the `.git` grant to write
157
- # repository metadata.
158
- writablePaths:
159
- - .git
201
+ player: dev.coder
202
+ effort: low
160
203
  ```
161
204
 
162
- Fragments merge into the agent block rather than replacing it, so
163
- settings the base defines and the fragment omits — here `mode: auto` —
164
- survive. Anything the adapter itself requires must still be stated: a
165
- role switched to `codex` needs its own `writablePaths` grant, because
166
- the base Claude block had no reason to carry one.
167
-
168
205
  The global file is never modified, and `--with` is not forwarded to
169
- `tmux-play` ([[playbook-cli-25](../specs/packages/playbook-cli.md#playbook-cli-25)]).
170
- Overlays apply only when creating a fresh session. A continued headless
171
- session restores its frozen config and working directory and rejects `--with`.
172
-
173
- ## Shared headless configuration
174
-
175
- Fresh interactive and headless sessions use the same top-level `captain`
176
- and `playbooks` blocks. A headless session retains the normalized lineup,
177
- catalog, options, and absolute working directory with every durable turn;
178
- continuation does not reread the current file. Presentation-only fields are
179
- inert headlessly.
206
+ `tmux-play` ([[playbook-cli-25](https://github.com/sublang-ai/playbook/blob/main/specs/packages/playbook-cli.md#playbook-cli-25)]).
207
+ Overlays apply when creating a fresh session and as current-config input for a
208
+ compatible ordinary reopen. A selected session keeps its stored catalog,
209
+ player roster, role bindings, adapter, instruction, permissions, and working
210
+ directory; only model and effort may change. The next call reapplies both
211
+ complete selections. An uncertain retry accepts no tuning overlay and uses the
212
+ exact attempted selections already stored with that turn.
213
+
214
+ ## Durable shared configuration
215
+
216
+ Fresh interactive and headless sessions use the same top-level Captain,
217
+ players, role bindings, and playbooks. Both persist the same logical-session
218
+ record, shell snapshot, player ledger, normalized catalog, structural agent
219
+ envelopes, last-applied tuning, and absolute working directory. A session
220
+ created by either front end can reopen through either front end with the same
221
+ public UUID. Presentation-only fields are inert headlessly.
222
+
223
+ An ordinary reopen reads current config and opening overlays, but first
224
+ projects them to the stored playbooks and referenced players. An unrelated new
225
+ entry cannot enter or invalidate the session. Structural drift fails closed;
226
+ compatible model or effort changes apply on the next provider call. Legacy
227
+ record, shell, runtime-snapshot, and trace schemas are rejected rather than
228
+ having role or player identity guessed.
180
229
 
181
230
  ## External playbooks
182
231
 
@@ -187,17 +236,25 @@ and `createRuntime`. Enable it under `playbooks`, bind every role listed in
187
236
  its `requiredRoleIds`, and invoke its effective slash command through Captain:
188
237
 
189
238
  ```yaml
239
+ players:
240
+ my.worker: claude
241
+
190
242
  playbooks:
191
243
  my-workflow:
192
244
  from: /absolute/path/to/my-workflow.ts
193
- players:
194
- worker: claude
245
+ roles:
246
+ worker: my.worker
195
247
  ```
196
248
 
197
249
  ```sh
198
250
  playbook run "/my-workflow perform the task"
199
251
  ```
200
252
 
253
+ Importing a `.ts` registry uses Node's native type stripping, available
254
+ unflagged on Node 22.18+ and 23.6+; on the older Node versions this
255
+ package supports (>= 20.6), compile the registry and point `from` at the
256
+ emitted `.js` module instead.
257
+
201
258
  A relative path-shaped `from` is resolved relative to the primary config
202
259
  file, not the invocation directory; an absolute path is clearest for an SLC
203
260
  entry emitted in a project working tree.
@@ -205,15 +262,60 @@ Before either front end imports a filesystem registry, the shared launcher
205
262
  checks and, unless `--no-provision` is set, provisions its runtime engine
206
263
  links as described in [Using the CLI](cli.md#external-playbooks-and-engine-provisioning).
207
264
 
265
+ ## Migrating per-playbook players
266
+
267
+ The former `playbooks.<id>.players` shape made agent configuration and local
268
+ workflow roles the same thing. It is removed. For example, this legacy config
269
+ gave CODE and REVIEW two separately configured `coder` entries:
270
+
271
+ ```yaml
272
+ playbooks:
273
+ code:
274
+ from: '@sublang/playbook/code/registry'
275
+ players:
276
+ coder: { adapter: claude, model: claude-opus-4-8[1m] }
277
+ review:
278
+ from: '@sublang/playbook/review/registry'
279
+ players:
280
+ coder: { adapter: claude, model: claude-opus-4-8[1m] }
281
+ reviewer: { adapter: codex, model: gpt-5.5 }
282
+ ```
283
+
284
+ Move each provider agent into the flat top-level map, choose stable IDs, and
285
+ bind the local roles explicitly:
286
+
287
+ ```yaml
288
+ players:
289
+ dev.coder: { adapter: claude, model: claude-opus-4-8[1m] }
290
+ dev.reviewer: { adapter: codex, model: gpt-5.5 }
291
+
292
+ playbooks:
293
+ code:
294
+ from: '@sublang/playbook/code/registry'
295
+ roles: { coder: dev.coder }
296
+ review:
297
+ from: '@sublang/playbook/review/registry'
298
+ roles:
299
+ coder: dev.coder
300
+ reviewer: dev.reviewer
301
+ ```
302
+
303
+ The launcher intentionally does **not** perform this migration for you. It
304
+ cannot know whether the two old `coder` blocks were meant to share one
305
+ conversation or remain isolated. Reusing `dev.coder` above chooses sharing;
306
+ using `code.coder` and `review.coder` would choose isolation. A surviving
307
+ per-playbook `players` block therefore rejects before profile migration,
308
+ registry preparation, or agent work.
309
+
208
310
  ## Migrating direct runs from 6.x
209
311
 
210
312
  The top-level `run:` block is deliberately rejected rather than silently
211
313
  ignored or rewritten, because doing otherwise could change the agents after
212
314
  an upgrade. Re-express `run.captain`, `run.players`, and former `--player`
213
- bindings as the inline agent blocks above; the old `run.player` catch-all has
214
- no shared equivalent, so configure every required role explicitly at
215
- `playbooks.<id>.players.<role>`. Use a fresh `--with` fragment for temporary
216
- lineup changes. Move former `--option` values into their `playbooks.<id>`
315
+ bindings as top-level stable player blocks and explicit role bindings above;
316
+ the old `run.player` catch-all has no shared equivalent, so configure every
317
+ required role at `playbooks.<id>.roles.<role>`. Use a `--with` fragment for
318
+ temporary compatible tuning changes. Move former `--option` values into their `playbooks.<id>`
217
319
  block, run from the desired directory instead of passing `--cwd`, enable a
218
320
  former positional `<from>` as a configured registry, and quote or pipe one
219
321
  `/command task` Boss message. Replace `resume` and `--last` with `--continue`
@@ -221,9 +323,9 @@ or `--session`.
221
323
 
222
324
  The JSON response is now exactly `{ "sessionId": "…", "reply": "…" }`.
223
325
  Released direct-run session records are not complete Captain sessions and
224
- cannot be continued by the new host ([[playbook-cli-19](../specs/packages/playbook-cli.md#playbook-cli-19)],
225
- [[playbook-cli-22](../specs/packages/playbook-cli.md#playbook-cli-22)],
226
- [[playbook-cli-28](../specs/packages/playbook-cli.md#playbook-cli-28)]).
326
+ cannot be continued by the new host ([[playbook-cli-19](https://github.com/sublang-ai/playbook/blob/main/specs/packages/playbook-cli.md#playbook-cli-19)],
327
+ [[playbook-cli-22](https://github.com/sublang-ai/playbook/blob/main/specs/packages/playbook-cli.md#playbook-cli-22)],
328
+ [[playbook-cli-28](https://github.com/sublang-ai/playbook/blob/main/specs/packages/playbook-cli.md#playbook-cli-28)]).
227
329
 
228
330
  ## Migrating from `profiles`
229
331
 
@@ -237,7 +339,7 @@ do by hand.
237
339
 
238
340
  For a one-off, pass a raw `tmux-play` config explicitly. This bypasses
239
341
  the seed, composition, and readiness gate, forwarding arguments to
240
- `tmux-play` verbatim ([[playbook-cli-1](../specs/packages/playbook-cli.md#playbook-cli-1)]):
342
+ `tmux-play` verbatim ([[playbook-cli-1](https://github.com/sublang-ai/playbook/blob/main/specs/packages/playbook-cli.md#playbook-cli-1)]):
241
343
 
242
344
  ```sh
243
345
  playbook --config ./tmux-play.config.yaml
package/docs/embedding.md CHANGED
@@ -9,15 +9,15 @@ app) is another. This guide shows how to wire a playbook runtime into
9
9
  your own host.
10
10
 
11
11
  > **Release note:** this guide targets the current semver-stable six-port
12
- > contract; see the [CHANGELOG](../CHANGELOG.md) for migration details.
12
+ > contract; see the [CHANGELOG](https://github.com/sublang-ai/playbook/blob/main/CHANGELOG.md) for migration details.
13
13
 
14
14
  ## The runtime contract
15
15
 
16
16
  The port and runtime contracts live in the type-only module
17
17
  [`@sublang/playbook/runtime`](../src/runtime.ts) — a public,
18
18
  semver-stable surface (`PlayerResult`, `PlaybookPorts`,
19
- `PlaybookRuntime`, `PlaybookSession`, `PlayerCallOptions`,
20
- `PlayerSessionStore`, `CaptainCallOptions`, `CaptainResult`,
19
+ `PlaybookRuntime`, `PlaybookSession`, `PlaybookRoleBinding`,
20
+ `PlayerCallOptions`, `PlayerSessionStore`, `CaptainCallOptions`, `CaptainResult`,
21
21
  `PlaybookTraceEvent`, and `PlaybookRuntimeFactory`) that imports no CODE
22
22
  or FSM types, so a host satisfies it once and inherits every playbook.
23
23
  The generated CODE, REVIEW, and DECIDE modules re-export their shared
@@ -31,12 +31,20 @@ nested-playbook bridge.
31
31
 
32
32
  ## Constructing a runtime against your own ports
33
33
 
34
+ `p-queue` is your host's own dependency here — declare it in your
35
+ application's `dependencies` (the same library `@sublang/playbook` itself
36
+ depends on) rather than relying on it resolving through the package's
37
+ tree, which pnpm's strict linking will not allow.
38
+
34
39
  ```ts
35
40
  import createPlaybookRuntime from '@sublang/playbook/review/playbook';
36
41
  import type {
37
42
  CaptainCallOptions,
38
43
  CaptainResult,
39
44
  PlaybookPorts,
45
+ PlaybookRoleBinding,
46
+ PlayerResult,
47
+ PlayerSessionStore,
40
48
  } from '@sublang/playbook/runtime';
41
49
  import { randomUUID } from 'node:crypto';
42
50
  import PQueue from 'p-queue';
@@ -53,6 +61,33 @@ declare const captainAdapter: {
53
61
  ): Promise<CaptainResult>;
54
62
  };
55
63
 
64
+ declare const playerAdapter: {
65
+ run(
66
+ playerId: string,
67
+ prompt: string,
68
+ options: { signal: AbortSignal; resume: string | false },
69
+ ): Promise<PlayerResult>;
70
+ };
71
+
72
+ // Roles are local workflow identities. Players are stable provider
73
+ // conversations owned by the logical Captain session. `promptIdentity` is
74
+ // the current model name, or the player's adapter when provider-default is
75
+ // selected; rebuild it from current compatible tuning on restore.
76
+ const roleBindings = {
77
+ coder: {
78
+ playerId: 'team.coder',
79
+ promptIdentity: 'claude-opus-4-8[1m]',
80
+ },
81
+ reviewer: {
82
+ playerId: 'team.reviewer',
83
+ promptIdentity: 'gpt-5.5',
84
+ },
85
+ } satisfies Readonly<Record<string, PlaybookRoleBinding>>;
86
+
87
+ // Supply a frame-local role view over your session-wide player ledger.
88
+ // Equal player IDs must select/update the same token; distinct IDs must not.
89
+ declare const playerSessions: PlayerSessionStore;
90
+
56
91
  // Construct one host-wide lane and reuse it for every runtime. Passing each
57
92
  // call's signal to both the lane and adapter cancels queued and active work.
58
93
  const captainLane = new PQueue({ concurrency: 1 });
@@ -69,10 +104,16 @@ async function runCaptain(
69
104
  }
70
105
 
71
106
  const ports: PlaybookPorts = {
72
- callPlayer: async (playerId, prompt, signal, { resume }) => {
107
+ callPlayer: async (roleId, prompt, signal, { resume }) => {
108
+ const binding = roleBindings[roleId as keyof typeof roleBindings];
109
+ if (binding === undefined) throw new Error(`Unknown role: ${roleId}`);
73
110
  // `resume === false` starts fresh; a string selects that player's
74
- // prior backend conversation. Return the adapter's next token.
75
- return { status: 'ok', finalText: 'done', resumeToken: 'next-token' };
111
+ // prior backend conversation. Return the adapter's next token; the
112
+ // runtime updates `playerSessions` only after validating this result.
113
+ return await playerAdapter.run(binding.playerId, prompt, {
114
+ signal,
115
+ resume,
116
+ });
76
117
  },
77
118
  callCaptain: async (prompt, signal, options) => {
78
119
  // Forward every option exactly: omission preserves configured tools, while
@@ -103,10 +144,7 @@ const ports: PlaybookPorts = {
103
144
  },
104
145
  };
105
146
 
106
- const runtime = createPlaybookRuntime({
107
- coderLlm: 'claude-opus-4-8[1m]',
108
- reviewerLlm: 'gpt-5.5',
109
- });
147
+ const runtime = createPlaybookRuntime({});
110
148
 
111
149
  const playbookSessionId = randomUUID();
112
150
  await runtime.init({
@@ -114,6 +152,8 @@ await runtime.init({
114
152
  playbookId: 'review',
115
153
  rootSessionId: playbookSessionId,
116
154
  depth: 0,
155
+ roleBindings,
156
+ playerSessions,
117
157
  ports,
118
158
  });
119
159
  await runtime.handleBossInput({
@@ -125,26 +165,37 @@ await runtime.dispose();
125
165
 
126
166
  ## Sessions and traces
127
167
 
128
- Every init-to-dispose lifecycle is one playbook session. Its
168
+ Every init-to-dispose lifecycle is one playbook session. Schema-3
129
169
  `playbook.trace` telemetry carries that immutable ID plus a contiguous
130
- sequence across exact Boss input, judge/player calls, FSM transitions,
131
- visible Captain work, nested playbook calls, status, settlement, and
132
- disposal. Without `PlaybookSession.playerSessions`, a standalone runtime
133
- starts each player fresh and privately retains the latest opaque
134
- `resumeToken` its adapter returned.
135
-
136
- A composing host can instead supply a frame-local `PlayerSessionStore`
137
- view over one root-owned continuation map. The host maps each local role
138
- to its effective binding, so a nested exact same-name role selects and
139
- updates the ancestor conversation while an unmatched child role gets
140
- its own binding. Child return or disposal does not clear the root's
141
- token, and a new root engagement starts fresh. Trace data and tokens
142
- never enter Boss-visible status text. Because trace observers do receive
143
- opaque resume tokens, persisted traces should be protected as sensitive
144
- data.
170
+ sequence across exact Boss input, judge/player calls, FSM transitions, visible
171
+ Captain work, nested playbook calls, status, settlement, and disposal. A
172
+ shell-hosted player boundary keeps both identities: `roleId` says which local
173
+ workflow job made the call, while `playerId` says which stable session
174
+ conversation owned it. A standalone runtime retains the role without
175
+ inventing host player identity.
176
+
177
+ Without `PlaybookSession.playerSessions`, a standalone runtime starts each
178
+ local role fresh and privately retains the latest opaque `resumeToken` its
179
+ adapter returned. A composing host instead supplies a frame-local
180
+ `PlayerSessionStore` view over one Captain-session ledger and explicit
181
+ `roleBindings`. The store's methods receive local role IDs; the view resolves
182
+ them to the configured stable player IDs. Equal IDs share one token and
183
+ sequential call lane across every frame that names them, while distinct IDs
184
+ remain isolated. Child return, frame disposal, and a later root engagement do
185
+ not clear the session ledger.
186
+
187
+ Runtime snapshots are schema 3. Their `roleResumeTokens` projection remains
188
+ role-local, while the composing shell's own schema-3 snapshot persists the
189
+ stable player ledger and every frame's exact role bindings. Do not restore
190
+ schema 1 or 2 by guessing identity. On a compatible restore, rebuild
191
+ `promptIdentity` from the current model selection (or adapter for an explicit
192
+ provider-default selection) so the next prompt and trace describe the current
193
+ invocation rather than stale machine state. Trace data and tokens never enter
194
+ Boss-visible status text. Because trace observers do receive opaque resume
195
+ tokens, persisted traces should be protected as sensitive data.
145
196
 
146
197
  See
147
- [`code.playbook.test.ts`](../reference/sdlc/code.playbook/code.playbook.test.ts)
198
+ [`code.playbook.test.ts`](https://github.com/sublang-ai/playbook/blob/main/reference/sdlc/code.playbook/code.playbook.test.ts)
148
199
  for the full range of port shapes (classifier, judge, abort, interrupt,
149
200
  status/telemetry) the runtime is contract-tested against.
150
201
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sublang/playbook",
3
- "version": "7.0.0",
3
+ "version": "9.0.0",
4
4
  "type": "module",
5
5
  "description": "Composable XState v5 playbook runtime with compiled Captain, CODE, REVIEW, and DECIDE workflows driven by GEARS specs.",
6
6
  "license": "Apache-2.0",
@@ -69,6 +69,7 @@
69
69
  "reference/sdlc/code.playbook/bin/playbook.js",
70
70
  "reference/sdlc/code.playbook/bin/launch-config.js",
71
71
  "reference/sdlc/code.playbook/bin/run.js",
72
+ "reference/sdlc/code.playbook/bin/interactive-session.js",
72
73
  "reference/sdlc/code.playbook/bin/session-store.js",
73
74
  "reference/sdlc/code.playbook/bin/provision.js",
74
75
  "reference/sdlc/code.playbook/bin/adapter-sdk.js",
@@ -142,7 +143,7 @@
142
143
  },
143
144
  "scripts": {
144
145
  "build": "tsc",
145
- "test": "spex lint && vitest run",
146
+ "test": "spex lint && vitest run --exclude src/cligent-release-capabilities.test.ts && vitest run src/cligent-release-capabilities.test.ts",
146
147
  "test:acceptance": "vitest run --config vitest.acceptance.config.ts",
147
148
  "smoke:release": "node scripts/release-smoke.mjs",
148
149
  "check:links": "node scripts/check-links.mjs",
@@ -153,7 +154,7 @@
153
154
  "provenance": true
154
155
  },
155
156
  "dependencies": {
156
- "@sublang/cligent": "^0.19.0",
157
+ "@sublang/cligent": "^0.22.0",
157
158
  "@sublang/spex": "^2.1.1",
158
159
  "p-queue": "^9.3.1",
159
160
  "xstate": "^5.19.4",