@utopia-ai/cli 0.1.1 → 0.1.3

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.
package/README.md ADDED
@@ -0,0 +1,332 @@
1
+ <div align="center">
2
+
3
+ # utopia
4
+
5
+ ### Debug AI Generated Code at Lightning Speed
6
+
7
+ **Your code talks back to the AI agents that wrote it.**
8
+
9
+ [![npm version](https://img.shields.io/npm/v/@utopia-ai/cli.svg)](https://www.npmjs.com/package/@utopia-ai/cli)
10
+ [![PyPI version](https://img.shields.io/pypi/v/utopia-runtime.svg)](https://pypi.org/project/utopia-runtime/)
11
+
12
+
13
+ <br />
14
+
15
+ [![Watch the demo](https://img.youtube.com/vi/dibx_WX7PpA/maxresdefault.jpg)](https://www.youtube.com/watch?v=dibx_WX7PpA)
16
+
17
+ **Watch: Utopia in action** (click to play)
18
+
19
+ <br />
20
+
21
+ </div>
22
+
23
+ ---
24
+
25
+ Utopia embeds intelligent probes into your codebase that capture how your code *actually runs* - errors, API calls, data shapes, auth flows, security patterns - and feeds that context directly to your AI coding agent. No more copying logs. No more explaining what went wrong. The agent already knows.
26
+
27
+ <br />
28
+
29
+ ## How It Works
30
+
31
+ ```
32
+ utopia init → Configure your project (30 seconds)
33
+ utopia instrument → AI adds probes to your codebase
34
+ utopia serve -b → Start the local data service
35
+ → Run your app, browse around
36
+ → AI agent queries probe data via MCP
37
+ → Writes better code because it sees production
38
+ ```
39
+
40
+ Utopia uses your AI agent (Claude Code or Codex) to analyze your codebase and decide where to place probes. The probes are contextual - they don't just log "API returned 200." They capture the response shape, what triggered the call, what data flowed through, and what decisions the code made at runtime.
41
+
42
+ When your agent works on the codebase next, it queries this data automatically before writing a single line of code.
43
+
44
+ <br />
45
+
46
+ ## Quick Start
47
+
48
+ ### Install
49
+
50
+ ```bash
51
+ npm install -g @utopia-ai/cli
52
+ ```
53
+
54
+ > **Requirements:** macOS, Node.js 18+, and either [Claude Code](https://docs.anthropic.com/en/docs/claude-code) or [Codex CLI](https://github.com/openai/codex) installed.
55
+
56
+ ### Setup (30 seconds)
57
+
58
+ ```bash
59
+ cd your-project
60
+ utopia init
61
+ ```
62
+
63
+ You'll choose your AI agent, cloud provider, data capture depth, and probe focus. Utopia auto-detects your framework and language.
64
+
65
+ ### Instrument
66
+
67
+ ```bash
68
+ utopia instrument
69
+ ```
70
+
71
+ Your AI agent analyzes the codebase and adds probes to high-value locations - API routes, auth flows, database calls, error boundaries, business logic. Takes 2-5 minutes depending on codebase size.
72
+
73
+ ### Run
74
+
75
+ ```bash
76
+ utopia serve -b # Start the data service (background)
77
+ npm run dev # Start your app as usual
78
+ ```
79
+
80
+ Browse your app. Probes start capturing data immediately.
81
+
82
+ ### See It Work
83
+
84
+ Open your AI agent in the project. Ask it to fix a bug or build a feature. It will automatically query Utopia's MCP tools *before* writing code - pulling in real production context about errors, data patterns, and runtime behavior.
85
+
86
+ ```
87
+ You: "Getting errors on the /api/users endpoint, can you fix it?"
88
+
89
+ Agent: *queries get_recent_errors* → sees the exact error, stack trace,
90
+ and the input data that caused it → fixes it in one shot
91
+ ```
92
+
93
+ <br />
94
+
95
+ ## Supported Frameworks
96
+
97
+ | Framework | Language | Status |
98
+ |-----------|----------|--------|
99
+ | **Next.js** | TypeScript / JavaScript | Fully supported |
100
+ | **React** | TypeScript / JavaScript | Fully supported |
101
+ | **Python** | FastAPI, Flask, Django | Fully supported |
102
+
103
+ <br />
104
+
105
+ ## Supported AI Agents
106
+
107
+ | Agent | Integration |
108
+ |-------|-------------|
109
+ | **Claude Code** | MCP tools + CLAUDE.md instructions |
110
+ | **Codex (OpenAI)** | MCP tools + AGENTS.md instructions |
111
+
112
+ <br />
113
+
114
+ ## CLI Reference
115
+
116
+ ### Core Commands
117
+
118
+ | Command | Description |
119
+ |---------|-------------|
120
+ | `utopia init` | Initialize Utopia in your project |
121
+ | `utopia instrument` | AI adds production probes to your codebase |
122
+ | `utopia reinstrument -p "purpose"` | Add targeted probes for a specific task |
123
+ | `utopia validate` | Check that all probes have valid syntax |
124
+ | `utopia serve -b` | Start the data service in the background |
125
+ | `utopia serve --stop` | Stop the background data service |
126
+ | `utopia destruct` | Remove all probes and restore original files |
127
+ | `utopia status` | Check probe counts, server health, configuration |
128
+
129
+ ### Examples
130
+
131
+ **Initial setup:**
132
+ ```bash
133
+ utopia init
134
+ utopia instrument
135
+ utopia validate
136
+ utopia serve -b
137
+ ```
138
+
139
+ **Add probes for a specific task:**
140
+ ```bash
141
+ utopia reinstrument -p "debugging auth failures on the login endpoint"
142
+ utopia reinstrument -p "need to understand billing data flow before refactoring"
143
+ utopia reinstrument -p "investigating slow database queries on the dashboard"
144
+ ```
145
+
146
+ **Clean removal:**
147
+ ```bash
148
+ utopia destruct # Remove all probes, restore original files
149
+ utopia destruct --dry-run # Preview what would be removed
150
+ ```
151
+
152
+ <br />
153
+
154
+ ## What the Probes Capture
155
+
156
+ Utopia probes are not logs. They capture the context an AI agent needs to understand your code at runtime.
157
+
158
+ ### Debugging Probes
159
+ - **API calls** - method, URL, status, duration, request/response shapes
160
+ - **Errors** - type, message, stack trace, *the exact input data that caused it*
161
+ - **Function behavior** - arguments, return values, which code path was taken and why
162
+ - **Database queries** - SQL patterns, timing, row counts, table access patterns
163
+ - **Infrastructure** - cloud provider, region, memory usage, environment config
164
+
165
+ ### Security Probes
166
+ - **SQL injection detection** - captures whether queries use parameterized inputs
167
+ - **Auth flow analysis** - token validation decisions, permission checks, role verification
168
+ - **Input validation** - where user input enters the system, whether it's sanitized
169
+ - **Insecure patterns** - HTTP calls, exposed error details, missing rate limiting, CORS config
170
+
171
+ ### Data Modes
172
+
173
+ | Mode | What's captured |
174
+ |------|----------------|
175
+ | **Schemas & shapes** | Counts, types, field names, distributions - no actual user data (GDPR/CCPA safe) |
176
+ | **Full data context** | Real inputs, outputs, DB results - maximum visibility for debugging |
177
+
178
+ <br />
179
+
180
+ ## Real-World Examples
181
+
182
+ ### "Fix the auth redirect bug"
183
+
184
+ Without Utopia, the agent would need to run the app, reproduce the issue, read logs, and guess at the cause.
185
+
186
+ With Utopia, the agent queries `get_recent_errors` and immediately sees:
187
+
188
+ ```
189
+ Error: NEXT_REDIRECT
190
+ File: app/login/route.ts:26
191
+ Data: { redirectUri: "https://staging.validia.ai/auth/callback",
192
+ origin: "http://localhost:3000" }
193
+ ```
194
+
195
+ The agent sees the redirect URI is hardcoded to staging instead of being computed from the request origin. Fix is immediate.
196
+
197
+ ### "Why is the dashboard slow?"
198
+
199
+ The agent queries `get_api_context` and sees:
200
+
201
+ ```
202
+ GET contentful://cdn.contentful.com/getEntries
203
+ Calls: 14 | Avg: 1,256ms | Slowest: 2,107ms
204
+
205
+ POST posthog://feature-flag/new-landing-page
206
+ Calls: 28 | Avg: 0ms | Status: exception_fallback
207
+ ```
208
+
209
+ Contentful is averaging 1.2s per call (too slow), and PostHog is failing silently on every request. The agent knows exactly what to optimize.
210
+
211
+ ### "Add probes before refactoring billing"
212
+
213
+ ```bash
214
+ utopia reinstrument -p "understand billing data flow, subscription states, and payment patterns"
215
+ ```
216
+
217
+ The agent adds targeted probes to billing endpoints, subscription status checks, and payment processing. After running the app, it has full visibility into the billing system's runtime behavior before changing a single line.
218
+
219
+ <br />
220
+
221
+ ## How the MCP Integration Works
222
+
223
+ When you run `utopia init`, Utopia registers an MCP server with your AI agent. This gives the agent these tools:
224
+
225
+ | MCP Tool | What it does |
226
+ |----------|--------------|
227
+ | `get_recent_errors` | Errors with stack traces and the input data that caused them |
228
+ | `get_production_context` | Context relevant to a specific task or file |
229
+ | `get_full_context` | Complete production overview - use at the start of any task |
230
+ | `get_api_context` | External API call patterns, status codes, latencies |
231
+ | `get_database_context` | Database query patterns, timing, data shapes |
232
+ | `get_infrastructure_context` | Deployment environment, provider, region, config |
233
+ | `get_impact_analysis` | What is affected by changing a specific file or function |
234
+
235
+ The agent is instructed (via CLAUDE.md or AGENTS.md) to **always** check these tools before writing code. It's not optional context - it's how the agent understands your production environment.
236
+
237
+ <br />
238
+
239
+ ## Architecture
240
+
241
+ ```
242
+ ┌─────────────┐ ┌──────────────┐ ┌─────────────────┐
243
+ │ Your App │────▶│ Utopia Probes │────▶│ Data Service │
244
+ │ (running) │ │ (in your code)│ │ (localhost:7890) │
245
+ └─────────────┘ └──────────────┘ └────────┬────────┘
246
+
247
+ ┌────────▼────────┐
248
+ │ MCP Server │
249
+ │ (utopia mcp) │
250
+ └────────┬────────┘
251
+
252
+ ┌────────▼────────┐
253
+ │ AI Agent │
254
+ │ (Claude/Codex) │
255
+ └─────────────────┘
256
+ ```
257
+
258
+ - **Probes** are lightweight, non-blocking, and never throw. They use a background queue with circuit breaker.
259
+ - **Data Service** is a local Express + SQLite server. No cloud, no accounts, no data leaves your machine.
260
+ - **MCP Server** translates agent queries into data service API calls with formatted, contextual responses.
261
+
262
+ <br />
263
+
264
+ ## Troubleshooting
265
+
266
+ ### `utopia: command not found`
267
+ ```bash
268
+ npm install -g @utopia-ai/cli
269
+ ```
270
+ Make sure your npm global bin is in your PATH. Check with `npm bin -g`.
271
+
272
+ ### `utopia instrument` hangs with no output
273
+ The AI agent is working - it reads files, plans the instrumentation, then writes probes. This takes 2-5 minutes. For Claude Code, you'll see streaming progress. For Codex, you'll see a spinner with elapsed time.
274
+
275
+ ### `Module not found: utopia-runtime` (JavaScript/TypeScript)
276
+ The runtime didn't install. Run `utopia instrument` again - it installs the runtime from npm (`utopia-runtime` package) automatically.
277
+
278
+ ### `ModuleNotFoundError: No module named 'utopia_runtime'` (Python)
279
+ The runtime didn't install into your virtualenv. Run `utopia instrument` again - it installs from PyPI (`utopia-runtime` package) automatically.
280
+
281
+ ### Pydantic `Extra inputs are not permitted` error (Python)
282
+ Old Utopia env vars in your `.env` file are conflicting with Pydantic Settings. Utopia no longer writes env vars for Python projects (it reads from `.utopia/config.json` instead). Remove any `UTOPIA_ENDPOINT` or `UTOPIA_PROJECT_ID` lines from your `.env`.
283
+
284
+ ### `utopia serve -b` says port 7890 is in use
285
+ ```bash
286
+ utopia serve --stop # Try stopping the existing server
287
+ lsof -ti:7890 | xargs kill # Force kill whatever is on that port
288
+ utopia serve -b # Start fresh
289
+ ```
290
+
291
+ ### MCP tools not available in Claude Code / Codex
292
+ Re-run `utopia init` to re-register the MCP server. Then restart your AI agent session. The MCP server must be registered with the agent before it can use the tools.
293
+
294
+ ### `utopia destruct` shows "user changes preserved"
295
+ This means you made code changes to files that also have probes. Utopia stripped the probes but kept your changes. This is expected and safe.
296
+
297
+ ### Probes not sending data (0 probes in server)
298
+ 1. Is the server running? Check: `curl http://localhost:7890/api/v1/health`
299
+ 2. For JS/TS: Are the env vars set? Check `.env.local` has `UTOPIA_ENDPOINT` and `UTOPIA_PROJECT_ID`
300
+ 3. For Python: Does `.utopia/config.json` exist in the project root?
301
+ 4. Did you restart your app after instrumenting?
302
+
303
+ <br />
304
+
305
+ ## Platform Support
306
+
307
+ | Platform | Status |
308
+ |----------|--------|
309
+ | **macOS** | Fully supported |
310
+ | **Linux** | Should work (not yet tested) |
311
+ | **Windows** | Not yet supported |
312
+
313
+ <br />
314
+
315
+ ## Privacy & Security
316
+
317
+ - All data stays on your machine. The data service runs locally on `localhost:7890`.
318
+ - No cloud accounts, no telemetry, no data transmission to external services.
319
+ - Probes can be configured to capture schemas only (no PII) or full data context.
320
+ - Passwords, tokens, API keys, and secrets are never captured regardless of mode.
321
+ - `utopia destruct` cleanly removes all probes and restores your original files.
322
+
323
+ <br />
324
+
325
+
326
+ <div align="center">
327
+
328
+ **Built by [Paul Vann](https://github.com/paulvann)**
329
+
330
+ *code that talks back*
331
+
332
+ </div>
package/package.json CHANGED
@@ -1,11 +1,20 @@
1
1
  {
2
2
  "name": "@utopia-ai/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Production-aware probes that give AI coding agents real-time context about how code runs in production",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "utopia": "bin/utopia.js"
8
8
  },
9
+ "files": [
10
+ "bin/",
11
+ "src/",
12
+ "python/utopia_runtime/",
13
+ "python/instrumenter/",
14
+ "python/pyproject.toml",
15
+ "python/README.md",
16
+ "scripts/"
17
+ ],
9
18
  "scripts": {
10
19
  "build": "tsc",
11
20
  "dev": "tsx src/cli/index.ts",
@@ -35,7 +44,8 @@
35
44
  "commander": "^13.0.0",
36
45
  "express": "^4.21.0",
37
46
  "inquirer": "^12.3.0",
38
- "uuid": "^11.0.0"
47
+ "uuid": "^11.0.0",
48
+ "tsx": "^4.19.0"
39
49
  },
40
50
  "devDependencies": {
41
51
  "@types/babel__core": "^7.20.5",
@@ -45,7 +55,6 @@
45
55
  "@types/express": "^5.0.0",
46
56
  "@types/node": "^22.10.0",
47
57
  "@types/uuid": "^10.0.0",
48
- "tsx": "^4.19.0",
49
58
  "typescript": "^5.7.0"
50
59
  },
51
60
  "engines": {
@@ -1 +0,0 @@
1
- {}
@@ -1,39 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npm install:*)",
5
- "Bash(npx tsc:*)",
6
- "Bash(curl:*)",
7
- "Bash(pkill -f \"tsx src/server\")",
8
- "Bash(npx tsx:*)",
9
- "Bash(npm link:*)",
10
- "Bash(utopia --version)",
11
- "Bash(chmod +x /Users/paulvann/Desktop/cool-projects/utopia/bin/utopia.js)",
12
- "Bash(npm unlink:*)",
13
- "Bash(pnpm link:*)",
14
- "Bash(ls /Users/paulvann/Desktop/cool-projects/validia-landing/node_modules/.pnpm/utopia-runtime*)",
15
- "Bash(ls:*)",
16
- "Bash(grep -r \"NEXT_PUBLIC\" /Users/paulvann/Desktop/cool-projects/validia-landing/.env*)",
17
- "Bash(utopia --help)",
18
- "Bash(utopia serve:*)",
19
- "Bash(rm -rf /Users/paulvann/Desktop/cool-projects/validia-landing/node_modules/utopia-runtime)",
20
- "Bash(pnpm install:*)",
21
- "Bash(pnpm unlink:*)",
22
- "Bash(rm -rf node_modules/utopia-runtime node_modules/.pnpm/utopia-runtime*)",
23
- "Bash(rm -f node_modules/utopia-runtime)",
24
- "Bash(rm -f pnpm-lock.yaml)",
25
- "Bash(node:*)",
26
- "Bash(/Users/paulvann/Desktop/cool-projects/validia-landing/.env.local:*)",
27
- "Bash(utopia reinstrument:*)",
28
- "WebSearch",
29
- "Bash(chmod:*)",
30
- "Bash(python3 -c \"import sys,json; d=json.load\\(sys.stdin\\); print\\(d.get\\(''''description'''',''''''''\\), d.get\\(''''default_branch'''',''''''''\\), d.get\\(''''html_url'''',''''''''\\)\\)\")",
31
- "Bash(python3 -c \":*)",
32
- "Bash(python3 -c ':*)",
33
- "Bash(npm view:*)",
34
- "Bash(npm org:*)",
35
- "Bash(npm publish:*)",
36
- "Bash(npm pkg:*)"
37
- ]
38
- }
39
- }
package/python/setup.py DELETED
@@ -1,27 +0,0 @@
1
- from setuptools import setup, find_packages
2
-
3
- setup(
4
- name='utopia-runtime',
5
- version='0.1.0',
6
- description='Lightweight probe runtime for Utopia - zero-impact production observability',
7
- long_description='Utopia Runtime provides non-blocking, zero-dependency probe reporting '
8
- 'for Python applications. It collects errors, database calls, API calls, '
9
- 'infrastructure info, and function traces, shipping them asynchronously '
10
- 'to the Utopia data service via a background daemon thread.',
11
- author='Utopia',
12
- license='MIT',
13
- packages=find_packages(),
14
- python_requires='>=3.9',
15
- classifiers=[
16
- 'Development Status :: 3 - Alpha',
17
- 'Intended Audience :: Developers',
18
- 'License :: OSI Approved :: MIT License',
19
- 'Programming Language :: Python :: 3',
20
- 'Programming Language :: Python :: 3.9',
21
- 'Programming Language :: Python :: 3.10',
22
- 'Programming Language :: Python :: 3.11',
23
- 'Programming Language :: Python :: 3.12',
24
- 'Topic :: Software Development :: Libraries',
25
- 'Topic :: System :: Monitoring',
26
- ],
27
- )
@@ -1,59 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: utopia-runtime
3
- Version: 0.1.0
4
- Summary: Zero-impact production probe runtime for Utopia — gives AI coding agents real-time visibility into how code runs
5
- Author: Utopia
6
- License: MIT
7
- Project-URL: Homepage, https://github.com/paulvann/utopia
8
- Project-URL: Repository, https://github.com/paulvann/utopia
9
- Keywords: utopia,probes,observability,production-context,ai-agents
10
- Classifier: Development Status :: 3 - Alpha
11
- Classifier: Intended Audience :: Developers
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.9
15
- Classifier: Programming Language :: Python :: 3.10
16
- Classifier: Programming Language :: Python :: 3.11
17
- Classifier: Programming Language :: Python :: 3.12
18
- Classifier: Programming Language :: Python :: 3.13
19
- Classifier: Topic :: Software Development :: Libraries
20
- Classifier: Topic :: System :: Monitoring
21
- Requires-Python: >=3.9
22
- Description-Content-Type: text/markdown
23
- Dynamic: author
24
- Dynamic: requires-python
25
-
26
- # utopia-runtime
27
-
28
- Zero-impact production probe runtime for [Utopia](https://github.com/paulvann/utopia).
29
-
30
- Captures errors, API calls, database queries, function behavior, and infrastructure context — sending it to the Utopia data service so AI coding agents can understand how your code runs in production.
31
-
32
- ## Installation
33
-
34
- ```bash
35
- pip install utopia-runtime
36
- ```
37
-
38
- ## Usage
39
-
40
- Probes are added by `utopia instrument` — you don't typically import this directly. The runtime auto-initializes from `.utopia/config.json` in your project root.
41
-
42
- ```python
43
- import utopia_runtime
44
-
45
- # Reports are non-blocking and never raise
46
- utopia_runtime.report_function(
47
- file="app/routes.py",
48
- line=25,
49
- function_name="get_user",
50
- args=[{"user_id": 123}],
51
- return_value={"found": True},
52
- duration=15,
53
- call_stack=[],
54
- )
55
- ```
56
-
57
- ## Zero dependencies
58
-
59
- Uses only the Python standard library. No external packages required.
@@ -1,10 +0,0 @@
1
- README.md
2
- pyproject.toml
3
- setup.py
4
- utopia_runtime/__init__.py
5
- utopia_runtime/client.py
6
- utopia_runtime/probe.py
7
- utopia_runtime.egg-info/PKG-INFO
8
- utopia_runtime.egg-info/SOURCES.txt
9
- utopia_runtime.egg-info/dependency_links.txt
10
- utopia_runtime.egg-info/top_level.txt
@@ -1 +0,0 @@
1
- utopia_runtime
@@ -1,30 +0,0 @@
1
- {
2
- "name": "utopia-runtime",
3
- "version": "0.1.0",
4
- "lockfileVersion": 3,
5
- "requires": true,
6
- "packages": {
7
- "": {
8
- "name": "utopia-runtime",
9
- "version": "0.1.0",
10
- "license": "MIT",
11
- "devDependencies": {
12
- "typescript": "^5.7.0"
13
- }
14
- },
15
- "node_modules/typescript": {
16
- "version": "5.9.3",
17
- "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
18
- "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
19
- "dev": true,
20
- "license": "Apache-2.0",
21
- "bin": {
22
- "tsc": "bin/tsc",
23
- "tsserver": "bin/tsserver"
24
- },
25
- "engines": {
26
- "node": ">=14.17"
27
- }
28
- }
29
- }
30
- }
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "resolveJsonModule": true,
13
- "declaration": true,
14
- "declarationMap": true,
15
- "sourceMap": true
16
- },
17
- "include": ["src/**/*"],
18
- "exclude": ["node_modules", "dist"]
19
- }