@sublang/playbook 13.1.0 → 13.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 (43) hide show
  1. package/README.md +7 -5
  2. package/docs/cli.md +28 -9
  3. package/docs/configuration.md +27 -14
  4. package/docs/embedding.md +1 -1
  5. package/package.json +40 -2
  6. package/reference/sdlc/branch.md +37 -0
  7. package/reference/sdlc/branch.playbook/branch.fsm.d.ts +169 -0
  8. package/reference/sdlc/branch.playbook/branch.fsm.js +325 -0
  9. package/reference/sdlc/branch.playbook/branch.fsm.ts +458 -0
  10. package/reference/sdlc/branch.playbook/branch.gears.md +44 -0
  11. package/reference/sdlc/branch.playbook/branch.playbook.d.ts +20 -0
  12. package/reference/sdlc/branch.playbook/branch.playbook.js +121 -0
  13. package/reference/sdlc/branch.playbook/branch.playbook.ts +217 -0
  14. package/reference/sdlc/branch.playbook/branch.registry.d.ts +40 -0
  15. package/reference/sdlc/branch.playbook/branch.registry.js +63 -0
  16. package/reference/sdlc/branch.playbook/branch.registry.ts +121 -0
  17. package/reference/sdlc/code.playbook/bin/session-host.js +13 -3
  18. package/reference/sdlc/code.playbook/playbook-captain.d.ts +26 -1
  19. package/reference/sdlc/code.playbook/playbook-captain.js +218 -6
  20. package/reference/sdlc/code.playbook/playbook-captain.ts +281 -6
  21. package/reference/sdlc/code.playbook/playbook.config.template.yaml +21 -8
  22. package/reference/sdlc/code.playbook/session-host.d.ts +26 -0
  23. package/reference/sdlc/dev.md +24 -3
  24. package/reference/sdlc/dev.playbook/dev.fsm.d.ts +100 -9
  25. package/reference/sdlc/dev.playbook/dev.fsm.js +235 -18
  26. package/reference/sdlc/dev.playbook/dev.fsm.ts +368 -24
  27. package/reference/sdlc/dev.playbook/dev.gears.md +45 -7
  28. package/reference/sdlc/dev.playbook/dev.playbook.js +13 -1
  29. package/reference/sdlc/dev.playbook/dev.playbook.ts +13 -1
  30. package/reference/sdlc/dev.playbook/dev.registry.d.ts +1 -1
  31. package/reference/sdlc/dev.playbook/dev.registry.js +7 -2
  32. package/reference/sdlc/dev.playbook/dev.registry.ts +7 -2
  33. package/reference/sdlc/pr.md +108 -0
  34. package/reference/sdlc/pr.playbook/pr.fsm.d.ts +352 -0
  35. package/reference/sdlc/pr.playbook/pr.fsm.js +902 -0
  36. package/reference/sdlc/pr.playbook/pr.fsm.ts +1251 -0
  37. package/reference/sdlc/pr.playbook/pr.gears.md +155 -0
  38. package/reference/sdlc/pr.playbook/pr.playbook.d.ts +27 -0
  39. package/reference/sdlc/pr.playbook/pr.playbook.js +133 -0
  40. package/reference/sdlc/pr.playbook/pr.playbook.ts +235 -0
  41. package/reference/sdlc/pr.playbook/pr.registry.d.ts +40 -0
  42. package/reference/sdlc/pr.playbook/pr.registry.js +68 -0
  43. package/reference/sdlc/pr.playbook/pr.registry.ts +124 -0
@@ -77,6 +77,9 @@ function isCanonicalLocalRoleId(value) {
77
77
  }
78
78
  const UNRESOLVED_EFFECT_RECONCILIATION_ACTION_ID = 'reconcile:unresolved-effect';
79
79
  const UNRESOLVED_EFFECT_ABANDONMENT_ACTION_ID = 'abandon:unresolved-effect';
80
+ // CAPTAIN-62: the shell's own control, not a runtime action. The id is machine
81
+ // data the host echoes back; the Boss never sees it (CAPPLAY-5).
82
+ const GIVE_UP_ACTION_ID = 'give-up';
80
83
  // The fixed machine-syntax guard of a player's Boss-question suspension
81
84
  // (slc/link.md §Boss-reply suspension): the accepted outcome that parks on
82
85
  // Boss rather than sparing Boss a relay.
@@ -1732,6 +1735,12 @@ export function createPlaybookCaptainShell(options, deps = {}) {
1732
1735
  // CAPTAIN-40's corrective re-ask on the very call whose prose it surfaces —
1733
1736
  // the selection reaches the controller port after that call's frame is gone.
1734
1737
  let decisionCall;
1738
+ // CAPTAIN-7: the control the host selected for the turn it is about to
1739
+ // submit, held with the exact Boss text that turn carries so an unrelated
1740
+ // turn never consumes the selection. One turn consumes it, whichever it is,
1741
+ // and one slot holds it whichever surface it came from — the leaf's
1742
+ // advertised actions or the shell's own controls (CAPTAIN-62).
1743
+ let pendingHostSelection;
1735
1744
  let lastAction;
1736
1745
  let lastSettlementStatus;
1737
1746
  const retainedGenerationCandidates = new Map();
@@ -3889,6 +3898,118 @@ export function createPlaybookCaptainShell(options, deps = {}) {
3889
3898
  lines.push(retainedResumptionDigest());
3890
3899
  return lines.join('\n');
3891
3900
  };
3901
+ // CAPTAIN-60: the same reading the ControlView digest performs, published as
3902
+ // data instead of prose. It states what the digest states and withholds what
3903
+ // the digest withholds: an idle shell, a leaf with no control surface, and a
3904
+ // control view that cannot be read all advertise nothing, and a leaf fenced
3905
+ // for repository-effect reconciliation advertises only its fence controls.
3906
+ // The pairs are detached and frozen, so a host holds the shell's reading
3907
+ // rather than a live view the runtime can rewrite underneath it.
3908
+ const advertisedRuntimeActions = () => {
3909
+ const empty = Object.freeze([]);
3910
+ if (lifecycle !== 'ready' || terminallyDisposed)
3911
+ return empty;
3912
+ // Between turns: while a turn is running, the leaf's control view is the
3913
+ // decision's grounding and the host can act on no selection, so the shell
3914
+ // publishes none and reads nothing from a runtime mid-run.
3915
+ if (activeTurn !== undefined || activeTurnHostCalls !== undefined) {
3916
+ return empty;
3917
+ }
3918
+ const leaf = leafFrame();
3919
+ if (!leaf || typeof leaf.runtime.describe !== 'function')
3920
+ return empty;
3921
+ refreshRetainedEffectFence();
3922
+ const fenced = retainedEffectReconciliation !== undefined;
3923
+ if (fenced && typeof leaf.runtime.apply !== 'function')
3924
+ return empty;
3925
+ let actions;
3926
+ try {
3927
+ actions = leaf.runtime.describe().actions;
3928
+ }
3929
+ catch {
3930
+ // An unreadable control view advertises nothing.
3931
+ return empty;
3932
+ }
3933
+ return Object.freeze(actions
3934
+ .filter((action) => !fenced ||
3935
+ action.id === UNRESOLVED_EFFECT_RECONCILIATION_ACTION_ID ||
3936
+ action.id === UNRESOLVED_EFFECT_ABANDONMENT_ACTION_ID)
3937
+ .map((action) => Object.freeze({ id: action.id, label: action.label })));
3938
+ };
3939
+ // CAPTAIN-62: the controls the shell effects itself, published beside the
3940
+ // leaf's advertised actions and never mixed with them — these are the
3941
+ // shell's own, so an engaged root offers one whatever its leaf advertises,
3942
+ // fenced or not. A fenced root keeps its control because giving up reports
3943
+ // unresolved effects (CAPTAIN-58) rather than reconciling them, and a run
3944
+ // whose effects are unknown is exactly the run a Boss gives up on.
3945
+ const advertisedShellActions = () => {
3946
+ const empty = Object.freeze([]);
3947
+ if (lifecycle !== 'ready' || terminallyDisposed)
3948
+ return empty;
3949
+ // Between turns, on the same rule the leaf's actions take: mid-turn the
3950
+ // host can act on no selection.
3951
+ if (activeTurn !== undefined || activeTurnHostCalls !== undefined) {
3952
+ return empty;
3953
+ }
3954
+ const root = rootFrame();
3955
+ if (!root)
3956
+ return empty;
3957
+ return Object.freeze([
3958
+ Object.freeze({
3959
+ id: GIVE_UP_ACTION_ID,
3960
+ // The label is the turn's durable Boss text, so it names the run the
3961
+ // way the Boss started it rather than the frame that happens to be
3962
+ // parked inside it.
3963
+ label: `Stop ${frameLabel(root)}`,
3964
+ }),
3965
+ ]);
3966
+ };
3967
+ // CAPTAIN-7: the host's selection of the shell's own control, validated here
3968
+ // against the same live reading. The returned text is the turn the host
3969
+ // submits, exactly as for an advertised runtime action.
3970
+ const selectShellAction = (actionId) => {
3971
+ if (lifecycle !== 'ready' || terminallyDisposed) {
3972
+ throw new Error('a shell control requires an initialized or restored Captain shell');
3973
+ }
3974
+ if (activeTurn !== undefined || activeTurnHostCalls !== undefined) {
3975
+ throw new Error('a shell control cannot be selected during a Boss turn');
3976
+ }
3977
+ if (typeof actionId !== 'string' || actionId.length === 0) {
3978
+ throw new TypeError('a shell control id must be a nonempty string');
3979
+ }
3980
+ const advertised = advertisedShellActions().find((action) => action.id === actionId);
3981
+ if (advertised === undefined) {
3982
+ throw new Error('the shell does not advertise that control');
3983
+ }
3984
+ pendingHostSelection = { kind: 'give-up', text: advertised.label };
3985
+ return advertised.label;
3986
+ };
3987
+ // CAPTAIN-7: the host's own selection of one advertised action, validated
3988
+ // here against the same live reading and validated again at the controller
3989
+ // port before any effect. The returned text is the turn the host submits.
3990
+ const selectRuntimeAction = (actionId) => {
3991
+ if (lifecycle !== 'ready' || terminallyDisposed) {
3992
+ throw new Error('a runtime action requires an initialized or restored Captain shell');
3993
+ }
3994
+ if (activeTurn !== undefined || activeTurnHostCalls !== undefined) {
3995
+ throw new Error('a runtime action cannot be selected during a Boss turn');
3996
+ }
3997
+ if (typeof actionId !== 'string' || actionId.length === 0) {
3998
+ throw new TypeError('a runtime action id must be a nonempty string');
3999
+ }
4000
+ const advertised = advertisedRuntimeActions().find((action) => action.id === actionId);
4001
+ if (advertised === undefined) {
4002
+ // CAPPLAY-5: the chosen id is control data whether or not the leaf
4003
+ // advertises it, so the refusal names the fact and not the string.
4004
+ throw new Error('the active leaf does not advertise that action');
4005
+ }
4006
+ const text = typeof advertised.label === 'string' ? advertised.label.trim() : '';
4007
+ if (text.length === 0) {
4008
+ throw new Error('the advertised action carries no Boss-facing label to submit as its turn');
4009
+ }
4010
+ pendingHostSelection = { kind: 'runtime', actionId, text };
4011
+ return text;
4012
+ };
3892
4013
  // The catalog is registry-authored, not shell-authored: an id, a command,
3893
4014
  // and an intent all arrive from an enabled module. They pass the same seam
3894
4015
  // the ControlView lines do, so an intent carrying a newline cannot open a
@@ -4341,6 +4462,42 @@ export function createPlaybookCaptainShell(options, deps = {}) {
4341
4462
  ? []
4342
4463
  : [labeledBlock('Conversation recap', options.reseedDigest)]),
4343
4464
  ]);
4465
+ // CAPTAIN-7: a turn whose decision the host already made allocates no
4466
+ // decision call. The host's selection is this state's decision reply, so
4467
+ // it passes the runtime's own reply validation and reaches the shell
4468
+ // through the controller port like every other selection — validation,
4469
+ // execution, the outcome report, and the closing reply are the loop's.
4470
+ if (kind === 'decision' && turn?.hostRuntimeActionId !== undefined) {
4471
+ return {
4472
+ status: 'ok',
4473
+ finalText: JSON.stringify({
4474
+ action: 'runtime',
4475
+ actionId: turn.hostRuntimeActionId,
4476
+ }),
4477
+ };
4478
+ }
4479
+ // CAPTAIN-63: a give-up allocates neither call. Its decision is the
4480
+ // host's, and its result phase is answered below from the settlement the
4481
+ // shell already holds, so an exit from a failing provider does not ask
4482
+ // that provider for permission.
4483
+ if (kind === 'decision' && turn?.hostGiveUp === true) {
4484
+ return {
4485
+ status: 'ok',
4486
+ finalText: JSON.stringify({ action: 'dismiss' }),
4487
+ };
4488
+ }
4489
+ if (kind === 'closingReply' && turn?.hostGiveUp === true) {
4490
+ // The durable conversation did not receive this turn, so it is marked
4491
+ // for the CAPTAIN-35 catch-up rather than left believing it is
4492
+ // current: the next call carries the journal records it missed.
4493
+ markConversationCatchUp();
4494
+ // Through the one presentation seam, exactly where a model-composed
4495
+ // reply is presented, so this reply is journaled and single-attempt
4496
+ // like every other. It needs no reply validation or corrective re-ask:
4497
+ // `giveUpReplyText` already validated what it composed.
4498
+ await surfaceSettlement({ context, text: giveUpReplyText() });
4499
+ return { status: 'ok', finalText: 'ok' };
4500
+ }
4344
4501
  const outcome = await durableCall(context, compose);
4345
4502
  if (kind === 'decision') {
4346
4503
  // A model-decided `respond` surfaces this call's own prose, so the
@@ -4537,8 +4694,18 @@ export function createPlaybookCaptainShell(options, deps = {}) {
4537
4694
  return false;
4538
4695
  const label = frameLabel(root);
4539
4696
  // Dismissal leaves the procedure unfinished. Persist the latest safe
4540
- // generation captured for this turn before disposal erases the frames.
4541
- retainOrClearDisposedRoot(root);
4697
+ // generation captured for this turn before disposal erases the frames —
4698
+ // unless the Boss gave up on it (CAPTAIN-44), in which case retaining it
4699
+ // would offer the abandoned run back on the idle digest's next reading.
4700
+ if (activeTurn?.hostGiveUp === true) {
4701
+ pendingRetentionUpdates.set(root.entry.id, {
4702
+ kind: 'clear',
4703
+ rootPlaybookId: root.entry.id,
4704
+ });
4705
+ }
4706
+ else {
4707
+ retainOrClearDisposedRoot(root);
4708
+ }
4542
4709
  try {
4543
4710
  await runEffect(() => disposeStack('dismiss'));
4544
4711
  facts.push(`Dismissed the ${label} engagement.`);
@@ -4994,10 +5161,16 @@ export function createPlaybookCaptainShell(options, deps = {}) {
4994
5161
  if (!leaf) {
4995
5162
  return rejectSelection(selection, 'no engagement is active to dismiss');
4996
5163
  }
5164
+ // CAPTAIN-63: a give-up ends the run. An ordinary dismissal of a nested
5165
+ // call returns to its caller, which is the right reading of "stop this
5166
+ // call" and the wrong one of "stop this workflow" — the Boss gave up on
5167
+ // the root, not on whichever child was parked when they did.
5168
+ const giveUp = turn.hostGiveUp === true;
5169
+ const dismissed = giveUp ? (rootFrame() ?? leaf) : leaf;
4997
5170
  turn.settled = true;
4998
- journalAction({ action: 'dismiss', playbookId: leaf.entry.id });
4999
- const label = frameLabel(leaf);
5000
- if (leaf.parent) {
5171
+ journalAction({ action: 'dismiss', playbookId: dismissed.entry.id });
5172
+ const label = frameLabel(dismissed);
5173
+ if (leaf.parent && !giveUp) {
5001
5174
  // No boundary around the return itself: `resumeParent` disposes the
5002
5175
  // child and drives the parent, and each of those is marked where it
5003
5176
  // happens. A visibility rejection raised on the way back is shell
@@ -5291,6 +5464,28 @@ export function createPlaybookCaptainShell(options, deps = {}) {
5291
5464
  // The reply composes from the authoritative report, never the early
5292
5465
  // `settled` guard. That guard closes duplicate submissions before an effect
5293
5466
  // starts; it is not evidence that anything ran.
5467
+ // CAPTAIN-63: the give-up's closing reply, composed from the same settlement
5468
+ // facts the result-phase prompt would have carried. Shell-authored Boss
5469
+ // prose passes the validation every model reply passes (CAPTAIN-34); what it
5470
+ // interpolates is not host-authored all the way down, so a fact set that
5471
+ // fails validation is dropped rather than spoken and the reply still states
5472
+ // the settlement truthfully.
5473
+ const giveUpReplyText = () => {
5474
+ const report = activeTurn?.report;
5475
+ const facts = report?.bossFacts ?? report?.facts ?? [];
5476
+ const opening = 'Stopped that workflow. I will not resume it.';
5477
+ const closing = 'Send the command again to start fresh work.';
5478
+ const composed = [
5479
+ opening,
5480
+ ...(facts.length === 0
5481
+ ? []
5482
+ : ['Here is what happened:', ...facts.map((fact) => `- ${fact}`)]),
5483
+ closing,
5484
+ ].join('\n');
5485
+ return replyRejection(composed) === undefined
5486
+ ? composed
5487
+ : [opening, closing].join('\n');
5488
+ };
5294
5489
  const failureReplyText = () => {
5295
5490
  const commands = [...enablementById.values()]
5296
5491
  .map((enablement) => `/${enablement.command} <task>`)
@@ -6151,6 +6346,10 @@ export function createPlaybookCaptainShell(options, deps = {}) {
6151
6346
  exportSettlement,
6152
6347
  restore: restoreShellSnapshot,
6153
6348
  installRetainedGenerations,
6349
+ describeRuntimeActions: advertisedRuntimeActions,
6350
+ submitRuntimeAction: selectRuntimeAction,
6351
+ describeShellActions: advertisedShellActions,
6352
+ submitShellAction: selectShellAction,
6154
6353
  async handleBossTurn(turn, context) {
6155
6354
  if (lifecycle !== 'ready' || terminallyDisposed) {
6156
6355
  throw new Error('init must be called first, or restore must complete before handling a Boss turn');
@@ -6184,13 +6383,25 @@ export function createPlaybookCaptainShell(options, deps = {}) {
6184
6383
  const turnHostCalls = new Set();
6185
6384
  activeTurnHostCalls = turnHostCalls;
6186
6385
  activeContext = context;
6187
- const parsed = resolveCommandTurn(turn.prompt);
6386
+ // CAPTAIN-7: one host selection is consumed by one turn. It decides only
6387
+ // the turn carrying the exact text the selection was made for; any other
6388
+ // turn drops it and resolves normally.
6389
+ const selected = pendingHostSelection;
6390
+ pendingHostSelection = undefined;
6391
+ const decided = selected !== undefined && selected.text === turn.prompt
6392
+ ? selected
6393
+ : undefined;
6394
+ const hostRuntimeActionId = decided?.kind === 'runtime' ? decided.actionId : undefined;
6395
+ const hostGiveUp = decided?.kind === 'give-up' ? true : undefined;
6396
+ const parsed = decided === undefined ? resolveCommandTurn(turn.prompt) : undefined;
6188
6397
  activeTurn = {
6189
6398
  id: ++turnSequence,
6190
6399
  captainSyncedJournalSeq: journalSeq,
6191
6400
  bossText: turn.prompt,
6192
6401
  authoritativeText: parsed?.authoritativeText ?? turn.prompt,
6193
6402
  ...(parsed ? { resolution: parsed.resolution } : {}),
6403
+ ...(hostRuntimeActionId === undefined ? {} : { hostRuntimeActionId }),
6404
+ ...(hostGiveUp === undefined ? {} : { hostGiveUp }),
6194
6405
  settled: false,
6195
6406
  presentationAttempted: false,
6196
6407
  settlementFacts: [],
@@ -6324,6 +6535,7 @@ export function createPlaybookCaptainShell(options, deps = {}) {
6324
6535
  failure ??= error;
6325
6536
  }
6326
6537
  }
6538
+ pendingHostSelection = undefined;
6327
6539
  // Quarantine is session-wide by design. Only terminal teardown may drop
6328
6540
  // its ownership after every frame host call and the Captain are drained.
6329
6541
  playerTransactions.clear();