@neurcode-ai/cli 0.2.0 → 0.2.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.
package/README.md DELETED
@@ -1,125 +0,0 @@
1
- # Neurcode CLI
2
-
3
- AI-powered code governance and diff analysis tool.
4
-
5
- ## Installation
6
-
7
- ### Option 1: Link locally (for development)
8
-
9
- ```bash
10
- # From the monorepo root
11
- pnpm install
12
- pnpm --filter @neurcode/cli build
13
-
14
- # Link globally
15
- cd packages/cli
16
- pnpm link --global
17
- ```
18
-
19
- ### Option 2: Use via pnpm (from monorepo)
20
-
21
- ```bash
22
- # From monorepo root
23
- pnpm cli check --help
24
- ```
25
-
26
- ## Configuration
27
-
28
- Create a `neurcode.config.json` file in your project root or home directory:
29
-
30
- ```json
31
- {
32
- "apiUrl": "https://api.neurcode.com",
33
- "apiKey": "nk_live_YOUR_API_KEY_HERE",
34
- "projectId": "optional-project-id"
35
- }
36
- ```
37
-
38
- Or set environment variables:
39
-
40
- ```bash
41
- export NEURCODE_API_URL="https://api.neurcode.com"
42
- export NEURCODE_API_KEY="nk_live_YOUR_API_KEY_HERE"
43
- export NEURCODE_PROJECT_ID="optional-project-id"
44
- ```
45
-
46
- ## Usage
47
-
48
- ### Basic Check (Local Rules)
49
-
50
- ```bash
51
- # Check staged changes
52
- neurcode check --staged
53
-
54
- # Check changes against HEAD
55
- neurcode check --head
56
-
57
- # Check against specific base
58
- neurcode check --base main
59
- ```
60
-
61
- ### Online Check (Rule-Based Analysis)
62
-
63
- ```bash
64
- # Send diff to API for rule-based analysis
65
- neurcode check --staged --online
66
- ```
67
-
68
- ### AI-Powered Analysis (with Session Tracking)
69
-
70
- ```bash
71
- # AI analysis with automatic session creation
72
- neurcode check --staged --online --ai --intent "Fix login bug"
73
-
74
- # Use existing session
75
- neurcode check --staged --online --ai --intent "Add feature" --session-id "session_123"
76
- ```
77
-
78
- ## Getting Your API Key
79
-
80
- 1. Go to https://neurcode.com/dashboard/api-keys
81
- 2. Create a new API key
82
- 3. Copy the key (starts with `nk_live_`)
83
- 4. Add it to your config file or environment variables
84
-
85
- ## Viewing Sessions
86
-
87
- After running AI analysis, you'll get a session ID. View it in the dashboard:
88
-
89
- ```
90
- https://neurcode.com/dashboard/sessions/{sessionId}
91
- ```
92
-
93
- ## Exit Codes (for CI/CD)
94
-
95
- The CLI uses exit codes to indicate analysis results:
96
-
97
- - **0**: `ALLOW` - Code is clean, no issues found
98
- - **1**: `WARN` - Issues found but not blocking (moderate redundancy or warnings)
99
- - **2**: `BLOCK` - Critical issues found (high redundancy, intent mismatch, or security violations)
100
-
101
- ### CI/CD Integration
102
-
103
- ```bash
104
- # In your CI/CD pipeline
105
- neurcode check --staged --ai --intent "Add feature"
106
-
107
- # Exit code 0 = success, continue
108
- # Exit code 1 = warnings, you may want to continue or fail
109
- # Exit code 2 = blocked, should fail the build
110
-
111
- # Example GitHub Actions
112
- - name: Check code with Neurcode
113
- run: neurcode check --staged --ai --intent "${{ github.event.head_commit.message }}"
114
- continue-on-error: false # Fail on exit code 1 or 2
115
- ```
116
-
117
- ### Custom Exit Code Behavior
118
-
119
- If you want to customize exit code behavior, you can wrap the command:
120
-
121
- ```bash
122
- # Only fail on BLOCK (exit code 2)
123
- neurcode check --staged --ai --intent "Add feature" || [ $? -eq 1 ]
124
- ```
125
-
@@ -1,7 +0,0 @@
1
- /**
2
- * Integration Tests for CLI → API Flow
3
- *
4
- * Tests the complete flow: CLI → API → Database → Response
5
- */
6
- export {};
7
- //# sourceMappingURL=check.integration.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check.integration.test.d.ts","sourceRoot":"","sources":["../../src/commands/check.integration.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -1,157 +0,0 @@
1
- "use strict";
2
- /**
3
- * Integration Tests for CLI → API Flow
4
- *
5
- * Tests the complete flow: CLI → API → Database → Response
6
- */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- const vitest_1 = require("vitest");
42
- const child_process_1 = require("child_process");
43
- const path_1 = require("path");
44
- const index_1 = require("../../../services/api/src/index");
45
- const db_1 = require("../../../services/api/src/db");
46
- const api_keys_1 = require("../../../services/api/src/lib/api-keys");
47
- (0, vitest_1.describe)('CLI → API Integration Tests', () => {
48
- let server;
49
- let apiKey;
50
- let apiUrl;
51
- let organizationId;
52
- let cliPath;
53
- (0, vitest_1.beforeAll)(async () => {
54
- // Initialize database
55
- await (0, db_1.initDatabase)(process.env.DATABASE_URL || 'postgresql://neurcode:neurcode@localhost:5432/neurcode');
56
- // Build server
57
- server = await (0, index_1.buildServer)();
58
- await server.ready();
59
- // Get server URL
60
- const address = server.server.address();
61
- if (typeof address === 'string') {
62
- apiUrl = address;
63
- }
64
- else if (address) {
65
- apiUrl = `http://localhost:${address.port}`;
66
- }
67
- else {
68
- apiUrl = 'http://localhost:3000';
69
- }
70
- // Create test organization and API key
71
- const orgResult = await (0, db_1.query)(`
72
- INSERT INTO organizations (id, name, slug)
73
- VALUES (gen_random_uuid(), 'Test Org', 'test-org-cli')
74
- ON CONFLICT (slug) DO UPDATE SET name = EXCLUDED.name
75
- RETURNING id
76
- `);
77
- organizationId = orgResult.rows[0].id;
78
- const keyData = await (0, api_keys_1.createApiKey)(organizationId, null, 'CLI Test Key');
79
- apiKey = keyData.key;
80
- // Build CLI
81
- const cliDir = (0, path_1.join)(__dirname, '..', '..');
82
- (0, child_process_1.execSync)('pnpm build', { cwd: cliDir, stdio: 'inherit' });
83
- cliPath = (0, path_1.join)(cliDir, 'dist', 'index.js');
84
- }, 30000);
85
- (0, vitest_1.afterAll)(async () => {
86
- await server.close();
87
- await (0, db_1.closeDatabase)();
88
- });
89
- (0, vitest_1.describe)('CLI online mode', () => {
90
- (0, vitest_1.it)('should send diff to API and get response', async () => {
91
- // Create a test git repo with a diff
92
- const testDir = '/tmp/neurcode-cli-test';
93
- try {
94
- (0, child_process_1.execSync)('rm -rf ' + testDir, { stdio: 'ignore' });
95
- (0, child_process_1.execSync)('mkdir -p ' + testDir, { stdio: 'ignore' });
96
- (0, child_process_1.execSync)('git init', { cwd: testDir, stdio: 'ignore' });
97
- (0, child_process_1.execSync)('git config user.email "test@test.com"', { cwd: testDir, stdio: 'ignore' });
98
- (0, child_process_1.execSync)('git config user.name "Test User"', { cwd: testDir, stdio: 'ignore' });
99
- // Create a test file
100
- const fs = await Promise.resolve().then(() => __importStar(require('fs')));
101
- fs.writeFileSync((0, path_1.join)(testDir, 'test.js'), 'console.log("test");\n');
102
- (0, child_process_1.execSync)('git add test.js', { cwd: testDir, stdio: 'ignore' });
103
- (0, child_process_1.execSync)('git commit -m "Initial commit"', { cwd: testDir, stdio: 'ignore' });
104
- // Make a change
105
- fs.writeFileSync((0, path_1.join)(testDir, 'test.js'), 'console.log("test");\nconst x = 1;\n');
106
- (0, child_process_1.execSync)('git add test.js', { cwd: testDir, stdio: 'ignore' });
107
- // Run CLI with online mode
108
- const result = (0, child_process_1.execSync)(`node ${cliPath} check --online --staged`, {
109
- cwd: testDir,
110
- env: {
111
- ...process.env,
112
- NEURCODE_API_URL: apiUrl,
113
- NEURCODE_API_KEY: apiKey,
114
- },
115
- encoding: 'utf-8',
116
- });
117
- // Should not throw and should contain analysis results
118
- (0, vitest_1.expect)(result).toBeDefined();
119
- (0, vitest_1.expect)(result.length).toBeGreaterThan(0);
120
- }
121
- finally {
122
- (0, child_process_1.execSync)('rm -rf ' + testDir, { stdio: 'ignore' });
123
- }
124
- }, 60000);
125
- (0, vitest_1.it)('should handle API errors gracefully', async () => {
126
- const testDir = '/tmp/neurcode-cli-test-error';
127
- try {
128
- (0, child_process_1.execSync)('rm -rf ' + testDir, { stdio: 'ignore' });
129
- (0, child_process_1.execSync)('mkdir -p ' + testDir, { stdio: 'ignore' });
130
- (0, child_process_1.execSync)('git init', { cwd: testDir, stdio: 'ignore' });
131
- (0, child_process_1.execSync)('git config user.email "test@test.com"', { cwd: testDir, stdio: 'ignore' });
132
- (0, child_process_1.execSync)('git config user.name "Test User"', { cwd: testDir, stdio: 'ignore' });
133
- // Use invalid API key
134
- try {
135
- (0, child_process_1.execSync)(`node ${cliPath} check --online --staged`, {
136
- cwd: testDir,
137
- env: {
138
- ...process.env,
139
- NEURCODE_API_URL: apiUrl,
140
- NEURCODE_API_KEY: 'invalid_key',
141
- },
142
- encoding: 'utf-8',
143
- stdio: 'pipe',
144
- });
145
- }
146
- catch (error) {
147
- // Should fail with error message
148
- (0, vitest_1.expect)(error.message).toBeDefined();
149
- }
150
- }
151
- finally {
152
- (0, child_process_1.execSync)('rm -rf ' + testDir, { stdio: 'ignore' });
153
- }
154
- }, 30000);
155
- });
156
- });
157
- //# sourceMappingURL=check.integration.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check.integration.test.js","sourceRoot":"","sources":["../../src/commands/check.integration.test.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,mCAAmE;AACnE,iDAAyC;AACzC,+BAA4B;AAC5B,2DAA8D;AAE9D,qDAAkF;AAClF,qEAAsE;AAEtE,IAAA,iBAAQ,EAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,IAAI,MAAuB,CAAC;IAC5B,IAAI,MAAc,CAAC;IACnB,IAAI,MAAc,CAAC;IACnB,IAAI,cAAsB,CAAC;IAC3B,IAAI,OAAe,CAAC;IAEpB,IAAA,kBAAS,EAAC,KAAK,IAAI,EAAE;QACnB,sBAAsB;QACtB,MAAM,IAAA,iBAAY,EAAC,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,wDAAwD,CAAC,CAAC;QAEzG,eAAe;QACf,MAAM,GAAG,MAAM,IAAA,mBAAW,GAAE,CAAC;QAC7B,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QAErB,iBAAiB;QACjB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACxC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,MAAM,GAAG,OAAO,CAAC;QACnB,CAAC;aAAM,IAAI,OAAO,EAAE,CAAC;YACnB,MAAM,GAAG,oBAAoB,OAAO,CAAC,IAAI,EAAE,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,uBAAuB,CAAC;QACnC,CAAC;QAED,uCAAuC;QACvC,MAAM,SAAS,GAAG,MAAM,IAAA,UAAK,EAAC;;;;;KAK7B,CAAC,CAAC;QACH,cAAc,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAEtC,MAAM,OAAO,GAAG,MAAM,IAAA,uBAAY,EAAC,cAAc,EAAE,IAAI,EAAE,cAAc,CAAC,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