@exaudeus/workrail 1.12.0 → 1.13.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.
@@ -14,10 +14,8 @@ export interface CompiledWorkflow {
14
14
  readonly compiledLoops: ReadonlyMap<string, CompiledLoop>;
15
15
  readonly loopBodyStepIds: ReadonlySet<string>;
16
16
  }
17
+ export declare function resolveDefinitionSteps(steps: readonly (WorkflowStepDefinition | LoopStepDefinition)[], features: readonly string[]): Result<readonly (WorkflowStepDefinition | LoopStepDefinition)[], DomainError>;
17
18
  export declare class WorkflowCompiler {
18
- private readonly refRegistry;
19
- private readonly featureRegistry;
20
- private readonly templateRegistry;
21
19
  compile(workflow: Workflow): Result<CompiledWorkflow, DomainError>;
22
20
  private deriveConditionSource;
23
21
  private resolveLoopBody;
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.WorkflowCompiler = void 0;
10
+ exports.resolveDefinitionSteps = resolveDefinitionSteps;
10
11
  const tsyringe_1 = require("tsyringe");
11
12
  const workflow_1 = require("../../types/workflow");
12
13
  const index_1 = require("../../v2/durable-core/schemas/artifacts/index");
@@ -19,43 +20,47 @@ const resolve_features_1 = require("./compiler/resolve-features");
19
20
  const feature_registry_1 = require("./compiler/feature-registry");
20
21
  const resolve_templates_1 = require("./compiler/resolve-templates");
21
22
  const template_registry_1 = require("./compiler/template-registry");
22
- let WorkflowCompiler = class WorkflowCompiler {
23
- constructor() {
24
- this.refRegistry = (0, ref_registry_1.createRefRegistry)();
25
- this.featureRegistry = (0, feature_registry_1.createFeatureRegistry)();
26
- this.templateRegistry = (0, template_registry_1.createTemplateRegistry)();
23
+ const _refRegistry = (0, ref_registry_1.createRefRegistry)();
24
+ const _featureRegistry = (0, feature_registry_1.createFeatureRegistry)();
25
+ const _templateRegistry = (0, template_registry_1.createTemplateRegistry)();
26
+ function resolveDefinitionSteps(steps, features) {
27
+ const templatesResult = (0, resolve_templates_1.resolveTemplatesPass)(steps, _templateRegistry);
28
+ if (templatesResult.isErr()) {
29
+ const e = templatesResult.error;
30
+ const message = e.code === 'TEMPLATE_RESOLVE_ERROR'
31
+ ? `Step '${e.stepId}': template error — ${e.cause.message}`
32
+ : `Step '${e.stepId}': template expansion error — ${e.cause.message}`;
33
+ return (0, neverthrow_1.err)(error_1.Err.invalidState(message));
34
+ }
35
+ const featuresResult = (0, resolve_features_1.resolveFeaturesPass)(templatesResult.value, features, _featureRegistry);
36
+ if (featuresResult.isErr()) {
37
+ const e = featuresResult.error;
38
+ const message = e.code === 'FEATURE_RESOLVE_ERROR'
39
+ ? `Feature error — ${e.cause.message}`
40
+ : e.message;
41
+ return (0, neverthrow_1.err)(error_1.Err.invalidState(message));
42
+ }
43
+ const refsResult = (0, resolve_refs_1.resolveRefsPass)(featuresResult.value, _refRegistry);
44
+ if (refsResult.isErr()) {
45
+ const e = refsResult.error;
46
+ return (0, neverthrow_1.err)(error_1.Err.invalidState(`Step '${e.stepId}': ref resolution error — ${e.cause.message}`));
27
47
  }
48
+ const blocksResult = (0, prompt_blocks_1.resolvePromptBlocksPass)(refsResult.value);
49
+ if (blocksResult.isErr()) {
50
+ const e = blocksResult.error;
51
+ const message = e.code === 'PROMPT_AND_BLOCKS_BOTH_SET'
52
+ ? e.message
53
+ : `Step '${e.stepId}': promptBlocks error — ${e.cause.message}`;
54
+ return (0, neverthrow_1.err)(error_1.Err.invalidState(message));
55
+ }
56
+ return (0, neverthrow_1.ok)(blocksResult.value);
57
+ }
58
+ let WorkflowCompiler = class WorkflowCompiler {
28
59
  compile(workflow) {
29
- const templatesResult = (0, resolve_templates_1.resolveTemplatesPass)(workflow.definition.steps, this.templateRegistry);
30
- if (templatesResult.isErr()) {
31
- const e = templatesResult.error;
32
- const message = e.code === 'TEMPLATE_RESOLVE_ERROR'
33
- ? `Step '${e.stepId}': template error — ${e.cause.message}`
34
- : `Step '${e.stepId}': template expansion error — ${e.cause.message}`;
35
- return (0, neverthrow_1.err)(error_1.Err.invalidState(message));
36
- }
37
- const featuresResult = (0, resolve_features_1.resolveFeaturesPass)(templatesResult.value, workflow.definition.features ?? [], this.featureRegistry);
38
- if (featuresResult.isErr()) {
39
- const e = featuresResult.error;
40
- const message = e.code === 'FEATURE_RESOLVE_ERROR'
41
- ? `Feature error — ${e.cause.message}`
42
- : e.message;
43
- return (0, neverthrow_1.err)(error_1.Err.invalidState(message));
44
- }
45
- const refsResult = (0, resolve_refs_1.resolveRefsPass)(featuresResult.value, this.refRegistry);
46
- if (refsResult.isErr()) {
47
- const e = refsResult.error;
48
- return (0, neverthrow_1.err)(error_1.Err.invalidState(`Step '${e.stepId}': ref resolution error — ${e.cause.message}`));
49
- }
50
- const blocksResult = (0, prompt_blocks_1.resolvePromptBlocksPass)(refsResult.value);
51
- if (blocksResult.isErr()) {
52
- const e = blocksResult.error;
53
- const message = e.code === 'PROMPT_AND_BLOCKS_BOTH_SET'
54
- ? e.message
55
- : `Step '${e.stepId}': promptBlocks error — ${e.cause.message}`;
56
- return (0, neverthrow_1.err)(error_1.Err.invalidState(message));
57
- }
58
- const steps = blocksResult.value;
60
+ const resolvedResult = resolveDefinitionSteps(workflow.definition.steps, workflow.definition.features ?? []);
61
+ if (resolvedResult.isErr())
62
+ return (0, neverthrow_1.err)(resolvedResult.error);
63
+ const steps = resolvedResult.value;
59
64
  const stepById = new Map();
60
65
  for (const step of steps) {
61
66
  if (stepById.has(step.id)) {
@@ -98,12 +98,12 @@
98
98
  "bytes": 31038
99
99
  },
100
100
  "application/services/workflow-compiler.d.ts": {
101
- "sha256": "d1371ca551a908a7f95078d20e02203d7b24525659d9160d50b06fd2708ca4a9",
102
- "bytes": 1101
101
+ "sha256": "41d0643ae2f07e5ce77a6e02344b5ca5b3c26bde828fbb307528a2ae097ac9d5",
102
+ "bytes": 1211
103
103
  },
104
104
  "application/services/workflow-compiler.js": {
105
- "sha256": "4fad72793de969fce4f269d154fc5743a329fc1e015e63b3c6e6ba12bcdeafc7",
106
- "bytes": 8017
105
+ "sha256": "db74bfe006cf703cc0c32165e09e2c684e24fcf7b538ecbc1273daf67012dc2d",
106
+ "bytes": 8182
107
107
  },
108
108
  "application/services/workflow-interpreter.d.ts": {
109
109
  "sha256": "56b5b5ad06d42096deba9f0abe7642c18a355a1e598749aab1730df4e9847674",
@@ -2174,8 +2174,8 @@
2174
2174
  "bytes": 463
2175
2175
  },
2176
2176
  "v2/read-only/v1-to-v2-shim.js": {
2177
- "sha256": "6ea788b80605db6d2057b3d5e520be48ace8afe6d8f37bf55cef00ba1471a6b7",
2178
- "bytes": 1935
2177
+ "sha256": "36a9c3f0faf71c49fc9624f41c26c452e276f4ac15190f2d22d89a003a2bb099",
2178
+ "bytes": 2678
2179
2179
  },
2180
2180
  "v2/usecases/enumerate-sessions.d.ts": {
2181
2181
  "sha256": "6043d64b45360dfc6a15b822d9f013a0832127596706bf81569dfce256236d2d",
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compileV1WorkflowToV2PreviewSnapshot = compileV1WorkflowToV2PreviewSnapshot;
4
4
  exports.compileV1WorkflowToPinnedSnapshot = compileV1WorkflowToPinnedSnapshot;
5
+ const workflow_compiler_js_1 = require("../../application/services/workflow-compiler.js");
5
6
  function compileV1WorkflowToV2PreviewSnapshot(workflow) {
6
7
  const firstStep = workflow.definition.steps[0];
7
8
  if (!firstStep) {
@@ -20,9 +21,19 @@ function compileV1WorkflowToV2PreviewSnapshot(workflow) {
20
21
  };
21
22
  }
22
23
  const isLoop = firstStep.type === 'loop';
23
- const prompt = !isLoop && typeof firstStep.prompt === 'string'
24
- ? firstStep.prompt
25
- : `Loop step '${firstStep.id}' cannot be previewed in v2 Slice 1 (loop execution/compilation not implemented yet).`;
24
+ let prompt;
25
+ if (isLoop) {
26
+ prompt = `Loop step '${firstStep.id}' cannot be previewed in v2 Slice 1 (loop execution/compilation not implemented yet).`;
27
+ }
28
+ else if (typeof firstStep.prompt === 'string') {
29
+ prompt = firstStep.prompt;
30
+ }
31
+ else {
32
+ const resolved = (0, workflow_compiler_js_1.resolveDefinitionSteps)([firstStep], workflow.definition.features ?? []);
33
+ prompt = resolved.isOk() && resolved.value[0]?.prompt
34
+ ? resolved.value[0].prompt
35
+ : `Step '${firstStep.id}' has no prompt (promptBlocks resolution failed).`;
36
+ }
26
37
  return {
27
38
  schemaVersion: 1,
28
39
  sourceKind: 'v1_preview',
@@ -38,6 +49,10 @@ function compileV1WorkflowToV2PreviewSnapshot(workflow) {
38
49
  };
39
50
  }
40
51
  function compileV1WorkflowToPinnedSnapshot(workflow) {
52
+ const resolved = (0, workflow_compiler_js_1.resolveDefinitionSteps)(workflow.definition.steps, workflow.definition.features ?? []);
53
+ const resolvedDefinition = resolved.isOk()
54
+ ? { ...workflow.definition, steps: resolved.value }
55
+ : workflow.definition;
41
56
  return {
42
57
  schemaVersion: 1,
43
58
  sourceKind: 'v1_pinned',
@@ -45,6 +60,6 @@ function compileV1WorkflowToPinnedSnapshot(workflow) {
45
60
  name: workflow.definition.name,
46
61
  description: workflow.definition.description,
47
62
  version: workflow.definition.version,
48
- definition: workflow.definition,
63
+ definition: resolvedDefinition,
49
64
  };
50
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exaudeus/workrail",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Step-by-step workflow enforcement for AI agents via MCP",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://workflowlookup.io/schemas/workflow/v0.2.0",
3
+ "$id": "https://workflowlookup.io/schemas/workflow/v0.3.0",
4
4
  "title": "Workflow Schema",
5
5
  "description": "Schema for defining workflows in the Workflow Orchestration System",
6
6
  "type": "object",
@@ -124,6 +124,16 @@
124
124
  }
125
125
  },
126
126
  "additionalProperties": false
127
+ },
128
+ "features": {
129
+ "type": "array",
130
+ "description": "Compiler features to apply to this workflow (e.g. wr.features.memory_context). Features inject content into promptBlocks at compile time.",
131
+ "items": {
132
+ "type": "string",
133
+ "minLength": 1,
134
+ "maxLength": 128
135
+ },
136
+ "uniqueItems": true
127
137
  }
128
138
  },
129
139
  "required": [
@@ -179,6 +189,7 @@
179
189
  "id": { "$ref": "#/$defs/stepId", "description": "Unique identifier for the step" },
180
190
  "title": { "type": "string", "minLength": 1, "maxLength": 128 },
181
191
  "prompt": { "type": "string", "minLength": 1, "maxLength": 8192 },
192
+ "promptBlocks": { "$ref": "#/$defs/promptBlocks" },
182
193
  "agentRole": { "type": "string", "minLength": 10, "maxLength": 1024 },
183
194
  "guidance": { "type": "array", "items": { "type": "string" } },
184
195
  "askForFiles": { "type": "boolean", "default": false },
@@ -190,9 +201,10 @@
190
201
  "notesOptional": { "type": "boolean", "description": "When true, output.notesMarkdown is not required for this step. Steps with outputContract are automatically exempt. Use sparingly for mechanical steps with no substantive work to document." },
191
202
  "functionDefinitions": { "type": "array", "items": { "$ref": "#/$defs/functionDefinition" } },
192
203
  "functionCalls": { "type": "array", "items": { "$ref": "#/$defs/functionCall" } },
193
- "functionReferences": { "type": "array", "items": { "type": "string", "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*\\(\\)$" } }
204
+ "functionReferences": { "type": "array", "items": { "type": "string", "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*\\(\\)$" } },
205
+ "templateCall": { "$ref": "#/$defs/templateCall" }
194
206
  },
195
- "required": ["id", "title", "prompt"],
207
+ "required": ["id", "title"],
196
208
  "additionalProperties": false
197
209
  },
198
210
  "loopStep": {
@@ -589,6 +601,83 @@
589
601
  },
590
602
  "required": ["name", "args"],
591
603
  "additionalProperties": false
604
+ },
605
+ "promptBlocks": {
606
+ "type": "object",
607
+ "description": "Structured prompt blocks. Alternative to raw prompt string. Rendered into prompt during compilation in deterministic order: goal, constraints, procedure, outputRequired, verify.",
608
+ "properties": {
609
+ "goal": { "$ref": "#/$defs/promptValue" },
610
+ "constraints": {
611
+ "type": "array",
612
+ "items": { "$ref": "#/$defs/promptValue" }
613
+ },
614
+ "procedure": {
615
+ "type": "array",
616
+ "items": { "$ref": "#/$defs/promptValue" }
617
+ },
618
+ "outputRequired": {
619
+ "type": "object",
620
+ "description": "Key-value pairs describing required outputs",
621
+ "additionalProperties": { "type": "string" }
622
+ },
623
+ "verify": {
624
+ "type": "array",
625
+ "items": { "$ref": "#/$defs/promptValue" }
626
+ }
627
+ },
628
+ "additionalProperties": false
629
+ },
630
+ "promptValue": {
631
+ "description": "A prompt value: either a plain string or an array of prompt parts (text and refs).",
632
+ "oneOf": [
633
+ { "type": "string" },
634
+ {
635
+ "type": "array",
636
+ "items": { "$ref": "#/$defs/promptPart" }
637
+ }
638
+ ]
639
+ },
640
+ "promptPart": {
641
+ "description": "A single part of a prompt value: literal text or a reference to a canonical WorkRail snippet.",
642
+ "oneOf": [
643
+ {
644
+ "type": "object",
645
+ "properties": {
646
+ "kind": { "const": "text" },
647
+ "text": { "type": "string" }
648
+ },
649
+ "required": ["kind", "text"],
650
+ "additionalProperties": false
651
+ },
652
+ {
653
+ "type": "object",
654
+ "properties": {
655
+ "kind": { "const": "ref" },
656
+ "refId": { "type": "string", "minLength": 1 }
657
+ },
658
+ "required": ["kind", "refId"],
659
+ "additionalProperties": false
660
+ }
661
+ ]
662
+ },
663
+ "templateCall": {
664
+ "type": "object",
665
+ "description": "Template call: expands this step into one or more steps at compile time.",
666
+ "properties": {
667
+ "templateId": {
668
+ "type": "string",
669
+ "description": "The template ID to expand (e.g. wr.templates.capability_probe)",
670
+ "minLength": 1,
671
+ "maxLength": 128
672
+ },
673
+ "args": {
674
+ "type": "object",
675
+ "description": "Arguments to pass to the template",
676
+ "additionalProperties": true
677
+ }
678
+ },
679
+ "required": ["templateId"],
680
+ "additionalProperties": false
592
681
  }
593
682
  }
594
683
  }