@sublang/playbook 9.0.0 → 11.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 (71) hide show
  1. package/README.md +1 -1
  2. package/docs/cli.md +109 -21
  3. package/docs/configuration.md +89 -40
  4. package/docs/embedding.md +126 -12
  5. package/package.json +14 -3
  6. package/reference/sdlc/captain.md +14 -10
  7. package/reference/sdlc/captain.playbook/captain.fsm.d.ts +33 -13
  8. package/reference/sdlc/captain.playbook/captain.fsm.js +80 -9
  9. package/reference/sdlc/captain.playbook/captain.fsm.ts +137 -18
  10. package/reference/sdlc/captain.playbook/captain.gears.md +10 -6
  11. package/reference/sdlc/captain.playbook/captain.playbook.d.ts +5 -1
  12. package/reference/sdlc/captain.playbook/captain.playbook.js +140 -10
  13. package/reference/sdlc/captain.playbook/captain.playbook.ts +188 -16
  14. package/reference/sdlc/code.md +35 -16
  15. package/reference/sdlc/code.playbook/bin/interactive-session.js +228 -23
  16. package/reference/sdlc/code.playbook/bin/launch-config.js +611 -221
  17. package/reference/sdlc/code.playbook/bin/playbook.js +304 -178
  18. package/reference/sdlc/code.playbook/bin/replay-observer.js +221 -0
  19. package/reference/sdlc/code.playbook/bin/repository-effects.js +2930 -0
  20. package/reference/sdlc/code.playbook/bin/run.js +669 -215
  21. package/reference/sdlc/code.playbook/bin/session-store.js +4546 -502
  22. package/reference/sdlc/code.playbook/code.fsm.d.ts +7 -0
  23. package/reference/sdlc/code.playbook/code.fsm.js +74 -25
  24. package/reference/sdlc/code.playbook/code.fsm.ts +83 -29
  25. package/reference/sdlc/code.playbook/code.gears.md +0 -2
  26. package/reference/sdlc/code.playbook/code.playbook.d.ts +5 -2
  27. package/reference/sdlc/code.playbook/code.playbook.js +54 -2
  28. package/reference/sdlc/code.playbook/code.playbook.ts +75 -6
  29. package/reference/sdlc/code.playbook/code.registry.d.ts +10 -3
  30. package/reference/sdlc/code.playbook/code.registry.js +10 -3
  31. package/reference/sdlc/code.playbook/code.registry.ts +23 -5
  32. package/reference/sdlc/code.playbook/playbook-captain.d.ts +103 -8
  33. package/reference/sdlc/code.playbook/playbook-captain.js +1871 -75
  34. package/reference/sdlc/code.playbook/playbook-captain.ts +2801 -102
  35. package/reference/sdlc/code.playbook/playbook.config.template.yaml +14 -10
  36. package/reference/sdlc/code.playbook/session-store.d.ts +82 -0
  37. package/reference/sdlc/code.playbook/session-store.js +113 -0
  38. package/reference/sdlc/decide.md +24 -16
  39. package/reference/sdlc/decide.playbook/decide.fsm.d.ts +7 -0
  40. package/reference/sdlc/decide.playbook/decide.fsm.js +80 -29
  41. package/reference/sdlc/decide.playbook/decide.fsm.ts +89 -31
  42. package/reference/sdlc/decide.playbook/decide.gears.md +0 -1
  43. package/reference/sdlc/decide.playbook/decide.playbook.d.ts +13 -5
  44. package/reference/sdlc/decide.playbook/decide.playbook.js +1712 -91
  45. package/reference/sdlc/decide.playbook/decide.playbook.ts +2677 -136
  46. package/reference/sdlc/decide.playbook/decide.registry.d.ts +7 -3
  47. package/reference/sdlc/decide.playbook/decide.registry.js +10 -3
  48. package/reference/sdlc/decide.playbook/decide.registry.ts +20 -5
  49. package/reference/sdlc/review.md +36 -18
  50. package/reference/sdlc/review.playbook/review.fsm.d.ts +7 -0
  51. package/reference/sdlc/review.playbook/review.fsm.js +133 -12
  52. package/reference/sdlc/review.playbook/review.fsm.ts +140 -12
  53. package/reference/sdlc/review.playbook/review.playbook.d.ts +5 -2
  54. package/reference/sdlc/review.playbook/review.playbook.js +65 -2
  55. package/reference/sdlc/review.playbook/review.playbook.ts +83 -6
  56. package/reference/sdlc/review.playbook/review.registry.d.ts +10 -3
  57. package/reference/sdlc/review.playbook/review.registry.js +10 -3
  58. package/reference/sdlc/review.playbook/review.registry.ts +23 -5
  59. package/slc/gears2fsm.md +6 -5
  60. package/slc/link.md +544 -41
  61. package/src/accepted-outcome.d.ts +18 -0
  62. package/src/accepted-outcome.js +94 -0
  63. package/src/accepted-outcome.ts +140 -0
  64. package/src/runtime.d.ts +164 -3
  65. package/src/runtime.ts +213 -2
  66. package/src/xstate-playbook-runtime.d.ts +149 -10
  67. package/src/xstate-playbook-runtime.js +2569 -270
  68. package/src/xstate-playbook-runtime.ts +4133 -490
  69. package/src/xstate-runtime.d.ts +59 -1
  70. package/src/xstate-runtime.js +866 -7
  71. package/src/xstate-runtime.ts +1397 -7
@@ -47,13 +47,20 @@ export const codePlaybookRegistryEntry = {
47
47
  id: 'code',
48
48
  command: 'code',
49
49
  intent: 'implement a coding intent in reviewed, one-commit phases, using an intent record when needed',
50
- artifactSchema: 2,
50
+ artifactSchema: 3,
51
+ runtimeProfile: Object.freeze({
52
+ kind: 'shared-factory',
53
+ compat: createPlaybookRuntime.compat,
54
+ }),
51
55
  requiredRoleIds: ['coder'],
52
56
  concurrentRoleSets: [],
53
57
  summaryPolicy: codeSummaryPolicy,
54
58
  validateOptions: validateCodeOptions,
55
- createRuntime(options) {
56
- return createPlaybookRuntime(options);
59
+ createRuntime(options, hostCapabilities) {
60
+ return createPlaybookRuntime({
61
+ configuredOptions: options,
62
+ hostCapabilities,
63
+ });
57
64
  },
58
65
  };
59
66
  export default codePlaybookRegistryEntry;
@@ -2,6 +2,7 @@
2
2
  // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
3
 
4
4
  import createPlaybookRuntime, {
5
+ type CodePlaybookHostCapabilities,
5
6
  type PlaybookRuntime,
6
7
  } from './code.playbook.js';
7
8
 
@@ -20,12 +21,22 @@ export interface CodePlaybookRegistryEntry {
20
21
  id: 'code';
21
22
  command: 'code';
22
23
  intent: string;
23
- artifactSchema: 2;
24
+ artifactSchema: 3;
25
+ runtimeProfile: {
26
+ readonly kind: 'shared-factory';
27
+ readonly compat: {
28
+ readonly artifactSchema: 3;
29
+ readonly runtimeAbi: number;
30
+ };
31
+ };
24
32
  requiredRoleIds: readonly ['coder'];
25
33
  concurrentRoleSets: readonly [];
26
34
  summaryPolicy: PlaybookSummaryPolicy;
27
35
  validateOptions(optionSlice: unknown): CodeOptions;
28
- createRuntime(options: CodeOptions): PlaybookRuntime;
36
+ createRuntime(
37
+ options: CodeOptions,
38
+ hostCapabilities: CodePlaybookHostCapabilities,
39
+ ): PlaybookRuntime;
29
40
  }
30
41
 
31
42
  // REVIEW owns and labels its real review rounds. CODE's two suspended wrapper
@@ -91,13 +102,20 @@ export const codePlaybookRegistryEntry: CodePlaybookRegistryEntry = {
91
102
  command: 'code',
92
103
  intent:
93
104
  'implement a coding intent in reviewed, one-commit phases, using an intent record when needed',
94
- artifactSchema: 2,
105
+ artifactSchema: 3,
106
+ runtimeProfile: Object.freeze({
107
+ kind: 'shared-factory',
108
+ compat: createPlaybookRuntime.compat,
109
+ }),
95
110
  requiredRoleIds: ['coder'],
96
111
  concurrentRoleSets: [],
97
112
  summaryPolicy: codeSummaryPolicy,
98
113
  validateOptions: validateCodeOptions,
99
- createRuntime(options) {
100
- return createPlaybookRuntime(options);
114
+ createRuntime(options, hostCapabilities) {
115
+ return createPlaybookRuntime({
116
+ configuredOptions: options,
117
+ hostCapabilities,
118
+ });
101
119
  },
102
120
  };
103
121
 
@@ -1,12 +1,15 @@
1
1
  import { type Captain, type CaptainSession, type TuningSelection } from '@sublang/cligent/tmux-play';
2
2
  import type { Effort, PermissionPolicy } from '@sublang/cligent';
3
- import type { JsonValue, PlaybookRuntime, PlaybookRuntimeSnapshot } from '@sublang/playbook/runtime';
3
+ import type { JsonValue, PlaybookEffectLedger, PlaybookEffectLedgerCommandBatch, PlaybookRuntime, PlaybookRuntimeSnapshot } from '@sublang/playbook/runtime';
4
4
  import { type CaptainControllerPort } from '../captain.playbook/captain.playbook.js';
5
5
  import type { PlaybookSummaryPolicy } from './code.registry.js';
6
6
  interface SessionAgent {
7
7
  readonly adapter: string;
8
8
  readonly model: TuningSelection;
9
9
  readonly effort: TuningSelection<Effort>;
10
+ /** Adapter-scoped fast mode. Absence is the provider default; `false` is a
11
+ * literal request, so this carries no provider-default sentinel. */
12
+ readonly fastMode?: boolean;
10
13
  readonly instruction?: string;
11
14
  readonly permissions?: PermissionPolicy;
12
15
  }
@@ -19,11 +22,22 @@ interface PlayerLedgerEntry {
19
22
  type DeepReadonly<T> = T extends (...args: never[]) => unknown ? T : T extends readonly (infer Element)[] ? readonly DeepReadonly<Element>[] : T extends object ? {
20
23
  readonly [Key in keyof T]: DeepReadonly<T[Key]>;
21
24
  } : T;
22
- type SnapshotAgentEnvelope = DeepReadonly<Omit<SessionAgent, 'model' | 'effort'>>;
25
+ export interface PlaybookCaptainUnresolvedEffect {
26
+ readonly classification: 'one-descendant-commit' | 'multiple-commits' | 'rewritten-or-non-descendant' | 'worktree-only-change' | 'concurrent-or-foreign-change' | 'observation-ambiguous' | 'incomplete';
27
+ readonly baselineHead: string;
28
+ readonly afterHead?: string;
29
+ readonly commitOid?: string;
30
+ }
31
+ interface PlaybookCaptainUnresolvedEffectSettlementInput {
32
+ readonly rootPlaybookId: string;
33
+ readonly unresolvedEffects: readonly PlaybookCaptainUnresolvedEffect[];
34
+ }
35
+ type SnapshotAgentEnvelope = DeepReadonly<Omit<SessionAgent, 'model' | 'effort' | 'fastMode'>>;
23
36
  type PlayerLedgerSnapshotEntry = DeepReadonly<PlayerLedgerEntry>;
24
37
  export interface PlaybookCaptainDeps {
25
38
  loadModule?: (specifier: string) => Promise<unknown>;
26
39
  createSessionId?: () => string;
40
+ hostCapabilities?: Readonly<Record<string, PlaybookHostConstructionCapabilities>>;
27
41
  createCaptainRuntime?: (options: {
28
42
  readonly enabledPlaybooks: readonly {
29
43
  readonly id: string;
@@ -32,18 +46,67 @@ export interface PlaybookCaptainDeps {
32
46
  }[];
33
47
  readonly controller: CaptainControllerPort;
34
48
  }) => PlaybookRuntime;
49
+ unresolvedEffectSettlement?: {
50
+ begin(input: PlaybookCaptainUnresolvedEffectSettlementInput): Promise<void>;
51
+ complete(input: PlaybookCaptainUnresolvedEffectSettlementInput): Promise<void>;
52
+ };
53
+ }
54
+ /** Live, artifact-typed host facilities supplied outside configured options. */
55
+ export interface PlaybookHostConstructionCapabilities {
56
+ readonly authority: {
57
+ readonly playbookId: string;
58
+ readonly artifactSchema: 3;
59
+ readonly cwd: string;
60
+ readonly sessionId: string;
61
+ readonly leaseOwnerToken: string;
62
+ readonly canonicalWorktree: {
63
+ readonly worktree: string;
64
+ readonly gitDir: string;
65
+ };
66
+ readonly requiredRoleIds: readonly string[];
67
+ readonly concurrentRoleSets: readonly (readonly string[])[];
68
+ };
69
+ readonly repository: {
70
+ readonly identity: {
71
+ readonly worktree: string;
72
+ readonly gitDir: string;
73
+ };
74
+ readonly observe: (options?: unknown) => Promise<unknown>;
75
+ readonly acquire: (options?: unknown) => Promise<unknown>;
76
+ readonly runExclusive: (options: unknown) => Promise<unknown>;
77
+ readonly runCohort: (options: unknown) => Promise<unknown>;
78
+ readonly runDeferred: (options: unknown) => Promise<unknown>;
79
+ };
80
+ readonly effectLedger: {
81
+ readonly snapshot: () => PlaybookEffectLedger;
82
+ readonly writeAhead: (commands: PlaybookEffectLedgerCommandBatch) => Promise<PlaybookEffectLedger>;
83
+ };
35
84
  }
36
- export interface PlaybookCaptainRegistryEntry {
85
+ export type PlaybookCaptainRuntimeProfile = {
86
+ readonly kind: 'shared-factory';
87
+ readonly compat: {
88
+ readonly artifactSchema: 3;
89
+ readonly runtimeAbi: number;
90
+ };
91
+ } | {
92
+ readonly kind: 'bespoke';
93
+ readonly artifactSchema: 3;
94
+ };
95
+ interface PlaybookCaptainRegistryEntryBase {
37
96
  id: string;
38
97
  command: string;
39
98
  intent: string;
40
- artifactSchema: 2;
99
+ runtimeProfile: PlaybookCaptainRuntimeProfile;
41
100
  requiredRoleIds: readonly string[];
42
101
  concurrentRoleSets: readonly (readonly string[])[];
43
102
  summaryPolicy?: PlaybookSummaryPolicy;
44
103
  validateOptions(optionSlice: unknown): unknown;
45
- createRuntime(options: unknown): PlaybookRuntime;
46
104
  }
105
+ export interface PlaybookCaptainRegistryEntryV3 extends PlaybookCaptainRegistryEntryBase {
106
+ artifactSchema: 3;
107
+ createRuntime(configuredOptions: unknown, hostCapabilities: PlaybookHostConstructionCapabilities): PlaybookRuntime;
108
+ }
109
+ export type PlaybookCaptainRegistryEntry = PlaybookCaptainRegistryEntryV3;
47
110
  type PlaybookCaptainConversationSnapshot = {
48
111
  readonly kind: 'unopened';
49
112
  } | {
@@ -62,7 +125,7 @@ interface PlaybookCaptainJournalRecord {
62
125
  readonly kind: 'boss' | 'reply' | 'handoff' | 'action' | 'outcome';
63
126
  readonly payload: JsonValue;
64
127
  }
65
- interface PlaybookCaptainFrameSnapshot {
128
+ export interface PlaybookCaptainFrameSnapshot {
66
129
  readonly playbookId: string;
67
130
  readonly sessionId: string;
68
131
  readonly rootSessionId: string;
@@ -74,7 +137,8 @@ interface PlaybookCaptainFrameSnapshot {
74
137
  readonly runtime: DeepReadonly<PlaybookRuntimeSnapshot>;
75
138
  }
76
139
  interface PlaybookCaptainShellSnapshotFields {
77
- readonly schemaVersion: 3;
140
+ readonly schemaVersion: 4;
141
+ readonly effectLedger: DeepReadonly<PlaybookEffectLedger>;
78
142
  readonly captain: {
79
143
  readonly sessionId: string;
80
144
  readonly runtime: DeepReadonly<PlaybookRuntimeSnapshot>;
@@ -89,7 +153,7 @@ interface PlaybookCaptainShellSnapshotFields {
89
153
  readonly journal: number;
90
154
  };
91
155
  readonly journal: readonly PlaybookCaptainJournalRecord[];
92
- readonly lastAction?: 'respond' | 'start' | 'switch' | 'dismiss' | 'deliver' | 'runtime';
156
+ readonly lastAction?: 'respond' | 'start' | 'switch' | 'resume' | 'dismiss' | 'deliver' | 'runtime';
93
157
  readonly lastSettlementStatus?: 'ok' | 'rejected' | 'failed';
94
158
  }
95
159
  /**
@@ -105,6 +169,7 @@ type PlaybookCaptainShellSnapshotValue = PlaybookCaptainShellSnapshotFields & ({
105
169
  readonly mode: 'engaged.parked';
106
170
  /** Root-to-leaf engagement order. */
107
171
  readonly frames: readonly PlaybookCaptainFrameSnapshot[];
172
+ readonly retainedEffectReconciliation?: PlaybookCaptainRetainedEffectReconciliation;
108
173
  readonly pendingBossQuestions?: JsonValue;
109
174
  readonly lastError?: {
110
175
  readonly name: string;
@@ -112,11 +177,41 @@ type PlaybookCaptainShellSnapshotValue = PlaybookCaptainShellSnapshotFields & ({
112
177
  };
113
178
  });
114
179
  export type PlaybookCaptainShellSnapshot = DeepReadonly<PlaybookCaptainShellSnapshotValue>;
180
+ export interface PlaybookCaptainRetainedGeneration {
181
+ /** Repository-effect checkpoint reflected by the retained machine state. */
182
+ readonly effectLedger: DeepReadonly<PlaybookEffectLedger>;
183
+ readonly frames: readonly PlaybookCaptainFrameSnapshot[];
184
+ readonly retainedEffectReconciliation?: {
185
+ readonly sourceGenerationId: string;
186
+ };
187
+ /** Boss-facing description published for the retained root state, if any. */
188
+ readonly rootStateDescription?: string;
189
+ }
190
+ interface PlaybookCaptainRetainedEffectReconciliation {
191
+ readonly sourceGenerationId: string;
192
+ readonly checkpoint: DeepReadonly<PlaybookEffectLedger>;
193
+ }
194
+ export type PlaybookCaptainRetentionUpdate = {
195
+ readonly kind: 'retain';
196
+ readonly rootPlaybookId: string;
197
+ readonly generation: PlaybookCaptainRetainedGeneration;
198
+ } | {
199
+ readonly kind: 'clear';
200
+ readonly rootPlaybookId: string;
201
+ };
202
+ export interface PlaybookCaptainSettlement {
203
+ readonly snapshot: PlaybookCaptainShellSnapshot;
204
+ readonly retentionUpdates: readonly PlaybookCaptainRetentionUpdate[];
205
+ readonly unresolvedEffects: readonly PlaybookCaptainUnresolvedEffect[];
206
+ }
115
207
  /** tmux and headless front ends share this one durable Captain shell API. */
116
208
  export interface PlaybookCaptainShell extends Captain {
209
+ installRetainedGenerations(generations: Readonly<Record<string, PlaybookCaptainRetainedGeneration>>): Promise<void>;
117
210
  exportSnapshot(): PlaybookCaptainShellSnapshot | undefined;
211
+ exportSettlement(): PlaybookCaptainSettlement | undefined;
118
212
  restore(session: CaptainSession, snapshot: PlaybookCaptainShellSnapshot): Promise<void>;
119
213
  }
214
+ export declare function assertPlaybookCaptainUnresolvedEffects(value: unknown): readonly PlaybookCaptainUnresolvedEffect[];
120
215
  /** Validate, detach, and freeze one untrusted shell snapshot. */
121
216
  export declare function assertPlaybookCaptainShellSnapshot(value: unknown): PlaybookCaptainShellSnapshot;
122
217
  export declare function createPlaybookCaptainShell(options: unknown, deps?: PlaybookCaptainDeps): PlaybookCaptainShell;