@exaudeus/workrail 1.9.0 → 1.11.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.
@@ -0,0 +1,19 @@
1
+ import type { Result } from 'neverthrow';
2
+ import type { PromptValue } from './prompt-blocks.js';
3
+ export interface FeatureDefinition {
4
+ readonly id: string;
5
+ readonly constraints?: readonly PromptValue[];
6
+ readonly procedure?: readonly PromptValue[];
7
+ readonly verify?: readonly PromptValue[];
8
+ }
9
+ export type FeatureResolveError = {
10
+ readonly code: 'UNKNOWN_FEATURE';
11
+ readonly featureId: string;
12
+ readonly message: string;
13
+ };
14
+ export interface FeatureRegistry {
15
+ readonly resolve: (featureId: string) => Result<FeatureDefinition, FeatureResolveError>;
16
+ readonly has: (featureId: string) => boolean;
17
+ readonly knownIds: () => readonly string[];
18
+ }
19
+ export declare function createFeatureRegistry(): FeatureRegistry;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFeatureRegistry = createFeatureRegistry;
4
+ const neverthrow_1 = require("neverthrow");
5
+ const FEATURE_DEFINITIONS = [
6
+ {
7
+ id: 'wr.features.memory_context',
8
+ constraints: [
9
+ [
10
+ { kind: 'ref', refId: 'wr.refs.memory_usage' },
11
+ ],
12
+ ],
13
+ },
14
+ ];
15
+ function createFeatureRegistry() {
16
+ const byId = new Map(FEATURE_DEFINITIONS.map(f => [f.id, f]));
17
+ const knownIds = FEATURE_DEFINITIONS.map(f => f.id);
18
+ return {
19
+ resolve(featureId) {
20
+ const def = byId.get(featureId);
21
+ if (!def) {
22
+ return (0, neverthrow_1.err)({
23
+ code: 'UNKNOWN_FEATURE',
24
+ featureId,
25
+ message: `Unknown feature '${featureId}'. Known features: ${knownIds.join(', ')}`,
26
+ });
27
+ }
28
+ return (0, neverthrow_1.ok)(def);
29
+ },
30
+ has(featureId) {
31
+ return byId.has(featureId);
32
+ },
33
+ knownIds() {
34
+ return knownIds;
35
+ },
36
+ };
37
+ }
@@ -0,0 +1,12 @@
1
+ import type { Result } from 'neverthrow';
2
+ import type { FeatureRegistry, FeatureResolveError } from './feature-registry.js';
3
+ import type { WorkflowStepDefinition, LoopStepDefinition } from '../../../types/workflow-definition.js';
4
+ export type ResolveFeaturesPassError = {
5
+ readonly code: 'FEATURE_RESOLVE_ERROR';
6
+ readonly cause: FeatureResolveError;
7
+ } | {
8
+ readonly code: 'FEATURE_ON_RAW_PROMPT_STEP';
9
+ readonly stepId: string;
10
+ readonly message: string;
11
+ };
12
+ export declare function resolveFeaturesPass(steps: readonly (WorkflowStepDefinition | LoopStepDefinition)[], featureIds: readonly string[], registry: FeatureRegistry): Result<readonly (WorkflowStepDefinition | LoopStepDefinition)[], ResolveFeaturesPassError>;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveFeaturesPass = resolveFeaturesPass;
4
+ const neverthrow_1 = require("neverthrow");
5
+ const workflow_definition_js_1 = require("../../../types/workflow-definition.js");
6
+ function appendValues(existing, injected) {
7
+ if (!injected || injected.length === 0)
8
+ return existing;
9
+ if (!existing || existing.length === 0)
10
+ return injected;
11
+ return [...existing, ...injected];
12
+ }
13
+ function applyFeatureToBlocks(blocks, feature) {
14
+ return {
15
+ ...blocks,
16
+ constraints: appendValues(blocks.constraints, feature.constraints),
17
+ procedure: appendValues(blocks.procedure, feature.procedure),
18
+ verify: appendValues(blocks.verify, feature.verify),
19
+ };
20
+ }
21
+ function applyFeaturesToStep(step, features) {
22
+ if (!step.promptBlocks || features.length === 0)
23
+ return step;
24
+ let blocks = step.promptBlocks;
25
+ for (const feature of features) {
26
+ blocks = applyFeatureToBlocks(blocks, feature);
27
+ }
28
+ return { ...step, promptBlocks: blocks };
29
+ }
30
+ function resolveFeaturesPass(steps, featureIds, registry) {
31
+ if (featureIds.length === 0)
32
+ return (0, neverthrow_1.ok)(steps);
33
+ const features = [];
34
+ for (const id of featureIds) {
35
+ const res = registry.resolve(id);
36
+ if (res.isErr()) {
37
+ return (0, neverthrow_1.err)({ code: 'FEATURE_RESOLVE_ERROR', cause: res.error });
38
+ }
39
+ features.push(res.value);
40
+ }
41
+ const resolved = [];
42
+ for (const step of steps) {
43
+ if ((0, workflow_definition_js_1.isLoopStepDefinition)(step)) {
44
+ const resolvedLoop = applyFeaturesToStep(step, features);
45
+ if (Array.isArray(step.body)) {
46
+ const bodyResolved = step.body.map(bodyStep => applyFeaturesToStep(bodyStep, features));
47
+ resolved.push({
48
+ ...step,
49
+ ...(resolvedLoop.promptBlocks ? { promptBlocks: resolvedLoop.promptBlocks } : {}),
50
+ body: bodyResolved,
51
+ });
52
+ }
53
+ else {
54
+ resolved.push({
55
+ ...step,
56
+ ...(resolvedLoop.promptBlocks ? { promptBlocks: resolvedLoop.promptBlocks } : {}),
57
+ });
58
+ }
59
+ }
60
+ else {
61
+ resolved.push(applyFeaturesToStep(step, features));
62
+ }
63
+ }
64
+ return (0, neverthrow_1.ok)(resolved);
65
+ }
@@ -0,0 +1,13 @@
1
+ import type { Result } from 'neverthrow';
2
+ import type { TemplateRegistry, TemplateResolveError, TemplateExpandError } from './template-registry.js';
3
+ import type { WorkflowStepDefinition, LoopStepDefinition } from '../../../types/workflow-definition.js';
4
+ export type ResolveTemplatesPassError = {
5
+ readonly code: 'TEMPLATE_RESOLVE_ERROR';
6
+ readonly stepId: string;
7
+ readonly cause: TemplateResolveError;
8
+ } | {
9
+ readonly code: 'TEMPLATE_EXPAND_ERROR';
10
+ readonly stepId: string;
11
+ readonly cause: TemplateExpandError;
12
+ };
13
+ export declare function resolveTemplatesPass(steps: readonly (WorkflowStepDefinition | LoopStepDefinition)[], registry: TemplateRegistry): Result<readonly (WorkflowStepDefinition | LoopStepDefinition)[], ResolveTemplatesPassError>;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveTemplatesPass = resolveTemplatesPass;
4
+ const neverthrow_1 = require("neverthrow");
5
+ const workflow_definition_js_1 = require("../../../types/workflow-definition.js");
6
+ function resolveStepTemplate(step, registry) {
7
+ if (!step.templateCall)
8
+ return (0, neverthrow_1.ok)([step]);
9
+ const { templateId, args } = step.templateCall;
10
+ const expanderResult = registry.resolve(templateId);
11
+ if (expanderResult.isErr()) {
12
+ return (0, neverthrow_1.err)({
13
+ code: 'TEMPLATE_RESOLVE_ERROR',
14
+ stepId: step.id,
15
+ cause: expanderResult.error,
16
+ });
17
+ }
18
+ const expandResult = expanderResult.value(step.id, args ?? {});
19
+ if (expandResult.isErr()) {
20
+ return (0, neverthrow_1.err)({
21
+ code: 'TEMPLATE_EXPAND_ERROR',
22
+ stepId: step.id,
23
+ cause: expandResult.error,
24
+ });
25
+ }
26
+ return (0, neverthrow_1.ok)(expandResult.value);
27
+ }
28
+ function resolveTemplatesPass(steps, registry) {
29
+ const resolved = [];
30
+ for (const step of steps) {
31
+ if ((0, workflow_definition_js_1.isLoopStepDefinition)(step)) {
32
+ if (Array.isArray(step.body)) {
33
+ const bodyResolved = [];
34
+ for (const bodyStep of step.body) {
35
+ const res = resolveStepTemplate(bodyStep, registry);
36
+ if (res.isErr())
37
+ return (0, neverthrow_1.err)(res.error);
38
+ bodyResolved.push(...res.value);
39
+ }
40
+ resolved.push({ ...step, body: bodyResolved });
41
+ }
42
+ else {
43
+ resolved.push(step);
44
+ }
45
+ }
46
+ else {
47
+ const res = resolveStepTemplate(step, registry);
48
+ if (res.isErr())
49
+ return (0, neverthrow_1.err)(res.error);
50
+ resolved.push(...res.value);
51
+ }
52
+ }
53
+ return (0, neverthrow_1.ok)(resolved);
54
+ }
@@ -0,0 +1,19 @@
1
+ import type { Result } from 'neverthrow';
2
+ import type { WorkflowStepDefinition } from '../../../types/workflow-definition.js';
3
+ export type TemplateExpander = (callerId: string, args: Readonly<Record<string, unknown>>) => Result<readonly WorkflowStepDefinition[], TemplateExpandError>;
4
+ export type TemplateExpandError = {
5
+ readonly code: 'TEMPLATE_EXPAND_FAILED';
6
+ readonly templateId: string;
7
+ readonly message: string;
8
+ };
9
+ export type TemplateResolveError = {
10
+ readonly code: 'UNKNOWN_TEMPLATE';
11
+ readonly templateId: string;
12
+ readonly message: string;
13
+ };
14
+ export interface TemplateRegistry {
15
+ readonly resolve: (templateId: string) => Result<TemplateExpander, TemplateResolveError>;
16
+ readonly has: (templateId: string) => boolean;
17
+ readonly knownIds: () => readonly string[];
18
+ }
19
+ export declare function createTemplateRegistry(): TemplateRegistry;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTemplateRegistry = createTemplateRegistry;
4
+ const neverthrow_1 = require("neverthrow");
5
+ const TEMPLATE_DEFINITIONS = new Map();
6
+ function createTemplateRegistry() {
7
+ const knownIds = [...TEMPLATE_DEFINITIONS.keys()];
8
+ return {
9
+ resolve(templateId) {
10
+ const expander = TEMPLATE_DEFINITIONS.get(templateId);
11
+ if (!expander) {
12
+ return (0, neverthrow_1.err)({
13
+ code: 'UNKNOWN_TEMPLATE',
14
+ templateId,
15
+ message: `Unknown template '${templateId}'. Known templates: ${knownIds.length > 0 ? knownIds.join(', ') : '(none)'}`,
16
+ });
17
+ }
18
+ return (0, neverthrow_1.ok)(expander);
19
+ },
20
+ has(templateId) {
21
+ return TEMPLATE_DEFINITIONS.has(templateId);
22
+ },
23
+ knownIds() {
24
+ return knownIds;
25
+ },
26
+ };
27
+ }
@@ -16,6 +16,8 @@ export interface CompiledWorkflow {
16
16
  }
17
17
  export declare class WorkflowCompiler {
18
18
  private readonly refRegistry;
19
+ private readonly featureRegistry;
20
+ private readonly templateRegistry;
19
21
  compile(workflow: Workflow): Result<CompiledWorkflow, DomainError>;
20
22
  private deriveConditionSource;
21
23
  private resolveLoopBody;
@@ -15,12 +15,34 @@ const error_1 = require("../../domain/execution/error");
15
15
  const prompt_blocks_1 = require("./compiler/prompt-blocks");
16
16
  const resolve_refs_1 = require("./compiler/resolve-refs");
17
17
  const ref_registry_1 = require("./compiler/ref-registry");
18
+ const resolve_features_1 = require("./compiler/resolve-features");
19
+ const feature_registry_1 = require("./compiler/feature-registry");
20
+ const resolve_templates_1 = require("./compiler/resolve-templates");
21
+ const template_registry_1 = require("./compiler/template-registry");
18
22
  let WorkflowCompiler = class WorkflowCompiler {
19
23
  constructor() {
20
24
  this.refRegistry = (0, ref_registry_1.createRefRegistry)();
25
+ this.featureRegistry = (0, feature_registry_1.createFeatureRegistry)();
26
+ this.templateRegistry = (0, template_registry_1.createTemplateRegistry)();
21
27
  }
22
28
  compile(workflow) {
23
- const refsResult = (0, resolve_refs_1.resolveRefsPass)(workflow.definition.steps, this.refRegistry);
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);
24
46
  if (refsResult.isErr()) {
25
47
  const e = refsResult.error;
26
48
  return (0, neverthrow_1.err)(error_1.Err.invalidState(`Step '${e.stepId}': ref resolution error — ${e.cause.message}`));
@@ -1,6 +1,14 @@
1
1
  {
2
2
  "distDir": "dist",
3
3
  "files": {
4
+ "application/services/compiler/feature-registry.d.ts": {
5
+ "sha256": "0df999218ba4dac5cf3fad34f3291e2b217b662badef01ee20f1258c4d03d13f",
6
+ "bytes": 740
7
+ },
8
+ "application/services/compiler/feature-registry.js": {
9
+ "sha256": "0350c0bd6ab92b1f38f58d12e2d2064af4275b34dfabf7e1677df9eb284d8ba4",
10
+ "bytes": 1124
11
+ },
4
12
  "application/services/compiler/prompt-blocks.d.ts": {
5
13
  "sha256": "2f40fd7599bd351584505152e9916fdea60891833d22c774c8ac9955f01ccf66",
6
14
  "bytes": 1416
@@ -17,6 +25,14 @@
17
25
  "sha256": "075b14ab0efd34df85eb9b564362d2415eacffc13f44f1ba54bdc5e8229a7d2e",
18
26
  "bytes": 2008
19
27
  },
28
+ "application/services/compiler/resolve-features.d.ts": {
29
+ "sha256": "bb5d0719f1156fe5fc92464bc828407b7be1b1149e79e70e71669cf54dce4ddc",
30
+ "bytes": 733
31
+ },
32
+ "application/services/compiler/resolve-features.js": {
33
+ "sha256": "04637806407d1888b8b0d78ee05a92eb08c9bb33f695a3db4ad6373e5666831a",
34
+ "bytes": 2444
35
+ },
20
36
  "application/services/compiler/resolve-refs.d.ts": {
21
37
  "sha256": "64ed63007495f8b95baeb5f867a6b6ac39f097ad5976803b2642defa80ed31bf",
22
38
  "bytes": 581
@@ -25,6 +41,22 @@
25
41
  "sha256": "9f9e2a44cec6dfd6d870a645b38e4faf52e17c9ef3654fd600ebcd9943f532c5",
26
42
  "bytes": 4214
27
43
  },
44
+ "application/services/compiler/resolve-templates.d.ts": {
45
+ "sha256": "623e4b9e7b65c1cbe8a6acee232ba3fa7b11c9394f22a77c7443a02681b0a0a8",
46
+ "bytes": 767
47
+ },
48
+ "application/services/compiler/resolve-templates.js": {
49
+ "sha256": "2d7bef8627cd933fa265d9faf9b0d6ced860bd66b39793af7ffa97956ba38a09",
50
+ "bytes": 1997
51
+ },
52
+ "application/services/compiler/template-registry.d.ts": {
53
+ "sha256": "16221e2671a95456abfd875fc7caceb40058f351a5a371e13acf53def2f77b24",
54
+ "bytes": 873
55
+ },
56
+ "application/services/compiler/template-registry.js": {
57
+ "sha256": "79ea2925e1d4a003a0b07a5f4c99cdc5fb8aa73e0b2be4e239435bf7bf1ffb13",
58
+ "bytes": 972
59
+ },
28
60
  "application/services/enhanced-error-service.d.ts": {
29
61
  "sha256": "b6fe8fad92717f0962f87aa9c0f88277bf28fe2b5e3cfd7875612ee57eb8c684",
30
62
  "bytes": 601
@@ -66,12 +98,12 @@
66
98
  "bytes": 31038
67
99
  },
68
100
  "application/services/workflow-compiler.d.ts": {
69
- "sha256": "65d65befc721926c125836692a0982f3cdef57f429326cde1b48e2fbc8593c98",
70
- "bytes": 1024
101
+ "sha256": "d1371ca551a908a7f95078d20e02203d7b24525659d9160d50b06fd2708ca4a9",
102
+ "bytes": 1101
71
103
  },
72
104
  "application/services/workflow-compiler.js": {
73
- "sha256": "7d03802161c8802553122be3132efb77dc42214f232d333df73230012a7ff9b5",
74
- "bytes": 6581
105
+ "sha256": "4fad72793de969fce4f269d154fc5743a329fc1e015e63b3c6e6ba12bcdeafc7",
106
+ "bytes": 8017
75
107
  },
76
108
  "application/services/workflow-interpreter.d.ts": {
77
109
  "sha256": "56b5b5ad06d42096deba9f0abe7642c18a355a1e598749aab1730df4e9847674",
@@ -1082,8 +1114,8 @@
1082
1114
  "bytes": 395
1083
1115
  },
1084
1116
  "types/workflow-definition.d.ts": {
1085
- "sha256": "cb7d6be7e9aa0d4b7b17323cd167edad2f616b6a8c2149df6c40e4d965e7d9b8",
1086
- "bytes": 3744
1117
+ "sha256": "13681513404db7396b07ded2c72fac53a9e42a76e5016c34f0fc77fc6591aa5a",
1118
+ "bytes": 3951
1087
1119
  },
1088
1120
  "types/workflow-definition.js": {
1089
1121
  "sha256": "e269d62f27b7f37f870183d6b77800b7aa1e22dabc894374bab8f34db049a55b",
@@ -18,10 +18,15 @@ export interface WorkflowStepDefinition {
18
18
  readonly validationCriteria?: ValidationCriteria;
19
19
  readonly outputContract?: OutputContract;
20
20
  readonly notesOptional?: boolean;
21
+ readonly templateCall?: TemplateCall;
21
22
  readonly functionDefinitions?: readonly FunctionDefinition[];
22
23
  readonly functionCalls?: readonly FunctionCall[];
23
24
  readonly functionReferences?: readonly string[];
24
25
  }
26
+ export interface TemplateCall {
27
+ readonly templateId: string;
28
+ readonly args?: Readonly<Record<string, unknown>>;
29
+ }
25
30
  export interface LoopStepDefinition extends WorkflowStepDefinition {
26
31
  readonly type: 'loop';
27
32
  readonly loop: LoopConfigDefinition;
@@ -79,6 +84,7 @@ export interface WorkflowDefinition {
79
84
  readonly metaGuidance?: readonly string[];
80
85
  readonly functionDefinitions?: readonly FunctionDefinition[];
81
86
  readonly recommendedPreferences?: WorkflowRecommendedPreferences;
87
+ readonly features?: readonly string[];
82
88
  }
83
89
  export declare function isLoopStepDefinition(step: WorkflowStepDefinition | LoopStepDefinition): step is LoopStepDefinition;
84
90
  export declare function isWorkflowStepDefinition(step: WorkflowStepDefinition | LoopStepDefinition): step is WorkflowStepDefinition;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exaudeus/workrail",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "Step-by-step workflow enforcement for AI agents via MCP",
5
5
  "license": "MIT",
6
6
  "repository": {