@sublang/playbook 0.1.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.
- package/LICENSE +201 -0
- package/README.md +181 -0
- package/bin/playbook-code.js +40 -0
- package/code.fsm.d.ts +86 -0
- package/code.fsm.introspect.d.ts +30 -0
- package/code.fsm.introspect.js +50 -0
- package/code.fsm.introspect.ts +129 -0
- package/code.fsm.js +1022 -0
- package/code.fsm.ts +1224 -0
- package/code.gears.md +250 -0
- package/code.playbook.d.ts +53 -0
- package/code.playbook.js +598 -0
- package/code.playbook.ts +743 -0
- package/code.tmux-play.d.ts +2 -0
- package/code.tmux-play.js +77 -0
- package/code.tmux-play.ts +110 -0
- package/package.json +77 -0
- package/tmux-play.config.yaml +33 -0
- package/tmux-play.production.config.yaml +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
<!-- SPDX-License-Identifier: Apache-2.0 -->
|
|
2
|
+
<!-- SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai> -->
|
|
3
|
+
|
|
4
|
+
# playbook
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/@sublang/playbook)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
[](https://github.com/sublang-ai/playbook/actions/workflows/ci.yml)
|
|
9
|
+
|
|
10
|
+
*Skills made reliable through state machines and visualization.*
|
|
11
|
+
|
|
12
|
+
playbook is a compiler stack and reference implementation for turning a
|
|
13
|
+
natural-language procedure into a runnable, inspectable state-machine
|
|
14
|
+
agent — a *playbook* — that orchestrates other AI agents (players) per a
|
|
15
|
+
spec written in plain prose. Three phases take prose to runtime:
|
|
16
|
+
|
|
17
|
+
1. **text → GEARS** ([slc/text2gears.md](slc/text2gears.md)) — normative
|
|
18
|
+
spec items, one per state behavior, partitioned by trigger and prompt
|
|
19
|
+
content.
|
|
20
|
+
2. **GEARS → FSM** ([slc/gears2fsm.md](slc/gears2fsm.md)) — an XState v5
|
|
21
|
+
finite state machine; each gear maps to one captain-invoking state
|
|
22
|
+
with a typed Captain actor contract.
|
|
23
|
+
3. **FSM → runtime** ([slc/link.md](slc/link.md)) — a host-agnostic
|
|
24
|
+
module that drives Boss turns through ports the host wires up
|
|
25
|
+
(cligent's `tmux-play` is one such host).
|
|
26
|
+
|
|
27
|
+
The repository is itself an end-to-end worked example: this
|
|
28
|
+
package — `@sublang/playbook` — is the SDLC coding workflow,
|
|
29
|
+
generated from [`reference/sdlc/code.md`](reference/sdlc/code.md)
|
|
30
|
+
as its prose source. The runtime drives a coder / reviewer /
|
|
31
|
+
committer loop end to end.
|
|
32
|
+
|
|
33
|
+
## Getting started — the reference CODE playbook
|
|
34
|
+
|
|
35
|
+
The reference is the canonical worked example —
|
|
36
|
+
[CODE source](reference/sdlc/code.md) →
|
|
37
|
+
[gears](code.gears.md) →
|
|
38
|
+
[FSM](code.fsm.ts) → runtime — with the
|
|
39
|
+
runtime ported to cligent's `tmux-play` host out of the box.
|
|
40
|
+
|
|
41
|
+
### Install (users)
|
|
42
|
+
|
|
43
|
+
Install the package globally alongside its `@sublang/cligent` peer:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npm install -g @sublang/playbook @sublang/cligent
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Then launch the reference playbook in a `tmux-play` session:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
playbook-code
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The `playbook-code` bin resolves the bundled
|
|
56
|
+
`tmux-play.production.config.yaml` and execs `tmux-play` against it; any
|
|
57
|
+
extra flags pass through (`playbook-code --help` lists `tmux-play`'s).
|
|
58
|
+
|
|
59
|
+
### Install (contributors / from source)
|
|
60
|
+
|
|
61
|
+
Clone, install, and run the suite locally:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
git clone https://github.com/sublang-ai/playbook.git
|
|
65
|
+
cd playbook
|
|
66
|
+
pnpm install
|
|
67
|
+
pnpm build
|
|
68
|
+
pnpm test
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`pnpm install` resolves `@sublang/cligent` (≥ 0.3.0) from the registry;
|
|
72
|
+
no local link required. To point pnpm at a local `cligent` checkout
|
|
73
|
+
instead, copy
|
|
74
|
+
[`pnpm-workspace.yaml.example`](pnpm-workspace.yaml.example)
|
|
75
|
+
into place; the override is gitignored so it never leaks into a
|
|
76
|
+
production install.
|
|
77
|
+
|
|
78
|
+
Drive a Boss turn against the source tree (uses the developer
|
|
79
|
+
[`tmux-play.config.yaml`](tmux-play.config.yaml)
|
|
80
|
+
that imports the compiled adapter via relative path):
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
pnpm exec tmux-play --config tmux-play.config.yaml
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`pnpm exec` resolves `tmux-play` from the package's local
|
|
87
|
+
`node_modules/.bin/`, so this works whether or not `@sublang/cligent` is
|
|
88
|
+
installed globally.
|
|
89
|
+
|
|
90
|
+
### Running a Boss turn
|
|
91
|
+
|
|
92
|
+
The Boss pane accepts four slash commands per
|
|
93
|
+
[PBRT-1](specs/user/playbook-runtime.md#pbrt-1):
|
|
94
|
+
|
|
95
|
+
- `/start <intent>` — begin a single coding turn
|
|
96
|
+
- `/continue <#>` — pick up an IR task
|
|
97
|
+
- `/summarize <#>` — turn an IR's commits into spec items
|
|
98
|
+
- `/interrupt <stateId> [intent]` — preempt the FSM into a named state
|
|
99
|
+
|
|
100
|
+
Anything else falls through to an LLM classifier. The Captain pane
|
|
101
|
+
streams the state machine progression with a four-glyph vocabulary —
|
|
102
|
+
`◆ ▸ ⮕ ⤷` per [PBRT-3](specs/user/playbook-runtime.md#pbrt-3) — while
|
|
103
|
+
player prompts ride their own panes.
|
|
104
|
+
|
|
105
|
+
### Embedding the runtime in your own host
|
|
106
|
+
|
|
107
|
+
The runtime is host-agnostic; the `tmux-play` adapter is one host.
|
|
108
|
+
Construct the runtime against your own ports:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import createPlaybookRuntime, {
|
|
112
|
+
type PlaybookPorts,
|
|
113
|
+
} from '@sublang/playbook/code/playbook';
|
|
114
|
+
|
|
115
|
+
const ports: PlaybookPorts = {
|
|
116
|
+
callPlayer: async (playerId, prompt, signal) => { /* … */ },
|
|
117
|
+
callJudge: async (prompt, signal) => { /* … */ },
|
|
118
|
+
emitStatus: async (message, data) => { /* … */ },
|
|
119
|
+
emitTelemetry: async ({ topic, payload }) => { /* … */ },
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const runtime = createPlaybookRuntime({
|
|
123
|
+
coderPlayer: 'claude',
|
|
124
|
+
reviewerPlayer: 'codex',
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
await runtime.init(ports);
|
|
128
|
+
await runtime.handleBossInput({
|
|
129
|
+
text: '/start fix the bug',
|
|
130
|
+
signal: new AbortController().signal,
|
|
131
|
+
});
|
|
132
|
+
await runtime.dispose();
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
See
|
|
136
|
+
[`code.playbook.test.ts`](code.playbook.test.ts)
|
|
137
|
+
for the full range of port shapes (classifier, judge, abort, interrupt,
|
|
138
|
+
status/telemetry) the runtime is contract-tested against.
|
|
139
|
+
|
|
140
|
+
## Workflow
|
|
141
|
+
|
|
142
|
+
playbook is itself spec-driven: the compiler phases are specs in `slc/`,
|
|
143
|
+
and the reference playbook is regenerated from its prose source. The
|
|
144
|
+
loop:
|
|
145
|
+
|
|
146
|
+
1. **Edit source.** For the reference, that's
|
|
147
|
+
[`reference/sdlc/code.md`](reference/sdlc/code.md).
|
|
148
|
+
2. **Recompile gears** per [`slc/text2gears.md`](slc/text2gears.md) into
|
|
149
|
+
the package's `code.gears.md`.
|
|
150
|
+
3. **Recompile FSM** per [`slc/gears2fsm.md`](slc/gears2fsm.md) into
|
|
151
|
+
the package's `code.fsm.ts`.
|
|
152
|
+
4. **Sync runtime, tests, and downstream specs** so `pnpm test` stays
|
|
153
|
+
green and the introspect contract holds 1:1 between gear items and
|
|
154
|
+
FSM captain-invoking states.
|
|
155
|
+
5. **Commit** with co-author trailers per
|
|
156
|
+
[`specs/dev/git.md`](specs/dev/git.md).
|
|
157
|
+
|
|
158
|
+
The behavioral contract between gears and FSM
|
|
159
|
+
([PLAYBOOK-1..6](specs/dev/playbook.md)) and the runtime contract that
|
|
160
|
+
ports satisfy ([PBRT-5..16](specs/dev/playbook-runtime.md)) are pinned
|
|
161
|
+
in [`specs/dev/`](specs/dev/) and verified by tests under the reference
|
|
162
|
+
package.
|
|
163
|
+
|
|
164
|
+
## Requirements
|
|
165
|
+
|
|
166
|
+
- Node.js ≥ 20
|
|
167
|
+
- pnpm 9 (for the reference package)
|
|
168
|
+
- A configured `tmux-play` host (for live Boss turns)
|
|
169
|
+
|
|
170
|
+
## Contributing
|
|
171
|
+
|
|
172
|
+
We welcome contributions of all kinds.
|
|
173
|
+
|
|
174
|
+
- 🌟 Star our repo if you find playbook useful.
|
|
175
|
+
- [Open an issue](https://github.com/sublang-ai/playbook/issues) for bugs or feature requests.
|
|
176
|
+
- [Open a PR](https://github.com/sublang-ai/playbook/pulls) for fixes or improvements.
|
|
177
|
+
- Discuss on [Discord](https://discord.gg/XxTPjNqy9g) for support or new ideas.
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
[Apache-2.0](LICENSE)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
4
|
+
|
|
5
|
+
// Thin shim that resolves the bundled tmux-play.production.config.yaml
|
|
6
|
+
// relative to this script's own location and execs `tmux-play` against
|
|
7
|
+
// it. Extra argv is forwarded verbatim, so callers can pass flags like
|
|
8
|
+
// --window or override the config with a later --config of their own
|
|
9
|
+
// (tmux-play uses the last --config wins).
|
|
10
|
+
//
|
|
11
|
+
// `tmux-play` is provided by the @sublang/cligent peer; this shim
|
|
12
|
+
// expects it to be discoverable on PATH (npm install -g or a project's
|
|
13
|
+
// node_modules/.bin).
|
|
14
|
+
|
|
15
|
+
import { spawn } from 'node:child_process';
|
|
16
|
+
import { dirname, resolve } from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
|
|
19
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
const configPath = resolve(here, '..', 'tmux-play.production.config.yaml');
|
|
21
|
+
|
|
22
|
+
const child = spawn(
|
|
23
|
+
'tmux-play',
|
|
24
|
+
['--config', configPath, ...process.argv.slice(2)],
|
|
25
|
+
{ stdio: 'inherit' },
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
child.on('error', (err) => {
|
|
29
|
+
const reason = err && err.code === 'ENOENT' ? 'not found on PATH' : err.message;
|
|
30
|
+
process.stderr.write(
|
|
31
|
+
`playbook-code: failed to launch tmux-play: ${reason}\n` +
|
|
32
|
+
"Install @sublang/cligent (which provides 'tmux-play') alongside @sublang/playbook.\n",
|
|
33
|
+
);
|
|
34
|
+
process.exit(127);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
child.on('exit', (code, signal) => {
|
|
38
|
+
if (signal) process.kill(process.pid, signal);
|
|
39
|
+
else process.exit(code ?? 0);
|
|
40
|
+
});
|
package/code.fsm.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
type Player = 'Coder' | 'Reviewer' | 'Committer';
|
|
2
|
+
type JumpableStateId = 'ready' | 'planAndImplement' | 'respondToReview' | 'continueIr' | 'summarizeSpecs' | 'reviewBossCommitSpecs' | 'reviewBossCommitCode' | 'reviewBossCommitMixed' | 'reviewIrTaskCommitSpecs' | 'reviewIrTaskCommitCode' | 'reviewIrTaskCommitMixed' | 'reviewChangesSpecs' | 'reviewChangesCode' | 'reviewChangesMixed' | 'reviewChangesAndChallengesSpecs' | 'reviewChangesAndChallengesCode' | 'reviewChangesAndChallengesMixed' | 'adjudicateChallenges' | 'commitCoderInitial' | 'commitJoint' | 'failed';
|
|
3
|
+
type WorkflowKind = 'singleCommit' | 'iteration' | 'specSummary';
|
|
4
|
+
type ChangeOrigin = 'bossIntent' | 'irTask';
|
|
5
|
+
type ReviewSubject = 'commit' | 'changes';
|
|
6
|
+
type AfterReview = 'continueIr' | 'summarizeSpecs' | 'done';
|
|
7
|
+
export type CaptainInput = {
|
|
8
|
+
player: Player;
|
|
9
|
+
sourceItem: string;
|
|
10
|
+
prompt: string;
|
|
11
|
+
result: Record<string, string>;
|
|
12
|
+
intent?: string;
|
|
13
|
+
irNumber?: string;
|
|
14
|
+
taskDescription?: string;
|
|
15
|
+
reviews?: string;
|
|
16
|
+
challenges?: string;
|
|
17
|
+
coderPlayer?: string;
|
|
18
|
+
reviewerPlayer?: string;
|
|
19
|
+
};
|
|
20
|
+
export type CaptainOutput = {
|
|
21
|
+
guard: string;
|
|
22
|
+
irNumber?: string;
|
|
23
|
+
taskDescription?: string;
|
|
24
|
+
reviews?: string;
|
|
25
|
+
challenges?: string;
|
|
26
|
+
summary?: string;
|
|
27
|
+
[k: string]: unknown;
|
|
28
|
+
};
|
|
29
|
+
export type CodingInput = {
|
|
30
|
+
intent?: string;
|
|
31
|
+
irNumber?: string;
|
|
32
|
+
coderPlayer?: string;
|
|
33
|
+
reviewerPlayer?: string;
|
|
34
|
+
committerPlayer?: string;
|
|
35
|
+
};
|
|
36
|
+
export type CodingContext = CodingInput & {
|
|
37
|
+
workflow?: WorkflowKind;
|
|
38
|
+
changeOrigin?: ChangeOrigin;
|
|
39
|
+
reviewSubject?: ReviewSubject;
|
|
40
|
+
afterReview?: AfterReview;
|
|
41
|
+
taskDescription?: string;
|
|
42
|
+
reviews?: string;
|
|
43
|
+
challenges?: string;
|
|
44
|
+
lastResult?: CaptainOutput;
|
|
45
|
+
lastError?: unknown;
|
|
46
|
+
};
|
|
47
|
+
export type CodingEvent = {
|
|
48
|
+
type: 'START_CODING';
|
|
49
|
+
intent: string;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'CONTINUE_IR';
|
|
52
|
+
irNumber: string;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'SUMMARIZE_IR';
|
|
55
|
+
irNumber: string;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'BOSS_INTERRUPT';
|
|
58
|
+
targetId: JumpableStateId;
|
|
59
|
+
intent?: string;
|
|
60
|
+
irNumber?: string;
|
|
61
|
+
};
|
|
62
|
+
export declare const codingMachine: import("xstate").StateMachine<CodingContext, {
|
|
63
|
+
type: "START_CODING";
|
|
64
|
+
intent: string;
|
|
65
|
+
} | {
|
|
66
|
+
type: "CONTINUE_IR";
|
|
67
|
+
irNumber: string;
|
|
68
|
+
} | {
|
|
69
|
+
type: "SUMMARIZE_IR";
|
|
70
|
+
irNumber: string;
|
|
71
|
+
} | {
|
|
72
|
+
type: "BOSS_INTERRUPT";
|
|
73
|
+
targetId: JumpableStateId;
|
|
74
|
+
intent?: string;
|
|
75
|
+
irNumber?: string;
|
|
76
|
+
}, {
|
|
77
|
+
[x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<CaptainOutput, CaptainInput, import("xstate").EventObject>> | undefined;
|
|
78
|
+
}, {
|
|
79
|
+
src: "captain";
|
|
80
|
+
logic: import("xstate").PromiseActorLogic<CaptainOutput, CaptainInput, import("xstate").EventObject>;
|
|
81
|
+
id: string | undefined;
|
|
82
|
+
}, never, never, never, {}, string, CodingInput, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, {
|
|
83
|
+
states?: {} | undefined;
|
|
84
|
+
id?: string | undefined | undefined;
|
|
85
|
+
}>;
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CaptainInput, CodingContext, codingMachine } from './code.fsm.js';
|
|
2
|
+
export interface CaptainStateInfo {
|
|
3
|
+
readonly stateId: string;
|
|
4
|
+
readonly sourceItem: string;
|
|
5
|
+
readonly getInput: (context: Partial<CodingContext>) => CaptainInput;
|
|
6
|
+
readonly transitions: ReadonlyArray<CaptainTransition>;
|
|
7
|
+
}
|
|
8
|
+
export interface CaptainTransition {
|
|
9
|
+
readonly index: number;
|
|
10
|
+
readonly target: string;
|
|
11
|
+
readonly guard: TransitionGuard;
|
|
12
|
+
}
|
|
13
|
+
export type TransitionGuard = (args: {
|
|
14
|
+
context: CodingContext;
|
|
15
|
+
event: unknown;
|
|
16
|
+
}) => boolean;
|
|
17
|
+
export interface RootEventTable {
|
|
18
|
+
readonly startCoding: {
|
|
19
|
+
readonly target: string;
|
|
20
|
+
};
|
|
21
|
+
readonly continueIr: {
|
|
22
|
+
readonly target: string;
|
|
23
|
+
};
|
|
24
|
+
readonly summarizeIr: {
|
|
25
|
+
readonly target: string;
|
|
26
|
+
};
|
|
27
|
+
readonly bossInterruptTargets: ReadonlyArray<string>;
|
|
28
|
+
}
|
|
29
|
+
export declare function enumerateCaptainStates(machine: typeof codingMachine): readonly CaptainStateInfo[];
|
|
30
|
+
export declare function enumerateRootEvents(machine: typeof codingMachine): RootEventTable;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
export function enumerateCaptainStates(machine) {
|
|
4
|
+
const states = getRawConfig(machine).states ?? {};
|
|
5
|
+
const out = [];
|
|
6
|
+
for (const [stateId, def] of Object.entries(states)) {
|
|
7
|
+
const invoke = def.invoke;
|
|
8
|
+
if (!invoke || invoke.src !== 'captain' || typeof invoke.input !== 'function') {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
const inputFn = invoke.input;
|
|
12
|
+
const getInput = (context) => inputFn({ context });
|
|
13
|
+
const probe = getInput({});
|
|
14
|
+
const transitions = toArmArray(invoke.onDone).map((arm, index) => ({
|
|
15
|
+
index,
|
|
16
|
+
target: stripIdPrefix(String(arm.target ?? '')),
|
|
17
|
+
guard: arm.guard ?? alwaysTrue,
|
|
18
|
+
}));
|
|
19
|
+
out.push({
|
|
20
|
+
stateId,
|
|
21
|
+
sourceItem: probe.sourceItem,
|
|
22
|
+
getInput,
|
|
23
|
+
transitions,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
export function enumerateRootEvents(machine) {
|
|
29
|
+
const cfg = getRawConfig(machine);
|
|
30
|
+
const readyOn = (cfg.states?.ready?.on ?? {});
|
|
31
|
+
const rootOn = (cfg.on ?? {});
|
|
32
|
+
return {
|
|
33
|
+
startCoding: { target: stripIdPrefix(String(readyOn.START_CODING?.target ?? '')) },
|
|
34
|
+
continueIr: { target: stripIdPrefix(String(readyOn.CONTINUE_IR?.target ?? '')) },
|
|
35
|
+
summarizeIr: { target: stripIdPrefix(String(readyOn.SUMMARIZE_IR?.target ?? '')) },
|
|
36
|
+
bossInterruptTargets: toArmArray(rootOn.BOSS_INTERRUPT).map((arm) => stripIdPrefix(String(arm.target ?? ''))),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function getRawConfig(machine) {
|
|
40
|
+
return machine.config;
|
|
41
|
+
}
|
|
42
|
+
function toArmArray(value) {
|
|
43
|
+
if (value === undefined || value === null)
|
|
44
|
+
return [];
|
|
45
|
+
return (Array.isArray(value) ? value : [value]);
|
|
46
|
+
}
|
|
47
|
+
function stripIdPrefix(target) {
|
|
48
|
+
return target.startsWith('#') ? target.slice(1) : target;
|
|
49
|
+
}
|
|
50
|
+
const alwaysTrue = () => true;
|