@sublang/playbook 0.9.0 → 1.3.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 (51) hide show
  1. package/README.md +190 -151
  2. package/package.json +50 -6
  3. package/reference/sdlc/captain.md +102 -0
  4. package/reference/sdlc/captain.playbook/captain.fsm.d.ts +227 -0
  5. package/reference/sdlc/captain.playbook/captain.fsm.js +628 -0
  6. package/reference/sdlc/captain.playbook/captain.fsm.ts +851 -0
  7. package/reference/sdlc/captain.playbook/captain.gears.md +60 -0
  8. package/reference/sdlc/captain.playbook/captain.playbook.d.ts +23 -0
  9. package/reference/sdlc/captain.playbook/captain.playbook.js +1053 -0
  10. package/reference/sdlc/captain.playbook/captain.playbook.ts +1144 -0
  11. package/reference/sdlc/code.playbook/bin/playbook.js +158 -12
  12. package/reference/sdlc/code.playbook/bin/run.js +999 -0
  13. package/reference/sdlc/code.playbook/code.fsm.d.ts +11 -4
  14. package/reference/sdlc/code.playbook/code.fsm.introspect.d.ts +2 -2
  15. package/reference/sdlc/code.playbook/code.fsm.introspect.js +1 -1
  16. package/reference/sdlc/code.playbook/code.fsm.introspect.ts +6 -6
  17. package/reference/sdlc/code.playbook/code.fsm.js +334 -102
  18. package/reference/sdlc/code.playbook/code.fsm.ts +467 -180
  19. package/reference/sdlc/code.playbook/code.gears.md +11 -10
  20. package/reference/sdlc/code.playbook/code.playbook.d.ts +16 -19
  21. package/reference/sdlc/code.playbook/code.playbook.js +199 -488
  22. package/reference/sdlc/code.playbook/code.playbook.ts +327 -566
  23. package/reference/sdlc/code.playbook/code.registry.d.ts +0 -3
  24. package/reference/sdlc/code.playbook/code.registry.js +0 -3
  25. package/reference/sdlc/code.playbook/code.registry.ts +0 -6
  26. package/reference/sdlc/code.playbook/playbook-captain.d.ts +9 -4
  27. package/reference/sdlc/code.playbook/playbook-captain.js +889 -210
  28. package/reference/sdlc/code.playbook/playbook-captain.ts +1136 -257
  29. package/reference/sdlc/code.playbook/playbook.config.template.yaml +21 -0
  30. package/reference/sdlc/discuss.playbook/discuss.fsm.d.ts +396 -0
  31. package/reference/sdlc/discuss.playbook/discuss.fsm.js +2066 -0
  32. package/reference/sdlc/discuss.playbook/discuss.fsm.ts +2464 -0
  33. package/reference/sdlc/discuss.playbook/discuss.gears.md +251 -0
  34. package/reference/sdlc/discuss.playbook/discuss.playbook.d.ts +113 -0
  35. package/reference/sdlc/discuss.playbook/discuss.playbook.js +1514 -0
  36. package/reference/sdlc/discuss.playbook/discuss.playbook.ts +1926 -0
  37. package/reference/sdlc/discuss.playbook/discuss.registry.d.ts +58 -0
  38. package/reference/sdlc/discuss.playbook/discuss.registry.js +97 -0
  39. package/reference/sdlc/discuss.playbook/discuss.registry.ts +153 -0
  40. package/slc/gears2fsm.md +557 -57
  41. package/slc/link.md +1165 -89
  42. package/slc/optimize.md +92 -0
  43. package/slc/text2gears.md +255 -7
  44. package/src/runtime.d.ts +146 -3
  45. package/src/runtime.ts +201 -2
  46. package/src/xstate-playbook-runtime.d.ts +201 -0
  47. package/src/xstate-playbook-runtime.js +2058 -0
  48. package/src/xstate-playbook-runtime.ts +2792 -0
  49. package/src/xstate-runtime.d.ts +95 -0
  50. package/src/xstate-runtime.js +1258 -0
  51. package/src/xstate-runtime.ts +1816 -0
@@ -0,0 +1,60 @@
1
+ <!-- SPDX-License-Identifier: Apache-2.0 -->
2
+ <!-- SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai> -->
3
+
4
+ # Captain GEARS
5
+
6
+ ### CAPTAIN-1
7
+
8
+ Where this is the default generic Captain playbook with no players beyond Boss and Captain, where at runtime Captain receives the exact original Boss intent and an immutable host input catalog of enabled callable playbooks whose entries contain only a stable playbook id, its command, and its intent, where Boss events and Captain decisions cannot replace the catalog, where Captain shall call only ids in that catalog and shall never call this Captain playbook itself, where Captain is a router and not the specialist that performs the requested work, where Captain shall decide only from the supplied Boss text and catalog without investigating the task, inspecting the workspace, using tools, or relying on ambient project evidence, where Captain shall keep a finite ordered plan and issue at most one child call at a time, where `remainingPlan` shall contain only calls after the selected next call and every continuation shall strictly reduce its length, where after Captain consumes an answer to its own routing question that question and answer are no longer pending before Captain calls a child or completes, where the host guarantees that this Captain receives Boss input only while it is the active leaf and resumes only from a matching child return, and where Boss's answer to a routing question resumes this same routing decision with continuation context without creating a separate Captain behavior, when Boss gives a new intent while Captain is the active playbook, Boss answers Captain's routing question, or a fresh directive interrupts any parked Captain work and restarts this routing behavior with that fresh intent without retaining the prior question, answer, plan, call history, evidence, selection, response, or error, Captain shall ask Boss one material routing question or select the first call in a one- or multi-playbook plan:
9
+
10
+ > Boss intent: <boss-intent>
11
+ > Enabled playbooks: <enabled-playbooks>
12
+ > You are routing this intent, not performing the requested work.
13
+ > Use only the Boss intent and enabled-playbooks catalog supplied here.
14
+ > Do not investigate the task, inspect files or project state, use tools, or attempt the specialized work yourself.
15
+ > Preserve Boss's intended outcome and constraints.
16
+ > If the supplied evidence identifies a useful route, select an enabled playbook; do not finish the intent yourself.
17
+ > Ask exactly one concise question only when its answer is necessary to choose a useful route or call order.
18
+ > For a complex intent, divide it into the smallest finite ordered plan of useful playbook calls.
19
+ > Name the selected first playbook and state its complete standalone request containing only the context it needs.
20
+ > List any later playbook calls in their intended order after the selected first call.
21
+ > Do not call a playbook merely to restate or classify the intent.
22
+ > Write only concise human-facing routing prose or the one routing question.
23
+ > Do not emit JSON, guard names, result property names, or control instructions.
24
+ > Do not expose internal state ids, session ids, call ids, stack data, hidden control data, or private reasoning.
25
+
26
+ Results:
27
+ - `question`: Captain asked the one material routing question. Output shall include `question: <verbatim final text from the visible Captain call>`.
28
+ - `delegation`: Captain selected the first useful call. Output shall include `remainingPlan: <finite JSON-safe array of only later calls>`, `nextPlaybookId: <selected stable enabled-playbook id>`, and `nextPlaybookInput: <complete standalone request>`.
29
+
30
+ ### CAPTAIN-2
31
+
32
+ Where `nextPlaybookId` is non-empty, selects a playbook id from the immutable enabled-playbooks catalog whose entries contain only a stable playbook id, its command, and its intent, does not select this Captain playbook itself, and the exact pair of stable target id and complete standalone input is recorded before invoking the child so an `ok`, `aborted`, or `error` return prevents the same later attempt, when Captain selects a next call, Captain shall call playbook selected by `nextPlaybookId`:
33
+
34
+ > <nextPlaybookInput>
35
+
36
+ ### CAPTAIN-3
37
+
38
+ Where Captain is the default generic Captain playbook with no players beyond Boss and Captain, where the enabled-playbooks catalog is immutable host input whose entries contain only a stable playbook id, its command, and its intent, where Captain shall call only ids in that catalog and shall never call this Captain playbook itself, where Captain is a router and not the specialist that performs the requested work, where Captain shall reassess only from the supplied Boss text, enabled-playbooks catalog, remaining plan, and completed call results without investigating the task, inspecting the workspace, using tools, or relying on ambient project evidence, where Captain shall issue at most one child call at a time, where each completed call result contains only the selected playbook id, its `ok`, `aborted`, or `error` status, and either the child's actual JSON-safe output or a compact error with only `name` and `message`, where completed call results never retain or expose a child session id, call id, child state, stack trace, or an opaque runtime result object, where for the machine's deterministic safety floor two calls are the same only when both the stable target id and complete standalone input match exactly, where the exact pair was recorded before invoking the child so an `ok`, `aborted`, or `error` return all prevent the same later attempt, where an input revised with new information is different for this exact check, where Captain still owns the broader semantic no-repeat instruction in the prompt, where after Captain consumes an answer to its own reassessment question that question and answer are no longer pending before Captain calls a child or completes, where Boss's answer to a reassessment question resumes this same reassessment with continuation context without creating a separate Captain behavior, and where a child abort or failure is a completed call result for reassessment and shall not route this playbook directly to its generic failure state, when the called playbook returns successfully, aborts, or fails, or Boss answers Captain's reassessment question, Captain shall reassess the original intent, remaining plan, and completed call results:
39
+
40
+ > Boss intent: <boss-intent>
41
+ > Enabled playbooks: <enabled-playbooks>
42
+ > Remaining plan: <remaining-plan>
43
+ > Completed call results: <completed-call-results>
44
+ > Preserve Boss's intended outcome and constraints.
45
+ > Treat each returned result as evidence and revise the remaining plan when needed.
46
+ > A continuing decision must strictly reduce the remaining plan length.
47
+ > Do not repeat an equivalent failed or completed call without new information.
48
+ > If the intent is fulfilled, give Boss one concise final response that states the result or actionable conclusion.
49
+ > Do not finish with a bare acknowledgement, a promise to act, or an announcement that the round is complete.
50
+ > If information from Boss is now necessary, ask exactly one concise question.
51
+ > Otherwise name exactly one next enabled playbook and state its complete standalone request containing only the context it needs.
52
+ > List any still-later playbook calls in their intended order after the selected next call.
53
+ > Write only concise human-facing final, question, or routing prose.
54
+ > Do not emit JSON, guard names, result property names, or control instructions.
55
+ > Do not expose internal state ids, session ids, call ids, stack data, hidden control data, or private reasoning.
56
+
57
+ Results:
58
+ - `final`: Captain gave Boss the concrete result or actionable conclusion. Output shall include `response: <verbatim final text from the visible Captain call>`.
59
+ - `followUpQuestion`: Captain asked one necessary follow-up question. Output shall include `question: <verbatim final text from the visible Captain call>`.
60
+ - `continuing`: Captain selected another useful call. Output shall include `remainingPlan: <strictly shorter finite JSON-safe array of only later calls>`, `nextPlaybookId: <selected stable enabled-playbook id>`, and `nextPlaybookInput: <complete standalone request>`.
@@ -0,0 +1,23 @@
1
+ import { type CaptainInput, type EnabledPlaybook } from './captain.fsm.js';
2
+ import type { PlaybookRuntime, PlaybookRuntimeFactory } from '../../../src/runtime.js';
3
+ export type { CaptainCallOptions, CaptainResult, JsonValue, NormalizedError, PlaybookCallRequest, PlaybookCallResult, PlaybookCallStart, PlaybookPorts, PlaybookRunResult, PlaybookRuntime, PlaybookRuntimeFactory, PlaybookSession, PlaybookState, PlaybookStateValue, PlaybookTraceEvent, PlayerCallOptions, PlayerResult, } from '../../../src/runtime.js';
4
+ export interface PlaybookRuntimeOptions {
5
+ readonly enabledPlaybooks: readonly EnabledPlaybook[];
6
+ }
7
+ export declare function composeCaptainPrompt(input: CaptainInput): string;
8
+ export declare function composePlayerPrompt(input: {
9
+ readonly prompt: string;
10
+ readonly pendingBossQuestion?: {
11
+ readonly question: string;
12
+ };
13
+ readonly bossReply?: string;
14
+ }): string;
15
+ declare function parseJsonObjectLoose(text: string): Record<string, unknown> | undefined;
16
+ export declare const _internal: {
17
+ composeCaptainPrompt: typeof composeCaptainPrompt;
18
+ composePlayerPrompt: typeof composePlayerPrompt;
19
+ parseJsonObjectLoose: typeof parseJsonObjectLoose;
20
+ };
21
+ export declare function createPlaybookRuntime(options: PlaybookRuntimeOptions): PlaybookRuntime;
22
+ declare const factory: PlaybookRuntimeFactory<PlaybookRuntimeOptions>;
23
+ export default factory;