cvm-server 0.12.0 → 0.14.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.
Files changed (3) hide show
  1. package/README.md +183 -157
  2. package/main.cjs +1443 -905
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,204 +1,230 @@
1
- # CVM: Stateful Task Engine for Claude
1
+ # cvm-server
2
2
 
3
- **Stop Claude from losing track. CVM is a passive state machine that Claude queries for tasks, maintaining perfect execution flow across complex operations.**
3
+ The executable MCP server application for CVM. This is the npm package that users install to run CVM with Claude Desktop.
4
4
 
5
- [![npm version](https://badge.fury.io/js/cvm-server.svg)](https://www.npmjs.com/package/cvm-server)
5
+ ## Overview
6
6
 
7
- ## The Problem
7
+ This app provides:
8
+ - **Executable MCP Server**: Ready-to-run server for Claude Desktop
9
+ - **Configuration Management**: Environment-based configuration
10
+ - **Logging**: Structured logging for debugging
11
+ - **Graceful Shutdown**: Proper cleanup on exit
12
+ - **Version Management**: Automatic version detection
8
13
 
9
- "Claude, analyze these 1000 files and create a report" → Claude gets confused, loses context, forgets what it's doing.
14
+ ## Architecture
10
15
 
11
- ## The Solution
16
+ ```
17
+ Claude Desktop
18
+ ↓ (stdio)
19
+ cvm-server (this app)
20
+
21
+ CVMMcpServer (@cvm/mcp-server)
22
+
23
+ VMManager (@cvm/vm)
24
+
25
+ Storage + VM Engine
26
+ ```
27
+
28
+ ## Installation
12
29
 
13
- CVM is a passive MCP server that holds program state. You write a program with loops and logic, but Claude only sees one task at a time. Claude asks "what's next?", completes the task, and asks again.
30
+ ### For End Users
14
31
 
15
- The magic: CVM never pushes tasks. Claude pulls tasks when ready, maintaining perfect control while CVM quietly manages state between requests.
32
+ Add to Claude Desktop's MCP settings:
16
33
 
17
- ## What CVM Really Is
34
+ ```json
35
+ {
36
+ "mcpServers": {
37
+ "cvm": {
38
+ "command": "npx",
39
+ "args": ["cvm-server@latest"],
40
+ "env": {
41
+ "CVM_STORAGE_TYPE": "file",
42
+ "CVM_DATA_DIR": ".cvm"
43
+ }
44
+ }
45
+ }
46
+ }
47
+ ```
18
48
 
19
- CVM is an **algorithmic TODO manager**. Think of it as:
20
- - A TODO list that can have loops ("do this 5 times")
21
- - A TODO list that can have conditions ("if X then do Y")
22
- - A TODO list that maintains variables between tasks
23
- - A TODO list shaped like a program
49
+ ### For Development
24
50
 
25
- When your program hits `CC("analyze this file")`, CVM doesn't call Claude. Instead:
26
- 1. CVM creates a TODO: "analyze this file"
27
- 2. CVM pauses execution and waits
28
- 3. Claude asks CVM: "What should I do next?"
29
- 4. CVM responds: "analyze this file"
30
- 5. Claude does the analysis and submits the result
31
- 6. CVM updates its state and moves to the next instruction
51
+ ```bash
52
+ # Clone repository
53
+ git clone https://github.com/LadislavSopko/cvm.git
54
+ cd cvm
32
55
 
33
- **CVM is completely passive** - it never initiates anything. Claude drives everything.
56
+ # Install dependencies
57
+ npm install
34
58
 
35
- ## Try It Now
59
+ # Build all packages
60
+ npx nx build cvm-server
36
61
 
37
- Save this as `counter.ts`:
38
- ```typescript
39
- function main() {
40
- let count = 0;
41
- while (count < 5) {
42
- const next = CC("Current number is " + count + ". What's the next number?");
43
- count = +next;
44
- console.log("Count is now: " + count);
45
- }
46
- return count; // Returns 5
47
- }
48
- main();
62
+ # Run locally
63
+ node apps/cvm-server/dist/main.js
49
64
  ```
50
65
 
51
- Then tell Claude: **"Run counter.ts with CVM"**
66
+ ## Configuration
52
67
 
53
- What actually happens:
54
- - CVM loads the program and starts execution
55
- - When it hits `CC()`, CVM creates a task and waits
56
- - Claude asks CVM for tasks using `getTask()`
57
- - CVM gives Claude: "Current number is 0. What's the next number?"
58
- - Claude figures out the answer is "1" and submits it
59
- - CVM continues the loop with count=1
60
- - Process repeats until done
68
+ The server uses environment variables for configuration:
61
69
 
62
- ## How It Works
70
+ ### Storage Configuration
63
71
 
64
- CVM is a passive MCP server. Claude actively drives execution:
72
+ ```bash
73
+ # File storage (default)
74
+ CVM_STORAGE_TYPE=file
75
+ CVM_DATA_DIR=.cvm
65
76
 
77
+ # MongoDB storage
78
+ CVM_STORAGE_TYPE=mongodb
79
+ MONGODB_URL=mongodb://localhost:27017/cvm
66
80
  ```
67
- Claude: load("counter", "...program code...")
68
- Claude: start("counter", "exec-123")
69
- Claude: getTask("exec-123") → CVM: "Current number is 0. What's the next number?"
70
- Claude: submitTask("exec-123", "1") → CVM sets count=1, continues loop
71
- Claude: getTask("exec-123") → CVM: "Current number is 1. What's the next number?"
72
- Claude: submitTask("exec-123", "2") → CVM sets count=2, continues loop
73
- ...
74
- Claude: getTask("exec-123") → CVM: "Execution completed with result: 5"
81
+
82
+ ### Logging Configuration
83
+
84
+ ```bash
85
+ # Log levels: debug, info, warn, error
86
+ CVM_LOG_LEVEL=info
87
+
88
+ # Log format: pretty (default) or json
89
+ CVM_LOG_FORMAT=pretty
75
90
  ```
76
91
 
77
- ## Why This Architecture
78
-
79
- **Traditional approach**: Claude tries to maintain state in its context window
80
- - Loses track in complex flows
81
- - ❌ Forgets variables between steps
82
- - ❌ Can't handle real loops or conditions reliably
83
-
84
- **CVM approach**: State lives in CVM, Claude just processes individual tasks
85
- - ✅ Perfect state management
86
- - ✅ Real loops and conditions that work
87
- - ✅ Claude's context stays clean
88
- - ✅ Complex workflows become simple task sequences
89
-
90
- ## Real Example
91
-
92
- ```typescript
93
- function main() {
94
- const files = fs.listFiles("./docs", { filter: "*.txt" });
95
- const summaries = [];
96
-
97
- for (const file of files) {
98
- // This creates a task for Claude, doesn't "call" Claude
99
- const content = CC("Read and summarize this file: " + file);
100
- // Now we can use objects!
101
- summaries.push({
102
- filename: file,
103
- summary: content
104
- });
105
- console.log("Processed: " + file);
106
- }
107
-
108
- // Convert summaries array to JSON for the final task
109
- const summariesJson = JSON.stringify(summaries);
110
- const report = CC("Create a final report from these file summaries: " + summariesJson);
111
- console.log("Final Report: " + report);
112
-
113
- return report;
114
- }
115
- main();
92
+ ### Environment
93
+
94
+ ```bash
95
+ # Environment: development, production
96
+ NODE_ENV=production
116
97
  ```
117
98
 
118
- CVM turns this into a dynamic TODO list:
119
- 1. Task: "Read and summarize this file: ./docs/file1.txt"
120
- 2. Task: "Read and summarize this file: ./docs/file2.txt"
121
- 3. Task: "Read and summarize this file: ./docs/file3.txt"
122
- 4. Task: "Create a final report from these summaries: [...]"
99
+ ## Features
123
100
 
124
- Claude works through these tasks one by one, while CVM maintains the loop state, the summaries array, and the execution position.
101
+ ### Automatic Storage Setup
102
+ - Creates storage directories if needed
103
+ - Warns about adding data directory to .gitignore
104
+ - Connects to MongoDB if configured
125
105
 
126
- ## Key Concepts
106
+ ### Version Detection
107
+ - Attempts to find package.json in multiple locations
108
+ - Works in development and production builds
109
+ - Falls back to hardcoded version if needed
127
110
 
128
- ### CC() - Cognitive Context
129
- `CC(prompt)` doesn't mean "call Claude". It means:
130
- - Create a task with this prompt
131
- - Pause execution here
132
- - Wait for Claude to ask for the next task
133
- - Resume when Claude provides a result
111
+ ### Graceful Shutdown
112
+ - Handles SIGINT and SIGTERM signals
113
+ - Closes all connections properly
114
+ - Ensures data is saved before exit
134
115
 
135
- ### CVM is Passive
136
- - CVM never sends messages to Claude
137
- - CVM never initiates actions
138
- - CVM only responds when Claude asks
139
- - Claude drives everything via MCP tools
116
+ ### Error Handling
117
+ - Comprehensive error logging
118
+ - Graceful degradation
119
+ - Clear error messages for debugging
140
120
 
141
- ### State Management
142
- While Claude processes tasks, CVM maintains:
143
- - All variables and their values
144
- - Current execution position
145
- - Loop counters and conditions
146
- - Arrays, objects, and complex data structures
121
+ ## File Structure
147
122
 
148
- ## Installation
123
+ ```
124
+ apps/cvm-server/
125
+ ├── src/
126
+ │ ├── main.ts # Entry point
127
+ │ ├── config.ts # Configuration management
128
+ │ └── logger.ts # Logging setup
129
+ ├── bin/
130
+ │ └── cvm-server.cjs # Executable wrapper
131
+ ├── package.json # Package metadata
132
+ └── README.md # This file
133
+ ```
134
+
135
+ ## Building and Publishing
149
136
 
150
- Add to Claude's `.mcp.json`:
137
+ ### Build
138
+
139
+ ```bash
140
+ # Development build
141
+ npx nx build cvm-server --configuration=development
142
+
143
+ # Production build
144
+ npx nx build cvm-server --configuration=production
145
+ ```
146
+
147
+ ### Publish to npm
148
+
149
+ ```bash
150
+ # Bump version and publish
151
+ npx nx release
152
+
153
+ # Or manually
154
+ cd apps/cvm-server/dist
155
+ npm publish --otp=YOUR_OTP
156
+ ```
157
+
158
+ ## Usage
159
+
160
+ Once installed, Claude can interact with CVM through MCP tools:
161
+
162
+ 1. Load a program: `mcp__cvm__load`
163
+ 2. Start execution: `mcp__cvm__start`
164
+ 3. Get tasks: `mcp__cvm__getTask`
165
+ 4. Submit results: `mcp__cvm__submitTask`
166
+
167
+ See the main project README for detailed usage examples.
168
+
169
+ ## Development Tips
170
+
171
+ ### Running Locally
172
+
173
+ ```bash
174
+ # Set environment variables
175
+ export CVM_STORAGE_TYPE=file
176
+ export CVM_DATA_DIR=.cvm-dev
177
+ export CVM_LOG_LEVEL=debug
178
+
179
+ # Run the server
180
+ node apps/cvm-server/dist/main.js
181
+ ```
182
+
183
+ ### Testing with Claude Desktop
184
+
185
+ 1. Build the server: `npx nx build cvm-server`
186
+ 2. Update MCP config to point to local build:
151
187
  ```json
152
188
  {
153
189
  "mcpServers": {
154
190
  "cvm": {
155
- "command": "npx",
156
- "args": ["cvm-server@latest"],
157
- "env": {
158
- "CVM_STORAGE_TYPE": "file",
159
- "CVM_DATA_DIR": ".cvm"
160
- }
191
+ "command": "node",
192
+ "args": ["/path/to/cvm/apps/cvm-server/dist/main.js"]
161
193
  }
162
194
  }
163
195
  }
164
196
  ```
165
197
 
166
- ## MCP Tools
167
-
168
- Claude uses these tools to interact with CVM:
169
-
170
- - **`load(programId, source)`** - Load a program into CVM
171
- - **`loadFile(programId, filePath)`** - Load from file
172
- - **`start(programId, executionId)`** - Start execution
173
- - **`getTask(executionId)`** - Get next task (CVM waits for this)
174
- - **`submitTask(executionId, result)`** - Submit task result
175
- - **`status(executionId)`** - Check execution state
198
+ ### Debugging
176
199
 
177
- ## Language Features
178
-
179
- CVM executes a TypeScript-like language:
180
- - Variables, arrays, objects, loops, conditions
181
- - String/array operations
182
- - Object literals and property access
183
- - `JSON.stringify()` and `JSON.parse()`
184
- - `CC()` for task creation
185
- - `fs.listFiles()` for file operations
186
- - `console.log()` for output
187
-
188
- [→ Full API Documentation](docs/API.md)
200
+ Enable debug logging:
201
+ ```bash
202
+ export CVM_LOG_LEVEL=debug
203
+ export CVM_LOG_FORMAT=pretty
204
+ ```
189
205
 
190
- ## Use Cases
206
+ Check logs for:
207
+ - Storage initialization
208
+ - MCP tool calls
209
+ - VM state changes
210
+ - Error traces
191
211
 
192
- Perfect for any workflow where Claude needs to process many items systematically:
193
- - Document analysis pipelines
194
- - Data extraction from multiple sources
195
- - Report generation with multiple inputs
196
- - Any task requiring loops with AI processing
212
+ ## Dependencies
197
213
 
198
- ## Summary
214
+ ### Runtime Dependencies
215
+ - **@modelcontextprotocol/sdk**: MCP protocol implementation
216
+ - **dotenv**: Environment variable loading
217
+ - **mongodb**: MongoDB driver (optional)
218
+ - **typescript**: Type definitions
219
+ - **zod**: Schema validation
199
220
 
200
- CVM is a passive, stateful task engine. It turns programs into smart TODO lists that Claude can work through systematically without losing context. The program defines the workflow, Claude provides the intelligence, and CVM quietly maintains the state between them.
221
+ ### Internal Dependencies
222
+ - **@cvm/mcp-server**: MCP server implementation
223
+ - **@cvm/vm**: Core VM engine
224
+ - **@cvm/storage**: Storage layer
225
+ - **@cvm/parser**: CVM language parser
226
+ - **@cvm/types**: Shared types
201
227
 
202
- ---
228
+ ## License
203
229
 
204
- Copyright 2025 Ladislav Sopko. Licensed under Apache 2.0.
230
+ Apache 2.0 - See LICENSE file for details