@sublang/playbook 3.1.0 → 5.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 (31) hide show
  1. package/README.md +64 -99
  2. package/docs/assets/playbook-venn.svg +13 -0
  3. package/docs/cli.md +83 -9
  4. package/docs/configuration.md +5 -3
  5. package/package.json +7 -4
  6. package/reference/sdlc/captain.md +70 -83
  7. package/reference/sdlc/captain.playbook/captain.fsm.d.ts +127 -142
  8. package/reference/sdlc/captain.playbook/captain.fsm.js +349 -470
  9. package/reference/sdlc/captain.playbook/captain.fsm.ts +535 -598
  10. package/reference/sdlc/captain.playbook/captain.gears.md +37 -41
  11. package/reference/sdlc/captain.playbook/captain.playbook.d.ts +90 -15
  12. package/reference/sdlc/captain.playbook/captain.playbook.js +464 -968
  13. package/reference/sdlc/captain.playbook/captain.playbook.ts +696 -993
  14. package/reference/sdlc/code.playbook/bin/adapter-sdk.js +247 -0
  15. package/reference/sdlc/code.playbook/bin/playbook.js +54 -9
  16. package/reference/sdlc/code.playbook/bin/run.js +97 -0
  17. package/reference/sdlc/code.playbook/code.playbook.js +17 -0
  18. package/reference/sdlc/code.playbook/code.playbook.ts +17 -0
  19. package/reference/sdlc/code.playbook/playbook-captain.d.ts +2 -0
  20. package/reference/sdlc/code.playbook/playbook-captain.js +1784 -215
  21. package/reference/sdlc/code.playbook/playbook-captain.ts +2293 -330
  22. package/reference/sdlc/code.playbook/playbook.config.template.yaml +7 -0
  23. package/reference/sdlc/discuss.playbook/discuss.playbook.js +41 -9
  24. package/reference/sdlc/discuss.playbook/discuss.playbook.ts +42 -9
  25. package/slc/gears2fsm.md +54 -2
  26. package/slc/link.md +293 -25
  27. package/src/runtime.d.ts +29 -1
  28. package/src/runtime.ts +47 -0
  29. package/src/xstate-playbook-runtime.d.ts +97 -5
  30. package/src/xstate-playbook-runtime.js +769 -29
  31. package/src/xstate-playbook-runtime.ts +962 -34
@@ -1,163 +1,154 @@
1
1
  export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
2
2
  readonly [key: string]: JsonValue;
3
3
  };
4
+ /** One immutable host-catalog entry (id + command + intent only). */
4
5
  export type EnabledPlaybook = {
5
6
  readonly id: string;
6
7
  readonly command: string;
7
8
  readonly intent: string;
8
9
  };
9
- export type NormalizedError = {
10
- readonly name: string;
11
- readonly message: string;
12
- readonly stack?: string;
13
- };
14
- export type PlaybookStateValue = string | {
15
- readonly [key: string]: PlaybookStateValue;
16
- };
17
- export type PlaybookState = {
18
- readonly value: PlaybookStateValue;
19
- readonly activeStateIds: readonly string[];
20
- readonly tags: readonly string[];
21
- readonly status: 'active' | 'done' | 'error' | 'stopped';
22
- readonly quiescent: boolean;
23
- readonly stateId?: string;
24
- };
25
- export type CompletedCallResult = {
10
+ /** The closed controller action set (DR-029; stable machine contract). */
11
+ export type DecisionAction = 'respond' | 'start' | 'switch' | 'dismiss' | 'deliver' | 'runtime';
12
+ /**
13
+ * A deterministic parse-resolved acting decision injected by the host
14
+ * (CAPTAIN-7 parse table): the turn's decision object, entering the decision
15
+ * state with no decision model call.
16
+ */
17
+ export type ParsedActingDecision = {
18
+ readonly action: 'start' | 'switch';
26
19
  readonly playbookId: string;
27
- readonly status: 'ok';
28
- readonly output?: JsonValue;
20
+ readonly input: string;
29
21
  } | {
30
- readonly playbookId: string;
31
- readonly status: 'aborted' | 'error';
32
- readonly error: NormalizedError;
22
+ readonly action: 'deliver';
23
+ };
24
+ /** Compact `{ name, message }` error evidence (never a raw Error). */
25
+ export type CompactError = {
26
+ readonly name: string;
27
+ readonly message: string;
33
28
  };
34
- export type PendingBossQuestion = {
35
- readonly questionId: ResumableStateId;
36
- readonly resumeStateId: ResumableStateId;
37
- readonly sourceItem: 'CAPTAIN-1' | 'CAPTAIN-3';
38
- readonly player: 'Captain';
39
- readonly question: string;
29
+ /** Receipt evidence of an executed `runtime` action (disposition only). */
30
+ export type SettlementReceiptEvidence = {
31
+ readonly disposition: 'executed' | 'rejected' | 'failed';
32
+ readonly reason?: string;
33
+ readonly error?: CompactError;
34
+ };
35
+ /**
36
+ * The controller-port settlement evidence the machine may retain: status,
37
+ * outcome-report facts, optional rejection reason, receipt disposition, and
38
+ * leaf-state summary — never a session id, call id, child state, stack
39
+ * ledger, resume token, or opaque runtime result (CAPPLAY-10).
40
+ */
41
+ export type SettlementEvidence = {
42
+ readonly status: 'ok' | 'rejected' | 'failed';
43
+ readonly facts: readonly string[];
44
+ readonly reason?: string;
45
+ readonly receipt?: SettlementReceiptEvidence;
46
+ readonly leafStateSummary?: string;
40
47
  };
41
- export type ResumableStateId = 'routing' | 'reassessing';
42
48
  export type CaptainMachineInput = {
43
49
  readonly enabledPlaybooks: readonly EnabledPlaybook[];
44
- readonly selfPlaybookId: string;
45
- readonly bossIntent?: string;
46
- };
47
- export type CaptainMachineOutput = {
48
- readonly response: string;
49
50
  };
51
+ export type CaptainStateId = 'deciding' | 'answeringCommand' | 'reporting';
52
+ export type CaptainSourceItem = 'CAPTAIN-1' | 'CAPTAIN-2' | 'CAPTAIN-3';
50
53
  export type CaptainInput = {
51
- readonly stateId: ResumableStateId;
52
- readonly sourceItem: 'CAPTAIN-1' | 'CAPTAIN-3';
54
+ readonly stateId: CaptainStateId;
55
+ readonly sourceItem: CaptainSourceItem;
53
56
  readonly prompt: string;
54
57
  readonly result: Record<string, string>;
55
- readonly bossIntent: string;
56
- readonly enabledPlaybooks: readonly EnabledPlaybook[];
57
- readonly remainingPlan?: readonly JsonValue[];
58
- readonly completedCallResults?: readonly CompletedCallResult[];
59
- readonly pendingBossQuestion?: PendingBossQuestion;
60
- readonly bossReply?: string;
61
- };
58
+ /**
59
+ * DR-013 A1 source-owned tool restriction: this playbook's policy forbids
60
+ * tools on every Captain call, so each state requests the empty allowlist.
61
+ */
62
+ readonly allowedTools: readonly string[];
63
+ /** The injected parse-resolved decision, when the host's parse decided the turn. */
64
+ readonly parsedDecision?: ParsedActingDecision;
65
+ };
66
+ /**
67
+ * Decision-state output: the validated selection under the stable controller
68
+ * guard contract — `respond` | `start` | `switch` | `dismiss` | `deliver` |
69
+ * `runtime`, with the payload fields DR-029 requires — plus the
70
+ * controller-port settlement evidence of the executed submission. The prose
71
+ * states (`answeringCommand`, `reporting`) carry the default single-outcome
72
+ * `done` contract.
73
+ */
62
74
  export type CaptainOutput = {
63
- readonly guard: 'question';
64
- readonly question: string;
75
+ readonly guard: 'respond';
76
+ readonly text: string;
77
+ readonly settlement: SettlementEvidence;
65
78
  } | {
66
- readonly guard: 'delegation';
67
- readonly remainingPlan: readonly JsonValue[];
68
- readonly nextPlaybookId: string;
69
- readonly nextPlaybookInput: string;
79
+ readonly guard: 'start';
80
+ readonly playbookId: string;
81
+ readonly input: string;
82
+ readonly settlement: SettlementEvidence;
70
83
  } | {
71
- readonly guard: 'final';
72
- readonly response: string;
84
+ readonly guard: 'switch';
85
+ readonly playbookId: string;
86
+ readonly input: string;
87
+ readonly settlement: SettlementEvidence;
73
88
  } | {
74
- readonly guard: 'followUpQuestion';
75
- readonly question: string;
89
+ readonly guard: 'dismiss';
90
+ readonly settlement: SettlementEvidence;
76
91
  } | {
77
- readonly guard: 'continuing';
78
- readonly remainingPlan: readonly JsonValue[];
79
- readonly nextPlaybookId: string;
80
- readonly nextPlaybookInput: string;
92
+ readonly guard: 'deliver';
93
+ readonly settlement: SettlementEvidence;
81
94
  } | {
82
- readonly guard: 'needsBossReply';
83
- readonly question: string;
84
- };
85
- export type PlaybookInput = {
86
- readonly stateId: 'callPlaybook';
87
- readonly sourceItem?: 'CAPTAIN-2';
88
- readonly playbookId: string;
89
- readonly text: string;
90
- readonly playbookIdContext: 'nextPlaybookId';
91
- readonly textContext: 'nextPlaybookInput';
95
+ readonly guard: 'runtime';
96
+ readonly actionId: string;
97
+ readonly settlement: SettlementEvidence;
98
+ } | {
99
+ readonly guard: 'done';
92
100
  };
93
- export type PlaybookOutput = JsonValue | undefined;
94
101
  type Context = {
95
- readonly bossIntent: string;
96
102
  readonly enabledPlaybooks: readonly EnabledPlaybook[];
97
- readonly selfPlaybookId: string;
98
- readonly remainingPlan: readonly JsonValue[];
99
- readonly completedCallResults: readonly CompletedCallResult[];
100
- readonly nextPlaybookId: string;
101
- readonly nextPlaybookInput: string;
102
- readonly callHistory: readonly string[];
103
- readonly response?: string;
104
- readonly pendingBossQuestion?: PendingBossQuestion;
105
- readonly bossReply?: string;
103
+ readonly bossText: string;
104
+ readonly parsedDecision?: ParsedActingDecision;
105
+ readonly selectedAction?: DecisionAction;
106
+ readonly settlementStatus?: 'ok' | 'rejected' | 'failed';
107
+ readonly settlementFacts?: readonly string[];
108
+ readonly settlementReason?: string;
109
+ readonly receiptDisposition?: 'executed' | 'rejected' | 'failed';
110
+ readonly receiptReason?: string;
111
+ readonly receiptError?: CompactError;
112
+ readonly leafStateSummary?: string;
106
113
  readonly lastError?: JsonValue;
107
114
  };
108
- type BossIntentEvent = {
109
- readonly type: 'BOSS_INTENT';
110
- readonly bossIntent: string;
115
+ type BossTurnEvent = {
116
+ readonly type: 'BOSS_TURN';
117
+ readonly bossText: string;
118
+ };
119
+ type ParsedRespondEvent = {
120
+ readonly type: 'PARSED_RESPOND';
121
+ readonly bossText: string;
111
122
  };
112
- type BossInterruptEvent = {
113
- readonly type: 'BOSS_INTERRUPT';
114
- readonly targetId: 'routing';
115
- readonly bossIntent: string;
123
+ type ParsedActionEvent = {
124
+ readonly type: 'PARSED_ACTION';
125
+ readonly bossText: string;
126
+ readonly decision: ParsedActingDecision;
116
127
  };
117
- type BossReplyEvent = {
118
- readonly type: 'BOSS_REPLY';
119
- readonly answer: string;
120
- readonly questionId?: string;
128
+ type ShutdownEvent = {
129
+ readonly type: 'SHUTDOWN';
121
130
  };
122
- export declare const captainMachine: import("xstate").StateMachine<Context, BossIntentEvent | BossInterruptEvent | BossReplyEvent, {
123
- [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<PlaybookOutput, PlaybookInput, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<CaptainOutput, CaptainInput, import("xstate").EventObject>> | undefined;
131
+ export type CaptainMachineEvent = BossTurnEvent | ParsedRespondEvent | ParsedActionEvent | ShutdownEvent;
132
+ export declare const captainMachine: import("xstate").StateMachine<Context, BossTurnEvent | ParsedRespondEvent | ParsedActionEvent | ShutdownEvent, {
133
+ [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<CaptainOutput, CaptainInput, import("xstate").EventObject>> | undefined;
124
134
  }, {
125
- src: "playbook";
126
- logic: import("xstate").PromiseActorLogic<PlaybookOutput, PlaybookInput, import("xstate").EventObject>;
127
- id: string | undefined;
128
- } | {
129
135
  src: "captain";
130
136
  logic: import("xstate").PromiseActorLogic<CaptainOutput, CaptainInput, import("xstate").EventObject>;
131
137
  id: string | undefined;
132
138
  }, {
133
- type: "startRoutingFromBoss";
139
+ type: "startDecidedTurn";
134
140
  params: import("xstate").NonReducibleUnknown;
135
141
  } | {
136
- type: "storeBossReply";
142
+ type: "startCommandTurn";
137
143
  params: import("xstate").NonReducibleUnknown;
138
144
  } | {
139
- type: "rememberInvalidBossReply";
145
+ type: "startParsedTurn";
140
146
  params: import("xstate").NonReducibleUnknown;
141
147
  } | {
142
- type: "setRoutingQuestion";
148
+ type: "recordSettlement";
143
149
  params: import("xstate").NonReducibleUnknown;
144
150
  } | {
145
- type: "storeRoutingDelegation";
146
- params: import("xstate").NonReducibleUnknown;
147
- } | {
148
- type: "appendSuccessfulChildResult";
149
- params: import("xstate").NonReducibleUnknown;
150
- } | {
151
- type: "appendRejectedChildResult";
152
- params: import("xstate").NonReducibleUnknown;
153
- } | {
154
- type: "storeFinalResponse";
155
- params: import("xstate").NonReducibleUnknown;
156
- } | {
157
- type: "setReassessQuestion";
158
- params: import("xstate").NonReducibleUnknown;
159
- } | {
160
- type: "storeContinuingCall";
151
+ type: "recordDecisionReplyFailure";
161
152
  params: import("xstate").NonReducibleUnknown;
162
153
  } | {
163
154
  type: "rememberInvalidActorOutput";
@@ -166,61 +157,55 @@ export declare const captainMachine: import("xstate").StateMachine<Context, Boss
166
157
  type: "rememberActorError";
167
158
  params: import("xstate").NonReducibleUnknown;
168
159
  }, {
169
- type: "isRoutingInterrupt";
170
- params: unknown;
171
- } | {
172
- type: "canResumeRouting";
160
+ type: "start";
173
161
  params: unknown;
174
162
  } | {
175
- type: "canResumeReassessing";
163
+ type: "respond";
176
164
  params: unknown;
177
165
  } | {
178
- type: "hasBossIntent";
166
+ type: "switch";
179
167
  params: unknown;
180
168
  } | {
181
- type: "isRoutingQuestion";
169
+ type: "dismiss";
182
170
  params: unknown;
183
171
  } | {
184
- type: "isRoutingDelegation";
172
+ type: "deliver";
185
173
  params: unknown;
186
174
  } | {
187
- type: "isReassessFinal";
175
+ type: "runtime";
188
176
  params: unknown;
189
177
  } | {
190
- type: "isReassessQuestion";
178
+ type: "hasBossTurnText";
191
179
  params: unknown;
192
180
  } | {
193
- type: "isReassessContinuing";
181
+ type: "hasCommandRespondText";
194
182
  params: unknown;
195
183
  } | {
196
- type: "isPlaybookSuccessOutput";
184
+ type: "hasParsedActingDecision";
197
185
  params: unknown;
198
186
  } | {
199
- type: "isAuthoredChildError";
187
+ type: "isDecisionReplyFailure";
200
188
  params: unknown;
201
- }, never, "done" | "failed" | "callPlaybook" | "awaitBossReply" | "ready" | "routing" | "reassessing", string, CaptainMachineInput, CaptainMachineOutput, import("xstate").EventObject, import("xstate").MetaObject, {
189
+ }, never, "failed" | "deciding" | "answeringCommand" | "reporting" | "hub" | "shutdown", string, CaptainMachineInput, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, {
202
190
  id: "captain";
203
191
  states: {
204
- readonly ready: {
205
- id: "ready";
206
- };
207
- readonly routing: {
208
- id: "routing";
192
+ readonly hub: {
193
+ id: "hub";
209
194
  };
210
- readonly callPlaybook: {
211
- id: "callPlaybook";
195
+ readonly deciding: {
196
+ id: "deciding";
212
197
  };
213
- readonly reassessing: {
214
- id: "reassessing";
198
+ readonly answeringCommand: {
199
+ id: "answeringCommand";
215
200
  };
216
- readonly awaitBossReply: {
217
- id: "awaitBossReply";
201
+ readonly reporting: {
202
+ id: "reporting";
218
203
  };
219
204
  readonly failed: {
220
205
  id: "failed";
221
206
  };
222
- readonly done: {
223
- id: "done";
207
+ readonly shutdown: {
208
+ id: "shutdown";
224
209
  };
225
210
  };
226
211
  }>;