@exaudeus/workrail 1.13.0 → 1.13.2

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.
@@ -13,6 +13,7 @@ export declare class EnhancedLoopValidator {
13
13
  validateLoopStep(step: LoopStepDefinition): EnhancedValidationResult;
14
14
  private getLoopBodySteps;
15
15
  private validateConditionalLogic;
16
+ private getPromptText;
16
17
  private validatePromptLength;
17
18
  private validateTemplateVariables;
18
19
  private getKnownLoopVariables;
@@ -55,10 +55,40 @@ let EnhancedLoopValidator = class EnhancedLoopValidator {
55
55
  }
56
56
  }
57
57
  }
58
+ getPromptText(step) {
59
+ if (step.prompt)
60
+ return step.prompt;
61
+ if (!step.promptBlocks)
62
+ return undefined;
63
+ const parts = [];
64
+ const b = step.promptBlocks;
65
+ if (typeof b.goal === 'string')
66
+ parts.push(b.goal);
67
+ if (Array.isArray(b.constraints)) {
68
+ for (const c of b.constraints) {
69
+ if (typeof c === 'string')
70
+ parts.push(c);
71
+ }
72
+ }
73
+ if (Array.isArray(b.procedure)) {
74
+ for (const p of b.procedure) {
75
+ if (typeof p === 'string')
76
+ parts.push(p);
77
+ }
78
+ }
79
+ if (Array.isArray(b.verify)) {
80
+ for (const v of b.verify) {
81
+ if (typeof v === 'string')
82
+ parts.push(v);
83
+ }
84
+ }
85
+ return parts.length > 0 ? parts.join('\n') : undefined;
86
+ }
58
87
  validatePromptLength(step, warnings, suggestions) {
59
- if (!step.prompt)
88
+ const promptText = this.getPromptText(step);
89
+ if (!promptText)
60
90
  return;
61
- const promptLength = step.prompt.length;
91
+ const promptLength = promptText.length;
62
92
  if (promptLength > this.PROMPT_ERROR_THRESHOLD) {
63
93
  warnings.push(`Step '${step.id}' has a very long prompt (${promptLength} characters). This may cause issues.`);
64
94
  suggestions.push(`Consider splitting this into multiple steps or moving content to the guidance section.`);
@@ -67,7 +97,7 @@ let EnhancedLoopValidator = class EnhancedLoopValidator {
67
97
  warnings.push(`Step '${step.id}' has a long prompt (${promptLength} characters).`);
68
98
  suggestions.push(`For better maintainability, consider breaking this into smaller, focused steps.`);
69
99
  }
70
- const conditionalMatches = step.prompt.match(/\{\{[^}]*\?[^}]*\}\}/g);
100
+ const conditionalMatches = step.prompt?.match(/\{\{[^}]*\?[^}]*\}\}/g);
71
101
  if (conditionalMatches) {
72
102
  let totalConditionalContent = 0;
73
103
  for (const match of conditionalMatches) {
@@ -115,15 +145,16 @@ let EnhancedLoopValidator = class EnhancedLoopValidator {
115
145
  const bodySteps = this.getLoopBodySteps(step);
116
146
  if (step.loop.type === 'for' && bodySteps.length > 0) {
117
147
  const firstStep = bodySteps[0];
118
- if (firstStep.prompt?.includes('analysis') ||
148
+ const firstPrompt = this.getPromptText(firstStep);
149
+ if (firstPrompt?.includes('analysis') ||
119
150
  firstStep.title?.toLowerCase().includes('analysis') ||
120
- firstStep.prompt?.includes('Step 1') ||
121
- firstStep.prompt?.includes('Structure')) {
151
+ firstPrompt?.includes('Step 1') ||
152
+ firstPrompt?.includes('Structure')) {
122
153
  info.push('Progressive analysis pattern detected.');
123
154
  suggestions.push('Consider using the multi-step pattern with separate steps and runCondition for clearer structure.');
124
155
  }
125
156
  }
126
- if (bodySteps.some(s => s.prompt?.includes('===') && s.prompt?.includes('?'))) {
157
+ if (bodySteps.some(s => { const p = this.getPromptText(s); return p?.includes('===') && p?.includes('?'); })) {
127
158
  info.push('Multi-conditional loop pattern detected.');
128
159
  suggestions.push('For loops with multiple conditional paths, the separate steps pattern is more maintainable than inline conditionals.');
129
160
  }
@@ -413,9 +413,9 @@ let ValidationEngine = ValidationEngine_1 = class ValidationEngine {
413
413
  issues.push(`Inline step '${inlineStep.id || 'unknown'}' must have a title`);
414
414
  suggestions.push('Add a title to all inline steps');
415
415
  }
416
- if (!inlineStep.prompt) {
417
- issues.push(`Inline step '${inlineStep.id || 'unknown'}' must have a prompt`);
418
- suggestions.push('Add a prompt to all inline steps');
416
+ if (!(0, workflow_definition_1.stepHasPromptSource)(inlineStep)) {
417
+ issues.push(`Inline step '${inlineStep.id || 'unknown'}' must have prompt, promptBlocks, or templateCall`);
418
+ suggestions.push('Add a prompt string, structured promptBlocks, or a templateCall to all inline steps');
419
419
  }
420
420
  if ((0, workflow_definition_1.isLoopStepDefinition)(inlineStep)) {
421
421
  issues.push(`Nested loops are not currently supported. Inline step '${inlineStep.id}' is a loop`);
@@ -486,8 +486,9 @@ let ValidationEngine = ValidationEngine_1 = class ValidationEngine {
486
486
  if (!step.title) {
487
487
  issues.push(`Step '${step.id}' missing required title`);
488
488
  }
489
- if (!step.prompt) {
490
- issues.push(`Step '${step.id}' missing required prompt`);
489
+ if (!(0, workflow_definition_1.stepHasPromptSource)(step)) {
490
+ issues.push(`Step '${step.id}' must have prompt, promptBlocks, or templateCall`);
491
+ suggestions.push('Add a prompt string, structured promptBlocks, or a templateCall to each step');
491
492
  }
492
493
  this.collectQuotedJsonValidationMessageWarnings(step, `Step '${step.id}'`, warnings);
493
494
  const callValidation = this.validateStepFunctionCalls(step, workflow.definition.functionDefinitions || []);
@@ -322,13 +322,7 @@ let WorkflowInterpreter = class WorkflowInterpreter {
322
322
  if (result.kind === 'found') {
323
323
  return (0, neverthrow_1.ok)(result.decision === 'continue');
324
324
  }
325
- return (0, neverthrow_1.err)({
326
- code: 'LOOP_MISSING_CONTEXT',
327
- loopId: loopCompiled.loop.id,
328
- message: result.kind === 'not_found'
329
- ? `Loop '${source.loopId}' requires a wr.loop_control artifact but none was provided`
330
- : `Loop '${source.loopId}' has an invalid loop control artifact: ${result.reason}`,
331
- });
325
+ return (0, neverthrow_1.ok)(true);
332
326
  }
333
327
  case 'context_variable': {
334
328
  const raw = (0, condition_evaluator_1.evaluateCondition)(source.condition, this.projectLoopContextAtIteration(loopCompiled.loop, iteration, context));
@@ -67,10 +67,10 @@ function generateSuggestions(errors) {
67
67
  suggestions.push('Use semantic versioning format (e.g., "0.0.1", "1.0.0").');
68
68
  }
69
69
  if (errorText.includes('steps')) {
70
- suggestions.push('Ensure the workflow has at least one step with id, title, and prompt fields.');
70
+ suggestions.push('Ensure the workflow has at least one step with id, title, and either prompt or promptBlocks.');
71
71
  }
72
72
  if (errorText.includes('step')) {
73
- suggestions.push('Check that all steps have required fields: id, title, and prompt.');
73
+ suggestions.push('Check that all steps have required fields: id, title, and either prompt or promptBlocks.');
74
74
  }
75
75
  if (errorText.includes('pattern')) {
76
76
  suggestions.push('Review the workflow schema documentation for correct field formats.');
@@ -66,12 +66,12 @@
66
66
  "bytes": 6252
67
67
  },
68
68
  "application/services/enhanced-loop-validator.d.ts": {
69
- "sha256": "042456f4080212c16acaee730bec5cf3342173f3307f405f85a9dbdaa410797f",
70
- "bytes": 774
69
+ "sha256": "bef909cb861b88beda04b44110f8abb18181bb82be22bfbde5fe819a66654d52",
70
+ "bytes": 801
71
71
  },
72
72
  "application/services/enhanced-loop-validator.js": {
73
- "sha256": "0af041281661c46cee1c63eebe36ee20d12b9fefc1f95e6baed9d959ae012b6a",
74
- "bytes": 7980
73
+ "sha256": "148e75778723842874037c1d0c4fc3ab737787ddb9e3c78c5386cd49abfd065e",
74
+ "bytes": 9020
75
75
  },
76
76
  "application/services/output-normalizer.d.ts": {
77
77
  "sha256": "35bd9e50e984132f83dac874f90c2a4e9e8223202c6832426654232c5d7e2236",
@@ -94,8 +94,8 @@
94
94
  "bytes": 2030
95
95
  },
96
96
  "application/services/validation-engine.js": {
97
- "sha256": "81592794bad1d77b0f8cdf6ed6486a17c6eebc3a4fe9e484693fbb6f8cdc5c96",
98
- "bytes": 31038
97
+ "sha256": "a2ad656656b8d2554d0a08f6e230c190c72939d11cdba329b8de268d9ad52584",
98
+ "bytes": 31342
99
99
  },
100
100
  "application/services/workflow-compiler.d.ts": {
101
101
  "sha256": "41d0643ae2f07e5ce77a6e02344b5ca5b3c26bde828fbb307528a2ae097ac9d5",
@@ -110,8 +110,8 @@
110
110
  "bytes": 1507
111
111
  },
112
112
  "application/services/workflow-interpreter.js": {
113
- "sha256": "0ea1861801d095d27e1e4c7c97978941b9d48613e28ce3a4c2efe64342814f5c",
114
- "bytes": 21402
113
+ "sha256": "e6ea1bc6f3881bc46a901b78720dee584090f86809bfa1979f04efa4c8a35613",
114
+ "bytes": 21011
115
115
  },
116
116
  "application/services/workflow-service.d.ts": {
117
117
  "sha256": "b92da17c6d91c90758ec42b4ee3bc448e5d5b1dfe7351f2fe0f5e1d10a715ec6",
@@ -166,8 +166,8 @@
166
166
  "bytes": 345
167
167
  },
168
168
  "application/use-cases/validate-workflow-json.js": {
169
- "sha256": "e5f0bfe7dfd8118a23f0690578159e8e591452a5635d77d5d0244685da07b9c2",
170
- "bytes": 3651
169
+ "sha256": "87caff4501c5ee59ce73fc37762eeedc1e00253c7bf7f432349288e07810293f",
170
+ "bytes": 3690
171
171
  },
172
172
  "application/validation.d.ts": {
173
173
  "sha256": "2b44ccd1db66c81d8d5306e4b3453b50c27bb5c2c4bec85191b325c339d188cc",
@@ -646,8 +646,8 @@
646
646
  "bytes": 936
647
647
  },
648
648
  "mcp/handlers/v2-advance-core/outcome-success.js": {
649
- "sha256": "e08268f3b8fd11213e67052721e231a6e055daa1dd4f729784f6ed3b20ddddb4",
650
- "bytes": 5961
649
+ "sha256": "b0e2f52b8843b067b1ca1c3aa6e797d3b6ad7bf175c46b1f036e70fc2174f992",
650
+ "bytes": 6129
651
651
  },
652
652
  "mcp/handlers/v2-advance-events.d.ts": {
653
653
  "sha256": "02cdb52a2c16dd619645b5496caf0880e57937bf21ea9efe44e6cd195cd43b94",
@@ -674,12 +674,12 @@
674
674
  "bytes": 7199
675
675
  },
676
676
  "mcp/handlers/v2-error-mapping.d.ts": {
677
- "sha256": "bbaf580dfc22ca6b5ef1d57036fb549c640d6f37bd7d525f1a805b4d14c4d75c",
678
- "bytes": 1711
677
+ "sha256": "1cf58654dd6f70a0e35b75435c835a410658a2c7220d1b86561124476c8742fa",
678
+ "bytes": 1798
679
679
  },
680
680
  "mcp/handlers/v2-error-mapping.js": {
681
- "sha256": "95dff130804524a007e1071784c20897ba6af1cc04fb2a636741e261fa22c3f8",
682
- "bytes": 10388
681
+ "sha256": "f63c6711fdd05cf89d7da5f1441a17efa540b2f4985f85759c7f740a6cf2e854",
682
+ "bytes": 10664
683
683
  },
684
684
  "mcp/handlers/v2-execution-helpers.d.ts": {
685
685
  "sha256": "1e52f266e991a9447d1254bf047f6a09062b038ed3363a3818d1f5c91eed2fc8",
@@ -710,8 +710,8 @@
710
710
  "bytes": 1830
711
711
  },
712
712
  "mcp/handlers/v2-execution/continue-advance.js": {
713
- "sha256": "bfbc14690fe08f51c5e1e2124e5561e9a093806e511803d68e4a2d22b5918919",
714
- "bytes": 7927
713
+ "sha256": "864b892e6e69afbe300dbc748d0b6f3476d299b5cbaea36b5197748f9972611b",
714
+ "bytes": 8332
715
715
  },
716
716
  "mcp/handlers/v2-execution/continue-rehydrate.d.ts": {
717
717
  "sha256": "af7475b7effe57f18fa8379bfd128d17afb2d27fe1c058c6f2ee8f5b2632e3d0",
@@ -790,8 +790,8 @@
790
790
  "bytes": 1748
791
791
  },
792
792
  "mcp/handlers/workflow.js": {
793
- "sha256": "a813ad7b201475a4362560b2ae2fbdc679ff416a92a4a5ab5dded4350e692daa",
794
- "bytes": 8068
793
+ "sha256": "c95bbef83298b7d518e5e587147bdf83546bba77d3ef026c3598e8b0c6168004",
794
+ "bytes": 8233
795
795
  },
796
796
  "mcp/index.d.ts": {
797
797
  "sha256": "525b4247cf90ba3af66769462bcfaab5dbf38ee8c49d2a9ceec1e4b38e33511b",
@@ -1114,12 +1114,12 @@
1114
1114
  "bytes": 395
1115
1115
  },
1116
1116
  "types/workflow-definition.d.ts": {
1117
- "sha256": "13681513404db7396b07ded2c72fac53a9e42a76e5016c34f0fc77fc6591aa5a",
1118
- "bytes": 3951
1117
+ "sha256": "19c5588e038d0d703def5ad59809bd9f7bbf4402999e56e664725cfeb9a0e18c",
1118
+ "bytes": 4035
1119
1119
  },
1120
1120
  "types/workflow-definition.js": {
1121
- "sha256": "e269d62f27b7f37f870183d6b77800b7aa1e22dabc894374bab8f34db049a55b",
1122
- "bytes": 1584
1121
+ "sha256": "293e18cc856c8b0f4d48858873c5832f7b9d2dc3896256bf19e59c92a222056d",
1122
+ "bytes": 1749
1123
1123
  },
1124
1124
  "types/workflow-source.d.ts": {
1125
1125
  "sha256": "ee439c36ac3002780837ff393120d08a1c21ef2641421cdf72f0e1449d0211eb",
@@ -1542,8 +1542,8 @@
1542
1542
  "bytes": 2743
1543
1543
  },
1544
1544
  "v2/durable-core/schemas/artifacts/loop-control.js": {
1545
- "sha256": "9d8277a83fb4c6e2e07019feab437853c2eccd94b7e6958eda6500fb064d5f6e",
1546
- "bytes": 2099
1545
+ "sha256": "1e0b70991023554e0ea3c858517aee7ffd050ab695a2f31768c4ec3d8de1cf92",
1546
+ "bytes": 2152
1547
1547
  },
1548
1548
  "v2/durable-core/schemas/compiled-workflow/index.d.ts": {
1549
1549
  "sha256": "d909c13d0d46bba1dcd411a0c53e767cf7e4c8bc5206581344ca1e7315552d95",
@@ -1802,20 +1802,20 @@
1802
1802
  "bytes": 3036
1803
1803
  },
1804
1804
  "v2/infra/local/directory-listing/index.d.ts": {
1805
- "sha256": "dbf0a610bf4871eec89cc39f218ebb5267c695ccd8524613868abf5aa79d8d4a",
1806
- "bytes": 447
1805
+ "sha256": "3139014cb738db3b0f10beca01a3a4a35b9ab8e72c8889b3bbff204fdbcb6b6c",
1806
+ "bytes": 557
1807
1807
  },
1808
1808
  "v2/infra/local/directory-listing/index.js": {
1809
- "sha256": "1930cb982b9034f46751a000011ea069b6e03becd898973afad4b74e6ebc1759",
1810
- "bytes": 566
1809
+ "sha256": "f3ed94836fa657dc34692378635efa12a5446e5f63c07637b3476a872e5064b1",
1810
+ "bytes": 844
1811
1811
  },
1812
1812
  "v2/infra/local/fs/index.d.ts": {
1813
- "sha256": "fe3f06badea2d62e9ade3954f716d0b7aa4778c4d49e5fb9f6f58db6d2e9429a",
1814
- "bytes": 1323
1813
+ "sha256": "dcfe3510dc6a8d92ededdb9c1376702dc88455ccb189eb7dc3ba2721b6b43d38",
1814
+ "bytes": 1437
1815
1815
  },
1816
1816
  "v2/infra/local/fs/index.js": {
1817
- "sha256": "05fcd1345b3f003c19a13ee8db4ef657f23815c253e4fa36fa4bd7092f0a0b68",
1818
- "bytes": 7179
1817
+ "sha256": "6d898cf90fd022530fb4ee4c03e0127955895d9da0f4ef52d85d8843803466df",
1818
+ "bytes": 8262
1819
1819
  },
1820
1820
  "v2/infra/local/hmac-sha256/index.d.ts": {
1821
1821
  "sha256": "dda3865510dfaf2f13947410d998da6ffecc9a2e728b3574f81e69d5db859815",
@@ -1878,8 +1878,8 @@
1878
1878
  "bytes": 1004
1879
1879
  },
1880
1880
  "v2/infra/local/session-summary-provider/index.js": {
1881
- "sha256": "a38c877faddb8e14bf1c30e173e4299af5edb4a1f8fb4b036732c6ba6f11ca6f",
1882
- "bytes": 5933
1881
+ "sha256": "1d8a543361c582f6e089f63f24318ff7caf97a78659ecdc5b89152b78d18c6aa",
1882
+ "bytes": 5942
1883
1883
  },
1884
1884
  "v2/infra/local/sha256/index.d.ts": {
1885
1885
  "sha256": "8a727b7e54a38275ca6f9f1b8730f97cfc0a212df035df1bdc58e716e6824230",
@@ -1954,16 +1954,16 @@
1954
1954
  "bytes": 77
1955
1955
  },
1956
1956
  "v2/ports/directory-listing.port.d.ts": {
1957
- "sha256": "3184229b7793bbd3100611c6308d33a96145c4dc63ba451d8c29ff507084e7b4",
1958
- "bytes": 207
1957
+ "sha256": "d707e849df351d2cf619942771b68dfeaa14095618ed3f3109e71da4d5f8d0fa",
1958
+ "bytes": 394
1959
1959
  },
1960
1960
  "v2/ports/directory-listing.port.js": {
1961
1961
  "sha256": "d43aa81f5bc89faa359e0f97c814ba25155591ff078fbb9bfd40f8c7c9683230",
1962
1962
  "bytes": 77
1963
1963
  },
1964
1964
  "v2/ports/fs.port.d.ts": {
1965
- "sha256": "7b0d36b7a1abbf6f3f7279a122fe623bfa5d8b18f9a600c191d536c0e93204f7",
1966
- "bytes": 1991
1965
+ "sha256": "49b481e09333784c5bbb95293a0cc1833ed5fe498aa3a52e86fad076fefe08d9",
1966
+ "bytes": 2182
1967
1967
  },
1968
1968
  "v2/ports/fs.port.js": {
1969
1969
  "sha256": "d43aa81f5bc89faa359e0f97c814ba25155591ff078fbb9bfd40f8c7c9683230",
@@ -2178,12 +2178,12 @@
2178
2178
  "bytes": 2678
2179
2179
  },
2180
2180
  "v2/usecases/enumerate-sessions.d.ts": {
2181
- "sha256": "6043d64b45360dfc6a15b822d9f013a0832127596706bf81569dfce256236d2d",
2182
- "bytes": 499
2181
+ "sha256": "46da8960bdeb154f79dee443425260f3ce18c50a0db01e7ab60700432d864857",
2182
+ "bytes": 699
2183
2183
  },
2184
2184
  "v2/usecases/enumerate-sessions.js": {
2185
- "sha256": "99e135a7c7411ce850c9dd89963ef6a05d3488078d6c6b2c540cb2d2043a2e89",
2186
- "bytes": 526
2185
+ "sha256": "4ae73f47c1e8ebea0d9a48dc786e5e4d0442a38827c427378712e9d198410ae2",
2186
+ "bytes": 1050
2187
2187
  },
2188
2188
  "v2/usecases/execution-session-gate.d.ts": {
2189
2189
  "sha256": "339c4a8e02a77416e725e063a57d39a20788244498ae2c7a31dc48d111af6280",
@@ -44,6 +44,9 @@ function buildSuccessOutcome(args) {
44
44
  });
45
45
  const nextRes = interpreter.next(compiledWf.value, advanced.value, v.mergedContext, artifactsForEval);
46
46
  if (nextRes.isErr()) {
47
+ if (nextRes.error._tag === 'MissingContext') {
48
+ return errAsync({ kind: 'advance_next_missing_context', message: nextRes.error.message });
49
+ }
47
50
  return errAsync({ kind: 'advance_next_failed', message: nextRes.error.message });
48
51
  }
49
52
  const out = nextRes.value;
@@ -12,6 +12,9 @@ export type InternalError = {
12
12
  } | {
13
13
  readonly kind: 'advance_next_failed';
14
14
  readonly message: string;
15
+ } | {
16
+ readonly kind: 'advance_next_missing_context';
17
+ readonly message: string;
15
18
  } | {
16
19
  readonly kind: 'missing_node_or_run';
17
20
  } | {
@@ -122,6 +122,8 @@ function mapInternalErrorToToolError(e) {
122
122
  return internalError('WorkRail could not record the workflow advancement. This is not caused by your input.', (0, v2_execution_helpers_js_1.internalSuggestion)('Retry the call.', 'WorkRail could not record the advancement.'));
123
123
  case 'advance_next_failed':
124
124
  return internalError('WorkRail could not compute the next workflow step. This is not caused by your input.', (0, v2_execution_helpers_js_1.internalSuggestion)('Retry the call.', 'WorkRail could not compute the next step.'));
125
+ case 'advance_next_missing_context':
126
+ return (0, types_js_1.errNotRetryable)('PRECONDITION_FAILED', e.message, { suggestion: 'Set the required context variable in the `context` field of your continue_workflow output. The variable must be a JSON array.' });
125
127
  default:
126
128
  const _exhaustive = e;
127
129
  return internalError('WorkRail encountered an unexpected error. This is not caused by your input.', (0, v2_execution_helpers_js_1.internalSuggestion)('Retry the call.', 'WorkRail has an internal error.'));
@@ -120,6 +120,13 @@ function handleAdvanceIntent(args) {
120
120
  }))
121
121
  .mapErr((cause) => {
122
122
  if ((0, v2_error_mapping_js_1.isInternalError)(cause)) {
123
+ if (cause.kind === 'advance_next_missing_context') {
124
+ return {
125
+ kind: 'precondition_failed',
126
+ message: cause.message,
127
+ suggestion: 'Set the required context variable in the `context` field of your continue_workflow output. The variable must be a JSON array.',
128
+ };
129
+ }
123
130
  return {
124
131
  kind: 'invariant_violation',
125
132
  message: `Advance failed due to internal error: ${cause.kind}`,
@@ -153,8 +153,9 @@ async function handleWorkflowGetSchema(_input, ctx) {
153
153
  stepStructure: {
154
154
  id: 'string (required): Unique step identifier',
155
155
  title: 'string (required): Human-readable step title',
156
- prompt: 'string (required): Instructions for the step',
157
- agentRole: 'string (required): Role description for the agent',
156
+ prompt: 'string (optional): Instructions for the step (use prompt OR promptBlocks)',
157
+ promptBlocks: 'object (optional): Structured prompt blocks (goal, constraints, procedure, outputRequired, verify)',
158
+ agentRole: 'string (optional): Role description for the agent',
158
159
  validationCriteria: 'array (optional): Validation rules for step output',
159
160
  },
160
161
  },
@@ -88,5 +88,6 @@ export interface WorkflowDefinition {
88
88
  }
89
89
  export declare function isLoopStepDefinition(step: WorkflowStepDefinition | LoopStepDefinition): step is LoopStepDefinition;
90
90
  export declare function isWorkflowStepDefinition(step: WorkflowStepDefinition | LoopStepDefinition): step is WorkflowStepDefinition;
91
+ export declare function stepHasPromptSource(step: WorkflowStepDefinition): boolean;
91
92
  export declare function hasWorkflowDefinitionShape(obj: unknown): obj is WorkflowDefinition;
92
93
  export declare function createWorkflowDefinition(definition: WorkflowDefinition): WorkflowDefinition;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLoopStepDefinition = isLoopStepDefinition;
4
4
  exports.isWorkflowStepDefinition = isWorkflowStepDefinition;
5
+ exports.stepHasPromptSource = stepHasPromptSource;
5
6
  exports.hasWorkflowDefinitionShape = hasWorkflowDefinitionShape;
6
7
  exports.createWorkflowDefinition = createWorkflowDefinition;
7
8
  function isLoopStepDefinition(step) {
@@ -10,6 +11,9 @@ function isLoopStepDefinition(step) {
10
11
  function isWorkflowStepDefinition(step) {
11
12
  return !isLoopStepDefinition(step);
12
13
  }
14
+ function stepHasPromptSource(step) {
15
+ return Boolean(step.prompt || step.promptBlocks || step.templateCall);
16
+ }
13
17
  function hasWorkflowDefinitionShape(obj) {
14
18
  if (!obj || typeof obj !== 'object')
15
19
  return false;
@@ -36,7 +36,8 @@ function parseLoopControlArtifact(artifact) {
36
36
  return result.success ? result.data : null;
37
37
  }
38
38
  function findLoopControlArtifact(artifacts, loopId) {
39
- for (const artifact of artifacts) {
39
+ for (let i = artifacts.length - 1; i >= 0; i--) {
40
+ const artifact = artifacts[i];
40
41
  if (!isLoopControlArtifact(artifact))
41
42
  continue;
42
43
  const parsed = parseLoopControlArtifact(artifact);
@@ -1,8 +1,9 @@
1
1
  import type { ResultAsync } from 'neverthrow';
2
2
  import type { FsError, DirectoryListingOpsPortV2 } from '../../../ports/fs.port.js';
3
- import type { DirectoryListingPortV2 } from '../../../ports/directory-listing.port.js';
3
+ import type { DirectoryListingPortV2, DirEntryWithMtime } from '../../../ports/directory-listing.port.js';
4
4
  export declare class LocalDirectoryListingV2 implements DirectoryListingPortV2 {
5
5
  private readonly fs;
6
6
  constructor(fs: DirectoryListingOpsPortV2);
7
7
  readdir(dirPath: string): ResultAsync<readonly string[], FsError>;
8
+ readdirWithMtime(dirPath: string): ResultAsync<readonly DirEntryWithMtime[], FsError>;
8
9
  }
@@ -14,5 +14,13 @@ class LocalDirectoryListingV2 {
14
14
  return (0, neverthrow_1.errAsync)(e);
15
15
  });
16
16
  }
17
+ readdirWithMtime(dirPath) {
18
+ return this.fs.readdirWithMtime(dirPath).orElse((e) => {
19
+ if (e.code === 'FS_NOT_FOUND') {
20
+ return (0, neverthrow_1.okAsync)([]);
21
+ }
22
+ return (0, neverthrow_1.errAsync)(e);
23
+ });
24
+ }
17
25
  }
18
26
  exports.LocalDirectoryListingV2 = LocalDirectoryListingV2;
@@ -1,5 +1,5 @@
1
1
  import type { ResultAsync } from 'neverthrow';
2
- import type { FileSystemPortV2, FsError } from '../../../ports/fs.port.js';
2
+ import type { FileSystemPortV2, FsError, FsDirEntryWithMtime } from '../../../ports/fs.port.js';
3
3
  export declare class NodeFileSystemV2 implements FileSystemPortV2 {
4
4
  mkdirp(dirPath: string): ResultAsync<void, FsError>;
5
5
  readFileUtf8(filePath: string): ResultAsync<string, FsError>;
@@ -24,4 +24,5 @@ export declare class NodeFileSystemV2 implements FileSystemPortV2 {
24
24
  readonly sizeBytes: number;
25
25
  }, FsError>;
26
26
  readdir(dirPath: string): ResultAsync<readonly string[], FsError>;
27
+ readdirWithMtime(dirPath: string): ResultAsync<readonly FsDirEntryWithMtime[], FsError>;
27
28
  }
@@ -38,6 +38,7 @@ const fs = __importStar(require("fs/promises"));
38
38
  const fsCb = __importStar(require("fs"));
39
39
  const fs_1 = require("fs");
40
40
  const neverthrow_1 = require("neverthrow");
41
+ const path = __importStar(require("path"));
41
42
  function nodeErrorCode(e) {
42
43
  if (typeof e !== 'object' || e === null)
43
44
  return undefined;
@@ -162,5 +163,28 @@ class NodeFileSystemV2 {
162
163
  readdir(dirPath) {
163
164
  return neverthrow_1.ResultAsync.fromPromise(fs.readdir(dirPath), (e) => mapFsError(e, dirPath));
164
165
  }
166
+ readdirWithMtime(dirPath) {
167
+ return neverthrow_1.ResultAsync.fromPromise((async () => {
168
+ const entries = await fs.readdir(dirPath);
169
+ const withMtime = [];
170
+ let skipped = 0;
171
+ for (const name of entries) {
172
+ try {
173
+ const stats = await fs.stat(path.join(dirPath, name));
174
+ withMtime.push({ name, mtimeMs: stats.mtimeMs });
175
+ }
176
+ catch (e) {
177
+ const code = nodeErrorCode(e);
178
+ skipped++;
179
+ console.error(`[workrail:session-enum] Skipping ${name}: stat failed (${code ?? 'unknown'}: ${e instanceof Error ? e.message : String(e)})`);
180
+ continue;
181
+ }
182
+ }
183
+ if (skipped > 0) {
184
+ console.error(`[workrail:session-enum] Enumerated ${withMtime.length} sessions, skipped ${skipped} (stat failures)`);
185
+ }
186
+ return withMtime;
187
+ })(), (e) => mapFsError(e, dirPath));
188
+ }
165
189
  }
166
190
  exports.NodeFileSystemV2 = NodeFileSystemV2;
@@ -21,7 +21,7 @@ class LocalSessionSummaryProviderV2 {
21
21
  this.ports = ports;
22
22
  }
23
23
  loadHealthySummaries() {
24
- return (0, enumerate_sessions_js_1.enumerateSessions)({
24
+ return (0, enumerate_sessions_js_1.enumerateSessionsByRecency)({
25
25
  directoryListing: this.ports.directoryListing,
26
26
  dataDir: this.ports.dataDir,
27
27
  })
@@ -1,5 +1,10 @@
1
1
  import type { ResultAsync } from 'neverthrow';
2
2
  import type { FsError } from './fs.port.js';
3
+ export interface DirEntryWithMtime {
4
+ readonly name: string;
5
+ readonly mtimeMs: number;
6
+ }
3
7
  export interface DirectoryListingPortV2 {
4
8
  readdir(dirPath: string): ResultAsync<readonly string[], FsError>;
9
+ readdirWithMtime(dirPath: string): ResultAsync<readonly DirEntryWithMtime[], FsError>;
5
10
  }
@@ -45,8 +45,13 @@ export interface FileManipulationPortV2 {
45
45
  unlink(filePath: string): ResultAsync<void, FsError>;
46
46
  writeFileBytes(filePath: string, bytes: Uint8Array): ResultAsync<void, FsError>;
47
47
  }
48
+ export interface FsDirEntryWithMtime {
49
+ readonly name: string;
50
+ readonly mtimeMs: number;
51
+ }
48
52
  export interface DirectoryListingOpsPortV2 {
49
53
  readdir(dirPath: string): ResultAsync<readonly string[], FsError>;
54
+ readdirWithMtime(dirPath: string): ResultAsync<readonly FsDirEntryWithMtime[], FsError>;
50
55
  }
51
56
  export interface CrashSafeFileOpsPortV2 extends DirectoryOpsPortV2, FileReadPortV2, FileDescriptorPortV2, FileManipulationPortV2, DirectoryListingOpsPortV2 {
52
57
  }
@@ -7,3 +7,7 @@ export declare function enumerateSessions(ports: {
7
7
  readonly directoryListing: DirectoryListingPortV2;
8
8
  readonly dataDir: DataDirPortV2;
9
9
  }): ResultAsync<readonly SessionId[], FsError>;
10
+ export declare function enumerateSessionsByRecency(ports: {
11
+ readonly directoryListing: DirectoryListingPortV2;
12
+ readonly dataDir: DataDirPortV2;
13
+ }): ResultAsync<readonly SessionId[], FsError>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.enumerateSessions = enumerateSessions;
4
+ exports.enumerateSessionsByRecency = enumerateSessionsByRecency;
4
5
  const index_js_1 = require("../durable-core/ids/index.js");
5
6
  const SESSION_DIR_PATTERN = /^sess_[a-zA-Z0-9_]+$/;
6
7
  function enumerateSessions(ports) {
@@ -11,3 +12,15 @@ function enumerateSessions(ports) {
11
12
  .sort()
12
13
  .map((entry) => (0, index_js_1.asSessionId)(entry)));
13
14
  }
15
+ function enumerateSessionsByRecency(ports) {
16
+ return ports.directoryListing
17
+ .readdirWithMtime(ports.dataDir.sessionsDir())
18
+ .map((entries) => entries
19
+ .filter((entry) => SESSION_DIR_PATTERN.test(entry.name))
20
+ .sort((a, b) => {
21
+ if (a.mtimeMs !== b.mtimeMs)
22
+ return b.mtimeMs - a.mtimeMs;
23
+ return a.name.localeCompare(b.name);
24
+ })
25
+ .map((entry) => (0, index_js_1.asSessionId)(entry.name)));
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exaudeus/workrail",
3
- "version": "1.13.0",
3
+ "version": "1.13.2",
4
4
  "description": "Step-by-step workflow enforcement for AI agents via MCP",
5
5
  "license": "MIT",
6
6
  "repository": {