@sublang/playbook 13.0.0 → 13.1.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 (37) hide show
  1. package/package.json +2 -2
  2. package/reference/sdlc/code.md +7 -0
  3. package/reference/sdlc/code.playbook/code.fsm.js +5 -5
  4. package/reference/sdlc/code.playbook/code.fsm.ts +5 -5
  5. package/reference/sdlc/code.playbook/code.gears.md +5 -5
  6. package/reference/sdlc/code.playbook/code.playbook.d.ts +1 -1
  7. package/reference/sdlc/code.playbook/code.playbook.js +6 -16
  8. package/reference/sdlc/code.playbook/code.playbook.ts +7 -17
  9. package/reference/sdlc/code.playbook/playbook-captain.js +4 -1
  10. package/reference/sdlc/code.playbook/playbook-captain.ts +4 -1
  11. package/reference/sdlc/decide.md +2 -0
  12. package/reference/sdlc/decide.playbook/decide.fsm.js +1 -1
  13. package/reference/sdlc/decide.playbook/decide.fsm.ts +1 -1
  14. package/reference/sdlc/decide.playbook/decide.gears.md +2 -2
  15. package/reference/sdlc/decide.playbook/decide.playbook.d.ts +1 -2
  16. package/reference/sdlc/decide.playbook/decide.playbook.js +8 -22
  17. package/reference/sdlc/decide.playbook/decide.playbook.ts +8 -25
  18. package/reference/sdlc/dev.md +21 -1
  19. package/reference/sdlc/dev.playbook/dev.fsm.js +10 -10
  20. package/reference/sdlc/dev.playbook/dev.fsm.ts +13 -13
  21. package/reference/sdlc/dev.playbook/dev.gears.md +15 -15
  22. package/reference/sdlc/dev.playbook/dev.playbook.d.ts +1 -1
  23. package/reference/sdlc/dev.playbook/dev.playbook.js +7 -17
  24. package/reference/sdlc/dev.playbook/dev.playbook.ts +8 -20
  25. package/reference/sdlc/review.md +18 -0
  26. package/reference/sdlc/review.playbook/review.fsm.js +8 -8
  27. package/reference/sdlc/review.playbook/review.fsm.ts +8 -8
  28. package/reference/sdlc/review.playbook/review.gears.md +8 -8
  29. package/reference/sdlc/review.playbook/review.playbook.d.ts +1 -1
  30. package/reference/sdlc/review.playbook/review.playbook.js +5 -15
  31. package/reference/sdlc/review.playbook/review.playbook.ts +6 -16
  32. package/slc/link.md +12 -24
  33. package/src/runtime.d.ts +2 -0
  34. package/src/runtime.ts +2 -0
  35. package/src/xstate-playbook-runtime.d.ts +4 -2
  36. package/src/xstate-playbook-runtime.js +18 -13
  37. package/src/xstate-playbook-runtime.ts +26 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sublang/playbook",
3
- "version": "13.0.0",
3
+ "version": "13.1.0",
4
4
  "type": "module",
5
5
  "description": "Composable XState v5 playbook runtime with compiled Captain, CODE, REVIEW, DECIDE, and DEV workflows driven by GEARS specs.",
6
6
  "license": "Apache-2.0",
@@ -198,7 +198,7 @@
198
198
  "provenance": true
199
199
  },
200
200
  "dependencies": {
201
- "@sublang/cligent": "^0.25.0",
201
+ "@sublang/cligent": "^0.26.0",
202
202
  "@sublang/spex": "^3.0.0",
203
203
  "p-queue": "^9.3.1",
204
204
  "xstate": "^5.19.4",
@@ -25,6 +25,9 @@ When the nested `review` call fails outside that authored result contract, `code
25
25
 
26
26
  At the start of the first phase, Captain shall relay to Coder the complete caller input and any relevant run results in quotes (`>`), along with the following instruction:
27
27
 
28
+ > Original request: <caller-input>
29
+ > Run results: <run-results>
30
+
28
31
  ```markdown
29
32
  First determine whether the coding request starts a new coding intent or continues an existing IR with unfinished work.
30
33
  If the request may continue an existing IR but does not identify it unambiguously, ask Boss before changing files.
@@ -44,6 +47,10 @@ Consult @specs/map.md for relevant context and @specs/meta.md for spec requireme
44
47
 
45
48
  At the start of every later IR-task phase, Captain shall relay to Coder the original caller input, the IR identity, and any relevant run results in quotes (`>`), along with the following instruction:
46
49
 
50
+ > Original request: <caller-input>
51
+ > IR number: <ir-number>
52
+ > Run results: <run-results>
53
+
47
54
  ```markdown
48
55
  Read the identified IR and implement exactly its next unfinished task, including corresponding tests or specs if any.
49
56
  Do not implement a later task in this phase.
@@ -12,8 +12,8 @@ const APPENDED_PHASE_PROMPT = [
12
12
  'Coder is <coder-llm>.',
13
13
  ];
14
14
  const FIRST_PHASE_PROMPT = [
15
- '> <caller-input>',
16
- '> <run-results>',
15
+ '> Original request: <caller-input>',
16
+ '> Run results: <run-results>',
17
17
  '',
18
18
  'First determine whether the coding request starts a new coding intent or continues an existing IR with unfinished work.',
19
19
  'If the request may continue an existing IR but does not identify it unambiguously, ask Boss before changing files.',
@@ -33,9 +33,9 @@ const FIRST_PHASE_PROMPT = [
33
33
  ...APPENDED_PHASE_PROMPT,
34
34
  ].join('\n');
35
35
  const IR_TASK_PROMPT = [
36
- '> <caller-input>',
37
- '> <ir-number>',
38
- '> <run-results>',
36
+ '> Original request: <caller-input>',
37
+ '> IR number: <ir-number>',
38
+ '> Run results: <run-results>',
39
39
  '',
40
40
  'Read the identified IR and implement exactly its next unfinished task, including corresponding tests or specs if any.',
41
41
  'Do not implement a later task in this phase.',
@@ -156,8 +156,8 @@ const APPENDED_PHASE_PROMPT = [
156
156
  ];
157
157
 
158
158
  const FIRST_PHASE_PROMPT = [
159
- '> <caller-input>',
160
- '> <run-results>',
159
+ '> Original request: <caller-input>',
160
+ '> Run results: <run-results>',
161
161
  '',
162
162
  'First determine whether the coding request starts a new coding intent or continues an existing IR with unfinished work.',
163
163
  'If the request may continue an existing IR but does not identify it unambiguously, ask Boss before changing files.',
@@ -178,9 +178,9 @@ const FIRST_PHASE_PROMPT = [
178
178
  ].join('\n');
179
179
 
180
180
  const IR_TASK_PROMPT = [
181
- '> <caller-input>',
182
- '> <ir-number>',
183
- '> <run-results>',
181
+ '> Original request: <caller-input>',
182
+ '> IR number: <ir-number>',
183
+ '> Run results: <run-results>',
184
184
  '',
185
185
  'Read the identified IR and implement exactly its next unfinished task, including corresponding tests or specs if any.',
186
186
  'Do not implement a later task in this phase.',
@@ -13,8 +13,8 @@ Roles:
13
13
 
14
14
  When the first coding phase begins, Captain shall prompt Coder:
15
15
 
16
- > > <caller-input>
17
- > > <run-results>
16
+ > > Original request: <caller-input>
17
+ > > Run results: <run-results>
18
18
  >
19
19
  > First determine whether the coding request starts a new coding intent or continues an existing IR with unfinished work.
20
20
  > If the request may continue an existing IR but does not identify it unambiguously, ask Boss before changing files.
@@ -63,9 +63,9 @@ Workflow outcomes:
63
63
 
64
64
  When a later IR-task phase begins, Captain shall prompt Coder:
65
65
 
66
- > > <caller-input>
67
- > > <ir-number>
68
- > > <run-results>
66
+ > > Original request: <caller-input>
67
+ > > IR number: <ir-number>
68
+ > > Run results: <run-results>
69
69
  >
70
70
  > Read the identified IR and implement exactly its next unfinished task, including corresponding tests or specs if any.
71
71
  > Do not implement a later task in this phase.
@@ -10,7 +10,7 @@ export type CodePlaybookHostCapabilities = PlaybookHostConstructionCapabilities
10
10
  * runtime text. The generic composer preserves the marker itself; CODE's
11
11
  * override additionally keeps a multiline value inside that quote.
12
12
  */
13
- declare function composePlayerPrompt(input: PlayerInput, promptIdentity: XStatePromptIdentity): string;
13
+ declare function composePlayerPrompt(input: PlayerInput, promptIdentity: XStatePromptIdentity, resuming?: boolean): string;
14
14
  export declare const _internal: {
15
15
  composePlayerPrompt: typeof composePlayerPrompt;
16
16
  VERBATIM_PAYLOAD_FIELDS: ReadonlySet<string>;
@@ -10,11 +10,10 @@
10
10
  // the first phase decides among four semantic outcomes
11
11
  // Nested call: literal review target through the shared bridge
12
12
  // Compat: artifact schema 3 / runtime ABI 1
13
- import { createXStatePlaybookRuntime, snapshotJsonValue, } from '@sublang/playbook/xstate-runtime';
13
+ import { createXStatePlaybookRuntime, composePlayerContinuation, snapshotJsonValue, } from '@sublang/playbook/xstate-runtime';
14
14
  import { codingMachine, } from './code.fsm.js';
15
15
  const OPTION_KEYS = new Set(['runResults']);
16
16
  const PLACEHOLDER = /<(#|[A-Za-z_$][A-Za-z0-9_$-]*)>/g;
17
- const CONTINUATION_PREAMBLE = 'You previously paused this task to ask Boss a question; Boss has now replied. Continue the same task using the reply below.';
18
17
  const VERBATIM_PAYLOAD_FIELDS = new Set([
19
18
  'coderOutput',
20
19
  ]);
@@ -52,11 +51,11 @@ function quoteContinuation(value) {
52
51
  * runtime text. The generic composer preserves the marker itself; CODE's
53
52
  * override additionally keeps a multiline value inside that quote.
54
53
  */
55
- function composePlayerPrompt(input, promptIdentity) {
54
+ function composePlayerPrompt(input, promptIdentity, resuming = false) {
56
55
  const fields = input;
57
56
  const template = input.prompt
58
57
  .split('\n')
59
- .filter((line) => !(line === '> <run-results>' && input.runResults.length === 0))
58
+ .filter((line) => !(line === '> Run results: <run-results>' && input.runResults.length === 0))
60
59
  .join('\n');
61
60
  const body = template.replace(PLACEHOLDER, (match, token, offset, source) => {
62
61
  const value = token === 'coder-llm'
@@ -66,18 +65,9 @@ function composePlayerPrompt(input, promptIdentity) {
66
65
  return match;
67
66
  const lineStart = source.lastIndexOf('\n', offset - 1) + 1;
68
67
  const literal = source.slice(lineStart, offset);
69
- return literal === '> ' ? quoteContinuation(value) : value;
68
+ return literal.startsWith('> ') ? quoteContinuation(value) : value;
70
69
  });
71
- if (input.pendingBossQuestion === undefined ||
72
- input.bossReply === undefined) {
73
- return body;
74
- }
75
- return [
76
- CONTINUATION_PREAMBLE,
77
- `Boss question:\n${input.pendingBossQuestion.question}`,
78
- `Boss reply:\n${input.bossReply}`,
79
- body,
80
- ].join('\n\n');
70
+ return composePlayerContinuation(input, body, resuming);
81
71
  }
82
72
  export const _internal = {
83
73
  composePlayerPrompt,
@@ -177,7 +167,7 @@ const runtimeSpec = {
177
167
  },
178
168
  },
179
169
  },
180
- composePlayerPrompt: (input, promptIdentity) => composePlayerPrompt(input, promptIdentity),
170
+ composePlayerPrompt: (input, promptIdentity, resuming) => composePlayerPrompt(input, promptIdentity, resuming),
181
171
  verbatimPayloadFields: VERBATIM_PAYLOAD_FIELDS,
182
172
  controlContextFields: ['phase'],
183
173
  unfinishedFinalStateIds: UNFINISHED_FINAL_STATE_IDS,
@@ -13,6 +13,7 @@
13
13
 
14
14
  import {
15
15
  createXStatePlaybookRuntime,
16
+ composePlayerContinuation,
16
17
  snapshotJsonValue,
17
18
  type PlaybookPlayerInput,
18
19
  type XStatePlaybookRuntimeFactory,
@@ -85,8 +86,6 @@ export type CodePlaybookHostCapabilities =
85
86
 
86
87
  const OPTION_KEYS = new Set(['runResults']);
87
88
  const PLACEHOLDER = /<(#|[A-Za-z_$][A-Za-z0-9_$-]*)>/g;
88
- const CONTINUATION_PREAMBLE =
89
- 'You previously paused this task to ask Boss a question; Boss has now replied. Continue the same task using the reply below.';
90
89
 
91
90
  const VERBATIM_PAYLOAD_FIELDS: ReadonlySet<string> = new Set([
92
91
  'coderOutput',
@@ -135,12 +134,13 @@ function quoteContinuation(value: string): string {
135
134
  function composePlayerPrompt(
136
135
  input: PlayerInput,
137
136
  promptIdentity: XStatePromptIdentity,
137
+ resuming = false,
138
138
  ): string {
139
139
  const fields = input as unknown as Record<string, unknown>;
140
140
  const template = input.prompt
141
141
  .split('\n')
142
142
  .filter(
143
- (line) => !(line === '> <run-results>' && input.runResults.length === 0),
143
+ (line) => !(line === '> Run results: <run-results>' && input.runResults.length === 0),
144
144
  )
145
145
  .join('\n');
146
146
  const body = template.replace(
@@ -153,21 +153,10 @@ function composePlayerPrompt(
153
153
  if (typeof value !== 'string') return match;
154
154
  const lineStart = source.lastIndexOf('\n', offset - 1) + 1;
155
155
  const literal = source.slice(lineStart, offset);
156
- return literal === '> ' ? quoteContinuation(value) : value;
156
+ return literal.startsWith('> ') ? quoteContinuation(value) : value;
157
157
  },
158
158
  );
159
- if (
160
- input.pendingBossQuestion === undefined ||
161
- input.bossReply === undefined
162
- ) {
163
- return body;
164
- }
165
- return [
166
- CONTINUATION_PREAMBLE,
167
- `Boss question:\n${input.pendingBossQuestion.question}`,
168
- `Boss reply:\n${input.bossReply}`,
169
- body,
170
- ].join('\n\n');
159
+ return composePlayerContinuation(input, body, resuming);
171
160
  }
172
161
 
173
162
  export const _internal = {
@@ -273,7 +262,8 @@ const runtimeSpec = {
273
262
  composePlayerPrompt: (
274
263
  input: PlaybookPlayerInput,
275
264
  promptIdentity: XStatePromptIdentity,
276
- ) => composePlayerPrompt(input as PlayerInput, promptIdentity),
265
+ resuming?: boolean,
266
+ ) => composePlayerPrompt(input as PlayerInput, promptIdentity, resuming),
277
267
  verbatimPayloadFields: VERBATIM_PAYLOAD_FIELDS,
278
268
  controlContextFields: ['phase'],
279
269
  unfinishedFinalStateIds: UNFINISHED_FINAL_STATE_IDS,
@@ -2599,6 +2599,9 @@ export function createPlaybookCaptainShell(options, deps = {}) {
2599
2599
  if (!ledger) {
2600
2600
  throw new Error(`${frameLabel(frame)} resolved absent session player ${JSON.stringify(binding.playerId)}`);
2601
2601
  }
2602
+ if (options.freshPrompt !== undefined && typeof options.freshPrompt !== 'string') {
2603
+ throw new TypeError('player freshPrompt must be a string');
2604
+ }
2602
2605
  const expectedResume = ledger.resumeToken ?? false;
2603
2606
  if (options.resume !== expectedResume) {
2604
2607
  throw new Error(`${frameLabel(frame)} player continuation changed before dispatch`);
@@ -2625,7 +2628,7 @@ export function createPlaybookCaptainShell(options, deps = {}) {
2625
2628
  const call = async (resume) => {
2626
2629
  await continuity?.beforeCall(binding.playerId);
2627
2630
  signal.throwIfAborted();
2628
- const raw = await trackHostCall(frame, classifySettingsCall(() => context.callPlayer(binding.playerId, prompt, { resume, settings })));
2631
+ const raw = await trackHostCall(frame, classifySettingsCall(() => context.callPlayer(binding.playerId, resume === false ? options.freshPrompt ?? prompt : prompt, { resume, settings })));
2629
2632
  hostResolved = true;
2630
2633
  return raw;
2631
2634
  };
@@ -4361,6 +4361,9 @@ export function createPlaybookCaptainShell(
4361
4361
  `${frameLabel(frame)} resolved absent session player ${JSON.stringify(binding.playerId)}`,
4362
4362
  );
4363
4363
  }
4364
+ if (options.freshPrompt !== undefined && typeof options.freshPrompt !== 'string') {
4365
+ throw new TypeError('player freshPrompt must be a string');
4366
+ }
4364
4367
  const expectedResume = ledger.resumeToken ?? false;
4365
4368
  if (options.resume !== expectedResume) {
4366
4369
  throw new Error(
@@ -4394,7 +4397,7 @@ export function createPlaybookCaptainShell(
4394
4397
  const raw = await trackHostCall(
4395
4398
  frame,
4396
4399
  classifySettingsCall(() =>
4397
- context.callPlayer(binding.playerId, prompt, { resume, settings }),
4400
+ context.callPlayer(binding.playerId, resume === false ? options.freshPrompt ?? prompt : prompt, { resume, settings }),
4398
4401
  ),
4399
4402
  );
4400
4403
  hostResolved = true;
@@ -15,6 +15,8 @@ When the caller gives a topic, Captain shall relay the complete topic in quotes
15
15
  Captain shall not wait for either proposal before requesting the other.
16
16
  Captain shall give the player bound to each role the following instruction:
17
17
 
18
+ > Original topic: <caller-topic>
19
+
18
20
  ```markdown
19
21
  Assess whether the topic is better expressed as a few spec items under @specs/packages/ or requires one or more DRs under @specs/decisions/.
20
22
  Propose your design.
@@ -7,7 +7,7 @@ import { assign, fromPromise, setup } from 'xstate';
7
7
  export const concurrentRoleSets = [['coder', 'reviewer']];
8
8
  const NEEDS_BOSS_REPLY_DESCRIPTION = "The acting agent's prose surfaces a clarifying question for Boss that the agent cannot answer alone. Output shall include `question: <verbatim question text from the acting agent's prose>`.";
9
9
  const INDEPENDENT_PROPOSAL_PROMPT = [
10
- '> <caller-topic>',
10
+ '> Original topic: <caller-topic>',
11
11
  '',
12
12
  'Assess whether the topic is better expressed as a few spec items under @specs/packages/ or requires one or more DRs under @specs/decisions/.',
13
13
  'Propose your design.',
@@ -148,7 +148,7 @@ const NEEDS_BOSS_REPLY_DESCRIPTION =
148
148
  "The acting agent's prose surfaces a clarifying question for Boss that the agent cannot answer alone. Output shall include `question: <verbatim question text from the acting agent's prose>`.";
149
149
 
150
150
  const INDEPENDENT_PROPOSAL_PROMPT = [
151
- '> <caller-topic>',
151
+ '> Original topic: <caller-topic>',
152
152
  '',
153
153
  'Assess whether the topic is better expressed as a few spec items under @specs/packages/ or requires one or more DRs under @specs/decisions/.',
154
154
  'Propose your design.',
@@ -22,7 +22,7 @@ Parallel group: independent-proposals
22
22
 
23
23
  When the caller gives a topic, Captain shall relay the complete topic to Coder in quotes and prompt Coder:
24
24
 
25
- > > <caller-topic>
25
+ > > Original topic: <caller-topic>
26
26
  >
27
27
  > Assess whether the topic is better expressed as a few spec items under @specs/packages/ or requires one or more DRs under @specs/decisions/.
28
28
  > Propose your design.
@@ -39,7 +39,7 @@ Parallel group: independent-proposals
39
39
 
40
40
  When the caller gives a topic, Captain shall relay the complete topic to Reviewer in quotes and prompt Reviewer:
41
41
 
42
- > > <caller-topic>
42
+ > > Original topic: <caller-topic>
43
43
  >
44
44
  > Assess whether the topic is better expressed as a few spec items under @specs/packages/ or requires one or more DRs under @specs/decisions/.
45
45
  > Propose your design.
@@ -10,7 +10,7 @@ export interface DecidePlaybookRuntimeConstruction {
10
10
  readonly hostCapabilities: DecidePlaybookHostCapabilities;
11
11
  }
12
12
  type PromptIdentity = (roleId: RoleId) => string;
13
- declare function composePlayerPrompt(input: PlayerInput, promptIdentity: PromptIdentity): string;
13
+ declare function composePlayerPrompt(input: PlayerInput, promptIdentity: PromptIdentity, resuming?: boolean): string;
14
14
  declare function requiredFieldsFor(description: string): string[];
15
15
  declare function extractJson(raw: string): Record<string, unknown> | null;
16
16
  declare function buildClassifierPrompt(text: string, ctx: {
@@ -67,7 +67,6 @@ export declare const _internal: {
67
67
  VERBATIM_PAYLOAD_FIELDS: ReadonlySet<string>;
68
68
  BOSS_INTERRUPT_TARGETS: readonly ["independentProposals"];
69
69
  UNFINISHED_FINAL_STATE_IDS: ReadonlySet<string>;
70
- CONTINUATION_PREAMBLE: string;
71
70
  TELEMETRY_TOPIC: string;
72
71
  };
73
72
  export default createPlaybookRuntime;
@@ -19,7 +19,7 @@ import { randomUUID } from 'node:crypto';
19
19
  import PQueue from 'p-queue';
20
20
  import { createActor, fromPromise } from 'xstate';
21
21
  import { createAcceptedOutcomeConsumer, } from '../../../src/accepted-outcome.js';
22
- import { assertJsonSafe, assertPlaybookEffectLedger, assertPlaybookRuntimeSnapshot, combineAbortSignals, createNestedPlaybookBridge, detachPersistedMachineSnapshot, normalizeError, normalizePlaybookSnapshot, PlaybookSemanticCandidateStructureError, reconcilePlaybookSemanticEvidence, renderGovernedOutcomeContract, snapshotJsonValue, snapshotPlaybookSession, terminalOutcomesFromMachine, validatePlayerResult, waitForPlaybookQuiescence, } from '../../../src/xstate-runtime.js';
22
+ import { assertJsonSafe, assertPlaybookEffectLedger, assertPlaybookRuntimeSnapshot, combineAbortSignals, composePlayerContinuation, createNestedPlaybookBridge, detachPersistedMachineSnapshot, normalizeError, normalizePlaybookSnapshot, PlaybookSemanticCandidateStructureError, reconcilePlaybookSemanticEvidence, renderGovernedOutcomeContract, snapshotJsonValue, snapshotPlaybookSession, terminalOutcomesFromMachine, validatePlayerResult, waitForPlaybookQuiescence, } from '../../../src/xstate-runtime.js';
23
23
  import decideMachine from './decide.fsm.js';
24
24
  function snapshotDecideRuntimeOptions(value) {
25
25
  const captured = snapshotJsonValue(value, 'DECIDE runtime options');
@@ -125,7 +125,6 @@ const TELEMETRY_TOPIC = 'playbook.fsm.state';
125
125
  const TRACE_TOPIC = 'playbook.trace';
126
126
  const UNRESOLVED_EFFECT_RECONCILIATION_ACTION_ID = 'reconcile:unresolved-effect';
127
127
  const UNRESOLVED_EFFECT_ABANDONMENT_ACTION_ID = 'abandon:unresolved-effect';
128
- const CONTINUATION_PREAMBLE = 'You previously paused this task to ask Boss a question; Boss has now replied. Continue the same task using the reply below.';
129
128
  const PLACEHOLDER_FIELDS = [
130
129
  ['<caller-topic>', 'callerTopic'],
131
130
  ['<reviewer-proposal>', 'reviewerProposal'],
@@ -135,19 +134,7 @@ const VERBATIM_PAYLOAD_FIELDS = new Set([
135
134
  'reviewerProposal',
136
135
  'coderOutput',
137
136
  ]);
138
- function composePlayerPrompt(input, promptIdentity) {
139
- const blocks = [];
140
- if (input.pendingBossQuestion && input.bossReply !== undefined) {
141
- blocks.push([
142
- CONTINUATION_PREAMBLE,
143
- '',
144
- 'Boss question:',
145
- input.pendingBossQuestion.question,
146
- '',
147
- 'Boss reply:',
148
- input.bossReply,
149
- ].join('\n'));
150
- }
137
+ function composePlayerPrompt(input, promptIdentity, resuming = false) {
151
138
  const replacements = new Map();
152
139
  for (const [placeholder, field] of PLACEHOLDER_FIELDS) {
153
140
  const value = input[field];
@@ -171,8 +158,7 @@ function composePlayerPrompt(input, promptIdentity) {
171
158
  ? value.replaceAll('\n', '\n> ')
172
159
  : value;
173
160
  });
174
- blocks.push(body);
175
- return blocks.join('\n\n');
161
+ return composePlayerContinuation(input, body, resuming);
176
162
  }
177
163
  // A `result` description names required payload fields in its
178
164
  // "Output shall include ..." sentence.
@@ -883,7 +869,7 @@ function createDecidePlaybookRuntime(options, deferredEffects) {
883
869
  };
884
870
  const resolvedPlayerId = (roleId) => requireSessionIdentity().roleBindings?.[roleId]?.playerId;
885
871
  const promptIdentity = (roleId) => requireSessionIdentity().roleBindings?.[roleId]?.promptIdentity ?? roleId;
886
- const composeInvocationPrompt = (input) => {
872
+ const composeInvocationPrompt = (input, resuming = false) => {
887
873
  let active = true;
888
874
  const lookup = (roleId) => {
889
875
  if (!active) {
@@ -895,7 +881,7 @@ function createDecidePlaybookRuntime(options, deferredEffects) {
895
881
  return promptIdentity(roleId);
896
882
  };
897
883
  try {
898
- return composePlayerPrompt(input, lookup);
884
+ return composePlayerPrompt(input, lookup, resuming);
899
885
  }
900
886
  finally {
901
887
  active = false;
@@ -1339,7 +1325,7 @@ function createDecidePlaybookRuntime(options, deferredEffects) {
1339
1325
  const roleId = input.role;
1340
1326
  const playerId = resolvedPlayerId(roleId);
1341
1327
  const playerKey = continuationKey(roleId, playerId);
1342
- const prompt = composeInvocationPrompt(input);
1328
+ const freshPrompt = composeInvocationPrompt(input);
1343
1329
  let resume;
1344
1330
  try {
1345
1331
  signal.throwIfAborted();
@@ -1353,6 +1339,7 @@ function createDecidePlaybookRuntime(options, deferredEffects) {
1353
1339
  latchControlPlaneError(error, signal);
1354
1340
  throw error;
1355
1341
  }
1342
+ const prompt = resume === false ? freshPrompt : composeInvocationPrompt(input, true);
1356
1343
  const callId = continuation?.callId ?? `player-${++playerCallSequence}`;
1357
1344
  const identity = {
1358
1345
  stateId: input.stateId,
@@ -1384,7 +1371,7 @@ function createDecidePlaybookRuntime(options, deferredEffects) {
1384
1371
  let rawResult;
1385
1372
  try {
1386
1373
  signal.throwIfAborted();
1387
- const boundary = Promise.resolve(requirePorts().callPlayer(roleId, prompt, signal, { resume }));
1374
+ const boundary = Promise.resolve(requirePorts().callPlayer(roleId, prompt, signal, { resume, ...(prompt === freshPrompt ? {} : { freshPrompt }) }));
1388
1375
  rawResult = await boundary;
1389
1376
  // An XState sibling cancellation does not cancel an arbitrary coder
1390
1377
  // promise. Re-check before a late resolution can mutate continuity or
@@ -3586,7 +3573,6 @@ export const _internal = {
3586
3573
  VERBATIM_PAYLOAD_FIELDS,
3587
3574
  BOSS_INTERRUPT_TARGETS,
3588
3575
  UNFINISHED_FINAL_STATE_IDS,
3589
- CONTINUATION_PREAMBLE,
3590
3576
  TELEMETRY_TOPIC,
3591
3577
  };
3592
3578
  export default createPlaybookRuntime;
@@ -32,6 +32,7 @@ import {
32
32
  assertPlaybookEffectLedger,
33
33
  assertPlaybookRuntimeSnapshot,
34
34
  combineAbortSignals,
35
+ composePlayerContinuation,
35
36
  createNestedPlaybookBridge,
36
37
  detachPersistedMachineSnapshot,
37
38
  normalizeError,
@@ -286,8 +287,6 @@ const UNRESOLVED_EFFECT_RECONCILIATION_ACTION_ID =
286
287
  const UNRESOLVED_EFFECT_ABANDONMENT_ACTION_ID =
287
288
  'abandon:unresolved-effect';
288
289
 
289
- const CONTINUATION_PREAMBLE =
290
- 'You previously paused this task to ask Boss a question; Boss has now replied. Continue the same task using the reply below.';
291
290
 
292
291
  const PLACEHOLDER_FIELDS: ReadonlyArray<readonly [string, keyof PlayerInput]> =
293
292
  [
@@ -306,23 +305,8 @@ type PromptIdentity = (roleId: RoleId) => string;
306
305
  function composePlayerPrompt(
307
306
  input: PlayerInput,
308
307
  promptIdentity: PromptIdentity,
308
+ resuming = false,
309
309
  ): string {
310
- const blocks: string[] = [];
311
-
312
- if (input.pendingBossQuestion && input.bossReply !== undefined) {
313
- blocks.push(
314
- [
315
- CONTINUATION_PREAMBLE,
316
- '',
317
- 'Boss question:',
318
- input.pendingBossQuestion.question,
319
- '',
320
- 'Boss reply:',
321
- input.bossReply,
322
- ].join('\n'),
323
- );
324
- }
325
-
326
310
  const replacements = new Map<string, string>();
327
311
  for (const [placeholder, field] of PLACEHOLDER_FIELDS) {
328
312
  const value = input[field];
@@ -348,8 +332,7 @@ function composePlayerPrompt(
348
332
  },
349
333
  );
350
334
 
351
- blocks.push(body);
352
- return blocks.join('\n\n');
335
+ return composePlayerContinuation(input, body, resuming);
353
336
  }
354
337
 
355
338
  // A `result` description names required payload fields in its
@@ -1518,7 +1501,7 @@ function createDecidePlaybookRuntime(
1518
1501
  const promptIdentity = (roleId: RoleId): string =>
1519
1502
  requireSessionIdentity().roleBindings?.[roleId]?.promptIdentity ?? roleId;
1520
1503
 
1521
- const composeInvocationPrompt = (input: PlayerInput): string => {
1504
+ const composeInvocationPrompt = (input: PlayerInput, resuming = false): string => {
1522
1505
  let active = true;
1523
1506
  const lookup: PromptIdentity = (roleId) => {
1524
1507
  if (!active) {
@@ -1534,7 +1517,7 @@ function createDecidePlaybookRuntime(
1534
1517
  return promptIdentity(roleId);
1535
1518
  };
1536
1519
  try {
1537
- return composePlayerPrompt(input, lookup);
1520
+ return composePlayerPrompt(input, lookup, resuming);
1538
1521
  } finally {
1539
1522
  active = false;
1540
1523
  }
@@ -2182,7 +2165,7 @@ function createDecidePlaybookRuntime(
2182
2165
  const roleId = input.role;
2183
2166
  const playerId = resolvedPlayerId(roleId);
2184
2167
  const playerKey = continuationKey(roleId, playerId);
2185
- const prompt = composeInvocationPrompt(input);
2168
+ const freshPrompt = composeInvocationPrompt(input);
2186
2169
  let resume: PlayerCallOptions['resume'];
2187
2170
  try {
2188
2171
  signal.throwIfAborted();
@@ -2195,6 +2178,7 @@ function createDecidePlaybookRuntime(
2195
2178
  latchControlPlaneError(error, signal);
2196
2179
  throw error;
2197
2180
  }
2181
+ const prompt = resume === false ? freshPrompt : composeInvocationPrompt(input, true);
2198
2182
  const callId =
2199
2183
  continuation?.callId ?? `player-${++playerCallSequence}`;
2200
2184
  const identity = {
@@ -2249,7 +2233,7 @@ function createDecidePlaybookRuntime(
2249
2233
  try {
2250
2234
  signal.throwIfAborted();
2251
2235
  const boundary = Promise.resolve(
2252
- requirePorts().callPlayer(roleId, prompt, signal, { resume }),
2236
+ requirePorts().callPlayer(roleId, prompt, signal, { resume, ...(prompt === freshPrompt ? {} : { freshPrompt }) }),
2253
2237
  );
2254
2238
  rawResult = await boundary;
2255
2239
  // An XState sibling cancellation does not cancel an arbitrary coder
@@ -5081,7 +5065,6 @@ export const _internal = {
5081
5065
  VERBATIM_PAYLOAD_FIELDS,
5082
5066
  BOSS_INTERRUPT_TARGETS,
5083
5067
  UNFINISHED_FINAL_STATE_IDS,
5084
- CONTINUATION_PREAMBLE,
5085
5068
  TELEMETRY_TOPIC,
5086
5069
  };
5087
5070
 
@@ -15,6 +15,10 @@ It coordinates existing playbooks and owns no repository commit itself.
15
15
 
16
16
  At the start of `dev` and after each Boss reply, Captain shall relay the development request, relevant discussion context, and any relevant run results to Analyst in quotes (`>`), along with the following instruction:
17
17
 
18
+ > Original request: <development-request>
19
+ > Prior discussion: <discussion-context>
20
+ > Run results: <run-results>
21
+
18
22
  ```markdown
19
23
  Inspect the request and the relevant repository and specs only as needed to determine the smallest sound next step.
20
24
  Do not change files or commit while planning or discussing the request.
@@ -35,15 +39,31 @@ No outcome depends on a fixed presentation format of Analyst's reply.
35
39
  `dev` shall act on the accepted outcome itself and shall not return to the session Captain for another routing decision.
36
40
 
37
41
  For needs Boss reply, `dev` shall use the standard Boss-question suspension with Analyst's complete response.
38
- The session Captain shall present that response to Boss and, after Boss replies, resume `dev` with the question and answer in the same Analyst conversation.
42
+ The session Captain shall present that response to Boss and, after Boss replies, resume `dev` with the answer in the same Analyst conversation; include the previous question only when that conversation must start fresh.
39
43
 
40
44
  Discussion complete is available only after a Boss reply, when any useful analysis has already been presented through needs Boss reply.
41
45
  It completes `dev` without a child call or repository change.
42
46
 
43
47
  For code, `dev` shall directly call playbook `code` with the development request, relevant discussion context, and planning result in quotes (`>`).
44
48
 
49
+ > Original request: <development-request>
50
+ > Prior discussion: <discussion-context>
51
+ > Planning result: <planning-result>
52
+
45
53
  For decide then code, `dev` shall call playbook `decide` with the development request, relevant discussion context, and planning result in quotes (`>`).
54
+
55
+ > Original request: <development-request>
56
+ > Prior discussion: <discussion-context>
57
+ > Planning result: <planning-result>
58
+
46
59
  Only after `decide` succeeds shall `dev` call playbook `code` with the development request, relevant discussion context, planning result, `decide`-owned commit, and exact evaluated repository revision in quotes (`>`).
60
+
61
+ > Original request: <development-request>
62
+ > Prior discussion: <discussion-context>
63
+ > Planning result: <planning-result>
64
+ > DECIDE commit: <decide-commit>
65
+ > Evaluated revision: <evaluated-revision>
66
+
47
67
  `dev` shall not separately call `review` for the design scope already reviewed by `decide`.
48
68
 
49
69
  `dev` completes with the successful result of its final child call.
@@ -4,9 +4,9 @@
4
4
  // Generated by slc/gears2fsm.md from ./dev.gears.md.
5
5
  import { assign, fromPromise, setup } from 'xstate';
6
6
  const PLAN_ANALYSIS_PROMPT = [
7
- '> <development-request>',
8
- '> <discussion-context>',
9
- '> <run-results>',
7
+ '> Original request: <development-request>',
8
+ '> Prior discussion: <discussion-context>',
9
+ '> Run results: <run-results>',
10
10
  '',
11
11
  'Inspect the request and the relevant repository and specs only as needed to determine the smallest sound next step.',
12
12
  'Do not change files or commit while planning or discussing the request.',
@@ -334,8 +334,8 @@ function archivedExchanges(context) {
334
334
  }
335
335
  function quotedRelay(values) {
336
336
  return values
337
- .filter((value) => value.length > 0)
338
- .map((value) => value
337
+ .filter(([, value]) => value.length > 0)
338
+ .map(([label, value]) => `${label}: ${value}`
339
339
  .split('\n')
340
340
  .map((line) => `> ${line}`)
341
341
  .join('\n'))
@@ -343,9 +343,9 @@ function quotedRelay(values) {
343
343
  }
344
344
  function planningRelayValues(context) {
345
345
  return [
346
- context.developmentRequest ?? '',
347
- renderDiscussionContext(context.discussionExchanges),
348
- context.planningResult ?? '',
346
+ ['Original request', context.developmentRequest ?? ''],
347
+ ['Prior discussion', renderDiscussionContext(context.discussionExchanges)],
348
+ ['Planning result', context.planningResult ?? ''],
349
349
  ];
350
350
  }
351
351
  function codeCallText(context) {
@@ -357,8 +357,8 @@ function decideCallText(context) {
357
357
  function codeAfterDecideCallText(context) {
358
358
  return quotedRelay([
359
359
  ...planningRelayValues(context),
360
- context.decideCommit ?? '',
361
- context.evaluatedRevision ?? '',
360
+ ['DECIDE commit', context.decideCommit ?? ''],
361
+ ['Evaluated revision', context.evaluatedRevision ?? ''],
362
362
  ]);
363
363
  }
364
364
  const machineSetup = setup({