@exaudeus/workrail 0.1.1 โ†’ 0.1.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.
Files changed (30) hide show
  1. package/README.md +153 -189
  2. package/dist/application/services/classification-engine.d.ts +33 -0
  3. package/dist/application/services/classification-engine.js +258 -0
  4. package/dist/application/services/compression-service.d.ts +20 -0
  5. package/dist/application/services/compression-service.js +312 -0
  6. package/dist/application/services/context-management-service.d.ts +38 -0
  7. package/dist/application/services/context-management-service.js +301 -0
  8. package/dist/application/services/context-persistence-service.d.ts +45 -0
  9. package/dist/application/services/context-persistence-service.js +273 -0
  10. package/dist/cli/migrate-workflow.js +3 -2
  11. package/dist/infrastructure/storage/context-storage.d.ts +150 -0
  12. package/dist/infrastructure/storage/context-storage.js +40 -0
  13. package/dist/infrastructure/storage/filesystem-blob-storage.d.ts +27 -0
  14. package/dist/infrastructure/storage/filesystem-blob-storage.js +363 -0
  15. package/dist/infrastructure/storage/hybrid-context-storage.d.ts +29 -0
  16. package/dist/infrastructure/storage/hybrid-context-storage.js +400 -0
  17. package/dist/infrastructure/storage/migrations/001_initial_schema.sql +38 -0
  18. package/dist/infrastructure/storage/migrations/002_context_concurrency_enhancements.sql +234 -0
  19. package/dist/infrastructure/storage/migrations/003_classification_overrides.sql +20 -0
  20. package/dist/infrastructure/storage/sqlite-metadata-storage.d.ts +35 -0
  21. package/dist/infrastructure/storage/sqlite-metadata-storage.js +410 -0
  22. package/dist/infrastructure/storage/sqlite-migrator.d.ts +46 -0
  23. package/dist/infrastructure/storage/sqlite-migrator.js +293 -0
  24. package/dist/types/context-types.d.ts +236 -0
  25. package/dist/types/context-types.js +10 -0
  26. package/dist/utils/storage-security.js +1 -1
  27. package/package.json +3 -1
  28. package/workflows/coding-task-workflow-with-loops.json +1 -1
  29. package/workflows/mr-review-workflow.json +75 -26
  30. package/workflows/systemic-bug-investigation-with-loops.json +423 -0
package/README.md CHANGED
@@ -1,270 +1,234 @@
1
- # WorkRail: A Workflow Orchestration Server for MCP
1
+ # WorkRail: Guided Workflow Orchestration for AI Agents
2
2
 
3
- > **Reliable, test-driven workflow execution for AI coding assistants โ€“ powered by Clean Architecture**
3
+ > **Transform chaotic AI interactions into structured, reliable workflows**
4
4
 
5
- [![Build](https://img.shields.io/github/actions/workflow/status/EtienneBBeaulac/mcp/ci.yml?branch=main)]()
6
- [![Version](https://img.shields.io/badge/version-0.0.1--alpha-orange)]()
7
5
  [![MCP Compatible](https://img.shields.io/badge/MCP-compatible-purple.svg)](https://modelcontextprotocol.org)
6
+ [![Version](https://img.shields.io/badge/version-0.1.0-blue)]()
8
7
 
9
8
  ---
10
9
 
11
- ## ๐Ÿš€ Overview
10
+ ## ๐Ÿค” The Problem
12
11
 
13
- Large language models are phenomenal at generating code, yet they often hallucinate, lose context, or perform unsafe operations.
14
- This server provides **structured, step-by-step workflows** (defined as JSON documents) that guide an AI assistant through safe, repeatable tasks.
15
- It follows [Model Context Protocol (MCP)](https://modelcontextprotocol.org) conventions and exposes a **JSON-RPC 2.0** interface on `stdin/stdout`.
12
+ Large Language Models are incredibly powerful but suffer from well-documented limitations:
16
13
 
17
- The codebase now implements the full MVP described in the original specification, refactored with Clean Architecture for long-term maintainability.
14
+ - **Hallucination** - They confidently generate plausible-sounding but incorrect information
15
+ - **Scope Creep** - Given a complex task, they often try to do too much at once, leading to half-baked solutions
16
+ - **Context Loss** - They struggle to maintain focus across long conversations
17
+ - **Inconsistency** - The same prompt can yield wildly different results based on minor variations
18
+ - **Missing Prerequisites** - They often start implementing before gathering necessary context
18
19
 
19
- ### โœจ New in v0.1.0: Loop Support
20
- WorkRail now supports powerful iteration patterns with four loop types:
21
- - **while**: Continue while a condition is true
22
- - **until**: Continue until a condition is met
23
- - **for**: Execute a fixed number of times
24
- - **forEach**: Process items in an array
20
+ Traditional approaches try to solve these through better prompting or more powerful models. WorkRail takes a different approach.
25
21
 
26
- See the [Loop Documentation](docs/features/loops.md) for details.
22
+ ## ๐Ÿ’ก The Solution
27
23
 
28
- ---
29
-
30
- ## ๐Ÿš€ Quick Start
31
-
32
- ```bash
33
- # Install globally
34
- npm install -g @exaudeus/workrail
35
-
36
- # Initialize your personal workflow directory
37
- workrail init
24
+ WorkRail guides LLMs through **proven software engineering best practices** via structured workflows, making it much more difficult for the LLM to go off track.
38
25
 
39
- # List all available workflows (bundled + your custom ones)
40
- workrail list
26
+ Instead of hoping an LLM will follow best practices, this system **guides them toward** best practices through structured, machine-readable workflows.
41
27
 
42
- # Check workflow sources and status
43
- workrail sources
44
-
45
- # Validate a workflow file
46
- workrail validate my-workflow.json
47
-
48
- # Start the MCP server
49
- workrail start
28
+ **Traditional Approach:**
50
29
  ```
51
-
52
- **Multiple Workflow Sources**: WorkRail automatically loads workflows from:
53
- - **Bundled workflows** (included with the package)
54
- - **User workflows** (`~/.workrail/workflows/`)
55
- - **Project workflows** (`./workflows/`)
56
- - **Custom directories** (via `WORKFLOW_STORAGE_PATH` environment variable)
57
-
58
- ---
59
-
60
- ## โœจ Key Features
61
-
62
- * **Clean Architecture** โ€“ clear separation of **Domain โ†’ Application โ†’ Infrastructure** layers.
63
- * **MCP Protocol Support** โ€“ Full MCP SDK integration with proper tool definitions and stdio transport.
64
- * **Workflow Orchestration Tools** โ€“ 5 core tools for workflow management:
65
- - `workflow_list` - List all available workflows
66
- - `workflow_get` - Get detailed workflow information
67
- - `workflow_next` - Get the next step in a workflow
68
- - `workflow_validate` - Advanced validation of step outputs with schema, context-aware, and composition rules
69
- - `workflow_validate_json` - Direct JSON workflow validation with comprehensive error reporting and actionable suggestions
70
- * **Loop Support (v0.1.0)** โ€“ Four loop types for powerful iteration patterns:
71
- - `while` loops - Continue while a condition is true
72
- - `until` loops - Continue until a condition is met
73
- - `for` loops - Execute a fixed number of times
74
- - `forEach` loops - Process items in an array
75
- * **Dependency Injection** โ€“ pluggable components are wired by `src/container.ts` (Inversify-style, no runtime reflection).
76
- * **Async, Secure Storage** โ€“ interchangeable back-ends: in-memory (default for tests) and file-based storage with path-traversal safeguards.
77
- * **Advanced ValidationEngine** โ€“ Three-tier validation system with JSON Schema validation (AJV), Context-Aware Validation (conditional rules), and Logical Composition (and/or/not operators) for comprehensive step output quality assurance.
78
- * **Typed Error Mapping** โ€“ domain errors (`WorkflowNotFoundError`, `ValidationError`, โ€ฆ) automatically translate to proper JSON-RPC codes.
79
- * **CLI Tools** โ€“
80
- - `validate` - Test workflow files locally with comprehensive error reporting
81
- - `migrate` - Automatically migrate workflows from v0.0.1 to v0.1.0
82
- * **Comprehensive Test Coverage** โ€“ 81 tests passing, 7 failing (performance optimizations in progress), 88 total tests covering storage, validation, error mapping, CLI, and server logic.
83
-
84
- ---
85
-
86
- ## โšก Quick Start
87
-
88
- ### Prerequisites
89
- * Node 18+
90
- * `npm install`
91
-
92
- ### Development mode
93
- ```bash
94
- npm run dev
30
+ User: "Help me implement this feature"
31
+ AI: [May or may not ask for context, may or may not plan, may or may not test]
95
32
  ```
96
- The MCP server listens for JSON-RPC requests on **stdin/stdout**.
97
33
 
98
- ### Production build
99
- ```bash
100
- npm run build
101
- node dist/mcp-server.js
34
+ **WorkRail Approach:**
102
35
  ```
103
-
104
- ### Workflow validation (CLI utility)
105
- ```bash
106
- npx ts-node src/cli.ts validate <workflow-file.json>
36
+ Workflow guides: Context โ†’ Clarification โ†’ Planning โ†’ Implementation โ†’ Verification
37
+ AI: [Cannot skip steps, must follow proven patterns]
107
38
  ```
108
39
 
109
- ### Docker
110
- ```bash
111
- docker-compose up
112
- ```
40
+ This creates an enhanced experience where developers are guided through optimal workflows, missing fewer critical steps, while LLMs work within their strengths following proven patterns.
113
41
 
114
42
  ---
115
43
 
116
- ## ๐Ÿ”ง Configuration
44
+ ## ๐Ÿ› ๏ธ MCP Tools
117
45
 
118
- ### Usage with Claude Desktop
46
+ WorkRail exposes 6 core tools through the Model Context Protocol:
47
+
48
+ - **`workflow_list`** - Browse available workflows for different task types
49
+ - **`workflow_get`** - Get complete workflow details and requirements
50
+ - **`workflow_next`** - Get the next step in an active workflow
51
+ - **`workflow_validate`** - Validate step outputs against quality criteria
52
+ - **`workflow_validate_json`** - Validate and lint workflow JSON files
53
+ - **`workflow_get_schema`** - Get the complete workflow JSON schema for workflow creation
54
+
55
+ ---
119
56
 
120
- Add this to your `claude_desktop_config.json`:
57
+ ## โš™๏ธ Installation
121
58
 
122
- #### npx (once published to npm)
59
+ Add WorkRail to your AI agent by configuring the MCP server:
123
60
 
61
+ ### NPX (Recommended)
62
+ Add to your agent's `config.json`:
124
63
  ```json
125
64
  {
126
65
  "mcpServers": {
127
66
  "workrail": {
128
67
  "command": "npx",
129
- "args": [
130
- "-y",
131
- "@exaudeus/workrail"
132
- ]
68
+ "args": ["-y", "@exaudeus/workrail"]
133
69
  }
134
70
  }
135
71
  }
136
72
  ```
137
73
 
138
- #### Local development
139
-
74
+ ### Docker
75
+ Add to your agent's `config.json`:
140
76
  ```json
141
77
  {
142
78
  "mcpServers": {
143
79
  "workrail": {
144
- "command": "node",
145
- "args": [
146
- "/path/to/your/mcp/packages/workrail/dist/mcp-server.js"
147
- ]
80
+ "command": "docker",
81
+ "args": ["run", "--rm", "-i", "workrail-mcp"]
148
82
  }
149
83
  }
150
84
  }
151
85
  ```
152
86
 
153
- ### Usage with VS Code
87
+ ---
154
88
 
155
- For manual installation, add this to your User Settings (JSON) or `.vscode/mcp.json`:
89
+ ## ๐Ÿ“‹ Available Workflows
156
90
 
157
- #### npx (once published)
91
+ WorkRail comes with battle-tested workflows for common development tasks:
158
92
 
159
- ```json
160
- {
161
- "mcp": {
162
- "servers": {
163
- "workrail": {
164
- "command": "npx",
165
- "args": [
166
- "-y",
167
- "@exaudeus/workrail"
168
- ]
169
- }
170
- }
171
- }
172
- }
173
- ```
93
+ ### ๐Ÿ”ง **Development Workflows**
94
+ - **`coding-task-workflow`** - Comprehensive coding workflow with analysis, planning, implementation, and review
95
+ - **`coding-task-workflow-with-loops`** - Enhanced version with iterative refinement loops
96
+ - **`systematic-bug-investigation`** - Systematic debugging methodology that prevents jumping to conclusions
97
+ - **`systemic-bug-investigation-with-loops`** - Enhanced debugging with iterative analysis loops
98
+
99
+ ### ๐Ÿš€ **Project Management**
100
+ - **`adaptive-ticket-creation`** - Create well-structured tickets with proper requirements
101
+ - **`mr-review-workflow`** - Thorough merge request review process
102
+
103
+ ### ๐Ÿ“š **Content & Documentation**
104
+ - **`document-creation-workflow`** - Structured approach to creating comprehensive documentation
105
+ - **`presentation-creation`** - Build engaging presentations with clear narrative flow
106
+ - **`personal-learning-course-design`** - Design educational content with learning objectives
107
+ - **`personal-learning-materials-creation-branched`** - Create comprehensive learning materials with adaptive complexity
108
+
109
+ ### ๐Ÿ” **Discovery & Analysis**
110
+ - **`exploration-workflow`** - Systematic codebase or domain exploration
111
+ - **`workflow-for-workflows`** - Meta-workflow for designing new workflows
112
+
113
+ ---
114
+
115
+ ## ๐Ÿ”„ Loop Support
116
+
117
+ WorkRail supports powerful iteration patterns for complex tasks:
118
+
119
+ - **`while`** - Continue while a condition is true
120
+ - **`until`** - Continue until a condition is met
121
+ - **`for`** - Execute a fixed number of times
122
+ - **`forEach`** - Process items in an array
123
+
124
+ Perfect for batch operations, retries, polling, and iterative refinement.
125
+
126
+ ---
127
+
128
+ ## ๐Ÿ“– Quick Example
174
129
 
175
- #### Local development
130
+ Here's what a workflow step looks like:
176
131
 
177
132
  ```json
178
133
  {
179
- "mcp": {
180
- "servers": {
181
- "workrail": {
182
- "command": "node",
183
- "args": [
184
- "/path/to/your/mcp/packages/workrail/dist/mcp-server.js"
185
- ]
186
- }
187
- }
134
+ "id": "analyze-codebase",
135
+ "name": "Deep Codebase Analysis",
136
+ "description": "Understand the codebase structure before making changes",
137
+ "agentRole": "You are a senior engineer performing careful code analysis",
138
+ "runCondition": {
139
+ "type": "context",
140
+ "key": "taskComplexity",
141
+ "operator": "in",
142
+ "values": ["Medium", "Large"]
143
+ },
144
+ "validationCriteria": {
145
+ "outputLength": {"min": 200, "max": 2000},
146
+ "mustContain": ["file structure", "key components", "dependencies"]
188
147
  }
189
148
  }
190
149
  ```
191
150
 
151
+ The agent receives structured guidance on **what to do**, **how to do it**, and **quality standards to meet**.
152
+
192
153
  ---
193
154
 
194
- ## ๐Ÿ—‚๏ธ Project Structure (post-refactor)
155
+ ## ๐ŸŒŸ Why Choose WorkRail?
195
156
 
196
- ```
197
- packages/workrail/
198
- โ”œโ”€ src/
199
- โ”‚ โ”œโ”€ domain/ # Pure entities & errors (no dependencies)
200
- โ”‚ โ”œโ”€ application/ # Use-cases, services, ValidationEngine (depends on domain)
201
- โ”‚ โ”œโ”€ infrastructure/
202
- โ”‚ โ”‚ โ”œโ”€ rpc/ # JSON-RPC server adapter
203
- โ”‚ โ”‚ โ””โ”€ storage/ # File, in-memory, caching, schema-validating adapters
204
- โ”‚ โ”œโ”€ mcp-server.ts # MCP server implementation (main entry point)
205
- โ”‚ โ”œโ”€ cli.ts # CLI utility for workflow validation
206
- โ”‚ โ”œโ”€ container.ts # DI registrations
207
- โ”‚ โ””โ”€ index.ts # Library entrypoint (exports container)
208
- โ”œโ”€ tests/ # Jest test suites (unit & integration)
209
- โ””โ”€ docs/ # Guides, reference, advanced topics
210
- ```
157
+ ### Consistency & Reproducibility
158
+ One of the biggest challenges with AI-assisted development is inconsistency. The same request can yield wildly different approaches depending on how the prompt is phrased, the LLM's randomness, or the developer's prompting expertise.
211
159
 
212
- ### Layered flow
213
- ```
214
- Client (AI Agent)
215
- โ–ผ MCP Protocol (stdin/stdout)
216
- MCP Server โ”€โ”€ mcp-server.ts (MCP SDK adapter)
217
- โ–ผ calls
218
- Application โ”€โ”€ use-cases (pure biz logic)
219
- โ–ผ operates on
220
- Domain โ”€โ”€ entities & value objects
221
- ```
160
+ WorkRail reduces these variables:
161
+ - **Same Process** - Every developer follows the same workflow
162
+ - **Same Quality** - Helps junior developers produce work closer to senior-level quality
163
+ - **Same Standards** - Code style and patterns are guided by workflows
164
+ - **Audit Trail** - Every decision is logged and reviewable
222
165
 
223
- ---
166
+ | Without WorkRail | With WorkRail |
167
+ |------------------|---------------|
168
+ | "Just fix this bug" โ†’ agent makes random changes | Systematic investigation โ†’ evidence-based diagnosis โ†’ targeted fix |
169
+ | "Add a feature" โ†’ incomplete implementation | Analysis โ†’ planning โ†’ implementation โ†’ testing โ†’ review |
170
+ | Inconsistent quality across tasks | Repeatable, high-quality processes |
171
+ | Outcome depends on prompting skills | Guided best practices regardless of experience |
224
172
 
225
- ## ๐Ÿ› ๏ธ Environment Variables
173
+ ---
226
174
 
227
- | Env Var | Default | Description |
228
- |---------|---------|-------------|
229
- | `WORKFLOW_DIR` | `spec/examples` | Path where workflow JSON files are loaded (file storage) |
230
- | `CACHE_TTL` | `300000` | Cache TTL in ms for `CachingWorkflowStorage` |
231
- | `PORT` | _n/a_ | Not used (stdin/stdout transport) |
175
+ ## ๐Ÿš€ Getting Started
232
176
 
233
- Change them before starting the server, e.g. `export WORKFLOW_DIR=/opt/workflows`.
177
+ 1. **Install** WorkRail as an MCP server (see installation above)
178
+ 2. **Browse workflows** - Use `workflow_list` to see available options
179
+ 3. **Start a workflow** - Use `workflow_get` to load a workflow for your task
180
+ 4. **Follow the steps** - Use `workflow_next` to get guided, step-by-step instructions
181
+ 5. **Validate progress** - Use `workflow_validate` to ensure quality at each step
234
182
 
235
183
  ---
236
184
 
237
- ## ๐Ÿงช Running Tests
185
+ ## ๐Ÿš€ Planned Features
238
186
 
239
- ```bash
240
- npm test
241
- ```
242
- Current status: 81 tests passing, 7 failing (performance optimizations in progress), 88 total tests.
187
+ WorkRail is actively evolving. Here are key enhancements on the roadmap:
243
188
 
244
- ---
189
+ ### **Workflow State Management**
190
+ - **Save & Resume** - Generate workflow state summaries for resuming complex workflows in new chat sessions
191
+ - **Context Preservation** - Maintain workflow progress across conversation boundaries
192
+ - **Checkpoint System** - Save progress at key milestones for easy recovery
193
+
194
+ ### **Model Switching Guidance**
195
+ Workflows could recommend optimal models for specific steps:
196
+ - **Analysis steps** โ†’ Tool-use heavy models (Claude) for codebase exploration
197
+ - **Planning/design** โ†’ Smartest available models for strategic thinking
198
+ - **Implementation** โ†’ Cost-effective models once requirements are clear
245
199
 
246
- ## ๐Ÿ“š Documentation Status
200
+ *Note: WorkRail provides text recommendations to users, not automatic model switching*
247
201
 
248
- | Component | Status | Updated |
249
- |-----------|--------|---------|
250
- | Root README | โœ… Complete | 2024-07-10 |
251
- | Implementation guides | ๐Ÿ”„ In Progress | 2024-07-10 |
252
- | Migration guide 1.2 | ๐Ÿ”„ In Progress | 2024-07-10 |
253
- | Code snippet refresh | ๐Ÿ”„ In Progress | 2024-07-10 |
202
+ ### **Enhanced Workflow Management**
203
+ - **Dynamic Workflow Loading** - Add/edit workflows without republishing the server
204
+ - **Workflow Categories** - Organize workflows by domain (debugging, planning, review, etc.)
205
+ - **Reusable Components** - Plugin system for common workflow patterns (codebase analysis, document creation, etc.)
206
+ - **Schema Versioning** - Backwards-compatible workflow schema evolution
207
+
208
+ ### **Advanced Validation & Quality**
209
+ - **Custom Validation Functions** - Domain-specific output validation beyond basic schema checks
210
+ - **Integration Hooks** - Connect with external quality tools and linters
211
+ - **Performance Validation** - Ensure workflow outputs meet performance criteria
212
+ - **Length Validation Optimization** - Faster validation using terminal commands vs. full content rewrite
213
+
214
+ ### **Workflow Discovery & Intelligence**
215
+ - **Smart Workflow Suggestions** - Recommend workflows based on task context
216
+ - **Pattern Recognition** - Identify when existing codebase patterns should inform workflow steps
254
217
 
255
218
  ---
219
+ *Have ideas for WorkRail? The planned features list helps guide development priorities.*
256
220
 
257
- ## ๐Ÿค Contributing
221
+ ---
258
222
 
259
- 1. **Fork & PR** โ€“ small, focused pull requests please.
260
- 2. **Follow the Architecture** โ€“ domain logic must remain framework-free; side effects live in infrastructure.
261
- 3. **Add Tests** โ€“ no code is accepted without unit tests.
262
- 4. **Run `npm run lint:fix`** before pushing.
223
+ ## ๐Ÿ“š Learn More
263
224
 
264
- See `docs/advanced/contributing.md` for full details.
225
+ - **[Complete Overview](workrail-mcp-overview.md)** - Deep dive into architecture, philosophy, and detailed examples
226
+ - **[Loop Documentation](docs/features/loops.md)** - Advanced iteration patterns
227
+ - **[API Specification](spec/mcp-api-v1.0.md)** - Complete MCP API reference
228
+ - **[Internal Documentation](docs/README.md)** - Development and architecture guides
265
229
 
266
230
  ---
267
231
 
268
232
  ## ๐Ÿ“„ License
269
233
 
270
- MIT โ€“ see [LICENSE](LICENSE).
234
+ MIT License - see [LICENSE](LICENSE)
@@ -0,0 +1,33 @@
1
+ import { ContextLayer, ClassificationRules, ClassifiedContext, RawContext } from '../../types/context-types';
2
+ export interface IClassificationEngine {
3
+ classify(context: RawContext, rules?: ClassificationRules): Promise<ClassifiedContext>;
4
+ loadRules(config?: Partial<ClassificationRules>): Promise<void>;
5
+ addOverride(sessionId: string, contextKey: string, layer: ContextLayer): void;
6
+ removeOverride(sessionId: string, contextKey: string): void;
7
+ markCritical(sessionId: string, contextKey: string): Promise<void>;
8
+ getStats(): ClassificationStats;
9
+ }
10
+ export interface ClassificationStats {
11
+ totalClassifications: number;
12
+ layerDistribution: Record<ContextLayer, number>;
13
+ overrideCount: number;
14
+ averageProcessingTime: number;
15
+ }
16
+ export declare class ClassificationEngine implements IClassificationEngine {
17
+ private rules;
18
+ private overrides;
19
+ private stats;
20
+ constructor(initialRules?: ClassificationRules);
21
+ classify(context: RawContext, rules?: ClassificationRules): Promise<ClassifiedContext>;
22
+ loadRules(config?: Partial<ClassificationRules>): Promise<void>;
23
+ addOverride(sessionId: string, contextKey: string, layer: ContextLayer): void;
24
+ removeOverride(sessionId: string, contextKey: string): void;
25
+ markCritical(sessionId: string, contextKey: string): Promise<void>;
26
+ getStats(): ClassificationStats;
27
+ private classifyKeyValue;
28
+ private applyPatternMatching;
29
+ private matchesPattern;
30
+ private applyHeuristics;
31
+ private updateStats;
32
+ private getDefaultRules;
33
+ }