@pikku/core 0.12.69 → 0.12.70

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 (84) hide show
  1. package/CHANGELOG.md +334 -0
  2. package/README.md +34 -2
  3. package/dist/function/functions.types.d.ts +27 -0
  4. package/dist/index.d.ts +1 -1
  5. package/dist/internal.d.ts +1 -1
  6. package/dist/internal.js +1 -1
  7. package/dist/pikku-state.js +1 -0
  8. package/dist/services/http-scenario-actors.d.ts +12 -4
  9. package/dist/services/http-scenario-actors.js +47 -45
  10. package/dist/services/index.d.ts +2 -1
  11. package/dist/services/index.js +1 -0
  12. package/dist/services/meta-service.d.ts +5 -1
  13. package/dist/services/meta-service.js +44 -18
  14. package/dist/services/scenario-actors-service.d.ts +108 -2
  15. package/dist/services/scenario-actors-service.js +40 -1
  16. package/dist/types/core.types.d.ts +21 -3
  17. package/dist/types/state.types.d.ts +3 -1
  18. package/dist/wirings/actor-flow/actor-flow.types.d.ts +1 -1
  19. package/dist/wirings/actor-flow/index.d.ts +1 -1
  20. package/dist/wirings/actor-flow/run-conversation.d.ts +10 -10
  21. package/dist/wirings/actor-flow/run-conversation.js +27 -27
  22. package/dist/wirings/cli/command-parser.js +11 -1
  23. package/dist/wirings/rpc/rpc-runner.js +1 -1
  24. package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +52 -3
  25. package/dist/wirings/workflow/feature.d.ts +28 -0
  26. package/dist/wirings/workflow/feature.js +57 -0
  27. package/dist/wirings/workflow/index.d.ts +13 -2
  28. package/dist/wirings/workflow/index.js +15 -0
  29. package/dist/wirings/workflow/pikku-scenario-service.d.ts +121 -0
  30. package/dist/wirings/workflow/pikku-scenario-service.js +419 -0
  31. package/dist/wirings/workflow/pikku-workflow-service.d.ts +103 -10
  32. package/dist/wirings/workflow/pikku-workflow-service.js +80 -135
  33. package/dist/wirings/workflow/scenario-cookie-jar.d.ts +29 -0
  34. package/dist/wirings/workflow/scenario-cookie-jar.js +51 -0
  35. package/dist/wirings/workflow/scenario-poll.d.ts +20 -0
  36. package/dist/wirings/workflow/scenario-poll.js +25 -0
  37. package/dist/wirings/workflow/scenario-prose.d.ts +38 -0
  38. package/dist/wirings/workflow/scenario-prose.js +45 -0
  39. package/dist/wirings/workflow/scenario-step-guards.d.ts +16 -0
  40. package/dist/wirings/workflow/scenario-step-guards.js +29 -0
  41. package/dist/wirings/workflow/scenario-step.types.d.ts +148 -0
  42. package/dist/wirings/workflow/scenario-step.types.js +1 -0
  43. package/dist/wirings/workflow/workflow.types.d.ts +81 -2
  44. package/package.json +3 -1
  45. package/src/function/functions.types.ts +32 -0
  46. package/src/index.ts +1 -0
  47. package/src/internal.ts +5 -1
  48. package/src/pikku-state.ts +1 -0
  49. package/src/services/http-scenario-actors.test.ts +85 -1
  50. package/src/services/http-scenario-actors.ts +65 -51
  51. package/src/services/index.ts +5 -0
  52. package/src/services/meta-service.test.ts +79 -0
  53. package/src/services/meta-service.ts +61 -26
  54. package/src/services/scenario-actors-service.ts +157 -2
  55. package/src/types/core.types.ts +27 -2
  56. package/src/types/state.types.ts +3 -0
  57. package/src/wirings/actor-flow/actor-flow.types.ts +1 -1
  58. package/src/wirings/actor-flow/index.ts +1 -1
  59. package/src/wirings/actor-flow/run-conversation.test.ts +12 -6
  60. package/src/wirings/actor-flow/run-conversation.ts +36 -41
  61. package/src/wirings/cli/command-parser.test.ts +60 -0
  62. package/src/wirings/cli/command-parser.ts +12 -1
  63. package/src/wirings/rpc/rpc-runner.test.ts +28 -5
  64. package/src/wirings/rpc/rpc-runner.ts +1 -1
  65. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +86 -2
  66. package/src/wirings/workflow/feature.test.ts +131 -0
  67. package/src/wirings/workflow/feature.ts +78 -0
  68. package/src/wirings/workflow/index.ts +73 -0
  69. package/src/wirings/workflow/pikku-scenario-service.ts +682 -0
  70. package/src/wirings/workflow/pikku-workflow-service.test.ts +55 -0
  71. package/src/wirings/workflow/pikku-workflow-service.ts +196 -208
  72. package/src/wirings/workflow/scenario-cookie-jar.test.ts +108 -0
  73. package/src/wirings/workflow/scenario-cookie-jar.ts +65 -0
  74. package/src/wirings/workflow/scenario-hooks.test.ts +212 -0
  75. package/src/wirings/workflow/scenario-poll.test.ts +66 -0
  76. package/src/wirings/workflow/scenario-poll.ts +36 -0
  77. package/src/wirings/workflow/scenario-prose.test.ts +152 -0
  78. package/src/wirings/workflow/scenario-prose.ts +79 -0
  79. package/src/wirings/workflow/scenario-service.test.ts +155 -0
  80. package/src/wirings/workflow/scenario-step-guards.ts +43 -0
  81. package/src/wirings/workflow/scenario-step.test.ts +441 -8
  82. package/src/wirings/workflow/scenario-step.types.ts +157 -0
  83. package/src/wirings/workflow/workflow.types.ts +98 -1
  84. package/tsconfig.tsbuildinfo +1 -1
@@ -1,5 +1,5 @@
1
- /** One turn the persona takes: the message to send and whether it's finished. */
2
- const PERSONA_TURN_SCHEMA = {
1
+ /** One turn the actor takes: the message to send and whether it's finished. */
2
+ const ACTOR_TURN_SCHEMA = {
3
3
  type: 'object',
4
4
  properties: {
5
5
  message: { type: 'string' },
@@ -7,7 +7,7 @@ const PERSONA_TURN_SCHEMA = {
7
7
  },
8
8
  required: ['message', 'done'],
9
9
  };
10
- /** The persona's approve/deny decision for each pending tool request. */
10
+ /** The actor's approve/deny decision for each pending tool request. */
11
11
  const APPROVAL_DECISION_SCHEMA = {
12
12
  type: 'object',
13
13
  properties: {
@@ -26,7 +26,7 @@ const APPROVAL_DECISION_SCHEMA = {
26
26
  },
27
27
  required: ['decisions'],
28
28
  };
29
- /** The persona's final verdict on whether the task was accomplished. */
29
+ /** The actor's final verdict on whether the task was accomplished. */
30
30
  const EVALUATION_SCHEMA = {
31
31
  type: 'object',
32
32
  properties: {
@@ -60,13 +60,13 @@ function readObject(result) {
60
60
  }
61
61
  return null;
62
62
  }
63
- function personaInstructions(persona, task) {
63
+ function actorInstructions(actor, task) {
64
64
  return [
65
65
  `You are role-playing a real user interacting with an AI assistant. Stay in character at all times — you are the user, not the assistant.`,
66
- persona.name ? `Your name is ${persona.name}.` : '',
67
- persona.jobTitle ? `Your role: ${persona.jobTitle}.` : '',
68
- persona.personality
69
- ? `Your personality and communication style: ${persona.personality}. Match this tone, vocabulary, and level of detail exactly.`
66
+ actor.name ? `Your name is ${actor.name}.` : '',
67
+ actor.jobTitle ? `Your role: ${actor.jobTitle}.` : '',
68
+ actor.personality
69
+ ? `Your personality and communication style: ${actor.personality}. Match this tone, vocabulary, and level of detail exactly.`
70
70
  : '',
71
71
  `Your goal in this conversation: ${task}.`,
72
72
  `Send one message at a time. Set "done" to true only once your goal is clearly accomplished, or clearly impossible.`,
@@ -74,7 +74,7 @@ function personaInstructions(persona, task) {
74
74
  .filter(Boolean)
75
75
  .join('\n');
76
76
  }
77
- /** Route the target agent's pending tool approvals through the persona. */
77
+ /** Route the target agent's pending tool approvals through the actor. */
78
78
  async function decideApprovals(params, instructions, pending) {
79
79
  const policy = params.approvals ?? 'in-persona';
80
80
  if (policy === 'always') {
@@ -88,7 +88,7 @@ async function decideApprovals(params, instructions, pending) {
88
88
  .join('\n');
89
89
  const result = await params.llm({
90
90
  model: params.model,
91
- instructions: `${instructions}\nThe assistant is asking permission to run tools on your behalf. Decide whether YOU, as this persona, would allow each one.`,
91
+ instructions: `${instructions}\nThe assistant is asking permission to run tools on your behalf. Decide whether YOU, as this actor, would allow each one.`,
92
92
  messages: [
93
93
  msg('user', `The assistant wants to run these tools:\n${summary}\nApprove or deny each toolCallId.`),
94
94
  ],
@@ -104,7 +104,7 @@ async function decideApprovals(params, instructions, pending) {
104
104
  return { toolCallId: p.toolCallId, approved: match?.approved ?? false };
105
105
  });
106
106
  }
107
- /** Drive the target to a non-suspended reply, routing approvals to the persona. */
107
+ /** Drive the target to a non-suspended reply, routing approvals to the actor. */
108
108
  async function converseWithTarget(params, instructions, message) {
109
109
  const maxRounds = params.maxApprovalRounds ?? DEFAULT_MAX_APPROVAL_ROUNDS;
110
110
  let reply = await params.target.run(message);
@@ -122,40 +122,40 @@ async function converseWithTarget(params, instructions, message) {
122
122
  return reply;
123
123
  }
124
124
  /**
125
- * Run a conversation: an LLM-driven persona holds a real multi-turn exchange
125
+ * Run a conversation: an LLM-driven actor holds a real multi-turn exchange
126
126
  * with a target agent (driven via the injected transport), answers the target's
127
127
  * tool-approval requests in-persona, then evaluates whether the task was met.
128
128
  * Deterministic checks are the caller's responsibility.
129
129
  */
130
130
  export async function runConversation(params) {
131
131
  const maxTurns = params.maxTurns ?? DEFAULT_MAX_TURNS;
132
- const instructions = personaInstructions(params.persona, params.task);
133
- // Seed a kickoff so the very first persona turn has a non-empty message list
134
- // (providers reject an empty prompt). It's an instruction TO the persona, so
132
+ const instructions = actorInstructions(params.actor, params.task);
133
+ // Seed a kickoff so the very first actor turn has a non-empty message list
134
+ // (providers reject an empty prompt). It's an instruction TO the actor, so
135
135
  // it never appears in the transcript.
136
- const personaMessages = [
136
+ const actorMessages = [
137
137
  msg('user', 'Begin the conversation now — send your first message to the assistant to work towards your goal.'),
138
138
  ];
139
139
  const transcript = [];
140
140
  for (let turn = 0; turn < maxTurns; turn++) {
141
- const personaResult = await params.llm({
141
+ const actorResult = await params.llm({
142
142
  model: params.model,
143
143
  instructions,
144
- messages: personaMessages,
144
+ messages: actorMessages,
145
145
  tools: [],
146
146
  maxSteps: 1,
147
147
  toolChoice: 'none',
148
- outputSchema: PERSONA_TURN_SCHEMA,
148
+ outputSchema: ACTOR_TURN_SCHEMA,
149
149
  });
150
- const turnData = readObject(personaResult);
151
- const personaMessage = turnData?.message?.trim();
152
- if (!personaMessage) {
150
+ const turnData = readObject(actorResult);
151
+ const actorMessage = turnData?.message?.trim();
152
+ if (!actorMessage) {
153
153
  break;
154
154
  }
155
- personaMessages.push(msg('assistant', personaMessage));
156
- transcript.push(`${params.personaName}: ${personaMessage}`);
157
- const reply = await converseWithTarget(params, instructions, personaMessage);
158
- personaMessages.push(msg('user', reply.text ?? ''));
155
+ actorMessages.push(msg('assistant', actorMessage));
156
+ transcript.push(`${params.actorName}: ${actorMessage}`);
157
+ const reply = await converseWithTarget(params, instructions, actorMessage);
158
+ actorMessages.push(msg('user', reply.text ?? ''));
159
159
  transcript.push(`${params.agentName}: ${reply.text ?? ''}`);
160
160
  if (turnData?.done) {
161
161
  break;
@@ -150,8 +150,18 @@ export function parseCLIArguments(args, programName, allMeta) {
150
150
  const arg = args[currentIndex];
151
151
  if (arg.startsWith('--')) {
152
152
  // Long option (--from-plan → fromPlan)
153
+ const negatedKey = arg.startsWith('--no-')
154
+ ? toCamelCase(arg.slice(5))
155
+ : undefined;
153
156
  const equalIndex = arg.indexOf('=');
154
- if (equalIndex > 0) {
157
+ if (negatedKey &&
158
+ typeof availableOptions[negatedKey]?.default === 'boolean') {
159
+ // --no-<flag> turns a boolean option off. Only options that declare a
160
+ // boolean default can be negated, so a literal `--no-something` option
161
+ // name still parses as itself.
162
+ optionArgs[negatedKey] = false;
163
+ }
164
+ else if (equalIndex > 0) {
155
165
  // --option=value format
156
166
  const key = toCamelCase(arg.slice(2, equalIndex));
157
167
  const optionDef = availableOptions[key];
@@ -129,7 +129,7 @@ export class ContextAwareRPCService {
129
129
  if (!functionMeta) {
130
130
  throw new RPCNotFoundError(funcName);
131
131
  }
132
- if (!functionMeta.expose) {
132
+ if (!functionMeta.expose || functionMeta.scenarioStep) {
133
133
  throw new RPCNotFoundError(funcName);
134
134
  }
135
135
  return await this.rpc(funcName, data);
@@ -5,6 +5,7 @@
5
5
  import type { StandardSchemaV1 } from '@standard-schema/spec';
6
6
  import type { WorkflowRun } from '../workflow.types.js';
7
7
  import type { ScenarioActor } from '../../../services/scenario-actors-service.js';
8
+ import type { ScenarioStepOptions, ScenarioStepPhase } from '../scenario-step.types.js';
8
9
  /**
9
10
  * Workflow step options
10
11
  */
@@ -60,6 +61,13 @@ export type WorkflowWireDoRPC = <TOutput = any, TInput = any>(stepName: string,
60
61
  * Type signature for workflow.do() inline form - used by inspector
61
62
  */
62
63
  export type WorkflowWireDoInline = <T>(stepName: string, fn: () => Promise<T> | T, options?: WorkflowStepOptions) => Promise<T>;
64
+ /**
65
+ * Type signature for scenario.step/given/when/then - used by inspector.
66
+ *
67
+ * Deliberately mirrors WorkflowWireDoRPC's shape: the target is a string, not
68
+ * an imported symbol, so the extractor reads it as a literal.
69
+ */
70
+ export type ScenarioStepInvocation = <TOutput = any, TInput = any>(stepName: string, stepFunc: string, data?: TInput, options?: ScenarioStepOptions) => Promise<TOutput>;
63
71
  /**
64
72
  * Type signature for workflow.sleep() - used by inspector
65
73
  */
@@ -172,6 +180,33 @@ export interface RpcStepMeta {
172
180
  /** True for workflow.expectEventually polling steps */
173
181
  expectEventually?: boolean;
174
182
  }
183
+ /**
184
+ * Scenario step metadata — a call to `scenario.step/given/when/then`.
185
+ *
186
+ * Distinct from RpcStepMeta on purpose: a step runs locally through
187
+ * runPikkuFunc and must never be treated as dispatchable on the queue/replay
188
+ * path, nor registered as a callable RPC (a browser-driving step must not be
189
+ * network-invocable).
190
+ */
191
+ export interface ScenarioStepMeta {
192
+ type: 'scenarioStep';
193
+ /** Cache key (first argument), ordinal-suffixed by the engine when repeated */
194
+ stepName: string;
195
+ /** Registered name of the step function being run */
196
+ stepFunc: string;
197
+ /** Which keyword the reporter prefixes — given/when/then, or none for `step` */
198
+ phase: ScenarioStepPhase;
199
+ /** Output variable name (if assigned) */
200
+ outputVar?: string;
201
+ /** Input source mappings, or 'passthrough' when entire data is passed */
202
+ inputs?: Record<string, InputSource> | 'passthrough';
203
+ /** Step options */
204
+ options?: WorkflowStepOptions;
205
+ /** Scenario actor name this step runs as ({ actor: actors.x }) */
206
+ actor?: string;
207
+ /** Mirrors the step function's `browser: true` declaration */
208
+ browser?: boolean;
209
+ }
175
210
  /**
176
211
  * Simple condition expression (leaf node)
177
212
  */
@@ -214,7 +249,7 @@ export interface BranchStepMeta {
214
249
  export interface ParallelGroupStepMeta {
215
250
  type: 'parallel';
216
251
  /** Child steps to execute in parallel */
217
- children: RpcStepMeta[];
252
+ children: Array<RpcStepMeta | ScenarioStepMeta>;
218
253
  }
219
254
  /**
220
255
  * Fanout step metadata (parallel or sequential iteration)
@@ -234,7 +269,7 @@ export interface FanoutStepMeta {
234
269
  /** Execution mode */
235
270
  mode: 'parallel' | 'sequential';
236
271
  /** Steps to execute inline per iteration, in order */
237
- body: Array<RpcStepMeta | SleepStepMeta | SuspendStepMeta>;
272
+ body: Array<RpcStepMeta | SleepStepMeta | SuspendStepMeta | ScenarioStepMeta>;
238
273
  /** Time between iterations (sequential mode only) */
239
274
  timeBetween?: string;
240
275
  }
@@ -385,7 +420,7 @@ export interface ArrayPredicateStepMeta {
385
420
  /**
386
421
  * Workflow step metadata (extracted by inspector)
387
422
  */
388
- export type WorkflowStepMeta = RpcStepMeta | BranchStepMeta | ParallelGroupStepMeta | FanoutStepMeta | ReturnStepMeta | InlineStepMeta | SleepStepMeta | CancelStepMeta | SuspendStepMeta | ApprovalStepMeta | SwitchStepMeta | FilterStepMeta | ArrayPredicateStepMeta | SetStepMeta;
423
+ export type WorkflowStepMeta = RpcStepMeta | ScenarioStepMeta | BranchStepMeta | ParallelGroupStepMeta | FanoutStepMeta | ReturnStepMeta | InlineStepMeta | SleepStepMeta | CancelStepMeta | SuspendStepMeta | ApprovalStepMeta | SwitchStepMeta | FilterStepMeta | ArrayPredicateStepMeta | SetStepMeta;
389
424
  /**
390
425
  * Workflow step wire context for RPC functions
391
426
  * Provides step-level metadata including retry attempt tracking
@@ -448,5 +483,19 @@ export interface PikkuScenarioWire extends PikkuWorkflowWire {
448
483
  expectError: <TInput = any>(stepName: string, rpcName: string, data: TInput, options?: WorkflowExpectErrorOptions) => Promise<string>;
449
484
  /** Stub-assertion step: asserts `service.method` was called on the target server */
450
485
  expectService: (stepName: string, serviceMethod: string, options?: WorkflowExpectServiceOptions) => Promise<void>;
486
+ /**
487
+ * Run a registered scenario step. Shaped exactly like `do`'s RPC form —
488
+ * `(stepName, target, data, options)` — so the inspector reads the target as
489
+ * a string literal rather than resolving an imported symbol.
490
+ *
491
+ * The generated `TypedScenario` narrows these over `FlattenedScenarioStepMap`.
492
+ */
493
+ step(stepName: string, stepFunc: string, data?: any, options?: ScenarioStepOptions): Promise<any>;
494
+ /** `step` with a "Given" prefix in the rendered prose */
495
+ given(stepName: string, stepFunc: string, data?: any, options?: ScenarioStepOptions): Promise<any>;
496
+ /** `step` with a "When" prefix in the rendered prose */
497
+ when(stepName: string, stepFunc: string, data?: any, options?: ScenarioStepOptions): Promise<any>;
498
+ /** `step` with a "Then" prefix in the rendered prose */
499
+ then(stepName: string, stepFunc: string, data?: any, options?: ScenarioStepOptions): Promise<any>;
451
500
  runScheduledTask: (name: string) => Promise<unknown>;
452
501
  }
@@ -0,0 +1,28 @@
1
+ import type { CoreFeature, CoreWorkflow, FeaturePlanEntry } from './workflow.types.js';
2
+ /**
3
+ * Register a feature under the name it is exported as. Called from generated
4
+ * wiring, the same way `addWorkflow` is.
5
+ */
6
+ export declare const addFeature: (featureId: string, feature: CoreFeature, packageName?: string | null) => void;
7
+ /**
8
+ * Resolve every feature's scenario references back to the names their
9
+ * scenarios are registered under.
10
+ *
11
+ * Matching is by **object identity**: `pikkuScenario` returns its config
12
+ * verbatim and `addWorkflow` registers that same object, so a feature holding
13
+ * the imported identifier holds the very object that was registered. Nothing
14
+ * is matched by shape, by name, or by any other guess — which is also why a
15
+ * scenario built inline inside a feature (and therefore never registered)
16
+ * comes back as unresolved rather than silently running as something else.
17
+ *
18
+ * Entries are returned in declaration order, features in registration order.
19
+ * A scenario's effective tags are its own plus the containing feature's, so
20
+ * `--tags credential` selects through the feature.
21
+ */
22
+ export declare const resolveFeatureScenarios: (features: Map<string, CoreFeature>, registrations: Map<string, CoreWorkflow>) => {
23
+ entries: FeaturePlanEntry[];
24
+ unresolved: Array<{
25
+ featureId: string;
26
+ index: number;
27
+ }>;
28
+ };
@@ -0,0 +1,57 @@
1
+ import { pikkuState } from '../../pikku-state.js';
2
+ /**
3
+ * Register a feature under the name it is exported as. Called from generated
4
+ * wiring, the same way `addWorkflow` is.
5
+ */
6
+ export const addFeature = (featureId, feature, packageName = null) => {
7
+ pikkuState(packageName, 'workflows', 'features').set(featureId, feature);
8
+ };
9
+ /**
10
+ * Resolve every feature's scenario references back to the names their
11
+ * scenarios are registered under.
12
+ *
13
+ * Matching is by **object identity**: `pikkuScenario` returns its config
14
+ * verbatim and `addWorkflow` registers that same object, so a feature holding
15
+ * the imported identifier holds the very object that was registered. Nothing
16
+ * is matched by shape, by name, or by any other guess — which is also why a
17
+ * scenario built inline inside a feature (and therefore never registered)
18
+ * comes back as unresolved rather than silently running as something else.
19
+ *
20
+ * Entries are returned in declaration order, features in registration order.
21
+ * A scenario's effective tags are its own plus the containing feature's, so
22
+ * `--tags credential` selects through the feature.
23
+ */
24
+ export const resolveFeatureScenarios = (features, registrations) => {
25
+ const nameByConfig = new Map();
26
+ for (const [name, registration] of registrations) {
27
+ nameByConfig.set(registration.func, name);
28
+ }
29
+ const entries = [];
30
+ const unresolved = [];
31
+ for (const [featureId, feature] of features) {
32
+ const scenarios = feature.scenarios ?? [];
33
+ for (let index = 0; index < scenarios.length; index++) {
34
+ const entry = scenarios[index];
35
+ const paired = typeof entry === 'object' && entry !== null && 'scenario' in entry;
36
+ const config = paired ? entry.scenario : entry;
37
+ const scenarioName = nameByConfig.get(config);
38
+ if (!scenarioName) {
39
+ unresolved.push({ featureId, index });
40
+ continue;
41
+ }
42
+ entries.push({
43
+ featureId,
44
+ featureName: feature.name ?? featureId,
45
+ scenarioName,
46
+ data: paired ? entry.data : undefined,
47
+ tags: [
48
+ ...new Set([
49
+ ...(registrations.get(scenarioName)?.func?.tags ?? []),
50
+ ...(feature.tags ?? []),
51
+ ]),
52
+ ],
53
+ });
54
+ }
55
+ }
56
+ return { entries, unresolved };
57
+ };
@@ -2,14 +2,25 @@
2
2
  * Workflow module exports
3
3
  */
4
4
  export { PikkuWorkflowService, WorkflowCancelledException, WorkflowSuspendedException, WorkflowDispatchException, WorkflowNotFoundError, WorkflowRunNotFoundError, WorkflowApprovalResolvedError, DEFAULT_STEP_RETRIES, } from './pikku-workflow-service.js';
5
+ export type { RunLifecycleContext, WorkflowRunEngine, WorkflowRunExtension, } from './pikku-workflow-service.js';
5
6
  export { deriveInvocationId, uuidv5 } from './workflow-invocation-id.js';
6
7
  export { buildRunTimeline, reconstructStateAt, reconstructFinalState, } from './run-timeline.js';
7
8
  export type { RunTimeline, RunTimelineEvent, ReconstructedRunState, ReconstructedStep, RunPhase, } from './run-timeline.js';
8
9
  export { addWorkflow } from './dsl/workflow-runner.js';
10
+ export { addFeature, resolveFeatureScenarios } from './feature.js';
9
11
  export { template, type TemplateString } from './graph/template.js';
10
12
  export { pikkuWorkflowGraph, type PikkuWorkflowGraphConfig, type PikkuWorkflowGraphResult, } from './graph/wire-workflow-graph.js';
11
13
  export { validateWorkflowWiring, computeEntryNodeIds, } from './graph/graph-validation.js';
12
14
  export { pikkuWorkflowWorkerFunc, pikkuWorkflowOrchestratorFunc, pikkuWorkflowSleeperFunc, } from './workflow-queue-workers.js';
13
15
  export type { WorkflowStepInput as WorkflowStepQueueInput, PikkuWorkflowOrchestratorInput, PikkuWorkflowSleeperInput, } from './workflow-queue-workers.js';
14
- export type { WorkflowService, WorkflowQueueOptions, WorkflowServiceConfig, WorkflowPlannedStep, WorkflowRunWire, WorkflowStatus, WorkflowVersionStatus, StepStatus, WorkflowRun, WorkflowRunStatus, StepState, WorkflowRunService, WorkflowRunMirror, CoreWorkflow, PikkuWorkflow, ContextVariable, WorkflowContext, WorkflowsMeta, WorkflowRuntimeMeta, WorkflowsRuntimeMeta, WorkflowStepInput, WorkflowOrchestratorInput, WorkflowSleeperInput, } from './workflow.types.js';
15
- export type { WorkflowStepOptions, WorkflowWireDoRPC, WorkflowWireDoInline, WorkflowWireSleep, WorkflowWireSuspend, WorkflowWireApproval, WorkflowApprovalOptions, ApprovalOutcome, InputSource, OutputBinding, RpcStepMeta, SimpleCondition, Condition, BranchCase, BranchStepMeta, ParallelGroupStepMeta, FanoutStepMeta, ReturnStepMeta, InlineStepMeta, SleepStepMeta, CancelStepMeta, SuspendStepMeta, ApprovalStepMeta, SetStepMeta, SwitchCaseMeta, SwitchStepMeta, FilterStepMeta, ArrayPredicateStepMeta, WorkflowStepMeta, WorkflowStepWire, PikkuWorkflowWire, PikkuScenarioWire, } from './workflow.types.js';
16
+ export type { WorkflowService, WorkflowQueueOptions, WorkflowServiceConfig, WorkflowPlannedStep, WorkflowRunWire, WorkflowStatus, WorkflowVersionStatus, StepStatus, WorkflowRun, WorkflowRunStatus, StepState, WorkflowRunService, WorkflowRunMirror, CoreWorkflow, CoreFeature, CoreFeatureScenario, FeatureMeta, FeatureMetaEntry, FeaturesMeta, FeaturePlanEntry, PikkuWorkflow, ContextVariable, WorkflowContext, WorkflowsMeta, WorkflowRuntimeMeta, WorkflowsRuntimeMeta, WorkflowStepInput, WorkflowOrchestratorInput, WorkflowSleeperInput, } from './workflow.types.js';
17
+ export type { WorkflowStepOptions, WorkflowWireDoRPC, WorkflowWireDoInline, WorkflowWireSleep, WorkflowWireSuspend, WorkflowWireApproval, WorkflowApprovalOptions, ApprovalOutcome, InputSource, OutputBinding, RpcStepMeta, SimpleCondition, Condition, BranchCase, BranchStepMeta, ParallelGroupStepMeta, FanoutStepMeta, ReturnStepMeta, InlineStepMeta, SleepStepMeta, CancelStepMeta, SuspendStepMeta, ApprovalStepMeta, SetStepMeta, SwitchCaseMeta, SwitchStepMeta, FilterStepMeta, ArrayPredicateStepMeta, ScenarioStepInvocation, ScenarioStepMeta, WorkflowStepMeta, WorkflowStepWire, PikkuWorkflowWire, PikkuScenarioWire, } from './workflow.types.js';
18
+ export type { ScenarioStepPhase, ScenarioStepOptions, PikkuScenarioStepWire, ScenarioEnvironment, } from './scenario-step.types.js';
19
+ export { requireActor, requireScenarioEnv } from './scenario-step-guards.js';
20
+ export { pollUntil, type PollOptions } from './scenario-poll.js';
21
+ export { createCookieJar } from './scenario-cookie-jar.js';
22
+ export type { ScenarioCookieJar } from './scenario-cookie-jar.js';
23
+ export type { ScenarioHttpResponse, ScenarioJsonRequest, } from '../../services/scenario-actors-service.js';
24
+ export { readScenarioHttpResponse, postScenarioJson, } from '../../services/scenario-actors-service.js';
25
+ export type { PikkuBrowserWire, TestIdSelector, ScenarioBrowserProvider, ScenarioBrowserFailure, } from './scenario-step.types.js';
26
+ export { composeStepProse, renderStepTemplate } from './scenario-prose.js';
@@ -7,6 +7,7 @@ export { deriveInvocationId, uuidv5 } from './workflow-invocation-id.js';
7
7
  export { buildRunTimeline, reconstructStateAt, reconstructFinalState, } from './run-timeline.js';
8
8
  // Internal registration functions (used by generated code)
9
9
  export { addWorkflow } from './dsl/workflow-runner.js';
10
+ export { addFeature, resolveFeatureScenarios } from './feature.js';
10
11
  // Graph helpers (template, pikkuWorkflowGraph)
11
12
  export { template } from './graph/template.js';
12
13
  export { pikkuWorkflowGraph, } from './graph/wire-workflow-graph.js';
@@ -14,3 +15,17 @@ export { pikkuWorkflowGraph, } from './graph/wire-workflow-graph.js';
14
15
  export { validateWorkflowWiring, computeEntryNodeIds, } from './graph/graph-validation.js';
15
16
  // Queue worker functions (registered by codegen, executed at runtime)
16
17
  export { pikkuWorkflowWorkerFunc, pikkuWorkflowOrchestratorFunc, pikkuWorkflowSleeperFunc, } from './workflow-queue-workers.js';
18
+ // Narrows the optional halves of the step wire, with a message that says what to do
19
+ export { requireActor, requireScenarioEnv } from './scenario-step-guards.js';
20
+ // Waits for the target to catch up, without every step writing the loop again
21
+ export { pollUntil } from './scenario-poll.js';
22
+ // Persists cookies across a step's requests, the way a browser would
23
+ export { createCookieJar } from './scenario-cookie-jar.js';
24
+ export { readScenarioHttpResponse, postScenarioJson, } from '../../services/scenario-actors-service.js';
25
+ /* ------------------------------------------------------------------ *
26
+ * Scenarios — reporting a run
27
+ *
28
+ * Used by the CLI reporter and the console, so the two render the same
29
+ * sentence for the same step. A step body needs none of it.
30
+ * ------------------------------------------------------------------ */
31
+ export { composeStepProse, renderStepTemplate } from './scenario-prose.js';
@@ -0,0 +1,121 @@
1
+ import { PikkuError } from '../../errors/error-handler.js';
2
+ import { InMemoryWorkflowService } from '../../services/in-memory-workflow-service.js';
3
+ import { type RunLifecycleContext, type WorkflowRunEngine, type WorkflowRunExtension } from './pikku-workflow-service.js';
4
+ import type { PikkuWire } from '../../types/core.types.js';
5
+ import type { ScenarioActors } from '../../services/scenario-actors-service.js';
6
+ import type { ScenarioBrowserProvider, ScenarioEnvironment } from './scenario-step.types.js';
7
+ import type { PikkuWorkflowWire, WorkflowQueueOptions } from './workflow.types.js';
8
+ /**
9
+ * A workflow service with the scenario capability attached — the two lines
10
+ * `pikku scenario run` needs, in one call so no caller has to remember that the
11
+ * capability is installed rather than inherited.
12
+ *
13
+ * The in-memory service is the right engine because a scenario run is a single
14
+ * external process driving a deployed app over its real transport: there is
15
+ * nothing to persist and no second worker to resume it.
16
+ */
17
+ export declare const createScenarioRunner: (options?: WorkflowQueueOptions) => {
18
+ workflowService: InMemoryWorkflowService;
19
+ scenarioService: PikkuScenarioService;
20
+ };
21
+ /**
22
+ * A scenario's `before` or `after` hook threw. The original error is kept as
23
+ * the `cause` so the failure that actually happened is never lost behind the
24
+ * label saying which phase it happened in.
25
+ */
26
+ export declare class ScenarioHookError extends PikkuError {
27
+ readonly scenarioName: string;
28
+ readonly phase: 'before' | 'after';
29
+ constructor(scenarioName: string, phase: 'before' | 'after', cause: unknown);
30
+ }
31
+ /**
32
+ * The scenario capability, layered onto a workflow service rather than being
33
+ * one.
34
+ *
35
+ * Every scenario affordance — steps, actors, lifecycle hooks, the browser
36
+ * provider, the assertion wire members — lives here rather than on
37
+ * `PikkuWorkflowService`, because a bundler drops an unused *module* but never
38
+ * an unused class member: anything declared on the workflow service ships in
39
+ * every server built on Pikku, along with everything it imports. Scenarios only
40
+ * ever run from `pikku scenario run`, so the whole surface stays behind an
41
+ * import only that runner makes.
42
+ *
43
+ * It is not a workflow service because a scenario is not a different kind of
44
+ * run — it is the same durable run with a step vocabulary on top. What it
45
+ * needs from the engine it gets through the narrow `WorkflowRunEngine` handle,
46
+ * which is why recording a step never became public API.
47
+ *
48
+ * ```ts
49
+ * const workflowService = new InMemoryWorkflowService()
50
+ * const scenarioService = workflowService.setRunExtension(
51
+ * (engine) => new PikkuScenarioService(engine)
52
+ * )
53
+ * ```
54
+ */
55
+ export declare class PikkuScenarioService implements WorkflowRunExtension {
56
+ private readonly engine;
57
+ private runActors;
58
+ private scenarioBrowserProvider?;
59
+ private scenarioEnvironment?;
60
+ constructor(engine: WorkflowRunEngine);
61
+ /**
62
+ * Registered by `@pikku/playwright` (or any other driver) before a scenario
63
+ * runs. Absent means browser steps cannot run, which the CLI checks up front
64
+ * so a run fails fast rather than mid-flow.
65
+ */
66
+ setScenarioBrowserProvider(provider: ScenarioBrowserProvider | undefined): void;
67
+ getScenarioBrowserProvider(): ScenarioBrowserProvider | undefined;
68
+ /**
69
+ * The environment scenario steps run against, set once by the runner. It is
70
+ * per-service rather than per-run because a runner process targets exactly
71
+ * one environment for every scenario it executes.
72
+ */
73
+ setScenarioEnvironment(env: ScenarioEnvironment | undefined): void;
74
+ getScenarioEnvironment(): ScenarioEnvironment | undefined;
75
+ attachRunContext(runId: string, workflowMeta: any, options?: {
76
+ actors?: ScenarioActors;
77
+ }): Promise<void>;
78
+ detachRunContext(runId: string): void;
79
+ decorateRunWire(wire: PikkuWire, context: {
80
+ runId: string;
81
+ workflowMeta: any;
82
+ workflowWire: PikkuWorkflowWire;
83
+ }): void;
84
+ onBeforeRunFunc(context: RunLifecycleContext): Promise<void>;
85
+ onAfterRunFunc(context: RunLifecycleContext, outcome: 'completed' | 'failed' | 'interrupted', failure: unknown): Promise<void>;
86
+ /**
87
+ * Hooks are a scenario affordance only: a plain workflow is durable and
88
+ * resumable, so a callback that reruns on every replay has no honest meaning
89
+ * there.
90
+ */
91
+ private scenarioHooks;
92
+ /**
93
+ * Run a scenario `before`/`after` hook.
94
+ *
95
+ * A hook is not a pikku function: it has no id, no meta and no schema, so it
96
+ * cannot go through `runPikkuFunc` and the runner records nothing for it. It
97
+ * gets exactly what the scenario body gets — the same wire (so `actors` is
98
+ * how it reaches the app), and singleton services composed with this
99
+ * invocation's wire services — and nothing else.
100
+ */
101
+ private runScenarioHook;
102
+ /**
103
+ * Build HTTP scenario actors for a run started without them; undefined when
104
+ * SCENARIO_ACTOR_SECRET or the API URL is missing.
105
+ *
106
+ * The actor client is imported lazily so that even a runner bundle only pays
107
+ * for the AI persona conversation loop it pulls in when a scenario actually
108
+ * signs an actor in.
109
+ */
110
+ resolveScenarioActors(): Promise<ScenarioActors | undefined>;
111
+ decorateWorkflowWire(wire: PikkuWorkflowWire, context: {
112
+ name: string;
113
+ runId: string;
114
+ rpcService: any;
115
+ addonNamespace?: string | null;
116
+ }): void;
117
+ private scenarioStep;
118
+ private scenarioStepConfig;
119
+ private scenarioStepDescription;
120
+ private requiresBrowser;
121
+ }