greenrun-cli 0.2.4 → 0.2.6

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.
@@ -3,6 +3,7 @@ import { execSync } from 'child_process';
3
3
  import { existsSync, readFileSync, writeFileSync, mkdirSync, appendFileSync } from 'fs';
4
4
  import { join, dirname } from 'path';
5
5
  import { fileURLToPath } from 'url';
6
+ import { homedir } from 'os';
6
7
  const __filename = fileURLToPath(import.meta.url);
7
8
  const __dirname = dirname(__filename);
8
9
  const TEMPLATES_DIR = join(__dirname, '..', '..', 'templates');
@@ -64,22 +65,65 @@ async function validateToken(token) {
64
65
  return { valid: false };
65
66
  }
66
67
  }
68
+ function getClaudeConfigPath() {
69
+ return join(homedir(), '.claude.json');
70
+ }
71
+ function readClaudeConfig() {
72
+ const configPath = getClaudeConfigPath();
73
+ if (!existsSync(configPath))
74
+ return {};
75
+ try {
76
+ return JSON.parse(readFileSync(configPath, 'utf-8'));
77
+ }
78
+ catch {
79
+ return {};
80
+ }
81
+ }
82
+ function writeClaudeConfig(config) {
83
+ writeFileSync(getClaudeConfigPath(), JSON.stringify(config, null, 2) + '\n');
84
+ }
85
+ function setLocalMcpServer(name, server) {
86
+ const config = readClaudeConfig();
87
+ const projectPath = process.cwd();
88
+ config.projects = config.projects || {};
89
+ config.projects[projectPath] = config.projects[projectPath] || {};
90
+ config.projects[projectPath].mcpServers = config.projects[projectPath].mcpServers || {};
91
+ config.projects[projectPath].mcpServers[name] = server;
92
+ writeClaudeConfig(config);
93
+ }
67
94
  function configureMcpLocal(token) {
68
95
  try {
69
- execSync(`claude mcp add greenrun --transport stdio -e GREENRUN_API_TOKEN=${token} -- npx -y greenrun-cli@latest`, { stdio: 'inherit' });
96
+ setLocalMcpServer('greenrun', {
97
+ type: 'stdio',
98
+ command: 'npx',
99
+ args: ['-y', 'greenrun-cli@latest'],
100
+ env: { GREENRUN_API_TOKEN: token },
101
+ });
102
+ console.log(' Configured greenrun MCP server');
70
103
  }
71
104
  catch {
72
- console.error('\nFailed to run "claude mcp add". Make sure Claude Code is installed and in your PATH.');
105
+ console.error('\nFailed to write greenrun MCP config to ~/.claude.json');
73
106
  console.error('You can add the MCP server manually by running:\n');
74
107
  console.error(` claude mcp add greenrun --transport stdio -e GREENRUN_API_TOKEN=${token} -- npx -y greenrun-cli@latest\n`);
75
108
  }
76
109
  }
77
110
  function configurePlaywrightMcp() {
78
111
  try {
79
- execSync('claude mcp add playwright -- npx @playwright/mcp@latest --browser chrome --user-data-dir ~/.greenrun/browser-profile', { stdio: 'inherit' });
112
+ setLocalMcpServer('playwright', {
113
+ type: 'stdio',
114
+ command: 'npx',
115
+ args: [
116
+ '@playwright/mcp@latest',
117
+ '--browser', 'chrome',
118
+ '--user-data-dir', join(homedir(), '.greenrun', 'browser-profile'),
119
+ ],
120
+ env: {},
121
+ });
122
+ console.log(' Configured playwright MCP server');
80
123
  }
81
124
  catch {
82
- console.error('\nFailed to add Playwright MCP. You can add it manually:\n');
125
+ console.error('\nFailed to write Playwright MCP config to ~/.claude.json');
126
+ console.error('You can add it manually:\n');
83
127
  console.error(' claude mcp add playwright -- npx @playwright/mcp@latest --browser chrome --user-data-dir ~/.greenrun/browser-profile\n');
84
128
  }
85
129
  }
@@ -117,7 +161,9 @@ function configureMcpProject(token) {
117
161
  console.log(' Added GREENRUN_API_TOKEN to .env');
118
162
  }
119
163
  else {
120
- console.log(' GREENRUN_API_TOKEN already in .env (not modified)');
164
+ const updated = envContent.replace(/GREENRUN_API_TOKEN=.*/g, envLine);
165
+ writeFileSync(envPath, updated);
166
+ console.log(' Updated GREENRUN_API_TOKEN in .env');
121
167
  }
122
168
  }
123
169
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greenrun-cli",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "CLI and MCP server for Greenrun - browser test management for Claude Code",
5
5
  "type": "module",
6
6
  "main": "dist/server.js",
@@ -37,6 +37,25 @@ Projects can be configured with authentication settings so tests auto-login befo
37
37
 
38
38
  Projects can also store named **credentials** (name/email/password sets). Each test can reference a credential by `credential_name` to use specific login details during execution.
39
39
 
40
+ ### Project Setup
41
+
42
+ When asked to create tests, first call `list_projects` to check for an existing project. Then:
43
+
44
+ - **No project exists**: Create one via `create_project` with the name, base URL, and description.
45
+ - **Project exists but missing credentials or auth config**: Update it via `update_project` to add what's missing.
46
+
47
+ In either case, follow these steps:
48
+
49
+ 1. **Derive the base URL** from the project's configuration (e.g. `APP_URL` in `.env`, framework config, or `docker-compose.yml`). Don't ask the user for this.
50
+ 2. **Set up authentication** -- most apps need auth for testing. Be proactive:
51
+ - Look for a registration or login page in the app's routes/config.
52
+ - Create test credentials and store them on the project using the `credentials` parameter. Use clear names like `"default"` or `"admin"`. Example: `{ name: "default", email: "greenrun-test@example.com", password: "TestPass123!" }`.
53
+ - Set `auth_mode: "existing_user"` with the app's `login_url` and step-by-step `login_instructions`.
54
+ - Then register the test account through the app's registration flow using Playwright so the credentials are valid.
55
+ 3. **Discover pages** by reading the app's route definitions, then register key pages via `create_page`.
56
+
57
+ Don't ask the user for information you can derive from the codebase (base URL, login URL, route structure). Only ask when there's genuine ambiguity.
58
+
40
59
  ### Creating Tests
41
60
 
42
61
  1. Navigate to the page you want to test using Playwright