@sublang/playbook 0.5.0 → 0.6.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/README.md +20 -9
- package/package.json +13 -3
- package/reference/sdlc/code.playbook/bin/playbook-code.js +50 -20
- package/reference/sdlc/code.playbook/code.fsm.js +16 -8
- package/reference/sdlc/code.playbook/code.fsm.ts +16 -8
- package/reference/sdlc/code.playbook/code.gears.md +16 -8
- package/reference/sdlc/code.playbook/code.registry.d.ts +43 -0
- package/reference/sdlc/code.playbook/code.registry.js +109 -0
- package/reference/sdlc/code.playbook/code.registry.ts +159 -0
- package/reference/sdlc/code.playbook/code.tmux-play.d.ts +2 -4
- package/reference/sdlc/code.playbook/code.tmux-play.js +7 -156
- package/reference/sdlc/code.playbook/code.tmux-play.ts +22 -196
- package/reference/sdlc/code.playbook/playbook-captain.d.ts +21 -0
- package/reference/sdlc/code.playbook/playbook-captain.js +491 -0
- package/reference/sdlc/code.playbook/playbook-captain.ts +701 -0
- package/reference/sdlc/code.playbook/playbook-code.config.template.yaml +13 -4
- package/reference/sdlc/code.playbook/tmux-play.config.yaml +13 -8
- package/reference/sdlc/code.playbook/tmux-play.production.config.yaml +8 -4
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
import createPlaybookRuntime from './code.playbook.js';
|
|
4
|
+
// PBRT-29/30: CODE runtime options are carried under
|
|
5
|
+
// `captain.options.code`, a namespaced object the host forwards
|
|
6
|
+
// verbatim through `captain.options`. cligent neither reads nor
|
|
7
|
+
// validates `options.code`; the CODE registry entry is the sole
|
|
8
|
+
// validator. The CODE options schema defines one key, `committer`: an
|
|
9
|
+
// optional Committer-alias player id, one of the baked player ids
|
|
10
|
+
// `coder` / `reviewer`. A valid `options.code` is absent, `{}`, or
|
|
11
|
+
// `{ committer: 'coder' | 'reviewer' }`; every other key is unknown
|
|
12
|
+
// and rejected with a path-named error, and an out-of-range
|
|
13
|
+
// `committer` value is rejected naming `captain.options.code.committer`.
|
|
14
|
+
// A further CODE option shall be introduced as its own higher-numbered
|
|
15
|
+
// item that widens `CODE_OPTION_KEYS`; the validator still fails closed
|
|
16
|
+
// on stray keys.
|
|
17
|
+
const CODE_OPTION_KEYS = new Set(['committer']);
|
|
18
|
+
const COMMITTER_PLAYER_IDS = new Set(['coder', 'reviewer']);
|
|
19
|
+
export const codeCopyPasteGuardNames = [
|
|
20
|
+
'accepted',
|
|
21
|
+
'approved',
|
|
22
|
+
'challengeAccepted',
|
|
23
|
+
'challengeRejected',
|
|
24
|
+
'challengesRaised',
|
|
25
|
+
'changesMadeCode',
|
|
26
|
+
'changesMadeCodeAndChallenged',
|
|
27
|
+
'changesMadeMixed',
|
|
28
|
+
'changesMadeMixedAndChallenged',
|
|
29
|
+
'changesMadeSpecs',
|
|
30
|
+
'changesMadeSpecsAndChallenged',
|
|
31
|
+
'hasFindings',
|
|
32
|
+
'needsRevision',
|
|
33
|
+
'noFindings',
|
|
34
|
+
'noOpenItems',
|
|
35
|
+
];
|
|
36
|
+
export const codeStateCountLabels = {
|
|
37
|
+
adjudicateChallenges: 'rebuttal',
|
|
38
|
+
reviewBossCommitSpecs: 'review round',
|
|
39
|
+
reviewBossCommitCode: 'review round',
|
|
40
|
+
reviewBossCommitMixed: 'review round',
|
|
41
|
+
reviewIrTaskCommitSpecs: 'review round',
|
|
42
|
+
reviewIrTaskCommitCode: 'review round',
|
|
43
|
+
reviewIrTaskCommitMixed: 'review round',
|
|
44
|
+
reviewChangesSpecs: 'review round',
|
|
45
|
+
reviewChangesCode: 'review round',
|
|
46
|
+
reviewChangesMixed: 'review round',
|
|
47
|
+
reviewChangesAndChallengesSpecs: 'review round',
|
|
48
|
+
reviewChangesAndChallengesCode: 'review round',
|
|
49
|
+
reviewChangesAndChallengesMixed: 'review round',
|
|
50
|
+
};
|
|
51
|
+
export function validateCodeOptions(captainOptions) {
|
|
52
|
+
const code = readCodeNamespace(captainOptions);
|
|
53
|
+
if (code === undefined)
|
|
54
|
+
return {};
|
|
55
|
+
if (typeof code !== 'object' || code === null || Array.isArray(code)) {
|
|
56
|
+
throw new Error('captain.options.code must be an object');
|
|
57
|
+
}
|
|
58
|
+
for (const key of Object.keys(code)) {
|
|
59
|
+
if (!CODE_OPTION_KEYS.has(key)) {
|
|
60
|
+
throw new Error(`Unknown config field captain.options.code.${key}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const options = {};
|
|
64
|
+
const committer = code.committer;
|
|
65
|
+
if (committer !== undefined) {
|
|
66
|
+
if (typeof committer !== 'string' || !COMMITTER_PLAYER_IDS.has(committer)) {
|
|
67
|
+
throw new Error("captain.options.code.committer must be 'coder' or 'reviewer'");
|
|
68
|
+
}
|
|
69
|
+
options.committer = committer;
|
|
70
|
+
}
|
|
71
|
+
return options;
|
|
72
|
+
}
|
|
73
|
+
function readCodeNamespace(captainOptions) {
|
|
74
|
+
if (typeof captainOptions !== 'object' ||
|
|
75
|
+
captainOptions === null ||
|
|
76
|
+
Array.isArray(captainOptions)) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return captainOptions.code;
|
|
80
|
+
}
|
|
81
|
+
function playerIdentity(players, id) {
|
|
82
|
+
const entry = players.find((p) => p.id === id);
|
|
83
|
+
return entry?.model ?? entry?.adapter;
|
|
84
|
+
}
|
|
85
|
+
export function createCodeRuntimeOptions({ captainOptions, players, }) {
|
|
86
|
+
const codeOptions = validateCodeOptions(captainOptions);
|
|
87
|
+
const coderPlayer = playerIdentity(players, 'coder');
|
|
88
|
+
const reviewerPlayer = playerIdentity(players, 'reviewer');
|
|
89
|
+
return {
|
|
90
|
+
coderPlayer,
|
|
91
|
+
reviewerPlayer,
|
|
92
|
+
...(codeOptions.committer !== undefined
|
|
93
|
+
? { committerPlayer: codeOptions.committer }
|
|
94
|
+
: {}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export const codePlaybookRegistryEntry = {
|
|
98
|
+
id: 'code',
|
|
99
|
+
command: 'code',
|
|
100
|
+
intent: 'software development / SDLC coding workflow',
|
|
101
|
+
idleStateId: 'ready',
|
|
102
|
+
finalStateId: 'done',
|
|
103
|
+
copyPasteGuardNames: codeCopyPasteGuardNames,
|
|
104
|
+
stateCountLabels: codeStateCountLabels,
|
|
105
|
+
validateOptions: validateCodeOptions,
|
|
106
|
+
createRuntime(options) {
|
|
107
|
+
return createPlaybookRuntime(createCodeRuntimeOptions(options));
|
|
108
|
+
},
|
|
109
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
|
|
4
|
+
import createPlaybookRuntime, {
|
|
5
|
+
type CodePlaybookOptions,
|
|
6
|
+
type PlaybookRuntime,
|
|
7
|
+
} from './code.playbook.js';
|
|
8
|
+
|
|
9
|
+
// PBRT-29/30: CODE runtime options are carried under
|
|
10
|
+
// `captain.options.code`, a namespaced object the host forwards
|
|
11
|
+
// verbatim through `captain.options`. cligent neither reads nor
|
|
12
|
+
// validates `options.code`; the CODE registry entry is the sole
|
|
13
|
+
// validator. The CODE options schema defines one key, `committer`: an
|
|
14
|
+
// optional Committer-alias player id, one of the baked player ids
|
|
15
|
+
// `coder` / `reviewer`. A valid `options.code` is absent, `{}`, or
|
|
16
|
+
// `{ committer: 'coder' | 'reviewer' }`; every other key is unknown
|
|
17
|
+
// and rejected with a path-named error, and an out-of-range
|
|
18
|
+
// `committer` value is rejected naming `captain.options.code.committer`.
|
|
19
|
+
// A further CODE option shall be introduced as its own higher-numbered
|
|
20
|
+
// item that widens `CODE_OPTION_KEYS`; the validator still fails closed
|
|
21
|
+
// on stray keys.
|
|
22
|
+
const CODE_OPTION_KEYS = new Set<string>(['committer']);
|
|
23
|
+
const COMMITTER_PLAYER_IDS = new Set<string>(['coder', 'reviewer']);
|
|
24
|
+
export const codeCopyPasteGuardNames = [
|
|
25
|
+
'accepted',
|
|
26
|
+
'approved',
|
|
27
|
+
'challengeAccepted',
|
|
28
|
+
'challengeRejected',
|
|
29
|
+
'challengesRaised',
|
|
30
|
+
'changesMadeCode',
|
|
31
|
+
'changesMadeCodeAndChallenged',
|
|
32
|
+
'changesMadeMixed',
|
|
33
|
+
'changesMadeMixedAndChallenged',
|
|
34
|
+
'changesMadeSpecs',
|
|
35
|
+
'changesMadeSpecsAndChallenged',
|
|
36
|
+
'hasFindings',
|
|
37
|
+
'needsRevision',
|
|
38
|
+
'noFindings',
|
|
39
|
+
'noOpenItems',
|
|
40
|
+
] as const;
|
|
41
|
+
|
|
42
|
+
export const codeStateCountLabels = {
|
|
43
|
+
adjudicateChallenges: 'rebuttal',
|
|
44
|
+
reviewBossCommitSpecs: 'review round',
|
|
45
|
+
reviewBossCommitCode: 'review round',
|
|
46
|
+
reviewBossCommitMixed: 'review round',
|
|
47
|
+
reviewIrTaskCommitSpecs: 'review round',
|
|
48
|
+
reviewIrTaskCommitCode: 'review round',
|
|
49
|
+
reviewIrTaskCommitMixed: 'review round',
|
|
50
|
+
reviewChangesSpecs: 'review round',
|
|
51
|
+
reviewChangesCode: 'review round',
|
|
52
|
+
reviewChangesMixed: 'review round',
|
|
53
|
+
reviewChangesAndChallengesSpecs: 'review round',
|
|
54
|
+
reviewChangesAndChallengesCode: 'review round',
|
|
55
|
+
reviewChangesAndChallengesMixed: 'review round',
|
|
56
|
+
} as const;
|
|
57
|
+
|
|
58
|
+
// The validated CODE options set. `committer`, when present, is the
|
|
59
|
+
// resolved Committer-alias player id (PBRT-8 / PBRT-30); a future CODE
|
|
60
|
+
// option widens both this type and `CODE_OPTION_KEYS`.
|
|
61
|
+
export interface CodeOptions {
|
|
62
|
+
committer?: 'coder' | 'reviewer';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface RegistryPlayer {
|
|
66
|
+
id: string;
|
|
67
|
+
adapter?: string;
|
|
68
|
+
model?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface CreateCodeRuntimeOptions {
|
|
72
|
+
captainOptions: unknown;
|
|
73
|
+
players: readonly RegistryPlayer[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface CodePlaybookRegistryEntry {
|
|
77
|
+
id: 'code';
|
|
78
|
+
command: 'code';
|
|
79
|
+
intent: string;
|
|
80
|
+
idleStateId: 'ready';
|
|
81
|
+
finalStateId: 'done';
|
|
82
|
+
copyPasteGuardNames: readonly string[];
|
|
83
|
+
stateCountLabels: typeof codeStateCountLabels;
|
|
84
|
+
validateOptions(captainOptions: unknown): CodeOptions;
|
|
85
|
+
createRuntime(options: CreateCodeRuntimeOptions): PlaybookRuntime;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function validateCodeOptions(captainOptions: unknown): CodeOptions {
|
|
89
|
+
const code = readCodeNamespace(captainOptions);
|
|
90
|
+
if (code === undefined) return {};
|
|
91
|
+
if (typeof code !== 'object' || code === null || Array.isArray(code)) {
|
|
92
|
+
throw new Error('captain.options.code must be an object');
|
|
93
|
+
}
|
|
94
|
+
for (const key of Object.keys(code)) {
|
|
95
|
+
if (!CODE_OPTION_KEYS.has(key)) {
|
|
96
|
+
throw new Error(`Unknown config field captain.options.code.${key}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const options: CodeOptions = {};
|
|
100
|
+
const committer = (code as Record<string, unknown>).committer;
|
|
101
|
+
if (committer !== undefined) {
|
|
102
|
+
if (typeof committer !== 'string' || !COMMITTER_PLAYER_IDS.has(committer)) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
"captain.options.code.committer must be 'coder' or 'reviewer'",
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
options.committer = committer as 'coder' | 'reviewer';
|
|
108
|
+
}
|
|
109
|
+
return options;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function readCodeNamespace(captainOptions: unknown): unknown {
|
|
113
|
+
if (
|
|
114
|
+
typeof captainOptions !== 'object' ||
|
|
115
|
+
captainOptions === null ||
|
|
116
|
+
Array.isArray(captainOptions)
|
|
117
|
+
) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
return (captainOptions as Record<string, unknown>).code;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function playerIdentity(
|
|
124
|
+
players: readonly RegistryPlayer[],
|
|
125
|
+
id: string,
|
|
126
|
+
): string | undefined {
|
|
127
|
+
const entry = players.find((p) => p.id === id);
|
|
128
|
+
return entry?.model ?? entry?.adapter;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function createCodeRuntimeOptions({
|
|
132
|
+
captainOptions,
|
|
133
|
+
players,
|
|
134
|
+
}: CreateCodeRuntimeOptions): CodePlaybookOptions {
|
|
135
|
+
const codeOptions = validateCodeOptions(captainOptions);
|
|
136
|
+
const coderPlayer = playerIdentity(players, 'coder');
|
|
137
|
+
const reviewerPlayer = playerIdentity(players, 'reviewer');
|
|
138
|
+
return {
|
|
139
|
+
coderPlayer,
|
|
140
|
+
reviewerPlayer,
|
|
141
|
+
...(codeOptions.committer !== undefined
|
|
142
|
+
? { committerPlayer: codeOptions.committer }
|
|
143
|
+
: {}),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const codePlaybookRegistryEntry: CodePlaybookRegistryEntry = {
|
|
148
|
+
id: 'code',
|
|
149
|
+
command: 'code',
|
|
150
|
+
intent: 'software development / SDLC coding workflow',
|
|
151
|
+
idleStateId: 'ready',
|
|
152
|
+
finalStateId: 'done',
|
|
153
|
+
copyPasteGuardNames: codeCopyPasteGuardNames,
|
|
154
|
+
stateCountLabels: codeStateCountLabels,
|
|
155
|
+
validateOptions: validateCodeOptions,
|
|
156
|
+
createRuntime(options) {
|
|
157
|
+
return createPlaybookRuntime(createCodeRuntimeOptions(options));
|
|
158
|
+
},
|
|
159
|
+
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { Captain } from '@sublang/cligent/tmux-play';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export declare function validateCodeOptions(captainOptions: unknown): CodeOptions;
|
|
2
|
+
export { codeCopyPasteGuardNames, codeStateCountLabels, codePlaybookRegistryEntry, createCodeRuntimeOptions, validateCodeOptions, } from './code.registry.js';
|
|
3
|
+
export type { CodeOptions, CodePlaybookRegistryEntry, CreateCodeRuntimeOptions, RegistryPlayer, } from './code.registry.js';
|
|
6
4
|
export default function createCodeTmuxPlayCaptain(options: unknown): Captain;
|
|
@@ -1,160 +1,11 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// optional Committer-alias player id, one of the baked player ids
|
|
10
|
-
// `coder` / `reviewer`. A valid `options.code` is absent, `{}`, or
|
|
11
|
-
// `{ committer: 'coder' | 'reviewer' }`; every other key is unknown
|
|
12
|
-
// and rejected with a path-named error, and an out-of-range
|
|
13
|
-
// `committer` value is rejected naming `captain.options.code.committer`.
|
|
14
|
-
// A further CODE option shall be introduced as its own higher-numbered
|
|
15
|
-
// item that widens `CODE_OPTION_KEYS`; the validator still fails closed
|
|
16
|
-
// on stray keys.
|
|
17
|
-
const CODE_OPTION_KEYS = new Set(['committer']);
|
|
18
|
-
const COMMITTER_PLAYER_IDS = new Set(['coder', 'reviewer']);
|
|
19
|
-
export function validateCodeOptions(captainOptions) {
|
|
20
|
-
const code = readCodeNamespace(captainOptions);
|
|
21
|
-
if (code === undefined)
|
|
22
|
-
return {};
|
|
23
|
-
if (typeof code !== 'object' || code === null || Array.isArray(code)) {
|
|
24
|
-
throw new Error('captain.options.code must be an object');
|
|
25
|
-
}
|
|
26
|
-
for (const key of Object.keys(code)) {
|
|
27
|
-
if (!CODE_OPTION_KEYS.has(key)) {
|
|
28
|
-
throw new Error(`Unknown config field captain.options.code.${key}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const options = {};
|
|
32
|
-
const committer = code.committer;
|
|
33
|
-
if (committer !== undefined) {
|
|
34
|
-
if (typeof committer !== 'string' || !COMMITTER_PLAYER_IDS.has(committer)) {
|
|
35
|
-
throw new Error("captain.options.code.committer must be 'coder' or 'reviewer'");
|
|
36
|
-
}
|
|
37
|
-
options.committer = committer;
|
|
38
|
-
}
|
|
39
|
-
return options;
|
|
40
|
-
}
|
|
41
|
-
function readCodeNamespace(captainOptions) {
|
|
42
|
-
if (typeof captainOptions !== 'object' ||
|
|
43
|
-
captainOptions === null ||
|
|
44
|
-
Array.isArray(captainOptions)) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
return captainOptions.code;
|
|
48
|
-
}
|
|
49
|
-
// Captain factory per TMUX-014: `(options: unknown) => Captain`.
|
|
50
|
-
// `options` is whatever `captain.options` carries in the YAML config;
|
|
51
|
-
// CODE reads only the namespaced `options.code` (PBRT-30). The per-run
|
|
52
|
-
// player identity strings (`coderPlayer`, `reviewerPlayer`) are
|
|
53
|
-
// derived from `session.players` at init time per PBRT-4 — preferring
|
|
54
|
-
// each entry's `model` and falling back to `adapter` when no model is
|
|
55
|
-
// pinned — so player prompts and commit-message trailers carry the
|
|
56
|
-
// concrete model identity (e.g. `claude-opus-4-7`) rather than the
|
|
57
|
-
// adapter family name (e.g. `claude`). They come from `session.players`
|
|
58
|
-
// independent of `captain.options.code` and override any same-named
|
|
59
|
-
// keys.
|
|
3
|
+
import createPlaybookCaptainShell from './playbook-captain.js';
|
|
4
|
+
export { codeCopyPasteGuardNames, codeStateCountLabels, codePlaybookRegistryEntry, createCodeRuntimeOptions, validateCodeOptions, } from './code.registry.js';
|
|
5
|
+
// Compatibility shim for the historic `./code/tmux-play` package
|
|
6
|
+
// export. Public launch paths now target the Playbook Captain shell
|
|
7
|
+
// directly; explicit configs that still import this module get the
|
|
8
|
+
// same shell with CODE registered.
|
|
60
9
|
export default function createCodeTmuxPlayCaptain(options) {
|
|
61
|
-
|
|
62
|
-
// CaptainContext is rebuilt per turn and carries the call
|
|
63
|
-
// primitives. The runtime is constructed in `init` so identity
|
|
64
|
-
// strings derived from `session.players` can flow into its options;
|
|
65
|
-
// PlaybookPorts is built once at init, so the per-turn context
|
|
66
|
-
// lives in a closure-scoped slot the port callbacks query lazily.
|
|
67
|
-
let runtime;
|
|
68
|
-
let activeContext;
|
|
69
|
-
return {
|
|
70
|
-
async init(session) {
|
|
71
|
-
// PBRT-30: validate `captain.options.code` before constructing
|
|
72
|
-
// the runtime so a stray key fails `init` closed with a
|
|
73
|
-
// path-named error; the empty schema yields an empty options set.
|
|
74
|
-
const codeOptions = validateCodeOptions(options);
|
|
75
|
-
const playerIdentity = (id) => {
|
|
76
|
-
const entry = session.players.find((p) => p.id === id);
|
|
77
|
-
return entry?.model ?? entry?.adapter;
|
|
78
|
-
};
|
|
79
|
-
const coderPlayer = playerIdentity('coder');
|
|
80
|
-
const reviewerPlayer = playerIdentity('reviewer');
|
|
81
|
-
// Identity strings from `session.players` override any same-named
|
|
82
|
-
// keys and are independent of `captain.options.code` (PBRT-30).
|
|
83
|
-
// The validated `committer` alias threads in as the runtime's
|
|
84
|
-
// Committer player id (`committerPlayer`, PBRT-8).
|
|
85
|
-
const runtimeOptions = {
|
|
86
|
-
coderPlayer,
|
|
87
|
-
reviewerPlayer,
|
|
88
|
-
...(codeOptions.committer !== undefined
|
|
89
|
-
? { committerPlayer: codeOptions.committer }
|
|
90
|
-
: {}),
|
|
91
|
-
};
|
|
92
|
-
runtime = createPlaybookRuntime(runtimeOptions);
|
|
93
|
-
const ports = {
|
|
94
|
-
callPlayer: async (playerId, prompt, _signal) => {
|
|
95
|
-
if (!activeContext) {
|
|
96
|
-
throw new Error('callPlayer invoked outside a Boss turn');
|
|
97
|
-
}
|
|
98
|
-
// PlayerRunResult per TMUX-033 already matches PlayerResult
|
|
99
|
-
// (`status: 'ok' | 'aborted' | 'error'`, `finalText?`,
|
|
100
|
-
// `error?`). cligent honors context.signal internally;
|
|
101
|
-
// the runtime's signal is the same source forwarded
|
|
102
|
-
// through handleBossInput, so dropping `_signal` is
|
|
103
|
-
// safe.
|
|
104
|
-
const r = await activeContext.callPlayer(playerId, prompt);
|
|
105
|
-
return {
|
|
106
|
-
status: r.status,
|
|
107
|
-
finalText: r.finalText,
|
|
108
|
-
error: r.error,
|
|
109
|
-
};
|
|
110
|
-
},
|
|
111
|
-
callJudge: async (prompt, _signal) => {
|
|
112
|
-
if (!activeContext) {
|
|
113
|
-
throw new Error('callJudge invoked outside a Boss turn');
|
|
114
|
-
}
|
|
115
|
-
// PBRT-15 / DR-007: run the judge call hidden so its JSON
|
|
116
|
-
// reply never reaches the Boss pane; the runtime composes the
|
|
117
|
-
// human-readable pane lines (PBRT-3) from the parsed result.
|
|
118
|
-
const r = await activeContext.callCaptain(prompt, {
|
|
119
|
-
visibility: 'hidden',
|
|
120
|
-
});
|
|
121
|
-
if (r.status !== 'ok') {
|
|
122
|
-
throw new Error(r.error ?? `callCaptain status "${r.status}"`);
|
|
123
|
-
}
|
|
124
|
-
if (r.finalText === undefined) {
|
|
125
|
-
throw new Error('callCaptain returned status=ok with no finalText');
|
|
126
|
-
}
|
|
127
|
-
return r.finalText;
|
|
128
|
-
},
|
|
129
|
-
emitStatus: async (message, data) => {
|
|
130
|
-
await session.emitStatus(message, data);
|
|
131
|
-
},
|
|
132
|
-
emitTelemetry: async (event) => {
|
|
133
|
-
await session.emitTelemetry(event);
|
|
134
|
-
},
|
|
135
|
-
};
|
|
136
|
-
await runtime.init(ports);
|
|
137
|
-
},
|
|
138
|
-
async handleBossTurn(turn, context) {
|
|
139
|
-
if (!runtime) {
|
|
140
|
-
throw new Error('init must be called first');
|
|
141
|
-
}
|
|
142
|
-
activeContext = context;
|
|
143
|
-
try {
|
|
144
|
-
// Forward the Boss prompt + cligent's per-turn signal into
|
|
145
|
-
// the runtime; the runtime stashes the signal so the
|
|
146
|
-
// captain bridge passes it down to callPlayer / callJudge.
|
|
147
|
-
await runtime.handleBossInput({
|
|
148
|
-
text: turn.prompt,
|
|
149
|
-
signal: context.signal,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
finally {
|
|
153
|
-
activeContext = undefined;
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
async dispose() {
|
|
157
|
-
await runtime?.dispose();
|
|
158
|
-
},
|
|
159
|
-
};
|
|
10
|
+
return createPlaybookCaptainShell(options);
|
|
160
11
|
}
|
|
@@ -1,203 +1,29 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from '
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
// optional Committer-alias player id, one of the baked player ids
|
|
26
|
-
// `coder` / `reviewer`. A valid `options.code` is absent, `{}`, or
|
|
27
|
-
// `{ committer: 'coder' | 'reviewer' }`; every other key is unknown
|
|
28
|
-
// and rejected with a path-named error, and an out-of-range
|
|
29
|
-
// `committer` value is rejected naming `captain.options.code.committer`.
|
|
30
|
-
// A further CODE option shall be introduced as its own higher-numbered
|
|
31
|
-
// item that widens `CODE_OPTION_KEYS`; the validator still fails closed
|
|
32
|
-
// on stray keys.
|
|
33
|
-
const CODE_OPTION_KEYS = new Set<string>(['committer']);
|
|
34
|
-
const COMMITTER_PLAYER_IDS = new Set<string>(['coder', 'reviewer']);
|
|
35
|
-
|
|
36
|
-
// The validated CODE options set. `committer`, when present, is the
|
|
37
|
-
// resolved Committer-alias player id (PBRT-8 / PBRT-30); a future CODE
|
|
38
|
-
// option widens both this type and `CODE_OPTION_KEYS`.
|
|
39
|
-
export interface CodeOptions {
|
|
40
|
-
committer?: 'coder' | 'reviewer';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function validateCodeOptions(captainOptions: unknown): CodeOptions {
|
|
44
|
-
const code = readCodeNamespace(captainOptions);
|
|
45
|
-
if (code === undefined) return {};
|
|
46
|
-
if (typeof code !== 'object' || code === null || Array.isArray(code)) {
|
|
47
|
-
throw new Error('captain.options.code must be an object');
|
|
48
|
-
}
|
|
49
|
-
for (const key of Object.keys(code)) {
|
|
50
|
-
if (!CODE_OPTION_KEYS.has(key)) {
|
|
51
|
-
throw new Error(`Unknown config field captain.options.code.${key}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const options: CodeOptions = {};
|
|
55
|
-
const committer = (code as Record<string, unknown>).committer;
|
|
56
|
-
if (committer !== undefined) {
|
|
57
|
-
if (typeof committer !== 'string' || !COMMITTER_PLAYER_IDS.has(committer)) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
"captain.options.code.committer must be 'coder' or 'reviewer'",
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
options.committer = committer as 'coder' | 'reviewer';
|
|
63
|
-
}
|
|
64
|
-
return options;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function readCodeNamespace(captainOptions: unknown): unknown {
|
|
68
|
-
if (
|
|
69
|
-
typeof captainOptions !== 'object' ||
|
|
70
|
-
captainOptions === null ||
|
|
71
|
-
Array.isArray(captainOptions)
|
|
72
|
-
) {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
return (captainOptions as Record<string, unknown>).code;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Captain factory per TMUX-014: `(options: unknown) => Captain`.
|
|
79
|
-
// `options` is whatever `captain.options` carries in the YAML config;
|
|
80
|
-
// CODE reads only the namespaced `options.code` (PBRT-30). The per-run
|
|
81
|
-
// player identity strings (`coderPlayer`, `reviewerPlayer`) are
|
|
82
|
-
// derived from `session.players` at init time per PBRT-4 — preferring
|
|
83
|
-
// each entry's `model` and falling back to `adapter` when no model is
|
|
84
|
-
// pinned — so player prompts and commit-message trailers carry the
|
|
85
|
-
// concrete model identity (e.g. `claude-opus-4-7`) rather than the
|
|
86
|
-
// adapter family name (e.g. `claude`). They come from `session.players`
|
|
87
|
-
// independent of `captain.options.code` and override any same-named
|
|
88
|
-
// keys.
|
|
4
|
+
import type { Captain } from '@sublang/cligent/tmux-play';
|
|
5
|
+
import createPlaybookCaptainShell from './playbook-captain.js';
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
codeCopyPasteGuardNames,
|
|
9
|
+
codeStateCountLabels,
|
|
10
|
+
codePlaybookRegistryEntry,
|
|
11
|
+
createCodeRuntimeOptions,
|
|
12
|
+
validateCodeOptions,
|
|
13
|
+
} from './code.registry.js';
|
|
14
|
+
export type {
|
|
15
|
+
CodeOptions,
|
|
16
|
+
CodePlaybookRegistryEntry,
|
|
17
|
+
CreateCodeRuntimeOptions,
|
|
18
|
+
RegistryPlayer,
|
|
19
|
+
} from './code.registry.js';
|
|
20
|
+
|
|
21
|
+
// Compatibility shim for the historic `./code/tmux-play` package
|
|
22
|
+
// export. Public launch paths now target the Playbook Captain shell
|
|
23
|
+
// directly; explicit configs that still import this module get the
|
|
24
|
+
// same shell with CODE registered.
|
|
89
25
|
export default function createCodeTmuxPlayCaptain(
|
|
90
26
|
options: unknown,
|
|
91
27
|
): Captain {
|
|
92
|
-
|
|
93
|
-
// CaptainContext is rebuilt per turn and carries the call
|
|
94
|
-
// primitives. The runtime is constructed in `init` so identity
|
|
95
|
-
// strings derived from `session.players` can flow into its options;
|
|
96
|
-
// PlaybookPorts is built once at init, so the per-turn context
|
|
97
|
-
// lives in a closure-scoped slot the port callbacks query lazily.
|
|
98
|
-
let runtime: PlaybookRuntime | undefined;
|
|
99
|
-
let activeContext: CaptainContext | undefined;
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
async init(session: CaptainSession): Promise<void> {
|
|
103
|
-
// PBRT-30: validate `captain.options.code` before constructing
|
|
104
|
-
// the runtime so a stray key fails `init` closed with a
|
|
105
|
-
// path-named error; the empty schema yields an empty options set.
|
|
106
|
-
const codeOptions = validateCodeOptions(options);
|
|
107
|
-
const playerIdentity = (id: string): string | undefined => {
|
|
108
|
-
const entry = session.players.find((p) => p.id === id);
|
|
109
|
-
return entry?.model ?? entry?.adapter;
|
|
110
|
-
};
|
|
111
|
-
const coderPlayer = playerIdentity('coder');
|
|
112
|
-
const reviewerPlayer = playerIdentity('reviewer');
|
|
113
|
-
// Identity strings from `session.players` override any same-named
|
|
114
|
-
// keys and are independent of `captain.options.code` (PBRT-30).
|
|
115
|
-
// The validated `committer` alias threads in as the runtime's
|
|
116
|
-
// Committer player id (`committerPlayer`, PBRT-8).
|
|
117
|
-
const runtimeOptions: CodePlaybookOptions = {
|
|
118
|
-
coderPlayer,
|
|
119
|
-
reviewerPlayer,
|
|
120
|
-
...(codeOptions.committer !== undefined
|
|
121
|
-
? { committerPlayer: codeOptions.committer }
|
|
122
|
-
: {}),
|
|
123
|
-
};
|
|
124
|
-
runtime = createPlaybookRuntime(runtimeOptions);
|
|
125
|
-
const ports: PlaybookPorts = {
|
|
126
|
-
callPlayer: async (playerId, prompt, _signal) => {
|
|
127
|
-
if (!activeContext) {
|
|
128
|
-
throw new Error('callPlayer invoked outside a Boss turn');
|
|
129
|
-
}
|
|
130
|
-
// PlayerRunResult per TMUX-033 already matches PlayerResult
|
|
131
|
-
// (`status: 'ok' | 'aborted' | 'error'`, `finalText?`,
|
|
132
|
-
// `error?`). cligent honors context.signal internally;
|
|
133
|
-
// the runtime's signal is the same source forwarded
|
|
134
|
-
// through handleBossInput, so dropping `_signal` is
|
|
135
|
-
// safe.
|
|
136
|
-
const r = await activeContext.callPlayer(playerId, prompt);
|
|
137
|
-
return {
|
|
138
|
-
status: r.status,
|
|
139
|
-
finalText: r.finalText,
|
|
140
|
-
error: r.error,
|
|
141
|
-
};
|
|
142
|
-
},
|
|
143
|
-
callJudge: async (prompt, _signal) => {
|
|
144
|
-
if (!activeContext) {
|
|
145
|
-
throw new Error('callJudge invoked outside a Boss turn');
|
|
146
|
-
}
|
|
147
|
-
// PBRT-15 / DR-007: run the judge call hidden so its JSON
|
|
148
|
-
// reply never reaches the Boss pane; the runtime composes the
|
|
149
|
-
// human-readable pane lines (PBRT-3) from the parsed result.
|
|
150
|
-
const r = await activeContext.callCaptain(prompt, {
|
|
151
|
-
visibility: 'hidden',
|
|
152
|
-
});
|
|
153
|
-
if (r.status !== 'ok') {
|
|
154
|
-
throw new Error(
|
|
155
|
-
r.error ?? `callCaptain status "${r.status}"`,
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
if (r.finalText === undefined) {
|
|
159
|
-
throw new Error(
|
|
160
|
-
'callCaptain returned status=ok with no finalText',
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
return r.finalText;
|
|
164
|
-
},
|
|
165
|
-
emitStatus: async (message, data) => {
|
|
166
|
-
await session.emitStatus(
|
|
167
|
-
message,
|
|
168
|
-
data as Record<string, unknown> | undefined,
|
|
169
|
-
);
|
|
170
|
-
},
|
|
171
|
-
emitTelemetry: async (event) => {
|
|
172
|
-
await session.emitTelemetry(event);
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
await runtime.init(ports);
|
|
176
|
-
},
|
|
177
|
-
|
|
178
|
-
async handleBossTurn(
|
|
179
|
-
turn: BossTurn,
|
|
180
|
-
context: CaptainContext,
|
|
181
|
-
): Promise<void> {
|
|
182
|
-
if (!runtime) {
|
|
183
|
-
throw new Error('init must be called first');
|
|
184
|
-
}
|
|
185
|
-
activeContext = context;
|
|
186
|
-
try {
|
|
187
|
-
// Forward the Boss prompt + cligent's per-turn signal into
|
|
188
|
-
// the runtime; the runtime stashes the signal so the
|
|
189
|
-
// captain bridge passes it down to callPlayer / callJudge.
|
|
190
|
-
await runtime.handleBossInput({
|
|
191
|
-
text: turn.prompt,
|
|
192
|
-
signal: context.signal,
|
|
193
|
-
});
|
|
194
|
-
} finally {
|
|
195
|
-
activeContext = undefined;
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
async dispose(): Promise<void> {
|
|
200
|
-
await runtime?.dispose();
|
|
201
|
-
},
|
|
202
|
-
};
|
|
28
|
+
return createPlaybookCaptainShell(options);
|
|
203
29
|
}
|