@exaudeus/workrail 1.8.0 → 1.9.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,12 @@
1
+ import type { Result } from 'neverthrow';
2
+ export type RefResolveError = {
3
+ readonly code: 'UNKNOWN_REF';
4
+ readonly refId: string;
5
+ readonly message: string;
6
+ };
7
+ export interface RefRegistry {
8
+ readonly resolve: (refId: string) => Result<string, RefResolveError>;
9
+ readonly has: (refId: string) => boolean;
10
+ readonly knownIds: () => readonly string[];
11
+ }
12
+ export declare function createRefRegistry(): RefRegistry;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRefRegistry = createRefRegistry;
4
+ const neverthrow_1 = require("neverthrow");
5
+ const REF_CONTENT = {
6
+ 'wr.refs.memory_usage': [
7
+ 'If Memory MCP tools are available (memory_briefing, memory_store, memory_query):',
8
+ '- Query Memory for relevant prior knowledge about this workspace before beginning work',
9
+ '- After completing significant work, store key discoveries and decisions',
10
+ '- Use descriptive topics and titles so future sessions can find them',
11
+ '- Do not block on Memory failures — it is advisory, not load-bearing',
12
+ ].join('\n'),
13
+ 'wr.refs.memory_store': [
14
+ 'If Memory MCP tools are available (memory_store):',
15
+ '- Store the key findings from this phase with a descriptive topic and title',
16
+ '- Include file paths, decisions made, and rationale',
17
+ '- Do not block on Memory failures — continue regardless',
18
+ ].join('\n'),
19
+ 'wr.refs.memory_query': [
20
+ 'If Memory MCP tools are available (memory_briefing, memory_query):',
21
+ '- Check Memory for prior context relevant to this task',
22
+ '- Use workspace-scoped queries to find related past work',
23
+ '- Do not block on Memory failures — proceed without prior context if unavailable',
24
+ ].join('\n'),
25
+ };
26
+ function createRefRegistry() {
27
+ const knownIds = Object.keys(REF_CONTENT);
28
+ return {
29
+ resolve(refId) {
30
+ const content = REF_CONTENT[refId];
31
+ if (content === undefined) {
32
+ return (0, neverthrow_1.err)({
33
+ code: 'UNKNOWN_REF',
34
+ refId,
35
+ message: `Unknown ref '${refId}'. Known refs: ${knownIds.join(', ')}`,
36
+ });
37
+ }
38
+ return (0, neverthrow_1.ok)(content);
39
+ },
40
+ has(refId) {
41
+ return refId in REF_CONTENT;
42
+ },
43
+ knownIds() {
44
+ return knownIds;
45
+ },
46
+ };
47
+ }
@@ -0,0 +1,9 @@
1
+ import type { Result } from 'neverthrow';
2
+ import type { RefRegistry, RefResolveError } from './ref-registry.js';
3
+ import type { WorkflowStepDefinition, LoopStepDefinition } from '../../../types/workflow-definition.js';
4
+ export type ResolveRefsPassError = {
5
+ readonly code: 'REF_RESOLVE_ERROR';
6
+ readonly stepId: string;
7
+ readonly cause: RefResolveError;
8
+ };
9
+ export declare function resolveRefsPass(steps: readonly (WorkflowStepDefinition | LoopStepDefinition)[], registry: RefRegistry): Result<readonly (WorkflowStepDefinition | LoopStepDefinition)[], ResolveRefsPassError>;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveRefsPass = resolveRefsPass;
4
+ const neverthrow_1 = require("neverthrow");
5
+ const workflow_definition_js_1 = require("../../../types/workflow-definition.js");
6
+ function resolvePromptValueRefs(value, registry) {
7
+ if (typeof value === 'string')
8
+ return (0, neverthrow_1.ok)(value);
9
+ const resolved = [];
10
+ for (const part of value) {
11
+ switch (part.kind) {
12
+ case 'text':
13
+ resolved.push(part);
14
+ break;
15
+ case 'ref': {
16
+ const res = registry.resolve(part.refId);
17
+ if (res.isErr())
18
+ return (0, neverthrow_1.err)(res.error);
19
+ resolved.push({ kind: 'text', text: res.value });
20
+ break;
21
+ }
22
+ }
23
+ }
24
+ return (0, neverthrow_1.ok)(resolved);
25
+ }
26
+ function resolvePromptValuesRefs(values, registry) {
27
+ const resolved = [];
28
+ for (const value of values) {
29
+ const res = resolvePromptValueRefs(value, registry);
30
+ if (res.isErr())
31
+ return (0, neverthrow_1.err)(res.error);
32
+ resolved.push(res.value);
33
+ }
34
+ return (0, neverthrow_1.ok)(resolved);
35
+ }
36
+ function resolveBlockRefs(blocks, registry) {
37
+ let result = { ...blocks };
38
+ if (blocks.goal !== undefined) {
39
+ const res = resolvePromptValueRefs(blocks.goal, registry);
40
+ if (res.isErr())
41
+ return (0, neverthrow_1.err)(res.error);
42
+ result = { ...result, goal: res.value };
43
+ }
44
+ if (blocks.constraints !== undefined) {
45
+ const res = resolvePromptValuesRefs(blocks.constraints, registry);
46
+ if (res.isErr())
47
+ return (0, neverthrow_1.err)(res.error);
48
+ result = { ...result, constraints: res.value };
49
+ }
50
+ if (blocks.procedure !== undefined) {
51
+ const res = resolvePromptValuesRefs(blocks.procedure, registry);
52
+ if (res.isErr())
53
+ return (0, neverthrow_1.err)(res.error);
54
+ result = { ...result, procedure: res.value };
55
+ }
56
+ if (blocks.verify !== undefined) {
57
+ const res = resolvePromptValuesRefs(blocks.verify, registry);
58
+ if (res.isErr())
59
+ return (0, neverthrow_1.err)(res.error);
60
+ result = { ...result, verify: res.value };
61
+ }
62
+ return (0, neverthrow_1.ok)(result);
63
+ }
64
+ function resolveStepRefs(step, registry) {
65
+ if (!step.promptBlocks)
66
+ return (0, neverthrow_1.ok)(step);
67
+ const res = resolveBlockRefs(step.promptBlocks, registry);
68
+ if (res.isErr()) {
69
+ return (0, neverthrow_1.err)({
70
+ code: 'REF_RESOLVE_ERROR',
71
+ stepId: step.id,
72
+ cause: res.error,
73
+ });
74
+ }
75
+ return (0, neverthrow_1.ok)({ ...step, promptBlocks: res.value });
76
+ }
77
+ function resolveRefsPass(steps, registry) {
78
+ const resolved = [];
79
+ for (const step of steps) {
80
+ if ((0, workflow_definition_js_1.isLoopStepDefinition)(step)) {
81
+ const loopRes = resolveStepRefs(step, registry);
82
+ if (loopRes.isErr())
83
+ return (0, neverthrow_1.err)(loopRes.error);
84
+ if (Array.isArray(step.body)) {
85
+ const bodyResolved = [];
86
+ for (const bodyStep of step.body) {
87
+ const bodyRes = resolveStepRefs(bodyStep, registry);
88
+ if (bodyRes.isErr())
89
+ return (0, neverthrow_1.err)(bodyRes.error);
90
+ bodyResolved.push(bodyRes.value);
91
+ }
92
+ resolved.push({
93
+ ...step,
94
+ ...(loopRes.value.promptBlocks ? { promptBlocks: loopRes.value.promptBlocks } : {}),
95
+ body: bodyResolved,
96
+ });
97
+ }
98
+ else {
99
+ resolved.push({
100
+ ...step,
101
+ ...(loopRes.value.promptBlocks ? { promptBlocks: loopRes.value.promptBlocks } : {}),
102
+ });
103
+ }
104
+ }
105
+ else {
106
+ const res = resolveStepRefs(step, registry);
107
+ if (res.isErr())
108
+ return (0, neverthrow_1.err)(res.error);
109
+ resolved.push(res.value);
110
+ }
111
+ }
112
+ return (0, neverthrow_1.ok)(resolved);
113
+ }
@@ -15,6 +15,7 @@ export interface CompiledWorkflow {
15
15
  readonly loopBodyStepIds: ReadonlySet<string>;
16
16
  }
17
17
  export declare class WorkflowCompiler {
18
+ private readonly refRegistry;
18
19
  compile(workflow: Workflow): Result<CompiledWorkflow, DomainError>;
19
20
  private deriveConditionSource;
20
21
  private resolveLoopBody;
@@ -13,9 +13,19 @@ const index_1 = require("../../v2/durable-core/schemas/artifacts/index");
13
13
  const neverthrow_1 = require("neverthrow");
14
14
  const error_1 = require("../../domain/execution/error");
15
15
  const prompt_blocks_1 = require("./compiler/prompt-blocks");
16
+ const resolve_refs_1 = require("./compiler/resolve-refs");
17
+ const ref_registry_1 = require("./compiler/ref-registry");
16
18
  let WorkflowCompiler = class WorkflowCompiler {
19
+ constructor() {
20
+ this.refRegistry = (0, ref_registry_1.createRefRegistry)();
21
+ }
17
22
  compile(workflow) {
18
- const blocksResult = (0, prompt_blocks_1.resolvePromptBlocksPass)(workflow.definition.steps);
23
+ const refsResult = (0, resolve_refs_1.resolveRefsPass)(workflow.definition.steps, this.refRegistry);
24
+ if (refsResult.isErr()) {
25
+ const e = refsResult.error;
26
+ return (0, neverthrow_1.err)(error_1.Err.invalidState(`Step '${e.stepId}': ref resolution error — ${e.cause.message}`));
27
+ }
28
+ const blocksResult = (0, prompt_blocks_1.resolvePromptBlocksPass)(refsResult.value);
19
29
  if (blocksResult.isErr()) {
20
30
  const e = blocksResult.error;
21
31
  const message = e.code === 'PROMPT_AND_BLOCKS_BOTH_SET'
@@ -9,6 +9,22 @@
9
9
  "sha256": "8ee0e8f7f23f0b298602b97af71a49eaf4fbdc8e7a2bb588c607c2f36e81ef1a",
10
10
  "bytes": 5201
11
11
  },
12
+ "application/services/compiler/ref-registry.d.ts": {
13
+ "sha256": "b93074634a3a26097b9ed35d72351272c567dff184401a95e9f80ea7ae8724a5",
14
+ "bytes": 428
15
+ },
16
+ "application/services/compiler/ref-registry.js": {
17
+ "sha256": "075b14ab0efd34df85eb9b564362d2415eacffc13f44f1ba54bdc5e8229a7d2e",
18
+ "bytes": 2008
19
+ },
20
+ "application/services/compiler/resolve-refs.d.ts": {
21
+ "sha256": "64ed63007495f8b95baeb5f867a6b6ac39f097ad5976803b2642defa80ed31bf",
22
+ "bytes": 581
23
+ },
24
+ "application/services/compiler/resolve-refs.js": {
25
+ "sha256": "9f9e2a44cec6dfd6d870a645b38e4faf52e17c9ef3654fd600ebcd9943f532c5",
26
+ "bytes": 4214
27
+ },
12
28
  "application/services/enhanced-error-service.d.ts": {
13
29
  "sha256": "b6fe8fad92717f0962f87aa9c0f88277bf28fe2b5e3cfd7875612ee57eb8c684",
14
30
  "bytes": 601
@@ -50,12 +66,12 @@
50
66
  "bytes": 31038
51
67
  },
52
68
  "application/services/workflow-compiler.d.ts": {
53
- "sha256": "dc7b1ed75ee4e90f90c35088d5c336a94d782012e5926fd7c939613e483b23fc",
54
- "bytes": 990
69
+ "sha256": "65d65befc721926c125836692a0982f3cdef57f429326cde1b48e2fbc8593c98",
70
+ "bytes": 1024
55
71
  },
56
72
  "application/services/workflow-compiler.js": {
57
- "sha256": "e4b8c0966ba04a87d753ca507fdc2ee5082a66e4fb6d539e4782c8ff8e93ef78",
58
- "bytes": 6050
73
+ "sha256": "7d03802161c8802553122be3132efb77dc42214f232d333df73230012a7ff9b5",
74
+ "bytes": 6581
59
75
  },
60
76
  "application/services/workflow-interpreter.d.ts": {
61
77
  "sha256": "56b5b5ad06d42096deba9f0abe7642c18a355a1e598749aab1730df4e9847674",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exaudeus/workrail",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Step-by-step workflow enforcement for AI agents via MCP",
5
5
  "license": "MIT",
6
6
  "repository": {