@exaudeus/workrail 0.1.7 → 0.1.8

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.
@@ -22,4 +22,9 @@ export declare const METHOD_NAMES: {
22
22
  readonly SHUTDOWN: "shutdown";
23
23
  };
24
24
  export type MethodName = typeof METHOD_NAMES[keyof typeof METHOD_NAMES];
25
- export declare function buildWorkflowApplication(workflowService: WorkflowService, validator?: MethodValidator): ApplicationMediator;
25
+ export interface IApplicationMediator {
26
+ execute(method: string, params: any): Promise<any>;
27
+ register(method: string, handler: any): void;
28
+ setResponseValidator(fn: (method: string, result: any) => void): void;
29
+ }
30
+ export declare function buildWorkflowApplication(workflowService: WorkflowService, validator?: MethodValidator, enableOutputOptimization?: boolean): IApplicationMediator;
@@ -71,6 +71,7 @@ const list_workflows_1 = require("./use-cases/list-workflows");
71
71
  const get_workflow_1 = require("./use-cases/get-workflow");
72
72
  const get_next_step_1 = require("./use-cases/get-next-step");
73
73
  const validate_step_output_1 = require("./use-cases/validate-step-output");
74
+ const simple_output_decorator_1 = require("./decorators/simple-output-decorator");
74
75
  exports.METHOD_NAMES = {
75
76
  WORKFLOW_LIST: 'workflow_list',
76
77
  WORKFLOW_GET: 'workflow_get',
@@ -80,7 +81,7 @@ exports.METHOD_NAMES = {
80
81
  TOOLS_LIST: 'tools/list',
81
82
  SHUTDOWN: 'shutdown'
82
83
  };
83
- function buildWorkflowApplication(workflowService, validator = request_validator_1.requestValidator) {
84
+ function buildWorkflowApplication(workflowService, validator = request_validator_1.requestValidator, enableOutputOptimization = true) {
84
85
  const app = new ApplicationMediator(validator);
85
86
  app.setResponseValidator((method, result) => response_validator_1.responseValidator.validate(method, result));
86
87
  const listWorkflowsUseCase = (0, list_workflows_1.createListWorkflows)(workflowService);
@@ -112,5 +113,8 @@ function buildWorkflowApplication(workflowService, validator = request_validator
112
113
  const { shutdownHandler } = await Promise.resolve().then(() => __importStar(require('../tools/mcp_shutdown')));
113
114
  return (await shutdownHandler({ id: 0, params, method: 'shutdown', jsonrpc: '2.0' })).result;
114
115
  });
116
+ if (enableOutputOptimization) {
117
+ return new simple_output_decorator_1.SimpleOutputDecorator(app);
118
+ }
115
119
  return app;
116
120
  }
@@ -0,0 +1,8 @@
1
+ import { IApplicationMediator } from '../app';
2
+ export declare class SimpleOutputDecorator implements IApplicationMediator {
3
+ private readonly wrapped;
4
+ constructor(wrapped: IApplicationMediator);
5
+ execute(method: string, params: any): Promise<any>;
6
+ register(method: string, handler: any): void;
7
+ setResponseValidator(fn: (method: string, result: any) => void): void;
8
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SimpleOutputDecorator = void 0;
4
+ const CONTEXT_OPTIMIZATION_TEXT = `
5
+
6
+ **CONTEXT OPTIMIZATION REQUIREMENTS**:
7
+
8
+ The MCP server is STATELESS. You MUST send required data with each request:
9
+
10
+ **ALWAYS INCLUDE:**
11
+ 1. \`workflowId\` - Required for all calls
12
+ 2. \`completedSteps\` - Full array of completed step IDs
13
+ 3. **Condition Variables** - ANY variable used in step \`runCondition\` fields
14
+ 4. **Template Variables** - ANY variable referenced in {{templates}} in prompts/titles
15
+ 5. **Your New/Modified Variables** - Variables you created or changed in this step
16
+
17
+ **CONDITIONALLY INCLUDE:**
18
+ - **Loop Variables** (when in a loop): \`currentIteration\`, \`currentItem\`, \`currentIndex\`
19
+ - **Active Loop State**: Only \`_loopState[currentLoopId]\` if currently in a loop
20
+ - **Referenced Variables**: Any variable that future steps might need
21
+
22
+ **NEVER INCLUDE:**
23
+ - Large arrays that aren't being actively iterated (e.g., \`implementationSteps\` array)
24
+ - Stale loop states from completed loops
25
+ - Unreferenced historical data
26
+ - Variables only used in completed steps
27
+
28
+ **SIZE TARGETS:**
29
+ - Normal steps: < 2KB
30
+ - Loop iterations: < 5KB
31
+ - Complex state: < 10KB
32
+
33
+ **EXAMPLE - Loop Context:**
34
+ \`\`\`json
35
+ {
36
+ "workflowId": "coding-task-workflow",
37
+ "completedSteps": ["phase-1", "phase-2", "loop-step-1"],
38
+ "context": {
39
+ // Required: condition/template variables
40
+ "taskComplexity": "Medium",
41
+ "totalImplementationSteps": 8,
42
+ "currentStepNumber": 3,
43
+
44
+ // Required: your changes
45
+ "stepCompleted": true,
46
+ "testResults": "passed",
47
+
48
+ // Required: active loop state only
49
+ "_loopState": {
50
+ "phase-6-loop": { "iteration": 3 }
51
+ },
52
+
53
+ // DON'T include:
54
+ // - implementationSteps: [...] // Large array
55
+ // - analysisResults: {...} // From phase 1
56
+ // - _loopState.oldLoop: {...} // Completed loop
57
+ }
58
+ }
59
+ \`\`\`
60
+
61
+ **VALIDATION CHECK**: Before sending, verify you have ALL variables referenced in:
62
+ - The next step's \`runCondition\`
63
+ - Any {{variable}} in the next step's prompts
64
+ - Variables needed for loop control`;
65
+ class SimpleOutputDecorator {
66
+ constructor(wrapped) {
67
+ this.wrapped = wrapped;
68
+ }
69
+ async execute(method, params) {
70
+ const result = await this.wrapped.execute(method, params);
71
+ if (method === 'workflow_next' && result?.guidance?.prompt) {
72
+ return {
73
+ ...result,
74
+ guidance: {
75
+ ...result.guidance,
76
+ prompt: result.guidance.prompt + CONTEXT_OPTIMIZATION_TEXT
77
+ }
78
+ };
79
+ }
80
+ return result;
81
+ }
82
+ register(method, handler) {
83
+ this.wrapped.register(method, handler);
84
+ }
85
+ setResponseValidator(fn) {
86
+ this.wrapped.setResponseValidator(fn);
87
+ }
88
+ }
89
+ exports.SimpleOutputDecorator = SimpleOutputDecorator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exaudeus/workrail",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "MCP server for structured workflow orchestration and step-by-step task guidance",
5
5
  "license": "MIT",
6
6
  "bin": {